Compare commits
No commits in common. "469eb2b4e00035939ab2621223321eef9dd0252e" and "46b7ecec8f5787d3a4b14a2fd2ec4f324a041345" have entirely different histories.
469eb2b4e0
...
46b7ecec8f
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "third_party/spdlog"]
|
||||||
|
path = third_party/spdlog
|
||||||
|
url = https://github.com/gabime/spdlog.git
|
@ -1,11 +1,11 @@
|
|||||||
SET (CMAKE_C_FLAGS "-Wall -std=c11")
|
SET (CMAKE_C_FLAGS "-Wall -std=c11")
|
||||||
SET (CMAKE_C_FLAGS_DEBUG "-g")
|
SET (CMAKE_C_FLAGS_DEBUG "-g -fsanitize=address -fsanitize-recover=address")
|
||||||
SET (CMAKE_C_FLAGS_MINSIZERE "-Os -DNDEBUG")
|
SET (CMAKE_C_FLAGS_MINSIZERE "-Os -DNDEBUG")
|
||||||
SET (CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
|
SET (CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
|
||||||
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
|
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
|
||||||
|
|
||||||
SET (CMAKE_CXX_FLAGS "-Wall -std=c++17")
|
SET (CMAKE_CXX_FLAGS "-Wall -std=c++17")
|
||||||
SET (CMAKE_CXX_FLAGS_DEBUG "-g")
|
SET (CMAKE_CXX_FLAGS_DEBUG "-g -fsanitize=address -fsanitize-recover=address")
|
||||||
SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
|
SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
|
||||||
SET (CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
|
SET (CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
|
||||||
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
|
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
|
@ -97,8 +97,11 @@ inline auto QMapToGFModuleMetaDataList(const QMap<QString, QString>& map)
|
|||||||
QByteArray const key = it.key().toUtf8();
|
QByteArray const key = it.key().toUtf8();
|
||||||
QByteArray const value = it.value().toUtf8();
|
QByteArray const value = it.value().toUtf8();
|
||||||
|
|
||||||
new_node->key = DUP(key);
|
new_node->key = new char[key.size() + 1];
|
||||||
new_node->value = DUP(value);
|
std::strcpy(const_cast<char*>(new_node->key), key.constData());
|
||||||
|
|
||||||
|
new_node->value = new char[value.size() + 1];
|
||||||
|
std::strcpy(const_cast<char*>(new_node->value), value.constData());
|
||||||
|
|
||||||
new_node->next = nullptr;
|
new_node->next = nullptr;
|
||||||
|
|
||||||
@ -136,8 +139,8 @@ auto SecureCreateSharedObject(Args&&... args) -> std::shared_ptr<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto CharArrayToQStringList(char** pl_components,
|
inline auto CharArrayToQStringList(char** pl_components, int size)
|
||||||
int size) -> QStringList {
|
-> QStringList {
|
||||||
QStringList list;
|
QStringList list;
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
list.append(QString::fromUtf8(pl_components[i]));
|
list.append(QString::fromUtf8(pl_components[i]));
|
||||||
|
71
include/LogFormatter.h
Normal file
71
include/LogFormatter.h
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2021 Saturneric <eric@bktus.com>
|
||||||
|
*
|
||||||
|
* This file is part of GpgFrontend.
|
||||||
|
*
|
||||||
|
* GpgFrontend is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* GpgFrontend is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* The initial version of the source code is inherited from
|
||||||
|
* the gpg4usb project, which is under GPL-3.0-or-later.
|
||||||
|
*
|
||||||
|
* All the source code of GpgFrontend was modified and released by
|
||||||
|
* Saturneric <eric@bktus.com> starting on May 12, 2021.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// spdlog library configuration
|
||||||
|
#undef SPDLOG_ACTIVE_LEVEL
|
||||||
|
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct fmt::formatter<QString> {
|
||||||
|
// 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 QString& qstr, FormatContext& ctx) const
|
||||||
|
-> decltype(ctx.out()) {
|
||||||
|
// Convert QString to UTF-8 QString (to handle Unicode characters
|
||||||
|
// correctly)
|
||||||
|
QByteArray const 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());
|
||||||
|
}
|
||||||
|
};
|
@ -30,6 +30,9 @@ aux_source_directory(. INTEGRATED_MODULE_SOURCE)
|
|||||||
# define libgpgfrontend_module
|
# define libgpgfrontend_module
|
||||||
add_library(mod_gpg_info SHARED ${INTEGRATED_MODULE_SOURCE})
|
add_library(mod_gpg_info SHARED ${INTEGRATED_MODULE_SOURCE})
|
||||||
|
|
||||||
|
target_include_directories(mod_gpg_info PRIVATE
|
||||||
|
${CMAKE_SOURCE_DIR}/third_party/spdlog/include)
|
||||||
|
|
||||||
# install dir
|
# install dir
|
||||||
install(TARGETS mod_gpg_info
|
install(TARGETS mod_gpg_info
|
||||||
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/modules")
|
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/modules")
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <GFSDKBasic.h>
|
#include <GFSDKBasic.h>
|
||||||
#include <GFSDKBuildInfo.h>
|
#include <GFSDKBuildInfo.h>
|
||||||
#include <GFSDKLog.h>
|
#include <GFSDKLog.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
// qt
|
// qt
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
@ -69,26 +70,44 @@ using Context = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
auto GFGetModuleGFSDKVersion() -> const char * {
|
auto GFGetModuleGFSDKVersion() -> const char * {
|
||||||
return DUP(GF_SDK_VERSION_STR);
|
return GFModuleStrDup(GF_SDK_VERSION_STR);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GFGetModuleQtEnvVersion() -> const char * { return DUP(QT_VERSION_STR); }
|
auto GFGetModuleQtEnvVersion() -> const char * {
|
||||||
|
return GFModuleStrDup(QT_VERSION_STR);
|
||||||
|
}
|
||||||
|
|
||||||
auto GFGetModuleID() -> const char * {
|
auto GFGetModuleID() -> const char * {
|
||||||
return DUP("com.bktus.gpgfrontend.module.gnupg_info_gathering");
|
return GFModuleStrDup("com.bktus.gpgfrontend.module.gnupg_info_gathering");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GFGetModuleVersion() -> const char * { return DUP("1.0.0"); }
|
auto GFGetModuleVersion() -> const char * { return GFModuleStrDup("1.0.0"); }
|
||||||
|
|
||||||
auto GFGetModuleMetaData() -> GFModuleMetaData * {
|
auto GFGetModuleMetaData() -> GFModuleMetaData * {
|
||||||
return QMapToGFModuleMetaDataList(
|
auto *p_meta = static_cast<GFModuleMetaData *>(
|
||||||
{{"Name", "GatherGnupgInfo"},
|
GFAllocateMemory(sizeof(GFModuleMetaData)));
|
||||||
{"Description", "Try gathering gnupg informations."},
|
auto *h_meta = p_meta;
|
||||||
{"Author", "Saturneric"}});
|
|
||||||
|
p_meta->key = "Name";
|
||||||
|
p_meta->value = "GatherGnupgInfo";
|
||||||
|
p_meta->next = static_cast<GFModuleMetaData *>(
|
||||||
|
GFAllocateMemory(sizeof(GFModuleMetaData)));
|
||||||
|
p_meta = p_meta->next;
|
||||||
|
|
||||||
|
p_meta->key = "Description";
|
||||||
|
p_meta->value = "Try gathering gnupg informations";
|
||||||
|
p_meta->next = static_cast<GFModuleMetaData *>(
|
||||||
|
GFAllocateMemory(sizeof(GFModuleMetaData)));
|
||||||
|
p_meta = p_meta->next;
|
||||||
|
|
||||||
|
p_meta->key = "Author";
|
||||||
|
p_meta->value = "Saturneric";
|
||||||
|
p_meta->next = nullptr;
|
||||||
|
return h_meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GFRegisterModule() -> int {
|
auto GFRegisterModule() -> int {
|
||||||
MLogDebug("gnupg info gathering module registering");
|
GFModuleLogDebug("gnupg info gathering module registering");
|
||||||
|
|
||||||
GFUIMountEntry(DUP("AboutDialogTabs"),
|
GFUIMountEntry(DUP("AboutDialogTabs"),
|
||||||
QMapToMetaDataArray({{"TabTitle", GTrC::tr("GnuPG")}}), 1,
|
QMapToMetaDataArray({{"TabTitle", GTrC::tr("GnuPG")}}), 1,
|
||||||
@ -98,8 +117,9 @@ auto GFRegisterModule() -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto GFActiveModule() -> int {
|
auto GFActiveModule() -> int {
|
||||||
MLogDebug("gnupg info gathering module activating");
|
GFModuleLogDebug("gnupg info gathering module activating");
|
||||||
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_GATHERING_GNUPG_INFO"));
|
GFModuleListenEvent(GFGetModuleID(),
|
||||||
|
GFModuleStrDup("REQUEST_GATHERING_GNUPG_INFO"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,39 +131,40 @@ auto GFExecuteModule(GFModuleEvent *event) -> int {
|
|||||||
|
|
||||||
char **event_argv =
|
char **event_argv =
|
||||||
static_cast<char **>(GFAllocateMemory(sizeof(char **) * 1));
|
static_cast<char **>(GFAllocateMemory(sizeof(char **) * 1));
|
||||||
event_argv[0] = DUP("0");
|
event_argv[0] = GFModuleStrDup("0");
|
||||||
|
|
||||||
GFModuleTriggerModuleEventCallback(event, GFGetModuleID(), 1, event_argv);
|
GFModuleTriggerModuleEventCallback(event, GFGetModuleID(), 1, event_argv);
|
||||||
|
|
||||||
MLogDebug("gnupg external info gathering done");
|
GFModuleLogDebug("gnupg external info gathering done");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GFDeactiveModule() -> int { return 0; }
|
auto GFDeactiveModule() -> int { return 0; }
|
||||||
|
|
||||||
auto GFUnregisterModule() -> int {
|
auto GFUnregisterModule() -> int {
|
||||||
MLogDebug("gnupg info gathering module unregistering");
|
GFModuleLogDebug("gnupg info gathering module unregistering");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto StartGatheringGnuPGInfo() -> int {
|
auto StartGatheringGnuPGInfo() -> int {
|
||||||
MLogDebug("start to load extra info at module gnupginfogathering...");
|
GFModuleLogDebug("start to load extra info at module gnupginfogathering...");
|
||||||
|
|
||||||
const auto *const gpgme_version = GFModuleRetrieveRTValueOrDefault(
|
const auto *const gpgme_version = GFModuleRetrieveRTValueOrDefault(
|
||||||
DUP("core"), DUP("gpgme.version"), DUP("0.0.0"));
|
GFModuleStrDup("core"), GFModuleStrDup("gpgme.version"),
|
||||||
|
GFModuleStrDup("0.0.0"));
|
||||||
MLogDebug(QString("got gpgme version from rt: %1").arg(gpgme_version));
|
MLogDebug(QString("got gpgme version from rt: %1").arg(gpgme_version));
|
||||||
|
|
||||||
const auto *const gpgconf_path = GFModuleRetrieveRTValueOrDefault(
|
const auto *const gpgconf_path = GFModuleRetrieveRTValueOrDefault(
|
||||||
DUP("core"), DUP("gpgme.ctx.gpgconf_path"), DUP(""));
|
GFModuleStrDup("core"), GFModuleStrDup("gpgme.ctx.gpgconf_path"),
|
||||||
|
GFModuleStrDup(""));
|
||||||
MLogDebug(QString("got gpgconf path from rt: %1").arg(gpgconf_path));
|
MLogDebug(QString("got gpgconf path from rt: %1").arg(gpgconf_path));
|
||||||
|
|
||||||
auto context = Context{gpgme_version, gpgconf_path};
|
auto context = Context{gpgme_version, gpgconf_path};
|
||||||
|
|
||||||
// get all components
|
// get all components
|
||||||
const char *argv[] = {DUP("--list-components")};
|
const char *argv[] = {GFModuleStrDup("--list-components")};
|
||||||
GFExecuteCommandSync(gpgconf_path, 1, argv, GetGpgComponentInfos, &context);
|
GFExecuteCommandSync(gpgconf_path, 1, argv, GetGpgComponentInfos, &context);
|
||||||
MLogDebug("load gnupg component info done.");
|
GFModuleLogDebug("load gnupg component info done.");
|
||||||
|
|
||||||
#ifdef QT5_BUILD
|
#ifdef QT5_BUILD
|
||||||
QVector<GFCommandExecuteContext> exec_contexts;
|
QVector<GFCommandExecuteContext> exec_contexts;
|
||||||
@ -153,14 +174,14 @@ auto StartGatheringGnuPGInfo() -> int {
|
|||||||
|
|
||||||
const char **argv_0 =
|
const char **argv_0 =
|
||||||
static_cast<const char **>(GFAllocateMemory(sizeof(const char *)));
|
static_cast<const char **>(GFAllocateMemory(sizeof(const char *)));
|
||||||
argv_0[0] = DUP("--list-dirs");
|
argv_0[0] = GFModuleStrDup("--list-dirs");
|
||||||
|
|
||||||
exec_contexts.push_back(
|
exec_contexts.push_back(
|
||||||
{gpgconf_path, 1, argv_0, GetGpgDirectoryInfos, nullptr});
|
{gpgconf_path, 1, argv_0, GetGpgDirectoryInfos, nullptr});
|
||||||
|
|
||||||
char **components_c_array;
|
char **components_c_array;
|
||||||
int ret = GFModuleListRTChildKeys(GFGetModuleID(), DUP("gnupg.components"),
|
int ret = GFModuleListRTChildKeys(
|
||||||
&components_c_array);
|
GFGetModuleID(), GFModuleStrDup("gnupg.components"), &components_c_array);
|
||||||
if (components_c_array == nullptr || ret == 0) return -1;
|
if (components_c_array == nullptr || ret == 0) return -1;
|
||||||
|
|
||||||
QStringList components;
|
QStringList components;
|
||||||
@ -170,7 +191,8 @@ auto StartGatheringGnuPGInfo() -> int {
|
|||||||
for (const auto &component : components) {
|
for (const auto &component : components) {
|
||||||
const auto *component_info_json = GFModuleRetrieveRTValueOrDefault(
|
const auto *component_info_json = GFModuleRetrieveRTValueOrDefault(
|
||||||
GFGetModuleID(),
|
GFGetModuleID(),
|
||||||
DUP(QString("gnupg.components.%1").arg(component).toUtf8()), nullptr);
|
GFModuleStrDup(QString("gnupg.components.%1").arg(component).toUtf8()),
|
||||||
|
nullptr);
|
||||||
|
|
||||||
if (component_info_json == nullptr) continue;
|
if (component_info_json == nullptr) continue;
|
||||||
|
|
||||||
@ -191,15 +213,16 @@ auto StartGatheringGnuPGInfo() -> int {
|
|||||||
|
|
||||||
const char **argv_0 =
|
const char **argv_0 =
|
||||||
static_cast<const char **>(GFAllocateMemory(sizeof(const char *) * 2));
|
static_cast<const char **>(GFAllocateMemory(sizeof(const char *) * 2));
|
||||||
argv_0[0] = DUP("--list-options"),
|
argv_0[0] = GFModuleStrDup("--list-options"),
|
||||||
argv_0[1] = DUP(component_info.name.toUtf8());
|
argv_0[1] = GFModuleStrDup(component_info.name.toUtf8());
|
||||||
exec_contexts.push_back(
|
exec_contexts.push_back(
|
||||||
{gpgconf_path, 2, argv_0, GetGpgOptionInfos, context});
|
{gpgconf_path, 2, argv_0, GetGpgOptionInfos, context});
|
||||||
}
|
}
|
||||||
|
|
||||||
GFExecuteCommandBatchSync(static_cast<int32_t>(exec_contexts.size()),
|
GFExecuteCommandBatchSync(static_cast<int32_t>(exec_contexts.size()),
|
||||||
exec_contexts.constData());
|
exec_contexts.constData());
|
||||||
GFModuleUpsertRTValueBool(GFGetModuleID(), DUP("gnupg.gathering_done"), 1);
|
GFModuleUpsertRTValueBool(GFGetModuleID(),
|
||||||
|
GFModuleStrDup("gnupg.gathering_done"), 1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -287,11 +310,11 @@ void GetGpgComponentInfos(void *data, int exit_code, const char *out,
|
|||||||
auto const jsonlized_gpgme_component_info = c_i_gpgme.Json();
|
auto const jsonlized_gpgme_component_info = c_i_gpgme.Json();
|
||||||
auto const jsonlized_gpgconf_component_info = c_i_gpgconf.Json();
|
auto const jsonlized_gpgconf_component_info = c_i_gpgconf.Json();
|
||||||
GFModuleUpsertRTValue(
|
GFModuleUpsertRTValue(
|
||||||
GFGetModuleID(), DUP("gnupg.components.gpgme"),
|
GFGetModuleID(), GFModuleStrDup("gnupg.components.gpgme"),
|
||||||
DUP(QJsonDocument(jsonlized_gpgme_component_info).toJson()));
|
GFModuleStrDup(QJsonDocument(jsonlized_gpgme_component_info).toJson()));
|
||||||
GFModuleUpsertRTValue(
|
GFModuleUpsertRTValue(
|
||||||
GFGetModuleID(), DUP("gnupg.components.gpgconf"),
|
GFGetModuleID(), GFModuleStrDup("gnupg.components.gpgconf"),
|
||||||
DUP(QJsonDocument(jsonlized_gpgconf_component_info).toJson()));
|
GFModuleStrDup(QJsonDocument(jsonlized_gpgconf_component_info).toJson()));
|
||||||
|
|
||||||
auto line_split_list = p_out.split("\n");
|
auto line_split_list = p_out.split("\n");
|
||||||
|
|
||||||
@ -323,19 +346,23 @@ void GetGpgComponentInfos(void *data, int exit_code, const char *out,
|
|||||||
|
|
||||||
if (component_name == "gpg") {
|
if (component_name == "gpg") {
|
||||||
version = GFModuleRetrieveRTValueOrDefault(
|
version = GFModuleRetrieveRTValueOrDefault(
|
||||||
DUP("core"), DUP("gpgme.ctx.gnupg_version"), DUP("2.0.0"));
|
GFModuleStrDup("core"), GFModuleStrDup("gpgme.ctx.gnupg_version"),
|
||||||
|
GFModuleStrDup("2.0.0"));
|
||||||
}
|
}
|
||||||
if (component_name == "gpg-agent") {
|
if (component_name == "gpg-agent") {
|
||||||
GFModuleUpsertRTValue(GFGetModuleID(), DUP("gnupg.gpg_agent_path"),
|
GFModuleUpsertRTValue(GFGetModuleID(),
|
||||||
DUP(QString(component_path).toUtf8()));
|
GFModuleStrDup("gnupg.gpg_agent_path"),
|
||||||
|
GFModuleStrDup(QString(component_path).toUtf8()));
|
||||||
}
|
}
|
||||||
if (component_name == "dirmngr") {
|
if (component_name == "dirmngr") {
|
||||||
GFModuleUpsertRTValue(GFGetModuleID(), DUP("gnupg.dirmngr_path"),
|
GFModuleUpsertRTValue(GFGetModuleID(),
|
||||||
DUP(QString(component_path).toUtf8()));
|
GFModuleStrDup("gnupg.dirmngr_path"),
|
||||||
|
GFModuleStrDup(QString(component_path).toUtf8()));
|
||||||
}
|
}
|
||||||
if (component_name == "keyboxd") {
|
if (component_name == "keyboxd") {
|
||||||
GFModuleUpsertRTValue(GFGetModuleID(), DUP("gnupg.keyboxd_path"),
|
GFModuleUpsertRTValue(GFGetModuleID(),
|
||||||
DUP(QString(component_path).toUtf8()));
|
GFModuleStrDup("gnupg.keyboxd_path"),
|
||||||
|
GFModuleStrDup(QString(component_path).toUtf8()));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -351,13 +378,14 @@ void GetGpgComponentInfos(void *data, int exit_code, const char *out,
|
|||||||
auto const jsonlized_component_info = c_i.Json();
|
auto const jsonlized_component_info = c_i.Json();
|
||||||
GFModuleUpsertRTValue(
|
GFModuleUpsertRTValue(
|
||||||
GFGetModuleID(),
|
GFGetModuleID(),
|
||||||
DUP(QString("gnupg.components.%1").arg(component_name).toUtf8()),
|
GFModuleStrDup(
|
||||||
DUP(QJsonDocument(jsonlized_component_info).toJson()));
|
QString("gnupg.components.%1").arg(component_name).toUtf8()),
|
||||||
|
GFModuleStrDup(QJsonDocument(jsonlized_component_info).toJson()));
|
||||||
|
|
||||||
component_infos.push_back(c_i);
|
component_infos.push_back(c_i);
|
||||||
}
|
}
|
||||||
|
|
||||||
MLogDebug("load gnupg component info actually done.");
|
GFModuleLogDebug("load gnupg component info actually done.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,14 +416,15 @@ void GetGpgDirectoryInfos(void *, int exit_code, const char *out,
|
|||||||
|
|
||||||
// record gnupg home path
|
// record gnupg home path
|
||||||
if (configuration_name == "homedir") {
|
if (configuration_name == "homedir") {
|
||||||
GFModuleUpsertRTValue(GFGetModuleID(), DUP("gnupg.home_path"),
|
GFModuleUpsertRTValue(GFGetModuleID(), GFModuleStrDup("gnupg.home_path"),
|
||||||
DUP(configuration_value.toUtf8()));
|
GFModuleStrDup(configuration_value.toUtf8()));
|
||||||
}
|
}
|
||||||
|
|
||||||
GFModuleUpsertRTValue(
|
GFModuleUpsertRTValue(
|
||||||
GFGetModuleID(),
|
GFGetModuleID(),
|
||||||
DUP(QString("gnupg.dirs.%1").arg(configuration_name).toUtf8()),
|
GFModuleStrDup(
|
||||||
DUP(configuration_value.toUtf8()));
|
QString("gnupg.dirs.%1").arg(configuration_name).toUtf8()),
|
||||||
|
GFModuleStrDup(configuration_value.toUtf8()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,12 +485,13 @@ void GetGpgOptionInfos(void *data, int exit_code, const char *out,
|
|||||||
info.value = option_value;
|
info.value = option_value;
|
||||||
|
|
||||||
auto const jsonlized_option_info = info.Json();
|
auto const jsonlized_option_info = info.Json();
|
||||||
GFModuleUpsertRTValue(GFGetModuleID(),
|
GFModuleUpsertRTValue(
|
||||||
DUP(QString("gnupg.components.%1.options.%2")
|
GFGetModuleID(),
|
||||||
|
GFModuleStrDup(QString("gnupg.components.%1.options.%2")
|
||||||
.arg(component_name)
|
.arg(component_name)
|
||||||
.arg(option_name)
|
.arg(option_name)
|
||||||
.toUtf8()),
|
.toUtf8()),
|
||||||
DUP(QJsonDocument(jsonlized_option_info).toJson()));
|
GFModuleStrDup(QJsonDocument(jsonlized_option_info).toJson()));
|
||||||
options_infos.push_back(info);
|
options_infos.push_back(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
68
src/m_gpg_info/QtLoggerFmt.h
Normal file
68
src/m_gpg_info/QtLoggerFmt.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2021 Saturneric <eric@bktus.com>
|
||||||
|
*
|
||||||
|
* This file is part of GpgFrontend.
|
||||||
|
*
|
||||||
|
* GpgFrontend is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* GpgFrontend is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* The initial version of the source code is inherited from
|
||||||
|
* the gpg4usb project, which is under GPL-3.0-or-later.
|
||||||
|
*
|
||||||
|
* All the source code of GpgFrontend was modified and released by
|
||||||
|
* Saturneric <eric@bktus.com> starting on May 12, 2021.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct fmt::formatter<QString> {
|
||||||
|
// 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 QString& qstr, FormatContext& ctx) const
|
||||||
|
-> decltype(ctx.out()) {
|
||||||
|
// Convert QString to UTF-8 QString (to handle Unicode characters
|
||||||
|
// correctly)
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
};
|
@ -30,6 +30,9 @@ aux_source_directory(. MODULE_SOURCE_FILES)
|
|||||||
# define libgpgfrontend_module
|
# define libgpgfrontend_module
|
||||||
add_library(mod_ver_check SHARED ${MODULE_SOURCE_FILES})
|
add_library(mod_ver_check SHARED ${MODULE_SOURCE_FILES})
|
||||||
|
|
||||||
|
target_include_directories(mod_ver_check PRIVATE
|
||||||
|
${CMAKE_SOURCE_DIR}/third_party/spdlog/include)
|
||||||
|
|
||||||
# install dir
|
# install dir
|
||||||
install(TARGETS mod_ver_check
|
install(TARGETS mod_ver_check
|
||||||
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/modules")
|
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/modules")
|
||||||
|
68
src/m_ver_check/QtLoggerFmt.h
Normal file
68
src/m_ver_check/QtLoggerFmt.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2021 Saturneric <eric@bktus.com>
|
||||||
|
*
|
||||||
|
* This file is part of GpgFrontend.
|
||||||
|
*
|
||||||
|
* GpgFrontend is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* GpgFrontend is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* The initial version of the source code is inherited from
|
||||||
|
* the gpg4usb project, which is under GPL-3.0-or-later.
|
||||||
|
*
|
||||||
|
* All the source code of GpgFrontend was modified and released by
|
||||||
|
* Saturneric <eric@bktus.com> starting on May 12, 2021.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct fmt::formatter<QString> {
|
||||||
|
// 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 QString& qstr, FormatContext& ctx) const
|
||||||
|
-> decltype(ctx.out()) {
|
||||||
|
// Convert QString to UTF-8 QString (to handle Unicode characters
|
||||||
|
// correctly)
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
};
|
@ -31,23 +31,59 @@
|
|||||||
#include <GFSDKBasic.h>
|
#include <GFSDKBasic.h>
|
||||||
#include <GFSDKExtra.h>
|
#include <GFSDKExtra.h>
|
||||||
#include <GFSDKLog.h>
|
#include <GFSDKLog.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "GFModuleCommonUtils.hpp"
|
template <>
|
||||||
|
struct fmt::formatter<QString> {
|
||||||
|
// 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 QString& qstr, FormatContext& ctx) const
|
||||||
|
-> decltype(ctx.out()) {
|
||||||
|
// Convert QString to UTF-8 QString (to handle Unicode characters
|
||||||
|
// correctly)
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
auto SoftwareVersion::NeedUpgrade() const -> bool {
|
auto SoftwareVersion::NeedUpgrade() const -> bool {
|
||||||
MLogDebug(QString("compare version current: %1 latest %2, result: %3")
|
GFModuleLogDebug(
|
||||||
.arg(current_version)
|
fmt::format(
|
||||||
.arg(latest_version)
|
"compair version current {} latest {}, result {}", current_version,
|
||||||
.arg(GFCompareSoftwareVersion(
|
latest_version,
|
||||||
GFModuleStrDup(current_version.toUtf8()),
|
GFCompareSoftwareVersion(GFModuleStrDup(current_version.toUtf8()),
|
||||||
GFModuleStrDup(latest_version.toUtf8()))));
|
GFModuleStrDup(latest_version.toUtf8())))
|
||||||
|
.c_str());
|
||||||
|
|
||||||
MLogDebug(QString("load done: %1, pre-release: %2, draft: %3")
|
GFModuleLogDebug(fmt::format("load done: {}, pre-release: {}, draft: {}",
|
||||||
.arg(static_cast<int>(loading_done))
|
loading_done,
|
||||||
.arg(static_cast<int>(latest_prerelease_version_from_remote))
|
latest_prerelease_version_from_remote,
|
||||||
.arg(static_cast<int>(latest_draft_from_remote)));
|
latest_draft_from_remote)
|
||||||
|
.c_str());
|
||||||
return loading_done && !latest_prerelease_version_from_remote &&
|
return loading_done && !latest_prerelease_version_from_remote &&
|
||||||
!latest_draft_from_remote &&
|
!latest_draft_from_remote &&
|
||||||
GFCompareSoftwareVersion(GFModuleStrDup(current_version.toUtf8()),
|
GFCompareSoftwareVersion(GFModuleStrDup(current_version.toUtf8()),
|
||||||
|
@ -31,12 +31,14 @@
|
|||||||
#include <GFSDKBasic.h>
|
#include <GFSDKBasic.h>
|
||||||
#include <GFSDKExtra.h>
|
#include <GFSDKExtra.h>
|
||||||
#include <GFSDKLog.h>
|
#include <GFSDKLog.h>
|
||||||
#include <qobject.h>
|
|
||||||
|
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QtNetwork>
|
#include <QtNetwork>
|
||||||
|
|
||||||
#include "GFModuleCommonUtils.hpp"
|
// spdlog
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
#include "LogFormatter.h"
|
||||||
#include "SoftwareVersion.h"
|
#include "SoftwareVersion.h"
|
||||||
#include "VersionCheckingModule.h"
|
#include "VersionCheckingModule.h"
|
||||||
|
|
||||||
@ -48,6 +50,8 @@ VersionCheckTask::VersionCheckTask()
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto VersionCheckTask::Run() -> int {
|
auto VersionCheckTask::Run() -> int {
|
||||||
|
GFModuleLogDebug(
|
||||||
|
fmt::format("current project version: {}", current_version_).c_str());
|
||||||
QString latest_version_url =
|
QString latest_version_url =
|
||||||
"https://api.github.com/repos/saturneric/gpgfrontend/releases/latest";
|
"https://api.github.com/repos/saturneric/gpgfrontend/releases/latest";
|
||||||
|
|
||||||
@ -66,8 +70,9 @@ void VersionCheckTask::slot_parse_latest_version_info() {
|
|||||||
version_.latest_version = current_version_;
|
version_.latest_version = current_version_;
|
||||||
version_.loading_done = false;
|
version_.loading_done = false;
|
||||||
} else if (latest_reply_->error() != QNetworkReply::NoError) {
|
} else if (latest_reply_->error() != QNetworkReply::NoError) {
|
||||||
MLogError(QString("latest version request error: %1")
|
GFModuleLogError(fmt::format("latest version request error: ",
|
||||||
.arg(latest_reply_->errorString()));
|
latest_reply_->errorString())
|
||||||
|
.c_str());
|
||||||
version_.latest_version = current_version_;
|
version_.latest_version = current_version_;
|
||||||
} else {
|
} else {
|
||||||
latest_reply_bytes_ = latest_reply_->readAll();
|
latest_reply_bytes_ = latest_reply_->readAll();
|
||||||
@ -80,10 +85,15 @@ void VersionCheckTask::slot_parse_latest_version_info() {
|
|||||||
auto version_match = re.match(latest_version);
|
auto version_match = re.match(latest_version);
|
||||||
if (version_match.hasMatch()) {
|
if (version_match.hasMatch()) {
|
||||||
latest_version = version_match.captured(0);
|
latest_version = version_match.captured(0);
|
||||||
|
GFModuleLogInfo(fmt::format("latest released version from github: {}",
|
||||||
|
latest_version)
|
||||||
|
.c_str());
|
||||||
} else {
|
} else {
|
||||||
latest_version = current_version_;
|
latest_version = current_version_;
|
||||||
MLogWarn(QString("latest version unknown, set to current version: %1")
|
GFModuleLogWarn(
|
||||||
.arg(current_version_));
|
fmt::format("latest version unknown, set to current version: {}",
|
||||||
|
current_version_)
|
||||||
|
.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool prerelease = latest_reply_json["prerelease"].toBool();
|
bool prerelease = latest_reply_json["prerelease"].toBool();
|
||||||
@ -96,8 +106,9 @@ void VersionCheckTask::slot_parse_latest_version_info() {
|
|||||||
version_.publish_date = publish_date;
|
version_.publish_date = publish_date;
|
||||||
version_.release_note = release_note;
|
version_.release_note = release_note;
|
||||||
} else {
|
} else {
|
||||||
MLogWarn(QString("cannot parse data got from github: %1")
|
GFModuleLogWarn(fmt::format("cannot parse data got from github: {}",
|
||||||
.arg(latest_reply_bytes_));
|
latest_reply_bytes_)
|
||||||
|
.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,6 +120,9 @@ void VersionCheckTask::slot_parse_latest_version_info() {
|
|||||||
QString current_version_url =
|
QString current_version_url =
|
||||||
"https://api.github.com/repos/saturneric/gpgfrontend/releases/tags/" +
|
"https://api.github.com/repos/saturneric/gpgfrontend/releases/tags/" +
|
||||||
current_version_;
|
current_version_;
|
||||||
|
GFModuleLogDebug(
|
||||||
|
fmt::format("current version info query url: {}", current_version_url)
|
||||||
|
.c_str());
|
||||||
|
|
||||||
QNetworkRequest current_request(current_version_url);
|
QNetworkRequest current_request(current_version_url);
|
||||||
current_request.setHeader(QNetworkRequest::UserAgentHeader,
|
current_request.setHeader(QNetworkRequest::UserAgentHeader,
|
||||||
@ -129,8 +143,9 @@ void VersionCheckTask::slot_parse_current_version_info() {
|
|||||||
version_.loading_done = false;
|
version_.loading_done = false;
|
||||||
|
|
||||||
} else if (current_reply_->error() != QNetworkReply::NoError) {
|
} else if (current_reply_->error() != QNetworkReply::NoError) {
|
||||||
MLogError(QString("current version request network error: {}")
|
GFModuleLogError(fmt::format("current version request network error: {}",
|
||||||
.arg(current_reply_->errorString()));
|
current_reply_->errorString())
|
||||||
|
.c_str());
|
||||||
|
|
||||||
// loading done
|
// loading done
|
||||||
version_.loading_done = true;
|
version_.loading_done = true;
|
||||||
@ -148,11 +163,16 @@ void VersionCheckTask::slot_parse_current_version_info() {
|
|||||||
// loading done
|
// loading done
|
||||||
version_.loading_done = true;
|
version_.loading_done = true;
|
||||||
} else {
|
} else {
|
||||||
MLogWarn(QString("cannot parse data got from github: %1")
|
GFModuleLogWarn(fmt::format("cannot parse data got from github: {}",
|
||||||
.arg(current_reply_bytes_));
|
current_reply_bytes_)
|
||||||
|
.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GFModuleLogDebug(fmt::format("current version parse done: {}",
|
||||||
|
version_.current_version_publish_in_remote)
|
||||||
|
.c_str());
|
||||||
|
|
||||||
if (current_reply_ != nullptr) current_reply_->deleteLater();
|
if (current_reply_ != nullptr) current_reply_->deleteLater();
|
||||||
|
|
||||||
slot_fill_grt_with_version_info(version_);
|
slot_fill_grt_with_version_info(version_);
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include <GFSDKExtra.h>
|
#include <GFSDKExtra.h>
|
||||||
#include <GFSDKLog.h>
|
#include <GFSDKLog.h>
|
||||||
#include <GFSDKUI.h>
|
#include <GFSDKUI.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QtNetwork>
|
#include <QtNetwork>
|
||||||
|
2
third_party/CMakeLists.txt
vendored
2
third_party/CMakeLists.txt
vendored
@ -22,3 +22,5 @@
|
|||||||
# Saturneric <eric@bktus.com> starting on May 12, 2021.
|
# Saturneric <eric@bktus.com> starting on May 12, 2021.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
add_subdirectory(spdlog EXCLUDE_FROM_ALL)
|
1
third_party/spdlog
vendored
Submodule
1
third_party/spdlog
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit d276069a6e916b1e1fd45885b15b72bd8ee000a7
|
Loading…
Reference in New Issue
Block a user