1 | /* $Id: filemoniker.cpp,v 1.1 1999-09-24 21:49:43 davidr Exp $ */
|
---|
2 | /*
|
---|
3 | * FileMonikers functions.
|
---|
4 | *
|
---|
5 | * 20/9/99
|
---|
6 | *
|
---|
7 | * Copyright 1999 David J. Raison
|
---|
8 | *
|
---|
9 | * Direct port of Wine Implementation
|
---|
10 | * Copyright 1999 Noomen Hamza
|
---|
11 | */
|
---|
12 |
|
---|
13 | #include "ole32.h"
|
---|
14 | #include "heapstring.h"
|
---|
15 | #include "debugtools.h"
|
---|
16 | #include "filemoniker.h"
|
---|
17 |
|
---|
18 | DEFAULT_DEBUG_CHANNEL(ole)
|
---|
19 |
|
---|
20 | /********************************************************************************/
|
---|
21 | /* FileMoniker prototype functions : */
|
---|
22 |
|
---|
23 | /* IUnknown prototype functions */
|
---|
24 | static HRESULT WINAPI FileMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
|
---|
25 | static ULONG WINAPI FileMonikerImpl_AddRef(IMoniker* iface);
|
---|
26 | static ULONG WINAPI FileMonikerImpl_Release(IMoniker* iface);
|
---|
27 |
|
---|
28 | /* IPersist prototype functions */
|
---|
29 | static HRESULT WINAPI FileMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
|
---|
30 |
|
---|
31 | /* IPersistStream prototype functions */
|
---|
32 | static HRESULT WINAPI FileMonikerImpl_IsDirty(IMoniker* iface);
|
---|
33 | static HRESULT WINAPI FileMonikerImpl_Load(IMoniker* iface, IStream* pStm);
|
---|
34 | static HRESULT WINAPI FileMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
|
---|
35 | static HRESULT WINAPI FileMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
|
---|
36 |
|
---|
37 | /* IMoniker prototype functions */
|
---|
38 | static HRESULT WINAPI FileMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
|
---|
39 | static HRESULT WINAPI FileMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
|
---|
40 | static HRESULT WINAPI FileMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
|
---|
41 | static HRESULT WINAPI FileMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
|
---|
42 | static HRESULT WINAPI FileMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
|
---|
43 | static HRESULT WINAPI FileMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
|
---|
44 | static HRESULT WINAPI FileMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
|
---|
45 | static HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
|
---|
46 | static HRESULT WINAPI FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pFileTime);
|
---|
47 | static HRESULT WINAPI FileMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
|
---|
48 | static HRESULT WINAPI FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
|
---|
49 | static HRESULT WINAPI FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
|
---|
50 | static HRESULT WINAPI FileMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
|
---|
51 | static HRESULT WINAPI FileMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
|
---|
52 | static HRESULT WINAPI FileMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
|
---|
53 |
|
---|
54 | /********************************************************************************/
|
---|
55 | /* IROTData prototype functions */
|
---|
56 |
|
---|
57 | /* IUnknown prototype functions */
|
---|
58 | static HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData* iface,REFIID riid,VOID** ppvObject);
|
---|
59 | static ULONG WINAPI FileMonikerROTDataImpl_AddRef(IROTData* iface);
|
---|
60 | static ULONG WINAPI FileMonikerROTDataImpl_Release(IROTData* iface);
|
---|
61 |
|
---|
62 | /* IROTData prototype function */
|
---|
63 | static HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface,BYTE* pbData,ULONG cbMax,ULONG* pcbData);
|
---|
64 |
|
---|
65 |
|
---|
66 | /********************************************************************************/
|
---|
67 | /* Virtual function table for the FileMonikerImpl class witch include Ipersist,*/
|
---|
68 | /* IPersistStream and IMoniker functions. */
|
---|
69 | static ICOM_VTABLE(IMoniker) VT_FileMonikerImpl =
|
---|
70 | {
|
---|
71 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
---|
72 | FileMonikerImpl_QueryInterface,
|
---|
73 | FileMonikerImpl_AddRef,
|
---|
74 | FileMonikerImpl_Release,
|
---|
75 | FileMonikerImpl_GetClassID,
|
---|
76 | FileMonikerImpl_IsDirty,
|
---|
77 | FileMonikerImpl_Load,
|
---|
78 | FileMonikerImpl_Save,
|
---|
79 | FileMonikerImpl_GetSizeMax,
|
---|
80 | FileMonikerImpl_BindToObject,
|
---|
81 | FileMonikerImpl_BindToStorage,
|
---|
82 | FileMonikerImpl_Reduce,
|
---|
83 | FileMonikerImpl_ComposeWith,
|
---|
84 | FileMonikerImpl_Enum,
|
---|
85 | FileMonikerImpl_IsEqual,
|
---|
86 | FileMonikerImpl_Hash,
|
---|
87 | FileMonikerImpl_IsRunning,
|
---|
88 | FileMonikerImpl_GetTimeOfLastChange,
|
---|
89 | FileMonikerImpl_Inverse,
|
---|
90 | FileMonikerImpl_CommonPrefixWith,
|
---|
91 | FileMonikerImpl_RelativePathTo,
|
---|
92 | FileMonikerImpl_GetDisplayName,
|
---|
93 | FileMonikerImpl_ParseDisplayName,
|
---|
94 | FileMonikerImpl_IsSystemMoniker
|
---|
95 | };
|
---|
96 |
|
---|
97 | /********************************************************************************/
|
---|
98 | /* Virtual function table for the IROTData class. */
|
---|
99 | static ICOM_VTABLE(IROTData) VT_ROTDataImpl =
|
---|
100 | {
|
---|
101 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
---|
102 | FileMonikerROTDataImpl_QueryInterface,
|
---|
103 | FileMonikerROTDataImpl_AddRef,
|
---|
104 | FileMonikerROTDataImpl_Release,
|
---|
105 | FileMonikerROTDataImpl_GetComparaisonData
|
---|
106 | };
|
---|
107 |
|
---|
108 | /*******************************************************************************
|
---|
109 | * FileMoniker_QueryInterface
|
---|
110 | *******************************************************************************/
|
---|
111 | HRESULT WINAPI FileMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
|
---|
112 | {
|
---|
113 | ICOM_THIS(FileMonikerImpl,iface);
|
---|
114 |
|
---|
115 | TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
|
---|
116 |
|
---|
117 | /* Perform a sanity check on the parameters.*/
|
---|
118 | if ( (This==0) || (ppvObject==0) )
|
---|
119 | return E_INVALIDARG;
|
---|
120 |
|
---|
121 | /* Initialize the return parameter */
|
---|
122 | *ppvObject = 0;
|
---|
123 |
|
---|
124 | /* Compare the riid with the interface IDs implemented by this object.*/
|
---|
125 | if (IsEqualIID(&IID_IUnknown, riid) ||
|
---|
126 | IsEqualIID(&IID_IPersist, riid) ||
|
---|
127 | IsEqualIID(&IID_IPersistStream,riid) ||
|
---|
128 | IsEqualIID(&IID_IMoniker, riid)
|
---|
129 | )
|
---|
130 | *ppvObject = iface;
|
---|
131 |
|
---|
132 | else if (IsEqualIID(&IID_IROTData, riid))
|
---|
133 | *ppvObject = (IROTData*)&(This->lpvtbl2);
|
---|
134 |
|
---|
135 | /* Check that we obtained an interface.*/
|
---|
136 | if ((*ppvObject)==0)
|
---|
137 | return E_NOINTERFACE;
|
---|
138 |
|
---|
139 | /* Query Interface always increases the reference count by one when it is successful */
|
---|
140 | FileMonikerImpl_AddRef(iface);
|
---|
141 |
|
---|
142 | return S_OK;
|
---|
143 | }
|
---|
144 |
|
---|
145 | /******************************************************************************
|
---|
146 | * FileMoniker_AddRef
|
---|
147 | ******************************************************************************/
|
---|
148 | ULONG WINAPI FileMonikerImpl_AddRef(IMoniker* iface)
|
---|
149 | {
|
---|
150 | ICOM_THIS(FileMonikerImpl,iface);
|
---|
151 |
|
---|
152 | TRACE("(%p)\n",iface);
|
---|
153 |
|
---|
154 | return ++(This->ref);
|
---|
155 | }
|
---|
156 |
|
---|
157 | /******************************************************************************
|
---|
158 | * FileMoniker_Release
|
---|
159 | ******************************************************************************/
|
---|
160 | ULONG WINAPI FileMonikerImpl_Release(IMoniker* iface)
|
---|
161 | {
|
---|
162 | ICOM_THIS(FileMonikerImpl,iface);
|
---|
163 |
|
---|
164 | TRACE("(%p)\n",iface);
|
---|
165 |
|
---|
166 | This->ref--;
|
---|
167 |
|
---|
168 | /* destroy the object if there's no more reference on it */
|
---|
169 | if (This->ref==0){
|
---|
170 |
|
---|
171 | FileMonikerImpl_Destroy(This);
|
---|
172 |
|
---|
173 | return 0;
|
---|
174 | }
|
---|
175 | return This->ref;;
|
---|
176 | }
|
---|
177 |
|
---|
178 | /******************************************************************************
|
---|
179 | * FileMoniker_GetClassID
|
---|
180 | ******************************************************************************/
|
---|
181 | HRESULT WINAPI FileMonikerImpl_GetClassID(IMoniker* iface,
|
---|
182 | CLSID *pClassID)/* Pointer to CLSID of object */
|
---|
183 | {
|
---|
184 | TRACE("(%p,%p),stub!\n",iface,pClassID);
|
---|
185 |
|
---|
186 | if (pClassID==NULL)
|
---|
187 | return E_POINTER;
|
---|
188 |
|
---|
189 | *pClassID = CLSID_FileMoniker;
|
---|
190 |
|
---|
191 | return S_OK;
|
---|
192 | }
|
---|
193 |
|
---|
194 | /******************************************************************************
|
---|
195 | * FileMoniker_IsDirty
|
---|
196 | ******************************************************************************/
|
---|
197 | HRESULT WINAPI FileMonikerImpl_IsDirty(IMoniker* iface)
|
---|
198 | {
|
---|
199 | /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
|
---|
200 | method in the OLE-provided moniker interfaces always return S_FALSE because
|
---|
201 | their internal state never changes. */
|
---|
202 |
|
---|
203 | TRACE("(%p)\n",iface);
|
---|
204 |
|
---|
205 | return S_FALSE;
|
---|
206 | }
|
---|
207 |
|
---|
208 | /******************************************************************************
|
---|
209 | * FileMoniker_Load
|
---|
210 | ******************************************************************************/
|
---|
211 | HRESULT WINAPI FileMonikerImpl_Load(IMoniker* iface,IStream* pStm)
|
---|
212 | {
|
---|
213 | HRESULT res;
|
---|
214 | CHAR* filePathA;
|
---|
215 | WCHAR* filePathW;
|
---|
216 | ULONG bread;
|
---|
217 | WORD wbuffer;
|
---|
218 | DWORD dwbuffer,length,i,doubleLenHex,doubleLenDec;
|
---|
219 |
|
---|
220 | ICOM_THIS(FileMonikerImpl,iface);
|
---|
221 |
|
---|
222 | TRACE("(%p,%p)\n",iface,pStm);
|
---|
223 |
|
---|
224 | /* this function locate and read from the stream the filePath string writen by FileMonikerImpl_Save */
|
---|
225 |
|
---|
226 | /* first WORD is non significative */
|
---|
227 | res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
|
---|
228 | if (bread!=sizeof(WORD) || wbuffer!=0)
|
---|
229 | return E_FAIL;
|
---|
230 |
|
---|
231 | /* read filePath string length (plus one) */
|
---|
232 | res=IStream_Read(pStm,&length,sizeof(DWORD),&bread);
|
---|
233 | if (bread != sizeof(DWORD))
|
---|
234 | return E_FAIL;
|
---|
235 |
|
---|
236 | /* read filePath string */
|
---|
237 | filePathA=(CHAR*)HeapAlloc(GetProcessHeap(),0,length);
|
---|
238 | res=IStream_Read(pStm,filePathA,length,&bread);
|
---|
239 | if (bread != length)
|
---|
240 | return E_FAIL;
|
---|
241 |
|
---|
242 | /* read the first constant */
|
---|
243 | IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
|
---|
244 | if (bread != sizeof(DWORD) || dwbuffer != 0xDEADFFFF)
|
---|
245 | return E_FAIL;
|
---|
246 |
|
---|
247 | length--;
|
---|
248 |
|
---|
249 | for(i=0;i<10;i++){
|
---|
250 | res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
|
---|
251 | if (bread!=sizeof(WORD) || wbuffer!=0)
|
---|
252 | return E_FAIL;
|
---|
253 | }
|
---|
254 |
|
---|
255 | if (length>8)
|
---|
256 | length=0;
|
---|
257 |
|
---|
258 | doubleLenHex=doubleLenDec=2*length;
|
---|
259 | if (length > 5)
|
---|
260 | doubleLenDec+=6;
|
---|
261 |
|
---|
262 | res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
|
---|
263 | if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenDec)
|
---|
264 | return E_FAIL;
|
---|
265 |
|
---|
266 | if (length==0)
|
---|
267 | return res;
|
---|
268 |
|
---|
269 | res=IStream_Read(pStm,&dwbuffer,sizeof(DWORD),&bread);
|
---|
270 | if (bread!=sizeof(DWORD) || dwbuffer!=doubleLenHex)
|
---|
271 | return E_FAIL;
|
---|
272 |
|
---|
273 | res=IStream_Read(pStm,&wbuffer,sizeof(WORD),&bread);
|
---|
274 | if (bread!=sizeof(WORD) || wbuffer!=0x3)
|
---|
275 | return E_FAIL;
|
---|
276 |
|
---|
277 | filePathW=(WCHAR*)HeapAlloc(GetProcessHeap(),0,(length+1)*sizeof(WCHAR));
|
---|
278 | filePathW[length]=0;
|
---|
279 | res=IStream_Read(pStm,filePathW,doubleLenHex,&bread);
|
---|
280 | if (bread!=doubleLenHex)
|
---|
281 | return E_FAIL;
|
---|
282 |
|
---|
283 | if (This->filePathName!=NULL)
|
---|
284 | HeapFree(GetProcessHeap(),0,This->filePathName);
|
---|
285 |
|
---|
286 | This->filePathName=filePathW;
|
---|
287 |
|
---|
288 | HeapFree(GetProcessHeap(),0,filePathA);
|
---|
289 |
|
---|
290 | return res;
|
---|
291 | }
|
---|
292 |
|
---|
293 | /******************************************************************************
|
---|
294 | * FileMoniker_Save
|
---|
295 | ******************************************************************************/
|
---|
296 | HRESULT WINAPI FileMonikerImpl_Save(IMoniker* iface,
|
---|
297 | IStream* pStm,/* poniter to the stream where the object is to be saved */
|
---|
298 | BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
|
---|
299 | {
|
---|
300 | /* this function saves data of this object. In the begining I thougth that I have just to write
|
---|
301 | * the filePath string on Stream. But, when I tested this function whith windows programs samples !
|
---|
302 | * I noted that it was not the case. So I analysed data writen by this function on Windows system and
|
---|
303 | * what did this function do exactly ! but I have no idear a bout its logic !
|
---|
304 | * I guessed data who must be writen on stream wich is:
|
---|
305 | * 1) WORD constant:zero 2) length of the path string ("\0" included) 3) path string type A
|
---|
306 | * 4) DWORD constant : 0xDEADFFFF 5) ten WORD constant: zero 6) DWORD: double-length of the the path
|
---|
307 | * string type W ("\0" not included) 7) WORD constant: 0x3 8) filePath unicode string.
|
---|
308 | * if the length(filePath) > 8 or.length(filePath) == 8 stop at step 5)
|
---|
309 | */
|
---|
310 |
|
---|
311 | ICOM_THIS(FileMonikerImpl,iface);
|
---|
312 |
|
---|
313 | HRESULT res;
|
---|
314 | LPOLESTR filePathW=This->filePathName;
|
---|
315 | CHAR* filePathA;
|
---|
316 | DWORD len=1+lstrlenW(filePathW);
|
---|
317 |
|
---|
318 | DWORD constant1 = 0xDEADFFFF; /* these constants are detected after analysing the data structure writen by */
|
---|
319 | WORD constant2 = 0x3; /* FileMoniker_Save function in a windows program system */
|
---|
320 |
|
---|
321 | WORD zero=0;
|
---|
322 | DWORD doubleLenHex;
|
---|
323 | DWORD doubleLenDec;
|
---|
324 | int i=0;
|
---|
325 |
|
---|
326 | TRACE("(%p,%p,%d)\n",iface,pStm,fClearDirty);
|
---|
327 |
|
---|
328 | if (pStm==NULL)
|
---|
329 | return E_POINTER;
|
---|
330 |
|
---|
331 | /* write a DWORD seted to 0 : constant */
|
---|
332 | res=IStream_Write(pStm,&zero,sizeof(WORD),NULL);
|
---|
333 |
|
---|
334 | /* write length of filePath string ( "\0" included )*/
|
---|
335 | res=IStream_Write(pStm,&len,sizeof(DWORD),NULL);
|
---|
336 |
|
---|
337 | /* write filePath string type A */
|
---|
338 | filePathA=(CHAR *)HeapAlloc(GetProcessHeap(),0,len);
|
---|
339 | lstrcpyWtoA(filePathA,filePathW);
|
---|
340 | res=IStream_Write(pStm,filePathA,len,NULL);
|
---|
341 | HeapFree(GetProcessHeap(),0,filePathA);
|
---|
342 |
|
---|
343 | /* write a DWORD seted to 0xDEADFFFF: constant */
|
---|
344 | res=IStream_Write(pStm,&constant1,sizeof(DWORD),NULL);
|
---|
345 |
|
---|
346 | len--;
|
---|
347 | /* write 10 times a DWORD seted to 0 : constants */
|
---|
348 | for(i=0;i<10;i++)
|
---|
349 | res=IStream_Write(pStm,&zero,sizeof(WORD),NULL);
|
---|
350 |
|
---|
351 | if (len>8)
|
---|
352 | len=0;
|
---|
353 |
|
---|
354 | doubleLenHex=doubleLenDec=2*len;
|
---|
355 | if (len > 5)
|
---|
356 | doubleLenDec+=6;
|
---|
357 |
|
---|
358 | /* write double-length of the path string ( "\0" included )*/
|
---|
359 | res=IStream_Write(pStm,&doubleLenDec,sizeof(DWORD),NULL);
|
---|
360 |
|
---|
361 | if (len==0)
|
---|
362 | return res;
|
---|
363 |
|
---|
364 | /* write double-length (hexa representation) of the path string ( "\0" included ) */
|
---|
365 | res=IStream_Write(pStm,&doubleLenHex,sizeof(DWORD),NULL);
|
---|
366 |
|
---|
367 | /* write a WORD seted to 0x3: constant */
|
---|
368 | res=IStream_Write(pStm,&constant2,sizeof(WORD),NULL);
|
---|
369 |
|
---|
370 | /* write path unicode string */
|
---|
371 | res=IStream_Write(pStm,filePathW,doubleLenHex,NULL);
|
---|
372 |
|
---|
373 | return res;
|
---|
374 | }
|
---|
375 |
|
---|
376 | /******************************************************************************
|
---|
377 | * FileMoniker_GetSizeMax
|
---|
378 | ******************************************************************************/
|
---|
379 | HRESULT WINAPI FileMonikerImpl_GetSizeMax(IMoniker* iface,
|
---|
380 | ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
|
---|
381 | {
|
---|
382 | ICOM_THIS(FileMonikerImpl,iface);
|
---|
383 | DWORD len=lstrlenW(This->filePathName);
|
---|
384 | DWORD sizeMAx;
|
---|
385 |
|
---|
386 | TRACE("(%p,%p)\n",iface,pcbSize);
|
---|
387 |
|
---|
388 | if (pcbSize!=NULL)
|
---|
389 | return E_POINTER;
|
---|
390 |
|
---|
391 | /* for more details see FileMonikerImpl_Save coments */
|
---|
392 |
|
---|
393 | sizeMAx = sizeof(WORD) + /* first WORD is 0 */
|
---|
394 | sizeof(DWORD)+ /* length of filePath including "\0" in the end of the string */
|
---|
395 | (len+1)+ /* filePath string */
|
---|
396 | sizeof(DWORD)+ /* constant : 0xDEADFFFF */
|
---|
397 | 10*sizeof(WORD)+ /* 10 zero WORD */
|
---|
398 | sizeof(DWORD); /* size of the unicode filePath: "\0" not included */
|
---|
399 |
|
---|
400 | if (len==0 || len > 8)
|
---|
401 | return S_OK;
|
---|
402 |
|
---|
403 | sizeMAx += sizeof(DWORD)+ /* size of the unicode filePath: "\0" not included */
|
---|
404 | sizeof(WORD)+ /* constant : 0x3 */
|
---|
405 | len*sizeof(WCHAR); /* unicde filePath string */
|
---|
406 |
|
---|
407 | pcbSize->LowPart=sizeMAx;
|
---|
408 | pcbSize->HighPart=0;
|
---|
409 |
|
---|
410 | return S_OK;
|
---|
411 | }
|
---|
412 |
|
---|
413 | /******************************************************************************
|
---|
414 | * FileMoniker_Construct (local function)
|
---|
415 | *******************************************************************************/
|
---|
416 | HRESULT WINAPI FileMonikerImpl_Construct(FileMonikerImpl* This, LPCOLESTR lpszPathName)
|
---|
417 | {
|
---|
418 | int nb=0,i;
|
---|
419 | int sizeStr=lstrlenW(lpszPathName);
|
---|
420 | LPOLESTR *tabStr=0;
|
---|
421 | WCHAR twoPoint[]={'.','.',0};
|
---|
422 | WCHAR bkSlash[]={'\\',0};
|
---|
423 | BYTE addBkSlash;
|
---|
424 |
|
---|
425 | TRACE("(%p,%p)\n",This,lpszPathName);
|
---|
426 |
|
---|
427 | /* Initialize the virtual fgunction table. */
|
---|
428 | This->lpvtbl1 = &VT_FileMonikerImpl;
|
---|
429 | This->lpvtbl2 = &VT_ROTDataImpl;
|
---|
430 | This->ref = 0;
|
---|
431 |
|
---|
432 | This->filePathName=(WCHAR *)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr+1));
|
---|
433 |
|
---|
434 | if (This->filePathName==NULL)
|
---|
435 | return E_OUTOFMEMORY;
|
---|
436 |
|
---|
437 | lstrcpyW(This->filePathName,lpszPathName);
|
---|
438 |
|
---|
439 | nb=FileMonikerImpl_DecomposePath(This->filePathName,&tabStr);
|
---|
440 |
|
---|
441 | if (nb > 0 ){
|
---|
442 |
|
---|
443 | addBkSlash=1;
|
---|
444 | if (lstrcmpW(tabStr[0],twoPoint)!=0)
|
---|
445 | addBkSlash=0;
|
---|
446 | else
|
---|
447 | for(i=0;i<nb;i++){
|
---|
448 |
|
---|
449 | if ( (lstrcmpW(tabStr[i],twoPoint)!=0) && (lstrcmpW(tabStr[i],bkSlash)!=0) ){
|
---|
450 | addBkSlash=0;
|
---|
451 | break;
|
---|
452 | }
|
---|
453 | else
|
---|
454 |
|
---|
455 | if (lstrcmpW(tabStr[i],bkSlash)==0 && i<nb-1 && lstrcmpW(tabStr[i+1],bkSlash)==0){
|
---|
456 | *tabStr[i]=0;
|
---|
457 | sizeStr--;
|
---|
458 | addBkSlash=0;
|
---|
459 | break;
|
---|
460 | }
|
---|
461 | }
|
---|
462 |
|
---|
463 | if (lstrcmpW(tabStr[nb-1],bkSlash)==0)
|
---|
464 | addBkSlash=0;
|
---|
465 |
|
---|
466 | This->filePathName=(WCHAR *)HeapReAlloc(GetProcessHeap(),0,This->filePathName,(sizeStr+1)*sizeof(WCHAR));
|
---|
467 |
|
---|
468 | *This->filePathName=0;
|
---|
469 |
|
---|
470 | for(i=0;tabStr[i]!=NULL;i++)
|
---|
471 | lstrcatW(This->filePathName,tabStr[i]);
|
---|
472 |
|
---|
473 | if (addBkSlash)
|
---|
474 | lstrcatW(This->filePathName,bkSlash);
|
---|
475 | }
|
---|
476 |
|
---|
477 | for(i=0; tabStr[i]!=NULL;i++)
|
---|
478 | CoTaskMemFree(tabStr[i]);
|
---|
479 | CoTaskMemFree(tabStr);
|
---|
480 |
|
---|
481 | return S_OK;
|
---|
482 | }
|
---|
483 |
|
---|
484 | /******************************************************************************
|
---|
485 | * FileMoniker_Destroy (local function)
|
---|
486 | *******************************************************************************/
|
---|
487 | HRESULT WINAPI FileMonikerImpl_Destroy(FileMonikerImpl* This)
|
---|
488 | {
|
---|
489 | TRACE("(%p)\n",This);
|
---|
490 |
|
---|
491 | if (This->filePathName!=NULL)
|
---|
492 | HeapFree(GetProcessHeap(),0,This->filePathName);
|
---|
493 |
|
---|
494 | HeapFree(GetProcessHeap(),0,This);
|
---|
495 |
|
---|
496 | return S_OK;
|
---|
497 | }
|
---|
498 |
|
---|
499 | /******************************************************************************
|
---|
500 | * FileMoniker_BindToObject
|
---|
501 | ******************************************************************************/
|
---|
502 | HRESULT WINAPI FileMonikerImpl_BindToObject(IMoniker* iface,
|
---|
503 | IBindCtx* pbc,
|
---|
504 | IMoniker* pmkToLeft,
|
---|
505 | REFIID riid,
|
---|
506 | VOID** ppvResult)
|
---|
507 | {
|
---|
508 | HRESULT res=E_FAIL;
|
---|
509 | CLSID clsID;
|
---|
510 | IUnknown* pObj=0;
|
---|
511 | IRunningObjectTable *prot=0;
|
---|
512 | IPersistFile *ppf=0;
|
---|
513 | IClassFactory *pcf=0;
|
---|
514 | IClassActivator *pca=0;
|
---|
515 |
|
---|
516 | ICOM_THIS(FileMonikerImpl,iface);
|
---|
517 |
|
---|
518 | *ppvResult=0;
|
---|
519 |
|
---|
520 | TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvResult);
|
---|
521 |
|
---|
522 | if(pmkToLeft==NULL){
|
---|
523 |
|
---|
524 | res=IBindCtx_GetRunningObjectTable(pbc,&prot);
|
---|
525 |
|
---|
526 | if (SUCCEEDED(res)){
|
---|
527 | /* if the requested class was loaded befor ! we dont need to reload it */
|
---|
528 | res = IRunningObjectTable_GetObject(prot,iface,&pObj);
|
---|
529 |
|
---|
530 | if (res==S_FALSE){
|
---|
531 | /* first activation of this class */
|
---|
532 | res=GetClassFile(This->filePathName,&clsID);
|
---|
533 | if (SUCCEEDED(res)){
|
---|
534 |
|
---|
535 | res=CoCreateInstance(&clsID,NULL,CLSCTX_ALL,&IID_IPersistFile,(void**)&ppf);
|
---|
536 | if (SUCCEEDED(res)){
|
---|
537 |
|
---|
538 | res=IPersistFile_Load(ppf,This->filePathName,STGM_READ);
|
---|
539 | if (SUCCEEDED(res)){
|
---|
540 |
|
---|
541 | pObj=(IUnknown*)ppf;
|
---|
542 | IUnknown_AddRef(pObj);
|
---|
543 | }
|
---|
544 | }
|
---|
545 | }
|
---|
546 | }
|
---|
547 | }
|
---|
548 | }
|
---|
549 | else{
|
---|
550 | res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassFactory,(void**)&pcf);
|
---|
551 |
|
---|
552 | if (res==E_NOINTERFACE){
|
---|
553 |
|
---|
554 | res=IMoniker_BindToObject(pmkToLeft,pbc,NULL,&IID_IClassActivator,(void**)&pca);
|
---|
555 |
|
---|
556 | if (res==E_NOINTERFACE)
|
---|
557 | return MK_E_INTERMEDIATEINTERFACENOTSUPPORTED;
|
---|
558 | }
|
---|
559 | if (pcf!=NULL){
|
---|
560 |
|
---|
561 | IClassFactory_CreateInstance(pcf,NULL,&IID_IPersistFile,(void**)ppf);
|
---|
562 |
|
---|
563 | res=IPersistFile_Load(ppf,This->filePathName,STGM_READ);
|
---|
564 |
|
---|
565 | if (SUCCEEDED(res)){
|
---|
566 |
|
---|
567 | pObj=(IUnknown*)ppf;
|
---|
568 | IUnknown_AddRef(pObj);
|
---|
569 | }
|
---|
570 | }
|
---|
571 | if (pca!=NULL){
|
---|
572 |
|
---|
573 | FIXME("()");
|
---|
574 |
|
---|
575 | /*res=GetClassFile(This->filePathName,&clsID);
|
---|
576 |
|
---|
577 | if (SUCCEEDED(res)){
|
---|
578 |
|
---|
579 | res=IClassActivator_GetClassObject(pca,&clsID,CLSCTX_ALL,0,&IID_IPersistFile,(void**)&ppf);
|
---|
580 |
|
---|
581 | if (SUCCEEDED(res)){
|
---|
582 |
|
---|
583 | pObj=(IUnknown*)ppf;
|
---|
584 | IUnknown_AddRef(pObj);
|
---|
585 | }
|
---|
586 | }*/
|
---|
587 | }
|
---|
588 | }
|
---|
589 |
|
---|
590 | if (pObj!=NULL){
|
---|
591 | /* get the requested interface from the loaded class */
|
---|
592 | res= IUnknown_QueryInterface(pObj,riid,ppvResult);
|
---|
593 |
|
---|
594 | IBindCtx_RegisterObjectBound(pbc,(IUnknown*)*ppvResult);
|
---|
595 |
|
---|
596 | IUnknown_Release(pObj);
|
---|
597 | }
|
---|
598 |
|
---|
599 | if (prot!=NULL)
|
---|
600 | IRunningObjectTable_Release(prot);
|
---|
601 |
|
---|
602 | if (ppf!=NULL)
|
---|
603 | IPersistFile_Release(ppf);
|
---|
604 |
|
---|
605 | if (pca!=NULL)
|
---|
606 | IClassActivator_Release(pca);
|
---|
607 |
|
---|
608 | if (pcf!=NULL)
|
---|
609 | IClassFactory_Release(pcf);
|
---|
610 |
|
---|
611 | return res;
|
---|
612 | }
|
---|
613 |
|
---|
614 | /******************************************************************************
|
---|
615 | * FileMoniker_BindToStorage
|
---|
616 | ******************************************************************************/
|
---|
617 | HRESULT WINAPI FileMonikerImpl_BindToStorage(IMoniker* iface,
|
---|
618 | IBindCtx* pbc,
|
---|
619 | IMoniker* pmkToLeft,
|
---|
620 | REFIID riid,
|
---|
621 | VOID** ppvObject)
|
---|
622 | {
|
---|
623 | LPOLESTR filePath=0;
|
---|
624 | IStorage *pstg=0;
|
---|
625 | HRESULT res;
|
---|
626 |
|
---|
627 | TRACE("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject);
|
---|
628 |
|
---|
629 | if (pmkToLeft==NULL){
|
---|
630 |
|
---|
631 | if (IsEqualIID(&IID_IStorage, riid)){
|
---|
632 |
|
---|
633 | /* get the file name */
|
---|
634 | FileMonikerImpl_GetDisplayName(iface,pbc,pmkToLeft,&filePath);
|
---|
635 |
|
---|
636 | /* verifie if the file contains a storage object */
|
---|
637 | res=StgIsStorageFile(filePath);
|
---|
638 |
|
---|
639 | if(res==S_OK){
|
---|
640 |
|
---|
641 | res=StgOpenStorage(filePath,NULL,STGM_READWRITE|STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
|
---|
642 |
|
---|
643 | if (SUCCEEDED(res)){
|
---|
644 |
|
---|
645 | *ppvObject=pstg;
|
---|
646 |
|
---|
647 | IStorage_AddRef(pstg);
|
---|
648 |
|
---|
649 | return res;
|
---|
650 | }
|
---|
651 | }
|
---|
652 | CoTaskMemFree(filePath);
|
---|
653 | }
|
---|
654 | else
|
---|
655 | if ( (IsEqualIID(&IID_IStream, riid)) || (IsEqualIID(&IID_ILockBytes, riid)) )
|
---|
656 |
|
---|
657 | return E_UNSPEC;
|
---|
658 | else
|
---|
659 |
|
---|
660 | return E_NOINTERFACE;
|
---|
661 | }
|
---|
662 | else {
|
---|
663 |
|
---|
664 | FIXME("(%p,%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,riid,ppvObject);
|
---|
665 |
|
---|
666 | return E_NOTIMPL;
|
---|
667 | }
|
---|
668 | return res;
|
---|
669 | }
|
---|
670 |
|
---|
671 | /******************************************************************************
|
---|
672 | * FileMoniker_Reduce
|
---|
673 | ******************************************************************************/
|
---|
674 | HRESULT WINAPI FileMonikerImpl_Reduce(IMoniker* iface,
|
---|
675 | IBindCtx* pbc,
|
---|
676 | DWORD dwReduceHowFar,
|
---|
677 | IMoniker** ppmkToLeft,
|
---|
678 | IMoniker** ppmkReduced)
|
---|
679 | {
|
---|
680 | TRACE("(%p,%p,%ld,%p,%p)\n",iface,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
|
---|
681 |
|
---|
682 | if (ppmkReduced==NULL)
|
---|
683 | return E_POINTER;
|
---|
684 |
|
---|
685 | FileMonikerImpl_AddRef(iface);
|
---|
686 |
|
---|
687 | *ppmkReduced=iface;
|
---|
688 |
|
---|
689 | return MK_S_REDUCED_TO_SELF;
|
---|
690 | }
|
---|
691 | /******************************************************************************
|
---|
692 | * FileMoniker_ComposeWith
|
---|
693 | ******************************************************************************/
|
---|
694 | HRESULT WINAPI FileMonikerImpl_ComposeWith(IMoniker* iface,
|
---|
695 | IMoniker* pmkRight,
|
---|
696 | BOOL fOnlyIfNotGeneric,
|
---|
697 | IMoniker** ppmkComposite)
|
---|
698 | {
|
---|
699 | HRESULT res;
|
---|
700 | LPOLESTR str1=0,str2=0,*strDec1=0,*strDec2=0,newStr=0;
|
---|
701 | WCHAR twoPoint[]={'.','.',0};
|
---|
702 | WCHAR bkSlash[]={'\\',0};
|
---|
703 | IBindCtx *bind=0;
|
---|
704 | int i=0,j=0,lastIdx1=0,lastIdx2=0;
|
---|
705 | DWORD mkSys;
|
---|
706 |
|
---|
707 | TRACE("(%p,%p,%d,%p)\n",iface,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
|
---|
708 |
|
---|
709 | if (ppmkComposite==NULL)
|
---|
710 | return E_POINTER;
|
---|
711 |
|
---|
712 | if (pmkRight==NULL)
|
---|
713 | return E_INVALIDARG;
|
---|
714 |
|
---|
715 | *ppmkComposite=0;
|
---|
716 |
|
---|
717 | IMoniker_IsSystemMoniker(pmkRight,&mkSys);
|
---|
718 |
|
---|
719 | /* check if we have two filemonikers to compose or not */
|
---|
720 | if(mkSys==MKSYS_FILEMONIKER){
|
---|
721 |
|
---|
722 | CreateBindCtx(0,&bind);
|
---|
723 |
|
---|
724 | FileMonikerImpl_GetDisplayName(iface,bind,NULL,&str1);
|
---|
725 | IMoniker_GetDisplayName(pmkRight,bind,NULL,&str2);
|
---|
726 |
|
---|
727 | /* decompose pathnames of the two monikers : (to prepare the path merge operation ) */
|
---|
728 | lastIdx1=FileMonikerImpl_DecomposePath(str1,&strDec1)-1;
|
---|
729 | lastIdx2=FileMonikerImpl_DecomposePath(str2,&strDec2)-1;
|
---|
730 |
|
---|
731 | if ((lastIdx1==-1 && lastIdx2>-1)||(lastIdx1==1 && lstrcmpW(strDec1[0],twoPoint)==0))
|
---|
732 | return MK_E_SYNTAX;
|
---|
733 |
|
---|
734 | if(lstrcmpW(strDec1[lastIdx1],bkSlash)==0)
|
---|
735 | lastIdx1--;
|
---|
736 |
|
---|
737 | /* for etch "..\" in the left of str2 remove the right element from str1 */
|
---|
738 | for(i=0; ( (lastIdx1>=0) && (strDec2[i]!=NULL) && (lstrcmpW(strDec2[i],twoPoint)==0) ) ;i+=2){
|
---|
739 |
|
---|
740 | lastIdx1-=2;
|
---|
741 | }
|
---|
742 |
|
---|
743 | /* the length of the composed path string is raised by the sum of the two paths lengths */
|
---|
744 | newStr=(WCHAR *)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(lstrlenW(str1)+lstrlenW(str2)+1));
|
---|
745 |
|
---|
746 | if (newStr==NULL)
|
---|
747 | return E_OUTOFMEMORY;
|
---|
748 |
|
---|
749 | /* new path is the concatenation of the rest of str1 and str2 */
|
---|
750 | for(*newStr=0,j=0;j<=lastIdx1;j++)
|
---|
751 | lstrcatW(newStr,strDec1[j]);
|
---|
752 |
|
---|
753 | if ((strDec2[i]==NULL && lastIdx1>-1 && lastIdx2>-1) || lstrcmpW(strDec2[i],bkSlash)!=0)
|
---|
754 | lstrcatW(newStr,bkSlash);
|
---|
755 |
|
---|
756 | for(j=i;j<=lastIdx2;j++)
|
---|
757 | lstrcatW(newStr,strDec2[j]);
|
---|
758 |
|
---|
759 | /* create a new moniker with the new string */
|
---|
760 | res=CreateFileMoniker(newStr,ppmkComposite);
|
---|
761 |
|
---|
762 | /* free all strings space memory used by this function */
|
---|
763 | HeapFree(GetProcessHeap(),0,newStr);
|
---|
764 |
|
---|
765 | for(i=0; strDec1[i]!=NULL;i++)
|
---|
766 | CoTaskMemFree(strDec1[i]);
|
---|
767 | for(i=0; strDec2[i]!=NULL;i++)
|
---|
768 | CoTaskMemFree(strDec2[i]);
|
---|
769 | CoTaskMemFree(strDec1);
|
---|
770 | CoTaskMemFree(strDec2);
|
---|
771 |
|
---|
772 | CoTaskMemFree(str1);
|
---|
773 | CoTaskMemFree(str2);
|
---|
774 |
|
---|
775 | return res;
|
---|
776 | }
|
---|
777 | else if(mkSys==MKSYS_ANTIMONIKER){
|
---|
778 |
|
---|
779 | *ppmkComposite=NULL;
|
---|
780 | return S_OK;
|
---|
781 | }
|
---|
782 | else if (fOnlyIfNotGeneric){
|
---|
783 |
|
---|
784 | *ppmkComposite=NULL;
|
---|
785 | return MK_E_NEEDGENERIC;
|
---|
786 | }
|
---|
787 | else
|
---|
788 |
|
---|
789 | return CreateGenericComposite(iface,pmkRight,ppmkComposite);
|
---|
790 | }
|
---|
791 |
|
---|
792 | /******************************************************************************
|
---|
793 | * FileMoniker_Enum
|
---|
794 | ******************************************************************************/
|
---|
795 | HRESULT WINAPI FileMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
|
---|
796 | {
|
---|
797 | TRACE("(%p,%d,%p)\n",iface,fForward,ppenumMoniker);
|
---|
798 |
|
---|
799 | if (ppenumMoniker == NULL)
|
---|
800 | return E_POINTER;
|
---|
801 |
|
---|
802 | *ppenumMoniker = NULL;
|
---|
803 |
|
---|
804 | return S_OK;
|
---|
805 | }
|
---|
806 |
|
---|
807 | /******************************************************************************
|
---|
808 | * FileMoniker_IsEqual
|
---|
809 | ******************************************************************************/
|
---|
810 | HRESULT WINAPI FileMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
|
---|
811 | {
|
---|
812 | ICOM_THIS(FileMonikerImpl,iface);
|
---|
813 | CLSID clsid;
|
---|
814 | LPOLESTR filePath;
|
---|
815 | IBindCtx* bind;
|
---|
816 | HRESULT res;
|
---|
817 |
|
---|
818 | TRACE("(%p,%p)\n",iface,pmkOtherMoniker);
|
---|
819 |
|
---|
820 | if (pmkOtherMoniker==NULL)
|
---|
821 | return S_FALSE;
|
---|
822 |
|
---|
823 | IMoniker_GetClassID(pmkOtherMoniker,&clsid);
|
---|
824 |
|
---|
825 | if (!IsEqualCLSID(&clsid,&CLSID_FileMoniker))
|
---|
826 |
|
---|
827 | return S_FALSE;
|
---|
828 |
|
---|
829 | res=CreateBindCtx(0,&bind);
|
---|
830 | if (FAILED(res))
|
---|
831 | return res;
|
---|
832 |
|
---|
833 | IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&filePath);
|
---|
834 |
|
---|
835 | if (lstrcmpiW(filePath,
|
---|
836 | This->filePathName)!=0)
|
---|
837 |
|
---|
838 | return S_FALSE;
|
---|
839 |
|
---|
840 | return S_OK;
|
---|
841 | }
|
---|
842 |
|
---|
843 | /******************************************************************************
|
---|
844 | * FileMoniker_Hash
|
---|
845 | ******************************************************************************/
|
---|
846 | HRESULT WINAPI FileMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
|
---|
847 | {
|
---|
848 | ICOM_THIS(FileMonikerImpl,iface);
|
---|
849 |
|
---|
850 | int h = 0,i,skip,len;
|
---|
851 | int off = 0;
|
---|
852 | LPOLESTR val;
|
---|
853 |
|
---|
854 | if (pdwHash==NULL)
|
---|
855 | return E_POINTER;
|
---|
856 |
|
---|
857 | val = This->filePathName;
|
---|
858 | len = lstrlenW(val);
|
---|
859 |
|
---|
860 | if (len < 16) {
|
---|
861 | for (i = len ; i > 0; i--) {
|
---|
862 | h = (h * 37) + val[off++];
|
---|
863 | }
|
---|
864 | } else {
|
---|
865 | /* only sample some characters */
|
---|
866 | skip = len / 8;
|
---|
867 | for (i = len ; i > 0; i -= skip, off += skip) {
|
---|
868 | h = (h * 39) + val[off];
|
---|
869 | }
|
---|
870 | }
|
---|
871 |
|
---|
872 | *pdwHash=h;
|
---|
873 |
|
---|
874 | return S_OK;
|
---|
875 | }
|
---|
876 |
|
---|
877 | /******************************************************************************
|
---|
878 | * FileMoniker_IsRunning
|
---|
879 | ******************************************************************************/
|
---|
880 | HRESULT WINAPI FileMonikerImpl_IsRunning(IMoniker* iface,
|
---|
881 | IBindCtx* pbc,
|
---|
882 | IMoniker* pmkToLeft,
|
---|
883 | IMoniker* pmkNewlyRunning)
|
---|
884 | {
|
---|
885 | IRunningObjectTable* rot;
|
---|
886 | HRESULT res;
|
---|
887 |
|
---|
888 | TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pmkNewlyRunning);
|
---|
889 |
|
---|
890 | if ( (pmkNewlyRunning!=NULL) && (IMoniker_IsEqual(pmkNewlyRunning,iface)==S_OK) )
|
---|
891 | return S_OK;
|
---|
892 |
|
---|
893 | if (pbc==NULL)
|
---|
894 | return E_POINTER;
|
---|
895 |
|
---|
896 | res=IBindCtx_GetRunningObjectTable(pbc,&rot);
|
---|
897 |
|
---|
898 | if (FAILED(res))
|
---|
899 | return res;
|
---|
900 |
|
---|
901 | res = IRunningObjectTable_IsRunning(rot,iface);
|
---|
902 |
|
---|
903 | IRunningObjectTable_Release(rot);
|
---|
904 |
|
---|
905 | return res;
|
---|
906 | }
|
---|
907 |
|
---|
908 | /******************************************************************************
|
---|
909 | * FileMoniker_GetTimeOfLastChange
|
---|
910 | ******************************************************************************/
|
---|
911 | HRESULT WINAPI FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
|
---|
912 | IBindCtx* pbc,
|
---|
913 | IMoniker* pmkToLeft,
|
---|
914 | FILETIME* pFileTime)
|
---|
915 | {
|
---|
916 | ICOM_THIS(FileMonikerImpl,iface);
|
---|
917 | IRunningObjectTable* rot;
|
---|
918 | HRESULT res;
|
---|
919 | WIN32_FILE_ATTRIBUTE_DATA info;
|
---|
920 |
|
---|
921 | TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pFileTime);
|
---|
922 |
|
---|
923 | if (pFileTime==NULL)
|
---|
924 | return E_POINTER;
|
---|
925 |
|
---|
926 | if (pmkToLeft!=NULL)
|
---|
927 | return E_INVALIDARG;
|
---|
928 |
|
---|
929 | res=IBindCtx_GetRunningObjectTable(pbc,&rot);
|
---|
930 |
|
---|
931 | if (FAILED(res))
|
---|
932 | return res;
|
---|
933 |
|
---|
934 | res= IRunningObjectTable_GetTimeOfLastChange(rot,iface,pFileTime);
|
---|
935 |
|
---|
936 | if (FAILED(res))
|
---|
937 | { /* the moniker is not registred */
|
---|
938 |
|
---|
939 | if (!GetFileAttributesExW(This->filePathName, GetFileExInfoStandard, &info))
|
---|
940 | return MK_E_NOOBJECT;
|
---|
941 |
|
---|
942 | *pFileTime=info.ftLastWriteTime;
|
---|
943 | }
|
---|
944 |
|
---|
945 | return S_OK;
|
---|
946 | }
|
---|
947 |
|
---|
948 | /******************************************************************************
|
---|
949 | * FileMoniker_Inverse
|
---|
950 | ******************************************************************************/
|
---|
951 | HRESULT WINAPI FileMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
|
---|
952 | {
|
---|
953 |
|
---|
954 | TRACE("(%p,%p)\n",iface,ppmk);
|
---|
955 |
|
---|
956 | return CreateAntiMoniker(ppmk);
|
---|
957 | }
|
---|
958 |
|
---|
959 | /******************************************************************************
|
---|
960 | * FileMoniker_CommonPrefixWith
|
---|
961 | ******************************************************************************/
|
---|
962 | HRESULT WINAPI FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
|
---|
963 | {
|
---|
964 |
|
---|
965 | LPOLESTR pathThis,pathOther,*stringTable1,*stringTable2,commonPath;
|
---|
966 | IBindCtx *pbind;
|
---|
967 | DWORD mkSys;
|
---|
968 | ULONG nb1,nb2,i,sameIdx;
|
---|
969 | BOOL machimeNameCase=FALSE;
|
---|
970 |
|
---|
971 | if (ppmkPrefix==NULL)
|
---|
972 | return E_POINTER;
|
---|
973 |
|
---|
974 | if (pmkOther==NULL)
|
---|
975 | return E_INVALIDARG;
|
---|
976 |
|
---|
977 | *ppmkPrefix=0;
|
---|
978 |
|
---|
979 | /* check if we have the same type of moniker */
|
---|
980 | IMoniker_IsSystemMoniker(pmkOther,&mkSys);
|
---|
981 |
|
---|
982 | if(mkSys==MKSYS_FILEMONIKER){
|
---|
983 |
|
---|
984 | CreateBindCtx(0,&pbind);
|
---|
985 |
|
---|
986 | /* create a string based on common part of the two paths */
|
---|
987 |
|
---|
988 | IMoniker_GetDisplayName(iface,pbind,NULL,&pathThis);
|
---|
989 | IMoniker_GetDisplayName(pmkOther,pbind,NULL,&pathOther);
|
---|
990 |
|
---|
991 | nb1=FileMonikerImpl_DecomposePath(pathThis,&stringTable1);
|
---|
992 | nb2=FileMonikerImpl_DecomposePath(pathOther,&stringTable2);
|
---|
993 |
|
---|
994 | if (nb1==0 || nb2==0)
|
---|
995 | return MK_E_NOPREFIX;
|
---|
996 |
|
---|
997 | commonPath=(WCHAR *)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(min(lstrlenW(pathThis),lstrlenW(pathOther))+1));
|
---|
998 |
|
---|
999 | *commonPath=0;
|
---|
1000 |
|
---|
1001 | for(sameIdx=0; ( (stringTable1[sameIdx]!=NULL) &&
|
---|
1002 | (stringTable2[sameIdx]!=NULL) &&
|
---|
1003 | (lstrcmpiW(stringTable1[sameIdx],stringTable2[sameIdx])==0)); sameIdx++);
|
---|
1004 |
|
---|
1005 | if (sameIdx > 1 && *stringTable1[0]=='\\' && *stringTable2[1]=='\\'){
|
---|
1006 |
|
---|
1007 | machimeNameCase=TRUE;
|
---|
1008 |
|
---|
1009 | for(i=2;i<sameIdx;i++)
|
---|
1010 |
|
---|
1011 | if( (*stringTable1[i]=='\\') && (i+1 < sameIdx) && (*stringTable1[i+1]=='\\') ){
|
---|
1012 | machimeNameCase=FALSE;
|
---|
1013 | break;
|
---|
1014 | }
|
---|
1015 | }
|
---|
1016 |
|
---|
1017 | if (machimeNameCase && *stringTable1[sameIdx-1]=='\\')
|
---|
1018 | sameIdx--;
|
---|
1019 |
|
---|
1020 | if (machimeNameCase && (sameIdx<=3) && (nb1 > 3 || nb2 > 3) )
|
---|
1021 | return MK_E_NOPREFIX;
|
---|
1022 |
|
---|
1023 | for(i=0;i<sameIdx;i++)
|
---|
1024 | lstrcatW(commonPath,stringTable1[i]);
|
---|
1025 |
|
---|
1026 | for(i=0;i<nb1;i++)
|
---|
1027 | CoTaskMemFree(stringTable1[i]);
|
---|
1028 |
|
---|
1029 | CoTaskMemFree(stringTable1);
|
---|
1030 |
|
---|
1031 | for(i=0;i<nb2;i++)
|
---|
1032 | CoTaskMemFree(stringTable2[i]);
|
---|
1033 |
|
---|
1034 | CoTaskMemFree(stringTable2);
|
---|
1035 |
|
---|
1036 | HeapFree(GetProcessHeap(),0,commonPath);
|
---|
1037 |
|
---|
1038 | return CreateFileMoniker(commonPath,ppmkPrefix);
|
---|
1039 | }
|
---|
1040 | else
|
---|
1041 | return MonikerCommonPrefixWith(iface,pmkOther,ppmkPrefix);
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | /******************************************************************************
|
---|
1045 | * DecomposePath (local function)
|
---|
1046 | ******************************************************************************/
|
---|
1047 | int WINAPI FileMonikerImpl_DecomposePath(LPOLESTR str, LPOLESTR** stringTable)
|
---|
1048 | {
|
---|
1049 | WCHAR bSlash[] = {'\\',0};
|
---|
1050 | WCHAR word[100];
|
---|
1051 | int i=0,j,tabIndex=0;
|
---|
1052 | LPOLESTR *strgtable ;
|
---|
1053 |
|
---|
1054 | int len=lstrlenW(str);
|
---|
1055 |
|
---|
1056 | strgtable = (LPOLESTR *)CoTaskMemAlloc(len*sizeof(LPOLESTR));
|
---|
1057 |
|
---|
1058 | if (strgtable==NULL)
|
---|
1059 | return E_OUTOFMEMORY;
|
---|
1060 |
|
---|
1061 | while(str[i]!=0){
|
---|
1062 |
|
---|
1063 | if(str[i]==bSlash[0]){
|
---|
1064 |
|
---|
1065 | strgtable[tabIndex]=(WCHAR *)CoTaskMemAlloc(2*sizeof(WCHAR));
|
---|
1066 |
|
---|
1067 | if (strgtable[tabIndex]==NULL)
|
---|
1068 | return E_OUTOFMEMORY;
|
---|
1069 |
|
---|
1070 | lstrcpyW(strgtable[tabIndex++],bSlash);
|
---|
1071 |
|
---|
1072 | i++;
|
---|
1073 |
|
---|
1074 | }
|
---|
1075 | else {
|
---|
1076 |
|
---|
1077 | for(j=0; str[i]!=0 && str[i]!=bSlash[0] ; i++,j++)
|
---|
1078 | word[j]=str[i];
|
---|
1079 |
|
---|
1080 | word[j]=0;
|
---|
1081 |
|
---|
1082 | strgtable[tabIndex]=(WCHAR *)CoTaskMemAlloc(sizeof(WCHAR)*(j+1));
|
---|
1083 |
|
---|
1084 | if (strgtable[tabIndex]==NULL)
|
---|
1085 | return E_OUTOFMEMORY;
|
---|
1086 |
|
---|
1087 | lstrcpyW(strgtable[tabIndex++],word);
|
---|
1088 | }
|
---|
1089 | }
|
---|
1090 | strgtable[tabIndex]=NULL;
|
---|
1091 |
|
---|
1092 | *stringTable=strgtable;
|
---|
1093 |
|
---|
1094 | return tabIndex;
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | /******************************************************************************
|
---|
1098 | * FileMoniker_RelativePathTo
|
---|
1099 | ******************************************************************************/
|
---|
1100 | HRESULT WINAPI FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
|
---|
1101 | {
|
---|
1102 | IBindCtx *bind;
|
---|
1103 | HRESULT res;
|
---|
1104 | LPOLESTR str1=0,str2=0,*tabStr1=0,*tabStr2=0,relPath=0;
|
---|
1105 | DWORD len1=0,len2=0,sameIdx=0,j=0;
|
---|
1106 | WCHAR back[] ={'.','.','\\',0};
|
---|
1107 |
|
---|
1108 | TRACE("(%p,%p,%p)\n",iface,pmOther,ppmkRelPath);
|
---|
1109 |
|
---|
1110 | if (ppmkRelPath==NULL)
|
---|
1111 | return E_POINTER;
|
---|
1112 |
|
---|
1113 | if (pmOther==NULL)
|
---|
1114 | return E_INVALIDARG;
|
---|
1115 |
|
---|
1116 | res=CreateBindCtx(0,&bind);
|
---|
1117 | if (FAILED(res))
|
---|
1118 | return res;
|
---|
1119 |
|
---|
1120 | res=IMoniker_GetDisplayName(iface,bind,NULL,&str1);
|
---|
1121 | if (FAILED(res))
|
---|
1122 | return res;
|
---|
1123 | res=IMoniker_GetDisplayName(pmOther,bind,NULL,&str2);
|
---|
1124 | if (FAILED(res))
|
---|
1125 | return res;
|
---|
1126 |
|
---|
1127 | len1=FileMonikerImpl_DecomposePath(str1,&tabStr1);
|
---|
1128 | len2=FileMonikerImpl_DecomposePath(str2,&tabStr2);
|
---|
1129 |
|
---|
1130 | if (FAILED(len1) || FAILED(len2))
|
---|
1131 | return E_OUTOFMEMORY;
|
---|
1132 |
|
---|
1133 | /* count the number of similar items from the begin of the two paths */
|
---|
1134 | for(sameIdx=0; ( (tabStr1[sameIdx]!=NULL) &&
|
---|
1135 | (tabStr2[sameIdx]!=NULL) &&
|
---|
1136 | (lstrcmpiW(tabStr1[sameIdx],tabStr2[sameIdx])==0)); sameIdx++);
|
---|
1137 |
|
---|
1138 | /* begin the construction of relativePath */
|
---|
1139 | /* if the two paths have a consecutive similar item from the begin ! the relativePath will be composed */
|
---|
1140 | /* by "..\\" in the begin */
|
---|
1141 | relPath=(WCHAR *)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(1+lstrlenW(str1)+lstrlenW(str2)));
|
---|
1142 |
|
---|
1143 | *relPath=0;
|
---|
1144 |
|
---|
1145 | if (len2>0 && !(len1==1 && len2==1 && sameIdx==0))
|
---|
1146 | for(j=sameIdx;(tabStr1[j] != NULL); j++)
|
---|
1147 | if (*tabStr1[j]!='\\')
|
---|
1148 | lstrcatW(relPath,back);
|
---|
1149 |
|
---|
1150 | /* add items of the second path (similar items with the first path are not included) to the relativePath */
|
---|
1151 | for(j=sameIdx;tabStr2[j]!=NULL;j++)
|
---|
1152 | lstrcatW(relPath,tabStr2[j]);
|
---|
1153 |
|
---|
1154 | res=CreateFileMoniker(relPath,ppmkRelPath);
|
---|
1155 |
|
---|
1156 | for(j=0; tabStr1[j]!=NULL;j++)
|
---|
1157 | CoTaskMemFree(tabStr1[j]);
|
---|
1158 | for(j=0; tabStr2[j]!=NULL;j++)
|
---|
1159 | CoTaskMemFree(tabStr2[j]);
|
---|
1160 | CoTaskMemFree(tabStr1);
|
---|
1161 | CoTaskMemFree(tabStr2);
|
---|
1162 | CoTaskMemFree(str1);
|
---|
1163 | CoTaskMemFree(str2);
|
---|
1164 | HeapFree(GetProcessHeap(),0,relPath);
|
---|
1165 |
|
---|
1166 | if (len1==0 || len2==0 || (len1==1 && len2==1 && sameIdx==0))
|
---|
1167 | return MK_S_HIM;
|
---|
1168 |
|
---|
1169 | return res;
|
---|
1170 | }
|
---|
1171 |
|
---|
1172 | /******************************************************************************
|
---|
1173 | * FileMoniker_GetDisplayName
|
---|
1174 | ******************************************************************************/
|
---|
1175 | HRESULT WINAPI FileMonikerImpl_GetDisplayName(IMoniker* iface,
|
---|
1176 | IBindCtx* pbc,
|
---|
1177 | IMoniker* pmkToLeft,
|
---|
1178 | LPOLESTR *ppszDisplayName)
|
---|
1179 | {
|
---|
1180 | ICOM_THIS(FileMonikerImpl,iface);
|
---|
1181 |
|
---|
1182 | int len=lstrlenW(This->filePathName);
|
---|
1183 |
|
---|
1184 | TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,ppszDisplayName);
|
---|
1185 |
|
---|
1186 | if (ppszDisplayName==NULL)
|
---|
1187 | return E_POINTER;
|
---|
1188 |
|
---|
1189 | if (pmkToLeft!=NULL)
|
---|
1190 | return E_INVALIDARG;
|
---|
1191 |
|
---|
1192 | *ppszDisplayName=(WCHAR *)CoTaskMemAlloc(sizeof(WCHAR)*(len+1));
|
---|
1193 | if (*ppszDisplayName==NULL)
|
---|
1194 | return E_OUTOFMEMORY;
|
---|
1195 |
|
---|
1196 | lstrcpyW(*ppszDisplayName,This->filePathName);
|
---|
1197 |
|
---|
1198 | return S_OK;
|
---|
1199 | }
|
---|
1200 |
|
---|
1201 | /******************************************************************************
|
---|
1202 | * FileMoniker_ParseDisplayName
|
---|
1203 | ******************************************************************************/
|
---|
1204 | HRESULT WINAPI FileMonikerImpl_ParseDisplayName(IMoniker* iface,
|
---|
1205 | IBindCtx* pbc,
|
---|
1206 | IMoniker* pmkToLeft,
|
---|
1207 | LPOLESTR pszDisplayName,
|
---|
1208 | ULONG* pchEaten,
|
---|
1209 | IMoniker** ppmkOut)
|
---|
1210 | {
|
---|
1211 | FIXME("(%p,%p,%p,%p,%p,%p),stub!\n",iface,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
|
---|
1212 | return E_NOTIMPL;
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | /******************************************************************************
|
---|
1216 | * FileMoniker_IsSystemMonker
|
---|
1217 | ******************************************************************************/
|
---|
1218 | HRESULT WINAPI FileMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
|
---|
1219 | {
|
---|
1220 | TRACE("(%p,%p)\n",iface,pwdMksys);
|
---|
1221 |
|
---|
1222 | if (!pwdMksys)
|
---|
1223 | return E_POINTER;
|
---|
1224 |
|
---|
1225 | (*pwdMksys)=MKSYS_FILEMONIKER;
|
---|
1226 |
|
---|
1227 | return S_OK;
|
---|
1228 | }
|
---|
1229 |
|
---|
1230 | /*******************************************************************************
|
---|
1231 | * FileMonikerIROTData_QueryInterface
|
---|
1232 | *******************************************************************************/
|
---|
1233 | HRESULT WINAPI FileMonikerROTDataImpl_QueryInterface(IROTData *iface,REFIID riid,VOID** ppvObject)
|
---|
1234 | {
|
---|
1235 |
|
---|
1236 | ICOM_THIS_From_IROTData(IMoniker, iface);
|
---|
1237 |
|
---|
1238 | TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
|
---|
1239 |
|
---|
1240 | return FileMonikerImpl_QueryInterface(This, riid, ppvObject);
|
---|
1241 | }
|
---|
1242 |
|
---|
1243 | /***********************************************************************
|
---|
1244 | * FileMonikerIROTData_AddRef
|
---|
1245 | */
|
---|
1246 | ULONG WINAPI FileMonikerROTDataImpl_AddRef(IROTData *iface)
|
---|
1247 | {
|
---|
1248 | ICOM_THIS_From_IROTData(IMoniker, iface);
|
---|
1249 |
|
---|
1250 | TRACE("(%p)\n",This);
|
---|
1251 |
|
---|
1252 | return FileMonikerImpl_AddRef(This);
|
---|
1253 | }
|
---|
1254 |
|
---|
1255 | /***********************************************************************
|
---|
1256 | * FileMonikerIROTData_Release
|
---|
1257 | */
|
---|
1258 | ULONG WINAPI FileMonikerROTDataImpl_Release(IROTData* iface)
|
---|
1259 | {
|
---|
1260 | ICOM_THIS_From_IROTData(IMoniker, iface);
|
---|
1261 |
|
---|
1262 | TRACE("(%p)\n",This);
|
---|
1263 |
|
---|
1264 | return FileMonikerImpl_Release(This);
|
---|
1265 | }
|
---|
1266 |
|
---|
1267 | /******************************************************************************
|
---|
1268 | * FileMonikerIROTData_GetComparaisonData
|
---|
1269 | ******************************************************************************/
|
---|
1270 | HRESULT WINAPI FileMonikerROTDataImpl_GetComparaisonData(IROTData* iface,
|
---|
1271 | BYTE* pbData,
|
---|
1272 | ULONG cbMax,
|
---|
1273 | ULONG* pcbData)
|
---|
1274 | {
|
---|
1275 | FIXME("(),stub!\n");
|
---|
1276 | return E_NOTIMPL;
|
---|
1277 | }
|
---|
1278 |
|
---|
1279 | /******************************************************************************
|
---|
1280 | * CreateFileMoniker16
|
---|
1281 | ******************************************************************************/
|
---|
1282 | HRESULT WINAPI CreateFileMoniker16(LPCOLESTR16 lpszPathName,LPMONIKER* ppmk)
|
---|
1283 | {
|
---|
1284 |
|
---|
1285 | FIXME("(%s,%p),stub!\n",lpszPathName,ppmk);
|
---|
1286 | return E_NOTIMPL;
|
---|
1287 | }
|
---|
1288 |
|
---|
1289 | /******************************************************************************
|
---|
1290 | * CreateFileMoniker
|
---|
1291 | ******************************************************************************/
|
---|
1292 | HRESULT WINAPI CreateFileMoniker(LPCOLESTR lpszPathName, LPMONIKER * ppmk)
|
---|
1293 | {
|
---|
1294 | FileMonikerImpl* newFileMoniker = 0;
|
---|
1295 | HRESULT hr = E_FAIL;
|
---|
1296 | IID riid=IID_IMoniker;
|
---|
1297 |
|
---|
1298 | TRACE("(%p,%p)\n",lpszPathName,ppmk);
|
---|
1299 |
|
---|
1300 | if (ppmk==NULL)
|
---|
1301 | return E_POINTER;
|
---|
1302 |
|
---|
1303 | if(lpszPathName==NULL)
|
---|
1304 | return MK_E_SYNTAX;
|
---|
1305 |
|
---|
1306 | *ppmk=0;
|
---|
1307 |
|
---|
1308 | newFileMoniker = (FileMonikerImpl *)HeapAlloc(GetProcessHeap(), 0, sizeof(FileMonikerImpl));
|
---|
1309 |
|
---|
1310 | if (newFileMoniker == 0)
|
---|
1311 | return E_OUTOFMEMORY;
|
---|
1312 |
|
---|
1313 | hr = FileMonikerImpl_Construct(newFileMoniker,lpszPathName);
|
---|
1314 |
|
---|
1315 | if (SUCCEEDED(hr))
|
---|
1316 | hr = FileMonikerImpl_QueryInterface((IMoniker*)newFileMoniker,&riid,(void**)ppmk);
|
---|
1317 | else
|
---|
1318 | HeapFree(GetProcessHeap(),0,newFileMoniker);
|
---|
1319 |
|
---|
1320 | return hr;
|
---|
1321 | }
|
---|