mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile, DatItem] Add better removal logic
This commit is contained in:
@@ -2534,6 +2534,29 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove all items marked for removal from the DAT
|
||||||
|
/// </summary>
|
||||||
|
private void RemoveMarkedItems()
|
||||||
|
{
|
||||||
|
List<string> keys = Keys;
|
||||||
|
foreach (string key in keys)
|
||||||
|
{
|
||||||
|
List<DatItem> items = this[key];
|
||||||
|
List<DatItem> newItems = new List<DatItem>();
|
||||||
|
foreach (DatItem item in items)
|
||||||
|
{
|
||||||
|
if (!item.Remove)
|
||||||
|
{
|
||||||
|
newItems.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Remove(key);
|
||||||
|
AddRange(key, newItems);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Strip the given hash types from the DAT
|
/// Strip the given hash types from the DAT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -4031,6 +4054,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
FileName = "fixDAT_" + FileName;
|
FileName = "fixDAT_" + FileName;
|
||||||
Name = "fixDAT_" + Name;
|
Name = "fixDAT_" + Name;
|
||||||
Description = "fixDAT_" + Description;
|
Description = "fixDAT_" + Description;
|
||||||
|
RemoveMarkedItems();
|
||||||
WriteToFile(outDir);
|
WriteToFile(outDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4178,6 +4202,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
FileName = "fixDAT_" + FileName;
|
FileName = "fixDAT_" + FileName;
|
||||||
Name = "fixDAT_" + Name;
|
Name = "fixDAT_" + Name;
|
||||||
Description = "fixDAT_" + Description;
|
Description = "fixDAT_" + Description;
|
||||||
|
RemoveMarkedItems();
|
||||||
WriteToFile(outDir);
|
WriteToFile(outDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace SabreTools.Library.Items
|
|||||||
|
|
||||||
// Standard item information
|
// Standard item information
|
||||||
protected string _name;
|
protected string _name;
|
||||||
private string _merge;
|
protected string _merge;
|
||||||
protected ItemType _itemType;
|
protected ItemType _itemType;
|
||||||
protected DupeType _dupeType;
|
protected DupeType _dupeType;
|
||||||
|
|
||||||
@@ -45,6 +45,7 @@ namespace SabreTools.Library.Items
|
|||||||
protected string _systemName;
|
protected string _systemName;
|
||||||
protected int _sourceId;
|
protected int _sourceId;
|
||||||
protected string _sourceName;
|
protected string _sourceName;
|
||||||
|
protected bool _remove;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -431,6 +432,11 @@ namespace SabreTools.Library.Items
|
|||||||
get { return _sourceName; }
|
get { return _sourceName; }
|
||||||
set { _sourceName = value; }
|
set { _sourceName = value; }
|
||||||
}
|
}
|
||||||
|
public bool Remove
|
||||||
|
{
|
||||||
|
get { return _remove; }
|
||||||
|
set { _remove = value; }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -582,7 +588,7 @@ namespace SabreTools.Library.Items
|
|||||||
/// List all duplicates found in a DAT based on a rom
|
/// List all duplicates found in a DAT based on a rom
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datdata">Dat to match against</param>
|
/// <param name="datdata">Dat to match against</param>
|
||||||
/// <param name="remove">True to remove matched roms from the input, false otherwise (default)</param>
|
/// <param name="remove">True to mark matched roms for removal from the input, false otherwise (default)</param>
|
||||||
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
||||||
/// <returns>List of matched DatItem objects</returns>
|
/// <returns>List of matched DatItem objects</returns>
|
||||||
public List<DatItem> GetDuplicates(DatFile datdata, bool remove = false, bool sorted = false)
|
public List<DatItem> GetDuplicates(DatFile datdata, bool remove = false, bool sorted = false)
|
||||||
@@ -607,23 +613,26 @@ namespace SabreTools.Library.Items
|
|||||||
// Try to find duplicates
|
// Try to find duplicates
|
||||||
List<DatItem> roms = datdata[key];
|
List<DatItem> roms = datdata[key];
|
||||||
List<DatItem> left = new List<DatItem>();
|
List<DatItem> left = new List<DatItem>();
|
||||||
|
for (int i = 0; i < roms.Count; i++)
|
||||||
foreach (DatItem rom in roms)
|
|
||||||
{
|
{
|
||||||
if (this.Equals(rom))
|
DatItem datItem = roms[i];
|
||||||
|
|
||||||
|
if (this.Equals(datItem))
|
||||||
{
|
{
|
||||||
output.Add(rom);
|
datItem.Remove = true;
|
||||||
|
output.Add(datItem);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
left.Add(rom);
|
left.Add(datItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're in removal mode, replace the list with the new one
|
// If we're in removal mode, add back all roms with the proper flags
|
||||||
if (remove)
|
if (remove)
|
||||||
{
|
{
|
||||||
datdata.Remove(key);
|
datdata.Remove(key);
|
||||||
|
datdata.AddRange(key, output);
|
||||||
datdata.AddRange(key, left);
|
datdata.AddRange(key, left);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user