Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions Engines/Wine/QuickScript/Custom Installer Script/script.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
include("engines.wine.quick_script.installer_script");

function CustomInstallerScript() {
InstallerScript.call(this);
class CustomInstallerScript extends InstallerScript {
constructor() {
super();
}

installationCommand(installationCommand) {
Comment thread
madoar marked this conversation as resolved.
this._installationCommand = installationCommand;
return this;
}
}

CustomInstallerScript.prototype = Object.create(InstallerScript.prototype);

CustomInstallerScript.prototype.constructor = CustomInstallerScript;

CustomInstallerScript.prototype.installationCommand = function (installationCommand) {
this._installationCommand = installationCommand;
return this;
};
207 changes: 103 additions & 104 deletions Engines/Wine/QuickScript/GoG Script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,108 +3,107 @@ include("utils.functions.net.download");
include("engines.wine.engine.object");
include("engines.wine.verbs.gdiplus");

function GogScript() {
QuickScript.call(this);
}

GogScript.prototype = Object.create(QuickScript.prototype);

GogScript.prototype.constructor = GogScript;

/**
* 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
*/
GogScript.prototype.gogSetupFileName = function (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
*/
GogScript.prototype.gogSetupFileNames = function (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
*/
GogScript.prototype.loginToGog = function (setupWizard) {
var 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/*");
var currentUrl = browserWindow.getCurrentUrl();
var code = currentUrl.split("code=")[1].split("&")[0];

var 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;
}

GogScript.prototype._downloadSetupFile = function (setupWizard, setupFileName, tmpDirectory) {
var 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
*/
GogScript.prototype.download = function (setupWizard) {
var setupDirectory = createTempDir();
var that = this;
var foundExecutable = null;
this._setupFileNames.forEach(function (setupFileName) {
var downloadedFile = that._downloadSetupFile(setupWizard, setupFileName, setupDirectory);
if (downloadedFile.endsWith(".exe")) {
foundExecutable = downloadedFile;
}
});

return foundExecutable;
}

GogScript.prototype.go = function () {
var setupWizard = SetupWizard(InstallationType.APPS, this._name, this.miniature());

setupWizard.presentation(this._name, this._editor, this._applicationHomepage, this._author);

this.loginToGog(setupWizard);
var setupFile = this.download(setupWizard);

var 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();
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) {
Comment thread
madoar marked this conversation as resolved.
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();
var that = this;
let foundExecutable = null;
this._setupFileNames.forEach(function (setupFileName) {
var downloadedFile = that._downloadSetupFile(setupWizard, setupFileName, setupDirectory);
if (downloadedFile.endsWith(".exe")) {
foundExecutable = downloadedFile;
}
});

return foundExecutable;
}

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();
}
}
139 changes: 68 additions & 71 deletions Engines/Wine/QuickScript/Installer Script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,91 +4,88 @@ include("utils.functions.filesystem.extract");
include("utils.functions.filesystem.files");
include("engines.wine.verbs.luna");


function InstallerScript() {
QuickScript.call(this);
}

InstallerScript.prototype = Object.create(QuickScript.prototype);

InstallerScript.prototype.constructor = InstallerScript;

InstallerScript.prototype.go = function () {
this._name = this._name || "Custom Installer";

var setupWizard = SetupWizard(InstallationType.APPS, this._name, this.miniature());

// if no name given, ask user
if (this._name == "Custom Installer") {
this._name = setupWizard.textbox(tr("Please enter the name of your application."));
class InstallerScript extends QuickScript {
constructor() {
super();
}

setupWizard.presentation(this._name, this._editor, this._applicationHomepage, this._author);

// get installation file from concrete InstallerScript implementation
var installationCommand = this._installationCommand(setupWizard);

var wine = new Wine()
.wizard(setupWizard);
go() {
this._name = this._name || "Custom Installer";

// let user select wine settings if desired
if (this._wineUserSettings) {
var architectures = ["x86", "amd64"];
var shownArchitectures = ["x86 (recommended)", "amd64"];
var selectedArchitecture = setupWizard.menu(tr("Please select the wine architecture."), shownArchitectures, "x86 (recommended)");
this._wineArchitecture = architectures[selectedArchitecture.index];
const setupWizard = SetupWizard(InstallationType.APPS, this._name, this.miniature());

var distributions = wine.availableDistributions(this._wineArchitecture);
var shownDistributions = [];
for (var distributionIdx in distributions) {
if (distributions[distributionIdx] == "upstream") {
shownDistributions.push("upstream (recommended)");
}
else {
shownDistributions.push(distributions[distributionIdx]);
}
// if no name given, ask user
if (this._name == "Custom Installer") {
this._name = setupWizard.textbox(tr("Please enter the name of your application."));
}
var selectedDistribution = setupWizard.menu(tr("Please select the wine distribution."), shownDistributions, "upstream (recommended)");
this._wineDistribution = distributions[selectedDistribution.index];

var operatingSystemFetcher = Bean("operatingSystemFetcher");
var operatingSystem = operatingSystemFetcher.fetchCurrentOperationSystem().getWinePackage();
var versions = wine.availableVersions(this._wineDistribution + "-" + operatingSystem + "-" + this._wineArchitecture);
var shownVersions = [];
for (var versionIdx in versions) {
if (versions[versionIdx] == LATEST_STABLE_VERSION) {
shownVersions.push(versions[versionIdx] + " (recommended)");

setupWizard.presentation(this._name, this._editor, this._applicationHomepage, this._author);

// get installation file from concrete InstallerScript implementation
var installationCommand = this._installationCommand(setupWizard);

var wine = new Wine()
.wizard(setupWizard);

// let user select wine settings if desired
if (this._wineUserSettings) {
var architectures = ["x86", "amd64"];
var shownArchitectures = ["x86 (recommended)", "amd64"];
var selectedArchitecture = setupWizard.menu(tr("Please select the wine architecture."), shownArchitectures, "x86 (recommended)");
this._wineArchitecture = architectures[selectedArchitecture.index];

var distributions = wine.availableDistributions(this._wineArchitecture);
var shownDistributions = [];
for (var distributionIdx in distributions) {
if (distributions[distributionIdx] == "upstream") {
shownDistributions.push("upstream (recommended)");
}
else {
shownDistributions.push(distributions[distributionIdx]);
}
}
else {
shownVersions.push(versions[versionIdx]);
var selectedDistribution = setupWizard.menu(tr("Please select the wine distribution."), shownDistributions, "upstream (recommended)");
this._wineDistribution = distributions[selectedDistribution.index];

var operatingSystemFetcher = Bean("operatingSystemFetcher");
var operatingSystem = operatingSystemFetcher.fetchCurrentOperationSystem().getWinePackage();
var versions = wine.availableVersions(this._wineDistribution + "-" + operatingSystem + "-" + this._wineArchitecture);
var shownVersions = [];
for (var versionIdx in versions) {
if (versions[versionIdx] == LATEST_STABLE_VERSION) {
shownVersions.push(versions[versionIdx] + " (recommended)");
}
else {
shownVersions.push(versions[versionIdx]);
}
}
var selectedVersion = setupWizard.menu(tr("Please select the wine version."), shownVersions, LATEST_STABLE_VERSION + " (recommended)");
this._wineVersion = versions[selectedVersion.index];
}
var selectedVersion = setupWizard.menu(tr("Please select the wine version."), shownVersions, LATEST_STABLE_VERSION + " (recommended)");
this._wineVersion = versions[selectedVersion.index];
}

// setup the prefix
wine.prefix(this._name, this._wineDistribution, this._wineArchitecture, this._wineVersion)
.luna();
// setup the prefix
wine.prefix(this._name, this._wineDistribution, this._wineArchitecture, this._wineVersion)
.luna();

this._preInstall(wine, setupWizard);
this._preInstall(wine, setupWizard);

// back to generic wait (might have been changed in preInstall)
setupWizard.wait(tr("Please wait..."));
// back to generic wait (might have been changed in preInstall)
setupWizard.wait(tr("Please wait..."));

wine.run(installationCommand.command, installationCommand.args, false, true);
wine.run(installationCommand.command, installationCommand.args, false, true);

// if no executable given, ask user
if (!this._executable) {
this._executable = fileName(setupWizard.browse(tr("Please select the executable."), wine.prefixDirectory(), ["exe"]));
}
// if no executable given, ask user
if (!this._executable) {
this._executable = fileName(setupWizard.browse(tr("Please select the executable."), wine.prefixDirectory(), ["exe"]));
}

this._createShortcut(wine.prefix());
this._createShortcut(wine.prefix());

this._postInstall(wine, setupWizard);
this._postInstall(wine, setupWizard);

// back to generic wait (might have been changed in postInstall)
setupWizard.wait(tr("Please wait..."));
// back to generic wait (might have been changed in postInstall)
setupWizard.wait(tr("Please wait..."));

setupWizard.close();
};
setupWizard.close();
}
}
Loading