forked from markus/S_New4
überarbeitete update function ( mit löschen der dateien (bei windows nötig) und verschieben der exe datei (für windows nötig))
This commit is contained in:
parent
42f66b673f
commit
4917d25fc9
@ -60,7 +60,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.8",
|
version = "3.3.0",
|
||||||
defaultFileVersion="1.6",
|
defaultFileVersion="1.6",
|
||||||
outputFilePath = "",
|
outputFilePath = "",
|
||||||
default_checkPath = "",
|
default_checkPath = "",
|
||||||
|
@ -970,12 +970,13 @@ int ProgramManager::updateModus(Settings *settings)
|
|||||||
std::cout << " => INFO: Suche nach der neusten Version..." << std::endl;
|
std::cout << " => INFO: Suche nach der neusten Version..." << std::endl;
|
||||||
std::string html = pageManager.getServerRequest(settings->VersionFileUrl).html;
|
std::string html = pageManager.getServerRequest(settings->VersionFileUrl).html;
|
||||||
|
|
||||||
if( html == "-1" ) {
|
if( html == "-1" || html == "") {
|
||||||
|
// Wenn debug mode print error
|
||||||
if(settings->debugMode)
|
if(settings->debugMode)
|
||||||
std::cerr << " => Error: Download newst Version failed." << std::endl;
|
std::cerr << " => Error: Download newst Version failed." << std::endl;
|
||||||
return 1;
|
// no error output in pagemanager => print error
|
||||||
} else if ( html == "" ) {
|
else if(html == "")
|
||||||
std::cout << " => Error: Das herunterladen der neusten Version ist fehlgeschlagen." << std::endl;
|
std::cout << " => Error: Das herunterladen der neusten Version ist fehlgeschlagen." << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
html = pageManager.replace(html, "\r", "");
|
html = pageManager.replace(html, "\r", "");
|
||||||
@ -991,6 +992,7 @@ int ProgramManager::updateModus(Settings *settings)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Gib Versionenunterschie aus
|
||||||
std::cout << " => INFO: Jetzige Version: '" << settings->version << "' - Neueste Version: '" << neusteVersion << "'" << std::endl;
|
std::cout << " => INFO: Jetzige Version: '" << settings->version << "' - Neueste Version: '" << neusteVersion << "'" << std::endl;
|
||||||
|
|
||||||
//Print INFOs
|
//Print INFOs
|
||||||
@ -1008,20 +1010,25 @@ int ProgramManager::updateModus(Settings *settings)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//lege pfad zum speichern fest
|
||||||
|
std::string downloadedFilePath = settings->cacheDir + "NeusteVersion" + ((settings->pathSymbol == '\\') ? ".exe" : "");
|
||||||
|
|
||||||
|
//wenn dort schon eine datei existiert, lösche diese
|
||||||
|
std::cout << " => INFO: Lösche Download-Datei, fallst bereits eine vorhanden ist..." << std::endl;
|
||||||
|
if(fileExists(downloadedFilePath)) {
|
||||||
|
if(remove(downloadedFilePath.c_str()) != 0) {
|
||||||
|
perror((" => Error: Das löschen der Datei '" + downloadedFilePath + "' ist fehlgeschlagen").c_str());
|
||||||
|
return 13;
|
||||||
|
} else if (settings->debugMode) {
|
||||||
|
std::cout << " => DEBUG: Erfolgreich alte gedownloadete Datei '" << downloadedFilePath << "' gelöscht." << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Download new Version of Program
|
//Download new Version of Program
|
||||||
std::cout << " => INFO: Lade neue Version herunter..." << std::endl;
|
std::cout << " => INFO: Lade neue Version herunter..." << std::endl;
|
||||||
|
|
||||||
std::string downloadedFilePath = settings->cacheDir + "NeusteVersion" + ((settings->pathSymbol == '\\') ? ".exe" : "");
|
|
||||||
if(fileExists(downloadedFilePath))
|
|
||||||
if(remove(downloadedFilePath.c_str()) != 0) {
|
|
||||||
perror("Failed to remove existing file");
|
|
||||||
return 13;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( pageManager.downLoadToFile(downloadedFilePath, settings->ProgrammFileUrl) != 0) {
|
if( pageManager.downLoadToFile(downloadedFilePath, settings->ProgrammFileUrl) != 0) {
|
||||||
std::cerr << "\n => Error: Download new Version failed." << std::endl;
|
std::cout << "\n => Error: Das herunterladen der neuen Version ist fehlgeschlagen." << std::endl;
|
||||||
return 3;
|
return 3;
|
||||||
} std::cout << std::endl;
|
} std::cout << std::endl;
|
||||||
|
|
||||||
@ -1043,34 +1050,40 @@ int ProgramManager::updateModus(Settings *settings)
|
|||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
//ersezte alte version mit neuer
|
//find exePath heraus
|
||||||
std::string exePath = pageManager.getExePath();
|
std::string exePath = pageManager.getExePath();
|
||||||
if(exePath == "") {
|
if(exePath == "") {
|
||||||
std::cout << " => Error: Function getExepath() ist fehlgeschlagen." << std::endl;
|
std::cout << " => Error: Function getExepath() ist fehlgeschlagen." << std::endl;
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
//lege pfad für alte version fest
|
||||||
std::cout << " => INFO: Verschiebe alte Version..." << std::endl;
|
std::string oldVersionPah = settings->cacheDir + "oldVersion" + ((settings->pathSymbol == '\\') ? ".exe" : "");
|
||||||
if(fileExists(settings->cacheDir + "oldVersion.exe")) {
|
|
||||||
if(remove( (settings->cacheDir + "oldVersion.exe").c_str() ) != 0) {
|
//lösche falls vorhanden altes backup
|
||||||
perror("Failed to remove existing file");
|
std::cout << " => INFO: Lösche alte Nofall Version falls vorhanden..." << std::endl;
|
||||||
|
if(fileExists(oldVersionPah)) {
|
||||||
|
if(remove( oldVersionPah.c_str() ) != 0) {
|
||||||
|
perror((" => Error: Das löschen der Datei '" + oldVersionPah + "' ist fehlgeschlagen.").c_str());
|
||||||
return 14;
|
return 14;
|
||||||
|
} else if (settings->debugMode) {
|
||||||
|
std::cout << " => DEBUG: Erfolgreich Notfall Version '" << oldVersionPah << "' gelöscht." << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(rename(exePath.c_str(), (settings->cacheDir + "oldVersion.exe").c_str() ) != 0) {
|
|
||||||
perror(("Mv '" + exePath + "' -> '" + settings->cacheDir + "oldVersion.exe' failed").c_str());
|
//verschiebe neue jetzige version zu backup
|
||||||
|
std::cout << " => INFO: Verschiebe alte Version für Notfälle zu: '" << oldVersionPah << "'." << std::endl;
|
||||||
|
|
||||||
|
if(rename(exePath.c_str(), oldVersionPah.c_str() ) != 0) {
|
||||||
|
perror((" => Error das Verschieben von '" + exePath + "' -> '" + oldVersionPah + "' ist fehlgeschlagen").c_str());
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
//verschibe neue Version
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::cout << " => INFO: Ersetzte alte 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 '" + downloadedFilePath + "' -> '" + exePath + "' failed").c_str());
|
perror((" => Error: Das Verschieben von '" + downloadedFilePath + "' nach '" + exePath + "' ist fehlgeschlagen").c_str());
|
||||||
return 7;
|
return 7;
|
||||||
} else {
|
} else {
|
||||||
std::cout << " => INFO: Erfolgreich verschoben und ersetzt:\n '"
|
std::cout << " => INFO: Erfolgreich verschoben und ersetzt:\n '"
|
||||||
|
Loading…
Reference in New Issue
Block a user