Skip to content

Commit

Permalink
fixed ssl crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Enn3Developer committed Jul 10, 2024
1 parent 7dcca75 commit 3883dc8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
35 changes: 25 additions & 10 deletions Data/Technic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,36 @@ namespace NewRGB.Data;

public class Technic(string modpackName)
{
private readonly HttpClient _httpClient = new();
private static readonly HttpClientHandler ClientHandler = new();
private readonly HttpClient _httpClient = new(ClientHandler);
private const int BuildVersion = 69420;
private string _version = "";
private string _downloadUrl = "";
private readonly string _modpackZipPath = Path.Combine(DataManager.Instance.DataPath, "modpack.zip");

public async Task Init()
static Technic()
{
var response =
await _httpClient.GetAsync($"https://api.technicpack.net/modpack/{modpackName}?build={BuildVersion}");
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
var json = JsonNode.Parse(responseBody) ?? throw new Exception("can't parse json");
_version = json["version"]!.GetValue<string>();
_downloadUrl = json["url"]!.GetValue<string>();
ClientHandler.ServerCertificateCustomValidationCallback = (_, _, _, _) => true;
}

public async Task<bool> Init()
{
try
{
var response =
await _httpClient.GetAsync($"https://api.technicpack.net/modpack/{modpackName}?build={BuildVersion}");
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
var json = JsonNode.Parse(responseBody) ?? throw new Exception("can't parse json");
_version = json["version"]!.GetValue<string>();
_downloadUrl = json["url"]!.GetValue<string>();
return true;
}
catch (HttpRequestException e)
{
Console.Error.WriteLine(e);
return false;
}
}

public async Task<bool> CheckUpdate()
Expand All @@ -42,7 +57,7 @@ public async Task SaveVersion()

public Task<DownloadProgress?> DownloadUpdate()
{
return DownloadProgress.Download(_downloadUrl, _modpackZipPath, _httpClient);
return DownloadProgress.Download(_downloadUrl, _modpackZipPath);
}

public async Task<InstallProgress> InstallUpdate()
Expand Down
3 changes: 2 additions & 1 deletion ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,8 @@ private async Task OnLoaded()
}

UpdateProgress(0.0f, "Checking for updates", false);
await _technic.Init();
if (!await _technic.Init()) UpdateProgress(1.0f, "Can't download info from technic");

_needsUpdate = await _technic.CheckUpdate();
if (_needsUpdate)
{
Expand Down

0 comments on commit 3883dc8

Please sign in to comment.