mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] Modify "Contains" a little
This commit is contained in:
@@ -424,7 +424,7 @@ namespace RombaSharp
|
||||
{
|
||||
sldr.Read();
|
||||
string hash = sldr.GetString(0);
|
||||
if (datroot.ContainsKey(hash))
|
||||
if (datroot.Contains(hash))
|
||||
{
|
||||
datroot.Remove(hash);
|
||||
databaseDats.Add(hash);
|
||||
|
||||
@@ -402,8 +402,10 @@ namespace SabreTools.Library.Dats
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to check</param>
|
||||
/// <returns>True if the key exists, false otherwise</returns>
|
||||
public bool ContainsKey(string key)
|
||||
public bool Contains(string key)
|
||||
{
|
||||
bool contains = false;
|
||||
|
||||
// If the dictionary is null, create it
|
||||
if (_items == null)
|
||||
{
|
||||
@@ -413,13 +415,48 @@ namespace SabreTools.Library.Dats
|
||||
// If the key is null, we return false since keys can't be null
|
||||
if (key == null)
|
||||
{
|
||||
return false;
|
||||
return contains;
|
||||
}
|
||||
|
||||
lock (_items)
|
||||
{
|
||||
return _items.ContainsKey(key);
|
||||
contains = _items.ContainsKey(key);
|
||||
}
|
||||
|
||||
return contains;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get if the file dictionary contains the key and value
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to check</param>
|
||||
/// <param name="value">Value in the dictionary to check</param>
|
||||
/// <returns>True if the key exists, false otherwise</returns>
|
||||
public bool Contains(string key, DatItem value)
|
||||
{
|
||||
bool contains = false;
|
||||
|
||||
// If the dictionary is null, create it
|
||||
if (_items == null)
|
||||
{
|
||||
_items = new SortedDictionary<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
// If the key is null, we return false since keys can't be null
|
||||
if (key == null)
|
||||
{
|
||||
return contains;
|
||||
}
|
||||
|
||||
lock (_items)
|
||||
{
|
||||
if (_items.ContainsKey(key))
|
||||
{
|
||||
contains = _items.ContainsKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
return contains;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -466,10 +503,13 @@ namespace SabreTools.Library.Dats
|
||||
_items = new SortedDictionary<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
lock (_items)
|
||||
// If the key doesn't exist, return
|
||||
if (!Contains(key))
|
||||
{
|
||||
// If the key is in the dictionary, remove it
|
||||
if (_items.ContainsKey(key))
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_items)
|
||||
{
|
||||
// Remove the statistics first
|
||||
foreach (DatItem item in _items[key])
|
||||
@@ -477,10 +517,10 @@ namespace SabreTools.Library.Dats
|
||||
RemoveItemStatistics(item);
|
||||
}
|
||||
|
||||
// Remove the key from the dictionary
|
||||
_items.Remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a value from the file dictionary
|
||||
@@ -495,6 +535,12 @@ namespace SabreTools.Library.Dats
|
||||
_items = new SortedDictionary<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
// If the key and value doesn't exist, return
|
||||
if (!Contains(key, value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_items)
|
||||
{
|
||||
// While the key is in the dictionary and the item is there, remove it
|
||||
|
||||
@@ -264,7 +264,7 @@ namespace SabreTools.Library.Dats
|
||||
string key = SortAndGetKey(datdata, sorted);
|
||||
|
||||
// If the key doesn't exist, return the empty list
|
||||
if (!datdata.ContainsKey(key))
|
||||
if (!datdata.Contains(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -303,7 +303,7 @@ namespace SabreTools.Library.Dats
|
||||
string key = SortAndGetKey(datdata);
|
||||
|
||||
// If the key doesn't exist, return the empty list
|
||||
if (!datdata.ContainsKey(key))
|
||||
if (!datdata.Contains(key))
|
||||
{
|
||||
return output;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user