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 RestSharp;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
2024-10-04 23:37:49 -05:00
|
|
|
|
namespace LANCommander.SDK.Services
|
2024-07-25 19:21:52 -05:00
|
|
|
|
{
|
|
|
|
|
|
public class LauncherService
|
|
|
|
|
|
{
|
2025-08-18 03:02:49 -05:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
private readonly Client _client;
|
2024-07-25 19:21:52 -05:00
|
|
|
|
|
|
|
|
|
|
public LauncherService(Client client)
|
|
|
|
|
|
{
|
2025-08-18 03:02:49 -05:00
|
|
|
|
_client = client;
|
2024-07-25 19:21:52 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LauncherService(Client client, ILogger logger)
|
|
|
|
|
|
{
|
2025-08-18 03:02:49 -05:00
|
|
|
|
_client = client;
|
|
|
|
|
|
_logger = logger;
|
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
|
|
|
|
|
|
{
|
2024-08-04 20:47:19 -05:00
|
|
|
|
var request = new RestRequest("/api/Launcher", Method.Get);
|
2024-07-25 19:21:52 -05:00
|
|
|
|
|
2025-08-18 03:02:49 -05:00
|
|
|
|
return await _client.GetRequestAsync<CheckForUpdateResponse>("/api/Launcher/CheckForUpdate", true);
|
2024-07-26 17:14:24 -05:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2025-08-18 03:02:49 -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-08-18 03:02:49 -05:00
|
|
|
|
_logger?.LogTrace("Downloading the launcher");
|
2024-07-25 19:21:52 -05:00
|
|
|
|
|
2025-08-18 03:02:49 -05:00
|
|
|
|
return await _client.DownloadRequestAsync("/api/Launcher/Download", destination);
|
2024-07-25 19:21:52 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|