mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-24 02:28:15 +03:00
Completed most of the stuff
This commit is contained in:
parent
08b0fcfa51
commit
022fd6578b
6 changed files with 99 additions and 5 deletions
17
entry.js
17
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'));
|
||||
});
|
||||
|
||||
|
|
|
@ -112,6 +112,12 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="prefixloc">
|
||||
<span id="setprefix">empty</span>
|
||||
|
||||
<button class="button" id="prefixdir" i18id="ChangePrefix">Change Prefix</button>
|
||||
</div>
|
||||
|
||||
<div class="selected-item">
|
||||
<span>System</span>
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
55
src/ts/lib/PrefixSelector.ts
Normal file
55
src/ts/lib/PrefixSelector.ts
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue