Compare commits

..

11 Commits
1.1.0 ... 1.2.0

Author SHA1 Message Date
Matt Nadareski
1391d90768 Bump version 2023-11-14 13:43:53 -05:00
Matt Nadareski
dfe0c2ffaa Cut off at .NET Framework 4.0 2023-11-08 10:53:03 -05:00
Matt Nadareski
4027470107 Expand supported RIDs 2023-11-08 10:38:30 -05:00
Matt Nadareski
5bccdeaf2c Enable latest language version 2023-11-07 23:06:50 -05:00
Matt Nadareski
27534d2539 Bump left padding to 6 digits 2023-10-29 00:33:26 -04:00
Matt Nadareski
9dea759f8a Update preprocessor directive 2023-09-24 20:18:53 -04:00
Matt Nadareski
55ea639caf Revert to simpler runtime identifiers 2023-09-24 17:24:55 -04:00
Matt Nadareski
cb8ac845d5 Update RIDs for .NET 8.0 RC1 2023-09-24 17:12:12 -04:00
Robert Konrad
bf551e614b Add some system names to ToRedumpSystem that are used by MPF (#1) 2023-09-24 14:03:32 -07:00
Matt Nadareski
1b97aca46e Change runtime identifiers set 2023-09-04 22:38:07 -04:00
Matt Nadareski
b0b9f2099b Add Nuget link 2023-09-04 21:37:57 -04:00
11 changed files with 87 additions and 486 deletions

View File

@@ -10,11 +10,7 @@ namespace SabreTools.RedumpLib.Attributes
/// </summary>
/// <param name="value">Value to use</param>
/// <returns>HumanReadableAttribute attached to the value</returns>
#if NET48
public static HumanReadableAttribute GetAttribute(T value)
#else
public static HumanReadableAttribute? GetAttribute(T value)
#endif
{
// Null value in, null value out
if (value == null)
@@ -26,11 +22,7 @@ namespace SabreTools.RedumpLib.Attributes
enumType = Nullable.GetUnderlyingType(enumType);
// If the value returns a null on ToString, just return null
#if NET48
string valueStr = value?.ToString();
#else
string? valueStr = value?.ToString();
#endif
if (string.IsNullOrWhiteSpace(valueStr))
return null;

View File

@@ -15,19 +15,11 @@ namespace SabreTools.RedumpLib.Attributes
/// <summary>
/// Human-readable name of the item
/// </summary>
#if NET48
public string LongName { get; set; }
#else
public string? LongName { get; set; }
#endif
/// <summary>
/// Internally used name of the item
/// </summary>
#if NET48
public string ShortName { get; set; }
#else
public string? ShortName { get; set; }
#endif
}
}

View File

@@ -11,28 +11,16 @@ namespace SabreTools.RedumpLib.Attributes
/// <summary>
/// ISO 639-1 Code
/// </summary>
#if NET48
public string TwoLetterCode { get; set; } = null;
#else
public string? TwoLetterCode { get; set; }
#endif
/// <summary>
/// ISO 639-2 Code (Standard or Bibliographic)
/// </summary>
#if NET48
public string ThreeLetterCode { get; set; } = null;
#else
public string? ThreeLetterCode { get; set; }
#endif
/// <summary>
/// ISO 639-2 Code (Terminology)
/// </summary>
#if NET48
public string ThreeLetterCodeAlt { get; set; } = null;
#else
public string? ThreeLetterCodeAlt { get; set; }
#endif
}
}

View File

