Reverse the order for deleting the items in resetcontent to correctly
[wine] / dlls / msi / suminfo.c
1 /*
2  * Implementation of the Microsoft Installer (msi.dll)
3  *
4  * Copyright 2002 Mike McCormack for CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22
23 #define COBJMACROS
24 #define NONAMELESSUNION
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winnls.h"
30 #include "shlwapi.h"
31 #include "wine/debug.h"
32 #include "msi.h"
33 #include "msiquery.h"
34 #include "msipriv.h"
35 #include "objidl.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(msi);
38
39 static const WCHAR szSumInfo[] = { 5 ,'S','u','m','m','a','r','y',
40                        'I','n','f','o','r','m','a','t','i','o','n',0 };
41
42 static void MSI_CloseSummaryInfo( MSIOBJECTHDR *arg )
43 {
44     MSISUMMARYINFO *suminfo = (MSISUMMARYINFO *) arg;
45     IPropertyStorage_Release( suminfo->propstg );
46 }
47
48 UINT WINAPI MsiGetSummaryInformationA(MSIHANDLE hDatabase, 
49               LPCSTR szDatabase, UINT uiUpdateCount, MSIHANDLE *phSummaryInfo)
50 {
51     LPWSTR szwDatabase = NULL;
52     UINT ret;
53
54     TRACE("%ld %s %d %p\n", hDatabase, debugstr_a(szDatabase), 
55           uiUpdateCount, phSummaryInfo);
56
57     if( szDatabase )
58     {
59         UINT len = MultiByteToWideChar( CP_ACP, 0, szDatabase, -1, NULL, 0 );
60         szwDatabase = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
61         if( !szwDatabase )
62             return ERROR_FUNCTION_FAILED;
63         MultiByteToWideChar( CP_ACP, 0, szDatabase, -1, szwDatabase, len );
64     }
65
66     ret = MsiGetSummaryInformationW(hDatabase, szwDatabase, uiUpdateCount, phSummaryInfo);
67
68     HeapFree( GetProcessHeap(), 0, szwDatabase );
69
70     return ret;
71 }
72
73 UINT WINAPI MsiGetSummaryInformationW(MSIHANDLE hDatabase, 
74               LPCWSTR szDatabase, UINT uiUpdateCount, MSIHANDLE *phSummaryInfo)
75 {
76     HRESULT r;
77     MSIHANDLE handle;
78     MSISUMMARYINFO *suminfo;
79     MSIDATABASE *db;
80     UINT ret = ERROR_SUCCESS;
81     IPropertySetStorage *psstg = NULL;
82     IPropertyStorage *ps = NULL;
83     DWORD grfMode;
84
85     TRACE("%ld %s %d %p\n", hDatabase, debugstr_w(szDatabase),
86            uiUpdateCount, phSummaryInfo);
87
88     if( !phSummaryInfo )
89         return ERROR_INVALID_PARAMETER;
90
91     if( szDatabase )
92     {
93         UINT res;
94
95         res = MSI_OpenDatabaseW(szDatabase, NULL, &db);
96         if( res != ERROR_SUCCESS )
97             return res;
98     }
99     else
100     {
101         db = msihandle2msiinfo(hDatabase, MSIHANDLETYPE_DATABASE);
102         if( !db )
103             return ERROR_INVALID_PARAMETER;
104     }
105
106     r = IStorage_QueryInterface( db->storage, 
107              &IID_IPropertySetStorage, (LPVOID)&psstg);
108     if( FAILED( r ) )
109     {
110         ERR("IStorage -> IPropertySetStorage failed\n");
111         ret = ERROR_FUNCTION_FAILED;
112         goto end;
113     }
114
115     grfMode = STGM_READ | STGM_SHARE_EXCLUSIVE;
116     r = IPropertySetStorage_Open( psstg, &FMTID_SummaryInformation, grfMode, &ps );
117     if( FAILED( r ) )
118     {
119         ERR("failed to get IPropertyStorage r=%08lx\n",r);
120         ret = ERROR_FUNCTION_FAILED;
121         goto end;
122     }
123
124     suminfo = alloc_msiobject( MSIHANDLETYPE_SUMMARYINFO, 
125                   sizeof (MSISUMMARYINFO), MSI_CloseSummaryInfo );
126     if( !suminfo )
127     {
128         ret = ERROR_FUNCTION_FAILED;
129         goto end;
130     }
131
132     IPropertyStorage_AddRef(ps);
133     suminfo->propstg = ps;
134     handle = alloc_msihandle( &suminfo->hdr );
135     if( handle )
136         *phSummaryInfo = handle;
137     else
138         ret = ERROR_FUNCTION_FAILED;
139     msiobj_release( &suminfo->hdr );
140
141 end:
142     if( ps )
143         IPropertyStorage_Release(ps);
144     if( psstg )
145         IPropertySetStorage_Release(psstg);
146     if( db )
147         msiobj_release(&db->hdr);
148
149     return ret;
150 }
151
152 UINT WINAPI MsiSummaryInfoGetPropertyCount(MSIHANDLE hSummaryInfo, UINT *pCount)
153 {
154     MSISUMMARYINFO *suminfo;
155
156     FIXME("%ld %p\n",hSummaryInfo, pCount);
157
158     suminfo = msihandle2msiinfo( hSummaryInfo, MSIHANDLETYPE_SUMMARYINFO );
159     if( !suminfo )
160         return ERROR_INVALID_HANDLE;
161
162     return ERROR_CALL_NOT_IMPLEMENTED;
163 }
164
165 UINT WINAPI MsiSummaryInfoGetPropertyA(
166       MSIHANDLE hSummaryInfo, UINT uiProperty, UINT *puiDataType, INT *piValue,
167       FILETIME *pftValue, LPSTR szValueBuf, DWORD *pcchValueBuf)
168 {
169     MSISUMMARYINFO *suminfo;
170     HRESULT r;
171     PROPSPEC spec;
172     PROPVARIANT var;
173
174     TRACE("%ld %d %p %p %p %p %p\n",
175         hSummaryInfo, uiProperty, puiDataType, piValue,
176         pftValue, szValueBuf, pcchValueBuf);
177
178     suminfo = msihandle2msiinfo( hSummaryInfo, MSIHANDLETYPE_SUMMARYINFO );
179     if( !suminfo )
180         return ERROR_INVALID_HANDLE;
181
182     spec.ulKind = PRSPEC_PROPID;
183     spec.u.propid = uiProperty;
184
185     r = IPropertyStorage_ReadMultiple( suminfo->propstg, 1, &spec, &var);
186     if( FAILED(r) )
187         return ERROR_FUNCTION_FAILED;
188
189     if( puiDataType )
190         *puiDataType = var.vt;
191
192     switch( var.vt )
193     {
194     case VT_I4:
195         if( piValue )
196             *piValue = var.u.lVal;
197         break;
198     case VT_LPSTR:
199         if( pcchValueBuf && szValueBuf )
200         {
201             lstrcpynA(szValueBuf, var.u.pszVal, *pcchValueBuf );
202             *pcchValueBuf = lstrlenA( var.u.pszVal );
203         }
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;
214     }
215
216     return ERROR_SUCCESS;
217 }
218
219 UINT WINAPI MsiSummaryInfoGetPropertyW(
220       MSIHANDLE hSummaryInfo, UINT uiProperty, UINT *puiDataType, INT *piValue,
221       FILETIME *pftValue, LPWSTR szValueBuf, DWORD *pcchValueBuf)
222 {
223     MSISUMMARYINFO *suminfo;
224     HRESULT r;
225     PROPSPEC spec;
226     PROPVARIANT var;
227
228     TRACE("%ld %d %p %p %p %p %p\n",
229         hSummaryInfo, uiProperty, puiDataType, piValue,
230         pftValue, szValueBuf, pcchValueBuf);
231
232     suminfo = msihandle2msiinfo( hSummaryInfo, MSIHANDLETYPE_SUMMARYINFO );
233     if( !suminfo )
234         return ERROR_INVALID_HANDLE;
235
236     spec.ulKind = PRSPEC_PROPID;
237     spec.u.propid = uiProperty;
238
239     r = IPropertyStorage_ReadMultiple( suminfo->propstg, 1, &spec, &var);
240     if( FAILED(r) )
241         return ERROR_FUNCTION_FAILED;
242
243     if( puiDataType )
244         *puiDataType = var.vt;
245
246     switch( var.vt )
247     {
248     case VT_I4:
249         if( piValue )
250             *piValue = var.u.lVal;
251         break;
252     case VT_LPSTR:
253         if( pcchValueBuf && szValueBuf )
254         {
255             MultiByteToWideChar(CP_ACP, 0,  var.u.pszVal, -1, szValueBuf, 
256                                 *pcchValueBuf );
257             *pcchValueBuf = lstrlenA( var.u.pszVal );
258         }
259         break;
260     case VT_FILETIME:
261         if( pftValue )
262             memcpy(pftValue, &var.u.filetime, sizeof (FILETIME) );
263         break;
264     case VT_EMPTY:
265         break;
266     default:
267         FIXME("Unknown property variant type\n");
268         break;
269     }
270
271     return ERROR_SUCCESS;
272 }
273
274 UINT WINAPI MsiSummaryInfoSetPropertyA( MSIHANDLE hSummaryInfo, UINT uiProperty,
275                                        UINT uiDataType, INT iValue, 
276                                        FILETIME* pftValue, LPSTR szValue )
277 {
278     FIXME("%ld %u %u %i %p %s\n", hSummaryInfo, uiProperty,
279           uiDataType, iValue, pftValue, debugstr_a(szValue) );
280     return ERROR_CALL_NOT_IMPLEMENTED;
281 }
282
283 UINT WINAPI MsiSummaryInfoSetPropertyW( MSIHANDLE hSummaryInfo, UINT uiProperty,
284                                        UINT uiDataType, INT iValue, 
285                                        FILETIME* pftValue, LPWSTR szValue )
286 {
287     FIXME("%ld %u %u %i %p %s\n", hSummaryInfo, uiProperty,
288           uiDataType, iValue, pftValue, debugstr_w(szValue) );
289     return ERROR_CALL_NOT_IMPLEMENTED;
290 }
291
292 UINT WINAPI MsiSummaryInfoPersist( MSIHANDLE hSummaryInfo )
293 {
294     FIXME("%ld\n", hSummaryInfo );
295     return ERROR_CALL_NOT_IMPLEMENTED;
296 }