diff --git a/package.json b/package.json index acdfaf2..1dbac4d 100644 --- a/package.json +++ b/package.json @@ -43,9 +43,9 @@ "@types/command-exists": "^1.2.0", "@types/discord-rpc": "^4.0.0", "@types/semver": "^7.3.9", - "electron": "^16.0.2", + "electron": "^16.0.4", "electron-builder": "^22.14.5", - "sass": "^1.43.5", + "sass": "^1.44.0", "typescript": "^4.5.2" }, "dependencies": { diff --git a/public/html/settings.html b/public/html/settings.html index 7d5f043..cd02f34 100644 --- a/public/html/settings.html +++ b/public/html/settings.html @@ -25,13 +25,49 @@ -

General

+
+ + +
1
+ +
+

Statistics

+ +
+ You've played for + + hours + + minutes +
+ + + +
+
+
Language @@ -274,18 +310,6 @@
- -
-

Statistics

- -
- You've played for - - hours - - minutes -
-
diff --git a/public/images/badges/torch.png b/public/images/badges/torch.png new file mode 100644 index 0000000..8ec9562 Binary files /dev/null and b/public/images/badges/torch.png differ diff --git a/public/images/rank.png b/public/images/rank.png new file mode 100644 index 0000000..8763916 Binary files /dev/null and b/public/images/rank.png differ diff --git a/public/locales/de.json b/public/locales/de.json index 316736d..117422a 100644 --- a/public/locales/de.json +++ b/public/locales/de.json @@ -40,6 +40,7 @@ "YouPlayedFor": "Sie haben ungefähr", "hours": "Stunden und", "minutes": "Minuten gespielt", + "YourLauncherLevel": "Your launcher's level", "Downloading": "wird Heruntergeladen", "Unpacking": "wird Entpackt", "GameDownloaded": "Spiel würde erfolgreich heruntergeladen", @@ -59,6 +60,8 @@ "LauncherUpdateTitle": "Launcher update verfügbar: ", "LauncherUpdateBody": "Sie können eine neue Version des Launchers aus dem Repository des Projekts unter {uri.launcher} herunterladen.", "TelemetryNotDisabled": "{placeholders.uppercase.company} Telemetrieserver sind nicht deaktiviert!", + "PatchRepoUnavailableTitle": "Patch's repository is not available", + "PatchRepoUnavailableBody": "Most likely notabug is under attack and is not responding", "DefPrefix": "Zurücksetzen zum Standard-Prefix", "ChangePrefix": "Prefix ändern" } \ No newline at end of file diff --git a/public/locales/en-us.json b/public/locales/en-us.json index 3fca36e..2801440 100644 --- a/public/locales/en-us.json +++ b/public/locales/en-us.json @@ -41,6 +41,7 @@ "YouPlayedFor": "You've played for", "hours": "hours", "minutes": "minutes", + "YourLauncherLevel": "Your launcher's level", "Unpacking": "Unpacking", "GameDownloaded": "Game was successfully installed", "ApplyPatch": "Applying patch...", @@ -59,6 +60,8 @@ "LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}", "TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!", + "PatchRepoUnavailableTitle": "Patch's repository is not available", + "PatchRepoUnavailableBody": "Most likely notabug is under attack and is not responding", "DefPrefix": "Reset to Default", "ChangePrefix": "Change Prefix" } \ No newline at end of file diff --git a/public/locales/en.json b/public/locales/en.json index 58a2402..ec49242 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -40,6 +40,7 @@ "YouPlayedFor": "You've played for", "hours": "hours", "minutes": "minutes", + "YourLauncherLevel": "Your launcher's level", "Downloading": "Downloading", "Unpacking": "Unpacking", "GameDownloaded": "Game was successfully installed", @@ -59,6 +60,8 @@ "LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}", "TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!", + "PatchRepoUnavailableTitle": "Patch's repository is not available", + "PatchRepoUnavailableBody": "Most likely notabug is under attack and is not responding", "DefPrefix": "Reset to Default", "ChangePrefix": "Change Prefix" } \ No newline at end of file diff --git a/public/locales/es.json b/public/locales/es.json index 58a2402..ec49242 100644 --- a/public/locales/es.json +++ b/public/locales/es.json @@ -40,6 +40,7 @@ "YouPlayedFor": "You've played for", "hours": "hours", "minutes": "minutes", + "YourLauncherLevel": "Your launcher's level", "Downloading": "Downloading", "Unpacking": "Unpacking", "GameDownloaded": "Game was successfully installed", @@ -59,6 +60,8 @@ "LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}", "TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!", + "PatchRepoUnavailableTitle": "Patch's repository is not available", + "PatchRepoUnavailableBody": "Most likely notabug is under attack and is not responding", "DefPrefix": "Reset to Default", "ChangePrefix": "Change Prefix" } \ No newline at end of file diff --git a/public/locales/fr.json b/public/locales/fr.json index 58a2402..ec49242 100644 --- a/public/locales/fr.json +++ b/public/locales/fr.json @@ -40,6 +40,7 @@ "YouPlayedFor": "You've played for", "hours": "hours", "minutes": "minutes", + "YourLauncherLevel": "Your launcher's level", "Downloading": "Downloading", "Unpacking": "Unpacking", "GameDownloaded": "Game was successfully installed", @@ -59,6 +60,8 @@ "LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}", "TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!", + "PatchRepoUnavailableTitle": "Patch's repository is not available", + "PatchRepoUnavailableBody": "Most likely notabug is under attack and is not responding", "DefPrefix": "Reset to Default", "ChangePrefix": "Change Prefix" } \ No newline at end of file diff --git a/public/locales/id.json b/public/locales/id.json index 4ce2576..a464841 100644 --- a/public/locales/id.json +++ b/public/locales/id.json @@ -19,11 +19,11 @@ "GameModeNotInstalled": "Kamu belum memasang GameMode", "SwitcherooNotInstalled": "Kamu belum memasang switcheroo-control", "AutoDeleteDXVKLogs": "Otomatis hapus log DXVK", - "RecommendableOnly": "Show recommendable versions", - "LauncherFolder": "launcher folder", + "RecommendableOnly": "Tampilkan pilihan yang direkomendasikan", + "LauncherFolder": "folder peluncur", "Prefix": "Prefix", - "SelectDir": "Select dir", - "ResetDir": "Reset dir", + "SelectDir": "Pilih direktori", + "ResetDir": "Setel ulang direktori", "Author": "Pembuat", "NoImages": "Tidak ada gambar ditambahkan", "SettingsTitle": "Pengaturan", @@ -40,6 +40,7 @@ "YouPlayedFor": "Kamu sudah bermain selama", "hours": "jam", "minutes": "menit", + "YourLauncherLevel": "Your launcher's level", "Downloading": "Mengunduh", "Unpacking": "Membuka paket", "GameDownloaded": "Game berhasil dipasang", @@ -59,6 +60,8 @@ "LauncherUpdateTitle": "Pembaruan Peluncur tersedia: ", "LauncherUpdateBody": "Kamu dapat mengunduh versi baru peluncur dari repositori di {uri.launcher}", "TelemetryNotDisabled": "Peladen telemetri {placeholders.uppercase.company} tidak dimatikan!", + "PatchRepoUnavailableTitle": "Patch's repository is not available", + "PatchRepoUnavailableBody": "Most likely notabug is under attack and is not responding", "DefPrefix": "Reset to Default", "ChangePrefix": "Change Prefix" } \ No newline at end of file diff --git a/public/locales/ja.json b/public/locales/ja.json index 67af50e..7ddd5ed 100644 --- a/public/locales/ja.json +++ b/public/locales/ja.json @@ -41,6 +41,7 @@ "YouPlayedFor": "あなたはのためにプレーしてきました", "hours": "時間", "minutes": "分", + "YourLauncherLevel": "Your launcher's level", "Unpacking": "開梱", "GameDownloaded": "ゲームのインストールに成功しました", "ApplyPatch": "パッチの適用...", @@ -59,6 +60,8 @@ "LauncherUpdateTitle": "ランチャーのアップデートが可能 ", "LauncherUpdateBody": "ランチャーの新バージョンは、プロジェクトのリポジトリ({uri.launcher})からダウンロードできます。", "TelemetryNotDisabled": "{placeholders.uppercase.company}のテレメトリサーバは無効になっていません!", + "PatchRepoUnavailableTitle": "Patch's repository is not available", + "PatchRepoUnavailableBody": "Most likely notabug is under attack and is not responding", "DefPrefix": "デフォルトへのリセット", "ChangePrefix": "プレフィックスを変更" } \ No newline at end of file diff --git a/public/locales/ko.json b/public/locales/ko.json index e4503e2..dbc224f 100644 --- a/public/locales/ko.json +++ b/public/locales/ko.json @@ -40,6 +40,7 @@ "YouPlayedFor": "당신은 위해 연주했습니다", "hours": "시간", "minutes": "분", + "YourLauncherLevel": "런처의 레벨", "Downloading": "다운로드 중", "Unpacking": "풀기", "GameDownloaded": "게임이 성공적으로 설치되었습니다", @@ -59,6 +60,8 @@ "LauncherUpdateTitle": "실행기 업데이트 가능: ", "LauncherUpdateBody": "에서 프로젝트의 저장소에서 실행기의 새 버전을 다운로드 할 수 있습니다 {uri.launcher}", "TelemetryNotDisabled": "{placeholders.uppercase.company} 의 원격 측정 서버가 비활성화되지 않음!", + "PatchRepoUnavailableTitle": "Patch's repository is not available", + "PatchRepoUnavailableBody": "Most likely notabug is under attack and is not responding", "DefPrefix": "Reset to Default", "ChangePrefix": "Change Prefix" } \ No newline at end of file diff --git a/public/locales/pt.json b/public/locales/pt.json index 58a2402..ec49242 100644 --- a/public/locales/pt.json +++ b/public/locales/pt.json @@ -40,6 +40,7 @@ "YouPlayedFor": "You've played for", "hours": "hours", "minutes": "minutes", + "YourLauncherLevel": "Your launcher's level", "Downloading": "Downloading", "Unpacking": "Unpacking", "GameDownloaded": "Game was successfully installed", @@ -59,6 +60,8 @@ "LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}", "TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!", + "PatchRepoUnavailableTitle": "Patch's repository is not available", + "PatchRepoUnavailableBody": "Most likely notabug is under attack and is not responding", "DefPrefix": "Reset to Default", "ChangePrefix": "Change Prefix" } \ No newline at end of file diff --git a/public/locales/ru.json b/public/locales/ru.json index 2680602..c92b3b8 100644 --- a/public/locales/ru.json +++ b/public/locales/ru.json @@ -40,6 +40,7 @@ "YouPlayedFor": "Вы играли", "hours": "часов", "minutes": "минут", + "YourLauncherLevel": "Уровень вашего лаунчера", "Downloading": "Загрузка", "Unpacking": "Распаковка", "GameDownloaded": "Игра была успешно установлена", @@ -59,6 +60,8 @@ "LauncherUpdateTitle": "Доступно обновление лаунчера: ", "LauncherUpdateBody": "Вы можете скачать новую версию лаунчера с репозитория проекта: {uri.launcher}", "TelemetryNotDisabled": "Серверы сбора телеметрии {placeholders.uppercase.company} не отключены!", + "PatchRepoUnavailableTitle": "Репозиторий патча недоступен", + "PatchRepoUnavailableBody": "Скорее всего notabug находится под атакой и не отвечает", "DefPrefix": "Сбросить до умолчания", "ChangePrefix": "Изменить префикс" } \ No newline at end of file diff --git a/public/locales/th.json b/public/locales/th.json index 58a2402..ec49242 100644 --- a/public/locales/th.json +++ b/public/locales/th.json @@ -40,6 +40,7 @@ "YouPlayedFor": "You've played for", "hours": "hours", "minutes": "minutes", + "YourLauncherLevel": "Your launcher's level", "Downloading": "Downloading", "Unpacking": "Unpacking", "GameDownloaded": "Game was successfully installed", @@ -59,6 +60,8 @@ "LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}", "TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!", + "PatchRepoUnavailableTitle": "Patch's repository is not available", + "PatchRepoUnavailableBody": "Most likely notabug is under attack and is not responding", "DefPrefix": "Reset to Default", "ChangePrefix": "Change Prefix" } \ No newline at end of file diff --git a/public/locales/vi.json b/public/locales/vi.json index 58a2402..ec49242 100644 --- a/public/locales/vi.json +++ b/public/locales/vi.json @@ -40,6 +40,7 @@ "YouPlayedFor": "You've played for", "hours": "hours", "minutes": "minutes", + "YourLauncherLevel": "Your launcher's level", "Downloading": "Downloading", "Unpacking": "Unpacking", "GameDownloaded": "Game was successfully installed", @@ -59,6 +60,8 @@ "LauncherUpdateTitle": "Launcher update available: ", "LauncherUpdateBody": "You can download a new version of the launcher from the project's repository at {uri.launcher}", "TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!", + "PatchRepoUnavailableTitle": "Patch's repository is not available", + "PatchRepoUnavailableBody": "Most likely notabug is under attack and is not responding", "DefPrefix": "Reset to Default", "ChangePrefix": "Change Prefix" } \ No newline at end of file diff --git a/public/locales/zh-cn.json b/public/locales/zh-cn.json index db2a09e..25e8507 100644 --- a/public/locales/zh-cn.json +++ b/public/locales/zh-cn.json @@ -41,6 +41,7 @@ "YouPlayedFor": "You've played for", "hours": "hours", "minutes": "minutes", + "YourLauncherLevel": "Your launcher's level", "Unpacking": "开箱", "GameDownloaded": "游戏安装成功", "ApplyPatch": "应用补丁...", @@ -59,6 +60,8 @@ "LauncherUpdateTitle": "启动器更新可用:", "LauncherUpdateBody": "你可以从项目的资源库中下载新版本的启动器,网址是:{uri.launcher}", "TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!", + "PatchRepoUnavailableTitle": "Patch's repository is not available", + "PatchRepoUnavailableBody": "Most likely notabug is under attack and is not responding", "DefPrefix": "Reset to Default", "ChangePrefix": "Change Prefix" } \ No newline at end of file diff --git a/public/locales/zh-tw.json b/public/locales/zh-tw.json index 08b8b50..5e906b0 100644 --- a/public/locales/zh-tw.json +++ b/public/locales/zh-tw.json @@ -41,6 +41,7 @@ "YouPlayedFor": "You've played for", "hours": "hours", "minutes": "minutes", + "YourLauncherLevel": "Your launcher's level", "Unpacking": "解壓縮中...", "GameDownloaded": "遊戲安裝成功", "ApplyPatch": "套用補丁...", @@ -59,6 +60,8 @@ "LauncherUpdateTitle": "啟動器有新的更新可用:", "LauncherUpdateBody": "您可以從此專案的資源庫中下載新版本的啟動器,網址是:{uri.launcher}", "TelemetryNotDisabled": "{placeholders.uppercase.company}'s telemetry servers don't disabled!", + "PatchRepoUnavailableTitle": "Patch's repository is not available", + "PatchRepoUnavailableBody": "Most likely notabug is under attack and is not responding", "DefPrefix": "Reset to Default", "ChangePrefix": "Change Prefix" } \ No newline at end of file diff --git a/src/sass/settings.sass b/src/sass/settings.sass index ea4cfe5..e9067ab 100644 --- a/src/sass/settings.sass +++ b/src/sass/settings.sass @@ -82,5 +82,45 @@ .settings-item:last-child margin-bottom: 24px + .launcher-stats + display: inline-flex + margin-bottom: 16px + + > img + width: 96px + height: 96px + + .level + position: absolute + width: 96px + top: 105px + + text-align: center + font-size: 20px + color: #71b71b + + .stats + margin-left: 32px + align-self: center + + > p + font-size: 20px + font-weight: 600 + margin: 0 + + .time-spent + font-size: 18px + margin: 8px 0 16px 0 + + .badges + margin-bottom: 16px + + img + width: 24px + height: 24px + + margin-right: 4px + + @include themable(light, $light) @include themable(dark, $dark) diff --git a/src/ts/index.ts b/src/ts/index.ts index ce235d4..d83c187 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -352,9 +352,8 @@ $(() => { LauncherUI.setState('patch-applying'); - LauncherLib.patchGame(() => { - LauncherUI.updateLauncherState(); - }, data => console.log(data.toString())); + LauncherLib.patchGame((data) => console.log(data.toString())) + .then(() => LauncherUI.updateLauncherState()); } // Voice pack update diff --git a/src/ts/lib/LauncherLib.ts b/src/ts/lib/LauncherLib.ts index 64d170f..c653cff 100644 --- a/src/ts/lib/LauncherLib.ts +++ b/src/ts/lib/LauncherLib.ts @@ -7,6 +7,9 @@ const path = require('path'); const os = require('os'); const { spawn, exec } = require('child_process'); +// TODO: This is an instrument-surprise which will be used later :) +// const crypto = require('crypto'); + const store = require('electron-store'); const https = require('follow-redirects').https; const got = require('got'); @@ -85,6 +88,38 @@ export default class LauncherLib return this.getConfig('version'); } + /*public static getKeypair(): { public: string, private: string } + { + const keypairFile = path.join(constants.launcherDir, 'keypair.json'); + + if (fs.existsSync(keypairFile)) + return JSON.parse(fs.readFileSync(keypairFile)); + + else + { + const { privateKey, publicKey } = crypto.generateKeyPairSync('ec', { + namedCurve: 'secp224r1' + }); + + fs.writeFileSync(keypairFile, JSON.stringify({ + public: publicKey.export({ + type: 'spki', + format: 'der' + }).toString('base64'), + + private: privateKey.export({ + type: 'sec1', + format: 'der' + }).toString('base64') + })); + + return { + public: publicKey, + private: privateKey + }; + } + }*/ + public static getRunners (): Promise<[{ title: string, runners: Runner[] }]> { /*return new Promise((resolve, reject) => { @@ -173,20 +208,30 @@ export default class LauncherLib return background; } - public static async getPatchInfo (): Promise<{ version: string, state: 'testing' | 'stable' }> + /** + * Get patch's state and version from the repository + * @returns information about the patch, or null if repository is not available + */ + public static async getPatchInfo(): Promise<{ version: string, state: 'testing' | 'stable' }|null> { return new Promise(resolve => { this.getData().then(async (data) => { let gameLatest: string = data.game.latest.version; - got(`${constants.uri.patch}/raw/master/${gameLatest.replaceAll('.', '')}/patch.sh`) - .then((patch: any) => { + got(`${constants.uri.patch}/raw/master/${gameLatest.replaceAll('.', '')}/patch.sh`, { + timeout: { + request: 4000 + } + }).then((patch: any) => { /** * [game version]/patch.sh file exists * so it's testing or stable version */ - got(`${constants.uri.patch}/raw/master/${gameLatest.replaceAll('.', '')}/patch_files/unityplayer_patch.vcdiff`) - .then(() => { + got(`${constants.uri.patch}/raw/master/${gameLatest.replaceAll('.', '')}/patch_files/unityplayer_patch.vcdiff`, { + timeout: { + request: 4000 + } + }).then(() => { /** * [game version]/patch_files/unityplayer_patch * exists so it's testing or stable @@ -197,27 +242,49 @@ export default class LauncherLib 'stable' : 'testing' }); }) - .catch(() => { + .catch((error: Error) => { + console.error(error); + + /** + * Notabug is not responding + */ + if (error.message.includes('Timeout awaiting')) + resolve(null); + /** * [game version]/patch_files/unityplayer_patch * doesn't exist so it's just a preparation * * TODO: add preparation state */ - resolve({ - version: data.game.diffs[0].version, - state: 'stable' - }); + else + { + resolve({ + version: data.game.diffs[0].version, + state: 'stable' + }); + } }); }) - .catch(() => { + .catch((error: Error) => { + console.error(error); + + /** + * Notabug is not responding + */ + if (error.message.includes('Timeout awaiting')) + resolve(null); + /** * Otherwise it's definitely preparation */ - resolve({ - version: data.game.diffs[0].version, - state: 'stable' - }); + else + { + resolve({ + version: data.game.diffs[0].version, + state: 'stable' + }); + } }); }); }); @@ -331,71 +398,76 @@ export default class LauncherLib }); } - public static isPrefixInstalled (prefixPath: string): boolean + public static isPrefixInstalled(prefixPath: string): boolean { return fs.existsSync(path.join(prefixPath, 'drive_c')); } - public static patchGame (onFinish: () => void, onData: (data: string) => void) + public static patchGame(onData: (data: string) => void): Promise { - this.getPatchInfo().then(pathInfo => { - Tools.downloadFile(constants.patchUri, path.join(constants.launcherDir, 'patch.zip')).then(() => { - Tools.unzip(path.join(constants.launcherDir, 'patch.zip'), constants.launcherDir).then(() => { - // Delete zip file and assign patch directory. - fs.unlinkSync(path.join(constants.launcherDir, 'patch.zip')); + return new Promise((resolve) => { + this.getPatchInfo().then(pathInfo => { + if (pathInfo === null) + resolve(false); - const patchDir = path.join(constants.launcherDir, 'dawn', pathInfo.version.replaceAll('.', '')); - - // Patch out the testing phase content from the shell files if active and make sure the shell files are executable. - exec(`cd ${patchDir} && sed -i '/^echo "If you would like to test this patch, modify this script and remove the line below this one."/,+5d' patch.sh`); - exec(`cd ${patchDir} && sed -i '/^echo " necessary afterwards (Friday?). If that's the case, comment the line below."/,+2d' patch_anti_logincrash.sh`); - exec(`chmod +x ${path.join(patchDir, 'patch.sh')}`); - exec(`chmod +x ${path.join(patchDir, 'patch_anti_logincrash.sh')}`); - - // Execute the patch file with "yes yes" in the beginning to agree to the choices. - let patcherProcess = exec(`yes yes | ${path.join(patchDir, 'patch.sh')}`, { - cwd: constants.gameDir, - env: { - ...process.env, - WINEPREFIX: constants.prefixDir.get() - } - }); - - patcherProcess.stdout.on('data', (data: string) => onData(data)); - - patcherProcess.on('close', () => { - // Make sure that launcher.bat exists if not run patch.sh again. - if (!fs.existsSync(path.join(constants.gameDir, 'launcher.bat'))) - exec(`yes yes | ${path.join(patchDir, 'patch.sh')}`, { - cwd: constants.gameDir, - env: { - ...process.env, - WINEPREFIX: constants.prefixDir.get() - } - }); - - // Execute the patch file with "yes" in the beginning to agree to the choice. - let patcherAntiCrashProcess = exec(`yes | ${path.join(patchDir, 'patch_anti_logincrash.sh')}`, { + else Tools.downloadFile(constants.patchUri, path.join(constants.launcherDir, 'patch.zip')).then(() => { + Tools.unzip(path.join(constants.launcherDir, 'patch.zip'), constants.launcherDir).then(() => { + // Delete zip file and assign patch directory. + fs.unlinkSync(path.join(constants.launcherDir, 'patch.zip')); + + const patchDir = path.join(constants.launcherDir, 'dawn', pathInfo.version.replaceAll('.', '')); + + // Patch out the testing phase content from the shell files if active and make sure the shell files are executable. + exec(`cd ${patchDir} && sed -i '/^echo "If you would like to test this patch, modify this script and remove the line below this one."/,+5d' patch.sh`); + exec(`cd ${patchDir} && sed -i '/^echo " necessary afterwards (Friday?). If that's the case, comment the line below."/,+2d' patch_anti_logincrash.sh`); + exec(`chmod +x ${path.join(patchDir, 'patch.sh')}`); + exec(`chmod +x ${path.join(patchDir, 'patch_anti_logincrash.sh')}`); + + // Execute the patch file with "yes yes" in the beginning to agree to the choices. + let patcherProcess = exec(`yes yes | ${path.join(patchDir, 'patch.sh')}`, { cwd: constants.gameDir, env: { ...process.env, WINEPREFIX: constants.prefixDir.get() } }); - - patcherAntiCrashProcess.stdout.on('data', (data: string) => onData(data)); - - patcherAntiCrashProcess.on('close', () => { - this.updateConfig('patch.version', pathInfo.version); - this.updateConfig('patch.state', pathInfo.state); - - fs.rmSync(path.join(constants.launcherDir, 'dawn'), { recursive: true }); - - onFinish(); + + patcherProcess.stdout.on('data', (data: string) => onData(data)); + + patcherProcess.on('close', () => { + // Make sure that launcher.bat exists if not run patch.sh again. + if (!fs.existsSync(path.join(constants.gameDir, 'launcher.bat'))) + exec(`yes yes | ${path.join(patchDir, 'patch.sh')}`, { + cwd: constants.gameDir, + env: { + ...process.env, + WINEPREFIX: constants.prefixDir.get() + } + }); + + // Execute the patch file with "yes" in the beginning to agree to the choice. + let patcherAntiCrashProcess = exec(`yes | ${path.join(patchDir, 'patch_anti_logincrash.sh')}`, { + cwd: constants.gameDir, + env: { + ...process.env, + WINEPREFIX: constants.prefixDir.get() + } + }); + + patcherAntiCrashProcess.stdout.on('data', (data: string) => onData(data)); + + patcherAntiCrashProcess.on('close', () => { + this.updateConfig('patch.version', pathInfo.version); + this.updateConfig('patch.state', pathInfo.state); + + fs.rmSync(path.join(constants.launcherDir, 'dawn'), { recursive: true }); + + resolve(true); + }); }); }); - }); - }) + }) + }); }); } } diff --git a/src/ts/lib/LauncherUI.ts b/src/ts/lib/LauncherUI.ts index 11fd8cf..048bda6 100644 --- a/src/ts/lib/LauncherUI.ts +++ b/src/ts/lib/LauncherUI.ts @@ -114,8 +114,22 @@ export default class LauncherUI public static async updateLauncherState(data: any = null) { - const gameData = data ?? await LauncherLib.getData(); - const patchInfo = await LauncherLib.getPatchInfo(); + const gameData = data ?? await LauncherLib.getData(); + let patchInfo = await LauncherLib.getPatchInfo(); + + // If patch's repo is not available + if (patchInfo === null) + { + patchInfo = { + version: LauncherLib.getConfig('patch.version'), + state: LauncherLib.getConfig('patch.state') + }; + + ipcRenderer.send('notification', { + title: this.i18n.translate('PatchRepoUnavailableTitle'), + body: this.i18n.translate('PatchRepoUnavailableBody') + }); + } // Update available if (LauncherLib.version != gameData.game.latest.version) @@ -151,9 +165,8 @@ export default class LauncherUI this.setState('patch-applying'); - LauncherLib.patchGame(() => { - this.setState('game-launch-available'); - }, data => console.log(data.toString())); + LauncherLib.patchGame((data) => console.log(data.toString())) + .then(() => this.setState('game-launch-available')); } // Patch is in testing phase @@ -169,9 +182,8 @@ export default class LauncherUI this.setState('patch-applying'); - LauncherLib.patchGame(() => { - this.setState('game-launch-available'); - }, data => console.log(data.toString())); + LauncherLib.patchGame((data) => console.log(data.toString())) + .then(() => this.setState('game-launch-available')); } else this.setState('game-launch-available'); @@ -183,7 +195,7 @@ export default class LauncherUI temp: 0 }; - public static initProgressBar (): void + public static initProgressBar(): void { this.progressBar = { beganAt: Date.now(), @@ -201,7 +213,7 @@ export default class LauncherUI $('#launch').css('display', 'none'); } - public static updateProgressBar (prefix: string, current: number, total: number, difference: number): void + public static updateProgressBar(prefix: string, current: number, total: number, difference: number): void { $('#downloaded').text(`${prefix}: ${ Math.round(current / total * 100) }% (${Tools.prettifyBytes(current)} / ${Tools.prettifyBytes(total)})`); @@ -248,7 +260,7 @@ export default class LauncherUI $('#downloader .progress').css('width', '0'); } - public static updateBackground (): void + public static updateBackground(): void { LauncherLib.getBackgroundUri().then(uri => { if ($('img.background').attr('src') != uri) @@ -299,14 +311,14 @@ export default class LauncherUI }); } - public static updateSocial (): void + public static updateSocial(): void { const socialUri = `https://${constants.placeholders.lowercase.first}.${constants.placeholders.lowercase.company}.com/launcher/10/${LauncherLib.getConfig('lang.launcher')}?api_url=https%3A%2F%2Fapi-os-takumi.${constants.placeholders.lowercase.company}.com%2Fhk4e_global&key=gcStgarh&prev=false`; $('#launcher-content #social').attr('src', socialUri); } - public static updateLang (lang: string|null = null): void + public static updateLang(lang: string|null = null): void { if (lang !== null) this.i18n.setLang(lang); diff --git a/src/ts/settings.ts b/src/ts/settings.ts index bbfd5da..8ace0ba 100644 --- a/src/ts/settings.ts +++ b/src/ts/settings.ts @@ -34,6 +34,26 @@ $(() => { $(`.menu-item[anchor=${anchor}]`).addClass('menu-item-active'); }); + /** + * Statistics + */ + + const playedHours = Math.floor(LauncherLib.getConfig('playtime') / 3600); + const playedMinutes = Math.floor((LauncherLib.getConfig('playtime') - playedHours * 3600) / 60); + + $('#play-hours').text(playedHours.toString()); + $('#play-minutes').text(playedMinutes.toString()); + + const levelHours = (level: number) => 0.000441332 * Math.pow(level + 10, 3.10628); + + let level = 1; + + while (level < 91 && levelHours(level) < playedHours) + ++level; + + $('.launcher-stats .level').text(level.toString()); + $('.launcher-stats .level').attr('data-hint', LauncherUI.i18n.translate('YourLauncherLevel')); + /** * Launcher language */ @@ -241,6 +261,14 @@ $(() => { for (const gpu of gpus.value) $(`
  • ${gpu.Name.value}
  • `).appendTo('#gpu .select-options ul'); + + SwitcherooControl.getGpuByName(LauncherLib.getConfig('gpu')).then((gpu) => { + if (gpu) + { + $(`#gpu li[value=${gpu.Name.value}]`).addClass('selected'); + $('#gpu .selected-item span').text(gpu.Name.value); + } + }); } }, () => { console.log('switcheroo-control not running'); @@ -368,16 +396,6 @@ $(() => { td.last().find('span').text(value); }); - /** - * Statistics - */ - - const playedHours = Math.floor(LauncherLib.getConfig('playtime') / 3600); - const playedMinutes = Math.floor((LauncherLib.getConfig('playtime') - playedHours * 3600) / 60); - - $('#play-hours').text(playedHours.toString()); - $('#play-minutes').text(playedMinutes.toString()); - /** * Wine recommendable only */