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
This commit is contained in:
Observer KRypt0n_ 2021-12-30 13:55:04 +02:00
parent ff6f80c9e0
commit aa4539cec3
No known key found for this signature in database
GPG key ID: DC5D4EC1303465DA
5 changed files with 35 additions and 41 deletions

View file

@ -26,6 +26,11 @@
}); });
}); });
constants.paths.launcherDir.then((dir) => {
Neutralino.filesystem.getStats(dir)
.catch(() => Neutralino.filesystem.createDirectory(dir));
});
const launcher = new Launcher(onMount); const launcher = new Launcher(onMount);
// Do some stuff when all the content will be loaded // Do some stuff when all the content will be loaded

View file

@ -64,14 +64,7 @@ class Paths
*/ */
public static get launcherDir(): Promise<string> public static get launcherDir(): Promise<string>
{ {
return new Promise(async (resolve) => { return new Promise(async (resolve) => resolve(`${await Neutralino.os.getPath('data')}/anime-game-launcher`));
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`);
});
});
} }
/** /**
@ -81,14 +74,7 @@ class Paths
*/ */
public static get runnersDir(): Promise<string> public static get runnersDir(): Promise<string>
{ {
return new Promise(async (resolve) => { return new Promise(async (resolve) => resolve(`${await this.launcherDir}/runners`));
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`);
});
});
} }
/** /**
@ -98,14 +84,7 @@ class Paths
*/ */
public static get dxvksDir(): Promise<string> public static get dxvksDir(): Promise<string>
{ {
return new Promise(async (resolve) => { return new Promise(async (resolve) => resolve(`${await this.launcherDir}/dxvks`));
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`);
});
});
} }
/** /**

View file

@ -7,6 +7,7 @@ import type {
import { DebugThread } from './Debug'; import { DebugThread } from './Debug';
import promisify from './promisify'; import promisify from './promisify';
import Process from '../neutralino/Process';
declare const Neutralino; declare const Neutralino;
declare const NL_CWD; declare const NL_CWD;
@ -76,11 +77,14 @@ class Stream
{ {
this.archive = info; this.archive = info;
const command = { let command = {
tar: `tar -xvf "${path}"${unpackDir ? ` -C "${unpackDir}"` : ''}`, tar: `tar -xvf '${Process.addSlashes(path)}'${unpackDir ? ` -C '${Process.addSlashes(unpackDir)}'` : ''}`,
zip: `unzip -o "${path}"${unpackDir ? ` -d "${unpackDir}"` : ''}` zip: `unzip -o '${Process.addSlashes(path)}'${unpackDir ? ` -d '${Process.addSlashes(unpackDir)}'` : ''}`
}[this.archive.type!]; }[this.archive.type!];
if (unpackDir)
command = `mkdir -p '${Process.addSlashes(unpackDir)}' && ${command}`;
let remainedFiles = this.archive.files; let remainedFiles = this.archive.files;
const baseDir = unpackDir ?? NL_CWD; const baseDir = unpackDir ?? NL_CWD;

View file

@ -53,18 +53,21 @@ export default class DXVK
*/ */
public static list(): Promise<TDXVK[]> public static list(): Promise<TDXVK[]>
{ {
return new Promise((resolve) => { return new Promise(async (resolve) => {
constants.paths.dxvksDir.then(async (dxvksDir: string) => { 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`)); 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[] = []; let dxvks: TDXVK[] = [];
list.forEach((dxvk) => { list.forEach((dxvk) => {
let inst = false; let inst = false;
for (let dir of installed) for (let dir of folders)
inst ||= dir.entry == `dxvk-${dxvk.version}`; inst ||= dir.entry == `dxvk-${dxvk.version}`;
dxvks.push({ dxvks.push({
@ -75,7 +78,7 @@ export default class DXVK
}); });
resolve(dxvks); resolve(dxvks);
}); };
}); });
} }

View file

@ -54,12 +54,15 @@ class Runners
*/ */
public static list(): Promise<RunnerFamily[]> public static list(): Promise<RunnerFamily[]>
{ {
return new Promise((resolve) => { return new Promise(async (resolve) => {
constants.paths.runnersDir.then(async (runnersDir: string) => { 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`)); 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[] = []; let runners: RunnerFamily[] = [];
list.forEach((family) => { list.forEach((family) => {
@ -71,7 +74,7 @@ class Runners
family.runners.forEach((runner) => { family.runners.forEach((runner) => {
let inst = false; let inst = false;
for (let dir of installed) for (let dir of folders)
inst ||= dir.entry == runner.name; inst ||= dir.entry == runner.name;
newFamily.runners.push({ newFamily.runners.push({
@ -85,7 +88,7 @@ class Runners
}); });
resolve(runners); resolve(runners);
}); };
}); });
} }