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);
// Do some stuff when all the content will be loaded

View file

@ -64,14 +64,7 @@ class Paths
*/
public static get launcherDir(): Promise<string>
{
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<string>
{
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<string>
{
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`));
}
/**

View file

@ -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;

View file

@ -53,18 +53,21 @@ export default class DXVK
*/
public static list(): Promise<TDXVK[]>
{
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);
});
};
});
}

View file

@ -54,12 +54,15 @@ class Runners
*/
public static list(): Promise<RunnerFamily[]>
{
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);
});
};
});
}