From edf9fed751bc4c078d09e4f1021de66e0a7fc99e Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 21 Nov 2023 20:59:20 -0500 Subject: [PATCH] Support .NET Framework 2.0 --- CrossModel/ArchiveDotOrg.Deserializer.cs | 4 -- CrossModel/AttractMode.Deserializer.cs | 4 -- CrossModel/EverdriveSMDB.Deserializer.cs | 4 -- CrossModel/Listrom.Serializer.cs | 2 +- CrossModel/Logiqx.Serializer.cs | 4 -- CrossModel/RomCenter.Deserializer.cs | 4 -- Extensions.PortableExecutable.cs | 16 ++++- Files/AttractMode.Serializer.cs | 2 +- Files/ClrMamePro.Serializer.cs | 2 +- Files/CueSheet.Deserializer.cs | 14 ++-- Files/CueSheet.Serializer.cs | 2 +- Files/DosCenter.Serializer.cs | 2 +- Files/EverdriveSMDB.Serializer.cs | 2 +- Files/Hashfile.Serializer.cs | 2 +- Files/IRD.Serializer.cs | 2 +- Files/Listrom.Serializer.cs | 2 +- Files/PIC.Serializer.cs | 2 +- Files/RomCenter.Serializer.cs | 2 +- Files/SeparatedValue.Serializer.cs | 2 +- Files/XmlFile.Serializer.cs | 2 +- Internal.cs | 19 ++---- OldDotNet.cs | 50 ++++++++++++++ PathProcessor.cs | 2 +- SabreTools.Serialization.csproj | 8 +-- Streams/ClrMamePro.Deserializer.cs | 6 +- Streams/ClrMamePro.Serializer.cs | 4 -- Streams/CueSheet.Serializer.cs | 23 ++++++- Streams/HashFile.Deserializer.cs | 14 ++-- Streams/Hashfile.Serializer.cs | 14 ++-- Streams/IRD.Deserializer.cs | 8 --- Streams/LinearExecutable.Deserializer.cs | 84 ++++++++++++++++++++++++ Streams/Listrom.Deserializer.cs | 2 +- Streams/Listrom.Serializer.cs | 8 +-- Streams/MicrosoftCabinet.Deserializer.cs | 16 +++++ Streams/N3DS.Deserializer.cs | 4 -- Streams/NewExecutable.Deserializer.cs | 4 -- Streams/XmlFile.Deserializer.cs | 2 + Streams/XmlFile.Serializer.cs | 2 +- Strings/XMID.Deserializer.cs | 4 +- Strings/XeMID.Deserializer.cs | 4 +- Strings/XeMID.Serializer.cs | 2 +- Wrappers/GCF.cs | 31 +++++++++ Wrappers/PortableExecutable.cs | 16 ++--- Wrappers/VPK.cs | 2 +- Wrappers/XMID.cs | 2 +- Wrappers/XeMID.cs | 2 +- 46 files changed, 286 insertions(+), 123 deletions(-) create mode 100644 OldDotNet.cs diff --git a/CrossModel/ArchiveDotOrg.Deserializer.cs b/CrossModel/ArchiveDotOrg.Deserializer.cs index d3efe646..5470756b 100644 --- a/CrossModel/ArchiveDotOrg.Deserializer.cs +++ b/CrossModel/ArchiveDotOrg.Deserializer.cs @@ -34,11 +34,7 @@ namespace SabreTools.Serialization.CrossModel { var roms = item.Read(Models.Metadata.Machine.RomKey); if (roms == null) -#if NET40 || NET452 return []; -#else - return Array.Empty(); -#endif return roms .Where(r => r != null) diff --git a/CrossModel/AttractMode.Deserializer.cs b/CrossModel/AttractMode.Deserializer.cs index 3cad1413..3628dd72 100644 --- a/CrossModel/AttractMode.Deserializer.cs +++ b/CrossModel/AttractMode.Deserializer.cs @@ -47,11 +47,7 @@ namespace SabreTools.Serialization.CrossModel { var roms = item.Read(Models.Metadata.Machine.RomKey); if (roms == null || !roms.Any()) -#if NET40 || NET452 return []; -#else - return Array.Empty(); -#endif return roms .Where(r => r != null) diff --git a/CrossModel/EverdriveSMDB.Deserializer.cs b/CrossModel/EverdriveSMDB.Deserializer.cs index 30009261..28c450cf 100644 --- a/CrossModel/EverdriveSMDB.Deserializer.cs +++ b/CrossModel/EverdriveSMDB.Deserializer.cs @@ -34,11 +34,7 @@ namespace SabreTools.Serialization.CrossModel { var roms = item.Read(Models.Metadata.Machine.RomKey); if (roms == null || !roms.Any()) -#if NET40 || NET452 return []; -#else - return Array.Empty(); -#endif return roms .Where(r => r != null) diff --git a/CrossModel/Listrom.Serializer.cs b/CrossModel/Listrom.Serializer.cs index 654ae3c6..71a9cfa1 100644 --- a/CrossModel/Listrom.Serializer.cs +++ b/CrossModel/Listrom.Serializer.cs @@ -47,7 +47,7 @@ namespace SabreTools.Serialization.CrossModel private static Models.Metadata.Machine ConvertMachineToInternalModel(Set item) { var machine = new Models.Metadata.Machine(); - if (!string.IsNullOrWhiteSpace(item.Device)) + if (!string.IsNullOrEmpty(item.Device)) { machine[Models.Metadata.Machine.NameKey] = item.Device; machine[Models.Metadata.Machine.IsDeviceKey] = "yes"; diff --git a/CrossModel/Logiqx.Serializer.cs b/CrossModel/Logiqx.Serializer.cs index ede47edb..8f1502c3 100644 --- a/CrossModel/Logiqx.Serializer.cs +++ b/CrossModel/Logiqx.Serializer.cs @@ -104,11 +104,7 @@ namespace SabreTools.Serialization.CrossModel private static Models.Metadata.Machine[] ConvertDirToInternalModel(Dir item) { if (item.Game == null || !item.Game.Any()) -#if NET40 || NET452 return []; -#else - return Array.Empty(); -#endif return item.Game .Where(g => g != null) diff --git a/CrossModel/RomCenter.Deserializer.cs b/CrossModel/RomCenter.Deserializer.cs index f92a1dd7..81a04fc5 100644 --- a/CrossModel/RomCenter.Deserializer.cs +++ b/CrossModel/RomCenter.Deserializer.cs @@ -91,11 +91,7 @@ namespace SabreTools.Serialization.CrossModel { var roms = item.Read(Models.Metadata.Machine.RomKey); if (roms == null) -#if NET40 || NET452 return []; -#else - return Array.Empty(); -#endif return roms .Where(r => r != null) diff --git a/Extensions.PortableExecutable.cs b/Extensions.PortableExecutable.cs index b54c30f4..64dbaec1 100644 --- a/Extensions.PortableExecutable.cs +++ b/Extensions.PortableExecutable.cs @@ -115,14 +115,14 @@ namespace SabreTools.Serialization addD.EntryCount = data.ReadUInt32(ref offset); addD.Version = data.ReadString(ref offset, Encoding.ASCII); - if (string.IsNullOrWhiteSpace(addD.Version)) + if (string.IsNullOrEmpty(addD.Version)) offset = originalOffset + 0x10; addD.Build = data.ReadBytes(ref offset, 4)?.Select(b => (char)b)?.ToArray(); // Distinguish between v1 and v2 int bytesToRead = 112; // v2 - if (string.IsNullOrWhiteSpace(addD.Version) + if (string.IsNullOrEmpty(addD.Version) || addD.Version!.StartsWith("3") || addD.Version.StartsWith("4.47")) { @@ -437,7 +437,11 @@ namespace SabreTools.Serialization #region Point size and typeface // Only if DS_SETFONT is set are the values here used +#if NET20 || NET35 + if ((dialogTemplateExtended.Style & WindowStyles.DS_SETFONT) != 0) +#else if (dialogTemplateExtended.Style.HasFlag(WindowStyles.DS_SETFONT)) +#endif { dialogTemplateExtended.PointSize = entry.Data.ReadUInt16(ref offset); dialogTemplateExtended.Weight = entry.Data.ReadUInt16(ref offset); @@ -679,7 +683,11 @@ namespace SabreTools.Serialization #region Point size and typeface // Only if DS_SETFONT is set are the values here used +#if NET20 || NET35 + if ((dialogTemplate.Style & WindowStyles.DS_SETFONT) != 0) +#else if (dialogTemplate.Style.HasFlag(WindowStyles.DS_SETFONT)) +#endif { dialogTemplate.PointSizeValue = entry.Data.ReadUInt16(ref offset); @@ -967,7 +975,11 @@ namespace SabreTools.Serialization // Determine if this is a popup int flagsOffset = offset; var initialFlags = (MenuFlags)entry.Data.ReadUInt16(ref flagsOffset); +#if NET20 || NET35 + if ((initialFlags & MenuFlags.MF_POPUP) != 0) +#else if (initialFlags.HasFlag(MenuFlags.MF_POPUP)) +#endif { menuItem.PopupItemType = (MenuFlags)entry.Data.ReadUInt32(ref offset); menuItem.PopupState = (MenuFlags)entry.Data.ReadUInt32(ref offset); diff --git a/Files/AttractMode.Serializer.cs b/Files/AttractMode.Serializer.cs index 0a44b26c..cf622df9 100644 --- a/Files/AttractMode.Serializer.cs +++ b/Files/AttractMode.Serializer.cs @@ -9,7 +9,7 @@ namespace SabreTools.Serialization.Files /// public bool Serialize(MetadataFile? obj, string? path) { - if (string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrEmpty(path)) return false; using (var stream = new Streams.AttractMode().Serialize(obj)) diff --git a/Files/ClrMamePro.Serializer.cs b/Files/ClrMamePro.Serializer.cs index 0d4553cb..a0426e69 100644 --- a/Files/ClrMamePro.Serializer.cs +++ b/Files/ClrMamePro.Serializer.cs @@ -12,7 +12,7 @@ namespace SabreTools.Serialization.Files /// public bool Serialize(MetadataFile? obj, string? path, bool quotes) { - if (string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrEmpty(path)) return false; using (var stream = new Streams.ClrMamePro().Serialize(obj, quotes)) diff --git a/Files/CueSheet.Deserializer.cs b/Files/CueSheet.Deserializer.cs index 68d53e22..ff7f2ae2 100644 --- a/Files/CueSheet.Deserializer.cs +++ b/Files/CueSheet.Deserializer.cs @@ -14,7 +14,7 @@ namespace SabreTools.Serialization.Files public Models.CueSheets.CueSheet? Deserialize(string? path) { // Check that the file exists - if (string.IsNullOrWhiteSpace(path) || !File.Exists(path)) + if (string.IsNullOrEmpty(path) || !File.Exists(path)) return null; // Check the extension @@ -43,7 +43,7 @@ namespace SabreTools.Serialization.Files .ToArray(); // If we have an empty line, we skip - if (string.IsNullOrWhiteSpace(line)) + if (string.IsNullOrEmpty(line)) continue; switch (splitLine[0]) @@ -143,7 +143,7 @@ namespace SabreTools.Serialization.Files string[] splitLine = line.Split(' '); // If we have an empty line, we skip - if (string.IsNullOrWhiteSpace(line)) + if (string.IsNullOrEmpty(line)) continue; switch (splitLine[0]) @@ -213,7 +213,7 @@ namespace SabreTools.Serialization.Files string[] splitLine = line.Split(' '); // If we have an empty line, we skip - if (string.IsNullOrWhiteSpace(line)) + if (string.IsNullOrEmpty(line)) continue; switch (splitLine[0]) @@ -317,7 +317,7 @@ namespace SabreTools.Serialization.Files private static PreGap CreatePreGap(string? length) { // Ignore empty lines - if (string.IsNullOrWhiteSpace(length)) + if (string.IsNullOrEmpty(length)) throw new ArgumentException("Length was null or whitespace"); // Ignore lines that don't contain the correct information @@ -374,7 +374,7 @@ namespace SabreTools.Serialization.Files throw new IndexOutOfRangeException($"Index must be between 0 and 99: {parsedIndex}"); // Ignore empty lines - if (string.IsNullOrWhiteSpace(startTime)) + if (string.IsNullOrEmpty(startTime)) throw new ArgumentException("Start time was null or whitespace"); // Ignore lines that don't contain the correct information @@ -425,7 +425,7 @@ namespace SabreTools.Serialization.Files private static PostGap CreatePostGap(string? length) { // Ignore empty lines - if (string.IsNullOrWhiteSpace(length)) + if (string.IsNullOrEmpty(length)) throw new ArgumentException("Length was null or whitespace"); // Ignore lines that don't contain the correct information diff --git a/Files/CueSheet.Serializer.cs b/Files/CueSheet.Serializer.cs index d7e78d61..6dadcc9f 100644 --- a/Files/CueSheet.Serializer.cs +++ b/Files/CueSheet.Serializer.cs @@ -8,7 +8,7 @@ namespace SabreTools.Serialization.Files /// public bool Serialize(Models.CueSheets.CueSheet? obj, string? path) { - if (string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrEmpty(path)) return false; using (var stream = new Streams.CueSheet().Serialize(obj)) diff --git a/Files/DosCenter.Serializer.cs b/Files/DosCenter.Serializer.cs index 6c056203..b5ebb864 100644 --- a/Files/DosCenter.Serializer.cs +++ b/Files/DosCenter.Serializer.cs @@ -8,7 +8,7 @@ namespace SabreTools.Serialization.Files /// public bool Serialize(MetadataFile? obj, string? path) { - if (string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrEmpty(path)) return false; using (var stream = new Streams.DosCenter().Serialize(obj)) diff --git a/Files/EverdriveSMDB.Serializer.cs b/Files/EverdriveSMDB.Serializer.cs index e34741dd..7f7c1026 100644 --- a/Files/EverdriveSMDB.Serializer.cs +++ b/Files/EverdriveSMDB.Serializer.cs @@ -8,7 +8,7 @@ namespace SabreTools.Serialization.Files /// public bool Serialize(MetadataFile? obj, string? path) { - if (string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrEmpty(path)) return false; using (var stream = new Streams.EverdriveSMDB().Serialize(obj)) diff --git a/Files/Hashfile.Serializer.cs b/Files/Hashfile.Serializer.cs index f41a07ba..5ed0b369 100644 --- a/Files/Hashfile.Serializer.cs +++ b/Files/Hashfile.Serializer.cs @@ -10,7 +10,7 @@ namespace SabreTools.Serialization.Files /// public bool Serialize(Models.Hashfile.Hashfile? obj, string? path, Hash hash) { - if (string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrEmpty(path)) return false; using (var stream = new Streams.Hashfile().Serialize(obj, hash)) diff --git a/Files/IRD.Serializer.cs b/Files/IRD.Serializer.cs index c08f4270..e4d9159d 100644 --- a/Files/IRD.Serializer.cs +++ b/Files/IRD.Serializer.cs @@ -7,7 +7,7 @@ namespace SabreTools.Serialization.Files /// public bool Serialize(Models.IRD.File? obj, string? path) { - if (string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrEmpty(path)) return false; using (var stream = new Streams.IRD().Serialize(obj)) diff --git a/Files/Listrom.Serializer.cs b/Files/Listrom.Serializer.cs index 117b2395..056532c0 100644 --- a/Files/Listrom.Serializer.cs +++ b/Files/Listrom.Serializer.cs @@ -8,7 +8,7 @@ namespace SabreTools.Serialization.Files /// public bool Serialize(MetadataFile? obj, string? path) { - if (string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrEmpty(path)) return false; using (var stream = new Streams.Listrom().Serialize(obj)) diff --git a/Files/PIC.Serializer.cs b/Files/PIC.Serializer.cs index 9b3620d3..1c312f0b 100644 --- a/Files/PIC.Serializer.cs +++ b/Files/PIC.Serializer.cs @@ -8,7 +8,7 @@ namespace SabreTools.Serialization.Files /// public bool Serialize(DiscInformation? obj, string? path) { - if (string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrEmpty(path)) return false; using (var stream = new Streams.PIC().Serialize(obj)) diff --git a/Files/RomCenter.Serializer.cs b/Files/RomCenter.Serializer.cs index 8b9d9eb3..538b7f97 100644 --- a/Files/RomCenter.Serializer.cs +++ b/Files/RomCenter.Serializer.cs @@ -8,7 +8,7 @@ namespace SabreTools.Serialization.Files /// public bool Serialize(MetadataFile? obj, string? path) { - if (string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrEmpty(path)) return false; using (var stream = new Streams.RomCenter().Serialize(obj)) diff --git a/Files/SeparatedValue.Serializer.cs b/Files/SeparatedValue.Serializer.cs index 84faa87f..b4f1fc88 100644 --- a/Files/SeparatedValue.Serializer.cs +++ b/Files/SeparatedValue.Serializer.cs @@ -11,7 +11,7 @@ namespace SabreTools.Serialization.Files /// public bool Serialize(MetadataFile? obj, string? path, char delim) { - if (string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrEmpty(path)) return false; using (var stream = new Streams.SeparatedValue().Serialize(obj, delim)) diff --git a/Files/XmlFile.Serializer.cs b/Files/XmlFile.Serializer.cs index 22688782..38ea1d3c 100644 --- a/Files/XmlFile.Serializer.cs +++ b/Files/XmlFile.Serializer.cs @@ -26,7 +26,7 @@ namespace SabreTools.Serialization.Files /// True on successful serialization, false otherwise public bool Serialize(T? obj, string? path, string? name = null, string? pubid = null, string? sysid = null, string? subset = null) { - if (string.IsNullOrWhiteSpace(path)) + if (string.IsNullOrEmpty(path)) return false; using (var stream = new Streams.XmlFile().Serialize(obj, name, pubid, sysid, subset)) diff --git a/Internal.cs b/Internal.cs index 88ac6428..75557aba 100644 --- a/Internal.cs +++ b/Internal.cs @@ -51,7 +51,8 @@ namespace SabreTools.Serialization { datItems.AddRange(dataAreas .Where(d => d != null) - .SelectMany(ExtractItems)); + .SelectMany(ExtractItems) + .Select(d => d as DatItem)); } var diskAreas = item.Read(Part.DiskAreaKey); @@ -59,14 +60,16 @@ namespace SabreTools.Serialization { datItems.AddRange(diskAreas .Where(d => d != null) - .SelectMany(ExtractItems)); + .SelectMany(ExtractItems) + .Select(d => d as DatItem)); } var dipSwitches = item.Read(Part.DipSwitchKey); if (dipSwitches != null && dipSwitches.Any()) { datItems.AddRange(dipSwitches - .Where(d => d != null)); + .Where(d => d != null) + .Select(d => d as DatItem)); } return datItems.ToArray(); @@ -79,11 +82,7 @@ namespace SabreTools.Serialization { var roms = item.Read(DataArea.RomKey); if (roms == null || !roms.Any()) -#if NET40 || NET452 return []; -#else - return Array.Empty(); -#endif return roms.ToArray(); } @@ -95,13 +94,9 @@ namespace SabreTools.Serialization { var roms = item.Read(DiskArea.DiskKey); if (roms == null || !roms.Any()) -#if NET40 || NET452 return []; -#else - return Array.Empty(); -#endif - return roms.ToArray(); + return [.. roms]; } } } \ No newline at end of file diff --git a/OldDotNet.cs b/OldDotNet.cs new file mode 100644 index 00000000..c4ae3704 --- /dev/null +++ b/OldDotNet.cs @@ -0,0 +1,50 @@ +#if NET20 || NET35 + +using System; +using System.IO; + +namespace SabreTools.Serialization +{ + /// + /// Derived from the mscorlib code from .NET Framework 4.0 + /// + internal static class OldDotNet + { + public static void CopyTo(this Stream source, Stream destination) + { + if (destination == null) + { + throw new ArgumentNullException("destination"); + } + + if (!source.CanRead && !source.CanWrite) + { + throw new ObjectDisposedException(null); + } + + if (!destination.CanRead && !destination.CanWrite) + { + throw new ObjectDisposedException("destination"); + } + + if (!source.CanRead) + { + throw new NotSupportedException(); + } + + if (!destination.CanWrite) + { + throw new NotSupportedException(); + } + + byte[] array = new byte[81920]; + int count; + while ((count = source.Read(array, 0, array.Length)) != 0) + { + destination.Write(array, 0, count); + } + } + } +} + +#endif diff --git a/PathProcessor.cs b/PathProcessor.cs index 709c8082..fdc623aa 100644 --- a/PathProcessor.cs +++ b/PathProcessor.cs @@ -16,7 +16,7 @@ namespace SabreTools.Serialization try { // If we don't have a file - if (string.IsNullOrWhiteSpace(path) || !File.Exists(path)) + if (string.IsNullOrEmpty(path) || !File.Exists(path)) return null; // Open the file for deserialization diff --git a/SabreTools.Serialization.csproj b/SabreTools.Serialization.csproj index 267a2348..e786890f 100644 --- a/SabreTools.Serialization.csproj +++ b/SabreTools.Serialization.csproj @@ -2,7 +2,7 @@ - net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 + net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64 true latest @@ -23,12 +23,12 @@ - + - - + + diff --git a/Streams/ClrMamePro.Deserializer.cs b/Streams/ClrMamePro.Deserializer.cs index e1e250cb..33e7a2f1 100644 --- a/Streams/ClrMamePro.Deserializer.cs +++ b/Streams/ClrMamePro.Deserializer.cs @@ -241,11 +241,7 @@ namespace SabreTools.Serialization.Streams var sample = new Sample { Name = reader.Standalone?.Value ?? string.Empty, -#if NET40 || NET452 - ADDITIONAL_ELEMENTS = [] -#else - ADDITIONAL_ELEMENTS = Array.Empty() -#endif + ADDITIONAL_ELEMENTS = [], }; samples.Add(sample); break; diff --git a/Streams/ClrMamePro.Serializer.cs b/Streams/ClrMamePro.Serializer.cs index 89cacf83..415de9a0 100644 --- a/Streams/ClrMamePro.Serializer.cs +++ b/Streams/ClrMamePro.Serializer.cs @@ -412,11 +412,7 @@ namespace SabreTools.Serialization.Streams { writer.WriteStartElement("dipswitch"); writer.WriteRequiredAttributeString("name", dipswitch.Name, throwOnError: true); -#if NET40 || NET452 foreach (var entry in dipswitch.Entry ?? []) -#else - foreach (var entry in dipswitch.Entry ?? Array.Empty()) -#endif { writer.WriteRequiredAttributeString("entry", entry); } diff --git a/Streams/CueSheet.Serializer.cs b/Streams/CueSheet.Serializer.cs index 0f1f15f1..be4fd3bb 100644 --- a/Streams/CueSheet.Serializer.cs +++ b/Streams/CueSheet.Serializer.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Text; using SabreTools.Models.CueSheets; +using SabreTools.Models.PortableExecutable; using SabreTools.Serialization.Interfaces; namespace SabreTools.Serialization.Streams @@ -25,7 +26,7 @@ namespace SabreTools.Serialization.Streams // Setup the writer and output var stream = new MemoryStream(); -#if NET40 +#if NET20 || NET35 || NET40 var writer = new StreamWriter(stream, Encoding.ASCII, 1024); #else var writer = new StreamWriter(stream, Encoding.ASCII, 1024, true); @@ -247,19 +248,39 @@ namespace SabreTools.Serialization.Streams { string outputFlagString = string.Empty; +#if NET20 || NET35 + if ((flags & CueTrackFlag.DCP) != 0) +#else if (flags.HasFlag(CueTrackFlag.DCP)) +#endif outputFlagString += "DCP "; +#if NET20 || NET35 + if ((flags & CueTrackFlag.FourCH) != 0) +#else if (flags.HasFlag(CueTrackFlag.FourCH)) +#endif outputFlagString += "4CH "; +#if NET20 || NET35 + if ((flags & CueTrackFlag.PRE) != 0) +#else if (flags.HasFlag(CueTrackFlag.PRE)) +#endif outputFlagString += "PRE "; +#if NET20 || NET35 + if ((flags & CueTrackFlag.SCMS) != 0) +#else if (flags.HasFlag(CueTrackFlag.SCMS)) +#endif outputFlagString += "SCMS "; +#if NET20 || NET35 + if ((flags & CueTrackFlag.DATA) != 0) +#else if (flags.HasFlag(CueTrackFlag.DATA)) +#endif outputFlagString += "DATA "; return outputFlagString.Trim(); diff --git a/Streams/HashFile.Deserializer.cs b/Streams/HashFile.Deserializer.cs index a49e1815..1d990b99 100644 --- a/Streams/HashFile.Deserializer.cs +++ b/Streams/HashFile.Deserializer.cs @@ -45,7 +45,7 @@ namespace SabreTools.Serialization.Streams var sfv = new SFV { #if NETFRAMEWORK - File = string.Join(" ", lineParts.Take(lineParts.Length - 1)), + File = string.Join(" ", lineParts.Take(lineParts.Length - 1).ToArray()), Hash = lineParts[lineParts.Length - 1], #else File = string.Join(" ", lineParts[..^1]), @@ -59,7 +59,7 @@ namespace SabreTools.Serialization.Streams { Hash = lineParts[0], #if NETFRAMEWORK - File = string.Join(" ", lineParts.Skip(1)), + File = string.Join(" ", lineParts.Skip(1).ToArray()), #else File = string.Join(" ", lineParts[1..]), #endif @@ -71,7 +71,7 @@ namespace SabreTools.Serialization.Streams { Hash = lineParts[0], #if NETFRAMEWORK - File = string.Join(" ", lineParts.Skip(1)), + File = string.Join(" ", lineParts.Skip(1).ToArray()), #else File = string.Join(" ", lineParts[1..]), #endif @@ -83,7 +83,7 @@ namespace SabreTools.Serialization.Streams { Hash = lineParts[0], #if NETFRAMEWORK - File = string.Join(" ", lineParts.Skip(1)), + File = string.Join(" ", lineParts.Skip(1).ToArray()), #else File = string.Join(" ", lineParts[1..]), #endif @@ -95,7 +95,7 @@ namespace SabreTools.Serialization.Streams { Hash = lineParts[0], #if NETFRAMEWORK - File = string.Join(" ", lineParts.Skip(1)), + File = string.Join(" ", lineParts.Skip(1).ToArray()), #else File = string.Join(" ", lineParts[1..]), #endif @@ -107,7 +107,7 @@ namespace SabreTools.Serialization.Streams { Hash = lineParts[0], #if NETFRAMEWORK - File = string.Join(" ", lineParts.Skip(1)), + File = string.Join(" ", lineParts.Skip(1).ToArray()), #else File = string.Join(" ", lineParts[1..]), #endif @@ -119,7 +119,7 @@ namespace SabreTools.Serialization.Streams { Hash = lineParts[0], #if NETFRAMEWORK - File = string.Join(" ", lineParts.Skip(1)), + File = string.Join(" ", lineParts.Skip(1).ToArray()), #else File = string.Join(" ", lineParts[1..]), #endif diff --git a/Streams/Hashfile.Serializer.cs b/Streams/Hashfile.Serializer.cs index 4b4ad71a..d4db4557 100644 --- a/Streams/Hashfile.Serializer.cs +++ b/Streams/Hashfile.Serializer.cs @@ -78,7 +78,7 @@ namespace SabreTools.Serialization.Streams { if (sfv == null) continue; - if (string.IsNullOrWhiteSpace(sfv.File) || string.IsNullOrWhiteSpace(sfv.Hash)) + if (string.IsNullOrEmpty(sfv.File) || string.IsNullOrEmpty(sfv.Hash)) continue; writer.WriteValues(new string[] { sfv.File!, sfv.Hash! }); @@ -102,7 +102,7 @@ namespace SabreTools.Serialization.Streams { if (md5 == null) continue; - if (string.IsNullOrWhiteSpace(md5.Hash) || string.IsNullOrWhiteSpace(md5.File)) + if (string.IsNullOrEmpty(md5.Hash) || string.IsNullOrEmpty(md5.File)) continue; writer.WriteValues(new string[] { md5.Hash!, md5.File! }); @@ -126,7 +126,7 @@ namespace SabreTools.Serialization.Streams { if (sha1 == null) continue; - if (string.IsNullOrWhiteSpace(sha1.Hash) || string.IsNullOrWhiteSpace(sha1.File)) + if (string.IsNullOrEmpty(sha1.Hash) || string.IsNullOrEmpty(sha1.File)) continue; writer.WriteValues(new string[] { sha1.Hash!, sha1.File! }); @@ -150,7 +150,7 @@ namespace SabreTools.Serialization.Streams { if (sha256 == null) continue; - if (string.IsNullOrWhiteSpace(sha256.Hash) || string.IsNullOrWhiteSpace(sha256.File)) + if (string.IsNullOrEmpty(sha256.Hash) || string.IsNullOrEmpty(sha256.File)) continue; writer.WriteValues(new string[] { sha256.Hash!, sha256.File! }); @@ -174,7 +174,7 @@ namespace SabreTools.Serialization.Streams { if (sha384 == null) continue; - if (string.IsNullOrWhiteSpace(sha384.Hash) || string.IsNullOrWhiteSpace(sha384.File)) + if (string.IsNullOrEmpty(sha384.Hash) || string.IsNullOrEmpty(sha384.File)) continue; writer.WriteValues(new string[] { sha384.Hash!, sha384.File! }); @@ -198,7 +198,7 @@ namespace SabreTools.Serialization.Streams { if (sha512 == null) continue; - if (string.IsNullOrWhiteSpace(sha512.Hash) || string.IsNullOrWhiteSpace(sha512.File)) + if (string.IsNullOrEmpty(sha512.Hash) || string.IsNullOrEmpty(sha512.File)) continue; writer.WriteValues(new string[] { sha512.Hash!, sha512.File! }); @@ -222,7 +222,7 @@ namespace SabreTools.Serialization.Streams { if (spamsum == null) continue; - if (string.IsNullOrWhiteSpace(spamsum.Hash) || string.IsNullOrWhiteSpace(spamsum.File)) + if (string.IsNullOrEmpty(spamsum.Hash) || string.IsNullOrEmpty(spamsum.File)) continue; writer.WriteValues(new string[] { spamsum.Hash!, spamsum.File! }); diff --git a/Streams/IRD.Deserializer.cs b/Streams/IRD.Deserializer.cs index 56bcb2a2..9a9eb8ff 100644 --- a/Streams/IRD.Deserializer.cs +++ b/Streams/IRD.Deserializer.cs @@ -80,11 +80,7 @@ namespace SabreTools.Serialization.Streams ird.RegionHashes = new byte[ird.RegionCount][]; for (int i = 0; i < ird.RegionCount; i++) { -#if NET40 || NET452 ird.RegionHashes[i] = data.ReadBytes(16) ?? []; -#else - ird.RegionHashes[i] = data.ReadBytes(16) ?? Array.Empty(); -#endif } ird.FileCount = data.ReadByteValue(); @@ -93,11 +89,7 @@ namespace SabreTools.Serialization.Streams for (int i = 0; i < ird.FileCount; i++) { ird.FileKeys[i] = data.ReadUInt64(); -#if NET40 || NET452 ird.FileHashes[i] = data.ReadBytes(16) ?? []; -#else - ird.FileHashes[i] = data.ReadBytes(16) ?? Array.Empty(); -#endif } ird.ExtraConfig = data.ReadUInt16(); diff --git a/Streams/LinearExecutable.Deserializer.cs b/Streams/LinearExecutable.Deserializer.cs index b0764b16..4b10360a 100644 --- a/Streams/LinearExecutable.Deserializer.cs +++ b/Streams/LinearExecutable.Deserializer.cs @@ -694,25 +694,45 @@ namespace SabreTools.Serialization.Streams entry.TargetFlags = (FixupRecordTargetFlags)data.ReadByteValue(); // Source list flag +#if NET20 || NET35 + if ((entry.SourceType & FixupRecordSourceType.SourceListFlag) != 0) +#else if (entry.SourceType.HasFlag(FixupRecordSourceType.SourceListFlag)) +#endif entry.SourceOffsetListCount = data.ReadByteValue(); else entry.SourceOffset = data.ReadUInt16(); // OBJECT / TRGOFF +#if NET20 || NET35 + if ((entry.TargetFlags & FixupRecordTargetFlags.InternalReference) != 0) +#else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.InternalReference)) +#endif { // 16-bit Object Number/Module Ordinal Flag +#if NET20 || NET35 + if ((entry.TargetFlags & FixupRecordTargetFlags.SixteenBitObjectNumberModuleOrdinalFlag) != 0) +#else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.SixteenBitObjectNumberModuleOrdinalFlag)) +#endif entry.TargetObjectNumberWORD = data.ReadUInt16(); else entry.TargetObjectNumberByte = data.ReadByteValue(); // 16-bit Selector fixup +#if NET20 || NET35 + if ((entry.SourceType & FixupRecordSourceType.SixteenBitSelectorFixup) == 0) +#else if (!entry.SourceType.HasFlag(FixupRecordSourceType.SixteenBitSelectorFixup)) +#endif { // 32-bit Target Offset Flag +#if NET20 || NET35 + if ((entry.TargetFlags & FixupRecordTargetFlags.ThirtyTwoBitTargetOffsetFlag) != 0) +#else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.ThirtyTwoBitTargetOffsetFlag)) +#endif entry.TargetOffsetDWORD = data.ReadUInt32(); else entry.TargetOffsetWORD = data.ReadUInt16(); @@ -720,27 +740,51 @@ namespace SabreTools.Serialization.Streams } // MOD ORD# / IMPORT ORD / ADDITIVE +#if NET20 || NET35 + else if ((entry.TargetFlags & FixupRecordTargetFlags.ImportedReferenceByOrdinal) != 0) +#else else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.ImportedReferenceByOrdinal)) +#endif { // 16-bit Object Number/Module Ordinal Flag +#if NET20 || NET35 + if ((entry.TargetFlags & FixupRecordTargetFlags.SixteenBitObjectNumberModuleOrdinalFlag) != 0) +#else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.SixteenBitObjectNumberModuleOrdinalFlag)) +#endif entry.OrdinalIndexImportModuleNameTableWORD = data.ReadUInt16(); else entry.OrdinalIndexImportModuleNameTableByte = data.ReadByteValue(); // 8-bit Ordinal Flag & 32-bit Target Offset Flag +#if NET20 || NET35 + if ((entry.TargetFlags & FixupRecordTargetFlags.EightBitOrdinalFlag) != 0) +#else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.EightBitOrdinalFlag)) +#endif entry.ImportedOrdinalNumberByte = data.ReadByteValue(); +#if NET20 || NET35 + else if ((entry.TargetFlags & FixupRecordTargetFlags.ThirtyTwoBitTargetOffsetFlag) != 0) +#else else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.ThirtyTwoBitTargetOffsetFlag)) +#endif entry.ImportedOrdinalNumberDWORD = data.ReadUInt32(); else entry.ImportedOrdinalNumberWORD = data.ReadUInt16(); // Additive Fixup Flag +#if NET20 || NET35 + if ((entry.TargetFlags & FixupRecordTargetFlags.AdditiveFixupFlag) != 0) +#else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.AdditiveFixupFlag)) +#endif { // 32-bit Additive Flag +#if NET20 || NET35 + if ((entry.TargetFlags & FixupRecordTargetFlags.ThirtyTwoBitAdditiveFixupFlag) != 0) +#else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.ThirtyTwoBitAdditiveFixupFlag)) +#endif entry.AdditiveFixupValueDWORD = data.ReadUInt32(); else entry.AdditiveFixupValueWORD = data.ReadUInt16(); @@ -748,25 +792,45 @@ namespace SabreTools.Serialization.Streams } // MOD ORD# / PROCEDURE NAME OFFSET / ADDITIVE +#if NET20 || NET35 + else if ((entry.TargetFlags & FixupRecordTargetFlags.ImportedReferenceByName) != 0) +#else else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.ImportedReferenceByName)) +#endif { // 16-bit Object Number/Module Ordinal Flag +#if NET20 || NET35 + if ((entry.TargetFlags & FixupRecordTargetFlags.SixteenBitObjectNumberModuleOrdinalFlag) != 0) +#else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.SixteenBitObjectNumberModuleOrdinalFlag)) +#endif entry.OrdinalIndexImportModuleNameTableWORD = data.ReadUInt16(); else entry.OrdinalIndexImportModuleNameTableByte = data.ReadByteValue(); // 32-bit Target Offset Flag +#if NET20 || NET35 + if ((entry.TargetFlags & FixupRecordTargetFlags.ThirtyTwoBitTargetOffsetFlag) != 0) +#else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.ThirtyTwoBitTargetOffsetFlag)) +#endif entry.OffsetImportProcedureNameTableDWORD = data.ReadUInt32(); else entry.OffsetImportProcedureNameTableWORD = data.ReadUInt16(); // Additive Fixup Flag +#if NET20 || NET35 + if ((entry.TargetFlags & FixupRecordTargetFlags.AdditiveFixupFlag) != 0) +#else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.AdditiveFixupFlag)) +#endif { // 32-bit Additive Flag +#if NET20 || NET35 + if ((entry.TargetFlags & FixupRecordTargetFlags.ThirtyTwoBitAdditiveFixupFlag) != 0) +#else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.ThirtyTwoBitAdditiveFixupFlag)) +#endif entry.AdditiveFixupValueDWORD = data.ReadUInt32(); else entry.AdditiveFixupValueWORD = data.ReadUInt16(); @@ -774,19 +838,35 @@ namespace SabreTools.Serialization.Streams } // ORD # / ADDITIVE +#if NET20 || NET35 + else if ((entry.TargetFlags & FixupRecordTargetFlags.InternalReferenceViaEntryTable) != 0) +#else else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.InternalReferenceViaEntryTable)) +#endif { // 16-bit Object Number/Module Ordinal Flag +#if NET20 || NET35 + if ((entry.TargetFlags & FixupRecordTargetFlags.SixteenBitObjectNumberModuleOrdinalFlag) != 0) +#else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.SixteenBitObjectNumberModuleOrdinalFlag)) +#endif entry.OrdinalIndexImportModuleNameTableWORD = data.ReadUInt16(); else entry.OrdinalIndexImportModuleNameTableByte = data.ReadByteValue(); // Additive Fixup Flag +#if NET20 || NET35 + if ((entry.TargetFlags & FixupRecordTargetFlags.AdditiveFixupFlag) != 0) +#else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.AdditiveFixupFlag)) +#endif { // 32-bit Additive Flag +#if NET20 || NET35 + if ((entry.TargetFlags & FixupRecordTargetFlags.ThirtyTwoBitAdditiveFixupFlag) != 0) +#else if (entry.TargetFlags.HasFlag(FixupRecordTargetFlags.ThirtyTwoBitAdditiveFixupFlag)) +#endif entry.AdditiveFixupValueDWORD = data.ReadUInt32(); else entry.AdditiveFixupValueWORD = data.ReadUInt16(); @@ -801,7 +881,11 @@ namespace SabreTools.Serialization.Streams #region SCROFFn +#if NET20 || NET35 + if ((entry.SourceType & FixupRecordSourceType.SourceListFlag) != 0) +#else if (entry.SourceType.HasFlag(FixupRecordSourceType.SourceListFlag)) +#endif { entry.SourceOffsetList = new ushort[entry.SourceOffsetListCount]; for (int i = 0; i < entry.SourceOffsetList.Length; i++) diff --git a/Streams/Listrom.Deserializer.cs b/Streams/Listrom.Deserializer.cs index c481d333..4c3103b1 100644 --- a/Streams/Listrom.Deserializer.cs +++ b/Streams/Listrom.Deserializer.cs @@ -29,7 +29,7 @@ namespace SabreTools.Serialization.Streams { // Read the line and don't split yet string? line = reader.ReadLine(); - if (string.IsNullOrWhiteSpace(line)) + if (string.IsNullOrEmpty(line)) { // If we have a set to process if (set != null) diff --git a/Streams/Listrom.Serializer.cs b/Streams/Listrom.Serializer.cs index 8eec68c4..f07ba57a 100644 --- a/Streams/Listrom.Serializer.cs +++ b/Streams/Listrom.Serializer.cs @@ -57,7 +57,7 @@ namespace SabreTools.Serialization.Streams if (set == null) return; - if (!string.IsNullOrWhiteSpace(set.Driver)) + if (!string.IsNullOrEmpty(set.Driver)) { if (set.Row != null && set.Row.Any()) { @@ -77,7 +77,7 @@ namespace SabreTools.Serialization.Streams writer.Flush(); } } - else if (!string.IsNullOrWhiteSpace(set.Device)) + else if (!string.IsNullOrEmpty(set.Device)) { if (set.Row != null && set.Row.Any()) { @@ -112,7 +112,7 @@ namespace SabreTools.Serialization.Streams foreach (var row in rows) { - if (string.IsNullOrWhiteSpace(row.Name)) + if (string.IsNullOrEmpty(row.Name)) continue; var rowBuilder = new StringBuilder(); @@ -141,7 +141,7 @@ namespace SabreTools.Serialization.Streams } else { - if (!string.IsNullOrWhiteSpace(row.MD5)) + if (!string.IsNullOrEmpty(row.MD5)) rowBuilder.Append($"MD5({row.MD5}) "); else rowBuilder.Append($"SHA1({row.SHA1}) "); diff --git a/Streams/MicrosoftCabinet.Deserializer.cs b/Streams/MicrosoftCabinet.Deserializer.cs index c93966c5..8a278b73 100644 --- a/Streams/MicrosoftCabinet.Deserializer.cs +++ b/Streams/MicrosoftCabinet.Deserializer.cs @@ -116,7 +116,11 @@ namespace SabreTools.Serialization.Streams header.SetID = data.ReadUInt16(); header.CabinetIndex = data.ReadUInt16(); +#if NET20 || NET35 + if ((header.Flags & HeaderFlags.RESERVE_PRESENT) != 0) +#else if (header.Flags.HasFlag(HeaderFlags.RESERVE_PRESENT)) +#endif { header.HeaderReservedSize = data.ReadUInt16(); if (header.HeaderReservedSize > 60_000) @@ -129,13 +133,21 @@ namespace SabreTools.Serialization.Streams header.ReservedData = data.ReadBytes(header.HeaderReservedSize); } +#if NET20 || NET35 + if ((header.Flags & HeaderFlags.PREV_CABINET) != 0) +#else if (header.Flags.HasFlag(HeaderFlags.PREV_CABINET)) +#endif { header.CabinetPrev = data.ReadString(Encoding.ASCII); header.DiskPrev = data.ReadString(Encoding.ASCII); } +#if NET20 || NET35 + if ((header.Flags & HeaderFlags.NEXT_CABINET) != 0) +#else if (header.Flags.HasFlag(HeaderFlags.NEXT_CABINET)) +#endif { header.CabinetNext = data.ReadString(Encoding.ASCII); header.DiskNext = data.ReadString(Encoding.ASCII); @@ -218,7 +230,11 @@ namespace SabreTools.Serialization.Streams file.Time = data.ReadUInt16(); file.Attributes = (Models.MicrosoftCabinet.FileAttributes)data.ReadUInt16(); +#if NET20 || NET35 + if ((file.Attributes & Models.MicrosoftCabinet.FileAttributes.NAME_IS_UTF) != 0) +#else if (file.Attributes.HasFlag(Models.MicrosoftCabinet.FileAttributes.NAME_IS_UTF)) +#endif file.Name = data.ReadString(Encoding.Unicode); else file.Name = data.ReadString(Encoding.ASCII); diff --git a/Streams/N3DS.Deserializer.cs b/Streams/N3DS.Deserializer.cs index b906a12b..23a62fd7 100644 --- a/Streams/N3DS.Deserializer.cs +++ b/Streams/N3DS.Deserializer.cs @@ -643,11 +643,7 @@ namespace SabreTools.Serialization.Streams exeFSHeader.FileHashes = new byte[10][]; for (int i = 0; i < 10; i++) { -#if NET40 || NET452 exeFSHeader.FileHashes[i] = data.ReadBytes(0x20) ?? []; -#else - exeFSHeader.FileHashes[i] = data.ReadBytes(0x20) ?? Array.Empty(); -#endif } return exeFSHeader; diff --git a/Streams/NewExecutable.Deserializer.cs b/Streams/NewExecutable.Deserializer.cs index 9e048e38..28b806df 100644 --- a/Streams/NewExecutable.Deserializer.cs +++ b/Streams/NewExecutable.Deserializer.cs @@ -327,11 +327,7 @@ namespace SabreTools.Serialization.Streams .Select(rt => rt!.TypeID) .Union(resourceTable.ResourceTypes .Where(rt => rt != null) -#if NET40 || NET452 .SelectMany(rt => rt!.Resources ?? []) -#else - .SelectMany(rt => rt!.Resources ?? System.Array.Empty()) -#endif .Where(r => r!.IsIntegerType() == false) .Select(r => r!.ResourceID)) .Distinct() diff --git a/Streams/XmlFile.Deserializer.cs b/Streams/XmlFile.Deserializer.cs index 292a1f59..d47b3e92 100644 --- a/Streams/XmlFile.Deserializer.cs +++ b/Streams/XmlFile.Deserializer.cs @@ -24,7 +24,9 @@ namespace SabreTools.Serialization.Streams var settings = new XmlReaderSettings { CheckCharacters = false, +#if NET40_OR_GREATER || NETCOREAPP DtdProcessing = DtdProcessing.Ignore, +#endif ValidationFlags = XmlSchemaValidationFlags.None, ValidationType = ValidationType.None, }; diff --git a/Streams/XmlFile.Serializer.cs b/Streams/XmlFile.Serializer.cs index ce53e4a2..0de1957e 100644 --- a/Streams/XmlFile.Serializer.cs +++ b/Streams/XmlFile.Serializer.cs @@ -50,7 +50,7 @@ namespace SabreTools.Serialization.Streams var xmlWriter = XmlWriter.Create(streamWriter, settings); // Write the doctype if provided - if (!string.IsNullOrWhiteSpace(name)) + if (!string.IsNullOrEmpty(name)) xmlWriter.WriteDocType(name, pubid, sysid, subset); // Perform the deserialization and return diff --git a/Strings/XMID.Deserializer.cs b/Strings/XMID.Deserializer.cs index 0780d45a..273d4fe6 100644 --- a/Strings/XMID.Deserializer.cs +++ b/Strings/XMID.Deserializer.cs @@ -7,11 +7,11 @@ namespace SabreTools.Serialization.Strings /// public Models.Xbox.XMID? Deserialize(string? str) { - if (string.IsNullOrWhiteSpace(str)) + if (string.IsNullOrEmpty(str)) return null; string xmid = str!.TrimEnd('\0'); - if (string.IsNullOrWhiteSpace(xmid)) + if (string.IsNullOrEmpty(xmid)) return null; return ParseXMID(xmid); diff --git a/Strings/XeMID.Deserializer.cs b/Strings/XeMID.Deserializer.cs index d7ba6682..d3f825ed 100644 --- a/Strings/XeMID.Deserializer.cs +++ b/Strings/XeMID.Deserializer.cs @@ -7,11 +7,11 @@ namespace SabreTools.Serialization.Strings /// public Models.Xbox.XeMID? Deserialize(string? str) { - if (string.IsNullOrWhiteSpace(str)) + if (string.IsNullOrEmpty(str)) return null; string xemid = str!.TrimEnd('\0'); - if (string.IsNullOrWhiteSpace(xemid)) + if (string.IsNullOrEmpty(xemid)) return null; return ParseXeMID(xemid); diff --git a/Strings/XeMID.Serializer.cs b/Strings/XeMID.Serializer.cs index ef05a6a7..b2b95a24 100644 --- a/Strings/XeMID.Serializer.cs +++ b/Strings/XeMID.Serializer.cs @@ -21,7 +21,7 @@ namespace SabreTools.Serialization.Strings sb.Append(obj.BaseVersion); sb.Append(obj.MediaSubtypeIdentifier); sb.Append(obj.DiscNumberIdentifier); - if (!string.IsNullOrWhiteSpace(obj.CertificationSubmissionIdentifier)) + if (!string.IsNullOrEmpty(obj.CertificationSubmissionIdentifier)) sb.Append(obj.CertificationSubmissionIdentifier); return sb.ToString(); diff --git a/Wrappers/GCF.cs b/Wrappers/GCF.cs index 8505b294..6fedc304 100644 --- a/Wrappers/GCF.cs +++ b/Wrappers/GCF.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; using System.IO; +using SabreTools.Models.CHD; +using SabreTools.Models.CueSheets; namespace SabreTools.Serialization.Wrappers { @@ -40,14 +42,22 @@ namespace SabreTools.Serialization.Wrappers continue; // If we have a directory, skip for now +#if NET20 || NET35 + if ((directoryEntry.DirectoryFlags & Models.GCF.HL_GCF_FLAG.HL_GCF_FLAG_FILE) == 0) +#else if (!directoryEntry.DirectoryFlags.HasFlag(Models.GCF.HL_GCF_FLAG.HL_GCF_FLAG_FILE)) +#endif continue; // Otherwise, start building the file info var fileInfo = new FileInfo() { Size = directoryEntry.ItemSize, +#if NET20 || NET35 + Encrypted = (directoryEntry.DirectoryFlags & Models.GCF.HL_GCF_FLAG.HL_GCF_FLAG_ENCRYPTED) != 0, +#else Encrypted = directoryEntry.DirectoryFlags.HasFlag(Models.GCF.HL_GCF_FLAG.HL_GCF_FLAG_ENCRYPTED), +#endif }; var pathParts = new List { directoryEntry.Name ?? string.Empty }; var blockEntries = new List(); @@ -80,7 +90,28 @@ namespace SabreTools.Serialization.Wrappers pathParts.Reverse(); // Build the remaining file info +#if NET20 || NET35 + var pathArray = pathParts.ToArray(); + + string tempPath = string.Empty; + if (pathArray.Length == 0 || pathArray.Length == 1) + { + tempPath = pathArray[0]; + } + else + { + for (int j = 0; j < pathArray.Length; j++) + { + if (j == 0) + tempPath = pathArray[j]; + else + tempPath = Path.Combine(tempPath, pathArray[j]); + } + } + fileInfo.Path = tempPath; +#else fileInfo.Path = Path.Combine(pathParts.ToArray()); +#endif fileInfo.BlockEntries = blockEntries.ToArray(); // Add the file info and continue diff --git a/Wrappers/PortableExecutable.cs b/Wrappers/PortableExecutable.cs index cd35abac..f2c0b5a3 100644 --- a/Wrappers/PortableExecutable.cs +++ b/Wrappers/PortableExecutable.cs @@ -586,15 +586,15 @@ namespace SabreTools.Serialization.Wrappers public string? GetInternalVersion() { string? version = this.FileVersion; - if (!string.IsNullOrWhiteSpace(version)) + if (!string.IsNullOrEmpty(version)) return version!.Replace(", ", "."); version = this.ProductVersion; - if (!string.IsNullOrWhiteSpace(version)) + if (!string.IsNullOrEmpty(version)) return version!.Replace(", ", "."); version = this.AssemblyVersion; - if (!string.IsNullOrWhiteSpace(version)) + if (!string.IsNullOrEmpty(version)) return version; return null; @@ -633,7 +633,7 @@ namespace SabreTools.Serialization.Wrappers var manifest = GetAssemblyManifest(); return manifest? .AssemblyIdentities? - .FirstOrDefault(ai => !string.IsNullOrWhiteSpace(ai?.Version))? + .FirstOrDefault(ai => !string.IsNullOrEmpty(ai?.Version))? .Version; } } @@ -826,11 +826,7 @@ namespace SabreTools.Serialization.Wrappers // Try to find a key that matches var match = stringTable -#if NET40 || NET452 .SelectMany(st => st?.Children ?? []) -#else - .SelectMany(st => st?.Children ?? Array.Empty()) -#endif .FirstOrDefault(sd => sd != null && key.Equals(sd.Key, StringComparison.OrdinalIgnoreCase)); // Return either the match or null @@ -894,7 +890,7 @@ namespace SabreTools.Serialization.Wrappers { // Ensure that we have the resource data cached if (DebugData == null) - return Enumerable.Empty(); + return Enumerable.Empty(); return DebugData.Select(r => r.Value) .Select(b => b as byte[]) @@ -1182,7 +1178,7 @@ namespace SabreTools.Serialization.Wrappers private void ParseResourceDataEntry(Models.PortableExecutable.ResourceDataEntry entry, List types) { // Create the key and value objects - string key = types == null ? $"UNKNOWN_{Guid.NewGuid()}" : string.Join(", ", types); + string key = types == null ? $"UNKNOWN_{Guid.NewGuid()}" : string.Join(", ", types.Select(t => t.ToString()).ToArray()); object? value = entry.Data; // If we have a known resource type diff --git a/Wrappers/VPK.cs b/Wrappers/VPK.cs index 1406cdd4..eda5a0c7 100644 --- a/Wrappers/VPK.cs +++ b/Wrappers/VPK.cs @@ -27,7 +27,7 @@ namespace SabreTools.Serialization.Wrappers return _archiveFilenames; // If we don't have a source filename - if (!(_streamData is FileStream fs) || string.IsNullOrWhiteSpace(fs.Name)) + if (!(_streamData is FileStream fs) || string.IsNullOrEmpty(fs.Name)) return null; // If the filename is not the right format diff --git a/Wrappers/XMID.cs b/Wrappers/XMID.cs index 4c135fef..10cce582 100644 --- a/Wrappers/XMID.cs +++ b/Wrappers/XMID.cs @@ -23,7 +23,7 @@ namespace SabreTools.Serialization.Wrappers get { var publisherIdentifier = this.Model.PublisherIdentifier; - if (string.IsNullOrWhiteSpace(publisherIdentifier)) + if (string.IsNullOrEmpty(publisherIdentifier)) return "Unknown"; if (Publishers.ContainsKey(publisherIdentifier!)) diff --git a/Wrappers/XeMID.cs b/Wrappers/XeMID.cs index 15e4f543..8d2bd677 100644 --- a/Wrappers/XeMID.cs +++ b/Wrappers/XeMID.cs @@ -38,7 +38,7 @@ namespace SabreTools.Serialization.Wrappers get { var publisherIdentifier = this.Model.PublisherIdentifier; - if (string.IsNullOrWhiteSpace(publisherIdentifier)) + if (string.IsNullOrEmpty(publisherIdentifier)) return "Unknown"; if (Publishers.ContainsKey(publisherIdentifier!))