Ensure the executable exists before trying to run it

This commit is contained in:
Matt Nadareski
2021-01-25 11:55:18 -08:00
parent 2957370fac
commit 999c4dceb5
3 changed files with 31 additions and 0 deletions

View File

@@ -164,11 +164,28 @@ namespace MPF.Data
/// <param name="drive">Drive representing the disc to get information from</param>
public abstract void GenerateSubmissionInfo(SubmissionInfo submissionInfo, string basePath, Drive drive);
/// <summary>
/// Returns if the related executable exists in the configured path or not
/// </summary>
/// <returns>True if the executable exists, false otherwise</returns>
public bool InternalProgramExists()
{
// Missing path information means we can't invoke anyway
if (string.IsNullOrWhiteSpace(ExecutablePath))
return false;
return File.Exists(ExecutablePath);
}
/// <summary>
/// Run internal program
/// </summary>
public void ExecuteInternalProgram()
{
// Invalid path means we shouldn't try to invoke
if (!InternalProgramExists())
return;
process = new Process()
{
StartInfo = new ProcessStartInfo()

View File

@@ -475,6 +475,13 @@ namespace MPF.Utilities
if (!result)
return result;
// Check that the internal tool exists
if (!Parameters.InternalProgramExists())
{
progress?.Report(Result.Success($"Could not find executable for {this.InternalProgram}!"));
return Result.Failure($"Could not find executable for {this.InternalProgram}!");
}
// Execute internal tool
progress?.Report(Result.Success($"Executing {this.InternalProgram}... please wait!"));
Directory.CreateDirectory(OutputDirectory);

View File

@@ -646,6 +646,13 @@ namespace MPF.Windows
ShowDiscInformationWindow
);
}
else
{
ViewModels.LoggerViewModel.VerboseLogLn(result.Message);
StatusLabel.Content = "Execution failed!";
StartStopButton.Content = Interface.StartDumping;
CopyProtectScanButton.IsEnabled = true;
}
}
catch
{