Introduced a new HttpHelper utility to centralize and standardize HTTP requests across the codebase, replacing direct usage of HttpClient. Updated authentication, asset, game, and Mojang API logic to use the new helper, improving maintainability and consistency. Also refactored game launch options for greater flexibility and configurability.
22 lines
755 B
C#
22 lines
755 B
C#
namespace Lentia.Core.Utils;
|
|
|
|
public static class FileHelper {
|
|
public static async Task DownloadFileAsync(string url, string destinationPath) {
|
|
string? directory = Path.GetDirectoryName(destinationPath);
|
|
if (!string.IsNullOrEmpty(directory)) {
|
|
Directory.CreateDirectory(directory);
|
|
}
|
|
|
|
if (File.Exists(destinationPath)) {
|
|
File.Delete(destinationPath);
|
|
}
|
|
|
|
using var response = await HttpHelper.FetchAsync(url);
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
using var streamToReadFrom = await response.Content.ReadAsStreamAsync();
|
|
using var streamToWriteTo = File.Create(destinationPath);
|
|
|
|
await streamToReadFrom.CopyToAsync(streamToWriteTo);
|
|
}
|
|
} |