From 822a69573ffb40b144e3824ac5dfc431d94a19c5 Mon Sep 17 00:00:00 2001 From: sardelka9515 Date: Sun, 13 Nov 2022 17:06:27 +0800 Subject: [PATCH] Remove update menu --- Client/Scripts/Menus/CoopMenu.cs | 2 - Client/Scripts/Menus/Sub/UpdateMenu.cs | 134 ------------------------- 2 files changed, 136 deletions(-) delete mode 100644 Client/Scripts/Menus/Sub/UpdateMenu.cs diff --git a/Client/Scripts/Menus/CoopMenu.cs b/Client/Scripts/Menus/CoopMenu.cs index f85b952..5d7ed30 100644 --- a/Client/Scripts/Menus/CoopMenu.cs +++ b/Client/Scripts/Menus/CoopMenu.cs @@ -60,7 +60,6 @@ namespace RageCoop.Client.Menus Menu.AddSubMenu(SettingsMenu.Menu); Menu.AddSubMenu(DevToolMenu.Menu); Menu.AddSubMenu(DebugMenu.Menu); - Menu.AddSubMenu(UpdateMenu.Menu); MenuPool.Add(Menu); MenuPool.Add(SettingsMenu.Menu); @@ -68,7 +67,6 @@ namespace RageCoop.Client.Menus MenuPool.Add(DebugMenu.Menu); MenuPool.Add(DebugMenu.DiagnosticMenu); MenuPool.Add(ServersMenu.Menu); - MenuPool.Add(UpdateMenu.Menu); MenuPool.Add(PopUp); Menu.Add(_aboutItem); diff --git a/Client/Scripts/Menus/Sub/UpdateMenu.cs b/Client/Scripts/Menus/Sub/UpdateMenu.cs deleted file mode 100644 index 9a89052..0000000 --- a/Client/Scripts/Menus/Sub/UpdateMenu.cs +++ /dev/null @@ -1,134 +0,0 @@ -using System; -using System.ComponentModel; -using System.Drawing; -using System.IO; -using System.Net; -using System.Threading.Tasks; -using GTA.UI; -using ICSharpCode.SharpZipLib.Zip; -using LemonUI.Menus; -using RageCoop.Client.Loader; -using RageCoop.Client.Scripting; -using RageCoop.Core; - -namespace RageCoop.Client.Menus -{ - internal class UpdateMenu - { - private static readonly NativeItem _updatingItem = new NativeItem("Updating..."); - - private static readonly NativeItem _downloadItem = - new NativeItem("Download", "Download and update to latest nightly"); - - private static readonly string _downloadPath = Path.Combine(Main.Settings.DataDirectory, "RageCoop.Client.zip"); - - public static NativeMenu Menu = - new NativeMenu("Update", "Update", "Download and install latest nightly build from GitHub") - { - UseMouse = false, - Alignment = Main.Settings.FlipMenu ? Alignment.Right : Alignment.Left - }; - - static UpdateMenu() - { - Menu.Banner.Color = Color.FromArgb(225, 0, 0, 0); - Menu.Title.Color = Color.FromArgb(255, 165, 0); - Menu.Opening += Opening; - _downloadItem.Activated += StartUpdate; - } - - public static bool IsUpdating { get; private set; } - - private static void StartUpdate(object sender, EventArgs e) - { - if (CoreUtils.GetLatestVersion() < Main.Version) - { - Notification.Show("Local version is newer than remote version, update can't continue"); - return; - } - - IsUpdating = true; - Menu.Clear(); - Menu.Add(_updatingItem); - Task.Run(() => - { - try - { - if (File.Exists(_downloadPath)) File.Delete(_downloadPath); - var client = new WebClient(); - - // TLS only - ServicePointManager.Expect100Continue = true; - ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12; - ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; - - client.DownloadProgressChanged += (s, e1) => - { - API.QueueAction(() => { _updatingItem.AltTitle = $"{e1.ProgressPercentage}%"; }); - }; - client.DownloadFileCompleted += (s, e2) => { Install(); }; - client.DownloadFileAsync( - new Uri("https://github.com/RAGECOOP/RAGECOOP-V/releases/download/nightly/RageCoop.Client.zip"), - _downloadPath); - } - catch (Exception ex) - { - Main.Logger.Error(ex); - } - }); - } - - private static void Install() - { - try - { - API.QueueAction(() => { _updatingItem.AltTitle = "Installing..."; }); - var insatllPath = @"RageCoop\Scripts"; - Directory.CreateDirectory(insatllPath); - foreach (var f in Directory.GetFiles(insatllPath, "*.dll", SearchOption.AllDirectories)) - try - { - File.Delete(f); - } - catch - { - } - - new FastZip().ExtractZip(_downloadPath, insatllPath, FastZip.Overwrite.Always, null, null, null, true); - try - { - File.Delete(_downloadPath); - } - catch - { - } - - try - { - File.Delete(Path.Combine(insatllPath, "RageCoop.Client.Installer.exe")); - } - catch - { - } - - LoaderContext.RequestUnload(); - IsUpdating = false; - } - catch (Exception ex) - { - Main.Logger.Error(ex); - } - } - - private static void Opening(object sender, CancelEventArgs e) - { - Menu.Clear(); - if (Networking.IsOnServer) - Menu.Add(new NativeItem("Disconnect from the server first")); - else if (IsUpdating) - Menu.Add(_updatingItem); - else - Menu.Add(_downloadItem); - } - } -} \ No newline at end of file