Compare commits

..

No commits in common. "469eb2b4e00035939ab2621223321eef9dd0252e" and "46b7ecec8f5787d3a4b14a2fd2ec4f324a041345" have entirely different histories.

14 changed files with 389 additions and 80 deletions

3
.gitmodules vendored
View File

@ -0,0 +1,3 @@
[submodule "third_party/spdlog"]
path = third_party/spdlog
url = https://github.com/gabime/spdlog.git

View File

@ -1,11 +1,11 @@
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_RELEASE "-O3 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
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_RELEASE "-O3 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")

View File

@ -97,8 +97,11 @@ inline auto QMapToGFModuleMetaDataList(const QMap<QString, QString>& map)
QByteArray const key = it.key().toUtf8();
QByteArray const value = it.value().toUtf8();
new_node->key = DUP(key);
new_node->value = DUP(value);
new_node->key = new char[key.size() + 1];
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;
@ -136,8 +139,8 @@ auto SecureCreateSharedObject(Args&&... args) -> std::shared_ptr<T> {
}
}
inline auto CharArrayToQStringList(char** pl_components,
int size) -> QStringList {
inline auto CharArrayToQStringList(char** pl_components, int size)
-> QStringList {
QStringList list;
for (int i = 0; i < size; ++i) {
list.append(QString::fromUtf8(pl_components[i]));

71
include/LogFormatter.h Normal file
View 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());
}
};

View File

