diff options
Diffstat (limited to 'src/module')
29 files changed, 1975 insertions, 0 deletions
diff --git a/src/module/CMakeLists.txt b/src/module/CMakeLists.txt new file mode 100644 index 00000000..a741f0af --- /dev/null +++ b/src/module/CMakeLists.txt @@ -0,0 +1,100 @@ +# Copyright (C) 2021 Saturneric <[email protected]> +# +# 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 <[email protected]> starting on May 12, 2021. +# +# SPDX-License-Identifier: GPL-3.0-or-later + +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) + +# define libgpgfrontend_module_sdk +aux_source_directory(sdk MODULE_SDK_SOURCE) + +add_library(gpgfrontend_module_sdk SHARED ${MODULE_SDK_SOURCE}) +set(_export_file_sdk "${CMAKE_CURRENT_SOURCE_DIR}/sdk/GpgFrontendModuleSDKExport.h") +generate_export_header(gpgfrontend_module_sdk EXPORT_FILE_NAME "${_export_file_sdk}") +target_include_directories(gpgfrontend_module_sdk PUBLIC + sdk + ${CMAKE_CURRENT_BINARY_DIR}/gpgfrontend_module_sdk_autogen/include + ${CMAKE_SOURCE_DIR}/third_party/spdlog/include) + +# link module system +target_link_libraries(gpgfrontend_module_sdk PUBLIC gpgfrontend_core) + +if (XCODE_BUILD) + set_target_properties(gpgfrontend_module_sdk + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + XCODE_ATTRIBUTE_SKIP_INSTALL "Yes" + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${GPGFRONTEND_XOCDE_CODE_SIGN_IDENTITY}") +endif () + +# tracking integrated modules +set(all_integrated_module_libraries "") +file(GLOB children LIST_DIRECTORIES true "integrated/*") +foreach(child ${children}) + if(IS_DIRECTORY ${child}) + get_filename_component(dirName ${child} NAME) + add_subdirectory("integrated/${dirName}") + + string(REPLACE "_module" "" stripped_module ${dirName}) + set(integrated_lib_name "gpgfrontend_integrated_module_${stripped_module}") + list(APPEND all_integrated_module_libraries ${integrated_lib_name}) + endif() +endforeach() + +aux_source_directory(. MODULE_SOURCE) +add_library(gpgfrontend_module SHARED ${MODULE_SOURCE}) + +set(_export_file "${CMAKE_CURRENT_SOURCE_DIR}/GpgFrontendModuleExport.h") +generate_export_header(gpgfrontend_module EXPORT_FILE_NAME "${_export_file}") + +# set up pch +target_precompile_headers(gpgfrontend_module PUBLIC GpgFrontendModule.h) + +# add ui generator include path +target_include_directories(gpgfrontend_module PUBLIC + ${CMAKE_CURRENT_BINARY_DIR}/gpgfrontend_module_autogen/include + ${CMAKE_SOURCE_DIR}/third_party/spdlog/include) + +# link gpgfrontend_module_sdk +target_link_libraries(gpgfrontend_module PRIVATE gpgfrontend_module_sdk) + +if (XCODE_BUILD) + set_target_properties(gpgfrontend_module + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + XCODE_ATTRIBUTE_SKIP_INSTALL "Yes" + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${GPGFRONTEND_XOCDE_CODE_SIGN_IDENTITY}") +endif () + + +# link all integrated modules +message(STATUS "All Module Libraries: ${all_integrated_module_libraries}") +target_link_libraries(gpgfrontend_module PRIVATE ${all_integrated_module_libraries}) + +# using std c++ 17 +target_compile_features(gpgfrontend_module PUBLIC cxx_std_17)
\ No newline at end of file diff --git a/src/module/GpgFrontendModule.h b/src/module/GpgFrontendModule.h new file mode 100644 index 00000000..cf7d8557 --- /dev/null +++ b/src/module/GpgFrontendModule.h @@ -0,0 +1,36 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +/** + * Project internal dependencies + */ +#include "GpgFrontend.h" +#include "GpgFrontendModuleExport.h" +#include "core/GpgFrontendCore.h" diff --git a/src/module/GpgFrontendModuleExport.h b/src/module/GpgFrontendModuleExport.h new file mode 100644 index 00000000..33ecbd3b --- /dev/null +++ b/src/module/GpgFrontendModuleExport.h @@ -0,0 +1,42 @@ + +#ifndef GPGFRONTEND_MODULE_EXPORT_H +#define GPGFRONTEND_MODULE_EXPORT_H + +#ifdef GPGFRONTEND_MODULE_STATIC_DEFINE +# define GPGFRONTEND_MODULE_EXPORT +# define GPGFRONTEND_MODULE_NO_EXPORT +#else +# ifndef GPGFRONTEND_MODULE_EXPORT +# ifdef gpgfrontend_module_EXPORTS + /* We are building this library */ +# define GPGFRONTEND_MODULE_EXPORT __attribute__((visibility("default"))) +# else + /* We are using this library */ +# define GPGFRONTEND_MODULE_EXPORT __attribute__((visibility("default"))) +# endif +# endif + +# ifndef GPGFRONTEND_MODULE_NO_EXPORT +# define GPGFRONTEND_MODULE_NO_EXPORT __attribute__((visibility("hidden"))) +# endif +#endif + +#ifndef GPGFRONTEND_MODULE_DEPRECATED +# define GPGFRONTEND_MODULE_DEPRECATED __attribute__ ((__deprecated__)) +#endif + +#ifndef GPGFRONTEND_MODULE_DEPRECATED_EXPORT +# define GPGFRONTEND_MODULE_DEPRECATED_EXPORT GPGFRONTEND_MODULE_EXPORT GPGFRONTEND_MODULE_DEPRECATED +#endif + +#ifndef GPGFRONTEND_MODULE_DEPRECATED_NO_EXPORT +# define GPGFRONTEND_MODULE_DEPRECATED_NO_EXPORT GPGFRONTEND_MODULE_NO_EXPORT GPGFRONTEND_MODULE_DEPRECATED +#endif + +#if 0 /* DEFINE_NO_DEPRECATED */ +# ifndef GPGFRONTEND_MODULE_NO_DEPRECATED +# define GPGFRONTEND_MODULE_NO_DEPRECATED +# endif +#endif + +#endif /* GPGFRONTEND_MODULE_EXPORT_H */ diff --git a/src/module/GpgFrontendModuleInit.cpp b/src/module/GpgFrontendModuleInit.cpp new file mode 100644 index 00000000..6f88b9ec --- /dev/null +++ b/src/module/GpgFrontendModuleInit.cpp @@ -0,0 +1,66 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "GpgFrontendModuleInit.h" + +#include <core/module/ModuleManager.h> + +#include "core/thread/Task.h" +#include "core/thread/TaskRunnerGetter.h" + +// integrated modules +#include "integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.h" +#include "integrated/version_checking_module/VersionCheckingModule.h" +#include "spdlog/common.h" + +namespace GpgFrontend::Module { + +void LoadGpgFrontendModules(ModuleInitArgs) { + // must init at default thread before core + Thread::TaskRunnerGetter::GetInstance().GetTaskRunner()->PostTask( + new Thread::Task( + [](const DataObjectPtr&) -> int { + MODULE_LOG_INFO("loading integrated module..."); + + // VersionCheckingModule + RegisterAndActivateModule< + Integrated::VersionCheckingModule::VersionCheckingModule>(); + + // VersionCheckingModule + RegisterAndActivateModule<Integrated::GnuPGInfoGatheringModule:: + GnuPGInfoGatheringModule>(); + + MODULE_LOG_INFO("load integrated module done."); + return 0; + }, + "modules_system_init_task")); +} + +void ShutdownGpgFrontendModules() {} + +} // namespace GpgFrontend::Module
\ No newline at end of file diff --git a/src/module/GpgFrontendModuleInit.h b/src/module/GpgFrontendModuleInit.h new file mode 100644 index 00000000..a3a8bbd3 --- /dev/null +++ b/src/module/GpgFrontendModuleInit.h @@ -0,0 +1,51 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include "module/GpgFrontendModule.h" + +namespace GpgFrontend::Module { + +struct ModuleInitArgs { + spdlog::level::level_enum log_level; +}; + +/** + * @brief init the module library + * + */ +void GPGFRONTEND_MODULE_EXPORT LoadGpgFrontendModules(ModuleInitArgs args); + +/** + * @brief shutdown the module library + * + */ +void GPGFRONTEND_MODULE_EXPORT ShutdownGpgFrontendModules(); + +}; // namespace GpgFrontend::Module diff --git a/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt b/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt new file mode 100644 index 00000000..48dbd0de --- /dev/null +++ b/src/module/integrated/gnupg_info_gathering_module/CMakeLists.txt @@ -0,0 +1,53 @@ +# Copyright (C) 2021 Saturneric <[email protected]> +# +# 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 <[email protected]> starting on May 12, 2021. +# +# SPDX-License-Identifier: GPL-3.0-or-later + +# com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering + +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 + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + XCODE_ATTRIBUTE_SKIP_INSTALL "Yes" + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${GPGFRONTEND_XOCDE_CODE_SIGN_IDENTITY}") +endif () + +# link sdk +target_link_libraries(gpgfrontend_integrated_module_gnupg_info_gathering PRIVATE + gpgfrontend_module_sdk) + +# property +set_property(TARGET gpgfrontend_integrated_module_gnupg_info_gathering PROPERTY AUTOMOC ON) + +# using std c++ 17 +target_compile_features(gpgfrontend_integrated_module_gnupg_info_gathering PRIVATE cxx_std_17)
\ No newline at end of file diff --git a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp new file mode 100644 index 00000000..c965ed30 --- /dev/null +++ b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp @@ -0,0 +1,345 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "GnuPGInfoGatheringModule.h" + +#include <vector> + +#include "GpgInfo.h" +#include "Log.h" +#include "core/function/gpg/GpgCommandExecutor.h" +#include "core/module/ModuleManager.h" + +namespace GpgFrontend::Module::Integrated::GnuPGInfoGatheringModule { + +auto CheckBinaryChacksum(QString path) -> std::optional<QString> { + // check file info and access rights + QFileInfo info(path); + if (!info.exists() || !info.isFile() || !info.isReadable()) { + MODULE_LOG_ERROR("get info for file {} error, exists: {}", info.filePath(), + info.exists()); + return {}; + } + + // open and read file + QFile f(info.filePath()); + if (!f.open(QIODevice::ReadOnly)) { + MODULE_LOG_ERROR("open {} to calculate check sum error: {}", path, + f.errorString()); + return {}; + } + + // read all data from file + auto buffer = f.readAll(); + f.close(); + + auto hash_sha = QCryptographicHash(QCryptographicHash::Sha256); + // md5 + hash_sha.addData(buffer); + return QString(hash_sha.result().toHex()).left(6); +} + +GnuPGInfoGatheringModule::GnuPGInfoGatheringModule() + : Module( + "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", + "1.0.0", + ModuleMetaData{{"description", "try to gathering gnupg informations"}, + {"author", "saturneric"}}) {} + +GnuPGInfoGatheringModule::~GnuPGInfoGatheringModule() = default; + +auto GnuPGInfoGatheringModule::Register() -> bool { + MODULE_LOG_DEBUG("gnupg info gathering module registering"); + listenEvent("GPGFRONTEND_CORE_INITLIZED"); + return true; +} + +auto GnuPGInfoGatheringModule::Active() -> bool { + MODULE_LOG_DEBUG("gnupg info gathering module activating"); + return true; +} + +auto GnuPGInfoGatheringModule::Exec(EventRefrernce event) -> int { + MODULE_LOG_DEBUG("gnupg info gathering module executing, event id: {}", + event->GetIdentifier()); + + const auto gpgme_version = RetrieveRTValueTypedOrDefault<>( + "core", "gpgme.version", QString{"0.0.0"}); + MODULE_LOG_DEBUG("got gpgme version from rt: {}", gpgme_version); + + const auto gpgconf_path = RetrieveRTValueTypedOrDefault<>( + "core", "gpgme.ctx.gpgconf_path", QString{}); + MODULE_LOG_DEBUG("got gpgconf path from rt: {}", gpgconf_path); + + MODULE_LOG_DEBUG("start to load extra info at module gnupginfogathering..."); + + // get all components + GpgCommandExecutor::ExecuteSync( + {gpgconf_path, QStringList{"--list-components"}, + [this, gpgme_version, gpgconf_path](int exit_code, const QString &p_out, + const QString &p_err) { + MODULE_LOG_DEBUG( + "gpgconf components exit_code: {} process stdout size: {}", + exit_code, p_out.size()); + + if (exit_code != 0) { + MODULE_LOG_ERROR( + "gpgconf execute error, process stderr: {}, " + "process stdout: {}", + p_err, p_out); + return; + } + + std::vector<GpgComponentInfo> component_infos; + GpgComponentInfo c_i_gpgme; + c_i_gpgme.name = "gpgme"; + c_i_gpgme.desc = "GPG Made Easy"; + c_i_gpgme.version = gpgme_version; + c_i_gpgme.path = tr("Embedded In"); + c_i_gpgme.binary_checksum = "/"; + + GpgComponentInfo c_i_gpgconf; + c_i_gpgconf.name = "gpgconf"; + c_i_gpgconf.desc = "GPG Configure"; + c_i_gpgconf.version = "/"; + c_i_gpgconf.path = gpgconf_path; + auto gpgconf_binary_checksum = CheckBinaryChacksum(gpgconf_path); + c_i_gpgconf.binary_checksum = (gpgconf_binary_checksum.has_value() + ? gpgconf_binary_checksum.value() + : QString("/")); + + component_infos.push_back(c_i_gpgme); + component_infos.push_back(c_i_gpgconf); + + auto const jsonlized_gpgme_component_info = c_i_gpgme.Json(); + auto const jsonlized_gpgconf_component_info = c_i_gpgconf.Json(); + UpsertRTValue(GetModuleIdentifier(), "gnupg.components.gpgme", + QJsonDocument(jsonlized_gpgme_component_info).toJson()); + UpsertRTValue( + GetModuleIdentifier(), "gnupg.components.gpgconf", + QJsonDocument(jsonlized_gpgconf_component_info).toJson()); + + auto line_split_list = p_out.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(); + +#ifdef WINDOWS + // replace some special substrings on windows platform + component_path.replace("%3a", ":"); +#endif + + auto binary_checksum = CheckBinaryChacksum(component_path); + + MODULE_LOG_DEBUG( + "gnupg component name: {} desc: {} checksum: {} path: {} ", + component_name, component_desc, + binary_checksum.has_value() ? binary_checksum.value() : "/", + component_path); + + QString version = "/"; + + if (component_name == "gpg") { + version = RetrieveRTValueTypedOrDefault<>( + "core", "gpgme.ctx.gnupg_version", QString{"2.0.0"}); + } + if (component_name == "gpg-agent") { + UpsertRTValue(GetModuleIdentifier(), "gnupg.gpg_agent_path", + QString(component_path)); + } + if (component_name == "dirmngr") { + UpsertRTValue(GetModuleIdentifier(), "gnupg.dirmngr_path", + QString(component_path)); + } + if (component_name == "keyboxd") { + UpsertRTValue(GetModuleIdentifier(), "gnupg.keyboxd_path", + QString(component_path)); + } + + { + GpgComponentInfo c_i; + c_i.name = component_name; + c_i.desc = component_desc; + c_i.version = version; + c_i.path = component_path; + c_i.binary_checksum = + (binary_checksum.has_value() ? binary_checksum.value() + : QString("/")); + + auto const jsonlized_component_info = c_i.Json(); + UpsertRTValue(GetModuleIdentifier(), + QString("gnupg.components.%1").arg(component_name), + QJsonDocument(jsonlized_component_info).toJson()); + + component_infos.push_back(c_i); + } + } + }, + getTaskRunner()}); + + GpgCommandExecutor::ExecuteContexts exec_contexts; + + exec_contexts.emplace_back(GpgCommandExecutor::ExecuteContext{ + gpgconf_path, QStringList{"--list-dirs"}, + [this](int exit_code, const QString &p_out, const QString &p_err) { + if (exit_code != 0) return; + + auto line_split_list = p_out.split("\n"); + + for (const auto &line : line_split_list) { + auto info_split_list = line.split(":"); + MODULE_LOG_DEBUG("gpgconf direcrotries info line: {} info size: {}", + line, info_split_list.size()); + + if (info_split_list.size() != 2) continue; + + auto configuration_name = info_split_list[0].trimmed(); + auto configuration_value = info_split_list[1].trimmed(); + +#ifdef WINDOWS + // replace some special substrings on windows platform + configuration_value.replace("%3a", ":"); +#endif + + // record gnupg home path + if (configuration_name == "homedir") { + UpsertRTValue(GetModuleIdentifier(), "gnupg.home_path", + configuration_value); + } + + UpsertRTValue(GetModuleIdentifier(), + QString("gnupg.dirs.%1").arg(configuration_name), + configuration_value); + } + }, + getTaskRunner()}); + + auto components = ListRTChildKeys(GetModuleIdentifier(), "gnupg.components"); + + for (const auto &component : components) { + auto component_info_json = RetrieveRTValueTypedOrDefault( + GetModuleIdentifier(), QString("gnupg.components.%1").arg(component), + QByteArray{}); + + auto jsonlized_component_info = + QJsonDocument::fromJson(component_info_json); + assert(jsonlized_component_info.isObject()); + + auto component_info = GpgComponentInfo(jsonlized_component_info.object()); + MODULE_LOG_DEBUG("gpgconf check options ready, component: {}", + component_info.name); + + if (component_info.name == "gpgme" || component_info.name == "gpgconf") { + continue; + } + + exec_contexts.emplace_back(GpgCommandExecutor::ExecuteContext{ + gpgconf_path, QStringList{"--list-options", component_info.name}, + [this, component_info](int exit_code, const QString &p_out, + const QString &p_err) { + MODULE_LOG_DEBUG( + "gpgconf {} avaliable options exit_code: {} process stdout " + "size: {} ", + component_info.name, exit_code, p_out.size()); + + if (exit_code != 0) { + MODULE_LOG_ERROR( + "gpgconf {} avaliable options execute error, process stderr: " + "{} , process stdout:", + component_info.name, p_err, p_out); + return; + } + + std::vector<GpgOptionsInfo> options_infos; + + auto line_split_list = p_out.split("\n"); + + for (const auto &line : line_split_list) { + auto info_split_list = line.split(":"); + + MODULE_LOG_DEBUG( + "component {} avaliable options line: {} info size: {}", + component_info.name, line, info_split_list.size()); + + if (info_split_list.size() < 10) continue; + + // The format of each line is: + // name:flags:level:description:type:alt-type:argname:default:argdef:value + + auto option_name = info_split_list[0].trimmed(); + auto option_flags = info_split_list[1].trimmed(); + auto option_level = info_split_list[2].trimmed(); + auto option_desc = info_split_list[3].trimmed(); + auto option_type = info_split_list[4].trimmed(); + auto option_alt_type = info_split_list[5].trimmed(); + auto option_argname = info_split_list[6].trimmed(); + auto option_default = info_split_list[7].trimmed(); + auto option_argdef = info_split_list[8].trimmed(); + auto option_value = info_split_list[9].trimmed(); + + GpgOptionsInfo info; + info.name = option_name; + info.flags = option_flags; + info.level = option_level; + info.description = option_desc; + info.type = option_type; + info.alt_type = option_alt_type; + info.argname = option_argname; + info.default_value = option_default; + info.argdef = option_argdef; + info.value = option_value; + + auto const jsonlized_option_info = info.Json(); + UpsertRTValue(GetModuleIdentifier(), + QString("gnupg.components.%1.options.%2") + .arg(component_info.name) + .arg(option_name), + QJsonDocument(jsonlized_option_info).toJson()); + options_infos.push_back(info); + } + }, + getTaskRunner()}); + } + + GpgCommandExecutor::ExecuteConcurrentlySync(exec_contexts); + UpsertRTValue(GetModuleIdentifier(), "gnupg.gathering_done", true); + event->ExecuteCallback(GetModuleIdentifier(), TransferParams(true)); + + MODULE_LOG_DEBUG("gnupg external info gathering done"); + return 0; +} + +auto GnuPGInfoGatheringModule::Deactive() -> bool { return true; } + +} // namespace GpgFrontend::Module::Integrated::GnuPGInfoGatheringModule diff --git a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.h b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.h new file mode 100644 index 00000000..88f64d7d --- /dev/null +++ b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.h @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include "GpgFrontendModuleExport.h" +#include "core/module/Module.h" + +namespace GpgFrontend::Module::Integrated::GnuPGInfoGatheringModule { + +/** + * @brief Use to record some info about gnupg + * + */ +class GPGFRONTEND_INTEGRATED_MODULE_GNUPG_INFO_GATHERING_EXPORT + GnuPGInfoGatheringModule : public Module { + public: + GnuPGInfoGatheringModule(); + + ~GnuPGInfoGatheringModule() override; + + auto Register() -> bool override; + + auto Active() -> bool override; + + auto Exec(EventRefrernce) -> int override; + + auto Deactive() -> bool override; +}; +} // namespace GpgFrontend::Module::Integrated::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/gnupg_info_gathering_module/GpgInfo.cpp b/src/module/integrated/gnupg_info_gathering_module/GpgInfo.cpp new file mode 100644 index 00000000..2015bc0a --- /dev/null +++ b/src/module/integrated/gnupg_info_gathering_module/GpgInfo.cpp @@ -0,0 +1,80 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "module/integrated/gnupg_info_gathering_module/GpgInfo.h" + +namespace GpgFrontend::Module::Integrated::GnuPGInfoGatheringModule { + +GpgOptionsInfo::GpgOptionsInfo(const QJsonObject &j) { + if (const auto v = j["name"]; v.isString()) name = v.toString(); + if (const auto v = j["flags"]; v.isString()) flags = v.toString(); + if (const auto v = j["level"]; v.isString()) level = v.toString(); + if (const auto v = j["description"]; v.isString()) description = v.toString(); + if (const auto v = j["type"]; v.isString()) type = v.toString(); + if (const auto v = j["alt_type"]; v.isString()) alt_type = v.toString(); + if (const auto v = j["argname"]; v.isString()) argname = v.toString(); + if (const auto v = j["default_value"]; v.isString()) + default_value = v.toString(); + if (const auto v = j["argdef"]; v.isString()) argdef = v.toString(); + if (const auto v = j["value"]; v.isString()) value = v.toString(); +} + +auto GpgOptionsInfo::Json() const -> QJsonObject { + QJsonObject j; + j["name"] = name; + j["flags"] = flags; + j["level"] = level; + j["description"] = description; + j["type"] = type; + j["alt_type"] = alt_type; + j["argname"] = argname; + j["default_value"] = default_value; + j["argdef"] = argdef; + j["value"] = value; + return j; +} + +auto GpgComponentInfo::Json() const -> QJsonObject { + QJsonObject j; + j["name"] = name; + j["desc"] = desc; + j["version"] = version; + j["path"] = path; + j["binary_checksum"] = binary_checksum; + return j; +} + +GpgComponentInfo::GpgComponentInfo(const QJsonObject &j) { + if (const auto v = j["name"]; v.isString()) name = v.toString(); + if (const auto v = j["desc"]; v.isString()) desc = v.toString(); + if (const auto v = j["version"]; v.isString()) version = v.toString(); + if (const auto v = j["path"]; v.isString()) path = v.toString(); + if (const auto v = j["binary_checksum"]; v.isString()) + binary_checksum = v.toString(); +} +} // namespace GpgFrontend::Module::Integrated::GnuPGInfoGatheringModule diff --git a/src/module/integrated/gnupg_info_gathering_module/GpgInfo.h b/src/module/integrated/gnupg_info_gathering_module/GpgInfo.h new file mode 100644 index 00000000..fb12b811 --- /dev/null +++ b/src/module/integrated/gnupg_info_gathering_module/GpgInfo.h @@ -0,0 +1,87 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +namespace GpgFrontend::Module::Integrated::GnuPGInfoGatheringModule { +/** + * @brief Use to record some info about gnupg + * + */ +class GpgInfo { + public: + QString GnuPGHomePath; ///< value of ---homedir + + std::map<QString, std::vector<QString>> ComponentsInfo; ///< + std::map<QString, std::vector<QString>> ConfigurationsInfo; ///< + std::map<QString, std::vector<QString>> OptionsInfo; ///< + std::map<QString, std::vector<QString>> AvailableOptionsInfo; ///< +}; + +/** + * @brief Use to record some info about gnupg components + * + */ +struct GpgComponentInfo { + QString name; + QString desc; + QString version; + QString path; + QString binary_checksum; + + GpgComponentInfo() = default; + + explicit GpgComponentInfo(const QJsonObject &j); + + [[nodiscard]] auto Json() const -> QJsonObject; +}; + +/** + * The format of each line is: + * name:flags:level:description:type:alt-type:argname:default:argdef:value + */ +struct GpgOptionsInfo { + QString name; + QString flags; + QString level; + QString description; + QString type; + QString alt_type; + QString argname; + QString default_value; + QString argdef; + QString value; + + GpgOptionsInfo() = default; + + explicit GpgOptionsInfo(const QJsonObject &j); + + [[nodiscard]] auto Json() const -> QJsonObject; +}; + +} // namespace GpgFrontend::Module::Integrated::GnuPGInfoGatheringModule diff --git a/src/module/integrated/version_checking_module/CMakeLists.txt b/src/module/integrated/version_checking_module/CMakeLists.txt new file mode 100644 index 00000000..f122be88 --- /dev/null +++ b/src/module/integrated/version_checking_module/CMakeLists.txt @@ -0,0 +1,56 @@ +# Copyright (C) 2021 Saturneric <[email protected]> +# +# 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 <[email protected]> starting on May 12, 2021. +# +# SPDX-License-Identifier: GPL-3.0-or-later + +# com.bktus.gpgfrontend.module.integrated.version-checking + +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 + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} + XCODE_ATTRIBUTE_SKIP_INSTALL "Yes" + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${GPGFRONTEND_XOCDE_CODE_SIGN_IDENTITY}") +endif () + +# link sdk +target_link_libraries(gpgfrontend_integrated_module_version_checking PRIVATE + gpgfrontend_module_sdk) + +# link Qt +target_link_libraries(gpgfrontend_integrated_module_version_checking PRIVATE Qt6::Network) + +# property +set_property(TARGET gpgfrontend_integrated_module_version_checking PROPERTY AUTOMOC ON) + +# using std c++ 17 +target_compile_features(gpgfrontend_integrated_module_version_checking PRIVATE cxx_std_17)
\ No newline at end of file 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 new file mode 100644 index 00000000..7d41b1c5 --- /dev/null +++ b/src/module/integrated/version_checking_module/SoftwareVersion.cpp @@ -0,0 +1,58 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "SoftwareVersion.h" + +#include "core/utils/CommonUtils.h" +#include "module/sdk/Log.h" + +namespace GpgFrontend::Module::Integrated::VersionCheckingModule { + +auto VersionCheckingModule::SoftwareVersion::NeedUpgrade() const -> bool { + MODULE_LOG_DEBUG("compair version current {} latest {}, result {}", + current_version, latest_version, + CompareSoftwareVersion(current_version, latest_version)); + + MODULE_LOG_DEBUG("load done: {}, pre-release: {}, draft: {}", loading_done, + latest_prerelease_version_from_remote, + latest_draft_from_remote); + return loading_done && !latest_prerelease_version_from_remote && + !latest_draft_from_remote && + CompareSoftwareVersion(current_version, latest_version) < 0; +} + +auto VersionCheckingModule::SoftwareVersion::VersionWithdrawn() const -> bool { + return loading_done && !current_version_publish_in_remote && + current_version_is_a_prerelease && !current_version_is_drafted; +} + +auto VersionCheckingModule::SoftwareVersion::CurrentVersionReleased() const + -> bool { + return loading_done && current_version_publish_in_remote; +} +} // namespace GpgFrontend::Module::Integrated::VersionCheckingModule
\ No newline at end of file diff --git a/src/module/integrated/version_checking_module/SoftwareVersion.h b/src/module/integrated/version_checking_module/SoftwareVersion.h new file mode 100644 index 00000000..43f718fa --- /dev/null +++ b/src/module/integrated/version_checking_module/SoftwareVersion.h @@ -0,0 +1,85 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include <module/sdk/GpgFrontendModuleSDK.h> + +namespace GpgFrontend::Module::Integrated::VersionCheckingModule { +/** + * @brief + * + */ +struct SoftwareVersion { + QString latest_version; ///< + QString current_version; ///< + bool latest_prerelease_version_from_remote = false; ///< + bool latest_draft_from_remote = false; ///< + bool current_version_is_a_prerelease = false; ///< + bool current_version_is_drafted = false; ///< + bool loading_done = false; ///< + bool current_version_publish_in_remote = false; ///< + QString publish_date; ///< + QString release_note; ///< + + /** + * @brief + * + * @return true + * @return false + */ + [[nodiscard]] bool InfoValid() const { return loading_done; } + + /** + * @brief + * + * @return true + * @return false + */ + [[nodiscard]] bool NeedUpgrade() const; + + /** + * @brief + * + * @return true + * @return false + */ + [[nodiscard]] bool VersionWithdrawn() const; + + /** + * @brief + * + * @return true + * @return false + */ + [[nodiscard]] bool CurrentVersionReleased() const; + + private: + static int version_compare(const QString& a, const QString& b); +}; +} // namespace GpgFrontend::Module::Integrated::VersionCheckingModule diff --git a/src/module/integrated/version_checking_module/VersionCheckTask.cpp b/src/module/integrated/version_checking_module/VersionCheckTask.cpp new file mode 100644 index 00000000..34827838 --- /dev/null +++ b/src/module/integrated/version_checking_module/VersionCheckTask.cpp @@ -0,0 +1,158 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "VersionCheckTask.h" + +#include <QMetaType> +#include <QtNetwork> + +#include "GpgFrontendBuildInfo.h" + +namespace GpgFrontend::Module::Integrated::VersionCheckingModule { + +VersionCheckTask::VersionCheckTask() + : Task("version_check_task"), + network_manager_(new QNetworkAccessManager(this)), + current_version_(QString("v") + VERSION_MAJOR + "." + VERSION_MINOR + + "." + VERSION_PATCH) { + HoldOnLifeCycle(true); + qRegisterMetaType<SoftwareVersion>("SoftwareVersion"); + version_.current_version = current_version_; +} + +auto VersionCheckTask::Run() -> int { + MODULE_LOG_DEBUG("current project version: {}", current_version_); + QString latest_version_url = + "https://api.github.com/repos/saturneric/gpgfrontend/releases/latest"; + + QNetworkRequest latest_request; + latest_request.setUrl(QUrl(latest_version_url)); + latest_reply_ = network_manager_->get(latest_request); + connect(latest_reply_, &QNetworkReply::finished, this, + &VersionCheckTask::slot_parse_latest_version_info); + return 0; +} + +void VersionCheckTask::slot_parse_latest_version_info() { + version_.current_version = current_version_; + + if (latest_reply_ == nullptr || + latest_reply_->error() != QNetworkReply::NoError) { + MODULE_LOG_ERROR("latest version request error"); + version_.latest_version = current_version_; + } else { + latest_reply_bytes_ = latest_reply_->readAll(); + auto latest_reply_json = QJsonDocument::fromJson(latest_reply_bytes_); + + QString latest_version = latest_reply_json["tag_name"].toString(); + MODULE_LOG_INFO("latest version from Github: {}", latest_version); + + QRegularExpression re(R"(^[vV](\d+\.)?(\d+\.)?(\*|\d+))"); + auto version_match = re.match(latest_version); + if (version_match.hasMatch()) { + latest_version = version_match.captured(0); + MODULE_LOG_DEBUG("latest version matched: {}", latest_version); + } else { + latest_version = current_version_; + MODULE_LOG_WARN("latest version unknown"); + } + + bool prerelease = latest_reply_json["prerelease"].toBool(); + bool draft = latest_reply_json["draft"].toBool(); + auto publish_date = latest_reply_json["published_at"].toString(); + auto release_note = latest_reply_json["body"].toString(); + version_.latest_version = latest_version; + version_.latest_prerelease_version_from_remote = prerelease; + version_.latest_draft_from_remote = draft; + version_.publish_date = publish_date; + version_.release_note = release_note; + } + + if (latest_reply_ != nullptr) { + latest_reply_->deleteLater(); + } + + try { + QString current_version_url = + "https://api.github.com/repos/saturneric/gpgfrontend/releases/tags/" + + current_version_; + MODULE_LOG_DEBUG("current version info query url: {}", current_version_url); + + QNetworkRequest current_request; + current_request.setUrl(QUrl(current_version_url)); + current_reply_ = network_manager_->get(current_request); + + connect(current_reply_, &QNetworkReply::finished, this, + &VersionCheckTask::slot_parse_current_version_info); + } catch (...) { + MODULE_LOG_ERROR("current version request create error"); + emit SignalTaskShouldEnd(-1); + } +} + +void VersionCheckTask::slot_parse_current_version_info() { + if (current_reply_ == nullptr || + current_reply_->error() != QNetworkReply::NoError) { + if (current_reply_ != nullptr) { + MODULE_LOG_ERROR("current version request network error: {}", + current_reply_->errorString().toStdString()); + } else { + MODULE_LOG_ERROR( + "current version request network error, null reply object"); + } + + version_.current_version_publish_in_remote = false; + + // loading done + version_.loading_done = true; + } else { + version_.current_version_publish_in_remote = true; + current_reply_bytes_ = current_reply_->readAll(); + auto current_reply_json = QJsonDocument::fromJson(current_reply_bytes_); + + if (current_reply_json.isObject()) { + bool current_prerelease = current_reply_json["prerelease"].toBool(); + bool current_draft = current_reply_json["draft"].toBool(); + version_.latest_prerelease_version_from_remote = current_prerelease; + version_.latest_draft_from_remote = current_draft; + // loading done + version_.loading_done = true; + } else { + MODULE_LOG_WARN("cannot parse data got from github"); + } + } + + MODULE_LOG_DEBUG("current version parse done: {}", + version_.current_version_publish_in_remote); + + if (current_reply_ != nullptr) current_reply_->deleteLater(); + emit SignalUpgradeVersion(version_); + emit SignalTaskShouldEnd(0); +} + +} // namespace GpgFrontend::Module::Integrated::VersionCheckingModule diff --git a/src/module/integrated/version_checking_module/VersionCheckTask.h b/src/module/integrated/version_checking_module/VersionCheckTask.h new file mode 100644 index 00000000..f5091819 --- /dev/null +++ b/src/module/integrated/version_checking_module/VersionCheckTask.h @@ -0,0 +1,96 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include <core/thread/Task.h> +#include <module/sdk/GpgFrontendModuleSDK.h> + +#include "SoftwareVersion.h" + +class QNetworkReply; +class QNetworkAccessManager; + +namespace GpgFrontend::Module::Integrated::VersionCheckingModule { + +/** + * @brief + * + */ +class VersionCheckTask : public Thread::Task { + Q_OBJECT + public: + /** + * @brief Construct a new Version Check Thread object + * + */ + VersionCheckTask(); + + signals: + + /** + * @brief + * + * @param version + */ + void SignalUpgradeVersion(SoftwareVersion version); + + protected: + /** + * @brief + + * + */ + auto Run() -> int override; + + private slots: + + /** + * @brief + * + */ + void slot_parse_latest_version_info(); + + /** + * @brief + * + */ + void slot_parse_current_version_info(); + + private: + QByteArray latest_reply_bytes_; ///< + QByteArray current_reply_bytes_; ///< + QNetworkReply* latest_reply_ = nullptr; ///< latest version info reply + QNetworkReply* current_reply_ = nullptr; ///< current version info reply + QNetworkAccessManager* network_manager_; ///< + QString current_version_; + SoftwareVersion version_; +}; + +} // namespace GpgFrontend::Module::Integrated::VersionCheckingModule + // GpgFrontend::Module::Custom::IntegradedModule::VersionCheckingModule diff --git a/src/module/integrated/version_checking_module/VersionCheckingModule.cpp b/src/module/integrated/version_checking_module/VersionCheckingModule.cpp new file mode 100644 index 00000000..9b62a9c8 --- /dev/null +++ b/src/module/integrated/version_checking_module/VersionCheckingModule.cpp @@ -0,0 +1,105 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "VersionCheckingModule.h" + +#include "Log.h" +#include "SoftwareVersion.h" +#include "VersionCheckTask.h" +#include "core/module/Module.h" +#include "core/module/ModuleManager.h" + +namespace GpgFrontend::Module::Integrated::VersionCheckingModule { + +VersionCheckingModule::VersionCheckingModule() + : Module("com.bktus.gpgfrontend.module.integrated.version-checking", + "1.0.0", + ModuleMetaData{{"description", "try to check gpgfrontend version"}, + {"author", "saturneric"}}) {} + +VersionCheckingModule::~VersionCheckingModule() = default; + +auto VersionCheckingModule::Register() -> bool { + MODULE_LOG_INFO("version checking module registering"); + listenEvent("APPLICATION_LOADED"); + listenEvent("CHECK_APPLICATION_VERSION"); + return true; +} + +auto VersionCheckingModule::Active() -> bool { + MODULE_LOG_INFO("version checking module activating"); + return true; +} + +auto VersionCheckingModule::Exec(EventRefrernce event) -> int { + MODULE_LOG_INFO("version checking module executing, event id: {}", + event->GetIdentifier()); + + auto* task = new VersionCheckTask(); + connect(task, &VersionCheckTask::SignalUpgradeVersion, this, + &VersionCheckingModule::SignalVersionCheckDone); + connect(this, &VersionCheckingModule::SignalVersionCheckDone, this, + [this, event](SoftwareVersion version) { + SlotVersionCheckDone(std::move(version)); + event->ExecuteCallback(GetModuleIdentifier(), + TransferParams(version.loading_done)); + }); + getTaskRunner()->PostTask(task); + return 0; +} + +auto VersionCheckingModule::Deactive() -> bool { return true; } + +void VersionCheckingModule::SlotVersionCheckDone(SoftwareVersion version) { + MODULE_LOG_DEBUG("registering software information info to rt"); + UpsertRTValue(GetModuleIdentifier(), "version.current_version", + version.current_version); + UpsertRTValue(GetModuleIdentifier(), "version.latest_version", + version.latest_version); + UpsertRTValue(GetModuleIdentifier(), "version.current_version_is_drafted", + version.current_version_is_drafted); + UpsertRTValue(GetModuleIdentifier(), + "version.current_version_is_a_prerelease", + version.current_version_is_a_prerelease); + UpsertRTValue(GetModuleIdentifier(), + "version.current_version_publish_in_remote", + version.current_version_publish_in_remote); + UpsertRTValue(GetModuleIdentifier(), + "version.latest_prerelease_version_from_remote", + version.latest_prerelease_version_from_remote); + UpsertRTValue(GetModuleIdentifier(), "version.need_upgrade", + version.NeedUpgrade()); + UpsertRTValue(GetModuleIdentifier(), "version.current_version_released", + version.CurrentVersionReleased()); + UpsertRTValue(GetModuleIdentifier(), "version.current_a_withdrawn_version", + version.VersionWithdrawn()); + UpsertRTValue(GetModuleIdentifier(), "version.loading_done", + version.loading_done); + MODULE_LOG_DEBUG("register software information to rt done"); +} +} // 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 new file mode 100644 index 00000000..0730feed --- /dev/null +++ b/src/module/integrated/version_checking_module/VersionCheckingModule.h @@ -0,0 +1,61 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include "GpgFrontendModuleExport.h" +#include "SoftwareVersion.h" +#include "core/module/Module.h" + +namespace GpgFrontend::Module::Integrated::VersionCheckingModule { + +class GPGFRONTEND_INTEGRATED_MODULE_VERSION_CHECKING_EXPORT + VersionCheckingModule : public Module { + Q_OBJECT + public: + VersionCheckingModule(); + + ~VersionCheckingModule() override; + + auto Register() -> bool override; + + auto Active() -> bool override; + + auto Exec(EventRefrernce) -> int override; + + auto Deactive() -> bool override; + + signals: + + void SignalVersionCheckDone(SoftwareVersion); + + public slots: + + void SlotVersionCheckDone(SoftwareVersion); +}; +} // namespace GpgFrontend::Module::Integrated::VersionCheckingModule diff --git a/src/module/sdk/Basic.cpp b/src/module/sdk/Basic.cpp new file mode 100644 index 00000000..63859763 --- /dev/null +++ b/src/module/sdk/Basic.cpp @@ -0,0 +1,27 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */
\ No newline at end of file diff --git a/src/module/sdk/Basic.h b/src/module/sdk/Basic.h new file mode 100644 index 00000000..62a547b3 --- /dev/null +++ b/src/module/sdk/Basic.h @@ -0,0 +1,36 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +namespace GpgFrontend::Module::SDK { + + + + +}
\ No newline at end of file diff --git a/src/module/sdk/Gpg.cpp b/src/module/sdk/Gpg.cpp new file mode 100644 index 00000000..63859763 --- /dev/null +++ b/src/module/sdk/Gpg.cpp @@ -0,0 +1,27 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */
\ No newline at end of file diff --git a/src/module/sdk/Gpg.h b/src/module/sdk/Gpg.h new file mode 100644 index 00000000..0702632a --- /dev/null +++ b/src/module/sdk/Gpg.h @@ -0,0 +1,29 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once
\ No newline at end of file diff --git a/src/module/sdk/GpgFrontendModuleSDK.h b/src/module/sdk/GpgFrontendModuleSDK.h new file mode 100644 index 00000000..97769462 --- /dev/null +++ b/src/module/sdk/GpgFrontendModuleSDK.h @@ -0,0 +1,33 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include <core/module/GpgFrontendModuleSystem.h> +#include <module/sdk/GpgFrontendModuleSDKExport.h> +#include <module/sdk/Log.h>
\ No newline at end of file diff --git a/src/module/sdk/GpgFrontendModuleSDKExport.h b/src/module/sdk/GpgFrontendModuleSDKExport.h new file mode 100644 index 00000000..a62168bc --- /dev/null +++ b/src/module/sdk/GpgFrontendModuleSDKExport.h @@ -0,0 +1,42 @@ + +#ifndef GPGFRONTEND_MODULE_SDK_EXPORT_H +#define GPGFRONTEND_MODULE_SDK_EXPORT_H + +#ifdef GPGFRONTEND_MODULE_SDK_STATIC_DEFINE +# define GPGFRONTEND_MODULE_SDK_EXPORT +# define GPGFRONTEND_MODULE_SDK_NO_EXPORT +#else +# ifndef GPGFRONTEND_MODULE_SDK_EXPORT +# ifdef gpgfrontend_module_sdk_EXPORTS + /* We are building this library */ +# define GPGFRONTEND_MODULE_SDK_EXPORT __attribute__((visibility("default"))) +# else + /* We are using this library */ +# define GPGFRONTEND_MODULE_SDK_EXPORT __attribute__((visibility("default"))) +# endif +# endif + +# ifndef GPGFRONTEND_MODULE_SDK_NO_EXPORT +# define GPGFRONTEND_MODULE_SDK_NO_EXPORT __attribute__((visibility("hidden"))) +# endif +#endif + +#ifndef GPGFRONTEND_MODULE_SDK_DEPRECATED +# define GPGFRONTEND_MODULE_SDK_DEPRECATED __attribute__ ((__deprecated__)) +#endif + +#ifndef GPGFRONTEND_MODULE_SDK_DEPRECATED_EXPORT +# define GPGFRONTEND_MODULE_SDK_DEPRECATED_EXPORT GPGFRONTEND_MODULE_SDK_EXPORT GPGFRONTEND_MODULE_SDK_DEPRECATED +#endif + +#ifndef GPGFRONTEND_MODULE_SDK_DEPRECATED_NO_EXPORT +# define GPGFRONTEND_MODULE_SDK_DEPRECATED_NO_EXPORT GPGFRONTEND_MODULE_SDK_NO_EXPORT GPGFRONTEND_MODULE_SDK_DEPRECATED +#endif + +#if 0 /* DEFINE_NO_DEPRECATED */ +# ifndef GPGFRONTEND_MODULE_SDK_NO_DEPRECATED +# define GPGFRONTEND_MODULE_SDK_NO_DEPRECATED +# endif +#endif + +#endif /* GPGFRONTEND_MODULE_SDK_EXPORT_H */ diff --git a/src/module/sdk/Log.cpp b/src/module/sdk/Log.cpp new file mode 100644 index 00000000..384fac1d --- /dev/null +++ b/src/module/sdk/Log.cpp @@ -0,0 +1,36 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "Log.h" + + +#include <stdexcept> + +#include "core/function/GlobalSettingStation.h" + +namespace GpgFrontend::Module::SDK {} // namespace GpgFrontend::Module::SDK diff --git a/src/module/sdk/Log.h b/src/module/sdk/Log.h new file mode 100644 index 00000000..0c40a097 --- /dev/null +++ b/src/module/sdk/Log.h @@ -0,0 +1,71 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include "core/utils/LogUtils.h" +#include "module/sdk/GpgFrontendModuleSDK.h" + +#define MODULE_LOG_TRACE(...) GF_LOG_TRACE("module", __VA_ARGS__) +#define MODULE_LOG_DEBUG(...) GF_LOG_DEBUG("module", __VA_ARGS__) +#define MODULE_LOG_INFO(...) GF_LOG_INFO("module", __VA_ARGS__) +#define MODULE_LOG_WARN(...) GF_LOG_WARN("module", __VA_ARGS__) +#define MODULE_LOG_ERROR(...) GF_LOG_ERROR("module", __VA_ARGS__) + +namespace spdlog { +class logger; +} + +namespace GpgFrontend::Module::SDK { + +template <typename... Args> +void ModuleLogTrace(const char* fmt, const Args&... args) { + MODULE_LOG_TRACE(fmt, args...); +} + +template <typename... Args> +void ModuleLogDebug(const char* fmt, const Args&... args) { + MODULE_LOG_DEBUG(fmt, args...); +} + +template <typename... Args> +void ModuleLogInfo(const char* fmt, const Args&... args) { + MODULE_LOG_INFO(fmt, args...); +} + +template <typename... Args> +void ModuleLogWarn(const char* fmt, const Args&... args) { + MODULE_LOG_WARN(fmt, args...); +} + +template <typename... Args> +void ModuleLogError(const char* fmt, const Args&... args) { + MODULE_LOG_ERROR(fmt, args...); +} + +} // namespace GpgFrontend::Module::SDK diff --git a/src/module/sdk/UI.cpp b/src/module/sdk/UI.cpp new file mode 100644 index 00000000..63859763 --- /dev/null +++ b/src/module/sdk/UI.cpp @@ -0,0 +1,27 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */
\ No newline at end of file diff --git a/src/module/sdk/UI.h b/src/module/sdk/UI.h new file mode 100644 index 00000000..0702632a --- /dev/null +++ b/src/module/sdk/UI.h @@ -0,0 +1,29 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * 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 <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once
\ No newline at end of file |