-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsettings.cpp
More file actions
450 lines (387 loc) · 18.2 KB
/
settings.cpp
File metadata and controls
450 lines (387 loc) · 18.2 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
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
#include <Windows.h>
#include <string>
#include <vector>
#include <sstream>
#include <windowsx.h>
#include <Commctrl.h>
#include "settings.h"
#include "gen_win7shell.h"
#include "api.h"
#include "resource.h"
using namespace std;
int SettingsManager::GetInt(wstring key, int default_value)
{
return GetPrivateProfileIntW(currentSection.c_str(), key.c_str(), default_value, mPath.c_str());
}
bool SettingsManager::GetBool(wstring key, bool default_value)
{
return (bool)GetPrivateProfileIntW(currentSection.c_str(), key.c_str(), default_value, mPath.c_str());
}
wstring SettingsManager::GetString(wstring key, wstring default_value, size_t max_size)
{
wstring buffer;
buffer.resize(max_size);
GetPrivateProfileStringW(currentSection.c_str(), key.c_str(), default_value.c_str(),
&buffer[0], max_size, mPath.c_str());
buffer.resize(wcslen(buffer.c_str()));
return wstring(buffer);
}
bool SettingsManager::WriteInt(wstring key, int value)
{
wstringstream s;
s << value;
return (bool)WritePrivateProfileStringW(currentSection.c_str(), key.c_str(), s.str().c_str(), mPath.c_str());
}
bool SettingsManager::WriteBool(wstring key, bool value)
{
wstring s;
s = (value ? L"1" : L"0");
return (bool)WritePrivateProfileStringW(currentSection.c_str(), key.c_str(), s.c_str(), mPath.c_str());
}
bool SettingsManager::WriteString(wstring key, wstring value)
{
return (bool)WritePrivateProfileStringW(currentSection.c_str(), key.c_str(), value.c_str(), mPath.c_str());
}
bool SettingsManager::ReadSettings(sSettings &Destination_struct)
{
bool result(true);
currentSection = SECTION_NAME_GENERAL;
ZeroMemory(&Destination_struct, sizeof(Destination_struct));
// Read all values from .ini file to Destination_struct
Destination_struct.Add2RecentDocs = GetBool(L"Add2RecentDocs", true);
Destination_struct.Antialias = GetBool(L"AntiAlias", true);
Destination_struct.AsIcon = GetBool(L"AsIcon", true);
Destination_struct.BGPath = GetString(L"BGPath", L"", MAX_PATH);
Destination_struct.DisableUpdates = GetBool(L"DisableUpdates", false);
Destination_struct.ForceVersion = GetBool(L"ForceVersion", false);
Destination_struct.JLbms = GetBool(L"JLBookMarks", true);
Destination_struct.JLfrequent = GetBool(L"JLFrequent", true);
Destination_struct.JLpl = GetBool(L"JLPlayList", true);
Destination_struct.JLrecent = GetBool(L"JLRecent", true);
Destination_struct.JLtasks = GetBool(L"JLTasks", true);
Destination_struct.Overlay = GetBool(L"IconOverlay", true);
Destination_struct.Progressbar = GetBool(L"ProgressBar", true);
Destination_struct.RemoveTitle = GetBool(L"RemoveTitle", false);
Destination_struct.Revertto = GetInt(L"RevertTo", BG_TRANSPARENT);
Destination_struct.Shrinkframe = GetBool(L"ShrinkFrame", false);
Destination_struct.Stoppedstatus = GetBool(L"StoppedStatusOn", true);
Destination_struct.Streamstatus = GetBool(L"StreamStatusOn", true);
Destination_struct.Text = GetString(L"Text",
L"%c%%s%%curpl% of %totalpl%. ‡%c%%s%%title%‡%c%%s%%artist%‡‡%c%%s%%curtime%/%totaltime%‡%c%%s%Track #: %track% Volume: %volume%%");
Destination_struct.Thumbnailbackground = GetInt(L"ThumbnailBackGround", BG_ALBUMART);
Destination_struct.Thumbnailbuttons = GetBool(L"ThumbnailButtons", true);
Destination_struct.Thumbnailenabled = GetBool(L"ThumbnailEnabled", true);
Destination_struct.Thumbnailpb = GetBool(L"ThumbnailPB", false);
Destination_struct.VolumeControl = GetBool(L"VolumeControl", false);
Destination_struct.VuMeter = GetBool(L"VUMeter", false);
Destination_struct.LowFrameRate = GetBool(L"LowFrameRate", false);
Destination_struct.LastTab = GetInt(L"LastTab", 0);
Destination_struct.LastUpdateCheck = GetInt(L"LastUpdateCheck", 0);
Destination_struct.IconSize = GetInt(L"IconSize", 50);
Destination_struct.IconPosition = GetInt(L"IconPosition", IP_UPPERLEFT);
Destination_struct.disallow_peek = GetBool(L"disallow_peek", true);
Destination_struct.BG_Transparency = GetInt(L"BG_Transparency", 0);
Destination_struct.LastMessage = GetInt(L"last_message", -1);
// Decoding bool[16] Buttons
wstring Buttons = GetString(L"Buttons", L"1111100000000000");
for (int i = 0; i!= 16; ++i)
{
Destination_struct.Buttons[i] = (Buttons[i] == '1' ? true : false);
}
if (!GetBool(L"OldSettings", false))
{
ReadOldSettings(Destination_struct);
WriteBool(L"OldSettings", true);
}
// Read font
currentSection = SECTION_NAME_FONT;
if (!GetPrivateProfileStructW(SECTION_NAME_FONT, L"font", &Destination_struct.font,
sizeof(Destination_struct.font), mPath.c_str()))
{
LOGFONT ft = {};
wcsncpy_s(ft.lfFaceName, L"Segoe UI", 32);
ft.lfHeight = -14;
ft.lfWeight = FW_NORMAL;
Destination_struct.font = ft;
}
Destination_struct.text_color = GetInt(L"color", RGB(255,255,255));
Destination_struct.bgcolor = GetInt(L"bgcolor", RGB(0,0,0));
return result;
}
bool SettingsManager::WriteSettings(const sSettings &Source_struct)
{
int result = 1;
currentSection = SECTION_NAME_GENERAL;
// Write values form Source_struct to .ini file
result = result & (int)WriteBool(L"Add2RecentDocs", Source_struct.Add2RecentDocs);
result = result & (int)WriteBool(L"AntiAlias", Source_struct.Antialias);
result = result & (int)WriteBool(L"AsIcon", Source_struct.AsIcon);
result = result & (int)WriteString(L"BGPath", Source_struct.BGPath);
result = result & (int)WriteBool(L"DisableUpdates", Source_struct.DisableUpdates);
result = result & (int)WriteBool(L"ForceVersion", Source_struct.ForceVersion);
result = result & (int)WriteBool(L"JLBookMarks", Source_struct.JLbms);
result = result & (int)WriteBool(L"JLFrequent", Source_struct.JLfrequent);
result = result & (int)WriteBool(L"JLPlayList", Source_struct.JLpl);
result = result & (int)WriteBool(L"JLRecent", Source_struct.JLrecent);
result = result & (int)WriteBool(L"JLTasks", Source_struct.JLtasks);
result = result & (int)WriteBool(L"IconOverlay", Source_struct.Overlay);
result = result & (int)WriteBool(L"ProgressBar", Source_struct.Progressbar);
result = result & (int)WriteBool(L"RemoveTitle", Source_struct.RemoveTitle);
result = result & (int)WriteInt(L"RevertTo", Source_struct.Revertto);
result = result & (int)WriteBool(L"ShrinkFrame", Source_struct.Shrinkframe);
result = result & (int)WriteBool(L"StoppedStatusOn", Source_struct.Stoppedstatus);
result = result & (int)WriteBool(L"StreamStatusOn", Source_struct.Streamstatus);
result = result & (int)WriteString(L"Text", Source_struct.Text);
result = result & (int)WriteInt(L"ThumbnailBackGround", Source_struct.Thumbnailbackground);
result = result & (int)WriteBool(L"ThumbnailButtons", Source_struct.Thumbnailbuttons);
result = result & (int)WriteBool(L"ThumbnailEnabled", Source_struct.Thumbnailenabled);
result = result & (int)WriteBool(L"ThumbnailPB", Source_struct.Thumbnailpb);
result = result & (int)WriteBool(L"VolumeControl", Source_struct.VolumeControl);
result = result & (int)WriteBool(L"VUMeter", Source_struct.VuMeter);
result = result & (int)WriteBool(L"LowFrameRate", Source_struct.LowFrameRate);
result = result & (int)WriteInt(L"LastTab", Source_struct.LastTab);
result = result & (int)WriteInt(L"LastUpdateCheck", Source_struct.LastUpdateCheck);
result = result & (int)WriteInt(L"IconSize", Source_struct.IconSize);
result = result & (int)WriteInt(L"IconPosition", Source_struct.IconPosition);
result = result & (int)WriteBool(L"disallow_peek", Source_struct.disallow_peek);
result = result & (int)WriteInt(L"BG_Transparency", Source_struct.BG_Transparency);
result = result & (int)WriteInt(L"last_message", Source_struct.LastMessage);
// Encoding bool[16] Buttons
wstringstream s;
for (int i = 0; i != 16; ++i)
{
s << Source_struct.Buttons[i];
}
result = result & (int)WriteString(L"Buttons", s.str());
// Font
currentSection = SECTION_NAME_FONT;
result = result & (int)WritePrivateProfileStructW(SECTION_NAME_FONT, L"font", (LPVOID)(&Source_struct.font),
sizeof(Source_struct.font), mPath.c_str());
result = result * (int)WriteInt(L"color", Source_struct.text_color);
result = result * (int)WriteInt(L"bgcolor", Source_struct.bgcolor);
return (result == 1);
}
bool SettingsManager::ReadResume(sResumeSettings &resume)
{
ZeroMemory(&resume, sizeof(resume));
currentSection = SECTION_NAME_RESUME;
resume.ResumePosition = GetInt(L"ResumePosition", 0);
resume.ResumeTime = GetInt(L"ResumeTime", 0);
return true;
}
bool SettingsManager::WriteResume(sResumeSettings &resume)
{
int result = 0;
currentSection = SECTION_NAME_RESUME;
result = result & (int)WriteInt(L"ResumePosition", resume.ResumePosition);
result = result & (int)WriteInt(L"ResumeTime", resume.ResumeTime);
return (result == 1);
}
void SettingsManager::WriteSettings_ToForm(HWND hwnd, HWND WinampWnd, const sSettings &Settings)
{
//Aero peek settings
switch (Settings.Thumbnailbackground)
{
case BG_TRANSPARENT:
SendMessage(GetDlgItem(hwnd, IDC_RADIO1), (UINT) BM_SETCHECK, BST_CHECKED , 0);
break;
case BG_ALBUMART:
SendMessage(GetDlgItem(hwnd, IDC_RADIO2), (UINT) BM_SETCHECK, BST_CHECKED , 0);
break;
case BG_CUSTOM:
SendMessage(GetDlgItem(hwnd, IDC_RADIO3), (UINT) BM_SETCHECK, BST_CHECKED , 0);
break;
}
switch (Settings.IconPosition)
{
case IP_UPPERLEFT:
SendMessage(GetDlgItem(hwnd, IDC_RADIO4), (UINT) BM_SETCHECK, BST_CHECKED , 0);
break;
case IP_LOWERLEFT:
SendMessage(GetDlgItem(hwnd, IDC_RADIO7), (UINT) BM_SETCHECK, BST_CHECKED , 0);
break;
case IP_UPPERRIGHT:
SendMessage(GetDlgItem(hwnd, IDC_RADIO6), (UINT) BM_SETCHECK, BST_CHECKED , 0);
break;
case IP_LOWERRIGHT:
SendMessage(GetDlgItem(hwnd, IDC_RADIO8), (UINT) BM_SETCHECK, BST_CHECKED , 0);
break;
}
SendMessage(GetDlgItem(hwnd, IDC_COMBO1), CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_TRANSPARENT));
SendMessage(GetDlgItem(hwnd, IDC_COMBO1), CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_ALBUM_ART));
SendMessage(GetDlgItem(hwnd, IDC_COMBO1), CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_CUSTOM_BACKGROUND));
SendMessage(GetDlgItem(hwnd, IDC_COMBO1), CB_SETCURSEL, Settings.Revertto, 0);
//Player control buttons
SendMessage(GetDlgItem(hwnd, IDC_CHECK6), (UINT) BM_SETCHECK, Settings.Thumbnailbuttons, 0);
//Progressbar
SendMessage(GetDlgItem(hwnd, IDC_CHECK2), (UINT) BM_SETCHECK, Settings.Progressbar, 0);
//Streamstatus
SendMessage(GetDlgItem(hwnd, IDC_CHECK4), (UINT) BM_SETCHECK, Settings.Streamstatus, 0);
//Stoppedstatus
SendMessage(GetDlgItem(hwnd, IDC_CHECK5), (UINT) BM_SETCHECK, Settings.Stoppedstatus, 0);
//Overlay
SendMessage(GetDlgItem(hwnd, IDC_CHECK3), (UINT) BM_SETCHECK, Settings.Overlay, 0);
//antialias
SendMessage(GetDlgItem(hwnd, IDC_CHECK8), (UINT) BM_SETCHECK, Settings.Antialias, 0);
//shrinkframe
SendMessage(GetDlgItem(hwnd, IDC_CHECK1), (UINT) BM_SETCHECK, Settings.Shrinkframe, 0);
//enable thumbnail
SendMessage(GetDlgItem(hwnd, IDC_CHECK7), (UINT) BM_SETCHECK, Settings.Thumbnailenabled, 0);
//disable updated
SendMessage(GetDlgItem(hwnd, IDC_CHECK9), (UINT) BM_SETCHECK, Settings.DisableUpdates, 0);
//remove winamp title
SendMessage(GetDlgItem(hwnd, IDC_CHECK10), (UINT) BM_SETCHECK, Settings.RemoveTitle, 0);
//Show image as icon
SendMessage(GetDlgItem(hwnd, IDC_CHECK25), (UINT) BM_SETCHECK, Settings.AsIcon, 0);
//VU Meter
SendMessage(GetDlgItem(hwnd, IDC_CHECK26), (UINT) BM_SETCHECK, Settings.VuMeter, 0);
//Thumbnail pb
SendMessage(GetDlgItem(hwnd, IDC_CHECK29), (UINT) BM_SETCHECK, Settings.Thumbnailpb, 0);
//Disallow aero peek
SendMessage(GetDlgItem(hwnd, IDC_CHECK_AEROPEEK), (UINT) BM_SETCHECK, Settings.disallow_peek, 0);
//Add 2 recent
SendMessage(GetDlgItem(hwnd, IDC_CHECK_A2R), (UINT) BM_SETCHECK, !Settings.Add2RecentDocs, 0);
SendMessage(GetDlgItem(hwnd, IDC_CHECK30), (UINT) BM_SETCHECK, Settings.JLrecent, 0);
SendMessage(GetDlgItem(hwnd, IDC_CHECK31), (UINT) BM_SETCHECK, Settings.JLfrequent, 0);
SendMessage(GetDlgItem(hwnd, IDC_CHECK32), (UINT) BM_SETCHECK, Settings.JLtasks, 0);
SendMessage(GetDlgItem(hwnd, IDC_CHECK33), (UINT) BM_SETCHECK, Settings.JLbms, 0);
SendMessage(GetDlgItem(hwnd, IDC_CHECK34), (UINT) BM_SETCHECK, Settings.JLpl, 0);
SendMessage(GetDlgItem(hwnd, IDC_CHECK35), (UINT) BM_SETCHECK, Settings.VolumeControl, 0);
SendMessage(GetDlgItem(hwnd, IDC_CHECK36), (UINT) BM_SETCHECK, static_cast<WPARAM>(Settings.LowFrameRate), 0);
//Trackbar
SendMessage(GetDlgItem(hwnd, IDC_SLIDER1), TBM_SETPOS, TRUE, Settings.IconSize);
SendMessage(GetDlgItem(hwnd, IDC_SLIDER_TRANSPARENCY), TBM_SETPOS, TRUE, Settings.BG_Transparency);
wstringstream size;
size << "Icon size (" << SendMessage(GetDlgItem(hwnd, IDC_SLIDER1), TBM_GETPOS, NULL, NULL) << "%)";
SetWindowTextW(GetDlgItem(hwnd, IDC_ICONSIZE), size.str().c_str());
size.str(L"");
size << SendMessage(GetDlgItem(hwnd, IDC_SLIDER_TRANSPARENCY), TBM_GETPOS, NULL, NULL) << "%";
SetWindowTextW(GetDlgItem(hwnd, IDC_TRANSPARENCY_PERCENT), size.str().c_str());
SetWindowText(GetDlgItem(hwnd, IDC_EDIT2), Settings.BGPath.c_str());
std::wstring tmpbuf = Settings.Text;
std::wstring::size_type pos = std::wstring::npos;
do
{
pos = tmpbuf.find(__T("‡"));
if (pos != std::wstring::npos)
tmpbuf.replace(pos, 1, __T("\xD\xA"));
}
while (pos != std::wstring::npos);
SetWindowText(GetDlgItem(hwnd, IDC_EDIT3), tmpbuf.c_str());
EnableWindow(GetDlgItem(hwnd, IDC_CHECK4), Settings.Progressbar);
EnableWindow(GetDlgItem(hwnd, IDC_CHECK5), Settings.Progressbar);
EnableWindow(GetDlgItem(hwnd, IDC_CHECK27), Settings.Thumbnailbuttons);
}
void SettingsManager::ReadOldSettings( sSettings & Destination_struct )
{
struct sSettings_old
{
bool Thumbnailenabled;
char Thumbnailbackground;
bool Thumbnailbuttons;
bool Progressbar;
bool Streamstatus;
bool Stoppedstatus;
bool Overlay;
bool Add2RecentDocs;
bool Antialias;
bool Shrinkframe;
bool ForceVersion;
bool DisableUpdates;
bool RemoveTitle;
bool AsIcon;
bool VuMeter;
bool Buttons[16];
bool Thumbnailpb;
bool JLrecent;
bool JLfrequent;
bool JLtasks;
bool JLbms;
bool JLpl;
bool VolumeControl;
char Revertto;
};
sSettings_old old_settings = {};
if (!GetPrivateProfileStruct(__T("win7shell"), __T("settings"), &old_settings, sizeof(old_settings), mPath.c_str()))
{
return;
}
else
{
Destination_struct.Add2RecentDocs = old_settings.Add2RecentDocs;
Destination_struct.Antialias = old_settings.Antialias;
Destination_struct.AsIcon = old_settings.AsIcon;
std::copy(old_settings.Buttons, old_settings.Buttons+16, Destination_struct.Buttons);
Destination_struct.DisableUpdates = old_settings.DisableUpdates;
Destination_struct.ForceVersion = old_settings.ForceVersion;
Destination_struct.JLbms = old_settings.JLbms;
Destination_struct.JLfrequent = old_settings.JLfrequent;
Destination_struct.JLpl = true;
Destination_struct.JLrecent = old_settings.JLrecent;
Destination_struct.JLtasks = old_settings.JLtasks;
Destination_struct.Overlay = old_settings.Overlay;
Destination_struct.Progressbar = old_settings.Progressbar;
Destination_struct.RemoveTitle = old_settings.RemoveTitle;
Destination_struct.Revertto = old_settings.Revertto;
Destination_struct.Shrinkframe = old_settings.Shrinkframe;
Destination_struct.Stoppedstatus = old_settings.Stoppedstatus;
Destination_struct.Streamstatus = old_settings.Streamstatus;
Destination_struct.Thumbnailbackground = old_settings.Thumbnailbackground;
Destination_struct.Thumbnailbuttons = old_settings.Thumbnailbuttons;
Destination_struct.Thumbnailenabled = old_settings.Thumbnailenabled;
Destination_struct.Thumbnailpb = old_settings.Thumbnailpb;
Destination_struct.VuMeter = old_settings.VuMeter;
}
}
bool SettingsManager::WriteButtons(std::vector<int> &tba)
{
if (tba.size() > 7)
{
tba.resize(7);
}
std::wstringstream button_TextStream;
for (int i = 0; i != tba.size(); ++i)
{
button_TextStream << tba[i] << ",";
}
std::wstring button_Text = button_TextStream.str();
button_Text.erase(button_Text.length()-1, 1);
return WritePrivateProfileString(SECTION_NAME_GENERAL, L"ThumbButtons", button_Text.c_str(), mPath.c_str());
}
bool SettingsManager::ReadButtons( std::vector<int> &tba )
{
std::wstring text;
text.resize(100);
if (!GetPrivateProfileString(SECTION_NAME_GENERAL, L"ThumbButtons", L"1300,1301,1302,1303,1308", &text[0], 99, mPath.c_str()))
{
return false;
}
text.resize(wcslen(&text[0]));
tba.clear();
std::wstring::size_type pos = std::wstring::npos;
do
{
pos = text.find_first_of(L',');
std::wstringstream buffer;
buffer << text.substr(0, pos);
int code;
buffer >> code;
if (code < 1300)
{
text.erase(0, pos+1);
continue;
}
tba.push_back(code);
text.erase(0, pos+1);
}
while (pos != std::wstring::npos);
if (tba.size() == 0)
{
tba.push_back(1300);
tba.push_back(1301);
tba.push_back(1302);
tba.push_back(1303);
tba.push_back(1308);
}
return true;
}