diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/GpgConstants.h | 4 | ||||
-rw-r--r-- | src/core/GpgContext.cpp | 13 | ||||
-rw-r--r-- | src/core/GpgCoreInit.cpp | 50 | ||||
-rw-r--r-- | src/core/GpgCoreInit.h | 12 | ||||
-rw-r--r-- | src/core/GpgFunctionObject.cpp | 8 | ||||
-rw-r--r-- | src/core/GpgFunctionObject.h | 10 | ||||
-rw-r--r-- | src/core/function/GlobalSettingStation.cpp | 1 | ||||
-rw-r--r-- | src/core/function/GlobalSettingStation.h | 5 |
8 files changed, 89 insertions, 14 deletions
diff --git a/src/core/GpgConstants.h b/src/core/GpgConstants.h index 06f8e20d..a8a87835 100644 --- a/src/core/GpgConstants.h +++ b/src/core/GpgConstants.h @@ -31,10 +31,10 @@ #include "GpgFrontendCore.h" -const int RESTART_CODE = 1000; ///< +const int RESTART_CODE = 1000; ///< only refresh ui +const int DEEP_RESTART_CODE = 1001; // refresh core and ui namespace GpgFrontend { - using ByteArray = std::string; ///< using ByteArrayPtr = std::unique_ptr<ByteArray>; ///< using StdBypeArrayPtr = std::unique_ptr<ByteArray>; ///< diff --git a/src/core/GpgContext.cpp b/src/core/GpgContext.cpp index 28857d32..7ebd9fa9 100644 --- a/src/core/GpgContext.cpp +++ b/src/core/GpgContext.cpp @@ -102,6 +102,9 @@ GpgContext::GpgContext(const GpgContextInitArgs &args) : args_(args) { find_openpgp = true; info_.AppPath = engine_info->file_name; info_.GnupgVersion = engine_info->version; + info_.DatabasePath = std::string(engine_info->home_dir == nullptr + ? "default" + : engine_info->home_dir); break; case GPGME_PROTOCOL_CMS: find_cms = true; @@ -128,6 +131,16 @@ GpgContext::GpgContext(const GpgContextInitArgs &args) : args_(args) { engine_info = engine_info->next; } + // set custom key db path + if (!args.db_path.empty()) { + info_.DatabasePath = args.db_path; + auto err = gpgme_ctx_set_engine_info(_ctx_ref.get(), GPGME_PROTOCOL_OpenPGP, + info_.AppPath.c_str(), + info_.DatabasePath.c_str()); + LOG(INFO) << "ctx set custom key db path:" << info_.DatabasePath; + assert(check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR); + } + // conditional check if ((info_.GnupgVersion >= "2.0.0" && find_gpgconf && find_openpgp && find_cms) || diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index f1664b2a..9ccc693d 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -77,23 +77,69 @@ void InitLoggingSystem() { LOG(INFO) << _("log file path") << logfile_path; } +void ResetGpgFrontendCore() { reset_gpgfrontend_core(); } + void init_gpgfrontend_core() { + // read from settings file + + bool use_custom_key_database_path = false; + try { + auto& settings = + GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings(); + use_custom_key_database_path = + settings.lookup("general.use_custom_key_database_path"); + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") + << _("use_custom_key_database_path"); + } + + LOG(INFO) << "core loaded if use custom key databse path: " + << use_custom_key_database_path; + + std::string custom_key_database_path; + try { + auto& settings = + GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings(); + custom_key_database_path = static_cast<std::string>( + settings.lookup("general.custom_key_database_path")); + + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") << _("custom_key_database_path"); + } + + LOG(INFO) << "core loaded custom key databse path: " + << custom_key_database_path; + // init default channel GpgFrontend::GpgContext::CreateInstance( - GPGFRONTEND_DEFAULT_CHANNEL, [&]() -> std::unique_ptr<ChannelObject> { + GPGFRONTEND_DEFAULT_CHANNEL, [=]() -> std::unique_ptr<ChannelObject> { GpgFrontend::GpgContextInitArgs args; + + // set key database path + if (use_custom_key_database_path && !custom_key_database_path.empty()) { + args.db_path = custom_key_database_path; + } + return std::unique_ptr<ChannelObject>(new GpgContext(args)); }); // init non-ascii channel GpgFrontend::GpgContext::CreateInstance( - GPGFRONTEND_NON_ASCII_CHANNEL, [&]() -> std::unique_ptr<ChannelObject> { + GPGFRONTEND_NON_ASCII_CHANNEL, [=]() -> std::unique_ptr<ChannelObject> { GpgFrontend::GpgContextInitArgs args; args.ascii = false; + + // set key database path + if (use_custom_key_database_path && !custom_key_database_path.empty()) { + args.db_path = custom_key_database_path; + } + return std::unique_ptr<ChannelObject>(new GpgContext(args)); }); } +void reset_gpgfrontend_core() { SingletonStorageCollection::GetInstance(true); } + void new_default_settings_channel(int channel) { GpgFrontend::GpgContext::CreateInstance( channel, [&]() -> std::unique_ptr<ChannelObject> { diff --git a/src/core/GpgCoreInit.h b/src/core/GpgCoreInit.h index 150e85e9..77942b56 100644 --- a/src/core/GpgCoreInit.h +++ b/src/core/GpgCoreInit.h @@ -43,11 +43,23 @@ void GPGFRONTEND_CORE_EXPORT InitLoggingSystem(); * @brief * */ +void GPGFRONTEND_CORE_EXPORT ResetGpgFrontendCore(); + +/** + * @brief + * + */ void init_gpgfrontend_core(); /** * @brief * + */ +void reset_gpgfrontend_core(); + +/** + * @brief + * * @param channel */ void new_default_settings_channel( diff --git a/src/core/GpgFunctionObject.cpp b/src/core/GpgFunctionObject.cpp index 1289d72f..6ff83d72 100644 --- a/src/core/GpgFunctionObject.cpp +++ b/src/core/GpgFunctionObject.cpp @@ -122,11 +122,15 @@ GpgFrontend::SingletonStorageCollection::GetSingletonStorage( } GpgFrontend::SingletonStorageCollection* -GpgFrontend::SingletonStorageCollection::GetInstance() { +GpgFrontend::SingletonStorageCollection::GetInstance( + bool force_refresh = false) { static SingletonStorageCollection* instance = nullptr; - if (instance == nullptr) { + + if (force_refresh || instance == nullptr) { instance = new SingletonStorageCollection(); + LOG(INFO) << "new single storage collection created: " << instance; } + return instance; } diff --git a/src/core/GpgFunctionObject.h b/src/core/GpgFunctionObject.h index de27ea42..56d0ab22 100644 --- a/src/core/GpgFunctionObject.h +++ b/src/core/GpgFunctionObject.h @@ -125,7 +125,7 @@ class GPGFRONTEND_CORE_EXPORT SingletonStorageCollection { * * @return SingletonStorageCollection* */ - static SingletonStorageCollection* GetInstance(); + static SingletonStorageCollection* GetInstance(bool force_refresh); /** * @brief Get the Singleton Storage object @@ -173,7 +173,7 @@ class SingletonFunctionObject : public ChannelObject { "T not derived from SingletonFunctionObject<T>"); auto p_storage = - SingletonStorageCollection::GetInstance()->GetSingletonStorage( + SingletonStorageCollection::GetInstance(false)->GetSingletonStorage( typeid(T)); auto* _p_pbj = (T*)(p_storage->FindObjectInChannel(channel)); @@ -200,7 +200,7 @@ class SingletonFunctionObject : public ChannelObject { "T not derived from SingletonFunctionObject<T>"); auto p_storage = - SingletonStorageCollection::GetInstance()->GetSingletonStorage( + SingletonStorageCollection::GetInstance(false)->GetSingletonStorage( typeid(T)); auto _p_pbj = (T*)(p_storage->FindObjectInChannel(channel)); @@ -219,7 +219,7 @@ class SingletonFunctionObject : public ChannelObject { * @return T& */ static void ReleaseChannel(int channel) { - SingletonStorageCollection::GetInstance() + SingletonStorageCollection::GetInstance(false) ->GetSingletonStorage(typeid(T)) ->ReleaseChannel(channel); } @@ -244,7 +244,7 @@ class SingletonFunctionObject : public ChannelObject { * @return std::vector<int> */ static std::vector<int> GetAllChannelId() { - return SingletonStorageCollection::GetInstance() + return SingletonStorageCollection::GetInstance(false) ->GetSingletonStorage(typeid(T)) ->GetAllChannelId(); } diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp index db8d1bc3..7231ac9e 100644 --- a/src/core/function/GlobalSettingStation.cpp +++ b/src/core/function/GlobalSettingStation.cpp @@ -55,6 +55,7 @@ GpgFrontend::GlobalSettingStation::GlobalSettingStation(int channel) noexcept LOG(INFO) << _("App Data Path") << app_data_path_; LOG(INFO) << _("App Log Path") << app_log_path_; LOG(INFO) << _("App Locale Path") << app_locale_path_; + LOG(INFO) << _("App Conf Path") << ui_config_path_; if (!is_directory(app_configure_path_)) create_directory(app_configure_path_); diff --git a/src/core/function/GlobalSettingStation.h b/src/core/function/GlobalSettingStation.h index 58282466..8811623f 100644 --- a/src/core/function/GlobalSettingStation.h +++ b/src/core/function/GlobalSettingStation.h @@ -173,10 +173,9 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) .toStdString(); ///< Program Configure Location std::filesystem::path ui_config_dir_path_ = - app_configure_path_ / - "UserInterface"; ///< Configure File Directory Location + app_configure_path_ / "conf"; ///< Configure File Directory Location std::filesystem::path ui_config_path_ = - ui_config_dir_path_ / "ui.cfg"; ///< UI Configure File Location + ui_config_dir_path_ / "main.cfg"; ///< Main Configure File Location libconfig::Config ui_cfg_; ///< UI Configure File |