Ensure that redistributable options persist in export/import

This commit is contained in:
Pat Hartl 2026-05-16 19:38:43 -05:00
parent 4fce064dd4
commit e84c8a9c7a
4 changed files with 32 additions and 3 deletions

View file

@ -21,9 +21,8 @@ public class GameExporter(
public override async Task<Game> ExportAsync(Guid id)
{
// Retrieve the game again, but only get the minimal amount of data required
var manifest = await gameService.GetAsync<Game>(id);
var manifest = await gameService.GetManifestAsync(id);
manifest.Actions ??= new List<SDK.Models.Manifest.Action>();
manifest.Archives ??= new List<SDK.Models.Manifest.Archive>();
manifest.Collections ??= new List<SDK.Models.Manifest.Collection>();
@ -36,6 +35,7 @@ public class GameExporter(
manifest.Platforms ??= new List<SDK.Models.Manifest.Platform>();
manifest.PlaySessions ??= new List<SDK.Models.Manifest.PlaySession>();
manifest.Publishers ??= new List<SDK.Models.Manifest.Company>();
manifest.Redistributables ??= new List<SDK.Models.Manifest.Redistributable>();
manifest.Saves ??= new List<SDK.Models.Manifest.Save>();
manifest.SavePaths ??= new List<SDK.Models.Manifest.SavePath>();
manifest.Scripts ??= new List<SDK.Models.Manifest.Script>();

View file

@ -37,10 +37,12 @@ public class ActionImporter(
var action = new Data.Models.Action
{
Name = record.Name,
Arguments = record.Arguments,
Path = record.Path,
WorkingDirectory = record.WorkingDirectory,
PrimaryAction = record.IsPrimaryAction,
SortOrder = record.SortOrder,
OptionOverrides = record.OptionOverrides,
CreatedOn = record.CreatedOn,
UpdatedOn = record.UpdatedOn,
};
@ -83,10 +85,12 @@ public class ActionImporter(
try
{
existing.Arguments = record.Arguments;
existing.Path = record.Path;
existing.WorkingDirectory = record.WorkingDirectory;
existing.PrimaryAction = record.IsPrimaryAction;
existing.SortOrder = record.SortOrder;
existing.OptionOverrides = record.OptionOverrides;
existing.CreatedOn = record.CreatedOn;
existing.UpdatedOn = record.UpdatedOn;

View file

@ -9,6 +9,7 @@ namespace LANCommander.Server.ImportExport.Importers;
public class GameImporter(
ILogger<GameImporter> logger,
GameService gameService,
RedistributableService redistributableService,
UserService userService) : BaseImporter<Game>
{
public override string GetKey(Game record)
@ -166,6 +167,29 @@ public class GameImporter(
manifest.Tags,
r => t => t.Name == r.Name);
if (manifest.Redistributables != null && manifest.Redistributables.Any())
{
await gameService.SyncRelatedCollectionAsync(
game,
g => g.Redistributables,
manifest.Redistributables,
r => rd => rd.Id == r.Id || rd.Name == r.Name);
foreach (var redistributable in manifest.Redistributables)
{
if (redistributable.Options != null && redistributable.Options.Any())
{
var existing = await redistributableService.FirstOrDefaultAsync(r => r.Id == redistributable.Id || r.Name == redistributable.Name);
if (existing != null)
{
var optionsJson = System.Text.Json.JsonSerializer.Serialize(redistributable.Options);
await gameService.SetRedistributableOptionsAsync(game.Id, existing.Id, optionsJson);
}
}
}
}
if (!string.IsNullOrWhiteSpace(manifest.BaseGame) || manifest.BaseGameId != Guid.Empty)
{
Data.Models.Game? baseGame = null;

View file

@ -52,6 +52,7 @@ public class RedistributableImporter(
existing.Name = record.Name;
existing.Description = record.Description;
existing.Notes = record.Notes;
existing.OptionSchema = record.OptionSchema;
existing.CreatedOn = record.CreatedOn;
existing.CreatedBy = await userService.GetAsync(record.CreatedBy);
existing.UpdatedOn = record.UpdatedOn;