2025-08-18 03:00:08 -05:00
|
|
|
|
using LANCommander.SDK.Models;
|
2024-07-25 19:21:52 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2025-09-22 00:29:51 -05:00
|
|
|
|
using LANCommander.SDK.Factories;
|
2024-07-25 19:21:52 -05:00
|
|
|
|
|
2024-10-04 23:37:49 -05:00
|
|
|
|
namespace LANCommander.SDK.Services
|
2024-07-25 19:21:52 -05:00
|
|
|
|
{
|
2025-09-24 20:58:23 -05:00
|
|
|
|
public class LauncherClient(
|
|
|
|
|
|
ILogger<LauncherClient> logger,
|
2025-09-22 00:29:51 -05:00
|
|
|
|
ApiRequestFactory apiRequestFactory)
|
2024-07-25 19:21:52 -05:00
|
|
|
|
{
|
2024-07-29 20:25:46 -05:00
|
|
|
|
public async Task<CheckForUpdateResponse> CheckForUpdateAsync()
|
2024-07-25 19:21:52 -05:00
|
|
|
|
{
|
2024-07-26 17:14:24 -05:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-09-22 00:29:51 -05:00
|
|
|
|
return await apiRequestFactory
|
|
|
|
|
|
.Create()
|
|
|
|
|
|
.UseRoute("/api/Launcher/CheckForUpdate")
|
|
|
|
|
|
.GetAsync<CheckForUpdateResponse>();
|
2024-07-26 17:14:24 -05:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2025-09-22 00:29:51 -05:00
|
|
|
|
logger?.LogError(ex, "Could not check for updates from server");
|
2024-07-26 17:14:24 -05:00
|
|
|
|
}
|
2024-07-25 19:21:52 -05:00
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<string> DownloadAsync(string destination)
|
|
|
|
|
|
{
|
2025-09-22 00:29:51 -05:00
|
|
|
|
logger?.LogTrace("Downloading the launcher");
|
|
|
|
|
|
|
|
|
|
|
|
var result = await apiRequestFactory
|
|
|
|
|
|
.Create()
|
|
|
|
|
|
.UseRoute("/api/Launcher/Download")
|
|
|
|
|
|
.DownloadAsync(destination);
|
2024-07-25 19:21:52 -05:00
|
|
|
|
|
2025-09-22 00:29:51 -05:00
|
|
|
|
return result.FullName;
|
2024-07-25 19:21:52 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|