#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"); } }