mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile, ArchiveTools] Better logging, better rebuild, enable delete
This commit is contained in:
@@ -218,7 +218,7 @@ namespace SabreTools.Helper.Data
|
|||||||
helptext.Add(" -dat= Input DAT to rebuild against");
|
helptext.Add(" -dat= Input DAT to rebuild against");
|
||||||
helptext.Add(" -out= Output directory");
|
helptext.Add(" -out= Output directory");
|
||||||
helptext.Add(" -t=, --temp= Set the temporary directory to use");
|
helptext.Add(" -t=, --temp= Set the temporary directory to use");
|
||||||
helptext.Add(" -del, --delete Delete input files [DO NOT USE]");
|
helptext.Add(" -del, --delete Delete fully rebuilt input files");
|
||||||
helptext.Add(" -in, --inverse Rebuild only files not in DAT");
|
helptext.Add(" -in, --inverse Rebuild only files not in DAT");
|
||||||
helptext.Add(" -qs, --quick Enable quick scanning of archives");
|
helptext.Add(" -qs, --quick Enable quick scanning of archives");
|
||||||
helptext.Add(" -ad, --add-date Add original dates from DAT, if possible");
|
helptext.Add(" -ad, --add-date Add original dates from DAT, if possible");
|
||||||
@@ -230,7 +230,7 @@ namespace SabreTools.Helper.Data
|
|||||||
//helptext.Add(" -trar Enable TorrentRAR output");
|
//helptext.Add(" -trar Enable TorrentRAR output");
|
||||||
//helptext.Add(" -txz Enable TorrentXZ output");
|
//helptext.Add(" -txz Enable TorrentXZ output");
|
||||||
helptext.Add(" -tzip Enable TorrentZip output");
|
helptext.Add(" -tzip Enable TorrentZip output");
|
||||||
helptext.Add(" -h=, --header= Set a header skipper to use, blank means all");
|
//helptext.Add(" -h=, --header= Set a header skipper to use, blank means all");
|
||||||
helptext.Add(" -7z={1} Set scanning level for 7z archives");
|
helptext.Add(" -7z={1} Set scanning level for 7z archives");
|
||||||
helptext.Add(" -gz={2} Set scanning level for GZip archives");
|
helptext.Add(" -gz={2} Set scanning level for GZip archives");
|
||||||
helptext.Add(" -rar={2} Set scanning level for RAR archives");
|
helptext.Add(" -rar={2} Set scanning level for RAR archives");
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
// If the input is a file
|
// If the input is a file
|
||||||
if (File.Exists(input))
|
if (File.Exists(input))
|
||||||
{
|
{
|
||||||
logger.User("Checking file: '" + input + "'");
|
logger.Verbose("Checking file: '" + input + "'");
|
||||||
RebuildToOutputHelper(input, outDir, tempDir, quickScan, date, delete, inverse,
|
RebuildToOutputHelper(input, outDir, tempDir, quickScan, date, delete, inverse,
|
||||||
outputFormat, romba, archiveScanLevel, updateDat, headerToCheckAgainst, maxDegreeOfParallelism, logger);
|
outputFormat, romba, archiveScanLevel, updateDat, headerToCheckAgainst, maxDegreeOfParallelism, logger);
|
||||||
}
|
}
|
||||||
@@ -127,10 +127,10 @@ namespace SabreTools.Helper.Dats
|
|||||||
// If the input is a directory
|
// If the input is a directory
|
||||||
else if (Directory.Exists(input))
|
else if (Directory.Exists(input))
|
||||||
{
|
{
|
||||||
logger.User("Checking directory: '" + input + "'");
|
logger.Verbose("Checking directory: '" + input + "'");
|
||||||
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
logger.User("Checking file: '" + file + "'");
|
logger.Verbose("Checking file: '" + file + "'");
|
||||||
RebuildToOutputHelper(file, outDir, tempDir, quickScan, date, delete, inverse,
|
RebuildToOutputHelper(file, outDir, tempDir, quickScan, date, delete, inverse,
|
||||||
outputFormat, romba, archiveScanLevel, updateDat, headerToCheckAgainst, maxDegreeOfParallelism, logger);
|
outputFormat, romba, archiveScanLevel, updateDat, headerToCheckAgainst, maxDegreeOfParallelism, logger);
|
||||||
}
|
}
|
||||||
@@ -213,26 +213,15 @@ namespace SabreTools.Helper.Dats
|
|||||||
// If the file was an archive and was extracted successfully, check it
|
// If the file was an archive and was extracted successfully, check it
|
||||||
if (!encounteredErrors)
|
if (!encounteredErrors)
|
||||||
{
|
{
|
||||||
|
usedInternally = true;
|
||||||
|
|
||||||
logger.Verbose(Path.GetFileName(file) + " treated like an archive");
|
logger.Verbose(Path.GetFileName(file) + " treated like an archive");
|
||||||
List<string> extracted = Directory.EnumerateFiles(tempSubDir, "*", SearchOption.AllDirectories).ToList();
|
List<string> extracted = Directory.EnumerateFiles(tempSubDir, "*", SearchOption.AllDirectories).ToList();
|
||||||
foreach (string entry in extracted)
|
foreach (string entry in extracted)
|
||||||
{
|
{
|
||||||
Rom rom = FileTools.GetFileInfo(entry, logger, noMD5: quickScan, noSHA1: quickScan, header: headerToCheckAgainst);
|
Rom rom = FileTools.GetFileInfo(entry, logger, noMD5: quickScan, noSHA1: quickScan, header: headerToCheckAgainst);
|
||||||
RebuildToOutputIndividual(rom, file, outDir, tempSubDir, date, inverse, outputFormat,
|
usedInternally &= RebuildToOutputIndividual(rom, entry, outDir, tempSubDir, date, inverse, outputFormat,
|
||||||
romba, updateDat, false /* isZip */, headerToCheckAgainst, logger);
|
romba, updateDat, false /* isZip */, headerToCheckAgainst, logger);
|
||||||
|
|
||||||
// Now we want to remove the file from the temp directory
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File.Delete(entry);
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the temp directory is empty, we assume that everything inside was used
|
|
||||||
if (Directory.EnumerateFiles(tempSubDir, "*", SearchOption.AllDirectories).Count() == 0)
|
|
||||||
{
|
|
||||||
usedInternally = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise, just get the info on the file itself
|
// Otherwise, just get the info on the file itself
|
||||||
@@ -250,9 +239,14 @@ namespace SabreTools.Helper.Dats
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
logger.Verbose("Attempting to delete input file '" + file + "'");
|
||||||
File.Delete(file);
|
File.Delete(file);
|
||||||
|
logger.Verbose("File '" + file + "' deleted");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.Error("An error occurred while trying to delete '" + file + "' " + ex.ToString());
|
||||||
}
|
}
|
||||||
catch { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now delete the temp directory
|
// Now delete the temp directory
|
||||||
@@ -313,6 +307,8 @@ namespace SabreTools.Helper.Dats
|
|||||||
return rebuilt;
|
return rebuilt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.User("Matches found for '" + file + "', rebuilding accordingly...");
|
||||||
|
|
||||||
// Now loop through the list and rebuild accordingly
|
// Now loop through the list and rebuild accordingly
|
||||||
foreach (Rom item in dupes)
|
foreach (Rom item in dupes)
|
||||||
{
|
{
|
||||||
@@ -339,7 +335,7 @@ namespace SabreTools.Helper.Dats
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
rebuilt &= false;
|
rebuilt = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -361,8 +357,11 @@ namespace SabreTools.Helper.Dats
|
|||||||
rebuilt &= ArchiveTools.WriteTorrentZip(file, outDir, item, logger, date: date);
|
rebuilt &= ArchiveTools.WriteTorrentZip(file, outDir, item, logger, date: date);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// And now clear the temp folder to get rid of any transient files
|
// And now clear the temp folder to get rid of any transient files if we unzipped
|
||||||
|
if (isZip)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.Delete(tempDir, true);
|
Directory.Delete(tempDir, true);
|
||||||
@@ -374,10 +373,13 @@ namespace SabreTools.Helper.Dats
|
|||||||
// If we have no duplicates and we're filtering, rebuild it
|
// If we have no duplicates and we're filtering, rebuild it
|
||||||
else if (!hasDuplicates && inverse)
|
else if (!hasDuplicates && inverse)
|
||||||
{
|
{
|
||||||
|
string machinename = null;
|
||||||
|
|
||||||
// If we have an archive input, get the real name of the file to use
|
// If we have an archive input, get the real name of the file to use
|
||||||
if (isZip)
|
if (isZip)
|
||||||
{
|
{
|
||||||
// Otherwise, extract the file to the temp folder
|
// Otherwise, extract the file to the temp folder
|
||||||
|
machinename = Style.GetFileNameWithoutExtension(file);
|
||||||
file = ArchiveTools.ExtractItem(file, rom.Name, tempDir, logger);
|
file = ArchiveTools.ExtractItem(file, rom.Name, tempDir, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,6 +391,20 @@ namespace SabreTools.Helper.Dats
|
|||||||
|
|
||||||
// Get the item from the current file
|
// Get the item from the current file
|
||||||
Rom item = FileTools.GetFileInfo(file, logger);
|
Rom item = FileTools.GetFileInfo(file, logger);
|
||||||
|
item.Machine = new Machine()
|
||||||
|
{
|
||||||
|
Name = Style.GetFileNameWithoutExtension(item.Name),
|
||||||
|
Description = Style.GetFileNameWithoutExtension(item.Name),
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are coming from an archive, set the correct machine name
|
||||||
|
if (machinename != null)
|
||||||
|
{
|
||||||
|
item.Machine.Name = machinename;
|
||||||
|
item.Machine.Description = machinename;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.User("Matches found for '" + file + "', rebuilding accordingly...");
|
||||||
|
|
||||||
// Now rebuild to the output file
|
// Now rebuild to the output file
|
||||||
switch (outputFormat)
|
switch (outputFormat)
|
||||||
@@ -435,13 +451,16 @@ namespace SabreTools.Helper.Dats
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// And now clear the temp folder to get rid of any transient files
|
// And now clear the temp folder to get rid of any transient files if we unzipped
|
||||||
|
if (isZip)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.Delete(tempDir, true);
|
Directory.Delete(tempDir, true);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return rebuilt;
|
return rebuilt;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -392,10 +392,10 @@ Options:
|
|||||||
(inside the running folder) is not preferred. This is used for any operations that
|
(inside the running folder) is not preferred. This is used for any operations that
|
||||||
require an archive to be extracted.
|
require an archive to be extracted.
|
||||||
|
|
||||||
-d, --delete Enable deletion of the input files [DO NOT USE]
|
-d, --delete Delete fully rebuilt input files
|
||||||
Optionally, the input files, once processed, can be deleted. This can be useful
|
Optionally, the input files, once processed and fully matched, can be deleted. This
|
||||||
when the original file structure is no longer needed or if there is limited space
|
can be useful when the original file structure is no longer needed or if there is
|
||||||
on the source drive.
|
limited space on the source drive.
|
||||||
|
|
||||||
-in, --inverse Match files not in the DAT
|
-in, --inverse Match files not in the DAT
|
||||||
Instead of the normal behavior of rebuilding using a DAT, this flag allows the user
|
Instead of the normal behavior of rebuilding using a DAT, this flag allows the user
|
||||||
@@ -461,7 +461,7 @@ Options:
|
|||||||
This is primarily used by external tool RomVault (http://www.romvault.com/) and is
|
This is primarily used by external tool RomVault (http://www.romvault.com/) and is
|
||||||
already widely used.
|
already widely used.
|
||||||
|
|
||||||
-h=, --header= Remove headers from hash calculations
|
-h=, --header= Remove headers from hash calculations [NOT IMPLEMENTED]
|
||||||
If this is set, then all files that have copier headers that are detected will
|
If this is set, then all files that have copier headers that are detected will
|
||||||
have them removed from the hash calculation. This will allow for a headered collection
|
have them removed from the hash calculation. This will allow for a headered collection
|
||||||
to be hashed without possibly variant information. If a particular header skipper is
|
to be hashed without possibly variant information. If a particular header skipper is
|
||||||
|
|||||||
@@ -190,6 +190,7 @@ namespace SabreTools.Helper.Tools
|
|||||||
zr = zf.CloseReadStream();
|
zr = zf.CloseReadStream();
|
||||||
writeStream.Dispose();
|
writeStream.Dispose();
|
||||||
}
|
}
|
||||||
|
zf.Close();
|
||||||
encounteredErrors = false;
|
encounteredErrors = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user