diff options
Diffstat (limited to 'client/DownloadClient.cpp')
-rw-r--r-- | client/DownloadClient.cpp | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/client/DownloadClient.cpp b/client/DownloadClient.cpp index b834622..3fe7b59 100644 --- a/client/DownloadClient.cpp +++ b/client/DownloadClient.cpp @@ -5,8 +5,6 @@ DownloadClient::DownloadClient(): isDownloading(false), current(NULL), currentId(-1) { - connect(this, SIGNAL(ReplyRecieved(SslClient::RequestType&, QByteArray&)), - this, SLOT(FileDataRecieved(SslClient::RequestType&, QByteArray&))); } DownloadClient::DownloadClient(QString addr): SslClient(addr), isDownloading(false), current(NULL), currentId(-1) @@ -41,28 +39,32 @@ void DownloadClient::Download(const vector<pair<string, string> > &fileList) Logger::Error("Previous downloading process wasn't finished! Aborting.\n"); return; } + + connect(this, SIGNAL(ReplyRecieved(SslClient::RequestType&, QByteArray&)), + this, SLOT(FileDataRecieved(SslClient::RequestType&, QByteArray&))); isDownloading = true; files = fileList; DoDownload(); } void DownloadClient::DoDownload() -{ +{ + currentId++; + if (currentId < (int)files.size()) { - currentId++; pair<string, string> file = files[currentId]; QString filename = QString::fromLocal8Bit(file.first.c_str()); string md5 = file.second; current = new QFile(filename); - current->open(QIODevice::ReadWrite); + current->open(QIODevice::WriteOnly | QIODevice::Unbuffered); - Logger::Info("Downloading file %s\n", file.first.c_str()); + Logger::Info("Downloading file (%d of %u): %s\n", currentId + 1, files.size(), file.first.c_str()); SendFileRequest(file.first); } else { - Logger::Info("All files have been downloaded."); + Logger::Info("All files have been downloaded.\n"); isDownloading = false; emit downloadFinished(); } @@ -70,33 +72,29 @@ void DownloadClient::DoDownload() void DownloadClient::FileDataRecieved(SslClient::RequestType &type, QByteArray &data) { + Logger::Trace("Recieved file data: %u bytes\n", data.size()); + if (type != RegularFile) { Logger::Error("Invalid reply recieved: %x\n", type); return; } - - if ((current != NULL) && (current->isOpen())) + if ((current == NULL) || (! current->isOpen())) { - Logger::Error("File is not open or invalid state\n"); + Logger::Error("File isn't open or in invalid state.\n"); return; } pair<string, string> file = files[currentId]; string filename = file.first; - if (data.size() == FRAGMENT_SIZE) + if (data.size() != 0) { - Logger::Debug("data:\n %s", data.constData()); current->write(data); - SendFileRequest(filename); + current->waitForBytesWritten(-1); } else { - if (data.size() != 0) - { - Logger::Debug("data:\n %s", data.constData()); - current->write(data); - } + Logger::Trace("Last (empty) packet recieved\n"); current->close(); delete current; current = NULL; @@ -105,6 +103,7 @@ void DownloadClient::FileDataRecieved(SslClient::RequestType &type, QByteArray & * @todo md5 hash check */ + // proceed to the next file DoDownload(); } } |