2025-04-11 02:31:29 -05:00
|
|
|
using AutoMapper;
|
2025-04-10 19:45:41 -05:00
|
|
|
using LANCommander.SDK.Enums;
|
2025-03-30 21:05:48 -05:00
|
|
|
using LANCommander.SDK.Models.Manifest;
|
2025-07-27 17:51:50 -05:00
|
|
|
using LANCommander.Server.ImportExport.Exceptions;
|
|
|
|
|
using LANCommander.Server.ImportExport.Models;
|
|
|
|
|
using LANCommander.Server.Services;
|
2025-03-29 17:58:00 -05:00
|
|
|
|
2025-07-27 17:51:50 -05:00
|
|
|
namespace LANCommander.Server.ImportExport.Importers;
|
2025-03-29 17:58:00 -05:00
|
|
|
|
2025-04-10 19:45:41 -05:00
|
|
|
public class SavePathImporter(
|
2025-04-11 02:31:29 -05:00
|
|
|
IMapper mapper,
|
2025-07-19 17:39:55 -05:00
|
|
|
SavePathService savePathService) : BaseImporter<SavePath, Data.Models.SavePath>
|
2025-03-29 17:58:00 -05:00
|
|
|
{
|
2025-07-19 17:39:55 -05:00
|
|
|
public override async Task<ImportItemInfo> GetImportInfoAsync(SavePath record)
|
2025-04-12 02:37:14 -05:00
|
|
|
{
|
|
|
|
|
return new ImportItemInfo
|
|
|
|
|
{
|
2025-08-01 02:27:06 -05:00
|
|
|
Type = ImportExportRecordType.SavePath,
|
2025-04-12 02:37:14 -05:00
|
|
|
Name = record.Path,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-19 17:39:55 -05:00
|
|
|
public override bool CanImport(SavePath record) => ImportContext.DataRecord is Data.Models.Game;
|
2025-03-29 17:58:00 -05:00
|
|
|
|
2025-07-19 17:39:55 -05:00
|
|
|
public override async Task<Data.Models.SavePath> AddAsync(SavePath record)
|
2025-04-09 19:44:07 -05:00
|
|
|
{
|
2025-03-29 17:58:00 -05:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var savePath = new Data.Models.SavePath
|
|
|
|
|
{
|
|
|
|
|
Id = record.Id,
|
2025-07-19 17:39:55 -05:00
|
|
|
Game = ImportContext.DataRecord as Data.Models.Game,
|
2025-03-29 17:58:00 -05:00
|
|
|
Path = record.Path,
|
|
|
|
|
WorkingDirectory = record.WorkingDirectory,
|
|
|
|
|
IsRegex = record.IsRegex,
|
|
|
|
|
Type = record.Type,
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-09 19:44:07 -05:00
|
|
|
savePath = await savePathService.AddAsync(savePath);
|
2025-03-29 17:58:00 -05:00
|
|
|
|
2025-03-29 20:10:35 -05:00
|
|
|
return savePath;
|
2025-03-29 17:58:00 -05:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new ImportSkippedException<SavePath>(record, "An unknown error occured while importing save path", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-19 17:39:55 -05:00
|
|
|
public override async Task<Data.Models.SavePath> UpdateAsync(SavePath record)
|
2025-03-29 17:58:00 -05:00
|
|
|
{
|
2025-04-09 19:44:07 -05:00
|
|
|
var existing = await savePathService.FirstOrDefaultAsync(p => p.Id == record.Id);
|
2025-03-29 17:58:00 -05:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2025-07-19 17:39:55 -05:00
|
|
|
existing.Game = ImportContext.DataRecord as Data.Models.Game;
|
2025-03-29 17:58:00 -05:00
|
|
|
existing.Path = record.Path;
|
|
|
|
|
existing.WorkingDirectory = record.WorkingDirectory;
|
|
|
|
|
existing.IsRegex = record.IsRegex;
|
|
|
|
|
existing.Type = record.Type;
|
|
|
|
|
|
2025-04-09 19:44:07 -05:00
|
|
|
existing = await savePathService.UpdateAsync(existing);
|
2025-03-29 17:58:00 -05:00
|
|
|
|
2025-03-29 20:10:35 -05:00
|
|
|
return existing;
|
2025-03-29 17:58:00 -05:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new ImportSkippedException<SavePath>(record, "An unknown error occured while importing save path", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-19 17:39:55 -05:00
|
|
|
public override async Task<bool> ExistsAsync(SavePath record)
|
2025-03-29 17:58:00 -05:00
|
|
|
{
|
2025-04-09 19:44:07 -05:00
|
|
|
return await savePathService.ExistsAsync(p => p.Id == record.Id);
|
2025-03-29 17:58:00 -05:00
|
|
|
}
|
|
|
|
|
}
|