Add dumping program selection to main UI (#479)

* Add dumping program selection to main UI

* Fix program dropdown

* Fix lingering location

* Final changes
This commit is contained in:
Matt Nadareski
2023-04-11 11:15:53 -04:00
committed by GitHub
parent a368afc14a
commit 01a69ef9b3
10 changed files with 70 additions and 14 deletions

View File

@@ -21,6 +21,7 @@
- Add PIC models for BD (unused)
- Handle PIC based on disc type
- UMDs always have "2 layers"
- Add dumping program selection to main UI
### 2.5 (2023-03-12)

View File

@@ -59,7 +59,7 @@ namespace MPF.Check
if (!string.IsNullOrWhiteSpace(path))
drive = Drive.Create(null, path);
var env = new DumpEnvironment(options, filepath, drive, knownSystem, mediaType, null);
var env = new DumpEnvironment(options, filepath, drive, knownSystem, mediaType, internalProgram: null, parameters: null);
// Finally, attempt to do the output dance
var result = env.VerifyAndSaveDumpOutput(resultProgress, protectionProgress).ConfigureAwait(false).GetAwaiter().GetResult();

View File

@@ -98,7 +98,6 @@ namespace MPF.Core.Converters
if (!LongNameMethods.TryGetValue(sourceType, out MethodInfo method))
{
method = typeof(RedumpLib.Data.Extensions).GetMethod("LongName", new[] { typeof(Nullable<>).MakeGenericType(sourceType) });
if (method == null)
method = typeof(EnumConverter).GetMethod("LongName", new[] { typeof(Nullable<>).MakeGenericType(sourceType) });

View File

@@ -42,6 +42,11 @@ namespace MPF.Library
/// </summary>
public MediaType? Type { get; private set; }
/// <summary>
/// Currently selected dumping program
/// </summary>
public InternalProgram InternalProgram { get; private set; }
/// <summary>
/// Options object representing user-defined options
/// </summary>
@@ -86,12 +91,14 @@ namespace MPF.Library
/// <param name="drive"></param>
/// <param name="system"></param>
/// <param name="type"></param>
/// <param name="internalProgram"></param>
/// <param name="parameters"></param>
public DumpEnvironment(Options options,
string outputPath,
Drive drive,
RedumpSystem? system,
MediaType? type,
InternalProgram? internalProgram,
string parameters)
{
// Set options object
@@ -104,6 +111,7 @@ namespace MPF.Library
this.Drive = drive;
this.System = system ?? options.DefaultSystem;
this.Type = type ?? MediaType.NONE;
this.InternalProgram = internalProgram ?? options.InternalProgram;
// Dumping program
SetParameters(parameters);
@@ -154,7 +162,7 @@ namespace MPF.Library
/// <param name="parameters">String representation of the parameters</param>
public void SetParameters(string parameters)
{
switch (Options.InternalProgram)
switch (this.InternalProgram)
{
// Dumping support
case InternalProgram.Aaru:
@@ -212,7 +220,7 @@ namespace MPF.Library
return null;
// Set the proper parameters
switch (Options.InternalProgram)
switch (this.InternalProgram)
{
case InternalProgram.Aaru:
Parameters = new Modules.Aaru.Parameters(System, Type, Drive.Letter, this.OutputPath, driveSpeed, Options);
@@ -283,10 +291,10 @@ namespace MPF.Library
}
// Execute internal tool
progress?.Report(Result.Success($"Executing {Options.InternalProgram}... {(Options.ToolsInSeparateWindow ? "please wait!" : "see log for output!")}"));
progress?.Report(Result.Success($"Executing {this.InternalProgram}... {(Options.ToolsInSeparateWindow ? "please wait!" : "see log for output!")}"));
Directory.CreateDirectory(Path.GetDirectoryName(this.OutputPath));
await Task.Run(() => Parameters.ExecuteInternalProgram(Options.ToolsInSeparateWindow));
progress?.Report(Result.Success($"{Options.InternalProgram} has finished!"));
progress?.Report(Result.Success($"{this.InternalProgram} has finished!"));
// Execute additional tools
progress?.Report(Result.Success("Running any additional tools... see log for output!"));
@@ -350,7 +358,7 @@ namespace MPF.Library
}
// Reset the drive automatically if configured to
if (Options.InternalProgram == InternalProgram.DiscImageCreator && Options.DICResetDriveAfterDump)
if (this.InternalProgram == InternalProgram.DiscImageCreator && Options.DICResetDriveAfterDump)
{
resultProgress?.Report(Result.Success($"Resetting drive {Drive.Letter}"));
await ResetDrive();

View File

@@ -24,7 +24,7 @@ namespace MPF.Test.Library
? Drive.Create(InternalDriveType.Floppy, letter.ToString())
: Drive.Create(InternalDriveType.Optical, letter.ToString());
var env = new DumpEnvironment(options, string.Empty, drive, RedumpSystem.IBMPCcompatible, mediaType, parameters);
var env = new DumpEnvironment(options, string.Empty, drive, RedumpSystem.IBMPCcompatible, mediaType, null, parameters);
bool actual = env.ParametersValid();
Assert.Equal(expected, actual);

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using MPF.Library;
using RedumpLib.Data;
using Xunit;
@@ -58,6 +59,9 @@ namespace MPF.Test.Library
[InlineData("superhero\\blah&foo.bin", "superhero\\blah&foo.bin")]
public void NormalizeOutputPathsTest(string outputPath, string expectedPath)
{
if (!string.IsNullOrWhiteSpace(expectedPath))
expectedPath = Path.GetFullPath(expectedPath);
string actualPath = InfoTool.NormalizeOutputPaths(outputPath);
Assert.Equal(expectedPath, actualPath);
}

View File

@@ -51,6 +51,11 @@ namespace MPF.UI.ViewModels
/// </summary>
public List<RedumpSystemComboBoxItem> Systems { get; set; } = RedumpSystemComboBoxItem.GenerateElements().ToList();
/// <summary>
/// List of available internal programs
/// </summary>
public List<Element<InternalProgram>> InternalPrograms { get; set; } = new List<Element<InternalProgram>>();
#endregion
#region Private Event Flags
@@ -161,7 +166,7 @@ namespace MPF.UI.ViewModels
/// <summary>
/// Populate media type according to system type
/// </summary>
public void PopulateMediaType()
private void PopulateMediaType()
{
RedumpSystem? currentSystem = App.Instance.SystemTypeComboBox.SelectedItem as RedumpSystemComboBoxItem;
@@ -186,6 +191,27 @@ namespace MPF.UI.ViewModels
App.Instance.UpdateLayout();
}
/// <summary>
/// Populate media type according to system type
/// </summary>
private void PopulateInternalPrograms()
{
// Get the current internal program
InternalProgram internalProgram = App.Options.InternalProgram;
// Create a static list of supported programs, not everything
var internalPrograms = new List<InternalProgram> { InternalProgram.DiscImageCreator, InternalProgram.Aaru, InternalProgram.Redumper, InternalProgram.DD };
InternalPrograms = internalPrograms.Select(ip => new Element<InternalProgram>(ip)).ToList();
App.Instance.DumpingProgramComboBox.ItemsSource = InternalPrograms;
// Select the current default dumping program
int currentIndex = InternalPrograms.FindIndex(m => m == internalProgram);
App.Instance.DumpingProgramComboBox.SelectedIndex = (currentIndex > -1 ? currentIndex : 0);
// Ensure the UI gets updated
App.Instance.UpdateLayout();
}
#endregion
#region UI Commands
@@ -557,6 +583,9 @@ namespace MPF.UI.ViewModels
CacheCurrentDiscType();
SetCurrentDiscType();
// Set the dumping program
await App.Instance.Dispatcher.InvokeAsync(PopulateInternalPrograms);
// Set the initial environment and UI values
SetSupportedDriveSpeed();
Env = DetermineEnvironment();
@@ -632,6 +661,7 @@ namespace MPF.UI.ViewModels
App.Instance.MediaTypeComboBox.SelectionChanged += MediaTypeComboBoxSelectionChanged;
App.Instance.DriveLetterComboBox.SelectionChanged += DriveLetterComboBoxSelectionChanged;
App.Instance.DriveSpeedComboBox.SelectionChanged += DriveSpeedComboBoxSelectionChanged;
App.Instance.DumpingProgramComboBox.SelectionChanged += DumpingProgramComboBoxSelectionChanged;
// User Area TextChanged
App.Instance.OutputPathTextBox.TextChanged += OutputPathTextBoxTextChanged;
@@ -929,6 +959,7 @@ namespace MPF.UI.ViewModels
App.Instance.DriveLetterComboBox.SelectedItem as Drive,
App.Instance.SystemTypeComboBox.SelectedItem as RedumpSystemComboBoxItem,
App.Instance.MediaTypeComboBox.SelectedItem as Element<MediaType>,
App.Instance.DumpingProgramComboBox.SelectedItem as Element<InternalProgram>,
App.Instance.ParametersTextBox.Text);
}
@@ -1116,7 +1147,7 @@ namespace MPF.UI.ViewModels
string output = Protection.FormatProtections(protections);
// If SmartE is detected on the current disc, remove `/sf` from the flags for DIC only
if (Env.Options.InternalProgram == InternalProgram.DiscImageCreator && output.Contains("SmartE"))
if (Env.InternalProgram == InternalProgram.DiscImageCreator && output.Contains("SmartE"))
{
((Modules.DiscImageCreator.Parameters)Env.Parameters)[Modules.DiscImageCreator.FlagStrings.ScanFileProtect] = false;
App.Logger.VerboseLogLn($"SmartE detected, removing {Modules.DiscImageCreator.FlagStrings.ScanFileProtect} from parameters");
@@ -1515,6 +1546,15 @@ namespace MPF.UI.ViewModels
EnsureDiscInformation();
}
/// <summary>
/// Handler for DumpingProgramComboBox SelectionChanged event
/// </summary>
private void DumpingProgramComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (_canExecuteSelectionChanged)
EnsureDiscInformation();
}
/// <summary>
/// Handler for EnableParametersCheckBox Click event
/// </summary>

View File

@@ -119,6 +119,7 @@
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label x:Name="SystemMediaTypeLabel" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Content="System/Media Type" />
@@ -152,9 +153,12 @@
<Label x:Name="DriveSpeedLabel" Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" Content="Drive Speed"/>
<ComboBox x:Name="DriveSpeedComboBox" Grid.Row="3" Grid.Column="1" Height="22" Width="60" HorizontalAlignment="Left" Style="{DynamicResource CustomComboBoxStyle}" />
<Label x:Name="ParametersLabel" Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" Content="Parameters"/>
<TextBox x:Name="ParametersTextBox" Grid.Row="4" Grid.Column="1" Height="22" Width="370" HorizontalAlignment="Left" IsEnabled="False" VerticalContentAlignment="Center" />
<CheckBox x:Name="EnableParametersCheckBox" Grid.Row="4" Grid.Column="1" Height="22" HorizontalAlignment="Right" IsChecked="False" />
<Label x:Name="DumpingProgramLabel" Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" Content="Dumping Program"/>
<ComboBox x:Name="DumpingProgramComboBox" Grid.Row="4" Grid.Column="1" Height="22" Width="250" HorizontalAlignment="Left" Style="{DynamicResource CustomComboBoxStyle}" />
<Label x:Name="ParametersLabel" Grid.Row="5" Grid.Column="0" VerticalAlignment="Center" Content="Parameters"/>
<TextBox x:Name="ParametersTextBox" Grid.Row="5" Grid.Column="1" Height="22" Width="370" HorizontalAlignment="Left" IsEnabled="False" VerticalContentAlignment="Center" />
<CheckBox x:Name="EnableParametersCheckBox" Grid.Row="5" Grid.Column="1" Height="22" HorizontalAlignment="Right" IsChecked="False" />
</Grid>
</GroupBox>

View File

@@ -118,7 +118,7 @@
<Button x:Name="RedumperPathButton" Grid.Row="3" Grid.Column="2" Height="22" Width="22" Content="..."
Style="{DynamicResource CustomButtonStyle}" />
<Label Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Content="Dumping Program" />
<Label Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Content="Default Dumping Program" />
<ComboBox x:Name="InternalProgramComboBox" Grid.Row="4" Grid.Column="1" Height="22" HorizontalAlignment="Stretch"
ItemsSource="{Binding InternalPrograms}" Style="{DynamicResource CustomComboBoxStyle}" />