#include "parameterManager.h" void setPaths(Settings &settings) { //Path settings std::string executablePathTo = getexepath(); executablePathTo.erase(executablePathTo.find_last_of(settings.pathSymbol) + 1 , executablePathTo.length() - ( executablePathTo.find_last_of(settings.pathSymbol) + 1) ); if(!dirExists(executablePathTo + "src" + settings.pathSymbol)) system(std::string("mkdir \"" + executablePathTo + "src" + settings.pathSymbol + "\"").c_str()); if(dirExists(executablePathTo + "src" + settings.pathSymbol)) executablePathTo+="src" + std::string(1, settings.pathSymbol); settings.cookieFilePath = executablePathTo + "S_New4_cookies"; settings.accountFilePath = executablePathTo + "Accounts"; settings.accountNumberPath = executablePathTo + "Account_Number"; settings.serienListPath = executablePathTo + "SerienListe"; } int manageParameter(Settings &settings, int argc, char **argv) { //Path settings setPathSymbol(settings); setPaths(settings); if(argc < 2) { std::cout << " => Error: Keine Unteroption angegeben." << std::endl; std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl; std::cout << "„" << getProgramName() << " --help“ liefert weitere Informationen." << std::endl; return 1; } int res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean", argv[1]); if(res != 1) { std::cout << " => Error: " << ( (res == 0) ? std::string("Unbekannte Unteroption: '") + argv[1] + "'" : std::string("Mehrere Optionen für '") + argv[1] + std::string("' gefunden.") ) << std::endl; std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl; std::cout << "„" << getProgramName() << " --help“ liefert weitere Informationen." << std::endl; return 2; } if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) { argv[1][0] = '\0'; return unterOption_help(); } else if (strncmp(argv[1], "default", strlen(argv[1])) == 0) { argv[1][0] = '\0'; return unterOption_default(&settings, argc, argv); } else if (strncmp(argv[1], "url", strlen(argv[1])) == 0) { argv[1][0] = '\0'; return unterOption_url(&settings, argc, argv); } else if (strncmp(argv[1], "--version", strlen(argv[1])) == 0) { std::cout << "Version: " << settings.version << std::endl; return -1; } else if (strncmp(argv[1], "search", strlen(argv[1])) == 0) { argv[1][0] = '\0'; return unterOption_search(&settings, argc, argv); } else if (strncmp(argv[1], "info", strlen(argv[1])) == 0) { argv[1][0] = '\0'; return unterOption_info(&settings, argc, argv); } else if (strncmp(argv[1], "clean", strlen(argv[1])) == 0) { argv[1][0] = '\0'; unterOption_clean(&settings, argc, argv); return -1; } else { std::cout << "Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl; return 3; } } int unterOption_help() { std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl << std::endl; std::cout << "Unteroptionen:" << std::endl << "\t„--help“\tListe aller Unteroptionen" << std::endl << "\t„--version“\tVersion des Programmes" << std::endl << "\t„url“\t\tModus um eigene Redirect-Links umzuwandeln." << std::endl << "\t„default“\tModus um Links von Serien zu bekommen." << std::endl << "\t„search“\tModus um Serien zu suchen." << std::endl << "\t„info“\tModus um Infos einer Serien zu bekommen." << std::endl << "\t„clean“\tModus um Cookie-Files zu löschen." << std::endl; return -1; } int unterOption_default(Settings *settings, int argc, char ** argv) { settings->modus = Modus::DEFAULT_MODUS; int c = 0; const option long_opts[] = { {"socks5-proxy", required_argument, nullptr, 'p'}, {"genauer-hoster", required_argument, nullptr, 'g'}, {"languages", required_argument, nullptr, 'l'}, {"output-file", required_argument, nullptr, 'o'}, {"start-episode", required_argument, nullptr, 'e'}, {"stop-episode", required_argument, nullptr, 'E'}, {"start-season", required_argument, nullptr, 's'}, {"stop-season", required_argument, nullptr, 'S'}, {"check-dir", required_argument, nullptr, 'C'}, {"check-muster", required_argument, nullptr, 'm'}, {"check-max-dirs", required_argument, nullptr, 'D'}, {"threads", required_argument, nullptr, 't'}, {"help", no_argument, nullptr, 'h'}, {"colorless", no_argument, nullptr, 'c'}, {"debug-mode", no_argument, nullptr, 'd'}, {nullptr, no_argument, nullptr, 0} }; while( ( c = getopt_long (argc, argv, "p:g:l:o:e:E:s:S:C:m:D:t:hcd", long_opts, nullptr) ) != -1 ) { switch(c) { case 'p': { if(!optarg || std::string(optarg) == "") break; std::string optarg = ::optarg; if(optarg.find(":") == std::string::npos) { std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl; return 31; } std::string ip = optarg.substr(0, optarg.find(":")); std::string portStr = optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":")); int port = atoi(portStr.c_str()); if(std::to_string(port) != portStr || port <= 0) { std::cout << "[-p]: Invalid Port: " << portStr << std::endl; return 32; } else if (ip == "") { std::cout << "[-p]: Invalid Ip Addresse: " << ip << std::endl; return 34; } else if(settings->debugMode) { std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl; } settings->proxy_ip = ip; settings->proxy_port = port; } break; case 'g': if(optarg) settings->genaueHoster =+ optarg + std::string(","); if(settings->debugMode) std::cout << "Hosterreihenfolge: " << settings->genaueHoster << std::endl; break; case 'l': if(optarg) settings->languages =+ optarg + std::string(","); if(settings->debugMode) std::cout << "Sprachenreihenfolge: " << settings->languages << std::endl; break; case 'o': if(optarg) settings->outputFilePath = optarg; if(settings->debugMode) std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl; break; case 'e': if(!optarg) break; settings->startEpisode = atoi(optarg); if (std::to_string(settings->startEpisode) != optarg) { std::cout << "Error: -e [Folge]: '" << optarg << "' ist keine Zahl." << std::endl; return 11; } else if (settings->startEpisode == 0) { std::cout << "Error: -e [Folge]: StartEpisode ist 0." << std::endl; return 12; } else if (settings->startEpisode < 0) { std::cout << "Error: -e [Folge]: StartEpisode " << settings->startEpisode << " ist kleiner 0." << std::endl; return 13; } if(settings->debugMode) std::cout << "StartEpisode: " << settings->startEpisode << std::endl; break; case 'E': if(!optarg) break; settings->stopEpisode = atoi(optarg); if (std::to_string(settings->stopEpisode) != optarg) { std::cout << "Error: -E [Folge]: '" << optarg << "' ist keine Zahl." << std::endl; return 14; } else if (settings->debugMode) std::cout << "StopEpisode: " << settings->stopEpisode << std::endl; break; case 's': if(!optarg) break; settings->startSeason = atoi(optarg); if (std::to_string(settings->startSeason) != optarg) { std::cout << "Error: -s [Staffel]: '" << optarg << "' ist keine Zahl." << std::endl; return 15; } else if (settings->startSeason == 0) { std::cout << "Error: -s [Staffel]: StartStaffel ist 0." << std::endl; return 16; } else if (settings->startSeason < 0) { std::cout << "Error: -s [Staffel]: StartStaffel " << settings->startSeason << " ist kleiner 0." << std::endl; return 17; } else if(settings->debugMode) std::cout << "StartStaffel: " << settings->startSeason << std::endl; break; case 'S': if(!optarg) break; settings->stopSeason = atoi(optarg); if (std::to_string(settings->stopSeason) != optarg) { std::cout << "Error: -S [Staffel]: '" << optarg << "' ist keine Zahl." << std::endl; return 18; } else if(settings->debugMode) std::cout << "StopSeason: " << settings->stopSeason << std::endl; break; case 'm': if(optarg) settings->default_Searchmuster = optarg; if(settings->debugMode) std::cout << "SearchMuster: " << settings->default_Searchmuster << std::endl; break; case 'D': if(!optarg) break; settings->default_maxDirs = atoi(optarg); if(std::to_string(settings->default_maxDirs) != std::string(optarg) ) { std::cout << "[-D]: Invalid Count: " << optarg << std::endl; return 18; } if(settings->debugMode) std::cout << "SearchMuster: " << settings->default_Searchmuster << std::endl; break; case 't': if(!optarg) break; settings->maxThreads = static_cast(atoi(optarg)); if(std::to_string(settings->maxThreads) != std::string(optarg) ) { std::cout << "[-t]: Ungültige Zahl: " << optarg << std::endl; return 18; } if(settings->debugMode) std::cout << "MaxThreads: " << settings->maxThreads << std::endl; break; case 'C': if(!optarg) break; settings->default_checkDirPath = optarg; if(settings->debugMode) std::cout << "To check Dir: " << settings->default_checkDirPath << std::endl; break; case 'c': settings->colorless = true; if(settings->debugMode) std::cout << "Farblos: true" << std::endl; if(argc > optind) if(argv[optind][0] != '-' && std::string(argv[optind]).find(settings->pathSymbol) != std::string::npos) { std::cout << " => Upps: Hast du -c (--colorless) mit -C (--check-dir) verwechselt?" << std::endl << " (Hat “Argument“ mit “"<< settings->pathSymbol << "“: '-c " << std::string(argv[optind]) << "')." << std::endl; return -1; } break; case 'd': settings->debugMode = true; if(settings->debugMode) std::cout << "Debug Modus: true" << std::endl; break; case 'h': unterOption_default_help(); return -1; default: std::cout << "Aufruf: " << getProgramName() << " default [OPTION]... [NAME]..." << std::endl; std::cout << "„" << getProgramName() << " default --help“ liefert weitere Informationen." << std::endl; return -1; } } //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 << "Name: " << settings->name << std::endl; std::cout << "Modus: DEFAULT_MODUS" << std::endl; } return 0; } void unterOption_default_help() { std::cout << "Usage: " << getProgramName() << " default [OPTION]... [NAME]..." << std::endl << "Parameter:" << std::endl << std::endl << " > Auswahloptionen:" << std::endl << "\t-g [Hoster1,Hoster2,...], --genauer-hoster [Hoster1,Hoster2,...]" << std::endl << "\t -> Die Namen der Hoster, deren Links du willst. Der wichtigste zuerst." << std::endl << "\t -> Default: Vivo,GoUnlimited" << std::endl << "\t-l [GerDub/GerSub/Eng,...], --languages [GerDub/GerSub/Eng,...]" << std::endl << "\t -> Die Sprache(n) die du willst. Die wichtigsten zuerst. Default: GerDub,GerSub,Eng" << std::endl << std::endl << " > Proxy-Optionen:" << std::endl << "\t-p [ProxyAddresse], --socks5-proxy [ProxyAddresse]" << std::endl << "\t -> Ip Addresse eines Socks5-Proxys angeben. Default: 127.0.0.1:9050" << std::endl << std::endl << " > Outputoptionen:" << std::endl << "\t-o [Pfad], --output-file [Pfad]" << std::endl << "\t -> Schreibe Links nach Redirect in diese Datei." << std::endl << "\t-c, --colorless" << std::endl << "\t -> Keine Farben beim Output verwenden. Default: false" << std::endl << "\t-d, --debug-mode" << std::endl << "\t -> Debug Nachrichten an. Default: false" << std::endl << std::endl << " > Check-Dir Optionen:" << std::endl << "\t-C [Pfad], --check-dir [Pfad]" << std::endl << "\t -> Überprüfe ob in diesem, oder in einen der Unterordnern die Folge vorkommt." << std::endl << "\t -> Wenn ja, dann überspringe diese." << std::endl << "\t-m, --check-muster" << std::endl << "\t -> Muster mit dem Überprüft wird, ob diese Folge in einem Ordner ist. Default: S%Staffel%E%Folge%" << std::endl << "\t -> %Staffel% ist eine Variable für die Staffel mit 0 + Staffel, wenn Staffel < 10. " << std::endl << "\t -> %Folge% ist eine Variable für die Folge mit 0 + Folge, wenn Folge < 10. " << std::endl << "\t-D, --check-max-dirs" << std::endl << "\t -> Maximale Anzahl der Ordner, die auf Dateien untersucht werden. Default: 20" << std::endl << std::endl << " > Durchlaufoptionen:" << std::endl << "\t-e [Folge], --start-episode [Folge]" << std::endl << "\t -> Das Programm startet mit dieser Folge." << std::endl << "\t Default: 1" << std::endl << "\t-E [Folge], --stop-episode [Folge]" << std::endl << "\t -> - Wenn -S nicht verwendet wird, stoppt das Programm sobald die Folge erreicht wurde." << std::endl << "\t - Wenn -S verwendet wird, stoppt es 1. wenn die Folge UND die Staffel erreicht wurden," << std::endl << "\t 2. wenn die die Staffel von -S fertig ist. Zum deaktivieren Folge <= 0 verwenden." << std::endl << "\t Default: 0" << std::endl << "\t-s [Staffel], --start-season [Staffel]" << std::endl << "\t -> Das Programm startet mit dieser Staffel." << std::endl << "\t Default: 1" << std::endl << "\t-S [Staffel], --stop-season [Staffel]" << std::endl << "\t -> Das Programm stopt mit dieser Staffel. Beachte Verwendung mit -E." << std::endl << "\t Zum deaktivieren Staffel <= 0 verwenden. Default: 0" << std::endl << " > Multi-Thrading Optionen:" << std::endl << "\t-t [maxThreads], --threads [maxThreads]" << std::endl << "\t -> Das Programm startet für jede Folge einen eigenen Thread," << std::endl << "\t -> bis die maximale Anzahl ereicht wurde. Dann wartet es auf" << std::endl << "\t -> das enden aller Threads und fängt dann wieder von vorne an." << std::endl << "\t -> Zum deaktivieren von Multithreading '0' verwenden. Default: 0" << std::endl << std::endl << " > Help-Optionen" << std::endl << "\t-h, --help" << std::endl; } int unterOption_url(Settings *settings, int argc, char **argv) { settings->modus = Modus::DIRECT_LINK_MODUS; int c = 0; const option long_opts[] = { {"socks5-proxy", required_argument, nullptr, 'p'}, {"output-file", required_argument, nullptr, 'o'}, {"help", no_argument, nullptr, 'h'}, {"colorless", no_argument, nullptr, 'c'}, {"debug-mode", no_argument, nullptr, 'd'}, {nullptr, no_argument, nullptr, 0} }; while( ( c = getopt_long (argc, argv, "p:o:hcd", long_opts, nullptr) ) != -1 ) { switch(c) { case 'p': { if(!optarg || std::string(optarg) == "") break; std::string optarg = ::optarg; if(optarg.find(":") == std::string::npos) { std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl; return 31; } std::string ip = optarg.substr(0, optarg.find(":")); std::string portStr = optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":")); int port = atoi(portStr.c_str()); if(std::to_string(port) != portStr || port <= 0) { std::cout << "[-p]: Invalid Port: " << portStr << std::endl; return 32; } else if (ip == "") { std::cout << "[-p]: Invalid Ip Addresse: " << ip << std::endl; return 34; } else if(settings->debugMode) { std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl; } settings->proxy_ip = ip; settings->proxy_port = port; } break; case 'o': if(optarg) settings->outputFilePath = optarg; if(settings->debugMode) std::cout << "Pfad zu Output-Datei: " << settings->outputFilePath << std::endl; break; case 'c': settings->colorless = true; if(settings->debugMode) std::cout << "Farblos: true" << std::endl; break; case 'd': settings->debugMode = true; if(settings->debugMode) std::cout << "Debug Modus: true" << std::endl; break; case 'h': unterOption_url_help(); return -1; default: std::cout << "Aufruf: " << getProgramName() << " url [OPTION]... [URL]..." << std::endl; std::cout << "„" << getProgramName() << " url --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 << "Urls: " << settings->name << std::endl; std::cout << "Modus: DIRECT_LINK_MODUS" << std::endl; } return 0; } void unterOption_url_help() { std::cout << "Usage: " << getProgramName() << " url [OPTION]... [URL]..." << std::endl << "Parameter:" << std::endl << "\t-p [ProxyAddresse], --socks5-proxy [ProxyAddresse]" << std::endl << "\t -> Type: Socks5, Default: 127.0.0.1:9050" << std::endl << "\t-o [Pfad], --output-file [Pfad]" << std::endl << "\t-c, --colorless" << std::endl << "\t -> Default: false" << std::endl << "\t-d, --debug-mode" << std::endl << "\t -> Debug Nachrichten an. Default: false" << std::endl << "\t-h, --help" << std::endl; } int unterOption_search(Settings *settings, int argc, char **argv) { settings->modus = Modus::SEARCH_MODUS; int c = 0; const option long_opts[] = { {"socks5-proxy", required_argument, nullptr, 'p'}, {"help", no_argument, nullptr, 'h'}, {"colorless", no_argument, nullptr, 'c'}, {"debug-mode", no_argument, nullptr, 'd'}, {"exactly-writing", no_argument, nullptr, 'e'}, {"update", no_argument, nullptr, 'u'}, {nullptr, no_argument, nullptr, 0} }; while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) { switch(c) { case 'p': { if(!optarg || std::string(optarg) == "") break; std::string optarg = ::optarg; if(optarg.find(":") == std::string::npos) { std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl; return 31; } std::string ip = optarg.substr(0, optarg.find(":")); std::string portStr = optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":")); int port = atoi(portStr.c_str()); if(std::to_string(port) != portStr || port <= 0) { std::cout << "[-p]: Invalid Port: " << portStr << std::endl; return 32; } else if (ip == "") { std::cout << "[-p]: Invalid Ip Addresse: " << ip << std::endl; return 34; } else if(settings->debugMode) { std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl; } settings->proxy_ip = ip; settings->proxy_port = port; } break; case 'h': unterOption_search_help(); return -1; case 'c': settings->colorless = true; if(settings->debugMode) std::cout << "Farblos: true" << std::endl; break; case 'd': settings->debugMode = true; if(settings->debugMode) std::cout << "Debug Modus: true" << std::endl; break; case 'e': settings->search_IgnoreUpperLower = false; if(settings->debugMode) std::cout << "Achte auf Groß und Kleinschreibung: true" << std::endl; break; case 'u': settings->search_wantUpdate = true; if(settings->debugMode) std::cout << "Update die Liste: true" << std::endl; break; default: std::cout << "Aufruf: " << getProgramName() << " search [OPTION]... [NAME]..." << std::endl; std::cout << "„" << getProgramName() << " search --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 << "Name: " << settings->name << std::endl; std::cout << "Modus: Search_MODUS" << std::endl; } return 0; } void unterOption_search_help() { std::cout << "Usage: " << getProgramName() << " search [OPTION]... [NAME]..." << std::endl << " " << getProgramName() << " search [-u, --update]" << std::endl << "Parameter:" << std::endl << "\t-p [Socks5Proxy], --socks5-proxy [Socks5Proxy]" << std::endl << "\t -> Verwende diesen Socks5-Proxy. Default: 127.0.0.1:9050" << std::endl << "\t-c, --colorless" << std::endl << "\t -> Gib keine Farbigen Infos aus. Default: false" << std::endl << "\t-d, --debug-mode" << std::endl << "\t -> Debug Nachrichten an. Default: false" << std::endl << "\t-e, --exactly-writing" << std::endl << "\t -> Achte auf Groß und kleinschreibung bei der Suche. Default: false" << std::endl << "\t-u, --update" << std::endl << "\t -> Update die Serienliste. Default: false" << std::endl << "\t-h, --help" << std::endl << "\t -> Gibt dieses Helpmenü aus." << std::endl; } int compare(std::string All_Options_with_komma_between, std::string input) { std::istringstream iStrStream( All_Options_with_komma_between + "\n"); std::string line; int allFounds = 0; while (getline(iStrStream, line).good()) if(strncmp(line.c_str(), input.c_str(), input.length()) == 0) { allFounds++; //std::cout << "Unteroption '" << input << "' stimmt mit '" << line << "' überein." << std::endl; } return allFounds; } bool dirExists(std::string dir) { struct stat sb; return (stat(dir.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) ? true : false; } std::string getProgramName() { return getexepath().erase(0, ( getexepath().find_last_of("/\\") != std::string::npos ) ? getexepath().find_last_of("/\\") +1 : 0 ); } int unterOption_info(Settings *settings, int argc, char **argv) { settings->modus = Modus::INFO_MODUS; int c = 0; const option long_opts[] = { {"socks5-proxy", required_argument, nullptr, 'p'}, {"help", no_argument, nullptr, 'h'}, {"colorless", no_argument, nullptr, 'c'}, {"debug-mode", no_argument, nullptr, 'd'}, {nullptr, no_argument, nullptr, 0} }; while( ( c = getopt_long (argc, argv, "n:p:hcdeu", long_opts, nullptr) ) != -1 ) { switch(c) { case 'p': { if(!optarg || std::string(optarg) == "") break; std::string optarg = ::optarg; if(optarg.find(":") == std::string::npos) { std::cout << "Invalid Socks5 Proxy: " << optarg << std::endl; return 31; } std::string ip = optarg.substr(0, optarg.find(":")); std::string portStr = optarg.substr(optarg.find(":") + 1, optarg.length() - optarg.find(":")); int port = atoi(portStr.c_str()); if(std::to_string(port) != portStr || port <= 0) { std::cout << "[-p]: Invalid Port: " << portStr << std::endl; return 32; } else if (ip == "") { std::cout << "[-p]: Invalid Ip Addresse: " << ip << std::endl; return 34; } else if(settings->debugMode) { std::cout << "Proxy Addresse: "<< ip << ":" << port << std::endl; } settings->proxy_ip = ip; settings->proxy_port = port; } break; case 'h': unterOption_info_help(); return -1; case 'c': settings->colorless = true; if(settings->debugMode) std::cout << "Farblos: true" << std::endl; break; case 'd': settings->debugMode = true; if(settings->debugMode) std::cout << "Debug Modus: true" << std::endl; break; default: std::cout << "Aufruf: " << getProgramName() << " info [OPTION]... [NAME]..." << std::endl; std::cout << "„" << getProgramName() << " info --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 << "Name: " << settings->name << std::endl; std::cout << "Modus: Search_MODUS" << std::endl; } return 0; } void unterOption_info_help() { std::cout << "Usage: " << getProgramName() << " info [OPTION]... [NAME]..." << std::endl << "Parameter:" << std::endl << "\t-p [Socks5Proxy], --socks5-proxy [Socks5Proxy]" << std::endl << "\t -> Verwende diesen Socks5-Proxy. Default: 127.0.0.1:9050" << std::endl << "\t-c, --colorless" << std::endl << "\t -> Gib keine Farbigen Infos aus. Default: false" << std::endl << "\t-d, --debug-mode" << std::endl << "\t -> Debug Nachrichten an. Default: false" << std::endl << "\t-h, --help" << std::endl << "\t -> Gibt dieses Helpmenü aus." << std::endl; } std::string getexepath() { #ifdef linux char result[ PATH_MAX ]; ssize_t count = readlink( "/proc/self/exe", result, PATH_MAX ); return std::string( result, (count > 0) ? static_cast(count) : 0 ); #endif #ifdef ABC ///_WIN32 wchar_t result[ MAX_PATH ]; char buffer[MAX_PATH]; return std::string( result, GetModuleFileName( NULL, buffer, MAX_PATH ) ); //GetModuleFileName(NULL, result, MAX_PATH) ; //return reinterpret_cast(result); #endif } void setPathSymbol(Settings &settings) { #ifdef linux settings.pathSymbol = '/'; #endif #ifdef _WIN32 settings.pathSymbol = '\\'; #endif } bool fileExists (const std::string& name) { struct stat buffer; return (stat (name.c_str(), &buffer) == 0 && S_ISREG(buffer.st_mode)); } void unterOption_clean(Settings * settings, int argc, char **argv) { if(argc > 1) if(strcmp(argv[1], "--help") == 0) { std::cout << "Aufruf: " << getProgramName() << " clean" << std::endl << std::endl; std::cout << "Mit dieser Function werden die Cookie-Files gelöscht." << std::endl; return; } unsigned count = 0; if(fileExists(settings->cookieFilePath)) { if(remove(settings->cookieFilePath.c_str()) != 0) { std::cout << "Das löschen von " << settings->cookieFilePath << " ist fehlgeschlagen: " << errno << std::endl; return; } else { count++; } } for (unsigned i = 0; i < UINT_MAX && fileExists(settings->cookieFilePath + std::to_string(i)); i++) { if(remove( (settings->cookieFilePath + std::to_string(i)).c_str() ) != 0) { std::cout << "Das löschen von " << settings->cookieFilePath + std::to_string(i) << " ist fehlgeschlagen: " << errno << std::endl; return; } else { count++; } } if(count == 0) std::cout << " => Nichts zu tun: Keine Cookies vorhanden." << std::endl; else std::cout << " => " << count << " Cookie-Files gelöscht." << std::endl; return; }