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.

160 lines
4.8 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1996
  5. //
  6. // File: dffuncs.cxx
  7. //
  8. // Contents: Private support functions for the DocFile code
  9. //
  10. // Methods: CopyTo
  11. // DeleteContents
  12. //
  13. //---------------------------------------------------------------
  14. #include "dfhead.cxx"
  15. #include "iter.hxx"
  16. #include "h/sstream.hxx"
  17. //+--------------------------------------------------------------
  18. //
  19. // Method: CDocFile::DeleteContents, public
  20. //
  21. // Synopsis: Deletes all entries in a DocFile recursing on entries
  22. // with children
  23. //
  24. // Returns: Appropriate status code
  25. //
  26. //---------------------------------------------------------------
  27. SCODE CDocFile::DeleteContents(void)
  28. {
  29. SCODE sc;
  30. olDebugOut((DEB_ITRACE, "In CDocFile::DeleteContents()\n"));
  31. sc = _stgh.DestroyEntry(NULL);
  32. olDebugOut((DEB_ITRACE, "Out CDocFile::DeleteContents\n"));
  33. return sc;
  34. }
  35. //+--------------------------------------------------------------
  36. //
  37. // Member: CDocFile::CopyTo, public
  38. //
  39. // Synopsis: Copies the contents of one DocFile to another
  40. //
  41. // Arguments: [pdfTo] - Destination DocFile
  42. // [dwFlags] - Control flags
  43. // [snbExclude] - Partial instantiation list
  44. //
  45. // Returns: Appropriate status code
  46. //
  47. //---------------------------------------------------------------
  48. SCODE CDocFile::CopyTo(CDocFile *pdfTo,
  49. DWORD dwFlags,
  50. SNBW snbExclude)
  51. {
  52. PDocFileIterator *pdfi;
  53. SIterBuffer ib;
  54. CDirectStream *pstFrom = NULL, *pstTo = NULL;
  55. CDocFile *pdfFromChild = NULL, *pdfToChild = NULL;
  56. DFLUID dlLUID = DF_NOLUID;
  57. SCODE sc;
  58. olDebugOut((DEB_ITRACE, "In CDocFile::CopyTo:%p(%p, %lX, %p)\n", this,
  59. pdfTo, dwFlags, snbExclude));
  60. olChk(GetIterator(&pdfi));
  61. for (;;)
  62. {
  63. if (FAILED(pdfi->BufferGetNext(&ib)))
  64. break;
  65. switch(REAL_STGTY(ib.type))
  66. {
  67. case STGTY_STORAGE:
  68. // Embedded DocFile, create destination and recurse
  69. olChkTo(EH_pwcsName, GetDocFile(&ib.dfnName, DF_READ, ib.type,
  70. &pdfFromChild));
  71. // Destination must be a direct docfile
  72. olChkTo(EH_Reserve, pdfTo->CreateDocFile(&ib.dfnName, DF_WRITE,
  73. dlLUID, ib.type,
  74. &pdfToChild));
  75. if (dwFlags & CDF_EXACT)
  76. pdfToChild->CopyTimesFrom(pdfFromChild);
  77. CLSID clsid;
  78. olChkTo(EH_Create, pdfFromChild->GetClass(&clsid));
  79. olChkTo(EH_Create, pdfToChild->SetClass(clsid));
  80. DWORD grfStateBits;
  81. olChkTo(EH_Create, pdfFromChild->GetStateBits(&grfStateBits));
  82. olChkTo(EH_Create, pdfToChild->SetStateBits(grfStateBits,
  83. 0xffffffff));
  84. if ((dwFlags & CDF_ENTRIESONLY) == 0 &&
  85. !(snbExclude && NameInSNB(&ib.dfnName, snbExclude) ==
  86. S_OK))
  87. olChkTo(EH_Create,
  88. pdfFromChild->CopyTo(pdfToChild, dwFlags, NULL));
  89. pdfFromChild->Release();
  90. pdfToChild->Release();
  91. break;
  92. case STGTY_STREAM:
  93. olChkTo(EH_pwcsName, GetStream(&ib.dfnName, DF_READ,
  94. ib.type, &pstFrom));
  95. // Destination must be a direct docfile
  96. olChkTo(EH_Reserve,
  97. pdfTo->CreateStream(&ib.dfnName, DF_WRITE,
  98. dlLUID, &pstTo));
  99. if (dwFlags & CDF_EXACT)
  100. pstTo->CopyTimesFrom(pstFrom);
  101. if ((dwFlags & CDF_ENTRIESONLY) == 0 &&
  102. !(snbExclude &&
  103. NameInSNB(&ib.dfnName, snbExclude) == S_OK))
  104. olChkTo(EH_Create, CopyStreamToStream(
  105. pstFrom, pstTo));
  106. pstFrom->Release();
  107. pstTo->Release();
  108. break;
  109. default:
  110. olAssert(!aMsg("Unknown entry type in CDocFile::CopyTo"));
  111. break;
  112. }
  113. }
  114. pdfi->Release();
  115. olDebugOut((DEB_ITRACE, "Out CDocFile::CopyTo\n"));
  116. return S_OK;
  117. EH_Create:
  118. if (REAL_STGTY(ib.type))
  119. pdfToChild->Release();
  120. else
  121. pstTo->Release();
  122. olAssert(&ib.dfnName);
  123. olVerSucc(pdfTo->DestroyEntry(&ib.dfnName, TRUE));
  124. goto EH_Get;
  125. EH_Reserve:
  126. EH_Get:
  127. if (REAL_STGTY(ib.type))
  128. pdfFromChild->Release();
  129. else
  130. pstFrom->Release();
  131. EH_pwcsName:
  132. pdfi->Release();
  133. EH_Err:
  134. return sc;
  135. }