[DatFile] Use extract-less methods for dfd

This commit is contained in:
Matt Nadareski
2017-03-16 14:17:35 -07:00
parent 9a9ea20614
commit 53c1f1f030

View File

@@ -209,16 +209,29 @@ namespace SabreTools.Helper.Dats
File.Copy(item, newItem, true); File.Copy(item, newItem, true);
} }
// Create a list for all found items
List<Rom> extracted = new List<Rom>();
// If all deep hash skip flags are set, do a quickscan // If all deep hash skip flags are set, do a quickscan
if (omitFromScan == Hash.SecureHashes) if (omitFromScan == Hash.SecureHashes)
{ {
ArchiveType? type = ArchiveTools.GetCurrentArchiveType(newItem); extracted = ArchiveTools.GetArchiveFileInfo(newItem);
}
// If we have an archive, scan it // Otherwise, get the list with whatever hashes are wanted
if (type != null && !archivesAsFiles) else
{ {
List<Rom> extracted = ArchiveTools.GetArchiveFileInfo(newItem); extracted = ArchiveTools.GetExtendedArchiveFileInfo(newItem, omitFromScan: omitFromScan);
}
// If the extracted list is null, just scan the item itself
if (extracted == null)
{
PopulateFromDirProcessFile(newItem, "", newBasePath, omitFromScan, addDate, headerToCheckAgainst);
}
// Otherwise, add all of the found items
else
{
// First take care of the found items
foreach (Rom rom in extracted) foreach (Rom rom in extracted)
{ {
PopulateFromDirProcessFileHelper(newItem, PopulateFromDirProcessFileHelper(newItem,
@@ -226,102 +239,23 @@ namespace SabreTools.Helper.Dats
basePath, basePath,
(Path.GetDirectoryName(Path.GetFullPath(item)) + Path.DirectorySeparatorChar).Remove(0, basePath.Length) + Path.GetFileNameWithoutExtension(item)); (Path.GetDirectoryName(Path.GetFullPath(item)) + Path.DirectorySeparatorChar).Remove(0, basePath.Length) + Path.GetFileNameWithoutExtension(item));
} }
}
// Otherwise, just get the info on the file itself
else if (File.Exists(newItem))
{
PopulateFromDirProcessFile(newItem, "", newBasePath, omitFromScan, addDate, headerToCheckAgainst);
}
}
// Otherwise, attempt to extract the files to the temporary directory
else
{
ArchiveScanLevel asl = (archivesAsFiles ? ArchiveScanLevel.SevenZipExternal : ArchiveScanLevel.SevenZipInternal)
| (!archivesAsFiles && enableGzip ? ArchiveScanLevel.GZipInternal : ArchiveScanLevel.GZipExternal)
| (archivesAsFiles ? ArchiveScanLevel.RarExternal : ArchiveScanLevel.RarInternal)
| (archivesAsFiles ? ArchiveScanLevel.ZipExternal : ArchiveScanLevel.ZipInternal);
bool encounteredErrors = ArchiveTools.ExtractArchive(newItem, tempSubDir, asl); // Then, if we're looking for blanks, get all of the blank folders and add them
// If the file was an archive and was extracted successfully, check it
if (!encounteredErrors)
{
Globals.Logger.Verbose(Path.GetFileName(item) + " treated like an archive");
List<string> extracted = Directory.EnumerateFiles(tempSubDir, "*", SearchOption.AllDirectories).ToList();
Parallel.ForEach(extracted,
Globals.ParallelOptions,
entry =>
{
PopulateFromDirProcessFile(entry,
Path.Combine((Type == "SuperDAT"
? (Path.GetDirectoryName(Path.GetFullPath(item)) + Path.DirectorySeparatorChar).Remove(0, basePath.Length)
: ""),
Path.GetFileNameWithoutExtension(item)),
tempSubDir,
omitFromScan,
addDate,
headerToCheckAgainst);
});
// Now find all folders that are empty, if we are supposed to
if (addBlanks) if (addBlanks)
{ {
// Get the list of empty directories List<string> empties = ArchiveTools.GetEmptyFoldersInArchive(newItem);
List<string> empties = FileTools.GetEmptyDirectories(tempSubDir).ToList();
Parallel.ForEach(empties, Parallel.ForEach(empties,
Globals.ParallelOptions, Globals.ParallelOptions,
dir => empty =>
{ {
// Get the full path for the directory Rom emptyRom = new Rom(Path.Combine(empty, "_"), newItem, omitFromScan);
string fulldir = Path.GetFullPath(dir); PopulateFromDirProcessFileHelper(newItem,
emptyRom,
// Set the temporary variables basePath,
string gamename = ""; (Path.GetDirectoryName(Path.GetFullPath(item)) + Path.DirectorySeparatorChar).Remove(0, basePath.Length) + Path.GetFileNameWithoutExtension(item));
string romname = "";
// If we have a SuperDAT, we want anything that's not the base path as the game, and the file as the rom
if (Type == "SuperDAT")
{
gamename = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(item)).Remove(0, basePath.Length), Path.GetFileNameWithoutExtension(item));
romname = Path.Combine(fulldir.Remove(0, tempSubDir.Length), "_");
}
// Otherwise, we want just the item as the game, and the file as everything else
else
{
gamename = Path.GetFileNameWithoutExtension(item);
romname = Path.Combine(fulldir.Remove(0, tempSubDir.Length), "_");
}
// Sanitize the names
if (gamename.StartsWith(Path.DirectorySeparatorChar.ToString()))
{
gamename = gamename.Substring(1);
}
if (gamename.EndsWith(Path.DirectorySeparatorChar.ToString()))
{
gamename = gamename.Substring(0, gamename.Length - 1);
}
if (romname.StartsWith(Path.DirectorySeparatorChar.ToString()))
{
romname = romname.Substring(1);
}
if (romname.EndsWith(Path.DirectorySeparatorChar.ToString()))
{
romname = romname.Substring(0, romname.Length - 1);
}
Globals.Logger.Verbose("Adding blank empty folder: " + gamename);
this["null"].Add(new Rom(romname, gamename, omitFromScan));
}); });
} }
} }
// Otherwise, just get the info on the file itself
else if (File.Exists(newItem))
{
PopulateFromDirProcessFile(newItem, "", newBasePath, omitFromScan, addDate, headerToCheckAgainst);
}
}
// Cue to delete the file if it's a copy // Cue to delete the file if it's a copy
if (copyFiles && item != newItem) if (copyFiles && item != newItem)
@@ -419,14 +353,14 @@ namespace SabreTools.Helper.Dats
if (Type == "SuperDAT") if (Type == "SuperDAT")
{ {
gamename = parent; gamename = parent;
romname = item.Remove(0, basepath.Length); romname = datItem.Name;
} }
// Otherwise, we want the archive name as the game, and the file as everything else // Otherwise, we want the archive name as the game, and the file as everything else
else else
{ {
gamename = parent; gamename = parent;
romname = item.Remove(0, basepath.Length); romname = datItem.Name;
} }
} }