Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5e91444

Browse files
Sébastien GeiserSébastien Geiser
Sébastien Geiser
authored and
Sébastien Geiser
committed
Readd update check
1 parent 920231b commit 5e91444

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

‎CSharpRegexTools4Npp/Main.cs‎

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// NPP plugin platform for .Net v0.91.57 by Kasper B. Graversen etc.
22
using CSharpRegexTools4Npp.PluginInfrastructure;
33
using CSharpRegexTools4Npp.Utils;
4+
using Newtonsoft.Json.Linq;
45
using RegexDialog;
56
using System;
67
using System.Diagnostics;
78
using System.Drawing;
89
using System.IO;
910
using System.Linq;
11+
using System.Net.Http;
12+
using System.Net;
1013
using System.Reflection;
1114
using System.Runtime.InteropServices;
1215
using System.Windows;
@@ -90,7 +93,7 @@ public static void ShowTheDialog()
9093
{
9194
RegExToolDialog dialog = null;
9295

93-
//RegExToolDialog.InitIsOK = () => CheckUpdates(dialog);
96+
RegExToolDialog.InitIsOK = () => CheckUpdates(dialog);
9497

9598
dialog = new RegExToolDialog
9699
{
@@ -215,6 +218,52 @@ internal static void SetToolBarIcon()
215218
}
216219
}
217220

221+
private static async void CheckUpdates(RegExToolDialog dialog)
222+
{
223+
double hoursFromLastCheck = Math.Abs((DateTime.Now - Config.Instance.LastUpdateCheck).TotalHours);
224+
225+
//if (hoursFromLastCheck > 8)
226+
if (true)
227+
{
228+
ServicePointManager.ServerCertificateValidationCallback += (_, __, ___, ____) => true;
229+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
230+
231+
try
232+
{
233+
HttpClient client = new();
234+
client.DefaultRequestHeaders.Add("Accept-Language", "en-US;q=0.5,en;q=0.3");
235+
client.DefaultRequestHeaders.Add("User-Agent", "C# App");
236+
237+
var response = await client.GetAsync("https://api.github.com/repos/codingseb/CSharpRegexTools4Npp/releases/latest").ConfigureAwait(true);
238+
239+
string responseText = await response.Content.ReadAsStringAsync();
240+
241+
var jsonResult = JObject.Parse(responseText);
242+
243+
int[] latestVersion = jsonResult["name"].ToString().Split('.').Select(digit => int.Parse(digit.Trim())).ToArray();
244+
int[] currentVersion = typeof(RegExToolDialog).Assembly.GetName().Version.ToString().Split('.').Select(digit => int.Parse(digit.Trim())).ToArray();
245+
246+
Debug.WriteLine($"{string.Join(".", latestVersion)} - {string.Join(".", currentVersion)}");
247+
248+
for (int i = 0; i < latestVersion.Length && i < currentVersion.Length; i++)
249+
{
250+
if (latestVersion[i] > currentVersion[i])
251+
{
252+
Config.Instance.UpdateAvailable = true;
253+
Config.Instance.UpdateURL = "https://github.com/codingseb/CSharpRegexTools4Npp/releases";
254+
break;
255+
}
256+
else if (latestVersion[i] < currentVersion[i])
257+
{
258+
break;
259+
}
260+
}
261+
}
262+
catch
263+
{ }
264+
}
265+
}
266+
218267
/// <summary>
219268
/// open GitHub repo with the web browser
220269
/// </summary>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /