From 470e748e4a2b16872fd6756be0c2afb91883edd4 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Sun, 26 Dec 2021 02:09:37 +0100 Subject: [PATCH] Fixed weird bug where config files spointainously appear everywhere (wtf...) --- core/src/config.cpp | 2 +- core/src/core.cpp | 2 ++ core/src/gui/main_window.cpp | 11 ++++++++--- core/src/options.cpp | 4 +++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/core/src/config.cpp b/core/src/config.cpp index 2d29adb0..d5ea33f6 100644 --- a/core/src/config.cpp +++ b/core/src/config.cpp @@ -12,7 +12,7 @@ ConfigManager::~ConfigManager() { } void ConfigManager::setPath(std::string file) { - path = file; + path = std::filesystem::absolute(file).string(); } void ConfigManager::load(json def, bool lock) { diff --git a/core/src/core.cpp b/core/src/core.cpp index 97eb2902..b8156f4b 100644 --- a/core/src/core.cpp +++ b/core/src/core.cpp @@ -305,6 +305,8 @@ int sdrpp_main(int argc, char* argv[]) { json bandColors = core::configManager.conf["bandColors"]; core::configManager.release(); + // Assert that the resource directory is absolute and check existance + resDir = std::filesystem::absolute(resDir).string(); if (!std::filesystem::is_directory(resDir)) { spdlog::error("Resource directory doesn't exist! Please make sure that you've configured it correctly in config.json (check readme for details)"); return 1; diff --git a/core/src/gui/main_window.cpp b/core/src/gui/main_window.cpp index 976d381a..70e6c733 100644 --- a/core/src/gui/main_window.cpp +++ b/core/src/gui/main_window.cpp @@ -46,6 +46,10 @@ void MainWindow::init() { std::string resourcesDir = core::configManager.conf["resourcesDirectory"]; core::configManager.release(); + // Assert that directories are absolute + modulesDir = std::filesystem::absolute(modulesDir).string(); + resourcesDir = std::filesystem::absolute(resourcesDir).string(); + // Load menu elements gui::menu.order.clear(); for (auto& elem : menuElements) { @@ -123,9 +127,10 @@ void MainWindow::init() { // Load additional modules specified through config for (auto const& path : modules) { - spdlog::info("Loading {0}", path); - LoadingScreen::show("Loading " + path); - core::moduleManager.loadModule(path); + std::string apath = std::filesystem::absolute(path).string(); + spdlog::info("Loading {0}", apath); + LoadingScreen::show("Loading " + apath); + core::moduleManager.loadModule(apath); } // Create module instances diff --git a/core/src/options.cpp b/core/src/options.cpp index 38d14da0..22e8080d 100644 --- a/core/src/options.cpp +++ b/core/src/options.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace options { CMDLineOptions opts; @@ -16,6 +17,7 @@ namespace options { std::string homedir = getenv("HOME"); opts.root = homedir + "/.config/sdrpp"; #endif + opts.root = std::filesystem::absolute(opts.root).string(); } bool parse(int argc, char* argv[]) { @@ -23,7 +25,7 @@ namespace options { char* arg = argv[i]; if (!strcmp(arg, "-r") || !strcmp(arg, "--root")) { if (i == argc - 1) { return false; } - opts.root = argv[++i]; + opts.root = std::filesystem::absolute(argv[++i]).string(); } else if (!strcmp(arg, "-s") || !strcmp(arg, "--show-console")) { opts.showConsole = true;