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
24 #define NONAMELESSUNION
32 #include "wine/debug.h"
33 #include "wine/exception.h"
38 #include "propvarutil.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
63 } PROPERTYSECTIONHEADER
;
85 static HRESULT (WINAPI
*pPropVariantChangeType
)
86 (PROPVARIANT
*ppropvarDest
, REFPROPVARIANT propvarSrc
,
87 PROPVAR_CHANGE_FLAGS flags
, VARTYPE vt
);
89 #define SECT_HDR_SIZE (sizeof(PROPERTYSECTIONHEADER))
91 static void free_prop( PROPVARIANT
*prop
)
93 if (prop
->vt
== VT_LPSTR
)
94 msi_free( prop
->pszVal
);
98 static void MSI_CloseSummaryInfo( MSIOBJECTHDR
*arg
)
100 MSISUMMARYINFO
*si
= (MSISUMMARYINFO
*) arg
;
103 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
104 free_prop( &si
->property
[i
] );
105 IStorage_Release( si
->storage
);
108 static UINT
get_type( UINT uiProperty
)
126 case PID_LASTPRINTED
:
128 case PID_LASTSAVE_DTM
:
140 static UINT
get_property_count( const PROPVARIANT
*property
)
146 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
147 if( property
[i
].vt
!= VT_EMPTY
)
152 static UINT
propvar_changetype(PROPVARIANT
*changed
, PROPVARIANT
*property
, VARTYPE vt
)
155 HMODULE propsys
= LoadLibraryA("propsys.dll");
156 pPropVariantChangeType
= (void *)GetProcAddress(propsys
, "PropVariantChangeType");
158 if (!pPropVariantChangeType
)
160 ERR("PropVariantChangeType function missing!\n");
161 return ERROR_FUNCTION_FAILED
;
164 hr
= pPropVariantChangeType(changed
, property
, 0, vt
);
165 return (hr
== S_OK
) ? ERROR_SUCCESS
: ERROR_FUNCTION_FAILED
;
168 /* FIXME: doesn't deal with endian conversion */
169 static void read_properties_from_data( PROPVARIANT
*prop
, LPBYTE data
, DWORD sz
)
173 PROPERTY_DATA
*propdata
;
174 PROPVARIANT property
, *ptr
;
176 PROPERTYIDOFFSET
*idofs
;
177 PROPERTYSECTIONHEADER
*section_hdr
;
179 section_hdr
= (PROPERTYSECTIONHEADER
*) &data
[0];
180 idofs
= (PROPERTYIDOFFSET
*) &data
[SECT_HDR_SIZE
];
182 /* now set all the properties */
183 for( i
= 0; i
< section_hdr
->cProperties
; i
++ )
185 if( idofs
[i
].propid
>= MSI_MAX_PROPS
)
187 ERR( "unknown property ID %lu\n", idofs
[i
].propid
);
191 type
= get_type( idofs
[i
].propid
);
192 if( type
== VT_EMPTY
)
194 ERR( "propid %lu has unknown type\n", idofs
[i
].propid
);
198 propdata
= (PROPERTY_DATA
*) &data
[ idofs
[i
].dwOffset
];
200 /* check we don't run off the end of the data */
201 size
= sz
- idofs
[i
].dwOffset
- sizeof(DWORD
);
202 if( sizeof(DWORD
) > size
||
203 ( propdata
->type
== VT_FILETIME
&& sizeof(FILETIME
) > size
) ||
204 ( propdata
->type
== VT_LPSTR
&& (propdata
->u
.str
.len
+ sizeof(DWORD
)) > size
) )
206 ERR("not enough data\n");
210 property
.vt
= propdata
->type
;
211 if( propdata
->type
== VT_LPSTR
)
213 LPSTR str
= msi_alloc( propdata
->u
.str
.len
);
214 memcpy( str
, propdata
->u
.str
.str
, propdata
->u
.str
.len
);
215 str
[ propdata
->u
.str
.len
- 1 ] = 0;
216 property
.pszVal
= str
;
218 else if( propdata
->type
== VT_FILETIME
)
219 property
.filetime
= propdata
->u
.ft
;
220 else if( propdata
->type
== VT_I2
)
221 property
.iVal
= propdata
->u
.i2
;
222 else if( propdata
->type
== VT_I4
)
223 property
.lVal
= propdata
->u
.i4
;
225 /* check the type is the same as we expect */
226 if( type
!= propdata
->type
)
228 propvar_changetype(&changed
, &property
, type
);
234 prop
[ idofs
[i
].propid
] = *ptr
;
238 static UINT
load_summary_info( MSISUMMARYINFO
*si
, IStream
*stm
)
240 PROPERTYSETHEADER set_hdr
;
241 FORMATIDOFFSET format_hdr
;
242 PROPERTYSECTIONHEADER section_hdr
;
248 TRACE("%p %p\n", si
, stm
);
250 /* read the header */
252 r
= IStream_Read( stm
, &set_hdr
, sz
, &count
);
253 if( FAILED(r
) || count
!= sz
)
254 return ERROR_FUNCTION_FAILED
;
256 if( set_hdr
.wByteOrder
!= 0xfffe )
258 ERR("property set not big-endian %04X\n", set_hdr
.wByteOrder
);
259 return ERROR_FUNCTION_FAILED
;
262 sz
= sizeof format_hdr
;
263 r
= IStream_Read( stm
, &format_hdr
, sz
, &count
);
264 if( FAILED(r
) || count
!= sz
)
265 return ERROR_FUNCTION_FAILED
;
267 /* check the format id is correct */
268 if( !IsEqualGUID( &FMTID_SummaryInformation
, &format_hdr
.fmtid
) )
269 return ERROR_FUNCTION_FAILED
;
271 /* seek to the location of the section */
272 ofs
.QuadPart
= format_hdr
.dwOffset
;
273 r
= IStream_Seek( stm
, ofs
, STREAM_SEEK_SET
, NULL
);
275 return ERROR_FUNCTION_FAILED
;
277 /* read the section itself */
279 r
= IStream_Read( stm
, §ion_hdr
, sz
, &count
);
280 if( FAILED(r
) || count
!= sz
)
281 return ERROR_FUNCTION_FAILED
;
283 if( section_hdr
.cProperties
> MSI_MAX_PROPS
)
285 ERR( "too many properties %lu\n", section_hdr
.cProperties
);
286 return ERROR_FUNCTION_FAILED
;
289 data
= msi_alloc( section_hdr
.cbSection
);
291 return ERROR_FUNCTION_FAILED
;
293 memcpy( data
, §ion_hdr
, SECT_HDR_SIZE
);
295 /* read all the data in one go */
296 sz
= section_hdr
.cbSection
- SECT_HDR_SIZE
;
297 r
= IStream_Read( stm
, &data
[ SECT_HDR_SIZE
], sz
, &count
);
298 if( SUCCEEDED(r
) && count
== sz
)
299 read_properties_from_data( si
->property
, data
, sz
+ SECT_HDR_SIZE
);
301 ERR( "failed to read properties %lu %lu\n", count
, sz
);
304 return ERROR_SUCCESS
;
307 static DWORD
write_dword( LPBYTE data
, DWORD ofs
, DWORD val
)
311 data
[ofs
++] = val
&0xff;
312 data
[ofs
++] = (val
>>8)&0xff;
313 data
[ofs
++] = (val
>>16)&0xff;
314 data
[ofs
++] = (val
>>24)&0xff;
319 static DWORD
write_filetime( LPBYTE data
, DWORD ofs
, const FILETIME
*ft
)
321 write_dword( data
, ofs
, ft
->dwLowDateTime
);
322 write_dword( data
, ofs
+ 4, ft
->dwHighDateTime
);
326 static DWORD
write_string( LPBYTE data
, DWORD ofs
, LPCSTR str
)
328 DWORD len
= lstrlenA( str
) + 1;
329 write_dword( data
, ofs
, len
);
331 memcpy( &data
[ofs
+ 4], str
, len
);
332 return (7 + len
) & ~3;
335 static UINT
write_property_to_data( const PROPVARIANT
*prop
, LPBYTE data
)
339 if( prop
->vt
== VT_EMPTY
)
343 sz
+= write_dword( data
, sz
, prop
->vt
);
347 sz
+= write_dword( data
, sz
, prop
->iVal
);
350 sz
+= write_dword( data
, sz
, prop
->lVal
);
353 sz
+= write_filetime( data
, sz
, &prop
->filetime
);
356 sz
+= write_string( data
, sz
, prop
->pszVal
);
362 static UINT
save_summary_info( const MSISUMMARYINFO
* si
, IStream
*stm
)
364 UINT ret
= ERROR_FUNCTION_FAILED
;
365 PROPERTYSETHEADER set_hdr
;
366 FORMATIDOFFSET format_hdr
;
367 PROPERTYSECTIONHEADER section_hdr
;
368 PROPERTYIDOFFSET idofs
[MSI_MAX_PROPS
];
374 /* write the header */
376 memset( &set_hdr
, 0, sz
);
377 set_hdr
.wByteOrder
= 0xfffe;
379 set_hdr
.dwOSVer
= 0x00020005; /* build 5, platform id 2 */
380 /* set_hdr.clsID is {00000000-0000-0000-0000-000000000000} */
381 set_hdr
.reserved
= 1;
382 r
= IStream_Write( stm
, &set_hdr
, sz
, &count
);
383 if( FAILED(r
) || count
!= sz
)
386 /* write the format header */
387 sz
= sizeof format_hdr
;
388 format_hdr
.fmtid
= FMTID_SummaryInformation
;
389 format_hdr
.dwOffset
= sizeof format_hdr
+ sizeof set_hdr
;
390 r
= IStream_Write( stm
, &format_hdr
, sz
, &count
);
391 if( FAILED(r
) || count
!= sz
)
394 /* add up how much space the data will take and calculate the offsets */
395 section_hdr
.cbSection
= sizeof section_hdr
;
396 section_hdr
.cbSection
+= (get_property_count( si
->property
) * sizeof idofs
[0]);
397 section_hdr
.cProperties
= 0;
398 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
400 sz
= write_property_to_data( &si
->property
[i
], NULL
);
403 idofs
[ section_hdr
.cProperties
].propid
= i
;
404 idofs
[ section_hdr
.cProperties
].dwOffset
= section_hdr
.cbSection
;
405 section_hdr
.cProperties
++;
406 section_hdr
.cbSection
+= sz
;
409 data
= msi_alloc_zero( section_hdr
.cbSection
);
412 memcpy( &data
[sz
], §ion_hdr
, sizeof section_hdr
);
413 sz
+= sizeof section_hdr
;
415 memcpy( &data
[sz
], idofs
, section_hdr
.cProperties
* sizeof idofs
[0] );
416 sz
+= section_hdr
.cProperties
* sizeof idofs
[0];
418 /* write out the data */
419 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
420 sz
+= write_property_to_data( &si
->property
[i
], &data
[sz
] );
422 r
= IStream_Write( stm
, data
, sz
, &count
);
424 if( FAILED(r
) || count
!= sz
)
427 return ERROR_SUCCESS
;
430 static MSISUMMARYINFO
*create_suminfo( IStorage
*stg
, UINT update_count
)
434 if (!(si
= alloc_msiobject( MSIHANDLETYPE_SUMMARYINFO
, sizeof(MSISUMMARYINFO
), MSI_CloseSummaryInfo
)))
437 si
->update_count
= update_count
;
438 IStorage_AddRef( stg
);
444 UINT
msi_get_suminfo( IStorage
*stg
, UINT uiUpdateCount
, MSISUMMARYINFO
**ret
)
451 TRACE("%p, %u\n", stg
, uiUpdateCount
);
453 if (!(si
= create_suminfo( stg
, uiUpdateCount
))) return ERROR_OUTOFMEMORY
;
455 hr
= IStorage_OpenStream( si
->storage
, L
"\5SummaryInformation", 0, STGM_READ
|STGM_SHARE_EXCLUSIVE
, 0, &stm
);
458 msiobj_release( &si
->hdr
);
459 return ERROR_FUNCTION_FAILED
;
462 r
= load_summary_info( si
, stm
);
463 IStream_Release( stm
);
464 if (r
!= ERROR_SUCCESS
)
466 msiobj_release( &si
->hdr
);
471 return ERROR_SUCCESS
;
474 UINT
msi_get_db_suminfo( MSIDATABASE
*db
, UINT uiUpdateCount
, MSISUMMARYINFO
**ret
)
480 if (!(si
= create_suminfo( db
->storage
, uiUpdateCount
))) return ERROR_OUTOFMEMORY
;
482 r
= msi_get_stream( db
, L
"\5SummaryInformation", &stm
);
483 if (r
!= ERROR_SUCCESS
)
485 msiobj_release( &si
->hdr
);
489 r
= load_summary_info( si
, stm
);
490 IStream_Release( stm
);
491 if (r
!= ERROR_SUCCESS
)
493 msiobj_release( &si
->hdr
);
498 return ERROR_SUCCESS
;
501 UINT WINAPI
MsiGetSummaryInformationW( MSIHANDLE hDatabase
, const WCHAR
*szDatabase
, UINT uiUpdateCount
,
508 TRACE( "%lu, %s, %u, %p\n", hDatabase
, debugstr_w(szDatabase
), uiUpdateCount
, pHandle
);
511 return ERROR_INVALID_PARAMETER
;
513 if( szDatabase
&& szDatabase
[0] )
515 LPCWSTR persist
= uiUpdateCount
? MSIDBOPEN_TRANSACT
: MSIDBOPEN_READONLY
;
517 ret
= MSI_OpenDatabaseW( szDatabase
, persist
, &db
);
518 if( ret
!= ERROR_SUCCESS
)
523 db
= msihandle2msiinfo( hDatabase
, MSIHANDLETYPE_DATABASE
);
526 MSIHANDLE remote
, remote_suminfo
;
528 if (!(remote
= msi_get_remote(hDatabase
)))
529 return ERROR_INVALID_HANDLE
;
533 ret
= remote_DatabaseGetSummaryInformation(remote
, uiUpdateCount
, &remote_suminfo
);
537 ret
= GetExceptionCode();
542 *pHandle
= alloc_msi_remote_handle(remote_suminfo
);
548 ret
= msi_get_suminfo( db
->storage
, uiUpdateCount
, &si
);
549 if (ret
!= ERROR_SUCCESS
)
550 ret
= msi_get_db_suminfo( db
, uiUpdateCount
, &si
);
551 if (ret
!= ERROR_SUCCESS
)
553 if ((si
= create_suminfo( db
->storage
, uiUpdateCount
)))
557 if (ret
== ERROR_SUCCESS
)
559 *pHandle
= alloc_msihandle( &si
->hdr
);
563 ret
= ERROR_NOT_ENOUGH_MEMORY
;
564 msiobj_release( &si
->hdr
);
567 msiobj_release( &db
->hdr
);
571 UINT WINAPI
MsiGetSummaryInformationA( MSIHANDLE hDatabase
, const char *szDatabase
, UINT uiUpdateCount
,
574 WCHAR
*szwDatabase
= NULL
;
577 TRACE( "%lu, %s, %u, %p\n", hDatabase
, debugstr_a(szDatabase
), uiUpdateCount
, pHandle
);
581 szwDatabase
= strdupAtoW( szDatabase
);
583 return ERROR_FUNCTION_FAILED
;
586 ret
= MsiGetSummaryInformationW(hDatabase
, szwDatabase
, uiUpdateCount
, pHandle
);
588 msi_free( szwDatabase
);
593 UINT WINAPI
MsiSummaryInfoGetPropertyCount( MSIHANDLE hSummaryInfo
, UINT
*pCount
)
597 TRACE( "%lu, %p\n", hSummaryInfo
, pCount
);
599 si
= msihandle2msiinfo( hSummaryInfo
, MSIHANDLETYPE_SUMMARYINFO
);
605 if (!(remote
= msi_get_remote( hSummaryInfo
)))
606 return ERROR_INVALID_HANDLE
;
610 ret
= remote_SummaryInfoGetPropertyCount( remote
, pCount
);
614 ret
= GetExceptionCode();
622 *pCount
= get_property_count( si
->property
);
623 msiobj_release( &si
->hdr
);
625 return ERROR_SUCCESS
;
628 static UINT
get_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT
*puiDataType
, INT
*piValue
,
629 FILETIME
*pftValue
, awstring
*str
, DWORD
*pcchValueBuf
)
632 UINT ret
= ERROR_SUCCESS
;
634 prop
= &si
->property
[uiProperty
];
637 *puiDataType
= prop
->vt
;
643 *piValue
= prop
->iVal
;
647 *piValue
= prop
->lVal
;
656 len
= MultiByteToWideChar( CP_ACP
, 0, prop
->pszVal
, -1, NULL
, 0 ) - 1;
657 MultiByteToWideChar( CP_ACP
, 0, prop
->pszVal
, -1, str
->str
.w
, *pcchValueBuf
);
661 len
= lstrlenA( prop
->pszVal
);
663 lstrcpynA(str
->str
.a
, prop
->pszVal
, *pcchValueBuf
);
665 if (len
>= *pcchValueBuf
)
666 ret
= ERROR_MORE_DATA
;
672 *pftValue
= prop
->filetime
;
677 FIXME("Unknown property variant type\n");
683 LPWSTR
msi_suminfo_dup_string( MSISUMMARYINFO
*si
, UINT uiProperty
)
687 if ( uiProperty
>= MSI_MAX_PROPS
)
689 prop
= &si
->property
[uiProperty
];
690 if( prop
->vt
!= VT_LPSTR
)
692 return strdupAtoW( prop
->pszVal
);
695 INT
msi_suminfo_get_int32( MSISUMMARYINFO
*si
, UINT uiProperty
)
699 if ( uiProperty
>= MSI_MAX_PROPS
)
701 prop
= &si
->property
[uiProperty
];
702 if( prop
->vt
!= VT_I4
)
707 LPWSTR
msi_get_suminfo_product( IStorage
*stg
)
713 r
= msi_get_suminfo( stg
, 0, &si
);
714 if (r
!= ERROR_SUCCESS
)
716 ERR("no summary information!\n");
719 prod
= msi_suminfo_dup_string( si
, PID_REVNUMBER
);
720 msiobj_release( &si
->hdr
);
724 UINT WINAPI
MsiSummaryInfoGetPropertyA( MSIHANDLE handle
, UINT uiProperty
, UINT
*puiDataType
, INT
*piValue
,
725 FILETIME
*pftValue
, char *szValueBuf
, DWORD
*pcchValueBuf
)
731 TRACE( "%lu, %u, %p, %p, %p, %p, %p\n", handle
, uiProperty
, puiDataType
, piValue
, pftValue
, szValueBuf
,
734 if (uiProperty
>= MSI_MAX_PROPS
)
736 if (puiDataType
) *puiDataType
= VT_EMPTY
;
737 return ERROR_UNKNOWN_PROPERTY
;
740 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
745 if (!(remote
= msi_get_remote( handle
)))
746 return ERROR_INVALID_HANDLE
;
750 r
= remote_SummaryInfoGetProperty( remote
, uiProperty
, puiDataType
, piValue
, pftValue
, &buf
);
754 r
= GetExceptionCode();
760 r
= msi_strncpyWtoA( buf
, -1, szValueBuf
, pcchValueBuf
, TRUE
);
763 midl_user_free( buf
);
768 str
.str
.a
= szValueBuf
;
770 r
= get_prop( si
, uiProperty
, puiDataType
, piValue
, pftValue
, &str
, pcchValueBuf
);
771 msiobj_release( &si
->hdr
);
775 UINT WINAPI
MsiSummaryInfoGetPropertyW( MSIHANDLE handle
, UINT uiProperty
, UINT
*puiDataType
, INT
*piValue
,
776 FILETIME
*pftValue
, WCHAR
*szValueBuf
, DWORD
*pcchValueBuf
)
782 TRACE( "%lu, %u, %p, %p, %p, %p, %p\n", handle
, uiProperty
, puiDataType
, piValue
, pftValue
, szValueBuf
,
785 if (uiProperty
>= MSI_MAX_PROPS
)
787 if (puiDataType
) *puiDataType
= VT_EMPTY
;
788 return ERROR_UNKNOWN_PROPERTY
;
791 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
796 if (!(remote
= msi_get_remote( handle
)))
797 return ERROR_INVALID_HANDLE
;
801 r
= remote_SummaryInfoGetProperty( remote
, uiProperty
, puiDataType
, piValue
, pftValue
, &buf
);
805 r
= GetExceptionCode();
810 r
= msi_strncpyW( buf
, -1, szValueBuf
, pcchValueBuf
);
812 midl_user_free( buf
);
817 str
.str
.w
= szValueBuf
;
819 r
= get_prop( si
, uiProperty
, puiDataType
, piValue
, pftValue
, &str
, pcchValueBuf
);
820 msiobj_release( &si
->hdr
);
824 static UINT
set_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT type
,
825 INT iValue
, FILETIME
*pftValue
, awcstring
*str
)
830 TRACE("%p, %u, %u, %d, %p, %p\n", si
, uiProperty
, type
, iValue
, pftValue
, str
);
832 prop
= &si
->property
[uiProperty
];
834 if( prop
->vt
== VT_EMPTY
)
836 if( !si
->update_count
)
837 return ERROR_FUNCTION_FAILED
;
841 else if( prop
->vt
!= type
)
842 return ERROR_SUCCESS
;
855 prop
->filetime
= *pftValue
;
860 len
= WideCharToMultiByte( CP_ACP
, 0, str
->str
.w
, -1,
861 NULL
, 0, NULL
, NULL
);
862 prop
->pszVal
= msi_alloc( len
);
863 WideCharToMultiByte( CP_ACP
, 0, str
->str
.w
, -1,
864 prop
->pszVal
, len
, NULL
, NULL
);
868 len
= lstrlenA( str
->str
.a
) + 1;
869 prop
->pszVal
= msi_alloc( len
);
870 lstrcpyA( prop
->pszVal
, str
->str
.a
);
875 return ERROR_SUCCESS
;
878 static UINT
msi_set_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT uiDataType
,
879 INT iValue
, FILETIME
*pftValue
, awcstring
*str
)
881 UINT type
= get_type( uiProperty
);
882 if( type
== VT_EMPTY
|| type
!= uiDataType
)
883 return ERROR_DATATYPE_MISMATCH
;
885 if( uiDataType
== VT_LPSTR
&& !str
->str
.a
)
886 return ERROR_INVALID_PARAMETER
;
888 if( uiDataType
== VT_FILETIME
&& !pftValue
)
889 return ERROR_INVALID_PARAMETER
;
891 return set_prop( si
, uiProperty
, type
, iValue
, pftValue
, str
);
894 UINT WINAPI
MsiSummaryInfoSetPropertyW( MSIHANDLE handle
, UINT uiProperty
, UINT uiDataType
, INT iValue
,
895 FILETIME
*pftValue
, const WCHAR
*szValue
)
901 TRACE( "%lu, %u, %u, %d, %p, %s\n", handle
, uiProperty
, uiDataType
, iValue
, pftValue
, debugstr_w(szValue
) );
903 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
907 if ((remote
= msi_get_remote( handle
)))
909 WARN("MsiSummaryInfoSetProperty not allowed during a custom action!\n");
910 return ERROR_FUNCTION_FAILED
;
913 return ERROR_INVALID_HANDLE
;
919 ret
= msi_set_prop( si
, uiProperty
, uiDataType
, iValue
, pftValue
, &str
);
920 msiobj_release( &si
->hdr
);
924 UINT WINAPI
MsiSummaryInfoSetPropertyA( MSIHANDLE handle
, UINT uiProperty
, UINT uiDataType
, INT iValue
,
925 FILETIME
*pftValue
, const char *szValue
)
931 TRACE( "%lu, %u, %u, %d, %p, %s\n", handle
, uiProperty
, uiDataType
, iValue
, pftValue
, debugstr_a(szValue
) );
933 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
937 if ((remote
= msi_get_remote( handle
)))
939 WARN("MsiSummaryInfoSetProperty not allowed during a custom action!\n");
940 return ERROR_FUNCTION_FAILED
;
943 return ERROR_INVALID_HANDLE
;
949 ret
= msi_set_prop( si
, uiProperty
, uiDataType
, iValue
, pftValue
, &str
);
950 msiobj_release( &si
->hdr
);
954 static UINT
suminfo_persist( MSISUMMARYINFO
*si
)
956 UINT ret
= ERROR_FUNCTION_FAILED
;
961 grfMode
= STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
;
962 r
= IStorage_CreateStream( si
->storage
, L
"\5SummaryInformation", grfMode
, 0, 0, &stm
);
965 ret
= save_summary_info( si
, stm
);
966 IStream_Release( stm
);
971 static void parse_filetime( LPCWSTR str
, FILETIME
*ft
)
974 const WCHAR
*p
= str
;
977 memset( <
, 0, sizeof(lt
) );
979 /* YYYY/MM/DD hh:mm:ss */
981 while (iswspace( *p
)) p
++;
983 lt
.wYear
= wcstol( p
, &end
, 10 );
984 if (*end
!= '/') return;
987 lt
.wMonth
= wcstol( p
, &end
, 10 );
988 if (*end
!= '/') return;
991 lt
.wDay
= wcstol( p
, &end
, 10 );
992 if (*end
!= ' ') return;
995 while (iswspace( *p
)) p
++;
997 lt
.wHour
= wcstol( p
, &end
, 10 );
998 if (*end
!= ':') return;
1001 lt
.wMinute
= wcstol( p
, &end
, 10 );
1002 if (*end
!= ':') return;
1005 lt
.wSecond
= wcstol( p
, &end
, 10 );
1007 TzSpecificLocalTimeToSystemTime( NULL
, <
, &utc
);
1008 SystemTimeToFileTime( &utc
, ft
);
1011 static UINT
parse_prop( LPCWSTR prop
, LPCWSTR value
, UINT
*pid
, INT
*int_value
,
1012 FILETIME
*ft_value
, awcstring
*str_value
)
1014 *pid
= wcstol( prop
, NULL
, 10 );
1022 *int_value
= wcstol( value
, NULL
, 10 );
1025 case PID_LASTPRINTED
:
1026 case PID_CREATE_DTM
:
1027 case PID_LASTSAVE_DTM
:
1028 parse_filetime( value
, ft_value
);
1036 case PID_LASTAUTHOR
:
1040 str_value
->str
.w
= value
;
1041 str_value
->unicode
= TRUE
;
1045 WARN("unhandled prop id %u\n", *pid
);
1046 return ERROR_FUNCTION_FAILED
;
1049 return ERROR_SUCCESS
;
1052 UINT
msi_add_suminfo( MSIDATABASE
*db
, LPWSTR
**records
, int num_records
, int num_columns
)
1058 r
= msi_get_suminfo( db
->storage
, num_records
* (num_columns
/ 2), &si
);
1059 if (r
!= ERROR_SUCCESS
)
1061 if (!(si
= create_suminfo( db
->storage
, num_records
* (num_columns
/ 2) )))
1062 return ERROR_OUTOFMEMORY
;
1066 for (i
= 0; i
< num_records
; i
++)
1068 for (j
= 0; j
< num_columns
; j
+= 2)
1073 awcstring str_value
;
1075 r
= parse_prop( records
[i
][j
], records
[i
][j
+ 1], &pid
, &int_value
, &ft_value
, &str_value
);
1076 if (r
!= ERROR_SUCCESS
)
1079 r
= set_prop( si
, pid
, get_type(pid
), int_value
, &ft_value
, &str_value
);
1080 if (r
!= ERROR_SUCCESS
)
1086 if (r
== ERROR_SUCCESS
)
1087 r
= suminfo_persist( si
);
1089 msiobj_release( &si
->hdr
);
1093 static UINT
save_prop( MSISUMMARYINFO
*si
, HANDLE handle
, UINT row
)
1095 static const char fmt_systemtime
[] = "%04u/%02u/%02u %02u:%02u:%02u";
1096 char data
[36]; /* largest string: YYYY/MM/DD hh:mm:ss */
1097 static const char fmt_begin
[] = "%u\t";
1098 static const char data_end
[] = "\r\n";
1099 static const char fmt_int
[] = "%u";
1101 SYSTEMTIME system_time
;
1107 str
.unicode
= FALSE
;
1110 r
= get_prop( si
, row
, &data_type
, &int_value
, &file_time
, &str
, &len
);
1111 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
1113 if (data_type
== VT_EMPTY
)
1114 return ERROR_SUCCESS
; /* property not set */
1115 sz
= sprintf( data
, fmt_begin
, row
);
1116 if (!WriteFile( handle
, data
, sz
, &sz
, NULL
))
1117 return ERROR_WRITE_FAULT
;
1123 sz
= sprintf( data
, fmt_int
, int_value
);
1124 if (!WriteFile( handle
, data
, sz
, &sz
, NULL
))
1125 return ERROR_WRITE_FAULT
;
1129 if (!(str
.str
.a
= msi_alloc( len
)))
1130 return ERROR_OUTOFMEMORY
;
1131 r
= get_prop( si
, row
, NULL
, NULL
, NULL
, &str
, &len
);
1132 if (r
!= ERROR_SUCCESS
)
1134 msi_free( str
.str
.a
);
1138 if (!WriteFile( handle
, str
.str
.a
, sz
, &sz
, NULL
))
1140 msi_free( str
.str
.a
);
1141 return ERROR_WRITE_FAULT
;
1143 msi_free( str
.str
.a
);
1146 if (!FileTimeToSystemTime( &file_time
, &system_time
))
1147 return ERROR_FUNCTION_FAILED
;
1148 sz
= sprintf( data
, fmt_systemtime
, system_time
.wYear
, system_time
.wMonth
,
1149 system_time
.wDay
, system_time
.wHour
, system_time
.wMinute
,
1150 system_time
.wSecond
);
1151 if (!WriteFile( handle
, data
, sz
, &sz
, NULL
))
1152 return ERROR_WRITE_FAULT
;
1155 /* cannot reach here, property not set */
1158 FIXME( "Unknown property variant type\n" );
1159 return ERROR_FUNCTION_FAILED
;
1162 sz
= ARRAY_SIZE(data_end
) - 1;
1163 if (!WriteFile( handle
, data_end
, sz
, &sz
, NULL
))
1164 return ERROR_WRITE_FAULT
;
1166 return ERROR_SUCCESS
;
1169 UINT
msi_export_suminfo( MSIDATABASE
*db
, HANDLE handle
)
1171 UINT i
, r
, num_rows
;
1174 r
= msi_get_suminfo( db
->storage
, 0, &si
);
1175 if (r
!= ERROR_SUCCESS
)
1176 r
= msi_get_db_suminfo( db
, 0, &si
);
1177 if (r
!= ERROR_SUCCESS
)
1180 num_rows
= get_property_count( si
->property
);
1183 msiobj_release( &si
->hdr
);
1184 return ERROR_FUNCTION_FAILED
;
1187 for (i
= 0; i
< num_rows
; i
++)
1189 r
= save_prop( si
, handle
, i
);
1190 if (r
!= ERROR_SUCCESS
)
1192 msiobj_release( &si
->hdr
);
1197 msiobj_release( &si
->hdr
);
1198 return ERROR_SUCCESS
;
1201 UINT WINAPI
MsiSummaryInfoPersist( MSIHANDLE handle
)
1206 TRACE( "%lu\n", handle
);
1208 si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
);
1210 return ERROR_INVALID_HANDLE
;
1212 ret
= suminfo_persist( si
);
1214 msiobj_release( &si
->hdr
);
1218 UINT WINAPI
MsiCreateTransformSummaryInfoA( MSIHANDLE db
, MSIHANDLE db_ref
, const char *transform
, int error
,
1222 WCHAR
*transformW
= NULL
;
1224 TRACE( "%lu, %lu, %s, %d, %d\n", db
, db_ref
, debugstr_a(transform
), error
, validation
);
1226 if (transform
&& !(transformW
= strdupAtoW( transform
)))
1227 return ERROR_OUTOFMEMORY
;
1229 r
= MsiCreateTransformSummaryInfoW( db
, db_ref
, transformW
, error
, validation
);
1230 msi_free( transformW
);
1234 UINT WINAPI
MsiCreateTransformSummaryInfoW( MSIHANDLE db
, MSIHANDLE db_ref
, const WCHAR
*transform
, int error
,
1237 FIXME( "%lu, %lu, %s, %d, %d\n", db
, db_ref
, debugstr_w(transform
), error
, validation
);
1238 return ERROR_FUNCTION_FAILED
;
1241 UINT
msi_load_suminfo_properties( MSIPACKAGE
*package
)
1244 WCHAR
*package_code
;
1250 r
= msi_get_suminfo( package
->db
->storage
, 0, &si
);
1251 if (r
!= ERROR_SUCCESS
)
1253 r
= msi_get_db_suminfo( package
->db
, 0, &si
);
1254 if (r
!= ERROR_SUCCESS
)
1256 ERR("Unable to open summary information stream %u\n", r
);
1264 r
= get_prop( si
, PID_REVNUMBER
, NULL
, NULL
, NULL
, &str
, &len
);
1265 if (r
!= ERROR_MORE_DATA
)
1267 WARN("Unable to query revision number %u\n", r
);
1268 msiobj_release( &si
->hdr
);
1269 return ERROR_FUNCTION_FAILED
;
1273 if (!(package_code
= msi_alloc( len
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
1274 str
.str
.w
= package_code
;
1276 r
= get_prop( si
, PID_REVNUMBER
, NULL
, NULL
, NULL
, &str
, &len
);
1277 if (r
!= ERROR_SUCCESS
)
1279 msi_free( package_code
);
1280 msiobj_release( &si
->hdr
);
1284 r
= msi_set_property( package
->db
, L
"PackageCode", package_code
, len
);
1285 msi_free( package_code
);
1288 get_prop( si
, PID_WORDCOUNT
, NULL
, &count
, NULL
, NULL
, NULL
);
1289 package
->WordCount
= count
;
1291 msiobj_release( &si
->hdr
);
1295 UINT __cdecl
s_remote_SummaryInfoGetPropertyCount( MSIHANDLE suminfo
, UINT
*count
)
1297 return MsiSummaryInfoGetPropertyCount( suminfo
, count
);
1300 UINT __cdecl
s_remote_SummaryInfoGetProperty( MSIHANDLE suminfo
, UINT property
, UINT
*type
,
1301 INT
*value
, FILETIME
*ft
, LPWSTR
*buf
)
1307 r
= MsiSummaryInfoGetPropertyW( suminfo
, property
, type
, value
, ft
, empty
, &size
);
1308 if (r
== ERROR_MORE_DATA
)
1311 *buf
= midl_user_allocate( size
* sizeof(WCHAR
) );
1312 if (!*buf
) return ERROR_OUTOFMEMORY
;
1313 r
= MsiSummaryInfoGetPropertyW( suminfo
, property
, type
, value
, ft
, *buf
, &size
);