@@ -17,7 +17,7 @@ namespace KoAR.SaveEditor.Updates;
1717
1818public static class UpdateMethods
1919{
20- private static readonly HttpClient _client = InitializeClient ( ) ;
20+ private static readonly HttpClient _client = UpdateMethods . InitializeClient ( ) ;
2121 private static readonly JsonSerializerOptions _jsonOptions = new ( ) { PropertyNamingPolicy = JsonSnakeCaseNamingPolicy . Instance } ;
2222
2323 /// <summary>
@@ -44,21 +44,12 @@ public static async void ExecuteUpdate(string zipFilePath)
4444 /// <param name="majorVersion">The major version of the release.</param>
4545 /// <param name="cancellationToken">Optionally used to propagate cancellation requests.</param>
4646 /// <returns>Information related to a release. Returns <see langword="null"/> if not found or an error occurs.</returns>
47- public static async Task < IReleaseInfo ? > FetchLatestVersionedReleaseAsync ( int majorVersion , CancellationToken cancellationToken = default )
47+ public static async Task < IReleaseInfo ? > FetchLatest2xReleaseAsync ( CancellationToken cancellationToken = default )
4848 {
4949 try
5050 {
51- foreach ( Tag tag in await UpdateMethods . FetchTagsAsync ( cancellationToken ) . ConfigureAwait ( false ) )
52- {
53- if ( tag . Version . Major != majorVersion )
54- {
55- continue ;
56- }
57- if ( await UpdateMethods . FetchReleaseAsync ( tag . Name , cancellationToken ) . ConfigureAwait ( false ) is { HasUpdateAsset : true } release )
58- {
59- return release ;
60- }
61- }
51+ const string tagName = "v2.1.189" ;
52+ return await UpdateMethods . FetchReleaseAsync ( tagName , cancellationToken ) . ConfigureAwait ( false ) ;
6253 }
6354 catch
6455 {
@@ -76,14 +67,9 @@ public static async void ExecuteUpdate(string zipFilePath)
7667 {
7768 try
7869 {
79- string [ ] tagNames = ( await UpdateMethods . FetchTagsAsync ( cancellationToken ) . ConfigureAwait ( false ) )
80- . Where ( tag => tag . Version . Major == App . Version . Major && tag . Version > App . Version )
70+ Release [ ] array = ( await UpdateMethods . FetchReleasesAsync ( cancellationToken ) . ConfigureAwait ( false ) )
71+ . Where ( release => release . Version . Major == App . Version . Major && release . Version > App . Version && release . HasUpdateAsset )
8172 . Take ( maxReleases )
82- . Select ( tag => tag . Name )
83- . ToArray ( ) ;
84- Release [ ] array = ( await Task . WhenAll ( Array . ConvertAll ( tagNames , tag => UpdateMethods . FetchReleaseAsync ( tag , cancellationToken ) ) ) . ConfigureAwait ( false ) )
85- . OfType < Release > ( )
86- . Where ( release => release . HasUpdateAsset )
8773 . ToArray ( ) ;
8874 if ( array . Length != 0 )
8975 {
@@ -125,7 +111,7 @@ private static async Task<string> ExtractPowershellScript()
125111 /// <returns>A model representing the GitHub release. Returns <see langword="null"/> if the release was deleted or an error occurs.</returns>
126112 private static Task < Release ? > FetchReleaseAsync ( string tag , CancellationToken cancellationToken ) => UpdateMethods . FetchDataAsync < Release > ( $ "releases/tags/{ tag } ", cancellationToken ) ;
127113
128- private static async Task < Tag [ ] > FetchTagsAsync ( CancellationToken cancellationToken ) => ( await UpdateMethods . FetchDataAsync < Tag [ ] > ( "tags " , cancellationToken ) . ConfigureAwait ( false ) ) ! ;
114+ private static Task < Release [ ] > FetchReleasesAsync ( CancellationToken cancellationToken ) => UpdateMethods . FetchDataAsync < Release [ ] > ( "releases " , cancellationToken ) ! ;
129115
130116 private static Stream GetResourceFileStream ( string name ) => Application . GetResourceStream ( new ( $ "/Updates/{ name } ", UriKind . Relative ) ) . Stream ;
131117
@@ -144,6 +130,8 @@ private static HttpClient InitializeClient()
144130
145131 private sealed class Release : IReleaseInfo
146132 {
133+ private static readonly Regex _regex = new ( @"^v(?<version>\d+\.\d+\.\d+)$" , RegexOptions . ExplicitCapture | RegexOptions . Compiled ) ;
134+
147135 private Version ? _version ;
148136 private ReleaseAsset ? _zipFileAsset ;
149137
@@ -159,7 +147,7 @@ private sealed class Release : IReleaseInfo
159147
160148 public string TagName { get ; set ; } = string . Empty ;
161149
162- public Version Version => this . _version ??= new ( this . TagName . Length != 0 ? this . TagName [ 1 ..] : "0.0.0" ) ;
150+ public Version Version => this . _version ??= new ( this . TagName . Length != 0 && Release . _regex . IsMatch ( this . TagName ) ? this . TagName [ 1 ..] : "0.0.0" ) ;
163151
164152 public ReleaseAsset ? ZipFileAsset => this . _zipFileAsset ??= this . Assets . FirstOrDefault ( asset => asset . ContentType == "application/zip" ) ;
165153
@@ -176,15 +164,4 @@ private sealed class ReleaseAsset
176164
177165 public int Size { get ; set ; }
178166 }
179-
180- private sealed class Tag
181- {
182- private static readonly Regex _regex = new ( @"^v(?<version>\d+\.\d+\.\d+)$" , RegexOptions . ExplicitCapture | RegexOptions . Compiled ) ;
183-
184- private Version ? _version ;
185-
186- public string Name { get ; set ; } = string . Empty ;
187-
188- public Version Version => this . _version ??= new ( Tag . _regex . IsMatch ( this . Name ) ? this . Name [ 1 ..] : "0.0.0" ) ;
189- }
190167}
0 commit comments