Skip to content

Commit

Permalink
added global plugins and profiles (#223)
Browse files Browse the repository at this point in the history
* added global plugins and profiles

* Fixed inconsistent tabs

* Plugins: Check if the folder exists before loading

* Plugins: Reduce code repetition

---------

Co-authored-by: praydog <praydog@praydog.com>
  • Loading branch information
mark-mon and praydog committed Mar 12, 2024
1 parent c2bc553 commit 8f54d16
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
39 changes: 24 additions & 15 deletions src/mods/PluginLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,8 @@ void PluginLoader::early_init() try {
spdlog::info("[PluginLoader] Module path {}", utility::narrow(module_path));

const auto plugin_path = Framework::get_persistent_dir() / "plugins";

const auto global_plugins_path = Framework::get_persistent_dir() / ".." / "UEVR" / "plugins";

spdlog::info("[PluginLoader] Creating directories {}", plugin_path.string());

if (!fs::create_directories(plugin_path) && !fs::exists(plugin_path)) {
Expand All @@ -1272,23 +1273,31 @@ void PluginLoader::early_init() try {

spdlog::info("[PluginLoader] Loading plugins...");

// Load all dlls in the plugins directory.
for (auto&& entry : fs::directory_iterator{plugin_path}) {
auto&& path = entry.path();
auto load_plugins_from_dir = [this](std::filesystem::path path) {
if (!fs::exists(path) || !fs::is_directory(path)) {
return;
}

if (path.has_extension() && path.extension() == ".dll") {
auto module = LoadLibrary(path.string().c_str());
for (auto&& entry : fs::directory_iterator{path}) {
auto&& path = entry.path();

if (module == nullptr) {
spdlog::error("[PluginLoader] Failed to load {}", path.string());
m_plugin_load_errors.emplace(path.stem().string(), "Failed to load");
continue;
}
if (path.has_extension() && path.extension() == ".dll") {
auto module = LoadLibrary(path.string().c_str());

spdlog::info("[PluginLoader] Loaded {}", path.string());
m_plugins.emplace(path.stem().string(), module);
if (module == nullptr) {
spdlog::error("[PluginLoader] Failed to load {}", path.string());
m_plugin_load_errors.emplace(path.stem().string(), "Failed to load");
continue;
}

spdlog::info("[PluginLoader] Loaded {}", path.string());
m_plugins.emplace(path.stem().string(), module);
}
}
}
};

load_plugins_from_dir(global_plugins_path);
load_plugins_from_dir(plugin_path);
} catch(const std::exception& e) {
spdlog::error("[PluginLoader] Exception during early init {}", e.what());
} catch(...) {
Expand Down Expand Up @@ -1777,4 +1786,4 @@ bool PluginLoader::add_on_post_viewport_client_draw(UEVR_ViewportClient_DrawCb c

m_on_post_viewport_client_draw_cbs.push_back(cb);
return true;
}
}
13 changes: 10 additions & 3 deletions src/mods/vr/runtimes/OpenXR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,12 +983,19 @@ std::optional<std::string> OpenXR::initialize_actions(const std::string& json_st
}
}

auto filename = controller + ".json";
auto profile_file = controller + ".json";

// replace the slashes with underscores
std::replace(filename.begin(), filename.end(), '/', '_');
std::replace(profile_file.begin(), profile_file.end(), '/', '_');

// If the json exists in the game's profile dir, use that.
auto filename = (Framework::get_persistent_dir() / profile_file).string();

filename = (Framework::get_persistent_dir() / filename).string();
// If not, check for global profile in UEVR\Profiles dir
if (!std::filesystem::exists(filename)) {
filename = (Framework::get_persistent_dir() / ".." / "UEVR" / "Profiles" / profile_file).string();
spdlog::info("[VR] Setting bindings file to {}", filename);
}

// check if the file exists
if (std::filesystem::exists(filename)) {
Expand Down

0 comments on commit 8f54d16

Please sign in to comment.