ersetzte getexepath function und getprogramname function mit varioable mit program Namen

This commit is contained in:
Markus 2019-09-04 11:04:20 +02:00
parent 66b3d9b08f
commit 3cabd9bbf7
3 changed files with 45 additions and 74 deletions

View File

@ -55,8 +55,8 @@ int manageParameter(Settings &settings, int argc, char **argv)

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;
std::cout << "Aufruf: " << settings.programName << " [Unteroption] [PARAMETER]" << std::endl;
std::cout << "\"" << settings.programName << " --help\" liefert weitere Informationen." << std::endl;
return 1;
}

@ -69,8 +69,8 @@ int manageParameter(Settings &settings, int argc, char **argv)
for (auto &e : res)
std::cout << " > '" << argv[1] << "' =? " << e << std::endl;
}
std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]" << std::endl;
std::cout << "\"" << getProgramName() << " --help\" liefert weitere Informationen." << std::endl;
std::cout << "Aufruf: " << settings.programName << " [Unteroption] [PARAMETER]" << std::endl;
std::cout << "\"" << settings.programName << " --help\" liefert weitere Informationen." << std::endl;
return 2;
}
res.clear();
@ -78,7 +78,7 @@ int manageParameter(Settings &settings, int argc, char **argv)

if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) {
argv[1][0] = '\0';
return unterOption_help();
return unterOption_help(settings.programName);

} else if (strncmp(argv[1], "default", strlen(argv[1])) == 0) {
argv[1][0] = '\0';
@ -261,9 +261,9 @@ int loadDefaulOptions(Settings &settings)
return 0;
}

int unterOption_help()
int unterOption_help(std::string programName)
{
std::cout << "Aufruf: " << getProgramName() << " [Unteroption] [PARAMETER]..." << std::endl << std::endl;
std::cout << "Aufruf: " << programName << " [Unteroption] [PARAMETER]..." << std::endl << std::endl;
std::cout << "Beschreibung:" << std::endl
<< " -> Mit diesem Programm kann man die Download-Urls" << std::endl
<< " oder Informationen von Serien bekommen." << std::endl
@ -444,11 +444,11 @@ int unterOption_default(Settings *settings, int argc, char ** argv)
std::cout << "Debug Modus: true" << std::endl;
break;
case 'h':
unterOption_default_help();
unterOption_default_help(settings->programName);
return -1;
default:
std::cout << "Aufruf: " << getProgramName() << " default [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << getProgramName() << " default --help\" liefert weitere Informationen." << std::endl;
std::cout << "Aufruf: " << settings->programName << " default [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << settings->programName << " default --help\" liefert weitere Informationen." << std::endl;
return -1;
}
}
@ -470,9 +470,9 @@ int unterOption_default(Settings *settings, int argc, char ** argv)
return 0;
}

void unterOption_default_help()
void unterOption_default_help(std::string programName)
{
std::cout << "Aufruf: " << getProgramName() << " default [OPTION]... [NAME]" << std::endl << std::endl;
std::cout << "Aufruf: " << programName << " default [OPTION]... [NAME]" << std::endl << std::endl;

std::cout << "Beschreibung:" << std::endl
<< " Mit dieser Unterfunktion kann man die Downloadlinks von Serien bekommen." << std::endl << std::endl;
@ -615,11 +615,11 @@ int unterOption_url(Settings *settings, int argc, char **argv)
std::cout << "Debug Modus: true" << std::endl;
break;
case 'h':
unterOption_url_help();
unterOption_url_help(settings->programName);
return -1;
default:
std::cout << "Aufruf: " << getProgramName() << " url [OPTION]... [URL]..." << std::endl;
std::cout << "\"" << getProgramName() << " url --help\" liefert weitere Informationen." << std::endl;
std::cout << "Aufruf: " << settings->programName << " url [OPTION]... [URL]..." << std::endl;
std::cout << "\"" << settings->programName << " url --help\" liefert weitere Informationen." << std::endl;
return 21;
}
}
@ -643,12 +643,12 @@ int unterOption_url(Settings *settings, int argc, char **argv)
return 0;
}

