mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[ALL] Rename and move some things around
This commit is contained in:
@@ -336,7 +336,7 @@ namespace SabreTools
|
||||
// Loop through the datroot and add only needed files
|
||||
foreach (string file in Directory.EnumerateFiles(_dats, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
Rom dat = FileTools.GetSingleFileInfo(file, _logger);
|
||||
Rom dat = FileTools.GetFileInfo(file, _logger);
|
||||
|
||||
// If the Dat isn't in the database and isn't already accounted for in the DatRoot, add it
|
||||
if (!databaseDats.Contains(dat.SHA1) && !toscan.ContainsKey(dat.SHA1))
|
||||
@@ -437,7 +437,7 @@ namespace SabreTools
|
||||
if (datRootDats.Contains(input.ToLowerInvariant()))
|
||||
{
|
||||
string fullpath = Path.GetFullPath(datRootDats[datRootDats.IndexOf(input.ToLowerInvariant())]);
|
||||
string sha1 = FileTools.GetSingleFileInfo(fullpath, _logger).SHA1;
|
||||
string sha1 = FileTools.GetFileInfo(fullpath, _logger).SHA1;
|
||||
foundDats.Add(sha1, fullpath);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -4564,11 +4564,11 @@ namespace SabreTools.Helper
|
||||
/// <param name="addDate">True if dates should be archived for all files, false otherwise</param>
|
||||
/// <param name="tempDir">Name of the directory to create a temp folder in (blank is current directory)</param>
|
||||
/// <param name="copyFiles">True if files should be copied to the temp directory before hashing, false otherwise</param>
|
||||
/// <param name="removeHeader">True if headers should be removed from files if possible, false otherwise</param>
|
||||
/// <param name="tryRemoveHeader">True if headers should be removed from files if possible, false otherwise</param>
|
||||
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
public bool PopulateDatFromDir(string basePath, bool noMD5, bool noSHA1, bool bare, bool archivesAsFiles,
|
||||
bool enableGzip, bool addBlanks, bool addDate, string tempDir, bool copyFiles, bool removeHeader, int maxDegreeOfParallelism, Logger logger)
|
||||
bool enableGzip, bool addBlanks, bool addDate, string tempDir, bool copyFiles, bool tryRemoveHeader, int maxDegreeOfParallelism, Logger logger)
|
||||
{
|
||||
// If the description is defined but not the name, set the name from the description
|
||||
if (String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Description))
|
||||
@@ -4599,7 +4599,7 @@ namespace SabreTools.Helper
|
||||
item =>
|
||||
{
|
||||
DFDProcessPossibleArchive(item, basePath, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
|
||||
tempDir, copyFiles, removeHeader, maxDegreeOfParallelism, logger);
|
||||
tempDir, copyFiles, tryRemoveHeader, maxDegreeOfParallelism, logger);
|
||||
});
|
||||
|
||||
// Now find all folders that are empty, if we are supposed to
|
||||
@@ -4688,11 +4688,11 @@ namespace SabreTools.Helper
|
||||
/// <param name="addDate">True if dates should be archived for all files, false otherwise</param>
|
||||
/// <param name="tempDir">Name of the directory to create a temp folder in (blank is current directory)</param>
|
||||
/// <param name="copyFiles">True if files should be copied to the temp directory before hashing, false otherwise</param>
|
||||
/// <param name="removeHeader">True if headers should be removed from files if possible, false otherwise</param>
|
||||
/// <param name="tryRemoveHeader">True if headers should be removed from files if possible, false otherwise</param>
|
||||
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
private void DFDProcessPossibleArchive(string item, string basePath, bool noMD5, bool noSHA1, bool bare, bool archivesAsFiles,
|
||||
bool enableGzip, bool addBlanks, bool addDate, string tempDir, bool copyFiles, bool removeHeader, int maxDegreeOfParallelism, Logger logger)
|
||||
bool enableGzip, bool addBlanks, bool addDate, string tempDir, bool copyFiles, bool tryRemoveHeader, int maxDegreeOfParallelism, Logger logger)
|
||||
{
|
||||
// Define the temporary directory
|
||||
string tempSubDir = Path.GetFullPath(Path.Combine(tempDir, Path.GetRandomFileName())) + Path.DirectorySeparatorChar;
|
||||
@@ -4762,7 +4762,7 @@ namespace SabreTools.Helper
|
||||
// Otherwise, just get the info on the file itself
|
||||
else if (File.Exists(newItem))
|
||||
{
|
||||
DFDProcessFile(newItem, "", newBasePath, noMD5, noSHA1, addDate, removeHeader, logger);
|
||||
DFDProcessFile(newItem, "", newBasePath, noMD5, noSHA1, addDate, tryRemoveHeader, logger);
|
||||
}
|
||||
}
|
||||
// Otherwise, attempt to extract the files to the temporary directory
|
||||
@@ -4794,14 +4794,14 @@ namespace SabreTools.Helper
|
||||
noMD5,
|
||||
noSHA1,
|
||||
addDate,
|
||||
removeHeader,
|
||||
tryRemoveHeader,
|
||||
logger);
|
||||
});
|
||||
}
|
||||
// Otherwise, just get the info on the file itself
|
||||
else if (File.Exists(newItem))
|
||||
{
|
||||
DFDProcessFile(newItem, "", newBasePath, noMD5, noSHA1, addDate, removeHeader, logger);
|
||||
DFDProcessFile(newItem, "", newBasePath, noMD5, noSHA1, addDate, tryRemoveHeader, logger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4831,12 +4831,12 @@ namespace SabreTools.Helper
|
||||
/// <param name="noMD5">True if MD5 hashes should be skipped over, false otherwise</param>
|
||||
/// <param name="noSHA1">True if SHA-1 hashes should be skipped over, false otherwise</param>
|
||||
/// <param name="addDate">True if dates should be archived for all files, false otherwise</param>
|
||||
/// <param name="removeHeader">True if headers should be removed from files if possible, false otherwise</param>
|
||||
/// <param name="tryRemoveHeader">True if headers should be removed from files if possible, false otherwise</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
private void DFDProcessFile(string item, string parent, string basePath, bool noMD5, bool noSHA1, bool addDate, bool removeHeader, Logger logger)
|
||||
private void DFDProcessFile(string item, string parent, string basePath, bool noMD5, bool noSHA1, bool addDate, bool tryRemoveHeader, Logger logger)
|
||||
{
|
||||
logger.Verbose(Path.GetFileName(item) + " treated like a file");
|
||||
Rom rom = FileTools.GetSingleFileInfo(item, logger, noMD5: noMD5, noSHA1: noSHA1, date: addDate, removeHeader: removeHeader);
|
||||
Rom rom = FileTools.GetFileInfo(item, logger, noMD5: noMD5, noSHA1: noSHA1, date: addDate, tryRemoveHeader: tryRemoveHeader);
|
||||
|
||||
DFDProcessFileHelper(item, rom, basePath, parent, logger);
|
||||
}
|
||||
|
||||
@@ -460,7 +460,7 @@ namespace SabreTools.Helper
|
||||
/// <returns>True if the file could be added, false otherwise</returns>
|
||||
public bool RebuildToOutputAlternateParseRomHelper(string file, ref DatFile matchdat, Logger logger)
|
||||
{
|
||||
Rom rom = FileTools.GetSingleFileInfo(file, logger);
|
||||
Rom rom = FileTools.GetFileInfo(file, logger);
|
||||
|
||||
// If we have a blank RomData, it's an error
|
||||
if (rom.Name == null)
|
||||
@@ -485,18 +485,18 @@ namespace SabreTools.Helper
|
||||
}
|
||||
|
||||
// Now attempt to see if the file has a header
|
||||
SkipperRule rule = Skippers.MatchesSkipper(file, "", _logger);
|
||||
FileStream input = File.OpenRead(file);
|
||||
SkipperRule rule = Skippers.GetMatchingRule(input, "", _logger);
|
||||
|
||||
// If there's a match, get the new information from the stream
|
||||
if (rule.Tests != null && rule.Tests.Count != 0)
|
||||
{
|
||||
// Create the input and output streams
|
||||
MemoryStream output = new MemoryStream();
|
||||
FileStream input = File.OpenRead(file);
|
||||
|
||||
// Transform the stream and get the information from it
|
||||
Skippers.TransformStream(input, output, rule, _logger, false, true);
|
||||
Rom romNH = FileTools.GetSingleStreamInfo(output, output.Length);
|
||||
Rom romNH = FileTools.GetStreamInfo(output, output.Length);
|
||||
romNH.Name = "HEAD::" + rom.Name;
|
||||
romNH.MachineName = rom.MachineName;
|
||||
|
||||
@@ -513,11 +513,13 @@ namespace SabreTools.Helper
|
||||
matchdat.Files.Add(key, temp);
|
||||
}
|
||||
|
||||
// Dispose of the streams
|
||||
// Dispose of the stream
|
||||
output.Dispose();
|
||||
input.Dispose();
|
||||
}
|
||||
|
||||
// Dispose of the stream
|
||||
input.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -546,7 +548,7 @@ namespace SabreTools.Helper
|
||||
// Hash and match the external files
|
||||
if (shouldExternalScan)
|
||||
{
|
||||
Rom rom = FileTools.GetSingleFileInfo(input, _logger);
|
||||
Rom rom = FileTools.GetFileInfo(input, _logger);
|
||||
|
||||
// If we have a blank RomData, it's an error
|
||||
if (rom.Name == null)
|
||||
@@ -608,7 +610,7 @@ namespace SabreTools.Helper
|
||||
}
|
||||
|
||||
// Now get the transformed file if it exists
|
||||
SkipperRule rule = Skippers.MatchesSkipper(input, "", _logger);
|
||||
SkipperRule rule = Skippers.GetMatchingRule(input, "", _logger);
|
||||
|
||||
// If we have have a non-empty rule, apply it
|
||||
if (rule.Tests != null && rule.Tests.Count != 0)
|
||||
@@ -616,7 +618,7 @@ namespace SabreTools.Helper
|
||||
// Otherwise, apply the rule to the file
|
||||
string newinput = input + ".new";
|
||||
Skippers.TransformFile(input, newinput, rule, _logger);
|
||||
Rom drom = FileTools.GetSingleFileInfo(newinput, _logger);
|
||||
Rom drom = FileTools.GetFileInfo(newinput, _logger);
|
||||
|
||||
// If we have a blank RomData, it's an error
|
||||
if (drom.Name == null)
|
||||
@@ -914,7 +916,7 @@ namespace SabreTools.Helper
|
||||
ArchiveTools.ExtractArchive(Path.GetFullPath(archive), temparcdir, _logger);
|
||||
foreach (string tempfile in Directory.EnumerateFiles(temparcdir, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
roms.Add(FileTools.GetSingleFileInfo(Path.GetFullPath(tempfile), _logger));
|
||||
roms.Add(FileTools.GetFileInfo(Path.GetFullPath(tempfile), _logger));
|
||||
}
|
||||
|
||||
// Clear the temporary archive directory
|
||||
|
||||
@@ -298,7 +298,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="skipperName">Name of the skipper to be used</param>
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
/// <returns>The SkipperRule that matched the file</returns>
|
||||
public static SkipperRule MatchesSkipper(string input, string skipperName, Logger logger)
|
||||
public static SkipperRule GetMatchingRule(string input, string skipperName, Logger logger)
|
||||
{
|
||||
// If the file doesn't exist, return a blank skipper rule
|
||||
if (!File.Exists(input))
|
||||
@@ -307,7 +307,7 @@ namespace SabreTools.Helper
|
||||
return new SkipperRule();
|
||||
}
|
||||
|
||||
return MatchesSkipper(File.OpenRead(input), skipperName, logger);
|
||||
return GetMatchingRule(File.OpenRead(input), skipperName, logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -318,7 +318,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
/// <param name="keepOpen">True if the underlying stream should be kept open, false otherwise</param>
|
||||
/// <returns>The SkipperRule that matched the file</returns>
|
||||
public static SkipperRule MatchesSkipper(Stream input, string skipperName, Logger logger, bool keepOpen = false)
|
||||
public static SkipperRule GetMatchingRule(Stream input, string skipperName, Logger logger, bool keepOpen = false)
|
||||
{
|
||||
SkipperRule skipperRule = new SkipperRule();
|
||||
|
||||
|
||||
@@ -965,7 +965,7 @@ namespace SabreTools.Helper
|
||||
outDir = Path.GetFullPath(outDir);
|
||||
|
||||
// Now get the Rom info for the file so we have hashes and size
|
||||
Rom rom = FileTools.GetSingleFileInfo(input, logger);
|
||||
Rom rom = FileTools.GetFileInfo(input, logger);
|
||||
|
||||
// If it doesn't exist, create the output file and then write
|
||||
string outfile = Path.Combine(outDir, rom.SHA1 + ".gz");
|
||||
|
||||
@@ -156,9 +156,9 @@ namespace SabreTools.Helper
|
||||
/// <param name="noSHA1">True if SHA-1 hashes should not be calcluated, false otherwise (default)</param>
|
||||
/// <param name="offset">Set a >0 number for getting hash for part of the file, 0 otherwise (default)</param>
|
||||
/// <param name="date">True if the file Date should be included, false otherwise (default)</param>
|
||||
/// <param name="removeHeader">True if headers should be removed from files if possible, false otherwise (default)</param>
|
||||
/// <param name="tryRemoveHeader">True if headers should be removed from files if possible, false otherwise (default)</param>
|
||||
/// <returns>Populated RomData object if success, empty one on error</returns>
|
||||
public static Rom GetSingleFileInfo(string input, Logger logger, bool noMD5 = false, bool noSHA1 = false, long offset = 0, bool date = false, bool removeHeader = false)
|
||||
public static Rom GetFileInfo(string input, Logger logger, bool noMD5 = false, bool noSHA1 = false, long offset = 0, bool date = false, bool tryRemoveHeader = false)
|
||||
{
|
||||
// Add safeguard if file doesn't exist
|
||||
if (!File.Exists(input))
|
||||
@@ -168,9 +168,9 @@ namespace SabreTools.Helper
|
||||
|
||||
// Get the information from the file stream
|
||||
Rom rom = new Rom();
|
||||
if (removeHeader)
|
||||
if (tryRemoveHeader)
|
||||
{
|
||||
SkipperRule rule = Skippers.MatchesSkipper(input, "", logger);
|
||||
SkipperRule rule = Skippers.GetMatchingRule(input, "", logger);
|
||||
|
||||
// If there's a match, get the new information from the stream
|
||||
if (rule.Tests != null && rule.Tests.Count != 0)
|
||||
@@ -180,8 +180,8 @@ namespace SabreTools.Helper
|
||||
FileStream inputStream = File.OpenRead(input);
|
||||
|
||||
// Transform the stream and get the information from it
|
||||
Skippers.TransformStream(inputStream, outputStream, rule, logger, false, true);
|
||||
rom = GetSingleStreamInfo(outputStream, outputStream.Length);
|
||||
Skippers.TransformStream(inputStream, outputStream, rule, logger, keepReadOpen: false, keepWriteOpen: true);
|
||||
rom = GetStreamInfo(outputStream, outputStream.Length);
|
||||
|
||||
// Dispose of the streams
|
||||
outputStream.Dispose();
|
||||
@@ -190,12 +190,12 @@ namespace SabreTools.Helper
|
||||
// Otherwise, just get the info
|
||||
else
|
||||
{
|
||||
rom = GetSingleStreamInfo(File.OpenRead(input), new FileInfo(input).Length, noMD5, noSHA1, offset, false);
|
||||
rom = GetStreamInfo(File.OpenRead(input), new FileInfo(input).Length, noMD5, noSHA1, offset, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rom = GetSingleStreamInfo(File.OpenRead(input), new FileInfo(input).Length, noMD5, noSHA1, offset, false);
|
||||
rom = GetStreamInfo(File.OpenRead(input), new FileInfo(input).Length, noMD5, noSHA1, offset, false);
|
||||
}
|
||||
|
||||
// Add unique data from the file
|
||||
@@ -328,7 +328,7 @@ namespace SabreTools.Helper
|
||||
logger.User("\nGetting skipper information for '" + file + "'");
|
||||
|
||||
// Get the skipper rule that matches the file, if any
|
||||
SkipperRule rule = Skippers.MatchesSkipper(file, "", logger);
|
||||
SkipperRule rule = Skippers.GetMatchingRule(file, "", logger);
|
||||
|
||||
// If we have an empty rule, return false
|
||||
if (rule.Tests == null || rule.Tests.Count == 0 || rule.Operation != HeaderSkipOperation.None)
|
||||
@@ -361,7 +361,7 @@ namespace SabreTools.Helper
|
||||
}
|
||||
|
||||
// Now add the information to the database if it's not already there
|
||||
Rom rom = GetSingleFileInfo(newfile, logger);
|
||||
Rom rom = GetFileInfo(newfile, logger);
|
||||
DatabaseTools.AddHeaderToDatabase(hstr, rom.SHA1, rule.SourceFile, logger);
|
||||
|
||||
return true;
|
||||
@@ -385,7 +385,7 @@ namespace SabreTools.Helper
|
||||
bool success = true;
|
||||
|
||||
// First, get the SHA-1 hash of the file
|
||||
Rom rom = GetSingleFileInfo(file, logger);
|
||||
Rom rom = GetFileInfo(file, logger);
|
||||
|
||||
// Then try to pull the corresponding headers from the database
|
||||
string header = "";
|
||||
@@ -465,7 +465,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="offset">Set a >0 number for getting hash for part of the file, 0 otherwise (default)</param>
|
||||
/// <param name="keepReadOpen">True if the underlying read stream should be kept open, false otherwise</param>
|
||||
/// <returns>Populated RomData object if success, empty one on error</returns>
|
||||
public static Rom GetSingleStreamInfo(Stream input, long size, bool noMD5 = false, bool noSHA1 = false, long offset = 0, bool keepReadOpen = false)
|
||||
public static Rom GetStreamInfo(Stream input, long size, bool noMD5 = false, bool noSHA1 = false, long offset = 0, bool keepReadOpen = false)
|
||||
{
|
||||
Rom rom = new Rom
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user