Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disposal checks #210

Merged
merged 3 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion OpenMcdf/CfbStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ public override void Write(byte[] buffer, int offset, int count)

#if (!NETSTANDARD2_0 && !NETFRAMEWORK)

public override int Read(Span<byte> buffer) => stream.Read(buffer);
public override int Read(Span<byte> buffer)
{
this.ThrowIfDisposed(isDisposed);

return stream.Read(buffer);
}

public override int ReadByte() => this.ReadByteCore();

Expand Down
1 change: 1 addition & 0 deletions OpenMcdf/DirectoryEntries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public DirectoryEntries(RootContextSite rootContextSite)

public void Dispose()
{
directoryEntryEnumerator.Dispose();
fatChainEnumerator.Dispose();
}

Expand Down
4 changes: 2 additions & 2 deletions OpenMcdf/DirectoryTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ public void Remove(DirectoryEntry entry)

public void WriteTrace(TextWriter writer)
{
if (root is null)
if (root.ChildId == StreamId.NoStream)
{
Trace.WriteLine("<empty tree>");
Trace.WriteLine("Empty tree");
return;
}

Expand Down
3 changes: 0 additions & 3 deletions OpenMcdf/FatSectorEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public bool MoveNext()
return MoveTo(nextIndex);
}

public bool IsAt(uint index) => !start && index == this.index;

/// <summary>
/// Moves the enumerator to the specified sector.
/// </summary>
Expand Down Expand Up @@ -120,7 +118,6 @@ public void Reset()
/// <returns>The ID of the new sector that was added</returns>
public uint Add()
{
// No FAT sectors are free, so add a new one
Header header = Context.Header;
uint nextIndex = Context.Header.FatSectorCount;
Sector newFatSector = new(Context.SectorCount, Context.SectorSize);
Expand Down
1 change: 1 addition & 0 deletions OpenMcdf/MiniFatChainEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public MiniFatChainEnumerator(RootContextSite rootContextSite, uint startSectorI
/// <inheritdoc/>
public void Dispose()
{
miniFatEnumerator.Dispose();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion OpenMcdf/RootStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void Consolidate()
if (Context.BaseStream is MemoryStream)
destinationStream = new MemoryStream((int)Context.BaseStream.Length);
else if (Context.BaseStream is FileStream)
destinationStream = File.Create(System.IO.Path.GetTempFileName());
destinationStream = File.Create(Path.GetTempFileName());
else
throw new NotSupportedException("Unsupported stream type for consolidation.");

Expand Down
1 change: 1 addition & 0 deletions exclusion.dic
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Blaseotto
CFB
CLSID
codepage
defragmentation
depersist
DIFAT
endian
Expand Down
Loading