#include "./cli/cli.h" #ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #include "./gui/initiategui.h" #endif #ifdef PASSWORD_MANAGER_GUI_QTQUICK #include "./quickgui/initiatequick.h" #endif #include "resources/config.h" #include #include #include #include #if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_GUI_QTQUICK) #include #include ENABLE_QT_RESOURCES_OF_STATIC_DEPENDENCIES #else #include #endif #include using namespace std; using namespace ApplicationUtilities; using namespace Util; int main(int argc, char *argv[]) { // setup argument parser SET_APPLICATION_INFO; ArgumentParser parser; // file argument Argument fileArg("file", 'f', "specifies the file to be opened (or created when using --modify)"); fileArg.setValueNames({ "path" }); fileArg.setRequiredValueCount(1); fileArg.setCombinable(true); fileArg.setRequired(false); fileArg.setImplicit(true); // Qt configuration arguments QT_CONFIG_ARGUMENTS qtConfigArgs; qtConfigArgs.qtWidgetsGuiArg().addSubArgument(&fileArg); qtConfigArgs.qtQuickGuiArg().addSubArgument(&fileArg); // cli argument Argument cliArg("interactive-cli", 'i', "starts the interactive command line interface"); cliArg.setDenotesOperation(true); cliArg.setSubArguments({ &fileArg }); // help argument HelpArgument helpArg(parser); parser.setMainArguments({ &qtConfigArgs.qtWidgetsGuiArg(), &qtConfigArgs.qtQuickGuiArg(), &cliArg, &helpArg }); // holds the application's return code int res = 0; // parse the specified arguments parser.parseArgsOrExit(argc, argv); // init open ssl OpenSsl::init(); // start either interactive CLI or GUI if (cliArg.isPresent()) { Cli::InteractiveCli cli; if (fileArg.isPresent()) { cli.run(fileArg.firstValue()); } else { cli.run(); } } else if (qtConfigArgs.areQtGuiArgsPresent()) { // run Qt gui if no arguments, --qt-gui or --qt-quick-gui specified, a file might be specified #if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_GUI_QTQUICK) const auto file(fileArg.isPresent() ? QString::fromLocal8Bit(fileArg.firstValue()) : QString()); #endif if (qtConfigArgs.qtWidgetsGuiArg().isPresent()) { #ifdef PASSWORD_MANAGER_GUI_QTWIDGETS res = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file); #else CMD_UTILS_START_CONSOLE; cerr << "The application has not been built with Qt widgets support." << endl; #endif } else if (qtConfigArgs.qtQuickGuiArg().isPresent()) { #ifdef PASSWORD_MANAGER_GUI_QTQUICK res = QtGui::runQuickGui(argc, argv, qtConfigArgs, file); #else CMD_UTILS_START_CONSOLE; cerr << "The application has not been built with Qt quick support." << endl; #endif } else { #if defined(PASSWORD_MANAGER_GUI_QTQUICK) res = QtGui::runQuickGui(argc, argv, qtConfigArgs, file); #elif defined(PASSWORD_MANAGER_GUI_QTWIDGETS) res = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file); #else CMD_UTILS_START_CONSOLE; cerr << "See --help for usage." << endl; #endif } } // clean open ssl OpenSsl::clean(); return res; }