summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLawnCable <git@lawncable.net>2021-03-01 00:24:52 +0100
committerLawnCable <git@lawncable.net>2021-03-01 00:24:52 +0100
commit54b187e1fd43e4b74e8f015f9c7d9ad84fd22034 (patch)
tree6164c355848290390d6ad482c7d55718778d706b
parentf781beecbc13ad5166dddfc65cbabda68dd1e219 (diff)
downloadelectron-54b187e1fd43e4b74e8f015f9c7d9ad84fd22034.tar.gz
electron-54b187e1fd43e4b74e8f015f9c7d9ad84fd22034.tar.bz2
electron-54b187e1fd43e4b74e8f015f9c7d9ad84fd22034.tar.xz
electron-54b187e1fd43e4b74e8f015f9c7d9ad84fd22034.zip
move out static paths to constants file
to have them at a central place (mainly to weaken the electron dependency in those files)
-rw-r--r--src/main/manaplus/manaApp/linux.ts22
-rw-r--r--src/main/manaplus/manaApp/windows.ts22
-rw-r--r--src/main/manaplus/manaplus.ts28
-rw-r--r--src/main/util/app_constants.ts14
4 files changed, 51 insertions, 35 deletions
diff --git a/src/main/manaplus/manaApp/linux.ts b/src/main/manaplus/manaApp/linux.ts
index 1a5d828..de48938 100644
--- a/src/main/manaplus/manaApp/linux.ts
+++ b/src/main/manaplus/manaApp/linux.ts
@@ -1,5 +1,4 @@
import { ManaPlusApp } from "./manaApp.interface";
-import { app } from "electron";
import * as fs from "fs-extra";
import { Status } from "../../status";
import { download, Progress as ProgressType } from "../../util/downloader";
@@ -9,16 +8,21 @@ import {
getVersionInfoForPlatform,
updateAvailable,
} from "./shared";
+import {
+ getTempPath,
+ getManaPlusPath,
+ getUserDataPath,
+} from "../../util/app_constants";
+import { join } from "path";
export class ManaPlusAppLinux implements ManaPlusApp {
private path: string;
startCommand: string;
versionRegEx: RegExp = /.*ManaPlus ([\d.]+) Linux.*/g; //TODO
constructor() {
- const ManaPath = app.getPath("userData") + "/manaplus";
+ const ManaPath = getManaPlusPath();
fs.existsSync(ManaPath) || fs.mkdirSync(ManaPath);
- fs.existsSync(app.getPath("userData") + "/temp") ||
- fs.mkdirSync(app.getPath("userData") + "/temp");
+ fs.existsSync(getTempPath()) || fs.mkdirSync(getTempPath());
this.path = ManaPath;
this.startCommand = ManaPath + "/Mana.AppImage";
}
@@ -38,8 +42,7 @@ export class ManaPlusAppLinux implements ManaPlusApp {
return updateAvailable("AppImage", this);
}
async update(): Promise<any> {
- fs.existsSync(app.getPath("userData") + "/temp") ||
- fs.mkdirSync(app.getPath("userData") + "/temp");
+ fs.existsSync(getTempPath()) || fs.mkdirSync(getTempPath());
// Get Update URL
Status.setProgress(500);
Status.setProgress(-1);
@@ -58,9 +61,10 @@ export class ManaPlusAppLinux implements ManaPlusApp {
}
Status.setProgress(-1);
- const updateDestination: string = `${app.getPath(
- "userData"
- )}/temp/update.AppImage`;
+ const updateDestination: string = join(
+ getUserDataPath(),
+ "/temp/update.AppImage"
+ );
try {
await download(downloadURL, updateDestination, (state: ProgressType) => {
diff --git a/src/main/manaplus/manaApp/windows.ts b/src/main/manaplus/manaApp/windows.ts
index 7bf5adb..a8a0ebd 100644
--- a/src/main/manaplus/manaApp/windows.ts
+++ b/src/main/manaplus/manaApp/windows.ts
@@ -1,5 +1,4 @@
import { ManaPlusApp } from "./manaApp.interface";
-import { app } from "electron";
import * as fs from "fs-extra";
import { Status } from "../../status";
import { download, Progress as ProgressType } from "../../util/downloader";
@@ -9,16 +8,21 @@ import {
getVersionInfoForPlatform,
updateAvailable,
} from "./shared";
+import {
+ getTempPath,
+ getManaPlusPath,
+ getUserDataPath,
+} from "../../util/app_constants";
+import { join } from "path";
export class ManaPlusAppWindows implements ManaPlusApp {
private path: string;
public readonly startCommand: string;
versionRegEx: RegExp = /.*ManaPlus ([\d.]+) Windows.*/g;
constructor() {
- const ManaPath = app.getPath("userData") + "\\manaplus";
+ const ManaPath = getManaPlusPath();
fs.existsSync(ManaPath) || fs.mkdirSync(ManaPath);
- fs.existsSync(app.getPath("userData") + "\\temp") ||
- fs.mkdirSync(app.getPath("userData") + "\\temp");
+ fs.existsSync(getTempPath()) || fs.mkdirSync(getTempPath());
this.path = ManaPath;
this.startCommand = this.path + "\\Mana\\manaplus.exe";
}
@@ -34,8 +38,7 @@ export class ManaPlusAppWindows implements ManaPlusApp {
}
async update() {
- fs.existsSync(app.getPath("userData") + "\\temp") ||
- fs.mkdirSync(app.getPath("userData") + "\\temp");
+ fs.existsSync(getTempPath()) || fs.mkdirSync(getTempPath());
// Get Update URL
Status.setProgress(500);
Status.setActivity("Fetching Download URL");
@@ -48,9 +51,10 @@ export class ManaPlusAppWindows implements ManaPlusApp {
}
Status.setProgress(-1);
- const updateDestination: string = `${app.getPath(
- "userData"
- )}\\temp\\update.zip`;
+ const updateDestination: string = join(
+ getUserDataPath(),
+ "\\temp\\update.zip"
+ );
try {
await download(downloadURL, updateDestination, (state: ProgressType) => {
Status.setProgress(Math.floor(state.percent * 100));
diff --git a/src/main/manaplus/manaplus.ts b/src/main/manaplus/manaplus.ts
index 981c7d5..96cbbd3 100644
--- a/src/main/manaplus/manaplus.ts
+++ b/src/main/manaplus/manaplus.ts
@@ -1,11 +1,12 @@
import { ManaPlusApp } from "./manaApp/manaApp.interface";
import { ManaPlusAppWindows } from "./manaApp/windows";
import * as os from "os";
-import * as path from "path";
+import { join } from "path";
import * as fs from "fs-extra";
-import { app, ipcMain, shell, dialog } from "electron";
+import { ipcMain, shell, dialog } from "electron";
import { Status, EventEmitter } from "../status";
import { ManaPlusAppLinux } from "./manaApp/linux";
+import { getUserDataPath } from "../util/app_constants";
let ManaPlusInstance: ManaPlusApp;
@@ -113,9 +114,7 @@ please check you network connection first.",
}
ipcMain.on("getScreenshots", (event: any, arg: string) => {
- const screenshotsDir = path.normalize(
- app.getPath("userData") + `/screenshots/${arg}/`
- );
+ const screenshotsDir = join(getUserDataPath(), "/screenshots/", `${arg}/`);
fs.existsSync(screenshotsDir) || fs.mkdirSync(screenshotsDir);
fs.readdir(screenshotsDir, (err, dir) => {
let screenshots: string[] = [];
@@ -131,9 +130,7 @@ ipcMain.on("getScreenshots", (event: any, arg: string) => {
EventEmitter.on("Mana:openScreenshotDir", () => {
shell.openItem(
- path.normalize(
- app.getPath("userData") + `/screenshots/${CurrentServer.address}/`
- )
+ join(getUserDataPath(), `/screenshots/${CurrentServer.address}/`)
);
});
@@ -159,13 +156,9 @@ async function makeParams(
}
}
// 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}`
- );
+ const configDir = join(getUserDataPath(), "/mana_config");
+ const localDataDir = join(getUserDataPath(), "/mana_local_data");
+ const screenshotsDir = join(getUserDataPath(), `/screenshots/${server}`);
await fs.ensureDir(configDir);
await fs.ensureDir(localDataDir);
await fs.ensureDir(screenshotsDir);
@@ -249,8 +242,9 @@ const default_server_config =
const parseString = require("xml2js").parseString,
xml2js = require("xml2js");
async function setSkipUpdateWindows(server: string) {
- const serverConfigXML = path.normalize(
- app.getPath("userData") + `/mana_config/${server}/config.xml`
+ const serverConfigXML = join(
+ getUserDataPath(),
+ `/mana_config/${server}/config.xml`
);
if (fs.existsSync(serverConfigXML)) {
diff --git a/src/main/util/app_constants.ts b/src/main/util/app_constants.ts
new file mode 100644
index 0000000..99f22da
--- /dev/null
+++ b/src/main/util/app_constants.ts
@@ -0,0 +1,14 @@
+import { app } from "electron";
+import { join } from "path";
+
+export function getUserDataPath() {
+ return app.getPath("userData");
+}
+
+export function getManaPlusPath() {
+ return join(getUserDataPath(), "/manaplus/");
+}
+
+export function getTempPath() {
+ return join(getUserDataPath(), "/temp/");
+}