-
Notifications
You must be signed in to change notification settings - Fork 37
/
MessageHook.cpp
208 lines (194 loc) · 9.06 KB
/
MessageHook.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
#include "MessageHook.h"
#include "Tools.h"
#include "SDK/apiPlaylists.h"
#include "SDK/apiPlayer.h"
#include "AIMPYouTube.h"
#include "YouTubeAPI.h"
MessageHook::MessageHook(Plugin *pl) : m_plugin(pl) {
}
MessageHook::~MessageHook() {
}
void WINAPI MessageHook::CoreMessage(DWORD AMessage, int AParam1, void *AParam2, HRESULT *AResult) {
if (AMessage == AIMP_MSG_CMD_PLS_DELETE_PLAYING_FROM_HDD) {
IAIMPString *url = nullptr;
IAIMPPlaylistItem *currentTrack = m_plugin->GetCurrentTrack();
if (SUCCEEDED(currentTrack->GetValueAsObject(AIMP_PLAYLISTITEM_PROPID_FILENAME, IID_IAIMPString, reinterpret_cast<void **>(&url)))) {
std::wstring id = Tools::TrackIdFromUrl(url->GetData());
url->Release();
if (!id.empty()) {
for (auto &x : Config::UserPlaylists) {
for (auto &xx : x.Items) {
if (xx == id) {
x.Items.erase(id);
if (IAIMPPlaylist *playlist = Plugin::instance()->GetPlaylistById(x.AIMPPlaylistId)) {
Plugin::instance()->ForEveryItem(playlist, [&id](IAIMPPlaylistItem *, IAIMPFileInfo *, const std::wstring &itemid) {
if (!itemid.empty() && itemid == id) {
return Plugin::FLAG_DELETE_ITEM | Plugin::FLAG_STOP_LOOP;
}
return 0;
});
playlist->Release();
}
break;
}
}
}
Config::TrackExclusions.insert(id);
Config::SaveExtendedConfig();
IAIMPPlaylist *parent = nullptr;
if (SUCCEEDED(currentTrack->GetValueAsObject(AIMP_PLAYLISTITEM_PROPID_PLAYLIST, IID_IAIMPPlaylist, reinterpret_cast<void **>(&parent)))) {
parent->Delete(currentTrack);
parent->Release();
}
currentTrack->Release();
IAIMPServicePlayer *player = nullptr;
if (SUCCEEDED(m_plugin->m_core->QueryInterface(IID_IAIMPServicePlayer, reinterpret_cast<void **>(&player)))) {
player->GoToNext();
player->Release();
}
*AResult = S_OK;
return;
}
}
}
if (AMessage == AIMP_MSG_CMD_PLS_DELETE_SELECTED) {
std::unordered_set<std::wstring> deleted;
m_plugin->ForSelectedTracks([&deleted](IAIMPPlaylist *, IAIMPPlaylistItem *, const std::wstring &id) -> int {
deleted.insert(id);
return 0;
});
Config::MonitorUrls.erase(
std::remove_if(Config::MonitorUrls.begin(), Config::MonitorUrls.end(), [&](const Config::MonitorUrl &element) -> bool {
return deleted.find(Tools::TrackIdFromUrl(element.URL)) != deleted.end();
}), Config::MonitorUrls.end());
Config::SaveExtendedConfig();
}
if (AMessage == AIMP_MSG_CMD_BOOKMARKS_ADD) {
IAIMPString *url = nullptr;
IAIMPPlaylistItem *currentTrack = m_plugin->GetCurrentTrack();
if (currentTrack && SUCCEEDED(currentTrack->GetValueAsObject(AIMP_PLAYLISTITEM_PROPID_FILENAME, IID_IAIMPString, reinterpret_cast<void **>(&url)))) {
std::wstring id = Tools::TrackIdFromUrl(url->GetData());
url->Release();
currentTrack->Release();
if (!id.empty()) {
for (auto &x : Config::UserPlaylists) {
if (x.ReferenceName == std::wstring(L"Favorites")) {
YouTubeAPI::AddToPlaylist(x, id);
break;
}
}
return;
}
}
}
#if 0
# define STRINGIFY(name) case name: DebugA(#name " %d %d\n", AParam1, AParam2); break;
switch (AMessage) {
STRINGIFY(AIMP_MSG_CMD_BASE)
STRINGIFY(AIMP_MSG_CMD_STATE_GET)
STRINGIFY(AIMP_MSG_CMD_QFI_PLAYBACK_TRACK)
STRINGIFY(AIMP_MSG_CMD_SHOW_NOTIFICATION)
STRINGIFY(AIMP_MSG_CMD_TOGGLE_PARTREPEAT)
STRINGIFY(AIMP_MSG_CMD_ABOUT)
STRINGIFY(AIMP_MSG_CMD_OPTIONS)
STRINGIFY(AIMP_MSG_CMD_PLUGINS)
STRINGIFY(AIMP_MSG_CMD_QUIT)
STRINGIFY(AIMP_MSG_CMD_SCHEDULER)
STRINGIFY(AIMP_MSG_CMD_VISUAL_NEXT)
STRINGIFY(AIMP_MSG_CMD_VISUAL_PREV)
STRINGIFY(AIMP_MSG_CMD_PLAY)
STRINGIFY(AIMP_MSG_CMD_PLAYPAUSE)
STRINGIFY(AIMP_MSG_CMD_PLAY_PREV_PLAYLIST)
STRINGIFY(AIMP_MSG_CMD_PAUSE)
STRINGIFY(AIMP_MSG_CMD_STOP)
STRINGIFY(AIMP_MSG_CMD_NEXT)
STRINGIFY(AIMP_MSG_CMD_PREV)
STRINGIFY(AIMP_MSG_CMD_OPEN_FILES)
STRINGIFY(AIMP_MSG_CMD_OPEN_FOLDERS)
STRINGIFY(AIMP_MSG_CMD_OPEN_PLAYLISTS)
STRINGIFY(AIMP_MSG_CMD_SAVE_PLAYLISTS)
STRINGIFY(AIMP_MSG_CMD_BOOKMARKS)
STRINGIFY(AIMP_MSG_CMD_BOOKMARKS_ADD)
STRINGIFY(AIMP_MSG_CMD_PLS_RESCAN)
STRINGIFY(AIMP_MSG_CMD_PLS_FOCUS_PLAYABLE)
STRINGIFY(AIMP_MSG_CMD_PLS_DELETE_ALL)
STRINGIFY(AIMP_MSG_CMD_PLS_DELETE_NON_EXISTS)
STRINGIFY(AIMP_MSG_CMD_PLS_DELETE_NON_SELECTED)
STRINGIFY(AIMP_MSG_CMD_PLS_DELETE_PLAYING_FROM_HDD)
STRINGIFY(AIMP_MSG_CMD_PLS_DELETE_SELECTED)
STRINGIFY(AIMP_MSG_CMD_PLS_DELETE_SELECTED_FROM_HDD)
STRINGIFY(AIMP_MSG_CMD_PLS_DELETE_SWITCHEDOFF)
STRINGIFY(AIMP_MSG_CMD_PLS_DELETE_SWITCHEDOFF_FROM_HDD)
STRINGIFY(AIMP_MSG_CMD_PLS_DELETE_DUPLICATES)
STRINGIFY(AIMP_MSG_CMD_PLS_SORT_BY_ARTIST)
STRINGIFY(AIMP_MSG_CMD_PLS_SORT_BY_TITLE)
STRINGIFY(AIMP_MSG_CMD_PLS_SORT_BY_PATH)
STRINGIFY(AIMP_MSG_CMD_PLS_SORT_BY_DURATION)
STRINGIFY(AIMP_MSG_CMD_PLS_SORT_RANDOMIZE)
STRINGIFY(AIMP_MSG_CMD_PLS_SORT_INVERT)
STRINGIFY(AIMP_MSG_CMD_PLS_SWITCH_ON)
STRINGIFY(AIMP_MSG_CMD_PLS_SWITCH_OFF)
STRINGIFY(AIMP_MSG_CMD_ADD_FILES)
STRINGIFY(AIMP_MSG_CMD_ADD_FOLDERS)
STRINGIFY(AIMP_MSG_CMD_ADD_PLAYLISTS)
STRINGIFY(AIMP_MSG_CMD_ADD_URL)
STRINGIFY(AIMP_MSG_CMD_QTE_PLAYABLE_TRACK)
STRINGIFY(AIMP_MSG_CMD_SEARCH)
STRINGIFY(AIMP_MSG_CMD_DSPMANAGER)
STRINGIFY(AIMP_MSG_CMD_PLS_RELOAD_FROM_PREIMAGE)
STRINGIFY(AIMP_MSG_CMD_VISUAL_START)
STRINGIFY(AIMP_MSG_CMD_VISUAL_STOP)
STRINGIFY(AIMP_MSG_PROPERTY_BASE)
STRINGIFY(AIMP_MSG_PROPERTY_VOLUME)
STRINGIFY(AIMP_MSG_PROPERTY_MUTE)
STRINGIFY(AIMP_MSG_PROPERTY_BALANCE)
STRINGIFY(AIMP_MSG_PROPERTY_CHORUS)
STRINGIFY(AIMP_MSG_PROPERTY_ECHO)
STRINGIFY(AIMP_MSG_PROPERTY_ENHANCER)
STRINGIFY(AIMP_MSG_PROPERTY_FLANGER)
STRINGIFY(AIMP_MSG_PROPERTY_REVERB)
STRINGIFY(AIMP_MSG_PROPERTY_PITCH)
STRINGIFY(AIMP_MSG_PROPERTY_SPEED)
STRINGIFY(AIMP_MSG_PROPERTY_TEMPO)
STRINGIFY(AIMP_MSG_PROPERTY_TRUEBASS)
STRINGIFY(AIMP_MSG_PROPERTY_PREAMP)
STRINGIFY(AIMP_MSG_PROPERTY_EQUALIZER)
STRINGIFY(AIMP_MSG_PROPERTY_EQUALIZER_BAND)
STRINGIFY(AIMP_MSG_PROPERTY_PLAYER_STATE)
//STRINGIFY(AIMP_MSG_PROPERTY_PLAYER_POSITION)
//STRINGIFY(AIMP_MSG_PROPERTY_PLAYER_DURATION)
STRINGIFY(AIMP_MSG_PROPERTY_PARTREPEAT)
STRINGIFY(AIMP_MSG_PROPERTY_REPEAT)
STRINGIFY(AIMP_MSG_PROPERTY_SHUFFLE)
STRINGIFY(AIMP_MSG_PROPERTY_HWND)
STRINGIFY(AIMP_MSG_PROPERTY_STAYONTOP)
STRINGIFY(AIMP_MSG_PROPERTY_REVERSETIME)
STRINGIFY(AIMP_MSG_PROPERTY_MINIMIZED_TO_TRAY)
STRINGIFY(AIMP_MSG_PROPERTY_REPEAT_SINGLE_FILE_PLAYLISTS)
STRINGIFY(AIMP_MSG_PROPERTY_ACTION_ON_END_OF_PLAYLIST)
STRINGIFY(AIMP_MSG_PROPERTY_STOP_AFTER_TRACK)
STRINGIFY(AIMP_MSG_PROPERTY_RADIOCAP)
STRINGIFY(AIMP_MSG_PROPERTY_LOADED)
STRINGIFY(AIMP_MSG_PROPERTY_VISUAL_FULLSCREEN)
STRINGIFY(AIMP_MSG_EVENT_BASE)
STRINGIFY(AIMP_MSG_EVENT_CMD_STATE)
STRINGIFY(AIMP_MSG_EVENT_OPTIONS)
STRINGIFY(AIMP_MSG_EVENT_STREAM_START)
STRINGIFY(AIMP_MSG_EVENT_STREAM_START_SUBTRACK)
STRINGIFY(AIMP_MSG_EVENT_STREAM_END)
STRINGIFY(AIMP_MSG_EVENT_PLAYER_STATE)
STRINGIFY(AIMP_MSG_EVENT_PROPERTY_VALUE)
STRINGIFY(AIMP_MSG_EVENT_OPTIONS_FRAME_LIST)
STRINGIFY(AIMP_MSG_EVENT_OPTIONS_FRAME_MODIFIED)
STRINGIFY(AIMP_MSG_EVENT_VISUAL_PLUGIN)
STRINGIFY(AIMP_MSG_EVENT_FILEMARK)
STRINGIFY(AIMP_MSG_EVENT_STATISTICS_CHANGED)
STRINGIFY(AIMP_MSG_EVENT_SKIN)
//STRINGIFY(AIMP_MSG_EVENT_PLAYER_UPDATE_POSITION)
STRINGIFY(AIMP_MSG_EVENT_LANGUAGE)
STRINGIFY(AIMP_MSG_EVENT_TERMINATING)
STRINGIFY(AIMP_MSG_EVENT_PLAYABLE_FILE_INFO)
//default: DebugA("%d %d %d\n", AMessage, AParam1, AParam2); break;
}
#endif
}