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 const IMonikerVtbl
*vtbl_ITS_IMoniker
;
52 /*** IUnknown methods ***/
53 static HRESULT WINAPI
ITS_IMonikerImpl_QueryInterface(
58 ITS_IMonikerImpl
*This
= (ITS_IMonikerImpl
*)iface
;
60 if (IsEqualGUID(riid
, &IID_IUnknown
)
61 || IsEqualGUID(riid
, &IID_IParseDisplayName
))
63 IClassFactory_AddRef(iface
);
68 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
72 static ULONG WINAPI
ITS_IMonikerImpl_AddRef(
75 ITS_IMonikerImpl
*This
= (ITS_IMonikerImpl
*)iface
;
77 return InterlockedIncrement(&This
->ref
);
80 static ULONG WINAPI
ITS_IMonikerImpl_Release(
83 ITS_IMonikerImpl
*This
= (ITS_IMonikerImpl
*)iface
;
84 ULONG ref
= InterlockedDecrement(&This
->ref
);
87 HeapFree(GetProcessHeap(), 0, This
);
94 /*** IPersist methods ***/
95 static HRESULT WINAPI
ITS_IMonikerImpl_GetClassID(
99 ITS_IMonikerImpl
*This
= (ITS_IMonikerImpl
*)iface
;
101 TRACE("%p %p\n", This
, pClassID
);
102 memcpy( pClassID
, &CLSID_ITStorage
, sizeof (CLSID
) );
106 /*** IPersistStream methods ***/
107 static HRESULT WINAPI
ITS_IMonikerImpl_IsDirty(
114 static HRESULT WINAPI
ITS_IMonikerImpl_Load(
122 static HRESULT WINAPI
ITS_IMonikerImpl_Save(
131 static HRESULT WINAPI
ITS_IMonikerImpl_GetSizeMax(
133 ULARGE_INTEGER
* pcbSize
)
139 /*** IMoniker methods ***/
140 static HRESULT WINAPI
ITS_IMonikerImpl_BindToObject(
151 static HRESULT WINAPI
ITS_IMonikerImpl_BindToStorage(
158 ITS_IMonikerImpl
*This
= (ITS_IMonikerImpl
*)iface
;
159 DWORD grfMode
= STGM_SIMPLE
| STGM_READ
| STGM_SHARE_EXCLUSIVE
;
161 IStorage
*stg
= NULL
;
163 TRACE("%p %p %p %s %p\n", This
,
164 pbc
, pmkToLeft
, debugstr_guid(riid
), ppvObj
);
166 r
= ITSS_StgOpenStorage( This
->szFile
, NULL
, grfMode
, 0, 0, &stg
);
169 TRACE("Opened storage %s\n", debugstr_w( This
->szFile
) );
170 if (IsEqualGUID(riid
, &IID_IStream
))
171 r
= IStorage_OpenStream( stg
, This
->szHtml
,
172 NULL
, grfMode
, 0, (IStream
**)ppvObj
);
173 else if (IsEqualGUID(riid
, &IID_IStorage
))
174 r
= IStorage_OpenStorage( stg
, This
->szHtml
,
175 NULL
, grfMode
, NULL
, 0, (IStorage
**)ppvObj
);
177 r
= STG_E_ACCESSDENIED
;
178 IStorage_Release( stg
);
184 static HRESULT WINAPI
ITS_IMonikerImpl_Reduce(
187 DWORD dwReduceHowFar
,
188 IMoniker
** ppmkToLeft
,
189 IMoniker
** ppmkReduced
)
195 static HRESULT WINAPI
ITS_IMonikerImpl_ComposeWith(
198 BOOL fOnlyIfNotGeneric
,
199 IMoniker
** ppmkComposite
)
205 static HRESULT WINAPI
ITS_IMonikerImpl_Enum(
208 IEnumMoniker
** ppenumMoniker
)
214 static HRESULT WINAPI
ITS_IMonikerImpl_IsEqual(
216 IMoniker
* pmkOtherMoniker
)
222 static HRESULT WINAPI
ITS_IMonikerImpl_Hash(
230 static HRESULT WINAPI
ITS_IMonikerImpl_IsRunning(
234 IMoniker
* pmkNewlyRunning
)
240 static HRESULT WINAPI
ITS_IMonikerImpl_GetTimeOfLastChange(
250 static HRESULT WINAPI
ITS_IMonikerImpl_Inverse(
258 static HRESULT WINAPI
ITS_IMonikerImpl_CommonPrefixWith(
261 IMoniker
** ppmkPrefix
)
267 static HRESULT WINAPI
ITS_IMonikerImpl_RelativePathTo(
270 IMoniker
** ppmkRelPath
)
276 static HRESULT WINAPI
ITS_IMonikerImpl_GetDisplayName(
280 LPOLESTR
* ppszDisplayName
)
282 ITS_IMonikerImpl
*This
= (ITS_IMonikerImpl
*)iface
;
283 static const WCHAR szFormat
[] = {
284 'm','s','-','i','t','s',':','%','s',':',':','%','s',0 };
285 DWORD len
= sizeof szFormat
/ sizeof(WCHAR
);
288 TRACE("%p %p %p %p\n", iface
, pbc
, pmkToLeft
, ppszDisplayName
);
290 len
= strlenW( This
->szFile
) + strlenW( This
->szHtml
);
291 str
= CoTaskMemAlloc( len
*sizeof(WCHAR
) );
292 sprintfW( str
, szFormat
, This
->szFile
, This
->szHtml
);
294 *ppszDisplayName
= str
;
299 static HRESULT WINAPI
ITS_IMonikerImpl_ParseDisplayName(
303 LPOLESTR pszDisplayName
,
311 static HRESULT WINAPI
ITS_IMonikerImpl_IsSystemMoniker(
319 static const IMonikerVtbl ITS_IMonikerImpl_Vtbl
=
321 ITS_IMonikerImpl_QueryInterface
,
322 ITS_IMonikerImpl_AddRef
,
323 ITS_IMonikerImpl_Release
,
324 ITS_IMonikerImpl_GetClassID
,
325 ITS_IMonikerImpl_IsDirty
,
326 ITS_IMonikerImpl_Load
,
327 ITS_IMonikerImpl_Save
,
328 ITS_IMonikerImpl_GetSizeMax
,
329 ITS_IMonikerImpl_BindToObject
,
330 ITS_IMonikerImpl_BindToStorage
,
331 ITS_IMonikerImpl_Reduce
,
332 ITS_IMonikerImpl_ComposeWith
,
333 ITS_IMonikerImpl_Enum
,
334 ITS_IMonikerImpl_IsEqual
,
335 ITS_IMonikerImpl_Hash
,
336 ITS_IMonikerImpl_IsRunning
,
337 ITS_IMonikerImpl_GetTimeOfLastChange
,
338 ITS_IMonikerImpl_Inverse
,
339 ITS_IMonikerImpl_CommonPrefixWith
,
340 ITS_IMonikerImpl_RelativePathTo
,
341 ITS_IMonikerImpl_GetDisplayName
,
342 ITS_IMonikerImpl_ParseDisplayName
,
343 ITS_IMonikerImpl_IsSystemMoniker
346 static HRESULT
ITS_IMoniker_create( IMoniker
**ppObj
, LPCWSTR name
, DWORD n
)
348 ITS_IMonikerImpl
*itsmon
;
351 /* szFile[1] has space for one character already */
352 sz
= sizeof(ITS_IMonikerImpl
) + strlenW( name
)*sizeof(WCHAR
);
354 itsmon
= HeapAlloc( GetProcessHeap(), 0, sz
);
355 itsmon
->vtbl_ITS_IMoniker
= &ITS_IMonikerImpl_Vtbl
;
357 strcpyW( itsmon
->szFile
, name
);
358 itsmon
->szHtml
= &itsmon
->szFile
[n
];
360 while( *itsmon
->szHtml
== ':' )
361 *itsmon
->szHtml
++ = 0;
363 TRACE("-> %p %s %s\n", itsmon
,
364 debugstr_w(itsmon
->szFile
), debugstr_w(itsmon
->szHtml
) );
365 *ppObj
= (IMoniker
*) itsmon
;
371 /*****************************************************************************/
374 const IParseDisplayNameVtbl
*vtbl_ITS_IParseDisplayName
;
376 } ITS_IParseDisplayNameImpl
;
378 static HRESULT WINAPI
ITS_IParseDisplayNameImpl_QueryInterface(
379 IParseDisplayName
* iface
,
383 ITS_IParseDisplayNameImpl
*This
= (ITS_IParseDisplayNameImpl
*)iface
;
385 if (IsEqualGUID(riid
, &IID_IUnknown
)
386 || IsEqualGUID(riid
, &IID_IParseDisplayName
))
388 IClassFactory_AddRef(iface
);
393 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
394 return E_NOINTERFACE
;
397 static ULONG WINAPI
ITS_IParseDisplayNameImpl_AddRef(
398 IParseDisplayName
* iface
)
400 ITS_IParseDisplayNameImpl
*This
= (ITS_IParseDisplayNameImpl
*)iface
;
402 return InterlockedIncrement(&This
->ref
);
405 static ULONG WINAPI
ITS_IParseDisplayNameImpl_Release(
406 IParseDisplayName
* iface
)
408 ITS_IParseDisplayNameImpl
*This
= (ITS_IParseDisplayNameImpl
*)iface
;
409 ULONG ref
= InterlockedDecrement(&This
->ref
);
412 HeapFree(GetProcessHeap(), 0, This
);
419 static HRESULT WINAPI
ITS_IParseDisplayNameImpl_ParseDisplayName(
420 IParseDisplayName
*iface
,
422 LPOLESTR pszDisplayName
,
426 static const WCHAR szPrefix
[] = {
427 '@','M','S','I','T','S','t','o','r','e',':',0 };
428 const DWORD prefix_len
= (sizeof szPrefix
/sizeof szPrefix
[0])-1;
431 ITS_IParseDisplayNameImpl
*This
= (ITS_IParseDisplayNameImpl
*)iface
;
433 TRACE("%p %s %p %p\n", This
,
434 debugstr_w( pszDisplayName
), pchEaten
, ppmkOut
);
436 if( strncmpW( pszDisplayName
, szPrefix
, prefix_len
) )
439 /* search backwards for a double colon */
440 for( n
= strlenW( pszDisplayName
) - 3; prefix_len
<= n
; n
-- )
441 if( ( pszDisplayName
[n
] == ':' ) && ( pszDisplayName
[n
+1] == ':' ) )
447 if( !pszDisplayName
[n
+2] )
450 *pchEaten
= strlenW( pszDisplayName
) - n
- 3;
452 return ITS_IMoniker_create( ppmkOut
,
453 &pszDisplayName
[prefix_len
], n
-prefix_len
);
456 static const IParseDisplayNameVtbl ITS_IParseDisplayNameImpl_Vtbl
=
458 ITS_IParseDisplayNameImpl_QueryInterface
,
459 ITS_IParseDisplayNameImpl_AddRef
,
460 ITS_IParseDisplayNameImpl_Release
,
461 ITS_IParseDisplayNameImpl_ParseDisplayName
464 HRESULT
ITS_IParseDisplayName_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
466 ITS_IParseDisplayNameImpl
*its
;
469 return CLASS_E_NOAGGREGATION
;
471 its
= HeapAlloc( GetProcessHeap(), 0, sizeof(ITS_IParseDisplayNameImpl
) );
472 its
->vtbl_ITS_IParseDisplayName
= &ITS_IParseDisplayNameImpl_Vtbl
;
475 TRACE("-> %p\n", its
);
476 *ppObj
= (LPVOID
) its
;