From d51adccab40e53e9b28774a6765d811950c45aeb Mon Sep 17 00:00:00 2001 From: Jacopo Santoni Date: Tue, 10 Jul 2018 01:35:46 +0200 Subject: [PATCH] Added new options (#90) * Split type combobox into system combobox and disc type combobox * corrected indentation for xaml file * fixed merge with head * fixed format * fixed issues for PR, added KnownSystem.CUSTOM * removed Updater.cs which ended by error in commit * fixed GetOuptutName() for new drive/system combobox * added 4 new options: quiet mode, paranoid mode, disable media type detect and c2 reread amount * added default C2 reread tries to config * fixed issues for PR * removed commented leftover --- DICUI.Test/Utilities/ConvertersTest.cs | 30 ++++++++----- DICUI.Test/Utilities/ValidatorsTest.cs | 2 +- DICUI/App.config | 2 + DICUI/DICUI.csproj | 1 + DICUI/MainWindow.xaml | 3 +- DICUI/MainWindow.xaml.cs | 16 ++++++- DICUI/Options.cs | 23 ++++++---- DICUI/OptionsWindow.xaml | 58 ++++++++++++++++++++++++-- DICUI/UI/ViewModels.cs | 52 +++++++++++++++++++++++ DICUI/Utilities/Converters.cs | 28 ++++++++++--- DICUI/Utilities/DumpEnvironment.cs | 14 ++++++- DICUI/Utilities/Validators.cs | 2 +- 12 files changed, 195 insertions(+), 36 deletions(-) create mode 100644 DICUI/UI/ViewModels.cs diff --git a/DICUI.Test/Utilities/ConvertersTest.cs b/DICUI.Test/Utilities/ConvertersTest.cs index c8c1acee..92a78512 100644 --- a/DICUI.Test/Utilities/ConvertersTest.cs +++ b/DICUI.Test/Utilities/ConvertersTest.cs @@ -92,20 +92,28 @@ namespace DICUI.Test.Utilities } [Theory] - [InlineData(KnownSystem.AppleMacintosh, MediaType.CD, new string[] { DICFlags.C2Opcode, "20", DICFlags.NoFixSubQSecuROM, DICFlags.ScanFileProtect })] - [InlineData(KnownSystem.AppleMacintosh, MediaType.LaserDisc, null)] - [InlineData(KnownSystem.NintendoGameCube, MediaType.GameCubeGameDisc, new string[] { DICFlags.Raw })] - [InlineData(KnownSystem.IBMPCCompatible, MediaType.DVD, new string[] { })] - public void KnownSystemAndMediaTypeToParametersTest(KnownSystem? knownSystem, MediaType? mediaType, string[] expected) + [InlineData(KnownSystem.AppleMacintosh, MediaType.LaserDisc, true, 20, null)] + [InlineData(KnownSystem.NintendoGameCube, MediaType.GameCubeGameDisc, false, 20, new string[] { DICFlags.Raw })] + [InlineData(KnownSystem.IBMPCCompatible, MediaType.DVD, false, 20, new string[] { })] + /* paranoid mode tests */ + [InlineData(KnownSystem.IBMPCCompatible, MediaType.CD, true, 1000, new string[] { DICFlags.C2Opcode, "1000", DICFlags.NoFixSubQSecuROM, DICFlags.ScanFileProtect, DICFlags.ScanSectorProtect, DICFlags.SubchannelReadLevel, "2"})] + [InlineData(KnownSystem.AppleMacintosh, MediaType.CD, false, 20, new string[] { DICFlags.C2Opcode, "20", DICFlags.NoFixSubQSecuROM, DICFlags.ScanFileProtect })] + [InlineData(KnownSystem.IBMPCCompatible, MediaType.DVD, true, 500, new string[] { DICFlags.CMI })] + [InlineData(KnownSystem.HDDVDVideo, MediaType.HDDVD, true, 500, new string[] { DICFlags.CMI })] + [InlineData(KnownSystem.IBMPCCompatible, MediaType.DVD, false, 500, new string[] { })] + [InlineData(KnownSystem.HDDVDVideo, MediaType.HDDVD, false, 500, new string[] { })] + /* reread c2 */ + [InlineData(KnownSystem.SegaDreamcast, MediaType.GDROM, false, 1000, new string[] { DICFlags.C2Opcode, "1000", })] + [InlineData(KnownSystem.SegaDreamcast, MediaType.GDROM, false, -1, new string[] { DICFlags.C2Opcode })] + + public void KnownSystemAndMediaTypeToParametersTest(KnownSystem? knownSystem, MediaType? mediaType, bool paranoid, int rereadC2, string[] expected) { - List actual = Converters.KnownSystemAndMediaTypeToParameters(knownSystem, mediaType); + List actual = Converters.KnownSystemAndMediaTypeToParameters(knownSystem, mediaType, paranoid, rereadC2); - if (expected == null) - Assert.Null(actual); + HashSet expectedSet = expected != null ? new HashSet(expected) : null; + HashSet actualSet = actual != null ? new HashSet(actual) : null; - else - foreach (string param in expected) - Assert.Contains(param, actual); + Assert.Equal(expectedSet, actualSet); } [Theory] diff --git a/DICUI.Test/Utilities/ValidatorsTest.cs b/DICUI.Test/Utilities/ValidatorsTest.cs index c2d69d54..9243de31 100644 --- a/DICUI.Test/Utilities/ValidatorsTest.cs +++ b/DICUI.Test/Utilities/ValidatorsTest.cs @@ -23,7 +23,7 @@ namespace DICUI.Test.Utilities [Fact] public void CreateListOfSystemsTest() { - int expected = Enum.GetValues(typeof(KnownSystem)).Length - 4; // - 4 for markers categories + int expected = Enum.GetValues(typeof(KnownSystem)).Length - 5; // - 4 -1 for markers categories and KnownSystem.NONE var actual = Validators.CreateListOfSystems(); Assert.Equal(expected, actual.Count); } diff --git a/DICUI/App.config b/DICUI/App.config index 3140b2cf..4decd164 100644 --- a/DICUI/App.config +++ b/DICUI/App.config @@ -6,5 +6,7 @@ + + diff --git a/DICUI/DICUI.csproj b/DICUI/DICUI.csproj index da38deb1..20eb90e4 100644 --- a/DICUI/DICUI.csproj +++ b/DICUI/DICUI.csproj @@ -103,6 +103,7 @@ + diff --git a/DICUI/MainWindow.xaml b/DICUI/MainWindow.xaml index dce06998..84fd0b82 100644 --- a/DICUI/MainWindow.xaml +++ b/DICUI/MainWindow.xaml @@ -6,6 +6,7 @@ xmlns:local="clr-namespace:DICUI" xmlns:utilities="clr-namespace:DICUI.Utilities" mc:Ignorable="d" + x:Name="mainWindow" Title="Disc Image Creator GUI" Height="450" Width="600" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize"> @@ -30,7 +31,7 @@ - + diff --git a/DICUI/MainWindow.xaml.cs b/DICUI/MainWindow.xaml.cs index 10c3125a..a2a81b1e 100644 --- a/DICUI/MainWindow.xaml.cs +++ b/DICUI/MainWindow.xaml.cs @@ -26,13 +26,18 @@ namespace DICUI private Options _options; private OptionsWindow _optionsWindow; + public bool QuietMode { get; set; } + public MainWindow() { + QuietMode = true; + InitializeComponent(); // Initializes and load Options object _options = new Options(); _options.Load(); + ViewModels.OptionsViewModel = new OptionsViewModel(_options); // Disable buttons until we load fully StartStopButton.IsEnabled = false; @@ -40,6 +45,7 @@ namespace DICUI CopyProtectScanButton.IsEnabled = false; } + #region Events protected override void OnContentRendered(EventArgs e) @@ -181,6 +187,7 @@ namespace DICUI { GetOutputNames(); SetSupportedDriveSpeed(); + EnsureDiscInformation(); } #endregion @@ -228,6 +235,8 @@ namespace DICUI List comboBoxItems = new List(); + comboBoxItems.Add(new KnownSystemComboBoxItem(KnownSystem.NONE)); + foreach (var group in mapping) { comboBoxItems.Add(new KnownSystemComboBoxItem(group.Key)); @@ -303,6 +312,10 @@ namespace DICUI DICParameters = ParametersTextBox.Text, + QuietMode = _options.QuietMode, + ParanoidMode = _options.ParanoidMode, + RereadAmountC2 = _options.RereadAmountForC2, + System = SystemTypeComboBox.SelectedItem as KnownSystemComboBoxItem, Type = MediaTypeComboBox.SelectedItem as MediaType? }; @@ -475,7 +488,8 @@ namespace DICUI return; // Get the current optical disc type - _currentMediaType = Validators.GetDiscType(drive.Letter); + if (!_options.SkipMediaTypeDetection) + _currentMediaType = Validators.GetDiscType(drive.Letter); } /// diff --git a/DICUI/Options.cs b/DICUI/Options.cs index 648cd835..eb5cecb2 100644 --- a/DICUI/Options.cs +++ b/DICUI/Options.cs @@ -14,26 +14,26 @@ namespace DICUI public int preferredDumpSpeedCD { get; set; } public int preferredDumpSpeedDVD { get; set; } + public bool QuietMode { get; set; } + public bool ParanoidMode { get; set; } + public int RereadAmountForC2 { get; set; } + + public bool SkipMediaTypeDetection { get; set; } + public void Save() { Configuration configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); //TODO: reflection is used + //TODO: is remove needed, doesn't the value get directly overridden Array.ForEach( GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance), p => { configFile.AppSettings.Settings.Remove(p.Name); - configFile.AppSettings.Settings.Add(p.Name, p.GetValue(this) as string); + configFile.AppSettings.Settings.Add(p.Name, Convert.ToString(p.GetValue(this))); } ); - - //TODO: is remove needed, doesn't the value get directly overridden? - configFile.AppSettings.Settings.Remove("preferredDumpSpeedCD"); - configFile.AppSettings.Settings.Add("preferredDumpSpeedCD", Convert.ToString(preferredDumpSpeedCD)); - - configFile.AppSettings.Settings.Remove("preferredDumpSpeedDVD"); - configFile.AppSettings.Settings.Add("preferredDumpSpeedDVD", Convert.ToString(preferredDumpSpeedDVD)); - + configFile.Save(ConfigurationSaveMode.Modified); } @@ -46,6 +46,11 @@ namespace DICUI this.preferredDumpSpeedCD = Int32.TryParse(ConfigurationManager.AppSettings["preferredDumpSpeedCD"], out int maxDumpSpeedCD) ? maxDumpSpeedCD : 72; this.preferredDumpSpeedDVD = Int32.TryParse(ConfigurationManager.AppSettings["preferredDumpSpeedDVD"], out int maxDumpSpeedDVD) ? maxDumpSpeedDVD : 72; + + this.QuietMode = Boolean.TryParse(ConfigurationManager.AppSettings["QuietMode"], out bool quietMode) ? quietMode : false; + this.ParanoidMode = Boolean.TryParse(ConfigurationManager.AppSettings["ParanoidMode"], out bool paranoidMode) ? paranoidMode : false; + this.SkipMediaTypeDetection = Boolean.TryParse(ConfigurationManager.AppSettings["SkipMediaTypeDetection"], out bool skipMediaTypeDetection) ? skipMediaTypeDetection : false; + this.RereadAmountForC2 = Int32.TryParse(ConfigurationManager.AppSettings["RereadAmountForC2"], out int rereadAmountForC2) ? rereadAmountForC2 : 20; } diff --git a/DICUI/OptionsWindow.xaml b/DICUI/OptionsWindow.xaml index fc8624be..352d78c4 100644 --- a/DICUI/OptionsWindow.xaml +++ b/DICUI/OptionsWindow.xaml @@ -4,18 +4,21 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:lui="clr-namespace:DICUI.UI" + xmlns:l="clr-namespace:DICUI" mc:Ignorable="d" - Title="Options" Height="300" Width="515.132"> + Title="Options" Height="400" Width="515.132"> + + - + @@ -65,8 +68,55 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DICUI/UI/ViewModels.cs b/DICUI/UI/ViewModels.cs new file mode 100644 index 00000000..7693f750 --- /dev/null +++ b/DICUI/UI/ViewModels.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DICUI.UI +{ + public class OptionsViewModel + { + private Options _options; + + public OptionsViewModel(Options options) + { + this._options = options; + } + + public bool QuietMode + { + get { return _options.QuietMode; } + set { _options.QuietMode = value; } + } + + public bool ParanoidMode + { + get { return _options.ParanoidMode; } + set { _options.ParanoidMode = value; } + } + + public bool SkipMediaTypeDetection + { + get { return _options.SkipMediaTypeDetection; } + set { _options.SkipMediaTypeDetection = value; } + } + + public string RereadAmountForC2 + { + get { return Convert.ToString(_options.RereadAmountForC2); } + set + { + if (Int32.TryParse(value, out int result)) + _options.RereadAmountForC2 = result; + } + } + } + + public static class ViewModels + { + public static OptionsViewModel OptionsViewModel { get; set; } + } + +} diff --git a/DICUI/Utilities/Converters.cs b/DICUI/Utilities/Converters.cs index e4c48ccb..4f2234ee 100644 --- a/DICUI/Utilities/Converters.cs +++ b/DICUI/Utilities/Converters.cs @@ -262,7 +262,7 @@ namespace DICUI.Utilities /// KnownSystem value to check /// MediaType value to check /// List of strings representing the parameters - public static List KnownSystemAndMediaTypeToParameters(KnownSystem? sys, MediaType? type) + public static List KnownSystemAndMediaTypeToParameters(KnownSystem? sys, MediaType? type, bool paranoid, int RereadAmountC2) { // First check to see if the combination of system and MediaType is valid var validTypes = Validators.GetValidMediaTypes(sys); @@ -271,12 +271,16 @@ namespace DICUI.Utilities return null; } + string rereadAmount = RereadAmountC2 > 0 ? Convert.ToString(RereadAmountC2) : null; + // Now sort based on disc type List parameters = new List(); switch (type) { case MediaType.CD: - parameters.Add(DICFlags.C2Opcode); parameters.Add("20"); + parameters.Add(DICFlags.C2Opcode); + if (rereadAmount != null) + parameters.Add(rereadAmount); switch (sys) { @@ -284,11 +288,19 @@ namespace DICUI.Utilities case KnownSystem.IBMPCCompatible: parameters.Add(DICFlags.NoFixSubQSecuROM); parameters.Add(DICFlags.ScanFileProtect); - parameters.Add(DICFlags.ScanSectorProtect); + + if (paranoid) + { + parameters.Add(DICFlags.ScanSectorProtect); + parameters.Add(DICFlags.SubchannelReadLevel); parameters.Add("2"); + } + break; + case KnownSystem.NECPCEngineTurboGrafxCD: parameters.Add(DICFlags.MCN); break; + case KnownSystem.SonyPlayStation: parameters.Add(DICFlags.ScanAntiMod); parameters.Add(DICFlags.NoFixSubQLibCrypt); @@ -296,13 +308,17 @@ namespace DICUI.Utilities } break; case MediaType.DVD: - // Currently no defaults set + if (paranoid) + parameters.Add(DICFlags.CMI); break; case MediaType.GDROM: - parameters.Add(DICFlags.C2Opcode); parameters.Add("20"); + parameters.Add(DICFlags.C2Opcode); + if (rereadAmount != null) + parameters.Add(rereadAmount); break; case MediaType.HDDVD: - // Currently no defaults set + if (paranoid) + parameters.Add(DICFlags.CMI); break; case MediaType.BluRay: // Currently no defaults set diff --git a/DICUI/Utilities/DumpEnvironment.cs b/DICUI/Utilities/DumpEnvironment.cs index c3bda4ba..617cb58f 100644 --- a/DICUI/Utilities/DumpEnvironment.cs +++ b/DICUI/Utilities/DumpEnvironment.cs @@ -51,6 +51,11 @@ namespace DICUI.Utilities public bool IsFloppy { get => Drive.IsFloppy; } public string DICParameters; + // extra DIC arguments + public bool QuietMode; + public bool ParanoidMode; + public int RereadAmountC2; + // External process information private Process dicProcess; @@ -202,12 +207,17 @@ namespace DICUI.Utilities return null; string command = Converters.KnownSystemAndMediaTypeToBaseCommand(System, Type); - List defaultParams = Converters.KnownSystemAndMediaTypeToParameters(System, Type); + List defaultParams = Converters.KnownSystemAndMediaTypeToParameters(System, Type, ParanoidMode, RereadAmountC2); + + if (QuietMode) + defaultParams.Add(DICFlags.DisableBeep); + return command + " " + Drive.Letter + " \"" + Path.Combine(OutputDirectory, OutputFilename) + "\" " + (Type.DoesSupportDriveSpeed() && System.DoesSupportDriveSpeed() ? driveSpeed + " " : "") - + string.Join(" ", defaultParams); + + string.Join(" ", defaultParams) + ; } return null; diff --git a/DICUI/Utilities/Validators.cs b/DICUI/Utilities/Validators.cs index 78971e7c..aa04011d 100644 --- a/DICUI/Utilities/Validators.cs +++ b/DICUI/Utilities/Validators.cs @@ -379,7 +379,7 @@ namespace DICUI.Utilities { return Enum.GetValues(typeof(KnownSystem)) .OfType() - .Where(s => !s.IsMarker()) + .Where(s => !s.IsMarker() && s != KnownSystem.NONE) .ToList(); }