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

Dispose wad on remove #220

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Obsidian/Data/Wad/IWadTreeParent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ WadChunk chunk
lock (parent) {
directory = parent.Items.FirstOrDefault(item => item.Type is not WadTreeItemType.File && item.NameHash == folderNameHash);
if (directory is null) {
directory = new(parent, folderName);
directory = new(parent, folderName, wad);
parent.Items.Add(directory);
}
}
Expand Down
4 changes: 1 addition & 3 deletions Obsidian/Data/Wad/WadTreeFileModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ namespace Obsidian.Data.Wad;
[DebuggerDisplay("{Name}")]
public sealed class WadTreeFileModel : WadTreeItemModel {
public WadChunk Chunk { get; }
public WadFile Wad { get; }

public WadTreeFileModel(IWadTreeParent parent, string name, WadFile wad, WadChunk chunk)
: base(parent, name) {
: base(parent, name, wad) {
this.Chunk = chunk;
this.Wad = wad;
}
}
7 changes: 5 additions & 2 deletions Obsidian/Data/Wad/WadTreeItemModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LeagueToolkit.Hashing;
using LeagueToolkit.Core.Wad;
using LeagueToolkit.Hashing;
using LeagueToolkit.Utils;
using MudBlazor;
using System.Diagnostics;
Expand Down Expand Up @@ -34,13 +35,15 @@ public class WadTreeItemModel
public bool IsChecked { get; set; }
public bool IsExpanded { get; set; }
public bool IsWadArchive { get; }
public WadFile Wad { get; }

public List<WadTreeItemModel> Items { get; protected set; } = new();

public WadTreeItemModel(IWadTreeParent parent, string name) {
public WadTreeItemModel(IWadTreeParent parent, string name, WadFile wad) {
this.Parent = parent;

this.Name = name;
this.Wad = wad;
this.Path = parent switch {
null or WadTreeModel or { IsWadArchive: true } => name,
_ => string.Join('/', parent.Path, name)
Expand Down
2 changes: 1 addition & 1 deletion Obsidian/Data/Wad/WadTreeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void CreateTreeForWadFile(WadFile wad, string wadFilePath, bool allowDupl

IWadTreeParent wadParent = this;
if (allowDuplicate) {
var wadItem = new WadTreeItemModel(this, wadFilePathComponents.First());
var wadItem = new WadTreeItemModel(this, wadFilePathComponents.First(), wad);
this.Items.Add(wadItem);
wadParent = wadItem;
wadFilePathComponents = wadFilePathComponents.Skip(1);
Expand Down
1 change: 1 addition & 0 deletions Obsidian/Shared/TreeWadItem.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,6 @@ private void Save() {
private void Delete() {
this.Item.Parent.Items.Remove(this.Item);
this.Explorer.RefreshState();
this.Item.Wad.Dispose();
}
}