diff --git a/SabreTools.DatFiles/Formats/OfflineList.Reader.cs b/SabreTools.DatFiles/Formats/OfflineList.Reader.cs index 79f74e1c..f1ba887c 100644 --- a/SabreTools.DatFiles/Formats/OfflineList.Reader.cs +++ b/SabreTools.DatFiles/Formats/OfflineList.Reader.cs @@ -1,10 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using SabreTools.Core; using SabreTools.Core.Tools; -using SabreTools.DatItems; -using SabreTools.DatItems.Formats; namespace SabreTools.DatFiles.Formats { @@ -20,6 +17,7 @@ namespace SabreTools.DatFiles.Formats { // Deserialize the input file var dat = new Serialization.Files.OfflineList().Deserialize(filename); + var metadata = new Serialization.CrossModel.OfflineList().Serialize(dat); // Convert the header to the internal format OfflineList.ConvertHeader(dat); @@ -27,8 +25,8 @@ namespace SabreTools.DatFiles.Formats // Convert the configuration to the internal format ConvertConfiguration(dat?.Configuration, keep); - // Convert the games to the internal format - ConvertGames(dat?.Games, filename, indexId, statsOnly); + // Convert to the internal format + ConvertMetadata(metadata, filename, indexId, statsOnly); // Convert the GUI to the internal format ConvertGUI(dat?.GUI); @@ -269,113 +267,6 @@ namespace SabreTools.DatFiles.Formats // TODO: Add to internal model } - /// - /// Convert games information - /// - /// Deserialized model to convert - /// Name of the file to be parsed - /// Index ID for the DAT - /// True to only add item statistics while parsing, false otherwise - private void ConvertGames(Models.OfflineList.Games? games, string filename, int indexId, bool statsOnly) - { - // If the games array is missing, we can't do anything - if (games?.Game == null || !games.Game.Any()) - return; - - foreach (var game in games.Game) - { - ConvertGame(game, filename, indexId, statsOnly); - } - } - - /// - /// Convert game information - /// - /// Deserialized model to convert - /// Name of the file to be parsed - /// Index ID for the DAT - /// True to only add item statistics while parsing, false otherwise - private void ConvertGame(Models.OfflineList.Game? game, string filename, int indexId, bool statsOnly) - { - // If the game is missing, we can't do anything - if (game == null) - return; - - var machine = new Machine(); - machine.SetFieldValue(Models.Metadata.Machine.CommentKey, game.Comment); - machine.SetFieldValue(Models.Metadata.Machine.Im1CRCKey, game.Im1CRC); - machine.SetFieldValue(Models.Metadata.Machine.Im2CRCKey, game.Im2CRC); - machine.SetFieldValue(Models.Metadata.Machine.ImageNumberKey, game.ImageNumber); - machine.SetFieldValue(Models.Metadata.Machine.LanguageKey, game.Language); - machine.SetFieldValue(Models.Metadata.Machine.LocationKey, game.Location); - machine.SetFieldValue(Models.Metadata.Machine.NameKey, game.Title); - machine.SetFieldValue(Models.Metadata.Machine.PublisherKey, game.Publisher); - machine.SetFieldValue(Models.Metadata.Machine.ReleaseNumberKey, game.ReleaseNumber); - machine.SetFieldValue(Models.Metadata.Machine.SaveTypeKey, game.SaveType); - machine.SetFieldValue(Models.Metadata.Machine.SourceRomKey, game.SourceRom); - - long? size = NumberHelper.ConvertToInt64(game.RomSize); - if (game.DuplicateID != "0") - machine.SetFieldValue(Models.Metadata.Machine.CloneOfKey, game.DuplicateID); - - // Check if there are any items - bool containsItems = false; - - // Loop through each file - ConvertFiles(game.Files, machine, size, game.ReleaseNumber, filename, indexId, statsOnly, ref containsItems); - - // If we had no items, create a Blank placeholder - if (!containsItems) - { - var blank = new Blank - { - Source = new Source { Index = indexId, Name = filename }, - }; - - blank.CopyMachineInformation(machine); - ParseAddHelper(blank, statsOnly); - } - } - - /// - /// Convert Files information - /// - /// Array of deserialized models to convert - /// Prefilled machine to use - /// Item size to use - /// Release number to use - /// Name of the file to be parsed - /// Index ID for the DAT - /// True to only add item statistics while parsing, false otherwise - /// True if there were any items in the array, false otherwise - private void ConvertFiles(Models.OfflineList.Files? files, Machine machine, long? size, string? releaseNumber, string filename, int indexId, bool statsOnly, ref bool containsItems) - { - // If the files array is missing, we can't do anything - if (files?.RomCRC == null || !files.RomCRC.Any()) - return; - - containsItems = true; - foreach (var crc in files.RomCRC) - { - string name = string.Empty; - if (!string.IsNullOrEmpty(releaseNumber) && releaseNumber != "0") - name += $"{releaseNumber} - "; - name += $"{machine.GetFieldValue(Models.Metadata.Machine.NameKey)}{crc.Extension}"; - - var item = new Rom - { - Source = new Source { Index = indexId, Name = filename }, - }; - item.SetName(name); - item.SetFieldValue(Models.Metadata.Rom.CRCKey, crc.Content); - item.SetFieldValue(Models.Metadata.Rom.SizeKey, size); - item.SetFieldValue(Models.Metadata.Rom.StatusKey, ItemStatus.None); - - item.CopyMachineInformation(machine); - ParseAddHelper(item, statsOnly); - } - } - /// /// Convert GUI information ///