From 472d4c22264af07ec07177c2d685eefd8943836f Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 4 Aug 2023 23:48:17 -0400 Subject: [PATCH] Add DosCenter machine serialization --- .../Internal.DosCenter.cs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/SabreTools.Serialization/Internal.DosCenter.cs b/SabreTools.Serialization/Internal.DosCenter.cs index c55581aa..a67b2a8a 100644 --- a/SabreTools.Serialization/Internal.DosCenter.cs +++ b/SabreTools.Serialization/Internal.DosCenter.cs @@ -1,3 +1,6 @@ +using System.Collections.Generic; +using System.Linq; + namespace SabreTools.Serialization { /// @@ -7,6 +10,29 @@ namespace SabreTools.Serialization { #region Serialize + /// + /// Convert from to + /// + public static Models.Internal.Machine ConvertMachineFromDosCenter(Models.DosCenter.Game item) + { + var machine = new Models.Internal.Machine + { + [Models.Internal.Machine.NameKey] = item.Name, + }; + + if (item.File != null && item.File.Any()) + { + var roms = new List(); + foreach (var file in item.File) + { + roms.Add(ConvertFromDosCenter(file)); + } + machine[Models.Internal.Machine.RomKey] = roms.ToArray(); + } + + return machine; + } + /// /// Convert from to /// @@ -26,6 +52,29 @@ namespace SabreTools.Serialization #region Deserialize + /// + /// Convert from to + /// + public static Models.DosCenter.Game ConvertMachineToDosCenter(Models.Internal.Machine item) + { + var game = new Models.DosCenter.Game + { + Name = item.ReadString(Models.Internal.Machine.NameKey), + }; + + if (item.ContainsKey(Models.Internal.Machine.RomKey) && item[Models.Internal.Machine.RomKey] is Models.Internal.Rom[] roms) + { + var fileItems = new List(); + foreach (var rom in roms) + { + fileItems.Add(ConvertToDosCenter(rom)); + } + game.File = fileItems.ToArray(); + } + + return game; + } + /// /// Convert from to ///