summaryrefslogtreecommitdiff
path: root/src/main/manaplus/manaApp/windows.ts
blob: 0728e3233e428224b519160e65534192415081ad (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
import { ManaPlusApp } from './manaApp.interface';
import { app } from 'electron';
//import * as path from 'path';
import * as fs from 'fs';
import { Status } from '../../status';
import {download, Progress as ProgressType} from '../../util/downloader';

export class ManaPlusAppWindows implements ManaPlusApp {
  private path:string;

  constructor(){
    const ManaPath = app.getPath('userData')+"\\manaplus";
    fs.existsSync(ManaPath) || fs.mkdirSync(ManaPath);
    fs.existsSync(app.getPath('userData')+"\\temp") || fs.mkdirSync(app.getPath('userData')+"\\temp");
    this.path = ManaPath;
  }
	run(parameters: string[]): void {

	}
	getGameDir(): string {
		return this.path;
	}
	getVersion(): Promise<string> {
		throw new Error("Not Installed.");
	}
  isInstalled(): boolean {
		return fs.existsSync(this.path+"\\Mana\\manaplus.exe");
	}

  async update() {
		// Get Update URL
    Status.setProgress(500);
    Status.setActivity("Fetching Download URL");
    //// TODO: Fetch update url
    Status.setProgress(-1);
    const downloadURL = 'https://[URL]/Mana.zip';
    try {
      await download(downloadURL, `${app.getPath('userData')}\\temp\\update.zip`, (state:ProgressType) => {
        Status.setProgress(Math.floor(state.percent*100));
        Status.setActivity(`Downloading ManaPlus... ${state.speed}`);
        console.log(state);
      });
    } catch (e){
      console.log(e);
      Status.showError("ManaPlus download failed", e.message, `DL Failed: ${e.message}`);
      throw new Error("Download Error");
    }
    Status.setProgress(100);
    Status.setActivity(`ManaPlus download completed`);
    Status.showError("Unziping isn't implemented yet", "WIP", "not further implemented")


    return 0;
	}
	updateAvailible(): Promise<{ isNewVersion: boolean; newestVersion: string; }> {
		throw new Error("Method not implemented.");
	}
}