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.

252 lines
9.5 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: RUNNPWIZ.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 6/15/2000
  12. *
  13. * DESCRIPTION: Runs the Web Publishing Wizard
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include <windows.h>
  19. #include <atlbase.h>
  20. #include "runnpwiz.h"
  21. #include <simidlst.h>
  22. #include <shellext.h>
  23. #include <shlobj.h>
  24. #include <shlguid.h>
  25. #include <shlwapi.h>
  26. #include <wiadebug.h>
  27. #include <simreg.h>
  28. namespace NetPublishingWizard
  29. {
  30. static const TCHAR *c_pszPublishWizardSuffix = TEXT(".publishwizard");
  31. static const TCHAR *c_pszClassIdPrefix = TEXT("CLSID\\");
  32. HRESULT GetClassIdOfPublishingWizard( CLSID &clsidWizard )
  33. {
  34. WIA_PUSH_FUNCTION((TEXT("GetClassIdOfPublishingWizard")));
  35. //
  36. // Assume failure
  37. //
  38. HRESULT hr = E_FAIL;
  39. //
  40. // Try to get the class id from the registry
  41. //
  42. CSimpleString strWizardClsid = CSimpleReg( HKEY_CLASSES_ROOT, c_pszPublishWizardSuffix, false, KEY_READ ).Query( TEXT(""), TEXT("") );
  43. WIA_TRACE((TEXT("strWizardClsid = %s"), strWizardClsid.String()));
  44. //
  45. // Make sure we have a string, and make sure the CLSID\ prefix is there
  46. //
  47. if (strWizardClsid.Length() && strWizardClsid.Left(lstrlen(c_pszClassIdPrefix)).ToUpper() == CSimpleString(c_pszClassIdPrefix))
  48. {
  49. //
  50. // Convert the string, minus the CLSID\, to a CLSID
  51. //
  52. hr = CLSIDFromString( const_cast<LPOLESTR>(CSimpleStringConvert::WideString(strWizardClsid.Right(strWizardClsid.Length()-6)).String()), &clsidWizard );
  53. }
  54. return hr;
  55. }
  56. HRESULT RunNetPublishingWizard( const CSimpleDynamicArray<CSimpleString> &strFiles )
  57. {
  58. WIA_PUSH_FUNCTION((TEXT("RunNetPublishingWizard")));
  59. HRESULT hr;
  60. //
  61. // Make sure there are some files in the list
  62. //
  63. if (strFiles.Size())
  64. {
  65. //
  66. // Get the CLSID of the publishing wizard from the registry
  67. //
  68. CLSID clsidWizard = IID_NULL;
  69. hr = GetClassIdOfPublishingWizard(clsidWizard);
  70. if (SUCCEEDED(hr))
  71. {
  72. WIA_PRINTGUID((clsidWizard,TEXT("Wizard class ID")));
  73. //
  74. // Get the data object for this list of files
  75. //
  76. CComPtr<IDataObject> pDataObject;
  77. hr = CreateDataObjectFromFileList( strFiles, &pDataObject );
  78. if (SUCCEEDED(hr))
  79. {
  80. //
  81. // Create the wizard
  82. //
  83. CComPtr<IDropTarget> pDropTarget;
  84. hr = CoCreateInstance( clsidWizard, NULL, CLSCTX_INPROC_SERVER, IID_IDropTarget, (void**)&pDropTarget );
  85. if (SUCCEEDED(hr))
  86. {
  87. //
  88. // Perform the drop
  89. //
  90. DWORD dwEffect = DROPEFFECT_LINK | DROPEFFECT_MOVE | DROPEFFECT_COPY;
  91. POINTL pt = { 0, 0 };
  92. hr = pDropTarget->Drop( pDataObject, 0, pt, &dwEffect );
  93. }
  94. }
  95. }
  96. }
  97. else
  98. {
  99. hr = E_INVALIDARG;
  100. }
  101. if (FAILED(hr))
  102. {
  103. WIA_PRINTHRESULT((hr,TEXT("RunNetPublishingWizard is returning")));
  104. }
  105. return hr;
  106. }
  107. HRESULT CreateDataObjectFromFileList( const CSimpleDynamicArray<CSimpleString> &strFiles, IDataObject **ppDataObject )
  108. {
  109. WIA_PUSH_FUNCTION((TEXT("CreateDataObjectFromFileList")));
  110. HRESULT hr;
  111. //
  112. // Make sure there are some files in the list
  113. //
  114. if (strFiles.Size())
  115. {
  116. //
  117. // Get the desktop folder
  118. //
  119. CComPtr<IShellFolder> pDesktopFolder;
  120. hr = SHGetDesktopFolder( &pDesktopFolder );
  121. if (SUCCEEDED(hr) && pDesktopFolder.p)
  122. {
  123. //
  124. // Allocate memory to hold the source folder name
  125. //
  126. LPTSTR pszPath = new TCHAR[strFiles[0].Length()+1];
  127. if (pszPath)
  128. {
  129. //
  130. // Copy the first filename to the folder name, and remove all but the directory
  131. //
  132. lstrcpy( pszPath, strFiles[0] );
  133. if (PathRemoveFileSpec(pszPath))
  134. {
  135. //
  136. // Get the pidl for the source folder
  137. //
  138. LPITEMIDLIST pidlFolder;
  139. hr = pDesktopFolder->ParseDisplayName( NULL, NULL, const_cast<LPWSTR>(CSimpleStringConvert::WideString(CSimpleString(pszPath)).String()), NULL, &pidlFolder, NULL );
  140. if (SUCCEEDED(hr))
  141. {
  142. WIA_TRACE((TEXT("pidlFolder: %s"), CSimpleIdList(pidlFolder).Name().String()));
  143. //
  144. // Get an IShellFolder for the source folder
  145. //
  146. CComPtr<IShellFolder> pSourceFolder;
  147. hr = pDesktopFolder->BindToObject( pidlFolder, NULL, IID_IShellFolder, (void**)&pSourceFolder );
  148. ILFree(pidlFolder);
  149. if (SUCCEEDED(hr) && pSourceFolder.p)
  150. {
  151. //
  152. // Create an array of pidls to hold the files
  153. //
  154. LPITEMIDLIST *pidlItems = new LPITEMIDLIST[strFiles.Size()];
  155. if (pidlItems)
  156. {
  157. //
  158. // Make sure we start out with NULL pidls
  159. //
  160. ZeroMemory( pidlItems, sizeof(LPITEMIDLIST)*strFiles.Size() );
  161. //
  162. // Get the pidls for the files
  163. //
  164. for (int i=0;i<strFiles.Size();i++)
  165. {
  166. //
  167. // Get the filename alone. We want relative pidls.
  168. //
  169. CSimpleString strFilename = PathFindFileName(strFiles[i]);
  170. WIA_TRACE((TEXT("strFilename = %s"), strFilename.String()));
  171. //
  172. // Create the relative pidl
  173. //
  174. hr = pSourceFolder->ParseDisplayName( NULL, NULL, const_cast<LPWSTR>(CSimpleStringConvert::WideString(strFilename).String()), NULL, pidlItems+i, NULL );
  175. if (FAILED(hr))
  176. {
  177. WIA_PRINTHRESULT((hr,TEXT("pSourceFolder->ParseDisplayName returned")));
  178. break;
  179. }
  180. }
  181. //
  182. // Make sure everything is still going OK
  183. //
  184. if (SUCCEEDED(hr))
  185. {
  186. //
  187. // Get the IDataObject for the source folder, and give it the list of file pidls
  188. //
  189. hr = pSourceFolder->GetUIObjectOf( NULL, strFiles.Size(), const_cast<LPCITEMIDLIST*>(pidlItems), IID_IDataObject, NULL, reinterpret_cast<LPVOID*>(ppDataObject) );
  190. }
  191. for (int i=0;i<strFiles.Size();i++)
  192. {
  193. if (pidlItems[i])
  194. {
  195. ILFree(pidlItems[i]);
  196. }
  197. }
  198. delete [] pidlItems;
  199. }
  200. else
  201. {
  202. hr = E_OUTOFMEMORY;
  203. }
  204. }
  205. }
  206. }
  207. else
  208. {
  209. hr = E_FAIL;
  210. }
  211. //
  212. // Free the folder name
  213. //
  214. delete[] pszPath;
  215. }
  216. else
  217. {
  218. hr = E_OUTOFMEMORY;
  219. }
  220. }
  221. }
  222. else
  223. {
  224. hr = E_INVALIDARG;
  225. }
  226. if (FAILED(hr))
  227. {
  228. WIA_PRINTHRESULT((hr,TEXT("CreateDataObjectFromFileList is returning")));
  229. }
  230. return hr;
  231. }
  232. }