From bc690614e6a89638f653be437e84c2ff6830507d Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 18 Nov 2024 12:21:13 -0500 Subject: [PATCH] Remove usages of `this.` in more places --- CHANGELIST.md | 1 + .../Aaru/ExecutionContext.cs | 34 +++++--- MPF.ExecutionContexts/BaseExecutionContext.cs | 24 ++++-- .../DiscImageCreator/ExecutionContext.cs | 84 ++++++++++--------- .../Redumper/ExecutionContext.cs | 56 +++++++------ MPF.Frontend/DumpEnvironment.cs | 4 +- MPF.Frontend/Options.cs | 6 +- 7 files changed, 121 insertions(+), 88 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index 7b33af0d..d6ddeac2 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -6,6 +6,7 @@ - Be smarter about some data types - Consolidate parameter string splitting - Fix fully matching when multiple matches found +- Remove usages of `this.` in more places ### 3.2.3 (2024-11-06) diff --git a/MPF.ExecutionContexts/Aaru/ExecutionContext.cs b/MPF.ExecutionContexts/Aaru/ExecutionContext.cs index b5aed321..5d5b33ce 100644 --- a/MPF.ExecutionContexts/Aaru/ExecutionContext.cs +++ b/MPF.ExecutionContexts/Aaru/ExecutionContext.cs @@ -114,7 +114,12 @@ namespace MPF.ExecutionContexts.Aaru public ExecutionContext(string? parameters) : base(parameters) { } /// - public ExecutionContext(RedumpSystem? system, MediaType? type, string? drivePath, string filename, int? driveSpeed, Dictionary options) + public ExecutionContext(RedumpSystem? system, + MediaType? type, + string? drivePath, + string filename, + int? driveSpeed, + Dictionary options) : base(system, type, drivePath, filename, driveSpeed, options) { } @@ -1191,7 +1196,10 @@ namespace MPF.ExecutionContexts.Aaru } /// - protected override void SetDefaultParameters(string? drivePath, string filename, int? driveSpeed, Dictionary options) + protected override void SetDefaultParameters(string? drivePath, + string filename, + int? driveSpeed, + Dictionary options) { BaseCommand = $"{CommandStrings.MediaPrefixLong} {CommandStrings.MediaDump}"; @@ -1205,8 +1213,8 @@ namespace MPF.ExecutionContexts.Aaru } // First check to see if the combination of system and MediaType is valid - var validTypes = this.System.MediaTypes(); - if (!validTypes.Contains(this.Type)) + var validTypes = RedumpSystem.MediaTypes(); + if (!validTypes.Contains(MediaType)) return; // Set retry count @@ -1229,40 +1237,40 @@ namespace MPF.ExecutionContexts.Aaru // TODO: Look at dump-media formats and the like and see what options there are there to fill in defaults // Now sort based on disc type - switch (this.Type) + switch (MediaType) { - case MediaType.CDROM: + case SabreTools.RedumpLib.Data.MediaType.CDROM: // Currently no defaults set break; - case MediaType.DVD: + case SabreTools.RedumpLib.Data.MediaType.DVD: this[FlagStrings.StoreEncryptedLong] = true; // TODO: Make this configurable this[FlagStrings.TitleKeysLong] = false; // TODO: Make this configurable this[FlagStrings.TrimLong] = true; // TODO: Make this configurable break; - case MediaType.GDROM: + case SabreTools.RedumpLib.Data.MediaType.GDROM: // Currently no defaults set break; - case MediaType.HDDVD: + case SabreTools.RedumpLib.Data.MediaType.HDDVD: this[FlagStrings.StoreEncryptedLong] = true; // TODO: Make this configurable this[FlagStrings.TitleKeysLong] = false; // TODO: Make this configurable this[FlagStrings.TrimLong] = true; // TODO: Make this configurable break; - case MediaType.BluRay: + case SabreTools.RedumpLib.Data.MediaType.BluRay: this[FlagStrings.StoreEncryptedLong] = true; // TODO: Make this configurable this[FlagStrings.TitleKeysLong] = false; // TODO: Make this configurable this[FlagStrings.TrimLong] = true; // TODO: Make this configurable break; // Special Formats - case MediaType.NintendoGameCubeGameDisc: + case SabreTools.RedumpLib.Data.MediaType.NintendoGameCubeGameDisc: // Currently no defaults set break; - case MediaType.NintendoWiiOpticalDisc: + case SabreTools.RedumpLib.Data.MediaType.NintendoWiiOpticalDisc: // Currently no defaults set break; // Non-optical - case MediaType.FloppyDisk: + case SabreTools.RedumpLib.Data.MediaType.FloppyDisk: // Currently no defaults set break; } diff --git a/MPF.ExecutionContexts/BaseExecutionContext.cs b/MPF.ExecutionContexts/BaseExecutionContext.cs index 4d1334ce..dbeb659b 100644 --- a/MPF.ExecutionContexts/BaseExecutionContext.cs +++ b/MPF.ExecutionContexts/BaseExecutionContext.cs @@ -82,12 +82,12 @@ namespace MPF.ExecutionContexts /// /// Currently represented system /// - public RedumpSystem? System { get; set; } + public RedumpSystem? RedumpSystem { get; set; } /// /// Currently represented media type /// - public MediaType? Type { get; set; } + public MediaType? MediaType { get; set; } #endregion @@ -111,10 +111,15 @@ namespace MPF.ExecutionContexts /// Filename to use /// Drive speed to use /// Dictionary object containing all settings that may be used for setting parameters - public BaseExecutionContext(RedumpSystem? system, MediaType? type, string? drivePath, string filename, int? driveSpeed, Dictionary options) + public BaseExecutionContext(RedumpSystem? system, + MediaType? type, + string? drivePath, + string filename, + int? driveSpeed, + Dictionary options) { - this.System = system; - this.Type = type; + RedumpSystem = system; + MediaType = type; SetDefaultParameters(drivePath, filename, driveSpeed, options); } @@ -169,7 +174,10 @@ namespace MPF.ExecutionContexts /// Filename to use /// Drive speed to use /// Dictionary containing all settings that may be used for setting parameters - protected abstract void SetDefaultParameters(string? drivePath, string filename, int? driveSpeed, Dictionary options); + protected abstract void SetDefaultParameters(string? drivePath, + string filename, + int? driveSpeed, + Dictionary options); /// /// Scan a possible parameter string and populate whatever possible @@ -326,9 +334,9 @@ namespace MPF.ExecutionContexts { if (CommandSupport == null) return false; - if (this.BaseCommand == null) + if (BaseCommand == null) return false; - if (!CommandSupport.TryGetValue(this.BaseCommand, out var supported)) + if (!CommandSupport.TryGetValue(BaseCommand, out var supported)) return false; return supported.Contains(flag); } diff --git a/MPF.ExecutionContexts/DiscImageCreator/ExecutionContext.cs b/MPF.ExecutionContexts/DiscImageCreator/ExecutionContext.cs index 8b791991..b952eb0c 100644 --- a/MPF.ExecutionContexts/DiscImageCreator/ExecutionContext.cs +++ b/MPF.ExecutionContexts/DiscImageCreator/ExecutionContext.cs @@ -164,7 +164,12 @@ namespace MPF.ExecutionContexts.DiscImageCreator public ExecutionContext(string? parameters) : base(parameters) { } /// - public ExecutionContext(RedumpSystem? system, MediaType? type, string? drivePath, string filename, int? driveSpeed, Dictionary options) + public ExecutionContext(RedumpSystem? system, + MediaType? type, + string? drivePath, + string filename, + int? driveSpeed, + Dictionary options) : base(system, type, drivePath, filename, driveSpeed, options) { } @@ -958,17 +963,20 @@ namespace MPF.ExecutionContexts.DiscImageCreator } /// - protected override void SetDefaultParameters(string? drivePath, string filename, int? driveSpeed, Dictionary options) + protected override void SetDefaultParameters(string? drivePath, + string filename, + int? driveSpeed, + Dictionary options) { - SetBaseCommand(this.System, this.Type); + SetBaseCommand(RedumpSystem, MediaType); DrivePath = drivePath; DriveSpeed = driveSpeed; Filename = filename; // First check to see if the combination of system and MediaType is valid - var validTypes = this.System.MediaTypes(); - if (!validTypes.Contains(this.Type)) + var validTypes = RedumpSystem.MediaTypes(); + if (!validTypes.Contains(MediaType)) return; // Set disable beep flag, if needed @@ -994,18 +1002,18 @@ namespace MPF.ExecutionContexts.DiscImageCreator }; // Now sort based on disc type - switch (this.Type) + switch (MediaType) { - case MediaType.CDROM: + case SabreTools.RedumpLib.Data.MediaType.CDROM: this[FlagStrings.C2Opcode] = true; this[FlagStrings.MultiSectorRead] = GetBooleanSetting(options, SettingConstants.MultiSectorRead, SettingConstants.MultiSectorReadDefault); if (this[FlagStrings.MultiSectorRead] == true) - this.MultiSectorReadValue = GetInt32Setting(options, SettingConstants.MultiSectorReadValue, SettingConstants.MultiSectorReadValueDefault); + MultiSectorReadValue = GetInt32Setting(options, SettingConstants.MultiSectorReadValue, SettingConstants.MultiSectorReadValueDefault); - switch (this.System) + switch (RedumpSystem) { - case RedumpSystem.AppleMacintosh: - case RedumpSystem.IBMPCcompatible: + case SabreTools.RedumpLib.Data.RedumpSystem.AppleMacintosh: + case SabreTools.RedumpLib.Data.RedumpSystem.IBMPCcompatible: this[FlagStrings.NoFixSubQSecuROM] = true; this[FlagStrings.ScanFileProtect] = true; this[FlagStrings.ScanSectorProtect] = GetBooleanSetting(options, SettingConstants.ParanoidMode, SettingConstants.ParanoidModeDefault); @@ -1014,48 +1022,48 @@ namespace MPF.ExecutionContexts.DiscImageCreator SubchannelReadLevelValue = 2; break; - case RedumpSystem.AtariJaguarCDInteractiveMultimediaSystem: + case SabreTools.RedumpLib.Data.RedumpSystem.AtariJaguarCDInteractiveMultimediaSystem: this[FlagStrings.AtariJaguar] = true; break; - case RedumpSystem.HasbroVideoNow: - case RedumpSystem.HasbroVideoNowColor: - case RedumpSystem.HasbroVideoNowJr: - case RedumpSystem.HasbroVideoNowXP: + case SabreTools.RedumpLib.Data.RedumpSystem.HasbroVideoNow: + case SabreTools.RedumpLib.Data.RedumpSystem.HasbroVideoNowColor: + case SabreTools.RedumpLib.Data.RedumpSystem.HasbroVideoNowJr: + case SabreTools.RedumpLib.Data.RedumpSystem.HasbroVideoNowXP: this[FlagStrings.AddOffset] = true; - this.AddOffsetValue = 0; // Value needed for first run and placeholder after + AddOffsetValue = 0; // Value needed for first run and placeholder after break; - case RedumpSystem.SonyPlayStation: + case SabreTools.RedumpLib.Data.RedumpSystem.SonyPlayStation: this[FlagStrings.ScanAntiMod] = true; this[FlagStrings.NoFixSubQLibCrypt] = true; break; } break; - case MediaType.DVD: + case SabreTools.RedumpLib.Data.MediaType.DVD: this[FlagStrings.CopyrightManagementInformation] = GetBooleanSetting(options, SettingConstants.UseCMIFlag, SettingConstants.UseCMIFlagDefault); this[FlagStrings.ScanFileProtect] = GetBooleanSetting(options, SettingConstants.ParanoidMode, SettingConstants.ParanoidModeDefault); this[FlagStrings.DVDReread] = true; break; - case MediaType.GDROM: + case SabreTools.RedumpLib.Data.MediaType.GDROM: this[FlagStrings.C2Opcode] = true; break; - case MediaType.HDDVD: + case SabreTools.RedumpLib.Data.MediaType.HDDVD: this[FlagStrings.CopyrightManagementInformation] = GetBooleanSetting(options, SettingConstants.UseCMIFlag, SettingConstants.UseCMIFlagDefault); this[FlagStrings.DVDReread] = true; break; - case MediaType.BluRay: + case SabreTools.RedumpLib.Data.MediaType.BluRay: this[FlagStrings.DVDReread] = true; break; // Special Formats - case MediaType.NintendoGameCubeGameDisc: + case SabreTools.RedumpLib.Data.MediaType.NintendoGameCubeGameDisc: this[FlagStrings.Raw] = true; break; - case MediaType.NintendoWiiOpticalDisc: + case SabreTools.RedumpLib.Data.MediaType.NintendoWiiOpticalDisc: this[FlagStrings.Raw] = true; break; // Non-optical - case MediaType.FloppyDisk: + case SabreTools.RedumpLib.Data.MediaType.FloppyDisk: // Currently no defaults set break; } @@ -1695,43 +1703,43 @@ namespace MPF.ExecutionContexts.DiscImageCreator switch (type) { - case MediaType.CDROM: - if (system == RedumpSystem.SuperAudioCD) + case SabreTools.RedumpLib.Data.MediaType.CDROM: + if (system == SabreTools.RedumpLib.Data.RedumpSystem.SuperAudioCD) BaseCommand = CommandStrings.SACD; else BaseCommand = CommandStrings.CompactDisc; return; - case MediaType.DVD: - if (system == RedumpSystem.MicrosoftXbox - || system == RedumpSystem.MicrosoftXbox360) + case SabreTools.RedumpLib.Data.MediaType.DVD: + if (system == SabreTools.RedumpLib.Data.RedumpSystem.MicrosoftXbox + || system == SabreTools.RedumpLib.Data.RedumpSystem.MicrosoftXbox360) { BaseCommand = CommandStrings.XBOX; return; } BaseCommand = CommandStrings.DigitalVideoDisc; return; - case MediaType.GDROM: + case SabreTools.RedumpLib.Data.MediaType.GDROM: BaseCommand = CommandStrings.GDROM; return; - case MediaType.HDDVD: + case SabreTools.RedumpLib.Data.MediaType.HDDVD: BaseCommand = CommandStrings.DigitalVideoDisc; return; - case MediaType.BluRay: + case SabreTools.RedumpLib.Data.MediaType.BluRay: BaseCommand = CommandStrings.BluRay; return; - case MediaType.NintendoGameCubeGameDisc: + case SabreTools.RedumpLib.Data.MediaType.NintendoGameCubeGameDisc: BaseCommand = CommandStrings.DigitalVideoDisc; return; - case MediaType.NintendoWiiOpticalDisc: + case SabreTools.RedumpLib.Data.MediaType.NintendoWiiOpticalDisc: BaseCommand = CommandStrings.DigitalVideoDisc; return; - case MediaType.FloppyDisk: + case SabreTools.RedumpLib.Data.MediaType.FloppyDisk: BaseCommand = CommandStrings.Floppy; return; - case MediaType.HardDisk: + case SabreTools.RedumpLib.Data.MediaType.HardDisk: BaseCommand = CommandStrings.Disk; return; - case MediaType.DataCartridge: + case SabreTools.RedumpLib.Data.MediaType.DataCartridge: BaseCommand = CommandStrings.Tape; return; diff --git a/MPF.ExecutionContexts/Redumper/ExecutionContext.cs b/MPF.ExecutionContexts/Redumper/ExecutionContext.cs index 7a2093f1..0f9aa0f8 100644 --- a/MPF.ExecutionContexts/Redumper/ExecutionContext.cs +++ b/MPF.ExecutionContexts/Redumper/ExecutionContext.cs @@ -19,7 +19,7 @@ namespace MPF.ExecutionContexts.Redumper public override string? OutputPath => Path.Combine( ImagePathValue?.Trim('"') ?? string.Empty, ImageNameValue?.Trim('"') ?? string.Empty) - + GetDefaultExtension(this.Type); + + GetDefaultExtension(MediaType); /// public override int? Speed => SpeedValue; @@ -159,7 +159,12 @@ namespace MPF.ExecutionContexts.Redumper public ExecutionContext(string? parameters) : base(parameters) { } /// - public ExecutionContext(RedumpSystem? system, MediaType? type, string? drivePath, string filename, int? driveSpeed, Dictionary options) + public ExecutionContext(RedumpSystem? system, + MediaType? type, + string? drivePath, + string filename, + int? driveSpeed, + Dictionary options) : base(system, type, drivePath, filename, driveSpeed, options) { } @@ -501,14 +506,14 @@ namespace MPF.ExecutionContexts.Redumper /// public override bool IsDumpingCommand() { - return this.BaseCommand == CommandStrings.NONE - || this.BaseCommand?.Contains(CommandStrings.CD) == true - || this.BaseCommand?.Contains(CommandStrings.DVD) == true - || this.BaseCommand?.Contains(CommandStrings.BluRay) == true - || this.BaseCommand?.Contains(CommandStrings.SACD) == true - || this.BaseCommand?.Contains(CommandStrings.New) == true - || this.BaseCommand?.Contains(CommandStrings.Dump) == true - || this.BaseCommand?.Contains(CommandStrings.DumpNew) == true; + return BaseCommand == CommandStrings.NONE + || BaseCommand?.Contains(CommandStrings.CD) == true + || BaseCommand?.Contains(CommandStrings.DVD) == true + || BaseCommand?.Contains(CommandStrings.BluRay) == true + || BaseCommand?.Contains(CommandStrings.SACD) == true + || BaseCommand?.Contains(CommandStrings.New) == true + || BaseCommand?.Contains(CommandStrings.Dump) == true + || BaseCommand?.Contains(CommandStrings.DumpNew) == true; } /// @@ -548,34 +553,37 @@ namespace MPF.ExecutionContexts.Redumper } /// - protected override void SetDefaultParameters(string? drivePath, string filename, int? driveSpeed, Dictionary options) + protected override void SetDefaultParameters(string? drivePath, + string filename, + int? driveSpeed, + Dictionary options) { // If we don't have a CD, DVD, HD-DVD, or BD, we can't dump using redumper - if (this.Type != MediaType.CDROM - && this.Type != MediaType.DVD - && this.Type != MediaType.HDDVD - && this.Type != MediaType.BluRay) + if (MediaType != SabreTools.RedumpLib.Data.MediaType.CDROM + && MediaType != SabreTools.RedumpLib.Data.MediaType.DVD + && MediaType != SabreTools.RedumpLib.Data.MediaType.HDDVD + && MediaType != SabreTools.RedumpLib.Data.MediaType.BluRay) { return; } BaseCommand = CommandStrings.NONE; - switch (this.Type) + switch (MediaType) { - case MediaType.CDROM: - ModeValues = this.System switch + case SabreTools.RedumpLib.Data.MediaType.CDROM: + ModeValues = RedumpSystem switch { - RedumpSystem.SuperAudioCD => [CommandStrings.SACD], + SabreTools.RedumpLib.Data.RedumpSystem.SuperAudioCD => [CommandStrings.SACD], _ => [CommandStrings.CD], }; break; - case MediaType.DVD: + case SabreTools.RedumpLib.Data.MediaType.DVD: ModeValues = [CommandStrings.DVD]; break; - case MediaType.HDDVD: // TODO: Keep in sync if another command string shows up + case SabreTools.RedumpLib.Data.MediaType.HDDVD: // TODO: Keep in sync if another command string shows up ModeValues = [CommandStrings.DVD]; break; - case MediaType.BluRay: + case SabreTools.RedumpLib.Data.MediaType.BluRay: ModeValues = [CommandStrings.BluRay]; break; default: @@ -899,8 +907,8 @@ namespace MPF.ExecutionContexts.Redumper } // If the image name was not set, set it with a default value - if (string.IsNullOrEmpty(this.ImageNameValue)) - this.ImageNameValue = "track"; + if (string.IsNullOrEmpty(ImageNameValue)) + ImageNameValue = "track"; return true; } diff --git a/MPF.Frontend/DumpEnvironment.cs b/MPF.Frontend/DumpEnvironment.cs index 95499407..aa3cf8b2 100644 --- a/MPF.Frontend/DumpEnvironment.cs +++ b/MPF.Frontend/DumpEnvironment.cs @@ -199,8 +199,8 @@ namespace MPF.Frontend // Set system, type, and drive if (_executionContext != null) { - _executionContext.System = _system; - _executionContext.Type = _type; + _executionContext.RedumpSystem = _system; + _executionContext.MediaType = _type; // Set some parameters, if not already set OutputPath ??= _executionContext.OutputPath!; diff --git a/MPF.Frontend/Options.cs b/MPF.Frontend/Options.cs index d85d8cc6..cd740141 100644 --- a/MPF.Frontend/Options.cs +++ b/MPF.Frontend/Options.cs @@ -671,7 +671,7 @@ namespace MPF.Frontend /// public Options(Dictionary? settings = null) { - this.Settings = settings ?? []; + Settings = settings ?? []; } /// @@ -688,8 +688,8 @@ namespace MPF.Frontend /// public string? this[string key] { - get => this.Settings[key]; - set => this.Settings[key] = value; + get => Settings[key]; + set => Settings[key] = value; } #region Helpers