diff options
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 |