Remove usages of this. in more places

This commit is contained in:
Matt Nadareski
2024-11-18 12:21:13 -05:00
parent d44798b27c
commit bc690614e6
7 changed files with 121 additions and 88 deletions

View File

@@ -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)

View File

@@ -114,7 +114,12 @@ namespace MPF.ExecutionContexts.Aaru
public ExecutionContext(string? parameters) : base(parameters) { }
/// <inheritdoc/>
public ExecutionContext(RedumpSystem? system, MediaType? type, string? drivePath, string filename, int? driveSpeed, Dictionary<string, string?> options)
public ExecutionContext(RedumpSystem? system,
MediaType? type,
string? drivePath,
string filename,
int? driveSpeed,
Dictionary<string, string?> options)
: base(system, type, drivePath, filename, driveSpeed, options)
{
}
@@ -1191,7 +1196,10 @@ namespace MPF.ExecutionContexts.Aaru
}
/// <inheritdoc/>
protected override void SetDefaultParameters(string? drivePath, string filename, int? driveSpeed, Dictionary<string, string?> options)
protected override void SetDefaultParameters(string? drivePath,
string filename,
int? driveSpeed,
Dictionary<string, string?> 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;
}

View File

@@ -82,12 +82,12 @@ namespace MPF.ExecutionContexts
/// <summary>
/// Currently represented system
/// </summary>
public RedumpSystem? System { get; set; }
public RedumpSystem? RedumpSystem { get; set; }
/// <summary>
/// Currently represented media type
/// </summary>
public MediaType? Type { get; set; }
public MediaType? MediaType { get; set; }
#endregion
@@ -111,10 +111,15 @@ namespace MPF.ExecutionContexts
/// <param name="filename">Filename to use</param>
/// <param name="driveSpeed">Drive speed to use</param>
/// <param name="options">Dictionary object containing all settings that may be used for setting parameters</param>
public BaseExecutionContext(RedumpSystem? system, MediaType? type, string? drivePath, string filename, int? driveSpeed, Dictionary<string, string?> options)
public BaseExecutionContext(RedumpSystem? system,
MediaType? type,
string? drivePath,
string filename,
int? driveSpeed,
Dictionary<string, string?> options)
{
this.System = system;
this.Type = type;
RedumpSystem = system;
MediaType = type;
SetDefaultParameters(drivePath, filename, driveSpeed, options);
}
@@ -169,7 +174,10 @@ namespace MPF.ExecutionContexts
/// <param name="filename">Filename to use</param>
/// <param name="driveSpeed">Drive speed to use</param>
/// <param name="options">Dictionary containing all settings that may be used for setting parameters</param>
protected abstract void SetDefaultParameters(string? drivePath, string filename, int? driveSpeed, Dictionary<string, string?> options);
protected abstract void SetDefaultParameters(string? drivePath,
string filename,
int? driveSpeed,
Dictionary<string, string?> options);
/// <summary>
/// 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);
}

View File

@@ -164,7 +164,12 @@ namespace MPF.ExecutionContexts.DiscImageCreator
public ExecutionContext(string? parameters) : base(parameters) { }
/// <inheritdoc/>
public ExecutionContext(RedumpSystem? system, MediaType? type, string? drivePath, string filename, int? driveSpeed, Dictionary<string, string?> options)
public ExecutionContext(RedumpSystem? system,
MediaType? type,
string? drivePath,
string filename,
int? driveSpeed,
Dictionary<string, string?> options)
: base(system, type, drivePath, filename, driveSpeed, options)
{
}
@@ -958,17 +963,20 @@ namespace MPF.ExecutionContexts.DiscImageCreator
}
/// <inheritdoc/>
protected override void SetDefaultParameters(string? drivePath, string filename, int? driveSpeed, Dictionary<string, string?> options)
protected override void SetDefaultParameters(string? drivePath,
string filename,
int? driveSpeed,
Dictionary<string, string?> 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;

View File

@@ -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);
/// <inheritdoc/>
public override int? Speed => SpeedValue;
@@ -159,7 +159,12 @@ namespace MPF.ExecutionContexts.Redumper
public ExecutionContext(string? parameters) : base(parameters) { }
/// <inheritdoc/>
public ExecutionContext(RedumpSystem? system, MediaType? type, string? drivePath, string filename, int? driveSpeed, Dictionary<string, string?> options)
public ExecutionContext(RedumpSystem? system,
MediaType? type,
string? drivePath,
string filename,
int? driveSpeed,
Dictionary<string, string?> options)
: base(system, type, drivePath, filename, driveSpeed, options)
{
}
@@ -501,14 +506,14 @@ namespace MPF.ExecutionContexts.Redumper
/// <inheritdoc/>
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;
}
/// <inheritdoc/>
@@ -548,34 +553,37 @@ namespace MPF.ExecutionContexts.Redumper
}
/// <inheritdoc/>
protected override void SetDefaultParameters(string? drivePath, string filename, int? driveSpeed, Dictionary<string, string?> options)
protected override void SetDefaultParameters(string? drivePath,
string filename,
int? driveSpeed,
Dictionary<string, string?> 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;
}

View File

@@ -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!;

View File

@@ -671,7 +671,7 @@ namespace MPF.Frontend
/// <param name="settings"></param>
public Options(Dictionary<string, string?>? settings = null)
{
this.Settings = settings ?? [];
Settings = settings ?? [];
}
/// <summary>
@@ -688,8 +688,8 @@ namespace MPF.Frontend
/// </summary>
public string? this[string key]
{
get => this.Settings[key];
set => this.Settings[key] = value;
get => Settings[key];
set => Settings[key] = value;
}
#region Helpers