-
Notifications
You must be signed in to change notification settings - Fork 4
/
settings.h
408 lines (361 loc) · 13.1 KB
/
settings.h
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#ifndef SETTINGS_H
#define SETTINGS_H
#include <QSettings>
enum /*class*/ SettingsUnicode {
AUTO, EXCLUDE, INCLUDE
};
enum SettingsDefaultAllocIn {
ALLOC_IN_SIZE, ALLOC_IN_COUNT, ALLOC_IN_RATIO
};
enum SettingsDefaultAllocRec {
ALLOC_REC_RATIO, ALLOC_REC_COUNT, ALLOC_REC_SIZE
};
struct OpenclDevice {
QString name;
float alloc;
QString memLimit;
QString minChunk;
QString gfMethod;
int batch;
unsigned iters;
int outputs;
OpenclDevice() {
alloc = 0.0;
memLimit = "";
minChunk = "32K";
gfMethod = "lookup";
batch = 0;
iters = 0;
outputs = 0;
}
};
class Settings
{
private:
QSettings settings;
Settings() : settings("ParParGUI.ini", QSettings::IniFormat) {}
public:
static Settings& getInstance()
{
static Settings* instance = new Settings();
return *instance;
}
void reset()
{
settings.clear();
}
SettingsUnicode unicode() const {
auto value = settings.value("PAR2/Unicode", "auto").toString().toLower();
if(value == "true") return SettingsUnicode::INCLUDE;
if(value == "false") return SettingsUnicode::EXCLUDE;
return SettingsUnicode::AUTO;
}
void setUnicode(const SettingsUnicode value) {
if(value == SettingsUnicode::INCLUDE)
settings.setValue("PAR2/Unicode", "true");
else if(value == SettingsUnicode::EXCLUDE)
settings.setValue("PAR2/Unicode", "false");
else
settings.setValue("PAR2/Unicode", "auto");
}
QString charset() const {
return settings.value("PAR2/LocalCharset", "utf8").toString();
}
void setCharset(const QString& value) {
settings.setValue("PAR2/LocalCharset", value);
}
int packetRepMin() const {
return settings.value("PAR2/PacketRepetitionMin", 1).toInt();
}
void setPacketRepMin(int value) {
settings.setValue("PAR2/PacketRepetitionMin", value);
}
int packetRepMax() const {
return settings.value("PAR2/PacketRepetitionMax", 16).toInt();
}
void setPacketRepMax(int value) {
settings.setValue("PAR2/PacketRepetitionMax", value);
}
bool stdNaming() const {
return settings.value("PAR2/StdNaming", false).toBool();
}
void setStdNaming(const bool value) {
settings.setValue("PAR2/StdNaming", value);
}
QString readSize() const {
return settings.value("Tuning/ReadSize", "4M").toString();
}
void setReadSize(const QString& value) {
settings.setValue("Tuning/ReadSize", value);
}
int readBuffers() const {
return settings.value("Tuning/ReadBuffers", 8).toInt();
}
void setReadBuffers(const int value) {
settings.setValue("Tuning/ReadBuffers", value);
}
int hashQueue() const {
return settings.value("Tuning/HashQueue", 5).toInt();
}
void setHashQueue(const int value) {
settings.setValue("Tuning/HashQueue", value);
}
QString minChunk() const {
return settings.value("Tuning/MinChunk", "128K").toString();
}
void setMinChunk(const QString& value) {
settings.setValue("Tuning/MinChunk", value);
}
int chunkReadThreads() const {
return settings.value("Tuning/ChunkReadThreads", 2).toInt();
}
void setChunkReadThreads(const int value) {
settings.setValue("Tuning/ChunkReadThreads", value);
}
int recBuffers() const {
return settings.value("Tuning/RecBuffers", 12).toInt();
}
void setRecBuffers(const int value) {
settings.setValue("Tuning/RecBuffers", value);
}
int hashBatch() const {
return settings.value("Tuning/HashBatch", 8).toInt();
}
void setHashBatch(const int value) {
settings.setValue("Tuning/HashBatch", value);
}
int procBatch() const {
const auto val = settings.value("Tuning/ProcBatch", "auto");
if(val.toString().toLower() == "auto") return -1;
return val.toInt();
}
void setProcBatch(const int value) {
if(value < 0)
settings.setValue("Tuning/ProcBatch", "auto");
else
settings.setValue("Tuning/ProcBatch", value);
}
QString memLimit() const {
const auto val = settings.value("Tuning/MemLimit", "auto").toString();
if(val.toLower() == "auto") return "";
return val;
}
void setMemLimit(const QString& value) {
if(value.isEmpty())
settings.setValue("Tuning/MemLimit", "auto");
else
settings.setValue("Tuning/MemLimit", value);
}
QString gfMethod() const {
const auto val = settings.value("Tuning/GFMethod", "auto").toString();
if(val.toLower() == "auto") return "";
return val;
}
void setGfMethod(const QString& value) {
if(value.isEmpty())
settings.setValue("Tuning/GFMethod", "auto");
else
settings.setValue("Tuning/GFMethod", value);
}
QString tileSize() const {
const auto val = settings.value("Tuning/LoopTileSize", "auto").toString();
if(val.toLower() == "auto") return "";
return val;
}
void setTileSize(const QString& value) {
if(value.isEmpty())
settings.setValue("Tuning/LoopTileSize", "auto");
else
settings.setValue("Tuning/LoopTileSize", value);
}
QString hashMethod() const {
const auto val = settings.value("Tuning/HashMethod", "auto").toString();
if(val.isEmpty()) return "auto";
return val.toLower();
}
void setHashMethod(const QString& value) {
if(value.isEmpty())
settings.setValue("Tuning/HashMethod", "auto");
else
settings.setValue("Tuning/HashMethod", value);
}
QString md5Method() const {
const auto val = settings.value("Tuning/MD5Method", "auto").toString();
if(val.isEmpty()) return "auto";
return val.toLower();
}
void setMd5Method(const QString& value) {
if(value.isEmpty())
settings.setValue("Tuning/MD5Method", "auto");
else
settings.setValue("Tuning/MD5Method", value);
}
bool outputSync() const {
return settings.value("Tuning/OutputSync", false).toBool();
}
void setOutputSync(bool value) {
settings.setValue("Tuning/OutputSync", value);
}
int threadNum() const {
const auto val = settings.value("Tuning/Threads", "auto");
if(val.toString().toLower() == "auto") return -1;
return val.toInt();
}
void setThreadNum(const int value) {
if(value < 0)
settings.setValue("Tuning/Threads", "auto");
else
settings.setValue("Tuning/Threads", value);
}
QString cpuMinChunk() const {
return settings.value("Tuning/CpuMinChunk", "128K").toString();
}
void setCpuMinChunk(const QString& value) {
settings.setValue("Tuning/CpuMinChunk", value);
}
QList<OpenclDevice> openclDevices() const {
QList<OpenclDevice> devices;
int i=0;
while(1) {
const auto skey = QString("OpenCL/%1_") + QString::number(i++);
const auto& devKey = skey.arg("Device");
if(!settings.contains(devKey)) break;
OpenclDevice dev;
dev.name = settings.value(devKey).toString();
dev.alloc = settings.value(skey.arg("AllocationPercent"), dev.alloc).toFloat();
if(dev.alloc <= 0.0) continue; // invalid allocation
dev.memLimit = settings.value(skey.arg("MemLimit"), dev.memLimit).toString();
dev.minChunk = settings.value(skey.arg("MinChunk"), dev.minChunk).toString();
dev.gfMethod = settings.value(skey.arg("GFMethod"), dev.gfMethod).toString();
dev.batch = settings.value(skey.arg("ProcBatch"), dev.batch).toInt();
dev.iters = settings.value(skey.arg("Iterations"), dev.iters).toUInt();
dev.outputs = settings.value(skey.arg("Outputs"), dev.outputs).toInt();
devices.append(dev);
}
return devices;
}
void setOpenclDevices(const QList<OpenclDevice>& value) {
settings.remove("OpenCL");
settings.beginGroup("OpenCL");
for(int i=0; i<value.size(); i++) {
const auto& dev = value.at(i);
const auto is = QString::number(i);
settings.setValue(QString("Device_%1").arg(is), dev.name);
settings.setValue(QString("AllocationPercent_%1").arg(is), dev.alloc);
settings.setValue(QString("MemLimit_%1").arg(is), dev.memLimit);
settings.setValue(QString("MinChunk_%1").arg(is), dev.minChunk);
settings.setValue(QString("GFMethod_%1").arg(is), dev.gfMethod);
settings.setValue(QString("ProcBatch_%1").arg(is), dev.batch);
settings.setValue(QString("Iterations_%1").arg(is), dev.iters);
settings.setValue(QString("Outputs_%1").arg(is), dev.outputs);
}
settings.endGroup();
}
QStringList parparBin(bool* isSystemExecutable = nullptr) const;
void setParparBin(const QString &parpar, const QString &node = QString());
bool runBackground() const {
return settings.value("Running/Background", false).toBool();
}
void setRunBackground(const bool value) {
settings.setValue("Running/Background", value);
}
bool runNotification() const {
return settings.value("Running/Notification", false).toBool();
}
void setRunNotification(const bool value) {
settings.setValue("Running/Notification", value);
}
bool runClose() const {
return settings.value("Running/AutoClose", false).toBool();
}
void setRunClose(const bool value) {
settings.setValue("Running/AutoClose", value);
}
bool uiExpSource() const {
return settings.value("UI/ExpandSource", false).toBool();
}
void setUiExpSource(const bool value) {
settings.setValue("UI/ExpandSource", value);
}
bool uiExpDest() const {
return settings.value("UI/ExpandDest", false).toBool();
}
void setUiExpDest(const bool value) {
settings.setValue("UI/ExpandDest", value);
}
SettingsDefaultAllocIn allocSliceMode() const {
if(settings.contains("UI/AllocSliceCount"))
return SettingsDefaultAllocIn::ALLOC_IN_COUNT;
if(settings.contains("UI/AllocSliceRatio"))
return SettingsDefaultAllocIn::ALLOC_IN_RATIO;
return SettingsDefaultAllocIn::ALLOC_IN_SIZE;
}
QString allocSliceSize() const {
return settings.value("UI/AllocSliceSize", "1M").toString();
}
void setAllocSliceSize(const QString& value) {
settings.remove("UI/AllocSliceCount");
settings.remove("UI/AllocSliceRatio");
settings.setValue("UI/AllocSliceSize", value);
}
int allocSliceCount() const {
return settings.value("UI/AllocSliceCount", 1000).toInt();
}
void setAllocSliceCount(int value) {
settings.remove("UI/AllocSliceSize");
settings.remove("UI/AllocSliceRatio");
settings.setValue("UI/AllocSliceCount", value);
}
float allocSliceRatio() const {
return settings.value("UI/AllocSliceRatio", 1.0).toFloat();
}
void setAllocSliceRatio(float value) {
settings.remove("UI/AllocSliceCount");
settings.remove("UI/AllocSliceSize");
settings.setValue("UI/AllocSliceRatio", value);
}
SettingsDefaultAllocRec allocRecoveryMode() const {
if(settings.contains("UI/AllocRecoveryCount"))
return SettingsDefaultAllocRec::ALLOC_REC_COUNT;
if(settings.contains("UI/AllocRecoverySize"))
return SettingsDefaultAllocRec::ALLOC_REC_SIZE;
return SettingsDefaultAllocRec::ALLOC_REC_RATIO;
}
float allocRecoveryRatio() const {
return settings.value("UI/AllocRecoveryRatio", 10.0).toFloat();
}
void setAllocRecoveryRatio(float value) {
settings.remove("UI/AllocRecoveryCount");
settings.remove("UI/AllocRecoverySize");
settings.setValue("UI/AllocRecoveryRatio", value);
}
int allocRecoveryCount() const {
return settings.value("UI/AllocRecoveryCount", 100).toInt();
}
void setAllocRecoveryCount(int value) {
settings.remove("UI/AllocRecoveryRatio");
settings.remove("UI/AllocRecoverySize");
settings.setValue("UI/AllocRecoveryCount", value);
}
QString allocRecoverySize() const {
return settings.value("UI/AllocRecoverySize", "100M").toString();
}
void setAllocRecoverySize(const QString& value) {
settings.remove("UI/AllocRecoveryRatio");
settings.remove("UI/AllocRecoveryCount");
settings.setValue("UI/AllocRecoverySize", value);
}
QString sliceMultiple() const {
return settings.value("UI/SizeMultiple", "").toString();
}
void setSliceMultple(const QString& value) {
settings.setValue("UI/SizeMultiple", value);
}
int sliceLimit() const {
return settings.value("UI/SliceLimit", 32768).toInt();
}
void setSliceLimit(int value) {
settings.setValue("UI/SliceLimit", value);
}
};
#endif // SETTINGS_H