Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

338 lines
11 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: POSTPLUG.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 4/11/2000
  12. *
  13. * DESCRIPTION:
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include <atlimpl.cpp>
  19. #include "postplug.h"
  20. #include "geturldlg.h"
  21. #include "simreg.h"
  22. CHttpPostPlugin::~CHttpPostPlugin(void)
  23. {
  24. DllRelease();
  25. }
  26. CHttpPostPlugin::CHttpPostPlugin()
  27. : m_cRef(1),
  28. m_pImageTransferPluginProgressCallback(NULL),
  29. m_nCurrentPluginId(-1)
  30. {
  31. DllAddRef();
  32. CSimpleReg reg( HKEY_CURRENT_USER, CSimpleString( IDS_COMMUNITIES_ACCOUNTS_KEY, g_hInstance ), false, KEY_READ );
  33. if (reg.OK())
  34. {
  35. reg.EnumValues( EnumCommunitiesProc, reinterpret_cast<LPARAM>(this) );
  36. }
  37. m_CommunityInfoArray.Append( CCommunityInfo( TEXT(""), CSimpleString( IDS_COMMUNITY_PICK, g_hInstance ) ) );
  38. }
  39. bool CHttpPostPlugin::EnumCommunitiesProc( CSimpleReg::CValueEnumInfo &enumInfo )
  40. {
  41. CHttpPostPlugin *pHttpPostPlugin = reinterpret_cast<CHttpPostPlugin*>(enumInfo.lParam);
  42. if (pHttpPostPlugin)
  43. {
  44. if (enumInfo.strName.Length())
  45. {
  46. CSimpleString strCommunityName = enumInfo.reg.Query( enumInfo.strName, TEXT("") );
  47. if (strCommunityName.Length())
  48. {
  49. pHttpPostPlugin->m_CommunityInfoArray.Append( CCommunityInfo( enumInfo.strName, strCommunityName ) );
  50. }
  51. }
  52. }
  53. return true;
  54. }
  55. STDMETHODIMP CHttpPostPlugin::QueryInterface( REFIID riid, LPVOID *ppvObject )
  56. {
  57. if (IsEqualIID( riid, IID_IUnknown ))
  58. {
  59. *ppvObject = static_cast<IImageTransferPlugin*>(this);
  60. }
  61. else if (IsEqualIID( riid, IID_IImageTransferPlugin ))
  62. {
  63. *ppvObject = static_cast<IImageTransferPlugin*>(this);
  64. }
  65. else
  66. {
  67. *ppvObject = NULL;
  68. return (E_NOINTERFACE);
  69. }
  70. reinterpret_cast<IUnknown*>(*ppvObject)->AddRef();
  71. return(S_OK);
  72. }
  73. STDMETHODIMP_(ULONG) CHttpPostPlugin::AddRef()
  74. {
  75. return(InterlockedIncrement(&m_cRef));
  76. }
  77. STDMETHODIMP_(ULONG) CHttpPostPlugin::Release()
  78. {
  79. LONG nRefCount = InterlockedDecrement(&m_cRef);
  80. if (!nRefCount)
  81. {
  82. delete this;
  83. }
  84. return(nRefCount);
  85. }
  86. STDMETHODIMP CHttpPostPlugin::GetPluginCount( ULONG *pnCount )
  87. {
  88. if (!pnCount)
  89. {
  90. return E_POINTER;
  91. }
  92. //
  93. // Calculate the number of plugin destinations this object provides
  94. //
  95. *pnCount = m_CommunityInfoArray.Size();
  96. return S_OK;
  97. }
  98. STDMETHODIMP CHttpPostPlugin::GetPluginName( ULONG nPluginId, BSTR *pbstrName )
  99. {
  100. if (nPluginId >= m_CommunityInfoArray.Size())
  101. {
  102. return E_INVALIDARG;
  103. }
  104. if (!pbstrName)
  105. {
  106. return E_POINTER;
  107. }
  108. *pbstrName = SysAllocString(CSimpleStringConvert::WideString(CSimpleString().Format( IDS_MSN_COMMUNITIES, g_hInstance, m_CommunityInfoArray[nPluginId].CommunityName().String())));
  109. if (NULL == *pbstrName)
  110. {
  111. return E_OUTOFMEMORY;
  112. }
  113. return S_OK;
  114. }
  115. STDMETHODIMP CHttpPostPlugin::GetPluginDescription( ULONG nPluginId, BSTR *pbstrDescription )
  116. {
  117. if (nPluginId >= m_CommunityInfoArray.Size())
  118. {
  119. return E_INVALIDARG;
  120. }
  121. if (!pbstrDescription)
  122. {
  123. return E_POINTER;
  124. }
  125. *pbstrDescription = SysAllocString(CSimpleStringConvert::WideString(CSimpleString(IDS_MSN_COMMUNITIES_DESCRIPTION,g_hInstance)));
  126. if (NULL == *pbstrDescription)
  127. {
  128. return E_OUTOFMEMORY;
  129. }
  130. return S_OK;
  131. }
  132. STDMETHODIMP CHttpPostPlugin::GetPluginIcon( ULONG nPluginId, HICON *phIcon, int nWidth, int nHeight )
  133. {
  134. if (nPluginId >= m_CommunityInfoArray.Size())
  135. {
  136. return E_INVALIDARG;
  137. }
  138. if (!phIcon)
  139. {
  140. return E_POINTER;
  141. }
  142. *phIcon = NULL;
  143. HICON hIcon = reinterpret_cast<HICON>(LoadImage( g_hInstance, MAKEINTRESOURCE(IDI_MSN_COMMUNITIES), IMAGE_ICON, nWidth, nHeight, LR_DEFAULTCOLOR ));
  144. if (hIcon)
  145. {
  146. *phIcon = CopyIcon(hIcon);
  147. DestroyIcon(hIcon);
  148. }
  149. return S_OK;
  150. }
  151. STDMETHODIMP CHttpPostPlugin::OpenConnection( HWND hwndParent, ULONG nPluginId, IImageTransferPluginProgressCallback *pImageTransferPluginProgressCallback )
  152. {
  153. if (nPluginId >= m_CommunityInfoArray.Size())
  154. {
  155. return E_INVALIDARG;
  156. }
  157. if (!pImageTransferPluginProgressCallback)
  158. {
  159. return E_INVALIDARG;
  160. }
  161. m_pImageTransferPluginProgressCallback = pImageTransferPluginProgressCallback;
  162. m_nCurrentPluginId = nPluginId;
  163. if (!m_CommunityInfoArray[m_nCurrentPluginId].CommunityId().Length())
  164. {
  165. CGetCommunityUrlDialog::CData UrlData;
  166. UrlData.MruRegistryKey( CSimpleString( IDS_COMMUNITIES_MRU_KEY, g_hInstance ) );
  167. UrlData.MruRegistryValue( CSimpleString( IDS_COMMUNITIES_MRU_VALUE, g_hInstance ) );
  168. INT_PTR nResult = DialogBoxParam( g_hInstance, MAKEINTRESOURCE(IDD_GETCOMMUNITY), hwndParent, CGetCommunityUrlDialog::DialogProc, reinterpret_cast<LPARAM>(&UrlData) );
  169. if (IDOK != nResult)
  170. {
  171. return S_FALSE;
  172. }
  173. //
  174. // Save the community id
  175. //
  176. int nCurrentPluginId = m_CommunityInfoArray.Append( CCommunityInfo( UrlData.Url(), UrlData.Url() ) );
  177. if (nCurrentPluginId < 0)
  178. {
  179. return E_OUTOFMEMORY;
  180. }
  181. m_nCurrentPluginId = nCurrentPluginId;
  182. }
  183. //
  184. // Open the connection with m_HttpFilePoster
  185. //
  186. CSimpleStringAnsi straCommunityId = CSimpleStringConvert::AnsiString(m_CommunityInfoArray[m_nCurrentPluginId].CommunityId());
  187. if (straCommunityId.Length())
  188. {
  189. m_HttpFilePoster.Initialize( "http://content.communities.msn.com/isapi/fetch.dll?action=add_photo", hwndParent );
  190. m_HttpFilePoster.AddFormData( "ID_Community", straCommunityId.String());
  191. m_HttpFilePoster.AddFormData( "ID_Topic", "1" );
  192. }
  193. else
  194. {
  195. return E_OUTOFMEMORY;
  196. }
  197. return S_OK;
  198. }
  199. STDMETHODIMP CHttpPostPlugin::AddFile( BSTR bstrFilename, BSTR bstrDescription, const GUID &guidImageFormat, BOOL bDelete )
  200. {
  201. HRESULT hr;
  202. CSimpleString strFilename(CSimpleStringConvert::NaturalString(CSimpleStringWide(bstrFilename)));
  203. if (strFilename.Length())
  204. {
  205. HANDLE hFile = CreateFile( strFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
  206. if (hFile)
  207. {
  208. DWORD dwFileSize = GetFileSize( hFile, NULL );
  209. if (dwFileSize)
  210. {
  211. //
  212. // What do we get back from addfile? Are there any errors?
  213. //
  214. m_HttpFilePoster.AddFile( CStdString(CSimpleStringConvert::AnsiString(strFilename).String()),
  215. CStdString(CSimpleStringConvert::AnsiString(CSimpleStringWide(bstrDescription)).String()),
  216. dwFileSize,
  217. bDelete );
  218. hr = S_OK;
  219. }
  220. else
  221. {
  222. hr = E_FAIL;
  223. }
  224. CloseHandle(hFile);
  225. }
  226. else
  227. {
  228. hr = HRESULT_FROM_WIN32(GetLastError());
  229. }
  230. }
  231. else
  232. {
  233. hr = E_INVALIDARG;
  234. }
  235. return hr;
  236. }
  237. UINT CHttpPostPlugin::ProgressProc( CProgressInfo *pProgressInfo )
  238. {
  239. UINT bCancelled = FALSE;
  240. if (pProgressInfo)
  241. {
  242. CHttpPostPlugin *pHttpPostPlugin = reinterpret_cast<CHttpPostPlugin*>(pProgressInfo->lParam);
  243. if (pHttpPostPlugin)
  244. {
  245. CComPtr<IImageTransferPluginProgressCallback> pImageTransferPluginProgressCallback = pHttpPostPlugin->m_pImageTransferPluginProgressCallback;
  246. if (pImageTransferPluginProgressCallback)
  247. {
  248. switch (pProgressInfo->dwStatus)
  249. {
  250. case TRANSFER_SESSION_INITIATE:
  251. pImageTransferPluginProgressCallback->SetOverallPercent(0);
  252. pImageTransferPluginProgressCallback->SetFilePercent(0);
  253. break;
  254. case TRANSFER_FILE_INITATE:
  255. pImageTransferPluginProgressCallback->SetCurrentFile(pProgressInfo->dwDoneFiles);
  256. pImageTransferPluginProgressCallback->SetOverallPercent(pProgressInfo->dwOverallPercent);
  257. pImageTransferPluginProgressCallback->SetFilePercent(0);
  258. break;
  259. case TRANSFER_FILE_TRANSFERING:
  260. pImageTransferPluginProgressCallback->SetFilePercent(pProgressInfo->dwCurrentPercent);
  261. pImageTransferPluginProgressCallback->SetOverallPercent(pProgressInfo->dwOverallPercent);
  262. break;
  263. case TRANSFER_FILE_COMPLETE:
  264. pImageTransferPluginProgressCallback->SetFilePercent(100);
  265. pImageTransferPluginProgressCallback->SetOverallPercent(pProgressInfo->dwOverallPercent);
  266. break;
  267. case TRANSFER_SESSION_COMPLETE:
  268. pImageTransferPluginProgressCallback->SetFilePercent(100);
  269. pImageTransferPluginProgressCallback->SetOverallPercent(100);
  270. break;
  271. }
  272. if (!SUCCEEDED(pImageTransferPluginProgressCallback->Cancelled(&bCancelled)))
  273. {
  274. bCancelled = FALSE;
  275. }
  276. }
  277. }
  278. }
  279. return bCancelled ? 1 : 0;
  280. }
  281. STDMETHODIMP CHttpPostPlugin::TransferFiles( BSTR bstrGlobalDescription )
  282. {
  283. CProgressInfo ProgressInfo;
  284. ProgressInfo.pfnProgress = ProgressProc;
  285. ProgressInfo.lParam = reinterpret_cast<LPARAM>(this);
  286. m_HttpFilePoster.AddFormData( "Message_Body", CSimpleStringConvert::AnsiString(CSimpleStringWide(bstrGlobalDescription)).String());
  287. return m_HttpFilePoster.ForegroundUpload(&ProgressInfo);
  288. }
  289. STDMETHODIMP CHttpPostPlugin::OpenDestination(void)
  290. {
  291. CSimpleStringAnsi straCommunityId = CSimpleStringConvert::AnsiString(m_CommunityInfoArray[m_nCurrentPluginId].CommunityId());
  292. if (straCommunityId.Length())
  293. {
  294. CSimpleStringAnsi strDestinationExecuteName("http://content.communities.msn.com/isapi/fetch.dll?action=get_album&ID_Topic=1&ID_Community=");
  295. if (strDestinationExecuteName.Length())
  296. {
  297. strDestinationExecuteName += straCommunityId;
  298. if (strDestinationExecuteName.Length())
  299. {
  300. ShellExecuteA( NULL, "open", strDestinationExecuteName, "", "", SW_SHOWNORMAL );
  301. return S_OK;
  302. }
  303. }
  304. }
  305. return E_FAIL;
  306. }
  307. STDMETHODIMP CHttpPostPlugin::CloseConnection(void)
  308. {
  309. m_pImageTransferPluginProgressCallback = NULL;
  310. m_nCurrentPluginId = -1;
  311. return S_OK;
  312. }