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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(itss);
47 extern ULONG dll_count;
49 /*****************************************************************************/
52 const IMonikerVtbl *vtbl_ITS_IMoniker;
58 /*** IUnknown methods ***/
59 static HRESULT WINAPI ITS_IMonikerImpl_QueryInterface(
64 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
66 if (IsEqualGUID(riid, &IID_IUnknown)
67 || IsEqualGUID(riid, &IID_IParseDisplayName))
69 IClassFactory_AddRef(iface);
74 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
78 static ULONG WINAPI ITS_IMonikerImpl_AddRef(
81 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
83 return InterlockedIncrement(&This->ref);
86 static ULONG WINAPI ITS_IMonikerImpl_Release(
89 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
90 ULONG ref = InterlockedDecrement(&This->ref);
93 HeapFree(GetProcessHeap(), 0, This);
94 InterlockedDecrement(&dll_count);
100 /*** IPersist methods ***/
101 static HRESULT WINAPI ITS_IMonikerImpl_GetClassID(
105 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
107 TRACE("%p %p\n", This, pClassID);
108 memcpy( pClassID, &CLSID_ITStorage, sizeof (CLSID) );
112 /*** IPersistStream methods ***/
113 static HRESULT WINAPI ITS_IMonikerImpl_IsDirty(
120 static HRESULT WINAPI ITS_IMonikerImpl_Load(
128 static HRESULT WINAPI ITS_IMonikerImpl_Save(
137 static HRESULT WINAPI ITS_IMonikerImpl_GetSizeMax(
139 ULARGE_INTEGER* pcbSize)
145 /*** IMoniker methods ***/
146 static HRESULT WINAPI ITS_IMonikerImpl_BindToObject(
157 static HRESULT WINAPI ITS_IMonikerImpl_BindToStorage(
164 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
165 DWORD grfMode = STGM_SIMPLE | STGM_READ | STGM_SHARE_EXCLUSIVE;
167 IStorage *stg = NULL;
169 TRACE("%p %p %p %s %p\n", This,
170 pbc, pmkToLeft, debugstr_guid(riid), ppvObj);
172 r = ITSS_StgOpenStorage( This->szFile, NULL, grfMode, 0, 0, &stg );
175 TRACE("Opened storage %s\n", debugstr_w( This->szFile ) );
176 if (IsEqualGUID(riid, &IID_IStream))
177 r = IStorage_OpenStream( stg, This->szHtml,
178 NULL, grfMode, 0, (IStream**)ppvObj );
179 else if (IsEqualGUID(riid, &IID_IStorage))
180 r = IStorage_OpenStorage( stg, This->szHtml,
181 NULL, grfMode, NULL, 0, (IStorage**)ppvObj );
183 r = STG_E_ACCESSDENIED;
184 IStorage_Release( stg );
190 static HRESULT WINAPI ITS_IMonikerImpl_Reduce(
193 DWORD dwReduceHowFar,
194 IMoniker** ppmkToLeft,
195 IMoniker** ppmkReduced)
201 static HRESULT WINAPI ITS_IMonikerImpl_ComposeWith(
204 BOOL fOnlyIfNotGeneric,
205 IMoniker** ppmkComposite)
211 static HRESULT WINAPI ITS_IMonikerImpl_Enum(
214 IEnumMoniker** ppenumMoniker)
220 static HRESULT WINAPI ITS_IMonikerImpl_IsEqual(
222 IMoniker* pmkOtherMoniker)
228 static HRESULT WINAPI ITS_IMonikerImpl_Hash(
236 static HRESULT WINAPI ITS_IMonikerImpl_IsRunning(
240 IMoniker* pmkNewlyRunning)
246 static HRESULT WINAPI ITS_IMonikerImpl_GetTimeOfLastChange(
256 static HRESULT WINAPI ITS_IMonikerImpl_Inverse(
264 static HRESULT WINAPI ITS_IMonikerImpl_CommonPrefixWith(
267 IMoniker** ppmkPrefix)
273 static HRESULT WINAPI ITS_IMonikerImpl_RelativePathTo(
276 IMoniker** ppmkRelPath)
282 static HRESULT WINAPI ITS_IMonikerImpl_GetDisplayName(
286 LPOLESTR* ppszDisplayName)
288 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
289 static const WCHAR szFormat[] = {
290 'm','s','-','i','t','s',':','%','s',':',':','%','s',0 };
291 DWORD len = sizeof szFormat / sizeof(WCHAR);
294 TRACE("%p %p %p %p\n", iface, pbc, pmkToLeft, ppszDisplayName);
296 len = strlenW( This->szFile ) + strlenW( This->szHtml );
297 str = CoTaskMemAlloc( len*sizeof(WCHAR) );
298 sprintfW( str, szFormat, This->szFile, This->szHtml );
300 *ppszDisplayName = str;
305 static HRESULT WINAPI ITS_IMonikerImpl_ParseDisplayName(
309 LPOLESTR pszDisplayName,
317 static HRESULT WINAPI ITS_IMonikerImpl_IsSystemMoniker(
325 static const IMonikerVtbl ITS_IMonikerImpl_Vtbl =
327 ITS_IMonikerImpl_QueryInterface,
328 ITS_IMonikerImpl_AddRef,
329 ITS_IMonikerImpl_Release,
330 ITS_IMonikerImpl_GetClassID,
331 ITS_IMonikerImpl_IsDirty,
332 ITS_IMonikerImpl_Load,
333 ITS_IMonikerImpl_Save,
334 ITS_IMonikerImpl_GetSizeMax,
335 ITS_IMonikerImpl_BindToObject,
336 ITS_IMonikerImpl_BindToStorage,
337 ITS_IMonikerImpl_Reduce,
338 ITS_IMonikerImpl_ComposeWith,
339 ITS_IMonikerImpl_Enum,
340 ITS_IMonikerImpl_IsEqual,
341 ITS_IMonikerImpl_Hash,
342 ITS_IMonikerImpl_IsRunning,
343 ITS_IMonikerImpl_GetTimeOfLastChange,
344 ITS_IMonikerImpl_Inverse,
345 ITS_IMonikerImpl_CommonPrefixWith,
346 ITS_IMonikerImpl_RelativePathTo,
347 ITS_IMonikerImpl_GetDisplayName,
348 ITS_IMonikerImpl_ParseDisplayName,
349 ITS_IMonikerImpl_IsSystemMoniker
352 static HRESULT ITS_IMoniker_create( IMoniker **ppObj, LPWSTR name, DWORD n )
354 ITS_IMonikerImpl *itsmon;
357 /* szFile[1] has space for one character already */
358 sz = sizeof(ITS_IMonikerImpl) + strlenW( name )*sizeof(WCHAR);
360 itsmon = HeapAlloc( GetProcessHeap(), 0, sz );
361 itsmon->vtbl_ITS_IMoniker = &ITS_IMonikerImpl_Vtbl;
363 strcpyW( itsmon->szFile, name );
364 itsmon->szHtml = &itsmon->szFile[n];
366 while( *itsmon->szHtml == ':' )
367 *itsmon->szHtml++ = 0;
369 TRACE("-> %p %s %s\n", itsmon,
370 debugstr_w(itsmon->szFile), debugstr_w(itsmon->szHtml) );
371 *ppObj = (IMoniker*) itsmon;
372 InterlockedIncrement(&dll_count);
377 /*****************************************************************************/
380 const IParseDisplayNameVtbl *vtbl_ITS_IParseDisplayName;
382 } ITS_IParseDisplayNameImpl;
384 static HRESULT WINAPI ITS_IParseDisplayNameImpl_QueryInterface(
385 IParseDisplayName* iface,
389 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
391 if (IsEqualGUID(riid, &IID_IUnknown)
392 || IsEqualGUID(riid, &IID_IParseDisplayName))
394 IClassFactory_AddRef(iface);
399 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
400 return E_NOINTERFACE;
403 static ULONG WINAPI ITS_IParseDisplayNameImpl_AddRef(
404 IParseDisplayName* iface)
406 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
408 return InterlockedIncrement(&This->ref);
411 static ULONG WINAPI ITS_IParseDisplayNameImpl_Release(
412 IParseDisplayName* iface)
414 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
415 ULONG ref = InterlockedDecrement(&This->ref);
418 HeapFree(GetProcessHeap(), 0, This);
419 InterlockedDecrement(&dll_count);
425 static HRESULT WINAPI ITS_IParseDisplayNameImpl_ParseDisplayName(
426 IParseDisplayName *iface,
428 LPOLESTR pszDisplayName,
432 static const WCHAR szPrefix[] = {
433 '@','M','S','I','T','S','t','o','r','e',':',0 };
434 const DWORD prefix_len = (sizeof szPrefix/sizeof szPrefix[0])-1;
437 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
439 TRACE("%p %s %p %p\n", This,
440 debugstr_w( pszDisplayName ), pchEaten, ppmkOut );
442 if( strncmpW( pszDisplayName, szPrefix, prefix_len ) )
445 /* search backwards for a double colon */
446 for( n = strlenW( pszDisplayName ) - 3; prefix_len <= n; n-- )
447 if( ( pszDisplayName[n] == ':' ) && ( pszDisplayName[n+1] == ':' ) )
453 if( !pszDisplayName[n+2] )
456 *pchEaten = strlenW( pszDisplayName ) - n - 3;
458 return ITS_IMoniker_create( ppmkOut,
459 &pszDisplayName[prefix_len], n-prefix_len );
462 static const IParseDisplayNameVtbl ITS_IParseDisplayNameImpl_Vtbl =
464 ITS_IParseDisplayNameImpl_QueryInterface,
465 ITS_IParseDisplayNameImpl_AddRef,
466 ITS_IParseDisplayNameImpl_Release,
467 ITS_IParseDisplayNameImpl_ParseDisplayName
470 HRESULT ITS_IParseDisplayName_create(IUnknown *pUnkOuter, LPVOID *ppObj)
472 ITS_IParseDisplayNameImpl *its;
475 return CLASS_E_NOAGGREGATION;
477 its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITS_IParseDisplayNameImpl) );
478 its->vtbl_ITS_IParseDisplayName = &ITS_IParseDisplayNameImpl_Vtbl;
481 TRACE("-> %p\n", its);
482 *ppObj = (LPVOID) its;
483 InterlockedIncrement(&dll_count);