Build a working DiffDat generator

This commit is contained in:
Matt Nadareski
2016-04-19 16:39:17 -07:00
parent 080357482c
commit 6ceac909da
10 changed files with 286 additions and 2 deletions

3
.gitignore vendored
View File

@@ -11,6 +11,9 @@
/Deheader/obj
/Deheader/obj/Debug
/Deheader/obj/Release
/DiffDat/obj
/DiffDat/obj/Debug
/DiffDat/obj/Release
/SabreHelper/obj
/SabreHelper/obj/Debug
/SabreHelper/obj/Release

6
DiffDat/App.config Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

90
DiffDat/DiffDat.cs Normal file
View File

@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.IO;
using SabreTools.Helper;
namespace SabreTools
{
public class DiffDat
{
private static Logger logger;
public static void Main(string[] args)
{
Console.Clear();
// Credits take precidence over all
if ((new List<string>(args)).Contains("--credits"))
{
Build.Credits();
return;
}
if (args.Length == 0)
{
Build.Help();
return;
}
logger = new Logger(false, "diffdat.log");
logger.Start();
// Output the title
Build.Start("DiffDat");
List<String> inputs = new List<String>();
bool tofile = false, help = false;
foreach (string arg in args)
{
switch (arg)
{
case "-h":
case "-?":
case "--help":
help = true;
break;
case "-l":
case "--log":
tofile = true;
break;
default:
// Add actual files to the list of inputs
if (File.Exists(arg.Replace("\"", "")))
{
inputs.Add(Path.GetFullPath(arg.Replace("\"", "")));
}
else if (Directory.Exists(arg.Replace("\"", "")))
{
foreach (string file in Directory.EnumerateFiles(arg, "*", SearchOption.AllDirectories))
{
inputs.Add(Path.GetFullPath(file));
}
}
break;
}
}
// Set the possibly new value for logger
logger.ToFile = tofile;
// Show help if explicitly asked for it or if not enough files are supplied
if (help || inputs.Count < 2)
{
Build.Help();
logger.Close();
return;
}
// Otherwise, read in the two files, diff them, and write the result to the file type that the first one is
List<RomData> A = new List<RomData>();
foreach (string input in inputs)
{
logger.Log("Merging in DAT: " + input);
List<RomData> B = RomManipulation.Parse(input, 0, 0, logger);
A = RomManipulation.Diff(A, B);
}
Output.WriteToDat("diffdat", "diffdat", "", "", "DiffDat", "SabreTools", false, !RomManipulation.IsXmlDat(inputs[0]), "", A, logger);
}
}
}

66
DiffDat/DiffDat.csproj Normal file
View File

@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{785A4E9E-0DC1-4FAD-AA3A-57B5B122CD8E}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DiffDat</RootNamespace>
<AssemblyName>DiffDat</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DiffDat.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SabreHelper\SabreHelper.csproj">
<Project>{225a1afd-0890-44e8-b779-7502665c23a5}</Project>
<Name>SabreHelper</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DiffDat")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DiffDat")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("785a4e9e-0dc1-4fad-aa3a-57b5b122cd8e")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -77,7 +77,7 @@ CURRENTLY UNCODED - A program to merge an arbitrary number of DATs into a single
<b>DiffDat</b>
<p/>
CURRENTLY UNCODED - A program to create a DAT based on the differences between two input DATs. Optionally, if the output file exists, the information is appended. (This latter functionality may be wrapped into MergeDAT.)
A program to create a DAT based on the differences between two or more input DATs.
<h3>Licensing</h3>
<p/>

View File

@@ -156,6 +156,15 @@ Options:
-l, --log Enable log to file
-sd, --superdat Enable SuperDAT creation");
break;
case "DiffDat":
Console.WriteLine(@"DiffDat - Get the difference between two or more DAT files
-----------------------------------------
Usage: DiffDat [options] [filename] [filename] ...
Options:
-h, -?, --help Show this help dialog
-l, --log Enable log to file");
break;
default:
Console.Write("This is the default help output");
break;

View File

@@ -171,5 +171,70 @@ namespace SabreTools.Helper
return true;
}
/// <summary>
/// Convert a List of RomData objects to a List of tab-deliminated strings
/// </summary>
/// <param name="roms">List of RomData objects representing the roms to be parsed</param>
/// <returns>List of Strings representing the roms</returns>
public static List<String> RomDataToString(List<RomData> roms)
{
List<String> outlist = new List<String>();
foreach (RomData rom in roms)
{
outlist.Add(rom.Manufacturer + "\t" +
rom.System + "\t" +
rom.SystemID + "\t" +
rom.Source + "\t" +
rom.URL + "\t" +
rom.SourceID + "\t" +
rom.Game + "\t" +
rom.Name + "\t" +
rom.Type + "\t" +
rom.Size + "\t" +
rom.CRC + "\t" +
rom.MD5 + "\t" +
rom.SHA1);
}
return outlist;
}
/// <summary>
/// Convert a List of tab-deliminated strings objects to a List of RomData objects
/// </summary>
/// <param name="roms">List of Strings representing the roms to be parsed</param>
/// <returns>List of RomData objects representing the roms</returns>
public static List<RomData> StringToRomData(List<String> roms)
{
List<RomData> outlist = new List<RomData>();
foreach (String rom in roms)
{
string[] temp = rom.Split('\t');
try
{
outlist.Add(new RomData
{
Manufacturer = temp[0],
System = temp[1],
SystemID = Int32.Parse(temp[2]),
Source = temp[3],
URL = temp[4],
SourceID = Int32.Parse(temp[5]),
Game = temp[6],
Name = temp[7],
Type = temp[8],
Size = Int64.Parse(temp[9]),
CRC = temp[10],
MD5 = temp[11],
SHA1 = temp[12],
});
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
return outlist;
}
}
}

View File

@@ -333,7 +333,10 @@ namespace SabreTools.Helper
/// <remarks>Adapted from http://stackoverflow.com/questions/5620266/the-opposite-of-intersect</remarks>
public static List<RomData> Diff(List<RomData> A, List<RomData> B)
{
return A.Except(B).Union(B.Except(A)).ToList();
List<String> AString = Output.RomDataToString(A);
List<String> BString = Output.RomDataToString(B);
List<String> CString = AString.Except(BString).Union(BString.Except(AString)).ToList();
return Output.StringToRomData(CString);
}
}
}

View File

@@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreHelper", "SabreHelper\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DATFromDir", "DATFromDir\DATFromDir.csproj", "{382B75D3-079E-49D5-A830-54DD6EB5A02D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiffDat", "DiffDat\DiffDat.csproj", "{785A4E9E-0DC1-4FAD-AA3A-57B5B122CD8E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -52,6 +54,10 @@ Global
{382B75D3-079E-49D5-A830-54DD6EB5A02D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{382B75D3-079E-49D5-A830-54DD6EB5A02D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{382B75D3-079E-49D5-A830-54DD6EB5A02D}.Release|Any CPU.Build.0 = Release|Any CPU
{785A4E9E-0DC1-4FAD-AA3A-57B5B122CD8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{785A4E9E-0DC1-4FAD-AA3A-57B5B122CD8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{785A4E9E-0DC1-4FAD-AA3A-57B5B122CD8E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{785A4E9E-0DC1-4FAD-AA3A-57B5B122CD8E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE