diff options
author | saturneric <[email protected]> | 2024-11-30 21:56:29 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-11-30 21:56:29 +0000 |
commit | f9106a5ce8c4507fb511a7b53d7e623487312605 (patch) | |
tree | 8f542d1da0e60c1ca8e942c6c2a49e92989f932c | |
parent | fix: solve discovered issues (diff) | |
download | GpgFrontend-f9106a5ce8c4507fb511a7b53d7e623487312605.tar.gz GpgFrontend-f9106a5ce8c4507fb511a7b53d7e623487312605.zip |
feat: improve app structure on windows
-rw-r--r-- | src/CMakeLists.txt | 66 | ||||
-rw-r--r-- | src/core/function/GlobalSettingStation.cpp | 80 | ||||
-rw-r--r-- | src/core/module/ModuleInit.cpp | 4 |
3 files changed, 56 insertions, 94 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ba92ef27..0c9171e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -65,13 +65,13 @@ if(APPLE) configure_file(${CMAKE_SOURCE_DIR}/resource/plist/ExportOptions.plist.in ${CMAKE_BINARY_DIR}/ExportOptions.plist @ONLY) endif() -# Set Runtime Output Directory -if(NOT XCODE_BUILD) - # Set Binary Output Path - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/artifacts) -else() - # Set Binary Output Path +# Set Binary Output Path +if(XCODE_BUILD) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}) +elseif(MINGW) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/artifacts/bin) +else() + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/artifacts) endif() # Print modules @@ -105,11 +105,14 @@ if(BUILD_APPLICATION) set_property(SOURCE gpgfrontend.rc APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/gpgfrontend.ico) endif() +# Set Resource Output Path if(BUILD_APPLICATION) - # Set Resource Output Path if(${CMAKE_BUILD_TYPE} STREQUAL "Release") if(APPLE) set(RESOURCE_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Resources) + set(GPGFRONTEND_MACOS_ICON ${CMAKE_SOURCE_DIR}/gpgfrontend.icns) + set_source_files_properties(${GPGFRONTEND_MACOS_ICON} PROPERTIES + MACOSX_PACKAGE_LOCATION "Resources") elseif(LINUX AND NOT LINUX_INSTALL_SOFTWARE) set(BUILD_APP_IMAGE 1) else() @@ -120,16 +123,6 @@ if(BUILD_APPLICATION) endif() endif() -if(BUILD_APPLICATION) - if(${CMAKE_BUILD_TYPE} STREQUAL "Release") - if(APPLE) - set(GPGFRONTEND_MACOS_ICON ${CMAKE_SOURCE_DIR}/gpgfrontend.icns) - set_source_files_properties(${GPGFRONTEND_MACOS_ICON} PROPERTIES - MACOSX_PACKAGE_LOCATION "Resources") - endif() - endif() -endif() - if(BUILD_APPLICATION AND MINGW) message(STATUS "Copying Dependent DLL For Windows Runtime Env") @@ -249,35 +242,19 @@ if(BUILD_APPLICATION AND MINGW) file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libxml2-*.dll") list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath}) - # /mingw64/libexec - execute_process( - COMMAND cygpath -m /mingw64/libexec - OUTPUT_VARIABLE MSYS64_LIBEXEC_PATH - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - # gpgme-w32spawn.exe - unset(_libExEPath) - file(GLOB _libExEPath "${MSYS64_LIBEXEC_PATH}/gpgme-*.exe") - list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libExEPath}) + unset(_libDllPath) + file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libarchive*.dll") + list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath}) - unset(_libExEPath) - file(GLOB _libExEPath "${MSYS64_BIN_PATH}/gpgme-*.exe") - list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libExEPath}) + unset(_libDllPath) + file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libgtest*.dll") + list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath}) # add gpgfrontend libraries if(STABLE_BUILD_ONLY_APPLICATION) unset(_libDllPath) file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libgpgfrontend_*.dll") list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath}) - - unset(_libDllPath) - file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libarchive*.dll") - list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath}) - - unset(_libDllPath) - file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libgtest*.dll") - list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath}) endif() # dll with only name @@ -403,17 +380,6 @@ if(BUILD_APPLICATION) else() # if the status is debug add_executable(${AppName} ${BASE_SOURCE} ${RESOURCE_FILES}) - - if(MINGW) - # include qt dependencies - if(NOT Qt6_DIR) - add_custom_command(TARGET ${AppName} POST_BUILD - COMMAND windeployqt --force ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${AppName}.exe) - else() - add_custom_command(TARGET ${AppName} POST_BUILD - COMMAND windeployqt-qt6.exe --force ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${AppName}.exe) - endif() - endif() endif() # Make app build with resources diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp index 42aced01..c0b935f5 100644 --- a/src/core/function/GlobalSettingStation.cpp +++ b/src/core/function/GlobalSettingStation.cpp @@ -40,22 +40,23 @@ class GlobalSettingStation::Impl { * */ explicit Impl() noexcept { - LOG_I() << "app path: " << GetAppDir(); + LOG_I() << "app path: " << app_path_; LOG_I() << "app working path: " << working_path_; auto portable_file_path = working_path_ + "/PORTABLE.txt"; if (QFileInfo(portable_file_path).exists()) { Module::UpsertRTValue("core", "env.state.portable", 1); + LOG_I() << "GpgFrontend runs in the portable mode now"; - app_data_path_ = working_path_; - app_log_path_ = app_data_path_ + "/logs"; - app_data_objs_path_ = app_data_path_ + "/data_objs"; + app_data_path_ = app_path_ + "/../"; + app_config_path_ = app_data_path_ + "/config"; portable_mode_ = true; } LOG_I() << "app data path: " << app_data_path_; - LOG_I() << "app log path: " << app_log_path_; + LOG_I() << "app log path: " << app_log_path(); + LOG_I() << "app modules path: " << app_modules_path(); #if defined(_WIN32) || defined(WIN32) LOG_I() << "app config path: " << app_config_path_; @@ -63,36 +64,35 @@ class GlobalSettingStation::Impl { #endif if (!QDir(app_data_path_).exists()) QDir(app_data_path_).mkpath("."); - if (!QDir(app_log_path_).exists()) QDir(app_log_path_).mkpath("."); - if (!QDir(GetModulesDir()).exists()) QDir(GetModulesDir()).mkpath("."); + if (!QDir(app_log_path()).exists()) QDir(app_log_path()).mkpath("."); + if (!QDir(app_modules_path()).exists()) { + QDir(app_modules_path()).mkpath("."); + } } [[nodiscard]] auto GetSettings() -> QSettings { - if (!portable_mode_) { #if defined(_WIN32) || defined(WIN32) - return QSettings(app_config_target_path_, QSettings::IniFormat); + return QSettings(app_config_file_path_, QSettings::IniFormat); #else - return QSettings(); + return QSettings(); #endif - } - return {app_portable_config_path_, QSettings::IniFormat}; } [[nodiscard]] auto GetLogFilesSize() const -> QString { - return GetHumanFriendlyFileSize(GetFileSizeByPath(app_log_path_, "*.log")); + return GetHumanFriendlyFileSize(GetFileSizeByPath(app_log_path(), "*.log")); } [[nodiscard]] auto GetDataObjectsFilesSize() const -> QString { return GetHumanFriendlyFileSize( - GetFileSizeByPath(app_data_objs_path_, "*")); + GetFileSizeByPath(app_data_objs_path(), "*")); } void ClearAllLogFiles() const { - DeleteAllFilesByPattern(app_log_path_, "*.log"); + DeleteAllFilesByPattern(app_log_path(), "*.log"); } void ClearAllDataObjects() const { - DeleteAllFilesByPattern(app_data_objs_path_, "*"); + DeleteAllFilesByPattern(app_data_objs_path(), "*"); } /** @@ -100,9 +100,7 @@ class GlobalSettingStation::Impl { * * @return QString */ - [[nodiscard]] auto GetAppDir() const -> QString { - return QCoreApplication::applicationDirPath(); - } + [[nodiscard]] auto GetAppDir() const -> QString { return app_path_; } /** * @brief Get the App Data Path object @@ -118,7 +116,7 @@ class GlobalSettingStation::Impl { * * @return QString */ - [[nodiscard]] auto GetLogDir() const -> QString { return app_log_path_; } + [[nodiscard]] auto GetLogDir() const -> QString { return app_log_path(); } /** * @brief Get the Modules Dir object @@ -126,35 +124,33 @@ class GlobalSettingStation::Impl { * @return QString */ [[nodiscard]] auto GetModulesDir() const -> QString { - return GetAppDataPath() + "/mods"; + return app_modules_path(); } private: - QString working_path_ = QDir::currentPath(); - - QString app_data_path_ = QString{QStandardPaths::writableLocation( - QStandardPaths::AppLocalDataLocation)}; ///< Program Data Location - - QString app_config_path_ = QString{ - QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)}; - - QString app_log_path_ = app_data_path_ + "/logs"; ///< Program Data Location + [[nodiscard]] auto app_config_file_path() const -> QString { + return app_config_path_ + "/config.ini"; + } - QString app_data_objs_path_ = - app_data_path_ + "/data_objs"; ///< Object storage path + [[nodiscard]] auto app_data_objs_path() const -> QString { + return app_data_path_ + "/data_objs"; + } - QString app_config_target_path_ = - app_config_path_ + "/config.ini"; ///< take effect only in portable mode + [[nodiscard]] auto app_log_path() const -> QString { + return app_data_path_ + "/logs"; + } - bool portable_mode_ = false; ///< - QString app_portable_config_path_ = - working_path_ + "/config.ini"; ///< take effect only in portable mode + [[nodiscard]] auto app_modules_path() const -> QString { + return app_data_path_ + "/mods"; + } - /** - * @brief - * - */ - void init_app_secure_key() {} + bool portable_mode_ = false; + const QString app_path_ = QCoreApplication::applicationDirPath(); + QString working_path_ = QDir::currentPath(); + QString app_data_path_ = QString{ + QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)}; + QString app_config_path_ = QString{ + QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)}; }; GlobalSettingStation::GlobalSettingStation(int channel) noexcept diff --git a/src/core/module/ModuleInit.cpp b/src/core/module/ModuleInit.cpp index 972e7025..175d35ad 100644 --- a/src/core/module/ModuleInit.cpp +++ b/src/core/module/ModuleInit.cpp @@ -49,8 +49,8 @@ auto SearchModuleFromPath(const QString& mods_path, } auto LoadIntegratedMods() -> QMap<QString, bool> { - const auto exec_binary_path = QCoreApplication::applicationDirPath(); - QString mods_path = exec_binary_path + "/modules"; + const auto exec_binary_path = GlobalSettingStation::GetInstance().GetAppDir(); + QString mods_path = exec_binary_path + "/../modules"; #ifdef NDEBUG |