mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] Tweaks to DFD
This commit is contained in:
@@ -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)
|
||||
if (Romba)
|
||||
{
|
||||
GZipArchive archive = new GZipArchive(item);
|
||||
BaseFile baseFile = archive.GetTorrentGZFileInfo();
|
||||
GZipArchive gzarc = new GZipArchive(item);
|
||||
BaseFile baseFile = gzarc.GetTorrentGZFileInfo();
|
||||
|
||||
// If the rom is valid, write it out
|
||||
if (baseFile != null && baseFile.Filename != null)
|
||||
@@ -3597,21 +3597,15 @@ namespace SabreTools.Library.DatFiles
|
||||
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;
|
||||
|
||||
// If we don't have archives as files, try to scan the file as an archive
|
||||
if (!archivesAsFiles)
|
||||
{
|
||||
// Get the base archive first
|
||||
Folder archive = Utilities.GetArchive(newItem);
|
||||
|
||||
// Now get all extracted items from the archive
|
||||
if (archive != null)
|
||||
// If we have an archive and we're supposed to scan it
|
||||
if (archive != null && !archivesAsFiles)
|
||||
{
|
||||
extracted = archive.GetChildren(omitFromScan: omitFromScan, date: addDate);
|
||||
}
|
||||
}
|
||||
|
||||
// If the file should be skipped based on type, do so now
|
||||
if ((extracted != null && skipFileType == SkipFileType.Archive)
|
||||
@@ -3643,9 +3637,6 @@ namespace SabreTools.Library.DatFiles
|
||||
{
|
||||
List<string> empties = new List<string>();
|
||||
|
||||
// Get the base archive first
|
||||
Folder archive = Utilities.GetArchive(newItem);
|
||||
|
||||
// Now get all blank folders from the archive
|
||||
if (archive != null)
|
||||
{
|
||||
@@ -3686,17 +3677,7 @@ namespace SabreTools.Library.DatFiles
|
||||
{
|
||||
Globals.Logger.Verbose("'{0}' treated like a file", Path.GetFileName(item));
|
||||
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, Utilities.GetDatItem(baseFile), basePath, parent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -3708,25 +3689,12 @@ namespace SabreTools.Library.DatFiles
|
||||
/// <param name="parent">Parent game to be used</param>
|
||||
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)
|
||||
{
|
||||
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
|
||||
{
|
||||
// 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
|
||||
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
|
||||
string gamename = "";
|
||||
string romname = "";
|
||||
@@ -3815,17 +3808,6 @@ namespace SabreTools.Library.DatFiles
|
||||
{
|
||||
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
|
||||
@@ -4201,7 +4183,7 @@ namespace SabreTools.Library.DatFiles
|
||||
bool isTorrentGzip = tgz.IsTorrent();
|
||||
|
||||
// Get the base archive first
|
||||
Folder archive = Utilities.GetArchive(file);
|
||||
BaseArchive archive = Utilities.GetArchive(file);
|
||||
|
||||
// Now get all extracted items from the archive
|
||||
if (archive != null)
|
||||
@@ -4343,7 +4325,7 @@ namespace SabreTools.Library.DatFiles
|
||||
if (isZip != null)
|
||||
{
|
||||
string realName = null;
|
||||
Folder archive = Utilities.GetArchive(file);
|
||||
BaseArchive archive = Utilities.GetArchive(file);
|
||||
if (archive != null)
|
||||
{
|
||||
(fileStream, realName) = archive.CopyToStream(datItem.Name);
|
||||
@@ -4427,7 +4409,7 @@ namespace SabreTools.Library.DatFiles
|
||||
if (isZip != null)
|
||||
{
|
||||
string realName = null;
|
||||
Folder archive = Utilities.GetArchive(file);
|
||||
BaseArchive archive = Utilities.GetArchive(file);
|
||||
if (archive != null)
|
||||
{
|
||||
(fileStream, realName) = archive.CopyToStream(datItem.Name);
|
||||
@@ -4517,7 +4499,7 @@ namespace SabreTools.Library.DatFiles
|
||||
if (isZip != null)
|
||||
{
|
||||
string realName = null;
|
||||
Folder archive = Utilities.GetArchive(file);
|
||||
BaseArchive archive = Utilities.GetArchive(file);
|
||||
if (archive != null)
|
||||
{
|
||||
(fileStream, realName) = archive.CopyToStream(datItem.Name);
|
||||
|
||||
Reference in New Issue
Block a user