mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-21 01:11:46 +03:00
Small code style changes
This commit is contained in:
parent
ab5cf4e658
commit
3abd53753d
2 changed files with 24 additions and 25 deletions
|
@ -1,5 +1,6 @@
|
|||
import type Launcher from '../../Launcher';
|
||||
import { Debug, Notification, fs, path } from '../../../empathize';
|
||||
|
||||
import { Debug, fs, path } from '../../../empathize';
|
||||
|
||||
import constants from '../../Constants';
|
||||
import Patch from "../../Patch";
|
||||
|
@ -10,16 +11,17 @@ declare const Neutralino;
|
|||
export default (launcher: Launcher): Promise<void> => {
|
||||
return new Promise(async (resolve) => {
|
||||
const gameDir = await constants.paths.gameDir;
|
||||
|
||||
Neutralino.filesystem.readFile(`${gameDir}/pkg_version`)
|
||||
.then(async (files) => {
|
||||
let checkErrors = 0;
|
||||
let mismatchedFiles = [];
|
||||
|
||||
files = files.split(/\r\n|\r|\n/).filter((file) => file != '');
|
||||
|
||||
const patch = await Patch.latest;
|
||||
|
||||
if (files.length > 0)
|
||||
{
|
||||
const patch = await Patch.latest;
|
||||
|
||||
launcher.progressBar?.init({
|
||||
label: Locales.translate('launcher.progress.game.integrity_check') as string,
|
||||
showSpeed: false,
|
||||
|
@ -31,29 +33,22 @@ export default (launcher: Launcher): Promise<void> => {
|
|||
launcher.progressBar?.show();
|
||||
|
||||
let current = 0, total = files.length;
|
||||
const mismatchedFiles = new Array();
|
||||
|
||||
for (const file of files)
|
||||
{
|
||||
// {"remoteName": "GenshinImpact_Data/StreamingAssets/AssetBundles/blocks/00/16567284.blk", "md5": "79ab71cfff894edeaaef025ef1152b77", "fileSize": 3232361}
|
||||
// {"remoteName": "AnAnimeGame_Data/StreamingAssets/AssetBundles/blocks/00/16567284.blk", "md5": "79ab71cfff894edeaaef025ef1152b77", "fileSize": 3232361}
|
||||
const fileCheckInfo = JSON.parse(file) as { remoteName: string, md5: string, fileSize: number };
|
||||
|
||||
if (await fs.exists(`${gameDir}/${fileCheckInfo.remoteName}`))
|
||||
// If this file exists, it's not UnityPlayer.dll,
|
||||
// or if it's UnityPlayer.dll, but patch wasn't applied
|
||||
if (await fs.exists(`${gameDir}/${fileCheckInfo.remoteName}`) &&
|
||||
(!fileCheckInfo.remoteName.includes('UnityPlayer.dll') || !patch.applied))
|
||||
{
|
||||
const process = await Neutralino.os.execCommand(`md5sum "${path.addSlashes(`${gameDir}/${fileCheckInfo.remoteName}`)}" | awk '{ print $1 }'`);
|
||||
const md5 = process.stdOut || process.stdErr;
|
||||
|
||||
if (md5.substring(0, md5.length - 1) != fileCheckInfo.md5)
|
||||
{
|
||||
if (fileCheckInfo.remoteName.includes('UnityPlayer.dll') && patch.applied)
|
||||
console.log('UnityPlayer patched. Skipping check...');
|
||||
else
|
||||
{
|
||||
++checkErrors;
|
||||
mismatchedFiles.push(fileCheckInfo);
|
||||
}
|
||||
}
|
||||
const process = await Neutralino.os.execCommand(`md5sum "${path.addSlashes(`${gameDir}/${fileCheckInfo.remoteName}`)}"`);
|
||||
const fileHash = (process.stdOut || process.stdErr).split(' ')[0];
|
||||
|
||||
if (fileHash != fileCheckInfo.md5)
|
||||
mismatchedFiles.push(fileCheckInfo);
|
||||
}
|
||||
|
||||
launcher.progressBar?.update(++current, total, 1);
|
||||
|
@ -61,13 +56,17 @@ export default (launcher: Launcher): Promise<void> => {
|
|||
|
||||
Debug.log({
|
||||
function: 'Launcher/States/Integrity',
|
||||
message: `Checked ${total} files${checkErrors > 0 ? `, there were ${checkErrors} mismatch(es):\n${JSON.stringify(mismatchedFiles, null, 4)}` : ', there were no mismatches'}`
|
||||
message: mismatchedFiles.length == 0 ?
|
||||
`Checked ${total} files with ${mismatchedFiles.length} mismatches` :
|
||||
[
|
||||
`Checked ${total} files with ${mismatchedFiles.length} mismatches:`,
|
||||
...mismatchedFiles
|
||||
]
|
||||
});
|
||||
|
||||
mismatchedFiles.length = 0;
|
||||
}
|
||||
|
||||
launcher.progressBar?.hide();
|
||||
|
||||
resolve();
|
||||
})
|
||||
.catch(() => resolve());
|
||||
|
|
Loading…
Reference in a new issue