mirror of
https://github.com/SabreTools/MPF.git
synced 2026-07-02 17:24:48 +00:00
* Allow child process to be killed (#10) * Add constants, use them, use child process more
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
namespace DICUI
|
||||
{
|
||||
public static class UIElements
|
||||
{
|
||||
public const string StartDumping = "Start Dumping";
|
||||
public const string StopDumping = "Stop Dumping";
|
||||
}
|
||||
|
||||
public static class DICCommands
|
||||
{
|
||||
// Commands
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Button x:Name="btn_Start" Grid.Row="0" Grid.Column="0" Height="22" Width="150" VerticalAlignment="Center" HorizontalAlignment="Center" Content="Start Dumping" Click="btn_Start_Click" IsEnabled="False" />
|
||||
<Button x:Name="btn_StartStop" Grid.Row="0" Grid.Column="0" Height="22" Width="150" VerticalAlignment="Center" HorizontalAlignment="Center" Content="Start Dumping" Click="btn_StartStop_Click" IsEnabled="False" />
|
||||
<Button x:Name="btn_Search" Grid.Row="0" Grid.Column="1" Height="22" Width="150" VerticalAlignment="Center" HorizontalAlignment="Center" Content="Scan for disks" Click="btn_Search_Click" />
|
||||
</Grid>
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace DICUI
|
||||
private List<Tuple<char, string>> _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 Process childProcess { get; set; }
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
@@ -37,19 +38,28 @@ namespace DICUI
|
||||
|
||||
#region Events
|
||||
|
||||
private void btn_Start_Click(object sender, RoutedEventArgs e)
|
||||
private void btn_StartStop_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
StartDumping();
|
||||
if ((string)btn_StartStop.Content == UIElements.StartDumping)
|
||||
{
|
||||
StartDumping();
|
||||
}
|
||||
else if ((string)btn_StartStop.Content == UIElements.StopDumping)
|
||||
{
|
||||
CancelDumping();
|
||||
}
|
||||
}
|
||||
|
||||
private void btn_OutputDirectoryBrowse_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
BrowseFolder();
|
||||
EnsureDiscInformation();
|
||||
}
|
||||
|
||||
private void btn_Search_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
PopulateDrives();
|
||||
EnsureDiscInformation();
|
||||
}
|
||||
|
||||
private void cmb_DiscType_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
@@ -61,6 +71,7 @@ namespace DICUI
|
||||
private void cmb_DriveLetter_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
GetOutputNames();
|
||||
EnsureDiscInformation();
|
||||
}
|
||||
|
||||
private void cmb_DriveSpeed_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
@@ -83,7 +94,7 @@ namespace DICUI
|
||||
cmb_DiscType.SelectedIndex = 0;
|
||||
cmb_DiscType_SelectionChanged(null, null);
|
||||
|
||||
btn_Start.IsEnabled = false;
|
||||
btn_StartStop.IsEnabled = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -102,12 +113,12 @@ namespace DICUI
|
||||
if (cmb_DriveLetter.Items.Count > 0)
|
||||
{
|
||||
lbl_Status.Content = "Valid optical disc found! Choose your Disc Type";
|
||||
btn_Start.IsEnabled = true;
|
||||
btn_StartStop.IsEnabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
lbl_Status.Content = "No valid optical disc found!";
|
||||
btn_Start.IsEnabled = false;
|
||||
btn_StartStop.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +154,7 @@ namespace DICUI
|
||||
string driveLetter = cmb_DriveLetter.Text;
|
||||
string outputDirectory = txt_OutputDirectory.Text;
|
||||
string outputFilename = txt_OutputFilename.Text;
|
||||
btn_Start.IsEnabled = false;
|
||||
btn_StartStop.Content = UIElements.StopDumping;
|
||||
|
||||
// Get the currently selected item
|
||||
var selected = cmb_DiscType.SelectedValue as Tuple<string, KnownSystem?, DiscType?>;
|
||||
@@ -153,7 +164,7 @@ namespace DICUI
|
||||
|| !Utilities.ValidateParameters(txt_CustomParameters.Text))
|
||||
{
|
||||
lbl_Status.Content = "Error! Current configuration is not supported!";
|
||||
btn_Start.IsEnabled = true;
|
||||
btn_StartStop.Content = UIElements.StartDumping;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -161,7 +172,7 @@ namespace DICUI
|
||||
if (!File.Exists(dicPath))
|
||||
{
|
||||
lbl_Status.Content = "Error! Could not find DiscImageCreator!";
|
||||
btn_Start.IsEnabled = true;
|
||||
btn_StartStop.Content = UIElements.StartDumping;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -172,22 +183,22 @@ namespace DICUI
|
||||
if (result == MessageBoxResult.No || result == MessageBoxResult.Cancel || result == MessageBoxResult.None)
|
||||
{
|
||||
lbl_Status.Content = "Dumping aborted!";
|
||||
btn_Start.IsEnabled = true;
|
||||
btn_StartStop.Content = UIElements.StartDumping;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
lbl_Status.Content = "Beginning dumping process";
|
||||
string parameters = txt_CustomParameters.Text;
|
||||
string parameters = txt_CustomParameters.Text;
|
||||
|
||||
await Task.Run(
|
||||
await Task.Run(
|
||||
() =>
|
||||
{
|
||||
Process process = new Process();
|
||||
process.StartInfo.FileName = dicPath;
|
||||
process.StartInfo.Arguments = parameters;
|
||||
process.Start();
|
||||
process.WaitForExit();
|
||||
childProcess = new Process();
|
||||
childProcess.StartInfo.FileName = dicPath;
|
||||
childProcess.StartInfo.Arguments = parameters;
|
||||
childProcess.Start();
|
||||
childProcess.WaitForExit();
|
||||
});
|
||||
|
||||
// Special cases
|
||||
@@ -201,7 +212,7 @@ namespace DICUI
|
||||
break;
|
||||
}
|
||||
|
||||
Process sgraw = new Process()
|
||||
childProcess = new Process()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
@@ -209,8 +220,8 @@ namespace DICUI
|
||||
Arguments = "-v -r 4100 -R " + driveLetter + ": " + "ad 01 00 00 00 00 00 00 10 04 00 00 -o \"PIC.bin\""
|
||||
},
|
||||
};
|
||||
sgraw.Start();
|
||||
sgraw.WaitForExit();
|
||||
childProcess.Start();
|
||||
childProcess.WaitForExit();
|
||||
break;
|
||||
case KnownSystem.SonyPlayStation:
|
||||
if (!File.Exists(psxtPath))
|
||||
@@ -221,7 +232,7 @@ namespace DICUI
|
||||
|
||||
// Invoke the program with all 3 configurations
|
||||
// TODO: Use these outputs for PSX information
|
||||
Process psxt001z = new Process()
|
||||
childProcess = new Process()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
@@ -229,10 +240,10 @@ namespace DICUI
|
||||
Arguments = "\"" + Utilities.GetFirstTrack(outputDirectory, outputFilename) + "\" > " + "\"" + Path.Combine(outputDirectory, "psxt001z.txt"),
|
||||
},
|
||||
};
|
||||
psxt001z.Start();
|
||||
psxt001z.WaitForExit();
|
||||
childProcess.Start();
|
||||
childProcess.WaitForExit();
|
||||
|
||||
psxt001z = new Process()
|
||||
childProcess = new Process()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
@@ -240,10 +251,10 @@ namespace DICUI
|
||||
Arguments = "--libcrypt " + "\"" + Path.Combine(outputDirectory, outputFilename + ".sub") + "\" > " + "\"" + Path.Combine(outputDirectory, "libcrypt.txt"),
|
||||
},
|
||||
};
|
||||
psxt001z.Start();
|
||||
psxt001z.WaitForExit();
|
||||
childProcess.Start();
|
||||
childProcess.WaitForExit();
|
||||
|
||||
psxt001z = new Process()
|
||||
childProcess = new Process()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
@@ -251,8 +262,8 @@ namespace DICUI
|
||||
Arguments = "--libcryptdrvfast " + driveLetter + " > " + "\"" + Path.Combine(outputDirectory, "libcryptdrv.log"),
|
||||
},
|
||||
};
|
||||
psxt001z.Start();
|
||||
psxt001z.WaitForExit();
|
||||
childProcess.Start();
|
||||
childProcess.WaitForExit();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -260,7 +271,7 @@ namespace DICUI
|
||||
if (!Utilities.FoundAllFiles(outputDirectory, outputFilename, selected.Item3))
|
||||
{
|
||||
lbl_Status.Content = "Error! Please check output directory as dump may be incomplete!";
|
||||
btn_Start.IsEnabled = true;
|
||||
btn_StartStop.Content = UIElements.StartDumping;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -270,7 +281,20 @@ namespace DICUI
|
||||
List<string> formattedValues = Utilities.FormatOutputData(templateValues, selected.Item2, selected.Item3);
|
||||
bool success = Utilities.WriteOutputData(outputDirectory, outputFilename, formattedValues);
|
||||
|
||||
btn_Start.IsEnabled = true;
|
||||
btn_StartStop.Content = UIElements.StartDumping;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancel an in-progress dumping process
|
||||
/// </summary>
|
||||
private void CancelDumping()
|
||||
{
|
||||
try
|
||||
{
|
||||
childProcess.Kill();
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -291,21 +315,21 @@ namespace DICUI
|
||||
{
|
||||
case DiscType.NONE:
|
||||
lbl_Status.Content = "Please select a valid disc type";
|
||||
btn_Start.IsEnabled = false;
|
||||
btn_StartStop.IsEnabled = false;
|
||||
break;
|
||||
case DiscType.GameCubeGameDisc:
|
||||
case DiscType.GDROM:
|
||||
lbl_Status.Content = string.Format("{0} discs are partially supported by DIC", Utilities.DiscTypeToString(tuple.Item3));
|
||||
btn_Start.IsEnabled = true;
|
||||
btn_StartStop.IsEnabled = true;
|
||||
break;
|
||||
case DiscType.HDDVD:
|
||||
case DiscType.UMD:
|
||||
lbl_Status.Content = string.Format("{0} discs are not currently supported by DIC", Utilities.DiscTypeToString(tuple.Item3));
|
||||
btn_Start.IsEnabled = true;
|
||||
btn_StartStop.IsEnabled = true;
|
||||
break;
|
||||
default:
|
||||
lbl_Status.Content = string.Format("{0} ready to dump", Utilities.DiscTypeToString(tuple.Item3));
|
||||
btn_Start.IsEnabled = true;
|
||||
btn_StartStop.IsEnabled = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user