[DatFile] Tweaks to DFD

This commit is contained in:
Matt Nadareski
2018-02-23 16:56:15 -08:00
parent 1340847047
commit abcafff384

View File

@@ -3566,8 +3566,8 @@ namespace SabreTools.Library.DatFiles
// Special case for if we are in Romba mode (all names are supposed to be SHA-1 hashes) // Special case for if we are in Romba mode (all names are supposed to be SHA-1 hashes)
if (Romba) if (Romba)
{ {
GZipArchive archive = new GZipArchive(item); GZipArchive gzarc = new GZipArchive(item);
BaseFile baseFile = archive.GetTorrentGZFileInfo(); BaseFile baseFile = gzarc.GetTorrentGZFileInfo();
// If the rom is valid, write it out // If the rom is valid, write it out
if (baseFile != null && baseFile.Filename != null) if (baseFile != null && baseFile.Filename != null)
@@ -3597,21 +3597,15 @@ namespace SabreTools.Library.DatFiles
File.Copy(item, newItem, true); File.Copy(item, newItem, true);
} }
// Create a list for all found items // Initialize possible archive variables
BaseArchive archive = Utilities.GetArchive(newItem);
List<BaseFile> extracted = null; List<BaseFile> extracted = null;
// If we don't have archives as files, try to scan the file as an archive // If we have an archive and we're supposed to scan it
if (!archivesAsFiles) if (archive != null && !archivesAsFiles)
{
// Get the base archive first
Folder archive = Utilities.GetArchive(newItem);
// Now get all extracted items from the archive
if (archive != null)
{ {
extracted = archive.GetChildren(omitFromScan: omitFromScan, date: addDate); extracted = archive.GetChildren(omitFromScan: omitFromScan, date: addDate);
} }
}
// If the file should be skipped based on type, do so now // If the file should be skipped based on type, do so now
if ((extracted != null && skipFileType == SkipFileType.Archive) if ((extracted != null && skipFileType == SkipFileType.Archive)
@@ -3643,9 +3637,6 @@ namespace SabreTools.Library.DatFiles
{ {
List<string> empties = new List<string>(); List<string> empties = new List<string>();
// Get the base archive first
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)
{ {
@@ -3686,17 +3677,7 @@ namespace SabreTools.Library.DatFiles
{ {
Globals.Logger.Verbose("'{0}' treated like a file", Path.GetFileName(item)); Globals.Logger.Verbose("'{0}' treated like a file", Path.GetFileName(item));
BaseFile baseFile = 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; ProcessFileHelper(item, Utilities.GetDatItem(baseFile), basePath, parent);
if (baseFile.Type == FileType.CHD)
{
datItem = new Disk(baseFile);
}
else if (baseFile.Type == FileType.None)
{
datItem = new Rom(baseFile);
}
ProcessFileHelper(item, datItem, basePath, parent);
} }
/// <summary> /// <summary>
@@ -3708,25 +3689,12 @@ namespace SabreTools.Library.DatFiles
/// <param name="parent">Parent game to be used</param> /// <param name="parent">Parent game to be used</param>
private void ProcessFileHelper(string item, DatItem datItem, string basepath, string parent) private void ProcessFileHelper(string item, DatItem datItem, string basepath, string parent)
{ {
// If the datItem isn't a Rom or Disk, return // If we somehow got something other than a Rom or Disk, cancel out
if (datItem.Type != ItemType.Rom && datItem.Type != ItemType.Disk) if (datItem.Type != ItemType.Rom && datItem.Type != ItemType.Disk)
{ {
return; return;
} }
string key = "";
if (datItem.Type == ItemType.Rom)
{
key = ((Rom)datItem).Size + "-" + ((Rom)datItem).CRC;
}
else if (datItem.Type == ItemType.Disk)
{
key = ((Disk)datItem).SHA1;
}
// Add the list if it doesn't exist already
Add(key);
try try
{ {
// If the basepath ends with a directory separator, remove it // If the basepath ends with a directory separator, remove it
@@ -3738,6 +3706,31 @@ namespace SabreTools.Library.DatFiles
// Make sure we have the full item path // Make sure we have the full item path
item = Path.GetFullPath(item); item = Path.GetFullPath(item);
// Process the item to sanitize names based on input
SetDatItemInfo(datItem, item, parent, basepath);
// Add the file information to the DAT
string key = Utilities.GetKeyFromDatItem(datItem, SortedBy.CRC);
Add(key, datItem);
Globals.Logger.User("File added: {0}", datItem.Name + Environment.NewLine);
}
catch (IOException ex)
{
Globals.Logger.Error(ex.ToString());
return;
}
}
/// <summary>
/// Set proper Game and Rom names from user inputs
/// </summary>
/// <param name="datItem">DatItem representing the input file</param>
/// <param name="item">Item name to use</param>
/// <param name="parent">Parent name to use</param>
/// <param name="basepath">Base path to use</param>
private void SetDatItemInfo(DatItem datItem, string item, string parent, string basepath)
{
// Get the data to be added as game and item names // Get the data to be added as game and item names
string gamename = ""; string gamename = "";
string romname = ""; string romname = "";
@@ -3815,17 +3808,6 @@ namespace SabreTools.Library.DatFiles
{ {
datItem.Name = datItem.Name.Replace(".chd", ""); datItem.Name = datItem.Name.Replace(".chd", "");
} }
// Add the file information to the DAT
Add(key, datItem);
Globals.Logger.User("File added: {0}", romname + Environment.NewLine);
}
catch (IOException ex)
{
Globals.Logger.Error(ex.ToString());
return;
}
} }
#endregion #endregion
@@ -4201,7 +4183,7 @@ namespace SabreTools.Library.DatFiles
bool isTorrentGzip = tgz.IsTorrent(); bool isTorrentGzip = tgz.IsTorrent();
// Get the base archive first // Get the base archive first
Folder archive = Utilities.GetArchive(file); BaseArchive 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)
@@ -4343,7 +4325,7 @@ namespace SabreTools.Library.DatFiles
if (isZip != null) if (isZip != null)
{ {
string realName = null; string realName = null;
Folder archive = Utilities.GetArchive(file); BaseArchive archive = Utilities.GetArchive(file);
if (archive != null) if (archive != null)
{ {
(fileStream, realName) = archive.CopyToStream(datItem.Name); (fileStream, realName) = archive.CopyToStream(datItem.Name);
@@ -4427,7 +4409,7 @@ namespace SabreTools.Library.DatFiles
if (isZip != null) if (isZip != null)
{ {
string realName = null; string realName = null;
Folder archive = Utilities.GetArchive(file); BaseArchive archive = Utilities.GetArchive(file);
if (archive != null) if (archive != null)
{ {
(fileStream, realName) = archive.CopyToStream(datItem.Name); (fileStream, realName) = archive.CopyToStream(datItem.Name);
@@ -4517,7 +4499,7 @@ namespace SabreTools.Library.DatFiles
if (isZip != null) if (isZip != null)
{ {
string realName = null; string realName = null;
Folder archive = Utilities.GetArchive(file); BaseArchive archive = Utilities.GetArchive(file);
if (archive != null) if (archive != null)
{ {
(fileStream, realName) = archive.CopyToStream(datItem.Name); (fileStream, realName) = archive.CopyToStream(datItem.Name);