-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSettingsManager.cs
More file actions
281 lines (258 loc) · 9.53 KB
/
Copy pathSettingsManager.cs
File metadata and controls
281 lines (258 loc) · 9.53 KB
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
using System.Collections.Generic;
namespace PoCXPlotterGui
{
/// <summary>
/// Manages persistent user settings for the plotter
/// </summary>
public class SettingsManager
{
/// <summary>
/// Loads all user settings from persistent storage
/// </summary>
public UserSettings LoadSettings()
{
return new UserSettings
{
AccountId = Properties.Settings.Default.ID,
MemoryLimit = Properties.Settings.Default.mem,
UseMemoryLimit = Properties.Settings.Default.memlimit,
LowPriority = Properties.Settings.Default.lowprio,
DirectIo = Properties.Settings.Default.ddio,
Warps = Properties.Settings.Default.warps,
Unit = Properties.Settings.Default.unit,
MaxNonces = Properties.Settings.Default.maxnonces,
Benchmark = Properties.Settings.Default.bench,
ZeroCopyBuffers = Properties.Settings.Default.zcb,
Encounters = Properties.Settings.Default.esc,
CompressionRatio = Properties.Settings.Default.cpr,
WorkGroups = Properties.Settings.Default.wks,
UseCustomEncounters = Properties.Settings.Default.esc_c,
UseCustomWorkGroups = Properties.Settings.Default.wks_c,
NumFiles = Properties.Settings.Default.num_files,
CpuEnabled = Properties.Settings.Default.cpu,
CpuThreads = Properties.Settings.Default.cpulimit,
Gpu1Enabled = Properties.Settings.Default.gpu1,
Gpu1Threads = Properties.Settings.Default.gpu1limit,
Gpu2Enabled = Properties.Settings.Default.gpu2,
Gpu2Threads = Properties.Settings.Default.gpu2limit,
Gpu3Enabled = Properties.Settings.Default.gpu3,
Gpu3Threads = Properties.Settings.Default.gpu3limit,
Gpu4Enabled = Properties.Settings.Default.gpu4,
Gpu4Threads = Properties.Settings.Default.gpu4limit
};
}
/// <summary>
/// Saves account ID setting
/// </summary>
public void SaveAccountId(string accountId)
{
Properties.Settings.Default.ID = accountId;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves memory limit setting
/// </summary>
public void SaveMemoryLimit(int memoryLimitMiB)
{
Properties.Settings.Default.mem = memoryLimitMiB;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves memory limit enabled flag
/// </summary>
public void SaveMemoryLimitEnabled(bool enabled)
{
Properties.Settings.Default.memlimit = enabled;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves max nonces setting
/// </summary>
public void SaveMaxNonces(bool maxNonces)
{
Properties.Settings.Default.maxnonces = maxNonces;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves warps setting
/// </summary>
public void SaveWarps(decimal warps)
{
Properties.Settings.Default.warps = warps;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves unit setting
/// </summary>
public void SaveUnit(int unit)
{
Properties.Settings.Default.unit = unit;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves low priority setting
/// </summary>
public void SaveLowPriority(bool lowPriority)
{
Properties.Settings.Default.lowprio = lowPriority;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves direct I/O setting
/// </summary>
public void SaveDirectIo(bool directIo)
{
Properties.Settings.Default.ddio = directIo;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves benchmark setting
/// </summary>
public void SaveBenchmark(bool benchmark)
{
Properties.Settings.Default.bench = benchmark;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves zero-copy buffers setting
/// </summary>
public void SaveZeroCopyBuffers(bool zcb)
{
Properties.Settings.Default.zcb = zcb;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves encounters setting
/// </summary>
public void SaveEncounters(decimal encounters)
{
Properties.Settings.Default.esc = encounters;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves compression ratio setting
/// </summary>
public void SaveCompressionRatio(decimal cpr)
{
Properties.Settings.Default.cpr = cpr;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves work groups setting
/// </summary>
public void SaveWorkGroups(decimal wks)
{
Properties.Settings.Default.wks = wks;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves custom encounters enabled flag
/// </summary>
public void SaveCustomEncountersEnabled(bool enabled)
{
Properties.Settings.Default.esc_c = enabled;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves custom work groups enabled flag
/// </summary>
public void SaveCustomWorkGroupsEnabled(bool enabled)
{
Properties.Settings.Default.wks_c = enabled;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves number of files setting
/// </summary>
public void SaveNumFiles(decimal numFiles)
{
Properties.Settings.Default.num_files = numFiles;
Properties.Settings.Default.Save();
}
/// <summary>
/// Saves device settings
/// </summary>
public void SaveDeviceSettings(List<DeviceSettings> devices)
{
if (devices.Count > 0 && devices[0].Type == DeviceSettings.DeviceType.CPU)
{
Properties.Settings.Default.cpu = devices[0].Enabled;
Properties.Settings.Default.cpulimit = devices[0].Threads;
}
int gpuIndex = 0;
for (int i = 1; i < devices.Count; i++)
{
if (devices[i].Type == DeviceSettings.DeviceType.GPU)
{
switch (gpuIndex)
{
case 0:
Properties.Settings.Default.gpu1 = devices[i].Enabled;
Properties.Settings.Default.gpu1limit = devices[i].Threads;
break;
case 1:
Properties.Settings.Default.gpu2 = devices[i].Enabled;
Properties.Settings.Default.gpu2limit = devices[i].Threads;
break;
case 2:
Properties.Settings.Default.gpu3 = devices[i].Enabled;
Properties.Settings.Default.gpu3limit = devices[i].Threads;
break;
case 3:
Properties.Settings.Default.gpu4 = devices[i].Enabled;
Properties.Settings.Default.gpu4limit = devices[i].Threads;
break;
}
gpuIndex++;
}
}
Properties.Settings.Default.Save();
}
}
/// <summary>
/// Holds all user settings
/// </summary>
public class UserSettings
{
public string AccountId { get; set; }
public int MemoryLimit { get; set; }
public bool UseMemoryLimit { get; set; }
public bool LowPriority { get; set; }
public bool DirectIo { get; set; }
public decimal Warps { get; set; }
public int Unit { get; set; }
public bool MaxNonces { get; set; }
public bool Benchmark { get; set; }
public bool ZeroCopyBuffers { get; set; }
public decimal Encounters { get; set; }
public decimal CompressionRatio { get; set; }
public decimal WorkGroups { get; set; }
public bool UseCustomEncounters { get; set; }
public bool UseCustomWorkGroups { get; set; }
public decimal NumFiles { get; set; }
public bool CpuEnabled { get; set; }
public int CpuThreads { get; set; }
public bool Gpu1Enabled { get; set; }
public int Gpu1Threads { get; set; }
public bool Gpu2Enabled { get; set; }
public int Gpu2Threads { get; set; }
public bool Gpu3Enabled { get; set; }
public int Gpu3Threads { get; set; }
public bool Gpu4Enabled { get; set; }
public int Gpu4Threads { get; set; }
}
/// <summary>
/// Device settings for persistence
/// </summary>
public class DeviceSettings
{
public enum DeviceType
{
CPU,
GPU
}
public DeviceType Type { get; set; }
public bool Enabled { get; set; }
public int Threads { get; set; }
}
}