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.

204 lines
6.4 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1992
  5. //
  6. // File: dffuncs.cxx
  7. //
  8. // Contents: Private support functions for the DocFile code
  9. //
  10. // Methods: StartMS
  11. // DeleteContents
  12. //
  13. // History: 11-Dec-91 DrewB Created
  14. //
  15. //---------------------------------------------------------------
  16. #include <dfhead.cxx>
  17. #pragma hdrstop
  18. //+--------------------------------------------------------------
  19. //
  20. // Method: CDocFile::DeleteContents, public
  21. //
  22. // Synopsis: Deletes all entries in a DocFile recursing on entries
  23. // with children
  24. //
  25. // Returns: Appropriate status code
  26. //
  27. // History: 25-Sep-91 DrewB Created
  28. //
  29. //---------------------------------------------------------------
  30. SCODE CDocFile::DeleteContents(void)
  31. {
  32. SCODE sc;
  33. olDebugOut((DEB_ITRACE, "In CDocFile::DeleteContents()\n"));
  34. sc = _stgh.DestroyEntry(NULL);
  35. olDebugOut((DEB_ITRACE, "Out CDocFile::DeleteContents\n"));
  36. return sc;
  37. }
  38. //+--------------------------------------------------------------
  39. //
  40. // Method: CDocFile::ApplyChanges, public
  41. //
  42. // Synopsis: Applies a list of updates to a docfile
  43. // Creates source entries in destination and links
  44. // them to child instances in the given TL
  45. //
  46. // Arguments: [ulChanged] - List of changes
  47. //
  48. // Returns: Appropriate status code
  49. //
  50. // History: 12-Mar-92 DrewB Created
  51. //
  52. //---------------------------------------------------------------
  53. SCODE CDocFile::ApplyChanges(CUpdateList &ulChanged)
  54. {
  55. SCODE sc = S_OK;
  56. CUpdate *pud;
  57. olDebugOut((DEB_ITRACE, "In CDocFile::ApplyChanges(%p)\n",
  58. ulChanged.GetHead()));
  59. for (pud = ulChanged.GetHead(); pud; pud = pud->GetNext())
  60. {
  61. if (pud->IsDelete())
  62. olChk(DestroyEntry(pud->GetOriginalName(), FALSE));
  63. else if (pud->IsRename())
  64. olChk(RenameEntry(pud->GetOriginalName(),
  65. pud->GetCurrentName()));
  66. else
  67. {
  68. olAssert(pud->IsCreate());
  69. olChk(CreateFromUpdate(pud, this, DF_WRITE));
  70. }
  71. }
  72. olDebugOut((DEB_ITRACE, "Out CDocFile::ApplyChanges\n"));
  73. // Fall through
  74. EH_Err:
  75. return sc;
  76. }
  77. //+--------------------------------------------------------------
  78. //
  79. // Member: CDocFile::CopyTo, public
  80. //
  81. // Synopsis: Copies the contents of one DocFile to another
  82. //
  83. // Arguments: [pdfTo] - Destination DocFile
  84. // [dwFlags] - Control flags
  85. // [snbExclude] - Partial instantiation list
  86. //
  87. // Returns: Appropriate status code
  88. //
  89. // History: 26-Sep-91 DrewB Created
  90. //
  91. //---------------------------------------------------------------
  92. SCODE CDocFile::CopyTo(CDocFile *pdfTo,
  93. DWORD dwFlags,
  94. SNBW snbExclude)
  95. {
  96. CDfName dfnKey;
  97. SIterBuffer ib;
  98. PSStream *psstFrom, *psstTo;
  99. CDocFile *pdfFromChild, *pdfToChild;
  100. DFLUID dlLUID = DF_NOLUID;
  101. SCODE sc;
  102. olDebugOut((DEB_ITRACE, "In CDocFile::CopyTo:%p(%p, %lX, %p)\n", this,
  103. pdfTo, dwFlags, snbExclude));
  104. for (;;)
  105. {
  106. if (FAILED(FindGreaterEntry(&dfnKey, &ib, NULL)))
  107. break;
  108. dfnKey.Set(&ib.dfnName);
  109. switch(REAL_STGTY(ib.type))
  110. {
  111. case STGTY_STORAGE:
  112. // Embedded DocFile, create destination and recurse
  113. olChkTo(EH_pwcsName, GetDocFile(&ib.dfnName, DF_READ, ib.type,
  114. (PDocFile **)&pdfFromChild));
  115. // Destination must be a direct docfile
  116. olChkTo(EH_Get, CDocFile::Reserve(1, BP_TO_P(CDFBasis *, _pdfb)));
  117. olChkTo(EH_Reserve, pdfTo->CreateDocFile(&ib.dfnName, DF_WRITE,
  118. dlLUID, ib.type,
  119. (PDocFile **)&pdfToChild));
  120. if (dwFlags & CDF_EXACT)
  121. pdfToChild->CopyTimesFrom(pdfFromChild);
  122. CLSID clsid;
  123. olChkTo(EH_Create, pdfFromChild->GetClass(&clsid));
  124. olChkTo(EH_Create, pdfToChild->SetClass(clsid));
  125. DWORD grfStateBits;
  126. olChkTo(EH_Create, pdfFromChild->GetStateBits(&grfStateBits));
  127. olChkTo(EH_Create, pdfToChild->SetStateBits(grfStateBits,
  128. 0xffffffff));
  129. if ((dwFlags & CDF_ENTRIESONLY) == 0 &&
  130. !(snbExclude && NameInSNB(&ib.dfnName, snbExclude) ==
  131. S_OK))
  132. olChkTo(EH_Create,
  133. pdfFromChild->CopyTo(pdfToChild, dwFlags, NULL));
  134. pdfFromChild->Release();
  135. pdfToChild->Release();
  136. break;
  137. case STGTY_STREAM:
  138. olChkTo(EH_pwcsName, GetStream(&ib.dfnName, DF_READ,
  139. ib.type, &psstFrom));
  140. // Destination must be a direct docfile
  141. olChkTo(EH_Get,
  142. CDirectStream::Reserve(1, BP_TO_P(CDFBasis *, _pdfb)));
  143. olChkTo(EH_Reserve,
  144. pdfTo->CreateStream(&ib.dfnName, DF_WRITE, dlLUID,
  145. ib.type, &psstTo));
  146. if ((dwFlags & CDF_ENTRIESONLY) == 0 &&
  147. !(snbExclude && NameInSNB(&ib.dfnName, snbExclude) ==
  148. S_OK))
  149. olChkTo(EH_Create, CopySStreamToSStream(psstFrom, psstTo));
  150. psstFrom->Release();
  151. psstTo->Release();
  152. break;
  153. default:
  154. olAssert(!aMsg("Unknown entry type in CDocFile::CopyTo"));
  155. break;
  156. }
  157. }
  158. olDebugOut((DEB_ITRACE, "Out CDocFile::CopyTo\n"));
  159. return S_OK;
  160. EH_Create:
  161. if (REAL_STGTY(ib.type) == STGTY_STORAGE)
  162. pdfToChild->Release();
  163. else if (REAL_STGTY(ib.type) == STGTY_STREAM)
  164. psstTo->Release();
  165. olAssert(&ib.dfnName);
  166. olVerSucc(pdfTo->DestroyEntry(&ib.dfnName, TRUE));
  167. goto EH_Get;
  168. EH_Reserve:
  169. if (REAL_STGTY(ib.type) == STGTY_STORAGE)
  170. CDocFile::Unreserve(1, BP_TO_P(CDFBasis *, _pdfb));
  171. else if (REAL_STGTY(ib.type) == STGTY_STREAM)
  172. CDirectStream::Unreserve(1, BP_TO_P(CDFBasis *, _pdfb));
  173. EH_Get:
  174. if (REAL_STGTY(ib.type) == STGTY_STORAGE)
  175. pdfFromChild->Release();
  176. else if (REAL_STGTY(ib.type) == STGTY_STREAM)
  177. psstFrom->Release();
  178. EH_pwcsName:
  179. return sc;
  180. }