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 []; }