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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
|
#include "main.h"
#include "ml.h"
#include "itemlist.h"
#include "../winamp/gen.h"
#include "config.h"
#include "../winamp/wa_ipc.h"
#include "../winamp/ipc_pe.h"
#include "resource.h"
#include "comboskin.h"
#include "../winamp/wa_dlg.h"
#include "childwnd.h"
#include "sendto.h"
#include "api__gen_ml.h"
#include "../nu/autowide.h"
#include "../nu/autochar.h"
#if defined(_WIN64)
#include "../Elevator/IFileTypeRegistrar_64.h"
#else
#include "../Elevator/IFileTypeRegistrar_32.h"
#endif
#include <time.h>
#include <shlwapi.h>
#include <strsafe.h>
#include "..\WAT\wa_logger.h"
#define ListView_InsertColumnW(hwnd, iCol, pcol) \
(int)SNDMSG((hwnd), LVM_INSERTCOLUMNW, (WPARAM)(int)(iCol), (LPARAM)(const LV_COLUMNW *)(pcol))
#define ListView_InsertItemW(hwnd, pitem) \
(int)SNDMSG((hwnd), LVM_INSERTITEMW, 0, (LPARAM)(const LV_ITEMW *)(pitem))
#define ListView_SetItemTextW(hwndLV, i, iSubItem_, pszText_) \
{ LV_ITEMW _macro_lvi;\
_macro_lvi.iSubItem = (iSubItem_);\
_macro_lvi.pszText = (pszText_);\
SNDMSG((hwndLV), LVM_SETITEMTEXTW, (WPARAM)(i), (LPARAM)(LV_ITEMW *)&_macro_lvi);\
}
#define ListView_SetItemW(hwnd, pitem) \
(BOOL)SNDMSG((hwnd), LVM_SETITEMW, 0, (LPARAM)(LV_ITEMW *)(pitem))
#define ListView_GetItemW(hwnd, pitem) \
(BOOL)SNDMSG((hwnd), LVM_GETITEMW, 0, (LPARAM)(LV_ITEMW *)(pitem))
extern "C" winampGeneralPurposePlugin plugin;
C_ItemList m_plugins;
static HCURSOR link_hand_cursor;
LRESULT link_handlecursor(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT ret = CallWindowProcW((WNDPROC)GetPropW(hwndDlg, L"link_proc"), hwndDlg, uMsg, wParam, lParam);
// override the normal cursor behaviour so we have a hand to show it is a link
if ( uMsg == WM_SETCURSOR )
{
if ( (HWND)wParam == hwndDlg )
{
if ( !link_hand_cursor )
{
link_hand_cursor = LoadCursor(NULL, IDC_HAND);
}
SetCursor(link_hand_cursor);
return TRUE;
}
}
return ret;
}
void link_startsubclass(HWND hwndDlg, UINT id)
{
HWND ctrl = GetDlgItem(hwndDlg, id);
SetPropW(ctrl, L"link_proc",
(HANDLE)(LONG_PTR)SetWindowLongPtrW(ctrl, GWLP_WNDPROC, (LONGX86)(LONG_PTR)link_handlecursor));
}
void link_handledraw(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if ( uMsg == WM_DRAWITEM )
{
DRAWITEMSTRUCT* di = (DRAWITEMSTRUCT*)lParam;
if ( di->CtlType == ODT_BUTTON )
{
wchar_t wt[123] = { 0 };
int y;
RECT r;
HPEN hPen, hOldPen;
GetDlgItemTextW(hwndDlg, (INT)wParam, wt, 123);
// draw text
SetTextColor(di->hDC, (di->itemState & ODS_SELECTED) ? RGB(220, 0, 0) : RGB(0, 0, 220));
r = di->rcItem;
r.left += 2;
DrawTextW(di->hDC, wt, -1, &r, DT_VCENTER | DT_SINGLELINE);
memset(&r, 0, sizeof(r));
DrawTextW(di->hDC, wt, -1, &r, DT_SINGLELINE | DT_CALCRECT);
// draw underline
y = di->rcItem.bottom - ((di->rcItem.bottom - di->rcItem.top) - (r.bottom - r.top)) / 2 - 1;
hPen = CreatePen(PS_SOLID, 0, (di->itemState & ODS_SELECTED) ? RGB(220, 0, 0) : RGB(0, 0, 220));
hOldPen = (HPEN)SelectObject(di->hDC, hPen);
MoveToEx(di->hDC, di->rcItem.left + 2, y, NULL);
LineTo(di->hDC, di->rcItem.right + 2 - ((di->rcItem.right - di->rcItem.left) - (r.right - r.left)), y);
SelectObject(di->hDC, hOldPen);
DeleteObject(hPen);
}
}
}
/* In Winamp's preferences, Plugins->Media Library */
static bool pluginsLoaded;
INT_PTR CALLBACK PluginsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if ( uMsg == WM_INITDIALOG )
{
pluginsLoaded = false;
extern BOOL init2();
if ( !g_hwnd ) init2();
WIN32_FIND_DATAW d = { 0 };
link_startsubclass(hwndDlg, IDC_PLUGINVERS);
HWND listWindow = GetDlgItem(hwndDlg, IDC_GENLIB);
if ( NULL != listWindow )
{
RECT r = { 0 }, rc = { 0 };
GetWindowRect(listWindow, &r);
GetClientRect(listWindow, &r);
MapWindowPoints(listWindow, hwndDlg, (LPPOINT)&r, 2);
InflateRect(&r, 2, 2);
DestroyWindow(listWindow);
listWindow = CreateWindowExW(WS_EX_NOPARENTNOTIFY | WS_EX_CLIENTEDGE, WC_LISTVIEWW, L"",
WS_CHILD | WS_VISIBLE | WS_TABSTOP | LVS_REPORT | LVS_SINGLESEL |
LVS_SHOWSELALWAYS | LVS_SORTASCENDING | LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER,
r.left, r.top, r.right - r.left, r.bottom - r.top,
hwndDlg, (HMENU)IDC_GENLIB, NULL, NULL);
SetWindowPos(listWindow, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
ListView_SetExtendedListViewStyleEx(listWindow, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
SendMessage(listWindow, WM_SETFONT, SendMessage(hwndDlg, WM_GETFONT, 0, 0), FALSE);
LVCOLUMNW lvc = { 0 };
ListView_InsertColumnW(listWindow, 0, &lvc);
ListView_InsertColumnW(listWindow, 1, &lvc);
wchar_t filename[MAX_PATH] = { 0 }, description[512] = { 0 };
for ( int x = 0; x < m_plugins.GetSize(); x++ )
{
winampMediaLibraryPlugin* mlplugin = (winampMediaLibraryPlugin*)m_plugins.Get(x);
if ( mlplugin && mlplugin->hDllInstance )
{
wchar_t buf[512] = { 0 };
LVITEMW lvi = { LVIF_TEXT | LVIF_PARAM, x, 0 };
lstrcpynW(buf, (mlplugin->version >= MLHDR_VER_U ? (wchar_t*)mlplugin->description : AutoWide(mlplugin->description)), 512);
lvi.pszText = buf;
lvi.lParam = x;
lvi.iItem = ListView_InsertItemW(listWindow, &lvi);
GetModuleFileNameW(mlplugin->hDllInstance, filename, ARRAYSIZE(filename));
PathStripPathW(filename);
lvi.mask = LVIF_TEXT;
lvi.iSubItem = 1;
lvi.pszText = filename;
ListView_SetItemW(listWindow, &lvi);
}
}
wchar_t dirstr[MAX_PATH] = { 0 };
PathCombineW(dirstr, pluginPath, L"ML_*.DLL");
HANDLE h = FindFirstFileW(dirstr, &d);
if ( h != INVALID_HANDLE_VALUE )
{
do
{
PathCombineW(dirstr, pluginPath, d.cFileName);
HMODULE b = LoadLibraryExW(dirstr, NULL, LOAD_LIBRARY_AS_DATAFILE);
int x = 0;
for ( x = 0; b && (x != m_plugins.GetSize()); x++ )
{
winampMediaLibraryPlugin* mlplugin = (winampMediaLibraryPlugin*)m_plugins.Get(x);
if ( mlplugin->hDllInstance == b )
{
break;
}
}
if ( x == m_plugins.GetSize() || !b )
{
LVITEMW lvi = { LVIF_TEXT | LVIF_PARAM, x, 0 };
lvi.pszText = d.cFileName;
lvi.lParam = -2;
lvi.iItem = ListView_InsertItemW(listWindow, &lvi);
lvi.mask = LVIF_TEXT;
lvi.iSubItem = 1;
lvi.pszText = WASABI_API_LNGSTRINGW(IDS_NOT_LOADED);
ListView_SetItemW(listWindow, &lvi);
}
FreeLibrary(b);
} while ( FindNextFileW(h, &d) );
FindClose(h);
}
GetClientRect(listWindow, &r);
ListView_SetColumnWidth(listWindow, 1, LVSCW_AUTOSIZE);
ListView_SetColumnWidth(listWindow, 0, (r.right - r.left) - ListView_GetColumnWidth(listWindow, 1));
if ( NULL != WASABI_API_APP )
WASABI_API_APP->DirectMouseWheel_EnableConvertToMouseWheel(listWindow, TRUE);
pluginsLoaded = true;
}
}
else if ( uMsg == WM_NOTIFY )
{
LPNMHDR p = (LPNMHDR)lParam;
if ( p->idFrom == IDC_GENLIB )
{
if ( p->code == LVN_ITEMCHANGED )
{
LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lParam;
LVITEM lvi = { LVIF_PARAM, pnmv->iItem };
if ( ListView_GetItem(p->hwndFrom, &lvi) && (pnmv->uNewState & LVIS_SELECTED) )
{
int loaded = (lvi.lParam != -2);
if ( loaded )
{
winampMediaLibraryPlugin* mlplugin;
if ( lvi.lParam >= 0 && lvi.lParam < m_plugins.GetSize() && (mlplugin = (winampMediaLibraryPlugin*)m_plugins.Get(lvi.lParam)) )
{
EnableWindow(GetDlgItem(hwndDlg, IDC_UNINST), !!mlplugin->hDllInstance);
// enables / disables the config button as applicable instead of the
// "This plug-in has no configuration implemented" message (opt-in)
EnableWindow(GetDlgItem(hwndDlg, IDC_GENCONF), (!mlplugin->MessageProc(ML_MSG_NO_CONFIG, 0, 0, 0)));
}
}
else
{
EnableWindow(GetDlgItem(hwndDlg, IDC_GENCONF), 0);
}
EnableWindow(GetDlgItem(hwndDlg, IDC_UNINST), 1);
}
else
{
EnableWindow(GetDlgItem(hwndDlg, IDC_GENCONF), 0);
EnableWindow(GetDlgItem(hwndDlg, IDC_UNINST), 0);
}
}
else if ( p->code == NM_DBLCLK )
{
PostMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_GENCONF, 0), (LPARAM)GetDlgItem(hwndDlg, IDC_GENCONF));
}
}
else if ( p->code == HDN_ITEMCHANGINGW )
{
if ( pluginsLoaded )
{
#if defined(_WIN64)
SetWindowLong(hwndDlg, DWLP_MSGRESULT, TRUE);
#else
SetWindowLong(hwndDlg, DWL_MSGRESULT, TRUE);
#endif
return TRUE;
}
}
}
else if ( uMsg == WM_DESTROY )
{
HWND listWindow = GetDlgItem(hwndDlg, IDC_GENLIB);
if ( IsWindow(listWindow) && (NULL != WASABI_API_APP) )
WASABI_API_APP->DirectMouseWheel_EnableConvertToMouseWheel(listWindow, FALSE);
}
else if ( uMsg == WM_COMMAND )
{
switch ( LOWORD(wParam) )
{
case IDC_GENCONF:
{
if ( IsWindowEnabled(GetDlgItem(hwndDlg, IDC_GENCONF)) )
{
HWND listWindow = GetDlgItem(hwndDlg, IDC_GENLIB);
LVITEM lvi = { LVIF_PARAM, ListView_GetSelectionMark(listWindow) };
if ( ListView_GetItem(listWindow, &lvi) )
{
winampMediaLibraryPlugin* mlplugin;
if ( lvi.lParam >= 0 && lvi.lParam < m_plugins.GetSize() && (mlplugin = (winampMediaLibraryPlugin*)m_plugins.Get(lvi.lParam)) )
{
if ( mlplugin->MessageProc && mlplugin->MessageProc(ML_MSG_CONFIG, (INT_PTR)hwndDlg, 0, 0) )
{
}
else
{
wchar_t title[128] = { 0 };
MessageBoxW(hwndDlg, WASABI_API_LNGSTRINGW(IDS_NO_CONFIG_PRESENT),
WASABI_API_LNGSTRINGW_BUF(IDS_ML_PLUGIN_INFO, title, 128), MB_OK);
}
}
}
}
}
return FALSE;
case IDC_UNINST:
{
if ( IsWindowEnabled(GetDlgItem(hwndDlg, IDC_UNINST)) )
{
HWND listWindow = GetDlgItem(hwndDlg, IDC_GENLIB);
int which_sel = ListView_GetSelectionMark(listWindow);
LVITEM lvi = { LVIF_PARAM, which_sel };
if ( ListView_GetItem(listWindow, &lvi) )
{
winampMediaLibraryPlugin* mlplugin;
wchar_t title[32] = { 0 };
int msgBox = MessageBoxW(hwndDlg, WASABI_API_LNGSTRINGW(IDS_UNINSTALL_PROMPT),
WASABI_API_LNGSTRINGW_BUF(IDS_UINSTALL_CONFIRMATION, title, 32),
MB_YESNO | MB_ICONEXCLAMATION);
if ( lvi.lParam >= 0 && lvi.lParam < m_plugins.GetSize() && (mlplugin = (winampMediaLibraryPlugin*)m_plugins.Get(lvi.lParam)) && msgBox == IDYES )
{
int ret = 0;
int (*pr)(HINSTANCE hDllInst, HWND hwndDlg, int param);
*(void**)&pr = (void*)GetProcAddress(mlplugin->hDllInstance, "winampUninstallPlugin");
if ( pr )ret = pr(mlplugin->hDllInstance, hwndDlg, 0);
// ok to uninstall but do with a full restart (default/needed in subclassing cases)
if ( ret == ML_PLUGIN_UNINSTALL_REBOOT )
{
wchar_t buf[MAX_PATH] = { 0 };
GetModuleFileNameW(mlplugin->hDllInstance, buf, MAX_PATH);
WritePrivateProfileStringW(L"winamp", L"remove_genplug", buf, WINAMP_INI);
WritePrivateProfileStringW(L"winamp", L"show_prefs", L"-1", WINAMP_INI);
PostMessage(plugin.hwndParent, WM_WA_IPC, 0, IPC_RESTARTWINAMP);
}
// added from 5.37+ so we can do true on-the-fly removals (will fall back to default if fails)
else if ( ret == ML_PLUGIN_UNINSTALL_NOW )
{
// get the filename before we free the dll otherwise things may go boom
wchar_t buf[MAX_PATH] = { 0 };
GetModuleFileNameW(mlplugin->hDllInstance, buf, MAX_PATH);
mlplugin->quit();
//if (mlplugin->hDllInstance) FreeLibrary(mlplugin->hDllInstance);
m_plugins.Del(lvi.lParam);
// try to use the elevator to do this
IFileTypeRegistrar* registrar = (IFileTypeRegistrar*)SendMessage(plugin.hwndParent, WM_WA_IPC, 0, IPC_GET_FILEREGISTRAR_OBJECT);
if ( registrar && (registrar != (IFileTypeRegistrar*)1) )
{
if ( registrar->DeleteItem(buf) != S_OK )
{
WritePrivateProfileStringW(L"winamp", L"remove_genplug", buf, WINAMP_INI);
WritePrivateProfileStringW(L"winamp", L"show_prefs", L"-1", WINAMP_INI);
PostMessage(plugin.hwndParent, WM_WA_IPC, 0, IPC_RESTARTWINAMP);
}
else
ListView_DeleteItem(listWindow, which_sel);
registrar->Release();
}
}
}
// will cope with not loaded plug-ins so we can still remove them, etc
else if ( lvi.lParam == -2 && msgBox == IDYES )
{
wchar_t buf[1024] = { 0 }, base[1024] = { 0 };
GetModuleFileNameW(plugin.hDllInstance, base, sizeof(base) / sizeof(wchar_t));
LVITEMW lvi = { LVIF_TEXT, which_sel };
lvi.pszText = buf;
lvi.cchTextMax = ARRAYSIZE(buf);
ListView_GetItemW(listWindow, &lvi);
wchar_t* p = wcschr(buf, L'.');
if ( p && *p == L'.' )
{
p += 4;
*p = 0;
PathRemoveFileSpecW(base);
PathAppendW(base, buf);
}
// try to use the elevator to do this
IFileTypeRegistrar* registrar = (IFileTypeRegistrar*)SendMessage(plugin.hwndParent, WM_WA_IPC, 0, IPC_GET_FILEREGISTRAR_OBJECT);
if ( registrar && (registrar != (IFileTypeRegistrar*)1) )
{
if ( registrar->DeleteItem(base) != S_OK )
{
WritePrivateProfileStringW(L"winamp", L"remove_genplug", base, WINAMP_INI);
WritePrivateProfileStringW(L"winamp", L"show_prefs", L"-1", WINAMP_INI);
PostMessage(plugin.hwndParent, WM_WA_IPC, 0, IPC_RESTARTWINAMP);
}
else
ListView_DeleteItem(listWindow, which_sel);
registrar->Release();
}
// otherwise revert to a standard method
else
{
WritePrivateProfileStringW(L"winamp", L"remove_genplug", base, WINAMP_INI);
WritePrivateProfileStringW(L"winamp", L"show_prefs", L"-1", WINAMP_INI);
PostMessage(plugin.hwndParent, WM_WA_IPC, 0, IPC_RESTARTWINAMP);
}
}
// resets the focus to the listbox so it'll keep ui response working
SetFocus(GetDlgItem(hwndDlg, IDC_GENLIB));
}
}
}
return FALSE;
case IDC_PLUGINVERS:
myOpenURLWithFallback(hwndDlg, L"http://www.google.com/search?q=Winamp+Library+Plugins", L"http://www.google.com/search?q=Winamp+Library+Plugins");
return TRUE;
}
}
link_handledraw(hwndDlg, uMsg, wParam, lParam);
return 0;
}
typedef struct _PLUGINORDER
{
LPCWSTR name;
bool found;
} PLUGINORDER;
static PLUGINORDER preload[] =
{
{ L"ml_local.dll", false },
{ L"ml_downloads.dll", false },
{ L"ml_playlists.dll", false },
{ L"ml_wire.dll", false },
{ L"ml_online.dll", false },
{ L"ml_history.dll", false },
{ L"ml_rg.dll", false },
{ L"ml_bookmarks.dll", false },
{ L"ml_disc.dll", false },
{ L"ml_nowplaying2.dll", false },
{ L"ml_devices.dll", false },
{ L"ml_pmp.dll", false },
};
static HANDLE hProfile = INVALID_HANDLE_VALUE;
HANDLE GetProfileFileHandle(int mode)
{
if ( profile & mode )
{
if ( hProfile == INVALID_HANDLE_VALUE )
{
wchar_t profileFile[MAX_PATH] = { 0 };
PathCombineW(profileFile, WINAMP_INI_DIR, ((mode == 2) ? L"profile_load.txt" : L"profile.txt"));
hProfile = CreateFileW(profileFile, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if ( hProfile != INVALID_HANDLE_VALUE )
{
// just to make sure we don't over-write things
SetFilePointer(hProfile, NULL, NULL, FILE_END);
}
}
return hProfile;
}
return INVALID_HANDLE_VALUE;
}
void LoadPlugin(const wchar_t* filename)
{
wsprintfW( _log_message_w, L"filename( %s )", filename );
LOG_DEBUG( _log_message_w );
wchar_t profile[MAX_PATH * 2] = { 0 };
LARGE_INTEGER starttime, endtime;
if ( hProfile != INVALID_HANDLE_VALUE )
{
QueryPerformanceCounter(&starttime);
}
wchar_t file[MAX_PATH] = { 0 };
PathCombineW(file, pluginPath, filename);
if ( !wa::files::file_exists( file ) )
{
wsprintfW( _log_message_w, L"The plugin '%s' is not found in the \"Plugins\" folder!", filename );
LOG_ERROR( _log_message_w );
return;
}
HMODULE hLib = LoadLibraryW(file);
if (hLib == NULL)
{
DWORD l_error_code = ::GetLastError();
wsprintfW( _log_message_w, L"Error when loading the plugin '%s'! Error code : %d!", filename, l_error_code );
LOG_ERROR( _log_message_w );
return;
}
winampMediaLibraryPlugin* (*pr)();
pr = (winampMediaLibraryPlugin * (__cdecl*)(void)) GetProcAddress(hLib, "winampGetMediaLibraryPlugin");
if (pr == NULL)
{
wsprintfW( _log_message_w, L"No entry point found for the plugin '%s'!", filename );
LOG_ERROR( _log_message_w );
FreeLibrary(hLib);
return;
}
winampMediaLibraryPlugin* mlplugin = pr();
if ( !mlplugin || (mlplugin->version > MLHDR_VER && mlplugin->version < MLHDR_VER_OLD) )
{
wsprintfW( _log_message_w, L"Either the plugin '%s' can't be loaded, or its version is incorrect!", filename );
LOG_ERROR( _log_message_w );
FreeLibrary(hLib);
return;
}
wsprintfW( _log_message_w, L"The plugin '%s' is correctly loaded!", filename );
LOG_DEBUG( _log_message_w );
if ( g_safeMode != 1 )
{
if ( g_safeMode == 2 )
{
FreeModule(hLib);
return;
}
char desc[128] = { 0 };
lstrcpynA(desc, mlplugin->description, sizeof(desc));
if ( desc[0] && !memcmp(desc, "nullsoft(", 9) )
{
char* p = strrchr(desc, ')');
if ( p )
{
*p = 0;
if ( stricmp(AutoChar(filename), (desc + 9)) )
{
FreeModule(hLib);
return;
}
}
}
else
{
FreeModule(hLib);
return;
}
}
mlplugin->hwndLibraryParent = g_hwnd;
mlplugin->hwndWinampParent = plugin.hwndParent;
mlplugin->hDllInstance = hLib;
int index = m_plugins.GetSize();
if ( mlplugin->version >= MLHDR_VER )
{
mlplugin->service = WASABI_API_SVC;
}
if ( mlplugin->init() == ML_INIT_SUCCESS )
{
wsprintfW( _log_message_w, L"The plugin '%s' is initialized!", filename );
LOG_DEBUG( _log_message_w );
m_plugins.Add( (void *)mlplugin );
}
else
{
wsprintfW( _log_message_w, L"An error occurs when initializing the plugin '%s'!", filename );
LOG_ERROR( _log_message_w );
FreeLibrary( hLib );
return;
}
if ( hProfile != INVALID_HANDLE_VALUE && mlplugin->hDllInstance )
{
QueryPerformanceCounter(&endtime);
DWORD written = 0;
unsigned int ms = (UINT)((endtime.QuadPart - starttime.QuadPart) * 1000 / freq.QuadPart);
int len = swprintf(profile, L"Library\t%s\t[%s]\t%dms\r\n", file,
(mlplugin->version >= MLHDR_VER_U ? (wchar_t*)mlplugin->description : AutoWide(mlplugin->description)), ms);
SetFilePointer(hProfile, NULL, NULL, FILE_END);
WriteFile(hProfile, profile, len * sizeof(wchar_t), &written, NULL);
}
}
void loadMlPlugins()
{
HANDLE hProfile = GetProfileFileHandle(2);
WIN32_FIND_DATAW d = { 0 };
wchar_t tofind[MAX_PATH] = { 0 };
int i, count = ARRAYSIZE(preload);
for ( i = 0; i < count; i++ )
LoadPlugin(preload[i].name);
PathCombineW(tofind, pluginPath, L"ML_*.DLL");
HANDLE h = FindFirstFileW(tofind, &d);
if ( h != INVALID_HANDLE_VALUE )
{
do
{
for ( i = 0; i < count && (preload[i].found || lstrcmpiW(preload[i].name, d.cFileName)); i++ );
if ( i == count )
LoadPlugin(d.cFileName);
else
preload[i].found = true;
} while ( FindNextFileW(h, &d) );
FindClose(h);
}
if ( hProfile != INVALID_HANDLE_VALUE )
{
DWORD written = 0;
WriteFile(hProfile, L"\r\n", 2, &written, NULL);
CloseHandle(hProfile);
hProfile = INVALID_HANDLE_VALUE;
}
if ( !m_plugins.GetSize() )
ShowWindow(GetDlgItem(g_hwnd, IDC_NO_VIEW), SW_SHOW);
}
void unloadMlPlugins()
{
HANDLE hProfile = GetProfileFileHandle(1);
if ( hProfile != INVALID_HANDLE_VALUE )
{
DWORD written = 0;
WriteFile(hProfile, L"\r\n", 2, &written, NULL);
}
int i = m_plugins.GetSize();
while ( i-- > 0 ) // reverse order to aid in not fucking up subclassing shit
{
winampMediaLibraryPlugin* mlplugin = (winampMediaLibraryPlugin*)m_plugins.Get(i);
wchar_t profile[MAX_PATH * 2] = { 0 }, filename[MAX_PATH] = { 0 };
LARGE_INTEGER starttime, endtime;
if ( hProfile != INVALID_HANDLE_VALUE )
{
GetModuleFileNameW(mlplugin->hDllInstance, filename, MAX_PATH);
QueryPerformanceCounter(&starttime);
}
if ( mlplugin->quit )
mlplugin->quit(); // deals with 'virtual' ml items on restart
if ( hProfile != INVALID_HANDLE_VALUE && mlplugin->hDllInstance )
{
QueryPerformanceCounter(&endtime);
DWORD written = 0;
unsigned int ms = (UINT)((endtime.QuadPart - starttime.QuadPart) * 1000 / freq.QuadPart);
int len = swprintf(profile, L"Library\t%s\t[%s]\t%dms\r\n", filename,
(mlplugin->version >= MLHDR_VER_U ? (wchar_t*)mlplugin->description : AutoWide(mlplugin->description)), ms);
SetFilePointer(hProfile, NULL, NULL, FILE_END);
WriteFile(hProfile, profile, len * sizeof(wchar_t), &written, NULL);
}
m_plugins.Del(i);
}
if ( hProfile != INVALID_HANDLE_VALUE )
{
DWORD written = 0;
WriteFile(hProfile, L"\r\n", 2, &written, NULL);
CloseHandle(hProfile);
hProfile = INVALID_HANDLE_VALUE;
}
}
INT_PTR plugin_SendMessage(int message_type, INT_PTR param1, INT_PTR param2, INT_PTR param3)
{
for ( int i = 0; i < m_plugins.GetSize(); i++ )
{
winampMediaLibraryPlugin* mlplugin = (winampMediaLibraryPlugin*)m_plugins.Get(i);
if ( mlplugin && mlplugin->MessageProc )
{
INT_PTR h = mlplugin->MessageProc(message_type, param1, param2, param3);
if ( h )
return h;
}
}
return 0;
}
|