add funvtion for loading defaults

This commit is contained in:
Markus 2019-08-17 16:03:28 +02:00
parent fdcb96e25e
commit 291e0d2acd
2 changed files with 75 additions and 64 deletions

View File

@ -24,6 +24,8 @@ int manageParameter(Settings &settings, int argc, char **argv)
//Path settings //Path settings
setPathSymbol(settings); setPathSymbol(settings);
setPaths(settings); setPaths(settings);
if(loadDefaulOptions(settings) != 0)
return 28;


if(argc < 2) { if(argc < 2) {
std::cout << " => Error: Keine Unteroption angegeben." << std::endl; std::cout << " => Error: Keine Unteroption angegeben." << std::endl;
@ -76,6 +78,11 @@ int manageParameter(Settings &settings, int argc, char **argv)
} }
} }


int loadDefaulOptions(Settings &settings)
{

}

int unterOption_help() int unterOption_help()
{ {
std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl << std::endl; std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl << std::endl;
@ -579,31 +586,6 @@ void unterOption_search_help()
} }




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) int unterOption_info(Settings *settings, int argc, char **argv)
{ {
settings->modus = Modus::INFO_MODUS; settings->modus = Modus::INFO_MODUS;
@ -698,6 +680,65 @@ void unterOption_info_help()
} }




void unterOption_clean(Settings * settings, int argc, char **argv)
{
if(argc > 2)
if(strcmp(argv[2], "--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 << " => Error: 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 << " => Error: 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-File(s) gelöscht." << std::endl;

return;
}

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 );
}

std::string getexepath() std::string getexepath()
{ {
#ifdef linux #ifdef linux
@ -729,37 +770,3 @@ bool fileExists (const std::string& name) {
return (stat (name.c_str(), &buffer) == 0 && S_ISREG(buffer.st_mode)); return (stat (name.c_str(), &buffer) == 0 && S_ISREG(buffer.st_mode));
} }


void unterOption_clean(Settings * settings, int argc, char **argv)
{
if(argc > 2)
if(strcmp(argv[2], "--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-File(s) gelöscht." << std::endl;

return;
}

View File

@ -30,9 +30,10 @@ struct Settings {


std::string name, std::string name,
accountFilePath = "/tmp/a", accountFilePath = "/tmp/a",
accountNumberPath= "/tmp/b", accountNumberPath= "/tmp/a_n",
cookieFilePath = "/tmp/S_New4_cookies", cookieFilePath = "/tmp/S_New4_cookies",
serienListPath = "/tmp/SerienListe", serienListPath = "/tmp/SerienListe",
defaultsFilePath = "/tmp/defaults",
proxy_ip = "127.0.0.1", proxy_ip = "127.0.0.1",
languages = "GerDub,GerSub,Eng", languages = "GerDub,GerSub,Eng",
genaueHoster = "Vivo,GoUnlimited", genaueHoster = "Vivo,GoUnlimited",
@ -58,14 +59,17 @@ struct Settings {
}; };


int manageParameter(Settings &settings, int argc, char ** argv); int manageParameter(Settings &settings, int argc, char ** argv);
std::string getProgramName(); int loadDefaulOptions(Settings & settings);
int compare(std::string All_Options_with_komma_between, std::string input); int compare(std::string All_Options_with_komma_between, std::string input);
void setPaths(Settings &settings);
bool dirExists(std::string dir);


std::string getProgramName();
std::string getexepath(); std::string getexepath();
void setPathSymbol(Settings &settings);


void setPathSymbol(Settings &settings);
void setPaths(Settings &settings);

bool fileExists (const std::string& name);
bool dirExists(std::string dir);


int unterOption_help(); int unterOption_help();