2using System.Text.Json.Serialization;
3using System.Text.RegularExpressions;
60 public static Regex
VersionRegex =
new(
@"(\d+)\.?(\d+)?\.?(\d+)?\.?(\d+)?");
72 for (
int i = 1; i < Math.Min(5, match.Groups.Count); i++) {
73 Group group = match.Groups[i];
75 if (
byte.TryParse(group.Value, out
byte value)) {
76 result |= (uint)value << (8 * (4 - i));
79 throw new FormatException($
"Invalid version format: {version}");
85 throw new FormatException($
"Invalid version format: {version}");
96 JsonElement root = remoteDoc.RootElement;
99 ? root.GetProperty(
"tag_name").GetString()
100 : root[root.GetArrayLength() - 1].GetProperty(
"tag_name").GetString();
115 if (target ==
"API_OLD") {
116 return current ==
"API_OLD" ? 0 : 1;
118 if (current ==
"API_OLD") {
123 return currentVersion.CompareTo(targetVersion);
133 public long id {
get;
set; }
137 public string name {
get;
set; }
138 public string body {
get;
set; }
150 public long id {
get;
set; }
152 public string name {
get;
set; }
154 public string url {
get;
set; }
166 public string type {
get;
set; }
176 public string name {
get;
set; }
179 [JsonSourceGenerationOptions(
180 PropertyNamingPolicy = JsonKnownNamingPolicy.SnakeCaseLower
182 [JsonSerializable(typeof(List<ReleaseInfo>))]
183 [JsonSerializable(typeof(ReleaseInfo))]
184 [JsonSerializable(typeof(Author))]
185 [JsonSerializable(typeof(List<Asset>))]
186 [JsonSerializable(typeof(Asset))]
static uint ParseVersionFromString(string version)
将API版本字符串以点分十进制数转为uint
static ? bool IsNeedUpdate
API是否需要更新?ture:需要;false:不需要;null:正在获取
static async Task< string > GetLatestVersion(bool direct)
获取 Gitee release最后一个版本的版本号
static string CurrentVersion
当前API版本
static async Task< bool > GetIsNeedUpdate()
对比API版本,判断是否需要更新
static async Task< JsonDocument > GetLatestAPIJsonDocument()
获取 Gitee release最后一个版本的Json文件数据
static Regex VersionRegex
版本号X.X.X.X的正则表达式s
static async Task< JsonDocument > GetAPIReleasesJsonDocument()
获取 Gitee 所有release版本的Json文件数据
static string LatestVersion
网络上最新的API的版本
static int CompareVersion(string current, string target)
比较两个版本的新旧关系。 current大于target,返回1 current小于target,返回-1 版本相等,返回0
string browser_download_url
string received_events_url
static async Task< JsonDocument > GetJsonFromUrlAsync(string url)
从链接获取 Json 文档
static string APILatestReleaseLink_API
static string APIVersionString
static string APIReleasesLink_API