mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-02-04 13:45:40 +00:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69e1f5ff0b | ||
|
|
d265c14841 | ||
|
|
1148245226 | ||
|
|
f53d9f94e6 | ||
|
|
4e3d832834 | ||
|
|
0713dfafb2 | ||
|
|
c0d4f403c3 | ||
|
|
5ed79166cf | ||
|
|
17030cfb9f | ||
|
|
530fa69d3c | ||
|
|
7a5956f599 | ||
|
|
5562768509 | ||
|
|
aa538df229 | ||
|
|
b7b22cba32 | ||
|
|
fc489125d9 | ||
|
|
036589473d | ||
|
|
432ce85f89 | ||
|
|
438e8067eb | ||
|
|
9715507aaf | ||
|
|
b745d4b9f6 | ||
|
|
4271bd86b3 | ||
|
|
88de4be27b | ||
|
|
33905165f7 | ||
|
|
83ec3b6950 | ||
|
|
9b5d51884c | ||
|
|
aaa6422921 | ||
|
|
f24b88031b | ||
|
|
edf9fed751 |
43
.github/workflows/build_nupkg.yml
vendored
Normal file
43
.github/workflows/build_nupkg.yml
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
name: Nuget Pack
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 8.0.x
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
- name: Pack
|
||||
run: dotnet pack
|
||||
|
||||
- name: Upload build
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: 'Nuget Package'
|
||||
path: 'bin/Release/*.nupkg'
|
||||
|
||||
- name: Upload to rolling
|
||||
uses: ncipollo/release-action@v1.14.0
|
||||
with:
|
||||
allowUpdates: True
|
||||
artifacts: 'bin/Release/*.nupkg'
|
||||
body: 'Last built commit: ${{ github.sha }}'
|
||||
name: 'Rolling Release'
|
||||
prerelease: True
|
||||
replacesArtifacts: True
|
||||
tag: "rolling"
|
||||
updateOnlyUnreleased: True
|
||||
17
.github/workflows/check_pr.yml
vendored
Normal file
17
.github/workflows/check_pr.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
name: Build PR
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 8.0.x
|
||||
|
||||
- name: Build
|
||||
run: dotnet build
|
||||
@@ -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)
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
|
||||
var metadataFile = new Models.Metadata.MetadataFile
|
||||
{
|
||||
[Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(item),
|
||||
@@ -45,10 +45,12 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// </summary>
|
||||
private static Models.Metadata.Machine ConvertMachineToInternalModel(Models.ArchiveDotOrg.File? item)
|
||||
{
|
||||
var machine = new Models.Metadata.Machine
|
||||
{
|
||||
[Models.Metadata.Machine.RomKey] = ConvertToInternalModel(item),
|
||||
};
|
||||
var machine = new Models.Metadata.Machine();
|
||||
|
||||
var rom = ConvertToInternalModel(item);
|
||||
if (rom != null)
|
||||
machine[Models.Metadata.Machine.RomKey] = new Models.Metadata.Rom[] { rom };
|
||||
|
||||
return machine;
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
@@ -65,8 +65,8 @@ namespace SabreTools.Serialization.CrossModel
|
||||
datItems.Add(ConvertToInternalModel(file));
|
||||
}
|
||||
|
||||
machine[Models.Metadata.Machine.DiskKey] = datItems.Where(i => i.ReadString(Models.Metadata.DatItem.TypeKey) == "disk")?.ToArray();
|
||||
machine[Models.Metadata.Machine.RomKey] = datItems.Where(i => i.ReadString(Models.Metadata.DatItem.TypeKey) == "rom")?.ToArray();
|
||||
machine[Models.Metadata.Machine.DiskKey] = datItems.Where(i => i.ReadString(Models.Metadata.DatItem.TypeKey) == "disk").Select(d => d as Models.Metadata.Disk).ToArray();
|
||||
machine[Models.Metadata.Machine.RomKey] = datItems.Where(i => i.ReadString(Models.Metadata.DatItem.TypeKey) == "rom").Select(d => d as Models.Metadata.Rom).ToArray();
|
||||
}
|
||||
|
||||
return machine;
|
||||
@@ -81,6 +81,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
var disk = new Models.Metadata.Disk
|
||||
{
|
||||
[Models.Metadata.DatItem.TypeKey] = "disk",
|
||||
[Models.Metadata.Disk.NameKey] = item.Name,
|
||||
[Models.Metadata.Disk.MD5Key] = item.MD5,
|
||||
[Models.Metadata.Disk.SHA1Key] = item.SHA1,
|
||||
@@ -97,6 +98,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
var rom = new Models.Metadata.Rom
|
||||
{
|
||||
[Models.Metadata.DatItem.TypeKey] = "rom",
|
||||
[Models.Metadata.Rom.NameKey] = item.Name,
|
||||
[Models.Metadata.Rom.SizeKey] = item.Size,
|
||||
[Models.Metadata.Rom.CRCKey] = item.CRC,
|
||||
|
||||
@@ -308,7 +308,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
Name = item.ReadString(Models.Metadata.Chip.NameKey),
|
||||
Tag = item.ReadString(Models.Metadata.Chip.TagKey),
|
||||
Type = item.ReadString(Models.Metadata.Chip.TypeKey),
|
||||
Type = item.ReadString(Models.Metadata.Chip.ChipTypeKey),
|
||||
SoundOnly = item.ReadString(Models.Metadata.Chip.SoundOnlyKey),
|
||||
Clock = item.ReadString(Models.Metadata.Chip.ClockKey),
|
||||
};
|
||||
@@ -407,7 +407,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
var control = new Control
|
||||
{
|
||||
Type = item.ReadString(Models.Metadata.Control.TypeKey),
|
||||
Type = item.ReadString(Models.Metadata.Control.ControlTypeKey),
|
||||
Player = item.ReadString(Models.Metadata.Control.PlayerKey),
|
||||
Buttons = item.ReadString(Models.Metadata.Control.ButtonsKey),
|
||||
ReqButtons = item.ReadString(Models.Metadata.Control.ReqButtonsKey),
|
||||
@@ -430,7 +430,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
var device = new Device
|
||||
{
|
||||
Type = item.ReadString(Models.Metadata.Device.TypeKey),
|
||||
Type = item.ReadString(Models.Metadata.Device.DeviceTypeKey),
|
||||
Tag = item.ReadString(Models.Metadata.Device.TagKey),
|
||||
FixedImage = item.ReadString(Models.Metadata.Device.FixedImageKey),
|
||||
Mandatory = item.ReadString(Models.Metadata.Device.MandatoryKey),
|
||||
@@ -563,7 +563,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
var display = new Display
|
||||
{
|
||||
Tag = item.ReadString(Models.Metadata.Display.TagKey),
|
||||
Type = item.ReadString(Models.Metadata.Display.TypeKey),
|
||||
Type = item.ReadString(Models.Metadata.Display.DisplayTypeKey),
|
||||
Rotate = item.ReadString(Models.Metadata.Display.RotateKey),
|
||||
FlipX = item.ReadString(Models.Metadata.Display.FlipXKey),
|
||||
Width = item.ReadString(Models.Metadata.Display.WidthKey),
|
||||
@@ -621,7 +621,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
var feature = new Feature
|
||||
{
|
||||
Type = item.ReadString(Models.Metadata.Feature.TypeKey),
|
||||
Type = item.ReadString(Models.Metadata.Feature.FeatureTypeKey),
|
||||
Status = item.ReadString(Models.Metadata.Feature.StatusKey),
|
||||
Overall = item.ReadString(Models.Metadata.Feature.OverallKey),
|
||||
};
|
||||
|
||||
@@ -264,7 +264,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
[Models.Metadata.Chip.NameKey] = item.Name,
|
||||
[Models.Metadata.Chip.TagKey] = item.Tag,
|
||||
[Models.Metadata.Chip.TypeKey] = item.Type,
|
||||
[Models.Metadata.Chip.ChipTypeKey] = item.Type,
|
||||
[Models.Metadata.Chip.SoundOnlyKey] = item.SoundOnly,
|
||||
[Models.Metadata.Chip.ClockKey] = item.Clock,
|
||||
};
|
||||
@@ -359,7 +359,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
var control = new Models.Metadata.Control
|
||||
{
|
||||
[Models.Metadata.Control.TypeKey] = item.Type,
|
||||
[Models.Metadata.Control.ControlTypeKey] = item.Type,
|
||||
[Models.Metadata.Control.PlayerKey] = item.Player,
|
||||
[Models.Metadata.Control.ButtonsKey] = item.Buttons,
|
||||
[Models.Metadata.Control.ReqButtonsKey] = item.ReqButtons,
|
||||
@@ -382,7 +382,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
var device = new Models.Metadata.Device
|
||||
{
|
||||
[Models.Metadata.Device.TypeKey] = item.Type,
|
||||
[Models.Metadata.Device.DeviceTypeKey] = item.Type,
|
||||
[Models.Metadata.Device.TagKey] = item.Tag,
|
||||
[Models.Metadata.Device.FixedImageKey] = item.FixedImage,
|
||||
[Models.Metadata.Device.MandatoryKey] = item.Mandatory,
|
||||
@@ -509,7 +509,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
var display = new Models.Metadata.Display
|
||||
{
|
||||
[Models.Metadata.Display.TagKey] = item.Tag,
|
||||
[Models.Metadata.Display.TypeKey] = item.Type,
|
||||
[Models.Metadata.Display.DisplayTypeKey] = item.Type,
|
||||
[Models.Metadata.Display.RotateKey] = item.Rotate,
|
||||
[Models.Metadata.Display.FlipXKey] = item.FlipX,
|
||||
[Models.Metadata.Display.WidthKey] = item.Width,
|
||||
@@ -567,7 +567,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
var feature = new Models.Metadata.Feature
|
||||
{
|
||||
[Models.Metadata.Feature.TypeKey] = item.Type,
|
||||
[Models.Metadata.Feature.FeatureTypeKey] = item.Type,
|
||||
[Models.Metadata.Feature.StatusKey] = item.Status,
|
||||
[Models.Metadata.Feature.OverallKey] = item.Overall,
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
var megaRom = new MegaRom
|
||||
{
|
||||
Start = item.ReadString(Models.Metadata.Rom.StartKey),
|
||||
Type = item.ReadString(Models.Metadata.Rom.TypeKey),
|
||||
Type = item.ReadString(Models.Metadata.Rom.OpenMSXType),
|
||||
Hash = item.ReadString(Models.Metadata.Rom.SHA1Key),
|
||||
Remark = item.ReadString(Models.Metadata.Rom.RemarkKey),
|
||||
};
|
||||
@@ -128,7 +128,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
var rom = new Rom
|
||||
{
|
||||
Start = item.ReadString(Models.Metadata.Rom.StartKey),
|
||||
Type = item.ReadString(Models.Metadata.Rom.TypeKey),
|
||||
Type = item.ReadString(Models.Metadata.Rom.OpenMSXType),
|
||||
Hash = item.ReadString(Models.Metadata.Rom.SHA1Key),
|
||||
Remark = item.ReadString(Models.Metadata.Rom.RemarkKey),
|
||||
};
|
||||
@@ -143,7 +143,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
var sccPlusCart = new SCCPlusCart
|
||||
{
|
||||
Start = item.ReadString(Models.Metadata.Rom.StartKey),
|
||||
Type = item.ReadString(Models.Metadata.Rom.TypeKey),
|
||||
Type = item.ReadString(Models.Metadata.Rom.OpenMSXType),
|
||||
Hash = item.ReadString(Models.Metadata.Rom.SHA1Key),
|
||||
Remark = item.ReadString(Models.Metadata.Rom.RemarkKey),
|
||||
};
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
var rom = new Models.Metadata.Rom
|
||||
{
|
||||
[Models.Metadata.Rom.StartKey] = item.Start,
|
||||
[Models.Metadata.Rom.TypeKey] = item.Type,
|
||||
[Models.Metadata.Rom.OpenMSXType] = item.Type,
|
||||
[Models.Metadata.Rom.SHA1Key] = item.Hash,
|
||||
[Models.Metadata.Rom.RemarkKey] = item.Remark,
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
metadataFile.Row = machines
|
||||
.Where(m => m != null)
|
||||
.SelectMany(ConvertMachineFromInternalModel)
|
||||
.SelectMany(m => ConvertMachineFromInternalModel(m, header))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <summary>
|
||||
/// Convert from <cref="Models.Metadata.Machine"/> to an array of <cref="Models.SeparatedValue.Row"/>
|
||||
/// </summary>
|
||||
private static Row[] ConvertMachineFromInternalModel(Models.Metadata.Machine item)
|
||||
private static Row[] ConvertMachineFromInternalModel(Models.Metadata.Machine item, Models.Metadata.Header? header)
|
||||
{
|
||||
var rowItems = new List<Row>();
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
rowItems.AddRange(roms
|
||||
.Where(r => r != null)
|
||||
.Select(rom => ConvertFromInternalModel(rom, item)));
|
||||
.Select(rom => ConvertFromInternalModel(rom, item, header)));
|
||||
}
|
||||
|
||||
var disks = item.Read<Models.Metadata.Disk[]>(Models.Metadata.Machine.DiskKey);
|
||||
@@ -60,7 +60,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
rowItems.AddRange(disks
|
||||
.Where(d => d != null)
|
||||
.Select(disk => ConvertFromInternalModel(disk, item)));
|
||||
.Select(disk => ConvertFromInternalModel(disk, item, header)));
|
||||
}
|
||||
|
||||
var media = item.Read<Models.Metadata.Media[]>(Models.Metadata.Machine.MediaKey);
|
||||
@@ -68,7 +68,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
rowItems.AddRange(media
|
||||
.Where(m => m != null)
|
||||
.Select(medium => ConvertFromInternalModel(medium, item)));
|
||||
.Select(medium => ConvertFromInternalModel(medium, item, header)));
|
||||
}
|
||||
|
||||
return rowItems.ToArray();
|
||||
@@ -77,16 +77,26 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <summary>
|
||||
/// Convert from <cref="Models.Metadata.Disk"/> to <cref="Models.SeparatedValue.Row"/>
|
||||
/// </summary>
|
||||
private static Row ConvertFromInternalModel(Models.Metadata.Disk item, Models.Metadata.Machine parent)
|
||||
private static Row ConvertFromInternalModel(Models.Metadata.Disk item, Models.Metadata.Machine parent, Models.Metadata.Header? header)
|
||||
{
|
||||
var row = new Row
|
||||
{
|
||||
FileName = header?.ReadString("FILENAME"), // TODO: Make this an actual key to retrieve
|
||||
InternalName = header?.ReadString(Models.Metadata.Header.NameKey),
|
||||
Description = header?.ReadString(Models.Metadata.Header.DescriptionKey),
|
||||
GameName = parent.ReadString(Models.Metadata.Machine.NameKey),
|
||||
Description = parent.ReadString(Models.Metadata.Machine.DescriptionKey),
|
||||
GameDescription = parent.ReadString(Models.Metadata.Machine.DescriptionKey),
|
||||
Type = "disk",
|
||||
RomName = null,
|
||||
DiskName = item.ReadString(Models.Metadata.Disk.NameKey),
|
||||
Size = null,
|
||||
CRC = null,
|
||||
MD5 = item.ReadString(Models.Metadata.Disk.MD5Key),
|
||||
SHA1 = item.ReadString(Models.Metadata.Disk.SHA1Key),
|
||||
SHA256 = null,
|
||||
SHA384 = null,
|
||||
SHA512 = null,
|
||||
SpamSum = null,
|
||||
Status = item.ReadString(Models.Metadata.Disk.StatusKey),
|
||||
};
|
||||
return row;
|
||||
@@ -95,17 +105,25 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <summary>
|
||||
/// Convert from <cref="Models.Metadata.Media"/> to <cref="Models.SeparatedValue.Row"/>
|
||||
/// </summary>
|
||||
private static Row ConvertFromInternalModel(Models.Metadata.Media item, Models.Metadata.Machine parent)
|
||||
private static Row ConvertFromInternalModel(Models.Metadata.Media item, Models.Metadata.Machine parent, Models.Metadata.Header? header)
|
||||
{
|
||||
var row = new Row
|
||||
{
|
||||
FileName = header?.ReadString("FILENAME"), // TODO: Make this an actual key to retrieve
|
||||
InternalName = header?.ReadString(Models.Metadata.Header.NameKey),
|
||||
Description = header?.ReadString(Models.Metadata.Header.DescriptionKey),
|
||||
GameName = parent.ReadString(Models.Metadata.Machine.NameKey),
|
||||
Description = parent.ReadString(Models.Metadata.Machine.DescriptionKey),
|
||||
GameDescription = parent.ReadString(Models.Metadata.Machine.DescriptionKey),
|
||||
Type = "media",
|
||||
RomName = null,
|
||||
DiskName = item.ReadString(Models.Metadata.Media.NameKey),
|
||||
Size = null,
|
||||
CRC = null,
|
||||
MD5 = item.ReadString(Models.Metadata.Media.MD5Key),
|
||||
SHA1 = item.ReadString(Models.Metadata.Media.SHA1Key),
|
||||
SHA256 = item.ReadString(Models.Metadata.Media.SHA256Key),
|
||||
SHA384 = null,
|
||||
SHA512 = null,
|
||||
SpamSum = item.ReadString(Models.Metadata.Media.SpamSumKey),
|
||||
};
|
||||
return row;
|
||||
@@ -114,14 +132,18 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <summary>
|
||||
/// Convert from <cref="Models.Metadata.Rom"/> to <cref="Models.SeparatedValue.Row"/>
|
||||
/// </summary>
|
||||
private static Row ConvertFromInternalModel(Models.Metadata.Rom item, Models.Metadata.Machine parent)
|
||||
private static Row ConvertFromInternalModel(Models.Metadata.Rom item, Models.Metadata.Machine parent, Models.Metadata.Header? header)
|
||||
{
|
||||
var row = new Row
|
||||
{
|
||||
GameName = parent?.ReadString(Models.Metadata.Machine.NameKey),
|
||||
Description = parent?.ReadString(Models.Metadata.Machine.DescriptionKey),
|
||||
FileName = header?.ReadString("FILENAME"), // TODO: Make this an actual key to retrieve
|
||||
InternalName = header?.ReadString(Models.Metadata.Header.NameKey),
|
||||
Description = header?.ReadString(Models.Metadata.Header.DescriptionKey),
|
||||
GameName = parent.ReadString(Models.Metadata.Machine.NameKey),
|
||||
GameDescription = parent.ReadString(Models.Metadata.Machine.DescriptionKey),
|
||||
Type = "rom",
|
||||
RomName = item.ReadString(Models.Metadata.Rom.NameKey),
|
||||
DiskName = null,
|
||||
Size = item.ReadString(Models.Metadata.Rom.SizeKey),
|
||||
CRC = item.ReadString(Models.Metadata.Rom.CRCKey),
|
||||
MD5 = item.ReadString(Models.Metadata.Rom.MD5Key),
|
||||
|
||||
@@ -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);
|
||||
@@ -1268,6 +1280,7 @@ namespace SabreTools.Serialization
|
||||
{
|
||||
var stringData = new StringData();
|
||||
|
||||
int dataStartOffset = offset;
|
||||
stringData.Length = data.ReadUInt16(ref offset);
|
||||
stringData.ValueLength = data.ReadUInt16(ref offset);
|
||||
stringData.ResourceType = (VersionResourceType)data.ReadUInt16(ref offset);
|
||||
@@ -1282,7 +1295,8 @@ namespace SabreTools.Serialization
|
||||
|
||||
if (stringData.ValueLength > 0)
|
||||
{
|
||||
byte[]? valueBytes = data.ReadBytes(ref offset, stringData.ValueLength * sizeof(ushort));
|
||||
int bytesReadable = Math.Min(stringData.ValueLength * sizeof(ushort), stringData.Length - (offset - dataStartOffset));
|
||||
byte[]? valueBytes = data.ReadBytes(ref offset, bytesReadable);
|
||||
if (valueBytes != null)
|
||||
stringData.Value = Encoding.Unicode.GetString(valueBytes);
|
||||
}
|
||||
@@ -1295,6 +1309,8 @@ namespace SabreTools.Serialization
|
||||
}
|
||||
|
||||
stringTableChildren.Add(stringData);
|
||||
if (stringData.Length == 0 && stringData.ValueLength == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
stringTable.Children = [.. stringTableChildren];
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Files/Catalog.Deserializer.cs
Normal file
11
Files/Catalog.Deserializer.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Text;
|
||||
|
||||
namespace SabreTools.Serialization.Files
|
||||
{
|
||||
public partial class Catalog : JsonFile<Models.Xbox.Catalog>
|
||||
{
|
||||
// Catalog.js file is a UTF-16 LE JSON
|
||||
public new Models.Xbox.Catalog? Deserialize(string? path)
|
||||
=> Deserialize(path, new UnicodeEncoding());
|
||||
}
|
||||
}
|
||||
11
Files/Catalog.Serializer.cs
Normal file
11
Files/Catalog.Serializer.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Text;
|
||||
|
||||
namespace SabreTools.Serialization.Files
|
||||
{
|
||||
public partial class Catalog : JsonFile<Models.Xbox.Catalog>
|
||||
{
|
||||
// Catalog.js file is a UTF-16 LE JSON
|
||||
public new bool Serialize(Models.Xbox.Catalog? obj, string? path)
|
||||
=> Serialize(obj, path, new UnicodeEncoding());
|
||||
}
|
||||
}
|
||||
@@ -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])
|
||||
@@ -165,6 +165,12 @@ namespace SabreTools.Serialization.Files
|
||||
cueTracks.Add(track);
|
||||
break;
|
||||
|
||||
// Next file found, return
|
||||
case "FILE":
|
||||
i--;
|
||||
cueFile.Tracks = cueTracks.ToArray();
|
||||
return cueFile;
|
||||
|
||||
// Default means return
|
||||
default:
|
||||
i--;
|
||||
@@ -213,7 +219,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])
|
||||
@@ -299,6 +305,13 @@ namespace SabreTools.Serialization.Files
|
||||
cueTrack.PostGap = postgap;
|
||||
break;
|
||||
|
||||
// Next track or file found, return
|
||||
case "TRACK":
|
||||
case "FILE":
|
||||
i--;
|
||||
cueTrack.Indices = cueIndices.ToArray();
|
||||
return cueTrack;
|
||||
|
||||
// Default means return
|
||||
default:
|
||||
i--;
|
||||
@@ -317,7 +330,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 +387,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 +438,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
|
||||
@@ -583,4 +596,4 @@ namespace SabreTools.Serialization.Files
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Files/JsonFile.Deserializer.cs
Normal file
31
Files/JsonFile.Deserializer.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Text;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Files
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for other JSON serializers
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public partial class JsonFile<T> : IFileSerializer<T>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public T? Deserialize(string? path)
|
||||
=> Deserialize(path, new UTF8Encoding(false));
|
||||
|
||||
/// <summary>
|
||||
/// Deserialize a file into <typeparamref name="T"/>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to deserialize to</typeparam>
|
||||
/// <param name="path">Path to deserialize from</param>
|
||||
/// <param name="encoding">Encoding to parse text as</param>
|
||||
/// <returns>Filled object on success, null on error</returns>
|
||||
public T? Deserialize(string? path, Encoding encoding)
|
||||
{
|
||||
using (var data = PathProcessor.OpenStream(path))
|
||||
{
|
||||
return new Streams.JsonFile<T>().Deserialize(data, encoding);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
40
Files/JsonFile.Serializer.cs
Normal file
40
Files/JsonFile.Serializer.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Files
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for other JSON serializers
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public partial class JsonFile<T> : IFileSerializer<T>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public bool Serialize(T? obj, string? path)
|
||||
=> Serialize(obj, path, new UTF8Encoding(false));
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a <typeparamref name="T"/> into a file
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to serialize from</typeparam>
|
||||
/// <param name="obj">Data to serialize</param>
|
||||
/// <param name="path">Path to the file to serialize to</param>
|
||||
/// <param name="encoding">Encoding to parse text as</param>
|
||||
/// <returns>True on successful serialization, false otherwise</returns>
|
||||
public bool Serialize(T? obj, string? path, Encoding encoding)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return false;
|
||||
|
||||
using var stream = new Streams.JsonFile<T>().Serialize(obj, encoding);
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
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.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace SabreTools.Serialization.Files
|
||||
public partial class Logiqx : XmlFile<Datafile>
|
||||
{
|
||||
/// <inheritdoc cref="Serialize(Datafile, string, string?, string?, string?, string?)" />
|
||||
public bool SerializeToFileWithDocType(Datafile obj, string path)
|
||||
public bool SerializeToFileWithDocType(Datafile? obj, string path)
|
||||
=> Serialize(obj, path, Serialization.Logiqx.DocTypeName, Serialization.Logiqx.DocTypePubId, Serialization.Logiqx.DocTypeSysId, Serialization.Logiqx.DocTypeSysId);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace SabreTools.Serialization.Files
|
||||
public partial class OpenMSX : XmlFile<SoftwareDb>
|
||||
{
|
||||
/// <inheritdoc cref="Serialize(SoftwareDb, string, string?, string?, string?, string?)" />
|
||||
public bool SerializeToFileWithDocType(SoftwareDb obj, string path)
|
||||
public bool SerializeToFileWithDocType(SoftwareDb? obj, string path)
|
||||
=> Serialize(obj, path, Serialization.OpenMSX.DocTypeName, Serialization.OpenMSX.DocTypePubId, Serialization.OpenMSX.DocTypeSysId, Serialization.OpenMSX.DocTypeSysId);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ namespace SabreTools.Serialization.Files
|
||||
public partial class SoftwareList : XmlFile<Models.SoftwareList.SoftwareList>
|
||||
{
|
||||
/// <inheritdoc cref="SerializeToFile(Models.SoftwareList.SoftwareList, string, string?, string?, string?, string?)" />
|
||||
public bool SerializeToFileWithDocType(Models.SoftwareList.SoftwareList obj, string path)
|
||||
public bool SerializeToFileWithDocType(Models.SoftwareList.SoftwareList? obj, string path)
|
||||
=> Serialize(obj, path, Serialization.SoftawreList.DocTypeName, Serialization.SoftawreList.DocTypePubId, Serialization.SoftawreList.DocTypeSysId, Serialization.SoftawreList.DocTypeSysId);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ namespace SabreTools.Serialization.Files
|
||||
/// </summary>
|
||||
/// <param name="obj">Data to serialize</param>
|
||||
/// <param name="path">Path to the file to serialize to</param>
|
||||
/// <param name="obj">Data to serialize</param>
|
||||
/// <param name="name">Optional DOCTYPE name</param>
|
||||
/// <param name="pubid">Optional DOCTYPE pubid</param>
|
||||
/// <param name="sysid">Optional DOCTYPE sysid</param>
|
||||
@@ -26,21 +25,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,11 +16,11 @@ 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
|
||||
var stream = File.OpenRead(path);
|
||||
var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
|
||||
// Get the extension to determine if additional handling is needed
|
||||
string ext = Path.GetExtension(path).TrimStart('.');
|
||||
|
||||
@@ -2,18 +2,18 @@
|
||||
|
||||
<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.1</Version>
|
||||
<Version>1.4.2</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
<Description>Serialization and deserialization helpers for various types</Description>
|
||||
<Copyright>Copyright (c) Matt Nadareski 2019-2023</Copyright>
|
||||
<Copyright>Copyright (c) Matt Nadareski 2019-2024</Copyright>
|
||||
<PackageProjectUrl>https://github.com/SabreTools/</PackageProjectUrl>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<RepositoryUrl>https://github.com/SabreTools/SabreTools.Serialization</RepositoryUrl>
|
||||
@@ -23,12 +23,13 @@
|
||||
</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="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="SabreTools.IO" Version="1.3.2" />
|
||||
<PackageReference Include="SabreTools.Models" Version="1.4.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace SabreTools.Serialization.Streams
|
||||
// TODO: Include flag to write out long or short header
|
||||
// Write the short header
|
||||
writer.WriteString(Serialization.AttractMode.HeaderWithoutRomname); // TODO: Convert to array of values
|
||||
writer.WriteLine();
|
||||
|
||||
// Write out the rows, if they exist
|
||||
WriteRows(obj.Row, writer);
|
||||
|
||||
12
Streams/Catalog.Deserializer.cs
Normal file
12
Streams/Catalog.Deserializer.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace SabreTools.Serialization.Streams
|
||||
{
|
||||
public partial class Catalog : JsonFile<Models.Xbox.Catalog>
|
||||
{
|
||||
// Catalog JSON is encoded as UTF-16 LE
|
||||
public new Models.Xbox.Catalog? Deserialize(Stream? data)
|
||||
=> Deserialize(data, new UnicodeEncoding());
|
||||
}
|
||||
}
|
||||
12
Streams/Catalog.Serializer.cs
Normal file
12
Streams/Catalog.Serializer.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace SabreTools.Serialization.Streams
|
||||
{
|
||||
public partial class Catalog : JsonFile<Models.Xbox.Catalog>
|
||||
{
|
||||
// Catalog JSON is encoded as UTF-16 LE
|
||||
public new Stream? Serialize(Models.Xbox.Catalog? obj)
|
||||
=> Serialize(obj, new UnicodeEncoding());
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
40
Streams/JsonFile.Deserializer.cs
Normal file
40
Streams/JsonFile.Deserializer.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Streams
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for other JSON serializers
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public partial class JsonFile<T> : IStreamSerializer<T>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public T? Deserialize(Stream? data)
|
||||
=> Deserialize(data, new UTF8Encoding(false));
|
||||
|
||||
/// <summary>
|
||||
/// Deserialize a Stream into <typeparamref name="T"/>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to deserialize to</typeparam>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="encoding">Text encoding to use</param>
|
||||
/// <returns>Filled object on success, null on error</returns>
|
||||
public T? Deserialize(Stream? data, Encoding encoding)
|
||||
{
|
||||
// If the stream is null
|
||||
if (data == null)
|
||||
return default;
|
||||
|
||||
// Setup the serializer and the reader
|
||||
var serializer = JsonSerializer.Create();
|
||||
var streamReader = new StreamReader(data, encoding);
|
||||
var jsonReader = new JsonTextReader(streamReader);
|
||||
|
||||
// Perform the deserialization and return
|
||||
return serializer.Deserialize<T>(jsonReader);
|
||||
}
|
||||
}
|
||||
}
|
||||
43
Streams/JsonFile.Serializer.cs
Normal file
43
Streams/JsonFile.Serializer.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Streams
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for other JSON serializers
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public partial class JsonFile<T> : IStreamSerializer<T>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public Stream? Serialize(T? obj)
|
||||
=> Serialize(obj, new UTF8Encoding(false));
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a <typeparamref name="T"/> into a Stream
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to serialize from</typeparam>
|
||||
/// <param name="obj">Data to serialize</param>
|
||||
/// <param name="encoding"></param>
|
||||
/// <returns>Filled object on success, null on error</returns>
|
||||
public Stream? Serialize(T? obj, Encoding encoding)
|
||||
{
|
||||
// If the object is null
|
||||
if (obj == null)
|
||||
return null;
|
||||
|
||||
// Setup the serializer and the writer
|
||||
var serializer = JsonSerializer.Create();
|
||||
var stream = new MemoryStream();
|
||||
var streamWriter = new StreamWriter(stream, encoding);
|
||||
var jsonWriter = new JsonTextWriter(streamWriter);
|
||||
|
||||
// Perform the deserialization and return
|
||||
serializer.Serialize(jsonWriter, obj);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -424,7 +424,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled information block on success, null on error</returns>
|
||||
private static InformationBlock? ParseInformationBlock(Stream data)
|
||||
public static InformationBlock? ParseInformationBlock(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var informationBlock = new InformationBlock();
|
||||
@@ -491,7 +491,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled object table entry on success, null on error</returns>
|
||||
private static ObjectTableEntry ParseObjectTableEntry(Stream data)
|
||||
public static ObjectTableEntry ParseObjectTableEntry(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var entry = new ObjectTableEntry();
|
||||
@@ -511,7 +511,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled object page map entry on success, null on error</returns>
|
||||
private static ObjectPageMapEntry ParseObjectPageMapEntry(Stream data)
|
||||
public static ObjectPageMapEntry ParseObjectPageMapEntry(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var entry = new ObjectPageMapEntry();
|
||||
@@ -528,7 +528,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled resource table entry on success, null on error</returns>
|
||||
private static ResourceTableEntry ParseResourceTableEntry(Stream data)
|
||||
public static ResourceTableEntry ParseResourceTableEntry(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var entry = new ResourceTableEntry();
|
||||
@@ -547,7 +547,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled resident names table entry on success, null on error</returns>
|
||||
private static ResidentNamesTableEntry ParseResidentNamesTableEntry(Stream data)
|
||||
public static ResidentNamesTableEntry ParseResidentNamesTableEntry(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var entry = new ResidentNamesTableEntry();
|
||||
@@ -569,7 +569,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled entry table bundle on success, null on error</returns>
|
||||
private static EntryTableBundle? ParseEntryTableBundle(Stream data)
|
||||
public static EntryTableBundle? ParseEntryTableBundle(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var bundle = new EntryTableBundle();
|
||||
@@ -632,7 +632,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled module format directives table entry on success, null on error</returns>
|
||||
private static ModuleFormatDirectivesTableEntry ParseModuleFormatDirectivesTableEntry(Stream data)
|
||||
public static ModuleFormatDirectivesTableEntry ParseModuleFormatDirectivesTableEntry(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var entry = new ModuleFormatDirectivesTableEntry();
|
||||
@@ -649,7 +649,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled verify record directive table entry on success, null on error</returns>
|
||||
private static VerifyRecordDirectiveTableEntry ParseVerifyRecordDirectiveTableEntry(Stream data)
|
||||
public static VerifyRecordDirectiveTableEntry ParseVerifyRecordDirectiveTableEntry(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var entry = new VerifyRecordDirectiveTableEntry();
|
||||
@@ -670,7 +670,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled fix-up page table entry on success, null on error</returns>
|
||||
private static FixupPageTableEntry ParseFixupPageTableEntry(Stream data)
|
||||
public static FixupPageTableEntry ParseFixupPageTableEntry(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var entry = new FixupPageTableEntry();
|
||||
@@ -685,7 +685,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled fix-up record table entry on success, null on error</returns>
|
||||
private static FixupRecordTableEntry? ParseFixupRecordTableEntry(Stream data)
|
||||
public static FixupRecordTableEntry? ParseFixupRecordTableEntry(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var entry = new FixupRecordTableEntry();
|
||||
@@ -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++)
|
||||
@@ -820,7 +904,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled import module name table entry on success, null on error</returns>
|
||||
private static ImportModuleNameTableEntry ParseImportModuleNameTableEntry(Stream data)
|
||||
public static ImportModuleNameTableEntry ParseImportModuleNameTableEntry(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var entry = new ImportModuleNameTableEntry();
|
||||
@@ -841,7 +925,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled import module name table entry on success, null on error</returns>
|
||||
private static ImportModuleProcedureNameTableEntry ParseImportModuleProcedureNameTableEntry(Stream data)
|
||||
public static ImportModuleProcedureNameTableEntry ParseImportModuleProcedureNameTableEntry(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var entry = new ImportModuleProcedureNameTableEntry();
|
||||
@@ -862,7 +946,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled per-page checksum table entry on success, null on error</returns>
|
||||
private static PerPageChecksumTableEntry ParsePerPageChecksumTableEntry(Stream data)
|
||||
public static PerPageChecksumTableEntry ParsePerPageChecksumTableEntry(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var entry = new PerPageChecksumTableEntry();
|
||||
@@ -877,7 +961,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled non-resident names table entry on success, null on error</returns>
|
||||
private static NonResidentNamesTableEntry ParseNonResidentNameTableEntry(Stream data)
|
||||
public static NonResidentNamesTableEntry ParseNonResidentNameTableEntry(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var entry = new NonResidentNamesTableEntry();
|
||||
@@ -900,7 +984,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="size">Total size of the debug information</param>
|
||||
/// <returns>Filled debug information on success, null on error</returns>
|
||||
private static DebugInformation? ParseDebugInformation(Stream data, long size)
|
||||
public static DebugInformation? ParseDebugInformation(Stream data, long size)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var debugInformation = new DebugInformation();
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -213,7 +213,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled executable header on success, null on error</returns>
|
||||
private static ExecutableHeader? ParseExecutableHeader(Stream data)
|
||||
public static ExecutableHeader? ParseExecutableHeader(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var header = new ExecutableHeader();
|
||||
@@ -266,7 +266,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="count">Number of segment table entries to read</param>
|
||||
/// <returns>Filled segment table on success, null on error</returns>
|
||||
private static SegmentTableEntry[] ParseSegmentTable(Stream data, int count)
|
||||
public static SegmentTableEntry[] ParseSegmentTable(Stream data, int count)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var segmentTable = new SegmentTableEntry[count];
|
||||
@@ -290,7 +290,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="count">Number of resource table entries to read</param>
|
||||
/// <returns>Filled resource table on success, null on error</returns>
|
||||
private static ResourceTable ParseResourceTable(Stream data, int count)
|
||||
public static ResourceTable ParseResourceTable(Stream data, int count)
|
||||
{
|
||||
long initialOffset = data.Position;
|
||||
|
||||
@@ -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);
|
||||
@@ -359,7 +355,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="endOffset">First address not part of the resident-name table</param>
|
||||
/// <returns>Filled resident-name table on success, null on error</returns>
|
||||
private static ResidentNameTableEntry[] ParseResidentNameTable(Stream data, int endOffset)
|
||||
public static ResidentNameTableEntry[] ParseResidentNameTable(Stream data, int endOffset)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var residentNameTable = new List<ResidentNameTableEntry>();
|
||||
@@ -373,7 +369,7 @@ namespace SabreTools.Serialization.Streams
|
||||
residentNameTable.Add(entry);
|
||||
}
|
||||
|
||||
return residentNameTable.ToArray();
|
||||
return [.. residentNameTable];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -382,7 +378,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="count">Number of module-reference table entries to read</param>
|
||||
/// <returns>Filled module-reference table on success, null on error</returns>
|
||||
private static ModuleReferenceTableEntry[] ParseModuleReferenceTable(Stream data, int count)
|
||||
public static ModuleReferenceTableEntry[] ParseModuleReferenceTable(Stream data, int count)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var moduleReferenceTable = new ModuleReferenceTableEntry[count];
|
||||
@@ -403,7 +399,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="endOffset">First address not part of the imported-name table</param>
|
||||
/// <returns>Filled imported-name table on success, null on error</returns>
|
||||
private static Dictionary<ushort, ImportedNameTableEntry?> ParseImportedNameTable(Stream data, int endOffset)
|
||||
public static Dictionary<ushort, ImportedNameTableEntry?> ParseImportedNameTable(Stream data, int endOffset)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var importedNameTable = new Dictionary<ushort, ImportedNameTableEntry?>();
|
||||
@@ -426,7 +422,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="endOffset">First address not part of the entry table</param>
|
||||
/// <returns>Filled entry table on success, null on error</returns>
|
||||
private static EntryTableBundle[] ParseEntryTable(Stream data, int endOffset)
|
||||
public static EntryTableBundle[] ParseEntryTable(Stream data, int endOffset)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var entryTable = new List<EntryTableBundle>();
|
||||
@@ -456,7 +452,7 @@ namespace SabreTools.Serialization.Streams
|
||||
entryTable.Add(entry);
|
||||
}
|
||||
|
||||
return entryTable.ToArray();
|
||||
return [.. entryTable];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -465,7 +461,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="endOffset">First address not part of the nonresident-name table</param>
|
||||
/// <returns>Filled nonresident-name table on success, null on error</returns>
|
||||
private static NonResidentNameTableEntry[] ParseNonResidentNameTable(Stream data, int endOffset)
|
||||
public static NonResidentNameTableEntry[] ParseNonResidentNameTable(Stream data, int endOffset)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var residentNameTable = new List<NonResidentNameTableEntry>();
|
||||
@@ -479,7 +475,7 @@ namespace SabreTools.Serialization.Streams
|
||||
residentNameTable.Add(entry);
|
||||
}
|
||||
|
||||
return residentNameTable.ToArray();
|
||||
return [.. residentNameTable];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -292,7 +292,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled executable header on success, null on error</returns>
|
||||
private static COFFFileHeader ParseCOFFFileHeader(Stream data)
|
||||
public static COFFFileHeader ParseCOFFFileHeader(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var fileHeader = new COFFFileHeader();
|
||||
@@ -314,7 +314,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="optionalSize">Size of the optional header</param>
|
||||
/// <returns>Filled optional header on success, null on error</returns>
|
||||
private static OptionalHeader ParseOptionalHeader(Stream data, int optionalSize)
|
||||
public static OptionalHeader ParseOptionalHeader(Stream data, int optionalSize)
|
||||
{
|
||||
long initialOffset = data.Position;
|
||||
|
||||
@@ -484,7 +484,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="count">Number of section table entries to read</param>
|
||||
/// <returns>Filled section table on success, null on error</returns>
|
||||
private static SectionHeader[] ParseSectionTable(Stream data, int count)
|
||||
public static SectionHeader[] ParseSectionTable(Stream data, int count)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var sectionTable = new SectionHeader[count];
|
||||
@@ -524,7 +524,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="count">Number of COFF symbol table entries to read</param>
|
||||
/// <returns>Filled COFF symbol table on success, null on error</returns>
|
||||
private static COFFSymbolTableEntry[] ParseCOFFSymbolTable(Stream data, uint count)
|
||||
public static COFFSymbolTableEntry[] ParseCOFFSymbolTable(Stream data, uint count)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var coffSymbolTable = new COFFSymbolTableEntry[count];
|
||||
@@ -681,7 +681,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled COFF string table on success, null on error</returns>
|
||||
private static COFFStringTable ParseCOFFStringTable(Stream data)
|
||||
public static COFFStringTable ParseCOFFStringTable(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var coffStringTable = new COFFStringTable();
|
||||
@@ -712,7 +712,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="endOffset">First address not part of the attribute certificate table</param>
|
||||
/// <returns>Filled attribute certificate on success, null on error</returns>
|
||||
private static AttributeCertificateTableEntry[] ParseAttributeCertificateTable(Stream data, int endOffset)
|
||||
public static AttributeCertificateTableEntry[] ParseAttributeCertificateTable(Stream data, int endOffset)
|
||||
{
|
||||
var attributeCertificateTable = new List<AttributeCertificateTableEntry>();
|
||||
|
||||
@@ -743,7 +743,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled delay-load directory table on success, null on error</returns>
|
||||
private static DelayLoadDirectoryTable ParseDelayLoadDirectoryTable(Stream data)
|
||||
public static DelayLoadDirectoryTable ParseDelayLoadDirectoryTable(Stream data)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var delayLoadDirectoryTable = new DelayLoadDirectoryTable();
|
||||
@@ -767,7 +767,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="endOffset">First address not part of the base relocation table</param>
|
||||
/// <param name="sections">Section table to use for virtual address translation</param>
|
||||
/// <returns>Filled base relocation table on success, null on error</returns>
|
||||
private static BaseRelocationBlock[] ParseBaseRelocationTable(Stream data, int endOffset, SectionHeader?[] sections)
|
||||
public static BaseRelocationBlock[] ParseBaseRelocationTable(Stream data, int endOffset, SectionHeader?[] sections)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var baseRelocationTable = new List<BaseRelocationBlock>();
|
||||
@@ -808,7 +808,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="endOffset">First address not part of the debug table</param>
|
||||
/// <param name="sections">Section table to use for virtual address translation</param>
|
||||
/// <returns>Filled debug table on success, null on error</returns>
|
||||
private static DebugTable ParseDebugTable(Stream data, int endOffset, SectionHeader?[] sections)
|
||||
public static DebugTable ParseDebugTable(Stream data, int endOffset, SectionHeader?[] sections)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var debugTable = new DebugTable();
|
||||
@@ -845,7 +845,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="sections">Section table to use for virtual address translation</param>
|
||||
/// <returns>Filled export table on success, null on error</returns>
|
||||
private static ExportTable ParseExportTable(Stream data, SectionHeader?[] sections)
|
||||
public static ExportTable ParseExportTable(Stream data, SectionHeader?[] sections)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var exportTable = new ExportTable();
|
||||
@@ -962,7 +962,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="magic">Optional header magic number indicating PE32 or PE32+</param>
|
||||
/// <param name="sections">Section table to use for virtual address translation</param>
|
||||
/// <returns>Filled import table on success, null on error</returns>
|
||||
private static ImportTable ParseImportTable(Stream data, OptionalHeaderMagicNumber magic, SectionHeader?[] sections)
|
||||
public static ImportTable ParseImportTable(Stream data, OptionalHeaderMagicNumber magic, SectionHeader?[] sections)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var importTable = new ImportTable();
|
||||
@@ -1187,7 +1187,7 @@ namespace SabreTools.Serialization.Streams
|
||||
/// <param name="sections">Section table to use for virtual address translation</param>
|
||||
/// <param name="topLevel">Indicates if this is the top level or not</param>
|
||||
/// <returns>Filled resource directory table on success, null on error</returns>
|
||||
private static ResourceDirectoryTable? ParseResourceDirectoryTable(Stream data, long initialOffset, SectionHeader?[] sections, bool topLevel = false)
|
||||
public static ResourceDirectoryTable? ParseResourceDirectoryTable(Stream data, long initialOffset, SectionHeader?[] sections, bool topLevel = false)
|
||||
{
|
||||
// TODO: Use marshalling here instead of building
|
||||
var resourceDirectoryTable = new ResourceDirectoryTable();
|
||||
|
||||
@@ -48,15 +48,22 @@ namespace SabreTools.Serialization.Streams
|
||||
if (credits == null)
|
||||
return;
|
||||
|
||||
writer.WriteSection("credits");
|
||||
writer.WriteSection("CREDITS");
|
||||
|
||||
writer.WriteKeyValuePair("author", credits.Author);
|
||||
writer.WriteKeyValuePair("version", credits.Version);
|
||||
writer.WriteKeyValuePair("email", credits.Email);
|
||||
writer.WriteKeyValuePair("homepage", credits.Homepage);
|
||||
writer.WriteKeyValuePair("url", credits.Url);
|
||||
writer.WriteKeyValuePair("date", credits.Date);
|
||||
writer.WriteKeyValuePair("comment", credits.Comment);
|
||||
if (credits.Author != null)
|
||||
writer.WriteKeyValuePair("Author", credits.Author);
|
||||
if (credits.Version != null)
|
||||
writer.WriteKeyValuePair("Version", credits.Version);
|
||||
if (credits.Email != null)
|
||||
writer.WriteKeyValuePair("Email", credits.Email);
|
||||
if (credits.Homepage != null)
|
||||
writer.WriteKeyValuePair("Homepage", credits.Homepage);
|
||||
if (credits.Url != null)
|
||||
writer.WriteKeyValuePair("Url", credits.Url);
|
||||
if (credits.Date != null)
|
||||
writer.WriteKeyValuePair("Date", credits.Date);
|
||||
if (credits.Comment != null)
|
||||
writer.WriteKeyValuePair("Comment", credits.Comment);
|
||||
writer.WriteLine();
|
||||
|
||||
writer.Flush();
|
||||
@@ -73,12 +80,16 @@ namespace SabreTools.Serialization.Streams
|
||||
if (dat == null)
|
||||
return;
|
||||
|
||||
writer.WriteSection("dat");
|
||||
writer.WriteSection("DAT");
|
||||
|
||||
writer.WriteKeyValuePair("version", dat.Version);
|
||||
writer.WriteKeyValuePair("plugin", dat.Plugin);
|
||||
writer.WriteKeyValuePair("split", dat.Split);
|
||||
writer.WriteKeyValuePair("merge", dat.Merge);
|
||||
if (dat.Version != null)
|
||||
writer.WriteKeyValuePair("Version", dat.Version);
|
||||
if (dat.Plugin != null)
|
||||
writer.WriteKeyValuePair("Plugin", dat.Plugin);
|
||||
if (dat.Split != null)
|
||||
writer.WriteKeyValuePair("Split", dat.Split);
|
||||
if (dat.Merge != null)
|
||||
writer.WriteKeyValuePair("Merge", dat.Merge);
|
||||
writer.WriteLine();
|
||||
|
||||
writer.Flush();
|
||||
@@ -95,10 +106,12 @@ namespace SabreTools.Serialization.Streams
|
||||
if (emulator == null)
|
||||
return;
|
||||
|
||||
writer.WriteSection("emulator");
|
||||
writer.WriteSection("EMULATOR");
|
||||
|
||||
writer.WriteKeyValuePair("refname", emulator.RefName);
|
||||
writer.WriteKeyValuePair("version", emulator.Version);
|
||||
if (emulator.RefName != null)
|
||||
writer.WriteKeyValuePair("refname", emulator.RefName);
|
||||
if (emulator.Version != null)
|
||||
writer.WriteKeyValuePair("version", emulator.Version);
|
||||
writer.WriteLine();
|
||||
|
||||
writer.Flush();
|
||||
@@ -115,7 +128,7 @@ namespace SabreTools.Serialization.Streams
|
||||
if (games?.Rom == null || !games.Rom.Any())
|
||||
return;
|
||||
|
||||
writer.WriteSection("games");
|
||||
writer.WriteSection("GAMES");
|
||||
|
||||
foreach (var rom in games.Rom)
|
||||
{
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace SabreTools.Serialization.Streams
|
||||
if (obj == null)
|
||||
return null;
|
||||
|
||||
// Setup the serializer and the reader
|
||||
// Setup the serializer and the writer
|
||||
var serializer = new XmlSerializer(typeof(T));
|
||||
var settings = new XmlWriterSettings
|
||||
{
|
||||
@@ -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