mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add new tool: HashSplit
This tool will simply split a DAT by the "best" available hash in order of SHA-1, MD5, and CRC/No-Hash. The files are output to the same directory as the original file. Requested by Obiwantje.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -11,6 +11,9 @@
|
||||
/Deheader/obj
|
||||
/Deheader/obj/Debug
|
||||
/Deheader/obj/Release
|
||||
/HashSplit/obj
|
||||
/HashSplit/obj/Debug
|
||||
/HashSplit/obj/Release
|
||||
/OfflineMerge/obj
|
||||
/OfflineMerge/obj/Debug
|
||||
/OfflineMerge/obj/Release
|
||||
|
||||
6
HashSplit/App.config
Normal file
6
HashSplit/App.config
Normal 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>
|
||||
234
HashSplit/HashSplit.cs
Normal file
234
HashSplit/HashSplit.cs
Normal file
@@ -0,0 +1,234 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using SabreTools.Helper;
|
||||
|
||||
namespace SabreTools
|
||||
{
|
||||
public class HashSplit
|
||||
{
|
||||
// Internal variables
|
||||
string _filename;
|
||||
Logger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Create a HashSplit object
|
||||
/// </summary>
|
||||
/// <param name="filename">The name of the file to be split</param>
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
public HashSplit(string filename, Logger logger)
|
||||
{
|
||||
_filename = filename;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start help or use supplied parameters
|
||||
/// </summary>
|
||||
/// <param name="args">String array representing command line parameters</param>
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.Clear();
|
||||
|
||||
// Credits take precidence over all
|
||||
if ((new List<string>(args)).Contains("--credits"))
|
||||
{
|
||||
Build.Credits();
|
||||
return;
|
||||
}
|
||||
|
||||
Logger logger = new Logger(true, "hashsplit.log");
|
||||
logger.Start();
|
||||
|
||||
// First things first, take care of all of the arguments that this could have
|
||||
string filename = "";
|
||||
foreach (string arg in args)
|
||||
{
|
||||
switch (arg)
|
||||
{
|
||||
case "-h":
|
||||
case "-?":
|
||||
case "--help":
|
||||
Build.Help();
|
||||
logger.Close();
|
||||
return;
|
||||
default:
|
||||
filename = arg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If there's no inputs, show the help
|
||||
if (filename == "")
|
||||
{
|
||||
Build.Help();
|
||||
logger.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Output the title
|
||||
Build.Start("HashSplit");
|
||||
|
||||
// Verify the input file
|
||||
filename = filename.Replace("\"", "");
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
logger.Error(filename + " is not a valid file!");
|
||||
Console.WriteLine();
|
||||
Build.Help();
|
||||
return;
|
||||
}
|
||||
|
||||
// If so, run the program
|
||||
filename = Path.GetFullPath(filename);
|
||||
HashSplit hs = new HashSplit(filename, logger);
|
||||
hs.Split();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Split the DAT into parts by best-available hash data
|
||||
/// </summary>
|
||||
/// <returns>True if the DATs were output, false otherwise</returns>
|
||||
public bool Split()
|
||||
{
|
||||
// Get the file data to be split
|
||||
OutputFormat outputFormat = RomManipulation.GetOutputFormat(_filename);
|
||||
DatData datdata = new DatData
|
||||
{
|
||||
Roms = new Dictionary<string, List<RomData>>(),
|
||||
};
|
||||
datdata = RomManipulation.Parse(_filename, 0, 0, datdata, _logger, true);
|
||||
|
||||
// Create each of the respective output DATs
|
||||
DatData sha1 = new DatData
|
||||
{
|
||||
Name = datdata.Name + " (SHA-1)",
|
||||
Description = datdata.Description + " (SHA-1)",
|
||||
Category = datdata.Category,
|
||||
Version = datdata.Version,
|
||||
Date = datdata.Date,
|
||||
Author = datdata.Author,
|
||||
Email = datdata.Email,
|
||||
Homepage = datdata.Homepage,
|
||||
Url = datdata.Url,
|
||||
Comment = datdata.Comment,
|
||||
Header = datdata.Header,
|
||||
Type = datdata.Type,
|
||||
ForceMerging = datdata.ForceMerging,
|
||||
ForceNodump = datdata.ForceNodump,
|
||||
ForcePacking = datdata.ForcePacking,
|
||||
OutputFormat = outputFormat,
|
||||
MergeRoms = datdata.MergeRoms,
|
||||
Roms = new Dictionary<string, List<RomData>>(),
|
||||
};
|
||||
DatData md5 = new DatData
|
||||
{
|
||||
Name = datdata.Name + " (MD5)",
|
||||
Description = datdata.Description + " (MD5)",
|
||||
Category = datdata.Category,
|
||||
Version = datdata.Version,
|
||||
Date = datdata.Date,
|
||||
Author = datdata.Author,
|
||||
Email = datdata.Email,
|
||||
Homepage = datdata.Homepage,
|
||||
Url = datdata.Url,
|
||||
Comment = datdata.Comment,
|
||||
Header = datdata.Header,
|
||||
Type = datdata.Type,
|
||||
ForceMerging = datdata.ForceMerging,
|
||||
ForceNodump = datdata.ForceNodump,
|
||||
ForcePacking = datdata.ForcePacking,
|
||||
OutputFormat = outputFormat,
|
||||
MergeRoms = datdata.MergeRoms,
|
||||
Roms = new Dictionary<string, List<RomData>>(),
|
||||
};
|
||||
DatData crc = new DatData
|
||||
{
|
||||
Name = datdata.Name + " (CRC and None)",
|
||||
Description = datdata.Description + " (CRC and None)",
|
||||
Category = datdata.Category,
|
||||
Version = datdata.Version,
|
||||
Date = datdata.Date,
|
||||
Author = datdata.Author,
|
||||
Email = datdata.Email,
|
||||
Homepage = datdata.Homepage,
|
||||
Url = datdata.Url,
|
||||
Comment = datdata.Comment,
|
||||
Header = datdata.Header,
|
||||
Type = datdata.Type,
|
||||
ForceMerging = datdata.ForceMerging,
|
||||
ForceNodump = datdata.ForceNodump,
|
||||
ForcePacking = datdata.ForcePacking,
|
||||
OutputFormat = outputFormat,
|
||||
MergeRoms = datdata.MergeRoms,
|
||||
Roms = new Dictionary<string, List<RomData>>(),
|
||||
};
|
||||
|
||||
// Now populate each of the DAT objects in turn
|
||||
List<string> keys = datdata.Roms.Keys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<RomData> roms = datdata.Roms[key];
|
||||
foreach (RomData rom in roms)
|
||||
{
|
||||
// If the file has a SHA-1
|
||||
if (rom.SHA1 != null && rom.SHA1 != "")
|
||||
{
|
||||
if (sha1.Roms.ContainsKey(key))
|
||||
{
|
||||
sha1.Roms[key].Add(rom);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RomData> temp = new List<RomData>();
|
||||
temp.Add(rom);
|
||||
sha1.Roms.Add(key, temp);
|
||||
}
|
||||
}
|
||||
// If the file has no SHA-1 but has an MD5
|
||||
else if (rom.MD5 != null && rom.MD5 != "")
|
||||
{
|
||||
if (md5.Roms.ContainsKey(key))
|
||||
{
|
||||
md5.Roms[key].Add(rom);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RomData> temp = new List<RomData>();
|
||||
temp.Add(rom);
|
||||
md5.Roms.Add(key, temp);
|
||||
}
|
||||
}
|
||||
// All other cases
|
||||
else
|
||||
{
|
||||
if (crc.Roms.ContainsKey(key))
|
||||
{
|
||||
crc.Roms[key].Add(rom);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<RomData> temp = new List<RomData>();
|
||||
temp.Add(rom);
|
||||
crc.Roms.Add(key, temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool success = true;
|
||||
|
||||
// Now, output all of the files to the original location
|
||||
string outdir = Path.GetDirectoryName(_filename);
|
||||
success &= Output.WriteDatfile(sha1, outdir, _logger);
|
||||
success &= Output.WriteDatfile(md5, outdir, _logger);
|
||||
success &= Output.WriteDatfile(crc, outdir, _logger);
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
}
|
||||
103
HashSplit/HashSplit.csproj
Normal file
103
HashSplit/HashSplit.csproj
Normal file
@@ -0,0 +1,103 @@
|
||||
<?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>{9E2D38DA-8D65-45B4-A853-6DBEE04B6BA4}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SabreTools</RootNamespace>
|
||||
<AssemblyName>HashSplit</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</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="HashSplit.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>
|
||||
36
HashSplit/Properties/AssemblyInfo.cs
Normal file
36
HashSplit/Properties/AssemblyInfo.cs
Normal 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("HashSplit")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("HashSplit")]
|
||||
[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("9e2d38da-8d65-45b4-a853-6dbee04b6ba4")]
|
||||
|
||||
// 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")]
|
||||
@@ -210,6 +210,15 @@ Options:
|
||||
-nr, --no-rename Don't auto-rename games by source/system
|
||||
-o, --old Output DAT in CMP format instead of XML
|
||||
-sys=, --system= System ID to generate from
|
||||
");
|
||||
break;
|
||||
case "HashSplit":
|
||||
Console.WriteLine(@"HashSplit - Split a DAT by best-available hashes
|
||||
-----------------------------------------
|
||||
Usage: DATabaseTwo [options] filename
|
||||
|
||||
Options:
|
||||
-h, -?, --help Show this help dialog
|
||||
");
|
||||
break;
|
||||
default:
|
||||
|
||||
Binary file not shown.
@@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UncompressedSize", "Uncompr
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DATabaseTwo", "DATabaseTwo\DATabaseTwo.csproj", "{C7732A05-1F96-43ED-AC8C-0E388F37EBC1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HashSplit", "HashSplit\HashSplit.csproj", "{9E2D38DA-8D65-45B4-A853-6DBEE04B6BA4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -92,6 +94,14 @@ Global
|
||||
{C7732A05-1F96-43ED-AC8C-0E388F37EBC1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C7732A05-1F96-43ED-AC8C-0E388F37EBC1}.Release|x64.ActiveCfg = Release|x64
|
||||
{C7732A05-1F96-43ED-AC8C-0E388F37EBC1}.Release|x64.Build.0 = Release|x64
|
||||
{9E2D38DA-8D65-45B4-A853-6DBEE04B6BA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9E2D38DA-8D65-45B4-A853-6DBEE04B6BA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9E2D38DA-8D65-45B4-A853-6DBEE04B6BA4}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9E2D38DA-8D65-45B4-A853-6DBEE04B6BA4}.Debug|x64.Build.0 = Debug|x64
|
||||
{9E2D38DA-8D65-45B4-A853-6DBEE04B6BA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9E2D38DA-8D65-45B4-A853-6DBEE04B6BA4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9E2D38DA-8D65-45B4-A853-6DBEE04B6BA4}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{9E2D38DA-8D65-45B4-A853-6DBEE04B6BA4}.Release|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user