void unterOption_url_help()
void unterOption_url_help(std::string programName)
{
std::cout << "Aufruf: " << getProgramName() << " url [OPTION]... [URL]..." << std::endl << std::endl;
std::cout << "Aufruf: " << programName << " url [OPTION]... [URL]..." << std::endl << std::endl;

std::cout << "Beschreibung:" << std::endl
<< " Mit dieser Unterfunction von " << getProgramName() << " können eigene" << std::endl
<< " Mit dieser Unterfunction von " << programName << " können eigene" << std::endl
<< " Redirect-Links umgewandelt werden. Beispiel:" << std::endl
<< " https://s.to/redirect/4449825 -> http://vivo.sx/d20b111ade" << std::endl
<< " Achtung: Achte, dass Url mit https:// nicht mit http:// beginnt." << std::endl
@ -696,7 +696,7 @@ int unterOption_search(Settings *settings, int argc, char **argv)
return 2;
break;
case 'h':
unterOption_search_help();
unterOption_search_help(settings->programName);
return -1;
case 'c':
settings->colorless = true;
@ -719,8 +719,8 @@ int unterOption_search(Settings *settings, int argc, char **argv)
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;
std::cout << "Aufruf: " << settings->programName << " search [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << settings->programName << " search --help\" liefert weitere Informationen." << std::endl;
return 21;
}
}
@ -742,10 +742,10 @@ int unterOption_search(Settings *settings, int argc, char **argv)
return 0;
}

void unterOption_search_help()
void unterOption_search_help(std::string programName)
{
std::cout << "Aufruf: " << getProgramName() << " search [OPTION]... [NAME]" << std::endl
<< " " << getProgramName() << " search [-u, --update]" << std::endl << std::endl;
std::cout << "Aufruf: " << programName << " search [OPTION]... [NAME]" << std::endl
<< " " << programName << " search [-u, --update]" << std::endl << std::endl;

std::cout << "Beschreibung:" << std::endl
<< " Mit dieser Unterfunction des Programms kann man Serien auf s.to suchen." << std::endl
@ -800,7 +800,7 @@ int unterOption_info(Settings *settings, int argc, char **argv)
return 2;
break;
case 'h':
unterOption_info_help();
unterOption_info_help(settings->programName);
return -1;
case 'c':
settings->colorless = true;
@ -813,8 +813,8 @@ int unterOption_info(Settings *settings, int argc, char **argv)
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;
std::cout << "Aufruf: " << settings->programName << " info [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << settings->programName << " info --help\" liefert weitere Informationen." << std::endl;
return 21;
}
}
@ -836,9 +836,9 @@ int unterOption_info(Settings *settings, int argc, char **argv)
return 0;
}

