Cleanups and mixups (#85)

Cleanups and Mixups
This commit is contained in:
Matt Nadareski
2018-07-05 16:52:34 -07:00
committed by GitHub
parent ac89f06843
commit 6d72417512
9 changed files with 340 additions and 328 deletions

View File

@@ -11,14 +11,13 @@ namespace DICUI.Test.Utilities
public void NameTest()
{
var values = (KnownSystem[])Enum.GetValues(typeof(KnownSystem));
Array.ForEach(values, system =>
foreach(var system in values)
{
string expected = Converters.KnownSystemToString(system);
string actual = ((KnownSystem?)system).Name();
Assert.Equal(expected, actual);
});
}
}
[Theory]
@@ -33,13 +32,11 @@ namespace DICUI.Test.Utilities
Assert.Equal(expected, actual);
}
[Fact]
public void IsMarkerTest()
{
var values = (KnownSystem[])Enum.GetValues(typeof(KnownSystem));
Array.ForEach(values, system =>
foreach(var system in values)
{
bool expected = system == KnownSystem.MarkerArcadeEnd || system == KnownSystem.MarkerComputerEnd ||
system == KnownSystem.MarkerOtherEnd || system == KnownSystem.MarkerConsoleEnd;
@@ -47,23 +44,18 @@ namespace DICUI.Test.Utilities
bool actual = ((KnownSystem?)system).IsMarker();
Assert.Equal(expected, actual);
});
}
}
[Fact]
public void CategoryNameNotEmptyTest()
{
var values = (KnownSystemCategory[])Enum.GetValues(typeof(KnownSystemCategory));
Array.ForEach(values, system =>
foreach (var system in values)
{
string actual = ((KnownSystem?)system).Name();
Assert.NotEqual("", actual);
});
}
}
}
}

View File

@@ -99,6 +99,7 @@
<Compile Include="UI\KnownSystemComboBoxItem.cs" />
<Compile Include="UI\AllowedSpeeds.cs" />
<Compile Include="Utilities\DumpEnvironment.cs" />
<Compile Include="Utilities\Extensions.cs" />
<Compile Include="Utilities\Validators.cs" />
<Compile Include="Utilities\Converters.cs" />
<Compile Include="OptionsWindow.xaml.cs">

View File

