Separated of System and Disc Type (#56)

* Split type combobox into system combobox and disc type combobox

* corrected indentation for xaml file

* fixed merge with head

* fixed format

* fixed issues for PR, added KnownSystem.CUSTOM

* removed Updater.cs which ended by error in commit

* fixed GetOuptutName() for new drive/system combobox
This commit is contained in:
Jacopo Santoni
2018-06-18 21:43:07 +02:00
committed by Matt Nadareski
parent 61ce45667b
commit 308fad3ed2
7 changed files with 158 additions and 108 deletions

View File

@@ -116,4 +116,4 @@
public const string OptionalValue = "(OPTIONAL)";
public const string YesNoValue = "Yes/No";
}
}
}

View File

@@ -151,5 +151,7 @@
VideoCD,
#endregion
Custom = -1
}
}

View File

@@ -42,8 +42,9 @@
<RowDefinition/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" VerticalAlignment="Center">Disc Type</Label>
<ComboBox x:Name="cmb_DiscType" Grid.Row="0" Grid.Column="1" Height="22" SelectionChanged="cmb_DiscType_SelectionChanged" />
<Label Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Content="System/Disc Type"/>
<ComboBox x:Name="cmb_SystemType" Grid.Row="0" Grid.Column="1" Height="22" Width="250" HorizontalAlignment="left" SelectionChanged="cmb_SystemType_SelectionChanged" />
<ComboBox x:Name="cmb_DiscType" Grid.Row="0" Grid.Column="1" Height="22" Width="140" HorizontalAlignment="right" SelectionChanged="cmb_DiscType_SelectionChanged" />
<Label Grid.Row="1" Grid.Column="0" VerticalAlignment="Center">Output Filename</Label>
<TextBox x:Name="txt_OutputFilename" Grid.Row="1" Grid.Column="1" Height="22" TextChanged="txt_OutputFilename_TextChanged"/>
@@ -53,7 +54,7 @@
<Button x:Name="btn_OutputDirectoryBrowse" Grid.Row="2" Grid.Column="1" Height="22" Width="50" HorizontalAlignment="Right" Content="Browse" Click="btn_OutputDirectoryBrowse_Click"/>
<Label Grid.Row="3" Grid.Column="0" VerticalAlignment="Center">Drive Letter</Label>
<ComboBox x:Name="cmb_DriveLetter" Grid.Row="3" Grid.Column="1" Height="22" Width="397" HorizontalAlignment="left" SelectionChanged="cmb_DriveLetter_SelectionChanged"/>
<ComboBox x:Name="cmb_DriveLetter" Grid.Row="3" Grid.Column="1" Height="22" Width="60" HorizontalAlignment="left" SelectionChanged="cmb_DriveLetter_SelectionChanged" Margin="0,8,0,7"/>
<Label Grid.Row="4" Grid.Column="0" VerticalAlignment="Center">Drive Speed</Label>
<ComboBox x:Name="cmb_DriveSpeed" Grid.Row="4" Grid.Column="1" Height="22" Width="60" HorizontalAlignment="left" SelectionChanged="cmb_DriveSpeed_SelectionChanged"/>

View File

