diff --git a/lcUI/operationloader.cpp b/lcUI/operationloader.cpp index 21a6cca0..dae3cdab 100644 --- a/lcUI/operationloader.cpp +++ b/lcUI/operationloader.cpp @@ -6,16 +6,53 @@ #include "managers/contextmenumanager.h" #include +#include +#include #include #include using namespace lc::ui; +namespace +{ +const char* operationsLua = "/actions/operations.lua"; + +std::string findLuaFolder(std::string luaPath) +{ + if (QFileInfo{luaPath + operationsLua}.exists()) + return luaPath; + luaPath = QDir{QCoreApplication::applicationDirPath()}.canonicalPath().toStdString(); +#if (defined (LINUX) || defined (__linux__)) + luaPath += "/../share/librecad/lcUILua/"; +#endif + if (QFileInfo{luaPath + operationsLua}.exists()) + return luaPath; + + QDirIterator it(luaPath, QDirIterator::Subdirectories); + + // Iterate through the directory using the QDirIterator + while (it.hasNext()) + { + QString folder = it.next(); + QFileInfo file(folder); + if (!file.isDir()) + continue; + + if (QDir{folder}.dirName() == QString{"lcUILua"}) + return folder.toStdString(); + } + return luaPath; +} +} + + OperationLoader::OperationLoader(const std::string& luaPath, QMainWindow* qmainWindow, kaguya::State& luaState) : qmainWindow(qmainWindow), - _L(luaState) { - loadLuaOperations(luaPath); + _L(luaState) +{ + std::string path = findLuaFolder(luaPath); + loadLuaOperations(path); } void OperationLoader::loadLuaOperations(const std::string& luaPath) { diff --git a/lcUILua/CMakeLists.txt b/lcUILua/CMakeLists.txt index 7f42665d..14875454 100644 --- a/lcUILua/CMakeLists.txt +++ b/lcUILua/CMakeLists.txt @@ -29,7 +29,7 @@ install(CODE "file(WRITE \"${FINAL_INSTALL_DIR}/${CMAKE_INSTALL_BINDIR}/path.lua )") install(DIRECTORY "${CMAKE_SOURCE_DIR}/lcUILua" - DESTINATION "${FINAL_INSTALL_DIR}/usr/share/librecad" + DESTINATION "${CMAKE_INSTALL_BINDIR}/../share/librecad" PATTERN "CMakeLists.txt" EXCLUDE ) endif()