VRCX self updater 1

This commit is contained in:
Natsumi
2021-08-03 23:48:41 +12:00
parent f0c8e27e40
commit 8ab59cde4c
4 changed files with 33 additions and 70 deletions

View File

@@ -299,7 +299,7 @@ namespace VRCX
public void DownloadVRCXUpdate(string url, string AppVersion) 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(); WebClient client = new WebClient();
client.Headers.Add("user-agent", AppVersion); client.Headers.Add("user-agent", AppVersion);
client.DownloadFile(new System.Uri(url), Location); client.DownloadFile(new System.Uri(url), Location);
@@ -316,7 +316,7 @@ namespace VRCX
public bool checkForUpdateZip() public bool checkForUpdateZip()
{ {
if (File.Exists(Path.Combine(Program.BaseDirectory, "update.zip"))) if (File.Exists(Path.Combine(Program.AppDataDirectory, "update.exe")))
return true; return true;
return false; return false;
} }

View File

@@ -156,7 +156,7 @@ namespace VRCX
if (IsUpdate) if (IsUpdate)
{ {
AssetBundleCacher.IsUpdate = true; AssetBundleCacher.IsUpdate = true;
DownloadTempLocation = Path.Combine(Program.BaseDirectory, "update.zip"); DownloadTempLocation = Path.Combine(Program.AppDataDirectory, "update.exe");
} }
client = new WebClient(); client = new WebClient();
client.Headers.Add("user-agent", AppVersion); client.Headers.Add("user-agent", AppVersion);

View File

@@ -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. // This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>. // For a copy, see <https://opensource.org/licenses/MIT>.
using System; using System;
using System.IO; using System.IO;
using System.IO.Compression;
using System.Windows.Forms; using System.Windows.Forms;
namespace VRCX namespace VRCX
@@ -13,67 +12,30 @@ namespace VRCX
class Update class Update
{ {
public static void Check() 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 try
{ {
var CurrentDirectory = new DirectoryInfo(Program.BaseDirectory); if (!File.Exists(Path.Combine(Program.AppDataDirectory, "update.exe")))
FileInfo[] Files = CurrentDirectory.GetFiles(); return;
foreach (FileInfo FileDetails in Files) File.Move(Path.Combine(Program.AppDataDirectory, "update.exe"), Path.Combine(Program.AppDataDirectory, "VRCX_Setup.exe"));
{ System.Diagnostics.Process VRCXProcess = new System.Diagnostics.Process();
var FilePath = Path.Combine(Program.BaseDirectory, FileDetails.Name); VRCXProcess.StartInfo.FileName = Path.Combine(Program.AppDataDirectory, "VRCX_Setup.exe");
if (FileDetails.Extension == ".old") VRCXProcess.StartInfo.Arguments = "/S";
File.Delete(FilePath); VRCXProcess.Start();
} System.Environment.Exit(0);
var Location = Path.Combine(Program.BaseDirectory, "update.zip");
if (File.Exists(Location))
Install();
} }
catch (Exception e) catch (Exception e)
{ {
MessageBox.Show(e.ToString(), "Update failed", MessageBoxButtons.OK, MessageBoxIcon.Error); 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);
}
} }
} }

View File

@@ -13234,8 +13234,8 @@ speechSynthesis.getVoices();
$app.data.checkingForVRCXUpdate = false; $app.data.checkingForVRCXUpdate = false;
$app.data.branches = { $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' }, 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://api.github.com/repos/natsumi-sama/VRCX/releases', urlLatest: 'https://api.github.com/repos/natsumi-sama/VRCX/releases/latest' } 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 () { $app.methods.showVRCXUpdateDialog = async function () {
@@ -13320,25 +13320,26 @@ speechSynthesis.getVoices();
json.published_at) { json.published_at) {
this.latestAppVersion = `${json.name} (${formatDate(json.published_at, 'YYYY-MM-DD HH24:MI:SS')})`; this.latestAppVersion = `${json.name} (${formatDate(json.published_at, 'YYYY-MM-DD HH24:MI:SS')})`;
if (json.name > this.appVersion) { 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; return;
} }
this.notifyMenu('settings'); this.notifyMenu('settings');
var downloadUrl = json.assets[0].browser_download_url;
var name = json.name; var name = json.name;
var type = 'Auto'; var type = 'Auto';
if (this.autoUpdateVRCX === 'Notify') { if (this.autoUpdateVRCX === 'Notify') {
this.showVRCXUpdateDialog(); this.showVRCXUpdateDialog();
} else if (this.autoUpdateVRCX === 'Auto Download') { } else if (this.autoUpdateVRCX === 'Auto Download') {
if (downloadUrl) { var autoInstall = false;
var autoInstall = false; this.downloadVRCXUpdate(downloadUrl, name, type, autoInstall);
this.downloadVRCXUpdate(downloadUrl, name, type, autoInstall);
}
} else if (this.autoUpdateVRCX === 'Auto Install') { } else if (this.autoUpdateVRCX === 'Auto Install') {
if (downloadUrl) { var autoInstall = true;
var autoInstall = true; this.downloadVRCXUpdate(downloadUrl, name, type, autoInstall);
this.downloadVRCXUpdate(downloadUrl, name, type, autoInstall);
}
} }
} }
} else { } else {