LANCommander/LANCommander.SDK/Services/LauncherService.cs

49 lines
1.3 KiB
C#
Raw Permalink Normal View History

2025-08-18 03:00:08 -05:00
using LANCommander.SDK.Models;
using Microsoft.Extensions.Logging;
using RestSharp;
using System;
using System.Threading.Tasks;
namespace LANCommander.SDK.Services
{
public class LauncherService
{
2025-08-18 03:02:49 -05:00
private readonly ILogger _logger;
private readonly Client _client;
public LauncherService(Client client)
{
2025-08-18 03:02:49 -05:00
_client = client;
}
public LauncherService(Client client, ILogger logger)
{
2025-08-18 03:02:49 -05:00
_client = client;
_logger = logger;
}
public async Task<CheckForUpdateResponse> CheckForUpdateAsync()
{
try
{
2024-08-04 20:47:19 -05:00
var request = new RestRequest("/api/Launcher", Method.Get);
2025-08-18 03:02:49 -05:00
return await _client.GetRequestAsync<CheckForUpdateResponse>("/api/Launcher/CheckForUpdate", true);
}
catch (Exception ex)
{
2025-08-18 03:02:49 -05:00
_logger?.LogError(ex, "Could not check for updates from server");
}
return null;
}
public async Task<string> DownloadAsync(string destination)
{
2025-08-18 03:02:49 -05:00
_logger?.LogTrace("Downloading the launcher");
2025-08-18 03:02:49 -05:00
return await _client.DownloadRequestAsync("/api/Launcher/Download", destination);
}
}
}