forked from markus/S_New4
add new default options and not full --help is ok at snew4 clean
This commit is contained in:
parent
f86e5a99b9
commit
2f5c22863b
@ -9,7 +9,7 @@ AccountManager::AccountManager(std::string pathToFile, std::string pathToAccount
|
||||
exit(12);
|
||||
ifs.open(pathToFile);
|
||||
if(!ifs.is_open()) {
|
||||
std::cout << "Konnte Account File nicht öffnen" << std::endl;
|
||||
std::cout << " => Error: Konnte Account File nicht öffnen" << std::endl;
|
||||
exit(13);
|
||||
}
|
||||
}
|
||||
@ -42,7 +42,7 @@ AccountManager::AccountManager(std::string pathToFile, std::string pathToAccount
|
||||
Account AccountManager::getNextAccount()
|
||||
{
|
||||
if(accounts.size() == 0) {
|
||||
std::cout << "Keine Accounts vorhanden." << std::endl;
|
||||
std::cout << " => Error: Keine Accounts vorhanden." << std::endl;
|
||||
exit(36);
|
||||
}
|
||||
size_t accountNumber = getLastAccountNumber();
|
||||
@ -60,10 +60,10 @@ int AccountManager::writeDefault(std::string path)
|
||||
{
|
||||
std::ofstream ofs(path);
|
||||
if(!ofs.is_open()) {
|
||||
perror((std::string("Konnte Account Datei nicht öffnen: ") + path).c_str());
|
||||
perror((std::string(" => Error: Konnte Account Datei nicht öffnen: ") + path).c_str());
|
||||
return -1;
|
||||
}
|
||||
std::cout << "Erstelle Datei mit Accounts unter: " << path << "..." <<std::endl;
|
||||
std::cout << " => Erstelle Datei mit Accounts unter: " << path << "..." <<std::endl;
|
||||
ofs << "# <- Am Anfang der Zeile deaktiviert diese." << std::endl;
|
||||
ofs << "#Email/Passwort - Falls diese gleich sind, geht auch nur Email oder Passwort" << std::endl;
|
||||
{
|
||||
@ -173,7 +173,7 @@ size_t AccountManager::getLastAccountNumber()
|
||||
ofs.close();
|
||||
fStream.open(pathToAccountNumberFile);
|
||||
if(!fStream.is_open()) {
|
||||
perror("Konnte Account Number Datei nicht erstellen");
|
||||
perror(" => Error: Konnte Account Number Datei nicht erstellen");
|
||||
exit(34);
|
||||
}
|
||||
}
|
||||
@ -187,7 +187,7 @@ int AccountManager::setLastAccountNumber(size_t number)
|
||||
std::ofstream ofs;
|
||||
ofs.open(pathToAccountNumberFile, std::ios::trunc);
|
||||
if(!ofs.is_open()) {
|
||||
std::cout << "Account Number Datei ist nicht geöffnet." << std::endl;
|
||||
std::cout << " => Error: Account Number Datei ist nicht geöffnet." << std::endl;
|
||||
return 110;
|
||||
}
|
||||
//fStream.clear();
|
||||
|
@ -7,8 +7,12 @@ void setPaths(Settings &settings)
|
||||
|
||||
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)) {
|
||||
if(system(std::string("mkdir \"" + executablePathTo + "src" + settings.pathSymbol + "\"").c_str()) == 0)
|
||||
std::cout << " => Erfolgreich Ordner 'src' erstellt." << std::endl;
|
||||
else
|
||||
std::cout << " => Error: Ordner '" << executablePathTo << "src' konnte nicht erstellt werden." << std::endl;
|
||||
}
|
||||
if(dirExists(executablePathTo + "src" + settings.pathSymbol))
|
||||
executablePathTo+="src" + std::string(1, settings.pathSymbol);
|
||||
|
||||
@ -16,6 +20,7 @@ void setPaths(Settings &settings)
|
||||
settings.accountFilePath = executablePathTo + "Accounts";
|
||||
settings.accountNumberPath = executablePathTo + "Account_Number";
|
||||
settings.serienListPath = executablePathTo + "SerienListe";
|
||||
settings.defaultsFilePath = executablePathTo + "Defaults";
|
||||
|
||||
}
|
||||
|
||||
@ -80,7 +85,167 @@ int manageParameter(Settings &settings, int argc, char **argv)
|
||||
|
||||
int loadDefaulOptions(Settings &settings)
|
||||
{
|
||||
std::fstream ifs(settings.defaultsFilePath);
|
||||
if(!ifs.is_open()) {
|
||||
std::ofstream ofs(settings.defaultsFilePath);
|
||||
if(!ofs.is_open()) {
|
||||
std::cout << " => Error: Konnte Defaults-Datei nicht öffnen: " << errno << std::endl;
|
||||
return 89;
|
||||
} else {
|
||||
std::cout << " => Erstelle Defaults-Datei: " << settings.defaultsFilePath << std::endl;
|
||||
ofs << "#Mit # kann man eine Zeile deaktivieren." << std::endl;
|
||||
ofs << "DefaultFileVersion="<< settings.defaultFileVersion << std::endl;
|
||||
ofs << "#DebugModus=false" << std::endl;
|
||||
ofs << std::endl;
|
||||
ofs << "#Socks5Proxy=127.0.0.1:9050" << std::endl;
|
||||
ofs << "#FarbloseAusgabe=false" << std::endl;
|
||||
ofs << std::endl;
|
||||
ofs << "#default-GenaueHoster=Vivo,GoUnlimited" << std::endl;
|
||||
ofs << "#default-Sprachen=GerDub,GerSub,Eng" << std::endl;
|
||||
ofs << "#default-CheckSuchMuster=S%Staffel%E%Folge%" << std::endl;
|
||||
ofs << "#default-CheckMaxDirs=20" << std::endl;
|
||||
ofs << "#default-maxThreads=0" << std::endl;
|
||||
ofs << std::endl;
|
||||
ofs << "#search-AchteAufGroßUndKleinschreibung=false" << std::endl;
|
||||
|
||||
|
||||
ofs.close();
|
||||
}
|
||||
ifs.open(settings.defaultsFilePath);
|
||||
if(!ifs.is_open()) {
|
||||
std::cout << " => Error: Konnte Defaults-Datei nach dem erstellen nicht öffnen: " << errno << std::endl;
|
||||
return 97;
|
||||
}
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while (std::getline(ifs, line).good()) {
|
||||
if(line.find("#") != std::string::npos || line == "")
|
||||
continue;
|
||||
else if ( line.find("=") == std::string::npos ) {
|
||||
std::cout << " => Warnung: Bitte Info-Texte mit '#' am Anfang: Ungültige Option '" << line << "'." << std::endl;
|
||||
continue;
|
||||
}
|
||||
std::string what = line.substr(0, line.find("=")), data = line.substr(line.find("=") + 1, line.length() - line.find("=") -1);
|
||||
if(what == "") {
|
||||
|
||||
} else if (what == "Socks5Proxy") { ///---
|
||||
if(data.find(":") == std::string::npos) {
|
||||
std::cout << " => Error_Defaults: Ungültiger Socks5 Proxy: " << optarg << std::endl;
|
||||
return 31;
|
||||
}
|
||||
std::string ip = data.substr(0, data.find(":"));
|
||||
std::string portStr = data.substr(data.find(":") + 1, data.length() - data.find(":"));
|
||||
int port = atoi(portStr.c_str());
|
||||
if(std::to_string(port) != portStr || port <= 0) {
|
||||
std::cout << " => Error_Defaults: Socks5 Proxy: Invalid Port: " << portStr << std::endl;
|
||||
return 32;
|
||||
} else if (ip == "") {
|
||||
std::cout << " => Error_Defaults: Socks5 Proxy: Invalid Ip Addresse: " << ip << std::endl;
|
||||
return 34;
|
||||
} else if(settings.debugMode) {
|
||||
std::cout << "Defaults: Proxy Addresse: "<< ip << ":" << port << std::endl;
|
||||
}
|
||||
settings.proxy_ip = ip;
|
||||
settings.proxy_port = port;
|
||||
|
||||
} else if (what == "DefaultFileVersion") { ///---
|
||||
if(data != settings.defaultFileVersion)
|
||||
std::cout << " => Warnung: Veraltetes Defaults-File. Löschen sie die Datei, um die neuste Version zu bekommen." << std::endl;
|
||||
|
||||
} else if (what == "DebugModus") { ///---
|
||||
if(data == "true")
|
||||
settings.debugMode=true;
|
||||
else if (data == "false")
|
||||
settings.debugMode=false;
|
||||
else {
|
||||
std::cout << " => Error_Defaults: DebugModus: Ungültiger Wert für 'true/false': " << data << std::endl;
|
||||
return 161;
|
||||
}
|
||||
if(settings.debugMode)
|
||||
std::cout << "Defaults: DebugMode: true" << std::endl;
|
||||
|
||||
} else if (what == "default-GenaueHoster") {
|
||||
settings.genaueHoster=data;
|
||||
if(settings.debugMode)
|
||||
std::cout << "Defaults: GenaueHoster: " << settings.genaueHoster << std::endl;
|
||||
|
||||
} else if (what == "default-Sprachen") {
|
||||
settings.languages=data;
|
||||
if(settings.debugMode)
|
||||
std::cout << "Defaults: Sprachen: " << settings.languages << std::endl;
|
||||
|
||||
} else if (what == "default-CheckSuchMuster") {
|
||||
settings.default_Searchmuster=data;
|
||||
if(settings.debugMode)
|
||||
std::cout << "Defaults: SuchMuster: " << settings.default_Searchmuster << std::endl;
|
||||
|
||||
} else if (what == "default-CheckMaxDirs") {
|
||||
settings.default_maxDirs = atoi(data.c_str());
|
||||
if(std::to_string(settings.default_maxDirs) != data ) {
|
||||
std::cout << " => Error_Defaults: Ungültige Zahl: " << data << std::endl;
|
||||
return 18;
|
||||
}
|
||||
if(settings.debugMode)
|
||||
std::cout << "Defaults: SuchMuster: " << settings.default_Searchmuster << std::endl;
|
||||
|
||||
|
||||
} else if (what == "default-maxThreads") {
|
||||
|
||||
settings.maxThreads = static_cast<unsigned>(atoi(data.c_str()));
|
||||
if(std::to_string(settings.maxThreads) != data ) {
|
||||
std::cout << " => Error_Defaults: Ungültige Zahl: " << data << std::endl;
|
||||
return 18;
|
||||
}
|
||||
if(settings.debugMode)
|
||||
std::cout << "Defaults: MaxThreads: " << settings.maxThreads << std::endl;
|
||||
|
||||
break;
|
||||
|
||||
} else if (what == "FarbloseAusgabe") {
|
||||
if(data == "true")
|
||||
settings.colorless=true;
|
||||
else if (data == "false")
|
||||
settings.colorless=false;
|
||||
else {
|
||||
std::cout << " => Error_Defaults: FarbloseAusgabe: Ungültiger Wert für 'true/false': " << data << std::endl;
|
||||
return 207;
|
||||
}
|
||||
if(settings.debugMode)
|
||||
std::cout << "Defaults: FarbloseAusgabe: " << settings.colorless << std::endl;
|
||||
|
||||
} else if (what == "search-AchteAufGroßUndKleinschreibung") {
|
||||
if(data == "true")
|
||||
settings.search_IgnoreUpperLower=false;
|
||||
else if (data == "false")
|
||||
settings.search_IgnoreUpperLower=true;
|
||||
else {
|
||||
std::cout << " => Error_Defaults: search-AchteAufGroßUndKleinschreibung: Ungültiger Wert für 'true/false': " << data << std::endl;
|
||||
return 227;
|
||||
}
|
||||
if(settings.debugMode)
|
||||
std::cout << "Defaults: search-AchteAufGroßUndKleinschreibung: " << settings.search_IgnoreUpperLower << std::endl;
|
||||
|
||||
} else if (what == "") {
|
||||
|
||||
} else if (what == "") {
|
||||
|
||||
} else if (what == "") {
|
||||
|
||||
} else if (what == "") {
|
||||
|
||||
} else if (what == "") {
|
||||
|
||||
} else {
|
||||
std::cout << " => Warnung: Unbekannte Default-Option: '" << what << "'." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ifs.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int unterOption_help()
|
||||
@ -579,7 +744,7 @@ void unterOption_search_help()
|
||||
<< "\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 -> Update die Serienliste." << std::endl
|
||||
<< "\t-h, --help" << std::endl
|
||||
<< "\t -> Gibt dieses Helpmenü aus." << std::endl;
|
||||
|
||||
@ -683,7 +848,7 @@ void unterOption_info_help()
|
||||
void unterOption_clean(Settings * settings, int argc, char **argv)
|
||||
{
|
||||
if(argc > 2)
|
||||
if(strcmp(argv[2], "--help") == 0) {
|
||||
if(strncmp("--help", argv[2], strlen(argv[2])) == 0) {
|
||||
std::cout << "Aufruf: " << getProgramName() << " clean" << std::endl << std::endl;
|
||||
std::cout << "Mit dieser Function werden die Cookie-Files gelöscht." << std::endl;
|
||||
return;
|
||||
@ -715,6 +880,7 @@ void unterOption_clean(Settings * settings, int argc, char **argv)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int compare(std::string All_Options_with_komma_between, std::string input)
|
||||
{
|
||||
std::istringstream iStrStream( All_Options_with_komma_between + "\n");
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <string.h>
|
||||
#include <sstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <limits.h> // PATH_MAX
|
||||
#include <unistd.h> // readlink()
|
||||
|
||||
@ -38,6 +38,7 @@ struct Settings {
|
||||
languages = "GerDub,GerSub,Eng",
|
||||
genaueHoster = "Vivo,GoUnlimited",
|
||||
version = "2.2.2",
|
||||
defaultFileVersion="1.2",
|
||||
outputFilePath = "",
|
||||
default_checkDirPath = "",
|
||||
default_Searchmuster = "S%Staffel%E%Folge%";
|
||||
|
Loading…
Reference in New Issue
Block a user