summaryrefslogtreecommitdiff
path: root/src/main/manaplus/manaApp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/manaplus/manaApp')
-rw-r--r--src/main/manaplus/manaApp/linux.ts246
-rw-r--r--src/main/manaplus/manaApp/manaApp.interface.ts12
-rw-r--r--src/main/manaplus/manaApp/windows.ts156
3 files changed, 241 insertions, 173 deletions
diff --git a/src/main/manaplus/manaApp/linux.ts b/src/main/manaplus/manaApp/linux.ts
index 6c804d5..da37de0 100644
--- a/src/main/manaplus/manaApp/linux.ts
+++ b/src/main/manaplus/manaApp/linux.ts
@@ -1,124 +1,160 @@
import { ManaPlusApp } from "./manaApp.interface";
import { app } from "electron";
-import * as fs from 'fs-extra';
+import * as fs from "fs-extra";
import { getRequest } from "../../util/webrequest";
import { Status } from "../../status";
import { download, Progress as ProgressType } from "../../util/downloader";
import { promisify } from "util";
export class ManaPlusAppLinux implements ManaPlusApp {
- private path: string;
- startCommand: string;
- versionRegEx: RegExp = /.*ManaPlus ([\d.]+) Linux.*/g;//TODO
- constructor() {
- const ManaPath = app.getPath('userData') + "/manaplus";
- fs.existsSync(ManaPath) || fs.mkdirSync(ManaPath);
- fs.existsSync(app.getPath('userData') + "/temp") || fs.mkdirSync(app.getPath('userData') + "/temp");
- this.path = ManaPath;
- this.startCommand = ManaPath + '/Mana.AppImage'
- }
- getGameDir(): string {
- throw new Error("getGameDir() is windows only!");
- }
- getVersion(): Promise<string> {
- return new Promise((res, rej) => {
- let output: string;
- const child = require('child_process').execFile(this.startCommand, ['-v'], function (err: Error, data: any) {
- output = data.toString();
- });
- child.on('close', () => {
- output = output.replace(this.versionRegEx, "$1");
- res(output);
- });
- child.on('error', () => {
- rej(new Error("Version check failed"));
- });
- });
- }
- isInstalled(): boolean {
- return fs.existsSync(this.path + '/Mana.AppImage');
- }
- async updateAvailable(): Promise<{ isNewVersion: boolean; newestVersion: string; }> {
- try {
- let versions = await getRequest("https://tmw2.org/manalauncher/versions.json?" + Date.now());
- let currect_version = await this.isInstalled ? await this.getVersion() : "-";
- return {
- isNewVersion: currect_version.indexOf(versions.AppImage.version) === -1,
- newestVersion: versions.AppImage.version
- };
- } catch (e) {
- throw e;
+ private path: string;
+ startCommand: string;
+ versionRegEx: RegExp = /.*ManaPlus ([\d.]+) Linux.*/g; //TODO
+ constructor() {
+ const ManaPath = app.getPath("userData") + "/manaplus";
+ fs.existsSync(ManaPath) || fs.mkdirSync(ManaPath);
+ fs.existsSync(app.getPath("userData") + "/temp") ||
+ fs.mkdirSync(app.getPath("userData") + "/temp");
+ this.path = ManaPath;
+ this.startCommand = ManaPath + "/Mana.AppImage";
+ }
+ getGameDir(): string {
+ throw new Error("getGameDir() is windows only!");
+ }
+ getVersion(): Promise<string> {
+ return new Promise((res, rej) => {
+ let output: string;
+ const child = require("child_process").execFile(
+ this.startCommand,
+ ["-v"],
+ function (err: Error, data: any) {
+ output = data.toString();
}
+ );
+ child.on("close", () => {
+ output = output.replace(this.versionRegEx, "$1");
+ res(output);
+ });
+ child.on("error", () => {
+ rej(new Error("Version check failed"));
+ });
+ });
+ }
+ isInstalled(): boolean {
+ return fs.existsSync(this.path + "/Mana.AppImage");
+ }
+ async updateAvailable(): Promise<{
+ isNewVersion: boolean;
+ newestVersion: string;
+ }> {
+ try {
+ let versions = await getRequest(
+ "https://tmw2.org/manalauncher/versions.json?" + Date.now()
+ );
+ let currect_version = (await this.isInstalled)
+ ? await this.getVersion()
+ : "-";
+ return {
+ isNewVersion: currect_version.indexOf(versions.AppImage.version) === -1,
+ newestVersion: versions.AppImage.version,
+ };
+ } catch (e) {
+ throw e;
}
- async update(): Promise<any> {
- fs.existsSync(app.getPath('userData') + "/temp") || fs.mkdirSync(app.getPath('userData') + "/temp");
- // Get Update URL
- Status.setProgress(500);
- Status.setProgress(-1);
- Status.setActivity("Fetching Download URL");
- let downloadURL;
- try {
- let versions = await getRequest("https://tmw2.org/manalauncher/versions.json?" + Date.now());
- downloadURL = versions.AppImage.file;
- } catch (e) {
- console.log(e);
- Status.showError("Download Url fetching error", e.message, `Download Url fetching error: ${e.message}`);
- throw new Error("Download Url fetching error");
- }
- Status.setProgress(-1);
+ }
+ async update(): Promise<any> {
+ fs.existsSync(app.getPath("userData") + "/temp") ||
+ fs.mkdirSync(app.getPath("userData") + "/temp");
+ // Get Update URL
+ Status.setProgress(500);
+ Status.setProgress(-1);
+ Status.setActivity("Fetching Download URL");
+ let downloadURL;
+ try {
+ let versions = await getRequest(
+ "https://tmw2.org/manalauncher/versions.json?" + Date.now()
+ );
+ downloadURL = versions.AppImage.file;
+ } catch (e) {
+ console.log(e);
+ Status.showError(
+ "Download Url fetching error",
+ e.message,
+ `Download Url fetching error: ${e.message}`
+ );
+ throw new Error("Download Url fetching error");
+ }
+ Status.setProgress(-1);
- const updateDestination: string = `${app.getPath('userData')}/temp/update.AppImage`;
+ const updateDestination: string = `${app.getPath(
+ "userData"
+ )}/temp/update.AppImage`;
- try {
- await download(downloadURL, updateDestination, (state: ProgressType) => {
- Status.setProgress(Math.floor(state.percent * 100));
- const speed = Math.floor(Math.floor(state.speed) / 1024);
- Status.setActivity(`Downloading ManaPlus... ${speed} KiB/s`);
- console.log(state);
- });
- } catch (e) {
- console.log(e);
- Status.showError("Download error", e.message, `Download error: ${e.message}`);
- throw new Error("Download error");
- }
- Status.setProgress(500);
+ try {
+ await download(downloadURL, updateDestination, (state: ProgressType) => {
+ Status.setProgress(Math.floor(state.percent * 100));
+ const speed = Math.floor(Math.floor(state.speed) / 1024);
+ Status.setActivity(`Downloading ManaPlus... ${speed} KiB/s`);
+ console.log(state);
+ });
+ } catch (e) {
+ console.log(e);
+ Status.showError(
+ "Download error",
+ e.message,
+ `Download error: ${e.message}`
+ );
+ throw new Error("Download error");
+ }
+ Status.setProgress(500);
- //IDEA: Check Integrity of the download
+ //IDEA: Check Integrity of the download
- // Backup old files
- Status.setActivity(`Backup Old version`);
- try {
- await fs.remove(this.path + '/Mana2.AppImage')
- if (fs.existsSync(this.path + '/Mana.AppImage'))
- await fs.move(this.path + '/Mana.AppImage', this.path + '/Mana2.AppImage');
- console.log("Backup old version done.");
- } catch (err) {
- Status.showError("Backup old version Failed", err.message, `Backup old version Failed: ${err.message}`);
- throw new Error("Backup error");
- }
+ // Backup old files
+ Status.setActivity(`Backup Old version`);
+ try {
+ await fs.remove(this.path + "/Mana2.AppImage");
+ if (fs.existsSync(this.path + "/Mana.AppImage"))
+ await fs.move(
+ this.path + "/Mana.AppImage",
+ this.path + "/Mana2.AppImage"
+ );
+ console.log("Backup old version done.");
+ } catch (err) {
+ Status.showError(
+ "Backup old version Failed",
+ err.message,
+ `Backup old version Failed: ${err.message}`
+ );
+ throw new Error("Backup error");
+ }
- Status.setProgress(500);
- Status.setActivity(`ManaPlus download completed. Instaling..`);
- try {
- console.log('Use chmod');
- const chmod = promisify(fs.chmod);
- await chmod(updateDestination, '755');
-
- console.log('Now move the thing!');
- await fs.move(updateDestination, this.path + '/Mana.AppImage');
- //await chmod(this.path + '/Mana.AppImage', '744');
- } catch (err) {
- console.log('Instalation error', err);
- Status.showError("Instalation failed", err ? err.message : 'undefined', `Instalation Failed: ${err ? err.message : 'undefined'}`);
- throw new Error("Instalation error");
- }
+ Status.setProgress(500);
+ Status.setActivity(`ManaPlus download completed. Instaling..`);
+ try {
+ console.log("Use chmod");
+ const chmod = promisify(fs.chmod);
+ await chmod(updateDestination, "755");
- Status.setActivity('Instalation completed');
+ console.log("Now move the thing!");
+ await fs.move(updateDestination, this.path + "/Mana.AppImage");
+ //await chmod(this.path + '/Mana.AppImage', '744');
+ } catch (err) {
+ console.log("Instalation error", err);
+ Status.showError(
+ "Instalation failed",
+ err ? err.message : "undefined",
+ `Instalation Failed: ${err ? err.message : "undefined"}`
+ );
+ throw new Error("Instalation error");
+ }
- //IDEA: Check Integrity of gamefiles
+ Status.setActivity("Instalation completed");
- Status.setActivity('Update successfull');
+ //IDEA: Check Integrity of gamefiles
- return 0;
- }
-} \ No newline at end of file
+ Status.setActivity("Update successfull");
+
+ return 0;
+ }
+}
diff --git a/src/main/manaplus/manaApp/manaApp.interface.ts b/src/main/manaplus/manaApp/manaApp.interface.ts
index a4fa795..c576f47 100644
--- a/src/main/manaplus/manaApp/manaApp.interface.ts
+++ b/src/main/manaplus/manaApp/manaApp.interface.ts
@@ -1,8 +1,8 @@
export interface ManaPlusApp {
- readonly startCommand:string,
- getGameDir():string,
- getVersion():Promise<string>,
- isInstalled():boolean,
- updateAvailable():Promise<{isNewVersion:boolean, newestVersion:string}>,
- update():Promise<any>
+ readonly startCommand: string;
+ getGameDir(): string;
+ getVersion(): Promise<string>;
+ isInstalled(): boolean;
+ updateAvailable(): Promise<{ isNewVersion: boolean; newestVersion: string }>;
+ update(): Promise<any>;
}
diff --git a/src/main/manaplus/manaApp/windows.ts b/src/main/manaplus/manaApp/windows.ts
index 293fc72..ed9e70c 100644
--- a/src/main/manaplus/manaApp/windows.ts
+++ b/src/main/manaplus/manaApp/windows.ts
@@ -1,70 +1,79 @@
-import { ManaPlusApp } from './manaApp.interface';
-import { app } from 'electron';
-import * as fs from 'fs-extra';
-import { Status } from '../../status';
-import {download, Progress as ProgressType} from '../../util/downloader';
-import * as extract from 'extract-zip';
-import { getRequest } from '../../util/webrequest';
-
+import { ManaPlusApp } from "./manaApp.interface";
+import { app } from "electron";
+import * as fs from "fs-extra";
+import { Status } from "../../status";
+import { download, Progress as ProgressType } from "../../util/downloader";
+import * as extract from "extract-zip";
+import { getRequest } from "../../util/webrequest";
export class ManaPlusAppWindows implements ManaPlusApp {
- private path:string;
- public readonly startCommand:string;
- versionRegEx:RegExp = /.*ManaPlus ([\d.]+) Windows.*/g;
- constructor(){
- const ManaPath = app.getPath('userData')+"\\manaplus";
+ private path: string;
+ public readonly startCommand: string;
+ versionRegEx: RegExp = /.*ManaPlus ([\d.]+) Windows.*/g;
+ constructor() {
+ const ManaPath = app.getPath("userData") + "\\manaplus";
fs.existsSync(ManaPath) || fs.mkdirSync(ManaPath);
- fs.existsSync(app.getPath('userData')+"\\temp") || fs.mkdirSync(app.getPath('userData')+"\\temp");
+ fs.existsSync(app.getPath("userData") + "\\temp") ||
+ fs.mkdirSync(app.getPath("userData") + "\\temp");
this.path = ManaPath;
- this.startCommand = this.path + "\\Mana\\manaplus.exe"
+ this.startCommand = this.path + "\\Mana\\manaplus.exe";
}
- getGameDir(): string {
- return this.path+"\\Mana\\";
- }
- getVersion(): Promise<string> {
+ getGameDir(): string {
+ return this.path + "\\Mana\\";
+ }
+ getVersion(): Promise<string> {
return new Promise((res, rej) => {
- let output:string;
- const child = require('child_process').execFile(this.startCommand, ['-v'], function(err:Error, data:any) {
- output = data.toString();
- });
- child.on('close', ()=>{
+ let output: string;
+ const child = require("child_process").execFile(
+ this.startCommand,
+ ["-v"],
+ function (err: Error, data: any) {
+ output = data.toString();
+ }
+ );
+ child.on("close", () => {
output = output.replace(this.versionRegEx, "$1");
res(output);
});
- child.on('error', ()=>{
+ child.on("error", () => {
rej(new Error("Version check failed"));
});
});
- }
+ }
isInstalled(): boolean {
- return fs.existsSync(this.path+"\\Mana\\manaplus.exe");
- }
+ return fs.existsSync(this.path + "\\Mana\\manaplus.exe");
+ }
async update() {
- fs.existsSync(app.getPath('userData')+"\\temp") || fs.mkdirSync(app.getPath('userData')+"\\temp");
- // Get Update URL
+ fs.existsSync(app.getPath("userData") + "\\temp") ||
+ fs.mkdirSync(app.getPath("userData") + "\\temp");
+ // Get Update URL
Status.setProgress(500);
Status.setActivity("Fetching Download URL");
let downloadURL;
try {
- let versions = await getRequest("https://tmw2.org/manalauncher/versions.json?"+Date.now());
+ let versions = await getRequest(
+ "https://tmw2.org/manalauncher/versions.json?" + Date.now()
+ );
downloadURL = versions.windows64.file;
- } catch (e){
+ } catch (e) {
console.log(e);
throw new Error("Download Url fetching error");
}
Status.setProgress(-1);
- const updateDestination:string = `${app.getPath('userData')}\\temp\\update.zip`;
+ const updateDestination: string = `${app.getPath(
+ "userData"
+ )}\\temp\\update.zip`;
try {
- await download(downloadURL, updateDestination, (state:ProgressType) => {
- Status.setProgress(Math.floor(state.percent*100));
- const speed = Math.floor(Math.floor(state.speed)/1024);
+ await download(downloadURL, updateDestination, (state: ProgressType) => {
+ Status.setProgress(Math.floor(state.percent * 100));
+ const speed = Math.floor(Math.floor(state.speed) / 1024);
Status.setActivity(`Downloading ManaPlus... ${speed} KiB/s`);
console.log(state);
});
- } catch (e){
+ } catch (e) {
console.log(e);
throw new Error("Download error");
}
@@ -74,22 +83,30 @@ export class ManaPlusAppWindows implements ManaPlusApp {
// Backup old files
Status.setActivity(`Backup Old version`);
try {
- await fs.remove(this.path+'\\Mana2')
- if(fs.existsSync(this.path+'\\Mana'))
- await fs.move(this.path+'\\Mana', this.path+'\\Mana2');
+ await fs.remove(this.path + "\\Mana2");
+ if (fs.existsSync(this.path + "\\Mana"))
+ await fs.move(this.path + "\\Mana", this.path + "\\Mana2");
console.log("Backup old version done.");
} catch (err) {
- Status.showError("Backup old version Failed", err.message, `Backup old version Failed: ${err.message}`);
+ Status.showError(
+ "Backup old version Failed",
+ err.message,
+ `Backup old version Failed: ${err.message}`
+ );
throw new Error("Backup error");
}
Status.setProgress(500);
Status.setActivity(`ManaPlus download completed. Unziping..`);
- const extraction = new Promise((resolve, reject)=>{
- extract(updateDestination, {dir: this.path }, function (err) {
- if(err){
+ const extraction = new Promise((resolve, reject) => {
+ extract(updateDestination, { dir: this.path }, function (err) {
+ if (err) {
console.log(err);
- Status.showError("ManaPlus unziping failed", err.message, `Unzip Failed: ${err.message}`);
+ Status.showError(
+ "ManaPlus unziping failed",
+ err.message,
+ `Unzip Failed: ${err.message}`
+ );
reject(new Error("Extraction Error"));
}
resolve();
@@ -97,38 +114,53 @@ export class ManaPlusAppWindows implements ManaPlusApp {
});
await extraction;
- Status.setActivity('Unziping completed');
+ Status.setActivity("Unziping completed");
//IDEA: Check Integrity of gamefiles
-
// DELETE Old File and remove update file
- Status.setActivity('Cleaning up (Deleting update files)');
+ Status.setActivity("Cleaning up (Deleting update files)");
try {
- await fs.remove(this.path+'\\Mana2')
- await fs.remove(updateDestination)
- console.log('Cleanup done');
+ await fs.remove(this.path + "\\Mana2");
+ await fs.remove(updateDestination);
+ console.log("Cleanup done");
} catch (err) {
console.error(err);
- Status.showError("Clean up Failed", "Please remove '"+updateDestination+"' and '"+'this.path'+'\\Mana2'+"' manualy", `Unzip Failed: ${err.message}`);
+ Status.showError(
+ "Clean up Failed",
+ "Please remove '" +
+ updateDestination +
+ "' and '" +
+ "this.path" +
+ "\\Mana2" +
+ "' manualy",
+ `Unzip Failed: ${err.message}`
+ );
}
Status.setProgress(-1);
//Status.showError("Unziping isn't implemented yet", "WIP", "not further implemented")
- Status.setActivity('Update successfull');
+ Status.setActivity("Update successfull");
return 0;
- }
- async updateAvailable(): Promise<{ isNewVersion: boolean; newestVersion: string; }> {
+ }
+ async updateAvailable(): Promise<{
+ isNewVersion: boolean;
+ newestVersion: string;
+ }> {
try {
- let versions = await getRequest("https://tmw2.org/manalauncher/versions.json?"+Date.now());
- let currect_version = await this.isInstalled ? await this.getVersion(): "-";
+ let versions = await getRequest(
+ "https://tmw2.org/manalauncher/versions.json?" + Date.now()
+ );
+ let currect_version = (await this.isInstalled)
+ ? await this.getVersion()
+ : "-";
return {
- isNewVersion:currect_version.indexOf(versions.windows64.version) === -1,
- newestVersion:versions.windows64.version
+ isNewVersion:
+ currect_version.indexOf(versions.windows64.version) === -1,
+ newestVersion: versions.windows64.version,
};
- }catch (e){
+ } catch (e) {
throw e;
}
-
- }
+ }
}