From a19e9744751d4278f56cb3b6ff885c0068f03a3d Mon Sep 17 00:00:00 2001 From: Alex Borisov Date: Sun, 27 Nov 2011 12:31:03 +0200 Subject: File downloading (no MD5 hash check yet). Various fixes --- client/FileOpThread.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 client/FileOpThread.cpp (limited to 'client/FileOpThread.cpp') diff --git a/client/FileOpThread.cpp b/client/FileOpThread.cpp new file mode 100644 index 0000000..42cb51b --- /dev/null +++ b/client/FileOpThread.cpp @@ -0,0 +1,63 @@ + +#include +#include "DownloadClient.h" +#include "FileOpThread.h" +#include "UpdatedConfig.h" + +void FileOpThread::run() +{ + UpdatedConfig *cfg = UpdatedConfig::CurrentConfig(); + + /* delete files */ + vector toDelete = cfg->GetDeleteList(); + for (unsigned i = 0; i < toDelete.size(); i++) + { + Logger::Trace("Deleting file: \"%s\"\n", toDelete[i].path.c_str()); + + QString path = QString::fromLocal8Bit(toDelete[i].path.c_str()); + QFile file(path); + QFileInfo fileInfo(file); + if (fileInfo.exists()) + { + file.remove(); + } + else + { + Logger::Info("File \"%s\" has already been deleted\n", toDelete[i].path.c_str()); + } + } + + /* download files */ + vector > files; + vector downloadList = cfg->GetDownloadList(); + for (unsigned i = 0; i < downloadList.size(); i++) + { + QString path = QString::fromLocal8Bit(downloadList[i].path.c_str()); + QFileInfo fileInfo(path); + if (fileInfo.exists()) + { + Logger::Info("File \"%s\" already exists\n", downloadList[i].path.c_str()); + /** + * @todo Compute md5 hash and check if they are the same + */ + } + else + { + pair file = make_pair(downloadList[i].path, downloadList[i].md5); + files.push_back(file); + } + } + + if (files.size() != 0) + { + Logger::Debug("Setting server address to %s\n", cfg->GetServerAddr().c_str()); + + QString addr = QString::fromLocal8Bit(cfg->GetServerAddr().c_str()); + DownloadClient downloadClient(addr); + downloadClient.Download(files); + } + else + { + Logger::Trace("No files to download from server.\n"); + } +} \ No newline at end of file -- cgit v1.2.3