-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from zkhssb/new
编码与连接优化
- Loading branch information
Showing
32 changed files
with
918 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<TargetFramework>net7.0-windows</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\NectarRCON.Updater\NectarRCON.Updater.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using NectarRCON.Updater; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NectarRCON.Tests | ||
{ | ||
[TestClass] | ||
public class UpdaterTests | ||
{ | ||
[TestMethod] | ||
public void Github() | ||
{ | ||
IUpdater updater = new GithubUpdater(); | ||
updater.SetVersion("NectarRcon-x86-1.0.0"); | ||
updater.IsLatestVersion(); | ||
} | ||
|
||
[TestMethod] | ||
public void AppVersionTest() | ||
{ | ||
AppVersion versionA = AppVersion.ParseVersion("TestApp-x64-1.0.0-beta1"); | ||
AppVersion versionB = AppVersion.ParseVersion("TestApp-x64-1.0.0-beta2"); | ||
|
||
Assert.IsTrue(versionA.Equals(versionA)); | ||
Assert.IsFalse(versionA.Equals(versionB)); | ||
|
||
#pragma warning disable CS1718 // 对同一变量进行了比较 | ||
Assert.IsTrue(versionA == versionA); | ||
Assert.IsFalse(versionA != versionA); | ||
Assert.IsFalse(versionA > versionA); | ||
#pragma warning restore CS1718 // 对同一变量进行了比较 | ||
|
||
Assert.IsTrue(versionB > versionA); | ||
Assert.IsFalse(versionB < versionA); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace NectarRCON.Updater | ||
{ | ||
public class AppVersion | ||
{ | ||
public string AppName { get; set; } = string.Empty; | ||
public int Version { get; set; } | ||
public int Major { get;set; } | ||
public int Minor { get;set; } | ||
public int Patch { get;set; } | ||
public int? Build { get; set; } | ||
public string PreReleaseType { get; set; } = string.Empty; | ||
public string Platform { get; set; } = string.Empty; | ||
public bool IsPreRelease | ||
=> !string.IsNullOrEmpty(PreReleaseType); | ||
|
||
public override string ToString() | ||
{ | ||
return $"{AppName}-{Platform}-{Major}.{Minor}.{Patch}" + (IsPreRelease ? $"-{PreReleaseType}{Build}" : string.Empty); | ||
} | ||
|
||
public override bool Equals(object? obj) | ||
{ | ||
return obj?.ToString() == ToString(); | ||
} | ||
|
||
public static bool operator <(AppVersion a, AppVersion b) | ||
{ | ||
return a.Version < b.Version || (a.Build ?? 0) < (b.Build ?? 0); | ||
} | ||
|
||
public static bool operator >(AppVersion a, AppVersion b) | ||
{ | ||
return a.Version > b.Version || (a.Build ?? 0) > (b.Build ?? 0); | ||
} | ||
|
||
public static bool operator ==(AppVersion a, AppVersion b) | ||
{ | ||
return a.Version == b.Version && (a.Build ?? 0) == (b.Build ?? 0); | ||
} | ||
|
||
public static bool operator !=(AppVersion a, AppVersion b) | ||
{ | ||
return a.Version != b.Version || (a.Build ?? 0) != (b.Build ?? 0); | ||
} | ||
|
||
private AppVersion() { } | ||
|
||
public static AppVersion ParseVersion(string version) | ||
{ | ||
string[] versionParts = version.Split("-"); | ||
if (versionParts.Length > 2) | ||
{ | ||
AppVersion result = new(); | ||
string name = versionParts[0]; | ||
string platform = versionParts[1]; | ||
string ver = versionParts[2]; | ||
string preRelease = string.Empty; | ||
|
||
if (versionParts.Length > 3) | ||
{ | ||
preRelease = versionParts[3]; | ||
} | ||
|
||
Regex versionRegex = new(@"(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)"); | ||
Match versionMatch = versionRegex.Match(ver); | ||
|
||
if (versionMatch.Success) | ||
{ | ||
result.Version = int.Parse(versionMatch.Groups["major"].Value + versionMatch.Groups["minor"].Value + versionMatch.Groups["patch"].Value); | ||
result.Major = int.Parse(versionMatch.Groups["major"].Value); | ||
result.Minor = int.Parse(versionMatch.Groups["minor"].Value); | ||
result.Patch = int.Parse(versionMatch.Groups["patch"].Value); | ||
} | ||
|
||
Regex preReleaseRegex = new(@"(?<preRelease>[a-zA-Z]+)(?<build>\d+)"); | ||
Match preReleaseMatch = preReleaseRegex.Match(preRelease); | ||
|
||
if (preReleaseMatch.Success) | ||
{ | ||
if (preReleaseMatch.Groups["build"].Success) | ||
{ | ||
result.Build = int.Parse(preReleaseMatch.Groups["build"].Value); | ||
} | ||
if (preReleaseMatch.Groups["preRelease"].Success) | ||
{ | ||
result.PreReleaseType = preReleaseMatch.Groups["preRelease"].Value; | ||
} | ||
} | ||
|
||
result.Platform = platform; | ||
result.AppName = name; | ||
return result; | ||
} | ||
throw new InvalidOperationException("Invalid version format"); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return RuntimeHelpers.GetHashCode(ToString()); | ||
} | ||
} | ||
} |
Oops, something went wrong.