From 3b987f59e04d8435a8b5a66ca6f968b339ddbdc4 Mon Sep 17 00:00:00 2001
From: oldnapalm <38410858+oldnapalm@users.noreply.github.com>
Date: Fri, 14 Jul 2023 09:43:00 -0300
Subject: [PATCH] Remove update menu
---
RageCoop.Client/Menus/CoopMenu.cs | 2 -
RageCoop.Client/Menus/Sub/UpdateMenu.cs | 105 ------------------------
RageCoop.Client/RageCoop.Client.csproj | 1 -
3 files changed, 108 deletions(-)
delete mode 100644 RageCoop.Client/Menus/Sub/UpdateMenu.cs
diff --git a/RageCoop.Client/Menus/CoopMenu.cs b/RageCoop.Client/Menus/CoopMenu.cs
index 76ce769..026421b 100644
--- a/RageCoop.Client/Menus/CoopMenu.cs
+++ b/RageCoop.Client/Menus/CoopMenu.cs
@@ -68,7 +68,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);
@@ -76,7 +75,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/RageCoop.Client/Menus/Sub/UpdateMenu.cs b/RageCoop.Client/Menus/Sub/UpdateMenu.cs
deleted file mode 100644
index 8ea727e..0000000
--- a/RageCoop.Client/Menus/Sub/UpdateMenu.cs
+++ /dev/null
@@ -1,105 +0,0 @@
-using ICSharpCode.SharpZipLib.Zip;
-using LemonUI.Menus;
-using System;
-using System.Drawing;
-using System.IO;
-using System.Net;
-using System.Threading.Tasks;
-
-namespace RageCoop.Client.Menus
-{
- internal class UpdateMenu
- {
- public static bool IsUpdating { get; private set; } = false;
- 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 ? GTA.UI.Alignment.Right : GTA.UI.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;
- }
-
- private static void StartUpdate(object sender, EventArgs e)
- {
- IsUpdating = true;
- Menu.Clear();
- Menu.Add(_updatingItem);
- Task.Run(() =>
- {
- try
- {
- if (File.Exists(_downloadPath)) { File.Delete(_downloadPath); }
- WebClient client = new WebClient();
-
- // TLS only
- ServicePointManager.Expect100Continue = true;
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12;
- ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
-
- client.DownloadProgressChanged += (s, e1) => { Main.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
- {
- Main.QueueAction(() =>
- {
- _updatingItem.AltTitle = "Installing...";
- });
- Directory.CreateDirectory(@"Scripts\RageCoop");
- foreach (var f in Directory.GetFiles(@"Scripts\RageCoop", "*.dll", SearchOption.AllDirectories))
- {
- try { File.Delete(f); }
- catch { }
- }
- new FastZip().ExtractZip(_downloadPath, "Scripts", FastZip.Overwrite.Always, null, null, null, true);
- try { File.Delete(_downloadPath); } catch { }
- try { File.Delete(Path.Combine("Scripts", "RageCoop.Client.Installer.exe")); } catch { }
- Main.QueueAction(() =>
- {
- Util.Reload();
- IsUpdating = false;
- });
- }
- catch (Exception ex)
- {
- Main.Logger.Error(ex);
- }
- }
-
- private static void Opening(object sender, System.ComponentModel.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);
- }
- }
- }
-}
diff --git a/RageCoop.Client/RageCoop.Client.csproj b/RageCoop.Client/RageCoop.Client.csproj
index 8311337..d0d44ef 100644
--- a/RageCoop.Client/RageCoop.Client.csproj
+++ b/RageCoop.Client/RageCoop.Client.csproj
@@ -36,7 +36,6 @@
-