[DATFromDir, SimpleSort] Add flags for blanks and date

This commit is contained in:
Matt Nadareski
2016-09-14 10:25:01 -07:00
parent e6d901f9b9
commit 87f249bb0c
9 changed files with 57 additions and 26 deletions

View File

@@ -67,7 +67,7 @@ namespace SabreTools
}; };
DATFromDir dfd = new DATFromDir(inputs, datdata, false /* noMD5 */, false /* noSHA1 */, true /* bare */, DATFromDir dfd = new DATFromDir(inputs, datdata, false /* noMD5 */, false /* noSHA1 */, true /* bare */,
false /* archivesAsFiles */, true /* enableGzip */, false /* addblanks */, "__temp__" /* tempdir */, _logger); false /* archivesAsFiles */, true /* enableGzip */, false /* addBlanks */, false /* addDate */, "__temp__" /* tempdir */, _logger);
dfd.Start(); dfd.Start();
} }

View File

@@ -133,6 +133,8 @@ namespace SabreTools.Helper
helptext.Add(" -v=, --version= Set the version of the DAT"); helptext.Add(" -v=, --version= Set the version of the DAT");
helptext.Add(" -au=, --author= Set the author of the DAT"); helptext.Add(" -au=, --author= Set the author of the DAT");
helptext.Add(" -sd, --superdat Enable SuperDAT creation"); helptext.Add(" -sd, --superdat Enable SuperDAT creation");
helptext.Add(" -ab, --add-blank Output blank files for folders");
helptext.Add(" -ad, --add-date Output dates for each file parsed");
helptext.Add(" -t=, --temp= Set the temporary directory to use"); helptext.Add(" -t=, --temp= Set the temporary directory to use");
helptext.Add(" -mt={4} Amount of threads to use (-1 unlimted)"); helptext.Add(" -mt={4} Amount of threads to use (-1 unlimted)");
helptext.Add(" -es, --ext-split Split a DAT by two file extensions"); helptext.Add(" -es, --ext-split Split a DAT by two file extensions");

View File

