From 56eaf7c2c58711db25120986245e2ebb1c9bfe04 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 28 Jun 2018 19:41:18 -0700 Subject: [PATCH] Add Test Project (#79) * Add Test project; Migrate so there's not an external folder * Add Test project; Migrate so that there's not an external folder * Fix build; Add remaining test classes (skeletons) * Fix more paths * Make unit tests runnable, fix issue found by unit tests * Add more tests, fix more things found by tests * Add skeleton for ValidatorsTest, fix OrderedDictionary * Add UIElementsTest * Add new test classes, slightly update Result * Implement DumpEnvirionment tests; fix minor things from testing * Add Tasks testing skeletons; Reorder methods and change access modifiers for some * Update notes for DumpInformation tests * Implement a couple Validators tests; fix ValidateParameters * Implement DetermineFlagsTest * Make one test more readable * More cleanup around ValidateParameters * Split check * WiiU is not supported by /raw command * Add TODO question * Update TODO with a plan --- DICUI.Test/DICUI.Test.csproj | 101 +++ DICUI.Test/Data/UIElementsTest.cs | 21 + DICUI.Test/DumpEnvironmentTest.cs | 74 +++ DICUI.Test/Properties/AssemblyInfo.cs | 20 + DICUI.Test/ResultTest.cs | 39 ++ DICUI.Test/TasksTest.cs | 30 + DICUI.Test/Utilities/ConvertersTest.cs | 123 ++++ DICUI.Test/Utilities/DumpInformationTest.cs | 61 ++ .../Utilities/KnownSystemExtensionsTest.cs | 21 + .../Utilities/MediaTypeExtensionsTest.cs | 48 ++ DICUI.Test/Utilities/ValidatorsTest.cs | 76 +++ DICUI.Test/packages.config | 14 + DICUI.sln | 8 +- App.config => DICUI/App.config | 0 App.xaml => DICUI/App.xaml | 0 App.xaml.cs => DICUI/App.xaml.cs | 0 DICUI.csproj => DICUI/DICUI.csproj | 0 {Data => DICUI/Data}/Constants.cs | 1 - {Data => DICUI/Data}/Enumerations.cs | 0 .../External}/IOrderedDictionary.cs | 0 .../External}/OrderedDictionary.cs | 6 +- Icon.ico => DICUI/Icon.ico | Bin MainWindow.xaml => DICUI/MainWindow.xaml | 0 .../MainWindow.xaml.cs | 6 +- Options.cs => DICUI/Options.cs | 0 .../OptionsWindow.xaml | 0 .../OptionsWindow.xaml.cs | 0 .../Properties}/AssemblyInfo.cs | 0 Tasks.cs => DICUI/Tasks.cs | 243 ++++---- {Utilities => DICUI/Utilities}/Converters.cs | 41 +- .../Utilities}/DumpInformation.cs | 13 +- {Utilities => DICUI/Utilities}/Validators.cs | 577 +++++++----------- appveyor.yml | 2 +- 33 files changed, 1026 insertions(+), 499 deletions(-) create mode 100644 DICUI.Test/DICUI.Test.csproj create mode 100644 DICUI.Test/Data/UIElementsTest.cs create mode 100644 DICUI.Test/DumpEnvironmentTest.cs create mode 100644 DICUI.Test/Properties/AssemblyInfo.cs create mode 100644 DICUI.Test/ResultTest.cs create mode 100644 DICUI.Test/TasksTest.cs create mode 100644 DICUI.Test/Utilities/ConvertersTest.cs create mode 100644 DICUI.Test/Utilities/DumpInformationTest.cs create mode 100644 DICUI.Test/Utilities/KnownSystemExtensionsTest.cs create mode 100644 DICUI.Test/Utilities/MediaTypeExtensionsTest.cs create mode 100644 DICUI.Test/Utilities/ValidatorsTest.cs create mode 100644 DICUI.Test/packages.config rename App.config => DICUI/App.config (100%) rename App.xaml => DICUI/App.xaml (100%) rename App.xaml.cs => DICUI/App.xaml.cs (100%) rename DICUI.csproj => DICUI/DICUI.csproj (100%) rename {Data => DICUI/Data}/Constants.cs (99%) rename {Data => DICUI/Data}/Enumerations.cs (100%) rename {External => DICUI/External}/IOrderedDictionary.cs (100%) rename {External => DICUI/External}/OrderedDictionary.cs (98%) rename Icon.ico => DICUI/Icon.ico (100%) rename MainWindow.xaml => DICUI/MainWindow.xaml (100%) rename MainWindow.xaml.cs => DICUI/MainWindow.xaml.cs (99%) rename Options.cs => DICUI/Options.cs (100%) rename OptionsWindow.xaml => DICUI/OptionsWindow.xaml (100%) rename OptionsWindow.xaml.cs => DICUI/OptionsWindow.xaml.cs (100%) rename {Properties => DICUI/Properties}/AssemblyInfo.cs (100%) rename Tasks.cs => DICUI/Tasks.cs (88%) rename {Utilities => DICUI/Utilities}/Converters.cs (96%) rename {Utilities => DICUI/Utilities}/DumpInformation.cs (99%) rename {Utilities => DICUI/Utilities}/Validators.cs (79%) diff --git a/DICUI.Test/DICUI.Test.csproj b/DICUI.Test/DICUI.Test.csproj new file mode 100644 index 00000000..2c2aeea3 --- /dev/null +++ b/DICUI.Test/DICUI.Test.csproj @@ -0,0 +1,101 @@ + + + + + + + + Debug + AnyCPU + {7CC064D2-38AB-4A05-8519-28660DE4562A} + Library + Properties + DICUI.Test + DICUI.Test + v4.6.1 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.CodeCoverage.1.0.3\lib\netstandard1.0\Microsoft.VisualStudio.CodeCoverage.Shim.dll + + + + + ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll + + + ..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll + + + ..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll + + + ..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll + + + + + + + + + + + + + + + + + + + + {7b1b75eb-8940-466f-bd51-76471a57f9be} + DICUI + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + \ No newline at end of file diff --git a/DICUI.Test/Data/UIElementsTest.cs b/DICUI.Test/Data/UIElementsTest.cs new file mode 100644 index 00000000..b1964624 --- /dev/null +++ b/DICUI.Test/Data/UIElementsTest.cs @@ -0,0 +1,21 @@ +using System.Linq; +using DICUI.Data; +using Xunit; + +namespace DICUI.Test.Data +{ + public class UIElementsTest + { + [Theory] + [InlineData(MediaType.CD, 72)] + [InlineData(MediaType.DVD, 24)] + [InlineData(MediaType.BluRay, 16)] + [InlineData(MediaType.LaserDisc, 72)] // TODO: Update when fully determined + [InlineData(null, 72)] // TODO: Update when fully determined + public void GetAllowedDriveSpeedForMediaTypeTest(MediaType? mediaType, int maxExpected) + { + var actual = UIElements.GetAllowedDriveSpeedsForMediaType(mediaType); + Assert.Equal(maxExpected, actual.Last()); + } + } +} diff --git a/DICUI.Test/DumpEnvironmentTest.cs b/DICUI.Test/DumpEnvironmentTest.cs new file mode 100644 index 00000000..bdafdaa1 --- /dev/null +++ b/DICUI.Test/DumpEnvironmentTest.cs @@ -0,0 +1,74 @@ +using DICUI.Data; +using Xunit; + +namespace DICUI.Test +{ + public class DumpEnvironmentTest + { + [Theory] + [InlineData(null, false, MediaType.NONE, false)] + [InlineData("", false, MediaType.NONE, false)] + [InlineData("cd F test.bin 8 /c2 20", false, MediaType.CD, true)] + [InlineData("fd A test.img", true, MediaType.Floppy, true)] + [InlineData("dvd X test.iso 8 /raw", false, MediaType.Floppy, false)] + [InlineData("stop D", false, MediaType.DVD, true)] + public void IsConfigurationValidTest(string parameters, bool isFloppy, MediaType? mediaType, bool expected) + { + var env = new DumpEnvironment + { + DICParameters = parameters, + IsFloppy = isFloppy, + Type = mediaType, + }; + + bool actual = env.IsConfigurationValid(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null, null, new char(), null, null)] + [InlineData("", null, null, new char(), null, null)] + [InlineData("cd F test.bin 8 /c2 20", MediaType.CD, KnownSystem.IBMPCCompatible, 'F', "", "test.bin")] + [InlineData("fd A blah\\test.img", MediaType.Floppy, KnownSystem.IBMPCCompatible, 'A', "blah", "test.img")] + [InlineData("dvd X super\\blah\\test.iso 8 /raw", MediaType.GameCubeGameDisc, KnownSystem.NintendoGameCube, 'X', "super\\blah", "test.iso")] + [InlineData("stop D", null, null, 'D', null, null)] + public void AdjustForCustomConfigurationTest(string parameters, MediaType? expectedMediaType, KnownSystem? expectedKnownSystem, char expectedDriveLetter, string expectedOutputDirectory, string expectedOutputFilename) + { + var env = new DumpEnvironment + { + DICParameters = parameters, + System = KnownSystem.Custom, + }; + + env.AdjustForCustomConfiguration(); + Assert.Equal(parameters, env.DICParameters); + Assert.Equal(expectedMediaType, env.Type); + Assert.Equal(expectedKnownSystem, env.System); + Assert.Equal(expectedDriveLetter, env.DriveLetter); + Assert.Equal(expectedOutputDirectory, env.OutputDirectory); + Assert.Equal(expectedOutputFilename, env.OutputFilename); + } + + [Theory] + [InlineData(null, null, null, null)] + [InlineData(" ", "", " ", "")] + [InlineData("super", "blah.bin", "super", "blah.bin")] + [InlineData("super\\hero", "blah.bin", "super\\hero", "blah.bin")] + [InlineData("super.hero", "blah.bin", "super_hero", "blah.bin")] + [InlineData("superhero", "blah.rev.bin", "superhero", "blah_rev.bin")] + [InlineData("super&hero", "blah.bin", "super_hero", "blah.bin")] + [InlineData("superhero", "blah&foo.bin", "superhero", "blah_foo.bin")] + public void FixOutputPathsTest(string outputDirectory, string outputFilename, string expectedOutputDirectory, string expectedOutputFilename) + { + var env = new DumpEnvironment + { + OutputDirectory = outputDirectory, + OutputFilename = outputFilename, + }; + + env.FixOutputPaths(); + Assert.Equal(expectedOutputDirectory, env.OutputDirectory); + Assert.Equal(expectedOutputFilename, env.OutputFilename); + } + } +} diff --git a/DICUI.Test/Properties/AssemblyInfo.cs b/DICUI.Test/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..48edce3a --- /dev/null +++ b/DICUI.Test/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("DICUI.Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DICUI.Test")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("7cc064d2-38ab-4a05-8519-28660de4562a")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DICUI.Test/ResultTest.cs b/DICUI.Test/ResultTest.cs new file mode 100644 index 00000000..ce41a96f --- /dev/null +++ b/DICUI.Test/ResultTest.cs @@ -0,0 +1,39 @@ +using Xunit; + +namespace DICUI.Test +{ + public class ResultTest + { + [Fact] + public void ResultSuccessTest() + { + Result actual = Result.Success(); + Assert.Empty(actual.Message); + + string message = "Success!"; + actual = Result.Success(message); + Assert.Equal(message, actual.Message); + + message = "Success! {0}"; + string parameter = "Parameter"; + actual = Result.Success(message, parameter); + Assert.Equal(string.Format(message, parameter), actual.Message); + } + + [Fact] + public void ResultFailureTest() + { + Result actual = Result.Failure(); + Assert.Empty(actual.Message); + + string message = "Failure!"; + actual = Result.Failure(message); + Assert.Equal(message, actual.Message); + + message = "Failure! {0}"; + string parameter = "Parameter"; + actual = Result.Failure(message, parameter); + Assert.Equal(string.Format(message, parameter), actual.Message); + } + } +} diff --git a/DICUI.Test/TasksTest.cs b/DICUI.Test/TasksTest.cs new file mode 100644 index 00000000..85dc6137 --- /dev/null +++ b/DICUI.Test/TasksTest.cs @@ -0,0 +1,30 @@ +using DICUI.Data; +using DICUI.Utilities; +using Xunit; + +namespace DICUI.Test +{ + public class TasksTest + { + [Fact] + public void EjectDiscTest() + { + // TODO: Implement + Assert.True(true); + } + + [Fact] + public void CancelDumpingTest() + { + // TODO: Implement + Assert.True(true); + } + + [Fact] + public void StartDumpingTest() + { + // TODO: Implement + Assert.True(true); + } + } +} diff --git a/DICUI.Test/Utilities/ConvertersTest.cs b/DICUI.Test/Utilities/ConvertersTest.cs new file mode 100644 index 00000000..ca554c7f --- /dev/null +++ b/DICUI.Test/Utilities/ConvertersTest.cs @@ -0,0 +1,123 @@ +using System.Collections.Generic; +using DICUI.Data; +using DICUI.Utilities; +using Xunit; + +namespace DICUI.Test.Utilities +{ + public class ConvertersTest + { + [Theory] + [InlineData(DICCommands.Audio, MediaType.CD)] + [InlineData(DICCommands.BluRay, MediaType.BluRay)] + [InlineData(DICCommands.Close, null)] + [InlineData(DICCommands.CompactDisc, MediaType.CD)] + [InlineData(DICCommands.Data, MediaType.CD)] + [InlineData(DICCommands.DigitalVideoDisc, MediaType.DVD)] + [InlineData(DICCommands.Eject, null)] + [InlineData(DICCommands.Floppy, MediaType.Floppy)] + [InlineData(DICCommands.GDROM, MediaType.GDROM)] + [InlineData(DICCommands.MDS, null)] + [InlineData(DICCommands.Reset, null)] + [InlineData(DICCommands.Start, null)] + [InlineData(DICCommands.Stop, null)] + [InlineData(DICCommands.Sub, null)] + [InlineData(DICCommands.Swap, MediaType.GDROM)] + [InlineData(DICCommands.XBOX, MediaType.DVD)] + public void BaseCommandToMediaTypeTest(string command, MediaType? expected) + { + MediaType? actual = Converters.BaseCommmandToMediaType(command); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(DICCommands.Audio, KnownSystem.AudioCD)] + [InlineData(DICCommands.BluRay, KnownSystem.SonyPlayStation3)] + [InlineData(DICCommands.Close, null)] + [InlineData(DICCommands.CompactDisc, KnownSystem.IBMPCCompatible)] + [InlineData(DICCommands.Data, KnownSystem.IBMPCCompatible)] + [InlineData(DICCommands.DigitalVideoDisc, KnownSystem.IBMPCCompatible)] + [InlineData(DICCommands.Eject, null)] + [InlineData(DICCommands.Floppy, KnownSystem.IBMPCCompatible)] + [InlineData(DICCommands.GDROM, KnownSystem.SegaDreamcast)] + [InlineData(DICCommands.MDS, null)] + [InlineData(DICCommands.Reset, null)] + [InlineData(DICCommands.Start, null)] + [InlineData(DICCommands.Stop, null)] + [InlineData(DICCommands.Sub, null)] + [InlineData(DICCommands.Swap, KnownSystem.SegaDreamcast)] + [InlineData(DICCommands.XBOX, KnownSystem.MicrosoftXBOX)] + public void BaseCommandToKnownSystemTest(string command, KnownSystem? expected) + { + KnownSystem? actual = Converters.BaseCommandToKnownSystem(command); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(MediaType.CD, ".bin")] + [InlineData(MediaType.DVD, ".iso")] + [InlineData(MediaType.LaserDisc, ".raw")] + [InlineData(MediaType.WiiUOpticalDisc, ".wud")] + [InlineData(MediaType.Floppy, ".img")] + [InlineData(MediaType.Cassette, ".wav")] + [InlineData(MediaType.NONE, null)] + public void MediaTypeToExtensionTest(MediaType? mediaType, string expected) + { + string actual = Converters.MediaTypeToExtension(mediaType); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(MediaType.CD, "CD-ROM")] + [InlineData(MediaType.LaserDisc, "LaserDisc")] + [InlineData(MediaType.NONE, "Unknown")] + public void MediaTypeToStringTest(MediaType? mediaType, string expected) + { + string actual = Converters.MediaTypeToString(mediaType); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(KnownSystem.MicrosoftXBOX, MediaType.CD, DICCommands.XBOX)] + [InlineData(KnownSystem.MicrosoftXBOX, MediaType.DVD, DICCommands.XBOX)] + [InlineData(KnownSystem.MicrosoftXBOX, MediaType.LaserDisc, null)] + [InlineData(KnownSystem.SegaNu, MediaType.BluRay, DICCommands.BluRay)] + [InlineData(KnownSystem.AppleMacintosh, MediaType.Floppy, DICCommands.Floppy)] + [InlineData(KnownSystem.RawThrillsVarious, MediaType.GDROM, null)] + public void KnownSystemAndMediaTypeToBaseCommandTest(KnownSystem? knownSystem, MediaType? mediaType, string expected) + { + string actual = Converters.KnownSystemAndMediaTypeToBaseCommand(knownSystem, mediaType); + Assert.Equal(expected, actual); + } + + [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) + { + List actual = Converters.KnownSystemAndMediaTypeToParameters(knownSystem, mediaType); + + if (expected == null) + Assert.Null(actual); + + else + foreach (string param in expected) + Assert.Contains(param, actual); + } + + [Theory] + [InlineData(KnownSystem.MicrosoftXBOX, "Microsoft XBOX")] + [InlineData(KnownSystem.NECPC88, "NEC PC-88")] + [InlineData(KnownSystem.KonamiPython, "Konami Python")] + [InlineData(KnownSystem.HDDVDVideo, "HD-DVD-Video")] + [InlineData(KnownSystem.Custom, "Custom Input")] + [InlineData(KnownSystem.NONE, "Unknown")] + public void KnownSystemToStringTest(KnownSystem? knownSystem, string expected) + { + string actual = Converters.KnownSystemToString(knownSystem); + Assert.Equal(expected, actual); + } + } +} diff --git a/DICUI.Test/Utilities/DumpInformationTest.cs b/DICUI.Test/Utilities/DumpInformationTest.cs new file mode 100644 index 00000000..1057f411 --- /dev/null +++ b/DICUI.Test/Utilities/DumpInformationTest.cs @@ -0,0 +1,61 @@ +using DICUI.Data; +using DICUI.Utilities; +using Xunit; + +namespace DICUI.Test.Utilities +{ + public class DumpInformationTest + { + [Fact] + public void GetFirstTrackTest() + { + // TODO: Implement + Assert.True(true); + } + + [Theory] + [InlineData(MediaType.CD)] + [InlineData(MediaType.DVD)] + [InlineData(MediaType.Floppy)] + [InlineData(MediaType.LaserDisc)] + public void FoundAllFilesTest(MediaType? mediaType) + { + // TODO: Implement + // TODO: Get sample output data for each of the major types + Assert.True(true); + } + + [Theory] + [InlineData(KnownSystem.AppleMacintosh, MediaType.CD)] + [InlineData(KnownSystem.PhilipsCDi, MediaType.CD)] + [InlineData(KnownSystem.SegaSaturn, MediaType.CD)] + [InlineData(KnownSystem.SonyPlayStation, MediaType.CD)] + [InlineData(KnownSystem.SonyPlayStation2, MediaType.CD)] + [InlineData(KnownSystem.AppleMacintosh, MediaType.DVD)] + [InlineData(KnownSystem.DVDVideo, MediaType.DVD)] + [InlineData(KnownSystem.MicrosoftXBOX, MediaType.DVD)] + [InlineData(KnownSystem.SonyPlayStation2, MediaType.DVD)] + [InlineData(KnownSystem.BDVideo, MediaType.BluRay)] + [InlineData(KnownSystem.AUSCOMSystem1, MediaType.Cassette)] + public void ExtractOutputInformation(KnownSystem? knownSystem, MediaType? mediaType) + { + // TODO: Implement + // TODO: Get sample output data for each of the major types + Assert.True(true); + } + + [Fact] + public void FormatOutputDataTest() + { + // TODO: Implement + Assert.True(true); + } + + [Fact] + public void WriteOutputDataTest() + { + // TODO: Implement + Assert.True(true); + } + } +} diff --git a/DICUI.Test/Utilities/KnownSystemExtensionsTest.cs b/DICUI.Test/Utilities/KnownSystemExtensionsTest.cs new file mode 100644 index 00000000..0e1fed27 --- /dev/null +++ b/DICUI.Test/Utilities/KnownSystemExtensionsTest.cs @@ -0,0 +1,21 @@ +using DICUI.Data; +using DICUI.Utilities; +using Xunit; + +namespace DICUI.Test.Utilities +{ + public class KnownSystemExtensionsTest + { + [Theory] + [InlineData(KnownSystem.AppleMacintosh, true)] + [InlineData(KnownSystem.MicrosoftXBOX, false)] + [InlineData(KnownSystem.MicrosoftXBOX360XDG2, false)] + [InlineData(KnownSystem.MicrosoftXBOX360XDG3, false)] + [InlineData(KnownSystem.SonyPlayStation3, true)] + public void DriveSpeedSupportedTest(KnownSystem? knownSystem, bool expected) + { + bool actual = knownSystem.DoesSupportDriveSpeed(); + Assert.Equal(expected, actual); + } + } +} diff --git a/DICUI.Test/Utilities/MediaTypeExtensionsTest.cs b/DICUI.Test/Utilities/MediaTypeExtensionsTest.cs new file mode 100644 index 00000000..42d8622c --- /dev/null +++ b/DICUI.Test/Utilities/MediaTypeExtensionsTest.cs @@ -0,0 +1,48 @@ +using DICUI.Data; +using DICUI.Utilities; +using Xunit; + +namespace DICUI.Test.Utilities +{ + public class MediaTypeExtensionsTest + { + [Theory] + [InlineData(MediaType.CD)] + [InlineData(MediaType.LaserDisc)] + [InlineData(MediaType.NONE)] + public void NameTest(MediaType? mediaType) + { + string expected = Converters.MediaTypeToString(mediaType); + string actual = mediaType.Name(); + + Assert.NotNull(actual); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(MediaType.CD)] + [InlineData(MediaType.DVD)] + [InlineData(MediaType.LaserDisc)] + [InlineData(MediaType.Floppy)] + [InlineData(MediaType.NONE)] + public void ExtensionTest(MediaType? mediaType) + { + string expected = Converters.MediaTypeToExtension(mediaType); + string actual = mediaType.Extension(); + + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(MediaType.CD, true)] + [InlineData(MediaType.DVD, true)] + [InlineData(MediaType.Floppy, false)] + [InlineData(MediaType.BluRay, false)] + [InlineData(MediaType.LaserDisc, false)] + public void DriveSpeedSupportedTest(MediaType? mediaType, bool expected) + { + bool actual = mediaType.DoesSupportDriveSpeed(); + Assert.Equal(expected, actual); + } + } +} diff --git a/DICUI.Test/Utilities/ValidatorsTest.cs b/DICUI.Test/Utilities/ValidatorsTest.cs new file mode 100644 index 00000000..16d34347 --- /dev/null +++ b/DICUI.Test/Utilities/ValidatorsTest.cs @@ -0,0 +1,76 @@ +using System; +using DICUI.Data; +using DICUI.Utilities; +using Xunit; + +namespace DICUI.Test.Utilities +{ + public class ValidatorsTest + { + [Theory] + [InlineData(KnownSystem.BandaiApplePippin, MediaType.CD)] + [InlineData(KnownSystem.MicrosoftXBOX, MediaType.DVD)] + [InlineData(KnownSystem.NintendoGameCube, MediaType.GameCubeGameDisc)] + [InlineData(KnownSystem.NintendoWii, MediaType.WiiOpticalDisc)] + [InlineData(KnownSystem.NintendoWiiU, MediaType.WiiUOpticalDisc)] + [InlineData(KnownSystem.SonyPlayStationPortable, MediaType.UMD)] + public void GetValidMediaTypesTest(KnownSystem? knownSystem, MediaType? expected) + { + var actual = Validators.GetValidMediaTypes(knownSystem); + Assert.Contains(expected, actual); + } + + [Fact] + public void CreateListOfSystemsTest() + { + int expected = Enum.GetValues(typeof(KnownSystem)).Length + 4; // + 4 for the separators + var actual = Validators.CreateListOfSystems(); + Assert.Equal(expected, actual.Count); + } + + [Fact] + public void CreateListOfDrivesTest() + { + // TODO: Implement + Assert.True(true); + } + + [Fact] + public void GetDiscTypeTest() + { + // TODO: Implement + Assert.True(true); + } + + [Theory] + [InlineData(null, false)] + [InlineData("", false)] + [InlineData("cd F test.bin 8 /c2 20", true)] + [InlineData("fd A test.img", true)] + [InlineData("dvd X super\\test.iso 8 /raw", true)] + [InlineData("bd D longer\\path_test.iso 16", false)] + [InlineData("stop D", true)] + [InlineData("ls", false)] + public void ValidateParametersTest(string parameters, bool expected) + { + bool actual = Validators.ValidateParameters(parameters); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(null, null, null, null, null)] + [InlineData("", null, null, null, null)] + [InlineData("cd F test.bin 8 /c2 20", MediaType.CD, KnownSystem.IBMPCCompatible, "F", "test.bin")] + [InlineData("fd A blah\\test.img", MediaType.Floppy, KnownSystem.IBMPCCompatible, "A", "blah\\test.img")] + [InlineData("dvd X super\\blah\\test.iso 8 /raw", MediaType.GameCubeGameDisc, KnownSystem.NintendoGameCube, "X", "super\\blah\\test.iso")] + [InlineData("stop D", null, null, "D", null)] + public void DetermineFlagsTest(string parameters, MediaType? expectedMediaType, KnownSystem? expectedKnownSystem, string expectedDriveLetter, string expectedPath) + { + bool actual = Validators.DetermineFlags(parameters, out MediaType? actualMediaType, out KnownSystem? actualKnownSystem, out string actualDriveLetter, out string actualPath); + Assert.Equal(expectedMediaType, actualMediaType); + Assert.Equal(expectedKnownSystem, actualKnownSystem); + Assert.Equal(expectedDriveLetter, actualDriveLetter); + Assert.Equal(expectedPath, actualPath); + } + } +} diff --git a/DICUI.Test/packages.config b/DICUI.Test/packages.config new file mode 100644 index 00000000..20b49795 --- /dev/null +++ b/DICUI.Test/packages.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DICUI.sln b/DICUI.sln index acc68a4c..fcb2872d 100644 --- a/DICUI.sln +++ b/DICUI.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27130.2036 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DICUI", "DICUI.csproj", "{7B1B75EB-8940-466F-BD51-76471A57F9BE}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DICUI", "DICUI\DICUI.csproj", "{7B1B75EB-8940-466F-BD51-76471A57F9BE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DICUI.Test", "DICUI.Test\DICUI.Test.csproj", "{7CC064D2-38AB-4A05-8519-28660DE4562A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {7B1B75EB-8940-466F-BD51-76471A57F9BE}.Debug|Any CPU.Build.0 = Debug|Any CPU {7B1B75EB-8940-466F-BD51-76471A57F9BE}.Release|Any CPU.ActiveCfg = Release|Any CPU {7B1B75EB-8940-466F-BD51-76471A57F9BE}.Release|Any CPU.Build.0 = Release|Any CPU + {7CC064D2-38AB-4A05-8519-28660DE4562A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7CC064D2-38AB-4A05-8519-28660DE4562A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7CC064D2-38AB-4A05-8519-28660DE4562A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7CC064D2-38AB-4A05-8519-28660DE4562A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/App.config b/DICUI/App.config similarity index 100% rename from App.config rename to DICUI/App.config diff --git a/App.xaml b/DICUI/App.xaml similarity index 100% rename from App.xaml rename to DICUI/App.xaml diff --git a/App.xaml.cs b/DICUI/App.xaml.cs similarity index 100% rename from App.xaml.cs rename to DICUI/App.xaml.cs diff --git a/DICUI.csproj b/DICUI/DICUI.csproj similarity index 100% rename from DICUI.csproj rename to DICUI/DICUI.csproj diff --git a/Data/Constants.cs b/DICUI/Data/Constants.cs similarity index 99% rename from Data/Constants.cs rename to DICUI/Data/Constants.cs index 4edd9961..46f6702a 100644 --- a/Data/Constants.cs +++ b/DICUI/Data/Constants.cs @@ -36,7 +36,6 @@ namespace DICUI.Data case MediaType.HDDVD: case MediaType.GameCubeGameDisc: case MediaType.WiiOpticalDisc: - case MediaType.WiiUOpticalDisc: return AllowedDriveSpeedsForDVD; case MediaType.BluRay: return AllowedDriveSpeedsForBD; diff --git a/Data/Enumerations.cs b/DICUI/Data/Enumerations.cs similarity index 100% rename from Data/Enumerations.cs rename to DICUI/Data/Enumerations.cs diff --git a/External/IOrderedDictionary.cs b/DICUI/External/IOrderedDictionary.cs similarity index 100% rename from External/IOrderedDictionary.cs rename to DICUI/External/IOrderedDictionary.cs diff --git a/External/OrderedDictionary.cs b/DICUI/External/OrderedDictionary.cs similarity index 98% rename from External/OrderedDictionary.cs rename to DICUI/External/OrderedDictionary.cs index 839aa576..5460c626 100644 --- a/External/OrderedDictionary.cs +++ b/DICUI/External/OrderedDictionary.cs @@ -13,7 +13,7 @@ namespace DICUI.External #region Interface properties - public int Count { get; } + public int Count { get; private set; } int ICollection.Count => Count; int ICollection>.Count => Count; @@ -142,6 +142,7 @@ namespace DICUI.External { _dictionary.Add(key, value); _list.Add(new KeyValuePair(key, value)); + Count++; return Count - 1; } @@ -152,6 +153,7 @@ namespace DICUI.External _dictionary.Add(key, value); _list.Insert(index, new KeyValuePair(key, value)); + Count++; } void IOrderedDictionary.RemoveAt(int index) @@ -165,6 +167,7 @@ namespace DICUI.External _list.RemoveAt(index); _dictionary.Remove(key); + Count--; } public bool Remove(TKey key) @@ -178,6 +181,7 @@ namespace DICUI.External if (_dictionary.Remove(key)) { _list.RemoveAt(index); + Count--; return true; } } diff --git a/Icon.ico b/DICUI/Icon.ico similarity index 100% rename from Icon.ico rename to DICUI/Icon.ico diff --git a/MainWindow.xaml b/DICUI/MainWindow.xaml similarity index 100% rename from MainWindow.xaml rename to DICUI/MainWindow.xaml diff --git a/MainWindow.xaml.cs b/DICUI/MainWindow.xaml.cs similarity index 99% rename from MainWindow.xaml.cs rename to DICUI/MainWindow.xaml.cs index a22bf157..dbd6bbd2 100644 --- a/MainWindow.xaml.cs +++ b/DICUI/MainWindow.xaml.cs @@ -262,7 +262,7 @@ namespace DICUI var task = Tasks.StartDumping(_env); Result result = await task; - lbl_Status.Content = result ? "Dumping complete!" : result.message; + lbl_Status.Content = result ? "Dumping complete!" : result.Message; btn_StartStop.Content = UIElements.StartDumping; if (chk_EjectWhenDone.IsChecked == true) @@ -289,7 +289,7 @@ namespace DICUI Result result = GetSupportStatus(selectedSystem, selectedMediaType); - lbl_Status.Content = result.message; + lbl_Status.Content = result.Message; btn_StartStop.IsEnabled = result && (_drives.Count > 0 ? true : false); // If we're in a type that doesn't support drive speeds @@ -390,11 +390,11 @@ namespace DICUI case MediaType.GDROM: case MediaType.GameCubeGameDisc: case MediaType.WiiOpticalDisc: - case MediaType.WiiUOpticalDisc: 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: diff --git a/Options.cs b/DICUI/Options.cs similarity index 100% rename from Options.cs rename to DICUI/Options.cs diff --git a/OptionsWindow.xaml b/DICUI/OptionsWindow.xaml similarity index 100% rename from OptionsWindow.xaml rename to DICUI/OptionsWindow.xaml diff --git a/OptionsWindow.xaml.cs b/DICUI/OptionsWindow.xaml.cs similarity index 100% rename from OptionsWindow.xaml.cs rename to DICUI/OptionsWindow.xaml.cs diff --git a/Properties/AssemblyInfo.cs b/DICUI/Properties/AssemblyInfo.cs similarity index 100% rename from Properties/AssemblyInfo.cs rename to DICUI/Properties/AssemblyInfo.cs diff --git a/Tasks.cs b/DICUI/Tasks.cs similarity index 88% rename from Tasks.cs rename to DICUI/Tasks.cs index 80fb373d..9a66d6b2 100644 --- a/Tasks.cs +++ b/DICUI/Tasks.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Text; @@ -15,18 +16,19 @@ namespace DICUI public class Result { private bool success; - public string message { get; private set; } + public string Message { get; private set; } private Result(bool success, string message) { this.success = success; - this.message = message; + this.Message = message; } public static Result Success() => new Result(true, ""); public static Result Success(string message) => new Result(true, message); public static Result Success(string message, params object[] args) => new Result(true, string.Format(message, args)); + public static Result Failure() => new Result(false, ""); public static Result Failure(string message) => new Result(false, message); public static Result Failure(string message, params object[] args) => new Result(false, string.Format(message, args)); @@ -64,7 +66,7 @@ namespace DICUI { return !((string.IsNullOrWhiteSpace(DICParameters) || !Validators.ValidateParameters(DICParameters) - || (IsFloppy ^ Type == Data.MediaType.Floppy))); + || (IsFloppy ^ Type == MediaType.Floppy))); } /// @@ -76,7 +78,7 @@ namespace DICUI if (System == KnownSystem.Custom) { Validators.DetermineFlags(DICParameters, out Type, out System, out string letter, out string path); - DriveLetter = letter[0]; + DriveLetter = (String.IsNullOrWhiteSpace(letter) ? new char() : letter[0]); OutputDirectory = Path.GetDirectoryName(path); OutputFilename = Path.GetFileName(path); } @@ -90,8 +92,13 @@ namespace DICUI /// public void FixOutputPaths() { - OutputDirectory = OutputDirectory.Replace('.', '_').Replace('&', '_'); - OutputFilename = new StringBuilder(OutputFilename.Replace('&', '_')).Replace('.', '_', 0, OutputFilename.LastIndexOf('.')).ToString(); + // Only fix OutputDirectory if it's not blank or null + if (!String.IsNullOrWhiteSpace(OutputDirectory)) + OutputDirectory = OutputDirectory.Replace('.', '_').Replace('&', '_'); + + // Only fix OutputFilename if it's not blank or null + if (!String.IsNullOrWhiteSpace(OutputFilename)) + OutputFilename = new StringBuilder(OutputFilename.Replace('&', '_')).Replace('.', '_', 0, OutputFilename.LastIndexOf('.')).ToString(); } } @@ -100,115 +107,6 @@ namespace DICUI /// public class Tasks { - /// - /// Validate the current DumpEnvironment - /// - /// DumpEnvirionment containing all required information - /// Result instance with the outcome - public static Result ValidateEnvironment(DumpEnvironment env) - { - // Validate that everything is good - if (!env.IsConfigurationValid()) - return Result.Failure("Error! Current configuration is not supported!"); - - env.AdjustForCustomConfiguration(); - env.FixOutputPaths(); - - // Validate that the required program exists - if (!File.Exists(env.DICPath)) - return Result.Failure("Error! Could not find DiscImageCreator!"); - - // If a complete dump already exists - if (DumpInformation.FoundAllFiles(env.OutputDirectory, env.OutputFilename, env.Type)) - { - MessageBoxResult result = MessageBox.Show("A complete dump already exists! Are you sure you want to overwrite?", "Overwrite?", MessageBoxButton.YesNo, MessageBoxImage.Exclamation); - if (result == MessageBoxResult.No || result == MessageBoxResult.Cancel || result == MessageBoxResult.None) - { - return Result.Failure("Dumping aborted!"); - } - } - - return Result.Success(); - } - - /// - /// Run DiscImageCreator with the given DumpEnvironment - /// - /// DumpEnvirionment containing all required information - public static void ExecuteDiskImageCreator(DumpEnvironment env) - { - env.dicProcess = new Process() - { - StartInfo = new ProcessStartInfo() - { - FileName = env.DICPath, - Arguments = env.DICParameters, - }, - }; - env.dicProcess.Start(); - env.dicProcess.WaitForExit(); - } - - /// - /// Execute subdump for a (potential) Sega Saturn dump - /// - /// DumpEnvirionment containing all required information - public static async void ExecuteSubdump(DumpEnvironment env) - { - await Task.Run(() => - { - Process childProcess = new Process() - { - StartInfo = new ProcessStartInfo() - { - FileName = env.SubdumpPath, - Arguments = "-i " + env.DriveLetter + ": -f " + Path.Combine(env.OutputDirectory, Path.GetFileNameWithoutExtension(env.OutputFilename) + "_subdump.sub") + "-mode 6 -rereadnum 25 -fix 2", - }, - }; - childProcess.Start(); - childProcess.WaitForExit(); - }); - } - - /// - /// Run any additional tools given a DumpEnvironment - /// - /// DumpEnvirionment containing all required information - /// Result instance with the outcome - public static Result ExecuteAdditionalToolsAfterDIC(DumpEnvironment env) - { - // Special cases - switch (env.System) - { - case KnownSystem.SegaSaturn: - if (!File.Exists(env.SubdumpPath)) - return Result.Failure("Error! Could not find subdump!"); - - ExecuteSubdump(env); - break; - } - - return Result.Success(); - } - - /// - /// Verify that the current environment has a complete dump and create submission info is possible - /// - /// DumpEnvirionment containing all required information - /// Result instance with the outcome - public static Result VerifyAndSaveDumpOutput(DumpEnvironment env) - { - // Check to make sure that the output had all the correct files - if (!DumpInformation.FoundAllFiles(env.OutputDirectory, env.OutputFilename, env.Type)) - return Result.Failure("Error! Please check output directory as dump may be incomplete!"); - - Dictionary templateValues = DumpInformation.ExtractOutputInformation(env.OutputDirectory, env.OutputFilename, env.System, env.Type, env.DriveLetter); - List formattedValues = DumpInformation.FormatOutputData(templateValues, env.System, env.Type); - bool success = DumpInformation.WriteOutputData(env.OutputDirectory, env.OutputFilename, formattedValues); - - return Result.Success(); - } - /// /// Eject the disc using DIC /// @@ -261,14 +159,14 @@ namespace DICUI /// public static async Task StartDumping(DumpEnvironment env) { - Result result = Tasks.ValidateEnvironment(env); + Result result = ValidateEnvironment(env); // is something is wrong in environment return if (!result) return result; // execute DIC - await Task.Run(() => Tasks.ExecuteDiskImageCreator(env)); + await Task.Run(() => ExecuteDiskImageCreator(env)); // execute additional tools result = Tasks.ExecuteAdditionalToolsAfterDIC(env); @@ -287,5 +185,114 @@ namespace DICUI return result; } + + /// + /// Validate the current DumpEnvironment + /// + /// DumpEnvirionment containing all required information + /// Result instance with the outcome + private static Result ValidateEnvironment(DumpEnvironment env) + { + // Validate that everything is good + if (!env.IsConfigurationValid()) + return Result.Failure("Error! Current configuration is not supported!"); + + env.AdjustForCustomConfiguration(); + env.FixOutputPaths(); + + // Validate that the required program exists + if (!File.Exists(env.DICPath)) + return Result.Failure("Error! Could not find DiscImageCreator!"); + + // If a complete dump already exists + if (DumpInformation.FoundAllFiles(env.OutputDirectory, env.OutputFilename, env.Type)) + { + MessageBoxResult result = MessageBox.Show("A complete dump already exists! Are you sure you want to overwrite?", "Overwrite?", MessageBoxButton.YesNo, MessageBoxImage.Exclamation); + if (result == MessageBoxResult.No || result == MessageBoxResult.Cancel || result == MessageBoxResult.None) + { + return Result.Failure("Dumping aborted!"); + } + } + + return Result.Success(); + } + + /// + /// Run DiscImageCreator with the given DumpEnvironment + /// + /// DumpEnvirionment containing all required information + private static void ExecuteDiskImageCreator(DumpEnvironment env) + { + env.dicProcess = new Process() + { + StartInfo = new ProcessStartInfo() + { + FileName = env.DICPath, + Arguments = env.DICParameters, + }, + }; + env.dicProcess.Start(); + env.dicProcess.WaitForExit(); + } + + /// + /// Run any additional tools given a DumpEnvironment + /// + /// DumpEnvirionment containing all required information + /// Result instance with the outcome + private static Result ExecuteAdditionalToolsAfterDIC(DumpEnvironment env) + { + // Special cases + switch (env.System) + { + case KnownSystem.SegaSaturn: + if (!File.Exists(env.SubdumpPath)) + return Result.Failure("Error! Could not find subdump!"); + + ExecuteSubdump(env); + break; + } + + return Result.Success(); + } + + /// + /// Execute subdump for a (potential) Sega Saturn dump + /// + /// DumpEnvirionment containing all required information + private static async void ExecuteSubdump(DumpEnvironment env) + { + await Task.Run(() => + { + Process childProcess = new Process() + { + StartInfo = new ProcessStartInfo() + { + FileName = env.SubdumpPath, + Arguments = "-i " + env.DriveLetter + ": -f " + Path.Combine(env.OutputDirectory, Path.GetFileNameWithoutExtension(env.OutputFilename) + "_subdump.sub") + "-mode 6 -rereadnum 25 -fix 2", + }, + }; + childProcess.Start(); + childProcess.WaitForExit(); + }); + } + + /// + /// Verify that the current environment has a complete dump and create submission info is possible + /// + /// DumpEnvirionment containing all required information + /// Result instance with the outcome + private static Result VerifyAndSaveDumpOutput(DumpEnvironment env) + { + // Check to make sure that the output had all the correct files + if (!DumpInformation.FoundAllFiles(env.OutputDirectory, env.OutputFilename, env.Type)) + return Result.Failure("Error! Please check output directory as dump may be incomplete!"); + + Dictionary templateValues = DumpInformation.ExtractOutputInformation(env.OutputDirectory, env.OutputFilename, env.System, env.Type, env.DriveLetter); + List formattedValues = DumpInformation.FormatOutputData(templateValues, env.System, env.Type); + bool success = DumpInformation.WriteOutputData(env.OutputDirectory, env.OutputFilename, formattedValues); + + return Result.Success(); + } } } diff --git a/Utilities/Converters.cs b/DICUI/Utilities/Converters.cs similarity index 96% rename from Utilities/Converters.cs rename to DICUI/Utilities/Converters.cs index 940c7332..f9dd6c41 100644 --- a/Utilities/Converters.cs +++ b/DICUI/Utilities/Converters.cs @@ -24,7 +24,18 @@ namespace DICUI.Utilities public static bool DoesSupportDriveSpeed(this MediaType? type) { - return type != MediaType.BluRay && type != MediaType.Floppy; + 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; + } } } @@ -72,7 +83,9 @@ namespace DICUI.Utilities { switch (baseCommand) { + case DICCommands.Audio: case DICCommands.CompactDisc: + case DICCommands.Data: return MediaType.CD; case DICCommands.GDROM: case DICCommands.Swap: @@ -100,7 +113,10 @@ namespace DICUI.Utilities { switch (baseCommand) { + case DICCommands.Audio: + return KnownSystem.AudioCD; case DICCommands.CompactDisc: + case DICCommands.Data: case DICCommands.DigitalVideoDisc: case DICCommands.Floppy: return KnownSystem.IBMPCCompatible; @@ -243,6 +259,12 @@ namespace DICUI.Utilities /// String containing the command, null on error public static string KnownSystemAndMediaTypeToBaseCommand(KnownSystem? sys, MediaType? type) { + // If we have an invalid combination, we should return null + if (!Validators.GetValidMediaTypes(sys).Contains(type)) + { + return null; + } + switch (type) { case MediaType.CD: @@ -265,18 +287,10 @@ namespace DICUI.Utilities return DICCommands.DigitalVideoDisc; case MediaType.BluRay: return DICCommands.BluRay; - - // Special Formats case MediaType.GameCubeGameDisc: return DICCommands.DigitalVideoDisc; case MediaType.WiiOpticalDisc: - return null; - case MediaType.WiiUOpticalDisc: - return null; - case MediaType.UMD: - return null; - - // Non-optical + return DICCommands.DigitalVideoDisc; case MediaType.Floppy: return DICCommands.Floppy; @@ -342,12 +356,7 @@ namespace DICUI.Utilities parameters.Add(DICFlags.Raw); break; case MediaType.WiiOpticalDisc: - // Currently no defaults set - break; - case MediaType.WiiUOpticalDisc: - // Currently no defaults set - break; - case MediaType.UMD: + parameters.Add(DICFlags.Raw); break; // Non-optical diff --git a/Utilities/DumpInformation.cs b/DICUI/Utilities/DumpInformation.cs similarity index 99% rename from Utilities/DumpInformation.cs rename to DICUI/Utilities/DumpInformation.cs index 7fe71c26..ba8385f8 100644 --- a/Utilities/DumpInformation.cs +++ b/DICUI/Utilities/DumpInformation.cs @@ -8,6 +8,7 @@ using DICUI.Data; namespace DICUI.Utilities { + // TODO: Wrap DumpEnvironment into this and rename this to DumpEnvironment public static class DumpInformation { /// @@ -91,8 +92,6 @@ namespace DICUI.Utilities case MediaType.BluRay: case MediaType.GameCubeGameDisc: case MediaType.WiiOpticalDisc: - case MediaType.WiiUOpticalDisc: - case MediaType.UMD: return File.Exists(combinedBase + ".dat") && File.Exists(combinedBase + "_cmd.txt") && File.Exists(combinedBase + "_disc.txt") @@ -122,10 +121,16 @@ namespace DICUI.Utilities /// TODO: Make sure that all special formats are accounted for public static Dictionary ExtractOutputInformation(string outputDirectory, string outputFilename, KnownSystem? sys, MediaType? type, char driveLetter) { - // First, sanitized the output filename to strip off any potential extension + // Ensure the current disc combination should exist + if (!Validators.GetValidMediaTypes(sys).Contains(type)) + { + return null; + } + + // Sanitize the output filename to strip off any potential extension outputFilename = Path.GetFileNameWithoutExtension(outputFilename); - // First, we want to check that all of the relevant files are there + // Check that all of the relevant files are there if (!FoundAllFiles(outputDirectory, outputFilename, type)) { return null; diff --git a/Utilities/Validators.cs b/DICUI/Utilities/Validators.cs similarity index 79% rename from Utilities/Validators.cs rename to DICUI/Utilities/Validators.cs index 51765e17..a11972e4 100644 --- a/Utilities/Validators.cs +++ b/DICUI/Utilities/Validators.cs @@ -716,174 +716,97 @@ namespace DICUI.Utilities int index = -1; switch (parts[0]) { - case DICCommands.CompactDisc: - case DICCommands.GDROM: - case DICCommands.Swap: + case DICCommands.Audio: case DICCommands.Data: - if (!IsValidDriveLetter(parts[1])) - { + if (!DoesExist(parts, 1) || !IsValidDriveLetter(parts[1])) return false; - } - else if (IsFlag(parts[2])) - { + else if (!DoesExist(parts, 2) || IsFlag(parts[2])) return false; - } - else if (!IsValidNumber(parts[3], lowerBound: 0, upperBound: 72)) - { + else if (!DoesExist(parts, 3) || !IsValidNumber(parts[3], lowerBound: 0, upperBound: 72)) + return false; + else if (!DoesExist(parts, 4) || !IsValidNumber(parts[4], lowerBound: 0)) + return false; + else if (!DoesExist(parts, 5) || !IsValidNumber(parts[5], lowerBound: 0)) return false; - } - - if (parts[0] == DICCommands.Swap) - { - if (parts.Count > 5) - { - return false; - } - } - else if (parts[0] == DICCommands.Data || parts[0] == DICCommands.Audio) - { - if (!IsValidNumber(parts[4]) || !IsValidNumber(parts[5])) - { - return false; - } - - index = 6; - } - else - { - index = 4; - } + index = 6; break; - case DICCommands.DigitalVideoDisc: - if (!IsValidDriveLetter(parts[1])) - { - return false; - } - else if (IsFlag(parts[2])) - { - return false; - } - else if (!IsValidNumber(parts[3], lowerBound: 0, upperBound: 72)) // Officially 0-16 - { - return false; - } - // Loop through all auxilary flags - for (int i = 4; i < parts.Count; i++) - { - switch (parts[i]) - { - case DICFlags.DisableBeep: - case DICFlags.CMI: - case DICFlags.Raw: - // No-op, all of these are single flags - break; - case DICFlags.ForceUnitAccess: - // If the next item doesn't exist, it's good - if (!DoesNextExist(parts, i)) - { - break; - } - // If the next item is a flag, it's good - if (IsFlag(parts[i + 1])) - { - break; - } - // If the next item isn't a valid number - else if (!IsValidNumber(parts[i + 1], lowerBound: 0)) - { - return false; - } - i++; - break; - default: - return false; - } - } - break; case DICCommands.BluRay: case DICCommands.XBOX: - if (!IsValidDriveLetter(parts[1])) - { + if (!DoesExist(parts, 1) || !IsValidDriveLetter(parts[1])) return false; - } - else if (IsFlag(parts[2])) - { + else if (!DoesExist(parts, 2) || IsFlag(parts[2])) return false; - } - // Loop through all auxilary flags - for (int i = 3; i < parts.Count; i++) - { - switch (parts[i]) - { - case DICFlags.DisableBeep: - // No-op, this is a single flag - break; - case DICFlags.ForceUnitAccess: - // If the next item doesn't exist, it's good - if (!DoesNextExist(parts, i)) - { - break; - } - // If the next item is a flag, it's good - if (IsFlag(parts[i + 1])) - { - break; - } - // If the next item isn't a valid number - else if (!IsValidNumber(parts[i + 1], lowerBound: 0)) - { - return false; - } - i++; - break; - default: - return false; - } - } + index = 3; break; + + case DICCommands.CompactDisc: + case DICCommands.GDROM: + if (!DoesExist(parts, 1) || !IsValidDriveLetter(parts[1])) + return false; + else if (!DoesExist(parts, 2) || IsFlag(parts[2])) + return false; + else if (!DoesExist(parts, 3) || !IsValidNumber(parts[3], lowerBound: 0, upperBound: 72)) + return false; + + index = 4; + break; + + case DICCommands.DigitalVideoDisc: + if (!DoesExist(parts, 1) || !IsValidDriveLetter(parts[1])) + return false; + else if (!DoesExist(parts, 2) || IsFlag(parts[2])) + return false; + else if (!DoesExist(parts, 3) || !IsValidNumber(parts[3], lowerBound: 0, upperBound: 24)) // Officially 0-16 + return false; + + index = 4; + break; + + case DICCommands.Swap: + if (!DoesExist(parts, 1) || !IsValidDriveLetter(parts[1])) + return false; + else if (!DoesExist(parts, 2) || IsFlag(parts[2])) + return false; + else if (!DoesExist(parts, 3) || !IsValidNumber(parts[3], lowerBound: 0, upperBound: 72)) + return false; + else if (parts.Count > 5) + return false; + + index = 4; + break; + case DICCommands.Floppy: - if (!IsValidDriveLetter(parts[1])) - { + if (!DoesExist(parts, 1) || !IsValidDriveLetter(parts[1])) return false; - } - else if (IsFlag(parts[2])) - { + else if (!DoesExist(parts, 2) || IsFlag(parts[2])) return false; - } else if (parts.Count > 3) - { return false; - } break; + case DICCommands.Stop: case DICCommands.Start: case DICCommands.Eject: case DICCommands.Close: case DICCommands.Reset: case DICCommands.DriveSpeed: - if (!IsValidDriveLetter(parts[1])) - { + if (!DoesExist(parts, 1) || !IsValidDriveLetter(parts[1])) return false; - } else if (parts.Count > 2) - { return false; - } break; + case DICCommands.Sub: case DICCommands.MDS: - if (IsFlag(parts[1])) - { + if (!DoesExist(parts, 1) || IsFlag(parts[1])) return false; - } else if (parts.Count > 2) - { return false; - } break; + default: return false; } @@ -895,260 +818,206 @@ namespace DICUI.Utilities { switch (parts[i]) { - case DICFlags.DisableBeep: - if (parts[0] != DICCommands.CompactDisc - && parts[0] != DICCommands.GDROM - && parts[0] != DICCommands.Data - && parts[0] != DICCommands.Audio) - { + case DICFlags.AddOffset: + if (parts[0] != DICCommands.Audio + && parts[0] != DICCommands.CompactDisc) return false; - } - break; - case DICFlags.D8Opcode: - if (parts[0] != DICCommands.CompactDisc - && parts[0] != DICCommands.GDROM - && parts[0] != DICCommands.Data - && parts[0] != DICCommands.Audio) - { + else if (!DoesExist(parts, i + 1)) return false; - } - break; - case DICFlags.MCN: - if (parts[0] != DICCommands.CompactDisc) - { + else if (!IsValidNumber(parts[i + 1])) return false; - } break; + case DICFlags.AMSF: if (parts[0] != DICCommands.CompactDisc) - { return false; - } break; + + case DICFlags.BEOpcode: + if (parts[0] != DICCommands.Audio + && parts[0] != DICCommands.CompactDisc + && parts[0] != DICCommands.Data + && parts[0] != DICCommands.GDROM) + return false; + else if (!DoesExist(parts, i + 1)) + break; + else if (IsFlag(parts[i + 1])) + break; + else if (parts[i + 1] != "raw" + && (parts[i + 1] != "pack")) + return false; + + i++; + break; + + case DICFlags.C2Opcode: + if (parts[0] != DICCommands.Audio + && parts[0] != DICCommands.CompactDisc + && parts[0] != DICCommands.Data + && parts[0] != DICCommands.GDROM) + return false; + + for (int j = 0; j < 4; j++) + { + if (!DoesExist(parts, i + 1)) + break; + else if (IsFlag(parts[i + 1])) + break; + else if (!IsValidNumber(parts[i + 1], lowerBound: 0)) + return false; + else + i++; + } + + break; + + case DICFlags.CMI: + if (parts[0] != DICCommands.DigitalVideoDisc) + return false; + break; + + case DICFlags.D8Opcode: + if (parts[0] != DICCommands.Audio + && parts[0] != DICCommands.CompactDisc + && parts[0] != DICCommands.Data + && parts[0] != DICCommands.GDROM) + return false; + break; + + case DICFlags.DisableBeep: + if (parts[0] != DICCommands.Audio + && parts[0] != DICCommands.BluRay + && parts[0] != DICCommands.CompactDisc + && parts[0] != DICCommands.Data + && parts[0] != DICCommands.DigitalVideoDisc + && parts[0] != DICCommands.GDROM + && parts[0] != DICCommands.XBOX) + return false; + break; + + case DICFlags.ForceUnitAccess: + if (parts[0] != DICCommands.Audio + && parts[0] != DICCommands.BluRay + && parts[0] != DICCommands.CompactDisc + && parts[0] != DICCommands.DigitalVideoDisc + && parts[0] != DICCommands.Data + && parts[0] != DICCommands.GDROM + && parts[0] != DICCommands.XBOX) + return false; + else if (!DoesExist(parts, i + 1)) + break; + else if (IsFlag(parts[i + 1])) + break; + else if (!IsValidNumber(parts[i + 1], lowerBound: 0)) + return false; + + i++; + break; + + case DICFlags.MCN: + if (parts[0] != DICCommands.CompactDisc) + return false; + break; + + case DICFlags.MultiSession: + if (parts[0] != DICCommands.CompactDisc) + return false; + break; + + case DICFlags.NoFixSubP: + if (parts[0] != DICCommands.Audio + && parts[0] != DICCommands.CompactDisc + && parts[0] != DICCommands.Data + && parts[0] != DICCommands.GDROM) + return false; + break; + + case DICFlags.NoFixSubQ: + if (parts[0] != DICCommands.Audio + && parts[0] != DICCommands.CompactDisc + && parts[0] != DICCommands.Data + && parts[0] != DICCommands.GDROM) + return false; + break; + + case DICFlags.NoFixSubQLibCrypt: + if (parts[0] != DICCommands.CompactDisc) + return false; + break; + + case DICFlags.NoFixSubQSecuROM: + if (parts[0] != DICCommands.Audio + && parts[0] != DICCommands.CompactDisc + && parts[0] != DICCommands.Data + && parts[0] != DICCommands.GDROM) + return false; + break; + + case DICFlags.NoFixSubRtoW: + if (parts[0] != DICCommands.Audio + && parts[0] != DICCommands.CompactDisc + && parts[0] != DICCommands.Data + && parts[0] != DICCommands.GDROM) + return false; + break; + + case DICFlags.Raw: + if (parts[0] != DICCommands.DigitalVideoDisc) + return false; + break; + case DICFlags.Reverse: if (parts[0] != DICCommands.CompactDisc && parts[0] != DICCommands.Data) - { return false; - } - break; - case DICFlags.MultiSession: - if (parts[0] != DICCommands.CompactDisc) - { - return false; - } - break; - case DICFlags.ScanSectorProtect: - if (parts[0] != DICCommands.CompactDisc - && parts[0] != DICCommands.Data) - { - return false; - } break; + case DICFlags.ScanAntiMod: if (parts[0] != DICCommands.CompactDisc) - { return false; - } - break; - case DICFlags.NoFixSubP: - if (parts[0] != DICCommands.CompactDisc - && parts[0] != DICCommands.GDROM - && parts[0] != DICCommands.Data - && parts[0] != DICCommands.Audio) - { - return false; - } - break; - case DICFlags.NoFixSubQ: - if (parts[0] != DICCommands.CompactDisc - && parts[0] != DICCommands.GDROM - && parts[0] != DICCommands.Data - && parts[0] != DICCommands.Audio) - { - return false; - } - break; - case DICFlags.NoFixSubRtoW: - if (parts[0] != DICCommands.CompactDisc - && parts[0] != DICCommands.GDROM - && parts[0] != DICCommands.Data - && parts[0] != DICCommands.Audio) - { - return false; - } - break; - case DICFlags.NoFixSubQLibCrypt: - if (parts[0] != DICCommands.CompactDisc) - { - return false; - } - break; - case DICFlags.NoFixSubQSecuROM: - if (parts[0] != DICCommands.CompactDisc - && parts[0] != DICCommands.GDROM - && parts[0] != DICCommands.Data - && parts[0] != DICCommands.Audio) - { - return false; - } break; + case DICFlags.ScanFileProtect: if (parts[0] != DICCommands.CompactDisc && parts[0] != DICCommands.Data) - { return false; - } - - // If the next item doesn't exist, it's good - if (!DoesNextExist(parts, i)) - { + else if (!DoesExist(parts, i + 1)) break; - } - // If the next item is a flag, it's good - if (IsFlag(parts[i + 1])) - { + else if (IsFlag(parts[i + 1])) break; - } - // If the next item isn't a valid number else if (!IsValidNumber(parts[i + 1], lowerBound: 0)) - { return false; - } + i++; break; - case DICFlags.ForceUnitAccess: - if (parts[0] != DICCommands.CompactDisc - && parts[0] != DICCommands.GDROM - && parts[0] != DICCommands.Data - && parts[0] != DICCommands.Audio) - { - return false; - } - // If the next item doesn't exist, it's good - if (!DoesNextExist(parts, i)) - { - break; - } - // If the next item is a flag, it's good - if (IsFlag(parts[i + 1])) - { - break; - } - // If the next item isn't a valid number - else if (!IsValidNumber(parts[i + 1], lowerBound: 0)) - { - return false; - } - i++; - break; - case DICFlags.AddOffset: + case DICFlags.ScanSectorProtect: if (parts[0] != DICCommands.CompactDisc - && parts[0] != DICCommands.Audio) - { + && parts[0] != DICCommands.Data) return false; - } - - // If the next item doesn't exist, it's not good - if (parts.Count == i + 1) - { - return false; - } - // If the next item isn't a valid number - else if (IsValidNumber(parts[i + 1])) - { - return false; - } break; - case DICFlags.BEOpcode: - if (parts[0] != DICCommands.CompactDisc - && parts[0] != DICCommands.GDROM - && parts[0] != DICCommands.Data - && parts[0] != DICCommands.Audio) - { - return false; - } - // If the next item doesn't exist, it's good - if (!DoesNextExist(parts, i)) - { - break; - } - // If the next item is a flag, it's good - if (IsFlag(parts[i + 1])) - { - break; - } - else if (parts[i + 1] != "raw" - && (parts[i + 1] != "pack")) - { - return false; - } - i++; - break; - case DICFlags.C2Opcode: - if (parts[0] != DICCommands.CompactDisc - && parts[0] != DICCommands.GDROM - && parts[0] != DICCommands.Data - && parts[0] != DICCommands.Audio) - { - return false; - } - - for (int j = 1; j < 4; j++) - { - // If the next item doesn't exist, it's good - if (!DoesNextExist(parts, i + 1)) - { - i++; - break; - } - // If the next item is a flag, it's good - if (IsFlag(parts[i + 1])) - { - i++; - break; - } - // If the next item isn't a valid number - else if (!IsValidNumber(parts[i + 1], lowerBound: 0)) - { - return false; - } - i++; - } - break; - case DICFlags.SubchannelReadLevel: - if (parts[0] != DICCommands.CompactDisc - && parts[0] != DICCommands.GDROM - && parts[0] != DICCommands.Data - && parts[0] != DICCommands.Audio) - { - return false; - } - - // If the next item doesn't exist, it's good - if (!DoesNextExist(parts, i)) - { - break; - } - // If the next item is a flag, it's good - if (IsFlag(parts[i + 1])) - { - break; - } - // If the next item isn't a valid number - else if (!IsValidNumber(parts[3], lowerBound: 0, upperBound: 2)) - { - return false; - } - break; case DICFlags.SeventyFour: if (parts[0] != DICCommands.Swap) - { return false; - } break; + + case DICFlags.SubchannelReadLevel: + if (parts[0] != DICCommands.Audio + && parts[0] != DICCommands.CompactDisc + && parts[0] != DICCommands.Data + && parts[0] != DICCommands.GDROM) + return false; + else if (DoesExist(parts, i + 1)) + break; + else if (IsFlag(parts[i + 1])) + break; + else if (!IsValidNumber(parts[i + 1], lowerBound: 0, upperBound: 2)) + return false; + + i++; + break; + default: return false; } @@ -1189,14 +1058,14 @@ namespace DICUI.Utilities } /// - /// Returns whether or not the next item exists + /// Returns whether or not the selected item exists /// /// List of parameters to check against /// Current index /// True if the next item exists, false otherwise - private static bool DoesNextExist(List parameters, int index) + private static bool DoesExist(List parameters, int index) { - if (index >= parameters.Count - 1) + if (index >= parameters.Count) { return false; } diff --git a/appveyor.yml b/appveyor.yml index b7e77de3..dd66d173 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -28,7 +28,7 @@ build: # post-build step after_build: -- 7z a dicui_%APPVEYOR_BUILD_VERSION%.zip bin\Debug +- 7z a dicui_%APPVEYOR_BUILD_VERSION%.zip DICUI\bin\Debug # artifact linking artifacts: