From e610b8168c4b3c8bbd7bea137cb8004947cb1351 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 4 Aug 2023 22:16:00 -0400 Subject: [PATCH] Split internal serializers in different way --- .../Internal.ArchiveDotOrg.cs | 163 ++ .../Internal.AttractMode.cs | 44 + .../Internal.ClrMamePro.cs | 438 +++++ .../Internal.Deserializer.cs | 1640 ----------------- .../Internal.DosCenter.cs | 46 + .../Internal.EverdriveSMDB.cs | 50 + SabreTools.Serialization/Internal.Hashfile.cs | 198 ++ SabreTools.Serialization/Internal.Listrom.cs | 97 + SabreTools.Serialization/Internal.Listxml.cs | 1151 ++++++++++++ SabreTools.Serialization/Internal.Logiqx.cs | 340 ++++ .../Internal.OfflineList.cs | 42 + SabreTools.Serialization/Internal.OpenMSX.cs | 156 ++ .../Internal.RomCenter.cs | 46 + .../Internal.SeparatedValue.cs | 110 ++ .../Internal.Serializer.cs | 1597 ---------------- .../Internal.SoftwareList.cs | 453 +++++ 16 files changed, 3334 insertions(+), 3237 deletions(-) create mode 100644 SabreTools.Serialization/Internal.ArchiveDotOrg.cs create mode 100644 SabreTools.Serialization/Internal.AttractMode.cs create mode 100644 SabreTools.Serialization/Internal.ClrMamePro.cs delete mode 100644 SabreTools.Serialization/Internal.Deserializer.cs create mode 100644 SabreTools.Serialization/Internal.DosCenter.cs create mode 100644 SabreTools.Serialization/Internal.EverdriveSMDB.cs create mode 100644 SabreTools.Serialization/Internal.Hashfile.cs create mode 100644 SabreTools.Serialization/Internal.Listrom.cs create mode 100644 SabreTools.Serialization/Internal.Listxml.cs create mode 100644 SabreTools.Serialization/Internal.Logiqx.cs create mode 100644 SabreTools.Serialization/Internal.OfflineList.cs create mode 100644 SabreTools.Serialization/Internal.OpenMSX.cs create mode 100644 SabreTools.Serialization/Internal.RomCenter.cs create mode 100644 SabreTools.Serialization/Internal.SeparatedValue.cs delete mode 100644 SabreTools.Serialization/Internal.Serializer.cs create mode 100644 SabreTools.Serialization/Internal.SoftwareList.cs diff --git a/SabreTools.Serialization/Internal.ArchiveDotOrg.cs b/SabreTools.Serialization/Internal.ArchiveDotOrg.cs new file mode 100644 index 00000000..0d50cb6e --- /dev/null +++ b/SabreTools.Serialization/Internal.ArchiveDotOrg.cs @@ -0,0 +1,163 @@ +namespace SabreTools.Serialization +{ + /// + /// Serializer for ArchiveDotOrg models to internal structure + /// + public partial class Internal + { + #region Serialize + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromArchiveDotOrg(Models.ArchiveDotOrg.File item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.NameKey] = item.Name, + [Models.Internal.Rom.SourceKey] = item.Source, + [Models.Internal.Rom.BitTorrentMagnetHashKey] = item.BitTorrentMagnetHash, + [Models.Internal.Rom.LastModifiedTimeKey] = item.LastModifiedTime, + [Models.Internal.Rom.SizeKey] = item.Size, + [Models.Internal.Rom.MD5Key] = item.MD5, + [Models.Internal.Rom.CRCKey] = item.CRC32, + [Models.Internal.Rom.SHA1Key] = item.SHA1, + [Models.Internal.Rom.FileCountKey] = item.FileCount, + [Models.Internal.Rom.FormatKey] = item.Format, + [Models.Internal.Rom.OriginalKey] = item.Original, + [Models.Internal.Rom.SummationKey] = item.Summation, + [Models.Internal.Rom.MatrixNumberKey] = item.MatrixNumber, + [Models.Internal.Rom.CollectionCatalogNumberKey] = item.CollectionCatalogNumber, + [Models.Internal.Rom.PublisherKey] = item.Publisher, + [Models.Internal.Rom.CommentKey] = item.Comment, + + [Models.Internal.Rom.ASRDetectedLangKey] = item.ASRDetectedLang, + [Models.Internal.Rom.ASRDetectedLangConfKey] = item.ASRDetectedLangConf, + [Models.Internal.Rom.ASRTranscribedLangKey] = item.ASRTranscribedLang, + [Models.Internal.Rom.WhisperASRModuleVersionKey] = item.WhisperASRModuleVersion, + [Models.Internal.Rom.WhisperModelHashKey] = item.WhisperModelHash, + [Models.Internal.Rom.WhisperModelNameKey] = item.WhisperModelName, + [Models.Internal.Rom.WhisperVersionKey] = item.WhisperVersion, + + [Models.Internal.Rom.ClothCoverDetectionModuleVersionKey] = item.ClothCoverDetectionModuleVersion, + [Models.Internal.Rom.hOCRCharToWordhOCRVersionKey] = item.hOCRCharToWordhOCRVersion, + [Models.Internal.Rom.hOCRCharToWordModuleVersionKey] = item.hOCRCharToWordModuleVersion, + [Models.Internal.Rom.hOCRFtsTexthOCRVersionKey] = item.hOCRFtsTexthOCRVersion, + [Models.Internal.Rom.hOCRFtsTextModuleVersionKey] = item.hOCRFtsTextModuleVersion, + [Models.Internal.Rom.hOCRPageIndexhOCRVersionKey] = item.hOCRPageIndexhOCRVersion, + [Models.Internal.Rom.hOCRPageIndexModuleVersionKey] = item.hOCRPageIndexModuleVersion, + [Models.Internal.Rom.TesseractOCRKey] = item.TesseractOCR, + [Models.Internal.Rom.TesseractOCRConvertedKey] = item.TesseractOCRConverted, + [Models.Internal.Rom.TesseractOCRDetectedLangKey] = item.TesseractOCRDetectedLang, + [Models.Internal.Rom.TesseractOCRDetectedLangConfKey] = item.TesseractOCRDetectedLangConf, + [Models.Internal.Rom.TesseractOCRDetectedScriptKey] = item.TesseractOCRDetectedScript, + [Models.Internal.Rom.TesseractOCRDetectedScriptConfKey] = item.TesseractOCRDetectedScriptConf, + [Models.Internal.Rom.TesseractOCRModuleVersionKey] = item.TesseractOCRModuleVersion, + [Models.Internal.Rom.TesseractOCRParametersKey] = item.TesseractOCRParameters, + [Models.Internal.Rom.PDFModuleVersionKey] = item.PDFModuleVersion, + [Models.Internal.Rom.WordConfidenceInterval0To10Key] = item.WordConfidenceInterval0To10, + [Models.Internal.Rom.WordConfidenceInterval11To20Key] = item.WordConfidenceInterval11To20, + [Models.Internal.Rom.WordConfidenceInterval21To30Key] = item.WordConfidenceInterval21To30, + [Models.Internal.Rom.WordConfidenceInterval31To40Key] = item.WordConfidenceInterval31To40, + [Models.Internal.Rom.WordConfidenceInterval41To50Key] = item.WordConfidenceInterval41To50, + [Models.Internal.Rom.WordConfidenceInterval51To60Key] = item.WordConfidenceInterval51To60, + [Models.Internal.Rom.WordConfidenceInterval61To70Key] = item.WordConfidenceInterval61To70, + [Models.Internal.Rom.WordConfidenceInterval71To80Key] = item.WordConfidenceInterval71To80, + [Models.Internal.Rom.WordConfidenceInterval81To90Key] = item.WordConfidenceInterval81To90, + [Models.Internal.Rom.WordConfidenceInterval91To100Key] = item.WordConfidenceInterval91To100, + + [Models.Internal.Rom.AlbumKey] = item.Album, + [Models.Internal.Rom.ArtistKey] = item.Artist, + [Models.Internal.Rom.BitrateKey] = item.Bitrate, + [Models.Internal.Rom.CreatorKey] = item.Creator, + [Models.Internal.Rom.HeightKey] = item.Height, + [Models.Internal.Rom.LengthKey] = item.Length, + [Models.Internal.Rom.PreviewImageKey] = item.PreviewImage, + [Models.Internal.Rom.RotationKey] = item.Rotation, + [Models.Internal.Rom.TitleKey] = item.Title, + [Models.Internal.Rom.TrackKey] = item.Track, + [Models.Internal.Rom.WidthKey] = item.Width, + }; + return rom; + } + + #endregion + + #region Deserialize + + /// + /// Convert from to + /// + public static Models.ArchiveDotOrg.File ConvertToArchiveDotOrg(Models.Internal.Rom item) + { + var file = new Models.ArchiveDotOrg.File + { + Name = item.ReadString(Models.Internal.Rom.NameKey), + Source = item.ReadString(Models.Internal.Rom.SourceKey), + BitTorrentMagnetHash = item.ReadString(Models.Internal.Rom.BitTorrentMagnetHashKey), + LastModifiedTime = item.ReadString(Models.Internal.Rom.LastModifiedTimeKey), + Size = item.ReadString(Models.Internal.Rom.SizeKey), + MD5 = item.ReadString(Models.Internal.Rom.MD5Key), + CRC32 = item.ReadString(Models.Internal.Rom.CRCKey), + SHA1 = item.ReadString(Models.Internal.Rom.SHA1Key), + FileCount = item.ReadString(Models.Internal.Rom.FileCountKey), + Format = item.ReadString(Models.Internal.Rom.FormatKey), + Original = item.ReadString(Models.Internal.Rom.OriginalKey), + Summation = item.ReadString(Models.Internal.Rom.SummationKey), + MatrixNumber = item.ReadString(Models.Internal.Rom.MatrixNumberKey), + CollectionCatalogNumber = item.ReadString(Models.Internal.Rom.CollectionCatalogNumberKey), + Comment = item.ReadString(Models.Internal.Rom.CommentKey), + + ASRDetectedLang = item.ReadString(Models.Internal.Rom.ASRDetectedLangKey), + ASRDetectedLangConf = item.ReadString(Models.Internal.Rom.ASRDetectedLangConfKey), + ASRTranscribedLang = item.ReadString(Models.Internal.Rom.ASRTranscribedLangKey), + WhisperASRModuleVersion = item.ReadString(Models.Internal.Rom.WhisperASRModuleVersionKey), + WhisperModelHash = item.ReadString(Models.Internal.Rom.WhisperModelHashKey), + WhisperModelName = item.ReadString(Models.Internal.Rom.WhisperModelNameKey), + WhisperVersion = item.ReadString(Models.Internal.Rom.WhisperVersionKey), + + ClothCoverDetectionModuleVersion = item.ReadString(Models.Internal.Rom.ClothCoverDetectionModuleVersionKey), + hOCRCharToWordhOCRVersion = item.ReadString(Models.Internal.Rom.hOCRCharToWordhOCRVersionKey), + hOCRCharToWordModuleVersion = item.ReadString(Models.Internal.Rom.hOCRCharToWordModuleVersionKey), + hOCRFtsTexthOCRVersion = item.ReadString(Models.Internal.Rom.hOCRFtsTexthOCRVersionKey), + hOCRFtsTextModuleVersion = item.ReadString(Models.Internal.Rom.hOCRFtsTextModuleVersionKey), + hOCRPageIndexhOCRVersion = item.ReadString(Models.Internal.Rom.hOCRPageIndexhOCRVersionKey), + hOCRPageIndexModuleVersion = item.ReadString(Models.Internal.Rom.hOCRPageIndexModuleVersionKey), + TesseractOCR = item.ReadString(key: Models.Internal.Rom.TesseractOCRKey), + TesseractOCRConverted = item.ReadString(Models.Internal.Rom.TesseractOCRConvertedKey), + TesseractOCRDetectedLang = item.ReadString(Models.Internal.Rom.TesseractOCRDetectedLangKey), + TesseractOCRDetectedLangConf = item.ReadString(Models.Internal.Rom.TesseractOCRDetectedLangConfKey), + TesseractOCRDetectedScript = item.ReadString(Models.Internal.Rom.TesseractOCRDetectedScriptKey), + TesseractOCRDetectedScriptConf = item.ReadString(Models.Internal.Rom.TesseractOCRDetectedScriptConfKey), + TesseractOCRModuleVersion = item.ReadString(Models.Internal.Rom.TesseractOCRModuleVersionKey), + TesseractOCRParameters = item.ReadString(Models.Internal.Rom.TesseractOCRParametersKey), + PDFModuleVersion = item.ReadString(Models.Internal.Rom.PDFModuleVersionKey), + WordConfidenceInterval0To10 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval0To10Key), + WordConfidenceInterval11To20 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval11To20Key), + WordConfidenceInterval21To30 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval21To30Key), + WordConfidenceInterval31To40 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval31To40Key), + WordConfidenceInterval41To50 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval41To50Key), + WordConfidenceInterval51To60 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval51To60Key), + WordConfidenceInterval61To70 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval61To70Key), + WordConfidenceInterval71To80 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval71To80Key), + WordConfidenceInterval81To90 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval81To90Key), + WordConfidenceInterval91To100 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval91To100Key), + + Album = item.ReadString(Models.Internal.Rom.AlbumKey), + Artist = item.ReadString(Models.Internal.Rom.ArtistKey), + Bitrate = item.ReadString(Models.Internal.Rom.BitrateKey), + Creator = item.ReadString(Models.Internal.Rom.CreatorKey), + Height = item.ReadString(Models.Internal.Rom.HeightKey), + Length = item.ReadString(Models.Internal.Rom.LengthKey), + PreviewImage = item.ReadString(Models.Internal.Rom.PreviewImageKey), + Rotation = item.ReadString(Models.Internal.Rom.RotationKey), + Title = item.ReadString(Models.Internal.Rom.TitleKey), + Track = item.ReadString(Models.Internal.Rom.TrackKey), + Width = item.ReadString(Models.Internal.Rom.WidthKey), + }; + return file; + } + + #endregion + } +} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.AttractMode.cs b/SabreTools.Serialization/Internal.AttractMode.cs new file mode 100644 index 00000000..0b72475b --- /dev/null +++ b/SabreTools.Serialization/Internal.AttractMode.cs @@ -0,0 +1,44 @@ +namespace SabreTools.Serialization +{ + /// + /// Serializer for AttractMode models to internal structure + /// + public partial class Internal + { + #region Serialize + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromAttractMode(Models.AttractMode.Row item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.NameKey] = item.Title, + [Models.Internal.Rom.AltRomnameKey] = item.AltRomname, + [Models.Internal.Rom.AltTitleKey] = item.AltTitle, + }; + return rom; + } + + #endregion + + #region Deserialize + + /// + /// Convert from to + /// + public static Models.AttractMode.Row ConvertToAttractMode(Models.Internal.Rom item) + { + var row = new Models.AttractMode.Row + { + Title = item.ReadString(Models.Internal.Rom.NameKey), + AltRomname = item.ReadString(Models.Internal.Rom.AltRomnameKey), + AltTitle = item.ReadString(Models.Internal.Rom.AltTitleKey), + }; + return row; + } + + #endregion + } +} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.ClrMamePro.cs b/SabreTools.Serialization/Internal.ClrMamePro.cs new file mode 100644 index 00000000..6314374e --- /dev/null +++ b/SabreTools.Serialization/Internal.ClrMamePro.cs @@ -0,0 +1,438 @@ +namespace SabreTools.Serialization +{ + /// + /// Serializer for ClrMamePro models to internal structure + /// + public partial class Internal + { + #region Serialize + + /// + /// Convert from to + /// + public static Models.Internal.Archive ConvertFromClrMamePro(Models.ClrMamePro.Archive item) + { + var archive = new Models.Internal.Archive + { + [Models.Internal.Archive.NameKey] = item.Name, + }; + return archive; + } + + /// + /// Convert from to + /// + public static Models.Internal.BiosSet ConvertFromClrMamePro(Models.ClrMamePro.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.Chip ConvertFromClrMamePro(Models.ClrMamePro.Chip item) + { + var chip = new Models.Internal.Chip + { + [Models.Internal.Chip.ChipTypeKey] = item.Type, + [Models.Internal.Chip.NameKey] = item.Name, + [Models.Internal.Chip.FlagsKey] = item.Flags, + [Models.Internal.Chip.ClockKey] = item.Clock, + }; + return chip; + } + + /// + /// Convert from to + /// + public static Models.Internal.DipSwitch ConvertFromClrMamePro(Models.ClrMamePro.DipSwitch item) + { + var dipswitch = new Models.Internal.DipSwitch + { + [Models.Internal.DipSwitch.NameKey] = item.Name, + [Models.Internal.DipSwitch.EntryKey] = item.Entry, + [Models.Internal.DipSwitch.DefaultKey] = item.Default, + }; + return dipswitch; + } + + /// + /// Convert from to + /// + public static Models.Internal.Disk ConvertFromClrMamePro(Models.ClrMamePro.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.FlagsKey] = item.Flags, + }; + return disk; + } + + /// + /// Convert from to + /// + public static Models.Internal.Driver ConvertFromClrMamePro(Models.ClrMamePro.Driver item) + { + var driver = new Models.Internal.Driver + { + [Models.Internal.Driver.StatusKey] = item.Status, + [Models.Internal.Driver.ColorKey] = item.Color, + [Models.Internal.Driver.SoundKey] = item.Sound, + [Models.Internal.Driver.PaletteSizeKey] = item.PaletteSize, + [Models.Internal.Driver.BlitKey] = item.Blit, + }; + return driver; + } + + /// + /// Convert from to + /// + public static Models.Internal.Input ConvertFromClrMamePro(Models.ClrMamePro.Input item) + { + var input = new Models.Internal.Input + { + [Models.Internal.Input.PlayersKey] = item.Players, + [Models.Internal.Input.ControlKey] = item.Control, + [Models.Internal.Input.ButtonsKey] = item.Buttons, + [Models.Internal.Input.CoinsKey] = item.Coins, + [Models.Internal.Input.TiltKey] = item.Tilt, + [Models.Internal.Input.ServiceKey] = item.Service, + }; + return input; + } + + /// + /// Convert from to + /// + public static Models.Internal.Media ConvertFromClrMamePro(Models.ClrMamePro.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 ConvertFromClrMamePro(Models.ClrMamePro.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 ConvertFromClrMamePro(Models.ClrMamePro.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.RegionKey] = item.Region, + [Models.Internal.Rom.FlagsKey] = item.Flags, + [Models.Internal.Rom.OffsetKey] = item.Offs, + [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 ConvertFromClrMamePro(Models.ClrMamePro.Sample item) + { + var sample = new Models.Internal.Sample + { + [Models.Internal.Sample.NameKey] = item.Name, + }; + return sample; + } + + /// + /// Convert from to + /// + public static Models.Internal.Sound ConvertFromClrMamePro(Models.ClrMamePro.Sound item) + { + var sound = new Models.Internal.Sound + { + [Models.Internal.Sound.ChannelsKey] = item.Channels, + }; + return sound; + } + + /// + /// Convert from to + /// + public static Models.Internal.Video ConvertFromClrMamePro(Models.ClrMamePro.Video item) + { + var video = new Models.Internal.Video + { + [Models.Internal.Video.ScreenKey] = item.Screen, + [Models.Internal.Video.OrientationKey] = item.Orientation, + [Models.Internal.Video.WidthKey] = item.X, + [Models.Internal.Video.HeightKey] = item.Y, + [Models.Internal.Video.AspectXKey] = item.AspectX, + [Models.Internal.Video.AspectYKey] = item.AspectY, + [Models.Internal.Video.RefreshKey] = item.Freq, + }; + return video; + } + + #endregion + + #region Deserialize + + /// + /// Convert from to + /// + public static Models.ClrMamePro.Archive ConvertToClrMamePro(Models.Internal.Archive item) + { + var archive = new Models.ClrMamePro.Archive + { + Name = item.ReadString(Models.Internal.Archive.NameKey), + }; + return archive; + } + + /// + /// Convert from to + /// + public static Models.ClrMamePro.BiosSet ConvertToClrMamePro(Models.Internal.BiosSet item) + { + var biosset = new Models.ClrMamePro.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.ClrMamePro.Chip ConvertToClrMamePro(Models.Internal.Chip item) + { + var chip = new Models.ClrMamePro.Chip + { + Type = item.ReadString(Models.Internal.Chip.ChipTypeKey), + Name = item.ReadString(Models.Internal.Chip.NameKey), + Flags = item.ReadString(Models.Internal.Chip.FlagsKey), + Clock = item.ReadString(Models.Internal.Chip.ClockKey), + }; + return chip; + } + + /// + /// Convert from to + /// + public static Models.ClrMamePro.DipSwitch ConvertToClrMamePro(Models.Internal.DipSwitch item) + { + var dipswitch = new Models.ClrMamePro.DipSwitch + { + Name = item.ReadString(Models.Internal.DipSwitch.NameKey), + Entry = item[Models.Internal.DipSwitch.EntryKey] as string[], + Default = item.ReadString(Models.Internal.DipSwitch.DefaultKey), + }; + return dipswitch; + } + + /// + /// Convert from to + /// + public static Models.ClrMamePro.Disk ConvertToClrMamePro(Models.Internal.Disk item) + { + var disk = new Models.ClrMamePro.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), + Flags = item.ReadString(Models.Internal.Disk.FlagsKey), + }; + return disk; + } + + /// + /// Convert from to + /// + public static Models.ClrMamePro.Driver ConvertToClrMamePro(Models.Internal.Driver item) + { + var driver = new Models.ClrMamePro.Driver + { + Status = item.ReadString(Models.Internal.Driver.StatusKey), + Color = item.ReadString(Models.Internal.Driver.ColorKey), + Sound = item.ReadString(Models.Internal.Driver.SoundKey), + PaletteSize = item.ReadString(Models.Internal.Driver.PaletteSizeKey), + Blit = item.ReadString(Models.Internal.Driver.BlitKey), + }; + return driver; + } + + /// + /// Convert from to + /// + public static Models.ClrMamePro.Input ConvertToClrMamePro(Models.Internal.Input item) + { + var input = new Models.ClrMamePro.Input + { + Players = item.ReadString(Models.Internal.Input.PlayersKey), + Control = item.ReadString(Models.Internal.Input.ControlKey), + Buttons = item.ReadString(Models.Internal.Input.ButtonsKey), + Coins = item.ReadString(Models.Internal.Input.CoinsKey), + Tilt = item.ReadString(Models.Internal.Input.TiltKey), + Service = item.ReadString(Models.Internal.Input.ServiceKey), + }; + return input; + } + + /// + /// Convert from to + /// + public static Models.ClrMamePro.Media ConvertToClrMamePro(Models.Internal.Media item) + { + var media = new Models.ClrMamePro.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.ClrMamePro.Release ConvertToClrMamePro(Models.Internal.Release item) + { + var release = new Models.ClrMamePro.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.ClrMamePro.Rom ConvertToClrMamePro(Models.Internal.Rom item) + { + var rom = new Models.ClrMamePro.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), + Region = item.ReadString(Models.Internal.Rom.RegionKey), + Flags = item.ReadString(Models.Internal.Rom.FlagsKey), + Offs = item.ReadString(Models.Internal.Rom.OffsetKey), + 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.ClrMamePro.Sample ConvertToClrMamePro(Models.Internal.Sample item) + { + var sample = new Models.ClrMamePro.Sample + { + Name = item.ReadString(Models.Internal.Sample.NameKey), + }; + return sample; + } + + /// + /// Convert from to + /// + public static Models.ClrMamePro.Sound ConvertToClrMamePro(Models.Internal.Sound item) + { + var sound = new Models.ClrMamePro.Sound + { + Channels = item.ReadString(Models.Internal.Sound.ChannelsKey), + }; + return sound; + } + + /// + /// Convert from to + /// + public static Models.ClrMamePro.Video ConvertToClrMamePro(Models.Internal.Video item) + { + var video = new Models.ClrMamePro.Video + { + Screen = item.ReadString(Models.Internal.Video.ScreenKey), + Orientation = item.ReadString(Models.Internal.Video.OrientationKey), + X = item.ReadString(Models.Internal.Video.WidthKey), + Y = item.ReadString(Models.Internal.Video.HeightKey), + AspectX = item.ReadString(Models.Internal.Video.AspectXKey), + AspectY = item.ReadString(Models.Internal.Video.AspectYKey), + Freq = item.ReadString(Models.Internal.Video.RefreshKey), + }; + return video; + } + + #endregion + } +} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.Deserializer.cs b/SabreTools.Serialization/Internal.Deserializer.cs deleted file mode 100644 index f6bf9dd2..00000000 --- a/SabreTools.Serialization/Internal.Deserializer.cs +++ /dev/null @@ -1,1640 +0,0 @@ -using System.Collections.Generic; - -namespace SabreTools.Serialization -{ - /// - /// Deserializer for all relevant models from internal structure - /// - public partial class Internal - { - #region ArchiveDotOrg - - /// - /// Convert from to - /// - public static Models.ArchiveDotOrg.File ConvertToArchiveDotOrg(Models.Internal.Rom item) - { - var file = new Models.ArchiveDotOrg.File - { - Name = item.ReadString(Models.Internal.Rom.NameKey), - Source = item.ReadString(Models.Internal.Rom.SourceKey), - BitTorrentMagnetHash = item.ReadString(Models.Internal.Rom.BitTorrentMagnetHashKey), - LastModifiedTime = item.ReadString(Models.Internal.Rom.LastModifiedTimeKey), - Size = item.ReadString(Models.Internal.Rom.SizeKey), - MD5 = item.ReadString(Models.Internal.Rom.MD5Key), - CRC32 = item.ReadString(Models.Internal.Rom.CRCKey), - SHA1 = item.ReadString(Models.Internal.Rom.SHA1Key), - FileCount = item.ReadString(Models.Internal.Rom.FileCountKey), - Format = item.ReadString(Models.Internal.Rom.FormatKey), - Original = item.ReadString(Models.Internal.Rom.OriginalKey), - Summation = item.ReadString(Models.Internal.Rom.SummationKey), - MatrixNumber = item.ReadString(Models.Internal.Rom.MatrixNumberKey), - CollectionCatalogNumber = item.ReadString(Models.Internal.Rom.CollectionCatalogNumberKey), - Comment = item.ReadString(Models.Internal.Rom.CommentKey), - - ASRDetectedLang = item.ReadString(Models.Internal.Rom.ASRDetectedLangKey), - ASRDetectedLangConf = item.ReadString(Models.Internal.Rom.ASRDetectedLangConfKey), - ASRTranscribedLang = item.ReadString(Models.Internal.Rom.ASRTranscribedLangKey), - WhisperASRModuleVersion = item.ReadString(Models.Internal.Rom.WhisperASRModuleVersionKey), - WhisperModelHash = item.ReadString(Models.Internal.Rom.WhisperModelHashKey), - WhisperModelName = item.ReadString(Models.Internal.Rom.WhisperModelNameKey), - WhisperVersion = item.ReadString(Models.Internal.Rom.WhisperVersionKey), - - ClothCoverDetectionModuleVersion = item.ReadString(Models.Internal.Rom.ClothCoverDetectionModuleVersionKey), - hOCRCharToWordhOCRVersion = item.ReadString(Models.Internal.Rom.hOCRCharToWordhOCRVersionKey), - hOCRCharToWordModuleVersion = item.ReadString(Models.Internal.Rom.hOCRCharToWordModuleVersionKey), - hOCRFtsTexthOCRVersion = item.ReadString(Models.Internal.Rom.hOCRFtsTexthOCRVersionKey), - hOCRFtsTextModuleVersion = item.ReadString(Models.Internal.Rom.hOCRFtsTextModuleVersionKey), - hOCRPageIndexhOCRVersion = item.ReadString(Models.Internal.Rom.hOCRPageIndexhOCRVersionKey), - hOCRPageIndexModuleVersion = item.ReadString(Models.Internal.Rom.hOCRPageIndexModuleVersionKey), - TesseractOCR = item.ReadString(key: Models.Internal.Rom.TesseractOCRKey), - TesseractOCRConverted = item.ReadString(Models.Internal.Rom.TesseractOCRConvertedKey), - TesseractOCRDetectedLang = item.ReadString(Models.Internal.Rom.TesseractOCRDetectedLangKey), - TesseractOCRDetectedLangConf = item.ReadString(Models.Internal.Rom.TesseractOCRDetectedLangConfKey), - TesseractOCRDetectedScript = item.ReadString(Models.Internal.Rom.TesseractOCRDetectedScriptKey), - TesseractOCRDetectedScriptConf = item.ReadString(Models.Internal.Rom.TesseractOCRDetectedScriptConfKey), - TesseractOCRModuleVersion = item.ReadString(Models.Internal.Rom.TesseractOCRModuleVersionKey), - TesseractOCRParameters = item.ReadString(Models.Internal.Rom.TesseractOCRParametersKey), - PDFModuleVersion = item.ReadString(Models.Internal.Rom.PDFModuleVersionKey), - WordConfidenceInterval0To10 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval0To10Key), - WordConfidenceInterval11To20 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval11To20Key), - WordConfidenceInterval21To30 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval21To30Key), - WordConfidenceInterval31To40 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval31To40Key), - WordConfidenceInterval41To50 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval41To50Key), - WordConfidenceInterval51To60 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval51To60Key), - WordConfidenceInterval61To70 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval61To70Key), - WordConfidenceInterval71To80 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval71To80Key), - WordConfidenceInterval81To90 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval81To90Key), - WordConfidenceInterval91To100 = item.ReadString(Models.Internal.Rom.WordConfidenceInterval91To100Key), - - Album = item.ReadString(Models.Internal.Rom.AlbumKey), - Artist = item.ReadString(Models.Internal.Rom.ArtistKey), - Bitrate = item.ReadString(Models.Internal.Rom.BitrateKey), - Creator = item.ReadString(Models.Internal.Rom.CreatorKey), - Height = item.ReadString(Models.Internal.Rom.HeightKey), - Length = item.ReadString(Models.Internal.Rom.LengthKey), - PreviewImage = item.ReadString(Models.Internal.Rom.PreviewImageKey), - Rotation = item.ReadString(Models.Internal.Rom.RotationKey), - Title = item.ReadString(Models.Internal.Rom.TitleKey), - Track = item.ReadString(Models.Internal.Rom.TrackKey), - Width = item.ReadString(Models.Internal.Rom.WidthKey), - }; - return file; - } - - #endregion - - #region AttractMode - - /// - /// Convert from to - /// - public static Models.AttractMode.Row ConvertToAttractMode(Models.Internal.Rom item) - { - var row = new Models.AttractMode.Row - { - Title = item.ReadString(Models.Internal.Rom.NameKey), - AltRomname = item.ReadString(Models.Internal.Rom.AltRomnameKey), - AltTitle = item.ReadString(Models.Internal.Rom.AltTitleKey), - }; - return row; - } - - #endregion - - #region ClrMamePro - - /// - /// Convert from to - /// - public static Models.ClrMamePro.Archive ConvertToClrMamePro(Models.Internal.Archive item) - { - var archive = new Models.ClrMamePro.Archive - { - Name = item.ReadString(Models.Internal.Archive.NameKey), - }; - return archive; - } - - /// - /// Convert from to - /// - public static Models.ClrMamePro.BiosSet ConvertToClrMamePro(Models.Internal.BiosSet item) - { - var biosset = new Models.ClrMamePro.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.ClrMamePro.Chip ConvertToClrMamePro(Models.Internal.Chip item) - { - var chip = new Models.ClrMamePro.Chip - { - Type = item.ReadString(Models.Internal.Chip.ChipTypeKey), - Name = item.ReadString(Models.Internal.Chip.NameKey), - Flags = item.ReadString(Models.Internal.Chip.FlagsKey), - Clock = item.ReadString(Models.Internal.Chip.ClockKey), - }; - return chip; - } - - /// - /// Convert from to - /// - public static Models.ClrMamePro.DipSwitch ConvertToClrMamePro(Models.Internal.DipSwitch item) - { - var dipswitch = new Models.ClrMamePro.DipSwitch - { - Name = item.ReadString(Models.Internal.DipSwitch.NameKey), - Entry = item[Models.Internal.DipSwitch.EntryKey] as string[], - Default = item.ReadString(Models.Internal.DipSwitch.DefaultKey), - }; - return dipswitch; - } - - /// - /// Convert from to - /// - public static Models.ClrMamePro.Disk ConvertToClrMamePro(Models.Internal.Disk item) - { - var disk = new Models.ClrMamePro.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), - Flags = item.ReadString(Models.Internal.Disk.FlagsKey), - }; - return disk; - } - - /// - /// Convert from to - /// - public static Models.ClrMamePro.Driver ConvertToClrMamePro(Models.Internal.Driver item) - { - var driver = new Models.ClrMamePro.Driver - { - Status = item.ReadString(Models.Internal.Driver.StatusKey), - Color = item.ReadString(Models.Internal.Driver.ColorKey), - Sound = item.ReadString(Models.Internal.Driver.SoundKey), - PaletteSize = item.ReadString(Models.Internal.Driver.PaletteSizeKey), - Blit = item.ReadString(Models.Internal.Driver.BlitKey), - }; - return driver; - } - - /// - /// Convert from to - /// - public static Models.ClrMamePro.Input ConvertToClrMamePro(Models.Internal.Input item) - { - var input = new Models.ClrMamePro.Input - { - Players = item.ReadString(Models.Internal.Input.PlayersKey), - Control = item.ReadString(Models.Internal.Input.ControlKey), - Buttons = item.ReadString(Models.Internal.Input.ButtonsKey), - Coins = item.ReadString(Models.Internal.Input.CoinsKey), - Tilt = item.ReadString(Models.Internal.Input.TiltKey), - Service = item.ReadString(Models.Internal.Input.ServiceKey), - }; - return input; - } - - /// - /// Convert from to - /// - public static Models.ClrMamePro.Media ConvertToClrMamePro(Models.Internal.Media item) - { - var media = new Models.ClrMamePro.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.ClrMamePro.Release ConvertToClrMamePro(Models.Internal.Release item) - { - var release = new Models.ClrMamePro.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.ClrMamePro.Rom ConvertToClrMamePro(Models.Internal.Rom item) - { - var rom = new Models.ClrMamePro.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), - Region = item.ReadString(Models.Internal.Rom.RegionKey), - Flags = item.ReadString(Models.Internal.Rom.FlagsKey), - Offs = item.ReadString(Models.Internal.Rom.OffsetKey), - 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.ClrMamePro.Sample ConvertToClrMamePro(Models.Internal.Sample item) - { - var sample = new Models.ClrMamePro.Sample - { - Name = item.ReadString(Models.Internal.Sample.NameKey), - }; - return sample; - } - - /// - /// Convert from to - /// - public static Models.ClrMamePro.Sound ConvertToClrMamePro(Models.Internal.Sound item) - { - var sound = new Models.ClrMamePro.Sound - { - Channels = item.ReadString(Models.Internal.Sound.ChannelsKey), - }; - return sound; - } - - /// - /// Convert from to - /// - public static Models.ClrMamePro.Video ConvertToClrMamePro(Models.Internal.Video item) - { - var video = new Models.ClrMamePro.Video - { - Screen = item.ReadString(Models.Internal.Video.ScreenKey), - Orientation = item.ReadString(Models.Internal.Video.OrientationKey), - X = item.ReadString(Models.Internal.Video.WidthKey), - Y = item.ReadString(Models.Internal.Video.HeightKey), - AspectX = item.ReadString(Models.Internal.Video.AspectXKey), - AspectY = item.ReadString(Models.Internal.Video.AspectYKey), - Freq = item.ReadString(Models.Internal.Video.RefreshKey), - }; - return video; - } - - #endregion - - #region DosCenter - - /// - /// Convert from to - /// - public static Models.DosCenter.File ConvertToDosCenter(Models.Internal.Rom item) - { - var file = new Models.DosCenter.File - { - Name = item.ReadString(Models.Internal.Rom.NameKey), - Size = item.ReadString(Models.Internal.Rom.SizeKey), - CRC = item.ReadString(Models.Internal.Rom.CRCKey), - Date = item.ReadString(Models.Internal.Rom.DateKey), - }; - return file; - } - - #endregion - - #region EverdriveSMDB - - /// - /// Convert from to - /// - public static Models.EverdriveSMDB.Row ConvertToEverdriveSMDB(Models.Internal.Rom item) - { - var row = new Models.EverdriveSMDB.Row - { - SHA256 = item.ReadString(Models.Internal.Rom.SHA256Key), - Name = item.ReadString(Models.Internal.Rom.NameKey), - SHA1 = item.ReadString(Models.Internal.Rom.SHA1Key), - MD5 = item.ReadString(Models.Internal.Rom.MD5Key), - CRC32 = item.ReadString(Models.Internal.Rom.CRCKey), - Size = item.ReadString(Models.Internal.Rom.SizeKey), - }; - return row; - } - - #endregion - - #region Hashfile - - /// - /// Convert from to - /// - public static Models.Hashfile.MD5 ConvertToMD5(Models.Internal.Rom item) - { - var md5 = new Models.Hashfile.MD5 - { - Hash = item.ReadString(Models.Internal.Rom.MD5Key), - File = item.ReadString(Models.Internal.Rom.NameKey), - }; - return md5; - } - - /// - /// Convert from to - /// - public static Models.Hashfile.SFV ConvertToSFV(Models.Internal.Rom item) - { - var sfv = new Models.Hashfile.SFV - { - File = item.ReadString(Models.Internal.Rom.NameKey), - Hash = item.ReadString(Models.Internal.Rom.CRCKey), - }; - return sfv; - } - - /// - /// Convert from to - /// - public static Models.Hashfile.SHA1 ConvertToSHA1(Models.Internal.Rom item) - { - var sha1 = new Models.Hashfile.SHA1 - { - Hash = item.ReadString(Models.Internal.Rom.SHA1Key), - File = item.ReadString(Models.Internal.Rom.NameKey), - }; - return sha1; - } - - /// - /// Convert from to - /// - public static Models.Hashfile.SHA256 ConvertToSHA256(Models.Internal.Rom item) - { - var sha256 = new Models.Hashfile.SHA256 - { - Hash = item.ReadString(Models.Internal.Rom.SHA256Key), - File = item.ReadString(Models.Internal.Rom.NameKey), - }; - return sha256; - } - - /// - /// Convert from to - /// - public static Models.Hashfile.SHA384 ConvertToSHA384(Models.Internal.Rom item) - { - var sha384 = new Models.Hashfile.SHA384 - { - Hash = item.ReadString(Models.Internal.Rom.SHA384Key), - File = item.ReadString(Models.Internal.Rom.NameKey), - }; - return sha384; - } - - /// - /// Convert from to - /// - public static Models.Hashfile.SHA512 ConvertToSHA512(Models.Internal.Rom item) - { - var sha512 = new Models.Hashfile.SHA512 - { - Hash = item.ReadString(Models.Internal.Rom.SHA512Key), - File = item.ReadString(Models.Internal.Rom.NameKey), - }; - return sha512; - } - - /// - /// Convert from to - /// - public static Models.Hashfile.SpamSum ConvertToSpamSum(Models.Internal.Rom item) - { - var spamsum = new Models.Hashfile.SpamSum - { - Hash = item.ReadString(Models.Internal.Rom.SpamSumKey), - File = item.ReadString(Models.Internal.Rom.NameKey), - }; - return spamsum; - } - - #endregion - - #region Listrom - - /// - /// Convert from to - /// - public static Models.Listrom.Row ConvertToListrom(Models.Internal.Disk item) - { - var row = new Models.Listrom.Row - { - Name = item.ReadString(Models.Internal.Disk.NameKey), - MD5 = item.ReadString(Models.Internal.Disk.MD5Key), - SHA1 = item.ReadString(Models.Internal.Disk.SHA1Key), - }; - - if (item[Models.Internal.Disk.StatusKey] as string == "nodump") - row.NoGoodDumpKnown = true; - else if (item[Models.Internal.Disk.StatusKey] as string == "baddump") - row.Bad = true; - - return row; - } - - /// - /// Convert from to - /// - public static Models.Listrom.Row ConvertToListrom(Models.Internal.Rom item) - { - var row = new Models.Listrom.Row - { - Name = item.ReadString(Models.Internal.Rom.NameKey), - Size = item.ReadString(Models.Internal.Rom.SizeKey), - CRC = item.ReadString(Models.Internal.Rom.CRCKey), - SHA1 = item.ReadString(Models.Internal.Rom.SHA1Key), - }; - - if (item[Models.Internal.Rom.StatusKey] as string == "nodump") - row.NoGoodDumpKnown = true; - else if (item[Models.Internal.Rom.StatusKey] as string == "baddump") - row.Bad = true; - - return row; - } - - #endregion - - #region Listxml - - /// - /// Convert from to - /// - public static Models.Listxml.Adjuster ConvertToListxml(Models.Internal.Adjuster item) - { - var adjuster = new Models.Listxml.Adjuster - { - Name = item.ReadString(Models.Internal.Adjuster.NameKey), - Default = item.ReadString(Models.Internal.Adjuster.DefaultKey), - }; - - if (item.ContainsKey(Models.Internal.Adjuster.ConditionKey) && item[Models.Internal.Adjuster.ConditionKey] is Models.Internal.Condition condition) - adjuster.Condition = ConvertToListxml(condition); - - return adjuster; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Analog ConvertToListxml(Models.Internal.Analog item) - { - var analog = new Models.Listxml.Analog - { - Mask = item.ReadString(Models.Internal.Analog.MaskKey), - }; - return analog; - } - - /// - /// Convert from to - /// - public static Models.Listxml.BiosSet ConvertToListxml(Models.Internal.BiosSet item) - { - var biosset = new Models.Listxml.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.Listxml.Chip ConvertToListxml(Models.Internal.Chip item) - { - var chip = new Models.Listxml.Chip - { - Name = item.ReadString(Models.Internal.Chip.NameKey), - Tag = item.ReadString(Models.Internal.Chip.TagKey), - Type = item.ReadString(Models.Internal.Chip.TypeKey), - SoundOnly = item.ReadString(Models.Internal.Chip.SoundOnlyKey), - Clock = item.ReadString(Models.Internal.Chip.ClockKey), - }; - return chip; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Condition ConvertToListxml(Models.Internal.Condition item) - { - var condition = new Models.Listxml.Condition - { - Tag = item.ReadString(Models.Internal.Condition.TagKey), - Mask = item.ReadString(Models.Internal.Condition.MaskKey), - Relation = item.ReadString(Models.Internal.Condition.RelationKey), - Value = item.ReadString(Models.Internal.Condition.ValueKey), - }; - return condition; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Configuration ConvertToListxml(Models.Internal.Configuration item) - { - var configuration = new Models.Listxml.Configuration - { - Name = item.ReadString(Models.Internal.Configuration.NameKey), - Tag = item.ReadString(Models.Internal.Configuration.TagKey), - Mask = item.ReadString(Models.Internal.Configuration.MaskKey), - }; - - if (item.ContainsKey(Models.Internal.Configuration.ConditionKey) && item[Models.Internal.Configuration.ConditionKey] is Models.Internal.Condition condition) - configuration.Condition = ConvertToListxml(condition); - - if (item.ContainsKey(Models.Internal.Configuration.ConfLocationKey) && item[Models.Internal.Configuration.ConfLocationKey] is Models.Internal.ConfLocation[] confLocations) - { - var confLocationItems = new List(); - foreach (var confLocation in confLocations) - { - confLocationItems.Add(ConvertToListxml(confLocation)); - } - configuration.ConfLocation = confLocationItems.ToArray(); - } - - if (item.ContainsKey(Models.Internal.Configuration.ConfSettingKey) && item[Models.Internal.Configuration.ConfSettingKey] is Models.Internal.ConfSetting[] confSettings) - { - var confSettingItems = new List(); - foreach (var confSetting in confSettings) - { - confSettingItems.Add(ConvertToListxml(confSetting)); - } - configuration.ConfSetting = confSettingItems.ToArray(); - } - - return configuration; - } - - /// - /// Convert from to - /// - public static Models.Listxml.ConfLocation ConvertToListxml(Models.Internal.ConfLocation item) - { - var confLocation = new Models.Listxml.ConfLocation - { - Name = item.ReadString(Models.Internal.ConfLocation.NameKey), - Number = item.ReadString(Models.Internal.ConfLocation.NumberKey), - Inverted = item.ReadString(Models.Internal.ConfLocation.InvertedKey), - }; - return confLocation; - } - - /// - /// Convert from to - /// - public static Models.Listxml.ConfSetting ConvertToListxml(Models.Internal.ConfSetting item) - { - var confSetting = new Models.Listxml.ConfSetting - { - Name = item.ReadString(Models.Internal.ConfSetting.NameKey), - Value = item.ReadString(Models.Internal.ConfSetting.ValueKey), - Default = item.ReadString(Models.Internal.ConfSetting.DefaultKey), - }; - - if (item.ContainsKey(Models.Internal.ConfSetting.ConditionKey) && item[Models.Internal.ConfSetting.ConditionKey] is Models.Internal.Condition condition) - confSetting.Condition = ConvertToListxml(condition); - - return confSetting; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Control ConvertToListxml(Models.Internal.Control item) - { - var control = new Models.Listxml.Control - { - Type = item.ReadString(Models.Internal.Control.TypeKey), - Player = item.ReadString(Models.Internal.Control.PlayerKey), - Buttons = item.ReadString(Models.Internal.Control.ButtonsKey), - ReqButtons = item.ReadString(Models.Internal.Control.ReqButtonsKey), - Minimum = item.ReadString(Models.Internal.Control.MinimumKey), - Maximum = item.ReadString(Models.Internal.Control.MaximumKey), - Sensitivity = item.ReadString(Models.Internal.Control.SensitivityKey), - KeyDelta = item.ReadString(Models.Internal.Control.KeyDeltaKey), - Reverse = item.ReadString(Models.Internal.Control.ReverseKey), - Ways = item.ReadString(Models.Internal.Control.WaysKey), - Ways2 = item.ReadString(Models.Internal.Control.Ways2Key), - Ways3 = item.ReadString(Models.Internal.Control.Ways3Key), - }; - return control; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Device ConvertToListxml(Models.Internal.Device item) - { - var device = new Models.Listxml.Device - { - Type = item.ReadString(Models.Internal.Device.TypeKey), - Tag = item.ReadString(Models.Internal.Device.TagKey), - FixedImage = item.ReadString(Models.Internal.Device.FixedImageKey), - Mandatory = item.ReadString(Models.Internal.Device.MandatoryKey), - Interface = item.ReadString(Models.Internal.Device.InterfaceKey), - }; - - if (item.ContainsKey(Models.Internal.Device.InstanceKey) && item[Models.Internal.Device.InstanceKey] is Models.Internal.Instance instance) - device.Instance = ConvertToListxml(instance); - - if (item.ContainsKey(Models.Internal.Device.ExtensionKey) && item[Models.Internal.Device.ExtensionKey] is Models.Internal.Extension[] extensions) - { - var extensionItems = new List(); - foreach (var extension in extensions) - { - extensionItems.Add(ConvertToListxml(extension)); - } - device.Extension = extensionItems.ToArray(); - } - - return device; - } - - /// - /// Convert from to - /// - public static Models.Listxml.DeviceRef ConvertToListxml(Models.Internal.DeviceRef item) - { - var deviceRef = new Models.Listxml.DeviceRef - { - Name = item.ReadString(Models.Internal.DeviceRef.NameKey), - }; - return deviceRef; - } - - /// - /// Convert from to - /// - public static Models.Listxml.DipLocation ConvertToListxml(Models.Internal.DipLocation item) - { - var dipLocation = new Models.Listxml.DipLocation - { - Name = item.ReadString(Models.Internal.DipLocation.NameKey), - Number = item.ReadString(Models.Internal.DipLocation.NumberKey), - Inverted = item.ReadString(Models.Internal.DipLocation.InvertedKey), - }; - return dipLocation; - } - - /// - /// Convert from to - /// - public static Models.Listxml.DipSwitch ConvertToListxml(Models.Internal.DipSwitch item) - { - var dipSwitch = new Models.Listxml.DipSwitch - { - Name = item.ReadString(Models.Internal.DipSwitch.NameKey), - Tag = item.ReadString(Models.Internal.DipSwitch.TagKey), - Mask = item.ReadString(Models.Internal.DipSwitch.MaskKey), - }; - - if (item.ContainsKey(Models.Internal.DipSwitch.ConditionKey) && item[Models.Internal.DipSwitch.ConditionKey] is Models.Internal.Condition condition) - dipSwitch.Condition = ConvertToListxml(condition); - - if (item.ContainsKey(Models.Internal.DipSwitch.DipLocationKey) && item[Models.Internal.DipSwitch.DipLocationKey] is Models.Internal.DipLocation[] dipLocations) - { - var dipLocationItems = new List(); - foreach (var dipLocation in dipLocations) - { - dipLocationItems.Add(ConvertToListxml(dipLocation)); - } - dipSwitch.DipLocation = dipLocationItems.ToArray(); - } - - if (item.ContainsKey(Models.Internal.DipSwitch.DipValueKey) && item[Models.Internal.DipSwitch.DipValueKey] is Models.Internal.DipValue[] dipValues) - { - var dipValueItems = new List(); - foreach (var dipValue in dipValues) - { - dipValueItems.Add(ConvertToListxml(dipValue)); - } - dipSwitch.DipValue = dipValueItems.ToArray(); - } - - return dipSwitch; - } - - /// - /// Convert from to - /// - public static Models.Listxml.DipValue ConvertToListxml(Models.Internal.DipValue item) - { - var dipValue = new Models.Listxml.DipValue - { - Name = item.ReadString(Models.Internal.DipValue.NameKey), - Value = item.ReadString(Models.Internal.DipValue.ValueKey), - Default = item.ReadString(Models.Internal.DipValue.DefaultKey), - }; - - if (item.ContainsKey(Models.Internal.DipValue.ConditionKey) && item[Models.Internal.DipValue.ConditionKey] is Models.Internal.Condition condition) - dipValue.Condition = ConvertToListxml(condition); - - return dipValue; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Disk ConvertToListxml(Models.Internal.Disk item) - { - var disk = new Models.Listxml.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), - Region = item.ReadString(Models.Internal.Disk.RegionKey), - Index = item.ReadString(Models.Internal.Disk.IndexKey), - Writable = item.ReadString(Models.Internal.Disk.WritableKey), - Status = item.ReadString(Models.Internal.Disk.StatusKey), - Optional = item.ReadString(Models.Internal.Disk.OptionalKey), - }; - return disk; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Display ConvertToListxml(Models.Internal.Display item) - { - var display = new Models.Listxml.Display - { - Tag = item.ReadString(Models.Internal.Display.TagKey), - Type = item.ReadString(Models.Internal.Display.TypeKey), - Rotate = item.ReadString(Models.Internal.Display.RotateKey), - FlipX = item.ReadString(Models.Internal.Display.FlipXKey), - Width = item.ReadString(Models.Internal.Display.WidthKey), - Height = item.ReadString(Models.Internal.Display.HeightKey), - Refresh = item.ReadString(Models.Internal.Display.RefreshKey), - PixClock = item.ReadString(Models.Internal.Display.PixClockKey), - HTotal = item.ReadString(Models.Internal.Display.HTotalKey), - HBEnd = item.ReadString(Models.Internal.Display.HBEndKey), - HBStart = item.ReadString(Models.Internal.Display.HBStartKey), - VTotal = item.ReadString(Models.Internal.Display.VTotalKey), - VBEnd = item.ReadString(Models.Internal.Display.VBEndKey), - VBStart = item.ReadString(Models.Internal.Display.VBStartKey), - }; - return display; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Driver ConvertToListxml(Models.Internal.Driver item) - { - var driver = new Models.Listxml.Driver - { - Status = item.ReadString(Models.Internal.Driver.StatusKey), - Color = item.ReadString(Models.Internal.Driver.ColorKey), - Sound = item.ReadString(Models.Internal.Driver.SoundKey), - PaletteSize = item.ReadString(Models.Internal.Driver.PaletteSizeKey), - 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.Listxml.Extension ConvertToListxml(Models.Internal.Extension item) - { - var extension = new Models.Listxml.Extension - { - Name = item.ReadString(Models.Internal.Extension.NameKey), - }; - return extension; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Feature ConvertToListxml(Models.Internal.Feature item) - { - var feature = new Models.Listxml.Feature - { - Type = item.ReadString(Models.Internal.Feature.TypeKey), - Status = item.ReadString(Models.Internal.Feature.StatusKey), - Overall = item.ReadString(Models.Internal.Feature.OverallKey), - }; - return feature; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Input ConvertToListxml(Models.Internal.Input item) - { - var input = new Models.Listxml.Input - { - Service = item.ReadString(Models.Internal.Input.ServiceKey), - Tilt = item.ReadString(Models.Internal.Input.TiltKey), - Players = item.ReadString(Models.Internal.Input.PlayersKey), - ControlAttr = item.ReadString(Models.Internal.Input.ControlKey), - Buttons = item.ReadString(Models.Internal.Input.ButtonsKey), - Coins = item.ReadString(Models.Internal.Input.CoinsKey), - }; - - if (item.ContainsKey(Models.Internal.Input.ControlKey) && item[Models.Internal.Input.ControlKey] is Models.Internal.Control[] controls) - { - var controlItems = new List(); - foreach (var control in controls) - { - controlItems.Add(ConvertToListxml(control)); - } - input.Control = controlItems.ToArray(); - } - - return input; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Instance ConvertToListxml(Models.Internal.Instance item) - { - var instance = new Models.Listxml.Instance - { - Name = item.ReadString(Models.Internal.Instance.NameKey), - BriefName = item.ReadString(Models.Internal.Instance.BriefNameKey), - }; - return instance; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Port ConvertToListxml(Models.Internal.Port item) - { - var input = new Models.Listxml.Port - { - Tag = item.ReadString(Models.Internal.Port.TagKey), - }; - - if (item.ContainsKey(Models.Internal.Port.AnalogKey) && item[Models.Internal.Port.AnalogKey] is Models.Internal.Analog[] analogs) - { - var analogItems = new List(); - foreach (var analog in analogs) - { - analogItems.Add(ConvertToListxml(analog)); - } - input.Analog = analogItems.ToArray(); - } - - return input; - } - - /// - /// Convert from to - /// - public static Models.Listxml.RamOption ConvertToListxml(Models.Internal.RamOption item) - { - var ramOption = new Models.Listxml.RamOption - { - Name = item.ReadString(Models.Internal.RamOption.NameKey), - Default = item.ReadString(Models.Internal.RamOption.DefaultKey), - }; - return ramOption; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Rom ConvertToListxml(Models.Internal.Rom item) - { - var rom = new Models.Listxml.Rom - { - Name = item.ReadString(Models.Internal.Rom.NameKey), - Bios = item.ReadString(Models.Internal.Rom.BiosKey), - Size = item.ReadString(Models.Internal.Rom.SizeKey), - CRC = item.ReadString(Models.Internal.Rom.CRCKey), - SHA1 = item.ReadString(Models.Internal.Rom.SHA1Key), - Merge = item.ReadString(Models.Internal.Rom.MergeKey), - Region = item.ReadString(Models.Internal.Rom.RegionKey), - Offset = item.ReadString(Models.Internal.Rom.OffsetKey), - Status = item.ReadString(Models.Internal.Rom.StatusKey), - Optional = item.ReadString(Models.Internal.Rom.OptionalKey), - Dispose = item.ReadString(Models.Internal.Rom.DisposeKey), - SoundOnly = item.ReadString(Models.Internal.Rom.SoundOnlyKey), - }; - return rom; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Sample ConvertToListxml(Models.Internal.Sample item) - { - var sample = new Models.Listxml.Sample - { - Name = item.ReadString(Models.Internal.Sample.NameKey), - }; - return sample; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Slot ConvertToListxml(Models.Internal.Slot item) - { - var slot = new Models.Listxml.Slot - { - Name = item.ReadString(Models.Internal.Slot.NameKey), - }; - - if (item.ContainsKey(Models.Internal.Slot.SlotOptionKey) && item[Models.Internal.Slot.SlotOptionKey] is Models.Internal.SlotOption[] slotOptions) - { - var slotOptionItems = new List(); - foreach (var slotOption in slotOptions) - { - slotOptionItems.Add(ConvertToListxml(slotOption)); - } - slot.SlotOption = slotOptionItems.ToArray(); - } - - return slot; - } - - /// - /// Convert from to - /// - public static Models.Listxml.SlotOption ConvertToListxml(Models.Internal.SlotOption item) - { - var slotOption = new Models.Listxml.SlotOption - { - Name = item.ReadString(Models.Internal.SlotOption.NameKey), - DevName = item.ReadString(Models.Internal.SlotOption.DevNameKey), - Default = item.ReadString(Models.Internal.SlotOption.DefaultKey), - }; - return slotOption; - } - - /// - /// Convert from to - /// - public static Models.Listxml.SoftwareList ConvertToListxml(Models.Internal.SoftwareList item) - { - var softwareList = new Models.Listxml.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; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Sound ConvertToListxml(Models.Internal.Sound item) - { - var sound = new Models.Listxml.Sound - { - Channels = item.ReadString(Models.Internal.Sound.ChannelsKey), - }; - return sound; - } - - /// - /// Convert from to - /// - public static Models.Listxml.Video ConvertToListxml(Models.Internal.Video item) - { - var video = new Models.Listxml.Video - { - Screen = item.ReadString(Models.Internal.Video.ScreenKey), - Orientation = item.ReadString(Models.Internal.Video.OrientationKey), - Width = item.ReadString(Models.Internal.Video.WidthKey), - Height = item.ReadString(Models.Internal.Video.HeightKey), - AspectX = item.ReadString(Models.Internal.Video.AspectXKey), - AspectY = item.ReadString(Models.Internal.Video.AspectYKey), - Refresh = item.ReadString(Models.Internal.Video.RefreshKey), - }; - return video; - } - - #endregion - - #region Logiqx - - /// - /// 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 - - #region OfflineList - - /// - /// Convert from to - /// - public static Models.OfflineList.FileRomCRC ConvertToOfflineList(Models.Internal.Rom item) - { - var fileRomCRC = new Models.OfflineList.FileRomCRC - { - Extension = item.ReadString(Models.Internal.Rom.ExtensionKey), - Content = item.ReadString(Models.Internal.Rom.CRCKey), - }; - return fileRomCRC; - } - - #endregion - - #region OpenMSX - - /// - /// Convert from to - /// - public static Models.OpenMSX.Dump ConvertToOpenMSX(Models.Internal.Dump item) - { - var dump = new Models.OpenMSX.Dump(); - - if (item.ContainsKey(Models.Internal.Dump.OriginalKey) && item[Models.Internal.Dump.OriginalKey] is Models.Internal.Original original) - dump.Original = ConvertToOpenMSX(original); - - if (item.ContainsKey(Models.Internal.Dump.RomKey) && item[Models.Internal.Dump.RomKey] is Models.Internal.Rom rom) - { - dump.Rom = ConvertToOpenMSXRom(rom); - } - else if (item.ContainsKey(Models.Internal.Dump.MegaRomKey) && item[Models.Internal.Dump.MegaRomKey] is Models.Internal.Rom megaRom) - { - dump.Rom = ConvertToOpenMSXMegaRom(megaRom); - } - else if (item.ContainsKey(Models.Internal.Dump.SCCPlusCartKey) && item[Models.Internal.Dump.SCCPlusCartKey] is Models.Internal.Rom sccPlusCart) - { - dump.Rom = ConvertToOpenMSXSCCPlusCart(sccPlusCart); - } - - return dump; - } - - /// - /// Convert from to - /// - public static Models.OpenMSX.MegaRom ConvertToOpenMSXMegaRom(Models.Internal.Rom item) - { - var megaRom = new Models.OpenMSX.MegaRom - { - Start = item.ReadString(Models.Internal.Rom.StartKey), - Type = item.ReadString(Models.Internal.Rom.TypeKey), - Hash = item.ReadString(Models.Internal.Rom.SHA1Key), - Remark = item.ReadString(Models.Internal.Rom.RemarkKey), - }; - return megaRom; - } - - /// - /// Convert from to - /// - public static Models.OpenMSX.Original ConvertToOpenMSX(Models.Internal.Original item) - { - var original = new Models.OpenMSX.Original - { - Value = item.ReadString(Models.Internal.Original.ValueKey), - Content = item.ReadString(Models.Internal.Original.ContentKey), - }; - return original; - } - - /// - /// Convert from to - /// - public static Models.OpenMSX.Rom ConvertToOpenMSXRom(Models.Internal.Rom item) - { - var rom = new Models.OpenMSX.Rom - { - Start = item.ReadString(Models.Internal.Rom.StartKey), - Type = item.ReadString(Models.Internal.Rom.TypeKey), - Hash = item.ReadString(Models.Internal.Rom.SHA1Key), - Remark = item.ReadString(Models.Internal.Rom.RemarkKey), - }; - return rom; - } - - /// - /// Convert from to - /// - public static Models.OpenMSX.SCCPlusCart ConvertToOpenMSXSCCPlusCart(Models.Internal.Rom item) - { - var sccPlusCart = new Models.OpenMSX.SCCPlusCart - { - Start = item.ReadString(Models.Internal.Rom.StartKey), - Type = item.ReadString(Models.Internal.Rom.TypeKey), - Hash = item.ReadString(Models.Internal.Rom.SHA1Key), - Remark = item.ReadString(Models.Internal.Rom.RemarkKey), - }; - return sccPlusCart; - } - - #endregion - - #region RomCenter - - /// - /// Convert from to - /// - public static Models.RomCenter.Rom ConvertToRomCenter(Models.Internal.Rom item) - { - var row = new Models.RomCenter.Rom - { - RomName = item.ReadString(Models.Internal.Rom.NameKey), - RomCRC = item.ReadString(Models.Internal.Rom.CRCKey), - RomSize = item.ReadString(Models.Internal.Rom.SizeKey), - MergeName = item.ReadString(Models.Internal.Rom.MergeKey), - }; - return row; - } - - #endregion - - #region SeparatedValue - - /// - /// Convert from to - /// - public static Models.SeparatedValue.Row ConvertToSeparatedValue(Models.Internal.Disk item) - { - var row = new Models.SeparatedValue.Row - { - Type = "disk", - DiskName = item.ReadString(Models.Internal.Disk.NameKey), - MD5 = item.ReadString(Models.Internal.Disk.MD5Key), - SHA1 = item.ReadString(Models.Internal.Disk.SHA1Key), - Status = item.ReadString(Models.Internal.Disk.StatusKey), - }; - return row; - } - - /// - /// Convert from to - /// - public static Models.SeparatedValue.Row ConvertToSeparatedValue(Models.Internal.Media item) - { - var row = new Models.SeparatedValue.Row - { - Type = "media", - DiskName = 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 row; - } - - /// - /// Convert from to - /// - public static Models.SeparatedValue.Row ConvertToSeparatedValue(Models.Internal.Rom item) - { - var row = new Models.SeparatedValue.Row - { - Type = "rom", - RomName = 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), - Status = item.ReadString(Models.Internal.Rom.StatusKey), - }; - return row; - } - - #endregion - - #region SoftwareList - - /// - /// Convert from to - /// - public static Models.SoftwareList.DataArea ConvertToSoftwareList(Models.Internal.DataArea item) - { - var dataArea = new Models.SoftwareList.DataArea - { - Name = item.ReadString(Models.Internal.DataArea.NameKey), - Size = item.ReadString(Models.Internal.DataArea.SizeKey), - Width = item.ReadString(Models.Internal.DataArea.WidthKey), - Endianness = item.ReadString(Models.Internal.DataArea.EndiannessKey), - }; - - if (item.ContainsKey(Models.Internal.DataArea.RomKey) && item[Models.Internal.DataArea.RomKey] is Models.Internal.Rom[] roms) - { - var romItems = new List(); - foreach (var rom in roms) - { - romItems.Add(ConvertToSoftwareList(rom)); - } - dataArea.Rom = romItems.ToArray(); - } - - return dataArea; - } - - /// - /// Convert from to - /// - public static Models.SoftwareList.DipSwitch ConvertToSoftwareList(Models.Internal.DipSwitch item) - { - var dipSwitch = new Models.SoftwareList.DipSwitch - { - Name = item.ReadString(Models.Internal.DipSwitch.NameKey), - Tag = item.ReadString(Models.Internal.DipSwitch.TagKey), - Mask = item.ReadString(Models.Internal.DipSwitch.MaskKey), - }; - - if (item.ContainsKey(Models.Internal.DipSwitch.DipValueKey) && item[Models.Internal.DipSwitch.DipValueKey] is Models.Internal.DipValue[] dipValues) - { - var dipValueItems = new List(); - foreach (var rom in dipValues) - { - dipValueItems.Add(ConvertToSoftwareList(rom)); - } - dipSwitch.DipValue = dipValueItems.ToArray(); - } - - return dipSwitch; - } - - /// - /// Convert from to - /// - public static Models.SoftwareList.DipValue ConvertToSoftwareList(Models.Internal.DipValue item) - { - var dipValue = new Models.SoftwareList.DipValue - { - Name = item.ReadString(Models.Internal.DipValue.NameKey), - Value = item.ReadString(Models.Internal.DipValue.ValueKey), - Default = item.ReadString(Models.Internal.DipValue.DefaultKey), - }; - return dipValue; - } - - /// - /// Convert from to - /// - public static Models.SoftwareList.Disk ConvertToSoftwareList(Models.Internal.Disk item) - { - var disk = new Models.SoftwareList.Disk - { - Name = item.ReadString(Models.Internal.Disk.NameKey), - MD5 = item.ReadString(Models.Internal.Disk.MD5Key), - SHA1 = item.ReadString(Models.Internal.Disk.SHA1Key), - Status = item.ReadString(Models.Internal.Disk.StatusKey), - Writeable = item.ReadString(Models.Internal.Disk.WritableKey), - }; - return disk; - } - - /// - /// Convert from to - /// - public static Models.SoftwareList.DiskArea ConvertToSoftwareList(Models.Internal.DiskArea item) - { - var diskArea = new Models.SoftwareList.DiskArea - { - Name = item.ReadString(Models.Internal.DiskArea.NameKey), - }; - - if (item.ContainsKey(Models.Internal.DiskArea.DiskKey) && item[Models.Internal.DiskArea.DiskKey] is Models.Internal.Disk[] disks) - { - var diskItems = new List(); - foreach (var disk in disks) - { - diskItems.Add(ConvertToSoftwareList(disk)); - } - diskArea.Disk = diskItems.ToArray(); - } - - return diskArea; - } - - /// - /// Convert from to - /// - public static Models.SoftwareList.Feature ConvertToSoftwareList(Models.Internal.Feature item) - { - var feature = new Models.SoftwareList.Feature - { - Name = item.ReadString(Models.Internal.Feature.NameKey), - Value = item.ReadString(Models.Internal.Feature.ValueKey), - }; - return feature; - } - - /// - /// Convert from to - /// - public static Models.SoftwareList.Info ConvertToSoftwareList(Models.Internal.Info item) - { - var info = new Models.SoftwareList.Info - { - Name = item.ReadString(Models.Internal.Info.NameKey), - Value = item.ReadString(Models.Internal.Info.ValueKey), - }; - return info; - } - - /// - /// Convert from to - /// - public static Models.SoftwareList.Part ConvertToSoftwareList(Models.Internal.Part item) - { - var part = new Models.SoftwareList.Part - { - Name = item.ReadString(Models.Internal.Part.NameKey), - Interface = item.ReadString(Models.Internal.Part.InterfaceKey), - }; - - if (item.ContainsKey(Models.Internal.Part.FeatureKey) && item[Models.Internal.Part.FeatureKey] is Models.Internal.Feature[] features) - { - var featureItems = new List(); - foreach (var feature in features) - { - featureItems.Add(ConvertToSoftwareList(feature)); - } - part.Feature = featureItems.ToArray(); - } - - if (item.ContainsKey(Models.Internal.Part.DataAreaKey) && item[Models.Internal.Part.DataAreaKey] is Models.Internal.DataArea[] dataAreas) - { - var dataAreaItems = new List(); - foreach (var dataArea in dataAreas) - { - dataAreaItems.Add(ConvertToSoftwareList(dataArea)); - } - part.DataArea = dataAreaItems.ToArray(); - } - - if (item.ContainsKey(Models.Internal.Part.DiskAreaKey) && item[Models.Internal.Part.DiskAreaKey] is Models.Internal.DiskArea[] diskAreas) - { - var diskAreaItems = new List(); - foreach (var diskArea in diskAreas) - { - diskAreaItems.Add(ConvertToSoftwareList(diskArea)); - } - part.DiskArea = diskAreaItems.ToArray(); - } - - if (item.ContainsKey(Models.Internal.Part.DipSwitchKey) && item[Models.Internal.Part.DipSwitchKey] is Models.Internal.DipSwitch[] dipSwitches) - { - var dipSwitchItems = new List(); - foreach (var rom in dipSwitches) - { - dipSwitchItems.Add(ConvertToSoftwareList(rom)); - } - part.DipSwitch = dipSwitchItems.ToArray(); - } - - return part; - } - - /// - /// Convert from to - /// - public static Models.SoftwareList.Rom ConvertToSoftwareList(Models.Internal.Rom item) - { - var rom = new Models.SoftwareList.Rom - { - Name = item.ReadString(Models.Internal.Rom.NameKey), - Size = item.ReadString(Models.Internal.Rom.SizeKey), - Length = item.ReadString(Models.Internal.Rom.LengthKey), - CRC = item.ReadString(Models.Internal.Rom.CRCKey), - SHA1 = item.ReadString(Models.Internal.Rom.SHA1Key), - Offset = item.ReadString(Models.Internal.Rom.OffsetKey), - Value = item.ReadString(Models.Internal.Rom.ValueKey), - Status = item.ReadString(Models.Internal.Rom.StatusKey), - LoadFlag = item.ReadString(Models.Internal.Rom.LoadFlagKey), - }; - return rom; - } - - /// - /// Convert from to - /// - public static Models.SoftwareList.SharedFeat ConvertToSoftwareList(Models.Internal.SharedFeat item) - { - var sharedFeat = new Models.SoftwareList.SharedFeat - { - Name = item.ReadString(Models.Internal.SharedFeat.NameKey), - Value = item.ReadString(Models.Internal.SharedFeat.ValueKey), - }; - return sharedFeat; - } - - #endregion - } -} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.DosCenter.cs b/SabreTools.Serialization/Internal.DosCenter.cs new file mode 100644 index 00000000..c55581aa --- /dev/null +++ b/SabreTools.Serialization/Internal.DosCenter.cs @@ -0,0 +1,46 @@ +namespace SabreTools.Serialization +{ + /// + /// Serializer for DosCenter models to internal structure + /// + public partial class Internal + { + #region Serialize + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromDosCenter(Models.DosCenter.File 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.DateKey] = item.Date, + }; + return rom; + } + + #endregion + + #region Deserialize + + /// + /// Convert from to + /// + public static Models.DosCenter.File ConvertToDosCenter(Models.Internal.Rom item) + { + var file = new Models.DosCenter.File + { + Name = item.ReadString(Models.Internal.Rom.NameKey), + Size = item.ReadString(Models.Internal.Rom.SizeKey), + CRC = item.ReadString(Models.Internal.Rom.CRCKey), + Date = item.ReadString(Models.Internal.Rom.DateKey), + }; + return file; + } + + #endregion + } +} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.EverdriveSMDB.cs b/SabreTools.Serialization/Internal.EverdriveSMDB.cs new file mode 100644 index 00000000..da274464 --- /dev/null +++ b/SabreTools.Serialization/Internal.EverdriveSMDB.cs @@ -0,0 +1,50 @@ +namespace SabreTools.Serialization +{ + /// + /// Serializer for EverdriveSMDB models to internal structure + /// + public partial class Internal + { + #region Serialize + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromEverdriveSMDB(Models.EverdriveSMDB.Row item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.SHA256Key] = item.SHA256, + [Models.Internal.Rom.NameKey] = item.Name, + [Models.Internal.Rom.SHA1Key] = item.SHA1, + [Models.Internal.Rom.MD5Key] = item.MD5, + [Models.Internal.Rom.CRCKey] = item.CRC32, + [Models.Internal.Rom.SizeKey] = item.Size, + }; + return rom; + } + + #endregion + + #region Deserialize + + /// + /// Convert from to + /// + public static Models.EverdriveSMDB.Row ConvertToEverdriveSMDB(Models.Internal.Rom item) + { + var row = new Models.EverdriveSMDB.Row + { + SHA256 = item.ReadString(Models.Internal.Rom.SHA256Key), + Name = item.ReadString(Models.Internal.Rom.NameKey), + SHA1 = item.ReadString(Models.Internal.Rom.SHA1Key), + MD5 = item.ReadString(Models.Internal.Rom.MD5Key), + CRC32 = item.ReadString(Models.Internal.Rom.CRCKey), + Size = item.ReadString(Models.Internal.Rom.SizeKey), + }; + return row; + } + + #endregion + } +} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.Hashfile.cs b/SabreTools.Serialization/Internal.Hashfile.cs new file mode 100644 index 00000000..208ca833 --- /dev/null +++ b/SabreTools.Serialization/Internal.Hashfile.cs @@ -0,0 +1,198 @@ +namespace SabreTools.Serialization +{ + /// + /// Serializer for Hashfile models to internal structure + /// + public partial class Internal + { + #region Serialize + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromMD5(Models.Hashfile.MD5 item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.MD5Key] = item.Hash, + [Models.Internal.Rom.NameKey] = item.File, + }; + return rom; + } + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromSFV(Models.Hashfile.SFV item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.NameKey] = item.File, + [Models.Internal.Rom.CRCKey] = item.Hash, + }; + return rom; + } + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromSHA1(Models.Hashfile.SHA1 item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.SHA1Key] = item.Hash, + [Models.Internal.Rom.NameKey] = item.File, + }; + return rom; + } + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromSHA256(Models.Hashfile.SHA256 item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.SHA256Key] = item.Hash, + [Models.Internal.Rom.NameKey] = item.File, + }; + return rom; + } + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromSHA384(Models.Hashfile.SHA384 item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.SHA384Key] = item.Hash, + [Models.Internal.Rom.NameKey] = item.File, + }; + return rom; + } + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromSHA512(Models.Hashfile.SHA512 item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.SHA512Key] = item.Hash, + [Models.Internal.Rom.NameKey] = item.File, + }; + return rom; + } + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromSpamSum(Models.Hashfile.SpamSum item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.SpamSumKey] = item.Hash, + [Models.Internal.Rom.NameKey] = item.File, + }; + return rom; + } + + #endregion + + #region Deserialize + + /// + /// Convert from to + /// + public static Models.Hashfile.MD5 ConvertToMD5(Models.Internal.Rom item) + { + var md5 = new Models.Hashfile.MD5 + { + Hash = item.ReadString(Models.Internal.Rom.MD5Key), + File = item.ReadString(Models.Internal.Rom.NameKey), + }; + return md5; + } + + /// + /// Convert from to + /// + public static Models.Hashfile.SFV ConvertToSFV(Models.Internal.Rom item) + { + var sfv = new Models.Hashfile.SFV + { + File = item.ReadString(Models.Internal.Rom.NameKey), + Hash = item.ReadString(Models.Internal.Rom.CRCKey), + }; + return sfv; + } + + /// + /// Convert from to + /// + public static Models.Hashfile.SHA1 ConvertToSHA1(Models.Internal.Rom item) + { + var sha1 = new Models.Hashfile.SHA1 + { + Hash = item.ReadString(Models.Internal.Rom.SHA1Key), + File = item.ReadString(Models.Internal.Rom.NameKey), + }; + return sha1; + } + + /// + /// Convert from to + /// + public static Models.Hashfile.SHA256 ConvertToSHA256(Models.Internal.Rom item) + { + var sha256 = new Models.Hashfile.SHA256 + { + Hash = item.ReadString(Models.Internal.Rom.SHA256Key), + File = item.ReadString(Models.Internal.Rom.NameKey), + }; + return sha256; + } + + /// + /// Convert from to + /// + public static Models.Hashfile.SHA384 ConvertToSHA384(Models.Internal.Rom item) + { + var sha384 = new Models.Hashfile.SHA384 + { + Hash = item.ReadString(Models.Internal.Rom.SHA384Key), + File = item.ReadString(Models.Internal.Rom.NameKey), + }; + return sha384; + } + + /// + /// Convert from to + /// + public static Models.Hashfile.SHA512 ConvertToSHA512(Models.Internal.Rom item) + { + var sha512 = new Models.Hashfile.SHA512 + { + Hash = item.ReadString(Models.Internal.Rom.SHA512Key), + File = item.ReadString(Models.Internal.Rom.NameKey), + }; + return sha512; + } + + /// + /// Convert from to + /// + public static Models.Hashfile.SpamSum ConvertToSpamSum(Models.Internal.Rom item) + { + var spamsum = new Models.Hashfile.SpamSum + { + Hash = item.ReadString(Models.Internal.Rom.SpamSumKey), + File = item.ReadString(Models.Internal.Rom.NameKey), + }; + return spamsum; + } + + #endregion + } +} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.Listrom.cs b/SabreTools.Serialization/Internal.Listrom.cs new file mode 100644 index 00000000..e77d6887 --- /dev/null +++ b/SabreTools.Serialization/Internal.Listrom.cs @@ -0,0 +1,97 @@ +namespace SabreTools.Serialization +{ + /// + /// Serializer for Listrom models to internal structure + /// + public partial class Internal + { + #region Serialize + + /// + /// Convert from to + /// + public static Models.Internal.DatItem ConvertFromListrom(Models.Listrom.Row item) + { + if (item.Size == null) + { + var disk = new Models.Internal.Disk + { + [Models.Internal.Disk.NameKey] = item.Name, + [Models.Internal.Disk.MD5Key] = item.MD5, + [Models.Internal.Disk.SHA1Key] = item.SHA1, + }; + + if (item.NoGoodDumpKnown) + disk[Models.Internal.Disk.StatusKey] = "nodump"; + else if (item.Bad) + disk[Models.Internal.Disk.StatusKey] = "baddump"; + + return disk; + } + else + { + 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.SHA1Key] = item.SHA1, + }; + + if (item.NoGoodDumpKnown) + rom[Models.Internal.Rom.StatusKey] = "nodump"; + else if (item.Bad) + rom[Models.Internal.Rom.StatusKey] = "baddump"; + + return rom; + } + } + + #endregion + + #region Deserialize + + /// + /// Convert from to + /// + public static Models.Listrom.Row ConvertToListrom(Models.Internal.Disk item) + { + var row = new Models.Listrom.Row + { + Name = item.ReadString(Models.Internal.Disk.NameKey), + MD5 = item.ReadString(Models.Internal.Disk.MD5Key), + SHA1 = item.ReadString(Models.Internal.Disk.SHA1Key), + }; + + if (item[Models.Internal.Disk.StatusKey] as string == "nodump") + row.NoGoodDumpKnown = true; + else if (item[Models.Internal.Disk.StatusKey] as string == "baddump") + row.Bad = true; + + return row; + } + + /// + /// Convert from to + /// + public static Models.Listrom.Row ConvertToListrom(Models.Internal.Rom item) + { + var row = new Models.Listrom.Row + { + Name = item.ReadString(Models.Internal.Rom.NameKey), + Size = item.ReadString(Models.Internal.Rom.SizeKey), + CRC = item.ReadString(Models.Internal.Rom.CRCKey), + SHA1 = item.ReadString(Models.Internal.Rom.SHA1Key), + }; + + if (item[Models.Internal.Rom.StatusKey] as string == "nodump") + row.NoGoodDumpKnown = true; + else if (item[Models.Internal.Rom.StatusKey] as string == "baddump") + row.Bad = true; + + return row; + } + + #endregion + } +} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.Listxml.cs b/SabreTools.Serialization/Internal.Listxml.cs new file mode 100644 index 00000000..a6fca7d4 --- /dev/null +++ b/SabreTools.Serialization/Internal.Listxml.cs @@ -0,0 +1,1151 @@ +using System.Collections.Generic; +using System.Linq; + +namespace SabreTools.Serialization +{ + /// + /// Serializer for Listxml models to internal structure + /// + public partial class Internal + { + #region Serialize + + /// + /// Convert from to + /// + public static Models.Internal.Adjuster ConvertFromListxml(Models.Listxml.Adjuster item) + { + var adjuster = new Models.Internal.Adjuster + { + [Models.Internal.Adjuster.NameKey] = item.Name, + [Models.Internal.Adjuster.DefaultKey] = item.Default, + }; + + if (item.Condition != null) + adjuster[Models.Internal.Adjuster.ConditionKey] = ConvertFromListxml(item.Condition); + + return adjuster; + } + + /// + /// Convert from to + /// + public static Models.Internal.Analog ConvertFromListxml(Models.Listxml.Analog item) + { + var analog = new Models.Internal.Analog + { + [Models.Internal.Analog.MaskKey] = item.Mask, + }; + return analog; + } + + /// + /// Convert from to + /// + public static Models.Internal.BiosSet ConvertFromListxml(Models.Listxml.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.Chip ConvertFromListxml(Models.Listxml.Chip item) + { + var chip = new Models.Internal.Chip + { + [Models.Internal.Chip.NameKey] = item.Name, + [Models.Internal.Chip.TagKey] = item.Tag, + [Models.Internal.Chip.TypeKey] = item.Type, + [Models.Internal.Chip.SoundOnlyKey] = item.SoundOnly, + [Models.Internal.Chip.ClockKey] = item.Clock, + }; + return chip; + } + + /// + /// Convert from to + /// + public static Models.Internal.Condition ConvertFromListxml(Models.Listxml.Condition item) + { + var condition = new Models.Internal.Condition + { + [Models.Internal.Condition.TagKey] = item.Tag, + [Models.Internal.Condition.MaskKey] = item.Mask, + [Models.Internal.Condition.RelationKey] = item.Relation, + [Models.Internal.Condition.ValueKey] = item.Value, + }; + return condition; + } + + /// + /// Convert from to + /// + public static Models.Internal.Configuration ConvertFromListxml(Models.Listxml.Configuration item) + { + var configuration = new Models.Internal.Configuration + { + [Models.Internal.Configuration.NameKey] = item.Name, + [Models.Internal.Configuration.TagKey] = item.Tag, + [Models.Internal.Configuration.MaskKey] = item.Mask, + }; + + if (item.Condition != null) + configuration[Models.Internal.Configuration.ConditionKey] = ConvertFromListxml(item.Condition); + + if (item.ConfLocation != null && item.ConfLocation.Any()) + { + var confLocations = new List(); + foreach (var confLocation in item.ConfLocation) + { + confLocations.Add(ConvertFromListxml(confLocation)); + } + configuration[Models.Internal.Configuration.ConfLocationKey] = confLocations.ToArray(); + } + + if (item.ConfSetting != null && item.ConfSetting.Any()) + { + var confSettings = new List(); + foreach (var confSetting in item.ConfSetting) + { + confSettings.Add(ConvertFromListxml(confSetting)); + } + configuration[Models.Internal.Configuration.ConfSettingKey] = confSettings.ToArray(); + } + + return configuration; + } + + /// + /// Convert from to + /// + public static Models.Internal.ConfLocation ConvertFromListxml(Models.Listxml.ConfLocation item) + { + var confLocation = new Models.Internal.ConfLocation + { + [Models.Internal.ConfLocation.NameKey] = item.Name, + [Models.Internal.ConfLocation.NumberKey] = item.Number, + [Models.Internal.ConfLocation.InvertedKey] = item.Inverted, + }; + return confLocation; + } + + /// + /// Convert from to + /// + public static Models.Internal.ConfSetting ConvertFromListxml(Models.Listxml.ConfSetting item) + { + var confSetting = new Models.Internal.ConfSetting + { + [Models.Internal.ConfSetting.NameKey] = item.Name, + [Models.Internal.ConfSetting.ValueKey] = item.Value, + [Models.Internal.ConfSetting.DefaultKey] = item.Default, + }; + + if (item.Condition != null) + confSetting[Models.Internal.ConfSetting.ConditionKey] = ConvertFromListxml(item.Condition); + + return confSetting; + } + + /// + /// Convert from to + /// + public static Models.Internal.Control ConvertFromListxml(Models.Listxml.Control item) + { + var control = new Models.Internal.Control + { + [Models.Internal.Control.TypeKey] = item.Type, + [Models.Internal.Control.PlayerKey] = item.Player, + [Models.Internal.Control.ButtonsKey] = item.Buttons, + [Models.Internal.Control.ReqButtonsKey] = item.ReqButtons, + [Models.Internal.Control.MinimumKey] = item.Minimum, + [Models.Internal.Control.MaximumKey] = item.Maximum, + [Models.Internal.Control.SensitivityKey] = item.Sensitivity, + [Models.Internal.Control.KeyDeltaKey] = item.KeyDelta, + [Models.Internal.Control.ReverseKey] = item.Reverse, + [Models.Internal.Control.WaysKey] = item.Ways, + [Models.Internal.Control.Ways2Key] = item.Ways2, + [Models.Internal.Control.Ways3Key] = item.Ways3, + }; + return control; + } + + /// + /// Convert from to + /// + public static Models.Internal.Device ConvertFromListxml(Models.Listxml.Device item) + { + var device = new Models.Internal.Device + { + [Models.Internal.Device.TypeKey] = item.Type, + [Models.Internal.Device.TagKey] = item.Tag, + [Models.Internal.Device.FixedImageKey] = item.FixedImage, + [Models.Internal.Device.MandatoryKey] = item.Mandatory, + [Models.Internal.Device.InterfaceKey] = item.Interface, + }; + + if (item.Instance != null) + device[Models.Internal.Device.InstanceKey] = ConvertFromListxml(item.Instance); + + if (item.Extension != null && item.Extension.Any()) + { + var extensions = new List(); + foreach (var extension in item.Extension) + { + extensions.Add(ConvertFromListxml(extension)); + } + device[Models.Internal.Device.ExtensionKey] = extensions.ToArray(); + } + + return device; + } + + /// + /// Convert from to + /// + public static Models.Internal.DeviceRef ConvertFromListxml(Models.Listxml.DeviceRef item) + { + var deviceRef = new Models.Internal.DeviceRef + { + [Models.Internal.DeviceRef.NameKey] = item.Name, + }; + return deviceRef; + } + + /// + /// Convert from to + /// + public static Models.Internal.DipLocation ConvertFromListxml(Models.Listxml.DipLocation item) + { + var dipLocation = new Models.Internal.DipLocation + { + [Models.Internal.DipLocation.NameKey] = item.Name, + [Models.Internal.DipLocation.NumberKey] = item.Number, + [Models.Internal.DipLocation.InvertedKey] = item.Inverted, + }; + return dipLocation; + } + + /// + /// Convert from to + /// + public static Models.Internal.DipSwitch ConvertFromListxml(Models.Listxml.DipSwitch item) + { + var dipSwitch = new Models.Internal.DipSwitch + { + [Models.Internal.DipSwitch.NameKey] = item.Name, + [Models.Internal.DipSwitch.TagKey] = item.Tag, + [Models.Internal.DipSwitch.MaskKey] = item.Mask, + }; + + if (item.Condition != null) + dipSwitch[Models.Internal.DipSwitch.ConditionKey] = ConvertFromListxml(item.Condition); + + if (item.DipLocation != null && item.DipLocation.Any()) + { + var dipLocations = new List(); + foreach (var dipLocation in item.DipLocation) + { + dipLocations.Add(ConvertFromListxml(dipLocation)); + } + dipSwitch[Models.Internal.DipSwitch.DipLocationKey] = dipLocations.ToArray(); + } + + if (item.DipValue != null && item.DipValue.Any()) + { + var dipValues = new List(); + foreach (var dipValue in item.DipValue) + { + dipValues.Add(ConvertFromListxml(dipValue)); + } + dipSwitch[Models.Internal.DipSwitch.DipValueKey] = dipValues.ToArray(); + } + + return dipSwitch; + } + + /// + /// Convert from to + /// + public static Models.Internal.DipValue ConvertFromListxml(Models.Listxml.DipValue item) + { + var dipValue = new Models.Internal.DipValue + { + [Models.Internal.DipValue.NameKey] = item.Name, + [Models.Internal.DipValue.ValueKey] = item.Value, + [Models.Internal.DipValue.DefaultKey] = item.Default, + }; + + if (item.Condition != null) + dipValue[Models.Internal.DipValue.ConditionKey] = ConvertFromListxml(item.Condition); + + return dipValue; + } + + /// + /// Convert from to + /// + public static Models.Internal.Disk ConvertFromListxml(Models.Listxml.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.RegionKey] = item.Region, + [Models.Internal.Disk.IndexKey] = item.Index, + [Models.Internal.Disk.WritableKey] = item.Writable, + [Models.Internal.Disk.StatusKey] = item.Status, + [Models.Internal.Disk.OptionalKey] = item.Optional, + }; + return disk; + } + + /// + /// Convert from to + /// + public static Models.Internal.Display ConvertFromListxml(Models.Listxml.Display item) + { + var display = new Models.Internal.Display + { + [Models.Internal.Display.TagKey] = item.Tag, + [Models.Internal.Display.TypeKey] = item.Type, + [Models.Internal.Display.RotateKey] = item.Rotate, + [Models.Internal.Display.FlipXKey] = item.FlipX, + [Models.Internal.Display.WidthKey] = item.Width, + [Models.Internal.Display.HeightKey] = item.Height, + [Models.Internal.Display.RefreshKey] = item.Refresh, + [Models.Internal.Display.PixClockKey] = item.PixClock, + [Models.Internal.Display.HTotalKey] = item.HTotal, + [Models.Internal.Display.HBEndKey] = item.HBEnd, + [Models.Internal.Display.HBStartKey] = item.HBStart, + [Models.Internal.Display.VTotalKey] = item.VTotal, + [Models.Internal.Display.VBEndKey] = item.VBEnd, + [Models.Internal.Display.VBStartKey] = item.VBStart, + }; + return display; + } + + /// + /// Convert from to + /// + public static Models.Internal.Driver ConvertFromListxml(Models.Listxml.Driver item) + { + var driver = new Models.Internal.Driver + { + [Models.Internal.Driver.StatusKey] = item.Status, + [Models.Internal.Driver.ColorKey] = item.Color, + [Models.Internal.Driver.SoundKey] = item.Sound, + [Models.Internal.Driver.PaletteSizeKey] = item.PaletteSize, + [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.Extension ConvertFromListxml(Models.Listxml.Extension item) + { + var extension = new Models.Internal.Extension + { + [Models.Internal.Extension.NameKey] = item.Name, + }; + return extension; + } + + /// + /// Convert from to + /// + public static Models.Internal.Feature ConvertFromListxml(Models.Listxml.Feature item) + { + var feature = new Models.Internal.Feature + { + [Models.Internal.Feature.TypeKey] = item.Type, + [Models.Internal.Feature.StatusKey] = item.Status, + [Models.Internal.Feature.OverallKey] = item.Overall, + }; + return feature; + } + + /// + /// Convert from to + /// + public static Models.Internal.Input ConvertFromListxml(Models.Listxml.Input item) + { + var input = new Models.Internal.Input + { + [Models.Internal.Input.ServiceKey] = item.Service, + [Models.Internal.Input.TiltKey] = item.Tilt, + [Models.Internal.Input.PlayersKey] = item.Players, + [Models.Internal.Input.ControlKey] = item.ControlAttr, + [Models.Internal.Input.ButtonsKey] = item.Buttons, + [Models.Internal.Input.CoinsKey] = item.Coins, + }; + + if (item.Control != null && item.Control.Any()) + { + var controls = new List(); + foreach (var control in item.Control) + { + controls.Add(ConvertFromListxml(control)); + } + input[Models.Internal.Input.ControlKey] = controls.ToArray(); + } + + return input; + } + + /// + /// Convert from to + /// + public static Models.Internal.Instance ConvertFromListxml(Models.Listxml.Instance item) + { + var instance = new Models.Internal.Instance + { + [Models.Internal.Instance.NameKey] = item.Name, + [Models.Internal.Instance.BriefNameKey] = item.BriefName, + }; + return instance; + } + + /// + /// Convert from to + /// + public static Models.Internal.Port ConvertFromListxml(Models.Listxml.Port item) + { + var port = new Models.Internal.Port + { + [Models.Internal.Port.TagKey] = item.Tag, + }; + + if (item.Analog != null && item.Analog.Any()) + { + var analogs = new List(); + foreach (var analog in item.Analog) + { + analogs.Add(ConvertFromListxml(analog)); + } + port[Models.Internal.Port.AnalogKey] = analogs.ToArray(); + } + + return port; + } + + /// + /// Convert from to + /// + public static Models.Internal.RamOption ConvertFromListxml(Models.Listxml.RamOption item) + { + var ramOption = new Models.Internal.RamOption + { + [Models.Internal.RamOption.NameKey] = item.Name, + [Models.Internal.RamOption.DefaultKey] = item.Default, + }; + return ramOption; + } + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromListxml(Models.Listxml.Rom item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.NameKey] = item.Name, + [Models.Internal.Rom.BiosKey] = item.Bios, + [Models.Internal.Rom.SizeKey] = item.Size, + [Models.Internal.Rom.CRCKey] = item.CRC, + [Models.Internal.Rom.SHA1Key] = item.SHA1, + [Models.Internal.Rom.MergeKey] = item.Merge, + [Models.Internal.Rom.RegionKey] = item.Region, + [Models.Internal.Rom.OffsetKey] = item.Offset, + [Models.Internal.Rom.StatusKey] = item.Status, + [Models.Internal.Rom.OptionalKey] = item.Optional, + [Models.Internal.Rom.DisposeKey] = item.Dispose, + [Models.Internal.Rom.SoundOnlyKey] = item.SoundOnly, + }; + return rom; + } + + /// + /// Convert from to + /// + public static Models.Internal.Sample ConvertFromListxml(Models.Listxml.Sample item) + { + var sample = new Models.Internal.Sample + { + [Models.Internal.Sample.NameKey] = item.Name, + }; + return sample; + } + + /// + /// Convert from to + /// + public static Models.Internal.Slot ConvertFromListxml(Models.Listxml.Slot item) + { + var slot = new Models.Internal.Slot + { + [Models.Internal.Slot.NameKey] = item.Name, + }; + + if (item.SlotOption != null && item.SlotOption.Any()) + { + var slotOptions = new List(); + foreach (var slotOption in item.SlotOption) + { + slotOptions.Add(ConvertFromListxml(slotOption)); + } + slot[Models.Internal.Slot.SlotOptionKey] = slotOptions.ToArray(); + } + + return slot; + } + + /// + /// Convert from to + /// + public static Models.Internal.SlotOption ConvertFromListxml(Models.Listxml.SlotOption item) + { + var slotOption = new Models.Internal.SlotOption + { + [Models.Internal.SlotOption.NameKey] = item.Name, + [Models.Internal.SlotOption.DevNameKey] = item.DevName, + [Models.Internal.SlotOption.DefaultKey] = item.Default, + }; + return slotOption; + } + + /// + /// Convert from to + /// + public static Models.Internal.SoftwareList ConvertFromListxml(Models.Listxml.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; + } + + /// + /// Convert from to + /// + public static Models.Internal.Sound ConvertFromListxml(Models.Listxml.Sound item) + { + var sound = new Models.Internal.Sound + { + [Models.Internal.Sound.ChannelsKey] = item.Channels, + }; + return sound; + } + + /// + /// Convert from to + /// + public static Models.Internal.Video ConvertFromListxml(Models.Listxml.Video item) + { + var video = new Models.Internal.Video + { + [Models.Internal.Video.ScreenKey] = item.Screen, + [Models.Internal.Video.OrientationKey] = item.Orientation, + [Models.Internal.Video.WidthKey] = item.Width, + [Models.Internal.Video.HeightKey] = item.Height, + [Models.Internal.Video.AspectXKey] = item.AspectX, + [Models.Internal.Video.AspectYKey] = item.AspectY, + [Models.Internal.Video.RefreshKey] = item.Refresh, + }; + return video; + } + + #endregion + + #region Deserialize + + /// + /// Convert from to + /// + public static Models.Listxml.Adjuster ConvertToListxml(Models.Internal.Adjuster item) + { + var adjuster = new Models.Listxml.Adjuster + { + Name = item.ReadString(Models.Internal.Adjuster.NameKey), + Default = item.ReadString(Models.Internal.Adjuster.DefaultKey), + }; + + if (item.ContainsKey(Models.Internal.Adjuster.ConditionKey) && item[Models.Internal.Adjuster.ConditionKey] is Models.Internal.Condition condition) + adjuster.Condition = ConvertToListxml(condition); + + return adjuster; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Analog ConvertToListxml(Models.Internal.Analog item) + { + var analog = new Models.Listxml.Analog + { + Mask = item.ReadString(Models.Internal.Analog.MaskKey), + }; + return analog; + } + + /// + /// Convert from to + /// + public static Models.Listxml.BiosSet ConvertToListxml(Models.Internal.BiosSet item) + { + var biosset = new Models.Listxml.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.Listxml.Chip ConvertToListxml(Models.Internal.Chip item) + { + var chip = new Models.Listxml.Chip + { + Name = item.ReadString(Models.Internal.Chip.NameKey), + Tag = item.ReadString(Models.Internal.Chip.TagKey), + Type = item.ReadString(Models.Internal.Chip.TypeKey), + SoundOnly = item.ReadString(Models.Internal.Chip.SoundOnlyKey), + Clock = item.ReadString(Models.Internal.Chip.ClockKey), + }; + return chip; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Condition ConvertToListxml(Models.Internal.Condition item) + { + var condition = new Models.Listxml.Condition + { + Tag = item.ReadString(Models.Internal.Condition.TagKey), + Mask = item.ReadString(Models.Internal.Condition.MaskKey), + Relation = item.ReadString(Models.Internal.Condition.RelationKey), + Value = item.ReadString(Models.Internal.Condition.ValueKey), + }; + return condition; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Configuration ConvertToListxml(Models.Internal.Configuration item) + { + var configuration = new Models.Listxml.Configuration + { + Name = item.ReadString(Models.Internal.Configuration.NameKey), + Tag = item.ReadString(Models.Internal.Configuration.TagKey), + Mask = item.ReadString(Models.Internal.Configuration.MaskKey), + }; + + if (item.ContainsKey(Models.Internal.Configuration.ConditionKey) && item[Models.Internal.Configuration.ConditionKey] is Models.Internal.Condition condition) + configuration.Condition = ConvertToListxml(condition); + + if (item.ContainsKey(Models.Internal.Configuration.ConfLocationKey) && item[Models.Internal.Configuration.ConfLocationKey] is Models.Internal.ConfLocation[] confLocations) + { + var confLocationItems = new List(); + foreach (var confLocation in confLocations) + { + confLocationItems.Add(ConvertToListxml(confLocation)); + } + configuration.ConfLocation = confLocationItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Configuration.ConfSettingKey) && item[Models.Internal.Configuration.ConfSettingKey] is Models.Internal.ConfSetting[] confSettings) + { + var confSettingItems = new List(); + foreach (var confSetting in confSettings) + { + confSettingItems.Add(ConvertToListxml(confSetting)); + } + configuration.ConfSetting = confSettingItems.ToArray(); + } + + return configuration; + } + + /// + /// Convert from to + /// + public static Models.Listxml.ConfLocation ConvertToListxml(Models.Internal.ConfLocation item) + { + var confLocation = new Models.Listxml.ConfLocation + { + Name = item.ReadString(Models.Internal.ConfLocation.NameKey), + Number = item.ReadString(Models.Internal.ConfLocation.NumberKey), + Inverted = item.ReadString(Models.Internal.ConfLocation.InvertedKey), + }; + return confLocation; + } + + /// + /// Convert from to + /// + public static Models.Listxml.ConfSetting ConvertToListxml(Models.Internal.ConfSetting item) + { + var confSetting = new Models.Listxml.ConfSetting + { + Name = item.ReadString(Models.Internal.ConfSetting.NameKey), + Value = item.ReadString(Models.Internal.ConfSetting.ValueKey), + Default = item.ReadString(Models.Internal.ConfSetting.DefaultKey), + }; + + if (item.ContainsKey(Models.Internal.ConfSetting.ConditionKey) && item[Models.Internal.ConfSetting.ConditionKey] is Models.Internal.Condition condition) + confSetting.Condition = ConvertToListxml(condition); + + return confSetting; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Control ConvertToListxml(Models.Internal.Control item) + { + var control = new Models.Listxml.Control + { + Type = item.ReadString(Models.Internal.Control.TypeKey), + Player = item.ReadString(Models.Internal.Control.PlayerKey), + Buttons = item.ReadString(Models.Internal.Control.ButtonsKey), + ReqButtons = item.ReadString(Models.Internal.Control.ReqButtonsKey), + Minimum = item.ReadString(Models.Internal.Control.MinimumKey), + Maximum = item.ReadString(Models.Internal.Control.MaximumKey), + Sensitivity = item.ReadString(Models.Internal.Control.SensitivityKey), + KeyDelta = item.ReadString(Models.Internal.Control.KeyDeltaKey), + Reverse = item.ReadString(Models.Internal.Control.ReverseKey), + Ways = item.ReadString(Models.Internal.Control.WaysKey), + Ways2 = item.ReadString(Models.Internal.Control.Ways2Key), + Ways3 = item.ReadString(Models.Internal.Control.Ways3Key), + }; + return control; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Device ConvertToListxml(Models.Internal.Device item) + { + var device = new Models.Listxml.Device + { + Type = item.ReadString(Models.Internal.Device.TypeKey), + Tag = item.ReadString(Models.Internal.Device.TagKey), + FixedImage = item.ReadString(Models.Internal.Device.FixedImageKey), + Mandatory = item.ReadString(Models.Internal.Device.MandatoryKey), + Interface = item.ReadString(Models.Internal.Device.InterfaceKey), + }; + + if (item.ContainsKey(Models.Internal.Device.InstanceKey) && item[Models.Internal.Device.InstanceKey] is Models.Internal.Instance instance) + device.Instance = ConvertToListxml(instance); + + if (item.ContainsKey(Models.Internal.Device.ExtensionKey) && item[Models.Internal.Device.ExtensionKey] is Models.Internal.Extension[] extensions) + { + var extensionItems = new List(); + foreach (var extension in extensions) + { + extensionItems.Add(ConvertToListxml(extension)); + } + device.Extension = extensionItems.ToArray(); + } + + return device; + } + + /// + /// Convert from to + /// + public static Models.Listxml.DeviceRef ConvertToListxml(Models.Internal.DeviceRef item) + { + var deviceRef = new Models.Listxml.DeviceRef + { + Name = item.ReadString(Models.Internal.DeviceRef.NameKey), + }; + return deviceRef; + } + + /// + /// Convert from to + /// + public static Models.Listxml.DipLocation ConvertToListxml(Models.Internal.DipLocation item) + { + var dipLocation = new Models.Listxml.DipLocation + { + Name = item.ReadString(Models.Internal.DipLocation.NameKey), + Number = item.ReadString(Models.Internal.DipLocation.NumberKey), + Inverted = item.ReadString(Models.Internal.DipLocation.InvertedKey), + }; + return dipLocation; + } + + /// + /// Convert from to + /// + public static Models.Listxml.DipSwitch ConvertToListxml(Models.Internal.DipSwitch item) + { + var dipSwitch = new Models.Listxml.DipSwitch + { + Name = item.ReadString(Models.Internal.DipSwitch.NameKey), + Tag = item.ReadString(Models.Internal.DipSwitch.TagKey), + Mask = item.ReadString(Models.Internal.DipSwitch.MaskKey), + }; + + if (item.ContainsKey(Models.Internal.DipSwitch.ConditionKey) && item[Models.Internal.DipSwitch.ConditionKey] is Models.Internal.Condition condition) + dipSwitch.Condition = ConvertToListxml(condition); + + if (item.ContainsKey(Models.Internal.DipSwitch.DipLocationKey) && item[Models.Internal.DipSwitch.DipLocationKey] is Models.Internal.DipLocation[] dipLocations) + { + var dipLocationItems = new List(); + foreach (var dipLocation in dipLocations) + { + dipLocationItems.Add(ConvertToListxml(dipLocation)); + } + dipSwitch.DipLocation = dipLocationItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.DipSwitch.DipValueKey) && item[Models.Internal.DipSwitch.DipValueKey] is Models.Internal.DipValue[] dipValues) + { + var dipValueItems = new List(); + foreach (var dipValue in dipValues) + { + dipValueItems.Add(ConvertToListxml(dipValue)); + } + dipSwitch.DipValue = dipValueItems.ToArray(); + } + + return dipSwitch; + } + + /// + /// Convert from to + /// + public static Models.Listxml.DipValue ConvertToListxml(Models.Internal.DipValue item) + { + var dipValue = new Models.Listxml.DipValue + { + Name = item.ReadString(Models.Internal.DipValue.NameKey), + Value = item.ReadString(Models.Internal.DipValue.ValueKey), + Default = item.ReadString(Models.Internal.DipValue.DefaultKey), + }; + + if (item.ContainsKey(Models.Internal.DipValue.ConditionKey) && item[Models.Internal.DipValue.ConditionKey] is Models.Internal.Condition condition) + dipValue.Condition = ConvertToListxml(condition); + + return dipValue; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Disk ConvertToListxml(Models.Internal.Disk item) + { + var disk = new Models.Listxml.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), + Region = item.ReadString(Models.Internal.Disk.RegionKey), + Index = item.ReadString(Models.Internal.Disk.IndexKey), + Writable = item.ReadString(Models.Internal.Disk.WritableKey), + Status = item.ReadString(Models.Internal.Disk.StatusKey), + Optional = item.ReadString(Models.Internal.Disk.OptionalKey), + }; + return disk; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Display ConvertToListxml(Models.Internal.Display item) + { + var display = new Models.Listxml.Display + { + Tag = item.ReadString(Models.Internal.Display.TagKey), + Type = item.ReadString(Models.Internal.Display.TypeKey), + Rotate = item.ReadString(Models.Internal.Display.RotateKey), + FlipX = item.ReadString(Models.Internal.Display.FlipXKey), + Width = item.ReadString(Models.Internal.Display.WidthKey), + Height = item.ReadString(Models.Internal.Display.HeightKey), + Refresh = item.ReadString(Models.Internal.Display.RefreshKey), + PixClock = item.ReadString(Models.Internal.Display.PixClockKey), + HTotal = item.ReadString(Models.Internal.Display.HTotalKey), + HBEnd = item.ReadString(Models.Internal.Display.HBEndKey), + HBStart = item.ReadString(Models.Internal.Display.HBStartKey), + VTotal = item.ReadString(Models.Internal.Display.VTotalKey), + VBEnd = item.ReadString(Models.Internal.Display.VBEndKey), + VBStart = item.ReadString(Models.Internal.Display.VBStartKey), + }; + return display; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Driver ConvertToListxml(Models.Internal.Driver item) + { + var driver = new Models.Listxml.Driver + { + Status = item.ReadString(Models.Internal.Driver.StatusKey), + Color = item.ReadString(Models.Internal.Driver.ColorKey), + Sound = item.ReadString(Models.Internal.Driver.SoundKey), + PaletteSize = item.ReadString(Models.Internal.Driver.PaletteSizeKey), + 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.Listxml.Extension ConvertToListxml(Models.Internal.Extension item) + { + var extension = new Models.Listxml.Extension + { + Name = item.ReadString(Models.Internal.Extension.NameKey), + }; + return extension; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Feature ConvertToListxml(Models.Internal.Feature item) + { + var feature = new Models.Listxml.Feature + { + Type = item.ReadString(Models.Internal.Feature.TypeKey), + Status = item.ReadString(Models.Internal.Feature.StatusKey), + Overall = item.ReadString(Models.Internal.Feature.OverallKey), + }; + return feature; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Input ConvertToListxml(Models.Internal.Input item) + { + var input = new Models.Listxml.Input + { + Service = item.ReadString(Models.Internal.Input.ServiceKey), + Tilt = item.ReadString(Models.Internal.Input.TiltKey), + Players = item.ReadString(Models.Internal.Input.PlayersKey), + ControlAttr = item.ReadString(Models.Internal.Input.ControlKey), + Buttons = item.ReadString(Models.Internal.Input.ButtonsKey), + Coins = item.ReadString(Models.Internal.Input.CoinsKey), + }; + + if (item.ContainsKey(Models.Internal.Input.ControlKey) && item[Models.Internal.Input.ControlKey] is Models.Internal.Control[] controls) + { + var controlItems = new List(); + foreach (var control in controls) + { + controlItems.Add(ConvertToListxml(control)); + } + input.Control = controlItems.ToArray(); + } + + return input; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Instance ConvertToListxml(Models.Internal.Instance item) + { + var instance = new Models.Listxml.Instance + { + Name = item.ReadString(Models.Internal.Instance.NameKey), + BriefName = item.ReadString(Models.Internal.Instance.BriefNameKey), + }; + return instance; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Port ConvertToListxml(Models.Internal.Port item) + { + var input = new Models.Listxml.Port + { + Tag = item.ReadString(Models.Internal.Port.TagKey), + }; + + if (item.ContainsKey(Models.Internal.Port.AnalogKey) && item[Models.Internal.Port.AnalogKey] is Models.Internal.Analog[] analogs) + { + var analogItems = new List(); + foreach (var analog in analogs) + { + analogItems.Add(ConvertToListxml(analog)); + } + input.Analog = analogItems.ToArray(); + } + + return input; + } + + /// + /// Convert from to + /// + public static Models.Listxml.RamOption ConvertToListxml(Models.Internal.RamOption item) + { + var ramOption = new Models.Listxml.RamOption + { + Name = item.ReadString(Models.Internal.RamOption.NameKey), + Default = item.ReadString(Models.Internal.RamOption.DefaultKey), + }; + return ramOption; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Rom ConvertToListxml(Models.Internal.Rom item) + { + var rom = new Models.Listxml.Rom + { + Name = item.ReadString(Models.Internal.Rom.NameKey), + Bios = item.ReadString(Models.Internal.Rom.BiosKey), + Size = item.ReadString(Models.Internal.Rom.SizeKey), + CRC = item.ReadString(Models.Internal.Rom.CRCKey), + SHA1 = item.ReadString(Models.Internal.Rom.SHA1Key), + Merge = item.ReadString(Models.Internal.Rom.MergeKey), + Region = item.ReadString(Models.Internal.Rom.RegionKey), + Offset = item.ReadString(Models.Internal.Rom.OffsetKey), + Status = item.ReadString(Models.Internal.Rom.StatusKey), + Optional = item.ReadString(Models.Internal.Rom.OptionalKey), + Dispose = item.ReadString(Models.Internal.Rom.DisposeKey), + SoundOnly = item.ReadString(Models.Internal.Rom.SoundOnlyKey), + }; + return rom; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Sample ConvertToListxml(Models.Internal.Sample item) + { + var sample = new Models.Listxml.Sample + { + Name = item.ReadString(Models.Internal.Sample.NameKey), + }; + return sample; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Slot ConvertToListxml(Models.Internal.Slot item) + { + var slot = new Models.Listxml.Slot + { + Name = item.ReadString(Models.Internal.Slot.NameKey), + }; + + if (item.ContainsKey(Models.Internal.Slot.SlotOptionKey) && item[Models.Internal.Slot.SlotOptionKey] is Models.Internal.SlotOption[] slotOptions) + { + var slotOptionItems = new List(); + foreach (var slotOption in slotOptions) + { + slotOptionItems.Add(ConvertToListxml(slotOption)); + } + slot.SlotOption = slotOptionItems.ToArray(); + } + + return slot; + } + + /// + /// Convert from to + /// + public static Models.Listxml.SlotOption ConvertToListxml(Models.Internal.SlotOption item) + { + var slotOption = new Models.Listxml.SlotOption + { + Name = item.ReadString(Models.Internal.SlotOption.NameKey), + DevName = item.ReadString(Models.Internal.SlotOption.DevNameKey), + Default = item.ReadString(Models.Internal.SlotOption.DefaultKey), + }; + return slotOption; + } + + /// + /// Convert from to + /// + public static Models.Listxml.SoftwareList ConvertToListxml(Models.Internal.SoftwareList item) + { + var softwareList = new Models.Listxml.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; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Sound ConvertToListxml(Models.Internal.Sound item) + { + var sound = new Models.Listxml.Sound + { + Channels = item.ReadString(Models.Internal.Sound.ChannelsKey), + }; + return sound; + } + + /// + /// Convert from to + /// + public static Models.Listxml.Video ConvertToListxml(Models.Internal.Video item) + { + var video = new Models.Listxml.Video + { + Screen = item.ReadString(Models.Internal.Video.ScreenKey), + Orientation = item.ReadString(Models.Internal.Video.OrientationKey), + Width = item.ReadString(Models.Internal.Video.WidthKey), + Height = item.ReadString(Models.Internal.Video.HeightKey), + AspectX = item.ReadString(Models.Internal.Video.AspectXKey), + AspectY = item.ReadString(Models.Internal.Video.AspectYKey), + Refresh = item.ReadString(Models.Internal.Video.RefreshKey), + }; + return video; + } + + #endregion + } +} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.Logiqx.cs b/SabreTools.Serialization/Internal.Logiqx.cs new file mode 100644 index 00000000..848a3a02 --- /dev/null +++ b/SabreTools.Serialization/Internal.Logiqx.cs @@ -0,0 +1,340 @@ +namespace SabreTools.Serialization +{ + /// + /// Serializer for Logiqx models to internal structure + /// + public partial class Internal + { + #region Serialize + + /// + /// 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 Logiqx + + /// + /// 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 + } +} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.OfflineList.cs b/SabreTools.Serialization/Internal.OfflineList.cs new file mode 100644 index 00000000..e0a81f46 --- /dev/null +++ b/SabreTools.Serialization/Internal.OfflineList.cs @@ -0,0 +1,42 @@ +namespace SabreTools.Serialization +{ + /// + /// Serializer for OfflineList models to internal structure + /// + public partial class Internal + { + #region Serialize + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromOfflineList(Models.OfflineList.FileRomCRC item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.ExtensionKey] = item.Extension, + [Models.Internal.Rom.CRCKey] = item.Content, + }; + return rom; + } + + #endregion + + #region Deserialize + + /// + /// Convert from to + /// + public static Models.OfflineList.FileRomCRC ConvertToOfflineList(Models.Internal.Rom item) + { + var fileRomCRC = new Models.OfflineList.FileRomCRC + { + Extension = item.ReadString(Models.Internal.Rom.ExtensionKey), + Content = item.ReadString(Models.Internal.Rom.CRCKey), + }; + return fileRomCRC; + } + + #endregion + } +} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.OpenMSX.cs b/SabreTools.Serialization/Internal.OpenMSX.cs new file mode 100644 index 00000000..9df5bd9a --- /dev/null +++ b/SabreTools.Serialization/Internal.OpenMSX.cs @@ -0,0 +1,156 @@ +namespace SabreTools.Serialization +{ + /// + /// Serializer for OpenMSX models to internal structure + /// + public partial class Internal + { + #region Serialize + + /// + /// Convert from to + /// + public static Models.Internal.Dump ConvertFromOpenMSX(Models.OpenMSX.Dump item) + { + var dump = new Models.Internal.Dump(); + + if (item.Original != null) + dump[Models.Internal.Dump.OriginalKey] = ConvertFromOpenMSX(item.Original); + + switch (item.Rom) + { + case Models.OpenMSX.Rom rom: + dump[Models.Internal.Dump.RomKey] = ConvertFromOpenMSX(rom); + break; + + case Models.OpenMSX.MegaRom megaRom: + dump[Models.Internal.Dump.MegaRomKey] = ConvertFromOpenMSX(megaRom); + break; + + case Models.OpenMSX.SCCPlusCart sccPlusCart: + dump[Models.Internal.Dump.SCCPlusCartKey] = ConvertFromOpenMSX(sccPlusCart); + break; + } + + return dump; + } + + /// + /// Convert from to + /// + public static Models.Internal.Original ConvertFromOpenMSX(Models.OpenMSX.Original item) + { + var original = new Models.Internal.Original + { + [Models.Internal.Original.ValueKey] = item.Value, + [Models.Internal.Original.ContentKey] = item.Content, + }; + return original; + } + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromOpenMSX(Models.OpenMSX.RomBase item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.StartKey] = item.Start, + [Models.Internal.Rom.TypeKey] = item.Type, + [Models.Internal.Rom.SHA1Key] = item.Hash, + [Models.Internal.Rom.RemarkKey] = item.Remark, + }; + return rom; + } + + #endregion + + #region Deserialize + + /// + /// Convert from to + /// + public static Models.OpenMSX.Dump ConvertToOpenMSX(Models.Internal.Dump item) + { + var dump = new Models.OpenMSX.Dump(); + + if (item.ContainsKey(Models.Internal.Dump.OriginalKey) && item[Models.Internal.Dump.OriginalKey] is Models.Internal.Original original) + dump.Original = ConvertToOpenMSX(original); + + if (item.ContainsKey(Models.Internal.Dump.RomKey) && item[Models.Internal.Dump.RomKey] is Models.Internal.Rom rom) + { + dump.Rom = ConvertToOpenMSXRom(rom); + } + else if (item.ContainsKey(Models.Internal.Dump.MegaRomKey) && item[Models.Internal.Dump.MegaRomKey] is Models.Internal.Rom megaRom) + { + dump.Rom = ConvertToOpenMSXMegaRom(megaRom); + } + else if (item.ContainsKey(Models.Internal.Dump.SCCPlusCartKey) && item[Models.Internal.Dump.SCCPlusCartKey] is Models.Internal.Rom sccPlusCart) + { + dump.Rom = ConvertToOpenMSXSCCPlusCart(sccPlusCart); + } + + return dump; + } + + /// + /// Convert from to + /// + public static Models.OpenMSX.MegaRom ConvertToOpenMSXMegaRom(Models.Internal.Rom item) + { + var megaRom = new Models.OpenMSX.MegaRom + { + Start = item.ReadString(Models.Internal.Rom.StartKey), + Type = item.ReadString(Models.Internal.Rom.TypeKey), + Hash = item.ReadString(Models.Internal.Rom.SHA1Key), + Remark = item.ReadString(Models.Internal.Rom.RemarkKey), + }; + return megaRom; + } + + /// + /// Convert from to + /// + public static Models.OpenMSX.Original ConvertToOpenMSX(Models.Internal.Original item) + { + var original = new Models.OpenMSX.Original + { + Value = item.ReadString(Models.Internal.Original.ValueKey), + Content = item.ReadString(Models.Internal.Original.ContentKey), + }; + return original; + } + + /// + /// Convert from to + /// + public static Models.OpenMSX.Rom ConvertToOpenMSXRom(Models.Internal.Rom item) + { + var rom = new Models.OpenMSX.Rom + { + Start = item.ReadString(Models.Internal.Rom.StartKey), + Type = item.ReadString(Models.Internal.Rom.TypeKey), + Hash = item.ReadString(Models.Internal.Rom.SHA1Key), + Remark = item.ReadString(Models.Internal.Rom.RemarkKey), + }; + return rom; + } + + /// + /// Convert from to + /// + public static Models.OpenMSX.SCCPlusCart ConvertToOpenMSXSCCPlusCart(Models.Internal.Rom item) + { + var sccPlusCart = new Models.OpenMSX.SCCPlusCart + { + Start = item.ReadString(Models.Internal.Rom.StartKey), + Type = item.ReadString(Models.Internal.Rom.TypeKey), + Hash = item.ReadString(Models.Internal.Rom.SHA1Key), + Remark = item.ReadString(Models.Internal.Rom.RemarkKey), + }; + return sccPlusCart; + } + + #endregion + } +} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.RomCenter.cs b/SabreTools.Serialization/Internal.RomCenter.cs new file mode 100644 index 00000000..acf7491d --- /dev/null +++ b/SabreTools.Serialization/Internal.RomCenter.cs @@ -0,0 +1,46 @@ +namespace SabreTools.Serialization +{ + /// + /// Serializer for RomCenter models to internal structure + /// + public partial class Internal + { + #region Serialize + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromRomCenter(Models.RomCenter.Rom item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.NameKey] = item.RomName, + [Models.Internal.Rom.CRCKey] = item.RomCRC, + [Models.Internal.Rom.SizeKey] = item.RomSize, + [Models.Internal.Rom.MergeKey] = item.MergeName, + }; + return rom; + } + + #endregion + + #region Deserialize + + /// + /// Convert from to + /// + public static Models.RomCenter.Rom ConvertToRomCenter(Models.Internal.Rom item) + { + var row = new Models.RomCenter.Rom + { + RomName = item.ReadString(Models.Internal.Rom.NameKey), + RomCRC = item.ReadString(Models.Internal.Rom.CRCKey), + RomSize = item.ReadString(Models.Internal.Rom.SizeKey), + MergeName = item.ReadString(Models.Internal.Rom.MergeKey), + }; + return row; + } + + #endregion + } +} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.SeparatedValue.cs b/SabreTools.Serialization/Internal.SeparatedValue.cs new file mode 100644 index 00000000..3086ba90 --- /dev/null +++ b/SabreTools.Serialization/Internal.SeparatedValue.cs @@ -0,0 +1,110 @@ +namespace SabreTools.Serialization +{ + /// + /// Serializer for SeparatedValue models to internal structure + /// + public partial class Internal + { + #region Serialize + + /// + /// Convert from to + /// + public static Models.Internal.DatItem? ConvertFromSeparatedValue(Models.SeparatedValue.Row item) + { + return item.Type switch + { + "disk" => new Models.Internal.Disk + { + [Models.Internal.Disk.NameKey] = item.DiskName, + [Models.Internal.Disk.MD5Key] = item.MD5, + [Models.Internal.Disk.SHA1Key] = item.SHA1, + [Models.Internal.Disk.StatusKey] = item.Status, + }, + "media" => new Models.Internal.Media + { + [Models.Internal.Media.NameKey] = item.DiskName, + [Models.Internal.Media.MD5Key] = item.MD5, + [Models.Internal.Media.SHA1Key] = item.SHA1, + [Models.Internal.Media.SHA256Key] = item.SHA256, + [Models.Internal.Media.SpamSumKey] = item.SpamSum, + }, + "rom" => new Models.Internal.Rom + { + [Models.Internal.Rom.NameKey] = item.RomName, + [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.StatusKey] = item.Status, + }, + _ => null, + }; + } + + #endregion + + #region Deserialize + + /// + /// Convert from to + /// + public static Models.SeparatedValue.Row ConvertToSeparatedValue(Models.Internal.Disk item) + { + var row = new Models.SeparatedValue.Row + { + Type = "disk", + DiskName = item.ReadString(Models.Internal.Disk.NameKey), + MD5 = item.ReadString(Models.Internal.Disk.MD5Key), + SHA1 = item.ReadString(Models.Internal.Disk.SHA1Key), + Status = item.ReadString(Models.Internal.Disk.StatusKey), + }; + return row; + } + + /// + /// Convert from to + /// + public static Models.SeparatedValue.Row ConvertToSeparatedValue(Models.Internal.Media item) + { + var row = new Models.SeparatedValue.Row + { + Type = "media", + DiskName = 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 row; + } + + /// + /// Convert from to + /// + public static Models.SeparatedValue.Row ConvertToSeparatedValue(Models.Internal.Rom item) + { + var row = new Models.SeparatedValue.Row + { + Type = "rom", + RomName = 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), + Status = item.ReadString(Models.Internal.Rom.StatusKey), + }; + return row; + } + + #endregion + } +} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.Serializer.cs b/SabreTools.Serialization/Internal.Serializer.cs deleted file mode 100644 index f53ad8e8..00000000 --- a/SabreTools.Serialization/Internal.Serializer.cs +++ /dev/null @@ -1,1597 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace SabreTools.Serialization -{ - /// - /// Serializer for all relevant models to internal structure - /// - public partial class Internal - { - #region ArchiveDotOrg - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromArchiveDotOrg(Models.ArchiveDotOrg.File item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.NameKey] = item.Name, - [Models.Internal.Rom.SourceKey] = item.Source, - [Models.Internal.Rom.BitTorrentMagnetHashKey] = item.BitTorrentMagnetHash, - [Models.Internal.Rom.LastModifiedTimeKey] = item.LastModifiedTime, - [Models.Internal.Rom.SizeKey] = item.Size, - [Models.Internal.Rom.MD5Key] = item.MD5, - [Models.Internal.Rom.CRCKey] = item.CRC32, - [Models.Internal.Rom.SHA1Key] = item.SHA1, - [Models.Internal.Rom.FileCountKey] = item.FileCount, - [Models.Internal.Rom.FormatKey] = item.Format, - [Models.Internal.Rom.OriginalKey] = item.Original, - [Models.Internal.Rom.SummationKey] = item.Summation, - [Models.Internal.Rom.MatrixNumberKey] = item.MatrixNumber, - [Models.Internal.Rom.CollectionCatalogNumberKey] = item.CollectionCatalogNumber, - [Models.Internal.Rom.PublisherKey] = item.Publisher, - [Models.Internal.Rom.CommentKey] = item.Comment, - - [Models.Internal.Rom.ASRDetectedLangKey] = item.ASRDetectedLang, - [Models.Internal.Rom.ASRDetectedLangConfKey] = item.ASRDetectedLangConf, - [Models.Internal.Rom.ASRTranscribedLangKey] = item.ASRTranscribedLang, - [Models.Internal.Rom.WhisperASRModuleVersionKey] = item.WhisperASRModuleVersion, - [Models.Internal.Rom.WhisperModelHashKey] = item.WhisperModelHash, - [Models.Internal.Rom.WhisperModelNameKey] = item.WhisperModelName, - [Models.Internal.Rom.WhisperVersionKey] = item.WhisperVersion, - - [Models.Internal.Rom.ClothCoverDetectionModuleVersionKey] = item.ClothCoverDetectionModuleVersion, - [Models.Internal.Rom.hOCRCharToWordhOCRVersionKey] = item.hOCRCharToWordhOCRVersion, - [Models.Internal.Rom.hOCRCharToWordModuleVersionKey] = item.hOCRCharToWordModuleVersion, - [Models.Internal.Rom.hOCRFtsTexthOCRVersionKey] = item.hOCRFtsTexthOCRVersion, - [Models.Internal.Rom.hOCRFtsTextModuleVersionKey] = item.hOCRFtsTextModuleVersion, - [Models.Internal.Rom.hOCRPageIndexhOCRVersionKey] = item.hOCRPageIndexhOCRVersion, - [Models.Internal.Rom.hOCRPageIndexModuleVersionKey] = item.hOCRPageIndexModuleVersion, - [Models.Internal.Rom.TesseractOCRKey] = item.TesseractOCR, - [Models.Internal.Rom.TesseractOCRConvertedKey] = item.TesseractOCRConverted, - [Models.Internal.Rom.TesseractOCRDetectedLangKey] = item.TesseractOCRDetectedLang, - [Models.Internal.Rom.TesseractOCRDetectedLangConfKey] = item.TesseractOCRDetectedLangConf, - [Models.Internal.Rom.TesseractOCRDetectedScriptKey] = item.TesseractOCRDetectedScript, - [Models.Internal.Rom.TesseractOCRDetectedScriptConfKey] = item.TesseractOCRDetectedScriptConf, - [Models.Internal.Rom.TesseractOCRModuleVersionKey] = item.TesseractOCRModuleVersion, - [Models.Internal.Rom.TesseractOCRParametersKey] = item.TesseractOCRParameters, - [Models.Internal.Rom.PDFModuleVersionKey] = item.PDFModuleVersion, - [Models.Internal.Rom.WordConfidenceInterval0To10Key] = item.WordConfidenceInterval0To10, - [Models.Internal.Rom.WordConfidenceInterval11To20Key] = item.WordConfidenceInterval11To20, - [Models.Internal.Rom.WordConfidenceInterval21To30Key] = item.WordConfidenceInterval21To30, - [Models.Internal.Rom.WordConfidenceInterval31To40Key] = item.WordConfidenceInterval31To40, - [Models.Internal.Rom.WordConfidenceInterval41To50Key] = item.WordConfidenceInterval41To50, - [Models.Internal.Rom.WordConfidenceInterval51To60Key] = item.WordConfidenceInterval51To60, - [Models.Internal.Rom.WordConfidenceInterval61To70Key] = item.WordConfidenceInterval61To70, - [Models.Internal.Rom.WordConfidenceInterval71To80Key] = item.WordConfidenceInterval71To80, - [Models.Internal.Rom.WordConfidenceInterval81To90Key] = item.WordConfidenceInterval81To90, - [Models.Internal.Rom.WordConfidenceInterval91To100Key] = item.WordConfidenceInterval91To100, - - [Models.Internal.Rom.AlbumKey] = item.Album, - [Models.Internal.Rom.ArtistKey] = item.Artist, - [Models.Internal.Rom.BitrateKey] = item.Bitrate, - [Models.Internal.Rom.CreatorKey] = item.Creator, - [Models.Internal.Rom.HeightKey] = item.Height, - [Models.Internal.Rom.LengthKey] = item.Length, - [Models.Internal.Rom.PreviewImageKey] = item.PreviewImage, - [Models.Internal.Rom.RotationKey] = item.Rotation, - [Models.Internal.Rom.TitleKey] = item.Title, - [Models.Internal.Rom.TrackKey] = item.Track, - [Models.Internal.Rom.WidthKey] = item.Width, - }; - return rom; - } - - #endregion - - #region AttractMode - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromAttractMode(Models.AttractMode.Row item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.NameKey] = item.Title, - [Models.Internal.Rom.AltRomnameKey] = item.AltRomname, - [Models.Internal.Rom.AltTitleKey] = item.AltTitle, - }; - return rom; - } - - #endregion - - #region ClrMamePro - - /// - /// Convert from to - /// - public static Models.Internal.Archive ConvertFromClrMamePro(Models.ClrMamePro.Archive item) - { - var archive = new Models.Internal.Archive - { - [Models.Internal.Archive.NameKey] = item.Name, - }; - return archive; - } - - /// - /// Convert from to - /// - public static Models.Internal.BiosSet ConvertFromClrMamePro(Models.ClrMamePro.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.Chip ConvertFromClrMamePro(Models.ClrMamePro.Chip item) - { - var chip = new Models.Internal.Chip - { - [Models.Internal.Chip.ChipTypeKey] = item.Type, - [Models.Internal.Chip.NameKey] = item.Name, - [Models.Internal.Chip.FlagsKey] = item.Flags, - [Models.Internal.Chip.ClockKey] = item.Clock, - }; - return chip; - } - - /// - /// Convert from to - /// - public static Models.Internal.DipSwitch ConvertFromClrMamePro(Models.ClrMamePro.DipSwitch item) - { - var dipswitch = new Models.Internal.DipSwitch - { - [Models.Internal.DipSwitch.NameKey] = item.Name, - [Models.Internal.DipSwitch.EntryKey] = item.Entry, - [Models.Internal.DipSwitch.DefaultKey] = item.Default, - }; - return dipswitch; - } - - /// - /// Convert from to - /// - public static Models.Internal.Disk ConvertFromClrMamePro(Models.ClrMamePro.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.FlagsKey] = item.Flags, - }; - return disk; - } - - /// - /// Convert from to - /// - public static Models.Internal.Driver ConvertFromClrMamePro(Models.ClrMamePro.Driver item) - { - var driver = new Models.Internal.Driver - { - [Models.Internal.Driver.StatusKey] = item.Status, - [Models.Internal.Driver.ColorKey] = item.Color, - [Models.Internal.Driver.SoundKey] = item.Sound, - [Models.Internal.Driver.PaletteSizeKey] = item.PaletteSize, - [Models.Internal.Driver.BlitKey] = item.Blit, - }; - return driver; - } - - /// - /// Convert from to - /// - public static Models.Internal.Input ConvertFromClrMamePro(Models.ClrMamePro.Input item) - { - var input = new Models.Internal.Input - { - [Models.Internal.Input.PlayersKey] = item.Players, - [Models.Internal.Input.ControlKey] = item.Control, - [Models.Internal.Input.ButtonsKey] = item.Buttons, - [Models.Internal.Input.CoinsKey] = item.Coins, - [Models.Internal.Input.TiltKey] = item.Tilt, - [Models.Internal.Input.ServiceKey] = item.Service, - }; - return input; - } - - /// - /// Convert from to - /// - public static Models.Internal.Media ConvertFromClrMamePro(Models.ClrMamePro.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 ConvertFromClrMamePro(Models.ClrMamePro.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 ConvertFromClrMamePro(Models.ClrMamePro.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.RegionKey] = item.Region, - [Models.Internal.Rom.FlagsKey] = item.Flags, - [Models.Internal.Rom.OffsetKey] = item.Offs, - [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 ConvertFromClrMamePro(Models.ClrMamePro.Sample item) - { - var sample = new Models.Internal.Sample - { - [Models.Internal.Sample.NameKey] = item.Name, - }; - return sample; - } - - /// - /// Convert from to - /// - public static Models.Internal.Sound ConvertFromClrMamePro(Models.ClrMamePro.Sound item) - { - var sound = new Models.Internal.Sound - { - [Models.Internal.Sound.ChannelsKey] = item.Channels, - }; - return sound; - } - - /// - /// Convert from to - /// - public static Models.Internal.Video ConvertFromClrMamePro(Models.ClrMamePro.Video item) - { - var video = new Models.Internal.Video - { - [Models.Internal.Video.ScreenKey] = item.Screen, - [Models.Internal.Video.OrientationKey] = item.Orientation, - [Models.Internal.Video.WidthKey] = item.X, - [Models.Internal.Video.HeightKey] = item.Y, - [Models.Internal.Video.AspectXKey] = item.AspectX, - [Models.Internal.Video.AspectYKey] = item.AspectY, - [Models.Internal.Video.RefreshKey] = item.Freq, - }; - return video; - } - - #endregion - - #region DosCenter - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromDosCenter(Models.DosCenter.File 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.DateKey] = item.Date, - }; - return rom; - } - - #endregion - - #region EverdriveSMDB - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromEverdriveSMDB(Models.EverdriveSMDB.Row item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.SHA256Key] = item.SHA256, - [Models.Internal.Rom.NameKey] = item.Name, - [Models.Internal.Rom.SHA1Key] = item.SHA1, - [Models.Internal.Rom.MD5Key] = item.MD5, - [Models.Internal.Rom.CRCKey] = item.CRC32, - [Models.Internal.Rom.SizeKey] = item.Size, - }; - return rom; - } - - #endregion - - #region Hashfile - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromMD5(Models.Hashfile.MD5 item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.MD5Key] = item.Hash, - [Models.Internal.Rom.NameKey] = item.File, - }; - return rom; - } - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromSFV(Models.Hashfile.SFV item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.NameKey] = item.File, - [Models.Internal.Rom.CRCKey] = item.Hash, - }; - return rom; - } - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromSHA1(Models.Hashfile.SHA1 item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.SHA1Key] = item.Hash, - [Models.Internal.Rom.NameKey] = item.File, - }; - return rom; - } - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromSHA256(Models.Hashfile.SHA256 item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.SHA256Key] = item.Hash, - [Models.Internal.Rom.NameKey] = item.File, - }; - return rom; - } - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromSHA384(Models.Hashfile.SHA384 item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.SHA384Key] = item.Hash, - [Models.Internal.Rom.NameKey] = item.File, - }; - return rom; - } - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromSHA512(Models.Hashfile.SHA512 item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.SHA512Key] = item.Hash, - [Models.Internal.Rom.NameKey] = item.File, - }; - return rom; - } - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromSpamSum(Models.Hashfile.SpamSum item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.SpamSumKey] = item.Hash, - [Models.Internal.Rom.NameKey] = item.File, - }; - return rom; - } - - #endregion - - #region Listrom - - /// - /// Convert from to - /// - public static Models.Internal.DatItem ConvertFromListrom(Models.Listrom.Row item) - { - if (item.Size == null) - { - var disk = new Models.Internal.Disk - { - [Models.Internal.Disk.NameKey] = item.Name, - [Models.Internal.Disk.MD5Key] = item.MD5, - [Models.Internal.Disk.SHA1Key] = item.SHA1, - }; - - if (item.NoGoodDumpKnown) - disk[Models.Internal.Disk.StatusKey] = "nodump"; - else if (item.Bad) - disk[Models.Internal.Disk.StatusKey] = "baddump"; - - return disk; - } - else - { - 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.SHA1Key] = item.SHA1, - }; - - if (item.NoGoodDumpKnown) - rom[Models.Internal.Rom.StatusKey] = "nodump"; - else if (item.Bad) - rom[Models.Internal.Rom.StatusKey] = "baddump"; - - return rom; - } - } - - #endregion - - #region Listxml - - /// - /// Convert from to - /// - public static Models.Internal.Adjuster ConvertFromListxml(Models.Listxml.Adjuster item) - { - var adjuster = new Models.Internal.Adjuster - { - [Models.Internal.Adjuster.NameKey] = item.Name, - [Models.Internal.Adjuster.DefaultKey] = item.Default, - }; - - if (item.Condition != null) - adjuster[Models.Internal.Adjuster.ConditionKey] = ConvertFromListxml(item.Condition); - - return adjuster; - } - - /// - /// Convert from to - /// - public static Models.Internal.Analog ConvertFromListxml(Models.Listxml.Analog item) - { - var analog = new Models.Internal.Analog - { - [Models.Internal.Analog.MaskKey] = item.Mask, - }; - return analog; - } - - /// - /// Convert from to - /// - public static Models.Internal.BiosSet ConvertFromListxml(Models.Listxml.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.Chip ConvertFromListxml(Models.Listxml.Chip item) - { - var chip = new Models.Internal.Chip - { - [Models.Internal.Chip.NameKey] = item.Name, - [Models.Internal.Chip.TagKey] = item.Tag, - [Models.Internal.Chip.TypeKey] = item.Type, - [Models.Internal.Chip.SoundOnlyKey] = item.SoundOnly, - [Models.Internal.Chip.ClockKey] = item.Clock, - }; - return chip; - } - - /// - /// Convert from to - /// - public static Models.Internal.Condition ConvertFromListxml(Models.Listxml.Condition item) - { - var condition = new Models.Internal.Condition - { - [Models.Internal.Condition.TagKey] = item.Tag, - [Models.Internal.Condition.MaskKey] = item.Mask, - [Models.Internal.Condition.RelationKey] = item.Relation, - [Models.Internal.Condition.ValueKey] = item.Value, - }; - return condition; - } - - /// - /// Convert from to - /// - public static Models.Internal.Configuration ConvertFromListxml(Models.Listxml.Configuration item) - { - var configuration = new Models.Internal.Configuration - { - [Models.Internal.Configuration.NameKey] = item.Name, - [Models.Internal.Configuration.TagKey] = item.Tag, - [Models.Internal.Configuration.MaskKey] = item.Mask, - }; - - if (item.Condition != null) - configuration[Models.Internal.Configuration.ConditionKey] = ConvertFromListxml(item.Condition); - - if (item.ConfLocation != null && item.ConfLocation.Any()) - { - var confLocations = new List(); - foreach (var confLocation in item.ConfLocation) - { - confLocations.Add(ConvertFromListxml(confLocation)); - } - configuration[Models.Internal.Configuration.ConfLocationKey] = confLocations.ToArray(); - } - - if (item.ConfSetting != null && item.ConfSetting.Any()) - { - var confSettings = new List(); - foreach (var confSetting in item.ConfSetting) - { - confSettings.Add(ConvertFromListxml(confSetting)); - } - configuration[Models.Internal.Configuration.ConfSettingKey] = confSettings.ToArray(); - } - - return configuration; - } - - /// - /// Convert from to - /// - public static Models.Internal.ConfLocation ConvertFromListxml(Models.Listxml.ConfLocation item) - { - var confLocation = new Models.Internal.ConfLocation - { - [Models.Internal.ConfLocation.NameKey] = item.Name, - [Models.Internal.ConfLocation.NumberKey] = item.Number, - [Models.Internal.ConfLocation.InvertedKey] = item.Inverted, - }; - return confLocation; - } - - /// - /// Convert from to - /// - public static Models.Internal.ConfSetting ConvertFromListxml(Models.Listxml.ConfSetting item) - { - var confSetting = new Models.Internal.ConfSetting - { - [Models.Internal.ConfSetting.NameKey] = item.Name, - [Models.Internal.ConfSetting.ValueKey] = item.Value, - [Models.Internal.ConfSetting.DefaultKey] = item.Default, - }; - - if (item.Condition != null) - confSetting[Models.Internal.ConfSetting.ConditionKey] = ConvertFromListxml(item.Condition); - - return confSetting; - } - - /// - /// Convert from to - /// - public static Models.Internal.Control ConvertFromListxml(Models.Listxml.Control item) - { - var control = new Models.Internal.Control - { - [Models.Internal.Control.TypeKey] = item.Type, - [Models.Internal.Control.PlayerKey] = item.Player, - [Models.Internal.Control.ButtonsKey] = item.Buttons, - [Models.Internal.Control.ReqButtonsKey] = item.ReqButtons, - [Models.Internal.Control.MinimumKey] = item.Minimum, - [Models.Internal.Control.MaximumKey] = item.Maximum, - [Models.Internal.Control.SensitivityKey] = item.Sensitivity, - [Models.Internal.Control.KeyDeltaKey] = item.KeyDelta, - [Models.Internal.Control.ReverseKey] = item.Reverse, - [Models.Internal.Control.WaysKey] = item.Ways, - [Models.Internal.Control.Ways2Key] = item.Ways2, - [Models.Internal.Control.Ways3Key] = item.Ways3, - }; - return control; - } - - /// - /// Convert from to - /// - public static Models.Internal.Device ConvertFromListxml(Models.Listxml.Device item) - { - var device = new Models.Internal.Device - { - [Models.Internal.Device.TypeKey] = item.Type, - [Models.Internal.Device.TagKey] = item.Tag, - [Models.Internal.Device.FixedImageKey] = item.FixedImage, - [Models.Internal.Device.MandatoryKey] = item.Mandatory, - [Models.Internal.Device.InterfaceKey] = item.Interface, - }; - - if (item.Instance != null) - device[Models.Internal.Device.InstanceKey] = ConvertFromListxml(item.Instance); - - if (item.Extension != null && item.Extension.Any()) - { - var extensions = new List(); - foreach (var extension in item.Extension) - { - extensions.Add(ConvertFromListxml(extension)); - } - device[Models.Internal.Device.ExtensionKey] = extensions.ToArray(); - } - - return device; - } - - /// - /// Convert from to - /// - public static Models.Internal.DeviceRef ConvertFromListxml(Models.Listxml.DeviceRef item) - { - var deviceRef = new Models.Internal.DeviceRef - { - [Models.Internal.DeviceRef.NameKey] = item.Name, - }; - return deviceRef; - } - - /// - /// Convert from to - /// - public static Models.Internal.DipLocation ConvertFromListxml(Models.Listxml.DipLocation item) - { - var dipLocation = new Models.Internal.DipLocation - { - [Models.Internal.DipLocation.NameKey] = item.Name, - [Models.Internal.DipLocation.NumberKey] = item.Number, - [Models.Internal.DipLocation.InvertedKey] = item.Inverted, - }; - return dipLocation; - } - - /// - /// Convert from to - /// - public static Models.Internal.DipSwitch ConvertFromListxml(Models.Listxml.DipSwitch item) - { - var dipSwitch = new Models.Internal.DipSwitch - { - [Models.Internal.DipSwitch.NameKey] = item.Name, - [Models.Internal.DipSwitch.TagKey] = item.Tag, - [Models.Internal.DipSwitch.MaskKey] = item.Mask, - }; - - if (item.Condition != null) - dipSwitch[Models.Internal.DipSwitch.ConditionKey] = ConvertFromListxml(item.Condition); - - if (item.DipLocation != null && item.DipLocation.Any()) - { - var dipLocations = new List(); - foreach (var dipLocation in item.DipLocation) - { - dipLocations.Add(ConvertFromListxml(dipLocation)); - } - dipSwitch[Models.Internal.DipSwitch.DipLocationKey] = dipLocations.ToArray(); - } - - if (item.DipValue != null && item.DipValue.Any()) - { - var dipValues = new List(); - foreach (var dipValue in item.DipValue) - { - dipValues.Add(ConvertFromListxml(dipValue)); - } - dipSwitch[Models.Internal.DipSwitch.DipValueKey] = dipValues.ToArray(); - } - - return dipSwitch; - } - - /// - /// Convert from to - /// - public static Models.Internal.DipValue ConvertFromListxml(Models.Listxml.DipValue item) - { - var dipValue = new Models.Internal.DipValue - { - [Models.Internal.DipValue.NameKey] = item.Name, - [Models.Internal.DipValue.ValueKey] = item.Value, - [Models.Internal.DipValue.DefaultKey] = item.Default, - }; - - if (item.Condition != null) - dipValue[Models.Internal.DipValue.ConditionKey] = ConvertFromListxml(item.Condition); - - return dipValue; - } - - /// - /// Convert from to - /// - public static Models.Internal.Disk ConvertFromListxml(Models.Listxml.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.RegionKey] = item.Region, - [Models.Internal.Disk.IndexKey] = item.Index, - [Models.Internal.Disk.WritableKey] = item.Writable, - [Models.Internal.Disk.StatusKey] = item.Status, - [Models.Internal.Disk.OptionalKey] = item.Optional, - }; - return disk; - } - - /// - /// Convert from to - /// - public static Models.Internal.Display ConvertFromListxml(Models.Listxml.Display item) - { - var display = new Models.Internal.Display - { - [Models.Internal.Display.TagKey] = item.Tag, - [Models.Internal.Display.TypeKey] = item.Type, - [Models.Internal.Display.RotateKey] = item.Rotate, - [Models.Internal.Display.FlipXKey] = item.FlipX, - [Models.Internal.Display.WidthKey] = item.Width, - [Models.Internal.Display.HeightKey] = item.Height, - [Models.Internal.Display.RefreshKey] = item.Refresh, - [Models.Internal.Display.PixClockKey] = item.PixClock, - [Models.Internal.Display.HTotalKey] = item.HTotal, - [Models.Internal.Display.HBEndKey] = item.HBEnd, - [Models.Internal.Display.HBStartKey] = item.HBStart, - [Models.Internal.Display.VTotalKey] = item.VTotal, - [Models.Internal.Display.VBEndKey] = item.VBEnd, - [Models.Internal.Display.VBStartKey] = item.VBStart, - }; - return display; - } - - /// - /// Convert from to - /// - public static Models.Internal.Driver ConvertFromListxml(Models.Listxml.Driver item) - { - var driver = new Models.Internal.Driver - { - [Models.Internal.Driver.StatusKey] = item.Status, - [Models.Internal.Driver.ColorKey] = item.Color, - [Models.Internal.Driver.SoundKey] = item.Sound, - [Models.Internal.Driver.PaletteSizeKey] = item.PaletteSize, - [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.Extension ConvertFromListxml(Models.Listxml.Extension item) - { - var extension = new Models.Internal.Extension - { - [Models.Internal.Extension.NameKey] = item.Name, - }; - return extension; - } - - /// - /// Convert from to - /// - public static Models.Internal.Feature ConvertFromListxml(Models.Listxml.Feature item) - { - var feature = new Models.Internal.Feature - { - [Models.Internal.Feature.TypeKey] = item.Type, - [Models.Internal.Feature.StatusKey] = item.Status, - [Models.Internal.Feature.OverallKey] = item.Overall, - }; - return feature; - } - - /// - /// Convert from to - /// - public static Models.Internal.Input ConvertFromListxml(Models.Listxml.Input item) - { - var input = new Models.Internal.Input - { - [Models.Internal.Input.ServiceKey] = item.Service, - [Models.Internal.Input.TiltKey] = item.Tilt, - [Models.Internal.Input.PlayersKey] = item.Players, - [Models.Internal.Input.ControlKey] = item.ControlAttr, - [Models.Internal.Input.ButtonsKey] = item.Buttons, - [Models.Internal.Input.CoinsKey] = item.Coins, - }; - - if (item.Control != null && item.Control.Any()) - { - var controls = new List(); - foreach (var control in item.Control) - { - controls.Add(ConvertFromListxml(control)); - } - input[Models.Internal.Input.ControlKey] = controls.ToArray(); - } - - return input; - } - - /// - /// Convert from to - /// - public static Models.Internal.Instance ConvertFromListxml(Models.Listxml.Instance item) - { - var instance = new Models.Internal.Instance - { - [Models.Internal.Instance.NameKey] = item.Name, - [Models.Internal.Instance.BriefNameKey] = item.BriefName, - }; - return instance; - } - - /// - /// Convert from to - /// - public static Models.Internal.Port ConvertFromListxml(Models.Listxml.Port item) - { - var port = new Models.Internal.Port - { - [Models.Internal.Port.TagKey] = item.Tag, - }; - - if (item.Analog != null && item.Analog.Any()) - { - var analogs = new List(); - foreach (var analog in item.Analog) - { - analogs.Add(ConvertFromListxml(analog)); - } - port[Models.Internal.Port.AnalogKey] = analogs.ToArray(); - } - - return port; - } - - /// - /// Convert from to - /// - public static Models.Internal.RamOption ConvertFromListxml(Models.Listxml.RamOption item) - { - var ramOption = new Models.Internal.RamOption - { - [Models.Internal.RamOption.NameKey] = item.Name, - [Models.Internal.RamOption.DefaultKey] = item.Default, - }; - return ramOption; - } - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromListxml(Models.Listxml.Rom item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.NameKey] = item.Name, - [Models.Internal.Rom.BiosKey] = item.Bios, - [Models.Internal.Rom.SizeKey] = item.Size, - [Models.Internal.Rom.CRCKey] = item.CRC, - [Models.Internal.Rom.SHA1Key] = item.SHA1, - [Models.Internal.Rom.MergeKey] = item.Merge, - [Models.Internal.Rom.RegionKey] = item.Region, - [Models.Internal.Rom.OffsetKey] = item.Offset, - [Models.Internal.Rom.StatusKey] = item.Status, - [Models.Internal.Rom.OptionalKey] = item.Optional, - [Models.Internal.Rom.DisposeKey] = item.Dispose, - [Models.Internal.Rom.SoundOnlyKey] = item.SoundOnly, - }; - return rom; - } - - /// - /// Convert from to - /// - public static Models.Internal.Sample ConvertFromListxml(Models.Listxml.Sample item) - { - var sample = new Models.Internal.Sample - { - [Models.Internal.Sample.NameKey] = item.Name, - }; - return sample; - } - - /// - /// Convert from to - /// - public static Models.Internal.Slot ConvertFromListxml(Models.Listxml.Slot item) - { - var slot = new Models.Internal.Slot - { - [Models.Internal.Slot.NameKey] = item.Name, - }; - - if (item.SlotOption != null && item.SlotOption.Any()) - { - var slotOptions = new List(); - foreach (var slotOption in item.SlotOption) - { - slotOptions.Add(ConvertFromListxml(slotOption)); - } - slot[Models.Internal.Slot.SlotOptionKey] = slotOptions.ToArray(); - } - - return slot; - } - - /// - /// Convert from to - /// - public static Models.Internal.SlotOption ConvertFromListxml(Models.Listxml.SlotOption item) - { - var slotOption = new Models.Internal.SlotOption - { - [Models.Internal.SlotOption.NameKey] = item.Name, - [Models.Internal.SlotOption.DevNameKey] = item.DevName, - [Models.Internal.SlotOption.DefaultKey] = item.Default, - }; - return slotOption; - } - - /// - /// Convert from to - /// - public static Models.Internal.SoftwareList ConvertFromListxml(Models.Listxml.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; - } - - /// - /// Convert from to - /// - public static Models.Internal.Sound ConvertFromListxml(Models.Listxml.Sound item) - { - var sound = new Models.Internal.Sound - { - [Models.Internal.Sound.ChannelsKey] = item.Channels, - }; - return sound; - } - - /// - /// Convert from to - /// - public static Models.Internal.Video ConvertFromListxml(Models.Listxml.Video item) - { - var video = new Models.Internal.Video - { - [Models.Internal.Video.ScreenKey] = item.Screen, - [Models.Internal.Video.OrientationKey] = item.Orientation, - [Models.Internal.Video.WidthKey] = item.Width, - [Models.Internal.Video.HeightKey] = item.Height, - [Models.Internal.Video.AspectXKey] = item.AspectX, - [Models.Internal.Video.AspectYKey] = item.AspectY, - [Models.Internal.Video.RefreshKey] = item.Refresh, - }; - return video; - } - - #endregion - - #region Logiqx - - /// - /// 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 OfflineList - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromOfflineList(Models.OfflineList.FileRomCRC item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.ExtensionKey] = item.Extension, - [Models.Internal.Rom.CRCKey] = item.Content, - }; - return rom; - } - - #endregion - - #region OpenMSX - - /// - /// Convert from to - /// - public static Models.Internal.Dump ConvertFromOpenMSX(Models.OpenMSX.Dump item) - { - var dump = new Models.Internal.Dump(); - - if (item.Original != null) - dump[Models.Internal.Dump.OriginalKey] = ConvertFromOpenMSX(item.Original); - - switch (item.Rom) - { - case Models.OpenMSX.Rom rom: - dump[Models.Internal.Dump.RomKey] = ConvertFromOpenMSX(rom); - break; - - case Models.OpenMSX.MegaRom megaRom: - dump[Models.Internal.Dump.MegaRomKey] = ConvertFromOpenMSX(megaRom); - break; - - case Models.OpenMSX.SCCPlusCart sccPlusCart: - dump[Models.Internal.Dump.SCCPlusCartKey] = ConvertFromOpenMSX(sccPlusCart); - break; - } - - return dump; - } - - /// - /// Convert from to - /// - public static Models.Internal.Original ConvertFromOpenMSX(Models.OpenMSX.Original item) - { - var original = new Models.Internal.Original - { - [Models.Internal.Original.ValueKey] = item.Value, - [Models.Internal.Original.ContentKey] = item.Content, - }; - return original; - } - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromOpenMSX(Models.OpenMSX.RomBase item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.StartKey] = item.Start, - [Models.Internal.Rom.TypeKey] = item.Type, - [Models.Internal.Rom.SHA1Key] = item.Hash, - [Models.Internal.Rom.RemarkKey] = item.Remark, - }; - return rom; - } - - #endregion - - #region RomCenter - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromRomCenter(Models.RomCenter.Rom item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.NameKey] = item.RomName, - [Models.Internal.Rom.CRCKey] = item.RomCRC, - [Models.Internal.Rom.SizeKey] = item.RomSize, - [Models.Internal.Rom.MergeKey] = item.MergeName, - }; - return rom; - } - - #endregion - - #region SeparatedValue - - /// - /// Convert from to - /// - public static Models.Internal.DatItem? ConvertFromSeparatedValue(Models.SeparatedValue.Row item) - { - return item.Type switch - { - "disk" => new Models.Internal.Disk - { - [Models.Internal.Disk.NameKey] = item.DiskName, - [Models.Internal.Disk.MD5Key] = item.MD5, - [Models.Internal.Disk.SHA1Key] = item.SHA1, - [Models.Internal.Disk.StatusKey] = item.Status, - }, - "media" => new Models.Internal.Media - { - [Models.Internal.Media.NameKey] = item.DiskName, - [Models.Internal.Media.MD5Key] = item.MD5, - [Models.Internal.Media.SHA1Key] = item.SHA1, - [Models.Internal.Media.SHA256Key] = item.SHA256, - [Models.Internal.Media.SpamSumKey] = item.SpamSum, - }, - "rom" => new Models.Internal.Rom - { - [Models.Internal.Rom.NameKey] = item.RomName, - [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.StatusKey] = item.Status, - }, - _ => null, - }; - } - - #endregion - - #region SoftwareList - - /// - /// Convert from to - /// - public static Models.Internal.DataArea ConvertFromSoftwareList(Models.SoftwareList.DataArea item) - { - var dataArea = new Models.Internal.DataArea - { - [Models.Internal.DataArea.NameKey] = item.Name, - [Models.Internal.DataArea.SizeKey] = item.Size, - [Models.Internal.DataArea.WidthKey] = item.Width, - [Models.Internal.DataArea.EndiannessKey] = item.Endianness, - }; - - if (item.Rom != null && item.Rom.Any()) - { - var roms = new List(); - foreach (var rom in item.Rom) - { - roms.Add(ConvertFromSoftwareList(rom)); - } - dataArea[Models.Internal.DataArea.RomKey] = roms.ToArray(); - } - - return dataArea; - } - - /// - /// Convert from to - /// - public static Models.Internal.DipSwitch ConvertFromSoftwareList(Models.SoftwareList.DipSwitch item) - { - var dipSwitch = new Models.Internal.DipSwitch - { - [Models.Internal.DipSwitch.NameKey] = item.Name, - [Models.Internal.DipSwitch.TagKey] = item.Tag, - [Models.Internal.DipSwitch.MaskKey] = item.Mask, - }; - - if (item.DipValue != null && item.DipValue.Any()) - { - var dipValues = new List(); - foreach (var dipValue in item.DipValue) - { - dipValues.Add(ConvertFromSoftwareList(dipValue)); - } - dipSwitch[Models.Internal.DipSwitch.DipValueKey] = dipValues.ToArray(); - } - - return dipSwitch; - } - - /// - /// Convert from to - /// - public static Models.Internal.DipValue ConvertFromSoftwareList(Models.SoftwareList.DipValue item) - { - var dipValue = new Models.Internal.DipValue - { - [Models.Internal.DipValue.NameKey] = item.Name, - [Models.Internal.DipValue.ValueKey] = item.Value, - [Models.Internal.DipValue.DefaultKey] = item.Default, - }; - return dipValue; - } - - /// - /// Convert from to - /// - public static Models.Internal.Disk ConvertFromSoftwareList(Models.SoftwareList.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.StatusKey] = item.Status, - [Models.Internal.Disk.WritableKey] = item.Writeable, - }; - return disk; - } - - /// - /// Convert from to - /// - public static Models.Internal.DiskArea ConvertFromSoftwareList(Models.SoftwareList.DiskArea item) - { - var diskArea = new Models.Internal.DiskArea - { - [Models.Internal.DiskArea.NameKey] = item.Name, - }; - - if (item.Disk != null && item.Disk.Any()) - { - var roms = new List(); - foreach (var disk in item.Disk) - { - roms.Add(ConvertFromSoftwareList(disk)); - } - diskArea[Models.Internal.DiskArea.DiskKey] = roms.ToArray(); - } - - return diskArea; - } - - /// - /// Convert from to - /// - public static Models.Internal.Feature ConvertFromSoftwareList(Models.SoftwareList.Feature item) - { - var feature = new Models.Internal.Feature - { - [Models.Internal.Feature.NameKey] = item.Name, - [Models.Internal.Feature.ValueKey] = item.Value, - }; - return feature; - } - - /// - /// Convert from to - /// - public static Models.Internal.Info ConvertFromSoftwareList(Models.SoftwareList.Info item) - { - var info = new Models.Internal.Info - { - [Models.Internal.Info.NameKey] = item.Name, - [Models.Internal.Info.ValueKey] = item.Value, - }; - return info; - } - - /// - /// Convert from to - /// - public static Models.Internal.Part ConvertFromSoftwareList(Models.SoftwareList.Part item) - { - var part = new Models.Internal.Part - { - [Models.Internal.Part.NameKey] = item.Name, - [Models.Internal.Part.InterfaceKey] = item.Interface, - }; - - if (item.Feature != null && item.Feature.Any()) - { - var features = new List(); - foreach (var feature in item.Feature) - { - features.Add(ConvertFromSoftwareList(feature)); - } - part[Models.Internal.Part.FeatureKey] = features.ToArray(); - } - - if (item.DataArea != null && item.DataArea.Any()) - { - var dataAreas = new List(); - foreach (var dataArea in item.DataArea) - { - dataAreas.Add(ConvertFromSoftwareList(dataArea)); - } - part[Models.Internal.Part.DataAreaKey] = dataAreas.ToArray(); - } - - if (item.DiskArea != null && item.DiskArea.Any()) - { - var diskAreas = new List(); - foreach (var diskArea in item.DiskArea) - { - diskAreas.Add(ConvertFromSoftwareList(diskArea)); - } - part[Models.Internal.Part.DiskAreaKey] = diskAreas.ToArray(); - } - - if (item.DipSwitch != null && item.DipSwitch.Any()) - { - var dipSwitches = new List(); - foreach (var rom in item.DipSwitch) - { - dipSwitches.Add(ConvertFromSoftwareList(rom)); - } - part[Models.Internal.Part.DipSwitchKey] = dipSwitches.ToArray(); - } - - return part; - } - - /// - /// Convert from to - /// - public static Models.Internal.Rom ConvertFromSoftwareList(Models.SoftwareList.Rom item) - { - var rom = new Models.Internal.Rom - { - [Models.Internal.Rom.NameKey] = item.Name, - [Models.Internal.Rom.SizeKey] = item.Size, - [Models.Internal.Rom.LengthKey] = item.Length, - [Models.Internal.Rom.CRCKey] = item.CRC, - [Models.Internal.Rom.SHA1Key] = item.SHA1, - [Models.Internal.Rom.OffsetKey] = item.Offset, - [Models.Internal.Rom.ValueKey] = item.Value, - [Models.Internal.Rom.StatusKey] = item.Status, - [Models.Internal.Rom.LoadFlagKey] = item.LoadFlag, - }; - return rom; - } - - /// - /// Convert from to - /// - public static Models.Internal.SharedFeat ConvertFromSoftwareList(Models.SoftwareList.SharedFeat item) - { - var sharedFeat = new Models.Internal.SharedFeat - { - [Models.Internal.SharedFeat.NameKey] = item.Name, - [Models.Internal.SharedFeat.ValueKey] = item.Value, - }; - return sharedFeat; - } - - #endregion - } -} \ No newline at end of file diff --git a/SabreTools.Serialization/Internal.SoftwareList.cs b/SabreTools.Serialization/Internal.SoftwareList.cs new file mode 100644 index 00000000..586df690 --- /dev/null +++ b/SabreTools.Serialization/Internal.SoftwareList.cs @@ -0,0 +1,453 @@ +using System.Collections.Generic; +using System.Linq; + +namespace SabreTools.Serialization +{ + /// + /// Serializer for SoftwareList models to internal structure + /// + public partial class Internal + { + #region Serialize + + /// + /// Convert from to + /// + public static Models.Internal.DataArea ConvertFromSoftwareList(Models.SoftwareList.DataArea item) + { + var dataArea = new Models.Internal.DataArea + { + [Models.Internal.DataArea.NameKey] = item.Name, + [Models.Internal.DataArea.SizeKey] = item.Size, + [Models.Internal.DataArea.WidthKey] = item.Width, + [Models.Internal.DataArea.EndiannessKey] = item.Endianness, + }; + + if (item.Rom != null && item.Rom.Any()) + { + var roms = new List(); + foreach (var rom in item.Rom) + { + roms.Add(ConvertFromSoftwareList(rom)); + } + dataArea[Models.Internal.DataArea.RomKey] = roms.ToArray(); + } + + return dataArea; + } + + /// + /// Convert from to + /// + public static Models.Internal.DipSwitch ConvertFromSoftwareList(Models.SoftwareList.DipSwitch item) + { + var dipSwitch = new Models.Internal.DipSwitch + { + [Models.Internal.DipSwitch.NameKey] = item.Name, + [Models.Internal.DipSwitch.TagKey] = item.Tag, + [Models.Internal.DipSwitch.MaskKey] = item.Mask, + }; + + if (item.DipValue != null && item.DipValue.Any()) + { + var dipValues = new List(); + foreach (var dipValue in item.DipValue) + { + dipValues.Add(ConvertFromSoftwareList(dipValue)); + } + dipSwitch[Models.Internal.DipSwitch.DipValueKey] = dipValues.ToArray(); + } + + return dipSwitch; + } + + /// + /// Convert from to + /// + public static Models.Internal.DipValue ConvertFromSoftwareList(Models.SoftwareList.DipValue item) + { + var dipValue = new Models.Internal.DipValue + { + [Models.Internal.DipValue.NameKey] = item.Name, + [Models.Internal.DipValue.ValueKey] = item.Value, + [Models.Internal.DipValue.DefaultKey] = item.Default, + }; + return dipValue; + } + + /// + /// Convert from to + /// + public static Models.Internal.Disk ConvertFromSoftwareList(Models.SoftwareList.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.StatusKey] = item.Status, + [Models.Internal.Disk.WritableKey] = item.Writeable, + }; + return disk; + } + + /// + /// Convert from to + /// + public static Models.Internal.DiskArea ConvertFromSoftwareList(Models.SoftwareList.DiskArea item) + { + var diskArea = new Models.Internal.DiskArea + { + [Models.Internal.DiskArea.NameKey] = item.Name, + }; + + if (item.Disk != null && item.Disk.Any()) + { + var roms = new List(); + foreach (var disk in item.Disk) + { + roms.Add(ConvertFromSoftwareList(disk)); + } + diskArea[Models.Internal.DiskArea.DiskKey] = roms.ToArray(); + } + + return diskArea; + } + + /// + /// Convert from to + /// + public static Models.Internal.Feature ConvertFromSoftwareList(Models.SoftwareList.Feature item) + { + var feature = new Models.Internal.Feature + { + [Models.Internal.Feature.NameKey] = item.Name, + [Models.Internal.Feature.ValueKey] = item.Value, + }; + return feature; + } + + /// + /// Convert from to + /// + public static Models.Internal.Info ConvertFromSoftwareList(Models.SoftwareList.Info item) + { + var info = new Models.Internal.Info + { + [Models.Internal.Info.NameKey] = item.Name, + [Models.Internal.Info.ValueKey] = item.Value, + }; + return info; + } + + /// + /// Convert from to + /// + public static Models.Internal.Part ConvertFromSoftwareList(Models.SoftwareList.Part item) + { + var part = new Models.Internal.Part + { + [Models.Internal.Part.NameKey] = item.Name, + [Models.Internal.Part.InterfaceKey] = item.Interface, + }; + + if (item.Feature != null && item.Feature.Any()) + { + var features = new List(); + foreach (var feature in item.Feature) + { + features.Add(ConvertFromSoftwareList(feature)); + } + part[Models.Internal.Part.FeatureKey] = features.ToArray(); + } + + if (item.DataArea != null && item.DataArea.Any()) + { + var dataAreas = new List(); + foreach (var dataArea in item.DataArea) + { + dataAreas.Add(ConvertFromSoftwareList(dataArea)); + } + part[Models.Internal.Part.DataAreaKey] = dataAreas.ToArray(); + } + + if (item.DiskArea != null && item.DiskArea.Any()) + { + var diskAreas = new List(); + foreach (var diskArea in item.DiskArea) + { + diskAreas.Add(ConvertFromSoftwareList(diskArea)); + } + part[Models.Internal.Part.DiskAreaKey] = diskAreas.ToArray(); + } + + if (item.DipSwitch != null && item.DipSwitch.Any()) + { + var dipSwitches = new List(); + foreach (var rom in item.DipSwitch) + { + dipSwitches.Add(ConvertFromSoftwareList(rom)); + } + part[Models.Internal.Part.DipSwitchKey] = dipSwitches.ToArray(); + } + + return part; + } + + /// + /// Convert from to + /// + public static Models.Internal.Rom ConvertFromSoftwareList(Models.SoftwareList.Rom item) + { + var rom = new Models.Internal.Rom + { + [Models.Internal.Rom.NameKey] = item.Name, + [Models.Internal.Rom.SizeKey] = item.Size, + [Models.Internal.Rom.LengthKey] = item.Length, + [Models.Internal.Rom.CRCKey] = item.CRC, + [Models.Internal.Rom.SHA1Key] = item.SHA1, + [Models.Internal.Rom.OffsetKey] = item.Offset, + [Models.Internal.Rom.ValueKey] = item.Value, + [Models.Internal.Rom.StatusKey] = item.Status, + [Models.Internal.Rom.LoadFlagKey] = item.LoadFlag, + }; + return rom; + } + + /// + /// Convert from to + /// + public static Models.Internal.SharedFeat ConvertFromSoftwareList(Models.SoftwareList.SharedFeat item) + { + var sharedFeat = new Models.Internal.SharedFeat + { + [Models.Internal.SharedFeat.NameKey] = item.Name, + [Models.Internal.SharedFeat.ValueKey] = item.Value, + }; + return sharedFeat; + } + + #endregion + + #region Deserialize + + /// + /// Convert from to + /// + public static Models.SoftwareList.DataArea ConvertToSoftwareList(Models.Internal.DataArea item) + { + var dataArea = new Models.SoftwareList.DataArea + { + Name = item.ReadString(Models.Internal.DataArea.NameKey), + Size = item.ReadString(Models.Internal.DataArea.SizeKey), + Width = item.ReadString(Models.Internal.DataArea.WidthKey), + Endianness = item.ReadString(Models.Internal.DataArea.EndiannessKey), + }; + + if (item.ContainsKey(Models.Internal.DataArea.RomKey) && item[Models.Internal.DataArea.RomKey] is Models.Internal.Rom[] roms) + { + var romItems = new List(); + foreach (var rom in roms) + { + romItems.Add(ConvertToSoftwareList(rom)); + } + dataArea.Rom = romItems.ToArray(); + } + + return dataArea; + } + + /// + /// Convert from to + /// + public static Models.SoftwareList.DipSwitch ConvertToSoftwareList(Models.Internal.DipSwitch item) + { + var dipSwitch = new Models.SoftwareList.DipSwitch + { + Name = item.ReadString(Models.Internal.DipSwitch.NameKey), + Tag = item.ReadString(Models.Internal.DipSwitch.TagKey), + Mask = item.ReadString(Models.Internal.DipSwitch.MaskKey), + }; + + if (item.ContainsKey(Models.Internal.DipSwitch.DipValueKey) && item[Models.Internal.DipSwitch.DipValueKey] is Models.Internal.DipValue[] dipValues) + { + var dipValueItems = new List(); + foreach (var rom in dipValues) + { + dipValueItems.Add(ConvertToSoftwareList(rom)); + } + dipSwitch.DipValue = dipValueItems.ToArray(); + } + + return dipSwitch; + } + + /// + /// Convert from to + /// + public static Models.SoftwareList.DipValue ConvertToSoftwareList(Models.Internal.DipValue item) + { + var dipValue = new Models.SoftwareList.DipValue + { + Name = item.ReadString(Models.Internal.DipValue.NameKey), + Value = item.ReadString(Models.Internal.DipValue.ValueKey), + Default = item.ReadString(Models.Internal.DipValue.DefaultKey), + }; + return dipValue; + } + + /// + /// Convert from to + /// + public static Models.SoftwareList.Disk ConvertToSoftwareList(Models.Internal.Disk item) + { + var disk = new Models.SoftwareList.Disk + { + Name = item.ReadString(Models.Internal.Disk.NameKey), + MD5 = item.ReadString(Models.Internal.Disk.MD5Key), + SHA1 = item.ReadString(Models.Internal.Disk.SHA1Key), + Status = item.ReadString(Models.Internal.Disk.StatusKey), + Writeable = item.ReadString(Models.Internal.Disk.WritableKey), + }; + return disk; + } + + /// + /// Convert from to + /// + public static Models.SoftwareList.DiskArea ConvertToSoftwareList(Models.Internal.DiskArea item) + { + var diskArea = new Models.SoftwareList.DiskArea + { + Name = item.ReadString(Models.Internal.DiskArea.NameKey), + }; + + if (item.ContainsKey(Models.Internal.DiskArea.DiskKey) && item[Models.Internal.DiskArea.DiskKey] is Models.Internal.Disk[] disks) + { + var diskItems = new List(); + foreach (var disk in disks) + { + diskItems.Add(ConvertToSoftwareList(disk)); + } + diskArea.Disk = diskItems.ToArray(); + } + + return diskArea; + } + + /// + /// Convert from to + /// + public static Models.SoftwareList.Feature ConvertToSoftwareList(Models.Internal.Feature item) + { + var feature = new Models.SoftwareList.Feature + { + Name = item.ReadString(Models.Internal.Feature.NameKey), + Value = item.ReadString(Models.Internal.Feature.ValueKey), + }; + return feature; + } + + /// + /// Convert from to + /// + public static Models.SoftwareList.Info ConvertToSoftwareList(Models.Internal.Info item) + { + var info = new Models.SoftwareList.Info + { + Name = item.ReadString(Models.Internal.Info.NameKey), + Value = item.ReadString(Models.Internal.Info.ValueKey), + }; + return info; + } + + /// + /// Convert from to + /// + public static Models.SoftwareList.Part ConvertToSoftwareList(Models.Internal.Part item) + { + var part = new Models.SoftwareList.Part + { + Name = item.ReadString(Models.Internal.Part.NameKey), + Interface = item.ReadString(Models.Internal.Part.InterfaceKey), + }; + + if (item.ContainsKey(Models.Internal.Part.FeatureKey) && item[Models.Internal.Part.FeatureKey] is Models.Internal.Feature[] features) + { + var featureItems = new List(); + foreach (var feature in features) + { + featureItems.Add(ConvertToSoftwareList(feature)); + } + part.Feature = featureItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Part.DataAreaKey) && item[Models.Internal.Part.DataAreaKey] is Models.Internal.DataArea[] dataAreas) + { + var dataAreaItems = new List(); + foreach (var dataArea in dataAreas) + { + dataAreaItems.Add(ConvertToSoftwareList(dataArea)); + } + part.DataArea = dataAreaItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Part.DiskAreaKey) && item[Models.Internal.Part.DiskAreaKey] is Models.Internal.DiskArea[] diskAreas) + { + var diskAreaItems = new List(); + foreach (var diskArea in diskAreas) + { + diskAreaItems.Add(ConvertToSoftwareList(diskArea)); + } + part.DiskArea = diskAreaItems.ToArray(); + } + + if (item.ContainsKey(Models.Internal.Part.DipSwitchKey) && item[Models.Internal.Part.DipSwitchKey] is Models.Internal.DipSwitch[] dipSwitches) + { + var dipSwitchItems = new List(); + foreach (var rom in dipSwitches) + { + dipSwitchItems.Add(ConvertToSoftwareList(rom)); + } + part.DipSwitch = dipSwitchItems.ToArray(); + } + + return part; + } + + /// + /// Convert from to + /// + public static Models.SoftwareList.Rom ConvertToSoftwareList(Models.Internal.Rom item) + { + var rom = new Models.SoftwareList.Rom + { + Name = item.ReadString(Models.Internal.Rom.NameKey), + Size = item.ReadString(Models.Internal.Rom.SizeKey), + Length = item.ReadString(Models.Internal.Rom.LengthKey), + CRC = item.ReadString(Models.Internal.Rom.CRCKey), + SHA1 = item.ReadString(Models.Internal.Rom.SHA1Key), + Offset = item.ReadString(Models.Internal.Rom.OffsetKey), + Value = item.ReadString(Models.Internal.Rom.ValueKey), + Status = item.ReadString(Models.Internal.Rom.StatusKey), + LoadFlag = item.ReadString(Models.Internal.Rom.LoadFlagKey), + }; + return rom; + } + + /// + /// Convert from to + /// + public static Models.SoftwareList.SharedFeat ConvertToSoftwareList(Models.Internal.SharedFeat item) + { + var sharedFeat = new Models.SoftwareList.SharedFeat + { + Name = item.ReadString(Models.Internal.SharedFeat.NameKey), + Value = item.ReadString(Models.Internal.SharedFeat.ValueKey), + }; + return sharedFeat; + } + + #endregion + } +} \ No newline at end of file