using System.Collections.Generic; using System.Linq; namespace SabreTools.Serialization { /// /// Serializer for Logiqx models to internal structure /// public partial class Internal { #region Serialize /// /// Convert from to /// public static Models.Internal.Machine ConvertMachineFromLogiqx(Models.Logiqx.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.CloneOfKey] = item.CloneOf, [Models.Internal.Machine.RomOfKey] = item.RomOf, [Models.Internal.Machine.SampleOfKey] = item.SampleOf, [Models.Internal.Machine.BoardKey] = item.Board, [Models.Internal.Machine.RebuildToKey] = item.RebuildTo, [Models.Internal.Machine.IdKey] = item.Id, [Models.Internal.Machine.CloneOfIdKey] = item.CloneOfId, [Models.Internal.Machine.RunnableKey] = item.Runnable, [Models.Internal.Machine.CommentKey] = item.Comment, [Models.Internal.Machine.DescriptionKey] = item.Description, [Models.Internal.Machine.YearKey] = item.Year, [Models.Internal.Machine.ManufacturerKey] = item.Manufacturer, [Models.Internal.Machine.PublisherKey] = item.Publisher, [Models.Internal.Machine.CategoryKey] = item.Category, [Models.Internal.Machine.TruripKey] = item.Trurip, }; if (item.Release != null && item.Release.Any()) { var releases = new List(); foreach (var release in item.Release) { releases.Add(ConvertFromLogiqx(release)); } machine[Models.Internal.Machine.ReleaseKey] = releases.ToArray(); } if (item.BiosSet != null && item.BiosSet.Any()) { var biosSets = new List(); foreach (var biosSet in item.BiosSet) { biosSets.Add(ConvertFromLogiqx(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(ConvertFromLogiqx(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(ConvertFromLogiqx(disk)); } machine[Models.Internal.Machine.DiskKey] = disks.ToArray(); } if (item.Media != null && item.Media.Any()) { var medias = new List(); foreach (var media in item.Media) { medias.Add(ConvertFromLogiqx(media)); } machine[Models.Internal.Machine.MediaKey] = medias.ToArray(); } if (item.DeviceRef != null && item.DeviceRef.Any()) { var deviceRefs = new List(); foreach (var deviceRef in item.DeviceRef) { deviceRefs.Add(ConvertFromLogiqx(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(ConvertFromLogiqx(sample)); } machine[Models.Internal.Machine.SampleKey] = samples.ToArray(); } if (item.Archive != null && item.Archive.Any()) { var archives = new List(); foreach (var archive in item.Archive) { archives.Add(ConvertFromLogiqx(archive)); } machine[Models.Internal.Machine.ArchiveKey] = archives.ToArray(); } if (item.Driver != null && item.Driver.Any()) { var drivers = new List(); foreach (var driver in item.Driver) { drivers.Add(ConvertFromLogiqx(driver)); } machine[Models.Internal.Machine.DriverKey] = drivers.ToArray(); } if (item.SoftwareList != null && item.SoftwareList.Any()) { var softwareLists = new List(); foreach (var softwareList in item.SoftwareList) { softwareLists.Add(ConvertFromLogiqx(softwareList)); } machine[Models.Internal.Machine.SoftwareListKey] = softwareLists.ToArray(); } return machine; } /// /// Convert from to /// public static Models.Internal.Archive ConvertFromLogiqx(Models.Logiqx.Archive item) { var archive = new Models.Internal.Archive { [Models.Internal.Archive.NameKey] = item.Name, }; return archive; } /// /// Convert from to /// public static Models.Internal.BiosSet ConvertFromLogiqx(Models.Logiqx.BiosSet item) { var biosset = new Models.Internal.BiosSet { [Models.Internal.BiosSet.NameKey] = item.Name, [Models.Internal.BiosSet.DescriptionKey] = item.Description, [Models.Internal.BiosSet.DefaultKey] = item.Default, }; return biosset; } /// /// Convert from to /// public static Models.Internal.DeviceRef ConvertFromLogiqx(Models.Logiqx.DeviceRef item) { var deviceRef = new Models.Internal.DeviceRef { [Models.Internal.DeviceRef.NameKey] = item.Name, }; return deviceRef; } /// /// Convert from to /// public static Models.Internal.Disk ConvertFromLogiqx(Models.Logiqx.Disk item) { var disk = new Models.Internal.Disk { [Models.Internal.Disk.NameKey] = item.Name, [Models.Internal.Disk.MD5Key] = item.MD5, [Models.Internal.Disk.SHA1Key] = item.SHA1, [Models.Internal.Disk.MergeKey] = item.Merge, [Models.Internal.Disk.StatusKey] = item.Status, [Models.Internal.Disk.RegionKey] = item.Region, }; return disk; } /// /// Convert from to /// public static Models.Internal.Driver ConvertFromLogiqx(Models.Logiqx.Driver item) { var driver = new Models.Internal.Driver { [Models.Internal.Driver.StatusKey] = item.Status, [Models.Internal.Driver.EmulationKey] = item.Emulation, [Models.Internal.Driver.CocktailKey] = item.Cocktail, [Models.Internal.Driver.SaveStateKey] = item.SaveState, [Models.Internal.Driver.RequiresArtworkKey] = item.RequiresArtwork, [Models.Internal.Driver.UnofficialKey] = item.Unofficial, [Models.Internal.Driver.NoSoundHardwareKey] = item.NoSoundHardware, [Models.Internal.Driver.IncompleteKey] = item.Incomplete, }; return driver; } /// /// Convert from to /// public static Models.Internal.Media ConvertFromLogiqx(Models.Logiqx.Media item) { var media = new Models.Internal.Media { [Models.Internal.Media.NameKey] = item.Name, [Models.Internal.Media.MD5Key] = item.MD5, [Models.Internal.Media.SHA1Key] = item.SHA1, [Models.Internal.Media.SHA256Key] = item.SHA256, [Models.Internal.Media.SpamSumKey] = item.SpamSum, }; return media; } /// /// Convert from to /// public static Models.Internal.Release ConvertFromLogiqx(Models.Logiqx.Release item) { var release = new Models.Internal.Release { [Models.Internal.Release.NameKey] = item.Name, [Models.Internal.Release.RegionKey] = item.Region, [Models.Internal.Release.LanguageKey] = item.Language, [Models.Internal.Release.DateKey] = item.Date, [Models.Internal.Release.DefaultKey] = item.Default, }; return release; } /// /// Convert from to /// public static Models.Internal.Rom ConvertFromLogiqx(Models.Logiqx.Rom item) { var rom = new Models.Internal.Rom { [Models.Internal.Rom.NameKey] = item.Name, [Models.Internal.Rom.SizeKey] = item.Size, [Models.Internal.Rom.CRCKey] = item.CRC, [Models.Internal.Rom.MD5Key] = item.MD5, [Models.Internal.Rom.SHA1Key] = item.SHA1, [Models.Internal.Rom.SHA256Key] = item.SHA256, [Models.Internal.Rom.SHA384Key] = item.SHA384, [Models.Internal.Rom.SHA512Key] = item.SHA512, [Models.Internal.Rom.SpamSumKey] = item.SpamSum, [Models.Internal.Rom.xxHash364Key] = item.xxHash364, [Models.Internal.Rom.xxHash3128Key] = item.xxHash3128, [Models.Internal.Rom.MergeKey] = item.Merge, [Models.Internal.Rom.StatusKey] = item.Status, [Models.Internal.Rom.SerialKey] = item.Serial, [Models.Internal.Rom.HeaderKey] = item.Header, [Models.Internal.Rom.DateKey] = item.Date, [Models.Internal.Rom.InvertedKey] = item.Inverted, [Models.Internal.Rom.MIAKey] = item.MIA, }; return rom; } /// /// Convert from to /// public static Models.Internal.Sample ConvertFromLogiqx(Models.Logiqx.Sample item) { var sample = new Models.Internal.Sample { [Models.Internal.Sample.NameKey] = item.Name, }; return sample; } /// /// Convert from to /// public static Models.Internal.SoftwareList ConvertFromLogiqx(Models.Logiqx.SoftwareList item) { var softwareList = new Models.Internal.SoftwareList { [Models.Internal.SoftwareList.TagKey] = item.Tag, [Models.Internal.SoftwareList.NameKey] = item.Name, [Models.Internal.SoftwareList.StatusKey] = item.Status, [Models.Internal.SoftwareList.FilterKey] = item.Filter, }; return softwareList; } #endregion #region Deserialize /// /// Convert from to /// public static Models.Logiqx.GameBase ConvertMachineToLogiqx(Models.Internal.Machine item, bool game = false) { Models.Logiqx.GameBase gameBase = game ? new Models.Logiqx.Game() : new Models.Logiqx.Machine(); gameBase.Name = item.ReadString(Models.Internal.Machine.NameKey); gameBase.SourceFile = item.ReadString(Models.Internal.Machine.SourceFileKey); gameBase.IsBios = item.ReadString(Models.Internal.Machine.IsBiosKey); gameBase.IsDevice = item.ReadString(Models.Internal.Machine.IsDeviceKey); gameBase.IsMechanical = item.ReadString(Models.Internal.Machine.IsMechanicalKey); gameBase.CloneOf = item.ReadString(Models.Internal.Machine.CloneOfKey); gameBase.RomOf = item.ReadString(Models.Internal.Machine.RomOfKey); gameBase.SampleOf = item.ReadString(Models.Internal.Machine.SampleOfKey); gameBase.Board = item.ReadString(Models.Internal.Machine.BoardKey); gameBase.RebuildTo = item.ReadString(Models.Internal.Machine.RebuildToKey); gameBase.Id = item.ReadString(Models.Internal.Machine.IdKey); gameBase.CloneOfId = item.ReadString(Models.Internal.Machine.CloneOfIdKey); gameBase.Runnable = item.ReadString(Models.Internal.Machine.RunnableKey); gameBase.Comment = item.ReadStringArray(Models.Internal.Machine.CommentKey); gameBase.Description = item.ReadString(Models.Internal.Machine.DescriptionKey); gameBase.Year = item.ReadString(Models.Internal.Machine.YearKey); gameBase.Manufacturer = item.ReadString(Models.Internal.Machine.ManufacturerKey); gameBase.Publisher = item.ReadString(Models.Internal.Machine.PublisherKey); gameBase.Category = item.ReadStringArray(Models.Internal.Machine.CategoryKey); if (item.ContainsKey(Models.Internal.Machine.TruripKey) && item[Models.Internal.Machine.TruripKey] is Models.Logiqx.Trurip trurip) gameBase.Trurip = trurip; if (item.ContainsKey(Models.Internal.Machine.ReleaseKey) && item[Models.Internal.Machine.ReleaseKey] is Models.Internal.Release[] releases) { var releaseItems = new List(); foreach (var release in releases) { releaseItems.Add(ConvertToLogiqx(release)); } gameBase.Release = releaseItems.ToArray(); } 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(ConvertToLogiqx(biosSet)); } gameBase.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(ConvertToLogiqx(rom)); } gameBase.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(ConvertToLogiqx(disk)); } gameBase.Disk = diskItems.ToArray(); } if (item.ContainsKey(Models.Internal.Machine.MediaKey) && item[Models.Internal.Machine.MediaKey] is Models.Internal.Media[] medias) { var mediaItems = new List(); foreach (var media in medias) { mediaItems.Add(ConvertToLogiqx(media)); } gameBase.Media = mediaItems.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(ConvertToLogiqx(deviceRef)); } gameBase.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(ConvertToLogiqx(sample)); } gameBase.Sample = sampleItems.ToArray(); } if (item.ContainsKey(Models.Internal.Machine.ArchiveKey) && item[Models.Internal.Machine.ArchiveKey] is Models.Internal.Archive[] archives) { var archiveItems = new List(); foreach (var archive in archives) { archiveItems.Add(ConvertToLogiqx(archive)); } gameBase.Archive = archiveItems.ToArray(); } if (item.ContainsKey(Models.Internal.Machine.DriverKey) && item[Models.Internal.Machine.DriverKey] is Models.Internal.Driver[] drivers) { var driverItems = new List(); foreach (var chip in drivers) { driverItems.Add(ConvertToLogiqx(chip)); } gameBase.Driver = driverItems.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(ConvertToLogiqx(softwareList)); } gameBase.SoftwareList = softwareListItems.ToArray(); } return gameBase; } /// /// Convert from to /// public static Models.Logiqx.Archive ConvertToLogiqx(Models.Internal.Archive item) { var archive = new Models.Logiqx.Archive { Name = item.ReadString(Models.Internal.Archive.NameKey), }; return archive; } /// /// Convert from to /// public static Models.Logiqx.BiosSet ConvertToLogiqx(Models.Internal.BiosSet item) { var biosset = new Models.Logiqx.BiosSet { Name = item.ReadString(Models.Internal.BiosSet.NameKey), Description = item.ReadString(Models.Internal.BiosSet.DescriptionKey), Default = item.ReadString(Models.Internal.BiosSet.DefaultKey), }; return biosset; } /// /// Convert from to /// public static Models.Logiqx.DeviceRef ConvertToLogiqx(Models.Internal.DeviceRef item) { var deviceRef = new Models.Logiqx.DeviceRef { Name = item.ReadString(Models.Internal.DipSwitch.NameKey), }; return deviceRef; } /// /// Convert from to /// public static Models.Logiqx.Disk ConvertToLogiqx(Models.Internal.Disk item) { var disk = new Models.Logiqx.Disk { Name = item.ReadString(Models.Internal.Disk.NameKey), MD5 = item.ReadString(Models.Internal.Disk.MD5Key), SHA1 = item.ReadString(Models.Internal.Disk.SHA1Key), Merge = item.ReadString(Models.Internal.Disk.MergeKey), Status = item.ReadString(Models.Internal.Disk.StatusKey), Region = item.ReadString(Models.Internal.Disk.RegionKey), }; return disk; } /// /// Convert from to /// public static Models.Logiqx.Driver ConvertToLogiqx(Models.Internal.Driver item) { var driver = new Models.Logiqx.Driver { Status = item.ReadString(Models.Internal.Driver.StatusKey), Emulation = item.ReadString(Models.Internal.Driver.EmulationKey), Cocktail = item.ReadString(Models.Internal.Driver.CocktailKey), SaveState = item.ReadString(Models.Internal.Driver.SaveStateKey), RequiresArtwork = item.ReadString(Models.Internal.Driver.RequiresArtworkKey), Unofficial = item.ReadString(Models.Internal.Driver.UnofficialKey), NoSoundHardware = item.ReadString(Models.Internal.Driver.NoSoundHardwareKey), Incomplete = item.ReadString(Models.Internal.Driver.IncompleteKey), }; return driver; } /// /// Convert from to /// public static Models.Logiqx.Media ConvertToLogiqx(Models.Internal.Media item) { var media = new Models.Logiqx.Media { Name = item.ReadString(Models.Internal.Media.NameKey), MD5 = item.ReadString(Models.Internal.Media.MD5Key), SHA1 = item.ReadString(Models.Internal.Media.SHA1Key), SHA256 = item.ReadString(Models.Internal.Media.SHA256Key), SpamSum = item.ReadString(Models.Internal.Media.SpamSumKey), }; return media; } /// /// Convert from to /// public static Models.Logiqx.Release ConvertToLogiqx(Models.Internal.Release item) { var release = new Models.Logiqx.Release { Name = item.ReadString(Models.Internal.Release.NameKey), Region = item.ReadString(Models.Internal.Release.RegionKey), Language = item.ReadString(Models.Internal.Release.LanguageKey), Date = item.ReadString(Models.Internal.Release.DateKey), Default = item.ReadString(Models.Internal.Release.DefaultKey), }; return release; } /// /// Convert from to /// public static Models.Logiqx.Rom ConvertToLogiqx(Models.Internal.Rom item) { var rom = new Models.Logiqx.Rom { Name = item.ReadString(Models.Internal.Rom.NameKey), Size = item.ReadString(Models.Internal.Rom.SizeKey), CRC = item.ReadString(Models.Internal.Rom.CRCKey), MD5 = item.ReadString(Models.Internal.Rom.MD5Key), SHA1 = item.ReadString(Models.Internal.Rom.SHA1Key), SHA256 = item.ReadString(Models.Internal.Rom.SHA256Key), SHA384 = item.ReadString(Models.Internal.Rom.SHA384Key), SHA512 = item.ReadString(Models.Internal.Rom.SHA512Key), SpamSum = item.ReadString(Models.Internal.Rom.SpamSumKey), xxHash364 = item.ReadString(Models.Internal.Rom.xxHash364Key), xxHash3128 = item.ReadString(Models.Internal.Rom.xxHash3128Key), Merge = item.ReadString(Models.Internal.Rom.MergeKey), Status = item.ReadString(Models.Internal.Rom.StatusKey), Serial = item.ReadString(Models.Internal.Rom.SerialKey), Header = item.ReadString(Models.Internal.Rom.HeaderKey), Date = item.ReadString(Models.Internal.Rom.DateKey), Inverted = item.ReadString(Models.Internal.Rom.InvertedKey), MIA = item.ReadString(Models.Internal.Rom.MIAKey), }; return rom; } /// /// Convert from to /// public static Models.Logiqx.Sample ConvertToLogiqx(Models.Internal.Sample item) { var sample = new Models.Logiqx.Sample { Name = item.ReadString(Models.Internal.Sample.NameKey), }; return sample; } /// /// Convert from to /// public static Models.Logiqx.SoftwareList ConvertToLogiqx(Models.Internal.SoftwareList item) { var softwareList = new Models.Logiqx.SoftwareList { Tag = item.ReadString(Models.Internal.SoftwareList.TagKey), Name = item.ReadString(Models.Internal.SoftwareList.NameKey), Status = item.ReadString(Models.Internal.SoftwareList.StatusKey), Filter = item.ReadString(Models.Internal.SoftwareList.FilterKey), }; return softwareList; } #endregion } }