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