@@ -12,20 +12,12 @@ namespace SabreTools.RedumpLib.Converters
{
public override bool CanRead { get { return false; } }
#if NET48
public override Language?[] ReadJson(JsonReader reader, Type objectType, Language?[] existingValue, bool hasExistingValue, JsonSerializer serializer)
#else
public override Language?[] ReadJson(JsonReader reader, Type objectType, Language?[]? existingValue, bool hasExistingValue, JsonSerializer serializer)
#endif
{
throw new NotImplementedException();
}
#if NET48
public override void WriteJson(JsonWriter writer, Language?[] value, JsonSerializer serializer)
#else
public override void WriteJson(JsonWriter writer, Language?[]? value, JsonSerializer serializer)
#endif
{
if (value == null)
return;

View File

@@ -12,20 +12,12 @@ namespace SabreTools.RedumpLib.Converters
{
public override bool CanRead { get { return false; } }
#if NET48
public override LanguageSelection?[] ReadJson(JsonReader reader, Type objectType, LanguageSelection?[] existingValue, bool hasExistingValue, JsonSerializer serializer)
#else
public override LanguageSelection?[] ReadJson(JsonReader reader, Type objectType, LanguageSelection?[]? existingValue, bool hasExistingValue, JsonSerializer serializer)
#endif
{
throw new NotImplementedException();
}
#if NET48
public override void WriteJson(JsonWriter writer, LanguageSelection?[] value, JsonSerializer serializer)
#else
public override void WriteJson(JsonWriter writer, LanguageSelection?[]? value, JsonSerializer serializer)
#endif
{
if (value == null)
return;

View File

@@ -812,11 +812,7 @@ namespace SabreTools.RedumpLib.Data
/// </summary>
/// <param name="category"></param>
/// <returns></returns>
#if NET48
public static string LongName(this DiscCategory? category) => AttributeHelper<DiscCategory?>.GetAttribute(category)?.LongName;
#else
public static string? LongName(this DiscCategory? category) => AttributeHelper<DiscCategory?>.GetAttribute(category)?.LongName;
#endif
/// <summary>
/// Get the Category enum value for a given string
@@ -865,11 +861,7 @@ namespace SabreTools.RedumpLib.Data
/// </summary>
/// <param name="discType"></param>
/// <returns></returns>
#if NET48
public static string LongName(this DiscType? discType) => AttributeHelper<DiscType?>.GetAttribute(discType)?.LongName;
#else
public static string? LongName(this DiscType? discType) => AttributeHelper<DiscType?>.GetAttribute(discType)?.LongName;
#endif
/// <summary>
/// Get the DiscType enum value for a given string
@@ -955,22 +947,14 @@ namespace SabreTools.RedumpLib.Data
/// </summary>
/// <param name="language"></param>
/// <returns></returns>
#if NET48
public static string LongName(this Language? language) => AttributeHelper<Language?>.GetAttribute(language)?.LongName;
#else
public static string? LongName(this Language? language) => AttributeHelper<Language?>.GetAttribute(language)?.LongName;
#endif
/// <summary>
/// Get the Redump shortnames for each known language
/// </summary>
/// <param name="language"></param>
/// <returns></returns>
#if NET48
public static string ShortName(this Language? language)
#else
public static string? ShortName(this Language? language)
#endif
{
// Some languages need to use the alternate code instead
switch (language)
@@ -1029,33 +1013,21 @@ namespace SabreTools.RedumpLib.Data
/// </summary>
/// <param name="language"></param>
/// <returns></returns>
#if NET48
public static string ThreeLetterCode(this Language? language) => ((LanguageAttribute)AttributeHelper<Language?>.GetAttribute(language))?.ThreeLetterCode;
#else
public static string? ThreeLetterCode(this Language? language) => (AttributeHelper<Language?>.GetAttribute(language) as LanguageAttribute)?.ThreeLetterCode;
#endif
/// <summary>
/// Get the ISO 639-2 alternate code for each known language
/// </summary>
/// <param name="language"></param>
/// <returns></returns>
#if NET48
public static string ThreeLetterCodeAlt(this Language? language) => ((LanguageAttribute)AttributeHelper<Language?>.GetAttribute(language))?.ThreeLetterCodeAlt;
#else
public static string? ThreeLetterCodeAlt(this Language? language) => (AttributeHelper<Language?>.GetAttribute(language) as LanguageAttribute)?.ThreeLetterCodeAlt;
#endif
/// <summary>
/// Get the ISO 639-1 code for each known language
/// </summary>
/// <param name="language"></param>
/// <returns></returns>
#if NET48
public static string TwoLetterCode(this Language? language) => ((LanguageAttribute)AttributeHelper<Language?>.GetAttribute(language))?.TwoLetterCode;
#else
public static string? TwoLetterCode(this Language? language) => (AttributeHelper<Language?>.GetAttribute(language) as LanguageAttribute)?.TwoLetterCode;
#endif
#endregion
@@ -1066,11 +1038,7 @@ namespace SabreTools.RedumpLib.Data
/// </summary>
/// <param name="langSelect">LanguageSelection value to convert</param>
/// <returns>String representing the value, if possible</returns>
#if NET48
public static string LongName(this LanguageSelection? langSelect) => AttributeHelper<LanguageSelection?>.GetAttribute(langSelect)?.LongName;
#else
public static string? LongName(this LanguageSelection? langSelect) => AttributeHelper<LanguageSelection?>.GetAttribute(langSelect)?.LongName;
#endif
#endregion
@@ -1085,7 +1053,7 @@ namespace SabreTools.RedumpLib.Data
foreach (var val in Enum.GetValues(typeof(MediaType)))
{
if (((MediaType)val) == MediaType.NONE)
if (val == null || ((MediaType)val) == MediaType.NONE)
continue;
mediaTypes.Add($"{((MediaType?)val).ShortName()} - {((MediaType?)val).LongName()}");
@@ -1099,22 +1067,14 @@ namespace SabreTools.RedumpLib.Data
/// </summary>
/// <param name="mediaType"></param>
/// <returns></returns>
#if NET48
public static string LongName(this MediaType? mediaType) => AttributeHelper<MediaType?>.GetAttribute(mediaType)?.LongName;
#else
public static string? LongName(this MediaType? mediaType) => AttributeHelper<MediaType?>.GetAttribute(mediaType)?.LongName;
#endif
/// <summary>
/// Get the Redump shortnames for each known media type
/// </summary>
/// <param name="mediaType"></param>
/// <returns></returns>
#if NET48
public static string ShortName(this MediaType? mediaType) => AttributeHelper<MediaType?>.GetAttribute(mediaType)?.ShortName;
#else
public static string? ShortName(this MediaType? mediaType) => AttributeHelper<MediaType?>.GetAttribute(mediaType)?.ShortName;
#endif
#endregion
@@ -1125,22 +1085,14 @@ namespace SabreTools.RedumpLib.Data
/// </summary>
/// <param name="region"></param>
/// <returns></returns>
#if NET48
public static string LongName(this Region? region) => AttributeHelper<Region?>.GetAttribute(region)?.LongName;
#else
public static string? LongName(this Region? region) => AttributeHelper<Region?>.GetAttribute(region)?.LongName;
#endif
/// <summary>
/// Get the Redump shortnames for each known region
/// </summary>
/// <param name="region"></param>
/// <returns></returns>
#if NET48
public static string ShortName(this Region? region) => AttributeHelper<Region?>.GetAttribute(region)?.ShortName;
#else
public static string? ShortName(this Region? region) => AttributeHelper<Region?>.GetAttribute(region)?.ShortName;
#endif
/// <summary>
/// Get the Region enum value for a given string
@@ -1172,22 +1124,14 @@ namespace SabreTools.RedumpLib.Data
/// </summary>
/// <param name="siteCode"></param>
/// <returns></returns>
#if NET48
public static string LongName(this SiteCode? siteCode) => AttributeHelper<SiteCode?>.GetAttribute(siteCode)?.LongName;
#else
public static string? LongName(this SiteCode? siteCode) => AttributeHelper<SiteCode?>.GetAttribute(siteCode)?.LongName;
#endif
/// <summary>
/// Get the short tag for each known site code
/// </summary>
/// <param name="siteCode"></param>
/// <returns></returns>
#if NET48
public static string ShortName(this SiteCode? siteCode) => AttributeHelper<SiteCode?>.GetAttribute(siteCode)?.ShortName;
#else
public static string? ShortName(this SiteCode? siteCode) => AttributeHelper<SiteCode?>.GetAttribute(siteCode)?.ShortName;
#endif
#endregion
@@ -1238,22 +1182,14 @@ namespace SabreTools.RedumpLib.Data
/// </summary>
/// <param name="system"></param>
/// <returns></returns>
#if NET48
public static string LongName(this RedumpSystem? system) => AttributeHelper<RedumpSystem?>.GetAttribute(system)?.LongName;
#else
public static string? LongName(this RedumpSystem? system) => AttributeHelper<RedumpSystem?>.GetAttribute(system)?.LongName;
#endif
/// <summary>
/// Get the Redump shortnames for each known system
/// </summary>
/// <param name="system"></param>
/// <returns></returns>
#if NET48
public static string ShortName(this RedumpSystem? system) => AttributeHelper<RedumpSystem?>.GetAttribute(system)?.ShortName;
#else
public static string? ShortName(this RedumpSystem? system) => AttributeHelper<RedumpSystem?>.GetAttribute(system)?.ShortName;
#endif
/// <summary>
/// Determine the category of a system
@@ -1376,6 +1312,7 @@ namespace SabreTools.RedumpLib.Data
case "atarijagcd":
case "atarijaguarcd":
case "atari jaguar cd":
case "atari jaguar cd interactive multimedia system":
return RedumpSystem.AtariJaguarCDInteractiveMultimediaSystem;
case "qis":
case "playdia":
@@ -1443,6 +1380,7 @@ namespace SabreTools.RedumpLib.Data
case "videonow jr":
case "hasbrovideonowjr":
case "hasbro videonow jr":
case "hasbro videonow jr.":
return RedumpSystem.HasbroVideoNowJr;
case "xvnxp":
case "videonowxp":
@@ -1516,6 +1454,7 @@ namespace SabreTools.RedumpLib.Data
case "nec pc-engine cd":
case "nec turbografx cd":
case "nec pc-engine / turbografx cd":
case "nec pc-engine cd & turbografx cd":
return RedumpSystem.NECPCEngineCDTurboGrafxCD;
case "pcfx":
case "pc-fx":
@@ -1526,6 +1465,7 @@ namespace SabreTools.RedumpLib.Data
case "nec pc-fx":
case "nec pc-fxga":
case "nec pc-fx / pc-fxga":
case "nec pc-fx & pc-fxga":
return RedumpSystem.NECPCFXPCFXGA;
case "gc":
case "gamecube":
@@ -1560,6 +1500,7 @@ namespace SabreTools.RedumpLib.Data
case "sonysupernintendocd":
case "sony super nintendo cd":
case "sony super nintendo-cd":
case "nintendo-sony super nes cd-rom system":
return RedumpSystem.NintendoSonySuperNESCDROMSystem;
case "wii":
case "nintendowii":
@@ -1595,6 +1536,7 @@ namespace SabreTools.RedumpLib.Data
case "sega cd":
case "mega cd":
case "sega cd / mega cd":
case "sega mega cd & sega cd":
return RedumpSystem.SegaMegaCDSegaCD;
case "dc":
case "sdc":
@@ -1698,6 +1640,7 @@ namespace SabreTools.RedumpLib.Data
case "vtech vsmile pro":
case "vtech v.smile pro":
case "vtech v.flash - v.smile pro":
case "vtech v.flash & v.smile pro":
return RedumpSystem.VTechVFlashVSmilePro;
case "gamewave":
case "game wave":
@@ -1729,6 +1672,7 @@ namespace SabreTools.RedumpLib.Data
case "amiga":
case "commodoreamiga":
case "commodore amiga":
case "commodore amiga cd":
return RedumpSystem.CommodoreAmigaCD;
case "fmtowns":
case "fmt":
@@ -1748,12 +1692,14 @@ namespace SabreTools.RedumpLib.Data
case "necpc88":
case "nec pc88":
case "nec pc-88":
case "nec pc-88 series":
return RedumpSystem.NECPC88series;
case "pc98":
case "pc-98":
case "necpc98":
case "nec pc98":
case "nec pc-98":
case "nec pc-98 series":
return RedumpSystem.NECPC98series;
case "x68k":
case "x68kcd":
@@ -1937,6 +1883,7 @@ namespace SabreTools.RedumpLib.Data
case "capcomsupersystem256":
case "capcom super system 256":
case "namco / capcom system 256/super system 256":
case "namco system 246 / system 256":
return RedumpSystem.NamcoSystem246256;
case "triforce":
case "namcotriforce":
@@ -1946,6 +1893,7 @@ namespace SabreTools.RedumpLib.Data
case "nintendotriforce":
case "nintendo triforce":
case "namco / sega / nintendo triforce":
case "Namco · Sega · Nintendo Triforce":
return RedumpSystem.NamcoSegaNintendoTriforce;
case "ns12":
case "system12":
@@ -2104,6 +2052,7 @@ namespace SabreTools.RedumpLib.Data
case "hddvdvideo":
case "hddvd-video":
case "hd-dvd-video":
case "hd dvd-video":
return RedumpSystem.HDDVDVideo;
case "navi21":
case "naviken":
@@ -2116,6 +2065,7 @@ namespace SabreTools.RedumpLib.Data
return RedumpSystem.NavisoftNaviken21;
case "palm":
case "palmos":
case "palm os":
return RedumpSystem.PalmOS;
case "photo":
case "photocd":
@@ -2145,6 +2095,7 @@ namespace SabreTools.RedumpLib.Data
case "segaprologue21":
case "sega prologue21":
case "sega prologue 21":
case "sega prologue 21 multimedia karaoke system":
return RedumpSystem.SegaPrologue21MultimediaKaraokeSystem;
case "electronicbook":
case "sonyelectronicbook":
@@ -2186,11 +2137,7 @@ namespace SabreTools.RedumpLib.Data
/// </summary>
/// <param name="category"></param>
/// <returns></returns>
#if NET48
public static string LongName(this SystemCategory? category) => AttributeHelper<SystemCategory?>.GetAttribute(category)?.LongName;
#else
public static string? LongName(this SystemCategory? category) => AttributeHelper<SystemCategory?>.GetAttribute(category)?.LongName;
#endif
#endregion

View File

@@ -24,11 +24,7 @@ namespace SabreTools.RedumpLib.Data
/// List of partially matched Redump IDs
/// </summary>
[JsonIgnore]
#if NET48
public List<int> PartiallyMatchedIDs { get; set; }
#else
public List<int>? PartiallyMatchedIDs { get; set; }
#endif
/// <summary>
/// DateTime of when the disc was added
@@ -43,81 +39,37 @@ namespace SabreTools.RedumpLib.Data
public DateTime? LastModified { get; set; }
[JsonProperty(PropertyName = "common_disc_info", DefaultValueHandling = DefaultValueHandling.Ignore)]
#if NET48
public CommonDiscInfoSection CommonDiscInfo { get; set; } = new CommonDiscInfoSection();
#else
public CommonDiscInfoSection? CommonDiscInfo { get; set; } = new CommonDiscInfoSection();
#endif
[JsonProperty(PropertyName = "versions_and_editions", DefaultValueHandling = DefaultValueHandling.Ignore)]
#if NET48
public VersionAndEditionsSection VersionAndEditions { get; set; } = new VersionAndEditionsSection();
#else
public VersionAndEditionsSection? VersionAndEditions { get; set; } = new VersionAndEditionsSection();
#endif
[JsonProperty(PropertyName = "edc", DefaultValueHandling = DefaultValueHandling.Ignore)]
#if NET48
public EDCSection EDC { get; set; } = new EDCSection();
#else
public EDCSection? EDC { get; set; } = new EDCSection();
#endif
[JsonProperty(PropertyName = "parent_clone_relationship", DefaultValueHandling = DefaultValueHandling.Ignore)]
#if NET48
public ParentCloneRelationshipSection ParentCloneRelationship { get; set; } = new ParentCloneRelationshipSection();
#else
public ParentCloneRelationshipSection? ParentCloneRelationship { get; set; } = new ParentCloneRelationshipSection();
#endif
[JsonProperty(PropertyName = "extras", DefaultValueHandling = DefaultValueHandling.Ignore)]
#if NET48
public ExtrasSection Extras { get; set; } = new ExtrasSection();
#else
public ExtrasSection? Extras { get; set; } = new ExtrasSection();
#endif
[JsonProperty(PropertyName = "copy_protection", DefaultValueHandling = DefaultValueHandling.Ignore)]
#if NET48
public CopyProtectionSection CopyProtection { get; set; } = new CopyProtectionSection();
#else
public CopyProtectionSection? CopyProtection { get; set; } = new CopyProtectionSection();
#endif
[JsonProperty(PropertyName = "dumpers_and_status", DefaultValueHandling = DefaultValueHandling.Ignore)]
#if NET48
public DumpersAndStatusSection DumpersAndStatus { get; set; } = new DumpersAndStatusSection();
#else
public DumpersAndStatusSection? DumpersAndStatus { get; set; } = new DumpersAndStatusSection();
#endif
[JsonProperty(PropertyName = "tracks_and_write_offsets", DefaultValueHandling = DefaultValueHandling.Ignore)]
#if NET48
public TracksAndWriteOffsetsSection TracksAndWriteOffsets { get; set; } = new TracksAndWriteOffsetsSection();
#else
public TracksAndWriteOffsetsSection? TracksAndWriteOffsets { get; set; } = new TracksAndWriteOffsetsSection();
#endif
[JsonProperty(PropertyName = "size_and_checksums", DefaultValueHandling = DefaultValueHandling.Ignore)]
#if NET48
public SizeAndChecksumsSection SizeAndChecksums { get; set; } = new SizeAndChecksumsSection();
#else
public SizeAndChecksumsSection? SizeAndChecksums { get; set; } = new SizeAndChecksumsSection();
#endif
[JsonProperty(PropertyName = "dumping_info", DefaultValueHandling = DefaultValueHandling.Ignore)]
#if NET48
public DumpingInfoSection DumpingInfo { get; set; } = new DumpingInfoSection();
#else
public DumpingInfoSection? DumpingInfo { get; set; } = new DumpingInfoSection();
#endif
[JsonProperty(PropertyName = "artifacts", DefaultValueHandling = DefaultValueHandling.Ignore)]
#if NET48
public Dictionary<string, string> Artifacts { get; set; } = new Dictionary<string, string>();
#else
public Dictionary<string, string>? Artifacts { get; set; } = new Dictionary<string, string>();
#endif
public object Clone()
{
@@ -159,32 +111,16 @@ namespace SabreTools.RedumpLib.Data
public DiscType? Media { get; set; }
[JsonProperty(PropertyName = "d_title", Required = Required.AllowNull)]
#if NET48
public string Title { get; set; }
#else
public string? Title { get; set; }
#endif
[JsonProperty(PropertyName = "d_title_foreign", DefaultValueHandling = DefaultValueHandling.Ignore)]
#if NET48
public string ForeignTitleNonLatin { get; set; }
#else
public string? ForeignTitleNonLatin { get; set; }
#endif
[JsonProperty(PropertyName = "d_number", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string DiscNumberLetter { get; set; }
#else
public string? DiscNumberLetter { get; set; }
#endif
[JsonProperty(PropertyName = "d_label", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string DiscTitle { get; set; }
#else
public string? DiscTitle { get; set; }
#endif
[JsonProperty(PropertyName = "d_category", Required = Required.AllowNull)]
[JsonConverter(typeof(DiscCategoryConverter))]
@@ -196,228 +132,104 @@ namespace SabreTools.RedumpLib.Data
[JsonProperty(PropertyName = "d_languages", Required = Required.AllowNull)]
[JsonConverter(typeof(LanguageConverter))]
#if NET48
public Language?[] Languages { get; set; }
#else
public Language?[]? Languages { get; set; }
#endif
[JsonProperty(PropertyName = "d_languages_selection", NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore)]
[JsonConverter(typeof(LanguageSelectionConverter))]
#if NET48
public LanguageSelection?[] LanguageSelection { get; set; }
#else
public LanguageSelection?[]? LanguageSelection { get; set; }
#endif
[JsonProperty(PropertyName = "d_serial", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Serial { get; set; }
#else
public string? Serial { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Ring { get; private set; }
#else
public string? Ring { get; private set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_id", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string RingId { get; private set; }
#else
public string? RingId { get; private set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_ma1", Required = Required.AllowNull)]
#if NET48
public string Layer0MasteringRing { get; set; }
#else
public string? Layer0MasteringRing { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_ma1_sid", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Layer0MasteringSID { get; set; }
#else
public string? Layer0MasteringSID { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_ts1", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Layer0ToolstampMasteringCode { get; set; }
#else
public string? Layer0ToolstampMasteringCode { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_mo1_sid", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Layer0MouldSID { get; set; }
#else
public string? Layer0MouldSID { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_mo1", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Layer0AdditionalMould { get; set; }
#else
public string? Layer0AdditionalMould { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_ma2", Required = Required.AllowNull)]
#if NET48
public string Layer1MasteringRing { get; set; }
#else
public string? Layer1MasteringRing { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_ma2_sid", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Layer1MasteringSID { get; set; }
#else
public string? Layer1MasteringSID { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_ts2", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Layer1ToolstampMasteringCode { get; set; }
#else
public string? Layer1ToolstampMasteringCode { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_mo2_sid", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Layer1MouldSID { get; set; }
#else
public string? Layer1MouldSID { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_mo2", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Layer1AdditionalMould { get; set; }
#else
public string? Layer1AdditionalMould { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_ma3", Required = Required.AllowNull)]
#if NET48
public string Layer2MasteringRing { get; set; }
#else
public string? Layer2MasteringRing { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_ma3_sid", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Layer2MasteringSID { get; set; }
#else
public string? Layer2MasteringSID { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_ts3", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Layer2ToolstampMasteringCode { get; set; }
#else
public string? Layer2ToolstampMasteringCode { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_ma4", Required = Required.AllowNull)]
#if NET48
public string Layer3MasteringRing { get; set; }
#else
public string? Layer3MasteringRing { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_ma4_sid", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Layer3MasteringSID { get; set; }
#else
public string? Layer3MasteringSID { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_ts4", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Layer3ToolstampMasteringCode { get; set; }
#else
public string? Layer3ToolstampMasteringCode { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_offsets", NullValueHandling = NullValueHandling.Ignore)]
public string RingOffsetsHidden { get { return "1"; } }
[JsonProperty(PropertyName = "d_ring_0_0_id", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string RingZeroId { get; private set; }
#else
public string? RingZeroId { get; private set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_0_density", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string RingZeroDensity { get; private set; }
#else
public string? RingZeroDensity { get; private set; }
#endif
[JsonProperty(PropertyName = "d_ring_0_0_value", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string RingWriteOffset { get; set; }
#else
public string? RingWriteOffset { get; set; }
#endif
[JsonProperty(PropertyName = "d_ring_count", NullValueHandling = NullValueHandling.Ignore)]
public string RingCount { get { return "1"; } }
[JsonProperty(PropertyName = "d_barcode", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Barcode { get; set; }
#else
public string? Barcode { get; set; }
#endif
[JsonProperty(PropertyName = "d_date", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string EXEDateBuildDate { get; set; }
#else
public string? EXEDateBuildDate { get; set; }
#endif
[JsonProperty(PropertyName = "d_errors", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string ErrorsCount { get; set; }
#else
public string? ErrorsCount { get; set; }
#endif
[JsonProperty(PropertyName = "d_comments", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Comments { get; set; }
#else
public string? Comments { get; set; }
#endif
[JsonIgnore]
#if NET48
public Dictionary<SiteCode?, string> CommentsSpecialFields { get; set; }
#else
public Dictionary<SiteCode, string>? CommentsSpecialFields { get; set; }
#endif
[JsonProperty(PropertyName = "d_contents", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Contents { get; set; }
#else
public string? Contents { get; set; }
#endif
[JsonIgnore]
#if NET48
public Dictionary<SiteCode?, string> ContentsSpecialFields { get; set; }
#else
public Dictionary<SiteCode, string>? ContentsSpecialFields { get; set; }
#endif
public object Clone()
{
@@ -472,32 +284,16 @@ namespace SabreTools.RedumpLib.Data
public class VersionAndEditionsSection : ICloneable
{
[JsonProperty(PropertyName = "d_version", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Version { get; set; }
#else
public string? Version { get; set; }
#endif
[JsonProperty(PropertyName = "d_version_datfile", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string VersionDatfile { get; set; }
#else
public string? VersionDatfile { get; set; }
#endif
[JsonProperty(PropertyName = "d_editions", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string[] CommonEditions { get; set; }
#else
public string[]? CommonEditions { get; set; }
#endif
[JsonProperty(PropertyName = "d_editions_text", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string OtherEditions { get; set; }
#else
public string? OtherEditions { get; set; }
#endif
public object Clone()
{
@@ -535,11 +331,7 @@ namespace SabreTools.RedumpLib.Data
public class ParentCloneRelationshipSection : ICloneable
{
[JsonProperty(PropertyName = "d_parent_id", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string ParentID { get; set; }
#else
public string? ParentID { get; set; }
#endif
[JsonProperty(PropertyName = "d_is_regional_parent", NullValueHandling = NullValueHandling.Ignore)]
public bool RegionalParent { get; set; }
@@ -560,53 +352,25 @@ namespace SabreTools.RedumpLib.Data
public class ExtrasSection : ICloneable
{
[JsonProperty(PropertyName = "d_pvd", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string PVD { get; set; }
#else
public string? PVD { get; set; }
#endif
[JsonProperty(PropertyName = "d_d1_key", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string DiscKey { get; set; }
#else
public string? DiscKey { get; set; }
#endif
[JsonProperty(PropertyName = "d_d2_key", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string DiscID { get; set; }
#else
public string? DiscID { get; set; }
#endif
[JsonProperty(PropertyName = "d_pic_data", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string PIC { get; set; }
#else
public string? PIC { get; set; }
#endif
[JsonProperty(PropertyName = "d_header", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Header { get; set; }
#else
public string? Header { get; set; }
#endif
[JsonProperty(PropertyName = "d_bca", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string BCA { get; set; }
#else
public string? BCA { get; set; }
#endif
[JsonProperty(PropertyName = "d_ssranges", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string SecuritySectorRanges { get; set; }
#else
public string? SecuritySectorRanges { get; set; }
#endif
public object Clone()
{
@@ -637,32 +401,16 @@ namespace SabreTools.RedumpLib.Data
public YesNo? LibCrypt { get; set; }
[JsonProperty(PropertyName = "d_libcrypt", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string LibCryptData { get; set; }
#else
public string? LibCryptData { get; set; }
#endif
[JsonProperty(PropertyName = "d_protection", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Protection { get; set; }
#else
public string? Protection { get; set; }
#endif
[JsonIgnore]
#if NET48
public Dictionary<string, List<string>> FullProtections { get; set; }
#else
public Dictionary<string, List<string>?>? FullProtections { get; set; }
#endif
[JsonProperty(PropertyName = "d_securom", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string SecuROMData { get; set; }
#else
public string? SecuROMData { get; set; }
#endif
public object Clone()
{
@@ -687,18 +435,10 @@ namespace SabreTools.RedumpLib.Data
public DumpStatus Status { get; set; }
[JsonProperty(PropertyName = "d_dumpers", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string[] Dumpers { get; set; }
#else
public string[]? Dumpers { get; set; }
#endif
[JsonProperty(PropertyName = "d_dumpers_text", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string OtherDumpers { get; set; }
#else
public string? OtherDumpers { get; set; }
#endif
public object Clone()
{
@@ -717,32 +457,16 @@ namespace SabreTools.RedumpLib.Data
public class TracksAndWriteOffsetsSection : ICloneable
{
[JsonProperty(PropertyName = "d_tracks", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string ClrMameProData { get; set; }
#else
public string? ClrMameProData { get; set; }
#endif
[JsonProperty(PropertyName = "d_cue", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string Cuesheet { get; set; }
#else
public string? Cuesheet { get; set; }
#endif
[JsonProperty(PropertyName = "d_offset", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public int[] CommonWriteOffsets { get; set; }
#else
public int[]? CommonWriteOffsets { get; set; }
#endif
[JsonProperty(PropertyName = "d_offset_text", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string OtherWriteOffsets { get; set; }
#else
public string? OtherWriteOffsets { get; set; }
#endif
public object Clone()
{
@@ -771,35 +495,19 @@ namespace SabreTools.RedumpLib.Data
public long Layerbreak3 { get; set; }
[JsonProperty(PropertyName = "d_pic_identifier", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string PICIdentifier { get; set; }
#else
public string? PICIdentifier { get; set; }
#endif
[JsonProperty(PropertyName = "d_size", NullValueHandling = NullValueHandling.Ignore)]
public long Size { get; set; }
[JsonProperty(PropertyName = "d_crc32", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string CRC32 { get; set; }
#else
public string? CRC32 { get; set; }
#endif
[JsonProperty(PropertyName = "d_md5", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string MD5 { get; set; }
#else
public string? MD5 { get; set; }
#endif
[JsonProperty(PropertyName = "d_sha1", NullValueHandling = NullValueHandling.Ignore)]
#if NET48
public string SHA1 { get; set; }
#else
public string? SHA1 { get; set; }
#endif
public object Clone()
{
@@ -824,51 +532,27 @@ namespace SabreTools.RedumpLib.Data
{
// Name not defined by Redump
[JsonProperty(PropertyName = "d_dumping_program", Required = Required.AllowNull)]
#if NET48
public string DumpingProgram { get; set; }
#else
public string? DumpingProgram { get; set; }
#endif
// Name not defined by Redump
[JsonProperty(PropertyName = "d_dumping_date", Required = Required.AllowNull)]
#if NET48
public string DumpingDate { get; set; }
#else
public string? DumpingDate { get; set; }
#endif
// Name not defined by Redump
[JsonProperty(PropertyName = "d_drive_manufacturer", Required = Required.AllowNull)]
#if NET48
public string Manufacturer { get; set; }
#else
public string? Manufacturer { get; set; }
#endif
// Name not defined by Redump
[JsonProperty(PropertyName = "d_drive_model", Required = Required.AllowNull)]
#if NET48
public string Model { get; set; }
#else
public string? Model { get; set; }
#endif
// Name not defined by Redump
[JsonProperty(PropertyName = "d_drive_firmware", Required = Required.AllowNull)]
#if NET48
public string Firmware { get; set; }
#else
public string? Firmware { get; set; }
#endif
// Name not defined by Redump
[JsonProperty(PropertyName = "d_reported_disc_type", Required = Required.AllowNull)]
#if NET48
public string ReportedDiscType { get; set; }
#else
public string? ReportedDiscType { get; set; }
#endif
public object Clone()
{

View File

@@ -1,3 +1,5 @@
# SabreTools.RedumpLib
This library comprises interaction logic for [Redump](http://redump.org/). Because there is no formal API for the site, this library interacts with the site through normal HTTP methods. It includes a fairly comprehensive reference of supported parts of the site, including URLs, page information, and packs.
Find the link to the Nuget package [here](https://www.nuget.org/packages/SabreTools.RedumpLib).

View File

@@ -2,9 +2,12 @@
<PropertyGroup>
<!-- Assembly Properties -->
<TargetFrameworks>net48;net6.0;net7.0;net8.0</TargetFrameworks>
<RuntimeIdentifiers>win-x86;win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
<Version>1.1.0</Version>
<TargetFrameworks>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.2.0</Version>
<!-- Package Properties -->
<Authors>Matt Nadareski</Authors>
@@ -18,14 +21,15 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)'!='net48'">
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath=""/>
</ItemGroup>
<!-- Support for old .NET versions -->
<ItemGroup Condition="$(TargetFramework.StartsWith(`net4`))">
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

View File

@@ -1,4 +1,4 @@
#if NET5_0_OR_GREATER
#if !NETFRAMEWORK
using System;
using System.Collections.Generic;
@@ -170,8 +170,11 @@ namespace SabreTools.RedumpLib.Web
// Otherwise, traverse each dump on the page
var matches = Constants.DiscRegex.Matches(dumpsPage);
foreach (Match match in matches)
foreach (Match? match in matches)
{
if (match == null)
continue;
try
{
if (int.TryParse(match.Groups[1].Value, out int value))
@@ -194,7 +197,7 @@ namespace SabreTools.RedumpLib.Web
/// <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)
public async Task<bool> CheckSingleSitePage(string url, string? outDir, bool failOnSingle)
{
// Try up to 3 times to retrieve the data
string? dumpsPage = await DownloadString(url, retries: 3);
@@ -219,8 +222,11 @@ namespace SabreTools.RedumpLib.Web
// Otherwise, traverse each dump on the page
var matches = Constants.DiscRegex.Matches(dumpsPage);
foreach (Match match in matches)
foreach (Match? match in matches)
{
if (match == null)
continue;
try
{
if (int.TryParse(match.Groups[1].Value, out int value))
@@ -258,8 +264,11 @@ namespace SabreTools.RedumpLib.Web
// Otherwise, traverse each dump on the page
var matches = Constants.NewDiscRegex.Matches(dumpsPage);
foreach (Match match in matches)
foreach (Match? match in matches)
{
if (match == null)
continue;
try
{
if (int.TryParse(match.Groups[2].Value, out int value))
@@ -282,7 +291,7 @@ namespace SabreTools.RedumpLib.Web
/// <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)
public async Task<bool> CheckSingleWIPPage(string url, string? outDir, bool failOnSingle)
{
// Try up to 3 times to retrieve the data
string? dumpsPage = await DownloadString(url, retries: 3);
@@ -293,8 +302,11 @@ namespace SabreTools.RedumpLib.Web
// Otherwise, traverse each dump on the page
var matches = Constants.NewDiscRegex.Matches(dumpsPage);
foreach (Match match in matches)
foreach (Match? match in matches)
{
if (match == null)
continue;
try
{
if (int.TryParse(match.Groups[2].Value, out int value))
@@ -344,7 +356,7 @@ namespace SabreTools.RedumpLib.Web
/// <param name="system">System to download packs for</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> DownloadSinglePack(string url, RedumpSystem? system, string outDir, string subfolder)
public async Task<bool> DownloadSinglePack(string url, RedumpSystem? system, string? outDir, string? subfolder)
{
try
{
@@ -357,7 +369,7 @@ namespace SabreTools.RedumpLib.Web
// Make the call to get the pack
string? remoteFileName = await DownloadFile(packUri, tempfile);
MoveOrDelete(tempfile, remoteFileName, outDir, subfolder);
MoveOrDelete(tempfile, remoteFileName, outDir!, subfolder);
return true;
}
catch (Exception ex)
@@ -374,7 +386,7 @@ namespace SabreTools.RedumpLib.Web
/// <returns>String containing the page contents if successful, null on error</returns>
public async Task<string?> DownloadSingleSiteID(int id)
{
string paddedId = id.ToString().PadLeft(5, '0');
string paddedId = id.ToString().PadLeft(6, '0');
Console.WriteLine($"Processing ID: {paddedId}");
try
{
@@ -405,13 +417,13 @@ namespace SabreTools.RedumpLib.Web
/// <param name="outDir">Output directory to save data to</param>
/// <param name="rename">True to rename deleted entries, false otherwise</param>
/// <returns>True if all data was downloaded, false otherwise</returns>
public async Task<bool> DownloadSingleSiteID(int id, string outDir, bool rename)
public async Task<bool> DownloadSingleSiteID(int id, string? outDir, bool rename)
{
// If no output directory is defined, use the current directory instead
if (string.IsNullOrWhiteSpace(outDir))
outDir = Environment.CurrentDirectory;
string paddedId = id.ToString().PadLeft(5, '0');
string paddedId = id.ToString().PadLeft(6, '0');
string paddedIdDir = Path.Combine(outDir, paddedId);
Console.WriteLine($"Processing ID: {paddedId}");
try
@@ -536,7 +548,7 @@ namespace SabreTools.RedumpLib.Web
/// <returns>String containing the page contents if successful, null on error</returns>
public async Task<string?> DownloadSingleWIPID(int id)
{
string paddedId = id.ToString().PadLeft(5, '0');
string paddedId = id.ToString().PadLeft(6, '0');
Console.WriteLine($"Processing ID: {paddedId}");
try
{
@@ -567,13 +579,13 @@ namespace SabreTools.RedumpLib.Web
/// <param name="outDir">Output directory to save data to</param>
/// <param name="rename">True to rename deleted entries, false otherwise</param>
/// <returns>True if all data was downloaded, false otherwise</returns>
public async Task<bool> DownloadSingleWIPID(int id, string outDir, bool rename)
public async Task<bool> DownloadSingleWIPID(int id, string? outDir, bool rename)
{
// If no output directory is defined, use the current directory instead
if (string.IsNullOrWhiteSpace(outDir))
outDir = Environment.CurrentDirectory;
string paddedId = id.ToString().PadLeft(5, '0');
string paddedId = id.ToString().PadLeft(6, '0');
string paddedIdDir = Path.Combine(outDir, paddedId);
Console.WriteLine($"Processing ID: {paddedId}");
try
@@ -694,7 +706,7 @@ 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)
@@ -778,7 +790,7 @@ namespace SabreTools.RedumpLib.Web
/// <param name="newfile">Path to new output file</param>
/// <param name="outDir">Output directory to save data to</param>
/// <param name="subfolder">Optional subfolder to append to the path</param>
private static void MoveOrDelete(string tempfile, string? newfile, string outDir, string subfolder)
private static void MoveOrDelete(string tempfile, string? newfile, string outDir, string? subfolder)
{
// If we don't have a file to move to, just delete the temp file
if (string.IsNullOrWhiteSpace(newfile))

View File

@@ -1,4 +1,4 @@
#if NET48
#if NETFRAMEWORK
using System;
using System.Collections.Generic;
@@ -29,7 +29,7 @@ namespace SabreTools.RedumpLib.Web
/// Get the last downloaded filename, if possible
/// </summary>
/// <returns></returns>
public string GetLastFilename()
public string? GetLastFilename()
{
// If the response headers are null or empty
if (ResponseHeaders == null || ResponseHeaders.Count == 0)
@@ -41,11 +41,7 @@ namespace SabreTools.RedumpLib.Web
return null;
// Extract the filename from the value
#if NETSTANDARD2_1
return headerValue[(headerValue.IndexOf("filename=") + 9)..].Replace("\"", "");
#else
return headerValue.Substring(headerValue.IndexOf("filename=") + 9).Replace("\"", "");
#endif
}
/// <inheritdoc/>
@@ -61,19 +57,15 @@ namespace SabreTools.RedumpLib.Web
/// <summary>
/// Validate supplied credentials
/// </summary>
public static (bool?, string) ValidateCredentials(string username, string password)
public static (bool?, string?) ValidateCredentials(string username, string password)
{
// If options are invalid or we're missing something key, just return
if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
return (false, null);
// Try logging in with the supplied credentials otherwise
#if NETSTANDARD2_1
using RedumpWebClient wc = new RedumpWebClient();
#else
using (RedumpWebClient wc = new RedumpWebClient())
{
#endif
bool? loggedIn = wc.Login(username, password);
if (loggedIn == true)
return (true, "Redump username and password accepted!");
@@ -81,9 +73,7 @@ namespace SabreTools.RedumpLib.Web
return (false, "Redump username and password denied!");
else
return (null, "An error occurred validating your credentials!");
#if NET48
}
#endif
}
/// <summary>
@@ -111,7 +101,11 @@ namespace SabreTools.RedumpLib.Web
}
// HTTP encode the password
#if NET40
password = Uri.EscapeUriString(password);
#else
password = WebUtility.UrlEncode(password);
#endif
// Attempt to login up to 3 times
for (int i = 0; i < 3; i++)
@@ -216,7 +210,7 @@ namespace SabreTools.RedumpLib.Web
/// <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 bool CheckSingleSitePage(string url, string outDir, bool failOnSingle)
public bool CheckSingleSitePage(string url, string? outDir, bool failOnSingle)
{
string dumpsPage = string.Empty;
@@ -323,7 +317,7 @@ namespace SabreTools.RedumpLib.Web
/// <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 bool CheckSingleWIPPage(string url, string outDir, bool failOnSingle)
public bool CheckSingleWIPPage(string url, string? outDir, bool failOnSingle)
{
string dumpsPage = string.Empty;
@@ -375,7 +369,7 @@ namespace SabreTools.RedumpLib.Web
/// <param name="url">Base URL to download using</param>
/// <param name="system">System to download packs for</param>
/// <returns>Byte array containing the downloaded pack, null on error</returns>
public byte[] DownloadSinglePack(string url, RedumpSystem? system)
public byte[]? DownloadSinglePack(string url, RedumpSystem? system)
{
try
{
@@ -395,7 +389,7 @@ namespace SabreTools.RedumpLib.Web
/// <param name="system">System to download packs for</param>
/// <param name="outDir">Output directory to save data to</param>
/// <param name="subfolder">Named subfolder for the pack, used optionally</param>
public void DownloadSinglePack(string url, RedumpSystem? system, string outDir, string subfolder)
public void DownloadSinglePack(string url, RedumpSystem? system, string? outDir, string? subfolder)
{
try
{
@@ -405,7 +399,7 @@ namespace SabreTools.RedumpLib.Web
string tempfile = Path.Combine(outDir, "tmp" + Guid.NewGuid().ToString());
DownloadFile(string.Format(url, system.ShortName()), tempfile);
MoveOrDelete(tempfile, GetLastFilename(), outDir, subfolder);
MoveOrDelete(tempfile, GetLastFilename(), outDir!, subfolder);
}
catch (Exception ex)
{
@@ -418,9 +412,9 @@ namespace SabreTools.RedumpLib.Web
/// </summary>
/// <param name="id">Redump disc ID to retrieve</param>
/// <returns>String containing the page contents if successful, null on error</returns>
public string DownloadSingleSiteID(int id)
public string? DownloadSingleSiteID(int id)
{
string paddedId = id.ToString().PadLeft(5, '0');
string paddedId = id.ToString().PadLeft(6, '0');
Console.WriteLine($"Processing ID: {paddedId}");
try
{
@@ -460,13 +454,13 @@ namespace SabreTools.RedumpLib.Web
/// <param name="outDir">Output directory to save data to</param>
/// <param name="rename">True to rename deleted entries, false otherwise</param>
/// <returns>True if all data was downloaded, false otherwise</returns>
public bool DownloadSingleSiteID(int id, string outDir, bool rename)
public bool DownloadSingleSiteID(int id, string? outDir, bool rename)
{
// If no output directory is defined, use the current directory instead
if (string.IsNullOrWhiteSpace(outDir))
outDir = Environment.CurrentDirectory;
string paddedId = id.ToString().PadLeft(5, '0');
string paddedId = id.ToString().PadLeft(6, '0');
string paddedIdDir = Path.Combine(outDir, paddedId);
Console.WriteLine($"Processing ID: {paddedId}");
try
@@ -598,9 +592,9 @@ namespace SabreTools.RedumpLib.Web
/// </summary>
/// <param name="id">Redump WIP disc ID to retrieve</param>
/// <returns>String containing the page contents if successful, null on error</returns>
public string DownloadSingleWIPID(int id)
public string? DownloadSingleWIPID(int id)
{
string paddedId = id.ToString().PadLeft(5, '0');
string paddedId = id.ToString().PadLeft(6, '0');
Console.WriteLine($"Processing ID: {paddedId}");
try
{
@@ -640,13 +634,13 @@ namespace SabreTools.RedumpLib.Web
/// <param name="outDir">Output directory to save data to</param>
/// <param name="rename">True to rename deleted entries, false otherwise</param>
/// <returns>True if all data was downloaded, false otherwise</returns>
public bool DownloadSingleWIPID(int id, string outDir, bool rename)
public bool DownloadSingleWIPID(int id, string? outDir, bool rename)
{
// If no output directory is defined, use the current directory instead
if (string.IsNullOrWhiteSpace(outDir))
outDir = Environment.CurrentDirectory;
string paddedId = id.ToString().PadLeft(5, '0');
string paddedId = id.ToString().PadLeft(6, '0');
string paddedIdDir = Path.Combine(outDir, paddedId);
Console.WriteLine($"Processing ID: {paddedId}");
try
@@ -752,12 +746,12 @@ namespace SabreTools.RedumpLib.Web
continue;
// If the system is unknown, we can't do anything
string longName = system.LongName();
string? longName = system.LongName();
if (string.IsNullOrWhiteSpace(longName))
continue;
Console.Write($"\r{longName}{new string(' ', Console.BufferWidth - longName.Length - 1)}");
byte[] pack = DownloadSinglePack(url, system);
Console.Write($"\r{longName}{new string(' ', Console.BufferWidth - longName!.Length - 1)}");
byte[]? pack = DownloadSinglePack(url, system);
if (pack != null)
packsDictionary.Add(system.Value, pack);
}
@@ -776,7 +770,7 @@ 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 void DownloadPacks(string url, RedumpSystem?[] systems, string title, string outDir, string subfolder)
public void DownloadPacks(string url, RedumpSystem?[] systems, string title, string? outDir, string? subfolder)
{
Console.WriteLine($"Downloading {title}");
foreach (var system in systems)
@@ -790,11 +784,11 @@ namespace SabreTools.RedumpLib.Web
continue;
// If the system is unknown, we can't do anything
string longName = system.LongName();
string? longName = system.LongName();
if (string.IsNullOrWhiteSpace(longName))
continue;
Console.Write($"\r{longName}{new string(' ', Console.BufferWidth - longName.Length - 1)}");
Console.Write($"\r{longName}{new string(' ', Console.BufferWidth - longName!.Length - 1)}");
DownloadSinglePack(url, system, outDir, subfolder);
}
@@ -809,7 +803,7 @@ namespace SabreTools.RedumpLib.Web
/// <param name="newfile">Path to new output file</param>
/// <param name="outDir">Output directory to save data to</param>
/// <param name="subfolder">Optional subfolder to append to the path</param>
private static void MoveOrDelete(string tempfile, string newfile, string outDir, string subfolder)
private static void MoveOrDelete(string tempfile, string? newfile, string outDir, string? subfolder)
{
if (!string.IsNullOrWhiteSpace(newfile))
{
@@ -827,7 +821,9 @@ namespace SabreTools.RedumpLib.Web
File.Move(tempfile, Path.Combine(outDir, newfile));
}
else
{
File.Delete(tempfile);
}
}
#endregion