-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bangs.cpp
590 lines (522 loc) · 15.8 KB
/
Bangs.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
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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
#include "bangs.h"
#include "albumart.h"
#include "utilities.h"
#include "crc32.h"
#include "LiteStep.h"
#include <process.h>
#include "constants.h"
#include <stdlib.h>
#include <strsafe.h>
extern char g_szDebugMessage[];
extern HWND g_hwndMessageHandler;
extern GroupMap g_Groups;
namespace Bangs
{
BangItem BangMap[] =
{
{"Debug", Debug},
{"SetUpdateFrequency", SetUpdateFrequency},
{"Create", Create},
{"Destroy", Destroy},
{"SetNoCRC", SetNoCRC},
{"SetNoArtPath", SetNoArtPath},
{"SetParsePath", SetParsePath},
{"SetTrackOffset", SetTrackOffset},
{"SetOutOfBoundsPath", SetOutOfBoundsPath},
{"SetSearchFolderBeforeTag", SetSearchFolderBeforeTag},
{"SetAutoDownloadCoversTo", SetAutoDownloadCoversTo},
{"AddParseType", AddParseType},
{"DeleteParseType", DeleteParseType},
{"AddCoverName", AddCoverName},
{"DeleteCoverName", DeleteCoverName},
{"DownloadCover", DownloadCover},
{NULL, NULL}
};
}
// Registers bangs
void Bangs::_Register()
{
char szBangName[MAX_BANGCOMMAND];
for (int i = 0; BangMap[i].pCommand != NULL; i++)
{
StringCchPrintf(szBangName, MAX_BANGCOMMAND, "!AlbumArt%s", BangMap[i].szName);
AddBangCommand(szBangName, BangMap[i].pCommand);
}
}
// Unregisters bangs
void Bangs::_Unregister()
{
char szBangName[MAX_BANGCOMMAND];
for (int i = 0; BangMap[i].pCommand != NULL; i++)
{
StringCchPrintf(szBangName, MAX_BANGCOMMAND, "!AlbumArt%s", BangMap[i].szName);
RemoveBangCommand(szBangName);
}
}
// Shows the debug message
void Bangs::Debug(HWND, LPCSTR)
{
MessageBox(NULL, g_szDebugMessage, "AlbumArt Status", MB_OK);
}
// Modifies the update frequency
void Bangs::SetUpdateFrequency(HWND, LPCSTR pszArgs)
{
int iFrequency = atoi(pszArgs);
if (iFrequency > USER_TIMER_MAXIMUM)
iFrequency = USER_TIMER_MAXIMUM;
else if (iFrequency < USER_TIMER_MINIMUM)
iFrequency = USER_TIMER_MINIMUM;
KillTimer(g_hwndMessageHandler, UPDATETIMER_ID);
SetTimer(g_hwndMessageHandler, UPDATETIMER_ID, iFrequency, NULL);
}
// Creates Group(s) in pszArgs
void Bangs::Create(HWND, LPCSTR pszArgs)
{
char szToken[MAX_LINE_LENGTH];
LPCSTR pszNext = pszArgs;
while (GetToken(pszNext, szToken, &pszNext, false))
{
if (strcmp(szToken, "") != 0)
{
AlbumArt::CreateGroup(szToken);
}
}
}
// Destroys Group(s) in pszArgs
void Bangs::Destroy(HWND, LPCSTR pszArgs)
{
char szToken[MAX_LINE_LENGTH];
LPCSTR pszNext = pszArgs;
while (GetToken(pszNext, szToken, &pszNext, false))
{
if (strcmp(szToken, "") != 0)
{
AlbumArt::DestroyGroup(szToken);
}
}
}
// Updates the NoCRC setting
void Bangs::SetNoCRC(HWND, LPCSTR pszArgs)
{
char szToken[MAX_LINE_LENGTH];
LPCSTR pszNext = pszArgs;
// Get the group name (first token)
GetToken(pszNext, szToken, &pszNext, false);
GroupData* gData = AlbumArt::GetGroupByPrefix(szToken);
if (gData != NULL)
{
// Get the "BOOL" (second token)
GetToken(pszNext, szToken, &pszNext, false);
if (_stricmp(szToken, "toggle") != 0)
{
gData->bNoCRC32 = Utilities::String2Bool(szToken);
}
else // Toggling
{
gData->bNoCRC32 = !gData->bNoCRC32;
}
// Update the CRC32 value if necesary
if (!gData->bNoCRC32)
{
char szPath[MAX_LINE_LENGTH];
LiteStep::GetPrefixedRCLine(szPath, sizeof(szPath), gData->szPrefix, "Path", "");
gData->crc = CRC32::crc32(szPath);
LiteStep::SetEvar(gData->szPrefix, "CRC", "%X", gData->crc);
}
else
{
LiteStep::SetEvar(gData->szPrefix, "CRC", "");
}
}
}
// Update the NoArtPath
void Bangs::SetNoArtPath(HWND, LPCSTR pszArgs)
{
char szToken[MAX_LINE_LENGTH];
LPCSTR pszNext = pszArgs;
// Get the group name (first token)
GetToken(pszNext, szToken, &pszNext, false);
GroupData* gData = AlbumArt::GetGroupByPrefix(szToken);
if (gData != NULL)
{
// Get the new path (second token)
GetToken(pszNext, szToken, &pszNext, false);
char szCoverPath[MAX_LINE_LENGTH], szCurrentNoArtPath[MAX_PATH];
LiteStep::GetPrefixedRCLine(szCoverPath, sizeof(szCoverPath), gData->szPrefix, "Path", "");
StringCchCopy(szCurrentNoArtPath, sizeof(szCurrentNoArtPath), gData->szNoArtPath);
// Update the NoArtPath
if (strcmp(szToken, "") != 0)
{
if (szToken[1] != ':') // Relative path...
{
char szImageFolder[MAX_PATH];
LiteStep::GetPrefixedRCLine(szImageFolder, sizeof(szImageFolder), "LS", "ImageFolder", "");
StringCchCopy(gData->szNoArtPath, sizeof(gData->szNoArtPath), szImageFolder);
StringCchCat(gData->szNoArtPath, sizeof(gData->szNoArtPath), szToken);
}
else
{
StringCchCopy(gData->szNoArtPath, sizeof(gData->szNoArtPath), szToken);
}
}
else
{
StringCchCopy(gData->szNoArtPath, sizeof(gData->szNoArtPath), szToken);
}
// Check if the current cover is using the NoArtPath, and if so, update the current path
if (_stricmp(szCoverPath, szCurrentNoArtPath) == 0)
{
AlbumArt::SetPath(gData, gData->szNoArtPath);
}
}
}
// Update the ParsePath
void Bangs::SetParsePath(HWND, LPCSTR pszArgs)
{
char szToken[MAX_LINE_LENGTH];
LPCSTR pszNext = pszArgs;
// Get the group name (first token)
GetToken(pszNext, szToken, &pszNext, false);
GroupData* gData = AlbumArt::GetGroupByPrefix(szToken);
if (gData != NULL)
{
// Get the new path (second token)
GetToken(pszNext, szToken, &pszNext, false);
// Update the ParsePath
if (strcmp(szToken, "") != 0)
{
if (szToken[1] != ':') // Relative path...
{
char szImageFolder[MAX_PATH];
LiteStep::GetPrefixedRCLine(szImageFolder, sizeof(szImageFolder), "LS", "ImageFolder", "");
StringCchCopy(gData->szParsedPath, sizeof(gData->szParsedPath), szImageFolder);
StringCchCat(gData->szParsedPath, sizeof(gData->szParsedPath), szToken);
}
else
{
StringCchCopy(gData->szParsedPath, sizeof(gData->szParsedPath), szToken);
}
}
else
{
StringCchCopy(gData->szParsedPath, sizeof(gData->szParsedPath), szToken);
}
}
}
// Update the trackoffset
void Bangs::SetTrackOffset(HWND, LPCSTR pszArgs)
{
char szToken[MAX_LINE_LENGTH];
LPCSTR pszNext = pszArgs;
// Get the group name (first token)
GetToken(pszNext, szToken, &pszNext, false);
GroupData* gData = AlbumArt::GetGroupByPrefix(szToken);
if (gData != NULL)
{
// Get the new offset (second token)
GetToken(pszNext, szToken, &pszNext, false);
// Update the GroupData
gData->iTrackOffset = atoi(szToken);
// Let UpdateInformation handle everything else
AlbumArt::UpdateInformation(true);
}
}
// Update the OutOfBounds path
void Bangs::SetOutOfBoundsPath(HWND, LPCSTR pszArgs)
{
char szToken[MAX_LINE_LENGTH];
LPCSTR pszNext = pszArgs;
// Get the group name (first token)
GetToken(pszNext, szToken, &pszNext, false);
GroupData* gData = AlbumArt::GetGroupByPrefix(szToken);
if (gData != NULL)
{
// Get the new path (second token)
GetToken(pszNext, szToken, &pszNext, false);
// Update the OutOfBounds path
if (strcmp(szToken, "") != 0)
{
if (szToken[1] != ':') // Relative path...
{
char szImageFolder[MAX_PATH];
LiteStep::GetPrefixedRCLine(szImageFolder, sizeof(szImageFolder), "LS", "ImageFolder", "");
StringCchCopy(gData->szOutOfBoundsPath, sizeof(gData->szOutOfBoundsPath), szImageFolder);
StringCchCat(gData->szOutOfBoundsPath, sizeof(gData->szOutOfBoundsPath), szToken);
}
else
{
StringCchCopy(gData->szOutOfBoundsPath, sizeof(gData->szOutOfBoundsPath), szToken);
}
}
else
{
StringCchCopy(gData->szOutOfBoundsPath, sizeof(gData->szOutOfBoundsPath), szToken);
}
// Check if we are currently using the OutOfBounds path
if (gData->bIsOutOfBounds)
{
AlbumArt::SetPath(gData, gData->szOutOfBoundsPath);
}
}
}
// Set the SearchFolderBeforeTag setting
void Bangs::SetSearchFolderBeforeTag(HWND, LPCSTR pszArgs)
{
char szToken[MAX_LINE_LENGTH];
LPCSTR pszNext = pszArgs;
// Get the group name (first token)
GetToken(pszNext, szToken, &pszNext, false);
GroupData* gData = AlbumArt::GetGroupByPrefix(szToken);
if (gData != NULL)
{
// Get the "BOOL" (second token)
GetToken(pszNext, szToken, &pszNext, false);
if (_stricmp(szToken, "toggle") != 0)
{
gData->bSearchFolderBeforeTag = Utilities::String2Bool(szToken);
}
else // Toggling
{
gData->bSearchFolderBeforeTag = !gData->bSearchFolderBeforeTag;
}
}
}
// Upadtes the AutoDownloadCoversTo path
void Bangs::SetAutoDownloadCoversTo(HWND, LPCSTR pszArgs)
{
char szToken[MAX_LINE_LENGTH];
LPCSTR pszNext = pszArgs;
// Get the group name (first token)
GetToken(pszNext, szToken, &pszNext, false);
GroupData* gData = AlbumArt::GetGroupByPrefix(szToken);
if (gData != NULL)
{
// Get the new path (second token)
GetToken(pszNext, szToken, &pszNext, false);
char szCoverPath[MAX_LINE_LENGTH];
LiteStep::GetPrefixedRCLine(szCoverPath, sizeof(szCoverPath), gData->szPrefix, "Path", "");
// Update the AutoDownloadCoversTo path
StringCchCopy(gData->szDownloadPath, sizeof(gData->szDownloadPath), szToken);
// Check if the current cover is using the NoArtPath, and if so, try to download a new cover
if (_stricmp(szCoverPath, gData->szNoArtPath) == 0)
{
if (_stricmp(szToken, "") != 0)
{
if (!gData->bIsOutOfBounds)
{
HWND hwndWA2 = FindWindow("Winamp v1.x", NULL);
if (hwndWA2 != NULL) // Winamp isn't running
{
int Track = SendMessage(hwndWA2, WM_USER, 0, 125);
HANDLE hWinamp;
ULONG dWinamp;
GetWindowThreadProcessId(hwndWA2, &dWinamp);
hWinamp = OpenProcess(PROCESS_VM_READ, false, dWinamp);
if (hWinamp != NULL)
{
char szTrackPath[MAX_PATH];
void* winampTrack = (void*)SendMessage(hwndWA2, WM_USER, Track + gData->iTrackOffset, 211);
ReadProcessMemory(hWinamp, winampTrack, &szTrackPath, sizeof(szTrackPath), NULL);
if (szTrackPath[4] == ':')
AlbumArt::DownloadCover(gData, szTrackPath + 7);
else
AlbumArt::DownloadCover(gData, szTrackPath);
CloseHandle(hWinamp);
}
}
}
}
}
}
}
// Add some parsetypes
void Bangs::AddParseType(HWND, LPCSTR pszArgs)
{
char szToken[MAX_LINE_LENGTH];
LPCSTR pszNext = pszArgs;
// Get the group name (first token)
GetToken(pszNext, szToken, &pszNext, false);
GroupData* gData = AlbumArt::GetGroupByPrefix(szToken);
if (gData != NULL)
{
// Get the new parsetypes (remaining tokens)
while (GetToken(pszNext, szToken, &pszNext, false))
{
if (strcmp(szToken, "") != 0)
{
gData->ParseTypes.push_back(Utilities::StringToParseType(szToken));
}
}
}
}
// Delete some parsetypes
void Bangs::DeleteParseType(HWND, LPCSTR pszArgs)
{
char szToken[MAX_LINE_LENGTH];
LPCSTR pszNext = pszArgs;
// Get the group name (first token)
GetToken(pszNext, szToken, &pszNext, false);
GroupData* gData = AlbumArt::GetGroupByPrefix(szToken);
if (gData != NULL)
{
// Get the parsetypes to delete (remaining tokens)
while (GetToken(pszNext, szToken, &pszNext, false))
{
if (_stricmp(szToken, ".all") == 0)
{
gData->ParseTypes.clear();
break;
}
else if (strcmp(szToken, "") != 0)
{
UCHAR uType = Utilities::StringToParseType(szToken);
for (std::vector<UCHAR>::const_iterator iter = gData->ParseTypes.begin(); iter != gData->ParseTypes.end(); iter++)
{
if (*iter == uType)
{
gData->ParseTypes.erase(iter);
}
}
}
}
}
}
// Add some covernames
void Bangs::AddCoverName(HWND, LPCSTR pszArgs)
{
char szToken[MAX_LINE_LENGTH];
LPCSTR pszNext = pszArgs;
// Get the group name (first token)
GetToken(pszNext, szToken, &pszNext, false);
GroupData* gData = AlbumArt::GetGroupByPrefix(szToken);
if (gData != NULL)
{
// Get the new covernames (remaining tokens)
while (GetToken(pszNext, szToken, &pszNext, false))
{
if (strcmp(szToken, "") != 0)
{
gData->CoverNames.push_back(std::string(szToken));
}
}
}
}
// Delete some covernames
void Bangs::DeleteCoverName(HWND, LPCSTR pszArgs)
{
char szToken[MAX_LINE_LENGTH];
LPCSTR pszNext = pszArgs;
// Get the group name (first token)
GetToken(pszNext, szToken, &pszNext, false);
GroupData* gData = AlbumArt::GetGroupByPrefix(szToken);
if (gData != NULL)
{
// Get the covernames to delete (remaining tokens)
while (GetToken(pszNext, szToken, &pszNext, false))
{
if (_stricmp(szToken, ".all") == 0)
{
gData->CoverNames.clear();
break;
}
else if (strcmp(szToken, "") != 0)
{
for (std::vector<std::string>::const_iterator iter = gData->CoverNames.begin(); iter != gData->CoverNames.end(); iter++)
{
if (strcmp(iter->c_str(), szToken) == 0)
{
gData->CoverNames.erase(iter);
}
}
}
}
}
}
// Manually download the cover art
void Bangs::DownloadCover(HWND, LPCSTR pszArgs)
{
char szToken[MAX_LINE_LENGTH], szSavePath[MAX_PATH], szAlbumName[MAX_LINE_LENGTH];
LPCSTR pszNext = pszArgs;
szSavePath[0] = szAlbumName[0] = 0;
// Get the group name (first token)
if (GetToken(pszNext, szToken, &pszNext, false))
{
if (_stricmp(szToken, ".none") == 0) // Group set to .none
{
// Get the path (2nd token) and albumname (3rd token)
if (GetToken(pszNext, szSavePath, &pszNext, false))
{
GetToken(pszNext, szAlbumName, &pszNext, false);
}
}
else
{
GroupData* gData = AlbumArt::GetGroupByPrefix(szToken);
if (gData != NULL)
{
// Get the path to download the file to (2nd token)
if (GetToken(pszNext, szSavePath, &pszNext, false))
{
if (_stricmp(szSavePath, "") != 0)
{
char szTrackPath[MAX_PATH];
// Get the albums name...
if (!gData->bIsOutOfBounds)
{
HWND hwndWA2 = FindWindow("Winamp v1.x", NULL);
if (hwndWA2 != NULL) // Winamp isn't running
{
int Track = SendMessage(hwndWA2, WM_USER, 0, 125);
HANDLE hWinamp;
ULONG dWinamp;
GetWindowThreadProcessId(hwndWA2, &dWinamp);
hWinamp = OpenProcess(PROCESS_VM_READ, false, dWinamp);
if (hWinamp != NULL)
{
void* winampTrack = (void*)SendMessage(hwndWA2, WM_USER, Track + gData->iTrackOffset, 211);
ReadProcessMemory(hWinamp, winampTrack, &szTrackPath, sizeof(szTrackPath), NULL);
if (szTrackPath[4] == ':')
StringCchCopy(szTrackPath, sizeof(szTrackPath), (LPCSTR)(szTrackPath + 7));
Utilities::GetExtendedWinampFileInfo(szTrackPath, "Album", szAlbumName, sizeof(szAlbumName));
CloseHandle(hWinamp);
}
}
}
// Let relative paths be relative to the folder
if (szSavePath[1] != ':') // If it's a relative path
{
StringCchCopy(szToken, sizeof(szToken), szSavePath);
StringCchCopy(szSavePath, sizeof(szSavePath), szTrackPath);
for (int i = sizeof(szSavePath); i > 0; i--)
{
if (szSavePath[i] == '\\')
{
szSavePath[++i] = 0;
break;
}
}
StringCchCat(szSavePath, sizeof(szSavePath), szToken);
}
}
}
}
}
// Download the cover, if appropriate
if (_stricmp(szSavePath, "") != 0)
{
if (_stricmp(szAlbumName, "") != 0)
{
DownLoadCoverData CoverData = {0};
StringCchCopy(CoverData.szAlbum, sizeof(CoverData.szAlbum), szAlbumName);
StringCchCopy(CoverData.szPath, sizeof(CoverData.szPath), szSavePath);
// Start the downloader thread
_beginthreadex(NULL, 0, AlbumArt_Download_Thread::DownloadCover_Thread, &CoverData, 0, &CoverData.threadID);
// We need to give the thread time to copy over the DownLoadCoverData struct to its own memory
while (!CoverData.bInitalized) // WaitForSingleObject is a pain...
{
Sleep(10);
}
}
}
}
}