Add initial type dectection, hopefully fixes #145

This commit is contained in:
Matt Nadareski
2019-06-17 14:36:54 -07:00
parent b2185dbed9
commit 44b91a6611
5 changed files with 107 additions and 15 deletions

View File

@@ -734,14 +734,14 @@ namespace DICUI.Utilities
}
/// <summary>
/// Get the current disc type from drive letter
/// Get the current media type from drive letter
/// </summary>
/// <param name="driveLetter"></param>
/// <returns></returns>
/// <remarks>
/// https://stackoverflow.com/questions/11420365/detecting-if-disc-is-in-dvd-drive
/// </remarks>
public static MediaType? GetDiscType(char? driveLetter)
public static MediaType? GetMediaType(char? driveLetter)
{
// Get the DeviceID from the current drive letter
string deviceId = null;
@@ -798,6 +798,74 @@ namespace DICUI.Utilities
return null;
}
/// <summary>
/// Get the current system from drive letter
/// </summary>
/// <param name="driveLetter"></param>
/// <returns></returns>
public static KnownSystem? GetKnownSystem(char? driveLetter)
{
// If no letter is provided, then we can't do anything
if (driveLetter == null)
return null;
string drivePath = $"{driveLetter}:\\";
// If we can't read the media in that drive, we can't do anything
if (!Directory.Exists(drivePath))
return null;
// Sega Dreamcast
if (File.Exists(Path.Combine(drivePath, "IP.BIN")))
{
return KnownSystem.SegaDreamcast;
}
// Sega Mega-CD / Sega-CD
if (File.Exists(Path.Combine(drivePath, "_BOOT", "IP.BIN"))
|| File.Exists(Path.Combine(drivePath, "_BOOT", "SP.BIN"))
|| File.Exists(Path.Combine(drivePath, "_BOOT", "SP_AS.BIN"))
|| File.Exists(Path.Combine(drivePath, "FILESYSTEM.BIN")))
{
return KnownSystem.SegaCDMegaCD;
}
// Sony PlayStation and Sony PlayStation 2
if (File.Exists(Path.Combine(drivePath, "SYSTEM.CNF")))
{
// Check for either BOOT or BOOT2
using (StreamReader reader = File.OpenText(Path.Combine(drivePath, "SYSTEM.CNF")))
{
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
if (line.Contains("BOOT2"))
return KnownSystem.SonyPlayStation2;
else if (line.Contains("BOOT"))
return KnownSystem.SonyPlayStation;
}
}
// If we have a weird disc, just assume PS1
return KnownSystem.SonyPlayStation;
}
// Sony PlayStation 4
if (File.Exists(Path.Combine(drivePath, "PSLogo.ico")))
{
return KnownSystem.SonyPlayStation4;
}
// V.Tech V.Flash / V.Smile Pro
if (File.Exists(Path.Combine(drivePath, "0SYSTEM")))
{
return KnownSystem.VTechVFlashVSmilePro;
}
// Default return
return KnownSystem.NONE;
}
/// <summary>
/// Verify that, given a system and a media type, they are correct
/// </summary>

View File

@@ -11,6 +11,7 @@
<add key="ParanoidMode" value="false"/>
<add key="ScanForProtection" value="true"/>
<add key="SkipMediaTypeDetection" value="false"/>
<add key="SkipSystemDetection" value="false"/>
<add key="RereadAmountForC2" value="20"/>
<add key="VerboseLogging" value="true"/>
<add key="OpenLogWindowAtStartup" value="true"/>

View File

@@ -23,6 +23,7 @@ namespace DICUI
public bool AddPlaceholders { get; set; }
public bool SkipMediaTypeDetection { get; set; }
public bool SkipSystemDetection { get; set; }
public bool VerboseLogging { get; set; }
public bool OpenLogWindowAtStartup { get; set; }
@@ -64,6 +65,7 @@ namespace DICUI
this.ParanoidMode = GetBooleanSetting(configFile, "ParanoidMode", false);
this.ScanForProtection = GetBooleanSetting(configFile, "ScanForProtection", true);
this.SkipMediaTypeDetection = GetBooleanSetting(configFile, "SkipMediaTypeDetection", false);
this.SkipSystemDetection = GetBooleanSetting(configFile, "SkipSystemDetection", false);
this.RereadAmountForC2 = GetInt32Setting(configFile, "RereadAmountForC2", 20);
this.VerboseLogging = GetBooleanSetting(configFile, "VerboseLogging", true);
this.OpenLogWindowAtStartup = GetBooleanSetting(configFile, "OpenLogWindowAtStartup", true);