@@ -24,7 +24,6 @@ using System.Text;
namespace DICUI.External
{
// TODO: Add any missing protection schemes
public static class ProtectionFind
{
/// <summary>
@@ -55,6 +54,10 @@ namespace DICUI.External
if (ProtectDVDVideo(path, files))
protections[path] = "Protect DVD-Video";
// Zzxzz
if (Directory.Exists(Path.Combine(path, "Zzxzz")))
protections[path] = "Zzxzz";
// Loop through all files and scan them
foreach (string file in files)
{
@@ -196,11 +199,11 @@ namespace DICUI.External
}
// SecuROM
if ((FileContent.IndexOf("AddD" + (char)0x03 + (char)0x00 + (char)0x00 + (char)0x00)) > -1)
if ((position = FileContent.IndexOf("AddD" + (char)0x03 + (char)0x00 + (char)0x00 + (char)0x00)) > -1)
return "SecuROM " + GetSecuROM4Version(file, position);
if ((position = FileContent.IndexOf("" + (char)0xCA + (char)0xDD + (char)0xDD + (char)0xAC + (char)0x03)) > -1)
return "SecuROM " + GetSecuROM4and5Version(file, --position);
return "SecuROM " + GetSecuROM4and5Version(file, position);
if (FileContent.StartsWith(".securom" + (char)0xE0 + (char)0xC0))
return "SecuROM " + GetSecuROM7Version(file);
@@ -337,13 +340,19 @@ namespace DICUI.External
#region Textfile Content Checks
// No-op
if (extension == "txt" || extension == "rtf" || extension == "doc" || extension == "docx")
{
// No-op
}
#endregion
#region Archive Content Checks
// No-op
if (extension == "7z" || extension == "cab" || extension == "rar" || extension == "zip")
{
// No-op
}
#endregion
@@ -501,10 +510,9 @@ namespace DICUI.External
private static string GetCDDVDCopsVersion(string file, int position)
{
char[] version;
BinaryReader br = new BinaryReader(new StreamReader(file).BaseStream);
br.BaseStream.Seek(position + 15, SeekOrigin.Begin); // Begin reading after "CD-Cops, ver."
version = br.ReadChars(4);
char[] version = br.ReadChars(4);
if (version[0] == 0x00)
return "";
return new string(version);
@@ -636,21 +644,19 @@ namespace DICUI.External
private static string GetProtectDiscVersionBuild76till10(string file, int position, out int irefBuild)
{
irefBuild = 0;
byte version, subversion, versionindicatorPD9, subsubversionPD9x, subversionPD9x1, subversionPD9x2;
BinaryReader br = new BinaryReader(new StreamReader(file).BaseStream);
br.BaseStream.Seek(position + 37, SeekOrigin.Begin);
subversion = br.ReadByte();
byte subversion = br.ReadByte();
br.ReadByte();
version = br.ReadByte();
byte version = br.ReadByte();
br.BaseStream.Seek(position + 49, SeekOrigin.Begin);
irefBuild = br.ReadInt32();
br.BaseStream.Seek(position + 53, SeekOrigin.Begin);
versionindicatorPD9 = br.ReadByte();
byte versionindicatorPD9 = br.ReadByte();
br.BaseStream.Seek(position + 0x40, SeekOrigin.Begin);
subsubversionPD9x = br.ReadByte();
subversionPD9x2 = br.ReadByte();
subversionPD9x1 = br.ReadByte();
byte subsubversionPD9x = br.ReadByte();
byte subversionPD9x2 = br.ReadByte();
byte subversionPD9x1 = br.ReadByte();
br.Close();
// version 7
@@ -703,14 +709,11 @@ namespace DICUI.External
private static string GetSafeDiscVersion(string file, int position)
{
int version;
int subVersion;
int subsubVersion;
BinaryReader br = new BinaryReader(new StreamReader(file).BaseStream);
br.BaseStream.Seek(position + 20, SeekOrigin.Begin); // Begin reading after "BoG_ *90.0&!! Yy>" for old SafeDisc
version = br.ReadInt32();
subVersion = br.ReadInt32();
subsubVersion = br.ReadInt32();
int version = br.ReadInt32();
int subVersion = br.ReadInt32();
int subsubVersion = br.ReadInt32();
if (version != 0)
return version + "." + subVersion.ToString("00") + "." + subsubVersion.ToString("000");
br.BaseStream.Seek(position + 18 + 14, SeekOrigin.Begin); // Begin reading after "BoG_ *90.0&!! Yy>" for newer SafeDisc
@@ -725,58 +728,40 @@ namespace DICUI.External
private static string GetSecuROM4Version(string file, int position)
{
char version;
char subVersion1;
char subVersion2;
char subsubVersion1;
char subsubVersion2;
char subsubsubVersion1;
char subsubsubVersion2;
char subsubsubVersion3;
char subsubsubVersion4;
BinaryReader br = new BinaryReader(new StreamReader(file).BaseStream, Encoding.Default);
br.BaseStream.Seek(position + 8, SeekOrigin.Begin); // Begin reading after "AddD"
version = br.ReadChar();
char version = br.ReadChar();
br.ReadByte();
subVersion1 = br.ReadChar();
subVersion2 = br.ReadChar();
char subVersion1 = br.ReadChar();
char subVersion2 = br.ReadChar();
br.ReadByte();
subsubVersion1 = br.ReadChar();
subsubVersion2 = br.ReadChar();
char subsubVersion1 = br.ReadChar();
char subsubVersion2 = br.ReadChar();
br.ReadByte();
subsubsubVersion1 = br.ReadChar();
subsubsubVersion2 = br.ReadChar();
subsubsubVersion3 = br.ReadChar();
subsubsubVersion4 = br.ReadChar();
char subsubsubVersion1 = br.ReadChar();
char subsubsubVersion2 = br.ReadChar();
char subsubsubVersion3 = br.ReadChar();
char subsubsubVersion4 = br.ReadChar();
br.Close();
return version + "." + subVersion1 + subVersion2 + "." + subsubVersion1 + subsubVersion2 + "." + subsubsubVersion1 + subsubsubVersion2 + subsubsubVersion3 + subsubsubVersion4;
}
private static string GetSecuROM4and5Version(string file, int position)
{
byte version;
byte subVersion1;
byte subVersion2;
byte subsubVersion1;
byte subsubVersion2;
byte subsubsubVersion1;
byte subsubsubVersion2;
byte subsubsubVersion3;
byte subsubsubVersion4;
BinaryReader br = new BinaryReader(new StreamReader(file).BaseStream);
br.BaseStream.Seek(position + 8, SeekOrigin.Begin); // Begin reading after "ÊÝݬ"
version = (byte)(br.ReadByte() & 0xF);
byte version = (byte)(br.ReadByte() & 0xF);
br.ReadByte();
subVersion1 = (byte)(br.ReadByte() ^ 36);
subVersion2 = (byte)(br.ReadByte() ^ 28);
byte subVersion1 = (byte)(br.ReadByte() ^ 36);
byte subVersion2 = (byte)(br.ReadByte() ^ 28);
br.ReadByte();
subsubVersion1 = (byte)(br.ReadByte() ^ 42);
subsubVersion2 = (byte)(br.ReadByte() ^ 8);
byte subsubVersion1 = (byte)(br.ReadByte() ^ 42);
byte subsubVersion2 = (byte)(br.ReadByte() ^ 8);
br.ReadByte();
subsubsubVersion1 = (byte)(br.ReadByte() ^ 16);
subsubsubVersion2 = (byte)(br.ReadByte() ^ 116);
subsubsubVersion3 = (byte)(br.ReadByte() ^ 34);
subsubsubVersion4 = (byte)(br.ReadByte() ^ 22);
byte subsubsubVersion1 = (byte)(br.ReadByte() ^ 16);
byte subsubsubVersion2 = (byte)(br.ReadByte() ^ 116);
byte subsubsubVersion3 = (byte)(br.ReadByte() ^ 34);
byte subsubsubVersion4 = (byte)(br.ReadByte() ^ 22);
br.Close();
if (version == 0 || version > 9)
return "";
@@ -788,7 +773,7 @@ namespace DICUI.External
BinaryReader br = new BinaryReader(new StreamReader(file).BaseStream);
br.BaseStream.Seek(236, SeekOrigin.Begin);
byte[] bytes = br.ReadBytes(4);
// if bytes(0) = 0xED && bytes(3) = 0x5C {
// if (bytes[0] == 0xED && bytes[3] == 0x5C {
if (bytes[3] == 0x5C)
{
//SecuROM 7 new and 8
@@ -807,13 +792,11 @@ namespace DICUI.External
private static string GetSysiphusVersion(string file, int position)
{
char version;
char subVersion;
BinaryReader br = new BinaryReader(new StreamReader(file).BaseStream, Encoding.Default);
br.BaseStream.Seek(position - 3, SeekOrigin.Begin);
subVersion = br.ReadChar();
char subVersion = br.ReadChar();
br.ReadChar();
version = br.ReadChar();
char version = br.ReadChar();
br.Close();
if (Char.IsNumber(version) && Char.IsNumber(subVersion))
return version + "." + subVersion;
@@ -853,17 +836,14 @@ namespace DICUI.External
private static string GetVOBProtectCDDVDVersion(string file, int position)
{
byte version;
byte subVersion;
byte subsubVersion;
BinaryReader br = new BinaryReader(new StreamReader(file).BaseStream, Encoding.Default);
br.BaseStream.Seek(position - 2, SeekOrigin.Begin);
version = br.ReadByte();
byte version = br.ReadByte();
if (version == 5)
{
br.BaseStream.Seek(position - 4, SeekOrigin.Begin);
subsubVersion = (byte)((br.ReadByte() & 0xF0) >> 4);
subVersion = (byte)((br.ReadByte() & 0xF0) >> 4);
byte subsubVersion = (byte)((br.ReadByte() & 0xF0) >> 4);
byte subVersion = (byte)((br.ReadByte() & 0xF0) >> 4);
br.Close();
return version + "." + subVersion + "." + subsubVersion;
}
@@ -1077,6 +1057,9 @@ namespace DICUI.External
mapping.Add("ECDPlayerControl.ocx", "XCP");
mapping.Add("go.exe", "XCP"); // Path.Combine("contents", "go.exe")
// Zzxzz
mapping.Add("Zzz.aze", "Zzxzz"); // Path.Combine("Zzxxzz", "Zzz.aze")
return mapping;
}

View File

@@ -221,12 +221,14 @@ namespace DICUI
cmb_DriveLetter.SelectedIndex = 0;
lbl_Status.Content = "Valid media found! Choose your Media Type";
btn_StartStop.IsEnabled = true;
btn_Scan.IsEnabled = true;
}
else
{
cmb_DriveLetter.SelectedIndex = -1;
lbl_Status.Content = "No valid media found!";
btn_StartStop.IsEnabled = false;
btn_Scan.IsEnabled = false;
}
}
@@ -250,8 +252,6 @@ namespace DICUI
/// <returns>Filled DumpEnvironment instance</returns>
private DumpEnvironment DetermineEnvironment()
{
// Populate all KVPs
return new DumpEnvironment()
{
// Paths to tools
@@ -266,7 +266,7 @@ namespace DICUI
DICParameters = txt_Parameters.Text,
System = (KnownSystem?)(cmb_SystemType.SelectedItem as KnownSystemComboBoxItem),
System = cmb_SystemType.SelectedItem as KnownSystemComboBoxItem,
Type = cmb_MediaType.SelectedItem as MediaType?
};
}
@@ -297,12 +297,24 @@ namespace DICUI
private void EnsureDiscInformation()
{
// Get the selected system info
KnownSystem? selectedSystem = (KnownSystem?)(cmb_SystemType.SelectedItem as KnownSystemComboBoxItem) ?? KnownSystem.NONE;
KnownSystem? selectedSystem = (KnownSystem?)(cmb_SystemType.SelectedItem as KnownSystemComboBoxItem) ?? KnownSystem.NONE;
MediaType? selectedMediaType = cmb_MediaType.SelectedItem as MediaType? ?? MediaType.NONE;
Result result = GetSupportStatus(selectedSystem, selectedMediaType);
Result result = Validators.GetSupportStatus(selectedSystem, selectedMediaType);
string resultMessage = result.Message;
if (result && _currentMediaType != null && _currentMediaType != MediaType.NONE)
{
// If the current media type is still supported, change the index to that
int index = _mediaTypes.IndexOf(_currentMediaType);
if (index != -1 && cmb_MediaType.SelectedIndex != index)
cmb_MediaType.SelectedIndex = index;
lbl_Status.Content = result.Message;
// Otherwise, we tell the user that the disc/system combo is not supported
else
resultMessage = $"Disc of type {_currentMediaType.Name()} found, but the current system does not support it!";
};
lbl_Status.Content = resultMessage;
btn_StartStop.IsEnabled = result && (_drives != null && _drives.Count > 0 ? true : false);
// If we're in a type that doesn't support drive speeds
@@ -353,74 +365,6 @@ namespace DICUI
}
}
/// <summary>
/// Verify that, given a system and a media type, they are correct
/// </summary>
private Result GetSupportStatus(KnownSystem? system, MediaType? type)
{
// No system chosen, update status
if (system == KnownSystem.NONE)
return Result.Failure("Please select a valid system");
// custom system chosen, then don't check anything
else if (system == KnownSystem.Custom)
return Result.Success("{0} ready to dump", type.Name());
// If we're on an unsupported type, update the status accordingly
switch (type)
{
// Fully supported types
case MediaType.CD:
case MediaType.DVD:
case MediaType.HDDVD:
case MediaType.BluRay:
if (system == KnownSystem.MicrosoftXBOX360XDG3)
{
return Result.Failure("{0} discs are not currently supported by DIC", type.Name());
}
else
{
// TODO: this code should adjust things in a method which is meant to verify values so maybe we can find a better fit
// Take care of the selected item
if (_currentMediaType != null && _currentMediaType != MediaType.NONE)
{
int index = _mediaTypes.IndexOf(_currentMediaType);
if (index != -1)
{
if (cmb_MediaType.SelectedIndex != index)
{
cmb_MediaType.SelectedIndex = index;
}
}
else
{
return Result.Success("Disc of type {0} found, but the current system does not support it!", _currentMediaType.Name());
}
}
}
return Result.Success("{0} ready to dump", type.Name());
// Partially supported types
case MediaType.GDROM:
case MediaType.GameCubeGameDisc:
case MediaType.WiiOpticalDisc:
return Result.Success("{0} discs are partially supported by DIC", type.Name());
// Undumpable but recognized types
case MediaType.LaserDisc:
case MediaType.WiiUOpticalDisc:
case MediaType.CED:
case MediaType.UMD:
case MediaType.Cartridge:
case MediaType.Cassette:
return Result.Failure("{0} discs are not currently supported by DIC", type.Name());
// Invalid or unknown types
case MediaType.NONE:
default:
return Result.Failure("Please select a valid disc type");
}
}
/// <summary>
/// Get the default output directory name from the currently selected drive
/// </summary>
@@ -471,54 +415,27 @@ namespace DICUI
}
/// <summary>
/// Get the highest supported drive speed as reported by DiscImageCreator
/// Set the drive speed based on reported maximum and user-defined option
/// </summary>
private void SetSupportedDriveSpeed()
private async void SetSupportedDriveSpeed()
{
// Set the drive speed list that's appropriate
var values = AllowedSpeeds.GetForMediaType(_currentMediaType);
cmb_DriveSpeed.ItemsSource = values;
cmb_DriveSpeed.SelectedIndex = values.Count / 2;
// Get the drive letter from the selected item
Drive drive = cmb_DriveLetter.SelectedItem as Drive;
if (drive == null || drive.IsFloppy)
// Get the current environment
var env = DetermineEnvironment();
// Get the drive speed
int speed = await Tasks.GetDiscSpeed(env);
// If we have an invalid speed, we need to jump out
// TODO: Should we disable dumping in this case?
if (speed == -1)
return;
//Validators.GetDriveSpeed((char)selected?.Key);
//Validators.GetDriveSpeedEx((char)selected?.Key, _currentMediaType);
// Validate that the required program exists and it's not DICUI itself
if (!File.Exists(_options.dicPath) ||
Path.GetFullPath(_options.dicPath) == Path.GetFullPath(Process.GetCurrentProcess().MainModule.FileName))
{
return;
}
Process childProcess = new Process()
{
StartInfo = new ProcessStartInfo()
{
FileName = _options.dicPath,
Arguments = DICCommands.DriveSpeed + " " + drive.Letter,
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) || speed <= 0)
{
return;
}
// choose speed value according to maximum value reported by DIC adjusted to a precise speed from list
// and the one choosen in options
// Choose the lower of the two speeds between the allowed speeds and the user-defined one
int chosenSpeed = Math.Min(
AllowedSpeeds.GetForMediaType(_currentMediaType).Where(s => s <= speed).Last(),
_options.preferredDumpSpeedCD

View File

@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using DICUI.Data;
@@ -40,6 +42,70 @@ namespace DICUI
/// </summary>
public class Tasks
{
/// <summary>
/// Get disc speed using DIC
/// </summary>
/// <returns>Drive speed if possible, -1 on error</returns>
public static async Task<int> GetDiscSpeed(DumpEnvironment env)
{
// Validate that the required program exists
if (!File.Exists(env.DICPath))
return -1;
// Validate that the drive is set up
if (env.Drive == null)
return -1;
// Validate we're not trying to get the speed for a floppy disk
if (env.IsFloppy)
return -1;
// Get the drive speed directly
//int speed = Validators.GetDriveSpeed((char)selected?.Key);
//int speed = Validators.GetDriveSpeedEx((char)selected?.Key, _currentMediaType);
// Get the drive speed from DIC, if possible
Process childProcess;
string output = await Task.Run(() =>
{
childProcess = new Process()
{
StartInfo = new ProcessStartInfo()
{
FileName = env.DICPath,
Arguments = DICCommands.DriveSpeed + " " + env.Drive.Letter,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
},
};
childProcess.Start();
childProcess.WaitForExit();
return childProcess.StandardOutput.ReadToEnd();
});
// If we get that the firmware is out of date, tell the user
if (output.Contains("[ERROR] This drive isn't latest firmware. Please update."))
{
MessageBox.Show($"DiscImageCreator has reported that drive {env.Drive.Letter} is not updated to the most recent firmware. Please update the firmware for your drive and try again.", "Outdated Firmware", MessageBoxButton.OK, MessageBoxImage.Error);
return -1;
}
// Otherwise, if we find the maximum read speed as reported
else if (output.Contains("ReadSpeedMaximum:"))
{
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) || speed <= 0)
{
return -1;
}
return speed;
}
return -1;
}
/// <summary>
/// Eject the disc using DIC
/// </summary>
@@ -51,6 +117,7 @@ namespace DICUI
CancelDumping(env);
// Validate we're not trying to eject a floppy disk
if (env.IsFloppy)
return;

View File

@@ -5,121 +5,8 @@ using System.Windows.Data;
using IMAPI2;
using DICUI.Data;
// TODO: Consider making the *Extensions classes into its own file
namespace DICUI.Utilities
{
/// <summary>
/// Extensions for MediaType? for easier calling
/// </summary>
public static class MediaTypeExtensions
{
public static string Name(this MediaType? type)
{
return Converters.MediaTypeToString(type);
}
public static string Extension(this MediaType? type)
{
return Converters.MediaTypeToExtension(type);
}
public static bool DoesSupportDriveSpeed(this MediaType? type)
{
switch(type)
{
case MediaType.CD:
case MediaType.DVD:
case MediaType.GDROM:
case MediaType.HDDVD:
case MediaType.GameCubeGameDisc:
case MediaType.WiiOpticalDisc:
return true;
default:
return false;
}
}
}
/// <summary>
/// Extensions for KnownSystem? for easier calling
/// </summary>
public static class KnownSystemExtensions
{
public static string Name(this KnownSystem? system)
{
return Converters.KnownSystemToString(system);
}
public static bool DoesSupportDriveSpeed(this KnownSystem? system)
{
switch (system)
{
case KnownSystem.MicrosoftXBOX:
case KnownSystem.MicrosoftXBOX360XDG2:
case KnownSystem.MicrosoftXBOX360XDG3:
return false;
default:
return true;
}
}
public static KnownSystemCategory Category(this KnownSystem? system)
{
if (system < KnownSystem.MarkerConsoleEnd)
return KnownSystemCategory.Console;
else if (system < KnownSystem.MarkerComputerEnd)
return KnownSystemCategory.Computer;
else if (system < KnownSystem.MarkerArcadeEnd)
return KnownSystemCategory.Arcade;
else if (system < KnownSystem.MarkerOtherEnd)
return KnownSystemCategory.Other;
else
return KnownSystemCategory.Custom;
}
public static bool IsMarker(this KnownSystem? system)
{
switch (system)
{
case KnownSystem.MarkerArcadeEnd:
case KnownSystem.MarkerComputerEnd:
case KnownSystem.MarkerConsoleEnd:
case KnownSystem.MarkerOtherEnd:
return true;
default:
return false;
}
}
}
/// <summary>
/// Extensions for KnownSystemCategory?
/// </summary>
public static class KnownSystemCategoryExtensions
{
/// <summary>
/// Get the string representation of a KnownSystemCategory
/// </summary>
public static string Name(this KnownSystemCategory? category)
{
switch (category)
{
case KnownSystemCategory.Arcade:
return "Arcade";
case KnownSystemCategory.Computer:
return "Computers";
case KnownSystemCategory.Console:
return "Consoles";
case KnownSystemCategory.Other:
return "Other";
case KnownSystemCategory.Custom:
return "Custom";
default:
return "";
}
}
}
/// <summary>
/// Used to provide a converter to XAML files to render comboboxes with enum values
/// </summary>

View File

@@ -11,6 +11,26 @@ using DICUI.Data;
namespace DICUI.Utilities
{
/// <summary>
/// Represents information for a single drive
/// </summary>
public class Drive
{
public char Letter { get; private set; }
public bool IsFloppy { get; private set; }
public string VolumeLabel { get; private set; }
private Drive(char letter, string volumeLabel, bool isFloppy)
{
this.Letter = letter;
this.IsFloppy = isFloppy;
this.VolumeLabel = volumeLabel;
}
public static Drive Floppy(char letter) => new Drive(letter, null, true);
public static Drive Optical(char letter, string volumeLabel) => new Drive(letter, volumeLabel, false);
}
/// <summary>
/// Represents the state of all settings to be used during dumping
/// </summary>

View File

@@ -0,0 +1,116 @@
using DICUI.Data;
namespace DICUI.Utilities
{
/// <summary>
/// Extensions for MediaType? for easier calling
/// </summary>
public static class MediaTypeExtensions
{
public static string Name(this MediaType? type)
{
return Converters.MediaTypeToString(type);
}
public static string Extension(this MediaType? type)
{
return Converters.MediaTypeToExtension(type);
}
public static bool DoesSupportDriveSpeed(this MediaType? type)
{
switch (type)
{
case MediaType.CD:
case MediaType.DVD:
case MediaType.GDROM:
case MediaType.HDDVD:
case MediaType.GameCubeGameDisc:
case MediaType.WiiOpticalDisc:
return true;
default:
return false;
}
}
}
/// <summary>
/// Extensions for KnownSystem? for easier calling
/// </summary>
public static class KnownSystemExtensions
{
public static string Name(this KnownSystem? system)
{
return Converters.KnownSystemToString(system);
}
public static bool DoesSupportDriveSpeed(this KnownSystem? system)
{
switch (system)
{
case KnownSystem.MicrosoftXBOX:
case KnownSystem.MicrosoftXBOX360XDG2:
case KnownSystem.MicrosoftXBOX360XDG3:
return false;
default:
return true;
}
}
public static KnownSystemCategory Category(this KnownSystem? system)
{
if (system < KnownSystem.MarkerConsoleEnd)
return KnownSystemCategory.Console;
else if (system < KnownSystem.MarkerComputerEnd)
return KnownSystemCategory.Computer;
else if (system < KnownSystem.MarkerArcadeEnd)
return KnownSystemCategory.Arcade;
else if (system < KnownSystem.MarkerOtherEnd)
return KnownSystemCategory.Other;
else
return KnownSystemCategory.Custom;
}
public static bool IsMarker(this KnownSystem? system)
{
switch (system)
{
case KnownSystem.MarkerArcadeEnd:
case KnownSystem.MarkerComputerEnd:
case KnownSystem.MarkerConsoleEnd:
case KnownSystem.MarkerOtherEnd:
return true;
default:
return false;
}
}
}
/// <summary>
/// Extensions for KnownSystemCategory?
/// </summary>
public static class KnownSystemCategoryExtensions
{
/// <summary>
/// Get the string representation of a KnownSystemCategory
/// </summary>
public static string Name(this KnownSystemCategory? category)
{
switch (category)
{
case KnownSystemCategory.Arcade:
return "Arcade";
case KnownSystemCategory.Computer:
return "Computers";
case KnownSystemCategory.Console:
return "Consoles";
case KnownSystemCategory.Other:
return "Other";
case KnownSystemCategory.Custom:
return "Custom";
default:
return "";
}
}
}
}

View File

@@ -10,25 +10,6 @@ using DICUI.Data;
namespace DICUI.Utilities
{
// TODO: Consider putting this in its own file, or with DumpEnvironment
// TODO: Investigate whether or not this could be a struct
public class Drive
{
public char Letter { get; private set; }
public bool IsFloppy { get; private set; }
public string VolumeLabel { get; private set; }
private Drive(char letter, string volumeLabel, bool isFloppy)
{
this.Letter = letter;
this.IsFloppy = isFloppy;
this.VolumeLabel = volumeLabel;
}
public static Drive Floppy(char letter) => new Drive(letter, null, true);
public static Drive Optical(char letter, string volumeLabel) => new Drive(letter, volumeLabel, false);
}
public static class Validators
{
/// <summary>
@@ -678,6 +659,54 @@ namespace DICUI.Utilities
return -1;
}
/// <summary>
/// Verify that, given a system and a media type, they are correct
/// </summary>
public static Result GetSupportStatus(KnownSystem? system, MediaType? type)
{
// No system chosen, update status
if (system == KnownSystem.NONE)
return Result.Failure("Please select a valid system");
// custom system chosen, then don't check anything
else if (system == KnownSystem.Custom)
return Result.Success("{0} ready to dump", type.Name());
// If we're on an unsupported type, update the status accordingly
switch (type)
{
// Fully supported types
case MediaType.CD:
case MediaType.DVD:
case MediaType.HDDVD:
case MediaType.BluRay:
if (system == KnownSystem.MicrosoftXBOX360XDG3)
{
return Result.Failure("{0} discs are not currently supported by DIC", type.Name());
}
return Result.Success("{0} ready to dump", type.Name());
// Partially supported types
case MediaType.GDROM:
case MediaType.GameCubeGameDisc:
case MediaType.WiiOpticalDisc:
return Result.Success("{0} discs are partially supported by DIC", type.Name());
// Undumpable but recognized types
case MediaType.LaserDisc:
case MediaType.WiiUOpticalDisc:
case MediaType.CED:
case MediaType.UMD:
case MediaType.Cartridge:
case MediaType.Cassette:
return Result.Failure("{0} discs are not currently supported by DIC", type.Name());
// Invalid or unknown types
case MediaType.NONE:
default:
return Result.Failure("Please select a valid disc type");
}
}
/// <summary>
/// Validate that at string would be valid as input to DiscImageCreator
/// </summary>