forked from jbaugh/patcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch_manager.cpp
76 lines (61 loc) · 2.05 KB
/
patch_manager.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "patch_manager.h"
void PatchManager::get_patch(
std::string domain, std::string port, std::string starting_uri_dir, std::string ignore_str
)
{
ignore_regex = boost::regex(ignore_str, boost::regex_constants::icase);
downloader.init(domain, port, starting_uri_dir);
download_patch_file();
download_patch_contents();
std::cout << std::endl;
std::cout << "Patch list received" << std::endl;
//downloader.run();
}
void PatchManager::download_patch_file()
{
downloader.get("/patch.txt");
downloader.run();
}
void PatchManager::download_patch_contents()
{
std::string line = "";
std::ifstream patch("patch/patch.txt");
int index;
int line_num = 0;
std::string checksum;
std::string filename;
if(patch) {
while(patch.good()) {
getline(patch, line);
if(line.empty()) {
continue;
}
index = line.find("\t");
if(index != std::string::npos) {
filename = line.substr(0, index);
checksum = line.substr(index + 1);
// Do not try to download if the file is meant to be ignored
if(!boost::regex_match(filename, ignore_regex)) {
// If the local file's checksum doesn't match the
// checksum on the patch file, we know that the file is
// out of date, so download it.
if(checksum != FileManager::checksum(filename)) {
downloader.get(filename, checksum);
}
}
else {
std::cout << filename << " ignored" << std::endl;
}
}
else {
std::cout << std::endl << "Invalid line in patch file: " << line_num << std::endl;
}
std::cout << ".";
++line_num;
}
patch.close();
}
else {
std::cout << "Could not open local patch file in patch/patch.txt" << std::endl;
}
}