[DatFile] Enable blank folders in archives (not quickscan)

This commit is contained in:
Matt Nadareski
2017-03-14 15:18:07 -07:00
parent eaa20e91d6
commit 0f210cd237
4 changed files with 92 additions and 19 deletions

View File

@@ -272,6 +272,63 @@ namespace SabreTools.Helper.Dats
addDate, addDate,
headerToCheckAgainst); headerToCheckAgainst);
}); });
// Now find all folders that are empty, if we are supposed to
if (addBlanks)
{
// Get the list of empty directories
List<string> empties = Directory
.EnumerateDirectories(tempSubDir, "*", SearchOption.AllDirectories)
.Where(dir => Directory.EnumerateFiles(dir, "*", SearchOption.TopDirectoryOnly).Count() == 0)
.ToList();
Parallel.ForEach(empties,
new ParallelOptions { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
dir =>
{
// Get the full path for the directory
string fulldir = Path.GetFullPath(dir);
// Set the temporary variables
string gamename = "";
string romname = "";
// If we have a SuperDAT, we want anything that's not the base path as the game, and the file as the rom
if (Type == "SuperDAT")
{
gamename = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(item)).Remove(0, basePath.Length), Path.GetFileNameWithoutExtension(item));
romname = Path.Combine(fulldir.Remove(0, tempSubDir.Length), "-");
}
// Otherwise, we want just the item as the game, and the file as everything else
else
{
gamename = Path.GetFileNameWithoutExtension(item);
romname = Path.Combine(fulldir.Remove(0, tempSubDir.Length), "-");
}
// Sanitize the names
if (gamename.StartsWith(Path.DirectorySeparatorChar.ToString()))
{
gamename = gamename.Substring(1);
}
if (gamename.EndsWith(Path.DirectorySeparatorChar.ToString()))
{
gamename = gamename.Substring(0, gamename.Length - 1);
}
if (romname.StartsWith(Path.DirectorySeparatorChar.ToString()))
{
romname = romname.Substring(1);
}
if (romname.EndsWith(Path.DirectorySeparatorChar.ToString()))
{
romname = romname.Substring(0, romname.Length - 1);
}
Globals.Logger.Verbose("Adding blank empty folder: " + gamename);
this["null"].Add(new Rom(romname, gamename, omitFromScan));
});
}
} }
// Otherwise, just get the info on the file itself // Otherwise, just get the info on the file itself
else if (File.Exists(newItem)) else if (File.Exists(newItem))

View File

@@ -190,11 +190,7 @@ namespace SabreTools.Helper.Dats
if (rom.Type == ItemType.Rom if (rom.Type == ItemType.Rom
&& ((Rom)rom).Size == -1 && ((Rom)rom).Size == -1
&& ((Rom)rom).CRC == "null" && ((Rom)rom).CRC == "null"
&& ((Rom)rom).MD5 == "null" && ((Rom)rom).MD5 == "null")
&& ((Rom)rom).SHA1 == "null"
&& ((Rom)rom).SHA256 == "null"
&& ((Rom)rom).SHA384 == "null"
&& ((Rom)rom).SHA512 == "null")
{ {
Globals.Logger.Verbose("Empty folder found: " + rom.Machine.Name); Globals.Logger.Verbose("Empty folder found: " + rom.Machine.Name);
@@ -206,12 +202,12 @@ namespace SabreTools.Helper.Dats
{ {
rom.Name = (rom.Name == "null" ? "-" : rom.Name); rom.Name = (rom.Name == "null" ? "-" : rom.Name);
((Rom)rom).Size = Constants.SizeZero; ((Rom)rom).Size = Constants.SizeZero;
((Rom)rom).CRC = Constants.CRCZero; ((Rom)rom).CRC = ((Rom)rom).CRC == "null" ? Constants.CRCZero : null;
((Rom)rom).MD5 = Constants.MD5Zero; ((Rom)rom).MD5 = ((Rom)rom).MD5 == "null" ? Constants.MD5Zero : null;
((Rom)rom).SHA1 = Constants.SHA1Zero; ((Rom)rom).SHA1 = ((Rom)rom).SHA1 == "null" ? Constants.SHA1Zero : null;
((Rom)rom).SHA256 = Constants.SHA256Zero; ((Rom)rom).SHA256 = ((Rom)rom).SHA256 == "null" ? Constants.SHA256Zero : null;
((Rom)rom).SHA384 = Constants.SHA384Zero; ((Rom)rom).SHA384 = ((Rom)rom).SHA384 == "null" ? Constants.SHA384Zero : null;
((Rom)rom).SHA512 = Constants.SHA512Zero; ((Rom)rom).SHA512 = ((Rom)rom).SHA512 == "null" ? Constants.SHA512Zero : null;
} }
// Otherwise, set the new path and such, write out, and continue // Otherwise, set the new path and such, write out, and continue

View File

@@ -55,17 +55,37 @@ namespace SabreTools.Helper.Dats
/// </summary> /// </summary>
/// <param name="name"></param> /// <param name="name"></param>
/// <param name="machineName"></param> /// <param name="machineName"></param>
public Rom(string name, string machineName) /// <param name="omitFromScan"></param>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public Rom(string name, string machineName, Hash omitFromScan = Hash.DeepHashes)
{ {
_name = name; _name = name;
_itemType = ItemType.Rom; _itemType = ItemType.Rom;
_size = -1; _size = -1;
_crc = "null"; if ((omitFromScan & Hash.CRC) == 0)
_md5 = "null"; {
_sha1 = "null"; _crc = "null";
_sha256 = "null"; }
_sha384 = "null"; if ((omitFromScan & Hash.MD5) == 0)
_sha512 = "null"; {
_md5 = "null";
}
if ((omitFromScan & Hash.SHA1) == 0)
{
_sha1 = "null";
}
if ((omitFromScan & Hash.SHA256) == 0)
{
_sha256 = "null";
}
if ((omitFromScan & Hash.SHA384) == 0)
{
_sha384 = "null";
}
if ((omitFromScan & Hash.SHA512) == 0)
{
_sha512 = "null";
}
_itemStatus = ItemStatus.None; _itemStatus = ItemStatus.None;
_machine = new Machine _machine = new Machine

View File

@@ -38,7 +38,7 @@ namespace SabreTools.Helper.Tools
* TODO: Full archive support for: RAR, LRZip, ZPAQ?, Zstd?, LZ4? * TODO: Full archive support for: RAR, LRZip, ZPAQ?, Zstd?, LZ4?
* Torrent 7-zip: https://sourceforge.net/p/t7z/code/HEAD/tree/ * Torrent 7-zip: https://sourceforge.net/p/t7z/code/HEAD/tree/
* LRZIP: https://github.com/ckolivas/lrzip * LRZIP: https://github.com/ckolivas/lrzip
* ZPAQ: https://github.com/zpaq/zpaq * ZPAQ: https://github.com/zpaq/zpaq - In progress as external DLL
* Zstd: https://github.com/skbkontur/ZstdNet * Zstd: https://github.com/skbkontur/ZstdNet
* LZ4: https://github.com/lz4/lz4 * LZ4: https://github.com/lz4/lz4
*/ */