Try to automatically populate the drive speed

This commit is contained in:
Matt Nadareski
2018-06-13 11:51:21 -07:00
parent 905bd1a7dc
commit 53a2ef227b
3 changed files with 53 additions and 6 deletions

View File

@@ -25,6 +25,7 @@
public const string ResetCommand = "reset";
public const string SubCommand = "sub";
public const string MDSCommand = "mds";
public const string DriveSpeedCommand = "ls"; // Unlisted in help text
// DIC Flags

View File

@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.IO;
using WinForms = System.Windows.Forms;
using System.Diagnostics;
using System.Threading.Tasks;
namespace DICUI
{
@@ -34,6 +35,7 @@ namespace DICUI
// Populate the list of drive speeds
PopulateDriveSpeeds();
SetSupportedDriveSpeed();
}
#region Events
@@ -59,6 +61,7 @@ namespace DICUI
private void btn_Search_Click(object sender, RoutedEventArgs e)
{
PopulateDrives();
SetSupportedDriveSpeed();
EnsureDiscInformation();
}
@@ -70,6 +73,7 @@ namespace DICUI
private void cmb_DriveLetter_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SetSupportedDriveSpeed();
GetOutputNames();
EnsureDiscInformation();
}
@@ -194,9 +198,14 @@ namespace DICUI
await Task.Run(
() =>
{
childProcess = new Process();
childProcess.StartInfo.FileName = dicPath;
childProcess.StartInfo.Arguments = parameters;
childProcess = new Process()
{
StartInfo = new ProcessStartInfo()
{
FileName = dicPath,
Arguments = parameters,
},
};
childProcess.Start();
childProcess.WaitForExit();
});
@@ -400,6 +409,42 @@ namespace DICUI
}
}
/// <summary>
/// Get the highest supported drive speed as reported by DiscImageCreator
/// </summary>
private void SetSupportedDriveSpeed()
{
string driveLetter = cmb_DriveLetter.Text;
if (String.IsNullOrWhiteSpace(driveLetter))
{
return;
}
childProcess = new Process()
{
StartInfo = new ProcessStartInfo()
{
FileName = dicPath,
Arguments = DICCommands.DriveSpeedCommand + " " + driveLetter,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
},
};
childProcess.Start();
childProcess.WaitForExit();
string output = childProcess.StandardOutput.ReadToEnd();
int index = output.IndexOf("ReadSpeedMaximum:");
string readspeed = Regex.Match(output.Substring(index), @"ReadSpeedMaximum: [0-9]+KB/sec \(([0-9]*)x\)").Groups[1].Value;
if (!Int32.TryParse(readspeed, out int speed))
{
return;
}
cmb_DriveSpeed.SelectedValue = speed;
}
#endregion
}
}

View File

@@ -1869,6 +1869,7 @@ namespace DICUI
case DICCommands.EjectCommand:
case DICCommands.CloseCommand:
case DICCommands.ResetCommand:
case DICCommands.DriveSpeedCommand:
if (!Regex.IsMatch(parts[1], @"[A-Z]:?\\?"))
{
return false;