From 6141ce8539f0ccb903897a002f082b3b165d3aa2 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sat, 7 Jul 2018 01:00:27 -0700 Subject: [PATCH] Remove Disable Beep; Handle Error Case (#89) * Disable beep not supported for these * Remove testing code This more or less ensures that the current run finishes properly * Extra fixing for process issues This, with the last 2 commits, make it so that geting disc speed works again. This was only found because in testing, many MANY instances of DiscImageCreator were made but never killed, polluting the process list. These issues should now be fixed. --- DICUI/Utilities/DumpEnvironment.cs | 31 ++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/DICUI/Utilities/DumpEnvironment.cs b/DICUI/Utilities/DumpEnvironment.cs index 2016c481..c3bda4ba 100644 --- a/DICUI/Utilities/DumpEnvironment.cs +++ b/DICUI/Utilities/DumpEnvironment.cs @@ -93,14 +93,20 @@ namespace DICUI.Utilities StartInfo = new ProcessStartInfo() { FileName = DICPath, - Arguments = DICCommands.Eject + " " + Drive.Letter + " " + DICFlags.DisableBeep, + Arguments = DICCommands.Eject + " " + Drive.Letter, CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, }, }; childProcess.Start(); - childProcess.WaitForExit(); + childProcess.WaitForExit(1000); + + // Just in case, we want to push a button 5 times to clear any errors + for (int i = 0; i < 5; i++) + childProcess.StandardInput.WriteLine("Y"); + + childProcess.Dispose(); }); } @@ -135,19 +141,32 @@ namespace DICUI.Utilities StartInfo = new ProcessStartInfo() { FileName = DICPath, - Arguments = DICCommands.DriveSpeed + " " + Drive.Letter + " " + DICFlags.DisableBeep, + Arguments = DICCommands.DriveSpeed + " " + Drive.Letter, CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, + RedirectStandardInput = true, }, }; childProcess.Start(); - childProcess.WaitForExit(); - return childProcess.StandardOutput.ReadToEnd(); + childProcess.WaitForExit(1000); + + // Just in case, we want to push a button 5 times to clear any errors + for (int i = 0; i < 5; i++) + childProcess.StandardInput.WriteLine("Y"); + + string stdout = childProcess.StandardOutput.ReadToEnd(); + childProcess.Dispose(); + return stdout; }); + // If a drive or argument was invalid, just exit + if (output.Contains("Invalid argument")) + { + return -1; + } // If we get that the firmware is out of date, tell the user - if (output.Contains("[ERROR] This drive isn't latest firmware. Please update.")) + else if (output.Contains("[ERROR] This drive isn't latest firmware. Please update.")) { MessageBox.Show($"DiscImageCreator has reported that drive {Drive.Letter} is not updated to the most recent firmware. Please update the firmware for your drive and try again.", "Outdated Firmware", MessageBoxButton.OK, MessageBoxImage.Error); return -1;