Skip to content

Commit

Permalink
safe wad tree creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Crauzer committed Apr 5, 2023
1 parent ac4f295 commit 505197f
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions Obsidian/Pages/ExplorerPage.razor.cs
Expand Up @@ -30,12 +30,19 @@ public partial class ExplorerPage

public WadTreeModel WadTree { get; set; }

private WadTreeModel CreateWadTree() =>
string.IsNullOrEmpty(this.Config.GameDataDirectory) switch
private WadTreeModel CreateWadTree()
{
return string.IsNullOrEmpty(this.Config.GameDataDirectory) switch
{
true => CreateEmptyWadTree(),
false => TryCreateWadTree()
};

WadTreeModel TryCreateWadTree()
{
true => new(this.Hashtable, this.Config, Array.Empty<string>()),
false
=> new(
try
{
return new(
this.Hashtable,
this.Config,
Directory
Expand All @@ -45,8 +52,22 @@ public partial class ExplorerPage
SearchOption.AllDirectories
)
.Where(x => x.EndsWith(".wad") || x.EndsWith(".wad.client"))
)
};
);
}
catch (Exception exception)
{
SnackbarUtils.ShowHardError(
this.Snackbar,
new InvalidOperationException("Failed to create wad tree", exception)
);

return CreateEmptyWadTree();
}
}
}

private WadTreeModel CreateEmptyWadTree() =>
new(this.Hashtable, this.Config, Array.Empty<string>());

private async Task RebuildWadTree()
{
Expand Down

0 comments on commit 505197f

Please sign in to comment.