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 #include <propvarutil.h>
26 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
46 } PROPERTYSECTIONHEADER
;
68 static HRESULT (WINAPI
*pPropVariantChangeType
)
69 (PROPVARIANT
*ppropvarDest
, REFPROPVARIANT propvarSrc
,
70 PROPVAR_CHANGE_FLAGS flags
, VARTYPE vt
);
72 #define SECT_HDR_SIZE (sizeof(PROPERTYSECTIONHEADER))
74 static void free_prop( PROPVARIANT
*prop
)
76 if (prop
->vt
== VT_LPSTR
)
77 msi_free( prop
->u
.pszVal
);
81 static void MSI_CloseSummaryInfo( MSIOBJECTHDR
*arg
)
83 MSISUMMARYINFO
*si
= (MSISUMMARYINFO
*) arg
;
86 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
87 free_prop( &si
->property
[i
] );
88 IStorage_Release( si
->storage
);
91 static UINT
get_type( UINT uiProperty
)
109 case PID_LASTPRINTED
:
111 case PID_LASTSAVE_DTM
:
123 static UINT
get_property_count( const PROPVARIANT
*property
)
129 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
130 if( property
[i
].vt
!= VT_EMPTY
)
135 static UINT
propvar_changetype(PROPVARIANT
*changed
, PROPVARIANT
*property
, VARTYPE vt
)
138 HMODULE propsys
= LoadLibraryA("propsys.dll");
139 pPropVariantChangeType
= (void *)GetProcAddress(propsys
, "PropVariantChangeType");
141 if (!pPropVariantChangeType
)
143 ERR("PropVariantChangeType function missing!\n");
144 return ERROR_FUNCTION_FAILED
;
147 hr
= pPropVariantChangeType(changed
, property
, 0, vt
);
148 return (hr
== S_OK
) ? ERROR_SUCCESS
: ERROR_FUNCTION_FAILED
;
151 /* FIXME: doesn't deal with endian conversion */
152 static void read_properties_from_data( PROPVARIANT
*prop
, LPBYTE data
, DWORD sz
)
156 PROPERTY_DATA
*propdata
;
157 PROPVARIANT property
, *ptr
;
159 PROPERTYIDOFFSET
*idofs
;
160 PROPERTYSECTIONHEADER
*section_hdr
;
162 section_hdr
= (PROPERTYSECTIONHEADER
*) &data
[0];
163 idofs
= (PROPERTYIDOFFSET
*) &data
[SECT_HDR_SIZE
];
165 /* now set all the properties */
166 for( i
= 0; i
< section_hdr
->cProperties
; i
++ )
168 if( idofs
[i
].propid
>= MSI_MAX_PROPS
)
170 ERR("Unknown property ID %d\n", idofs
[i
].propid
);
174 type
= get_type( idofs
[i
].propid
);
175 if( type
== VT_EMPTY
)
177 ERR("propid %d has unknown type\n", idofs
[i
].propid
);
181 propdata
= (PROPERTY_DATA
*) &data
[ idofs
[i
].dwOffset
];
183 /* check we don't run off the end of the data */
184 size
= sz
- idofs
[i
].dwOffset
- sizeof(DWORD
);
185 if( sizeof(DWORD
) > size
||
186 ( propdata
->type
== VT_FILETIME
&& sizeof(FILETIME
) > size
) ||
187 ( propdata
->type
== VT_LPSTR
&& (propdata
->u
.str
.len
+ sizeof(DWORD
)) > size
) )
189 ERR("not enough data\n");
193 property
.vt
= propdata
->type
;
194 if( propdata
->type
== VT_LPSTR
)
196 LPSTR str
= msi_alloc( propdata
->u
.str
.len
);
197 memcpy( str
, propdata
->u
.str
.str
, propdata
->u
.str
.len
);
198 str
[ propdata
->u
.str
.len
- 1 ] = 0;
199 property
.u
.pszVal
= str
;
201 else if( propdata
->type
== VT_FILETIME
)
202 property
.u
.filetime
= propdata
->u
.ft
;
203 else if( propdata
->type
== VT_I2
)
204 property
.u
.iVal
= propdata
->u
.i2
;
205 else if( propdata
->type
== VT_I4
)
206 property
.u
.lVal
= propdata
->u
.i4
;
208 /* check the type is the same as we expect */
209 if( type
!= propdata
->type
)
211 propvar_changetype(&changed
, &property
, type
);
217 prop
[ idofs
[i
].propid
] = *ptr
;
221 static UINT
load_summary_info( MSISUMMARYINFO
*si
, IStream
*stm
)
223 PROPERTYSETHEADER set_hdr
;
224 FORMATIDOFFSET format_hdr
;
225 PROPERTYSECTIONHEADER section_hdr
;
231 TRACE("%p %p\n", si
, stm
);
233 /* read the header */
235 r
= IStream_Read( stm
, &set_hdr
, sz
, &count
);
236 if( FAILED(r
) || count
!= sz
)
237 return ERROR_FUNCTION_FAILED
;
239 if( set_hdr
.wByteOrder
!= 0xfffe )
241 ERR("property set not big-endian %04X\n", set_hdr
.wByteOrder
);
242 return ERROR_FUNCTION_FAILED
;
245 sz
= sizeof format_hdr
;
246 r
= IStream_Read( stm
, &format_hdr
, sz
, &count
);
247 if( FAILED(r
) || count
!= sz
)
248 return ERROR_FUNCTION_FAILED
;
250 /* check the format id is correct */
251 if( !IsEqualGUID( &FMTID_SummaryInformation
, &format_hdr
.fmtid
) )
252 return ERROR_FUNCTION_FAILED
;
254 /* seek to the location of the section */
255 ofs
.QuadPart
= format_hdr
.dwOffset
;
256 r
= IStream_Seek( stm
, ofs
, STREAM_SEEK_SET
, NULL
);
258 return ERROR_FUNCTION_FAILED
;
260 /* read the section itself */
262 r
= IStream_Read( stm
, §ion_hdr
, sz
, &count
);
263 if( FAILED(r
) || count
!= sz
)
264 return ERROR_FUNCTION_FAILED
;
266 if( section_hdr
.cProperties
> MSI_MAX_PROPS
)
268 ERR("too many properties %d\n", section_hdr
.cProperties
);
269 return ERROR_FUNCTION_FAILED
;
272 data
= msi_alloc( section_hdr
.cbSection
);
274 return ERROR_FUNCTION_FAILED
;
276 memcpy( data
, §ion_hdr
, SECT_HDR_SIZE
);
278 /* read all the data in one go */
279 sz
= section_hdr
.cbSection
- SECT_HDR_SIZE
;
280 r
= IStream_Read( stm
, &data
[ SECT_HDR_SIZE
], sz
, &count
);
281 if( SUCCEEDED(r
) && count
== sz
)
282 read_properties_from_data( si
->property
, data
, sz
+ SECT_HDR_SIZE
);
284 ERR("failed to read properties %d %d\n", count
, sz
);
287 return ERROR_SUCCESS
;
290 static DWORD
write_dword( LPBYTE data
, DWORD ofs
, DWORD val
)
294 data
[ofs
++] = val
&0xff;
295 data
[ofs
++] = (val
>>8)&0xff;
296 data
[ofs
++] = (val
>>16)&0xff;
297 data
[ofs
++] = (val
>>24)&0xff;
302 static DWORD
write_filetime( LPBYTE data
, DWORD ofs
, const FILETIME
*ft
)
304 write_dword( data
, ofs
, ft
->dwLowDateTime
);
305 write_dword( data
, ofs
+ 4, ft
->dwHighDateTime
);
309 static DWORD
write_string( LPBYTE data
, DWORD ofs
, LPCSTR str
)
311 DWORD len
= lstrlenA( str
) + 1;
312 write_dword( data
, ofs
, len
);
314 memcpy( &data
[ofs
+ 4], str
, len
);
315 return (7 + len
) & ~3;
318 static UINT
write_property_to_data( const PROPVARIANT
*prop
, LPBYTE data
)
322 if( prop
->vt
== VT_EMPTY
)
326 sz
+= write_dword( data
, sz
, prop
->vt
);
330 sz
+= write_dword( data
, sz
, prop
->u
.iVal
);
333 sz
+= write_dword( data
, sz
, prop
->u
.lVal
);
336 sz
+= write_filetime( data
, sz
, &prop
->u
.filetime
);
339 sz
+= write_string( data
, sz
, prop
->u
.pszVal
);
345 static UINT
save_summary_info( const MSISUMMARYINFO
* si
, IStream
*stm
)
347 UINT ret
= ERROR_FUNCTION_FAILED
;
348 PROPERTYSETHEADER set_hdr
;
349 FORMATIDOFFSET format_hdr
;
350 PROPERTYSECTIONHEADER section_hdr
;
351 PROPERTYIDOFFSET idofs
[MSI_MAX_PROPS
];
357 /* write the header */
359 memset( &set_hdr
, 0, sz
);
360 set_hdr
.wByteOrder
= 0xfffe;
362 set_hdr
.dwOSVer
= 0x00020005; /* build 5, platform id 2 */
363 /* set_hdr.clsID is {00000000-0000-0000-0000-000000000000} */
364 set_hdr
.reserved
= 1;
365 r
= IStream_Write( stm
, &set_hdr
, sz
, &count
);
366 if( FAILED(r
) || count
!= sz
)
369 /* write the format header */
370 sz
= sizeof format_hdr
;
371 format_hdr
.fmtid
= FMTID_SummaryInformation
;
372 format_hdr
.dwOffset
= sizeof format_hdr
+ sizeof set_hdr
;
373 r
= IStream_Write( stm
, &format_hdr
, sz
, &count
);
374 if( FAILED(r
) || count
!= sz
)
377 /* add up how much space the data will take and calculate the offsets */
378 section_hdr
.cbSection
= sizeof section_hdr
;
379 section_hdr
.cbSection
+= (get_property_count( si
->property
) * sizeof idofs
[0]);
380 section_hdr
.cProperties
= 0;
381 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
383 sz
= write_property_to_data( &si
->property
[i
], NULL
);
386 idofs
[ section_hdr
.cProperties
].propid
= i
;
387 idofs
[ section_hdr
.cProperties
].dwOffset
= section_hdr
.cbSection
;
388 section_hdr
.cProperties
++;
389 section_hdr
.cbSection
+= sz
;
392 data
= msi_alloc_zero( section_hdr
.cbSection
);
395 memcpy( &data
[sz
], §ion_hdr
, sizeof section_hdr
);
396 sz
+= sizeof section_hdr
;
398 memcpy( &data
[sz
], idofs
, section_hdr
.cProperties
* sizeof idofs
[0] );
399 sz
+= section_hdr
.cProperties
* sizeof idofs
[0];
401 /* write out the data */
402 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
403 sz
+= write_property_to_data( &si
->property
[i
], &data
[sz
] );
405 r
= IStream_Write( stm
, data
, sz
, &count
);
407 if( FAILED(r
) || count
!= sz
)
410 return ERROR_SUCCESS
;
413 static MSISUMMARYINFO
*create_suminfo( IStorage
*stg
, UINT update_count
)
417 if (!(si
= alloc_msiobject( MSIHANDLETYPE_SUMMARYINFO
, sizeof(MSISUMMARYINFO
), MSI_CloseSummaryInfo
)))
420 si
->update_count
= update_count
;
421 IStorage_AddRef( stg
);
427 UINT
msi_get_suminfo( IStorage
*stg
, UINT uiUpdateCount
, MSISUMMARYINFO
**ret
)
434 TRACE("%p, %u\n", stg
, uiUpdateCount
);
436 if (!(si
= create_suminfo( stg
, uiUpdateCount
))) return ERROR_OUTOFMEMORY
;
438 hr
= IStorage_OpenStream( si
->storage
, szSumInfo
, 0, STGM_READ
|STGM_SHARE_EXCLUSIVE
, 0, &stm
);
441 msiobj_release( &si
->hdr
);
442 return ERROR_FUNCTION_FAILED
;
445 r
= load_summary_info( si
, stm
);
446 IStream_Release( stm
);
447 if (r
!= ERROR_SUCCESS
)
449 msiobj_release( &si
->hdr
);
454 return ERROR_SUCCESS
;
457 UINT
msi_get_db_suminfo( MSIDATABASE
*db
, UINT uiUpdateCount
, MSISUMMARYINFO
**ret
)
463 if (!(si
= create_suminfo( db
->storage
, uiUpdateCount
))) return ERROR_OUTOFMEMORY
;
465 r
= msi_get_stream( db
, szSumInfo
, &stm
);
466 if (r
!= ERROR_SUCCESS
)
468 msiobj_release( &si
->hdr
);
472 r
= load_summary_info( si
, stm
);
473 IStream_Release( stm
);
474 if (r
!= ERROR_SUCCESS
)
476 msiobj_release( &si
->hdr
);
481 return ERROR_SUCCESS
;
484 UINT WINAPI
MsiGetSummaryInformationW( MSIHANDLE hDatabase
,
485 LPCWSTR szDatabase
, UINT uiUpdateCount
, MSIHANDLE
*pHandle
)
491 TRACE("%d %s %d %p\n", hDatabase
, debugstr_w(szDatabase
),
492 uiUpdateCount
, pHandle
);
495 return ERROR_INVALID_PARAMETER
;
497 if( szDatabase
&& szDatabase
[0] )
499 LPCWSTR persist
= uiUpdateCount
? MSIDBOPEN_TRANSACT
: MSIDBOPEN_READONLY
;
501 ret
= MSI_OpenDatabaseW( szDatabase
, persist
, &db
);
502 if( ret
!= ERROR_SUCCESS
)
507 db
= msihandle2msiinfo( hDatabase
, MSIHANDLETYPE_DATABASE
);
511 IWineMsiRemoteDatabase
*remote_database
;
513 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hDatabase
);
514 if ( !remote_database
)
515 return ERROR_INVALID_HANDLE
;
517 hr
= IWineMsiRemoteDatabase_GetSummaryInformation( remote_database
,
518 uiUpdateCount
, pHandle
);
519 IWineMsiRemoteDatabase_Release( remote_database
);
523 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
524 return HRESULT_CODE(hr
);
526 return ERROR_FUNCTION_FAILED
;
529 return ERROR_SUCCESS
;
533 ret
= msi_get_suminfo( db
->storage
, uiUpdateCount
, &si
);
534 if (ret
!= ERROR_SUCCESS
)
535 ret
= msi_get_db_suminfo( db
, uiUpdateCount
, &si
);
536 if (ret
!= ERROR_SUCCESS
)
538 if ((si
= create_suminfo( db
->storage
, uiUpdateCount
)))
542 if (ret
== ERROR_SUCCESS
)
544 *pHandle
= alloc_msihandle( &si
->hdr
);
548 ret
= ERROR_NOT_ENOUGH_MEMORY
;
549 msiobj_release( &si
->hdr
);
552 msiobj_release( &db
->hdr
);
556 UINT WINAPI
MsiGetSummaryInformationA(MSIHANDLE hDatabase
,
557 LPCSTR szDatabase
, UINT uiUpdateCount
, MSIHANDLE
*pHandle
)
559 LPWSTR szwDatabase
= NULL
;
562 TRACE("%d %s %d %p\n", hDatabase
, debugstr_a(szDatabase
),
563 uiUpdateCount
, pHandle
);
567 szwDatabase
= strdupAtoW( szDatabase
);
569 return ERROR_FUNCTION_FAILED
;
572 ret
= MsiGetSummaryInformationW(hDatabase
, szwDatabase
, uiUpdateCount
, pHandle
);
574 msi_free( szwDatabase
);
579 UINT WINAPI
MsiSummaryInfoGetPropertyCount(MSIHANDLE hSummaryInfo
, PUINT pCount
)
583 TRACE("%d %p\n", hSummaryInfo
, pCount
);
585 si
= msihandle2msiinfo( hSummaryInfo
, MSIHANDLETYPE_SUMMARYINFO
);
587 return ERROR_INVALID_HANDLE
;
590 *pCount
= get_property_count( si
->property
);
591 msiobj_release( &si
->hdr
);
593 return ERROR_SUCCESS
;
596 static UINT
get_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT
*puiDataType
, INT
*piValue
,
597 FILETIME
*pftValue
, awstring
*str
, DWORD
*pcchValueBuf
)
600 UINT ret
= ERROR_SUCCESS
;
602 prop
= &si
->property
[uiProperty
];
605 *puiDataType
= prop
->vt
;
611 *piValue
= prop
->u
.iVal
;
615 *piValue
= prop
->u
.lVal
;
624 len
= MultiByteToWideChar( CP_ACP
, 0, prop
->u
.pszVal
, -1, NULL
, 0 ) - 1;
625 MultiByteToWideChar( CP_ACP
, 0, prop
->u
.pszVal
, -1, str
->str
.w
, *pcchValueBuf
);
629 len
= lstrlenA( prop
->u
.pszVal
);
631 lstrcpynA(str
->str
.a
, prop
->u
.pszVal
, *pcchValueBuf
);
633 if (len
>= *pcchValueBuf
)
634 ret
= ERROR_MORE_DATA
;
640 *pftValue
= prop
->u
.filetime
;
645 FIXME("Unknown property variant type\n");
651 LPWSTR
msi_suminfo_dup_string( MSISUMMARYINFO
*si
, UINT uiProperty
)
655 if ( uiProperty
>= MSI_MAX_PROPS
)
657 prop
= &si
->property
[uiProperty
];
658 if( prop
->vt
!= VT_LPSTR
)
660 return strdupAtoW( prop
->u
.pszVal
);
663 INT
msi_suminfo_get_int32( MSISUMMARYINFO
*si
, UINT uiProperty
)
667 if ( uiProperty
>= MSI_MAX_PROPS
)
669 prop
= &si
->property
[uiProperty
];
670 if( prop
->vt
!= VT_I4
)
675 LPWSTR
msi_get_suminfo_product( IStorage
*stg
)
681 r
= msi_get_suminfo( stg
, 0, &si
);
682 if (r
!= ERROR_SUCCESS
)
684 ERR("no summary information!\n");
687 prod
= msi_suminfo_dup_string( si
, PID_REVNUMBER
);
688 msiobj_release( &si
->hdr
);
692 UINT WINAPI
MsiSummaryInfoGetPropertyA(
693 MSIHANDLE handle
, UINT uiProperty
, PUINT puiDataType
, LPINT piValue
,
694 FILETIME
*pftValue
, LPSTR szValueBuf
, LPDWORD pcchValueBuf
)
700 TRACE("%u, %u, %p, %p, %p, %p, %p\n", handle
, uiProperty
, puiDataType
,
701 piValue
, pftValue
, szValueBuf
, pcchValueBuf
);
703 if (uiProperty
>= MSI_MAX_PROPS
)
705 if (puiDataType
) *puiDataType
= VT_EMPTY
;
706 return ERROR_UNKNOWN_PROPERTY
;
709 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
710 return ERROR_INVALID_HANDLE
;
713 str
.str
.a
= szValueBuf
;
715 r
= get_prop( si
, uiProperty
, puiDataType
, piValue
, pftValue
, &str
, pcchValueBuf
);
716 msiobj_release( &si
->hdr
);
720 UINT WINAPI
MsiSummaryInfoGetPropertyW(
721 MSIHANDLE handle
, UINT uiProperty
, PUINT puiDataType
, LPINT piValue
,
722 FILETIME
*pftValue
, LPWSTR szValueBuf
, LPDWORD pcchValueBuf
)
728 TRACE("%u, %u, %p, %p, %p, %p, %p\n", handle
, uiProperty
, puiDataType
,
729 piValue
, pftValue
, szValueBuf
, pcchValueBuf
);
731 if (uiProperty
>= MSI_MAX_PROPS
)
733 if (puiDataType
) *puiDataType
= VT_EMPTY
;
734 return ERROR_UNKNOWN_PROPERTY
;
737 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
738 return ERROR_INVALID_HANDLE
;
741 str
.str
.w
= szValueBuf
;
743 r
= get_prop( si
, uiProperty
, puiDataType
, piValue
, pftValue
, &str
, pcchValueBuf
);
744 msiobj_release( &si
->hdr
);
748 static UINT
set_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT type
,
749 INT iValue
, FILETIME
*pftValue
, awcstring
*str
)
754 TRACE("%p, %u, %u, %d, %p, %p\n", si
, uiProperty
, type
, iValue
, pftValue
, str
);
756 prop
= &si
->property
[uiProperty
];
758 if( prop
->vt
== VT_EMPTY
)
760 if( !si
->update_count
)
761 return ERROR_FUNCTION_FAILED
;
765 else if( prop
->vt
!= type
)
766 return ERROR_SUCCESS
;
773 prop
->u
.lVal
= iValue
;
776 prop
->u
.iVal
= iValue
;
779 prop
->u
.filetime
= *pftValue
;
784 len
= WideCharToMultiByte( CP_ACP
, 0, str
->str
.w
, -1,
785 NULL
, 0, NULL
, NULL
);
786 prop
->u
.pszVal
= msi_alloc( len
);
787 WideCharToMultiByte( CP_ACP
, 0, str
->str
.w
, -1,
788 prop
->u
.pszVal
, len
, NULL
, NULL
);
792 len
= lstrlenA( str
->str
.a
) + 1;
793 prop
->u
.pszVal
= msi_alloc( len
);
794 lstrcpyA( prop
->u
.pszVal
, str
->str
.a
);
799 return ERROR_SUCCESS
;
802 UINT WINAPI
MsiSummaryInfoSetPropertyW( MSIHANDLE handle
, UINT uiProperty
, UINT uiDataType
,
803 INT iValue
, FILETIME
*pftValue
, LPCWSTR szValue
)
809 TRACE("%u, %u, %u, %d, %p, %s\n", handle
, uiProperty
, uiDataType
, iValue
, pftValue
,
810 debugstr_w(szValue
) );
812 type
= get_type( uiProperty
);
813 if( type
== VT_EMPTY
|| type
!= uiDataType
)
814 return ERROR_DATATYPE_MISMATCH
;
816 if( uiDataType
== VT_LPSTR
&& !szValue
)
817 return ERROR_INVALID_PARAMETER
;
819 if( uiDataType
== VT_FILETIME
&& !pftValue
)
820 return ERROR_INVALID_PARAMETER
;
822 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
823 return ERROR_INVALID_HANDLE
;
828 ret
= set_prop( si
, uiProperty
, type
, iValue
, pftValue
, &str
);
829 msiobj_release( &si
->hdr
);
833 UINT WINAPI
MsiSummaryInfoSetPropertyA( MSIHANDLE handle
, UINT uiProperty
, UINT uiDataType
,
834 INT iValue
, FILETIME
*pftValue
, LPCSTR szValue
)
840 TRACE("%u, %u, %u, %d, %p, %s\n", handle
, uiProperty
, uiDataType
, iValue
, pftValue
,
841 debugstr_a(szValue
) );
843 type
= get_type( uiProperty
);
844 if( type
== VT_EMPTY
|| type
!= uiDataType
)
845 return ERROR_DATATYPE_MISMATCH
;
847 if( uiDataType
== VT_LPSTR
&& !szValue
)
848 return ERROR_INVALID_PARAMETER
;
850 if( uiDataType
== VT_FILETIME
&& !pftValue
)
851 return ERROR_INVALID_PARAMETER
;
853 if (!(si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
)))
854 return ERROR_INVALID_HANDLE
;
859 ret
= set_prop( si
, uiProperty
, uiDataType
, iValue
, pftValue
, &str
);
860 msiobj_release( &si
->hdr
);
864 static UINT
suminfo_persist( MSISUMMARYINFO
*si
)
866 UINT ret
= ERROR_FUNCTION_FAILED
;
871 grfMode
= STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
;
872 r
= IStorage_CreateStream( si
->storage
, szSumInfo
, grfMode
, 0, 0, &stm
);
875 ret
= save_summary_info( si
, stm
);
876 IStream_Release( stm
);
881 static void parse_filetime( LPCWSTR str
, FILETIME
*ft
)
884 const WCHAR
*p
= str
;
887 memset( <
, 0, sizeof(lt
) );
889 /* YYYY/MM/DD hh:mm:ss */
891 while (isspaceW( *p
)) p
++;
893 lt
.wYear
= strtolW( p
, &end
, 10 );
894 if (*end
!= '/') return;
897 lt
.wMonth
= strtolW( p
, &end
, 10 );
898 if (*end
!= '/') return;
901 lt
.wDay
= strtolW( p
, &end
, 10 );
902 if (*end
!= ' ') return;
905 while (isspaceW( *p
)) p
++;
907 lt
.wHour
= strtolW( p
, &end
, 10 );
908 if (*end
!= ':') return;
911 lt
.wMinute
= strtolW( p
, &end
, 10 );
912 if (*end
!= ':') return;
915 lt
.wSecond
= strtolW( p
, &end
, 10 );
917 TzSpecificLocalTimeToSystemTime( NULL
, <
, &utc
);
918 SystemTimeToFileTime( &utc
, ft
);
921 static UINT
parse_prop( LPCWSTR prop
, LPCWSTR value
, UINT
*pid
, INT
*int_value
,
922 FILETIME
*ft_value
, awcstring
*str_value
)
924 *pid
= atoiW( prop
);
932 *int_value
= atoiW( value
);
935 case PID_LASTPRINTED
:
937 case PID_LASTSAVE_DTM
:
938 parse_filetime( value
, ft_value
);
950 str_value
->str
.w
= value
;
951 str_value
->unicode
= TRUE
;
955 WARN("unhandled prop id %u\n", *pid
);
956 return ERROR_FUNCTION_FAILED
;
959 return ERROR_SUCCESS
;
962 UINT
msi_add_suminfo( MSIDATABASE
*db
, LPWSTR
**records
, int num_records
, int num_columns
)
968 r
= msi_get_suminfo( db
->storage
, num_records
* (num_columns
/ 2), &si
);
969 if (r
!= ERROR_SUCCESS
)
971 if (!(si
= create_suminfo( db
->storage
, num_records
* (num_columns
/ 2) )))
972 return ERROR_OUTOFMEMORY
;
976 for (i
= 0; i
< num_records
; i
++)
978 for (j
= 0; j
< num_columns
; j
+= 2)
985 r
= parse_prop( records
[i
][j
], records
[i
][j
+ 1], &pid
, &int_value
, &ft_value
, &str_value
);
986 if (r
!= ERROR_SUCCESS
)
989 r
= set_prop( si
, pid
, get_type(pid
), int_value
, &ft_value
, &str_value
);
990 if (r
!= ERROR_SUCCESS
)
996 if (r
== ERROR_SUCCESS
)
997 r
= suminfo_persist( si
);
999 msiobj_release( &si
->hdr
);
1003 static UINT
save_prop( MSISUMMARYINFO
*si
, HANDLE handle
, UINT row
)
1005 static const char fmt_systemtime
[] = "%d/%02d/%02d %02d:%02d:%02d";
1006 char data
[20]; /* largest string: YYYY/MM/DD hh:mm:ss */
1007 static const char fmt_begin
[] = "%u\t";
1008 static const char data_end
[] = "\r\n";
1009 static const char fmt_int
[] = "%u";
1010 UINT r
, data_type
, len
;
1011 SYSTEMTIME system_time
;
1017 str
.unicode
= FALSE
;
1020 r
= get_prop( si
, row
, &data_type
, &int_value
, &file_time
, &str
, &len
);
1021 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
1023 if (data_type
== VT_EMPTY
)
1024 return ERROR_SUCCESS
; /* property not set */
1025 snprintf( data
, sizeof(data
), fmt_begin
, row
);
1026 sz
= lstrlenA( data
);
1027 if (!WriteFile( handle
, data
, sz
, &sz
, NULL
))
1028 return ERROR_WRITE_FAULT
;
1034 snprintf( data
, sizeof(data
), fmt_int
, int_value
);
1035 sz
= lstrlenA( data
);
1036 if (!WriteFile( handle
, data
, sz
, &sz
, NULL
))
1037 return ERROR_WRITE_FAULT
;
1041 if (!(str
.str
.a
= msi_alloc( len
)))
1042 return ERROR_OUTOFMEMORY
;
1043 r
= get_prop( si
, row
, NULL
, NULL
, NULL
, &str
, &len
);
1044 if (r
!= ERROR_SUCCESS
)
1046 msi_free( str
.str
.a
);
1049 sz
= lstrlenA( str
.str
.a
);
1050 if (!WriteFile( handle
, str
.str
.a
, sz
, &sz
, NULL
))
1052 msi_free( str
.str
.a
);
1053 return ERROR_WRITE_FAULT
;
1055 msi_free( str
.str
.a
);
1058 if (!FileTimeToSystemTime( &file_time
, &system_time
))
1059 return ERROR_FUNCTION_FAILED
;
1060 snprintf( data
, sizeof(data
), fmt_systemtime
, system_time
.wYear
, system_time
.wMonth
,
1061 system_time
.wDay
, system_time
.wHour
, system_time
.wMinute
,
1062 system_time
.wSecond
);
1063 sz
= lstrlenA( data
);
1064 if (!WriteFile( handle
, data
, sz
, &sz
, NULL
))
1065 return ERROR_WRITE_FAULT
;
1068 /* cannot reach here, property not set */
1071 FIXME( "Unknown property variant type\n" );
1072 return ERROR_FUNCTION_FAILED
;
1075 sz
= lstrlenA( data_end
);
1076 if (!WriteFile( handle
, data_end
, sz
, &sz
, NULL
))
1077 return ERROR_WRITE_FAULT
;
1079 return ERROR_SUCCESS
;
1082 UINT
msi_export_suminfo( MSIDATABASE
*db
, HANDLE handle
)
1084 UINT i
, r
, num_rows
;
1087 r
= msi_get_suminfo( db
->storage
, 0, &si
);
1088 if (r
!= ERROR_SUCCESS
)
1089 r
= msi_get_db_suminfo( db
, 0, &si
);
1090 if (r
!= ERROR_SUCCESS
)
1093 num_rows
= get_property_count( si
->property
);
1096 msiobj_release( &si
->hdr
);
1097 return ERROR_FUNCTION_FAILED
;
1100 for (i
= 0; i
< num_rows
; i
++)
1102 r
= save_prop( si
, handle
, i
);
1103 if (r
!= ERROR_SUCCESS
)
1105 msiobj_release( &si
->hdr
);
1110 msiobj_release( &si
->hdr
);
1111 return ERROR_SUCCESS
;
1114 UINT WINAPI
MsiSummaryInfoPersist( MSIHANDLE handle
)
1119 TRACE("%d\n", handle
);
1121 si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
);
1123 return ERROR_INVALID_HANDLE
;
1125 ret
= suminfo_persist( si
);
1127 msiobj_release( &si
->hdr
);
1131 UINT WINAPI
MsiCreateTransformSummaryInfoA( MSIHANDLE db
, MSIHANDLE db_ref
, LPCSTR transform
, int error
, int validation
)
1134 WCHAR
*transformW
= NULL
;
1136 TRACE("%u, %u, %s, %d, %d\n", db
, db_ref
, debugstr_a(transform
), error
, validation
);
1138 if (transform
&& !(transformW
= strdupAtoW( transform
)))
1139 return ERROR_OUTOFMEMORY
;
1141 r
= MsiCreateTransformSummaryInfoW( db
, db_ref
, transformW
, error
, validation
);
1142 msi_free( transformW
);
1146 UINT WINAPI
MsiCreateTransformSummaryInfoW( MSIHANDLE db
, MSIHANDLE db_ref
, LPCWSTR transform
, int error
, int validation
)
1148 FIXME("%u, %u, %s, %d, %d\n", db
, db_ref
, debugstr_w(transform
), error
, validation
);
1149 return ERROR_FUNCTION_FAILED
;
1152 UINT
msi_load_suminfo_properties( MSIPACKAGE
*package
)
1154 static const WCHAR packagecodeW
[] = {'P','a','c','k','a','g','e','C','o','d','e',0};
1156 WCHAR
*package_code
;
1161 r
= msi_get_suminfo( package
->db
->storage
, 0, &si
);
1162 if (r
!= ERROR_SUCCESS
)
1164 r
= msi_get_db_suminfo( package
->db
, 0, &si
);
1165 if (r
!= ERROR_SUCCESS
)
1167 ERR("Unable to open summary information stream %u\n", r
);
1175 r
= get_prop( si
, PID_REVNUMBER
, NULL
, NULL
, NULL
, &str
, &len
);
1176 if (r
!= ERROR_MORE_DATA
)
1178 WARN("Unable to query revision number %u\n", r
);
1179 msiobj_release( &si
->hdr
);
1180 return ERROR_FUNCTION_FAILED
;
1184 if (!(package_code
= msi_alloc( len
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
1185 str
.str
.w
= package_code
;
1187 r
= get_prop( si
, PID_REVNUMBER
, NULL
, NULL
, NULL
, &str
, &len
);
1188 if (r
!= ERROR_SUCCESS
)
1190 msi_free( package_code
);
1191 msiobj_release( &si
->hdr
);
1195 r
= msi_set_property( package
->db
, packagecodeW
, package_code
, len
);
1196 msi_free( package_code
);
1199 get_prop( si
, PID_WORDCOUNT
, NULL
, &count
, NULL
, NULL
, NULL
);
1200 package
->WordCount
= count
;
1202 msiobj_release( &si
->hdr
);