Merge branch 'main' into 'main'

Add resuming downloads

See merge request KRypt0n_/an-anime-game-launcher!2
This commit is contained in:
Observer KRypt0n_ 2021-11-27 19:27:30 +00:00
commit 83d3e7ef74
16 changed files with 38 additions and 5 deletions

View file

@ -2,6 +2,7 @@
"Install": "Installieren", "Install": "Installieren",
"Update": "Updaten", "Update": "Updaten",
"Launch": "Starten", "Launch": "Starten",
"ResumeDownload": "Download Fortsetzen",
"Runners": "Runners", "Runners": "Runners",
"Language": "Sprache", "Language": "Sprache",
"Voice": "Sprachpaket", "Voice": "Sprachpaket",

View file

@ -2,6 +2,7 @@
"Install": "Install", "Install": "Install",
"Update": "Update", "Update": "Update",
"Launch": "Launch", "Launch": "Launch",
"ResumeDownload": "Resume Download",
"Runners": "Runners", "Runners": "Runners",
"Language": "Language", "Language": "Language",
"Voice": "Voice Pack", "Voice": "Voice Pack",

View file

@ -2,6 +2,7 @@
"Install": "Install", "Install": "Install",
"Update": "Update", "Update": "Update",
"Launch": "Launch", "Launch": "Launch",
"ResumeDownload": "Resume Download",
"Runners": "Runners", "Runners": "Runners",
"Language": "Language", "Language": "Language",
"Voice": "Voice Pack", "Voice": "Voice Pack",

View file

@ -2,6 +2,7 @@
"Install": "Install", "Install": "Install",
"Update": "Update", "Update": "Update",
"Launch": "Launch", "Launch": "Launch",
"ResumeDownload": "Resume Download",
"Runners": "Runners", "Runners": "Runners",
"Language": "Language", "Language": "Language",
"Voice": "Voice Pack", "Voice": "Voice Pack",

View file

@ -2,6 +2,7 @@
"Install": "Install", "Install": "Install",
"Update": "Update", "Update": "Update",
"Launch": "Launch", "Launch": "Launch",
"ResumeDownload": "Resume Download",
"Runners": "Runners", "Runners": "Runners",
"Language": "Language", "Language": "Language",
"Voice": "Voice Pack", "Voice": "Voice Pack",

View file

@ -2,6 +2,7 @@
"Install": "Pasang", "Install": "Pasang",
"Update": "Perbarui", "Update": "Perbarui",
"Launch": "Luncurkan", "Launch": "Luncurkan",
"ResumeDownload": "Resume Download",
"Runners": "Runners", "Runners": "Runners",
"Language": "Bahasa", "Language": "Bahasa",
"Voice": "Paket Suara", "Voice": "Paket Suara",

View file

@ -2,6 +2,7 @@
"Install": "インストール", "Install": "インストール",
"Update": "アップデート", "Update": "アップデート",
"Launch": "打ち上げ", "Launch": "打ち上げ",
"ResumeDownload": "Resume Download",
"Runners": "Runners", "Runners": "Runners",
"Language": "言語", "Language": "言語",
"Voice": "ボイスパック", "Voice": "ボイスパック",

View file

@ -2,6 +2,7 @@
"Install": "설치", "Install": "설치",
"Update": "업데이트", "Update": "업데이트",
"Launch": "발사", "Launch": "발사",
"ResumeDownload": "Resume Download",
"Runners": "주자", "Runners": "주자",
"Language": "언어", "Language": "언어",
"Voice": "음성 팩", "Voice": "음성 팩",

View file

@ -2,6 +2,7 @@
"Install": "Install", "Install": "Install",
"Update": "Update", "Update": "Update",
"Launch": "Launch", "Launch": "Launch",
"ResumeDownload": "Resume Download",
"Runners": "Runners", "Runners": "Runners",
"Language": "Language", "Language": "Language",
"Voice": "Voice Pack", "Voice": "Voice Pack",

View file

@ -2,6 +2,7 @@
"Install": "Установить", "Install": "Установить",
"Update": "Обновить", "Update": "Обновить",
"Launch": "Запустить", "Launch": "Запустить",
"ResumeDownload": "Resume Download",
"Runners": "Версии Wine", "Runners": "Версии Wine",
"Language": "Язык", "Language": "Язык",
"Voice": "Озвучка", "Voice": "Озвучка",

View file

