From 72efffcec4dda49cd68b9ada18eb1b6c438ce2b0 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 20 May 2019 22:14:53 -0700 Subject: [PATCH] Cleanup brigade --- DICUI.Check/Program.cs | 4 +- DICUI.Library/DICUI.Library.csproj | 1 + DICUI.Library/Properties/AssemblyInfo.cs | 1 + DICUI.Library/Utilities/Converters.cs | 322 +++++++------ DICUI.Library/Utilities/Drive.cs | 52 ++ DICUI.Library/Utilities/DumpEnvironment.cs | 447 ++++++++++-------- DICUI.Library/Utilities/Extensions.cs | 133 ------ DICUI.Library/Utilities/Parameters.cs | 54 +-- DICUI.Library/Utilities/Validators.cs | 10 +- DICUI.Test/DICUI.Test.csproj | 2 - DICUI.Test/Utilities/ConvertersTest.cs | 6 +- .../Utilities/DICCommandExtensionsTest.cs | 23 - DICUI.Test/Utilities/DICFlagExtensionsTest.cs | 23 - .../Utilities/KnownSystemExtensionsTest.cs | 15 +- .../Utilities/MediaTypeExtensionsTest.cs | 24 +- DICUI/EnumDescriptionConverter.cs | 8 +- DICUI/KnownSystemComboBoxItem.cs | 4 +- DICUI/MediaTypeComboBoxItem.cs | 2 +- DICUI/Windows/MainWindow.xaml.cs | 6 +- 19 files changed, 539 insertions(+), 598 deletions(-) create mode 100644 DICUI.Library/Utilities/Drive.cs delete mode 100644 DICUI.Test/Utilities/DICCommandExtensionsTest.cs delete mode 100644 DICUI.Test/Utilities/DICFlagExtensionsTest.cs diff --git a/DICUI.Check/Program.cs b/DICUI.Check/Program.cs index 2333aa7f..1117e32a 100644 --- a/DICUI.Check/Program.cs +++ b/DICUI.Check/Program.cs @@ -149,7 +149,7 @@ x360 - Microsoft XBOX 360"); if (((MediaType)val) == MediaType.NONE) continue; - Console.WriteLine($"{((MediaType?)val).ShortName()} - {((MediaType?)val).Name()}"); + Console.WriteLine($"{((MediaType?)val).ShortName()} - {((MediaType?)val).LongName()}"); } } @@ -164,7 +164,7 @@ x360 - Microsoft XBOX 360"); if (((KnownSystem)val) == KnownSystem.NONE) continue; - Console.WriteLine($"{((KnownSystem?)val).ShortName()} - {((KnownSystem?)val).Name()}"); + Console.WriteLine($"{((KnownSystem?)val).ShortName()} - {((KnownSystem?)val).LongName()}"); } } diff --git a/DICUI.Library/DICUI.Library.csproj b/DICUI.Library/DICUI.Library.csproj index cdaaa0b7..9c40db54 100644 --- a/DICUI.Library/DICUI.Library.csproj +++ b/DICUI.Library/DICUI.Library.csproj @@ -63,6 +63,7 @@ + Component diff --git a/DICUI.Library/Properties/AssemblyInfo.cs b/DICUI.Library/Properties/AssemblyInfo.cs index 30095116..3468181c 100644 --- a/DICUI.Library/Properties/AssemblyInfo.cs +++ b/DICUI.Library/Properties/AssemblyInfo.cs @@ -34,3 +34,4 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.11")] [assembly: AssemblyFileVersion("1.11.0.0")] +[assembly: InternalsVisibleTo("DICUI.Test")] diff --git a/DICUI.Library/Utilities/Converters.cs b/DICUI.Library/Utilities/Converters.cs index 3d5aba5b..ef860310 100644 --- a/DICUI.Library/Utilities/Converters.cs +++ b/DICUI.Library/Utilities/Converters.cs @@ -5,13 +5,47 @@ namespace DICUI.Utilities { public static class Converters { + #region Cross-enumeration conversions + + /// + /// Get the most common known system for a given MediaType + /// + /// DICCommand value to check + /// KnownSystem if possible, null on error + public static KnownSystem? ToKnownSystem(this DICCommand baseCommand) + { + switch (baseCommand) + { + case DICCommand.Audio: + return KnownSystem.AudioCD; + case DICCommand.CompactDisc: + case DICCommand.Data: + case DICCommand.DigitalVideoDisc: + case DICCommand.Floppy: + return KnownSystem.IBMPCCompatible; + case DICCommand.GDROM: + case DICCommand.Swap: + return KnownSystem.SegaDreamcast; + case DICCommand.BluRay: + return KnownSystem.SonyPlayStation3; + case DICCommand.XBOX: + case DICCommand.XBOXSwap: + return KnownSystem.MicrosoftXBOX; + case DICCommand.XGD2Swap: + case DICCommand.XGD3Swap: + return KnownSystem.MicrosoftXBOX360; + default: + return null; + } + } + /// /// Get the MediaType associated with a given base command /// /// DICCommand value to check /// MediaType if possible, null on error /// This takes the "safe" route by assuming the larger of any given format - public static MediaType? BaseCommmandToMediaType(DICCommand baseCommand) + public static MediaType? ToMediaType(this DICCommand baseCommand) { switch (baseCommand) { @@ -40,32 +74,113 @@ namespace DICUI.Utilities } /// - /// Get the most common known system for a given MediaType + /// Convert IMAPI physical media type to a MediaType /// - /// DICCommand value to check - /// KnownSystem if possible, null on error - public static KnownSystem? BaseCommandToKnownSystem(DICCommand baseCommand) + /// IMAPI_MEDIA_PHYSICAL_TYPE value to check + /// MediaType if possible, null on error + public static MediaType? ToMediaType(IMAPI_MEDIA_PHYSICAL_TYPE type) { - switch (baseCommand) + switch (type) { - case DICCommand.Audio: - return KnownSystem.AudioCD; - case DICCommand.CompactDisc: - case DICCommand.Data: - case DICCommand.DigitalVideoDisc: - case DICCommand.Floppy: - return KnownSystem.IBMPCCompatible; - case DICCommand.GDROM: - case DICCommand.Swap: - return KnownSystem.SegaDreamcast; - case DICCommand.BluRay: - return KnownSystem.SonyPlayStation3; - case DICCommand.XBOX: - case DICCommand.XBOXSwap: - return KnownSystem.MicrosoftXBOX; - case DICCommand.XGD2Swap: - case DICCommand.XGD3Swap: - return KnownSystem.MicrosoftXBOX360; + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN: + return MediaType.NONE; + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDROM: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDR: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDRW: + return MediaType.CDROM; + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDROM: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDRAM: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR_DUALLAYER: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHRW: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR_DUALLAYER: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW_DUALLAYER: + return MediaType.DVD; + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDROM: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDR: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDRAM: + return MediaType.HDDVD; + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDROM: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDR: + case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDRE: + return MediaType.BluRay; + default: + return null; + } + } + + /// + /// Get the default extension for a given disc type + /// + /// MediaType value to check + /// Valid extension (with leading '.'), null on error + public static string Extension(this MediaType? type) + { + switch (type) + { + case MediaType.CDROM: + case MediaType.GDROM: + case MediaType.Cartridge: + return ".bin"; + case MediaType.DVD: + case MediaType.HDDVD: + case MediaType.BluRay: + case MediaType.NintendoWiiOpticalDisc: + case MediaType.UMD: + return ".iso"; + case MediaType.LaserDisc: + case MediaType.NintendoGameCubeGameDisc: + return ".raw"; + case MediaType.NintendoWiiUOpticalDisc: + return ".wud"; + case MediaType.FloppyDisk: + return ".img"; + case MediaType.Cassette: + return ".wav"; + case MediaType.NONE: + default: + return null; + } + } + + #endregion + + #region Convert to Long Name + + /// + /// Get the string representation of the Category enum values + /// + /// Category value to convert + /// Short string representing the value, if possible + public static string LongName(this Category? category) + { + switch (category) + { + case Category.Games: + return "Games"; + case Category.Demos: + return "Demos"; + case Category.Video: + return "Video"; + case Category.Audio: + return "Audio"; + case Category.Multimedia: + return "Multimedia"; + case Category.Applications: + return "Applications"; + case Category.Coverdiscs: + return "Coverdiscs"; + case Category.Educational: + return "Educational"; + case Category.BonusDiscs: + return "Bonus Discs"; + case Category.Preproduction: + return "Preproduction"; + case Category.AddOns: + return "Add-Ons"; default: return null; } @@ -76,7 +191,7 @@ namespace DICUI.Utilities /// /// DICCommand value to convert /// String representing the value, if possible - public static string DICCommandToString(DICCommand command) + public static string LongName(this DICCommand command) { switch (command) { @@ -134,7 +249,7 @@ namespace DICUI.Utilities /// /// DICFlag value to convert /// String representing the value, if possible - public static string DICFlagToString(DICFlag flag) + public static string LongName(this DICFlag flag) { switch (flag) { @@ -193,123 +308,12 @@ namespace DICUI.Utilities } } - /// - /// Convert IMAPI physical media type to a MediaType - /// - /// IMAPI_MEDIA_PHYSICAL_TYPE value to check - /// MediaType if possible, null on error - public static MediaType? IMAPIDiskTypeToMediaType(IMAPI_MEDIA_PHYSICAL_TYPE type) - { - switch (type) - { - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN: - return MediaType.NONE; - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDROM: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDR: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_CDRW: - return MediaType.CDROM; - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDROM: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDRAM: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSR_DUALLAYER: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHRW: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDDASHR_DUALLAYER: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DVDPLUSRW_DUALLAYER: - return MediaType.DVD; - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDROM: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDR: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_HDDVDRAM: - return MediaType.HDDVD; - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDROM: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDR: - case IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_BDRE: - return MediaType.BluRay; - default: - return null; - } - } - - /// - /// Get the default extension for a given disc type - /// - /// MediaType value to check - /// Valid extension (with leading '.'), null on error - public static string MediaTypeToExtension(MediaType? type) - { - switch (type) - { - case MediaType.CDROM: - case MediaType.GDROM: - case MediaType.Cartridge: - return ".bin"; - case MediaType.DVD: - case MediaType.HDDVD: - case MediaType.BluRay: - case MediaType.NintendoWiiOpticalDisc: - case MediaType.UMD: - return ".iso"; - case MediaType.LaserDisc: - case MediaType.NintendoGameCubeGameDisc: - return ".raw"; - case MediaType.NintendoWiiUOpticalDisc: - return ".wud"; - case MediaType.FloppyDisk: - return ".img"; - case MediaType.Cassette: - return ".wav"; - case MediaType.NONE: - default: - return null; - } - } - - #region Convert to Long Name - - /// - /// Get the string representation of the Category enum values - /// - /// Category value to convert - /// Short string representing the value, if possible - public static string LongName(Category? category) - { - switch (category) - { - case Category.Games: - return "Games"; - case Category.Demos: - return "Demos"; - case Category.Video: - return "Video"; - case Category.Audio: - return "Audio"; - case Category.Multimedia: - return "Multimedia"; - case Category.Applications: - return "Applications"; - case Category.Coverdiscs: - return "Coverdiscs"; - case Category.Educational: - return "Educational"; - case Category.BonusDiscs: - return "Bonus Discs"; - case Category.Preproduction: - return "Preproduction"; - case Category.AddOns: - return "Add-Ons"; - default: - return null; - } - } - /// /// Get the string representation of the KnownSystem enum values /// /// KnownSystem value to convert /// String representing the value, if possible - public static string LongName(KnownSystem? sys) + public static string LongName(this KnownSystem? sys) { switch (sys) { @@ -563,12 +567,38 @@ namespace DICUI.Utilities } } + /// + /// Get the string representation of the KnownSystemCategory enum values + /// + /// KnownSystemCategory value to convert + /// String representing the value, if possible + public static string LongName(this KnownSystemCategory? category) + { + switch (category) + { + case KnownSystemCategory.Arcade: + return "Arcade"; + case KnownSystemCategory.Computer: + return "Computers"; + case KnownSystemCategory.DiscBasedConsole: + return "Disc-Based Consoles"; + case KnownSystemCategory.OtherConsole: + return "Other Consoles"; + case KnownSystemCategory.Other: + return "Other"; + case KnownSystemCategory.Custom: + return "Custom"; + default: + return ""; + } + } + /// /// Get the string representation of the Language enum values /// /// Language value to convert /// String representing the value, if possible - public static string LongName(Language? lang) + public static string LongName(this Language? lang) { switch (lang) { @@ -654,7 +684,7 @@ namespace DICUI.Utilities /// /// MediaType value to convert /// String representing the value, if possible - public static string LongName(MediaType? type) + public static string LongName(this MediaType? type) { switch (type) { @@ -744,7 +774,7 @@ namespace DICUI.Utilities /// /// Region value to convert /// String representing the value, if possible - public static string LongName(Region? region) + public static string LongName(this Region? region) { switch (region) { @@ -876,7 +906,7 @@ namespace DICUI.Utilities /// /// YesNo value to convert /// String representing the value, if possible - public static string LongName(YesNo yesno) + public static string LongName(this YesNo yesno) { switch(yesno) { @@ -899,7 +929,7 @@ namespace DICUI.Utilities /// /// KnownSystem value to convert /// Short string representing the value, if possible - public static string ShortName(KnownSystem? sys) + public static string ShortName(this KnownSystem? sys) { switch (sys) { @@ -1158,7 +1188,7 @@ namespace DICUI.Utilities /// /// Language value to convert /// Short string representing the value, if possible - public static string ShortName(Language? lang) + public static string ShortName(this Language? lang) { switch (lang) { @@ -1244,7 +1274,7 @@ namespace DICUI.Utilities /// /// MediaType value to convert /// Short string representing the value, if possible - public static string ShortName(MediaType? type) + public static string ShortName(this MediaType? type) { switch (type) { @@ -1334,7 +1364,7 @@ namespace DICUI.Utilities /// /// Region value to convert /// Short string representing the value, if possible - public static string ShortName(Region? region) + public static string ShortName(this Region? region) { switch (region) { diff --git a/DICUI.Library/Utilities/Drive.cs b/DICUI.Library/Utilities/Drive.cs new file mode 100644 index 00000000..bb08fadd --- /dev/null +++ b/DICUI.Library/Utilities/Drive.cs @@ -0,0 +1,52 @@ +namespace DICUI.Utilities +{ + /// + /// Represents information for a single drive + /// + public class Drive + { + /// + /// Windows drive letter + /// + public char Letter { get; private set; } + + /// + /// Represents if it is a floppy drive + /// + public bool IsFloppy { get; private set; } + + /// + /// Media label as read by Windows + /// + public string VolumeLabel { get; private set; } + + /// + /// Represents if Windows has marked the drive as active + /// + public bool MarkedActive { get; private set; } + + private Drive(char letter, string volumeLabel, bool isFloppy, bool markedActive) + { + this.Letter = letter; + this.IsFloppy = isFloppy; + this.VolumeLabel = volumeLabel; + this.MarkedActive = markedActive; + } + + /// + /// Create a new Floppy drive instance + /// + /// Drive letter to use + /// Drive object for a Floppy drive + public static Drive Floppy(char letter) => new Drive(letter, null, true, true); + + /// + /// Create a new Optical drive instance + /// + /// Drive letter to use + /// Media label, if it exists + /// True if the drive is marked active, false otherwise + /// Drive object for an Optical drive + public static Drive Optical(char letter, string volumeLabel, bool active) => new Drive(letter, volumeLabel, false, active); + } +} diff --git a/DICUI.Library/Utilities/DumpEnvironment.cs b/DICUI.Library/Utilities/DumpEnvironment.cs index 35acffc0..5e6b9d09 100644 --- a/DICUI.Library/Utilities/DumpEnvironment.cs +++ b/DICUI.Library/Utilities/DumpEnvironment.cs @@ -12,62 +12,115 @@ using Newtonsoft.Json; namespace DICUI.Utilities { - /// - /// Represents information for a single drive - /// - public class Drive - { - public char Letter { get; private set; } - public bool IsFloppy { get; private set; } - public string VolumeLabel { get; private set; } - public bool MarkedActive { get; private set; } - - private Drive(char letter, string volumeLabel, bool isFloppy, bool markedActive) - { - this.Letter = letter; - this.IsFloppy = isFloppy; - this.VolumeLabel = volumeLabel; - this.MarkedActive = markedActive; - } - - public static Drive Floppy(char letter) => new Drive(letter, null, true, true); - public static Drive Optical(char letter, string volumeLabel, bool active) => new Drive(letter, volumeLabel, false, active); - } - /// /// Represents the state of all settings to be used during dumping /// public class DumpEnvironment { - // Tool paths - public string DICPath; - public string SubdumpPath; + #region Tool paths - // Output paths - public string OutputDirectory; - public string OutputFilename; + /// + /// Path to DiscImageCreator executable + /// + public string DICPath { get; set; } - // UI information - public Drive Drive; - public KnownSystem? System; - public MediaType? Type; - public bool IsFloppy { get => Drive.IsFloppy; } - public Parameters DICParameters; + /// + /// Path to Subdump executable + /// + public string SubdumpPath { get; set; } - // extra DIC arguments - public bool QuietMode; - public bool ParanoidMode; - public bool ScanForProtection; - public int RereadAmountC2; + #endregion - // Redump login information - public string Username; - public string Password; + #region Output paths + + /// + /// Base output directory to write files to + /// + public string OutputDirectory { get; set; } + + /// + /// Base output filename for DiscImageCreator + /// + public string OutputFilename { get; set; } + + #endregion + + #region UI information + + /// + /// Drive object representing the current drive + /// + public Drive Drive { get; set; } + + /// + /// Currently selected system + /// + public KnownSystem? System { get; set; } + + /// + /// Currently selected media type + /// + public MediaType? Type { get; set; } + + /// + /// Parameters object representing what to send to DiscImageCreator + /// + public Parameters DICParameters { get; set; } + + #endregion + + #region Extra DIC arguments + + /// + /// Enable quiet mode (no beeps) + /// + public bool QuietMode { get; set; } + + /// + /// Enable paranoid mode (extra flags) + /// + public bool ParanoidMode { get; set; } + + /// + /// Scan for copy protection, where applicable + /// + public bool ScanForProtection { get; set; } + + /// + /// Number of C2 error reread attempts + /// + public int RereadAmountC2 { get; set; } + + #endregion + + #region Redump login information + + /// + /// Redump.org username for pulling existing disc data + /// + public string Username { get; set; } + + /// + /// Redump.org password for pulling existing disc data + /// + public string Password { get; set; } + + /// + /// Determine if a complete set of Redump credentials might exist + /// public bool HasRedumpLogin { get => !string.IsNullOrWhiteSpace(Username) && !string.IsNullOrWhiteSpace(Password); } + + #endregion - // External process information + #region External process information + + /// + /// Process to track DiscImageCreator instances + /// private Process dicProcess; + #endregion + #region Public Functionality /// @@ -84,47 +137,6 @@ namespace DICUI.Utilities { } } - /// - /// Eject the disc using DIC - /// - public async void EjectDisc() - { - // Validate that the required program exists - if (!File.Exists(DICPath)) - return; - - CancelDumping(); - - // Validate we're not trying to eject a floppy disk - if (IsFloppy) - return; - - Process childProcess; - await Task.Run(() => - { - childProcess = new Process() - { - StartInfo = new ProcessStartInfo() - { - FileName = DICPath, - Arguments = DICCommandStrings.Eject + " " + Drive.Letter, - CreateNoWindow = true, - UseShellExecute = false, - RedirectStandardInput = true, - RedirectStandardOutput = true, - }, - }; - childProcess.Start(); - childProcess.WaitForExit(1000); - - // Just in case, we want to push a button 5 times to clear any errors - for (int i = 0; i < 5; i++) - childProcess.StandardInput.WriteLine("Y"); - - childProcess.Dispose(); - }); - } - /// /// Gets if the current drive has the latest firmware /// @@ -172,71 +184,46 @@ namespace DICUI.Utilities } /// - /// Get the full parameter string for DIC + /// Eject the disc using DIC /// - /// Nullable int representing the drive speed - /// String representing the params, null on error - public string GetFullParameters(int? driveSpeed) + public async void EjectDisc() { - // Populate with the correct params for inputs (if we're not on the default option) - if (System != KnownSystem.NONE && Type != MediaType.NONE) + // Validate that the required program exists + if (!File.Exists(DICPath)) + return; + + CancelDumping(); + + // Validate we're not trying to eject a floppy disk + if (Drive.IsFloppy) + return; + + Process childProcess; + await Task.Run(() => { - // If drive letter is invalid, skip this - if (Drive == null) - return null; + childProcess = new Process() + { + StartInfo = new ProcessStartInfo() + { + FileName = DICPath, + Arguments = DICCommandStrings.Eject + " " + Drive.Letter, + CreateNoWindow = true, + UseShellExecute = false, + RedirectStandardInput = true, + RedirectStandardOutput = true, + }, + }; + childProcess.Start(); + childProcess.WaitForExit(1000); - FixOutputPaths(); + // Just in case, we want to push a button 5 times to clear any errors + for (int i = 0; i < 5; i++) + childProcess.StandardInput.WriteLine("Y"); - // Set the proper parameters - DICParameters = new Parameters(System, Type, Drive.Letter, Path.Combine(OutputDirectory, OutputFilename), driveSpeed, ParanoidMode, RereadAmountC2); - if (QuietMode) - DICParameters[DICFlag.DisableBeep] = true; - - // Generate and return the param string - return DICParameters.GenerateParameters(); - } - - return null; + childProcess.Dispose(); + }); } - /// - /// Execute a complete dump workflow - /// - public async Task StartDumping(IProgress progress) - { - Result result = IsValidForDump(); - - // Execute DIC and external tools, if needed - if (Validators.GetSupportStatus(System, Type) - && !result.Message.Contains("not supported") // Completely unsupported media - && !result.Message.Contains("submission info")) // Submission info-only media - { - // If the environment is invalid, return - if (!result) - return result; - - progress?.Report(Result.Success("Executing DiscImageCreator... please wait!")); - await Task.Run(() => ExecuteDiskImageCreator()); - progress?.Report(Result.Success("DiscImageCreator has finished!")); - - // Execute additional tools - progress?.Report(Result.Success("Running any additional tools... please wait!")); - result = await Task.Run(() => ExecuteAdditionalToolsAfterDIC()); - progress?.Report(result); - } - - // Verify dump output and save it - progress?.Report(Result.Success("Gathering submission information... please wait!")); - result = await Task.Run(() => VerifyAndSaveDumpOutput(progress)); - progress?.Report(Result.Success("All submission information gathered!")); - - return result; - } - - #endregion - - #region Public for Testing Purposes - /// /// Fix output paths to strip out any invalid characters /// @@ -284,15 +271,6 @@ namespace DICUI.Utilities } } - /// - /// Checks if the parameters are valid - /// - /// True if the configuration is valid, false otherwise - public bool ParametersValid() - { - return DICParameters.IsValid() && !(IsFloppy ^ Type == MediaType.FloppyDisk); - } - /// /// Ensures that all required output files have been created /// @@ -358,6 +336,113 @@ namespace DICUI.Utilities } } + /// + /// Get the full parameter string for DIC + /// + /// Nullable int representing the drive speed + /// String representing the params, null on error + public string GetFullParameters(int? driveSpeed) + { + // Populate with the correct params for inputs (if we're not on the default option) + if (System != KnownSystem.NONE && Type != MediaType.NONE) + { + // If drive letter is invalid, skip this + if (Drive == null) + return null; + + FixOutputPaths(); + + // Set the proper parameters + DICParameters = new Parameters(System, Type, Drive.Letter, Path.Combine(OutputDirectory, OutputFilename), driveSpeed, ParanoidMode, RereadAmountC2); + if (QuietMode) + DICParameters[DICFlag.DisableBeep] = true; + + // Generate and return the param string + return DICParameters.GenerateParameters(); + } + + return null; + } + + /// + /// Execute a complete dump workflow + /// + public async Task StartDumping(IProgress progress) + { + Result result = IsValidForDump(); + + // Execute DIC and external tools, if needed + if (Validators.GetSupportStatus(System, Type) + && !result.Message.Contains("not supported") // Completely unsupported media + && !result.Message.Contains("submission info")) // Submission info-only media + { + // If the environment is invalid, return + if (!result) + return result; + + progress?.Report(Result.Success("Executing DiscImageCreator... please wait!")); + await Task.Run(() => ExecuteDiskImageCreator()); + progress?.Report(Result.Success("DiscImageCreator has finished!")); + + // Execute additional tools + progress?.Report(Result.Success("Running any additional tools... please wait!")); + result = await Task.Run(() => ExecuteAdditionalToolsAfterDIC()); + progress?.Report(result); + } + + // Verify dump output and save it + progress?.Report(Result.Success("Gathering submission information... please wait!")); + result = await Task.Run(() => VerifyAndSaveDumpOutput(progress)); + progress?.Report(Result.Success("All submission information gathered!")); + + return result; + } + + /// + /// Verify that the current environment has a complete dump and create submission info is possible + /// + /// Result instance with the outcome + public Result VerifyAndSaveDumpOutput(IProgress progress) + { + // Check to make sure that the output had all the correct files + if (!FoundAllFiles()) + return Result.Failure("Error! Please check output directory as dump may be incomplete!"); + + progress?.Report(Result.Success("Extracting output information from output files...")); + SubmissionInfo submissionInfo = ExtractOutputInformation(progress); + progress?.Report(Result.Success("Extracting information complete!")); + + // TODO: Add UI step here (possibly) to get user info on the disc + + progress?.Report(Result.Success("Formatting extracted information...")); + List formattedValues = FormatOutputData(submissionInfo); + progress?.Report(Result.Success("Formatting complete!")); + + progress?.Report(Result.Success("Writing information to !submissionInfo.txt...")); + bool success = WriteOutputData(formattedValues); + success &= WriteOutputData(submissionInfo); + + if (success) + progress?.Report(Result.Success("Writing complete!")); + else + progress?.Report(Result.Failure("Writing could not complete!")); + + return Result.Success(); + } + + #endregion + + #region Internal for Testing Purposes + + /// + /// Checks if the parameters are valid + /// + /// True if the configuration is valid, false otherwise + internal bool ParametersValid() + { + return DICParameters.IsValid() && !(Drive.IsFloppy ^ Type == MediaType.FloppyDisk); + } + #endregion #region Private Helpers @@ -858,12 +943,12 @@ namespace DICUI.Utilities AddIfExists(output, Template.ForeignTitleField, info.ForeignTitleNonLatin, 1); AddIfExists(output, Template.DiscNumberField, info.DiscNumberLetter, 1); AddIfExists(output, Template.DiscTitleField, info.DiscTitle, 1); - AddIfExists(output, Template.SystemField, info.System.Name(), 1); + AddIfExists(output, Template.SystemField, info.System.LongName(), 1); AddIfExists(output, Template.MediaTypeField, GetFixedMediaType(info.Media, info.Layerbreak), 1); - AddIfExists(output, Template.CategoryField, info.Category.Name(), 1); + AddIfExists(output, Template.CategoryField, info.Category.LongName(), 1); AddIfExists(output, Template.MatchingIDsField, info.MatchedIDs, 1); - AddIfExists(output, Template.RegionField, info.Region.Name(), 1); - AddIfExists(output, Template.LanguagesField, (info.Languages ?? new Language?[] { null }).Select(l => l.Name()).ToArray(), 1); + AddIfExists(output, Template.RegionField, info.Region.LongName(), 1); + AddIfExists(output, Template.LanguagesField, (info.Languages ?? new Language?[] { null }).Select(l => l.LongName()).ToArray(), 1); AddIfExists(output, Template.PlaystationLanguageSelectionViaField, info.LanguageSelection, 1); AddIfExists(output, Template.DiscSerialField, info.Serial, 1); @@ -909,7 +994,7 @@ namespace DICUI.Utilities if (info.EDC != YesNo.NULL) { output.Add("EDC:"); - AddIfExists(output, Template.PlayStationEDCField, info.EDC.Name(), 1); + AddIfExists(output, Template.PlayStationEDCField, info.EDC.LongName(), 1); } // Parent/Clone Relationship section @@ -936,8 +1021,8 @@ namespace DICUI.Utilities output.Add(""); output.Add("Copy Protection:"); if (info.EDC != YesNo.NULL) { - AddIfExists(output, Template.PlayStationAntiModchipField, info.AntiModchip.Name(), 1); - AddIfExists(output, Template.PlayStationLibCryptField, info.LibCrypt.Name(), 1); + AddIfExists(output, Template.PlayStationAntiModchipField, info.AntiModchip.LongName(), 1); + AddIfExists(output, Template.PlayStationLibCryptField, info.LibCrypt.LongName(), 1); AddIfExists(output, Template.SubIntentionField, info.LibCryptData, 1); } @@ -1072,24 +1157,24 @@ namespace DICUI.Utilities { case MediaType.DVD: if (layerbreak != default(long)) - return $"{mediaType.Name()}-9"; + return $"{mediaType.LongName()}-9"; else - return $"{mediaType.Name()}-5"; + return $"{mediaType.LongName()}-5"; case MediaType.BluRay: if (layerbreak != default(long)) - return $"{mediaType.Name()}-50"; + return $"{mediaType.LongName()}-50"; else - return $"{mediaType.Name()}-25"; + return $"{mediaType.LongName()}-25"; case MediaType.UMD: if (layerbreak != default(long)) - return $"{mediaType.Name()}-DL"; + return $"{mediaType.LongName()}-DL"; else - return $"{mediaType.Name()}-SL"; + return $"{mediaType.LongName()}-SL"; default: - return mediaType.Name(); + return mediaType.LongName(); } } @@ -1112,38 +1197,6 @@ namespace DICUI.Utilities return Result.Success(); } - /// - /// Verify that the current environment has a complete dump and create submission info is possible - /// - /// Result instance with the outcome - public Result VerifyAndSaveDumpOutput(IProgress progress) - { - // Check to make sure that the output had all the correct files - if (!FoundAllFiles()) - return Result.Failure("Error! Please check output directory as dump may be incomplete!"); - - progress?.Report(Result.Success("Extracting output information from output files...")); - SubmissionInfo submissionInfo = ExtractOutputInformation(progress); - progress?.Report(Result.Success("Extracting information complete!")); - - // TODO: Add UI step here (possibly) to get user info on the disc - - progress?.Report(Result.Success("Formatting extracted information...")); - List formattedValues = FormatOutputData(submissionInfo); - progress?.Report(Result.Success("Formatting complete!")); - - progress?.Report(Result.Success("Writing information to !submissionInfo.txt...")); - bool success = WriteOutputData(formattedValues); - success &= WriteOutputData(submissionInfo); - - if (success) - progress?.Report(Result.Success("Writing complete!")); - else - progress?.Report(Result.Failure("Writing could not complete!")); - - return Result.Success(); - } - /// /// Write the data to the output folder /// diff --git a/DICUI.Library/Utilities/Extensions.cs b/DICUI.Library/Utilities/Extensions.cs index 239d7c72..af330972 100644 --- a/DICUI.Library/Utilities/Extensions.cs +++ b/DICUI.Library/Utilities/Extensions.cs @@ -2,59 +2,11 @@ namespace DICUI.Utilities { - /// - /// Extensions for Category? - /// - public static class CategoryExtensions - { - public static string Name(this Category? category) - { - return Converters.LongName(category); - } - } - - /// - /// Extensions for DICCommand for easier calling - /// - public static class DICCommandExtensions - { - public static string Name(this DICCommand command) - { - return Converters.DICCommandToString(command); - } - } - - /// - /// Extensions for DICFlag for easier calling - /// - public static class DICFlagExtensions - { - public static string Name(this DICFlag command) - { - return Converters.DICFlagToString(command); - } - } - /// /// Extensions for MediaType? for easier calling /// public static class MediaTypeExtensions { - public static string Name(this MediaType? type) - { - return Converters.LongName(type); - } - - public static string ShortName(this MediaType? type) - { - return Converters.ShortName(type); - } - - public static string Extension(this MediaType? type) - { - return Converters.MediaTypeToExtension(type); - } - public static bool DoesSupportDriveSpeed(this MediaType? type) { switch (type) @@ -78,16 +30,6 @@ namespace DICUI.Utilities /// public static class KnownSystemExtensions { - public static string Name(this KnownSystem? system) - { - return Converters.LongName(system); - } - - public static string ShortName(this KnownSystem? system) - { - return Converters.ShortName(system); - } - public static KnownSystemCategory Category(this KnownSystem? system) { if (system < KnownSystem.MarkerDiscBasedConsoleEnd) @@ -121,79 +63,4 @@ namespace DICUI.Utilities } } } - - /// - /// Extensions for KnownSystemCategory? - /// - public static class KnownSystemCategoryExtensions - { - /// - /// Get the string representation of a KnownSystemCategory - /// - public static string Name(this KnownSystemCategory? category) - { - switch (category) - { - case KnownSystemCategory.Arcade: - return "Arcade"; - case KnownSystemCategory.Computer: - return "Computers"; - case KnownSystemCategory.DiscBasedConsole: - return "Disc-Based Consoles"; - case KnownSystemCategory.OtherConsole: - return "Other Consoles"; - case KnownSystemCategory.Other: - return "Other"; - case KnownSystemCategory.Custom: - return "Custom"; - default: - return ""; - } - } - } - - /// - /// Extensions for Language? - /// - public static class LanguageExtensions - { - public static string Name(this Language? lang) - { - return Converters.LongName(lang); - } - - public static string ShortName(this Language? lang) - { - return Converters.ShortName(lang); - } - - } - - /// - /// Extensions for Region? - /// - public static class RegionExtensions - { - public static string Name(this Region? region) - { - return Converters.LongName(region); - } - - public static string ShortName(this Region? region) - { - return Converters.ShortName(region); - } - - } - - /// - /// Extensions for YesNo - /// - public static class YesNoExtensions - { - public static string Name(this YesNo yesno) - { - return Converters.LongName(yesno); - } - } } diff --git a/DICUI.Library/Utilities/Parameters.cs b/DICUI.Library/Utilities/Parameters.cs index 8aebbadc..ba07c3c9 100644 --- a/DICUI.Library/Utilities/Parameters.cs +++ b/DICUI.Library/Utilities/Parameters.cs @@ -133,8 +133,8 @@ namespace DICUI.Utilities return false; // Set the default outputs - type = Converters.BaseCommmandToMediaType(Command); - system = Converters.BaseCommandToKnownSystem(Command); + type = Converters.ToMediaType(Command); + system = Converters.ToKnownSystem(Command); letter = DriveLetter; path = Filename; @@ -184,7 +184,7 @@ namespace DICUI.Utilities List parameters = new List(); if (Command != DICCommand.NONE) - parameters.Add(Command.Name()); + parameters.Add(Command.LongName()); else return null; @@ -285,7 +285,7 @@ namespace DICUI.Utilities { if (this[DICFlag.AddOffset]) { - parameters.Add(DICFlag.AddOffset.Name()); + parameters.Add(DICFlag.AddOffset.LongName()); if (AddOffsetValue != null) parameters.Add(AddOffsetValue.ToString()); else @@ -297,7 +297,7 @@ namespace DICUI.Utilities if (Command == DICCommand.CompactDisc) { if (this[DICFlag.AMSF]) - parameters.Add(DICFlag.AMSF.Name()); + parameters.Add(DICFlag.AMSF.LongName()); } // BE Opcode @@ -309,7 +309,7 @@ namespace DICUI.Utilities { if (this[DICFlag.BEOpcode] && !this[DICFlag.D8Opcode]) { - parameters.Add(DICFlag.BEOpcode.Name()); + parameters.Add(DICFlag.BEOpcode.LongName()); if (BEOpcodeValue != null && (BEOpcodeValue == "raw" || BEOpcodeValue == "pack")) parameters.Add(BEOpcodeValue); @@ -325,7 +325,7 @@ namespace DICUI.Utilities { if (this[DICFlag.C2Opcode]) { - parameters.Add(DICFlag.C2Opcode.Name()); + parameters.Add(DICFlag.C2Opcode.LongName()); if (C2OpcodeValue[0] != null) { if (C2OpcodeValue[0] > 0) @@ -361,7 +361,7 @@ namespace DICUI.Utilities if (Command == DICCommand.DigitalVideoDisc) { if (this[DICFlag.CopyrightManagementInformation]) - parameters.Add(DICFlag.CopyrightManagementInformation.Name()); + parameters.Add(DICFlag.CopyrightManagementInformation.LongName()); } // D8 Opcode @@ -372,7 +372,7 @@ namespace DICUI.Utilities || Command == DICCommand.Swap) { if (this[DICFlag.D8Opcode]) - parameters.Add(DICFlag.D8Opcode.Name()); + parameters.Add(DICFlag.D8Opcode.LongName()); } // Disable Beep @@ -386,7 +386,7 @@ namespace DICUI.Utilities || Command == DICCommand.XBOX) { if (this[DICFlag.DisableBeep]) - parameters.Add(DICFlag.DisableBeep.Name()); + parameters.Add(DICFlag.DisableBeep.LongName()); } // Force Unit Access @@ -398,7 +398,7 @@ namespace DICUI.Utilities { if (this[DICFlag.ForceUnitAccess]) { - parameters.Add(DICFlag.ForceUnitAccess.Name()); + parameters.Add(DICFlag.ForceUnitAccess.LongName()); if (ForceUnitAccessValue != null) parameters.Add(ForceUnitAccessValue.ToString()); } @@ -408,14 +408,14 @@ namespace DICUI.Utilities if (Command == DICCommand.CompactDisc) { if (this[DICFlag.MCN]) - parameters.Add(DICFlag.MCN.Name()); + parameters.Add(DICFlag.MCN.LongName()); } // Multi-Session if (Command == DICCommand.CompactDisc) { if (this[DICFlag.MultiSession]) - parameters.Add(DICFlag.MultiSession.Name()); + parameters.Add(DICFlag.MultiSession.LongName()); } // Not fix SubP @@ -426,7 +426,7 @@ namespace DICUI.Utilities || Command == DICCommand.Swap) { if (this[DICFlag.NoFixSubP]) - parameters.Add(DICFlag.NoFixSubP.Name()); + parameters.Add(DICFlag.NoFixSubP.LongName()); } // Not fix SubQ @@ -437,7 +437,7 @@ namespace DICUI.Utilities || Command == DICCommand.Swap) { if (this[DICFlag.NoFixSubQ]) - parameters.Add(DICFlag.NoFixSubQ.Name()); + parameters.Add(DICFlag.NoFixSubQ.LongName()); } // Not fix SubQ (PlayStation LibCrypt) @@ -448,7 +448,7 @@ namespace DICUI.Utilities || Command == DICCommand.Swap) { if (this[DICFlag.NoFixSubQLibCrypt]) - parameters.Add(DICFlag.NoFixSubQLibCrypt.Name()); + parameters.Add(DICFlag.NoFixSubQLibCrypt.LongName()); } // Not fix SubQ (SecuROM) @@ -459,7 +459,7 @@ namespace DICUI.Utilities || Command == DICCommand.Swap) { if (this[DICFlag.NoFixSubQSecuROM]) - parameters.Add(DICFlag.NoFixSubQSecuROM.Name()); + parameters.Add(DICFlag.NoFixSubQSecuROM.LongName()); } // Not fix SubRtoW @@ -470,14 +470,14 @@ namespace DICUI.Utilities || Command == DICCommand.Swap) { if (this[DICFlag.NoFixSubRtoW]) - parameters.Add(DICFlag.NoFixSubRtoW.Name()); + parameters.Add(DICFlag.NoFixSubRtoW.LongName()); } // Raw read (2064 byte/sector) if (Command == DICCommand.DigitalVideoDisc) { if (this[DICFlag.Raw]) - parameters.Add(DICFlag.Raw.Name()); + parameters.Add(DICFlag.Raw.LongName()); } // Reverse read @@ -485,7 +485,7 @@ namespace DICUI.Utilities || Command == DICCommand.Data) { if (this[DICFlag.Reverse]) - parameters.Add(DICFlag.Reverse.Name()); + parameters.Add(DICFlag.Reverse.LongName()); } // Scan PlayStation anti-mod strings @@ -493,7 +493,7 @@ namespace DICUI.Utilities || Command == DICCommand.Data) { if (this[DICFlag.ScanAntiMod]) - parameters.Add(DICFlag.ScanAntiMod.Name()); + parameters.Add(DICFlag.ScanAntiMod.LongName()); } // Scan file to detect protect @@ -505,7 +505,7 @@ namespace DICUI.Utilities { if (this[DICFlag.ScanFileProtect]) { - parameters.Add(DICFlag.ScanFileProtect.Name()); + parameters.Add(DICFlag.ScanFileProtect.LongName()); if (ScanFileProtectValue != null) { if (ScanFileProtectValue > 0) @@ -522,14 +522,14 @@ namespace DICUI.Utilities || Command == DICCommand.Swap) { if (this[DICFlag.ScanSectorProtect]) - parameters.Add(DICFlag.ScanSectorProtect.Name()); + parameters.Add(DICFlag.ScanSectorProtect.LongName()); } // Scan 74:00:00 (Saturn) if (Command == DICCommand.Swap) { if (this[DICFlag.SeventyFour]) - parameters.Add(DICFlag.SeventyFour.Name()); + parameters.Add(DICFlag.SeventyFour.LongName()); } // Skip sectors @@ -539,7 +539,7 @@ namespace DICUI.Utilities { if (SkipSectorValue[0] != null && SkipSectorValue[1] != null) { - parameters.Add(DICFlag.SkipSector.Name()); + parameters.Add(DICFlag.SkipSector.LongName()); if (SkipSectorValue[0] >= 0 && SkipSectorValue[1] >= 0) { parameters.Add(SkipSectorValue[0].ToString()); @@ -562,7 +562,7 @@ namespace DICUI.Utilities { if (this[DICFlag.SubchannelReadLevel]) { - parameters.Add(DICFlag.SubchannelReadLevel.Name()); + parameters.Add(DICFlag.SubchannelReadLevel.LongName()); if (SubchannelReadLevelValue != null) { if (SubchannelReadLevelValue >= 0 && SubchannelReadLevelValue <= 2) @@ -578,7 +578,7 @@ namespace DICUI.Utilities { if (this[DICFlag.VideoNow]) { - parameters.Add(DICFlag.VideoNow.Name()); + parameters.Add(DICFlag.VideoNow.LongName()); if (VideoNowValue != null) { if (VideoNowValue >= 0) diff --git a/DICUI.Library/Utilities/Validators.cs b/DICUI.Library/Utilities/Validators.cs index 4794fa6d..ff8122b4 100644 --- a/DICUI.Library/Utilities/Validators.cs +++ b/DICUI.Library/Utilities/Validators.cs @@ -788,7 +788,7 @@ namespace DICUI.Utilities dataWriter.Recorder = recorder; var media = dataWriter.CurrentPhysicalMediaType; if (media != IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_UNKNOWN) - return Converters.IMAPIDiskTypeToMediaType(media); + return Converters.ToMediaType(media); } catch { @@ -816,17 +816,17 @@ namespace DICUI.Utilities case MediaType.DVD: case MediaType.FloppyDisk: case MediaType.HDDVD: - return Result.Success("{0} ready to dump", type.Name()); + return Result.Success("{0} ready to dump", type.LongName()); // Partially supported types case MediaType.GDROM: case MediaType.NintendoGameCubeGameDisc: case MediaType.NintendoWiiOpticalDisc: - return Result.Success("{0} partially supported for dumping", type.Name()); + return Result.Success("{0} partially supported for dumping", type.LongName()); // Special case for other supported tools case MediaType.UMD: - return Result.Success("{0} supported for submission info parsing", type.Name()); + return Result.Success("{0} supported for submission info parsing", type.LongName()); // Specifically unknown type case MediaType.NONE: @@ -834,7 +834,7 @@ namespace DICUI.Utilities // Undumpable but recognized types default: - return Result.Failure("{0} discs are not supported for dumping", type.Name()); + return Result.Failure("{0} discs are not supported for dumping", type.LongName()); } } diff --git a/DICUI.Test/DICUI.Test.csproj b/DICUI.Test/DICUI.Test.csproj index 6be8f167..fbd46649 100644 --- a/DICUI.Test/DICUI.Test.csproj +++ b/DICUI.Test/DICUI.Test.csproj @@ -62,13 +62,11 @@ - - diff --git a/DICUI.Test/Utilities/ConvertersTest.cs b/DICUI.Test/Utilities/ConvertersTest.cs index c9be309c..e87454ed 100644 --- a/DICUI.Test/Utilities/ConvertersTest.cs +++ b/DICUI.Test/Utilities/ConvertersTest.cs @@ -26,7 +26,7 @@ namespace DICUI.Test.Utilities [InlineData(DICCommand.XBOX, MediaType.DVD)] public void BaseCommandToMediaTypeTest(DICCommand command, MediaType? expected) { - MediaType? actual = Converters.BaseCommmandToMediaType(command); + MediaType? actual = command.ToMediaType(); Assert.Equal(expected, actual); } @@ -49,7 +49,7 @@ namespace DICUI.Test.Utilities [InlineData(DICCommand.XBOX, KnownSystem.MicrosoftXBOX)] public void BaseCommandToKnownSystemTest(DICCommand command, KnownSystem? expected) { - KnownSystem? actual = Converters.BaseCommandToKnownSystem(command); + KnownSystem? actual = Converters.ToKnownSystem(command); Assert.Equal(expected, actual); } @@ -63,7 +63,7 @@ namespace DICUI.Test.Utilities [InlineData(MediaType.NONE, null)] public void MediaTypeToExtensionTest(MediaType? mediaType, string expected) { - string actual = Converters.MediaTypeToExtension(mediaType); + string actual = Converters.Extension(mediaType); Assert.Equal(expected, actual); } diff --git a/DICUI.Test/Utilities/DICCommandExtensionsTest.cs b/DICUI.Test/Utilities/DICCommandExtensionsTest.cs deleted file mode 100644 index f8fa2722..00000000 --- a/DICUI.Test/Utilities/DICCommandExtensionsTest.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using DICUI.Data; -using DICUI.Utilities; -using Xunit; - -namespace DICUI.Test.Utilities -{ - public class DICCommandExtensionsTest - { - [Fact] - public void NameTest() - { - var values = (DICCommand[])Enum.GetValues(typeof(DICCommand)); - foreach(var command in values) - { - string expected = Converters.DICCommandToString(command); - string actual = command.Name(); - - Assert.Equal(expected, actual); - } - } - } -} diff --git a/DICUI.Test/Utilities/DICFlagExtensionsTest.cs b/DICUI.Test/Utilities/DICFlagExtensionsTest.cs deleted file mode 100644 index ba58dce6..00000000 --- a/DICUI.Test/Utilities/DICFlagExtensionsTest.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using DICUI.Data; -using DICUI.Utilities; -using Xunit; - -namespace DICUI.Test.Utilities -{ - public class DICFlagExtensionsTest - { - [Fact] - public void NameTest() - { - var values = (DICFlag[])Enum.GetValues(typeof(DICFlag)); - foreach(var command in values) - { - string expected = Converters.DICFlagToString(command); - string actual = command.Name(); - - Assert.Equal(expected, actual); - } - } - } -} diff --git a/DICUI.Test/Utilities/KnownSystemExtensionsTest.cs b/DICUI.Test/Utilities/KnownSystemExtensionsTest.cs index 1802a1e6..5e3f8643 100644 --- a/DICUI.Test/Utilities/KnownSystemExtensionsTest.cs +++ b/DICUI.Test/Utilities/KnownSystemExtensionsTest.cs @@ -7,19 +7,6 @@ namespace DICUI.Test.Utilities { public class KnownSystemExtensionsTest { - [Fact] - public void NameTest() - { - var values = (KnownSystem[])Enum.GetValues(typeof(KnownSystem)); - foreach(var system in values) - { - string expected = Converters.LongName(system); - string actual = ((KnownSystem?)system).Name(); - - Assert.Equal(expected, actual); - } - } - [Fact] public void IsMarkerTest() { @@ -42,7 +29,7 @@ namespace DICUI.Test.Utilities var values = (KnownSystemCategory[])Enum.GetValues(typeof(KnownSystemCategory)); foreach (var system in values) { - string actual = ((KnownSystem?)system).Name(); + string actual = ((KnownSystem?)system).LongName(); Assert.NotEqual("", actual); } } diff --git a/DICUI.Test/Utilities/MediaTypeExtensionsTest.cs b/DICUI.Test/Utilities/MediaTypeExtensionsTest.cs index a9da9065..30eaf099 100644 --- a/DICUI.Test/Utilities/MediaTypeExtensionsTest.cs +++ b/DICUI.Test/Utilities/MediaTypeExtensionsTest.cs @@ -7,27 +7,25 @@ namespace DICUI.Test.Utilities public class MediaTypeExtensionsTest { [Theory] - [InlineData(MediaType.CDROM)] - [InlineData(MediaType.LaserDisc)] - [InlineData(MediaType.NONE)] - public void NameTest(MediaType? mediaType) + [InlineData(MediaType.CDROM, "CD-ROM")] + [InlineData(MediaType.LaserDisc, "LD-ROM / LV-ROM")] + [InlineData(MediaType.NONE, "Unknown")] + public void NameTest(MediaType? mediaType, string expected) { - string expected = Converters.LongName(mediaType); - string actual = mediaType.Name(); + string actual = mediaType.LongName(); Assert.NotNull(actual); Assert.Equal(expected, actual); } [Theory] - [InlineData(MediaType.CDROM)] - [InlineData(MediaType.DVD)] - [InlineData(MediaType.LaserDisc)] - [InlineData(MediaType.FloppyDisk)] - [InlineData(MediaType.NONE)] - public void ExtensionTest(MediaType? mediaType) + [InlineData(MediaType.CDROM, ".bin")] + [InlineData(MediaType.DVD, ".iso")] + [InlineData(MediaType.LaserDisc, ".raw")] + [InlineData(MediaType.FloppyDisk, ".img")] + [InlineData(MediaType.NONE, null)] + public void ExtensionTest(MediaType? mediaType, string expected) { - string expected = Converters.MediaTypeToExtension(mediaType); string actual = mediaType.Extension(); Assert.Equal(expected, actual); diff --git a/DICUI/EnumDescriptionConverter.cs b/DICUI/EnumDescriptionConverter.cs index ffb04c9f..7490d3c8 100644 --- a/DICUI/EnumDescriptionConverter.cs +++ b/DICUI/EnumDescriptionConverter.cs @@ -14,13 +14,13 @@ namespace DICUI public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is DICCommand) - return ((DICCommand)value).Name(); + return ((DICCommand)value).LongName(); else if (value is DICFlag) - return ((DICFlag)value).Name(); + return ((DICFlag)value).LongName(); else if (value is MediaType?) - return ((MediaType?)value).Name(); + return ((MediaType?)value).LongName(); else if (value is KnownSystem?) - return ((KnownSystem?)value).Name(); + return ((KnownSystem?)value).LongName(); else return ""; } diff --git a/DICUI/KnownSystemComboBoxItem.cs b/DICUI/KnownSystemComboBoxItem.cs index ef91bd51..df5add00 100644 --- a/DICUI/KnownSystemComboBoxItem.cs +++ b/DICUI/KnownSystemComboBoxItem.cs @@ -26,9 +26,9 @@ namespace DICUI get { if (IsHeader()) - return "---------- " + (data as KnownSystemCategory?).Name() + " ----------"; + return "---------- " + (data as KnownSystemCategory?).LongName() + " ----------"; else - return (data as KnownSystem?).Name(); + return (data as KnownSystem?).LongName(); } } } diff --git a/DICUI/MediaTypeComboBoxItem.cs b/DICUI/MediaTypeComboBoxItem.cs index 3ea4894f..6f8f57ef 100644 --- a/DICUI/MediaTypeComboBoxItem.cs +++ b/DICUI/MediaTypeComboBoxItem.cs @@ -14,7 +14,7 @@ namespace DICUI public static implicit operator MediaType? (MediaTypeComboBoxItem item) => item.data; - public string Name { get { return data.Name(); } + public string Name { get { return data.LongName(); } } } } diff --git a/DICUI/Windows/MainWindow.xaml.cs b/DICUI/Windows/MainWindow.xaml.cs index 6f2120ca..fd76e281 100644 --- a/DICUI/Windows/MainWindow.xaml.cs +++ b/DICUI/Windows/MainWindow.xaml.cs @@ -291,7 +291,7 @@ namespace DICUI.Windows .ToDictionary( k => k.Key, v => v - .OrderBy(s => s.Name()) + .OrderBy(s => s.LongName()) .ToList() ); @@ -631,7 +631,7 @@ namespace DICUI.Windows { ViewModels.LoggerViewModel.VerboseLog("Trying to detect media type for drive {0}.. ", drive.Letter); _currentMediaType = Validators.GetDiscType(drive.Letter); - ViewModels.LoggerViewModel.VerboseLogLn(_currentMediaType == null ? "unable to detect." : ("detected " + _currentMediaType.Name() + ".")); + ViewModels.LoggerViewModel.VerboseLogLn(_currentMediaType == null ? "unable to detect." : ("detected " + _currentMediaType.LongName() + ".")); } } @@ -681,7 +681,7 @@ namespace DICUI.Windows else outputFilename = OutputFilenameTextBox.Text; - MediaType? mediaType = Converters.BaseCommmandToMediaType(_env.DICParameters.Command); + MediaType? mediaType = _env.DICParameters.Command.ToMediaType(); int mediaTypeIndex = _mediaTypes.IndexOf(mediaType); if (mediaTypeIndex > -1) MediaTypeComboBox.SelectedIndex = mediaTypeIndex;