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
This commit is contained in:
Matt Nadareski
2018-06-28 19:41:18 -07:00
committed by GitHub
parent c1bd30e008
commit 56eaf7c2c5
33 changed files with 1026 additions and 499 deletions

View File

@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.props" Condition="Exists('..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.props')" />
<Import Project="..\packages\xunit.runner.console.2.3.1\build\xunit.runner.console.props" Condition="Exists('..\packages\xunit.runner.console.2.3.1\build\xunit.runner.console.props')" />
<Import Project="..\packages\xunit.core.2.3.1\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.3.1\build\xunit.core.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7CC064D2-38AB-4A05-8519-28660DE4562A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DICUI.Test</RootNamespace>
<AssemblyName>DICUI.Test</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.CodeCoverage.Shim, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeCoverage.1.0.3\lib\netstandard1.0\Microsoft.VisualStudio.CodeCoverage.Shim.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Data\UIElementsTest.cs" />
<Compile Include="DumpEnvironmentTest.cs" />
<Compile Include="ResultTest.cs" />
<Compile Include="TasksTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilities\ConvertersTest.cs" />
<Compile Include="Utilities\DumpInformationTest.cs" />
<Compile Include="Utilities\KnownSystemExtensionsTest.cs" />
<Compile Include="Utilities\MediaTypeExtensionsTest.cs" />
<Compile Include="Utilities\ValidatorsTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DICUI\DICUI.csproj">
<Project>{7b1b75eb-8940-466f-bd51-76471a57f9be}</Project>
<Name>DICUI</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\xunit.analyzers.0.9.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.core.2.3.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.3.1\build\xunit.core.props'))" />
<Error Condition="!Exists('..\packages\xunit.core.2.3.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.3.1\build\xunit.core.targets'))" />
<Error Condition="!Exists('..\packages\xunit.runner.console.2.3.1\build\xunit.runner.console.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.console.2.3.1\build\xunit.runner.console.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.targets'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<Import Project="..\packages\xunit.core.2.3.1\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.3.1\build\xunit.core.targets')" />
<Import Project="..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.targets" Condition="Exists('..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.targets')" />
</Project>

View File

@@ -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());
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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")]

39
DICUI.Test/ResultTest.cs Normal file
View File

@@ -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);
}
}
}

30
DICUI.Test/TasksTest.cs Normal file
View File

@@ -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);
}
}
}

View File

@@ -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<string> 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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.CodeCoverage" version="1.0.3" targetFramework="net461" />
<package id="Microsoft.NET.Test.Sdk" version="15.7.2" targetFramework="net461" />
<package id="xunit" version="2.3.1" targetFramework="net461" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net461" />
<package id="xunit.analyzers" version="0.9.0" targetFramework="net461" />
<package id="xunit.assert" version="2.3.1" targetFramework="net461" />
<package id="xunit.core" version="2.3.1" targetFramework="net461" />
<package id="xunit.extensibility.core" version="2.3.1" targetFramework="net461" />
<package id="xunit.extensibility.execution" version="2.3.1" targetFramework="net461" />
<package id="xunit.runner.console" version="2.3.1" targetFramework="net461" developmentDependency="true" />
<package id="xunit.runner.visualstudio" version="2.3.1" targetFramework="net461" developmentDependency="true" />
</packages>

View File

@@ -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

View File

@@ -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;

View File

@@ -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<KeyValuePair<TKey, TValue>>.Count => Count;
@@ -142,6 +142,7 @@ namespace DICUI.External
{
_dictionary.Add(key, value);
_list.Add(new KeyValuePair<TKey, TValue>(key, value));
Count++;
return Count - 1;
}
@@ -152,6 +153,7 @@ namespace DICUI.External
_dictionary.Add(key, value);
_list.Insert(index, new KeyValuePair<TKey, TValue>(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;
}
}

View File

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 71 KiB

View File

@@ -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:

View File

