From 7327231c04b132649e5f3c7204883da3c9c91f21 Mon Sep 17 00:00:00 2001 From: Maroxy Date: Sun, 20 Feb 2022 13:39:14 +0100 Subject: [PATCH] Add Downloading of mismatched files Add Locales --- public/locales/de-de.yaml | 3 ++ public/locales/en-us.yaml | 3 ++ public/locales/es-es.yaml | 3 ++ public/locales/fr-fr.yaml | 3 ++ public/locales/hu-hu.yaml | 3 ++ public/locales/id-id.yaml | 3 ++ public/locales/it-it.yaml | 3 ++ public/locales/nb-no.yaml | 3 ++ public/locales/ru-ru.yaml | 3 ++ public/locales/uwu.yaml | 3 ++ src/ts/launcher/states/CheckIntegrity.ts | 55 +++++++++++++++++++++--- 11 files changed, 79 insertions(+), 6 deletions(-) diff --git a/public/locales/de-de.yaml b/public/locales/de-de.yaml index 395f8f3..ec7e4f1 100644 --- a/public/locales/de-de.yaml +++ b/public/locales/de-de.yaml @@ -25,6 +25,8 @@ launcher: unpacking: Spiel wird entpackt... applying_changes: Änderungen werden angewandt... deleting_outdated: Lösche veraltete dateien... + integrity_check: Verifiziere Dateien... + download_mismatch_files: Lade nicht übereinstimmenden Dateien herunter... # Voice packages installation voice: @@ -70,6 +72,7 @@ launcher: ready: launch: Starten predownload: Update vorinstallieren + integrity: Dateien verifizieren und reparieren # Einstellungs Fenster settings: diff --git a/public/locales/en-us.yaml b/public/locales/en-us.yaml index 02ae16d..2b826de 100644 --- a/public/locales/en-us.yaml +++ b/public/locales/en-us.yaml @@ -25,6 +25,8 @@ launcher: unpacking: Unpacking game... applying_changes: Applying changes... deleting_outdated: Deleting outdated files... + integrity_check: Verifying Files... + download_mismatch_files: Downloading mismatched files... # Voice packages installation voice: @@ -70,6 +72,7 @@ launcher: ready: launch: Launch predownload: Pre-download update + integrity: Verify Files & Repair # Settings window settings: diff --git a/public/locales/es-es.yaml b/public/locales/es-es.yaml index 509dbbc..4927063 100644 --- a/public/locales/es-es.yaml +++ b/public/locales/es-es.yaml @@ -25,6 +25,8 @@ launcher: unpacking: Descomprimiendo el juego... applying_changes: Applying changes... deleting_outdated: Borrando archivos viejos... + integrity_check: Verifying Files... + download_mismatch_files: Downloading mismatched files... # Instalación de paquetes de voz voice: @@ -70,6 +72,7 @@ launcher: ready: launch: Jugar predownload: Pre-descargar actualización + integrity: Verify Files & Repair # Ventana de opciones settings: diff --git a/public/locales/fr-fr.yaml b/public/locales/fr-fr.yaml index 47d82ca..1410e3d 100644 --- a/public/locales/fr-fr.yaml +++ b/public/locales/fr-fr.yaml @@ -25,6 +25,8 @@ launcher: unpacking: Décompression du jeu... applying_changes: Application des changements... deleting_outdated: Suppression des fichiers non à jour... + integrity_check: Verifying Files... + download_mismatch_files: Downloading mismatched files... # Voice packages installation voice: @@ -73,6 +75,7 @@ launcher: ready: launch: Lancer predownload: Pre-téléchargement de mise à jour + integrity: Verify Files & Repair # Settings window settings: diff --git a/public/locales/hu-hu.yaml b/public/locales/hu-hu.yaml index c459240..5e71482 100644 --- a/public/locales/hu-hu.yaml +++ b/public/locales/hu-hu.yaml @@ -25,6 +25,8 @@ launcher: unpacking: Játék kibontása folyamatban... applying_changes: Változások alkalmazása... deleting_outdated: Lejárt fájlok kitörlése... + integrity_check: Verifying Files... + download_mismatch_files: Downloading mismatched files... # Voice packages installation voice: @@ -70,6 +72,7 @@ launcher: ready: launch: Indítás predownload: Frissítés előtöltése + integrity: Verify Files & Repair # Settings window settings: diff --git a/public/locales/id-id.yaml b/public/locales/id-id.yaml index ed99d82..a0f06b2 100644 --- a/public/locales/id-id.yaml +++ b/public/locales/id-id.yaml @@ -25,6 +25,8 @@ launcher: unpacking: Membongkar game... applying_changes: Applying changes... deleting_outdated: Menghapus file lama... + integrity_check: Verifying Files... + download_mismatch_files: Downloading mismatched files... # Voice packages installation voice: @@ -70,6 +72,7 @@ launcher: ready: launch: Luncurkan predownload: Pembaruan pra-unduh + integrity: Verify Files & Repair # Settings window settings: diff --git a/public/locales/it-it.yaml b/public/locales/it-it.yaml index 10dcb52..3ab7497 100644 --- a/public/locales/it-it.yaml +++ b/public/locales/it-it.yaml @@ -25,6 +25,8 @@ launcher: unpacking: Decomprimendo il gioco... applying_changes: Applying changes... deleting_outdated: Cancellando file vecchi... + integrity_check: Verifying Files... + download_mismatch_files: Downloading mismatched files... # Voice packages installation voice: @@ -70,6 +72,7 @@ launcher: ready: launch: Avvia predownload: Pre-scarica aggiornamento + integrity: Verify Files & Repair # Settings window settings: diff --git a/public/locales/nb-no.yaml b/public/locales/nb-no.yaml index f59c18d..d4e2cbb 100644 --- a/public/locales/nb-no.yaml +++ b/public/locales/nb-no.yaml @@ -25,6 +25,8 @@ launcher: unpacking: Pakker ut spill... applying_changes: Applying changes... deleting_outdated: Fjerner utdaterte filer... + integrity_check: Verifying Files... + download_mismatch_files: Downloading mismatched files... # Voice packages installation voice: @@ -70,6 +72,7 @@ launcher: ready: launch: Start predownload: Forhånds-nedlast oppdatering + integrity: Verify Files & Repair # Settings window settings: diff --git a/public/locales/ru-ru.yaml b/public/locales/ru-ru.yaml index 27a15c8..fedd125 100644 --- a/public/locales/ru-ru.yaml +++ b/public/locales/ru-ru.yaml @@ -25,6 +25,8 @@ launcher: unpacking: Распаковка игры... applying_changes: Применение изменений... deleting_outdated: Удаление устаревших файлов... + integrity_check: Verifying Files... + download_mismatch_files: Downloading mismatched files... # Установка звуковых пакетов voice: @@ -70,6 +72,7 @@ launcher: ready: launch: Запустить predownload: Предзагрузить обновление + integrity: Verify Files & Repair # Окно настроек settings: diff --git a/public/locales/uwu.yaml b/public/locales/uwu.yaml index a8d8b05..9c659c0 100644 --- a/public/locales/uwu.yaml +++ b/public/locales/uwu.yaml @@ -25,6 +25,8 @@ launcher: unpacking: unpacking g-game (o^▽^o) applying_changes: appwying changes... deleting_outdated: deweting outdated fiwes... + integrity_check: vewifying fiwes... + download_mismatch_files: downwoading mismatched fiwes... # Voice packages installation voice: @@ -70,6 +72,7 @@ launcher: ready: launch: launch (◕▿◕✿) predownload: pwe-downwoad update + integrity: vewify files & wepaiw # Settings window settings: diff --git a/src/ts/launcher/states/CheckIntegrity.ts b/src/ts/launcher/states/CheckIntegrity.ts index 3f014df..106d768 100644 --- a/src/ts/launcher/states/CheckIntegrity.ts +++ b/src/ts/launcher/states/CheckIntegrity.ts @@ -1,14 +1,43 @@ import type Launcher from '../../Launcher'; -import { Debug, fs, path } from '../../../empathize'; +import { Debug, fs, path, Cache, Downloader } from '../../../empathize'; import constants from '../../Constants'; import Patch from "../../Patch"; import Locales from '../Locales'; -import Voice from "../../Voice" +import Voice from "../../Voice"; declare const Neutralino; +async function download(fileInfo): Promise +{ + return new Promise(async (resolve) => { + const gameDir = await constants.paths.gameDir; + const cache = await Cache.get('Game.getLatestData.ServerResponse'); + + let uri = `${cache!.value['game']['latest']['decompressed_path']}/${fileInfo.remoteName}`; + + Downloader.download(uri, `${gameDir}/${fileInfo.remoteName}.new`).then((stream) => { + stream.finish(async () => { + const process = await Neutralino.os.execCommand(`md5sum "${path.addSlashes(`${gameDir}/${fileInfo.remoteName}.new`)}"`); + const fileHash = (process.stdOut || process.stdErr).split(' ')[0]; + + if (fileHash == fileInfo.md5) + { + await fs.remove(`${gameDir}/${fileInfo.remoteName}`); + await fs.move(`${gameDir}/${fileInfo.remoteName}.new`, `${gameDir}/${fileInfo.remoteName}`); + resolve(true); + } + else + { + await fs.remove(`${gameDir}/${fileInfo.remoteName}.new`); + resolve(false); + } + }); + }); + }); +} + export default (launcher: Launcher): Promise => { return new Promise(async (resolve) => { const gameDir = await constants.paths.gameDir; @@ -74,7 +103,7 @@ export default (launcher: Launcher): Promise => { `Checked ${total} files with ${mismatchedFiles.length} mismatches` : [ `Checked ${total} files with ${mismatchedFiles.length} mismatch(es):`, - ...mismatchedFiles + ...mismatchedFiles.map(e => `[${e.md5}] ${e.remoteName}`) ] }); } @@ -83,10 +112,24 @@ export default (launcher: Launcher): Promise => { // Replace mismatched files - for (const file of mismatchedFiles) + mismatchedFiles.forEach(async (fileInfo: { remoteName: string, md5: string, fileSize: number }) => { - const fileInfo = JSON.parse(file) as { remoteName: string, md5: string, fileSize: number }; - } + launcher.progressBar?.init({ + label: Locales.translate('launcher.progress.game.download_mismatch_files') as string, + showSpeed: false, + showEta: false, + showPercents: false, + showTotals: false + }); + + download(fileInfo).then(async (success) => { + if (!success) + Debug.log({ + function: 'Launcher/States/Integrity', + message: `Download of ${fileInfo.remoteName} failed` + }); + }); + }) resolve(); })