Merge pull request #90 from daffyyyy/some-changes

!skins thread-safe and checking version
This commit is contained in:
Nereziel
2023-12-06 17:18:06 +01:00
committed by GitHub
6 changed files with 65 additions and 19 deletions

View File

@@ -5,6 +5,7 @@ using MySqlConnector;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Reflection;
using Microsoft.Extensions.Logging;
namespace WeaponPaints
{
@@ -107,6 +108,45 @@ namespace WeaponPaints
return message;
}
internal static async Task CheckVersion(string version)
{
using (HttpClient client = new HttpClient())
{
try
{
HttpResponseMessage response = await client.GetAsync("https://github.com/Nereziel/cs2-WeaponPaints/blob/main/VERSION");
if (response.IsSuccessStatusCode)
{
string remoteVersion = await response.Content.ReadAsStringAsync();
remoteVersion = remoteVersion.Trim();
int comparisonResult = string.Compare(version, remoteVersion);
if (comparisonResult < 0)
{
WeaponPaints.logger!.LogWarning("Plugin is outdated! Check https://github.com/Nereziel/cs2-WeaponPaints");
}
else if (comparisonResult > 0)
{
WeaponPaints.logger!.LogInformation("Probably dev version detected");
}
else
{
WeaponPaints.logger!.LogInformation("Plugin is up to date");
}
}
else
{
WeaponPaints.logger!.LogWarning("Failed to check version");
}
}
catch (Exception)
{
}
}
}
internal static void ShowAd(string moduleVersion)
{
Console.WriteLine(" ");