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
30 #include "wine/debug.h"
31 #include "wine/exception.h"
36 #include "propvarutil.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
45 struct property_set_header
54 struct format_id_offset
60 struct property_section_header
66 struct property_id_offset
88 static HRESULT (WINAPI
*pPropVariantChangeType
)
89 (PROPVARIANT
*ppropvarDest
, REFPROPVARIANT propvarSrc
,
90 PROPVAR_CHANGE_FLAGS flags
, VARTYPE vt
);
92 #define SECT_HDR_SIZE (sizeof(struct property_section_header))
94 static void free_prop( PROPVARIANT
*prop
)
96 if (prop
->vt
== VT_LPSTR
)
101 static void MSI_CloseSummaryInfo( MSIOBJECTHDR
*arg
)
103 MSISUMMARYINFO
*si
= (MSISUMMARYINFO
*) arg
;
106 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
107 free_prop( &si
->property
[i
] );
108 IStorage_Release( si
->storage
);
111 static UINT
get_type( UINT uiProperty
)
129 case PID_LASTPRINTED
:
131 case PID_LASTSAVE_DTM
:
143 static UINT
get_property_count( const PROPVARIANT
*property
)
149 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
150 if( property
[i
].vt
!= VT_EMPTY
)
155 static UINT
propvar_changetype(PROPVARIANT
*changed
, PROPVARIANT
*property
, VARTYPE vt
)
158 HMODULE propsys
= LoadLibraryA("propsys.dll");
159 pPropVariantChangeType
= (void *)GetProcAddress(propsys
, "PropVariantChangeType");
161 if (!pPropVariantChangeType
)
163 ERR("PropVariantChangeType function missing!\n");
164 return ERROR_FUNCTION_FAILED
;
167 hr
= pPropVariantChangeType(changed
, property
, 0, vt
);
168 return (hr
== S_OK
) ? ERROR_SUCCESS
: ERROR_FUNCTION_FAILED
;
171 /* FIXME: doesn't deal with endian conversion */
172 static void read_properties_from_data( PROPVARIANT
*prop
, LPBYTE data
, DWORD sz
)
176 struct property_data
*propdata
;
177 PROPVARIANT property
, *ptr
;
179 struct property_id_offset
*idofs
;
180 struct property_section_header
*section_hdr
;
182 section_hdr
= (struct property_section_header
*) &data
[0];
183 idofs
= (struct property_id_offset
*)&data
[SECT_HDR_SIZE
];
185 /* now set all the properties */
186 for( i
= 0; i
< section_hdr
->cProperties
; i
++ )
188 if( idofs
[i
].propid
>= MSI_MAX_PROPS
)
190 ERR( "unknown property ID %lu\n", idofs
[i
].propid
);
194 type
= get_type( idofs
[i
].propid
);
195 if( type
== VT_EMPTY
)
197 ERR( "propid %lu has unknown type\n", idofs
[i
].propid
);
201 propdata
= (struct property_data
*)&data
[ idofs
[i
].dwOffset
];
203 /* check we don't run off the end of the data */
204 size
= sz
- idofs
[i
].dwOffset
- sizeof(DWORD
);
205 if( sizeof(DWORD
) > size
||
206 ( propdata
->type
== VT_FILETIME
&& sizeof(FILETIME
) > size
) ||
207 ( propdata
->type
== VT_LPSTR
&& (propdata
->u
.str
.len
+ sizeof(DWORD
)) > size
) )
209 ERR("not enough data\n");
213 property
.vt
= propdata
->type
;
214 if( propdata
->type
== VT_LPSTR
)
216 char *str
= malloc( propdata
->u
.str
.len
);
217 memcpy( str
, propdata
->u
.str
.str
, propdata
->u
.str
.len
);
218 str
[ propdata
->u
.str
.len
- 1 ] = 0;
219 property
.pszVal
= str
;
221 else if( propdata
->type
== VT_FILETIME
)
222 property
.filetime
= propdata
->u
.ft
;
223 else if( propdata
->type
== VT_I2
)
224 property
.iVal
= propdata
->u
.i2
;
225 else if( propdata
->type
== VT_I4
)
226 property
.lVal
= propdata
->u
.i4
;
228 /* check the type is the same as we expect */
229 if( type
!= propdata
->type
)
231 propvar_changetype(&changed
, &property
, type
);
237 prop
[ idofs
[i
].propid
] = *ptr
;
241 static UINT
load_summary_info( MSISUMMARYINFO
*si
, IStream
*stm
)
243 struct property_set_header set_hdr
;
244 struct format_id_offset format_hdr
;
245 struct property_section_header section_hdr
;
251 TRACE("%p %p\n", si
, stm
);
253 /* read the header */
255 r
= IStream_Read( stm
, &set_hdr
, sz
, &count
);
256 if( FAILED(r
) || count
!= sz
)
257 return ERROR_FUNCTION_FAILED
;
259 if( set_hdr
.wByteOrder
!= 0xfffe )
261 ERR("property set not big-endian %04X\n", set_hdr
.wByteOrder
);
262 return ERROR_FUNCTION_FAILED
;
265 sz
= sizeof format_hdr
;
266 r
= IStream_Read( stm
, &format_hdr
, sz
, &count
);
267 if( FAILED(r
) || count
!= sz
)
268 return ERROR_FUNCTION_FAILED
;
270 /* check the format id is correct */
271 if( !IsEqualGUID( &FMTID_SummaryInformation
, &format_hdr
.fmtid
) )
272 return ERROR_FUNCTION_FAILED
;
274 /* seek to the location of the section */
275 ofs
.QuadPart
= format_hdr
.dwOffset
;
276 r
= IStream_Seek( stm
, ofs
, STREAM_SEEK_SET
, NULL
);
278 return ERROR_FUNCTION_FAILED
;
280 /* read the section itself */
282 r
= IStream_Read( stm
, §ion_hdr
, sz
, &count
);
283 if( FAILED(r
) || count
!= sz
)
284 return ERROR_FUNCTION_FAILED
;
286 if( section_hdr
.cProperties
> MSI_MAX_PROPS
)
288 ERR( "too many properties %lu\n", section_hdr
.cProperties
);
289 return ERROR_FUNCTION_FAILED
;
292 data
= malloc( section_hdr
.cbSection
);
294 return ERROR_FUNCTION_FAILED
;
296 memcpy( data
, §ion_hdr
, SECT_HDR_SIZE
);
298 /* read all the data in one go */
299 sz
= section_hdr
.cbSection
- SECT_HDR_SIZE
;
300 r
= IStream_Read( stm
, &data
[ SECT_HDR_SIZE
], sz
, &count
);
301 if( SUCCEEDED(r
) && count
== sz
)
302 read_properties_from_data( si
->property
, data
, sz
+ SECT_HDR_SIZE
);
304 ERR( "failed to read properties %lu %lu\n", count
, sz
);
307 return ERROR_SUCCESS
;
310 static DWORD
write_dword( LPBYTE data
, DWORD ofs
, DWORD val
)
314 data
[ofs
++] = val
&0xff;
315 data
[ofs
++] = (val
>>8)&0xff;
316 data
[ofs
++] = (val
>>16)&0xff;
317 data
[ofs
++] = (val
>>24)&0xff;
322 static DWORD
write_filetime( LPBYTE data
, DWORD ofs
, const FILETIME
*ft
)
324 write_dword( data
, ofs
, ft
->dwLowDateTime
);
325 write_dword( data
, ofs
+ 4, ft
->dwHighDateTime
);
329 static DWORD
write_string( LPBYTE data
, DWORD ofs
, LPCSTR str
)
331 DWORD len
= lstrlenA( str
) + 1;
332 write_dword( data
, ofs
, len
);
334 memcpy( &data
[ofs
+ 4], str
, len
);
335 return (7 + len
) & ~3;
338 static UINT
write_property_to_data( const PROPVARIANT
*prop
, LPBYTE data
)
342 if( prop
->vt
== VT_EMPTY
)
346 sz
+= write_dword( data
, sz
, prop
->vt
);
350 sz
+= write_dword( data
, sz
, prop
->iVal
);
353 sz
+= write_dword( data
, sz
, prop
->lVal
);
356 sz
+= write_filetime( data
, sz
, &prop
->filetime
);
359 sz
+= write_string( data
, sz
, prop
->pszVal
);
365 static UINT
save_summary_info( const MSISUMMARYINFO
* si
, IStream
*stm
)
367 UINT ret
= ERROR_FUNCTION_FAILED
;
368 struct property_set_header set_hdr
;
369 struct format_id_offset format_hdr
;
370 struct property_section_header section_hdr
;
371 struct property_id_offset idofs
[MSI_MAX_PROPS
];
377 /* write the header */
379 memset( &set_hdr
, 0, sz
);
380 set_hdr
.wByteOrder
= 0xfffe;
382 set_hdr
.dwOSVer
= 0x00020005; /* build 5, platform id 2 */
383 /* set_hdr.clsID is {00000000-0000-0000-0000-000000000000} */
384 set_hdr
.reserved
= 1;
385 r
= IStream_Write( stm
, &set_hdr
, sz
, &count
);
386 if( FAILED(r
) || count
!= sz
)
389 /* write the format header */
390 sz
= sizeof format_hdr
;
391 format_hdr
.fmtid
= FMTID_SummaryInformation
;
392 format_hdr
.dwOffset
= sizeof format_hdr
+ sizeof set_hdr
;
393 r
= IStream_Write( stm
, &format_hdr
, sz
, &count
);
394 if( FAILED(r
) || count
!= sz
)
397 /* add up how much space the data will take and calculate the offsets */
398 section_hdr
.cbSection
= sizeof section_hdr
;
399 section_hdr
.cbSection
+= (get_property_count( si
->property
) * sizeof idofs
[0]);
400 section_hdr
.cProperties
= 0;
401 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
403 sz
= write_property_to_data( &si
->property
[i
], NULL
);
406 idofs
[ section_hdr
.cProperties
].propid
= i
;
407 idofs
[ section_hdr
.cProperties
].dwOffset
= section_hdr
.cbSection
;
408 section_hdr
.cProperties
++;
409 section_hdr
.cbSection
+= sz
;
412 data
= calloc( 1, section_hdr
.cbSection
);
415 memcpy( &data
[sz
], §ion_hdr
, sizeof section_hdr
);
416 sz
+= sizeof section_hdr
;
418 memcpy( &data
[sz
], idofs
, section_hdr
.cProperties
* sizeof idofs
[0] );
419 sz
+= section_hdr
.cProperties
* sizeof idofs
[0];
421 /* write out the data */
422 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
423 sz
+= write_property_to_data( &si
->property
[i
], &data
[sz
] );
425 r
= IStream_Write( stm
, data
, sz
, &count
);
427 if( FAILED(r
) || count
!= sz
)
430 return ERROR_SUCCESS
;
433 static MSISUMMARYINFO
*create_suminfo( IStorage
*stg
, UINT update_count
)
437 if (!(si
= alloc_msiobject( MSIHANDLETYPE_SUMMARYINFO
, sizeof(MSISUMMARYINFO
), MSI_CloseSummaryInfo
)))
440 si
->update_count
= update_count
;
441 IStorage_AddRef( stg
);
447 UINT
msi_get_suminfo( IStorage
*stg
, UINT uiUpdateCount
, MSISUMMARYINFO
**ret
)
454 TRACE("%p, %u\n", stg
, uiUpdateCount
);
456 if (!(si
= create_suminfo( stg
, uiUpdateCount
))) return ERROR_OUTOFMEMORY
;
458 hr
= IStorage_OpenStream( si
->storage
, L
"\5SummaryInformation", 0, STGM_READ
|STGM_SHARE_EXCLUSIVE
, 0, &stm
);
461 msiobj_release( &si
->hdr
);
462 return ERROR_FUNCTION_FAILED
;
465 r
= load_summary_info( si
, stm
);
466 IStream_Release( stm
);
467 if (r
!= ERROR_SUCCESS
)
469 msiobj_release( &si
->hdr
);
474 return ERROR_SUCCESS
;
477 UINT
msi_get_db_suminfo( MSIDATABASE
*db
, UINT uiUpdateCount
, MSISUMMARYINFO
**ret
)
483 if (!(si
= create_suminfo( db
->storage
, uiUpdateCount
))) return ERROR_OUTOFMEMORY
;
485 r
= msi_get_stream( db
, L
"\5SummaryInformation", &stm
);
486 if (r
!= ERROR_SUCCESS
)
488 msiobj_release( &si
->hdr
);
492 r
= load_summary_info( si
, stm
);
493 IStream_Release( stm
);
494 if (r
!= ERROR_SUCCESS
)
496 msiobj_release( &si
->hdr
);
501 return ERROR_SUCCESS
;
504 UINT WINAPI
MsiGetSummaryInformationW( MSIHANDLE hDatabase
, const WCHAR
*szDatabase
, UINT uiUpdateCount
,
511 TRACE( "%lu, %s, %u, %p\n", hDatabase
, debugstr_w(szDatabase
), uiUpdateCount
, pHandle
);
514 return ERROR_INVALID_PARAMETER
;
516 if( szDatabase
&& szDatabase
[0] )
518 LPCWSTR persist
= uiUpdateCount
? MSIDBOPEN_TRANSACT
: MSIDBOPEN_READONLY
;
520 ret
= MSI_OpenDatabaseW( szDatabase
, persist
, &db
);
521 if( ret
!= ERROR_SUCCESS
)
526 db
= msihandle2msiinfo( hDatabase
, MSIHANDLETYPE_DATABASE
);
529 MSIHANDLE remote
, remote_suminfo
;
531 if (!(remote
= msi_get_remote(hDatabase
)))
532 return ERROR_INVALID_HANDLE
;
536 ret
= remote_DatabaseGetSummaryInformation(remote
, uiUpdateCount
, &remote_suminfo
);
540 ret
= GetExceptionCode();
545 *pHandle
= alloc_msi_remote_handle(remote_suminfo
);
551 ret
= msi_get_suminfo( db
->storage
, uiUpdateCount
, &si
);
552 if (ret
!= ERROR_SUCCESS
)
553 ret
= msi_get_db_suminfo( db
, uiUpdateCount
, &si
);
554 if (ret
!= ERROR_SUCCESS
)
556 if ((si
= create_suminfo( db
->storage
, uiUpdateCount
)))
560 if (ret
== ERROR_SUCCESS
)
562 *pHandle
= alloc_msihandle( &si
->hdr
);
566 ret
= ERROR_NOT_ENOUGH_MEMORY
;
567 msiobj_release( &si
->hdr
);
570 msiobj_release( &db
->hdr
);
574 UINT WINAPI
MsiGetSummaryInformationA( MSIHANDLE hDatabase
, const char *szDatabase
, UINT uiUpdateCount
,
577 WCHAR
*szwDatabase
= NULL
;
580 TRACE( "%lu, %s, %u, %p\n", hDatabase
, debugstr_a(szDatabase
), uiUpdateCount
, pHandle
);
584 szwDatabase
= strdupAtoW( szDatabase
);
586 return ERROR_FUNCTION_FAILED
;
589 ret
= MsiGetSummaryInformationW(hDatabase
, szwDatabase
, uiUpdateCount
, pHandle
);
596 UINT WINAPI
MsiSummaryInfoGetPropertyCount( MSIHANDLE hSummaryInfo
, UINT
*pCount
)
600 TRACE( "%lu, %p\n", hSummaryInfo
, pCount
);
602 si
= msihandle2msiinfo( hSummaryInfo
, MSIHANDLETYPE_SUMMARYINFO
);
608 if (!(remote
= msi_get_remote( hSummaryInfo
)))
609 return ERROR_INVALID_HANDLE
;
613 ret
= remote_SummaryInfoGetPropertyCount( remote
, pCount
);
617 ret
= GetExceptionCode();
625 *pCount
= get_property_count( si
->property
);
626 msiobj_release( &si
->hdr
);
628 return ERROR_SUCCESS
;
631 static UINT
get_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT
*puiDataType
, INT
*piValue
,
632 FILETIME
*pftValue
, awstring
*str
, DWORD
*pcchValueBuf
)
635 UINT ret
= ERROR_SUCCESS
;
637 prop
= &si
->property
[uiProperty
];
640 *puiDataType
= prop
->vt
;
646 *piValue
= prop
->iVal
;
650 *piValue
= prop
->lVal
;
659 len
= MultiByteToWideChar( CP_ACP
, 0, prop
->pszVal
, -1, NULL
, 0 ) - 1;
660 MultiByteToWideChar( CP_ACP
, 0, prop
->pszVal
, -1, str
->str
.w
, *pcchValueBuf
);
664 len
= lstrlenA( prop
->pszVal
);
666 lstrcpynA(str
->str
.a
, prop
->pszVal
, *pcchValueBuf
);
668 if (len
>= *pcchValueBuf
)
669 ret
= ERROR_MORE_DATA
;
675 *pftValue
= prop
->filetime
;
680 FIXME("Unknown property variant type\n");
686 LPWSTR
msi_suminfo_dup_string( MSISUMMARYINFO
*si
, UINT uiProperty
)
690 if ( uiProperty
>= MSI_MAX_PROPS
)
692 prop
= &si
->property
[uiProperty
];
693 if( prop
->vt
!= VT_LPSTR
)
695 return strdupAtoW( prop
->pszVal
);
698 INT
msi_suminfo_get_int32( MSISUMMARYINFO
*si
, UINT uiProperty
)
702 if ( uiProperty
>= MSI_MAX_PROPS
)
704 prop
= &si
->property
[uiProperty
];
705 if( prop
->vt
!= VT_I4
)
710 LPWSTR
msi_get_suminfo_product( IStorage
*stg
)
716 r
= msi_get_suminfo( stg
, 0, &si
);
717 if (r
!= ERROR_SUCCESS
)
719 ERR("no summary information!\n");
722 prod
= msi_suminfo_dup_string( si
, PID_REVNUMBER
);
723 msiobj_release( &si
->hdr
);
727 UINT WINAPI
MsiSummaryInfoGetPropertyA( MSIHANDLE handle
, UINT uiProperty
, UINT
*puiDataType
, INT
*piValue
,
728 FILETIME
*pftValue
, char *szValueBuf
, DWORD
*pcchValueBuf
)
734 TRACE( "%lu, %u, %p, %p, %p, %p, %p\n", handle
, uiProperty
, puiDataType
, piValue
, pftValue
, szValueBuf
,
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( MSIHANDLE handle
, UINT uiProperty
, UINT
*puiDataType
, INT
*piValue
,
779 FILETIME
*pftValue
, WCHAR
*szValueBuf
, DWORD
*pcchValueBuf
)
785 TRACE( "%lu, %u, %p, %p, %p, %p, %p\n", handle
, uiProperty
, puiDataType
, piValue
, pftValue
, szValueBuf
,
788 if (uiProperty
>= MSI_MAX_PROPS
)
790 if (puiDataType
) *puiDataType
= VT_EMPTY
;
791 return ERROR_UNKNOWN_PROPERTY
;
794 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
799 if (!(remote
= msi_get_remote( handle
)))
800 return ERROR_INVALID_HANDLE
;
804 r
= remote_SummaryInfoGetProperty( remote
, uiProperty
, puiDataType
, piValue
, pftValue
, &buf
);
808 r
= GetExceptionCode();
813 r
= msi_strncpyW( buf
, -1, szValueBuf
, pcchValueBuf
);
815 midl_user_free( buf
);
820 str
.str
.w
= szValueBuf
;
822 r
= get_prop( si
, uiProperty
, puiDataType
, piValue
, pftValue
, &str
, pcchValueBuf
);
823 msiobj_release( &si
->hdr
);
827 static UINT
set_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT type
,
828 INT iValue
, FILETIME
*pftValue
, awcstring
*str
)
833 TRACE("%p, %u, %u, %d, %p, %p\n", si
, uiProperty
, type
, iValue
, pftValue
, str
);
835 prop
= &si
->property
[uiProperty
];
837 if( prop
->vt
== VT_EMPTY
)
839 if( !si
->update_count
)
840 return ERROR_FUNCTION_FAILED
;
844 else if( prop
->vt
!= type
)
845 return ERROR_SUCCESS
;
858 prop
->filetime
= *pftValue
;
863 len
= WideCharToMultiByte( CP_ACP
, 0, str
->str
.w
, -1,
864 NULL
, 0, NULL
, NULL
);
865 prop
->pszVal
= malloc( len
);
866 WideCharToMultiByte( CP_ACP
, 0, str
->str
.w
, -1,
867 prop
->pszVal
, len
, NULL
, NULL
);
871 len
= lstrlenA( str
->str
.a
) + 1;
872 prop
->pszVal
= malloc( len
);
873 lstrcpyA( prop
->pszVal
, str
->str
.a
);
878 return ERROR_SUCCESS
;
881 static UINT
suminfo_set_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT uiDataType
, INT iValue
, FILETIME
*pftValue
,
884 UINT type
= get_type( uiProperty
);
885 if( type
== VT_EMPTY
|| type
!= uiDataType
)
886 return ERROR_DATATYPE_MISMATCH
;
888 if( uiDataType
== VT_LPSTR
&& !str
->str
.a
)
889 return ERROR_INVALID_PARAMETER
;
891 if( uiDataType
== VT_FILETIME
&& !pftValue
)
892 return ERROR_INVALID_PARAMETER
;
894 return set_prop( si
, uiProperty
, type
, iValue
, pftValue
, str
);
897 UINT WINAPI
MsiSummaryInfoSetPropertyW( MSIHANDLE handle
, UINT uiProperty
, UINT uiDataType
, INT iValue
,
898 FILETIME
*pftValue
, const WCHAR
*szValue
)
904 TRACE( "%lu, %u, %u, %d, %p, %s\n", handle
, uiProperty
, uiDataType
, iValue
, pftValue
, debugstr_w(szValue
) );
906 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
910 if ((remote
= msi_get_remote( handle
)))
912 WARN("MsiSummaryInfoSetProperty not allowed during a custom action!\n");
913 return ERROR_FUNCTION_FAILED
;
916 return ERROR_INVALID_HANDLE
;
922 ret
= suminfo_set_prop( si
, uiProperty
, uiDataType
, iValue
, pftValue
, &str
);
923 msiobj_release( &si
->hdr
);
927 UINT WINAPI
MsiSummaryInfoSetPropertyA( MSIHANDLE handle
, UINT uiProperty
, UINT uiDataType
, INT iValue
,
928 FILETIME
*pftValue
, const char *szValue
)
934 TRACE( "%lu, %u, %u, %d, %p, %s\n", handle
, uiProperty
, uiDataType
, iValue
, pftValue
, debugstr_a(szValue
) );
936 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
940 if ((remote
= msi_get_remote( handle
)))
942 WARN("MsiSummaryInfoSetProperty not allowed during a custom action!\n");
943 return ERROR_FUNCTION_FAILED
;
946 return ERROR_INVALID_HANDLE
;
952 ret
= suminfo_set_prop( si
, uiProperty
, uiDataType
, iValue
, pftValue
, &str
);
953 msiobj_release( &si
->hdr
);
957 static UINT
suminfo_persist( MSISUMMARYINFO
*si
)
959 UINT ret
= ERROR_FUNCTION_FAILED
;
964 grfMode
= STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
;
965 r
= IStorage_CreateStream( si
->storage
, L
"\5SummaryInformation", grfMode
, 0, 0, &stm
);
968 ret
= save_summary_info( si
, stm
);
969 IStream_Release( stm
);
974 static void parse_filetime( LPCWSTR str
, FILETIME
*ft
)
977 const WCHAR
*p
= str
;
980 memset( <
, 0, sizeof(lt
) );
982 /* YYYY/MM/DD hh:mm:ss */
984 while (iswspace( *p
)) p
++;
986 lt
.wYear
= wcstol( p
, &end
, 10 );
987 if (*end
!= '/') return;
990 lt
.wMonth
= wcstol( p
, &end
, 10 );
991 if (*end
!= '/') return;
994 lt
.wDay
= wcstol( p
, &end
, 10 );
995 if (*end
!= ' ') return;
998 while (iswspace( *p
)) p
++;
1000 lt
.wHour
= wcstol( p
, &end
, 10 );
1001 if (*end
!= ':') return;
1004 lt
.wMinute
= wcstol( p
, &end
, 10 );
1005 if (*end
!= ':') return;
1008 lt
.wSecond
= wcstol( p
, &end
, 10 );
1010 TzSpecificLocalTimeToSystemTime( NULL
, <
, &utc
);
1011 SystemTimeToFileTime( &utc
, ft
);
1014 static UINT
parse_prop( LPCWSTR prop
, LPCWSTR value
, UINT
*pid
, INT
*int_value
,
1015 FILETIME
*ft_value
, awcstring
*str_value
)
1017 *pid
= wcstol( prop
, NULL
, 10 );
1025 *int_value
= wcstol( value
, NULL
, 10 );
1028 case PID_LASTPRINTED
:
1029 case PID_CREATE_DTM
:
1030 case PID_LASTSAVE_DTM
:
1031 parse_filetime( value
, ft_value
);
1039 case PID_LASTAUTHOR
:
1043 str_value
->str
.w
= value
;
1044 str_value
->unicode
= TRUE
;
1048 WARN("unhandled prop id %u\n", *pid
);
1049 return ERROR_FUNCTION_FAILED
;
1052 return ERROR_SUCCESS
;
1055 UINT
msi_add_suminfo( MSIDATABASE
*db
, LPWSTR
**records
, int num_records
, int num_columns
)
1061 r
= msi_get_suminfo( db
->storage
, num_records
* (num_columns
/ 2), &si
);
1062 if (r
!= ERROR_SUCCESS
)
1064 if (!(si
= create_suminfo( db
->storage
, num_records
* (num_columns
/ 2) )))
1065 return ERROR_OUTOFMEMORY
;
1069 for (i
= 0; i
< num_records
; i
++)
1071 for (j
= 0; j
< num_columns
; j
+= 2)
1076 awcstring str_value
;
1078 r
= parse_prop( records
[i
][j
], records
[i
][j
+ 1], &pid
, &int_value
, &ft_value
, &str_value
);
1079 if (r
!= ERROR_SUCCESS
)
1082 r
= set_prop( si
, pid
, get_type(pid
), int_value
, &ft_value
, &str_value
);
1083 if (r
!= ERROR_SUCCESS
)
1089 if (r
== ERROR_SUCCESS
)
1090 r
= suminfo_persist( si
);
1092 msiobj_release( &si
->hdr
);
1096 static UINT
save_prop( MSISUMMARYINFO
*si
, HANDLE handle
, UINT row
)
1098 static const char fmt_systemtime
[] = "%04u/%02u/%02u %02u:%02u:%02u";
1099 char data
[36]; /* largest string: YYYY/MM/DD hh:mm:ss */
1100 static const char fmt_begin
[] = "%u\t";
1101 static const char data_end
[] = "\r\n";
1102 static const char fmt_int
[] = "%u";
1104 SYSTEMTIME system_time
;
1110 str
.unicode
= FALSE
;
1113 r
= get_prop( si
, row
, &data_type
, &int_value
, &file_time
, &str
, &len
);
1114 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
1116 if (data_type
== VT_EMPTY
)
1117 return ERROR_SUCCESS
; /* property not set */
1118 sz
= sprintf( data
, fmt_begin
, row
);
1119 if (!WriteFile( handle
, data
, sz
, &sz
, NULL
))
1120 return ERROR_WRITE_FAULT
;
1126 sz
= sprintf( data
, fmt_int
, int_value
);
1127 if (!WriteFile( handle
, data
, sz
, &sz
, NULL
))
1128 return ERROR_WRITE_FAULT
;
1132 if (!(str
.str
.a
= malloc( len
)))
1133 return ERROR_OUTOFMEMORY
;
1134 r
= get_prop( si
, row
, NULL
, NULL
, NULL
, &str
, &len
);
1135 if (r
!= ERROR_SUCCESS
)
1141 if (!WriteFile( handle
, str
.str
.a
, sz
, &sz
, NULL
))
1144 return ERROR_WRITE_FAULT
;
1149 if (!FileTimeToSystemTime( &file_time
, &system_time
))
1150 return ERROR_FUNCTION_FAILED
;
1151 sz
= sprintf( data
, fmt_systemtime
, system_time
.wYear
, system_time
.wMonth
,
1152 system_time
.wDay
, system_time
.wHour
, system_time
.wMinute
,
1153 system_time
.wSecond
);
1154 if (!WriteFile( handle
, data
, sz
, &sz
, NULL
))
1155 return ERROR_WRITE_FAULT
;
1158 /* cannot reach here, property not set */
1161 FIXME( "Unknown property variant type\n" );
1162 return ERROR_FUNCTION_FAILED
;
1165 sz
= ARRAY_SIZE(data_end
) - 1;
1166 if (!WriteFile( handle
, data_end
, sz
, &sz
, NULL
))
1167 return ERROR_WRITE_FAULT
;
1169 return ERROR_SUCCESS
;
1172 UINT
msi_export_suminfo( MSIDATABASE
*db
, HANDLE handle
)
1174 UINT i
, r
, num_rows
;
1177 r
= msi_get_suminfo( db
->storage
, 0, &si
);
1178 if (r
!= ERROR_SUCCESS
)
1179 r
= msi_get_db_suminfo( db
, 0, &si
);
1180 if (r
!= ERROR_SUCCESS
)
1183 num_rows
= get_property_count( si
->property
);
1186 msiobj_release( &si
->hdr
);
1187 return ERROR_FUNCTION_FAILED
;
1190 for (i
= 0; i
< num_rows
; i
++)
1192 r
= save_prop( si
, handle
, i
);
1193 if (r
!= ERROR_SUCCESS
)
1195 msiobj_release( &si
->hdr
);
1200 msiobj_release( &si
->hdr
);
1201 return ERROR_SUCCESS
;
1204 UINT WINAPI
MsiSummaryInfoPersist( MSIHANDLE handle
)
1209 TRACE( "%lu\n", handle
);
1211 si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
);
1213 return ERROR_INVALID_HANDLE
;
1215 ret
= suminfo_persist( si
);
1217 msiobj_release( &si
->hdr
);
1221 UINT WINAPI
MsiCreateTransformSummaryInfoA( MSIHANDLE db
, MSIHANDLE db_ref
, const char *transform
, int error
,
1225 WCHAR
*transformW
= NULL
;
1227 TRACE( "%lu, %lu, %s, %d, %d\n", db
, db_ref
, debugstr_a(transform
), error
, validation
);
1229 if (transform
&& !(transformW
= strdupAtoW( transform
)))
1230 return ERROR_OUTOFMEMORY
;
1232 r
= MsiCreateTransformSummaryInfoW( db
, db_ref
, transformW
, error
, validation
);
1237 UINT WINAPI
MsiCreateTransformSummaryInfoW( MSIHANDLE db
, MSIHANDLE db_ref
, const WCHAR
*transform
, int error
,
1240 FIXME( "%lu, %lu, %s, %d, %d\n", db
, db_ref
, debugstr_w(transform
), error
, validation
);
1241 return ERROR_FUNCTION_FAILED
;
1244 UINT
msi_load_suminfo_properties( MSIPACKAGE
*package
)
1247 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
= malloc( 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 free( package_code
);
1283 msiobj_release( &si
->hdr
);
1287 r
= msi_set_property( package
->db
, L
"PackageCode", package_code
, len
);
1288 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
);