diff --git a/libs/module/ApplicationContextBase.cpp b/libs/module/ApplicationContextBase.cpp index 93e6032017..5f99ec7a65 100644 --- a/libs/module/ApplicationContextBase.cpp +++ b/libs/module/ApplicationContextBase.cpp @@ -8,16 +8,22 @@ #include "os/fs.h" #include "os/path.h" #include "os/dir.h" -#if 0 -#include "log/PopupErrorHandler.h" -#endif -#if defined(WIN32) +#include "string/encoding.h" + +#ifdef WIN32 +#define NOMINMAX #include #endif namespace radiant { +namespace +{ + const std::string PLUGINS_DIR = "plugins/"; ///< name of plugins directory + const std::string MODULES_DIR = "modules/"; ///< name of modules directory +} + /** * Return the application path of the current Radiant instance. */ @@ -28,21 +34,33 @@ std::string ApplicationContextBase::getApplicationPath() const std::vector ApplicationContextBase::getLibraryPaths() const { - std::vector libPaths; + auto libBasePath = os::standardPathWithSlash(getLibraryBasePath()); + +#if defined(__APPLE__) && defined(DR_MODULES_NEXT_TO_APP) + // Xcode output goes to the application folder right now + return { libBasePath }; +#else + return + { + libBasePath + MODULES_DIR, + libBasePath + PLUGINS_DIR + }; +#endif +} +std::string ApplicationContextBase::getLibraryBasePath() const +{ #if defined(__APPLE__) - libPaths.push_back(_appPath); + return _appPath; #elif defined(POSIX) # if defined(PKGLIBDIR) && !defined(ENABLE_RELOCATION) - libPaths.push_back(PKGLIBDIR); + return PKGLIBDIR; # else - libPaths.push_back(_appPath + "../lib/darkradiant/"); + return _appPath + "../lib/darkradiant/"; # endif #else // !defined(POSIX) - libPaths.push_back(_appPath); + return _appPath; #endif - - return libPaths; } std::string ApplicationContextBase::getRuntimeDataPath() const @@ -263,7 +281,7 @@ void ApplicationContextBase::initialise(int argc, char* argv[]) // convert to std::string std::wstring wide(filename); - std::string appPathNarrow(wide.begin(), wide.end()); + std::string appPathNarrow = string::unicode_to_mb(wide); // Make sure we have forward slashes _appPath = os::standardPath(appPathNarrow); diff --git a/libs/module/ApplicationContextBase.h b/libs/module/ApplicationContextBase.h index a18da7cf00..ffec9947f0 100644 --- a/libs/module/ApplicationContextBase.h +++ b/libs/module/ApplicationContextBase.h @@ -45,6 +45,9 @@ class ApplicationContextBase : protected: void setErrorHandlingFunction(const ErrorHandlingFunction& function); + // The platform-specific path where any library folders like modules/ and plugins/ are stored + std::string getLibraryBasePath() const; + private: // Sets up the bitmap path and settings path void initPaths(); diff --git a/radiantcore/Makefile.am b/radiantcore/Makefile.am index 73095ba9b8..4dd7637a1a 100644 --- a/radiantcore/Makefile.am +++ b/radiantcore/Makefile.am @@ -1,4 +1,4 @@ -libradiantcoredir = $(pkglibdir) +libradiantcoredir = $(pkglibdir)/modules libradiantcore_LTLIBRARIES = libradiantcore.la libradiantcore_la_CPPFLAGS = -DPKGLIBDIR='"$(pkglibdir)"' \ diff --git a/radiantcore/modulesystem/ModuleLoader.cpp b/radiantcore/modulesystem/ModuleLoader.cpp index abdc665656..6e0306aa51 100644 --- a/radiantcore/modulesystem/ModuleLoader.cpp +++ b/radiantcore/modulesystem/ModuleLoader.cpp @@ -16,9 +16,6 @@ namespace module namespace { - const std::string PLUGINS_DIR = "plugins/"; ///< name of plugins directory - const std::string MODULES_DIR = "modules/"; ///< name of modules directory - // This is the name of the entry point symbol in the module const char* const SYMBOL_REGISTER_MODULE = "RegisterModule"; @@ -91,10 +88,11 @@ void ModuleLoader::processModuleFile(const fs::path& file) } } -void ModuleLoader::loadModules(const std::string& root) +#if 0 +void ModuleLoader::loadModules(const std::string& libraryPath) { // Get standardised paths - std::string stdRoot = os::standardPathWithSlash(root); + std::string stdRoot = os::standardPathWithSlash(libraryPath); #if defined(DR_MODULES_NEXT_TO_APP) // Xcode output goes to the application folder right now @@ -105,7 +103,7 @@ void ModuleLoader::loadModules(const std::string& root) std::string pluginsPath = stdRoot + PLUGINS_DIR; #endif - rConsole() << "ModuleLoader: loading modules from " << root << std::endl; + rConsole() << "ModuleLoader: loading modules from " << libraryPath << std::endl; // Load modules first, then plugins loadModulesFromPath(modulesPath); @@ -116,13 +114,16 @@ void ModuleLoader::loadModules(const std::string& root) loadModulesFromPath(pluginsPath); } } +#endif void ModuleLoader::loadModulesFromPath(const std::string& path) { + rConsole() << "ModuleLoader: loading modules from " << path << std::endl; + // In case the folder is non-existent, catch the exception try { - os::foreachItemInDirectory(path, [&](const fs::path& file) + os::foreachItemInDirectory(os::standardPathWithSlash(path), [&](const fs::path& file) { processModuleFile(file); }); diff --git a/radiantcore/modulesystem/ModuleLoader.h b/radiantcore/modulesystem/ModuleLoader.h index 1c7ef5b496..47a04fb124 100644 --- a/radiantcore/modulesystem/ModuleLoader.h +++ b/radiantcore/modulesystem/ModuleLoader.h @@ -27,15 +27,13 @@ class ModuleLoader public: ModuleLoader(IModuleRegistry& registry); - // Load algorithm, searches plugins/ and modules/ for .dll/.so files - void loadModules(const std::string& root); + // Load algorithm, searches the given folder for .dll/.so files + void loadModulesFromPath(const std::string& path); // Frees the list of DLLs void unloadModules(); private: - void loadModulesFromPath(const std::string& path); - // File functor, gets called with each file's name in the searched folder void processModuleFile(const fs::path& fileName); }; diff --git a/radiantcore/modulesystem/ModuleRegistry.cpp b/radiantcore/modulesystem/ModuleRegistry.cpp index 6a86f3b29c..78929b5ad4 100644 --- a/radiantcore/modulesystem/ModuleRegistry.cpp +++ b/radiantcore/modulesystem/ModuleRegistry.cpp @@ -165,7 +165,7 @@ void ModuleRegistry::loadAndInitialiseModules() auto libraryPaths = _context.getLibraryPaths(); for (auto path : libraryPaths) { - _loader->loadModules(path); + _loader->loadModulesFromPath(path); } _progress = 0.1f; diff --git a/tools/msvc/DarkRadiantCore.vcxproj b/tools/msvc/DarkRadiantCore.vcxproj index 0b39957fb4..1a4d5fc798 100644 --- a/tools/msvc/DarkRadiantCore.vcxproj +++ b/tools/msvc/DarkRadiantCore.vcxproj @@ -1105,16 +1105,16 @@ - $(SolutionDir)\..\..\install\ + $(SolutionDir)\..\..\install\modules\ - $(SolutionDir)\..\..\install\ + $(SolutionDir)\..\..\install\modules\ - $(SolutionDir)\..\..\install\ + $(SolutionDir)\..\..\install\modules\ - $(SolutionDir)\..\..\install\ + $(SolutionDir)\..\..\install\modules\