summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/manaplus/manaplus.ts62
1 files changed, 58 insertions, 4 deletions
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));
+
+ });
+ });
+}