@@ -24,7 +24,8 @@ namespace DICUI
// Private UI-related variables
private List<Tuple<char, string, bool>> _drives { get; set; }
private List<int> _driveSpeeds { get { return new List<int> { 1, 2, 3, 4, 6, 8, 12, 16, 20, 24, 32, 40, 44, 48, 52, 56, 72 }; } }
private List<Tuple<string, KnownSystem?, DiscType?>> _systems { get; set; }
private List<Tuple<string, KnownSystem?>> _systems { get; set; }
private List<Tuple<string, DiscType?>> _discTypes { get; set; }
private Process childProcess { get; set; }
private Window childWindow { get; set; }
@@ -79,7 +80,14 @@ namespace DICUI
EnsureDiscInformation();
}
private void cmb_DiscType_SelectionChanged(object sender, SelectionChangedEventArgs e)
private void cmb_SystemType_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
GetOutputNames();
PopulateDiscTypeAccordingToChosenSystem();
EnsureDiscInformation();
}
private void cmb_DiscType_SelectionChanged(object sencder, SelectionChangedEventArgs e)
{
GetOutputNames();
EnsureDiscInformation();
@@ -133,16 +141,48 @@ namespace DICUI
#region Helpers
/// <summary>
/// Populate disc type according to system type
private void PopulateDiscTypeAccordingToChosenSystem()
{
cmb_DiscType.SelectedIndex = -1;
var currentSystem = cmb_SystemType.SelectedItem as Tuple<string, KnownSystem?>;
if (currentSystem != null)
{
List<Tuple<string, DiscType?>> allowedDiscTypesForSystem = Utilities.Validation.GetValidDiscTypes(currentSystem.Item2)
.ConvertAll(d => Tuple.Create(Utilities.Converters.DiscTypeToString(d), d));
cmb_DiscType.ItemsSource = allowedDiscTypesForSystem;
cmb_DiscType.DisplayMemberPath = "Item1";
cmb_DiscType.IsEnabled = allowedDiscTypesForSystem.Count > 1;
if (!cmb_DiscType.IsEnabled)
cmb_DiscType.SelectedIndex = 0;
}
else
{
cmb_DiscType.IsEnabled = false;
cmb_DiscType.ItemsSource = null;
cmb_DiscType.SelectedIndex = 0;
}
}
/// </summary>
/// <summary>
/// Get a complete list of supported systems and fill the combo box
/// </summary>
private void PopulateSystems()
{
_systems = Utilities.Validation.CreateListOfSystems();
cmb_DiscType.ItemsSource = _systems;
cmb_DiscType.DisplayMemberPath = "Item1";
cmb_DiscType.SelectedIndex = 0;
cmb_DiscType_SelectionChanged(null, null);
_discTypes = Utilities.Validation.CreateListOfDiscTypesForKnownSystems(_systems.ConvertAll(s => s.Item2));
cmb_SystemType.ItemsSource = _systems;
cmb_SystemType.DisplayMemberPath = "Item1";
cmb_SystemType.SelectedIndex = 0;
cmb_SystemType_SelectionChanged(null, null);
btn_StartStop.IsEnabled = false;
}
@@ -210,7 +250,7 @@ namespace DICUI
string outputDirectory = txt_OutputDirectory.Text;
string outputFilename = txt_OutputFilename.Text;
var selected = cmb_DiscType.SelectedValue as Tuple<string, KnownSystem?, DiscType?>;
var selected = cmb_SystemType.SelectedValue as Tuple<string, KnownSystem?, DiscType?>;
string systemName = selected.Item1;
KnownSystem? system = selected.Item2;
DiscType? type = selected.Item3;
@@ -228,7 +268,7 @@ namespace DICUI
}
// If we have a custom configuration, we need to extract the best possible information from it
if (systemName == "Custom Input" && system == KnownSystem.NONE && type == DiscType.NONE)
if (system == KnownSystem.Custom)
{
Utilities.Validation.DetermineFlags(customParameters, out type, out system, out string letter, out string path);
driveLetter = letter[0];
@@ -446,54 +486,65 @@ namespace DICUI
/// </summary>
private void EnsureDiscInformation()
{
// If we're on a separator, go to the next item
var tuple = cmb_DiscType.SelectedItem as Tuple<string, KnownSystem?, DiscType?>;
if (tuple.Item2 == null && tuple.Item3 == null)
{
cmb_DiscType.SelectedIndex++;
tuple = cmb_DiscType.SelectedItem as Tuple<string, KnownSystem?, DiscType?>;
}
var systemTuple = cmb_SystemType.SelectedItem as Tuple<string, KnownSystem?>;
var discTypeTuple = cmb_DiscType.SelectedItem as Tuple<string, DiscType?>;
// If we're on an unsupported type, update the status accordingly
switch (tuple.Item3)
// If we're on a separator, go to the next item
if (systemTuple.Item2 == null)
systemTuple = cmb_SystemType.Items[++cmb_SystemType.SelectedIndex] as Tuple<string, KnownSystem?>;
var selectedSystem = systemTuple.Item2;
var selectedDiscType = discTypeTuple != null ? discTypeTuple.Item2 : DiscType.NONE;
// No system chosen, update status
if (selectedSystem == KnownSystem.NONE)
{
case DiscType.NONE:
lbl_Status.Content = "Please select a valid disc type";
btn_StartStop.IsEnabled = false;
break;
case DiscType.GameCubeGameDisc:
case DiscType.GDROM:
lbl_Status.Content = string.Format("{0} discs are partially supported by DIC", Converters.DiscTypeToString(tuple.Item3));
btn_StartStop.IsEnabled = (_drives.Count > 0 ? true : false);
break;
case DiscType.HDDVD:
case DiscType.UMD:
case DiscType.WiiOpticalDisc:
case DiscType.WiiUOpticalDisc:
lbl_Status.Content = string.Format("{0} discs are not currently supported by DIC", Converters.DiscTypeToString(tuple.Item3));
btn_StartStop.IsEnabled = false;
break;
case DiscType.DVD5:
case DiscType.DVD9:
if (tuple.Item2 == KnownSystem.MicrosoftXBOX360XDG3)
{
lbl_Status.Content = string.Format("{0} discs are not currently supported by DIC", Converters.DiscTypeToString(tuple.Item3));
lbl_Status.Content = "Please select a valid system";
btn_StartStop.IsEnabled = false;
}
else if (selectedSystem != KnownSystem.Custom)
{
// If we're on an unsupported type, update the status accordingly
switch (selectedDiscType)
{
case DiscType.NONE:
lbl_Status.Content = "Please select a valid disc type";
btn_StartStop.IsEnabled = false;
}
else
{
lbl_Status.Content = string.Format("{0} ready to dump", Converters.DiscTypeToString(tuple.Item3));
break;
case DiscType.GameCubeGameDisc:
case DiscType.GDROM:
lbl_Status.Content = string.Format("{0} discs are partially supported by DIC", discTypeTuple.Item1);
btn_StartStop.IsEnabled = (_drives.Count > 0 ? true : false);
}
break;
default:
lbl_Status.Content = string.Format("{0} ready to dump", Converters.DiscTypeToString(tuple.Item3));
btn_StartStop.IsEnabled = (_drives.Count > 0 ? true : false);
break;
break;
case DiscType.HDDVD:
case DiscType.UMD:
case DiscType.WiiOpticalDisc:
case DiscType.WiiUOpticalDisc:
lbl_Status.Content = string.Format("{0} discs are not currently supported by DIC", discTypeTuple.Item1);
btn_StartStop.IsEnabled = false;
break;
case DiscType.DVD5:
case DiscType.DVD9:
if (selectedSystem == KnownSystem.MicrosoftXBOX360XDG3)
{
lbl_Status.Content = string.Format("{0} discs are not currently supported by DIC", discTypeTuple.Item1);
btn_StartStop.IsEnabled = false;
}
else
{
lbl_Status.Content = string.Format("{0} ready to dump", discTypeTuple.Item1);
btn_StartStop.IsEnabled = (_drives.Count > 0 ? true : false);
}
break;
default:
lbl_Status.Content = string.Format("{0} ready to dump", discTypeTuple.Item1);
btn_StartStop.IsEnabled = (_drives.Count > 0 ? true : false);
break;
}
}
// If we're in a type that doesn't support drive speeds
switch (tuple.Item3)
switch (selectedDiscType)
{
case DiscType.Floppy:
case DiscType.BD25:
@@ -501,9 +552,9 @@ namespace DICUI
cmb_DriveSpeed.IsEnabled = false;
break;
default:
if (tuple.Item2 == KnownSystem.MicrosoftXBOX
|| tuple.Item2 == KnownSystem.MicrosoftXBOX360XDG2
|| tuple.Item2 == KnownSystem.MicrosoftXBOX360XDG3)
if (selectedSystem == KnownSystem.MicrosoftXBOX
|| selectedSystem == KnownSystem.MicrosoftXBOX360XDG2
|| selectedSystem == KnownSystem.MicrosoftXBOX360XDG3)
{
cmb_DriveSpeed.IsEnabled = false;
}
@@ -515,7 +566,7 @@ namespace DICUI
}
// Special case for Custom input
if (tuple.Item1 == "Custom Input" && tuple.Item2 == KnownSystem.NONE && tuple.Item3 == DiscType.NONE)
if (selectedSystem == KnownSystem.Custom)
{
txt_Parameters.IsEnabled = true;
txt_OutputFilename.IsEnabled = false;
@@ -535,28 +586,25 @@ namespace DICUI
cmb_DriveLetter.IsEnabled = true;
// Populate with the correct params for inputs (if we're not on the default option)
if (cmb_DiscType.SelectedIndex > 0)
if (selectedSystem != KnownSystem.NONE && selectedDiscType != DiscType.NONE)
{
var selected = cmb_DiscType.SelectedValue as Tuple<string, KnownSystem?, DiscType?>;
var driveletter = cmb_DriveLetter.SelectedValue as Tuple<char, string, bool>;
// If either item is invalid, skip this
if (selected == null || driveletter == null)
{
// If drive letter is invalid, skip this
if (driveletter == null)
return;
}
string discType = Converters.KnownSystemAndDiscTypeToBaseCommand(selected.Item2, selected.Item3);
List<string> defaultParams = Converters.KnownSystemAndDiscTypeToParameters(selected.Item2, selected.Item3);
string discType = Converters.KnownSystemAndDiscTypeToBaseCommand(selectedSystem, selectedDiscType);
List<string> defaultParams = Converters.KnownSystemAndDiscTypeToParameters(selectedSystem, selectedDiscType);
txt_Parameters.Text = discType
+ " " + driveletter.Item1
+ " \"" + Path.Combine(txt_OutputDirectory.Text, txt_OutputFilename.Text) + "\" "
+ (selected.Item3 != DiscType.Floppy
&& selected.Item3 != DiscType.BD25
&& selected.Item3 != DiscType.BD50
&& selected.Item2 != KnownSystem.MicrosoftXBOX
&& selected.Item2 != KnownSystem.MicrosoftXBOX360XDG2
&& selected.Item2 != KnownSystem.MicrosoftXBOX360XDG3
+ (selectedDiscType != DiscType.Floppy
&& selectedDiscType != DiscType.BD25
&& selectedDiscType != DiscType.BD50
&& selectedSystem != KnownSystem.MicrosoftXBOX
&& selectedSystem != KnownSystem.MicrosoftXBOX360XDG2
&& selectedSystem != KnownSystem.MicrosoftXBOX360XDG3
? (int)cmb_DriveSpeed.SelectedItem + " " : "")
+ string.Join(" ", defaultParams);
}
@@ -569,12 +617,13 @@ namespace DICUI
private void GetOutputNames()
{
var driveTuple = cmb_DriveLetter.SelectedItem as Tuple<char, string, bool>;
var discTuple = cmb_DiscType.SelectedItem as Tuple<string, KnownSystem?, DiscType?>;
var systemTuple = cmb_SystemType.SelectedItem as Tuple<string, KnownSystem?>;
var discTuple = cmb_DiscType.SelectedItem as Tuple<string, DiscType?>;
if (driveTuple != null && discTuple != null)
if (driveTuple != null && systemTuple != null && discTuple != null)
{
txt_OutputDirectory.Text = Path.Combine(defaultOutputPath, driveTuple.Item2);
txt_OutputFilename.Text = driveTuple.Item2 + Converters.DiscTypeToExtension(discTuple.Item3);
txt_OutputFilename.Text = driveTuple.Item2 + Converters.DiscTypeToExtension(discTuple.Item2);
}
else
{

View File

@@ -498,10 +498,13 @@ namespace DICUI.Utilities
#endregion
case KnownSystem.Custom:
return "Custom Input";
case KnownSystem.NONE:
default:
return "Unknown";
}
}
}
}
}

View File

@@ -619,7 +619,7 @@ namespace DICUI.Utilities
{
byte[] sub = new byte[16];
Array.Copy(headerBytes, ptr, sub, 0, 16);
headerString += ptr.ToString("X").PadLeft(4, '0') + " : "
headerString += ptr.ToString("X").PadLeft(4, '0') + " : "
+ BitConverter.ToString(sub).Replace("-", " ") + " "
+ Encoding.ASCII.GetString(sub) + "\n";
ptr += 16;
@@ -830,7 +830,7 @@ namespace DICUI.Utilities
break;
}
output.Add(Template.BarcodeField + ": " + info[Template.BarcodeField]);
switch(sys)
switch (sys)
{
case KnownSystem.AppleMacintosh:
case KnownSystem.IBMPCCompatible:
@@ -950,4 +950,4 @@ namespace DICUI.Utilities
return true;
}
}
}
}

