Skip to content

Commit

Permalink
Add exceptions parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
BigBang1112 committed Jul 17, 2024
1 parent 4968fb0 commit db1584c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions Src/GBX.NET/Components/GbxRefTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public string GetFullFilePath(GbxRefTableFile file)
return Path.GetFullPath(GetFilePath(file));
}

public CMwNod? LoadNode(GbxRefTableFile file, GbxReadSettings settings = default)
public CMwNod? LoadNode(GbxRefTableFile file, GbxReadSettings settings = default, bool exceptions = false)
{
if (file is null)
{
Expand Down Expand Up @@ -77,6 +77,12 @@ public string GetFullFilePath(GbxRefTableFile file)
{
scope?.Dispose();
logger?.LogError(ex, "Failed to load node from file: {FilePath}", filePath);

if (exceptions)
{
throw;
}

return default;
}
}
Expand Down Expand Up @@ -104,16 +110,22 @@ public string GetFullFilePath(GbxRefTableFile file)
{
scope?.Dispose();
logger?.LogError(ex, "Failed to load node from file: {Length} bytes", data.Length);

if (exceptions)
{
throw;
}

return default;
}
}

return default;
}

public T? LoadNode<T>(GbxRefTableFile file, GbxReadSettings settings = default) where T : CMwNod
public T? LoadNode<T>(GbxRefTableFile file, GbxReadSettings settings = default, bool exceptions = false) where T : CMwNod
{
return LoadNode(file, settings) as T;
return LoadNode(file, settings, exceptions) as T;
}

internal static GbxRefTable? Parse(GbxReader reader, GbxHeader header, string? fileSystemPath)
Expand Down
4 changes: 2 additions & 2 deletions Src/GBX.NET/Components/GbxRefTableFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public override string ToString()
return $"{FilePath}, Flags: {Flags}, UseFile: {UseFile}";
}

public T? GetNode<T>(ref T? cachedNode, GbxReadSettings settings = default) where T : CMwNod
public T? GetNode<T>(ref T? cachedNode, GbxReadSettings settings = default, bool exceptions = false) where T : CMwNod
{
if (cachedNode is not null)
{
return cachedNode;
}

return cachedNode = RefTable.LoadNode<T>(this, settings);
return cachedNode = RefTable.LoadNode<T>(this, settings, exceptions);
}

public string GetFullPath()
Expand Down

0 comments on commit db1584c

Please sign in to comment.