Generate stub entries on the fly for missing entry points instead of
[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     if( szwDatabase )
69         HeapFree( GetProcessHeap(), 0, szwDatabase );
70
71     return ret;
72 }
73
74 UINT WINAPI MsiGetSummaryInformationW(MSIHANDLE hDatabase, 
75               LPCWSTR szDatabase, UINT uiUpdateCount, MSIHANDLE *phSummaryInfo)
76 {
77     HRESULT r;
78     MSIHANDLE handle;
79     MSISUMMARYINFO *suminfo;
80     MSIDATABASE *db;
81     UINT ret = ERROR_SUCCESS;
82     IPropertySetStorage *psstg = NULL;
83     IPropertyStorage *ps = NULL;
84     DWORD grfMode;
85
86     TRACE("%ld %s %d %p\n", hDatabase, debugstr_w(szDatabase),
87            uiUpdateCount, phSummaryInfo);
88
89     if( !phSummaryInfo )
90         return ERROR_INVALID_PARAMETER;
91
92     if( szDatabase )
93     {
94         UINT res;
95
96         res = MSI_OpenDatabaseW(szDatabase, NULL, &db);
97         if( res != ERROR_SUCCESS )
98             return res;
99     }
100     else
101     {
102         db = msihandle2msiinfo(hDatabase, MSIHANDLETYPE_DATABASE);
103         if( !db )
104             return ERROR_INVALID_PARAMETER;
105     }
106
107     r = IStorage_QueryInterface( db->storage, 
108              &IID_IPropertySetStorage, (LPVOID)&psstg);
109     if( FAILED( r ) )
110     {
111         ERR("IStorage -> IPropertySetStorage failed\n");
112         if (db)
113             msiobj_release(&db->hdr);
114         return ERROR_FUNCTION_FAILED;
115     }
116     ERR("storage = %p propertysetstorage = %p\n", db->storage, psstg);
117
118     grfMode = STGM_READ | STGM_SHARE_EXCLUSIVE;
119     r = IPropertySetStorage_Open( psstg, &FMTID_SummaryInformation, grfMode, &ps );
120     if( FAILED( r ) )
121     {
122         ERR("failed to get IPropertyStorage r=%08lx\n",r);
123         ret = ERROR_FUNCTION_FAILED;
124         goto end;
125     }
126
127     suminfo = alloc_msiobject( MSIHANDLETYPE_SUMMARYINFO, 
128                   sizeof (MSISUMMARYINFO), MSI_CloseSummaryInfo );
129     if( !suminfo )
130     {
131         ret = ERROR_FUNCTION_FAILED;
132         goto end;
133     }
134
135     IPropertyStorage_AddRef(ps);
136     suminfo->propstg = ps;
137     handle = alloc_msihandle( &suminfo->hdr );
138     if( handle )
139     *phSummaryInfo = handle;
140     else
141         ret = ERROR_FUNCTION_FAILED;
142     msiobj_release( &suminfo->hdr );
143
144 end:
145     if( ps )
146         IPropertyStorage_Release(ps);
147     if( psstg )
148         IPropertySetStorage_Release(psstg);
149     if (db)
150         msiobj_release(&db->hdr);
151
152     return ret;
153 }
154
155 UINT WINAPI MsiSummaryInfoGetPropertyCount(MSIHANDLE hSummaryInfo, UINT *pCount)
156 {
157     MSISUMMARYINFO *suminfo;
158
159     FIXME("%ld %p\n",hSummaryInfo, pCount);
160
161     suminfo = msihandle2msiinfo( hSummaryInfo, MSIHANDLETYPE_SUMMARYINFO );
162     if( !suminfo )
163         return ERROR_INVALID_HANDLE;
164
165     return ERROR_CALL_NOT_IMPLEMENTED;
166 }
167
168 UINT WINAPI MsiSummaryInfoGetPropertyA(
169       MSIHANDLE hSummaryInfo, UINT uiProperty, UINT *puiDataType, INT *piValue,
170       FILETIME *pftValue, LPSTR szValueBuf, DWORD *pcchValueBuf)
171 {
172     MSISUMMARYINFO *suminfo;
173     HRESULT r;
174     PROPSPEC spec;
175     PROPVARIANT var;
176
177     TRACE("%ld %d %p %p %p %p %p\n",
178         hSummaryInfo, uiProperty, puiDataType, piValue,
179         pftValue, szValueBuf, pcchValueBuf);
180
181     suminfo = msihandle2msiinfo( hSummaryInfo, MSIHANDLETYPE_SUMMARYINFO );
182     if( !suminfo )
183         return ERROR_INVALID_HANDLE;
184
185     spec.ulKind = PRSPEC_PROPID;
186     spec.u.propid = uiProperty;
187
188     r = IPropertyStorage_ReadMultiple( suminfo->propstg, 1, &spec, &var);
189     if( FAILED(r) )
190         return ERROR_FUNCTION_FAILED;
191
192     if( puiDataType )
193         *puiDataType = var.vt;
194
195     switch( var.vt )
196     {
197     case VT_I4:
198         if( piValue )
199             *piValue = var.u.lVal;
200         break;
201     case VT_LPSTR:
202         if( pcchValueBuf && szValueBuf )
203         {
204             lstrcpynA(szValueBuf, var.u.pszVal, *pcchValueBuf );
205             *pcchValueBuf = lstrlenA( var.u.pszVal );
206         }
207         break;
208     case VT_FILETIME:
209         if( pftValue )
210             memcpy(pftValue, &var.u.filetime, sizeof (FILETIME) );
211         break;
212     case VT_EMPTY:
213         break;
214     default:
215         FIXME("Unknown property variant type\n");
216         break;
217     }
218
219     return ERROR_SUCCESS;
220 }
221
222 UINT WINAPI MsiSummaryInfoGetPropertyW(
223       MSIHANDLE hSummaryInfo, UINT uiProperty, UINT *puiDataType, INT *piValue,
224       FILETIME *pftValue, LPWSTR szValueBuf, DWORD *pcchValueBuf)
225 {
226     FIXME("%ld %d %p %p %p %p %p\n",
227         hSummaryInfo, uiProperty, puiDataType, piValue,
228         pftValue, szValueBuf, pcchValueBuf);
229     
230     return ERROR_CALL_NOT_IMPLEMENTED;
231 }