mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-02-03 21:30:35 +00:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1da5f192c | ||
|
|
c15809dd72 | ||
|
|
89a67d1bd2 | ||
|
|
c4c6709478 | ||
|
|
5e1f6ac4b3 | ||
|
|
8f8d86d0bb | ||
|
|
ecca11e2f3 | ||
|
|
527b09c6bc | ||
|
|
69b6595434 | ||
|
|
59b918c75f | ||
|
|
344132b50a | ||
|
|
a35e58e9cc | ||
|
|
4300d94858 | ||
|
|
ee85a84d8f | ||
|
|
2959d82231 | ||
|
|
5dfe6aefb0 | ||
|
|
7f7d0f84ef | ||
|
|
4bfaf36e24 | ||
|
|
695fc4b0af | ||
|
|
f16ed9742f | ||
|
|
6bfe68b8cf | ||
|
|
2e5c5b3c79 | ||
|
|
2a6e193756 | ||
|
|
65a86d87f0 | ||
|
|
d7131dfa4c | ||
|
|
a228b16314 | ||
|
|
b8c9048ac6 | ||
|
|
0b54350d59 | ||
|
|
59eddb7129 | ||
|
|
1096232f9d | ||
|
|
4b39ee8d00 | ||
|
|
27a9b12bbf | ||
|
|
11319c3341 |
167
.editorconfig
Normal file
167
.editorconfig
Normal file
@@ -0,0 +1,167 @@
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# C# files
|
||||
[*.cs]
|
||||
|
||||
# Indentation and spacing
|
||||
charset = utf-8
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
tab_width = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# New line preferences
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
max_line_length = unset
|
||||
|
||||
# using directive preferences
|
||||
csharp_using_directive_placement = outside_namespace
|
||||
dotnet_diagnostic.IDE0005.severity = error
|
||||
|
||||
# Code-block preferences
|
||||
csharp_style_namespace_declarations = block_scoped
|
||||
csharp_style_prefer_method_group_conversion = true
|
||||
csharp_style_prefer_top_level_statements = false
|
||||
|
||||
# Expression-level preferences
|
||||
csharp_prefer_simple_default_expression = true
|
||||
csharp_style_inlined_variable_declaration = true
|
||||
csharp_style_unused_value_assignment_preference = discard_variable
|
||||
csharp_style_unused_value_expression_statement_preference = discard_variable
|
||||
dotnet_diagnostic.IDE0001.severity = warning
|
||||
dotnet_diagnostic.IDE0002.severity = warning
|
||||
dotnet_diagnostic.IDE0004.severity = warning
|
||||
dotnet_diagnostic.IDE0010.severity = error
|
||||
dotnet_diagnostic.IDE0051.severity = warning
|
||||
dotnet_diagnostic.IDE0052.severity = warning
|
||||
dotnet_diagnostic.IDE0072.severity = warning
|
||||
dotnet_diagnostic.IDE0080.severity = warning
|
||||
dotnet_diagnostic.IDE0100.severity = error
|
||||
dotnet_diagnostic.IDE0110.severity = error
|
||||
dotnet_diagnostic.IDE0120.severity = warning
|
||||
dotnet_diagnostic.IDE0121.severity = warning
|
||||
dotnet_diagnostic.IDE0240.severity = error
|
||||
dotnet_diagnostic.IDE0241.severity = error
|
||||
dotnet_style_coalesce_expression = true
|
||||
dotnet_style_namespace_match_folder = false
|
||||
dotnet_style_null_propagation = true
|
||||
dotnet_style_prefer_auto_properties = true
|
||||
dotnet_style_prefer_collection_expression = when_types_loosely_match
|
||||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true
|
||||
dotnet_style_prefer_compound_assignment = true
|
||||
csharp_style_prefer_simple_property_accessors = true
|
||||
dotnet_style_prefer_simplified_interpolation = true
|
||||
dotnet_style_prefer_simplified_boolean_expressions = true
|
||||
csharp_style_prefer_unbound_generic_type_in_nameof = true
|
||||
|
||||
# Field preferences
|
||||
dotnet_diagnostic.IDE0044.severity = warning
|
||||
dotnet_style_readonly_field = true
|
||||
|
||||
# Language keyword vs. framework types preferences
|
||||
dotnet_diagnostic.IDE0049.severity = error
|
||||
dotnet_style_predefined_type_for_locals_parameters_members = true
|
||||
dotnet_style_predefined_type_for_member_access = true
|
||||
|
||||
# Modifier preferences
|
||||
csharp_prefer_static_local_function = true
|
||||
csharp_style_prefer_readonly_struct = true
|
||||
dotnet_diagnostic.IDE0036.severity = warning
|
||||
dotnet_diagnostic.IDE0040.severity = error
|
||||
dotnet_diagnostic.IDE0380.severity = error
|
||||
dotnet_style_require_accessibility_modifiers = always
|
||||
|
||||
# New-line preferences
|
||||
dotnet_diagnostic.IDE2000.severity = warning
|
||||
dotnet_diagnostic.IDE2002.severity = warning
|
||||
dotnet_diagnostic.IDE2003.severity = warning
|
||||
dotnet_diagnostic.IDE2004.severity = warning
|
||||
dotnet_diagnostic.IDE2005.severity = warning
|
||||
dotnet_diagnostic.IDE2006.severity = warning
|
||||
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false
|
||||
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false
|
||||
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false
|
||||
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
|
||||
dotnet_style_allow_multiple_blank_lines_experimental = false
|
||||
dotnet_style_allow_statement_immediately_after_block_experimental = false
|
||||
|
||||
# Null-checking preferences
|
||||
csharp_style_conditional_delegate_call = true
|
||||
|
||||
# Parameter preferences
|
||||
dotnet_code_quality_unused_parameters = all
|
||||
dotnet_diagnostic.IDE0280.severity = error
|
||||
|
||||
# Parentheses preferences
|
||||
dotnet_diagnostic.IDE0047.severity = warning
|
||||
dotnet_diagnostic.IDE0048.severity = warning
|
||||
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
|
||||
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
|
||||
dotnet_style_parentheses_in_other_operators = always_for_clarity
|
||||
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
|
||||
|
||||
# Pattern-matching preferences
|
||||
dotnet_diagnostic.IDE0019.severity = warning
|
||||
dotnet_diagnostic.IDE0020.severity = warning
|
||||
dotnet_diagnostic.IDE0038.severity = warning
|
||||
dotnet_diagnostic.IDE0066.severity = none
|
||||
dotnet_diagnostic.IDE0083.severity = warning
|
||||
dotnet_diagnostic.IDE0260.severity = warning
|
||||
csharp_style_pattern_matching_over_as_with_null_check = true
|
||||
csharp_style_pattern_matching_over_is_with_cast_check = true
|
||||
csharp_style_prefer_not_pattern = true
|
||||
csharp_style_prefer_pattern_matching = true
|
||||
|
||||
# this. and Me. preferences
|
||||
dotnet_style_qualification_for_event = false
|
||||
dotnet_style_qualification_for_field = false
|
||||
dotnet_style_qualification_for_method = false
|
||||
dotnet_style_qualification_for_property = false
|
||||
|
||||
# var preferences
|
||||
csharp_style_var_for_built_in_types = false
|
||||
csharp_style_var_when_type_is_apparent = true
|
||||
|
||||
# .NET formatting options
|
||||
dotnet_separate_import_directive_groups = false
|
||||
dotnet_sort_system_directives_first = true
|
||||
|
||||
# C# formatting options
|
||||
csharp_indent_block_contents = true
|
||||
csharp_indent_braces = false
|
||||
csharp_indent_case_contents = true
|
||||
csharp_indent_case_contents_when_block = false
|
||||
csharp_indent_labels = one_less_than_current
|
||||
csharp_indent_switch_labels = true
|
||||
csharp_new_line_before_catch = true
|
||||
csharp_new_line_before_else = true
|
||||
csharp_new_line_before_finally = true
|
||||
csharp_new_line_before_members_in_anonymous_types = true
|
||||
csharp_new_line_before_members_in_object_initializers = true
|
||||
csharp_new_line_before_open_brace = all
|
||||
csharp_new_line_between_query_expression_clauses = true
|
||||
csharp_preserve_single_line_blocks = true
|
||||
csharp_preserve_single_line_statements = true
|
||||
csharp_space_after_cast = false
|
||||
csharp_space_after_colon_in_inheritance_clause = true
|
||||
csharp_space_after_comma = true
|
||||
csharp_space_after_dot = false
|
||||
csharp_space_after_keywords_in_control_flow_statements = true
|
||||
csharp_space_after_semicolon_in_for_statement = true
|
||||
csharp_space_around_binary_operators = before_and_after
|
||||
csharp_space_around_declaration_statements = false
|
||||
csharp_space_before_colon_in_inheritance_clause = true
|
||||
csharp_space_before_comma = false
|
||||
csharp_space_before_dot = false
|
||||
csharp_space_before_open_square_brackets = false
|
||||
csharp_space_before_semicolon_in_for_statement = false
|
||||
csharp_space_between_empty_square_brackets = false
|
||||
csharp_space_between_method_call_empty_parameter_list_parentheses = false
|
||||
csharp_space_between_method_call_name_and_opening_parenthesis = false
|
||||
csharp_space_between_method_call_parameter_list_parentheses = false
|
||||
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
|
||||
csharp_space_between_method_declaration_parameter_list_parentheses = false
|
||||
csharp_space_between_parentheses = false
|
||||
csharp_space_between_square_brackets = false
|
||||
@@ -10,7 +10,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>2.2.0</Version>
|
||||
<Version>2.2.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Support All Frameworks -->
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace ExtractionTool
|
||||
var commandSet = CreateCommands(mainFeature);
|
||||
|
||||
// If we have no args, show the help and quit
|
||||
if (args == null || args.Length == 0)
|
||||
if (args is null || args.Length == 0)
|
||||
{
|
||||
commandSet.OutputAllHelp();
|
||||
return;
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace InfoPrint.Features
|
||||
if (Hash)
|
||||
{
|
||||
var hashBuilder = PrintHashInfo(file);
|
||||
if (hashBuilder != null)
|
||||
if (hashBuilder is not null)
|
||||
{
|
||||
// Create the output data
|
||||
string hashData = hashBuilder.ToString();
|
||||
@@ -172,7 +172,7 @@ namespace InfoPrint.Features
|
||||
var wrapper = WrapperFactory.CreateWrapper(ft, stream);
|
||||
|
||||
// If we don't have a wrapper
|
||||
if (wrapper == null)
|
||||
if (wrapper is null)
|
||||
{
|
||||
Console.WriteLine($"Either {ft} is not supported or something went wrong during parsing!");
|
||||
Console.WriteLine();
|
||||
@@ -195,7 +195,7 @@ namespace InfoPrint.Features
|
||||
|
||||
// Create the output data
|
||||
var builder = wrapper.ExportStringBuilder();
|
||||
if (builder == null)
|
||||
if (builder is null)
|
||||
{
|
||||
Console.WriteLine("No item information could be generated");
|
||||
return;
|
||||
@@ -235,7 +235,7 @@ namespace InfoPrint.Features
|
||||
{
|
||||
// Get all file hashes for flexibility
|
||||
var hashes = HashTool.GetFileHashes(file);
|
||||
if (hashes == null)
|
||||
if (hashes is null)
|
||||
{
|
||||
if (Debug) Console.WriteLine($"Hashes for {file} could not be retrieved");
|
||||
return null;
|
||||
@@ -243,27 +243,29 @@ namespace InfoPrint.Features
|
||||
|
||||
// Output subset of available hashes
|
||||
var builder = new StringBuilder();
|
||||
if (hashes.TryGetValue(HashType.CRC16, out string? crc16) && crc16 != null)
|
||||
if (hashes.TryGetValue(HashType.CRC16, out string? crc16) && crc16 is not null)
|
||||
builder.AppendLine($"CRC-16 checksum: {crc16}");
|
||||
if (hashes.TryGetValue(HashType.CRC32, out string? crc32) && crc32 != null)
|
||||
if (hashes.TryGetValue(HashType.CRC32, out string? crc32) && crc32 is not null)
|
||||
builder.AppendLine($"CRC-32 checksum: {crc32}");
|
||||
if (hashes.TryGetValue(HashType.MD2, out string? md2) && md2 != null)
|
||||
if (hashes.TryGetValue(HashType.CRC64, out string? crc64) && crc64 is not null)
|
||||
builder.AppendLine($"CRC-64 checksum: {crc64}");
|
||||
if (hashes.TryGetValue(HashType.MD2, out string? md2) && md2 is not null)
|
||||
builder.AppendLine($"MD2 hash: {md2}");
|
||||
if (hashes.TryGetValue(HashType.MD4, out string? md4) && md4 != null)
|
||||
if (hashes.TryGetValue(HashType.MD4, out string? md4) && md4 is not null)
|
||||
builder.AppendLine($"MD4 hash: {md4}");
|
||||
if (hashes.TryGetValue(HashType.MD5, out string? md5) && md5 != null)
|
||||
if (hashes.TryGetValue(HashType.MD5, out string? md5) && md5 is not null)
|
||||
builder.AppendLine($"MD5 hash: {md5}");
|
||||
if (hashes.TryGetValue(HashType.RIPEMD128, out string? ripemd128) && ripemd128 != null)
|
||||
if (hashes.TryGetValue(HashType.RIPEMD128, out string? ripemd128) && ripemd128 is not null)
|
||||
builder.AppendLine($"RIPEMD-128 hash: {ripemd128}");
|
||||
if (hashes.TryGetValue(HashType.RIPEMD160, out string? ripemd160) && ripemd160 != null)
|
||||
if (hashes.TryGetValue(HashType.RIPEMD160, out string? ripemd160) && ripemd160 is not null)
|
||||
builder.AppendLine($"RIPEMD-160 hash: {ripemd160}");
|
||||
if (hashes.TryGetValue(HashType.SHA1, out string? sha1) && sha1 != null)
|
||||
if (hashes.TryGetValue(HashType.SHA1, out string? sha1) && sha1 is not null)
|
||||
builder.AppendLine($"SHA-1 hash: {sha1}");
|
||||
if (hashes.TryGetValue(HashType.SHA256, out string? sha256) && sha256 != null)
|
||||
if (hashes.TryGetValue(HashType.SHA256, out string? sha256) && sha256 is not null)
|
||||
builder.AppendLine($"SHA-256 hash: {sha256}");
|
||||
if (hashes.TryGetValue(HashType.SHA384, out string? sha384) && sha384 != null)
|
||||
if (hashes.TryGetValue(HashType.SHA384, out string? sha384) && sha384 is not null)
|
||||
builder.AppendLine($"SHA-384 hash: {sha384}");
|
||||
if (hashes.TryGetValue(HashType.SHA512, out string? sha512) && sha512 != null)
|
||||
if (hashes.TryGetValue(HashType.SHA512, out string? sha512) && sha512 is not null)
|
||||
builder.AppendLine($"SHA-512 hash: {sha512}");
|
||||
|
||||
return builder;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>2.2.0</Version>
|
||||
<Version>2.2.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Support All Frameworks -->
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace InfoPrint
|
||||
var commandSet = CreateCommands(mainFeature);
|
||||
|
||||
// If we have no args, show the help and quit
|
||||
if (args == null || args.Length == 0)
|
||||
if (args is null || args.Length == 0)
|
||||
{
|
||||
commandSet.OutputAllHelp();
|
||||
return;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Data.Models.ArchiveDotOrg.Files files = Build();
|
||||
|
||||
// Serialize to generic model
|
||||
SabreTools.Data.Models.Metadata.MetadataFile? metadata = serializer.Serialize(files);
|
||||
Data.Models.Metadata.MetadataFile? metadata = serializer.Serialize(files);
|
||||
Assert.NotNull(metadata);
|
||||
|
||||
// Serialize back to original model
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.NotNull(newMf.Game);
|
||||
var newGame = Assert.Single(newMf.Game);
|
||||
Validate(newGame);
|
||||
Validate(newMf.Info);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,6 +52,7 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.NotNull(newMf.Game);
|
||||
var newGame = Assert.Single(newMf.Game);
|
||||
Validate(newGame);
|
||||
Validate(newMf.Info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -97,7 +99,9 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
{
|
||||
Name = "XXXXXX",
|
||||
Size = "XXXXXX",
|
||||
CRC16 = "XXXXXX",
|
||||
CRC = "XXXXXX",
|
||||
CRC64 = "XXXXXX",
|
||||
MD2 = "XXXXXX",
|
||||
MD4 = "XXXXXX",
|
||||
MD5 = "XXXXXX",
|
||||
@@ -207,6 +211,7 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
: new Data.Models.ClrMamePro.Machine();
|
||||
gameBase.Name = "XXXXXX";
|
||||
gameBase.Description = "XXXXXX";
|
||||
gameBase.DriverStatus = "XXXXXX";
|
||||
gameBase.Year = "XXXXXX";
|
||||
gameBase.Manufacturer = "XXXXXX";
|
||||
gameBase.Category = "XXXXXX";
|
||||
@@ -227,10 +232,16 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
gameBase.DipSwitch = [dipswitch];
|
||||
gameBase.Driver = driver;
|
||||
|
||||
var info = new Data.Models.ClrMamePro.Info
|
||||
{
|
||||
Source = ["XXXXXX"],
|
||||
};
|
||||
|
||||
return new Data.Models.ClrMamePro.MetadataFile
|
||||
{
|
||||
ClrMamePro = cmp,
|
||||
Game = [gameBase],
|
||||
Info = info,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -265,6 +276,7 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.NotNull(gb);
|
||||
Assert.Equal("XXXXXX", gb.Name);
|
||||
Assert.Equal("XXXXXX", gb.Description);
|
||||
// Assert.Equal("XXXXXX", gb.DriverStatus); // TODO: Needs metadata mapping
|
||||
Assert.Equal("XXXXXX", gb.Year);
|
||||
Assert.Equal("XXXXXX", gb.Manufacturer);
|
||||
Assert.Equal("XXXXXX", gb.Category);
|
||||
@@ -350,7 +362,9 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.NotNull(rom);
|
||||
Assert.Equal("XXXXXX", rom.Name);
|
||||
Assert.Equal("XXXXXX", rom.Size);
|
||||
Assert.Equal("XXXXXX", rom.CRC16);
|
||||
Assert.Equal("XXXXXX", rom.CRC);
|
||||
Assert.Equal("XXXXXX", rom.CRC64);
|
||||
Assert.Equal("XXXXXX", rom.MD2);
|
||||
Assert.Equal("XXXXXX", rom.MD4);
|
||||
Assert.Equal("XXXXXX", rom.MD5);
|
||||
@@ -497,5 +511,16 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.Equal("XXXXXX", driver.PaletteSize);
|
||||
Assert.Equal("XXXXXX", driver.Blit);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate a ClrMamePro
|
||||
/// </summary>
|
||||
private static void Validate(Data.Models.ClrMamePro.Info? info)
|
||||
{
|
||||
Assert.NotNull(info);
|
||||
Assert.NotNull(info.Source);
|
||||
string source = Assert.Single(info.Source);
|
||||
Assert.Equal("XXXXXX", source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +219,7 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
/// </summary>
|
||||
private static Data.Models.Hashfile.Hashfile Build(HashType hashType)
|
||||
{
|
||||
#pragma warning disable IDE0072
|
||||
return hashType switch
|
||||
{
|
||||
HashType.CRC32 => new Data.Models.Hashfile.Hashfile { SFV = [new Data.Models.Hashfile.SFV { File = "XXXXXX", Hash = "XXXXXX" }] },
|
||||
@@ -230,8 +231,9 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
HashType.SHA384 => new Data.Models.Hashfile.Hashfile { SHA384 = [new Data.Models.Hashfile.SHA384 { Hash = "XXXXXX", File = "XXXXXX" }] },
|
||||
HashType.SHA512 => new Data.Models.Hashfile.Hashfile { SHA512 = [new Data.Models.Hashfile.SHA512 { Hash = "XXXXXX", File = "XXXXXX" }] },
|
||||
HashType.SpamSum => new Data.Models.Hashfile.Hashfile { SpamSum = [new Data.Models.Hashfile.SpamSum { Hash = "XXXXXX", File = "XXXXXX" }] },
|
||||
_ => throw new ArgumentOutOfRangeException(),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(hashType)),
|
||||
};
|
||||
#pragma warning restore IDE0072
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -150,7 +150,9 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
{
|
||||
Name = "XXXXXX",
|
||||
Size = "XXXXXX",
|
||||
CRC16 = "XXXXXX",
|
||||
CRC = "XXXXXX",
|
||||
CRC64 = "XXXXXX",
|
||||
MD2 = "XXXXXX",
|
||||
MD4 = "XXXXXX",
|
||||
MD5 = "XXXXXX",
|
||||
@@ -464,7 +466,9 @@ namespace SabreTools.Serialization.Test.CrossModel
|
||||
Assert.NotNull(rom);
|
||||
Assert.Equal("XXXXXX", rom.Name);
|
||||
Assert.Equal("XXXXXX", rom.Size);
|
||||
Assert.Equal("XXXXXX", rom.CRC16);
|
||||
Assert.Equal("XXXXXX", rom.CRC);
|
||||
Assert.Equal("XXXXXX", rom.CRC64);
|
||||
Assert.Equal("XXXXXX", rom.MD2);
|
||||
Assert.Equal("XXXXXX", rom.MD4);
|
||||
Assert.Equal("XXXXXX", rom.MD5);
|
||||
|
||||
@@ -3,6 +3,7 @@ using SabreTools.Data.Extensions;
|
||||
using SabreTools.Data.Models.ASN1;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable IDE0230 // Use UTF-8 string literal
|
||||
namespace SabreTools.Serialization.Test.Extensions
|
||||
{
|
||||
public class TypeLengthValueTests
|
||||
@@ -31,7 +32,7 @@ namespace SabreTools.Serialization.Test.Extensions
|
||||
public void Format_InvalidConstructed()
|
||||
{
|
||||
string expected = "Type: V_ASN1_OBJECT, V_ASN1_CONSTRUCTED, Length: 1, Value: [INVALID DATA TYPE]";
|
||||
var tlv = new Data.Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OBJECT | ASN1Type.V_ASN1_CONSTRUCTED, Length = 1, Value = (object?)false };
|
||||
var tlv = new Data.Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OBJECT | ASN1Type.V_ASN1_CONSTRUCTED, Length = 1, Value = false };
|
||||
string actual = tlv.Format();
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
@@ -50,7 +51,7 @@ namespace SabreTools.Serialization.Test.Extensions
|
||||
public void Format_InvalidDataType()
|
||||
{
|
||||
string expected = "Type: V_ASN1_OBJECT, Length: 1, Value: [INVALID DATA TYPE]";
|
||||
var tlv = new Data.Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OBJECT, Length = 1, Value = (object?)false };
|
||||
var tlv = new Data.Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OBJECT, Length = 1, Value = false };
|
||||
string actual = tlv.Format();
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SabreTools.Serialization.Readers;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
public class AppPkgHeaderTests
|
||||
{
|
||||
[Fact]
|
||||
public void NullArray_Null()
|
||||
{
|
||||
byte[]? data = null;
|
||||
int offset = 0;
|
||||
var deserializer = new AppPkgHeader();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyArray_Null()
|
||||
{
|
||||
byte[]? data = [];
|
||||
int offset = 0;
|
||||
var deserializer = new AppPkgHeader();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidArray_Null()
|
||||
{
|
||||
byte[]? data = [.. Enumerable.Repeat<byte>(0xFF, 1024)];
|
||||
int offset = 0;
|
||||
var deserializer = new AppPkgHeader();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullStream_Null()
|
||||
{
|
||||
Stream? data = null;
|
||||
var deserializer = new AppPkgHeader();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([]);
|
||||
var deserializer = new AppPkgHeader();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([.. Enumerable.Repeat<byte>(0xFF, 1024)]);
|
||||
var deserializer = new AppPkgHeader();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SabreTools.Serialization.Readers;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
public class AppPkgHeaderTests
|
||||
{
|
||||
[Fact]
|
||||
public void NullArray_Null()
|
||||
{
|
||||
byte[]? data = null;
|
||||
int offset = 0;
|
||||
var deserializer = new AppPkgHeader();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyArray_Null()
|
||||
{
|
||||
byte[]? data = [];
|
||||
int offset = 0;
|
||||
var deserializer = new AppPkgHeader();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidArray_Null()
|
||||
{
|
||||
byte[]? data = [.. Enumerable.Repeat<byte>(0xFF, 1024)];
|
||||
int offset = 0;
|
||||
var deserializer = new AppPkgHeader();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullStream_Null()
|
||||
{
|
||||
Stream? data = null;
|
||||
var deserializer = new AppPkgHeader();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([]);
|
||||
var deserializer = new AppPkgHeader();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([.. Enumerable.Repeat<byte>(0xFF, 1024)]);
|
||||
var deserializer = new AppPkgHeader();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new ArchiveDotOrg();
|
||||
var serializer = new SabreTools.Serialization.Writers.ArchiveDotOrg();
|
||||
var serializer = new Serialization.Writers.ArchiveDotOrg();
|
||||
|
||||
// Build the data
|
||||
Data.Models.ArchiveDotOrg.Files files = Build();
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new AttractMode();
|
||||
var serializer = new SabreTools.Serialization.Writers.AttractMode();
|
||||
var serializer = new Serialization.Writers.AttractMode();
|
||||
|
||||
// Build the data
|
||||
Data.Models.AttractMode.MetadataFile mf = Build();
|
||||
@@ -101,7 +101,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new AttractMode();
|
||||
var serializer = new SabreTools.Serialization.Writers.AttractMode();
|
||||
var serializer = new Serialization.Writers.AttractMode();
|
||||
|
||||
// Build the data
|
||||
Data.Models.AttractMode.MetadataFile mf = Build();
|
||||
@@ -168,9 +168,9 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
Assert.NotNull(header);
|
||||
if (longHeader)
|
||||
Assert.True(SabreTools.Serialization.Writers.AttractMode.HeaderArrayWithRomname.SequenceEqual(header));
|
||||
Assert.True(Serialization.Writers.AttractMode.HeaderArrayWithRomname.SequenceEqual(header));
|
||||
else
|
||||
Assert.True(SabreTools.Serialization.Writers.AttractMode.HeaderArrayWithoutRomname.SequenceEqual(header));
|
||||
Assert.True(Serialization.Writers.AttractMode.HeaderArrayWithoutRomname.SequenceEqual(header));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new ClrMamePro();
|
||||
var serializer = new SabreTools.Serialization.Writers.ClrMamePro();
|
||||
var serializer = new Serialization.Writers.ClrMamePro();
|
||||
|
||||
// Build the data
|
||||
Data.Models.ClrMamePro.MetadataFile mf = Build(game: true);
|
||||
@@ -93,6 +93,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.NotNull(newMf.Game);
|
||||
var newGame = Assert.Single(newMf.Game);
|
||||
Validate(newGame);
|
||||
Validate(newMf.Info);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -100,7 +101,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new ClrMamePro();
|
||||
var serializer = new SabreTools.Serialization.Writers.ClrMamePro();
|
||||
var serializer = new Serialization.Writers.ClrMamePro();
|
||||
|
||||
// Build the data
|
||||
Data.Models.ClrMamePro.MetadataFile mf = Build(game: true);
|
||||
@@ -118,6 +119,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.NotNull(newMf.Game);
|
||||
var newGame = Assert.Single(newMf.Game);
|
||||
Validate(newGame);
|
||||
Validate(newMf.Info);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -125,7 +127,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new ClrMamePro();
|
||||
var serializer = new SabreTools.Serialization.Writers.ClrMamePro();
|
||||
var serializer = new Serialization.Writers.ClrMamePro();
|
||||
|
||||
// Build the data
|
||||
Data.Models.ClrMamePro.MetadataFile mf = Build(game: false);
|
||||
@@ -150,7 +152,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new ClrMamePro();
|
||||
var serializer = new SabreTools.Serialization.Writers.ClrMamePro();
|
||||
var serializer = new Serialization.Writers.ClrMamePro();
|
||||
|
||||
// Build the data
|
||||
Data.Models.ClrMamePro.MetadataFile mf = Build(game: false);
|
||||
@@ -214,7 +216,9 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
Name = "XXXXXX",
|
||||
Size = "XXXXXX",
|
||||
CRC16 = "XXXXXX",
|
||||
CRC = "XXXXXX",
|
||||
CRC64 = "XXXXXX",
|
||||
MD2 = "XXXXXX",
|
||||
MD4 = "XXXXXX",
|
||||
MD5 = "XXXXXX",
|
||||
@@ -324,6 +328,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
: new Data.Models.ClrMamePro.Machine();
|
||||
gameBase.Name = "XXXXXX";
|
||||
gameBase.Description = "XXXXXX";
|
||||
gameBase.DriverStatus = "XXXXXX";
|
||||
gameBase.Year = "XXXXXX";
|
||||
gameBase.Manufacturer = "XXXXXX";
|
||||
gameBase.Category = "XXXXXX";
|
||||
@@ -344,10 +349,16 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
gameBase.DipSwitch = [dipswitch];
|
||||
gameBase.Driver = driver;
|
||||
|
||||
var info = new Data.Models.ClrMamePro.Info
|
||||
{
|
||||
Source = ["XXXXXX"],
|
||||
};
|
||||
|
||||
return new Data.Models.ClrMamePro.MetadataFile
|
||||
{
|
||||
ClrMamePro = cmp,
|
||||
Game = [gameBase],
|
||||
Info = info,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -382,6 +393,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.NotNull(gb);
|
||||
Assert.Equal("XXXXXX", gb.Name);
|
||||
Assert.Equal("XXXXXX", gb.Description);
|
||||
// Assert.Equal("XXXXXX", gb.DriverStatus); // TODO: Needs metadata mapping
|
||||
Assert.Equal("XXXXXX", gb.Year);
|
||||
Assert.Equal("XXXXXX", gb.Manufacturer);
|
||||
Assert.Equal("XXXXXX", gb.Category);
|
||||
@@ -467,7 +479,9 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.NotNull(rom);
|
||||
Assert.Equal("XXXXXX", rom.Name);
|
||||
Assert.Equal("XXXXXX", rom.Size);
|
||||
Assert.Equal("XXXXXX", rom.CRC16);
|
||||
Assert.Equal("XXXXXX", rom.CRC);
|
||||
Assert.Equal("XXXXXX", rom.CRC64);
|
||||
Assert.Equal("XXXXXX", rom.MD2);
|
||||
Assert.Equal("XXXXXX", rom.MD4);
|
||||
Assert.Equal("XXXXXX", rom.MD5);
|
||||
@@ -614,5 +628,16 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Equal("XXXXXX", driver.PaletteSize);
|
||||
Assert.Equal("XXXXXX", driver.Blit);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate a ClrMamePro
|
||||
/// </summary>
|
||||
private static void Validate(Data.Models.ClrMamePro.Info? info)
|
||||
{
|
||||
Assert.NotNull(info);
|
||||
Assert.NotNull(info.Source);
|
||||
string source = Assert.Single(info.Source);
|
||||
Assert.Equal("XXXXXX", source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new DosCenter();
|
||||
var serializer = new SabreTools.Serialization.Writers.DosCenter();
|
||||
var serializer = new Serialization.Writers.DosCenter();
|
||||
|
||||
// Build the data
|
||||
Data.Models.DosCenter.MetadataFile mf = Build();
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new EverdriveSMDB();
|
||||
var serializer = new SabreTools.Serialization.Writers.EverdriveSMDB();
|
||||
var serializer = new Serialization.Writers.EverdriveSMDB();
|
||||
|
||||
// Build the data
|
||||
Data.Models.EverdriveSMDB.MetadataFile mf = Build();
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Hashfile();
|
||||
var serializer = new SabreTools.Serialization.Writers.Hashfile();
|
||||
var serializer = new Serialization.Writers.Hashfile();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Hashfile.Hashfile hf = Build(HashType.CRC32);
|
||||
@@ -101,7 +101,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Hashfile();
|
||||
var serializer = new SabreTools.Serialization.Writers.Hashfile();
|
||||
var serializer = new Serialization.Writers.Hashfile();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Hashfile.Hashfile hf = Build(HashType.MD2);
|
||||
@@ -125,7 +125,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Hashfile();
|
||||
var serializer = new SabreTools.Serialization.Writers.Hashfile();
|
||||
var serializer = new Serialization.Writers.Hashfile();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Hashfile.Hashfile hf = Build(HashType.MD4);
|
||||
@@ -149,7 +149,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Hashfile();
|
||||
var serializer = new SabreTools.Serialization.Writers.Hashfile();
|
||||
var serializer = new Serialization.Writers.Hashfile();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Hashfile.Hashfile hf = Build(HashType.MD5);
|
||||
@@ -173,7 +173,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Hashfile();
|
||||
var serializer = new SabreTools.Serialization.Writers.Hashfile();
|
||||
var serializer = new Serialization.Writers.Hashfile();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Hashfile.Hashfile hf = Build(HashType.SHA1);
|
||||
@@ -197,7 +197,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Hashfile();
|
||||
var serializer = new SabreTools.Serialization.Writers.Hashfile();
|
||||
var serializer = new Serialization.Writers.Hashfile();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Hashfile.Hashfile hf = Build(HashType.SHA256);
|
||||
@@ -221,7 +221,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Hashfile();
|
||||
var serializer = new SabreTools.Serialization.Writers.Hashfile();
|
||||
var serializer = new Serialization.Writers.Hashfile();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Hashfile.Hashfile hf = Build(HashType.SHA384);
|
||||
@@ -245,7 +245,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Hashfile();
|
||||
var serializer = new SabreTools.Serialization.Writers.Hashfile();
|
||||
var serializer = new Serialization.Writers.Hashfile();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Hashfile.Hashfile hf = Build(HashType.SHA512);
|
||||
@@ -269,7 +269,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Hashfile();
|
||||
var serializer = new SabreTools.Serialization.Writers.Hashfile();
|
||||
var serializer = new Serialization.Writers.Hashfile();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Hashfile.Hashfile hf = Build(HashType.SpamSum);
|
||||
@@ -293,6 +293,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
/// </summary>
|
||||
private static Data.Models.Hashfile.Hashfile Build(HashType hashType)
|
||||
{
|
||||
#pragma warning disable IDE0072
|
||||
return hashType switch
|
||||
{
|
||||
HashType.CRC32 => new Data.Models.Hashfile.Hashfile { SFV = [new Data.Models.Hashfile.SFV { File = "XXXXXX", Hash = "XXXXXX" }] },
|
||||
@@ -304,8 +305,9 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
HashType.SHA384 => new Data.Models.Hashfile.Hashfile { SHA384 = [new Data.Models.Hashfile.SHA384 { Hash = "XXXXXX", File = "XXXXXX" }] },
|
||||
HashType.SHA512 => new Data.Models.Hashfile.Hashfile { SHA512 = [new Data.Models.Hashfile.SHA512 { Hash = "XXXXXX", File = "XXXXXX" }] },
|
||||
HashType.SpamSum => new Data.Models.Hashfile.Hashfile { SpamSum = [new Data.Models.Hashfile.SpamSum { Hash = "XXXXXX", File = "XXXXXX" }] },
|
||||
_ => throw new ArgumentOutOfRangeException(),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(hashType)),
|
||||
};
|
||||
#pragma warning restore IDE0072
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -5,14 +5,14 @@ using Xunit;
|
||||
|
||||
namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
public class InstallShieldExecutableFileTests
|
||||
public class InstallShieldExecutableTests
|
||||
{
|
||||
[Fact]
|
||||
public void NullArray_Null()
|
||||
{
|
||||
byte[]? data = null;
|
||||
int offset = 0;
|
||||
var deserializer = new InstallShieldExecutableFile();
|
||||
var deserializer = new InstallShieldExecutable();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
@@ -23,7 +23,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
byte[]? data = [];
|
||||
int offset = 0;
|
||||
var deserializer = new InstallShieldExecutableFile();
|
||||
var deserializer = new InstallShieldExecutable();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
@@ -34,7 +34,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
byte[]? data = [.. Enumerable.Repeat<byte>(0xFF, 1024)];
|
||||
int offset = 0;
|
||||
var deserializer = new InstallShieldExecutableFile();
|
||||
var deserializer = new InstallShieldExecutable();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
@@ -44,7 +44,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
public void NullStream_Null()
|
||||
{
|
||||
Stream? data = null;
|
||||
var deserializer = new InstallShieldExecutableFile();
|
||||
var deserializer = new InstallShieldExecutable();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
@@ -54,7 +54,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
public void EmptyStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([]);
|
||||
var deserializer = new InstallShieldExecutableFile();
|
||||
var deserializer = new InstallShieldExecutable();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
@@ -64,7 +64,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
public void InvalidStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([.. Enumerable.Repeat<byte>(0xFF, 1024)]);
|
||||
var deserializer = new InstallShieldExecutableFile();
|
||||
var deserializer = new InstallShieldExecutable();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
@@ -75,7 +75,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Listrom();
|
||||
var serializer = new SabreTools.Serialization.Writers.Listrom();
|
||||
var serializer = new Serialization.Writers.Listrom();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Listrom.MetadataFile mf = Build();
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Listxml();
|
||||
var serializer = new SabreTools.Serialization.Writers.Listxml();
|
||||
var serializer = new Serialization.Writers.Listxml();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Listxml.Mame mame = Build(game: true);
|
||||
@@ -103,7 +103,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Listxml();
|
||||
var serializer = new SabreTools.Serialization.Writers.Listxml();
|
||||
var serializer = new Serialization.Writers.Listxml();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Listxml.Mame mame = Build(game: false);
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Logiqx();
|
||||
var serializer = new SabreTools.Serialization.Writers.Logiqx();
|
||||
var serializer = new Serialization.Writers.Logiqx();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Logiqx.Datafile df = Build(game: true);
|
||||
@@ -107,7 +107,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Logiqx();
|
||||
var serializer = new SabreTools.Serialization.Writers.Logiqx();
|
||||
var serializer = new Serialization.Writers.Logiqx();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Logiqx.Datafile df = Build(game: false);
|
||||
@@ -215,7 +215,9 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
Name = "XXXXXX",
|
||||
Size = "XXXXXX",
|
||||
CRC16 = "XXXXXX",
|
||||
CRC = "XXXXXX",
|
||||
CRC64 = "XXXXXX",
|
||||
MD2 = "XXXXXX",
|
||||
MD4 = "XXXXXX",
|
||||
MD5 = "XXXXXX",
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new M1();
|
||||
var serializer = new SabreTools.Serialization.Writers.M1();
|
||||
var serializer = new Serialization.Writers.M1();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Listxml.M1 m1 = Build(game: true);
|
||||
@@ -101,7 +101,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new M1();
|
||||
var serializer = new SabreTools.Serialization.Writers.M1();
|
||||
var serializer = new Serialization.Writers.M1();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Listxml.M1 m1 = Build(game: false);
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Mess();
|
||||
var serializer = new SabreTools.Serialization.Writers.Mess();
|
||||
var serializer = new Serialization.Writers.Mess();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Listxml.Mess m1 = Build(game: true);
|
||||
@@ -101,7 +101,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new Mess();
|
||||
var serializer = new SabreTools.Serialization.Writers.Mess();
|
||||
var serializer = new Serialization.Writers.Mess();
|
||||
|
||||
// Build the data
|
||||
Data.Models.Listxml.Mess m1 = Build(game: false);
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new OfflineList();
|
||||
var serializer = new SabreTools.Serialization.Writers.OfflineList();
|
||||
var serializer = new Serialization.Writers.OfflineList();
|
||||
|
||||
// Build the data
|
||||
Data.Models.OfflineList.Dat dat = Build();
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new OpenMSX();
|
||||
var serializer = new SabreTools.Serialization.Writers.OpenMSX();
|
||||
var serializer = new Serialization.Writers.OpenMSX();
|
||||
|
||||
// Build the data
|
||||
Data.Models.OpenMSX.SoftwareDb sdb = Build();
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new RomCenter();
|
||||
var serializer = new SabreTools.Serialization.Writers.RomCenter();
|
||||
var serializer = new Serialization.Writers.RomCenter();
|
||||
|
||||
// Build the data
|
||||
Data.Models.RomCenter.MetadataFile mf = Build();
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new SeparatedValue();
|
||||
var serializer = new SabreTools.Serialization.Writers.SeparatedValue();
|
||||
var serializer = new Serialization.Writers.SeparatedValue();
|
||||
|
||||
// Build the data
|
||||
Data.Models.SeparatedValue.MetadataFile mf = Build();
|
||||
@@ -104,7 +104,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new SeparatedValue();
|
||||
var serializer = new SabreTools.Serialization.Writers.SeparatedValue();
|
||||
var serializer = new Serialization.Writers.SeparatedValue();
|
||||
|
||||
// Build the data
|
||||
Data.Models.SeparatedValue.MetadataFile mf = Build();
|
||||
@@ -197,9 +197,9 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
Assert.NotNull(header);
|
||||
if (longHeader)
|
||||
Assert.True(SabreTools.Serialization.Writers.SeparatedValue.HeaderArrayExtended.SequenceEqual(header));
|
||||
Assert.True(Serialization.Writers.SeparatedValue.HeaderArrayExtended.SequenceEqual(header));
|
||||
else
|
||||
Assert.True(SabreTools.Serialization.Writers.SeparatedValue.HeaderArrayStandard.SequenceEqual(header));
|
||||
Assert.True(Serialization.Writers.SeparatedValue.HeaderArrayStandard.SequenceEqual(header));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -233,6 +233,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(row.SHA512);
|
||||
Assert.Null(row.SpamSum);
|
||||
}
|
||||
|
||||
Assert.Equal("XXXXXX", row.Status);
|
||||
}
|
||||
|
||||
@@ -267,6 +268,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(row.SHA512);
|
||||
Assert.Null(row.SpamSum);
|
||||
}
|
||||
|
||||
Assert.NotNull(row.Status); Assert.Empty(row.Status);
|
||||
}
|
||||
|
||||
@@ -302,6 +304,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
Assert.Null(row.SHA512);
|
||||
Assert.Null(row.SpamSum);
|
||||
}
|
||||
|
||||
Assert.Equal("XXXXXX", row.Status);
|
||||
}
|
||||
}
|
||||
|
||||
73
SabreTools.Serialization.Test/Readers/SkuSisTests.cs
Normal file
73
SabreTools.Serialization.Test/Readers/SkuSisTests.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SabreTools.Serialization.Readers;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
public class SkuSisTests
|
||||
{
|
||||
[Fact]
|
||||
public void NullArray_Null()
|
||||
{
|
||||
byte[]? data = null;
|
||||
int offset = 0;
|
||||
var deserializer = new SkuSis();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyArray_Null()
|
||||
{
|
||||
byte[]? data = [];
|
||||
int offset = 0;
|
||||
var deserializer = new SkuSis();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidArray_Null()
|
||||
{
|
||||
byte[]? data = [.. Enumerable.Repeat<byte>(0xFF, 1024)];
|
||||
int offset = 0;
|
||||
var deserializer = new SkuSis();
|
||||
|
||||
var actual = deserializer.Deserialize(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullStream_Null()
|
||||
{
|
||||
Stream? data = null;
|
||||
var deserializer = new SkuSis();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([]);
|
||||
var deserializer = new SkuSis();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([.. Enumerable.Repeat<byte>(0xFF, 1024)]);
|
||||
var deserializer = new SkuSis();
|
||||
|
||||
var actual = deserializer.Deserialize(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ namespace SabreTools.Serialization.Test.Readers
|
||||
{
|
||||
// Get the serializer and deserializer
|
||||
var deserializer = new SoftwareList();
|
||||
var serializer = new SabreTools.Serialization.Writers.SoftwareList();
|
||||
var serializer = new Serialization.Writers.SoftwareList();
|
||||
|
||||
// Build the data
|
||||
Data.Models.SoftwareList.SoftwareList sl = Build();
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using SabreTools.Serialization.Wrappers;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable xUnit1004 // Test methods should not be skipped
|
||||
namespace SabreTools.Serialization.Test.Wrappers
|
||||
{
|
||||
public class BZip2Tests
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using SabreTools.Serialization.Wrappers;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable xUnit1004 // Test methods should not be skipped
|
||||
namespace SabreTools.Serialization.Test.Wrappers
|
||||
{
|
||||
public class LDSCRYPTTests
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using SabreTools.Serialization.Wrappers;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable xUnit1004 // Test methods should not be skipped
|
||||
namespace SabreTools.Serialization.Test.Wrappers
|
||||
{
|
||||
public class RARTests
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using SabreTools.Serialization.Wrappers;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable xUnit1004 // Test methods should not be skipped
|
||||
namespace SabreTools.Serialization.Test.Wrappers
|
||||
{
|
||||
public class RealArcadeInstallerTests
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using SabreTools.Serialization.Wrappers;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable xUnit1004 // Test methods should not be skipped
|
||||
namespace SabreTools.Serialization.Test.Wrappers
|
||||
{
|
||||
public class RealArcadeMezzanineTests
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using SabreTools.Serialization.Wrappers;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable xUnit1004 // Test methods should not be skipped
|
||||
namespace SabreTools.Serialization.Test.Wrappers
|
||||
{
|
||||
public class SevenZipTests
|
||||
|
||||
61
SabreTools.Serialization.Test/Wrappers/SkuSisTests.cs
Normal file
61
SabreTools.Serialization.Test/Wrappers/SkuSisTests.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SabreTools.Serialization.Wrappers;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.Serialization.Test.Wrappers
|
||||
{
|
||||
public class SkuSisTests
|
||||
{
|
||||
[Fact]
|
||||
public void NullArray_Null()
|
||||
{
|
||||
byte[]? data = null;
|
||||
int offset = 0;
|
||||
var actual = SkuSis.Create(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyArray_Null()
|
||||
{
|
||||
byte[]? data = [];
|
||||
int offset = 0;
|
||||
var actual = SkuSis.Create(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidArray_Null()
|
||||
{
|
||||
byte[]? data = [.. Enumerable.Repeat<byte>(0xFF, 1024)];
|
||||
int offset = 0;
|
||||
var actual = SkuSis.Create(data, offset);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullStream_Null()
|
||||
{
|
||||
Stream? data = null;
|
||||
var actual = SkuSis.Create(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmptyStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([]);
|
||||
var actual = SkuSis.Create(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InvalidStream_Null()
|
||||
{
|
||||
Stream? data = new MemoryStream([.. Enumerable.Repeat<byte>(0xFF, 1024)]);
|
||||
var actual = SkuSis.Create(data);
|
||||
Assert.Null(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using SabreTools.Serialization.Wrappers;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable xUnit1004 // Test methods should not be skipped
|
||||
namespace SabreTools.Serialization.Test.Wrappers
|
||||
{
|
||||
public class XZTests
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Files? Deserialize(Data.Models.Metadata.MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var files = new Files();
|
||||
@@ -31,7 +31,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
private static File[] ConvertFromInternalModel(Data.Models.Metadata.Machine item)
|
||||
{
|
||||
var roms = item.Read<Data.Models.Metadata.Rom[]>(Data.Models.Metadata.Machine.RomKey);
|
||||
if (roms == null)
|
||||
if (roms is null)
|
||||
return [];
|
||||
|
||||
return Array.ConvertAll(roms, ConvertFromInternalModel);
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(Files? item)
|
||||
{
|
||||
if (item == null)
|
||||
if (item is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile
|
||||
@@ -16,7 +16,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(),
|
||||
};
|
||||
|
||||
if (item?.File != null && item.File.Length > 0)
|
||||
if (item?.File is not null && item.File.Length > 0)
|
||||
{
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.MachineKey]
|
||||
= Array.ConvertAll(item.File, ConvertMachineToInternalModel);
|
||||
@@ -45,7 +45,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
var machine = new Data.Models.Metadata.Machine();
|
||||
|
||||
var rom = ConvertToInternalModel(item);
|
||||
if (rom != null)
|
||||
if (rom is not null)
|
||||
machine[Data.Models.Metadata.Machine.RomKey] = new Data.Models.Metadata.Rom[] { rom };
|
||||
|
||||
return machine;
|
||||
@@ -56,7 +56,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// </summary>
|
||||
private static Data.Models.Metadata.Rom? ConvertToInternalModel(File? item)
|
||||
{
|
||||
if (item == null)
|
||||
if (item is null)
|
||||
return null;
|
||||
|
||||
var rom = new Data.Models.Metadata.Rom
|
||||
|
||||
@@ -9,11 +9,11 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override MetadataFile? Deserialize(Data.Models.Metadata.MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var header = obj.Read<Data.Models.Metadata.Header>(Data.Models.Metadata.MetadataFile.HeaderKey);
|
||||
var metadataFile = header != null ? ConvertHeaderFromInternalModel(header) : new MetadataFile();
|
||||
var metadataFile = header is not null ? ConvertHeaderFromInternalModel(header) : new MetadataFile();
|
||||
|
||||
var machines = obj.Read<Data.Models.Metadata.Machine[]>(Data.Models.Metadata.MetadataFile.MachineKey);
|
||||
var items = new List<Row>();
|
||||
@@ -44,7 +44,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
private static Row[] ConvertMachineFromInternalModel(Data.Models.Metadata.Machine item)
|
||||
{
|
||||
var roms = item.Read<Data.Models.Metadata.Rom[]>(Data.Models.Metadata.Machine.RomKey);
|
||||
if (roms == null || roms.Length == 0)
|
||||
if (roms is null || roms.Length == 0)
|
||||
return [];
|
||||
|
||||
return Array.ConvertAll(roms, r => ConvertFromInternalModel(r, item));
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile
|
||||
@@ -16,7 +16,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(obj),
|
||||
};
|
||||
|
||||
if (obj?.Row != null && obj.Row.Length > 0)
|
||||
if (obj?.Row is not null && obj.Row.Length > 0)
|
||||
{
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.MachineKey]
|
||||
= Array.ConvertAll(obj.Row, ConvertMachineToInternalModel);
|
||||
@@ -42,7 +42,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// </summary>
|
||||
private static Data.Models.Metadata.Machine? ConvertMachineToInternalModel(Row? item)
|
||||
{
|
||||
if (item == null)
|
||||
if (item is null)
|
||||
return null;
|
||||
|
||||
var machine = new Data.Models.Metadata.Machine
|
||||
|
||||
@@ -9,6 +9,9 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <typeparam name="TModel">Model convertable to <see cref="MetadataFile"/></typeparam>
|
||||
public abstract class BaseMetadataSerializer<TModel> : ICrossModel<TModel, MetadataFile>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public bool Debug { get; set; } = false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public abstract TModel? Deserialize(MetadataFile? obj);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using SabreTools.Data.Models.ClrMamePro;
|
||||
|
||||
#pragma warning disable CA1822 // Mark members as static
|
||||
namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
public partial class ClrMamePro : BaseMetadataSerializer<MetadataFile>
|
||||
@@ -12,22 +13,26 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc cref="Deserialize(Data.Models.Metadata.MetadataFile)"/>
|
||||
public MetadataFile? Deserialize(Data.Models.Metadata.MetadataFile? obj, bool game)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new MetadataFile();
|
||||
|
||||
var header = obj.Read<Data.Models.Metadata.Header>(Data.Models.Metadata.MetadataFile.HeaderKey);
|
||||
if (header != null)
|
||||
if (header is not null)
|
||||
metadataFile.ClrMamePro = ConvertHeaderFromInternalModel(header);
|
||||
|
||||
var machines = obj.Read<Data.Models.Metadata.Machine[]>(Data.Models.Metadata.MetadataFile.MachineKey);
|
||||
if (machines != null && machines.Length > 0)
|
||||
if (machines is not null && machines.Length > 0)
|
||||
{
|
||||
metadataFile.Game
|
||||
= Array.ConvertAll(machines, m => ConvertMachineFromInternalModel(m, game));
|
||||
}
|
||||
|
||||
var info = obj.Read<Data.Models.Metadata.InfoSource>(Data.Models.Metadata.MetadataFile.InfoSourceKey);
|
||||
if (info is not null)
|
||||
metadataFile.Info = ConvertInfoSourceFromInternalModel(info);
|
||||
|
||||
return metadataFile;
|
||||
}
|
||||
|
||||
@@ -66,6 +71,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
|
||||
gameBase.Name = item.ReadString(Data.Models.Metadata.Machine.NameKey);
|
||||
gameBase.Description = item.ReadString(Data.Models.Metadata.Machine.DescriptionKey);
|
||||
// gameBase.DriverStatus = item.ReadString(Data.Models.Metadata.Machine.DriverKey); // TODO: Needs metadata mapping
|
||||
gameBase.Year = item.ReadString(Data.Models.Metadata.Machine.YearKey);
|
||||
gameBase.Manufacturer = item.ReadString(Data.Models.Metadata.Machine.ManufacturerKey);
|
||||
gameBase.Category = item.ReadString(Data.Models.Metadata.Machine.CategoryKey);
|
||||
@@ -74,55 +80,55 @@ namespace SabreTools.Serialization.CrossModel
|
||||
gameBase.SampleOf = item.ReadString(Data.Models.Metadata.Machine.SampleOfKey);
|
||||
|
||||
var releases = item.Read<Data.Models.Metadata.Release[]>(Data.Models.Metadata.Machine.ReleaseKey);
|
||||
if (releases != null && releases.Length > 0)
|
||||
if (releases is not null && releases.Length > 0)
|
||||
gameBase.Release = Array.ConvertAll(releases, ConvertFromInternalModel);
|
||||
|
||||
var biosSets = item.Read<Data.Models.Metadata.BiosSet[]>(Data.Models.Metadata.Machine.BiosSetKey);
|
||||
if (biosSets != null && biosSets.Length > 0)
|
||||
if (biosSets is not null && biosSets.Length > 0)
|
||||
gameBase.BiosSet = Array.ConvertAll(biosSets, ConvertFromInternalModel);
|
||||
|
||||
var roms = item.Read<Data.Models.Metadata.Rom[]>(Data.Models.Metadata.Machine.RomKey);
|
||||
if (roms != null && roms.Length > 0)
|
||||
if (roms is not null && roms.Length > 0)
|
||||
gameBase.Rom = Array.ConvertAll(roms, ConvertFromInternalModel);
|
||||
|
||||
var disks = item.Read<Data.Models.Metadata.Disk[]>(Data.Models.Metadata.Machine.DiskKey);
|
||||
if (disks != null && disks.Length > 0)
|
||||
if (disks is not null && disks.Length > 0)
|
||||
gameBase.Disk = Array.ConvertAll(disks, ConvertFromInternalModel);
|
||||
|
||||
var medias = item.Read<Data.Models.Metadata.Media[]>(Data.Models.Metadata.Machine.MediaKey);
|
||||
if (medias != null && medias.Length > 0)
|
||||
if (medias is not null && medias.Length > 0)
|
||||
gameBase.Media = Array.ConvertAll(medias, ConvertFromInternalModel);
|
||||
|
||||
var samples = item.Read<Data.Models.Metadata.Sample[]>(Data.Models.Metadata.Machine.SampleKey);
|
||||
if (samples != null && samples.Length > 0)
|
||||
if (samples is not null && samples.Length > 0)
|
||||
gameBase.Sample = Array.ConvertAll(samples, ConvertFromInternalModel);
|
||||
|
||||
var archives = item.Read<Data.Models.Metadata.Archive[]>(Data.Models.Metadata.Machine.ArchiveKey);
|
||||
if (archives != null && archives.Length > 0)
|
||||
if (archives is not null && archives.Length > 0)
|
||||
gameBase.Archive = Array.ConvertAll(archives, ConvertFromInternalModel);
|
||||
|
||||
var chips = item.Read<Data.Models.Metadata.Chip[]>(Data.Models.Metadata.Machine.ChipKey);
|
||||
if (chips != null && chips.Length > 0)
|
||||
if (chips is not null && chips.Length > 0)
|
||||
gameBase.Chip = Array.ConvertAll(chips, ConvertFromInternalModel);
|
||||
|
||||
var videos = item.Read<Data.Models.Metadata.Video[]>(Data.Models.Metadata.Machine.VideoKey);
|
||||
if (videos != null && videos.Length > 0)
|
||||
if (videos is not null && videos.Length > 0)
|
||||
gameBase.Video = Array.ConvertAll(videos, ConvertFromInternalModel);
|
||||
|
||||
var sound = item.Read<Data.Models.Metadata.Sound>(Data.Models.Metadata.Machine.SoundKey);
|
||||
if (sound != null)
|
||||
if (sound is not null)
|
||||
gameBase.Sound = ConvertFromInternalModel(sound);
|
||||
|
||||
var input = item.Read<Data.Models.Metadata.Input>(Data.Models.Metadata.Machine.InputKey);
|
||||
if (input != null)
|
||||
if (input is not null)
|
||||
gameBase.Input = ConvertFromInternalModel(input);
|
||||
|
||||
var dipSwitches = item.Read<Data.Models.Metadata.DipSwitch[]>(Data.Models.Metadata.Machine.DipSwitchKey);
|
||||
if (dipSwitches != null && dipSwitches.Length > 0)
|
||||
if (dipSwitches is not null && dipSwitches.Length > 0)
|
||||
gameBase.DipSwitch = Array.ConvertAll(dipSwitches, ConvertFromInternalModel);
|
||||
|
||||
var driver = item.Read<Data.Models.Metadata.Driver>(Data.Models.Metadata.Machine.DriverKey);
|
||||
if (driver != null)
|
||||
if (driver is not null)
|
||||
gameBase.Driver = ConvertFromInternalModel(driver);
|
||||
|
||||
return gameBase;
|
||||
@@ -274,7 +280,9 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
Name = item.ReadString(Data.Models.Metadata.Rom.NameKey),
|
||||
Size = item.ReadString(Data.Models.Metadata.Rom.SizeKey),
|
||||
CRC16 = item.ReadString(Data.Models.Metadata.Rom.CRC16Key),
|
||||
CRC = item.ReadString(Data.Models.Metadata.Rom.CRCKey),
|
||||
CRC64 = item.ReadString(Data.Models.Metadata.Rom.CRC64Key),
|
||||
MD2 = item.ReadString(Data.Models.Metadata.Rom.MD2Key),
|
||||
MD4 = item.ReadString(Data.Models.Metadata.Rom.MD4Key),
|
||||
MD5 = item.ReadString(Data.Models.Metadata.Rom.MD5Key),
|
||||
@@ -342,5 +350,19 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
return video;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert from <see cref="Models.Metadata.InfoSource"/> to <see cref="Models.ClrMamePro.Info"/>
|
||||
/// </summary>
|
||||
private static Info ConvertInfoSourceFromInternalModel(Data.Models.Metadata.InfoSource item)
|
||||
{
|
||||
var info = new Info();
|
||||
|
||||
var sources = item.Read<string[]>(Data.Models.Metadata.InfoSource.SourceKey);
|
||||
if (sources is not null && sources.Length > 0)
|
||||
info.Source = [.. sources];
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,20 +8,23 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile();
|
||||
|
||||
if (obj?.ClrMamePro != null)
|
||||
if (obj?.ClrMamePro is not null)
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(obj.ClrMamePro);
|
||||
|
||||
if (obj?.Game != null && obj.Game.Length > 0)
|
||||
if (obj?.Game is not null && obj.Game.Length > 0)
|
||||
{
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.MachineKey]
|
||||
= Array.ConvertAll(obj.Game, ConvertMachineToInternalModel);
|
||||
}
|
||||
|
||||
if (obj?.Info is not null)
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.InfoSourceKey] = ConvertInfoSourceToInternalModel(obj.Info);
|
||||
|
||||
return metadataFile;
|
||||
}
|
||||
|
||||
@@ -56,13 +59,14 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// </summary>
|
||||
private static Data.Models.Metadata.Machine? ConvertMachineToInternalModel(GameBase? item)
|
||||
{
|
||||
if (item == null)
|
||||
if (item is null)
|
||||
return null;
|
||||
|
||||
var machine = new Data.Models.Metadata.Machine
|
||||
{
|
||||
[Data.Models.Metadata.Machine.NameKey] = item.Name,
|
||||
[Data.Models.Metadata.Machine.DescriptionKey] = item.Description,
|
||||
// [Data.Models.Metadata.Machine.DriverKey] = item.DriverStatus, // TODO: Needs metadata mapping
|
||||
[Data.Models.Metadata.Machine.YearKey] = item.Year,
|
||||
[Data.Models.Metadata.Machine.ManufacturerKey] = item.Manufacturer,
|
||||
[Data.Models.Metadata.Machine.CategoryKey] = item.Category,
|
||||
@@ -71,73 +75,73 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Machine.SampleOfKey] = item.SampleOf,
|
||||
};
|
||||
|
||||
if (item.Release != null && item.Release.Length > 0)
|
||||
if (item.Release is not null && item.Release.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.ReleaseKey]
|
||||
= Array.ConvertAll(item.Release, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.BiosSet != null && item.BiosSet.Length > 0)
|
||||
if (item.BiosSet is not null && item.BiosSet.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.BiosSetKey]
|
||||
= Array.ConvertAll(item.BiosSet, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Rom != null && item.Rom.Length > 0)
|
||||
if (item.Rom is not null && item.Rom.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.RomKey]
|
||||
= Array.ConvertAll(item.Rom, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Disk != null && item.Disk.Length > 0)
|
||||
if (item.Disk is not null && item.Disk.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.DiskKey]
|
||||
= Array.ConvertAll(item.Disk, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Media != null && item.Media.Length > 0)
|
||||
if (item.Media is not null && item.Media.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.MediaKey]
|
||||
= Array.ConvertAll(item.Media, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Sample != null && item.Sample.Length > 0)
|
||||
if (item.Sample is not null && item.Sample.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.SampleKey]
|
||||
= Array.ConvertAll(item.Sample, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Archive != null && item.Archive.Length > 0)
|
||||
if (item.Archive is not null && item.Archive.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.ArchiveKey]
|
||||
= Array.ConvertAll(item.Archive, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Chip != null && item.Chip.Length > 0)
|
||||
if (item.Chip is not null && item.Chip.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.ChipKey]
|
||||
= Array.ConvertAll(item.Chip, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Video != null)
|
||||
if (item.Video is not null)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.VideoKey]
|
||||
= Array.ConvertAll(item.Video, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Sound != null)
|
||||
if (item.Sound is not null)
|
||||
machine[Data.Models.Metadata.Machine.SoundKey] = ConvertToInternalModel(item.Sound);
|
||||
|
||||
if (item.Input != null)
|
||||
if (item.Input is not null)
|
||||
machine[Data.Models.Metadata.Machine.InputKey] = ConvertToInternalModel(item.Input);
|
||||
|
||||
if (item.DipSwitch != null && item.DipSwitch.Length > 0)
|
||||
if (item.DipSwitch is not null && item.DipSwitch.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.DipSwitchKey]
|
||||
= Array.ConvertAll(item.DipSwitch, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Driver != null)
|
||||
if (item.Driver is not null)
|
||||
machine[Data.Models.Metadata.Machine.DriverKey] = ConvertToInternalModel(item.Driver);
|
||||
|
||||
return machine;
|
||||
@@ -289,7 +293,9 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
[Data.Models.Metadata.Rom.NameKey] = item.Name,
|
||||
[Data.Models.Metadata.Rom.SizeKey] = item.Size,
|
||||
[Data.Models.Metadata.Rom.CRC16Key] = item.CRC16,
|
||||
[Data.Models.Metadata.Rom.CRCKey] = item.CRC,
|
||||
[Data.Models.Metadata.Rom.CRC64Key] = item.CRC64,
|
||||
[Data.Models.Metadata.Rom.MD2Key] = item.MD2,
|
||||
[Data.Models.Metadata.Rom.MD4Key] = item.MD4,
|
||||
[Data.Models.Metadata.Rom.MD5Key] = item.MD5,
|
||||
@@ -357,5 +363,22 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
return video;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert from <see cref="Models.ClrMamePro.Info"/> to <see cref="Models.Metadata.InfoSource"/>
|
||||
/// </summary>
|
||||
private static Data.Models.Metadata.InfoSource ConvertInfoSourceToInternalModel(Info item)
|
||||
{
|
||||
var infoSource = new Data.Models.Metadata.InfoSource();
|
||||
|
||||
var sources = item.Source;
|
||||
if (sources is not null && sources.Length > 0)
|
||||
{
|
||||
string[] sourcesCopy = [.. sources];
|
||||
infoSource[Data.Models.Metadata.InfoSource.SourceKey] = sourcesCopy;
|
||||
}
|
||||
|
||||
return infoSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,17 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override MetadataFile? Deserialize(Data.Models.Metadata.MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new MetadataFile();
|
||||
|
||||
var header = obj.Read<Data.Models.Metadata.Header>(Data.Models.Metadata.MetadataFile.HeaderKey);
|
||||
if (header != null)
|
||||
if (header is not null)
|
||||
metadataFile.DosCenter = ConvertHeaderFromInternalModel(header);
|
||||
|
||||
var machines = obj.Read<Data.Models.Metadata.Machine[]>(Data.Models.Metadata.MetadataFile.MachineKey);
|
||||
if (machines != null && machines.Length > 0)
|
||||
if (machines is not null && machines.Length > 0)
|
||||
metadataFile.Game = Array.ConvertAll(machines, ConvertMachineFromInternalModel);
|
||||
|
||||
return metadataFile;
|
||||
@@ -53,7 +53,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var roms = item.Read<Data.Models.Metadata.Rom[]>(Data.Models.Metadata.Machine.RomKey);
|
||||
if (roms != null && roms.Length > 0)
|
||||
if (roms is not null && roms.Length > 0)
|
||||
game.File = Array.ConvertAll(roms, ConvertFromInternalModel);
|
||||
|
||||
return game;
|
||||
|
||||
@@ -8,15 +8,15 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile();
|
||||
|
||||
if (obj?.DosCenter != null)
|
||||
if (obj?.DosCenter is not null)
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(obj.DosCenter);
|
||||
|
||||
if (obj?.Game != null && obj.Game.Length > 0)
|
||||
if (obj?.Game is not null && obj.Game.Length > 0)
|
||||
{
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.MachineKey]
|
||||
= Array.ConvertAll(obj.Game, ConvertMachineToInternalModel);
|
||||
@@ -53,7 +53,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Machine.NameKey] = item.Name,
|
||||
};
|
||||
|
||||
if (item.File != null && item.File.Length > 0)
|
||||
if (item.File is not null && item.File.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.RomKey]
|
||||
= Array.ConvertAll(item.File, ConvertToInternalModel);
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override MetadataFile? Deserialize(Data.Models.Metadata.MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new MetadataFile();
|
||||
@@ -32,7 +32,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
private static Row[] ConvertMachineFromInternalModel(Data.Models.Metadata.Machine item)
|
||||
{
|
||||
var roms = item.Read<Data.Models.Metadata.Rom[]>(Data.Models.Metadata.Machine.RomKey);
|
||||
if (roms == null || roms.Length == 0)
|
||||
if (roms is null || roms.Length == 0)
|
||||
return [];
|
||||
|
||||
return Array.ConvertAll(roms, ConvertFromInternalModel);
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile
|
||||
@@ -16,7 +16,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(),
|
||||
};
|
||||
|
||||
if (obj?.Row != null && obj.Row.Length > 0)
|
||||
if (obj?.Row is not null && obj.Row.Length > 0)
|
||||
{
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.MachineKey]
|
||||
= Array.ConvertAll(obj.Row, ConvertMachineToInternalModel);
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using SabreTools.Data.Models.Hashfile;
|
||||
using SabreTools.Hashing;
|
||||
|
||||
#pragma warning disable CA1822 // Mark members as static
|
||||
namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
public partial class Hashfile : BaseMetadataSerializer<Data.Models.Hashfile.Hashfile>
|
||||
@@ -14,11 +15,11 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public Data.Models.Hashfile.Hashfile? Deserialize(Data.Models.Metadata.MetadataFile? obj, HashType hash)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var machines = obj.Read<Data.Models.Metadata.Machine[]>(Data.Models.Metadata.MetadataFile.MachineKey);
|
||||
if (machines == null || machines.Length == 0)
|
||||
if (machines is null || machines.Length == 0)
|
||||
return null;
|
||||
|
||||
var hashfiles = Array.ConvertAll(machines,
|
||||
@@ -38,27 +39,27 @@ namespace SabreTools.Serialization.CrossModel
|
||||
|
||||
foreach (var hashfile in hashfiles)
|
||||
{
|
||||
if (hashfile.SFV != null && hashfile.SFV.Length > 0)
|
||||
if (hashfile.SFV is not null && hashfile.SFV.Length > 0)
|
||||
sfvs.AddRange(hashfile.SFV);
|
||||
if (hashfile.MD2 != null && hashfile.MD2.Length > 0)
|
||||
if (hashfile.MD2 is not null && hashfile.MD2.Length > 0)
|
||||
md2s.AddRange(hashfile.MD2);
|
||||
if (hashfile.MD4 != null && hashfile.MD4.Length > 0)
|
||||
if (hashfile.MD4 is not null && hashfile.MD4.Length > 0)
|
||||
md4s.AddRange(hashfile.MD4);
|
||||
if (hashfile.MD5 != null && hashfile.MD5.Length > 0)
|
||||
if (hashfile.MD5 is not null && hashfile.MD5.Length > 0)
|
||||
md5s.AddRange(hashfile.MD5);
|
||||
if (hashfile.RIPEMD128 != null && hashfile.RIPEMD128.Length > 0)
|
||||
if (hashfile.RIPEMD128 is not null && hashfile.RIPEMD128.Length > 0)
|
||||
ripemd128s.AddRange(hashfile.RIPEMD128);
|
||||
if (hashfile.RIPEMD160 != null && hashfile.RIPEMD160.Length > 0)
|
||||
if (hashfile.RIPEMD160 is not null && hashfile.RIPEMD160.Length > 0)
|
||||
ripemd160s.AddRange(hashfile.RIPEMD160);
|
||||
if (hashfile.SHA1 != null && hashfile.SHA1.Length > 0)
|
||||
if (hashfile.SHA1 is not null && hashfile.SHA1.Length > 0)
|
||||
sha1s.AddRange(hashfile.SHA1);
|
||||
if (hashfile.SHA256 != null && hashfile.SHA256.Length > 0)
|
||||
if (hashfile.SHA256 is not null && hashfile.SHA256.Length > 0)
|
||||
sha256s.AddRange(hashfile.SHA256);
|
||||
if (hashfile.SHA384 != null && hashfile.SHA384.Length > 0)
|
||||
if (hashfile.SHA384 is not null && hashfile.SHA384.Length > 0)
|
||||
sha384s.AddRange(hashfile.SHA384);
|
||||
if (hashfile.SHA512 != null && hashfile.SHA512.Length > 0)
|
||||
if (hashfile.SHA512 is not null && hashfile.SHA512.Length > 0)
|
||||
sha512s.AddRange(hashfile.SHA512);
|
||||
if (hashfile.SpamSum != null && hashfile.SpamSum.Length > 0)
|
||||
if (hashfile.SpamSum is not null && hashfile.SpamSum.Length > 0)
|
||||
spamsums.AddRange(hashfile.SpamSum);
|
||||
}
|
||||
|
||||
@@ -96,7 +97,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
private static Data.Models.Hashfile.Hashfile ConvertMachineFromInternalModel(Data.Models.Metadata.Machine item, HashType hash)
|
||||
{
|
||||
var roms = item.Read<Data.Models.Metadata.Rom[]>(Data.Models.Metadata.Machine.RomKey);
|
||||
if (roms == null)
|
||||
if (roms is null)
|
||||
return new Data.Models.Hashfile.Hashfile();
|
||||
|
||||
return new Data.Models.Hashfile.Hashfile
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(Data.Models.Hashfile.Hashfile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile
|
||||
@@ -41,27 +41,27 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
var machine = new Data.Models.Metadata.Machine();
|
||||
|
||||
if (item.SFV != null && item.SFV.Length > 0)
|
||||
if (item.SFV is not null && item.SFV.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.RomKey] = Array.ConvertAll(item.SFV, ConvertToInternalModel);
|
||||
else if (item.MD2 != null && item.MD2.Length > 0)
|
||||
else if (item.MD2 is not null && item.MD2.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.RomKey] = Array.ConvertAll(item.MD2, ConvertToInternalModel);
|
||||
else if (item.MD4 != null && item.MD4.Length > 0)
|
||||
else if (item.MD4 is not null && item.MD4.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.RomKey] = Array.ConvertAll(item.MD4, ConvertToInternalModel);
|
||||
else if (item.MD5 != null && item.MD5.Length > 0)
|
||||
else if (item.MD5 is not null && item.MD5.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.RomKey] = Array.ConvertAll(item.MD5, ConvertToInternalModel);
|
||||
else if (item.RIPEMD128 != null && item.RIPEMD128.Length > 0)
|
||||
else if (item.RIPEMD128 is not null && item.RIPEMD128.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.RomKey] = Array.ConvertAll(item.RIPEMD128, ConvertToInternalModel);
|
||||
else if (item.RIPEMD160 != null && item.RIPEMD160.Length > 0)
|
||||
else if (item.RIPEMD160 is not null && item.RIPEMD160.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.RomKey] = Array.ConvertAll(item.RIPEMD160, ConvertToInternalModel);
|
||||
else if (item.SHA1 != null && item.SHA1.Length > 0)
|
||||
else if (item.SHA1 is not null && item.SHA1.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.RomKey] = Array.ConvertAll(item.SHA1, ConvertToInternalModel);
|
||||
else if (item.SHA256 != null && item.SHA256.Length > 0)
|
||||
else if (item.SHA256 is not null && item.SHA256.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.RomKey] = Array.ConvertAll(item.SHA256, ConvertToInternalModel);
|
||||
else if (item.SHA384 != null && item.SHA384.Length > 0)
|
||||
else if (item.SHA384 is not null && item.SHA384.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.RomKey] = Array.ConvertAll(item.SHA384, ConvertToInternalModel);
|
||||
else if (item.SHA512 != null && item.SHA512.Length > 0)
|
||||
else if (item.SHA512 is not null && item.SHA512.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.RomKey] = Array.ConvertAll(item.SHA512, ConvertToInternalModel);
|
||||
else if (item.SpamSum != null && item.SpamSum.Length > 0)
|
||||
else if (item.SpamSum is not null && item.SpamSum.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.RomKey] = Array.ConvertAll(item.SpamSum, ConvertToInternalModel);
|
||||
|
||||
return machine;
|
||||
|
||||
@@ -9,13 +9,13 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override MetadataFile? Deserialize(Data.Models.Metadata.MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new MetadataFile();
|
||||
|
||||
var machines = obj.Read<Data.Models.Metadata.Machine[]>(Data.Models.Metadata.MetadataFile.MachineKey);
|
||||
if (machines != null && machines.Length > 0)
|
||||
if (machines is not null && machines.Length > 0)
|
||||
metadataFile.Set = Array.ConvertAll(machines, ConvertMachineFromInternalModel);
|
||||
|
||||
return metadataFile;
|
||||
@@ -35,13 +35,13 @@ namespace SabreTools.Serialization.CrossModel
|
||||
var rowItems = new List<Row>();
|
||||
|
||||
var roms = item.Read<Data.Models.Metadata.Rom[]>(Data.Models.Metadata.Machine.RomKey);
|
||||
if (roms != null)
|
||||
if (roms is not null)
|
||||
{
|
||||
rowItems.AddRange(Array.ConvertAll(roms, ConvertFromInternalModel));
|
||||
}
|
||||
|
||||
var disks = item.Read<Data.Models.Metadata.Disk[]>(Data.Models.Metadata.Machine.DiskKey);
|
||||
if (disks != null)
|
||||
if (disks is not null)
|
||||
rowItems.AddRange(Array.ConvertAll(disks, ConvertFromInternalModel));
|
||||
|
||||
set.Row = [.. rowItems];
|
||||
@@ -60,9 +60,9 @@ namespace SabreTools.Serialization.CrossModel
|
||||
SHA1 = item.ReadString(Data.Models.Metadata.Disk.SHA1Key),
|
||||
};
|
||||
|
||||
if (item[Data.Models.Metadata.Disk.StatusKey] as string == "nodump")
|
||||
if ((item[Data.Models.Metadata.Disk.StatusKey] as string) == "nodump")
|
||||
row.NoGoodDumpKnown = true;
|
||||
else if (item[Data.Models.Metadata.Disk.StatusKey] as string == "baddump")
|
||||
else if ((item[Data.Models.Metadata.Disk.StatusKey] as string) == "baddump")
|
||||
row.Bad = true;
|
||||
|
||||
return row;
|
||||
@@ -81,9 +81,9 @@ namespace SabreTools.Serialization.CrossModel
|
||||
SHA1 = item.ReadString(Data.Models.Metadata.Rom.SHA1Key),
|
||||
};
|
||||
|
||||
if (item[Data.Models.Metadata.Rom.StatusKey] as string == "nodump")
|
||||
if ((item[Data.Models.Metadata.Rom.StatusKey] as string) == "nodump")
|
||||
row.NoGoodDumpKnown = true;
|
||||
else if (item[Data.Models.Metadata.Rom.StatusKey] as string == "baddump")
|
||||
else if ((item[Data.Models.Metadata.Rom.StatusKey] as string) == "baddump")
|
||||
row.Bad = true;
|
||||
|
||||
return row;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile
|
||||
@@ -17,7 +17,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(),
|
||||
};
|
||||
|
||||
if (obj?.Set != null && obj.Set.Length > 0)
|
||||
if (obj?.Set is not null && obj.Set.Length > 0)
|
||||
{
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.MachineKey]
|
||||
= Array.ConvertAll(obj.Set, ConvertMachineToInternalModel);
|
||||
@@ -54,7 +54,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
machine[Data.Models.Metadata.Machine.NameKey] = item.Driver;
|
||||
}
|
||||
|
||||
if (item.Row != null && item.Row.Length > 0)
|
||||
if (item.Row is not null && item.Row.Length > 0)
|
||||
{
|
||||
var disks = new List<Data.Models.Metadata.Disk>();
|
||||
var roms = new List<Data.Models.Metadata.Rom>();
|
||||
@@ -79,7 +79,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// </summary>
|
||||
private static Data.Models.Metadata.DatItem ConvertToInternalModel(Row item)
|
||||
{
|
||||
if (item.Size == null)
|
||||
if (item.Size is null)
|
||||
{
|
||||
var disk = new Data.Models.Metadata.Disk
|
||||
{
|
||||
|
||||
@@ -8,14 +8,14 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Mame? Deserialize(Data.Models.Metadata.MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var header = obj.Read<Data.Models.Metadata.Header>(Data.Models.Metadata.MetadataFile.HeaderKey);
|
||||
var mame = header != null ? ConvertMameFromInternalModel(header) : new Mame();
|
||||
var mame = header is not null ? ConvertMameFromInternalModel(header) : new Mame();
|
||||
|
||||
var machines = obj.Read<Data.Models.Metadata.Machine[]>(Data.Models.Metadata.MetadataFile.MachineKey);
|
||||
if (machines != null && machines.Length > 0)
|
||||
if (machines is not null && machines.Length > 0)
|
||||
mame.Game = Array.ConvertAll(machines, ConvertMachineFromInternalModel);
|
||||
|
||||
return mame;
|
||||
@@ -59,83 +59,83 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var biosSets = item.Read<Data.Models.Metadata.BiosSet[]>(Data.Models.Metadata.Machine.BiosSetKey);
|
||||
if (biosSets != null && biosSets.Length > 0)
|
||||
if (biosSets is not null && biosSets.Length > 0)
|
||||
machine.BiosSet = Array.ConvertAll(biosSets, ConvertFromInternalModel);
|
||||
|
||||
var roms = item.Read<Data.Models.Metadata.Rom[]>(Data.Models.Metadata.Machine.RomKey);
|
||||
if (roms != null && roms.Length > 0)
|
||||
if (roms is not null && roms.Length > 0)
|
||||
machine.Rom = Array.ConvertAll(roms, ConvertFromInternalModel);
|
||||
|
||||
var disks = item.Read<Data.Models.Metadata.Disk[]>(Data.Models.Metadata.Machine.DiskKey);
|
||||
if (disks != null && disks.Length > 0)
|
||||
if (disks is not null && disks.Length > 0)
|
||||
machine.Disk = Array.ConvertAll(disks, ConvertFromInternalModel);
|
||||
|
||||
var deviceRefs = item.Read<Data.Models.Metadata.DeviceRef[]>(Data.Models.Metadata.Machine.DeviceRefKey);
|
||||
if (deviceRefs != null && deviceRefs.Length > 0)
|
||||
if (deviceRefs is not null && deviceRefs.Length > 0)
|
||||
machine.DeviceRef = Array.ConvertAll(deviceRefs, ConvertFromInternalModel);
|
||||
|
||||
var samples = item.Read<Data.Models.Metadata.Sample[]>(Data.Models.Metadata.Machine.SampleKey);
|
||||
if (samples != null && samples.Length > 0)
|
||||
if (samples is not null && samples.Length > 0)
|
||||
machine.Sample = Array.ConvertAll(samples, ConvertFromInternalModel);
|
||||
|
||||
var chips = item.Read<Data.Models.Metadata.Chip[]>(Data.Models.Metadata.Machine.ChipKey);
|
||||
if (chips != null && chips.Length > 0)
|
||||
if (chips is not null && chips.Length > 0)
|
||||
machine.Chip = Array.ConvertAll(chips, ConvertFromInternalModel);
|
||||
|
||||
var displays = item.Read<Data.Models.Metadata.Display[]>(Data.Models.Metadata.Machine.DisplayKey);
|
||||
if (displays != null && displays.Length > 0)
|
||||
if (displays is not null && displays.Length > 0)
|
||||
machine.Display = Array.ConvertAll(displays, ConvertFromInternalModel);
|
||||
|
||||
var videos = item.Read<Data.Models.Metadata.Video[]>(Data.Models.Metadata.Machine.VideoKey);
|
||||
if (videos != null && videos.Length > 0)
|
||||
if (videos is not null && videos.Length > 0)
|
||||
machine.Video = Array.ConvertAll(videos, ConvertFromInternalModel);
|
||||
|
||||
var sound = item.Read<Data.Models.Metadata.Sound>(Data.Models.Metadata.Machine.SoundKey);
|
||||
if (sound != null)
|
||||
if (sound is not null)
|
||||
machine.Sound = ConvertFromInternalModel(sound);
|
||||
|
||||
var input = item.Read<Data.Models.Metadata.Input>(Data.Models.Metadata.Machine.InputKey);
|
||||
if (input != null)
|
||||
if (input is not null)
|
||||
machine.Input = ConvertFromInternalModel(input);
|
||||
|
||||
var dipSwitches = item.Read<Data.Models.Metadata.DipSwitch[]>(Data.Models.Metadata.Machine.DipSwitchKey);
|
||||
if (dipSwitches != null && dipSwitches.Length > 0)
|
||||
if (dipSwitches is not null && dipSwitches.Length > 0)
|
||||
machine.DipSwitch = Array.ConvertAll(dipSwitches, ConvertFromInternalModel);
|
||||
|
||||
var configurations = item.Read<Data.Models.Metadata.Configuration[]>(Data.Models.Metadata.Machine.ConfigurationKey);
|
||||
if (configurations != null && configurations.Length > 0)
|
||||
if (configurations is not null && configurations.Length > 0)
|
||||
machine.Configuration = Array.ConvertAll(configurations, ConvertFromInternalModel);
|
||||
|
||||
var ports = item.Read<Data.Models.Metadata.Port[]>(Data.Models.Metadata.Machine.PortKey);
|
||||
if (ports != null && ports.Length > 0)
|
||||
if (ports is not null && ports.Length > 0)
|
||||
machine.Port = Array.ConvertAll(ports, ConvertFromInternalModel);
|
||||
|
||||
var adjusters = item.Read<Data.Models.Metadata.Adjuster[]>(Data.Models.Metadata.Machine.AdjusterKey);
|
||||
if (adjusters != null && adjusters.Length > 0)
|
||||
if (adjusters is not null && adjusters.Length > 0)
|
||||
machine.Adjuster = Array.ConvertAll(adjusters, ConvertFromInternalModel);
|
||||
|
||||
var driver = item.Read<Data.Models.Metadata.Driver>(Data.Models.Metadata.Machine.DriverKey);
|
||||
if (driver != null)
|
||||
if (driver is not null)
|
||||
machine.Driver = ConvertFromInternalModel(driver);
|
||||
|
||||
var features = item.Read<Data.Models.Metadata.Feature[]>(Data.Models.Metadata.Machine.FeatureKey);
|
||||
if (features != null && features.Length > 0)
|
||||
if (features is not null && features.Length > 0)
|
||||
machine.Feature = Array.ConvertAll(features, ConvertFromInternalModel);
|
||||
|
||||
var devices = item.Read<Data.Models.Metadata.Device[]>(Data.Models.Metadata.Machine.DeviceKey);
|
||||
if (devices != null && devices.Length > 0)
|
||||
if (devices is not null && devices.Length > 0)
|
||||
machine.Device = Array.ConvertAll(devices, ConvertFromInternalModel);
|
||||
|
||||
var slots = item.Read<Data.Models.Metadata.Slot[]>(Data.Models.Metadata.Machine.SlotKey);
|
||||
if (slots != null && slots.Length > 0)
|
||||
if (slots is not null && slots.Length > 0)
|
||||
machine.Slot = Array.ConvertAll(slots, ConvertFromInternalModel);
|
||||
|
||||
var softwareLists = item.Read<Data.Models.Metadata.SoftwareList[]>(Data.Models.Metadata.Machine.SoftwareListKey);
|
||||
if (softwareLists != null && softwareLists.Length > 0)
|
||||
if (softwareLists is not null && softwareLists.Length > 0)
|
||||
machine.SoftwareList = Array.ConvertAll(softwareLists, ConvertFromInternalModel);
|
||||
|
||||
var ramOptions = item.Read<Data.Models.Metadata.RamOption[]>(Data.Models.Metadata.Machine.RamOptionKey);
|
||||
if (ramOptions != null && ramOptions.Length > 0)
|
||||
if (ramOptions is not null && ramOptions.Length > 0)
|
||||
machine.RamOption = Array.ConvertAll(ramOptions, ConvertFromInternalModel);
|
||||
|
||||
return machine;
|
||||
@@ -153,7 +153,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var condition = item.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.Adjuster.ConditionKey);
|
||||
if (condition != null)
|
||||
if (condition is not null)
|
||||
adjuster.Condition = ConvertFromInternalModel(condition);
|
||||
|
||||
return adjuster;
|
||||
@@ -229,15 +229,15 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var condition = item.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.Configuration.ConditionKey);
|
||||
if (condition != null)
|
||||
if (condition is not null)
|
||||
configuration.Condition = ConvertFromInternalModel(condition);
|
||||
|
||||
var confLocations = item.Read<Data.Models.Metadata.ConfLocation[]>(Data.Models.Metadata.Configuration.ConfLocationKey);
|
||||
if (confLocations != null && confLocations.Length > 0)
|
||||
if (confLocations is not null && confLocations.Length > 0)
|
||||
configuration.ConfLocation = Array.ConvertAll(confLocations, ConvertFromInternalModel);
|
||||
|
||||
var confSettings = item.Read<Data.Models.Metadata.ConfSetting[]>(Data.Models.Metadata.Configuration.ConfSettingKey);
|
||||
if (confSettings != null && confSettings.Length > 0)
|
||||
if (confSettings is not null && confSettings.Length > 0)
|
||||
configuration.ConfSetting = Array.ConvertAll(confSettings, ConvertFromInternalModel);
|
||||
|
||||
return configuration;
|
||||
@@ -270,7 +270,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var condition = item.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.ConfSetting.ConditionKey);
|
||||
if (condition != null)
|
||||
if (condition is not null)
|
||||
confSetting.Condition = ConvertFromInternalModel(condition);
|
||||
|
||||
return confSetting;
|
||||
@@ -314,11 +314,11 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var instance = item.Read<Data.Models.Metadata.Instance>(Data.Models.Metadata.Device.InstanceKey);
|
||||
if (instance != null)
|
||||
if (instance is not null)
|
||||
device.Instance = ConvertFromInternalModel(instance);
|
||||
|
||||
var extensions = item.Read<Data.Models.Metadata.Extension[]>(Data.Models.Metadata.Device.ExtensionKey);
|
||||
if (extensions != null && extensions.Length > 0)
|
||||
if (extensions is not null && extensions.Length > 0)
|
||||
device.Extension = Array.ConvertAll(extensions, ConvertFromInternalModel);
|
||||
|
||||
return device;
|
||||
@@ -363,15 +363,15 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var condition = item.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.DipSwitch.ConditionKey);
|
||||
if (condition != null)
|
||||
if (condition is not null)
|
||||
dipSwitch.Condition = ConvertFromInternalModel(condition);
|
||||
|
||||
var dipLocations = item.Read<Data.Models.Metadata.DipLocation[]>(Data.Models.Metadata.DipSwitch.DipLocationKey);
|
||||
if (dipLocations != null && dipLocations.Length > 0)
|
||||
if (dipLocations is not null && dipLocations.Length > 0)
|
||||
dipSwitch.DipLocation = Array.ConvertAll(dipLocations, ConvertFromInternalModel);
|
||||
|
||||
var dipValues = item.Read<Data.Models.Metadata.DipValue[]>(Data.Models.Metadata.DipSwitch.DipValueKey);
|
||||
if (dipValues != null && dipValues.Length > 0)
|
||||
if (dipValues is not null && dipValues.Length > 0)
|
||||
dipSwitch.DipValue = Array.ConvertAll(dipValues, ConvertFromInternalModel);
|
||||
|
||||
return dipSwitch;
|
||||
@@ -390,7 +390,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var condition = item.Read<Data.Models.Metadata.Condition>(Data.Models.Metadata.DipValue.ConditionKey);
|
||||
if (condition != null)
|
||||
if (condition is not null)
|
||||
dipValue.Condition = ConvertFromInternalModel(condition);
|
||||
|
||||
return dipValue;
|
||||
@@ -504,11 +504,11 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var controlAttr = item.ReadString(Data.Models.Metadata.Input.ControlKey);
|
||||
if (controlAttr != null)
|
||||
if (controlAttr is not null)
|
||||
input.ControlAttr = controlAttr;
|
||||
|
||||
var controls = item.Read<Data.Models.Metadata.Control[]>(Data.Models.Metadata.Input.ControlKey);
|
||||
if (controls != null && controls.Length > 0)
|
||||
if (controls is not null && controls.Length > 0)
|
||||
input.Control = Array.ConvertAll(controls, ConvertFromInternalModel);
|
||||
|
||||
return input;
|
||||
@@ -538,7 +538,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var analogs = item.Read<Data.Models.Metadata.Analog[]>(Data.Models.Metadata.Port.AnalogKey);
|
||||
if (analogs != null && analogs.Length > 0)
|
||||
if (analogs is not null && analogs.Length > 0)
|
||||
port.Analog = Array.ConvertAll(analogs, ConvertFromInternalModel);
|
||||
|
||||
return port;
|
||||
@@ -604,7 +604,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var slotOptions = item.Read<Data.Models.Metadata.SlotOption[]>(Data.Models.Metadata.Slot.SlotOptionKey);
|
||||
if (slotOptions != null && slotOptions.Length > 0)
|
||||
if (slotOptions is not null && slotOptions.Length > 0)
|
||||
slot.SlotOption = Array.ConvertAll(slotOptions, ConvertFromInternalModel);
|
||||
|
||||
return slot;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(Mame? item)
|
||||
{
|
||||
if (item == null)
|
||||
if (item is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile
|
||||
@@ -16,7 +16,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(item),
|
||||
};
|
||||
|
||||
if (item?.Game != null && item.Game.Length > 0)
|
||||
if (item?.Game is not null && item.Game.Length > 0)
|
||||
{
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.MachineKey]
|
||||
= Array.ConvertAll(item.Game, ConvertMachineToInternalModel);
|
||||
@@ -61,112 +61,112 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Machine.HistoryKey] = item.History,
|
||||
};
|
||||
|
||||
if (item.BiosSet != null && item.BiosSet.Length > 0)
|
||||
if (item.BiosSet is not null && item.BiosSet.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.BiosSetKey]
|
||||
= Array.ConvertAll(item.BiosSet, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Rom != null && item.Rom.Length > 0)
|
||||
if (item.Rom is not null && item.Rom.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.RomKey]
|
||||
= Array.ConvertAll(item.Rom, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Disk != null && item.Disk.Length > 0)
|
||||
if (item.Disk is not null && item.Disk.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.DiskKey]
|
||||
= Array.ConvertAll(item.Disk, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.DeviceRef != null && item.DeviceRef.Length > 0)
|
||||
if (item.DeviceRef is not null && item.DeviceRef.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.DeviceRefKey]
|
||||
= Array.ConvertAll(item.DeviceRef, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Sample != null && item.Sample.Length > 0)
|
||||
if (item.Sample is not null && item.Sample.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.SampleKey]
|
||||
= Array.ConvertAll(item.Sample, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Chip != null && item.Chip.Length > 0)
|
||||
if (item.Chip is not null && item.Chip.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.ChipKey]
|
||||
= Array.ConvertAll(item.Chip, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Display != null && item.Display.Length > 0)
|
||||
if (item.Display is not null && item.Display.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.DisplayKey]
|
||||
= Array.ConvertAll(item.Display, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Video != null && item.Video.Length > 0)
|
||||
if (item.Video is not null && item.Video.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.VideoKey]
|
||||
= Array.ConvertAll(item.Video, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Sound != null)
|
||||
if (item.Sound is not null)
|
||||
machine[Data.Models.Metadata.Machine.SoundKey] = ConvertToInternalModel(item.Sound);
|
||||
|
||||
if (item.Input != null)
|
||||
if (item.Input is not null)
|
||||
machine[Data.Models.Metadata.Machine.InputKey] = ConvertToInternalModel(item.Input);
|
||||
|
||||
if (item.DipSwitch != null && item.DipSwitch.Length > 0)
|
||||
if (item.DipSwitch is not null && item.DipSwitch.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.DipSwitchKey]
|
||||
= Array.ConvertAll(item.DipSwitch, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Configuration != null && item.Configuration.Length > 0)
|
||||
if (item.Configuration is not null && item.Configuration.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.ConfigurationKey]
|
||||
= Array.ConvertAll(item.Configuration, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Port != null && item.Port.Length > 0)
|
||||
if (item.Port is not null && item.Port.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.PortKey]
|
||||
= Array.ConvertAll(item.Port, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Adjuster != null && item.Adjuster.Length > 0)
|
||||
if (item.Adjuster is not null && item.Adjuster.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.AdjusterKey]
|
||||
= Array.ConvertAll(item.Adjuster, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Driver != null)
|
||||
if (item.Driver is not null)
|
||||
machine[Data.Models.Metadata.Machine.DriverKey] = ConvertToInternalModel(item.Driver);
|
||||
|
||||
if (item.Feature != null && item.Feature.Length > 0)
|
||||
if (item.Feature is not null && item.Feature.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.FeatureKey]
|
||||
= Array.ConvertAll(item.Feature, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Device != null && item.Device.Length > 0)
|
||||
if (item.Device is not null && item.Device.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.DeviceKey]
|
||||
= Array.ConvertAll(item.Device, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.Slot != null && item.Slot.Length > 0)
|
||||
if (item.Slot is not null && item.Slot.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.SlotKey]
|
||||
= Array.ConvertAll(item.Slot, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.SoftwareList != null && item.SoftwareList.Length > 0)
|
||||
if (item.SoftwareList is not null && item.SoftwareList.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.SoftwareListKey]
|
||||
= Array.ConvertAll(item.SoftwareList, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.RamOption != null && item.RamOption.Length > 0)
|
||||
if (item.RamOption is not null && item.RamOption.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.RamOptionKey]
|
||||
= Array.ConvertAll(item.RamOption, ConvertToInternalModel);
|
||||
@@ -186,7 +186,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Adjuster.DefaultKey] = item.Default,
|
||||
};
|
||||
|
||||
if (item.Condition != null)
|
||||
if (item.Condition is not null)
|
||||
adjuster[Data.Models.Metadata.Adjuster.ConditionKey] = ConvertToInternalModel(item.Condition);
|
||||
|
||||
return adjuster;
|
||||
@@ -261,16 +261,16 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Configuration.MaskKey] = item.Mask,
|
||||
};
|
||||
|
||||
if (item.Condition != null)
|
||||
if (item.Condition is not null)
|
||||
configuration[Data.Models.Metadata.Configuration.ConditionKey] = ConvertToInternalModel(item.Condition);
|
||||
|
||||
if (item.ConfLocation != null && item.ConfLocation.Length > 0)
|
||||
if (item.ConfLocation is not null && item.ConfLocation.Length > 0)
|
||||
{
|
||||
configuration[Data.Models.Metadata.Configuration.ConfLocationKey]
|
||||
= Array.ConvertAll(item.ConfLocation, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.ConfSetting != null && item.ConfSetting.Length > 0)
|
||||
if (item.ConfSetting is not null && item.ConfSetting.Length > 0)
|
||||
{
|
||||
configuration[Data.Models.Metadata.Configuration.ConfSettingKey]
|
||||
= Array.ConvertAll(item.ConfSetting, ConvertToInternalModel);
|
||||
@@ -305,7 +305,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.ConfSetting.DefaultKey] = item.Default,
|
||||
};
|
||||
|
||||
if (item.Condition != null)
|
||||
if (item.Condition is not null)
|
||||
confSetting[Data.Models.Metadata.ConfSetting.ConditionKey] = ConvertToInternalModel(item.Condition);
|
||||
|
||||
return confSetting;
|
||||
@@ -348,10 +348,10 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Device.InterfaceKey] = item.Interface,
|
||||
};
|
||||
|
||||
if (item.Instance != null)
|
||||
if (item.Instance is not null)
|
||||
device[Data.Models.Metadata.Device.InstanceKey] = ConvertToInternalModel(item.Instance);
|
||||
|
||||
if (item.Extension != null && item.Extension.Length > 0)
|
||||
if (item.Extension is not null && item.Extension.Length > 0)
|
||||
{
|
||||
device[Data.Models.Metadata.Device.ExtensionKey]
|
||||
= Array.ConvertAll(item.Extension, ConvertToInternalModel);
|
||||
@@ -398,16 +398,16 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.DipSwitch.MaskKey] = item.Mask,
|
||||
};
|
||||
|
||||
if (item.Condition != null)
|
||||
if (item.Condition is not null)
|
||||
dipSwitch[Data.Models.Metadata.DipSwitch.ConditionKey] = ConvertToInternalModel(item.Condition);
|
||||
|
||||
if (item.DipLocation != null && item.DipLocation.Length > 0)
|
||||
if (item.DipLocation is not null && item.DipLocation.Length > 0)
|
||||
{
|
||||
dipSwitch[Data.Models.Metadata.DipSwitch.DipLocationKey]
|
||||
= Array.ConvertAll(item.DipLocation, ConvertToInternalModel);
|
||||
}
|
||||
|
||||
if (item.DipValue != null && item.DipValue.Length > 0)
|
||||
if (item.DipValue is not null && item.DipValue.Length > 0)
|
||||
{
|
||||
dipSwitch[Data.Models.Metadata.DipSwitch.DipValueKey]
|
||||
= Array.ConvertAll(item.DipValue, ConvertToInternalModel);
|
||||
@@ -428,7 +428,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.DipValue.DefaultKey] = item.Default,
|
||||
};
|
||||
|
||||
if (item.Condition != null)
|
||||
if (item.Condition is not null)
|
||||
dipValue[Data.Models.Metadata.DipValue.ConditionKey] = ConvertToInternalModel(item.Condition);
|
||||
|
||||
return dipValue;
|
||||
@@ -542,7 +542,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Input.CoinsKey] = item.Coins,
|
||||
};
|
||||
|
||||
if (item.Control != null && item.Control.Length > 0)
|
||||
if (item.Control is not null && item.Control.Length > 0)
|
||||
{
|
||||
input[Data.Models.Metadata.Input.ControlKey]
|
||||
= Array.ConvertAll(item.Control, ConvertToInternalModel);
|
||||
@@ -574,7 +574,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Port.TagKey] = item.Tag,
|
||||
};
|
||||
|
||||
if (item.Analog != null && item.Analog.Length > 0)
|
||||
if (item.Analog is not null && item.Analog.Length > 0)
|
||||
{
|
||||
port[Data.Models.Metadata.Port.AnalogKey]
|
||||
= Array.ConvertAll(item.Analog, ConvertToInternalModel);
|
||||
@@ -642,7 +642,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Slot.NameKey] = item.Name,
|
||||
};
|
||||
|
||||
if (item.SlotOption != null && item.SlotOption.Length > 0)
|
||||
if (item.SlotOption is not null && item.SlotOption.Length > 0)
|
||||
{
|
||||
slot[Data.Models.Metadata.Slot.SlotOptionKey]
|
||||
= Array.ConvertAll(item.SlotOption, ConvertToInternalModel);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using SabreTools.Data.Models.Logiqx;
|
||||
|
||||
#pragma warning disable CA1822 // Mark members as static
|
||||
namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
public partial class Logiqx : BaseMetadataSerializer<Datafile>
|
||||
@@ -12,13 +13,13 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public Datafile? Deserialize(Data.Models.Metadata.MetadataFile? obj, bool game)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var datafile = new Datafile();
|
||||
|
||||
var header = obj.Read<Data.Models.Metadata.Header>(Data.Models.Metadata.MetadataFile.HeaderKey);
|
||||
if (header != null)
|
||||
if (header is not null)
|
||||
{
|
||||
datafile.Build = header.ReadString(Data.Models.Metadata.Header.BuildKey);
|
||||
datafile.Debug = header.ReadString(Data.Models.Metadata.Header.DebugKey);
|
||||
@@ -27,7 +28,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
}
|
||||
|
||||
var machines = obj.Read<Data.Models.Metadata.Machine[]>(Data.Models.Metadata.MetadataFile.MachineKey);
|
||||
if (machines != null && machines.Length > 0)
|
||||
if (machines is not null && machines.Length > 0)
|
||||
datafile.Game = Array.ConvertAll(machines, m => ConvertMachineFromInternalModel(m, game));
|
||||
|
||||
return datafile;
|
||||
@@ -60,19 +61,19 @@ namespace SabreTools.Serialization.CrossModel
|
||||
string? forceNodump = item.ReadString(Data.Models.Metadata.Header.ForceNodumpKey);
|
||||
string? forceUnpacking = item.ReadString(Data.Models.Metadata.Header.ForcePackingKey);
|
||||
|
||||
if (headerVal != null
|
||||
|| forceMerging != null
|
||||
|| forceNodump != null
|
||||
|| forceUnpacking != null)
|
||||
if (headerVal is not null
|
||||
|| forceMerging is not null
|
||||
|| forceNodump is not null
|
||||
|| forceUnpacking is not null)
|
||||
{
|
||||
header.ClrMamePro = new Data.Models.Logiqx.ClrMamePro();
|
||||
if (headerVal != null)
|
||||
if (headerVal is not null)
|
||||
header.ClrMamePro.Header = headerVal;
|
||||
if (forceMerging != null)
|
||||
if (forceMerging is not null)
|
||||
header.ClrMamePro.ForceMerging = forceMerging;
|
||||
if (forceNodump != null)
|
||||
if (forceNodump is not null)
|
||||
header.ClrMamePro.ForceNodump = forceNodump;
|
||||
if (forceUnpacking != null)
|
||||
if (forceUnpacking is not null)
|
||||
header.ClrMamePro.ForcePacking = forceUnpacking;
|
||||
}
|
||||
|
||||
@@ -84,28 +85,28 @@ namespace SabreTools.Serialization.CrossModel
|
||||
string? lockBiosMode = item.ReadString(Data.Models.Metadata.Header.LockBiosModeKey);
|
||||
string? lockSampleMode = item.ReadString(Data.Models.Metadata.Header.LockSampleModeKey);
|
||||
|
||||
if (plugin != null
|
||||
|| romMode != null
|
||||
|| biosMode != null
|
||||
|| sampleMode != null
|
||||
|| lockRomMode != null
|
||||
|| lockBiosMode != null
|
||||
|| lockSampleMode != null)
|
||||
if (plugin is not null
|
||||
|| romMode is not null
|
||||
|| biosMode is not null
|
||||
|| sampleMode is not null
|
||||
|| lockRomMode is not null
|
||||
|| lockBiosMode is not null
|
||||
|| lockSampleMode is not null)
|
||||
{
|
||||
header.RomCenter = new Data.Models.Logiqx.RomCenter();
|
||||
if (plugin != null)
|
||||
if (plugin is not null)
|
||||
header.RomCenter.Plugin = plugin;
|
||||
if (romMode != null)
|
||||
if (romMode is not null)
|
||||
header.RomCenter.RomMode = romMode;
|
||||
if (biosMode != null)
|
||||
if (biosMode is not null)
|
||||
header.RomCenter.BiosMode = biosMode;
|
||||
if (sampleMode != null)
|
||||
if (sampleMode is not null)
|
||||
header.RomCenter.SampleMode = sampleMode;
|
||||
if (lockRomMode != null)
|
||||
if (lockRomMode is not null)
|
||||
header.RomCenter.LockRomMode = lockRomMode;
|
||||
if (lockBiosMode != null)
|
||||
if (lockBiosMode is not null)
|
||||
header.RomCenter.LockBiosMode = lockBiosMode;
|
||||
if (lockSampleMode != null)
|
||||
if (lockSampleMode is not null)
|
||||
header.RomCenter.LockSampleMode = lockSampleMode;
|
||||
}
|
||||
|
||||
@@ -140,47 +141,47 @@ namespace SabreTools.Serialization.CrossModel
|
||||
gameBase.Category = item.ReadStringArray(Data.Models.Metadata.Machine.CategoryKey);
|
||||
|
||||
var trurip = item.Read<Trurip>(Data.Models.Metadata.Machine.TruripKey);
|
||||
if (trurip != null)
|
||||
if (trurip is not null)
|
||||
gameBase.Trurip = trurip;
|
||||
|
||||
var releases = item.Read<Data.Models.Metadata.Release[]>(Data.Models.Metadata.Machine.ReleaseKey);
|
||||
if (releases != null && releases.Length > 0)
|
||||
if (releases is not null && releases.Length > 0)
|
||||
gameBase.Release = Array.ConvertAll(releases, ConvertFromInternalModel);
|
||||
|
||||
var biosSets = item.Read<Data.Models.Metadata.BiosSet[]>(Data.Models.Metadata.Machine.BiosSetKey);
|
||||
if (biosSets != null && biosSets.Length > 0)
|
||||
if (biosSets is not null && biosSets.Length > 0)
|
||||
gameBase.BiosSet = Array.ConvertAll(biosSets, ConvertFromInternalModel);
|
||||
|
||||
var roms = item.Read<Data.Models.Metadata.Rom[]>(Data.Models.Metadata.Machine.RomKey);
|
||||
if (roms != null && roms.Length > 0)
|
||||
if (roms is not null && roms.Length > 0)
|
||||
gameBase.Rom = Array.ConvertAll(roms, ConvertFromInternalModel);
|
||||
|
||||
var disks = item.Read<Data.Models.Metadata.Disk[]>(Data.Models.Metadata.Machine.DiskKey);
|
||||
if (disks != null && disks.Length > 0)
|
||||
if (disks is not null && disks.Length > 0)
|
||||
gameBase.Disk = Array.ConvertAll(disks, ConvertFromInternalModel);
|
||||
|
||||
var medias = item.Read<Data.Models.Metadata.Media[]>(Data.Models.Metadata.Machine.MediaKey);
|
||||
if (medias != null && medias.Length > 0)
|
||||
if (medias is not null && medias.Length > 0)
|
||||
gameBase.Media = Array.ConvertAll(medias, ConvertFromInternalModel);
|
||||
|
||||
var deviceRefs = item.Read<Data.Models.Metadata.DeviceRef[]>(Data.Models.Metadata.Machine.DeviceRefKey);
|
||||
if (deviceRefs != null && deviceRefs.Length > 0)
|
||||
if (deviceRefs is not null && deviceRefs.Length > 0)
|
||||
gameBase.DeviceRef = Array.ConvertAll(deviceRefs, ConvertFromInternalModel);
|
||||
|
||||
var samples = item.Read<Data.Models.Metadata.Sample[]>(Data.Models.Metadata.Machine.SampleKey);
|
||||
if (samples != null && samples.Length > 0)
|
||||
if (samples is not null && samples.Length > 0)
|
||||
gameBase.Sample = Array.ConvertAll(samples, ConvertFromInternalModel);
|
||||
|
||||
var archives = item.Read<Data.Models.Metadata.Archive[]>(Data.Models.Metadata.Machine.ArchiveKey);
|
||||
if (archives != null && archives.Length > 0)
|
||||
if (archives is not null && archives.Length > 0)
|
||||
gameBase.Archive = Array.ConvertAll(archives, ConvertFromInternalModel);
|
||||
|
||||
var driver = item.Read<Data.Models.Metadata.Driver>(Data.Models.Metadata.Machine.DriverKey);
|
||||
if (driver != null)
|
||||
if (driver is not null)
|
||||
gameBase.Driver = ConvertFromInternalModel(driver);
|
||||
|
||||
var softwareLists = item.Read<Data.Models.Metadata.SoftwareList[]>(Data.Models.Metadata.Machine.SoftwareListKey);
|
||||
if (softwareLists != null && softwareLists.Length > 0)
|
||||
if (softwareLists is not null && softwareLists.Length > 0)
|
||||
gameBase.SoftwareList = Array.ConvertAll(softwareLists, ConvertFromInternalModel);
|
||||
|
||||
return gameBase;
|
||||
@@ -301,7 +302,9 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
Name = item.ReadString(Data.Models.Metadata.Rom.NameKey),
|
||||
Size = item.ReadString(Data.Models.Metadata.Rom.SizeKey),
|
||||
CRC16 = item.ReadString(Data.Models.Metadata.Rom.CRC16Key),
|
||||
CRC = item.ReadString(Data.Models.Metadata.Rom.CRCKey),
|
||||
CRC64 = item.ReadString(Data.Models.Metadata.Rom.CRC64Key),
|
||||
MD2 = item.ReadString(Data.Models.Metadata.Rom.MD2Key),
|
||||
MD4 = item.ReadString(Data.Models.Metadata.Rom.MD4Key),
|
||||
MD5 = item.ReadString(Data.Models.Metadata.Rom.MD5Key),
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(Datafile? item)
|
||||
{
|
||||
if (item == null)
|
||||
if (item is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile
|
||||
@@ -18,7 +18,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
|
||||
var machines = new List<Data.Models.Metadata.Machine>();
|
||||
|
||||
if (item.Game != null && item.Game.Length > 0)
|
||||
if (item.Game is not null && item.Game.Length > 0)
|
||||
machines.AddRange(Array.ConvertAll(item.Game, g => ConvertMachineToInternalModel(g)));
|
||||
|
||||
foreach (var dir in item.Dir ?? [])
|
||||
@@ -37,7 +37,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// </summary>
|
||||
private static Data.Models.Metadata.Header ConvertHeaderToInternalModel(Datafile item)
|
||||
{
|
||||
var header = item.Header != null ? ConvertHeaderToInternalModel(item.Header) : [];
|
||||
var header = item.Header is not null ? ConvertHeaderToInternalModel(item.Header) : [];
|
||||
|
||||
header[Data.Models.Metadata.Header.BuildKey] = item.Build;
|
||||
header[Data.Models.Metadata.Header.DebugKey] = item.Debug;
|
||||
@@ -68,7 +68,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Header.TypeKey] = item.Type,
|
||||
};
|
||||
|
||||
if (item.ClrMamePro != null)
|
||||
if (item.ClrMamePro is not null)
|
||||
{
|
||||
header[Data.Models.Metadata.Header.HeaderKey] = item.ClrMamePro.Header;
|
||||
header[Data.Models.Metadata.Header.ForceMergingKey] = item.ClrMamePro.ForceMerging;
|
||||
@@ -76,7 +76,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
header[Data.Models.Metadata.Header.ForcePackingKey] = item.ClrMamePro.ForcePacking;
|
||||
}
|
||||
|
||||
if (item.RomCenter != null)
|
||||
if (item.RomCenter is not null)
|
||||
{
|
||||
header[Data.Models.Metadata.Header.PluginKey] = item.RomCenter.Plugin;
|
||||
header[Data.Models.Metadata.Header.RomModeKey] = item.RomCenter.RomMode;
|
||||
@@ -97,12 +97,12 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
// Get the directory name
|
||||
string? dirName = item.Name;
|
||||
if (parent != null)
|
||||
if (parent is not null)
|
||||
dirName = $"{parent}\\{item.Name}";
|
||||
|
||||
// Handle machine items
|
||||
Data.Models.Metadata.Machine[] machines = [];
|
||||
if (item.Game != null && item.Game.Length > 0)
|
||||
if (item.Game is not null && item.Game.Length > 0)
|
||||
machines = Array.ConvertAll(item.Game, g => ConvertMachineToInternalModel(g, dirName));
|
||||
|
||||
// Handle dir items
|
||||
@@ -121,7 +121,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
private static Data.Models.Metadata.Machine ConvertMachineToInternalModel(GameBase item, string? dir = null)
|
||||
{
|
||||
string? machineName = item.Name;
|
||||
if (machineName != null && dir != null)
|
||||
if (machineName is not null && dir is not null)
|
||||
machineName = $"{dir}\\{machineName}";
|
||||
|
||||
var machine = new Data.Models.Metadata.Machine
|
||||
@@ -148,34 +148,34 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Machine.TruripKey] = item.Trurip,
|
||||
};
|
||||
|
||||
if (item.Release != null && item.Release.Length > 0)
|
||||
if (item.Release is not null && item.Release.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.ReleaseKey] = Array.ConvertAll(item.Release, ConvertToInternalModel);
|
||||
|
||||
if (item.BiosSet != null && item.BiosSet.Length > 0)
|
||||
if (item.BiosSet is not null && item.BiosSet.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.BiosSetKey] = Array.ConvertAll(item.BiosSet, ConvertToInternalModel);
|
||||
|
||||
if (item.Rom != null && item.Rom.Length > 0)
|
||||
if (item.Rom is not null && item.Rom.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.RomKey] = Array.ConvertAll(item.Rom, ConvertToInternalModel);
|
||||
|
||||
if (item.Disk != null && item.Disk.Length > 0)
|
||||
if (item.Disk is not null && item.Disk.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.DiskKey] = Array.ConvertAll(item.Disk, ConvertToInternalModel);
|
||||
|
||||
if (item.Media != null && item.Media.Length > 0)
|
||||
if (item.Media is not null && item.Media.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.MediaKey] = Array.ConvertAll(item.Media, ConvertToInternalModel);
|
||||
|
||||
if (item.DeviceRef != null && item.DeviceRef.Length > 0)
|
||||
if (item.DeviceRef is not null && item.DeviceRef.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.DeviceRefKey] = Array.ConvertAll(item.DeviceRef, ConvertToInternalModel);
|
||||
|
||||
if (item.Sample != null && item.Sample.Length > 0)
|
||||
if (item.Sample is not null && item.Sample.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.SampleKey] = Array.ConvertAll(item.Sample, ConvertToInternalModel);
|
||||
|
||||
if (item.Archive != null && item.Archive.Length > 0)
|
||||
if (item.Archive is not null && item.Archive.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.ArchiveKey] = Array.ConvertAll(item.Archive, ConvertToInternalModel);
|
||||
|
||||
if (item.Driver != null)
|
||||
if (item.Driver is not null)
|
||||
machine[Data.Models.Metadata.Machine.DriverKey] = ConvertToInternalModel(item.Driver);
|
||||
|
||||
if (item.SoftwareList != null && item.SoftwareList.Length > 0)
|
||||
if (item.SoftwareList is not null && item.SoftwareList.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.SoftwareListKey] = Array.ConvertAll(item.SoftwareList, ConvertToInternalModel);
|
||||
|
||||
return machine;
|
||||
@@ -296,7 +296,9 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
[Data.Models.Metadata.Rom.NameKey] = item.Name,
|
||||
[Data.Models.Metadata.Rom.SizeKey] = item.Size,
|
||||
[Data.Models.Metadata.Rom.CRC16Key] = item.CRC16,
|
||||
[Data.Models.Metadata.Rom.CRCKey] = item.CRC,
|
||||
[Data.Models.Metadata.Rom.CRC64Key] = item.CRC64,
|
||||
[Data.Models.Metadata.Rom.MD2Key] = item.MD2,
|
||||
[Data.Models.Metadata.Rom.MD4Key] = item.MD4,
|
||||
[Data.Models.Metadata.Rom.MD5Key] = item.MD5,
|
||||
|
||||
@@ -7,14 +7,14 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Listxml.M1? Deserialize(Data.Models.Metadata.MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var header = obj.Read<Data.Models.Metadata.Header>(Data.Models.Metadata.MetadataFile.HeaderKey);
|
||||
var m1 = header != null ? ConvertM1FromInternalModel(header) : new Data.Models.Listxml.M1();
|
||||
var m1 = header is not null ? ConvertM1FromInternalModel(header) : new Data.Models.Listxml.M1();
|
||||
|
||||
var machines = obj.Read<Data.Models.Metadata.Machine[]>(Data.Models.Metadata.MetadataFile.MachineKey);
|
||||
if (machines != null && machines.Length > 0)
|
||||
if (machines is not null && machines.Length > 0)
|
||||
m1.Game = Array.ConvertAll(machines, Listxml.ConvertMachineFromInternalModel);
|
||||
|
||||
return m1;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(Data.Models.Listxml.M1? item)
|
||||
{
|
||||
if (item == null)
|
||||
if (item is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile
|
||||
@@ -15,7 +15,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(item),
|
||||
};
|
||||
|
||||
if (item?.Game != null && item.Game.Length > 0)
|
||||
if (item?.Game is not null && item.Game.Length > 0)
|
||||
{
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.MachineKey]
|
||||
= Array.ConvertAll(item.Game, Listxml.ConvertMachineToInternalModel);
|
||||
|
||||
@@ -7,14 +7,14 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Listxml.Mess? Deserialize(Data.Models.Metadata.MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var header = obj.Read<Data.Models.Metadata.Header>(Data.Models.Metadata.MetadataFile.HeaderKey);
|
||||
var m1 = header != null ? ConvertMessFromInternalModel(header) : new Data.Models.Listxml.Mess();
|
||||
var m1 = header is not null ? ConvertMessFromInternalModel(header) : new Data.Models.Listxml.Mess();
|
||||
|
||||
var machines = obj.Read<Data.Models.Metadata.Machine[]>(Data.Models.Metadata.MetadataFile.MachineKey);
|
||||
if (machines != null && machines.Length > 0)
|
||||
if (machines is not null && machines.Length > 0)
|
||||
m1.Game = Array.ConvertAll(machines, Listxml.ConvertMachineFromInternalModel);
|
||||
|
||||
return m1;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(Data.Models.Listxml.Mess? item)
|
||||
{
|
||||
if (item == null)
|
||||
if (item is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile
|
||||
@@ -15,7 +15,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(item),
|
||||
};
|
||||
|
||||
if (item?.Game != null && item.Game.Length > 0)
|
||||
if (item?.Game is not null && item.Game.Length > 0)
|
||||
{
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.MachineKey]
|
||||
= Array.ConvertAll(item.Game, Listxml.ConvertMachineToInternalModel);
|
||||
|
||||
@@ -8,14 +8,14 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Dat? Deserialize(Data.Models.Metadata.MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var header = obj.Read<Data.Models.Metadata.Header>(Data.Models.Metadata.MetadataFile.HeaderKey);
|
||||
var dat = header != null ? ConvertHeaderFromInternalModel(header) : new Dat();
|
||||
var dat = header is not null ? ConvertHeaderFromInternalModel(header) : new Dat();
|
||||
|
||||
var machines = obj.Read<Data.Models.Metadata.Machine[]>(Data.Models.Metadata.MetadataFile.MachineKey);
|
||||
if (machines != null && machines.Length > 0)
|
||||
if (machines is not null && machines.Length > 0)
|
||||
{
|
||||
dat.Games = new Games
|
||||
{
|
||||
@@ -97,7 +97,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var roms = item.Read<Data.Models.Metadata.Rom[]>(Data.Models.Metadata.Machine.RomKey);
|
||||
if (roms != null && roms.Length > 0)
|
||||
if (roms is not null && roms.Length > 0)
|
||||
{
|
||||
var romSizes = Array.ConvertAll(roms, r => r.ReadLong(Data.Models.Metadata.Rom.SizeKey) ?? -1);
|
||||
game.RomSize = Array.Find(romSizes, s => s > -1).ToString();
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(Dat? item)
|
||||
{
|
||||
if (item == null)
|
||||
if (item is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile
|
||||
@@ -16,7 +16,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(item),
|
||||
};
|
||||
|
||||
if (item?.Games?.Game != null && item.Games.Game.Length > 0)
|
||||
if (item?.Games?.Game is not null && item.Games.Game.Length > 0)
|
||||
{
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.MachineKey]
|
||||
= Array.ConvertAll(item.Games.Game, ConvertMachineToInternalModel);
|
||||
@@ -35,7 +35,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Header.SchemaLocationKey] = item.NoNamespaceSchemaLocation,
|
||||
};
|
||||
|
||||
if (item.Configuration != null)
|
||||
if (item.Configuration is not null)
|
||||
{
|
||||
header[Data.Models.Metadata.Header.NameKey] = item.Configuration.DatName;
|
||||
header[Data.Models.Metadata.Header.ImFolderKey] = item.Configuration.ImFolder;
|
||||
@@ -50,7 +50,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
header[Data.Models.Metadata.Header.RomTitleKey] = item.Configuration.RomTitle;
|
||||
}
|
||||
|
||||
if (item.GUI != null)
|
||||
if (item.GUI is not null)
|
||||
{
|
||||
header[Data.Models.Metadata.Header.ImagesKey] = item.GUI.Images;
|
||||
}
|
||||
@@ -79,7 +79,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Machine.DuplicateIDKey] = item.DuplicateID,
|
||||
};
|
||||
|
||||
if (item.Files?.RomCRC != null && item.Files.RomCRC.Length > 0)
|
||||
if (item.Files?.RomCRC is not null && item.Files.RomCRC.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.RomKey]
|
||||
= Array.ConvertAll(item.Files.RomCRC, romCRC =>
|
||||
|
||||
@@ -8,14 +8,14 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override SoftwareDb? Deserialize(Data.Models.Metadata.MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var header = obj.Read<Data.Models.Metadata.Header>(Data.Models.Metadata.MetadataFile.HeaderKey);
|
||||
var softwareDb = header != null ? ConvertHeaderFromInternalModel(header) : new SoftwareDb();
|
||||
var softwareDb = header is not null ? ConvertHeaderFromInternalModel(header) : new SoftwareDb();
|
||||
|
||||
var machines = obj.Read<Data.Models.Metadata.Machine[]>(Data.Models.Metadata.MetadataFile.MachineKey);
|
||||
if (machines != null && machines.Length > 0)
|
||||
if (machines is not null && machines.Length > 0)
|
||||
softwareDb.Software = Array.ConvertAll(machines, ConvertMachineFromInternalModel);
|
||||
|
||||
return softwareDb;
|
||||
@@ -49,7 +49,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var dumps = item.Read<Data.Models.Metadata.Dump[]>(Data.Models.Metadata.Machine.DumpKey);
|
||||
if (dumps != null && dumps.Length > 0)
|
||||
if (dumps is not null && dumps.Length > 0)
|
||||
game.Dump = Array.ConvertAll(dumps, ConvertFromInternalModel);
|
||||
|
||||
return game;
|
||||
@@ -63,19 +63,19 @@ namespace SabreTools.Serialization.CrossModel
|
||||
var dump = new Dump();
|
||||
|
||||
var original = item.Read<Data.Models.Metadata.Original>(Data.Models.Metadata.Dump.OriginalKey);
|
||||
if (original != null)
|
||||
if (original is not null)
|
||||
dump.Original = ConvertFromInternalModel(original);
|
||||
|
||||
var rom = item.Read<Data.Models.Metadata.Rom>(Data.Models.Metadata.Dump.RomKey);
|
||||
if (rom != null)
|
||||
if (rom is not null)
|
||||
dump.Rom = ConvertRomFromInternalModel(rom);
|
||||
|
||||
var megaRom = item.Read<Data.Models.Metadata.Rom>(Data.Models.Metadata.Dump.MegaRomKey);
|
||||
if (megaRom != null)
|
||||
if (megaRom is not null)
|
||||
dump.Rom = ConvertMegaRomFromInternalModel(megaRom);
|
||||
|
||||
var sccPlusCart = item.Read<Data.Models.Metadata.Rom>(Data.Models.Metadata.Dump.SCCPlusCartKey);
|
||||
if (sccPlusCart != null)
|
||||
if (sccPlusCart is not null)
|
||||
dump.Rom = ConvertSCCPlusCartFromInternalModel(sccPlusCart);
|
||||
|
||||
return dump;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(SoftwareDb? item)
|
||||
{
|
||||
if (item == null)
|
||||
if (item is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile
|
||||
@@ -16,7 +16,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(item),
|
||||
};
|
||||
|
||||
if (item?.Software != null && item.Software.Length > 0)
|
||||
if (item?.Software is not null && item.Software.Length > 0)
|
||||
{
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.MachineKey]
|
||||
= Array.ConvertAll(item.Software, ConvertMachineToInternalModel);
|
||||
@@ -52,7 +52,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Machine.CountryKey] = item.Country,
|
||||
};
|
||||
|
||||
if (item.Dump != null && item.Dump.Length > 0)
|
||||
if (item.Dump is not null && item.Dump.Length > 0)
|
||||
{
|
||||
machine[Data.Models.Metadata.Machine.DumpKey]
|
||||
= Array.ConvertAll(item.Dump, ConvertToInternalModel);
|
||||
@@ -68,10 +68,10 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
var dump = new Data.Models.Metadata.Dump();
|
||||
|
||||
if (item.Original != null)
|
||||
if (item.Original is not null)
|
||||
dump[Data.Models.Metadata.Dump.OriginalKey] = ConvertToInternalModel(item.Original);
|
||||
|
||||
if (item.Rom != null)
|
||||
if (item.Rom is not null)
|
||||
{
|
||||
switch (item.Rom)
|
||||
{
|
||||
@@ -86,6 +86,10 @@ namespace SabreTools.Serialization.CrossModel
|
||||
case SCCPlusCart sccPlusCart:
|
||||
dump[Data.Models.Metadata.Dump.SCCPlusCartKey] = ConvertToInternalModel(sccPlusCart);
|
||||
break;
|
||||
|
||||
default:
|
||||
// TODO: Log invalid values
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override MetadataFile? Deserialize(Data.Models.Metadata.MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var header = obj.Read<Data.Models.Metadata.Header>(Data.Models.Metadata.MetadataFile.HeaderKey);
|
||||
var metadataFile = header != null ? ConvertHeaderFromInternalModel(header) : new MetadataFile();
|
||||
var metadataFile = header is not null ? ConvertHeaderFromInternalModel(header) : new MetadataFile();
|
||||
|
||||
var machines = obj.Read<Data.Models.Metadata.Machine[]>(Data.Models.Metadata.MetadataFile.MachineKey);
|
||||
var items = new List<Rom>();
|
||||
@@ -85,7 +85,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
private static Rom[] ConvertMachineFromInternalModel(Data.Models.Metadata.Machine item)
|
||||
{
|
||||
var roms = item.Read<Data.Models.Metadata.Rom[]>(Data.Models.Metadata.Machine.RomKey);
|
||||
if (roms == null)
|
||||
if (roms is null)
|
||||
return [];
|
||||
|
||||
return Array.ConvertAll(roms, r => ConvertFromInternalModel(r, item));
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile
|
||||
@@ -16,7 +16,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(obj),
|
||||
};
|
||||
|
||||
if (obj?.Games?.Rom != null && obj.Games.Rom.Length > 0)
|
||||
if (obj?.Games?.Rom is not null && obj.Games.Rom.Length > 0)
|
||||
{
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.MachineKey]
|
||||
= Array.ConvertAll(obj.Games.Rom, ConvertMachineToInternalModel);
|
||||
@@ -32,7 +32,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
{
|
||||
var header = new Data.Models.Metadata.Header();
|
||||
|
||||
if (item.Credits != null)
|
||||
if (item.Credits is not null)
|
||||
{
|
||||
header[Data.Models.Metadata.Header.AuthorKey] = item.Credits.Author;
|
||||
header[Data.Models.Metadata.Header.VersionKey] = item.Credits.Version;
|
||||
@@ -43,7 +43,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
header[Data.Models.Metadata.Header.CommentKey] = item.Credits.Comment;
|
||||
}
|
||||
|
||||
if (item.Dat != null)
|
||||
if (item.Dat is not null)
|
||||
{
|
||||
header[Data.Models.Metadata.Header.DatVersionKey] = item.Dat.Version;
|
||||
header[Data.Models.Metadata.Header.PluginKey] = item.Dat.Plugin;
|
||||
@@ -54,7 +54,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
header[Data.Models.Metadata.Header.ForceMergingKey] = "merge";
|
||||
}
|
||||
|
||||
if (item.Emulator != null)
|
||||
if (item.Emulator is not null)
|
||||
{
|
||||
header[Data.Models.Metadata.Header.RefNameKey] = item.Emulator.RefName;
|
||||
header[Data.Models.Metadata.Header.EmulatorVersionKey] = item.Emulator.Version;
|
||||
|
||||
@@ -9,11 +9,11 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override MetadataFile? Deserialize(Data.Models.Metadata.MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var header = obj.Read<Data.Models.Metadata.Header>(Data.Models.Metadata.MetadataFile.HeaderKey);
|
||||
var metadataFile = header != null ? ConvertHeaderFromInternalModel(header) : new MetadataFile();
|
||||
var metadataFile = header is not null ? ConvertHeaderFromInternalModel(header) : new MetadataFile();
|
||||
|
||||
var machines = obj.Read<Data.Models.Metadata.Machine[]>(Data.Models.Metadata.MetadataFile.MachineKey);
|
||||
var items = new List<Row>();
|
||||
@@ -46,21 +46,21 @@ namespace SabreTools.Serialization.CrossModel
|
||||
var rowItems = new List<Row>();
|
||||
|
||||
var roms = item.Read<Data.Models.Metadata.Rom[]>(Data.Models.Metadata.Machine.RomKey);
|
||||
if (roms != null && roms.Length > 0)
|
||||
if (roms is not null && roms.Length > 0)
|
||||
{
|
||||
rowItems.AddRange(
|
||||
Array.ConvertAll(roms, r => ConvertFromInternalModel(r, item, header)));
|
||||
}
|
||||
|
||||
var disks = item.Read<Data.Models.Metadata.Disk[]>(Data.Models.Metadata.Machine.DiskKey);
|
||||
if (disks != null && disks.Length > 0)
|
||||
if (disks is not null && disks.Length > 0)
|
||||
{
|
||||
rowItems.AddRange(
|
||||
Array.ConvertAll(disks, d => ConvertFromInternalModel(d, item, header)));
|
||||
}
|
||||
|
||||
var media = item.Read<Data.Models.Metadata.Media[]>(Data.Models.Metadata.Machine.MediaKey);
|
||||
if (media != null && media.Length > 0)
|
||||
if (media is not null && media.Length > 0)
|
||||
{
|
||||
rowItems.AddRange(
|
||||
Array.ConvertAll(media, m => ConvertFromInternalModel(m, item, header)));
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile
|
||||
@@ -16,7 +16,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(obj),
|
||||
};
|
||||
|
||||
if (obj?.Row != null && obj.Row.Length > 0)
|
||||
if (obj?.Row is not null && obj.Row.Length > 0)
|
||||
{
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.MachineKey]
|
||||
= Array.ConvertAll(obj.Row, ConvertMachineToInternalModel);
|
||||
@@ -35,7 +35,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Header.HeaderKey] = item.Header,
|
||||
};
|
||||
|
||||
if (item.Row != null && item.Row.Length > 0)
|
||||
if (item.Row is not null && item.Row.Length > 0)
|
||||
{
|
||||
var first = item.Row[0];
|
||||
header["FILENAME"] = first.FileName; // TODO: Make this an actual key to retrieve on an item -- OriginalFilename
|
||||
@@ -71,6 +71,10 @@ namespace SabreTools.Serialization.CrossModel
|
||||
case Data.Models.Metadata.Rom rom:
|
||||
machine[Data.Models.Metadata.Machine.RomKey] = new Data.Models.Metadata.Rom[] { rom };
|
||||
break;
|
||||
|
||||
default:
|
||||
// TODO: Log invalid values
|
||||
break;
|
||||
}
|
||||
|
||||
return machine;
|
||||
|
||||
@@ -8,14 +8,14 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.SoftwareList.SoftwareList? Deserialize(Data.Models.Metadata.MetadataFile? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (obj is null)
|
||||
return null;
|
||||
|
||||
var header = obj.Read<Data.Models.Metadata.Header>(Data.Models.Metadata.MetadataFile.HeaderKey);
|
||||
var metadataFile = header != null ? ConvertHeaderFromInternalModel(header) : new Data.Models.SoftwareList.SoftwareList();
|
||||
var metadataFile = header is not null ? ConvertHeaderFromInternalModel(header) : new Data.Models.SoftwareList.SoftwareList();
|
||||
|
||||
var machines = obj.Read<Data.Models.Metadata.Machine[]>(Data.Models.Metadata.MetadataFile.MachineKey);
|
||||
if (machines != null && machines.Length > 0)
|
||||
if (machines is not null && machines.Length > 0)
|
||||
metadataFile.Software = Array.ConvertAll(machines, ConvertMachineFromInternalModel);
|
||||
|
||||
return metadataFile;
|
||||
@@ -52,15 +52,15 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var infos = item.Read<Data.Models.Metadata.Info[]>(Data.Models.Metadata.Machine.InfoKey);
|
||||
if (infos != null && infos.Length > 0)
|
||||
if (infos is not null && infos.Length > 0)
|
||||
software.Info = Array.ConvertAll(infos, ConvertFromInternalModel);
|
||||
|
||||
var sharedFeats = item.Read<Data.Models.Metadata.SharedFeat[]>(Data.Models.Metadata.Machine.SharedFeatKey);
|
||||
if (sharedFeats != null && sharedFeats.Length > 0)
|
||||
if (sharedFeats is not null && sharedFeats.Length > 0)
|
||||
software.SharedFeat = Array.ConvertAll(sharedFeats, ConvertFromInternalModel);
|
||||
|
||||
var parts = item.Read<Data.Models.Metadata.Part[]>(Data.Models.Metadata.Machine.PartKey);
|
||||
if (parts != null && parts.Length > 0)
|
||||
if (parts is not null && parts.Length > 0)
|
||||
software.Part = Array.ConvertAll(parts, ConvertFromInternalModel);
|
||||
|
||||
return software;
|
||||
@@ -80,7 +80,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var roms = item.Read<Data.Models.Metadata.Rom[]>(Data.Models.Metadata.DataArea.RomKey);
|
||||
if (roms != null && roms.Length > 0)
|
||||
if (roms is not null && roms.Length > 0)
|
||||
dataArea.Rom = Array.ConvertAll(roms, ConvertFromInternalModel);
|
||||
|
||||
return dataArea;
|
||||
@@ -99,7 +99,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var dipValues = item.Read<Data.Models.Metadata.DipValue[]>(Data.Models.Metadata.DipSwitch.DipValueKey);
|
||||
if (dipValues != null && dipValues.Length > 0)
|
||||
if (dipValues is not null && dipValues.Length > 0)
|
||||
dipSwitch.DipValue = Array.ConvertAll(dipValues, ConvertFromInternalModel);
|
||||
|
||||
return dipSwitch;
|
||||
@@ -146,7 +146,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var disks = item.Read<Data.Models.Metadata.Disk[]>(Data.Models.Metadata.DiskArea.DiskKey);
|
||||
if (disks != null && disks.Length > 0)
|
||||
if (disks is not null && disks.Length > 0)
|
||||
diskArea.Disk = Array.ConvertAll(disks, ConvertFromInternalModel);
|
||||
|
||||
return diskArea;
|
||||
@@ -190,19 +190,19 @@ namespace SabreTools.Serialization.CrossModel
|
||||
};
|
||||
|
||||
var features = item.Read<Data.Models.Metadata.Feature[]>(Data.Models.Metadata.Part.FeatureKey);
|
||||
if (features != null && features.Length > 0)
|
||||
if (features is not null && features.Length > 0)
|
||||
part.Feature = Array.ConvertAll(features, ConvertFromInternalModel);
|
||||
|
||||
var dataAreas = item.Read<Data.Models.Metadata.DataArea[]>(Data.Models.Metadata.Part.DataAreaKey);
|
||||
if (dataAreas != null && dataAreas.Length > 0)
|
||||
if (dataAreas is not null && dataAreas.Length > 0)
|
||||
part.DataArea = Array.ConvertAll(dataAreas, ConvertFromInternalModel);
|
||||
|
||||
var diskAreas = item.Read<Data.Models.Metadata.DiskArea[]>(Data.Models.Metadata.Part.DiskAreaKey);
|
||||
if (diskAreas != null && diskAreas.Length > 0)
|
||||
if (diskAreas is not null && diskAreas.Length > 0)
|
||||
part.DiskArea = Array.ConvertAll(diskAreas, ConvertFromInternalModel);
|
||||
|
||||
var dipSwitches = item.Read<Data.Models.Metadata.DipSwitch[]>(Data.Models.Metadata.Part.DipSwitchKey);
|
||||
if (dipSwitches != null && dipSwitches.Length > 0)
|
||||
if (dipSwitches is not null && dipSwitches.Length > 0)
|
||||
part.DipSwitch = Array.ConvertAll(dipSwitches, ConvertFromInternalModel);
|
||||
|
||||
return part;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
/// <inheritdoc/>
|
||||
public override Data.Models.Metadata.MetadataFile? Serialize(Data.Models.SoftwareList.SoftwareList? item)
|
||||
{
|
||||
if (item == null)
|
||||
if (item is null)
|
||||
return null;
|
||||
|
||||
var metadataFile = new Data.Models.Metadata.MetadataFile
|
||||
@@ -16,7 +16,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.MetadataFile.HeaderKey] = ConvertHeaderToInternalModel(item),
|
||||
};
|
||||
|
||||
if (item?.Software != null && item.Software.Length > 0)
|
||||
if (item?.Software is not null && item.Software.Length > 0)
|
||||
{
|
||||
metadataFile[Data.Models.Metadata.MetadataFile.MachineKey]
|
||||
= Array.ConvertAll(item.Software, ConvertMachineToInternalModel);
|
||||
@@ -55,13 +55,13 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Machine.NotesKey] = item.Notes,
|
||||
};
|
||||
|
||||
if (item.Info != null && item.Info.Length > 0)
|
||||
if (item.Info is not null && item.Info.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.InfoKey] = Array.ConvertAll(item.Info, ConvertToInternalModel);
|
||||
|
||||
if (item.SharedFeat != null && item.SharedFeat.Length > 0)
|
||||
if (item.SharedFeat is not null && item.SharedFeat.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.SharedFeatKey] = Array.ConvertAll(item.SharedFeat, ConvertToInternalModel);
|
||||
|
||||
if (item.Part != null && item.Part.Length > 0)
|
||||
if (item.Part is not null && item.Part.Length > 0)
|
||||
machine[Data.Models.Metadata.Machine.PartKey] = Array.ConvertAll(item.Part, ConvertToInternalModel);
|
||||
|
||||
return machine;
|
||||
@@ -80,7 +80,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.DataArea.EndiannessKey] = item.Endianness,
|
||||
};
|
||||
|
||||
if (item.Rom != null && item.Rom.Length > 0)
|
||||
if (item.Rom is not null && item.Rom.Length > 0)
|
||||
dataArea[Data.Models.Metadata.DataArea.RomKey] = Array.ConvertAll(item.Rom, ConvertToInternalModel);
|
||||
|
||||
return dataArea;
|
||||
@@ -98,7 +98,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.DipSwitch.MaskKey] = item.Mask,
|
||||
};
|
||||
|
||||
if (item.DipValue != null && item.DipValue.Length > 0)
|
||||
if (item.DipValue is not null && item.DipValue.Length > 0)
|
||||
dipSwitch[Data.Models.Metadata.DipSwitch.DipValueKey] = Array.ConvertAll(item.DipValue, ConvertToInternalModel);
|
||||
|
||||
return dipSwitch;
|
||||
@@ -144,7 +144,7 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.DiskArea.NameKey] = item.Name,
|
||||
};
|
||||
|
||||
if (item.Disk != null && item.Disk.Length > 0)
|
||||
if (item.Disk is not null && item.Disk.Length > 0)
|
||||
diskArea[Data.Models.Metadata.DiskArea.DiskKey] = Array.ConvertAll(item.Disk, ConvertToInternalModel);
|
||||
|
||||
return diskArea;
|
||||
@@ -187,16 +187,16 @@ namespace SabreTools.Serialization.CrossModel
|
||||
[Data.Models.Metadata.Part.InterfaceKey] = item.Interface,
|
||||
};
|
||||
|
||||
if (item.Feature != null && item.Feature.Length > 0)
|
||||
if (item.Feature is not null && item.Feature.Length > 0)
|
||||
part[Data.Models.Metadata.Part.FeatureKey] = Array.ConvertAll(item.Feature, ConvertToInternalModel);
|
||||
|
||||
if (item.DataArea != null && item.DataArea.Length > 0)
|
||||
if (item.DataArea is not null && item.DataArea.Length > 0)
|
||||
part[Data.Models.Metadata.Part.DataAreaKey] = Array.ConvertAll(item.DataArea, ConvertToInternalModel);
|
||||
|
||||
if (item.DiskArea != null && item.DiskArea.Length > 0)
|
||||
if (item.DiskArea is not null && item.DiskArea.Length > 0)
|
||||
part[Data.Models.Metadata.Part.DiskAreaKey] = Array.ConvertAll(item.DiskArea, ConvertToInternalModel);
|
||||
|
||||
if (item.DipSwitch != null && item.DipSwitch.Length > 0)
|
||||
if (item.DipSwitch is not null && item.DipSwitch.Length > 0)
|
||||
part[Data.Models.Metadata.Part.DipSwitchKey] = Array.ConvertAll(item.DipSwitch, ConvertToInternalModel);
|
||||
|
||||
return part;
|
||||
|
||||
@@ -1,308 +1,312 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SabreTools.Data.Models.CDROM;
|
||||
using SabreTools.IO.Extensions;
|
||||
|
||||
namespace SabreTools.Data.Extensions
|
||||
{
|
||||
public static class CDROM
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the sector mode for a CD-ROM stream
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream to derive the sector mode from</param>
|
||||
/// <returns>Sector mode from the stream on success, <see cref="SectorMode.UNKNOWN"/> on error</returns>
|
||||
public static SectorMode GetSectorMode(this Stream stream)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte modeByte = stream.ReadByteValue();
|
||||
if (modeByte == 0)
|
||||
{
|
||||
return SectorMode.MODE0;
|
||||
}
|
||||
else if (modeByte == 1)
|
||||
{
|
||||
return SectorMode.MODE1;
|
||||
}
|
||||
else if (modeByte == 2)
|
||||
{
|
||||
stream.SeekIfPossible(2, SeekOrigin.Current);
|
||||
byte submode = stream.ReadByteValue();
|
||||
if ((submode & 0x20) == 0x20)
|
||||
return SectorMode.MODE2_FORM2;
|
||||
else
|
||||
return SectorMode.MODE2_FORM1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SectorMode.UNKNOWN;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore the actual error
|
||||
return SectorMode.UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the user data size for a sector mode
|
||||
/// </summary>
|
||||
/// <param name="mode">Sector mode to get a value for</param>
|
||||
/// <returns>User data size, if possible</returns>
|
||||
public static long GetUserDataSize(this SectorMode mode)
|
||||
{
|
||||
return mode switch
|
||||
{
|
||||
SectorMode.MODE0 => Constants.Mode0DataSize,
|
||||
SectorMode.MODE1 => Constants.Mode1DataSize,
|
||||
SectorMode.MODE2 => Constants.Mode0DataSize,
|
||||
SectorMode.MODE2_FORM1 => Constants.Mode2Form1DataSize,
|
||||
SectorMode.MODE2_FORM2 => Constants.Mode2Form2DataSize,
|
||||
_ => Constants.Mode0DataSize,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the user data end offset for a sector mode
|
||||
/// </summary>
|
||||
/// <param name="mode">Sector mode to get a value for</param>
|
||||
/// <returns>User data end offset, if possible</returns>
|
||||
public static long GetUserDataEnd(this SectorMode mode)
|
||||
{
|
||||
return mode switch
|
||||
{
|
||||
SectorMode.MODE0 => Constants.Mode0UserDataEnd, // TODO: Support flexible sector length (2352)
|
||||
SectorMode.MODE1 => Constants.Mode1UserDataEnd,
|
||||
SectorMode.MODE2 => Constants.Mode0UserDataEnd, // TODO: Support flexible sector length (2352)
|
||||
SectorMode.MODE2_FORM1 => Constants.Mode2Form1UserDataEnd,
|
||||
SectorMode.MODE2_FORM2 => Constants.Mode2Form2UserDataEnd, // TODO: Support flexible sector length (2348)
|
||||
_ => Constants.Mode0UserDataEnd,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the user data start offset for a sector mode
|
||||
/// </summary>
|
||||
/// <param name="mode">Sector mode to get a value for</param>
|
||||
/// <returns>User data start offset, if possible</returns>
|
||||
public static long GetUserDataStart(this SectorMode mode)
|
||||
{
|
||||
return mode switch
|
||||
{
|
||||
SectorMode.MODE0 => Constants.Mode0UserDataStart,
|
||||
SectorMode.MODE1 => Constants.Mode1UserDataStart,
|
||||
SectorMode.MODE2 => Constants.Mode0UserDataStart,
|
||||
SectorMode.MODE2_FORM1 => Constants.Mode2Form1UserDataStart,
|
||||
SectorMode.MODE2_FORM2 => Constants.Mode2Form2UserDataStart,
|
||||
_ => Constants.Mode0UserDataStart,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a stream that provides only the user data of a CDROM stream
|
||||
/// </summary>
|
||||
public class ISO9660Stream : Stream
|
||||
{
|
||||
// Base CDROM stream (2352-byte sector)
|
||||
private readonly Stream _baseStream;
|
||||
|
||||
// State variables
|
||||
private long _position = 0;
|
||||
private SectorMode _currentMode = SectorMode.UNKNOWN;
|
||||
private long _userDataStart = Constants.Mode1UserDataStart;
|
||||
private long _userDataEnd = Constants.Mode1UserDataEnd;
|
||||
private long _isoSectorSize = Constants.Mode1DataSize;
|
||||
|
||||
public ISO9660Stream(Stream inputStream)
|
||||
{
|
||||
if (!inputStream.CanSeek || !inputStream.CanRead)
|
||||
throw new ArgumentException("Stream must be readable and seekable.", nameof(inputStream));
|
||||
|
||||
_baseStream = inputStream;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool CanRead => _baseStream.CanRead;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool CanSeek => _baseStream.CanSeek;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool CanWrite => false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Flush() => _baseStream.Flush();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override long Length
|
||||
=> (_baseStream.Length / Constants.CDROMSectorSize) * _isoSectorSize;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetLength(long value)
|
||||
=> throw new NotSupportedException("Setting the length of this stream is not supported.");
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
=> throw new NotSupportedException("Writing to this stream is not supported.");
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
_baseStream.Dispose();
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override long Position
|
||||
{
|
||||
// Get the position of the underlying ISO9660 stream
|
||||
get
|
||||
{
|
||||
// Get the user data location based on the current sector mode
|
||||
SetState(_position);
|
||||
|
||||
// Get the number of ISO sectors before current position
|
||||
long isoPosition = (_position / Constants.CDROMSectorSize) * _isoSectorSize;
|
||||
|
||||
// Add the within-sector position
|
||||
long remainder = _position % Constants.CDROMSectorSize;
|
||||
if (remainder > _userDataEnd)
|
||||
isoPosition += _isoSectorSize;
|
||||
else if (remainder > _userDataStart)
|
||||
isoPosition += remainder - _userDataStart;
|
||||
|
||||
return isoPosition;
|
||||
}
|
||||
set
|
||||
{
|
||||
// Seek to the underlying ISO9660 position
|
||||
Seek(value, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
int totalRead = 0;
|
||||
int remaining = count;
|
||||
|
||||
while (remaining > 0 && _position < _baseStream.Length)
|
||||
{
|
||||
// Determine location of current sector
|
||||
long baseStreamOffset = _position - (_position % Constants.CDROMSectorSize);
|
||||
|
||||
// Set the current sector's mode and user data location
|
||||
SetState(baseStreamOffset);
|
||||
|
||||
// Deal with case where base position is not in ISO stream
|
||||
long remainder = _position % Constants.CDROMSectorSize;
|
||||
long sectorOffset = remainder - _userDataStart;
|
||||
if (remainder < _userDataStart)
|
||||
{
|
||||
baseStreamOffset += _userDataStart;
|
||||
sectorOffset = 0;
|
||||
_position += _userDataStart;
|
||||
}
|
||||
else if (remainder >= _userDataEnd)
|
||||
{
|
||||
baseStreamOffset += Constants.CDROMSectorSize;
|
||||
sectorOffset = 0;
|
||||
_position += Constants.CDROMSectorSize - _userDataEnd + _userDataStart;
|
||||
}
|
||||
else
|
||||
{
|
||||
baseStreamOffset += remainder;
|
||||
}
|
||||
|
||||
// Sanity check on read location before seeking
|
||||
if (baseStreamOffset < 0 || baseStreamOffset > _baseStream.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(offset), "Attempted to seek outside the stream boundaries.");
|
||||
|
||||
// Seek to target position in base CDROM stream
|
||||
_baseStream.SeekIfPossible(baseStreamOffset, SeekOrigin.Begin);
|
||||
|
||||
// Read the remaining bytes, up to max of one ISO sector (2048 bytes)
|
||||
int bytesToRead = (int)Math.Min(remaining, _isoSectorSize - sectorOffset);
|
||||
|
||||
// Don't overshoot end of stream
|
||||
bytesToRead = (int)Math.Min(bytesToRead, _baseStream.Length - _position);
|
||||
|
||||
// Finish reading if no more bytes to be read
|
||||
if (bytesToRead <= 0)
|
||||
break;
|
||||
|
||||
// Read up to 2048 bytes from base CDROM stream
|
||||
int bytesRead = _baseStream.Read(buffer, offset + totalRead, bytesToRead);
|
||||
|
||||
// Update state for base stream
|
||||
_position = _baseStream.Position;
|
||||
if (bytesToRead == (_isoSectorSize - sectorOffset))
|
||||
_position += (Constants.CDROMSectorSize - _userDataEnd) + _userDataStart;
|
||||
|
||||
// Update state for ISO stream
|
||||
totalRead += bytesRead;
|
||||
remaining -= bytesRead;
|
||||
|
||||
if (bytesRead == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return totalRead;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
// Get the intended position for the ISO9660 stream
|
||||
long targetPosition = origin switch
|
||||
{
|
||||
SeekOrigin.Begin => offset,
|
||||
SeekOrigin.Current => Position + offset,
|
||||
SeekOrigin.End => Length + offset,
|
||||
_ => throw new ArgumentException("Invalid SeekOrigin.", nameof(origin)),
|
||||
};
|
||||
|
||||
// Get the number of ISO sectors before current position
|
||||
long newPosition = (targetPosition / _isoSectorSize) * Constants.CDROMSectorSize;
|
||||
|
||||
// Set the current sector's mode and user data location
|
||||
SetState(newPosition);
|
||||
|
||||
// Add the within-sector position
|
||||
newPosition += _userDataStart + (targetPosition % _isoSectorSize);
|
||||
if (newPosition < 0 || newPosition > _baseStream.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(offset), "Attempted to seek outside the stream boundaries.");
|
||||
|
||||
_position = _baseStream.SeekIfPossible(newPosition, SeekOrigin.Begin);
|
||||
return Position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the current stream state based on the location
|
||||
/// </summary>
|
||||
/// <param name="sectorLocation">Sector location to update from</param>
|
||||
private void SetState(long sectorLocation)
|
||||
{
|
||||
long current = _baseStream.Position;
|
||||
long modePosition = sectorLocation - (sectorLocation % Constants.CDROMSectorSize) + 15;
|
||||
|
||||
// Get the current sector mode
|
||||
_baseStream.SeekIfPossible(modePosition, SeekOrigin.Begin);
|
||||
_currentMode = _baseStream.GetSectorMode();
|
||||
|
||||
// Set the user data location variables
|
||||
_userDataStart = _currentMode.GetUserDataStart();
|
||||
_userDataEnd = _currentMode.GetUserDataEnd();
|
||||
// _isoSectorSize = _currentMode.GetUserDataSize();
|
||||
|
||||
// Reset the stream position
|
||||
_baseStream.SeekIfPossible(current, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.IO;
|
||||
using SabreTools.Data.Models.CDROM;
|
||||
using SabreTools.IO.Extensions;
|
||||
|
||||
namespace SabreTools.Data.Extensions
|
||||
{
|
||||
public static class CDROM
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the sector mode for a CD-ROM stream
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream to derive the sector mode from</param>
|
||||
/// <returns>Sector mode from the stream on success, <see cref="SectorMode.UNKNOWN"/> on error</returns>
|
||||
public static SectorMode GetSectorMode(this Stream stream)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte modeByte = stream.ReadByteValue();
|
||||
if (modeByte == 0)
|
||||
{
|
||||
return SectorMode.MODE0;
|
||||
}
|
||||
else if (modeByte == 1)
|
||||
{
|
||||
return SectorMode.MODE1;
|
||||
}
|
||||
else if (modeByte == 2)
|
||||
{
|
||||
stream.SeekIfPossible(2, SeekOrigin.Current);
|
||||
byte submode = stream.ReadByteValue();
|
||||
if ((submode & 0x20) == 0x20)
|
||||
return SectorMode.MODE2_FORM2;
|
||||
else
|
||||
return SectorMode.MODE2_FORM1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SectorMode.UNKNOWN;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore the actual error
|
||||
return SectorMode.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the user data size for a sector mode
|
||||
/// </summary>
|
||||
/// <param name="mode">Sector mode to get a value for</param>
|
||||
/// <returns>User data size, if possible</returns>
|
||||
public static long GetUserDataSize(this SectorMode mode)
|
||||
{
|
||||
return mode switch
|
||||
{
|
||||
SectorMode.UNKNOWN => Constants.Mode0DataSize,
|
||||
SectorMode.MODE0 => Constants.Mode0DataSize,
|
||||
SectorMode.MODE1 => Constants.Mode1DataSize,
|
||||
SectorMode.MODE2 => Constants.Mode0DataSize,
|
||||
SectorMode.MODE2_FORM1 => Constants.Mode2Form1DataSize,
|
||||
SectorMode.MODE2_FORM2 => Constants.Mode2Form2DataSize,
|
||||
_ => Constants.Mode0DataSize,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the user data end offset for a sector mode
|
||||
/// </summary>
|
||||
/// <param name="mode">Sector mode to get a value for</param>
|
||||
/// <returns>User data end offset, if possible</returns>
|
||||
public static long GetUserDataEnd(this SectorMode mode)
|
||||
{
|
||||
return mode switch
|
||||
{
|
||||
SectorMode.UNKNOWN => Constants.Mode0UserDataEnd,
|
||||
SectorMode.MODE0 => Constants.Mode0UserDataEnd, // TODO: Support flexible sector length (2352)
|
||||
SectorMode.MODE1 => Constants.Mode1UserDataEnd,
|
||||
SectorMode.MODE2 => Constants.Mode0UserDataEnd, // TODO: Support flexible sector length (2352)
|
||||
SectorMode.MODE2_FORM1 => Constants.Mode2Form1UserDataEnd,
|
||||
SectorMode.MODE2_FORM2 => Constants.Mode2Form2UserDataEnd, // TODO: Support flexible sector length (2348)
|
||||
_ => Constants.Mode0UserDataEnd,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the user data start offset for a sector mode
|
||||
/// </summary>
|
||||
/// <param name="mode">Sector mode to get a value for</param>
|
||||
/// <returns>User data start offset, if possible</returns>
|
||||
public static long GetUserDataStart(this SectorMode mode)
|
||||
{
|
||||
return mode switch
|
||||
{
|
||||
SectorMode.UNKNOWN => Constants.Mode0UserDataStart,
|
||||
SectorMode.MODE0 => Constants.Mode0UserDataStart,
|
||||
SectorMode.MODE1 => Constants.Mode1UserDataStart,
|
||||
SectorMode.MODE2 => Constants.Mode0UserDataStart,
|
||||
SectorMode.MODE2_FORM1 => Constants.Mode2Form1UserDataStart,
|
||||
SectorMode.MODE2_FORM2 => Constants.Mode2Form2UserDataStart,
|
||||
_ => Constants.Mode0UserDataStart,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a stream that provides only the user data of a CDROM stream
|
||||
/// </summary>
|
||||
public class ISO9660Stream : Stream
|
||||
{
|
||||
// Base CDROM stream (2352-byte sector)
|
||||
private readonly Stream _baseStream;
|
||||
|
||||
// State variables
|
||||
private long _position = 0;
|
||||
private SectorMode _currentMode = SectorMode.UNKNOWN;
|
||||
private long _userDataStart = Constants.Mode1UserDataStart;
|
||||
private long _userDataEnd = Constants.Mode1UserDataEnd;
|
||||
#pragma warning disable IDE0044
|
||||
private long _isoSectorSize = Constants.Mode1DataSize;
|
||||
#pragma warning restore IDE0044
|
||||
|
||||
public ISO9660Stream(Stream inputStream)
|
||||
{
|
||||
if (!inputStream.CanSeek || !inputStream.CanRead)
|
||||
throw new ArgumentException("Stream must be readable and seekable.", nameof(inputStream));
|
||||
|
||||
_baseStream = inputStream;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool CanRead => _baseStream.CanRead;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool CanSeek => _baseStream.CanSeek;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool CanWrite => false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Flush() => _baseStream.Flush();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override long Length
|
||||
=> _baseStream.Length / Constants.CDROMSectorSize * _isoSectorSize;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void SetLength(long value)
|
||||
=> throw new NotSupportedException("Setting the length of this stream is not supported.");
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
=> throw new NotSupportedException("Writing to this stream is not supported.");
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
_baseStream.Dispose();
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override long Position
|
||||
{
|
||||
// Get the position of the underlying ISO9660 stream
|
||||
get
|
||||
{
|
||||
// Get the user data location based on the current sector mode
|
||||
SetState(_position);
|
||||
|
||||
// Get the number of ISO sectors before current position
|
||||
long isoPosition = _position / Constants.CDROMSectorSize * _isoSectorSize;
|
||||
|
||||
// Add the within-sector position
|
||||
long remainder = _position % Constants.CDROMSectorSize;
|
||||
if (remainder > _userDataEnd)
|
||||
isoPosition += _isoSectorSize;
|
||||
else if (remainder > _userDataStart)
|
||||
isoPosition += remainder - _userDataStart;
|
||||
|
||||
return isoPosition;
|
||||
}
|
||||
set
|
||||
{
|
||||
// Seek to the underlying ISO9660 position
|
||||
Seek(value, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
int totalRead = 0;
|
||||
int remaining = count;
|
||||
|
||||
while (remaining > 0 && _position < _baseStream.Length)
|
||||
{
|
||||
// Determine location of current sector
|
||||
long baseStreamOffset = _position - (_position % Constants.CDROMSectorSize);
|
||||
|
||||
// Set the current sector's mode and user data location
|
||||
SetState(baseStreamOffset);
|
||||
|
||||
// Deal with case where base position is not in ISO stream
|
||||
long remainder = _position % Constants.CDROMSectorSize;
|
||||
long sectorOffset = remainder - _userDataStart;
|
||||
if (remainder < _userDataStart)
|
||||
{
|
||||
baseStreamOffset += _userDataStart;
|
||||
sectorOffset = 0;
|
||||
_position += _userDataStart;
|
||||
}
|
||||
else if (remainder >= _userDataEnd)
|
||||
{
|
||||
baseStreamOffset += Constants.CDROMSectorSize;
|
||||
sectorOffset = 0;
|
||||
_position += Constants.CDROMSectorSize - _userDataEnd + _userDataStart;
|
||||
}
|
||||
else
|
||||
{
|
||||
baseStreamOffset += remainder;
|
||||
}
|
||||
|
||||
// Sanity check on read location before seeking
|
||||
if (baseStreamOffset < 0 || baseStreamOffset > _baseStream.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(offset), "Attempted to seek outside the stream boundaries.");
|
||||
|
||||
// Seek to target position in base CDROM stream
|
||||
_baseStream.SeekIfPossible(baseStreamOffset, SeekOrigin.Begin);
|
||||
|
||||
// Read the remaining bytes, up to max of one ISO sector (2048 bytes)
|
||||
int bytesToRead = (int)Math.Min(remaining, _isoSectorSize - sectorOffset);
|
||||
|
||||
// Don't overshoot end of stream
|
||||
bytesToRead = (int)Math.Min(bytesToRead, _baseStream.Length - _position);
|
||||
|
||||
// Finish reading if no more bytes to be read
|
||||
if (bytesToRead <= 0)
|
||||
break;
|
||||
|
||||
// Read up to 2048 bytes from base CDROM stream
|
||||
int bytesRead = _baseStream.Read(buffer, offset + totalRead, bytesToRead);
|
||||
|
||||
// Update state for base stream
|
||||
_position = _baseStream.Position;
|
||||
if (bytesToRead == (_isoSectorSize - sectorOffset))
|
||||
_position += Constants.CDROMSectorSize - _userDataEnd + _userDataStart;
|
||||
|
||||
// Update state for ISO stream
|
||||
totalRead += bytesRead;
|
||||
remaining -= bytesRead;
|
||||
|
||||
if (bytesRead == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return totalRead;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
// Get the intended position for the ISO9660 stream
|
||||
long targetPosition = origin switch
|
||||
{
|
||||
SeekOrigin.Begin => offset,
|
||||
SeekOrigin.Current => Position + offset,
|
||||
SeekOrigin.End => Length + offset,
|
||||
_ => throw new ArgumentException("Invalid SeekOrigin.", nameof(origin)),
|
||||
};
|
||||
|
||||
// Get the number of ISO sectors before current position
|
||||
long newPosition = targetPosition / _isoSectorSize * Constants.CDROMSectorSize;
|
||||
|
||||
// Set the current sector's mode and user data location
|
||||
SetState(newPosition);
|
||||
|
||||
// Add the within-sector position
|
||||
newPosition += _userDataStart + (targetPosition % _isoSectorSize);
|
||||
if (newPosition < 0 || newPosition > _baseStream.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(offset), "Attempted to seek outside the stream boundaries.");
|
||||
|
||||
_position = _baseStream.SeekIfPossible(newPosition, SeekOrigin.Begin);
|
||||
return Position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the current stream state based on the location
|
||||
/// </summary>
|
||||
/// <param name="sectorLocation">Sector location to update from</param>
|
||||
private void SetState(long sectorLocation)
|
||||
{
|
||||
long current = _baseStream.Position;
|
||||
long modePosition = sectorLocation - (sectorLocation % Constants.CDROMSectorSize) + 15;
|
||||
|
||||
// Get the current sector mode
|
||||
_baseStream.SeekIfPossible(modePosition, SeekOrigin.Begin);
|
||||
_currentMode = _baseStream.GetSectorMode();
|
||||
|
||||
// Set the user data location variables
|
||||
_userDataStart = _currentMode.GetUserDataStart();
|
||||
_userDataEnd = _currentMode.GetUserDataEnd();
|
||||
// _isoSectorSize = _currentMode.GetUserDataSize();
|
||||
|
||||
// Reset the stream position
|
||||
_baseStream.SeekIfPossible(current, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static string? DecodeStreamName(this byte[]? input)
|
||||
{
|
||||
// Ignore invalid inputs
|
||||
if (input == null)
|
||||
if (input is null)
|
||||
return null;
|
||||
else if (input.Length == 0)
|
||||
return string.Empty;
|
||||
@@ -69,7 +69,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static string? DecodeStreamName(this string? input)
|
||||
{
|
||||
// Ignore invalid inputs
|
||||
if (input == null)
|
||||
if (input is null)
|
||||
return null;
|
||||
else if (input.Length == 0)
|
||||
return string.Empty;
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
using SabreTools.Data.Models.ISO9660;
|
||||
using SabreTools.Numerics;
|
||||
|
||||
namespace SabreTools.Data.Extensions
|
||||
{
|
||||
public static class ISO9660
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the logical block size from a sector length
|
||||
/// </summary>
|
||||
/// <param name="vd">Volume descriptor containing block information</param>
|
||||
/// <param name="sectorLength">Defined sector length</param>
|
||||
/// <returns>Size of a logical block</returns>
|
||||
public static short GetLogicalBlockSize(this VolumeDescriptor vd, short sectorLength)
|
||||
{
|
||||
BothInt16 blockSize;
|
||||
if (vd is PrimaryVolumeDescriptor pvd)
|
||||
blockSize = pvd.LogicalBlockSize;
|
||||
else if (vd is SupplementaryVolumeDescriptor svd)
|
||||
blockSize = svd.LogicalBlockSize;
|
||||
else
|
||||
return sectorLength;
|
||||
|
||||
// If the block size is inconsistent
|
||||
if (!blockSize.IsValid)
|
||||
{
|
||||
bool leValid = BlockSizeValid(blockSize.LittleEndian, sectorLength);
|
||||
bool beValid = BlockSizeValid(blockSize.BigEndian, sectorLength);
|
||||
|
||||
if (leValid && !beValid)
|
||||
blockSize = blockSize.LittleEndian;
|
||||
else if (beValid && !leValid)
|
||||
blockSize = blockSize.BigEndian;
|
||||
else
|
||||
return sectorLength;
|
||||
}
|
||||
|
||||
// Validate logical block size
|
||||
if (!BlockSizeValid(blockSize, sectorLength))
|
||||
blockSize = sectorLength;
|
||||
|
||||
return blockSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if a block size is valid
|
||||
/// </summary>
|
||||
/// <param name="blockSize">Block length to check</param>
|
||||
/// <param name="sectorLength">Defined sector length</param>
|
||||
/// <returns>True if the block length is valid, false otherwise</returns>
|
||||
private static bool BlockSizeValid(short blockSize, short sectorLength)
|
||||
=> blockSize >= 512 && blockSize <= sectorLength && (blockSize & (blockSize - 1)) == 0;
|
||||
}
|
||||
}
|
||||
using SabreTools.Data.Models.ISO9660;
|
||||
using SabreTools.Numerics;
|
||||
|
||||
namespace SabreTools.Data.Extensions
|
||||
{
|
||||
public static class ISO9660
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the logical block size from a sector length
|
||||
/// </summary>
|
||||
/// <param name="vd">Volume descriptor containing block information</param>
|
||||
/// <param name="sectorLength">Defined sector length</param>
|
||||
/// <returns>Size of a logical block</returns>
|
||||
public static short GetLogicalBlockSize(this VolumeDescriptor vd, short sectorLength)
|
||||
{
|
||||
BothInt16 blockSize;
|
||||
if (vd is PrimaryVolumeDescriptor pvd)
|
||||
blockSize = pvd.LogicalBlockSize;
|
||||
else if (vd is SupplementaryVolumeDescriptor svd)
|
||||
blockSize = svd.LogicalBlockSize;
|
||||
else
|
||||
return sectorLength;
|
||||
|
||||
// If the block size is inconsistent
|
||||
if (!blockSize.IsValid)
|
||||
{
|
||||
bool leValid = BlockSizeValid(blockSize.LittleEndian, sectorLength);
|
||||
bool beValid = BlockSizeValid(blockSize.BigEndian, sectorLength);
|
||||
|
||||
if (leValid && !beValid)
|
||||
blockSize = blockSize.LittleEndian;
|
||||
else if (beValid && !leValid)
|
||||
blockSize = blockSize.BigEndian;
|
||||
else
|
||||
return sectorLength;
|
||||
}
|
||||
|
||||
// Validate logical block size
|
||||
if (!BlockSizeValid(blockSize, sectorLength))
|
||||
blockSize = sectorLength;
|
||||
|
||||
return blockSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if a block size is valid
|
||||
/// </summary>
|
||||
/// <param name="blockSize">Block length to check</param>
|
||||
/// <param name="sectorLength">Defined sector length</param>
|
||||
/// <returns>True if the block length is valid, false otherwise</returns>
|
||||
private static bool BlockSizeValid(short blockSize, short sectorLength)
|
||||
=> blockSize >= 512 && blockSize <= sectorLength && (blockSize & (blockSize - 1)) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static bool IsCompressed(this FileDescriptor? fileDescriptor)
|
||||
{
|
||||
// Ignore invalid descriptors
|
||||
if (fileDescriptor == null)
|
||||
if (fileDescriptor is null)
|
||||
return true;
|
||||
|
||||
#if NET20 || NET35
|
||||
@@ -32,7 +32,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static bool IsInvalid(this FileDescriptor? fileDescriptor)
|
||||
{
|
||||
// Ignore invalid descriptors
|
||||
if (fileDescriptor == null)
|
||||
if (fileDescriptor is null)
|
||||
return true;
|
||||
|
||||
#if NET20 || NET35
|
||||
@@ -50,7 +50,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static bool IsObfuscated(this FileDescriptor? fileDescriptor)
|
||||
{
|
||||
// Ignore invalid descriptors
|
||||
if (fileDescriptor == null)
|
||||
if (fileDescriptor is null)
|
||||
return false;
|
||||
|
||||
#if NET20 || NET35
|
||||
@@ -68,7 +68,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static bool IsSplit(this FileDescriptor? fileDescriptor)
|
||||
{
|
||||
// Ignore invalid descriptors
|
||||
if (fileDescriptor == null)
|
||||
if (fileDescriptor is null)
|
||||
return false;
|
||||
|
||||
#if NET20 || NET35
|
||||
@@ -90,7 +90,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static int GetMajorVersion(this Cabinet? cabinet)
|
||||
{
|
||||
// Ignore invalid cabinets
|
||||
if (cabinet == null)
|
||||
if (cabinet is null)
|
||||
return -1;
|
||||
|
||||
return cabinet.CommonHeader.GetMajorVersion();
|
||||
@@ -104,7 +104,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static int GetMajorVersion(this CommonHeader? commonHeader)
|
||||
{
|
||||
// Ignore invalid headers
|
||||
if (commonHeader == null)
|
||||
if (commonHeader is null)
|
||||
return -1;
|
||||
|
||||
uint majorVersion = commonHeader.Version;
|
||||
|
||||
@@ -8,6 +8,7 @@ using SabreTools.Data.Models.PortableExecutable;
|
||||
using SabreTools.Data.Models.PortableExecutable.Resource.Entries;
|
||||
using SabreTools.IO.Extensions;
|
||||
|
||||
#pragma warning disable IDE0017 // Simplify object initialization
|
||||
namespace SabreTools.Data.Extensions
|
||||
{
|
||||
public static class PortableExecutable
|
||||
@@ -30,7 +31,7 @@ namespace SabreTools.Data.Extensions
|
||||
|
||||
// If the RVA matches a section start exactly, use that
|
||||
var matchingSection = Array.Find(sections, s => s.VirtualAddress == rva);
|
||||
if (matchingSection != null)
|
||||
if (matchingSection is not null)
|
||||
return rva - matchingSection.VirtualAddress + matchingSection.PointerToRawData;
|
||||
|
||||
// Loop through all of the sections
|
||||
@@ -72,7 +73,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static int ContainingSectionIndex(this uint rva, SectionHeader[] sections)
|
||||
{
|
||||
// If we have an invalid section table, we can't do anything
|
||||
if (sections == null || sections.Length == 0)
|
||||
if (sections is null || sections.Length == 0)
|
||||
return -1;
|
||||
|
||||
// If the RVA is 0, we just return -1 because it's invalid
|
||||
@@ -159,7 +160,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static AcceleratorTableEntry[]? AsAcceleratorTableResource(this Models.PortableExecutable.Resource.DataEntry? entry)
|
||||
{
|
||||
// If we have data that's invalid for this resource type, we can't do anything
|
||||
if (entry?.Data == null || entry.Data.Length % 8 != 0)
|
||||
if (entry?.Data is null || entry.Data.Length % 8 != 0)
|
||||
return null;
|
||||
|
||||
// Get the number of entries
|
||||
@@ -188,7 +189,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static AssemblyManifest? AsAssemblyManifest(this Models.PortableExecutable.Resource.DataEntry? entry)
|
||||
{
|
||||
// If we have an invalid entry, just skip
|
||||
if (entry?.Data == null)
|
||||
if (entry?.Data is null)
|
||||
return null;
|
||||
|
||||
try
|
||||
@@ -210,7 +211,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static DialogBoxResource? AsDialogBox(this Models.PortableExecutable.Resource.DataEntry? entry)
|
||||
{
|
||||
// If we have an invalid entry, just skip
|
||||
if (entry?.Data == null)
|
||||
if (entry?.Data is null)
|
||||
return null;
|
||||
|
||||
// Initialize the iterator
|
||||
@@ -687,7 +688,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static FontGroupHeader? AsFontGroup(this Models.PortableExecutable.Resource.DataEntry? entry)
|
||||
{
|
||||
// If we have an invalid entry, just skip
|
||||
if (entry?.Data == null)
|
||||
if (entry?.Data is null)
|
||||
return null;
|
||||
|
||||
// Initialize the iterator
|
||||
@@ -756,7 +757,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static MenuResource? AsMenu(this Models.PortableExecutable.Resource.DataEntry? entry)
|
||||
{
|
||||
// If we have an invalid entry, just skip
|
||||
if (entry?.Data == null)
|
||||
if (entry?.Data is null)
|
||||
return null;
|
||||
|
||||
// Initialize the iterator
|
||||
@@ -830,7 +831,7 @@ namespace SabreTools.Data.Extensions
|
||||
// Align to the DWORD boundary if we're not at the end
|
||||
entry.Data.AlignToBoundary(ref offset, 4);
|
||||
|
||||
if (menuItem == null)
|
||||
if (menuItem is null)
|
||||
return null;
|
||||
|
||||
menuItems.Add(menuItem);
|
||||
@@ -852,7 +853,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static MessageResourceData? AsMessageResourceData(this Models.PortableExecutable.Resource.DataEntry? entry)
|
||||
{
|
||||
// If we have an invalid entry, just skip
|
||||
if (entry?.Data == null)
|
||||
if (entry?.Data is null)
|
||||
return null;
|
||||
|
||||
// Initialize the iterator
|
||||
@@ -884,7 +885,7 @@ namespace SabreTools.Data.Extensions
|
||||
for (int i = 0; i < messageResourceData.Blocks.Length; i++)
|
||||
{
|
||||
var messageResourceBlock = messageResourceData.Blocks[i];
|
||||
if (messageResourceBlock == null)
|
||||
if (messageResourceBlock is null)
|
||||
continue;
|
||||
|
||||
offset = (int)messageResourceBlock.OffsetToEntries;
|
||||
@@ -929,7 +930,7 @@ namespace SabreTools.Data.Extensions
|
||||
stringFileInfo.Key = data.ReadNullTerminatedUnicodeString(ref offset) ?? string.Empty;
|
||||
if (stringFileInfo.Key != "StringFileInfo")
|
||||
{
|
||||
offset -= 6 + ((stringFileInfo.Key?.Length ?? 0 + 1) * 2);
|
||||
offset -= 6 + (((stringFileInfo.Key?.Length ?? 0) + 1) * 2);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -996,7 +997,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static Dictionary<int, string?>? AsStringTable(this Models.PortableExecutable.Resource.DataEntry? entry)
|
||||
{
|
||||
// If we have an invalid entry, just skip
|
||||
if (entry?.Data == null)
|
||||
if (entry?.Data is null)
|
||||
return null;
|
||||
|
||||
// Initialize the iterators
|
||||
@@ -1009,7 +1010,7 @@ namespace SabreTools.Data.Extensions
|
||||
while (offset < entry.Data.Length)
|
||||
{
|
||||
string? stringValue = entry.Data.ReadPrefixedUnicodeString(ref offset);
|
||||
if (stringValue != null)
|
||||
if (stringValue is not null)
|
||||
{
|
||||
stringValue = stringValue.Replace("\n", "\\n").Replace("\r", newValue: "\\r");
|
||||
stringTable[stringIndex++] = stringValue;
|
||||
@@ -1053,7 +1054,7 @@ namespace SabreTools.Data.Extensions
|
||||
varData.Key = data.ReadNullTerminatedUnicodeString(ref offset) ?? string.Empty;
|
||||
if (varData.Key != "Translation")
|
||||
{
|
||||
offset -= 6 + ((varData.Key?.Length ?? 0 + 1) * 2);
|
||||
offset -= 6 + (((varData.Key?.Length ?? 0) + 1) * 2);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1088,7 +1089,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static VersionInfo? AsVersionInfo(this Models.PortableExecutable.Resource.DataEntry? entry)
|
||||
{
|
||||
// If we have an invalid entry, just skip
|
||||
if (entry?.Data == null)
|
||||
if (entry?.Data is null)
|
||||
return null;
|
||||
|
||||
// Initialize the iterator
|
||||
@@ -1346,7 +1347,7 @@ namespace SabreTools.Data.Extensions
|
||||
private static bool AlignToBoundary(this byte[]? input, ref int offset, byte alignment)
|
||||
{
|
||||
// If the array is invalid
|
||||
if (input == null || input.Length == 0)
|
||||
if (input is null || input.Length == 0)
|
||||
return false;
|
||||
|
||||
// If already at the end of the array
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace SabreTools.Data.Extensions
|
||||
/// </summary>
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, char? value, string prefixString)
|
||||
{
|
||||
string valueString = (value == null ? "[NULL]" : value.Value.ToString());
|
||||
string valueString = value is null ? "[NULL]" : value.Value.ToString();
|
||||
return sb.AppendLine($"{prefixString}: {valueString}");
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ namespace SabreTools.Data.Extensions
|
||||
/// </summary>
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, byte[]? value, string prefixString)
|
||||
{
|
||||
string valueString = (value == null ? "[NULL]" : BitConverter.ToString(value).Replace('-', ' '));
|
||||
string valueString = value is null ? "[NULL]" : BitConverter.ToString(value).Replace('-', ' ');
|
||||
if (valueString.Length == 0)
|
||||
return sb.AppendLine($"{prefixString}: [EMPTY]");
|
||||
|
||||
@@ -268,7 +268,7 @@ namespace SabreTools.Data.Extensions
|
||||
/// </summary>
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, byte[]? value, string prefixString, Encoding encoding)
|
||||
{
|
||||
string valueString = (value == null ? "[NULL]" : encoding.GetString(value).Replace("\0", string.Empty));
|
||||
string valueString = value is null ? "[NULL]" : encoding.GetString(value).Replace("\0", string.Empty);
|
||||
if (valueString.Length == 0)
|
||||
return sb.AppendLine($"{prefixString}: [EMPTY]");
|
||||
|
||||
@@ -281,7 +281,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, char[]? value, string prefixString)
|
||||
{
|
||||
string valueString = "[NULL]";
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
{
|
||||
var valueArr = Array.ConvertAll(value, c => c.ToString());
|
||||
valueString = string.Join(", ", valueArr);
|
||||
@@ -299,7 +299,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, short[]? value, string prefixString)
|
||||
{
|
||||
string valueString = "[NULL]";
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
{
|
||||
var valueArr = Array.ConvertAll(value, s => s.ToString());
|
||||
valueString = string.Join(", ", valueArr);
|
||||
@@ -317,7 +317,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, ushort[]? value, string prefixString)
|
||||
{
|
||||
string valueString = "[NULL]";
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
{
|
||||
var valueArr = Array.ConvertAll(value, u => u.ToString());
|
||||
valueString = string.Join(", ", valueArr);
|
||||
@@ -335,7 +335,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, int[]? value, string prefixString)
|
||||
{
|
||||
string valueString = "[NULL]";
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
{
|
||||
var valueArr = Array.ConvertAll(value, i => i.ToString());
|
||||
valueString = string.Join(", ", valueArr);
|
||||
@@ -353,7 +353,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, uint[]? value, string prefixString)
|
||||
{
|
||||
string valueString = "[NULL]";
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
{
|
||||
var valueArr = Array.ConvertAll(value, u => u.ToString());
|
||||
valueString = string.Join(", ", valueArr);
|
||||
@@ -371,7 +371,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, float[]? value, string prefixString)
|
||||
{
|
||||
string valueString = "[NULL]";
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
{
|
||||
var valueArr = Array.ConvertAll(value, u => u.ToString());
|
||||
valueString = string.Join(", ", valueArr);
|
||||
@@ -389,7 +389,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, long[]? value, string prefixString)
|
||||
{
|
||||
string valueString = "[NULL]";
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
{
|
||||
var valueArr = Array.ConvertAll(value, l => l.ToString());
|
||||
valueString = string.Join(", ", valueArr);
|
||||
@@ -407,7 +407,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, ulong[]? value, string prefixString)
|
||||
{
|
||||
string valueString = "[NULL]";
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
{
|
||||
var valueArr = Array.ConvertAll(value, u => u.ToString());
|
||||
valueString = string.Join(", ", valueArr);
|
||||
@@ -425,7 +425,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, double[]? value, string prefixString)
|
||||
{
|
||||
string valueString = "[NULL]";
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
{
|
||||
var valueArr = Array.ConvertAll(value, u => u.ToString());
|
||||
valueString = string.Join(", ", valueArr);
|
||||
@@ -443,7 +443,7 @@ namespace SabreTools.Data.Extensions
|
||||
public static StringBuilder AppendLine(this StringBuilder sb, Guid[]? value, string prefixString)
|
||||
{
|
||||
string valueString = "[NULL]";
|
||||
if (value != null)
|
||||
if (value is not null)
|
||||
{
|
||||
var valueArr = Array.ConvertAll(value, g => g.ToString());
|
||||
valueString = string.Join(", ", valueArr);
|
||||
|
||||
@@ -148,6 +148,27 @@ namespace SabreTools.Data.Extensions
|
||||
formatBuilder.Append($", Value: {Encoding.Unicode.GetString(valueAsByteArray)}");
|
||||
break;
|
||||
|
||||
// Unimplemented
|
||||
case ASN1Type.V_ASN1_EOC:
|
||||
case ASN1Type.V_ASN1_NULL:
|
||||
case ASN1Type.V_ASN1_OBJECT_DESCRIPTOR:
|
||||
case ASN1Type.V_ASN1_EXTERNAL:
|
||||
case ASN1Type.V_ASN1_REAL:
|
||||
case ASN1Type.V_ASN1_ENUMERATED:
|
||||
case ASN1Type.V_ASN1_SEQUENCE:
|
||||
case ASN1Type.V_ASN1_SET:
|
||||
case ASN1Type.V_ASN1_NUMERICSTRING:
|
||||
case ASN1Type.V_ASN1_VIDEOTEXSTRING:
|
||||
case ASN1Type.V_ASN1_GENERALIZEDTIME:
|
||||
case ASN1Type.V_ASN1_GRAPHICSTRING:
|
||||
case ASN1Type.V_ASN1_ISO64STRING:
|
||||
case ASN1Type.V_ASN1_GENERALSTRING:
|
||||
case ASN1Type.V_ASN1_UNIVERSALSTRING:
|
||||
case ASN1Type.V_ASN1_PRIMITIVE_TAG:
|
||||
case ASN1Type.V_ASN1_CONSTRUCTED:
|
||||
case ASN1Type.V_ASN1_APPLICATION:
|
||||
case ASN1Type.V_ASN1_CONTEXT_SPECIFIC:
|
||||
case ASN1Type.V_ASN1_PRIVATE:
|
||||
default:
|
||||
formatBuilder.Append($", Value: {BitConverter.ToString(valueAsByteArray).Replace('-', ' ')}");
|
||||
break;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
#pragma warning disable SYSLIB1045 // Convert to 'GeneratedRegexAttribute'
|
||||
namespace SabreTools.Data.Extensions
|
||||
{
|
||||
public static class WiseScript
|
||||
|
||||
@@ -5,6 +5,11 @@ namespace SabreTools.Serialization.Interfaces
|
||||
/// </summary>
|
||||
public interface IByteReader<TModel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Enable outputting debug information
|
||||
/// </summary>
|
||||
public bool Debug { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Deserialize a byte array into <typeparamref name="TModel"/>
|
||||
/// </summary>
|
||||
@@ -12,6 +17,6 @@ namespace SabreTools.Serialization.Interfaces
|
||||
/// <param name="data">Byte array to parse</param>
|
||||
/// <param name="offset">Offset into the byte array</param>
|
||||
/// <returns>Filled object on success, null on error</returns>
|
||||
TModel? Deserialize(byte[]? data, int offset);
|
||||
public TModel? Deserialize(byte[]? data, int offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,17 @@ namespace SabreTools.Serialization.Interfaces
|
||||
/// </summary>
|
||||
public interface IByteWriter<TModel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Enable outputting debug information
|
||||
/// </summary>
|
||||
public bool Debug { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a <typeparamref name="TModel"/> into a byte array
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to serialize from</typeparam>
|
||||
/// <param name="obj">Data to serialize</param>
|
||||
/// <returns>Filled object on success, null on error</returns>
|
||||
byte[]? SerializeArray(TModel? obj);
|
||||
public byte[]? SerializeArray(TModel? obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,11 @@ namespace SabreTools.Serialization.Interfaces
|
||||
/// </summary>
|
||||
public interface ICrossModel<TSource, TDest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Enable outputting debug information
|
||||
/// </summary>
|
||||
public bool Debug { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Deserialize a <typeparamref name="TDest"/> into <typeparamref name="TSource"/>
|
||||
/// </summary>
|
||||
@@ -12,7 +17,7 @@ namespace SabreTools.Serialization.Interfaces
|
||||
/// <typeparam name="U">Type of object to deserialize from</typeparam>
|
||||
/// <param name="obj">Object to deserialize from</param>
|
||||
/// <returns>Filled object on success, null on error</returns>
|
||||
TSource? Deserialize(TDest? obj);
|
||||
public TSource? Deserialize(TDest? obj);
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a <typeparamref name="TSource"/> into <typeparamref name="TDest"/>
|
||||
@@ -21,6 +26,6 @@ namespace SabreTools.Serialization.Interfaces
|
||||
/// <typeparam name="U">Type of object to serialize to</typeparam>
|
||||
/// <param name="obj">Object to serialize from</param>
|
||||
/// <returns>Filled object on success, null on error</returns>
|
||||
TDest? Serialize(TSource? obj);
|
||||
public TDest? Serialize(TSource? obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,17 @@ namespace SabreTools.Serialization.Interfaces
|
||||
/// </summary>
|
||||
public interface IFileReader<TModel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Enable outputting debug information
|
||||
/// </summary>
|
||||
public bool Debug { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Deserialize a file into <typeparamref name="TModel"/>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to deserialize to</typeparam>
|
||||
/// <param name="path">Path to deserialize from</param>
|
||||
/// <returns>Filled object on success, null on error</returns>
|
||||
TModel? Deserialize(string? path);
|
||||
public TModel? Deserialize(string? path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,11 @@ namespace SabreTools.Serialization.Interfaces
|
||||
/// </summary>
|
||||
public interface IFileWriter<TModel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Enable outputting debug information
|
||||
/// </summary>
|
||||
public bool Debug { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a <typeparamref name="TModel"/> into a file
|
||||
/// </summary>
|
||||
@@ -12,6 +17,6 @@ namespace SabreTools.Serialization.Interfaces
|
||||
/// <param name="obj">Data to serialize</param>
|
||||
/// <param name="path">Path to the file to serialize to</param>
|
||||
/// <returns>True on successful serialization, false otherwise</returns>
|
||||
bool SerializeFile(TModel? obj, string? path);
|
||||
public bool SerializeFile(TModel? obj, string? path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,17 @@ namespace SabreTools.Serialization.Interfaces
|
||||
/// </summary>
|
||||
public interface IStreamReader<TModel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Enable outputting debug information
|
||||
/// </summary>
|
||||
public bool Debug { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Deserialize a Stream into <typeparamref name="TModel"/>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to deserialize to</typeparam>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled object on success, null on error</returns>
|
||||
TModel? Deserialize(System.IO.Stream? data);
|
||||
public TModel? Deserialize(System.IO.Stream? data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,17 @@ namespace SabreTools.Serialization.Interfaces
|
||||
/// </summary>
|
||||
public interface IStreamWriter<TModel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Enable outputting debug information
|
||||
/// </summary>
|
||||
public bool Debug { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a <typeparamref name="TModel"/> into a Stream
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to serialize from</typeparam>
|
||||
/// <param name="obj">Data to serialize</param>
|
||||
/// <returns>Filled object on success, null on error</returns>
|
||||
System.IO.Stream? SerializeStream(TModel? obj);
|
||||
public System.IO.Stream? SerializeStream(TModel? obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,17 @@ namespace SabreTools.Serialization.Interfaces
|
||||
/// </summary>
|
||||
public interface IStringReader<TModel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Enable outputting debug information
|
||||
/// </summary>
|
||||
public bool Debug { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Deserialize a string into <typeparamref name="TModel"/>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to deserialize to</typeparam>
|
||||
/// <param name="str">String to deserialize from</param>
|
||||
/// <returns>Filled object on success, null on error</returns>
|
||||
TModel? Deserialize(string? str);
|
||||
public TModel? Deserialize(string? str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,17 @@ namespace SabreTools.Serialization.Interfaces
|
||||
/// </summary>
|
||||
public interface IStringWriter<TModel>
|
||||
{
|
||||
/// <summary>
|
||||
/// Enable outputting debug information
|
||||
/// </summary>
|
||||
public bool Debug { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Serialize a <typeparamref name="TModel"/> into a string
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to serialize from</typeparam>
|
||||
/// <param name="obj">Data to serialize</param>
|
||||
/// <returns>Filled string on successful serialization, null otherwise</returns>
|
||||
string? Serialize(TModel? obj);
|
||||
public string? Serialize(TModel? obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
|
||||
#pragma warning disable CA1069 // Enums values should not be duplicated
|
||||
namespace SabreTools.Data.Models.ASN1
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
#pragma warning disable IDE1006 // Naming Styles
|
||||
namespace SabreTools.Data.Models.ArchiveDotOrg
|
||||
{
|
||||
[XmlRoot("file")]
|
||||
@@ -202,4 +203,4 @@ namespace SabreTools.Data.Models.ArchiveDotOrg
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,4 @@ namespace SabreTools.Data.Models.ArchiveDotOrg
|
||||
[XmlElement("file")]
|
||||
public File[]? File { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,4 @@ namespace SabreTools.Data.Models.AttractMode
|
||||
|
||||
public Row[]? Row { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,4 +50,4 @@ namespace SabreTools.Data.Models.AttractMode
|
||||
|
||||
public string? FileIsAvailable { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace SabreTools.Data.Models.BSP
|
||||
public const int MAX_MAP_MODELS = 400;
|
||||
public const int MAX_MAP_BRUSHES = 4096;
|
||||
public const int MAX_MAP_ENTITIES = 1024;
|
||||
public const int MAX_MAP_ENTSTRING = (128 * 1024);
|
||||
public const int MAX_MAP_ENTSTRING = 128 * 1024;
|
||||
|
||||
public const int MAX_MAP_PLANES = 32767;
|
||||
public const int MAX_MAP_NODES = 32767;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace SabreTools.Data.Models.BSP
|
||||
/// related to the properties of a particular triangle in the
|
||||
/// displacement mesh.
|
||||
/// </summary>
|
||||
/// <see href="https://developer.valvesoftware.com/wiki/BSP_(Source)"/>
|
||||
/// <see href="https://developer.valvesoftware.com/wiki/BSP_(Source)"/>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public sealed class DispTri
|
||||
{
|
||||
@@ -16,4 +16,4 @@ namespace SabreTools.Data.Models.BSP
|
||||
/// </summary>
|
||||
public DispTriTag Tags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
|
||||
#pragma warning disable CA1069 // Enums values should not be duplicated
|
||||
namespace SabreTools.Data.Models.BSP
|
||||
{
|
||||
/// <see href="https://developer.valvesoftware.com/wiki/BSP_(GoldSrc)"/>
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
namespace SabreTools.Data.Models.CDROM
|
||||
{
|
||||
/// <summary>
|
||||
/// A CD-ROM disc image, made up of data sectors, ISO 10149 / ECMA-130
|
||||
/// Intentionally not a mixed-mode CD disc image, pure CD-ROM disc (no audio sectors)
|
||||
/// This model intentionally does not take tracks into consideration
|
||||
/// </summary>
|
||||
/// <see href="https://ecma-international.org/wp-content/uploads/ECMA-130_2nd_edition_june_1996.pdf"/>
|
||||
public sealed class CDROM
|
||||
{
|
||||
/// <summary>
|
||||
/// CD-ROM data sectors
|
||||
/// </summary>
|
||||
public DataSector[] Sectors { get; set; } = [];
|
||||
}
|
||||
}
|
||||
namespace SabreTools.Data.Models.CDROM
|
||||
{
|
||||
/// <summary>
|
||||
/// A CD-ROM disc image, made up of data sectors, ISO 10149 / ECMA-130
|
||||
/// Intentionally not a mixed-mode CD disc image, pure CD-ROM disc (no audio sectors)
|
||||
/// This model intentionally does not take tracks into consideration
|
||||
/// </summary>
|
||||
/// <see href="https://ecma-international.org/wp-content/uploads/ECMA-130_2nd_edition_june_1996.pdf"/>
|
||||
public sealed class CDROM
|
||||
{
|
||||
/// <summary>
|
||||
/// CD-ROM data sectors
|
||||
/// </summary>
|
||||
public DataSector[] Sectors { get; set; } = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
namespace SabreTools.Data.Models.CDROM
|
||||
{
|
||||
/// <summary>
|
||||
/// CDROM constant values
|
||||
/// </summary>
|
||||
/// <see href="https://ecma-international.org/wp-content/uploads/ECMA-130_2nd_edition_june_1996.pdf"/>
|
||||
public static class Constants
|
||||
{
|
||||
/// <summary>
|
||||
/// Size of a complete CDROM data sector
|
||||
/// </summary>
|
||||
public const long CDROMSectorSize = 2352;
|
||||
|
||||
/// <summary>
|
||||
/// Size of user data length for Mode0 / Mode2 Formless
|
||||
/// </summary>
|
||||
public const long Mode0DataSize = 2336;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode0 sector where user data starts
|
||||
/// </summary>
|
||||
public const long Mode0UserDataStart = 16;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode0 sector where user data ends
|
||||
/// </summary>
|
||||
public const long Mode0UserDataEnd = 2064;
|
||||
|
||||
/// <summary>
|
||||
/// Size of user data length for Mode1
|
||||
/// </summary>
|
||||
public const long Mode1DataSize = 2048;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode1 sector where user data starts
|
||||
/// </summary>
|
||||
public const long Mode1UserDataStart = 16;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode1 sector where user data ends
|
||||
/// </summary>
|
||||
public const long Mode1UserDataEnd = 2064;
|
||||
|
||||
/// <summary>
|
||||
/// Size of user data length for Mode2 Form1
|
||||
/// </summary>
|
||||
public const long Mode2Form1DataSize = 2048;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode2 Form1 sector where user data starts
|
||||
/// </summary>
|
||||
public const long Mode2Form1UserDataStart = 24;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode2 Form1 sector where user data ends
|
||||
/// </summary>
|
||||
public const long Mode2Form1UserDataEnd = 2072;
|
||||
|
||||
/// <summary>
|
||||
/// Size of user data length for Mode2 Form2
|
||||
/// </summary>
|
||||
public const long Mode2Form2DataSize = 2324;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode2 Form2 sector where user data starts
|
||||
/// </summary>
|
||||
public const long Mode2Form2UserDataStart = 24;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode2 Form2 sector where user data ends
|
||||
/// </summary>
|
||||
public const long Mode2Form2UserDataEnd = 2072;
|
||||
}
|
||||
}
|
||||
namespace SabreTools.Data.Models.CDROM
|
||||
{
|
||||
/// <summary>
|
||||
/// CDROM constant values
|
||||
/// </summary>
|
||||
/// <see href="https://ecma-international.org/wp-content/uploads/ECMA-130_2nd_edition_june_1996.pdf"/>
|
||||
public static class Constants
|
||||
{
|
||||
/// <summary>
|
||||
/// Size of a complete CDROM data sector
|
||||
/// </summary>
|
||||
public const long CDROMSectorSize = 2352;
|
||||
|
||||
/// <summary>
|
||||
/// Size of user data length for Mode0 / Mode2 Formless
|
||||
/// </summary>
|
||||
public const long Mode0DataSize = 2336;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode0 sector where user data starts
|
||||
/// </summary>
|
||||
public const long Mode0UserDataStart = 16;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode0 sector where user data ends
|
||||
/// </summary>
|
||||
public const long Mode0UserDataEnd = 2064;
|
||||
|
||||
/// <summary>
|
||||
/// Size of user data length for Mode1
|
||||
/// </summary>
|
||||
public const long Mode1DataSize = 2048;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode1 sector where user data starts
|
||||
/// </summary>
|
||||
public const long Mode1UserDataStart = 16;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode1 sector where user data ends
|
||||
/// </summary>
|
||||
public const long Mode1UserDataEnd = 2064;
|
||||
|
||||
/// <summary>
|
||||
/// Size of user data length for Mode2 Form1
|
||||
/// </summary>
|
||||
public const long Mode2Form1DataSize = 2048;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode2 Form1 sector where user data starts
|
||||
/// </summary>
|
||||
public const long Mode2Form1UserDataStart = 24;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode2 Form1 sector where user data ends
|
||||
/// </summary>
|
||||
public const long Mode2Form1UserDataEnd = 2072;
|
||||
|
||||
/// <summary>
|
||||
/// Size of user data length for Mode2 Form2
|
||||
/// </summary>
|
||||
public const long Mode2Form2DataSize = 2324;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode2 Form2 sector where user data starts
|
||||
/// </summary>
|
||||
public const long Mode2Form2UserDataStart = 24;
|
||||
|
||||
/// <summary>
|
||||
/// Offset in a Mode2 Form2 sector where user data ends
|
||||
/// </summary>
|
||||
public const long Mode2Form2UserDataEnd = 2072;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
namespace SabreTools.Data.Models.CDROM
|
||||
{
|
||||
/// <summary>
|
||||
/// A CD-ROM data sector
|
||||
/// </summary>
|
||||
/// <see href="https://ecma-international.org/wp-content/uploads/ECMA-130_2nd_edition_june_1996.pdf"/>
|
||||
public abstract class DataSector : ISO9660.Sector
|
||||
{
|
||||
/// <summary>
|
||||
/// Sync pattern, 12 bytes
|
||||
/// </summary>
|
||||
public byte[] SyncPattern { get; set; } = new byte[12];
|
||||
|
||||
/// <summary>
|
||||
/// Sector Address, 3 bytes
|
||||
/// </summary>
|
||||
public byte[] Address { get; set; } = new byte[3];
|
||||
|
||||
/// <summary>
|
||||
/// CD-ROM mode
|
||||
/// </summary>
|
||||
public byte Mode { get; set; }
|
||||
}
|
||||
}
|
||||
namespace SabreTools.Data.Models.CDROM
|
||||
{
|
||||
/// <summary>
|
||||
/// A CD-ROM data sector
|
||||
/// </summary>
|
||||
/// <see href="https://ecma-international.org/wp-content/uploads/ECMA-130_2nd_edition_june_1996.pdf"/>
|
||||
public abstract class DataSector : ISO9660.Sector
|
||||
{
|
||||
/// <summary>
|
||||
/// Sync pattern, 12 bytes
|
||||
/// </summary>
|
||||
public byte[] SyncPattern { get; set; } = new byte[12];
|
||||
|
||||
/// <summary>
|
||||
/// Sector Address, 3 bytes
|
||||
/// </summary>
|
||||
public byte[] Address { get; set; } = new byte[3];
|
||||
|
||||
/// <summary>
|
||||
/// CD-ROM mode
|
||||
/// </summary>
|
||||
public byte Mode { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
namespace SabreTools.Data.Models.CDROM
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum for a CD-ROM's sector mode
|
||||
/// Explicitly does not contain non-CD-ROM modes like AUDIO, CDG, CDI, and length-specific modes
|
||||
/// </summary>
|
||||
/// <see href="https://ecma-international.org/wp-content/uploads/ECMA-130_2nd_edition_june_1996.pdf"/>
|
||||
public enum SectorMode
|
||||
{
|
||||
/// <summary>
|
||||
/// CD-ROM Unknown Mode
|
||||
/// </summary>
|
||||
UNKNOWN,
|
||||
|
||||
/// <summary>
|
||||
/// CD-ROM Mode 0 (All bytes after header are 0x00)
|
||||
/// </summary>
|
||||
MODE0,
|
||||
|
||||
/// <summary>
|
||||
/// CD-ROM Mode 1
|
||||
/// </summary>
|
||||
MODE1,
|
||||
|
||||
/// <summary>
|
||||
/// CD-ROM Mode 2 (Formless)
|
||||
/// </summary>
|
||||
MODE2,
|
||||
|
||||
/// <summary>
|
||||
/// CD-ROM XA Mode 2 Form 1
|
||||
/// </summary>
|
||||
MODE2_FORM1,
|
||||
|
||||
/// <summary>
|
||||
/// CD-ROM XA Mode 2 Form 2
|
||||
/// </summary>
|
||||
MODE2_FORM2,
|
||||
}
|
||||
}
|
||||
namespace SabreTools.Data.Models.CDROM
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum for a CD-ROM's sector mode
|
||||
/// Explicitly does not contain non-CD-ROM modes like AUDIO, CDG, CDI, and length-specific modes
|
||||
/// </summary>
|
||||
/// <see href="https://ecma-international.org/wp-content/uploads/ECMA-130_2nd_edition_june_1996.pdf"/>
|
||||
public enum SectorMode
|
||||
{
|
||||
/// <summary>
|
||||
/// CD-ROM Unknown Mode
|
||||
/// </summary>
|
||||
UNKNOWN,
|
||||
|
||||
/// <summary>
|
||||
/// CD-ROM Mode 0 (All bytes after header are 0x00)
|
||||
/// </summary>
|
||||
MODE0,
|
||||
|
||||
/// <summary>
|
||||
/// CD-ROM Mode 1
|
||||
/// </summary>
|
||||
MODE1,
|
||||
|
||||
/// <summary>
|
||||
/// CD-ROM Mode 2 (Formless)
|
||||
/// </summary>
|
||||
MODE2,
|
||||
|
||||
/// <summary>
|
||||
/// CD-ROM XA Mode 2 Form 1
|
||||
/// </summary>
|
||||
MODE2_FORM1,
|
||||
|
||||
/// <summary>
|
||||
/// CD-ROM XA Mode 2 Form 2
|
||||
/// </summary>
|
||||
MODE2_FORM2,
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user