Skip to content

Commit

Permalink
add err msg for failed script precompiling, fix CompileScript caring …
Browse files Browse the repository at this point in the history
…about "\" vs "/"
  • Loading branch information
Demorome committed Oct 6, 2023
1 parent e2a7972 commit d5c8179
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
8 changes: 7 additions & 1 deletion nvse/nvse/CachedScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ void CacheAllScriptsInPath(std::string_view pathStr)
{
if (dir_entry.is_regular_file())
{
CompileAndCacheScript(dir_entry.path(), false);
if (!CompileAndCacheScript(dir_entry.path(), false))
{
std::string errMsg = std::format("xNVSE: Failed to precompile script file {}",
dir_entry.path().string());
Console_Print(errMsg.c_str());
_ERROR(errMsg.c_str());
}
}
}
}
Expand Down
24 changes: 18 additions & 6 deletions nvse/nvse/Commands_Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1620,9 +1620,14 @@ bool Cmd_CompileScript_Execute(COMMAND_ARGS)
if (ExpressionEvaluator eval(PASS_COMMAND_ARGS);
eval.ExtractArgs())
{
auto const path = eval.Arg(0)->GetString();
if (!path || !path[0])
return true;
std::string pathStr;
{
auto const path = eval.Arg(0)->GetString();
if (!path || !path[0])
return true;
pathStr = path;
}
ReplaceAll(pathStr, "/", "\\");

bool forceRecompile = false;
if (eval.NumArgs() > 1)
Expand All @@ -1632,24 +1637,31 @@ bool Cmd_CompileScript_Execute(COMMAND_ARGS)

if (forceRecompile)
{
if (auto* script = CompileAndCacheScript(path))
if (auto* script = CompileAndCacheScript(pathStr.c_str()))
*refResult = script->refID;
}
else
{
// Try to get the cached result
ScopedLock lock(g_cachedUdfCS);
if (auto iter = cachedFileUDFs.Find(const_cast<char*>(path));
if (auto iter = cachedFileUDFs.Find(const_cast<char*>(pathStr.c_str()));
!iter.End())
{
*refResult = iter.Get()->refID;

#if _DEBUG
Console_Print("CompileScript >> Got cached script");
#endif
}
else
{
// No cached result, so create & cache
// Should only happen if file wasn't pre-cached at startup, i.e it didn't exist and was created mid-game.
if (auto* script = CompileAndCacheScript(path))
if (auto* script = CompileAndCacheScript(pathStr.c_str()))
*refResult = script->refID;
#if _DEBUG
Console_Print("CompileScript >> Had to compile script; couldn't find cached script.");
#endif
}
}
}
Expand Down

0 comments on commit d5c8179

Please sign in to comment.