forked from mtrlt/Reaper_prime
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Config.cpp
113 lines (103 loc) · 2.98 KB
/
Config.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "Global.h"
#include "Config.h"
#include <fstream>
#include <map>
using std::map;
using std::pair;
using std::ifstream;
using std::ofstream;
#include <cstdio>
#include <algorithm>
void Config::Clear()
{
config.clear();
}
void Config::Load(string filename, vector<string> included_already)
{
included_already.push_back(filename);
{
FILE* filu = fopen(filename.c_str(), "r");
if (filu == NULL)
throw string("Config file " + filename + " not found.");
fclose(filu);
}
map<string, string> config_values;
config_values["aggression"] = "uint";
config_values["worksize"] = "uint";
config_values["threads_per_gpu"] = "uint";
config_values["device"] = "uint array";
config_values["kernel"] = "string";
config_values["save_binaries"] = "bool";
config_values["cpu_mining_threads"] = "uint";
config_values["platform"] = "uint";
config_values["enable_graceful_shutdown"] = "bool";
config_values["host"] = "string";
config_values["port"] = "string";
config_values["user"] = "string";
config_values["pass"] = "string";
config_values["proxy"] = "string";
config_values["long_polling"] = "bool";
config_values["include"] = "string";
config_values["cpu_algorithm"] = "string";
config_values["protocol"] = "string";
config_values["mine"] = "string";
config_values["gpu_sharemask"] = "string";
config_values["vectors"] = "uint";
config_values["sharethreads"] = "uint";
config_values["dont_check_shares"] = "bool";
config_values["lookup_gap"] = "uint";
config_values["gpu_thread_concurrency"] = "uint";
config_values["check_shares"] = "bool";
config_values["nfactor_override"] = "uint";
config_values["getwork_rate"] = "uint";
config_values["sieve_size"] = "uint";
config_values["min_chain_length"] = "uint";
config_values["sievesize"] = "uint";
config_values["sievepercentage"] = "uint";
config_values["primecoin_address"] = "string";
config_values["debug"] = "bool";
ifstream filu(filename.c_str());
while(!filu.eof())
{
string prop;
filu >> prop;
string value;
filu >> value;
if (prop == "include")
{
if (std::find(included_already.begin(), included_already.end(), value) != included_already.end())
{
cout << "Circular include: ";
for(uint i=0; i<included_already.size(); ++i)
cout << included_already[i] << " -> ";
cout << value << endl;
}
else
{
Config includedconfig;
includedconfig.Load(value, included_already);
for(map<string,vector<string> >::iterator it = includedconfig.config.begin(); it != includedconfig.config.end(); ++it)
for(uint i=0; i<it->second.size(); ++i)
config[it->first] = it->second;
}
}
if (config_values.find(prop) == config_values.end())
{
bool fail = true;
CombiKey c = GetCombiKey(prop);
if (c.base != "" && c.id != -1 && c.prop != "")
{
fail = false;
}
if (fail)
{
if (prop != "")
{
cout << "Warning: unknown property \"" << prop << "\" in configuration file." << endl;
}
}
}
config[prop].push_back(value);
}
included_already.pop_back();
}