summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLawnCable <lawncable.tmw2@simonlaux.de>2018-06-21 00:31:19 +0200
committerLawnCable <lawncable.tmw2@simonlaux.de>2018-06-21 00:31:19 +0200
commit8c63737d25bce9bcd5d7dc33f9fc1bb5cd1b9c24 (patch)
tree8141212c7934a4509ccdc3e9354e5f7459239d57
parentf1960f5154acc8a8791fcb4094c462a3b5abdbef (diff)
downloadelectron-8c63737d25bce9bcd5d7dc33f9fc1bb5cd1b9c24.tar.gz
electron-8c63737d25bce9bcd5d7dc33f9fc1bb5cd1b9c24.tar.bz2
electron-8c63737d25bce9bcd5d7dc33f9fc1bb5cd1b9c24.tar.xz
electron-8c63737d25bce9bcd5d7dc33f9fc1bb5cd1b9c24.zip
Auto skip the update dialog
-rw-r--r--package-lock.json21
-rw-r--r--package.json3
-rw-r--r--src/main/manaplus/manaplus.ts62
3 files changed, 81 insertions, 5 deletions
diff --git a/package-lock.json b/package-lock.json
index 819a00c..cda0f9f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1659,6 +1659,11 @@
"truncate-utf8-bytes": "1.0.2"
}
},
+ "sax": {
+ "version": "1.2.4",
+ "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
+ "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
+ },
"semver": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz",
@@ -1964,6 +1969,22 @@
"safe-buffer": "5.1.2"
}
},
+ "xml2js": {
+ "version": "0.4.19",
+ "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz",
+ "integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==",
+ "requires": {
+ "sax": "1.2.4",
+ "xmlbuilder": "9.0.7"
+ },
+ "dependencies": {
+ "xmlbuilder": {
+ "version": "9.0.7",
+ "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz",
+ "integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0="
+ }
+ }
+ },
"xmlbuilder": {
"version": "8.2.2",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-8.2.2.tgz",
diff --git a/package.json b/package.json
index b66919c..53aef23 100644
--- a/package.json
+++ b/package.json
@@ -32,6 +32,7 @@
"extract-zip": "^1.6.6",
"fs-extra": "^6.0.1",
"request": "^2.87.0",
- "request-progress": "^3.0.0"
+ "request-progress": "^3.0.0",
+ "xml2js": "^0.4.19"
}
}
diff --git a/src/main/manaplus/manaplus.ts b/src/main/manaplus/manaplus.ts
index 5396649..9183b94 100644
--- a/src/main/manaplus/manaplus.ts
+++ b/src/main/manaplus/manaplus.ts
@@ -73,7 +73,7 @@ export namespace ManaPlus{
Status.setGameRunning(true);
EventEmitter.emit('closeWindow');
EventEmitter.emit('openTray');
- await runManaProgram(params,ManaPlusInstance.startCommand);
+ await runManaProgram(params,ManaPlusInstance.startCommand,args.address);
// On Close
Status.setGameRunning(false);
Status.setPlaying(false);
@@ -129,7 +129,7 @@ async function makeParams(server: any,port: any,engine: any,username?: any,passw
parameters.push(...[
"-C", configDir,
"-L", localDataDir,
- "--screenshot-dir", screenshotsDir
+ "--screenshot-dir", screenshotsDir,
]);
//console.log(parameters);
@@ -138,8 +138,12 @@ async function makeParams(server: any,port: any,engine: any,username?: any,passw
let manaplusInstance: any=null;
-function runManaProgram(parameters: string[],gameExe:string): Promise<any> {
- return new Promise((resolve, reject)=>{
+function runManaProgram(parameters: string[],gameExe:string,server?:string): Promise<any> {
+ return new Promise(async(resolve, reject)=>{
+ if(server){
+ Status.setActivity(`Preparing Launch`);
+ await setSkipUpdateWindows(server);
+ }
Status.setActivity(`Starting ManaPlus`);
//console.log(gameExe, parameters);
@@ -185,3 +189,53 @@ function dialogPromiseWrapper(options:any):Promise<number>{
})
});
}
+
+const default_server_config = '<?xml version="1.0"?>\
+<configuration>\
+ <option name="updateType" value="1"/>\
+ <list name="player"/>\
+</configuration>';
+const parseString = require('xml2js').parseString, xml2js = require('xml2js');
+async function setSkipUpdateWindows(server:string){
+ const serverConfigXML = path.normalize(app.getPath('userData')+`/mana_config/${server}/config.xml`);
+
+ if(fs.existsSync(serverConfigXML)){
+ //add to this file
+ try{
+ let data = await fs.readFile(serverConfigXML, 'utf8');
+ data = await editXML(data);
+ await fs.outputFile(serverConfigXML, data);
+ } catch (err){
+ console.log(err);
+ }
+
+ }else{
+ //create the file
+ fs.outputFile(serverConfigXML, default_server_config);
+ }
+
+ return;
+}
+
+function editXML(xml:string):Promise<string>{
+ return new Promise((res, rej)=>{
+ parseString(xml, function(err:any, result:any){
+ if(err) console.log(err);
+
+ var json = result;
+ const updaterVar = json.configuration.option.find((item:any)=>item.$.name=="updateType");
+ if(updaterVar){
+ if(updaterVar.$.value === 1){
+ return rej(new Error("Has allready the right value"));
+ }
+ updaterVar.$.value = 1;
+ }else{
+ json.configuration.option.push({$:{name:"updateType",value:1}});
+ }
+
+ var builder = new xml2js.Builder();
+ res(builder.buildObject(json));
+
+ });
+ });
+}