mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-02-04 13:45:40 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aaa6422921 | ||
|
|
f24b88031b | ||
|
|
edf9fed751 | ||
|
|
beca747943 | ||
|
|
58e538eff6 | ||
|
|
4f04c8aa89 |
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -22,9 +22,9 @@ namespace SabreTools.Serialization.CrossModel
|
||||
|
||||
if (item.Game != null && item.Game.Any())
|
||||
{
|
||||
machines.AddRange(item.Game
|
||||
.Where(g => g != null)
|
||||
.Select(ConvertMachineToInternalModel));
|
||||
machines.AddRange(item.Game
|
||||
.Where(g => g != null)
|
||||
.Select(ConvertMachineToInternalModel));
|
||||
}
|
||||
|
||||
if (item.Dir != null && item.Dir.Any())
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"))
|
||||
{
|
||||
@@ -289,7 +289,7 @@ namespace SabreTools.Serialization
|
||||
|
||||
try
|
||||
{
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(AssemblyManifest));
|
||||
var serializer = new XmlSerializer(typeof(AssemblyManifest));
|
||||
return serializer.Deserialize(new MemoryStream(entry.Data)) as AssemblyManifest;
|
||||
}
|
||||
catch
|
||||
@@ -358,7 +358,7 @@ namespace SabreTools.Serialization
|
||||
dialogTemplateExtended.MenuResource = entry.Data.ReadString(ref offset, Encoding.Unicode);
|
||||
|
||||
// Align to the WORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 2) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
@@ -394,7 +394,7 @@ namespace SabreTools.Serialization
|
||||
dialogTemplateExtended.ClassResource = entry.Data.ReadString(ref offset, Encoding.Unicode);
|
||||
|
||||
// Align to the WORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 2) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
@@ -425,7 +425,7 @@ namespace SabreTools.Serialization
|
||||
dialogTemplateExtended.TitleResource = entry.Data.ReadString(ref offset, Encoding.Unicode);
|
||||
|
||||
// Align to the WORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 2) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
@@ -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);
|
||||
@@ -447,9 +451,9 @@ namespace SabreTools.Serialization
|
||||
}
|
||||
|
||||
// Align to the DWORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 4) != 0)
|
||||
while (offset < entry.Data.Length && (offset % 4) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
}
|
||||
|
||||
@@ -502,7 +506,7 @@ namespace SabreTools.Serialization
|
||||
dialogItemTemplate.ClassResource = entry.Data.ReadString(ref offset, Encoding.Unicode);
|
||||
|
||||
// Align to the WORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 2) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
@@ -532,7 +536,7 @@ namespace SabreTools.Serialization
|
||||
dialogItemTemplate.TitleResource = entry.Data.ReadString(ref offset, Encoding.Unicode);
|
||||
|
||||
// Align to the WORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 2) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
@@ -550,16 +554,16 @@ namespace SabreTools.Serialization
|
||||
#endregion
|
||||
|
||||
// Align to the DWORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 4) != 0)
|
||||
while (offset < entry.Data.Length && (offset % 4) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
}
|
||||
|
||||
dialogItemExtendedTemplates.Add(dialogItemTemplate);
|
||||
}
|
||||
|
||||
dialogBoxResource.ExtendedDialogItemTemplates = dialogItemExtendedTemplates.ToArray();
|
||||
dialogBoxResource.ExtendedDialogItemTemplates = [.. dialogItemExtendedTemplates];
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -600,7 +604,7 @@ namespace SabreTools.Serialization
|
||||
dialogTemplate.MenuResource = entry.Data.ReadString(ref offset, Encoding.Unicode);
|
||||
|
||||
// Align to the WORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 2) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
@@ -636,7 +640,7 @@ namespace SabreTools.Serialization
|
||||
dialogTemplate.ClassResource = entry.Data.ReadString(ref offset, Encoding.Unicode);
|
||||
|
||||
// Align to the WORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 2) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
@@ -667,7 +671,7 @@ namespace SabreTools.Serialization
|
||||
dialogTemplate.TitleResource = entry.Data.ReadString(ref offset, Encoding.Unicode);
|
||||
|
||||
// Align to the WORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 2) != 0)
|
||||
_ = entry.Data.ReadByte(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);
|
||||
|
||||
@@ -688,9 +696,9 @@ namespace SabreTools.Serialization
|
||||
}
|
||||
|
||||
// Align to the DWORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 4) != 0)
|
||||
while (offset < entry.Data.Length && (offset % 4) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
}
|
||||
|
||||
@@ -742,7 +750,7 @@ namespace SabreTools.Serialization
|
||||
dialogItemTemplate.ClassResource = entry.Data.ReadString(ref offset, Encoding.Unicode);
|
||||
|
||||
// Align to the WORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 2) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
@@ -772,7 +780,7 @@ namespace SabreTools.Serialization
|
||||
dialogItemTemplate.TitleResource = entry.Data.ReadString(ref offset, Encoding.Unicode);
|
||||
|
||||
// Align to the WORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 2) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
@@ -790,16 +798,16 @@ namespace SabreTools.Serialization
|
||||
#endregion
|
||||
|
||||
// Align to the DWORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 4) != 0)
|
||||
while (offset < entry.Data.Length && (offset % 4) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
}
|
||||
|
||||
dialogItemTemplates.Add(dialogItemTemplate);
|
||||
}
|
||||
|
||||
dialogBoxResource.DialogItemTemplates = dialogItemTemplates.ToArray();
|
||||
dialogBoxResource.DialogItemTemplates = [.. dialogItemTemplates];
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -929,9 +937,9 @@ namespace SabreTools.Serialization
|
||||
extendedMenuItem.MenuText = entry.Data.ReadString(ref offset, Encoding.Unicode);
|
||||
|
||||
// Align to the DWORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 4) != 0)
|
||||
while (offset < entry.Data.Length && (offset % 4) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
}
|
||||
|
||||
@@ -939,7 +947,7 @@ namespace SabreTools.Serialization
|
||||
}
|
||||
}
|
||||
|
||||
menuResource.ExtendedMenuItems = extendedMenuItems.ToArray();
|
||||
menuResource.ExtendedMenuItems = [.. extendedMenuItems];
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -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);
|
||||
@@ -982,16 +994,16 @@ namespace SabreTools.Serialization
|
||||
}
|
||||
|
||||
// Align to the DWORD boundary if we're not at the end
|
||||
if (offset != entry.Data.Length)
|
||||
if (offset < entry.Data.Length)
|
||||
{
|
||||
while ((offset % 4) != 0)
|
||||
while (offset < entry.Data.Length && (offset % 4) != 0)
|
||||
_ = entry.Data.ReadByte(ref offset);
|
||||
}
|
||||
|
||||
menuItems.Add(menuItem);
|
||||
}
|
||||
|
||||
menuResource.MenuItems = menuItems.ToArray();
|
||||
menuResource.MenuItems = [.. menuItems];
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1033,7 +1045,7 @@ namespace SabreTools.Serialization
|
||||
messageResourceBlocks.Add(messageResourceBlock);
|
||||
}
|
||||
|
||||
messageResourceData.Blocks = messageResourceBlocks.ToArray();
|
||||
messageResourceData.Blocks = [.. messageResourceBlocks];
|
||||
}
|
||||
|
||||
// Message resource entries
|
||||
@@ -1138,7 +1150,7 @@ namespace SabreTools.Serialization
|
||||
if (versionInfo.Key != "VS_VERSION_INFO")
|
||||
return null;
|
||||
|
||||
while ((offset % 4) != 0)
|
||||
while (offset < entry.Data.Length && (offset % 4) != 0)
|
||||
versionInfo.Padding1 = entry.Data.ReadUInt16(ref offset);
|
||||
|
||||
// Read fixed file info
|
||||
@@ -1164,7 +1176,7 @@ namespace SabreTools.Serialization
|
||||
versionInfo.Value = fixedFileInfo;
|
||||
}
|
||||
|
||||
while ((offset % 4) != 0)
|
||||
while (offset < entry.Data.Length && (offset % 4) != 0)
|
||||
versionInfo.Padding2 = entry.Data.ReadUInt16(ref offset);
|
||||
|
||||
// TODO: Make the following block a private helper method
|
||||
@@ -1240,9 +1252,9 @@ namespace SabreTools.Serialization
|
||||
}
|
||||
|
||||
// Align to the DWORD boundary if we're not at the end
|
||||
if (offset != data.Length)
|
||||
if (offset < data.Length)
|
||||
{
|
||||
while ((offset % 4) != 0)
|
||||
while (offset < data.Length && (offset % 4) != 0)
|
||||
stringFileInfo.Padding = data.ReadByte(ref offset);
|
||||
}
|
||||
|
||||
@@ -1257,9 +1269,9 @@ namespace SabreTools.Serialization
|
||||
stringTable.Key = data.ReadString(ref offset, Encoding.Unicode);
|
||||
|
||||
// Align to the DWORD boundary if we're not at the end
|
||||
if (offset != data.Length)
|
||||
if (offset < data.Length)
|
||||
{
|
||||
while ((offset % 4) != 0)
|
||||
while (offset < data.Length && (offset % 4) != 0)
|
||||
stringTable.Padding = data.ReadByte(ref offset);
|
||||
}
|
||||
|
||||
@@ -1274,9 +1286,9 @@ namespace SabreTools.Serialization
|
||||
stringData.Key = data.ReadString(ref offset, Encoding.Unicode);
|
||||
|
||||
// Align to the DWORD boundary if we're not at the end
|
||||
if (offset != data.Length)
|
||||
if (offset < data.Length)
|
||||
{
|
||||
while ((offset % 4) != 0)
|
||||
while (offset < data.Length && (offset % 4) != 0)
|
||||
stringData.Padding = data.ReadByte(ref offset);
|
||||
}
|
||||
|
||||
@@ -1288,21 +1300,21 @@ namespace SabreTools.Serialization
|
||||
}
|
||||
|
||||
// Align to the DWORD boundary if we're not at the end
|
||||
if (offset != data.Length)
|
||||
if (offset < data.Length)
|
||||
{
|
||||
while ((offset % 4) != 0)
|
||||
while (offset < data.Length && (offset % 4) != 0)
|
||||
_ = data.ReadByte(ref offset);
|
||||
}
|
||||
|
||||
stringTableChildren.Add(stringData);
|
||||
}
|
||||
|
||||
stringTable.Children = stringTableChildren.ToArray();
|
||||
stringTable.Children = [.. stringTableChildren];
|
||||
|
||||
stringFileInfoChildren.Add(stringTable);
|
||||
}
|
||||
|
||||
stringFileInfo.Children = stringFileInfoChildren.ToArray();
|
||||
stringFileInfo.Children = [.. stringFileInfoChildren];
|
||||
|
||||
return stringFileInfo;
|
||||
}
|
||||
@@ -1328,9 +1340,9 @@ namespace SabreTools.Serialization
|
||||
return null;
|
||||
|
||||
// Align to the DWORD boundary if we're not at the end
|
||||
if (offset != data.Length)
|
||||
if (offset < data.Length)
|
||||
{
|
||||
while ((offset % 4) != 0)
|
||||
while (offset < data.Length && (offset % 4) != 0)
|
||||
varFileInfo.Padding = data.ReadByte(ref offset);
|
||||
}
|
||||
|
||||
@@ -1350,9 +1362,9 @@ namespace SabreTools.Serialization
|
||||
}
|
||||
|
||||
// Align to the DWORD boundary if we're not at the end
|
||||
if (offset != data.Length)
|
||||
if (offset < data.Length)
|
||||
{
|
||||
while ((offset % 4) != 0)
|
||||
while (offset < data.Length && (offset % 4) != 0)
|
||||
varData.Padding = data.ReadByte(ref offset);
|
||||
}
|
||||
|
||||
@@ -1366,12 +1378,12 @@ namespace SabreTools.Serialization
|
||||
varDataValue.Add(languageAndCodeIdentifierPair);
|
||||
}
|
||||
|
||||
varData.Value = varDataValue.ToArray();
|
||||
varData.Value = [.. varDataValue];
|
||||
|
||||
varFileInfoChildren.Add(varData);
|
||||
}
|
||||
|
||||
varFileInfo.Children = varFileInfoChildren.ToArray();
|
||||
varFileInfo.Children = [.. varFileInfoChildren];
|
||||
|
||||
return varFileInfo;
|
||||
}
|
||||
|
||||
@@ -9,20 +9,16 @@ 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))
|
||||
{
|
||||
if (stream == null)
|
||||
return false;
|
||||
using var stream = new Streams.AttractMode().Serialize(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using (var fs = File.OpenWrite(path))
|
||||
{
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
using var fs = File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,20 +12,16 @@ 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))
|
||||
{
|
||||
if (stream == null)
|
||||
return false;
|
||||
using var stream = new Streams.ClrMamePro().Serialize(obj, quotes);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using (var fs = File.OpenWrite(path))
|
||||
{
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
using var fs = File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -8,20 +8,16 @@ 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))
|
||||
{
|
||||
if (stream == null)
|
||||
return false;
|
||||
using var stream = new Streams.CueSheet().Serialize(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using (var fs = File.OpenWrite(path))
|
||||
{
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
using var fs = File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,20 +8,16 @@ 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))
|
||||
{
|
||||
if (stream == null)
|
||||
return false;
|
||||
using var stream = new Streams.DosCenter().Serialize(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using (var fs = System.IO.File.OpenWrite(path))
|
||||
{
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
using var fs = System.IO.File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,20 +8,16 @@ 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))
|
||||
{
|
||||
if (stream == null)
|
||||
return false;
|
||||
using var stream = new Streams.EverdriveSMDB().Serialize(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using (var fs = System.IO.File.OpenWrite(path))
|
||||
{
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
using var fs = System.IO.File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,20 +10,16 @@ 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))
|
||||
{
|
||||
if (stream == null)
|
||||
return false;
|
||||
using var stream = new Streams.Hashfile().Serialize(obj, hash);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using (var fs = System.IO.File.OpenWrite(path))
|
||||
{
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
using var fs = System.IO.File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,20 +7,16 @@ 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))
|
||||
{
|
||||
if (stream == null)
|
||||
return false;
|
||||
using var stream = new Streams.IRD().Serialize(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using (var fs = System.IO.File.OpenWrite(path))
|
||||
{
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
using var fs = System.IO.File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,20 +8,16 @@ 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))
|
||||
{
|
||||
if (stream == null)
|
||||
return false;
|
||||
using var stream = new Streams.Listrom().Serialize(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using (var fs = System.IO.File.OpenWrite(path))
|
||||
{
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
using var fs = System.IO.File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,20 +8,16 @@ 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))
|
||||
{
|
||||
if (stream == null)
|
||||
return false;
|
||||
using var stream = new Streams.PIC().Serialize(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using (var fs = System.IO.File.OpenWrite(path))
|
||||
{
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
using var fs = System.IO.File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,20 +8,16 @@ 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))
|
||||
{
|
||||
if (stream == null)
|
||||
return false;
|
||||
using var stream = new Streams.RomCenter().Serialize(obj);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using (var fs = System.IO.File.OpenWrite(path))
|
||||
{
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
using var fs = System.IO.File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,20 +11,16 @@ 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))
|
||||
{
|
||||
if (stream == null)
|
||||
return false;
|
||||
using var stream = new Streams.SeparatedValue().Serialize(obj, delim);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using (var fs = System.IO.File.OpenWrite(path))
|
||||
{
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
using var fs = System.IO.File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,21 +26,17 @@ 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))
|
||||
{
|
||||
if (stream == null)
|
||||
return false;
|
||||
using var stream = new Streams.XmlFile<T>().Serialize(obj, name, pubid, sysid, subset);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
using (var fs = File.OpenWrite(path))
|
||||
{
|
||||
stream.CopyTo(fs);
|
||||
}
|
||||
using var fs = File.OpenWrite(path);
|
||||
stream.CopyTo(fs);
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Internal.cs
25
Internal.cs
@@ -29,7 +29,7 @@ namespace SabreTools.Serialization
|
||||
if (sccPlusCart != null)
|
||||
datItems.Add(sccPlusCart);
|
||||
|
||||
return datItems.ToArray();
|
||||
return [.. datItems];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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,17 +60,19 @@ 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();
|
||||
return [.. datItems];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -79,13 +82,9 @@ 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();
|
||||
return [.. roms];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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
50
OldDotNet.cs
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
<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>
|
||||
<Nullable>enable</Nullable>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>1.2.0</Version>
|
||||
<Version>1.3.0</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
@@ -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>
|
||||
|
||||
@@ -48,9 +48,9 @@ namespace SabreTools.Serialization.Streams
|
||||
break;
|
||||
|
||||
// Align to the 4-byte boundary if we're not at the end
|
||||
if (data.Position != data.Length)
|
||||
if (data.Position < data.Length)
|
||||
{
|
||||
while ((data.Position % 4) != 0)
|
||||
while (data.Position < data.Length && (data.Position % 4) != 0)
|
||||
_ = data.ReadByteValue();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace SabreTools.Serialization.Streams
|
||||
{
|
||||
case "doscenter":
|
||||
if (dat.ClrMamePro != null)
|
||||
dat.ClrMamePro.ADDITIONAL_ELEMENTS = headerAdditional.ToArray();
|
||||
dat.ClrMamePro.ADDITIONAL_ELEMENTS = [.. headerAdditional];
|
||||
|
||||
headerAdditional.Clear();
|
||||
break;
|
||||
@@ -70,17 +70,17 @@ namespace SabreTools.Serialization.Streams
|
||||
case "set":
|
||||
if (game != null)
|
||||
{
|
||||
game.Release = releases.ToArray();
|
||||
game.BiosSet = biosSets.ToArray();
|
||||
game.Rom = roms.ToArray();
|
||||
game.Disk = disks.ToArray();
|
||||
game.Media = medias.ToArray();
|
||||
game.Sample = samples.ToArray();
|
||||
game.Archive = archives.ToArray();
|
||||
game.Chip = chips.ToArray();
|
||||
game.Video = videos.ToArray();
|
||||
game.DipSwitch = dipSwitches.ToArray();
|
||||
game.ADDITIONAL_ELEMENTS = gameAdditional.ToArray();
|
||||
game.Release = [.. releases];
|
||||
game.BiosSet = [.. biosSets];
|
||||
game.Rom = [.. roms];
|
||||
game.Disk = [.. disks];
|
||||
game.Media = [.. medias];
|
||||
game.Sample = [.. samples];
|
||||
game.Archive = [.. archives];
|
||||
game.Chip = [.. chips];
|
||||
game.Video = [.. videos];
|
||||
game.DipSwitch = [.. dipSwitches];
|
||||
game.ADDITIONAL_ELEMENTS = [.. gameAdditional];
|
||||
|
||||
games.Add(game);
|
||||
game = null;
|
||||
@@ -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;
|
||||
@@ -347,8 +343,8 @@ namespace SabreTools.Serialization.Streams
|
||||
}
|
||||
|
||||
// Add extra pieces and return
|
||||
dat.Game = games.ToArray();
|
||||
dat.ADDITIONAL_ELEMENTS = additional.ToArray();
|
||||
dat.Game = [.. games];
|
||||
dat.ADDITIONAL_ELEMENTS = [.. additional];
|
||||
return dat;
|
||||
}
|
||||
|
||||
@@ -389,7 +385,7 @@ namespace SabreTools.Serialization.Streams
|
||||
}
|
||||
}
|
||||
|
||||
release.ADDITIONAL_ELEMENTS = itemAdditional.ToArray();
|
||||
release.ADDITIONAL_ELEMENTS = [.. itemAdditional];
|
||||
return release;
|
||||
}
|
||||
|
||||
@@ -424,7 +420,7 @@ namespace SabreTools.Serialization.Streams
|
||||
}
|
||||
}
|
||||
|
||||
biosset.ADDITIONAL_ELEMENTS = itemAdditional.ToArray();
|
||||
biosset.ADDITIONAL_ELEMENTS = [.. itemAdditional];
|
||||
return biosset;
|
||||
}
|
||||
|
||||
@@ -513,7 +509,7 @@ namespace SabreTools.Serialization.Streams
|
||||
}
|
||||
}
|
||||
|
||||
rom.ADDITIONAL_ELEMENTS = itemAdditional.ToArray();
|
||||
rom.ADDITIONAL_ELEMENTS = [.. itemAdditional];
|
||||
return rom;
|
||||
}
|
||||
|
||||
@@ -557,7 +553,7 @@ namespace SabreTools.Serialization.Streams
|
||||
}
|
||||
}
|
||||
|
||||
disk.ADDITIONAL_ELEMENTS = itemAdditional.ToArray();
|
||||
disk.ADDITIONAL_ELEMENTS = [.. itemAdditional];
|
||||
return disk;
|
||||
}
|
||||
|
||||
@@ -598,7 +594,7 @@ namespace SabreTools.Serialization.Streams
|
||||
}
|
||||
}
|
||||
|
||||
media.ADDITIONAL_ELEMENTS = itemAdditional.ToArray();
|
||||
media.ADDITIONAL_ELEMENTS = [.. itemAdditional];
|
||||
return media;
|
||||
}
|
||||
|
||||
@@ -627,7 +623,7 @@ namespace SabreTools.Serialization.Streams
|
||||
}
|
||||
}
|
||||
|
||||
sample.ADDITIONAL_ELEMENTS = itemAdditional.ToArray();
|
||||
sample.ADDITIONAL_ELEMENTS = [.. itemAdditional];
|
||||
return sample;
|
||||
}
|
||||
|
||||
@@ -656,7 +652,7 @@ namespace SabreTools.Serialization.Streams
|
||||
}
|
||||
}
|
||||
|
||||
archive.ADDITIONAL_ELEMENTS = itemAdditional.ToArray();
|
||||
archive.ADDITIONAL_ELEMENTS = [.. itemAdditional];
|
||||
return archive;
|
||||
}
|
||||
|
||||
@@ -850,7 +846,7 @@ namespace SabreTools.Serialization.Streams
|
||||
}
|
||||
}
|
||||
|
||||
dipswitch.Entry = entries.ToArray();
|
||||
dipswitch.Entry = [.. entries];
|
||||
dipswitch.ADDITIONAL_ELEMENTS = itemAdditional.ToArray();
|
||||
return dipswitch;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -178,26 +179,15 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <returns>String, if possible (default BINARY)</returns>
|
||||
private static string FromFileType(CueFileType fileType)
|
||||
{
|
||||
switch (fileType)
|
||||
return fileType switch
|
||||
{
|
||||
case CueFileType.BINARY:
|
||||
return "BINARY";
|
||||
|
||||
case CueFileType.MOTOROLA:
|
||||
return "MOTOROLA";
|
||||
|
||||
case CueFileType.AIFF:
|
||||
return "AIFF";
|
||||
|
||||
case CueFileType.WAVE:
|
||||
return "WAVE";
|
||||
|
||||
case CueFileType.MP3:
|
||||
return "MP3";
|
||||
|
||||
default:
|
||||
return string.Empty;
|
||||
}
|
||||
CueFileType.BINARY => "BINARY",
|
||||
CueFileType.MOTOROLA => "MOTOROLA",
|
||||
CueFileType.AIFF => "AIFF",
|
||||
CueFileType.WAVE => "WAVE",
|
||||
CueFileType.MP3 => "MP3",
|
||||
_ => string.Empty,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -207,35 +197,18 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <returns>string, if possible</returns>
|
||||
private static string FromDataType(CueTrackDataType dataType)
|
||||
{
|
||||
switch (dataType)
|
||||
return dataType switch
|
||||
{
|
||||
case CueTrackDataType.AUDIO:
|
||||
return "AUDIO";
|
||||
|
||||
case CueTrackDataType.CDG:
|
||||
return "CDG";
|
||||
|
||||
case CueTrackDataType.MODE1_2048:
|
||||
return "MODE1/2048";
|
||||
|
||||
case CueTrackDataType.MODE1_2352:
|
||||
return "MODE1/2352";
|
||||
|
||||
case CueTrackDataType.MODE2_2336:
|
||||
return "MODE2/2336";
|
||||
|
||||
case CueTrackDataType.MODE2_2352:
|
||||
return "MODE2/2352";
|
||||
|
||||
case CueTrackDataType.CDI_2336:
|
||||
return "CDI/2336";
|
||||
|
||||
case CueTrackDataType.CDI_2352:
|
||||
return "CDI/2352";
|
||||
|
||||
default:
|
||||
return string.Empty;
|
||||
}
|
||||
CueTrackDataType.AUDIO => "AUDIO",
|
||||
CueTrackDataType.CDG => "CDG",
|
||||
CueTrackDataType.MODE1_2048 => "MODE1/2048",
|
||||
CueTrackDataType.MODE1_2352 => "MODE1/2352",
|
||||
CueTrackDataType.MODE2_2336 => "MODE2/2336",
|
||||
CueTrackDataType.MODE2_2352 => "MODE2/2352",
|
||||
CueTrackDataType.CDI_2336 => "CDI/2336",
|
||||
CueTrackDataType.CDI_2352 => "CDI/2352",
|
||||
_ => string.Empty,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -247,19 +220,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();
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace SabreTools.Serialization.Streams
|
||||
// Read and split the line
|
||||
string? line = reader.ReadLine();
|
||||
#if NETFRAMEWORK || NETCOREAPP3_1
|
||||
string[]? lineParts = line?.Split(new char[] { ' ' } , StringSplitOptions.RemoveEmptyEntries);
|
||||
string[]? lineParts = line?.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
#else
|
||||
string[]? lineParts = line?.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -154,7 +154,7 @@ namespace SabreTools.Serialization.Streams
|
||||
dat.SpamSum = hashes.Cast<SpamSum>().ToArray();
|
||||
break;
|
||||
}
|
||||
dat.ADDITIONAL_ELEMENTS = additional.ToArray();
|
||||
dat.ADDITIONAL_ELEMENTS = [.. additional];
|
||||
return dat;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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! });
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -166,7 +166,7 @@ namespace SabreTools.Serialization.Streams
|
||||
}
|
||||
|
||||
// Assign the resident names table
|
||||
executable.ResidentNamesTable = residentNamesTable.ToArray();
|
||||
executable.ResidentNamesTable = [.. residentNamesTable];
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -196,7 +196,7 @@ namespace SabreTools.Serialization.Streams
|
||||
}
|
||||
|
||||
// Assign the entry table
|
||||
executable.EntryTable = entryTable.ToArray();
|
||||
executable.EntryTable = [.. entryTable];
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -337,7 +337,7 @@ namespace SabreTools.Serialization.Streams
|
||||
}
|
||||
|
||||
// Assign the resident names table
|
||||
executable.ImportModuleProcedureNameTable = importModuleProcedureNameTable.ToArray();
|
||||
executable.ImportModuleProcedureNameTable = [.. importModuleProcedureNameTable];
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -391,7 +391,7 @@ namespace SabreTools.Serialization.Streams
|
||||
}
|
||||
|
||||
// Assign the non-resident names table
|
||||
executable.NonResidentNamesTable = nonResidentNamesTable.ToArray();
|
||||
executable.NonResidentNamesTable = [.. nonResidentNamesTable];
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -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++)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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}) ");
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <returns>Filled cabinet header on success, null on error</returns>
|
||||
private static CFHEADER? ParseCabinetHeader(Stream data)
|
||||
{
|
||||
CFHEADER header = new CFHEADER();
|
||||
var header = new CFHEADER();
|
||||
|
||||
byte[]? signature = data.ReadBytes(4);
|
||||
if (signature == null)
|
||||
@@ -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);
|
||||
@@ -152,7 +164,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <returns>Filled folder on success, null on error</returns>
|
||||
private static CFFOLDER ParseFolder(Stream data, CFHEADER header)
|
||||
{
|
||||
CFFOLDER folder = new CFFOLDER();
|
||||
var folder = new CFFOLDER();
|
||||
|
||||
folder.CabStartOffset = data.ReadUInt32();
|
||||
folder.DataCount = data.ReadUInt16();
|
||||
@@ -187,7 +199,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <returns>Filled folder on success, null on error</returns>
|
||||
private static CFDATA ParseDataBlock(Stream data, byte dataReservedSize)
|
||||
{
|
||||
CFDATA dataBlock = new CFDATA();
|
||||
var dataBlock = new CFDATA();
|
||||
|
||||
dataBlock.Checksum = data.ReadUInt32();
|
||||
dataBlock.CompressedSize = data.ReadUInt16();
|
||||
@@ -209,7 +221,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <returns>Filled file on success, null on error</returns>
|
||||
private static CFFILE ParseFile(Stream data)
|
||||
{
|
||||
CFFILE file = new CFFILE();
|
||||
var file = new CFFILE();
|
||||
|
||||
file.FileSize = data.ReadUInt32();
|
||||
file.FolderStartOffset = data.ReadUInt32();
|
||||
@@ -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);
|
||||
|
||||
@@ -186,7 +186,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static NCSDHeader? ParseNCSDHeader(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
NCSDHeader header = new NCSDHeader();
|
||||
var header = new NCSDHeader();
|
||||
|
||||
header.RSA2048Signature = data.ReadBytes(0x100);
|
||||
byte[]? magicNumber = data.ReadBytes(4);
|
||||
@@ -243,7 +243,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static PartitionTableEntry ParsePartitionTableEntry(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
PartitionTableEntry partitionTableEntry = new PartitionTableEntry();
|
||||
var partitionTableEntry = new PartitionTableEntry();
|
||||
|
||||
partitionTableEntry.Offset = data.ReadUInt32();
|
||||
partitionTableEntry.Length = data.ReadUInt32();
|
||||
@@ -259,7 +259,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static CardInfoHeader ParseCardInfoHeader(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
CardInfoHeader cardInfoHeader = new CardInfoHeader();
|
||||
var cardInfoHeader = new CardInfoHeader();
|
||||
|
||||
cardInfoHeader.WritableAddressMediaUnits = data.ReadUInt32();
|
||||
cardInfoHeader.CardInfoBitmask = data.ReadUInt32();
|
||||
@@ -284,7 +284,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static DevelopmentCardInfoHeader? ParseDevelopmentCardInfoHeader(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
DevelopmentCardInfoHeader developmentCardInfoHeader = new DevelopmentCardInfoHeader();
|
||||
var developmentCardInfoHeader = new DevelopmentCardInfoHeader();
|
||||
|
||||
developmentCardInfoHeader.InitialData = ParseInitialData(data);
|
||||
if (developmentCardInfoHeader.InitialData == null)
|
||||
@@ -309,7 +309,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static InitialData? ParseInitialData(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
InitialData initialData = new InitialData();
|
||||
var initialData = new InitialData();
|
||||
|
||||
initialData.CardSeedKeyY = data.ReadBytes(0x10);
|
||||
initialData.EncryptedCardSeed = data.ReadBytes(0x10);
|
||||
@@ -332,7 +332,7 @@ namespace SabreTools.Serialization.Streams
|
||||
internal static NCCHHeader ParseNCCHHeader(Stream data, bool skipSignature = false)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
NCCHHeader header = new NCCHHeader();
|
||||
var header = new NCCHHeader();
|
||||
|
||||
if (!skipSignature)
|
||||
header.RSA2048Signature = data.ReadBytes(0x100);
|
||||
@@ -381,7 +381,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static NCCHHeaderFlags ParseNCCHHeaderFlags(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
NCCHHeaderFlags headerFlags = new NCCHHeaderFlags();
|
||||
var headerFlags = new NCCHHeaderFlags();
|
||||
|
||||
headerFlags.Reserved0 = data.ReadByteValue();
|
||||
headerFlags.Reserved1 = data.ReadByteValue();
|
||||
@@ -403,7 +403,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static TestData ParseTestData(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
TestData testData = new TestData();
|
||||
var testData = new TestData();
|
||||
|
||||
// TODO: Validate some of the values
|
||||
testData.Signature = data.ReadBytes(8);
|
||||
@@ -428,7 +428,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static NCCHExtendedHeader? ParseNCCHExtendedHeader(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
NCCHExtendedHeader extendedHeader = new NCCHExtendedHeader();
|
||||
var extendedHeader = new NCCHExtendedHeader();
|
||||
|
||||
extendedHeader.SCI = ParseSystemControlInfo(data);
|
||||
if (extendedHeader.SCI == null)
|
||||
@@ -456,7 +456,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static SystemControlInfo ParseSystemControlInfo(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
SystemControlInfo systemControlInfo = new SystemControlInfo();
|
||||
var systemControlInfo = new SystemControlInfo();
|
||||
|
||||
byte[]? applicationTitle = data.ReadBytes(8);
|
||||
if (applicationTitle != null)
|
||||
@@ -488,7 +488,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static CodeSetInfo ParseCodeSetInfo(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
CodeSetInfo codeSetInfo = new CodeSetInfo();
|
||||
var codeSetInfo = new CodeSetInfo();
|
||||
|
||||
codeSetInfo.Address = data.ReadUInt32();
|
||||
codeSetInfo.PhysicalRegionSizeInPages = data.ReadUInt32();
|
||||
@@ -505,7 +505,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static SystemInfo ParseSystemInfo(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
SystemInfo systemInfo = new SystemInfo();
|
||||
var systemInfo = new SystemInfo();
|
||||
|
||||
systemInfo.SaveDataSize = data.ReadUInt64();
|
||||
systemInfo.JumpID = data.ReadUInt64();
|
||||
@@ -522,7 +522,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static AccessControlInfo ParseAccessControlInfo(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
AccessControlInfo accessControlInfo = new AccessControlInfo();
|
||||
var accessControlInfo = new AccessControlInfo();
|
||||
|
||||
accessControlInfo.ARM11LocalSystemCapabilities = ParseARM11LocalSystemCapabilities(data);
|
||||
accessControlInfo.ARM11KernelCapabilities = ParseARM11KernelCapabilities(data);
|
||||
@@ -539,7 +539,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static ARM11LocalSystemCapabilities ParseARM11LocalSystemCapabilities(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
ARM11LocalSystemCapabilities arm11LocalSystemCapabilities = new ARM11LocalSystemCapabilities();
|
||||
var arm11LocalSystemCapabilities = new ARM11LocalSystemCapabilities();
|
||||
|
||||
arm11LocalSystemCapabilities.ProgramID = data.ReadUInt64();
|
||||
arm11LocalSystemCapabilities.CoreVersion = data.ReadUInt32();
|
||||
@@ -577,7 +577,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static StorageInfo ParseStorageInfo(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
StorageInfo storageInfo = new StorageInfo();
|
||||
var storageInfo = new StorageInfo();
|
||||
|
||||
storageInfo.ExtdataID = data.ReadUInt64();
|
||||
storageInfo.SystemSavedataIDs = data.ReadBytes(8);
|
||||
@@ -596,7 +596,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static ARM11KernelCapabilities ParseARM11KernelCapabilities(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
ARM11KernelCapabilities arm11KernelCapabilities = new ARM11KernelCapabilities();
|
||||
var arm11KernelCapabilities = new ARM11KernelCapabilities();
|
||||
|
||||
arm11KernelCapabilities.Descriptors = new uint[28];
|
||||
for (int i = 0; i < 28; i++)
|
||||
@@ -616,7 +616,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static ARM9AccessControl ParseARM9AccessControl(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
ARM9AccessControl arm9AccessControl = new ARM9AccessControl();
|
||||
var arm9AccessControl = new ARM9AccessControl();
|
||||
|
||||
arm9AccessControl.Descriptors = data.ReadBytes(15);
|
||||
arm9AccessControl.DescriptorVersion = data.ReadByteValue();
|
||||
@@ -632,7 +632,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static ExeFSHeader ParseExeFSHeader(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
ExeFSHeader exeFSHeader = new ExeFSHeader();
|
||||
var exeFSHeader = new ExeFSHeader();
|
||||
|
||||
exeFSHeader.FileHeaders = new ExeFSFileHeader[10];
|
||||
for (int i = 0; i < 10; i++)
|
||||
@@ -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;
|
||||
@@ -661,7 +657,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static ExeFSFileHeader ParseExeFSFileHeader(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
ExeFSFileHeader exeFSFileHeader = new ExeFSFileHeader();
|
||||
var exeFSFileHeader = new ExeFSFileHeader();
|
||||
|
||||
byte[]? fileName = data.ReadBytes(8);
|
||||
if (fileName != null)
|
||||
@@ -680,7 +676,7 @@ namespace SabreTools.Serialization.Streams
|
||||
private static RomFSHeader? ParseRomFSHeader(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
RomFSHeader romFSHeader = new RomFSHeader();
|
||||
var romFSHeader = new RomFSHeader();
|
||||
|
||||
byte[]? magicString = data.ReadBytes(4);
|
||||
if (magicString == null)
|
||||
|
||||
@@ -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()
|
||||
@@ -339,7 +335,7 @@ namespace SabreTools.Serialization.Streams
|
||||
.ToList();
|
||||
|
||||
// Populate the type and name string dictionary
|
||||
resourceTable.TypeAndNameStrings = new Dictionary<ushort, ResourceTypeAndNameString?>();
|
||||
resourceTable.TypeAndNameStrings = [];
|
||||
for (int i = 0; i < stringOffsets.Count; i++)
|
||||
{
|
||||
int stringOffset = (int)(stringOffsets[i] + initialOffset);
|
||||
@@ -373,7 +369,7 @@ namespace SabreTools.Serialization.Streams
|
||||
residentNameTable.Add(entry);
|
||||
}
|
||||
|
||||
return residentNameTable.ToArray();
|
||||
return [.. residentNameTable];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -456,7 +452,7 @@ namespace SabreTools.Serialization.Streams
|
||||
entryTable.Add(entry);
|
||||
}
|
||||
|
||||
return entryTable.ToArray();
|
||||
return [.. entryTable];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -479,7 +475,7 @@ namespace SabreTools.Serialization.Streams
|
||||
residentNameTable.Add(entry);
|
||||
}
|
||||
|
||||
return residentNameTable.ToArray();
|
||||
return [.. residentNameTable];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -716,7 +716,7 @@ namespace SabreTools.Serialization.Streams
|
||||
{
|
||||
var attributeCertificateTable = new List<AttributeCertificateTableEntry>();
|
||||
|
||||
while (data.Position < endOffset && data.Position != data.Length)
|
||||
while (data.Position < endOffset && data.Position < data.Length)
|
||||
{
|
||||
var entry = new AttributeCertificateTableEntry();
|
||||
|
||||
@@ -731,7 +731,7 @@ namespace SabreTools.Serialization.Streams
|
||||
attributeCertificateTable.Add(entry);
|
||||
|
||||
// Align to the 8-byte boundary
|
||||
while ((data.Position % 8) != 0 && data.Position < endOffset && data.Position != data.Length)
|
||||
while ((data.Position % 8) != 0 && data.Position < endOffset && data.Position < data.Length)
|
||||
_ = data.ReadByteValue();
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,15 +90,36 @@ 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());
|
||||
fileInfo.BlockEntries = blockEntries.ToArray();
|
||||
#endif
|
||||
fileInfo.BlockEntries = [.. blockEntries];
|
||||
|
||||
// Add the file info and continue
|
||||
files.Add(fileInfo);
|
||||
}
|
||||
|
||||
// Set and return the file infos
|
||||
_files = files.ToArray();
|
||||
_files = [.. files];
|
||||
return _files;
|
||||
}
|
||||
}
|
||||
@@ -170,7 +201,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
return null;
|
||||
|
||||
// Create a memory stream and use that
|
||||
MemoryStream dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return Create(dataStream);
|
||||
}
|
||||
|
||||
|
||||
@@ -344,7 +344,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
// If we're at the end of the file, cache an empty list
|
||||
if (endOfSectionData >= endOfFile)
|
||||
{
|
||||
_overlayStrings = new List<string>();
|
||||
_overlayStrings = [];
|
||||
return _overlayStrings;
|
||||
}
|
||||
|
||||
@@ -467,7 +467,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
return null;
|
||||
|
||||
// Otherwise, build and return the cached dictionary
|
||||
ParseResourceDirectoryTable(this.Model.ResourceDirectoryTable, types: new List<object>());
|
||||
ParseResourceDirectoryTable(this.Model.ResourceDirectoryTable, types: []);
|
||||
return _resourceData;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -707,12 +707,12 @@ namespace SabreTools.Serialization.Wrappers
|
||||
/// <summary>
|
||||
/// Cached debug data
|
||||
/// </summary>
|
||||
private readonly Dictionary<int, object> _debugData = new Dictionary<int, object>();
|
||||
private readonly Dictionary<int, object> _debugData = [];
|
||||
|
||||
/// <summary>
|
||||
/// Cached resource data
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, object?> _resourceData = new Dictionary<string, object?>();
|
||||
private readonly Dictionary<string, object?> _resourceData = [];
|
||||
|
||||
/// <summary>
|
||||
/// Cached version info data
|
||||
@@ -727,7 +727,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
/// <summary>
|
||||
/// Lock object for reading from the source
|
||||
/// </summary>
|
||||
private readonly object _sourceDataLock = new object();
|
||||
private readonly object _sourceDataLock = new();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -764,7 +764,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
return null;
|
||||
|
||||
// Create a memory stream and use that
|
||||
MemoryStream dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
var dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return Create(dataStream);
|
||||
}
|
||||
|
||||
@@ -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[])
|
||||
@@ -1149,7 +1145,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
if (entry == null)
|
||||
continue;
|
||||
|
||||
var newTypes = new List<object>(types ?? new List<object>());
|
||||
var newTypes = new List<object>(types ?? []);
|
||||
|
||||
if (entry.Name?.UnicodeString != null)
|
||||
newTypes.Add(Encoding.UTF8.GetString(entry.Name.UnicodeString));
|
||||
@@ -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
|
||||
@@ -1473,8 +1469,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
lock (_sourceDataLock)
|
||||
{
|
||||
// Create the section data array if we have to
|
||||
if (_sectionData == null)
|
||||
_sectionData = new byte[SectionNames.Length][];
|
||||
_sectionData ??= new byte[SectionNames.Length][];
|
||||
|
||||
// If we already have cached data, just use that immediately
|
||||
if (_sectionData[index] != null)
|
||||
@@ -1560,8 +1555,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
lock (_sourceDataLock)
|
||||
{
|
||||
// Create the section string array if we have to
|
||||
if (_sectionStringData == null)
|
||||
_sectionStringData = new List<string>[SectionNames.Length];
|
||||
_sectionStringData ??= new List<string>[SectionNames.Length];
|
||||
|
||||
// If we already have cached data, just use that immediately
|
||||
if (_sectionStringData[index] != null)
|
||||
@@ -1673,8 +1667,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
lock (_sourceDataLock)
|
||||
{
|
||||
// Create the table data array if we have to
|
||||
if (_tableData == null)
|
||||
_tableData = new byte[16][];
|
||||
_tableData ??= new byte[16][];
|
||||
|
||||
// If we already have cached data, just use that immediately
|
||||
if (_tableData[index] != null)
|
||||
@@ -1782,8 +1775,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
lock (_sourceDataLock)
|
||||
{
|
||||
// Create the table string array if we have to
|
||||
if (_tableStringData == null)
|
||||
_tableStringData = new List<string>[16];
|
||||
_tableStringData ??= new List<string>[16];
|
||||
|
||||
// If we already have cached data, just use that immediately
|
||||
if (_tableStringData[index] != null)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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!))
|
||||
|
||||
@@ -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!))
|
||||
|
||||
Reference in New Issue
Block a user