From aa4539cec30131ccf54170dfa51b3e119f2faf7d Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Thu, 30 Dec 2021 13:55:04 +0200 Subject: [PATCH] Made better folder creation - now Archive Stream creates folders recursively before unpacking - `DXVK.list()` and `Runners.list()` now don't require related to them folders to work - now launcher automatically creates `constants.paths.launcherDir` directory at the start --- src/index.svelte | 5 +++++ src/ts/Constants.ts | 27 +++------------------------ src/ts/core/Archive.ts | 10 +++++++--- src/ts/core/DXVK.ts | 17 ++++++++++------- src/ts/core/Runners.ts | 17 ++++++++++------- 5 files changed, 35 insertions(+), 41 deletions(-) diff --git a/src/index.svelte b/src/index.svelte index 068184b..92a3909 100644 --- a/src/index.svelte +++ b/src/index.svelte @@ -26,6 +26,11 @@ }); }); + constants.paths.launcherDir.then((dir) => { + Neutralino.filesystem.getStats(dir) + .catch(() => Neutralino.filesystem.createDirectory(dir)); + }); + const launcher = new Launcher(onMount); // Do some stuff when all the content will be loaded diff --git a/src/ts/Constants.ts b/src/ts/Constants.ts index 30f71b4..894a2cc 100644 --- a/src/ts/Constants.ts +++ b/src/ts/Constants.ts @@ -64,14 +64,7 @@ class Paths */ public static get launcherDir(): Promise { - return new Promise(async (resolve) => { - Neutralino.filesystem.getStats(`${await Neutralino.os.getPath('data')}/anime-game-launcher`) - .then(async () => resolve(`${await Neutralino.os.getPath('data')}/anime-game-launcher`)) - .catch(async () => { - await Neutralino.filesystem.createDirectory(`${await Neutralino.os.getPath('data')}/anime-game-launcher`); - resolve(`${await Neutralino.os.getPath('data')}/anime-game-launcher`); - }); - }); + return new Promise(async (resolve) => resolve(`${await Neutralino.os.getPath('data')}/anime-game-launcher`)); } /** @@ -81,14 +74,7 @@ class Paths */ public static get runnersDir(): Promise { - return new Promise(async (resolve) => { - Neutralino.filesystem.getStats(`${await this.launcherDir}/runners`) - .then(async () => resolve(`${await this.launcherDir}/runners`)) - .catch(async () => { - await Neutralino.filesystem.createDirectory(`${await this.launcherDir}/runners`); - resolve(`${await this.launcherDir}/runners`); - }); - }); + return new Promise(async (resolve) => resolve(`${await this.launcherDir}/runners`)); } /** @@ -98,14 +84,7 @@ class Paths */ public static get dxvksDir(): Promise { - return new Promise(async (resolve) => { - Neutralino.filesystem.getStats(`${await this.launcherDir}/dxvks`) - .then(async () => resolve(`${await this.launcherDir}/dxvks`)) - .catch(async () => { - await Neutralino.filesystem.createDirectory(`${await this.launcherDir}/dxvks`); - resolve(`${await this.launcherDir}/dxvks`); - }); - }); + return new Promise(async (resolve) => resolve(`${await this.launcherDir}/dxvks`)); } /** diff --git a/src/ts/core/Archive.ts b/src/ts/core/Archive.ts index b62b9d0..79bd48b 100644 --- a/src/ts/core/Archive.ts +++ b/src/ts/core/Archive.ts @@ -7,6 +7,7 @@ import type { import { DebugThread } from './Debug'; import promisify from './promisify'; +import Process from '../neutralino/Process'; declare const Neutralino; declare const NL_CWD; @@ -76,11 +77,14 @@ class Stream { this.archive = info; - const command = { - tar: `tar -xvf "${path}"${unpackDir ? ` -C "${unpackDir}"` : ''}`, - zip: `unzip -o "${path}"${unpackDir ? ` -d "${unpackDir}"` : ''}` + let command = { + tar: `tar -xvf '${Process.addSlashes(path)}'${unpackDir ? ` -C '${Process.addSlashes(unpackDir)}'` : ''}`, + zip: `unzip -o '${Process.addSlashes(path)}'${unpackDir ? ` -d '${Process.addSlashes(unpackDir)}'` : ''}` }[this.archive.type!]; + if (unpackDir) + command = `mkdir -p '${Process.addSlashes(unpackDir)}' && ${command}`; + let remainedFiles = this.archive.files; const baseDir = unpackDir ?? NL_CWD; diff --git a/src/ts/core/DXVK.ts b/src/ts/core/DXVK.ts index 2448ad5..0ca6694 100644 --- a/src/ts/core/DXVK.ts +++ b/src/ts/core/DXVK.ts @@ -53,18 +53,21 @@ export default class DXVK */ public static list(): Promise { - return new Promise((resolve) => { - constants.paths.dxvksDir.then(async (dxvksDir: string) => { + return new Promise(async (resolve) => { + const dxvksDir = await constants.paths.dxvksDir; + + Neutralino.filesystem.readDirectory(dxvksDir) + .then((folders) => resolveList(folders)) + .catch(() => resolveList([])); + + const resolveList = async (folders: { entry: string, type: string }[]) => { let list: TDXVK[] = JSON.parse(await Neutralino.filesystem.readFile(`${constants.paths.appDir}/public/dxvks.json`)); - - const installed: { entry: string, type: string }[] = await Neutralino.filesystem.readDirectory(dxvksDir); - let dxvks: TDXVK[] = []; list.forEach((dxvk) => { let inst = false; - for (let dir of installed) + for (let dir of folders) inst ||= dir.entry == `dxvk-${dxvk.version}`; dxvks.push({ @@ -75,7 +78,7 @@ export default class DXVK }); resolve(dxvks); - }); + }; }); } diff --git a/src/ts/core/Runners.ts b/src/ts/core/Runners.ts index be63fe8..3241835 100644 --- a/src/ts/core/Runners.ts +++ b/src/ts/core/Runners.ts @@ -54,12 +54,15 @@ class Runners */ public static list(): Promise { - return new Promise((resolve) => { - constants.paths.runnersDir.then(async (runnersDir: string) => { + return new Promise(async (resolve) => { + const runnersDir = await constants.paths.runnersDir; + + Neutralino.filesystem.readDirectory(runnersDir) + .then((folders) => resolveList(folders)) + .catch(() => resolveList([])); + + const resolveList = async (folders: { entry: string, type: string }[]) => { let list: RunnerFamily[] = JSON.parse(await Neutralino.filesystem.readFile(`${constants.paths.appDir}/public/runners.json`)); - - const installed: { entry: string, type: string }[] = await Neutralino.filesystem.readDirectory(runnersDir); - let runners: RunnerFamily[] = []; list.forEach((family) => { @@ -71,7 +74,7 @@ class Runners family.runners.forEach((runner) => { let inst = false; - for (let dir of installed) + for (let dir of folders) inst ||= dir.entry == runner.name; newFamily.runners.push({ @@ -85,7 +88,7 @@ class Runners }); resolve(runners); - }); + }; }); }