API improvements

- added `folders` field in config file
  and now you can specify some pathes
- added `constants.paths.tempDir` field
This commit is contained in:
Observer KRypt0n_ 2022-01-06 15:46:49 +02:00
parent 4c5d08ba13
commit 3904a86381
No known key found for this signature in database
GPG key ID: DC5D4EC1303465DA
6 changed files with 67 additions and 17 deletions

View file

@ -10,13 +10,29 @@ promisify(async () => {
'en-us' 'en-us'
] ]
}, },
/** folders: {
* Path to wine prefix /**
* * Path to wine prefix
* @default constants.paths.prefix.default *
*/ * @default "~/.local/share/anime-game-launcher"
prefix: await constants.paths.prefix.default, */
prefix: await constants.paths.prefix.default,
/**
* Path to game installation folder
*
* @default "~/.local/share/anime-game-launcher/game/drive_c/Program Files/[An Anime Game]"
*/
game: `${await constants.paths.prefix.default}/game/drive_c/Program Files/${constants.placeholders.uppercase.first} ${constants.placeholders.uppercase.second}`,
/**
* Path to some temp folder
*
* @default "~/.local/share/anime-game-launcher"
*/
temp: await constants.paths.prefix.default
},
/** /**
* Runner name to use, or null if runner is not specified * Runner name to use, or null if runner is not specified

View file

@ -48,7 +48,7 @@
Downloader.closeStreams(true); Downloader.closeStreams(true);
Archive.closeStreams(true); Archive.closeStreams(true);
constants.paths.launcherDir.then(async (path) => { constants.paths.tempDir.then(async (tempDir) => {
// Remove IPC file // Remove IPC file
await IPC.purge(); await IPC.purge();
@ -56,8 +56,8 @@
if (launcher.rpc) if (launcher.rpc)
await launcher.rpc.stop(true); await launcher.rpc.stop(true);
// Remove .tmp files from the launcher folder // Remove .tmp files from the temp folder
await Neutralino.os.execCommand(`rm -f "${Process.addSlashes(`${path}/*.tmp`)}"`); await Neutralino.os.execCommand(`rm -f "${Process.addSlashes(`${tempDir}/*.tmp`)}"`);
// Save logs // Save logs
const log = Debug.get().join("\r\n"); const log = Debug.get().join("\r\n");

View file

@ -109,16 +109,28 @@ class Paths
public static readonly prefix = Prefix; public static readonly prefix = Prefix;
/**
* Temp directory
*
* @default "~/.local/share/anime-game-launcher"
*
* @returns "[folders.temp] config field"
*/
public static get tempDir(): Promise<string>
{
return new Promise(async (resolve) => resolve(await Configs.get('folders.temp') as string));
}
/** /**
* Game directory * Game directory
* *
* @default "~/.local/share/anime-game-launcher/game/drive_c/Program Files/[An Anime Game]" * @default "~/.local/share/anime-game-launcher/game/drive_c/Program Files/[An Anime Game]"
* *
* @returns "[constants.paths.prefix.current]/drive_c/Program Files/[An Anime Game]" * @returns "[folders.game] config field"
*/ */
public static get gameDir(): Promise<string> public static get gameDir(): Promise<string>
{ {
return new Promise(async (resolve) => resolve(`${await this.prefix.current}/drive_c/Program Files/${constants.placeholders.uppercase.full}`)); return new Promise(async (resolve) => resolve(await Configs.get('folders.game') as string));
} }
/** /**
@ -126,7 +138,7 @@ class Paths
* *
* @default "~/.local/share/anime-game-launcher/game/drive_c/Program Files/[An Anime Game]/[An Anime Game]_Data" * @default "~/.local/share/anime-game-launcher/game/drive_c/Program Files/[An Anime Game]/[An Anime Game]_Data"
* *
* @returns "[constants.paths.gameDir]/[An Anime Game]_Data" * @returns "[folders.game]/[An Anime Game]_Data"
*/ */
public static get gameDataDir(): Promise<string> public static get gameDataDir(): Promise<string>
{ {
@ -163,15 +175,37 @@ export default class constants
public static readonly placeholders = { public static readonly placeholders = {
uppercase: uppercase:
{ {
/**
* Anime
*/
first: atob('R2Vuc2hpbg=='), first: atob('R2Vuc2hpbg=='),
/**
* Game
*/
second: atob('SW1wYWN0'), second: atob('SW1wYWN0'),
/**
* Anime Game
*/
full: atob('R2Vuc2hpbiBJbXBhY3Q='), full: atob('R2Vuc2hpbiBJbXBhY3Q='),
/**
* anAnimeCompany
*/
company: atob('bWlIb1lv') company: atob('bWlIb1lv')
}, },
lowercase: lowercase:
{ {
/**
* anime
*/
first: atob('Z2Vuc2hpbg=='), first: atob('Z2Vuc2hpbg=='),
/**
* animecompany
*/
company: atob('bWlob3lv') company: atob('bWlob3lv')
} }
}; };

View file

@ -51,8 +51,8 @@ export default abstract class Installer
} }
}); });
constants.paths.launcherDir.then((launcherDir) => { constants.paths.tempDir.then((tempDir) => {
const archivePath = alreadyDownloaded ? uri : `${launcherDir}/${Downloader.fileFromUri(uri)}`; const archivePath = alreadyDownloaded ? uri : `${tempDir}/${Downloader.fileFromUri(uri)}`;
// And then unpack it // And then unpack it
const unpackArchive = () => { const unpackArchive = () => {

View file

@ -195,7 +195,7 @@ class Process
public static run(command: string, options: ProcessOptions = {}): Promise<Process> public static run(command: string, options: ProcessOptions = {}): Promise<Process>
{ {
return new Promise(async (resolve) => { return new Promise(async (resolve) => {
const tmpFile = `${await constants.paths.launcherDir}/${10000 + Math.round(Math.random() * 89999)}.tmp`; const tmpFile = `${await constants.paths.tempDir}/${10000 + Math.round(Math.random() * 89999)}.tmp`;
// Set env variables // Set env variables
if (options.env) if (options.env)

View file

@ -43,7 +43,7 @@ class Window
center(windowWidth: number, windowHeight: number) center(windowWidth: number, windowHeight: number)
{ {
Neutralino.window.move((window.screen.width - windowWidth) / 2, (window.screen.height - windowHeight) / 2); Neutralino.window.move(Math.round((window.screen.width - windowWidth) / 2), Math.round((window.screen.height - windowHeight) / 2));
} }
}; };
} }