Skip to content

Commit

Permalink
Updater fixes and crash fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aebian committed Aug 23, 2020
1 parent b9abf02 commit d735828
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
8 changes: 4 additions & 4 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("")]

Expand All @@ -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")]

8 changes: 5 additions & 3 deletions SilencerKI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
1 change: 0 additions & 1 deletion Utils/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Utils/Notifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down
35 changes: 17 additions & 18 deletions Utils/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit d735828

Please sign in to comment.