2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002-2004 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
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msidb
);
45 #define MSIFIELD_NULL 0
46 #define MSIFIELD_INT 1
47 #define MSIFIELD_WSTR 3
48 #define MSIFIELD_STREAM 4
49 #define MSIFIELD_INTPTR 5
51 static void MSI_FreeField( MSIFIELD
*field
)
60 msi_free( field
->u
.szwVal
);
63 IStream_Release( field
->u
.stream
);
66 ERR("Invalid field type %d\n", field
->type
);
70 void MSI_CloseRecord( MSIOBJECTHDR
*arg
)
72 MSIRECORD
*rec
= (MSIRECORD
*) arg
;
75 for( i
=0; i
<=rec
->count
; i
++ )
76 MSI_FreeField( &rec
->fields
[i
] );
79 MSIRECORD
*MSI_CreateRecord( UINT cParams
)
84 TRACE("%d\n", cParams
);
89 len
= sizeof (MSIRECORD
) + sizeof (MSIFIELD
)*cParams
;
90 rec
= alloc_msiobject( MSIHANDLETYPE_RECORD
, len
, MSI_CloseRecord
);
96 MSIHANDLE WINAPI
MsiCreateRecord( UINT cParams
)
101 TRACE("%d\n", cParams
);
103 rec
= MSI_CreateRecord( cParams
);
106 ret
= alloc_msihandle( &rec
->hdr
);
107 msiobj_release( &rec
->hdr
);
112 UINT
MSI_RecordGetFieldCount( const MSIRECORD
*rec
)
117 UINT WINAPI
MsiRecordGetFieldCount( MSIHANDLE handle
)
122 TRACE("%d\n", handle
);
124 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
128 msiobj_lock( &rec
->hdr
);
129 ret
= MSI_RecordGetFieldCount( rec
);
130 msiobj_unlock( &rec
->hdr
);
131 msiobj_release( &rec
->hdr
);
136 static BOOL
string2intW( LPCWSTR str
, int *out
)
141 if( *p
== '-' ) /* skip the minus sign */
145 if( (*p
< '0') || (*p
> '9') )
152 if( str
[0] == '-' ) /* check if it's negative */
159 UINT
MSI_RecordCopyField( MSIRECORD
*in_rec
, UINT in_n
,
160 MSIRECORD
*out_rec
, UINT out_n
)
162 UINT r
= ERROR_SUCCESS
;
164 msiobj_lock( &in_rec
->hdr
);
166 if ( in_n
> in_rec
->count
|| out_n
> out_rec
->count
)
167 r
= ERROR_FUNCTION_FAILED
;
168 else if ( in_rec
!= out_rec
|| in_n
!= out_n
)
173 in
= &in_rec
->fields
[in_n
];
174 out
= &out_rec
->fields
[out_n
];
181 out
->u
.iVal
= in
->u
.iVal
;
183 case MSIFIELD_INTPTR
:
184 out
->u
.pVal
= in
->u
.pVal
;
187 str
= strdupW( in
->u
.szwVal
);
189 r
= ERROR_OUTOFMEMORY
;
193 case MSIFIELD_STREAM
:
194 IStream_AddRef( in
->u
.stream
);
195 out
->u
.stream
= in
->u
.stream
;
198 ERR("invalid field type %d\n", in
->type
);
200 if (r
== ERROR_SUCCESS
)
201 out
->type
= in
->type
;
204 msiobj_unlock( &in_rec
->hdr
);
209 INT_PTR
MSI_RecordGetIntPtr( MSIRECORD
*rec
, UINT iField
)
213 TRACE( "%p %d\n", rec
, iField
);
215 if( iField
> rec
->count
)
218 switch( rec
->fields
[iField
].type
)
221 return rec
->fields
[iField
].u
.iVal
;
222 case MSIFIELD_INTPTR
:
223 return rec
->fields
[iField
].u
.pVal
;
225 if( string2intW( rec
->fields
[iField
].u
.szwVal
, &ret
) )
235 int MSI_RecordGetInteger( MSIRECORD
*rec
, UINT iField
)
239 TRACE("%p %d\n", rec
, iField
);
241 if( iField
> rec
->count
)
242 return MSI_NULL_INTEGER
;
244 switch( rec
->fields
[iField
].type
)
247 return rec
->fields
[iField
].u
.iVal
;
248 case MSIFIELD_INTPTR
:
249 return rec
->fields
[iField
].u
.pVal
;
251 if( string2intW( rec
->fields
[iField
].u
.szwVal
, &ret
) )
253 return MSI_NULL_INTEGER
;
258 return MSI_NULL_INTEGER
;
261 int WINAPI
MsiRecordGetInteger( MSIHANDLE handle
, UINT iField
)
266 TRACE("%d %d\n", handle
, iField
);
268 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
270 return MSI_NULL_INTEGER
;
272 msiobj_lock( &rec
->hdr
);
273 ret
= MSI_RecordGetInteger( rec
, iField
);
274 msiobj_unlock( &rec
->hdr
);
275 msiobj_release( &rec
->hdr
);
280 UINT WINAPI
MsiRecordClearData( MSIHANDLE handle
)
285 TRACE("%d\n", handle
);
287 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
289 return ERROR_INVALID_HANDLE
;
291 msiobj_lock( &rec
->hdr
);
292 for( i
=0; i
<=rec
->count
; i
++)
294 MSI_FreeField( &rec
->fields
[i
] );
295 rec
->fields
[i
].type
= MSIFIELD_NULL
;
296 rec
->fields
[i
].u
.iVal
= 0;
298 msiobj_unlock( &rec
->hdr
);
299 msiobj_release( &rec
->hdr
);
301 return ERROR_SUCCESS
;
304 UINT
MSI_RecordSetIntPtr( MSIRECORD
*rec
, UINT iField
, INT_PTR pVal
)
306 TRACE("%p %u %ld\n", rec
, iField
, pVal
);
308 if( iField
> rec
->count
)
309 return ERROR_INVALID_PARAMETER
;
311 MSI_FreeField( &rec
->fields
[iField
] );
312 rec
->fields
[iField
].type
= MSIFIELD_INTPTR
;
313 rec
->fields
[iField
].u
.pVal
= pVal
;
315 return ERROR_SUCCESS
;
318 UINT
MSI_RecordSetInteger( MSIRECORD
*rec
, UINT iField
, int iVal
)
320 TRACE("%p %u %d\n", rec
, iField
, iVal
);
322 if( iField
> rec
->count
)
323 return ERROR_INVALID_PARAMETER
;
325 MSI_FreeField( &rec
->fields
[iField
] );
326 rec
->fields
[iField
].type
= MSIFIELD_INT
;
327 rec
->fields
[iField
].u
.iVal
= iVal
;
329 return ERROR_SUCCESS
;
332 UINT WINAPI
MsiRecordSetInteger( MSIHANDLE handle
, UINT iField
, int iVal
)
337 TRACE("%d %u %d\n", handle
, iField
, iVal
);
339 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
341 return ERROR_INVALID_HANDLE
;
343 msiobj_lock( &rec
->hdr
);
344 ret
= MSI_RecordSetInteger( rec
, iField
, iVal
);
345 msiobj_unlock( &rec
->hdr
);
346 msiobj_release( &rec
->hdr
);
350 BOOL
MSI_RecordIsNull( MSIRECORD
*rec
, UINT iField
)
354 TRACE("%p %d\n", rec
, iField
);
356 r
= ( iField
> rec
->count
) ||
357 ( rec
->fields
[iField
].type
== MSIFIELD_NULL
);
362 BOOL WINAPI
MsiRecordIsNull( MSIHANDLE handle
, UINT iField
)
367 TRACE("%d %d\n", handle
, iField
);
369 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
372 msiobj_lock( &rec
->hdr
);
373 ret
= MSI_RecordIsNull( rec
, iField
);
374 msiobj_unlock( &rec
->hdr
);
375 msiobj_release( &rec
->hdr
);
380 UINT
MSI_RecordGetStringA(MSIRECORD
*rec
, UINT iField
,
381 LPSTR szValue
, LPDWORD pcchValue
)
386 TRACE("%p %d %p %p\n", rec
, iField
, szValue
, pcchValue
);
388 if( iField
> rec
->count
)
390 if ( szValue
&& *pcchValue
> 0 )
394 return ERROR_SUCCESS
;
398 switch( rec
->fields
[iField
].type
)
401 wsprintfA(buffer
, "%d", rec
->fields
[iField
].u
.iVal
);
402 len
= lstrlenA( buffer
);
404 lstrcpynA(szValue
, buffer
, *pcchValue
);
407 len
= WideCharToMultiByte( CP_ACP
, 0, rec
->fields
[iField
].u
.szwVal
, -1,
408 NULL
, 0 , NULL
, NULL
);
410 WideCharToMultiByte( CP_ACP
, 0, rec
->fields
[iField
].u
.szwVal
, -1,
411 szValue
, *pcchValue
, NULL
, NULL
);
412 if( szValue
&& *pcchValue
&& len
>*pcchValue
)
413 szValue
[*pcchValue
-1] = 0;
418 if( szValue
&& *pcchValue
> 0 )
422 ret
= ERROR_INVALID_PARAMETER
;
426 if( szValue
&& *pcchValue
<= len
)
427 ret
= ERROR_MORE_DATA
;
433 UINT WINAPI
MsiRecordGetStringA(MSIHANDLE handle
, UINT iField
,
434 LPSTR szValue
, LPDWORD pcchValue
)
439 TRACE("%d %d %p %p\n", handle
, iField
, szValue
, pcchValue
);
441 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
443 return ERROR_INVALID_HANDLE
;
444 msiobj_lock( &rec
->hdr
);
445 ret
= MSI_RecordGetStringA( rec
, iField
, szValue
, pcchValue
);
446 msiobj_unlock( &rec
->hdr
);
447 msiobj_release( &rec
->hdr
);
451 const WCHAR
*MSI_RecordGetString( const MSIRECORD
*rec
, UINT iField
)
453 if( iField
> rec
->count
)
456 if( rec
->fields
[iField
].type
!= MSIFIELD_WSTR
)
459 return rec
->fields
[iField
].u
.szwVal
;
462 UINT
MSI_RecordGetStringW(MSIRECORD
*rec
, UINT iField
,
463 LPWSTR szValue
, LPDWORD pcchValue
)
467 static const WCHAR szFormat
[] = { '%','d',0 };
469 TRACE("%p %d %p %p\n", rec
, iField
, szValue
, pcchValue
);
471 if( iField
> rec
->count
)
473 if ( szValue
&& *pcchValue
> 0 )
477 return ERROR_SUCCESS
;
481 switch( rec
->fields
[iField
].type
)
484 wsprintfW(buffer
, szFormat
, rec
->fields
[iField
].u
.iVal
);
485 len
= lstrlenW( buffer
);
487 lstrcpynW(szValue
, buffer
, *pcchValue
);
490 len
= lstrlenW( rec
->fields
[iField
].u
.szwVal
);
492 lstrcpynW(szValue
, rec
->fields
[iField
].u
.szwVal
, *pcchValue
);
495 if( szValue
&& *pcchValue
> 0 )
501 if( szValue
&& *pcchValue
<= len
)
502 ret
= ERROR_MORE_DATA
;
508 UINT WINAPI
MsiRecordGetStringW(MSIHANDLE handle
, UINT iField
,
509 LPWSTR szValue
, LPDWORD pcchValue
)
514 TRACE("%d %d %p %p\n", handle
, iField
, szValue
, pcchValue
);
516 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
518 return ERROR_INVALID_HANDLE
;
520 msiobj_lock( &rec
->hdr
);
521 ret
= MSI_RecordGetStringW( rec
, iField
, szValue
, pcchValue
);
522 msiobj_unlock( &rec
->hdr
);
523 msiobj_release( &rec
->hdr
);
527 static UINT
msi_get_stream_size( IStream
*stm
)
532 r
= IStream_Stat( stm
, &stat
, STATFLAG_NONAME
);
535 return stat
.cbSize
.QuadPart
;
538 static UINT
MSI_RecordDataSize(MSIRECORD
*rec
, UINT iField
)
540 TRACE("%p %d\n", rec
, iField
);
542 if( iField
> rec
->count
)
545 switch( rec
->fields
[iField
].type
)
550 return lstrlenW( rec
->fields
[iField
].u
.szwVal
);
553 case MSIFIELD_STREAM
:
554 return msi_get_stream_size( rec
->fields
[iField
].u
.stream
);
559 UINT WINAPI
MsiRecordDataSize(MSIHANDLE handle
, UINT iField
)
564 TRACE("%d %d\n", handle
, iField
);
566 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
569 msiobj_lock( &rec
->hdr
);
570 ret
= MSI_RecordDataSize( rec
, iField
);
571 msiobj_unlock( &rec
->hdr
);
572 msiobj_release( &rec
->hdr
);
576 static UINT
MSI_RecordSetStringA( MSIRECORD
*rec
, UINT iField
, LPCSTR szValue
)
580 TRACE("%p %d %s\n", rec
, iField
, debugstr_a(szValue
));
582 if( iField
> rec
->count
)
583 return ERROR_INVALID_FIELD
;
585 MSI_FreeField( &rec
->fields
[iField
] );
586 if( szValue
&& szValue
[0] )
588 str
= strdupAtoW( szValue
);
589 rec
->fields
[iField
].type
= MSIFIELD_WSTR
;
590 rec
->fields
[iField
].u
.szwVal
= str
;
594 rec
->fields
[iField
].type
= MSIFIELD_NULL
;
595 rec
->fields
[iField
].u
.szwVal
= NULL
;
601 UINT WINAPI
MsiRecordSetStringA( MSIHANDLE handle
, UINT iField
, LPCSTR szValue
)
606 TRACE("%d %d %s\n", handle
, iField
, debugstr_a(szValue
));
608 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
610 return ERROR_INVALID_HANDLE
;
611 msiobj_lock( &rec
->hdr
);
612 ret
= MSI_RecordSetStringA( rec
, iField
, szValue
);
613 msiobj_unlock( &rec
->hdr
);
614 msiobj_release( &rec
->hdr
);
618 UINT
MSI_RecordSetStringW( MSIRECORD
*rec
, UINT iField
, LPCWSTR szValue
)
622 TRACE("%p %d %s\n", rec
, iField
, debugstr_w(szValue
));
624 if( iField
> rec
->count
)
625 return ERROR_INVALID_FIELD
;
627 MSI_FreeField( &rec
->fields
[iField
] );
629 if( szValue
&& szValue
[0] )
631 str
= strdupW( szValue
);
632 rec
->fields
[iField
].type
= MSIFIELD_WSTR
;
633 rec
->fields
[iField
].u
.szwVal
= str
;
637 rec
->fields
[iField
].type
= MSIFIELD_NULL
;
638 rec
->fields
[iField
].u
.szwVal
= NULL
;
644 UINT WINAPI
MsiRecordSetStringW( MSIHANDLE handle
, UINT iField
, LPCWSTR szValue
)
649 TRACE("%d %d %s\n", handle
, iField
, debugstr_w(szValue
));
651 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
653 return ERROR_INVALID_HANDLE
;
655 msiobj_lock( &rec
->hdr
);
656 ret
= MSI_RecordSetStringW( rec
, iField
, szValue
);
657 msiobj_unlock( &rec
->hdr
);
658 msiobj_release( &rec
->hdr
);
662 /* read the data in a file into an IStream */
663 static UINT
RECORD_StreamFromFile(LPCWSTR szFile
, IStream
**pstm
)
665 DWORD sz
, szHighWord
= 0, read
;
669 ULARGE_INTEGER ulSize
;
671 TRACE("reading %s\n", debugstr_w(szFile
));
673 /* read the file into memory */
674 handle
= CreateFileW(szFile
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
675 if( handle
== INVALID_HANDLE_VALUE
)
676 return GetLastError();
677 sz
= GetFileSize(handle
, &szHighWord
);
678 if( sz
!= INVALID_FILE_SIZE
&& szHighWord
== 0 )
680 hGlob
= GlobalAlloc(GMEM_FIXED
, sz
);
683 BOOL r
= ReadFile(handle
, hGlob
, sz
, &read
, NULL
);
693 return ERROR_FUNCTION_FAILED
;
695 /* make a stream out of it, and set the correct file size */
696 hr
= CreateStreamOnHGlobal(hGlob
, TRUE
, pstm
);
700 return ERROR_FUNCTION_FAILED
;
703 /* set the correct size - CreateStreamOnHGlobal screws it up */
704 ulSize
.QuadPart
= sz
;
705 IStream_SetSize(*pstm
, ulSize
);
707 TRACE("read %s, %d bytes into IStream %p\n", debugstr_w(szFile
), sz
, *pstm
);
709 return ERROR_SUCCESS
;
712 UINT
MSI_RecordSetStream(MSIRECORD
*rec
, UINT iField
, IStream
*stream
)
714 if ( (iField
== 0) || (iField
> rec
->count
) )
715 return ERROR_INVALID_PARAMETER
;
717 MSI_FreeField( &rec
->fields
[iField
] );
718 rec
->fields
[iField
].type
= MSIFIELD_STREAM
;
719 rec
->fields
[iField
].u
.stream
= stream
;
721 return ERROR_SUCCESS
;
724 UINT
MSI_RecordSetStreamFromFileW(MSIRECORD
*rec
, UINT iField
, LPCWSTR szFilename
)
729 if( (iField
== 0) || (iField
> rec
->count
) )
730 return ERROR_INVALID_PARAMETER
;
732 /* no filename means we should seek back to the start of the stream */
738 if( rec
->fields
[iField
].type
!= MSIFIELD_STREAM
)
739 return ERROR_INVALID_FIELD
;
741 stm
= rec
->fields
[iField
].u
.stream
;
743 return ERROR_INVALID_FIELD
;
746 r
= IStream_Seek( stm
, ofs
, STREAM_SEEK_SET
, &cur
);
748 return ERROR_FUNCTION_FAILED
;
752 /* read the file into a stream and save the stream in the record */
753 r
= RECORD_StreamFromFile(szFilename
, &stm
);
754 if( r
!= ERROR_SUCCESS
)
757 /* if all's good, store it in the record */
758 MSI_RecordSetStream(rec
, iField
, stm
);
761 return ERROR_SUCCESS
;
764 UINT WINAPI
MsiRecordSetStreamA(MSIHANDLE hRecord
, UINT iField
, LPCSTR szFilename
)
769 TRACE("%d %d %s\n", hRecord
, iField
, debugstr_a(szFilename
));
773 wstr
= strdupAtoW( szFilename
);
775 return ERROR_OUTOFMEMORY
;
777 ret
= MsiRecordSetStreamW(hRecord
, iField
, wstr
);
783 UINT WINAPI
MsiRecordSetStreamW(MSIHANDLE handle
, UINT iField
, LPCWSTR szFilename
)
788 TRACE("%d %d %s\n", handle
, iField
, debugstr_w(szFilename
));
790 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
792 return ERROR_INVALID_HANDLE
;
794 msiobj_lock( &rec
->hdr
);
795 ret
= MSI_RecordSetStreamFromFileW( rec
, iField
, szFilename
);
796 msiobj_unlock( &rec
->hdr
);
797 msiobj_release( &rec
->hdr
);
801 UINT
MSI_RecordReadStream(MSIRECORD
*rec
, UINT iField
, char *buf
, LPDWORD sz
)
807 TRACE("%p %d %p %p\n", rec
, iField
, buf
, sz
);
810 return ERROR_INVALID_PARAMETER
;
812 if( iField
> rec
->count
)
813 return ERROR_INVALID_PARAMETER
;
815 if ( rec
->fields
[iField
].type
== MSIFIELD_NULL
)
818 return ERROR_INVALID_DATA
;
821 if( rec
->fields
[iField
].type
!= MSIFIELD_STREAM
)
822 return ERROR_INVALID_DATATYPE
;
824 stm
= rec
->fields
[iField
].u
.stream
;
826 return ERROR_INVALID_PARAMETER
;
828 /* if there's no buffer pointer, calculate the length to the end */
832 ULARGE_INTEGER end
, cur
;
834 ofs
.QuadPart
= cur
.QuadPart
= 0;
836 r
= IStream_Seek( stm
, ofs
, STREAM_SEEK_SET
, &cur
);
837 IStream_Seek( stm
, ofs
, STREAM_SEEK_END
, &end
);
838 ofs
.QuadPart
= cur
.QuadPart
;
839 IStream_Seek( stm
, ofs
, STREAM_SEEK_SET
, &cur
);
840 *sz
= end
.QuadPart
- cur
.QuadPart
;
842 return ERROR_SUCCESS
;
847 r
= IStream_Read( stm
, buf
, *sz
, &count
);
851 return ERROR_FUNCTION_FAILED
;
856 return ERROR_SUCCESS
;
859 UINT WINAPI
MsiRecordReadStream(MSIHANDLE handle
, UINT iField
, char *buf
, LPDWORD sz
)
864 TRACE("%d %d %p %p\n", handle
, iField
, buf
, sz
);
866 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
868 return ERROR_INVALID_HANDLE
;
869 msiobj_lock( &rec
->hdr
);
870 ret
= MSI_RecordReadStream( rec
, iField
, buf
, sz
);
871 msiobj_unlock( &rec
->hdr
);
872 msiobj_release( &rec
->hdr
);
876 UINT
MSI_RecordSetIStream( MSIRECORD
*rec
, UINT iField
, IStream
*stm
)
878 TRACE("%p %d %p\n", rec
, iField
, stm
);
880 if( iField
> rec
->count
)
881 return ERROR_INVALID_FIELD
;
883 MSI_FreeField( &rec
->fields
[iField
] );
885 rec
->fields
[iField
].type
= MSIFIELD_STREAM
;
886 rec
->fields
[iField
].u
.stream
= stm
;
887 IStream_AddRef( stm
);
889 return ERROR_SUCCESS
;
892 UINT
MSI_RecordGetIStream( MSIRECORD
*rec
, UINT iField
, IStream
**pstm
)
894 TRACE("%p %d %p\n", rec
, iField
, pstm
);
896 if( iField
> rec
->count
)
897 return ERROR_INVALID_FIELD
;
899 if( rec
->fields
[iField
].type
!= MSIFIELD_STREAM
)
900 return ERROR_INVALID_FIELD
;
902 *pstm
= rec
->fields
[iField
].u
.stream
;
903 IStream_AddRef( *pstm
);
905 return ERROR_SUCCESS
;
908 static UINT
msi_dump_stream_to_file( IStream
*stm
, LPCWSTR name
)
916 stgm
= STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_FAILIFTHERE
;
917 r
= SHCreateStreamOnFileW( name
, stgm
, &out
);
919 return ERROR_FUNCTION_FAILED
;
922 r
= IStream_Seek( stm
, pos
, STREAM_SEEK_END
, &size
);
927 r
= IStream_Seek( stm
, pos
, STREAM_SEEK_SET
, NULL
);
931 r
= IStream_CopyTo( stm
, out
, size
, NULL
, NULL
);
934 IStream_Release( out
);
936 return ERROR_FUNCTION_FAILED
;
937 return ERROR_SUCCESS
;
940 UINT
MSI_RecordStreamToFile( MSIRECORD
*rec
, UINT iField
, LPCWSTR name
)
945 TRACE("%p %u %s\n", rec
, iField
, debugstr_w(name
));
947 msiobj_lock( &rec
->hdr
);
949 r
= MSI_RecordGetIStream( rec
, iField
, &stm
);
950 if( r
== ERROR_SUCCESS
)
952 r
= msi_dump_stream_to_file( stm
, name
);
953 IStream_Release( stm
);
956 msiobj_unlock( &rec
->hdr
);
961 MSIRECORD
*MSI_CloneRecord(MSIRECORD
*rec
)
966 count
= MSI_RecordGetFieldCount(rec
);
967 clone
= MSI_CreateRecord(count
);
971 for (i
= 0; i
<= count
; i
++)
973 if (rec
->fields
[i
].type
== MSIFIELD_STREAM
)
975 if (FAILED(IStream_Clone(rec
->fields
[i
].u
.stream
,
976 &clone
->fields
[i
].u
.stream
)))
978 msiobj_release(&clone
->hdr
);
981 clone
->fields
[i
].type
= MSIFIELD_STREAM
;
985 r
= MSI_RecordCopyField(rec
, i
, clone
, i
);
986 if (r
!= ERROR_SUCCESS
)
988 msiobj_release(&clone
->hdr
);
997 BOOL
MSI_RecordsAreEqual(MSIRECORD
*a
, MSIRECORD
*b
)
1001 if (a
->count
!= b
->count
)
1004 for (i
= 0; i
<= a
->count
; i
++)
1006 if (a
->fields
[i
].type
!= b
->fields
[i
].type
)
1009 switch (a
->fields
[i
].type
)
1015 if (a
->fields
[i
].u
.iVal
!= b
->fields
[i
].u
.iVal
)
1020 if (strcmpW(a
->fields
[i
].u
.szwVal
, b
->fields
[i
].u
.szwVal
))
1024 case MSIFIELD_STREAM
: