From 39ce56d57933344cd8735f513e75ef5ad2f6d193 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 5 Jul 2018 13:18:01 -0700 Subject: [PATCH] Post-merge cleanup --- DICUI.Test/Utilities/DriveTest.cs | 6 ------ DICUI/Data/Constants.cs | 3 +++ DICUI/Data/Enumerations.cs | 3 +-- DICUI/MainWindow.xaml.cs | 21 +++++++++--------- DICUI/Utilities/Converters.cs | 34 +++++++++++++++++++++--------- DICUI/Utilities/DumpEnvironment.cs | 17 +++++++++------ DICUI/Utilities/Validators.cs | 12 ++++------- 7 files changed, 52 insertions(+), 44 deletions(-) diff --git a/DICUI.Test/Utilities/DriveTest.cs b/DICUI.Test/Utilities/DriveTest.cs index 2d96348e..8919999c 100644 --- a/DICUI.Test/Utilities/DriveTest.cs +++ b/DICUI.Test/Utilities/DriveTest.cs @@ -1,12 +1,6 @@ using DICUI.Utilities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Xunit; - namespace DICUI.Test.Utilities { public class DriveTest diff --git a/DICUI/Data/Constants.cs b/DICUI/Data/Constants.cs index 3c7b7ebc..e8e70de9 100644 --- a/DICUI/Data/Constants.cs +++ b/DICUI/Data/Constants.cs @@ -9,6 +9,9 @@ namespace DICUI.Data /// /// Variables for UI elements /// + /// + /// TODO: Pull out anything not a const string from this class + /// public static class UIElements { public const string StartDumping = "Start Dumping"; diff --git a/DICUI/Data/Enumerations.cs b/DICUI/Data/Enumerations.cs index 7286f260..f6aa1de4 100644 --- a/DICUI/Data/Enumerations.cs +++ b/DICUI/Data/Enumerations.cs @@ -3,7 +3,6 @@ /// /// Known systems /// - /// Ensure that Utilities methods are updated as well public enum KnownSystem { NONE = 0, @@ -137,7 +136,7 @@ #endregion - Custom = 0x0EADBEEF + Custom, } /// diff --git a/DICUI/MainWindow.xaml.cs b/DICUI/MainWindow.xaml.cs index 495ba6fb..6e4cbe7f 100644 --- a/DICUI/MainWindow.xaml.cs +++ b/DICUI/MainWindow.xaml.cs @@ -9,7 +9,6 @@ using System.Windows.Controls; using WinForms = System.Windows.Forms; using DICUI.Data; using DICUI.Utilities; -using static DICUI.Data.UIElements; namespace DICUI { @@ -81,7 +80,7 @@ namespace DICUI private void cmb_SystemType_SelectionChanged(object sender, SelectionChangedEventArgs e) { // If we're on a separator, go to the next item and return - if ((cmb_SystemType.SelectedItem as KnownSystemComboBoxItem).IsHeader()) + if ((cmb_SystemType.SelectedItem as UIElements.KnownSystemComboBoxItem).IsHeader()) { cmb_SystemType.SelectedIndex++; return; @@ -158,7 +157,7 @@ namespace DICUI /// private void PopulateMediaTypeAccordingToChosenSystem() { - KnownSystem? currentSystem = cmb_SystemType.SelectedItem as KnownSystemComboBoxItem; + KnownSystem? currentSystem = cmb_SystemType.SelectedItem as UIElements.KnownSystemComboBoxItem; if (currentSystem != null) { @@ -192,12 +191,12 @@ namespace DICUI .ToList() ); - List comboBoxItems = new List(); + List comboBoxItems = new List(); foreach (var group in mapping) { - comboBoxItems.Add(new KnownSystemComboBoxItem(group.Key)); - group.Value.ForEach(system => comboBoxItems.Add(new KnownSystemComboBoxItem(system))); + comboBoxItems.Add(new UIElements.KnownSystemComboBoxItem(group.Key)); + group.Value.ForEach(system => comboBoxItems.Add(new UIElements.KnownSystemComboBoxItem(system))); } cmb_SystemType.ItemsSource = comboBoxItems; @@ -266,7 +265,7 @@ namespace DICUI DICParameters = txt_Parameters.Text, - System = (KnownSystem?)(cmb_SystemType.SelectedItem as KnownSystemComboBoxItem), + System = (KnownSystem?)(cmb_SystemType.SelectedItem as UIElements.KnownSystemComboBoxItem), Type = cmb_MediaType.SelectedItem as MediaType? }; } @@ -297,7 +296,7 @@ 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 UIElements.KnownSystemComboBoxItem) ?? KnownSystem.NONE; MediaType? selectedMediaType = cmb_MediaType.SelectedItem as MediaType? ?? MediaType.NONE; Result result = GetSupportStatus(selectedSystem, selectedMediaType); @@ -427,7 +426,7 @@ namespace DICUI private void GetOutputNames() { Drive drive = cmb_DriveLetter.SelectedItem as Drive; - KnownSystem? systemType = (KnownSystem?)(cmb_SystemType.SelectedItem as KnownSystemComboBoxItem); + KnownSystem? systemType = (KnownSystem?)(cmb_SystemType.SelectedItem as UIElements.KnownSystemComboBoxItem); MediaType? mediaType = cmb_MediaType.SelectedItem as MediaType?; if (drive != null @@ -452,7 +451,7 @@ namespace DICUI private async void ScanAndShowProtection() { var env = DetermineEnvironment(); - if (env.DriveLetter != default(char)) + if (env.Drive.Letter != default(char)) { var tempContent = lbl_Status.Content; lbl_Status.Content = "Scanning for copy protection... this might take a while!"; @@ -460,7 +459,7 @@ namespace DICUI btn_Search.IsEnabled = false; btn_Scan.IsEnabled = false; - string protections = await Tasks.RunProtectionScan(env.DriveLetter + ":\\"); + string protections = await Tasks.RunProtectionScan(env.Drive.Letter + ":\\"); MessageBox.Show(protections, "Detected Protection", MessageBoxButton.OK, MessageBoxImage.Information); lbl_Status.Content = tempContent; diff --git a/DICUI/Utilities/Converters.cs b/DICUI/Utilities/Converters.cs index 4706b6d5..b7ba8f66 100644 --- a/DICUI/Utilities/Converters.cs +++ b/DICUI/Utilities/Converters.cs @@ -4,8 +4,8 @@ using System.Globalization; using System.Windows.Data; using IMAPI2; using DICUI.Data; -using static DICUI.Data.UIElements; +// TODO: Consider making the *Extensions classes into its own file namespace DICUI.Utilities { /// @@ -52,9 +52,15 @@ namespace DICUI.Utilities public static bool DoesSupportDriveSpeed(this KnownSystem? system) { - return system != KnownSystem.MicrosoftXBOX - && system != KnownSystem.MicrosoftXBOX360XDG2 - && system != KnownSystem.MicrosoftXBOX360XDG3; + switch (system) + { + case KnownSystem.MicrosoftXBOX: + case KnownSystem.MicrosoftXBOX360XDG2: + case KnownSystem.MicrosoftXBOX360XDG3: + return false; + default: + return true; + } } public static KnownSystemCategory Category(this KnownSystem? system) @@ -98,12 +104,18 @@ namespace DICUI.Utilities { 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 ""; + 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 ""; } } } @@ -117,6 +129,8 @@ namespace DICUI.Utilities { if (value is MediaType?) return ((MediaType?)value).Name(); + else if (value is KnownSystem?) + return ((KnownSystem?)value).Name(); else return ""; } diff --git a/DICUI/Utilities/DumpEnvironment.cs b/DICUI/Utilities/DumpEnvironment.cs index 85a6fa50..e7048a07 100644 --- a/DICUI/Utilities/DumpEnvironment.cs +++ b/DICUI/Utilities/DumpEnvironment.cs @@ -54,7 +54,10 @@ namespace DICUI.Utilities if (System == KnownSystem.Custom) { Validators.DetermineFlags(DICParameters, out Type, out System, out string letter, out string path); - Drive = Drive.Optical(String.IsNullOrWhiteSpace(letter) ? new char() : letter[0], ""); + if (Type == MediaType.Floppy) + Drive = Drive.Floppy(String.IsNullOrWhiteSpace(letter) ? new char() : letter[0]); + else + Drive = Drive.Optical(String.IsNullOrWhiteSpace(letter) ? new char() : letter[0], ""); OutputDirectory = Path.GetDirectoryName(path); OutputFilename = Path.GetFileName(path); } @@ -257,7 +260,7 @@ namespace DICUI.Utilities } break; case KnownSystem.SonyPlayStation: - mappings[Template.PlaystationEXEDateField] = GetPlayStationEXEDate(DriveLetter) ?? ""; + mappings[Template.PlaystationEXEDateField] = GetPlayStationEXEDate(Drive.Letter) ?? ""; mappings[Template.PlayStationEDCField] = GetMissingEDCCount(combinedBase + ".img_eccEdc.txt") > 0 ? "No" : "Yes"; // TODO: This needs to be verified mappings[Template.PlayStationAntiModchipField] = GetAntiModchipDetected(combinedBase + "_disc.txt") ? "Yes" : "No"; mappings[Template.PlayStationLibCryptField] = "No"; @@ -273,8 +276,8 @@ namespace DICUI.Utilities break; case KnownSystem.SonyPlayStation2: - mappings[Template.PlaystationEXEDateField] = GetPlayStationEXEDate(DriveLetter) ?? ""; - mappings[Template.VersionField] = GetPlayStation2Version(DriveLetter) ?? ""; + mappings[Template.PlaystationEXEDateField] = GetPlayStationEXEDate(Drive.Letter) ?? ""; + mappings[Template.VersionField] = GetPlayStation2Version(Drive.Letter) ?? ""; break; } @@ -355,8 +358,8 @@ namespace DICUI.Utilities } break; case KnownSystem.SonyPlayStation2: - mappings[Template.PlaystationEXEDateField] = GetPlayStationEXEDate(DriveLetter) ?? ""; - mappings[Template.VersionField] = GetPlayStation2Version(DriveLetter) ?? ""; + mappings[Template.PlaystationEXEDateField] = GetPlayStationEXEDate(Drive.Letter) ?? ""; + mappings[Template.VersionField] = GetPlayStation2Version(Drive.Letter) ?? ""; break; } break; @@ -730,7 +733,7 @@ namespace DICUI.Utilities return "(CHECK WITH PROTECTIONID)"; } - return Task.Run(() => Tasks.RunProtectionScan(DriveLetter + ":\\")).Result; + return Task.Run(() => Tasks.RunProtectionScan(Drive.Letter + ":\\")).Result; } /// diff --git a/DICUI/Utilities/Validators.cs b/DICUI/Utilities/Validators.cs index b90ec03f..7fc8a7e2 100644 --- a/DICUI/Utilities/Validators.cs +++ b/DICUI/Utilities/Validators.cs @@ -7,11 +7,11 @@ using System.Runtime.InteropServices; using System.Text.RegularExpressions; using IMAPI2; using DICUI.Data; -using DICUI.External; -using static DICUI.Data.UIElements; 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; } @@ -389,13 +389,9 @@ namespace DICUI.Utilities } /// - /// Create a list of systems matched to their respective enums + /// Create a list of systems /// - /// Systems matched to enums, if possible - /// - /// If something has a "string, null" value, it should be assumed that it is a separator - /// - /// TODO: Figure out a way that the sections can be generated more automatically + /// KnownSystems, if possible public static List CreateListOfSystems() { return Enum.GetValues(typeof(KnownSystem))