@ -2,6 +2,7 @@
"Install": "Install", "Install": "Install",
"Update": "Update", "Update": "Update",
"Launch": "Launch", "Launch": "Launch",
"ResumeDownload": "Resume Download",
"Runners": "Runners", "Runners": "Runners",
"Language": "Language", "Language": "Language",
"Voice": "Voice Pack", "Voice": "Voice Pack",

View file

@ -2,6 +2,7 @@
"Install": "Install", "Install": "Install",
"Update": "Update", "Update": "Update",
"Launch": "Launch", "Launch": "Launch",
"ResumeDownload": "Resume Download",
"Runners": "Runners", "Runners": "Runners",
"Language": "Language", "Language": "Language",
"Voice": "Voice Pack", "Voice": "Voice Pack",

View file

@ -2,6 +2,7 @@
"Install": "安装", "Install": "安装",
"Update": "更新", "Update": "更新",
"Launch": "发射", "Launch": "发射",
"ResumeDownload": "Resume Download",
"Runners": "Runners", "Runners": "Runners",
"Language": "语言", "Language": "语言",
"Voice": "语音包", "Voice": "语音包",

View file

@ -2,6 +2,7 @@
"Install": "安裝", "Install": "安裝",
"Update": "更新", "Update": "更新",
"Launch": "啟動遊戲", "Launch": "啟動遊戲",
"ResumeDownload": "Resume Download",
"Runners": "執行器", "Runners": "執行器",
"Language": "界面語言", "Language": "界面語言",
"Voice": "語音包", "Voice": "語音包",

View file

@ -1,6 +1,8 @@
const { ipcRenderer } = require('electron'); const { ipcRenderer } = require('electron');
import $ from 'cash-dom'; import $ from 'cash-dom';
import path from 'path';
import fs from 'fs';
import constants from './constants'; import constants from './constants';
import LauncherLib from './LauncherLib'; import LauncherLib from './LauncherLib';
@ -15,6 +17,7 @@ type LauncherState =
'game-update-available' | 'game-update-available' |
'game-installation-available' | 'game-installation-available' |
'game-voice-update-required' | 'game-voice-update-required' |
'download-resumable' |
'game-launch-available'; 'game-launch-available';
type Theme = 'light' | 'dark'; type Theme = 'light' | 'dark';
@ -99,6 +102,8 @@ export default class LauncherUI
$('#launch').text(this.i18n.translate('Launch')); $('#launch').text(this.i18n.translate('Launch'));
break; break;
case 'download-resumable':
$('#launch').text(this.i18n.translate('ResumeDownload'));
} }
this._launcherState = state; this._launcherState = state;
@ -110,8 +115,11 @@ export default class LauncherUI
const patchInfo = await LauncherLib.getPatchInfo(); const patchInfo = await LauncherLib.getPatchInfo();
// Update available // Update available
if (LauncherLib.version != gameData.game.latest.version) if (LauncherLib.version != gameData.game.latest.version) {
this.setState(LauncherLib.version === null ? 'game-installation-available' : 'game-update-available'); if(!fs.existsSync(path.join(constants.launcherDir, `latest-${gameData.game.latest.version}.zip`)))
this.setState(LauncherLib.version === null ? 'game-installation-available' : 'game-update-available');
else this.setState('download-resumable');
}
// Voice pack update required // Voice pack update required
else if (LauncherLib.getConfig('lang.voice.active') != LauncherLib.getConfig('lang.voice.installed')) else if (LauncherLib.getConfig('lang.voice.active') != LauncherLib.getConfig('lang.voice.installed'))

View file

@ -126,9 +126,20 @@ export default class Tools
public static async downloadFile (uri: string, savePath: string, progress: null|((current: number, total: number, difference: number) => void) = null): Promise<void|Error> public static async downloadFile (uri: string, savePath: string, progress: null|((current: number, total: number, difference: number) => void) = null): Promise<void|Error>
{ {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
https.get(uri, (response: any) => { let rangeStart = 0;
let length = parseInt(response.headers['content-length'], 10),
total = 0; if(fs.existsSync(savePath)) {
// Part of the file was already downloaded, resume the download
rangeStart = fs.statSync(savePath).size;
}
https.get(uri, {
headers: {
Range: `bytes=${rangeStart}-`
}
}, (response: any) => {
let length = parseInt(response.headers['content-length'], 10) + rangeStart,
total = rangeStart;
response.on('data', (chunk: any) => { response.on('data', (chunk: any) => {
total += chunk.length; total += chunk.length;