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.

322 lines
8.0 KiB

  1. /****************************************************************
  2. * @doc SHROOM EXTERNAL API
  3. *
  4. * A Legsdin added autodoc headers for IITBuildCollect Interface
  5. *
  6. ****************************************************************/
  7. #include <mvopsys.h>
  8. // wwbmain.CPP: Implementation of wordwheel update interface
  9. #ifdef _DEBUG
  10. static char s_aszModule[] = __FILE__; /* For error report */
  11. #endif
  12. #include <windows.h>
  13. #include <iterror.h>
  14. #include <itpropl.h>
  15. #include <ccfiles.h>
  16. #include <orkin.h>
  17. #include <atlinc.h>
  18. #include "..\svutil.h"
  19. #include "gpumain.h"
  20. CITGroupUpdate::~CITGroupUpdate()
  21. {
  22. (void)Close();
  23. }
  24. STDMETHODIMP CITGroupUpdate::GetTypeString(LPWSTR pPrefix, DWORD *pLen)
  25. {
  26. DWORD dwLen = (DWORD) WSTRLEN (SZ_GP_STORAGE) + 1;
  27. if (NULL == pPrefix)
  28. {
  29. *pLen = dwLen;
  30. return S_OK;
  31. }
  32. if (pLen && *pLen < dwLen)
  33. {
  34. *pLen = dwLen;
  35. return S_OK;
  36. }
  37. if (pLen)
  38. *pLen = dwLen;
  39. WSTRCPY (pPrefix, SZ_GP_STORAGE);
  40. return S_OK;
  41. } /* GetTypeString */
  42. STDMETHODIMP CITGroupUpdate::SetConfigInfo
  43. (IITDatabase *piitdb, VARARG vaParams)
  44. {
  45. if(vaParams.dwArgc)
  46. m_fGroupNot = !WSTRICMP(L"GROUP_NOT", (LPWSTR)vaParams.Argv[0]);
  47. return S_OK;
  48. } /* SetConfigInfo */
  49. STDMETHODIMP CITGroupUpdate::InitHelperInstance(
  50. DWORD dwHelperObjInstance,
  51. IITDatabase *pITDatabase, DWORD dwCodePage,
  52. LCID lcid, VARARG vaDword, VARARG vaString
  53. )
  54. {
  55. if (FALSE == m_fInitialized)
  56. return SetErrReturn(E_NOTINIT);
  57. return S_OK;
  58. } /* InitHelperInstance */
  59. STDMETHODIMP CITGroupUpdate::SetEntry(LPCWSTR szDest, IITPropList *pPropList)
  60. {
  61. if (FALSE == m_fInitialized)
  62. return SetErrReturn(E_NOTINIT);
  63. HRESULT hr;
  64. // The only property we are interested in is STDPROP_UID
  65. CProperty UidProp;
  66. if (FAILED(hr = pPropList->Get(STDPROP_UID, UidProp))
  67. || TYPE_STRING == UidProp.dwType)
  68. return SetErrReturn(E_INVALIDARG);
  69. // This could be a pointer to a UID or a DWORD UID
  70. DWORD dwUID;
  71. if (TYPE_VALUE == UidProp.dwType)
  72. dwUID = UidProp.dwValue;
  73. else if (TYPE_POINTER == UidProp.dwType)
  74. dwUID = *((LPDWORD&)UidProp.lpvData);
  75. // Save highest UID
  76. if (dwUID > m_dwMaxUID)
  77. m_dwMaxUID = dwUID;
  78. DWORD dwWritten;
  79. WriteFile (m_hTempFile, &dwUID, sizeof (dwUID), &dwWritten, NULL);
  80. if (dwWritten != sizeof (dwUID))
  81. return SetErrReturn(E_FILEWRITE);
  82. m_fIsDirty = TRUE;
  83. return S_OK;
  84. } /* SetEntry */
  85. STDMETHODIMP CITGroupUpdate::Close(void)
  86. {
  87. if (m_pStorage)
  88. {
  89. m_pStorage->Release();
  90. m_pStorage = NULL;
  91. }
  92. DeleteFile (m_szTempFile);
  93. m_dwMaxTitleUID = 0;
  94. m_fInitialized = FALSE;
  95. return S_OK;
  96. } /* Close */
  97. /************************************************************************
  98. * @method STDMETHODIMP | IITBuildCollect | SetBuildStats |
  99. * Gives the build object information about the title.
  100. *
  101. * @parm ITBuildObjectControlInfo | &itboci| A structure consisting of
  102. * a DWORD dwSize set to the size of the structure, and a DWORD dwMaxUID that
  103. * represents the highest UID authored for the title.
  104. *
  105. * @rvalue S_OK | The operation completed successfully
  106. * @rvalue E_NOTINIT | The object has not been initialized
  107. * @rvalue E_INVALIDARG | dwSize cannot be zero
  108. *
  109. * @comm Call this method at the end of the build process before the object
  110. * is persisted.
  111. ************************************************************************/
  112. STDMETHODIMP CITGroupUpdate::SetBuildStats(ITBuildObjectControlInfo &itboci)
  113. {
  114. if (FALSE == m_fInitialized)
  115. return SetErrReturn(E_NOTINIT);
  116. if (0 == itboci.dwSize)
  117. return SetErrReturn(E_INVALIDARG);
  118. #ifdef _DEBUG // {
  119. if(itboci.dwSize != 8)
  120. ITASSERT(0);
  121. #endif // _DEBUG }
  122. m_dwMaxTitleUID = itboci.dwMaxUID;
  123. return S_OK;
  124. } /* SetControlInfo */
  125. STDMETHODIMP CITGroupUpdate::InitNew(IStorage *pStg)
  126. {
  127. if (NULL == pStg)
  128. return SetErrReturn(E_INVALIDARG);
  129. if (m_fInitialized)
  130. return SetErrReturn(CO_E_ALREADYINITIALIZED);
  131. // Create the temp file
  132. char szTempPath [_MAX_PATH + 1];
  133. if (0 == GetTempPath(_MAX_PATH, szTempPath))
  134. return SetErrReturn(E_FILECREATE);
  135. if (0 == GetTempFileName(szTempPath, "GPU", 0, m_szTempFile))
  136. return SetErrReturn(E_FILECREATE);
  137. m_hTempFile = CreateFile
  138. (m_szTempFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS,
  139. FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
  140. if (INVALID_HANDLE_VALUE == m_hTempFile)
  141. return SetErrReturn(E_FILECREATE);
  142. m_fGroupNot = FALSE;
  143. m_dwMaxUID = 0;
  144. m_pStorage = pStg;
  145. pStg->AddRef();
  146. m_fIsDirty = FALSE;
  147. m_fInitialized = TRUE;
  148. return S_OK;
  149. } /* InitNew */
  150. STDMETHODIMP CITGroupUpdate::Save(IStorage *pStgSave, BOOL fSameAsLoad)
  151. {
  152. HRESULT hr;
  153. LPDWORD pInput, pCur;
  154. _LPGROUP pGroup = NULL;
  155. if (FALSE == m_fInitialized)
  156. return SetErrReturn(E_NOTINIT);
  157. if (NULL == pStgSave)
  158. return SetErrReturn(E_INVALIDARG);
  159. DWORD dwSize = GetFileSize(m_hTempFile, NULL);
  160. if (0 == dwSize)
  161. {
  162. HFPB hfpb = NULL;
  163. pGroup = GroupInitiate (m_dwMaxUID + 1, &hr);
  164. if (SUCCEEDED(hr))
  165. {
  166. // Group code only works if you add at least one item,
  167. // so we add one and remove it
  168. GroupAddItem(pGroup, 0);
  169. GroupRemoveItem(pGroup, 0);
  170. hfpb = (HFPB)FpbFromHfs (pStgSave, &hr);
  171. }
  172. if (SUCCEEDED(hr))
  173. hr = GroupFileBuild (hfpb, SZ_GROUP_MAIN_A, pGroup);
  174. if (hfpb != NULL)
  175. FreeHfpb(hfpb);
  176. GroupFree(pGroup);
  177. return S_OK;
  178. }
  179. CloseHandle (m_hTempFile);
  180. pCur = pInput = (LPDWORD)MapSequentialReadFile(m_szTempFile, &dwSize);
  181. if (NULL == pInput)
  182. {
  183. SetErrCode(&hr, E_FILEREAD);
  184. exit0:
  185. UnmapViewOfFile (pInput);
  186. // Open a handle to the temp file in case we want to add more
  187. // items later
  188. m_hTempFile = CreateFile
  189. (m_szTempFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING,
  190. FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
  191. SetFilePointer(m_hTempFile, 0, NULL, FILE_END);
  192. if (pGroup)
  193. GroupFree (pGroup);
  194. return hr;
  195. }
  196. LPDWORD pEnd = pInput + (dwSize / sizeof (DWORD));
  197. // Initialize the group info structure for this group
  198. if (m_fGroupNot && m_dwMaxTitleUID > m_dwMaxUID)
  199. // If the group is to be inverted we must grow the size to match
  200. // the maximum UID for the title not just for this group.
  201. pGroup = GroupInitiate (m_dwMaxTitleUID + 1, &hr);
  202. else
  203. pGroup = GroupInitiate (m_dwMaxUID + 1, &hr);
  204. if (NULL == pGroup)
  205. goto exit0;
  206. while (pEnd != pCur)
  207. {
  208. if (FAILED(hr = GroupAddItem (pGroup, *pCur++)))
  209. goto exit0;
  210. }
  211. if (m_fGroupNot)
  212. {
  213. _LPGROUP pOldGroup = pGroup;
  214. pGroup = GroupNot (pGroup, &hr);
  215. GroupFree (pOldGroup);
  216. }
  217. HFPB hfpb;
  218. if (NULL == (hfpb = (HFPB)FpbFromHfs (pStgSave, &hr)))
  219. goto exit0;
  220. hr = GroupFileBuild (hfpb, SZ_GROUP_MAIN_A, pGroup);
  221. FreeHfpb(hfpb);
  222. goto exit0;
  223. } /* Save */
  224. STDMETHODIMP CITGroupUpdate::GetClassID(CLSID *pClsID)
  225. {
  226. if (NULL == pClsID
  227. || IsBadWritePtr(pClsID, sizeof(CLSID)))
  228. return SetErrReturn(E_INVALIDARG);
  229. *pClsID = CLSID_IITGroupUpdate;
  230. return S_OK;
  231. } /* GetClassID */
  232. inline STDMETHODIMP CITGroupUpdate::IsDirty(void)
  233. {
  234. return m_fIsDirty ? S_OK : S_FALSE;
  235. } /* IsDirty */
  236. inline STDMETHODIMP CITGroupUpdate::Load(IStorage *pStg)
  237. {
  238. return SetErrReturn(E_NOTIMPL);
  239. } /* Load */
  240. STDMETHODIMP CITGroupUpdate::SaveCompleted(IStorage *pStgNew)
  241. {
  242. if (pStgNew)
  243. {
  244. if (!m_pStorage)
  245. return SetErrReturn(E_UNEXPECTED);
  246. m_pStorage->Release();
  247. (m_pStorage = pStgNew)->AddRef();
  248. }
  249. m_fIsDirty = FALSE;
  250. return S_OK;
  251. } /* SaveCompleted */
  252. inline STDMETHODIMP CITGroupUpdate::HandsOffStorage(void)
  253. {
  254. return S_OK;
  255. } /* HandsOffStorage */