[DatFile] Re-add single-file DAT creation for DFD

This commit is contained in:
Matt Nadareski
2016-10-24 16:01:03 -07:00
parent b6aa1f4c62
commit 64733038f8
2 changed files with 69 additions and 50 deletions

View File

@@ -5188,72 +5188,80 @@ namespace SabreTools.Helper.Dats
Description = Name + (bare ? "" : " (" + Date + ")"); Description = Name + (bare ? "" : " (" + Date + ")");
} }
// Process the input folder // Process the input
logger.Verbose("Folder found: " + basePath); if (Directory.Exists(basePath))
// Process the files in all subfolders
List<string> files = Directory.EnumerateFiles(basePath, "*", SearchOption.AllDirectories).ToList();
Parallel.ForEach(files,
new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism },
item =>
{
DFDProcessPossibleArchive(item, basePath, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
tempDir, copyFiles, headerToCheckAgainst, maxDegreeOfParallelism, logger);
});
// Now find all folders that are empty, if we are supposed to
if (!Romba && addBlanks)
{ {
List<string> empties = Directory.EnumerateDirectories(basePath, "*", SearchOption.AllDirectories).ToList(); logger.Verbose("Folder found: " + basePath);
Parallel.ForEach(empties,
// Process the files in all subfolders
List<string> files = Directory.EnumerateFiles(basePath, "*", SearchOption.AllDirectories).ToList();
Parallel.ForEach(files,
new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism },
dir => item =>
{ {
if (Directory.EnumerateFiles(dir, "*", SearchOption.TopDirectoryOnly).Count() == 0) DFDProcessPossibleArchive(item, basePath, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
tempDir, copyFiles, headerToCheckAgainst, maxDegreeOfParallelism, logger);
});
// Now find all folders that are empty, if we are supposed to
if (!Romba && addBlanks)
{
List<string> empties = Directory.EnumerateDirectories(basePath, "*", SearchOption.AllDirectories).ToList();
Parallel.ForEach(empties,
new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism },
dir =>
{ {
if (Directory.EnumerateFiles(dir, "*", SearchOption.TopDirectoryOnly).Count() == 0)
{
// Get the full path for the directory // Get the full path for the directory
string fulldir = Path.GetFullPath(dir); string fulldir = Path.GetFullPath(dir);
// Set the temporary variables // Set the temporary variables
string gamename = ""; string gamename = "";
string romname = ""; 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 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") if (Type == "SuperDAT")
{ {
gamename = fulldir.Remove(0, basePath.Length + 1); gamename = fulldir.Remove(0, basePath.Length + 1);
romname = "-"; romname = "-";
} }
// Otherwise, we want just the top level folder as the game, and the file as everything else // Otherwise, we want just the top level folder as the game, and the file as everything else
else else
{ {
gamename = fulldir.Remove(0, basePath.Length + 1).Split(Path.DirectorySeparatorChar)[0]; gamename = fulldir.Remove(0, basePath.Length + 1).Split(Path.DirectorySeparatorChar)[0];
romname = Path.Combine(fulldir.Remove(0, basePath.Length + 1 + gamename.Length), "-"); romname = Path.Combine(fulldir.Remove(0, basePath.Length + 1 + gamename.Length), "-");
} }
// Sanitize the names // Sanitize the names
if (gamename.StartsWith(Path.DirectorySeparatorChar.ToString())) if (gamename.StartsWith(Path.DirectorySeparatorChar.ToString()))
{ {
gamename = gamename.Substring(1); gamename = gamename.Substring(1);
} }
if (gamename.EndsWith(Path.DirectorySeparatorChar.ToString())) if (gamename.EndsWith(Path.DirectorySeparatorChar.ToString()))
{ {
gamename = gamename.Substring(0, gamename.Length - 1); gamename = gamename.Substring(0, gamename.Length - 1);
} }
if (romname.StartsWith(Path.DirectorySeparatorChar.ToString())) if (romname.StartsWith(Path.DirectorySeparatorChar.ToString()))
{ {
romname = romname.Substring(1); romname = romname.Substring(1);
} }
if (romname.EndsWith(Path.DirectorySeparatorChar.ToString())) if (romname.EndsWith(Path.DirectorySeparatorChar.ToString()))
{ {
romname = romname.Substring(0, romname.Length - 1); romname = romname.Substring(0, romname.Length - 1);
} }
logger.Verbose("Adding blank empty folder: " + gamename); logger.Verbose("Adding blank empty folder: " + gamename);
Files["null"].Add(new Rom(romname, gamename)); Files["null"].Add(new Rom(romname, gamename));
} }
}); });
}
}
else if (File.Exists(basePath))
{
DFDProcessPossibleArchive(basePath, basePath, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, addBlanks, addDate,
tempDir, copyFiles, headerToCheckAgainst, maxDegreeOfParallelism, logger);
} }
// Now that we're done, delete the temp folder (if it's not the default) // Now that we're done, delete the temp folder (if it's not the default)
@@ -5545,8 +5553,19 @@ namespace SabreTools.Helper.Dats
// Update rom information // Update rom information
datItem.Name = romname; datItem.Name = romname;
datItem.Machine.Name = gamename; if (datItem.Machine == null)
datItem.Machine.Description = gamename; {
datItem.Machine = new Machine
{
Name = gamename,
Description = gamename,
};
}
else
{
datItem.Machine.Name = gamename;
datItem.Machine.Description = gamename;
}
// Add the file information to the DAT // Add the file information to the DAT
lock (Files) lock (Files)

View File

@@ -158,7 +158,7 @@ namespace SabreTools
// For each input directory, create a DAT // For each input directory, create a DAT
foreach (string path in inputs) foreach (string path in inputs)
{ {
if (Directory.Exists(path)) if (Directory.Exists(path) || File.Exists(path))
{ {
// Clone the base Dat for information // Clone the base Dat for information
DatFile datdata = (DatFile)basedat.Clone(); DatFile datdata = (DatFile)basedat.Clone();