forked from markus/S_New4
v3.3.1: better VersionCheck
This commit is contained in:
parent
4917d25fc9
commit
7ae7f4ed83
@ -383,6 +383,47 @@ std::string PageManager::getExePath()
|
||||
return std::string(wstr.begin(), wstr.end());
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
int PageManager::compareVersions(std::string Version1, std::string Version2)
|
||||
{
|
||||
std::string StringList[2] = { ( Version1 + "." ), ( Version2 + "." ) };
|
||||
int Versions[2][3];
|
||||
size_t pos;
|
||||
|
||||
//Für beide Versionen:
|
||||
for (int n = 0; n < 2; ++n) {
|
||||
//Für 3 Punkte:
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
//Wenn kein Punkt gefunden werden konnte => Error:
|
||||
if( (pos = StringList[n].find(".")) == std::string::npos) {
|
||||
std::cout << " => Error: Ungültige ProgrammVersion: '" << ( (n == 0) ? Version1 : Version2 ) << "'" << std::endl;
|
||||
return -1;
|
||||
//wenn punkt gefunden werden konnte
|
||||
} else {
|
||||
//Wenn der Teilstring keine Zahl ist error:
|
||||
if( !isNumber(StringList[n].substr(0, pos)) ) {
|
||||
std::cout << " => Error: Ungültige ProgrammVersion: (Keine Zahl): '" << ( (n == 0) ? Version1 : Version2 ) << "'" << std::endl;
|
||||
return -1;
|
||||
} else {
|
||||
//Sonst speicher Zahl in array und entferne den anfang des strings
|
||||
Versions[n][i] = atoi(StringList[n].substr(0, pos).c_str());
|
||||
StringList[n].erase(0, pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
if(Versions[0][i] > Versions[1][i]) {
|
||||
return 2;
|
||||
} else if(Versions[0][i] < Versions[1][i]) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
int PageManager::writeToFile(std::string path, std::string text)
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "accountManager.h"
|
||||
#include "curl/curl.h"
|
||||
#include "parameterManager.h" // for isNumber
|
||||
|
||||
#include <sstream>
|
||||
#include <unistd.h> // sleep
|
||||
@ -45,6 +46,8 @@ public:
|
||||
size_t getDate();
|
||||
std::string getExePath();
|
||||
|
||||
int compareVersions(std::string Version1, std::string Version2);
|
||||
|
||||
int writeToFile(std::string path, std::string text);
|
||||
|
||||
const std::string UrlPraefix = "https://s.to/serie/stream/";
|
||||
|
@ -34,6 +34,7 @@ enum Modus {
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct Settings {
|
||||
Settings() {}
|
||||
Settings(std::string name) : name(name) {}
|
||||
@ -60,7 +61,7 @@ struct Settings {
|
||||
proxy_ip = "127.0.0.1",
|
||||
languages = "GerDub,GerSub,Eng",
|
||||
genaueHoster = "",
|
||||
version = "3.3.0",
|
||||
version = "3.3.1",
|
||||
defaultFileVersion="1.6",
|
||||
outputFilePath = "",
|
||||
default_checkPath = "",
|
||||
|
@ -970,7 +970,7 @@ int ProgramManager::updateModus(Settings *settings)
|
||||
std::cout << " => INFO: Suche nach der neusten Version..." << std::endl;
|
||||
std::string html = pageManager.getServerRequest(settings->VersionFileUrl).html;
|
||||
|
||||
if( html == "-1" || html == "") {
|
||||
if( html == "-1" || html == "" || html.find("\n") == std::string::npos) {
|
||||
// Wenn debug mode print error
|
||||
if(settings->debugMode)
|
||||
std::cerr << " => Error: Download newst Version failed." << std::endl;
|
||||
@ -982,15 +982,10 @@ int ProgramManager::updateModus(Settings *settings)
|
||||
html = pageManager.replace(html, "\r", "");
|
||||
}
|
||||
|
||||
|
||||
// Get newst Version
|
||||
std::stringstream strstream(html+ "\n");
|
||||
html.clear();
|
||||
std::string neusteVersion;
|
||||
std::getline(strstream, neusteVersion);
|
||||
if( !isNumber( (pageManager.replace(neusteVersion, ".", "")) ) ) {
|
||||
std::cout << " => Error: Gedownloadete neuste Version ist ungültig: '" << neusteVersion << "'" << std::endl;
|
||||
return 2;
|
||||
}
|
||||
std::string neusteVersion = html.substr(0, html.find("\n"));
|
||||
html.erase(0, html.find("\n") + 1);
|
||||
|
||||
//Gib Versionenunterschie aus
|
||||
std::cout << " => INFO: Jetzige Version: '" << settings->version << "' - Neueste Version: '" << neusteVersion << "'" << std::endl;
|
||||
@ -998,16 +993,26 @@ int ProgramManager::updateModus(Settings *settings)
|
||||
//Print INFOs
|
||||
std::cout << " => Infos (zur Version): " << std::endl;
|
||||
std::string line;
|
||||
std::stringstream strstream(html+ "\n");
|
||||
while (std::getline(strstream, line).good()) {
|
||||
if(line != "")
|
||||
std::cout << " > " << line << std::endl;
|
||||
}
|
||||
|
||||
|
||||
//Vergleiche Versionen:
|
||||
if( atoi(pageManager.replace(neusteVersion, ".", "").c_str()) <= atoi(pageManager.replace(settings->version, ".", "").c_str()) ) {
|
||||
switch (pageManager.compareVersions(settings->version, neusteVersion)) {
|
||||
case 0:
|
||||
std::cout << "\n => Du benützt bereits die neuste Release-Version." << std::endl;
|
||||
return 0;
|
||||
case 1:
|
||||
//Diese Version ist klleienr als aktuelle Version => Updatete
|
||||
break;
|
||||
case 2:
|
||||
std::cout << "\n => Du benützt bereits eine Aktuellere Version als die neuste Release-Version." << std::endl;
|
||||
return 0;
|
||||
default:
|
||||
//Error
|
||||
return 2;
|
||||
}
|
||||
|
||||
//lege pfad zum speichern fest
|
||||
|
Loading…
Reference in New Issue
Block a user