From 0a1c1250dd988effc07dc356741863c78af2a675 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Tue, 27 Feb 2018 23:07:14 +0100 Subject: [PATCH] logic: removed license options from commandline API, accept EULA via commandline if necessary --- src/app/main.cpp | 60 ++++++----- .../utility/commandline/CommandlineHelper.cpp | 21 +--- .../utility/commandline/CommandlineHelper.h | 9 +- .../commands/CommandlineCommandConfig.cpp | 101 +++++------------- 4 files changed, 65 insertions(+), 126 deletions(-) diff --git a/src/app/main.cpp b/src/app/main.cpp index edfb85ca..9bb58cf0 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -7,7 +7,6 @@ #include "data/indexer/IndexerFactoryModuleJava.h" #include "data/indexer/IndexerFactoryModuleCxxCdb.h" #include "data/indexer/IndexerFactoryModuleCxxEmpty.h" -#include "LicenseChecker.h" #include "project/SourceGroupFactory.h" #include "project/SourceGroupFactoryModuleCxx.h" #include "project/SourceGroupFactoryModuleJava.h" @@ -16,6 +15,7 @@ #include "qt/QtCoreApplication.h" #include "qt/utility/utilityQt.h" #include "qt/view/QtViewFactory.h" +#include "qt/window/QtEulaWindow.h" #include "settings/ApplicationSettings.h" #include "utility/commandline/CommandLineParser.h" #include "utility/logging/ConsoleLogger.h" @@ -27,6 +27,7 @@ #include "utility/messaging/type/MessageStatus.h" #include "utility/ResourcePaths.h" #include "utility/ScopedFunctor.h" +#include "utility/text/TextAccess.h" #include "utility/UserPaths.h" #include "utility/utility.h" #include "utility/utilityApp.h" @@ -128,7 +129,8 @@ void prefillCxxHeaderPaths() std::vector paths = cxxHeaderDetector->getPaths(); if (!paths.empty()) { - MessageStatus(L"Ran C/C++ header path detection, found " + std::to_wstring(paths.size()) + L" path" + (paths.size() == 1 ? L"" : L"s")).dispatch(); + MessageStatus(L"Ran C/C++ header path detection, found " + std::to_wstring(paths.size()) + L" path" + + (paths.size() == 1 ? L"" : L"s")).dispatch(); settings->setHeaderSearchPaths(paths); settings->save(); @@ -145,7 +147,8 @@ void prefillCxxFrameworkPaths() std::vector paths = cxxFrameworkDetector->getPaths(); if (!paths.empty()) { - MessageStatus(L"Ran C/C++ framework path detection, found " + std::to_wstring(paths.size()) + L" path" + (paths.size() == 1 ? L"" : L"s")).dispatch(); + MessageStatus(L"Ran C/C++ framework path detection, found " + std::to_wstring(paths.size()) + L" path" + + (paths.size() == 1 ? L"" : L"s")).dispatch(); settings->setFrameworkSearchPaths(paths); settings->save(); @@ -235,42 +238,49 @@ int main(int argc, char *argv[]) Application::destroyInstance(); }); + // check if already agreed to EULA + ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); + if (appSettings->getAcceptedEulaVersion() < QtEulaWindow::EULA_VERSION) + { + // to avoid interferring with other console output + std::this_thread::sleep_for(std::chrono::milliseconds(250)); + + std::shared_ptr text = + TextAccess::createFromFile(ResourcePaths::getGuiPath().concatenate(L"installer/EULA.txt")); + + std::cout << std::endl << text->getText() << std::endl; + std::cout << "Do you accept the Sourcetrail Software License Agreement? (y/n)" << std::endl; + + char c = 'n'; + std::cin >> c; + + if (c == 'Y' || c == 'y') + { + std::cout << "\nAgreement accepted.\n" << std::endl; + appSettings->setAcceptedEulaVersion(QtEulaWindow::EULA_VERSION); + appSettings->save(); + } + else + { + std::cout << "\nAgreement not accepted. quitting..." << std::endl; + return 1; + } + } + prefillPaths(); addLanguageModules(); - std::shared_ptr checker = LicenseChecker::getInstance(); - signal(SIGINT, signalHandler); signal(SIGTERM, signalHandler); signal(SIGABRT, signalHandler); commandLineParser.parse(); - if (commandLineParser.startedWithLicense()) - { - utility::saveLicense(commandLineParser.getLicensePtr()); - } if (commandLineParser.exitApplication()) { return 0; } - if (!checker->isCurrentLicenseValid() && !ApplicationSettings::getInstance()->getNonCommercialUse()) - { - std::string appName = argc > 0 && std::string(argv[0]).size() ? argv[0] : "sourcetrail"; - - std::cout << "\nERROR: No valid license option selected.\n\n"; - std::cout << "For commercial use please run:\n\n"; - std::cout << "\t" << appName << " config --license-string \n"; - std::cout << "or\n"; - std::cout << "\t" << appName << " config --license-file \n\n\n"; - std::cout << "For non-commercial use please run:\n\n"; - std::cout << "\t" << appName << " config --non-commercial-use true\n" << std::endl; - - LOG_WARNING("Your current Sourcetrail license seems to be invalid. Please update your license info."); - return 0; - } - if (commandLineParser.hasError() ) { std::wcout << commandLineParser.getError() << std::endl; diff --git a/src/lib/utility/commandline/CommandlineHelper.cpp b/src/lib/utility/commandline/CommandlineHelper.cpp index 2797cc99..2459a5f3 100644 --- a/src/lib/utility/commandline/CommandlineHelper.cpp +++ b/src/lib/utility/commandline/CommandlineHelper.cpp @@ -6,12 +6,9 @@ #include "boost/program_options.hpp" -namespace po = boost::program_options; - namespace commandline { -void parseConfigFile(po::variables_map& vm, - po::options_description& options) +void parseConfigFile(po::variables_map& vm, po::options_description& options) { if (vm.count("config-file")) { @@ -20,9 +17,7 @@ void parseConfigFile(po::variables_map& vm, if (!ifs) { - std::cout << "Could not open config file( " - << configFile << ")" - << std::endl; + std::cout << "Could not open config file( " << configFile << ")" << std::endl; } else { @@ -31,18 +26,6 @@ void parseConfigFile(po::variables_map& vm, } } -void conflicting_options(const boost::program_options::variables_map& vm, - const char* opt1, const char* opt2) -{ - if (vm.count(opt1) && !vm[opt1].defaulted() - && vm.count(opt2) && !vm[opt2].defaulted()) - { - std::cout << "Options " << opt1 - << " and " << opt2 - << " are conflicted." << std::endl; - } -} - std::vector extractPaths(const std::vector& vector) { std::vector v; diff --git a/src/lib/utility/commandline/CommandlineHelper.h b/src/lib/utility/commandline/CommandlineHelper.h index 679938ab..6b2ee65a 100644 --- a/src/lib/utility/commandline/CommandlineHelper.h +++ b/src/lib/utility/commandline/CommandlineHelper.h @@ -14,6 +14,8 @@ namespace program_options { } } +namespace po = boost::program_options; + namespace commandline { enum class ReturnStatus { @@ -22,14 +24,9 @@ namespace commandline CMD_FAILURE }; - void parseConfigFile(boost::program_options::variables_map& vm, - boost::program_options::options_description& options); - - void conflicting_options(const boost::program_options::variables_map& vm, - const char* opt1, const char* opt2); + void parseConfigFile(po::variables_map& vm, po::options_description& options); std::vector extractPaths(const std::vector& vector); - } #endif // COMMANDLINE_HELPER_H diff --git a/src/lib/utility/commandline/commands/CommandlineCommandConfig.cpp b/src/lib/utility/commandline/commands/CommandlineCommandConfig.cpp index a91b4a62..081f397d 100644 --- a/src/lib/utility/commandline/commands/CommandlineCommandConfig.cpp +++ b/src/lib/utility/commandline/commands/CommandlineCommandConfig.cpp @@ -3,28 +3,23 @@ #include #include - #include "boost/program_options.hpp" -#include "utility/UserPaths.h" #include "utility/commandline/CommandlineHelper.h" #include "utility/commandline/CommandLineParser.h" #include "utility/file/FilePath.h" -#include "settings/ApplicationSettings.h" -#include "PublicKey.h" -#include "utility/AppPath.h" -namespace po = boost::program_options; +#include "settings/ApplicationSettings.h" namespace commandline { // helper functions typedef void(ApplicationSettings::*intFunc)(int); void parseAndSetValue( - intFunc f, - const char* opt, - ApplicationSettings* settings, - po::variables_map& vm) + intFunc f, + const char* opt, + ApplicationSettings* settings, + po::variables_map& vm) { if (vm.count(opt)) { @@ -34,10 +29,10 @@ void parseAndSetValue( typedef void(ApplicationSettings::*boolFunc)(bool); void parseAndSetValue( - boolFunc f, - const char* opt, - ApplicationSettings* settings, - po::variables_map& vm) + boolFunc f, + const char* opt, + ApplicationSettings* settings, + po::variables_map& vm) { if (vm.count(opt)) { @@ -47,10 +42,10 @@ void parseAndSetValue( typedef void(ApplicationSettings::*filePathFunc)(const FilePath&); void parseAndSetValue( - filePathFunc f, - const char* opt, - ApplicationSettings* settings, - po::variables_map& vm) + filePathFunc f, + const char* opt, + ApplicationSettings* settings, + po::variables_map& vm) { if (vm.count(opt)) { @@ -66,10 +61,10 @@ void parseAndSetValue( typedef bool(ApplicationSettings::*vectorFunc)(const std::vector&); void parseAndSetValue( - vectorFunc f, - const char* opt, - ApplicationSettings* settings, - po::variables_map& vm) + vectorFunc f, + const char* opt, + ApplicationSettings* settings, + po::variables_map& vm) { if (vm.count(opt)) { @@ -96,22 +91,21 @@ void CommandConfig::setup() ("use-processes,p", po::value(), "Enable C/C++ Indexer threads to run in different processes. ") ("logging-enabled,l", po::value(), "Enable file/console logging ") ("verbose-indexer-logging-enabled,L", po::value(), - "Enable additional log of abstract syntax tree during the indexing. WARNINIG Slows down indexing speed") + "Enable additional log of abstract syntax tree during the indexing. WARNINIG Slows down " + "indexing speed") ("jvm-path,j", po::value(), "Path to the location of the jvm library") ("jvm-max-memory,M", po::value(), - "Set the maximum amount of memory for the JVM indexer(-1 for using the JVM default settings)") + "Set the maximum amount of memory for the JVM indexer(-1 for using the JVM default settings)") ("maven-path,m", po::value(), "Path to the maven binary") ("jre-system-library-paths,J", po::value>(), - "paths to the jars of the JRE system library. " - "These jars can be found inside your JRE install directory (once per path or comma separated)") - ("license-file,z", po::value(), "Enter license via Licensefile") - ("license-string,Z", po::value(), "Enter licenes via commandline") + "paths to the jars of the JRE system library. " + "These jars can be found inside your JRE install directory (once per path or comma separated)") ("global-header-search-paths,g", po::value>(), - "Global include paths (once per path or comma separated)") + "Global include paths (once per path or comma separated)") ("global-framework-search-paths,F", po::value>(), - "Global include paths (once per path or comma separated)") + "Global include paths (once per path or comma separated)") ("show,s", "displays all settings") - ("non-commercial-use", po::value(), "Enable non-commercial use. "); + ; m_options.add(options); } @@ -202,51 +196,6 @@ ReturnStatus CommandConfig::parse(std::vector& args) parseAndSetValue(&ApplicationSettings::setHeaderSearchPaths, "global-header-search-paths", settings, vm); parseAndSetValue(&ApplicationSettings::setFrameworkSearchPaths, "global-framework-search-paths", settings, vm); - parseAndSetValue(&ApplicationSettings::setNonCommercialUse, "non-commercial-use", settings, vm); - - // license - if (vm.count("license-string") || vm.count("license-file") ) - { - bool licenseLoaded = false; - if (vm.count("license-string")) - { - std::string licensetext = utility::replace(vm["license-string"].as(), "\\n", "\n"); - licenseLoaded = m_parser->getLicensePtr()->loadFromString(licensetext); - } - - if (vm.count("license-file")) - { - const std::string licensefile = vm["license-file"].as(); - if (FilePath(licensefile).exists()) - { - std::cout << "Load license from file" << std::endl; - licenseLoaded = m_parser->getLicensePtr()->loadFromFile(licensefile); - } - else - { - std::cout << licensefile << " not found" << std::endl; - } - } - - if (licenseLoaded) - { - if (!m_parser->getLicensePtr()->isValid()) - { - std::cout << "License is not valid" << std::endl; - return ReturnStatus::CMD_FAILURE; - } - else - { - std::cout << "License is valid" << std::endl; - } - } - else - { - std::cout << "Could not load License" << std::endl; - return ReturnStatus::CMD_FAILURE; - } - } - settings->save(); return ReturnStatus::CMD_QUIT;