From 8fcac1d425ea15815b2baccb065f3109aa9ecc14 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 11 Oct 2023 23:55:50 -0400 Subject: [PATCH] Cleanup and gated code --- MPF.Core/Data/IniFile.cs | 20 +- MPF.Core/DumpEnvironment.cs | 44 +- MPF.Core/InfoTool.cs | 345 ++++++++++- MPF.Core/Modules/Aaru/Parameters.cs | 198 ++++--- MPF.Core/Modules/BaseParameters.cs | 8 + MPF.Core/Modules/CleanRIp/Parameters.cs | 80 ++- .../Modules/DiscImageCreator/Parameters.cs | 544 ++++++++++++------ MPF.Core/Modules/Redumper/Parameters.cs | 204 ++++--- .../Modules/UmdImageCreator/Parameters.cs | 47 +- MPF.Core/Utilities/Tools.cs | 4 +- 10 files changed, 1059 insertions(+), 435 deletions(-) diff --git a/MPF.Core/Data/IniFile.cs b/MPF.Core/Data/IniFile.cs index 40c082fc..66495ba5 100644 --- a/MPF.Core/Data/IniFile.cs +++ b/MPF.Core/Data/IniFile.cs @@ -8,14 +8,22 @@ namespace MPF.Core.Data { public class IniFile : IDictionary { +#if NET48 private Dictionary _keyValuePairs = new Dictionary(); +#else + private Dictionary _keyValuePairs = new(); +#endif public string this[string key] { get { +#if NET48 if (_keyValuePairs == null) _keyValuePairs = new Dictionary(); +#else + _keyValuePairs ??= new Dictionary(); +#endif key = key.ToLowerInvariant(); if (_keyValuePairs.ContainsKey(key)) @@ -25,8 +33,12 @@ namespace MPF.Core.Data } set { +#if NET48 if (_keyValuePairs == null) _keyValuePairs = new Dictionary(); +#else + _keyValuePairs ??= new Dictionary(); +#endif key = key.ToLowerInvariant(); _keyValuePairs[key] = value; @@ -99,7 +111,7 @@ namespace MPF.Core.Data // Keys are case-insensitive by default try { - using (StreamReader sr = new StreamReader(stream)) + using (var sr = new StreamReader(stream)) { string section = string.Empty; while (!sr.EndOfStream) @@ -125,7 +137,11 @@ namespace MPF.Core.Data } // Valid INI lines are in the format key=value +#if NET48 else if (line.Contains("=")) +#else + else if (line.Contains('=')) +#endif { // Split the line by '=' for key-value pairs string[] data = line.Split('='); @@ -185,7 +201,7 @@ namespace MPF.Core.Data try { - using (StreamWriter sw = new StreamWriter(stream)) + using (var sw = new StreamWriter(stream)) { // Order the dictionary by keys to link sections together var orderedKeyValuePairs = _keyValuePairs.OrderBy(kvp => kvp.Key); diff --git a/MPF.Core/DumpEnvironment.cs b/MPF.Core/DumpEnvironment.cs index c8274410..499b58bd 100644 --- a/MPF.Core/DumpEnvironment.cs +++ b/MPF.Core/DumpEnvironment.cs @@ -65,7 +65,7 @@ namespace MPF.Core public BaseParameters? Parameters { get; private set; } #endif -#endregion + #endregion #region Event Handlers @@ -292,7 +292,7 @@ namespace MPF.Core return null; } -#endregion + #endregion #region Dumping @@ -358,11 +358,6 @@ namespace MPF.Core await Task.Run(() => Parameters.ExecuteInternalProgram(Options.ToolsInSeparateWindow)); progress?.Report(Result.Success($"{this.InternalProgram} has finished!")); - // Execute additional tools - progress?.Report(Result.Success("Running any additional tools... see log for output!")); - result = await Task.Run(() => ExecuteAdditionalTools()); - progress?.Report(result); - // Remove event handler if needed if (!Options.ToolsInSeparateWindow) { @@ -535,18 +530,12 @@ namespace MPF.Core return parametersValid && floppyValid && removableDiskValid; } - /// - /// Run any additional tools given a DumpEnvironment - /// - /// Result instance with the outcome - private Result ExecuteAdditionalTools() => Result.Success("No external tools needed!"); - /// /// Run internal program async with an input set of parameters /// /// /// Standard output from commandline window - private async Task ExecuteInternalProgram(BaseParameters parameters) + private static async Task ExecuteInternalProgram(BaseParameters parameters) { Process childProcess; string output = await Task.Run(() => @@ -584,20 +573,21 @@ namespace MPF.Core /// Existing submission information /// User-supplied submission information #if NET48 - private void InjectSubmissionInformation(SubmissionInfo info, SubmissionInfo seed) + private static void InjectSubmissionInformation(SubmissionInfo info, SubmissionInfo seed) #else - private void InjectSubmissionInformation(SubmissionInfo? info, SubmissionInfo? seed) + private static void InjectSubmissionInformation(SubmissionInfo? info, SubmissionInfo? seed) #endif { // If we have any invalid info - if (info == null || seed == null) + if (seed == null) return; - // Otherwise, inject information as necessary - if (seed.CommonDiscInfo != null) - { - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); + // Ensure that required sections exist + info = InfoTool.EnsureAllSections(info); + // Otherwise, inject information as necessary + if (info.CommonDiscInfo != null && seed.CommonDiscInfo != null) + { // Info that only overwrites if supplied if (!string.IsNullOrWhiteSpace(seed.CommonDiscInfo.Title)) info.CommonDiscInfo.Title = seed.CommonDiscInfo.Title; if (!string.IsNullOrWhiteSpace(seed.CommonDiscInfo.ForeignTitleNonLatin)) info.CommonDiscInfo.ForeignTitleNonLatin = seed.CommonDiscInfo.ForeignTitleNonLatin; @@ -607,7 +597,7 @@ namespace MPF.Core if (seed.CommonDiscInfo.Region != null) info.CommonDiscInfo.Region = seed.CommonDiscInfo.Region; if (seed.CommonDiscInfo.Languages != null) info.CommonDiscInfo.Languages = seed.CommonDiscInfo.Languages; if (seed.CommonDiscInfo.LanguageSelection != null) info.CommonDiscInfo.LanguageSelection = seed.CommonDiscInfo.LanguageSelection; - if (seed.CommonDiscInfo.Serial != null) info.CommonDiscInfo.Serial = seed.CommonDiscInfo.Serial; + if (!string.IsNullOrWhiteSpace(seed.CommonDiscInfo.Serial)) info.CommonDiscInfo.Serial = seed.CommonDiscInfo.Serial; if (!string.IsNullOrWhiteSpace(seed.CommonDiscInfo.Barcode)) info.CommonDiscInfo.Barcode = seed.CommonDiscInfo.Barcode; if (!string.IsNullOrWhiteSpace(seed.CommonDiscInfo.Comments)) info.CommonDiscInfo.Comments = seed.CommonDiscInfo.Comments; if (seed.CommonDiscInfo.CommentsSpecialFields != null) info.CommonDiscInfo.CommentsSpecialFields = seed.CommonDiscInfo.CommentsSpecialFields; @@ -636,19 +626,15 @@ namespace MPF.Core info.CommonDiscInfo.Layer3ToolstampMasteringCode = seed.CommonDiscInfo.Layer3ToolstampMasteringCode; } - if (seed.VersionAndEditions != null) + if (info.VersionAndEditions != null && seed.VersionAndEditions != null) { - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); - // Info that only overwrites if supplied if (!string.IsNullOrWhiteSpace(seed.VersionAndEditions.Version)) info.VersionAndEditions.Version = seed.VersionAndEditions.Version; if (!string.IsNullOrWhiteSpace(seed.VersionAndEditions.OtherEditions)) info.VersionAndEditions.OtherEditions = seed.VersionAndEditions.OtherEditions; } - if (seed.CopyProtection != null) + if (info.CopyProtection != null && seed.CopyProtection != null) { - if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection(); - // Info that only overwrites if supplied if (!string.IsNullOrWhiteSpace(seed.CopyProtection.Protection)) info.CopyProtection.Protection = seed.CopyProtection.Protection; } @@ -732,6 +718,6 @@ namespace MPF.Core return await ExecuteInternalProgram(parameters); } -#endregion + #endregion } } diff --git a/MPF.Core/InfoTool.cs b/MPF.Core/InfoTool.cs index 912aae79..5a757f58 100644 --- a/MPF.Core/InfoTool.cs +++ b/MPF.Core/InfoTool.cs @@ -56,6 +56,58 @@ namespace MPF.Core } } + /// + /// Ensure all required sections in a submission info exist + /// + /// SubmissionInfo object to verify +#if NET48 + public static SubmissionInfo EnsureAllSections(SubmissionInfo info) + { + // If there's no info, create one + if (info == null) info = new SubmissionInfo(); + + // Ensure all sections + if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); + if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); + if (info.EDC == null) info.EDC = new EDCSection(); + if (info.Extras == null) info.Extras = new ExtrasSection(); + if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection(); + if (info.TracksAndWriteOffsets == null) info.TracksAndWriteOffsets = new TracksAndWriteOffsetsSection(); + if (info.SizeAndChecksums == null) info.SizeAndChecksums = new SizeAndChecksumsSection(); + if (info.DumpingInfo == null) info.DumpingInfo = new DumpingInfoSection(); + + // Ensure special dictionaries + if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); + if (info.CommonDiscInfo.ContentsSpecialFields == null) info.CommonDiscInfo.ContentsSpecialFields = new Dictionary(); + + return info; + } +#else + public static SubmissionInfo EnsureAllSections(SubmissionInfo? info) + { + // If there's no info, create one + info ??= new SubmissionInfo(); + + // Ensure all sections + info.CommonDiscInfo ??= new CommonDiscInfoSection(); + info.VersionAndEditions ??= new VersionAndEditionsSection(); + info.EDC ??= new EDCSection(); + info.ParentCloneRelationship ??= new ParentCloneRelationshipSection(); + info.Extras ??= new ExtrasSection(); + info.CopyProtection ??= new CopyProtectionSection(); + info.DumpersAndStatus ??= new DumpersAndStatusSection(); + info.TracksAndWriteOffsets ??= new TracksAndWriteOffsetsSection(); + info.SizeAndChecksums ??= new SizeAndChecksumsSection(); + info.DumpingInfo ??= new DumpingInfoSection(); + + // Ensure special dictionaries + info.CommonDiscInfo.CommentsSpecialFields ??= new Dictionary(); + info.CommonDiscInfo.ContentsSpecialFields ??= new Dictionary(); + + return info; + } +#endif + /// /// Extract all of the possible information from a given input combination /// @@ -135,34 +187,26 @@ namespace MPF.Core Serial = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty, Barcode = options.AddPlaceholders ? Template.OptionalValue : string.Empty, Contents = string.Empty, -#if NET48 - ContentsSpecialFields = new Dictionary(), -#else - ContentsSpecialFields = new Dictionary(), -#endif - Comments = string.Empty, -#if NET48 - CommentsSpecialFields = new Dictionary(), -#else - CommentsSpecialFields = new Dictionary(), -#endif }, VersionAndEditions = new VersionAndEditionsSection() { Version = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty, OtherEditions = options.AddPlaceholders ? "(VERIFY THIS) Original" : string.Empty, }, - TracksAndWriteOffsets = new TracksAndWriteOffsetsSection(), }; + // Ensure that required sections exist + info = EnsureAllSections(info); + // Get specific tool output handling parameters?.GenerateSubmissionInfo(info, options, combinedBase, drive, options.IncludeArtifacts); // Get a list of matching IDs for each line in the DAT - if (!string.IsNullOrEmpty(info.TracksAndWriteOffsets.ClrMameProData) && options.HasRedumpLogin) #if NET48 + if (!string.IsNullOrEmpty(info.TracksAndWriteOffsets.ClrMameProData) && options.HasRedumpLogin) FillFromRedump(options, info, resultProgress); #else + if (!string.IsNullOrEmpty(info.TracksAndWriteOffsets!.ClrMameProData) && options.HasRedumpLogin) _ = await FillFromRedump(options, info, resultProgress); #endif @@ -172,14 +216,22 @@ namespace MPF.Core // Add the volume label to comments, if possible or necessary if (drive?.VolumeLabel != null && drive.GetRedumpSystemFromVolumeLabel() == null) +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.VolumeLabel] = drive.VolumeLabel; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.VolumeLabel] = drive.VolumeLabel; +#endif // Extract info based generically on MediaType switch (mediaType) { case MediaType.CDROM: case MediaType.GDROM: +#if NET48 info.CommonDiscInfo.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#else + info.CommonDiscInfo!.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#endif info.CommonDiscInfo.Layer0MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; @@ -190,12 +242,19 @@ namespace MPF.Core case MediaType.DVD: case MediaType.HDDVD: case MediaType.BluRay: - if (info.SizeAndChecksums == null) info.SizeAndChecksums = new SizeAndChecksumsSection(); // If we have a single-layer disc +#if NET48 if (info.SizeAndChecksums.Layerbreak == default) +#else + if (info.SizeAndChecksums!.Layerbreak == default) +#endif { +#if NET48 info.CommonDiscInfo.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#else + info.CommonDiscInfo!.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#endif info.CommonDiscInfo.Layer0MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; @@ -205,7 +264,11 @@ namespace MPF.Core // If we have a dual-layer disc else { +#if NET48 info.CommonDiscInfo.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#else + info.CommonDiscInfo!.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#endif info.CommonDiscInfo.Layer0MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; @@ -220,23 +283,37 @@ namespace MPF.Core break; case MediaType.NintendoGameCubeGameDisc: +#if NET48 info.CommonDiscInfo.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#else + info.CommonDiscInfo!.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#endif info.CommonDiscInfo.Layer0MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer1MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0AdditionalMould = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.BCA = info.Extras.BCA ?? (options.AddPlaceholders ? Template.RequiredValue : string.Empty); +#else + info.Extras!.BCA ??= (options.AddPlaceholders ? Template.RequiredValue : string.Empty); +#endif break; case MediaType.NintendoWiiOpticalDisc: - if (info.SizeAndChecksums == null) info.SizeAndChecksums = new SizeAndChecksumsSection(); // If we have a single-layer disc +#if NET48 if (info.SizeAndChecksums.Layerbreak == default) +#else + if (info.SizeAndChecksums!.Layerbreak == default) +#endif { +#if NET48 info.CommonDiscInfo.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#else + info.CommonDiscInfo!.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#endif info.CommonDiscInfo.Layer0MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; @@ -246,7 +323,11 @@ namespace MPF.Core // If we have a dual-layer disc else { +#if NET48 info.CommonDiscInfo.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#else + info.CommonDiscInfo!.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#endif info.CommonDiscInfo.Layer0MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; @@ -258,15 +339,22 @@ namespace MPF.Core info.CommonDiscInfo.Layer1MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; } - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.DiscKey = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.Extras!.DiscKey = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif info.Extras.BCA = info.Extras.BCA ?? (options.AddPlaceholders ? Template.RequiredValue : string.Empty); break; case MediaType.UMD: // Both single- and dual-layer discs have two "layers" for the ring +#if NET48 info.CommonDiscInfo.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#else + info.CommonDiscInfo!.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#endif info.CommonDiscInfo.Layer0MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer0MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; @@ -275,10 +363,15 @@ namespace MPF.Core info.CommonDiscInfo.Layer1MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; info.CommonDiscInfo.Layer1ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; - if (info.SizeAndChecksums == null) info.SizeAndChecksums = new SizeAndChecksumsSection(); +#if NET48 info.SizeAndChecksums.CRC32 = info.SizeAndChecksums.CRC32 ?? (options.AddPlaceholders ? Template.RequiredValue + " [Not automatically generated for UMD]" : string.Empty); info.SizeAndChecksums.MD5 = info.SizeAndChecksums.MD5 ?? (options.AddPlaceholders ? Template.RequiredValue + " [Not automatically generated for UMD]" : string.Empty); info.SizeAndChecksums.SHA1 = info.SizeAndChecksums.SHA1 ?? (options.AddPlaceholders ? Template.RequiredValue + " [Not automatically generated for UMD]" : string.Empty); +#else + info.SizeAndChecksums!.CRC32 ??= (options.AddPlaceholders ? Template.RequiredValue + " [Not automatically generated for UMD]" : string.Empty); + info.SizeAndChecksums.MD5 ??= (options.AddPlaceholders ? Template.RequiredValue + " [Not automatically generated for UMD]" : string.Empty); + info.SizeAndChecksums.SHA1 ??= (options.AddPlaceholders ? Template.RequiredValue + " [Not automatically generated for UMD]" : string.Empty); +#endif info.TracksAndWriteOffsets.ClrMameProData = null; break; } @@ -287,7 +380,11 @@ namespace MPF.Core switch (system) { case RedumpSystem.AcornArchimedes: +#if NET48 info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.UnitedKingdom; +#else + info.CommonDiscInfo!.Region ??= Region.UnitedKingdom; +#endif break; case RedumpSystem.AppleMacintosh: @@ -300,11 +397,11 @@ namespace MPF.Core resultProgress?.Report(Result.Success("Running copy protection scan... this might take a while!")); var (protectionString, fullProtections) = await GetCopyProtection(drive, options, protectionProgress); - if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection(); - info.CopyProtection.Protection = protectionString; #if NET48 + info.CopyProtection.Protection = protectionString; info.CopyProtection.FullProtections = fullProtections ?? new Dictionary>(); #else + info.CopyProtection!.Protection = protectionString; info.CopyProtection.FullProtections = fullProtections as Dictionary?> ?? new Dictionary?>(); #endif resultProgress?.Report(Result.Success("Copy protection scan complete!")); @@ -314,73 +411,139 @@ namespace MPF.Core case RedumpSystem.AudioCD: case RedumpSystem.DVDAudio: case RedumpSystem.SuperAudioCD: +#if NET48 info.CommonDiscInfo.Category = info.CommonDiscInfo.Category ?? DiscCategory.Audio; +#else + info.CommonDiscInfo!.Category ??= DiscCategory.Audio; +#endif break; case RedumpSystem.BandaiPlaydiaQuickInteractiveSystem: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan; break; case RedumpSystem.BDVideo: +#if NET48 info.CommonDiscInfo.Category = info.CommonDiscInfo.Category ?? DiscCategory.BonusDiscs; - if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection(); info.CopyProtection.Protection = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#else + info.CommonDiscInfo!.Category ??= DiscCategory.BonusDiscs; + info.CopyProtection!.Protection = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#endif break; case RedumpSystem.CommodoreAmigaCD: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.CommodoreAmigaCD32: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Europe; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; + info.CommonDiscInfo.Region ??= Region.Europe; +#endif break; case RedumpSystem.CommodoreAmigaCDTV: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Europe; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; + info.CommonDiscInfo.Region ??= Region.Europe; +#endif break; case RedumpSystem.DVDVideo: +#if NET48 info.CommonDiscInfo.Category = info.CommonDiscInfo.Category ?? DiscCategory.BonusDiscs; +#else + info.CommonDiscInfo!.Category ??= DiscCategory.BonusDiscs; +#endif break; case RedumpSystem.FujitsuFMTownsseries: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan; break; case RedumpSystem.FujitsuFMTownsMarty: +#if NET48 info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan; +#else + info.CommonDiscInfo!.Region ??= Region.Japan; +#endif break; case RedumpSystem.IncredibleTechnologiesEagle: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.KonamieAmusement: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.KonamiFireBeat: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.KonamiSystemGV: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.KonamiSystem573: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.KonamiTwinkle: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.MattelHyperScan: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.MicrosoftXboxOne: @@ -389,7 +552,11 @@ namespace MPF.Core string xboxOneMsxcPath = Path.Combine($"{drive.Letter}:\\", "MSXC"); if (drive != null && Directory.Exists(xboxOneMsxcPath)) { +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.Filename] = string.Join("\n", +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.Filename] = string.Join("\n", +#endif Directory.GetFiles(xboxOneMsxcPath, "*", SearchOption.TopDirectoryOnly).Select(Path.GetFileName)); } } @@ -402,7 +569,11 @@ namespace MPF.Core string xboxSeriesXMsxcPath = Path.Combine($"{drive.Letter}:\\", "MSXC"); if (drive != null && Directory.Exists(xboxSeriesXMsxcPath)) { +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.Filename] = string.Join("\n", +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.Filename] = string.Join("\n", +#endif Directory.GetFiles(xboxSeriesXMsxcPath, "*", SearchOption.TopDirectoryOnly).Select(Path.GetFileName)); } } @@ -410,59 +581,112 @@ namespace MPF.Core break; case RedumpSystem.NamcoSegaNintendoTriforce: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.NavisoftNaviken21: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; + info.CommonDiscInfo.Region ??= Region.Japan; +#endif break; case RedumpSystem.NECPC88series: +#if NET48 info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan; +#else + info.CommonDiscInfo!.Region ??= Region.Japan; +#endif break; case RedumpSystem.NECPC98series: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; + info.CommonDiscInfo!.Region ??= Region.Japan; +#endif break; case RedumpSystem.NECPCFXPCFXGA: +#if NET48 info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan; +#else + info.CommonDiscInfo!.Region ??= Region.Japan; +#endif break; case RedumpSystem.SegaChihiro: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.SegaDreamcast: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.SegaNaomi: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.SegaNaomi2: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.SegaTitanVideo: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.SharpX68000: +#if NET48 info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan; +#else + info.CommonDiscInfo!.Region ??= Region.Japan; +#endif break; case RedumpSystem.SNKNeoGeoCD: +#if NET48 info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif break; case RedumpSystem.SonyPlayStation: // Only check the disc if the dumping program couldn't detect - if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection(); +#if NET48 if (drive != null && info.CopyProtection.AntiModchip == YesNo.NULL) +#else + if (drive != null && info.CopyProtection!.AntiModchip == YesNo.NULL) +#endif { resultProgress?.Report(Result.Success("Checking for anti-modchip strings... this might take a while!")); info.CopyProtection.AntiModchip = await GetAntiModchipDetected(drive) ? YesNo.Yes : YesNo.No; @@ -480,27 +704,45 @@ namespace MPF.Core break; case RedumpSystem.SonyPlayStation2: +#if NET48 info.CommonDiscInfo.LanguageSelection = new LanguageSelection?[] { LanguageSelection.BiosSettings, LanguageSelection.LanguageSelector, LanguageSelection.OptionsMenu }; +#else + info.CommonDiscInfo!.LanguageSelection = new LanguageSelection?[] { LanguageSelection.BiosSettings, LanguageSelection.LanguageSelector, LanguageSelection.OptionsMenu }; +#endif break; case RedumpSystem.SonyPlayStation3: - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.DiscKey = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#else + info.Extras!.DiscKey = options.AddPlaceholders ? Template.RequiredValue : string.Empty; +#endif info.Extras.DiscID = options.AddPlaceholders ? Template.RequiredValue : string.Empty; break; case RedumpSystem.TomyKissSite: +#if NET48 info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan; +#else + info.CommonDiscInfo!.Region ??= Region.Japan; +#endif break; case RedumpSystem.ZAPiTGamesGameWaveFamilyEntertainmentSystem: - if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection(); +#if NET48 info.CopyProtection.Protection = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#else + info.CopyProtection!.Protection = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty; +#endif break; } // Set the category if it's not overriden +#if NET48 info.CommonDiscInfo.Category = info.CommonDiscInfo.Category ?? DiscCategory.Games; +#else + info.CommonDiscInfo!.Category ??= DiscCategory.Games; +#endif // Comments and contents have odd handling if (string.IsNullOrEmpty(info.CommonDiscInfo.Comments)) @@ -642,8 +884,13 @@ namespace MPF.Core /// Status of the LibCrypt data, if possible private static void GetLibCryptDetected(SubmissionInfo info, string basePath) { - bool? psLibCryptStatus = Protection.GetLibCryptDetected(basePath + ".sub"); +#if NET48 if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection(); +#else + info.CopyProtection ??= new CopyProtectionSection(); +#endif + + bool? psLibCryptStatus = Protection.GetLibCryptDetected(basePath + ".sub"); if (psLibCryptStatus == true) { // Guard against false positives @@ -2161,11 +2408,7 @@ namespace MPF.Core private async static Task FillFromId(RedumpHttpClient wc, SubmissionInfo info, int id, bool includeAllData) { // Ensure that required sections exist - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); - if (info.CommonDiscInfo.ContentsSpecialFields == null) info.CommonDiscInfo.ContentsSpecialFields = new Dictionary(); - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); - if (info.DumpersAndStatus == null) info.DumpersAndStatus = new DumpersAndStatusSection(); + info = EnsureAllSections(info); var discData = await wc.DownloadSingleSiteID(id); if (string.IsNullOrEmpty(discData)) @@ -2185,7 +2428,7 @@ namespace MPF.Core #if NET48 info.CommonDiscInfo.Title = title.Substring(0, firstParenLocation); #else - info.CommonDiscInfo.Title = title[..firstParenLocation]; + info.CommonDiscInfo!.Title = title[..firstParenLocation]; #endif var subMatches = Constants.DiscNumberLetterRegex.Matches(title); foreach (Match subMatch in subMatches.Cast()) @@ -2208,16 +2451,28 @@ namespace MPF.Core // Otherwise, leave the title as-is else { +#if NET48 info.CommonDiscInfo.Title = title; +#else + info.CommonDiscInfo!.Title = title; +#endif } } // Foreign Title match = Constants.ForeignTitleRegex.Match(discData); if (match.Success) +#if NET48 info.CommonDiscInfo.ForeignTitleNonLatin = WebUtility.HtmlDecode(match.Groups[1].Value); +#else + info.CommonDiscInfo!.ForeignTitleNonLatin = WebUtility.HtmlDecode(match.Groups[1].Value); +#endif else +#if NET48 info.CommonDiscInfo.ForeignTitleNonLatin = null; +#else + info.CommonDiscInfo!.ForeignTitleNonLatin = null; +#endif // Category match = Constants.CategoryRegex.Match(discData); @@ -2265,7 +2520,11 @@ namespace MPF.Core } // Version +#if NET48 if (info.VersionAndEditions.Version == null) +#else + if (info.VersionAndEditions!.Version == null) +#endif { match = Constants.VersionRegex.Match(discData); if (match.Success) @@ -2278,7 +2537,11 @@ namespace MPF.Core { // Start with any currently listed dumpers var tempDumpers = new List(); +#if NET48 if (info.DumpersAndStatus.Dumpers != null && info.DumpersAndStatus.Dumpers.Length > 0) +#else + if (info.DumpersAndStatus!.Dumpers != null && info.DumpersAndStatus.Dumpers.Length > 0) +#endif { foreach (string dumper in info.DumpersAndStatus.Dumpers) tempDumpers.Add(dumper); @@ -2387,7 +2650,11 @@ namespace MPF.Core } // If we don't already have this site code, add it to the dictionary +#if NET48 if (!info.CommonDiscInfo.CommentsSpecialFields.ContainsKey(siteCode.Value)) +#else + if (!info.CommonDiscInfo.CommentsSpecialFields!.ContainsKey(siteCode.Value)) +#endif info.CommonDiscInfo.CommentsSpecialFields[siteCode.Value] = $"(VERIFY THIS) {commentLine.Replace(shortName, string.Empty).Trim()}"; // Otherwise, append the value to the existing key @@ -2402,7 +2669,11 @@ namespace MPF.Core { if (addToLast && lastSiteCode != null) { +#if NET48 if (!string.IsNullOrWhiteSpace(info.CommonDiscInfo.CommentsSpecialFields[lastSiteCode.Value])) +#else + if (!string.IsNullOrWhiteSpace(info.CommonDiscInfo.CommentsSpecialFields![lastSiteCode.Value])) +#endif info.CommonDiscInfo.CommentsSpecialFields[lastSiteCode.Value] += "\n"; info.CommonDiscInfo.CommentsSpecialFields[lastSiteCode.Value] += commentLine; @@ -2474,7 +2745,11 @@ namespace MPF.Core lastSiteCode = siteCode; // If we don't already have this site code, add it to the dictionary +#if NET48 if (!info.CommonDiscInfo.ContentsSpecialFields.ContainsKey(siteCode.Value)) +#else + if (!info.CommonDiscInfo.ContentsSpecialFields!.ContainsKey(siteCode.Value)) +#endif info.CommonDiscInfo.ContentsSpecialFields[siteCode.Value] = $"(VERIFY THIS) {contentLine.Replace(shortName, string.Empty).Trim()}"; // A subset of tags can be multiline @@ -2490,7 +2765,11 @@ namespace MPF.Core { if (addToLast && lastSiteCode != null) { +#if NET48 if (!string.IsNullOrWhiteSpace(info.CommonDiscInfo.ContentsSpecialFields[lastSiteCode.Value])) +#else + if (!string.IsNullOrWhiteSpace(info.CommonDiscInfo.ContentsSpecialFields![lastSiteCode.Value])) +#endif info.CommonDiscInfo.ContentsSpecialFields[lastSiteCode.Value] += "\n"; info.CommonDiscInfo.ContentsSpecialFields[lastSiteCode.Value] += contentLine; @@ -2547,7 +2826,11 @@ namespace MPF.Core return false; // Set the current dumper based on username +#if NET48 if (info.DumpersAndStatus == null) info.DumpersAndStatus = new DumpersAndStatusSection(); +#else + info.DumpersAndStatus ??= new DumpersAndStatusSection(); +#endif info.DumpersAndStatus.Dumpers = new string[] { options.RedumpUsername }; info.PartiallyMatchedIDs = new List(); diff --git a/MPF.Core/Modules/Aaru/Parameters.cs b/MPF.Core/Modules/Aaru/Parameters.cs index 41e455ce..123ea8db 100644 --- a/MPF.Core/Modules/Aaru/Parameters.cs +++ b/MPF.Core/Modules/Aaru/Parameters.cs @@ -273,7 +273,7 @@ namespace MPF.Core.Modules.Aaru /// public override (bool, List) CheckAllOutputFilesExist(string basePath, bool preCheck) { - List missingFiles = new List(); + var missingFiles = new List(); switch (this.Type) { case MediaType.CDROM: @@ -332,9 +332,15 @@ namespace MPF.Core.Modules.Aaru // TODO: Fill in submission info specifics for Aaru var outputDirectory = Path.GetDirectoryName(basePath); + // Ensure that required sections exist + info = InfoTool.EnsureAllSections(info); + // TODO: Determine if there's an Aaru version anywhere - if (info.DumpingInfo == null) info.DumpingInfo = new DumpingInfoSection(); +#if NET48 info.DumpingInfo.DumpingProgram = EnumConverter.LongName(this.InternalProgram); +#else + info.DumpingInfo!.DumpingProgram = EnumConverter.LongName(this.InternalProgram); +#endif info.DumpingInfo.DumpingDate = GetFileModifiedDate(basePath + ".cicm.xml")?.ToString("yyyy-MM-dd HH:mm:ss"); // Deserialize the sidecar, if possible @@ -366,8 +372,11 @@ namespace MPF.Core.Modules.Aaru var datafile = GenerateDatafile(sidecar, basePath); // Fill in the hash data - if (info.TracksAndWriteOffsets == null) info.TracksAndWriteOffsets = new TracksAndWriteOffsetsSection(); +#if NET48 info.TracksAndWriteOffsets.ClrMameProData = GenerateDatfile(datafile); +#else + info.TracksAndWriteOffsets!.ClrMameProData = GenerateDatfile(datafile); +#endif switch (this.Type) { @@ -381,8 +390,11 @@ namespace MPF.Core.Modules.Aaru if (File.Exists(basePath + ".resume.xml")) errorCount = GetErrorCount(basePath + ".resume.xml"); - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); +#if NET48 info.CommonDiscInfo.ErrorsCount = (errorCount == -1 ? "Error retrieving error count" : errorCount.ToString()); +#else + info.CommonDiscInfo!.ErrorsCount = (errorCount == -1 ? "Error retrieving error count" : errorCount.ToString()); +#endif info.TracksAndWriteOffsets.Cuesheet = GenerateCuesheet(sidecar, basePath) ?? string.Empty; @@ -394,12 +406,15 @@ namespace MPF.Core.Modules.Aaru case MediaType.DVD: case MediaType.HDDVD: case MediaType.BluRay: - if (info.SizeAndChecksums == null) info.SizeAndChecksums = new SizeAndChecksumsSection(); // Get the individual hash data, as per internal if (GetISOHashValues(datafile, out long size, out var crc32, out var md5, out var sha1)) { +#if NET48 info.SizeAndChecksums.Size = size; +#else + info.SizeAndChecksums!.CRC32 = crc32; +#endif info.SizeAndChecksums.CRC32 = crc32; info.SizeAndChecksums.MD5 = md5; info.SizeAndChecksums.SHA1 = sha1; @@ -418,7 +433,11 @@ namespace MPF.Core.Modules.Aaru if (this.Type == MediaType.DVD) layerbreak = GetLayerbreak(sidecar) ?? string.Empty; else if (this.Type == MediaType.BluRay) +#if NET48 layerbreak = info.SizeAndChecksums.Size > 25_025_314_816 ? "25025314816" : null; +#else + layerbreak = info.SizeAndChecksums!.Size > 25_025_314_816 ? "25025314816" : null; +#endif // If we have a single-layer disc if (string.IsNullOrWhiteSpace(layerbreak)) @@ -428,7 +447,11 @@ namespace MPF.Core.Modules.Aaru // If we have a dual-layer disc else { +#if NET48 info.SizeAndChecksums.Layerbreak = Int64.Parse(layerbreak); +#else + info.SizeAndChecksums!.Layerbreak = Int64.Parse(layerbreak); +#endif } // TODO: Investigate XGD disc outputs @@ -448,52 +471,60 @@ namespace MPF.Core.Modules.Aaru case RedumpSystem.DVDAudio: case RedumpSystem.DVDVideo: - if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection(); +#if NET48 info.CopyProtection.Protection = GetDVDProtection(sidecar) ?? string.Empty; +#else + info.CopyProtection!.Protection = GetDVDProtection(sidecar) ?? string.Empty; +#endif break; case RedumpSystem.KonamiPython2: if (GetPlayStationExecutableInfo(drive?.Letter, out var pythonTwoSerial, out Region? pythonTwoRegion, out var pythonTwoDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = pythonTwoSerial ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = pythonTwoSerial ?? string.Empty; +#endif info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? pythonTwoRegion; info.CommonDiscInfo.EXEDateBuildDate = pythonTwoDate; } - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); +#if NET48 info.VersionAndEditions.Version = GetPlayStation2Version(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation2Version(drive?.Letter) ?? string.Empty; +#endif break; case RedumpSystem.MicrosoftXbox: if (GetXgdAuxInfo(sidecar, out var xgd1DMIHash, out var xgd1PFIHash, out var xgd1SSHash, out var ss, out var xgd1SSVer)) { - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.DMIHash] = xgd1DMIHash ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.DMIHash] = xgd1DMIHash ?? string.Empty; +#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.PFIHash] = xgd1PFIHash ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd1SSHash ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSVersion] = xgd1SSVer ?? string.Empty; - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.SecuritySectorRanges = ss ?? string.Empty; +#else + info.Extras!.SecuritySectorRanges = ss ?? string.Empty; +#endif } if (GetXboxDMIInfo(sidecar, out var serial, out var version, out Region? region)) { - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); +#if NET48 info.CommonDiscInfo.Serial = serial ?? string.Empty; - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); info.VersionAndEditions.Version = version ?? string.Empty; +#else + info.CommonDiscInfo!.Serial = serial ?? string.Empty; + info.VersionAndEditions!.Version = version ?? string.Empty; +#endif info.CommonDiscInfo.Region = region; } @@ -502,26 +533,30 @@ namespace MPF.Core.Modules.Aaru case RedumpSystem.MicrosoftXbox360: if (GetXgdAuxInfo(sidecar, out var xgd23DMIHash, out var xgd23PFIHash, out var xgd23SSHash, out var ss360, out var xgd23SSVer)) { - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.DMIHash] = xgd23DMIHash ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.DMIHash] = xgd23DMIHash ?? string.Empty; +#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.PFIHash] = xgd23PFIHash ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd23SSHash ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSVersion] = xgd23SSVer ?? string.Empty; - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.SecuritySectorRanges = ss360 ?? string.Empty; +#else + info.Extras!.SecuritySectorRanges = ss360 ?? string.Empty; +#endif } if (GetXbox360DMIInfo(sidecar, out var serial360, out var version360, out Region? region360)) { - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); +#if NET48 info.CommonDiscInfo.Serial = serial360 ?? string.Empty; - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); info.VersionAndEditions.Version = version360 ?? string.Empty; +#else + info.CommonDiscInfo!.Serial = serial360 ?? string.Empty; + info.VersionAndEditions!.Version = version360 ?? string.Empty; +#endif info.CommonDiscInfo.Region = region360; } break; @@ -530,13 +565,11 @@ namespace MPF.Core.Modules.Aaru if (GetPlayStationExecutableInfo(drive?.Letter, out var playstationSerial, out Region? playstationRegion, out var playstationDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = playstationSerial ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = playstationSerial ?? string.Empty; +#endif info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? playstationRegion; info.CommonDiscInfo.EXEDateBuildDate = playstationDate; } @@ -547,62 +580,61 @@ namespace MPF.Core.Modules.Aaru if (GetPlayStationExecutableInfo(drive?.Letter, out var playstationTwoSerial, out Region? playstationTwoRegion, out var playstationTwoDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = playstationTwoSerial ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = playstationTwoSerial ?? string.Empty; +#endif info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? playstationTwoRegion; info.CommonDiscInfo.EXEDateBuildDate = playstationTwoDate; } - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); +#if NET48 info.VersionAndEditions.Version = GetPlayStation2Version(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation2Version(drive?.Letter) ?? string.Empty; +#endif break; case RedumpSystem.SonyPlayStation3: - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); - info.VersionAndEditions.Version = GetPlayStation3Version(drive?.Letter) ?? string.Empty; - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif + info.VersionAndEditions.Version = GetPlayStation3Version(drive?.Letter) ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = GetPlayStation3Serial(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation3Version(drive?.Letter) ?? string.Empty; + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = GetPlayStation3Serial(drive?.Letter) ?? string.Empty; +#endif break; case RedumpSystem.SonyPlayStation4: - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); - info.VersionAndEditions.Version = GetPlayStation4Version(drive?.Letter) ?? string.Empty; - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif + info.VersionAndEditions.Version = GetPlayStation4Version(drive?.Letter) ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = GetPlayStation4Serial(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation4Version(drive?.Letter) ?? string.Empty; + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = GetPlayStation4Serial(drive?.Letter) ?? string.Empty; +#endif break; case RedumpSystem.SonyPlayStation5: - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); - info.VersionAndEditions.Version = GetPlayStation5Version(drive?.Letter) ?? string.Empty; - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif + info.VersionAndEditions.Version = GetPlayStation5Version(drive?.Letter) ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = GetPlayStation5Serial(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation5Version(drive?.Letter) ?? string.Empty; + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = GetPlayStation5Serial(drive?.Letter) ?? string.Empty; +#endif break; } // Fill in any artifacts that exist, Base64-encoded, if we need to if (includeArtifacts) { +#if NET48 if (info.Artifacts == null) info.Artifacts = new Dictionary(); +#else + info.Artifacts ??= new Dictionary(); +#endif if (File.Exists(basePath + ".cicm.xml")) info.Artifacts["cicm"] = GetBase64(GetFullFile(basePath + ".cicm.xml")) ?? string.Empty; if (File.Exists(basePath + ".ibg")) @@ -625,7 +657,7 @@ namespace MPF.Core.Modules.Aaru public override string? GenerateParameters() #endif { - List parameters = new List(); + var parameters = new List(); #region Pre-command flags @@ -651,8 +683,12 @@ namespace MPF.Core.Modules.Aaru #endregion +#if NET48 if (BaseCommand == null) BaseCommand = CommandStrings.NONE; +#else + BaseCommand ??= CommandStrings.NONE; +#endif if (!string.IsNullOrWhiteSpace(BaseCommand)) parameters.Add(BaseCommand); @@ -1641,7 +1677,7 @@ namespace MPF.Core.Modules.Aaru /// public override List GetLogFilePaths(string basePath) { - List logFiles = new List(); + var logFiles = new List(); switch (this.Type) { case MediaType.CDROM: @@ -2340,7 +2376,7 @@ namespace MPF.Core.Modules.Aaru return true; } -#endregion + #endregion #region Private Extra Methods @@ -2350,9 +2386,9 @@ namespace MPF.Core.Modules.Aaru /// Command string to normalize /// Normalized command #if NET48 - private string NormalizeCommand(List parts, ref int start) + private static string NormalizeCommand(List parts, ref int start) #else - private string? NormalizeCommand(List parts, ref int start) + private static string? NormalizeCommand(List parts, ref int start) #endif { // Invalid start means invalid command @@ -2383,9 +2419,9 @@ namespace MPF.Core.Modules.Aaru /// Command string to normalize /// Normalized command #if NET48 - private string NormalizeCommand(string baseCommand) + private static string NormalizeCommand(string baseCommand) #else - private string? NormalizeCommand(string baseCommand) + private static string? NormalizeCommand(string baseCommand) #endif { // If the base command is inavlid, just return nulls @@ -2606,7 +2642,7 @@ namespace MPF.Core.Modules.Aaru /// TrackTypeTrackType to convert /// Sector size to help with specific subtypes /// CueTrackDataType representing the input data - private CueTrackDataType ConvertToDataType(TrackTypeTrackType trackType, uint bytesPerSector) + private static CueTrackDataType ConvertToDataType(TrackTypeTrackType trackType, uint bytesPerSector) { switch (trackType) { @@ -2637,7 +2673,7 @@ namespace MPF.Core.Modules.Aaru /// /// TrackFlagsType containing flag data /// CueTrackFlag representing the flags - private CueTrackFlag ConvertToTrackFlag(TrackFlagsType trackFlagsType) + private static CueTrackFlag ConvertToTrackFlag(TrackFlagsType trackFlagsType) { if (trackFlagsType == null) return 0; @@ -2663,9 +2699,9 @@ namespace MPF.Core.Modules.Aaru /// Base path for determining file names /// String containing the cuesheet, null on error #if NET48 - private string GenerateCuesheet(CICMMetadataType cicmSidecar, string basePath) + private static string GenerateCuesheet(CICMMetadataType cicmSidecar, string basePath) #else - private string? GenerateCuesheet(CICMMetadataType? cicmSidecar, string basePath) + private static string? GenerateCuesheet(CICMMetadataType? cicmSidecar, string basePath) #endif { // If the object is null, we can't get information from it @@ -2677,7 +2713,7 @@ namespace MPF.Core.Modules.Aaru var cueFiles = new List(); var cueSheet = new CueSheet { - Performer = string.Join(", ", cicmSidecar.Performer ?? new string[0]), + Performer = string.Join(", ", cicmSidecar.Performer ?? Array.Empty()), }; // Only care about OpticalDisc types @@ -2702,7 +2738,7 @@ namespace MPF.Core.Modules.Aaru foreach (TrackType track in opticalDisc.Track) { // Create cue track entry - CueTrack cueTrack = new CueTrack + var cueTrack = new CueTrack { Number = (int)(track.Sequence?.TrackNumber ?? 0), DataType = ConvertToDataType(track.TrackType1, track.BytesPerSector), @@ -2711,7 +2747,7 @@ namespace MPF.Core.Modules.Aaru }; // Create cue file entry - CueFile cueFile = new CueFile + var cueFile = new CueFile { FileName = GenerateTrackName(basePath, (int)totalTracks, cueTrack.Number, opticalDisc.DiscType), FileType = CueFileType.BINARY, @@ -2930,8 +2966,8 @@ namespace MPF.Core.Modules.Aaru return null; // Required variables - Datafile datafile = new Datafile(); - List roms = new List(); + var datafile = new Datafile(); + var roms = new List(); // Process OpticalDisc, if possible if (cicmSidecar.OpticalDisc != null && cicmSidecar.OpticalDisc.Length > 0) @@ -3184,7 +3220,7 @@ namespace MPF.Core.Modules.Aaru } // Now generate the byte array data - List pvdData = new List(); + var pvdData = new List(); pvdData.AddRange(new string(' ', 13).ToCharArray().Select(c => (byte)c)); pvdData.AddRange(GeneratePVDDateTimeBytes(creation)); pvdData.AddRange(GeneratePVDDateTimeBytes(modification)); @@ -3255,7 +3291,11 @@ namespace MPF.Core.Modules.Aaru return null; string pvdLine = $"{row} : "; +#if NET48 pvdLine += BitConverter.ToString(bytes.Slice(0, 8).ToArray()).Replace("-", " "); +#else + pvdLine += BitConverter.ToString(bytes[..8].ToArray()).Replace("-", " "); +#endif pvdLine += " "; pvdLine += BitConverter.ToString(bytes.Slice(8, 8).ToArray().ToArray()).Replace("-", " "); pvdLine += " "; @@ -3295,7 +3335,7 @@ namespace MPF.Core.Modules.Aaru if (xtr == null) return null; - XmlSerializer serializer = new XmlSerializer(typeof(CICMMetadataType)); + var serializer = new XmlSerializer(typeof(CICMMetadataType)); return serializer.Deserialize(xtr) as CICMMetadataType; } @@ -3402,7 +3442,7 @@ namespace MPF.Core.Modules.Aaru long? totalErrors = null; // Parse the resume XML file - using (StreamReader sr = File.OpenText(resume)) + using (var sr = File.OpenText(resume)) { try { diff --git a/MPF.Core/Modules/BaseParameters.cs b/MPF.Core/Modules/BaseParameters.cs index fda68a07..b8ee3b29 100644 --- a/MPF.Core/Modules/BaseParameters.cs +++ b/MPF.Core/Modules/BaseParameters.cs @@ -47,7 +47,11 @@ namespace MPF.Core.Modules /// /// Set of flags to pass to the executable /// +#if NET48 protected Dictionary flags = new Dictionary(); +#else + protected Dictionary flags = new(); +#endif protected internal IEnumerable Keys => flags.Keys; /// @@ -239,7 +243,11 @@ namespace MPF.Core.Modules /// /// Base filename and path to use for checking /// List of all log file paths, empty otherwise +#if NET48 public virtual List GetLogFilePaths(string basePath) => new List(); +#else + public virtual List GetLogFilePaths(string basePath) => new(); +#endif /// /// Get the MediaType from the current set of parameters diff --git a/MPF.Core/Modules/CleanRIp/Parameters.cs b/MPF.Core/Modules/CleanRIp/Parameters.cs index e18a56a1..5d7ddfec 100644 --- a/MPF.Core/Modules/CleanRIp/Parameters.cs +++ b/MPF.Core/Modules/CleanRIp/Parameters.cs @@ -39,7 +39,7 @@ namespace MPF.Core.Modules.CleanRip /// public override (bool, List) CheckAllOutputFilesExist(string basePath, bool preCheck) { - List missingFiles = new List(); + var missingFiles = new List(); switch (this.Type) { case MediaType.DVD: // Only added here to help users; not strictly correct @@ -70,9 +70,15 @@ namespace MPF.Core.Modules.CleanRip public override void GenerateSubmissionInfo(SubmissionInfo info, Options options, string basePath, Drive? drive, bool includeArtifacts) #endif { + // Ensure that required sections exist + info = InfoTool.EnsureAllSections(info); + // TODO: Determine if there's a CleanRip version anywhere - if (info.DumpingInfo == null) info.DumpingInfo = new DumpingInfoSection(); +#if NET48 info.DumpingInfo.DumpingProgram = EnumConverter.LongName(this.InternalProgram); +#else + info.DumpingInfo!.DumpingProgram = EnumConverter.LongName(this.InternalProgram); +#endif info.DumpingInfo.DumpingDate = GetFileModifiedDate(basePath + "-dumpinfo.txt")?.ToString("yyyy-MM-dd HH:mm:ss"); var datafile = GenerateCleanripDatafile(basePath + ".iso", basePath + "-dumpinfo.txt"); @@ -80,8 +86,11 @@ namespace MPF.Core.Modules.CleanRip // Get the individual hash data, as per internal if (GetISOHashValues(datafile, out long size, out var crc32, out var md5, out var sha1)) { - if (info.SizeAndChecksums == null) info.SizeAndChecksums = new SizeAndChecksumsSection(); +#if NET48 info.SizeAndChecksums.Size = size; +#else + info.SizeAndChecksums!.Size = size; +#endif info.SizeAndChecksums.CRC32 = crc32; info.SizeAndChecksums.MD5 = md5; info.SizeAndChecksums.SHA1 = sha1; @@ -98,23 +107,23 @@ namespace MPF.Core.Modules.CleanRip case MediaType.NintendoGameCubeGameDisc: case MediaType.NintendoWiiOpticalDisc: if (File.Exists(basePath + ".bca")) - { - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.BCA = GetBCA(basePath + ".bca"); - } +#else + info.Extras!.BCA = GetBCA(basePath + ".bca"); +#endif if (GetGameCubeWiiInformation(basePath + "-dumpinfo.txt", out Region? gcRegion, out var gcVersion, out var gcName)) { - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); - info.CommonDiscInfo.Region = gcRegion ?? info.CommonDiscInfo.Region; - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); - info.VersionAndEditions.Version = gcVersion ?? info.VersionAndEditions.Version; #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif + info.CommonDiscInfo.Region = gcRegion ?? info.CommonDiscInfo.Region; + info.VersionAndEditions.Version = gcVersion ?? info.VersionAndEditions.Version; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalName] = gcName ?? string.Empty; +#else + info.CommonDiscInfo!.Region = gcRegion ?? info.CommonDiscInfo.Region; + info.VersionAndEditions!.Version = gcVersion ?? info.VersionAndEditions.Version; + info.CommonDiscInfo.CommentsSpecialFields![SiteCode.InternalName] = gcName ?? string.Empty; +#endif } break; @@ -123,7 +132,12 @@ namespace MPF.Core.Modules.CleanRip // Fill in any artifacts that exist, Base64-encoded, if we need to if (includeArtifacts) { +#if NET48 if (info.Artifacts == null) info.Artifacts = new Dictionary(); +#else + info.Artifacts ??= new Dictionary(); +#endif + if (File.Exists(basePath + ".bca")) info.Artifacts["bca"] = GetBase64(GetFullFile(basePath + ".bca", binary: true)) ?? string.Empty; if (File.Exists(basePath + "-dumpinfo.txt")) @@ -134,7 +148,7 @@ namespace MPF.Core.Modules.CleanRip /// public override List GetLogFilePaths(string basePath) { - List logFiles = new List(); + var logFiles = new List(); switch (this.Type) { case MediaType.DVD: // Only added here to help users; not strictly correct @@ -171,7 +185,7 @@ namespace MPF.Core.Modules.CleanRip if (!File.Exists(dumpinfo)) return null; - using (StreamReader sr = File.OpenText(dumpinfo)) + using (var sr = File.OpenText(dumpinfo)) { long size = new FileInfo(iso).Length; string crc = string.Empty; @@ -190,12 +204,21 @@ namespace MPF.Core.Modules.CleanRip var line = sr.ReadLine()?.Trim(); if (string.IsNullOrWhiteSpace(line)) continue; +#if NET48 else if (line.StartsWith("CRC32")) crc = line.Substring(7).ToLowerInvariant(); else if (line.StartsWith("MD5")) md5 = line.Substring(5); else if (line.StartsWith("SHA-1")) sha1 = line.Substring(7); +#else + else if (line.StartsWith("CRC32")) + crc = line[7..].ToLowerInvariant(); + else if (line.StartsWith("MD5")) + md5 = line[5..]; + else if (line.StartsWith("SHA-1")) + sha1 = line[7..]; +#endif } return new Datafile @@ -267,7 +290,7 @@ namespace MPF.Core.Modules.CleanRip if (!File.Exists(dumpinfo)) return null; - using (StreamReader sr = File.OpenText(dumpinfo)) + using (var sr = File.OpenText(dumpinfo)) { long size = new FileInfo(iso).Length; string crc = string.Empty; @@ -286,12 +309,21 @@ namespace MPF.Core.Modules.CleanRip var line = sr.ReadLine()?.Trim(); if (string.IsNullOrWhiteSpace(line)) continue; +#if NET48 else if (line.StartsWith("CRC32")) crc = line.Substring(7).ToLowerInvariant(); else if (line.StartsWith("MD5")) md5 = line.Substring(5); else if (line.StartsWith("SHA-1")) sha1 = line.Substring(7); +#else + else if (line.StartsWith("CRC32")) + crc = line[7..].ToLowerInvariant(); + else if (line.StartsWith("MD5")) + md5 = line[5..]; + else if (line.StartsWith("SHA-1")) + sha1 = line[7..]; +#endif } return $""; @@ -324,7 +356,7 @@ namespace MPF.Core.Modules.CleanRip if (!File.Exists(dumpinfo)) return false; - using (StreamReader sr = File.OpenText(dumpinfo)) + using (var sr = File.OpenText(dumpinfo)) { try { @@ -342,15 +374,27 @@ namespace MPF.Core.Modules.CleanRip } else if (line.StartsWith("Version")) { +#if NET48 version = line.Substring("Version: ".Length); +#else + version = line["Version: ".Length..]; +#endif } else if (line.StartsWith("Internal Name")) { +#if NET48 name = line.Substring("Internal Name: ".Length); +#else + name = line["Internal Name: ".Length..]; +#endif } else if (line.StartsWith("Filename")) { +#if NET48 string serial = line.Substring("Filename: ".Length); +#else + string serial = line["Filename: ".Length..]; +#endif // char gameType = serial[0]; // string gameid = serial[1] + serial[2]; diff --git a/MPF.Core/Modules/DiscImageCreator/Parameters.cs b/MPF.Core/Modules/DiscImageCreator/Parameters.cs index 82ec09c4..822e49a9 100644 --- a/MPF.Core/Modules/DiscImageCreator/Parameters.cs +++ b/MPF.Core/Modules/DiscImageCreator/Parameters.cs @@ -251,7 +251,7 @@ namespace MPF.Core.Modules.DiscImageCreator - volDesc - Volume descriptor information */ - List missingFiles = new List(); + var missingFiles = new List(); switch (this.Type) { case MediaType.CDROM: @@ -416,10 +416,16 @@ namespace MPF.Core.Modules.DiscImageCreator { var outputDirectory = Path.GetDirectoryName(basePath); + // Ensure that required sections exist + info = InfoTool.EnsureAllSections(info); + // Get the dumping program and version var (dicCmd, dicVersion) = GetCommandFilePathAndVersion(basePath); - if (info.DumpingInfo == null) info.DumpingInfo = new DumpingInfoSection(); +#if NET48 info.DumpingInfo.DumpingProgram = $"{EnumConverter.LongName(this.InternalProgram)} {dicVersion ?? "Unknown Version"}"; +#else + info.DumpingInfo!.DumpingProgram = $"{EnumConverter.LongName(this.InternalProgram)} {dicVersion ?? "Unknown Version"}"; +#endif info.DumpingInfo.DumpingDate = GetFileModifiedDate(dicCmd)?.ToString("yyyy-MM-dd HH:mm:ss"); // Fill in the hardware data @@ -438,28 +444,31 @@ namespace MPF.Core.Modules.DiscImageCreator var datafile = GetDatafile($"{basePath}.dat"); // Fill in the hash data - if (info.TracksAndWriteOffsets == null) info.TracksAndWriteOffsets = new TracksAndWriteOffsetsSection(); +#if NET48 info.TracksAndWriteOffsets.ClrMameProData = GenerateDatfile(datafile); +#else + info.TracksAndWriteOffsets!.ClrMameProData = GenerateDatfile(datafile); +#endif // Extract info based generically on MediaType switch (this.Type) { case MediaType.CDROM: case MediaType.GDROM: // TODO: Verify GD-ROM outputs this - if (info.Extras == null) info.Extras = new ExtrasSection(); - info.Extras.PVD = GetPVD($"{basePath}_mainInfo.txt") ?? "Disc has no PVD"; - - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); + info.Extras.PVD = GetPVD($"{basePath}_mainInfo.txt") ?? "Disc has no PVD"; #else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); + info.Extras!.PVD = GetPVD($"{basePath}_mainInfo.txt") ?? "Disc has no PVD"; #endif // Audio-only discs will fail if there are any C2 errors, so they would never get here if (this.System.IsAudio()) { +#if NET48 info.CommonDiscInfo.ErrorsCount = "0"; +#else + info.CommonDiscInfo!.ErrorsCount = "0"; +#endif } else { @@ -469,7 +478,11 @@ namespace MPF.Core.Modules.DiscImageCreator else if (File.Exists($"{basePath}.img_EccEdc.txt")) errorCount = GetErrorCount($"{basePath}.img_EccEdc.txt"); +#if NET48 info.CommonDiscInfo.ErrorsCount = (errorCount == -1 ? "Error retrieving error count" : errorCount.ToString()); +#else + info.CommonDiscInfo!.ErrorsCount = (errorCount == -1 ? "Error retrieving error count" : errorCount.ToString()); +#endif } info.TracksAndWriteOffsets.Cuesheet = GetFullFile($"{basePath}.cue") ?? string.Empty; @@ -483,13 +496,21 @@ namespace MPF.Core.Modules.DiscImageCreator // Attempt to get multisession data string cdMultiSessionInfo = GetMultisessionInformation($"{basePath}_disc.txt") ?? string.Empty; if (!string.IsNullOrWhiteSpace(cdMultiSessionInfo)) +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.Multisession] = cdMultiSessionInfo; +#else + info.CommonDiscInfo.CommentsSpecialFields![SiteCode.Multisession] = cdMultiSessionInfo; +#endif // Attempt to get the universal hash, if it's an audio disc if (this.System.IsAudio()) { string universalHash = GetUniversalHash($"{basePath}_disc.txt") ?? string.Empty; +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.UniversalHash] = universalHash; +#else + info.CommonDiscInfo.CommentsSpecialFields![SiteCode.UniversalHash] = universalHash; +#endif } break; @@ -497,11 +518,15 @@ namespace MPF.Core.Modules.DiscImageCreator case MediaType.DVD: case MediaType.HDDVD: case MediaType.BluRay: + // Get the individual hash data, as per internal - if (info.SizeAndChecksums == null) info.SizeAndChecksums = new SizeAndChecksumsSection(); if (GetISOHashValues(datafile, out long size, out var crc32, out var md5, out var sha1)) { +#if NET48 info.SizeAndChecksums.Size = size; +#else + info.SizeAndChecksums!.Size = size; +#endif info.SizeAndChecksums.CRC32 = crc32; info.SizeAndChecksums.MD5 = md5; info.SizeAndChecksums.SHA1 = sha1; @@ -511,12 +536,20 @@ namespace MPF.Core.Modules.DiscImageCreator if (this.Type == MediaType.DVD) { string layerbreak = GetLayerbreak($"{basePath}_disc.txt", System.IsXGD()) ?? string.Empty; +#if NET48 info.SizeAndChecksums.Layerbreak = !string.IsNullOrEmpty(layerbreak) ? Int64.Parse(layerbreak) : default; +#else + info.SizeAndChecksums!.Layerbreak = !string.IsNullOrEmpty(layerbreak) ? Int64.Parse(layerbreak) : default; +#endif } else if (this.Type == MediaType.BluRay) { var di = GetDiscInformation($"{basePath}_PIC.bin"); +#if NET48 info.SizeAndChecksums.PICIdentifier = GetPICIdentifier(di); +#else + info.SizeAndChecksums!.PICIdentifier = GetPICIdentifier(di); +#endif if (GetLayerbreaks(di, out long? layerbreak1, out long? layerbreak2, out long? layerbreak3)) { if (layerbreak1 != null && layerbreak1 * 2048 < info.SizeAndChecksums.Size) @@ -531,9 +564,12 @@ namespace MPF.Core.Modules.DiscImageCreator } // Read the PVD - if (info.Extras == null) info.Extras = new ExtrasSection(); if (!options.EnableRedumpCompatibility || System != RedumpSystem.MicrosoftXbox) +#if NET48 info.Extras.PVD = GetPVD($"{basePath}_mainInfo.txt") ?? string.Empty; +#else + info.Extras!.PVD = GetPVD($"{basePath}_mainInfo.txt") ?? string.Empty; +#endif // Bluray-specific options if (this.Type == MediaType.BluRay) @@ -548,7 +584,11 @@ namespace MPF.Core.Modules.DiscImageCreator break; } +#if NET48 info.Extras.PIC = GetPIC($"{basePath}_PIC.bin", trimLength) ?? string.Empty; +#else + info.Extras!.PIC = GetPIC($"{basePath}_PIC.bin", trimLength) ?? string.Empty; +#endif } break; @@ -564,48 +604,47 @@ namespace MPF.Core.Modules.DiscImageCreator case RedumpSystem.SonyElectronicBook: if (File.Exists($"{basePath}_subIntention.txt")) { - FileInfo fi = new FileInfo($"{basePath}_subIntention.txt"); + var fi = new FileInfo($"{basePath}_subIntention.txt"); if (fi.Length > 0) - { - if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection(); +#if NET48 info.CopyProtection.SecuROMData = GetFullFile($"{basePath}_subIntention.txt") ?? string.Empty; - } +#else + info.CopyProtection!.SecuROMData = GetFullFile($"{basePath}_subIntention.txt") ?? string.Empty; +#endif } break; case RedumpSystem.DVDAudio: case RedumpSystem.DVDVideo: - if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection(); +#if NET48 info.CopyProtection.Protection = GetDVDProtection($"{basePath}_CSSKey.txt", $"{basePath}_disc.txt") ?? string.Empty; +#else + info.CopyProtection!.Protection = GetDVDProtection($"{basePath}_CSSKey.txt", $"{basePath}_disc.txt") ?? string.Empty; +#endif break; case RedumpSystem.KonamiPython2: if (GetPlayStationExecutableInfo(drive?.Letter, out var pythonTwoSerial, out Region? pythonTwoRegion, out var pythonTwoDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = pythonTwoSerial ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = pythonTwoSerial ?? string.Empty; +#endif info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? pythonTwoRegion; info.CommonDiscInfo.EXEDateBuildDate = pythonTwoDate; } - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); +#if NET48 info.VersionAndEditions.Version = GetPlayStation2Version(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation2Version(drive?.Letter) ?? string.Empty; +#endif break; case RedumpSystem.MicrosoftXbox: - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); -#if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif string xgd1XMID; if (string.IsNullOrWhiteSpace(outputDirectory)) @@ -613,21 +652,22 @@ namespace MPF.Core.Modules.DiscImageCreator else xgd1XMID = GetXGD1XMID(Path.Combine(outputDirectory, $"{basePath}_DMI.bin")); - XgdInfo xgd1Info = new XgdInfo(xgd1XMID); + var xgd1Info = new XgdInfo(xgd1XMID); if (xgd1Info?.Initialized == true) { #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.XMID] = xgd1Info.RawXMID ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.XMID] = xgd1Info.RawXMID ?? string.Empty; +#endif info.CommonDiscInfo.Serial = xgd1Info.GetSerial() ?? string.Empty; if (!options.EnableRedumpCompatibility) - { - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); +#if NET48 info.VersionAndEditions.Version = xgd1Info.GetVersion() ?? string.Empty; - } +#else + info.VersionAndEditions!.Version = xgd1Info.GetVersion() ?? string.Empty; +#endif + info.CommonDiscInfo.Region = XgdInfo.GetRegion(xgd1Info.XMID?.RegionIdentifier); } @@ -637,58 +677,71 @@ namespace MPF.Core.Modules.DiscImageCreator var suppl = GetDatafile($"{basePath}_suppl.dat"); if (GetXGDAuxHashInfo(suppl, out var xgd1DMIHash, out var xgd1PFIHash, out var xgd1SSHash)) { - +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.DMIHash] = xgd1DMIHash ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.DMIHash] = xgd1DMIHash ?? string.Empty; +#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.PFIHash] = xgd1PFIHash ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd1SSHash ?? string.Empty; } if (GetXGDAuxSSInfo($"{basePath}_disc.txt", out var xgd1SS, out var xgd1SSVer)) { +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSVersion] = xgd1SSVer ?? string.Empty; - if (info.Extras == null) info.Extras = new ExtrasSection(); info.Extras.SecuritySectorRanges = xgd1SS ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.SSVersion] = xgd1SSVer ?? string.Empty; + info.Extras!.SecuritySectorRanges = xgd1SS ?? string.Empty; +#endif } } else { if (GetXGDAuxInfo($"{basePath}_disc.txt", out var xgd1DMIHash, out var xgd1PFIHash, out var xgd1SSHash, out var xgd1SS, out var xgd1SSVer)) { +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.DMIHash] = xgd1DMIHash ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.DMIHash] = xgd1DMIHash ?? string.Empty; +#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.PFIHash] = xgd1PFIHash ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd1SSHash ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSVersion] = xgd1SSVer ?? string.Empty; - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.SecuritySectorRanges = xgd1SS ?? string.Empty; +#else + info.Extras!.SecuritySectorRanges = xgd1SS ?? string.Empty; +#endif } } break; case RedumpSystem.MicrosoftXbox360: - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); -#if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif - string xgd23XeMID; if (string.IsNullOrWhiteSpace(outputDirectory)) xgd23XeMID = GetXGD23XeMID($"{basePath}_DMI.bin"); else xgd23XeMID = GetXGD23XeMID(Path.Combine(outputDirectory, $"{basePath}_DMI.bin")); - XgdInfo xgd23Info = new XgdInfo(xgd23XeMID); + var xgd23Info = new XgdInfo(xgd23XeMID); if (xgd23Info?.Initialized == true) { +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.XeMID] = xgd23Info.RawXMID ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.XeMID] = xgd23Info.RawXMID ?? string.Empty; +#endif info.CommonDiscInfo.Serial = xgd23Info.GetSerial() ?? string.Empty; if (!options.EnableRedumpCompatibility) - { - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); +#if NET48 info.VersionAndEditions.Version = xgd23Info.GetVersion() ?? string.Empty; - } +#else + info.VersionAndEditions!.Version = xgd23Info.GetVersion() ?? string.Empty; +#endif + info.CommonDiscInfo.Region = XgdInfo.GetRegion(xgd23Info.XeMID?.RegionIdentifier); } @@ -698,28 +751,43 @@ namespace MPF.Core.Modules.DiscImageCreator var suppl = GetDatafile($"{basePath}_suppl.dat"); if (GetXGDAuxHashInfo(suppl, out var xgd23DMIHash, out var xgd23PFIHash, out var xgd23SSHash)) { +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.DMIHash] = xgd23DMIHash ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.DMIHash] = xgd23DMIHash ?? string.Empty; +#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.PFIHash] = xgd23PFIHash ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd23SSHash ?? string.Empty; } if (GetXGDAuxSSInfo($"{basePath}_disc.txt", out var xgd23SS, out var xgd23SSVer)) { +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSVersion] = xgd23SSVer ?? string.Empty; - if (info.Extras == null) info.Extras = new ExtrasSection(); info.Extras.SecuritySectorRanges = xgd23SS ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.SSVersion] = xgd23SSVer ?? string.Empty; + info.Extras!.SecuritySectorRanges = xgd23SS ?? string.Empty; +#endif } } else { if (GetXGDAuxInfo($"{basePath}_disc.txt", out var xgd23DMIHash, out var xgd23PFIHash, out var xgd23SSHash, out var xgd23SS, out var xgd23SSVer)) { +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.DMIHash] = xgd23DMIHash ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.DMIHash] = xgd23DMIHash ?? string.Empty; +#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.PFIHash] = xgd23PFIHash ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd23SSHash ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSVersion] = xgd23SSVer ?? string.Empty; - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.SecuritySectorRanges = xgd23SS ?? string.Empty; +#else + info.Extras!.SecuritySectorRanges = xgd23SS ?? string.Empty; +#endif } } @@ -728,8 +796,11 @@ namespace MPF.Core.Modules.DiscImageCreator case RedumpSystem.NamcoSegaNintendoTriforce: if (this.Type == MediaType.CDROM) { - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.Header = GetSegaHeader($"{basePath}_mainInfo.txt") ?? string.Empty; +#else + info.Extras!.Header = GetSegaHeader($"{basePath}_mainInfo.txt") ?? string.Empty; +#endif // Take only the first 16 lines for GD-ROM if (!string.IsNullOrEmpty(info.Extras.Header)) @@ -738,15 +809,13 @@ namespace MPF.Core.Modules.DiscImageCreator if (GetGDROMBuildInfo(info.Extras.Header, out var gdSerial, out var gdVersion, out var gdDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = gdSerial ?? string.Empty; - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); info.VersionAndEditions.Version = gdVersion ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = gdSerial ?? string.Empty; + info.VersionAndEditions!.Version = gdVersion ?? string.Empty; +#endif info.CommonDiscInfo.EXEDateBuildDate = gdDate ?? string.Empty; } } @@ -754,8 +823,11 @@ namespace MPF.Core.Modules.DiscImageCreator break; case RedumpSystem.SegaMegaCDSegaCD: - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.Header = GetSegaHeader($"{basePath}_mainInfo.txt") ?? string.Empty; +#else + info.Extras!.Header = GetSegaHeader($"{basePath}_mainInfo.txt") ?? string.Empty; +#endif // Take only the last 16 lines for Sega CD if (!string.IsNullOrEmpty(info.Extras.Header)) @@ -764,13 +836,11 @@ namespace MPF.Core.Modules.DiscImageCreator if (GetSegaCDBuildInfo(info.Extras.Header, out var scdSerial, out var fixedDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = scdSerial ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = scdSerial ?? string.Empty; +#endif info.CommonDiscInfo.EXEDateBuildDate = fixedDate ?? string.Empty; } @@ -779,8 +849,11 @@ namespace MPF.Core.Modules.DiscImageCreator case RedumpSystem.SegaChihiro: if (this.Type == MediaType.CDROM) { - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.Header = GetSegaHeader($"{basePath}_mainInfo.txt") ?? string.Empty; +#else + info.Extras!.Header = GetSegaHeader($"{basePath}_mainInfo.txt") ?? string.Empty; +#endif // Take only the first 16 lines for GD-ROM if (!string.IsNullOrEmpty(info.Extras.Header)) @@ -789,15 +862,13 @@ namespace MPF.Core.Modules.DiscImageCreator if (GetGDROMBuildInfo(info.Extras.Header, out var gdSerial, out var gdVersion, out var gdDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = gdSerial ?? string.Empty; - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); info.VersionAndEditions.Version = gdVersion ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = gdSerial ?? string.Empty; + info.VersionAndEditions!.Version = gdVersion ?? string.Empty; +#endif info.CommonDiscInfo.EXEDateBuildDate = gdDate ?? string.Empty; } } @@ -807,8 +878,11 @@ namespace MPF.Core.Modules.DiscImageCreator case RedumpSystem.SegaDreamcast: if (this.Type == MediaType.CDROM) { - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.Header = GetSegaHeader($"{basePath}_mainInfo.txt") ?? string.Empty; +#else + info.Extras!.Header = GetSegaHeader($"{basePath}_mainInfo.txt") ?? string.Empty; +#endif // Take only the first 16 lines for GD-ROM if (!string.IsNullOrEmpty(info.Extras.Header)) @@ -817,15 +891,13 @@ namespace MPF.Core.Modules.DiscImageCreator if (GetGDROMBuildInfo(info.Extras.Header, out var gdSerial, out var gdVersion, out var gdDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = gdSerial ?? string.Empty; - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); info.VersionAndEditions.Version = gdVersion ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = gdSerial ?? string.Empty; + info.VersionAndEditions!.Version = gdVersion ?? string.Empty; +#endif info.CommonDiscInfo.EXEDateBuildDate = gdDate ?? string.Empty; } } @@ -835,8 +907,11 @@ namespace MPF.Core.Modules.DiscImageCreator case RedumpSystem.SegaNaomi: if (this.Type == MediaType.CDROM) { - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.Header = GetSegaHeader($"{basePath}_mainInfo.txt") ?? string.Empty; +#else + info.Extras!.Header = GetSegaHeader($"{basePath}_mainInfo.txt") ?? string.Empty; +#endif // Take only the first 16 lines for GD-ROM if (!string.IsNullOrEmpty(info.Extras.Header)) @@ -845,15 +920,13 @@ namespace MPF.Core.Modules.DiscImageCreator if (GetGDROMBuildInfo(info.Extras.Header, out var gdSerial, out var gdVersion, out var gdDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = gdSerial ?? string.Empty; - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); info.VersionAndEditions.Version = gdVersion ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = gdSerial ?? string.Empty; + info.VersionAndEditions!.Version = gdVersion ?? string.Empty; +#endif info.CommonDiscInfo.EXEDateBuildDate = gdDate ?? string.Empty; } } @@ -863,8 +936,11 @@ namespace MPF.Core.Modules.DiscImageCreator case RedumpSystem.SegaNaomi2: if (this.Type == MediaType.CDROM) { - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.Header = GetSegaHeader($"{basePath}_mainInfo.txt") ?? string.Empty; +#else + info.Extras!.Header = GetSegaHeader($"{basePath}_mainInfo.txt") ?? string.Empty; +#endif // Take only the first 16 lines for GD-ROM if (!string.IsNullOrEmpty(info.Extras.Header)) @@ -873,15 +949,13 @@ namespace MPF.Core.Modules.DiscImageCreator if (GetGDROMBuildInfo(info.Extras.Header, out var gdSerial, out var gdVersion, out var gdDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = gdSerial ?? string.Empty; - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); info.VersionAndEditions.Version = gdVersion ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = gdSerial ?? string.Empty; + info.VersionAndEditions!.Version = gdVersion ?? string.Empty; +#endif info.CommonDiscInfo.EXEDateBuildDate = gdDate ?? string.Empty; } } @@ -889,8 +963,11 @@ namespace MPF.Core.Modules.DiscImageCreator break; case RedumpSystem.SegaSaturn: - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.Header = GetSegaHeader($"{basePath}_mainInfo.txt") ?? string.Empty; +#else + info.Extras!.Header = GetSegaHeader($"{basePath}_mainInfo.txt") ?? string.Empty; +#endif // Take only the first 16 lines for Saturn if (!string.IsNullOrEmpty(info.Extras.Header)) @@ -899,15 +976,13 @@ namespace MPF.Core.Modules.DiscImageCreator if (GetSaturnBuildInfo(info.Extras.Header, out var saturnSerial, out var saturnVersion, out var buildDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = saturnSerial ?? string.Empty; - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); info.VersionAndEditions.Version = saturnVersion ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = saturnSerial ?? string.Empty; + info.VersionAndEditions!.Version = saturnVersion ?? string.Empty; +#endif info.CommonDiscInfo.EXEDateBuildDate = buildDate ?? string.Empty; } @@ -917,13 +992,11 @@ namespace MPF.Core.Modules.DiscImageCreator if (GetPlayStationExecutableInfo(drive?.Letter, out var playstationSerial, out Region? playstationRegion, out var playstationDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = playstationSerial ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = playstationSerial ?? string.Empty; +#endif info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? playstationRegion; info.CommonDiscInfo.EXEDateBuildDate = playstationDate; } @@ -934,72 +1007,74 @@ namespace MPF.Core.Modules.DiscImageCreator else if (File.Exists($"{basePath}.img_EccEdc.txt")) psEdcStatus = GetPlayStationEDCStatus($"{basePath}.img_EccEdc.txt"); - if (info.EDC == null) info.EDC = new EDCSection(); +#if NET48 info.EDC.EDC = psEdcStatus.ToYesNo(); - if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection(); info.CopyProtection.AntiModchip = GetPlayStationAntiModchipDetected($"{basePath}_disc.txt").ToYesNo(); +#else + info.EDC!.EDC = psEdcStatus.ToYesNo(); + info.CopyProtection!.AntiModchip = GetPlayStationAntiModchipDetected($"{basePath}_disc.txt").ToYesNo(); +#endif break; case RedumpSystem.SonyPlayStation2: if (GetPlayStationExecutableInfo(drive?.Letter, out var playstationTwoSerial, out Region? playstationTwoRegion, out var playstationTwoDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = playstationTwoSerial ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = playstationTwoSerial ?? string.Empty; +#endif info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? playstationTwoRegion; info.CommonDiscInfo.EXEDateBuildDate = playstationTwoDate; } - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); +#if NET48 info.VersionAndEditions.Version = GetPlayStation2Version(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation2Version(drive?.Letter) ?? string.Empty; +#endif break; case RedumpSystem.SonyPlayStation3: - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); - info.VersionAndEditions.Version = GetPlayStation3Version(drive?.Letter) ?? string.Empty; - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif + info.VersionAndEditions.Version = GetPlayStation3Version(drive?.Letter) ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = GetPlayStation3Serial(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation3Version(drive?.Letter) ?? string.Empty; + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = GetPlayStation3Serial(drive?.Letter) ?? string.Empty; +#endif break; case RedumpSystem.SonyPlayStation4: - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); - info.VersionAndEditions.Version = GetPlayStation4Version(drive?.Letter) ?? string.Empty; - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif + info.VersionAndEditions.Version = GetPlayStation4Version(drive?.Letter) ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = GetPlayStation4Serial(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation4Version(drive?.Letter) ?? string.Empty; + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = GetPlayStation4Serial(drive?.Letter) ?? string.Empty; +#endif break; case RedumpSystem.SonyPlayStation5: - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); - info.VersionAndEditions.Version = GetPlayStation5Version(drive?.Letter) ?? string.Empty; - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif + info.VersionAndEditions.Version = GetPlayStation5Version(drive?.Letter) ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = GetPlayStation5Serial(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation5Version(drive?.Letter) ?? string.Empty; + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = GetPlayStation5Serial(drive?.Letter) ?? string.Empty; +#endif break; } // Fill in any artifacts that exist, Base64-encoded, if we need to if (includeArtifacts) { +#if NET48 if (info.Artifacts == null) info.Artifacts = new Dictionary(); +#else + info.Artifacts ??= new Dictionary(); +#endif //if (File.Exists($"{basePath}.c2")) // info.Artifacts["c2"] = Convert.ToBase64String(File.ReadAllBytes($"{basePath}.c2")) ?? string.Empty; @@ -1061,10 +1136,14 @@ namespace MPF.Core.Modules.DiscImageCreator public override string? GenerateParameters() #endif { - List parameters = new List(); + var parameters = new List(); +#if NET48 if (BaseCommand == null) BaseCommand = CommandStrings.NONE; +#else + BaseCommand ??= CommandStrings.NONE; +#endif if (!string.IsNullOrWhiteSpace(BaseCommand)) parameters.Add(BaseCommand); @@ -1195,7 +1274,7 @@ namespace MPF.Core.Modules.DiscImageCreator // BE Opcode if (IsFlagSupported(FlagStrings.BEOpcode)) { - if (this[FlagStrings.BEOpcode] == true && this[FlagStrings.D8Opcode]== false) + if (this[FlagStrings.BEOpcode] == true && this[FlagStrings.D8Opcode] == false) { parameters.Add(FlagStrings.BEOpcode); if (BEOpcodeValue != null @@ -1785,7 +1864,7 @@ namespace MPF.Core.Modules.DiscImageCreator { (var cmdPath, _) = GetCommandFilePathAndVersion(basePath); - List logFiles = new List(); + var logFiles = new List(); switch (this.Type) { case MediaType.CDROM: @@ -2743,7 +2822,7 @@ namespace MPF.Core.Modules.DiscImageCreator // Generate the matching regex based on the base path string basePathFileName = Path.GetFileName(basePath); - Regex cmdFilenameRegex = new Regex(Regex.Escape(basePathFileName) + @"_(\d{8})T\d{6}\.txt"); + var cmdFilenameRegex = new Regex(Regex.Escape(basePathFileName) + @"_(\d{8})T\d{6}\.txt"); // Find the first match for the command file var parentDirectory = Path.GetDirectoryName(basePath); @@ -2845,7 +2924,7 @@ namespace MPF.Core.Modules.DiscImageCreator if (!File.Exists(drive)) return false; - using (StreamReader sr = File.OpenText(drive)) + using (var sr = File.OpenText(drive)) { try { @@ -2862,25 +2941,41 @@ namespace MPF.Core.Modules.DiscImageCreator if (line.StartsWith("DiscType:")) { // DiscType: +#if NET48 string identifier = line.Substring("DiscType: ".Length); +#else + string identifier = line["DiscType: ".Length..]; +#endif discTypeOrBookTypeSet.Add(identifier); } else if (line.StartsWith("DiscTypeIdentifier:")) { // DiscTypeIdentifier: +#if NET48 string identifier = line.Substring("DiscTypeIdentifier: ".Length); +#else + string identifier = line["DiscTypeIdentifier: ".Length..]; +#endif discTypeOrBookTypeSet.Add(identifier); } else if (line.StartsWith("DiscTypeSpecific:")) { // DiscTypeSpecific: +#if NET48 string identifier = line.Substring("DiscTypeSpecific: ".Length); +#else + string identifier = line["DiscTypeSpecific: ".Length..]; +#endif discTypeOrBookTypeSet.Add(identifier); } else if (line.StartsWith("BookType:")) { // BookType: +#if NET48 string identifier = line.Substring("BookType: ".Length); +#else + string identifier = line["BookType: ".Length..]; +#endif discTypeOrBookTypeSet.Add(identifier); } @@ -2926,24 +3021,31 @@ namespace MPF.Core.Modules.DiscImageCreator #endif // Get everything from _disc.txt first - using (StreamReader sr = File.OpenText(disc)) + using (var sr = File.OpenText(disc)) { try { // Fast forward to the copyright information - while (sr.ReadLine()?.Trim()?.StartsWith("========== CopyrightInformation ==========")== false) ; + while (sr.ReadLine()?.Trim()?.StartsWith("========== CopyrightInformation ==========") == false) ; // Now read until we hit the manufacturing information var line = sr.ReadLine()?.Trim(); - while (line?.StartsWith("========== ManufacturingInformation ==========")== false) + while (line?.StartsWith("========== ManufacturingInformation ==========") == false) { if (line == null) break; +#if NET48 if (line.StartsWith("CopyrightProtectionType")) copyrightProtectionSystemType = line.Substring("CopyrightProtectionType: ".Length); else if (line.StartsWith("RegionManagementInformation")) region = line.Substring("RegionManagementInformation: ".Length); +#else + if (line.StartsWith("CopyrightProtectionType")) + copyrightProtectionSystemType = line["CopyrightProtectionType: ".Length..]; + else if (line.StartsWith("RegionManagementInformation")) + region = line["RegionManagementInformation: ".Length..]; +#endif line = sr.ReadLine()?.Trim(); } @@ -2954,7 +3056,7 @@ namespace MPF.Core.Modules.DiscImageCreator // Get everything from _CSSKey.txt next, if it exists if (File.Exists(cssKey)) { - using (StreamReader sr = File.OpenText(cssKey)) + using (var sr = File.OpenText(cssKey)) { try { @@ -2967,13 +3069,21 @@ namespace MPF.Core.Modules.DiscImageCreator if (line.StartsWith("DecryptedDiscKey")) { +#if NET48 decryptedDiscKey = line.Substring("DecryptedDiscKey[020]: ".Length); +#else + decryptedDiscKey = line["DecryptedDiscKey[020]: ".Length..]; +#endif } else if (line.StartsWith("LBA:")) { // Set the key string if necessary +#if NET48 if (vobKeys == null) vobKeys = string.Empty; +#else + vobKeys ??= string.Empty; +#endif // No keys if (line.Contains("No TitleKey")) @@ -2981,7 +3091,11 @@ namespace MPF.Core.Modules.DiscImageCreator var match = Regex.Match(line, @"^LBA:\s*[0-9]+, Filename: (.*?), No TitleKey$"); string matchedFilename = match.Groups[1].Value; if (matchedFilename.EndsWith(";1")) +#if NET48 matchedFilename = matchedFilename.Substring(0, matchedFilename.Length - 2); +#else + matchedFilename = matchedFilename[..^2]; +#endif vobKeys += $"{matchedFilename} Title Key: No Title Key\n"; } @@ -2990,7 +3104,11 @@ namespace MPF.Core.Modules.DiscImageCreator var match = Regex.Match(line, @"^LBA:\s*[0-9]+, Filename: (.*?), EncryptedTitleKey: .*?, DecryptedTitleKey: (.*?)$"); string matchedFilename = match.Groups[1].Value; if (matchedFilename.EndsWith(";1")) +#if NET48 matchedFilename = matchedFilename.Substring(0, matchedFilename.Length - 2); +#else + matchedFilename = matchedFilename[..^2]; +#endif vobKeys += $"{matchedFilename} Title Key: {match.Groups[2].Value}\n"; } @@ -3034,7 +3152,7 @@ namespace MPF.Core.Modules.DiscImageCreator long? totalErrors = null; // First line of defense is the EdcEcc error file - using (StreamReader sr = File.OpenText(edcecc)) + using (var sr = File.OpenText(edcecc)) { try { @@ -3052,18 +3170,34 @@ namespace MPF.Core.Modules.DiscImageCreator } else if (line.StartsWith("Total errors")) { +#if NET48 if (totalErrors == null) totalErrors = 0; +#else + totalErrors ??= 0; +#endif +#if NET48 if (Int64.TryParse(line.Substring("Total errors: ".Length).Trim(), out long te)) +#else + if (Int64.TryParse(line["Total errors: ".Length..].Trim(), out long te)) +#endif totalErrors += te; } else if (line.StartsWith("Total warnings")) { +#if NET48 if (totalErrors == null) totalErrors = 0; +#else + totalErrors ??= 0; +#endif +#if NET48 if (Int64.TryParse(line.Substring("Total warnings: ".Length).Trim(), out long tw)) +#else + if (Int64.TryParse(line["Total warnings: ".Length..].Trim(), out long tw)) +#endif totalErrors += tw; } } @@ -3100,11 +3234,19 @@ namespace MPF.Core.Modules.DiscImageCreator try { string[] header = segaHeader.Split('\n'); +#if NET48 string versionLine = header[4].Substring(58); string dateLine = header[5].Substring(58); serial = versionLine.Substring(0, 10).TrimEnd(); version = versionLine.Substring(10, 6).TrimStart('V', 'v'); date = dateLine.Substring(0, 8); +#else + string versionLine = header[4][58..]; + string dateLine = header[5][58..]; + serial = versionLine[..10].TrimEnd(); + version = versionLine.Substring(10, 6).TrimStart('V', 'v'); + date = dateLine[..8]; +#endif return true; } catch @@ -3132,7 +3274,7 @@ namespace MPF.Core.Modules.DiscImageCreator if (!File.Exists(drive)) return false; - using (StreamReader sr = File.OpenText(drive)) + using (var sr = File.OpenText(drive)) { try { @@ -3146,17 +3288,29 @@ namespace MPF.Core.Modules.DiscImageCreator if (string.IsNullOrEmpty(manufacturer) && line.StartsWith("VendorId")) { // VendorId: +#if NET48 manufacturer = line.Substring("VendorId: ".Length); +#else + manufacturer = line["VendorId: ".Length..]; +#endif } else if (string.IsNullOrEmpty(model) && line.StartsWith("ProductId")) { // ProductId: +#if NET48 model = line.Substring("ProductId: ".Length); +#else + model = line["ProductId: ".Length..]; +#endif } else if (string.IsNullOrEmpty(firmware) && line.StartsWith("ProductRevisionLevel")) { // ProductRevisionLevel: +#if NET48 firmware = line.Substring("ProductRevisionLevel: ".Length); +#else + firmware = line["ProductRevisionLevel: ".Length..]; +#endif } line = sr.ReadLine(); @@ -3188,7 +3342,7 @@ namespace MPF.Core.Modules.DiscImageCreator if (!File.Exists(disc)) return null; - using (StreamReader sr = File.OpenText(disc)) + using (var sr = File.OpenText(disc)) { try { @@ -3249,7 +3403,7 @@ namespace MPF.Core.Modules.DiscImageCreator if (!File.Exists(disc)) return null; - using (StreamReader sr = File.OpenText(disc)) + using (var sr = File.OpenText(disc)) { try { @@ -3259,12 +3413,12 @@ namespace MPF.Core.Modules.DiscImageCreator return null; if (!line.StartsWith("========== TOC")) - while ((line = sr.ReadLine())?.StartsWith("========== TOC")== false) ; + while ((line = sr.ReadLine())?.StartsWith("========== TOC") == false) ; if (line == null) return null; // Create the required regex - Regex trackLengthRegex = new Regex(@"^\s*.*?Track\s*([0-9]{1,2}), LBA\s*[0-9]{1,8} - \s*[0-9]{1,8}, Length\s*([0-9]{1,8})$"); + var trackLengthRegex = new Regex(@"^\s*.*?Track\s*([0-9]{1,2}), LBA\s*[0-9]{1,8} - \s*[0-9]{1,8}, Length\s*([0-9]{1,8})$"); // Read in the track length data var trackLengthMapping = new Dictionary(); @@ -3283,16 +3437,16 @@ namespace MPF.Core.Modules.DiscImageCreator return null; if (!line.StartsWith("========== FULL TOC")) - while ((line = sr.ReadLine())?.StartsWith("========== FULL TOC")== false) ; + while ((line = sr.ReadLine())?.StartsWith("========== FULL TOC") == false) ; if (line == null) return null; // Create the required regex - Regex trackSessionRegex = new Regex(@"^\s*Session\s*([0-9]{1,2}),.*?,\s*Track\s*([0-9]{1,2}).*?$"); + var trackSessionRegex = new Regex(@"^\s*Session\s*([0-9]{1,2}),.*?,\s*Track\s*([0-9]{1,2}).*?$"); // Read in the track session data var trackSessionMapping = new Dictionary(); - while ((line = sr.ReadLine())?.StartsWith("========== OpCode")== false) + while ((line = sr.ReadLine())?.StartsWith("========== OpCode") == false) { if (line == null) return null; @@ -3314,12 +3468,16 @@ namespace MPF.Core.Modules.DiscImageCreator return null; if (!line.StartsWith("Lead-out length")) - while ((line = sr.ReadLine()?.Trim())?.StartsWith("Lead-out length")== false) ; + while ((line = sr.ReadLine()?.Trim())?.StartsWith("Lead-out length") == false) ; // TODO: Are there any examples of 3+ session discs? // Read the first session lead-out +#if NET48 var firstSessionLeadOutLengthString = line?.Substring("Lead-out length of 1st session: ".Length); +#else + var firstSessionLeadOutLengthString = line?["Lead-out length of 1st session: ".Length..]; +#endif line = sr.ReadLine()?.Trim(); if (line == null) return null; @@ -3330,14 +3488,22 @@ namespace MPF.Core.Modules.DiscImageCreator #else string? secondSessionLeadInLengthString = null; #endif - while (line?.StartsWith("Lead-in length")== false) + while (line?.StartsWith("Lead-in length") == false) { +#if NET48 secondSessionLeadInLengthString = line?.Substring("Lead-in length of 2nd session: ".Length); +#else + secondSessionLeadInLengthString = line?["Lead-in length of 2nd session: ".Length..]; +#endif line = sr.ReadLine()?.Trim(); } // Read the second session pregap +#if NET48 var secondSessionPregapLengthString = line?.Substring("Pregap length of 1st track of 2nd session: ".Length); +#else + var secondSessionPregapLengthString = line?["Pregap length of 1st track of 2nd session: ".Length..]; +#endif // Calculate the session gap total if (!int.TryParse(firstSessionLeadOutLengthString, out int firstSessionLeadOutLength)) @@ -3404,7 +3570,11 @@ namespace MPF.Core.Modules.DiscImageCreator return null; if (trimLength > -1) +#if NET48 hex = hex.Substring(0, trimLength); +#else + hex = hex[..trimLength]; +#endif return Regex.Replace(hex, ".{32}", "$0\n"); } @@ -3426,7 +3596,7 @@ namespace MPF.Core.Modules.DiscImageCreator if (!File.Exists(disc)) return null; - using (StreamReader sr = File.OpenText(disc)) + using (var sr = File.OpenText(disc)) { try { @@ -3472,7 +3642,7 @@ namespace MPF.Core.Modules.DiscImageCreator // First line of defense is the EdcEcc error file int modeTwoNoEdc = 0; int modeTwoFormTwo = 0; - using (StreamReader sr = File.OpenText(edcecc)) + using (var sr = File.OpenText(edcecc)) { try { @@ -3530,7 +3700,7 @@ namespace MPF.Core.Modules.DiscImageCreator if (!File.Exists(mainInfo)) return null; - using (StreamReader sr = File.OpenText(mainInfo)) + using (var sr = File.OpenText(mainInfo)) { try { @@ -3544,7 +3714,7 @@ namespace MPF.Core.Modules.DiscImageCreator || line.StartsWith("========== FULL TOC (Binary)")) { // Seek to unscrambled data - while ((line = sr.ReadLine())?.StartsWith("========== Check Volume Descriptor ==========")== false) ; + while ((line = sr.ReadLine())?.StartsWith("========== Check Volume Descriptor ==========") == false) ; // Read the next line so the search goes properly line = sr.ReadLine(); @@ -3555,25 +3725,25 @@ namespace MPF.Core.Modules.DiscImageCreator // Make sure we're in the area if (line.StartsWith("========== LBA") == true) - while ((line = sr.ReadLine())?.StartsWith("========== LBA")== false) ; + while ((line = sr.ReadLine())?.StartsWith("========== LBA") == false) ; if (line == null) return null; // If we have a Sega disc, skip sector 0 if (line.StartsWith("========== LBA[000000, 0000000]: Main Channel ==========")) - while ((line = sr.ReadLine())?.StartsWith("========== LBA")== false) ; + while ((line = sr.ReadLine())?.StartsWith("========== LBA") == false) ; if (line == null) return null; // If we have a PlayStation disc, skip sector 4 if (line.StartsWith("========== LBA[000004, 0x00004]: Main Channel ==========")) - while ((line = sr.ReadLine())?.StartsWith("========== LBA")== false) ; + while ((line = sr.ReadLine())?.StartsWith("========== LBA") == false) ; if (line == null) return null; // We assume the first non-LBA0/4 sector listed is the proper one // Fast forward to the PVD - while ((line = sr.ReadLine())?.StartsWith("0310")== false) ; + while ((line = sr.ReadLine())?.StartsWith("0310") == false) ; // Now that we're at the PVD, read each line in and concatenate string pvd = ""; @@ -3611,12 +3781,21 @@ namespace MPF.Core.Modules.DiscImageCreator try { string[] header = segaHeader.Split('\n'); +#if NET48 string serialVersionLine = header[2].Substring(58); string dateLine = header[3].Substring(58); serial = serialVersionLine.Substring(0, 10).Trim(); version = serialVersionLine.Substring(10, 6).TrimStart('V', 'v'); date = dateLine.Substring(0, 8); date = $"{date[0]}{date[1]}{date[2]}{date[3]}-{date[4]}{date[5]}-{date[6]}{date[7]}"; +#else + string serialVersionLine = header[2][58..]; + string dateLine = header[3][58..]; + serial = serialVersionLine[..10].Trim(); + version = serialVersionLine.Substring(10, 6).TrimStart('V', 'v'); + date = dateLine[..8]; + date = $"{date[0]}{date[1]}{date[2]}{date[3]}-{date[4]}{date[5]}-{date[6]}{date[7]}"; +#endif return true; } catch @@ -3648,16 +3827,27 @@ namespace MPF.Core.Modules.DiscImageCreator try { string[] header = segaHeader.Split('\n'); +#if NET48 string serialVersionLine = header[8].Substring(58); string dateLine = header[1].Substring(58); serial = serialVersionLine.Substring(3, 8).TrimEnd('-', ' '); date = dateLine.Substring(8).Trim(); +#else + string serialVersionLine = header[8][58..]; + string dateLine = header[1][58..]; + serial = serialVersionLine.Substring(3, 8).TrimEnd('-', ' '); + date = dateLine[8..].Trim(); +#endif // Properly format the date string, if possible string[] dateSplit = date.Split('.'); if (dateSplit.Length == 1) +#if NET48 dateSplit = new string[] { date.Substring(0, 4), date.Substring(4) }; +#else + dateSplit = new string[] { date[..4], date[4..] }; +#endif string month = dateSplit[1]; switch (month) @@ -3729,7 +3919,7 @@ namespace MPF.Core.Modules.DiscImageCreator if (!File.Exists(mainInfo)) return null; - using (StreamReader sr = File.OpenText(mainInfo)) + using (var sr = File.OpenText(mainInfo)) { try { @@ -3743,7 +3933,7 @@ namespace MPF.Core.Modules.DiscImageCreator || line.StartsWith("========== FULL TOC (Binary)")) { // Seek to unscrambled data - while ((line = sr.ReadLine())?.Contains("Check MCN and/or ISRC")== false) ; + while ((line = sr.ReadLine())?.Contains("Check MCN and/or ISRC") == false) ; if (line == null) return null; @@ -3756,18 +3946,18 @@ namespace MPF.Core.Modules.DiscImageCreator // Make sure we're in the area if (!line.StartsWith("========== LBA")) - while ((line = sr.ReadLine())?.StartsWith("========== LBA")== false) ; + while ((line = sr.ReadLine())?.StartsWith("========== LBA") == false) ; if (line == null) return null; // Make sure we're in the right sector if (!line.StartsWith("========== LBA[000000, 0000000]: Main Channel ==========")) - while ((line = sr.ReadLine())?.StartsWith("========== LBA[000000, 0000000]: Main Channel ==========")== false) ; + while ((line = sr.ReadLine())?.StartsWith("========== LBA[000000, 0000000]: Main Channel ==========") == false) ; if (line == null) return null; // Fast forward to the header - while ((line = sr.ReadLine())?.Trim()?.StartsWith("+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F")== false) ; + while ((line = sr.ReadLine())?.Trim()?.StartsWith("+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F") == false) ; if (line == null) return null; @@ -3801,12 +3991,12 @@ namespace MPF.Core.Modules.DiscImageCreator if (!File.Exists(disc)) return null; - using (StreamReader sr = File.OpenText(disc)) + using (var sr = File.OpenText(disc)) { try { // Fast forward to the universal hash information - while (sr.ReadLine()?.Trim().StartsWith("========== Hash(Universal Whole image) ==========")== false) ; + while (sr.ReadLine()?.Trim().StartsWith("========== Hash(Universal Whole image) ==========") == false) ; // If we find the universal hash line, return the SHA-1 hash only #if NET48 @@ -3853,12 +4043,12 @@ namespace MPF.Core.Modules.DiscImageCreator if (!File.Exists(disc)) return null; - using (StreamReader sr = File.OpenText(disc)) + using (var sr = File.OpenText(disc)) { try { // Fast forward to the offsets - while (sr.ReadLine()?.Trim()?.StartsWith("========== Offset")== false) ; + while (sr.ReadLine()?.Trim()?.StartsWith("========== Offset") == false) ; sr.ReadLine(); // Combined Offset sr.ReadLine(); // Drive Offset sr.ReadLine(); // Separator line @@ -3933,7 +4123,7 @@ namespace MPF.Core.Modules.DiscImageCreator // This flag is needed because recent versions of DIC include security data twice bool foundSecuritySectors = false; - using (StreamReader sr = File.OpenText(disc)) + using (var sr = File.OpenText(disc)) { try { @@ -3955,7 +4145,7 @@ namespace MPF.Core.Modules.DiscImageCreator // Set the flag so we don't read duplicate data foundSecuritySectors = true; - Regex layerRegex = new Regex(@"Layer [01].*, startLBA-endLBA:\s*(\d+)-\s*(\d+)"); + var layerRegex = new Regex(@"Layer [01].*, startLBA-endLBA:\s*(\d+)-\s*(\d+)"); line = sr.ReadLine()?.Trim(); if (line == null) @@ -4027,7 +4217,7 @@ namespace MPF.Core.Modules.DiscImageCreator // This flag is needed because recent versions of DIC include security data twice bool foundSecuritySectors = false; - using (StreamReader sr = File.OpenText(disc)) + using (var sr = File.OpenText(disc)) { try { @@ -4049,7 +4239,7 @@ namespace MPF.Core.Modules.DiscImageCreator // Set the flag so we don't read duplicate data foundSecuritySectors = true; - Regex layerRegex = new Regex(@"Layer [01].*, startLBA-endLBA:\s*(\d+)-\s*(\d+)"); + var layerRegex = new Regex(@"Layer [01].*, startLBA-endLBA:\s*(\d+)-\s*(\d+)"); line = sr.ReadLine()?.Trim(); if (line == null) @@ -4095,7 +4285,7 @@ namespace MPF.Core.Modules.DiscImageCreator if (!File.Exists(dmi)) return string.Empty; - using (BinaryReader br = new BinaryReader(File.OpenRead(dmi))) + using (var br = new BinaryReader(File.OpenRead(dmi))) { try { @@ -4119,7 +4309,7 @@ namespace MPF.Core.Modules.DiscImageCreator if (!File.Exists(dmi)) return string.Empty; - using (BinaryReader br = new BinaryReader(File.OpenRead(dmi))) + using (var br = new BinaryReader(File.OpenRead(dmi))) { try { diff --git a/MPF.Core/Modules/Redumper/Parameters.cs b/MPF.Core/Modules/Redumper/Parameters.cs index 78534739..831c89b6 100644 --- a/MPF.Core/Modules/Redumper/Parameters.cs +++ b/MPF.Core/Modules/Redumper/Parameters.cs @@ -293,9 +293,15 @@ namespace MPF.Core.Modules.Redumper public override void GenerateSubmissionInfo(SubmissionInfo info, Options options, string basePath, Drive? drive, bool includeArtifacts) #endif { + // Ensure that required sections exist + info = InfoTool.EnsureAllSections(info); + // Get the dumping program and version - if (info.DumpingInfo == null) info.DumpingInfo = new DumpingInfoSection(); +#if NET48 info.DumpingInfo.DumpingProgram = $"{EnumConverter.LongName(this.InternalProgram)} {GetVersion($"{basePath}.log") ?? "Unknown Version"}"; +#else + info.DumpingInfo!.DumpingProgram = $"{EnumConverter.LongName(this.InternalProgram)} {GetVersion($"{basePath}.log") ?? "Unknown Version"}"; +#endif info.DumpingInfo.DumpingDate = GetFileModifiedDate($"{basePath}.log")?.ToString("yyyy-MM-dd HH:mm:ss"); // Fill in the hardware data @@ -309,67 +315,89 @@ namespace MPF.Core.Modules.Redumper switch (this.Type) { case MediaType.CDROM: - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.PVD = GetPVD($"{basePath}.log") ?? "Disc has no PVD"; - if (info.TracksAndWriteOffsets == null) info.TracksAndWriteOffsets = new TracksAndWriteOffsetsSection(); info.TracksAndWriteOffsets.ClrMameProData = GetDatfile($"{basePath}.log"); +#else + info.Extras!.PVD = GetPVD($"{basePath}.log") ?? "Disc has no PVD"; + info.TracksAndWriteOffsets!.ClrMameProData = GetDatfile($"{basePath}.log"); +#endif info.TracksAndWriteOffsets.Cuesheet = GetFullFile($"{basePath}.cue") ?? string.Empty; // Attempt to get the write offset string cdWriteOffset = GetWriteOffset($"{basePath}.log") ?? string.Empty; - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); +#if NET48 info.CommonDiscInfo.RingWriteOffset = cdWriteOffset; +#else + info.CommonDiscInfo!.RingWriteOffset = cdWriteOffset; +#endif info.TracksAndWriteOffsets.OtherWriteOffsets = cdWriteOffset; // Attempt to get the error count long errorCount = GetErrorCount($"{basePath}.log"); info.CommonDiscInfo.ErrorsCount = (errorCount == -1 ? "Error retrieving error count" : errorCount.ToString()); -#if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif - // Attempt to get multisession data string cdMultiSessionInfo = GetMultisessionInformation($"{basePath}.log") ?? string.Empty; if (!string.IsNullOrWhiteSpace(cdMultiSessionInfo)) +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.Multisession] = cdMultiSessionInfo; +#else + info.CommonDiscInfo.CommentsSpecialFields![SiteCode.Multisession] = cdMultiSessionInfo; +#endif // Attempt to get the universal hash, if it's an audio disc if (this.System.IsAudio()) { string universalHash = GetUniversalHash($"{basePath}.log") ?? string.Empty; +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.UniversalHash] = universalHash; +#else + info.CommonDiscInfo.CommentsSpecialFields![SiteCode.UniversalHash] = universalHash; +#endif } // Attempt to get the non-zero data start, if it's an audio disc if (this.System.IsAudio()) { string ringNonZeroDataStart = GetRingNonZeroDataStart($"{basePath}.log") ?? string.Empty; +#if NET48 info.CommonDiscInfo.CommentsSpecialFields[SiteCode.RingNonZeroDataStart] = ringNonZeroDataStart; +#else + info.CommonDiscInfo.CommentsSpecialFields![SiteCode.RingNonZeroDataStart] = ringNonZeroDataStart; +#endif } break; case MediaType.DVD: - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.PVD = GetPVD($"{basePath}.log") ?? "Disc has no PVD"; - if (info.TracksAndWriteOffsets == null) info.TracksAndWriteOffsets = new TracksAndWriteOffsetsSection(); info.TracksAndWriteOffsets.ClrMameProData = GetDatfile($"{basePath}.log"); +#else + info.Extras!.PVD = GetPVD($"{basePath}.log") ?? "Disc has no PVD"; + info.TracksAndWriteOffsets!.ClrMameProData = GetDatfile($"{basePath}.log"); +#endif // Get the individual hash data, as per internal - if (info.SizeAndChecksums == null) info.SizeAndChecksums = new SizeAndChecksumsSection(); if (GetISOHashValues(info.TracksAndWriteOffsets.ClrMameProData, out long size, out var crc32, out var md5, out var sha1)) { +#if NET48 info.SizeAndChecksums.Size = size; +#else + info.SizeAndChecksums!.Size = size; +#endif info.SizeAndChecksums.CRC32 = crc32; info.SizeAndChecksums.MD5 = md5; info.SizeAndChecksums.SHA1 = sha1; } string layerbreak = GetLayerbreak($"{basePath}.log") ?? string.Empty; +#if NET48 info.SizeAndChecksums.Layerbreak = !string.IsNullOrEmpty(layerbreak) ? Int64.Parse(layerbreak) : default; +#else + info.SizeAndChecksums!.Layerbreak = !string.IsNullOrEmpty(layerbreak) ? Int64.Parse(layerbreak) : default; +#endif break; } @@ -385,27 +413,31 @@ namespace MPF.Core.Modules.Redumper case RedumpSystem.DVDAudio: case RedumpSystem.DVDVideo: - if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection(); +#if NET48 info.CopyProtection.Protection = GetDVDProtection($"{basePath}.log") ?? string.Empty; +#else + info.CopyProtection!.Protection = GetDVDProtection($"{basePath}.log") ?? string.Empty; +#endif break; case RedumpSystem.KonamiPython2: if (GetPlayStationExecutableInfo(drive?.Letter, out var pythonTwoSerial, out Region? pythonTwoRegion, out var pythonTwoDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = pythonTwoSerial ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = pythonTwoSerial ?? string.Empty; +#endif info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? pythonTwoRegion; info.CommonDiscInfo.EXEDateBuildDate = pythonTwoDate; } - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); +#if NET48 info.VersionAndEditions.Version = GetPlayStation2Version(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation2Version(drive?.Letter) ?? string.Empty; +#endif break; case RedumpSystem.MicrosoftXbox: @@ -421,15 +453,13 @@ namespace MPF.Core.Modules.Redumper break; case RedumpSystem.SegaMegaCDSegaCD: - if (info.Extras == null) info.Extras = new ExtrasSection(); - info.Extras.Header = GetSegaCDHeader($"{basePath}.log", out var scdBuildDate, out var scdSerial, out _) ?? string.Empty; - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif + info.Extras.Header = GetSegaCDHeader($"{basePath}.log", out var scdBuildDate, out var scdSerial, out _) ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = scdSerial ?? string.Empty; +#else + info.Extras!.Header = GetSegaCDHeader($"{basePath}.log", out var scdBuildDate, out var scdSerial, out _) ?? string.Empty; + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = scdSerial ?? string.Empty; +#endif info.CommonDiscInfo.EXEDateBuildDate = scdBuildDate ?? string.Empty; // TODO: Support region setting from parsed value break; @@ -451,8 +481,11 @@ namespace MPF.Core.Modules.Redumper break; case RedumpSystem.SegaSaturn: - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.Header = GetSaturnHeader($"{basePath}.log") ?? string.Empty; +#else + info.Extras!.Header = GetSaturnHeader($"{basePath}.log") ?? string.Empty; +#endif // Take only the first 16 lines for Saturn if (!string.IsNullOrEmpty(info.Extras.Header)) @@ -461,15 +494,13 @@ namespace MPF.Core.Modules.Redumper if (GetSaturnBuildInfo(info.Extras.Header, out var saturnSerial, out var saturnVersion, out var buildDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = saturnSerial ?? string.Empty; - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); info.VersionAndEditions.Version = saturnVersion ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = saturnSerial ?? string.Empty; + info.VersionAndEditions!.Version = saturnVersion ?? string.Empty; +#endif info.CommonDiscInfo.EXEDateBuildDate = buildDate ?? string.Empty; } @@ -479,21 +510,22 @@ namespace MPF.Core.Modules.Redumper if (GetPlayStationExecutableInfo(drive?.Letter, out var playstationSerial, out Region? playstationRegion, out var playstationDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = playstationSerial ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = playstationSerial ?? string.Empty; +#endif info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? playstationRegion; info.CommonDiscInfo.EXEDateBuildDate = playstationDate; } - if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection(); +#if NET48 info.CopyProtection.AntiModchip = GetPlayStationAntiModchipDetected($"{basePath}.log").ToYesNo(); - if (info.EDC == null) info.EDC = new EDCSection(); info.EDC.EDC = GetPlayStationEDCStatus($"{basePath}.log").ToYesNo(); +#else + info.CopyProtection!.AntiModchip = GetPlayStationAntiModchipDetected($"{basePath}.log").ToYesNo(); + info.EDC!.EDC = GetPlayStationEDCStatus($"{basePath}.log").ToYesNo(); +#endif info.CopyProtection.LibCrypt = GetPlayStationLibCryptStatus($"{basePath}.log").ToYesNo(); info.CopyProtection.LibCryptData = GetPlayStationLibCryptData($"{basePath}.log"); break; @@ -502,62 +534,62 @@ namespace MPF.Core.Modules.Redumper if (GetPlayStationExecutableInfo(drive?.Letter, out var playstationTwoSerial, out Region? playstationTwoRegion, out var playstationTwoDate)) { // Ensure internal serial is pulled from local data - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = playstationTwoSerial ?? string.Empty; +#else + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = playstationTwoSerial ?? string.Empty; +#endif info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? playstationTwoRegion; info.CommonDiscInfo.EXEDateBuildDate = playstationTwoDate; } - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); +#if NET48 info.VersionAndEditions.Version = GetPlayStation2Version(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation2Version(drive?.Letter) ?? string.Empty; +#endif break; case RedumpSystem.SonyPlayStation3: - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); - info.VersionAndEditions.Version = GetPlayStation3Version(drive?.Letter) ?? string.Empty; - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif + info.VersionAndEditions.Version = GetPlayStation3Version(drive?.Letter) ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = GetPlayStation3Serial(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation3Version(drive?.Letter) ?? string.Empty; + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = GetPlayStation3Serial(drive?.Letter) ?? string.Empty; +#endif break; case RedumpSystem.SonyPlayStation4: - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); - info.VersionAndEditions.Version = GetPlayStation4Version(drive?.Letter) ?? string.Empty; - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif + info.VersionAndEditions.Version = GetPlayStation4Version(drive?.Letter) ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = GetPlayStation4Serial(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation4Version(drive?.Letter) ?? string.Empty; + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = GetPlayStation4Serial(drive?.Letter) ?? string.Empty; +#endif break; case RedumpSystem.SonyPlayStation5: - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); - info.VersionAndEditions.Version = GetPlayStation5Version(drive?.Letter) ?? string.Empty; - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); #if NET48 - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#else - if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary(); -#endif + info.VersionAndEditions.Version = GetPlayStation5Version(drive?.Letter) ?? string.Empty; info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = GetPlayStation5Serial(drive?.Letter) ?? string.Empty; +#else + info.VersionAndEditions!.Version = GetPlayStation5Version(drive?.Letter) ?? string.Empty; + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = GetPlayStation5Serial(drive?.Letter) ?? string.Empty; +#endif break; } // Fill in any artifacts that exist, Base64-encoded, if we need to if (includeArtifacts) { +#if NET48 if (info.Artifacts == null) info.Artifacts = new Dictionary(); +#else + info.Artifacts ??= new Dictionary(); +#endif + if (File.Exists($"{basePath}.cdtext")) info.Artifacts["cdtext"] = GetBase64(GetFullFile($"{basePath}.cdtext")) ?? string.Empty; if (File.Exists($"{basePath}.cue")) @@ -1330,7 +1362,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return null; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -1376,7 +1408,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return null; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -1428,7 +1460,7 @@ namespace MPF.Core.Modules.Redumper #else string? region = null, rceProtection = null, copyrightProtectionSystemType = null, vobKeys = null, decryptedDiscKey = null; #endif - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -1529,7 +1561,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return -1; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -1580,7 +1612,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return null; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -1659,7 +1691,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return null; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -1725,7 +1757,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return null; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -1765,7 +1797,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return null; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -1809,7 +1841,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return null; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -1851,7 +1883,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return null; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -1895,7 +1927,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return null; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -1941,7 +1973,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return null; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -2033,7 +2065,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return null; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -2093,7 +2125,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return null; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -2185,7 +2217,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return null; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -2232,7 +2264,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return null; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -2283,7 +2315,7 @@ namespace MPF.Core.Modules.Redumper // redumper v2022.10.28 [Oct 28 2022, 05:41:43] (print usage: --help,-h) // redumper v2022.12.22 build_87 [Dec 22 2022, 01:56:26] - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { @@ -2327,7 +2359,7 @@ namespace MPF.Core.Modules.Redumper if (!File.Exists(log)) return false; - using (StreamReader sr = File.OpenText(log)) + using (var sr = File.OpenText(log)) { try { diff --git a/MPF.Core/Modules/UmdImageCreator/Parameters.cs b/MPF.Core/Modules/UmdImageCreator/Parameters.cs index 16fd069a..99e3bd2e 100644 --- a/MPF.Core/Modules/UmdImageCreator/Parameters.cs +++ b/MPF.Core/Modules/UmdImageCreator/Parameters.cs @@ -38,7 +38,7 @@ namespace MPF.Core.Modules.UmdImageCreator /// public override (bool, List) CheckAllOutputFilesExist(string basePath, bool preCheck) { - List missingFiles = new List(); + var missingFiles = new List(); switch (this.Type) { case MediaType.UMD: @@ -71,22 +71,34 @@ namespace MPF.Core.Modules.UmdImageCreator public override void GenerateSubmissionInfo(SubmissionInfo info, Options options, string basePath, Drive? drive, bool includeArtifacts) #endif { + // Ensure that required sections exist + info = InfoTool.EnsureAllSections(info); + // TODO: Determine if there's a UMDImageCreator version anywhere - if (info.DumpingInfo == null) info.DumpingInfo = new DumpingInfoSection(); +#if NET48 info.DumpingInfo.DumpingProgram = EnumConverter.LongName(this.InternalProgram); +#else + info.DumpingInfo!.DumpingProgram = EnumConverter.LongName(this.InternalProgram); +#endif info.DumpingInfo.DumpingDate = GetFileModifiedDate(basePath + "_disc.txt")?.ToString("yyyy-MM-dd HH:mm:ss"); // Extract info based generically on MediaType switch (this.Type) { case MediaType.UMD: - if (info.Extras == null) info.Extras = new ExtrasSection(); +#if NET48 info.Extras.PVD = GetPVD(basePath + "_mainInfo.txt") ?? string.Empty; +#else + info.Extras!.PVD = GetPVD(basePath + "_mainInfo.txt") ?? string.Empty; +#endif if (GetFileHashes(basePath + ".iso", out long filesize, out var crc32, out var md5, out var sha1)) { - if (info.SizeAndChecksums == null) info.SizeAndChecksums = new SizeAndChecksumsSection(); +#if NET48 info.SizeAndChecksums.Size = filesize; +#else + info.SizeAndChecksums!.Size = filesize; +#endif info.SizeAndChecksums.CRC32 = crc32; info.SizeAndChecksums.MD5 = md5; info.SizeAndChecksums.SHA1 = sha1; @@ -94,13 +106,17 @@ namespace MPF.Core.Modules.UmdImageCreator if (GetUMDAuxInfo(basePath + "_disc.txt", out var title, out DiscCategory? umdcat, out var umdversion, out var umdlayer, out long umdsize)) { - if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection(); +#if NET48 info.CommonDiscInfo.Title = title ?? string.Empty; info.CommonDiscInfo.Category = umdcat ?? DiscCategory.Games; - if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection(); info.VersionAndEditions.Version = umdversion ?? string.Empty; - if (info.SizeAndChecksums == null) info.SizeAndChecksums = new SizeAndChecksumsSection(); info.SizeAndChecksums.Size = umdsize; +#else + info.CommonDiscInfo!.Title = title ?? string.Empty; + info.CommonDiscInfo.Category = umdcat ?? DiscCategory.Games; + info.VersionAndEditions!.Version = umdversion ?? string.Empty; + info.SizeAndChecksums!.Size = umdsize; +#endif if (!string.IsNullOrWhiteSpace(umdlayer)) info.SizeAndChecksums.Layerbreak = Int64.Parse(umdlayer ?? "-1"); @@ -112,7 +128,12 @@ namespace MPF.Core.Modules.UmdImageCreator // Fill in any artifacts that exist, Base64-encoded, if we need to if (includeArtifacts) { +#if NET48 if (info.Artifacts == null) info.Artifacts = new Dictionary(); +#else + info.Artifacts ??= new Dictionary(); +#endif + if (File.Exists(basePath + "_disc.txt")) info.Artifacts["disc"] = GetBase64(GetFullFile(basePath + "_disc.txt")) ?? string.Empty; if (File.Exists(basePath + "_drive.txt")) @@ -129,7 +150,7 @@ namespace MPF.Core.Modules.UmdImageCreator /// public override List GetLogFilePaths(string basePath) { - List logFiles = new List(); + var logFiles = new List(); switch (this.Type) { case MediaType.UMD: @@ -169,7 +190,7 @@ namespace MPF.Core.Modules.UmdImageCreator if (!File.Exists(mainInfo)) return null; - using (StreamReader sr = File.OpenText(mainInfo)) + using (var sr = File.OpenText(mainInfo)) { try { @@ -211,7 +232,7 @@ namespace MPF.Core.Modules.UmdImageCreator if (!File.Exists(disc)) return false; - using (StreamReader sr = File.OpenText(disc)) + using (var sr = File.OpenText(disc)) { try { @@ -224,7 +245,11 @@ namespace MPF.Core.Modules.UmdImageCreator break; if (line.StartsWith("TITLE") && title == null) +#if NET48 title = line.Substring("TITLE: ".Length); +#else + title = line["TITLE: ".Length..]; +#endif else if (line.StartsWith("DISC_VERSION") && umdversion == null) umdversion = line.Split(' ')[1]; else if (line.StartsWith("pspUmdTypes")) @@ -236,7 +261,7 @@ namespace MPF.Core.Modules.UmdImageCreator } // If the L0 length is the size of the full disc, there's no layerbreak - if (Int64.TryParse(umdlayer, out long umdlayerValue) && umdlayerValue * 2048 == umdsize) + if (Int64.TryParse(umdlayer, out long umdlayerValue) && umdlayerValue * 2048 == umdsize) umdlayer = null; return true; diff --git a/MPF.Core/Utilities/Tools.cs b/MPF.Core/Utilities/Tools.cs index 4a245e75..0aefece8 100644 --- a/MPF.Core/Utilities/Tools.cs +++ b/MPF.Core/Utilities/Tools.cs @@ -197,7 +197,7 @@ namespace MPF.Core.Utilities #endif { #if NET48 - using (System.Net.WebClient wc = new System.Net.WebClient()) + using (var wc = new System.Net.WebClient()) { wc.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0"; @@ -211,7 +211,7 @@ namespace MPF.Core.Utilities return (latestTag, releaseUrl); } #else - using (System.Net.Http.HttpClient hc = new System.Net.Http.HttpClient()) + using (var hc = new System.Net.Http.HttpClient()) { // TODO: Figure out a better way than having this hardcoded... string url = "https://api.github.com/repos/SabreTools/MPF/releases/latest";