Support .NET Framework 2.0

This commit is contained in:
Matt Nadareski
2023-11-21 20:59:20 -05:00
parent beca747943
commit edf9fed751
46 changed files with 286 additions and 123 deletions

View File

@@ -34,11 +34,7 @@ namespace SabreTools.Serialization.CrossModel
{
var roms = item.Read<Models.Metadata.Rom[]>(Models.Metadata.Machine.RomKey);
if (roms == null)
#if NET40 || NET452
return [];
#else
return Array.Empty<File>();
#endif
return roms
.Where(r => r != null)

View File

@@ -47,11 +47,7 @@ namespace SabreTools.Serialization.CrossModel
{
var roms = item.Read<Models.Metadata.Rom[]>(Models.Metadata.Machine.RomKey);
if (roms == null || !roms.Any())
#if NET40 || NET452
return [];
#else
return Array.Empty<Row>();
#endif
return roms
.Where(r => r != null)

View File

@@ -34,11 +34,7 @@ namespace SabreTools.Serialization.CrossModel
{
var roms = item.Read<Models.Metadata.Rom[]>(Models.Metadata.Machine.RomKey);
if (roms == null || !roms.Any())
#if NET40 || NET452
return [];
#else
return Array.Empty<Row>();
#endif
return roms
.Where(r => r != null)

View File

@@ -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";

View File

@@ -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<Models.Metadata.Machine>();
#endif
return item.Game
.Where(g => g != null)

View File

@@ -91,11 +91,7 @@ namespace SabreTools.Serialization.CrossModel
{
var roms = item.Read<Models.Metadata.Rom[]>(Models.Metadata.Machine.RomKey);
if (roms == null)
#if NET40 || NET452
return [];
#else
return Array.Empty<Rom>();
#endif
return roms
.Where(r => r != null)

View File

@@ -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);

View File

@@ -9,7 +9,7 @@ namespace SabreTools.Serialization.Files
/// <inheritdoc/>
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))

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Serialization.Files
/// <inheritdoc cref="Serialize(MetadataFile, string)"/>
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))

View File

@@ -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

View File

@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.Files
/// <inheritdoc/>
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))

View File

@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.Files
/// <inheritdoc/>
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))

View File

@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.Files
/// <inheritdoc/>
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))

View File

@@ -10,7 +10,7 @@ namespace SabreTools.Serialization.Files
/// <inheritdoc/>
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))

View File

@@ -7,7 +7,7 @@ namespace SabreTools.Serialization.Files
/// <inheritdoc/>
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))

View File

@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.Files
/// <inheritdoc/>
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))

View File

@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.Files
/// <inheritdoc/>
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))

View File

@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.Files
/// <inheritdoc/>
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))

View File

@@ -11,7 +11,7 @@ namespace SabreTools.Serialization.Files
/// <inheritdoc/>
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))

View File

@@ -26,7 +26,7 @@ namespace SabreTools.Serialization.Files
/// <returns>True on successful serialization, false otherwise</returns>
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<T>().Serialize(obj, name, pubid, sysid, subset))

View File

@@ -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<DiskArea[]>(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<DipSwitch[]>(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<Rom[]>(DataArea.RomKey);
if (roms == null || !roms.Any())
#if NET40 || NET452
return [];
#else
return Array.Empty<Rom>();
#endif
return roms.ToArray();
}
@@ -95,13 +94,9 @@ namespace SabreTools.Serialization
{
var roms = item.Read<Disk[]>(DiskArea.DiskKey);
if (roms == null || !roms.Any())
#if NET40 || NET452
return [];
#else
return Array.Empty<Disk>();
#endif
return roms.ToArray();
return [.. roms];
}
}
}

50
OldDotNet.cs Normal file
View File

@@ -0,0 +1,50 @@
#if NET20 || NET35
using System;
using System.IO;
namespace SabreTools.Serialization
{
/// <summary>
/// Derived from the mscorlib code from .NET Framework 4.0
/// </summary>
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

View File

@@ -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

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<!-- Assembly Properties -->
<TargetFrameworks>net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
@@ -23,12 +23,12 @@
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath=""/>
<None Include="README.md" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SabreTools.IO" Version="1.2.0" />
<PackageReference Include="SabreTools.Models" Version="1.2.0" />
<PackageReference Include="SabreTools.IO" Version="1.3.0" />
<PackageReference Include="SabreTools.Models" Version="1.3.0" />
</ItemGroup>
</Project>

View File

@@ -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<string>()
#endif
ADDITIONAL_ELEMENTS = [],
};
samples.Add(sample);
break;

View File

@@ -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<string>())
#endif
{
writer.WriteRequiredAttributeString("entry", entry);
}

View File

@@ -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();

View File

@@ -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

View File

@@ -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! });

View File

@@ -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<byte>();
#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<byte>();
#endif
}
ird.ExtraConfig = data.ReadUInt16();

View File

@@ -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++)

View File

@@ -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)

View File

@@ -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}) ");

View File

@@ -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);

View File

@@ -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<byte>();
#endif
}
return exeFSHeader;

View File

@@ -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<ResourceTypeResourceEntry>())
#endif
.Where(r => r!.IsIntegerType() == false)
.Select(r => r!.ResourceID))
.Distinct()

View File

@@ -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,
};

View File

@@ -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

View File

@@ -7,11 +7,11 @@ namespace SabreTools.Serialization.Strings
/// <inheritdoc/>
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);

View File

@@ -7,11 +7,11 @@ namespace SabreTools.Serialization.Strings
/// <inheritdoc/>
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);

View File

@@ -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();

View File

@@ -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<string> { directoryEntry.Name ?? string.Empty };
var blockEntries = new List<Models.GCF.BlockEntry?>();
@@ -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

View File

@@ -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<Models.PortableExecutable.StringData>())
#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<byte[]>();
return Enumerable.Empty<byte[]?>();
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<object> 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

View File

@@ -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

View File

@@ -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!))

View File

@@ -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!))