@ -30,6 +30,9 @@ aux_source_directory(. INTEGRATED_MODULE_SOURCE)
# define libgpgfrontend_module
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(TARGETS mod_gpg_info
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/modules")

View File

@ -31,6 +31,7 @@
#include <GFSDKBasic.h>
#include <GFSDKBuildInfo.h>
#include <GFSDKLog.h>
#include <spdlog/spdlog.h>
// qt
#include <QCoreApplication>
@ -69,26 +70,44 @@ using Context = struct {
};
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 * {
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 * {
return QMapToGFModuleMetaDataList(
{{"Name", "GatherGnupgInfo"},
{"Description", "Try gathering gnupg informations."},
{"Author", "Saturneric"}});
auto *p_meta = static_cast<GFModuleMetaData *>(
GFAllocateMemory(sizeof(GFModuleMetaData)));
auto *h_meta = p_meta;
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 {
MLogDebug("gnupg info gathering module registering");
GFModuleLogDebug("gnupg info gathering module registering");
GFUIMountEntry(DUP("AboutDialogTabs"),
QMapToMetaDataArray({{"TabTitle", GTrC::tr("GnuPG")}}), 1,
@ -98,8 +117,9 @@ auto GFRegisterModule() -> int {
}
auto GFActiveModule() -> int {
MLogDebug("gnupg info gathering module activating");
GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_GATHERING_GNUPG_INFO"));
GFModuleLogDebug("gnupg info gathering module activating");
GFModuleListenEvent(GFGetModuleID(),
GFModuleStrDup("REQUEST_GATHERING_GNUPG_INFO"));
return 0;
}
@ -111,39 +131,40 @@ auto GFExecuteModule(GFModuleEvent *event) -> int {
char **event_argv =
static_cast<char **>(GFAllocateMemory(sizeof(char **) * 1));
event_argv[0] = DUP("0");
event_argv[0] = GFModuleStrDup("0");
GFModuleTriggerModuleEventCallback(event, GFGetModuleID(), 1, event_argv);
MLogDebug("gnupg external info gathering done");
GFModuleLogDebug("gnupg external info gathering done");
return 0;
}
auto GFDeactiveModule() -> int { return 0; }
auto GFUnregisterModule() -> int {
MLogDebug("gnupg info gathering module unregistering");
GFModuleLogDebug("gnupg info gathering module unregistering");
return 0;
}
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(
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));
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));
auto context = Context{gpgme_version, gpgconf_path};
// get all components
const char *argv[] = {DUP("--list-components")};
const char *argv[] = {GFModuleStrDup("--list-components")};
GFExecuteCommandSync(gpgconf_path, 1, argv, GetGpgComponentInfos, &context);
MLogDebug("load gnupg component info done.");
GFModuleLogDebug("load gnupg component info done.");
#ifdef QT5_BUILD
QVector<GFCommandExecuteContext> exec_contexts;
@ -153,14 +174,14 @@ auto StartGatheringGnuPGInfo() -> int {
const char **argv_0 =
static_cast<const char **>(GFAllocateMemory(sizeof(const char *)));
argv_0[0] = DUP("--list-dirs");
argv_0[0] = GFModuleStrDup("--list-dirs");
exec_contexts.push_back(
{gpgconf_path, 1, argv_0, GetGpgDirectoryInfos, nullptr});
char **components_c_array;
int ret = GFModuleListRTChildKeys(GFGetModuleID(), DUP("gnupg.components"),
&components_c_array);
int ret = GFModuleListRTChildKeys(
GFGetModuleID(), GFModuleStrDup("gnupg.components"), &components_c_array);
if (components_c_array == nullptr || ret == 0) return -1;
QStringList components;
@ -170,7 +191,8 @@ auto StartGatheringGnuPGInfo() -> int {
for (const auto &component : components) {
const auto *component_info_json = GFModuleRetrieveRTValueOrDefault(
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;
@ -191,15 +213,16 @@ auto StartGatheringGnuPGInfo() -> int {
const char **argv_0 =
static_cast<const char **>(GFAllocateMemory(sizeof(const char *) * 2));
argv_0[0] = DUP("--list-options"),
argv_0[1] = DUP(component_info.name.toUtf8());
argv_0[0] = GFModuleStrDup("--list-options"),
argv_0[1] = GFModuleStrDup(component_info.name.toUtf8());
exec_contexts.push_back(
{gpgconf_path, 2, argv_0, GetGpgOptionInfos, context});
}
GFExecuteCommandBatchSync(static_cast<int32_t>(exec_contexts.size()),
exec_contexts.constData());
GFModuleUpsertRTValueBool(GFGetModuleID(), DUP("gnupg.gathering_done"), 1);
GFModuleUpsertRTValueBool(GFGetModuleID(),
GFModuleStrDup("gnupg.gathering_done"), 1);
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_gpgconf_component_info = c_i_gpgconf.Json();
GFModuleUpsertRTValue(
GFGetModuleID(), DUP("gnupg.components.gpgme"),
DUP(QJsonDocument(jsonlized_gpgme_component_info).toJson()));
GFGetModuleID(), GFModuleStrDup("gnupg.components.gpgme"),
GFModuleStrDup(QJsonDocument(jsonlized_gpgme_component_info).toJson()));
GFModuleUpsertRTValue(
GFGetModuleID(), DUP("gnupg.components.gpgconf"),
DUP(QJsonDocument(jsonlized_gpgconf_component_info).toJson()));
GFGetModuleID(), GFModuleStrDup("gnupg.components.gpgconf"),
GFModuleStrDup(QJsonDocument(jsonlized_gpgconf_component_info).toJson()));
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") {
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") {
GFModuleUpsertRTValue(GFGetModuleID(), DUP("gnupg.gpg_agent_path"),
DUP(QString(component_path).toUtf8()));
GFModuleUpsertRTValue(GFGetModuleID(),
GFModuleStrDup("gnupg.gpg_agent_path"),
GFModuleStrDup(QString(component_path).toUtf8()));
}
if (component_name == "dirmngr") {
GFModuleUpsertRTValue(GFGetModuleID(), DUP("gnupg.dirmngr_path"),
DUP(QString(component_path).toUtf8()));
GFModuleUpsertRTValue(GFGetModuleID(),
GFModuleStrDup("gnupg.dirmngr_path"),
GFModuleStrDup(QString(component_path).toUtf8()));
}
if (component_name == "keyboxd") {
GFModuleUpsertRTValue(GFGetModuleID(), DUP("gnupg.keyboxd_path"),
DUP(QString(component_path).toUtf8()));
GFModuleUpsertRTValue(GFGetModuleID(),
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();
GFModuleUpsertRTValue(
GFGetModuleID(),
DUP(QString("gnupg.components.%1").arg(component_name).toUtf8()),
DUP(QJsonDocument(jsonlized_component_info).toJson()));
GFModuleStrDup(
QString("gnupg.components.%1").arg(component_name).toUtf8()),
GFModuleStrDup(QJsonDocument(jsonlized_component_info).toJson()));
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
if (configuration_name == "homedir") {
GFModuleUpsertRTValue(GFGetModuleID(), DUP("gnupg.home_path"),
DUP(configuration_value.toUtf8()));
GFModuleUpsertRTValue(GFGetModuleID(), GFModuleStrDup("gnupg.home_path"),
GFModuleStrDup(configuration_value.toUtf8()));
}
GFModuleUpsertRTValue(
GFGetModuleID(),
DUP(QString("gnupg.dirs.%1").arg(configuration_name).toUtf8()),
DUP(configuration_value.toUtf8()));
GFModuleStrDup(
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;
auto const jsonlized_option_info = info.Json();
GFModuleUpsertRTValue(GFGetModuleID(),
DUP(QString("gnupg.components.%1.options.%2")
.arg(component_name)
.arg(option_name)
.toUtf8()),
DUP(QJsonDocument(jsonlized_option_info).toJson()));
GFModuleUpsertRTValue(
GFGetModuleID(),
GFModuleStrDup(QString("gnupg.components.%1.options.%2")
.arg(component_name)
.arg(option_name)
.toUtf8()),
GFModuleStrDup(QJsonDocument(jsonlized_option_info).toJson()));
options_infos.push_back(info);
}

View 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());
}
};

View File

@ -30,6 +30,9 @@ aux_source_directory(. MODULE_SOURCE_FILES)
# define libgpgfrontend_module
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(TARGETS mod_ver_check
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/modules")

View 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());
}
};

View File

