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
39 #include "wine/itss.h"
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(itss);
47 /*****************************************************************************/
50 const IMonikerVtbl *vtbl_ITS_IMoniker;
56 /*** IUnknown methods ***/
57 static HRESULT WINAPI ITS_IMonikerImpl_QueryInterface(
62 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
64 if (IsEqualGUID(riid, &IID_IUnknown)
65 || IsEqualGUID(riid, &IID_IParseDisplayName))
67 IClassFactory_AddRef(iface);
72 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
76 static ULONG WINAPI ITS_IMonikerImpl_AddRef(
79 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
81 return InterlockedIncrement(&This->ref);
84 static ULONG WINAPI ITS_IMonikerImpl_Release(
87 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
88 ULONG ref = InterlockedDecrement(&This->ref);
91 HeapFree(GetProcessHeap(), 0, This);
98 /*** IPersist methods ***/
99 static HRESULT WINAPI ITS_IMonikerImpl_GetClassID(
103 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
105 TRACE("%p %p\n", This, pClassID);
106 memcpy( pClassID, &CLSID_ITStorage, sizeof (CLSID) );
110 /*** IPersistStream methods ***/
111 static HRESULT WINAPI ITS_IMonikerImpl_IsDirty(
118 static HRESULT WINAPI ITS_IMonikerImpl_Load(
126 static HRESULT WINAPI ITS_IMonikerImpl_Save(
135 static HRESULT WINAPI ITS_IMonikerImpl_GetSizeMax(
137 ULARGE_INTEGER* pcbSize)
143 /*** IMoniker methods ***/
144 static HRESULT WINAPI ITS_IMonikerImpl_BindToObject(
155 static HRESULT WINAPI ITS_IMonikerImpl_BindToStorage(
162 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
163 DWORD grfMode = STGM_SIMPLE | STGM_READ | STGM_SHARE_EXCLUSIVE;
165 IStorage *stg = NULL;
167 TRACE("%p %p %p %s %p\n", This,
168 pbc, pmkToLeft, debugstr_guid(riid), ppvObj);
170 r = ITSS_StgOpenStorage( This->szFile, NULL, grfMode, 0, 0, &stg );
173 TRACE("Opened storage %s\n", debugstr_w( This->szFile ) );
174 if (IsEqualGUID(riid, &IID_IStream))
175 r = IStorage_OpenStream( stg, This->szHtml,
176 NULL, grfMode, 0, (IStream**)ppvObj );
177 else if (IsEqualGUID(riid, &IID_IStorage))
178 r = IStorage_OpenStorage( stg, This->szHtml,
179 NULL, grfMode, NULL, 0, (IStorage**)ppvObj );
181 r = STG_E_ACCESSDENIED;
182 IStorage_Release( stg );
188 static HRESULT WINAPI ITS_IMonikerImpl_Reduce(
191 DWORD dwReduceHowFar,
192 IMoniker** ppmkToLeft,
193 IMoniker** ppmkReduced)
199 static HRESULT WINAPI ITS_IMonikerImpl_ComposeWith(
202 BOOL fOnlyIfNotGeneric,
203 IMoniker** ppmkComposite)
209 static HRESULT WINAPI ITS_IMonikerImpl_Enum(
212 IEnumMoniker** ppenumMoniker)
218 static HRESULT WINAPI ITS_IMonikerImpl_IsEqual(
220 IMoniker* pmkOtherMoniker)
226 static HRESULT WINAPI ITS_IMonikerImpl_Hash(
234 static HRESULT WINAPI ITS_IMonikerImpl_IsRunning(
238 IMoniker* pmkNewlyRunning)
244 static HRESULT WINAPI ITS_IMonikerImpl_GetTimeOfLastChange(
254 static HRESULT WINAPI ITS_IMonikerImpl_Inverse(
262 static HRESULT WINAPI ITS_IMonikerImpl_CommonPrefixWith(
265 IMoniker** ppmkPrefix)
271 static HRESULT WINAPI ITS_IMonikerImpl_RelativePathTo(
274 IMoniker** ppmkRelPath)
280 static HRESULT WINAPI ITS_IMonikerImpl_GetDisplayName(
284 LPOLESTR* ppszDisplayName)
286 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
287 static const WCHAR szFormat[] = {
288 'm','s','-','i','t','s',':','%','s',':',':','%','s',0 };
289 DWORD len = sizeof szFormat / sizeof(WCHAR);
292 TRACE("%p %p %p %p\n", iface, pbc, pmkToLeft, ppszDisplayName);
294 len = strlenW( This->szFile ) + strlenW( This->szHtml );
295 str = CoTaskMemAlloc( len*sizeof(WCHAR) );
296 sprintfW( str, szFormat, This->szFile, This->szHtml );
298 *ppszDisplayName = str;
303 static HRESULT WINAPI ITS_IMonikerImpl_ParseDisplayName(
307 LPOLESTR pszDisplayName,
315 static HRESULT WINAPI ITS_IMonikerImpl_IsSystemMoniker(
323 static const IMonikerVtbl ITS_IMonikerImpl_Vtbl =
325 ITS_IMonikerImpl_QueryInterface,
326 ITS_IMonikerImpl_AddRef,
327 ITS_IMonikerImpl_Release,
328 ITS_IMonikerImpl_GetClassID,
329 ITS_IMonikerImpl_IsDirty,
330 ITS_IMonikerImpl_Load,
331 ITS_IMonikerImpl_Save,
332 ITS_IMonikerImpl_GetSizeMax,
333 ITS_IMonikerImpl_BindToObject,
334 ITS_IMonikerImpl_BindToStorage,
335 ITS_IMonikerImpl_Reduce,
336 ITS_IMonikerImpl_ComposeWith,
337 ITS_IMonikerImpl_Enum,
338 ITS_IMonikerImpl_IsEqual,
339 ITS_IMonikerImpl_Hash,
340 ITS_IMonikerImpl_IsRunning,
341 ITS_IMonikerImpl_GetTimeOfLastChange,
342 ITS_IMonikerImpl_Inverse,
343 ITS_IMonikerImpl_CommonPrefixWith,
344 ITS_IMonikerImpl_RelativePathTo,
345 ITS_IMonikerImpl_GetDisplayName,
346 ITS_IMonikerImpl_ParseDisplayName,
347 ITS_IMonikerImpl_IsSystemMoniker
350 static HRESULT ITS_IMoniker_create( IMoniker **ppObj, LPWSTR name, DWORD n )
352 ITS_IMonikerImpl *itsmon;
355 /* szFile[1] has space for one character already */
356 sz = sizeof(ITS_IMonikerImpl) + strlenW( name )*sizeof(WCHAR);
358 itsmon = HeapAlloc( GetProcessHeap(), 0, sz );
359 itsmon->vtbl_ITS_IMoniker = &ITS_IMonikerImpl_Vtbl;
361 strcpyW( itsmon->szFile, name );
362 itsmon->szHtml = &itsmon->szFile[n];
364 while( *itsmon->szHtml == ':' )
365 *itsmon->szHtml++ = 0;
367 TRACE("-> %p %s %s\n", itsmon,
368 debugstr_w(itsmon->szFile), debugstr_w(itsmon->szHtml) );
369 *ppObj = (IMoniker*) itsmon;
375 /*****************************************************************************/
378 const IParseDisplayNameVtbl *vtbl_ITS_IParseDisplayName;
380 } ITS_IParseDisplayNameImpl;
382 static HRESULT WINAPI ITS_IParseDisplayNameImpl_QueryInterface(
383 IParseDisplayName* iface,
387 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
389 if (IsEqualGUID(riid, &IID_IUnknown)
390 || IsEqualGUID(riid, &IID_IParseDisplayName))
392 IClassFactory_AddRef(iface);
397 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
398 return E_NOINTERFACE;
401 static ULONG WINAPI ITS_IParseDisplayNameImpl_AddRef(
402 IParseDisplayName* iface)
404 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
406 return InterlockedIncrement(&This->ref);
409 static ULONG WINAPI ITS_IParseDisplayNameImpl_Release(
410 IParseDisplayName* iface)
412 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
413 ULONG ref = InterlockedDecrement(&This->ref);
416 HeapFree(GetProcessHeap(), 0, This);
423 static HRESULT WINAPI ITS_IParseDisplayNameImpl_ParseDisplayName(
424 IParseDisplayName *iface,
426 LPOLESTR pszDisplayName,
430 static const WCHAR szPrefix[] = {
431 '@','M','S','I','T','S','t','o','r','e',':',0 };
432 const DWORD prefix_len = (sizeof szPrefix/sizeof szPrefix[0])-1;
435 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
437 TRACE("%p %s %p %p\n", This,
438 debugstr_w( pszDisplayName ), pchEaten, ppmkOut );
440 if( strncmpW( pszDisplayName, szPrefix, prefix_len ) )
443 /* search backwards for a double colon */
444 for( n = strlenW( pszDisplayName ) - 3; prefix_len <= n; n-- )
445 if( ( pszDisplayName[n] == ':' ) && ( pszDisplayName[n+1] == ':' ) )
451 if( !pszDisplayName[n+2] )
454 *pchEaten = strlenW( pszDisplayName ) - n - 3;
456 return ITS_IMoniker_create( ppmkOut,
457 &pszDisplayName[prefix_len], n-prefix_len );
460 static const IParseDisplayNameVtbl ITS_IParseDisplayNameImpl_Vtbl =
462 ITS_IParseDisplayNameImpl_QueryInterface,
463 ITS_IParseDisplayNameImpl_AddRef,
464 ITS_IParseDisplayNameImpl_Release,
465 ITS_IParseDisplayNameImpl_ParseDisplayName
468 HRESULT ITS_IParseDisplayName_create(IUnknown *pUnkOuter, LPVOID *ppObj)
470 ITS_IParseDisplayNameImpl *its;
473 return CLASS_E_NOAGGREGATION;
475 its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITS_IParseDisplayNameImpl) );
476 its->vtbl_ITS_IParseDisplayName = &ITS_IParseDisplayNameImpl_Vtbl;
479 TRACE("-> %p\n", its);
480 *ppObj = (LPVOID) its;