summaryrefslogtreecommitdiff
path: root/src/main/manaplus/manaplus.ts
blob: dfa86a73453d0908c1dca7648b79d5aebded4e24 (plain) (blame)
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
import { ManaPlusApp } from './ManaApp/manaApp.interface';
import { ManaPlusAppWindows } from './ManaApp/windows';
import * as os from 'os';

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,engine: any,port: any,username: any,password: any){

    const params = makeParams(server,engine,port,username,password);
    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";
}

function makeParams(server: any,engine: any,port: any,username: any,password: any):string[]{
    // TODO check if everything is there
    var parameters = [
      "-s"+server,
      "-y"+engine,
      "-p"+port,
      "-U"+username,
      "-P"+password,
    ];
    // TODO make this function real
    return [];
}