From d2eea7382c0b49280a50342032f7065cdd3b4fe1 Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Tue, 20 Dec 2022 01:22:09 +0100 Subject: [PATCH] Updater is almost done --- buildnumber.txt | 2 +- source/funkin/system/Main.hx | 3 +++ source/funkin/updating/AsyncUpdater.hx | 17 ++++++++++++++--- source/funkin/updating/UpdateUtil.hx | 11 +++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/buildnumber.txt b/buildnumber.txt index 5e1a2736..a907bf03 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1565 \ No newline at end of file +1571 \ No newline at end of file diff --git a/source/funkin/system/Main.hx b/source/funkin/system/Main.hx index e7dfad85..dbaf70f4 100644 --- a/source/funkin/system/Main.hx +++ b/source/funkin/system/Main.hx @@ -132,6 +132,9 @@ class Main extends Sprite #end Paths.assetsTree = new AssetsLibraryList(); + #if UPDATE_CHECKING + funkin.updating.UpdateUtil.init(); + #end CrashHandler.init(); Logs.init(); Paths.init(); diff --git a/source/funkin/updating/AsyncUpdater.hx b/source/funkin/updating/AsyncUpdater.hx index 2d044c3a..a3110cd4 100644 --- a/source/funkin/updating/AsyncUpdater.hx +++ b/source/funkin/updating/AsyncUpdater.hx @@ -1,5 +1,6 @@ package funkin.updating; +import sys.io.Process; import haxe.zip.Reader; import funkin.system.ZipUtils; import haxe.io.Path; @@ -47,7 +48,7 @@ class AsyncUpdater { public function installFiles(files:Array) { progress.step = INSTALLING; - progress.files = files.length; + progress.files = files.length+1; for(k=>e in files) { var path = '$path$e'; progress.curFile = k+1; @@ -57,6 +58,16 @@ class AsyncUpdater { progress.curZipProgress = new ZipProgress(); ZipUtils.uncompressZip(reader, './', null, progress.curZipProgress); } + + var progPath = Sys.programPath(); + var bakFile = '${Path.withoutExtension(progPath)}.bak'; + if (FileSystem.exists(bakFile)) + FileSystem.deleteFile(bakFile); + FileSystem.rename(progPath, bakFile); + FileSystem.rename('$path$executableName', progPath); + + Sys.command('start /B $executableName'); + openfl.system.System.exit(0); } public function downloadFiles() { @@ -82,11 +93,11 @@ class AsyncUpdater { progress.files = 1; progress.step = DOWNLOADING_EXECUTABLE; trace('starting exe download'); - doFile([exePath], [executableName], function() { + // doFile([exePath], [executableName], function() { trace('done, starting installation'); installFiles(fileNames); progress.done = true; - }); + // }); }); } diff --git a/source/funkin/updating/UpdateUtil.hx b/source/funkin/updating/UpdateUtil.hx index 9e052c82..f29a2b05 100644 --- a/source/funkin/updating/UpdateUtil.hx +++ b/source/funkin/updating/UpdateUtil.hx @@ -1,5 +1,7 @@ package funkin.updating; +import sys.FileSystem; +import haxe.io.Path; import funkin.github.GitHubRelease; import funkin.github.GitHub; import lime.app.Application; @@ -7,6 +9,15 @@ import lime.app.Application; using funkin.github.GitHub; class UpdateUtil { + public static function init() { + // deletes old bak file if it exists + #if sys + var bakPath = '${Path.withoutExtension(Sys.programPath())}.bak'; + if (FileSystem.exists(bakPath)) + FileSystem.deleteFile(bakPath); + #end + } + public static function checkForUpdates():UpdateCheckCallback { var curTag = 'v${Application.current.meta.get('version')}'; trace(curTag);