[DATabase, Filter] Move filter into DATabase

This commit is contained in:
Matt Nadareski
2016-06-10 13:18:46 -07:00
parent dc2b76d127
commit 3eec524bf2
9 changed files with 138 additions and 149 deletions

3
.gitignore vendored
View File

@@ -8,9 +8,6 @@
/Deheader/obj
/Deheader/obj/Debug
/Deheader/obj/Release
/Filter/obj
/Filter/obj/Debug
/Filter/obj/Release
/OfflineMerge/obj
/OfflineMerge/obj/Debug
/OfflineMerge/obj/Release

View File

@@ -85,11 +85,12 @@ namespace SabreTools
bare = false,
cascade = false,
clean = false,
datprefix = false,
dedup = false,
diff = false,
gamename = false,
disableForce = false,
extsplit = false,
filter = false,
forceunpack = false,
generate = false,
genall = false,
@@ -118,10 +119,15 @@ namespace SabreTools
skip = false,
update = false,
usegame = true;
bool? nodump = null;
long sgt = -1,
slt = -1,
seq = -1;
string addext = "",
author = "",
category = "",
comment = "",
crc = "",
date = "",
description = "",
email = "",
@@ -131,14 +137,19 @@ namespace SabreTools
forcemerge = "",
forcend = "",
forcepack = "",
gamename = "",
header = "",
homepage = "",
name = "",
manu = "",
md5 = "",
outdir = "",
postfix = "",
prefix = "",
repext = "",
romname = "",
romtype = "",
sha1 = "",
sources = "",
systems = "",
root = "",
@@ -208,6 +219,10 @@ namespace SabreTools
case "--ext-split":
extsplit = true;
break;
case "-f":
case "--filter":
filter = true;
break;
case "-g":
case "--generate":
generate = true;
@@ -218,7 +233,7 @@ namespace SabreTools
break;
case "-gp":
case "--game-prefix":
gamename = true;
datprefix = true;
break;
case "-hs":
case "--hash-split":
@@ -248,6 +263,14 @@ namespace SabreTools
case "--merge":
merge = true;
break;
case "-nd":
case "--nodump":
nodump = true;
break;
case "-nnd":
case "--not-nodump":
nodump = false;
break;
case "-nr":
case "--no-rename":
norename = true;
@@ -340,6 +363,10 @@ namespace SabreTools
{
comment = arg.Split('=')[1];
}
else if (arg.StartsWith("-crc=") || arg.StartsWith("--crc="))
{
crc = arg.Split('=')[1];
}
else if (arg.StartsWith("-da=") || arg.StartsWith("--date="))
{
date = arg.Split('=')[1];
@@ -376,6 +403,10 @@ namespace SabreTools
{
forcepack = arg.Split('=')[1];
}
else if (arg.StartsWith("-gn=") || arg.StartsWith("--game-name="))
{
gamename = arg.Split('=')[1];
}
else if (arg.StartsWith("-h=") || arg.StartsWith("--header="))
{
header = arg.Split('=')[1];
@@ -392,6 +423,10 @@ namespace SabreTools
{
manu = arg.Split('=')[1];
}
else if (arg.StartsWith("-md5=") || arg.StartsWith("--md5="))
{
md5 = arg.Split('=')[1];
}
else if (arg.StartsWith("-n=") || arg.StartsWith("--name="))
{
name = arg.Split('=')[1];
@@ -408,6 +443,39 @@ namespace SabreTools
{
prefix = arg.Split('=')[1];
}
else if (arg.StartsWith("-rn=") || arg.StartsWith("--rom-name="))
{
romname = arg.Split('=')[1];
}
else if (arg.StartsWith("-rt=") || arg.StartsWith("--rom-type="))
{
romtype = arg.Split('=')[1];
}
else if (arg.StartsWith("-seq=") || arg.StartsWith("--equal="))
{
if (!Int64.TryParse(arg.Split('=')[1], out seq))
{
seq = -1;
}
}
else if (arg.StartsWith("-sgt=") || arg.StartsWith("--greater="))
{
if (!Int64.TryParse(arg.Split('=')[1], out sgt))
{
sgt = -1;
}
}
else if (arg.StartsWith("-sha1=") || arg.StartsWith("--sha1="))
{
sha1 = arg.Split('=')[1];
}
else if (arg.StartsWith("-slt=") || arg.StartsWith("--less="))
{
if (!Int64.TryParse(arg.Split('=')[1], out slt))
{
slt = -1;
}
}
else if (arg.StartsWith("-source=") && sources == "")
{
sources = arg.Split('=')[1];
@@ -467,7 +535,7 @@ namespace SabreTools
}
// If more than one switch is enabled, show the help screen
if (!(add ^ extsplit ^ generate ^ genall ^ hashsplit ^ import ^ listsrc ^ listsys ^ (merge || diff) ^
if (!(add ^ extsplit ^ filter ^ generate ^ genall ^ hashsplit ^ import ^ listsrc ^ listsys ^ (merge || diff) ^
(update || outputCMP || outputRC || outputSD || outputXML || outputMiss || romba) ^ rem ^ stats ^ trim))
{
_logger.Error("Only one feature switch is allowed at a time");
@@ -478,7 +546,7 @@ namespace SabreTools
// If a switch that requires a filename is set and no file is, show the help screen
if (inputs.Count == 0 && (update || (outputMiss || romba) || outputCMP || outputRC || outputSD
|| outputXML || extsplit || hashsplit || (merge || diff) || stats || trim))
|| outputXML || filter || extsplit || hashsplit || (merge || diff) || stats || trim))
{
_logger.Error("This feature requires at least one input");
Build.Help();
@@ -527,7 +595,7 @@ namespace SabreTools
{
InitUpdate(input, filename, name, description, category, version, date, author, email, homepage, url, comment, header,
superdat, forcemerge, forcend, forcepack, outputCMP, outputMiss, outputRC, outputSD, outputXML, usegame, prefix,
postfix, quotes, repext, addext, gamename, romba, tsv, outdir, clean);
postfix, quotes, repext, addext, datprefix, romba, tsv, outdir, clean);
}
}
@@ -601,6 +669,12 @@ namespace SabreTools
InitStats(inputs, single);
}
// Filter input files
else if (filter)
{
InitFilter(inputs, outdir, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger);
}
// If nothing is set, show the help
else
{

View File

@@ -105,6 +105,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ExtSplit.cs" />
<Compile Include="Filter.cs" />
<Compile Include="ImportExport\Generate.cs" />
<Compile Include="ImportExport\GenerateTwo.cs" />
<Compile Include="HashSplit.cs" />

View File

@@ -102,7 +102,7 @@ namespace SabreTools
/// <param name="quotes">Add quotes to each item</param>
/// <param name="repext">Replace all extensions with another</param>
/// <param name="addext">Add an extension to all items</param>
/// <param name="gamename">Add the dat name as a directory prefix</param>
/// <param name="datprefix">Add the dat name as a directory prefix</param>
/// <param name="romba">Output files in romba format</param>
/// <param name="tsv">Output files in TSV format</param>
/// <param name="outdir">Optional param for output directory</param>
@@ -135,7 +135,7 @@ namespace SabreTools
bool quotes,
string repext,
string addext,
bool gamename,
bool datprefix,
bool romba,
bool tsv,
string outdir,
@@ -221,7 +221,7 @@ namespace SabreTools
Quotes = quotes,
RepExt = repext,
AddExt = addext,
GameName = gamename,
GameName = datprefix,
Romba = romba,
TSV = tsv,
};
@@ -491,6 +491,61 @@ namespace SabreTools
statlog.Close();
}
/// <summary>
/// Wrap filtering a DAT or set of DATs
/// </summary>
/// <param name="inputs">List of inputs to be procesed</param>
/// <param name="outdir">Output directory for new files (optional)</param>
/// <param name="gamename">Name of the game to match (can use asterisk-partials)</param>
/// <param name="romname">Name of the rom to match (can use asterisk-partials)</param>
/// <param name="romtype">Type of the rom to match</param>
/// <param name="sgt">Find roms greater than or equal to this size</param>
/// <param name="slt">Find roms less than or equal to this size</param>
/// <param name="seq">Find roms equal to this size</param>
/// <param name="crc">CRC of the rom to match (can use asterisk-partials)</param>
/// <param name="md5">MD5 of the rom to match (can use asterisk-partials)</param>
/// <param name="sha1">SHA-1 of the rom to match (can use asterisk-partials)</param>
/// <param name="nodump">Select roms with nodump status as follows: null (match all), true (match Nodump only), false (exclude Nodump)</param>
/// <param name="logger">Logging object for file and console output</param>
private static void InitFilter(List<string> inputs, string outdir, string gamename, string romname, string romtype, long sgt,
long slt, long seq, string crc, string md5, string sha1, bool? nodump, Logger logger)
{
// Create new Filter objects for each input
Filter filter;
bool success = true;
foreach (string input in inputs)
{
string newinput = Path.GetFullPath(input.Replace("\"", ""));
if (File.Exists(newinput))
{
filter = new Filter(newinput, outdir, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger);
success &= filter.Process();
}
if (Directory.Exists(newinput))
{
foreach (string file in Directory.EnumerateFiles(newinput, "*", SearchOption.AllDirectories))
{
string nestedoutdir = "";
if (outdir != "")
{
nestedoutdir = outdir + Path.GetDirectoryName(file).Remove(0, newinput.Length);
}
filter = new Filter(file, nestedoutdir, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger);
success &= filter.Process();
}
}
}
// If we failed, show the help
if (!success)
{
Console.WriteLine();
Build.Help();
}
}
/// <summary>
/// Wrap adding a new source to the database
/// </summary>

View File

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

View File

@@ -1,86 +0,0 @@
<?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>{136AA0D0-9234-4680-B593-A32C0762972E}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SabreTools</RootNamespace>
<AssemblyName>Filter</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>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\..\Debug-x64\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>..\..\Release-x64\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</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="Filter.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

@@ -1,36 +0,0 @@
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("Filter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Filter")]
[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("136aa0d0-9234-4680-b593-a32c0762972e")]
// 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

