LANCommander/LANCommander.Launcher.Services/SaveService.cs

95 lines
3 KiB
C#
Raw Permalink Normal View History

2025-10-08 19:51:44 -05:00
using LANCommander.SDK.Extensions;
using LANCommander.SDK.Models;
using LANCommander.SDK.Services;
2024-09-11 00:24:34 -05:00
using Microsoft.Extensions.Logging;
namespace LANCommander.Launcher.Services
{
public class SaveService(
ILogger<SaveService> logger,
SaveClient saveClient) : BaseService(logger)
{
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);
var saves = await saveClient.GetAsync(gameId);
2025-10-08 19:51:44 -05:00
if (saves == null)
saves = new List<GameSave>();
op.Complete();
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);
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)
{
2025-10-08 19:51:44 -05:00
using (var op = Logger.BeginDebugOperation("Downloading latest save"))
{
op.Enrich("GameId", gameId);
op.Enrich("InstallDirectory", installDirectory);
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);
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);
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);
await saveClient.DeleteAsync(saveId);
2025-10-08 19:51:44 -05:00
op.Complete();
}
}
}
}
2024-10-23 18:17:01 -05:00