summaryrefslogtreecommitdiff
path: root/client/DownloadClient.cpp
diff options
context:
space:
mode:
authorAlex Borisov <b0ric.alex@gmail.com>2012-03-30 00:42:18 +0300
committerAlex Borisov <b0ric.alex@gmail.com>2012-03-30 00:42:18 +0300
commitfcc5a8982adc2e2b8cdd9491ac458986b94cac5a (patch)
tree824c9cc98af61c3aba073f93e6f5e8850aad0c42 /client/DownloadClient.cpp
parentec80c67bcfec64177910f39d31c4b20974629096 (diff)
FIX: proxy order, speed color, client update issue
Diffstat (limited to 'client/DownloadClient.cpp')
-rw-r--r--client/DownloadClient.cpp45
1 files changed, 33 insertions, 12 deletions
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<string, string> file(filename, 0);
+ pair<string, string> file(filename, "0");
vector<pair<string, string> > fileList;
fileList.push_back(file);
Download(fileList);
@@ -42,18 +43,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);
@@ -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;