From 3abd53753dd13b9e720d6c7b5467ce0e7de64c46 Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Sun, 20 Feb 2022 08:26:44 +0000 Subject: [PATCH] Small code style changes --- src/sass/index.sass | 2 +- src/ts/launcher/states/CheckIntegrity.ts | 47 ++++++++++++------------ 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/sass/index.sass b/src/sass/index.sass index 1578210..aa43461 100644 --- a/src/sass/index.sass +++ b/src/sass/index.sass @@ -168,4 +168,4 @@ img.background #downloader background-color: rgba(0,0,0,.3) - border: 1px solid rgba(0,0,0,.4) \ No newline at end of file + border: 1px solid rgba(0,0,0,.4) diff --git a/src/ts/launcher/states/CheckIntegrity.ts b/src/ts/launcher/states/CheckIntegrity.ts index 323dc3d..62fe922 100644 --- a/src/ts/launcher/states/CheckIntegrity.ts +++ b/src/ts/launcher/states/CheckIntegrity.ts @@ -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 => { 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 => { 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,15 +56,19 @@ export default (launcher: Launcher): Promise => { 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()); }) -} \ No newline at end of file +}