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
|
#include "JSAPI2_PlayerAPI.h"
#include "JSAPI2_Security.h"
#include "main.h"
#include "JSAPI.h"
#include "ipc_pe.h"
#include <strsafe.h>
JSAPI2::PlayerAPI::PlayerAPI(const wchar_t *_key, JSAPI::ifc_info *_info)
{
info = _info;
key = _key;
refCount = 1;
}
enum
{
DISPID_PLAYERAPI_PLAY, // start playing a file immediately (and clear the old playlist)
DISPID_PLAYERAPI_ENQUEUE, // insert a URL at the end of the playlist
DISPID_PLAYERAPI_INSERT, // insert a URL at a particular position in the playlist
DISPID_PLAYERAPI_CLEARQUEUE, // clear the playlist
DISPID_PLAYERAPI_GETURL, // get the URL (or filename) for an item in the playlist
DISPID_PLAYERAPI_GETTITLE, // get title for an item in the playlist
DISPID_PLAYERAPI_GETMETADATA, // get a metadata string for an item in the playlist
// properties
DISPID_PLAYERAPI_LENGTH, // length of the playlist
DISPID_PLAYERAPI_POSITION, // position in the playlist
};
#define DISP_TABLE \
CHECK_ID(Play, DISPID_PLAYERAPI_PLAY)\
CHECK_ID(Enqueue, DISPID_PLAYERAPI_ENQUEUE)\
CHECK_ID(Insert, DISPID_PLAYERAPI_INSERT)\
CHECK_ID(ClearQueue, DISPID_PLAYERAPI_CLEARQUEUE)\
CHECK_ID(GetURL, DISPID_PLAYERAPI_GETURL)\
CHECK_ID(GetTitle, DISPID_PLAYERAPI_GETTITLE)\
CHECK_ID(GetMetadata, DISPID_PLAYERAPI_GETMETADATA)\
CHECK_ID(length, DISPID_PLAYERAPI_LENGTH)\
CHECK_ID(cursor, DISPID_PLAYERAPI_POSITION)\
#define CHECK_ID(str, id)\
if (CSTR_EQUAL == CompareStringW(lcid, NORM_IGNORECASE, rgszNames[i], -1, L## #str, -1))\
{ rgdispid[i] = id; continue; }
HRESULT JSAPI2::PlayerAPI::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid)
{
bool unknowns = false;
for (unsigned int i = 0;i != cNames;i++)
{
DISP_TABLE
rgdispid[i] = DISPID_UNKNOWN;
unknowns = true;
}
if (unknowns)
return DISP_E_UNKNOWNNAME;
else
return S_OK;
}
HRESULT JSAPI2::PlayerAPI::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo)
{
return E_NOTIMPL;
}
HRESULT JSAPI2::PlayerAPI::GetTypeInfoCount(unsigned int FAR * pctinfo)
{
return E_NOTIMPL;
}
HRESULT JSAPI2::PlayerAPI::Play(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
{
JSAPI_VERIFY_METHOD(wFlags);
JSAPI_VERIFY_PARAMCOUNT_OPTIONAL(pdispparams, 1, 3);
JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_BSTR, puArgErr);
JSAPI_VERIFY_PARAMTYPE_OPTIONAL(pdispparams, 2, VT_BSTR, puArgErr);
JSAPI_VERIFY_PARAMTYPE_OPTIONAL(pdispparams, 3, VT_I4, puArgErr);
JSAPI_INIT_RESULT(pvarResult, VT_BOOL);
if (security.GetActionAuthorization(L"player", L"playlist", key, info, JSAPI2::api_security::ACTION_PROMPT) == JSAPI2::api_security::ACTION_ALLOWED)
{
JSAPI_SET_RESULT(pvarResult, boolVal, VARIANT_TRUE);
enqueueFileWithMetaStructW s = {0,0,0,0};
SendMessageW(hMainWindow, WM_WA_IPC, 0, IPC_DELETE);
//PlayList_delete();
s.filename = JSAPI_PARAM(pdispparams, 1).bstrVal;
s.title = JSAPI_PARAM_OPTIONAL(pdispparams, 2, bstrVal, 0);
s.ext = NULL;
s.length = JSAPI_PARAM_OPTIONAL(pdispparams, 3, lVal, 0);
/*if (title)
PlayList_append_withinfo(filename, title, length);
else
PlayList_appendthing(filename, 0);
plEditRefresh();
*/
SendMessageW(hMainWindow, WM_WA_IPC, (WPARAM)&s, IPC_PLAYFILEW);
SendMessageW(hMainWindow, WM_WA_IPC, 0, IPC_STARTPLAY);
}
else
{
JSAPI_SET_RESULT(pvarResult, boolVal, VARIANT_FALSE);
}
return S_OK;
}
HRESULT JSAPI2::PlayerAPI::Enqueue(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
{
JSAPI_VERIFY_METHOD(wFlags);
JSAPI_VERIFY_PARAMCOUNT_OPTIONAL(pdispparams, 1, 3);
JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_BSTR, puArgErr);
JSAPI_VERIFY_PARAMTYPE_OPTIONAL(pdispparams, 2, VT_BSTR, puArgErr);
JSAPI_VERIFY_PARAMTYPE_OPTIONAL(pdispparams, 3, VT_I4, puArgErr);
JSAPI_INIT_RESULT(pvarResult, VT_BOOL);
if (security.GetActionAuthorization(L"player", L"playlist", key, info, JSAPI2::api_security::ACTION_PROMPT) == JSAPI2::api_security::ACTION_ALLOWED)
{
JSAPI_SET_RESULT(pvarResult, boolVal, VARIANT_TRUE);
enqueueFileWithMetaStructW s = {0,0,0,0};
//PlayList_delete();
s.filename = JSAPI_PARAM(pdispparams, 1).bstrVal;
s.title = JSAPI_PARAM_OPTIONAL(pdispparams, 2, bstrVal, 0);
s.ext = NULL;
s.length = JSAPI_PARAM_OPTIONAL(pdispparams, 3, lVal, 0);
/*if (title)
PlayList_append_withinfo(filename, title, length);
else
PlayList_appendthing(filename, 0);
plEditRefresh();
*/
SendMessageW(hMainWindow, WM_WA_IPC, (WPARAM)&s, IPC_PLAYFILEW);
}
else
{
JSAPI_SET_RESULT(pvarResult, boolVal, VARIANT_FALSE);
}
return S_OK;
}
HRESULT JSAPI2::PlayerAPI::Insert(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
{
JSAPI_VERIFY_METHOD(wFlags);
JSAPI_VERIFY_PARAMCOUNT_OPTIONAL(pdispparams, 2, 4);
JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_I4, puArgErr);
JSAPI_VERIFY_PARAMTYPE(pdispparams, 2, VT_BSTR, puArgErr);
JSAPI_VERIFY_PARAMTYPE_OPTIONAL(pdispparams, 3, VT_BSTR, puArgErr);
JSAPI_VERIFY_PARAMTYPE_OPTIONAL(pdispparams, 4, VT_I4, puArgErr);
JSAPI_INIT_RESULT(pvarResult, VT_BOOL);
if (security.GetActionAuthorization(L"player", L"playlist", key, info, JSAPI2::api_security::ACTION_PROMPT) == JSAPI2::api_security::ACTION_ALLOWED)
{
JSAPI_SET_RESULT(pvarResult, boolVal, VARIANT_TRUE);
fileinfoW info;
COPYDATASTRUCT cds;
cds.dwData = IPC_PE_INSERTFILENAMEW;
cds.lpData = &info;
cds.cbData = sizeof(info);
StringCbCopyW(info.file, sizeof(info.file), JSAPI_PARAM(pdispparams, 2).bstrVal);
info.index = JSAPI_PARAM(pdispparams, 1).lVal;
// benski> TODO const wchar_t *title = JSAPI_PARAM_OPTIONAL(pdispparams, 3, bstrVal, 0);
// benski> TODO int length = JSAPI_PARAM_OPTIONAL(pdispparams, 4, lVal, 0);
SendMessageW(hPLWindow, WM_COPYDATA, 0, (LPARAM)&cds);
}
else
{
JSAPI_SET_RESULT(pvarResult, boolVal, VARIANT_FALSE);
}
return S_OK;
}
HRESULT JSAPI2::PlayerAPI::ClearQueue(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
{
JSAPI_VERIFY_METHOD(wFlags);
JSAPI_VERIFY_PARAMCOUNT(pdispparams, 0);
JSAPI_INIT_RESULT(pvarResult, VT_BOOL);
if (security.GetActionAuthorization(L"player", L"playlist", key, info, JSAPI2::api_security::ACTION_PROMPT) == JSAPI2::api_security::ACTION_ALLOWED)
{
JSAPI_SET_RESULT(pvarResult, boolVal, VARIANT_TRUE);
SendMessageW(hMainWindow, WM_WA_IPC, 0, IPC_DELETE);
}
else
{
JSAPI_SET_RESULT(pvarResult, boolVal, VARIANT_FALSE);
}
return S_OK;
}
HRESULT JSAPI2::PlayerAPI::GetURL(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
{
JSAPI_VERIFY_METHOD(wFlags);
JSAPI_VERIFY_PARAMCOUNT(pdispparams, 1);
JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_I4, puArgErr);
JSAPI_INIT_RESULT(pvarResult, VT_BSTR);
if (security.GetActionAuthorization(L"player", L"metadata", key, info, JSAPI2::api_security::ACTION_PROMPT) == JSAPI2::api_security::ACTION_ALLOWED)
{
int position = JSAPI_PARAM(pdispparams, 1).lVal;
wchar_t filename[FILENAME_SIZE] = {0};
if (PlayList_getitem2W(position, filename, 0) == 0)
{
JSAPI_SET_RESULT(pvarResult, bstrVal, SysAllocString(filename));
}
else
{
JSAPI_EMPTY_RESULT(pvarResult);
}
}
else
{
JSAPI_EMPTY_RESULT(pvarResult);
}
return S_OK;
}
HRESULT JSAPI2::PlayerAPI::GetTitle(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
{
JSAPI_VERIFY_METHOD(wFlags);
JSAPI_VERIFY_PARAMCOUNT(pdispparams, 1);
JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_I4, puArgErr);
JSAPI_INIT_RESULT(pvarResult, VT_BSTR);
if (security.GetActionAuthorization(L"player", L"metadata", key, info, JSAPI2::api_security::ACTION_PROMPT) == JSAPI2::api_security::ACTION_ALLOWED)
{
int position = JSAPI_PARAM(pdispparams, 1).lVal;
wchar_t filetitle[FILETITLE_SIZE] = {0};
if (PlayList_getitem2W(position, 0, filetitle) == 0)
{
JSAPI_SET_RESULT(pvarResult, bstrVal, SysAllocString(filetitle));
}
else
{
JSAPI_EMPTY_RESULT(pvarResult);
}
}
else
{
JSAPI_EMPTY_RESULT(pvarResult);
}
return S_OK;
}
HRESULT JSAPI2::PlayerAPI::GetMetadata(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
{
JSAPI_VERIFY_METHOD(wFlags);
JSAPI_VERIFY_PARAMCOUNT(pdispparams, 2);
JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_I4, puArgErr);
JSAPI_VERIFY_PARAMTYPE(pdispparams, 2, VT_BSTR, puArgErr);
JSAPI_INIT_RESULT(pvarResult, VT_BSTR);
if (security.GetActionAuthorization(L"player", L"metadata", key, info, JSAPI2::api_security::ACTION_PROMPT) == JSAPI2::api_security::ACTION_ALLOWED)
{
int position = JSAPI_PARAM(pdispparams, 1).lVal;
wchar_t filename[FILENAME_SIZE] = {0};
if (PlayList_getitem2W(position, filename, 0) == 0)
{
wchar_t buffer[4096] = {0};
extendedFileInfoStructW info;
info.filename = filename;
info.metadata = JSAPI_PARAM(pdispparams, 2).bstrVal;
info.ret = buffer;
info.retlen = sizeof(buffer)/sizeof(*buffer);
if (NULL != info.filename &&
NULL != info.metadata)
{
if (0 == SendMessageW(hMainWindow, WM_WA_IPC, (WPARAM)&info, IPC_GET_EXTENDED_FILE_INFOW_HOOKABLE))
info.ret = NULL;
JSAPI_SET_RESULT(pvarResult, bstrVal, SysAllocString(info.ret));
}
else
JSAPI_EMPTY_RESULT(pvarResult);
}
else
{
JSAPI_EMPTY_RESULT(pvarResult);
}
}
else
{
JSAPI_EMPTY_RESULT(pvarResult);
}
return S_OK;
}
HRESULT JSAPI2::PlayerAPI::length(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
{
if (wFlags & DISPATCH_PROPERTYGET)
{
JSAPI_VERIFY_PARAMCOUNT(pdispparams, 0);
VariantInit(pvarResult);
V_VT(pvarResult) = VT_I4;
V_I4(pvarResult) = PlayList_getlength();
return S_OK;
}
return DISP_E_MEMBERNOTFOUND;
}
HRESULT JSAPI2::PlayerAPI::cursor(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
{
if (wFlags & DISPATCH_PROPERTYPUT)
{
JSAPI_VERIFY_PARAMCOUNT(pdispparams, 1);
JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_I4, puArgErr);
if (security.GetActionAuthorization(L"player", L"playlist", key, info, JSAPI2::api_security::ACTION_PROMPT) == JSAPI2::api_security::ACTION_ALLOWED)
{
PlayList_setposition(JSAPI_PARAM(pdispparams, 1).lVal);
plEditRefresh();
}
return S_OK;
}
else if (wFlags & DISPATCH_PROPERTYGET)
{
JSAPI_VERIFY_PARAMCOUNT(pdispparams, 0);
VariantInit(pvarResult);
V_VT(pvarResult) = VT_I4;
V_I4(pvarResult) = PlayList_getPosition();
return S_OK;
}
return DISP_E_MEMBERNOTFOUND;
}
#undef CHECK_ID
#define CHECK_ID(str, id) case id: return str(wFlags, pdispparams, pvarResult, puArgErr);
HRESULT JSAPI2::PlayerAPI::Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr)
{
switch (dispid)
{
DISP_TABLE
}
return DISP_E_MEMBERNOTFOUND;
}
STDMETHODIMP JSAPI2::PlayerAPI::QueryInterface(REFIID riid, PVOID *ppvObject)
{
if (!ppvObject)
return E_POINTER;
else if (IsEqualIID(riid, IID_IDispatch))
*ppvObject = (IDispatch *)this;
else if (IsEqualIID(riid, IID_IUnknown))
*ppvObject = this;
else
{
*ppvObject = NULL;
return E_NOINTERFACE;
}
AddRef();
return S_OK;
}
ULONG JSAPI2::PlayerAPI::AddRef(void)
{
return InterlockedIncrement(&refCount);
}
ULONG JSAPI2::PlayerAPI::Release(void)
{
LONG lRef = InterlockedDecrement(&refCount);
if (lRef == 0) delete this;
return lRef;
}
|