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
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
37 #include "propvarutil.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
62 } PROPERTYSECTIONHEADER
;
84 static HRESULT (WINAPI
*pPropVariantChangeType
)
85 (PROPVARIANT
*ppropvarDest
, REFPROPVARIANT propvarSrc
,
86 PROPVAR_CHANGE_FLAGS flags
, VARTYPE vt
);
88 #define SECT_HDR_SIZE (sizeof(PROPERTYSECTIONHEADER))
90 static void free_prop( PROPVARIANT
*prop
)
92 if (prop
->vt
== VT_LPSTR
)
93 msi_free( prop
->u
.pszVal
);
97 static void MSI_CloseSummaryInfo( MSIOBJECTHDR
*arg
)
99 MSISUMMARYINFO
*si
= (MSISUMMARYINFO
*) arg
;
102 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
103 free_prop( &si
->property
[i
] );
104 IStorage_Release( si
->storage
);
107 static UINT
get_type( UINT uiProperty
)
125 case PID_LASTPRINTED
:
127 case PID_LASTSAVE_DTM
:
139 static UINT
get_property_count( const PROPVARIANT
*property
)
145 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
146 if( property
[i
].vt
!= VT_EMPTY
)
151 static UINT
propvar_changetype(PROPVARIANT
*changed
, PROPVARIANT
*property
, VARTYPE vt
)
154 HMODULE propsys
= LoadLibraryA("propsys.dll");
155 pPropVariantChangeType
= (void *)GetProcAddress(propsys
, "PropVariantChangeType");
157 if (!pPropVariantChangeType
)
159 ERR("PropVariantChangeType function missing!\n");
160 return ERROR_FUNCTION_FAILED
;
163 hr
= pPropVariantChangeType(changed
, property
, 0, vt
);
164 return (hr
== S_OK
) ? ERROR_SUCCESS
: ERROR_FUNCTION_FAILED
;
167 /* FIXME: doesn't deal with endian conversion */
168 static void read_properties_from_data( PROPVARIANT
*prop
, LPBYTE data
, DWORD sz
)
172 PROPERTY_DATA
*propdata
;
173 PROPVARIANT property
, *ptr
;
175 PROPERTYIDOFFSET
*idofs
;
176 PROPERTYSECTIONHEADER
*section_hdr
;
178 section_hdr
= (PROPERTYSECTIONHEADER
*) &data
[0];
179 idofs
= (PROPERTYIDOFFSET
*) &data
[SECT_HDR_SIZE
];
181 /* now set all the properties */
182 for( i
= 0; i
< section_hdr
->cProperties
; i
++ )
184 if( idofs
[i
].propid
>= MSI_MAX_PROPS
)
186 ERR("Unknown property ID %d\n", idofs
[i
].propid
);
190 type
= get_type( idofs
[i
].propid
);
191 if( type
== VT_EMPTY
)
193 ERR("propid %d has unknown type\n", idofs
[i
].propid
);
197 propdata
= (PROPERTY_DATA
*) &data
[ idofs
[i
].dwOffset
];
199 /* check we don't run off the end of the data */
200 size
= sz
- idofs
[i
].dwOffset
- sizeof(DWORD
);
201 if( sizeof(DWORD
) > size
||
202 ( propdata
->type
== VT_FILETIME
&& sizeof(FILETIME
) > size
) ||
203 ( propdata
->type
== VT_LPSTR
&& (propdata
->u
.str
.len
+ sizeof(DWORD
)) > size
) )
205 ERR("not enough data\n");
209 property
.vt
= propdata
->type
;
210 if( propdata
->type
== VT_LPSTR
)
212 LPSTR str
= msi_alloc( propdata
->u
.str
.len
);
213 memcpy( str
, propdata
->u
.str
.str
, propdata
->u
.str
.len
);
214 str
[ propdata
->u
.str
.len
- 1 ] = 0;
215 property
.u
.pszVal
= str
;
217 else if( propdata
->type
== VT_FILETIME
)
218 property
.u
.filetime
= propdata
->u
.ft
;
219 else if( propdata
->type
== VT_I2
)
220 property
.u
.iVal
= propdata
->u
.i2
;
221 else if( propdata
->type
== VT_I4
)
222 property
.u
.lVal
= propdata
->u
.i4
;
224 /* check the type is the same as we expect */
225 if( type
!= propdata
->type
)
227 propvar_changetype(&changed
, &property
, type
);
233 prop
[ idofs
[i
].propid
] = *ptr
;
237 static UINT
load_summary_info( MSISUMMARYINFO
*si
, IStream
*stm
)
239 PROPERTYSETHEADER set_hdr
;
240 FORMATIDOFFSET format_hdr
;
241 PROPERTYSECTIONHEADER section_hdr
;
247 TRACE("%p %p\n", si
, stm
);
249 /* read the header */
251 r
= IStream_Read( stm
, &set_hdr
, sz
, &count
);
252 if( FAILED(r
) || count
!= sz
)
253 return ERROR_FUNCTION_FAILED
;
255 if( set_hdr
.wByteOrder
!= 0xfffe )
257 ERR("property set not big-endian %04X\n", set_hdr
.wByteOrder
);
258 return ERROR_FUNCTION_FAILED
;
261 sz
= sizeof format_hdr
;
262 r
= IStream_Read( stm
, &format_hdr
, sz
, &count
);
263 if( FAILED(r
) || count
!= sz
)
264 return ERROR_FUNCTION_FAILED
;
266 /* check the format id is correct */
267 if( !IsEqualGUID( &FMTID_SummaryInformation
, &format_hdr
.fmtid
) )
268 return ERROR_FUNCTION_FAILED
;
270 /* seek to the location of the section */
271 ofs
.QuadPart
= format_hdr
.dwOffset
;
272 r
= IStream_Seek( stm
, ofs
, STREAM_SEEK_SET
, NULL
);
274 return ERROR_FUNCTION_FAILED
;
276 /* read the section itself */
278 r
= IStream_Read( stm
, §ion_hdr
, sz
, &count
);
279 if( FAILED(r
) || count
!= sz
)
280 return ERROR_FUNCTION_FAILED
;
282 if( section_hdr
.cProperties
> MSI_MAX_PROPS
)
284 ERR("too many properties %d\n", section_hdr
.cProperties
);
285 return ERROR_FUNCTION_FAILED
;
288 data
= msi_alloc( section_hdr
.cbSection
);
290 return ERROR_FUNCTION_FAILED
;
292 memcpy( data
, §ion_hdr
, SECT_HDR_SIZE
);
294 /* read all the data in one go */
295 sz
= section_hdr
.cbSection
- SECT_HDR_SIZE
;
296 r
= IStream_Read( stm
, &data
[ SECT_HDR_SIZE
], sz
, &count
);
297 if( SUCCEEDED(r
) && count
== sz
)
298 read_properties_from_data( si
->property
, data
, sz
+ SECT_HDR_SIZE
);
300 ERR("failed to read properties %d %d\n", count
, sz
);
303 return ERROR_SUCCESS
;
306 static DWORD
write_dword( LPBYTE data
, DWORD ofs
, DWORD val
)
310 data
[ofs
++] = val
&0xff;
311 data
[ofs
++] = (val
>>8)&0xff;
312 data
[ofs
++] = (val
>>16)&0xff;
313 data
[ofs
++] = (val
>>24)&0xff;
318 static DWORD
write_filetime( LPBYTE data
, DWORD ofs
, const FILETIME
*ft
)
320 write_dword( data
, ofs
, ft
->dwLowDateTime
);
321 write_dword( data
, ofs
+ 4, ft
->dwHighDateTime
);
325 static DWORD
write_string( LPBYTE data
, DWORD ofs
, LPCSTR str
)
327 DWORD len
= lstrlenA( str
) + 1;
328 write_dword( data
, ofs
, len
);
330 memcpy( &data
[ofs
+ 4], str
, len
);
331 return (7 + len
) & ~3;
334 static UINT
write_property_to_data( const PROPVARIANT
*prop
, LPBYTE data
)
338 if( prop
->vt
== VT_EMPTY
)
342 sz
+= write_dword( data
, sz
, prop
->vt
);
346 sz
+= write_dword( data
, sz
, prop
->u
.iVal
);
349 sz
+= write_dword( data
, sz
, prop
->u
.lVal
);
352 sz
+= write_filetime( data
, sz
, &prop
->u
.filetime
);
355 sz
+= write_string( data
, sz
, prop
->u
.pszVal
);
361 static UINT
save_summary_info( const MSISUMMARYINFO
* si
, IStream
*stm
)
363 UINT ret
= ERROR_FUNCTION_FAILED
;
364 PROPERTYSETHEADER set_hdr
;
365 FORMATIDOFFSET format_hdr
;
366 PROPERTYSECTIONHEADER section_hdr
;
367 PROPERTYIDOFFSET idofs
[MSI_MAX_PROPS
];
373 /* write the header */
375 memset( &set_hdr
, 0, sz
);
376 set_hdr
.wByteOrder
= 0xfffe;
378 set_hdr
.dwOSVer
= 0x00020005; /* build 5, platform id 2 */
379 /* set_hdr.clsID is {00000000-0000-0000-0000-000000000000} */
380 set_hdr
.reserved
= 1;
381 r
= IStream_Write( stm
, &set_hdr
, sz
, &count
);
382 if( FAILED(r
) || count
!= sz
)
385 /* write the format header */
386 sz
= sizeof format_hdr
;
387 format_hdr
.fmtid
= FMTID_SummaryInformation
;
388 format_hdr
.dwOffset
= sizeof format_hdr
+ sizeof set_hdr
;
389 r
= IStream_Write( stm
, &format_hdr
, sz
, &count
);
390 if( FAILED(r
) || count
!= sz
)
393 /* add up how much space the data will take and calculate the offsets */
394 section_hdr
.cbSection
= sizeof section_hdr
;
395 section_hdr
.cbSection
+= (get_property_count( si
->property
) * sizeof idofs
[0]);
396 section_hdr
.cProperties
= 0;
397 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
399 sz
= write_property_to_data( &si
->property
[i
], NULL
);
402 idofs
[ section_hdr
.cProperties
].propid
= i
;
403 idofs
[ section_hdr
.cProperties
].dwOffset
= section_hdr
.cbSection
;
404 section_hdr
.cProperties
++;
405 section_hdr
.cbSection
+= sz
;
408 data
= msi_alloc_zero( section_hdr
.cbSection
);
411 memcpy( &data
[sz
], §ion_hdr
, sizeof section_hdr
);
412 sz
+= sizeof section_hdr
;
414 memcpy( &data
[sz
], idofs
, section_hdr
.cProperties
* sizeof idofs
[0] );
415 sz
+= section_hdr
.cProperties
* sizeof idofs
[0];
417 /* write out the data */
418 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
419 sz
+= write_property_to_data( &si
->property
[i
], &data
[sz
] );
421 r
= IStream_Write( stm
, data
, sz
, &count
);
423 if( FAILED(r
) || count
!= sz
)
426 return ERROR_SUCCESS
;
429 static MSISUMMARYINFO
*create_suminfo( IStorage
*stg
, UINT update_count
)
433 if (!(si
= alloc_msiobject( MSIHANDLETYPE_SUMMARYINFO
, sizeof(MSISUMMARYINFO
), MSI_CloseSummaryInfo
)))
436 si
->update_count
= update_count
;
437 IStorage_AddRef( stg
);
443 UINT
msi_get_suminfo( IStorage
*stg
, UINT uiUpdateCount
, MSISUMMARYINFO
**ret
)
450 TRACE("%p, %u\n", stg
, uiUpdateCount
);
452 if (!(si
= create_suminfo( stg
, uiUpdateCount
))) return ERROR_OUTOFMEMORY
;
454 hr
= IStorage_OpenStream( si
->storage
, szSumInfo
, 0, STGM_READ
|STGM_SHARE_EXCLUSIVE
, 0, &stm
);
457 msiobj_release( &si
->hdr
);
458 return ERROR_FUNCTION_FAILED
;
461 r
= load_summary_info( si
, stm
);
462 IStream_Release( stm
);
463 if (r
!= ERROR_SUCCESS
)
465 msiobj_release( &si
->hdr
);
470 return ERROR_SUCCESS
;
473 UINT
msi_get_db_suminfo( MSIDATABASE
*db
, UINT uiUpdateCount
, MSISUMMARYINFO
**ret
)
479 if (!(si
= create_suminfo( db
->storage
, uiUpdateCount
))) return ERROR_OUTOFMEMORY
;
481 r
= msi_get_stream( db
, szSumInfo
, &stm
);
482 if (r
!= ERROR_SUCCESS
)
484 msiobj_release( &si
->hdr
);
488 r
= load_summary_info( si
, stm
);
489 IStream_Release( stm
);
490 if (r
!= ERROR_SUCCESS
)
492 msiobj_release( &si
->hdr
);
497 return ERROR_SUCCESS
;
500 UINT WINAPI
MsiGetSummaryInformationW( MSIHANDLE hDatabase
,
501 LPCWSTR szDatabase
, UINT uiUpdateCount
, MSIHANDLE
*pHandle
)
507 TRACE("%d %s %d %p\n", hDatabase
, debugstr_w(szDatabase
),
508 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
;
531 ret
= remote_DatabaseGetSummaryInformation(remote
, uiUpdateCount
, &remote_suminfo
);
533 *pHandle
= alloc_msi_remote_handle(remote_suminfo
);
539 ret
= msi_get_suminfo( db
->storage
, uiUpdateCount
, &si
);
540 if (ret
!= ERROR_SUCCESS
)
541 ret
= msi_get_db_suminfo( db
, uiUpdateCount
, &si
);
542 if (ret
!= ERROR_SUCCESS
)
544 if ((si
= create_suminfo( db
->storage
, uiUpdateCount
)))
548 if (ret
== ERROR_SUCCESS
)
550 *pHandle
= alloc_msihandle( &si
->hdr
);
554 ret
= ERROR_NOT_ENOUGH_MEMORY
;
555 msiobj_release( &si
->hdr
);
558 msiobj_release( &db
->hdr
);
562 UINT WINAPI
MsiGetSummaryInformationA(MSIHANDLE hDatabase
,
563 LPCSTR szDatabase
, UINT uiUpdateCount
, MSIHANDLE
*pHandle
)
565 LPWSTR szwDatabase
= NULL
;
568 TRACE("%d %s %d %p\n", hDatabase
, debugstr_a(szDatabase
),
569 uiUpdateCount
, pHandle
);
573 szwDatabase
= strdupAtoW( szDatabase
);
575 return ERROR_FUNCTION_FAILED
;
578 ret
= MsiGetSummaryInformationW(hDatabase
, szwDatabase
, uiUpdateCount
, pHandle
);
580 msi_free( szwDatabase
);
585 UINT WINAPI
MsiSummaryInfoGetPropertyCount(MSIHANDLE hSummaryInfo
, PUINT pCount
)
589 TRACE("%d %p\n", hSummaryInfo
, pCount
);
591 si
= msihandle2msiinfo( hSummaryInfo
, MSIHANDLETYPE_SUMMARYINFO
);
593 return ERROR_INVALID_HANDLE
;
596 *pCount
= get_property_count( si
->property
);
597 msiobj_release( &si
->hdr
);
599 return ERROR_SUCCESS
;
602 static UINT
get_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT
*puiDataType
, INT
*piValue
,
603 FILETIME
*pftValue
, awstring
*str
, DWORD
*pcchValueBuf
)
606 UINT ret
= ERROR_SUCCESS
;
608 prop
= &si
->property
[uiProperty
];
611 *puiDataType
= prop
->vt
;
617 *piValue
= prop
->u
.iVal
;
621 *piValue
= prop
->u
.lVal
;
630 len
= MultiByteToWideChar( CP_ACP
, 0, prop
->u
.pszVal
, -1, NULL
, 0 ) - 1;
631 MultiByteToWideChar( CP_ACP
, 0, prop
->u
.pszVal
, -1, str
->str
.w
, *pcchValueBuf
);
635 len
= lstrlenA( prop
->u
.pszVal
);
637 lstrcpynA(str
->str
.a
, prop
->u
.pszVal
, *pcchValueBuf
);
639 if (len
>= *pcchValueBuf
)
640 ret
= ERROR_MORE_DATA
;
646 *pftValue
= prop
->u
.filetime
;
651 FIXME("Unknown property variant type\n");
657 LPWSTR
msi_suminfo_dup_string( MSISUMMARYINFO
*si
, UINT uiProperty
)
661 if ( uiProperty
>= MSI_MAX_PROPS
)
663 prop
= &si
->property
[uiProperty
];
664 if( prop
->vt
!= VT_LPSTR
)
666 return strdupAtoW( prop
->u
.pszVal
);
669 INT
msi_suminfo_get_int32( MSISUMMARYINFO
*si
, UINT uiProperty
)
673 if ( uiProperty
>= MSI_MAX_PROPS
)
675 prop
= &si
->property
[uiProperty
];
676 if( prop
->vt
!= VT_I4
)
681 LPWSTR
msi_get_suminfo_product( IStorage
*stg
)
687 r
= msi_get_suminfo( stg
, 0, &si
);
688 if (r
!= ERROR_SUCCESS
)
690 ERR("no summary information!\n");
693 prod
= msi_suminfo_dup_string( si
, PID_REVNUMBER
);
694 msiobj_release( &si
->hdr
);
698 UINT WINAPI
MsiSummaryInfoGetPropertyA(
699 MSIHANDLE handle
, UINT uiProperty
, PUINT puiDataType
, LPINT piValue
,
700 FILETIME
*pftValue
, LPSTR szValueBuf
, LPDWORD pcchValueBuf
)
706 TRACE("%u, %u, %p, %p, %p, %p, %p\n", handle
, uiProperty
, puiDataType
,
707 piValue
, pftValue
, szValueBuf
, pcchValueBuf
);
709 if (uiProperty
>= MSI_MAX_PROPS
)
711 if (puiDataType
) *puiDataType
= VT_EMPTY
;
712 return ERROR_UNKNOWN_PROPERTY
;
715 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
716 return ERROR_INVALID_HANDLE
;
719 str
.str
.a
= szValueBuf
;
721 r
= get_prop( si
, uiProperty
, puiDataType
, piValue
, pftValue
, &str
, pcchValueBuf
);
722 msiobj_release( &si
->hdr
);
726 UINT WINAPI
MsiSummaryInfoGetPropertyW(
727 MSIHANDLE handle
, UINT uiProperty
, PUINT puiDataType
, LPINT piValue
,
728 FILETIME
*pftValue
, LPWSTR 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
)))
744 return ERROR_INVALID_HANDLE
;
747 str
.str
.w
= szValueBuf
;
749 r
= get_prop( si
, uiProperty
, puiDataType
, piValue
, pftValue
, &str
, pcchValueBuf
);
750 msiobj_release( &si
->hdr
);
754 static UINT
set_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT type
,
755 INT iValue
, FILETIME
*pftValue
, awcstring
*str
)
760 TRACE("%p, %u, %u, %d, %p, %p\n", si
, uiProperty
, type
, iValue
, pftValue
, str
);
762 prop
= &si
->property
[uiProperty
];
764 if( prop
->vt
== VT_EMPTY
)
766 if( !si
->update_count
)
767 return ERROR_FUNCTION_FAILED
;
771 else if( prop
->vt
!= type
)
772 return ERROR_SUCCESS
;
779 prop
->u
.lVal
= iValue
;
782 prop
->u
.iVal
= iValue
;
785 prop
->u
.filetime
= *pftValue
;
790 len
= WideCharToMultiByte( CP_ACP
, 0, str
->str
.w
, -1,
791 NULL
, 0, NULL
, NULL
);
792 prop
->u
.pszVal
= msi_alloc( len
);
793 WideCharToMultiByte( CP_ACP
, 0, str
->str
.w
, -1,
794 prop
->u
.pszVal
, len
, NULL
, NULL
);
798 len
= lstrlenA( str
->str
.a
) + 1;
799 prop
->u
.pszVal
= msi_alloc( len
);
800 lstrcpyA( prop
->u
.pszVal
, str
->str
.a
);
805 return ERROR_SUCCESS
;
808 UINT WINAPI
MsiSummaryInfoSetPropertyW( MSIHANDLE handle
, UINT uiProperty
, UINT uiDataType
,
809 INT iValue
, FILETIME
*pftValue
, LPCWSTR szValue
)
815 TRACE("%u, %u, %u, %d, %p, %s\n", handle
, uiProperty
, uiDataType
, iValue
, pftValue
,
816 debugstr_w(szValue
) );
818 type
= get_type( uiProperty
);
819 if( type
== VT_EMPTY
|| type
!= uiDataType
)
820 return ERROR_DATATYPE_MISMATCH
;
822 if( uiDataType
== VT_LPSTR
&& !szValue
)
823 return ERROR_INVALID_PARAMETER
;
825 if( uiDataType
== VT_FILETIME
&& !pftValue
)
826 return ERROR_INVALID_PARAMETER
;
828 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
829 return ERROR_INVALID_HANDLE
;
834 ret
= set_prop( si
, uiProperty
, type
, iValue
, pftValue
, &str
);
835 msiobj_release( &si
->hdr
);
839 UINT WINAPI
MsiSummaryInfoSetPropertyA( MSIHANDLE handle
, UINT uiProperty
, UINT uiDataType
,
840 INT iValue
, FILETIME
*pftValue
, LPCSTR szValue
)
846 TRACE("%u, %u, %u, %d, %p, %s\n", handle
, uiProperty
, uiDataType
, iValue
, pftValue
,
847 debugstr_a(szValue
) );
849 type
= get_type( uiProperty
);
850 if( type
== VT_EMPTY
|| type
!= uiDataType
)
851 return ERROR_DATATYPE_MISMATCH
;
853 if( uiDataType
== VT_LPSTR
&& !szValue
)
854 return ERROR_INVALID_PARAMETER
;
856 if( uiDataType
== VT_FILETIME
&& !pftValue
)
857 return ERROR_INVALID_PARAMETER
;
859 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
860 return ERROR_INVALID_HANDLE
;
865 ret
= set_prop( si
, uiProperty
, uiDataType
, iValue
, pftValue
, &str
);
866 msiobj_release( &si
->hdr
);
870 static UINT
suminfo_persist( MSISUMMARYINFO
*si
)
872 UINT ret
= ERROR_FUNCTION_FAILED
;
877 grfMode
= STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
;
878 r
= IStorage_CreateStream( si
->storage
, szSumInfo
, grfMode
, 0, 0, &stm
);
881 ret
= save_summary_info( si
, stm
);
882 IStream_Release( stm
);
887 static void parse_filetime( LPCWSTR str
, FILETIME
*ft
)
890 const WCHAR
*p
= str
;
893 memset( <
, 0, sizeof(lt
) );
895 /* YYYY/MM/DD hh:mm:ss */
897 while (isspaceW( *p
)) p
++;
899 lt
.wYear
= strtolW( p
, &end
, 10 );
900 if (*end
!= '/') return;
903 lt
.wMonth
= strtolW( p
, &end
, 10 );
904 if (*end
!= '/') return;
907 lt
.wDay
= strtolW( p
, &end
, 10 );
908 if (*end
!= ' ') return;
911 while (isspaceW( *p
)) p
++;
913 lt
.wHour
= strtolW( p
, &end
, 10 );
914 if (*end
!= ':') return;
917 lt
.wMinute
= strtolW( p
, &end
, 10 );
918 if (*end
!= ':') return;
921 lt
.wSecond
= strtolW( p
, &end
, 10 );
923 TzSpecificLocalTimeToSystemTime( NULL
, <
, &utc
);
924 SystemTimeToFileTime( &utc
, ft
);
927 static UINT
parse_prop( LPCWSTR prop
, LPCWSTR value
, UINT
*pid
, INT
*int_value
,
928 FILETIME
*ft_value
, awcstring
*str_value
)
930 *pid
= atoiW( prop
);
938 *int_value
= atoiW( value
);
941 case PID_LASTPRINTED
:
943 case PID_LASTSAVE_DTM
:
944 parse_filetime( value
, ft_value
);
956 str_value
->str
.w
= value
;
957 str_value
->unicode
= TRUE
;
961 WARN("unhandled prop id %u\n", *pid
);
962 return ERROR_FUNCTION_FAILED
;
965 return ERROR_SUCCESS
;
968 UINT
msi_add_suminfo( MSIDATABASE
*db
, LPWSTR
**records
, int num_records
, int num_columns
)
974 r
= msi_get_suminfo( db
->storage
, num_records
* (num_columns
/ 2), &si
);
975 if (r
!= ERROR_SUCCESS
)
977 if (!(si
= create_suminfo( db
->storage
, num_records
* (num_columns
/ 2) )))
978 return ERROR_OUTOFMEMORY
;
982 for (i
= 0; i
< num_records
; i
++)
984 for (j
= 0; j
< num_columns
; j
+= 2)
991 r
= parse_prop( records
[i
][j
], records
[i
][j
+ 1], &pid
, &int_value
, &ft_value
, &str_value
);
992 if (r
!= ERROR_SUCCESS
)
995 r
= set_prop( si
, pid
, get_type(pid
), int_value
, &ft_value
, &str_value
);
996 if (r
!= ERROR_SUCCESS
)
1002 if (r
== ERROR_SUCCESS
)
1003 r
= suminfo_persist( si
);
1005 msiobj_release( &si
->hdr
);
1009 UINT WINAPI
MsiSummaryInfoPersist( MSIHANDLE handle
)
1014 TRACE("%d\n", handle
);
1016 si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
);
1018 return ERROR_INVALID_HANDLE
;
1020 ret
= suminfo_persist( si
);
1022 msiobj_release( &si
->hdr
);
1026 UINT WINAPI
MsiCreateTransformSummaryInfoA( MSIHANDLE db
, MSIHANDLE db_ref
, LPCSTR transform
, int error
, int validation
)
1029 WCHAR
*transformW
= NULL
;
1031 TRACE("%u, %u, %s, %d, %d\n", db
, db_ref
, debugstr_a(transform
), error
, validation
);
1033 if (transform
&& !(transformW
= strdupAtoW( transform
)))
1034 return ERROR_OUTOFMEMORY
;
1036 r
= MsiCreateTransformSummaryInfoW( db
, db_ref
, transformW
, error
, validation
);
1037 msi_free( transformW
);
1041 UINT WINAPI
MsiCreateTransformSummaryInfoW( MSIHANDLE db
, MSIHANDLE db_ref
, LPCWSTR transform
, int error
, int validation
)
1043 FIXME("%u, %u, %s, %d, %d\n", db
, db_ref
, debugstr_w(transform
), error
, validation
);
1044 return ERROR_FUNCTION_FAILED
;
1047 UINT
msi_load_suminfo_properties( MSIPACKAGE
*package
)
1049 static const WCHAR packagecodeW
[] = {'P','a','c','k','a','g','e','C','o','d','e',0};
1051 WCHAR
*package_code
;
1056 r
= msi_get_suminfo( package
->db
->storage
, 0, &si
);
1057 if (r
!= ERROR_SUCCESS
)
1059 r
= msi_get_db_suminfo( package
->db
, 0, &si
);
1060 if (r
!= ERROR_SUCCESS
)
1062 ERR("Unable to open summary information stream %u\n", r
);
1070 r
= get_prop( si
, PID_REVNUMBER
, NULL
, NULL
, NULL
, &str
, &len
);
1071 if (r
!= ERROR_MORE_DATA
)
1073 WARN("Unable to query revision number %u\n", r
);
1074 msiobj_release( &si
->hdr
);
1075 return ERROR_FUNCTION_FAILED
;
1079 if (!(package_code
= msi_alloc( len
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
1080 str
.str
.w
= package_code
;
1082 r
= get_prop( si
, PID_REVNUMBER
, NULL
, NULL
, NULL
, &str
, &len
);
1083 if (r
!= ERROR_SUCCESS
)
1085 msi_free( package_code
);
1086 msiobj_release( &si
->hdr
);
1090 r
= msi_set_property( package
->db
, packagecodeW
, package_code
, len
);
1091 msi_free( package_code
);
1094 get_prop( si
, PID_WORDCOUNT
, NULL
, &count
, NULL
, NULL
, NULL
);
1095 package
->WordCount
= count
;
1097 msiobj_release( &si
->hdr
);