Skip to content

Commit

Permalink
Hide unavailable dumping programs (SabreTools#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
Deterous authored Feb 21, 2024
1 parent e35f1fc commit c6517d5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Port build script fixes from BOS
- Fix double git hash version (feat. Deterous)
- Readd x86 builds by default
- Hide unavailable dumping programs (Deterous)

### 3.1.1 (2024-02-20)

Expand Down
15 changes: 12 additions & 3 deletions MPF.Core/DumpEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,11 @@ public void SetParameters(string? parameters)
InternalProgram.DCDumper => null, // TODO: Create correct parameter type when supported
InternalProgram.UmdImageCreator => new Modules.UmdImageCreator.Parameters(parameters) { ExecutablePath = null },

// If no dumping program found, set to null
InternalProgram.NONE => null,

// This should never happen, but it needs a fallback
_ => new Modules.DiscImageCreator.Parameters(parameters) { ExecutablePath = Options.DiscImageCreatorPath },
_ => new Modules.Redumper.Parameters(parameters) { ExecutablePath = Options.RedumperPath },
};

// Set system and type
Expand Down Expand Up @@ -183,12 +186,15 @@ public void SetParameters(string? parameters)
InternalProgram.DiscImageCreator => new Modules.DiscImageCreator.Parameters(System, Type, Drive.Name, OutputPath, driveSpeed, Options),
InternalProgram.Redumper => new Modules.Redumper.Parameters(System, Type, Drive.Name, OutputPath, driveSpeed, Options),

// If no dumping program found, set to null
InternalProgram.NONE => null,

// This should never happen, but it needs a fallback
_ => new Modules.DiscImageCreator.Parameters(System, Type, Drive.Name, OutputPath, driveSpeed, Options),
_ => new Modules.Redumper.Parameters(System, Type, Drive.Name, OutputPath, driveSpeed, Options),
};

// Generate and return the param string
return Parameters.GenerateParameters();
return Parameters?.GenerateParameters();
}

return null;
Expand Down Expand Up @@ -281,6 +287,9 @@ public async Task<Result> VerifyAndSaveDumpOutput(
Func<SubmissionInfo?, (bool?, SubmissionInfo?)>? processUserInfo = null,
SubmissionInfo? seedInfo = null)
{
if (Parameters == null)
return Result.Failure("Error! Current configuration is not supported!");

resultProgress?.Report(Result.Success("Gathering submission information... please wait!"));

// Get the output directory and filename separately
Expand Down
52 changes: 44 additions & 8 deletions MPF.Core/UI/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -721,16 +721,23 @@ private void PopulateInternalPrograms()
bool cachedCanExecuteSelectionChanged = CanExecuteSelectionChanged;
DisableEventHandlers();

// Create a static list of supported programs, not everything
InternalPrograms = Enum.GetValues(typeof(InternalProgram)).Cast<InternalProgram>().Where(ip => InternalProgramExists(ip)).Select(ip => new Element<InternalProgram>(ip)).ToList();

// Get the current internal program
InternalProgram internalProgram = this.Options.InternalProgram;

// Create a static list of supported programs, not everything
var internalPrograms = new List<InternalProgram> { InternalProgram.Redumper, InternalProgram.DiscImageCreator, InternalProgram.Aaru };
InternalPrograms = internalPrograms.Select(ip => new Element<InternalProgram>(ip)).ToList();

// Select the current default dumping program
int currentIndex = InternalPrograms.FindIndex(m => m == internalProgram);
this.CurrentProgram = (currentIndex > -1 ? InternalPrograms[currentIndex].Value : InternalPrograms[0].Value);
if (InternalPrograms.Count == 0)
{
// If no programs are found, default to InternalProgram.NONE
this.CurrentProgram = InternalProgram.NONE;
}
else
{
int currentIndex = InternalPrograms.FindIndex(m => m == internalProgram);
this.CurrentProgram = (currentIndex > -1 ? InternalPrograms[currentIndex].Value : InternalPrograms[0].Value);
}

// Reenable event handlers, if necessary
if (cachedCanExecuteSelectionChanged) EnableEventHandlers();
Expand Down Expand Up @@ -1341,7 +1348,10 @@ public void EnsureDiscInformation()

// Get the status to write out
Result result = Tools.GetSupportStatus(_environment.System, _environment.Type);
this.Status = result.Message;
if (this.CurrentProgram == InternalProgram.NONE || _environment.Parameters == null)
this.Status = "No dumping program found";
else
this.Status = result.Message;

// Enable or disable the button
this.StartStopButtonEnabled = result && ShouldEnableDumpingButton();
Expand Down Expand Up @@ -1792,6 +1802,9 @@ public void ToggleParameters()
/// <returns>True if dumping should start, false otherwise</returns>
private bool ValidateBeforeDumping()
{
if (Parameters == null)
return false;

// Validate that we have an output path of any sort
if (string.IsNullOrEmpty(_environment?.OutputPath))
{
Expand Down Expand Up @@ -1900,7 +1913,30 @@ private bool ValidateBeforeDumping()
return true;
}

#endregion
/// <summary>
/// Checks whether a internal program is found in its path
/// </summary>
/// <param name="program">Program to check for</param>
/// <returns>True if the program is found, false otherwise</returns>
private bool InternalProgramExists(InternalProgram program)
{
try
{
return program switch
{
InternalProgram.Redumper => File.Exists(this.Options.RedumperPath),
InternalProgram.Aaru => File.Exists(this.Options.AaruPath),
InternalProgram.DiscImageCreator => File.Exists(this.Options.DiscImageCreatorPath),
_ => false,
};
}
catch
{
return false;
}
}

#endregion

#region Progress Reporting

Expand Down

0 comments on commit c6517d5

Please sign in to comment.