mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] Fix locking on dictionary
This commit is contained in:
@@ -30,7 +30,7 @@ namespace SabreTools.Helper.Dats
|
||||
private DatFormat _datFormat;
|
||||
private bool _excludeOf;
|
||||
private bool _mergeRoms;
|
||||
private SortedDictionary<string, List<DatItem>> _files;
|
||||
private SortedDictionary<string, List<DatItem>> _files = new SortedDictionary<string, List<DatItem>>();
|
||||
private SortedBy _sortedBy;
|
||||
|
||||
// Data specific to the Miss DAT type
|
||||
@@ -274,6 +274,8 @@ namespace SabreTools.Helper.Dats
|
||||
_files = new SortedDictionary<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
lock (_files)
|
||||
{
|
||||
// If the key is missing from the dictionary, add it
|
||||
if (!_files.ContainsKey(key))
|
||||
{
|
||||
@@ -283,6 +285,7 @@ namespace SabreTools.Helper.Dats
|
||||
// Now return the value
|
||||
return _files[key];
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
// If the dictionary is null, create it
|
||||
@@ -291,6 +294,8 @@ namespace SabreTools.Helper.Dats
|
||||
_files = new SortedDictionary<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
lock (_files)
|
||||
{
|
||||
// If the key is missing from the dictionary, add it
|
||||
if (!_files.ContainsKey(key))
|
||||
{
|
||||
@@ -301,14 +306,13 @@ namespace SabreTools.Helper.Dats
|
||||
_files[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new key to the file dictionary
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to add to</param>
|
||||
public void Add(string key)
|
||||
{
|
||||
lock (_files)
|
||||
{
|
||||
// If the dictionary is null, create it
|
||||
if (_files == null)
|
||||
@@ -316,6 +320,8 @@ namespace SabreTools.Helper.Dats
|
||||
_files = new SortedDictionary<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
lock (_files)
|
||||
{
|
||||
// If the key is missing from the dictionary, add it
|
||||
if (!_files.ContainsKey(key))
|
||||
{
|
||||
@@ -330,8 +336,6 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="key">Key in the dictionary to add to</param>
|
||||
/// <param name="value">Value to add to the dictionary</param>
|
||||
public void Add(string key, DatItem value)
|
||||
{
|
||||
lock (_files)
|
||||
{
|
||||
// If the dictionary is null, create it
|
||||
if (_files == null)
|
||||
@@ -339,6 +343,8 @@ namespace SabreTools.Helper.Dats
|
||||
_files = new SortedDictionary<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
lock (_files)
|
||||
{
|
||||
// If the key is missing from the dictionary, add it
|
||||
if (!_files.ContainsKey(key))
|
||||
{
|
||||
@@ -356,8 +362,6 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="key">Key in the dictionary to add to</param>
|
||||
/// <param name="value">Value to add to the dictionary</param>
|
||||
public void AddRange(string key, List<DatItem> value)
|
||||
{
|
||||
lock (_files)
|
||||
{
|
||||
// If the dictionary is null, create it
|
||||
if (_files == null)
|
||||
@@ -365,6 +369,8 @@ namespace SabreTools.Helper.Dats
|
||||
_files = new SortedDictionary<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
lock (_files)
|
||||
{
|
||||
// If the key is missing from the dictionary, add it
|
||||
if (!_files.ContainsKey(key))
|
||||
{
|
||||
@@ -382,8 +388,6 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="key">Key in the dictionary to check</param>
|
||||
/// <returns>True if the key exists, false otherwise</returns>
|
||||
public bool ContainsKey(string key)
|
||||
{
|
||||
lock (_files)
|
||||
{
|
||||
// If the dictionary is null, create it
|
||||
if (_files == null)
|
||||
@@ -391,6 +395,8 @@ namespace SabreTools.Helper.Dats
|
||||
_files = new SortedDictionary<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
lock (_files)
|
||||
{
|
||||
return _files.ContainsKey(key);
|
||||
}
|
||||
}
|
||||
@@ -402,8 +408,6 @@ namespace SabreTools.Helper.Dats
|
||||
public long Count
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_files)
|
||||
{
|
||||
// If the dictionary is null, create it
|
||||
if (_files == null)
|
||||
@@ -411,6 +415,8 @@ namespace SabreTools.Helper.Dats
|
||||
_files = new SortedDictionary<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
lock (_files)
|
||||
{
|
||||
return _files.Count;
|
||||
}
|
||||
}
|
||||
@@ -431,8 +437,6 @@ namespace SabreTools.Helper.Dats
|
||||
public IEnumerable<string> Keys
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_files)
|
||||
{
|
||||
// If the dictionary is null, create it
|
||||
if (_files == null)
|
||||
@@ -440,6 +444,8 @@ namespace SabreTools.Helper.Dats
|
||||
_files = new SortedDictionary<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
lock (_files)
|
||||
{
|
||||
return _files.Keys;
|
||||
}
|
||||
}
|
||||
@@ -450,8 +456,6 @@ namespace SabreTools.Helper.Dats
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
public void Remove(string key)
|
||||
{
|
||||
lock (_files)
|
||||
{
|
||||
// If the dictionary is null, create it
|
||||
if (_files == null)
|
||||
@@ -459,6 +463,8 @@ namespace SabreTools.Helper.Dats
|
||||
_files = new SortedDictionary<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
lock (_files)
|
||||
{
|
||||
// If the key is in the dictionary, remove it
|
||||
if (_files.ContainsKey(key))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user