From d735828e239d1206aa230530ea3e33164d91b521 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 23 Aug 2020 04:35:22 +0200 Subject: [PATCH] Updater fixes and crash fixes --- Properties/AssemblyInfo.cs | 8 ++++---- SilencerKI.cs | 8 +++++--- Utils/Core.cs | 1 - Utils/Notifier.cs | 2 +- Utils/Updater.cs | 35 +++++++++++++++++------------------ 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 667a54f..ad93b2c 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -9,9 +9,9 @@ [assembly: AssemblyTitle("SilencerKI")] [assembly: AssemblyDescription("Attach Silencers to any weapon with ease")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] +[assembly: AssemblyCompany("Knight Industries")] [assembly: AssemblyProduct("SilencerKI")] -[assembly: AssemblyCopyright("Copyright © 2008 - 2020 by Knight Industries")] +[assembly: AssemblyCopyright("© 2008 - 2020 by Knight Industries")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -33,7 +33,7 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.3")] -[assembly: AssemblyFileVersion("0.3")] +[assembly: AssemblyVersion("0.4.0.0")] +[assembly: AssemblyFileVersion("0.4.0.0")] [assembly: NeutralResourcesLanguage("en-US")] diff --git a/SilencerKI.cs b/SilencerKI.cs index 9c9eaa0..8def744 100644 --- a/SilencerKI.cs +++ b/SilencerKI.cs @@ -23,19 +23,21 @@ public static void Main() { Global.Application.ConfigPath = "Plugins/"; Global.Application.CurrentVersion = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Version}"; - int versionStatus = Updater.CheckUpdate(); + + int versionStatus = Updater.CheckUpdate(); if (versionStatus == -1) { Notifier.Notify("Plugin is out of date! (Current Version: ~r~" + Global.Application.CurrentVersion + " ~s~) - (Latest Version: ~g~" + Global.Application.LatestVersion + "~s~) Please update the plugin!"); Logger.Log("Plugin is out of date. (Current Version: " + Global.Application.CurrentVersion + ") - (Latest Version: " + Global.Application.LatestVersion + ")"); } else if(versionStatus == -2) { Logger.Log("There was an issue checking plugin versions, the plugin may be out of date!"); - } + } else if (versionStatus == 1) { Logger.Log("Current version of plugin is higher than the version reported, this could be an error that you may want to report!"); + Logger.Log(Global.Application.CurrentVersion); } else { - Notifier.Notify("Plugin loaded ~g~successfully~s~!"); + Notifier.Notify("Silencer Plugin loaded!"); Logger.Log("Plugin Version v" + Global.Application.CurrentVersion + " loaded successfully"); } diff --git a/Utils/Core.cs b/Utils/Core.cs index 81d3298..91b4f36 100644 --- a/Utils/Core.cs +++ b/Utils/Core.cs @@ -50,7 +50,6 @@ public static void RunPlugin() private static void UpdatePlayer() { - Global.Dynamics.CurrentPed = Game.LocalPlayer.Character; Global.Dynamics.EquippedWeaponHash = Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject.Model.Hash; } diff --git a/Utils/Notifier.cs b/Utils/Notifier.cs index eb5d5aa..e925cb3 100644 --- a/Utils/Notifier.cs +++ b/Utils/Notifier.cs @@ -13,7 +13,7 @@ internal static class Notifier //Simple log line internal static void Notify(string body) { - string notice = string.Format("~p~[{0}]~s~:", body); + string notice = string.Format("~p~{0}~s~", body); Game.DisplayNotification(notice); Logger.DebugLog("Notification Sent."); } diff --git a/Utils/Updater.cs b/Utils/Updater.cs index c40d158..2bca13a 100644 --- a/Utils/Updater.cs +++ b/Utils/Updater.cs @@ -9,45 +9,44 @@ namespace SilencerKI.Utils { using System; using System.Net; + using System.Net.Http; internal static class Updater { - private static readonly WebClient wc = new WebClient(); + private static readonly HttpClient hc = new HttpClient(); public static int CheckUpdate() { - string response = null; + string response = ""; try { - Logger.DebugLog("Fetching latest plugin version from Repo"); - response = wc.DownloadStringTaskAsync(new Uri("https://adm.knight-industries.org/updates/SilencerKI/SKI.txt")).Result; + + ServicePointManager.Expect100Continue = true; + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + + Logger.Log("Fetching latest plugin version from Repo"); + response = hc.GetStringAsync(new Uri("https://adm.knight-industries.org/updates/SilencerKI/latestVersion.txt")).Result; } - catch (Exception) + catch (Exception ex) { - /// TODO - } + Logger.Log(ex.ToString()); - //If we get a null respone then the download failed and we just return -2 and inform user of failing the download - if (string.IsNullOrWhiteSpace(response)) - { return -2; + } Global.Application.LatestVersion = response; - Version current = new Version(Global.Application.CurrentVersion); - Version latest = new Version(Global.Application.LatestVersion); - //This is where we're checking the results - //If the plugin is newer than what's being reported then we'll return 1 (This will just log the issue, no notification) - //If the plugin is older than what's being reported then we'll return -1(This Logs aswell as displays a notification) - //If the plugin is the same version as what's being reported than we'll return 0 (This logs & displays notification that it loaded successfully) - if (current.CompareTo(latest) > 0) + Version CurrentVN = new Version(Global.Application.CurrentVersion); + Version LatestVN = new Version(Global.Application.LatestVersion); + + if (CurrentVN.CompareTo(LatestVN) > 0) { return 1; } - else if (current.CompareTo(latest) < 0) + else if (CurrentVN.CompareTo(LatestVN) < 0) { return -1; }