forked from markus/S_New4
v3.1.0 add selection serie wehn invalid name at default and autosearch
This commit is contained in:
parent
ee46da07cb
commit
17a80f74f2
@ -50,7 +50,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.0.6",
|
version = "3.1.0",
|
||||||
defaultFileVersion="1.6",
|
defaultFileVersion="1.6",
|
||||||
outputFilePath = "",
|
outputFilePath = "",
|
||||||
default_checkPath = "",
|
default_checkPath = "",
|
||||||
|
@ -171,32 +171,102 @@ int ProgramManager::waitForThreads()
|
|||||||
int ProgramManager::sucheNach_1_Serien(Settings *settings, PageManager &pageManager, std::string &newName)
|
int ProgramManager::sucheNach_1_Serien(Settings *settings, PageManager &pageManager, std::string &newName)
|
||||||
{
|
{
|
||||||
std::string finds, line;
|
std::string finds, line;
|
||||||
if(searchModus(settings, &finds) != 0) {
|
//Führe unterfunction zum suchen von Serien aus, aber ohne suche auszugeben und speichere datein in variable
|
||||||
|
if(searchModus(settings, &finds, true) != 0) {
|
||||||
if(settings->debugMode)
|
if(settings->debugMode)
|
||||||
std::cerr << ">>> Debug In " << __FUNCTION__ << ": Function searchModus returned error." << std::endl;
|
std::cerr << ">>> Debug In " << __FUNCTION__ << ": Function searchModus returned error." << std::endl;
|
||||||
return 24;
|
return 24;
|
||||||
}
|
|
||||||
else if(finds.find("/") == std::string::npos || finds.find("|") == std::string::npos || finds.find("\n") != std::string::npos) {
|
// Wenn der Rückgabe wert ungültig ist brich ab...
|
||||||
|
} else if(finds.find("/") == std::string::npos || finds.find("|") == std::string::npos ) { // ||
|
||||||
if(settings->debugMode)
|
if(settings->debugMode)
|
||||||
std::cerr << ">>> Debug In " << __FUNCTION__ << ": searchModus's returnValue contains no / or |, or " << std::endl
|
std::cerr << ">>> Debug In " << __FUNCTION__ << ": searchModus's returnValue contains no / or | => error " << std::endl;
|
||||||
<< "\t\t\tcontains an \\n => more than 1 Serie found => error." << std::endl;
|
|
||||||
return 45;
|
return 45;
|
||||||
}
|
|
||||||
else if ( (finds = finds.substr( finds.find("/") + 1, finds.find("|", finds.find("/")) - finds.find("/") -1) ) == "" ) {
|
// Wenn der Rückgabewert mehrene newlines enthält gibt es mehrere Möglichkeiten
|
||||||
std::cout << " => Error: Konnte den Namen aus der zurückgegebenen Zeile nicht extrahieren." << std::endl;
|
} else if (finds.find("\n") != std::string::npos) {
|
||||||
if(settings->debugMode)
|
|
||||||
std::cerr << ">>> Debug In " << __FUNCTION__ << ": Return value from searchModus.subStr(pos(/)-> next |, after /) is ''." << std::endl;
|
//Gib alle gefundenen Serien Zeilenweise aus und schreibe davor die Zeile:
|
||||||
return 46;
|
std::stringstream myStrStream(finds + "\n");
|
||||||
|
std::cout << "\nWähle eine der folgenden Serien, oder nur [Enter] um Forgang abzubrechen." << std::endl;
|
||||||
|
for (unsigned i = 1; std::getline(myStrStream, line).good() ; ++i) {
|
||||||
|
if(line.find_last_of("|") == std::string::npos) {
|
||||||
|
std::cout << " => Error: Invalid Line: " << line << std::endl;
|
||||||
|
return -21;
|
||||||
|
}
|
||||||
|
std::cout << i << ": " << line.erase(0, line.find_last_of("|") + 1) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Lass Benutzer Zeile auswählen:
|
||||||
|
std::cout << "Zeile: " << std::flush;
|
||||||
|
std::string input;
|
||||||
|
std::getline(std::cin, input);
|
||||||
|
|
||||||
|
//Wenn kein Input, brich ab
|
||||||
|
if(input == "") {
|
||||||
|
std::cout << "Abbruch..." << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Wähle Zeile aus
|
||||||
|
myStrStream.clear();
|
||||||
|
myStrStream.str(finds + "\n");
|
||||||
|
bool hasNewName = false;
|
||||||
|
|
||||||
|
//Geh die Liste nochmal durch
|
||||||
|
for (unsigned i = 1; std::getline(myStrStream, line).good() ; ++i) {
|
||||||
|
if(line.find_last_of("|") == std::string::npos) {
|
||||||
|
std::cout << " => Error: Invalid Line: " << line << std::endl;
|
||||||
|
return -22;
|
||||||
|
|
||||||
|
// Wenn die Zeile gleich der ausgewählten ist:
|
||||||
|
} else if(static_cast<int>(i) == atoi(input.c_str()) ) {
|
||||||
|
//Speichere den Namen der Serie und setzte hasName auf true und brich schleife ab
|
||||||
|
if ( (finds = line.substr( line.find("/") + 1, line.find("|", line.find("/")) - line.find("/") -1) ) == "" ) {
|
||||||
|
std::cout << " => Error: Konnte den Namen aus der zurückgegebenen Zeile nicht extrahieren. In ausWahlVariante" << std::endl;
|
||||||
|
if(settings->debugMode)
|
||||||
|
std::cerr << ">>> Debug In " << __FUNCTION__ << ": Return value from searchModus.subStr(pos(/)-> next |, after /) is ''." << std::endl;
|
||||||
|
return 48;
|
||||||
|
}
|
||||||
|
hasNewName = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Wenn keine der Zeilen gelcih dem Input war, input invali -> brich ab...
|
||||||
|
if(!hasNewName) {
|
||||||
|
std::cout << " => Error: Ungültige Eingabe: '" << input << "'" << std::endl;
|
||||||
|
return 123;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Wenn nur 1 Serie gefunden wurde:
|
||||||
|
} else {
|
||||||
|
//Speicher die Zeile für Namenausgabe:
|
||||||
|
line = finds;
|
||||||
|
|
||||||
|
//Überschreibe eine Zeile mit nur dem url Namen
|
||||||
|
if ( (finds = finds.substr( finds.find("/") + 1, finds.find("|", finds.find("/")) - finds.find("/") -1) ) == "" ) {
|
||||||
|
std::cout << " => Error: Konnte den Namen aus der zurückgegebenen Zeile nicht extrahieren." << std::endl;
|
||||||
|
if(settings->debugMode)
|
||||||
|
std::cerr << ">>> Debug In " << __FUNCTION__ << ": Return value from searchModus.subStr(pos(/)-> next |, after /) is ''." << std::endl;
|
||||||
|
return 46;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Frag den User ob das die Richtige Serie ist:
|
||||||
|
std::cout << " -> Ist das deine gewünschte Serie: '" << line.erase(0, line.find_last_of("|") + 1) << "'" << std::endl
|
||||||
|
<< "Drücke nur [Enter] um fortzufahren: " << std::flush;
|
||||||
|
std::getline(std::cin, line);
|
||||||
|
|
||||||
|
//Wenn input => abbruch
|
||||||
|
if ( line != "") {
|
||||||
|
std::cout << " => Abbruch..." << std::endl;
|
||||||
|
if(settings->debugMode)
|
||||||
|
std::cerr << ">>> Debug In " << __FUNCTION__ << ": User tipped an Value => wrong serie." << std::endl;
|
||||||
|
return 48;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Ist das deine gewünschte Serie? Drücke nur Enter um fortzufahren: " << std::flush;
|
//Überprüfe ob es die serie gibt wenn ja speicher ihn in newname und beende Function
|
||||||
std::getline(std::cin, line);
|
if ( (newName = pageManager.checkName(finds)) == "-1") {
|
||||||
if ( line != "") {
|
|
||||||
std::cout << " => Abbruch..." << std::endl;
|
|
||||||
if(settings->debugMode)
|
|
||||||
std::cerr << ">>> Debug In " << __FUNCTION__ << ": User tipped an Value => wrong serie." << std::endl;
|
|
||||||
return 48;
|
|
||||||
} else if ( (newName = pageManager.checkName(finds)) == "-1") {
|
|
||||||
std::cout << " => Error: Konnte die von der Suche vorgeschlagene Serie nicht finden." << std::endl;
|
std::cout << " => Error: Konnte die von der Suche vorgeschlagene Serie nicht finden." << std::endl;
|
||||||
if(settings->debugMode)
|
if(settings->debugMode)
|
||||||
std::cerr << ">>> Debug In " << __FUNCTION__ << ": Extracted Name from searchModus is invalid." << std::endl;
|
std::cerr << ">>> Debug In " << __FUNCTION__ << ": Extracted Name from searchModus is invalid." << std::endl;
|
||||||
@ -534,7 +604,7 @@ int ProgramManager::directLinkModus(Settings *settings)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ProgramManager::searchModus(Settings *settings, std::string *saveTo)
|
int ProgramManager::searchModus(Settings *settings, std::string *saveTo, bool noPrint)
|
||||||
{
|
{
|
||||||
if(settings->search_wantUpdate) {
|
if(settings->search_wantUpdate) {
|
||||||
int res = searchModus_update(settings) ;
|
int res = searchModus_update(settings) ;
|
||||||
@ -601,6 +671,8 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo)
|
|||||||
if(saveTo) {
|
if(saveTo) {
|
||||||
//Save List to Variable if set
|
//Save List to Variable if set
|
||||||
*saveTo=finds;
|
*saveTo=finds;
|
||||||
|
} if (noPrint) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Text mit Farben versehen
|
//Text mit Farben versehen
|
||||||
|
@ -44,7 +44,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
int defaultModus(Settings * settings);
|
int defaultModus(Settings * settings);
|
||||||
int directLinkModus(Settings * settings);
|
int directLinkModus(Settings * settings);
|
||||||
int searchModus(Settings * settings, std::string *saveTo = nullptr);
|
int searchModus(Settings * settings, std::string *saveTo = nullptr, bool noPrint = false);
|
||||||
int infoModus(Settings * settings);
|
int infoModus(Settings * settings);
|
||||||
int newsModus(Settings *settings);
|
int newsModus(Settings *settings);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user