From fbfc7caab72fba7c114de37d23556040cc75409c Mon Sep 17 00:00:00 2001 From: Markus Date: Sun, 27 Oct 2019 10:55:53 +0100 Subject: [PATCH] v3.4.0 fix subfunction --remove --- parameterManager.cpp | 39 ++++++++++++++++++++++++++------------- parameterManager.h | 2 +- programManager.cpp | 39 +++++++++++++++++++++++++-------------- 3 files changed, 52 insertions(+), 28 deletions(-) diff --git a/parameterManager.cpp b/parameterManager.cpp index 6f9085d..b59199d 100644 --- a/parameterManager.cpp +++ b/parameterManager.cpp @@ -69,7 +69,7 @@ int manageParameter(Settings &settings, int argc, char **argv) return 1; } - std::vector res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean\nnews\n--update", argv[1]); + std::vector res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean\nnews\n--update\n--remove", argv[1]); if(res.size() != 1) { if(res.size() == 0) std::cout << " => Error: Keine Unteroption für " << argv[1] << " gefunden." << std::endl; @@ -121,6 +121,10 @@ int manageParameter(Settings &settings, int argc, char **argv) argv[1][0] = '\0'; return unterOption_update(&settings, argc, argv); + } else if (strncmp(argv[1], "--remove", strlen(argv[1])) == 0) { + argv[1][0] = '\0'; + return unterOption_RemoveSettings_or_CacheDir(&settings, argc, argv); + } else { std::cout << " => Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl; return 3; @@ -1322,20 +1326,17 @@ int unterOption_RemoveSettings_or_CacheDir(Settings *settings, int argc, char ** int c = 0; const option long_opts[] = { - {"", required_argument, nullptr, 'p'}, - {"help", no_argument, nullptr, 'h'}, {"debug-mode", no_argument, nullptr, 'd'}, - {nullptr, no_argument, nullptr, 0} }; - while( ( c = getopt_long (argc, argv, "p:hd", long_opts, nullptr) ) != -1 ) { + while( ( c = getopt_long (argc, argv, "hd", long_opts, nullptr) ) != -1 ) { switch(c) { case 'h': - unterOption_update_help(settings->programName); + unterOption_RemoveSettings_or_CacheDire_help(settings->programName); return -1; case 'd': settings->debugMode = true; @@ -1343,12 +1344,23 @@ int unterOption_RemoveSettings_or_CacheDir(Settings *settings, int argc, char ** std::cout << "Debug Modus: true" << std::endl; break; default: - std::cout << "Aufruf: " << settings->programName << " --update [OPTION]..." << std::endl; - std::cout << "\"" << settings->programName << " --update --help\" liefert weitere Informationen." << std::endl; + std::cout << "Aufruf: " << settings->programName << " --remove [OPTION]... [settings|cache|all]" << std::endl; + std::cout << "\"" << settings->programName << " --remove --help\" liefert weitere Informationen." << std::endl; return 21; } } + //Alle nicht verwendeten Parameter == Name + while (optind < argc) { + if(argv[optind][0]) { + settings->name.append(argv[optind++]).append(" "); + } else + ++optind; + } + if(settings->name.length() > 0) + settings->name.pop_back(); + + if(settings->debugMode) std::cout << "Modus: RemoveModus" << std::endl; @@ -1358,15 +1370,16 @@ int unterOption_RemoveSettings_or_CacheDir(Settings *settings, int argc, char ** void unterOption_RemoveSettings_or_CacheDire_help(std::string programName) { - std::cout << "Aufruf: " << programName << " --aa [OPTION]..." << std::endl << std::endl; + std::cout << "Aufruf: " << programName << " --remove [OPTION]... [settings|cache|all]" << std::endl << std::endl; std::cout << "Beschreibung:" << std::endl - << " Mit dieser Unterfunktion kann man das Programm updaten." << std::endl << std::endl; + << " Mit dieser Unterfunktion kann man die erstellten Settings/Cache" << std::endl + << " Ordner löschen." << std::endl + << " 'settings': Nur den Ordner mit den Einstellungen löschen." << std::endl + << " 'cache': Nur den Ordner mit den Zwischengespeicherten Dateien löschen." << std::endl + << " 'all': Beide Ordner löschen." << std::endl << std::endl; std::cout << "OPTIONEN:" << std::endl - << " -p [ip:port/ip/port], --socks5-proxy [ip:port/ip/port]" << std::endl - << " Mit dieser Option kann man den Socks5Proxy ändern." << std::endl - << " Standart: 127.0.0.1:9050" << std::endl << std::endl << " -d, --debug-mode" << std::endl << " Mit dieser Option kann man den Debug-Modus einschalten." << std::endl << " Dabei werden vielmehr Infos ausgegeben." << std::endl << std::endl diff --git a/parameterManager.h b/parameterManager.h index 15e980e..498d6eb 100644 --- a/parameterManager.h +++ b/parameterManager.h @@ -63,7 +63,7 @@ struct Settings { proxy_ip = "127.0.0.1", languages = "GerDub,GerSub,Eng,", genaueHoster = "", - version = "3.3.2", + version = "3.4.0", defaultFileVersion="1.6", outputFilePath = "", default_checkPath = "", diff --git a/programManager.cpp b/programManager.cpp index d140176..1580cec 100644 --- a/programManager.cpp +++ b/programManager.cpp @@ -40,7 +40,10 @@ int ProgramManager::start(Settings *settings) return newsModus(settings); case Modus::UPDATE_MODUS: return updateModus(settings); + case Modus::REMOVE_SETTINGS_AND_CACHE_MODUS: + return cleanUpSettingsAndCache(settings); default: + std::cout << " => Error: Keine Unteroption ausgewählt." << std::endl; return -1; } } @@ -1103,24 +1106,32 @@ int ProgramManager::updateModus(Settings *settings) int ProgramManager::cleanUpSettingsAndCache(Settings *settings) { - std::string input; - std::cout << "Bitte Bestätigen sie, dass sie alle Einstellungen und" << std::endl - << "Zwischengespeicherten Dateien löschen wollen:\nGeben Sie 'CONFIRM' ein: " << std::flush; - std::getline(std::cin, input); - if( input != "CONFIRM" ) { - std::cout << "Abbruch..." << std::endl; - return 0; + //Alle Groß + settings->name = pageManager.upper_string(settings->name); + + //setting dir + if(settings->name == "SETTINGS" || settings->name == "ALL") { + if( ! removeDirIsOk(settings->configDir, settings)) { + std::cout << " => Error: Das löschen des Settings-Ordners ist fehlgeschlagen." << std::endl; + return 1; + } + } //Cache Dir - if( ! removeDirIsOk(settings->cacheDir, settings)) { - std::cout << " => Error: Das löschen des Cache-Ordners ist fehlgeschlagen." << std::endl; - return 1; + if (settings->name == "CACHE" || settings->name == "ALL") { + if( ! removeDirIsOk(settings->cacheDir, settings)) { + std::cout << " => Error: Das löschen des Cache-Ordners ist fehlgeschlagen." << std::endl; + return 2; + } + } - //setting dir - if( ! removeDirIsOk(settings->configDir, settings)) { - std::cout << " => Error: Das löschen des Settings-Ordners ist fehlgeschlagen." << std::endl; - return 1; + if(settings->name != "CACHE" && settings->name != "SETTINGS" && settings->name != "ALL") + { + std::cout << " => Error: Unbekannte Option '" << settings->name << "' für Ordnerauswahl." << std::endl; + std::cout << "Aufruf: " << settings->programName << " --remove [OPTION]... [settings|cache|all]" << std::endl; + std::cout << "\"" << settings->programName << " --remove --help\" liefert weitere Informationen." << std::endl; + return 3; }