This repository has been archived by the owner on Sep 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathutilities.ts
110 lines (94 loc) · 3.23 KB
/
utilities.ts
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { dialog, app } from "electron";
import fs from "fs";
import process from "process";
import path from "path";
import ProgressBar from "electron-progressbar";
import log from "electron-log";
import { Install } from "./mod_list_loader";
const loadingTextStyle = {
color: "ghostwhite"
};
class Utilities {
/**
* Create an error dialog and print the error to the log files.
* @param error The error object/message.
* @param title Title for the error dialog.
*/
public static ErrorDialog(error: any, title: string): any {
log.error(`Error Dialog shown: ${title} : ${error.toString()}`);
//@ts-ignore
dialog.showMessageBox(global.mainWindow, {
type: "error",
title: title,
message: error.toString(),
buttons: ["OK"]
});
}
/**
* Get the data folder dynamically based on the platform.
*/
public static GetDataFolder(): string {
const _path = (process.env.APPDATA || (process.platform == "darwin" ? process.env.HOME + "/Library/Preferences" : process.env.HOME + "/.local/share")) + "/creators-tf-launcher";
if (!fs.existsSync(_path)) {
fs.mkdirSync(_path);
}
return _path;
}
static GetLogsFolder(): string {
return log.transports.file.getFile().path;
}
static GetNewLoadingPopup(title: string, mainWindow: any, onCanceled: () => void): any {
const progressBar = new ProgressBar({
text: title,
detail: "...",
browserWindow: {
webPreferences: {
nodeIntegration: true
},
parent: mainWindow,
modal: true,
title: title,
backgroundColor: "#2b2826",
closable: true
},
style: {
text: loadingTextStyle,
detail: loadingTextStyle,
value: loadingTextStyle
}
}, app);
progressBar.on("aborted", onCanceled);
return progressBar;
}
public static currentLauncherVersion: string;
public static GetCurrentVersion(): string {
if (this.currentLauncherVersion == null) {
try {
const packageJson = fs.readFileSync(path.join(__dirname, "..", "..", "package.json"));
this.currentLauncherVersion = JSON.parse(packageJson.toString()).version;
}
catch {
return null;
}
}
return this.currentLauncherVersion;
}
//Find which element in an Install[] has the desiredCollectionString as an argument
public static FindCollectionNumber(Installs: Install[], desiredCollectionString: string): number {
if (typeof(desiredCollectionString) == "undefined") {
return 0;
}
if(Installs.length < 2) {
//It has a single item
return 0;
}
for (let i = 0; i < Installs.length; i++) {
const element = Installs[i];
if (element.itemname == desiredCollectionString) {
//We've found it!
return i;
}
}
}
}
export default Utilities;