blob: 42cb51bb1e53d4d3da22ef7fc5cdd085e0105985 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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");
}
}
|