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.

301 lines
8.0 KiB

  1. // wwumain.cpp: Implementation of wordwheel update interface
  2. #ifdef _DEBUG
  3. static char s_aszModule[] = __FILE__; /* For error report */
  4. #endif
  5. #include <windows.h>
  6. #include <itcc.h>
  7. #include <iterror.h>
  8. #include <ccfiles.h>
  9. #include <atlinc.h>
  10. #include <mvopsys.h>
  11. #include <_mvutil.h>
  12. #include <itdb.h>
  13. #include <itsortid.h>
  14. #include "wwumain.h"
  15. CITWordWheelUpdate::CITWordWheelUpdate()
  16. {
  17. m_fInitialized = FALSE;
  18. m_piitskSortKey = NULL;
  19. m_pStorage = NULL;
  20. }
  21. CITWordWheelUpdate::~CITWordWheelUpdate()
  22. {
  23. (void)Close();
  24. } /* Destructor */
  25. HRESULT CITWordWheelUpdate::Close(void)
  26. {
  27. if (FALSE == m_fInitialized)
  28. return S_OK;
  29. if (m_hTempFile)
  30. {
  31. CloseHandle(m_hTempFile);
  32. DeleteFile(m_szTempFile);
  33. m_hTempFile = NULL;
  34. }
  35. if (m_hGlobalPropTempFile)
  36. {
  37. CloseHandle(m_hGlobalPropTempFile);
  38. DeleteFile(m_szGlobalPropTempFile);
  39. m_hGlobalPropTempFile = NULL;
  40. }
  41. if (m_lpbOccHeader)
  42. delete m_lpbOccHeader;
  43. if (m_lpbKeyHeader)
  44. delete m_lpbKeyHeader;
  45. if (m_pStorage)
  46. {
  47. m_pStorage->Release();
  48. m_pStorage = NULL;
  49. }
  50. if(m_piitskSortKey)
  51. {
  52. m_piitskSortKey->Release();
  53. m_piitskSortKey = NULL;
  54. }
  55. m_fInitialized = FALSE;
  56. return S_OK;
  57. } /* Close */
  58. STDMETHODIMP CITWordWheelUpdate::GetTypeString(LPWSTR pPrefix, DWORD *pLen)
  59. {
  60. DWORD dwLen = (DWORD) WSTRLEN (SZ_WW_STORAGE) + 1;
  61. if (NULL == pPrefix)
  62. {
  63. *pLen = dwLen;
  64. return S_OK;
  65. }
  66. if (pLen && *pLen < dwLen)
  67. {
  68. *pLen = dwLen;
  69. return S_OK;
  70. }
  71. if (pLen)
  72. *pLen = dwLen;
  73. WSTRCPY (pPrefix, SZ_WW_STORAGE);
  74. return S_OK;
  75. }
  76. STDMETHODIMP CITWordWheelUpdate::SetConfigInfo
  77. (IITDatabase *piitdb, VARARG vaParams)
  78. {
  79. return S_OK;
  80. }
  81. /********************************************************************
  82. * @method HRESULT WINAPI | CITWordWheelUpdate | InitHelperInstance |
  83. * Creates and initiates a structure to allow for the creation of word wheels.
  84. * This method must be called before any others in this object.
  85. *
  86. * @rvalue E_FAIL | The object is already initialized or file create failed
  87. *
  88. * @xref <om.CancelUpdate>
  89. * @xref <om.CompleteUpdate>
  90. * @xref <om.SetEntry>
  91. *
  92. * @comm
  93. ********************************************************************/
  94. STDMETHODIMP CITWordWheelUpdate::InitHelperInstance
  95. (DWORD dwHelperObjInstance,
  96. IITDatabase *pITDatabase,
  97. DWORD dwCodePage,
  98. LCID lcid,
  99. VARARG vaDword,
  100. VARARG vaString)
  101. {
  102. if (FALSE == m_fInitialized)
  103. return SetErrReturn(E_NOTINIT);
  104. HRESULT hr;
  105. // Get the Sorter Object
  106. if (FAILED(hr = pITDatabase->GetObject
  107. (dwHelperObjInstance, IID_IITSortKey, (void **)&m_piitskSortKey)))
  108. return hr;
  109. IITSortKeyConfig *pSortKeyConfig;
  110. if (FAILED(hr = pITDatabase->GetObject (dwHelperObjInstance,
  111. IID_IITSortKeyConfig, (void **)&pSortKeyConfig)))
  112. // This object doesn't support IITSortKeyConfig.
  113. return S_OK;
  114. // We should have at least 1 param (key type) specified
  115. if (!vaDword.dwArgc)
  116. SetErrCode(&hr, E_INVALIDARG);
  117. // Configure the sort key object
  118. if(SUCCEEDED(hr))
  119. hr = pSortKeyConfig->SetLocaleInfo(dwCodePage, lcid);
  120. if (SUCCEEDED(hr) || hr == E_NOTIMPL)
  121. hr = pSortKeyConfig->SetKeyType(*(LPDWORD)vaDword.Argv);
  122. if ((SUCCEEDED(hr) || hr == E_NOTIMPL)
  123. && vaDword.dwArgc >= 2)
  124. hr = pSortKeyConfig->SetControlInfo(*(LPDWORD)(vaDword.Argv + 1), 0);
  125. pSortKeyConfig->Release();
  126. if (SUCCEEDED(hr) || hr == E_NOTIMPL)
  127. {
  128. // Fill out BTREE structure
  129. MEMSET(&m_btParams, 0, sizeof (BTREE_PARAMS));
  130. m_btParams.cbBlock = CBKWBLOCKSIZE;
  131. m_btParams.bFlags = fFSReadWrite;
  132. m_btParams.dwCodePageID = dwCodePage;
  133. m_btParams.lcid = lcid;
  134. m_btParams.dwExtSortInstID = dwHelperObjInstance;
  135. m_btParams.dwExtSortKeyType = *(LPDWORD)(vaDword.Argv);
  136. m_btParams.rgchFormat[0] = KT_EXTSORT;
  137. m_btParams.rgchFormat[1] = '4';
  138. m_btParams.rgchFormat[2] = '4';
  139. m_btParams.rgchFormat[3] = '\0';
  140. }
  141. return (hr == E_NOTIMPL ? S_OK : hr);
  142. } /* InitHelperInstance */
  143. STDMETHODIMP CITWordWheelUpdate::SetEntry
  144. (LPCWSTR szDest, IITPropList *pPropList)
  145. {
  146. HRESULT hr;
  147. CProperty KeyProp;
  148. DWORD dwWritten, dwSize;
  149. LPBYTE pHeader;
  150. DWORD cbHeader, *pMaxPropData;
  151. // UNDONE: fix this!!!!!!!!!!!!!!
  152. char pUserBuffer[4*1024]; // see COUNT_WWDATASIZE in wwbuild
  153. if (FALSE == m_fInitialized || NULL == m_piitskSortKey)
  154. return SetErrReturn(E_NOTINIT);
  155. m_fIsDirty = TRUE;
  156. if (NULL == szDest)
  157. szDest = SZ_WWDEST_OCC;
  158. // Is this a global property list?
  159. if (!WSTRICMP(szDest, SZ_WWDEST_GLOBAL))
  160. {
  161. ULARGE_INTEGER ulSize;
  162. // Write to global temp file
  163. pPropList->GetSizeMax(&ulSize);
  164. if (ulSize.QuadPart > 4*1024)
  165. return SetErrReturn(E_OUTOFMEMORY);
  166. // Write property list
  167. pPropList->SaveToMem(pUserBuffer, ulSize.LowPart);
  168. WriteFile(m_hGlobalPropTempFile,
  169. pUserBuffer, ulSize.LowPart, &dwWritten, NULL);
  170. if (ulSize.LowPart != dwWritten)
  171. return SetErrReturn(E_FILEWRITE);
  172. m_dwGlobalPropSize += ulSize.LowPart;
  173. return S_OK;
  174. }
  175. if (FAILED(hr = pPropList->Get(STDPROP_SORTKEY, KeyProp)))
  176. return SetErrReturn(E_NOKEYPROP);
  177. // Don't save the KEY in the property list
  178. pPropList->SetPersist(STDPROP_SORTKEY, FALSE);
  179. // Determine property destination
  180. char wcType;
  181. if (!WSTRICMP(szDest, SZ_WWDEST_KEY))
  182. {
  183. wcType = C_PROPDEST_KEY;
  184. // Is this the first entry?
  185. if (NULL == m_lpbKeyHeader)
  186. {
  187. pPropList->GetHeaderSize (m_cbKeyHeader);
  188. m_lpbKeyHeader = new BYTE[m_cbKeyHeader];
  189. pPropList->SaveHeader (m_lpbKeyHeader, m_cbKeyHeader);
  190. }
  191. pHeader = m_lpbKeyHeader;
  192. cbHeader = m_cbKeyHeader;
  193. pMaxPropData = &m_cbMaxKeyData;
  194. }
  195. else
  196. {
  197. wcType = C_PROPDEST_OCC;
  198. // Is this the first entry?
  199. if (NULL == m_lpbOccHeader)
  200. {
  201. pPropList->GetHeaderSize (m_cbOccHeader);
  202. m_lpbOccHeader = new BYTE[m_cbOccHeader];
  203. pPropList->SaveHeader (m_lpbOccHeader, m_cbOccHeader);
  204. }
  205. pHeader = m_lpbOccHeader;
  206. cbHeader = m_cbOccHeader;
  207. pMaxPropData = &m_cbMaxOccData;
  208. }
  209. pPropList->GetDataSize(pHeader, cbHeader, dwSize);
  210. if (dwSize > 4 * 1024)
  211. return SetErrReturn(E_OUTOFMEMORY);
  212. // Write key
  213. WriteFile(m_hTempFile, &KeyProp.cbData, sizeof (DWORD), &dwWritten, NULL);
  214. if (dwWritten != sizeof (DWORD))
  215. return SetErrReturn(E_FILEWRITE);
  216. WriteFile(m_hTempFile, KeyProp.lpvData, KeyProp.cbData, &dwWritten, NULL);
  217. if (dwWritten != KeyProp.cbData)
  218. return SetErrReturn(E_FILEWRITE);
  219. // Write Type char
  220. WriteFile(m_hTempFile, &wcType, sizeof (char), &dwWritten, NULL);
  221. if (dwWritten != sizeof (char))
  222. return SetErrReturn(E_FILEWRITE);
  223. // Write (tertiary) sort order value
  224. ++m_dwEntryCount;
  225. WriteFile(m_hTempFile, &m_dwEntryCount, sizeof (DWORD), &dwWritten, NULL);
  226. if (dwWritten != sizeof (DWORD))
  227. return SetErrReturn(E_FILEWRITE);
  228. // Write property list size
  229. WriteFile(m_hTempFile, &dwSize, sizeof (DWORD), &dwWritten, NULL);
  230. if (dwWritten != sizeof (DWORD))
  231. return SetErrReturn(E_FILEWRITE);
  232. // Write property list if it exists
  233. if (dwSize)
  234. {
  235. if (dwSize > *pMaxPropData)
  236. *pMaxPropData = dwSize;
  237. // Write out custom properties
  238. pPropList->SaveData(pHeader, cbHeader, pUserBuffer, dwSize);
  239. WriteFile(m_hTempFile, pUserBuffer, dwSize, &dwWritten, NULL);
  240. if (dwSize != dwWritten)
  241. return SetErrReturn(E_FILEWRITE);
  242. }
  243. #if 0
  244. WriteFile(m_hTempFile, "\n", strlen("\n"), &dwWritten, NULL);
  245. if (STRLEN("\n") != dwWritten)
  246. return SetErrReturn(E_FILEWRITE);
  247. #endif
  248. return S_OK;
  249. } /* SetEntry */