diff options
l--------- | updater/Logger.cpp | 1 | ||||
l--------- | updater/Logger.h | 1 | ||||
-rw-r--r-- | updater/main.cpp | 73 | ||||
-rw-r--r-- | updater/updater.pro | 18 |
4 files changed, 93 insertions, 0 deletions
diff --git a/updater/Logger.cpp b/updater/Logger.cpp new file mode 120000 index 0000000..d1ee7ee --- /dev/null +++ b/updater/Logger.cpp @@ -0,0 +1 @@ +../client/Logger.cpp
\ No newline at end of file diff --git a/updater/Logger.h b/updater/Logger.h new file mode 120000 index 0000000..03aacbf --- /dev/null +++ b/updater/Logger.h @@ -0,0 +1 @@ +../client/Logger.h
\ No newline at end of file diff --git a/updater/main.cpp b/updater/main.cpp new file mode 100644 index 0000000..e39a0b2 --- /dev/null +++ b/updater/main.cpp @@ -0,0 +1,73 @@ + +#include <stdio.h> +#ifdef WINDOWS + #include <direct.h> + #define GetCurrentDir _getcwd + #define ClientName "client.exe" +#else + #include <unistd.h> + #define GetCurrentDir getcwd + #define ClientName "client" +#endif +#include <errno.h> +#include <QFileInfo> +#include <QProcess> +#include <QString> +#include "Logger.h" + + +int main() +{ + Logger::Info("Starting updater application\n"); + char currentPath[FILENAME_MAX]; + if (! GetCurrentDir(currentPath, sizeof(currentPath))) + { + return errno; + } + // 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); + if (client.exists()) + { + Logger::Trace("Removing old client executable\n"); + if (! client.remove()) + { + Logger::Fatal("Can't remove %s\n", client.fileName().toStdString().c_str()); + return -1; + } + } + else + { + Logger::Warn("Client executable is absent\n"); + } + + if (QFile::rename(cwd + "/client.bin.latest", cwd + "/" + ClientName)) + { + Logger::Info("Client successfully updated\n"); + } + else + { + Logger::Fatal("Can't rename 'client.bin.latest'\n"); + return -1; + } + + // starting client process + QString program(cwd + "/" + ClientName); + if (! QProcess::startDetached(program)) + { + Logger::Fatal("Failed to start client application\n"); + return -1; + } + + return 0; +} diff --git a/updater/updater.pro b/updater/updater.pro new file mode 100644 index 0000000..6321f56 --- /dev/null +++ b/updater/updater.pro @@ -0,0 +1,18 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Sat Dec 3 22:14:40 2011 +###################################################################### + +QMAKE_CXXFLAGS_DEBUG += -DDEBUG -g3 -ggdb -O0 +CONFIG += qt debug console warn_on + +QT = core gui + + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . + +# Input +HEADERS += Logger.h +SOURCES += main.cpp Logger.cpp |