aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-01-23 06:55:18 +0000
committersaturneric <[email protected]>2024-01-23 06:55:18 +0000
commita9c382c7338ded874604bb4f9038d16e604417c7 (patch)
treea5d4790a6b2efc8786a3c0f74a07f5a8032d4e94
parentfeat: improve gpg context configure logic and ui (diff)
downloadGpgFrontend-a9c382c7338ded874604bb4f9038d16e604417c7.tar.gz
GpgFrontend-a9c382c7338ded874604bb4f9038d16e604417c7.zip
fix: solve issues on detected gnupg path function and fix linking errors on windows platform
-rw-r--r--src/core/CMakeLists.txt7
-rw-r--r--src/core/GpgCoreInit.cpp154
-rw-r--r--src/core/log/QtLoggerFmt.h21
-rw-r--r--src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt2
-rw-r--r--src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.h6
-rw-r--r--src/module/integrated/gnupg_info_gathering_module/GpgFrontendModuleExport.h42
-rw-r--r--src/module/integrated/version_checking_module/CMakeLists.txt2
-rw-r--r--src/module/integrated/version_checking_module/GpgFrontendModuleExport.h42
-rw-r--r--src/module/integrated/version_checking_module/SoftwareVersion.cpp1
-rw-r--r--src/module/integrated/version_checking_module/VersionCheckingModule.h7
10 files changed, 223 insertions, 61 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index d51ec6d1..ed12ad01 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -46,6 +46,13 @@ generate_export_header(gpgfrontend_core EXPORT_FILE_NAME "${_export_file}")
if(NOT APPLE)
target_link_libraries(gpgfrontend_core PUBLIC mimalloc)
+ if(MINGW)
+ set_target_properties(mimalloc
+ PROPERTIES
+ LIBRARY_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
+ )
+ endif()
endif()
# qt-aes
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp
index 286c6d1f..f231056f 100644
--- a/src/core/GpgCoreInit.cpp
+++ b/src/core/GpgCoreInit.cpp
@@ -77,7 +77,7 @@ auto SearchKeyDatabasePath(const QList<QString>& candidate_paths) -> QString {
return {};
}
-auto InitGpgME() -> bool {
+auto InitGpgME(const QString& gnupg_path) -> bool {
// init gpgme subsystem and get gpgme library version
Module::UpsertRTValue("core", "gpgme.version",
QString(gpgme_check_version(nullptr)));
@@ -87,8 +87,13 @@ auto InitGpgME() -> bool {
gpgme_set_locale(nullptr, LC_MESSAGES, setlocale(LC_MESSAGES, nullptr));
#endif
- gpgme_ctx_t p_ctx;
+ if (!gnupg_path.isEmpty()) {
+ GF_CORE_LOG_DEBUG("gpgme set engine info, gnupg path: {}", gnupg_path);
+ CheckGpgError(gpgme_set_engine_info(GPGME_PROTOCOL_OPENPGP,
+ gnupg_path.toUtf8(), nullptr));
+ }
+ gpgme_ctx_t p_ctx;
CheckGpgError(gpgme_new(&p_ctx));
// get engine info
@@ -179,6 +184,90 @@ auto InitGpgME() -> bool {
return true;
}
+auto GetGnuPGPathByGpgConf(const QString& gnupg_install_fs_path) -> QString {
+ auto* process = new QProcess();
+ process->setProgram(gnupg_install_fs_path);
+ process->start();
+ process->waitForFinished(1000);
+ auto output_buffer = process->readAllStandardOutput();
+ process->deleteLater();
+
+ if (output_buffer.isEmpty()) return {};
+
+ auto line_split_list = QString(output_buffer).split("\n");
+ for (const auto& line : line_split_list) {
+ auto info_split_list = line.split(":");
+
+ if (info_split_list.size() != 3) continue;
+
+ auto component_name = info_split_list[0].trimmed();
+ auto component_desc = info_split_list[1].trimmed();
+ auto component_path = info_split_list[2].trimmed();
+
+ if (component_name.toLower() == "gpg") {
+#ifdef WINDOWS
+ // replace some special substrings on windows platform
+ component_path.replace("%3a", ":");
+#endif
+ QFileInfo file_info(component_path);
+ if (file_info.exists() && file_info.isFile()) {
+ return file_info.absoluteFilePath();
+ }
+ return {};
+ }
+ }
+ return "";
+}
+
+auto DetectGnuPGPath() -> QString {
+ auto settings = GlobalSettingStation::GetInstance().GetSettings();
+ auto use_custom_gnupg_install_path =
+ settings.value("basic/use_custom_gnupg_install_path", false).toBool();
+ auto custom_gnupg_install_path =
+ settings.value("basic/custom_gnupg_install_path", QString{}).toString();
+
+ QString gnupg_install_fs_path;
+ // user defined
+ if (use_custom_gnupg_install_path && !custom_gnupg_install_path.isEmpty()) {
+ // check gpgconf path
+ gnupg_install_fs_path = custom_gnupg_install_path;
+#ifdef WINDOWS
+ gnupg_install_fs_path += "/gpgconf.exe";
+#else
+ gnupg_install_fs_path += "/gpgconf";
+#endif
+
+ if (!VerifyGpgconfPath(QFileInfo(gnupg_install_fs_path))) {
+ GF_CORE_LOG_ERROR("core loaded custom gpgconf path is illegal: {}",
+ gnupg_install_fs_path);
+ gnupg_install_fs_path = "";
+ }
+ }
+
+ // fallback to default path
+ if (gnupg_install_fs_path.isEmpty()) {
+#ifdef MACOS
+ gnupg_install_fs_path = SearchGpgconfPath(
+ {"/usr/local/bin/gpgconf", "/opt/homebrew/bin/gpgconf"});
+ GF_CORE_LOG_DEBUG("core loaded searched gpgconf path: {}",
+ gnupg_install_fs_path);
+#endif
+
+#ifdef WINDOWS
+ gnupg_install_fs_path =
+ SearchGpgconfPath({"C:/Program Files (x86)/gnupg/bin"});
+ GF_CORE_LOG_DEBUG("core loaded searched gpgconf path: {}",
+ gnupg_install_fs_path);
+#endif
+ }
+
+ if (!gnupg_install_fs_path.isEmpty()) {
+ return GetGnuPGPathByGpgConf(
+ QFileInfo(gnupg_install_fs_path).absoluteFilePath());
+ }
+ return "";
+}
+
void InitGpgFrontendCore(CoreInitArgs args) {
// initialize global register table
Module::UpsertRTValue("core", "env.state.gpgme", 0);
@@ -190,15 +279,18 @@ void InitGpgFrontendCore(CoreInitArgs args) {
// initialize locale environment
GF_CORE_LOG_DEBUG("locale: {}", setlocale(LC_CTYPE, nullptr));
+ auto gnupg_install_fs_path = DetectGnuPGPath();
+ GF_CORE_LOG_INFO("detected gnupg path: {}", gnupg_install_fs_path);
+
// initialize library gpgme
- if (!InitGpgME()) {
+ if (!InitGpgME(gnupg_install_fs_path)) {
CoreSignalStation::GetInstance()->SignalBadGnupgEnv(
QObject::tr("GpgME inilization failed"));
return;
}
auto* task = new Thread::Task(
- [args](const DataObjectPtr&) -> int {
+ [args, gnupg_install_fs_path](const DataObjectPtr&) -> int {
auto settings = GlobalSettingStation::GetInstance().GetSettings();
// read settings from config file
auto forbid_all_gnupg_connection =
@@ -216,10 +308,6 @@ void InitGpgFrontendCore(CoreInitArgs args) {
settings.value("basic/custom_key_database_path", QString{})
.toString();
- auto use_custom_gnupg_install_path =
- settings.value("basic/use_custom_gnupg_install_path", false)
- .toBool();
-
auto custom_gnupg_install_path =
settings.value("basic/custom_gnupg_install_path", QString{})
.toString();
@@ -233,36 +321,6 @@ void InitGpgFrontendCore(CoreInitArgs args) {
GF_CORE_LOG_DEBUG("core loaded custom key databse path: {}",
custom_key_database_path);
- QString gnupg_install_fs_path;
- // user defined
- if (use_custom_gnupg_install_path &&
- !custom_gnupg_install_path.isEmpty()) {
- // check gpgconf path
- gnupg_install_fs_path = custom_gnupg_install_path;
-#ifdef WINDOWS
- gnupg_install_fs_path += "/gpgconf.exe";
-#else
- gnupg_install_fs_path += "/gpgconf";
-#endif
-
- if (!VerifyGpgconfPath(QFileInfo(gnupg_install_fs_path))) {
- use_custom_gnupg_install_path = false;
- GF_CORE_LOG_ERROR("core loaded custom gpgconf path is illegal: {}",
- gnupg_install_fs_path);
- } else {
- GF_CORE_LOG_DEBUG("core loaded custom gpgconf path: {}",
- gnupg_install_fs_path);
- }
- } else {
-#ifdef MACOS
- use_custom_gnupg_install_path = true;
- gnupg_install_fs_path = SearchGpgconfPath(
- {"/usr/local/bin/gpgconf", "/opt/homebrew/bin/gpgconf"});
- GF_CORE_LOG_DEBUG("core loaded searched gpgconf path: {}",
- gnupg_install_fs_path);
-#endif
- }
-
// check key database path
QString key_database_fs_path;
// user defined
@@ -307,26 +365,14 @@ void InitGpgFrontendCore(CoreInitArgs args) {
GF_CORE_LOG_ERROR(
"custom key database path: {}, is not point to "
"an accessible directory",
- gnupg_install_fs_path);
+ key_database_fs_path);
}
}
// set custom gnupg path
- if (use_custom_gnupg_install_path &&
- !gnupg_install_fs_path.isEmpty()) {
- QFileInfo file_info(gnupg_install_fs_path);
- if (file_info.exists() && file_info.isFile() &&
- file_info.isExecutable()) {
- args.custom_gpgconf = true;
- args.custom_gpgconf_path = file_info.absoluteFilePath();
- GF_CORE_LOG_INFO("using gnupg path: {}",
- args.custom_gpgconf_path);
- } else {
- GF_CORE_LOG_ERROR(
- "custom gnupg path: {}, is not point to an executable "
- "gpgconf binary",
- gnupg_install_fs_path);
- }
+ if (!gnupg_install_fs_path.isEmpty()) {
+ args.custom_gpgconf = true;
+ args.custom_gpgconf_path = gnupg_install_fs_path;
}
args.offline_mode = forbid_all_gnupg_connection;
diff --git a/src/core/log/QtLoggerFmt.h b/src/core/log/QtLoggerFmt.h
index dbf97c64..e7ac2c82 100644
--- a/src/core/log/QtLoggerFmt.h
+++ b/src/core/log/QtLoggerFmt.h
@@ -41,7 +41,24 @@ struct fmt::formatter<QString> {
-> decltype(ctx.out()) {
// Convert QString to UTF-8 QString (to handle Unicode characters
// correctly)
- QByteArray utf8Str = qstr.toUtf8();
- return fmt::format_to(ctx.out(), "{}", utf8Str.constData());
+ QByteArray utf8_array = qstr.toUtf8();
+ return fmt::format_to(ctx.out(), "{}", utf8_array.constData());
+ }
+};
+
+template <>
+struct fmt::formatter<QByteArray> {
+ // Parses format specifications.
+ constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) {
+ return ctx.begin();
+ }
+
+ // Formats the QString qstr and writes it to the output.
+ template <typename FormatContext>
+ auto format(const QByteArray& qarray, FormatContext& ctx) const
+ -> decltype(ctx.out()) {
+ // Convert QString to UTF-8 QString (to handle Unicode characters
+ // correctly)
+ return fmt::format_to(ctx.out(), "{}", qarray.constData());
}
};
diff --git a/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt b/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt
index e8ec477c..48dbd0de 100644
--- a/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt
+++ b/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt
@@ -29,6 +29,8 @@ aux_source_directory(. INTEGRATED_MODULE_SOURCE)
# define libgpgfrontend_module
add_library(gpgfrontend_integrated_module_gnupg_info_gathering SHARED ${INTEGRATED_MODULE_SOURCE})
+set(_export_file "${CMAKE_CURRENT_SOURCE_DIR}/GpgFrontendModuleExport.h")
+generate_export_header(gpgfrontend_integrated_module_gnupg_info_gathering EXPORT_FILE_NAME "${_export_file}")
if (XCODE_BUILD)
set_target_properties(gpgfrontend_integrated_module_gnupg_info_gathering
diff --git a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.h b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.h
index 8b62ceba..88f64d7d 100644
--- a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.h
+++ b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.h
@@ -28,7 +28,8 @@
#pragma once
-#include <module/sdk/GpgFrontendModuleSDK.h>
+#include "GpgFrontendModuleExport.h"
+#include "core/module/Module.h"
namespace GpgFrontend::Module::Integrated::GnuPGInfoGatheringModule {
@@ -36,7 +37,8 @@ namespace GpgFrontend::Module::Integrated::GnuPGInfoGatheringModule {
* @brief Use to record some info about gnupg
*
*/
-class GPGFRONTEND_MODULE_SDK_EXPORT GnuPGInfoGatheringModule : public Module {
+class GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_EXPORT
+ GnuPGInfoGatheringModule : public Module {
public:
GnuPGInfoGatheringModule();
diff --git a/src/module/integrated/gnupg_info_gathering_module/GpgFrontendModuleExport.h b/src/module/integrated/gnupg_info_gathering_module/GpgFrontendModuleExport.h
new file mode 100644
index 00000000..3a5ba68b
--- /dev/null
+++ b/src/module/integrated/gnupg_info_gathering_module/GpgFrontendModuleExport.h
@@ -0,0 +1,42 @@
+
+#ifndef GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_EXPORT_H
+#define GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_EXPORT_H
+
+#ifdef GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_STATIC_DEFINE
+# define GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_EXPORT
+# define GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_NO_EXPORT
+#else
+# ifndef GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_EXPORT
+# ifdef gpgfrontend_integrated_module_gnupg_info_gathering_EXPORTS
+ /* We are building this library */
+# define GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_EXPORT __attribute__((visibility("default")))
+# else
+ /* We are using this library */
+# define GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_EXPORT __attribute__((visibility("default")))
+# endif
+# endif
+
+# ifndef GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_NO_EXPORT
+# define GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_NO_EXPORT __attribute__((visibility("hidden")))
+# endif
+#endif
+
+#ifndef GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_DEPRECATED
+# define GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_DEPRECATED __attribute__ ((__deprecated__))
+#endif
+
+#ifndef GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_DEPRECATED_EXPORT
+# define GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_DEPRECATED_EXPORT GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_EXPORT GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_DEPRECATED
+#endif
+
+#ifndef GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_DEPRECATED_NO_EXPORT
+# define GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_DEPRECATED_NO_EXPORT GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_NO_EXPORT GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_DEPRECATED
+#endif
+
+#if 0 /* DEFINE_NO_DEPRECATED */
+# ifndef GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_NO_DEPRECATED
+# define GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_NO_DEPRECATED
+# endif
+#endif
+
+#endif /* GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_EXPORT_H */
diff --git a/src/module/integrated/version_checking_module/CMakeLists.txt b/src/module/integrated/version_checking_module/CMakeLists.txt
index 81b1d881..f122be88 100644
--- a/src/module/integrated/version_checking_module/CMakeLists.txt
+++ b/src/module/integrated/version_checking_module/CMakeLists.txt
@@ -29,6 +29,8 @@ aux_source_directory(. INTEGRATED_MODULE_SOURCE)
# define libgpgfrontend_module
add_library(gpgfrontend_integrated_module_version_checking SHARED ${INTEGRATED_MODULE_SOURCE})
+set(_export_file "${CMAKE_CURRENT_SOURCE_DIR}/GpgFrontendModuleExport.h")
+generate_export_header(gpgfrontend_integrated_module_version_checking EXPORT_FILE_NAME "${_export_file}")
if (XCODE_BUILD)
set_target_properties(gpgfrontend_integrated_module_version_checking
diff --git a/src/module/integrated/version_checking_module/GpgFrontendModuleExport.h b/src/module/integrated/version_checking_module/GpgFrontendModuleExport.h
new file mode 100644
index 00000000..0ac60b2f
--- /dev/null
+++ b/src/module/integrated/version_checking_module/GpgFrontendModuleExport.h
@@ -0,0 +1,42 @@
+
+#ifndef GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_EXPORT_H
+#define GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_EXPORT_H
+
+#ifdef GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_STATIC_DEFINE
+# define GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_EXPORT
+# define GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_NO_EXPORT
+#else
+# ifndef GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_EXPORT
+# ifdef gpgfrontend_integrated_module_version_checking_EXPORTS
+ /* We are building this library */
+# define GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_EXPORT __attribute__((visibility("default")))
+# else
+ /* We are using this library */
+# define GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_EXPORT __attribute__((visibility("default")))
+# endif
+# endif
+
+# ifndef GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_NO_EXPORT
+# define GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_NO_EXPORT __attribute__((visibility("hidden")))
+# endif
+#endif
+
+#ifndef GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_DEPRECATED
+# define GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_DEPRECATED __attribute__ ((__deprecated__))
+#endif
+
+#ifndef GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_DEPRECATED_EXPORT
+# define GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_DEPRECATED_EXPORT GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_EXPORT GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_DEPRECATED
+#endif
+
+#ifndef GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_DEPRECATED_NO_EXPORT
+# define GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_DEPRECATED_NO_EXPORT GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_NO_EXPORT GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_DEPRECATED
+#endif
+
+#if 0 /* DEFINE_NO_DEPRECATED */
+# ifndef GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_NO_DEPRECATED
+# define GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_NO_DEPRECATED
+# endif
+#endif
+
+#endif /* GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_EXPORT_H */
diff --git a/src/module/integrated/version_checking_module/SoftwareVersion.cpp b/src/module/integrated/version_checking_module/SoftwareVersion.cpp
index e4077d65..7d41b1c5 100644
--- a/src/module/integrated/version_checking_module/SoftwareVersion.cpp
+++ b/src/module/integrated/version_checking_module/SoftwareVersion.cpp
@@ -29,6 +29,7 @@
#include "SoftwareVersion.h"
#include "core/utils/CommonUtils.h"
+#include "module/sdk/Log.h"
namespace GpgFrontend::Module::Integrated::VersionCheckingModule {
diff --git a/src/module/integrated/version_checking_module/VersionCheckingModule.h b/src/module/integrated/version_checking_module/VersionCheckingModule.h
index 0a215588..0730feed 100644
--- a/src/module/integrated/version_checking_module/VersionCheckingModule.h
+++ b/src/module/integrated/version_checking_module/VersionCheckingModule.h
@@ -28,13 +28,14 @@
#pragma once
-#include <module/sdk/GpgFrontendModuleSDK.h>
-
+#include "GpgFrontendModuleExport.h"
#include "SoftwareVersion.h"
+#include "core/module/Module.h"
namespace GpgFrontend::Module::Integrated::VersionCheckingModule {
-class GPGFRONTEND_MODULE_SDK_EXPORT VersionCheckingModule : public Module {
+class GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_EXPORT
+ VersionCheckingModule : public Module {
Q_OBJECT
public:
VersionCheckingModule();