forked from markus/S_New4
fix html error like 404; fix check version missing atoi
This commit is contained in:
parent
03332c66d6
commit
298a4603c6
@ -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) {
|
||||
|
@ -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 = "",
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user