@ -31,23 +31,59 @@
#include <GFSDKBasic.h>
#include <GFSDKExtra.h>
#include <GFSDKLog.h>
#include <spdlog/spdlog.h>
#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 {
MLogDebug(QString("compare version current: %1 latest %2, result: %3")
.arg(current_version)
.arg(latest_version)
.arg(GFCompareSoftwareVersion(
GFModuleStrDup(current_version.toUtf8()),
GFModuleStrDup(latest_version.toUtf8()))));
GFModuleLogDebug(
fmt::format(
"compair version current {} latest {}, result {}", current_version,
latest_version,
GFCompareSoftwareVersion(GFModuleStrDup(current_version.toUtf8()),
GFModuleStrDup(latest_version.toUtf8())))
.c_str());
MLogDebug(QString("load done: %1, pre-release: %2, draft: %3")
.arg(static_cast<int>(loading_done))
.arg(static_cast<int>(latest_prerelease_version_from_remote))
.arg(static_cast<int>(latest_draft_from_remote)));
GFModuleLogDebug(fmt::format("load done: {}, pre-release: {}, draft: {}",
loading_done,
latest_prerelease_version_from_remote,
latest_draft_from_remote)
.c_str());
return loading_done && !latest_prerelease_version_from_remote &&
!latest_draft_from_remote &&
GFCompareSoftwareVersion(GFModuleStrDup(current_version.toUtf8()),

View File

@ -31,12 +31,14 @@
#include <GFSDKBasic.h>
#include <GFSDKExtra.h>
#include <GFSDKLog.h>
#include <qobject.h>
#include <QMetaType>
#include <QtNetwork>
#include "GFModuleCommonUtils.hpp"
// spdlog
#include <spdlog/spdlog.h>
#include "LogFormatter.h"
#include "SoftwareVersion.h"
#include "VersionCheckingModule.h"
@ -48,6 +50,8 @@ VersionCheckTask::VersionCheckTask()
}
auto VersionCheckTask::Run() -> int {
GFModuleLogDebug(
fmt::format("current project version: {}", current_version_).c_str());
QString latest_version_url =
"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_.loading_done = false;
} else if (latest_reply_->error() != QNetworkReply::NoError) {
MLogError(QString("latest version request error: %1")
.arg(latest_reply_->errorString()));
GFModuleLogError(fmt::format("latest version request error: ",
latest_reply_->errorString())
.c_str());
version_.latest_version = current_version_;
} else {
latest_reply_bytes_ = latest_reply_->readAll();
@ -80,10 +85,15 @@ void VersionCheckTask::slot_parse_latest_version_info() {
auto version_match = re.match(latest_version);
if (version_match.hasMatch()) {
latest_version = version_match.captured(0);
GFModuleLogInfo(fmt::format("latest released version from github: {}",
latest_version)
.c_str());
} else {
latest_version = current_version_;
MLogWarn(QString("latest version unknown, set to current version: %1")
.arg(current_version_));
GFModuleLogWarn(
fmt::format("latest version unknown, set to current version: {}",
current_version_)
.c_str());
}
bool prerelease = latest_reply_json["prerelease"].toBool();
@ -96,8 +106,9 @@ void VersionCheckTask::slot_parse_latest_version_info() {
version_.publish_date = publish_date;
version_.release_note = release_note;
} else {
MLogWarn(QString("cannot parse data got from github: %1")
.arg(latest_reply_bytes_));
GFModuleLogWarn(fmt::format("cannot parse data got from github: {}",
latest_reply_bytes_)
.c_str());
}
}
@ -109,6 +120,9 @@ void VersionCheckTask::slot_parse_latest_version_info() {
QString current_version_url =
"https://api.github.com/repos/saturneric/gpgfrontend/releases/tags/" +
current_version_;
GFModuleLogDebug(
fmt::format("current version info query url: {}", current_version_url)
.c_str());
QNetworkRequest current_request(current_version_url);
current_request.setHeader(QNetworkRequest::UserAgentHeader,
@ -129,8 +143,9 @@ void VersionCheckTask::slot_parse_current_version_info() {
version_.loading_done = false;
} else if (current_reply_->error() != QNetworkReply::NoError) {
MLogError(QString("current version request network error: {}")
.arg(current_reply_->errorString()));
GFModuleLogError(fmt::format("current version request network error: {}",
current_reply_->errorString())
.c_str());
// loading done
version_.loading_done = true;
@ -148,11 +163,16 @@ void VersionCheckTask::slot_parse_current_version_info() {
// loading done
version_.loading_done = true;
} else {
MLogWarn(QString("cannot parse data got from github: %1")
.arg(current_reply_bytes_));
GFModuleLogWarn(fmt::format("cannot parse data got from github: {}",
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();
slot_fill_grt_with_version_info(version_);

View File

@ -33,6 +33,7 @@
#include <GFSDKExtra.h>
#include <GFSDKLog.h>
#include <GFSDKUI.h>
#include <spdlog/spdlog.h>
#include <QMetaType>
#include <QtNetwork>

View File

@ -22,3 +22,5 @@
# Saturneric <eric@bktus.com> starting on May 12, 2021.
#
# SPDX-License-Identifier: GPL-3.0-or-later
add_subdirectory(spdlog EXCLUDE_FROM_ALL)

1
third_party/spdlog vendored Submodule

@ -0,0 +1 @@
Subproject commit d276069a6e916b1e1fd45885b15b72bd8ee000a7