aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp170
1 files changed, 29 insertions, 141 deletions
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);
}