v3.4.0 fix subfunction --remove

This commit is contained in:
Markus 2019-10-27 10:55:53 +01:00
parent 82160eab80
commit fbfc7caab7
3 changed files with 52 additions and 28 deletions

View File

@ -69,7 +69,7 @@ int manageParameter(Settings &settings, int argc, char **argv)
return 1; return 1;
} }


std::vector<std::string> res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean\nnews\n--update", argv[1]); std::vector<std::string> res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean\nnews\n--update\n--remove", argv[1]);
if(res.size() != 1) { if(res.size() != 1) {
if(res.size() == 0) if(res.size() == 0)
std::cout << " => Error: Keine Unteroption für " << argv[1] << " gefunden." << std::endl; 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'; argv[1][0] = '\0';
return unterOption_update(&settings, argc, argv); 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 { } else {
std::cout << " => Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl; std::cout << " => Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl;
return 3; return 3;
@ -1322,20 +1326,17 @@ int unterOption_RemoveSettings_or_CacheDir(Settings *settings, int argc, char **


int c = 0; int c = 0;
const option long_opts[] = { const option long_opts[] = {
{"", required_argument, nullptr, 'p'},

{"help", no_argument, nullptr, 'h'}, {"help", no_argument, nullptr, 'h'},
{"debug-mode", no_argument, nullptr, 'd'}, {"debug-mode", no_argument, nullptr, 'd'},

{nullptr, no_argument, nullptr, 0} {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) { switch(c) {


case 'h': case 'h':
unterOption_update_help(settings->programName); unterOption_RemoveSettings_or_CacheDire_help(settings->programName);
return -1; return -1;
case 'd': case 'd':
settings->debugMode = true; settings->debugMode = true;
@ -1343,12 +1344,23 @@ int unterOption_RemoveSettings_or_CacheDir(Settings *settings, int argc, char **
std::cout << "Debug Modus: true" << std::endl; std::cout << "Debug Modus: true" << std::endl;
break; break;
default: default:
std::cout << "Aufruf: " << settings->programName << " --update [OPTION]..." << std::endl; std::cout << "Aufruf: " << settings->programName << " --remove [OPTION]... [settings|cache|all]" << std::endl;
std::cout << "\"" << settings->programName << " --update --help\" liefert weitere Informationen." << std::endl; std::cout << "\"" << settings->programName << " --remove --help\" liefert weitere Informationen." << std::endl;
return 21; 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) if(settings->debugMode)
std::cout << "Modus: RemoveModus" << std::endl; 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) 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 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 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 << " -d, --debug-mode" << std::endl
<< " Mit dieser Option kann man den Debug-Modus einschalten." << std::endl << " Mit dieser Option kann man den Debug-Modus einschalten." << std::endl
<< " Dabei werden vielmehr Infos ausgegeben." << std::endl << std::endl << " Dabei werden vielmehr Infos ausgegeben." << std::endl << std::endl

View File

@ -63,7 +63,7 @@ struct Settings {
proxy_ip = "127.0.0.1", proxy_ip = "127.0.0.1",
languages = "GerDub,GerSub,Eng,", languages = "GerDub,GerSub,Eng,",
genaueHoster = "", genaueHoster = "",
version = "3.3.2", version = "3.4.0",
defaultFileVersion="1.6", defaultFileVersion="1.6",
outputFilePath = "", outputFilePath = "",
default_checkPath = "", default_checkPath = "",

View File

@ -40,7 +40,10 @@ int ProgramManager::start(Settings *settings)
return newsModus(settings); return newsModus(settings);
case Modus::UPDATE_MODUS: case Modus::UPDATE_MODUS:
return updateModus(settings); return updateModus(settings);
case Modus::REMOVE_SETTINGS_AND_CACHE_MODUS:
return cleanUpSettingsAndCache(settings);
default: default:
std::cout << " => Error: Keine Unteroption ausgewählt." << std::endl;
return -1; return -1;
} }
} }
@ -1103,24 +1106,32 @@ int ProgramManager::updateModus(Settings *settings)


int ProgramManager::cleanUpSettingsAndCache(Settings *settings) int ProgramManager::cleanUpSettingsAndCache(Settings *settings)
{ {
std::string input; //Alle Groß
std::cout << "Bitte Bestätigen sie, dass sie alle Einstellungen und" << std::endl settings->name = pageManager.upper_string(settings->name);
<< "Zwischengespeicherten Dateien löschen wollen:\nGeben Sie 'CONFIRM' ein: " << std::flush;
std::getline(std::cin, input); //setting dir
if( input != "CONFIRM" ) { if(settings->name == "SETTINGS" || settings->name == "ALL") {
std::cout << "Abbruch..." << std::endl; if( ! removeDirIsOk(settings->configDir, settings)) {
return 0; std::cout << " => Error: Das löschen des Settings-Ordners ist fehlgeschlagen." << std::endl;
return 1;
}

} }


//Cache Dir //Cache Dir
if( ! removeDirIsOk(settings->cacheDir, settings)) { if (settings->name == "CACHE" || settings->name == "ALL") {
std::cout << " => Error: Das löschen des Cache-Ordners ist fehlgeschlagen." << std::endl; if( ! removeDirIsOk(settings->cacheDir, settings)) {
return 1; std::cout << " => Error: Das löschen des Cache-Ordners ist fehlgeschlagen." << std::endl;
return 2;
}

} }
//setting dir if(settings->name != "CACHE" && settings->name != "SETTINGS" && settings->name != "ALL")
if( ! removeDirIsOk(settings->configDir, settings)) { {
std::cout << " => Error: Das löschen des Settings-Ordners ist fehlgeschlagen." << std::endl; std::cout << " => Error: Unbekannte Option '" << settings->name << "' für Ordnerauswahl." << std::endl;
return 1; 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;
} }