diff options
-rw-r--r-- | client/DownloadClient.cpp | 6 | ||||
-rw-r--r-- | client/Logger.cpp | 6 | ||||
-rw-r--r-- | client/SslClient.cpp | 4 | ||||
-rw-r--r-- | client/Utility.cpp | 3 | ||||
-rw-r--r-- | client/main.cpp | 37 | ||||
-rw-r--r-- | updater/main.cpp | 5 |
6 files changed, 40 insertions, 21 deletions
diff --git a/client/DownloadClient.cpp b/client/DownloadClient.cpp index 723dbcb..110601a 100644 --- a/client/DownloadClient.cpp +++ b/client/DownloadClient.cpp @@ -57,7 +57,11 @@ void DownloadClient::DoDownload() QString filename = QString::fromLocal8Bit(file.first.c_str()); string md5 = file.second; current = new QFile(filename); - current->open(QIODevice::WriteOnly | QIODevice::Unbuffered); + if (! current->open(QIODevice::WriteOnly | QIODevice::Unbuffered)) + { + Logger::Info("Can't open file: path isn't available\n"); + DoDownload(); + } Logger::Info("Downloading file (%d of %u): %s\n", currentId + 1, files.size(), file.first.c_str()); SendFileRequest(file.first); diff --git a/client/Logger.cpp b/client/Logger.cpp index 1367751..9de51c8 100644 --- a/client/Logger.cpp +++ b/client/Logger.cpp @@ -15,11 +15,13 @@ FILE* Logger::logFile = NULL; void Logger::InitLogFile() { + /* if (logFile == NULL) { logFile = fopen("client.log", "a"); - setbuf(logFile, NULL); + setbuf(logFile, NULL); } + */ } void Logger::Trace(string msg, ...) @@ -116,4 +118,4 @@ void Logger::Log(LogLevelType logLevel, string msg, va_list args) delete [] newfmt; } -#endif
\ No newline at end of file +#endif diff --git a/client/SslClient.cpp b/client/SslClient.cpp index ee9de34..64f63ac 100644 --- a/client/SslClient.cpp +++ b/client/SslClient.cpp @@ -220,6 +220,7 @@ void SslClient::DataRecieved() return; } + /* fprintf(Logger::logFile, "[ "); const char * tmp = pkt.constData(); for (int i = 0; i < pkt.size(); i++) @@ -234,7 +235,8 @@ void SslClient::DataRecieved() } } fprintf(Logger::logFile, "]\n"); - + */ + /* remove header and tail */ pkt.remove(pkt.size()-3, 3); pkt.remove(0, 3); diff --git a/client/Utility.cpp b/client/Utility.cpp index 547a56a..4adf348 100644 --- a/client/Utility.cpp +++ b/client/Utility.cpp @@ -1,7 +1,6 @@ #include <QCryptographicHash> #include "client.h" -#include "Logger.h" #include "Utility.h" @@ -52,4 +51,4 @@ char* wstrdup(_TCHAR* wSrc) return l_nstr; } -#endif
\ No newline at end of file +#endif diff --git a/client/main.cpp b/client/main.cpp index 95b1cba..ce83fcb 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -1,8 +1,10 @@ #ifdef WIN32 + #define ClientName "client.exe" #define UpdaterName "updater.exe" #define PathSlash "\\" #else + #define ClientName "client" #define UpdaterName "updater" #define PathSlash "/" #endif @@ -10,8 +12,9 @@ #include <QProcess> #include <QString> #include <string> -#include "ProxyClientApp.h" #include "client.h" +#include "ProxyClientApp.h" +#include "Utility.h" using std::string; @@ -35,19 +38,27 @@ int main(int argc, char *argv[]) // check if the client should be updated QFileInfo newClient(dir + PathSlash + "client.bin.latest"); + QFileInfo client(dir + PathSlash + ClientName); if (newClient.exists()) - { - Logger::Info("New client version found!\n"); - QString updater = dir + PathSlash + UpdaterName; - if (QProcess::startDetached(updater)) - { - Logger::Info("Updater launched\n"); - return 0; - } - else - { - Logger::Error("Can't launch updater to update client app\n"); - } + { + QString clentName = client.fileName(); + QString newClientName = newClient.fileName(); + QByteArray md5old = md5_sum(clentName); + QByteArray md5new = md5_sum(newClientName); + if (md5old != md5new) + { + Logger::Info("New client version found!\n"); + QString updater = dir + PathSlash + UpdaterName; + if (QProcess::startDetached(updater)) + { + Logger::Info("Updater launched\n"); + return 0; + } + else + { + Logger::Error("Can't launch updater to update client app\n"); + } + } } // check if initial config exists (config.cfg) // without it application is useless diff --git a/updater/main.cpp b/updater/main.cpp index a345d58..ac39264 100644 --- a/updater/main.cpp +++ b/updater/main.cpp @@ -57,13 +57,14 @@ int main(int argc, char* argv[]) Logger::Warn("Client executable is absent\n"); } - if (QFile::rename(dir + PathSlash + "client.bin.latest", dir + PathSlash + ClientName)) + // copy client.bin.lates to client.exe or client + if (QFile::copy(dir + PathSlash + "client.bin.latest", dir + PathSlash + ClientName)) { Logger::Info("Client successfully updated\n"); } else { - Logger::Fatal("Can't rename 'client.bin.latest'\n"); + Logger::Fatal("Can't copy 'client.bin.latest'\n"); return -1; } |