gdiplus: Convert formats that can't be drawn by gdi32 when drawing bitmaps.
[wine.git] / dlls / msi / suminfo.c
blobdf35c4d0d4cd376a9b7df702b8c112a94b8ac2aa
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002, 2005 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #define COBJMACROS
24 #define NONAMELESSUNION
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 "wine/unicode.h"
33 #include "msi.h"
34 #include "msiquery.h"
35 #include "msidefs.h"
36 #include "msipriv.h"
37 #include "objidl.h"
38 #include "propvarutil.h"
39 #include "msiserver.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi);
43 #include "pshpack1.h"
45 typedef struct {
46 WORD wByteOrder;
47 WORD wFormat;
48 DWORD dwOSVer;
49 CLSID clsID;
50 DWORD reserved;
51 } PROPERTYSETHEADER;
53 typedef struct {
54 FMTID fmtid;
55 DWORD dwOffset;
56 } FORMATIDOFFSET;
58 typedef struct {
59 DWORD cbSection;
60 DWORD cProperties;
61 } PROPERTYSECTIONHEADER;
63 typedef struct {
64 DWORD propid;
65 DWORD dwOffset;
66 } PROPERTYIDOFFSET;
68 typedef struct {
69 DWORD type;
70 union {
71 INT i4;
72 SHORT i2;
73 FILETIME ft;
74 struct {
75 DWORD len;
76 BYTE str[1];
77 } str;
78 } u;
79 } PROPERTY_DATA;
81 #include "poppack.h"
83 static HRESULT (WINAPI *pPropVariantChangeType)
84 (PROPVARIANT *ppropvarDest, REFPROPVARIANT propvarSrc,
85 PROPVAR_CHANGE_FLAGS flags, VARTYPE vt);
87 #define SECT_HDR_SIZE (sizeof(PROPERTYSECTIONHEADER))
89 static const WCHAR szSumInfo[] = { 5 ,'S','u','m','m','a','r','y',
90 'I','n','f','o','r','m','a','t','i','o','n',0 };
92 static void free_prop( PROPVARIANT *prop )
94 if (prop->vt == VT_LPSTR )
95 msi_free( prop->u.pszVal );
96 prop->vt = VT_EMPTY;
99 static void MSI_CloseSummaryInfo( MSIOBJECTHDR *arg )
101 MSISUMMARYINFO *si = (MSISUMMARYINFO *) arg;
102 DWORD i;
104 for( i = 0; i < MSI_MAX_PROPS; i++ )
105 free_prop( &si->property[i] );
106 IStorage_Release( si->storage );
109 static UINT get_type( UINT uiProperty )
111 switch( uiProperty )
113 case PID_CODEPAGE:
114 return VT_I2;
116 case PID_SUBJECT:
117 case PID_AUTHOR:
118 case PID_KEYWORDS:
119 case PID_COMMENTS:
120 case PID_TEMPLATE:
121 case PID_LASTAUTHOR:
122 case PID_REVNUMBER:
123 case PID_APPNAME:
124 case PID_TITLE:
125 return VT_LPSTR;
127 case PID_LASTPRINTED:
128 case PID_CREATE_DTM:
129 case PID_LASTSAVE_DTM:
130 return VT_FILETIME;
132 case PID_WORDCOUNT:
133 case PID_CHARCOUNT:
134 case PID_SECURITY:
135 case PID_PAGECOUNT:
136 return VT_I4;
138 return VT_EMPTY;
141 static UINT get_property_count( const PROPVARIANT *property )
143 UINT i, n = 0;
145 if( !property )
146 return n;
147 for( i = 0; i < MSI_MAX_PROPS; i++ )
148 if( property[i].vt != VT_EMPTY )
149 n++;
150 return n;
153 static UINT propvar_changetype(PROPVARIANT *changed, PROPVARIANT *property, VARTYPE vt)
155 HRESULT hr;
156 HMODULE propsys = LoadLibraryA("propsys.dll");
157 pPropVariantChangeType = (void *)GetProcAddress(propsys, "PropVariantChangeType");
159 if (!pPropVariantChangeType)
161 ERR("PropVariantChangeType function missing!\n");
162 return ERROR_FUNCTION_FAILED;
165 hr = pPropVariantChangeType(changed, property, 0, vt);
166 return (hr == S_OK) ? ERROR_SUCCESS : ERROR_FUNCTION_FAILED;
169 /* FIXME: doesn't deal with endian conversion */
170 static void read_properties_from_data( PROPVARIANT *prop, LPBYTE data, DWORD sz )
172 UINT type;
173 DWORD i, size;
174 PROPERTY_DATA *propdata;
175 PROPVARIANT property, *ptr;
176 PROPVARIANT changed;
177 PROPERTYIDOFFSET *idofs;
178 PROPERTYSECTIONHEADER *section_hdr;
180 section_hdr = (PROPERTYSECTIONHEADER*) &data[0];
181 idofs = (PROPERTYIDOFFSET*) &data[SECT_HDR_SIZE];
183 /* now set all the properties */
184 for( i = 0; i < section_hdr->cProperties; i++ )
186 if( idofs[i].propid >= MSI_MAX_PROPS )
188 ERR("Unknown property ID %d\n", idofs[i].propid );
189 break;
192 type = get_type( idofs[i].propid );
193 if( type == VT_EMPTY )
195 ERR("propid %d has unknown type\n", idofs[i].propid);
196 break;
199 propdata = (PROPERTY_DATA*) &data[ idofs[i].dwOffset ];
201 /* check we don't run off the end of the data */
202 size = sz - idofs[i].dwOffset - sizeof(DWORD);
203 if( sizeof(DWORD) > size ||
204 ( propdata->type == VT_FILETIME && sizeof(FILETIME) > size ) ||
205 ( propdata->type == VT_LPSTR && (propdata->u.str.len + sizeof(DWORD)) > size ) )
207 ERR("not enough data\n");
208 break;
211 property.vt = propdata->type;
212 if( propdata->type == VT_LPSTR )
214 LPSTR str = msi_alloc( propdata->u.str.len );
215 memcpy( str, propdata->u.str.str, propdata->u.str.len );
216 str[ propdata->u.str.len - 1 ] = 0;
217 property.u.pszVal = str;
219 else if( propdata->type == VT_FILETIME )
220 property.u.filetime = propdata->u.ft;
221 else if( propdata->type == VT_I2 )
222 property.u.iVal = propdata->u.i2;
223 else if( propdata->type == VT_I4 )
224 property.u.lVal = propdata->u.i4;
226 /* check the type is the same as we expect */
227 if( type != propdata->type )
229 propvar_changetype(&changed, &property, type);
230 ptr = &changed;
232 else
233 ptr = &property;
235 prop[ idofs[i].propid ] = *ptr;
239 static UINT load_summary_info( MSISUMMARYINFO *si, IStream *stm )
241 UINT ret = ERROR_FUNCTION_FAILED;
242 PROPERTYSETHEADER set_hdr;
243 FORMATIDOFFSET format_hdr;
244 PROPERTYSECTIONHEADER section_hdr;
245 LPBYTE data = NULL;
246 LARGE_INTEGER ofs;
247 ULONG count, sz;
248 HRESULT r;
250 TRACE("%p %p\n", si, stm);
252 /* read the header */
253 sz = sizeof set_hdr;
254 r = IStream_Read( stm, &set_hdr, sz, &count );
255 if( FAILED(r) || count != sz )
256 return ret;
258 if( set_hdr.wByteOrder != 0xfffe )
260 ERR("property set not big-endian %04X\n", set_hdr.wByteOrder);
261 return ret;
264 sz = sizeof format_hdr;
265 r = IStream_Read( stm, &format_hdr, sz, &count );
266 if( FAILED(r) || count != sz )
267 return ret;
269 /* check the format id is correct */
270 if( !IsEqualGUID( &FMTID_SummaryInformation, &format_hdr.fmtid ) )
271 return ret;
273 /* seek to the location of the section */
274 ofs.QuadPart = format_hdr.dwOffset;
275 r = IStream_Seek( stm, ofs, STREAM_SEEK_SET, NULL );
276 if( FAILED(r) )
277 return ret;
279 /* read the section itself */
280 sz = SECT_HDR_SIZE;
281 r = IStream_Read( stm, &section_hdr, sz, &count );
282 if( FAILED(r) || count != sz )
283 return ret;
285 if( section_hdr.cProperties > MSI_MAX_PROPS )
287 ERR("too many properties %d\n", section_hdr.cProperties);
288 return ret;
291 data = msi_alloc( section_hdr.cbSection);
292 if( !data )
293 return ret;
295 memcpy( data, &section_hdr, SECT_HDR_SIZE );
297 /* read all the data in one go */
298 sz = section_hdr.cbSection - SECT_HDR_SIZE;
299 r = IStream_Read( stm, &data[ SECT_HDR_SIZE ], sz, &count );
300 if( SUCCEEDED(r) && count == sz )
301 read_properties_from_data( si->property, data, sz + SECT_HDR_SIZE );
302 else
303 ERR("failed to read properties %d %d\n", count, sz);
305 msi_free( data );
306 return ret;
309 static DWORD write_dword( LPBYTE data, DWORD ofs, DWORD val )
311 if( data )
313 data[ofs++] = val&0xff;
314 data[ofs++] = (val>>8)&0xff;
315 data[ofs++] = (val>>16)&0xff;
316 data[ofs++] = (val>>24)&0xff;
318 return 4;
321 static DWORD write_filetime( LPBYTE data, DWORD ofs, const FILETIME *ft )
323 write_dword( data, ofs, ft->dwLowDateTime );
324 write_dword( data, ofs + 4, ft->dwHighDateTime );
325 return 8;
328 static DWORD write_string( LPBYTE data, DWORD ofs, LPCSTR str )
330 DWORD len = lstrlenA( str ) + 1;
331 write_dword( data, ofs, len );
332 if( data )
333 memcpy( &data[ofs + 4], str, len );
334 return (7 + len) & ~3;
337 static UINT write_property_to_data( const PROPVARIANT *prop, LPBYTE data )
339 DWORD sz = 0;
341 if( prop->vt == VT_EMPTY )
342 return sz;
344 /* add the type */
345 sz += write_dword( data, sz, prop->vt );
346 switch( prop->vt )
348 case VT_I2:
349 sz += write_dword( data, sz, prop->u.iVal );
350 break;
351 case VT_I4:
352 sz += write_dword( data, sz, prop->u.lVal );
353 break;
354 case VT_FILETIME:
355 sz += write_filetime( data, sz, &prop->u.filetime );
356 break;
357 case VT_LPSTR:
358 sz += write_string( data, sz, prop->u.pszVal );
359 break;
361 return sz;
364 static UINT save_summary_info( const MSISUMMARYINFO * si, IStream *stm )
366 UINT ret = ERROR_FUNCTION_FAILED;
367 PROPERTYSETHEADER set_hdr;
368 FORMATIDOFFSET format_hdr;
369 PROPERTYSECTIONHEADER section_hdr;
370 PROPERTYIDOFFSET idofs[MSI_MAX_PROPS];
371 LPBYTE data = NULL;
372 ULONG count, sz;
373 HRESULT r;
374 int i;
376 /* write the header */
377 sz = sizeof set_hdr;
378 memset( &set_hdr, 0, sz );
379 set_hdr.wByteOrder = 0xfffe;
380 set_hdr.wFormat = 0;
381 set_hdr.dwOSVer = 0x00020005; /* build 5, platform id 2 */
382 /* set_hdr.clsID is {00000000-0000-0000-0000-000000000000} */
383 set_hdr.reserved = 1;
384 r = IStream_Write( stm, &set_hdr, sz, &count );
385 if( FAILED(r) || count != sz )
386 return ret;
388 /* write the format header */
389 sz = sizeof format_hdr;
390 format_hdr.fmtid = FMTID_SummaryInformation;
391 format_hdr.dwOffset = sizeof format_hdr + sizeof set_hdr;
392 r = IStream_Write( stm, &format_hdr, sz, &count );
393 if( FAILED(r) || count != sz )
394 return ret;
396 /* add up how much space the data will take and calculate the offsets */
397 section_hdr.cbSection = sizeof section_hdr;
398 section_hdr.cbSection += (get_property_count( si->property ) * sizeof idofs[0]);
399 section_hdr.cProperties = 0;
400 for( i = 0; i < MSI_MAX_PROPS; i++ )
402 sz = write_property_to_data( &si->property[i], NULL );
403 if( !sz )
404 continue;
405 idofs[ section_hdr.cProperties ].propid = i;
406 idofs[ section_hdr.cProperties ].dwOffset = section_hdr.cbSection;
407 section_hdr.cProperties++;
408 section_hdr.cbSection += sz;
411 data = msi_alloc_zero( section_hdr.cbSection );
413 sz = 0;
414 memcpy( &data[sz], &section_hdr, sizeof section_hdr );
415 sz += sizeof section_hdr;
417 memcpy( &data[sz], idofs, section_hdr.cProperties * sizeof idofs[0] );
418 sz += section_hdr.cProperties * sizeof idofs[0];
420 /* write out the data */
421 for( i = 0; i < MSI_MAX_PROPS; i++ )
422 sz += write_property_to_data( &si->property[i], &data[sz] );
424 r = IStream_Write( stm, data, sz, &count );
425 msi_free( data );
426 if( FAILED(r) || count != sz )
427 return ret;
429 return ERROR_SUCCESS;
432 MSISUMMARYINFO *MSI_GetSummaryInformationW( IStorage *stg, UINT uiUpdateCount )
434 IStream *stm = NULL;
435 MSISUMMARYINFO *si;
436 DWORD grfMode;
437 HRESULT r;
439 TRACE("%p %d\n", stg, uiUpdateCount );
441 si = alloc_msiobject( MSIHANDLETYPE_SUMMARYINFO,
442 sizeof (MSISUMMARYINFO), MSI_CloseSummaryInfo );
443 if( !si )
444 return si;
446 si->update_count = uiUpdateCount;
447 IStorage_AddRef( stg );
448 si->storage = stg;
450 /* read the stream... if we fail, we'll start with an empty property set */
451 grfMode = STGM_READ | STGM_SHARE_EXCLUSIVE;
452 r = IStorage_OpenStream( si->storage, szSumInfo, 0, grfMode, 0, &stm );
453 if( SUCCEEDED(r) )
455 load_summary_info( si, stm );
456 IStream_Release( stm );
459 return si;
462 UINT WINAPI MsiGetSummaryInformationW( MSIHANDLE hDatabase,
463 LPCWSTR szDatabase, UINT uiUpdateCount, MSIHANDLE *pHandle )
465 MSISUMMARYINFO *si;
466 MSIDATABASE *db;
467 UINT ret = ERROR_FUNCTION_FAILED;
469 TRACE("%d %s %d %p\n", hDatabase, debugstr_w(szDatabase),
470 uiUpdateCount, pHandle);
472 if( !pHandle )
473 return ERROR_INVALID_PARAMETER;
475 if( szDatabase )
477 LPCWSTR persist = uiUpdateCount ? MSIDBOPEN_TRANSACT : MSIDBOPEN_READONLY;
479 ret = MSI_OpenDatabaseW( szDatabase, persist, &db );
480 if( ret != ERROR_SUCCESS )
481 return ret;
483 else
485 db = msihandle2msiinfo( hDatabase, MSIHANDLETYPE_DATABASE );
486 if( !db )
488 HRESULT hr;
489 IWineMsiRemoteDatabase *remote_database;
491 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( hDatabase );
492 if ( !remote_database )
493 return ERROR_INVALID_HANDLE;
495 hr = IWineMsiRemoteDatabase_GetSummaryInformation( remote_database,
496 uiUpdateCount, pHandle );
497 IWineMsiRemoteDatabase_Release( remote_database );
499 if (FAILED(hr))
501 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
502 return HRESULT_CODE(hr);
504 return ERROR_FUNCTION_FAILED;
507 return ERROR_SUCCESS;
511 si = MSI_GetSummaryInformationW( db->storage, uiUpdateCount );
512 if (si)
514 *pHandle = alloc_msihandle( &si->hdr );
515 if( *pHandle )
516 ret = ERROR_SUCCESS;
517 else
518 ret = ERROR_NOT_ENOUGH_MEMORY;
519 msiobj_release( &si->hdr );
522 if( db )
523 msiobj_release( &db->hdr );
525 return ret;
528 UINT WINAPI MsiGetSummaryInformationA(MSIHANDLE hDatabase,
529 LPCSTR szDatabase, UINT uiUpdateCount, MSIHANDLE *pHandle)
531 LPWSTR szwDatabase = NULL;
532 UINT ret;
534 TRACE("%d %s %d %p\n", hDatabase, debugstr_a(szDatabase),
535 uiUpdateCount, pHandle);
537 if( szDatabase )
539 szwDatabase = strdupAtoW( szDatabase );
540 if( !szwDatabase )
541 return ERROR_FUNCTION_FAILED;
544 ret = MsiGetSummaryInformationW(hDatabase, szwDatabase, uiUpdateCount, pHandle);
546 msi_free( szwDatabase );
548 return ret;
551 UINT WINAPI MsiSummaryInfoGetPropertyCount(MSIHANDLE hSummaryInfo, PUINT pCount)
553 MSISUMMARYINFO *si;
555 TRACE("%d %p\n", hSummaryInfo, pCount);
557 si = msihandle2msiinfo( hSummaryInfo, MSIHANDLETYPE_SUMMARYINFO );
558 if( !si )
559 return ERROR_INVALID_HANDLE;
561 if( pCount )
562 *pCount = get_property_count( si->property );
563 msiobj_release( &si->hdr );
565 return ERROR_SUCCESS;
568 static UINT get_prop( MSIHANDLE handle, UINT uiProperty, UINT *puiDataType,
569 INT *piValue, FILETIME *pftValue, awstring *str, DWORD *pcchValueBuf)
571 MSISUMMARYINFO *si;
572 PROPVARIANT *prop;
573 UINT ret = ERROR_SUCCESS;
575 TRACE("%d %d %p %p %p %p %p\n", handle, uiProperty, puiDataType,
576 piValue, pftValue, str, pcchValueBuf);
578 if ( uiProperty >= MSI_MAX_PROPS )
580 if (puiDataType) *puiDataType = VT_EMPTY;
581 return ERROR_UNKNOWN_PROPERTY;
584 si = msihandle2msiinfo( handle, MSIHANDLETYPE_SUMMARYINFO );
585 if( !si )
586 return ERROR_INVALID_HANDLE;
588 prop = &si->property[uiProperty];
590 if( puiDataType )
591 *puiDataType = prop->vt;
593 switch( prop->vt )
595 case VT_I2:
596 if( piValue )
597 *piValue = prop->u.iVal;
598 break;
599 case VT_I4:
600 if( piValue )
601 *piValue = prop->u.lVal;
602 break;
603 case VT_LPSTR:
604 if( pcchValueBuf )
606 DWORD len = 0;
608 if( str->unicode )
610 len = MultiByteToWideChar( CP_ACP, 0, prop->u.pszVal, -1, NULL, 0 ) - 1;
611 MultiByteToWideChar( CP_ACP, 0, prop->u.pszVal, -1, str->str.w, *pcchValueBuf );
613 else
615 len = lstrlenA( prop->u.pszVal );
616 if( str->str.a )
617 lstrcpynA(str->str.a, prop->u.pszVal, *pcchValueBuf );
619 if (len >= *pcchValueBuf)
620 ret = ERROR_MORE_DATA;
621 *pcchValueBuf = len;
623 break;
624 case VT_FILETIME:
625 if( pftValue )
626 *pftValue = prop->u.filetime;
627 break;
628 case VT_EMPTY:
629 break;
630 default:
631 FIXME("Unknown property variant type\n");
632 break;
634 msiobj_release( &si->hdr );
635 return ret;
638 LPWSTR msi_suminfo_dup_string( MSISUMMARYINFO *si, UINT uiProperty )
640 PROPVARIANT *prop;
642 if ( uiProperty >= MSI_MAX_PROPS )
643 return NULL;
644 prop = &si->property[uiProperty];
645 if( prop->vt != VT_LPSTR )
646 return NULL;
647 return strdupAtoW( prop->u.pszVal );
650 LPWSTR msi_get_suminfo_product( IStorage *stg )
652 MSISUMMARYINFO *si;
653 LPWSTR prod;
655 si = MSI_GetSummaryInformationW( stg, 0 );
656 if (!si)
658 ERR("no summary information!\n");
659 return NULL;
661 prod = msi_suminfo_dup_string( si, PID_REVNUMBER );
662 msiobj_release( &si->hdr );
663 return prod;
666 UINT WINAPI MsiSummaryInfoGetPropertyA(
667 MSIHANDLE handle, UINT uiProperty, PUINT puiDataType, LPINT piValue,
668 FILETIME *pftValue, LPSTR szValueBuf, LPDWORD pcchValueBuf)
670 awstring str;
672 TRACE("%d %d %p %p %p %p %p\n", handle, uiProperty, puiDataType,
673 piValue, pftValue, szValueBuf, pcchValueBuf );
675 str.unicode = FALSE;
676 str.str.a = szValueBuf;
678 return get_prop( handle, uiProperty, puiDataType, piValue,
679 pftValue, &str, pcchValueBuf );
682 UINT WINAPI MsiSummaryInfoGetPropertyW(
683 MSIHANDLE handle, UINT uiProperty, PUINT puiDataType, LPINT piValue,
684 FILETIME *pftValue, LPWSTR szValueBuf, LPDWORD pcchValueBuf)
686 awstring str;
688 TRACE("%d %d %p %p %p %p %p\n", handle, uiProperty, puiDataType,
689 piValue, pftValue, szValueBuf, pcchValueBuf );
691 str.unicode = TRUE;
692 str.str.w = szValueBuf;
694 return get_prop( handle, uiProperty, puiDataType, piValue,
695 pftValue, &str, pcchValueBuf );
698 static UINT set_prop( MSISUMMARYINFO *si, UINT uiProperty, UINT type,
699 INT iValue, FILETIME* pftValue, awcstring *str )
701 PROPVARIANT *prop;
702 UINT len;
704 TRACE("%p %u %u %i %p %p\n", si, uiProperty, type, iValue,
705 pftValue, str );
707 prop = &si->property[uiProperty];
709 if( prop->vt == VT_EMPTY )
711 if( !si->update_count )
712 return ERROR_FUNCTION_FAILED;
714 si->update_count--;
716 else if( prop->vt != type )
717 return ERROR_SUCCESS;
719 free_prop( prop );
720 prop->vt = type;
721 switch( type )
723 case VT_I4:
724 prop->u.lVal = iValue;
725 break;
726 case VT_I2:
727 prop->u.iVal = iValue;
728 break;
729 case VT_FILETIME:
730 prop->u.filetime = *pftValue;
731 break;
732 case VT_LPSTR:
733 if( str->unicode )
735 len = WideCharToMultiByte( CP_ACP, 0, str->str.w, -1,
736 NULL, 0, NULL, NULL );
737 prop->u.pszVal = msi_alloc( len );
738 WideCharToMultiByte( CP_ACP, 0, str->str.w, -1,
739 prop->u.pszVal, len, NULL, NULL );
741 else
743 len = lstrlenA( str->str.a ) + 1;
744 prop->u.pszVal = msi_alloc( len );
745 lstrcpyA( prop->u.pszVal, str->str.a );
747 break;
750 return ERROR_SUCCESS;
753 UINT WINAPI MsiSummaryInfoSetPropertyW( MSIHANDLE handle, UINT uiProperty,
754 UINT uiDataType, INT iValue, FILETIME* pftValue, LPCWSTR szValue )
756 awcstring str;
757 MSISUMMARYINFO *si;
758 UINT type, ret;
760 TRACE("%d %u %u %i %p %s\n", handle, uiProperty, uiDataType,
761 iValue, pftValue, debugstr_w(szValue) );
763 type = get_type( uiProperty );
764 if( type == VT_EMPTY || type != uiDataType )
765 return ERROR_DATATYPE_MISMATCH;
767 if( uiDataType == VT_LPSTR && !szValue )
768 return ERROR_INVALID_PARAMETER;
770 if( uiDataType == VT_FILETIME && !pftValue )
771 return ERROR_INVALID_PARAMETER;
773 si = msihandle2msiinfo( handle, MSIHANDLETYPE_SUMMARYINFO );
774 if( !si )
775 return ERROR_INVALID_HANDLE;
777 str.unicode = TRUE;
778 str.str.w = szValue;
779 ret = set_prop( si, uiProperty, type, iValue, pftValue, &str );
781 msiobj_release( &si->hdr );
782 return ret;
785 UINT WINAPI MsiSummaryInfoSetPropertyA( MSIHANDLE handle, UINT uiProperty,
786 UINT uiDataType, INT iValue, FILETIME* pftValue, LPCSTR szValue )
788 awcstring str;
789 MSISUMMARYINFO *si;
790 UINT type, ret;
792 TRACE("%d %u %u %i %p %s\n", handle, uiProperty, uiDataType,
793 iValue, pftValue, debugstr_a(szValue) );
795 type = get_type( uiProperty );
796 if( type == VT_EMPTY || type != uiDataType )
797 return ERROR_DATATYPE_MISMATCH;
799 if( uiDataType == VT_LPSTR && !szValue )
800 return ERROR_INVALID_PARAMETER;
802 if( uiDataType == VT_FILETIME && !pftValue )
803 return ERROR_INVALID_PARAMETER;
805 si = msihandle2msiinfo( handle, MSIHANDLETYPE_SUMMARYINFO );
806 if( !si )
807 return ERROR_INVALID_HANDLE;
809 str.unicode = FALSE;
810 str.str.a = szValue;
811 ret = set_prop( si, uiProperty, uiDataType, iValue, pftValue, &str );
813 msiobj_release( &si->hdr );
814 return ret;
817 static UINT suminfo_persist( MSISUMMARYINFO *si )
819 UINT ret = ERROR_FUNCTION_FAILED;
820 IStream *stm = NULL;
821 DWORD grfMode;
822 HRESULT r;
824 grfMode = STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE;
825 r = IStorage_CreateStream( si->storage, szSumInfo, grfMode, 0, 0, &stm );
826 if( SUCCEEDED(r) )
828 ret = save_summary_info( si, stm );
829 IStream_Release( stm );
831 return ret;
834 static void parse_filetime( LPCWSTR str, FILETIME *ft )
836 SYSTEMTIME lt, utc;
837 const WCHAR *p = str;
838 WCHAR *end;
840 memset( &lt, 0, sizeof(lt) );
842 /* YYYY/MM/DD hh:mm:ss */
844 while (isspaceW( *p )) p++;
846 lt.wYear = strtolW( p, &end, 10 );
847 if (*end != '/') return;
848 p = end + 1;
850 lt.wMonth = strtolW( p, &end, 10 );
851 if (*end != '/') return;
852 p = end + 1;
854 lt.wDay = strtolW( p, &end, 10 );
855 if (*end != ' ') return;
856 p = end + 1;
858 while (isspaceW( *p )) p++;
860 lt.wHour = strtolW( p, &end, 10 );
861 if (*end != ':') return;
862 p = end + 1;
864 lt.wMinute = strtolW( p, &end, 10 );
865 if (*end != ':') return;
866 p = end + 1;
868 lt.wSecond = strtolW( p, &end, 10 );
870 TzSpecificLocalTimeToSystemTime( NULL, &lt, &utc );
871 SystemTimeToFileTime( &utc, ft );
874 static UINT parse_prop( LPCWSTR prop, LPCWSTR value, UINT *pid, INT *int_value,
875 FILETIME *ft_value, awcstring *str_value )
877 *pid = atoiW( prop );
878 switch (*pid)
880 case PID_CODEPAGE:
881 case PID_WORDCOUNT:
882 case PID_CHARCOUNT:
883 case PID_SECURITY:
884 case PID_PAGECOUNT:
885 *int_value = atoiW( value );
886 break;
888 case PID_LASTPRINTED:
889 case PID_CREATE_DTM:
890 case PID_LASTSAVE_DTM:
891 parse_filetime( value, ft_value );
892 break;
894 case PID_SUBJECT:
895 case PID_AUTHOR:
896 case PID_KEYWORDS:
897 case PID_COMMENTS:
898 case PID_TEMPLATE:
899 case PID_LASTAUTHOR:
900 case PID_REVNUMBER:
901 case PID_APPNAME:
902 case PID_TITLE:
903 str_value->str.w = value;
904 str_value->unicode = TRUE;
905 break;
907 default:
908 WARN("unhandled prop id %u\n", *pid);
909 return ERROR_FUNCTION_FAILED;
912 return ERROR_SUCCESS;
915 UINT msi_add_suminfo( MSIDATABASE *db, LPWSTR **records, int num_records, int num_columns )
917 UINT r = ERROR_FUNCTION_FAILED;
918 DWORD i, j;
919 MSISUMMARYINFO *si;
921 si = MSI_GetSummaryInformationW( db->storage, num_records * (num_columns / 2) );
922 if (!si)
924 ERR("no summary information!\n");
925 return ERROR_FUNCTION_FAILED;
928 for (i = 0; i < num_records; i++)
930 for (j = 0; j < num_columns; j += 2)
932 UINT pid;
933 INT int_value = 0;
934 FILETIME ft_value;
935 awcstring str_value;
937 r = parse_prop( records[i][j], records[i][j + 1], &pid, &int_value, &ft_value, &str_value );
938 if (r != ERROR_SUCCESS)
939 goto end;
941 r = set_prop( si, pid, get_type(pid), int_value, &ft_value, &str_value );
942 if (r != ERROR_SUCCESS)
943 goto end;
947 end:
948 if (r == ERROR_SUCCESS)
949 r = suminfo_persist( si );
951 msiobj_release( &si->hdr );
952 return r;
955 UINT WINAPI MsiSummaryInfoPersist( MSIHANDLE handle )
957 MSISUMMARYINFO *si;
958 UINT ret;
960 TRACE("%d\n", handle );
962 si = msihandle2msiinfo( handle, MSIHANDLETYPE_SUMMARYINFO );
963 if( !si )
964 return ERROR_INVALID_HANDLE;
966 ret = suminfo_persist( si );
968 msiobj_release( &si->hdr );
969 return ret;