Ensure blanks during D2D are handled properly (fixes #80)

This commit is contained in:
Matt Nadareski
2024-10-22 13:05:51 -04:00
parent f59d754623
commit 0c65e5b588
4 changed files with 33 additions and 29 deletions

View File

@@ -692,39 +692,39 @@ namespace SabreTools.DatFiles
#elif NET40_OR_GREATER
Parallel.For(0, oldkeys.Count, k =>
#else
for (int k = 0; k < oldkeys.Count; k++)
for (int k = 0; k < oldkeys.Count; k++)
#endif
{
string key = oldkeys[k];
if (this[key] == null)
Remove(key);
// Now add each of the roms to their respective keys
for (int i = 0; i < this[key]!.Count; i++)
{
DatItem item = this[key]![i];
if (item == null)
continue;
string key = oldkeys[k];
if (this[key] == null)
Remove(key);
// We want to get the key most appropriate for the given sorting type
string newkey = item.GetKey(bucketBy, lower, norename);
// If the key is different, move the item to the new key
if (newkey != key)
// Now add each of the roms to their respective keys
for (int i = 0; i < this[key]!.Count; i++)
{
Add(newkey, item);
Remove(key, item);
i--; // This make sure that the pointer stays on the correct since one was removed
}
}
DatItem item = this[key]![i];
if (item == null)
continue;
// If the key is now empty, remove it
if (this[key]!.Count == 0)
Remove(key);
#if NET40_OR_GREATER || NETCOREAPP
});
#else
// We want to get the key most appropriate for the given sorting type
string newkey = item.GetKey(bucketBy, lower, norename);
// If the key is different, move the item to the new key
if (newkey != key)
{
Add(newkey, item);
Remove(key, item);
i--; // This make sure that the pointer stays on the correct since one was removed
}
}
// If the key is now empty, remove it
if (this[key]!.Count == 0)
Remove(key);
#if NET40_OR_GREATER || NETCOREAPP
});
#else
}
#endif
}

View File

@@ -20,7 +20,7 @@ namespace SabreTools.DatItems.Formats
#region Constructors
/// <summary>
/// Create a default, empty Archive object
/// Create a default, empty Blank object
/// </summary>
public Blank()
{

View File

@@ -378,7 +378,7 @@ namespace SabreTools.DatTools
var blankMachine = new Machine();
blankMachine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, gamename);
var blankRom = new Rom();
var blankRom = new Blank();
blankRom.SetName(romname);
blankRom.SetFieldValue<Machine?>(DatItem.MachineKey, blankMachine);

View File

@@ -73,6 +73,10 @@ namespace SabreTools.Features
DatFile basedat = DatFile.Create(Header!);
basedat.Header.SetFieldValue<string?>(Models.Metadata.Header.DateKey, DateTime.Now.ToString("yyyy-MM-dd"));
// Update the cleaner based on certain flags
if (addBlankFiles)
Cleaner!.KeepEmptyGames = true;
// For each input directory, create a DAT
foreach (string path in Inputs)
{