From 8ab59cde4c8ef5ef9df73becfd6ba43be53bc32c Mon Sep 17 00:00:00 2001 From: Natsumi Date: Tue, 3 Aug 2021 23:48:41 +1200 Subject: [PATCH] VRCX self updater 1 --- AppApi.cs | 4 +-- AssetBundleCacher.cs | 2 +- Update.cs | 72 +++++++++++--------------------------------- html/src/app.js | 25 +++++++-------- 4 files changed, 33 insertions(+), 70 deletions(-) diff --git a/AppApi.cs b/AppApi.cs index f7f0bf99..f8191a61 100644 --- a/AppApi.cs +++ b/AppApi.cs @@ -299,7 +299,7 @@ namespace VRCX public void DownloadVRCXUpdate(string url, string AppVersion) { - var Location = Path.Combine(Program.BaseDirectory, "update.zip"); + var Location = Path.Combine(Program.AppDataDirectory, "update.exe"); WebClient client = new WebClient(); client.Headers.Add("user-agent", AppVersion); client.DownloadFile(new System.Uri(url), Location); @@ -316,7 +316,7 @@ namespace VRCX public bool checkForUpdateZip() { - if (File.Exists(Path.Combine(Program.BaseDirectory, "update.zip"))) + if (File.Exists(Path.Combine(Program.AppDataDirectory, "update.exe"))) return true; return false; } diff --git a/AssetBundleCacher.cs b/AssetBundleCacher.cs index 86cee8f6..e056089e 100644 --- a/AssetBundleCacher.cs +++ b/AssetBundleCacher.cs @@ -156,7 +156,7 @@ namespace VRCX if (IsUpdate) { AssetBundleCacher.IsUpdate = true; - DownloadTempLocation = Path.Combine(Program.BaseDirectory, "update.zip"); + DownloadTempLocation = Path.Combine(Program.AppDataDirectory, "update.exe"); } client = new WebClient(); client.Headers.Add("user-agent", AppVersion); diff --git a/Update.cs b/Update.cs index e7960055..7f107ec7 100644 --- a/Update.cs +++ b/Update.cs @@ -1,11 +1,10 @@ -// Copyright(c) 2019-2021 pypy. All rights reserved. +// Copyright(c) 2019-2021 pypy. All rights reserved. // // This work is licensed under the terms of the MIT license. // For a copy, see . using System; using System.IO; -using System.IO.Compression; using System.Windows.Forms; namespace VRCX @@ -13,67 +12,30 @@ namespace VRCX class Update { public static void Check() + { + if (File.Exists(Path.Combine(Program.AppDataDirectory, "VRCX_Setup.exe"))) + File.Delete(Path.Combine(Program.AppDataDirectory, "VRCX_Setup.exe")); + if (File.Exists(Path.Combine(Program.AppDataDirectory, "update.exe"))) + Install(); + } + + public static void Install() { try { - var CurrentDirectory = new DirectoryInfo(Program.BaseDirectory); - FileInfo[] Files = CurrentDirectory.GetFiles(); - foreach (FileInfo FileDetails in Files) - { - var FilePath = Path.Combine(Program.BaseDirectory, FileDetails.Name); - if (FileDetails.Extension == ".old") - File.Delete(FilePath); - } - var Location = Path.Combine(Program.BaseDirectory, "update.zip"); - if (File.Exists(Location)) - Install(); + if (!File.Exists(Path.Combine(Program.AppDataDirectory, "update.exe"))) + return; + File.Move(Path.Combine(Program.AppDataDirectory, "update.exe"), Path.Combine(Program.AppDataDirectory, "VRCX_Setup.exe")); + System.Diagnostics.Process VRCXProcess = new System.Diagnostics.Process(); + VRCXProcess.StartInfo.FileName = Path.Combine(Program.AppDataDirectory, "VRCX_Setup.exe"); + VRCXProcess.StartInfo.Arguments = "/S"; + VRCXProcess.Start(); + System.Environment.Exit(0); } catch (Exception e) { MessageBox.Show(e.ToString(), "Update failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - - public static void Install() - { - var Location = Path.Combine(Program.BaseDirectory, "update.zip"); - if (!File.Exists(Location)) - return; - if (File.Exists(Path.Combine(Program.BaseDirectory, "VRCX.exe.old"))) - File.Delete(Path.Combine(Program.BaseDirectory, "VRCX.exe.old")); - if (File.Exists(Path.Combine(Program.BaseDirectory, "VRCX.exe"))) - File.Move(Path.Combine(Program.BaseDirectory, "VRCX.exe"), Path.Combine(Program.BaseDirectory, "VRCX.exe.old")); - var CurrentDirectory = new DirectoryInfo(Program.BaseDirectory); - FileInfo[] Files = CurrentDirectory.GetFiles(); - foreach (FileInfo FileDetails in Files) - { - var FilePath = Path.Combine(Program.BaseDirectory, $"{FileDetails.Name}.old"); - if (FileDetails.Extension == ".dll") - { - if (File.Exists(FilePath)) - File.Delete(FilePath); - File.Move(Path.Combine(Program.BaseDirectory, FileDetails.Name), FilePath); - } - } - using (ZipArchive archive = ZipFile.OpenRead(Location)) - { - foreach (ZipArchiveEntry entry in archive.Entries) - { - var path = Path.Combine(Program.BaseDirectory, entry.FullName); - if (entry.Name == "") - { - Directory.CreateDirectory(Path.GetDirectoryName(path)); - continue; - } - entry.ExtractToFile(path, true); - } - } - File.Delete(Location); - System.Diagnostics.Process VRCXProcess = new System.Diagnostics.Process(); - VRCXProcess.StartInfo.FileName = Path.Combine(Program.BaseDirectory, "VRCX.exe"); - VRCXProcess.StartInfo.UseShellExecute = false; - VRCXProcess.Start(); - System.Environment.Exit(0); - } } } diff --git a/html/src/app.js b/html/src/app.js index f85bb8e6..3870b3d9 100644 --- a/html/src/app.js +++ b/html/src/app.js @@ -13234,8 +13234,8 @@ speechSynthesis.getVoices(); $app.data.checkingForVRCXUpdate = false; $app.data.branches = { - Stable: { name: 'Stable', urlReleases: 'https://api.github.com/repos/pypy-vrc/VRCX/releases', urlLatest: 'https://api.github.com/repos/pypy-vrc/VRCX/releases/latest' }, - Beta: { name: 'Beta', urlReleases: 'https://api.github.com/repos/natsumi-sama/VRCX/releases', urlLatest: 'https://api.github.com/repos/natsumi-sama/VRCX/releases/latest' } + Stable: { name: 'Stable', urlReleases: 'https://vrcx.pypy.moe/releases/pypy-vrc.json', urlLatest: 'https://vrcx.pypy.moe/releases/latest/pypy-vrc.json' }, + Beta: { name: 'Beta', urlReleases: 'https://vrcx.pypy.moe/releases/natsumi-sama.json', urlLatest: 'https://vrcx.pypy.moe/releases/latest/natsumi-sama.json' } }; $app.methods.showVRCXUpdateDialog = async function () { @@ -13320,25 +13320,26 @@ speechSynthesis.getVoices(); json.published_at) { this.latestAppVersion = `${json.name} (${formatDate(json.published_at, 'YYYY-MM-DD HH24:MI:SS')})`; if (json.name > this.appVersion) { - if ((json.assets[0].content_type !== 'application/x-zip-compressed') || (json.assets[0].state !== 'uploaded')) { + for (var asset of json.assets) { + if ((asset.content_type === 'application/octet-stream') && (asset.state === 'uploaded')) { + var downloadUrl = asset.browser_download_url; + break; + } + } + if (!downloadUrl) { return; } this.notifyMenu('settings'); - var downloadUrl = json.assets[0].browser_download_url; var name = json.name; var type = 'Auto'; if (this.autoUpdateVRCX === 'Notify') { this.showVRCXUpdateDialog(); } else if (this.autoUpdateVRCX === 'Auto Download') { - if (downloadUrl) { - var autoInstall = false; - this.downloadVRCXUpdate(downloadUrl, name, type, autoInstall); - } + var autoInstall = false; + this.downloadVRCXUpdate(downloadUrl, name, type, autoInstall); } else if (this.autoUpdateVRCX === 'Auto Install') { - if (downloadUrl) { - var autoInstall = true; - this.downloadVRCXUpdate(downloadUrl, name, type, autoInstall); - } + var autoInstall = true; + this.downloadVRCXUpdate(downloadUrl, name, type, autoInstall); } } } else {