aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2023-11-29 12:45:48 +0000
committersaturneric <[email protected]>2023-11-29 12:45:48 +0000
commit635a6c16e982ba2a5c7bea28eb31ee235df158c2 (patch)
tree39561f439fdac98b813b671edabdc43f166b642d
parentfix: repair gnupg info listing funtion (diff)
downloadGpgFrontend-635a6c16e982ba2a5c7bea28eb31ee235df158c2.tar.gz
GpgFrontend-635a6c16e982ba2a5c7bea28eb31ee235df158c2.zip
feat: introduce cmd functions
Diffstat (limited to '')
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/app.cpp144
-rw-r--r--src/app.h33
-rw-r--r--src/before_exit.cpp4
-rw-r--r--src/cmd.cpp73
-rw-r--r--src/cmd.h39
-rw-r--r--src/core/GpgCoreInit.cpp9
-rw-r--r--src/core/GpgCoreInit.h3
-rw-r--r--src/init.cpp50
-rw-r--r--src/init.h62
-rw-r--r--src/main.cpp170
-rw-r--r--src/module/GpgFrontendModuleInit.cpp4
-rw-r--r--src/module/GpgFrontendModuleInit.h6
-rw-r--r--src/module/sdk/Log.cpp9
-rw-r--r--src/module/sdk/Log.h6
-rw-r--r--src/signal.cpp2
-rw-r--r--src/type.h35
-rw-r--r--src/ui/GpgFrontendUIInit.cpp16
-rw-r--r--src/ui/GpgFrontendUIInit.h4
19 files changed, 485 insertions, 188 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1cbe04c0..88ec8148 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -26,10 +26,10 @@
# Introduce boost
if(NOT BOOST_ROOT)
- find_package(Boost COMPONENTS date_time system REQUIRED)
+ find_package(Boost COMPONENTS date_time system program_options REQUIRED)
else()
find_package(Boost
- COMPONENTS date_time system REQUIRED
+ COMPONENTS date_time system program_options REQUIRED
PATHS ${BOOST_ROOT} NO_DEFAULT_PATH)
endif()
diff --git a/src/app.cpp b/src/app.cpp
new file mode 100644
index 00000000..71e3fd7b
--- /dev/null
+++ b/src/app.cpp
@@ -0,0 +1,144 @@
+/**
+ * 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 <csetjmp>
+#include <csignal>
+
+#include "core/GpgConstants.h"
+#include "core/GpgCoreInit.h"
+#include "core/function/GlobalSettingStation.h"
+#include "module/GpgFrontendModuleInit.h"
+#include "ui/GpgFrontendApplication.h"
+#include "ui/GpgFrontendUIInit.h"
+
+// main
+#include "init.h"
+#include "type.h"
+
+/**
+ * \brief Store the jump buff and make it possible to recover from a crash.
+ */
+#ifdef FREEBSD
+sigjmp_buf recover_env;
+#else
+jmp_buf recover_env;
+#endif
+
+constexpr int kCrashCode = ~0; ///<
+
+/**
+ * @brief
+ *
+ * @param argc
+ * @param argv
+ * @return int
+ */
+auto StartApplication(InitArgs args) -> int {
+ SPDLOG_INFO("start running application");
+
+#ifdef RELEASE
+ // re
+ signal(SIGSEGV, HandleSignal);
+ signal(SIGFPE, HandleSignal);
+ signal(SIGILL, HandleSignal);
+#endif
+
+ // clean something before exit
+ atexit(BeforeExit);
+
+ // initialize qt resources
+ Q_INIT_RESOURCE(gpgfrontend);
+
+ // create qt application
+ auto* app = GpgFrontend::UI::GpgFrontendApplication::GetInstance(
+ args.argc, args.argv, true);
+
+ // init the logging system for main
+ InitModules(args);
+
+ // change path to search for related
+ InitGlobalPathEnv();
+
+ /**
+ * internationalisation. loop to restart main window
+ * with changed translation when settings change.
+ */
+ int return_from_event_loop_code;
+ int restart_count = 0;
+
+ do {
+#ifndef WINDOWS
+ int r = sigsetjmp(recover_env, 1);
+#else
+ int r = setjmp(recover_env);
+#endif
+ if (!r) {
+ // init ui library
+ GpgFrontend::UI::InitGpgFrontendUI(app);
+
+ // create main window
+ return_from_event_loop_code = GpgFrontend::UI::RunGpgFrontendUI(app);
+ } else {
+ SPDLOG_ERROR("recover from a crash");
+ // when signal is caught, restart the main window
+ auto* message_box = new QMessageBox(
+ QMessageBox::Critical, _("A serious error has occurred"),
+ _("Oh no! GpgFrontend caught a serious error in the software, so "
+ "it needs to be restarted. If the problem recurs, please "
+ "manually terminate the program and report the problem to the "
+ "developer."),
+ QMessageBox::Ok, nullptr);
+ message_box->exec();
+ return_from_event_loop_code = kCrashCode;
+ }
+
+ restart_count++;
+
+ SPDLOG_DEBUG("restart loop refresh, event loop code: {}, restart count: {}",
+ return_from_event_loop_code, restart_count);
+ } while (return_from_event_loop_code == GpgFrontend::kRestartCode &&
+ restart_count < 3);
+
+ // log for debug
+ SPDLOG_INFO("GpgFrontend is about to exit.");
+
+ // deep restart mode
+ if (return_from_event_loop_code == GpgFrontend::kRestartCode ||
+ return_from_event_loop_code == kCrashCode) {
+ // log for debug
+ SPDLOG_DEBUG(
+ "deep restart or cash loop status caught, restart a new application");
+ QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
+ };
+
+ // close logging system
+ ShutdownModules();
+
+ // exit the program
+ return return_from_event_loop_code;
+}
diff --git a/src/app.h b/src/app.h
new file mode 100644
index 00000000..ce357083
--- /dev/null
+++ b/src/app.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 "init.h"
+
+auto StartApplication(InitArgs args) -> int;
diff --git a/src/before_exit.cpp b/src/before_exit.cpp
index 759093d0..e5e4ed63 100644
--- a/src/before_exit.cpp
+++ b/src/before_exit.cpp
@@ -32,6 +32,4 @@
* @brief Actions performed before exiting the application
*
*/
-void before_exit() {
-
-}
+void BeforeExit() {}
diff --git a/src/cmd.cpp b/src/cmd.cpp
new file mode 100644
index 00000000..66e2604f
--- /dev/null
+++ b/src/cmd.cpp
@@ -0,0 +1,73 @@
+/**
+ * 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 "cmd.h"
+
+// std
+#include <iostream>
+
+// boost
+#include <boost/program_options.hpp>
+
+// GpgFrontend
+#include "GpgFrontendBuildInfo.h"
+
+namespace po = boost::program_options;
+
+auto PrintVersion() -> int {
+ std::cout << PROJECT_NAME << " "
+ << "v" << VERSION_MAJOR << "." << VERSION_MINOR << "."
+ << VERSION_PATCH << std::endl;
+ std::cout
+ << "Copyright (C) 2021 Saturneric <[email protected]>" << std::endl
+ << _("This is free software; see the source for copying conditions.")
+ << std::endl
+ << std::endl;
+
+ std::cout << _("Build Timestamp: ") << BUILD_TIMESTAMP << std::endl
+ << _("Build Version: ") << BUILD_VERSION << std::endl
+ << _("Source Code Version: ") << GIT_VERSION << std::endl;
+
+ return 0;
+}
+
+auto ParseLogLevel(const po::variables_map& vm) -> spdlog::level::level_enum {
+ std::string log_level = vm["log-level"].as<std::string>();
+
+ if (log_level == "trace") {
+ return spdlog::level::trace;
+ } else if (log_level == "debug") {
+ return spdlog::level::debug;
+ } else if (log_level == "info") {
+ return spdlog::level::info;
+ } else if (log_level == "warn") {
+ return spdlog::level::warn;
+ } else if (log_level == "error") {
+ return spdlog::level::err;
+ }
+} \ No newline at end of file
diff --git a/src/cmd.h b/src/cmd.h
new file mode 100644
index 00000000..62d123e2
--- /dev/null
+++ b/src/cmd.h
@@ -0,0 +1,39 @@
+/**
+ * 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
+
+// boost
+#include <boost/program_options.hpp>
+
+// functions
+
+auto PrintVersion() -> int;
+
+auto ParseLogLevel(const boost::program_options::variables_map&)
+ -> spdlog::level::level_enum; \ No newline at end of file
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp
index cbf07b62..97f9f68a 100644
--- a/src/core/GpgCoreInit.cpp
+++ b/src/core/GpgCoreInit.cpp
@@ -49,7 +49,7 @@ namespace GpgFrontend {
* @brief setup logging system and do proper initialization
*
*/
-void InitCoreLoggingSystem() {
+void InitCoreLoggingSystem(spdlog::level::level_enum level) {
// get the log directory
auto logfile_path =
(GlobalSettingStation::GetInstance().GetLogDir() / "core");
@@ -70,11 +70,8 @@ void InitCoreLoggingSystem() {
core_logger->set_pattern(
"[%H:%M:%S.%e] [T:%t] [%=6n] %^[%=8l]%$ [%s:%#] [%!] -> %v (+%ius)");
-#ifdef DEBUG
- core_logger->set_level(spdlog::level::trace);
-#else
- core_logger->set_level(spdlog::level::info);
-#endif
+ // set the level of logger
+ core_logger->set_level(level);
// flush policy
#ifdef DEBUG
diff --git a/src/core/GpgCoreInit.h b/src/core/GpgCoreInit.h
index b249548d..910e0562 100644
--- a/src/core/GpgCoreInit.h
+++ b/src/core/GpgCoreInit.h
@@ -36,7 +36,8 @@ namespace GpgFrontend {
* @brief
*
*/
-void GPGFRONTEND_CORE_EXPORT InitCoreLoggingSystem();
+void GPGFRONTEND_CORE_EXPORT
+InitCoreLoggingSystem(spdlog::level::level_enum level);
/**
* @brief
diff --git a/src/init.cpp b/src/init.cpp
index 8cbdd034..ad07425c 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -26,6 +26,8 @@
*
*/
+#include "init.h"
+
#include <spdlog/async.h>
#include <spdlog/common.h>
#include <spdlog/sinks/rotating_file_sink.h>
@@ -37,7 +39,13 @@
#include "GpgFrontend.h"
#include "GpgFrontendBuildInfo.h"
+#include "core/GpgCoreInit.h"
#include "core/function/GlobalSettingStation.h"
+#include "module/GpgFrontendModuleInit.h"
+#include "ui/GpgFrontendUIInit.h"
+
+// main
+#include "type.h"
#ifdef WINDOWS
int setenv(const char *name, const char *value, int overwrite) {
@@ -51,10 +59,7 @@ int setenv(const char *name, const char *value, int overwrite) {
}
#endif
-void init_logging_system() {
- using namespace boost::posix_time;
- using namespace boost::gregorian;
-
+void InitMainLoggingSystem(spdlog::level::level_enum level) {
// sinks
std::vector<spdlog::sink_ptr> sinks;
sinks.push_back(std::make_shared<spdlog::sinks::stderr_color_sink_mt>());
@@ -68,11 +73,8 @@ void init_logging_system() {
main_logger->set_pattern(
"[%H:%M:%S.%e] [T:%t] [%=6n] %^[%=8l]%$ [%s:%#] [%!] -> %v (+%ius)");
-#ifdef DEBUG
- main_logger->set_level(spdlog::level::trace);
-#else
- main_logger->set_level(spdlog::level::info);
-#endif
+ // set the level of logger
+ main_logger->set_level(level);
// flush policy
main_logger->flush_on(spdlog::level::err);
@@ -82,7 +84,33 @@ void init_logging_system() {
spdlog::set_default_logger(main_logger);
}
-void shutdown_logging_system() {
+void InitModules(InitArgs args) {
+ // init the logging system for main
+ InitMainLoggingSystem(args.log_level);
+
+ // init the logging system for core
+ GpgFrontend::InitCoreLoggingSystem(args.log_level);
+
+ // init the logging system for ui
+ GpgFrontend::UI::InitUILoggingSystem(args.log_level);
+
+ // init the logging system for modules
+ GpgFrontend::Module::ModuleInitArgs module_init_args;
+ module_init_args.log_level = args.log_level;
+ //
+ GpgFrontend::Module::LoadGpgFrontendModules(module_init_args);
+}
+
+void ShutdownModules() {
+ // shutdown the logging system for core
+ GpgFrontend::Module::ShutdownGpgFrontendModules();
+
+ // shutdown the logging system for ui
+ GpgFrontend::UI::ShutdownUILoggingSystem();
+
+ // shutdown the logging system for core
+ GpgFrontend::ShutdownCoreLoggingSystem();
+
#ifdef WINDOWS
// Under VisualStudio, this must be called before main finishes to workaround
// a known VS issue
@@ -91,7 +119,7 @@ void shutdown_logging_system() {
#endif
}
-void init_global_path_env() {
+void InitGlobalPathEnv() {
// read settings
bool use_custom_gnupg_install_path =
GpgFrontend::GlobalSettingStation::GetInstance().LookupSettings(
diff --git a/src/init.h b/src/init.h
new file mode 100644
index 00000000..cc8e2200
--- /dev/null
+++ b/src/init.h
@@ -0,0 +1,62 @@
+/**
+ * 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
+
+struct InitArgs;
+
+/**
+ * @brief handle the signal SIGSEGV
+ *
+ * @param sig
+ */
+void HandleSignal(int sig);
+
+/**
+ * @brief processes before exit the program.
+ *
+ */
+void BeforeExit();
+
+/**
+ * @brief initialize the logging system.
+ *
+ */
+void InitModules(InitArgs);
+
+/**
+ * @brief initialize the logging system.
+ *
+ */
+void ShutdownModules();
+
+/**
+ * @brief init global PATH env
+ *
+ */
+void InitGlobalPathEnv();
diff --git a/src/main.cpp b/src/main.cpp
index 53b80944..260f6200 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -30,60 +30,16 @@
* \mainpage GpgFrontend Develop Document Main Page
*/
-#include <csetjmp>
-#include <csignal>
#include <cstddef>
#include <cstdlib>
+#include <iostream>
#include <string>
-#include "core/GpgConstants.h"
-#include "core/GpgCoreInit.h"
-#include "core/function/GlobalSettingStation.h"
-#include "module/GpgFrontendModuleInit.h"
-#include "ui/GpgFrontendApplication.h"
-#include "ui/GpgFrontendUIInit.h"
+#include "app.h"
+#include "cmd.h"
+#include "type.h"
-/**
- * \brief Store the jump buff and make it possible to recover from a crash.
- */
-#ifdef FREEBSD
-sigjmp_buf recover_env;
-#else
-jmp_buf recover_env;
-#endif
-
-constexpr int CRASH_CODE = ~0; ///<
-
-/**
- * @brief handle the signal SIGSEGV
- *
- * @param sig
- */
-extern void handle_signal(int sig);
-
-/**
- * @brief processes before exit the program.
- *
- */
-extern void before_exit();
-
-/**
- * @brief initialize the logging system.
- *
- */
-extern void init_logging_system();
-
-/**
- * @brief initialize the logging system.
- *
- */
-extern void shutdown_logging_system();
-
-/**
- * @brief init global PATH env
- *
- */
-extern void init_global_path_env();
+namespace po = boost::program_options;
/**
*
@@ -91,103 +47,35 @@ extern void init_global_path_env();
* @param argv
* @return
*/
-int main(int argc, char* argv[]) {
-#ifdef RELEASE
- // re
- signal(SIGSEGV, handle_signal);
- signal(SIGFPE, handle_signal);
- signal(SIGILL, handle_signal);
-#endif
-
- // clean something before exit
- atexit(before_exit);
-
- // initialize qt resources
- Q_INIT_RESOURCE(gpgfrontend);
-
- // create qt application
- auto* app =
- GpgFrontend::UI::GpgFrontendApplication::GetInstance(argc, argv, true);
-
- // init the logging system for main
- init_logging_system();
-
- // init the logging system for core
- GpgFrontend::InitCoreLoggingSystem();
-
- // init the logging system for ui
- GpgFrontend::UI::InitUILoggingSystem();
-
- // init the logging system for ui
- GpgFrontend::Module::LoadGpgFrontendModules();
-
- // change path to search for related
- init_global_path_env();
-
- /**
- * internationalisation. loop to restart main window
- * with changed translation when settings change.
- */
- int return_from_event_loop_code;
- int restart_count = 0;
-
- // load integrated modules
- GpgFrontend::Module::LoadGpgFrontendModules();
-
- do {
-#ifndef WINDOWS
- int r = sigsetjmp(recover_env, 1);
-#else
- int r = setjmp(recover_env);
-#endif
- if (!r) {
- // init ui library
- GpgFrontend::UI::InitGpgFrontendUI(app);
-
- // create main window
- return_from_event_loop_code = GpgFrontend::UI::RunGpgFrontendUI(app);
- } else {
- SPDLOG_ERROR("recover from a crash");
- // when signal is caught, restart the main window
- auto* message_box = new QMessageBox(
- QMessageBox::Critical, _("A serious error has occurred"),
- _("Oh no! GpgFrontend caught a serious error in the software, so "
- "it needs to be restarted. If the problem recurs, please "
- "manually terminate the program and report the problem to the "
- "developer."),
- QMessageBox::Ok, nullptr);
- message_box->exec();
- return_from_event_loop_code = CRASH_CODE;
- }
-
- restart_count++;
+auto main(int argc, char* argv[]) -> int {
+ po::options_description desc("Allowed options");
- SPDLOG_DEBUG("restart loop refresh, event loop code: {}, restart count: {}",
- return_from_event_loop_code, restart_count);
- } while (return_from_event_loop_code == GpgFrontend::kRestartCode &&
- restart_count < 3);
+ desc.add_options()("help,h", "produce help message")(
+ "version,v", "show version information")(
+ "log-level,l", po::value<std::string>()->default_value("info"),
+ "set log level (trace, debug, info, warn, error)");
- // shutdown the logging system for core
- GpgFrontend::Module::ShutdownGpgFrontendModules();
+ po::variables_map vm;
+ po::store(po::parse_command_line(argc, argv, desc), vm);
+ po::notify(vm);
- // shutdown the logging system for ui
- GpgFrontend::UI::ShutdownUILoggingSystem();
+ InitArgs args;
+ args.argc = argc;
+ args.argv = argv;
+ args.log_level = spdlog::level::info;
- // shutdown the logging system for core
- GpgFrontend::ShutdownCoreLoggingSystem();
+ if (vm.count("help") != 0U) {
+ std::cout << desc << "\n";
+ return 0;
+ }
- // log for debug
- SPDLOG_INFO("GpgFrontend about to exit.");
+ if (vm.count("version") != 0U) {
+ return PrintVersion();
+ }
- // deep restart mode
- if (return_from_event_loop_code == GpgFrontend::kRestartCode ||
- return_from_event_loop_code == CRASH_CODE) {
- // log for debug
- SPDLOG_DEBUG(
- "deep restart or cash loop status caught, restart a new application");
- QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
- };
+ if (vm.count("log-level") != 0U) {
+ args.log_level = ParseLogLevel(vm);
+ }
- // exit the program
- return return_from_event_loop_code;
+ return StartApplication(args);
}
diff --git a/src/module/GpgFrontendModuleInit.cpp b/src/module/GpgFrontendModuleInit.cpp
index 46a57f47..367d1be1 100644
--- a/src/module/GpgFrontendModuleInit.cpp
+++ b/src/module/GpgFrontendModuleInit.cpp
@@ -37,8 +37,8 @@
namespace GpgFrontend::Module {
-void LoadGpgFrontendModules() {
- SDK::InitModuleLoggingSystem();
+void LoadGpgFrontendModules(ModuleInitArgs args) {
+ SDK::InitModuleLoggingSystem(args.log_level);
MODULE_LOG_INFO("loading integrated module...");
diff --git a/src/module/GpgFrontendModuleInit.h b/src/module/GpgFrontendModuleInit.h
index 87d7994c..252338bf 100644
--- a/src/module/GpgFrontendModuleInit.h
+++ b/src/module/GpgFrontendModuleInit.h
@@ -32,11 +32,15 @@
namespace GpgFrontend::Module {
+struct ModuleInitArgs {
+ spdlog::level::level_enum log_level;
+};
+
/**
* @brief init the module library
*
*/
-void GPGFRONTEND_MODULE_EXPORT LoadGpgFrontendModules();
+void GPGFRONTEND_MODULE_EXPORT LoadGpgFrontendModules(ModuleInitArgs);
/**
* @brief shutdown the module library
diff --git a/src/module/sdk/Log.cpp b/src/module/sdk/Log.cpp
index e225259b..1132826b 100644
--- a/src/module/sdk/Log.cpp
+++ b/src/module/sdk/Log.cpp
@@ -37,7 +37,7 @@
namespace GpgFrontend::Module::SDK {
-void InitModuleLoggingSystem() {
+void InitModuleLoggingSystem(spdlog::level::level_enum level) {
// get the log directory
auto log_file_path =
(GpgFrontend::GlobalSettingStation::GetInstance().GetLogDir() / "module");
@@ -58,11 +58,8 @@ void InitModuleLoggingSystem() {
module_logger->set_pattern(
"[%H:%M:%S.%e] [T:%t] [%=6n] %^[%=8l]%$ [%s:%#] [%!] -> %v (+%ius)");
-#ifdef DEBUG
- module_logger->set_level(spdlog::level::trace);
-#else
- module_logger->set_level(spdlog::level::info);
-#endif
+ // set the level of logger
+ module_logger->set_level(level);
// flush policy
module_logger->flush_on(spdlog::level::err);
diff --git a/src/module/sdk/Log.h b/src/module/sdk/Log.h
index bc298688..bff9893e 100644
--- a/src/module/sdk/Log.h
+++ b/src/module/sdk/Log.h
@@ -51,7 +51,8 @@ namespace GpgFrontend::Module::SDK {
* @brief
*
*/
-void GPGFRONTEND_MODULE_SDK_EXPORT InitModuleLoggingSystem();
+void GPGFRONTEND_MODULE_SDK_EXPORT
+ InitModuleLoggingSystem(spdlog::level::level_enum);
/**
* @brief
@@ -63,7 +64,8 @@ void GPGFRONTEND_MODULE_SDK_EXPORT ShutdownModuleLoggingSystem();
* @brief
*
*/
-std::shared_ptr<spdlog::logger> GPGFRONTEND_MODULE_SDK_EXPORT GetModuleLogger();
+auto GPGFRONTEND_MODULE_SDK_EXPORT GetModuleLogger()
+ -> std::shared_ptr<spdlog::logger>;
template <typename... Args>
void ModuleLogTrace(const char* fmt, const Args&... args) {
diff --git a/src/signal.cpp b/src/signal.cpp
index f6aff819..b7a9cef3 100644
--- a/src/signal.cpp
+++ b/src/signal.cpp
@@ -42,7 +42,7 @@ extern jmp_buf recover_env;
*
* @param sig signal number
*/
-void handle_signal(int sig) {
+void HandleSignal(int sig) {
static int _repeat_handle_num = 1, last_sig = sig;
// SPDLOG_DEBUG("signal caught {}", sig);
std::cout << "signal caught" << sig;
diff --git a/src/type.h b/src/type.h
new file mode 100644
index 00000000..1b98b60f
--- /dev/null
+++ b/src/type.h
@@ -0,0 +1,35 @@
+/**
+ * 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
+
+struct InitArgs {
+ int argc;
+ char **argv;
+ spdlog::level::level_enum log_level;
+}; \ No newline at end of file
diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp
index c3d6b69e..4fc3d8fa 100644
--- a/src/ui/GpgFrontendUIInit.cpp
+++ b/src/ui/GpgFrontendUIInit.cpp
@@ -50,12 +50,11 @@
namespace GpgFrontend::UI {
-extern void init_logging_system();
-extern void init_locale();
+extern void InitLocale();
void InitGpgFrontendUI(QApplication* app) {
// init locale
- init_locale();
+ InitLocale();
#if !defined(RELEASE) && defined(WINDOWS)
// css
@@ -198,7 +197,7 @@ int RunGpgFrontendUI(QApplication* app) {
return app->exec();
}
-void InitUILoggingSystem() {
+void InitUILoggingSystem(spdlog::level::level_enum level) {
using namespace boost::posix_time;
using namespace boost::gregorian;
@@ -221,11 +220,8 @@ void InitUILoggingSystem() {
ui_logger->set_pattern(
"[%H:%M:%S.%e] [T:%t] [%=6n] %^[%=8l]%$ [%s:%#] [%!] -> %v (+%ius)");
-#ifdef DEBUG
- ui_logger->set_level(spdlog::level::trace);
-#else
- ui_logger->set_level(spdlog::level::info);
-#endif
+ // set the level of logger
+ ui_logger->set_level(level);
// flush policy
ui_logger->flush_on(spdlog::level::err);
@@ -248,7 +244,7 @@ void ShutdownUILoggingSystem() {
* @brief setup the locale and load the translations
*
*/
-void init_locale() {
+void InitLocale() {
// get the instance of the GlobalSettingStation
auto& settings =
GpgFrontend::GlobalSettingStation::GetInstance().GetMainSettings();
diff --git a/src/ui/GpgFrontendUIInit.h b/src/ui/GpgFrontendUIInit.h
index 947d26e4..b14b43b9 100644
--- a/src/ui/GpgFrontendUIInit.h
+++ b/src/ui/GpgFrontendUIInit.h
@@ -42,7 +42,7 @@ void GPGFRONTEND_UI_EXPORT InitGpgFrontendUI(QApplication *);
* @brief
*
*/
-void GPGFRONTEND_UI_EXPORT InitUILoggingSystem();
+void GPGFRONTEND_UI_EXPORT InitUILoggingSystem(spdlog::level::level_enum level);
/**
* @brief
@@ -53,6 +53,6 @@ void GPGFRONTEND_UI_EXPORT ShutdownUILoggingSystem();
/**
* @brief run main window
*/
-int GPGFRONTEND_UI_EXPORT RunGpgFrontendUI(QApplication *);
+auto GPGFRONTEND_UI_EXPORT RunGpgFrontendUI(QApplication *) -> int;
}; // namespace GpgFrontend::UI