This commit is contained in:
sardelka9515
2022-10-23 19:02:39 +08:00
parent 6b34ab6e36
commit 2828b9b74f
114 changed files with 7374 additions and 7205 deletions

View File

@ -1,27 +1,34 @@
using ICSharpCode.SharpZipLib.Zip;
using LemonUI.Menus;
using RageCoop.Client.Scripting;
using RageCoop.Core;
using System;
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
{
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 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
};
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);
@ -30,13 +37,16 @@ namespace RageCoop.Client.Menus
_downloadItem.Activated += StartUpdate;
}
public static bool IsUpdating { get; private set; }
private static void StartUpdate(object sender, EventArgs e)
{
if (CoreUtils.GetLatestVersion() < Main.Version)
{
GTA.UI.Notification.Show("Local version is newer than remote version, update can't continue");
Notification.Show("Local version is newer than remote version, update can't continue");
return;
}
IsUpdating = true;
Menu.Clear();
Menu.Add(_updatingItem);
@ -44,17 +54,22 @@ namespace RageCoop.Client.Menus
{
try
{
if (File.Exists(_downloadPath)) { File.Delete(_downloadPath); }
WebClient client = new WebClient();
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.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);
client.DownloadFileAsync(
new Uri("https://github.com/RAGECOOP/RAGECOOP-V/releases/download/nightly/RageCoop.Client.zip"),
_downloadPath);
}
catch (Exception ex)
{
@ -67,21 +82,36 @@ namespace RageCoop.Client.Menus
{
try
{
API.QueueAction(() =>
{
_updatingItem.AltTitle = "Installing...";
});
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 { }
}
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 { }
Loader.LoaderContext.RequestUnload();
try
{
File.Delete(_downloadPath);
}
catch
{
}
try
{
File.Delete(Path.Combine(insatllPath, "RageCoop.Client.Installer.exe"));
}
catch
{
}
LoaderContext.RequestUnload();
IsUpdating = false;
}
catch (Exception ex)
@ -90,21 +120,15 @@ namespace RageCoop.Client.Menus
}
}
private static void Opening(object sender, System.ComponentModel.CancelEventArgs e)
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);
}
}
}
}
}