-
Notifications
You must be signed in to change notification settings - Fork 79
/
FileDownloader.cpp
61 lines (51 loc) · 1.89 KB
/
FileDownloader.cpp
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
#include "FileDownloader.h"
#include "mainResources.h"
#include "fstream"
#include <algorithm>
std::string FileDownloader::lastModifiedNeg = "";
std::string FileDownloader::lastModifiedL = "";
std::string FileDownloader::lastModifiedP = "";
std::string FileDownloader::lastModifiedSSH = "";
std::string FileDownloader::lastModifiedWFL = "";
std::string FileDownloader::lastModifiedWFP = "";
std::string getLM(std::string *buffer) {
std::size_t pos1 = buffer->find("Last-Modified:");
if(pos1 == std::string::npos) {
stt->doEmitionFoundData("<font color=\"Pink\">Cannot find Last-Modified.</font>");
return "";
}
int pos2 = buffer->find("\r\n", pos1);
if(pos2 == std::string::npos) {
stt->doEmitionFoundData("<font color=\"Pink\">Weird reply.</font>");
return "";
}
std::string res = buffer->substr(pos1 + 15, pos2 - pos1 - 15);
return res;
}
void checkWeb(const char *fileName, std::string *oldLM) {
std::string buffer;
Connector con;
con.nConnect(std::string("http://nesca.d3w.org/files/" + std::string(fileName)).c_str(), 80, &buffer);
const std::string &lm = getLM(&buffer);
if(lm.size() == 0) return;
if(lm.compare(*oldLM) != 0) {
*oldLM = lm;
std::string res(buffer.substr(buffer.find("\r\n\r\n") + 4).c_str());
res.erase(std::remove(res.begin(), res.end(), '\r'), res.end());
std::ofstream out(fileName);
out << std::string(res);
out.close();
stt->doEmitionFoundData("<font color=\"Pink\">File " + QString(fileName) + " downloaded.</font>");
}
}
void FileDownloader::checkWebFiles() {
while (true) {
checkWeb(NEGATIVE_FN, &lastModifiedNeg);
checkWeb(LOGIN_FN, &lastModifiedL);
checkWeb(PASS_FN, &lastModifiedP);
checkWeb(SSH_PASS_FN, &lastModifiedSSH);
checkWeb(WF_LOGIN_FN, &lastModifiedWFL);
checkWeb(WF_PASS_FN, &lastModifiedWFP);
Sleep(600000);
}
}