diff options
Diffstat (limited to 'updater')
-rw-r--r-- | updater/main.cpp | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/updater/main.cpp b/updater/main.cpp index e39a0b2..b0198f6 100644 --- a/updater/main.cpp +++ b/updater/main.cpp @@ -1,42 +1,41 @@ -#include <stdio.h> #ifdef WINDOWS - #include <direct.h> - #define GetCurrentDir _getcwd #define ClientName "client.exe" + #define PathSlash "\\" #else - #include <unistd.h> - #define GetCurrentDir getcwd #define ClientName "client" + #define PathSlash "/" #endif -#include <errno.h> #include <QFileInfo> #include <QProcess> #include <QString> +#include <string> #include "Logger.h" +using std::string; -int main() + +int main(int argc, char* argv[]) { - Logger::Info("Starting updater application\n"); - char currentPath[FILENAME_MAX]; - if (! GetCurrentDir(currentPath, sizeof(currentPath))) + Logger::Info("Starting updater application\n"); + + string path = argv[0]; + size_t p = path.find_last_of(PathSlash); + QString dir = QString::fromStdString(path.substr(0, p)); + Logger::Trace("Application path: %s\n", dir.toStdString().c_str()); + + // check if whether client.bin.latest exists + // it shoultd be renamed to client.exe (on Windows) ot just client (on Linux) + QFileInfo binInfo(dir + PathSlash +"client.bin.latest"); + if (! binInfo.exists()) { - return errno; + Logger::Fatal("New client version not present.\n"); + Logger::Fatal("Terminating.\n"); + return -1; } - // check if whether client.bin.latest exists - // it shoultd be renamed to client.exe (on Windows) ot just client (on Linux) - QString cwd(currentPath); - QFileInfo binInfo(cwd + "/client.bin.latest"); - if (! binInfo.exists()) - { - Logger::Fatal("New client version not present.\n"); - Logger::Fatal("Terminating.\n"); - return -1; - } // remove old client binary - QFile client(cwd + "/" + ClientName); + QFile client(dir + PathSlash + ClientName); if (client.exists()) { Logger::Trace("Removing old client executable\n"); @@ -51,7 +50,7 @@ int main() Logger::Warn("Client executable is absent\n"); } - if (QFile::rename(cwd + "/client.bin.latest", cwd + "/" + ClientName)) + if (QFile::rename(dir + PathSlash + "client.bin.latest", dir + PathSlash + ClientName)) { Logger::Info("Client successfully updated\n"); } @@ -62,7 +61,7 @@ int main() } // starting client process - QString program(cwd + "/" + ClientName); + QString program(dir + PathSlash + ClientName); if (! QProcess::startDetached(program)) { Logger::Fatal("Failed to start client application\n"); |