mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-24 02:28:15 +03:00
Proper TS
This commit is contained in:
parent
bf3e57a7dd
commit
182cddb006
9 changed files with 29 additions and 27 deletions
|
@ -42,8 +42,8 @@ export default class Configs
|
||||||
public static set(name: string, value: scalar|scalar[]): Promise<void>
|
public static set(name: string, value: scalar|scalar[]): Promise<void>
|
||||||
{
|
{
|
||||||
const getUpdatedArray = (path: string[], array: scalar|scalar[], value: scalar|scalar[]): scalar|scalar[] => {
|
const getUpdatedArray = (path: string[], array: scalar|scalar[], value: scalar|scalar[]): scalar|scalar[] => {
|
||||||
array[path[0]] = path.length > 1 ?
|
array![path[0]] = path.length > 1 ?
|
||||||
getUpdatedArray(path.slice(1), array[path[0]] ?? {}, value) : value;
|
getUpdatedArray(path.slice(1), array![path[0]] ?? {}, value) : value;
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
};
|
};
|
||||||
|
@ -74,14 +74,14 @@ export default class Configs
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
const setDefaults = async (current: scalar) => {
|
const setDefaults = async (current: scalar) => {
|
||||||
const updateDefaults = (current: scalar, defaults: scalar) => {
|
const updateDefaults = (current: scalar, defaults: scalar) => {
|
||||||
Object.keys(defaults).forEach((key) => {
|
Object.keys(defaults!).forEach((key) => {
|
||||||
// If the field exists in defaults and doesn't exist in current
|
// If the field exists in defaults and doesn't exist in current
|
||||||
if (current[key] === undefined)
|
if (current![key] === undefined)
|
||||||
current[key] = defaults[key];
|
current![key] = defaults![key];
|
||||||
|
|
||||||
// If both of default and current are objects
|
// If both of default and current are objects
|
||||||
else if (typeof current[key] == 'object' && typeof defaults[key] == 'object')
|
else if (typeof current![key] == 'object' && typeof defaults![key] == 'object')
|
||||||
current[key] = updateDefaults(current[key], defaults[key]);
|
current![key] = updateDefaults(current![key], defaults![key]);
|
||||||
});
|
});
|
||||||
|
|
||||||
return current;
|
return current;
|
||||||
|
|
|
@ -6,6 +6,7 @@ import type {
|
||||||
} from './types/GameData';
|
} from './types/GameData';
|
||||||
|
|
||||||
import constants from './Constants';
|
import constants from './Constants';
|
||||||
|
import fetch from './core/Fetch';
|
||||||
|
|
||||||
declare const Neutralino;
|
declare const Neutralino;
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ export default class Game
|
||||||
|
|
||||||
if (response.ok)
|
if (response.ok)
|
||||||
{
|
{
|
||||||
const json: ServerResponse = await response.json();
|
const json: ServerResponse = await (response as any).json();
|
||||||
|
|
||||||
if (json.message == 'OK')
|
if (json.message == 'OK')
|
||||||
resolve(json.data);
|
resolve(json.data);
|
||||||
|
|
|
@ -74,7 +74,7 @@ export default class Voice
|
||||||
{
|
{
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
Game.getDiff(version)
|
Game.getDiff(version)
|
||||||
.then((data) => resolve(data.voice_packs ?? null))
|
.then((data) => resolve(data!.voice_packs ?? null))
|
||||||
.catch((error) => reject(error));
|
.catch((error) => reject(error));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Stream
|
||||||
protected unpackDir: string|null;
|
protected unpackDir: string|null;
|
||||||
protected unpacked: number = 0;
|
protected unpacked: number = 0;
|
||||||
|
|
||||||
protected archive: ArchiveInfo;
|
protected archive?: ArchiveInfo;
|
||||||
|
|
||||||
protected onStart?: () => void;
|
protected onStart?: () => void;
|
||||||
protected onProgress?: (current: number, total: number, difference: number) => void;
|
protected onProgress?: (current: number, total: number, difference: number) => void;
|
||||||
|
@ -59,7 +59,7 @@ class Stream
|
||||||
const command = {
|
const command = {
|
||||||
tar: `tar -xvf "${path}"${unpackDir ? ` -C "${unpackDir}"` : ''}`,
|
tar: `tar -xvf "${path}"${unpackDir ? ` -C "${unpackDir}"` : ''}`,
|
||||||
zip: `unzip -o "${path}"${unpackDir ? ` -d "${unpackDir}"` : ''}`
|
zip: `unzip -o "${path}"${unpackDir ? ` -d "${unpackDir}"` : ''}`
|
||||||
}[this.archive.type];
|
}[this.archive.type!];
|
||||||
|
|
||||||
let remainedFiles = this.archive.files;
|
let remainedFiles = this.archive.files;
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ class Stream
|
||||||
{
|
{
|
||||||
Neutralino.filesystem.getStats(`${baseDir}/${file.path}`)
|
Neutralino.filesystem.getStats(`${baseDir}/${file.path}`)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.unpacked += file.size.uncompressed;
|
this.unpacked += file.size.uncompressed!;
|
||||||
difference += file.size.uncompressed;
|
difference += file.size.uncompressed!;
|
||||||
|
|
||||||
file.path = '#unpacked#';
|
file.path = '#unpacked#';
|
||||||
})
|
})
|
||||||
|
@ -89,9 +89,9 @@ class Stream
|
||||||
remainedFiles = remainedFiles.filter((file) => file.path != '#unpacked#');
|
remainedFiles = remainedFiles.filter((file) => file.path != '#unpacked#');
|
||||||
|
|
||||||
if (this.onProgress)
|
if (this.onProgress)
|
||||||
this.onProgress(this.unpacked, this.archive.size.uncompressed, difference);
|
this.onProgress(this.unpacked, this.archive!.size.uncompressed!, difference);
|
||||||
|
|
||||||
if (this.unpacked >= this.archive.size.uncompressed)
|
if (this.unpacked >= this.archive!.size.uncompressed!)
|
||||||
{
|
{
|
||||||
this.finished = true;
|
this.finished = true;
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ export default class Archive
|
||||||
{
|
{
|
||||||
let fileSize = parseInt(match[1]);
|
let fileSize = parseInt(match[1]);
|
||||||
|
|
||||||
archive.size.uncompressed += fileSize;
|
archive.size.uncompressed! += fileSize;
|
||||||
|
|
||||||
archive.files.push({
|
archive.files.push({
|
||||||
path: match[2],
|
path: match[2],
|
||||||
|
@ -227,8 +227,8 @@ export default class Archive
|
||||||
let uncompressedSize = parseInt(match[1]),
|
let uncompressedSize = parseInt(match[1]),
|
||||||
compressedSize = parseInt(match[2]);
|
compressedSize = parseInt(match[2]);
|
||||||
|
|
||||||
archive.size.compressed += compressedSize;
|
archive.size.compressed! += compressedSize;
|
||||||
archive.size.uncompressed += uncompressedSize;
|
archive.size.uncompressed! += uncompressedSize;
|
||||||
|
|
||||||
archive.files.push({
|
archive.files.push({
|
||||||
path: match[3],
|
path: match[3],
|
||||||
|
|
|
@ -59,7 +59,7 @@ export default class DXVK
|
||||||
// then we should find this DXVK version and call this method for it
|
// then we should find this DXVK version and call this method for it
|
||||||
if (typeof dxvk == 'string')
|
if (typeof dxvk == 'string')
|
||||||
{
|
{
|
||||||
let foundDXVK = null;
|
let foundDXVK;
|
||||||
|
|
||||||
(await this.get()).forEach((currDxvk) => {
|
(await this.get()).forEach((currDxvk) => {
|
||||||
if (currDxvk.version == dxvk)
|
if (currDxvk.version == dxvk)
|
||||||
|
|
|
@ -110,14 +110,14 @@ export default class Downloader
|
||||||
{
|
{
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
fetch(uri).then((response) => {
|
fetch(uri).then((response) => {
|
||||||
resolve(new Stream(uri, output ?? this.fileFromUri(uri), response.length));
|
resolve(new Stream(uri, output ?? this.fileFromUri(uri), response.length!));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static fileFromUri(uri: string): string
|
public static fileFromUri(uri: string): string
|
||||||
{
|
{
|
||||||
const file = uri.split('/').pop().split('#')[0].split('?')[0];
|
const file = uri.split('/').pop()!.split('#')[0].split('?')[0];
|
||||||
|
|
||||||
if (file === '')
|
if (file === '')
|
||||||
return 'index.html';
|
return 'index.html';
|
||||||
|
@ -125,7 +125,7 @@ export default class Downloader
|
||||||
else if (`https://${file}` != uri && `http://${file}` != uri)
|
else if (`https://${file}` != uri && `http://${file}` != uri)
|
||||||
return file;
|
return file;
|
||||||
|
|
||||||
else 'index.html';
|
else return 'index.html';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ class Response
|
||||||
this.length = length;
|
this.length = length;
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/Response/ok
|
// https://developer.mozilla.org/en-US/docs/Web/API/Response/ok
|
||||||
this.ok = status >= 200 && status <= 299;
|
this.ok = status! >= 200 && status! <= 299;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Runners
|
||||||
// then we should find this runner and call this method for it
|
// then we should find this runner and call this method for it
|
||||||
if (typeof runner == 'string')
|
if (typeof runner == 'string')
|
||||||
{
|
{
|
||||||
let foundRunner = null;
|
let foundRunner;
|
||||||
|
|
||||||
(await this.get()).forEach((family) => {
|
(await this.get()).forEach((family) => {
|
||||||
family.runners.forEach((familyRunner) => {
|
family.runners.forEach((familyRunner) => {
|
||||||
|
|
7
src/ts/types/Archive.d.ts
vendored
7
src/ts/types/Archive.d.ts
vendored
|
@ -1,10 +1,11 @@
|
||||||
type ArchiveType =
|
type ArchiveType =
|
||||||
| 'tar'
|
| 'tar'
|
||||||
| 'zip';
|
| 'zip'
|
||||||
|
| null;
|
||||||
|
|
||||||
type Size = {
|
type Size = {
|
||||||
compressed?: number;
|
compressed?: number | null;
|
||||||
uncompressed?: number;
|
uncompressed?: number | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
type File = {
|
type File = {
|
||||||
|
|
Loading…
Reference in a new issue