Skip to content

Commit

Permalink
Merge pull request #14834 from michaelnebel/csharp/robustassetsfileread
Browse files Browse the repository at this point in the history
C#: Make assets file reading more robust.
  • Loading branch information
michaelnebel authored Nov 20, 2023
2 parents db180d9 + 7531852 commit d3e047f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,31 @@ public bool TryParse(string json, DependencyContainer dependencies)
}
}

private static bool TryReadAllText(string path, ProgressMonitor progressMonitor, out string content)
{
try
{
content = File.ReadAllText(path);
return true;
}
catch (Exception e)
{
progressMonitor.LogInfo($"Failed to read assets file '{path}': {e.Message}");
content = "";
return false;
}
}

public static DependencyContainer GetCompilationDependencies(ProgressMonitor progressMonitor, IEnumerable<string> assets)
{
var parser = new Assets(progressMonitor);
var dependencies = new DependencyContainer();
assets.ForEach(asset =>
{
var json = File.ReadAllText(asset);
parser.TryParse(json, dependencies);
if (TryReadAllText(asset, progressMonitor, out var json))
{
parser.TryParse(json, dependencies);
}
});
return dependencies;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public bool Exec(string execArgs)
[GeneratedRegex("Restored\\s+(.+\\.csproj)", RegexOptions.Compiled)]
private static partial Regex RestoredProjectRegex();

[GeneratedRegex("[Assets\\sfile\\shas\\snot\\schanged.\\sSkipping\\sassets\\sfile\\swriting.|Writing\\sassets\\sfile\\sto\\sdisk.]\\sPath:\\s(.*)", RegexOptions.Compiled)]
[GeneratedRegex("[Assets\\sfile\\shas\\snot\\schanged.\\sSkipping\\sassets\\sfile\\swriting.|Writing\\sassets\\sfile\\sto\\sdisk.]\\sPath:\\s(.+)", RegexOptions.Compiled)]
private static partial Regex AssetsFileRegex();
}
}

0 comments on commit d3e047f

Please sign in to comment.