diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2012-09-04 12:29:59 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2012-09-04 12:29:59 +0300 |
commit | 6d8b331a37a025f4a16d8278da715e7a628b33d3 (patch) | |
tree | 11b7880b2afe9575f99a0a9eeb2ba97b8e6c88b9 /client/DownloadClient.cpp | |
parent | 1052c8bd510b92827a61aba725083c9feb24e042 (diff) | |
parent | ad1559db52cf01869c0fb31252ad9f69af2ddd4c (diff) |
Merge branch 'master' of ssh://sss.chaoslab.ru//home/git/proxy_ui
Diffstat (limited to 'client/DownloadClient.cpp')
-rw-r--r-- | client/DownloadClient.cpp | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/client/DownloadClient.cpp b/client/DownloadClient.cpp index d25e6dc..c94109a 100644 --- a/client/DownloadClient.cpp +++ b/client/DownloadClient.cpp @@ -23,13 +23,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<string, string> file(filename, 0); + pair<string, string> file(filename, "0"); vector<pair<string, string> > fileList; fileList.push_back(file); Download(fileList); @@ -57,18 +58,31 @@ void DownloadClient::Download(const vector<pair<string, string> > &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<string, string> file = files[currentId]; + pair<string, string> 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); @@ -76,14 +90,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(); } @@ -118,15 +134,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; |