forked from markus/S_New4
change getExePath to function + ...
This commit is contained in:
parent
2a76c4c10e
commit
f2f9a37a64
@ -134,7 +134,7 @@ int PageManager::downLoadToFile(std::string filePath, std::string url)
|
||||
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, false);
|
||||
|
||||
/* disable progress meter, set to 0L to enable and disable debug output */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, true);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, false);
|
||||
|
||||
/* send all data to this function */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
|
||||
@ -345,6 +345,31 @@ size_t PageManager::getDate()
|
||||
static_cast<double>(tm_now->tm_mon +1) * 30.43685 + tm_now->tm_mday);
|
||||
}
|
||||
|
||||
std::string PageManager::getExePath()
|
||||
{
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
char buff[PATH_MAX];
|
||||
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
|
||||
if (len == -1) {
|
||||
perror("Readlink proc self exe failed");
|
||||
return "";
|
||||
} else {
|
||||
buff[len] = '\0';
|
||||
return std::string(buff);
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
wchar_t buffer[MAX_PATH + 1];
|
||||
GetModuleFileName( nullptr, buffer, MAX_PATH );
|
||||
std::wstring wstr(buffer);
|
||||
return std::string(wstr.begin(), wstr.end());
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
int PageManager::writeToFile(std::string path, std::string text)
|
||||
{
|
||||
if(path == "")
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
std::string grep(std::string text, std::string substring, bool IgnoreCaseSensetifity = false);
|
||||
std::string upper_string(const std::string& str);
|
||||
size_t getDate();
|
||||
std::string getExePath();
|
||||
|
||||
int writeToFile(std::string path, std::string text);
|
||||
|
||||
|
@ -27,7 +27,7 @@ int ProgramManager::start(Settings *settings)
|
||||
return 174;
|
||||
}
|
||||
|
||||
//settings->modus = UPDATE_MODUS;
|
||||
settings->modus = UPDATE_MODUS;
|
||||
|
||||
|
||||
switch (settings->modus) {
|
||||
@ -975,7 +975,7 @@ int ProgramManager::updateModus(Settings *settings)
|
||||
|
||||
if( (html = pageManager.getServerRequest(settings->VersionFileUrl).html) == "-1") {
|
||||
if(settings->debugMode)
|
||||
std::cerr << "Download newst Version file failed" << std::endl;
|
||||
std::cerr << "Download newst Version failed" << std::endl;
|
||||
return 1;
|
||||
} else {
|
||||
html = pageManager.replace(html, "\r", "");
|
||||
@ -983,18 +983,16 @@ int ProgramManager::updateModus(Settings *settings)
|
||||
|
||||
// Get newst Version
|
||||
std::stringstream strstream(html+ "\n");
|
||||
std::string neusteVersion, dieseVersion;
|
||||
std::string neusteVersion;
|
||||
std::getline(strstream, neusteVersion);
|
||||
if( !isNumber( (neusteVersion = pageManager.replace(neusteVersion, ".", "")) ) ) {
|
||||
if( !isNumber( (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;
|
||||
std::cout << "Neueste Version: " << neusteVersion << " diese Version " << settings->version << std::endl;
|
||||
|
||||
if(neusteVersion <= dieseVersion) {
|
||||
if(pageManager.replace(neusteVersion, ".", "") <= pageManager.replace(settings->version, ".", "")) {
|
||||
std::cout << " => INFO: Du benützt bereits die neuste Release-Version." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@ -1009,8 +1007,8 @@ int ProgramManager::updateModus(Settings *settings)
|
||||
}
|
||||
|
||||
|
||||
std::cout << "Mache das Programm ausführbar..." << std::endl;
|
||||
#ifdef __linux__
|
||||
std::cout << "Mache das Programm ausführbar..." << std::endl;
|
||||
chmod(downloadedFilePath.c_str(), S_IRWXU);
|
||||
#endif
|
||||
|
||||
@ -1021,22 +1019,11 @@ int ProgramManager::updateModus(Settings *settings)
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
std::string exePath;
|
||||
#ifdef __linux__
|
||||
char result[PATH_MAX + 1];
|
||||
if(readlink("/proc/self/exe", result, PATH_MAX) == -1) {
|
||||
perror("Readlink failed");
|
||||
std::string exePath = pageManager.getExePath();
|
||||
if(exePath == "") {
|
||||
std::cout << "getExepath failed" << std::endl;
|
||||
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;
|
||||
|
||||
@ -1048,7 +1035,7 @@ int ProgramManager::updateModus(Settings *settings)
|
||||
}
|
||||
|
||||
|
||||
std::cout << "Update Erfolgreich ausgeführt." << std::endl;
|
||||
std::cout << "Update Erfolgreich ausgeführt:" << settings->version << " -> " << neusteVersion << std::endl;
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user