diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2011-11-27 20:34:04 +0200 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2011-11-27 20:34:04 +0200 |
commit | 0d96f9d417250b77a6f5366f3b14035c42782d90 (patch) | |
tree | d035590083cbf27f824f1a7c00c822ed812b4f6d /client/FileOpThread.cpp | |
parent | 8ce6d0ce269723658f8b84edaebf9d24afc3a251 (diff) | |
parent | a19e9744751d4278f56cb3b6ff885c0068f03a3d (diff) |
Merge branch 'master' of ssh://sss.chaoslab.ru//home/private_git/proxy_ui
Diffstat (limited to 'client/FileOpThread.cpp')
-rw-r--r-- | client/FileOpThread.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
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 <QtCore> +#include "DownloadClient.h" +#include "FileOpThread.h" +#include "UpdatedConfig.h" + +void FileOpThread::run() +{ + UpdatedConfig *cfg = UpdatedConfig::CurrentConfig(); + + /* delete files */ + vector<Config::FileEntry> 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<pair<string, string> > files; + vector<Config::FileEntry> 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<string, string> 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 |