Release 1.7.39.
[wine.git] / dlls / msi / suminfo.c
blob97544d553593b71eb41a9869dbbc24d2d6890d04
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 void free_prop( PROPVARIANT *prop )
91 if (prop->vt == VT_LPSTR )
92 msi_free( prop->u.pszVal );
93 prop->vt = VT_EMPTY;
96 static void MSI_CloseSummaryInfo( MSIOBJECTHDR *arg )
98 MSISUMMARYINFO *si = (MSISUMMARYINFO *) arg;
99 DWORD i;
101 for( i = 0; i < MSI_MAX_PROPS; i++ )
102 free_prop( &si->property[i] );
103 IStorage_Release( si->storage );
106 static UINT get_type( UINT uiProperty )
108 switch( uiProperty )
110 case PID_CODEPAGE:
111 return VT_I2;
113 case PID_SUBJECT:
114 case PID_AUTHOR:
115 case PID_KEYWORDS:
116 case PID_COMMENTS:
117 case PID_TEMPLATE:
118 case PID_LASTAUTHOR:
119 case PID_REVNUMBER:
120 case PID_APPNAME:
121 case PID_TITLE:
122 return VT_LPSTR;
124 case PID_LASTPRINTED:
125 case PID_CREATE_DTM:
126 case PID_LASTSAVE_DTM:
127 return VT_FILETIME;
129 case PID_WORDCOUNT:
130 case PID_CHARCOUNT:
131 case PID_SECURITY:
132 case PID_PAGECOUNT:
133 return VT_I4;
135 return VT_EMPTY;
138 static UINT get_property_count( const PROPVARIANT *property )
140 UINT i, n = 0;
142 if( !property )
143 return n;
144 for( i = 0; i < MSI_MAX_PROPS; i++ )
145 if( property[i].vt != VT_EMPTY )
146 n++;
147 return n;
150 static UINT propvar_changetype(PROPVARIANT *changed, PROPVARIANT *property, VARTYPE vt)
152 HRESULT hr;
153 HMODULE propsys = LoadLibraryA("propsys.dll");
154 pPropVariantChangeType = (void *)GetProcAddress(propsys, "PropVariantChangeType");
156 if (!pPropVariantChangeType)
158 ERR("PropVariantChangeType function missing!\n");
159 return ERROR_FUNCTION_FAILED;
162 hr = pPropVariantChangeType(changed, property, 0, vt);
163 return (hr == S_OK) ? ERROR_SUCCESS : ERROR_FUNCTION_FAILED;
166 /* FIXME: doesn't deal with endian conversion */
167 static void read_properties_from_data( PROPVARIANT *prop, LPBYTE data, DWORD sz )
169 UINT type;
170 DWORD i, size;
171 PROPERTY_DATA *propdata;
172 PROPVARIANT property, *ptr;
173 PROPVARIANT changed;
174 PROPERTYIDOFFSET *idofs;
175 PROPERTYSECTIONHEADER *section_hdr;
177 section_hdr = (PROPERTYSECTIONHEADER*) &data[0];
178 idofs = (PROPERTYIDOFFSET*) &data[SECT_HDR_SIZE];
180 /* now set all the properties */
181 for( i = 0; i < section_hdr->cProperties; i++ )
183 if( idofs[i].propid >= MSI_MAX_PROPS )
185 ERR("Unknown property ID %d\n", idofs[i].propid );
186 break;
189 type = get_type( idofs[i].propid );
190 if( type == VT_EMPTY )
192 ERR("propid %d has unknown type\n", idofs[i].propid);
193 break;
196 propdata = (PROPERTY_DATA*) &data[ idofs[i].dwOffset ];
198 /* check we don't run off the end of the data */
199 size = sz - idofs[i].dwOffset - sizeof(DWORD);
200 if( sizeof(DWORD) > size ||
201 ( propdata->type == VT_FILETIME && sizeof(FILETIME) > size ) ||
202 ( propdata->type == VT_LPSTR && (propdata->u.str.len + sizeof(DWORD)) > size ) )
204 ERR("not enough data\n");
205 break;
208 property.vt = propdata->type;
209 if( propdata->type == VT_LPSTR )
211 LPSTR str = msi_alloc( propdata->u.str.len );
212 memcpy( str, propdata->u.str.str, propdata->u.str.len );
213 str[ propdata->u.str.len - 1 ] = 0;
214 property.u.pszVal = str;
216 else if( propdata->type == VT_FILETIME )
217 property.u.filetime = propdata->u.ft;
218 else if( propdata->type == VT_I2 )
219 property.u.iVal = propdata->u.i2;
220 else if( propdata->type == VT_I4 )
221 property.u.lVal = propdata->u.i4;
223 /* check the type is the same as we expect */
224 if( type != propdata->type )
226 propvar_changetype(&changed, &property, type);
227 ptr = &changed;
229 else
230 ptr = &property;
232 prop[ idofs[i].propid ] = *ptr;
236 static UINT load_summary_info( MSISUMMARYINFO *si, IStream *stm )
238 PROPERTYSETHEADER set_hdr;
239 FORMATIDOFFSET format_hdr;
240 PROPERTYSECTIONHEADER section_hdr;
241 LPBYTE data = NULL;
242 LARGE_INTEGER ofs;
243 ULONG count, sz;
244 HRESULT r;
246 TRACE("%p %p\n", si, stm);
248 /* read the header */
249 sz = sizeof set_hdr;
250 r = IStream_Read( stm, &set_hdr, sz, &count );
251 if( FAILED(r) || count != sz )
252 return ERROR_FUNCTION_FAILED;
254 if( set_hdr.wByteOrder != 0xfffe )
256 ERR("property set not big-endian %04X\n", set_hdr.wByteOrder);
257 return ERROR_FUNCTION_FAILED;
260 sz = sizeof format_hdr;
261 r = IStream_Read( stm, &format_hdr, sz, &count );
262 if( FAILED(r) || count != sz )
263 return ERROR_FUNCTION_FAILED;
265 /* check the format id is correct */
266 if( !IsEqualGUID( &FMTID_SummaryInformation, &format_hdr.fmtid ) )
267 return ERROR_FUNCTION_FAILED;
269 /* seek to the location of the section */
270 ofs.QuadPart = format_hdr.dwOffset;
271 r = IStream_Seek( stm, ofs, STREAM_SEEK_SET, NULL );
272 if( FAILED(r) )
273 return ERROR_FUNCTION_FAILED;
275 /* read the section itself */
276 sz = SECT_HDR_SIZE;
277 r = IStream_Read( stm, &section_hdr, sz, &count );
278 if( FAILED(r) || count != sz )
279 return ERROR_FUNCTION_FAILED;
281 if( section_hdr.cProperties > MSI_MAX_PROPS )
283 ERR("too many properties %d\n", section_hdr.cProperties);
284 return ERROR_FUNCTION_FAILED;
287 data = msi_alloc( section_hdr.cbSection);
288 if( !data )
289 return ERROR_FUNCTION_FAILED;
291 memcpy( data, &section_hdr, SECT_HDR_SIZE );
293 /* read all the data in one go */
294 sz = section_hdr.cbSection - SECT_HDR_SIZE;
295 r = IStream_Read( stm, &data[ SECT_HDR_SIZE ], sz, &count );
296 if( SUCCEEDED(r) && count == sz )
297 read_properties_from_data( si->property, data, sz + SECT_HDR_SIZE );
298 else
299 ERR("failed to read properties %d %d\n", count, sz);
301 msi_free( data );
302 return ERROR_SUCCESS;
305 static DWORD write_dword( LPBYTE data, DWORD ofs, DWORD val )
307 if( data )
309 data[ofs++] = val&0xff;
310 data[ofs++] = (val>>8)&0xff;
311 data[ofs++] = (val>>16)&0xff;
312 data[ofs++] = (val>>24)&0xff;
314 return 4;
317 static DWORD write_filetime( LPBYTE data, DWORD ofs, const FILETIME *ft )
319 write_dword( data, ofs, ft->dwLowDateTime );
320 write_dword( data, ofs + 4, ft->dwHighDateTime );
321 return 8;
324 static DWORD write_string( LPBYTE data, DWORD ofs, LPCSTR str )
326 DWORD len = lstrlenA( str ) + 1;
327 write_dword( data, ofs, len );
328 if( data )
329 memcpy( &data[ofs + 4], str, len );
330 return (7 + len) & ~3;
333 static UINT write_property_to_data( const PROPVARIANT *prop, LPBYTE data )
335 DWORD sz = 0;
337 if( prop->vt == VT_EMPTY )
338 return sz;
340 /* add the type */
341 sz += write_dword( data, sz, prop->vt );
342 switch( prop->vt )
344 case VT_I2:
345 sz += write_dword( data, sz, prop->u.iVal );
346 break;
347 case VT_I4:
348 sz += write_dword( data, sz, prop->u.lVal );
349 break;
350 case VT_FILETIME:
351 sz += write_filetime( data, sz, &prop->u.filetime );
352 break;
353 case VT_LPSTR:
354 sz += write_string( data, sz, prop->u.pszVal );
355 break;
357 return sz;
360 static UINT save_summary_info( const MSISUMMARYINFO * si, IStream *stm )
362 UINT ret = ERROR_FUNCTION_FAILED;
363 PROPERTYSETHEADER set_hdr;
364 FORMATIDOFFSET format_hdr;
365 PROPERTYSECTIONHEADER section_hdr;
366 PROPERTYIDOFFSET idofs[MSI_MAX_PROPS];
367 LPBYTE data = NULL;
368 ULONG count, sz;
369 HRESULT r;
370 int i;
372 /* write the header */
373 sz = sizeof set_hdr;
374 memset( &set_hdr, 0, sz );
375 set_hdr.wByteOrder = 0xfffe;
376 set_hdr.wFormat = 0;
377 set_hdr.dwOSVer = 0x00020005; /* build 5, platform id 2 */
378 /* set_hdr.clsID is {00000000-0000-0000-0000-000000000000} */
379 set_hdr.reserved = 1;
380 r = IStream_Write( stm, &set_hdr, sz, &count );
381 if( FAILED(r) || count != sz )
382 return ret;
384 /* write the format header */
385 sz = sizeof format_hdr;
386 format_hdr.fmtid = FMTID_SummaryInformation;
387 format_hdr.dwOffset = sizeof format_hdr + sizeof set_hdr;
388 r = IStream_Write( stm, &format_hdr, sz, &count );
389 if( FAILED(r) || count != sz )
390 return ret;
392 /* add up how much space the data will take and calculate the offsets */
393 section_hdr.cbSection = sizeof section_hdr;
394 section_hdr.cbSection += (get_property_count( si->property ) * sizeof idofs[0]);
395 section_hdr.cProperties = 0;
396 for( i = 0; i < MSI_MAX_PROPS; i++ )
398 sz = write_property_to_data( &si->property[i], NULL );
399 if( !sz )
400 continue;
401 idofs[ section_hdr.cProperties ].propid = i;
402 idofs[ section_hdr.cProperties ].dwOffset = section_hdr.cbSection;
403 section_hdr.cProperties++;
404 section_hdr.cbSection += sz;
407 data = msi_alloc_zero( section_hdr.cbSection );
409 sz = 0;
410 memcpy( &data[sz], &section_hdr, sizeof section_hdr );
411 sz += sizeof section_hdr;
413 memcpy( &data[sz], idofs, section_hdr.cProperties * sizeof idofs[0] );
414 sz += section_hdr.cProperties * sizeof idofs[0];
416 /* write out the data */
417 for( i = 0; i < MSI_MAX_PROPS; i++ )
418 sz += write_property_to_data( &si->property[i], &data[sz] );
420 r = IStream_Write( stm, data, sz, &count );
421 msi_free( data );
422 if( FAILED(r) || count != sz )
423 return ret;
425 return ERROR_SUCCESS;
428 static MSISUMMARYINFO *create_suminfo( IStorage *stg, UINT update_count )
430 MSISUMMARYINFO *si;
432 if (!(si = alloc_msiobject( MSIHANDLETYPE_SUMMARYINFO, sizeof(MSISUMMARYINFO), MSI_CloseSummaryInfo )))
433 return NULL;
435 si->update_count = update_count;
436 IStorage_AddRef( stg );
437 si->storage = stg;
439 return si;
442 UINT msi_get_suminfo( IStorage *stg, UINT uiUpdateCount, MSISUMMARYINFO **ret )
444 IStream *stm;
445 MSISUMMARYINFO *si;
446 HRESULT hr;
447 UINT r;
449 TRACE("%p, %u\n", stg, uiUpdateCount);
451 if (!(si = create_suminfo( stg, uiUpdateCount ))) return ERROR_OUTOFMEMORY;
453 hr = IStorage_OpenStream( si->storage, szSumInfo, 0, STGM_READ|STGM_SHARE_EXCLUSIVE, 0, &stm );
454 if (FAILED( hr ))
456 msiobj_release( &si->hdr );
457 return ERROR_FUNCTION_FAILED;
460 r = load_summary_info( si, stm );
461 IStream_Release( stm );
462 if (r != ERROR_SUCCESS)
464 msiobj_release( &si->hdr );
465 return r;
468 *ret = si;
469 return ERROR_SUCCESS;
472 static UINT get_db_suminfo( MSIDATABASE *db, UINT uiUpdateCount, MSISUMMARYINFO **ret )
474 IStream *stm;
475 MSISUMMARYINFO *si;
476 UINT r;
478 if (!(si = create_suminfo( db->storage, uiUpdateCount ))) return ERROR_OUTOFMEMORY;
480 r = msi_get_stream( db, szSumInfo, &stm );
481 if (r != ERROR_SUCCESS)
483 msiobj_release( &si->hdr );
484 return r;
487 r = load_summary_info( si, stm );
488 IStream_Release( stm );
489 if (r != ERROR_SUCCESS)
491 msiobj_release( &si->hdr );
492 return r;
495 *ret = si;
496 return ERROR_SUCCESS;
499 UINT WINAPI MsiGetSummaryInformationW( MSIHANDLE hDatabase,
500 LPCWSTR szDatabase, UINT uiUpdateCount, MSIHANDLE *pHandle )
502 MSISUMMARYINFO *si;
503 MSIDATABASE *db;
504 UINT ret;
506 TRACE("%d %s %d %p\n", hDatabase, debugstr_w(szDatabase),
507 uiUpdateCount, pHandle);
509 if( !pHandle )
510 return ERROR_INVALID_PARAMETER;
512 if( szDatabase && szDatabase[0] )
514 LPCWSTR persist = uiUpdateCount ? MSIDBOPEN_TRANSACT : MSIDBOPEN_READONLY;
516 ret = MSI_OpenDatabaseW( szDatabase, persist, &db );
517 if( ret != ERROR_SUCCESS )
518 return ret;
520 else
522 db = msihandle2msiinfo( hDatabase, MSIHANDLETYPE_DATABASE );
523 if( !db )
525 HRESULT hr;
526 IWineMsiRemoteDatabase *remote_database;
528 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( hDatabase );
529 if ( !remote_database )
530 return ERROR_INVALID_HANDLE;
532 hr = IWineMsiRemoteDatabase_GetSummaryInformation( remote_database,
533 uiUpdateCount, pHandle );
534 IWineMsiRemoteDatabase_Release( remote_database );
536 if (FAILED(hr))
538 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
539 return HRESULT_CODE(hr);
541 return ERROR_FUNCTION_FAILED;
544 return ERROR_SUCCESS;
548 ret = msi_get_suminfo( db->storage, uiUpdateCount, &si );
549 if (ret != ERROR_SUCCESS)
550 ret = get_db_suminfo( db, uiUpdateCount, &si );
551 if (ret != ERROR_SUCCESS)
553 if ((si = create_suminfo( db->storage, uiUpdateCount )))
554 ret = ERROR_SUCCESS;
557 if (ret == ERROR_SUCCESS)
559 *pHandle = alloc_msihandle( &si->hdr );
560 if( *pHandle )
561 ret = ERROR_SUCCESS;
562 else
563 ret = ERROR_NOT_ENOUGH_MEMORY;
564 msiobj_release( &si->hdr );
567 msiobj_release( &db->hdr );
568 return ret;
571 UINT WINAPI MsiGetSummaryInformationA(MSIHANDLE hDatabase,
572 LPCSTR szDatabase, UINT uiUpdateCount, MSIHANDLE *pHandle)
574 LPWSTR szwDatabase = NULL;
575 UINT ret;
577 TRACE("%d %s %d %p\n", hDatabase, debugstr_a(szDatabase),
578 uiUpdateCount, pHandle);
580 if( szDatabase )
582 szwDatabase = strdupAtoW( szDatabase );
583 if( !szwDatabase )
584 return ERROR_FUNCTION_FAILED;
587 ret = MsiGetSummaryInformationW(hDatabase, szwDatabase, uiUpdateCount, pHandle);
589 msi_free( szwDatabase );
591 return ret;
594 UINT WINAPI MsiSummaryInfoGetPropertyCount(MSIHANDLE hSummaryInfo, PUINT pCount)
596 MSISUMMARYINFO *si;
598 TRACE("%d %p\n", hSummaryInfo, pCount);
600 si = msihandle2msiinfo( hSummaryInfo, MSIHANDLETYPE_SUMMARYINFO );
601 if( !si )
602 return ERROR_INVALID_HANDLE;
604 if( pCount )
605 *pCount = get_property_count( si->property );
606 msiobj_release( &si->hdr );
608 return ERROR_SUCCESS;
611 static UINT get_prop( MSIHANDLE handle, UINT uiProperty, UINT *puiDataType,
612 INT *piValue, FILETIME *pftValue, awstring *str, DWORD *pcchValueBuf)
614 MSISUMMARYINFO *si;
615 PROPVARIANT *prop;
616 UINT ret = ERROR_SUCCESS;
618 TRACE("%d %d %p %p %p %p %p\n", handle, uiProperty, puiDataType,
619 piValue, pftValue, str, pcchValueBuf);
621 if ( uiProperty >= MSI_MAX_PROPS )
623 if (puiDataType) *puiDataType = VT_EMPTY;
624 return ERROR_UNKNOWN_PROPERTY;
627 si = msihandle2msiinfo( handle, MSIHANDLETYPE_SUMMARYINFO );
628 if( !si )
629 return ERROR_INVALID_HANDLE;
631 prop = &si->property[uiProperty];
633 if( puiDataType )
634 *puiDataType = prop->vt;
636 switch( prop->vt )
638 case VT_I2:
639 if( piValue )
640 *piValue = prop->u.iVal;
641 break;
642 case VT_I4:
643 if( piValue )
644 *piValue = prop->u.lVal;
645 break;
646 case VT_LPSTR:
647 if( pcchValueBuf )
649 DWORD len = 0;
651 if( str->unicode )
653 len = MultiByteToWideChar( CP_ACP, 0, prop->u.pszVal, -1, NULL, 0 ) - 1;
654 MultiByteToWideChar( CP_ACP, 0, prop->u.pszVal, -1, str->str.w, *pcchValueBuf );
656 else
658 len = lstrlenA( prop->u.pszVal );
659 if( str->str.a )
660 lstrcpynA(str->str.a, prop->u.pszVal, *pcchValueBuf );
662 if (len >= *pcchValueBuf)
663 ret = ERROR_MORE_DATA;
664 *pcchValueBuf = len;
666 break;
667 case VT_FILETIME:
668 if( pftValue )
669 *pftValue = prop->u.filetime;
670 break;
671 case VT_EMPTY:
672 break;
673 default:
674 FIXME("Unknown property variant type\n");
675 break;
677 msiobj_release( &si->hdr );
678 return ret;
681 LPWSTR msi_suminfo_dup_string( MSISUMMARYINFO *si, UINT uiProperty )
683 PROPVARIANT *prop;
685 if ( uiProperty >= MSI_MAX_PROPS )
686 return NULL;
687 prop = &si->property[uiProperty];
688 if( prop->vt != VT_LPSTR )
689 return NULL;
690 return strdupAtoW( prop->u.pszVal );
693 INT msi_suminfo_get_int32( MSISUMMARYINFO *si, UINT uiProperty )
695 PROPVARIANT *prop;
697 if ( uiProperty >= MSI_MAX_PROPS )
698 return -1;
699 prop = &si->property[uiProperty];
700 if( prop->vt != VT_I4 )
701 return -1;
702 return prop->u.lVal;
705 LPWSTR msi_get_suminfo_product( IStorage *stg )
707 MSISUMMARYINFO *si;
708 LPWSTR prod;
709 UINT r;
711 r = msi_get_suminfo( stg, 0, &si );
712 if (r != ERROR_SUCCESS)
714 ERR("no summary information!\n");
715 return NULL;
717 prod = msi_suminfo_dup_string( si, PID_REVNUMBER );
718 msiobj_release( &si->hdr );
719 return prod;
722 UINT WINAPI MsiSummaryInfoGetPropertyA(
723 MSIHANDLE handle, UINT uiProperty, PUINT puiDataType, LPINT piValue,
724 FILETIME *pftValue, LPSTR szValueBuf, LPDWORD pcchValueBuf)
726 awstring str;
728 TRACE("%d %d %p %p %p %p %p\n", handle, uiProperty, puiDataType,
729 piValue, pftValue, szValueBuf, pcchValueBuf );
731 str.unicode = FALSE;
732 str.str.a = szValueBuf;
734 return get_prop( handle, uiProperty, puiDataType, piValue,
735 pftValue, &str, pcchValueBuf );
738 UINT WINAPI MsiSummaryInfoGetPropertyW(
739 MSIHANDLE handle, UINT uiProperty, PUINT puiDataType, LPINT piValue,
740 FILETIME *pftValue, LPWSTR szValueBuf, LPDWORD pcchValueBuf)
742 awstring str;
744 TRACE("%d %d %p %p %p %p %p\n", handle, uiProperty, puiDataType,
745 piValue, pftValue, szValueBuf, pcchValueBuf );
747 str.unicode = TRUE;
748 str.str.w = szValueBuf;
750 return get_prop( handle, uiProperty, puiDataType, piValue,
751 pftValue, &str, pcchValueBuf );
754 static UINT set_prop( MSISUMMARYINFO *si, UINT uiProperty, UINT type,
755 INT iValue, FILETIME* pftValue, awcstring *str )
757 PROPVARIANT *prop;
758 UINT len;
760 TRACE("%p %u %u %i %p %p\n", si, uiProperty, type, iValue,
761 pftValue, str );
763 prop = &si->property[uiProperty];
765 if( prop->vt == VT_EMPTY )
767 if( !si->update_count )
768 return ERROR_FUNCTION_FAILED;
770 si->update_count--;
772 else if( prop->vt != type )
773 return ERROR_SUCCESS;
775 free_prop( prop );
776 prop->vt = type;
777 switch( type )
779 case VT_I4:
780 prop->u.lVal = iValue;
781 break;
782 case VT_I2:
783 prop->u.iVal = iValue;
784 break;
785 case VT_FILETIME:
786 prop->u.filetime = *pftValue;
787 break;
788 case VT_LPSTR:
789 if( str->unicode )
791 len = WideCharToMultiByte( CP_ACP, 0, str->str.w, -1,
792 NULL, 0, NULL, NULL );
793 prop->u.pszVal = msi_alloc( len );
794 WideCharToMultiByte( CP_ACP, 0, str->str.w, -1,
795 prop->u.pszVal, len, NULL, NULL );
797 else
799 len = lstrlenA( str->str.a ) + 1;
800 prop->u.pszVal = msi_alloc( len );
801 lstrcpyA( prop->u.pszVal, str->str.a );
803 break;
806 return ERROR_SUCCESS;
809 UINT WINAPI MsiSummaryInfoSetPropertyW( MSIHANDLE handle, UINT uiProperty,
810 UINT uiDataType, INT iValue, FILETIME* pftValue, LPCWSTR szValue )
812 awcstring str;
813 MSISUMMARYINFO *si;
814 UINT type, ret;
816 TRACE("%d %u %u %i %p %s\n", handle, uiProperty, uiDataType,
817 iValue, pftValue, debugstr_w(szValue) );
819 type = get_type( uiProperty );
820 if( type == VT_EMPTY || type != uiDataType )
821 return ERROR_DATATYPE_MISMATCH;
823 if( uiDataType == VT_LPSTR && !szValue )
824 return ERROR_INVALID_PARAMETER;
826 if( uiDataType == VT_FILETIME && !pftValue )
827 return ERROR_INVALID_PARAMETER;
829 si = msihandle2msiinfo( handle, MSIHANDLETYPE_SUMMARYINFO );
830 if( !si )
831 return ERROR_INVALID_HANDLE;
833 str.unicode = TRUE;
834 str.str.w = szValue;
835 ret = set_prop( si, uiProperty, type, iValue, pftValue, &str );
837 msiobj_release( &si->hdr );
838 return ret;
841 UINT WINAPI MsiSummaryInfoSetPropertyA( MSIHANDLE handle, UINT uiProperty,
842 UINT uiDataType, INT iValue, FILETIME* pftValue, LPCSTR szValue )
844 awcstring str;
845 MSISUMMARYINFO *si;
846 UINT type, ret;
848 TRACE("%d %u %u %i %p %s\n", handle, uiProperty, uiDataType,
849 iValue, pftValue, debugstr_a(szValue) );
851 type = get_type( uiProperty );
852 if( type == VT_EMPTY || type != uiDataType )
853 return ERROR_DATATYPE_MISMATCH;
855 if( uiDataType == VT_LPSTR && !szValue )
856 return ERROR_INVALID_PARAMETER;
858 if( uiDataType == VT_FILETIME && !pftValue )
859 return ERROR_INVALID_PARAMETER;
861 si = msihandle2msiinfo( handle, MSIHANDLETYPE_SUMMARYINFO );
862 if( !si )
863 return ERROR_INVALID_HANDLE;
865 str.unicode = FALSE;
866 str.str.a = szValue;
867 ret = set_prop( si, uiProperty, uiDataType, iValue, pftValue, &str );
869 msiobj_release( &si->hdr );
870 return ret;
873 static UINT suminfo_persist( MSISUMMARYINFO *si )
875 UINT ret = ERROR_FUNCTION_FAILED;
876 IStream *stm = NULL;
877 DWORD grfMode;
878 HRESULT r;
880 grfMode = STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE;
881 r = IStorage_CreateStream( si->storage, szSumInfo, grfMode, 0, 0, &stm );
882 if( SUCCEEDED(r) )
884 ret = save_summary_info( si, stm );
885 IStream_Release( stm );
887 return ret;
890 static void parse_filetime( LPCWSTR str, FILETIME *ft )
892 SYSTEMTIME lt, utc;
893 const WCHAR *p = str;
894 WCHAR *end;
896 memset( &lt, 0, sizeof(lt) );
898 /* YYYY/MM/DD hh:mm:ss */
900 while (isspaceW( *p )) p++;
902 lt.wYear = strtolW( p, &end, 10 );
903 if (*end != '/') return;
904 p = end + 1;
906 lt.wMonth = strtolW( p, &end, 10 );
907 if (*end != '/') return;
908 p = end + 1;
910 lt.wDay = strtolW( p, &end, 10 );
911 if (*end != ' ') return;
912 p = end + 1;
914 while (isspaceW( *p )) p++;
916 lt.wHour = strtolW( p, &end, 10 );
917 if (*end != ':') return;
918 p = end + 1;
920 lt.wMinute = strtolW( p, &end, 10 );
921 if (*end != ':') return;
922 p = end + 1;
924 lt.wSecond = strtolW( p, &end, 10 );
926 TzSpecificLocalTimeToSystemTime( NULL, &lt, &utc );
927 SystemTimeToFileTime( &utc, ft );
930 static UINT parse_prop( LPCWSTR prop, LPCWSTR value, UINT *pid, INT *int_value,
931 FILETIME *ft_value, awcstring *str_value )
933 *pid = atoiW( prop );
934 switch (*pid)
936 case PID_CODEPAGE:
937 case PID_WORDCOUNT:
938 case PID_CHARCOUNT:
939 case PID_SECURITY:
940 case PID_PAGECOUNT:
941 *int_value = atoiW( value );
942 break;
944 case PID_LASTPRINTED:
945 case PID_CREATE_DTM:
946 case PID_LASTSAVE_DTM:
947 parse_filetime( value, ft_value );
948 break;
950 case PID_SUBJECT:
951 case PID_AUTHOR:
952 case PID_KEYWORDS:
953 case PID_COMMENTS:
954 case PID_TEMPLATE:
955 case PID_LASTAUTHOR:
956 case PID_REVNUMBER:
957 case PID_APPNAME:
958 case PID_TITLE:
959 str_value->str.w = value;
960 str_value->unicode = TRUE;
961 break;
963 default:
964 WARN("unhandled prop id %u\n", *pid);
965 return ERROR_FUNCTION_FAILED;
968 return ERROR_SUCCESS;
971 UINT msi_add_suminfo( MSIDATABASE *db, LPWSTR **records, int num_records, int num_columns )
973 UINT r;
974 int i, j;
975 MSISUMMARYINFO *si;
977 r = msi_get_suminfo( db->storage, num_records * (num_columns / 2), &si );
978 if (r != ERROR_SUCCESS)
980 if (!(si = create_suminfo( db->storage, num_records * (num_columns / 2) )))
981 return ERROR_OUTOFMEMORY;
982 r = ERROR_SUCCESS;
985 for (i = 0; i < num_records; i++)
987 for (j = 0; j < num_columns; j += 2)
989 UINT pid;
990 INT int_value = 0;
991 FILETIME ft_value;
992 awcstring str_value;
994 r = parse_prop( records[i][j], records[i][j + 1], &pid, &int_value, &ft_value, &str_value );
995 if (r != ERROR_SUCCESS)
996 goto end;
998 r = set_prop( si, pid, get_type(pid), int_value, &ft_value, &str_value );
999 if (r != ERROR_SUCCESS)
1000 goto end;
1004 end:
1005 if (r == ERROR_SUCCESS)
1006 r = suminfo_persist( si );
1008 msiobj_release( &si->hdr );
1009 return r;
1012 UINT WINAPI MsiSummaryInfoPersist( MSIHANDLE handle )
1014 MSISUMMARYINFO *si;
1015 UINT ret;
1017 TRACE("%d\n", handle );
1019 si = msihandle2msiinfo( handle, MSIHANDLETYPE_SUMMARYINFO );
1020 if( !si )
1021 return ERROR_INVALID_HANDLE;
1023 ret = suminfo_persist( si );
1025 msiobj_release( &si->hdr );
1026 return ret;
1029 UINT WINAPI MsiCreateTransformSummaryInfoA( MSIHANDLE db, MSIHANDLE db_ref, LPCSTR transform, int error, int validation )
1031 UINT r;
1032 WCHAR *transformW = NULL;
1034 TRACE("%u, %u, %s, %d, %d\n", db, db_ref, debugstr_a(transform), error, validation);
1036 if (transform && !(transformW = strdupAtoW( transform )))
1037 return ERROR_OUTOFMEMORY;
1039 r = MsiCreateTransformSummaryInfoW( db, db_ref, transformW, error, validation );
1040 msi_free( transformW );
1041 return r;
1044 UINT WINAPI MsiCreateTransformSummaryInfoW( MSIHANDLE db, MSIHANDLE db_ref, LPCWSTR transform, int error, int validation )
1046 FIXME("%u, %u, %s, %d, %d\n", db, db_ref, debugstr_w(transform), error, validation);
1047 return ERROR_FUNCTION_FAILED;