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

Fix GUI Crashes since cli tree support #43

Merged
merged 3 commits into from
Dec 10, 2023
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
6 changes: 6 additions & 0 deletions ScrapPackedExplorer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ public TreeViewTreeEntryAlias(ScrapTreeEntry p_Reference) : base(p_Reference.Par
}

public class TreeViewTreeEntry : ScrapTreeEntry {
public override ScrapTreeEntry CreateChild(ScrapTreeEntry p_Parent, string p_Name = "", PackedFileIndexData p_IndexData = null) {
TreeViewTreeEntry Result = new TreeViewTreeEntry(p_Parent) { Name = p_Name, IndexData = p_IndexData };
Items.Add(Result);
return Result;
}

public TreeViewTreeEntry(ScrapTreeEntry p_Parent) : base(p_Parent) {
}

Expand Down
31 changes: 18 additions & 13 deletions ScrapPackedLibrary/ScrapPackedTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,36 @@

namespace ch.romibi.Scrap.Packed.PackerLib {
public class ScrapTreeEntry : IComparable {
public virtual ScrapTreeEntry CreateChild(ScrapTreeEntry p_Parent, string p_Name = "", PackedFileIndexData p_IndexData = null) {
ScrapTreeEntry Result = new ScrapTreeEntry(p_Parent) { Name = p_Name, IndexData = p_IndexData };
Items.Add(Result);
return Result;
}

public ScrapTreeEntry(ScrapTreeEntry p_Parent) {
Items = new ObservableCollection<ScrapTreeEntry>();
IndexData = null;
Parent = p_Parent;
}

public string Name { get; set; }
public virtual string Name { get; set; }

public ScrapTreeEntry Parent { get; set; }
public virtual ScrapTreeEntry Parent { get; set; }

public PackedFileIndexData IndexData { get; set; }
public virtual PackedFileIndexData IndexData { get; set; }
public bool IsFile {
get {
return !IsDirectory;
}
}

public bool IsDirectory {
public virtual bool IsDirectory {
get {
return IndexData is null;
}
}

public void AddFileData(PackedFileIndexData p_File, string p_SubdirFilename = "") {
public virtual void AddFileData(PackedFileIndexData p_File, string p_SubdirFilename = "") {
string fileName;
if (p_SubdirFilename.Length == 0) {
fileName = p_File.FilePath;
Expand All @@ -49,16 +55,15 @@ public void AddFileData(PackedFileIndexData p_File, string p_SubdirFilename = ""
}
}
if (subDir == null) {
subDir = new ScrapTreeEntry(this) { Name = nextDir };
Items.Add(subDir);
subDir = CreateChild(this, nextDir);
}
subDir.AddFileData(p_File, fileName.Substring(nextDir.Length + 1));
} else {
Items.Add(new ScrapTreeEntry(this) { Name = fileName, IndexData = p_File });
CreateChild(this, fileName, p_File);
}
}

public List<ScrapTreeEntry> GetItemPath() {
public virtual List<ScrapTreeEntry> GetItemPath() {
// get a list of TreeItems from parent to selection
// Todo: move logic inside TreeEntry and cache
List<ScrapTreeEntry> itemPath = new List<ScrapTreeEntry>();
Expand All @@ -73,7 +78,7 @@ public List<ScrapTreeEntry> GetItemPath() {
return itemPath;
}

public string GetItemPathString(bool p_IgnoreRoot = true) {
public virtual string GetItemPathString(bool p_IgnoreRoot = true) {
List<ScrapTreeEntry> itemPath = GetItemPath();
string pathString = "";

Expand All @@ -91,7 +96,7 @@ public string GetItemPathString(bool p_IgnoreRoot = true) {
return pathString;
}

public int CompareTo(object p_Other) {
public virtual int CompareTo(object p_Other) {
ScrapTreeEntry a = this;
ScrapTreeEntry b = (ScrapTreeEntry)p_Other;
if (a.IsDirectory == b.IsDirectory)
Expand All @@ -103,7 +108,7 @@ public int CompareTo(object p_Other) {
return 1;
}

public void Sort() {
public virtual void Sort() {
var sorted = Items.OrderBy(p_X => p_X).ToList();

for (int i = 0; i < sorted.Count; i++)
Expand All @@ -116,6 +121,6 @@ public void Sort() {
}
}

public ObservableCollection<ScrapTreeEntry> Items { get; set; }
public virtual ObservableCollection<ScrapTreeEntry> Items { get; set; }
}
}
Loading