From 101193cb78603fb8f7b7cb302cb460fb84b9e05d Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 25 Jan 2021 13:11:20 -0800 Subject: [PATCH] Streamline statuses from trying to execute --- MPF.Library/Data/BaseParameters.cs | 17 --------- MPF.Library/Utilities/DumpEnvironment.cs | 44 +++++++++--------------- MPF.Library/Utilities/Validators.cs | 10 +++--- 3 files changed, 21 insertions(+), 50 deletions(-) diff --git a/MPF.Library/Data/BaseParameters.cs b/MPF.Library/Data/BaseParameters.cs index a9adc190..e9b1bc9b 100644 --- a/MPF.Library/Data/BaseParameters.cs +++ b/MPF.Library/Data/BaseParameters.cs @@ -164,28 +164,11 @@ namespace MPF.Data /// Drive representing the disc to get information from public abstract void GenerateSubmissionInfo(SubmissionInfo submissionInfo, string basePath, Drive drive); - /// - /// Returns if the related executable exists in the configured path or not - /// - /// True if the executable exists, false otherwise - public bool InternalProgramExists() - { - // Missing path information means we can't invoke anyway - if (string.IsNullOrWhiteSpace(ExecutablePath)) - return false; - - return File.Exists(ExecutablePath); - } - /// /// Run internal program /// public void ExecuteInternalProgram() { - // Invalid path means we shouldn't try to invoke - if (!InternalProgramExists()) - return; - process = new Process() { StartInfo = new ProcessStartInfo() diff --git a/MPF.Library/Utilities/DumpEnvironment.cs b/MPF.Library/Utilities/DumpEnvironment.cs index 91847421..dd9e7899 100644 --- a/MPF.Library/Utilities/DumpEnvironment.cs +++ b/MPF.Library/Utilities/DumpEnvironment.cs @@ -464,35 +464,21 @@ namespace MPF.Utilities /// Optional result progress callback public async Task Run(IProgress progress = null) { + // Check that we have the basics for dumping Result result = IsValidForDump(); + if (!result) + return result; - // Execute dumping program and external tools, if needed - if (Validators.GetSupportStatus(System, Type) - && !result.Message.Contains("not supported") // Completely unsupported media - && !result.Message.Contains("submission info")) // Submission info-only media - { - // If the environment is invalid, return - if (!result) - return result; + // Execute internal tool + progress?.Report(Result.Success($"Executing {this.InternalProgram}... please wait!")); + Directory.CreateDirectory(OutputDirectory); + await Task.Run(() => Parameters.ExecuteInternalProgram()); + progress?.Report(Result.Success($"{this.InternalProgram} has finished!")); - // 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); - await Task.Run(() => Parameters.ExecuteInternalProgram()); - progress?.Report(Result.Success($"{this.InternalProgram} has finished!")); - - // Execute additional tools - progress?.Report(Result.Success("Running any additional tools... please wait!")); - result = await Task.Run(() => ExecuteAdditionalTools()); - progress?.Report(result); - } + // Execute additional tools + progress?.Report(Result.Success("Running any additional tools... please wait!")); + result = await Task.Run(() => ExecuteAdditionalTools()); + progress?.Report(result); return result; } @@ -1298,15 +1284,17 @@ namespace MPF.Utilities if (!ParametersValid()) return Result.Failure("Error! Current configuration is not supported!"); + // Fix the output paths, just in case FixOutputPaths(); // Validate that the required program exists if (!File.Exists(Parameters.ExecutablePath)) - return Result.Failure("Error! Could not find the program!"); + return Result.Failure($"Error! {Parameters.ExecutablePath} does not exist!"); // TODO: Ensure output path not the same as input drive OR executable location - return Result.Success(); + // Validate that the current configuration is supported + return Validators.GetSupportStatus(System, Type); } /// diff --git a/MPF.Library/Utilities/Validators.cs b/MPF.Library/Utilities/Validators.cs index 4f3c6025..9bf63c56 100644 --- a/MPF.Library/Utilities/Validators.cs +++ b/MPF.Library/Utilities/Validators.cs @@ -979,25 +979,25 @@ namespace MPF.Utilities case MediaType.SDCard: case MediaType.FlashDrive: case MediaType.HDDVD: - return Result.Success("{0} ready to dump", type.LongName()); + return Result.Success($"{type.LongName()} ready to dump"); // Partially supported types case MediaType.GDROM: case MediaType.NintendoGameCubeGameDisc: case MediaType.NintendoWiiOpticalDisc: - return Result.Success("{0} partially supported for dumping", type.LongName()); + return Result.Success($"{type.LongName()} partially supported for dumping"); // Special case for other supported tools case MediaType.UMD: - return Result.Success("{0} supported for submission info parsing", type.LongName()); + return Result.Failure($"{type.LongName()} supported for submission info parsing"); // Specifically unknown type case MediaType.NONE: - return Result.Failure("Please select a valid media type"); + return Result.Failure($"Please select a valid media type"); // Undumpable but recognized types default: - return Result.Failure("{0} media are not supported for dumping", type.LongName()); + return Result.Failure($"{type.LongName()} media are not supported for dumping"); } }