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
->u
.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 %d\n", idofs
[i
].propid
);
191 type
= get_type( idofs
[i
].propid
);
192 if( type
== VT_EMPTY
)
194 ERR("propid %d 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
.u
.pszVal
= str
;
218 else if( propdata
->type
== VT_FILETIME
)
219 property
.u
.filetime
= propdata
->u
.ft
;
220 else if( propdata
->type
== VT_I2
)
221 property
.u
.iVal
= propdata
->u
.i2
;
222 else if( propdata
->type
== VT_I4
)
223 property
.u
.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 %d\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 %d %d\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
->u
.iVal
);
350 sz
+= write_dword( data
, sz
, prop
->u
.lVal
);
353 sz
+= write_filetime( data
, sz
, &prop
->u
.filetime
);
356 sz
+= write_string( data
, sz
, prop
->u
.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
,
502 LPCWSTR szDatabase
, UINT uiUpdateCount
, MSIHANDLE
*pHandle
)
508 TRACE("%d %s %d %p\n", hDatabase
, debugstr_w(szDatabase
),
509 uiUpdateCount
, pHandle
);
512 return ERROR_INVALID_PARAMETER
;
514 if( szDatabase
&& szDatabase
[0] )
516 LPCWSTR persist
= uiUpdateCount
? MSIDBOPEN_TRANSACT
: MSIDBOPEN_READONLY
;
518 ret
= MSI_OpenDatabaseW( szDatabase
, persist
, &db
);
519 if( ret
!= ERROR_SUCCESS
)
524 db
= msihandle2msiinfo( hDatabase
, MSIHANDLETYPE_DATABASE
);
527 MSIHANDLE remote
, remote_suminfo
;
529 if (!(remote
= msi_get_remote(hDatabase
)))
530 return ERROR_INVALID_HANDLE
;
534 ret
= remote_DatabaseGetSummaryInformation(remote
, uiUpdateCount
, &remote_suminfo
);
538 ret
= GetExceptionCode();
543 *pHandle
= alloc_msi_remote_handle(remote_suminfo
);
549 ret
= msi_get_suminfo( db
->storage
, uiUpdateCount
, &si
);
550 if (ret
!= ERROR_SUCCESS
)
551 ret
= msi_get_db_suminfo( db
, uiUpdateCount
, &si
);
552 if (ret
!= ERROR_SUCCESS
)
554 if ((si
= create_suminfo( db
->storage
, uiUpdateCount
)))
558 if (ret
== ERROR_SUCCESS
)
560 *pHandle
= alloc_msihandle( &si
->hdr
);
564 ret
= ERROR_NOT_ENOUGH_MEMORY
;
565 msiobj_release( &si
->hdr
);
568 msiobj_release( &db
->hdr
);
572 UINT WINAPI
MsiGetSummaryInformationA(MSIHANDLE hDatabase
,
573 LPCSTR szDatabase
, UINT uiUpdateCount
, MSIHANDLE
*pHandle
)
575 LPWSTR szwDatabase
= NULL
;
578 TRACE("%d %s %d %p\n", hDatabase
, debugstr_a(szDatabase
),
579 uiUpdateCount
, pHandle
);
583 szwDatabase
= strdupAtoW( szDatabase
);
585 return ERROR_FUNCTION_FAILED
;
588 ret
= MsiGetSummaryInformationW(hDatabase
, szwDatabase
, uiUpdateCount
, pHandle
);
590 msi_free( szwDatabase
);
595 UINT WINAPI
MsiSummaryInfoGetPropertyCount(MSIHANDLE hSummaryInfo
, PUINT pCount
)
599 TRACE("%d %p\n", hSummaryInfo
, pCount
);
601 si
= msihandle2msiinfo( hSummaryInfo
, MSIHANDLETYPE_SUMMARYINFO
);
607 if (!(remote
= msi_get_remote( hSummaryInfo
)))
608 return ERROR_INVALID_HANDLE
;
612 ret
= remote_SummaryInfoGetPropertyCount( remote
, pCount
);
616 ret
= GetExceptionCode();
624 *pCount
= get_property_count( si
->property
);
625 msiobj_release( &si
->hdr
);
627 return ERROR_SUCCESS
;
630 static UINT
get_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT
*puiDataType
, INT
*piValue
,
631 FILETIME
*pftValue
, awstring
*str
, DWORD
*pcchValueBuf
)
634 UINT ret
= ERROR_SUCCESS
;
636 prop
= &si
->property
[uiProperty
];
639 *puiDataType
= prop
->vt
;
645 *piValue
= prop
->u
.iVal
;
649 *piValue
= prop
->u
.lVal
;
658 len
= MultiByteToWideChar( CP_ACP
, 0, prop
->u
.pszVal
, -1, NULL
, 0 ) - 1;
659 MultiByteToWideChar( CP_ACP
, 0, prop
->u
.pszVal
, -1, str
->str
.w
, *pcchValueBuf
);
663 len
= lstrlenA( prop
->u
.pszVal
);
665 lstrcpynA(str
->str
.a
, prop
->u
.pszVal
, *pcchValueBuf
);
667 if (len
>= *pcchValueBuf
)
668 ret
= ERROR_MORE_DATA
;
674 *pftValue
= prop
->u
.filetime
;
679 FIXME("Unknown property variant type\n");
685 LPWSTR
msi_suminfo_dup_string( MSISUMMARYINFO
*si
, UINT uiProperty
)
689 if ( uiProperty
>= MSI_MAX_PROPS
)
691 prop
= &si
->property
[uiProperty
];
692 if( prop
->vt
!= VT_LPSTR
)
694 return strdupAtoW( prop
->u
.pszVal
);
697 INT
msi_suminfo_get_int32( MSISUMMARYINFO
*si
, UINT uiProperty
)
701 if ( uiProperty
>= MSI_MAX_PROPS
)
703 prop
= &si
->property
[uiProperty
];
704 if( prop
->vt
!= VT_I4
)
709 LPWSTR
msi_get_suminfo_product( IStorage
*stg
)
715 r
= msi_get_suminfo( stg
, 0, &si
);
716 if (r
!= ERROR_SUCCESS
)
718 ERR("no summary information!\n");
721 prod
= msi_suminfo_dup_string( si
, PID_REVNUMBER
);
722 msiobj_release( &si
->hdr
);
726 UINT WINAPI
MsiSummaryInfoGetPropertyA(
727 MSIHANDLE handle
, UINT uiProperty
, PUINT puiDataType
, LPINT piValue
,
728 FILETIME
*pftValue
, LPSTR szValueBuf
, LPDWORD pcchValueBuf
)
734 TRACE("%u, %u, %p, %p, %p, %p, %p\n", handle
, uiProperty
, puiDataType
,
735 piValue
, pftValue
, szValueBuf
, pcchValueBuf
);
737 if (uiProperty
>= MSI_MAX_PROPS
)
739 if (puiDataType
) *puiDataType
= VT_EMPTY
;
740 return ERROR_UNKNOWN_PROPERTY
;
743 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
748 if (!(remote
= msi_get_remote( handle
)))
749 return ERROR_INVALID_HANDLE
;
753 r
= remote_SummaryInfoGetProperty( remote
, uiProperty
, puiDataType
, piValue
, pftValue
, &buf
);
757 r
= GetExceptionCode();
763 r
= msi_strncpyWtoA( buf
, -1, szValueBuf
, pcchValueBuf
, TRUE
);
766 midl_user_free( buf
);
771 str
.str
.a
= szValueBuf
;
773 r
= get_prop( si
, uiProperty
, puiDataType
, piValue
, pftValue
, &str
, pcchValueBuf
);
774 msiobj_release( &si
->hdr
);
778 UINT WINAPI
MsiSummaryInfoGetPropertyW(
779 MSIHANDLE handle
, UINT uiProperty
, PUINT puiDataType
, LPINT piValue
,
780 FILETIME
*pftValue
, LPWSTR szValueBuf
, LPDWORD pcchValueBuf
)
786 TRACE("%u, %u, %p, %p, %p, %p, %p\n", handle
, uiProperty
, puiDataType
,
787 piValue
, pftValue
, szValueBuf
, pcchValueBuf
);
789 if (uiProperty
>= MSI_MAX_PROPS
)
791 if (puiDataType
) *puiDataType
= VT_EMPTY
;
792 return ERROR_UNKNOWN_PROPERTY
;
795 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
800 if (!(remote
= msi_get_remote( handle
)))
801 return ERROR_INVALID_HANDLE
;
805 r
= remote_SummaryInfoGetProperty( remote
, uiProperty
, puiDataType
, piValue
, pftValue
, &buf
);
809 r
= GetExceptionCode();
814 r
= msi_strncpyW( buf
, -1, szValueBuf
, pcchValueBuf
);
816 midl_user_free( buf
);
821 str
.str
.w
= szValueBuf
;
823 r
= get_prop( si
, uiProperty
, puiDataType
, piValue
, pftValue
, &str
, pcchValueBuf
);
824 msiobj_release( &si
->hdr
);
828 static UINT
set_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT type
,
829 INT iValue
, FILETIME
*pftValue
, awcstring
*str
)
834 TRACE("%p, %u, %u, %d, %p, %p\n", si
, uiProperty
, type
, iValue
, pftValue
, str
);
836 prop
= &si
->property
[uiProperty
];
838 if( prop
->vt
== VT_EMPTY
)
840 if( !si
->update_count
)
841 return ERROR_FUNCTION_FAILED
;
845 else if( prop
->vt
!= type
)
846 return ERROR_SUCCESS
;
853 prop
->u
.lVal
= iValue
;
856 prop
->u
.iVal
= iValue
;
859 prop
->u
.filetime
= *pftValue
;
864 len
= WideCharToMultiByte( CP_ACP
, 0, str
->str
.w
, -1,
865 NULL
, 0, NULL
, NULL
);
866 prop
->u
.pszVal
= msi_alloc( len
);
867 WideCharToMultiByte( CP_ACP
, 0, str
->str
.w
, -1,
868 prop
->u
.pszVal
, len
, NULL
, NULL
);
872 len
= lstrlenA( str
->str
.a
) + 1;
873 prop
->u
.pszVal
= msi_alloc( len
);
874 lstrcpyA( prop
->u
.pszVal
, str
->str
.a
);
879 return ERROR_SUCCESS
;
882 static UINT
msi_set_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT uiDataType
,
883 INT iValue
, FILETIME
*pftValue
, awcstring
*str
)
885 UINT type
= get_type( uiProperty
);
886 if( type
== VT_EMPTY
|| type
!= uiDataType
)
887 return ERROR_DATATYPE_MISMATCH
;
889 if( uiDataType
== VT_LPSTR
&& !str
->str
.a
)
890 return ERROR_INVALID_PARAMETER
;
892 if( uiDataType
== VT_FILETIME
&& !pftValue
)
893 return ERROR_INVALID_PARAMETER
;
895 return set_prop( si
, uiProperty
, type
, iValue
, pftValue
, str
);
898 UINT WINAPI
MsiSummaryInfoSetPropertyW( MSIHANDLE handle
, UINT uiProperty
, UINT uiDataType
,
899 INT iValue
, FILETIME
*pftValue
, LPCWSTR szValue
)
905 TRACE("%u, %u, %u, %d, %p, %s\n", handle
, uiProperty
, uiDataType
, iValue
, pftValue
,
906 debugstr_w(szValue
) );
908 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
912 if ((remote
= msi_get_remote( handle
)))
914 WARN("MsiSummaryInfoSetProperty not allowed during a custom action!\n");
915 return ERROR_FUNCTION_FAILED
;
918 return ERROR_INVALID_HANDLE
;
924 ret
= msi_set_prop( si
, uiProperty
, uiDataType
, iValue
, pftValue
, &str
);
925 msiobj_release( &si
->hdr
);
929 UINT WINAPI
MsiSummaryInfoSetPropertyA( MSIHANDLE handle
, UINT uiProperty
, UINT uiDataType
,
930 INT iValue
, FILETIME
*pftValue
, LPCSTR szValue
)
936 TRACE("%u, %u, %u, %d, %p, %s\n", handle
, uiProperty
, uiDataType
, iValue
, pftValue
,
937 debugstr_a(szValue
) );
939 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
943 if ((remote
= msi_get_remote( handle
)))
945 WARN("MsiSummaryInfoSetProperty not allowed during a custom action!\n");
946 return ERROR_FUNCTION_FAILED
;
949 return ERROR_INVALID_HANDLE
;
955 ret
= msi_set_prop( si
, uiProperty
, uiDataType
, iValue
, pftValue
, &str
);
956 msiobj_release( &si
->hdr
);
960 static UINT
suminfo_persist( MSISUMMARYINFO
*si
)
962 UINT ret
= ERROR_FUNCTION_FAILED
;
967 grfMode
= STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
;
968 r
= IStorage_CreateStream( si
->storage
, L
"\5SummaryInformation", grfMode
, 0, 0, &stm
);
971 ret
= save_summary_info( si
, stm
);
972 IStream_Release( stm
);
977 static void parse_filetime( LPCWSTR str
, FILETIME
*ft
)
980 const WCHAR
*p
= str
;
983 memset( <
, 0, sizeof(lt
) );
985 /* YYYY/MM/DD hh:mm:ss */
987 while (iswspace( *p
)) p
++;
989 lt
.wYear
= wcstol( p
, &end
, 10 );
990 if (*end
!= '/') return;
993 lt
.wMonth
= wcstol( p
, &end
, 10 );
994 if (*end
!= '/') return;
997 lt
.wDay
= wcstol( p
, &end
, 10 );
998 if (*end
!= ' ') return;
1001 while (iswspace( *p
)) p
++;
1003 lt
.wHour
= wcstol( p
, &end
, 10 );
1004 if (*end
!= ':') return;
1007 lt
.wMinute
= wcstol( p
, &end
, 10 );
1008 if (*end
!= ':') return;
1011 lt
.wSecond
= wcstol( p
, &end
, 10 );
1013 TzSpecificLocalTimeToSystemTime( NULL
, <
, &utc
);
1014 SystemTimeToFileTime( &utc
, ft
);
1017 static UINT
parse_prop( LPCWSTR prop
, LPCWSTR value
, UINT
*pid
, INT
*int_value
,
1018 FILETIME
*ft_value
, awcstring
*str_value
)
1020 *pid
= wcstol( prop
, NULL
, 10 );
1028 *int_value
= wcstol( value
, NULL
, 10 );
1031 case PID_LASTPRINTED
:
1032 case PID_CREATE_DTM
:
1033 case PID_LASTSAVE_DTM
:
1034 parse_filetime( value
, ft_value
);
1042 case PID_LASTAUTHOR
:
1046 str_value
->str
.w
= value
;
1047 str_value
->unicode
= TRUE
;
1051 WARN("unhandled prop id %u\n", *pid
);
1052 return ERROR_FUNCTION_FAILED
;
1055 return ERROR_SUCCESS
;
1058 UINT
msi_add_suminfo( MSIDATABASE
*db
, LPWSTR
**records
, int num_records
, int num_columns
)
1064 r
= msi_get_suminfo( db
->storage
, num_records
* (num_columns
/ 2), &si
);
1065 if (r
!= ERROR_SUCCESS
)
1067 if (!(si
= create_suminfo( db
->storage
, num_records
* (num_columns
/ 2) )))
1068 return ERROR_OUTOFMEMORY
;
1072 for (i
= 0; i
< num_records
; i
++)
1074 for (j
= 0; j
< num_columns
; j
+= 2)
1079 awcstring str_value
;
1081 r
= parse_prop( records
[i
][j
], records
[i
][j
+ 1], &pid
, &int_value
, &ft_value
, &str_value
);
1082 if (r
!= ERROR_SUCCESS
)
1085 r
= set_prop( si
, pid
, get_type(pid
), int_value
, &ft_value
, &str_value
);
1086 if (r
!= ERROR_SUCCESS
)
1092 if (r
== ERROR_SUCCESS
)
1093 r
= suminfo_persist( si
);
1095 msiobj_release( &si
->hdr
);
1099 static UINT
save_prop( MSISUMMARYINFO
*si
, HANDLE handle
, UINT row
)
1101 static const char fmt_systemtime
[] = "%04u/%02u/%02u %02u:%02u:%02u";
1102 char data
[36]; /* largest string: YYYY/MM/DD hh:mm:ss */
1103 static const char fmt_begin
[] = "%u\t";
1104 static const char data_end
[] = "\r\n";
1105 static const char fmt_int
[] = "%u";
1106 UINT r
, data_type
, len
;
1107 SYSTEMTIME system_time
;
1113 str
.unicode
= FALSE
;
1116 r
= get_prop( si
, row
, &data_type
, &int_value
, &file_time
, &str
, &len
);
1117 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
1119 if (data_type
== VT_EMPTY
)
1120 return ERROR_SUCCESS
; /* property not set */
1121 sz
= sprintf( data
, fmt_begin
, row
);
1122 if (!WriteFile( handle
, data
, sz
, &sz
, NULL
))
1123 return ERROR_WRITE_FAULT
;
1129 sz
= sprintf( data
, fmt_int
, int_value
);
1130 if (!WriteFile( handle
, data
, sz
, &sz
, NULL
))
1131 return ERROR_WRITE_FAULT
;
1135 if (!(str
.str
.a
= msi_alloc( len
)))
1136 return ERROR_OUTOFMEMORY
;
1137 r
= get_prop( si
, row
, NULL
, NULL
, NULL
, &str
, &len
);
1138 if (r
!= ERROR_SUCCESS
)
1140 msi_free( str
.str
.a
);
1144 if (!WriteFile( handle
, str
.str
.a
, sz
, &sz
, NULL
))
1146 msi_free( str
.str
.a
);
1147 return ERROR_WRITE_FAULT
;
1149 msi_free( str
.str
.a
);
1152 if (!FileTimeToSystemTime( &file_time
, &system_time
))
1153 return ERROR_FUNCTION_FAILED
;
1154 sz
= sprintf( data
, fmt_systemtime
, system_time
.wYear
, system_time
.wMonth
,
1155 system_time
.wDay
, system_time
.wHour
, system_time
.wMinute
,
1156 system_time
.wSecond
);
1157 if (!WriteFile( handle
, data
, sz
, &sz
, NULL
))
1158 return ERROR_WRITE_FAULT
;
1161 /* cannot reach here, property not set */
1164 FIXME( "Unknown property variant type\n" );
1165 return ERROR_FUNCTION_FAILED
;
1168 sz
= ARRAY_SIZE(data_end
) - 1;
1169 if (!WriteFile( handle
, data_end
, sz
, &sz
, NULL
))
1170 return ERROR_WRITE_FAULT
;
1172 return ERROR_SUCCESS
;
1175 UINT
msi_export_suminfo( MSIDATABASE
*db
, HANDLE handle
)
1177 UINT i
, r
, num_rows
;
1180 r
= msi_get_suminfo( db
->storage
, 0, &si
);
1181 if (r
!= ERROR_SUCCESS
)
1182 r
= msi_get_db_suminfo( db
, 0, &si
);
1183 if (r
!= ERROR_SUCCESS
)
1186 num_rows
= get_property_count( si
->property
);
1189 msiobj_release( &si
->hdr
);
1190 return ERROR_FUNCTION_FAILED
;
1193 for (i
= 0; i
< num_rows
; i
++)
1195 r
= save_prop( si
, handle
, i
);
1196 if (r
!= ERROR_SUCCESS
)
1198 msiobj_release( &si
->hdr
);
1203 msiobj_release( &si
->hdr
);
1204 return ERROR_SUCCESS
;
1207 UINT WINAPI
MsiSummaryInfoPersist( MSIHANDLE handle
)
1212 TRACE("%d\n", handle
);
1214 si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
);
1216 return ERROR_INVALID_HANDLE
;
1218 ret
= suminfo_persist( si
);
1220 msiobj_release( &si
->hdr
);
1224 UINT WINAPI
MsiCreateTransformSummaryInfoA( MSIHANDLE db
, MSIHANDLE db_ref
, LPCSTR transform
, int error
, int validation
)
1227 WCHAR
*transformW
= NULL
;
1229 TRACE("%u, %u, %s, %d, %d\n", db
, db_ref
, debugstr_a(transform
), error
, validation
);
1231 if (transform
&& !(transformW
= strdupAtoW( transform
)))
1232 return ERROR_OUTOFMEMORY
;
1234 r
= MsiCreateTransformSummaryInfoW( db
, db_ref
, transformW
, error
, validation
);
1235 msi_free( transformW
);
1239 UINT WINAPI
MsiCreateTransformSummaryInfoW( MSIHANDLE db
, MSIHANDLE db_ref
, LPCWSTR transform
, int error
, int validation
)
1241 FIXME("%u, %u, %s, %d, %d\n", db
, db_ref
, debugstr_w(transform
), error
, validation
);
1242 return ERROR_FUNCTION_FAILED
;
1245 UINT
msi_load_suminfo_properties( MSIPACKAGE
*package
)
1248 WCHAR
*package_code
;
1253 r
= msi_get_suminfo( package
->db
->storage
, 0, &si
);
1254 if (r
!= ERROR_SUCCESS
)
1256 r
= msi_get_db_suminfo( package
->db
, 0, &si
);
1257 if (r
!= ERROR_SUCCESS
)
1259 ERR("Unable to open summary information stream %u\n", r
);
1267 r
= get_prop( si
, PID_REVNUMBER
, NULL
, NULL
, NULL
, &str
, &len
);
1268 if (r
!= ERROR_MORE_DATA
)
1270 WARN("Unable to query revision number %u\n", r
);
1271 msiobj_release( &si
->hdr
);
1272 return ERROR_FUNCTION_FAILED
;
1276 if (!(package_code
= msi_alloc( len
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
1277 str
.str
.w
= package_code
;
1279 r
= get_prop( si
, PID_REVNUMBER
, NULL
, NULL
, NULL
, &str
, &len
);
1280 if (r
!= ERROR_SUCCESS
)
1282 msi_free( package_code
);
1283 msiobj_release( &si
->hdr
);
1287 r
= msi_set_property( package
->db
, L
"PackageCode", package_code
, len
);
1288 msi_free( package_code
);
1291 get_prop( si
, PID_WORDCOUNT
, NULL
, &count
, NULL
, NULL
, NULL
);
1292 package
->WordCount
= count
;
1294 msiobj_release( &si
->hdr
);
1298 UINT __cdecl
s_remote_SummaryInfoGetPropertyCount( MSIHANDLE suminfo
, UINT
*count
)
1300 return MsiSummaryInfoGetPropertyCount( suminfo
, count
);
1303 UINT __cdecl
s_remote_SummaryInfoGetProperty( MSIHANDLE suminfo
, UINT property
, UINT
*type
,
1304 INT
*value
, FILETIME
*ft
, LPWSTR
*buf
)
1310 r
= MsiSummaryInfoGetPropertyW( suminfo
, property
, type
, value
, ft
, empty
, &size
);
1311 if (r
== ERROR_MORE_DATA
)
1314 *buf
= midl_user_allocate( size
* sizeof(WCHAR
) );
1315 if (!*buf
) return ERROR_OUTOFMEMORY
;
1316 r
= MsiSummaryInfoGetPropertyW( suminfo
, property
, type
, value
, ft
, *buf
, &size
);