@@ -9,21 +9,36 @@ namespace NewRGB.Data;
9
9
10
10
public class Technic ( string modpackName )
11
11
{
12
- private readonly HttpClient _httpClient = new ( ) ;
12
+ private static readonly HttpClientHandler ClientHandler = new ( ) ;
13
+ private readonly HttpClient _httpClient = new ( ClientHandler ) ;
13
14
private const int BuildVersion = 69420 ;
14
15
private string _version = "" ;
15
16
private string _downloadUrl = "" ;
16
17
private readonly string _modpackZipPath = Path . Combine ( DataManager . Instance . DataPath , "modpack.zip" ) ;
17
18
18
- public async Task Init ( )
19
+ static Technic ( )
19
20
{
20
- var response =
21
- await _httpClient . GetAsync ( $ "https://api.technicpack.net/modpack/{ modpackName } ?build={ BuildVersion } ") ;
22
- response . EnsureSuccessStatusCode ( ) ;
23
- var responseBody = await response . Content . ReadAsStringAsync ( ) ;
24
- var json = JsonNode . Parse ( responseBody ) ?? throw new Exception ( "can't parse json" ) ;
25
- _version = json [ "version" ] ! . GetValue < string > ( ) ;
26
- _downloadUrl = json [ "url" ] ! . GetValue < string > ( ) ;
21
+ ClientHandler . ServerCertificateCustomValidationCallback = ( _ , _ , _ , _ ) => true ;
22
+ }
23
+
24
+ public async Task < bool > Init ( )
25
+ {
26
+ try
27
+ {
28
+ var response =
29
+ await _httpClient . GetAsync ( $ "https://api.technicpack.net/modpack/{ modpackName } ?build={ BuildVersion } ") ;
30
+ response . EnsureSuccessStatusCode ( ) ;
31
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
32
+ var json = JsonNode . Parse ( responseBody ) ?? throw new Exception ( "can't parse json" ) ;
33
+ _version = json [ "version" ] ! . GetValue < string > ( ) ;
34
+ _downloadUrl = json [ "url" ] ! . GetValue < string > ( ) ;
35
+ return true ;
36
+ }
37
+ catch ( HttpRequestException e )
38
+ {
39
+ Console . Error . WriteLine ( e ) ;
40
+ return false ;
41
+ }
27
42
}
28
43
29
44
public async Task < bool > CheckUpdate ( )
@@ -42,7 +57,7 @@ public async Task SaveVersion()
42
57
43
58
public Task < DownloadProgress ? > DownloadUpdate ( )
44
59
{
45
- return DownloadProgress . Download ( _downloadUrl , _modpackZipPath , _httpClient ) ;
60
+ return DownloadProgress . Download ( _downloadUrl , _modpackZipPath ) ;
46
61
}
47
62
48
63
public async Task < InstallProgress > InstallUpdate ( )
0 commit comments