mirror of
https://github.com/SabreTools/MPF.git
synced 2026-07-02 17:24:48 +00:00
Add option to reset drive after dump (fixes #143)
This commit is contained in:
@@ -157,33 +157,13 @@ namespace DICUI.Utilities
|
||||
if (!File.Exists(DICPath))
|
||||
return false;
|
||||
|
||||
// Use the drive speed command as a quick test
|
||||
Process childProcess;
|
||||
string output = await Task.Run(() =>
|
||||
Parameters parameters = new Parameters(string.Empty)
|
||||
{
|
||||
childProcess = new Process()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = DICPath,
|
||||
Arguments = DICCommandStrings.DriveSpeed + " " + Drive.Letter,
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
},
|
||||
};
|
||||
childProcess.Start();
|
||||
childProcess.WaitForExit(1000);
|
||||
Command = DICCommand.DriveSpeed,
|
||||
DriveLetter = Drive.Letter.ToString(),
|
||||
};
|
||||
|
||||
// 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;
|
||||
});
|
||||
string output = await ExecuteDiscImageCreatorWithParameters(parameters);
|
||||
|
||||
// If we get the firmware message
|
||||
if (output.Contains("[ERROR] This drive isn't latest firmware. Please update."))
|
||||
@@ -208,30 +188,13 @@ namespace DICUI.Utilities
|
||||
if (Drive.InternalDriveType != InternalDriveType.Optical)
|
||||
return;
|
||||
|
||||
Process childProcess;
|
||||
await Task.Run(() =>
|
||||
Parameters parameters = new Parameters(string.Empty)
|
||||
{
|
||||
childProcess = new Process()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = DICPath,
|
||||
Arguments = DICCommandStrings.Eject + " " + Drive.Letter,
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
},
|
||||
};
|
||||
childProcess.Start();
|
||||
childProcess.WaitForExit(1000);
|
||||
Command = DICCommand.Eject,
|
||||
DriveLetter = Drive.Letter.ToString(),
|
||||
};
|
||||
|
||||
// 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();
|
||||
});
|
||||
await ExecuteDiscImageCreatorWithParameters(parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -389,6 +352,31 @@ namespace DICUI.Utilities
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the current drive using DIC
|
||||
/// </summary>
|
||||
public async void ResetDrive()
|
||||
{
|
||||
// Validate that the required program exists
|
||||
if (!File.Exists(DICPath))
|
||||
return;
|
||||
|
||||
// Precautionary check for dumping, just in case
|
||||
CancelDumping();
|
||||
|
||||
// Validate we're not trying to reset a non-optical
|
||||
if (Drive.InternalDriveType != InternalDriveType.Optical)
|
||||
return;
|
||||
|
||||
Parameters parameters = new Parameters(string.Empty)
|
||||
{
|
||||
Command = DICCommand.Reset,
|
||||
DriveLetter = Drive.Letter.ToString(),
|
||||
};
|
||||
|
||||
await ExecuteDiscImageCreatorWithParameters(parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute a complete dump workflow
|
||||
/// </summary>
|
||||
@@ -422,7 +410,7 @@ namespace DICUI.Utilities
|
||||
/// Verify that the current environment has a complete dump and create submission info is possible
|
||||
/// </summary>
|
||||
/// <returns>Result instance with the outcome</returns>
|
||||
public Result VerifyAndSaveDumpOutput(IProgress<Result> progress, bool? ejectDisc = null, Func<SubmissionInfo, bool?> ShowUserPrompt = null)
|
||||
public Result VerifyAndSaveDumpOutput(IProgress<Result> progress, bool? ejectDisc = null, bool resetDrive = false, Func<SubmissionInfo, bool?> ShowUserPrompt = null)
|
||||
{
|
||||
progress.Report(Result.Success("Gathering submission information... please wait!"));
|
||||
|
||||
@@ -440,6 +428,12 @@ namespace DICUI.Utilities
|
||||
EjectDisc();
|
||||
}
|
||||
|
||||
if (resetDrive)
|
||||
{
|
||||
progress.Report(Result.Success($"Resetting drive {Drive.Letter}"));
|
||||
ResetDrive();
|
||||
}
|
||||
|
||||
if (PromptForDiscInformation && ShowUserPrompt != null)
|
||||
{
|
||||
progress?.Report(Result.Success("Waiting for additional disc information..."));
|
||||
@@ -522,6 +516,43 @@ namespace DICUI.Utilities
|
||||
dicProcess.WaitForExit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Run DIC async with an input set of parameters
|
||||
/// </summary>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns>Standard output from commandline window</returns>
|
||||
private async Task<string> ExecuteDiscImageCreatorWithParameters(Parameters parameters)
|
||||
{
|
||||
Process childProcess;
|
||||
string output = await Task.Run(() =>
|
||||
{
|
||||
childProcess = new Process()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = DICPath,
|
||||
Arguments = parameters.GenerateParameters(),
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
},
|
||||
};
|
||||
childProcess.Start();
|
||||
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;
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute subdump for a (potential) Sega Saturn dump
|
||||
/// </summary>
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<add key="AddPlaceholders" value="true"/>
|
||||
<add key="PromptForDiscInformation" value="true"/>
|
||||
<add key="IgnoreFixedDrives" value="false"/>
|
||||
<add key="ResetDriveAfterDump" value="false"/>
|
||||
|
||||
<add key="Username" value=""/>
|
||||
<add key="Password" value=""/>
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace DICUI
|
||||
public bool AddPlaceholders { get; set; }
|
||||
public bool PromptForDiscInformation { get; set; }
|
||||
public bool IgnoreFixedDrives { get; set; }
|
||||
public bool ResetDriveAfterDump { get; set; }
|
||||
|
||||
public bool SkipMediaTypeDetection { get; set; }
|
||||
public bool SkipSystemDetection { get; set; }
|
||||
@@ -74,6 +75,7 @@ namespace DICUI
|
||||
this.AddPlaceholders = GetBooleanSetting(configFile, "AddPlaceholders", true);
|
||||
this.PromptForDiscInformation = GetBooleanSetting(configFile, "PromptForDiscInformation", true);
|
||||
this.IgnoreFixedDrives = GetBooleanSetting(configFile, "IgnoreFixedDrives", false);
|
||||
this.ResetDriveAfterDump = GetBooleanSetting(configFile, "ResetDriveAfterDump", false);
|
||||
|
||||
this.Username = GetStringSetting(configFile, "Username", "");
|
||||
this.Password = GetStringSetting(configFile, "Password", "");
|
||||
|
||||
@@ -59,6 +59,12 @@ namespace DICUI
|
||||
set { _options.IgnoreFixedDrives = value; }
|
||||
}
|
||||
|
||||
public bool ResetDriveAfterDump
|
||||
{
|
||||
get { return _options.ResetDriveAfterDump; }
|
||||
set { _options.ResetDriveAfterDump = value; }
|
||||
}
|
||||
|
||||
public bool SkipMediaTypeDetection
|
||||
{
|
||||
get { return _options.SkipMediaTypeDetection; }
|
||||
|
||||
@@ -105,6 +105,12 @@ namespace DICUI.Windows
|
||||
ViewModels.LoggerViewModel.VerboseLogLn($"Ejecting disc in drive {_env.Drive.Letter}");
|
||||
_env.EjectDisc();
|
||||
}
|
||||
|
||||
if (_options.ResetDriveAfterDump)
|
||||
{
|
||||
ViewModels.LoggerViewModel.VerboseLogLn($"Resetting drive {_env.Drive.Letter}");
|
||||
_env.ResetDrive();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -510,7 +516,9 @@ namespace DICUI.Windows
|
||||
if (result)
|
||||
{
|
||||
// Verify dump output and save it
|
||||
result = _env.VerifyAndSaveDumpOutput(progress, EjectWhenDoneCheckBox.IsChecked,
|
||||
result = _env.VerifyAndSaveDumpOutput(progress,
|
||||
EjectWhenDoneCheckBox.IsChecked,
|
||||
_options.ResetDriveAfterDump,
|
||||
(si) =>
|
||||
{
|
||||
// lazy initialization
|
||||
|
||||
@@ -137,6 +137,12 @@
|
||||
IsChecked="{Binding Path=IgnoreFixedDrives}"
|
||||
ToolTip="Ignore hard drives and other fixed drives" Margin="0,4"
|
||||
/>
|
||||
|
||||
<CheckBox Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" Content="Reset After Dump"
|
||||
DataContext="{Binding Source={x:Static local:ViewModels.OptionsViewModel}}"
|
||||
IsChecked="{Binding Path=ResetDriveAfterDump}"
|
||||
ToolTip="Reset disc drives after dumping; useful for some older machines" Margin="0,4"
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
</GroupBox>
|
||||
|
||||
Reference in New Issue
Block a user