Add resuming downloads

This commit is contained in:
Laurin Neff 2021-11-27 20:18:48 +01:00
parent bff274e001
commit 3bfa0dfb9f
No known key found for this signature in database
GPG key ID: ACC6088154D0F6C7
16 changed files with 38 additions and 5 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,8 @@
const { ipcRenderer } = require('electron');
import $ from 'cash-dom';
import path from 'path';
import fs from 'fs';
import constants from './constants';
import LauncherLib from './LauncherLib';
@ -15,6 +17,7 @@ type LauncherState =
'game-update-available' |
'game-installation-available' |
'game-voice-update-required' |
'download-resumable' |
'game-launch-available';
type Theme = 'light' | 'dark';
@ -99,6 +102,8 @@ export default class LauncherUI
$('#launch').text(this.i18n.translate('Launch'));
break;
case 'download-resumable':
$('#launch').text(this.i18n.translate('ResumeDownload'));
}
this._launcherState = state;
@ -110,8 +115,11 @@ export default class LauncherUI
const patchInfo = await LauncherLib.getPatchInfo();
// Update available
if (LauncherLib.version != gameData.game.latest.version)
this.setState(LauncherLib.version === null ? 'game-installation-available' : 'game-update-available');
if (LauncherLib.version != gameData.game.latest.version) {
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
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>
{
return new Promise((resolve, reject) => {
https.get(uri, (response: any) => {
let length = parseInt(response.headers['content-length'], 10),
total = 0;
let rangeStart = 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) => {
total += chunk.length;