[ArchiveTools] Use new extended info method

This commit is contained in:
Matt Nadareski
2017-03-16 12:43:47 -07:00
parent e06226b142
commit 849afb3f5d
2 changed files with 66 additions and 46 deletions

View File

@@ -398,45 +398,36 @@ namespace SabreTools.Helper.Dats
// If we're supposed to scan the file internally
if (shouldInternalProcess)
{
// If quickscan is set, do so
// Create an empty list of Roms for archive entries
List<Rom> entries = new List<Rom>();
usedInternally = true;
// If we're in quickscan, use the header information
if (quickScan)
{
List<Rom> extracted = ArchiveTools.GetArchiveFileInfo(file);
usedInternally = true;
foreach (Rom rom in extracted)
{
usedInternally &= RebuildIndividualFile(rom, file, outDir, tempSubDir, date, inverse, outputFormat,
romba, updateDat, true /* isZip */, headerToCheckAgainst);
}
entries = ArchiveTools.GetArchiveFileInfo(file);
}
// Otherwise, attempt to extract the files to the temporary directory
// Otherwise get the deeper information
else
{
bool encounteredErrors = ArchiveTools.ExtractArchive(file, tempSubDir, archiveScanLevel);
entries = ArchiveTools.GetExtendedArchiveFileInfo(file);
}
// If the file was an archive and was extracted successfully, check it
if (!encounteredErrors)
// If the entries list is null, we encountered an error and should scan exteranlly
if (entries == null && File.Exists(file))
{
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
Rom rom = FileTools.GetFileInfo(file, omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes));
usedExternally = RebuildIndividualFile(rom, file, outDir, tempSubDir, date, inverse, outputFormat,
romba, updateDat, false /* isZip */, headerToCheckAgainst);
}
// Otherwise, loop through the entries and try to match
else
{
foreach (Rom entry in entries)
{
usedInternally = true;
Globals.Logger.Verbose(Path.GetFileName(file) + " treated like an archive");
List<string> extracted = Directory.EnumerateFiles(tempSubDir, "*", SearchOption.AllDirectories).ToList();
foreach (string entry in extracted)
{
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
Rom rom = FileTools.GetFileInfo(entry, omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes));
usedInternally &= RebuildIndividualFile(rom, entry, outDir, tempSubDir, date, inverse, outputFormat,
romba, updateDat, false /* isZip */, headerToCheckAgainst);
}
}
// Otherwise, just get the info on the file itself
else if (File.Exists(file))
{
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
Rom rom = FileTools.GetFileInfo(file, omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes));
usedExternally = RebuildIndividualFile(rom, file, outDir, tempSubDir, date, inverse, outputFormat,
romba, updateDat, false /* isZip */, headerToCheckAgainst);
usedInternally &= RebuildIndividualFile(entry, file, outDir, tempSubDir, date, inverse, outputFormat,
romba, updateDat, true /* isZip */, headerToCheckAgainst);
}
}
}
@@ -444,16 +435,7 @@ namespace SabreTools.Helper.Dats
// If we are supposed to delete the file, do so
if (delete && (usedExternally || usedInternally))
{
try
{
Globals.Logger.Verbose("Attempting to delete input file '" + file + "'");
FileTools.TryDeleteFile(file, true);
Globals.Logger.Verbose("File '" + file + "' deleted");
}
catch (Exception ex)
{
Globals.Logger.Error("An error occurred while trying to delete '" + file + "' " + ex.ToString());
}
FileTools.TryDeleteFile(file);
}
// Now delete the temp directory
@@ -500,6 +482,7 @@ namespace SabreTools.Helper.Dats
}
// If we have an archive input, get the real name of the file to use
// TODO: Remove the need to extract the file first; reimplement ArchiveToArchive?
if (isZip)
{
// Otherwise, extract the file to the temp folder

View File

@@ -43,6 +43,43 @@ namespace SabreTools.Helper.Tools
{
private const int _bufferSize = 4096 * 128;
#region Archive-to-Archive handling
/// <summary>
/// Transfer a single file from one archive to another
/// </summary>
/// <param name="inputArchive">Input archive name</param>
/// <param name="inputEntry">Input entry name</param>
/// <param name="outputDir">Output directory</param>
/// <param name="outputEntry">Output Rom information</param>
/// <param name="date">True if dates are preserved, false otherwise (default)</param>
/// <returns>True if the transfer was a success, false otherwise</returns>
public static bool Transfer(string inputArchive, string inputEntry, string outputDir, Rom outputEntry, bool date = false)
{
// Verify inputs
// Create list versions
// return Transfer(multiple)
return false;
}
/// <summary>
/// Transfer multiple files from one archive to another
/// </summary>
/// <param name="inputArchives">Input archive names</param>
/// <param name="inputEntries">Input entry names</param>
/// <param name="outputDir">Output directory</param>
/// <param name="outputEntries">Output Rom informations</param>
/// <param name="date">True if dates are preserved, false otherwise (default)</param>
/// <returns>True if the transfesr were a success, false otherwise</returns>
public static bool Transfer(List<string> inputArchives, List<string> inputEntries, string outputDir, List<Rom> outputEntries, bool date = false)
{
// Verify inputs
// For each item, extract to stream, write to archive
return false;
}
#endregion
#region Extraction
/// <summary>
@@ -241,7 +278,6 @@ namespace SabreTools.Helper.Tools
SevenZipArchive sza = SevenZipArchive.Open(input, new ReaderOptions { LeaveStreamOpen = false, });
foreach (SevenZipArchiveEntry entry in sza.Entries)
{
Globals.Logger.Verbose("Current entry name: '" + entry.Key + "'");
if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName))
{
realEntry = entry.Key;
@@ -293,7 +329,6 @@ namespace SabreTools.Helper.Tools
RarArchive ra = RarArchive.Open(input, new ReaderOptions { LeaveStreamOpen = false, });
foreach (RarArchiveEntry entry in ra.Entries)
{
Globals.Logger.Verbose("Current entry name: '" + entry.Key + "'");
if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName))
{
realEntry = entry.Key;
@@ -317,7 +352,6 @@ namespace SabreTools.Helper.Tools
TarArchive ta = TarArchive.Open(input, new ReaderOptions { LeaveStreamOpen = false, });
foreach (TarArchiveEntry entry in ta.Entries)
{
Globals.Logger.Verbose("Current entry name: '" + entry.Key + "'");
if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName))
{
realEntry = entry.Key;
@@ -347,7 +381,6 @@ namespace SabreTools.Helper.Tools
for (int i = 0; i < zf.EntriesCount && zr == ZipReturn.ZipGood; i++)
{
Globals.Logger.Verbose("Current entry name: '" + zf.Entries[i].FileName + "'");
if (zf.Entries[i].FileName.Contains(entryName))
{
realEntry = zf.Entries[i].FileName;
@@ -376,6 +409,8 @@ namespace SabreTools.Helper.Tools
zipfileout.Dispose();
}
}
zf.Dispose();
break;
}
}
@@ -397,6 +432,7 @@ namespace SabreTools.Helper.Tools
/// </summary>
/// <param name="input">Input file to get data from</param>
/// <returns>List of RomData objects representing the found data</returns>
/// TODO: Can this be merged with the extended one?
public static List<Rom> GetArchiveFileInfo(string input)
{
List<Rom> roms = new List<Rom>();
@@ -747,6 +783,7 @@ namespace SabreTools.Helper.Tools
catch (Exception)
{
// Don't log file open errors
return null;
}
return found;