View File

@@ -17,7 +17,7 @@ namespace DICUI.Utilities
public static List<DiscType?> GetValidDiscTypes(KnownSystem? sys)
{
List<DiscType?> types = new List<DiscType?>();
switch (sys)
{
#region Consoles
@@ -405,12 +405,11 @@ namespace DICUI.Utilities
/// This returns a List of Tuples whose structure is as follows:
/// Item 1: Printable name
/// Item 2: KnownSystem mapping
/// Item 3: DiscType mapping
/// If something has a "string, null, null" value, it should be assumed that it is a separator
/// If something has a "string, null" value, it should be assumed that it is a separator
/// </remarks>
public static List<Tuple<string, KnownSystem?, DiscType?>> CreateListOfSystems()
public static List<Tuple<string, KnownSystem?>> CreateListOfSystems()
{
List<Tuple<string, KnownSystem?, DiscType?>> mapping = new List<Tuple<string, KnownSystem?, DiscType?>>();
List<Tuple<string, KnownSystem?>> mapping = new List<Tuple<string, KnownSystem?>>();
foreach (KnownSystem system in Enum.GetValues(typeof(KnownSystem)))
{
@@ -419,49 +418,45 @@ namespace DICUI.Utilities
{
// Consoles section
case KnownSystem.BandaiPlaydiaQuickInteractiveSystem:
mapping.Add(new Tuple<string, KnownSystem?, DiscType?>("---------- Consoles ----------", null, null));
mapping.Add(new Tuple<string, KnownSystem?>("---------- Consoles ----------", null));
break;
// Computers section
case KnownSystem.AcornArchimedes:
mapping.Add(new Tuple<string, KnownSystem?, DiscType?>("---------- Computers ----------", null, null));
mapping.Add(new Tuple<string, KnownSystem?>("---------- Computers ----------", null));
break;
// Arcade section
case KnownSystem.AmigaCUBOCD32:
mapping.Add(new Tuple<string, KnownSystem?, DiscType?>("---------- Arcade ----------", null, null));
mapping.Add(new Tuple<string, KnownSystem?>("---------- Arcade ----------", null));
break;
// Other section
case KnownSystem.AudioCD:
mapping.Add(new Tuple<string, KnownSystem?, DiscType?>("---------- Others ----------", null, null));
mapping.Add(new Tuple<string, KnownSystem?>("---------- Others ----------", null));
break;
}
// First, get a list of all DiscTypes for a given KnownSystem
List<DiscType?> types = GetValidDiscTypes(system);
// If we have a single type, we don't want to postfix the system name with it
if (types.Count == 1)
{
mapping.Add(new Tuple<string, KnownSystem?, DiscType?>(Converters.KnownSystemToString(system), system, types[0]));
}
// Otherwise, postfix the system name properly
else
{
foreach (DiscType type in types)
{
mapping.Add(new Tuple<string, KnownSystem?, DiscType?>(Converters.KnownSystemToString(system) + " (" + Converters.DiscTypeToString(type) + ")", system, type));
}
}
mapping.Add(new Tuple<string, KnownSystem?>(Converters.KnownSystemToString(system), system));
}
// Add final mapping for "Custom"
mapping.Add(new Tuple<string, KnownSystem?, DiscType?>("Custom Input", KnownSystem.NONE, DiscType.NONE));
return mapping;
}
/// <summary>
/// Create a list of all actually used DiskTypes for current Knownystem list
/// </summary>
public static List<Tuple<string, DiscType?>> CreateListOfDiscTypesForKnownSystems(List<KnownSystem?> systems)
{
return systems
.ConvertAll(s => GetValidDiscTypes(s))
.SelectMany(d => d)
.Distinct()
.Select(d => Tuple.Create(Converters.DiscTypeToString(d), d))
.OrderBy(t => t.Item1)
.ToList();
}
/// <summary>
/// Create a list of active optical drives matched to their volume labels
/// </summary>
@@ -713,7 +708,7 @@ namespace DICUI.Utilities
{
for (int i = index; i < parts.Count; i++)
{
switch(parts[i])
switch (parts[i])
{
case DICFlags.DisableBeep:
if (parts[0] != DICCommands.CompactDisc
@@ -819,7 +814,7 @@ namespace DICUI.Utilities
{
return false;
}
// If the next item doesn't exist, it's good
if (!DoesNextExist(parts, i))
{