forked from markus/S_New4
überarbeite alles + überarbeitete infoausgabe + zu parametern als usb function hinzugefügt
This commit is contained in:
parent
f2f9a37a64
commit
03332c66d6
@ -70,7 +70,7 @@ int manageParameter(Settings &settings, int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean\nnews", argv[1]);
|
std::vector<std::string> res = compare("--help\ndefault\nurl\n--version\nsearch\ninfo\nclean\nnews\n--update", argv[1]);
|
||||||
if(res.size() != 1) {
|
if(res.size() != 1) {
|
||||||
if(res.size() == 0)
|
if(res.size() == 0)
|
||||||
std::cout << " => Error: Keine Unteroption für " << argv[1] << " gefunden." << std::endl;
|
std::cout << " => Error: Keine Unteroption für " << argv[1] << " gefunden." << std::endl;
|
||||||
@ -82,8 +82,7 @@ int manageParameter(Settings &settings, int argc, char **argv)
|
|||||||
std::cout << "Aufruf: " << settings.programName << " [Unteroption] [PARAMETER]" << std::endl;
|
std::cout << "Aufruf: " << settings.programName << " [Unteroption] [PARAMETER]" << std::endl;
|
||||||
std::cout << "\"" << settings.programName << " --help\" liefert weitere Informationen." << std::endl;
|
std::cout << "\"" << settings.programName << " --help\" liefert weitere Informationen." << std::endl;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
} res.clear();
|
||||||
res.clear();
|
|
||||||
|
|
||||||
|
|
||||||
if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) {
|
if(strncmp(argv[1], "--help", strlen(argv[1])) == 0) {
|
||||||
@ -99,17 +98,7 @@ int manageParameter(Settings &settings, int argc, char **argv)
|
|||||||
return unterOption_url(&settings, argc, argv);
|
return unterOption_url(&settings, argc, argv);
|
||||||
|
|
||||||
} else if (strncmp(argv[1], "--version", strlen(argv[1])) == 0) {
|
} else if (strncmp(argv[1], "--version", strlen(argv[1])) == 0) {
|
||||||
std::cout << "Programinfos:" << std::endl
|
unterOption_printVersion(settings);
|
||||||
<< " > Program Version: " << settings.version << std::endl
|
|
||||||
<< " > Defaults Datei Version: " << settings.defaultFileVersion << std::endl
|
|
||||||
<< " > C++ Standart: ";
|
|
||||||
if(__cplusplus == 1) std::cout << "C++_Pre_C++98" << std::endl;
|
|
||||||
else if (__cplusplus == 199711) std::cout << "C++98" << std::endl;
|
|
||||||
else if (__cplusplus == 201103) std::cout << "C++11" << std::endl;
|
|
||||||
else if (__cplusplus == 201402) std::cout << "C++14" << std::endl;
|
|
||||||
else if (__cplusplus == 201703) std::cout << "C++17" << std::endl;
|
|
||||||
else std::cout << "C++_Newer_C++17" << std::endl;
|
|
||||||
std::cout << " > " << sizeof (void *) * 8 << " Bit Version" << std::endl;
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
} else if (strncmp(argv[1], "search", strlen(argv[1])) == 0) {
|
} else if (strncmp(argv[1], "search", strlen(argv[1])) == 0) {
|
||||||
@ -129,12 +118,31 @@ int manageParameter(Settings &settings, int argc, char **argv)
|
|||||||
argv[1][0] = '\0';
|
argv[1][0] = '\0';
|
||||||
return unterOption_news(&settings, argc, argv);
|
return unterOption_news(&settings, argc, argv);
|
||||||
|
|
||||||
|
} else if (strncmp(argv[1], "--update", strlen(argv[1])) == 0) {
|
||||||
|
argv[1][0] = '\0';
|
||||||
|
return unterOption_update(&settings, argc, argv);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
std::cout << " => Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl;
|
std::cout << " => Error: Invalid option " << argv[1] << ", but not detected in compare-Function" << std::endl;
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void unterOption_printVersion(Settings &settings)
|
||||||
|
{
|
||||||
|
std::cout << "Programinfos:" << std::endl
|
||||||
|
<< " > Program Version: " << settings.version << std::endl
|
||||||
|
<< " > Defaults Datei Version: " << settings.defaultFileVersion << std::endl
|
||||||
|
<< " > C++ Standart: ";
|
||||||
|
if(__cplusplus == 1) std::cout << "C++_Pre_C++98" << std::endl;
|
||||||
|
else if (__cplusplus == 199711) std::cout << "C++98" << std::endl;
|
||||||
|
else if (__cplusplus == 201103) std::cout << "C++11" << std::endl;
|
||||||
|
else if (__cplusplus == 201402) std::cout << "C++14" << std::endl;
|
||||||
|
else if (__cplusplus == 201703) std::cout << "C++17" << std::endl;
|
||||||
|
else std::cout << "C++_Newer_C++17" << std::endl;
|
||||||
|
std::cout << " > " << sizeof (void *) * 8 << " Bit Version" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
int loadDefaulOptions(Settings &settings)
|
int loadDefaulOptions(Settings &settings)
|
||||||
{
|
{
|
||||||
std::fstream ifs(settings.defaultsFilePath);
|
std::fstream ifs(settings.defaultsFilePath);
|
||||||
@ -332,6 +340,7 @@ int unterOption_help(Settings &settings)
|
|||||||
std::cout << "Unteroptionen:" << std::endl
|
std::cout << "Unteroptionen:" << std::endl
|
||||||
<< "\t\"--help\"\tGibt dieses Helpmenue aus." << std::endl
|
<< "\t\"--help\"\tGibt dieses Helpmenue aus." << std::endl
|
||||||
<< "\t\"--version\"\tGibt die Version des Programmes aus." << std::endl
|
<< "\t\"--version\"\tGibt die Version des Programmes aus." << std::endl
|
||||||
|
<< "\t\"--update\"\tModus um das Programm zu aktualisieren." << std::endl
|
||||||
<< "\t\"url\"\t\tModus um eigene Redirect-Links umzuwandeln." << 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\"default\"\tModus um Links von Serien zu bekommen." << std::endl
|
||||||
<< "\t\"search\"\tModus um Serien zu suchen." << std::endl
|
<< "\t\"search\"\tModus um Serien zu suchen." << std::endl
|
||||||
@ -1151,8 +1160,8 @@ int unterOption_news(Settings *settings, int argc, char **argv)
|
|||||||
std::cout << "Debug Modus: true" << std::endl;
|
std::cout << "Debug Modus: true" << std::endl;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
std::cout << "Aufruf: " << settings->programName << " info [OPTION]... [NAME]..." << std::endl;
|
std::cout << "Aufruf: " << settings->programName << " news [OPTION]..." << std::endl;
|
||||||
std::cout << "\"" << settings->programName << " info --help\" liefert weitere Informationen." << std::endl;
|
std::cout << "\"" << settings->programName << " news --help\" liefert weitere Informationen." << std::endl;
|
||||||
return 21;
|
return 21;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1183,3 +1192,64 @@ void unterOption_news_help(std::string programName)
|
|||||||
<< " -h, --help" << std::endl
|
<< " -h, --help" << std::endl
|
||||||
<< " Mit dieser Option wird dieses Helpmenue ausgegeben." << std::endl;
|
<< " Mit dieser Option wird dieses Helpmenue ausgegeben." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int unterOption_update(Settings *settings, int argc, char **argv)
|
||||||
|
{
|
||||||
|
settings->modus = Modus::UPDATE_MODUS;
|
||||||
|
|
||||||
|
int c = 0;
|
||||||
|
const option long_opts[] = {
|
||||||
|
{"socks5-proxy", required_argument, nullptr, 'p'},
|
||||||
|
|
||||||
|
{"help", no_argument, nullptr, 'h'},
|
||||||
|
{"debug-mode", no_argument, nullptr, 'd'},
|
||||||
|
|
||||||
|
{nullptr, no_argument, nullptr, 0}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
while( ( c = getopt_long (argc, argv, "p:hd", long_opts, nullptr) ) != -1 ) {
|
||||||
|
switch(c) {
|
||||||
|
case 'p':
|
||||||
|
if(optarg && setS5ProxytoSettings(*settings, optarg) != 0)
|
||||||
|
return 2;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
unterOption_update_help(settings->programName);
|
||||||
|
return -1;
|
||||||
|
case 'd':
|
||||||
|
settings->debugMode = true;
|
||||||
|
if(settings->debugMode)
|
||||||
|
std::cout << "Debug Modus: true" << std::endl;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
std::cout << "Aufruf: " << settings->programName << " --update [OPTION]..." << std::endl;
|
||||||
|
std::cout << "\"" << settings->programName << " --update --help\" liefert weitere Informationen." << std::endl;
|
||||||
|
return 21;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(settings->debugMode)
|
||||||
|
std::cout << "Modus: Search_MODUS" << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unterOption_update_help(std::string programName)
|
||||||
|
{
|
||||||
|
std::cout << "Aufruf: " << programName << " --update [OPTION]..." << std::endl << std::endl;
|
||||||
|
|
||||||
|
std::cout << "Beschreibung:" << std::endl
|
||||||
|
<< " Mit dieser Unterfunktion kann man das Programm updaten." << std::endl << std::endl;
|
||||||
|
|
||||||
|
std::cout << "OPTIONEN:" << std::endl
|
||||||
|
<< " -p [ip:port/ip/port], --socks5-proxy [ip:port/ip/port]" << std::endl
|
||||||
|
<< " Mit dieser Option kann man den Socks5Proxy ändern." << std::endl
|
||||||
|
<< " Standart: 127.0.0.1:9050" << std::endl << std::endl
|
||||||
|
<< " -d, --debug-mode" << std::endl
|
||||||
|
<< " Mit dieser Option kann man den Debug-Modus einschalten." << std::endl
|
||||||
|
<< " Dabei werden vielmehr Infos ausgegeben." << std::endl << std::endl
|
||||||
|
<< " -h, --help" << std::endl
|
||||||
|
<< " Mit dieser Option wird dieses Helpmenue ausgegeben." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,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.2.0",
|
version = "3.2.1",
|
||||||
defaultFileVersion="1.6",
|
defaultFileVersion="1.6",
|
||||||
outputFilePath = "",
|
outputFilePath = "",
|
||||||
default_checkPath = "",
|
default_checkPath = "",
|
||||||
@ -94,6 +94,7 @@ bool createDirIsOk(std::string path);
|
|||||||
bool makePathIsOk(std::string path);
|
bool makePathIsOk(std::string path);
|
||||||
|
|
||||||
int unterOption_help(Settings &settings);
|
int unterOption_help(Settings &settings);
|
||||||
|
void unterOption_printVersion(Settings &settings);
|
||||||
|
|
||||||
int unterOption_default(Settings * settings, int argc, char **argv);
|
int unterOption_default(Settings * settings, int argc, char **argv);
|
||||||
void unterOption_default_help(std::string programName);
|
void unterOption_default_help(std::string programName);
|
||||||
@ -112,6 +113,8 @@ void unterOption_clean(Settings * settings, int argc, char **argv);
|
|||||||
int unterOption_news(Settings * settings, int argc, char **argv);
|
int unterOption_news(Settings * settings, int argc, char **argv);
|
||||||
void unterOption_news_help(std::string programName);
|
void unterOption_news_help(std::string programName);
|
||||||
|
|
||||||
|
int unterOption_update(Settings * settings, int argc, char **argv);
|
||||||
|
void unterOption_update_help(std::string programName);
|
||||||
|
|
||||||
int setS5ProxytoSettings(Settings &settings, std::string optarg);
|
int setS5ProxytoSettings(Settings &settings, std::string optarg);
|
||||||
|
|
||||||
|
@ -27,9 +27,6 @@ int ProgramManager::start(Settings *settings)
|
|||||||
return 174;
|
return 174;
|
||||||
}
|
}
|
||||||
|
|
||||||
settings->modus = UPDATE_MODUS;
|
|
||||||
|
|
||||||
|
|
||||||
switch (settings->modus) {
|
switch (settings->modus) {
|
||||||
case Modus::DEFAULT_MODUS:
|
case Modus::DEFAULT_MODUS:
|
||||||
return defaultModus(settings);
|
return defaultModus(settings);
|
||||||
@ -970,12 +967,12 @@ int ProgramManager::newsModus(Settings *settings)
|
|||||||
|
|
||||||
int ProgramManager::updateModus(Settings *settings)
|
int ProgramManager::updateModus(Settings *settings)
|
||||||
{
|
{
|
||||||
std::cout << "Check newst Version..." << std::endl;
|
std::cout << " => INFO: Suche nach der neusten Version..." << std::endl;
|
||||||
std::string html;
|
std::string html;
|
||||||
|
|
||||||
if( (html = pageManager.getServerRequest(settings->VersionFileUrl).html) == "-1") {
|
if( (html = pageManager.getServerRequest(settings->VersionFileUrl).html) == "-1") {
|
||||||
if(settings->debugMode)
|
if(settings->debugMode)
|
||||||
std::cerr << "Download newst Version failed" << std::endl;
|
std::cerr << " => Error: Download newst Version failed." << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
html = pageManager.replace(html, "\r", "");
|
html = pageManager.replace(html, "\r", "");
|
||||||
@ -990,55 +987,54 @@ int ProgramManager::updateModus(Settings *settings)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Neueste Version: " << neusteVersion << " diese Version " << settings->version << std::endl;
|
std::cout << " => INFO: Jetzige Version: " << settings->version << " - Neueste Version: " << neusteVersion << std::endl;
|
||||||
|
|
||||||
if(pageManager.replace(neusteVersion, ".", "") <= pageManager.replace(settings->version, ".", "")) {
|
if(pageManager.replace(neusteVersion, ".", "") <= pageManager.replace(settings->version, ".", "")) {
|
||||||
std::cout << " => INFO: Du benützt bereits die neuste Release-Version." << std::endl;
|
std::cout << " => Du benützt bereits die neuste Release-Version." << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Lade Dateien herunter..." << std::endl;
|
std::cout << " => INFO: Lade neue Version herunter..." << std::endl;
|
||||||
|
|
||||||
std::string downloadedFilePath = settings->cacheDir + "NeusteVersion" + ((settings->pathSymbol == '\\') ? ".exe" : "");
|
std::string downloadedFilePath = settings->cacheDir + "NeusteVersion" + ((settings->pathSymbol == '\\') ? ".exe" : "");
|
||||||
if( pageManager.downLoadToFile(downloadedFilePath, settings->ProgrammFileUrl) != 0) {
|
if( pageManager.downLoadToFile(downloadedFilePath, settings->ProgrammFileUrl) != 0) {
|
||||||
if(settings->debugMode)
|
std::cerr << " => Error: Download new Version failed." << std::endl;
|
||||||
std::cerr << "Download new Version failed" << std::endl;
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
std::cout << "Mache das Programm ausführbar..." << std::endl;
|
std::cout << " => INFO: Mache das Programm ausführbar..." << std::endl;
|
||||||
chmod(downloadedFilePath.c_str(), S_IRWXU);
|
if(chmod(downloadedFilePath.c_str(), S_IRWXU) != 0) {
|
||||||
|
perror(" => Error: Chmod failed");
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::cout << "Überprüfe funktionalität der neuen Version..." << std::endl;
|
std::cout << " => INFO: Überprüfe die Funktionalität der neuen Version..." << std::endl;
|
||||||
|
|
||||||
if( system((downloadedFilePath + " --version" ).c_str()) != 0) {
|
if( system((downloadedFilePath + " --version" ).c_str()) != 0) {
|
||||||
perror("Ausführen der neues Version fehlgeschlagen");
|
perror(" => Error: Ausführen der neuen Version ist fehlgeschlagen");
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string exePath = pageManager.getExePath();
|
std::string exePath = pageManager.getExePath();
|
||||||
if(exePath == "") {
|
if(exePath == "") {
|
||||||
std::cout << "getExepath failed" << std::endl;
|
std::cout << " => Error: Function getExepath() ist fehlgeschlagen." << std::endl;
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Ersetzte jetzige Version mit neuer Version des Programms..." << std::endl;
|
std::cout << " => INFO: Ersetzte alte Version mit neuer Version des Programms..." << std::endl;
|
||||||
|
|
||||||
if(rename(downloadedFilePath.c_str(), exePath.c_str() ) != 0) {
|
if(rename(downloadedFilePath.c_str(), exePath.c_str() ) != 0) {
|
||||||
perror("Mv failed");
|
perror(("Mv '" + downloadedFilePath + "' -> '" + exePath + "' failed").c_str());
|
||||||
return 6;
|
return 6;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Erfolgreich verschoben: '" << downloadedFilePath << "' -> '" << exePath << "'" << std::endl;
|
std::cout << " => INFO: Erfolgreich verschoben und ersetzt:\n '"
|
||||||
|
<< downloadedFilePath << "' -> '" << exePath << "'" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << " => Update Erfolgreich ausgeführt: " << settings->version << " -> " << neusteVersion << std::endl;
|
||||||
std::cout << "Update Erfolgreich ausgeführt:" << settings->version << " -> " << neusteVersion << std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user