2025-10-08 19:51:44 -05:00
|
|
|
|
using LANCommander.SDK.Extensions;
|
|
|
|
|
|
using LANCommander.SDK.Models;
|
2026-01-24 15:32:40 -06:00
|
|
|
|
using LANCommander.SDK.Services;
|
2024-09-11 00:24:34 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2024-05-29 19:25:41 -05:00
|
|
|
|
|
2024-08-04 17:53:19 -05:00
|
|
|
|
namespace LANCommander.Launcher.Services
|
2024-05-29 19:25:41 -05:00
|
|
|
|
{
|
2025-09-24 20:58:23 -05:00
|
|
|
|
public class SaveService(
|
|
|
|
|
|
ILogger<SaveService> logger,
|
2026-01-24 15:32:40 -06:00
|
|
|
|
SaveClient saveClient) : BaseService(logger)
|
2024-05-29 19:25:41 -05:00
|
|
|
|
{
|
2024-10-23 18:17:01 -05:00
|
|
|
|
public async Task<IEnumerable<GameSave>> Get(Guid gameId)
|
|
|
|
|
|
{
|
2025-10-08 19:51:44 -05:00
|
|
|
|
using (var op = Logger.BeginDebugOperation("Getting saves for game"))
|
|
|
|
|
|
{
|
|
|
|
|
|
op.Enrich("GameId", gameId);
|
|
|
|
|
|
|
2026-01-24 15:32:40 -06:00
|
|
|
|
var saves = await saveClient.GetAsync(gameId);
|
2025-03-11 18:20:34 -05:00
|
|
|
|
|
2025-10-08 19:51:44 -05:00
|
|
|
|
if (saves == null)
|
|
|
|
|
|
saves = new List<GameSave>();
|
|
|
|
|
|
|
|
|
|
|
|
op.Complete();
|
2025-03-11 18:20:34 -05:00
|
|
|
|
|
2025-10-08 19:51:44 -05:00
|
|
|
|
return saves;
|
|
|
|
|
|
}
|
2024-10-23 18:17:01 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-15 19:13:40 -05:00
|
|
|
|
public async Task DownloadLatestAsync(string installDirectory, Guid gameId)
|
|
|
|
|
|
{
|
2025-10-08 19:51:44 -05:00
|
|
|
|
using (var op = Logger.BeginDebugOperation("Downloading latest save"))
|
|
|
|
|
|
{
|
|
|
|
|
|
op.Enrich("GameId", gameId);
|
|
|
|
|
|
op.Enrich("InstallDirectory", installDirectory);
|
|
|
|
|
|
|
2026-01-24 15:32:40 -06:00
|
|
|
|
await saveClient.DownloadAsync(installDirectory, gameId);
|
2025-10-08 19:51:44 -05:00
|
|
|
|
|
|
|
|
|
|
op.Complete();
|
|
|
|
|
|
}
|
2024-07-15 19:13:40 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task DownloadLatest(string installDirectory, Guid gameId)
|
2024-05-29 19:25:41 -05:00
|
|
|
|
{
|
2025-10-08 19:51:44 -05:00
|
|
|
|
using (var op = Logger.BeginDebugOperation("Downloading latest save"))
|
|
|
|
|
|
{
|
|
|
|
|
|
op.Enrich("GameId", gameId);
|
|
|
|
|
|
op.Enrich("InstallDirectory", installDirectory);
|
|
|
|
|
|
|
2026-01-24 15:32:40 -06:00
|
|
|
|
await saveClient.DownloadAsync(installDirectory, gameId);
|
2025-10-08 19:51:44 -05:00
|
|
|
|
|
|
|
|
|
|
op.Complete();
|
|
|
|
|
|
}
|
2024-10-23 18:17:01 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task DownloadAsync(string installDirectory, Guid gameId, Guid saveId)
|
|
|
|
|
|
{
|
2025-10-08 19:51:44 -05:00
|
|
|
|
using (var op = Logger.BeginDebugOperation("Downloading save"))
|
|
|
|
|
|
{
|
|
|
|
|
|
op.Enrich("GameId", gameId);
|
|
|
|
|
|
op.Enrich("SaveId", saveId);
|
|
|
|
|
|
op.Enrich("InstallDirectory", installDirectory);
|
|
|
|
|
|
|
2026-01-24 15:32:40 -06:00
|
|
|
|
await saveClient.DownloadAsync(installDirectory, gameId, saveId);
|
2025-10-08 19:51:44 -05:00
|
|
|
|
|
|
|
|
|
|
op.Complete();
|
|
|
|
|
|
}
|
2024-07-15 19:13:40 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task UploadAsync(string installDirectory, Guid gameId)
|
|
|
|
|
|
{
|
2025-10-08 19:51:44 -05:00
|
|
|
|
using (var op = Logger.BeginDebugOperation("Uploading save"))
|
|
|
|
|
|
{
|
|
|
|
|
|
op.Enrich("GameId", gameId);
|
|
|
|
|
|
op.Enrich("InstallDirectory", installDirectory);
|
|
|
|
|
|
|
2026-01-24 15:32:40 -06:00
|
|
|
|
await saveClient.UploadAsync(installDirectory, gameId);
|
2025-10-08 19:51:44 -05:00
|
|
|
|
|
|
|
|
|
|
op.Complete();
|
|
|
|
|
|
}
|
2024-10-23 18:17:01 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task DeleteAsync(Guid saveId)
|
|
|
|
|
|
{
|
2025-10-08 19:51:44 -05:00
|
|
|
|
using (var op = Logger.BeginDebugOperation("Deleting save"))
|
|
|
|
|
|
{
|
|
|
|
|
|
op.Enrich("SaveId", saveId);
|
|
|
|
|
|
|
2026-01-24 15:32:40 -06:00
|
|
|
|
await saveClient.DeleteAsync(saveId);
|
2025-10-08 19:51:44 -05:00
|
|
|
|
|
|
|
|
|
|
op.Complete();
|
|
|
|
|
|
}
|
2024-05-29 19:25:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-23 18:17:01 -05:00
|
|
|
|
|