From fcc5a8982adc2e2b8cdd9491ac458986b94cac5a Mon Sep 17 00:00:00 2001 From: Alex Borisov Date: Fri, 30 Mar 2012 00:42:18 +0300 Subject: FIX: proxy order, speed color, client update issue --- client/DownloadClient.cpp | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'client/DownloadClient.cpp') diff --git a/client/DownloadClient.cpp b/client/DownloadClient.cpp index 110601a..0175df7 100644 --- a/client/DownloadClient.cpp +++ b/client/DownloadClient.cpp @@ -8,13 +8,14 @@ DownloadClient::DownloadClient(): isDownloading(false), current(NULL), currentId { } -DownloadClient::DownloadClient(QString addr): SslClient(addr), isDownloading(false), current(NULL), currentId(-1) +DownloadClient::DownloadClient(QString addr): + SslClient(addr), isDownloading(false), current(NULL), currentId(-1) { } void DownloadClient::Download(const string &filename) { - pair file(filename, 0); + pair file(filename, "0"); vector > fileList; fileList.push_back(file); Download(fileList); @@ -42,18 +43,31 @@ void DownloadClient::Download(const vector > &fileList) connect(this, SIGNAL(ReplyRecieved(SslClient::RequestType&, QByteArray&)), this, SLOT(FileDataRecieved(SslClient::RequestType&, QByteArray&))); - isDownloading = true; + + isDownloading = true; files = fileList; + for(unsigned i = 0; i < files.size(); i++) + { + status[files[i].first] = 0; + } DoDownload(); } void DownloadClient::DoDownload() { currentId++; - + if (currentId < (int)files.size()) { - pair file = files[currentId]; + pair file = files[currentId]; + if (status[file.first] > MAX_DOWNLOAD_ATTEMPTS) + { + Logger::Warn("Maximum number of %d download retries exceeded. Skipping %s\n", + MAX_DOWNLOAD_ATTEMPTS, file.first.c_str()); + DoDownload(); + return; + } + QString filename = QString::fromLocal8Bit(file.first.c_str()); string md5 = file.second; current = new QFile(filename); @@ -61,14 +75,16 @@ void DownloadClient::DoDownload() { Logger::Info("Can't open file: path isn't available\n"); DoDownload(); + return; } Logger::Info("Downloading file (%d of %u): %s\n", currentId + 1, files.size(), file.first.c_str()); - SendFileRequest(file.first); + status[file.first]++; + SendFileRequest(file.first); } else { - Logger::Info("All files have been downloaded.\n"); + Logger::Info("All files have been downloaded.\n"); isDownloading = false; emit downloadFinished(); } @@ -103,15 +119,20 @@ void DownloadClient::FileDataRecieved(SslClient::RequestType &type, QByteArray & QString md5string = QString::fromLocal8Bit(file.second.c_str()); QString filename = QString::fromLocal8Bit(file.first.c_str()); QByteArray md5 = md5_sum(filename); - if (md5 == md5string) - { + if (md5 == md5string) + { Logger::Trace("File %s was downloaded correctly!\n", filename.toStdString().c_str()); + if (QString::compare(filename, QString("client.bin.tmp")) == 0) + { + Logger::Trace("Copying client.bin.tmp => client.bin.latest\n"); + current->copy(QString("client.bin.latest")); + } } else { - Logger::Error("File %s was downloaded incorrectly! Removing and trying again!\n", filename.toStdString().c_str()); - current->remove(); - currentId--; + Logger::Error("File %s was downloaded incorrectly! Removing and trying again!\n", filename.toStdString().c_str()); + current->remove(); + currentId--; } // free pointer to the current file delete current; -- cgit v1.2.3