mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Create passthrough methods for scaffolding
This commit is contained in:
@@ -71,7 +71,7 @@ namespace SabreTools.DatFiles
|
||||
// Loop through the sorted items and create games for them
|
||||
foreach (string key in Items.SortedKeys)
|
||||
{
|
||||
var items = Items.FilteredItems(key);
|
||||
var items = Items.GetItemsForBucket(key, filter: true);
|
||||
if (items == null || items.Count == 0)
|
||||
continue;
|
||||
|
||||
@@ -494,7 +494,7 @@ namespace SabreTools.DatFiles
|
||||
// Loop through the sorted items and create games for them
|
||||
foreach (string key in ItemsDB.SortedKeys)
|
||||
{
|
||||
var items = ItemsDB.GetItemsForBucket(key, filter: true);
|
||||
var items = GetItemsForBucketDB(key, filter: true);
|
||||
if (items == null || items.Count == 0)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -38,6 +38,13 @@ namespace SabreTools.DatFiles
|
||||
[JsonProperty("items"), XmlElement("items")]
|
||||
public ItemDictionaryDB ItemsDB { get; private set; } = new ItemDictionaryDB();
|
||||
|
||||
/// <summary>
|
||||
/// DAT statistics
|
||||
/// </summary>
|
||||
[JsonIgnore, XmlIgnore]
|
||||
public DatStatistics DatStatistics => Items.DatStatistics;
|
||||
//public DatStatistics DatStatistics => ItemsDB.DatStatistics;
|
||||
|
||||
/// <summary>
|
||||
/// List of supported types for writing
|
||||
/// </summary>
|
||||
@@ -134,21 +141,7 @@ namespace SabreTools.DatFiles
|
||||
|
||||
#endregion
|
||||
|
||||
#region Filtering
|
||||
|
||||
/// <summary>
|
||||
/// Execute all filters in a filter runner on the items in the dictionary
|
||||
/// </summary>
|
||||
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
||||
public void ExecuteFilters(FilterRunner filterRunner)
|
||||
{
|
||||
Items.ExecuteFilters(filterRunner);
|
||||
ItemsDB.ExecuteFilters(filterRunner);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Item Dictionary Manipulation
|
||||
#region Item Dictionary Passthrough - Accessors
|
||||
|
||||
/// <summary>
|
||||
/// Add a value to the file dictionary
|
||||
@@ -228,6 +221,18 @@ namespace SabreTools.DatFiles
|
||||
ItemsDB.ClearMarked();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the items associated with a bucket name
|
||||
/// </summary>
|
||||
public List<DatItem> GetItemsForBucket(string bucketName, bool filter = false)
|
||||
=> Items.GetItemsForBucket(bucketName, filter);
|
||||
|
||||
/// <summary>
|
||||
/// Get the indices and items associated with a bucket name
|
||||
/// </summary>
|
||||
public Dictionary<long, DatItem> GetItemsForBucketDB(string bucketName, bool filter = false)
|
||||
=> ItemsDB.GetItemsForBucket(bucketName, filter);
|
||||
|
||||
/// <summary>
|
||||
/// Remove a key from the file dictionary if it exists
|
||||
/// </summary>
|
||||
@@ -248,6 +253,203 @@ namespace SabreTools.DatFiles
|
||||
|
||||
#endregion
|
||||
|
||||
#region Item Dictionary Passthrough - Bucketing
|
||||
|
||||
/// <summary>
|
||||
/// Take the arbitrarily bucketed Files Dictionary and convert to one bucketed by a user-defined method
|
||||
/// </summary>
|
||||
/// <param name="bucketBy">ItemKey enum representing how to bucket the individual items</param>
|
||||
/// <param name="dedupeType">Dedupe type that should be used</param>
|
||||
/// <param name="lower">True if the key should be lowercased (default), false otherwise</param>
|
||||
/// <param name="norename">True if games should only be compared on game and file name, false if system and source are counted</param>
|
||||
public void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true)
|
||||
{
|
||||
Items.BucketBy(bucketBy, dedupeType, lower, norename);
|
||||
ItemsDB.BucketBy(bucketBy, dedupeType, lower, norename);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List all duplicates found in a DAT based on a DatItem
|
||||
/// </summary>
|
||||
/// <param name="datItem">Item to try to match</param>
|
||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
||||
/// <returns>List of matched DatItem objects</returns>
|
||||
public List<DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
|
||||
=> Items.GetDuplicates(datItem, sorted);
|
||||
|
||||
/// <summary>
|
||||
/// List all duplicates found in a DAT based on a DatItem
|
||||
/// </summary>
|
||||
/// <param name="datItem">Item to try to match</param>
|
||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
||||
/// <returns>List of matched DatItem objects</returns>
|
||||
public Dictionary<long, DatItem> GetDuplicatesDB(KeyValuePair<long, DatItem> datItem, bool sorted = false)
|
||||
=> ItemsDB.GetDuplicates(datItem, sorted);
|
||||
|
||||
/// <summary>
|
||||
/// Check if a DAT contains the given DatItem
|
||||
/// </summary>
|
||||
/// <param name="datItem">Item to try to match</param>
|
||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
||||
/// <returns>True if it contains the rom, false otherwise</returns>
|
||||
public bool HasDuplicates(DatItem datItem, bool sorted = false)
|
||||
=> Items.HasDuplicates(datItem, sorted);
|
||||
|
||||
/// <summary>
|
||||
/// Check if a DAT contains the given DatItem
|
||||
/// </summary>
|
||||
/// <param name="datItem">Item to try to match</param>
|
||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
||||
/// <returns>True if it contains the rom, false otherwise</returns>
|
||||
public bool HasDuplicates(KeyValuePair<long, DatItem> datItem, bool sorted = false)
|
||||
=> ItemsDB.HasDuplicates(datItem, sorted);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Item Dictionary Passthrough - Filtering
|
||||
|
||||
/// <summary>
|
||||
/// Execute all filters in a filter runner on the items in the dictionary
|
||||
/// </summary>
|
||||
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
||||
public void ExecuteFilters(FilterRunner filterRunner)
|
||||
{
|
||||
Items.ExecuteFilters(filterRunner);
|
||||
ItemsDB.ExecuteFilters(filterRunner);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use game descriptions as names, updating cloneof/romof/sampleof
|
||||
/// </summary>
|
||||
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||
public void MachineDescriptionToName(bool throwOnError = false)
|
||||
{
|
||||
Items.MachineDescriptionToName(throwOnError);
|
||||
ItemsDB.MachineDescriptionToName(throwOnError);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensure that all roms are in their own game (or at least try to ensure)
|
||||
/// </summary>
|
||||
public void SetOneRomPerGame()
|
||||
{
|
||||
Items.SetOneRomPerGame();
|
||||
ItemsDB.SetOneRomPerGame();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter a DAT using 1G1R logic given an ordered set of regions
|
||||
/// </summary>
|
||||
/// <param name="regionList">List of regions in order of priority</param>
|
||||
/// <remarks>
|
||||
/// In the most technical sense, the way that the region list is being used does not
|
||||
/// confine its values to be just regions. Since it's essentially acting like a
|
||||
/// specialized version of the machine name filter, anything that is usually encapsulated
|
||||
/// in parenthesis would be matched on, including disc numbers, languages, editions,
|
||||
/// and anything else commonly used. Please note that, unlike other existing 1G1R
|
||||
/// solutions, this does not have the ability to contain custom mappings of parent
|
||||
/// to clone sets based on name, nor does it have the ability to match on the
|
||||
/// Release DatItem type.
|
||||
/// </remarks>
|
||||
public void SetOneGamePerRegion(List<string> regionList)
|
||||
{
|
||||
Items.SetOneGamePerRegion(regionList);
|
||||
ItemsDB.SetOneGamePerRegion(regionList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Strip the dates from the beginning of scene-style set names
|
||||
/// </summary>
|
||||
public void StripSceneDatesFromItems()
|
||||
{
|
||||
Items.StripSceneDatesFromItems();
|
||||
ItemsDB.StripSceneDatesFromItems();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Item Dictionary Passthrough - Splitting
|
||||
|
||||
/// <summary>
|
||||
/// Use romof tags to add roms to the children
|
||||
/// </summary>
|
||||
public void AddRomsFromBios()
|
||||
{
|
||||
Items.AddRomsFromBios();
|
||||
ItemsDB.AddRomsFromBios();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use device_ref and optionally slotoption tags to add roms to the children
|
||||
/// </summary>
|
||||
/// <param name="dev">True if only child device sets are touched, false for non-device sets</param>
|
||||
/// <param name="useSlotOptions">True if slotoptions tags are used as well, false otherwise</param>
|
||||
public bool AddRomsFromDevices(bool dev, bool useSlotOptions)
|
||||
{
|
||||
bool foundnew = Items.AddRomsFromDevices(dev, useSlotOptions);
|
||||
foundnew |= ItemsDB.AddRomsFromDevices(dev, useSlotOptions);
|
||||
return foundnew;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use cloneof tags to add roms to the parents, removing the child sets in the process
|
||||
/// </summary>
|
||||
/// <param name="subfolder">True to add DatItems to subfolder of parent (not including Disk), false otherwise</param>
|
||||
/// <param name="skipDedup">True to skip checking for duplicate ROMs in parent, false otherwise</param>
|
||||
public void AddRomsFromChildren(bool subfolder, bool skipDedup)
|
||||
{
|
||||
Items.AddRomsFromChildren(subfolder, skipDedup);
|
||||
ItemsDB.AddRomsFromChildren(subfolder, skipDedup);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use cloneof tags to add roms to the children, setting the new romof tag in the process
|
||||
/// </summary>
|
||||
public void AddRomsFromParent()
|
||||
{
|
||||
Items.AddRomsFromParent();
|
||||
ItemsDB.AddRomsFromParent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all BIOS and device sets
|
||||
/// </summary>
|
||||
public void RemoveBiosAndDeviceSets()
|
||||
{
|
||||
Items.RemoveBiosAndDeviceSets();
|
||||
ItemsDB.RemoveBiosAndDeviceSets();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use romof tags to remove bios roms from children
|
||||
/// </summary>
|
||||
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
|
||||
public void RemoveBiosRomsFromChild(bool bios)
|
||||
{
|
||||
Items.RemoveBiosRomsFromChild(bios);
|
||||
ItemsDB.RemoveBiosRomsFromChild(bios);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use cloneof tags to remove roms from the children
|
||||
/// </summary>
|
||||
public void RemoveRomsFromChild()
|
||||
{
|
||||
Items.RemoveRomsFromChild();
|
||||
ItemsDB.RemoveRomsFromChild();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all romof and cloneof tags from all games
|
||||
/// </summary>
|
||||
public void RemoveTagsFromChild()
|
||||
{
|
||||
Items.RemoveTagsFromChild();
|
||||
ItemsDB.RemoveTagsFromChild();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Parsing
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -320,7 +320,7 @@ namespace SabreTools.DatFiles
|
||||
foreach (var key in keys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem>? items = datFile.Items[key];
|
||||
List<DatItem>? items = datFile.GetItemsForBucket(key);
|
||||
if (items == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
@@ -391,7 +391,7 @@ namespace SabreTools.DatFiles
|
||||
foreach (var key in keys)
|
||||
#endif
|
||||
{
|
||||
var items = datFile.ItemsDB.GetItemsForBucket(key);
|
||||
var items = datFile.GetItemsForBucketDB(key);
|
||||
if (items == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
@@ -462,8 +462,8 @@ namespace SabreTools.DatFiles
|
||||
if (itemFieldNames.Count > 0)
|
||||
{
|
||||
// For comparison's sake, we want to use CRC as the base bucketing
|
||||
datFile.Items.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||
intDat.Items.BucketBy(ItemKey.CRC, DedupeType.None);
|
||||
datFile.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||
intDat.BucketBy(ItemKey.CRC, DedupeType.None);
|
||||
|
||||
// Then we do a hashwise comparison against the base DAT
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
@@ -474,7 +474,7 @@ namespace SabreTools.DatFiles
|
||||
foreach (var key in intDat.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem>? datItems = intDat.Items[key];
|
||||
List<DatItem>? datItems = intDat.GetItemsForBucket(key);
|
||||
if (datItems == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
@@ -510,8 +510,8 @@ namespace SabreTools.DatFiles
|
||||
if (machineFieldNames.Count > 0)
|
||||
{
|
||||
// For comparison's sake, we want to use Machine Name as the base bucketing
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.Full);
|
||||
intDat.Items.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.Full);
|
||||
intDat.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
|
||||
// Then we do a namewise comparison against the base DAT
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
@@ -522,7 +522,7 @@ namespace SabreTools.DatFiles
|
||||
foreach (var key in intDat.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem>? datItems = intDat.Items[key];
|
||||
List<DatItem>? datItems = intDat.GetItemsForBucket(key);
|
||||
if (datItems == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
@@ -579,8 +579,8 @@ namespace SabreTools.DatFiles
|
||||
if (itemFieldNames.Count > 0)
|
||||
{
|
||||
// For comparison's sake, we want to use CRC as the base bucketing
|
||||
datFile.ItemsDB.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||
intDat.ItemsDB.BucketBy(ItemKey.CRC, DedupeType.None);
|
||||
datFile.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||
intDat.BucketBy(ItemKey.CRC, DedupeType.None);
|
||||
|
||||
// Then we do a hashwise comparison against the base DAT
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
@@ -591,7 +591,7 @@ namespace SabreTools.DatFiles
|
||||
foreach (var key in intDat.ItemsDB.SortedKeys)
|
||||
#endif
|
||||
{
|
||||
var datItems = intDat.ItemsDB.GetItemsForBucket(key);
|
||||
var datItems = intDat.GetItemsForBucketDB(key);
|
||||
if (datItems == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
@@ -601,7 +601,7 @@ namespace SabreTools.DatFiles
|
||||
|
||||
foreach (var datItem in datItems)
|
||||
{
|
||||
var dupes = datFile.ItemsDB.GetDuplicates(datItem, sorted: true);
|
||||
var dupes = datFile.GetDuplicatesDB(datItem, sorted: true);
|
||||
if (datItem.Value.Clone() is not DatItem newDatItem)
|
||||
continue;
|
||||
|
||||
@@ -620,8 +620,8 @@ namespace SabreTools.DatFiles
|
||||
if (machineFieldNames.Count > 0)
|
||||
{
|
||||
// For comparison's sake, we want to use Machine Name as the base bucketing
|
||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.Full);
|
||||
intDat.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.Full);
|
||||
intDat.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
|
||||
// Then we do a namewise comparison against the base DAT
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
@@ -632,7 +632,7 @@ namespace SabreTools.DatFiles
|
||||
foreach (var key in intDat.ItemsDB.SortedKeys)
|
||||
#endif
|
||||
{
|
||||
var datItems = intDat.ItemsDB.GetItemsForBucket(key);
|
||||
var datItems = intDat.GetItemsForBucketDB(key);
|
||||
if (datItems == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
@@ -642,7 +642,7 @@ namespace SabreTools.DatFiles
|
||||
|
||||
foreach (var datItem in datItems)
|
||||
{
|
||||
var datMachine = datFile.ItemsDB.GetMachineForItem(datFile.ItemsDB.GetItemsForBucket(key)!.First().Key);
|
||||
var datMachine = datFile.ItemsDB.GetMachineForItem(datFile.GetItemsForBucketDB(key)!.First().Key);
|
||||
var intMachine = intDat.ItemsDB.GetMachineForItem(datItem.Key);
|
||||
if (datMachine.Value != null && intMachine.Value != null)
|
||||
Replacer.ReplaceFields(intMachine.Value, datMachine.Value, machineFieldNames, onlySame);
|
||||
@@ -671,17 +671,17 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
// For comparison's sake, we want to use a base ordering
|
||||
if (useGames)
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
else
|
||||
datFile.Items.BucketBy(ItemKey.CRC, DedupeType.None);
|
||||
datFile.BucketBy(ItemKey.CRC, DedupeType.None);
|
||||
|
||||
InternalStopwatch watch = new($"Comparing '{intDat.Header.GetStringFieldValue(DatHeader.FileNameKey)}' to base DAT");
|
||||
|
||||
// For comparison's sake, we want to a the base bucketing
|
||||
if (useGames)
|
||||
intDat.Items.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
intDat.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
else
|
||||
intDat.Items.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||
intDat.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||
|
||||
// Then we compare against the base DAT
|
||||
List<string> keys = [.. intDat.Items.Keys];
|
||||
@@ -740,7 +740,7 @@ namespace SabreTools.DatFiles
|
||||
// Standard Against uses hashes
|
||||
else
|
||||
{
|
||||
List<DatItem>? datItems = intDat.Items[key];
|
||||
List<DatItem>? datItems = intDat.GetItemsForBucket(key);
|
||||
if (datItems == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
@@ -751,7 +751,7 @@ namespace SabreTools.DatFiles
|
||||
List<DatItem> keepDatItems = [];
|
||||
foreach (DatItem datItem in datItems)
|
||||
{
|
||||
if (!datFile.Items.HasDuplicates(datItem, true))
|
||||
if (!datFile.HasDuplicates(datItem, true))
|
||||
keepDatItems.Add(datItem);
|
||||
}
|
||||
|
||||
@@ -780,7 +780,7 @@ namespace SabreTools.DatFiles
|
||||
List<DatFile> outDats = [];
|
||||
|
||||
// Ensure the current DatFile is sorted optimally
|
||||
datFile.Items.BucketBy(ItemKey.CRC, DedupeType.None);
|
||||
datFile.BucketBy(ItemKey.CRC, DedupeType.None);
|
||||
|
||||
// Loop through each of the inputs and get or create a new DatData object
|
||||
InternalStopwatch watch = new("Initializing and filling all output DATs");
|
||||
@@ -795,10 +795,10 @@ namespace SabreTools.DatFiles
|
||||
for (int j = 0; j < datHeaders.Count; j++)
|
||||
#endif
|
||||
{
|
||||
DatFile diffData = DatFileTool.CreateDatFile(datHeaders[j]);
|
||||
DatFile diffData = CreateDatFile(datHeaders[j]);
|
||||
diffData.ResetDictionary();
|
||||
FillWithSourceIndex(datFile, diffData, j);
|
||||
//FillWithSourceIndexDB(datFile, diffData, j);
|
||||
FillWithSourceIndexDB(datFile, diffData, j);
|
||||
outDatsArray[j] = diffData;
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
@@ -844,7 +844,7 @@ namespace SabreTools.DatFiles
|
||||
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "datFile.All DATs");
|
||||
|
||||
string post = " (Duplicates)";
|
||||
DatFile dupeData = DatFileTool.CreateDatFile(datFile.Header);
|
||||
DatFile dupeData = CreateDatFile(datFile.Header);
|
||||
dupeData.Header.SetFieldValue<string?>(DatHeader.FileNameKey, dupeData.Header.GetStringFieldValue(DatHeader.FileNameKey) + post);
|
||||
dupeData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post);
|
||||
dupeData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post);
|
||||
@@ -863,7 +863,7 @@ namespace SabreTools.DatFiles
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem> items = Merge(datFile.Items[key]);
|
||||
List<DatItem> items = Merge(datFile.GetItemsForBucket(key));
|
||||
|
||||
// If the rom list is empty or null, just skip it
|
||||
if (items == null || items.Count == 0)
|
||||
@@ -922,7 +922,7 @@ namespace SabreTools.DatFiles
|
||||
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "datFile.All DATs");
|
||||
|
||||
string post = " (Duplicates)";
|
||||
DatFile dupeData = DatFileTool.CreateDatFile(datFile.Header);
|
||||
DatFile dupeData = CreateDatFile(datFile.Header);
|
||||
dupeData.Header.SetFieldValue<string?>(DatHeader.FileNameKey, dupeData.Header.GetStringFieldValue(DatHeader.FileNameKey) + post);
|
||||
dupeData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post);
|
||||
dupeData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, dupeData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post);
|
||||
@@ -1060,7 +1060,7 @@ namespace SabreTools.DatFiles
|
||||
#endif
|
||||
{
|
||||
string innerpost = $" ({j} - {inputs[j].GetNormalizedFileName(true)} Only)";
|
||||
DatFile diffData = DatFileTool.CreateDatFile(datFile.Header);
|
||||
DatFile diffData = CreateDatFile(datFile.Header);
|
||||
diffData.Header.SetFieldValue<string?>(DatHeader.FileNameKey, diffData.Header.GetStringFieldValue(DatHeader.FileNameKey) + innerpost);
|
||||
diffData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + innerpost);
|
||||
diffData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + innerpost);
|
||||
@@ -1088,7 +1088,7 @@ namespace SabreTools.DatFiles
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem> items = Merge(datFile.Items[key]);
|
||||
List<DatItem> items = Merge(datFile.GetItemsForBucket(key));
|
||||
|
||||
// If the rom list is empty or null, just skip it
|
||||
if (items == null || items.Count == 0)
|
||||
@@ -1153,7 +1153,7 @@ namespace SabreTools.DatFiles
|
||||
#endif
|
||||
{
|
||||
string innerpost = $" ({j} - {inputs[j].GetNormalizedFileName(true)} Only)";
|
||||
DatFile diffData = DatFileTool.CreateDatFile(datFile.Header);
|
||||
DatFile diffData = CreateDatFile(datFile.Header);
|
||||
diffData.Header.SetFieldValue<string?>(DatHeader.FileNameKey, diffData.Header.GetStringFieldValue(DatHeader.FileNameKey) + innerpost);
|
||||
diffData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + innerpost);
|
||||
diffData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, diffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + innerpost);
|
||||
@@ -1279,7 +1279,7 @@ namespace SabreTools.DatFiles
|
||||
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "All DATs");
|
||||
|
||||
string post = " (No Duplicates)";
|
||||
DatFile outerDiffData = DatFileTool.CreateDatFile(datFile.Header);
|
||||
DatFile outerDiffData = CreateDatFile(datFile.Header);
|
||||
outerDiffData.Header.SetFieldValue<string?>(DatHeader.FileNameKey, outerDiffData.Header.GetStringFieldValue(DatHeader.FileNameKey) + post);
|
||||
outerDiffData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post);
|
||||
outerDiffData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post);
|
||||
@@ -1298,7 +1298,7 @@ namespace SabreTools.DatFiles
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem> items = Merge(datFile.Items[key]);
|
||||
List<DatItem> items = Merge(datFile.GetItemsForBucket(key));
|
||||
|
||||
// If the rom list is empty or null, just skip it
|
||||
if (items == null || items.Count == 0)
|
||||
@@ -1355,7 +1355,7 @@ namespace SabreTools.DatFiles
|
||||
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, "All DATs");
|
||||
|
||||
string post = " (No Duplicates)";
|
||||
DatFile outerDiffData = DatFileTool.CreateDatFile(datFile.Header);
|
||||
DatFile outerDiffData = CreateDatFile(datFile.Header);
|
||||
outerDiffData.Header.SetFieldValue<string?>(DatHeader.FileNameKey, outerDiffData.Header.GetStringFieldValue(DatHeader.FileNameKey) + post);
|
||||
outerDiffData.Header.SetFieldValue<string?>(Models.Metadata.Header.NameKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.NameKey) + post);
|
||||
outerDiffData.Header.SetFieldValue<string?>(Models.Metadata.Header.DescriptionKey, outerDiffData.Header.GetStringFieldValue(Models.Metadata.Header.DescriptionKey) + post);
|
||||
@@ -1488,7 +1488,7 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
var input = inputs[i];
|
||||
_staticLogger.User($"Adding DAT: {input.CurrentPath}");
|
||||
datFiles[i] = DatFileTool.CreateDatFile(datFile.Header.CloneFiltering());
|
||||
datFiles[i] = CreateDatFile(datFile.Header.CloneFiltering());
|
||||
Parser.ParseInto(datFiles[i], input, i, keep: true);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
@@ -1523,7 +1523,7 @@ namespace SabreTools.DatFiles
|
||||
foreach (string key in keys)
|
||||
{
|
||||
// Add everything from the key to the internal DAT
|
||||
addTo.Add(key, addFrom.Items[key]);
|
||||
addTo.Add(key, addFrom.GetItemsForBucket(key));
|
||||
|
||||
// Now remove the key from the source DAT
|
||||
if (delete)
|
||||
@@ -1616,7 +1616,7 @@ namespace SabreTools.DatFiles
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem> items = Merge(datFile.Items[key]);
|
||||
List<DatItem> items = Merge(datFile.GetItemsForBucket(key));
|
||||
|
||||
// If the rom list is empty or null, just skip it
|
||||
if (items == null || items.Count == 0)
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
// Use a sorted list of games to output
|
||||
foreach (string key in Items.SortedKeys)
|
||||
{
|
||||
List<DatItem> datItems = Items.FilteredItems(key);
|
||||
List<DatItem> datItems = GetItemsForBucket(key, filter: true);
|
||||
|
||||
// If this machine doesn't contain any writable items, skip
|
||||
if (!ContainsWritable(datItems))
|
||||
@@ -122,7 +122,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
foreach (string key in ItemsDB.SortedKeys)
|
||||
{
|
||||
// If this machine doesn't contain any writable items, skip
|
||||
var itemsDict = ItemsDB.GetItemsForBucket(key, filter: true);
|
||||
var itemsDict = GetItemsForBucketDB(key, filter: true);
|
||||
if (itemsDict == null || !ContainsWritable([.. itemsDict.Values]))
|
||||
continue;
|
||||
|
||||
|
||||
@@ -396,7 +396,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
// Use a sorted list of games to output
|
||||
foreach (string key in Items.SortedKeys)
|
||||
{
|
||||
List<DatItem> datItems = Items.FilteredItems(key);
|
||||
List<DatItem> datItems = GetItemsForBucket(key, filter: true);
|
||||
|
||||
// If this machine doesn't contain any writable items, skip
|
||||
if (!ContainsWritable(datItems))
|
||||
@@ -478,7 +478,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
foreach (string key in ItemsDB.SortedKeys)
|
||||
{
|
||||
// If this machine doesn't contain any writable items, skip
|
||||
var itemsDict = ItemsDB.GetItemsForBucket(key, filter: true);
|
||||
var itemsDict = GetItemsForBucketDB(key, filter: true);
|
||||
if (itemsDict == null || !ContainsWritable([.. itemsDict.Values]))
|
||||
continue;
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
// Use a sorted list of games to output
|
||||
foreach (string key in Items.SortedKeys)
|
||||
{
|
||||
List<DatItem> datItems = Items.FilteredItems(key);
|
||||
List<DatItem> datItems = GetItemsForBucket(key, filter: true);
|
||||
|
||||
// If this machine doesn't contain any writable items, skip
|
||||
if (!ContainsWritable(datItems))
|
||||
@@ -307,7 +307,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
foreach (string key in ItemsDB.SortedKeys)
|
||||
{
|
||||
// If this machine doesn't contain any writable items, skip
|
||||
var itemsDict = ItemsDB.GetItemsForBucket(key, filter: true);
|
||||
var itemsDict = GetItemsForBucketDB(key, filter: true);
|
||||
if (itemsDict == null || !ContainsWritable([.. itemsDict.Values]))
|
||||
continue;
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace SabreTools.DatFiles
|
||||
/// Internal dictionary for the class
|
||||
/// </summary>
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
private readonly ConcurrentDictionary<string, List<DatItem>?> items = [];
|
||||
private readonly ConcurrentDictionary<string, List<DatItem>?> _items = [];
|
||||
#else
|
||||
private readonly Dictionary<string, List<DatItem>?> items = [];
|
||||
#endif
|
||||
@@ -67,7 +67,7 @@ namespace SabreTools.DatFiles
|
||||
[JsonIgnore, XmlIgnore]
|
||||
public ICollection<string> Keys
|
||||
{
|
||||
get { return items.Keys; }
|
||||
get { return _items.Keys; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -79,7 +79,7 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
get
|
||||
{
|
||||
List<string> keys = [.. items.Keys];
|
||||
List<string> keys = [.. _items.Keys];
|
||||
keys.Sort(new NaturalComparer());
|
||||
return keys;
|
||||
}
|
||||
@@ -130,14 +130,14 @@ namespace SabreTools.DatFiles
|
||||
EnsureKey(key);
|
||||
|
||||
// Now return the value
|
||||
return items[key];
|
||||
return _items[key];
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
Remove(key);
|
||||
if (value == null)
|
||||
items[key] = null;
|
||||
_items[key] = null;
|
||||
else
|
||||
Add(key, value);
|
||||
}
|
||||
@@ -161,7 +161,7 @@ namespace SabreTools.DatFiles
|
||||
return;
|
||||
|
||||
// Now add the value
|
||||
items[key]!.Add(value);
|
||||
_items[key]!.Add(value);
|
||||
|
||||
// Now update the statistics
|
||||
DatStatistics.AddItemStatistics(value);
|
||||
@@ -186,7 +186,7 @@ namespace SabreTools.DatFiles
|
||||
EnsureKey(key);
|
||||
|
||||
// Now add the value
|
||||
items[key]!.AddRange(value);
|
||||
_items[key]!.AddRange(value);
|
||||
|
||||
// Now update the statistics
|
||||
foreach (DatItem item in value)
|
||||
@@ -299,23 +299,23 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Remove any keys that have null or empty values
|
||||
/// </summary>
|
||||
public void ClearEmpty()
|
||||
internal void ClearEmpty()
|
||||
{
|
||||
string[] keys = [.. Keys];
|
||||
foreach (string key in keys)
|
||||
{
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
// If the key doesn't exist, skip
|
||||
if (!items.TryGetValue(key, out var value))
|
||||
if (!_items.TryGetValue(key, out var value))
|
||||
continue;
|
||||
|
||||
// If the value is null, remove
|
||||
else if (value == null)
|
||||
items.TryRemove(key, out _);
|
||||
_items.TryRemove(key, out _);
|
||||
|
||||
// If there are no non-blank items, remove
|
||||
else if (value!.FindIndex(i => i != null && i is not Blank) == -1)
|
||||
items.TryRemove(key, out _);
|
||||
_items.TryRemove(key, out _);
|
||||
#else
|
||||
// If the key doesn't exist, skip
|
||||
if (!items.ContainsKey(key))
|
||||
@@ -335,7 +335,7 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Remove all items marked for removal
|
||||
/// </summary>
|
||||
public void ClearMarked()
|
||||
internal void ClearMarked()
|
||||
{
|
||||
string[] keys = [.. Keys];
|
||||
foreach (string key in keys)
|
||||
@@ -366,7 +366,7 @@ namespace SabreTools.DatFiles
|
||||
// Explicit lock for some weird corner cases
|
||||
lock (key)
|
||||
{
|
||||
return items.ContainsKey(key);
|
||||
return _items.ContainsKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ namespace SabreTools.DatFiles
|
||||
lock (key)
|
||||
{
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
if (items.TryGetValue(key, out var list) && list != null)
|
||||
if (_items.TryGetValue(key, out var list) && list != null)
|
||||
return list.Contains(value);
|
||||
#else
|
||||
if (items.ContainsKey(key) && items[key] != null)
|
||||
@@ -404,32 +404,34 @@ namespace SabreTools.DatFiles
|
||||
public void EnsureKey(string key)
|
||||
{
|
||||
// If the key is missing from the dictionary, add it
|
||||
if (!items.ContainsKey(key))
|
||||
if (!_items.ContainsKey(key))
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
items.TryAdd(key, []);
|
||||
_items.TryAdd(key, []);
|
||||
#else
|
||||
items[key] = [];
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of filtered items for a given key
|
||||
/// Get the items associated with a bucket name
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to retrieve</param>
|
||||
public List<DatItem> FilteredItems(string key)
|
||||
public List<DatItem> GetItemsForBucket(string bucketName, bool filter = false)
|
||||
{
|
||||
lock (key)
|
||||
{
|
||||
// Get the list, if possible
|
||||
List<DatItem>? fi = items[key];
|
||||
if (fi == null)
|
||||
return [];
|
||||
if (!_items.ContainsKey(bucketName))
|
||||
return [];
|
||||
|
||||
// Filter the list
|
||||
return fi.FindAll(i => i != null)
|
||||
.FindAll(i => i.GetBoolFieldValue(DatItem.RemoveKey) != true)
|
||||
.FindAll(i => i.GetFieldValue<Machine>(DatItem.MachineKey) != null);
|
||||
var items = _items[bucketName];
|
||||
if (items == null)
|
||||
return [];
|
||||
|
||||
var datItems = new List<DatItem>();
|
||||
foreach (DatItem item in items)
|
||||
{
|
||||
if (!filter || item.GetBoolFieldValue(DatItem.RemoveKey) != true)
|
||||
datItems.Add(item);
|
||||
}
|
||||
|
||||
return datItems;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -442,18 +444,18 @@ namespace SabreTools.DatFiles
|
||||
lock (key)
|
||||
{
|
||||
// If the key doesn't exist, return
|
||||
if (!ContainsKey(key) || items[key] == null)
|
||||
if (!ContainsKey(key) || _items[key] == null)
|
||||
return false;
|
||||
|
||||
// Remove the statistics first
|
||||
foreach (DatItem item in items[key]!)
|
||||
foreach (DatItem item in _items[key]!)
|
||||
{
|
||||
DatStatistics.RemoveItemStatistics(item);
|
||||
}
|
||||
|
||||
// Remove the key from the dictionary
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return items.TryRemove(key, out _);
|
||||
return _items.TryRemove(key, out _);
|
||||
#else
|
||||
return items.Remove(key);
|
||||
#endif
|
||||
@@ -471,13 +473,13 @@ namespace SabreTools.DatFiles
|
||||
lock (key)
|
||||
{
|
||||
// If the key and value doesn't exist, return
|
||||
if (!Contains(key, value) || items[key] == null)
|
||||
if (!Contains(key, value) || _items[key] == null)
|
||||
return false;
|
||||
|
||||
// Remove the statistics first
|
||||
DatStatistics.RemoveItemStatistics(value);
|
||||
|
||||
return items[key]!.Remove(value);
|
||||
return _items[key]!.Remove(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,17 +490,17 @@ namespace SabreTools.DatFiles
|
||||
public bool Reset(string key)
|
||||
{
|
||||
// If the key doesn't exist, return
|
||||
if (!ContainsKey(key) || items[key] == null)
|
||||
if (!ContainsKey(key) || _items[key] == null)
|
||||
return false;
|
||||
|
||||
// Remove the statistics first
|
||||
foreach (DatItem item in items[key]!)
|
||||
foreach (DatItem item in _items[key]!)
|
||||
{
|
||||
DatStatistics.RemoveItemStatistics(item);
|
||||
}
|
||||
|
||||
// Remove the key from the dictionary
|
||||
items[key] = [];
|
||||
_items[key] = [];
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -522,10 +524,10 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="dedupeType">Dedupe type that should be used</param>
|
||||
/// <param name="lower">True if the key should be lowercased (default), false otherwise</param>
|
||||
/// <param name="norename">True if games should only be compared on game and file name, false if system and source are counted</param>
|
||||
public void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true)
|
||||
internal void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true)
|
||||
{
|
||||
// If we have a situation where there's no dictionary or no keys at all, we skip
|
||||
if (items == null || items.Count == 0)
|
||||
if (_items == null || _items.Count == 0)
|
||||
return;
|
||||
|
||||
// If the sorted type isn't the same, we want to sort the dictionary accordingly
|
||||
@@ -555,7 +557,7 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="datItem">Item to try to match</param>
|
||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
||||
/// <returns>List of matched DatItem objects</returns>
|
||||
public List<DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
|
||||
internal List<DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
|
||||
{
|
||||
List<DatItem> output = [];
|
||||
|
||||
@@ -607,7 +609,7 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="datItem">Item to try to match</param>
|
||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
||||
/// <returns>True if it contains the rom, false otherwise</returns>
|
||||
public bool HasDuplicates(DatItem datItem, bool sorted = false)
|
||||
internal bool HasDuplicates(DatItem datItem, bool sorted = false)
|
||||
{
|
||||
// Check for an empty rom list first
|
||||
if (DatStatistics.TotalCount == 0)
|
||||
@@ -820,13 +822,14 @@ namespace SabreTools.DatFiles
|
||||
|
||||
#endregion
|
||||
|
||||
// TODO: All internal, can this be put into a better location?
|
||||
#region Filtering
|
||||
|
||||
/// <summary>
|
||||
/// Execute all filters in a filter runner on the items in the dictionary
|
||||
/// </summary>
|
||||
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
||||
public void ExecuteFilters(FilterRunner filterRunner)
|
||||
internal void ExecuteFilters(FilterRunner filterRunner)
|
||||
{
|
||||
List<string> keys = [.. Keys];
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
@@ -867,7 +870,7 @@ namespace SabreTools.DatFiles
|
||||
/// Use game descriptions as names, updating cloneof/romof/sampleof
|
||||
/// </summary>
|
||||
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||
public void MachineDescriptionToName(bool throwOnError = false)
|
||||
internal void MachineDescriptionToName(bool throwOnError = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -883,6 +886,39 @@ namespace SabreTools.DatFiles
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensure that all roms are in their own game (or at least try to ensure)
|
||||
/// </summary>
|
||||
internal void SetOneRomPerGame()
|
||||
{
|
||||
// For each rom, we want to update the game to be "<game name>/<rom name>"
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(Keys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(Keys, key =>
|
||||
#else
|
||||
foreach (var key in Keys)
|
||||
#endif
|
||||
{
|
||||
var items = this[key];
|
||||
if (items == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
#else
|
||||
continue;
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
SetOneRomPerGame(items[i]);
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter a DAT using 1G1R logic given an ordered set of regions
|
||||
/// </summary>
|
||||
@@ -897,7 +933,7 @@ namespace SabreTools.DatFiles
|
||||
/// to clone sets based on name, nor does it have the ability to match on the
|
||||
/// Release DatItem type.
|
||||
/// </remarks>
|
||||
public void SetOneGamePerRegion(List<string> regionList)
|
||||
internal void SetOneGamePerRegion(List<string> regionList)
|
||||
{
|
||||
// If we have null region list, make it empty
|
||||
regionList ??= [];
|
||||
@@ -976,43 +1012,10 @@ namespace SabreTools.DatFiles
|
||||
RemoveTagsFromChild();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensure that all roms are in their own game (or at least try to ensure)
|
||||
/// </summary>
|
||||
public void SetOneRomPerGame()
|
||||
{
|
||||
// For each rom, we want to update the game to be "<game name>/<rom name>"
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(Keys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(Keys, key =>
|
||||
#else
|
||||
foreach (var key in Keys)
|
||||
#endif
|
||||
{
|
||||
var items = this[key];
|
||||
if (items == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
#else
|
||||
continue;
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
SetOneRomPerGame(items[i]);
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Strip the dates from the beginning of scene-style set names
|
||||
/// </summary>
|
||||
public void StripSceneDatesFromItems()
|
||||
internal void StripSceneDatesFromItems()
|
||||
{
|
||||
// Set the regex pattern to use
|
||||
string pattern = @"([0-9]{2}\.[0-9]{2}\.[0-9]{2}-)(.*?-.*?)";
|
||||
@@ -1184,12 +1187,13 @@ namespace SabreTools.DatFiles
|
||||
|
||||
#endregion
|
||||
|
||||
// TODO: All internal, can this be put into a better location?
|
||||
#region Splitting
|
||||
|
||||
/// <summary>
|
||||
/// Use romof tags to add roms to the children
|
||||
/// </summary>
|
||||
public void AddRomsFromBios()
|
||||
internal void AddRomsFromBios()
|
||||
{
|
||||
List<string> games = [.. Keys];
|
||||
games.Sort();
|
||||
@@ -1233,7 +1237,7 @@ namespace SabreTools.DatFiles
|
||||
/// </summary>
|
||||
/// <param name="dev">True if only child device sets are touched, false for non-device sets (default)</param>
|
||||
/// <param name="useSlotOptions">True if slotoptions tags are used as well, false otherwise</param>
|
||||
public bool AddRomsFromDevices(bool dev, bool useSlotOptions)
|
||||
internal bool AddRomsFromDevices(bool dev, bool useSlotOptions)
|
||||
{
|
||||
bool foundnew = false;
|
||||
List<string> machines = [.. Keys];
|
||||
@@ -1382,7 +1386,7 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Use cloneof tags to add roms to the children, setting the new romof tag in the process
|
||||
/// </summary>
|
||||
public void AddRomsFromParent()
|
||||
internal void AddRomsFromParent()
|
||||
{
|
||||
List<string> games = [.. Keys];
|
||||
games.Sort();
|
||||
@@ -1437,7 +1441,7 @@ namespace SabreTools.DatFiles
|
||||
/// </summary>
|
||||
/// <param name="subfolder">True to add DatItems to subfolder of parent (not including Disk), false otherwise</param>
|
||||
/// <param name="skipDedup">True to skip checking for duplicate ROMs in parent, false otherwise</param>
|
||||
public void AddRomsFromChildren(bool subfolder, bool skipDedup)
|
||||
internal void AddRomsFromChildren(bool subfolder, bool skipDedup)
|
||||
{
|
||||
List<string> games = [.. Keys];
|
||||
games.Sort();
|
||||
@@ -1563,7 +1567,7 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Remove all BIOS and device sets
|
||||
/// </summary>
|
||||
public void RemoveBiosAndDeviceSets()
|
||||
internal void RemoveBiosAndDeviceSets()
|
||||
{
|
||||
List<string> games = [.. Keys];
|
||||
games.Sort();
|
||||
@@ -1593,7 +1597,7 @@ namespace SabreTools.DatFiles
|
||||
/// Use romof tags to remove bios roms from children
|
||||
/// </summary>
|
||||
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
|
||||
public void RemoveBiosRomsFromChild(bool bios)
|
||||
internal void RemoveBiosRomsFromChild(bool bios)
|
||||
{
|
||||
// Loop through the romof tags
|
||||
List<string> games = [.. Keys];
|
||||
@@ -1640,7 +1644,7 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Use cloneof tags to remove roms from the children
|
||||
/// </summary>
|
||||
public void RemoveRomsFromChild()
|
||||
internal void RemoveRomsFromChild()
|
||||
{
|
||||
List<string> games = [.. Keys];
|
||||
games.Sort();
|
||||
@@ -1690,7 +1694,7 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Remove all romof and cloneof tags from all games
|
||||
/// </summary>
|
||||
public void RemoveTagsFromChild()
|
||||
internal void RemoveTagsFromChild()
|
||||
{
|
||||
List<string> games = [.. Keys];
|
||||
games.Sort();
|
||||
@@ -1724,13 +1728,13 @@ namespace SabreTools.DatFiles
|
||||
DatStatistics.ResetStatistics();
|
||||
|
||||
// If we have a blank Dat in any way, return
|
||||
if (items == null)
|
||||
if (_items == null)
|
||||
return;
|
||||
|
||||
// Loop through and add
|
||||
foreach (string key in items.Keys)
|
||||
foreach (string key in _items.Keys)
|
||||
{
|
||||
List<DatItem>? datItems = items[key];
|
||||
List<DatItem>? datItems = _items[key];
|
||||
if (datItems == null)
|
||||
continue;
|
||||
|
||||
@@ -1745,50 +1749,50 @@ namespace SabreTools.DatFiles
|
||||
|
||||
#region IDictionary Implementations
|
||||
|
||||
public ICollection<List<DatItem>?> Values => ((IDictionary<string, List<DatItem>?>)items).Values;
|
||||
public ICollection<List<DatItem>?> Values => ((IDictionary<string, List<DatItem>?>)_items).Values;
|
||||
|
||||
public int Count => ((ICollection<KeyValuePair<string, List<DatItem>?>>)items).Count;
|
||||
public int Count => ((ICollection<KeyValuePair<string, List<DatItem>?>>)_items).Count;
|
||||
|
||||
public bool IsReadOnly => ((ICollection<KeyValuePair<string, List<DatItem>?>>)items).IsReadOnly;
|
||||
public bool IsReadOnly => ((ICollection<KeyValuePair<string, List<DatItem>?>>)_items).IsReadOnly;
|
||||
|
||||
public bool TryGetValue(string key, out List<DatItem>? value)
|
||||
{
|
||||
return ((IDictionary<string, List<DatItem>?>)items).TryGetValue(key, out value);
|
||||
return ((IDictionary<string, List<DatItem>?>)_items).TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
public void Add(KeyValuePair<string, List<DatItem>?> item)
|
||||
{
|
||||
((ICollection<KeyValuePair<string, List<DatItem>?>>)items).Add(item);
|
||||
((ICollection<KeyValuePair<string, List<DatItem>?>>)_items).Add(item);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
((ICollection<KeyValuePair<string, List<DatItem>?>>)items).Clear();
|
||||
((ICollection<KeyValuePair<string, List<DatItem>?>>)_items).Clear();
|
||||
}
|
||||
|
||||
public bool Contains(KeyValuePair<string, List<DatItem>?> item)
|
||||
{
|
||||
return ((ICollection<KeyValuePair<string, List<DatItem>?>>)items).Contains(item);
|
||||
return ((ICollection<KeyValuePair<string, List<DatItem>?>>)_items).Contains(item);
|
||||
}
|
||||
|
||||
public void CopyTo(KeyValuePair<string, List<DatItem>?>[] array, int arrayIndex)
|
||||
{
|
||||
((ICollection<KeyValuePair<string, List<DatItem>?>>)items).CopyTo(array, arrayIndex);
|
||||
((ICollection<KeyValuePair<string, List<DatItem>?>>)_items).CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
public bool Remove(KeyValuePair<string, List<DatItem>?> item)
|
||||
{
|
||||
return ((ICollection<KeyValuePair<string, List<DatItem>?>>)items).Remove(item);
|
||||
return ((ICollection<KeyValuePair<string, List<DatItem>?>>)_items).Remove(item);
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, List<DatItem>?>> GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable<KeyValuePair<string, List<DatItem>?>>)items).GetEnumerator();
|
||||
return ((IEnumerable<KeyValuePair<string, List<DatItem>?>>)_items).GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable)items).GetEnumerator();
|
||||
return ((IEnumerable)_items).GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -286,7 +286,7 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Remove any keys that have null or empty values
|
||||
/// </summary>
|
||||
public void ClearEmpty()
|
||||
internal void ClearEmpty()
|
||||
{
|
||||
var keys = Array.FindAll(SortedKeys, k => k != null);
|
||||
foreach (string key in keys)
|
||||
@@ -308,7 +308,7 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Remove all items marked for removal
|
||||
/// </summary>
|
||||
public void ClearMarked()
|
||||
internal void ClearMarked()
|
||||
{
|
||||
var itemIndices = _items.Keys;
|
||||
foreach (long itemIndex in itemIndices)
|
||||
@@ -594,7 +594,7 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="lower">True if the key should be lowercased (default), false otherwise</param>
|
||||
/// <param name="norename">True if games should only be compared on game and file name, false if system and source are counted</param>
|
||||
/// <returns></returns>
|
||||
public void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true)
|
||||
internal void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true)
|
||||
{
|
||||
// If the sorted type isn't the same, we want to sort the dictionary accordingly
|
||||
if (_bucketedBy != bucketBy && bucketBy != ItemKey.NULL)
|
||||
@@ -618,7 +618,7 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="datItem">Item to try to match</param>
|
||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
||||
/// <returns>List of matched DatItem objects</returns>
|
||||
public Dictionary<long, DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
|
||||
internal Dictionary<long, DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
|
||||
{
|
||||
Dictionary<long, DatItem> output = [];
|
||||
|
||||
@@ -663,7 +663,7 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="datItem">Item to try to match</param>
|
||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
||||
/// <returns>List of matched DatItem objects</returns>
|
||||
public Dictionary<long, DatItem> GetDuplicates(KeyValuePair<long, DatItem> datItem, bool sorted = false)
|
||||
internal Dictionary<long, DatItem> GetDuplicates(KeyValuePair<long, DatItem> datItem, bool sorted = false)
|
||||
{
|
||||
Dictionary<long, DatItem> output = [];
|
||||
|
||||
@@ -708,7 +708,7 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="datItem">Item to try to match</param>
|
||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
||||
/// <returns>True if it contains the rom, false otherwise</returns>
|
||||
public bool HasDuplicates(KeyValuePair<long, DatItem> datItem, bool sorted = false)
|
||||
internal bool HasDuplicates(KeyValuePair<long, DatItem> datItem, bool sorted = false)
|
||||
{
|
||||
// Check for an empty rom list first
|
||||
if (DatStatistics.TotalCount == 0)
|
||||
@@ -1206,13 +1206,14 @@ namespace SabreTools.DatFiles
|
||||
|
||||
#endregion
|
||||
|
||||
// TODO: All internal, can this be put into a better location?
|
||||
#region Filtering
|
||||
|
||||
/// <summary>
|
||||
/// Execute all filters in a filter runner on the items in the dictionary
|
||||
/// </summary>
|
||||
/// <param name="filterRunner">Preconfigured filter runner to use</param>
|
||||
public void ExecuteFilters(FilterRunner filterRunner)
|
||||
internal void ExecuteFilters(FilterRunner filterRunner)
|
||||
{
|
||||
List<string> keys = [.. SortedKeys];
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
@@ -1235,7 +1236,7 @@ namespace SabreTools.DatFiles
|
||||
/// Use game descriptions as names, updating cloneof/romof/sampleof
|
||||
/// </summary>
|
||||
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||
public void MachineDescriptionToName(bool throwOnError = false)
|
||||
internal void MachineDescriptionToName(bool throwOnError = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -1251,6 +1252,39 @@ namespace SabreTools.DatFiles
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensure that all roms are in their own game (or at least try to ensure)
|
||||
/// </summary>
|
||||
internal void SetOneRomPerGame()
|
||||
{
|
||||
// For each rom, we want to update the game to be "<game name>/<rom name>"
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(SortedKeys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(SortedKeys, key =>
|
||||
#else
|
||||
foreach (var key in SortedKeys)
|
||||
#endif
|
||||
{
|
||||
var items = GetItemsForBucket(key);
|
||||
if (items == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
#else
|
||||
continue;
|
||||
#endif
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
SetOneRomPerGame(item);
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter a DAT using 1G1R logic given an ordered set of regions
|
||||
/// </summary>
|
||||
@@ -1265,7 +1299,7 @@ namespace SabreTools.DatFiles
|
||||
/// to clone sets based on name, nor does it have the ability to match on the
|
||||
/// Release DatItem type.
|
||||
/// </remarks>
|
||||
public void SetOneGamePerRegion(List<string> regionList)
|
||||
internal void SetOneGamePerRegion(List<string> regionList)
|
||||
{
|
||||
// If we have null region list, make it empty
|
||||
regionList ??= [];
|
||||
@@ -1351,43 +1385,10 @@ namespace SabreTools.DatFiles
|
||||
RemoveTagsFromChild();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensure that all roms are in their own game (or at least try to ensure)
|
||||
/// </summary>
|
||||
public void SetOneRomPerGame()
|
||||
{
|
||||
// For each rom, we want to update the game to be "<game name>/<rom name>"
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(SortedKeys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(SortedKeys, key =>
|
||||
#else
|
||||
foreach (var key in SortedKeys)
|
||||
#endif
|
||||
{
|
||||
var items = GetItemsForBucket(key);
|
||||
if (items == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
#else
|
||||
continue;
|
||||
#endif
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
SetOneRomPerGame(item);
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Strip the dates from the beginning of scene-style set names
|
||||
/// </summary>
|
||||
public void StripSceneDatesFromItems()
|
||||
internal void StripSceneDatesFromItems()
|
||||
{
|
||||
// Set the regex pattern to use
|
||||
string pattern = @"([0-9]{2}\.[0-9]{2}\.[0-9]{2}-)(.*?-.*?)";
|
||||
@@ -1599,12 +1600,13 @@ namespace SabreTools.DatFiles
|
||||
|
||||
#endregion
|
||||
|
||||
// TODO: All internal, can this be put into a better location?
|
||||
#region Splitting
|
||||
|
||||
/// <summary>
|
||||
/// Use romof tags to add roms to the children
|
||||
/// </summary>
|
||||
public void AddRomsFromBios()
|
||||
internal void AddRomsFromBios()
|
||||
{
|
||||
List<string> games = [.. SortedKeys];
|
||||
foreach (string game in games)
|
||||
@@ -1650,7 +1652,7 @@ namespace SabreTools.DatFiles
|
||||
/// </summary>
|
||||
/// <param name="dev">True if only child device sets are touched, false for non-device sets</param>
|
||||
/// <param name="useSlotOptions">True if slotoptions tags are used as well, false otherwise</param>
|
||||
public bool AddRomsFromDevices(bool dev, bool useSlotOptions)
|
||||
internal bool AddRomsFromDevices(bool dev, bool useSlotOptions)
|
||||
{
|
||||
bool foundnew = false;
|
||||
List<string> games = [.. SortedKeys];
|
||||
@@ -1812,7 +1814,7 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Use cloneof tags to add roms to the children, setting the new romof tag in the process
|
||||
/// </summary>
|
||||
public void AddRomsFromParent()
|
||||
internal void AddRomsFromParent()
|
||||
{
|
||||
List<string> games = [.. SortedKeys];
|
||||
foreach (string game in games)
|
||||
@@ -1875,7 +1877,7 @@ namespace SabreTools.DatFiles
|
||||
/// </summary>
|
||||
/// <param name="subfolder">True to add DatItems to subfolder of parent (not including Disk), false otherwise</param>
|
||||
/// <param name="skipDedup">True to skip checking for duplicate ROMs in parent, false otherwise</param>
|
||||
public void AddRomsFromChildren(bool subfolder, bool skipDedup)
|
||||
internal void AddRomsFromChildren(bool subfolder, bool skipDedup)
|
||||
{
|
||||
List<string> games = [.. SortedKeys];
|
||||
foreach (string game in games)
|
||||
@@ -2002,7 +2004,7 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Remove all BIOS and device sets
|
||||
/// </summary>
|
||||
public void RemoveBiosAndDeviceSets()
|
||||
internal void RemoveBiosAndDeviceSets()
|
||||
{
|
||||
List<string> games = [.. SortedKeys];
|
||||
foreach (string game in games)
|
||||
@@ -2033,7 +2035,7 @@ namespace SabreTools.DatFiles
|
||||
/// Use romof tags to remove bios roms from children
|
||||
/// </summary>
|
||||
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
|
||||
public void RemoveBiosRomsFromChild(bool bios)
|
||||
internal void RemoveBiosRomsFromChild(bool bios)
|
||||
{
|
||||
// Loop through the romof tags
|
||||
List<string> games = [.. SortedKeys];
|
||||
@@ -2078,7 +2080,7 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Use cloneof tags to remove roms from the children
|
||||
/// </summary>
|
||||
public void RemoveRomsFromChild()
|
||||
internal void RemoveRomsFromChild()
|
||||
{
|
||||
List<string> games = [.. SortedKeys];
|
||||
foreach (string game in games)
|
||||
@@ -2134,7 +2136,7 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Remove all romof and cloneof tags from all games
|
||||
/// </summary>
|
||||
public void RemoveTagsFromChild()
|
||||
internal void RemoveTagsFromChild()
|
||||
{
|
||||
List<string> games = [.. SortedKeys];
|
||||
foreach (string game in games)
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="SabreTools.DatFiles.Test" />
|
||||
<InternalsVisibleTo Include="SabreTools.Test" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -106,43 +106,25 @@ namespace SabreTools.DatTools
|
||||
|
||||
// Bucket and dedupe according to the flag
|
||||
if (DedupeRoms == DedupeType.Full)
|
||||
{
|
||||
datFile.Items.BucketBy(ItemKey.CRC, DedupeRoms);
|
||||
datFile.ItemsDB.BucketBy(ItemKey.CRC, DedupeRoms);
|
||||
}
|
||||
datFile.BucketBy(ItemKey.CRC, DedupeRoms);
|
||||
else if (DedupeRoms == DedupeType.Game)
|
||||
{
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeRoms);
|
||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeRoms);
|
||||
}
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeRoms);
|
||||
|
||||
// Process description to machine name
|
||||
if (DescriptionAsName == true)
|
||||
{
|
||||
datFile.Items.MachineDescriptionToName(throwOnError);
|
||||
datFile.ItemsDB.MachineDescriptionToName(throwOnError);
|
||||
}
|
||||
datFile.MachineDescriptionToName(throwOnError);
|
||||
|
||||
// If we are removing scene dates, do that now
|
||||
if (SceneDateStrip == true)
|
||||
{
|
||||
datFile.Items.StripSceneDatesFromItems();
|
||||
datFile.ItemsDB.StripSceneDatesFromItems();
|
||||
}
|
||||
datFile.StripSceneDatesFromItems();
|
||||
|
||||
// Run the one rom per game logic, if required
|
||||
if (OneGamePerRegion == true && RegionList != null)
|
||||
{
|
||||
datFile.Items.SetOneGamePerRegion(RegionList);
|
||||
datFile.ItemsDB.SetOneGamePerRegion(RegionList);
|
||||
}
|
||||
datFile.SetOneGamePerRegion(RegionList);
|
||||
|
||||
// Run the one rom per game logic, if required
|
||||
if (OneRomPerGame == true)
|
||||
{
|
||||
datFile.Items.SetOneRomPerGame();
|
||||
datFile.ItemsDB.SetOneRomPerGame();
|
||||
}
|
||||
datFile.SetOneRomPerGame();
|
||||
|
||||
// Remove all marked items
|
||||
datFile.ClearMarked();
|
||||
@@ -174,7 +156,7 @@ namespace SabreTools.DatTools
|
||||
foreach (string key in keys)
|
||||
{
|
||||
// For every item in the current key
|
||||
var items = datFile.Items[key];
|
||||
var items = datFile.GetItemsForBucket(key);
|
||||
if (items == null)
|
||||
continue;
|
||||
|
||||
@@ -203,7 +185,7 @@ namespace SabreTools.DatTools
|
||||
foreach (string key in keys)
|
||||
{
|
||||
// For every item in the current key
|
||||
var items = datFile.ItemsDB.GetItemsForBucket(key);
|
||||
var items = datFile.GetItemsForBucketDB(key);
|
||||
if (items == null)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace SabreTools.DatTools
|
||||
try
|
||||
{
|
||||
// Bucket by game first
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
|
||||
// Create mappings based on the extra items
|
||||
var combinedMaps = CombineExtras();
|
||||
@@ -109,7 +109,7 @@ namespace SabreTools.DatTools
|
||||
continue;
|
||||
|
||||
// Get the list of DatItems for the machine
|
||||
var datItems = datFile.Items[machine];
|
||||
var datItems = datFile.GetItemsForBucket(machine);
|
||||
if (datItems == null)
|
||||
continue;
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace SabreTools.DatTools
|
||||
try
|
||||
{
|
||||
// Bucket by game first
|
||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
|
||||
// Create mappings based on the extra items
|
||||
var combinedMaps = CombineExtras();
|
||||
@@ -168,7 +168,7 @@ namespace SabreTools.DatTools
|
||||
foreach (string game in games)
|
||||
{
|
||||
// Get the list of DatItems for the machine
|
||||
var datItems = datFile.ItemsDB.GetItemsForBucket(game);
|
||||
var datItems = datFile.GetItemsForBucketDB(game);
|
||||
if (datItems == null)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -102,18 +102,14 @@ namespace SabreTools.DatTools
|
||||
_staticLogger.User("Creating device non-merged sets from the DAT");
|
||||
|
||||
// For sake of ease, the first thing we want to do is bucket by game
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
|
||||
// Now we want to loop through all of the games and set the correct information
|
||||
while (datFile.Items.AddRomsFromDevices(false, false)) ;
|
||||
while (datFile.ItemsDB.AddRomsFromDevices(false, false)) ;
|
||||
while (datFile.Items.AddRomsFromDevices(true, false)) ;
|
||||
while (datFile.ItemsDB.AddRomsFromDevices(true, false)) ;
|
||||
while (datFile.AddRomsFromDevices(false, false)) ;
|
||||
while (datFile.AddRomsFromDevices(true, false)) ;
|
||||
|
||||
// Then, remove the romof and cloneof tags so it's not picked up by the manager
|
||||
datFile.Items.RemoveTagsFromChild();
|
||||
datFile.ItemsDB.RemoveTagsFromChild();
|
||||
datFile.RemoveTagsFromChild();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -125,22 +121,17 @@ namespace SabreTools.DatTools
|
||||
_staticLogger.User("Creating fully merged sets from the DAT");
|
||||
|
||||
// For sake of ease, the first thing we want to do is bucket by game
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
|
||||
// Now we want to loop through all of the games and set the correct information
|
||||
datFile.Items.AddRomsFromChildren(true, false);
|
||||
datFile.ItemsDB.AddRomsFromChildren(true, false);
|
||||
datFile.AddRomsFromChildren(true, false);
|
||||
|
||||
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
||||
datFile.Items.RemoveBiosRomsFromChild(false);
|
||||
datFile.ItemsDB.RemoveBiosRomsFromChild(false);
|
||||
datFile.Items.RemoveBiosRomsFromChild(true);
|
||||
datFile.ItemsDB.RemoveBiosRomsFromChild(true);
|
||||
datFile.RemoveBiosRomsFromChild(false);
|
||||
datFile.RemoveBiosRomsFromChild(true);
|
||||
|
||||
// Finally, remove the romof and cloneof tags so it's not picked up by the manager
|
||||
datFile.Items.RemoveTagsFromChild();
|
||||
datFile.ItemsDB.RemoveTagsFromChild();
|
||||
datFile.RemoveTagsFromChild();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -152,24 +143,18 @@ namespace SabreTools.DatTools
|
||||
_staticLogger.User("Creating fully non-merged sets from the DAT");
|
||||
|
||||
// For sake of ease, the first thing we want to do is bucket by game
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
|
||||
// Now we want to loop through all of the games and set the correct information
|
||||
while (datFile.Items.AddRomsFromDevices(true, true)) ;
|
||||
while (datFile.ItemsDB.AddRomsFromDevices(true, true)) ;
|
||||
datFile.Items.AddRomsFromDevices(false, true);
|
||||
datFile.ItemsDB.AddRomsFromDevices(false, true);
|
||||
datFile.Items.AddRomsFromParent();
|
||||
datFile.ItemsDB.AddRomsFromParent();
|
||||
while (datFile.AddRomsFromDevices(true, true)) ;
|
||||
datFile.AddRomsFromDevices(false, true);
|
||||
datFile.AddRomsFromParent();
|
||||
|
||||
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
||||
datFile.Items.AddRomsFromBios();
|
||||
datFile.ItemsDB.AddRomsFromBios();
|
||||
datFile.AddRomsFromBios();
|
||||
|
||||
// Then, remove the romof and cloneof tags so it's not picked up by the manager
|
||||
datFile.Items.RemoveTagsFromChild();
|
||||
datFile.ItemsDB.RemoveTagsFromChild();
|
||||
datFile.RemoveTagsFromChild();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -181,22 +166,17 @@ namespace SabreTools.DatTools
|
||||
_staticLogger.User("Creating merged sets from the DAT");
|
||||
|
||||
// For sake of ease, the first thing we want to do is bucket by game
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
|
||||
// Now we want to loop through all of the games and set the correct information
|
||||
datFile.Items.AddRomsFromChildren(true, true);
|
||||
datFile.ItemsDB.AddRomsFromChildren(true, true);
|
||||
datFile.AddRomsFromChildren(true, true);
|
||||
|
||||
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
||||
datFile.Items.RemoveBiosRomsFromChild(false);
|
||||
datFile.ItemsDB.RemoveBiosRomsFromChild(false);
|
||||
datFile.Items.RemoveBiosRomsFromChild(true);
|
||||
datFile.ItemsDB.RemoveBiosRomsFromChild(true);
|
||||
datFile.RemoveBiosRomsFromChild(false);
|
||||
datFile.RemoveBiosRomsFromChild(true);
|
||||
|
||||
// Finally, remove the romof and cloneof tags so it's not picked up by the manager
|
||||
datFile.Items.RemoveTagsFromChild();
|
||||
datFile.ItemsDB.RemoveTagsFromChild();
|
||||
datFile.RemoveTagsFromChild();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -208,22 +188,17 @@ namespace SabreTools.DatTools
|
||||
_staticLogger.User("Creating non-merged sets from the DAT");
|
||||
|
||||
// For sake of ease, the first thing we want to do is bucket by game
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
|
||||
// Now we want to loop through all of the games and set the correct information
|
||||
datFile.Items.AddRomsFromParent();
|
||||
datFile.ItemsDB.AddRomsFromParent();
|
||||
datFile.AddRomsFromParent();
|
||||
|
||||
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
||||
datFile.Items.RemoveBiosRomsFromChild(false);
|
||||
datFile.ItemsDB.RemoveBiosRomsFromChild(false);
|
||||
datFile.Items.RemoveBiosRomsFromChild(true);
|
||||
datFile.ItemsDB.RemoveBiosRomsFromChild(true);
|
||||
datFile.RemoveBiosRomsFromChild(false);
|
||||
datFile.RemoveBiosRomsFromChild(true);
|
||||
|
||||
// Finally, remove the romof and cloneof tags so it's not picked up by the manager
|
||||
datFile.Items.RemoveTagsFromChild();
|
||||
datFile.ItemsDB.RemoveTagsFromChild();
|
||||
datFile.RemoveTagsFromChild();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -235,22 +210,17 @@ namespace SabreTools.DatTools
|
||||
_staticLogger.User("Creating split sets from the DAT");
|
||||
|
||||
// For sake of ease, the first thing we want to do is bucket by game
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
|
||||
// Now we want to loop through all of the games and set the correct information
|
||||
datFile.Items.RemoveRomsFromChild();
|
||||
datFile.ItemsDB.RemoveRomsFromChild();
|
||||
datFile.RemoveRomsFromChild();
|
||||
|
||||
// Now that we have looped through the cloneof tags, we loop through the romof tags
|
||||
datFile.Items.RemoveBiosRomsFromChild(false);
|
||||
datFile.ItemsDB.RemoveBiosRomsFromChild(false);
|
||||
datFile.Items.RemoveBiosRomsFromChild(true);
|
||||
datFile.ItemsDB.RemoveBiosRomsFromChild(true);
|
||||
datFile.RemoveBiosRomsFromChild(false);
|
||||
datFile.RemoveBiosRomsFromChild(true);
|
||||
|
||||
// Finally, remove the romof and cloneof tags so it's not picked up by the manager
|
||||
datFile.Items.RemoveTagsFromChild();
|
||||
datFile.ItemsDB.RemoveTagsFromChild();
|
||||
datFile.RemoveTagsFromChild();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace SabreTools.DatTools
|
||||
#region Perform setup
|
||||
|
||||
// If the DAT is not populated and inverse is not set, inform the user and quit
|
||||
if (datFile.Items.DatStatistics.TotalCount == 0 && !inverse)
|
||||
if (datFile.DatStatistics.TotalCount == 0 && !inverse)
|
||||
{
|
||||
_staticLogger.User("No entries were found to rebuild, exiting...");
|
||||
return false;
|
||||
@@ -106,7 +106,7 @@ namespace SabreTools.DatTools
|
||||
return success;
|
||||
|
||||
// Now that we have a list of depots, we want to bucket the input DAT by SHA-1
|
||||
datFile.Items.BucketBy(ItemKey.SHA1, DedupeType.None);
|
||||
datFile.BucketBy(ItemKey.SHA1, DedupeType.None);
|
||||
|
||||
// Then we want to loop through each of the hashes and see if we can rebuild
|
||||
List<string> keys = [.. datFile.Items.SortedKeys];
|
||||
@@ -147,10 +147,10 @@ namespace SabreTools.DatTools
|
||||
continue;
|
||||
|
||||
// Ensure we are sorted correctly (some other calls can change this)
|
||||
//datFile.Items.BucketBy(ItemKey.SHA1, DedupeType.None);
|
||||
//datFile.BucketBy(ItemKey.SHA1, DedupeType.None);
|
||||
|
||||
// If there are no items in the hash, we continue
|
||||
var items = datFile.Items[hash];
|
||||
var items = datFile.GetItemsForBucket(hash);
|
||||
if (items == null || items.Count == 0)
|
||||
continue;
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace SabreTools.DatTools
|
||||
#region Perform setup
|
||||
|
||||
// If the DAT is not populated and inverse is not set, inform the user and quit
|
||||
if (datFile.Items.DatStatistics.TotalCount == 0 && !inverse)
|
||||
if (datFile.DatStatistics.TotalCount == 0 && !inverse)
|
||||
{
|
||||
_staticLogger.User("No entries were found to rebuild, exiting...");
|
||||
return false;
|
||||
@@ -451,7 +451,7 @@ namespace SabreTools.DatTools
|
||||
if (outputFormat == OutputFormat.Folder && datFile.Header.GetStringFieldValue(Models.Metadata.Header.ForcePackingKey).AsEnumValue<PackingFlag>() == PackingFlag.Partial)
|
||||
{
|
||||
shouldCheck = true;
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, lower: false);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None, lower: false);
|
||||
}
|
||||
|
||||
// Now loop through the list and rebuild accordingly
|
||||
@@ -463,7 +463,7 @@ namespace SabreTools.DatTools
|
||||
continue;
|
||||
|
||||
// If we should check for the items in the machine
|
||||
var items = datFile.Items[machine.GetStringFieldValue(Models.Metadata.Machine.NameKey)!];
|
||||
var items = datFile.GetItemsForBucket(machine.GetStringFieldValue(Models.Metadata.Machine.NameKey)!);
|
||||
if (shouldCheck && items!.Count > 1)
|
||||
outputFormat = OutputFormat.Folder;
|
||||
else if (shouldCheck && items!.Count == 1)
|
||||
@@ -553,7 +553,7 @@ namespace SabreTools.DatTools
|
||||
private static bool ShouldRebuild(DatFile datFile, DatItem datItem, Stream? stream, bool inverse, out List<DatItem> dupes)
|
||||
{
|
||||
// Find if the file has duplicates in the DAT
|
||||
dupes = datFile.Items.GetDuplicates(datItem);
|
||||
dupes = datFile.GetDuplicates(datItem);
|
||||
bool hasDuplicates = dupes.Count > 0;
|
||||
|
||||
// If we have duplicates but we're filtering
|
||||
@@ -609,7 +609,7 @@ namespace SabreTools.DatTools
|
||||
private static bool ShouldRebuildDB(DatFile datFile, KeyValuePair<long, DatItem> datItem, Stream? stream, bool inverse, out Dictionary<long, DatItem> dupes)
|
||||
{
|
||||
// Find if the file has duplicates in the DAT
|
||||
dupes = datFile.ItemsDB.GetDuplicates(datItem);
|
||||
dupes = datFile.GetDuplicatesDB(datItem);
|
||||
bool hasDuplicates = dupes.Count > 0;
|
||||
|
||||
// If we have duplicates but we're filtering
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace SabreTools.DatTools
|
||||
public static (DatFile? extADat, DatFile? extBDat) SplitByExtension(DatFile datFile, List<string> extA, List<string> extB)
|
||||
{
|
||||
// If roms is empty, return false
|
||||
if (datFile.Items.DatStatistics.TotalCount == 0)
|
||||
if (datFile.DatStatistics.TotalCount == 0)
|
||||
return (null, null);
|
||||
|
||||
InternalStopwatch watch = new($"Splitting DAT by extension");
|
||||
@@ -73,7 +73,7 @@ namespace SabreTools.DatTools
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
var items = datFile.Items[key];
|
||||
var items = datFile.GetItemsForBucket(key);
|
||||
if (items == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
@@ -249,7 +249,7 @@ namespace SabreTools.DatTools
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
var items = datFile.Items[key];
|
||||
var items = datFile.GetItemsForBucket(key);
|
||||
if (items == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
@@ -493,7 +493,7 @@ namespace SabreTools.DatTools
|
||||
InternalStopwatch watch = new($"Splitting DAT by level");
|
||||
|
||||
// First, bucket by games so that we can do the right thing
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, lower: false, norename: true);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None, lower: false, norename: true);
|
||||
|
||||
// Create a temporary DAT to add things to
|
||||
DatFile tempDat = DatFileTool.CreateDatFile(datFile.Header);
|
||||
@@ -521,7 +521,7 @@ namespace SabreTools.DatTools
|
||||
}
|
||||
|
||||
// Clean the input list and set all games to be pathless
|
||||
List<DatItem>? items = datFile.Items[key];
|
||||
List<DatItem>? items = datFile.GetItemsForBucket(key);
|
||||
if (items == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
@@ -638,7 +638,7 @@ namespace SabreTools.DatTools
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem>? items = datFile.Items[key];
|
||||
List<DatItem>? items = datFile.GetItemsForBucket(key);
|
||||
if (items == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
@@ -777,7 +777,7 @@ namespace SabreTools.DatTools
|
||||
InternalStopwatch watch = new($"Splitting DAT by total size");
|
||||
|
||||
// Sort the DatFile by machine name
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
|
||||
// Get the keys in a known order for easier sorting
|
||||
var keys = datFile.Items.SortedKeys;
|
||||
@@ -920,7 +920,7 @@ namespace SabreTools.DatTools
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem> items = DatFileTool.Merge(datFile.Items[key]);
|
||||
List<DatItem> items = DatFileTool.Merge(datFile.GetItemsForBucket(key));
|
||||
|
||||
// If the rom list is empty or null, just skip it
|
||||
if (items == null || items.Count == 0)
|
||||
|
||||
@@ -81,21 +81,18 @@ namespace SabreTools.DatTools
|
||||
// Add single DAT stats (if asked)
|
||||
if (single)
|
||||
{
|
||||
DatStatistics individualStats = datdata.Items.DatStatistics;
|
||||
//DatStatistics individualStats = datdata.ItemsDB.DatStatistics;
|
||||
DatStatistics individualStats = datdata.DatStatistics;
|
||||
individualStats.DisplayName = datdata.Header.GetStringFieldValue(DatHeader.FileNameKey);
|
||||
individualStats.MachineCount = datdata.Items.Keys.Count;
|
||||
stats.Add(individualStats);
|
||||
}
|
||||
|
||||
// Add single DAT stats to dir
|
||||
dirStats.AddStatistics(datdata.Items.DatStatistics);
|
||||
//dirStats.AddStatistics(datdata.ItemsDB.DatStatistics);
|
||||
dirStats.AddStatistics(datdata.DatStatistics);
|
||||
dirStats.GameCount += datdata.Items.Keys.Count;
|
||||
|
||||
// Add single DAT stats to totals
|
||||
totalStats.AddStatistics(datdata.Items.DatStatistics);
|
||||
//totalStats.AddStatistics(datdata.ItemsDB.DatStatistics);
|
||||
totalStats.AddStatistics(datdata.DatStatistics);
|
||||
totalStats.GameCount += datdata.Items.Keys.Count;
|
||||
|
||||
// Make sure to assign the new directory
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace SabreTools.DatTools
|
||||
return success;
|
||||
|
||||
// Now that we have a list of depots, we want to bucket the input DAT by SHA-1
|
||||
datFile.Items.BucketBy(ItemKey.SHA1, DedupeType.None);
|
||||
datFile.BucketBy(ItemKey.SHA1, DedupeType.None);
|
||||
|
||||
// Then we want to loop through each of the hashes and see if we can rebuild
|
||||
List<string> keys = [.. datFile.Items.SortedKeys];
|
||||
@@ -96,8 +96,8 @@ namespace SabreTools.DatTools
|
||||
continue;
|
||||
|
||||
// Now we want to remove all duplicates from the DAT
|
||||
datFile.Items.GetDuplicates(fileinfo.ConvertToRom())
|
||||
.AddRange(datFile.Items.GetDuplicates(fileinfo.ConvertToDisk()));
|
||||
datFile.GetDuplicates(fileinfo.ConvertToRom())
|
||||
.AddRange(datFile.GetDuplicates(fileinfo.ConvertToDisk()));
|
||||
}
|
||||
|
||||
watch.Stop();
|
||||
@@ -140,7 +140,7 @@ namespace SabreTools.DatTools
|
||||
return success;
|
||||
|
||||
// Now that we have a list of depots, we want to bucket the input DAT by SHA-1
|
||||
datFile.ItemsDB.BucketBy(ItemKey.SHA1, DedupeType.None);
|
||||
datFile.BucketBy(ItemKey.SHA1, DedupeType.None);
|
||||
|
||||
// Then we want to loop through each of the hashes and see if we can rebuild
|
||||
List<string> keys = [.. datFile.ItemsDB.SortedKeys];
|
||||
@@ -181,8 +181,8 @@ namespace SabreTools.DatTools
|
||||
continue;
|
||||
|
||||
// Now we want to remove all duplicates from the DAT
|
||||
datFile.ItemsDB.GetDuplicates(new KeyValuePair<long, DatItem>(-1, fileinfo.ConvertToRom()))
|
||||
.Concat(datFile.ItemsDB.GetDuplicates(new KeyValuePair<long, DatItem>(-1, fileinfo.ConvertToDisk())));
|
||||
datFile.GetDuplicatesDB(new KeyValuePair<long, DatItem>(-1, fileinfo.ConvertToRom()))
|
||||
.Concat(datFile.GetDuplicatesDB(new KeyValuePair<long, DatItem>(-1, fileinfo.ConvertToDisk())));
|
||||
}
|
||||
|
||||
watch.Stop();
|
||||
@@ -211,15 +211,15 @@ namespace SabreTools.DatTools
|
||||
// Force bucketing according to the flags
|
||||
datFile.Items.SetBucketedBy(ItemKey.NULL);
|
||||
if (hashOnly)
|
||||
datFile.Items.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||
datFile.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||
else
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.Full);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.Full);
|
||||
|
||||
// Then mark items for removal
|
||||
List<string> keys = [.. datFile.Items.SortedKeys];
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<DatItem>? items = datFile.Items[key];
|
||||
List<DatItem>? items = datFile.GetItemsForBucket(key);
|
||||
if (items == null)
|
||||
continue;
|
||||
|
||||
@@ -259,9 +259,9 @@ namespace SabreTools.DatTools
|
||||
|
||||
// Force bucketing according to the flags
|
||||
if (hashOnly)
|
||||
datFile.ItemsDB.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||
datFile.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||
else
|
||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.Full);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.Full);
|
||||
|
||||
// Then mark items for removal
|
||||
List<string> keys = [.. datFile.ItemsDB.SortedKeys];
|
||||
|
||||
@@ -77,12 +77,10 @@ namespace SabreTools.DatTools
|
||||
EnsureHeaderFields(datFile);
|
||||
|
||||
// Bucket roms by game name, if not already
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||
|
||||
// Output the number of items we're going to be writing
|
||||
_staticLogger.User($"A total of {datFile.Items.DatStatistics.TotalCount - datFile.Items.DatStatistics.RemovedCount} items will be written out to '{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}'");
|
||||
//logger.User($"A total of {datFile.ItemsDB.DatStatistics.TotalCount - datFile.ItemsDB.DatStatistics.RemovedCount} items will be written out to '{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}'");
|
||||
_staticLogger.User($"A total of {datFile.DatStatistics.TotalCount - datFile.DatStatistics.RemovedCount} items will be written out to '{datFile.Header.GetStringFieldValue(DatHeader.FileNameKey)}'");
|
||||
|
||||
// Get the outfile names
|
||||
Dictionary<DatFormat, string> outfiles = datFile.Header.CreateOutFileNames(outDir!, overwrite);
|
||||
@@ -133,33 +131,21 @@ namespace SabreTools.DatTools
|
||||
/// <param name="datFile">Current DatFile object to write from</param>
|
||||
public static void WriteStatsToConsole(DatFile datFile)
|
||||
{
|
||||
long diskCount = datFile.Items.DatStatistics.GetItemCount(ItemType.Disk);
|
||||
long mediaCount = datFile.Items.DatStatistics.GetItemCount(ItemType.Media);
|
||||
long romCount = datFile.Items.DatStatistics.GetItemCount(ItemType.Rom);
|
||||
long diskCount = datFile.DatStatistics.GetItemCount(ItemType.Disk);
|
||||
long mediaCount = datFile.DatStatistics.GetItemCount(ItemType.Media);
|
||||
long romCount = datFile.DatStatistics.GetItemCount(ItemType.Rom);
|
||||
|
||||
if (diskCount + mediaCount + romCount == 0)
|
||||
datFile.Items.RecalculateStats();
|
||||
|
||||
diskCount = datFile.ItemsDB.DatStatistics.GetItemCount(ItemType.Disk);
|
||||
mediaCount = datFile.ItemsDB.DatStatistics.GetItemCount(ItemType.Media);
|
||||
romCount = datFile.ItemsDB.DatStatistics.GetItemCount(ItemType.Rom);
|
||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
|
||||
if (diskCount + mediaCount + romCount == 0)
|
||||
datFile.ItemsDB.RecalculateStats();
|
||||
|
||||
datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||
|
||||
datFile.Items.DatStatistics.DisplayName = datFile.Header.GetStringFieldValue(DatHeader.FileNameKey);
|
||||
datFile.Items.DatStatistics.MachineCount = datFile.Items.Keys.Count;
|
||||
|
||||
datFile.ItemsDB.DatStatistics.DisplayName = datFile.Header.GetStringFieldValue(DatHeader.FileNameKey);
|
||||
datFile.ItemsDB.DatStatistics.MachineCount = datFile.Items.Keys.Count;
|
||||
datFile.DatStatistics.DisplayName = datFile.Header.GetStringFieldValue(DatHeader.FileNameKey);
|
||||
datFile.DatStatistics.MachineCount = datFile.Items.Keys.Count;
|
||||
|
||||
List<DatStatistics> statsList =
|
||||
[
|
||||
datFile.Items.DatStatistics,
|
||||
//datFile.ItemsDB.DatStatistics,
|
||||
datFile.DatStatistics,
|
||||
];
|
||||
var consoleOutput = BaseReport.Create(StatReportFormat.None, statsList);
|
||||
consoleOutput!.WriteToFile(null, true, true);
|
||||
@@ -232,13 +218,13 @@ namespace SabreTools.DatTools
|
||||
datFile.ItemsDB.RecalculateStats();
|
||||
|
||||
// If there's nothing there, abort
|
||||
if (datFile.Items.DatStatistics.TotalCount == 0)
|
||||
if (datFile.DatStatistics.TotalCount == 0)
|
||||
return false;
|
||||
// if (datFile.ItemsDB.DatStatistics.TotalCount == 0)
|
||||
// return false;
|
||||
|
||||
// If every item is removed, abort
|
||||
if (datFile.Items.DatStatistics.TotalCount == datFile.Items.DatStatistics.RemovedCount)
|
||||
if (datFile.DatStatistics.TotalCount == datFile.DatStatistics.RemovedCount)
|
||||
return false;
|
||||
// if (datFile.ItemsDB.DatStatistics.TotalCount == datFile.ItemsDB.DatStatistics.RemovedCount)
|
||||
// return false;
|
||||
|
||||
@@ -236,8 +236,7 @@ Reset the internal state: reset();";
|
||||
/// <inheritdoc/>
|
||||
public override void Process(BatchState batchState)
|
||||
{
|
||||
batchState.DatFile.Items.MachineDescriptionToName();
|
||||
batchState.DatFile.ItemsDB.MachineDescriptionToName();
|
||||
batchState.DatFile.MachineDescriptionToName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -608,8 +607,7 @@ Reset the internal state: reset();";
|
||||
/// <inheritdoc/>
|
||||
public override void Process(BatchState batchState)
|
||||
{
|
||||
batchState.DatFile.Items.SetOneGamePerRegion([.. Arguments]);
|
||||
batchState.DatFile.ItemsDB.SetOneGamePerRegion([.. Arguments]);
|
||||
batchState.DatFile.SetOneGamePerRegion([.. Arguments]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -642,8 +640,7 @@ Reset the internal state: reset();";
|
||||
/// <inheritdoc/>
|
||||
public override void Process(BatchState batchState)
|
||||
{
|
||||
batchState.DatFile.Items.SetOneRomPerGame();
|
||||
batchState.DatFile.ItemsDB.SetOneRomPerGame();
|
||||
batchState.DatFile.SetOneRomPerGame();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -777,8 +774,7 @@ Reset the internal state: reset();";
|
||||
/// <inheritdoc/>
|
||||
public override void Process(BatchState batchState)
|
||||
{
|
||||
batchState.DatFile.Items.StripSceneDatesFromItems();
|
||||
batchState.DatFile.ItemsDB.StripSceneDatesFromItems();
|
||||
batchState.DatFile.StripSceneDatesFromItems();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user