Use improved filesystem.

This commit is contained in:
Ottermandias 2025-06-13 17:27:49 +02:00
parent 4981b0348f
commit 1f4ec984b3
3 changed files with 5 additions and 15 deletions

@ -1 +1 @@
Subproject commit 17a3ee5711ca30eb7f5b393dfb8136f0bce49b2b Subproject commit 78528f93ac253db0061d9a8244cfa0cee5c2f873

View file

@ -112,7 +112,7 @@ public class ModsApi : IPenumbraApiMods, IApiService, IDisposable
public (PenumbraApiEc, string, bool, bool) GetModPath(string modDirectory, string modName) public (PenumbraApiEc, string, bool, bool) GetModPath(string modDirectory, string modName)
{ {
if (!_modManager.TryGetMod(modDirectory, modName, out var mod) if (!_modManager.TryGetMod(modDirectory, modName, out var mod)
|| !_modFileSystem.FindLeaf(mod, out var leaf)) || !_modFileSystem.TryGetValue(mod, out var leaf))
return (PenumbraApiEc.ModMissing, string.Empty, false, false); return (PenumbraApiEc.ModMissing, string.Empty, false, false);
var fullPath = leaf.FullName(); var fullPath = leaf.FullName();
@ -127,7 +127,7 @@ public class ModsApi : IPenumbraApiMods, IApiService, IDisposable
return PenumbraApiEc.InvalidArgument; return PenumbraApiEc.InvalidArgument;
if (!_modManager.TryGetMod(modDirectory, modName, out var mod) if (!_modManager.TryGetMod(modDirectory, modName, out var mod)
|| !_modFileSystem.FindLeaf(mod, out var leaf)) || !_modFileSystem.TryGetValue(mod, out var leaf))
return PenumbraApiEc.ModMissing; return PenumbraApiEc.ModMissing;
try try

View file

@ -80,7 +80,7 @@ public sealed class ModFileSystem : FileSystem<Mod>, IDisposable, ISavable, ISer
// Update sort order when defaulted mod names change. // Update sort order when defaulted mod names change.
private void OnModDataChange(ModDataChangeType type, Mod mod, string? oldName) private void OnModDataChange(ModDataChangeType type, Mod mod, string? oldName)
{ {
if (!type.HasFlag(ModDataChangeType.Name) || oldName == null || !FindLeaf(mod, out var leaf)) if (!type.HasFlag(ModDataChangeType.Name) || oldName == null || !TryGetValue(mod, out var leaf))
return; return;
var old = oldName.FixName(); var old = oldName.FixName();
@ -111,7 +111,7 @@ public sealed class ModFileSystem : FileSystem<Mod>, IDisposable, ISavable, ISer
CreateDuplicateLeaf(parent, mod.Name.Text, mod); CreateDuplicateLeaf(parent, mod.Name.Text, mod);
break; break;
case ModPathChangeType.Deleted: case ModPathChangeType.Deleted:
if (FindLeaf(mod, out var leaf)) if (TryGetValue(mod, out var leaf))
Delete(leaf); Delete(leaf);
break; break;
@ -124,16 +124,6 @@ public sealed class ModFileSystem : FileSystem<Mod>, IDisposable, ISavable, ISer
} }
} }
// Search the entire filesystem for the leaf corresponding to a mod.
public bool FindLeaf(Mod mod, [NotNullWhen(true)] out Leaf? leaf)
{
leaf = Root.GetAllDescendants(ISortMode<Mod>.Lexicographical)
.OfType<Leaf>()
.FirstOrDefault(l => l.Value == mod);
return leaf != null;
}
// Used for saving and loading. // Used for saving and loading.
private static string ModToIdentifier(Mod mod) private static string ModToIdentifier(Mod mod)
=> mod.ModPath.Name; => mod.ModPath.Name;