mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
bugfix: added locks on external methods
This commit is contained in:
parent
d4b6f611f8
commit
0bf9fdea84
1 changed files with 24 additions and 12 deletions
|
|
@ -94,23 +94,35 @@ public class CollectionStorage : IReadOnlyList<ModCollection>, IDisposable, ISer
|
||||||
|
|
||||||
/// <summary> Default enumeration skips the empty collection. </summary>
|
/// <summary> Default enumeration skips the empty collection. </summary>
|
||||||
public IEnumerator<ModCollection> GetEnumerator()
|
public IEnumerator<ModCollection> GetEnumerator()
|
||||||
=> _collections.Skip(1).GetEnumerator();
|
=> GetModSnapShot().ToList().GetEnumerator();
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
=> GetEnumerator();
|
=> GetEnumerator();
|
||||||
|
|
||||||
public int Count
|
public int Count
|
||||||
=> _collections.Count;
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock(_collectionsLock)
|
||||||
|
return _collections.Count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ModCollection this[int index]
|
public ModCollection this[int index]
|
||||||
=> _collections[index];
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock(_collectionsLock)
|
||||||
|
return _collections[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Find a collection by its name. If the name is empty or None, the empty collection is returned. </summary>
|
/// <summary> Find a collection by its name. If the name is empty or None, the empty collection is returned. </summary>
|
||||||
public bool ByName(string name, [NotNullWhen(true)] out ModCollection? collection)
|
public bool ByName(string name, [NotNullWhen(true)] out ModCollection? collection)
|
||||||
{
|
{
|
||||||
if (name.Length != 0)
|
if (name.Length != 0)
|
||||||
|
lock(_collectionsLock)
|
||||||
return _collections.FindFirst(c => string.Equals(c.Identity.Name, name, StringComparison.OrdinalIgnoreCase), out collection);
|
return _collections.FindFirst(c => string.Equals(c.Identity.Name, name, StringComparison.OrdinalIgnoreCase), out collection);
|
||||||
|
|
||||||
collection = ModCollection.Empty;
|
collection = ModCollection.Empty;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -119,8 +131,8 @@ public class CollectionStorage : IReadOnlyList<ModCollection>, IDisposable, ISer
|
||||||
public bool ById(Guid id, [NotNullWhen(true)] out ModCollection? collection)
|
public bool ById(Guid id, [NotNullWhen(true)] out ModCollection? collection)
|
||||||
{
|
{
|
||||||
if (id != Guid.Empty)
|
if (id != Guid.Empty)
|
||||||
|
lock(_collectionsLock)
|
||||||
return _collections.FindFirst(c => c.Identity.Id == id, out collection);
|
return _collections.FindFirst(c => c.Identity.Id == id, out collection);
|
||||||
|
|
||||||
collection = ModCollection.Empty;
|
collection = ModCollection.Empty;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -189,7 +201,7 @@ public class CollectionStorage : IReadOnlyList<ModCollection>, IDisposable, ISer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool RemoveCollection(ModCollection collection)
|
public bool RemoveCollection(ModCollection collection)
|
||||||
{
|
{
|
||||||
if (collection.Identity.Index <= ModCollection.Empty.Identity.Index || collection.Identity.Index >= _collections.Count)
|
if (collection.Identity.Index <= ModCollection.Empty.Identity.Index || collection.Identity.Index >= Count)
|
||||||
{
|
{
|
||||||
Penumbra.Messager.NotificationMessage("Can not remove the empty collection.", NotificationType.Error, false);
|
Penumbra.Messager.NotificationMessage("Can not remove the empty collection.", NotificationType.Error, false);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -207,7 +219,7 @@ public class CollectionStorage : IReadOnlyList<ModCollection>, IDisposable, ISer
|
||||||
{
|
{
|
||||||
_collections.RemoveAt(collection.Identity.Index);
|
_collections.RemoveAt(collection.Identity.Index);
|
||||||
// Update indices.
|
// Update indices.
|
||||||
for (var i = collection.Identity.Index; i < Count; ++i)
|
for (var i = collection.Identity.Index; i < _collections.Count; ++i)
|
||||||
_collections[i].Identity.Index = i;
|
_collections[i].Identity.Index = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -322,12 +334,12 @@ public class CollectionStorage : IReadOnlyList<ModCollection>, IDisposable, ISer
|
||||||
return collection;
|
return collection;
|
||||||
|
|
||||||
if (AddCollection(ModCollectionIdentity.DefaultCollectionName, null))
|
if (AddCollection(ModCollectionIdentity.DefaultCollectionName, null))
|
||||||
return _collections[^1];
|
return this[^1];
|
||||||
|
|
||||||
Penumbra.Messager.NotificationMessage(
|
Penumbra.Messager.NotificationMessage(
|
||||||
$"Unknown problem creating a collection with the name {ModCollectionIdentity.DefaultCollectionName}, which is required to exist.",
|
$"Unknown problem creating a collection with the name {ModCollectionIdentity.DefaultCollectionName}, which is required to exist.",
|
||||||
NotificationType.Error);
|
NotificationType.Error);
|
||||||
return Count > 1 ? _collections[1] : _collections[0];
|
return Count > 1 ? this[1] : this[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Move all settings in all collections to unused settings. </summary>
|
/// <summary> Move all settings in all collections to unused settings. </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue