[DatFile, ArchiveTools] TGZ and DFD fixes

This commit is contained in:
Matt Nadareski
2016-11-02 10:29:34 -07:00
parent 6d5217355e
commit f4436df8a8
2 changed files with 51 additions and 7 deletions

View File

@@ -3598,13 +3598,45 @@ namespace SabreTools.Helper.Dats
Description = Name + (bare ? "" : " (" + Date + ")");
}
// Make sure the dictionary is defined
if (Files == null || Files.Keys.Count == 0)
{
Files = new SortedDictionary<string, List<DatItem>>();
}
// Process the input
if (Directory.Exists(basePath))
{
logger.Verbose("Folder found: " + basePath);
// Process the files in the main folder
List<string> files = Directory.EnumerateFiles(basePath, "*", SearchOption.TopDirectoryOnly).ToList();
Parallel.ForEach(files,
new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism },
item =>
{
PopulateFromDirCheckFile(item, basePath, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
tempDir, copyFiles, headerToCheckAgainst, maxDegreeOfParallelism, logger);
});
// Find all top-level subfolders
files = Directory.EnumerateDirectories(basePath, "*", SearchOption.TopDirectoryOnly).ToList();
Parallel.ForEach(files,
new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism },
item =>
{
List<string> subfiles = Directory.EnumerateFiles(item, "*", SearchOption.AllDirectories).ToList();
Parallel.ForEach(subfiles,
new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism },
subitem =>
{
PopulateFromDirCheckFile(subitem, basePath, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
tempDir, copyFiles, headerToCheckAgainst, maxDegreeOfParallelism, logger);
});
});
// Process the files in all subfolders
List<string> files = Directory.EnumerateFiles(basePath, "*", SearchOption.AllDirectories).ToList();
files = Directory.EnumerateFiles(basePath, "*", SearchOption.AllDirectories).ToList();
Parallel.ForEach(files,
new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism },
item =>
@@ -3721,7 +3753,7 @@ namespace SabreTools.Helper.Dats
Rom rom = ArchiveTools.GetTorrentGZFileInfo(item, logger);
// If the rom is valid, write it out
if (rom.Name != null)
if (rom != null && rom.Name != null)
{
// Add the list if it doesn't exist already
string key = rom.Size + "-" + rom.CRC;
@@ -3736,7 +3768,6 @@ namespace SabreTools.Helper.Dats
Files[key].Add(rom);
logger.User("File added: " + Path.GetFileNameWithoutExtension(item) + Environment.NewLine);
}
}
else
{

View File

@@ -570,20 +570,33 @@ namespace SabreTools.Helper.Tools
/// <returns>Populated RomData object if success, empty one on error</returns>
public static Rom GetTorrentGZFileInfo(string input, Logger logger)
{
// Check for the file existing first
if (!File.Exists(input))
{
return null;
}
string datum = Path.GetFileName(input).ToLowerInvariant();
long filesize = new FileInfo(input).Length;
// If we have the romba depot files, just skip them gracefully
if (datum == ".romba_size" || datum == ".romba_size.backup")
{
logger.Verbose("Romba depot file found, skipping: " + input);
return null;
}
// Check if the name is the right length
if (!Regex.IsMatch(datum, @"^[0-9a-f]{40}\.gz"))
{
logger.Warning("Non SHA-1 filename found, skipping: '" + datum + "'");
logger.Warning("Non SHA-1 filename found, skipping: '" + Path.GetFullPath(input) + "'");
return null;
}
// Check if the file is at least the minimum length
if (filesize < 40 /* bytes */)
{
logger.Warning("Possibly corrupt file '" + input + "' with size " + Style.GetBytesReadable(filesize));
logger.Warning("Possibly corrupt file '" + Path.GetFullPath(input) + "' with size " + Style.GetBytesReadable(filesize));
return null;
}