Skip to content

Commit

Permalink
Lua: Add $autorun and $natives support to fs.glob
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Sep 9, 2023
1 parent d134e16 commit 89b9098
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/mods/bindings/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ ::fs::path get_datadir(std::string wanted_subdir = "") {
modpath.resize(1024, 0);
modpath.resize(GetModuleFileName(nullptr, modpath.data(), modpath.size()));

if (!wanted_subdir.empty() && wanted_subdir.starts_with("$")) {
if (wanted_subdir.starts_with("$natives")) {
if (!wanted_subdir.empty() && wanted_subdir.find("$") != std::string::npos) {
if (wanted_subdir.find("$natives") != std::string::npos) {
auto datadir = ::fs::path{modpath}.parent_path() / "natives";

::fs::create_directories(datadir);

return datadir;
}

if (wanted_subdir.find("$autorun") != std::string::npos) {
auto datadir = REFramework::get_persistent_dir() / "reframework" / "autorun";

::fs::create_directories(datadir);

return datadir;
}

// todo, other subdirs?
}
Expand Down Expand Up @@ -58,7 +66,7 @@ sol::table glob(sol::this_state l, const char* filter) {
sol::state_view state{l};
std::regex filter_regex{filter};
auto results = state.create_table();
auto datadir = detail::get_datadir();
auto datadir = detail::get_datadir(filter);
auto i = 0;

for (const auto& entry : ::fs::recursive_directory_iterator{datadir}) {
Expand Down

0 comments on commit 89b9098

Please sign in to comment.