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 DatFormat _datFormat;
|
||||||
private bool _excludeOf;
|
private bool _excludeOf;
|
||||||
private bool _mergeRoms;
|
private bool _mergeRoms;
|
||||||
private SortedDictionary<string, List<DatItem>> _files;
|
private SortedDictionary<string, List<DatItem>> _files = new SortedDictionary<string, List<DatItem>>();
|
||||||
private SortedBy _sortedBy;
|
private SortedBy _sortedBy;
|
||||||
|
|
||||||
// Data specific to the Miss DAT type
|
// Data specific to the Miss DAT type
|
||||||
@@ -274,14 +274,17 @@ namespace SabreTools.Helper.Dats
|
|||||||
_files = new SortedDictionary<string, List<DatItem>>();
|
_files = new SortedDictionary<string, List<DatItem>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the key is missing from the dictionary, add it
|
lock (_files)
|
||||||
if (!_files.ContainsKey(key))
|
|
||||||
{
|
{
|
||||||
_files.Add(key, new List<DatItem>());
|
// If the key is missing from the dictionary, add it
|
||||||
}
|
if (!_files.ContainsKey(key))
|
||||||
|
{
|
||||||
|
_files.Add(key, new List<DatItem>());
|
||||||
|
}
|
||||||
|
|
||||||
// Now return the value
|
// Now return the value
|
||||||
return _files[key];
|
return _files[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
@@ -291,14 +294,17 @@ namespace SabreTools.Helper.Dats
|
|||||||
_files = new SortedDictionary<string, List<DatItem>>();
|
_files = new SortedDictionary<string, List<DatItem>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the key is missing from the dictionary, add it
|
lock (_files)
|
||||||
if (!_files.ContainsKey(key))
|
|
||||||
{
|
{
|
||||||
_files.Add(key, new List<DatItem>());
|
// If the key is missing from the dictionary, add it
|
||||||
}
|
if (!_files.ContainsKey(key))
|
||||||
|
{
|
||||||
|
_files.Add(key, new List<DatItem>());
|
||||||
|
}
|
||||||
|
|
||||||
// Now set the value
|
// Now set the value
|
||||||
_files[key] = value;
|
_files[key] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,14 +314,14 @@ namespace SabreTools.Helper.Dats
|
|||||||
/// <param name="key">Key in the dictionary to add to</param>
|
/// <param name="key">Key in the dictionary to add to</param>
|
||||||
public void Add(string key)
|
public void Add(string key)
|
||||||
{
|
{
|
||||||
|
// If the dictionary is null, create it
|
||||||
|
if (_files == null)
|
||||||
|
{
|
||||||
|
_files = new SortedDictionary<string, List<DatItem>>();
|
||||||
|
}
|
||||||
|
|
||||||
lock (_files)
|
lock (_files)
|
||||||
{
|
{
|
||||||
// If the dictionary is null, create it
|
|
||||||
if (_files == null)
|
|
||||||
{
|
|
||||||
_files = new SortedDictionary<string, List<DatItem>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the key is missing from the dictionary, add it
|
// If the key is missing from the dictionary, add it
|
||||||
if (!_files.ContainsKey(key))
|
if (!_files.ContainsKey(key))
|
||||||
{
|
{
|
||||||
@@ -331,14 +337,14 @@ namespace SabreTools.Helper.Dats
|
|||||||
/// <param name="value">Value to add to the dictionary</param>
|
/// <param name="value">Value to add to the dictionary</param>
|
||||||
public void Add(string key, DatItem value)
|
public void Add(string key, DatItem value)
|
||||||
{
|
{
|
||||||
|
// If the dictionary is null, create it
|
||||||
|
if (_files == null)
|
||||||
|
{
|
||||||
|
_files = new SortedDictionary<string, List<DatItem>>();
|
||||||
|
}
|
||||||
|
|
||||||
lock (_files)
|
lock (_files)
|
||||||
{
|
{
|
||||||
// If the dictionary is null, create it
|
|
||||||
if (_files == null)
|
|
||||||
{
|
|
||||||
_files = new SortedDictionary<string, List<DatItem>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the key is missing from the dictionary, add it
|
// If the key is missing from the dictionary, add it
|
||||||
if (!_files.ContainsKey(key))
|
if (!_files.ContainsKey(key))
|
||||||
{
|
{
|
||||||
@@ -357,14 +363,14 @@ namespace SabreTools.Helper.Dats
|
|||||||
/// <param name="value">Value to add to the dictionary</param>
|
/// <param name="value">Value to add to the dictionary</param>
|
||||||
public void AddRange(string key, List<DatItem> value)
|
public void AddRange(string key, List<DatItem> value)
|
||||||
{
|
{
|
||||||
|
// If the dictionary is null, create it
|
||||||
|
if (_files == null)
|
||||||
|
{
|
||||||
|
_files = new SortedDictionary<string, List<DatItem>>();
|
||||||
|
}
|
||||||
|
|
||||||
lock (_files)
|
lock (_files)
|
||||||
{
|
{
|
||||||
// If the dictionary is null, create it
|
|
||||||
if (_files == null)
|
|
||||||
{
|
|
||||||
_files = new SortedDictionary<string, List<DatItem>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the key is missing from the dictionary, add it
|
// If the key is missing from the dictionary, add it
|
||||||
if (!_files.ContainsKey(key))
|
if (!_files.ContainsKey(key))
|
||||||
{
|
{
|
||||||
@@ -383,14 +389,14 @@ namespace SabreTools.Helper.Dats
|
|||||||
/// <returns>True if the key exists, false otherwise</returns>
|
/// <returns>True if the key exists, false otherwise</returns>
|
||||||
public bool ContainsKey(string key)
|
public bool ContainsKey(string key)
|
||||||
{
|
{
|
||||||
|
// If the dictionary is null, create it
|
||||||
|
if (_files == null)
|
||||||
|
{
|
||||||
|
_files = new SortedDictionary<string, List<DatItem>>();
|
||||||
|
}
|
||||||
|
|
||||||
lock (_files)
|
lock (_files)
|
||||||
{
|
{
|
||||||
// If the dictionary is null, create it
|
|
||||||
if (_files == null)
|
|
||||||
{
|
|
||||||
_files = new SortedDictionary<string, List<DatItem>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _files.ContainsKey(key);
|
return _files.ContainsKey(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -403,14 +409,14 @@ namespace SabreTools.Helper.Dats
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
// If the dictionary is null, create it
|
||||||
|
if (_files == null)
|
||||||
|
{
|
||||||
|
_files = new SortedDictionary<string, List<DatItem>>();
|
||||||
|
}
|
||||||
|
|
||||||
lock (_files)
|
lock (_files)
|
||||||
{
|
{
|
||||||
// If the dictionary is null, create it
|
|
||||||
if (_files == null)
|
|
||||||
{
|
|
||||||
_files = new SortedDictionary<string, List<DatItem>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _files.Count;
|
return _files.Count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -432,14 +438,14 @@ namespace SabreTools.Helper.Dats
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
// If the dictionary is null, create it
|
||||||
|
if (_files == null)
|
||||||
|
{
|
||||||
|
_files = new SortedDictionary<string, List<DatItem>>();
|
||||||
|
}
|
||||||
|
|
||||||
lock (_files)
|
lock (_files)
|
||||||
{
|
{
|
||||||
// If the dictionary is null, create it
|
|
||||||
if (_files == null)
|
|
||||||
{
|
|
||||||
_files = new SortedDictionary<string, List<DatItem>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _files.Keys;
|
return _files.Keys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -451,14 +457,14 @@ namespace SabreTools.Helper.Dats
|
|||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
public void Remove(string key)
|
public void Remove(string key)
|
||||||
{
|
{
|
||||||
|
// If the dictionary is null, create it
|
||||||
|
if (_files == null)
|
||||||
|
{
|
||||||
|
_files = new SortedDictionary<string, List<DatItem>>();
|
||||||
|
}
|
||||||
|
|
||||||
lock (_files)
|
lock (_files)
|
||||||
{
|
{
|
||||||
// If the dictionary is null, create it
|
|
||||||
if (_files == null)
|
|
||||||
{
|
|
||||||
_files = new SortedDictionary<string, List<DatItem>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the key is in the dictionary, remove it
|
// If the key is in the dictionary, remove it
|
||||||
if (_files.ContainsKey(key))
|
if (_files.ContainsKey(key))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user