mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[FileTypes/] BaseFile for life
This commit is contained in:
@@ -41,7 +41,7 @@ namespace RombaSharp
|
|||||||
if (lowerCaseDats.Contains(input.ToLowerInvariant()))
|
if (lowerCaseDats.Contains(input.ToLowerInvariant()))
|
||||||
{
|
{
|
||||||
string fullpath = Path.GetFullPath(datRootDats[lowerCaseDats.IndexOf(input.ToLowerInvariant())]);
|
string fullpath = Path.GetFullPath(datRootDats[lowerCaseDats.IndexOf(input.ToLowerInvariant())]);
|
||||||
string sha1 = ((Rom)Utilities.GetFileInfo(fullpath)).SHA1;
|
string sha1 = Utilities.ByteArrayToString(Utilities.GetFileInfo(fullpath).SHA1);
|
||||||
foundDats.Add(sha1, fullpath);
|
foundDats.Add(sha1, fullpath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -3625,13 +3625,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
if (Romba)
|
if (Romba)
|
||||||
{
|
{
|
||||||
GZipArchive archive = new GZipArchive(item);
|
GZipArchive archive = new GZipArchive(item);
|
||||||
Rom rom = archive.GetTorrentGZFileInfo();
|
BaseFile rom = archive.GetTorrentGZFileInfo();
|
||||||
|
|
||||||
// If the rom is valid, write it out
|
// If the rom is valid, write it out
|
||||||
if (rom != null && rom.Name != null)
|
if (rom != null && rom.Filename != null)
|
||||||
{
|
{
|
||||||
// Add the list if it doesn't exist already
|
// Add the list if it doesn't exist already
|
||||||
Add(rom.Size + "-" + rom.CRC, rom);
|
Add(rom.Size + "-" + rom.CRC, new Rom(rom));
|
||||||
Globals.Logger.User("File added: {0}", Path.GetFileNameWithoutExtension(item) + Environment.NewLine);
|
Globals.Logger.User("File added: {0}", Path.GetFileNameWithoutExtension(item) + Environment.NewLine);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -3655,18 +3655,18 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a list for all found items
|
// Create a list for all found items
|
||||||
List<Rom> extracted = null;
|
List<BaseFile> extracted = null;
|
||||||
|
|
||||||
// If we don't have archives as files, try to scan the file as an archive
|
// If we don't have archives as files, try to scan the file as an archive
|
||||||
if (!archivesAsFiles)
|
if (!archivesAsFiles)
|
||||||
{
|
{
|
||||||
// Get the base archive first
|
// Get the base archive first
|
||||||
BaseArchive archive = Utilities.GetArchive(newItem);
|
Folder archive = Utilities.GetArchive(newItem);
|
||||||
|
|
||||||
// Now get all extracted items from the archive
|
// Now get all extracted items from the archive
|
||||||
if (archive != null)
|
if (archive != null)
|
||||||
{
|
{
|
||||||
extracted = archive.GetArchiveFileInfo(omitFromScan: omitFromScan, date: addDate);
|
extracted = archive.GetChildren(omitFromScan: omitFromScan, date: addDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3688,8 +3688,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
// First take care of the found items
|
// First take care of the found items
|
||||||
Parallel.ForEach(extracted, Globals.ParallelOptions, rom =>
|
Parallel.ForEach(extracted, Globals.ParallelOptions, rom =>
|
||||||
{
|
{
|
||||||
|
DatItem datItem = (rom.Type == FileType.CHD ? (DatItem)(new Disk(rom)) : (DatItem)(new Rom(rom)));
|
||||||
ProcessFileHelper(newItem,
|
ProcessFileHelper(newItem,
|
||||||
rom,
|
datItem,
|
||||||
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));
|
||||||
});
|
});
|
||||||
@@ -3700,7 +3701,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
List<string> empties = new List<string>();
|
List<string> empties = new List<string>();
|
||||||
|
|
||||||
// Get the base archive first
|
// Get the base archive first
|
||||||
BaseArchive archive = Utilities.GetArchive(newItem);
|
Folder archive = Utilities.GetArchive(newItem);
|
||||||
|
|
||||||
// Now get all blank folders from the archive
|
// Now get all blank folders from the archive
|
||||||
if (archive != null)
|
if (archive != null)
|
||||||
@@ -3741,7 +3742,16 @@ namespace SabreTools.Library.DatFiles
|
|||||||
bool addDate, string headerToCheckAgainst, bool chdsAsFiles)
|
bool addDate, string headerToCheckAgainst, bool chdsAsFiles)
|
||||||
{
|
{
|
||||||
Globals.Logger.Verbose("'{0}' treated like a file", Path.GetFileName(item));
|
Globals.Logger.Verbose("'{0}' treated like a file", Path.GetFileName(item));
|
||||||
DatItem datItem = Utilities.GetFileInfo(item, omitFromScan: omitFromScan, date: addDate, header: headerToCheckAgainst, chdsAsFiles: chdsAsFiles);
|
BaseFile baseFile = Utilities.GetFileInfo(item, omitFromScan: omitFromScan, date: addDate, header: headerToCheckAgainst, chdsAsFiles: chdsAsFiles);
|
||||||
|
DatItem datItem = null;
|
||||||
|
if (baseFile.Type == FileType.CHD)
|
||||||
|
{
|
||||||
|
datItem = new Disk(baseFile);
|
||||||
|
}
|
||||||
|
else if (baseFile.Type == FileType.None)
|
||||||
|
{
|
||||||
|
datItem = new Rom(baseFile);
|
||||||
|
}
|
||||||
|
|
||||||
ProcessFileHelper(item, datItem, basePath, parent);
|
ProcessFileHelper(item, datItem, basePath, parent);
|
||||||
}
|
}
|
||||||
@@ -4023,7 +4033,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
// If we have a path, we want to try to get the rom information
|
// If we have a path, we want to try to get the rom information
|
||||||
GZipArchive archive = new GZipArchive(foundpath);
|
GZipArchive archive = new GZipArchive(foundpath);
|
||||||
Rom fileinfo = archive.GetTorrentGZFileInfo();
|
BaseFile fileinfo = archive.GetTorrentGZFileInfo();
|
||||||
|
|
||||||
// If the file information is null, then we continue
|
// If the file information is null, then we continue
|
||||||
if (fileinfo == null)
|
if (fileinfo == null)
|
||||||
@@ -4032,7 +4042,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we rebuild that file to all locations that we need to
|
// Otherwise, we rebuild that file to all locations that we need to
|
||||||
RebuildIndividualFile(fileinfo, foundpath, outDir, date, inverse, outputFormat, romba,
|
RebuildIndividualFile(new Rom(fileinfo), foundpath, outDir, date, inverse, outputFormat, romba,
|
||||||
updateDat, false /* isZip */, headerToCheckAgainst);
|
updateDat, false /* isZip */, headerToCheckAgainst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4220,17 +4230,27 @@ namespace SabreTools.Library.DatFiles
|
|||||||
if (shouldExternalProcess)
|
if (shouldExternalProcess)
|
||||||
{
|
{
|
||||||
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
|
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
|
||||||
DatItem fileinfo = Utilities.GetFileInfo(file, omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes),
|
BaseFile fileinfo = Utilities.GetFileInfo(file, omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes),
|
||||||
header: headerToCheckAgainst, chdsAsFiles: chdsAsFiles);
|
header: headerToCheckAgainst, chdsAsFiles: chdsAsFiles);
|
||||||
usedExternally = RebuildIndividualFile(fileinfo, file, outDir, date, inverse, outputFormat,
|
DatItem datItem = null;
|
||||||
|
if (fileinfo.Type == FileType.CHD)
|
||||||
|
{
|
||||||
|
datItem = new Disk(fileinfo);
|
||||||
|
}
|
||||||
|
else if (fileinfo.Type == FileType.None)
|
||||||
|
{
|
||||||
|
datItem = new Rom(fileinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
usedExternally = RebuildIndividualFile(datItem, file, outDir, date, inverse, outputFormat,
|
||||||
romba, updateDat, null /* isZip */, headerToCheckAgainst);
|
romba, updateDat, null /* isZip */, headerToCheckAgainst);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're supposed to scan the file internally
|
// If we're supposed to scan the file internally
|
||||||
if (shouldInternalProcess)
|
if (shouldInternalProcess)
|
||||||
{
|
{
|
||||||
// Create an empty list of Roms for archive entries
|
// Create an empty list of BaseFile for archive entries
|
||||||
List<Rom> entries = null;
|
List<BaseFile> entries = null;
|
||||||
usedInternally = true;
|
usedInternally = true;
|
||||||
|
|
||||||
// Get the TGZ status for later
|
// Get the TGZ status for later
|
||||||
@@ -4238,29 +4258,40 @@ namespace SabreTools.Library.DatFiles
|
|||||||
bool isTorrentGzip = tgz.IsTorrent();
|
bool isTorrentGzip = tgz.IsTorrent();
|
||||||
|
|
||||||
// Get the base archive first
|
// Get the base archive first
|
||||||
BaseArchive archive = Utilities.GetArchive(file);
|
Folder archive = Utilities.GetArchive(file);
|
||||||
|
|
||||||
// Now get all extracted items from the archive
|
// Now get all extracted items from the archive
|
||||||
if (archive != null)
|
if (archive != null)
|
||||||
{
|
{
|
||||||
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
|
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
|
||||||
entries = archive.GetArchiveFileInfo(omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes), date: date);
|
entries = archive.GetChildren(omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes), date: date);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the entries list is null, we encountered an error and should scan exteranlly
|
// If the entries list is null, we encountered an error and should scan exteranlly
|
||||||
if (entries == null && File.Exists(file))
|
if (entries == null && File.Exists(file))
|
||||||
{
|
{
|
||||||
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
|
// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually
|
||||||
DatItem fileinfo = Utilities.GetFileInfo(file, omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes), chdsAsFiles: chdsAsFiles);
|
BaseFile fileinfo = Utilities.GetFileInfo(file, omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes), chdsAsFiles: chdsAsFiles);
|
||||||
usedExternally = RebuildIndividualFile(fileinfo, file, outDir, date, inverse, outputFormat,
|
DatItem datItem = null;
|
||||||
|
if (fileinfo.Type == FileType.CHD)
|
||||||
|
{
|
||||||
|
datItem = new Disk(fileinfo);
|
||||||
|
}
|
||||||
|
else if (fileinfo.Type == FileType.None)
|
||||||
|
{
|
||||||
|
datItem = new Rom(fileinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
usedExternally = RebuildIndividualFile(datItem, file, outDir, date, inverse, outputFormat,
|
||||||
romba, updateDat, null /* isZip */, headerToCheckAgainst);
|
romba, updateDat, null /* isZip */, headerToCheckAgainst);
|
||||||
}
|
}
|
||||||
// Otherwise, loop through the entries and try to match
|
// Otherwise, loop through the entries and try to match
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (Rom entry in entries)
|
foreach (BaseFile entry in entries)
|
||||||
{
|
{
|
||||||
usedInternally &= RebuildIndividualFile(entry, file, outDir, date, inverse, outputFormat,
|
DatItem datItem = (entry.Type == FileType.CHD ? (DatItem)(new Disk(entry)) : (DatItem)(new Rom(entry)));
|
||||||
|
usedInternally &= RebuildIndividualFile(datItem, file, outDir, date, inverse, outputFormat,
|
||||||
romba, updateDat, !isTorrentGzip /* isZip */, headerToCheckAgainst);
|
romba, updateDat, !isTorrentGzip /* isZip */, headerToCheckAgainst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4330,7 +4361,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
// If we have a very specifc TGZ->TGZ case, just copy it accordingly
|
// If we have a very specifc TGZ->TGZ case, just copy it accordingly
|
||||||
GZipArchive tgz = new GZipArchive(file);
|
GZipArchive tgz = new GZipArchive(file);
|
||||||
Rom rom = tgz.GetTorrentGZFileInfo();
|
BaseFile rom = tgz.GetTorrentGZFileInfo();
|
||||||
if (isZip == false && rom != null && outputFormat == OutputFormat.TorrentGzip)
|
if (isZip == false && rom != null && outputFormat == OutputFormat.TorrentGzip)
|
||||||
{
|
{
|
||||||
Globals.Logger.User("Matches found for '{0}', rebuilding accordingly...", Path.GetFileName(datItem.Name));
|
Globals.Logger.User("Matches found for '{0}', rebuilding accordingly...", Path.GetFileName(datItem.Name));
|
||||||
@@ -4369,7 +4400,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
if (isZip != null)
|
if (isZip != null)
|
||||||
{
|
{
|
||||||
string realName = null;
|
string realName = null;
|
||||||
BaseArchive archive = Utilities.GetArchive(file);
|
Folder archive = Utilities.GetArchive(file);
|
||||||
if (archive != null)
|
if (archive != null)
|
||||||
{
|
{
|
||||||
(fileStream, realName) = archive.ExtractEntryStream(datItem.Name);
|
(fileStream, realName) = archive.ExtractEntryStream(datItem.Name);
|
||||||
@@ -4397,7 +4428,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
foreach (DatItem item in dupes)
|
foreach (DatItem item in dupes)
|
||||||
{
|
{
|
||||||
// Get the output archive, if possible
|
// Get the output archive, if possible
|
||||||
BaseArchive outputArchive = Utilities.GetArchive(outputFormat);
|
Folder outputArchive = Utilities.GetArchive(outputFormat);
|
||||||
|
|
||||||
// Now rebuild to the output file
|
// Now rebuild to the output file
|
||||||
outputArchive.Write(fileStream, outDir, (Rom)item, date: date, romba: romba);
|
outputArchive.Write(fileStream, outDir, (Rom)item, date: date, romba: romba);
|
||||||
@@ -4414,7 +4445,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
// If we have a very specifc TGZ->TGZ case, just copy it accordingly
|
// If we have a very specifc TGZ->TGZ case, just copy it accordingly
|
||||||
GZipArchive tgz = new GZipArchive(file);
|
GZipArchive tgz = new GZipArchive(file);
|
||||||
Rom rom = tgz.GetTorrentGZFileInfo();
|
BaseFile rom = tgz.GetTorrentGZFileInfo();
|
||||||
if (isZip == false && rom != null && outputFormat == OutputFormat.TorrentGzip)
|
if (isZip == false && rom != null && outputFormat == OutputFormat.TorrentGzip)
|
||||||
{
|
{
|
||||||
Globals.Logger.User("Matches found for '{0}', rebuilding accordingly...", Path.GetFileName(datItem.Name));
|
Globals.Logger.User("Matches found for '{0}', rebuilding accordingly...", Path.GetFileName(datItem.Name));
|
||||||
@@ -4453,7 +4484,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
if (isZip != null)
|
if (isZip != null)
|
||||||
{
|
{
|
||||||
string realName = null;
|
string realName = null;
|
||||||
BaseArchive archive = Utilities.GetArchive(file);
|
Folder archive = Utilities.GetArchive(file);
|
||||||
if (archive != null)
|
if (archive != null)
|
||||||
{
|
{
|
||||||
(fileStream, realName) = archive.ExtractEntryStream(datItem.Name);
|
(fileStream, realName) = archive.ExtractEntryStream(datItem.Name);
|
||||||
@@ -4472,7 +4503,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the item from the current file
|
// Get the item from the current file
|
||||||
Rom item = (Rom)Utilities.GetStreamInfo(fileStream, fileStream.Length, keepReadOpen: true);
|
Rom item = new Rom(Utilities.GetStreamInfo(fileStream, fileStream.Length, keepReadOpen: true));
|
||||||
item.MachineName = Path.GetFileNameWithoutExtension(item.Name);
|
item.MachineName = Path.GetFileNameWithoutExtension(item.Name);
|
||||||
item.MachineDescription = Path.GetFileNameWithoutExtension(item.Name);
|
item.MachineDescription = Path.GetFileNameWithoutExtension(item.Name);
|
||||||
|
|
||||||
@@ -4486,7 +4517,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
Globals.Logger.User("No matches found for '{0}', rebuilding accordingly from inverse flag...", Path.GetFileName(datItem.Name));
|
Globals.Logger.User("No matches found for '{0}', rebuilding accordingly from inverse flag...", Path.GetFileName(datItem.Name));
|
||||||
|
|
||||||
// Get the output archive, if possible
|
// Get the output archive, if possible
|
||||||
BaseArchive outputArchive = Utilities.GetArchive(outputFormat);
|
Folder outputArchive = Utilities.GetArchive(outputFormat);
|
||||||
|
|
||||||
// Now rebuild to the output file
|
// Now rebuild to the output file
|
||||||
if (outputArchive == null)
|
if (outputArchive == null)
|
||||||
@@ -4543,7 +4574,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
if (isZip != null)
|
if (isZip != null)
|
||||||
{
|
{
|
||||||
string realName = null;
|
string realName = null;
|
||||||
BaseArchive archive = Utilities.GetArchive(file);
|
Folder archive = Utilities.GetArchive(file);
|
||||||
if (archive != null)
|
if (archive != null)
|
||||||
{
|
{
|
||||||
(fileStream, realName) = archive.ExtractEntryStream(datItem.Name);
|
(fileStream, realName) = archive.ExtractEntryStream(datItem.Name);
|
||||||
@@ -4572,7 +4603,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
if (rule.TransformStream(fileStream, transformStream, keepReadOpen: true, keepWriteOpen: true))
|
if (rule.TransformStream(fileStream, transformStream, keepReadOpen: true, keepWriteOpen: true))
|
||||||
{
|
{
|
||||||
// Get the file informations that we will be using
|
// Get the file informations that we will be using
|
||||||
Rom headerless = (Rom)Utilities.GetStreamInfo(transformStream, transformStream.Length, keepReadOpen: true);
|
Rom headerless = new Rom(Utilities.GetStreamInfo(transformStream, transformStream.Length, keepReadOpen: true));
|
||||||
|
|
||||||
// Find if the file has duplicates in the DAT
|
// Find if the file has duplicates in the DAT
|
||||||
hasDuplicates = headerless.HasDuplicates(this);
|
hasDuplicates = headerless.HasDuplicates(this);
|
||||||
@@ -4603,7 +4634,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
bool eitherSuccess = false;
|
bool eitherSuccess = false;
|
||||||
|
|
||||||
// Get the output archive, if possible
|
// Get the output archive, if possible
|
||||||
BaseArchive outputArchive = Utilities.GetArchive(outputFormat);
|
Folder outputArchive = Utilities.GetArchive(outputFormat);
|
||||||
|
|
||||||
// Now rebuild to the output file
|
// Now rebuild to the output file
|
||||||
eitherSuccess |= outputArchive.Write(transformStream, outDir, (Rom)item, date: date, romba: romba);
|
eitherSuccess |= outputArchive.Write(transformStream, outDir, (Rom)item, date: date, romba: romba);
|
||||||
@@ -4693,7 +4724,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
// If we have a path, we want to try to get the rom information
|
// If we have a path, we want to try to get the rom information
|
||||||
GZipArchive tgz = new GZipArchive(foundpath);
|
GZipArchive tgz = new GZipArchive(foundpath);
|
||||||
Rom fileinfo = tgz.GetTorrentGZFileInfo();
|
BaseFile fileinfo = tgz.GetTorrentGZFileInfo();
|
||||||
|
|
||||||
// If the file information is null, then we continue
|
// If the file information is null, then we continue
|
||||||
if (fileinfo == null)
|
if (fileinfo == null)
|
||||||
@@ -4702,7 +4733,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now we want to remove all duplicates from the DAT
|
// Now we want to remove all duplicates from the DAT
|
||||||
fileinfo.GetDuplicates(this, remove: true);
|
new Rom(fileinfo).GetDuplicates(this, remove: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
watch.Stop();
|
watch.Stop();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using SabreTools.Library.Data;
|
using SabreTools.Library.Data;
|
||||||
|
using SabreTools.Library.FileTypes;
|
||||||
using SabreTools.Library.Tools;
|
using SabreTools.Library.Tools;
|
||||||
|
|
||||||
namespace SabreTools.Library.DatItems
|
namespace SabreTools.Library.DatItems
|
||||||
@@ -101,6 +102,20 @@ namespace SabreTools.Library.DatItems
|
|||||||
_itemStatus = ItemStatus.None;
|
_itemStatus = ItemStatus.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a Rom object from a BaseFile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="baseFile"></param>
|
||||||
|
public Disk(BaseFile baseFile)
|
||||||
|
{
|
||||||
|
_name = baseFile.Filename;
|
||||||
|
_md5 = baseFile.MD5;
|
||||||
|
_sha1 = baseFile.SHA1;
|
||||||
|
_sha256 = baseFile.SHA256;
|
||||||
|
_sha384 = baseFile.SHA384;
|
||||||
|
_sha512 = baseFile.SHA512;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Cloning Methods
|
#region Cloning Methods
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using SabreTools.Library.Data;
|
using SabreTools.Library.Data;
|
||||||
|
using SabreTools.Library.FileTypes;
|
||||||
using SabreTools.Library.Tools;
|
using SabreTools.Library.Tools;
|
||||||
|
|
||||||
namespace SabreTools.Library.DatItems
|
namespace SabreTools.Library.DatItems
|
||||||
@@ -165,6 +166,21 @@ namespace SabreTools.Library.DatItems
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a Rom object from a BaseFile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="baseFile"></param>
|
||||||
|
public Rom(BaseFile baseFile)
|
||||||
|
{
|
||||||
|
_name = baseFile.Filename;
|
||||||
|
_crc = baseFile.CRC;
|
||||||
|
_md5 = baseFile.MD5;
|
||||||
|
_sha1 = baseFile.SHA1;
|
||||||
|
_sha256 = baseFile.SHA256;
|
||||||
|
_sha384 = baseFile.SHA384;
|
||||||
|
_sha512 = baseFile.SHA512;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Cloning Methods
|
#region Cloning Methods
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ using Stream = System.IO.Stream;
|
|||||||
|
|
||||||
namespace SabreTools.Library.FileTypes
|
namespace SabreTools.Library.FileTypes
|
||||||
{
|
{
|
||||||
public abstract class BaseArchive : BaseFile
|
public abstract class BaseArchive : Folder
|
||||||
{
|
{
|
||||||
#region Protected instance variables
|
#region Protected instance variables
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="outDir">Output directory for archive extraction</param>
|
/// <param name="outDir">Output directory for archive extraction</param>
|
||||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||||
public abstract bool ExtractAll(string outDir);
|
public new abstract bool ExtractAll(string outDir);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempt to extract an entry from an archive
|
/// Attempt to extract an entry from an archive
|
||||||
@@ -56,7 +56,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||||
/// <param name="outDir">Output directory for archive extraction</param>
|
/// <param name="outDir">Output directory for archive extraction</param>
|
||||||
/// <returns>Name of the extracted file, null on error</returns>
|
/// <returns>Name of the extracted file, null on error</returns>
|
||||||
public abstract string ExtractEntry(string entryName, string outDir);
|
public new abstract string ExtractEntry(string entryName, string outDir);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempt to extract a stream from an archive
|
/// Attempt to extract a stream from an archive
|
||||||
@@ -64,7 +64,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||||
public abstract (MemoryStream, string) ExtractEntryStream(string entryName);
|
public new abstract (MemoryStream, string) ExtractEntryStream(string entryName);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -77,14 +77,14 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
||||||
/// <returns>List of DatItem objects representing the found data</returns>
|
/// <returns>List of DatItem objects representing the found data</returns>
|
||||||
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
||||||
public abstract List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false);
|
public new abstract List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate a list of empty folders in an archive
|
/// Generate a list of empty folders in an archive
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">Input file to get data from</param>
|
/// <param name="input">Input file to get data from</param>
|
||||||
/// <returns>List of empty folders in the archive</returns>
|
/// <returns>List of empty folders in the archive</returns>
|
||||||
public abstract List<string> GetEmptyFolders();
|
public new abstract List<string> GetEmptyFolders();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check whether the input file is a standardized format
|
/// Check whether the input file is a standardized format
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ using SabreTools.Library.Data;
|
|||||||
|
|
||||||
namespace SabreTools.Library.FileTypes
|
namespace SabreTools.Library.FileTypes
|
||||||
{
|
{
|
||||||
public abstract class BaseFile
|
public class BaseFile
|
||||||
{
|
{
|
||||||
#region Protected instance variables
|
#region Protected instance variables
|
||||||
|
|
||||||
protected FileType _fileType;
|
protected FileType _fileType;
|
||||||
protected string _filename;
|
protected string _filename;
|
||||||
protected List<BaseFile> _children;
|
protected string _parent;
|
||||||
|
protected string _date;
|
||||||
|
|
||||||
// External hash values for the file
|
// External hash values for the file
|
||||||
protected long? _size;
|
protected long? _size;
|
||||||
@@ -26,11 +27,25 @@ namespace SabreTools.Library.FileTypes
|
|||||||
#region Publicly facing variables
|
#region Publicly facing variables
|
||||||
|
|
||||||
// TODO: Get all of these values automatically so there is no public "set"
|
// TODO: Get all of these values automatically so there is no public "set"
|
||||||
|
public FileType Type
|
||||||
|
{
|
||||||
|
get { return _fileType; }
|
||||||
|
}
|
||||||
public string Filename
|
public string Filename
|
||||||
{
|
{
|
||||||
get { return _filename; }
|
get { return _filename; }
|
||||||
set { _filename = value; }
|
set { _filename = value; }
|
||||||
}
|
}
|
||||||
|
public string Parent
|
||||||
|
{
|
||||||
|
get { return _parent; }
|
||||||
|
set { _parent = value; }
|
||||||
|
}
|
||||||
|
public string Date
|
||||||
|
{
|
||||||
|
get { return _date; }
|
||||||
|
set { _date = value; }
|
||||||
|
}
|
||||||
public long? Size
|
public long? Size
|
||||||
{
|
{
|
||||||
get { return _size; }
|
get { return _size; }
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,14 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a folder for reading and writing
|
/// Represents a folder for reading and writing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Folder : BaseArchive
|
public class Folder : BaseFile
|
||||||
{
|
{
|
||||||
|
#region Protected instance variables
|
||||||
|
|
||||||
|
protected List<BaseFile> _children;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -60,7 +66,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="outDir">Output directory for archive extraction</param>
|
/// <param name="outDir">Output directory for archive extraction</param>
|
||||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||||
public override bool ExtractAll(string outDir)
|
public bool ExtractAll(string outDir)
|
||||||
{
|
{
|
||||||
// Copy all files from the current folder to the output directory recursively
|
// Copy all files from the current folder to the output directory recursively
|
||||||
try
|
try
|
||||||
@@ -86,7 +92,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||||
/// <param name="outDir">Output directory for archive extraction</param>
|
/// <param name="outDir">Output directory for archive extraction</param>
|
||||||
/// <returns>Name of the extracted file, null on error</returns>
|
/// <returns>Name of the extracted file, null on error</returns>
|
||||||
public override string ExtractEntry(string entryName, string outDir)
|
public string ExtractEntry(string entryName, string outDir)
|
||||||
{
|
{
|
||||||
string realentry = null;
|
string realentry = null;
|
||||||
|
|
||||||
@@ -125,7 +131,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||||
public override (MemoryStream, string) ExtractEntryStream(string entryName)
|
public (MemoryStream, string) ExtractEntryStream(string entryName)
|
||||||
{
|
{
|
||||||
MemoryStream ms = new MemoryStream();
|
MemoryStream ms = new MemoryStream();
|
||||||
string realentry = null;
|
string realentry = null;
|
||||||
@@ -163,33 +169,40 @@ namespace SabreTools.Library.FileTypes
|
|||||||
#region Information
|
#region Information
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate a list of DatItem objects from the header values in an archive
|
/// Generate a list of immediate children from the current folder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
|
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
|
||||||
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
||||||
/// <returns>List of DatItem objects representing the found data</returns>
|
/// <returns>List of BaseFile objects representing the found data</returns>
|
||||||
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
||||||
public override List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
public List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (_children == null || _children.Count == 0)
|
||||||
|
{
|
||||||
|
_children = new List<BaseFile>();
|
||||||
|
foreach (string file in Directory.EnumerateFiles(_filename, "*", SearchOption.TopDirectoryOnly))
|
||||||
|
{
|
||||||
|
BaseFile nf = Utilities.GetFileInfo(file, omitFromScan: omitFromScan, date: date);
|
||||||
|
_children.Add(nf);
|
||||||
|
}
|
||||||
|
foreach (string dir in Directory.EnumerateDirectories(_filename, "*", SearchOption.TopDirectoryOnly))
|
||||||
|
{
|
||||||
|
Folder fl = new Folder(dir);
|
||||||
|
_children.Add(fl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _children;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate a list of empty folders in an archive
|
/// Generate a list of empty folders in an archive
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">Input file to get data from</param>
|
/// <param name="input">Input file to get data from</param>
|
||||||
/// <returns>List of empty folders in the archive</returns>
|
/// <returns>List of empty folders in the folder</returns>
|
||||||
public override List<string> GetEmptyFolders()
|
public List<string> GetEmptyFolders()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return Utilities.GetEmptyDirectories(_filename).ToList();
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check whether the input file is a standardized format
|
|
||||||
/// </summary>
|
|
||||||
public override bool IsTorrent()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -206,7 +219,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
|
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
|
||||||
/// <returns>True if the write was a success, false otherwise</returns>
|
/// <returns>True if the write was a success, false otherwise</returns>
|
||||||
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
|
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
|
||||||
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool romba = false)
|
public bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool romba = false)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@@ -221,7 +234,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
|
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
|
||||||
/// <returns>True if the write was a success, false otherwise</returns>
|
/// <returns>True if the write was a success, false otherwise</returns>
|
||||||
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
|
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
|
||||||
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool romba = false)
|
public bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool romba = false)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
@@ -303,7 +316,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
|
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
|
||||||
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
|
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
|
||||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
|
public bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,54 +194,59 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
||||||
/// <returns>List of DatItem objects representing the found data</returns>
|
/// <returns>List of DatItem objects representing the found data</returns>
|
||||||
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
||||||
public override List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||||
{
|
{
|
||||||
List<Rom> found = new List<Rom>();
|
if (_children == null || _children.Count == 0)
|
||||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
|
||||||
|
|
||||||
Rom possibleTgz = GetTorrentGZFileInfo();
|
|
||||||
|
|
||||||
// If it was, then add it to the outputs and continue
|
|
||||||
if (possibleTgz != null && possibleTgz.Name != null)
|
|
||||||
{
|
{
|
||||||
found.Add(possibleTgz);
|
_children = new List<BaseFile>();
|
||||||
return found;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||||
{
|
|
||||||
// If secure hashes are disabled, do a quickscan
|
BaseFile possibleTgz = GetTorrentGZFileInfo();
|
||||||
if (omitFromScan == Hash.SecureHashes)
|
|
||||||
|
// If it was, then add it to the outputs and continue
|
||||||
|
if (possibleTgz != null && possibleTgz.Filename != null)
|
||||||
{
|
{
|
||||||
Rom tempRom = new Rom(gamename, gamename, omitFromScan);
|
_children.Add(possibleTgz);
|
||||||
BinaryReader br = new BinaryReader(Utilities.TryOpenRead(_filename));
|
|
||||||
br.BaseStream.Seek(-8, SeekOrigin.End);
|
|
||||||
byte[] headercrc = br.ReadBytesReverse(4);
|
|
||||||
tempRom.CRC = Utilities.ByteArrayToString(headercrc);
|
|
||||||
tempRom.Size = br.ReadInt32Reverse();
|
|
||||||
br.Dispose();
|
|
||||||
|
|
||||||
found.Add(tempRom);
|
|
||||||
}
|
}
|
||||||
// Otherwise, use the stream directly
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GZipStream gzstream = new GZipStream(Utilities.TryOpenRead(_filename), Ionic.Zlib.CompressionMode.Decompress);
|
try
|
||||||
Rom gzipEntryRom = (Rom)Utilities.GetStreamInfo(gzstream, gzstream.Length, omitFromScan: omitFromScan);
|
{
|
||||||
gzipEntryRom.Name = gzstream.FileName;
|
// If secure hashes are disabled, do a quickscan
|
||||||
gzipEntryRom.MachineName = gamename;
|
if (omitFromScan == Hash.SecureHashes)
|
||||||
gzipEntryRom.Date = (date && gzstream.LastModified != null ? gzstream.LastModified?.ToString("yyyy/MM/dd hh:mm:ss") : null);
|
{
|
||||||
found.Add(gzipEntryRom);
|
BaseFile tempRom = new BaseFile(gamename);
|
||||||
gzstream.Dispose();
|
BinaryReader br = new BinaryReader(Utilities.TryOpenRead(_filename));
|
||||||
|
br.BaseStream.Seek(-8, SeekOrigin.End);
|
||||||
|
byte[] headercrc = br.ReadBytesReverse(4);
|
||||||
|
tempRom.CRC = headercrc;
|
||||||
|
tempRom.Size = br.ReadInt32Reverse();
|
||||||
|
br.Dispose();
|
||||||
|
|
||||||
|
_children.Add(tempRom);
|
||||||
|
}
|
||||||
|
// Otherwise, use the stream directly
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GZipStream gzstream = new GZipStream(Utilities.TryOpenRead(_filename), Ionic.Zlib.CompressionMode.Decompress);
|
||||||
|
BaseFile gzipEntryRom = Utilities.GetStreamInfo(gzstream, gzstream.Length, omitFromScan: omitFromScan);
|
||||||
|
gzipEntryRom.Filename = gzstream.FileName;
|
||||||
|
gzipEntryRom.Parent = gamename;
|
||||||
|
gzipEntryRom.Date = (date && gzstream.LastModified != null ? gzstream.LastModified?.ToString("yyyy/MM/dd hh:mm:ss") : null);
|
||||||
|
_children.Add(gzipEntryRom);
|
||||||
|
gzstream.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// Don't log file open errors
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
// Don't log file open errors
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return found;
|
return _children;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -325,7 +330,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// Retrieve file information for a single torrent GZ file
|
/// Retrieve file information for a single torrent GZ file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Populated DatItem object if success, empty one on error</returns>
|
/// <returns>Populated DatItem object if success, empty one on error</returns>
|
||||||
public Rom GetTorrentGZFileInfo()
|
public BaseFile GetTorrentGZFileInfo()
|
||||||
{
|
{
|
||||||
// Check for the file existing first
|
// Check for the file existing first
|
||||||
if (!File.Exists(_filename))
|
if (!File.Exists(_filename))
|
||||||
@@ -386,23 +391,20 @@ namespace SabreTools.Library.FileTypes
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now convert the data and get the right position
|
// Now convert the data and get the right position
|
||||||
string gzmd5 = Utilities.ByteArrayToString(headermd5);
|
|
||||||
string gzcrc = Utilities.ByteArrayToString(headercrc);
|
|
||||||
long extractedsize = (long)headersz;
|
long extractedsize = (long)headersz;
|
||||||
|
|
||||||
Rom rom = new Rom
|
BaseFile baseFile = new BaseFile
|
||||||
{
|
{
|
||||||
Type = ItemType.Rom,
|
Filename = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(),
|
||||||
Name = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(),
|
|
||||||
Size = extractedsize,
|
Size = extractedsize,
|
||||||
CRC = gzcrc.ToLowerInvariant(),
|
CRC = headercrc,
|
||||||
MD5 = gzmd5.ToLowerInvariant(),
|
MD5 = headermd5,
|
||||||
SHA1 = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(), // TODO: When updating to SHA-256, this needs to update to SHA256
|
SHA1 = Utilities.StringToByteArray(Path.GetFileNameWithoutExtension(_filename)), // TODO: When updating to SHA-256, this needs to update to SHA256
|
||||||
|
|
||||||
MachineName = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(),
|
Parent = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(),
|
||||||
};
|
};
|
||||||
|
|
||||||
return rom;
|
return baseFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -461,7 +463,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
outDir = Path.GetFullPath(outDir);
|
outDir = Path.GetFullPath(outDir);
|
||||||
|
|
||||||
// Now get the Rom info for the file so we have hashes and size
|
// Now get the Rom info for the file so we have hashes and size
|
||||||
rom = (Rom)Utilities.GetStreamInfo(inputStream, inputStream.Length, keepReadOpen: true);
|
rom = new Rom(Utilities.GetStreamInfo(inputStream, inputStream.Length, keepReadOpen: true));
|
||||||
|
|
||||||
// Get the output file name
|
// Get the output file name
|
||||||
string outfile = null;
|
string outfile = null;
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
||||||
/// <returns>List of DatItem objects representing the found data</returns>
|
/// <returns>List of DatItem objects representing the found data</returns>
|
||||||
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
||||||
public override List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
||||||
/// <returns>List of DatItem objects representing the found data</returns>
|
/// <returns>List of DatItem objects representing the found data</returns>
|
||||||
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
||||||
public override List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,9 +187,9 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
||||||
/// <returns>List of DatItem objects representing the found data</returns>
|
/// <returns>List of DatItem objects representing the found data</returns>
|
||||||
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
||||||
public override List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||||
{
|
{
|
||||||
List<Rom> found = new List<Rom>();
|
List<BaseFile> found = new List<BaseFile>();
|
||||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -200,24 +200,23 @@ namespace SabreTools.Library.FileTypes
|
|||||||
// If secure hashes are disabled, do a quickscan
|
// If secure hashes are disabled, do a quickscan
|
||||||
if (omitFromScan == Hash.SecureHashes)
|
if (omitFromScan == Hash.SecureHashes)
|
||||||
{
|
{
|
||||||
found.Add(new Rom
|
found.Add(new BaseFile
|
||||||
{
|
{
|
||||||
Type = ItemType.Rom,
|
Filename = entry.Key,
|
||||||
Name = entry.Key,
|
|
||||||
Size = entry.Size,
|
Size = entry.Size,
|
||||||
CRC = entry.Crc.ToString("X").ToLowerInvariant(),
|
CRC = BitConverter.GetBytes(entry.Crc),
|
||||||
Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null),
|
Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null),
|
||||||
|
|
||||||
MachineName = gamename,
|
Parent = gamename,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Otherwise, use the stream directly
|
// Otherwise, use the stream directly
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Stream entryStream = entry.OpenEntryStream();
|
Stream entryStream = entry.OpenEntryStream();
|
||||||
Rom rarEntryRom = (Rom)Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
|
BaseFile rarEntryRom = Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
|
||||||
rarEntryRom.Name = entry.Key;
|
rarEntryRom.Filename = entry.Key;
|
||||||
rarEntryRom.MachineName = gamename;
|
rarEntryRom.Parent = gamename;
|
||||||
rarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
|
rarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
|
||||||
found.Add(rarEntryRom);
|
found.Add(rarEntryRom);
|
||||||
entryStream.Dispose();
|
entryStream.Dispose();
|
||||||
|
|||||||
@@ -191,9 +191,9 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
||||||
/// <returns>List of DatItem objects representing the found data</returns>
|
/// <returns>List of DatItem objects representing the found data</returns>
|
||||||
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
||||||
public override List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||||
{
|
{
|
||||||
List<Rom> found = new List<Rom>();
|
List<BaseFile> found = new List<BaseFile>();
|
||||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -204,24 +204,23 @@ namespace SabreTools.Library.FileTypes
|
|||||||
// If secure hashes are disabled, do a quickscan
|
// If secure hashes are disabled, do a quickscan
|
||||||
if (omitFromScan == Hash.SecureHashes)
|
if (omitFromScan == Hash.SecureHashes)
|
||||||
{
|
{
|
||||||
found.Add(new Rom
|
found.Add(new BaseFile
|
||||||
{
|
{
|
||||||
Type = ItemType.Rom,
|
Filename = entry.Key,
|
||||||
Name = entry.Key,
|
|
||||||
Size = entry.Size,
|
Size = entry.Size,
|
||||||
CRC = entry.Crc.ToString("X").ToLowerInvariant(),
|
CRC = BitConverter.GetBytes(entry.Crc),
|
||||||
Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null),
|
Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null),
|
||||||
|
|
||||||
MachineName = gamename,
|
Parent = gamename,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Otherwise, use the stream directly
|
// Otherwise, use the stream directly
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Stream entryStream = entry.OpenEntryStream();
|
Stream entryStream = entry.OpenEntryStream();
|
||||||
Rom sevenZipEntryRom = (Rom)Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
|
BaseFile sevenZipEntryRom = Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
|
||||||
sevenZipEntryRom.Name = entry.Key;
|
sevenZipEntryRom.Filename = entry.Key;
|
||||||
sevenZipEntryRom.MachineName = gamename;
|
sevenZipEntryRom.Parent = gamename;
|
||||||
sevenZipEntryRom.Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null);
|
sevenZipEntryRom.Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null);
|
||||||
found.Add(sevenZipEntryRom);
|
found.Add(sevenZipEntryRom);
|
||||||
entryStream.Dispose();
|
entryStream.Dispose();
|
||||||
|
|||||||
@@ -190,9 +190,9 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
||||||
/// <returns>List of DatItem objects representing the found data</returns>
|
/// <returns>List of DatItem objects representing the found data</returns>
|
||||||
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
||||||
public override List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||||
{
|
{
|
||||||
List<Rom> found = new List<Rom>();
|
List<BaseFile> found = new List<BaseFile>();
|
||||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -203,24 +203,23 @@ namespace SabreTools.Library.FileTypes
|
|||||||
// If secure hashes are disabled, do a quickscan
|
// If secure hashes are disabled, do a quickscan
|
||||||
if (omitFromScan == Hash.SecureHashes)
|
if (omitFromScan == Hash.SecureHashes)
|
||||||
{
|
{
|
||||||
found.Add(new Rom
|
found.Add(new BaseFile
|
||||||
{
|
{
|
||||||
Type = ItemType.Rom,
|
Filename = entry.Key,
|
||||||
Name = entry.Key,
|
|
||||||
Size = entry.Size,
|
Size = entry.Size,
|
||||||
CRC = entry.Crc.ToString("X").ToLowerInvariant(),
|
CRC = BitConverter.GetBytes(entry.Crc),
|
||||||
Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null),
|
Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null),
|
||||||
|
|
||||||
MachineName = gamename,
|
Parent = gamename,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Otherwise, use the stream directly
|
// Otherwise, use the stream directly
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Stream entryStream = entry.OpenEntryStream();
|
Stream entryStream = entry.OpenEntryStream();
|
||||||
Rom tarEntryRom = (Rom)Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
|
BaseFile tarEntryRom = Utilities.GetStreamInfo(entryStream, entry.Size, omitFromScan: omitFromScan);
|
||||||
tarEntryRom.Name = entry.Key;
|
tarEntryRom.Filename = entry.Key;
|
||||||
tarEntryRom.MachineName = gamename;
|
tarEntryRom.Parent = gamename;
|
||||||
tarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
|
tarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
|
||||||
found.Add(tarEntryRom);
|
found.Add(tarEntryRom);
|
||||||
entryStream.Dispose();
|
entryStream.Dispose();
|
||||||
|
|||||||
@@ -268,9 +268,9 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
||||||
/// <returns>List of DatItem objects representing the found data</returns>
|
/// <returns>List of DatItem objects representing the found data</returns>
|
||||||
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
||||||
public override List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||||
{
|
{
|
||||||
List<Rom> found = new List<Rom>();
|
List<BaseFile> found = new List<BaseFile>();
|
||||||
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
string gamename = Path.GetFileNameWithoutExtension(_filename);
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -300,26 +300,25 @@ namespace SabreTools.Library.FileTypes
|
|||||||
{
|
{
|
||||||
string newname = zf.Entries[i].FileName;
|
string newname = zf.Entries[i].FileName;
|
||||||
long newsize = (long)zf.Entries[i].UncompressedSize;
|
long newsize = (long)zf.Entries[i].UncompressedSize;
|
||||||
string newcrc = BitConverter.ToString(zf.Entries[i].CRC.Reverse().ToArray(), 0, zf.Entries[i].CRC.Length).Replace("-", string.Empty).ToLowerInvariant();
|
byte[] newcrc = zf.Entries[i].CRC.Reverse().ToArray();
|
||||||
string convertedDate = Utilities.ConvertMsDosTimeFormatToDateTime(zf.Entries[i].LastMod).ToString("yyyy/MM/dd hh:mm:ss");
|
string convertedDate = Utilities.ConvertMsDosTimeFormatToDateTime(zf.Entries[i].LastMod).ToString("yyyy/MM/dd hh:mm:ss");
|
||||||
|
|
||||||
found.Add(new Rom
|
found.Add(new BaseFile
|
||||||
{
|
{
|
||||||
Type = ItemType.Rom,
|
Filename = newname,
|
||||||
Name = newname,
|
|
||||||
Size = newsize,
|
Size = newsize,
|
||||||
CRC = newcrc,
|
CRC = newcrc,
|
||||||
Date = (date ? convertedDate : null),
|
Date = (date ? convertedDate : null),
|
||||||
|
|
||||||
MachineName = gamename,
|
Parent = gamename,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Otherwise, use the stream directly
|
// Otherwise, use the stream directly
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Rom zipEntryRom = (Rom)Utilities.GetStreamInfo(readStream, (long)zf.Entries[i].UncompressedSize, omitFromScan: omitFromScan);
|
BaseFile zipEntryRom = Utilities.GetStreamInfo(readStream, (long)zf.Entries[i].UncompressedSize, omitFromScan: omitFromScan);
|
||||||
zipEntryRom.Name = zf.Entries[i].FileName;
|
zipEntryRom.Filename = zf.Entries[i].FileName;
|
||||||
zipEntryRom.MachineName = gamename;
|
zipEntryRom.Parent = gamename;
|
||||||
string convertedDate = Utilities.ConvertMsDosTimeFormatToDateTime(zf.Entries[i].LastMod).ToString("yyyy/MM/dd hh:mm:ss");
|
string convertedDate = Utilities.ConvertMsDosTimeFormatToDateTime(zf.Entries[i].LastMod).ToString("yyyy/MM/dd hh:mm:ss");
|
||||||
zipEntryRom.Date = (date ? convertedDate : null);
|
zipEntryRom.Date = (date ? convertedDate : null);
|
||||||
found.Add(zipEntryRom);
|
found.Add(zipEntryRom);
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
||||||
/// <returns>List of DatItem objects representing the found data</returns>
|
/// <returns>List of DatItem objects representing the found data</returns>
|
||||||
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
||||||
public override List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
||||||
/// <returns>List of DatItem objects representing the found data</returns>
|
/// <returns>List of DatItem objects representing the found data</returns>
|
||||||
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
||||||
public override List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ namespace SabreTools.Library.FileTypes
|
|||||||
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
/// <param name="date">True if entry dates should be included, false otherwise (default)</param>
|
||||||
/// <returns>List of DatItem objects representing the found data</returns>
|
/// <returns>List of DatItem objects representing the found data</returns>
|
||||||
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
|
||||||
public override List<Rom> GetArchiveFileInfo(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -440,7 +440,7 @@ namespace SabreTools.Library.Tools
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">Name of the file to create the archive from</param>
|
/// <param name="input">Name of the file to create the archive from</param>
|
||||||
/// <returns>Archive object representing the inputs</returns>
|
/// <returns>Archive object representing the inputs</returns>
|
||||||
public static BaseArchive GetArchive(string input)
|
public static Folder GetArchive(string input)
|
||||||
{
|
{
|
||||||
BaseArchive archive = null;
|
BaseArchive archive = null;
|
||||||
|
|
||||||
@@ -485,7 +485,7 @@ namespace SabreTools.Library.Tools
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="archiveType">SharpCompress.Common.ArchiveType representing the archive to create</param>
|
/// <param name="archiveType">SharpCompress.Common.ArchiveType representing the archive to create</param>
|
||||||
/// <returns>Archive object representing the inputs</returns>
|
/// <returns>Archive object representing the inputs</returns>
|
||||||
public static BaseArchive GetArchive(FileType archiveType)
|
public static Folder GetArchive(FileType archiveType)
|
||||||
{
|
{
|
||||||
switch (archiveType)
|
switch (archiveType)
|
||||||
{
|
{
|
||||||
@@ -509,7 +509,7 @@ namespace SabreTools.Library.Tools
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="archiveType">SabreTools.Library.Data.SharpCompress.OutputFormat representing the archive to create</param>
|
/// <param name="archiveType">SabreTools.Library.Data.SharpCompress.OutputFormat representing the archive to create</param>
|
||||||
/// <returns>Archive object representing the inputs</returns>
|
/// <returns>Archive object representing the inputs</returns>
|
||||||
public static BaseArchive GetArchive(OutputFormat outputFormat)
|
public static Folder GetArchive(OutputFormat outputFormat)
|
||||||
{
|
{
|
||||||
switch (outputFormat)
|
switch (outputFormat)
|
||||||
{
|
{
|
||||||
@@ -1033,14 +1033,14 @@ namespace SabreTools.Library.Tools
|
|||||||
/// Get internal metadata from a CHD
|
/// Get internal metadata from a CHD
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">Filename of possible CHD</param>
|
/// <param name="input">Filename of possible CHD</param>
|
||||||
/// <returns>A Disk object with internal SHA-1 on success, null on error, empty Disk otherwise</returns>
|
/// <returns>A CHDFile object with internal SHA-1 on success, null otherwise</returns>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Original code had a "writable" param. This is not required for metadata checking
|
/// Original code had a "writable" param. This is not required for metadata checking
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static DatItem GetCHDInfo(string input)
|
public static BaseFile GetCHDInfo(string input)
|
||||||
{
|
{
|
||||||
FileStream fs = TryOpenRead(input);
|
FileStream fs = TryOpenRead(input);
|
||||||
DatItem datItem = GetCHDInfo(fs);
|
BaseFile datItem = GetCHDInfo(fs);
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
return datItem;
|
return datItem;
|
||||||
}
|
}
|
||||||
@@ -1217,18 +1217,18 @@ namespace SabreTools.Library.Tools
|
|||||||
/// <param name="date">True if the file Date should be included, false otherwise (default)</param>
|
/// <param name="date">True if the file Date should be included, false otherwise (default)</param>
|
||||||
/// <param name="header">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param>
|
/// <param name="header">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param>
|
||||||
/// <param name="chdsAsFiles">True if CHDs should be treated like regular files, false otherwise</param>
|
/// <param name="chdsAsFiles">True if CHDs should be treated like regular files, false otherwise</param>
|
||||||
/// <returns>Populated DatItem object if success, empty one on error</returns>
|
/// <returns>Populated BaseFile object if success, empty one on error</returns>
|
||||||
public static DatItem GetFileInfo(string input, Hash omitFromScan = 0x0,
|
public static BaseFile GetFileInfo(string input, Hash omitFromScan = 0x0,
|
||||||
long offset = 0, bool date = false, string header = null, bool chdsAsFiles = true)
|
long offset = 0, bool date = false, string header = null, bool chdsAsFiles = true)
|
||||||
{
|
{
|
||||||
// Add safeguard if file doesn't exist
|
// Add safeguard if file doesn't exist
|
||||||
if (!File.Exists(input))
|
if (!File.Exists(input))
|
||||||
{
|
{
|
||||||
return new Rom();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the information from the file stream
|
// Get the information from the file stream
|
||||||
DatItem datItem = new Rom();
|
BaseFile baseFile = new BaseFile();
|
||||||
if (header != null)
|
if (header != null)
|
||||||
{
|
{
|
||||||
SkipperRule rule = Skipper.GetMatchingRule(input, Path.GetFileNameWithoutExtension(header));
|
SkipperRule rule = Skipper.GetMatchingRule(input, Path.GetFileNameWithoutExtension(header));
|
||||||
@@ -1242,7 +1242,7 @@ namespace SabreTools.Library.Tools
|
|||||||
|
|
||||||
// Transform the stream and get the information from it
|
// Transform the stream and get the information from it
|
||||||
rule.TransformStream(inputStream, outputStream, keepReadOpen: false, keepWriteOpen: true);
|
rule.TransformStream(inputStream, outputStream, keepReadOpen: false, keepWriteOpen: true);
|
||||||
datItem = GetStreamInfo(outputStream, outputStream.Length, omitFromScan: omitFromScan, keepReadOpen: false, chdsAsFiles: chdsAsFiles);
|
baseFile = GetStreamInfo(outputStream, outputStream.Length, omitFromScan: omitFromScan, keepReadOpen: false, chdsAsFiles: chdsAsFiles);
|
||||||
|
|
||||||
// Dispose of the streams
|
// Dispose of the streams
|
||||||
outputStream.Dispose();
|
outputStream.Dispose();
|
||||||
@@ -1252,23 +1252,20 @@ namespace SabreTools.Library.Tools
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
long length = new FileInfo(input).Length;
|
long length = new FileInfo(input).Length;
|
||||||
datItem = GetStreamInfo(TryOpenRead(input), length, omitFromScan, offset, keepReadOpen: false, chdsAsFiles: chdsAsFiles);
|
baseFile = GetStreamInfo(TryOpenRead(input), length, omitFromScan, offset, keepReadOpen: false, chdsAsFiles: chdsAsFiles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
long length = new FileInfo(input).Length;
|
long length = new FileInfo(input).Length;
|
||||||
datItem = GetStreamInfo(TryOpenRead(input), length, omitFromScan, offset, keepReadOpen: false, chdsAsFiles: chdsAsFiles);
|
baseFile = GetStreamInfo(TryOpenRead(input), length, omitFromScan, offset, keepReadOpen: false, chdsAsFiles: chdsAsFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add unique data from the file
|
// Add unique data from the file
|
||||||
datItem.Name = Path.GetFileName(input);
|
baseFile.Filename = Path.GetFileName(input);
|
||||||
if (datItem.Type == ItemType.Rom)
|
baseFile.Date = (date ? new FileInfo(input).LastWriteTime.ToString("yyyy/MM/dd HH:mm:ss") : "");
|
||||||
{
|
|
||||||
((Rom)datItem).Date = (date ? new FileInfo(input).LastWriteTime.ToString("yyyy/MM/dd HH:mm:ss") : "");
|
|
||||||
}
|
|
||||||
|
|
||||||
return datItem;
|
return baseFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1394,10 +1391,10 @@ namespace SabreTools.Library.Tools
|
|||||||
/// <returns>True if the file is a valid CHD, false otherwise</returns>
|
/// <returns>True if the file is a valid CHD, false otherwise</returns>
|
||||||
public static bool IsValidCHD(string input)
|
public static bool IsValidCHD(string input)
|
||||||
{
|
{
|
||||||
DatItem datItem = GetCHDInfo(input);
|
BaseFile baseFile = GetCHDInfo(input);
|
||||||
return datItem != null
|
return baseFile != null
|
||||||
&& datItem.Type == ItemType.Disk
|
&& (((CHDFile)baseFile).MD5 != null
|
||||||
&& ((Disk)datItem).SHA1 != null;
|
|| ((CHDFile)baseFile).SHA1 != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1563,8 +1560,8 @@ namespace SabreTools.Library.Tools
|
|||||||
// Now add the information to the database if it's not already there
|
// Now add the information to the database if it's not already there
|
||||||
if (!nostore)
|
if (!nostore)
|
||||||
{
|
{
|
||||||
Rom rom = (Rom)GetFileInfo(newfile, chdsAsFiles: true);
|
BaseFile baseFile = GetFileInfo(newfile, chdsAsFiles: true);
|
||||||
DatabaseTools.AddHeaderToDatabase(hstr, rom.SHA1, rule.SourceFile);
|
DatabaseTools.AddHeaderToDatabase(hstr, ByteArrayToString(baseFile.SHA1), rule.SourceFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -1698,10 +1695,10 @@ namespace SabreTools.Library.Tools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// First, get the SHA-1 hash of the file
|
// First, get the SHA-1 hash of the file
|
||||||
Rom rom = (Rom)GetFileInfo(file, chdsAsFiles: true);
|
BaseFile baseFile = GetFileInfo(file, chdsAsFiles: true);
|
||||||
|
|
||||||
// Retrieve a list of all related headers from the database
|
// Retrieve a list of all related headers from the database
|
||||||
List<string> headers = DatabaseTools.RetrieveHeadersFromDatabase(rom.SHA1);
|
List<string> headers = DatabaseTools.RetrieveHeadersFromDatabase(ByteArrayToString(baseFile.SHA1));
|
||||||
|
|
||||||
// If we have nothing retrieved, we return false
|
// If we have nothing retrieved, we return false
|
||||||
if (headers.Count == 0)
|
if (headers.Count == 0)
|
||||||
@@ -1923,8 +1920,8 @@ namespace SabreTools.Library.Tools
|
|||||||
/// <param name="offset">Set a >0 number for getting hash for part of the file, 0 otherwise (default)</param>
|
/// <param name="offset">Set a >0 number for getting hash for part of the file, 0 otherwise (default)</param>
|
||||||
/// <param name="keepReadOpen">True if the underlying read stream should be kept open, false otherwise</param>
|
/// <param name="keepReadOpen">True if the underlying read stream should be kept open, false otherwise</param>
|
||||||
/// <param name="chdsAsFiles">True if CHDs should be treated like regular files, false otherwise</param>
|
/// <param name="chdsAsFiles">True if CHDs should be treated like regular files, false otherwise</param>
|
||||||
/// <returns>Populated DatItem object if success, empty one on error</returns>
|
/// <returns>Populated BaseFile object if success, empty one on error</returns>
|
||||||
public static DatItem GetStreamInfo(Stream input, long size, Hash omitFromScan = 0x0,
|
public static BaseFile GetStreamInfo(Stream input, long size, Hash omitFromScan = 0x0,
|
||||||
long offset = 0, bool keepReadOpen = false, bool chdsAsFiles = true)
|
long offset = 0, bool keepReadOpen = false, bool chdsAsFiles = true)
|
||||||
{
|
{
|
||||||
// We first check to see if it's a CHD
|
// We first check to see if it's a CHD
|
||||||
@@ -1956,7 +1953,7 @@ namespace SabreTools.Library.Tools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the Disk from the information
|
// Get the Disk from the information
|
||||||
DatItem disk = GetCHDInfo(input);
|
BaseFile disk = GetCHDInfo(input);
|
||||||
|
|
||||||
// Seek to the beginning of the stream if possible
|
// Seek to the beginning of the stream if possible
|
||||||
try
|
try
|
||||||
@@ -1980,16 +1977,9 @@ namespace SabreTools.Library.Tools
|
|||||||
return disk;
|
return disk;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rom rom = new Rom
|
BaseFile rom = new BaseFile()
|
||||||
{
|
{
|
||||||
Type = ItemType.Rom,
|
|
||||||
Size = size,
|
Size = size,
|
||||||
CRC = string.Empty,
|
|
||||||
MD5 = string.Empty,
|
|
||||||
SHA1 = string.Empty,
|
|
||||||
SHA256 = string.Empty,
|
|
||||||
SHA384 = string.Empty,
|
|
||||||
SHA512 = string.Empty,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -2061,32 +2051,32 @@ namespace SabreTools.Library.Tools
|
|||||||
}
|
}
|
||||||
|
|
||||||
crc.Update(buffer, 0, 0);
|
crc.Update(buffer, 0, 0);
|
||||||
rom.CRC = crc.Value.ToString("X8").ToLowerInvariant();
|
rom.CRC = BitConverter.GetBytes(crc.Value);
|
||||||
|
|
||||||
if ((omitFromScan & Hash.MD5) == 0)
|
if ((omitFromScan & Hash.MD5) == 0)
|
||||||
{
|
{
|
||||||
md5.TransformFinalBlock(buffer, 0, 0);
|
md5.TransformFinalBlock(buffer, 0, 0);
|
||||||
rom.MD5 = ByteArrayToString(md5.Hash);
|
rom.MD5 = md5.Hash;
|
||||||
}
|
}
|
||||||
if ((omitFromScan & Hash.SHA1) == 0)
|
if ((omitFromScan & Hash.SHA1) == 0)
|
||||||
{
|
{
|
||||||
sha1.TransformFinalBlock(buffer, 0, 0);
|
sha1.TransformFinalBlock(buffer, 0, 0);
|
||||||
rom.SHA1 = ByteArrayToString(sha1.Hash);
|
rom.SHA1 = sha1.Hash;
|
||||||
}
|
}
|
||||||
if ((omitFromScan & Hash.SHA256) == 0)
|
if ((omitFromScan & Hash.SHA256) == 0)
|
||||||
{
|
{
|
||||||
sha256.TransformFinalBlock(buffer, 0, 0);
|
sha256.TransformFinalBlock(buffer, 0, 0);
|
||||||
rom.SHA256 = ByteArrayToString(sha256.Hash);
|
rom.SHA256 = sha256.Hash;
|
||||||
}
|
}
|
||||||
if ((omitFromScan & Hash.SHA384) == 0)
|
if ((omitFromScan & Hash.SHA384) == 0)
|
||||||
{
|
{
|
||||||
sha384.TransformFinalBlock(buffer, 0, 0);
|
sha384.TransformFinalBlock(buffer, 0, 0);
|
||||||
rom.SHA384 = ByteArrayToString(sha384.Hash);
|
rom.SHA384 = sha384.Hash;
|
||||||
}
|
}
|
||||||
if ((omitFromScan & Hash.SHA512) == 0)
|
if ((omitFromScan & Hash.SHA512) == 0)
|
||||||
{
|
{
|
||||||
sha512.TransformFinalBlock(buffer, 0, 0);
|
sha512.TransformFinalBlock(buffer, 0, 0);
|
||||||
rom.SHA512 = ByteArrayToString(sha512.Hash);
|
rom.SHA512 = sha512.Hash;
|
||||||
}
|
}
|
||||||
if ((omitFromScan & Hash.xxHash) == 0)
|
if ((omitFromScan & Hash.xxHash) == 0)
|
||||||
{
|
{
|
||||||
@@ -2103,7 +2093,7 @@ namespace SabreTools.Library.Tools
|
|||||||
}
|
}
|
||||||
catch (IOException)
|
catch (IOException)
|
||||||
{
|
{
|
||||||
return new Rom();
|
return new BaseFile();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -2134,32 +2124,31 @@ namespace SabreTools.Library.Tools
|
|||||||
/// Get internal metadata from a CHD
|
/// Get internal metadata from a CHD
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">Stream of possible CHD</param>
|
/// <param name="input">Stream of possible CHD</param>
|
||||||
/// <returns>A Disk object with internal SHA-1 on success, null on error, empty Disk otherwise</returns>
|
/// <returns>A CHDFile object with internal MD5 (v1, v2) or SHA-1 (v3, v4, v5) on success, null otherwise</returns>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Original code had a "writable" param. This is not required for metadata checking
|
/// Original code had a "writable" param. This is not required for metadata checking
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static DatItem GetCHDInfo(Stream input)
|
public static BaseFile GetCHDInfo(Stream input)
|
||||||
{
|
{
|
||||||
// Create a blank Disk to populate and return
|
|
||||||
Disk datItem = new Disk();
|
|
||||||
|
|
||||||
// Get a CHD object to store the data
|
// Get a CHD object to store the data
|
||||||
CHDFile chd = new CHDFile(input);
|
CHDFile chd = new CHDFile(input);
|
||||||
|
|
||||||
// Get the best possible hash from the chd
|
// Ensure that the header is valid
|
||||||
byte[] hash = chd.GetHashFromHeader();
|
byte[] hash = chd.GetHashFromHeader();
|
||||||
|
|
||||||
// Set the proper hash of the Disk to return
|
// Set the proper hash of the Disk to return
|
||||||
if (hash.Length == Constants.MD5Length)
|
if (hash.Length == Constants.MD5Length)
|
||||||
{
|
{
|
||||||
datItem.MD5 = (hash == null ? null : ByteArrayToString(hash));
|
chd.MD5 = hash;
|
||||||
|
return chd;
|
||||||
}
|
}
|
||||||
else if (hash.Length == Constants.SHA1Length)
|
else if (hash.Length == Constants.SHA1Length)
|
||||||
{
|
{
|
||||||
datItem.SHA1 = (hash == null ? null : ByteArrayToString(hash));
|
chd.SHA1 = hash;
|
||||||
|
return chd;
|
||||||
}
|
}
|
||||||
|
|
||||||
return datItem;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -2185,10 +2174,10 @@ namespace SabreTools.Library.Tools
|
|||||||
/// <returns>True if the stream is a valid CHD, false otherwise</returns>
|
/// <returns>True if the stream is a valid CHD, false otherwise</returns>
|
||||||
public static bool IsValidCHD(Stream input)
|
public static bool IsValidCHD(Stream input)
|
||||||
{
|
{
|
||||||
DatItem datItem = GetCHDInfo(input);
|
BaseFile baseFile = GetCHDInfo(input);
|
||||||
return datItem != null
|
return baseFile != null
|
||||||
&& datItem.Type == ItemType.Disk
|
&& (((CHDFile)baseFile).MD5 != null
|
||||||
&& ((Disk)datItem).SHA1 != null;
|
|| ((CHDFile)baseFile).SHA1 != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user