mirror of
https://github.com/SabreTools/SabreTools.RedumpLib.git
synced 2026-02-08 21:31:55 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
415b488005 | ||
|
|
5d300c9975 | ||
|
|
304236774f | ||
|
|
9924289c48 | ||
|
|
240eb74ead | ||
|
|
a64b109d2c | ||
|
|
3e0f9b5410 | ||
|
|
668be418ac | ||
|
|
7d184a634e | ||
|
|
67aed0899d | ||
|
|
9fbaf1a187 | ||
|
|
fe8686a2bb | ||
|
|
652270c8c7 | ||
|
|
905d8a94fb | ||
|
|
3ee8416695 | ||
|
|
49fa06da55 | ||
|
|
70e29afd89 | ||
|
|
2a402a53db | ||
|
|
66bb3b75b2 | ||
|
|
9d7d46673a |
8
.github/workflows/build_nupkg.yml
vendored
8
.github/workflows/build_nupkg.yml
vendored
@@ -16,10 +16,16 @@ jobs:
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 8.0.x
|
||||
dotnet-version: 9.0.x
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
- name: Build library
|
||||
run: dotnet build
|
||||
|
||||
- name: Run tests
|
||||
run: dotnet test
|
||||
|
||||
- name: Pack
|
||||
run: dotnet pack
|
||||
|
||||
7
.github/workflows/check_pr.yml
vendored
7
.github/workflows/check_pr.yml
vendored
@@ -11,7 +11,10 @@ jobs:
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 8.0.x
|
||||
dotnet-version: 9.0.x
|
||||
|
||||
- name: Build
|
||||
run: dotnet build
|
||||
run: dotnet build
|
||||
|
||||
- name: Run tests
|
||||
run: dotnet test
|
||||
28
SabreTools.RedumpLib.Test/BuilderTests.cs
Normal file
28
SabreTools.RedumpLib.Test/BuilderTests.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.RedumpLib.Test
|
||||
{
|
||||
public class BuilderTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("success_complete.json", false)]
|
||||
[InlineData("success_invalid.json", false)] // Fully in valid returns a default object
|
||||
[InlineData("success_partial.json", false)]
|
||||
[InlineData("fail_invalid.json", true)]
|
||||
public void CreateFromFileTest(string filename, bool expectNull)
|
||||
{
|
||||
// Get the full path to the test file
|
||||
string path = Path.Combine(Environment.CurrentDirectory, "TestData", filename);
|
||||
|
||||
// Try to create the submission info from file
|
||||
var si = Builder.CreateFromFile(path);
|
||||
|
||||
// Check for an expected result
|
||||
Assert.Equal(expectNull, si == null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,8 @@ namespace SabreTools.RedumpLib.Test
|
||||
/// <summary>
|
||||
/// DiscType values that map to MediaType
|
||||
/// </summary>
|
||||
private static readonly DiscType?[] _mappableDiscTypes = new DiscType?[]
|
||||
{
|
||||
private static readonly DiscType?[] _mappableDiscTypes =
|
||||
[
|
||||
DiscType.BD25,
|
||||
DiscType.BD33,
|
||||
DiscType.BD50,
|
||||
@@ -35,13 +35,13 @@ namespace SabreTools.RedumpLib.Test
|
||||
DiscType.NintendoWiiUOpticalDiscSL,
|
||||
DiscType.UMDSL,
|
||||
DiscType.UMDDL,
|
||||
};
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// MediaType values that map to DiscType
|
||||
/// </summary>
|
||||
private static readonly MediaType?[] _mappableMediaTypes = new MediaType?[]
|
||||
{
|
||||
private static readonly MediaType?[] _mappableMediaTypes =
|
||||
[
|
||||
MediaType.BluRay,
|
||||
MediaType.CDROM,
|
||||
MediaType.DVD,
|
||||
@@ -51,7 +51,7 @@ namespace SabreTools.RedumpLib.Test
|
||||
MediaType.NintendoWiiOpticalDisc,
|
||||
MediaType.NintendoWiiUOpticalDisc,
|
||||
MediaType.UMD,
|
||||
};
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Check that every supported system has some set of MediaTypes supported
|
||||
@@ -101,9 +101,9 @@ namespace SabreTools.RedumpLib.Test
|
||||
foreach (DiscType? discType in Enum.GetValues(typeof(DiscType)))
|
||||
{
|
||||
if (_mappableDiscTypes.Contains(discType))
|
||||
testData.Add(new object?[] { discType, false });
|
||||
testData.Add([discType, false]);
|
||||
else
|
||||
testData.Add(new object?[] { discType, true });
|
||||
testData.Add([discType, true]);
|
||||
}
|
||||
|
||||
return testData;
|
||||
@@ -118,7 +118,7 @@ namespace SabreTools.RedumpLib.Test
|
||||
var testData = new List<object?[]>() { new object?[] { null } };
|
||||
foreach (RedumpSystem? redumpSystem in Enum.GetValues(typeof(RedumpSystem)))
|
||||
{
|
||||
testData.Add(new object?[] { redumpSystem });
|
||||
testData.Add([redumpSystem]);
|
||||
}
|
||||
|
||||
return testData;
|
||||
@@ -135,9 +135,9 @@ namespace SabreTools.RedumpLib.Test
|
||||
foreach (MediaType? mediaType in Enum.GetValues(typeof(MediaType)))
|
||||
{
|
||||
if (_mappableMediaTypes.Contains(mediaType))
|
||||
testData.Add(new object?[] { mediaType, false });
|
||||
testData.Add([mediaType, false]);
|
||||
else
|
||||
testData.Add(new object?[] { mediaType, true });
|
||||
testData.Add([mediaType, true]);
|
||||
}
|
||||
|
||||
return testData;
|
||||
@@ -173,7 +173,7 @@ namespace SabreTools.RedumpLib.Test
|
||||
var testData = new List<object?[]>() { new object?[] { null, true } };
|
||||
foreach (DiscCategory? discCategory in Enum.GetValues(typeof(DiscCategory)))
|
||||
{
|
||||
testData.Add(new object?[] { discCategory, false });
|
||||
testData.Add([discCategory, false]);
|
||||
}
|
||||
|
||||
return testData;
|
||||
@@ -210,9 +210,9 @@ namespace SabreTools.RedumpLib.Test
|
||||
foreach (DiscType? discType in Enum.GetValues(typeof(DiscType)))
|
||||
{
|
||||
if (discType == DiscType.NONE)
|
||||
testData.Add(new object?[] { discType, true });
|
||||
testData.Add([discType, true]);
|
||||
else
|
||||
testData.Add(new object?[] { discType, false });
|
||||
testData.Add([discType, false]);
|
||||
}
|
||||
|
||||
return testData;
|
||||
@@ -346,7 +346,7 @@ namespace SabreTools.RedumpLib.Test
|
||||
var testData = new List<object?[]>() { new object?[] { null, true } };
|
||||
foreach (Language? language in Enum.GetValues(typeof(Language)))
|
||||
{
|
||||
testData.Add(new object?[] { language, false });
|
||||
testData.Add([language, false]);
|
||||
}
|
||||
|
||||
return testData;
|
||||
@@ -382,7 +382,7 @@ namespace SabreTools.RedumpLib.Test
|
||||
var testData = new List<object?[]>() { new object?[] { null, true } };
|
||||
foreach (LanguageSelection? languageSelection in Enum.GetValues(typeof(LanguageSelection)))
|
||||
{
|
||||
testData.Add(new object?[] { languageSelection, false });
|
||||
testData.Add([languageSelection, false]);
|
||||
}
|
||||
|
||||
return testData;
|
||||
@@ -435,7 +435,7 @@ namespace SabreTools.RedumpLib.Test
|
||||
var testData = new List<object?[]>() { new object?[] { null, true } };
|
||||
foreach (MediaType? mediaType in Enum.GetValues(typeof(MediaType)))
|
||||
{
|
||||
testData.Add(new object?[] { mediaType, false });
|
||||
testData.Add([mediaType, false]);
|
||||
}
|
||||
|
||||
return testData;
|
||||
@@ -515,7 +515,7 @@ namespace SabreTools.RedumpLib.Test
|
||||
var testData = new List<object?[]>() { new object?[] { null, true } };
|
||||
foreach (Region? region in Enum.GetValues(typeof(Region)))
|
||||
{
|
||||
testData.Add(new object?[] { region, false });
|
||||
testData.Add([region, false]);
|
||||
}
|
||||
|
||||
return testData;
|
||||
@@ -568,7 +568,7 @@ namespace SabreTools.RedumpLib.Test
|
||||
var testData = new List<object?[]>() { new object?[] { null, true } };
|
||||
foreach (SiteCode? siteCode in Enum.GetValues(typeof(SiteCode)))
|
||||
{
|
||||
testData.Add(new object?[] { siteCode, false });
|
||||
testData.Add([siteCode, false]);
|
||||
}
|
||||
|
||||
return testData;
|
||||
@@ -631,7 +631,7 @@ namespace SabreTools.RedumpLib.Test
|
||||
if (redumpSystem.IsMarker())
|
||||
continue;
|
||||
|
||||
testData.Add(new object?[] { redumpSystem, false });
|
||||
testData.Add([redumpSystem, false]);
|
||||
}
|
||||
|
||||
return testData;
|
||||
@@ -668,9 +668,9 @@ namespace SabreTools.RedumpLib.Test
|
||||
foreach (SystemCategory? systemCategory in Enum.GetValues(typeof(SystemCategory)))
|
||||
{
|
||||
if (systemCategory == SystemCategory.NONE)
|
||||
testData.Add(new object?[] { systemCategory, true });
|
||||
testData.Add([systemCategory, true]);
|
||||
else
|
||||
testData.Add(new object?[] { systemCategory, false });
|
||||
testData.Add([systemCategory, false]);
|
||||
}
|
||||
|
||||
return testData;
|
||||
@@ -706,7 +706,7 @@ namespace SabreTools.RedumpLib.Test
|
||||
var testData = new List<object?[]>() { new object?[] { null, false } };
|
||||
foreach (YesNo? yesNo in Enum.GetValues(typeof(YesNo)))
|
||||
{
|
||||
testData.Add(new object?[] { yesNo, false });
|
||||
testData.Add([yesNo, false]);
|
||||
}
|
||||
|
||||
return testData;
|
||||
|
||||
@@ -1,37 +1,47 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
|
||||
<CheckEolTargetFramework>false</CheckEolTargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
|
||||
<CheckEolTargetFramework>false</CheckEolTargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SabreTools.RedumpLib\SabreTools.RedumpLib.csproj" />
|
||||
<ProjectReference Include="..\SabreTools.RedumpLib\SabreTools.RedumpLib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeCoverage" Version="17.10.0-release-24177-07" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0-release-24177-07" />
|
||||
<PackageReference Include="xunit" Version="2.8.0" />
|
||||
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
|
||||
<PackageReference Include="xunit.analyzers" Version="1.13.0" />
|
||||
<PackageReference Include="xunit.assert" Version="2.8.0" />
|
||||
<PackageReference Include="xunit.core" Version="2.8.0" />
|
||||
<PackageReference Include="xunit.extensibility.core" Version="2.8.0" />
|
||||
<PackageReference Include="xunit.extensibility.execution" Version="2.8.0" />
|
||||
<PackageReference Include="xunit.runner.console" Version="2.8.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<None Remove="TestData\*" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="TestData\*">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeCoverage" Version="17.11.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
|
||||
<PackageReference Include="xunit.analyzers" Version="1.17.0" />
|
||||
<PackageReference Include="xunit.assert" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.core" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.extensibility.core" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.extensibility.execution" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.console" Version="2.9.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
1
SabreTools.RedumpLib.Test/TestData/fail_invalid.json
Normal file
1
SabreTools.RedumpLib.Test/TestData/fail_invalid.json
Normal file
@@ -0,0 +1 @@
|
||||
This isn't even JSON, I lied.
|
||||
96
SabreTools.RedumpLib.Test/TestData/success_complete.json
Normal file
96
SabreTools.RedumpLib.Test/TestData/success_complete.json
Normal file
@@ -0,0 +1,96 @@
|
||||
{
|
||||
"schema_version": 3,
|
||||
"common_disc_info":
|
||||
{
|
||||
"d_system": "ajcd",
|
||||
"d_media": "cd",
|
||||
"d_title": "Test Title",
|
||||
"d_title_foreign": "Foreign Title",
|
||||
"d_number": "1",
|
||||
"d_label": "Install",
|
||||
"d_category": "Games",
|
||||
"d_region": "U",
|
||||
"d_languages":
|
||||
[
|
||||
"en",
|
||||
"fr",
|
||||
"es"
|
||||
],
|
||||
"d_languages_selection": [],
|
||||
"d_serial": "Serial",
|
||||
"d_ring_0_ma1": "Ringcode 0 Layer 0",
|
||||
"d_ring_0_ma1_sid": "SID 0 Layer 0",
|
||||
"d_ring_0_ts1": "Toolstamp 0 Layer 0",
|
||||
"d_ring_0_mo1_sid": "Mould SID 0 Layer 0",
|
||||
"d_ring_0_mo1": "Additional Mould 0 Layer 0",
|
||||
"d_ring_0_ma2": "Ringcode 0 Layer 1",
|
||||
"d_ring_0_ma2_sid": "SID 0 Layer 1",
|
||||
"d_ring_0_ts2": "Toolstamp 0 Layer 1",
|
||||
"d_ring_0_mo2_sid": "Mould SID 0 Layer 1",
|
||||
"d_ring_0_mo2": "Additional Mould 0 Layer 1",
|
||||
"d_ring_0_ma3": "Ringcode 0 Layer 2",
|
||||
"d_ring_0_ma3_sid": "SID 0 Layer 2",
|
||||
"d_ring_0_ts3": "Toolstamp 0 Layer 2",
|
||||
"d_ring_0_ma4": "Ringcode 0 Layer 3",
|
||||
"d_ring_0_ma4_sid": "SID 0 Layer 2",
|
||||
"d_ring_0_ts4": "Toolstamp 0 Layer 2",
|
||||
"d_ring_0_offsets": "-22",
|
||||
"d_ring_0_0_value": "-21",
|
||||
"d_barcode": "0 12345 67890 1",
|
||||
"d_date": "1980-01-01",
|
||||
"d_errors": "0",
|
||||
"d_comments": "This is a comment\nwith a newline",
|
||||
"d_contents": "These are contents, sorry"
|
||||
},
|
||||
"versions_and_editions":
|
||||
{
|
||||
"d_version": "1.0.0.0",
|
||||
"d_version_datfile": "1.00",
|
||||
"d_editions_text": "Demo"
|
||||
|
||||
},
|
||||
"edc":
|
||||
{
|
||||
"d_edc": false
|
||||
},
|
||||
"parent_clone_relationship":
|
||||
{
|
||||
"d_parent_id": "12345",
|
||||
"d_is_regional_parent": false
|
||||
},
|
||||
"extras":
|
||||
{
|
||||
"d_pvd": "Pretend\nthis\nis\na\nPVD",
|
||||
"d_d1_key": "Disc key",
|
||||
"d_d2_key": "Disc ID",
|
||||
"d_pic_data": "Pretend\nthis\nis\na\nPIC",
|
||||
"d_header": "Pretend\nthis\nis\na\nHeader",
|
||||
"d_bca": "Pretend\nthis\nis\na\nBCA",
|
||||
"d_ssranges": "Pretend\nthis\nis\na\nsecurity_range"
|
||||
},
|
||||
"copy_protection":
|
||||
{
|
||||
"d_protection_a": false,
|
||||
"d_protection_1": false,
|
||||
"d_libcrypt": "Definitely\nLibCrypt\nData",
|
||||
"d_protection": "Super easy to find protection",
|
||||
"d_securom": "Definitely\nSecuROM\nData"
|
||||
},
|
||||
"tracks_and_write_offsets":
|
||||
{
|
||||
"d_tracks": "Hash data",
|
||||
"d_cue": "Real cuesheet",
|
||||
"d_offset_text": "-22"
|
||||
},
|
||||
"size_and_checksums":
|
||||
{
|
||||
"d_layerbreak": 1,
|
||||
"d_layerbreak_2": 2,
|
||||
"d_layerbreak_3": 3,
|
||||
"d_pic_identifier": "Pretend\nthis\nis\na\nPIC",
|
||||
"d_size": 123456,
|
||||
"d_crc32": "cbf43926",
|
||||
"d_md5": "d41d8cd98f00b204e9800998ecf8427e",
|
||||
"d_sha1": "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
||||
}
|
||||
}
|
||||
4
SabreTools.RedumpLib.Test/TestData/success_invalid.json
Normal file
4
SabreTools.RedumpLib.Test/TestData/success_invalid.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"invalid_key": "invalid_value",
|
||||
"invalid_x": 12345
|
||||
}
|
||||
7
SabreTools.RedumpLib.Test/TestData/success_partial.json
Normal file
7
SabreTools.RedumpLib.Test/TestData/success_partial.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"schema_version": 3,
|
||||
"common_disc_info":
|
||||
{
|
||||
"d_title": "Test Title"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace SabreTools.RedumpLib.Attributes
|
||||
{
|
||||
@@ -25,24 +24,24 @@ namespace SabreTools.RedumpLib.Attributes
|
||||
string? valueStr = value?.ToString();
|
||||
if (string.IsNullOrEmpty(valueStr))
|
||||
return null;
|
||||
|
||||
|
||||
// Get the member info array
|
||||
var memberInfos = enumType?.GetMember(valueStr);
|
||||
if (memberInfos == null)
|
||||
return null;
|
||||
|
||||
// Get the enum value info from the array, if possible
|
||||
var enumValueMemberInfo = memberInfos.FirstOrDefault(m => m.DeclaringType == enumType);
|
||||
var enumValueMemberInfo = Array.Find(memberInfos, m => m.DeclaringType == enumType);
|
||||
if (enumValueMemberInfo == null)
|
||||
return null;
|
||||
|
||||
|
||||
// Try to get the relevant attribute
|
||||
var attributes = enumValueMemberInfo.GetCustomAttributes(typeof(HumanReadableAttribute), true);
|
||||
if (attributes == null)
|
||||
if (attributes == null || attributes.Length == 0)
|
||||
return null;
|
||||
|
||||
|
||||
// Return the first attribute, if possible
|
||||
return attributes.FirstOrDefault() as HumanReadableAttribute;
|
||||
return attributes[0] as HumanReadableAttribute;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
using System.Net;
|
||||
#endif
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
@@ -269,22 +270,25 @@ namespace SabreTools.RedumpLib
|
||||
if (title != null && firstParenLocation >= 0)
|
||||
{
|
||||
info.CommonDiscInfo!.Title = title.Substring(0, firstParenLocation);
|
||||
var subMatches = Constants.DiscNumberLetterRegex.Matches(title);
|
||||
foreach (Match subMatch in subMatches.Cast<Match>())
|
||||
var submatches = Constants.DiscNumberLetterRegex.Matches(title);
|
||||
foreach (Match? submatch in submatches)
|
||||
{
|
||||
var subMatchValue = subMatch.Groups[1].Value;
|
||||
if (submatch == null)
|
||||
continue;
|
||||
|
||||
var submatchValue = submatch.Groups[1].Value;
|
||||
|
||||
// Disc number or letter
|
||||
if (subMatchValue.StartsWith("Disc"))
|
||||
info.CommonDiscInfo.DiscNumberLetter = subMatchValue.Remove(0, "Disc ".Length);
|
||||
if (submatchValue.StartsWith("Disc"))
|
||||
info.CommonDiscInfo.DiscNumberLetter = submatchValue.Remove(0, "Disc ".Length);
|
||||
|
||||
// Issue number
|
||||
else if (subMatchValue.All(c => char.IsNumber(c)))
|
||||
info.CommonDiscInfo.Title += $" ({subMatchValue})";
|
||||
else if (ulong.TryParse(submatchValue, out _))
|
||||
info.CommonDiscInfo.Title += $" ({submatchValue})";
|
||||
|
||||
// Disc title
|
||||
else
|
||||
info.CommonDiscInfo.DiscTitle = subMatchValue;
|
||||
info.CommonDiscInfo.DiscTitle = submatchValue;
|
||||
}
|
||||
}
|
||||
// Otherwise, leave the title as-is
|
||||
@@ -298,15 +302,13 @@ namespace SabreTools.RedumpLib
|
||||
match = Constants.ForeignTitleRegex.Match(discData);
|
||||
if (match.Success)
|
||||
info.CommonDiscInfo!.ForeignTitleNonLatin = WebUtility.HtmlDecode(match.Groups[1].Value);
|
||||
else
|
||||
info.CommonDiscInfo!.ForeignTitleNonLatin = null;
|
||||
|
||||
// Category
|
||||
match = Constants.CategoryRegex.Match(discData);
|
||||
if (match.Success)
|
||||
info.CommonDiscInfo.Category = Extensions.ToDiscCategory(match.Groups[1].Value);
|
||||
info.CommonDiscInfo!.Category = Extensions.ToDiscCategory(match.Groups[1].Value);
|
||||
else
|
||||
info.CommonDiscInfo.Category = DiscCategory.Games;
|
||||
info.CommonDiscInfo!.Category = DiscCategory.Games;
|
||||
|
||||
// Region
|
||||
if (info.CommonDiscInfo.Region == null)
|
||||
@@ -321,12 +323,17 @@ namespace SabreTools.RedumpLib
|
||||
if (matches.Count > 0)
|
||||
{
|
||||
var tempLanguages = new List<Language?>();
|
||||
foreach (Match submatch in matches.Cast<Match>())
|
||||
foreach (Match? submatch in matches)
|
||||
{
|
||||
tempLanguages.Add(Extensions.ToLanguage(submatch.Groups[1].Value));
|
||||
if (submatch == null)
|
||||
continue;
|
||||
|
||||
var language = Extensions.ToLanguage(submatch.Groups[1].Value);
|
||||
if (language != null)
|
||||
tempLanguages.Add(language);
|
||||
}
|
||||
|
||||
info.CommonDiscInfo.Languages = tempLanguages.Where(l => l != null).ToArray();
|
||||
info.CommonDiscInfo.Languages = [.. tempLanguages];
|
||||
}
|
||||
|
||||
// Serial
|
||||
@@ -366,8 +373,11 @@ namespace SabreTools.RedumpLib
|
||||
tempDumpers.Add(dumper);
|
||||
}
|
||||
|
||||
foreach (Match submatch in matches.Cast<Match>())
|
||||
foreach (Match? submatch in matches)
|
||||
{
|
||||
if (submatch == null)
|
||||
continue;
|
||||
|
||||
string? dumper = WebUtility.HtmlDecode(submatch.Groups[1].Value);
|
||||
if (dumper != null)
|
||||
tempDumpers.Add(dumper);
|
||||
|
||||
@@ -10,11 +10,21 @@ namespace SabreTools.RedumpLib.Converters
|
||||
/// </summary>
|
||||
public class DiscCategoryConverter : JsonConverter<DiscCategory?>
|
||||
{
|
||||
public override bool CanRead { get { return false; } }
|
||||
public override bool CanRead { get { return true; } }
|
||||
|
||||
public override DiscCategory? ReadJson(JsonReader reader, Type objectType, DiscCategory? existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// If we have a value already, don't overwrite it
|
||||
if (hasExistingValue)
|
||||
return existingValue;
|
||||
|
||||
// Read the value
|
||||
string? value = reader.Value as string;
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
// Try to parse the value
|
||||
return Data.Extensions.ToDiscCategory(value);
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, DiscCategory? value, JsonSerializer serializer)
|
||||
|
||||
@@ -10,11 +10,21 @@ namespace SabreTools.RedumpLib.Converters
|
||||
/// </summary>
|
||||
public class DiscTypeConverter : JsonConverter<DiscType?>
|
||||
{
|
||||
public override bool CanRead { get { return false; } }
|
||||
public override bool CanRead { get { return true; } }
|
||||
|
||||
public override DiscType? ReadJson(JsonReader reader, Type objectType, DiscType? existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// If we have a value already, don't overwrite it
|
||||
if (hasExistingValue)
|
||||
return existingValue;
|
||||
|
||||
// Read the value
|
||||
string? value = reader.Value as string;
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
// Try to parse the value
|
||||
return Data.Extensions.ToDiscType(value);
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, DiscType? value, JsonSerializer serializer)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SabreTools.RedumpLib.Data;
|
||||
@@ -10,11 +11,31 @@ namespace SabreTools.RedumpLib.Converters
|
||||
/// </summary>
|
||||
public class LanguageConverter : JsonConverter<Language?[]>
|
||||
{
|
||||
public override bool CanRead { get { return false; } }
|
||||
public override bool CanRead { get { return true; } }
|
||||
|
||||
public override Language?[] ReadJson(JsonReader reader, Type objectType, Language?[]? existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// If we have a value already, don't overwrite it
|
||||
if (hasExistingValue)
|
||||
return existingValue ?? [];
|
||||
|
||||
// Get the current depth for checking
|
||||
int currentDepth = reader.Depth;
|
||||
|
||||
// Read the array while it exists
|
||||
List<Language> languages = [];
|
||||
while (reader.Read() && reader.Depth > currentDepth)
|
||||
{
|
||||
string? value = reader.Value as string;
|
||||
if (value == null)
|
||||
continue;
|
||||
|
||||
Language? lang = Data.Extensions.ToLanguage(value);
|
||||
if (lang != null)
|
||||
languages.Add(lang.Value);
|
||||
}
|
||||
|
||||
return [.. languages];
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, Language?[]? value, JsonSerializer serializer)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SabreTools.RedumpLib.Data;
|
||||
@@ -10,11 +11,31 @@ namespace SabreTools.RedumpLib.Converters
|
||||
/// </summary>
|
||||
public class LanguageSelectionConverter : JsonConverter<LanguageSelection?[]>
|
||||
{
|
||||
public override bool CanRead { get { return false; } }
|
||||
public override bool CanRead { get { return true; } }
|
||||
|
||||
public override LanguageSelection?[] ReadJson(JsonReader reader, Type objectType, LanguageSelection?[]? existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// If we have a value already, don't overwrite it
|
||||
if (hasExistingValue)
|
||||
return existingValue ?? [];
|
||||
|
||||
// Get the current depth for checking
|
||||
int currentDepth = reader.Depth;
|
||||
|
||||
// Read the array while it exists
|
||||
List<LanguageSelection> selections = [];
|
||||
while (reader.Read() && reader.Depth > currentDepth)
|
||||
{
|
||||
string? value = reader.Value as string;
|
||||
if (value == null)
|
||||
continue;
|
||||
|
||||
LanguageSelection? sel = Data.Extensions.ToLanguageSelection(value);
|
||||
if (sel != null)
|
||||
selections.Add(sel.Value);
|
||||
}
|
||||
|
||||
return [.. selections];
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, LanguageSelection?[]? value, JsonSerializer serializer)
|
||||
|
||||
@@ -10,11 +10,21 @@ namespace SabreTools.RedumpLib.Converters
|
||||
/// </summary>
|
||||
public class RegionConverter : JsonConverter<Region?>
|
||||
{
|
||||
public override bool CanRead { get { return false; } }
|
||||
public override bool CanRead { get { return true; } }
|
||||
|
||||
public override Region? ReadJson(JsonReader reader, Type objectType, Region? existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// If we have a value already, don't overwrite it
|
||||
if (hasExistingValue)
|
||||
return existingValue;
|
||||
|
||||
// Read the value
|
||||
string? value = reader.Value as string;
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
// Try to parse the value
|
||||
return Data.Extensions.ToRegion(value);
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, Region? value, JsonSerializer serializer)
|
||||
|
||||
@@ -10,11 +10,21 @@ namespace SabreTools.RedumpLib.Converters
|
||||
/// </summary>
|
||||
public class SystemConverter : JsonConverter<RedumpSystem?>
|
||||
{
|
||||
public override bool CanRead { get { return false; } }
|
||||
public override bool CanRead { get { return true; } }
|
||||
|
||||
public override RedumpSystem? ReadJson(JsonReader reader, Type objectType, RedumpSystem? existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// If we have a value already, don't overwrite it
|
||||
if (hasExistingValue)
|
||||
return existingValue;
|
||||
|
||||
// Read the value
|
||||
string? value = reader.Value as string;
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
// Try to parse the value
|
||||
return Data.Extensions.ToRedumpSystem(value);
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, RedumpSystem? value, JsonSerializer serializer)
|
||||
|
||||
@@ -10,11 +10,21 @@ namespace SabreTools.RedumpLib.Converters
|
||||
/// </summary>
|
||||
public class YesNoConverter : JsonConverter<YesNo?>
|
||||
{
|
||||
public override bool CanRead { get { return false; } }
|
||||
public override bool CanRead { get { return true; } }
|
||||
|
||||
public override YesNo? ReadJson(JsonReader reader, Type objectType, YesNo? existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// If we have a value already, don't overwrite it
|
||||
if (hasExistingValue)
|
||||
return existingValue;
|
||||
|
||||
// Read the value
|
||||
if (reader.Value is bool bVal)
|
||||
return Data.Extensions.ToYesNo(bVal);
|
||||
else if (reader.Value is string sVal)
|
||||
return Data.Extensions.ToYesNo(sVal);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, YesNo? value, JsonSerializer serializer)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SabreTools.RedumpLib.Attributes;
|
||||
|
||||
namespace SabreTools.RedumpLib.Data
|
||||
@@ -791,7 +790,8 @@ namespace SabreTools.RedumpLib.Data
|
||||
/// </summary>
|
||||
/// <param name="category"></param>
|
||||
/// <returns></returns>
|
||||
public static string? LongName(this DiscCategory? category) => AttributeHelper<DiscCategory?>.GetAttribute(category)?.LongName;
|
||||
public static string? LongName(this DiscCategory? category)
|
||||
=> AttributeHelper<DiscCategory?>.GetAttribute(category)?.LongName;
|
||||
|
||||
/// <summary>
|
||||
/// Get the Category enum value for a given string
|
||||
@@ -828,7 +828,8 @@ namespace SabreTools.RedumpLib.Data
|
||||
/// </summary>
|
||||
/// <param name="discType"></param>
|
||||
/// <returns></returns>
|
||||
public static string? LongName(this DiscType? discType) => AttributeHelper<DiscType?>.GetAttribute(discType)?.LongName;
|
||||
public static string? LongName(this DiscType? discType)
|
||||
=> AttributeHelper<DiscType?>.GetAttribute(discType)?.LongName;
|
||||
|
||||
/// <summary>
|
||||
/// Get the DiscType enum value for a given string
|
||||
@@ -894,7 +895,8 @@ namespace SabreTools.RedumpLib.Data
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
public static string? LongName(this Language? language) => AttributeHelper<Language?>.GetAttribute(language)?.LongName;
|
||||
public static string? LongName(this Language? language)
|
||||
=> AttributeHelper<Language?>.GetAttribute(language)?.LongName;
|
||||
|
||||
/// <summary>
|
||||
/// Get the Redump shortnames for each known language
|
||||
@@ -923,31 +925,23 @@ namespace SabreTools.RedumpLib.Data
|
||||
/// <returns>Language represented by the string, if possible</returns>
|
||||
public static Language? ToLanguage(string lang)
|
||||
{
|
||||
var languages = Enum.GetValues(typeof(Language)).Cast<Language?>().ToList();
|
||||
lang = lang.ToLowerInvariant();
|
||||
var languages = (Language[])Enum.GetValues(typeof(Language));
|
||||
|
||||
// Check ISO 639-1 codes
|
||||
Dictionary<string, Language?> languageMapping = languages
|
||||
.Where(l => l.TwoLetterCode() != null)
|
||||
.ToDictionary(l => l.TwoLetterCode() ?? string.Empty, l => l);
|
||||
|
||||
if (languageMapping.ContainsKey(lang))
|
||||
return languageMapping[lang];
|
||||
int index = Array.FindIndex(languages, l => lang == l.TwoLetterCode());
|
||||
if (index > -1)
|
||||
return languages[index];
|
||||
|
||||
// Check standard ISO 639-2 codes
|
||||
languageMapping = languages
|
||||
.Where(l => l.ThreeLetterCode() != null)
|
||||
.ToDictionary(l => l.ThreeLetterCode() ?? string.Empty, l => l);
|
||||
|
||||
if (languageMapping.ContainsKey(lang))
|
||||
return languageMapping[lang];
|
||||
index = Array.FindIndex(languages, r => lang == r.ThreeLetterCode());
|
||||
if (index > -1)
|
||||
return languages[index];
|
||||
|
||||
// Check alternate ISO 639-2 codes
|
||||
languageMapping = languages
|
||||
.Where(l => l.ThreeLetterCodeAlt() != null)
|
||||
.ToDictionary(l => l.ThreeLetterCodeAlt() ?? string.Empty, l => l);
|
||||
|
||||
if (languageMapping.ContainsKey(lang))
|
||||
return languageMapping[lang];
|
||||
index = Array.FindIndex(languages, r => lang == r.ThreeLetterCodeAlt());
|
||||
if (index > -1)
|
||||
return languages[index];
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -957,21 +951,48 @@ namespace SabreTools.RedumpLib.Data
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
public static string? ThreeLetterCode(this Language? language) => (AttributeHelper<Language?>.GetAttribute(language) as LanguageAttribute)?.ThreeLetterCode;
|
||||
public static string? ThreeLetterCode(this Language language)
|
||||
=> (AttributeHelper<Language>.GetAttribute(language) as LanguageAttribute)?.ThreeLetterCode;
|
||||
|
||||
/// <summary>
|
||||
/// Get the ISO 639-2 code for each known language
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
public static string? ThreeLetterCode(this Language? language)
|
||||
=> (AttributeHelper<Language?>.GetAttribute(language) as LanguageAttribute)?.ThreeLetterCode;
|
||||
|
||||
/// <summary>
|
||||
/// Get the ISO 639-2 alternate code for each known language
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
public static string? ThreeLetterCodeAlt(this Language? language) => (AttributeHelper<Language?>.GetAttribute(language) as LanguageAttribute)?.ThreeLetterCodeAlt;
|
||||
public static string? ThreeLetterCodeAlt(this Language language)
|
||||
=> (AttributeHelper<Language>.GetAttribute(language) as LanguageAttribute)?.ThreeLetterCodeAlt;
|
||||
|
||||
/// <summary>
|
||||
/// Get the ISO 639-2 alternate code for each known language
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
public static string? ThreeLetterCodeAlt(this Language? language)
|
||||
=> (AttributeHelper<Language?>.GetAttribute(language) as LanguageAttribute)?.ThreeLetterCodeAlt;
|
||||
|
||||
/// <summary>
|
||||
/// Get the ISO 639-1 code for each known language
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
public static string? TwoLetterCode(this Language? language) => (AttributeHelper<Language?>.GetAttribute(language) as LanguageAttribute)?.TwoLetterCode;
|
||||
public static string? TwoLetterCode(this Language language)
|
||||
=> (AttributeHelper<Language>.GetAttribute(language) as LanguageAttribute)?.TwoLetterCode;
|
||||
|
||||
/// <summary>
|
||||
/// Get the ISO 639-1 code for each known language
|
||||
/// </summary>
|
||||
/// <param name="language"></param>
|
||||
/// <returns></returns>
|
||||
public static string? TwoLetterCode(this Language? language)
|
||||
=> (AttributeHelper<Language?>.GetAttribute(language) as LanguageAttribute)?.TwoLetterCode;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -984,6 +1005,29 @@ namespace SabreTools.RedumpLib.Data
|
||||
/// <returns>String representing the value, if possible</returns>
|
||||
public static string? LongName(this LanguageSelection? langSelect) => AttributeHelper<LanguageSelection?>.GetAttribute(langSelect)?.LongName;
|
||||
|
||||
/// <summary>
|
||||
/// Get the LanguageSelection enum value for a given string
|
||||
/// </summary>
|
||||
/// <param name="langSelect">String value to convert</param>
|
||||
/// <returns>LanguageSelection represented by the string, if possible</returns>
|
||||
public static LanguageSelection? ToLanguageSelection(string langSelect)
|
||||
{
|
||||
return (langSelect?.ToLowerInvariant()) switch
|
||||
{
|
||||
"bios"
|
||||
or "biossettings"
|
||||
or "bios settings" => (LanguageSelection?)LanguageSelection.BiosSettings,
|
||||
"selector"
|
||||
or "langselector"
|
||||
or "lang selector"
|
||||
or "langauge selector" => (LanguageSelection?)LanguageSelection.LanguageSelector,
|
||||
"options"
|
||||
or "optionsmenu"
|
||||
or "options menu" => (LanguageSelection?)LanguageSelection.OptionsMenu,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Media Type
|
||||
@@ -1029,14 +1073,32 @@ namespace SabreTools.RedumpLib.Data
|
||||
/// </summary>
|
||||
/// <param name="region"></param>
|
||||
/// <returns></returns>
|
||||
public static string? LongName(this Region? region) => AttributeHelper<Region?>.GetAttribute(region)?.LongName;
|
||||
public static string? LongName(this Region region)
|
||||
=> AttributeHelper<Region>.GetAttribute(region)?.LongName;
|
||||
|
||||
/// <summary>
|
||||
/// Get the Redump longnames for each known region
|
||||
/// </summary>
|
||||
/// <param name="region"></param>
|
||||
/// <returns></returns>
|
||||
public static string? LongName(this Region? region)
|
||||
=> AttributeHelper<Region?>.GetAttribute(region)?.LongName;
|
||||
|
||||
/// <summary>
|
||||
/// Get the Redump shortnames for each known region
|
||||
/// </summary>
|
||||
/// <param name="region"></param>
|
||||
/// <returns></returns>
|
||||
public static string? ShortName(this Region? region) => AttributeHelper<Region?>.GetAttribute(region)?.ShortName;
|
||||
public static string? ShortName(this Region region)
|
||||
=> AttributeHelper<Region>.GetAttribute(region)?.ShortName;
|
||||
|
||||
/// <summary>
|
||||
/// Get the Redump shortnames for each known region
|
||||
/// </summary>
|
||||
/// <param name="region"></param>
|
||||
/// <returns></returns>
|
||||
public static string? ShortName(this Region? region)
|
||||
=> AttributeHelper<Region?>.GetAttribute(region)?.ShortName;
|
||||
|
||||
/// <summary>
|
||||
/// Get the Region enum value for a given string
|
||||
@@ -1046,15 +1108,15 @@ namespace SabreTools.RedumpLib.Data
|
||||
public static Region? ToRegion(string region)
|
||||
{
|
||||
region = region.ToLowerInvariant();
|
||||
var regions = Enum.GetValues(typeof(Region)).Cast<Region?>().ToList();
|
||||
var regions = (Region[])Enum.GetValues(typeof(Region));
|
||||
|
||||
// Check ISO 3166-1 alpha-2 codes
|
||||
Dictionary<string, Region?> regionMapping = regions
|
||||
.Where(r => r.ShortName() != null)
|
||||
.ToDictionary(r => r.ShortName()?.ToLowerInvariant() ?? string.Empty, r => r);
|
||||
int index = Array.FindIndex(regions, r => region == r.ShortName());
|
||||
if (index > -1)
|
||||
return regions[index];
|
||||
|
||||
if (regionMapping.ContainsKey(region))
|
||||
return regionMapping[region];
|
||||
index = Array.FindIndex(regions, r => region == r.LongName());
|
||||
if (index > -1)
|
||||
return regions[index];
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -1074,7 +1136,7 @@ namespace SabreTools.RedumpLib.Data
|
||||
{
|
||||
string? shortName = ((SiteCode?)val).ShortName()?.TrimEnd(':');
|
||||
string? longName = ((SiteCode?)val).LongName()?.TrimEnd(':');
|
||||
|
||||
|
||||
bool isCommentCode = ((SiteCode?)val).IsCommentCode();
|
||||
bool isContentCode = ((SiteCode?)val).IsContentCode();
|
||||
bool isMultiline = ((SiteCode?)val).IsMultiLine();
|
||||
@@ -1360,19 +1422,10 @@ namespace SabreTools.RedumpLib.Data
|
||||
/// </summary>
|
||||
public static List<string> ListSystems()
|
||||
{
|
||||
var systems = new List<string>();
|
||||
|
||||
var knownSystems = Enum.GetValues(typeof(RedumpSystem))
|
||||
.OfType<RedumpSystem?>()
|
||||
.Where(s => s != null && !s.IsMarker() && s.GetCategory() != SystemCategory.NONE)
|
||||
.OrderBy(s => s.LongName() ?? string.Empty);
|
||||
|
||||
foreach (var val in knownSystems)
|
||||
{
|
||||
systems.Add($"{val.ShortName()} - {val.LongName()}");
|
||||
}
|
||||
|
||||
return systems;
|
||||
var systems = (RedumpSystem?[])Enum.GetValues(typeof(RedumpSystem));
|
||||
var knownSystems = Array.FindAll(systems, s => s != null && !s.IsMarker() && s.GetCategory() != SystemCategory.NONE);
|
||||
Array.Sort(knownSystems, (x, y) => (x.LongName() ?? string.Empty).CompareTo(y.LongName() ?? string.Empty));
|
||||
return [.. Array.ConvertAll(knownSystems, val => $"{val.ShortName()} - {val.LongName()}")];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1380,64 +1433,146 @@ namespace SabreTools.RedumpLib.Data
|
||||
/// </summary>
|
||||
/// <param name="system"></param>
|
||||
/// <returns></returns>
|
||||
public static string? LongName(this RedumpSystem? system) => AttributeHelper<RedumpSystem?>.GetAttribute(system)?.LongName;
|
||||
public static string? LongName(this RedumpSystem system)
|
||||
=> AttributeHelper<RedumpSystem>.GetAttribute(system)?.LongName;
|
||||
|
||||
/// <summary>
|
||||
/// Get the Redump longnames for each known system
|
||||
/// </summary>
|
||||
/// <param name="system"></param>
|
||||
/// <returns></returns>
|
||||
public static string? LongName(this RedumpSystem? system)
|
||||
=> AttributeHelper<RedumpSystem?>.GetAttribute(system)?.LongName;
|
||||
|
||||
/// <summary>
|
||||
/// Get the Redump shortnames for each known system
|
||||
/// </summary>
|
||||
/// <param name="system"></param>
|
||||
/// <returns></returns>
|
||||
public static string? ShortName(this RedumpSystem? system) => AttributeHelper<RedumpSystem?>.GetAttribute(system)?.ShortName;
|
||||
public static string? ShortName(this RedumpSystem system)
|
||||
=> AttributeHelper<RedumpSystem>.GetAttribute(system)?.ShortName;
|
||||
|
||||
/// <summary>
|
||||
/// Get the Redump shortnames for each known system
|
||||
/// </summary>
|
||||
/// <param name="system"></param>
|
||||
/// <returns></returns>
|
||||
public static string? ShortName(this RedumpSystem? system)
|
||||
=> AttributeHelper<RedumpSystem?>.GetAttribute(system)?.ShortName;
|
||||
|
||||
/// <summary>
|
||||
/// Determine the category of a system
|
||||
/// </summary>
|
||||
public static SystemCategory GetCategory(this RedumpSystem? system) => (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.Category ?? SystemCategory.NONE;
|
||||
public static SystemCategory GetCategory(this RedumpSystem? system)
|
||||
=> (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.Category ?? SystemCategory.NONE;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system is available in Redump yet
|
||||
/// </summary>
|
||||
public static bool IsAvailable(this RedumpSystem? system) => (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.Available ?? false;
|
||||
public static bool IsAvailable(this RedumpSystem system)
|
||||
=> (AttributeHelper<RedumpSystem>.GetAttribute(system) as SystemAttribute)?.Available ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system is available in Redump yet
|
||||
/// </summary>
|
||||
public static bool IsAvailable(this RedumpSystem? system)
|
||||
=> (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.Available ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system is restricted to dumpers
|
||||
/// </summary>
|
||||
public static bool IsBanned(this RedumpSystem? system) => (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.IsBanned ?? false;
|
||||
public static bool IsBanned(this RedumpSystem system)
|
||||
=> (AttributeHelper<RedumpSystem>.GetAttribute(system) as SystemAttribute)?.IsBanned ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system is restricted to dumpers
|
||||
/// </summary>
|
||||
public static bool IsBanned(this RedumpSystem? system)
|
||||
=> (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.IsBanned ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system has a CUE pack
|
||||
/// </summary>
|
||||
public static bool HasCues(this RedumpSystem? system) => (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.HasCues ?? false;
|
||||
public static bool HasCues(this RedumpSystem system)
|
||||
=> (AttributeHelper<RedumpSystem>.GetAttribute(system) as SystemAttribute)?.HasCues ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system has a CUE pack
|
||||
/// </summary>
|
||||
public static bool HasCues(this RedumpSystem? system)
|
||||
=> (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.HasCues ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system has a DAT
|
||||
/// </summary>
|
||||
public static bool HasDat(this RedumpSystem? system) => (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.HasDat ?? false;
|
||||
public static bool HasDat(this RedumpSystem system)
|
||||
=> (AttributeHelper<RedumpSystem>.GetAttribute(system) as SystemAttribute)?.HasDat ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system has a DAT
|
||||
/// </summary>
|
||||
public static bool HasDat(this RedumpSystem? system)
|
||||
=> (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.HasDat ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system has a decrypted keys pack
|
||||
/// </summary>
|
||||
public static bool HasDkeys(this RedumpSystem? system) => (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.HasDkeys ?? false;
|
||||
public static bool HasDkeys(this RedumpSystem system)
|
||||
=> (AttributeHelper<RedumpSystem>.GetAttribute(system) as SystemAttribute)?.HasDkeys ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system has a decrypted keys pack
|
||||
/// </summary>
|
||||
public static bool HasDkeys(this RedumpSystem? system)
|
||||
=> (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.HasDkeys ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system has a GDI pack
|
||||
/// </summary>
|
||||
public static bool HasGdi(this RedumpSystem? system) => (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.HasGdi ?? false;
|
||||
public static bool HasGdi(this RedumpSystem system)
|
||||
=> (AttributeHelper<RedumpSystem>.GetAttribute(system) as SystemAttribute)?.HasGdi ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system has a GDI pack
|
||||
/// </summary>
|
||||
public static bool HasGdi(this RedumpSystem? system)
|
||||
=> (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.HasGdi ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system has a keys pack
|
||||
/// </summary>
|
||||
public static bool HasKeys(this RedumpSystem? system) => (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.HasKeys ?? false;
|
||||
public static bool HasKeys(this RedumpSystem system)
|
||||
=> (AttributeHelper<RedumpSystem>.GetAttribute(system) as SystemAttribute)?.HasKeys ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system has a keys pack
|
||||
/// </summary>
|
||||
public static bool HasKeys(this RedumpSystem? system)
|
||||
=> (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.HasKeys ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system has an LSD pack
|
||||
/// </summary>
|
||||
public static bool HasLsd(this RedumpSystem? system) => (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.HasLsd ?? false;
|
||||
public static bool HasLsd(this RedumpSystem system)
|
||||
=> (AttributeHelper<RedumpSystem>.GetAttribute(system) as SystemAttribute)?.HasLsd ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system has an LSD pack
|
||||
/// </summary>
|
||||
public static bool HasLsd(this RedumpSystem? system)
|
||||
=> (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.HasLsd ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system has an SBI pack
|
||||
/// </summary>
|
||||
public static bool HasSbi(this RedumpSystem? system) => (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.HasSbi ?? false;
|
||||
public static bool HasSbi(this RedumpSystem system)
|
||||
=> (AttributeHelper<RedumpSystem>.GetAttribute(system) as SystemAttribute)?.HasSbi ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if a system has an SBI pack
|
||||
/// </summary>
|
||||
public static bool HasSbi(this RedumpSystem? system)
|
||||
=> (AttributeHelper<RedumpSystem?>.GetAttribute(system) as SystemAttribute)?.HasSbi ?? false;
|
||||
|
||||
/// <summary>
|
||||
/// Get the RedumpSystem enum value for a given string
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.RedumpLib.Converters;
|
||||
|
||||
@@ -73,6 +75,20 @@ namespace SabreTools.RedumpLib.Data
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
#if NET20 || NET35
|
||||
Dictionary<string, string>? artifacts = null;
|
||||
if (this.Artifacts != null)
|
||||
{
|
||||
artifacts = new Dictionary<string, string>();
|
||||
foreach (var kvp in this.Artifacts)
|
||||
{
|
||||
artifacts[kvp.Key] = kvp.Value;
|
||||
}
|
||||
}
|
||||
#else
|
||||
var artifacts = this.Artifacts?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||
#endif
|
||||
|
||||
return new SubmissionInfo
|
||||
{
|
||||
SchemaVersion = this.SchemaVersion,
|
||||
@@ -90,7 +106,7 @@ namespace SabreTools.RedumpLib.Data
|
||||
TracksAndWriteOffsets = this.TracksAndWriteOffsets?.Clone() as TracksAndWriteOffsetsSection,
|
||||
SizeAndChecksums = this.SizeAndChecksums?.Clone() as SizeAndChecksumsSection,
|
||||
DumpingInfo = this.DumpingInfo?.Clone() as DumpingInfoSection,
|
||||
Artifacts = this.Artifacts?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value),
|
||||
Artifacts = artifacts,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -101,16 +117,16 @@ namespace SabreTools.RedumpLib.Data
|
||||
public class CommonDiscInfoSection : ICloneable
|
||||
{
|
||||
// Name not defined by Redump
|
||||
[JsonProperty(PropertyName = "d_system", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_system", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
[JsonConverter(typeof(SystemConverter))]
|
||||
public RedumpSystem? System { get; set; }
|
||||
|
||||
// Name not defined by Redump
|
||||
[JsonProperty(PropertyName = "d_media", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_media", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
[JsonConverter(typeof(DiscTypeConverter))]
|
||||
public DiscType? Media { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "d_title", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_title", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
public string? Title { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "d_title_foreign", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
@@ -122,15 +138,15 @@ namespace SabreTools.RedumpLib.Data
|
||||
[JsonProperty(PropertyName = "d_label", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string? DiscTitle { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "d_category", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_category", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
[JsonConverter(typeof(DiscCategoryConverter))]
|
||||
public DiscCategory? Category { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "d_region", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_region", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
[JsonConverter(typeof(RegionConverter))]
|
||||
public Region? Region { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "d_languages", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_languages", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
[JsonConverter(typeof(LanguageConverter))]
|
||||
public Language?[]? Languages { get; set; }
|
||||
|
||||
@@ -147,7 +163,7 @@ namespace SabreTools.RedumpLib.Data
|
||||
[JsonProperty(PropertyName = "d_ring_0_id", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string? RingId { get; private set; }
|
||||
|
||||
[JsonProperty(PropertyName = "d_ring_0_ma1", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_ring_0_ma1", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
public string? Layer0MasteringRing { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "d_ring_0_ma1_sid", NullValueHandling = NullValueHandling.Ignore)]
|
||||
@@ -162,7 +178,7 @@ namespace SabreTools.RedumpLib.Data
|
||||
[JsonProperty(PropertyName = "d_ring_0_mo1", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string? Layer0AdditionalMould { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "d_ring_0_ma2", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_ring_0_ma2", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
public string? Layer1MasteringRing { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "d_ring_0_ma2_sid", NullValueHandling = NullValueHandling.Ignore)]
|
||||
@@ -177,7 +193,7 @@ namespace SabreTools.RedumpLib.Data
|
||||
[JsonProperty(PropertyName = "d_ring_0_mo2", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string? Layer1AdditionalMould { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "d_ring_0_ma3", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_ring_0_ma3", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
public string? Layer2MasteringRing { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "d_ring_0_ma3_sid", NullValueHandling = NullValueHandling.Ignore)]
|
||||
@@ -186,7 +202,7 @@ namespace SabreTools.RedumpLib.Data
|
||||
[JsonProperty(PropertyName = "d_ring_0_ts3", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string? Layer2ToolstampMasteringCode { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "d_ring_0_ma4", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_ring_0_ma4", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
public string? Layer3MasteringRing { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "d_ring_0_ma4_sid", NullValueHandling = NullValueHandling.Ignore)]
|
||||
@@ -233,6 +249,31 @@ namespace SabreTools.RedumpLib.Data
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
#if NET20 || NET35
|
||||
Dictionary<SiteCode, string>? commentsSpecialFields = null;
|
||||
if (this.CommentsSpecialFields != null)
|
||||
{
|
||||
commentsSpecialFields = new Dictionary<SiteCode, string>();
|
||||
foreach (var kvp in this.CommentsSpecialFields)
|
||||
{
|
||||
commentsSpecialFields[kvp.Key] = kvp.Value;
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<SiteCode, string>? contentsSpecialFields = null;
|
||||
if (this.ContentsSpecialFields != null)
|
||||
{
|
||||
contentsSpecialFields = new Dictionary<SiteCode, string>();
|
||||
foreach (var kvp in this.ContentsSpecialFields)
|
||||
{
|
||||
contentsSpecialFields[kvp.Key] = kvp.Value;
|
||||
}
|
||||
}
|
||||
#else
|
||||
var commentsSpecialFields = this.CommentsSpecialFields?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||
var contentsSpecialFields = this.ContentsSpecialFields?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||
#endif
|
||||
|
||||
return new CommonDiscInfoSection
|
||||
{
|
||||
System = this.System,
|
||||
@@ -271,9 +312,9 @@ namespace SabreTools.RedumpLib.Data
|
||||
EXEDateBuildDate = this.EXEDateBuildDate,
|
||||
ErrorsCount = this.ErrorsCount,
|
||||
Comments = this.Comments,
|
||||
CommentsSpecialFields = this.CommentsSpecialFields?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value),
|
||||
CommentsSpecialFields = commentsSpecialFields,
|
||||
Contents = this.Contents,
|
||||
ContentsSpecialFields = this.ContentsSpecialFields?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value),
|
||||
ContentsSpecialFields = contentsSpecialFields,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -414,13 +455,27 @@ namespace SabreTools.RedumpLib.Data
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
#if NET20 || NET35
|
||||
Dictionary<string, List<string>?>? fullProtections = null;
|
||||
if (this.FullProtections != null)
|
||||
{
|
||||
fullProtections = new Dictionary<string, List<string>?>();
|
||||
foreach (var kvp in this.FullProtections)
|
||||
{
|
||||
fullProtections[kvp.Key] = kvp.Value;
|
||||
}
|
||||
}
|
||||
#else
|
||||
var fullProtections = this.FullProtections?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||
#endif
|
||||
|
||||
return new CopyProtectionSection
|
||||
{
|
||||
AntiModchip = this.AntiModchip,
|
||||
LibCrypt = this.LibCrypt,
|
||||
LibCryptData = this.LibCryptData,
|
||||
Protection = this.Protection,
|
||||
FullProtections = this.FullProtections?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value),
|
||||
FullProtections = fullProtections,
|
||||
SecuROMData = this.SecuROMData,
|
||||
};
|
||||
}
|
||||
@@ -531,35 +586,35 @@ namespace SabreTools.RedumpLib.Data
|
||||
public class DumpingInfoSection : ICloneable
|
||||
{
|
||||
// Name not defined by Redump -- Only used with MPF
|
||||
[JsonProperty(PropertyName = "d_frontend_version", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_frontend_version", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
public string? FrontendVersion { get; set; }
|
||||
|
||||
// Name not defined by Redump
|
||||
[JsonProperty(PropertyName = "d_dumping_program", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_dumping_program", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
public string? DumpingProgram { get; set; }
|
||||
|
||||
// Name not defined by Redump
|
||||
[JsonProperty(PropertyName = "d_dumping_date", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_dumping_date", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
public string? DumpingDate { get; set; }
|
||||
|
||||
// Name not defined by Redump
|
||||
[JsonProperty(PropertyName = "d_dumping_params", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_dumping_params", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
public string? DumpingParameters { get; set; }
|
||||
|
||||
// Name not defined by Redump
|
||||
[JsonProperty(PropertyName = "d_drive_manufacturer", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_drive_manufacturer", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
public string? Manufacturer { get; set; }
|
||||
|
||||
// Name not defined by Redump
|
||||
[JsonProperty(PropertyName = "d_drive_model", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_drive_model", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
public string? Model { get; set; }
|
||||
|
||||
// Name not defined by Redump
|
||||
[JsonProperty(PropertyName = "d_drive_firmware", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_drive_firmware", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
public string? Firmware { get; set; }
|
||||
|
||||
// Name not defined by Redump
|
||||
[JsonProperty(PropertyName = "d_reported_disc_type", Required = Required.AllowNull)]
|
||||
[JsonProperty(PropertyName = "d_reported_disc_type", DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
public string? ReportedDiscType { get; set; }
|
||||
|
||||
// Name not defined by Redump -- Only used with Redumper
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using SabreTools.RedumpLib.Data;
|
||||
using SabreTools.RedumpLib.Web;
|
||||
|
||||
@@ -51,6 +52,11 @@ namespace SabreTools.RedumpLib
|
||||
/// </summary>
|
||||
public bool OnlyList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Don't replace forward slashes with `-` in queries
|
||||
/// </summary>
|
||||
public bool NoSlash { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Force continuing downloads until user cancels or pages run out
|
||||
/// </summary>
|
||||
@@ -97,49 +103,85 @@ namespace SabreTools.RedumpLib
|
||||
/// <summary>
|
||||
/// Run the downloads that should go
|
||||
/// </summary>
|
||||
/// <returns>True if there was a valid download type, false otherwise</returns>
|
||||
public async Task<bool> Download()
|
||||
/// <returns>List of IDs that were processed on success, empty on error</returns>
|
||||
/// <remarks>Packs will never return anything other than empty</remarks>
|
||||
public async Task<List<int>> Download()
|
||||
{
|
||||
// Login to Redump, if possible
|
||||
if (!_client.LoggedIn)
|
||||
await _client.Login(Username ?? string.Empty, Password ?? string.Empty);
|
||||
|
||||
// Create output list
|
||||
List<int> processedIds = [];
|
||||
|
||||
switch (Feature)
|
||||
{
|
||||
case Feature.Site:
|
||||
if (OnlyNew)
|
||||
await Discs.DownloadLastModified(_client, OutDir, Force);
|
||||
else
|
||||
await Discs.DownloadSiteRange(_client, OutDir, MinimumId, MaximumId);
|
||||
break;
|
||||
case Feature.WIP:
|
||||
if (OnlyNew)
|
||||
await WIP.DownloadLastSubmitted(_client, OutDir);
|
||||
else
|
||||
await WIP.DownloadWIPRange(_client, OutDir, MinimumId, MaximumId);
|
||||
break;
|
||||
case Feature.Packs:
|
||||
await Packs.DownloadPacks(_client, OutDir, UseSubfolders);
|
||||
break;
|
||||
case Feature.User:
|
||||
if (OnlyList)
|
||||
await User.ListUser(_client, Username);
|
||||
else if (OnlyNew)
|
||||
await User.DownloadUserLastModified(_client, Username, OutDir);
|
||||
else
|
||||
await User.DownloadUser(_client, Username, OutDir);
|
||||
break;
|
||||
case Feature.Quicksearch:
|
||||
if (OnlyList)
|
||||
await Search.ListSearchResults(_client, QueryString);
|
||||
else
|
||||
await Search.DownloadSearchResults(_client, QueryString, OutDir);
|
||||
processedIds = await ProcessQuicksearch();
|
||||
break;
|
||||
case Feature.Site:
|
||||
processedIds = await ProcessSite();
|
||||
break;
|
||||
case Feature.User:
|
||||
processedIds = await ProcessUser();
|
||||
break;
|
||||
case Feature.WIP:
|
||||
processedIds = await ProcessWIP();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
return [];
|
||||
}
|
||||
|
||||
return true;
|
||||
return processedIds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process the Quicksearch feature
|
||||
/// </summary>
|
||||
private async Task<List<int>> ProcessQuicksearch()
|
||||
{
|
||||
if (OnlyList)
|
||||
return await Search.ListSearchResults(_client, QueryString, NoSlash);
|
||||
else
|
||||
return await Search.DownloadSearchResults(_client, QueryString, OutDir, NoSlash);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process the Site feature
|
||||
/// </summary>
|
||||
private async Task<List<int>> ProcessSite()
|
||||
{
|
||||
if (OnlyNew)
|
||||
return await Discs.DownloadLastModified(_client, OutDir, Force);
|
||||
else
|
||||
return await Discs.DownloadSiteRange(_client, OutDir, MinimumId, MaximumId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process the User feature
|
||||
/// </summary>
|
||||
private async Task<List<int>> ProcessUser()
|
||||
{
|
||||
if (OnlyList)
|
||||
return await User.ListUser(_client, Username);
|
||||
else if (OnlyNew)
|
||||
return await User.DownloadUserLastModified(_client, Username, OutDir);
|
||||
else
|
||||
return await User.DownloadUser(_client, Username, OutDir);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process the WIP feature
|
||||
/// </summary>
|
||||
private async Task<List<int>> ProcessWIP()
|
||||
{
|
||||
if (OnlyNew)
|
||||
return await WIP.DownloadLastSubmitted(_client, OutDir);
|
||||
else
|
||||
return await WIP.DownloadWIPRange(_client, OutDir, MinimumId, MaximumId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using SabreTools.RedumpLib.Data;
|
||||
|
||||
@@ -14,11 +13,14 @@ namespace SabreTools.RedumpLib
|
||||
/// <param name="info">Information object that should contain normalized values</param>
|
||||
/// <param name="enableRedumpCompatibility">True to enable Redump compatiblity, false otherwise</param>
|
||||
/// <returns>List of strings representing each line of an output file, null on error</returns>
|
||||
public static (List<string>?, string?) FormatOutputData(SubmissionInfo? info, bool enableRedumpCompatibility)
|
||||
public static List<string>? FormatOutputData(SubmissionInfo? info, bool enableRedumpCompatibility, out string? status)
|
||||
{
|
||||
// Check to see if the inputs are valid
|
||||
if (info == null)
|
||||
return (null, "Submission information was missing");
|
||||
{
|
||||
status = "Submission information was missing";
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
@@ -55,8 +57,10 @@ namespace SabreTools.RedumpLib
|
||||
AddIfExists(output, Template.FullyMatchingIDField, info.FullyMatchedID?.ToString(), 1);
|
||||
AddIfExists(output, Template.PartiallyMatchingIDsField, info.PartiallyMatchedIDs, 1);
|
||||
AddIfExists(output, Template.RegionField, info.CommonDiscInfo?.Region.LongName() ?? "SPACE! (CHANGE THIS)", 1);
|
||||
AddIfExists(output, Template.LanguagesField, (info.CommonDiscInfo?.Languages ?? [null]).Select(l => l.LongName() ?? "SILENCE! (CHANGE THIS)").ToArray(), 1);
|
||||
AddIfExists(output, Template.PlaystationLanguageSelectionViaField, (info.CommonDiscInfo?.LanguageSelection ?? []).Select(l => l.LongName()).ToArray(), 1);
|
||||
AddIfExists(output, Template.LanguagesField,
|
||||
Array.ConvertAll(info.CommonDiscInfo?.Languages ?? [null], l => l.LongName() ?? "SILENCE! (CHANGE THIS)"), 1);
|
||||
AddIfExists(output, Template.PlaystationLanguageSelectionViaField,
|
||||
Array.ConvertAll(info.CommonDiscInfo?.LanguageSelection ?? [], l => l.LongName()), 1);
|
||||
AddIfExists(output, Template.DiscSerialField, info.CommonDiscInfo?.Serial, 1);
|
||||
|
||||
// All ringcode information goes in an indented area
|
||||
@@ -254,11 +258,13 @@ namespace SabreTools.RedumpLib
|
||||
}
|
||||
}
|
||||
|
||||
return (output, "Formatting complete!");
|
||||
status = "Formatting complete!";
|
||||
return output;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return (null, $"Error formatting submission info: {ex}");
|
||||
status = $"Error formatting submission info: {ex}";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +279,7 @@ namespace SabreTools.RedumpLib
|
||||
return;
|
||||
|
||||
// Process the comments field
|
||||
if (info.CommonDiscInfo?.CommentsSpecialFields != null && info.CommonDiscInfo.CommentsSpecialFields?.Any() == true)
|
||||
if (info.CommonDiscInfo?.CommentsSpecialFields != null && info.CommonDiscInfo.CommentsSpecialFields.Count > 0)
|
||||
{
|
||||
// If the field is missing, add an empty one to fill in
|
||||
if (info.CommonDiscInfo.Comments == null)
|
||||
@@ -282,9 +288,9 @@ namespace SabreTools.RedumpLib
|
||||
// Add all special fields before any comments
|
||||
info.CommonDiscInfo.Comments = string.Join(
|
||||
"\n", OrderCommentTags(info.CommonDiscInfo.CommentsSpecialFields)
|
||||
.Where(kvp => !string.IsNullOrEmpty(kvp.Value))
|
||||
.Select(FormatSiteTag)
|
||||
.Where(s => !string.IsNullOrEmpty(s))
|
||||
.FindAll(kvp => !string.IsNullOrEmpty(kvp.Value))
|
||||
.ConvertAll(FormatSiteTag)
|
||||
.FindAll(s => !string.IsNullOrEmpty(s))
|
||||
.ToArray()
|
||||
) + "\n" + info.CommonDiscInfo.Comments;
|
||||
|
||||
@@ -299,7 +305,7 @@ namespace SabreTools.RedumpLib
|
||||
}
|
||||
|
||||
// Process the contents field
|
||||
if (info.CommonDiscInfo?.ContentsSpecialFields != null && info.CommonDiscInfo.ContentsSpecialFields?.Any() == true)
|
||||
if (info.CommonDiscInfo?.ContentsSpecialFields != null && info.CommonDiscInfo.ContentsSpecialFields.Count > 0)
|
||||
{
|
||||
// If the field is missing, add an empty one to fill in
|
||||
if (info.CommonDiscInfo.Contents == null)
|
||||
@@ -308,9 +314,9 @@ namespace SabreTools.RedumpLib
|
||||
// Add all special fields before any contents
|
||||
info.CommonDiscInfo.Contents = string.Join(
|
||||
"\n", OrderContentTags(info.CommonDiscInfo.ContentsSpecialFields)
|
||||
.Where(kvp => !string.IsNullOrEmpty(kvp.Value))
|
||||
.Select(FormatSiteTag)
|
||||
.Where(s => !string.IsNullOrEmpty(s))
|
||||
.FindAll(kvp => !string.IsNullOrEmpty(kvp.Value))
|
||||
.ConvertAll(FormatSiteTag)
|
||||
.FindAll(s => !string.IsNullOrEmpty(s))
|
||||
.ToArray()
|
||||
) + "\n" + info.CommonDiscInfo.Contents;
|
||||
|
||||
@@ -360,7 +366,7 @@ namespace SabreTools.RedumpLib
|
||||
|
||||
// If the value contains a newline
|
||||
value = value.Replace("\r\n", "\n");
|
||||
if (value.Contains('\n'))
|
||||
if (value.Contains("\n"))
|
||||
{
|
||||
output.Add(prefix + key + ":"); output.Add("");
|
||||
string[] values = value.Split('\n');
|
||||
@@ -426,7 +432,7 @@ namespace SabreTools.RedumpLib
|
||||
if (value == null || value.Count == 0)
|
||||
return;
|
||||
|
||||
AddIfExists(output, key, string.Join(", ", value.Select(o => o.ToString()).ToArray()), indent);
|
||||
AddIfExists(output, key, string.Join(", ", [.. value.ConvertAll(o => o.ToString())]), indent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SabreTools.RedumpLib
|
||||
@@ -40,8 +39,13 @@ namespace SabreTools.RedumpLib
|
||||
new StringBuilder(256) :
|
||||
new StringBuilder(value.Length);
|
||||
|
||||
sb.Append(valueSpan.Take(index).ToArray());
|
||||
HtmlDecode(valueSpan.Skip(index).ToArray(), ref sb);
|
||||
char[] take = new char[index];
|
||||
Array.Copy(valueSpan, take, index);
|
||||
sb.Append(take);
|
||||
|
||||
char[] skip = new char[valueSpan.Length - index];
|
||||
Array.Copy(valueSpan, index, skip, 0, skip.Length);
|
||||
HtmlDecode(skip, ref sb);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
@@ -57,7 +61,8 @@ namespace SabreTools.RedumpLib
|
||||
// We found a '&'. Now look for the next ';' or '&'. The idea is that
|
||||
// if we find another '&' before finding a ';', then this is not an entity,
|
||||
// and the next '&' might start a real entity (VSWhidbey 275184)
|
||||
char[] inputSlice = input.Skip(i + 1).ToArray();
|
||||
char[] inputSlice = new char[input.Length - (i + 1)];
|
||||
Array.Copy(input, i + 1, inputSlice, 0, inputSlice.Length);
|
||||
|
||||
int semicolonPos = Array.IndexOf(inputSlice, ';');
|
||||
int ampersandPos = Array.IndexOf(inputSlice, '&');
|
||||
@@ -81,9 +86,13 @@ namespace SabreTools.RedumpLib
|
||||
// å --> same char in hex
|
||||
// See http://www.w3.org/TR/REC-html40/charset.html#entities
|
||||
|
||||
int offset = inputSlice[1] == 'x' || inputSlice[1] == 'X' ? 2 : 1;
|
||||
char[] inputSliceNoPrefix = new char[entityLength - offset];
|
||||
Array.Copy(inputSlice, offset, inputSliceNoPrefix, 0, inputSliceNoPrefix.Length);
|
||||
|
||||
bool parsedSuccessfully = inputSlice[1] == 'x' || inputSlice[1] == 'X'
|
||||
? uint.TryParse(new string(inputSlice.Skip(2).Take(entityLength - 2).ToArray()), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out uint parsedValue)
|
||||
: uint.TryParse(new string(inputSlice.Skip(1).Take(entityLength - 1).ToArray()), NumberStyles.Integer, CultureInfo.InvariantCulture, out parsedValue);
|
||||
? uint.TryParse(new string(inputSliceNoPrefix), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out uint parsedValue)
|
||||
: uint.TryParse(new string(inputSliceNoPrefix), NumberStyles.Integer, CultureInfo.InvariantCulture, out parsedValue);
|
||||
|
||||
if (parsedSuccessfully)
|
||||
{
|
||||
@@ -112,7 +121,8 @@ namespace SabreTools.RedumpLib
|
||||
}
|
||||
else
|
||||
{
|
||||
char[] entity = inputSlice.Take(entityLength).ToArray();
|
||||
char[] entity = new char[entityLength];
|
||||
Array.Copy(inputSlice, entity, entityLength);
|
||||
i = entityEndPosition; // already looked at everything until semicolon
|
||||
char entityChar = HtmlEntities.Lookup(entity);
|
||||
|
||||
@@ -414,7 +424,10 @@ namespace SabreTools.RedumpLib
|
||||
ulong key = BitConverter.ToUInt64(tableData, 0);
|
||||
char value = (char)BitConverter.ToUInt16(tableData, sizeof(ulong));
|
||||
dictionary[key] = value;
|
||||
tableData = tableData.Skip((sizeof(ulong) + sizeof(char))).ToArray();
|
||||
|
||||
byte[] tempTableData = new byte[tableData.Length - (sizeof(ulong) + sizeof(char))];
|
||||
Array.Copy(tableData, (sizeof(ulong) + sizeof(char)), tempTableData, 0, tempTableData.Length);
|
||||
tableData = tempTableData;
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
@@ -1,46 +1,54 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Assembly Properties -->
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>1.4.0</Version>
|
||||
<PropertyGroup>
|
||||
<!-- Assembly Properties -->
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>1.5.2</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
<Description>Code to interact with redump.org</Description>
|
||||
<Copyright>Copyright (c) Matt Nadareski 2020-2024</Copyright>
|
||||
<PackageProjectUrl>https://github.com/SabreTools/</PackageProjectUrl>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<RepositoryUrl>https://github.com/SabreTools/SabreTools.RedumpLib</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>web client redump</PackageTags>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
</PropertyGroup>
|
||||
<!-- Package Properties -->
|
||||
<Authors>Matt Nadareski</Authors>
|
||||
<Description>Code to interact with redump.org</Description>
|
||||
<Copyright>Copyright (c) Matt Nadareski 2020-2024</Copyright>
|
||||
<PackageProjectUrl>https://github.com/SabreTools/</PackageProjectUrl>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<RepositoryUrl>https://github.com/SabreTools/SabreTools.RedumpLib</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>web client redump</PackageTags>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="../README.md" Pack="true" PackagePath="" />
|
||||
</ItemGroup>
|
||||
<!-- Support All Frameworks -->
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net2`)) OR $(TargetFramework.StartsWith(`net3`)) OR $(TargetFramework.StartsWith(`net4`))">
|
||||
<RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`))">
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
|
||||
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Support for old .NET versions -->
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith(`net2`)) OR $(TargetFramework.StartsWith(`net3`))">
|
||||
<PackageReference Include="MinValueTupleBridge" Version="0.2.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith(`net2`)) OR $(TargetFramework.StartsWith(`net3`)) OR $(TargetFramework.StartsWith(`net40`))">
|
||||
<PackageReference Include="MinAsyncBridge" Version="0.12.4" />
|
||||
<PackageReference Include="MinThreadingBridge" Version="0.11.4" />
|
||||
<PackageReference Include="Net30.LinqBridge" Version="1.3.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith(`net4`))">
|
||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="../README.md" Pack="true" PackagePath="" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="SabreTools.Models" Version="1.4.8" />
|
||||
</ItemGroup>
|
||||
<!-- Support for old .NET versions -->
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith(`net2`))">
|
||||
<PackageReference Include="Net30.LinqBridge" Version="1.3.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith(`net2`)) OR $(TargetFramework.StartsWith(`net3`)) OR $(TargetFramework.StartsWith(`net40`))">
|
||||
<PackageReference Include="MinAsyncBridge" Version="0.12.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="SabreTools.Models" Version="1.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using SabreTools.RedumpLib.Data;
|
||||
using SabreTools.RedumpLib.Web;
|
||||
@@ -130,27 +129,27 @@ namespace SabreTools.RedumpLib
|
||||
/// <param name="rc">RedumpClient for making the connection</param>
|
||||
/// <param name="info">Existing SubmissionInfo object to fill</param>
|
||||
/// <param name="sha1">SHA-1 hash to check against</param>
|
||||
/// <returns>True if the track was found, false otherwise; List of found values, if possible</returns>
|
||||
public async static Task<(bool, List<int>?, string?)> ValidateSingleTrack(RedumpClient rc, SubmissionInfo info, string? sha1)
|
||||
/// <returns>List of found values, if possible</returns>
|
||||
public async static Task<List<int>?> ValidateSingleTrack(RedumpClient rc, SubmissionInfo info, string? sha1)
|
||||
{
|
||||
// Get all matching IDs for the track
|
||||
var newIds = await ListSearchResults(rc, sha1);
|
||||
|
||||
// If we got null back, there was an error
|
||||
if (newIds == null)
|
||||
return (false, null, "There was an unknown error retrieving information from Redump");
|
||||
return null;
|
||||
|
||||
// If no IDs match, just return
|
||||
if (!newIds.Any())
|
||||
return (false, null, $"There were no matching IDs for track with SHA-1 of '{sha1}'");
|
||||
if (newIds.Count == 0)
|
||||
return null;
|
||||
|
||||
// Join the list of found IDs to the existing list, if possible
|
||||
if (info.PartiallyMatchedIDs != null && info.PartiallyMatchedIDs.Any())
|
||||
if (info.PartiallyMatchedIDs != null && info.PartiallyMatchedIDs.Count > 0)
|
||||
info.PartiallyMatchedIDs.AddRange(newIds);
|
||||
else
|
||||
info.PartiallyMatchedIDs = newIds;
|
||||
|
||||
return (true, newIds, $"There were matching ID(s) found for track with SHA-1 of '{sha1}'");
|
||||
return newIds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -159,17 +158,17 @@ namespace SabreTools.RedumpLib
|
||||
/// <param name="rc">RedumpClient for making the connection</param>
|
||||
/// <param name="info">Existing SubmissionInfo object to fill</param>
|
||||
/// <param name="resultProgress">Optional result progress callback</param>
|
||||
/// <returns>True if the track was found, false otherwise; List of found values, if possible</returns>
|
||||
public async static Task<(bool, List<int>?, string?)> ValidateUniversalHash(RedumpClient rc, SubmissionInfo info)
|
||||
/// <returns>List of found values, if possible</returns>
|
||||
public async static Task<List<int>?> ValidateUniversalHash(RedumpClient rc, SubmissionInfo info)
|
||||
{
|
||||
// If we don't have special fields
|
||||
if (info.CommonDiscInfo?.CommentsSpecialFields == null)
|
||||
return (false, null, "Universal hash was missing");
|
||||
return null;
|
||||
|
||||
// If we don't have a universal hash
|
||||
string? universalHash = info.CommonDiscInfo.CommentsSpecialFields[SiteCode.UniversalHash];
|
||||
if (string.IsNullOrEmpty(universalHash))
|
||||
return (false, null, "Universal hash was missing");
|
||||
return null;
|
||||
|
||||
// Format the universal hash for finding within the comments
|
||||
string universalHashQuery = $"{universalHash.Substring(0, universalHash.Length - 1)}/comments/only";
|
||||
@@ -179,19 +178,19 @@ namespace SabreTools.RedumpLib
|
||||
|
||||
// If we got null back, there was an error
|
||||
if (newIds == null)
|
||||
return (false, null, "There was an unknown error retrieving information from Redump");
|
||||
return null;
|
||||
|
||||
// If no IDs match, just return
|
||||
if (!newIds.Any())
|
||||
return (false, null, $"There were no matching IDs for universal hash of '{universalHash}'");
|
||||
if (newIds.Count == 0)
|
||||
return null;
|
||||
|
||||
// Join the list of found IDs to the existing list, if possible
|
||||
if (info.PartiallyMatchedIDs != null && info.PartiallyMatchedIDs.Any())
|
||||
if (info.PartiallyMatchedIDs != null && info.PartiallyMatchedIDs.Count > 0)
|
||||
info.PartiallyMatchedIDs.AddRange(newIds);
|
||||
else
|
||||
info.PartiallyMatchedIDs = newIds;
|
||||
|
||||
return (true, newIds, $"There were matching ID(s) found for universal hash of '{universalHash}'");
|
||||
return newIds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using SabreTools.RedumpLib.Data;
|
||||
|
||||
@@ -15,17 +16,22 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <param name="rc">RedumpClient for connectivity</param>
|
||||
/// <param name="outDir">Output directory to save data to</param>
|
||||
/// <param name="force">Force continuation of download</param>
|
||||
public static async Task<bool> DownloadLastModified(RedumpClient rc, string? outDir, bool force)
|
||||
/// <returns>All disc IDs in last modified range, empty on error</returns>
|
||||
public static async Task<List<int>> DownloadLastModified(RedumpClient rc, string? outDir, bool force)
|
||||
{
|
||||
List<int> ids = [];
|
||||
|
||||
// Keep getting last modified pages until there are none left
|
||||
int pageNumber = 1;
|
||||
while (true)
|
||||
{
|
||||
if (!await rc.CheckSingleSitePage(string.Format(Constants.LastModifiedUrl, pageNumber++), outDir, !force))
|
||||
var pageIds = await rc.CheckSingleSitePage(string.Format(Constants.LastModifiedUrl, pageNumber++), outDir, !force);
|
||||
ids.AddRange(pageIds);
|
||||
if (pageIds.Count == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
return ids;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -35,21 +41,25 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <param name="outDir">Output directory to save data to</param>
|
||||
/// <param name="minId">Starting ID for the range</param>
|
||||
/// <param name="maxId">Ending ID for the range (inclusive)</param>
|
||||
public static async Task<bool> DownloadSiteRange(RedumpClient rc, string? outDir, int minId = 0, int maxId = 0)
|
||||
/// <returns>All disc IDs in last modified range, empty on error</returns>
|
||||
public static async Task<List<int>> DownloadSiteRange(RedumpClient rc, string? outDir, int minId = 0, int maxId = 0)
|
||||
{
|
||||
List<int> ids = [];
|
||||
|
||||
if (!rc.LoggedIn)
|
||||
{
|
||||
Console.WriteLine("Site download functionality is only available to Redump members");
|
||||
return false;
|
||||
return ids;
|
||||
}
|
||||
|
||||
for (int id = minId; id <= maxId; id++)
|
||||
{
|
||||
ids.Add(id);
|
||||
if (await rc.DownloadSingleSiteID(id, outDir, true))
|
||||
DelayHelper.DelayRandom(); // Intentional sleep here so we don't flood the server
|
||||
}
|
||||
|
||||
return true;
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using SabreTools.RedumpLib.Data;
|
||||
|
||||
@@ -18,19 +17,15 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <param name="useSubfolders">True to use named subfolders to store downloads, false to store directly in the output directory</param>
|
||||
public static async Task<bool> DownloadPacks(RedumpClient rc, string? outDir, bool useSubfolders)
|
||||
{
|
||||
#if NETFRAMEWORK || NETCOREAPP3_1
|
||||
var systems = Enum.GetValues(typeof(RedumpSystem)).OfType<RedumpSystem>().Select(s => new Nullable<RedumpSystem>(s));
|
||||
#else
|
||||
var systems = Enum.GetValues<RedumpSystem>().Select(s => new RedumpSystem?(s));
|
||||
#endif
|
||||
var systems = (RedumpSystem[])Enum.GetValues(typeof(RedumpSystem));
|
||||
|
||||
await rc.DownloadPacks(Constants.PackCuesUrl, systems.Where(s => s.HasCues()).ToArray(), "CUEs", outDir, useSubfolders ? "cue" : null);
|
||||
await rc.DownloadPacks(Constants.PackDatfileUrl, systems.Where(s => s.HasDat()).ToArray(), "DATs", outDir, useSubfolders ? "dat" : null);
|
||||
await rc.DownloadPacks(Constants.PackDkeysUrl, systems.Where(s => s.HasDkeys()).ToArray(), "Decrypted KEYS", outDir, useSubfolders ? "dkey" : null);
|
||||
await rc.DownloadPacks(Constants.PackGdiUrl, systems.Where(s => s.HasGdi()).ToArray(), "GDIs", outDir, useSubfolders ? "gdi" : null);
|
||||
await rc.DownloadPacks(Constants.PackKeysUrl, systems.Where(s => s.HasKeys()).ToArray(), "KEYS", outDir, useSubfolders ? "keys" : null);
|
||||
await rc.DownloadPacks(Constants.PackLsdUrl, systems.Where(s => s.HasLsd()).ToArray(), "LSD", outDir, useSubfolders ? "lsd" : null);
|
||||
await rc.DownloadPacks(Constants.PackSbiUrl, systems.Where(s => s.HasSbi()).ToArray(), "SBIs", outDir, useSubfolders ? "sbi" : null);
|
||||
await rc.DownloadPacks(Constants.PackCuesUrl, Array.FindAll(systems, s => s.HasCues()), "CUEs", outDir, useSubfolders ? "cue" : null);
|
||||
await rc.DownloadPacks(Constants.PackDatfileUrl, Array.FindAll(systems, s => s.HasDat()), "DATs", outDir, useSubfolders ? "dat" : null);
|
||||
await rc.DownloadPacks(Constants.PackDkeysUrl, Array.FindAll(systems, s => s.HasDkeys()), "Decrypted KEYS", outDir, useSubfolders ? "dkey" : null);
|
||||
await rc.DownloadPacks(Constants.PackGdiUrl, Array.FindAll(systems, s => s.HasGdi()), "GDIs", outDir, useSubfolders ? "gdi" : null);
|
||||
await rc.DownloadPacks(Constants.PackKeysUrl, Array.FindAll(systems, s => s.HasKeys()), "KEYS", outDir, useSubfolders ? "keys" : null);
|
||||
await rc.DownloadPacks(Constants.PackLsdUrl, Array.FindAll(systems, s => s.HasLsd()), "LSD", outDir, useSubfolders ? "lsd" : null);
|
||||
await rc.DownloadPacks(Constants.PackSbiUrl, Array.FindAll(systems, s => s.HasSbi()), "SBIs", outDir, useSubfolders ? "sbi" : null);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -44,7 +39,10 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <param name="useSubfolders">True to use named subfolders to store downloads, false to store directly in the output directory</param>
|
||||
public static async Task<bool> DownloadPacksForSystem(RedumpClient rc, RedumpSystem? system, string? outDir, bool useSubfolders)
|
||||
{
|
||||
var systemAsArray = new RedumpSystem?[] { system };
|
||||
if (system == null)
|
||||
return false;
|
||||
|
||||
var systemAsArray = new RedumpSystem[] { system.Value };
|
||||
|
||||
if (system.HasCues())
|
||||
await rc.DownloadPacks(Constants.PackCuesUrl, systemAsArray, "CUEs", outDir, useSubfolders ? "cue" : null);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
#if NETCOREAPP
|
||||
using System.Net.Http;
|
||||
@@ -74,22 +73,22 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <summary>
|
||||
/// Validate supplied credentials
|
||||
/// </summary>
|
||||
public async static Task<(bool?, string?)> ValidateCredentials(string username, string password)
|
||||
public async static Task<bool?> ValidateCredentials(string username, string password)
|
||||
{
|
||||
// If options are invalid or we're missing something key, just return
|
||||
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
|
||||
return (false, null);
|
||||
return false;
|
||||
|
||||
// Try logging in with the supplied credentials otherwise
|
||||
var redumpClient = new RedumpClient();
|
||||
|
||||
bool? loggedIn = await redumpClient.Login(username, password);
|
||||
if (loggedIn == true)
|
||||
return (true, "Redump username and password accepted!");
|
||||
return true;
|
||||
else if (loggedIn == false)
|
||||
return (false, "Redump username and password denied!");
|
||||
return false;
|
||||
else
|
||||
return (null, "An error occurred validating your credentials!");
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,7 +128,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
try
|
||||
{
|
||||
// Get the current token from the login page
|
||||
var loginPage = await DownloadStringWithRetries(Constants.LoginUrl);
|
||||
var loginPage = await DownloadString(Constants.LoginUrl);
|
||||
string token = Constants.TokenRegex.Match(loginPage ?? string.Empty).Groups[1].Value;
|
||||
|
||||
#if NETFRAMEWORK
|
||||
@@ -187,6 +186,108 @@ namespace SabreTools.RedumpLib.Web
|
||||
|
||||
#endregion
|
||||
|
||||
#region Generic Helpers
|
||||
|
||||
/// <summary>
|
||||
/// Download from a URI to a byte array
|
||||
/// </summary>
|
||||
/// <param name="uri">Remote URI to retrieve</param>
|
||||
/// <returns>Byte array from the URI, null on error</returns>
|
||||
public async Task<byte[]?> DownloadData(string uri)
|
||||
{
|
||||
// Only retry a positive number of times
|
||||
if (RetryCount <= 0)
|
||||
return null;
|
||||
|
||||
for (int i = 0; i < RetryCount; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
#if NET40
|
||||
return await Task.Factory.StartNew(() => _internalClient.DownloadData(uri));
|
||||
#elif NETFRAMEWORK
|
||||
return await Task.Run(() => _internalClient.DownloadData(uri));
|
||||
#else
|
||||
return await _internalClient.GetByteArrayAsync(uri);
|
||||
#endif
|
||||
}
|
||||
catch { }
|
||||
|
||||
// Sleep for 100ms if the last attempt failed
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download from a URI to a local file
|
||||
/// </summary>
|
||||
/// <param name="uri">Remote URI to retrieve</param>
|
||||
/// <param name="fileName">Filename to write to</param>
|
||||
/// <returns>The remote filename from the URI, null on error</returns>
|
||||
public async Task<string?> DownloadFile(string uri, string fileName)
|
||||
{
|
||||
#if NET40
|
||||
await Task.Factory.StartNew(() => { _internalClient.DownloadFile(uri, fileName); return true; });
|
||||
return _internalClient.GetLastFilename();
|
||||
#elif NETFRAMEWORK
|
||||
await Task.Run(() => _internalClient.DownloadFile(uri, fileName));
|
||||
return _internalClient.GetLastFilename();
|
||||
#else
|
||||
// Make the call to get the file
|
||||
var response = await _internalClient.GetAsync(uri);
|
||||
if (response?.Content?.Headers == null || !response.IsSuccessStatusCode)
|
||||
{
|
||||
Console.WriteLine($"Could not download {uri}");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Copy the data to a local temp file
|
||||
using (var responseStream = await response.Content.ReadAsStreamAsync())
|
||||
using (var tempFileStream = File.OpenWrite(fileName))
|
||||
{
|
||||
responseStream.CopyTo(tempFileStream);
|
||||
}
|
||||
|
||||
return response.Content.Headers.ContentDisposition?.FileName?.Replace("\"", "");
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download from a URI to a string
|
||||
/// </summary>
|
||||
/// <param name="uri">Remote URI to retrieve</param>
|
||||
/// <returns>String from the URI, null on error</returns>
|
||||
public async Task<string?> DownloadString(string uri)
|
||||
{
|
||||
// Only retry a positive number of times
|
||||
if (RetryCount <= 0)
|
||||
return null;
|
||||
|
||||
for (int i = 0; i < RetryCount; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
#if NET40
|
||||
return await Task.Factory.StartNew(() => _internalClient.DownloadString(uri));
|
||||
#elif NETFRAMEWORK
|
||||
return await Task.Run(() => _internalClient.DownloadString(uri));
|
||||
#else
|
||||
return await _internalClient.GetStringAsync(uri);
|
||||
#endif
|
||||
}
|
||||
catch { }
|
||||
|
||||
// Sleep for 100ms if the last attempt failed
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Single Page Helpers
|
||||
|
||||
/// <summary>
|
||||
@@ -199,7 +300,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
List<int> ids = [];
|
||||
|
||||
// Try to retrieve the data
|
||||
string? dumpsPage = await DownloadStringWithRetries(url);
|
||||
string? dumpsPage = await DownloadString(url);
|
||||
|
||||
// If we have no dumps left
|
||||
if (dumpsPage == null || dumpsPage.Contains("No discs found."))
|
||||
@@ -217,7 +318,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
|
||||
// Otherwise, traverse each dump on the page
|
||||
var matches = Constants.DiscRegex.Matches(dumpsPage);
|
||||
foreach (Match? match in matches.Cast<Match?>())
|
||||
foreach (Match? match in matches)
|
||||
{
|
||||
if (match == null)
|
||||
continue;
|
||||
@@ -243,15 +344,17 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <param name="url">Base URL to download using</param>
|
||||
/// <param name="outDir">Output directory to save data to</param>
|
||||
/// <param name="failOnSingle">True to return on first error, false otherwise</param>
|
||||
/// <returns>True if the page could be downloaded, false otherwise</returns>
|
||||
public async Task<bool> CheckSingleSitePage(string url, string? outDir, bool failOnSingle)
|
||||
/// <returns>List of IDs that were found on success, empty on error</returns>
|
||||
public async Task<List<int>> CheckSingleSitePage(string url, string? outDir, bool failOnSingle)
|
||||
{
|
||||
List<int> ids = [];
|
||||
|
||||
// Try to retrieve the data
|
||||
string? dumpsPage = await DownloadStringWithRetries(url);
|
||||
string? dumpsPage = await DownloadString(url);
|
||||
|
||||
// If we have no dumps left
|
||||
if (dumpsPage == null || dumpsPage.Contains("No discs found."))
|
||||
return false;
|
||||
return ids;
|
||||
|
||||
// If we have a single disc page already
|
||||
if (dumpsPage.Contains("<b>Download:</b>"))
|
||||
@@ -259,17 +362,18 @@ namespace SabreTools.RedumpLib.Web
|
||||
var value = Regex.Match(dumpsPage, @"/disc/(\d+)/sfv/").Groups[1].Value;
|
||||
if (int.TryParse(value, out int id))
|
||||
{
|
||||
ids.Add(id);
|
||||
bool downloaded = await DownloadSingleSiteID(id, outDir, false);
|
||||
if (!downloaded && failOnSingle)
|
||||
return false;
|
||||
return ids;
|
||||
}
|
||||
|
||||
return false;
|
||||
return ids;
|
||||
}
|
||||
|
||||
// Otherwise, traverse each dump on the page
|
||||
var matches = Constants.DiscRegex.Matches(dumpsPage);
|
||||
foreach (Match? match in matches.Cast<Match?>())
|
||||
foreach (Match? match in matches)
|
||||
{
|
||||
if (match == null)
|
||||
continue;
|
||||
@@ -278,9 +382,10 @@ namespace SabreTools.RedumpLib.Web
|
||||
{
|
||||
if (int.TryParse(match.Groups[1].Value, out int value))
|
||||
{
|
||||
ids.Add(value);
|
||||
bool downloaded = await DownloadSingleSiteID(value, outDir, false);
|
||||
if (!downloaded && failOnSingle)
|
||||
return false;
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -290,7 +395,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return ids;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -303,7 +408,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
List<int> ids = [];
|
||||
|
||||
// Try to retrieve the data
|
||||
string? dumpsPage = await DownloadStringWithRetries(url);
|
||||
string? dumpsPage = await DownloadString(url);
|
||||
|
||||
// If we have no dumps left
|
||||
if (dumpsPage == null || dumpsPage.Contains("No discs found."))
|
||||
@@ -311,7 +416,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
|
||||
// Otherwise, traverse each dump on the page
|
||||
var matches = Constants.NewDiscRegex.Matches(dumpsPage);
|
||||
foreach (Match? match in matches.Cast<Match?>())
|
||||
foreach (Match? match in matches)
|
||||
{
|
||||
if (match == null)
|
||||
continue;
|
||||
@@ -337,19 +442,21 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <param name="wc">RedumpWebClient to access the packs</param>
|
||||
/// <param name="outDir">Output directory to save data to</param>
|
||||
/// <param name="failOnSingle">True to return on first error, false otherwise</param>
|
||||
/// <returns>True if the page could be downloaded, false otherwise</returns>
|
||||
public async Task<bool> CheckSingleWIPPage(string url, string? outDir, bool failOnSingle)
|
||||
/// <returns>List of IDs that were found on success, empty on error</returns>
|
||||
public async Task<List<int>> CheckSingleWIPPage(string url, string? outDir, bool failOnSingle)
|
||||
{
|
||||
List<int> ids = [];
|
||||
|
||||
// Try to retrieve the data
|
||||
string? dumpsPage = await DownloadStringWithRetries(url);
|
||||
string? dumpsPage = await DownloadString(url);
|
||||
|
||||
// If we have no dumps left
|
||||
if (dumpsPage == null || dumpsPage.Contains("No discs found."))
|
||||
return false;
|
||||
return ids;
|
||||
|
||||
// Otherwise, traverse each dump on the page
|
||||
var matches = Constants.NewDiscRegex.Matches(dumpsPage);
|
||||
foreach (Match? match in matches.Cast<Match?>())
|
||||
foreach (Match? match in matches)
|
||||
{
|
||||
if (match == null)
|
||||
continue;
|
||||
@@ -358,9 +465,10 @@ namespace SabreTools.RedumpLib.Web
|
||||
{
|
||||
if (int.TryParse(match.Groups[2].Value, out int value))
|
||||
{
|
||||
ids.Add(value);
|
||||
bool downloaded = await DownloadSingleWIPID(value, outDir, false);
|
||||
if (!downloaded && failOnSingle)
|
||||
return false;
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -370,7 +478,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return ids;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -445,7 +553,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
{
|
||||
// Try to retrieve the data
|
||||
string discPageUri = string.Format(Constants.DiscPageUrl, +id);
|
||||
string? discPage = await DownloadStringWithRetries(discPageUri);
|
||||
string? discPage = await DownloadString(discPageUri);
|
||||
|
||||
if (discPage == null || discPage.Contains($"Disc with ID \"{id}\" doesn't exist"))
|
||||
{
|
||||
@@ -483,7 +591,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
{
|
||||
// Try to retrieve the data
|
||||
string discPageUri = string.Format(Constants.DiscPageUrl, +id);
|
||||
string? discPage = await DownloadStringWithRetries(discPageUri);
|
||||
string? discPage = await DownloadString(discPageUri);
|
||||
|
||||
if (discPage == null || discPage.Contains($"Disc with ID \"{id}\" doesn't exist"))
|
||||
{
|
||||
@@ -607,7 +715,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
{
|
||||
// Try to retrieve the data
|
||||
string discPageUri = string.Format(Constants.WipDiscPageUrl, +id);
|
||||
string? discPage = await DownloadStringWithRetries(discPageUri);
|
||||
string? discPage = await DownloadString(discPageUri);
|
||||
|
||||
if (discPage == null || discPage.Contains($"WIP disc with ID \"{id}\" doesn't exist"))
|
||||
{
|
||||
@@ -645,7 +753,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
{
|
||||
// Try to retrieve the data
|
||||
string discPageUri = string.Format(Constants.WipDiscPageUrl, +id);
|
||||
string? discPage = await DownloadStringWithRetries(discPageUri);
|
||||
string? discPage = await DownloadString(discPageUri);
|
||||
|
||||
if (discPage == null || discPage.Contains($"WIP disc with ID \"{id}\" doesn't exist"))
|
||||
{
|
||||
@@ -719,7 +827,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <param name="url">Base URL to download using</param>
|
||||
/// <param name="system">Systems to download packs for</param>
|
||||
/// <param name="title">Name of the pack that is downloading</param>
|
||||
public async Task<Dictionary<RedumpSystem, byte[]>> DownloadPacks(string url, RedumpSystem?[] systems, string title)
|
||||
public async Task<Dictionary<RedumpSystem, byte[]>> DownloadPacks(string url, RedumpSystem[] systems, string title)
|
||||
{
|
||||
var packsDictionary = new Dictionary<RedumpSystem, byte[]>();
|
||||
|
||||
@@ -727,7 +835,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
foreach (var system in systems)
|
||||
{
|
||||
// If the system is invalid, we can't do anything
|
||||
if (system == null || !system.IsAvailable())
|
||||
if (!system.IsAvailable())
|
||||
continue;
|
||||
|
||||
// If we didn't have credentials
|
||||
@@ -742,7 +850,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
Console.Write($"\r{longName}{new string(' ', Console.BufferWidth - longName!.Length - 1)}");
|
||||
byte[]? pack = await DownloadSinglePack(url, system);
|
||||
if (pack != null)
|
||||
packsDictionary.Add(system.Value, pack);
|
||||
packsDictionary.Add(system, pack);
|
||||
}
|
||||
|
||||
Console.Write($"\rComplete!{new string(' ', Console.BufferWidth - 10)}");
|
||||
@@ -759,13 +867,13 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <param name="title">Name of the pack that is downloading</param>
|
||||
/// <param name="outDir">Output directory to save data to</param>
|
||||
/// <param name="subfolder">Named subfolder for the pack, used optionally</param>
|
||||
public async Task<bool> DownloadPacks(string url, RedumpSystem?[] systems, string title, string? outDir, string? subfolder)
|
||||
public async Task<bool> DownloadPacks(string url, RedumpSystem[] systems, string title, string? outDir, string? subfolder)
|
||||
{
|
||||
Console.WriteLine($"Downloading {title}");
|
||||
foreach (var system in systems)
|
||||
{
|
||||
// If the system is invalid, we can't do anything
|
||||
if (system == null || !system.IsAvailable())
|
||||
if (!system.IsAvailable())
|
||||
continue;
|
||||
|
||||
// If we didn't have credentials
|
||||
@@ -786,72 +894,6 @@ namespace SabreTools.RedumpLib.Web
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download from a URI to a local file
|
||||
/// </summary>
|
||||
/// <param name="uri">Remote URI to retrieve</param>
|
||||
/// <param name="fileName">Filename to write to</param>
|
||||
/// <returns>The remote filename from the URI, null on error</returns>
|
||||
private async Task<string?> DownloadFile(string uri, string fileName)
|
||||
{
|
||||
#if NET40
|
||||
await Task.Factory.StartNew(() => { _internalClient.DownloadFile(uri, fileName); return true; });
|
||||
return _internalClient.GetLastFilename();
|
||||
#elif NETFRAMEWORK
|
||||
await Task.Run(() => _internalClient.DownloadFile(uri, fileName));
|
||||
return _internalClient.GetLastFilename();
|
||||
#else
|
||||
// Make the call to get the file
|
||||
var response = await _internalClient.GetAsync(uri);
|
||||
if (response?.Content?.Headers == null || !response.IsSuccessStatusCode)
|
||||
{
|
||||
Console.WriteLine($"Could not download {uri}");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Copy the data to a local temp file
|
||||
using (var responseStream = await response.Content.ReadAsStreamAsync())
|
||||
using (var tempFileStream = File.OpenWrite(fileName))
|
||||
{
|
||||
responseStream.CopyTo(tempFileStream);
|
||||
}
|
||||
|
||||
return response.Content.Headers.ContentDisposition?.FileName?.Replace("\"", "");
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download from a URI to a string
|
||||
/// </summary>
|
||||
/// <param name="uri">Remote URI to retrieve</param>
|
||||
/// <returns>String from the URI, null on error</returns>
|
||||
private async Task<string?> DownloadStringWithRetries(string uri)
|
||||
{
|
||||
// Only retry a positive number of times
|
||||
if (RetryCount <= 0)
|
||||
return null;
|
||||
|
||||
for (int i = 0; i < RetryCount; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
#if NET40
|
||||
return await Task.Factory.StartNew(() => _internalClient.DownloadString(uri));
|
||||
#elif NETFRAMEWORK
|
||||
return await Task.Run(() => _internalClient.DownloadString(uri));
|
||||
#else
|
||||
return await _internalClient.GetStringAsync(uri);
|
||||
#endif
|
||||
}
|
||||
catch { }
|
||||
|
||||
// Sleep for 100ms if the last attempt failed
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move a tempfile to a new name unless it aleady exists, in which case, delete the tempfile
|
||||
/// </summary>
|
||||
|
||||
@@ -15,12 +15,13 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// </summary>
|
||||
/// <param name="rc">RedumpClient for connectivity</param>
|
||||
/// <param name="query">Query string to attempt to search for</param>
|
||||
/// <returns>All disc IDs for the given query, null on error</returns>
|
||||
public static async Task<List<int>?> ListSearchResults(RedumpClient rc, string? query)
|
||||
/// <param name="noSlash">Don't replace slashes with `-` in queries</param>
|
||||
/// <returns>All disc IDs for the given query, empty on error</returns>
|
||||
public static async Task<List<int>> ListSearchResults(RedumpClient rc, string? query, bool noSlash)
|
||||
{
|
||||
// If the query is invalid
|
||||
if (string.IsNullOrEmpty(query))
|
||||
return null;
|
||||
return [];
|
||||
|
||||
List<int> ids = [];
|
||||
|
||||
@@ -29,8 +30,9 @@ namespace SabreTools.RedumpLib.Web
|
||||
|
||||
// Special characters become dashes
|
||||
query = query.Replace(' ', '-');
|
||||
query = query.Replace('/', '-');
|
||||
query = query.Replace('\\', '/');
|
||||
query = query.Replace('\\', '-');
|
||||
if (!noSlash)
|
||||
query = query.Replace('/', '-');
|
||||
|
||||
// Lowercase is defined per language
|
||||
query = query.ToLowerInvariant();
|
||||
@@ -50,7 +52,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"An exception occurred while trying to log in: {ex}");
|
||||
return null;
|
||||
return [];
|
||||
}
|
||||
|
||||
return ids;
|
||||
@@ -62,19 +64,24 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <param name="rc">RedumpClient for connectivity</param>
|
||||
/// <param name="query">Query string to attempt to search for</param>
|
||||
/// <param name="outDir">Output directory to save data to</param>
|
||||
public static async Task<bool> DownloadSearchResults(RedumpClient rc, string? query, string? outDir)
|
||||
/// <param name="noSlash">Don't replace slashes with `-` in queries</param>
|
||||
/// <returns>All disc IDs for the given query, empty on error</returns>
|
||||
public static async Task<List<int>> DownloadSearchResults(RedumpClient rc, string? query, string? outDir, bool noSlash)
|
||||
{
|
||||
List<int> ids = [];
|
||||
|
||||
// If the query is invalid
|
||||
if (string.IsNullOrEmpty(query))
|
||||
return false;
|
||||
return ids;
|
||||
|
||||
// Strip quotes
|
||||
query = query!.Trim('"', '\'');
|
||||
|
||||
// Special characters become dashes
|
||||
query = query.Replace(' ', '-');
|
||||
query = query.Replace('/', '-');
|
||||
query = query.Replace('\\', '/');
|
||||
query = query.Replace('\\', '-');
|
||||
if (!noSlash)
|
||||
query = query.Replace('/', '-');
|
||||
|
||||
// Lowercase is defined per language
|
||||
query = query.ToLowerInvariant();
|
||||
@@ -83,11 +90,13 @@ namespace SabreTools.RedumpLib.Web
|
||||
int pageNumber = 1;
|
||||
while (true)
|
||||
{
|
||||
if (!await rc.CheckSingleSitePage(string.Format(Constants.QuickSearchUrl, query, pageNumber++), outDir, false))
|
||||
var pageIds = await rc.CheckSingleSitePage(string.Format(Constants.QuickSearchUrl, query, pageNumber++), outDir, false);
|
||||
ids.AddRange(pageIds);
|
||||
if (pageIds.Count == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,23 +16,28 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <param name="rc">RedumpClient for connectivity</param>
|
||||
/// <param name="username">Username to check discs for</param>
|
||||
/// <param name="outDir">Output directory to save data to</param>
|
||||
public static async Task<bool> DownloadUser(RedumpClient rc, string? username, string? outDir)
|
||||
/// <returns>All disc IDs for the given user, empty on error</returns>
|
||||
public static async Task<List<int>> DownloadUser(RedumpClient rc, string? username, string? outDir)
|
||||
{
|
||||
List<int> ids = [];
|
||||
|
||||
if (!rc.LoggedIn || string.IsNullOrEmpty(username))
|
||||
{
|
||||
Console.WriteLine("User download functionality is only available to Redump members");
|
||||
return false;
|
||||
return ids;
|
||||
}
|
||||
|
||||
// Keep getting user pages until there are none left
|
||||
int pageNumber = 1;
|
||||
while (true)
|
||||
{
|
||||
if (!await rc.CheckSingleSitePage(string.Format(Constants.UserDumpsUrl, username, pageNumber++), outDir, false))
|
||||
var pageIds = await rc.CheckSingleSitePage(string.Format(Constants.UserDumpsUrl, username, pageNumber++), outDir, false);
|
||||
ids.AddRange(pageIds);
|
||||
if (pageIds.Count == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
return ids;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -41,23 +46,28 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <param name="rc">RedumpClient for connectivity</param>
|
||||
/// <param name="username">Username to check discs for</param>
|
||||
/// <param name="outDir">Output directory to save data to</param>
|
||||
public static async Task<bool> DownloadUserLastModified(RedumpClient rc, string? username, string? outDir)
|
||||
/// <returns>All disc IDs for the given user, empty on error</returns>
|
||||
public static async Task<List<int>> DownloadUserLastModified(RedumpClient rc, string? username, string? outDir)
|
||||
{
|
||||
List<int> ids = [];
|
||||
|
||||
if (!rc.LoggedIn || string.IsNullOrEmpty(username))
|
||||
{
|
||||
Console.WriteLine("User download functionality is only available to Redump members");
|
||||
return false;
|
||||
return ids;
|
||||
}
|
||||
|
||||
// Keep getting last modified user pages until there are none left
|
||||
int pageNumber = 1;
|
||||
while (true)
|
||||
{
|
||||
if (!await rc.CheckSingleSitePage(string.Format(Constants.UserDumpsLastModifiedUrl, username, pageNumber++), outDir, true))
|
||||
var pageIds = await rc.CheckSingleSitePage(string.Format(Constants.UserDumpsLastModifiedUrl, username, pageNumber++), outDir, true);
|
||||
ids.AddRange(pageIds);
|
||||
if (pageIds.Count == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
return ids;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -65,8 +75,8 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// </summary>
|
||||
/// <param name="rc">RedumpClient for connectivity</param>
|
||||
/// <param name="username">Username to check discs for</param>
|
||||
/// <returns>All disc IDs for the given user, null on error</returns>
|
||||
public static async Task<List<int>?> ListUser(RedumpClient rc, string? username)
|
||||
/// <returns>All disc IDs for the given user, empty on error</returns>
|
||||
public static async Task<List<int>> ListUser(RedumpClient rc, string? username)
|
||||
{
|
||||
List<int> ids = [];
|
||||
|
||||
@@ -82,7 +92,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
int pageNumber = 1;
|
||||
while (true)
|
||||
{
|
||||
List<int> pageIds = await rc.CheckSingleSitePage(string.Format(Constants.UserDumpsUrl, username, pageNumber++));
|
||||
var pageIds = await rc.CheckSingleSitePage(string.Format(Constants.UserDumpsUrl, username, pageNumber++));
|
||||
ids.AddRange(pageIds);
|
||||
if (pageIds.Count <= 1)
|
||||
break;
|
||||
@@ -91,7 +101,7 @@ namespace SabreTools.RedumpLib.Web
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"An exception occurred while trying to log in: {ex}");
|
||||
return null;
|
||||
return [];
|
||||
}
|
||||
|
||||
return ids;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using SabreTools.RedumpLib.Data;
|
||||
|
||||
@@ -14,7 +15,8 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// </summary>
|
||||
/// <param name="rc">RedumpClient for connectivity</param>
|
||||
/// <param name="outDir">Output directory to save data to</param>
|
||||
public static async Task<bool> DownloadLastSubmitted(RedumpClient rc, string? outDir)
|
||||
/// <returns>All disc IDs in last submitted range, empty on error</returns>
|
||||
public static async Task<List<int>> DownloadLastSubmitted(RedumpClient rc, string? outDir)
|
||||
{
|
||||
return await rc.CheckSingleWIPPage(Constants.WipDumpsUrl, outDir, false);
|
||||
}
|
||||
@@ -26,21 +28,25 @@ namespace SabreTools.RedumpLib.Web
|
||||
/// <param name="outDir">Output directory to save data to</param>
|
||||
/// <param name="minId">Starting ID for the range</param>
|
||||
/// <param name="maxId">Ending ID for the range (inclusive)</param>
|
||||
public static async Task<bool> DownloadWIPRange(RedumpClient rc, string? outDir, int minId = 0, int maxId = 0)
|
||||
/// <returns>All disc IDs in last submitted range, empty on error</returns>
|
||||
public static async Task<List<int>> DownloadWIPRange(RedumpClient rc, string? outDir, int minId = 0, int maxId = 0)
|
||||
{
|
||||
List<int> ids = [];
|
||||
|
||||
if (!rc.LoggedIn || !rc.IsStaff)
|
||||
{
|
||||
Console.WriteLine("WIP download functionality is only available to Redump moderators");
|
||||
return false;
|
||||
return ids;
|
||||
}
|
||||
|
||||
for (int id = minId; id <= maxId; id++)
|
||||
{
|
||||
ids.Add(id);
|
||||
if (await rc.DownloadSingleWIPID(id, outDir, true))
|
||||
DelayHelper.DelayRandom(); // Intentional sleep here so we don't flood the server
|
||||
}
|
||||
|
||||
return true;
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
publish-nix.sh
Normal file
36
publish-nix.sh
Normal file
@@ -0,0 +1,36 @@
|
||||
#! /bin/bash
|
||||
|
||||
# This batch file assumes the following:
|
||||
# - .NET 9.0 (or newer) SDK is installed and in PATH
|
||||
#
|
||||
# If any of these are not satisfied, the operation may fail
|
||||
# in an unpredictable way and result in an incomplete output.
|
||||
|
||||
# Optional parameters
|
||||
NO_BUILD=false
|
||||
while getopts "uba" OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
b)
|
||||
NO_BUILD=true
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option provided"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Set the current directory as a variable
|
||||
BUILD_FOLDER=$PWD
|
||||
|
||||
# Only build if requested
|
||||
if [ $NO_BUILD = false ]
|
||||
then
|
||||
# Restore Nuget packages for all builds
|
||||
echo "Restoring Nuget packages"
|
||||
dotnet restore
|
||||
|
||||
# Create Nuget Package
|
||||
dotnet pack SabreTools.RedumpLib/SabreTools.RedumpLib.csproj --output $BUILD_FOLDER
|
||||
fi
|
||||
26
publish-win.ps1
Normal file
26
publish-win.ps1
Normal file
@@ -0,0 +1,26 @@
|
||||
# This batch file assumes the following:
|
||||
# - .NET 9.0 (or newer) SDK is installed and in PATH
|
||||
#
|
||||
# If any of these are not satisfied, the operation may fail
|
||||
# in an unpredictable way and result in an incomplete output.
|
||||
|
||||
# Optional parameters
|
||||
param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
[Alias("NoBuild")]
|
||||
[switch]$NO_BUILD
|
||||
)
|
||||
|
||||
# Set the current directory as a variable
|
||||
$BUILD_FOLDER = $PSScriptRoot
|
||||
|
||||
# Only build if requested
|
||||
if (!$NO_BUILD.IsPresent)
|
||||
{
|
||||
# Restore Nuget packages for all builds
|
||||
Write-Host "Restoring Nuget packages"
|
||||
dotnet restore
|
||||
|
||||
# Create Nuget Package
|
||||
dotnet pack SabreTools.RedumpLib\SabreTools.RedumpLib.csproj --output $BUILD_FOLDER
|
||||
}
|
||||
Reference in New Issue
Block a user