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};
67 WCHAR source
[MAX_PATH
];
70 static UINT
msi_change_media( MSIPACKAGE
*package
, struct media_info
*mi
)
73 LPWSTR error
, error_dialog
;
74 UINT r
= ERROR_SUCCESS
;
76 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
77 static const WCHAR error_prop
[] = {'E','r','r','o','r','D','i','a','l','o','g',0};
79 if ( msi_get_property_int(package
, szUILevel
, 0) == INSTALLUILEVEL_NONE
&& !gUIHandlerA
)
82 error
= generate_error_string( package
, 1302, 1, mi
->disk_prompt
);
83 error_dialog
= msi_dup_property( package
, error_prop
);
85 while ( r
== ERROR_SUCCESS
&& GetFileAttributesW( mi
->source
) == INVALID_FILE_ATTRIBUTES
)
87 r
= msi_spawn_error_dialog( package
, error_dialog
, error
);
91 msg
= strdupWtoA( error
);
92 gUIHandlerA( gUIContext
, MB_RETRYCANCEL
| INSTALLMESSAGE_ERROR
, msg
);
98 msi_free( error_dialog
);
104 * This is a helper function for handling embedded cabinet media
106 static UINT
writeout_cabinet_stream(MSIPACKAGE
*package
, LPCWSTR stream_name
,
116 rc
= read_raw_stream_data(package
->db
,stream_name
,&data
,&size
);
117 if (rc
!= ERROR_SUCCESS
)
121 if (MSI_GetPropertyW(package
, cszTempFolder
, tmp
, &write
))
122 GetTempPathW(MAX_PATH
,tmp
);
124 GetTempFileNameW(tmp
,stream_name
,0,source
);
126 track_tempfile(package
, source
);
127 the_file
= CreateFileW(source
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
128 FILE_ATTRIBUTE_NORMAL
, NULL
);
130 if (the_file
== INVALID_HANDLE_VALUE
)
132 ERR("Unable to create file %s\n",debugstr_w(source
));
133 rc
= ERROR_FUNCTION_FAILED
;
137 WriteFile(the_file
,data
,size
,&write
,NULL
);
138 CloseHandle(the_file
);
139 TRACE("wrote %i bytes to %s\n",write
,debugstr_w(source
));
146 /* Support functions for FDI functions */
150 struct media_info
*mi
;
153 static void * cabinet_alloc(ULONG cb
)
155 return msi_alloc(cb
);
158 static void cabinet_free(void *pv
)
163 static INT_PTR
cabinet_open(char *pszFile
, int oflag
, int pmode
)
167 DWORD dwShareMode
= 0;
168 DWORD dwCreateDisposition
= OPEN_EXISTING
;
169 switch (oflag
& _O_ACCMODE
)
172 dwAccess
= GENERIC_READ
;
173 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_DELETE
;
176 dwAccess
= GENERIC_WRITE
;
177 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
180 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
181 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
184 if ((oflag
& (_O_CREAT
| _O_EXCL
)) == (_O_CREAT
| _O_EXCL
))
185 dwCreateDisposition
= CREATE_NEW
;
186 else if (oflag
& _O_CREAT
)
187 dwCreateDisposition
= CREATE_ALWAYS
;
188 handle
= CreateFileA( pszFile
, dwAccess
, dwShareMode
, NULL
,
189 dwCreateDisposition
, 0, NULL
);
190 if (handle
== INVALID_HANDLE_VALUE
)
192 return (INT_PTR
) handle
;
195 static UINT
cabinet_read(INT_PTR hf
, void *pv
, UINT cb
)
197 HANDLE handle
= (HANDLE
) hf
;
199 if (ReadFile(handle
, pv
, cb
, &dwRead
, NULL
))
204 static UINT
cabinet_write(INT_PTR hf
, void *pv
, UINT cb
)
206 HANDLE handle
= (HANDLE
) hf
;
208 if (WriteFile(handle
, pv
, cb
, &dwWritten
, NULL
))
213 static int cabinet_close(INT_PTR hf
)
215 HANDLE handle
= (HANDLE
) hf
;
216 return CloseHandle(handle
) ? 0 : -1;
219 static long cabinet_seek(INT_PTR hf
, long dist
, int seektype
)
221 HANDLE handle
= (HANDLE
) hf
;
222 /* flags are compatible and so are passed straight through */
223 return SetFilePointer(handle
, dist
, NULL
, seektype
);
226 static void msi_file_update_ui( MSIPACKAGE
*package
, MSIFILE
*f
, const WCHAR
*action
)
232 uirow
= MSI_CreateRecord( 9 );
233 MSI_RecordSetStringW( uirow
, 1, f
->FileName
);
234 uipath
= strdupW( f
->TargetPath
);
235 p
= strrchrW(uipath
,'\\');
238 MSI_RecordSetStringW( uirow
, 9, uipath
);
239 MSI_RecordSetInteger( uirow
, 6, f
->FileSize
);
240 ui_actiondata( package
, action
, uirow
);
241 msiobj_release( &uirow
->hdr
);
243 ui_progress( package
, 2, f
->FileSize
, 0, 0);
246 static UINT
msi_media_get_disk_info( MSIPACKAGE
*package
, struct media_info
*mi
)
251 static const WCHAR query
[] =
252 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
253 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
254 '`','D','i','s','k','I','d','`',' ','=',' ','%','i',0};
256 row
= MSI_QueryGetRecord(package
->db
, query
, mi
->disk_id
);
259 TRACE("Unable to query row\n");
260 return ERROR_FUNCTION_FAILED
;
263 mi
->disk_prompt
= strdupW(MSI_RecordGetString(row
, 3));
264 mi
->cabinet
= strdupW(MSI_RecordGetString(row
, 4));
266 ptr
= strrchrW(mi
->source
, '\\') + 1;
267 lstrcpyW(ptr
, mi
->cabinet
);
268 msiobj_release(&row
->hdr
);
270 return ERROR_SUCCESS
;
273 static INT_PTR
cabinet_notify(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
275 TRACE("(%d)\n", fdint
);
279 case fdintPARTIAL_FILE
:
281 CabData
*data
= (CabData
*)pfdin
->pv
;
282 data
->mi
->is_continuous
= FALSE
;
285 case fdintNEXT_CABINET
:
287 CabData
*data
= (CabData
*)pfdin
->pv
;
288 struct media_info
*mi
= data
->mi
;
289 LPWSTR cab
= strdupAtoW(pfdin
->psz1
);
292 msi_free(mi
->disk_prompt
);
295 mi
->is_continuous
= TRUE
;
297 rc
= msi_media_get_disk_info(data
->package
, mi
);
298 if (rc
!= ERROR_SUCCESS
)
300 ERR("Failed to get next cabinet information: %d\n", rc
);
304 if (lstrcmpiW(mi
->cabinet
, cab
))
307 ERR("Continuous cabinet does not match the next cabinet in the Media table\n");
313 TRACE("Searching for %s\n", debugstr_w(mi
->source
));
315 if (GetFileAttributesW(mi
->source
) == INVALID_FILE_ATTRIBUTES
)
316 rc
= msi_change_media(data
->package
, mi
);
318 if (rc
!= ERROR_SUCCESS
)
325 CabData
*data
= (CabData
*) pfdin
->pv
;
331 file
= strdupAtoW(pfdin
->psz1
);
332 f
= get_loaded_file(data
->package
, file
);
337 WARN("unknown file in cabinet (%s)\n",debugstr_a(pfdin
->psz1
));
341 if (f
->state
!= msifs_missing
&& f
->state
!= msifs_overwrite
)
343 TRACE("Skipping extraction of %s\n",debugstr_a(pfdin
->psz1
));
347 msi_file_update_ui( data
->package
, f
, szInstallFiles
);
349 TRACE("extracting %s\n", debugstr_w(f
->TargetPath
) );
351 attrs
= f
->Attributes
& (FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
);
352 if (!attrs
) attrs
= FILE_ATTRIBUTE_NORMAL
;
354 handle
= CreateFileW( f
->TargetPath
, GENERIC_READ
| GENERIC_WRITE
, 0,
355 NULL
, CREATE_ALWAYS
, attrs
, NULL
);
356 if ( handle
== INVALID_HANDLE_VALUE
)
358 if ( GetFileAttributesW( f
->TargetPath
) != INVALID_FILE_ATTRIBUTES
)
359 f
->state
= msifs_installed
;
361 ERR("failed to create %s (error %d)\n",
362 debugstr_w( f
->TargetPath
), GetLastError() );
367 f
->state
= msifs_installed
;
368 return (INT_PTR
) handle
;
370 case fdintCLOSE_FILE_INFO
:
374 HANDLE handle
= (HANDLE
) pfdin
->hf
;
376 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
378 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
380 if (!SetFileTime(handle
, &ftLocal
, 0, &ftLocal
))
390 /***********************************************************************
391 * extract_cabinet_file
393 * Extract files from a cab file.
395 static BOOL
extract_cabinet_file(MSIPACKAGE
* package
, struct media_info
*mi
)
397 LPSTR cabinet
, cab_path
= NULL
;
404 TRACE("Extracting %s\n", debugstr_w(mi
->source
));
406 hfdi
= FDICreate(cabinet_alloc
, cabinet_free
, cabinet_open
, cabinet_read
,
407 cabinet_write
, cabinet_close
, cabinet_seek
, 0, &erf
);
410 ERR("FDICreate failed\n");
414 ptr
= strrchrW(mi
->source
, '\\') + 1;
415 cabinet
= strdupWtoA(ptr
);
419 cab_path
= strdupWtoA(mi
->source
);
423 cab_path
[ptr
- mi
->source
] = '\0';
425 data
.package
= package
;
428 ret
= FDICopy(hfdi
, cabinet
, cab_path
, 0, cabinet_notify
, NULL
, &data
);
430 ERR("FDICopy failed\n");
440 static VOID
set_file_source(MSIPACKAGE
* package
, MSIFILE
* file
, LPCWSTR path
)
442 if (!file
->IsCompressed
)
445 p
= resolve_folder(package
, file
->Component
->Directory
, TRUE
, FALSE
, NULL
);
446 path
= build_directory_name(2, p
, file
->ShortName
);
447 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW( path
))
450 path
= build_directory_name(2, p
, file
->LongName
);
452 file
->SourcePath
= path
;
456 file
->SourcePath
= build_directory_name(2, path
, file
->File
);
459 static void free_media_info( struct media_info
*mi
)
461 msi_free( mi
->disk_prompt
);
462 msi_free( mi
->cabinet
);
463 msi_free( mi
->volume_label
);
467 static UINT
download_remote_cabinet(MSIPACKAGE
*package
, struct media_info
*mi
)
469 WCHAR temppath
[MAX_PATH
];
473 src
= strdupW(package
->BaseURL
);
475 return ERROR_OUTOFMEMORY
;
477 ptr
= strrchrW(src
, '/');
481 return ERROR_FUNCTION_FAILED
;
485 ptr
= strrchrW(mi
->source
, '\\');
489 src
= msi_realloc(src
, (lstrlenW(src
) + lstrlenW(ptr
)) * sizeof(WCHAR
));
491 return ERROR_OUTOFMEMORY
;
493 lstrcatW(src
, ptr
+ 1);
496 cab
= msi_download_file(src
, temppath
);
497 lstrcpyW(mi
->source
, cab
);
500 return ERROR_SUCCESS
;
503 static UINT
load_media_info(MSIPACKAGE
*package
, MSIFILE
*file
, struct media_info
*mi
)
509 static const WCHAR query
[] = {
510 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
511 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
512 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',
513 ' ','%','i',' ','A','N','D',' ','`','D','i','s','k','I','d','`',' ','>','=',
514 ' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ',
515 '`','D','i','s','k','I','d','`',0
518 row
= MSI_QueryGetRecord(package
->db
, query
, file
->Sequence
, mi
->disk_id
);
521 TRACE("Unable to query row\n");
522 return ERROR_FUNCTION_FAILED
;
525 mi
->disk_id
= MSI_RecordGetInteger(row
, 1);
526 mi
->last_sequence
= MSI_RecordGetInteger(row
, 2);
527 msi_free(mi
->disk_prompt
);
528 mi
->disk_prompt
= strdupW(MSI_RecordGetString(row
, 3));
529 msi_free(mi
->cabinet
);
530 mi
->cabinet
= strdupW(MSI_RecordGetString(row
, 4));
531 msi_free(mi
->volume_label
);
532 mi
->volume_label
= strdupW(MSI_RecordGetString(row
, 5));
533 msiobj_release(&row
->hdr
);
535 source_dir
= msi_dup_property(package
, cszSourceDir
);
537 if (mi
->cabinet
&& mi
->cabinet
[0] == '#')
539 r
= writeout_cabinet_stream(package
, &mi
->cabinet
[1], mi
->source
);
540 if (r
!= ERROR_SUCCESS
)
542 ERR("Failed to extract cabinet stream\n");
543 return ERROR_FUNCTION_FAILED
;
548 lstrcpyW(mi
->source
, source_dir
);
552 lstrcatW(mi
->source
, mi
->cabinet
);
555 MsiSourceListAddMediaDiskW(package
->ProductCode
, NULL
,
556 MSIINSTALLCONTEXT_USERMANAGED
, MSICODE_PRODUCT
,
557 mi
->disk_id
, mi
->volume_label
, mi
->disk_prompt
);
559 MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
560 MSIINSTALLCONTEXT_USERMANAGED
,
561 MSICODE_PRODUCT
| MSISOURCETYPE_MEDIA
,
562 INSTALLPROPERTY_LASTUSEDSOURCEW
, mi
->source
);
564 msi_free(source_dir
);
565 return ERROR_SUCCESS
;
568 static UINT
ready_media(MSIPACKAGE
*package
, MSIFILE
*file
, struct media_info
*mi
)
570 UINT rc
= ERROR_SUCCESS
;
573 /* media info for continuous cabinet is already loaded */
574 if (mi
->is_continuous
)
575 return ERROR_SUCCESS
;
577 rc
= load_media_info(package
, file
, mi
);
578 if (rc
!= ERROR_SUCCESS
)
580 ERR("Unable to load media info\n");
581 return ERROR_FUNCTION_FAILED
;
584 if (file
->IsCompressed
&&
585 GetFileAttributesW(mi
->source
) == INVALID_FILE_ATTRIBUTES
)
587 if (package
->BaseURL
&& UrlIsW(package
->BaseURL
, URLIS_URL
))
589 rc
= download_remote_cabinet(package
, mi
);
590 if (rc
== ERROR_SUCCESS
&&
591 GetFileAttributesW(mi
->source
) != INVALID_FILE_ATTRIBUTES
)
598 rc
= msi_change_media(package
, mi
);
604 static UINT
get_file_target(MSIPACKAGE
*package
, LPCWSTR file_key
,
607 LIST_FOR_EACH_ENTRY( *file
, &package
->files
, MSIFILE
, entry
)
609 if (lstrcmpW( file_key
, (*file
)->File
)==0)
611 if ((*file
)->state
>= msifs_overwrite
)
612 return ERROR_SUCCESS
;
614 return ERROR_FILE_NOT_FOUND
;
618 return ERROR_FUNCTION_FAILED
;
621 static void schedule_install_files(MSIPACKAGE
*package
)
625 LIST_FOR_EACH_ENTRY(file
, &package
->files
, MSIFILE
, entry
)
627 if (!ACTION_VerifyComponentForAction(file
->Component
, INSTALLSTATE_LOCAL
))
629 TRACE("File %s is not scheduled for install\n", debugstr_w(file
->File
));
631 ui_progress(package
,2,file
->FileSize
,0,0);
632 file
->state
= msifs_skipped
;
637 static UINT
copy_install_file(MSIFILE
*file
)
642 TRACE("Copying %s to %s\n", debugstr_w(file
->SourcePath
),
643 debugstr_w(file
->TargetPath
));
645 ret
= CopyFileW(file
->SourcePath
, file
->TargetPath
, FALSE
);
648 file
->state
= msifs_installed
;
649 return ERROR_SUCCESS
;
652 gle
= GetLastError();
653 if (gle
== ERROR_ALREADY_EXISTS
&& file
->state
== msifs_overwrite
)
655 TRACE("overwriting existing file\n");
658 else if (gle
== ERROR_FILE_NOT_FOUND
)
660 /* FIXME: this needs to be tested, I'm pretty sure it fails */
661 TRACE("Source file not found\n");
664 else if (!(file
->Attributes
& msidbFileAttributesVital
))
666 TRACE("Ignoring error for nonvital\n");
674 * ACTION_InstallFiles()
676 * For efficiency, this is done in two passes:
677 * 1) Correct all the TargetPaths and determine what files are to be installed.
678 * 2) Extract Cabinets and copy files.
680 UINT
ACTION_InstallFiles(MSIPACKAGE
*package
)
682 struct media_info
*mi
;
683 UINT rc
= ERROR_SUCCESS
;
687 /* increment progress bar each time action data is sent */
688 ui_progress(package
,1,1,0,0);
690 /* handle the keys for the SourceList */
691 ptr
= strrchrW(package
->PackagePath
,'\\');
695 MsiSourceListSetInfoW(package
->ProductCode
, NULL
,
696 MSIINSTALLCONTEXT_USERMANAGED
,
698 INSTALLPROPERTY_PACKAGENAMEW
, ptr
);
701 schedule_install_files(package
);
704 * Despite MSDN specifying that the CreateFolders action
705 * should be called before InstallFiles, some installers don't
706 * do that, and they seem to work correctly. We need to create
707 * directories here to make sure that the files can be copied.
709 msi_create_component_directories( package
);
711 mi
= msi_alloc_zero( sizeof(struct media_info
) );
713 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
715 if (file
->state
!= msifs_missing
&& file
->state
!= msifs_overwrite
)
718 if (file
->Sequence
> mi
->last_sequence
|| mi
->is_continuous
)
720 rc
= ready_media(package
, file
, mi
);
721 if (rc
!= ERROR_SUCCESS
)
723 ERR("Failed to ready media\n");
724 rc
= ERROR_FUNCTION_FAILED
;
728 if (file
->IsCompressed
&& !extract_cabinet_file(package
, mi
))
730 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi
->cabinet
));
731 rc
= ERROR_FUNCTION_FAILED
;
736 set_file_source(package
, file
, mi
->source
);
738 TRACE("file paths %s to %s\n",debugstr_w(file
->SourcePath
),
739 debugstr_w(file
->TargetPath
));
741 if (!file
->IsCompressed
)
743 rc
= copy_install_file(file
);
744 if (rc
!= ERROR_SUCCESS
)
746 ERR("Failed to copy %s to %s (%d)\n", debugstr_w(file
->SourcePath
),
747 debugstr_w(file
->TargetPath
), rc
);
748 rc
= ERROR_INSTALL_FAILURE
;
752 else if (file
->state
!= msifs_installed
)
754 ERR("compressed file wasn't extracted (%s)\n", debugstr_w(file
->TargetPath
));
755 rc
= ERROR_INSTALL_FAILURE
;
760 free_media_info( mi
);
764 static UINT
ITERATE_DuplicateFiles(MSIRECORD
*row
, LPVOID param
)
766 MSIPACKAGE
*package
= (MSIPACKAGE
*)param
;
767 WCHAR dest_name
[0x100];
768 LPWSTR dest_path
, dest
;
769 LPCWSTR file_key
, component
;
775 component
= MSI_RecordGetString(row
,2);
776 comp
= get_loaded_component(package
,component
);
778 if (!ACTION_VerifyComponentForAction( comp
, INSTALLSTATE_LOCAL
))
780 TRACE("Skipping copy due to disabled component %s\n",
781 debugstr_w(component
));
783 /* the action taken was the same as the current install state */
784 comp
->Action
= comp
->Installed
;
786 return ERROR_SUCCESS
;
789 comp
->Action
= INSTALLSTATE_LOCAL
;
791 file_key
= MSI_RecordGetString(row
,3);
794 ERR("Unable to get file key\n");
795 return ERROR_FUNCTION_FAILED
;
798 rc
= get_file_target(package
,file_key
,&file
);
800 if (rc
!= ERROR_SUCCESS
)
802 ERR("Original file unknown %s\n",debugstr_w(file_key
));
803 return ERROR_SUCCESS
;
806 if (MSI_RecordIsNull(row
,4))
807 strcpyW(dest_name
,strrchrW(file
->TargetPath
,'\\')+1);
811 MSI_RecordGetStringW(row
,4,dest_name
,&sz
);
812 reduce_to_longfilename(dest_name
);
815 if (MSI_RecordIsNull(row
,5))
818 dest_path
= strdupW(file
->TargetPath
);
819 p
= strrchrW(dest_path
,'\\');
826 destkey
= MSI_RecordGetString(row
,5);
827 dest_path
= resolve_folder(package
, destkey
, FALSE
,FALSE
,NULL
);
831 dest_path
= msi_dup_property( package
, destkey
);
834 FIXME("Unable to get destination folder, try AppSearch properties\n");
835 return ERROR_SUCCESS
;
840 dest
= build_directory_name(2, dest_path
, dest_name
);
842 TRACE("Duplicating file %s to %s\n",debugstr_w(file
->TargetPath
),
845 if (strcmpW(file
->TargetPath
,dest
))
846 rc
= !CopyFileW(file
->TargetPath
,dest
,TRUE
);
850 if (rc
!= ERROR_SUCCESS
)
851 ERR("Failed to copy file %s -> %s, last error %d\n",
852 debugstr_w(file
->TargetPath
), debugstr_w(dest_path
), GetLastError());
854 FIXME("We should track these duplicate files as well\n");
859 msi_file_update_ui(package
, file
, szDuplicateFiles
);
861 return ERROR_SUCCESS
;
864 UINT
ACTION_DuplicateFiles(MSIPACKAGE
*package
)
868 static const WCHAR ExecSeqQuery
[] =
869 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
870 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
872 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
873 if (rc
!= ERROR_SUCCESS
)
874 return ERROR_SUCCESS
;
876 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_DuplicateFiles
, package
);
877 msiobj_release(&view
->hdr
);
882 /* compares the version of a file read from the filesystem and
883 * the version specified in the File table
885 static int msi_compare_file_version( MSIFILE
*file
)
887 WCHAR version
[MAX_PATH
];
893 r
= MsiGetFileVersionW( file
->TargetPath
, version
, &size
, NULL
, NULL
);
894 if ( r
!= ERROR_SUCCESS
)
897 return lstrcmpW( version
, file
->Version
);
900 UINT
ACTION_RemoveFiles( MSIPACKAGE
*package
)
904 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
909 if ( !file
->Component
)
911 if ( file
->Component
->Installed
== INSTALLSTATE_LOCAL
)
914 if ( file
->state
== msifs_installed
)
915 ERR("removing installed file %s\n", debugstr_w(file
->TargetPath
));
917 if ( file
->state
!= msifs_present
)
920 /* only remove a file if the version to be installed
921 * is strictly newer than the old file
923 if ( msi_compare_file_version( file
) >= 0 )
926 TRACE("removing %s\n", debugstr_w(file
->File
) );
927 if ( !DeleteFileW( file
->TargetPath
) )
928 ERR("failed to delete %s\n", debugstr_w(file
->TargetPath
) );
929 file
->state
= msifs_missing
;
932 uirow
= MSI_CreateRecord( 9 );
933 MSI_RecordSetStringW( uirow
, 1, file
->FileName
);
934 uipath
= strdupW( file
->TargetPath
);
935 p
= strrchrW(uipath
,'\\');
938 MSI_RecordSetStringW( uirow
, 9, uipath
);
939 ui_actiondata( package
, szRemoveFiles
, uirow
);
940 msiobj_release( &uirow
->hdr
);
942 /* FIXME: call ui_progress here? */
945 return ERROR_SUCCESS
;