From 298a4603c6d555b41462779f188134ffd1c27a45 Mon Sep 17 00:00:00 2001 From: Markus Date: Mon, 14 Oct 2019 18:27:14 +0200 Subject: [PATCH] fix html error like 404; fix check version missing atoi --- pageManager.cpp | 3 +++ parameterManager.h | 13 +++++++++---- programManager.cpp | 19 +++++++++++-------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/pageManager.cpp b/pageManager.cpp index b9561df..ab21845 100644 --- a/pageManager.cpp +++ b/pageManager.cpp @@ -58,6 +58,7 @@ Reply PageManager::getServerRequest(std::string Url, bool useCookies, std::strin } //Settings + curl_easy_setopt(curl, CURLOPT_FAILONERROR, true); // html errors to errorcode res curl_easy_setopt(curl, CURLOPT_URL, Url.c_str()); //Url für Curl curl_easy_setopt(curl, CURLOPT_PROXY, sock5Proxy.c_str() ); //Sock5Proxy für Curl curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); //follows redirection @@ -148,6 +149,8 @@ int PageManager::downLoadToFile(std::string filePath, std::string url) /* write the page body to this file handle */ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, pagefile); + //Error 404, for example => not found + curl_easy_setopt(curl_handle, CURLOPT_FAILONERROR, true); /* get it! */ if( (res = curl_easy_perform(curl_handle)) != CURLE_OK) { diff --git a/parameterManager.h b/parameterManager.h index 05bf587..455ecbf 100644 --- a/parameterManager.h +++ b/parameterManager.h @@ -40,9 +40,14 @@ struct Settings { Settings(std::string name) : name(name) {} const std::string programName = "S_New4"; - const std::string VersionFileUrl = "https://cloud.obermui.de/s/H47Xoqy2czfJzYp/download?path=%2F&files=Version.txt"; - const std::string ProgrammFileUrl = "https://cloud.obermui.de/s/H47Xoqy2czfJzYp/download?path=%2F&files=S_New4"; - +#ifdef __linux + const std::string VersionFileUrl = "https://cloud.obermui.de/s/H47Xoqy2czfJzYp/download?path=%2F&files=Version-LINx86.txt"; + const std::string ProgrammFileUrl = "https://cloud.obermui.de/s/H47Xoqy2czfJzYp/download?path=%2F&files=S_New4-LINx86"; +#endif +#ifdef _WIN32 + const std::string VersionFileUrl = "https://cloud.obermui.de/s/H47Xoqy2czfJzYp/download?path=%2F&files=Version-WINx86.txt"; + const std::string ProgrammFileUrl = "https://cloud.obermui.de/s/H47Xoqy2czfJzYp/download?path=%2F&files=S_New4-WINx86"; +#endif std::string name, accountFilePath = "/tmp/a", accountNumberPath= "/tmp/a_n", @@ -56,7 +61,7 @@ struct Settings { proxy_ip = "127.0.0.1", languages = "GerDub,GerSub,Eng", genaueHoster = "", - version = "3.2.1", + version = "3.2.2", defaultFileVersion="1.6", outputFilePath = "", default_checkPath = "", diff --git a/programManager.cpp b/programManager.cpp index 002e4ec..f1e8f60 100644 --- a/programManager.cpp +++ b/programManager.cpp @@ -968,12 +968,15 @@ int ProgramManager::newsModus(Settings *settings) int ProgramManager::updateModus(Settings *settings) { std::cout << " => INFO: Suche nach der neusten Version..." << std::endl; - std::string html; + std::string html = pageManager.getServerRequest(settings->VersionFileUrl).html; - if( (html = pageManager.getServerRequest(settings->VersionFileUrl).html) == "-1") { + if( html == "-1" ) { if(settings->debugMode) std::cerr << " => Error: Download newst Version failed." << std::endl; return 1; + } else if ( html == "" ) { + std::cout << " => Error: Das herunterladen der neusten Version ist fehlgeschlagen." << std::endl; + return 1; } else { html = pageManager.replace(html, "\r", ""); } @@ -987,9 +990,9 @@ int ProgramManager::updateModus(Settings *settings) return 2; } - std::cout << " => INFO: Jetzige Version: " << settings->version << " - Neueste Version: " << neusteVersion << std::endl; + std::cout << " => INFO: Jetzige Version: '" << settings->version << "' - Neueste Version: '" << neusteVersion << "'" << std::endl; - if(pageManager.replace(neusteVersion, ".", "") <= pageManager.replace(settings->version, ".", "")) { + if( atoi(pageManager.replace(neusteVersion, ".", "").c_str()) <= atoi(pageManager.replace(settings->version, ".", "").c_str()) ) { std::cout << " => Du benützt bereits die neuste Release-Version." << std::endl; return 0; } @@ -1015,26 +1018,26 @@ int ProgramManager::updateModus(Settings *settings) if( system((downloadedFilePath + " --version" ).c_str()) != 0) { perror(" => Error: Ausführen der neuen Version ist fehlgeschlagen"); - return 4; + return 5; } std::string exePath = pageManager.getExePath(); if(exePath == "") { std::cout << " => Error: Function getExepath() ist fehlgeschlagen." << std::endl; - return 5; + return 6; } std::cout << " => INFO: Ersetzte alte Version mit neuer Version des Programms..." << std::endl; if(rename(downloadedFilePath.c_str(), exePath.c_str() ) != 0) { perror(("Mv '" + downloadedFilePath + "' -> '" + exePath + "' failed").c_str()); - return 6; + return 7; } else { 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; }