1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Alax.Info, 2006-2013 |
---|
3 | // http://alax.info |
---|
4 | // |
---|
5 | // A permission to use the source code is granted as long as reference to |
---|
6 | // source website http://alax.info is retained. |
---|
7 | |
---|
8 | #pragma once |
---|
9 | |
---|
10 | #include <upnp.h> |
---|
11 | #include "rocrypt.h" |
---|
12 | |
---|
13 | //////////////////////////////////////////////////////////// |
---|
14 | // CMainDialog |
---|
15 | |
---|
16 | class CMainDialog : |
---|
17 | public CDialogImpl<CMainDialog>, |
---|
18 | public CDialogResize<CMainDialog>, |
---|
19 | public CWindowWithPrivateMessagesT<CMainDialog> |
---|
20 | { |
---|
21 | public: |
---|
22 | enum { IDD = IDD_MAIN }; |
---|
23 | |
---|
24 | BEGIN_MSG_MAP_EX(CMainDialog) |
---|
25 | CHAIN_MSG_MAP(CDialogResize<CMainDialog>) |
---|
26 | CHAIN_MSG_MAP(CWindowWithPrivateMessages) |
---|
27 | MSG_WM_INITDIALOG(OnInitDialog) |
---|
28 | MSG_WM_DESTROY(OnDestroy) |
---|
29 | MESSAGE_HANDLER_EX(WM_SEARCHCOMPLETE, OnSearchComplete) |
---|
30 | COMMAND_ID_HANDLER_EX(IDOK, OnCommand) |
---|
31 | COMMAND_ID_HANDLER_EX(IDCANCEL, OnCommand) |
---|
32 | COMMAND_HANDLER_EX(IDC_SCAN, BN_CLICKED, OnScanClicked) |
---|
33 | COMMAND_HANDLER_EX(IDC_SUBMIT, BN_CLICKED, OnSubmitClicked) |
---|
34 | REFLECT_NOTIFICATIONS() |
---|
35 | END_MSG_MAP() |
---|
36 | |
---|
37 | BEGIN_DLGRESIZE_MAP(CMainDialog) |
---|
38 | DLGRESIZE_CONTROL(IDC_TEXT, DLSZ_SIZE_X | DLSZ_SIZE_Y) |
---|
39 | DLGRESIZE_CONTROL(IDC_SCAN, DLSZ_MOVE_X | DLSZ_MOVE_Y) |
---|
40 | DLGRESIZE_CONTROL(IDC_SUBMIT, DLSZ_MOVE_X | DLSZ_MOVE_Y) |
---|
41 | DLGRESIZE_CONTROL(IDCANCEL, DLSZ_MOVE_X | DLSZ_MOVE_Y) |
---|
42 | END_DLGRESIZE_MAP() |
---|
43 | |
---|
44 | public: |
---|
45 | |
---|
46 | //////////////////////////////////////////////////////// |
---|
47 | // CService |
---|
48 | |
---|
49 | class CService |
---|
50 | { |
---|
51 | public: |
---|
52 | CComPtr<IUPnPService> m_pService; |
---|
53 | CString m_sServiceTypeIdentifier; |
---|
54 | CString m_sIdentifier; |
---|
55 | LONG m_nLastTransportStatus; |
---|
56 | |
---|
57 | public: |
---|
58 | // CService |
---|
59 | CService() throw() |
---|
60 | { |
---|
61 | } |
---|
62 | CService(IUPnPService* pService) |
---|
63 | { |
---|
64 | Initialize(pService); |
---|
65 | } |
---|
66 | VOID Initialize(IUPnPService* pService) |
---|
67 | { |
---|
68 | _A(pService); |
---|
69 | m_pService = m_pService; |
---|
70 | CComBSTR sServiceTypeIdentifier; |
---|
71 | __C(pService->get_ServiceTypeIdentifier(&sServiceTypeIdentifier)); |
---|
72 | m_sServiceTypeIdentifier = CString(sServiceTypeIdentifier); |
---|
73 | CComBSTR sIdentifier; |
---|
74 | __C(pService->get_Id(&sIdentifier)); |
---|
75 | m_sIdentifier = CString(sIdentifier); |
---|
76 | LONG nLastTransportStatus = 0; |
---|
77 | __C(pService->get_LastTransportStatus(&nLastTransportStatus)); |
---|
78 | m_nLastTransportStatus = nLastTransportStatus; |
---|
79 | } |
---|
80 | }; |
---|
81 | |
---|
82 | //////////////////////////////////////////////////////// |
---|
83 | // CServiceList |
---|
84 | |
---|
85 | class CServiceList : |
---|
86 | public CAtlList<CService> |
---|
87 | { |
---|
88 | public: |
---|
89 | CComPtr<IUPnPServices> m_pServices; |
---|
90 | |
---|
91 | public: |
---|
92 | // CServiceList |
---|
93 | CServiceList() throw() |
---|
94 | { |
---|
95 | } |
---|
96 | CServiceList(IUPnPServices* pServices) |
---|
97 | { |
---|
98 | _A(pServices); |
---|
99 | Initialize(pServices); |
---|
100 | } |
---|
101 | VOID Initialize(IUPnPServices* pServices) |
---|
102 | { |
---|
103 | _A(pServices); |
---|
104 | m_pServices = pServices; |
---|
105 | RemoveAll(); |
---|
106 | CComPtr<IUnknown> pEnumUnknownUnknown; |
---|
107 | __C(pServices->get__NewEnum(&pEnumUnknownUnknown)); |
---|
108 | CAtlList<CComPtr<IUPnPService> > ServiceList; |
---|
109 | EnumerateInterfaceList(pEnumUnknownUnknown, ServiceList); |
---|
110 | for(POSITION ServicePosition = ServiceList.GetHeadPosition(); ServicePosition; ServiceList.GetNext(ServicePosition)) |
---|
111 | { |
---|
112 | const CComPtr<IUPnPService>& pService = ServiceList.GetAt(ServicePosition); |
---|
113 | _A(pService); |
---|
114 | POSITION Position = AddTail(); |
---|
115 | _ATLTRY |
---|
116 | { |
---|
117 | GetAt(Position).Initialize(pService); |
---|
118 | } |
---|
119 | _ATLCATCHALL() |
---|
120 | { |
---|
121 | RemoveAt(Position); |
---|
122 | _ATLRETHROW; |
---|
123 | } |
---|
124 | } |
---|
125 | } |
---|
126 | }; |
---|
127 | |
---|
128 | //////////////////////////////////////////////////////// |
---|
129 | // CDevice |
---|
130 | |
---|
131 | class CDevice |
---|
132 | { |
---|
133 | public: |
---|
134 | CComPtr<IUPnPDevice> m_pDevice; |
---|
135 | BOOL m_bIsRootDevice; |
---|
136 | BOOL m_bHasChildren; |
---|
137 | CAtlList<CDevice> m_ChildDeviceList; |
---|
138 | CString m_sUniqueDeviceName; |
---|
139 | CString m_sFriendlyName; |
---|
140 | CString m_sType; |
---|
141 | CString m_sPresentationURL; |
---|
142 | CString m_sManufacturerName; |
---|
143 | CString m_sManufacturerURL; |
---|
144 | CString m_sModelName; |
---|
145 | CString m_sModelNumber; |
---|
146 | CString m_sDescription; |
---|
147 | CString m_sModelURL; |
---|
148 | CString m_sUPC; |
---|
149 | CString m_sSerialNumber; |
---|
150 | CServiceList m_ServiceList; |
---|
151 | |
---|
152 | public: |
---|
153 | // CDevice |
---|
154 | CDevice() throw() |
---|
155 | { |
---|
156 | } |
---|
157 | CDevice(IUPnPDevice* pDevice) |
---|
158 | { |
---|
159 | _A(pDevice); |
---|
160 | Initialize(pDevice); |
---|
161 | } |
---|
162 | VOID Initialize(IUPnPDevice* pDevice) |
---|
163 | { |
---|
164 | _A(pDevice); |
---|
165 | m_pDevice = pDevice; |
---|
166 | VARIANT_BOOL bIsRootDevice = ATL_VARIANT_FALSE; |
---|
167 | __C(pDevice->get_IsRootDevice(&bIsRootDevice)); |
---|
168 | m_bIsRootDevice = m_bIsRootDevice != ATL_VARIANT_FALSE; |
---|
169 | //__C(pDevice->get_RootDevice( |
---|
170 | //__C(pDevice->get_ParentDevice( |
---|
171 | VARIANT_BOOL bHasChildren = ATL_VARIANT_FALSE; |
---|
172 | __C(pDevice->get_HasChildren(&bHasChildren)); |
---|
173 | m_bHasChildren = bHasChildren; |
---|
174 | m_ChildDeviceList.RemoveAll(); |
---|
175 | if(bHasChildren) |
---|
176 | { |
---|
177 | CComPtr<IUPnPDevices> pDevices; |
---|
178 | __C(pDevice->get_Children(&pDevices)); |
---|
179 | __D(pDevices, E_NOINTERFACE); |
---|
180 | CComPtr<IUnknown> pEnumUnknownUnknown; |
---|
181 | __C(pDevices->get__NewEnum(&pEnumUnknownUnknown)); |
---|
182 | CAtlList<CComPtr<IUPnPDevice> > DeviceList; |
---|
183 | EnumerateInterfaceList(pEnumUnknownUnknown, DeviceList); |
---|
184 | for(POSITION Position = DeviceList.GetHeadPosition(); Position; DeviceList.GetNext(Position)) |
---|
185 | { |
---|
186 | const CComPtr<IUPnPDevice>& pDevice = DeviceList.GetAt(Position); |
---|
187 | _A(pDevice); |
---|
188 | POSITION ChildDevicePosition = m_ChildDeviceList.AddTail(); |
---|
189 | _ATLTRY |
---|
190 | { |
---|
191 | m_ChildDeviceList.GetAt(ChildDevicePosition).Initialize(pDevice); |
---|
192 | } |
---|
193 | _ATLCATCHALL() |
---|
194 | { |
---|
195 | m_ChildDeviceList.RemoveAt(ChildDevicePosition); |
---|
196 | _ATLRETHROW; |
---|
197 | } |
---|
198 | } |
---|
199 | } |
---|
200 | CComBSTR sUniqueDeviceName; |
---|
201 | __C(pDevice->get_UniqueDeviceName(&sUniqueDeviceName)); |
---|
202 | m_sUniqueDeviceName = CString(sUniqueDeviceName); |
---|
203 | CComBSTR sFriendlyName; |
---|
204 | __C(pDevice->get_FriendlyName(&sFriendlyName)); |
---|
205 | m_sFriendlyName = CString(sFriendlyName); |
---|
206 | CComBSTR sType; |
---|
207 | __C(pDevice->get_Type(&sType)); |
---|
208 | m_sType = CString(sType); |
---|
209 | CComBSTR sPresentationURL; |
---|
210 | __C(pDevice->get_PresentationURL(&sPresentationURL)); |
---|
211 | m_sPresentationURL = CString(sPresentationURL); |
---|
212 | CComBSTR sManufacturerName; |
---|
213 | __C(pDevice->get_ManufacturerName(&sManufacturerName)); |
---|
214 | m_sManufacturerName = CString(sManufacturerName); |
---|
215 | CComBSTR sManufacturerURL; |
---|
216 | __C(pDevice->get_ManufacturerURL(&sManufacturerURL)); |
---|
217 | m_sManufacturerURL = CString(sManufacturerURL); |
---|
218 | CComBSTR sModelName; |
---|
219 | __C(pDevice->get_ModelName(&sModelName)); |
---|
220 | m_sModelName = CString(sModelName); |
---|
221 | CComBSTR sModelNumber; |
---|
222 | __C(pDevice->get_ModelNumber(&sModelNumber)); |
---|
223 | m_sModelNumber = CString(sModelNumber); |
---|
224 | CComBSTR sDescription; |
---|
225 | __C(pDevice->get_Description(&sDescription)); |
---|
226 | m_sDescription = CString(sDescription); |
---|
227 | CComBSTR sModelURL; |
---|
228 | __C(pDevice->get_ModelURL(&sModelURL)); |
---|
229 | m_sModelURL = CString(sModelURL); |
---|
230 | CComBSTR sUPC; |
---|
231 | __C(pDevice->get_UPC(&sUPC)); |
---|
232 | m_sUPC = CString(sUPC); |
---|
233 | CComBSTR sSerialNumber; |
---|
234 | __C(pDevice->get_SerialNumber(&sSerialNumber)); |
---|
235 | m_sSerialNumber = CString(sSerialNumber); |
---|
236 | CComPtr<IUPnPServices> pServices; |
---|
237 | __C(pDevice->get_Services(&pServices)); |
---|
238 | m_ServiceList.Initialize(pServices); |
---|
239 | } |
---|
240 | }; |
---|
241 | |
---|
242 | //////////////////////////////////////////////////////// |
---|
243 | // CDeviceList |
---|
244 | |
---|
245 | class CDeviceList : |
---|
246 | public CAtlList<CDevice> |
---|
247 | { |
---|
248 | public: |
---|
249 | CComPtr<IUPnPDevices> m_pDevices; |
---|
250 | |
---|
251 | public: |
---|
252 | // CDeviceList |
---|
253 | CDeviceList() throw() |
---|
254 | { |
---|
255 | } |
---|
256 | CDeviceList(IUPnPDevices* pDevices) |
---|
257 | { |
---|
258 | _A(pDevices); |
---|
259 | Initialize(pDevices); |
---|
260 | } |
---|
261 | VOID Initialize(IUPnPDevices* pDevices) |
---|
262 | { |
---|
263 | _A(pDevices); |
---|
264 | m_pDevices = pDevices; |
---|
265 | RemoveAll(); |
---|
266 | CComPtr<IUnknown> pEnumUnknownUnknown; |
---|
267 | __C(pDevices->get__NewEnum(&pEnumUnknownUnknown)); |
---|
268 | CAtlList<CComPtr<IUPnPDevice> > DeviceList; |
---|
269 | EnumerateInterfaceList(pEnumUnknownUnknown, DeviceList); |
---|
270 | for(POSITION DevicePosition = DeviceList.GetHeadPosition(); DevicePosition; DeviceList.GetNext(DevicePosition)) |
---|
271 | { |
---|
272 | const CComPtr<IUPnPDevice>& pDevice = DeviceList.GetAt(DevicePosition); |
---|
273 | _A(pDevice); |
---|
274 | POSITION Position = AddTail(); |
---|
275 | _ATLTRY |
---|
276 | { |
---|
277 | GetAt(Position).Initialize(pDevice); |
---|
278 | } |
---|
279 | _ATLCATCHALL() |
---|
280 | { |
---|
281 | RemoveAt(Position); |
---|
282 | _ATLRETHROW; |
---|
283 | } |
---|
284 | } |
---|
285 | } |
---|
286 | }; |
---|
287 | |
---|
288 | //////////////////////////////////////////////////////// |
---|
289 | // Window message identifiers |
---|
290 | |
---|
291 | enum |
---|
292 | { |
---|
293 | WM_FIRST = WM_APP, |
---|
294 | WM_SEARCHCOMPLETE, |
---|
295 | }; |
---|
296 | |
---|
297 | //////////////////////////////////////////////////////// |
---|
298 | // CDeviceFinderCallback |
---|
299 | |
---|
300 | class ATL_NO_VTABLE CDeviceFinderCallback : |
---|
301 | public CComObjectRootEx<CComMultiThreadModelNoCS>, |
---|
302 | public IUPnPDeviceFinderCallback//, |
---|
303 | //public IUPnPDeviceFinderAddCallbackWithInterface |
---|
304 | { |
---|
305 | public: |
---|
306 | |
---|
307 | BEGIN_COM_MAP(CDeviceFinderCallback) |
---|
308 | COM_INTERFACE_ENTRY(IUPnPDeviceFinderCallback) |
---|
309 | //COM_INTERFACE_ENTRY(IUPnPDeviceFinderAddCallbackWithInterface) |
---|
310 | END_COM_MAP() |
---|
311 | |
---|
312 | private: |
---|
313 | mutable CRoCriticalSection m_DataCriticalSection; |
---|
314 | CMainDialog* m_pOwner; |
---|
315 | CDeviceList m_DeviceList; |
---|
316 | |
---|
317 | public: |
---|
318 | // CDeviceFinderCallback |
---|
319 | CDeviceFinderCallback() throw() : |
---|
320 | m_pOwner(NULL) |
---|
321 | { |
---|
322 | _Z4(atlTraceRefcount, 4, _T("this 0x%08x\n"), this); |
---|
323 | } |
---|
324 | ~CDeviceFinderCallback() throw() |
---|
325 | { |
---|
326 | _Z4(atlTraceRefcount, 4, _T("this 0x%08x\n"), this); |
---|
327 | _A(!m_pOwner); |
---|
328 | } |
---|
329 | VOID Initialize(CMainDialog* pOwner) |
---|
330 | { |
---|
331 | _A(pOwner); |
---|
332 | CRoCriticalSectionLock DataLock(m_DataCriticalSection); |
---|
333 | _A(!m_pOwner); |
---|
334 | m_pOwner = pOwner; |
---|
335 | _A(m_DeviceList.IsEmpty()); |
---|
336 | } |
---|
337 | VOID Terminate() |
---|
338 | { |
---|
339 | CRoCriticalSectionLock DataLock(m_DataCriticalSection); |
---|
340 | m_pOwner = NULL; |
---|
341 | } |
---|
342 | CMainDialog* GetOwner() const throw() |
---|
343 | { |
---|
344 | CRoCriticalSectionLock DataLock(m_DataCriticalSection); |
---|
345 | return m_pOwner; |
---|
346 | } |
---|
347 | const CDeviceList& GetDeviceList() const throw() |
---|
348 | { |
---|
349 | _A(!GetOwner()); |
---|
350 | return m_DeviceList; |
---|
351 | } |
---|
352 | |
---|
353 | // IUPnPDeviceFinderCallback |
---|
354 | STDMETHOD(DeviceAdded)(LONG nCookie, IUPnPDevice* pDevice) throw() |
---|
355 | { |
---|
356 | _Z4(atlTraceCOM, 4, _T("nCookie 0x%08x\n"), nCookie); |
---|
357 | _ATLTRY |
---|
358 | { |
---|
359 | __D(pDevice, E_INVALIDARG); |
---|
360 | CRoCriticalSectionLock DataLock(m_DataCriticalSection); |
---|
361 | if(!m_pOwner) |
---|
362 | return S_FALSE; |
---|
363 | _A(nCookie == m_pOwner->m_nAsynchronousDeviceFinderCookie); |
---|
364 | VARIANT_BOOL bIsRootDevice = ATL_VARIANT_FALSE; |
---|
365 | __C(pDevice->get_IsRootDevice(&bIsRootDevice)); |
---|
366 | if(bIsRootDevice == ATL_VARIANT_FALSE) |
---|
367 | return S_FALSE; |
---|
368 | #if _DEVELOPMENT |
---|
369 | CComBSTR sUniqueDeviceName; |
---|
370 | __C(pDevice->get_UniqueDeviceName(&sUniqueDeviceName)); |
---|
371 | _Z4(atlTraceGeneral, 4, _T("sUniqueDeviceName %s\n"), CString(sUniqueDeviceName)); |
---|
372 | #endif // _DEVELOPMENT |
---|
373 | POSITION Position = m_DeviceList.AddTail(); |
---|
374 | _A(Position); |
---|
375 | _ATLTRY |
---|
376 | { |
---|
377 | m_DeviceList.GetAt(Position).Initialize(pDevice); |
---|
378 | } |
---|
379 | _ATLCATCHALL() |
---|
380 | { |
---|
381 | m_DeviceList.RemoveAt(Position); |
---|
382 | _ATLRETHROW; |
---|
383 | } |
---|
384 | } |
---|
385 | _ATLCATCH(Exception) |
---|
386 | { |
---|
387 | _Z_ATLEXCEPTION(Exception); |
---|
388 | } |
---|
389 | return S_OK; |
---|
390 | } |
---|
391 | STDMETHOD(DeviceRemoved)(LONG nCookie, BSTR sUniqueDeviceName) throw() |
---|
392 | { |
---|
393 | _Z4(atlTraceCOM, 4, _T("nCookie 0x%08x, sUniqueDeviceName %s\n"), nCookie, CString(sUniqueDeviceName)); |
---|
394 | _ATLTRY |
---|
395 | { |
---|
396 | CRoCriticalSectionLock DataLock(m_DataCriticalSection); |
---|
397 | if(!m_pOwner) |
---|
398 | return S_FALSE; |
---|
399 | _A(nCookie == m_pOwner->m_nAsynchronousDeviceFinderCookie); |
---|
400 | // TODO: IUPnPDeviceFinderCallback::DeviceRemoved |
---|
401 | } |
---|
402 | _ATLCATCH(Exception) |
---|
403 | { |
---|
404 | _Z_ATLEXCEPTION(Exception); |
---|
405 | } |
---|
406 | return S_OK; |
---|
407 | } |
---|
408 | STDMETHOD(SearchComplete)(LONG nCookie) throw() |
---|
409 | { |
---|
410 | _Z4(atlTraceCOM, 4, _T("nCookie 0x%08x\n"), nCookie); |
---|
411 | _ATLTRY |
---|
412 | { |
---|
413 | CRoCriticalSectionLock DataLock(m_DataCriticalSection); |
---|
414 | if(!m_pOwner) |
---|
415 | return S_FALSE; |
---|
416 | _A(nCookie == m_pOwner->m_nAsynchronousDeviceFinderCookie); |
---|
417 | m_pOwner->PostPrivateMessage(WM_SEARCHCOMPLETE); |
---|
418 | } |
---|
419 | _ATLCATCH(Exception) |
---|
420 | { |
---|
421 | _Z_ATLEXCEPTION(Exception); |
---|
422 | } |
---|
423 | return S_OK; |
---|
424 | } |
---|
425 | |
---|
426 | // IUPnPDeviceFinderAddCallbackWithInterface |
---|
427 | }; |
---|
428 | |
---|
429 | private: |
---|
430 | CButton m_ScanButton; |
---|
431 | CButton m_SubmitButton; |
---|
432 | CRoEdit m_TextEdit; |
---|
433 | CComPtr<IUPnPDeviceFinder> m_pDeviceFinder; |
---|
434 | LONG m_nAsynchronousDeviceFinderCookie; |
---|
435 | CObjectPtr<CDeviceFinderCallback> m_pDeviceFinderCallback; |
---|
436 | |
---|
437 | VOID UpdateControls() |
---|
438 | { |
---|
439 | m_ScanButton.EnableWindow(m_pDeviceFinder == NULL); |
---|
440 | } |
---|
441 | VOID AddDeviceToText(CString& sText, const CString& sIndent, const CDevice& Device) |
---|
442 | { |
---|
443 | sText.Append(AtlFormatString( |
---|
444 | _T("%s Unique Device Name: %s\r\n") |
---|
445 | _T("%s Friendly Name: %s\r\n") |
---|
446 | _T("%s Type: %s\r\n") |
---|
447 | _T("%s Presentation URL: %s\r\n") |
---|
448 | _T("%s Manufacturer Name: %s\r\n") |
---|
449 | _T("%s Manufacturer URL: %s\r\n") |
---|
450 | _T("%s Model Name: %s\r\n") |
---|
451 | _T("%s Model Number: %s\r\n") |
---|
452 | _T("%s Description: %s\r\n") |
---|
453 | _T("%s Model URL: %s\r\n") |
---|
454 | _T("%s UPC: %s\r\n") |
---|
455 | _T("%s Serial Number: %s\r\n") |
---|
456 | _T(""), |
---|
457 | sIndent, Device.m_sUniqueDeviceName, |
---|
458 | sIndent, Device.m_sFriendlyName, |
---|
459 | sIndent, Device.m_sType, |
---|
460 | sIndent, Device.m_sPresentationURL, |
---|
461 | sIndent, Device.m_sManufacturerName, |
---|
462 | sIndent, Device.m_sManufacturerURL, |
---|
463 | sIndent, Device.m_sModelName, |
---|
464 | sIndent, Device.m_sModelNumber, |
---|
465 | sIndent, Device.m_sDescription, |
---|
466 | sIndent, Device.m_sModelURL, |
---|
467 | sIndent, Device.m_sUPC, |
---|
468 | sIndent, Device.m_sSerialNumber, |
---|
469 | 0)); |
---|
470 | const CServiceList& ServiceList = Device.m_ServiceList; |
---|
471 | UINT nServiceIndex = 0; |
---|
472 | for(POSITION Position = ServiceList.GetHeadPosition(); Position; ServiceList.GetNext(Position), nServiceIndex++) |
---|
473 | { |
---|
474 | const CService& Service = ServiceList.GetAt(Position); |
---|
475 | sText.Append(AtlFormatString( |
---|
476 | _T("%s Service %d:\r\n") |
---|
477 | _T("%s Service Type Identifier: %s\r\n") |
---|
478 | _T("%s Identifier: %s\r\n") |
---|
479 | _T("%s Last Transport Status: %d\r\n") |
---|
480 | _T(""), |
---|
481 | sIndent, nServiceIndex + 1, |
---|
482 | sIndent, Service.m_sServiceTypeIdentifier, |
---|
483 | sIndent, Service.m_sIdentifier, |
---|
484 | sIndent, Service.m_nLastTransportStatus, |
---|
485 | 0)); |
---|
486 | } |
---|
487 | const CAtlList<CDevice>& DeviceList = Device.m_ChildDeviceList; |
---|
488 | UINT nDeviceIndex = 0; |
---|
489 | for(POSITION Position = DeviceList.GetHeadPosition(); Position; DeviceList.GetNext(Position), nDeviceIndex++) |
---|
490 | { |
---|
491 | const CDevice& Device = DeviceList.GetAt(Position); |
---|
492 | sText.Append(AtlFormatString( |
---|
493 | _T("%s Subdevice %d:\r\n") |
---|
494 | _T(""), |
---|
495 | sIndent, nDeviceIndex + 1, |
---|
496 | 0)); |
---|
497 | AddDeviceToText(sText, sIndent + _T(" "), Device); |
---|
498 | sText.Append(_T("\r\n")); |
---|
499 | } |
---|
500 | } |
---|
501 | |
---|
502 | public: |
---|
503 | // CMainDialog |
---|
504 | template <typename _Interface> |
---|
505 | static SIZE_T EnumerateInterfaceList(IEnumUnknown* pEnumUnknown, CAtlList<CComPtr<_Interface> >& InterfaceList) |
---|
506 | { |
---|
507 | InterfaceList.RemoveAll(); |
---|
508 | if(pEnumUnknown) |
---|
509 | { |
---|
510 | CComPtr<IUnknown> pUnknown; |
---|
511 | for(; pEnumUnknown->Next(1, &pUnknown, NULL) == S_OK; ) |
---|
512 | { |
---|
513 | CComQIPtr<_Interface> pInterface = pUnknown; |
---|
514 | __D(pInterface, E_NOINTERFACE); |
---|
515 | _W(InterfaceList.AddTail(pInterface)); |
---|
516 | pUnknown.Release(); |
---|
517 | } |
---|
518 | } |
---|
519 | return InterfaceList.GetCount(); |
---|
520 | } |
---|
521 | template <typename _Interface> |
---|
522 | static SIZE_T EnumerateInterfaceList(IUnknown* pEnumUnknownUnknown, CAtlList<CComPtr<_Interface> >& InterfaceList) |
---|
523 | { |
---|
524 | return EnumerateInterfaceList<_Interface>(CComQIPtr<IEnumUnknown>(pEnumUnknownUnknown), InterfaceList); |
---|
525 | } |
---|
526 | |
---|
527 | // Window message handlers |
---|
528 | LRESULT OnInitDialog(HWND, LPARAM) |
---|
529 | { |
---|
530 | DlgResize_Init(); |
---|
531 | m_ScanButton = GetDlgItem(IDC_SCAN); |
---|
532 | m_SubmitButton = GetDlgItem(IDC_SUBMIT); |
---|
533 | m_TextEdit = GetDlgItem(IDC_TEXT); |
---|
534 | m_TextEdit.SetLimitText(0); |
---|
535 | SetIcon(AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)), TRUE); |
---|
536 | SetIcon(AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)), FALSE); |
---|
537 | _W(CenterWindow()); |
---|
538 | #if _DEVELOPMENT && FALSE |
---|
539 | m_TextEdit.SetValue(_T("Test")); |
---|
540 | #endif // _DEVELOPMENT |
---|
541 | UpdateControls(); |
---|
542 | return TRUE; |
---|
543 | } |
---|
544 | LRESULT OnDestroy() |
---|
545 | { |
---|
546 | if(m_pDeviceFinderCallback) |
---|
547 | m_pDeviceFinderCallback->Terminate(); |
---|
548 | if(m_pDeviceFinder) |
---|
549 | _V(m_pDeviceFinder->CancelAsyncFind(m_nAsynchronousDeviceFinderCookie)); |
---|
550 | return 0; |
---|
551 | } |
---|
552 | LRESULT OnSearchComplete(UINT, WPARAM, LPARAM) |
---|
553 | { |
---|
554 | m_pDeviceFinder.Release(); |
---|
555 | m_pDeviceFinderCallback->Terminate(); |
---|
556 | UpdateControls(); |
---|
557 | CString sText; |
---|
558 | const CDeviceList& DeviceList = m_pDeviceFinderCallback->GetDeviceList(); |
---|
559 | sText.Append(AtlFormatString(_T("Devices Found: %d\r\n"), DeviceList.GetCount())); |
---|
560 | sText.Append(_T("\r\n")); |
---|
561 | UINT nDeviceIndex = 0; |
---|
562 | for(POSITION Position = DeviceList.GetHeadPosition(); Position; DeviceList.GetNext(Position), nDeviceIndex++) |
---|
563 | { |
---|
564 | const CDevice& Device = DeviceList.GetAt(Position); |
---|
565 | sText.Append(AtlFormatString(_T("Device %d:\r\n"), nDeviceIndex + 1)); |
---|
566 | AddDeviceToText(sText, _T(""), Device); |
---|
567 | sText.Append(_T("\r\n")); |
---|
568 | } |
---|
569 | sText.Append(_T("* * *") _T("\r\n") _T("\r\n")); |
---|
570 | OSVERSIONINFOEX VersionInformation = { sizeof VersionInformation }; |
---|
571 | _W(GetVersionEx((OSVERSIONINFO*) &VersionInformation)); |
---|
572 | CString sVersion = AtlFormatString(_T("%d.%d Build %d"), VersionInformation.dwMajorVersion, VersionInformation.dwMinorVersion, VersionInformation.dwBuildNumber); |
---|
573 | if(VersionInformation.wServicePackMajor) |
---|
574 | sVersion += AtlFormatString(_T(", Service Pack %d.%d"), VersionInformation.wServicePackMajor, VersionInformation.wServicePackMinor); |
---|
575 | sText.Append(AtlFormatString(_T("Operating System: %s\r\n"), sVersion)); |
---|
576 | sText.Append(_T("\r\n")); |
---|
577 | sText.Append(_T("* * *") _T("\r\n") _T("\r\n")); |
---|
578 | sText.Append(_T("Please submit scan results to http://alax.info/ using Submit button.\r\n")); |
---|
579 | sText.Append(_T("No personal information is transmitted.\r\n")); |
---|
580 | m_TextEdit.SetValue(sText); |
---|
581 | m_TextEdit.ScrollCaret(); |
---|
582 | m_SubmitButton.EnableWindow(TRUE); |
---|
583 | return 0; |
---|
584 | } |
---|
585 | LRESULT OnCommand(UINT, INT nIdentifier, HWND) |
---|
586 | { |
---|
587 | _W(EndDialog(nIdentifier)); |
---|
588 | return 0; |
---|
589 | } |
---|
590 | LRESULT OnScanClicked(UINT, INT, HWND) |
---|
591 | { |
---|
592 | m_TextEdit.SetValue(_T("")); |
---|
593 | m_SubmitButton.EnableWindow(FALSE); |
---|
594 | if(m_pDeviceFinder) |
---|
595 | return 0; |
---|
596 | __C(m_pDeviceFinder.CoCreateInstance(CLSID_UPnPDeviceFinder)); |
---|
597 | _ATLTRY |
---|
598 | { |
---|
599 | m_pDeviceFinderCallback = NULL; |
---|
600 | m_pDeviceFinderCallback.Construct()->Initialize(this); |
---|
601 | __C(m_pDeviceFinder->CreateAsyncFind(CComBSTR(_T("upnp:rootdevice")), 0, m_pDeviceFinderCallback, &m_nAsynchronousDeviceFinderCookie)); |
---|
602 | __C(m_pDeviceFinder->StartAsyncFind(m_nAsynchronousDeviceFinderCookie)); |
---|
603 | m_TextEdit.SetValue(_T("Scanning, the process may take a few minutes, please wait...")); |
---|
604 | } |
---|
605 | _ATLCATCHALL() |
---|
606 | { |
---|
607 | m_pDeviceFinder.Release(); |
---|
608 | _ATLRETHROW; |
---|
609 | } |
---|
610 | UpdateControls(); |
---|
611 | return 0; |
---|
612 | } |
---|
613 | LRESULT OnSubmitClicked(UINT, INT, HWND) |
---|
614 | { |
---|
615 | CWaitCursor WaitCursor; |
---|
616 | CWinHttpPostData PostData; |
---|
617 | PostData.AddValue(_T("subj"), _T("Alax.Info UPnP Scan")); |
---|
618 | { |
---|
619 | CStringA sTextA = Utf8StringFromString(m_TextEdit.GetValue()); |
---|
620 | static const UINT g_nFlags = _Base64Helper::FLAG_NOPAD | _Base64Helper::FLAG_NOCRLF; |
---|
621 | SIZE_T nEncodedTextSize = _Base64Helper::GetEncodeOutputSize(sTextA.GetLength(), g_nFlags); |
---|
622 | CStringA sEncodedTextA; |
---|
623 | nEncodedTextSize = _Base64Helper::Encode<CHAR>((const BYTE*) (LPCSTR) sTextA, sTextA.GetLength(), sEncodedTextA.GetBufferSetLength((INT) nEncodedTextSize), nEncodedTextSize, g_nFlags); |
---|
624 | sEncodedTextA.GetBufferSetLength((INT) nEncodedTextSize); |
---|
625 | PostData.AddValue(_T("body"), CString(sEncodedTextA)); |
---|
626 | } |
---|
627 | CWinHttpSessionHandle Session = OpenWinHttpSessionHandle(AtlFormatString(IDS_PROJNAME)); |
---|
628 | __E(Session); |
---|
629 | CWinHttpConnectionHandle Connection = Session.Connect(CStringW(_T("alax.info"))); |
---|
630 | __E(Connection); |
---|
631 | CWinHttpRequestHandle Request = Connection.OpenRequest(CStringW(_T("POST")), CStringW(_T("/post.php"))); |
---|
632 | __E(Request); |
---|
633 | CStringW sPostHeaders = PostData.GetHeaders(); |
---|
634 | CStringA sPostData(PostData.GetValue()); |
---|
635 | __E(Request.Send(sPostHeaders, -1, const_cast<LPSTR>((LPCSTR) sPostData), sPostData.GetLength(), sPostData.GetLength())); |
---|
636 | __E(Request.ReceiveResponse()); |
---|
637 | DWORD nStatusCode = 0; |
---|
638 | __E(Request.QueryNumberHeader(WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, nStatusCode)); |
---|
639 | __D(nStatusCode / 100 == 2, E_UNNAMED); |
---|
640 | AtlMessageBoxEx(m_hWnd, _T("Submission complete, thank you!"), IDS_INFORMATION, MB_ICONINFORMATION | MB_OK); |
---|
641 | UpdateControls(); |
---|
642 | return 0; |
---|
643 | } |
---|
644 | }; |
---|