Leaked source code of windows server 2003
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.

298 lines
7.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: layoutui.cxx
  7. //
  8. // Contents: debug UI implementation on Docfile Layout Tool
  9. //
  10. // Classes: CLayoutApp
  11. //
  12. // Functions:
  13. //
  14. // History: 07-Apr-96 SusiA Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "layoutui.hxx"
  18. #if DBG==1
  19. BOOL CompareStatStg(STATSTG *pstat1, STATSTG *pstat2)
  20. {
  21. if (lstrcmpW(pstat1->pwcsName, pstat2->pwcsName) != 0)
  22. {
  23. return FALSE;
  24. }
  25. if (pstat1->type != pstat2->type)
  26. {
  27. return FALSE;
  28. }
  29. if (!IsEqualIID(pstat1->clsid, pstat2->clsid))
  30. {
  31. return FALSE;
  32. }
  33. if (pstat1->type == STGTY_STREAM)
  34. {
  35. if ((pstat1->cbSize).QuadPart != (pstat2->cbSize).QuadPart)
  36. {
  37. return FALSE;
  38. }
  39. }
  40. //Also check statebits and timestamps?
  41. return TRUE;
  42. }
  43. BOOL CompareStreams(IStream *pstm1, IStream *pstm2)
  44. {
  45. const ULONG BUFSIZE = 4096;
  46. BYTE buffer1[BUFSIZE];
  47. BYTE buffer2[BUFSIZE];
  48. ULONG cbRead1;
  49. ULONG cbRead2;
  50. STATSTG stat1;
  51. STATSTG stat2;
  52. LARGE_INTEGER li;
  53. li.QuadPart = 0;
  54. pstm1->Seek(li, STREAM_SEEK_SET, NULL);
  55. pstm2->Seek(li, STREAM_SEEK_SET, NULL);
  56. do
  57. {
  58. SCODE sc;
  59. sc = pstm1->Read(buffer1, BUFSIZE, &cbRead1);
  60. if (FAILED(sc))
  61. {
  62. return FALSE;
  63. }
  64. sc = pstm2->Read(buffer2, BUFSIZE, &cbRead2);
  65. if (FAILED(sc))
  66. {
  67. return FALSE;
  68. }
  69. if ((cbRead1 != cbRead2) || (memcmp(buffer1, buffer2, cbRead1) != 0))
  70. {
  71. return FALSE;
  72. }
  73. }
  74. while (cbRead1 == BUFSIZE);
  75. return TRUE;
  76. }
  77. BOOL CompareStorages(IStorage *pstg1, IStorage *pstg2)
  78. {
  79. SCODE sc1, sc2, sc;
  80. HRESULT hr = TRUE;
  81. IStorage *pstgChild1,
  82. *pstgChild2;
  83. IStream *pstmChild1,
  84. *pstmChild2;
  85. IEnumSTATSTG *penum1 = NULL,
  86. *penum2 = NULL;
  87. STATSTG stat1,
  88. stat2;
  89. pstg1->EnumElements(0, 0, 0, &penum1);
  90. if (!penum1)
  91. return FALSE;
  92. pstg2->EnumElements(0, 0, 0, &penum2);
  93. if (!penum2)
  94. {
  95. penum1->Release();
  96. return FALSE;
  97. }
  98. do
  99. {
  100. ULONG celtFetched1, celtFetched2;
  101. sc1 = penum1->Next(1, &stat1, &celtFetched1);
  102. if (FAILED(sc1))
  103. {
  104. hr = FALSE;
  105. goto Done;
  106. }
  107. sc2 = penum2->Next(1, &stat2, &celtFetched2);
  108. if (FAILED(sc2) || (celtFetched1 != celtFetched2) || (sc1 != sc2))
  109. {
  110. hr = FALSE;
  111. goto Done;
  112. }
  113. if (celtFetched1 == 0)
  114. {
  115. // we are done
  116. hr = TRUE;
  117. goto Done;
  118. }
  119. if (!CompareStatStg(&stat1, &stat2))
  120. {
  121. hr = FALSE;
  122. goto Done;
  123. }
  124. //Items have compared OK so far. Now compare contents.
  125. if (stat1.type == STGTY_STREAM)
  126. {
  127. sc = pstg1->OpenStream(stat1.pwcsName,
  128. 0,
  129. STGM_DIRECT |
  130. STGM_READ | STGM_SHARE_EXCLUSIVE,
  131. 0,
  132. &pstmChild1);
  133. if (FAILED(sc))
  134. {
  135. hr = FALSE;
  136. goto Done;
  137. }
  138. sc = pstg2->OpenStream(stat2.pwcsName,
  139. 0,
  140. STGM_DIRECT |
  141. STGM_READ | STGM_SHARE_EXCLUSIVE,
  142. 0,
  143. &pstmChild2);
  144. if (FAILED(sc))
  145. {
  146. pstmChild1->Release();
  147. hr = FALSE;
  148. goto Done;
  149. }
  150. if (!CompareStreams(pstmChild1, pstmChild2))
  151. {
  152. pstmChild1->Release();
  153. pstmChild2->Release();
  154. hr = FALSE;
  155. goto Done;
  156. }
  157. pstmChild1->Release();
  158. pstmChild2->Release();
  159. }
  160. else
  161. {
  162. //Compare storages
  163. sc = pstg1->OpenStorage(stat1.pwcsName,
  164. NULL,
  165. STGM_DIRECT | STGM_READ |
  166. STGM_SHARE_EXCLUSIVE,
  167. NULL,
  168. 0,
  169. &pstgChild1);
  170. if (FAILED(sc))
  171. {
  172. hr = FALSE;
  173. goto Done;
  174. }
  175. sc = pstg2->OpenStorage(stat2.pwcsName,
  176. NULL,
  177. STGM_DIRECT | STGM_READ |
  178. STGM_SHARE_EXCLUSIVE,
  179. NULL,
  180. 0,
  181. &pstgChild2);
  182. if (FAILED(sc))
  183. {
  184. pstgChild1->Release();
  185. hr = FALSE;
  186. goto Done;
  187. }
  188. if (!CompareStorages(pstgChild1, pstgChild2))
  189. {
  190. pstgChild1->Release();
  191. pstgChild2->Release();
  192. hr = FALSE;
  193. goto Done;
  194. }
  195. pstgChild1->Release();
  196. pstgChild2->Release();
  197. }
  198. CoTaskMemFree(stat1.pwcsName);
  199. CoTaskMemFree(stat2.pwcsName);
  200. } while (sc1 != S_FALSE);
  201. Done:
  202. penum1->Release();
  203. penum2->Release();
  204. return hr;
  205. }
  206. //+---------------------------------------------------------------------------
  207. //
  208. // Member: CLayoutApp::IdenticalFiles public
  209. //
  210. // Synopsis: Check two docfiles to ensure they are the same
  211. //
  212. // Returns: TRUE is the files are identical, FALSE is they are not
  213. //
  214. // History: 07-April-96 SusiA Created
  215. //
  216. //----------------------------------------------------------------------------
  217. BOOL CLayoutApp::IdenticalFiles( TCHAR *patcFileOne,
  218. TCHAR *patcFileTwo)
  219. {
  220. SCODE sc;
  221. IStorage *pstgOne,
  222. *pstgTwo;
  223. OLECHAR awcNewFileOne[MAX_PATH];
  224. OLECHAR awcNewFileTwo[MAX_PATH];
  225. sc = StgOpenStorage(TCharToOleChar(patcFileOne, awcNewFileOne, MAX_PATH),
  226. NULL,
  227. STGM_DIRECT | STGM_READ | STGM_SHARE_EXCLUSIVE,
  228. NULL,
  229. 0,
  230. &pstgOne);
  231. if (FAILED(sc))
  232. {
  233. return FALSE;
  234. }
  235. sc = StgOpenStorage (TCharToOleChar(patcFileTwo, awcNewFileTwo, MAX_PATH),
  236. NULL,
  237. STGM_DIRECT | STGM_READ | STGM_SHARE_EXCLUSIVE,
  238. NULL,
  239. 0,
  240. &pstgTwo);
  241. if (FAILED(sc))
  242. {
  243. pstgOne->Release();
  244. return FALSE;
  245. }
  246. sc = CompareStorages(pstgOne, pstgTwo);
  247. pstgOne->Release();
  248. pstgTwo->Release();
  249. if (sc)
  250. return TRUE;
  251. else
  252. return FALSE;
  253. }
  254. #endif