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
23 #include <propvarutil.h>
25 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
45 } PROPERTYSECTIONHEADER
;
67 static HRESULT (WINAPI
*pPropVariantChangeType
)
68 (PROPVARIANT
*ppropvarDest
, REFPROPVARIANT propvarSrc
,
69 PROPVAR_CHANGE_FLAGS flags
, VARTYPE vt
);
71 #define SECT_HDR_SIZE (sizeof(PROPERTYSECTIONHEADER))
73 static void free_prop( PROPVARIANT
*prop
)
75 if (prop
->vt
== VT_LPSTR
)
76 msi_free( prop
->u
.pszVal
);
80 static void MSI_CloseSummaryInfo( MSIOBJECTHDR
*arg
)
82 MSISUMMARYINFO
*si
= (MSISUMMARYINFO
*) arg
;
85 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
86 free_prop( &si
->property
[i
] );
87 IStorage_Release( si
->storage
);
90 static UINT
get_type( UINT uiProperty
)
108 case PID_LASTPRINTED
:
110 case PID_LASTSAVE_DTM
:
122 static UINT
get_property_count( const PROPVARIANT
*property
)
128 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
129 if( property
[i
].vt
!= VT_EMPTY
)
134 static UINT
propvar_changetype(PROPVARIANT
*changed
, PROPVARIANT
*property
, VARTYPE vt
)
137 HMODULE propsys
= LoadLibraryA("propsys.dll");
138 pPropVariantChangeType
= (void *)GetProcAddress(propsys
, "PropVariantChangeType");
140 if (!pPropVariantChangeType
)
142 ERR("PropVariantChangeType function missing!\n");
143 return ERROR_FUNCTION_FAILED
;
146 hr
= pPropVariantChangeType(changed
, property
, 0, vt
);
147 return (hr
== S_OK
) ? ERROR_SUCCESS
: ERROR_FUNCTION_FAILED
;
150 /* FIXME: doesn't deal with endian conversion */
151 static void read_properties_from_data( PROPVARIANT
*prop
, LPBYTE data
, DWORD sz
)
155 PROPERTY_DATA
*propdata
;
156 PROPVARIANT property
, *ptr
;
158 PROPERTYIDOFFSET
*idofs
;
159 PROPERTYSECTIONHEADER
*section_hdr
;
161 section_hdr
= (PROPERTYSECTIONHEADER
*) &data
[0];
162 idofs
= (PROPERTYIDOFFSET
*) &data
[SECT_HDR_SIZE
];
164 /* now set all the properties */
165 for( i
= 0; i
< section_hdr
->cProperties
; i
++ )
167 if( idofs
[i
].propid
>= MSI_MAX_PROPS
)
169 ERR("Unknown property ID %d\n", idofs
[i
].propid
);
173 type
= get_type( idofs
[i
].propid
);
174 if( type
== VT_EMPTY
)
176 ERR("propid %d has unknown type\n", idofs
[i
].propid
);
180 propdata
= (PROPERTY_DATA
*) &data
[ idofs
[i
].dwOffset
];
182 /* check we don't run off the end of the data */
183 size
= sz
- idofs
[i
].dwOffset
- sizeof(DWORD
);
184 if( sizeof(DWORD
) > size
||
185 ( propdata
->type
== VT_FILETIME
&& sizeof(FILETIME
) > size
) ||
186 ( propdata
->type
== VT_LPSTR
&& (propdata
->u
.str
.len
+ sizeof(DWORD
)) > size
) )
188 ERR("not enough data\n");
192 property
.vt
= propdata
->type
;
193 if( propdata
->type
== VT_LPSTR
)
195 LPSTR str
= msi_alloc( propdata
->u
.str
.len
);
196 memcpy( str
, propdata
->u
.str
.str
, propdata
->u
.str
.len
);
197 str
[ propdata
->u
.str
.len
- 1 ] = 0;
198 property
.u
.pszVal
= str
;
200 else if( propdata
->type
== VT_FILETIME
)
201 property
.u
.filetime
= propdata
->u
.ft
;
202 else if( propdata
->type
== VT_I2
)
203 property
.u
.iVal
= propdata
->u
.i2
;
204 else if( propdata
->type
== VT_I4
)
205 property
.u
.lVal
= propdata
->u
.i4
;
207 /* check the type is the same as we expect */
208 if( type
!= propdata
->type
)
210 propvar_changetype(&changed
, &property
, type
);
216 prop
[ idofs
[i
].propid
] = *ptr
;
220 static UINT
load_summary_info( MSISUMMARYINFO
*si
, IStream
*stm
)
222 PROPERTYSETHEADER set_hdr
;
223 FORMATIDOFFSET format_hdr
;
224 PROPERTYSECTIONHEADER section_hdr
;
230 TRACE("%p %p\n", si
, stm
);
232 /* read the header */
234 r
= IStream_Read( stm
, &set_hdr
, sz
, &count
);
235 if( FAILED(r
) || count
!= sz
)
236 return ERROR_FUNCTION_FAILED
;
238 if( set_hdr
.wByteOrder
!= 0xfffe )
240 ERR("property set not big-endian %04X\n", set_hdr
.wByteOrder
);
241 return ERROR_FUNCTION_FAILED
;
244 sz
= sizeof format_hdr
;
245 r
= IStream_Read( stm
, &format_hdr
, sz
, &count
);
246 if( FAILED(r
) || count
!= sz
)
247 return ERROR_FUNCTION_FAILED
;
249 /* check the format id is correct */
250 if( !IsEqualGUID( &FMTID_SummaryInformation
, &format_hdr
.fmtid
) )
251 return ERROR_FUNCTION_FAILED
;
253 /* seek to the location of the section */
254 ofs
.QuadPart
= format_hdr
.dwOffset
;
255 r
= IStream_Seek( stm
, ofs
, STREAM_SEEK_SET
, NULL
);
257 return ERROR_FUNCTION_FAILED
;
259 /* read the section itself */
261 r
= IStream_Read( stm
, §ion_hdr
, sz
, &count
);
262 if( FAILED(r
) || count
!= sz
)
263 return ERROR_FUNCTION_FAILED
;
265 if( section_hdr
.cProperties
> MSI_MAX_PROPS
)
267 ERR("too many properties %d\n", section_hdr
.cProperties
);
268 return ERROR_FUNCTION_FAILED
;
271 data
= msi_alloc( section_hdr
.cbSection
);
273 return ERROR_FUNCTION_FAILED
;
275 memcpy( data
, §ion_hdr
, SECT_HDR_SIZE
);
277 /* read all the data in one go */
278 sz
= section_hdr
.cbSection
- SECT_HDR_SIZE
;
279 r
= IStream_Read( stm
, &data
[ SECT_HDR_SIZE
], sz
, &count
);
280 if( SUCCEEDED(r
) && count
== sz
)
281 read_properties_from_data( si
->property
, data
, sz
+ SECT_HDR_SIZE
);
283 ERR("failed to read properties %d %d\n", count
, sz
);
286 return ERROR_SUCCESS
;
289 static DWORD
write_dword( LPBYTE data
, DWORD ofs
, DWORD val
)
293 data
[ofs
++] = val
&0xff;
294 data
[ofs
++] = (val
>>8)&0xff;
295 data
[ofs
++] = (val
>>16)&0xff;
296 data
[ofs
++] = (val
>>24)&0xff;
301 static DWORD
write_filetime( LPBYTE data
, DWORD ofs
, const FILETIME
*ft
)
303 write_dword( data
, ofs
, ft
->dwLowDateTime
);
304 write_dword( data
, ofs
+ 4, ft
->dwHighDateTime
);
308 static DWORD
write_string( LPBYTE data
, DWORD ofs
, LPCSTR str
)
310 DWORD len
= lstrlenA( str
) + 1;
311 write_dword( data
, ofs
, len
);
313 memcpy( &data
[ofs
+ 4], str
, len
);
314 return (7 + len
) & ~3;
317 static UINT
write_property_to_data( const PROPVARIANT
*prop
, LPBYTE data
)
321 if( prop
->vt
== VT_EMPTY
)
325 sz
+= write_dword( data
, sz
, prop
->vt
);
329 sz
+= write_dword( data
, sz
, prop
->u
.iVal
);
332 sz
+= write_dword( data
, sz
, prop
->u
.lVal
);
335 sz
+= write_filetime( data
, sz
, &prop
->u
.filetime
);
338 sz
+= write_string( data
, sz
, prop
->u
.pszVal
);
344 static UINT
save_summary_info( const MSISUMMARYINFO
* si
, IStream
*stm
)
346 UINT ret
= ERROR_FUNCTION_FAILED
;
347 PROPERTYSETHEADER set_hdr
;
348 FORMATIDOFFSET format_hdr
;
349 PROPERTYSECTIONHEADER section_hdr
;
350 PROPERTYIDOFFSET idofs
[MSI_MAX_PROPS
];
356 /* write the header */
358 memset( &set_hdr
, 0, sz
);
359 set_hdr
.wByteOrder
= 0xfffe;
361 set_hdr
.dwOSVer
= 0x00020005; /* build 5, platform id 2 */
362 /* set_hdr.clsID is {00000000-0000-0000-0000-000000000000} */
363 set_hdr
.reserved
= 1;
364 r
= IStream_Write( stm
, &set_hdr
, sz
, &count
);
365 if( FAILED(r
) || count
!= sz
)
368 /* write the format header */
369 sz
= sizeof format_hdr
;
370 format_hdr
.fmtid
= FMTID_SummaryInformation
;
371 format_hdr
.dwOffset
= sizeof format_hdr
+ sizeof set_hdr
;
372 r
= IStream_Write( stm
, &format_hdr
, sz
, &count
);
373 if( FAILED(r
) || count
!= sz
)
376 /* add up how much space the data will take and calculate the offsets */
377 section_hdr
.cbSection
= sizeof section_hdr
;
378 section_hdr
.cbSection
+= (get_property_count( si
->property
) * sizeof idofs
[0]);
379 section_hdr
.cProperties
= 0;
380 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
382 sz
= write_property_to_data( &si
->property
[i
], NULL
);
385 idofs
[ section_hdr
.cProperties
].propid
= i
;
386 idofs
[ section_hdr
.cProperties
].dwOffset
= section_hdr
.cbSection
;
387 section_hdr
.cProperties
++;
388 section_hdr
.cbSection
+= sz
;
391 data
= msi_alloc_zero( section_hdr
.cbSection
);
394 memcpy( &data
[sz
], §ion_hdr
, sizeof section_hdr
);
395 sz
+= sizeof section_hdr
;
397 memcpy( &data
[sz
], idofs
, section_hdr
.cProperties
* sizeof idofs
[0] );
398 sz
+= section_hdr
.cProperties
* sizeof idofs
[0];
400 /* write out the data */
401 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
402 sz
+= write_property_to_data( &si
->property
[i
], &data
[sz
] );
404 r
= IStream_Write( stm
, data
, sz
, &count
);
406 if( FAILED(r
) || count
!= sz
)
409 return ERROR_SUCCESS
;
412 static MSISUMMARYINFO
*create_suminfo( IStorage
*stg
, UINT update_count
)
416 if (!(si
= alloc_msiobject( MSIHANDLETYPE_SUMMARYINFO
, sizeof(MSISUMMARYINFO
), MSI_CloseSummaryInfo
)))
419 si
->update_count
= update_count
;
420 IStorage_AddRef( stg
);
426 UINT
msi_get_suminfo( IStorage
*stg
, UINT uiUpdateCount
, MSISUMMARYINFO
**ret
)
433 TRACE("%p, %u\n", stg
, uiUpdateCount
);
435 if (!(si
= create_suminfo( stg
, uiUpdateCount
))) return ERROR_OUTOFMEMORY
;
437 hr
= IStorage_OpenStream( si
->storage
, szSumInfo
, 0, STGM_READ
|STGM_SHARE_EXCLUSIVE
, 0, &stm
);
440 msiobj_release( &si
->hdr
);
441 return ERROR_FUNCTION_FAILED
;
444 r
= load_summary_info( si
, stm
);
445 IStream_Release( stm
);
446 if (r
!= ERROR_SUCCESS
)
448 msiobj_release( &si
->hdr
);
453 return ERROR_SUCCESS
;
456 UINT
msi_get_db_suminfo( MSIDATABASE
*db
, UINT uiUpdateCount
, MSISUMMARYINFO
**ret
)
462 if (!(si
= create_suminfo( db
->storage
, uiUpdateCount
))) return ERROR_OUTOFMEMORY
;
464 r
= msi_get_stream( db
, szSumInfo
, &stm
);
465 if (r
!= ERROR_SUCCESS
)
467 msiobj_release( &si
->hdr
);
471 r
= load_summary_info( si
, stm
);
472 IStream_Release( stm
);
473 if (r
!= ERROR_SUCCESS
)
475 msiobj_release( &si
->hdr
);
480 return ERROR_SUCCESS
;
483 UINT WINAPI
MsiGetSummaryInformationW( MSIHANDLE hDatabase
,
484 LPCWSTR szDatabase
, UINT uiUpdateCount
, MSIHANDLE
*pHandle
)
490 TRACE("%d %s %d %p\n", hDatabase
, debugstr_w(szDatabase
),
491 uiUpdateCount
, pHandle
);
494 return ERROR_INVALID_PARAMETER
;
496 if( szDatabase
&& szDatabase
[0] )
498 LPCWSTR persist
= uiUpdateCount
? MSIDBOPEN_TRANSACT
: MSIDBOPEN_READONLY
;
500 ret
= MSI_OpenDatabaseW( szDatabase
, persist
, &db
);
501 if( ret
!= ERROR_SUCCESS
)
506 db
= msihandle2msiinfo( hDatabase
, MSIHANDLETYPE_DATABASE
);
510 IWineMsiRemoteDatabase
*remote_database
;
512 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hDatabase
);
513 if ( !remote_database
)
514 return ERROR_INVALID_HANDLE
;
516 hr
= IWineMsiRemoteDatabase_GetSummaryInformation( remote_database
,
517 uiUpdateCount
, pHandle
);
518 IWineMsiRemoteDatabase_Release( remote_database
);
522 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
523 return HRESULT_CODE(hr
);
525 return ERROR_FUNCTION_FAILED
;
528 return ERROR_SUCCESS
;
532 ret
= msi_get_suminfo( db
->storage
, uiUpdateCount
, &si
);
533 if (ret
!= ERROR_SUCCESS
)
534 ret
= msi_get_db_suminfo( db
, uiUpdateCount
, &si
);
535 if (ret
!= ERROR_SUCCESS
)
537 if ((si
= create_suminfo( db
->storage
, uiUpdateCount
)))
541 if (ret
== ERROR_SUCCESS
)
543 *pHandle
= alloc_msihandle( &si
->hdr
);
547 ret
= ERROR_NOT_ENOUGH_MEMORY
;
548 msiobj_release( &si
->hdr
);
551 msiobj_release( &db
->hdr
);
555 UINT WINAPI
MsiGetSummaryInformationA(MSIHANDLE hDatabase
,
556 LPCSTR szDatabase
, UINT uiUpdateCount
, MSIHANDLE
*pHandle
)
558 LPWSTR szwDatabase
= NULL
;
561 TRACE("%d %s %d %p\n", hDatabase
, debugstr_a(szDatabase
),
562 uiUpdateCount
, pHandle
);
566 szwDatabase
= strdupAtoW( szDatabase
);
568 return ERROR_FUNCTION_FAILED
;
571 ret
= MsiGetSummaryInformationW(hDatabase
, szwDatabase
, uiUpdateCount
, pHandle
);
573 msi_free( szwDatabase
);
578 UINT WINAPI
MsiSummaryInfoGetPropertyCount(MSIHANDLE hSummaryInfo
, PUINT pCount
)
582 TRACE("%d %p\n", hSummaryInfo
, pCount
);
584 si
= msihandle2msiinfo( hSummaryInfo
, MSIHANDLETYPE_SUMMARYINFO
);
586 return ERROR_INVALID_HANDLE
;
589 *pCount
= get_property_count( si
->property
);
590 msiobj_release( &si
->hdr
);
592 return ERROR_SUCCESS
;
595 static UINT
get_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT
*puiDataType
, INT
*piValue
,
596 FILETIME
*pftValue
, awstring
*str
, DWORD
*pcchValueBuf
)
599 UINT ret
= ERROR_SUCCESS
;
601 prop
= &si
->property
[uiProperty
];
604 *puiDataType
= prop
->vt
;
610 *piValue
= prop
->u
.iVal
;
614 *piValue
= prop
->u
.lVal
;
623 len
= MultiByteToWideChar( CP_ACP
, 0, prop
->u
.pszVal
, -1, NULL
, 0 ) - 1;
624 MultiByteToWideChar( CP_ACP
, 0, prop
->u
.pszVal
, -1, str
->str
.w
, *pcchValueBuf
);
628 len
= lstrlenA( prop
->u
.pszVal
);
630 lstrcpynA(str
->str
.a
, prop
->u
.pszVal
, *pcchValueBuf
);
632 if (len
>= *pcchValueBuf
)
633 ret
= ERROR_MORE_DATA
;
639 *pftValue
= prop
->u
.filetime
;
644 FIXME("Unknown property variant type\n");
650 LPWSTR
msi_suminfo_dup_string( MSISUMMARYINFO
*si
, UINT uiProperty
)
654 if ( uiProperty
>= MSI_MAX_PROPS
)
656 prop
= &si
->property
[uiProperty
];
657 if( prop
->vt
!= VT_LPSTR
)
659 return strdupAtoW( prop
->u
.pszVal
);
662 INT
msi_suminfo_get_int32( MSISUMMARYINFO
*si
, UINT uiProperty
)
666 if ( uiProperty
>= MSI_MAX_PROPS
)
668 prop
= &si
->property
[uiProperty
];
669 if( prop
->vt
!= VT_I4
)
674 LPWSTR
msi_get_suminfo_product( IStorage
*stg
)
680 r
= msi_get_suminfo( stg
, 0, &si
);
681 if (r
!= ERROR_SUCCESS
)
683 ERR("no summary information!\n");
686 prod
= msi_suminfo_dup_string( si
, PID_REVNUMBER
);
687 msiobj_release( &si
->hdr
);
691 UINT WINAPI
MsiSummaryInfoGetPropertyA(
692 MSIHANDLE handle
, UINT uiProperty
, PUINT puiDataType
, LPINT piValue
,
693 FILETIME
*pftValue
, LPSTR szValueBuf
, LPDWORD pcchValueBuf
)
699 TRACE("%u, %u, %p, %p, %p, %p, %p\n", handle
, uiProperty
, puiDataType
,
700 piValue
, pftValue
, szValueBuf
, pcchValueBuf
);
702 if (uiProperty
>= MSI_MAX_PROPS
)
704 if (puiDataType
) *puiDataType
= VT_EMPTY
;
705 return ERROR_UNKNOWN_PROPERTY
;
708 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
709 return ERROR_INVALID_HANDLE
;
712 str
.str
.a
= szValueBuf
;
714 r
= get_prop( si
, uiProperty
, puiDataType
, piValue
, pftValue
, &str
, pcchValueBuf
);
715 msiobj_release( &si
->hdr
);
719 UINT WINAPI
MsiSummaryInfoGetPropertyW(
720 MSIHANDLE handle
, UINT uiProperty
, PUINT puiDataType
, LPINT piValue
,
721 FILETIME
*pftValue
, LPWSTR szValueBuf
, LPDWORD pcchValueBuf
)
727 TRACE("%u, %u, %p, %p, %p, %p, %p\n", handle
, uiProperty
, puiDataType
,
728 piValue
, pftValue
, szValueBuf
, pcchValueBuf
);
730 if (uiProperty
>= MSI_MAX_PROPS
)
732 if (puiDataType
) *puiDataType
= VT_EMPTY
;
733 return ERROR_UNKNOWN_PROPERTY
;
736 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
737 return ERROR_INVALID_HANDLE
;
740 str
.str
.w
= szValueBuf
;
742 r
= get_prop( si
, uiProperty
, puiDataType
, piValue
, pftValue
, &str
, pcchValueBuf
);
743 msiobj_release( &si
->hdr
);
747 static UINT
set_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT type
,
748 INT iValue
, FILETIME
*pftValue
, awcstring
*str
)
753 TRACE("%p, %u, %u, %d, %p, %p\n", si
, uiProperty
, type
, iValue
, pftValue
, str
);
755 prop
= &si
->property
[uiProperty
];
757 if( prop
->vt
== VT_EMPTY
)
759 if( !si
->update_count
)
760 return ERROR_FUNCTION_FAILED
;
764 else if( prop
->vt
!= type
)
765 return ERROR_SUCCESS
;
772 prop
->u
.lVal
= iValue
;
775 prop
->u
.iVal
= iValue
;
778 prop
->u
.filetime
= *pftValue
;
783 len
= WideCharToMultiByte( CP_ACP
, 0, str
->str
.w
, -1,
784 NULL
, 0, NULL
, NULL
);
785 prop
->u
.pszVal
= msi_alloc( len
);
786 WideCharToMultiByte( CP_ACP
, 0, str
->str
.w
, -1,
787 prop
->u
.pszVal
, len
, NULL
, NULL
);
791 len
= lstrlenA( str
->str
.a
) + 1;
792 prop
->u
.pszVal
= msi_alloc( len
);
793 lstrcpyA( prop
->u
.pszVal
, str
->str
.a
);
798 return ERROR_SUCCESS
;
801 UINT WINAPI
MsiSummaryInfoSetPropertyW( MSIHANDLE handle
, UINT uiProperty
, UINT uiDataType
,
802 INT iValue
, FILETIME
*pftValue
, LPCWSTR szValue
)
808 TRACE("%u, %u, %u, %d, %p, %s\n", handle
, uiProperty
, uiDataType
, iValue
, pftValue
,
809 debugstr_w(szValue
) );
811 type
= get_type( uiProperty
);
812 if( type
== VT_EMPTY
|| type
!= uiDataType
)
813 return ERROR_DATATYPE_MISMATCH
;
815 if( uiDataType
== VT_LPSTR
&& !szValue
)
816 return ERROR_INVALID_PARAMETER
;
818 if( uiDataType
== VT_FILETIME
&& !pftValue
)
819 return ERROR_INVALID_PARAMETER
;
821 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
822 return ERROR_INVALID_HANDLE
;
827 ret
= set_prop( si
, uiProperty
, type
, iValue
, pftValue
, &str
);
828 msiobj_release( &si
->hdr
);
832 UINT WINAPI
MsiSummaryInfoSetPropertyA( MSIHANDLE handle
, UINT uiProperty
, UINT uiDataType
,
833 INT iValue
, FILETIME
*pftValue
, LPCSTR szValue
)
839 TRACE("%u, %u, %u, %d, %p, %s\n", handle
, uiProperty
, uiDataType
, iValue
, pftValue
,
840 debugstr_a(szValue
) );
842 type
= get_type( uiProperty
);
843 if( type
== VT_EMPTY
|| type
!= uiDataType
)
844 return ERROR_DATATYPE_MISMATCH
;
846 if( uiDataType
== VT_LPSTR
&& !szValue
)
847 return ERROR_INVALID_PARAMETER
;
849 if( uiDataType
== VT_FILETIME
&& !pftValue
)
850 return ERROR_INVALID_PARAMETER
;
852 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
853 return ERROR_INVALID_HANDLE
;
858 ret
= set_prop( si
, uiProperty
, uiDataType
, iValue
, pftValue
, &str
);
859 msiobj_release( &si
->hdr
);
863 static UINT
suminfo_persist( MSISUMMARYINFO
*si
)
865 UINT ret
= ERROR_FUNCTION_FAILED
;
870 grfMode
= STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
;
871 r
= IStorage_CreateStream( si
->storage
, szSumInfo
, grfMode
, 0, 0, &stm
);
874 ret
= save_summary_info( si
, stm
);
875 IStream_Release( stm
);
880 static void parse_filetime( LPCWSTR str
, FILETIME
*ft
)
883 const WCHAR
*p
= str
;
886 memset( <
, 0, sizeof(lt
) );
888 /* YYYY/MM/DD hh:mm:ss */
890 while (isspaceW( *p
)) p
++;
892 lt
.wYear
= strtolW( p
, &end
, 10 );
893 if (*end
!= '/') return;
896 lt
.wMonth
= strtolW( p
, &end
, 10 );
897 if (*end
!= '/') return;
900 lt
.wDay
= strtolW( p
, &end
, 10 );
901 if (*end
!= ' ') return;
904 while (isspaceW( *p
)) p
++;
906 lt
.wHour
= strtolW( p
, &end
, 10 );
907 if (*end
!= ':') return;
910 lt
.wMinute
= strtolW( p
, &end
, 10 );
911 if (*end
!= ':') return;
914 lt
.wSecond
= strtolW( p
, &end
, 10 );
916 TzSpecificLocalTimeToSystemTime( NULL
, <
, &utc
);
917 SystemTimeToFileTime( &utc
, ft
);
920 static UINT
parse_prop( LPCWSTR prop
, LPCWSTR value
, UINT
*pid
, INT
*int_value
,
921 FILETIME
*ft_value
, awcstring
*str_value
)
923 *pid
= atoiW( prop
);
931 *int_value
= atoiW( value
);
934 case PID_LASTPRINTED
:
936 case PID_LASTSAVE_DTM
:
937 parse_filetime( value
, ft_value
);
949 str_value
->str
.w
= value
;
950 str_value
->unicode
= TRUE
;
954 WARN("unhandled prop id %u\n", *pid
);
955 return ERROR_FUNCTION_FAILED
;
958 return ERROR_SUCCESS
;
961 UINT
msi_add_suminfo( MSIDATABASE
*db
, LPWSTR
**records
, int num_records
, int num_columns
)
967 r
= msi_get_suminfo( db
->storage
, num_records
* (num_columns
/ 2), &si
);
968 if (r
!= ERROR_SUCCESS
)
970 if (!(si
= create_suminfo( db
->storage
, num_records
* (num_columns
/ 2) )))
971 return ERROR_OUTOFMEMORY
;
975 for (i
= 0; i
< num_records
; i
++)
977 for (j
= 0; j
< num_columns
; j
+= 2)
984 r
= parse_prop( records
[i
][j
], records
[i
][j
+ 1], &pid
, &int_value
, &ft_value
, &str_value
);
985 if (r
!= ERROR_SUCCESS
)
988 r
= set_prop( si
, pid
, get_type(pid
), int_value
, &ft_value
, &str_value
);
989 if (r
!= ERROR_SUCCESS
)
995 if (r
== ERROR_SUCCESS
)
996 r
= suminfo_persist( si
);
998 msiobj_release( &si
->hdr
);
1002 UINT WINAPI
MsiSummaryInfoPersist( MSIHANDLE handle
)
1007 TRACE("%d\n", handle
);
1009 si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
);
1011 return ERROR_INVALID_HANDLE
;
1013 ret
= suminfo_persist( si
);
1015 msiobj_release( &si
->hdr
);
1019 UINT WINAPI
MsiCreateTransformSummaryInfoA( MSIHANDLE db
, MSIHANDLE db_ref
, LPCSTR transform
, int error
, int validation
)
1022 WCHAR
*transformW
= NULL
;
1024 TRACE("%u, %u, %s, %d, %d\n", db
, db_ref
, debugstr_a(transform
), error
, validation
);
1026 if (transform
&& !(transformW
= strdupAtoW( transform
)))
1027 return ERROR_OUTOFMEMORY
;
1029 r
= MsiCreateTransformSummaryInfoW( db
, db_ref
, transformW
, error
, validation
);
1030 msi_free( transformW
);
1034 UINT WINAPI
MsiCreateTransformSummaryInfoW( MSIHANDLE db
, MSIHANDLE db_ref
, LPCWSTR transform
, int error
, int validation
)
1036 FIXME("%u, %u, %s, %d, %d\n", db
, db_ref
, debugstr_w(transform
), error
, validation
);
1037 return ERROR_FUNCTION_FAILED
;
1040 UINT
msi_load_suminfo_properties( MSIPACKAGE
*package
)
1042 static const WCHAR packagecodeW
[] = {'P','a','c','k','a','g','e','C','o','d','e',0};
1044 WCHAR
*package_code
;
1049 r
= msi_get_suminfo( package
->db
->storage
, 0, &si
);
1050 if (r
!= ERROR_SUCCESS
)
1052 r
= msi_get_db_suminfo( package
->db
, 0, &si
);
1053 if (r
!= ERROR_SUCCESS
)
1055 ERR("Unable to open summary information stream %u\n", r
);
1063 r
= get_prop( si
, PID_REVNUMBER
, NULL
, NULL
, NULL
, &str
, &len
);
1064 if (r
!= ERROR_MORE_DATA
)
1066 WARN("Unable to query revision number %u\n", r
);
1067 msiobj_release( &si
->hdr
);
1068 return ERROR_FUNCTION_FAILED
;
1072 if (!(package_code
= msi_alloc( len
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
1073 str
.str
.w
= package_code
;
1075 r
= get_prop( si
, PID_REVNUMBER
, NULL
, NULL
, NULL
, &str
, &len
);
1076 if (r
!= ERROR_SUCCESS
)
1078 msi_free( package_code
);
1079 msiobj_release( &si
->hdr
);
1083 r
= msi_set_property( package
->db
, packagecodeW
, package_code
, len
);
1084 msi_free( package_code
);
1087 get_prop( si
, PID_WORDCOUNT
, NULL
, &count
, NULL
, NULL
, NULL
);
1088 package
->WordCount
= count
;
1090 msiobj_release( &si
->hdr
);