View File

@@ -37,6 +37,12 @@ namespace DICUI
set { _options.SkipMediaTypeDetection = value; }
}
public bool SkipSystemDetection
{
get { return _options.SkipSystemDetection; }
set { _options.SkipSystemDetection = value; }
}
public string RereadAmountForC2
{
get { return Convert.ToString(_options.RereadAmountForC2); }

View File

@@ -16,7 +16,7 @@ namespace DICUI.Windows
// Private UI-related variables
private List<Drive> _drives;
private MediaType? _currentMediaType;
private List<KnownSystem?> _systems;
private List<KnownSystemComboBoxItem> _systems;
private List<MediaType?> _mediaTypes;
private bool _alreadyShown;
@@ -282,11 +282,11 @@ namespace DICUI.Windows
/// </summary>
private void PopulateSystems()
{
_systems = Validators.CreateListOfSystems();
var knownSystems = Validators.CreateListOfSystems();
ViewModels.LoggerViewModel.VerboseLogLn("Populating systems, {0} systems found.", _systems.Count);
ViewModels.LoggerViewModel.VerboseLogLn("Populating systems, {0} systems found.", knownSystems.Count);
Dictionary<KnownSystemCategory, List<KnownSystem?>> mapping = _systems
Dictionary<KnownSystemCategory, List<KnownSystem?>> mapping = knownSystems
.GroupBy(s => s.Category())
.ToDictionary(
k => k.Key,
@@ -295,17 +295,16 @@ namespace DICUI.Windows
.ToList()
);
List<KnownSystemComboBoxItem> comboBoxItems = new List<KnownSystemComboBoxItem>();
comboBoxItems.Add(new KnownSystemComboBoxItem(KnownSystem.NONE));
_systems = new List<KnownSystemComboBoxItem>();
_systems.Add(new KnownSystemComboBoxItem(KnownSystem.NONE));
foreach (var group in mapping)
{
comboBoxItems.Add(new KnownSystemComboBoxItem(group.Key));
group.Value.ForEach(system => comboBoxItems.Add(new KnownSystemComboBoxItem(system)));
_systems.Add(new KnownSystemComboBoxItem(group.Key));
group.Value.ForEach(system => _systems.Add(new KnownSystemComboBoxItem(system)));
}
SystemTypeComboBox.ItemsSource = comboBoxItems;
SystemTypeComboBox.ItemsSource = _systems;
SystemTypeComboBox.SelectedIndex = 0;
StartStopButton.IsEnabled = false;
@@ -331,8 +330,24 @@ namespace DICUI.Windows
int index = _drives.FindIndex(d => d.MarkedActive);
DriveLetterComboBox.SelectedIndex = (index != -1 ? index : 0);
StatusLabel.Content = "Valid drive found! Choose your Media Type";
StartStopButton.IsEnabled = true;
CopyProtectScanButton.IsEnabled = true;
CopyProtectScanButton.IsEnabled = true;
// Get the current optical disc type
if (!_options.SkipSystemDetection && index != -1)
{
ViewModels.LoggerViewModel.VerboseLog("Trying to detect system for drive {0}.. ", _drives[index].Letter);
var currentSystem = Validators.GetKnownSystem(_drives[index].Letter);
ViewModels.LoggerViewModel.VerboseLogLn(currentSystem == null || currentSystem == KnownSystem.NONE ? "unable to detect." : ("detected " + currentSystem.LongName() + "."));
if (currentSystem != null && currentSystem != KnownSystem.NONE)
{
int sysIndex = _systems.FindIndex(s => s == currentSystem);
SystemTypeComboBox.SelectedIndex = sysIndex;
}
}
// Only enable the start/stop if we don't have the default selected
StartStopButton.IsEnabled = (SystemTypeComboBox.SelectedItem as KnownSystemComboBoxItem) != KnownSystem.NONE;
ViewModels.LoggerViewModel.VerboseLogLn("Found {0} drives: {1}", _drives.Count, String.Join(", ", _drives.Select(d => d.Letter)));
}
@@ -631,7 +646,7 @@ namespace DICUI.Windows
if (!_options.SkipMediaTypeDetection)
{
ViewModels.LoggerViewModel.VerboseLog("Trying to detect media type for drive {0}.. ", drive.Letter);
_currentMediaType = Validators.GetDiscType(drive.Letter);
_currentMediaType = Validators.GetMediaType(drive.Letter);
ViewModels.LoggerViewModel.VerboseLogLn(_currentMediaType == null ? "unable to detect." : ("detected " + _currentMediaType.LongName() + "."));
}
}