2 * ITSS Moniker implementation
4 * Copyright 2004 Mike McCormack
6 * Implementation of the infamous mk:@MSITStore moniker
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 #include "wine/itss.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(itss
);
43 /*****************************************************************************/
46 IMoniker IMoniker_iface
;
52 static inline ITS_IMonikerImpl
*impl_from_IMoniker(IMoniker
*iface
)
54 return CONTAINING_RECORD(iface
, ITS_IMonikerImpl
, IMoniker_iface
);
57 /*** IUnknown methods ***/
58 static HRESULT WINAPI
ITS_IMonikerImpl_QueryInterface(
63 ITS_IMonikerImpl
*This
= impl_from_IMoniker(iface
);
65 if (IsEqualGUID(riid
, &IID_IUnknown
)
66 || IsEqualGUID(riid
, &IID_IParseDisplayName
))
68 IClassFactory_AddRef(iface
);
73 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
77 static ULONG WINAPI
ITS_IMonikerImpl_AddRef(
80 ITS_IMonikerImpl
*This
= impl_from_IMoniker(iface
);
82 return InterlockedIncrement(&This
->ref
);
85 static ULONG WINAPI
ITS_IMonikerImpl_Release(
88 ITS_IMonikerImpl
*This
= impl_from_IMoniker(iface
);
89 ULONG ref
= InterlockedDecrement(&This
->ref
);
92 HeapFree(GetProcessHeap(), 0, This
);
99 /*** IPersist methods ***/
100 static HRESULT WINAPI
ITS_IMonikerImpl_GetClassID(
104 ITS_IMonikerImpl
*This
= impl_from_IMoniker(iface
);
106 TRACE("%p %p\n", This
, pClassID
);
107 *pClassID
= CLSID_ITStorage
;
111 /*** IPersistStream methods ***/
112 static HRESULT WINAPI
ITS_IMonikerImpl_IsDirty(
119 static HRESULT WINAPI
ITS_IMonikerImpl_Load(
127 static HRESULT WINAPI
ITS_IMonikerImpl_Save(
136 static HRESULT WINAPI
ITS_IMonikerImpl_GetSizeMax(
138 ULARGE_INTEGER
* pcbSize
)
144 /*** IMoniker methods ***/
145 static HRESULT WINAPI
ITS_IMonikerImpl_BindToObject(
156 static HRESULT WINAPI
ITS_IMonikerImpl_BindToStorage(
163 ITS_IMonikerImpl
*This
= impl_from_IMoniker(iface
);
164 DWORD grfMode
= STGM_SIMPLE
| STGM_READ
| STGM_SHARE_EXCLUSIVE
;
166 IStorage
*stg
= NULL
;
168 TRACE("%p %p %p %s %p\n", This
,
169 pbc
, pmkToLeft
, debugstr_guid(riid
), ppvObj
);
171 r
= ITSS_StgOpenStorage( This
->szFile
, NULL
, grfMode
, 0, 0, &stg
);
174 TRACE("Opened storage %s\n", debugstr_w( This
->szFile
) );
175 if (IsEqualGUID(riid
, &IID_IStream
))
176 r
= IStorage_OpenStream( stg
, This
->szHtml
,
177 NULL
, grfMode
, 0, (IStream
**)ppvObj
);
178 else if (IsEqualGUID(riid
, &IID_IStorage
))
179 r
= IStorage_OpenStorage( stg
, This
->szHtml
,
180 NULL
, grfMode
, NULL
, 0, (IStorage
**)ppvObj
);
182 r
= STG_E_ACCESSDENIED
;
183 IStorage_Release( stg
);
189 static HRESULT WINAPI
ITS_IMonikerImpl_Reduce(
192 DWORD dwReduceHowFar
,
193 IMoniker
** ppmkToLeft
,
194 IMoniker
** ppmkReduced
)
200 static HRESULT WINAPI
ITS_IMonikerImpl_ComposeWith(
203 BOOL fOnlyIfNotGeneric
,
204 IMoniker
** ppmkComposite
)
210 static HRESULT WINAPI
ITS_IMonikerImpl_Enum(
213 IEnumMoniker
** ppenumMoniker
)
219 static HRESULT WINAPI
ITS_IMonikerImpl_IsEqual(
221 IMoniker
* pmkOtherMoniker
)
227 static HRESULT WINAPI
ITS_IMonikerImpl_Hash(
235 static HRESULT WINAPI
ITS_IMonikerImpl_IsRunning(
239 IMoniker
* pmkNewlyRunning
)
245 static HRESULT WINAPI
ITS_IMonikerImpl_GetTimeOfLastChange(
255 static HRESULT WINAPI
ITS_IMonikerImpl_Inverse(
263 static HRESULT WINAPI
ITS_IMonikerImpl_CommonPrefixWith(
266 IMoniker
** ppmkPrefix
)
272 static HRESULT WINAPI
ITS_IMonikerImpl_RelativePathTo(
275 IMoniker
** ppmkRelPath
)
281 static HRESULT WINAPI
ITS_IMonikerImpl_GetDisplayName(
285 LPOLESTR
* ppszDisplayName
)
287 ITS_IMonikerImpl
*This
= impl_from_IMoniker(iface
);
288 static const WCHAR szFormat
[] = {
289 'm','s','-','i','t','s',':','%','s',':',':','%','s',0 };
290 DWORD len
= sizeof szFormat
/ sizeof(WCHAR
);
293 TRACE("%p %p %p %p\n", iface
, pbc
, pmkToLeft
, ppszDisplayName
);
295 len
= strlenW( This
->szFile
) + strlenW( This
->szHtml
);
296 str
= CoTaskMemAlloc( len
*sizeof(WCHAR
) );
297 sprintfW( str
, szFormat
, This
->szFile
, This
->szHtml
);
299 *ppszDisplayName
= str
;
304 static HRESULT WINAPI
ITS_IMonikerImpl_ParseDisplayName(
308 LPOLESTR pszDisplayName
,
316 static HRESULT WINAPI
ITS_IMonikerImpl_IsSystemMoniker(
324 static const IMonikerVtbl ITS_IMonikerImpl_Vtbl
=
326 ITS_IMonikerImpl_QueryInterface
,
327 ITS_IMonikerImpl_AddRef
,
328 ITS_IMonikerImpl_Release
,
329 ITS_IMonikerImpl_GetClassID
,
330 ITS_IMonikerImpl_IsDirty
,
331 ITS_IMonikerImpl_Load
,
332 ITS_IMonikerImpl_Save
,
333 ITS_IMonikerImpl_GetSizeMax
,
334 ITS_IMonikerImpl_BindToObject
,
335 ITS_IMonikerImpl_BindToStorage
,
336 ITS_IMonikerImpl_Reduce
,
337 ITS_IMonikerImpl_ComposeWith
,
338 ITS_IMonikerImpl_Enum
,
339 ITS_IMonikerImpl_IsEqual
,
340 ITS_IMonikerImpl_Hash
,
341 ITS_IMonikerImpl_IsRunning
,
342 ITS_IMonikerImpl_GetTimeOfLastChange
,
343 ITS_IMonikerImpl_Inverse
,
344 ITS_IMonikerImpl_CommonPrefixWith
,
345 ITS_IMonikerImpl_RelativePathTo
,
346 ITS_IMonikerImpl_GetDisplayName
,
347 ITS_IMonikerImpl_ParseDisplayName
,
348 ITS_IMonikerImpl_IsSystemMoniker
351 static HRESULT
ITS_IMoniker_create( IMoniker
**ppObj
, LPCWSTR name
, DWORD n
)
353 ITS_IMonikerImpl
*itsmon
;
356 /* szFile[1] has space for one character already */
357 sz
= sizeof(ITS_IMonikerImpl
) + strlenW( name
)*sizeof(WCHAR
);
359 itsmon
= HeapAlloc( GetProcessHeap(), 0, sz
);
360 itsmon
->IMoniker_iface
.lpVtbl
= &ITS_IMonikerImpl_Vtbl
;
362 strcpyW( itsmon
->szFile
, name
);
363 itsmon
->szHtml
= &itsmon
->szFile
[n
];
365 while( *itsmon
->szHtml
== ':' )
366 *itsmon
->szHtml
++ = 0;
368 TRACE("-> %p %s %s\n", itsmon
,
369 debugstr_w(itsmon
->szFile
), debugstr_w(itsmon
->szHtml
) );
370 *ppObj
= &itsmon
->IMoniker_iface
;
376 /*****************************************************************************/
379 IParseDisplayName IParseDisplayName_iface
;
381 } ITS_IParseDisplayNameImpl
;
383 static inline ITS_IParseDisplayNameImpl
*impl_from_IParseDisplayName(IParseDisplayName
*iface
)
385 return CONTAINING_RECORD(iface
, ITS_IParseDisplayNameImpl
, IParseDisplayName_iface
);
388 static HRESULT WINAPI
ITS_IParseDisplayNameImpl_QueryInterface(
389 IParseDisplayName
* iface
,
393 ITS_IParseDisplayNameImpl
*This
= impl_from_IParseDisplayName(iface
);
395 if (IsEqualGUID(riid
, &IID_IUnknown
)
396 || IsEqualGUID(riid
, &IID_IParseDisplayName
))
398 IClassFactory_AddRef(iface
);
403 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
404 return E_NOINTERFACE
;
407 static ULONG WINAPI
ITS_IParseDisplayNameImpl_AddRef(
408 IParseDisplayName
* iface
)
410 ITS_IParseDisplayNameImpl
*This
= impl_from_IParseDisplayName(iface
);
412 return InterlockedIncrement(&This
->ref
);
415 static ULONG WINAPI
ITS_IParseDisplayNameImpl_Release(
416 IParseDisplayName
* iface
)
418 ITS_IParseDisplayNameImpl
*This
= impl_from_IParseDisplayName(iface
);
419 ULONG ref
= InterlockedDecrement(&This
->ref
);
422 HeapFree(GetProcessHeap(), 0, This
);
429 static HRESULT WINAPI
ITS_IParseDisplayNameImpl_ParseDisplayName(
430 IParseDisplayName
*iface
,
432 LPOLESTR pszDisplayName
,
436 static const WCHAR szPrefix
[] = {
437 '@','M','S','I','T','S','t','o','r','e',':',0 };
438 const DWORD prefix_len
= (sizeof szPrefix
/sizeof szPrefix
[0])-1;
441 ITS_IParseDisplayNameImpl
*This
= impl_from_IParseDisplayName(iface
);
443 TRACE("%p %s %p %p\n", This
,
444 debugstr_w( pszDisplayName
), pchEaten
, ppmkOut
);
446 if( strncmpiW( pszDisplayName
, szPrefix
, prefix_len
) )
449 /* search backwards for a double colon */
450 for( n
= strlenW( pszDisplayName
) - 3; prefix_len
<= n
; n
-- )
451 if( ( pszDisplayName
[n
] == ':' ) && ( pszDisplayName
[n
+1] == ':' ) )
457 if( !pszDisplayName
[n
+2] )
460 *pchEaten
= strlenW( pszDisplayName
) - n
- 3;
462 return ITS_IMoniker_create( ppmkOut
,
463 &pszDisplayName
[prefix_len
], n
-prefix_len
);
466 static const IParseDisplayNameVtbl ITS_IParseDisplayNameImpl_Vtbl
=
468 ITS_IParseDisplayNameImpl_QueryInterface
,
469 ITS_IParseDisplayNameImpl_AddRef
,
470 ITS_IParseDisplayNameImpl_Release
,
471 ITS_IParseDisplayNameImpl_ParseDisplayName
474 HRESULT
ITS_IParseDisplayName_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
476 ITS_IParseDisplayNameImpl
*its
;
479 return CLASS_E_NOAGGREGATION
;
481 its
= HeapAlloc( GetProcessHeap(), 0, sizeof(ITS_IParseDisplayNameImpl
) );
482 its
->IParseDisplayName_iface
.lpVtbl
= &ITS_IParseDisplayNameImpl_Vtbl
;
485 TRACE("-> %p\n", its
);