forked from TheSaw/win7shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_win7shell.cpp
2623 lines (2356 loc) · 69.4 KB
/
gen_win7shell.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
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
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define PLUGIN_VERSION L"4.8.1"
#define NR_BUTTONS 15
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <commdlg.h>
#include <dwmapi.h>
#include <shlobj.h>
#include <shellapi.h>
#include <strsafe.h>
#include <shobjidl.h>
#include <gdiplus.h>
#include <process.h>
#include "gen_win7shell.h"
#include <loader/loader/utils.h>
#include <loader/loader/runtime_helper.h>
#include <loader/hook/squash.h>
#include <loader/hook/plugins.h>
#include <sdk/winamp/wa_cup.h>
#include <sdk/winamp/wa_msgids.h>
#include <sdk/Agave/Language/lang.h>
#include <sdk/winamp/ipc_pe.h>
#include <common/wa_prefs.h>
#include "resource.h"
#include "api.h"
#include "tools.h"
#include "metadata.h"
#include "jumplist.h"
#include "settings.h"
#include "taskbar.h"
#include "renderer.h"
// TODO add to lang.h
// Taskbar Integration plugin (gen_win7shell.dll)
// {0B1E9802-CA15-4939-8445-FD800E8BFF9A}
static const GUID GenWin7PlusShellLangGUID =
{ 0xb1e9802, 0xca15, 0x4939, { 0x84, 0x45, 0xfd, 0x80, 0xe, 0x8b, 0xff, 0x9a } };
SETUP_API_LNG_VARS;
UINT WM_TASKBARBUTTONCREATED = (UINT)-1;
std::wstring AppID; // this is updated on loading to what the
// running WACUP install has generated as
// it otherwise makes multiple instances
// tricky to work with independently
bool thumbshowing = false, no_uninstall = true, classicSkin = true,
windowShade = false, modernSUI = false, modernFix = false,
finishedLoad = false, running = false, closing = false;
HWND ratewnd = 0, dialogParent = 0;
int pladv = 1, repeat = 0;
#ifdef USE_MOUSE
HHOOK hMouseHook = NULL;
#endif
SettingsManager *SManager = NULL;
sSettings Settings = { 0 };
std::vector<int> TButtons;
iTaskBar *itaskbar = NULL;
MetaData *metadata = NULL;
renderer *thumbnaildrawer = NULL;
HANDLE updatethread = NULL, setupthread = NULL;
CRITICAL_SECTION g_cs[4] = { 0 };
HIMAGELIST theicons = NULL, overlayicons = NULL;
api_albumart *WASABI_API_ALBUMART = 0;
api_playlists *WASABI_API_PLAYLISTS = 0;
//api_explorerfindfile *WASABI_API_EXPLORERFINDFILE = 0;
// CALLBACKS
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
LRESULT CALLBACK rateWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
#ifdef USE_MOUSE
LRESULT CALLBACK KeyboardEvent(int nCode, WPARAM wParam, LPARAM lParam);
#endif
WA_UTILS_API HBITMAP GetMainWindowBmp(void);
#ifndef _WIN64
WA_UTILS_API const bool IsWasabiWindow(HWND hwnd);
WA_UTILS_API const bool IsModernSkinActive(const wchar_t** skin);
#endif
extern "C" __declspec(dllexport) LRESULT CALLBACK TabHandler_Taskbar(HWND, UINT, WPARAM, LPARAM);
extern "C" __declspec(dllexport) LRESULT CALLBACK TabHandler_Thumbnail(HWND, UINT, WPARAM, LPARAM);
extern "C" __declspec(dllexport) LRESULT CALLBACK TabHandler_ThumbnailImage(HWND, UINT, WPARAM, LPARAM);
void updateToolbar(HIMAGELIST ImageList = NULL);
void SetupJumpList(void);
void SetThumbnailTimer(void);
void AddStringtoList(HWND window, const int control_ID);
// Winamp EVENTS
int init(void);
void config(void);
void quit(void);
void __cdecl MessageProc(HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM lParam);
// this structure contains plugin information, version, name...
winampGeneralPurposePlugin plugin =
{
(char*)L"Taskbar Integration",
GPPHDR_VER_WACUP,
init, config, quit,
GEN_INIT_WACUP_HAS_MESSAGES
};
MetaData* get_metadata(void)
{
if (metadata == NULL)
{
metadata = new MetaData();
}
return metadata;
}
bool CreateThumbnailDrawer(const bool always_create = true)
{
if ((thumbnaildrawer == NULL) && always_create)
{
// Create thumbnail renderer
thumbnaildrawer = new renderer(Settings, *get_metadata());
}
return (thumbnaildrawer != NULL);
}
#if 0
const bool GenerateAppIDFromFolder(const wchar_t *search_path, wchar_t *app_id)
{
CreateCOM();
IKnownFolderManager* pkfm = NULL;
HRESULT hr = CreateCOMInProc(CLSID_KnownFolderManager,
__uuidof(IKnownFolderManager), (LPVOID*)&pkfm);
if (SUCCEEDED(hr))
{
IKnownFolder* pFolder = NULL;
// use FFFP_NEARESTPARENTMATCH instead of FFFP_EXACTMATCH so
// it'll better cope with the possible variations in location
if (SUCCEEDED(pkfm->FindFolderFromPath(search_path, FFFP_NEARESTPARENTMATCH, &pFolder)))
{
wchar_t *path = 0;
if (SUCCEEDED(pFolder->GetPath(0, &path)))
{
// we now check that things are a match
const size_t len = wcslen(path);
if (SameStrN(search_path, path, len))
{
// and if they are then we'll merge
// the two together to get the final
// version of the string for an appid
KNOWNFOLDERID pkfid = {0};
if (SUCCEEDED(pFolder->GetId(&pkfid)))
{
wchar_t szGuid[40] = {0};
StringFromGUID2(pkfid, szGuid, 40);
StringCchPrintf(app_id, MAX_PATH, L"%s%s", szGuid, &search_path[len]);
}
}
}
MemFreeCOM(path);
pFolder->Release();
return (!!app_id[0]);
}
pkfm->Release();
}
return false;
}
LPCWSTR GetAppID(void)
{
// we do this to make sure we can group things correctly
// especially if used in a plug-in in WACUP so that the
// taskbar handling will be correct vs existing pinnings
// under WACUP, we do a few things so winamp.original is
// instead re-mapped to wacup.exe so the load is called
if (AppID.empty())
{
LPWSTR id = NULL;
GetCurrentProcessExplicitAppUserModelID(&id);
if (!id)
{
wchar_t self_path[MAX_PATH] = { 0 };
if (GetModuleFileName(NULL, self_path, ARRAYSIZE(self_path)))
{
wchar_t app_id[MAX_PATH] = { 0 };
if (!GenerateAppIDFromFolder(self_path, app_id))
{
(void)StringCchCopy(app_id, ARRAYSIZE(app_id), self_path);
}
RenameExtension(app_id, L".exe");
// TODO: auto-pin icon (?)
if (SetCurrentProcessExplicitAppUserModelID(app_id) != S_OK)
{
MessageBox(plugin.hwndParent,
WASABI_API_LNGSTRINGW(IDS_ERROR_SETTING_APPID),
(LPWSTR)plugin.description, MB_ICONWARNING);
}
else
{
AppID = app_id;
}
}
}
else
{
AppID = id;
MemFreeCOM(id);
}
if (AppID.empty())
{
AppID = L"WACUP";
}
}
return AppID.c_str();
}
#endif
// event functions follow
int init(void)
{
/************************************************************************/
/* Winamp services */
/************************************************************************/
//ServiceBuild(plugin.service, WASABI_API_MEMMGR, memMgrApiServiceGuid);
//ServiceBuild(plugin.service, WASABI_API_ALBUMART, albumArtGUID);
WASABI_API_ALBUMART = plugin.albumart;
//ServiceBuild(plugin.service, WASABI_API_PLAYLISTS, api_playlistsGUID);
WASABI_API_PLAYLISTS = plugin.playlists;
//ServiceBuild(plugin.service, WASABI_API_LNG, languageApiGUID);
WASABI_API_START_LANG_DESC(plugin.language, plugin.hDllInstance,
GenWin7PlusShellLangGUID, IDS_PLUGIN_NAME,
PLUGIN_VERSION, &plugin.description);
for (int i = 0; i < ARRAYSIZE(g_cs); i++)
{
InitializeCriticalSectionEx(&g_cs[i], 400, CRITICAL_SECTION_NO_DEBUG_INFO);
}
return GEN_INIT_SUCCESS;/*/
return GEN_INIT_FAILURE;/**/
}
void config(void)
{
HMENU popup = CreatePopupMenu();
AddItemToMenu(popup, 128, (LPWSTR)plugin.description);
EnableMenuItem(popup, 128, MF_BYCOMMAND | MF_GRAYED | MF_DISABLED);
AddItemToMenu(popup, (UINT)-1, 0);
AddItemToMenu(popup, 2, WASABI_API_LNGSTRINGW(IDS_OPEN_TASKBAR_PREFS));
AddItemToMenu(popup, (UINT)-1, 0);
AddItemToMenu(popup, 1, WASABI_API_LNGSTRINGW(IDS_ABOUT));
POINT pt = { 0 };
HWND list = GetPrefsListPos(&pt);
switch (TrackPopupMenu(popup, TPM_RETURNCMD, pt.x, pt.y, 0, list, NULL))
{
case 1:
{
wchar_t text[1024] = { 0 };
const unsigned char* output = DecompressResourceText(plugin.hDllInstance,
plugin.hDllInstance, IDR_ABOUT_GZ);
StringCchPrintf(text, ARRAYSIZE(text), (LPCWSTR)output, WACUP_Author(),
WACUP_Copyright(), TEXT(__DATE__));
DecompressResourceFree(output);
AboutMessageBox(list, text, (LPWSTR)plugin.description);
break;
}
case 2:
{
// leave the WACUP core to handle opening
// to the 'taskbar' preferences node
OpenPrefsPage((WPARAM)-667);
break;
}
}
DestroyMenu(popup);
}
void quit(void)
{
closing = true;
running = false;
KillTimer(plugin.hwndParent, 6667);
KillTimer(plugin.hwndParent, 6668);
KillTimer(plugin.hwndParent, 6670);
KillTimer(plugin.hwndParent, 6671);
KillTimer(plugin.hwndParent, 6672);
KillTimer(plugin.hwndParent, 6673);
if (CheckThreadHandleIsValid(&updatethread))
{
WaitForSingleObjectEx(updatethread, 10000, TRUE);
if (updatethread != NULL)
{
CloseHandle(updatethread);
updatethread = NULL;
}
}
if (CheckThreadHandleIsValid(&setupthread))
{
WaitForSingleObjectEx(setupthread, 10000, TRUE);
if (setupthread != NULL)
{
CloseHandle(setupthread);
setupthread = NULL;
}
}
#ifdef USE_MOUSE
if (hMouseHook != NULL)
{
UnhookWindowsHookEx(hMouseHook);
}
#endif
if (itaskbar != NULL)
{
delete itaskbar;
itaskbar = NULL;
}
if (thumbnaildrawer != NULL)
{
delete thumbnaildrawer;
thumbnaildrawer = NULL;
}
//ServiceRelease(plugin.service, WASABI_API_MEMMGR, memMgrApiServiceGuid);
//ServiceRelease(plugin.service, WASABI_API_ALBUMART, albumArtGUID);
//ServiceRelease(plugin.service, WASABI_API_PLAYLISTS, api_playlistsGUID);
//ServiceRelease(plugin.service, WASABI_API_LNG, languageApiGUID);
//ServiceRelease(plugin.service, WASABI_API_EXPLORERFINDFILE, ExplorerFindFileApiGUID);
for (int i = 0; i < ARRAYSIZE(g_cs); i++)
{
DeleteCriticalSection(&g_cs[i]);
}
}
void updateToolbar(HIMAGELIST ImageList)
{
if ((itaskbar != NULL) && Settings.Thumbnailbuttons && plugin.messages)
{
const size_t count = TButtons.size();
std::vector<THUMBBUTTON> thbButtons(count);
for (size_t i = 0; i < count; ++i)
{
THUMBBUTTON& button = thbButtons[i];
button.dwMask = THB_BITMAP | THB_TOOLTIP;
button.iId = (UINT)TButtons[i];
button.iBitmap = 0;
button.hIcon = NULL;
button.szTip[0] = 0;
button.dwFlags = THBF_ENABLED;
if (button.iId == TB_RATE || button.iId == TB_STOPAFTER ||
button.iId == TB_DELETE || button.iId == TB_JTFE ||
button.iId == TB_OPENEXPLORER)
{
button.dwMask = button.dwMask | THB_FLAGS;
button.dwFlags = THBF_DISMISSONCLICK;
}
else if (button.iId == TB_PLAYPAUSE)
{
button.iBitmap = tools::getBitmap(button.iId, !!(Settings.play_state == PLAYSTATE_PLAYING));
(void)StringCchCopy(button.szTip, ARRAYSIZE(button.szTip), tools::getToolTip(TB_PLAYPAUSE, Settings.play_state));
}
else if (button.iId == TB_REPEAT)
{
button.iBitmap = tools::getBitmap(button.iId, Settings.state_repeat);
(void)StringCchCopy(button.szTip, ARRAYSIZE(button.szTip), tools::getToolTip(TB_REPEAT, Settings.state_repeat));
}
else if (button.iId == TB_SHUFFLE)
{
button.iBitmap = tools::getBitmap(button.iId, Settings.play_state == Settings.state_shuffle);
(void)StringCchCopy(button.szTip, ARRAYSIZE(button.szTip), tools::getToolTip(TB_SHUFFLE, Settings.state_shuffle));
}
if (!button.iBitmap)
{
button.iBitmap = tools::getBitmap(button.iId, 0);
}
if (!button.szTip[0])
{
(void)StringCchCopy(button.szTip, ARRAYSIZE(button.szTip), tools::getToolTip(button.iId, 0));
}
}
if (itaskbar != NULL)
{
__try
{
itaskbar->ThumbBarUpdateButtons(thbButtons, ImageList);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
}
}
}
}
BOOL CALLBACK checkSkinProc(HWND hwnd, LPARAM lParam)
{
#ifndef _WIN64
if (IsWasabiWindow(hwnd))
{
// if any of these are a child window of
// the current skin being used then it's
// very likely it's a SUI modern skin...
// BaseWindow_RootWnd -> BaseWindow_RootWnd -> Winamp *
HWND child = GetWindow(hwnd, GW_CHILD);
if (IsWindow(child))
{
wchar_t cl[16] = { 0 };
if (GetClassName(child, cl, ARRAYSIZE(cl)) &&
(SameStrN(cl, L"Winamp EQ", 9) ||
SameStrN(cl, L"Winamp PE", 9) ||
SameStrN(cl, L"Winamp Gen", 10) ||
SameStrN(cl, L"Winamp Video", 12)))
{
modernSUI = true;
return FALSE;
}
}
}
#endif
(void)lParam;
return TRUE;
}
void updateRepeatButton(void)
{
// update repeat state
int current_repeat_state = repeat;
if (current_repeat_state == 1 && pladv == 1)
{
current_repeat_state = 2;
}
if (current_repeat_state != Settings.state_repeat)
{
Settings.state_repeat = current_repeat_state;
updateToolbar();
}
}
void UpdateLivePreview(void)
{
static bool processing = false;
if (!processing)
{
processing = true;
// incase this is updating then we'll try to
// ensure we're "live" updating to make this
// look more like the default OS handling...
if (running && classicSkin && (IsIconic(plugin.hwndParent) ||
(Settings.Thumbnailbackground != BG_WINAMP)))
{
const HBITMAP main_window_bmp = GetMainWindowBmp();
if (main_window_bmp != NULL)
{
// afaict this does not respect being
// given a bitmap where alpha is set!
// as the WACUP core will for classic
// skins try to set the faux alpha as
// needed which isn't an issue for it
// as it uses regions to do clipping
// but will cause those skin areas to
// appear as black when drawn here...
DwmSetIconicLivePreviewBitmap(plugin.hwndParent, main_window_bmp, NULL, 0);
DeleteObject(main_window_bmp);
}
}
processing = false;
}
}
DWORD WINAPI UpdateThread(LPVOID lp)
{
(void)CreateCOM();
while (running && CreateThumbnailDrawer())
{
const HBITMAP thumbnail = (running && (thumbnaildrawer != NULL) ?
thumbnaildrawer->GetThumbnail(false, false) : NULL);
if (thumbnail != NULL)
{
HRESULT hr = S_OK;
__try
{
hr = DwmSetIconicThumbnail(plugin.hwndParent, thumbnail, 0);
UpdateLivePreview();
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
}
DeleteObject(thumbnail);
if (!running || FAILED(hr))
{
running = false;
SetThumbnailTimer();
break;
}
}
SleepEx((running ? (Settings.Thumbnailbackground == BG_WINAMP) ?
(!Settings.LowFrameRate ? Settings.MFT : Settings.MST) :
(!Settings.LowFrameRate ? Settings.TFT : Settings.TST) : 1000), TRUE);
}
CloseCOM();
if (updatethread != NULL)
{
CloseHandle(updatethread);
updatethread = NULL;
}
return 0;
}
void SetThumbnailTimer(void)
{
KillTimer(plugin.hwndParent, 6670);
SetTimer(plugin.hwndParent, 6670, (running ? (Settings.Thumbnailbackground == BG_WINAMP) ?
(!Settings.LowFrameRate ? Settings.MFT : Settings.MST) :
(!Settings.LowFrameRate ? Settings.TFT : Settings.TST) : 1000), TimerProc);
KillTimer(plugin.hwndParent, 6671);
if (!CheckThreadHandleIsValid(&updatethread))
{
updatethread = StartThread(UpdateThread, 0, THREAD_PRIORITY_NORMAL, 0, NULL);
}
SetTimer(plugin.hwndParent, 6671, 30000, TimerProc);
}
void ResetThumbnail(void)
{
if (CreateThumbnailDrawer(false))
{
thumbnaildrawer->ClearAlbumart();
thumbnaildrawer->ClearBackground(false);
thumbnaildrawer->ClearCustomBackground();
thumbnaildrawer->ClearFonts();
thumbnaildrawer->ThumbnailPopup();
}
}
HIMAGELIST GetThumbnailIcons(const bool force_refresh)
{
EnterCriticalSection(&thumbnai_icons_cs);
if (!theicons || force_refresh)
{
if (theicons)
{
ImageListDestroy(theicons);
theicons = NULL;
}
theicons = tools::prepareIcons();
}
LeaveCriticalSection(&thumbnai_icons_cs);
return theicons;
}
HIMAGELIST GetOverlayIcons(const bool force_refresh)
{
EnterCriticalSection(&overlay_icons_cs);
if (!overlayicons || force_refresh)
{
if (overlayicons)
{
ImageListDestroy(overlayicons);
overlayicons = NULL;
}
overlayicons = tools::prepareOverlayIcons();
}
LeaveCriticalSection(&overlay_icons_cs);
return overlayicons;
}
void UpdateOverlyStatus(const bool force_refresh)
{
Settings.play_state = GetPlayingState();
// ensure we're either updating the full imagelist when needed or that
// we're going to be able to correctly show toggled play/paused states
updateToolbar((force_refresh ? GetThumbnailIcons(force_refresh) : NULL));
if (Settings.Overlay)
{
static wchar_t *playing_str = WASABI_API_LNGSTRINGW_DUP(IDS_PLAYING),
*paused_str = WASABI_API_LNGSTRINGW_DUP(IDS_PAUSED);
HICON icon = NULL;
switch (Settings.play_state)
{
case PLAYSTATE_PLAYING:
case PLAYSTATE_PAUSED:
{
if (itaskbar != NULL)
{
const bool paused = (Settings.play_state == PLAYSTATE_PAUSED);
const int index = tools::getBitmap(TB_PLAYPAUSE, paused);
if ((index >= 0) && (index < tools::getBitmapCount()))
{
icon = ImageListGetIcon(GetOverlayIcons(force_refresh), (index - 1), 0);
if (icon == NULL)
{
icon = ImageListGetIcon(GetThumbnailIcons(false), index, 0);
}
if (itaskbar != NULL)
{
itaskbar->SetIconOverlay(icon, (!paused ? playing_str : paused_str));
}
}
}
break;
}
default:
{
if (itaskbar != NULL)
{
const int index = tools::getBitmap(TB_STOP, 1);
if ((index >= 0) && (index < tools::getBitmapCount()))
{
icon = ImageListGetIcon(GetOverlayIcons(force_refresh), index, 0);
if (icon == NULL)
{
icon = ImageListGetIcon(GetThumbnailIcons(false/*force_refresh*/), index, 0);
}
if (itaskbar != NULL)
{
itaskbar->SetIconOverlay(icon, paused_str);
}
}
}
break;
}
}
if (icon != NULL)
{
DestroyIcon(icon);
}
}
}
MetaData* reset_metadata(LPCWSTR filename, const bool force = false)
{
MetaData* meta_data = get_metadata();
if (meta_data != NULL)
{
meta_data->reset(filename, force);
}
return meta_data;
}
void __cdecl MessageProc(HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM lParam)
{
if (uMsg == WM_DWMSENDICONICTHUMBNAIL)
{
if (CreateThumbnailDrawer())
{
// just update the dimensions and let the timer
// process the rendering later on as is needed.
thumbnaildrawer->SetDimensions(HIWORD(lParam), LOWORD(lParam));
running = true;
SetThumbnailTimer();
DwmInvalidateIconicBitmaps(plugin.hwndParent);
}
}
else if (uMsg == WM_DWMSENDICONICLIVEPREVIEWBITMAP)
{
UpdateLivePreview();
}
else if (uMsg == WM_WA_IPC)
{
switch (lParam)
{
case IPC_PLAYING_FILEW:
{
Settings.play_playlistpos = GetPlaylistPosition();
EnterCriticalSection(&metadata_cs);
std::wstring filename((wParam ? (wchar_t*)wParam : L""));
if (filename.empty())
{
LPCWSTR p = GetPlayingFilename(1, NULL);
if (p != NULL)
{
filename = p;
}
}
MetaData* meta_data = reset_metadata(filename.c_str());
LeaveCriticalSection(&metadata_cs);
Settings.play_total = GetCurrentTrackLengthMilliSeconds();
Settings.play_current = 0;
Settings.play_state = GetPlayingState();
if ((meta_data != NULL) && (Settings.JLrecent || Settings.JLfrequent) &&
(Settings.play_state == PLAYSTATE_PLAYING) && Settings.Add2RecentDocs)
{
// these are used to help minimise the impact of directly
// querying the file for multiple pieces of metadata &/or
// if there's an issue with the local library db handling
INT_PTR db_error = FALSE;
void *token = NULL;
bool reentrant = false, already_tried = false;
__try
{
const std::wstring title(meta_data->getMetadata(L"title", &token, &reentrant, &already_tried,
&db_error) + L" - " + meta_data->getMetadata(L"artist", &token,
&reentrant, &already_tried, &db_error) + ((Settings.play_total > 0) ?
L" (" + tools::SecToTime(Settings.play_total / 1000) + L")" : L""));
IShellLink *psl = NULL;
if ((tools::CreateShellLink(filename.c_str(), title.c_str(), &psl) == S_OK) && psl)
{
const SHARDAPPIDINFOLINK applink = { psl, GetAppID() };
wchar_t temp[32] = { 0 };
psl->SetDescription(TimeNow2Str(temp, ARRAYSIZE(temp)));
// based on testing, this & things in the
// CreateShellLink() sometimes fails :'(
// I can't find any reason for it. due to
// that it is necessary to try & catch it
// so we don't take down the entire thing
SHAddToRecentDocs(SHARD_APPIDINFOLINK, &applink);
}
// try to ensure we clean-up everything even if
// the CreateShellLink failed e.g. on SetPath()
if (psl)
{
psl->Release();
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
}
plugin.metadata->FreeExtendedFileInfoToken(&token);
}
DwmInvalidateIconicBitmaps(hWnd);
ResetThumbnail();
break;
}
/*case IPC_SETDIALOGBOXPARENT:
case IPC_UPDATEDIALOGBOXPARENT:*/
// instead of checking for the above
// we'll use this since WACUP 1.6.4+
// which consolidates & filters out
// duplicate messages to reduce work
case IPC_CB_ONDIALOGPARENTCHANGE:
{
// we cache this now as winamp will have
// cached it too by now so we're in-sync
dialogParent = (HWND)wParam;
if (!IsWindow(dialogParent))
{
dialogParent = hWnd;
}
// look at things that could need us to
// force a refresh of the iconic bitmap
SetThumbnailTimer();
break;
}
case IPC_CB_ONTOGGLEMANUALADVANCE:
{
pladv = (int)wParam;
updateRepeatButton();
break;
}
case IPC_CB_ONTOGGLEREPEAT:
{
repeat = (int)wParam;
updateRepeatButton();
break;
}
case IPC_CB_ONTOGGLESHUFFLE:
{
Settings.state_shuffle = (int)wParam;
updateToolbar();
break;
}
case IPC_PLAYLIST_MODIFIED:
{
Settings.play_playlistlen = (int)wParam;
break;
}
case IPC_ADDBOOKMARK:
case IPC_ADDBOOKMARKW:
{
if (wParam)
{
SetTimer(plugin.hwndParent, 6673, 1000, TimerProc);
}
break;
}
case IPC_WACUP_IS_CLOSING:
{
// give things a nudge
closing = true;
running = false;
break;
}
case IPC_IS_MINIMISED_OR_RESTORED:
case IPC_SKIN_CHANGED_NEW:
{
if (plugin.messages)
{
const bool minimised = (lParam == IPC_IS_MINIMISED_OR_RESTORED);
if (!minimised)
{
// this is needed when the vu mode is enabled to allow the
// data to be obtained if the main wnidow mode is disabled
static void (__cdecl *export_sa_setreq)(int) = (void (__cdecl *)(int))GetSADataFunc(1);
if (export_sa_setreq)
{
export_sa_setreq(Settings.VuMeter);
}
#ifndef _WIN64
LPCWSTR skin_name = NULL;
classicSkin = !IsModernSkinActive(&skin_name);
modernSUI = false;
modernFix = (skin_name && *skin_name && SameStrN(skin_name, L"Winamp Modern", 13));
if (!classicSkin)
{
// see if it's likely to be a SUI or not as
// we need it to help determine how we will
// capture the main window for the preview
// as WM_PRINTCLIENT is slow for SUI skins
// but is needed for others especially if
// we're wanting to do support alpha better
EnumChildWindows(dialogParent, checkSkinProc, 0);
}
#endif
}
if (itaskbar != NULL)
{
itaskbar->SetWindowAttr();
UpdateOverlyStatus(true);
}
}
// fall-through for the other handling needed
}
default:
{
// make sure if not playing but prev / next is done
// that we update the thumbnail for the current one
if ((lParam == IPC_FILE_TAG_MAY_HAVE_UPDATEDW) ||
#ifndef _WIN64
(lParam == IPC_FILE_TAG_MAY_HAVE_UPDATED) ||
#endif
(lParam == IPC_CB_MISC) &&
((wParam == IPC_CB_MISC_TITLE) ||
(wParam == IPC_CB_MISC_AA_OPT_CHANGED) ||
(wParam == IPC_CB_MISC_TITLE_RATING) ||
(wParam == IPC_CB_MISC_ON_STOP) ||
(wParam == IPC_CB_MISC_ADVANCED_NEXT_ON_STOP)))
{
EnterCriticalSection(&metadata_cs);
LPCWSTR p = GetPlayingFilename(0, NULL);
if (p != NULL)
{
reset_metadata(p);
}
LeaveCriticalSection(&metadata_cs);
DwmInvalidateIconicBitmaps(hWnd);
ResetThumbnail();
}
else if ((lParam == IPC_CB_MISC) && (wParam == IPC_CB_MISC_STATUS))
{
UpdateOverlyStatus(false);
}
else if ((lParam == IPC_CB_MISC) && (wParam == IPC_CB_MISC_VOLUME))
{
Settings.play_volume = (int)GetSetVolume((WPARAM)-666, FALSE);
}
else if (lParam == IPC_WACUP_HAS_LOADED)
{
SetTimer(plugin.hwndParent, 6672, 100, TimerProc);
}
else if (lParam == IPC_WACUP_IS_CLOSING)
{
// to help avoid anything else being
// done when wacup is starting close
// then we'll stop responding to any
// messages to avoid some crashes...
plugin.messages = NULL;
}
break;
}
}
}
else if ((uMsg == WM_SYSCOMMAND) && (wParam == SC_CLOSE))
{
PostMessage(plugin.hwndParent, WM_COMMAND, 40001, 0);
}
else if (uMsg == WM_COMMAND)
{
if (HIWORD(wParam) == THBN_CLICKED)
{
switch (LOWORD(wParam))
{
case TB_PREVIOUS:
case TB_NEXT:
{
SendMessage(plugin.hwndParent, WM_COMMAND, MAKEWPARAM(((LOWORD(wParam) == TB_PREVIOUS) ? 40044 : 40048), 0), 0);
Settings.play_playlistpos = GetPlaylistPosition();
if (Settings.Thumbnailbackground == BG_ALBUMART)
{
ResetThumbnail();
if (Settings.play_state != PLAYSTATE_PLAYING)
{
DwmInvalidateIconicBitmaps(plugin.hwndParent);
}
}
EnterCriticalSection(&metadata_cs);
LPCWSTR p = GetPlayingFilename(0, NULL);
if (p != NULL)
{
reset_metadata(p);
}
LeaveCriticalSection(&metadata_cs);
if (CreateThumbnailDrawer())
{
thumbnaildrawer->ThumbnailPopup();
}
break;
}
case TB_PLAYPAUSE:
{
const int res = GetPlayingState();
PostMessage(plugin.hwndParent, WM_COMMAND,
MAKEWPARAM(((res == 1) ?
40046 : 40045), 0), 0);
Settings.play_state = res;
break;
}
case TB_STOP:
{
PostMessage(plugin.hwndParent, WM_COMMAND,
MAKEWPARAM(40047, 0), 0);