Skip to content

Commit

Permalink
Merge pull request #353 from WSSDude420/batch-of-fixes
Browse files Browse the repository at this point in the history
Fix crash if mods folder does not exist
  • Loading branch information
Yamashi authored Jan 1, 2021
2 parents 4d45f81 + c5b2349 commit 440e24c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ Options::Options(HMODULE aModule)
RootPath = exePath.parent_path();

CETPath = RootPath;
CETPath /= _T("plugins");
CETPath /= _T("cyber_engine_tweaks");
CETPath /= "plugins";
CETPath /= "cyber_engine_tweaks";
std::filesystem::create_directories(CETPath);

ScriptsPath = CETPath / "mods";

std::error_code ec;
std::filesystem::create_directories(CETPath, ec);
std::filesystem::create_directories(ScriptsPath);

const auto rotatingLogger = std::make_shared<spdlog::sinks::rotating_file_sink_mt>((CETPath / "cyber_engine_tweaks.log").string(), 1048576 * 5, 3);

Expand Down
11 changes: 7 additions & 4 deletions src/scripting/Scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,16 @@ void Scripting::Initialize()


// execute autoexec.lua inside our default script directory
std::filesystem::path defPath = Options::Get().CETPath / "scripts";
std::filesystem::current_path(defPath);
m_lua.do_file("autoexec.lua");
std::filesystem::current_path(Options::Get().CETPath / "scripts");
if (std::filesystem::exists("autoexec.lua"))
m_lua.do_file("autoexec.lua");
else
Overlay::Get().Log("WARNING: missing CET autoexec.lua!");

// execute autoexec.lua inside user script directory (NOTE: directory stays set afterwards to this for now)
std::filesystem::current_path(Options::Get().ScriptsPath);
m_lua.do_file("autoexec.lua");
if (std::filesystem::exists("autoexec.lua"))
m_lua.do_file("autoexec.lua");
}

sol::object Scripting::Index(const std::string& acName)
Expand Down

0 comments on commit 440e24c

Please sign in to comment.