1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
import { ManaPlusApp } from './ManaApp/manaApp.interface';
import { ManaPlusAppWindows } from './ManaApp/windows';
import * as os from 'os';
import * as path from 'path';
import * as fs from 'fs-extra';
import { app } from 'electron';
import { Status } from '../status';
let ManaPlusInstance:ManaPlusApp;
export namespace ManaPlus{
export const ERRORS = {
NOT_INITILIZED_YET_ERROR:new Error("The ManaPlus updater wasn't initilized")
}
export function init(){
if(os.platform() == "win32"){
ManaPlusInstance = new ManaPlusAppWindows();
console.log("GameDir:"+ManaPlusInstance.getGameDir());
}
}
export async function update(){
if(!wasInitilized())throw ERRORS.NOT_INITILIZED_YET_ERROR;
return await ManaPlusInstance.update();
}
export async function start(server: any,port: any,engine: any,username: any,password: any){
let params:string[];
try {
params = await makeParams(server,port,engine,username,password);
} catch (e){
console.log(e);
Status.showError("Launch Preperation Failed", e.message, "Launch preparation failed")
return;
}
let willUpdate:boolean=false;
// check if it is installed
willUpdate = !ManaPlusInstance.isInstalled();
//Check if update is availible and ask if the user wants to update
//TODO
// Install/Update the gameclient if needed
if(willUpdate){
await update();
}
//IDEA have client data updated here to, if needed
ManaPlusInstance.run(params);
}
}
function wasInitilized(){
return typeof(ManaPlusInstance) !== "undefined" && typeof(ManaPlusInstance) !== "undefined";
}
async function makeParams(server: any,port: any,engine: any,username?: any,password?: any):Promise<string[]>{
let parameters:string[] = [];
if(server && engine && port){
parameters.push(...[
"-s", server,
"-y", engine,
"-p", port
]);
if(username && password){
parameters.push(...[
"-U", username,
"-P", password
]);
}
}
// Setup Paths and stuff
const configDir = path.normalize(app.getPath('userData')+"/mana_config");
const localDataDir = path.normalize(app.getPath('userData')+"/mana_local_data");
const screenshotsDir = path.normalize(app.getPath('userData')+`/screenshots/${server}`);
await fs.ensureDir(configDir);
await fs.ensureDir(localDataDir);
await fs.ensureDir(screenshotsDir);
parameters.push(...[
"-C", configDir,
"-L", localDataDir,
"--screenshot-dir", screenshotsDir
]);
console.log(parameters);
return parameters;
}
|