forked from markus/S_New4
v3.2.0: add updater tests
This commit is contained in:
parent
0bda3b6c4c
commit
27b33bfad4
@ -43,6 +43,9 @@ int setPaths(Settings &settings)
|
|||||||
settings.serienListPath = SettingsDir + "SerienListe";
|
settings.serienListPath = SettingsDir + "SerienListe";
|
||||||
settings.defaultsFilePath = SettingsDir + "Defaults";
|
settings.defaultsFilePath = SettingsDir + "Defaults";
|
||||||
|
|
||||||
|
settings.cacheDir = CacheDir;
|
||||||
|
settings.configDir = SettingsDir;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,8 @@ enum Modus {
|
|||||||
DIRECT_LINK_MODUS = 1,
|
DIRECT_LINK_MODUS = 1,
|
||||||
SEARCH_MODUS = 2,
|
SEARCH_MODUS = 2,
|
||||||
INFO_MODUS = 3,
|
INFO_MODUS = 3,
|
||||||
NEWS_MODUS = 4
|
NEWS_MODUS = 4,
|
||||||
|
UPDATE_MODUS = 5
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -39,18 +40,22 @@ struct Settings {
|
|||||||
Settings(std::string name) : name(name) {}
|
Settings(std::string name) : name(name) {}
|
||||||
|
|
||||||
const std::string programName = "S_New4";
|
const std::string programName = "S_New4";
|
||||||
|
const std::string VersionFileUrl = "https://cloud.obermui.de/s/cLRYJQAMqWDFt5g/download";
|
||||||
|
|
||||||
std::string name,
|
std::string name,
|
||||||
accountFilePath = "/tmp/a",
|
accountFilePath = "/tmp/a",
|
||||||
accountNumberPath= "/tmp/a_n",
|
accountNumberPath= "/tmp/a_n",
|
||||||
cookieFilePath = "/tmp/S_New4_cookies",
|
cookieFilePath = "/tmp/S_New4_cookies",
|
||||||
serienListPath = "/tmp/SerienListe",
|
serienListPath = "/tmp/SerienListe",
|
||||||
lastUpdateDateFilePath = "/tmp/lastUpdateDateFile",
|
lastUpdateDateFilePath = "/tmp/lastUpdateDateFile",
|
||||||
|
configDir="/tmp/",
|
||||||
|
cacheDir="/tmp/",
|
||||||
|
|
||||||
defaultsFilePath = "/tmp/defaults",
|
defaultsFilePath = "/tmp/defaults",
|
||||||
proxy_ip = "127.0.0.1",
|
proxy_ip = "127.0.0.1",
|
||||||
languages = "GerDub,GerSub,Eng",
|
languages = "GerDub,GerSub,Eng",
|
||||||
genaueHoster = "",
|
genaueHoster = "",
|
||||||
version = "3.1.1",
|
version = "3.2.0",
|
||||||
defaultFileVersion="1.6",
|
defaultFileVersion="1.6",
|
||||||
outputFilePath = "",
|
outputFilePath = "",
|
||||||
default_checkPath = "",
|
default_checkPath = "",
|
||||||
|
@ -27,6 +27,9 @@ 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);
|
||||||
@ -38,6 +41,8 @@ int ProgramManager::start(Settings *settings)
|
|||||||
return infoModus(settings);
|
return infoModus(settings);
|
||||||
case Modus::NEWS_MODUS:
|
case Modus::NEWS_MODUS:
|
||||||
return newsModus(settings);
|
return newsModus(settings);
|
||||||
|
case Modus::UPDATE_MODUS:
|
||||||
|
return updateModus(settings);
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -960,6 +965,103 @@ int ProgramManager::newsModus(Settings *settings)
|
|||||||
<< ((settings->colorless) ? "" : "\033[92m") << id << ((settings->colorless) ? "" : "\033[0m") << std::endl;
|
<< ((settings->colorless) ? "" : "\033[92m") << id << ((settings->colorless) ? "" : "\033[0m") << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <zip.h>
|
||||||
|
|
||||||
|
int ProgramManager::updateModus(Settings *settings)
|
||||||
|
{
|
||||||
|
std::cout << "Check newst Version..." << std::endl;
|
||||||
|
std::string html;
|
||||||
|
|
||||||
|
if( (html = pageManager.getServerRequest(settings->VersionFileUrl).html) == "-1") {
|
||||||
|
if(settings->debugMode)
|
||||||
|
std::cerr << "Download newst Version file failed" << std::endl;
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
html = pageManager.replace(html, "\r", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get newst Version
|
||||||
|
std::stringstream strstream(html+ "\n");
|
||||||
|
std::string neusteVersion, dieseVersion;
|
||||||
|
std::getline(strstream, neusteVersion);
|
||||||
|
if( !isNumber( (neusteVersion = pageManager.replace(neusteVersion, ".", "")) ) ) {
|
||||||
|
std::cout << " => Error: Gedownloadete neuste Version ist ungültig: '" << neusteVersion << "'" << std::endl;
|
||||||
|
return 2;
|
||||||
|
} else {
|
||||||
|
dieseVersion = pageManager.replace(settings->version, ".", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Neueste Version: " << neusteVersion << " diese Version " << dieseVersion << std::endl;
|
||||||
|
|
||||||
|
if(neusteVersion <= dieseVersion) {
|
||||||
|
std::cout << " => INFO: Du benützt bereits die neuste Release-Version." << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Lade Dateien herunter..." << std::endl;
|
||||||
|
|
||||||
|
std::string downloadUrl;
|
||||||
|
std::getline(strstream, downloadUrl);
|
||||||
|
if(downloadUrl.find("/download") == std::string::npos) {
|
||||||
|
std::cout << " => Error: Gedownloadete Datei hat ungültigen DownloadLink: '" << downloadUrl << "'" << std::endl;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string downloadedFilePath = settings->cacheDir + "NeusteVersion" + ((settings->pathSymbol == '\\') ? ".exe" : "");
|
||||||
|
if( pageManager.downLoadToFile(downloadedFilePath, downloadUrl) != 0) {
|
||||||
|
if(settings->debugMode)
|
||||||
|
std::cerr << "Download new Version failed" << std::endl;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "Mache das Programm ausführbar..." << std::endl;
|
||||||
|
#ifdef __linux__
|
||||||
|
chmod(downloadedFilePath.c_str(), S_IRWXU);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::cout << "Überprüfe funktionalität der neuen Version..." << std::endl;
|
||||||
|
|
||||||
|
if( system((downloadedFilePath + " --version" ).c_str()) != 0) {
|
||||||
|
perror("Ausführen der neues Version fehlgeschlagen");
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string exePath;
|
||||||
|
#ifdef __linux__
|
||||||
|
char result[PATH_MAX + 1];
|
||||||
|
if(readlink("/proc/self/exe", result, PATH_MAX) == -1) {
|
||||||
|
perror("Readlink failed");
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
exePath = result;
|
||||||
|
#endif
|
||||||
|
#ifdef _WIN32
|
||||||
|
wchar_t buffer[MAX_PATH + 1];
|
||||||
|
GetModuleFileName( nullptr, buffer, MAX_PATH );
|
||||||
|
std::wstring wstr(buffer);
|
||||||
|
exePath = std::string(wstr.begin(), wstr.end());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::cout << "Ersetzte jetzige Version mit neuer Version des Programms..." << std::endl;
|
||||||
|
|
||||||
|
if(rename(downloadedFilePath.c_str(), exePath.c_str()) != 0) {
|
||||||
|
perror("Mv failed");
|
||||||
|
return 6;
|
||||||
|
} else {
|
||||||
|
std::cout << "Erfolgreich verschoben: '" << downloadedFilePath << "' -> '" << exePath << "'" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "Update Erfolgreich ausgeführt." << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ private:
|
|||||||
int searchModus(Settings * settings, std::string *saveTo = nullptr, bool noPrint = false);
|
int searchModus(Settings * settings, std::string *saveTo = nullptr, bool noPrint = false);
|
||||||
int infoModus(Settings * settings);
|
int infoModus(Settings * settings);
|
||||||
int newsModus(Settings *settings);
|
int newsModus(Settings *settings);
|
||||||
|
int updateModus(Settings *settings);
|
||||||
|
|
||||||
PageManager pageManager;
|
PageManager pageManager;
|
||||||
std::vector<ThreadData*> threadList;
|
std::vector<ThreadData*> threadList;
|
||||||
|
Loading…
Reference in New Issue
Block a user