forked from PhoenicisOrg/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
122 lines (102 loc) · 4.15 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const Wine = include("engines.wine.engine.object");
include("engines.wine.quick_script.quick_script");
include("engines.wine.verbs.gdiplus");
include("utils.functions.net.download");
class GogScript extends QuickScript {
constructor() {
super();
}
/**
* Sets one setup file name so that the script can fetch it from gog.com
*
* @param {string} setupFileName The setup file name
* @returns {GogScript} This
*/
gogSetupFileName(setupFileName) {
this._setupFileNames = [setupFileName];
return this;
}
/**
* Sets the setup file(s) name so that the script can fetch it from gog.com
*
* @param {string[]} setupFileNames The setup file name(s)
* @returns {GogScript} This
*/
gogSetupFileNames(setupFileNames) {
this._setupFileNames = setupFileNames;
return this;
}
/**
* Presents a Gog.com login window to the user, login to its account and return a token that can be used later.
* Stores the tocken in a parameter
*
* @param {SetupWizard} setupWizard The setupWizard to use
* @returns {GogScript} This
*/
loginToGog(setupWizard) {
const browserWindow = setupWizard.createBrowser(
tr("Please login to your GoG.com account so that we can download the game for you:")
);
browserWindow.goToUrl(
"https://auth.gog.com/auth?" +
"client_id=46899977096215655&" +
"redirect_uri=https%3A%2F%2Fembed.gog.com%2Fon_login_success%3Forigin%3Dclient&" +
"response_type=code&" +
"layout=client2"
);
browserWindow.waitForUrl("https://embed.gog.com/*");
const currentUrl = browserWindow.getCurrentUrl();
const code = currentUrl.split("code=")[1].split("&")[0];
const tokenUrl =
"https://auth.gog.com/token?" +
"client_id=46899977096215655&" +
"client_secret=9d85c43b1482497dbbce61f6e4aa173a433796eeae2ca8c5f6129f2dc4de46d9&" +
"grant_type=authorization_code&" +
`code=${code}&` +
"redirect_uri=https%3A%2F%2Fembed.gog.com%2Fon_login_success%3Forigin%3Dclient";
this._token = new Downloader().url(tokenUrl).json();
return this;
}
_downloadSetupFile(setupWizard, setupFileName, tmpDirectory) {
const url = `https://www.gog.com/downloads/${setupFileName}`;
// We set a user agent so that GoG sends the filename of the executable
return new Downloader()
.url(url)
.wizard(setupWizard)
.to(tmpDirectory)
.headers({
"Authorization": "Bearer " + this._token["access_token"],
"User-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:64.0) Gecko/20100101 Firefox/64.0"
})
.get();
}
/**
* Download the setup resources in the same directory, and returns the path of the .exe
*
* @param {SetupWizard} setupWizard The setup wizard
* @returns {String} The .exe file entry that can be used to continue the installation
*/
download(setupWizard) {
const setupDirectory = createTempDir();
return this._setupFileNames
.map(setupFileName => this._downloadSetupFile(setupWizard, setupFileName, setupDirectory))
.find(downloadedFile => downloadedFile.endsWith(".exe"));
}
go() {
const setupWizard = SetupWizard(InstallationType.APPS, this._name, this.miniature());
setupWizard.presentation(this._name, this._editor, this._applicationHomepage, this._author);
this.loginToGog(setupWizard);
const setupFile = this.download(setupWizard);
const wine = new Wine()
.wizard(setupWizard)
.prefix(this._name, this._wineDistribution, this._wineArchitecture, this._wineVersion)
.create()
.wait();
this._preInstall(wine, setupWizard);
wine.gdiplus();
wine.run(setupFile, [], wine.prefixDirectory() + "/drive_c/", true, true);
this._postInstall(wine, setupWizard);
this._createShortcut(wine.prefix());
setupWizard.close();
}
}