summaryrefslogtreecommitdiff
path: root/updater/main.cpp
diff options
context:
space:
mode:
authorAlex Borisov <borisov.alexandr@rambler.ru>2011-12-03 22:50:51 +0200
committerAlex Borisov <borisov.alexandr@rambler.ru>2011-12-03 22:50:51 +0200
commitb59011f52c95d2f6ac19152641c418d9f0221b43 (patch)
tree7cd78cd8c47585bbb711bf7598df973ad2d5eadd /updater/main.cpp
parent2cb38f2d082f765d87f8a73b09957c3fd839afa0 (diff)
Client updater app
Diffstat (limited to 'updater/main.cpp')
-rw-r--r--updater/main.cpp73
1 files changed, 73 insertions, 0 deletions
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;
+}