updater is done

This commit is contained in:
Yoshman29
2022-12-20 22:22:35 +01:00
parent f85ee1cfe9
commit 41ebe30677
4 changed files with 60 additions and 5 deletions
+1 -1
View File
@@ -1 +1 @@
1590 1596
+2 -2
View File
@@ -68,7 +68,7 @@ class CoolUtil
return str; return str;
} }
public static function getSizeString(size:UInt):String { public static function getSizeString(size:Float):String {
var labels = ["B", "KB", "MB", "GB", "TB"]; var labels = ["B", "KB", "MB", "GB", "TB"];
var rSize:Float = size; var rSize:Float = size;
var label:Int = 0; var label:Int = 0;
@@ -76,7 +76,7 @@ class CoolUtil
label++; label++;
rSize /= 1024; rSize /= 1024;
} }
return '${FlxMath.roundDecimal(rSize, 2)}${labels[label]}'; return '${Std.int(rSize) + "." + addZeros(Std.string(Math.round((rSize % 1) * 100)), 2)}${labels[label]}';
} }
public static function fpsLerp(v1:Float, v2:Float, ratio:Float):Float { public static function fpsLerp(v1:Float, v2:Float, ratio:Float):Float {
+20 -2
View File
@@ -1,5 +1,6 @@
package funkin.updating; package funkin.updating;
import openfl.Lib;
import sys.io.Process; import sys.io.Process;
import haxe.zip.Reader; import haxe.zip.Reader;
import funkin.system.ZipUtils; import funkin.system.ZipUtils;
@@ -41,6 +42,9 @@ class AsyncUpdater {
public var path:String; public var path:String;
public var downloadStream:URLLoader; public var downloadStream:URLLoader;
public var executableReplaced:Bool = false; public var executableReplaced:Bool = false;
public var lastTime:Float = 0;
public var oldBytesLoaded:Float = 0;
public function installUpdates() { public function installUpdates() {
prepareInstallationEnvironment(); prepareInstallationEnvironment();
@@ -84,12 +88,14 @@ class AsyncUpdater {
} }
} }
} }
progress.curFile = 0; progress.curFile = -1;
progress.curFileName = null;
progress.files = files.length; progress.files = files.length;
progress.step = DOWNLOADING_ASSETS; progress.step = DOWNLOADING_ASSETS;
trace('starting assets download'); trace('starting assets download');
doFile([for(e in files) e], [for(e in fileNames) e], function() { doFile([for(e in files) e], [for(e in fileNames) e], function() {
progress.curFile = 0; progress.curFile = -1;
progress.curFileName = null;
progress.files = 1; progress.files = 1;
progress.step = DOWNLOADING_EXECUTABLE; progress.step = DOWNLOADING_EXECUTABLE;
trace('starting exe download'); trace('starting exe download');
@@ -110,6 +116,7 @@ class AsyncUpdater {
var fn = fileNames.shift(); var fn = fileNames.shift();
trace('downloading $f ($fn)'); trace('downloading $f ($fn)');
progress.curFile++; progress.curFile++;
progress.curFileName = fn;
progress.bytesLoaded = 0; progress.bytesLoaded = 0;
progress.bytesTotal = 1; progress.bytesTotal = 1;
downloadStream = new URLLoader(); downloadStream = new URLLoader();
@@ -118,6 +125,13 @@ class AsyncUpdater {
downloadStream.addEventListener(ProgressEvent.PROGRESS, function(e) { downloadStream.addEventListener(ProgressEvent.PROGRESS, function(e) {
progress.bytesLoaded = e.bytesLoaded; progress.bytesLoaded = e.bytesLoaded;
progress.bytesTotal = e.bytesTotal; progress.bytesTotal = e.bytesTotal;
var curTime = Lib.getTimer();
progress.downloadSpeed = (e.bytesLoaded - oldBytesLoaded) / ((curTime - lastTime) / 1000);
lastTime = curTime;
oldBytesLoaded = e.bytesLoaded;
}); });
downloadStream.addEventListener(Event.COMPLETE, function(e) { downloadStream.addEventListener(Event.COMPLETE, function(e) {
var fileOutput:FileOutput = File.write('$path$fn', true); var fileOutput:FileOutput = File.write('$path$fn', true);
@@ -131,6 +145,8 @@ class AsyncUpdater {
doFile(files, fileNames, onFinish); doFile(files, fileNames, onFinish);
}); });
oldBytesLoaded = 0;
lastTime = Lib.getTimer();
downloadStream.load(new URLRequest(f)); downloadStream.load(new URLRequest(f));
} }
@@ -153,6 +169,8 @@ class UpdaterProgress {
public var files:Int = 0; public var files:Int = 0;
public var bytesLoaded:Float = 0; public var bytesLoaded:Float = 0;
public var bytesTotal:Float = 0; public var bytesTotal:Float = 0;
public var downloadSpeed:Float = 0;
public var curFileName:String = "";
public var done:Bool = false; public var done:Bool = false;
public var curZipProgress:ZipProgress = new ZipProgress(); public var curZipProgress:ZipProgress = new ZipProgress();
+37
View File
@@ -1,5 +1,7 @@
package funkin.updating; package funkin.updating;
import flixel.util.FlxDestroyUtil;
import funkin.ui.FunkinText;
import funkin.menus.TitleState; import funkin.menus.TitleState;
import flixel.math.FlxRect; import flixel.math.FlxRect;
import flixel.system.FlxSound; import flixel.system.FlxSound;
@@ -15,8 +17,13 @@ class UpdateScreen extends MusicBeatState {
public var bf:FlxSprite; public var bf:FlxSprite;
public var done:Bool = false; public var done:Bool = false;
public var elapsedTime:Float = 0;
public var lerpSpeed:Float = 0;
public var overSound:FlxSound; public var overSound:FlxSound;
public var generalProgress:FunkinText;
public var partProgress:FunkinText;
public function new(check:UpdateCheckCallback) { public function new(check:UpdateCheckCallback) {
super(false); super(false);
updater = new AsyncUpdater(check.updates); updater = new AsyncUpdater(check.updates);
@@ -39,6 +46,16 @@ class UpdateScreen extends MusicBeatState {
bf.screenCenter(); bf.screenCenter();
add(bf); add(bf);
partProgress = new FunkinText(0, progressBar.y, FlxG.width, "-\n-", 20);
partProgress.y -= partProgress.height;
partProgress.alignment = CENTER;
add(partProgress);
generalProgress = new FunkinText(0, partProgress.y - 10, FlxG.width, "", 32);
generalProgress.y -= generalProgress.height;
generalProgress.alignment = CENTER;
add(generalProgress);
overSound = FlxG.sound.load(Paths.sound('gameOverEnd')); overSound = FlxG.sound.load(Paths.sound('gameOverEnd'));
updater.execute(); updater.execute();
@@ -47,17 +64,30 @@ class UpdateScreen extends MusicBeatState {
public override function update(elapsed:Float) { public override function update(elapsed:Float) {
super.update(elapsed); super.update(elapsed);
elapsedTime += elapsed;
progressBar.y = FlxG.height - (60 + (Math.sin(elapsedTime * Math.PI / 2) * 15));
if (done) return; if (done) return;
var prog = updater.progress; var prog = updater.progress;
lerpSpeed = lerp(lerpSpeed, prog.downloadSpeed, 1/16);
switch(prog.step) { switch(prog.step) {
case PREPARING: case PREPARING:
progressBar.value = 0; progressBar.value = 0;
generalProgress.text = "Preparing update installation... (1/4)";
partProgress.text = "Creating installation folder and cleaning old update files...";
case DOWNLOADING_ASSETS: case DOWNLOADING_ASSETS:
progressBar.value = 1 + ((prog.curFile-1+(prog.bytesLoaded/prog.bytesTotal)) / prog.files); progressBar.value = 1 + ((prog.curFile-1+(prog.bytesLoaded/prog.bytesTotal)) / prog.files);
generalProgress.text = "Download update assets... (2/4)";
partProgress.text = 'Downloading file ${prog.curFileName}\n(${prog.curFile+1}/${prog.files} | ${CoolUtil.getSizeString(prog.bytesLoaded)} / ${CoolUtil.getSizeString(prog.bytesTotal)} | ${CoolUtil.getSizeString(lerpSpeed)}/s)';
case DOWNLOADING_EXECUTABLE: case DOWNLOADING_EXECUTABLE:
progressBar.value = 2 + (prog.bytesLoaded/prog.bytesTotal); progressBar.value = 2 + (prog.bytesLoaded/prog.bytesTotal);
generalProgress.text = "Download new engine executable... (3/4)";
partProgress.text = 'Downloading ${prog.curFileName}\n(${CoolUtil.getSizeString(prog.bytesLoaded)} / ${CoolUtil.getSizeString(prog.bytesTotal)} | ${CoolUtil.getSizeString(lerpSpeed)}/s)';
case INSTALLING: case INSTALLING:
progressBar.value = 3 + ((prog.curFile-1+(prog.curZipProgress.curFile/prog.curZipProgress.fileCount))/prog.files); progressBar.value = 3 + ((prog.curFile-1+(prog.curZipProgress.curFile/prog.curZipProgress.fileCount))/prog.files);
generalProgress.text = "Installing new files... (4/4)";
} }
var rect = new FlxRect(0, (1 - (progressBar.value / 4)) * bf.frameHeight, bf.frameWidth, 0); var rect = new FlxRect(0, (1 - (progressBar.value / 4)) * bf.frameHeight, bf.frameWidth, 0);
rect.height = bf.frameHeight - rect.y; rect.height = bf.frameHeight - rect.y;
@@ -68,9 +98,16 @@ class UpdateScreen extends MusicBeatState {
// update is done, play bf's anim // update is done, play bf's anim
FlxG.sound.music.stop(); FlxG.sound.music.stop();
overSound.play(); overSound.play();
remove(generalProgress);
remove(partProgress);
generalProgress = FlxDestroyUtil.destroy(generalProgress);
partProgress = FlxDestroyUtil.destroy(partProgress);
bf.animation.curAnim.frameRate = 24; bf.animation.curAnim.frameRate = 24;
bf.animation.play("loading-anim", true, false, 1); bf.animation.play("loading-anim", true, false, 1);
bf.alpha = 1; bf.alpha = 1;
FlxG.camera.fade(0xFF000000, overSound.length / 1000, false, function() { FlxG.camera.fade(0xFF000000, overSound.length / 1000, false, function() {
if (updater.executableReplaced) { if (updater.executableReplaced) {
// the executable has been replaced, restart the game entirely // the executable has been replaced, restart the game entirely