diff --git a/SabreTools.DatFiles/Formats/DosCenter.Reader.cs b/SabreTools.DatFiles/Formats/DosCenter.Reader.cs index 3ed2e4f7..56ad3166 100644 --- a/SabreTools.DatFiles/Formats/DosCenter.Reader.cs +++ b/SabreTools.DatFiles/Formats/DosCenter.Reader.cs @@ -1,8 +1,4 @@ using System; -using System.Linq; -using SabreTools.Core.Tools; -using SabreTools.DatItems; -using SabreTools.DatItems.Formats; namespace SabreTools.DatFiles.Formats { @@ -18,12 +14,13 @@ namespace SabreTools.DatFiles.Formats { // Deserialize the input file var metadataFile = new Serialization.Files.DosCenter().Deserialize(filename); + var metadata = new Serialization.CrossModel.DosCenter().Serialize(metadataFile); // Convert the header to the internal format ConvertHeader(metadataFile?.DosCenter, keep); - // Convert the game data to the internal format - ConvertGames(metadataFile?.Game, filename, indexId, statsOnly); + // Convert to the internal format + ConvertMetadata(metadata, filename, indexId, statsOnly); } catch (Exception ex) when (!throwOnError) { @@ -57,98 +54,6 @@ namespace SabreTools.DatFiles.Formats if (doscenter.Name?.Contains(" - SuperDAT") == true && keep) Header.Type ??= "SuperDAT"; } - - /// - /// Convert games information - /// - /// Array of deserialized models 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.DosCenter.Game[]? games, string filename, int indexId, bool statsOnly) - { - // If the game array is missing, we can't do anything - if (games == null || !games.Any()) - return; - - // Loop through the games and add - foreach (var game in games) - { - 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.DosCenter.Game game, string filename, int indexId, bool statsOnly) - { - // If the game is missing, we can't do anything - if (game == null) - return; - - // Create the machine for copying information - string? machineName = game.Name?.Trim('"'); - if (machineName?.EndsWith(".zip") == true) - machineName = System.IO.Path.GetFileNameWithoutExtension(machineName); - - var machine = new Machine(); - machine.SetFieldValue(Models.Metadata.Machine.NameKey, machineName); - - // Check if there are any items - bool containsItems = false; - - // Loop through each type of item - ConvertFiles(game.File, machine, 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 Rom information - /// - /// Array of deserialized models to convert - /// Prefilled machine 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.DosCenter.File[]? files, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems) - { - // If the files array is missing, we can't do anything - if (files == null || !files.Any()) - return; - - containsItems = true; - foreach (var file in files) - { - var item = new Rom - { - Source = new Source { Index = indexId, Name = filename }, - }; - item.SetName(file.Name); - item.SetFieldValue(Models.Metadata.Rom.CRCKey, file.CRC); - item.SetFieldValue(Models.Metadata.Rom.DateKey, file.Date); - item.SetFieldValue(Models.Metadata.Rom.SizeKey, NumberHelper.ConvertToInt64(file.Size)); - - item.CopyMachineInformation(machine); - ParseAddHelper(item, statsOnly); - } - } #endregion }