2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Aric Stewart 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 * Actions dealing with files These are
29 * RemoveDuplicateFiles(TODO)
38 #include "wine/debug.h"
42 #include "msvcrt/fcntl.h"
47 #include "wine/unicode.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
51 extern const WCHAR szInstallFiles
[];
52 extern const WCHAR szDuplicateFiles
[];
53 extern const WCHAR szMoveFiles
[];
54 extern const WCHAR szPatchFiles
[];
55 extern const WCHAR szRemoveDuplicateFiles
[];
56 extern const WCHAR szRemoveFiles
[];
58 static const WCHAR cszTempFolder
[]= {'T','e','m','p','F','o','l','d','e','r',0};
65 WCHAR source
[MAX_PATH
];
69 * This is a helper function for handling embedded cabinet media
71 static UINT
writeout_cabinet_stream(MSIPACKAGE
*package
, LPCWSTR stream_name
,
81 rc
= read_raw_stream_data(package
->db
,stream_name
,&data
,&size
);
82 if (rc
!= ERROR_SUCCESS
)
86 if (MSI_GetPropertyW(package
, cszTempFolder
, tmp
, &write
))
87 GetTempPathW(MAX_PATH
,tmp
);
89 GetTempFileNameW(tmp
,stream_name
,0,source
);
91 track_tempfile(package
,strrchrW(source
,'\\'), source
);
92 the_file
= CreateFileW(source
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
93 FILE_ATTRIBUTE_NORMAL
, NULL
);
95 if (the_file
== INVALID_HANDLE_VALUE
)
97 ERR("Unable to create file %s\n",debugstr_w(source
));
98 rc
= ERROR_FUNCTION_FAILED
;
102 WriteFile(the_file
,data
,size
,&write
,NULL
);
103 CloseHandle(the_file
);
104 TRACE("wrote %i bytes to %s\n",write
,debugstr_w(source
));
111 /* Support functions for FDI functions */
118 static void * cabinet_alloc(ULONG cb
)
120 return msi_alloc(cb
);
123 static void cabinet_free(void *pv
)
128 static INT_PTR
cabinet_open(char *pszFile
, int oflag
, int pmode
)
132 DWORD dwShareMode
= 0;
133 DWORD dwCreateDisposition
= OPEN_EXISTING
;
134 switch (oflag
& _O_ACCMODE
)
137 dwAccess
= GENERIC_READ
;
138 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_DELETE
;
141 dwAccess
= GENERIC_WRITE
;
142 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
145 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
146 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
149 if ((oflag
& (_O_CREAT
| _O_EXCL
)) == (_O_CREAT
| _O_EXCL
))
150 dwCreateDisposition
= CREATE_NEW
;
151 else if (oflag
& _O_CREAT
)
152 dwCreateDisposition
= CREATE_ALWAYS
;
153 handle
= CreateFileA( pszFile
, dwAccess
, dwShareMode
, NULL
,
154 dwCreateDisposition
, 0, NULL
);
155 if (handle
== INVALID_HANDLE_VALUE
)
157 return (INT_PTR
) handle
;
160 static UINT
cabinet_read(INT_PTR hf
, void *pv
, UINT cb
)
162 HANDLE handle
= (HANDLE
) hf
;
164 if (ReadFile(handle
, pv
, cb
, &dwRead
, NULL
))
169 static UINT
cabinet_write(INT_PTR hf
, void *pv
, UINT cb
)
171 HANDLE handle
= (HANDLE
) hf
;
173 if (WriteFile(handle
, pv
, cb
, &dwWritten
, NULL
))
178 static int cabinet_close(INT_PTR hf
)
180 HANDLE handle
= (HANDLE
) hf
;
181 return CloseHandle(handle
) ? 0 : -1;
184 static long cabinet_seek(INT_PTR hf
, long dist
, int seektype
)
186 HANDLE handle
= (HANDLE
) hf
;
187 /* flags are compatible and so are passed straight through */
188 return SetFilePointer(handle
, dist
, NULL
, seektype
);
191 static void msi_file_update_ui( MSIPACKAGE
*package
, MSIFILE
*f
, const WCHAR
*action
)
197 uirow
= MSI_CreateRecord( 9 );
198 MSI_RecordSetStringW( uirow
, 1, f
->FileName
);
199 uipath
= strdupW( f
->TargetPath
);
200 p
= strrchrW(uipath
,'\\');
203 MSI_RecordSetStringW( uirow
, 9, uipath
);
204 MSI_RecordSetInteger( uirow
, 6, f
->FileSize
);
205 ui_actiondata( package
, action
, uirow
);
206 msiobj_release( &uirow
->hdr
);
208 ui_progress( package
, 2, f
->FileSize
, 0, 0);
211 static INT_PTR
cabinet_notify(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
217 CabData
*data
= (CabData
*) pfdin
->pv
;
223 file
= strdupAtoW(pfdin
->psz1
);
224 f
= get_loaded_file(data
->package
, file
);
229 WARN("unknown file in cabinet (%s)\n",debugstr_a(pfdin
->psz1
));
233 if (f
->state
!= msifs_missing
&& f
->state
!= msifs_overwrite
)
235 TRACE("Skipping extraction of %s\n",debugstr_a(pfdin
->psz1
));
239 msi_file_update_ui( data
->package
, f
, szInstallFiles
);
241 TRACE("extracting %s\n", debugstr_w(f
->TargetPath
) );
243 attrs
= f
->Attributes
& (FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
);
244 if (!attrs
) attrs
= FILE_ATTRIBUTE_NORMAL
;
246 handle
= CreateFileW( f
->TargetPath
, GENERIC_READ
| GENERIC_WRITE
, 0,
247 NULL
, CREATE_ALWAYS
, attrs
, NULL
);
248 if ( handle
== INVALID_HANDLE_VALUE
)
250 ERR("failed to create %s (error %d)\n",
251 debugstr_w( f
->TargetPath
), GetLastError() );
255 f
->state
= msifs_installed
;
256 return (INT_PTR
) handle
;
258 case fdintCLOSE_FILE_INFO
:
262 HANDLE handle
= (HANDLE
) pfdin
->hf
;
264 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
266 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
268 if (!SetFileTime(handle
, &ftLocal
, 0, &ftLocal
))
278 /***********************************************************************
279 * extract_cabinet_file
281 * Extract files from a cab file.
283 static BOOL
extract_cabinet_file(MSIPACKAGE
* package
, struct media_info
*mi
)
290 static CHAR empty
[] = "";
293 TRACE("Extracting %s to %s\n",debugstr_w(mi
->source
), debugstr_w(mi
->last_path
));
295 hfdi
= FDICreate(cabinet_alloc
,
306 ERR("FDICreate failed\n");
310 if (!(cabinet
= strdupWtoA( mi
->source
)))
315 if (!(cab_path
= strdupWtoA( mi
->last_path
)))
322 data
.package
= package
;
323 data
.cab_path
= cab_path
;
325 ret
= FDICopy(hfdi
, cabinet
, empty
, 0, cabinet_notify
, NULL
, &data
);
328 ERR("FDICopy failed\n");
338 static VOID
set_file_source(MSIPACKAGE
* package
, MSIFILE
* file
, LPCWSTR path
)
340 if (!file
->IsCompressed
)
343 p
= resolve_folder(package
, file
->Component
->Directory
, TRUE
, FALSE
, NULL
);
344 path
= build_directory_name(2, p
, file
->ShortName
);
345 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW( path
))
348 path
= build_directory_name(2, p
, file
->LongName
);
350 file
->SourcePath
= path
;
354 file
->SourcePath
= build_directory_name(2, path
, file
->File
);
357 static struct media_info
*create_media_info( void )
359 struct media_info
*mi
;
361 mi
= msi_alloc( sizeof *mi
);
364 mi
->last_sequence
= 0;
365 mi
->last_volume
= NULL
;
366 mi
->last_path
= NULL
;
374 static void free_media_info( struct media_info
*mi
)
376 msi_free( mi
->last_path
);
380 /* downloads a remote cabinet and extracts it if it exists */
381 static UINT
msi_extract_remote_cabinet( MSIPACKAGE
*package
, struct media_info
*mi
)
383 FDICABINETINFO cabinfo
;
384 WCHAR temppath
[MAX_PATH
];
393 /* the URL is the path prefix of the package URL and the filename
394 * of the file to download
396 ptr
= strrchrW(package
->PackagePath
, '/');
397 lstrcpynW(src
, package
->PackagePath
, ptr
- package
->PackagePath
+ 2);
398 ptr
= strrchrW(mi
->source
, '\\');
399 lstrcatW(src
, ptr
+ 1);
401 file
= msi_download_file( src
, temppath
);
402 lstrcpyW(mi
->source
, file
);
404 /* check if the remote cabinet still exists, ignore if it doesn't */
405 hfdi
= FDICreate(cabinet_alloc
, cabinet_free
, cabinet_open
, cabinet_read
,
406 cabinet_write
, cabinet_close
, cabinet_seek
, 0, &erf
);
409 ERR("FDICreate failed\n");
410 return ERROR_FUNCTION_FAILED
;
413 cabpath
= strdupWtoA(mi
->source
);
414 hf
= cabinet_open(cabpath
, _O_RDONLY
, 0);
415 if (!FDIIsCabinet(hfdi
, hf
, &cabinfo
))
417 WARN("Remote cabinet %s does not exist.\n", debugstr_w(mi
->source
));
419 return ERROR_SUCCESS
;
423 return !extract_cabinet_file(package
, mi
);
426 static UINT
msi_change_media( MSIPACKAGE
*package
, struct media_info
*mi
, LPCWSTR prompt
)
428 LPWSTR error
, error_dialog
;
429 UINT r
= ERROR_SUCCESS
;
431 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
432 static const WCHAR error_prop
[] = {'E','r','r','o','r','D','i','a','l','o','g',0};
434 if ( msi_get_property_int(package
, szUILevel
, 0) == INSTALLUILEVEL_NONE
)
435 return ERROR_SUCCESS
;
437 error
= generate_error_string( package
, 1302, 1, prompt
);
438 error_dialog
= msi_dup_property( package
, error_prop
);
440 while ( r
== ERROR_SUCCESS
&& GetFileAttributesW( mi
->source
) == INVALID_FILE_ATTRIBUTES
)
441 r
= msi_spawn_error_dialog( package
, error_dialog
, error
);
444 msi_free( error_dialog
);
449 static UINT
ready_media_for_file( MSIPACKAGE
*package
, struct media_info
*mi
,
452 UINT rc
= ERROR_SUCCESS
;
454 static const WCHAR ExecSeqQuery
[] =
455 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
456 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
457 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',
458 ' ','%', 'i',' ','O','R','D','E','R',' ','B','Y',' ',
459 '`','D','i','s','k','I','d','`',0};
464 MSICOMPONENT
*comp
= file
->Component
;
466 if (file
->Sequence
<= mi
->last_sequence
)
468 set_file_source(package
, file
, mi
->last_path
);
469 TRACE("Media already ready (%u, %u)\n",file
->Sequence
,mi
->last_sequence
);
470 return ERROR_SUCCESS
;
474 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, file
->Sequence
);
477 TRACE("Unable to query row\n");
478 return ERROR_FUNCTION_FAILED
;
481 volume
= MSI_RecordGetString(row
, 5);
482 prompt
= MSI_RecordGetString(row
, 3);
484 msi_free(mi
->last_path
);
485 mi
->last_path
= NULL
;
487 if (!file
->IsCompressed
)
489 mi
->last_path
= resolve_folder(package
, comp
->Directory
, TRUE
, FALSE
, NULL
);
490 set_file_source(package
, file
, mi
->last_path
);
492 MsiSourceListAddMediaDiskW(package
->ProductCode
, NULL
,
493 MSIINSTALLCONTEXT_USERMANAGED
, MSICODE_PRODUCT
, mi
->count
, volume
,
496 MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
497 MSIINSTALLCONTEXT_USERMANAGED
,
498 MSICODE_PRODUCT
|MSISOURCETYPE_MEDIA
,
499 INSTALLPROPERTY_LASTUSEDSOURCEW
, mi
->last_path
);
500 msiobj_release(&row
->hdr
);
504 seq
= MSI_RecordGetInteger(row
,2);
505 mi
->last_sequence
= seq
;
507 cab
= MSI_RecordGetString(row
,4);
510 TRACE("Source is CAB %s\n",debugstr_w(cab
));
511 /* the stream does not contain the # character */
516 rc
= writeout_cabinet_stream(package
,&cab
[1],mi
->source
);
517 if (rc
!= ERROR_SUCCESS
)
520 mi
->last_path
= strdupW(mi
->source
);
521 p
= strrchrW(mi
->last_path
,'\\');
525 path
= msi_dup_property( package
, cszSourceDir
);
527 MsiSourceListAddMediaDiskW(package
->ProductCode
, NULL
,
528 MSIINSTALLCONTEXT_USERMANAGED
, MSICODE_PRODUCT
, mi
->count
,
531 MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
532 MSIINSTALLCONTEXT_USERMANAGED
,
533 MSICODE_PRODUCT
|MSISOURCETYPE_NETWORK
,
534 INSTALLPROPERTY_LASTUSEDSOURCEW
, path
);
541 mi
->last_path
= msi_alloc(MAX_PATH
*sizeof(WCHAR
));
542 if (MSI_GetPropertyW(package
, cszSourceDir
, mi
->source
, &sz
))
544 ERR("No Source dir defined\n");
545 rc
= ERROR_FUNCTION_FAILED
;
549 strcpyW(mi
->last_path
,mi
->source
);
550 strcatW(mi
->source
,cab
);
552 if (GetFileAttributesW(mi
->source
) == INVALID_FILE_ATTRIBUTES
)
553 rc
= msi_change_media(package
, mi
, prompt
);
555 if ( rc
!= ERROR_SUCCESS
)
558 MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
559 MSIINSTALLCONTEXT_USERMANAGED
,
560 MSICODE_PRODUCT
|MSISOURCETYPE_MEDIA
,
561 INSTALLPROPERTY_LASTUSEDSOURCEW
, mi
->last_path
);
563 /* extract the cab file into a folder in the temp folder */
565 if (MSI_GetPropertyW(package
, cszTempFolder
,mi
->last_path
, &sz
)
567 GetTempPathW(MAX_PATH
,mi
->last_path
);
571 /* only download the remote cabinet file if a local copy does not exist */
572 if (GetFileAttributesW(mi
->source
) == INVALID_FILE_ATTRIBUTES
&&
573 UrlIsW(package
->PackagePath
, URLIS_URL
))
575 rc
= msi_extract_remote_cabinet(package
, mi
);
579 rc
= !extract_cabinet_file(package
, mi
);
585 mi
->last_path
= msi_alloc(MAX_PATH
*sizeof(WCHAR
));
586 MSI_GetPropertyW(package
,cszSourceDir
,mi
->source
,&sz
);
587 strcpyW(mi
->last_path
,mi
->source
);
589 MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
590 MSIINSTALLCONTEXT_USERMANAGED
,
591 MSICODE_PRODUCT
|MSISOURCETYPE_MEDIA
,
592 INSTALLPROPERTY_LASTUSEDSOURCEW
, mi
->last_path
);
594 set_file_source(package
, file
, mi
->last_path
);
596 MsiSourceListAddMediaDiskW(package
->ProductCode
, NULL
,
597 MSIINSTALLCONTEXT_USERMANAGED
, MSICODE_PRODUCT
, mi
->count
, volume
,
601 msiobj_release(&row
->hdr
);
606 static UINT
get_file_target(MSIPACKAGE
*package
, LPCWSTR file_key
,
609 LIST_FOR_EACH_ENTRY( *file
, &package
->files
, MSIFILE
, entry
)
611 if (lstrcmpW( file_key
, (*file
)->File
)==0)
613 if ((*file
)->state
>= msifs_overwrite
)
614 return ERROR_SUCCESS
;
616 return ERROR_FILE_NOT_FOUND
;
620 return ERROR_FUNCTION_FAILED
;
624 * ACTION_InstallFiles()
626 * For efficiency, this is done in two passes:
627 * 1) Correct all the TargetPaths and determine what files are to be installed.
628 * 2) Extract Cabinets and copy files.
630 UINT
ACTION_InstallFiles(MSIPACKAGE
*package
)
632 struct media_info
*mi
;
633 UINT rc
= ERROR_SUCCESS
;
637 /* increment progress bar each time action data is sent */
638 ui_progress(package
,1,1,0,0);
640 /* handle the keys for the SourceList */
641 ptr
= strrchrW(package
->PackagePath
,'\\');
645 MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
646 MSIINSTALLCONTEXT_USERMANAGED
,
648 INSTALLPROPERTY_PACKAGENAMEW
, ptr
);
650 /* FIXME("Write DiskPrompt\n"); */
653 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
655 if (!ACTION_VerifyComponentForAction( file
->Component
, INSTALLSTATE_LOCAL
))
657 ui_progress(package
,2,file
->FileSize
,0,0);
658 TRACE("File %s is not scheduled for install\n",
659 debugstr_w(file
->File
));
661 file
->state
= msifs_skipped
;
666 * Despite MSDN specifying that the CreateFolders action
667 * should be called before InstallFiles, some installers don't
668 * do that, and they seem to work correctly. We need to create
669 * directories here to make sure that the files can be copied.
671 msi_create_component_directories( package
);
673 mi
= create_media_info();
676 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
678 if (file
->state
!= msifs_missing
&& file
->state
!= msifs_overwrite
)
681 TRACE("Pass 2: %s\n",debugstr_w(file
->File
));
683 rc
= ready_media_for_file( package
, mi
, file
);
684 if (rc
!= ERROR_SUCCESS
)
686 ERR("Unable to ready media\n");
687 rc
= ERROR_FUNCTION_FAILED
;
691 TRACE("file paths %s to %s\n",debugstr_w(file
->SourcePath
),
692 debugstr_w(file
->TargetPath
));
694 if (file
->state
!= msifs_missing
&& file
->state
!= msifs_overwrite
)
697 /* compressed files are extracted in ready_media_for_file */
698 if (file
->IsCompressed
)
700 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(file
->TargetPath
))
702 ERR("compressed file wasn't extracted (%s)\n",
703 debugstr_w(file
->TargetPath
));
704 rc
= ERROR_INSTALL_FAILURE
;
711 rc
= CopyFileW(file
->SourcePath
,file
->TargetPath
,FALSE
);
715 ERR("Unable to copy file (%s -> %s) (error %d)\n",
716 debugstr_w(file
->SourcePath
), debugstr_w(file
->TargetPath
), rc
);
717 if (rc
== ERROR_ALREADY_EXISTS
&& file
->state
== msifs_overwrite
)
721 else if (rc
== ERROR_FILE_NOT_FOUND
)
723 ERR("Source File Not Found! Continuing\n");
726 else if (file
->Attributes
& msidbFileAttributesVital
)
728 ERR("Ignoring Error and continuing (nonvital file)...\n");
734 file
->state
= msifs_installed
;
740 free_media_info( mi
);
744 static UINT
ITERATE_DuplicateFiles(MSIRECORD
*row
, LPVOID param
)
746 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
747 WCHAR dest_name
[0x100];
748 LPWSTR dest_path
, dest
;
749 LPCWSTR file_key
, component
;
755 component
= MSI_RecordGetString(row
,2);
756 comp
= get_loaded_component(package
,component
);
758 if (!ACTION_VerifyComponentForAction( comp
, INSTALLSTATE_LOCAL
))
760 TRACE("Skipping copy due to disabled component %s\n",
761 debugstr_w(component
));
763 /* the action taken was the same as the current install state */
764 comp
->Action
= comp
->Installed
;
766 return ERROR_SUCCESS
;
769 comp
->Action
= INSTALLSTATE_LOCAL
;
771 file_key
= MSI_RecordGetString(row
,3);
774 ERR("Unable to get file key\n");
775 return ERROR_FUNCTION_FAILED
;
778 rc
= get_file_target(package
,file_key
,&file
);
780 if (rc
!= ERROR_SUCCESS
)
782 ERR("Original file unknown %s\n",debugstr_w(file_key
));
783 return ERROR_SUCCESS
;
786 if (MSI_RecordIsNull(row
,4))
787 strcpyW(dest_name
,strrchrW(file
->TargetPath
,'\\')+1);
791 MSI_RecordGetStringW(row
,4,dest_name
,&sz
);
792 reduce_to_longfilename(dest_name
);
795 if (MSI_RecordIsNull(row
,5))
798 dest_path
= strdupW(file
->TargetPath
);
799 p
= strrchrW(dest_path
,'\\');
806 destkey
= MSI_RecordGetString(row
,5);
807 dest_path
= resolve_folder(package
, destkey
, FALSE
,FALSE
,NULL
);
811 dest_path
= msi_dup_property( package
, destkey
);
814 FIXME("Unable to get destination folder, try AppSearch properties\n");
815 return ERROR_SUCCESS
;
820 dest
= build_directory_name(2, dest_path
, dest_name
);
822 TRACE("Duplicating file %s to %s\n",debugstr_w(file
->TargetPath
),
825 if (strcmpW(file
->TargetPath
,dest
))
826 rc
= !CopyFileW(file
->TargetPath
,dest
,TRUE
);
830 if (rc
!= ERROR_SUCCESS
)
831 ERR("Failed to copy file %s -> %s, last error %d\n",
832 debugstr_w(file
->TargetPath
), debugstr_w(dest_path
), GetLastError());
834 FIXME("We should track these duplicate files as well\n");
839 msi_file_update_ui(package
, file
, szDuplicateFiles
);
841 return ERROR_SUCCESS
;
844 UINT
ACTION_DuplicateFiles(MSIPACKAGE
*package
)
848 static const WCHAR ExecSeqQuery
[] =
849 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
850 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
852 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
853 if (rc
!= ERROR_SUCCESS
)
854 return ERROR_SUCCESS
;
856 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_DuplicateFiles
, package
);
857 msiobj_release(&view
->hdr
);
862 /* compares the version of a file read from the filesystem and
863 * the version specified in the File table
865 static int msi_compare_file_version( MSIFILE
*file
)
867 WCHAR version
[MAX_PATH
];
873 r
= MsiGetFileVersionW( file
->TargetPath
, version
, &size
, NULL
, NULL
);
874 if ( r
!= ERROR_SUCCESS
)
877 return lstrcmpW( version
, file
->Version
);
880 UINT
ACTION_RemoveFiles( MSIPACKAGE
*package
)
884 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
889 if ( !file
->Component
)
891 if ( file
->Component
->Installed
== INSTALLSTATE_LOCAL
)
894 if ( file
->state
== msifs_installed
)
895 ERR("removing installed file %s\n", debugstr_w(file
->TargetPath
));
897 if ( file
->state
!= msifs_present
)
900 /* only remove a file if the version to be installed
901 * is strictly newer than the old file
903 if ( msi_compare_file_version( file
) >= 0 )
906 TRACE("removing %s\n", debugstr_w(file
->File
) );
907 if ( !DeleteFileW( file
->TargetPath
) )
908 ERR("failed to delete %s\n", debugstr_w(file
->TargetPath
) );
909 file
->state
= msifs_missing
;
912 uirow
= MSI_CreateRecord( 9 );
913 MSI_RecordSetStringW( uirow
, 1, file
->FileName
);
914 uipath
= strdupW( file
->TargetPath
);
915 p
= strrchrW(uipath
,'\\');
918 MSI_RecordSetStringW( uirow
, 9, uipath
);
919 ui_actiondata( package
, szRemoveFiles
, uirow
);
920 msiobj_release( &uirow
->hdr
);
922 /* FIXME: call ui_progress here? */
925 return ERROR_SUCCESS
;