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: CRootPubDocFile implementation
9 //
10 //---------------------------------------------------------------
11
12 #include "dfhead.cxx"
13
14 #include "h/header.hxx"
15 #include "h/rexpdf.hxx"
16 #include "dfbasis.hxx"
17 #include "h/tchar.h"
18
19 // Priority mode lock permissions
20 #define PRIORITY_PERMS DF_READ
21
22 //+--------------------------------------------------------------
23 //
24 // Member: CRootExposedDocFile::CRootExposedDocFile, public
25 //
26 // Synopsis: Ctor - Initializes empty object
27 //
28 //---------------------------------------------------------------
29
30
CRootExposedDocFile(CDFBasis * pdfb)31 CRootExposedDocFile::CRootExposedDocFile(CDFBasis *pdfb) :
32 CExposedDocFile(NULL, NULL, 0, ROOT_LUID, NULL, NULL, NULL, pdfb)
33 {
34 olDebugOut((DEB_ITRACE, "CRootExposedDocFile constructor called\n"));
35 }
36
37
38 //+--------------------------------------------------------------
39 //
40 // Member: CRootExposedDocFile::Init, private
41 //
42 // Synopsis: Dependent root initialization
43 //
44 // Arguments: [plstBase] - Base
45 // [snbExclude] - Limited instantiation exclusions
46 // [dwStartFlags] - Startup flags
47 //
48 // Returns: Appropriate status code
49 //
50 //---------------------------------------------------------------
51
Init(ILockBytes * plstBase,SNBW snbExclude,DWORD const dwStartFlags)52 SCODE CRootExposedDocFile::Init( ILockBytes *plstBase,
53 SNBW snbExclude,
54 DWORD const dwStartFlags)
55 {
56 CDocFile *pdf;
57 SCODE sc;
58 CMStream *pms;
59
60 olDebugOut((DEB_ITRACE, "In CRootExposedDocFile::Init()\n"));
61 if (snbExclude)
62 {
63 olChk(DllMultiStreamFromStream(&pms, &plstBase, dwStartFlags));
64 olMemTo(EH_pms,
65 pdf = new CDocFile(pms, SIDROOT, ROOT_LUID, _pilbBase));
66 pdf->AddRef();
67 olChkTo(EH_pdf, pdf->ExcludeEntries(pdf, snbExclude));
68 olChkTo(EH_pdf, pms->Flush(0));
69 pdf->Release();
70 }
71 plstBase->AddRef();
72 _pilbBase = plstBase;
73 olDebugOut((DEB_ITRACE, "Out CRootExposedDocFile::Init()\n"));
74 return S_OK;
75
76 EH_pdf:
77 pdf->Release();
78 EH_pms:
79 DllReleaseMultiStream(pms);
80 EH_Err:
81 return sc;
82 }
83
84 //+--------------------------------------------------------------
85 //
86 // Member: CRootExposedDocFile::InitRoot, public
87 //
88 // Synopsis: Initialising a root storage
89 //
90 // Arguments: [plstBase] - Base LStream
91 // [dwStartFlags] - How to start things
92 // [df] - Transactioning flags
93 // [snbExclude] - Parital instantiation list
94 // [ppdfb] - Basis pointer return
95 //
96 // Returns: Appropriate status code
97 //
98 // Modifies: [ppdfb]
99 //
100 //---------------------------------------------------------------
101
InitRoot(ILockBytes * plstBase,DWORD const dwStartFlags,DFLAGS const df,SNBW snbExclude)102 SCODE CRootExposedDocFile::InitRoot( ILockBytes *plstBase,
103 DWORD const dwStartFlags,
104 DFLAGS const df,
105 SNBW snbExclude)
106 {
107 CDocFile *pdfBase;
108 SCODE sc, scConv = S_OK;
109 STATSTG statstg;
110
111 olDebugOut((DEB_ITRACE, "In CRootExposedDocFile::InitRoot("
112 "%p, %lX, %lX, %p)\n",
113 plstBase, dwStartFlags, df, snbExclude));
114
115 // Exclusion only works with a plain open
116 olAssert(snbExclude == NULL ||
117 (dwStartFlags & (RSF_CREATEFLAGS | RSF_CONVERT)) == 0);
118
119 olHChk(plstBase->Stat(&statstg, STATFLAG_NONAME));
120
121 olChkTo(EH_GetPriority,
122 Init(plstBase, snbExclude, dwStartFlags));
123
124 scConv = DllMultiStreamFromStream(&_pmsBase, &_pilbBase,
125 dwStartFlags);
126 if (scConv == STG_E_INVALIDHEADER)
127 scConv = STG_E_FILEALREADYEXISTS;
128 olChkTo(EH_pfstScratchInit, scConv);
129
130 olMemTo(EH_pmsBase,
131 pdfBase = new CDocFile(_pmsBase, SIDROOT, ROOT_LUID, _pilbBase));
132
133 pdfBase->AddRef();
134
135 _pdf = pdfBase;
136 _df = df;
137 olDebugOut((DEB_ITRACE, "Out CRootExposedDocFile::InitRoot\n"));
138 return scConv;
139
140 EH_pmsBase:
141 DllReleaseMultiStream(_pmsBase);
142
143 EH_pfstScratchInit:
144 EH_GetPriority:
145 EH_Err:
146 return sc;
147 }
148
149 //+--------------------------------------------------------------
150 //
151 // Member: CRootExposedDocFile::~CRootExposedDocFile,
152 // public virutal
153 //
154 // Synopsis: dtor (virtual)
155 //
156 //---------------------------------------------------------------
157
158
~CRootExposedDocFile(void)159 CRootExposedDocFile::~CRootExposedDocFile(void)
160 {
161 olDebugOut((DEB_TRACE, "In CRootExposedDocFile::~CRootExposedDocFile\n"));
162
163 olAssert(_cReferences == 0);
164
165 if (SUCCEEDED(CheckReverted()))
166 {
167 if (_pilbBase) {
168 _pilbBase->Release();
169 _pilbBase = NULL;
170 }
171 }
172 olDebugOut((DEB_TRACE, "Out CRootExposedDocFile::~CRootExposedDocFile\n"));
173 }
174
175 //+-------------------------------------------------------------------
176 //
177 // Member: CRootExposedDocFile::Stat, public
178 // virtual fr. CExposedDocFile
179 //
180 // Synopsis: Fills in a stat buffer from the base LStream
181 //
182 // Arguments: [pstatstg] - Stat buffer
183 // [grfStatFlag] - Stat flags
184 //
185 // Returns: Appropriate status code
186 //
187 // Modifies: [pstatstg]
188 //
189 //--------------------------------------------------------------------
190
191
Stat(STATSTGW * pstatstgw,DWORD grfStatFlag)192 SCODE CRootExposedDocFile::Stat(STATSTGW *pstatstgw, DWORD grfStatFlag)
193 {
194 SCODE sc;
195 STATSTG *pstatstg= (STATSTG*)pstatstgw;
196
197 olDebugOut((DEB_ITRACE, "In CRootExposedDocFile::Stat(%p, %lu)\n",
198 pstatstg, grfStatFlag));
199 olChk(ValidateOutBuffer(pstatstg, sizeof(STATSTGW)));
200 olChk(VerifyStatFlag(grfStatFlag));
201 olChk(CheckReverted());
202 olHChk(_pilbBase->Stat(pstatstg, grfStatFlag));
203 pstatstg->type = STGTY_STORAGE;
204 ULISet32(pstatstg->cbSize, 0); // size undefined for storage obj
205 pstatstg->grfLocksSupported = 0;
206 pstatstg->reserved = 0;
207 if (pstatstg->pwcsName)
208 {
209 // pilbBase returns either wide or ansi names depending on
210 // system type, so we have to convert to ANSI char if neccessay
211 WCHAR *pwcs;
212 olChkTo(EH_pwcsName,
213 DfAllocWC(_tcslen(pstatstg->pwcsName)+1, &pwcs));
214 TTOW(pstatstg->pwcsName, pwcs, _tcslen(pstatstg->pwcsName)+1);
215 delete[] pstatstg->pwcsName;
216 pstatstgw->pwcsName = pwcs;
217 }
218 pstatstg->grfMode = DFlagsToMode(_df);
219 olChkTo(EH_pwcsName, _pdf->GetClass(&pstatstg->clsid));
220 olChkTo(EH_pwcsName, _pdf->GetStateBits(&pstatstg->grfStateBits));
221 olDebugOut((DEB_ITRACE, "Out CRootExposedDocFile::Stat\n"));
222 return S_OK;
223
224 EH_pwcsName:
225 if (pstatstg->pwcsName)
226 delete[] pstatstg->pwcsName;
227 EH_Err:
228 return sc;
229 }
230
231
232
233