Fixed a couple of crashes.
[wine.git] / dlls / msi / suminfo.c
bloba2f1c6cb31397f4f4bbaf16549edf2e150c483e0
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define NONAMELESSUNION
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28 #include "winnls.h"
29 #include "shlwapi.h"
30 #include "wine/debug.h"
31 #include "msi.h"
32 #include "msiquery.h"
33 #include "msipriv.h"
34 #include "objidl.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msi);
38 const WCHAR szSumInfo[] = { 5 ,'S','u','m','m','a','r','y',
39 'I','n','f','o','r','m','a','t','i','o','n',0 };
41 static void MSI_CloseSummaryInfo( VOID *arg )
43 MSISUMMARYINFO *suminfo = (MSISUMMARYINFO *) arg;
44 IPropertyStorage_Release( suminfo->propstg );
47 UINT WINAPI MsiGetSummaryInformationA(MSIHANDLE hDatabase,
48 LPCSTR szDatabase, UINT uiUpdateCount, MSIHANDLE *phSummaryInfo)
50 LPWSTR szwDatabase = NULL;
51 UINT ret;
53 TRACE("%ld %s %d %p\n", hDatabase, debugstr_a(szDatabase),
54 uiUpdateCount, phSummaryInfo);
56 if( szDatabase )
58 UINT len = MultiByteToWideChar( CP_ACP, 0, szDatabase, -1, NULL, 0 );
59 szwDatabase = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
60 if( !szwDatabase )
61 return ERROR_FUNCTION_FAILED;
62 MultiByteToWideChar( CP_ACP, 0, szDatabase, -1, szwDatabase, len );
65 ret = MsiGetSummaryInformationW(hDatabase, szwDatabase, uiUpdateCount, phSummaryInfo);
67 if( szwDatabase )
68 HeapFree( GetProcessHeap(), 0, szwDatabase );
70 return ret;
73 UINT WINAPI MsiGetSummaryInformationW(MSIHANDLE hDatabase,
74 LPCWSTR szDatabase, UINT uiUpdateCount, MSIHANDLE *phSummaryInfo)
76 HRESULT r;
77 MSIHANDLE handle, hdb = hDatabase;
78 MSISUMMARYINFO *suminfo;
79 MSIDATABASE *db;
80 UINT ret = ERROR_SUCCESS;
81 IPropertySetStorage *psstg = NULL;
82 IPropertyStorage *ps = NULL;
83 DWORD grfMode;
85 TRACE("%ld %s %d %p\n", hDatabase, debugstr_w(szDatabase),
86 uiUpdateCount, phSummaryInfo);
88 if( !phSummaryInfo )
89 return ERROR_INVALID_PARAMETER;
91 if( szDatabase )
93 UINT res;
95 res = MsiOpenDatabaseW(szDatabase, NULL, &hdb);
96 if( res != ERROR_SUCCESS )
97 return res;
100 db = msihandle2msiinfo(hdb, MSIHANDLETYPE_DATABASE);
101 if( !db )
102 return ERROR_INVALID_PARAMETER;
104 r = IStorage_QueryInterface( db->storage,
105 &IID_IPropertySetStorage, (LPVOID)&psstg);
106 if( FAILED( r ) )
108 ERR("IStorage -> IPropertySetStorage failed\n");
109 return ERROR_FUNCTION_FAILED;
111 ERR("storage = %p propertysetstorage = %p\n", db->storage, psstg);
113 grfMode = STGM_READ | STGM_SHARE_EXCLUSIVE;
114 r = IPropertySetStorage_Open( psstg, &FMTID_SummaryInformation, grfMode, &ps );
115 if( FAILED( r ) )
117 ERR("failed to get IPropertyStorage r=%08lx\n",r);
118 ret = ERROR_FUNCTION_FAILED;
119 goto end;
122 handle = alloc_msihandle( MSIHANDLETYPE_SUMMARYINFO,
123 sizeof (MSISUMMARYINFO), MSI_CloseSummaryInfo );
124 if( !handle )
126 ret = ERROR_FUNCTION_FAILED;
127 goto end;
130 suminfo = msihandle2msiinfo( handle, MSIHANDLETYPE_SUMMARYINFO );
131 if( !suminfo )
133 ret = ERROR_FUNCTION_FAILED;
134 goto end;
137 IPropertyStorage_AddRef(ps);
138 suminfo->propstg = ps;
139 *phSummaryInfo = handle;
141 end:
142 if( ps )
143 IPropertyStorage_Release(ps);
144 if( psstg )
145 IPropertySetStorage_Release(psstg);
146 if( !hDatabase )
147 MsiCloseHandle( hdb );
149 return ret;
152 UINT WINAPI MsiSummaryInfoGetPropertyCount(MSIHANDLE hSummaryInfo, UINT *pCount)
154 MSISUMMARYINFO *suminfo;
156 FIXME("%ld %p\n",hSummaryInfo, pCount);
158 suminfo = msihandle2msiinfo( hSummaryInfo, MSIHANDLETYPE_SUMMARYINFO );
159 if( !suminfo )
160 return ERROR_INVALID_HANDLE;
162 return ERROR_CALL_NOT_IMPLEMENTED;
165 UINT WINAPI MsiSummaryInfoGetPropertyA(
166 MSIHANDLE hSummaryInfo, UINT uiProperty, UINT *puiDataType, INT *piValue,
167 FILETIME *pftValue, LPSTR szValueBuf, DWORD *pcchValueBuf)
169 MSISUMMARYINFO *suminfo;
170 HRESULT r;
171 PROPSPEC spec;
172 PROPVARIANT var;
174 TRACE("%ld %d %p %p %p %p %p\n",
175 hSummaryInfo, uiProperty, puiDataType, piValue,
176 pftValue, szValueBuf, pcchValueBuf);
178 suminfo = msihandle2msiinfo( hSummaryInfo, MSIHANDLETYPE_SUMMARYINFO );
179 if( !suminfo )
180 return ERROR_INVALID_HANDLE;
182 spec.ulKind = PRSPEC_PROPID;
183 spec.u.propid = uiProperty;
185 r = IPropertyStorage_ReadMultiple( suminfo->propstg, 1, &spec, &var);
186 if( FAILED(r) )
187 return ERROR_FUNCTION_FAILED;
189 if( puiDataType )
190 *puiDataType = var.vt;
192 switch( var.vt )
194 case VT_I4:
195 if( piValue )
196 *piValue = var.u.lVal;
197 break;
198 case VT_LPSTR:
199 if( pcchValueBuf && szValueBuf )
201 lstrcpynA(szValueBuf, var.u.pszVal, *pcchValueBuf );
202 *pcchValueBuf = lstrlenA( var.u.pszVal );
204 break;
205 case VT_FILETIME:
206 if( pftValue )
207 memcpy(pftValue, &var.u.filetime, sizeof (FILETIME) );
208 break;
209 case VT_EMPTY:
210 break;
211 default:
212 FIXME("Unknown property variant type\n");
213 break;
216 return ERROR_SUCCESS;
219 UINT WINAPI MsiSummaryInfoGetPropertyW(
220 MSIHANDLE hSummaryInfo, UINT uiProperty, UINT *puiDataType, INT *piValue,
221 FILETIME *pftValue, LPWSTR szValueBuf, DWORD *pcchValueBuf)
223 FIXME("%ld %d %p %p %p %p %p\n",
224 hSummaryInfo, uiProperty, puiDataType, piValue,
225 pftValue, szValueBuf, pcchValueBuf);
227 return ERROR_CALL_NOT_IMPLEMENTED;