1+ using Ryujinx . Systems . Update . Common ;
2+
3+ namespace Ryujinx . Systems . Update . Client ;
4+
5+ public partial class UpdateClient
6+ {
7+ /// <summary>
8+ /// Query the next version for a release channel.
9+ /// </summary>
10+ /// <param name="rc">The target release channel.</param>
11+ /// <returns>true if request success; false if non-200 series HTTP status code, null if not configured to support this endpoint.</returns>
12+ public async Task < string ? > NextVersionAsync ( ReleaseChannel rc )
13+ {
14+ var httpRequest = new HttpRequestMessage ( HttpMethod . Get ,
15+ $ "{ Constants . FullRouteName_Api_Versioning } /{ Constants . RouteName_Api_Versioning_GetNextVersion } ?rc={ rc . QueryStringValue } ") ;
16+ ApplyAuthorization ( httpRequest ) ;
17+
18+ var resp = await _http . SendAsync ( httpRequest ) ;
19+
20+ if ( ! resp . IsSuccessStatusCode )
21+ {
22+ Log ( "Increment version failed: received status code {0}; content body: {1}" ,
23+ [ Enum . GetName ( resp . StatusCode ) ?? $ "{ ( int ) resp . StatusCode } ", await resp . Content . ReadAsStringAsync ( ) ] ) ;
24+ return null ;
25+ }
26+
27+ return await resp . Content . ReadAsStringAsync ( ) ;
28+ }
29+
30+ /// <summary>
31+ /// Requests the configured update server to increment its version for a given release channel.
32+ /// </summary>
33+ /// <param name="rc">The target release channel.</param>
34+ /// <returns>true if request success; false if non-200 series HTTP status code, null if not configured to support this endpoint.</returns>
35+ /// <remarks>Requires an authorization-bearing client configuration.</remarks>
36+ public async Task < bool ? > IncrementVersionAsync ( ReleaseChannel rc )
37+ {
38+ if ( ! _config . CanUseAdminEndpoints )
39+ {
40+ Log ( "Cannot request version increment, as there is no configured admin access token." ) ;
41+ return null ;
42+ }
43+
44+ var httpRequest = new HttpRequestMessage ( HttpMethod . Patch ,
45+ $ "{ Constants . FullRouteName_Api_Versioning } /{ Constants . RouteName_Api_Versioning_IncrementVersion } ?rc={ rc . QueryStringValue } ") ;
46+ ApplyAuthorization ( httpRequest ) ;
47+
48+ if ( await _http . SendAsync ( httpRequest ) is { IsSuccessStatusCode : false } resp )
49+ {
50+ Log ( "Increment version failed: received status code {0}; content body: {1}" ,
51+ [ Enum . GetName ( resp . StatusCode ) ?? $ "{ ( int ) resp . StatusCode } ", await resp . Content . ReadAsStringAsync ( ) ] ) ;
52+ return false ;
53+ }
54+
55+ return true ;
56+ }
57+
58+ /// <summary>
59+ /// Requests the configured update server to increment the major version by one for both stable and canary, and to reset the build number to 0.
60+ /// </summary>
61+ /// <returns>true if request success; false if non-200 series HTTP status code, null if not configured to support this endpoint.</returns>
62+ /// <remarks>Requires an authorization-bearing client configuration.</remarks>
63+ public async Task < bool ? > AdvanceVersionAsync ( )
64+ {
65+ if ( ! _config . CanUseAdminEndpoints )
66+ {
67+ Log ( "Cannot request version advance, as there is no configured admin access token." ) ;
68+ return null ;
69+ }
70+
71+ var httpRequest = new HttpRequestMessage ( HttpMethod . Patch ,
72+ $ "{ Constants . FullRouteName_Api_Versioning } /{ Constants . RouteName_Api_Versioning_AdvanceVersion } ") ;
73+ ApplyAuthorization ( httpRequest ) ;
74+
75+ if ( await _http . SendAsync ( httpRequest ) is { IsSuccessStatusCode : false } resp )
76+ {
77+ Log ( "Advancing version failed: received status code {0}; content body: {1}" ,
78+ [ Enum . GetName ( resp . StatusCode ) ?? $ "{ ( int ) resp . StatusCode } ", await resp . Content . ReadAsStringAsync ( ) ] ) ;
79+ return false ;
80+ }
81+
82+ return true ;
83+ }
84+ }
0 commit comments