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
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(itss);
45 /*****************************************************************************/
48 IMonikerVtbl *vtbl_ITS_IMoniker;
54 /*** IUnknown methods ***/
55 static HRESULT WINAPI ITS_IMonikerImpl_QueryInterface(
60 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
62 if (IsEqualGUID(riid, &IID_IUnknown)
63 || IsEqualGUID(riid, &IID_IParseDisplayName))
65 IClassFactory_AddRef(iface);
70 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
74 static ULONG WINAPI ITS_IMonikerImpl_AddRef(
77 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
82 static ULONG WINAPI ITS_IMonikerImpl_Release(
85 ITS_IMonikerImpl *This = (ITS_IMonikerImpl *)iface;
86 ULONG ref = --This->ref;
89 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 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, LPWSTR 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;
370 /*****************************************************************************/
373 IParseDisplayNameVtbl *vtbl_ITS_IParseDisplayName;
375 } ITS_IParseDisplayNameImpl;
377 static HRESULT WINAPI ITS_IParseDisplayNameImpl_QueryInterface(
378 IParseDisplayName* iface,
382 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
384 if (IsEqualGUID(riid, &IID_IUnknown)
385 || IsEqualGUID(riid, &IID_IParseDisplayName))
387 IClassFactory_AddRef(iface);
392 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
393 return E_NOINTERFACE;
396 static ULONG WINAPI ITS_IParseDisplayNameImpl_AddRef(
397 IParseDisplayName* iface)
399 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
401 return ++(This->ref);
404 static ULONG WINAPI ITS_IParseDisplayNameImpl_Release(
405 IParseDisplayName* iface)
407 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
408 ULONG ref = --This->ref;
411 HeapFree(GetProcessHeap(), 0, This);
416 static HRESULT WINAPI ITS_IParseDisplayNameImpl_ParseDisplayName(
417 IParseDisplayName *iface,
419 LPOLESTR pszDisplayName,
423 static const WCHAR szPrefix[] = {
424 '@','M','S','I','T','S','t','o','r','e',':',0 };
425 const DWORD prefix_len = (sizeof szPrefix/sizeof szPrefix[0])-1;
428 ITS_IParseDisplayNameImpl *This = (ITS_IParseDisplayNameImpl *)iface;
430 TRACE("%p %s %p %p\n", This,
431 debugstr_w( pszDisplayName ), pchEaten, ppmkOut );
433 if( strncmpW( pszDisplayName, szPrefix, prefix_len ) )
436 /* search backwards for a double colon */
437 for( n = strlenW( pszDisplayName ) - 3; prefix_len <= n; n-- )
438 if( ( pszDisplayName[n] == ':' ) && ( pszDisplayName[n+1] == ':' ) )
444 if( !pszDisplayName[n+2] )
447 *pchEaten = strlenW( pszDisplayName ) - n - 3;
449 return ITS_IMoniker_create( ppmkOut,
450 &pszDisplayName[prefix_len], n-prefix_len );
453 static IParseDisplayNameVtbl ITS_IParseDisplayNameImpl_Vtbl =
455 ITS_IParseDisplayNameImpl_QueryInterface,
456 ITS_IParseDisplayNameImpl_AddRef,
457 ITS_IParseDisplayNameImpl_Release,
458 ITS_IParseDisplayNameImpl_ParseDisplayName
461 HRESULT ITS_IParseDisplayName_create(IUnknown *pUnkOuter, LPVOID *ppObj)
463 ITS_IParseDisplayNameImpl *its;
465 its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITS_IParseDisplayNameImpl) );
466 its->vtbl_ITS_IParseDisplayName = &ITS_IParseDisplayNameImpl_Vtbl;
469 TRACE("-> %p\n", its);
470 *ppObj = (LPVOID) its;