void unterOption_info_help()
void unterOption_info_help(std::string programName)
{
std::cout << "Aufruf: " << getProgramName() << " info [OPTION]... [NAME]" << std::endl << std::endl;
std::cout << "Aufruf: " << programName << " info [OPTION]... [NAME]" << std::endl << std::endl;

std::cout << "Beschreibung:" << std::endl
<< " Mit dieser Unterfunktion kann man Informationen zu einer Serie bekommen." << std::endl << std::endl;
@ -861,7 +861,7 @@ void unterOption_clean(Settings * settings, int argc, char **argv)
{
if(argc > 2)
if(strncmp("--help", argv[2], strlen(argv[2])) == 0) {
std::cout << "Aufruf: " << getProgramName() << "clean\n " << getProgramName() << "clean --help" << std::endl << std::endl
std::cout << "Aufruf: " << settings->programName << " clean\n " << settings->programName << " clean --help" << std::endl << std::endl
<< "Beschreibung:" << std::endl << " Mit dieser Unterfunction kann man die Cookie-Dateien löschen." << std::endl << std::endl;
return;
}
@ -911,33 +911,6 @@ bool dirExists(std::string dir)
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()
{
#ifdef linux
char result[ PATH_MAX ];
ssize_t count = readlink( "/proc/self/exe", result, PATH_MAX );
return std::string( result, (count > 0) ? static_cast<size_t>(count) : 0 );
#endif
#ifdef V2
char buffer[MAX_PATH];
GetModuleFileName( NULL, buffer, MAX_PATH );
return buffer;
#endif
#ifdef _WIN32
wchar_t buffer[MAX_PATH];
char CharArray[MAX_PATH + 1];
memset( CharArray, 0, MAX_PATH + 1);
GetModuleFileName( nullptr, buffer, MAX_PATH );
wcstombs(CharArray, buffer, MAX_PATH + 1);
return CharArray;
#endif
}

bool fileExists (const std::string& name) {
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0 && S_ISREG(buffer.st_mode));

View File

@ -30,7 +30,8 @@ struct Settings {
Settings() {}
Settings(std::string name) : name(name) {}

std::string name,
std::string programName = "S_New4",
name,
accountFilePath = "/tmp/a",
accountNumberPath= "/tmp/a_n",
cookieFilePath = "/tmp/S_New4_cookies",
@ -66,9 +67,6 @@ int loadDefaulOptions(Settings & settings);
std::vector<std::string> compare(std::string All_Options_with_komma_between, std::string input);
bool isNumber(std::string number);

std::string getProgramName();
std::string getexepath();

int setPaths(Settings &settings);

bool fileExists (const std::string& name);
@ -76,19 +74,19 @@ bool dirExists(std::string dir);
bool nothingExists(std::string path);
bool createDirIsOk(std::string path);

int unterOption_help();
int unterOption_help(std::string programName);

int unterOption_default(Settings * settings, int argc, char **argv);
void unterOption_default_help();
void unterOption_default_help(std::string programName);

int unterOption_url(Settings * settings, int argc, char **argv);
void unterOption_url_help();
void unterOption_url_help(std::string programName);

int unterOption_search(Settings * settings, int argc, char **argv);
void unterOption_search_help();
void unterOption_search_help(std::string programName);

int unterOption_info(Settings * settings, int argc, char **argv);
void unterOption_info_help();
void unterOption_info_help(std::string programName);

void unterOption_clean(Settings * settings, int argc, char **argv);


View File

@ -170,8 +170,8 @@ int ProgramManager::defaultModus(Settings *settings)
}
} if(settings->name == "") {
std::cout << " => Error: Kein Name angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName() << " default [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << getProgramName() << " default --help\" liefert weitere Informationen." << std::endl;
std::cout << "Aufruf: " << settings->programName << " default [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << settings->programName << " default --help\" liefert weitere Informationen." << std::endl;
return 27;
}
}
@ -344,8 +344,8 @@ int ProgramManager::directLinkModus(Settings *settings)

if(settings->name == "") {
std::cout << " => Error: Kein(e) Link(s) angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName() << " url [OPTION]... [URL]..." << std::endl;
std::cout << "\"" << getProgramName() << " url --help\" liefert weitere Informationen." << std::endl;
std::cout << "Aufruf: " << settings->programName << " url [OPTION]... [URL]..." << std::endl;
std::cout << "\"" << settings->programName << " url --help\" liefert weitere Informationen." << std::endl;
return 76;
}

@ -379,8 +379,8 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo)

} else if(settings->name == "") {
std::cout << " => Error: Kein Name angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName() << " search [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << getProgramName() << " search --help\" liefert weitere Informationen." << std::endl;
std::cout << "Aufruf: " << settings->programName << " search [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << settings->programName << " search --help\" liefert weitere Informationen." << std::endl;
return 27;
}

@ -450,8 +450,8 @@ int ProgramManager::infoModus(Settings *settings)
{
if(settings->name == "") {
std::cout << " => Error: Kein Name angegeben." << std::endl;
std::cout << "Aufruf: " << getProgramName() << " info [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << getProgramName() << " info --help\" liefert weitere Informationen." << std::endl;
std::cout << "Aufruf: " << settings->programName << " info [OPTION]... [NAME]..." << std::endl;
std::cout << "\"" << settings->programName << " info --help\" liefert weitere Informationen." << std::endl;
return 27;
}