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
|
/*
Copyright (C) 2005-2009 Ricardo Pescuma Domenecci
This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this file; see the file license.txt. If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "../stdafx.h"
#define WMP_WINDOWCLASS L"MsnMsgrUIManager"
static LRESULT CALLBACK ReceiverWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
static UINT hTimer = NULL;
WindowsMediaPlayer *singleton = nullptr;
WindowsMediaPlayer::WindowsMediaPlayer()
{
name = L"WindowsMediaPlayer";
received[0] = '\0';
singleton = this;
WNDCLASS wc = {};
wc.lpfnWndProc = ReceiverWndProc;
wc.hInstance = g_plugin.getInst();
wc.lpszClassName = WMP_WINDOWCLASS;
RegisterClass(&wc);
hWnd = CreateWindow(WMP_WINDOWCLASS, LPGENW("Miranda ListeningTo WMP receiver"), 0, 0, 0, 0, 0, nullptr, nullptr, g_plugin.getInst(), nullptr);
}
WindowsMediaPlayer::~WindowsMediaPlayer()
{
if (hTimer != NULL) {
KillTimer(nullptr, hTimer);
hTimer = NULL;
}
DestroyWindow(hWnd);
hWnd = nullptr;
UnregisterClass(WMP_WINDOWCLASS, g_plugin.getInst());
singleton = nullptr;
}
void WindowsMediaPlayer::ProcessReceived()
{
{
mir_cslock lck(cs);
FreeData();
// Do the processing
// MSNMusicString = L"\\0Music\\0%d\\0%s\\0%s\\0%s\\0%s\\0%s\\0\\0"
// MSNMusicString, msn->msncommand, strMSNFormat, msn->title, msn->artist, msn->album, msn->wmcontentid);
wchar_t *p1 = wcsstr(received, L"\\0");
if (received[0] == L'\0' || p1 == nullptr) {
NotifyInfoChanged();
return;
}
// Process string
wchar_t *parts[8] = {};
int pCount = 0;
wchar_t *p = received;
do {
*p1 = L'\0';
parts[pCount] = p;
pCount++;
p = p1 + 2;
p1 = wcsstr(p, L"\\0");
} while (p1 != nullptr && pCount < 7);
if (p1 != nullptr)
*p1 = L'\0';
parts[pCount] = p;
// Fill cache
if (pCount > 4 && !IsEmpty(parts[1]) && (!IsEmpty(parts[4]) || !IsEmpty(parts[5]))) {
listening_info.cbSize = sizeof(listening_info);
listening_info.dwFlags = LTI_TCHAR;
listening_info.ptszType = U2T(parts[1]);
listening_info.ptszTitle = U2T(parts[4]);
listening_info.ptszArtist = U2T(parts[5]);
listening_info.ptszAlbum = U2T(parts[6]);
listening_info.ptszPlayer = mir_wstrdup(name);
}
// Put back the '\\'s
for (int i = 1; i <= pCount; i++)
*(parts[i] - 2) = L'\\';
if (p1 != nullptr)
*p1 = L'\\';
}
NotifyInfoChanged();
}
static VOID CALLBACK SendTimerProc(HWND, UINT, UINT_PTR, DWORD)
{
KillTimer(nullptr, hTimer);
hTimer = NULL;
if (!loaded)
return;
if (singleton != nullptr)
singleton->ProcessReceived();
}
void WindowsMediaPlayer::NewData(const wchar_t *data, size_t len)
{
mir_cslock lck(cs);
len = min(len, 1023);
if (wcsncmp(received, data, len) != 0) {
wcsncpy(received, data, len);
received[len] = '\0';
if (hTimer)
KillTimer(nullptr, hTimer);
hTimer = SetTimer(nullptr, NULL, 300, SendTimerProc); // Do the processing after we return true
}
}
static LRESULT CALLBACK ReceiverWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_COPYDATA) {
if (!loaded)
return FALSE;
if (singleton == nullptr || !singleton->enabled)
return FALSE;
COPYDATASTRUCT* pData = (PCOPYDATASTRUCT)lParam;
if (pData->dwData != 0x547 || pData->cbData == 0 || pData->lpData == nullptr)
return FALSE;
if (singleton != nullptr)
singleton->NewData((wchar_t *)pData->lpData, pData->cbData / 2);
return TRUE;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
|