Skip to content

Commit

Permalink
Add methods to query specific entries
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-visionaid committed Nov 19, 2024
1 parent ec8e656 commit 532b8b8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions OpenMcdf.Tests/StorageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public void OpenStorage(string fileName)

Assert.ThrowsException<DirectoryNotFoundException>(() => rootStorage.OpenStorage(""));

Assert.IsTrue(rootStorage.ContainsEntry("MyStorage"));
Assert.IsFalse(rootStorage.ContainsEntry("NonExistentStorage"));

bool found = rootStorage.TryGetEntryInfo("MyStorage", out EntryInfo entryInfo);
Assert.IsTrue(found);
Assert.IsNotNull(entryInfo);
Assert.AreEqual("MyStorage", entryInfo.Name);

Storage storage = rootStorage.OpenStorage("MyStorage");
Assert.AreEqual("MyStorage", storage.EntryInfo.Name);
}
Expand Down
26 changes: 26 additions & 0 deletions OpenMcdf/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,32 @@ IEnumerable<DirectoryEntry> EnumerateDirectoryEntries()
}
}

public bool ContainsEntry(string name)
{
ThrowHelper.ThrowIfNameIsInvalid(name);

this.ThrowIfDisposed(Context.IsDisposed);

return directoryTree.TryGetDirectoryEntry(name, out DirectoryEntry? _);
}

public bool TryGetEntryInfo(string name, out EntryInfo entryInfo)
{
ThrowHelper.ThrowIfNameIsInvalid(name);

this.ThrowIfDisposed(Context.IsDisposed);

if (!directoryTree.TryGetDirectoryEntry(name, out DirectoryEntry? entry))
{
entryInfo = default;
return false;
}

string path = $"{EntryInfo.Path}{EntryInfo.Name}";
entryInfo = entry.ToEntryInfo(path);
return true;
}

DirectoryEntry AddDirectoryEntry(StorageType storageType, string name)
{
DirectoryEntry entry = Context.DirectoryEntries.CreateOrRecycleDirectoryEntry();
Expand Down

0 comments on commit 532b8b8

Please sign in to comment.