diff --git a/SabreTools/Partials/SabreTools_Inits.cs b/SabreTools/Partials/SabreTools_Inits.cs
index 529345f6..61765201 100644
--- a/SabreTools/Partials/SabreTools_Inits.cs
+++ b/SabreTools/Partials/SabreTools_Inits.cs
@@ -12,13 +12,225 @@ namespace SabreTools
#region Init Methods
///
- /// Wrap importing and updating DATs
+ /// Wrap adding a new source to the database
///
- ///
- private static void InitImport(bool ignore)
+ /// Source name
+ /// Source URL(s)
+ private static void InitAddSource(string name, string url)
{
- IImport imp = new ImportTwo(_datroot, _databaseConnectionString, _logger, ignore);
- imp.UpdateDatabase();
+ if (DBTools.AddSource(name, url, _databaseConnectionString))
+ {
+ _logger.Log("Source " + name + " added!");
+ }
+ else
+ {
+ _logger.Error("Source " + name + " could not be added!");
+ }
+ }
+
+ ///
+ /// Wrap adding a new system to the database
+ ///
+ /// Manufacturer name
+ /// System name
+ private static void InitAddSystem(string manufacturer, string system)
+ {
+ if (DBTools.AddSystem(manufacturer, system, _databaseConnectionString))
+ {
+ _logger.Log("System " + manufacturer + " - " + system + " added!");
+ }
+ else
+ {
+ _logger.Error("System " + manufacturer + " - " + system + " could not be added!");
+ }
+ }
+
+ ///
+ /// Wrap creating a DAT file from files or a directory
+ ///
+ /// List of innput filenames
+ /// New filename
+ /// New name
+ /// New description
+ /// New category
+ /// New version
+ /// New author
+ /// True to set forcepacking="unzip" on the created file, false otherwise
+ /// OutputFormat to be used for outputting the DAT
+ /// True to enable reading a directory like a Romba depot, false otherwise
+ /// True to enable SuperDAT-style reading, false otherwise
+ /// True to disable getting MD5 hash, false otherwise
+ /// True to disable getting SHA-1 hash, false otherwise
+ /// True if the date should be omitted from the DAT, false otherwise
+ /// True if archives should be treated as files, false otherwise
+ /// True if GZIP archives should be treated as files, false otherwise
+ /// Name of the directory to create a temp folder in (blank is current directory
+ private static void InitDatFromDir(List inputs,
+ string filename,
+ string name,
+ string description,
+ string category,
+ string version,
+ string author,
+ bool forceunpack,
+ OutputFormat outputFormat,
+ bool romba,
+ bool superdat,
+ bool noMD5,
+ bool noSHA1,
+ bool bare,
+ bool archivesAsFiles,
+ bool enableGzip,
+ string tempDir)
+ {
+ // Create a new DATFromDir object and process the inputs
+ Dat datdata = new Dat
+ {
+ FileName = filename,
+ Name = name,
+ Description = description,
+ Category = category,
+ Version = version,
+ Date = DateTime.Now.ToString("yyyy-MM-dd"),
+ Author = author,
+ ForcePacking = (forceunpack ? ForcePacking.Unzip : ForcePacking.None),
+ OutputFormat = outputFormat,
+ Romba = romba,
+ Type = (superdat ? "SuperDAT" : ""),
+ Files = new Dictionary>(),
+ };
+
+ DATFromDir dfd = new DATFromDir(inputs, datdata, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, tempDir, _logger);
+ bool success = dfd.Start();
+
+ // If we failed, show the help
+ if (!success)
+ {
+ Console.WriteLine();
+ Build.Help();
+ }
+ }
+
+ ///
+ /// Wrap creating a DAT file from files or a directory in parallel
+ ///
+ /// List of input filenames
+ /// New filename
+ /// New name
+ /// New description
+ /// New category
+ /// New version
+ /// New author
+ /// True to set forcepacking="unzip" on the created file, false otherwise
+ /// OutputFormat to be used for outputting the DAT
+ /// True to enable reading a directory like a Romba depot, false otherwise
+ /// True to enable SuperDAT-style reading, false otherwise
+ /// True to disable getting MD5 hash, false otherwise
+ /// True to disable getting SHA-1 hash, false otherwise
+ /// True if the date should be omitted from the DAT, false otherwise
+ /// True if archives should be treated as files, false otherwise
+ /// True if GZIP archives should be treated as files, false otherwise
+ /// Name of the directory to create a temp folder in (blank is current directory
+ /// Integer representing the maximum amount of parallelization to be used
+ private static void InitDatFromDirParallel(List inputs,
+ string filename,
+ string name,
+ string description,
+ string category,
+ string version,
+ string author,
+ bool forceunpack,
+ OutputFormat outputFormat,
+ bool romba,
+ bool superdat,
+ bool noMD5,
+ bool noSHA1,
+ bool bare,
+ bool archivesAsFiles,
+ bool enableGzip,
+ string tempDir,
+ int maxDegreeOfParallelism)
+ {
+ // Create a new DATFromDir object and process the inputs
+ Dat basedat = new Dat
+ {
+ FileName = filename,
+ Name = name,
+ Description = description,
+ Category = category,
+ Version = version,
+ Date = DateTime.Now.ToString("yyyy-MM-dd"),
+ Author = author,
+ ForcePacking = (forceunpack ? ForcePacking.Unzip : ForcePacking.None),
+ OutputFormat = outputFormat,
+ Romba = romba,
+ Type = (superdat ? "SuperDAT" : ""),
+ };
+
+ // For each input directory, create a DAT
+ foreach (string path in inputs)
+ {
+ if (Directory.Exists(path))
+ {
+ // Clone the base Dat for information
+ Dat datdata = (Dat)basedat.Clone();
+ datdata.Files = new Dictionary>();
+
+ string basePath = Path.GetFullPath(path);
+ DATFromDirParallel dfd = new DATFromDirParallel(basePath, datdata, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, tempDir, maxDegreeOfParallelism, _logger);
+ bool success = dfd.Start();
+
+ // If it was a success, write the DAT out
+ if (success)
+ {
+ DatTools.WriteDatfile(dfd.DatData, "", _logger);
+ }
+
+ // Otherwise, show the help
+ else
+ {
+ Console.WriteLine();
+ Build.Help();
+ }
+ }
+ }
+ }
+
+ ///
+ /// Wrap splitting a DAT by 2 extensions
+ ///
+ /// Input files or folders to be split
+ /// First extension to split on
+ /// Second extension to split on
+ /// Output directory for the split files
+ private static void InitExtSplit(List inputs, string exta, string extb, string outdir)
+ {
+ // Convert comma-separated strings to list
+ List extaList = exta.Split(',').ToList();
+ List extbList = extb.Split(',').ToList();
+
+ // Loop over the input files
+ foreach (string input in inputs)
+ {
+ if (File.Exists(input))
+ {
+ DatTools.SplitByExt(Path.GetFullPath(input), outdir, Path.GetDirectoryName(input), extaList, extbList, _logger);
+ }
+ else if (Directory.Exists(input))
+ {
+ foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
+ {
+ DatTools.SplitByExt(file, outdir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), extaList, extbList, _logger);
+ }
+ }
+ else
+ {
+ _logger.Error(input + " is not a valid file or folder!");
+ Console.WriteLine();
+ Build.Help();
+ return;
+ }
+ }
}
///
@@ -71,6 +283,169 @@ namespace SabreTools
}
}
+ ///
+ /// Wrap splitting a DAT by best available hashes
+ ///
+ /// List of inputs to be used
+ /// Output directory for the split files
+ private static void InitHashSplit(List inputs, string outdir)
+ {
+ // Loop over the input files
+ foreach (string input in inputs)
+ {
+ if (File.Exists(input))
+ {
+ DatTools.SplitByHash(Path.GetFullPath(input), outdir, Path.GetDirectoryName(input), _logger);
+ }
+ else if (Directory.Exists(input))
+ {
+ foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
+ {
+ DatTools.SplitByHash(file, outdir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), _logger);
+ }
+ }
+ else
+ {
+ _logger.Error(input + " is not a valid file or folder!");
+ Console.WriteLine();
+ Build.Help();
+ return;
+ }
+ }
+ }
+
+ ///
+ /// Wrap extracting and replacing headers
+ ///
+ /// Input file or folder name
+ /// True if we're extracting headers (default), false if we're replacing them
+ /// Logger object for file and console output
+ private static void InitHeaderer(string input, bool extract, Logger logger)
+ {
+ Headerer headerer = new Headerer(input, extract, logger);
+ headerer.Process();
+ }
+
+ ///
+ /// Wrap importing and updating DATs
+ ///
+ ///
+ private static void InitImport(bool ignore)
+ {
+ IImport imp = new ImportTwo(_datroot, _databaseConnectionString, _logger, ignore);
+ imp.UpdateDatabase();
+ }
+
+ ///
+ /// Wrap removing an existing source from the database
+ ///
+ /// Source ID to be removed from the database
+ private static void InitRemoveSource(string sourceid)
+ {
+ int srcid = -1;
+ if (Int32.TryParse(sourceid, out srcid))
+ {
+ if (DBTools.RemoveSource(srcid, _databaseConnectionString))
+ {
+ _logger.Log("Source '" + srcid + "' removed!");
+ }
+ else
+ {
+ _logger.Error("Source with id '" + srcid + "' could not be removed.");
+ }
+ }
+ else
+ {
+ _logger.Error("Invalid input");
+ }
+ }
+
+ ///
+ /// Wrap removing an existing system from the database
+ ///
+ /// System ID to be removed from the database
+ private static void InitRemoveSystem(string systemid)
+ {
+ int sysid = -1;
+ if (Int32.TryParse(systemid, out sysid))
+ {
+ if (DBTools.RemoveSystem(sysid, _databaseConnectionString))
+ {
+ _logger.Log("System '" + sysid + "' removed!");
+ }
+ else
+ {
+ _logger.Error("System with id '" + sysid + "' could not be removed.");
+ }
+ }
+ else
+ {
+ _logger.Error("Invalid input");
+ }
+ }
+
+ ///
+ /// Wrap getting statistics on a DAT or folder of DATs
+ ///
+ /// List of inputs to be used
+ /// True to show individual DAT statistics, false otherwise
+ private static void InitStats(List inputs, bool single)
+ {
+ List newinputs = new List();
+
+ foreach (string input in inputs)
+ {
+ if (File.Exists(input))
+ {
+ newinputs.Add(input);
+ }
+ if (Directory.Exists(input))
+ {
+ foreach (string file in Directory.GetFiles(input, "*", SearchOption.AllDirectories))
+ {
+ newinputs.Add(file);
+ }
+ }
+ }
+
+ Logger statlog = new Logger(true, "stats.txt");
+ statlog.Start();
+ Stats stats = new Stats(newinputs, single, statlog);
+ stats.Process();
+ statlog.Close(true);
+ }
+
+ ///
+ /// Wrap splitting a DAT by item type
+ ///
+ /// List of inputs to be used
+ /// Output directory for the split files
+ private static void InitTypeSplit(List inputs, string outdir)
+ {
+ // Loop over the input files
+ foreach (string input in inputs)
+ {
+ if (File.Exists(input))
+ {
+ DatTools.SplitByType(Path.GetFullPath(input), outdir, Path.GetDirectoryName(input), _logger);
+ }
+ else if (Directory.Exists(input))
+ {
+ foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
+ {
+ DatTools.SplitByType(file, outdir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), _logger);
+ }
+ }
+ else
+ {
+ _logger.Error(input + " is not a valid file or folder!");
+ Console.WriteLine();
+ Build.Help();
+ return;
+ }
+ }
+ }
+
///
/// Wrap converting and updating DAT file from any format to any format
///
@@ -323,369 +698,6 @@ namespace SabreTools
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, maxDegreeOfParallelism, _logger);
}
- ///
- /// Wrap creating a DAT file from files or a directory
- ///
- /// List of innput filenames
- /// New filename
- /// New name
- /// New description
- /// New category
- /// New version
- /// New author
- /// True to set forcepacking="unzip" on the created file, false otherwise
- /// OutputFormat to be used for outputting the DAT
- /// True to enable reading a directory like a Romba depot, false otherwise
- /// True to enable SuperDAT-style reading, false otherwise
- /// True to disable getting MD5 hash, false otherwise
- /// True to disable getting SHA-1 hash, false otherwise
- /// True if the date should be omitted from the DAT, false otherwise
- /// True if archives should be treated as files, false otherwise
- /// True if GZIP archives should be treated as files, false otherwise
- /// Name of the directory to create a temp folder in (blank is current directory
- private static void InitDatFromDir(List inputs,
- string filename,
- string name,
- string description,
- string category,
- string version,
- string author,
- bool forceunpack,
- OutputFormat outputFormat,
- bool romba,
- bool superdat,
- bool noMD5,
- bool noSHA1,
- bool bare,
- bool archivesAsFiles,
- bool enableGzip,
- string tempDir)
- {
- // Create a new DATFromDir object and process the inputs
- Dat datdata = new Dat
- {
- FileName = filename,
- Name = name,
- Description = description,
- Category = category,
- Version = version,
- Date = DateTime.Now.ToString("yyyy-MM-dd"),
- Author = author,
- ForcePacking = (forceunpack ? ForcePacking.Unzip : ForcePacking.None),
- OutputFormat = outputFormat,
- Romba = romba,
- Type = (superdat ? "SuperDAT" : ""),
- Files = new Dictionary>(),
- };
-
- DATFromDir dfd = new DATFromDir(inputs, datdata, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, tempDir, _logger);
- bool success = dfd.Start();
-
- // If we failed, show the help
- if (!success)
- {
- Console.WriteLine();
- Build.Help();
- }
- }
-
- ///
- /// Wrap creating a DAT file from files or a directory in parallel
- ///
- /// List of input filenames
- /// New filename
- /// New name
- /// New description
- /// New category
- /// New version
- /// New author
- /// True to set forcepacking="unzip" on the created file, false otherwise
- /// OutputFormat to be used for outputting the DAT
- /// True to enable reading a directory like a Romba depot, false otherwise
- /// True to enable SuperDAT-style reading, false otherwise
- /// True to disable getting MD5 hash, false otherwise
- /// True to disable getting SHA-1 hash, false otherwise
- /// True if the date should be omitted from the DAT, false otherwise
- /// True if archives should be treated as files, false otherwise
- /// True if GZIP archives should be treated as files, false otherwise
- /// Name of the directory to create a temp folder in (blank is current directory
- /// Integer representing the maximum amount of parallelization to be used
- private static void InitDatFromDirParallel(List inputs,
- string filename,
- string name,
- string description,
- string category,
- string version,
- string author,
- bool forceunpack,
- OutputFormat outputFormat,
- bool romba,
- bool superdat,
- bool noMD5,
- bool noSHA1,
- bool bare,
- bool archivesAsFiles,
- bool enableGzip,
- string tempDir,
- int maxDegreeOfParallelism)
- {
- // Create a new DATFromDir object and process the inputs
- Dat basedat = new Dat
- {
- FileName = filename,
- Name = name,
- Description = description,
- Category = category,
- Version = version,
- Date = DateTime.Now.ToString("yyyy-MM-dd"),
- Author = author,
- ForcePacking = (forceunpack ? ForcePacking.Unzip : ForcePacking.None),
- OutputFormat = outputFormat,
- Romba = romba,
- Type = (superdat ? "SuperDAT" : ""),
- };
-
- // For each input directory, create a DAT
- foreach (string path in inputs)
- {
- if (Directory.Exists(path))
- {
- // Clone the base Dat for information
- Dat datdata = (Dat)basedat.Clone();
- datdata.Files = new Dictionary>();
-
- string basePath = Path.GetFullPath(path);
- DATFromDirParallel dfd = new DATFromDirParallel(basePath, datdata, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, tempDir, maxDegreeOfParallelism, _logger);
- bool success = dfd.Start();
-
- // If it was a success, write the DAT out
- if (success)
- {
- DatTools.WriteDatfile(dfd.DatData, "", _logger);
- }
-
- // Otherwise, show the help
- else
- {
- Console.WriteLine();
- Build.Help();
- }
- }
- }
- }
-
- ///
- /// Wrap splitting a DAT by 2 extensions
- ///
- /// Input files or folders to be split
- /// First extension to split on
- /// Second extension to split on
- /// Output directory for the split files
- private static void InitExtSplit(List inputs, string exta, string extb, string outdir)
- {
- // Convert comma-separated strings to list
- List extaList = exta.Split(',').ToList();
- List extbList = extb.Split(',').ToList();
-
- // Loop over the input files
- foreach (string input in inputs)
- {
- if (File.Exists(input))
- {
- DatTools.SplitByExt(Path.GetFullPath(input), outdir, Path.GetDirectoryName(input), extaList, extbList, _logger);
- }
- else if (Directory.Exists(input))
- {
- foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
- {
- DatTools.SplitByExt(file, outdir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), extaList, extbList, _logger);
- }
- }
- else
- {
- _logger.Error(input + " is not a valid file or folder!");
- Console.WriteLine();
- Build.Help();
- return;
- }
- }
- }
-
- ///
- /// Wrap splitting a DAT by best available hashes
- ///
- /// List of inputs to be used
- /// Output directory for the split files
- private static void InitHashSplit(List inputs, string outdir)
- {
- // Loop over the input files
- foreach (string input in inputs)
- {
- if (File.Exists(input))
- {
- DatTools.SplitByHash(Path.GetFullPath(input), outdir, Path.GetDirectoryName(input), _logger);
- }
- else if (Directory.Exists(input))
- {
- foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
- {
- DatTools.SplitByHash(file, outdir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), _logger);
- }
- }
- else
- {
- _logger.Error(input + " is not a valid file or folder!");
- Console.WriteLine();
- Build.Help();
- return;
- }
- }
- }
-
- ///
- /// Wrap splitting a DAT by item type
- ///
- /// List of inputs to be used
- /// Output directory for the split files
- private static void InitTypeSplit(List inputs, string outdir)
- {
- // Loop over the input files
- foreach (string input in inputs)
- {
- if (File.Exists(input))
- {
- DatTools.SplitByType(Path.GetFullPath(input), outdir, Path.GetDirectoryName(input), _logger);
- }
- else if (Directory.Exists(input))
- {
- foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
- {
- DatTools.SplitByType(file, outdir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), _logger);
- }
- }
- else
- {
- _logger.Error(input + " is not a valid file or folder!");
- Console.WriteLine();
- Build.Help();
- return;
- }
- }
- }
-
- ///
- /// Wrap getting statistics on a DAT or folder of DATs
- ///
- /// List of inputs to be used
- /// True to show individual DAT statistics, false otherwise
- private static void InitStats(List inputs, bool single)
- {
- List newinputs = new List();
-
- foreach (string input in inputs)
- {
- if (File.Exists(input))
- {
- newinputs.Add(input);
- }
- if (Directory.Exists(input))
- {
- foreach (string file in Directory.GetFiles(input, "*", SearchOption.AllDirectories))
- {
- newinputs.Add(file);
- }
- }
- }
-
- Logger statlog = new Logger(true, "stats.txt");
- statlog.Start();
- Stats stats = new Stats(newinputs, single, statlog);
- stats.Process();
- statlog.Close(true);
- }
-
- ///
- /// Wrap adding a new source to the database
- ///
- /// Source name
- /// Source URL(s)
- private static void InitAddSource(string name, string url)
- {
- if (DBTools.AddSource(name, url, _databaseConnectionString))
- {
- _logger.Log("Source " + name + " added!");
- }
- else
- {
- _logger.Error("Source " + name + " could not be added!");
- }
- }
-
- ///
- /// Wrap removing an existing source from the database
- ///
- /// Source ID to be removed from the database
- private static void InitRemoveSource(string sourceid)
- {
- int srcid = -1;
- if (Int32.TryParse(sourceid, out srcid))
- {
- if (DBTools.RemoveSource(srcid, _databaseConnectionString))
- {
- _logger.Log("Source '" + srcid + "' removed!");
- }
- else
- {
- _logger.Error("Source with id '" + srcid + "' could not be removed.");
- }
- }
- else
- {
- _logger.Error("Invalid input");
- }
- }
-
- ///
- /// Wrap adding a new system to the database
- ///
- /// Manufacturer name
- /// System name
- private static void InitAddSystem(string manufacturer, string system)
- {
- if (DBTools.AddSystem(manufacturer, system, _databaseConnectionString))
- {
- _logger.Log("System " + manufacturer + " - " + system + " added!");
- }
- else
- {
- _logger.Error("System " + manufacturer + " - " + system + " could not be added!");
- }
- }
-
- ///
- /// Wrap removing an existing system from the database
- ///
- /// System ID to be removed from the database
- private static void InitRemoveSystem(string systemid)
- {
- int sysid = -1;
- if (Int32.TryParse(systemid, out sysid))
- {
- if (DBTools.RemoveSystem(sysid, _databaseConnectionString))
- {
- _logger.Log("System '" + sysid + "' removed!");
- }
- else
- {
- _logger.Error("System with id '" + sysid + "' could not be removed.");
- }
- }
- else
- {
- _logger.Error("Invalid input");
- }
- }
-
#endregion
}
}