2021-12-22 12:51:25 +03:00
|
|
|
import type { VoicePack } from './types/GameData';
|
2021-12-27 17:08:06 +03:00
|
|
|
import type { InstalledVoice, VoiceLang } from './types/Voice';
|
2021-12-22 12:35:10 +03:00
|
|
|
|
|
|
|
import constants from './Constants';
|
2021-12-22 12:51:25 +03:00
|
|
|
import Game from './Game';
|
2021-12-23 23:19:32 +03:00
|
|
|
import AbstractInstaller from './core/AbstractInstaller';
|
2021-12-27 17:08:06 +03:00
|
|
|
import Configs from './Configs';
|
2021-12-22 12:35:10 +03:00
|
|
|
|
|
|
|
declare const Neutralino;
|
|
|
|
|
2021-12-23 23:19:32 +03:00
|
|
|
class Stream extends AbstractInstaller
|
|
|
|
{
|
|
|
|
public constructor(uri: string)
|
|
|
|
{
|
|
|
|
super(uri, constants.paths.gameDir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-22 12:35:10 +03:00
|
|
|
export default class Voice
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get current installed voice data info
|
|
|
|
*/
|
|
|
|
public static get current(): Promise<InstalledVoice>
|
|
|
|
{
|
|
|
|
return new Promise(async (resolve) => {
|
|
|
|
const persistentPath = `${await constants.paths.gameDataDir}/Persistent/audio_lang_14`;
|
|
|
|
|
|
|
|
const langs = {
|
|
|
|
'English(US)': 'en-us',
|
2021-12-23 23:19:32 +03:00
|
|
|
'Japanese': 'ja-jp',
|
|
|
|
'Korean': 'ko-kr',
|
|
|
|
'Chinese': 'zn-cn'
|
2021-12-22 12:35:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
let installedVoice: InstalledVoice = {
|
|
|
|
installed: [],
|
|
|
|
active: null
|
|
|
|
};
|
|
|
|
|
|
|
|
// Parse installed voice packages
|
|
|
|
Neutralino.filesystem.readDirectory(await constants.paths.voiceDir)
|
|
|
|
.then((files) => {
|
|
|
|
files = files
|
|
|
|
.filter((file) => file.type == 'DIRECTORY')
|
|
|
|
.map((file) => file.entry);
|
|
|
|
|
|
|
|
Object.keys(langs).forEach((folder) => {
|
|
|
|
if (files.includes(folder) && langs[folder] !== undefined)
|
|
|
|
installedVoice.installed.push(langs[folder]);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
|
|
|
|
|
|
|
// Parse active voice package
|
|
|
|
Neutralino.filesystem.readFile(persistentPath)
|
|
|
|
.then((lang) => installedVoice.active = langs[lang] ?? null)
|
|
|
|
.catch(() => {});
|
|
|
|
|
|
|
|
resolve(installedVoice);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-27 17:08:06 +03:00
|
|
|
/**
|
2021-12-27 17:36:54 +03:00
|
|
|
* Get currently selected voice package language according to the config file
|
2021-12-27 17:08:06 +03:00
|
|
|
*/
|
|
|
|
public static get selected(): Promise<VoiceLang>
|
|
|
|
{
|
|
|
|
return Configs.get('lang.voice') as Promise<VoiceLang>;
|
|
|
|
}
|
|
|
|
|
2021-12-22 12:35:10 +03:00
|
|
|
/**
|
2021-12-22 12:51:25 +03:00
|
|
|
* Get latest voice data info
|
|
|
|
*
|
2021-12-27 17:36:54 +03:00
|
|
|
* @returns Latest Voice Pack information else throws Error if company's servers are unreachable or if they responded with an error
|
2021-12-22 12:51:25 +03:00
|
|
|
*/
|
|
|
|
public static get latest(): Promise<VoicePack[]>
|
|
|
|
{
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
Game.getLatestData()
|
|
|
|
.then((data) => resolve(data.game.latest.voice_packs))
|
|
|
|
.catch((error) => reject(error));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get updated voice data from the specified version to the latest
|
2021-12-22 12:35:10 +03:00
|
|
|
*
|
2021-12-27 19:39:40 +03:00
|
|
|
* @returns null if the difference can't be calculated
|
2021-12-27 17:36:54 +03:00
|
|
|
* @returns Error object if company's servers are unreachable or they responded with an error
|
2021-12-22 12:35:10 +03:00
|
|
|
*/
|
2021-12-22 12:51:25 +03:00
|
|
|
public static getDiff(version: string): Promise<VoicePack[]|null>
|
2021-12-22 12:35:10 +03:00
|
|
|
{
|
2021-12-22 12:51:25 +03:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
Game.getDiff(version)
|
2021-12-27 17:08:06 +03:00
|
|
|
.then((data) => resolve(data?.voice_packs ?? null))
|
2021-12-22 12:35:10 +03:00
|
|
|
.catch((error) => reject(error));
|
|
|
|
});
|
2021-12-22 12:51:25 +03:00
|
|
|
}
|
2021-12-23 23:19:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the voice data installation stream
|
|
|
|
*
|
|
|
|
* @returns null if the language or the version can't be found
|
|
|
|
* @returns rejects Error object if company's servers are unreachable or they responded with an error
|
|
|
|
*/
|
|
|
|
public static update(lang: string|null = null, version: string|null = null): Promise<Stream|null>
|
|
|
|
{
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
(version === null ? this.latest : this.getDiff(version))
|
|
|
|
.then((data: VoicePack[]|null) => {
|
|
|
|
if (data === null)
|
|
|
|
resolve(null);
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const voice = data.filter(voice => voice.language === lang);
|
|
|
|
|
|
|
|
resolve(voice.length === 1 ? new Stream(voice[0].path) : null);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => reject(error));
|
|
|
|
});
|
|
|
|
}
|
2021-12-22 12:35:10 +03:00
|
|
|
}
|
2021-12-23 23:19:32 +03:00
|
|
|
|
|
|
|
export { Stream };
|