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.

489 lines
13 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1996.
  5. //
  6. // File: cdocfile.cxx
  7. //
  8. // Contents: Implementation of CDocFile methods for DocFiles
  9. //
  10. //---------------------------------------------------------------
  11. #include "dfhead.cxx"
  12. #include "h/vectfunc.hxx"
  13. //+--------------------------------------------------------------
  14. //
  15. // Member: PEntry::_dlBase, static private data
  16. //
  17. // Synopsis: luid allocation base
  18. //
  19. // Notes: Since DF_NOLUID is 0 and ROOT_LUID is 1 we start
  20. // issuing at 2.
  21. //
  22. //---------------------------------------------------------------
  23. DFLUID PEntry::_dlBase = LUID_BASE;
  24. //+--------------------------------------------------------------
  25. //
  26. // Member: CDocFile::InitFromEntry, public
  27. //
  28. // Synopsis: Creation/Instantiation constructor for embeddings
  29. //
  30. // Arguments: [pstghParent] - Parent handle
  31. // [pdfn] - Name
  32. // [fCreate] - Create/Instantiate
  33. // [dwType] - Type of entry
  34. //
  35. // Returns: Appropriate status code
  36. //
  37. //---------------------------------------------------------------
  38. SCODE CDocFile::InitFromEntry(CStgHandle *pstghParent,
  39. CDfName const *pdfn,
  40. BOOL const fCreate)
  41. {
  42. SCODE sc;
  43. olDebugOut((DEB_ITRACE, "In CDocFile::InitFromEntry(%p, %ws, %d)\n",
  44. pstghParent, pdfn, fCreate));
  45. if (fCreate)
  46. sc = pstghParent->CreateEntry(pdfn, STGTY_STORAGE, &_stgh);
  47. else
  48. sc = pstghParent->GetEntry(pdfn, STGTY_STORAGE, &_stgh);
  49. if (SUCCEEDED(sc))
  50. AddRef();
  51. olDebugOut((DEB_ITRACE, "Out CDocFile::InitFromEntry\n"));
  52. return sc;
  53. }
  54. //+--------------------------------------------------------------
  55. //
  56. // Member: CDocFile::CreateDocFile, public
  57. //
  58. // Synopsis: Creates a DocFile object in a parent
  59. //
  60. // Arguments: [pdfn] - Name of DocFile
  61. // [df] - Transactioning flags
  62. // [dlSet] - LUID to set or DF_NOLUID
  63. // [dwType] - Type of entry
  64. // [ppdfDocFile] - DocFile return
  65. //
  66. // Returns: Appropriate status code
  67. //
  68. // Modifies: [ppdfDocFile]
  69. //
  70. //---------------------------------------------------------------
  71. SCODE CDocFile::CreateDocFile(CDfName const *pdfn,
  72. DFLAGS const df,
  73. DFLUID dlSet,
  74. CDocFile **ppdfDocFile)
  75. {
  76. CDocFile *pdf;
  77. SCODE sc;
  78. olDebugOut((DEB_ITRACE, "In CDocFile::CreateDocFile:%p("
  79. "%ws, %X, %lu, %p)\n", this, pdfn, df, dlSet,
  80. ppdfDocFile));
  81. UNREFERENCED_PARM(df);
  82. if (dlSet == DF_NOLUID)
  83. dlSet = CDocFile::GetNewLuid();
  84. olMem(pdf = new CDocFile(dlSet, _pilbBase));
  85. olChkTo(EH_pdf, pdf->InitFromEntry(&_stgh, pdfn, TRUE));
  86. *ppdfDocFile = pdf;
  87. olDebugOut((DEB_ITRACE, "Out CDocFile::CreateDocFile => %p\n",
  88. SAFE_DREF(ppdfDocFile)));
  89. return S_OK;
  90. EH_pdf:
  91. delete pdf;
  92. EH_Err:
  93. return sc;
  94. }
  95. //+--------------------------------------------------------------
  96. //
  97. // Member: CDocFile::GetDocFile, public
  98. //
  99. // Synopsis: Instantiates an existing docfile
  100. //
  101. // Arguments: [pdfn] - Name of stream
  102. // [df] - Transactioning flags
  103. // [dwType] - Type of entry
  104. // [ppdfDocFile] - Docfile return
  105. //
  106. // Returns: Appropriate status code
  107. //
  108. // Modifies: [ppdfDocFile]
  109. //
  110. //---------------------------------------------------------------
  111. SCODE CDocFile::GetDocFile(CDfName const *pdfn,
  112. DFLAGS const df,
  113. CDocFile **ppdfDocFile)
  114. {
  115. CDocFile *pdf;
  116. SCODE sc;
  117. olDebugOut((DEB_ITRACE, "In CDocFile::GetDocFile:%p("
  118. "%ws, %X, %p)\n", this, pdfn, df, ppdfDocFile));
  119. UNREFERENCED_PARM(df);
  120. DFLUID dl = CDocFile::GetNewLuid();
  121. olMem(pdf = new CDocFile(dl, _pilbBase));
  122. olChkTo(EH_pdf, pdf->InitFromEntry(&_stgh, pdfn, FALSE));
  123. *ppdfDocFile = pdf;
  124. olDebugOut((DEB_ITRACE, "Out CDocFile::GetDocFile => %p\n",
  125. *ppdfDocFile));
  126. return S_OK;
  127. EH_pdf:
  128. delete pdf;
  129. EH_Err:
  130. return sc;
  131. }
  132. //+--------------------------------------------------------------
  133. //
  134. // Member: CDocFile::Release, public
  135. //
  136. // Synopsis: Release resources for a DocFile
  137. //
  138. //---------------------------------------------------------------
  139. void CDocFile::Release(void)
  140. {
  141. olDebugOut((DEB_ITRACE, "In CDocFile::Release()\n"));
  142. olAssert(_cReferences > 0);
  143. AtomicDec(&_cReferences);
  144. if (_cReferences == 0)
  145. delete this;
  146. olDebugOut((DEB_ITRACE, "Out CDocFile::Release\n"));
  147. }
  148. //+--------------------------------------------------------------
  149. //
  150. // Member: CDocFile::RenameEntry, public
  151. //
  152. // Synopsis: Renames a child
  153. //
  154. // Arguments: [pdfnName] - Old name
  155. // [pdfnNewName] - New name
  156. //
  157. // Returns: Appropriate status code
  158. //
  159. //---------------------------------------------------------------
  160. SCODE CDocFile::RenameEntry(CDfName const *pdfnName,
  161. CDfName const *pdfnNewName)
  162. {
  163. SCODE sc;
  164. olDebugOut((DEB_ITRACE, "In CDocFile::RenameEntry(%ws, %ws)\n",
  165. pdfnName, pdfnNewName));
  166. sc = _stgh.RenameEntry(pdfnName, pdfnNewName);
  167. olDebugOut((DEB_ITRACE, "Out CDocFile::RenameEntry\n"));
  168. return sc;
  169. }
  170. //+--------------------------------------------------------------
  171. //
  172. // Member: CDocFile::DestroyEntry, public
  173. //
  174. // Synopsis: Permanently destroys a child
  175. //
  176. // Arguments: [pdfnName] - Name of child
  177. // [fClean] - Ignored
  178. //
  179. // Returns: Appropriate status code
  180. //
  181. //---------------------------------------------------------------
  182. SCODE CDocFile::DestroyEntry(CDfName const *pdfnName,
  183. BOOL fClean)
  184. {
  185. SCODE sc;
  186. olDebugOut((DEB_ITRACE, "In CDocFile::DestroyEntry:%p(%ws, %d)\n",
  187. this, pdfnName, fClean));
  188. UNREFERENCED_PARM(fClean);
  189. sc = _stgh.DestroyEntry(pdfnName);
  190. olDebugOut((DEB_ITRACE, "Out CDocFile::DestroyEntry\n"));
  191. return sc;
  192. }
  193. //+--------------------------------------------------------------
  194. //
  195. // Member: CDocFile::IsEntry, public
  196. //
  197. // Synopsis: Determines whether the given object is a member
  198. // of the DocFile
  199. //
  200. // Arguments: [pdfnName] - Name
  201. // [peb] - Entry buffer to fill in
  202. //
  203. // Returns: Appropriate status code
  204. //
  205. // Modifies: [peb]
  206. //
  207. //---------------------------------------------------------------
  208. SCODE CDocFile::IsEntry(CDfName const *pdfnName,
  209. SEntryBuffer *peb)
  210. {
  211. SCODE sc;
  212. olDebugOut((DEB_ITRACE, "In CDocFile::IsEntry(%ws, %p)\n",
  213. pdfnName, peb));
  214. sc = _stgh.IsEntry(pdfnName, peb);
  215. olDebugOut((DEB_ITRACE, "Out CDocFile::IsEntry => %lu, %lu, %lu\n",
  216. sc, peb->luid, peb->dwType));
  217. return sc;
  218. }
  219. //+--------------------------------------------------------------
  220. //
  221. // Member: CDocFile::AddRef, public
  222. //
  223. // Synopsis: Increments the ref count
  224. //
  225. //---------------------------------------------------------------
  226. void CDocFile::AddRef(void)
  227. {
  228. olDebugOut((DEB_ITRACE, "In CDocFile::AddRef()\n"));
  229. AtomicInc(&_cReferences);
  230. olDebugOut((DEB_ITRACE, "Out CDocFile::AddRef, %lu\n", _cReferences));
  231. }
  232. //+--------------------------------------------------------------
  233. //
  234. // Member: CDocFile::GetTime, public
  235. //
  236. // Synopsis: Gets a time
  237. //
  238. // Arguments: [wt] - Which time
  239. // [ptm] - Time return
  240. //
  241. // Returns: Appropriate status code
  242. //
  243. // Modifies: [ptm]
  244. //
  245. //---------------------------------------------------------------
  246. SCODE CDocFile::GetTime(WHICHTIME wt, TIME_T *ptm)
  247. {
  248. return _stgh.GetTime(wt, ptm);
  249. }
  250. //+--------------------------------------------------------------
  251. //
  252. // Member: CDocFile::SetTime, public
  253. //
  254. // Synopsis: Sets a time
  255. //
  256. // Arguments: [wt] - Which time
  257. // [tm] - New time
  258. //
  259. // Returns: Appropriate status code
  260. //
  261. //---------------------------------------------------------------
  262. SCODE CDocFile::SetTime(WHICHTIME wt, TIME_T tm)
  263. {
  264. return _stgh.SetTime(wt, tm);
  265. }
  266. //+---------------------------------------------------------------------------
  267. //
  268. // Member: CDocFile::GetClass, public
  269. //
  270. // Synopsis: Gets the class ID
  271. //
  272. // Arguments: [pclsid] - Class ID return
  273. //
  274. // Returns: Appropriate status code
  275. //
  276. // Modifies: [pclsid]
  277. //
  278. //----------------------------------------------------------------------------
  279. SCODE CDocFile::GetClass(CLSID *pclsid)
  280. {
  281. return _stgh.GetClass(pclsid);
  282. }
  283. //+---------------------------------------------------------------------------
  284. //
  285. // Member: CDocFile::SetClass, public
  286. //
  287. // Synopsis: Sets the class ID
  288. //
  289. // Arguments: [clsid] - New class ID
  290. //
  291. // Returns: Appropriate status code
  292. //
  293. //----------------------------------------------------------------------------
  294. SCODE CDocFile::SetClass(REFCLSID clsid)
  295. {
  296. return _stgh.SetClass(clsid);
  297. }
  298. //+---------------------------------------------------------------------------
  299. //
  300. // Member: CDocFile::GetStateBits, public
  301. //
  302. // Synopsis: Gets the state bits
  303. //
  304. // Arguments: [pgrfStateBits] - State bits return
  305. //
  306. // Returns: Appropriate status code
  307. //
  308. // Modifies: [pgrfStateBits]
  309. //
  310. //----------------------------------------------------------------------------
  311. SCODE CDocFile::GetStateBits(DWORD *pgrfStateBits)
  312. {
  313. return _stgh.GetStateBits(pgrfStateBits);
  314. }
  315. //+---------------------------------------------------------------------------
  316. //
  317. // Member: CDocFile::SetStateBits, public
  318. //
  319. // Synopsis: Sets the state bits
  320. //
  321. // Arguments: [grfStateBits] - Bits to set
  322. // [grfMask] - Mask
  323. //
  324. // Returns: Appropriate status code
  325. //
  326. //----------------------------------------------------------------------------
  327. SCODE CDocFile::SetStateBits(DWORD grfStateBits, DWORD grfMask)
  328. {
  329. return _stgh.SetStateBits(grfStateBits, grfMask);
  330. }
  331. //+---------------------------------------------------------------------------
  332. //
  333. // Member: CDocFile::FindGreaterEntry, public (virtual)
  334. //
  335. // Synopsis: Returns the next greater child
  336. //
  337. // Arguments: [pdfnKey] - Previous key
  338. // [pNextKey] - The found key
  339. // [pstat] - Full iterator buffer
  340. //
  341. // Returns: Appropriate status code
  342. //
  343. // Modifies: [pstat] - if it is not null
  344. // [pNextKey] - if it is not null
  345. //
  346. //----------------------------------------------------------------------------
  347. SCODE CDocFile::FindGreaterEntry(CDfName const *pdfnKey,
  348. CDfName *pNextKey,
  349. STATSTGW *pstat)
  350. {
  351. SID sid, sidChild;
  352. SCODE sc;
  353. olDebugOut((DEB_ITRACE, "In CDocFile::FindGreaterEntry:%p(%p, %p, %p)\n",
  354. this, pdfnKey, pNextKey, pstat));
  355. if (SUCCEEDED(sc = _stgh.GetMS()->GetChild(_stgh.GetSid(), &sidChild)))
  356. {
  357. if (sidChild == NOSTREAM)
  358. sc = STG_E_NOMOREFILES;
  359. else if (SUCCEEDED(sc = _stgh.GetMS()->
  360. FindGreaterEntry(sidChild, pdfnKey, &sid)))
  361. {
  362. sc = _stgh.GetMS()->StatEntry(sid, pNextKey, pstat);
  363. }
  364. }
  365. olDebugOut((DEB_ITRACE, "Out CDocFile::FindGreaterEntry\n"));
  366. return sc;
  367. }
  368. //+--------------------------------------------------------------
  369. //
  370. // Member: CDocFile::ExcludeEntries, public
  371. //
  372. // Synopsis: Excludes the given entries
  373. //
  374. // Arguments: [snbExclude] - Entries to exclude
  375. //
  376. // Returns: Appropriate status code
  377. //
  378. //---------------------------------------------------------------
  379. SCODE CDocFile::ExcludeEntries(CDocFile *pdf, SNBW snbExclude)
  380. {
  381. PDocFileIterator *pdfi;
  382. CDirectStream *pstChild;
  383. CDocFile *pdfChild;
  384. SCODE sc;
  385. SIterBuffer ib;
  386. olDebugOut((DEB_ITRACE, "In PDocFile::ExcludeEntries(%p)\n",
  387. snbExclude));
  388. olChk(pdf->GetIterator(&pdfi));
  389. for (;;)
  390. {
  391. if (FAILED(pdfi->BufferGetNext(&ib)))
  392. break;
  393. if (NameInSNB(&ib.dfnName, snbExclude) == S_OK)
  394. {
  395. switch(REAL_STGTY(ib.type))
  396. {
  397. case STGTY_STORAGE:
  398. olChkTo(EH_pwcsName, pdf->GetDocFile(&ib.dfnName, DF_READ |
  399. DF_WRITE, ib.type,
  400. &pdfChild));
  401. olChkTo(EH_Get, pdfChild->DeleteContents());
  402. pdfChild->Release();
  403. break;
  404. case STGTY_STREAM:
  405. olChkTo(EH_pwcsName, pdf->GetStream(&ib.dfnName, DF_WRITE,
  406. ib.type, &pstChild));
  407. olChkTo(EH_Get, pstChild->SetSize(0));
  408. pstChild->Release();
  409. break;
  410. }
  411. }
  412. }
  413. pdfi->Release();
  414. olDebugOut((DEB_ITRACE, "Out ExcludeEntries\n"));
  415. return S_OK;
  416. EH_Get:
  417. if (REAL_STGTY(ib.type))
  418. pdfChild->Release();
  419. else
  420. pstChild->Release();
  421. EH_pwcsName:
  422. pdfi->Release();
  423. EH_Err:
  424. return sc;
  425. }