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"
38 #include "propvarutil.h"
39 #include "msiserver.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
61 } PROPERTYSECTIONHEADER
;
83 static HRESULT (WINAPI
*pPropVariantChangeType
)
84 (PROPVARIANT
*ppropvarDest
, REFPROPVARIANT propvarSrc
,
85 PROPVAR_CHANGE_FLAGS flags
, VARTYPE vt
);
87 #define SECT_HDR_SIZE (sizeof(PROPERTYSECTIONHEADER))
89 static void free_prop( PROPVARIANT
*prop
)
91 if (prop
->vt
== VT_LPSTR
)
92 msi_free( prop
->u
.pszVal
);
96 static void MSI_CloseSummaryInfo( MSIOBJECTHDR
*arg
)
98 MSISUMMARYINFO
*si
= (MSISUMMARYINFO
*) arg
;
101 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
102 free_prop( &si
->property
[i
] );
103 IStorage_Release( si
->storage
);
106 static UINT
get_type( UINT uiProperty
)
124 case PID_LASTPRINTED
:
126 case PID_LASTSAVE_DTM
:
138 static UINT
get_property_count( const PROPVARIANT
*property
)
144 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
145 if( property
[i
].vt
!= VT_EMPTY
)
150 static UINT
propvar_changetype(PROPVARIANT
*changed
, PROPVARIANT
*property
, VARTYPE vt
)
153 HMODULE propsys
= LoadLibraryA("propsys.dll");
154 pPropVariantChangeType
= (void *)GetProcAddress(propsys
, "PropVariantChangeType");
156 if (!pPropVariantChangeType
)
158 ERR("PropVariantChangeType function missing!\n");
159 return ERROR_FUNCTION_FAILED
;
162 hr
= pPropVariantChangeType(changed
, property
, 0, vt
);
163 return (hr
== S_OK
) ? ERROR_SUCCESS
: ERROR_FUNCTION_FAILED
;
166 /* FIXME: doesn't deal with endian conversion */
167 static void read_properties_from_data( PROPVARIANT
*prop
, LPBYTE data
, DWORD sz
)
171 PROPERTY_DATA
*propdata
;
172 PROPVARIANT property
, *ptr
;
174 PROPERTYIDOFFSET
*idofs
;
175 PROPERTYSECTIONHEADER
*section_hdr
;
177 section_hdr
= (PROPERTYSECTIONHEADER
*) &data
[0];
178 idofs
= (PROPERTYIDOFFSET
*) &data
[SECT_HDR_SIZE
];
180 /* now set all the properties */
181 for( i
= 0; i
< section_hdr
->cProperties
; i
++ )
183 if( idofs
[i
].propid
>= MSI_MAX_PROPS
)
185 ERR("Unknown property ID %d\n", idofs
[i
].propid
);
189 type
= get_type( idofs
[i
].propid
);
190 if( type
== VT_EMPTY
)
192 ERR("propid %d has unknown type\n", idofs
[i
].propid
);
196 propdata
= (PROPERTY_DATA
*) &data
[ idofs
[i
].dwOffset
];
198 /* check we don't run off the end of the data */
199 size
= sz
- idofs
[i
].dwOffset
- sizeof(DWORD
);
200 if( sizeof(DWORD
) > size
||
201 ( propdata
->type
== VT_FILETIME
&& sizeof(FILETIME
) > size
) ||
202 ( propdata
->type
== VT_LPSTR
&& (propdata
->u
.str
.len
+ sizeof(DWORD
)) > size
) )
204 ERR("not enough data\n");
208 property
.vt
= propdata
->type
;
209 if( propdata
->type
== VT_LPSTR
)
211 LPSTR str
= msi_alloc( propdata
->u
.str
.len
);
212 memcpy( str
, propdata
->u
.str
.str
, propdata
->u
.str
.len
);
213 str
[ propdata
->u
.str
.len
- 1 ] = 0;
214 property
.u
.pszVal
= str
;
216 else if( propdata
->type
== VT_FILETIME
)
217 property
.u
.filetime
= propdata
->u
.ft
;
218 else if( propdata
->type
== VT_I2
)
219 property
.u
.iVal
= propdata
->u
.i2
;
220 else if( propdata
->type
== VT_I4
)
221 property
.u
.lVal
= propdata
->u
.i4
;
223 /* check the type is the same as we expect */
224 if( type
!= propdata
->type
)
226 propvar_changetype(&changed
, &property
, type
);
232 prop
[ idofs
[i
].propid
] = *ptr
;
236 static UINT
load_summary_info( MSISUMMARYINFO
*si
, IStream
*stm
)
238 PROPERTYSETHEADER set_hdr
;
239 FORMATIDOFFSET format_hdr
;
240 PROPERTYSECTIONHEADER section_hdr
;
246 TRACE("%p %p\n", si
, stm
);
248 /* read the header */
250 r
= IStream_Read( stm
, &set_hdr
, sz
, &count
);
251 if( FAILED(r
) || count
!= sz
)
252 return ERROR_FUNCTION_FAILED
;
254 if( set_hdr
.wByteOrder
!= 0xfffe )
256 ERR("property set not big-endian %04X\n", set_hdr
.wByteOrder
);
257 return ERROR_FUNCTION_FAILED
;
260 sz
= sizeof format_hdr
;
261 r
= IStream_Read( stm
, &format_hdr
, sz
, &count
);
262 if( FAILED(r
) || count
!= sz
)
263 return ERROR_FUNCTION_FAILED
;
265 /* check the format id is correct */
266 if( !IsEqualGUID( &FMTID_SummaryInformation
, &format_hdr
.fmtid
) )
267 return ERROR_FUNCTION_FAILED
;
269 /* seek to the location of the section */
270 ofs
.QuadPart
= format_hdr
.dwOffset
;
271 r
= IStream_Seek( stm
, ofs
, STREAM_SEEK_SET
, NULL
);
273 return ERROR_FUNCTION_FAILED
;
275 /* read the section itself */
277 r
= IStream_Read( stm
, §ion_hdr
, sz
, &count
);
278 if( FAILED(r
) || count
!= sz
)
279 return ERROR_FUNCTION_FAILED
;
281 if( section_hdr
.cProperties
> MSI_MAX_PROPS
)
283 ERR("too many properties %d\n", section_hdr
.cProperties
);
284 return ERROR_FUNCTION_FAILED
;
287 data
= msi_alloc( section_hdr
.cbSection
);
289 return ERROR_FUNCTION_FAILED
;
291 memcpy( data
, §ion_hdr
, SECT_HDR_SIZE
);
293 /* read all the data in one go */
294 sz
= section_hdr
.cbSection
- SECT_HDR_SIZE
;
295 r
= IStream_Read( stm
, &data
[ SECT_HDR_SIZE
], sz
, &count
);
296 if( SUCCEEDED(r
) && count
== sz
)
297 read_properties_from_data( si
->property
, data
, sz
+ SECT_HDR_SIZE
);
299 ERR("failed to read properties %d %d\n", count
, sz
);
302 return ERROR_SUCCESS
;
305 static DWORD
write_dword( LPBYTE data
, DWORD ofs
, DWORD val
)
309 data
[ofs
++] = val
&0xff;
310 data
[ofs
++] = (val
>>8)&0xff;
311 data
[ofs
++] = (val
>>16)&0xff;
312 data
[ofs
++] = (val
>>24)&0xff;
317 static DWORD
write_filetime( LPBYTE data
, DWORD ofs
, const FILETIME
*ft
)
319 write_dword( data
, ofs
, ft
->dwLowDateTime
);
320 write_dword( data
, ofs
+ 4, ft
->dwHighDateTime
);
324 static DWORD
write_string( LPBYTE data
, DWORD ofs
, LPCSTR str
)
326 DWORD len
= lstrlenA( str
) + 1;
327 write_dword( data
, ofs
, len
);
329 memcpy( &data
[ofs
+ 4], str
, len
);
330 return (7 + len
) & ~3;
333 static UINT
write_property_to_data( const PROPVARIANT
*prop
, LPBYTE data
)
337 if( prop
->vt
== VT_EMPTY
)
341 sz
+= write_dword( data
, sz
, prop
->vt
);
345 sz
+= write_dword( data
, sz
, prop
->u
.iVal
);
348 sz
+= write_dword( data
, sz
, prop
->u
.lVal
);
351 sz
+= write_filetime( data
, sz
, &prop
->u
.filetime
);
354 sz
+= write_string( data
, sz
, prop
->u
.pszVal
);
360 static UINT
save_summary_info( const MSISUMMARYINFO
* si
, IStream
*stm
)
362 UINT ret
= ERROR_FUNCTION_FAILED
;
363 PROPERTYSETHEADER set_hdr
;
364 FORMATIDOFFSET format_hdr
;
365 PROPERTYSECTIONHEADER section_hdr
;
366 PROPERTYIDOFFSET idofs
[MSI_MAX_PROPS
];
372 /* write the header */
374 memset( &set_hdr
, 0, sz
);
375 set_hdr
.wByteOrder
= 0xfffe;
377 set_hdr
.dwOSVer
= 0x00020005; /* build 5, platform id 2 */
378 /* set_hdr.clsID is {00000000-0000-0000-0000-000000000000} */
379 set_hdr
.reserved
= 1;
380 r
= IStream_Write( stm
, &set_hdr
, sz
, &count
);
381 if( FAILED(r
) || count
!= sz
)
384 /* write the format header */
385 sz
= sizeof format_hdr
;
386 format_hdr
.fmtid
= FMTID_SummaryInformation
;
387 format_hdr
.dwOffset
= sizeof format_hdr
+ sizeof set_hdr
;
388 r
= IStream_Write( stm
, &format_hdr
, sz
, &count
);
389 if( FAILED(r
) || count
!= sz
)
392 /* add up how much space the data will take and calculate the offsets */
393 section_hdr
.cbSection
= sizeof section_hdr
;
394 section_hdr
.cbSection
+= (get_property_count( si
->property
) * sizeof idofs
[0]);
395 section_hdr
.cProperties
= 0;
396 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
398 sz
= write_property_to_data( &si
->property
[i
], NULL
);
401 idofs
[ section_hdr
.cProperties
].propid
= i
;
402 idofs
[ section_hdr
.cProperties
].dwOffset
= section_hdr
.cbSection
;
403 section_hdr
.cProperties
++;
404 section_hdr
.cbSection
+= sz
;
407 data
= msi_alloc_zero( section_hdr
.cbSection
);
410 memcpy( &data
[sz
], §ion_hdr
, sizeof section_hdr
);
411 sz
+= sizeof section_hdr
;
413 memcpy( &data
[sz
], idofs
, section_hdr
.cProperties
* sizeof idofs
[0] );
414 sz
+= section_hdr
.cProperties
* sizeof idofs
[0];
416 /* write out the data */
417 for( i
= 0; i
< MSI_MAX_PROPS
; i
++ )
418 sz
+= write_property_to_data( &si
->property
[i
], &data
[sz
] );
420 r
= IStream_Write( stm
, data
, sz
, &count
);
422 if( FAILED(r
) || count
!= sz
)
425 return ERROR_SUCCESS
;
428 static MSISUMMARYINFO
*create_suminfo( IStorage
*stg
, UINT update_count
)
432 if (!(si
= alloc_msiobject( MSIHANDLETYPE_SUMMARYINFO
, sizeof(MSISUMMARYINFO
), MSI_CloseSummaryInfo
)))
435 si
->update_count
= update_count
;
436 IStorage_AddRef( stg
);
442 UINT
msi_get_suminfo( IStorage
*stg
, UINT uiUpdateCount
, MSISUMMARYINFO
**ret
)
449 TRACE("%p, %u\n", stg
, uiUpdateCount
);
451 if (!(si
= create_suminfo( stg
, uiUpdateCount
))) return ERROR_OUTOFMEMORY
;
453 hr
= IStorage_OpenStream( si
->storage
, szSumInfo
, 0, STGM_READ
|STGM_SHARE_EXCLUSIVE
, 0, &stm
);
456 msiobj_release( &si
->hdr
);
457 return ERROR_FUNCTION_FAILED
;
460 r
= load_summary_info( si
, stm
);
461 IStream_Release( stm
);
462 if (r
!= ERROR_SUCCESS
)
464 msiobj_release( &si
->hdr
);
469 return ERROR_SUCCESS
;
472 static UINT
get_db_suminfo( MSIDATABASE
*db
, UINT uiUpdateCount
, MSISUMMARYINFO
**ret
)
478 if (!(si
= create_suminfo( db
->storage
, uiUpdateCount
))) return ERROR_OUTOFMEMORY
;
480 r
= msi_get_stream( db
, szSumInfo
, &stm
);
481 if (r
!= ERROR_SUCCESS
)
483 msiobj_release( &si
->hdr
);
487 r
= load_summary_info( si
, stm
);
488 IStream_Release( stm
);
489 if (r
!= ERROR_SUCCESS
)
491 msiobj_release( &si
->hdr
);
496 return ERROR_SUCCESS
;
499 UINT WINAPI
MsiGetSummaryInformationW( MSIHANDLE hDatabase
,
500 LPCWSTR szDatabase
, UINT uiUpdateCount
, MSIHANDLE
*pHandle
)
506 TRACE("%d %s %d %p\n", hDatabase
, debugstr_w(szDatabase
),
507 uiUpdateCount
, pHandle
);
510 return ERROR_INVALID_PARAMETER
;
512 if( szDatabase
&& szDatabase
[0] )
514 LPCWSTR persist
= uiUpdateCount
? MSIDBOPEN_TRANSACT
: MSIDBOPEN_READONLY
;
516 ret
= MSI_OpenDatabaseW( szDatabase
, persist
, &db
);
517 if( ret
!= ERROR_SUCCESS
)
522 db
= msihandle2msiinfo( hDatabase
, MSIHANDLETYPE_DATABASE
);
526 IWineMsiRemoteDatabase
*remote_database
;
528 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hDatabase
);
529 if ( !remote_database
)
530 return ERROR_INVALID_HANDLE
;
532 hr
= IWineMsiRemoteDatabase_GetSummaryInformation( remote_database
,
533 uiUpdateCount
, pHandle
);
534 IWineMsiRemoteDatabase_Release( remote_database
);
538 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
539 return HRESULT_CODE(hr
);
541 return ERROR_FUNCTION_FAILED
;
544 return ERROR_SUCCESS
;
548 ret
= msi_get_suminfo( db
->storage
, uiUpdateCount
, &si
);
549 if (ret
!= ERROR_SUCCESS
)
550 ret
= get_db_suminfo( db
, uiUpdateCount
, &si
);
551 if (ret
!= ERROR_SUCCESS
)
553 if ((si
= create_suminfo( db
->storage
, uiUpdateCount
)))
557 if (ret
== ERROR_SUCCESS
)
559 *pHandle
= alloc_msihandle( &si
->hdr
);
563 ret
= ERROR_NOT_ENOUGH_MEMORY
;
564 msiobj_release( &si
->hdr
);
567 msiobj_release( &db
->hdr
);
571 UINT WINAPI
MsiGetSummaryInformationA(MSIHANDLE hDatabase
,
572 LPCSTR szDatabase
, UINT uiUpdateCount
, MSIHANDLE
*pHandle
)
574 LPWSTR szwDatabase
= NULL
;
577 TRACE("%d %s %d %p\n", hDatabase
, debugstr_a(szDatabase
),
578 uiUpdateCount
, pHandle
);
582 szwDatabase
= strdupAtoW( szDatabase
);
584 return ERROR_FUNCTION_FAILED
;
587 ret
= MsiGetSummaryInformationW(hDatabase
, szwDatabase
, uiUpdateCount
, pHandle
);
589 msi_free( szwDatabase
);
594 UINT WINAPI
MsiSummaryInfoGetPropertyCount(MSIHANDLE hSummaryInfo
, PUINT pCount
)
598 TRACE("%d %p\n", hSummaryInfo
, pCount
);
600 si
= msihandle2msiinfo( hSummaryInfo
, MSIHANDLETYPE_SUMMARYINFO
);
602 return ERROR_INVALID_HANDLE
;
605 *pCount
= get_property_count( si
->property
);
606 msiobj_release( &si
->hdr
);
608 return ERROR_SUCCESS
;
611 static UINT
get_prop( MSIHANDLE handle
, UINT uiProperty
, UINT
*puiDataType
,
612 INT
*piValue
, FILETIME
*pftValue
, awstring
*str
, DWORD
*pcchValueBuf
)
616 UINT ret
= ERROR_SUCCESS
;
618 TRACE("%d %d %p %p %p %p %p\n", handle
, uiProperty
, puiDataType
,
619 piValue
, pftValue
, str
, pcchValueBuf
);
621 if ( uiProperty
>= MSI_MAX_PROPS
)
623 if (puiDataType
) *puiDataType
= VT_EMPTY
;
624 return ERROR_UNKNOWN_PROPERTY
;
627 si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
);
629 return ERROR_INVALID_HANDLE
;
631 prop
= &si
->property
[uiProperty
];
634 *puiDataType
= prop
->vt
;
640 *piValue
= prop
->u
.iVal
;
644 *piValue
= prop
->u
.lVal
;
653 len
= MultiByteToWideChar( CP_ACP
, 0, prop
->u
.pszVal
, -1, NULL
, 0 ) - 1;
654 MultiByteToWideChar( CP_ACP
, 0, prop
->u
.pszVal
, -1, str
->str
.w
, *pcchValueBuf
);
658 len
= lstrlenA( prop
->u
.pszVal
);
660 lstrcpynA(str
->str
.a
, prop
->u
.pszVal
, *pcchValueBuf
);
662 if (len
>= *pcchValueBuf
)
663 ret
= ERROR_MORE_DATA
;
669 *pftValue
= prop
->u
.filetime
;
674 FIXME("Unknown property variant type\n");
677 msiobj_release( &si
->hdr
);
681 LPWSTR
msi_suminfo_dup_string( MSISUMMARYINFO
*si
, UINT uiProperty
)
685 if ( uiProperty
>= MSI_MAX_PROPS
)
687 prop
= &si
->property
[uiProperty
];
688 if( prop
->vt
!= VT_LPSTR
)
690 return strdupAtoW( prop
->u
.pszVal
);
693 INT
msi_suminfo_get_int32( MSISUMMARYINFO
*si
, UINT uiProperty
)
697 if ( uiProperty
>= MSI_MAX_PROPS
)
699 prop
= &si
->property
[uiProperty
];
700 if( prop
->vt
!= VT_I4
)
705 LPWSTR
msi_get_suminfo_product( IStorage
*stg
)
711 r
= msi_get_suminfo( stg
, 0, &si
);
712 if (r
!= ERROR_SUCCESS
)
714 ERR("no summary information!\n");
717 prod
= msi_suminfo_dup_string( si
, PID_REVNUMBER
);
718 msiobj_release( &si
->hdr
);
722 UINT WINAPI
MsiSummaryInfoGetPropertyA(
723 MSIHANDLE handle
, UINT uiProperty
, PUINT puiDataType
, LPINT piValue
,
724 FILETIME
*pftValue
, LPSTR szValueBuf
, LPDWORD pcchValueBuf
)
728 TRACE("%d %d %p %p %p %p %p\n", handle
, uiProperty
, puiDataType
,
729 piValue
, pftValue
, szValueBuf
, pcchValueBuf
);
732 str
.str
.a
= szValueBuf
;
734 return get_prop( handle
, uiProperty
, puiDataType
, piValue
,
735 pftValue
, &str
, pcchValueBuf
);
738 UINT WINAPI
MsiSummaryInfoGetPropertyW(
739 MSIHANDLE handle
, UINT uiProperty
, PUINT puiDataType
, LPINT piValue
,
740 FILETIME
*pftValue
, LPWSTR szValueBuf
, LPDWORD pcchValueBuf
)
744 TRACE("%d %d %p %p %p %p %p\n", handle
, uiProperty
, puiDataType
,
745 piValue
, pftValue
, szValueBuf
, pcchValueBuf
);
748 str
.str
.w
= szValueBuf
;
750 return get_prop( handle
, uiProperty
, puiDataType
, piValue
,
751 pftValue
, &str
, pcchValueBuf
);
754 static UINT
set_prop( MSISUMMARYINFO
*si
, UINT uiProperty
, UINT type
,
755 INT iValue
, FILETIME
* pftValue
, awcstring
*str
)
760 TRACE("%p %u %u %i %p %p\n", si
, uiProperty
, type
, iValue
,
763 prop
= &si
->property
[uiProperty
];
765 if( prop
->vt
== VT_EMPTY
)
767 if( !si
->update_count
)
768 return ERROR_FUNCTION_FAILED
;
772 else if( prop
->vt
!= type
)
773 return ERROR_SUCCESS
;
780 prop
->u
.lVal
= iValue
;
783 prop
->u
.iVal
= iValue
;
786 prop
->u
.filetime
= *pftValue
;
791 len
= WideCharToMultiByte( CP_ACP
, 0, str
->str
.w
, -1,
792 NULL
, 0, NULL
, NULL
);
793 prop
->u
.pszVal
= msi_alloc( len
);
794 WideCharToMultiByte( CP_ACP
, 0, str
->str
.w
, -1,
795 prop
->u
.pszVal
, len
, NULL
, NULL
);
799 len
= lstrlenA( str
->str
.a
) + 1;
800 prop
->u
.pszVal
= msi_alloc( len
);
801 lstrcpyA( prop
->u
.pszVal
, str
->str
.a
);
806 return ERROR_SUCCESS
;
809 UINT WINAPI
MsiSummaryInfoSetPropertyW( MSIHANDLE handle
, UINT uiProperty
,
810 UINT uiDataType
, INT iValue
, FILETIME
* pftValue
, LPCWSTR szValue
)
816 TRACE("%d %u %u %i %p %s\n", handle
, uiProperty
, uiDataType
,
817 iValue
, pftValue
, debugstr_w(szValue
) );
819 type
= get_type( uiProperty
);
820 if( type
== VT_EMPTY
|| type
!= uiDataType
)
821 return ERROR_DATATYPE_MISMATCH
;
823 if( uiDataType
== VT_LPSTR
&& !szValue
)
824 return ERROR_INVALID_PARAMETER
;
826 if( uiDataType
== VT_FILETIME
&& !pftValue
)
827 return ERROR_INVALID_PARAMETER
;
829 si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
);
831 return ERROR_INVALID_HANDLE
;
835 ret
= set_prop( si
, uiProperty
, type
, iValue
, pftValue
, &str
);
837 msiobj_release( &si
->hdr
);
841 UINT WINAPI
MsiSummaryInfoSetPropertyA( MSIHANDLE handle
, UINT uiProperty
,
842 UINT uiDataType
, INT iValue
, FILETIME
* pftValue
, LPCSTR szValue
)
848 TRACE("%d %u %u %i %p %s\n", handle
, uiProperty
, uiDataType
,
849 iValue
, pftValue
, debugstr_a(szValue
) );
851 type
= get_type( uiProperty
);
852 if( type
== VT_EMPTY
|| type
!= uiDataType
)
853 return ERROR_DATATYPE_MISMATCH
;
855 if( uiDataType
== VT_LPSTR
&& !szValue
)
856 return ERROR_INVALID_PARAMETER
;
858 if( uiDataType
== VT_FILETIME
&& !pftValue
)
859 return ERROR_INVALID_PARAMETER
;
861 si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
);
863 return ERROR_INVALID_HANDLE
;
867 ret
= set_prop( si
, uiProperty
, uiDataType
, iValue
, pftValue
, &str
);
869 msiobj_release( &si
->hdr
);
873 static UINT
suminfo_persist( MSISUMMARYINFO
*si
)
875 UINT ret
= ERROR_FUNCTION_FAILED
;
880 grfMode
= STGM_CREATE
| STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
;
881 r
= IStorage_CreateStream( si
->storage
, szSumInfo
, grfMode
, 0, 0, &stm
);
884 ret
= save_summary_info( si
, stm
);
885 IStream_Release( stm
);
890 static void parse_filetime( LPCWSTR str
, FILETIME
*ft
)
893 const WCHAR
*p
= str
;
896 memset( <
, 0, sizeof(lt
) );
898 /* YYYY/MM/DD hh:mm:ss */
900 while (isspaceW( *p
)) p
++;
902 lt
.wYear
= strtolW( p
, &end
, 10 );
903 if (*end
!= '/') return;
906 lt
.wMonth
= strtolW( p
, &end
, 10 );
907 if (*end
!= '/') return;
910 lt
.wDay
= strtolW( p
, &end
, 10 );
911 if (*end
!= ' ') return;
914 while (isspaceW( *p
)) p
++;
916 lt
.wHour
= strtolW( p
, &end
, 10 );
917 if (*end
!= ':') return;
920 lt
.wMinute
= strtolW( p
, &end
, 10 );
921 if (*end
!= ':') return;
924 lt
.wSecond
= strtolW( p
, &end
, 10 );
926 TzSpecificLocalTimeToSystemTime( NULL
, <
, &utc
);
927 SystemTimeToFileTime( &utc
, ft
);
930 static UINT
parse_prop( LPCWSTR prop
, LPCWSTR value
, UINT
*pid
, INT
*int_value
,
931 FILETIME
*ft_value
, awcstring
*str_value
)
933 *pid
= atoiW( prop
);
941 *int_value
= atoiW( value
);
944 case PID_LASTPRINTED
:
946 case PID_LASTSAVE_DTM
:
947 parse_filetime( value
, ft_value
);
959 str_value
->str
.w
= value
;
960 str_value
->unicode
= TRUE
;
964 WARN("unhandled prop id %u\n", *pid
);
965 return ERROR_FUNCTION_FAILED
;
968 return ERROR_SUCCESS
;
971 UINT
msi_add_suminfo( MSIDATABASE
*db
, LPWSTR
**records
, int num_records
, int num_columns
)
977 r
= msi_get_suminfo( db
->storage
, num_records
* (num_columns
/ 2), &si
);
978 if (r
!= ERROR_SUCCESS
)
980 if (!(si
= create_suminfo( db
->storage
, num_records
* (num_columns
/ 2) )))
981 return ERROR_OUTOFMEMORY
;
985 for (i
= 0; i
< num_records
; i
++)
987 for (j
= 0; j
< num_columns
; j
+= 2)
994 r
= parse_prop( records
[i
][j
], records
[i
][j
+ 1], &pid
, &int_value
, &ft_value
, &str_value
);
995 if (r
!= ERROR_SUCCESS
)
998 r
= set_prop( si
, pid
, get_type(pid
), int_value
, &ft_value
, &str_value
);
999 if (r
!= ERROR_SUCCESS
)
1005 if (r
== ERROR_SUCCESS
)
1006 r
= suminfo_persist( si
);
1008 msiobj_release( &si
->hdr
);
1012 UINT WINAPI
MsiSummaryInfoPersist( MSIHANDLE handle
)
1017 TRACE("%d\n", handle
);
1019 si
= msihandle2msiinfo( handle
, MSIHANDLETYPE_SUMMARYINFO
);
1021 return ERROR_INVALID_HANDLE
;
1023 ret
= suminfo_persist( si
);
1025 msiobj_release( &si
->hdr
);
1029 UINT WINAPI
MsiCreateTransformSummaryInfoA( MSIHANDLE db
, MSIHANDLE db_ref
, LPCSTR transform
, int error
, int validation
)
1032 WCHAR
*transformW
= NULL
;
1034 TRACE("%u, %u, %s, %d, %d\n", db
, db_ref
, debugstr_a(transform
), error
, validation
);
1036 if (transform
&& !(transformW
= strdupAtoW( transform
)))
1037 return ERROR_OUTOFMEMORY
;
1039 r
= MsiCreateTransformSummaryInfoW( db
, db_ref
, transformW
, error
, validation
);
1040 msi_free( transformW
);
1044 UINT WINAPI
MsiCreateTransformSummaryInfoW( MSIHANDLE db
, MSIHANDLE db_ref
, LPCWSTR transform
, int error
, int validation
)
1046 FIXME("%u, %u, %s, %d, %d\n", db
, db_ref
, debugstr_w(transform
), error
, validation
);
1047 return ERROR_FUNCTION_FAILED
;