summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLawnCable <lawncable.tmw2@simonlaux.de>2018-06-11 18:03:42 +0200
committerLawnCable <lawncable.tmw2@simonlaux.de>2018-06-11 18:03:42 +0200
commite8cbdff4ee7d3f04ec1481ed235d2e7edcff4fee (patch)
treefe6cd382c741402e98a87291c2aa25c5acd7b574
parent3b993aaddd032d33882881fed4468314bc8ca256 (diff)
downloadelectron-e8cbdff4ee7d3f04ec1481ed235d2e7edcff4fee.tar.gz
electron-e8cbdff4ee7d3f04ec1481ed235d2e7edcff4fee.tar.bz2
electron-e8cbdff4ee7d3f04ec1481ed235d2e7edcff4fee.tar.xz
electron-e8cbdff4ee7d3f04ec1481ed235d2e7edcff4fee.zip
Update for Windows is now working
-rw-r--r--src/main.ts2
-rw-r--r--src/main/manaplus/manaApp/manaApp.interface.ts2
-rw-r--r--src/main/manaplus/manaApp/windows.ts45
-rw-r--r--src/main/richpresence.ts2
-rw-r--r--src/main/util/webrequest.ts35
-rw-r--r--src/renderer/gameserver/data.ts2
6 files changed, 77 insertions, 11 deletions
diff --git a/src/main.ts b/src/main.ts
index 0f60c34..9df2c55 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -156,7 +156,7 @@ ManaPlus.init();
ipcMain.on('play', async (event:any, arg:any) => {
if(Status.getStatus().playing)return;
- console.log("play", arg);
+ //console.log("play", arg);
Status.setPlaying(true);
await ManaPlus.start(arg);
//Status.showError("Failed To Launch Mana Plus","Not implemented yet!","Launch Manaplus faild: Not Implemented");
diff --git a/src/main/manaplus/manaApp/manaApp.interface.ts b/src/main/manaplus/manaApp/manaApp.interface.ts
index 4db7c15..a4fa795 100644
--- a/src/main/manaplus/manaApp/manaApp.interface.ts
+++ b/src/main/manaplus/manaApp/manaApp.interface.ts
@@ -3,6 +3,6 @@ export interface ManaPlusApp {
getGameDir():string,
getVersion():Promise<string>,
isInstalled():boolean,
- updateAvailible():Promise<{isNewVersion:boolean, newestVersion:string}>,
+ 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 92acb7f..832a140 100644
--- a/src/main/manaplus/manaApp/windows.ts
+++ b/src/main/manaplus/manaApp/windows.ts
@@ -4,11 +4,13 @@ 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";
fs.existsSync(ManaPath) || fs.mkdirSync(ManaPath);
@@ -21,7 +23,19 @@ export class ManaPlusAppWindows implements ManaPlusApp {
return this.path+"\\Mana\\";
}
getVersion(): Promise<string> {
- throw new Error("Not Implemented yet");
+ 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\\manaplus.exe");
@@ -32,20 +46,27 @@ export class ManaPlusAppWindows implements ManaPlusApp {
// Get Update URL
Status.setProgress(500);
Status.setActivity("Fetching Download URL");
- //// TODO: Fetch update url
+ let downloadURL;
+ try {
+ let versions = await getRequest("https://tmw2.org/manalauncher/versions.json?"+Date.now());
+ downloadURL = versions.windows64.file;
+ } catch (e){
+ console.log(e);
+ throw new Error("Download Url fetching error");
+ }
Status.setProgress(-1);
- const downloadURL = 'https://[URL]/Mana.zip';
const updateDestination:string = `${app.getPath('userData')}\\temp\\update.zip`;
try {
await download(downloadURL, updateDestination, (state:ProgressType) => {
Status.setProgress(Math.floor(state.percent*100));
- Status.setActivity(`Downloading ManaPlus... ${state.speed}`);
+ const speed = Math.floor(Math.floor(state.speed)/1024);
+ Status.setActivity(`Downloading ManaPlus... ${speed} KiB/s`);
console.log(state);
});
} catch (e){
console.log(e);
-
+ throw new Error("Download error");
}
Status.setProgress(500);
// Backup old files
@@ -95,7 +116,17 @@ export class ManaPlusAppWindows implements ManaPlusApp {
return 0;
}
- updateAvailible(): Promise<{ isNewVersion: boolean; newestVersion: string; }> {
- throw new Error("Method not implemented.");
+ 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.windows64.version) === -1,
+ newestVersion:versions.windows64.version
+ };
+ }catch (e){
+ throw e;
+ }
+
}
}
diff --git a/src/main/richpresence.ts b/src/main/richpresence.ts
index f39341b..4ef8f42 100644
--- a/src/main/richpresence.ts
+++ b/src/main/richpresence.ts
@@ -20,7 +20,7 @@ async function setActivity() {
// smallImageKey: 'snek_small',
// smallImageText: 'i am my own pillows',
partySize:2, //TODO get online players
- partyMax:100,
+ partyMax:999,
partyId:"ae488379-351d-4a4f-ad32-2b9b01c91657",
joinSecret:"MTI4NzM0OjFpMmhuZToxMjMxMjM="
});
diff --git a/src/main/util/webrequest.ts b/src/main/util/webrequest.ts
new file mode 100644
index 0000000..aba8bfd
--- /dev/null
+++ b/src/main/util/webrequest.ts
@@ -0,0 +1,35 @@
+import * as https from 'https';
+import * as http from 'http';
+
+export function getRequest(url:string):Promise<any> {
+ const webrequest:any = url.indexOf('https') !== -1 ? https:http;
+ const t1 = Date.now();
+ return new Promise((resolve, reject) => {
+ webrequest.get(url, (res:any) => {
+ const { statusCode } = res;
+
+ let error;
+ if (statusCode !== 200) {
+ error = new Error('Request Failed.\n' +
+ `Status Code: ${statusCode}`);
+ }
+ if (error) {
+ res.resume();
+ reject(error);
+ } else {
+ res.setEncoding('utf8');
+ let rawData = '';
+ res.on('data', (chunk:any) => { rawData += chunk; });
+ res.on('end', () => {
+ try {
+ resolve(JSON.parse(rawData));
+ } catch (e) {
+ reject(e);
+ }
+ });
+ }
+ }).on('error', (e:Error) => {
+ reject(e);
+ });
+ });
+}
diff --git a/src/renderer/gameserver/data.ts b/src/renderer/gameserver/data.ts
index 570fdb2..92cf250 100644
--- a/src/renderer/gameserver/data.ts
+++ b/src/renderer/gameserver/data.ts
@@ -13,7 +13,7 @@ const TMW2 = new GameServer(
"TMW2"
),
"TMW2",
- "TMW2: Monster Wars",
+ "TMW2: Moubootaur Legends",
"What happens if you mix TMW with Evol and add many new Ideas",
"https://tmw2.org/news",
{url:"http://updates.tmw2.org/news.txt",type:NewsType.ManaPlus},