From 5bccdeaf2c66c3fd510ac8ed514625012c142ff3 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 7 Nov 2023 23:06:50 -0500 Subject: [PATCH] Enable latest language version --- Attributes/AttributeHelper.cs | 8 - Attributes/HumanReadableAttribute.cs | 8 - Attributes/LanguageAttribute.cs | 12 - Converters/LanguageConverter.cs | 8 - Converters/LanguageSelectionConverter.cs | 8 - Data/Extensions.cs | 68 ----- Data/SubmissionInfo.cs | 316 ----------------------- SabreTools.RedumpLib.csproj | 7 +- Web/RedumpHttpClient.cs | 18 +- Web/RedumpWebClient.cs | 50 ++-- 10 files changed, 33 insertions(+), 470 deletions(-) diff --git a/Attributes/AttributeHelper.cs b/Attributes/AttributeHelper.cs index c41b5e2..74fc700 100644 --- a/Attributes/AttributeHelper.cs +++ b/Attributes/AttributeHelper.cs @@ -10,11 +10,7 @@ namespace SabreTools.RedumpLib.Attributes /// /// Value to use /// HumanReadableAttribute attached to the value -#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; diff --git a/Attributes/HumanReadableAttribute.cs b/Attributes/HumanReadableAttribute.cs index 54a5e6f..bd69d03 100644 --- a/Attributes/HumanReadableAttribute.cs +++ b/Attributes/HumanReadableAttribute.cs @@ -15,19 +15,11 @@ namespace SabreTools.RedumpLib.Attributes /// /// Human-readable name of the item /// -#if NET48 - public string LongName { get; set; } -#else public string? LongName { get; set; } -#endif /// /// Internally used name of the item /// -#if NET48 - public string ShortName { get; set; } -#else public string? ShortName { get; set; } -#endif } } \ No newline at end of file diff --git a/Attributes/LanguageAttribute.cs b/Attributes/LanguageAttribute.cs index a018c46..8a2550a 100644 --- a/Attributes/LanguageAttribute.cs +++ b/Attributes/LanguageAttribute.cs @@ -11,28 +11,16 @@ namespace SabreTools.RedumpLib.Attributes /// /// ISO 639-1 Code /// -#if NET48 - public string TwoLetterCode { get; set; } = null; -#else public string? TwoLetterCode { get; set; } -#endif /// /// ISO 639-2 Code (Standard or Bibliographic) /// -#if NET48 - public string ThreeLetterCode { get; set; } = null; -#else public string? ThreeLetterCode { get; set; } -#endif /// /// ISO 639-2 Code (Terminology) /// -#if NET48 - public string ThreeLetterCodeAlt { get; set; } = null; -#else public string? ThreeLetterCodeAlt { get; set; } -#endif } } \ No newline at end of file diff --git a/Converters/LanguageConverter.cs b/Converters/LanguageConverter.cs index 0e010fc..aec3664 100644 --- a/Converters/LanguageConverter.cs +++ b/Converters/LanguageConverter.cs @@ -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; diff --git a/Converters/LanguageSelectionConverter.cs b/Converters/LanguageSelectionConverter.cs index 278c1f5..498a499 100644 --- a/Converters/LanguageSelectionConverter.cs +++ b/Converters/LanguageSelectionConverter.cs @@ -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; diff --git a/Data/Extensions.cs b/Data/Extensions.cs index 9b2db06..3aa3e36 100644 --- a/Data/Extensions.cs +++ b/Data/Extensions.cs @@ -812,11 +812,7 @@ namespace SabreTools.RedumpLib.Data /// /// /// -#if NET48 - public static string LongName(this DiscCategory? category) => AttributeHelper.GetAttribute(category)?.LongName; -#else public static string? LongName(this DiscCategory? category) => AttributeHelper.GetAttribute(category)?.LongName; -#endif /// /// Get the Category enum value for a given string @@ -865,11 +861,7 @@ namespace SabreTools.RedumpLib.Data /// /// /// -#if NET48 - public static string LongName(this DiscType? discType) => AttributeHelper.GetAttribute(discType)?.LongName; -#else public static string? LongName(this DiscType? discType) => AttributeHelper.GetAttribute(discType)?.LongName; -#endif /// /// Get the DiscType enum value for a given string @@ -955,22 +947,14 @@ namespace SabreTools.RedumpLib.Data /// /// /// -#if NET48 - public static string LongName(this Language? language) => AttributeHelper.GetAttribute(language)?.LongName; -#else public static string? LongName(this Language? language) => AttributeHelper.GetAttribute(language)?.LongName; -#endif /// /// Get the Redump shortnames for each known language /// /// /// -#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 /// /// /// -#if NET48 - public static string ThreeLetterCode(this Language? language) => ((LanguageAttribute)AttributeHelper.GetAttribute(language))?.ThreeLetterCode; -#else public static string? ThreeLetterCode(this Language? language) => (AttributeHelper.GetAttribute(language) as LanguageAttribute)?.ThreeLetterCode; -#endif /// /// Get the ISO 639-2 alternate code for each known language /// /// /// -#if NET48 - public static string ThreeLetterCodeAlt(this Language? language) => ((LanguageAttribute)AttributeHelper.GetAttribute(language))?.ThreeLetterCodeAlt; -#else public static string? ThreeLetterCodeAlt(this Language? language) => (AttributeHelper.GetAttribute(language) as LanguageAttribute)?.ThreeLetterCodeAlt; -#endif /// /// Get the ISO 639-1 code for each known language /// /// /// -#if NET48 - public static string TwoLetterCode(this Language? language) => ((LanguageAttribute)AttributeHelper.GetAttribute(language))?.TwoLetterCode; -#else public static string? TwoLetterCode(this Language? language) => (AttributeHelper.GetAttribute(language) as LanguageAttribute)?.TwoLetterCode; -#endif #endregion @@ -1066,11 +1038,7 @@ namespace SabreTools.RedumpLib.Data /// /// LanguageSelection value to convert /// String representing the value, if possible -#if NET48 - public static string LongName(this LanguageSelection? langSelect) => AttributeHelper.GetAttribute(langSelect)?.LongName; -#else public static string? LongName(this LanguageSelection? langSelect) => AttributeHelper.GetAttribute(langSelect)?.LongName; -#endif #endregion @@ -1099,22 +1067,14 @@ namespace SabreTools.RedumpLib.Data /// /// /// -#if NET48 - public static string LongName(this MediaType? mediaType) => AttributeHelper.GetAttribute(mediaType)?.LongName; -#else public static string? LongName(this MediaType? mediaType) => AttributeHelper.GetAttribute(mediaType)?.LongName; -#endif /// /// Get the Redump shortnames for each known media type /// /// /// -#if NET48 - public static string ShortName(this MediaType? mediaType) => AttributeHelper.GetAttribute(mediaType)?.ShortName; -#else public static string? ShortName(this MediaType? mediaType) => AttributeHelper.GetAttribute(mediaType)?.ShortName; -#endif #endregion @@ -1125,22 +1085,14 @@ namespace SabreTools.RedumpLib.Data /// /// /// -#if NET48 - public static string LongName(this Region? region) => AttributeHelper.GetAttribute(region)?.LongName; -#else public static string? LongName(this Region? region) => AttributeHelper.GetAttribute(region)?.LongName; -#endif /// /// Get the Redump shortnames for each known region /// /// /// -#if NET48 - public static string ShortName(this Region? region) => AttributeHelper.GetAttribute(region)?.ShortName; -#else public static string? ShortName(this Region? region) => AttributeHelper.GetAttribute(region)?.ShortName; -#endif /// /// Get the Region enum value for a given string @@ -1172,22 +1124,14 @@ namespace SabreTools.RedumpLib.Data /// /// /// -#if NET48 - public static string LongName(this SiteCode? siteCode) => AttributeHelper.GetAttribute(siteCode)?.LongName; -#else public static string? LongName(this SiteCode? siteCode) => AttributeHelper.GetAttribute(siteCode)?.LongName; -#endif /// /// Get the short tag for each known site code /// /// /// -#if NET48 - public static string ShortName(this SiteCode? siteCode) => AttributeHelper.GetAttribute(siteCode)?.ShortName; -#else public static string? ShortName(this SiteCode? siteCode) => AttributeHelper.GetAttribute(siteCode)?.ShortName; -#endif #endregion @@ -1238,22 +1182,14 @@ namespace SabreTools.RedumpLib.Data /// /// /// -#if NET48 - public static string LongName(this RedumpSystem? system) => AttributeHelper.GetAttribute(system)?.LongName; -#else public static string? LongName(this RedumpSystem? system) => AttributeHelper.GetAttribute(system)?.LongName; -#endif /// /// Get the Redump shortnames for each known system /// /// /// -#if NET48 - public static string ShortName(this RedumpSystem? system) => AttributeHelper.GetAttribute(system)?.ShortName; -#else public static string? ShortName(this RedumpSystem? system) => AttributeHelper.GetAttribute(system)?.ShortName; -#endif /// /// Determine the category of a system @@ -2201,11 +2137,7 @@ namespace SabreTools.RedumpLib.Data /// /// /// -#if NET48 - public static string LongName(this SystemCategory? category) => AttributeHelper.GetAttribute(category)?.LongName; -#else public static string? LongName(this SystemCategory? category) => AttributeHelper.GetAttribute(category)?.LongName; -#endif #endregion diff --git a/Data/SubmissionInfo.cs b/Data/SubmissionInfo.cs index 35d8871..df777b2 100644 --- a/Data/SubmissionInfo.cs +++ b/Data/SubmissionInfo.cs @@ -24,11 +24,7 @@ namespace SabreTools.RedumpLib.Data /// List of partially matched Redump IDs /// [JsonIgnore] -#if NET48 - public List PartiallyMatchedIDs { get; set; } -#else public List? PartiallyMatchedIDs { get; set; } -#endif /// /// 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 Artifacts { get; set; } = new Dictionary(); -#else public Dictionary? Artifacts { get; set; } = new Dictionary(); -#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 CommentsSpecialFields { get; set; } -#else public Dictionary? 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 ContentsSpecialFields { get; set; } -#else public Dictionary? 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> FullProtections { get; set; } -#else public Dictionary?>? 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() { diff --git a/SabreTools.RedumpLib.csproj b/SabreTools.RedumpLib.csproj index 489e5a3..1bc1ed5 100644 --- a/SabreTools.RedumpLib.csproj +++ b/SabreTools.RedumpLib.csproj @@ -4,6 +4,9 @@ net48;net6.0;net7.0;net8.0 win-x86;win-x64;linux-x64;osx-x64 + latest + enable + true 1.1.1 @@ -18,10 +21,6 @@ MIT - - enable - - diff --git a/Web/RedumpHttpClient.cs b/Web/RedumpHttpClient.cs index af8b4b6..3343893 100644 --- a/Web/RedumpHttpClient.cs +++ b/Web/RedumpHttpClient.cs @@ -1,4 +1,4 @@ -#if NET6_0_OR_GREATER +#if !NETFRAMEWORK using System; using System.Collections.Generic; @@ -194,7 +194,7 @@ namespace SabreTools.RedumpLib.Web /// Output directory to save data to /// True to return on first error, false otherwise /// True if the page could be downloaded, false otherwise - public async Task CheckSingleSitePage(string url, string outDir, bool failOnSingle) + public async Task CheckSingleSitePage(string url, string? outDir, bool failOnSingle) { // Try up to 3 times to retrieve the data string? dumpsPage = await DownloadString(url, retries: 3); @@ -282,7 +282,7 @@ namespace SabreTools.RedumpLib.Web /// Output directory to save data to /// True to return on first error, false otherwise /// True if the page could be downloaded, false otherwise - public async Task CheckSingleWIPPage(string url, string outDir, bool failOnSingle) + public async Task CheckSingleWIPPage(string url, string? outDir, bool failOnSingle) { // Try up to 3 times to retrieve the data string? dumpsPage = await DownloadString(url, retries: 3); @@ -344,7 +344,7 @@ namespace SabreTools.RedumpLib.Web /// System to download packs for /// Output directory to save data to /// Named subfolder for the pack, used optionally - public async Task DownloadSinglePack(string url, RedumpSystem? system, string outDir, string subfolder) + public async Task DownloadSinglePack(string url, RedumpSystem? system, string? outDir, string? subfolder) { try { @@ -357,7 +357,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) @@ -405,7 +405,7 @@ namespace SabreTools.RedumpLib.Web /// Output directory to save data to /// True to rename deleted entries, false otherwise /// True if all data was downloaded, false otherwise - public async Task DownloadSingleSiteID(int id, string outDir, bool rename) + public async Task DownloadSingleSiteID(int id, string? outDir, bool rename) { // If no output directory is defined, use the current directory instead if (string.IsNullOrWhiteSpace(outDir)) @@ -567,7 +567,7 @@ namespace SabreTools.RedumpLib.Web /// Output directory to save data to /// True to rename deleted entries, false otherwise /// True if all data was downloaded, false otherwise - public async Task DownloadSingleWIPID(int id, string outDir, bool rename) + public async Task DownloadSingleWIPID(int id, string? outDir, bool rename) { // If no output directory is defined, use the current directory instead if (string.IsNullOrWhiteSpace(outDir)) @@ -694,7 +694,7 @@ namespace SabreTools.RedumpLib.Web /// Name of the pack that is downloading /// Output directory to save data to /// Named subfolder for the pack, used optionally - public async Task DownloadPacks(string url, RedumpSystem?[] systems, string title, string outDir, string subfolder) + public async Task DownloadPacks(string url, RedumpSystem?[] systems, string title, string? outDir, string? subfolder) { Console.WriteLine($"Downloading {title}"); foreach (var system in systems) @@ -778,7 +778,7 @@ namespace SabreTools.RedumpLib.Web /// Path to new output file /// Output directory to save data to /// Optional subfolder to append to the path - 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)) diff --git a/Web/RedumpWebClient.cs b/Web/RedumpWebClient.cs index 2423513..9c99e2b 100644 --- a/Web/RedumpWebClient.cs +++ b/Web/RedumpWebClient.cs @@ -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 /// /// - 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 } /// @@ -61,19 +57,15 @@ namespace SabreTools.RedumpLib.Web /// /// Validate supplied credentials /// - 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 } /// @@ -216,7 +206,7 @@ namespace SabreTools.RedumpLib.Web /// Output directory to save data to /// True to return on first error, false otherwise /// True if the page could be downloaded, false otherwise - public bool CheckSingleSitePage(string url, string outDir, bool failOnSingle) + public bool CheckSingleSitePage(string url, string? outDir, bool failOnSingle) { string dumpsPage = string.Empty; @@ -323,7 +313,7 @@ namespace SabreTools.RedumpLib.Web /// Output directory to save data to /// True to return on first error, false otherwise /// True if the page could be downloaded, false otherwise - public bool CheckSingleWIPPage(string url, string outDir, bool failOnSingle) + public bool CheckSingleWIPPage(string url, string? outDir, bool failOnSingle) { string dumpsPage = string.Empty; @@ -375,7 +365,7 @@ namespace SabreTools.RedumpLib.Web /// Base URL to download using /// System to download packs for /// Byte array containing the downloaded pack, null on error - public byte[] DownloadSinglePack(string url, RedumpSystem? system) + public byte[]? DownloadSinglePack(string url, RedumpSystem? system) { try { @@ -395,7 +385,7 @@ namespace SabreTools.RedumpLib.Web /// System to download packs for /// Output directory to save data to /// Named subfolder for the pack, used optionally - 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 +395,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,7 +408,7 @@ namespace SabreTools.RedumpLib.Web /// /// Redump disc ID to retrieve /// String containing the page contents if successful, null on error - public string DownloadSingleSiteID(int id) + public string? DownloadSingleSiteID(int id) { string paddedId = id.ToString().PadLeft(6, '0'); Console.WriteLine($"Processing ID: {paddedId}"); @@ -460,7 +450,7 @@ namespace SabreTools.RedumpLib.Web /// Output directory to save data to /// True to rename deleted entries, false otherwise /// True if all data was downloaded, false otherwise - 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)) @@ -598,7 +588,7 @@ namespace SabreTools.RedumpLib.Web /// /// Redump WIP disc ID to retrieve /// String containing the page contents if successful, null on error - public string DownloadSingleWIPID(int id) + public string? DownloadSingleWIPID(int id) { string paddedId = id.ToString().PadLeft(6, '0'); Console.WriteLine($"Processing ID: {paddedId}"); @@ -640,7 +630,7 @@ namespace SabreTools.RedumpLib.Web /// Output directory to save data to /// True to rename deleted entries, false otherwise /// True if all data was downloaded, false otherwise - 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)) @@ -752,12 +742,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 +766,7 @@ namespace SabreTools.RedumpLib.Web /// Name of the pack that is downloading /// Output directory to save data to /// Named subfolder for the pack, used optionally - 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 +780,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 +799,7 @@ namespace SabreTools.RedumpLib.Web /// Path to new output file /// Output directory to save data to /// Optional subfolder to append to the path - 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 +817,9 @@ namespace SabreTools.RedumpLib.Web File.Move(tempfile, Path.Combine(outDir, newfile)); } else + { File.Delete(tempfile); + } } #endregion