@@ -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)));
}
/// <summary>
@@ -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
/// </remarks>
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
/// </summary>
public class Tasks
{
/// <summary>
/// Validate the current DumpEnvironment
/// </summary>
/// <param name="env">DumpEnvirionment containing all required information</param>
/// <returns>Result instance with the outcome</returns>
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();
}
/// <summary>
/// Run DiscImageCreator with the given DumpEnvironment
/// </summary>
/// <param name="env">DumpEnvirionment containing all required information</param>
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();
}
/// <summary>
/// Execute subdump for a (potential) Sega Saturn dump
/// </summary>
/// <param name="env">DumpEnvirionment containing all required information</param>
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();
});
}
/// <summary>
/// Run any additional tools given a DumpEnvironment
/// </summary>
/// <param name="env">DumpEnvirionment containing all required information</param>
/// <returns>Result instance with the outcome</returns>
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();
}
/// <summary>
/// Verify that the current environment has a complete dump and create submission info is possible
/// </summary>
/// <param name="env">DumpEnvirionment containing all required information</param>
/// <returns>Result instance with the outcome</returns>
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<string, string> templateValues = DumpInformation.ExtractOutputInformation(env.OutputDirectory, env.OutputFilename, env.System, env.Type, env.DriveLetter);
List<string> formattedValues = DumpInformation.FormatOutputData(templateValues, env.System, env.Type);
bool success = DumpInformation.WriteOutputData(env.OutputDirectory, env.OutputFilename, formattedValues);
return Result.Success();
}
/// <summary>
/// Eject the disc using DIC
/// </summary>
@@ -261,14 +159,14 @@ namespace DICUI
/// </summary>
public static async Task<Result> 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;
}
/// <summary>
/// Validate the current DumpEnvironment
/// </summary>
/// <param name="env">DumpEnvirionment containing all required information</param>
/// <returns>Result instance with the outcome</returns>
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();
}
/// <summary>
/// Run DiscImageCreator with the given DumpEnvironment
/// </summary>
/// <param name="env">DumpEnvirionment containing all required information</param>
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();
}
/// <summary>
/// Run any additional tools given a DumpEnvironment
/// </summary>
/// <param name="env">DumpEnvirionment containing all required information</param>
/// <returns>Result instance with the outcome</returns>
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();
}
/// <summary>
/// Execute subdump for a (potential) Sega Saturn dump
/// </summary>
/// <param name="env">DumpEnvirionment containing all required information</param>
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();
});
}
/// <summary>
/// Verify that the current environment has a complete dump and create submission info is possible
/// </summary>
/// <param name="env">DumpEnvirionment containing all required information</param>
/// <returns>Result instance with the outcome</returns>
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<string, string> templateValues = DumpInformation.ExtractOutputInformation(env.OutputDirectory, env.OutputFilename, env.System, env.Type, env.DriveLetter);
List<string> formattedValues = DumpInformation.FormatOutputData(templateValues, env.System, env.Type);
bool success = DumpInformation.WriteOutputData(env.OutputDirectory, env.OutputFilename, formattedValues);
return Result.Success();
}
}
}

View File

@@ -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
/// <returns>String containing the command, null on error</returns>
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

View File

@@ -8,6 +8,7 @@ using DICUI.Data;
namespace DICUI.Utilities
{
// TODO: Wrap DumpEnvironment into this and rename this to DumpEnvironment
public static class DumpInformation
{
/// <summary>
@@ -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
/// <remarks>TODO: Make sure that all special formats are accounted for</remarks>
public static Dictionary<string, string> 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;

View File

@@ -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
}
/// <summary>
/// Returns whether or not the next item exists
/// Returns whether or not the selected item exists
/// </summary>
/// <param name="parameters">List of parameters to check against</param>
/// <param name="index">Current index</param>
/// <returns>True if the next item exists, false otherwise</returns>
private static bool DoesNextExist(List<string> parameters, int index)
private static bool DoesExist(List<string> parameters, int index)
{
if (index >= parameters.Count - 1)
if (index >= parameters.Count)
{
return false;
}

View File

@@ -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: