mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DATabase] Clean up partial classes further
This commit is contained in:
@@ -571,277 +571,6 @@ namespace SabreTools
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Init Methods
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wrap importing and updating DATs
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ignore"></param>
|
|
||||||
private static void InitImport(bool ignore)
|
|
||||||
{
|
|
||||||
IImport imp = new ImportTwo(_datroot, _connectionString, _logger, ignore);
|
|
||||||
imp.UpdateDatabase();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wrap trimming and merging a single DAT
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="input">Input file or folder to be converted</param>
|
|
||||||
/// <param name="root">Root directory to base path lengths on</param>
|
|
||||||
/// <param name="rename">True is games should not be renamed</param>
|
|
||||||
/// <param name="force">True if forcepacking="unzip" should be included</param>
|
|
||||||
private static void InitTrimMerge(string input, string root, bool rename, bool force)
|
|
||||||
{
|
|
||||||
// Strip any quotations from the name
|
|
||||||
input = input.Replace("\"", "");
|
|
||||||
|
|
||||||
if (input != "" && (File.Exists(input) || Directory.Exists(input)))
|
|
||||||
{
|
|
||||||
TrimMerge sg = new TrimMerge(input, root, rename, force, _logger);
|
|
||||||
sg.Process();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wrap merging, diffing, and deduping 2 or mor DATs
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="inputs">A List of Strings representing the DATs or DAT folders to be merged</param>
|
|
||||||
/// <param name="name">Internal name of the DAT</param>
|
|
||||||
/// <param name="desc">Description and external name of the DAT</param>
|
|
||||||
/// <param name="cat">Category for the DAT</param>
|
|
||||||
/// <param name="version">Version of the DAT</param>
|
|
||||||
/// <param name="author">Author of the DAT</param>
|
|
||||||
/// <param name="diff">True if a DiffDat of all inputs is wanted, false otherwise</param>
|
|
||||||
/// <param name="dedup">True if the outputted file should remove duplicates, false otherwise</param>
|
|
||||||
/// <param name="bare">True if the date should be omitted from the DAT, false otherwise</param>
|
|
||||||
/// <param name="forceunpack">True if the forcepacking="unzip" tag is to be added, false otherwise</param>
|
|
||||||
/// <param name="old">True if a old-style DAT should be output, false otherwise</param>
|
|
||||||
/// <param name="superdat">True if DATs should be merged in SuperDAT style, false otherwise</param>
|
|
||||||
/// <param name="cascade">True if the outputted diffs should be cascaded, false otherwise</param>
|
|
||||||
/// <param name="inplace">True if cascaded diffs overwrite the source files, false otherwise</param>
|
|
||||||
/// <param name="outdir">Output directory for the files (blank is default)</param>
|
|
||||||
/// <param name="clean">True to clean the game names to WoD standard, false otherwise (default)</param>
|
|
||||||
private static void InitMergeDiff(List<string> inputs, string name, string desc, string cat, string version, string author,
|
|
||||||
bool diff, bool dedup, bool bare, bool forceunpack, bool old, bool superdat, bool cascade, bool inplace, string outdir = "", bool clean = false)
|
|
||||||
{
|
|
||||||
// Make sure there are no folders in inputs
|
|
||||||
List<string> newInputs = new List<string>();
|
|
||||||
foreach (string input in inputs)
|
|
||||||
{
|
|
||||||
if (Directory.Exists(input.Replace("\"", "")))
|
|
||||||
{
|
|
||||||
foreach (string file in Directory.EnumerateFiles(input.Replace("\"", ""), "*", SearchOption.AllDirectories))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
newInputs.Add(Path.GetFullPath(file) + "¬" + Path.GetFullPath(input.Replace("\"", "")));
|
|
||||||
}
|
|
||||||
catch (PathTooLongException)
|
|
||||||
{
|
|
||||||
_logger.Warning("The path for " + file + " was too long");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.Error(ex.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (File.Exists(input.Replace("\"", "")))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
newInputs.Add(Path.GetFullPath(input.Replace("\"", "")) + "¬" + Path.GetDirectoryName(Path.GetFullPath(input.Replace("\"", ""))));
|
|
||||||
}
|
|
||||||
catch (PathTooLongException)
|
|
||||||
{
|
|
||||||
_logger.Warning("The path for " + input.Replace("\"", "") + " was too long");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.Error(ex.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MergeDiff md = new MergeDiff(newInputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat, cascade, inplace, outdir, clean, _logger);
|
|
||||||
md.Process();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wrap splitting a DAT by 2 extensions
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="input">Input file or folder to be split</param>
|
|
||||||
/// <param name="exta">First extension to split on</param>
|
|
||||||
/// <param name="extb">Second extension to split on</param>
|
|
||||||
/// <param name="outdir">Output directory for the split files</param>
|
|
||||||
private static void InitExtSplit(string input, string exta, string extb, string outdir)
|
|
||||||
{
|
|
||||||
// Strip any quotations from the names
|
|
||||||
input = input.Replace("\"", "");
|
|
||||||
exta = exta.Replace("\"", "");
|
|
||||||
extb = extb.Replace("\"", "");
|
|
||||||
outdir = outdir.Replace("\"", "");
|
|
||||||
|
|
||||||
if (input != "" && File.Exists(input))
|
|
||||||
{
|
|
||||||
if (exta == "" || extb == "")
|
|
||||||
{
|
|
||||||
_logger.Warning("Two extensions are needed to split a DAT!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ExtSplit es = new ExtSplit(input, exta, extb, outdir, _logger);
|
|
||||||
es.Split();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Log("I'm sorry but " + input + "doesn't exist!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wrap splitting a DAT by best available hashes
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="inputs">List of inputs to be used</param>
|
|
||||||
/// <param name="outdir">Output directory for the split files</param>
|
|
||||||
private static void InitHashSplit(List<string> inputs, string outdir)
|
|
||||||
{
|
|
||||||
// Strip any quotations from the names
|
|
||||||
outdir = outdir.Replace("\"", "");
|
|
||||||
|
|
||||||
// Verify the input files
|
|
||||||
foreach (string input in inputs)
|
|
||||||
{
|
|
||||||
if (!File.Exists(input.Replace("\"", "")) && !Directory.Exists(input.Replace("\"", "")))
|
|
||||||
{
|
|
||||||
_logger.Error(input + " is not a valid file or folder!");
|
|
||||||
Console.WriteLine();
|
|
||||||
Build.Help();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If so, run the program
|
|
||||||
HashSplit hs = new HashSplit(inputs, outdir, _logger);
|
|
||||||
hs.Split();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wrap getting statistics on a DAT or folder of DATs
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="inputs">List of inputs to be used</param>
|
|
||||||
/// <param name="single">True to show individual DAT statistics, false otherwise</param>
|
|
||||||
private static void InitStats(List<string> inputs, bool single)
|
|
||||||
{
|
|
||||||
List<string> newinputs = new List<string>();
|
|
||||||
|
|
||||||
foreach (string input in inputs)
|
|
||||||
{
|
|
||||||
if (File.Exists(input.Replace("\"", "")))
|
|
||||||
{
|
|
||||||
newinputs.Add(input.Replace("\"", ""));
|
|
||||||
}
|
|
||||||
if (Directory.Exists(input.Replace("\"", "")))
|
|
||||||
{
|
|
||||||
foreach (string file in Directory.GetFiles(input.Replace("\"", ""), "*", SearchOption.AllDirectories))
|
|
||||||
{
|
|
||||||
newinputs.Add(file.Replace("\"", ""));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger statlog = new Logger(true, "stats.txt");
|
|
||||||
statlog.Start();
|
|
||||||
Stats stats = new Stats(newinputs, single, statlog);
|
|
||||||
stats.Process();
|
|
||||||
statlog.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wrap adding a new source to the database
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">Source name</param>
|
|
||||||
/// <param name="url">Source URL(s)</param>
|
|
||||||
private static void InitAddSource(string name, string url)
|
|
||||||
{
|
|
||||||
if (DBTools.AddSource(name, url, _connectionString))
|
|
||||||
{
|
|
||||||
_logger.Log("Source " + name + " added!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Error("Source " + name + " could not be added!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wrap removing an existing source from the database
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">Source ID to be removed from the database</param>
|
|
||||||
private static void InitRemoveSource(string sourceid)
|
|
||||||
{
|
|
||||||
int srcid = -1;
|
|
||||||
if (Int32.TryParse(sourceid, out srcid))
|
|
||||||
{
|
|
||||||
if (DBTools.RemoveSource(srcid, _connectionString))
|
|
||||||
{
|
|
||||||
_logger.Log("Source '" + srcid + "' removed!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Error("Source with id '" + srcid + "' could not be removed.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Error("Invalid input");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wrap adding a new system to the database
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="manufacturer">Manufacturer name</param>
|
|
||||||
/// <param name="system">System name</param>
|
|
||||||
private static void InitAddSystem(string manufacturer, string system)
|
|
||||||
{
|
|
||||||
if (DBTools.AddSystem(manufacturer, system, _connectionString))
|
|
||||||
{
|
|
||||||
_logger.Log("System " + manufacturer + " - " + system + " added!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Error("System " + manufacturer + " - " + system + " could not be added!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wrap removing an existing system from the database
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">System ID to be removed from the database</param>
|
|
||||||
private static void InitRemoveSystem(string systemid)
|
|
||||||
{
|
|
||||||
int sysid = -1;
|
|
||||||
if (Int32.TryParse(systemid, out sysid))
|
|
||||||
{
|
|
||||||
if (DBTools.RemoveSystem(sysid, _connectionString))
|
|
||||||
{
|
|
||||||
_logger.Log("System '" + sysid + "' removed!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Error("System with id '" + sysid + "' could not be removed.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Error("Invalid input");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Helper methods
|
#region Helper methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -112,12 +112,11 @@
|
|||||||
<Compile Include="DATabase.cs" />
|
<Compile Include="DATabase.cs" />
|
||||||
<Compile Include="ImportExport\ImportTwo.cs" />
|
<Compile Include="ImportExport\ImportTwo.cs" />
|
||||||
<Compile Include="MergeDiff.cs" />
|
<Compile Include="MergeDiff.cs" />
|
||||||
<Compile Include="Partials\DATabase_InitGenerate.cs" />
|
<Compile Include="Partials\DATabase_Inits.cs" />
|
||||||
<Compile Include="Partials\DATabase_Menus.cs" />
|
<Compile Include="Partials\DATabase_Menus.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="TrimMerge.cs" />
|
<Compile Include="TrimMerge.cs" />
|
||||||
<Compile Include="Stats.cs" />
|
<Compile Include="Stats.cs" />
|
||||||
<Compile Include="Partials\DATabase_InitUpdate.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using Mono.Data.Sqlite;
|
|
||||||
|
|
||||||
using SabreTools.Helper;
|
|
||||||
|
|
||||||
namespace SabreTools
|
|
||||||
{
|
|
||||||
public partial class DATabase
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Wrap generating a DAT from the library
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="system">System ID to be used in the DAT (blank means all)</param>
|
|
||||||
/// <param name="norename">True if files should not be renamed with system and/or source in merged mode (default false)</param>
|
|
||||||
/// <param name="old">True if the output file should be in ClrMamePro format (default false)</param>
|
|
||||||
private static void InitGenerate(string systemid, bool norename, bool old)
|
|
||||||
{
|
|
||||||
IGenerate gen = new GenerateTwo(systemid, "" /* sourceid */, _datroot, _outroot, _connectionString, _logger, norename, old);
|
|
||||||
gen.Export();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wrap generating all standard DATs from the library
|
|
||||||
/// </summary>
|
|
||||||
private static void InitGenerateAll(bool norename, bool old)
|
|
||||||
{
|
|
||||||
List<string> systems = new List<string>();
|
|
||||||
using (SqliteConnection dbc = new SqliteConnection(_connectionString))
|
|
||||||
{
|
|
||||||
dbc.Open();
|
|
||||||
|
|
||||||
string query = "SELECT id FROM system";
|
|
||||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
|
||||||
{
|
|
||||||
using (SqliteDataReader sldr = slc.ExecuteReader())
|
|
||||||
{
|
|
||||||
// If nothing is found, tell the user and exit
|
|
||||||
if (!sldr.HasRows)
|
|
||||||
{
|
|
||||||
_logger.Warning("No systems found! Please add a system and then try again.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (sldr.Read())
|
|
||||||
{
|
|
||||||
systems.Add(sldr.GetInt32(0).ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop through the inputs
|
|
||||||
foreach (string system in systems)
|
|
||||||
{
|
|
||||||
_logger.User("Generating DAT for system id " + system);
|
|
||||||
InitGenerate(system, norename, old);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,76 @@
|
|||||||
using System.IO;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using Mono.Data.Sqlite;
|
||||||
|
|
||||||
using SabreTools.Helper;
|
using SabreTools.Helper;
|
||||||
|
|
||||||
namespace SabreTools
|
namespace SabreTools
|
||||||
{
|
{
|
||||||
public partial class DATabase
|
public partial class DATabase
|
||||||
{
|
{
|
||||||
|
#region Init Methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wrap importing and updating DATs
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ignore"></param>
|
||||||
|
private static void InitImport(bool ignore)
|
||||||
|
{
|
||||||
|
IImport imp = new ImportTwo(_datroot, _connectionString, _logger, ignore);
|
||||||
|
imp.UpdateDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wrap generating a DAT from the library
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="system">System ID to be used in the DAT (blank means all)</param>
|
||||||
|
/// <param name="norename">True if files should not be renamed with system and/or source in merged mode (default false)</param>
|
||||||
|
/// <param name="old">True if the output file should be in ClrMamePro format (default false)</param>
|
||||||
|
private static void InitGenerate(string systemid, bool norename, bool old)
|
||||||
|
{
|
||||||
|
IGenerate gen = new GenerateTwo(systemid, "" /* sourceid */, _datroot, _outroot, _connectionString, _logger, norename, old);
|
||||||
|
gen.Export();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wrap generating all standard DATs from the library
|
||||||
|
/// </summary>
|
||||||
|
private static void InitGenerateAll(bool norename, bool old)
|
||||||
|
{
|
||||||
|
List<string> systems = new List<string>();
|
||||||
|
using (SqliteConnection dbc = new SqliteConnection(_connectionString))
|
||||||
|
{
|
||||||
|
dbc.Open();
|
||||||
|
|
||||||
|
string query = "SELECT id FROM system";
|
||||||
|
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||||
|
{
|
||||||
|
using (SqliteDataReader sldr = slc.ExecuteReader())
|
||||||
|
{
|
||||||
|
// If nothing is found, tell the user and exit
|
||||||
|
if (!sldr.HasRows)
|
||||||
|
{
|
||||||
|
_logger.Warning("No systems found! Please add a system and then try again.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (sldr.Read())
|
||||||
|
{
|
||||||
|
systems.Add(sldr.GetInt32(0).ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through the inputs
|
||||||
|
foreach (string system in systems)
|
||||||
|
{
|
||||||
|
_logger.User("Generating DAT for system id " + system);
|
||||||
|
InitGenerate(system, norename, old);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wrap converting and updating DAT file from any format to any format
|
/// Wrap converting and updating DAT file from any format to any format
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -41,7 +107,7 @@ namespace SabreTools
|
|||||||
/// <param name="tsv">Output files in TSV format</param>
|
/// <param name="tsv">Output files in TSV format</param>
|
||||||
/// <param name="outdir">Optional param for output directory</param>
|
/// <param name="outdir">Optional param for output directory</param>
|
||||||
/// <param name="clean">True to clean the game names to WoD standard, false otherwise (default)</param>
|
/// <param name="clean">True to clean the game names to WoD standard, false otherwise (default)</param>
|
||||||
public static void InitUpdate(string input,
|
private static void InitUpdate(string input,
|
||||||
string filename,
|
string filename,
|
||||||
string name,
|
string name,
|
||||||
string description,
|
string description,
|
||||||
@@ -198,7 +264,7 @@ namespace SabreTools
|
|||||||
/// <param name="datdata">User specified inputs contained in a DatData object</param>
|
/// <param name="datdata">User specified inputs contained in a DatData object</param>
|
||||||
/// <param name="outputDirectory">Optional param for output directory</param>
|
/// <param name="outputDirectory">Optional param for output directory</param>
|
||||||
/// <param name="clean">True to clean the game names to WoD standard, false otherwise (default)</param>
|
/// <param name="clean">True to clean the game names to WoD standard, false otherwise (default)</param>
|
||||||
public static void InitUpdate(string inputFileName, DatData datdata, string outputDirectory, bool clean = false)
|
private static void InitUpdate(string inputFileName, DatData datdata, string outputDirectory, bool clean = false)
|
||||||
{
|
{
|
||||||
// Clean the input strings
|
// Clean the input strings
|
||||||
outputDirectory = outputDirectory.Replace("\"", "");
|
outputDirectory = outputDirectory.Replace("\"", "");
|
||||||
@@ -250,6 +316,265 @@ namespace SabreTools
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wrap trimming and merging a single DAT
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">Input file or folder to be converted</param>
|
||||||
|
/// <param name="root">Root directory to base path lengths on</param>
|
||||||
|
/// <param name="rename">True is games should not be renamed</param>
|
||||||
|
/// <param name="force">True if forcepacking="unzip" should be included</param>
|
||||||
|
private static void InitTrimMerge(string input, string root, bool rename, bool force)
|
||||||
|
{
|
||||||
|
// Strip any quotations from the name
|
||||||
|
input = input.Replace("\"", "");
|
||||||
|
|
||||||
|
if (input != "" && (File.Exists(input) || Directory.Exists(input)))
|
||||||
|
{
|
||||||
|
TrimMerge sg = new TrimMerge(input, root, rename, force, _logger);
|
||||||
|
sg.Process();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wrap merging, diffing, and deduping 2 or mor DATs
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="inputs">A List of Strings representing the DATs or DAT folders to be merged</param>
|
||||||
|
/// <param name="name">Internal name of the DAT</param>
|
||||||
|
/// <param name="desc">Description and external name of the DAT</param>
|
||||||
|
/// <param name="cat">Category for the DAT</param>
|
||||||
|
/// <param name="version">Version of the DAT</param>
|
||||||
|
/// <param name="author">Author of the DAT</param>
|
||||||
|
/// <param name="diff">True if a DiffDat of all inputs is wanted, false otherwise</param>
|
||||||
|
/// <param name="dedup">True if the outputted file should remove duplicates, false otherwise</param>
|
||||||
|
/// <param name="bare">True if the date should be omitted from the DAT, false otherwise</param>
|
||||||
|
/// <param name="forceunpack">True if the forcepacking="unzip" tag is to be added, false otherwise</param>
|
||||||
|
/// <param name="old">True if a old-style DAT should be output, false otherwise</param>
|
||||||
|
/// <param name="superdat">True if DATs should be merged in SuperDAT style, false otherwise</param>
|
||||||
|
/// <param name="cascade">True if the outputted diffs should be cascaded, false otherwise</param>
|
||||||
|
/// <param name="inplace">True if cascaded diffs overwrite the source files, false otherwise</param>
|
||||||
|
/// <param name="outdir">Output directory for the files (blank is default)</param>
|
||||||
|
/// <param name="clean">True to clean the game names to WoD standard, false otherwise (default)</param>
|
||||||
|
private static void InitMergeDiff(List<string> inputs, string name, string desc, string cat, string version, string author,
|
||||||
|
bool diff, bool dedup, bool bare, bool forceunpack, bool old, bool superdat, bool cascade, bool inplace, string outdir = "", bool clean = false)
|
||||||
|
{
|
||||||
|
// Make sure there are no folders in inputs
|
||||||
|
List<string> newInputs = new List<string>();
|
||||||
|
foreach (string input in inputs)
|
||||||
|
{
|
||||||
|
if (Directory.Exists(input.Replace("\"", "")))
|
||||||
|
{
|
||||||
|
foreach (string file in Directory.EnumerateFiles(input.Replace("\"", ""), "*", SearchOption.AllDirectories))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
newInputs.Add(Path.GetFullPath(file) + "¬" + Path.GetFullPath(input.Replace("\"", "")));
|
||||||
|
}
|
||||||
|
catch (PathTooLongException)
|
||||||
|
{
|
||||||
|
_logger.Warning("The path for " + file + " was too long");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (File.Exists(input.Replace("\"", "")))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
newInputs.Add(Path.GetFullPath(input.Replace("\"", "")) + "¬" + Path.GetDirectoryName(Path.GetFullPath(input.Replace("\"", ""))));
|
||||||
|
}
|
||||||
|
catch (PathTooLongException)
|
||||||
|
{
|
||||||
|
_logger.Warning("The path for " + input.Replace("\"", "") + " was too long");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MergeDiff md = new MergeDiff(newInputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat, cascade, inplace, outdir, clean, _logger);
|
||||||
|
md.Process();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wrap splitting a DAT by 2 extensions
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">Input file or folder to be split</param>
|
||||||
|
/// <param name="exta">First extension to split on</param>
|
||||||
|
/// <param name="extb">Second extension to split on</param>
|
||||||
|
/// <param name="outdir">Output directory for the split files</param>
|
||||||
|
private static void InitExtSplit(string input, string exta, string extb, string outdir)
|
||||||
|
{
|
||||||
|
// Strip any quotations from the names
|
||||||
|
input = input.Replace("\"", "");
|
||||||
|
exta = exta.Replace("\"", "");
|
||||||
|
extb = extb.Replace("\"", "");
|
||||||
|
outdir = outdir.Replace("\"", "");
|
||||||
|
|
||||||
|
if (input != "" && File.Exists(input))
|
||||||
|
{
|
||||||
|
if (exta == "" || extb == "")
|
||||||
|
{
|
||||||
|
_logger.Warning("Two extensions are needed to split a DAT!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ExtSplit es = new ExtSplit(input, exta, extb, outdir, _logger);
|
||||||
|
es.Split();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Log("I'm sorry but " + input + "doesn't exist!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wrap splitting a DAT by best available hashes
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="inputs">List of inputs to be used</param>
|
||||||
|
/// <param name="outdir">Output directory for the split files</param>
|
||||||
|
private static void InitHashSplit(List<string> inputs, string outdir)
|
||||||
|
{
|
||||||
|
// Strip any quotations from the names
|
||||||
|
outdir = outdir.Replace("\"", "");
|
||||||
|
|
||||||
|
// Verify the input files
|
||||||
|
foreach (string input in inputs)
|
||||||
|
{
|
||||||
|
if (!File.Exists(input.Replace("\"", "")) && !Directory.Exists(input.Replace("\"", "")))
|
||||||
|
{
|
||||||
|
_logger.Error(input + " is not a valid file or folder!");
|
||||||
|
Console.WriteLine();
|
||||||
|
Build.Help();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If so, run the program
|
||||||
|
HashSplit hs = new HashSplit(inputs, outdir, _logger);
|
||||||
|
hs.Split();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wrap getting statistics on a DAT or folder of DATs
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="inputs">List of inputs to be used</param>
|
||||||
|
/// <param name="single">True to show individual DAT statistics, false otherwise</param>
|
||||||
|
private static void InitStats(List<string> inputs, bool single)
|
||||||
|
{
|
||||||
|
List<string> newinputs = new List<string>();
|
||||||
|
|
||||||
|
foreach (string input in inputs)
|
||||||
|
{
|
||||||
|
if (File.Exists(input.Replace("\"", "")))
|
||||||
|
{
|
||||||
|
newinputs.Add(input.Replace("\"", ""));
|
||||||
|
}
|
||||||
|
if (Directory.Exists(input.Replace("\"", "")))
|
||||||
|
{
|
||||||
|
foreach (string file in Directory.GetFiles(input.Replace("\"", ""), "*", SearchOption.AllDirectories))
|
||||||
|
{
|
||||||
|
newinputs.Add(file.Replace("\"", ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger statlog = new Logger(true, "stats.txt");
|
||||||
|
statlog.Start();
|
||||||
|
Stats stats = new Stats(newinputs, single, statlog);
|
||||||
|
stats.Process();
|
||||||
|
statlog.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wrap adding a new source to the database
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Source name</param>
|
||||||
|
/// <param name="url">Source URL(s)</param>
|
||||||
|
private static void InitAddSource(string name, string url)
|
||||||
|
{
|
||||||
|
if (DBTools.AddSource(name, url, _connectionString))
|
||||||
|
{
|
||||||
|
_logger.Log("Source " + name + " added!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Error("Source " + name + " could not be added!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wrap removing an existing source from the database
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Source ID to be removed from the database</param>
|
||||||
|
private static void InitRemoveSource(string sourceid)
|
||||||
|
{
|
||||||
|
int srcid = -1;
|
||||||
|
if (Int32.TryParse(sourceid, out srcid))
|
||||||
|
{
|
||||||
|
if (DBTools.RemoveSource(srcid, _connectionString))
|
||||||
|
{
|
||||||
|
_logger.Log("Source '" + srcid + "' removed!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Error("Source with id '" + srcid + "' could not be removed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Error("Invalid input");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wrap adding a new system to the database
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="manufacturer">Manufacturer name</param>
|
||||||
|
/// <param name="system">System name</param>
|
||||||
|
private static void InitAddSystem(string manufacturer, string system)
|
||||||
|
{
|
||||||
|
if (DBTools.AddSystem(manufacturer, system, _connectionString))
|
||||||
|
{
|
||||||
|
_logger.Log("System " + manufacturer + " - " + system + " added!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Error("System " + manufacturer + " - " + system + " could not be added!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wrap removing an existing system from the database
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">System ID to be removed from the database</param>
|
||||||
|
private static void InitRemoveSystem(string systemid)
|
||||||
|
{
|
||||||
|
int sysid = -1;
|
||||||
|
if (Int32.TryParse(systemid, out sysid))
|
||||||
|
{
|
||||||
|
if (DBTools.RemoveSystem(sysid, _connectionString))
|
||||||
|
{
|
||||||
|
_logger.Log("System '" + sysid + "' removed!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Error("System with id '" + sysid + "' could not be removed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Error("Invalid input");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region OBSOLETE
|
#region OBSOLETE
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
Reference in New Issue
Block a user