@@ -25,7 +25,8 @@ namespace SabreTools
private bool _bare; private bool _bare;
private bool _archivesAsFiles; private bool _archivesAsFiles;
private bool _enableGzip; private bool _enableGzip;
private bool _addblanks; private bool _addBlanks;
private bool _addDate;
private bool _nowrite; private bool _nowrite;
// Other required variables // Other required variables
@@ -47,11 +48,13 @@ namespace SabreTools
/// <param name="bare">True if the date should be omitted from the DAT, false otherwise</param> /// <param name="bare">True if the date should be omitted from the DAT, false otherwise</param>
/// <param name="archivesAsFiles">True if archives should be treated as files, false otherwise</param> /// <param name="archivesAsFiles">True if archives should be treated as files, false otherwise</param>
/// <param name="enableGzip">True if GZIP archives should be treated as files, false otherwise</param> /// <param name="enableGzip">True if GZIP archives should be treated as files, false otherwise</param>
/// <param name="addblanks">True if blank items should be created for empty folders, false otherwise</param> /// <param name="addBlanks">True if blank items should be created for empty folders, false otherwise</param>
/// <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="tempDir">Name of the directory to create a temp folder in (blank is current directory)</param>
/// <param name="nowrite">True if the file should not be written out, false otherwise (default)</param> /// <param name="nowrite">True if the file should not be written out, false otherwise (default)</param>
/// <param name="logger">Logger object for console and file output</param> /// <param name="logger">Logger object for console and file output</param>
public DATFromDir(List<String> inputs, Dat datdata, bool noMD5, bool noSHA1, bool bare, bool archivesAsFiles, bool enableGzip, bool addblanks, string tempDir, Logger logger, bool nowrite = false) public DATFromDir(List<String> inputs, Dat datdata, bool noMD5, bool noSHA1, bool bare, bool archivesAsFiles,
bool enableGzip, bool addBlanks, bool addDate, string tempDir, Logger logger, bool nowrite = false)
{ {
_inputs = inputs; _inputs = inputs;
_datdata = datdata; _datdata = datdata;
@@ -62,7 +65,8 @@ namespace SabreTools
_enableGzip = enableGzip; _enableGzip = enableGzip;
_tempDir = tempDir; _tempDir = tempDir;
_logger = logger; _logger = logger;
_addblanks = addblanks; _addBlanks = addBlanks;
_addDate = addDate;
_nowrite = nowrite; _nowrite = nowrite;
} }
@@ -167,7 +171,7 @@ namespace SabreTools
} }
// Now find all folders that are empty, if we are supposed to // Now find all folders that are empty, if we are supposed to
if (!_datdata.Romba && _addblanks) if (!_datdata.Romba && _addBlanks)
{ {
// If there were no subitems, add a "blank" game to to the set (if not in Romba mode) // If there were no subitems, add a "blank" game to to the set (if not in Romba mode)
if (!items) if (!items)
@@ -257,7 +261,7 @@ namespace SabreTools
} }
// Now find all folders that are empty, if we are supposed to // Now find all folders that are empty, if we are supposed to
if (!_datdata.Romba && _addblanks) if (!_datdata.Romba && _addBlanks)
{ {
List<string> keys = _datdata.Files.Keys.ToList(); List<string> keys = _datdata.Files.Keys.ToList();
foreach (string key in keys) foreach (string key in keys)
@@ -465,7 +469,7 @@ namespace SabreTools
private string ProcessFile(string item, StreamWriter sw, string basepath, string parent, Dat datdata, string lastparent) private string ProcessFile(string item, StreamWriter sw, string basepath, string parent, Dat datdata, string lastparent)
{ {
_logger.Log(Path.GetFileName(item) + " treated like a file"); _logger.Log(Path.GetFileName(item) + " treated like a file");
Rom rom = FileTools.GetSingleFileInfo(item, _noMD5, _noSHA1); Rom rom = FileTools.GetSingleFileInfo(item, noMD5: _noMD5, noSHA1: _noSHA1, date: _addDate);
return ProcessFileHelper(item, rom, sw, basepath, parent, datdata, lastparent); return ProcessFileHelper(item, rom, sw, basepath, parent, datdata, lastparent);
} }

View File

@@ -24,7 +24,8 @@ namespace SabreTools
private bool _bare; private bool _bare;
private bool _archivesAsFiles; private bool _archivesAsFiles;
private bool _enableGzip; private bool _enableGzip;
private bool _addblanks; private bool _addBlanks;
private bool _addDate;
private int _maxDegreeOfParallelism; private int _maxDegreeOfParallelism;
// Other required variables // Other required variables
@@ -46,12 +47,13 @@ namespace SabreTools
/// <param name="bare">True if the date should be omitted from the DAT, false otherwise</param> /// <param name="bare">True if the date should be omitted from the DAT, false otherwise</param>
/// <param name="archivesAsFiles">True if archives should be treated as files, false otherwise</param> /// <param name="archivesAsFiles">True if archives should be treated as files, false otherwise</param>
/// <param name="enableGzip">True if GZIP archives should be treated as files, false otherwise</param> /// <param name="enableGzip">True if GZIP archives should be treated as files, false otherwise</param>
/// <param name="addblanks">True if blank items should be created for empty folders, false otherwise</param> /// <param name="addBlanks">True if blank items should be created for empty folders, false otherwise</param>
/// <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="tempDir">Name of the directory to create a temp folder in (blank is current directory)</param>
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</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> /// <param name="logger">Logger object for console and file output</param>
public DATFromDirParallel(string basePath, Dat datdata, bool noMD5, bool noSHA1, bool bare, public DATFromDirParallel(string basePath, Dat datdata, bool noMD5, bool noSHA1, bool bare, bool archivesAsFiles,
bool archivesAsFiles, bool enableGzip, bool addblanks, string tempDir, int maxDegreeOfParallelism, Logger logger) bool enableGzip, bool addBlanks, bool addDate, string tempDir, int maxDegreeOfParallelism, Logger logger)
{ {
_basePath = Path.GetFullPath(basePath); _basePath = Path.GetFullPath(basePath);
_datdata = datdata; _datdata = datdata;
@@ -62,7 +64,8 @@ namespace SabreTools
_bare = bare; _bare = bare;
_archivesAsFiles = archivesAsFiles; _archivesAsFiles = archivesAsFiles;
_enableGzip = enableGzip; _enableGzip = enableGzip;
_addblanks = addblanks; _addBlanks = addBlanks;
_addDate = addDate;
_tempDir = tempDir; _tempDir = tempDir;
_maxDegreeOfParallelism = maxDegreeOfParallelism; _maxDegreeOfParallelism = maxDegreeOfParallelism;
_logger = logger; _logger = logger;
@@ -105,7 +108,7 @@ namespace SabreTools
}); });
// Now find all folders that are empty, if we are supposed to // Now find all folders that are empty, if we are supposed to
if (!_datdata.Romba && _addblanks) if (!_datdata.Romba && _addBlanks)
{ {
Parallel.ForEach(Directory.EnumerateDirectories(_basePath, "*", SearchOption.AllDirectories), Parallel.ForEach(Directory.EnumerateDirectories(_basePath, "*", SearchOption.AllDirectories),
new ParallelOptions { MaxDegreeOfParallelism = _maxDegreeOfParallelism }, new ParallelOptions { MaxDegreeOfParallelism = _maxDegreeOfParallelism },
@@ -297,7 +300,7 @@ namespace SabreTools
private void ProcessFile(string item, string basepath, string parent) private void ProcessFile(string item, string basepath, string parent)
{ {
_logger.Log(Path.GetFileName(item) + " treated like a file"); _logger.Log(Path.GetFileName(item) + " treated like a file");
Rom rom = FileTools.GetSingleFileInfo(item, _noMD5, _noSHA1); Rom rom = FileTools.GetSingleFileInfo(item, noMD5:_noMD5, noSHA1: _noSHA1, date: _addDate);
ProcessFileHelper(item, rom, basepath, parent); ProcessFileHelper(item, rom, basepath, parent);
} }

View File

@@ -133,7 +133,7 @@ namespace SabreTools.Helper
// Then, loop through and check each of the inputs // Then, loop through and check each of the inputs
_logger.User("Processing files:\n"); _logger.User("Processing files:\n");
DATFromDir dfd = new DATFromDir(files, _datdata, false /* noMD5 */, false /* noSHA1 */, false /* bare */, DATFromDir dfd = new DATFromDir(files, _datdata, false /* noMD5 */, false /* noSHA1 */, false /* bare */,
false /* archivesAsFiles */, true /* enableGzip */, false /* addblanks */, "" /* tempdir */, _logger, true /* nowrite */); false /* archivesAsFiles */, true /* enableGzip */, false /* addBlanks */, false /* addDate */, "" /* tempdir */, _logger, true /* nowrite */);
dfd.Start(); dfd.Start();
// Setup the fixdat // Setup the fixdat

View File

@@ -230,6 +230,15 @@ Options:
Set the type flag to "SuperDAT" for the output DAT as well as preserving the Set the type flag to "SuperDAT" for the output DAT as well as preserving the
directory structure of the inputted folder, if applicable directory structure of the inputted folder, if applicable
-ab, --add-blank Output blank files for folders
If this flag is set, then blank entries will be created for each of the empty
directories in the source. This is useful for tools that require all folders
be accounted for in the output DAT.
-ad, --add-date Output dates for each file parsed
If this flag is set, then the Date will be appended to each file information
in the output DAT. The output format is standardized as "yyyy/MM/dd HH:mm:ss".
-t=, --temp= Set the name of the temporary directory -t=, --temp= Set the name of the temporary directory
Optionally, a temp folder can be supplied in the case the default temp directory Optionally, a temp folder can be supplied in the case the default temp directory
(inside the running folder) is not preferred. This is used for any operations (inside the running folder) is not preferred. This is used for any operations

View File

@@ -632,11 +632,13 @@ namespace SabreTools.Helper
/// Retrieve file information for a single file /// Retrieve file information for a single file
/// </summary> /// </summary>
/// <param name="input">Filename to get information from</param> /// <param name="input">Filename to get information from</param>
/// <param name="noMD5">True if MD5 hashes should not be calculated, false otherwise</param> /// <param name="noMD5">True if MD5 hashes should not be calculated, false otherwise (default)</param>
/// <param name="noSHA1">True if SHA-1 hashes should not be calcluated, false otherwise</param> /// <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>
/// <returns>Populated RomData object if success, empty one on error</returns> /// <returns>Populated RomData object if success, empty one on error</returns>
/// <remarks>Add read-offset for hash info</remarks> /// <remarks>Add read-offset for hash info</remarks>
public static Rom GetSingleFileInfo(string input, bool noMD5 = false, bool noSHA1 = false, long offset = 0) public static Rom GetSingleFileInfo(string input, bool noMD5 = false, bool noSHA1 = false, long offset = 0, bool date = false)
{ {
// Add safeguard if file doesn't exist // Add safeguard if file doesn't exist
if (!File.Exists(input)) if (!File.Exists(input))
@@ -656,7 +658,7 @@ namespace SabreTools.Helper
MD5 = string.Empty, MD5 = string.Empty,
SHA1 = string.Empty, SHA1 = string.Empty,
}, },
//Date = temp.LastWriteTime.ToString(), Date = (date ? temp.LastWriteTime.ToString("yyyy/MM/dd HH:mm:ss") : ""),
}; };
try try

View File

@@ -101,7 +101,8 @@ namespace SabreTools
/// <param name="bare">True if the date should be omitted from the DAT, false otherwise</param> /// <param name="bare">True if the date should be omitted from the DAT, false otherwise</param>
/// <param name="archivesAsFiles">True if archives should be treated as files, false otherwise</param> /// <param name="archivesAsFiles">True if archives should be treated as files, false otherwise</param>
/// <param name="enableGzip">True if GZIP archives should be treated as files, false otherwise</param> /// <param name="enableGzip">True if GZIP archives should be treated as files, false otherwise</param>
/// <param name="addblanks">True if blank items should be created for empty folders, false otherwise</param> /// <param name="addBlanks">True if blank items should be created for empty folders, false otherwise</param>
/// <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="tempDir">Name of the directory to create a temp folder in (blank is current directory</param>
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param> /// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
private static void InitDatFromDir(List<string> inputs, private static void InitDatFromDir(List<string> inputs,
@@ -120,7 +121,8 @@ namespace SabreTools
bool bare, bool bare,
bool archivesAsFiles, bool archivesAsFiles,
bool enableGzip, bool enableGzip,
bool addblanks, bool addBlanks,
bool addDate,
string tempDir, string tempDir,
int maxDegreeOfParallelism) int maxDegreeOfParallelism)
{ {
@@ -144,7 +146,7 @@ namespace SabreTools
// If the user has only set a single thread, use the original version // If the user has only set a single thread, use the original version
if (maxDegreeOfParallelism == 1) if (maxDegreeOfParallelism == 1)
{ {
DATFromDir dfd = new DATFromDir(inputs, basedat, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, addblanks, tempDir, _logger); DATFromDir dfd = new DATFromDir(inputs, basedat, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, addBlanks, addDate, tempDir, _logger);
bool success = dfd.Start(); bool success = dfd.Start();
// If we failed, show the help // If we failed, show the help
@@ -168,7 +170,7 @@ namespace SabreTools
datdata.Files = new Dictionary<string, List<Rom>>(); datdata.Files = new Dictionary<string, List<Rom>>();
string basePath = Path.GetFullPath(path); string basePath = Path.GetFullPath(path);
DATFromDirParallel dfd = new DATFromDirParallel(basePath, datdata, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, addblanks, tempDir, maxDegreeOfParallelism, _logger); DATFromDirParallel dfd = new DATFromDirParallel(basePath, datdata, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, addBlanks, addDate, tempDir, maxDegreeOfParallelism, _logger);
bool success = dfd.Start(); bool success = dfd.Start();
// If it was a success, write the DAT out // If it was a success, write the DAT out

View File

@@ -77,7 +77,8 @@ namespace SabreTools
// Set all default values // Set all default values
bool help = false, bool help = false,
add = false, add = false,
addblanks = false, addBlanks = false,
addDate = false,
archivesAsFiles = false, archivesAsFiles = false,
bare = false, bare = false,
clean = false, clean = false,
@@ -177,6 +178,14 @@ namespace SabreTools
case "--add": case "--add":
add = true; add = true;
break; break;
case "-ab":
case "--add-blank":
addBlanks = true;
break;
case "-ad":
case "--add-date":
addDate = true;
break;
case "-b": case "-b":
case "--bare": case "--bare":
bare = true; bare = true;
@@ -661,7 +670,7 @@ namespace SabreTools
else if (datfromdir) else if (datfromdir)
{ {
InitDatFromDir(inputs, filename, name, description, category, version, author, forceunpack, outputFormat, InitDatFromDir(inputs, filename, name, description, category, version, author, forceunpack, outputFormat,
romba, superdat, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, addblanks, tempdir, maxParallelism); romba, superdat, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, addBlanks, addDate, tempdir, maxParallelism);
} }
// Split a DAT by extension // Split a DAT by extension