Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
make some of the commands more error-tolerant
Browse files Browse the repository at this point in the history
  • Loading branch information
parzivail committed Aug 3, 2021
1 parent cebccbf commit 1691a08
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
3 changes: 1 addition & 2 deletions DumpTool/DumpAllMeshPropsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public static void Run(DumpAllMeshPropsCommand args)
{
var db = new LiteDatabase(args.IndexFilename);

foreach (var entry in forge.Entries)
DumpMeshPropsCommand.ProcessFlatArchive(db, forge, entry, Environment.CurrentDirectory, Path.GetDirectoryName(args.ForgeFilename));
foreach (var entry in forge.Entries) DumpMeshPropsCommand.ProcessFlatArchive(db, forge, entry, Environment.CurrentDirectory, Path.GetDirectoryName(args.ForgeFilename));
}
catch (Exception e)
{
Expand Down
11 changes: 9 additions & 2 deletions DumpTool/DumpMeshPropsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void Run(DumpMeshPropsCommand args)
public static void ProcessFlatArchive(ILiteDatabase db, Forge forge, Entry entry, string rootOutputDir, string rootForgeDir)
{
var container = forge.GetContainer(entry.Uid);
if (container is not ForgeAsset forgeAsset) throw new InvalidDataException("Container is not asset");
if (container is not ForgeAsset forgeAsset) return;

var assetStream = forgeAsset.GetDataStream(forge);
var arc = FlatArchive.Read(assetStream);
Expand All @@ -64,7 +64,14 @@ public static void ProcessFlatArchive(ILiteDatabase db, Forge forge, Entry entry
var outputDir = Path.Combine(rootOutputDir, $"model_flatarchive_id{entry.Uid}", $"{(Magic) meshProp.Meta.Magic}_{meshProp.Meta.Uid}");
Directory.CreateDirectory(outputDir);

DumpHelper.DumpNonContainerChildren(outputDir, assetStream, arc, meshProp, unresolvedExterns);
try
{
DumpHelper.DumpNonContainerChildren(outputDir, assetStream, arc, meshProp, unresolvedExterns);
}
catch
{
continue;
}

var resolvedExterns = new Dictionary<string, List<ulong>>();

Expand Down
27 changes: 10 additions & 17 deletions DumpTool/FindAllMeshPropsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public class FindAllMeshPropsCommand

public static void Run(FindAllMeshPropsCommand args)
{
try
{
var forge = Program.GetForge(args.ForgeFilename);
foreach (var entry in forge.Entries)
var forge = Program.GetForge(args.ForgeFilename);
foreach (var entry in forge.Entries)
try
{
if (SearchFlatArchive(forge, entry, args.Uid))
Console.WriteLine(entry.Uid);
}
catch (Exception e)
{
Console.Error.WriteLine($"Error while dumping: {e}");
}
}
catch (Exception e)
{
Console.Error.WriteLine($"Error while dumping: {e}");
}
}

public static bool SearchFlatArchive(Forge forge, Entry entry, ulong uid)
Expand All @@ -46,14 +46,7 @@ public static bool SearchFlatArchive(Forge forge, Entry entry, ulong uid)
{
var unresolvedExterns = new List<ulong>();

try
{
DumpHelper.SearchNonContainerChildren(assetStream, arc, meshProp, unresolvedExterns);
}
catch (NotSupportedException)
{
continue;
}
DumpHelper.SearchNonContainerChildren(assetStream, arc, meshProp, unresolvedExterns);

if (unresolvedExterns.Contains(uid))
return true;
Expand Down
20 changes: 14 additions & 6 deletions RainbowForge/Dump/DumpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,21 @@ void TryRecurseChildren(string dir, ulong uid)
{
case Magic.Shader:
{
var shader = Shader.Read(assetStream);
var pathVert = Path.Combine(rootDir, $"{entry.Meta.Uid}_vert.hlsl");
var pathExtra = Path.Combine(rootDir, $"{entry.Meta.Uid}_extra.hlsl");
try
{
var shader = Shader.Read(assetStream);
var pathVert = Path.Combine(rootDir, $"{entry.Meta.Uid}_vert.hlsl");
var pathExtra = Path.Combine(rootDir, $"{entry.Meta.Uid}_extra.hlsl");

Directory.CreateDirectory(rootDir);
File.WriteAllText(pathVert, shader.Vert);
File.WriteAllText(pathExtra, shader.ExtraFunctions);
}
catch (Exception e)
{
// ignored
}

Directory.CreateDirectory(rootDir);
File.WriteAllText(pathVert, shader.Vert);
File.WriteAllText(pathExtra, shader.ExtraFunctions);
break;
}
case Magic.MaterialContainer:
Expand Down

0 comments on commit 1691a08

Please sign in to comment.