@@ -15,8 +15,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DATFromDir", "DATFromDir\DA
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OfflineMerge", "OfflineMerge\OfflineMerge.csproj", "{88310DB9-3B64-4268-AD48-2E0358D4CA5F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Filter", "Filter\Filter.csproj", "{136AA0D0-9234-4680-B593-A32C0762972E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -70,14 +68,6 @@ Global
{88310DB9-3B64-4268-AD48-2E0358D4CA5F}.Release|Any CPU.Build.0 = Release|Any CPU
{88310DB9-3B64-4268-AD48-2E0358D4CA5F}.Release|x64.ActiveCfg = Release|x64
{88310DB9-3B64-4268-AD48-2E0358D4CA5F}.Release|x64.Build.0 = Release|x64
{136AA0D0-9234-4680-B593-A32C0762972E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{136AA0D0-9234-4680-B593-A32C0762972E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{136AA0D0-9234-4680-B593-A32C0762972E}.Debug|x64.ActiveCfg = Debug|x64
{136AA0D0-9234-4680-B593-A32C0762972E}.Debug|x64.Build.0 = Debug|x64
{136AA0D0-9234-4680-B593-A32C0762972E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{136AA0D0-9234-4680-B593-A32C0762972E}.Release|Any CPU.Build.0 = Release|Any CPU
{136AA0D0-9234-4680-B593-A32C0762972E}.Release|x64.ActiveCfg = Release|Any CPU
{136AA0D0-9234-4680-B593-A32C0762972E}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE