mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-18 00:13:10 +00:00
4e12e54028
Only remaining uses of regex in the sln are wordfilter (required), and unescape for QR replies from web api. This is slightly faster -- cover all cases if the response json changes (shouldn't).
35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
using System;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
public static class UpdateUtil
|
|
{
|
|
/// <summary>
|
|
/// Gets the latest version of PKHeX according to the Github API
|
|
/// </summary>
|
|
/// <returns>A version representing the latest available version of PKHeX, or null if the latest version could not be determined</returns>
|
|
public static Version? GetLatestPKHeXVersion()
|
|
{
|
|
const string apiEndpoint = "https://api.github.com/repos/kwsch/pkhex/releases/latest";
|
|
var responseJson = NetUtil.GetStringFromURL(apiEndpoint);
|
|
if (responseJson is null)
|
|
return null;
|
|
|
|
// Parse it manually; no need to parse the entire json to object.
|
|
const string tag = "tag_name";
|
|
var index = responseJson.IndexOf(tag, StringComparison.Ordinal);
|
|
if (index == -1)
|
|
return null;
|
|
|
|
var first = responseJson.IndexOf('"', index + tag.Length + 1) + 1;
|
|
if (first == 0)
|
|
return null;
|
|
var second = responseJson.IndexOf('"', first);
|
|
if (second == -1)
|
|
return null;
|
|
|
|
var tagString = responseJson[first..second];
|
|
return !Version.TryParse(tagString, out var latestVersion) ? null : latestVersion;
|
|
}
|
|
}
|
|
}
|