diff --git a/SabreTools.Models/Internal/Machine.cs b/SabreTools.Models/Internal/Machine.cs index 6d619c90..8502477c 100644 --- a/SabreTools.Models/Internal/Machine.cs +++ b/SabreTools.Models/Internal/Machine.cs @@ -54,6 +54,9 @@ namespace SabreTools.Models.Internal /// string public const string DescriptionKey = "description"; + /// Device[] + public const string DeviceKey = "device"; + /// DeviceRef[] public const string DeviceRefKey = "device_ref"; @@ -90,6 +93,9 @@ namespace SabreTools.Models.Internal /// string public const string FavoriteKey = "favorite"; + /// Feature[] + public const string FeatureKey = "feature"; + /// string public const string GenMSXIDKey = "genmsxid"; diff --git a/SabreTools.Serialization/Internal.Listxml.cs b/SabreTools.Serialization/Internal.Listxml.cs index a6fca7d4..044a07d3 100644 --- a/SabreTools.Serialization/Internal.Listxml.cs +++ b/SabreTools.Serialization/Internal.Listxml.cs @@ -10,6 +10,210 @@ namespace SabreTools.Serialization { #region Serialize + /// + /// Convert from to + /// + public static Models.Internal.Machine ConvertMachineFromListxml(Models.Listxml.GameBase item) + { + var machine = new Models.Internal.Machine + { + [Models.Internal.Machine.NameKey] = item.Name, + [Models.Internal.Machine.SourceFileKey] = item.SourceFile, + [Models.Internal.Machine.IsBiosKey] = item.IsBios, + [Models.Internal.Machine.IsDeviceKey] = item.IsDevice, + [Models.Internal.Machine.IsMechanicalKey] = item.IsMechanical, + [Models.Internal.Machine.RunnableKey] = item.Runnable, + [Models.Internal.Machine.CloneOfKey] = item.CloneOf, + [Models.Internal.Machine.RomOfKey] = item.RomOf, + [Models.Internal.Machine.SampleOfKey] = item.SampleOf, + [Models.Internal.Machine.DescriptionKey] = item.Description, + [Models.Internal.Machine.YearKey] = item.Year, + [Models.Internal.Machine.ManufacturerKey] = item.Manufacturer, + [Models.Internal.Machine.HistoryKey] = item.History, + }; + + if (item.BiosSet != null && item.BiosSet.Any()) + { + var biosSets = new List(); + foreach (var biosSet in item.BiosSet) + { + biosSets.Add(ConvertFromListxml(biosSet)); + } + machine[Models.Internal.Machine.BiosSetKey] = biosSets.ToArray(); + } + + if (item.Rom != null && item.Rom.Any()) + { + var roms = new List(); + foreach (var rom in item.Rom) + { + roms.Add(ConvertFromListxml(rom)); + } + machine[Models.Internal.Machine.RomKey] = roms.ToArray(); + } + + if (item.Disk != null && item.Disk.Any()) + { + var disks = new List(); + foreach (var disk in item.Disk) + { + disks.Add(ConvertFromListxml(disk)); + } + machine[Models.Internal.Machine.DiskKey] = disks.ToArray(); + } + + if (item.DeviceRef != null && item.DeviceRef.Any()) + { + var deviceRefs = new List(); + foreach (var deviceRef in item.DeviceRef) + { + deviceRefs.Add(ConvertFromListxml(deviceRef)); + } + machine[Models.Internal.Machine.DeviceRefKey] = deviceRefs.ToArray(); + } + + if (item.Sample != null && item.Sample.Any()) + { + var samples = new List(); + foreach (var sample in item.Sample) + { + samples.Add(ConvertFromListxml(sample)); + } + machine[Models.Internal.Machine.SampleKey] = samples.ToArray(); + } + + if (item.Chip != null && item.Chip.Any()) + { + var chips = new List(); + foreach (var chip in item.Chip) + { + chips.Add(ConvertFromListxml(chip)); + } + machine[Models.Internal.Machine.ChipKey] = chips.ToArray(); + } + + if (item.Display != null && item.Display.Any()) + { + var displays = new List(); + foreach (var display in item.Display) + { + displays.Add(ConvertFromListxml(display)); + } + machine[Models.Internal.Machine.DisplayKey] = displays.ToArray(); + } + + if (item.Video != null && item.Video.Any()) + { + var videos = new List(); + foreach (var video in item.Video) + { + videos.Add(ConvertFromListxml(video)); + } + machine[Models.Internal.Machine.VideoKey] = videos.ToArray(); + } + + if (item.Sound != null) + machine[Models.Internal.Machine.SoundKey] = ConvertFromListxml(item.Sound); + + if (item.Input != null) + machine[Models.Internal.Machine.InputKey] = ConvertFromListxml(item.Input); + + if (item.DipSwitch != null && item.DipSwitch.Any()) + { + var dipSwitches = new List(); + foreach (var dipSwitch in item.DipSwitch) + { + dipSwitches.Add(ConvertFromListxml(dipSwitch)); + } + machine[Models.Internal.Machine.DipSwitchKey] = dipSwitches.ToArray(); + } + + if (item.Configuration != null && item.Configuration.Any()) + { + var configurations = new List(); + foreach (var configuration in item.Configuration) + { + configurations.Add(ConvertFromListxml(configuration)); + } + machine[Models.Internal.Machine.ConfigurationKey] = configurations.ToArray(); + } + + if (item.Port != null && item.Port.Any()) + { + var ports = new List(); + foreach (var port in item.Port) + { + ports.Add(ConvertFromListxml(port)); + } + machine[Models.Internal.Machine.PortKey] = ports.ToArray(); + } + + if (item.Adjuster != null && item.Adjuster.Any()) + { + var adjusters = new List(); + foreach (var adjuster in item.Adjuster) + { + adjusters.Add(ConvertFromListxml(adjuster)); + } + machine[Models.Internal.Machine.AdjusterKey] = adjusters.ToArray(); + } + + if (item.Driver != null) + machine[Models.Internal.Machine.DriverKey] = ConvertFromListxml(item.Driver); + + if (item.Feature != null && item.Feature.Any()) + { + var features = new List(); + foreach (var feature in item.Feature) + { + features.Add(ConvertFromListxml(feature)); + } + machine[Models.Internal.Machine.FeatureKey] = features.ToArray(); + } + + if (item.Device != null && item.Device.Any()) + { + var devices = new List(); + foreach (var device in item.Device) + { + devices.Add(ConvertFromListxml(device)); + } + machine[Models.Internal.Machine.DeviceKey] = devices.ToArray(); + } + + if (item.Slot != null && item.Slot.Any()) + { + var slots = new List(); + foreach (var slot in item.Slot) + { + slots.Add(ConvertFromListxml(slot)); + } + machine[Models.Internal.Machine.SlotKey] = slots.ToArray(); + } + + if (item.SoftwareList != null && item.SoftwareList.Any()) + { + var softwareLists = new List(); + foreach (var softwareList in item.SoftwareList) + { + softwareLists.Add(ConvertFromListxml(softwareList)); + } + machine[Models.Internal.Machine.SoftwareListKey] = softwareLists.ToArray(); + } + + if (item.RamOption != null && item.RamOption.Any()) + { + var ramOptions = new List(); + foreach (var ramOption in item.RamOption) + { + ramOptions.Add(ConvertFromListxml(ramOption)); + } + machine[Models.Internal.Machine.RamOptionKey] = ramOptions.ToArray(); + } + + return machine; + } + /// /// Convert from to /// @@ -580,6 +784,210 @@ namespace SabreTools.Serialization #region Deserialize + /// + /// Convert from to + /// + public static Models.Listxml.GameBase ConvertMachineToListxml(Models.Internal.Machine item) + { + var machine = new Models.Listxml.Machine + { + Name = item.ReadString(Models.Internal.Machine.NameKey), + SourceFile = item.ReadString(Models.Internal.Machine.SourceFileKey), + IsBios = item.ReadString(Models.Internal.Machine.IsBiosKey), + IsDevice = item.ReadString(Models.Internal.Machine.IsDeviceKey), + IsMechanical = item.ReadString(Models.Internal.Machine.IsMechanicalKey), + Runnable = item.ReadString(Models.Internal.Machine.RunnableKey), + CloneOf = item.ReadString(Models.Internal.Machine.CloneOfKey), + RomOf = item.ReadString(Models.Internal.Machine.RomOfKey), + SampleOf = item.ReadString(Models.Internal.Machine.SampleOfKey), + Description = item.ReadString(Models.Internal.Machine.DescriptionKey), + Year = item.ReadString(Models.Internal.Machine.YearKey), + Manufacturer = item.ReadString(Models.Internal.Machine.ManufacturerKey), + History = item.ReadString(Models.Internal.Machine.HistoryKey), + }; + + if (item.ContainsKey(Models.Internal.Machine.BiosSetKey) && item[Models.Internal.Machine.BiosSetKey] is Models.Internal.BiosSet[] biosSets) + { + var biosSetItems = new List(); + foreach (var biosSet in biosSets) + { + biosSetItems.Add(ConvertToListxml(biosSet)); + } + machine.BiosSet = biosSetItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.RomKey) && item[Models.Internal.Machine.RomKey] is Models.Internal.Rom[] roms) + { + var romItems = new List(); + foreach (var rom in roms) + { + romItems.Add(ConvertToListxml(rom)); + } + machine.Rom = romItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.DiskKey) && item[Models.Internal.Machine.DiskKey] is Models.Internal.Disk[] disks) + { + var diskItems = new List(); + foreach (var disk in disks) + { + diskItems.Add(ConvertToListxml(disk)); + } + machine.Disk = diskItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.DeviceRefKey) && item[Models.Internal.Machine.DeviceRefKey] is Models.Internal.DeviceRef[] deviceRefs) + { + var deviceRefItems = new List(); + foreach (var deviceRef in deviceRefs) + { + deviceRefItems.Add(ConvertToListxml(deviceRef)); + } + machine.DeviceRef = deviceRefItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.SampleKey) && item[Models.Internal.Machine.SampleKey] is Models.Internal.Sample[] samples) + { + var sampleItems = new List(); + foreach (var sample in samples) + { + sampleItems.Add(ConvertToListxml(sample)); + } + machine.Sample = sampleItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.ChipKey) && item[Models.Internal.Machine.ChipKey] is Models.Internal.Chip[] chips) + { + var chipItems = new List(); + foreach (var chip in chips) + { + chipItems.Add(ConvertToListxml(chip)); + } + machine.Chip = chipItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.DisplayKey) && item[Models.Internal.Machine.DisplayKey] is Models.Internal.Display[] displays) + { + var displayItems = new List(); + foreach (var display in displays) + { + displayItems.Add(ConvertToListxml(display)); + } + machine.Display = displayItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.VideoKey) && item[Models.Internal.Machine.VideoKey] is Models.Internal.Video[] videos) + { + var videoItems = new List(); + foreach (var video in videos) + { + videoItems.Add(ConvertToListxml(video)); + } + machine.Video = videoItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.SoundKey) && item[Models.Internal.Machine.SoundKey] is Models.Internal.Sound sound) + machine.Sound = ConvertToListxml(sound); + + if (item.ContainsKey(Models.Internal.Machine.InputKey) && item[Models.Internal.Machine.InputKey] is Models.Internal.Input input) + machine.Input = ConvertToListxml(input); + + if (item.ContainsKey(Models.Internal.Machine.DipSwitchKey) && item[Models.Internal.Machine.DipSwitchKey] is Models.Internal.DipSwitch[] dipSwitches) + { + var dipSwitchItems = new List(); + foreach (var dipSwitch in dipSwitches) + { + dipSwitchItems.Add(ConvertToListxml(dipSwitch)); + } + machine.DipSwitch = dipSwitchItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.ConfigurationKey) && item[Models.Internal.Machine.ConfigurationKey] is Models.Internal.Configuration[] configurations) + { + var configurationItems = new List(); + foreach (var configuration in configurations) + { + configurationItems.Add(ConvertToListxml(configuration)); + } + machine.Configuration = configurationItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.PortKey) && item[Models.Internal.Machine.PortKey] is Models.Internal.Port[] ports) + { + var portItems = new List(); + foreach (var port in ports) + { + portItems.Add(ConvertToListxml(port)); + } + machine.Port = portItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.AdjusterKey) && item[Models.Internal.Machine.AdjusterKey] is Models.Internal.Adjuster[] adjusters) + { + var adjusterItems = new List(); + foreach (var adjuster in adjusters) + { + adjusterItems.Add(ConvertToListxml(adjuster)); + } + machine.Adjuster = adjusterItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.DriverKey) && item[Models.Internal.Machine.DriverKey] is Models.Internal.Driver driver) + machine.Driver = ConvertToListxml(driver); + + if (item.ContainsKey(Models.Internal.Machine.FeatureKey) && item[Models.Internal.Machine.FeatureKey] is Models.Internal.Feature[] features) + { + var featureItems = new List(); + foreach (var feature in features) + { + featureItems.Add(ConvertToListxml(feature)); + } + machine.Feature = featureItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.DeviceKey) && item[Models.Internal.Machine.DeviceKey] is Models.Internal.Device[] devices) + { + var deviceItems = new List(); + foreach (var device in devices) + { + deviceItems.Add(ConvertToListxml(device)); + } + machine.Device = deviceItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.SlotKey) && item[Models.Internal.Machine.SlotKey] is Models.Internal.Slot[] slots) + { + var slotItems = new List(); + foreach (var slot in slots) + { + slotItems.Add(ConvertToListxml(slot)); + } + machine.Slot = slotItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.SoftwareListKey) && item[Models.Internal.Machine.SoftwareListKey] is Models.Internal.SoftwareList[] softwareLists) + { + var softwareListItems = new List(); + foreach (var softwareList in softwareLists) + { + softwareListItems.Add(ConvertToListxml(softwareList)); + } + machine.SoftwareList = softwareListItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Machine.RamOptionKey) && item[Models.Internal.Machine.RamOptionKey] is Models.Internal.RamOption[] ramOptions) + { + var ramOptionItems = new List(); + foreach (var ramOption in ramOptions) + { + ramOptionItems.Add(ConvertToListxml(ramOption)); + } + machine.RamOption = ramOptionItems.ToArray(); + } + + return machine; + } + /// /// Convert from to ///