Change search path priority

This commit is contained in:
Federico Cecchetto 2022-07-19 19:42:59 +02:00
parent 1f2025d75e
commit c8ded5b1d6
5 changed files with 22 additions and 8 deletions

View File

@ -16,9 +16,9 @@ namespace filesystem
{ {
bool initialized = false; bool initialized = false;
std::vector<std::filesystem::path>& get_search_paths_internal() std::deque<std::filesystem::path>& get_search_paths_internal()
{ {
static std::vector<std::filesystem::path> search_paths{}; static std::deque<std::filesystem::path> search_paths{};
return search_paths; return search_paths;
} }
@ -35,9 +35,9 @@ namespace filesystem
initialized = true; initialized = true;
filesystem::register_path(L"" CLIENT_DATA_FOLDER);
filesystem::register_path(L"."); filesystem::register_path(L".");
filesystem::register_path(L"h2-mod"); filesystem::register_path(L"h2-mod");
filesystem::register_path(L"" CLIENT_DATA_FOLDER);
localized_strings::clear(); localized_strings::clear();
@ -121,7 +121,7 @@ namespace filesystem
if (can_insert_path(path_)) if (can_insert_path(path_))
{ {
console::info("[FS] Registering path '%s'\n", path_.generic_string().data()); console::info("[FS] Registering path '%s'\n", path_.generic_string().data());
get_search_paths_internal().push_back(path_); get_search_paths_internal().push_front(path_);
} }
} }
} }
@ -164,6 +164,19 @@ namespace filesystem
return paths; return paths;
} }
std::vector<std::string> get_search_paths_rev()
{
std::vector<std::string> paths{};
const auto& search_paths = get_search_paths_internal();
for (auto i = search_paths.rbegin(); i != search_paths.rend(); ++i)
{
paths.push_back(i->generic_string());
}
return paths;
}
class component final : public component_interface class component final : public component_interface
{ {
public: public:

View File

@ -11,4 +11,5 @@ namespace filesystem
void unregister_path(const std::filesystem::path& path); void unregister_path(const std::filesystem::path& path);
std::vector<std::string> get_search_paths(); std::vector<std::string> get_search_paths();
std::vector<std::string> get_search_paths_rev();
} }

View File

@ -125,7 +125,7 @@ namespace localized_strings
{ {
bool found = false; bool found = false;
const auto search_paths = filesystem::get_search_paths(); const auto search_paths = filesystem::get_search_paths_rev();
const auto language = game::SEH_GetCurrentLanguageName(); const auto language = game::SEH_GetCurrentLanguageName();
for (const auto& path : search_paths) for (const auto& path : search_paths)

View File

@ -365,7 +365,7 @@ namespace ui_scripting
load_script("lui_updater", lui_updater); load_script("lui_updater", lui_updater);
load_script("lua_json", lua_json); load_script("lua_json", lua_json);
for (const auto& path : filesystem::get_search_paths()) for (const auto& path : filesystem::get_search_paths_rev())
{ {
load_scripts(path + "/ui_scripts/"); load_scripts(path + "/ui_scripts/");
} }

View File

@ -49,7 +49,7 @@ namespace scripting::lua::engine
load_generic_script(); load_generic_script();
for (const auto& path : filesystem::get_search_paths()) for (const auto& path : filesystem::get_search_paths_rev())
{ {
load_scripts(path + "/scripts/"); load_scripts(path + "/scripts/");
} }