diff --git a/entry.js b/entry.js
index 425f615..60e2567 100644
--- a/entry.js
+++ b/entry.js
@@ -5,14 +5,15 @@ const {
Notification,
shell,
nativeImage,
- nativeTheme
+ nativeTheme,
+ dialog
} = require('electron');
const path = require('path');
require('electron-store').initRenderer();
-let mainWindow, analyticsWindow;
+let mainWindow, analyticsWindow, settingsWindow;
ipcMain.handle('hide-window', () => mainWindow.hide());
ipcMain.handle('show-window', () => mainWindow.show());
@@ -26,7 +27,7 @@ ipcMain.on('notification', (event, args) => {
ipcMain.on('is-window-dark', (e) => e.returnValue = nativeTheme.shouldUseDarkColors);
ipcMain.handle('open-settings', () => {
- const settingsWindow = new BrowserWindow ({
+ settingsWindow = new BrowserWindow ({
width: 900,
height: 600,
webPreferences: {
@@ -120,6 +121,16 @@ app.whenReady().then(() => {
mainWindow.webContents.send('change-voicepack');
});
+ ipcMain.on('prefix-con', async () => {
+ const result = await dialog.showOpenDialog({ properties: ['openDirectory'] });
+ if(result.filePaths.length == 0) return;
+ mainWindow.webContents.send('change-prefix', { 'dir': result.filePaths[0] });
+ });
+
+ ipcMain.on('prefix-changed', async () => {
+ settingsWindow.webContents.send('prefix-changed');
+ });
+
ipcMain.on('rpc-toggle', () => mainWindow.webContents.send('rpc-toggle'));
});
diff --git a/public/html/settings.html b/public/html/settings.html
index 91bac00..1fb5e96 100644
--- a/public/html/settings.html
+++ b/public/html/settings.html
@@ -112,6 +112,12 @@
+
+ empty
+
+
+
+
System
diff --git a/src/ts/index.ts b/src/ts/index.ts
index 0f0909c..fdf0309 100644
--- a/src/ts/index.ts
+++ b/src/ts/index.ts
@@ -13,12 +13,13 @@ import LauncherLib from './lib/LauncherLib';
import LauncherUI from './lib/LauncherUI';
import Tools from './lib/Tools';
import DiscordRPC from './lib/DiscordRPC';
+import PrefixSelector from './lib/PrefixSelector';
import SwitcherooControl from './lib/SwitcherooControl';
const launcher_version = require('../../package.json').version;
-if (!fs.existsSync(constants.prefixDir))
- fs.mkdirSync(constants.prefixDir, { recursive: true });
+if (!fs.existsSync(LauncherLib.getConfig('prefix')))
+ fs.mkdirSync(LauncherLib.getConfig('prefix'), { recursive: true });
if (!fs.existsSync(constants.runnersDir))
fs.mkdirSync(constants.runnersDir, { recursive: true });
@@ -59,6 +60,12 @@ $(() => {
LauncherUI.updateLauncherState();
});
+ ipcRenderer.on('change-prefix', (event: void, data: any) => {
+ PrefixSelector.set(data.dir);
+ LauncherUI.updateLauncherState();
+ ipcRenderer.send('prefix-changed');
+ });
+
Tools.getGitTags(constants.uri.launcher).then(tags => {
const latestVersion = tags[tags.length - 1].tag;
diff --git a/src/ts/lib/LauncherLib.ts b/src/ts/lib/LauncherLib.ts
index 46db0b3..4ec68e0 100644
--- a/src/ts/lib/LauncherLib.ts
+++ b/src/ts/lib/LauncherLib.ts
@@ -27,6 +27,7 @@ const config = new store ({
file: null
},
version: null, // Installed game version
+ prefix: path.join(os.homedir(), '.local', 'share', 'anime-game-launcher', 'game'), // Default Prefix
patch: null, // Installed patch info ({ version, state } - related game's version and patch's state)
runner: null, // Selected runner ({ folder, executable })
rpc: false, // Discord RPC
diff --git a/src/ts/lib/PrefixSelector.ts b/src/ts/lib/PrefixSelector.ts
new file mode 100644
index 0000000..16a214e
--- /dev/null
+++ b/src/ts/lib/PrefixSelector.ts
@@ -0,0 +1,55 @@
+const fs = require('fs');
+import LauncherLib from "./LauncherLib";
+const path = require('path');
+const os = require('os');
+
+export default class PrefixSelector
+{
+ protected static prefix: string = LauncherLib.getConfig('prefix');
+
+ public static set(location: string) {
+ if (this.prefix == location) return console.log('Can\'t set already selected prefix as new prefix');
+
+ if (fs.existsSync(path.join(location, 'drive_c', 'Program Files', 'Genshin Impact', 'GenshinImpact_Data', 'Persistent'))) {
+ const version = fs.readFileSync(path.join(location, 'drive_c', 'Program Files', 'Genshin Impact', 'GenshinImpact_Data', 'Persistent', 'ScriptVersion'), { encoding: 'UTF-8' }).toString();
+
+ LauncherLib.updateConfig('version', version);
+ LauncherLib.updateConfig('prefix', location);
+ this.prefix = location;
+ } else if (fs.existsSync(path.join(location, 'drive_c', 'Program Files', 'Genshin Impact', 'GenshinImpact_Data', 'globalgamemanagers'))) {
+ const config = fs.readFileSync(path.join(location, 'drive_c', 'Program Files', 'Genshin Impact', 'GenshinImpact_Data', 'globalgamemanagers'), { encoding: 'ascii' });
+ const version = /([1-9]+\.[0-9]+\.[0-9]+)_[\d]+_[\d]+/.exec(config)![1];
+ console.log(version);
+ LauncherLib.updateConfig('prefix', location);
+ this.prefix = location;
+ } else {
+ console.log('Game not found.');
+
+ // Unset version if game is not found.
+ LauncherLib.updateConfig('version', null);
+ LauncherLib.updateConfig('prefix', location);
+ this.prefix = location;
+ }
+ }
+
+ public static Default() {
+ const dp = path.join(os.homedir(), '.local', 'share', 'anime-game-launcher', 'game');
+
+ if (this.prefix == dp) return console.log('Can\'t set already selected prefix as new prefix');
+
+ if (fs.existsSync(path.join(dp, 'drive_c', 'Program Files', 'Genshin Impact', 'GenshinImpact_Data', 'Persistent'))) {
+ const version = fs.readFileSync(path.join(dp, 'drive_c', 'Program Files', 'Genshin Impact', 'GenshinImpact_Data', 'Persistent', 'ScriptVersion'), { encoding: 'UTF-8' }).toString();
+ console.log(version);
+ } else if (fs.existsSync(path.join(dp, 'drive_c', 'Program Files', 'Genshin Impact', 'GenshinImpact_Data', 'globalgamemanagers'))) {
+ const config = fs.readFileSync(path.join(dp, 'drive_c', 'Program Files', 'Genshin Impact', 'GenshinImpact_Data', 'globalgamemanagers'), { encoding: 'ascii' });
+ const version = /([1-9]+\.[0-9]+\.[0-9]+)_[\d]+_[\d]+/.exec(config)![1];
+ console.log(version);
+ } else {
+ console.log('Game not found.');
+
+ // Unset version if game is not found.
+ LauncherLib.updateConfig('version', null);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/ts/settings.ts b/src/ts/settings.ts
index 71104af..3328ded 100644
--- a/src/ts/settings.ts
+++ b/src/ts/settings.ts
@@ -54,6 +54,20 @@ $(() => {
}
});
+ /**
+ * Prefix
+ */
+
+ $('#prefixloc span').text(LauncherLib.getConfig('prefix'));
+
+ ipcRenderer.on('prefix-changed', () => {
+ $('#prefixloc span').text(LauncherLib.getConfig('prefix'));
+ })
+
+ $('#prefixloc #prefixdir').on('click', () => {
+ ipcRenderer.send('prefix-con');
+ })
+
/**
* Game voice language
*/