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.

295 lines
7.0 KiB

  1. // wfumain.CPP: Implementation of wordwheel update interface
  2. #include <mvopsys.h>
  3. #ifdef _DEBUG
  4. static char s_aszModule[] = __FILE__; /* For error report */
  5. #endif
  6. #include <windows.h>
  7. #include <iterror.h>
  8. #include <itpropl.h>
  9. #include <ccfiles.h>
  10. #include <atlinc.h>
  11. #include <itdb.h>
  12. #include <itgroup.h>
  13. #include <itww.h>
  14. #include <itrs.h>
  15. #include <groups.h>
  16. //#include "..\svutil.h"
  17. #include "wfumain.h"
  18. CITWWFilterUpdate::~CITWWFilterUpdate()
  19. {
  20. (void)Close();
  21. }
  22. STDMETHODIMP CITWWFilterUpdate::GetTypeString(LPWSTR pPrefix, DWORD *pLen)
  23. {
  24. DWORD dwLen = (DWORD) WSTRLEN (SZ_GP_STORAGE) + 1;
  25. if (NULL == pPrefix)
  26. {
  27. *pLen = dwLen;
  28. return S_OK;
  29. }
  30. if (pLen && *pLen < dwLen)
  31. {
  32. *pLen = dwLen;
  33. return S_OK;
  34. }
  35. if (pLen)
  36. *pLen = dwLen;
  37. WSTRCPY (pPrefix, SZ_GP_STORAGE);
  38. return S_OK;
  39. } /* GetTypeString */
  40. STDMETHODIMP CITWWFilterUpdate::SetConfigInfo
  41. (IITDatabase *piitdb, VARARG vaParams)
  42. {
  43. if(m_fConfigured == TRUE)
  44. return SetErrReturn(E_ALREADYINIT);
  45. if (FALSE == m_fInitialized)
  46. return SetErrReturn(E_NOTINIT);
  47. if(vaParams.dwArgc < 2 || NULL == piitdb)
  48. return SetErrReturn(E_INVALIDARG);
  49. (m_piitdb = piitdb)->AddRef();
  50. WSTRCPY(m_wstrSrcWheel, (LPWSTR)vaParams.Argv[0]);
  51. WSTRCPY(m_wstrSrcGroup, (LPWSTR)vaParams.Argv[1]);
  52. if(vaParams.dwArgc == 3)
  53. m_fGroupNot = !WSTRICMP(L"GROUP_NOT", (LPWSTR)vaParams.Argv[2]);
  54. else
  55. m_fGroupNot = FALSE;
  56. m_fConfigured = TRUE;
  57. return S_OK;
  58. } /* SetConfigInfo */
  59. /********************************************************************
  60. * @method HRESULT WINAPI | CITWWFilterUpdate | InitiateUpdate |
  61. * Creates and initiates a structure to allow for the creation of word wheels.
  62. * This method must be called before any others in this object.
  63. *
  64. * @rvalue E_FAIL | The object is already initialized or file create failed
  65. *
  66. * @xref <om.CancelUpdate>
  67. * @xref <om.CompleteUpdate>
  68. * @xref <om.SetEntry>
  69. *
  70. * @comm
  71. ********************************************************************/
  72. STDMETHODIMP CITWWFilterUpdate::InitHelperInstance(
  73. DWORD dwHelperObjInstance,
  74. IITDatabase *pITDatabase, DWORD dwCodePage,
  75. LCID lcid, VARARG vaDword, VARARG vaString
  76. )
  77. {
  78. if (FALSE == m_fInitialized)
  79. return SetErrReturn(E_NOTINIT);
  80. return S_OK;
  81. } /* InitHelperInstance */
  82. STDMETHODIMP CITWWFilterUpdate::SetEntry(LPCWSTR szDest, IITPropList *pPropList)
  83. {
  84. if (FALSE == m_fInitialized)
  85. return SetErrReturn(E_NOTINIT);
  86. return S_OK;
  87. } /* SetEntry */
  88. STDMETHODIMP CITWWFilterUpdate::Close(void)
  89. {
  90. if(!m_fInitialized)
  91. return S_OK;
  92. if(TRUE == m_fConfigured)
  93. m_piitdb->Release();
  94. m_fConfigured = FALSE;
  95. m_fInitialized = FALSE;
  96. return S_OK;
  97. } /* Close */
  98. STDMETHODIMP CITWWFilterUpdate::InitNew(IStorage *pStg)
  99. {
  100. m_fIsDirty = FALSE;
  101. m_fInitialized = TRUE;
  102. m_fConfigured = FALSE;
  103. return S_OK;
  104. } /* InitNew */
  105. STDMETHODIMP CITWWFilterUpdate::Save(IStorage *pStgSave, BOOL fSameAsLoad)
  106. {
  107. HRESULT hr;
  108. LONG lMaxItems;
  109. IITGroup *pSrcGroup = NULL, *pGroup = NULL;
  110. IITWordWheel *pSrcWheel = NULL;
  111. IITResultSet *pResultSet= NULL;
  112. _LPGROUP lpGroup;
  113. if (FALSE == m_fInitialized || FALSE == m_fConfigured)
  114. return SetErrReturn(E_NOTINIT);
  115. // Open Source Group
  116. if (FAILED (hr = CoCreateInstance (CLSID_IITGroupLocal, NULL,
  117. CLSCTX_INPROC_SERVER, IID_IITGroup, (void**)&pSrcGroup)))
  118. goto cleanup;
  119. if (FAILED (hr = pSrcGroup->Open(m_piitdb, m_wstrSrcGroup)))
  120. goto cleanup;
  121. // Open Source Wheel
  122. if (FAILED (hr = CoCreateInstance (CLSID_IITWordWheelLocal, NULL,
  123. CLSCTX_INPROC_SERVER, IID_IITWordWheel, (void**)&pSrcWheel)))
  124. goto cleanup;
  125. if (FAILED (hr = pSrcWheel->Open (m_piitdb, m_wstrSrcWheel, 0)))
  126. goto cleanup;
  127. pSrcWheel->Count(&lMaxItems);
  128. if (!lMaxItems)
  129. {
  130. SetErrCode(&hr, E_FAIL);
  131. goto cleanup;
  132. }
  133. // Create destination group
  134. if (FAILED (hr = CoCreateInstance (CLSID_IITGroupLocal, NULL,
  135. CLSCTX_INPROC_SERVER, IID_IITGroup, (void**)&pGroup)))
  136. goto cleanup;
  137. pGroup->Initiate ((DWORD)lMaxItems);
  138. lpGroup = (_LPGROUP)pGroup->GetLocalImageOfGroup();
  139. // Create Result Set
  140. if (FAILED (hr = CoCreateInstance (CLSID_IITResultSet, NULL,
  141. CLSCTX_INPROC_SERVER, IID_IITResultSet, (void**)&pResultSet)))
  142. goto cleanup;
  143. if (FAILED (hr = pResultSet->Add (STDPROP_UID, (DWORD)0, PRIORITY_NORMAL)))
  144. goto cleanup;
  145. // This is the real work.
  146. // The result group will have a bit set for every entry in the word wheel
  147. // that has a UID that is set in the source group
  148. do
  149. {
  150. DWORD dwOcc;
  151. --lMaxItems;
  152. // Get all occurence info for this entry
  153. pSrcWheel->GetDataCount(lMaxItems, &dwOcc);
  154. pResultSet->ClearRows();
  155. //pResultSet->SetMaxRows (dwOcc);
  156. pSrcWheel->GetData(lMaxItems, pResultSet);
  157. for (LONG loop = 0; loop < (LONG)dwOcc; ++loop)
  158. {
  159. CProperty prop;
  160. // Get UID
  161. if (FAILED (hr = pResultSet->Get(loop, 0, prop)))
  162. goto cleanup;
  163. // Lookup UID is source group
  164. // IsBitSet returns S_OK if bit is set or S_FALSE if not
  165. if (S_OK == pSrcGroup->IsBitSet (prop.dwValue))
  166. {
  167. GroupAddItem (lpGroup, lMaxItems);
  168. break;
  169. }
  170. }
  171. } while (lMaxItems);
  172. if (TRUE == m_fGroupNot)
  173. pGroup->Not();
  174. HFPB hfpb;
  175. if (NULL == (hfpb = (HFPB)FpbFromHfs (pStgSave, &hr)))
  176. goto cleanup;
  177. hr = GroupFileBuild (hfpb, SZ_GROUP_MAIN_A, lpGroup);
  178. pStgSave->Commit(STGC_DEFAULT);
  179. FreeHfpb(hfpb);
  180. cleanup:
  181. if (pResultSet)
  182. {
  183. pResultSet->Free();
  184. pResultSet->Release();
  185. }
  186. if (pSrcGroup)
  187. {
  188. pSrcGroup->Free();
  189. pSrcGroup->Release();
  190. }
  191. if (pSrcWheel)
  192. {
  193. pSrcWheel->Close();
  194. pSrcWheel->Release();
  195. }
  196. if (pGroup)
  197. {
  198. pGroup->Free();
  199. pGroup->Release();
  200. }
  201. return hr;
  202. } /* Save */
  203. STDMETHODIMP CITWWFilterUpdate::GetClassID(CLSID *pClsID)
  204. {
  205. if (NULL == pClsID
  206. || IsBadWritePtr(pClsID, sizeof(CLSID)))
  207. return SetErrReturn(E_INVALIDARG);
  208. *pClsID = CLSID_IITWWFilterBuild;
  209. return S_OK;
  210. } /* GetClassID */
  211. inline STDMETHODIMP CITWWFilterUpdate::IsDirty(void)
  212. {
  213. return m_fIsDirty ? S_OK : S_FALSE;
  214. } /* IsDirty */
  215. inline STDMETHODIMP CITWWFilterUpdate::Load(IStorage *pStg)
  216. {
  217. return SetErrReturn(E_NOTIMPL);
  218. } /* Load */
  219. STDMETHODIMP CITWWFilterUpdate::SaveCompleted(IStorage *pStgNew)
  220. {
  221. if (pStgNew)
  222. {
  223. if (!m_pStorage)
  224. return SetErrReturn(E_UNEXPECTED);
  225. m_pStorage->Release();
  226. (m_pStorage = pStgNew)->AddRef();
  227. }
  228. m_fIsDirty = FALSE;
  229. return S_OK;
  230. } /* SaveCompleted */
  231. inline STDMETHODIMP CITWWFilterUpdate::HandsOffStorage(void)
  232. {
  233. return S_OK;
  234. } /* HandsOffStorage */