mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] Modularize and rename code
This commit is contained in:
@@ -402,7 +402,7 @@ namespace SabreTools
|
|||||||
|
|
||||||
// First get a list of SHA-1's from the input DATs
|
// First get a list of SHA-1's from the input DATs
|
||||||
DatFile datroot = new DatFile { Type = "SuperDAT", };
|
DatFile datroot = new DatFile { Type = "SuperDAT", };
|
||||||
datroot.PopulateDatFromDir(_dats, false, false, false, false, false, false, false, _tmpdir, false, null, 4, _logger);
|
datroot.PopulateFromDir(_dats, false, false, false, false, false, false, false, _tmpdir, false, null, 4, _logger);
|
||||||
datroot.BucketBySHA1(false, _logger, false);
|
datroot.BucketBySHA1(false, _logger, false);
|
||||||
|
|
||||||
// Create a List of dat hashes in the database (SHA-1)
|
// Create a List of dat hashes in the database (SHA-1)
|
||||||
@@ -616,7 +616,7 @@ namespace SabreTools
|
|||||||
|
|
||||||
// Now rescan the depot itself
|
// Now rescan the depot itself
|
||||||
DatFile depot = new DatFile();
|
DatFile depot = new DatFile();
|
||||||
depot.PopulateDatFromDir(depotname, false, false, false, false, true, false, false, _tmpdir, false, null, _workers, _logger);
|
depot.PopulateFromDir(depotname, false, false, false, false, true, false, false, _tmpdir, false, null, _workers, _logger);
|
||||||
depot.BucketBySHA1(false, _logger, false);
|
depot.BucketBySHA1(false, _logger, false);
|
||||||
|
|
||||||
// Set the base queries to use
|
// Set the base queries to use
|
||||||
|
|||||||
@@ -41,12 +41,12 @@ namespace SabreTools
|
|||||||
DatFile df = new DatFile();
|
DatFile df = new DatFile();
|
||||||
foreach (string dir in onlyDirs)
|
foreach (string dir in onlyDirs)
|
||||||
{
|
{
|
||||||
df.PopulateDatFromDir(dir, false, false, false, false, true, false, false, _tmpdir, false, null, _workers, _logger);
|
df.PopulateFromDir(dir, false, false, false, false, true, false, false, _tmpdir, false, null, _workers, _logger);
|
||||||
|
|
||||||
// If we're looking for only needed, consider the zipfiles themselves too
|
// If we're looking for only needed, consider the zipfiles themselves too
|
||||||
if (onlyNeeded)
|
if (onlyNeeded)
|
||||||
{
|
{
|
||||||
df.PopulateDatFromDir(dir, false, false, false, true, true, false, false, _tmpdir, false, null, _workers, _logger);
|
df.PopulateFromDir(dir, false, false, false, true, true, false, false, _tmpdir, false, null, _workers, _logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,7 +266,7 @@ namespace SabreTools
|
|||||||
Logger logger = new Logger();
|
Logger logger = new Logger();
|
||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
datdata.PopulateDatFromDir(input, false /* noMD5 */, false /* noSHA1 */, true /* bare */, false /* archivesAsFiles */,
|
datdata.PopulateFromDir(input, false /* noMD5 */, false /* noSHA1 */, true /* bare */, false /* archivesAsFiles */,
|
||||||
true /* enableGzip */, false /* addBlanks */, false /* addDate */, _tmpdir /* tempDir */, false /* copyFiles */,
|
true /* enableGzip */, false /* addBlanks */, false /* addDate */, _tmpdir /* tempDir */, false /* copyFiles */,
|
||||||
null /* headerToCheckAgainst */, _workers /* maxDegreeOfParallelism */, _logger);
|
null /* headerToCheckAgainst */, _workers /* maxDegreeOfParallelism */, _logger);
|
||||||
datdata.WriteToFile("", logger);
|
datdata.WriteToFile("", logger);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Schema;
|
using System.Xml.Schema;
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ using BinaryWriter = System.IO.BinaryWriter;
|
|||||||
using FileStream = System.IO.FileStream;
|
using FileStream = System.IO.FileStream;
|
||||||
using IOException = System.IO.IOException;
|
using IOException = System.IO.IOException;
|
||||||
using MemoryStream = System.IO.MemoryStream;
|
using MemoryStream = System.IO.MemoryStream;
|
||||||
|
using PathTooLongException = System.IO.PathTooLongException;
|
||||||
using SearchOption = System.IO.SearchOption;
|
using SearchOption = System.IO.SearchOption;
|
||||||
using SeekOrigin = System.IO.SeekOrigin;
|
using SeekOrigin = System.IO.SeekOrigin;
|
||||||
using Stream = System.IO.Stream;
|
using Stream = System.IO.Stream;
|
||||||
@@ -79,7 +81,7 @@ namespace SabreTools.Helper.Tools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read the input file, if possible
|
// Read the input file, if possible
|
||||||
logger.Verbose("Attempting to read file: \"" + filename + "\"");
|
logger.Verbose("Attempting to read file to get format: \"" + filename + "\"");
|
||||||
|
|
||||||
// Check if file exists
|
// Check if file exists
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
@@ -446,6 +448,66 @@ namespace SabreTools.Helper.Tools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve a list of just files from inputs
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="inputs">List of strings representing directories and files</param>
|
||||||
|
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
|
||||||
|
/// <param name="logger">Logger object for file and console output</param>
|
||||||
|
/// <param name="appendparent">True if the parent name should be appended after the special character "¬", false otherwise</param>
|
||||||
|
/// <returns>List of strings representing just files from the inputs</returns>
|
||||||
|
public static List<string> GetOnlyFilesFromInputs(List<string> inputs, int maxDegreeOfParallelism, Logger logger, bool appendparent = false)
|
||||||
|
{
|
||||||
|
List<string> outputs = new List<string>();
|
||||||
|
Parallel.ForEach(inputs,
|
||||||
|
new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism, },
|
||||||
|
input =>
|
||||||
|
{
|
||||||
|
if (Directory.Exists(input))
|
||||||
|
{
|
||||||
|
List<string> files = FileTools.RetrieveFiles(input, new List<string>());
|
||||||
|
foreach (string file in files)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
lock (outputs)
|
||||||
|
{
|
||||||
|
outputs.Add(Path.GetFullPath(file) + (appendparent ? "¬" + Path.GetFullPath(input) : ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (PathTooLongException)
|
||||||
|
{
|
||||||
|
logger.Warning("The path for " + file + " was too long");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.Error(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (File.Exists(input))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
lock (outputs)
|
||||||
|
{
|
||||||
|
outputs.Add(Path.GetFullPath(input) + (appendparent ? "¬" + Path.GetFullPath(input) : ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (PathTooLongException)
|
||||||
|
{
|
||||||
|
logger.Warning("The path for " + input + " was too long");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.Error(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return outputs;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Stream Information
|
#region Stream Information
|
||||||
|
|||||||
@@ -396,6 +396,31 @@ namespace SabreTools.Helper.Tools
|
|||||||
.ToArray());
|
.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Split a line as if it were a CMP rom line
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="s">Line to split</param>
|
||||||
|
/// <returns>Line split</returns>
|
||||||
|
/// <remarks>Uses code from http://stackoverflow.com/questions/554013/regular-expression-to-split-on-spaces-unless-in-quotes</remarks>
|
||||||
|
public static string[] SplitLineAsCMP(string s)
|
||||||
|
{
|
||||||
|
// Preprocess the string
|
||||||
|
s = Regex.Replace(s, @"^\S* \(", ""); // Remove item identifier and opening brace
|
||||||
|
s = Regex.Replace(s, @"#.*$", ""); // Remove trailing comments
|
||||||
|
s = s.TrimEnd(')'); // Remove closing brace
|
||||||
|
s = s.Trim(); // Remove leading and trailing whitespace
|
||||||
|
|
||||||
|
// Now we get each string, divided up as cleanly as possible
|
||||||
|
string[] matches = Regex
|
||||||
|
//.Matches(s, @"([^\s]*""[^""]+""[^\s]*)|[^""]?\w+[^""]?")
|
||||||
|
.Matches(s, @"[^\s""]+|""[^""]*""")
|
||||||
|
.Cast<Match>()
|
||||||
|
.Select(m => m.Groups[0].Value)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region System.IO.Path Replacements
|
#region System.IO.Path Replacements
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ namespace SabreTools
|
|||||||
datdata.Files = new SortedDictionary<string, List<DatItem>>();
|
datdata.Files = new SortedDictionary<string, List<DatItem>>();
|
||||||
|
|
||||||
string basePath = Path.GetFullPath(path);
|
string basePath = Path.GetFullPath(path);
|
||||||
bool success = datdata.PopulateDatFromDir(basePath, noMD5, noSHA1, removeDateFromAutomaticName, parseArchivesAsFiles, enableGzip,
|
bool success = datdata.PopulateFromDir(basePath, noMD5, noSHA1, removeDateFromAutomaticName, parseArchivesAsFiles, enableGzip,
|
||||||
addBlankFilesForEmptyFolder, addFileDates, tempDir, copyFiles, headerToCheckAgainst, maxDegreeOfParallelism, _logger);
|
addBlankFilesForEmptyFolder, addFileDates, tempDir, copyFiles, headerToCheckAgainst, maxDegreeOfParallelism, _logger);
|
||||||
|
|
||||||
// If it was a success, write the DAT out
|
// If it was a success, write the DAT out
|
||||||
|
|||||||
Reference in New Issue
Block a user