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'
]
},
/**
* Path to wine prefix
*
* @default constants.paths.prefix.default
*/
prefix: await constants.paths.prefix.default,
folders: {
/**
* Path to wine prefix
*
* @default "~/.local/share/anime-game-launcher"
*/
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

View file

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

View file

@ -109,16 +109,28 @@ class Paths
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
*
* @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>
{
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"
*
* @returns "[constants.paths.gameDir]/[An Anime Game]_Data"
* @returns "[folders.game]/[An Anime Game]_Data"
*/
public static get gameDataDir(): Promise<string>
{
@ -163,15 +175,37 @@ export default class constants
public static readonly placeholders = {
uppercase:
{
/**
* Anime
*/
first: atob('R2Vuc2hpbg=='),
/**
* Game
*/
second: atob('SW1wYWN0'),
/**
* Anime Game
*/
full: atob('R2Vuc2hpbiBJbXBhY3Q='),
/**
* anAnimeCompany
*/
company: atob('bWlIb1lv')
},
lowercase:
{
/**
* anime
*/
first: atob('Z2Vuc2hpbg=='),
/**
* animecompany
*/
company: atob('bWlob3lv')
}
};

View file

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

View file

@ -195,7 +195,7 @@ class Process
public static run(command: string, options: ProcessOptions = {}): Promise<Process>
{
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
if (options.env)

View file

@ -43,7 +43,7 @@ class Window
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));
}
};
}