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};
68 WCHAR source[MAX_PATH];
71 static BOOL source_matches_volume(struct media_info *mi, LPWSTR source_root)
73 WCHAR volume_name[MAX_PATH + 1];
75 if (!GetVolumeInformationW(source_root, volume_name, MAX_PATH + 1,
76 NULL, NULL, NULL, NULL, 0))
78 ERR("Failed to get volume information\n");
82 return !lstrcmpW(mi->volume_label, volume_name);
85 static UINT msi_change_media( MSIPACKAGE *package, struct media_info *mi )
88 LPWSTR error, error_dialog;
90 UINT r = ERROR_SUCCESS;
92 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
93 static const WCHAR error_prop[] = {'E','r','r','o','r','D','i','a','l','o','g',0};
95 if ( (msi_get_property_int(package, szUILevel, 0) & INSTALLUILEVEL_MASK) == INSTALLUILEVEL_NONE && !gUIHandlerA )
98 error = generate_error_string( package, 1302, 1, mi->disk_prompt );
99 error_dialog = msi_dup_property( package, error_prop );
100 source_dir = msi_dup_property( package, cszSourceDir );
101 PathStripToRootW(source_dir);
103 while ( r == ERROR_SUCCESS &&
104 !source_matches_volume(mi, source_dir) )
106 r = msi_spawn_error_dialog( package, error_dialog, error );
110 msg = strdupWtoA( error );
111 gUIHandlerA( gUIContext, MB_RETRYCANCEL | INSTALLMESSAGE_ERROR, msg );
117 msi_free( error_dialog );
118 msi_free( source_dir );
124 * This is a helper function for handling embedded cabinet media
126 static UINT writeout_cabinet_stream(MSIPACKAGE *package, LPCWSTR stream_name,
136 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
137 if (rc != ERROR_SUCCESS)
141 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
142 GetTempPathW(MAX_PATH,tmp);
144 GetTempFileNameW(tmp,stream_name,0,source);
146 track_tempfile(package, source);
147 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
148 FILE_ATTRIBUTE_NORMAL, NULL);
150 if (the_file == INVALID_HANDLE_VALUE)
152 ERR("Unable to create file %s\n",debugstr_w(source));
153 rc = ERROR_FUNCTION_FAILED;
157 WriteFile(the_file,data,size,&write,NULL);
158 CloseHandle(the_file);
159 TRACE("wrote %i bytes to %s\n",write,debugstr_w(source));
166 /* Support functions for FDI functions */
170 struct media_info *mi;
173 static void * cabinet_alloc(ULONG cb)
175 return msi_alloc(cb);
178 static void cabinet_free(void *pv)
183 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
187 DWORD dwShareMode = 0;
188 DWORD dwCreateDisposition = OPEN_EXISTING;
189 switch (oflag & _O_ACCMODE)
192 dwAccess = GENERIC_READ;
193 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
196 dwAccess = GENERIC_WRITE;
197 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
200 dwAccess = GENERIC_READ | GENERIC_WRITE;
201 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
204 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
205 dwCreateDisposition = CREATE_NEW;
206 else if (oflag & _O_CREAT)
207 dwCreateDisposition = CREATE_ALWAYS;
208 handle = CreateFileA( pszFile, dwAccess, dwShareMode, NULL,
209 dwCreateDisposition, 0, NULL );
210 if (handle == INVALID_HANDLE_VALUE)
212 return (INT_PTR) handle;
215 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
217 HANDLE handle = (HANDLE) hf;
219 if (ReadFile(handle, pv, cb, &dwRead, NULL))
224 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
226 HANDLE handle = (HANDLE) hf;
228 if (WriteFile(handle, pv, cb, &dwWritten, NULL))
233 static int cabinet_close(INT_PTR hf)
235 HANDLE handle = (HANDLE) hf;
236 return CloseHandle(handle) ? 0 : -1;
239 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
241 HANDLE handle = (HANDLE) hf;
242 /* flags are compatible and so are passed straight through */
243 return SetFilePointer(handle, dist, NULL, seektype);
246 static void msi_file_update_ui( MSIPACKAGE *package, MSIFILE *f, const WCHAR *action )
252 uirow = MSI_CreateRecord( 9 );
253 MSI_RecordSetStringW( uirow, 1, f->FileName );
254 uipath = strdupW( f->TargetPath );
255 p = strrchrW(uipath,'\\');
258 MSI_RecordSetStringW( uirow, 9, uipath);
259 MSI_RecordSetInteger( uirow, 6, f->FileSize );
260 ui_actiondata( package, action, uirow);
261 msiobj_release( &uirow->hdr );
263 ui_progress( package, 2, f->FileSize, 0, 0);
266 static UINT msi_media_get_disk_info( MSIPACKAGE *package, struct media_info *mi )
271 static const WCHAR query[] =
272 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
273 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
274 '`','D','i','s','k','I','d','`',' ','=',' ','%','i',0};
276 row = MSI_QueryGetRecord(package->db, query, mi->disk_id);
279 TRACE("Unable to query row\n");
280 return ERROR_FUNCTION_FAILED;
283 mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
284 mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
286 ptr = strrchrW(mi->source, '\\') + 1;
287 lstrcpyW(ptr, mi->cabinet);
288 msiobj_release(&row->hdr);
290 return ERROR_SUCCESS;
293 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
295 TRACE("(%d)\n", fdint);
299 case fdintPARTIAL_FILE:
301 CabData *data = (CabData *)pfdin->pv;
302 data->mi->is_continuous = FALSE;
305 case fdintNEXT_CABINET:
307 CabData *data = (CabData *)pfdin->pv;
308 struct media_info *mi = data->mi;
309 LPWSTR cab = strdupAtoW(pfdin->psz1);
312 msi_free(mi->disk_prompt);
315 mi->is_continuous = TRUE;
317 rc = msi_media_get_disk_info(data->package, mi);
318 if (rc != ERROR_SUCCESS)
320 ERR("Failed to get next cabinet information: %d\n", rc);
324 if (lstrcmpiW(mi->cabinet, cab))
327 ERR("Continuous cabinet does not match the next cabinet in the Media table\n");
333 TRACE("Searching for %s\n", debugstr_w(mi->source));
335 if (GetFileAttributesW(mi->source) == INVALID_FILE_ATTRIBUTES)
336 rc = msi_change_media(data->package, mi);
338 if (rc != ERROR_SUCCESS)
345 CabData *data = (CabData*) pfdin->pv;
351 file = strdupAtoW(pfdin->psz1);
352 f = get_loaded_file(data->package, file);
357 WARN("unknown file in cabinet (%s)\n",debugstr_a(pfdin->psz1));
361 if (f->state != msifs_missing && f->state != msifs_overwrite)
363 TRACE("Skipping extraction of %s\n",debugstr_a(pfdin->psz1));
367 msi_file_update_ui( data->package, f, szInstallFiles );
369 TRACE("extracting %s\n", debugstr_w(f->TargetPath) );
371 attrs = f->Attributes & (FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
372 if (!attrs) attrs = FILE_ATTRIBUTE_NORMAL;
374 handle = CreateFileW( f->TargetPath, GENERIC_READ | GENERIC_WRITE, 0,
375 NULL, CREATE_ALWAYS, attrs, NULL );
376 if ( handle == INVALID_HANDLE_VALUE )
378 if ( GetFileAttributesW( f->TargetPath ) != INVALID_FILE_ATTRIBUTES )
379 f->state = msifs_installed;
381 ERR("failed to create %s (error %d)\n",
382 debugstr_w( f->TargetPath ), GetLastError() );
387 f->state = msifs_installed;
388 return (INT_PTR) handle;
390 case fdintCLOSE_FILE_INFO:
394 HANDLE handle = (HANDLE) pfdin->hf;
396 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
398 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
400 if (!SetFileTime(handle, &ftLocal, 0, &ftLocal))
410 /***********************************************************************
411 * extract_cabinet_file
413 * Extract files from a cab file.
415 static BOOL extract_cabinet_file(MSIPACKAGE* package, struct media_info *mi)
417 LPSTR cabinet, cab_path = NULL;
424 TRACE("Extracting %s\n", debugstr_w(mi->source));
426 hfdi = FDICreate(cabinet_alloc, cabinet_free, cabinet_open, cabinet_read,
427 cabinet_write, cabinet_close, cabinet_seek, 0, &erf);
430 ERR("FDICreate failed\n");
434 ptr = strrchrW(mi->source, '\\') + 1;
435 cabinet = strdupWtoA(ptr);
439 cab_path = strdupWtoA(mi->source);
443 cab_path[ptr - mi->source] = '\0';
445 data.package = package;
448 ret = FDICopy(hfdi, cabinet, cab_path, 0, cabinet_notify, NULL, &data);
450 ERR("FDICopy failed\n");
458 mi->is_extracted = TRUE;
463 static VOID set_file_source(MSIPACKAGE* package, MSIFILE* file, LPCWSTR path)
465 if (!file->IsCompressed)
468 p = resolve_folder(package, file->Component->Directory, TRUE, FALSE, TRUE, NULL);
469 path = build_directory_name(2, p, file->ShortName);
470 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
473 path = build_directory_name(2, p, file->LongName);
475 file->SourcePath = path;
479 file->SourcePath = build_directory_name(2, path, file->File);
482 static void free_media_info( struct media_info *mi )
484 msi_free( mi->disk_prompt );
485 msi_free( mi->cabinet );
486 msi_free( mi->volume_label );
490 static UINT download_remote_cabinet(MSIPACKAGE *package, struct media_info *mi)
492 WCHAR temppath[MAX_PATH];
496 src = strdupW(package->BaseURL);
498 return ERROR_OUTOFMEMORY;
500 ptr = strrchrW(src, '/');
504 return ERROR_FUNCTION_FAILED;
508 ptr = strrchrW(mi->source, '\\');
512 src = msi_realloc(src, (lstrlenW(src) + lstrlenW(ptr)) * sizeof(WCHAR));
514 return ERROR_OUTOFMEMORY;
516 lstrcatW(src, ptr + 1);
519 cab = msi_download_file(src, temppath);
520 lstrcpyW(mi->source, cab);
523 return ERROR_SUCCESS;
526 static UINT load_media_info(MSIPACKAGE *package, MSIFILE *file, struct media_info *mi)
532 static const WCHAR query[] = {
533 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
534 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
535 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',
536 ' ','%','i',' ','A','N','D',' ','`','D','i','s','k','I','d','`',' ','>','=',
537 ' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ',
538 '`','D','i','s','k','I','d','`',0
541 row = MSI_QueryGetRecord(package->db, query, file->Sequence, mi->disk_id);
544 TRACE("Unable to query row\n");
545 return ERROR_FUNCTION_FAILED;
548 mi->is_extracted = FALSE;
549 mi->disk_id = MSI_RecordGetInteger(row, 1);
550 mi->last_sequence = MSI_RecordGetInteger(row, 2);
551 msi_free(mi->disk_prompt);
552 mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
553 msi_free(mi->cabinet);
554 mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
555 msi_free(mi->volume_label);
556 mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
557 msiobj_release(&row->hdr);
559 source_dir = msi_dup_property(package, cszSourceDir);
561 if (mi->cabinet && mi->cabinet[0] == '#')
563 r = writeout_cabinet_stream(package, &mi->cabinet[1], mi->source);
564 if (r != ERROR_SUCCESS)
566 ERR("Failed to extract cabinet stream\n");
567 return ERROR_FUNCTION_FAILED;
572 lstrcpyW(mi->source, source_dir);
576 lstrcatW(mi->source, mi->cabinet);
579 MsiSourceListAddMediaDiskW(package->ProductCode, NULL,
580 MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT,
581 mi->disk_id, mi->volume_label, mi->disk_prompt);
583 MsiSourceListSetInfoW(package->ProductCode, NULL,
584 MSIINSTALLCONTEXT_USERMANAGED,
585 MSICODE_PRODUCT | MSISOURCETYPE_MEDIA,
586 INSTALLPROPERTY_LASTUSEDSOURCEW, mi->source);
588 msi_free(source_dir);
589 return ERROR_SUCCESS;
592 static UINT ready_media(MSIPACKAGE *package, MSIFILE *file, struct media_info *mi)
594 UINT rc = ERROR_SUCCESS, type;
598 /* media info for continuous cabinet is already loaded */
599 if (mi->is_continuous)
600 return ERROR_SUCCESS;
602 rc = load_media_info(package, file, mi);
603 if (rc != ERROR_SUCCESS)
605 ERR("Unable to load media info\n");
606 return ERROR_FUNCTION_FAILED;
609 if (mi->volume_label && mi->disk_id > 1)
611 source_dir = msi_dup_property(package, cszSourceDir);
612 PathStripToRootW(source_dir);
613 type = GetDriveTypeW(source_dir);
615 if (type == DRIVE_CDROM || type == DRIVE_REMOVABLE)
616 found = source_matches_volume(mi, source_dir);
618 msi_free(source_dir);
621 if (file->IsCompressed &&
622 GetFileAttributesW(mi->source) == INVALID_FILE_ATTRIBUTES)
626 if (package->BaseURL && UrlIsW(package->BaseURL, URLIS_URL))
628 rc = download_remote_cabinet(package, mi);
629 if (rc == ERROR_SUCCESS &&
630 GetFileAttributesW(mi->source) != INVALID_FILE_ATTRIBUTES)
638 rc = msi_change_media(package, mi);
643 static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
646 LIST_FOR_EACH_ENTRY( *file, &package->files, MSIFILE, entry )
648 if (lstrcmpW( file_key, (*file)->File )==0)
650 if ((*file)->state >= msifs_overwrite)
651 return ERROR_SUCCESS;
653 return ERROR_FILE_NOT_FOUND;
657 return ERROR_FUNCTION_FAILED;
660 static void schedule_install_files(MSIPACKAGE *package)
664 LIST_FOR_EACH_ENTRY(file, &package->files, MSIFILE, entry)
666 if (!ACTION_VerifyComponentForAction(file->Component, INSTALLSTATE_LOCAL))
668 TRACE("File %s is not scheduled for install\n", debugstr_w(file->File));
670 ui_progress(package,2,file->FileSize,0,0);
671 file->state = msifs_skipped;
676 static UINT copy_file(MSIFILE *file)
680 ret = CopyFileW(file->SourcePath, file->TargetPath, FALSE);
683 file->state = msifs_installed;
684 return ERROR_SUCCESS;
687 return GetLastError();
690 static UINT copy_install_file(MSIFILE *file)
694 TRACE("Copying %s to %s\n", debugstr_w(file->SourcePath),
695 debugstr_w(file->TargetPath));
697 gle = copy_file(file);
698 if (gle == ERROR_SUCCESS)
701 if (gle == ERROR_ALREADY_EXISTS && file->state == msifs_overwrite)
703 TRACE("overwriting existing file\n");
706 else if (gle == ERROR_FILE_NOT_FOUND)
708 /* FIXME: this needs to be tested, I'm pretty sure it fails */
709 TRACE("Source file not found\n");
712 else if (gle == ERROR_ACCESS_DENIED)
714 SetFileAttributesW(file->TargetPath, FILE_ATTRIBUTE_NORMAL);
716 gle = copy_file(file);
717 TRACE("Overwriting existing file: %d\n", gle);
719 else if (!(file->Attributes & msidbFileAttributesVital))
721 TRACE("Ignoring error for nonvital\n");
729 * ACTION_InstallFiles()
731 * For efficiency, this is done in two passes:
732 * 1) Correct all the TargetPaths and determine what files are to be installed.
733 * 2) Extract Cabinets and copy files.
735 UINT ACTION_InstallFiles(MSIPACKAGE *package)
737 struct media_info *mi;
738 UINT rc = ERROR_SUCCESS;
742 /* increment progress bar each time action data is sent */
743 ui_progress(package,1,1,0,0);
745 /* handle the keys for the SourceList */
746 ptr = strrchrW(package->PackagePath,'\\');
750 MsiSourceListSetInfoW(package->ProductCode, NULL,
751 MSIINSTALLCONTEXT_USERMANAGED,
753 INSTALLPROPERTY_PACKAGENAMEW, ptr);
756 schedule_install_files(package);
759 * Despite MSDN specifying that the CreateFolders action
760 * should be called before InstallFiles, some installers don't
761 * do that, and they seem to work correctly. We need to create
762 * directories here to make sure that the files can be copied.
764 msi_create_component_directories( package );
766 mi = msi_alloc_zero( sizeof(struct media_info) );
768 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
770 if (file->state != msifs_missing && !mi->is_continuous && file->state != msifs_overwrite)
773 if (file->Sequence > mi->last_sequence || mi->is_continuous ||
774 (file->IsCompressed && !mi->is_extracted))
776 rc = ready_media(package, file, mi);
777 if (rc != ERROR_SUCCESS)
779 ERR("Failed to ready media\n");
780 rc = ERROR_FUNCTION_FAILED;
784 if (file->IsCompressed && !extract_cabinet_file(package, mi))
786 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi->cabinet));
787 rc = ERROR_FUNCTION_FAILED;
792 set_file_source(package, file, mi->source);
794 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
795 debugstr_w(file->TargetPath));
797 if (!file->IsCompressed)
799 msi_file_update_ui(package, file, szInstallFiles);
800 rc = copy_install_file(file);
801 if (rc != ERROR_SUCCESS)
803 ERR("Failed to copy %s to %s (%d)\n", debugstr_w(file->SourcePath),
804 debugstr_w(file->TargetPath), rc);
805 rc = ERROR_INSTALL_FAILURE;
809 else if (file->state != msifs_installed)
811 ERR("compressed file wasn't extracted (%s)\n", debugstr_w(file->TargetPath));
812 rc = ERROR_INSTALL_FAILURE;
817 free_media_info( mi );
821 static UINT ITERATE_DuplicateFiles(MSIRECORD *row, LPVOID param)
823 MSIPACKAGE *package = (MSIPACKAGE*)param;
824 WCHAR dest_name[0x100];
825 LPWSTR dest_path, dest;
826 LPCWSTR file_key, component;
832 component = MSI_RecordGetString(row,2);
833 comp = get_loaded_component(package,component);
835 if (!ACTION_VerifyComponentForAction( comp, INSTALLSTATE_LOCAL ))
837 TRACE("Skipping copy due to disabled component %s\n",
838 debugstr_w(component));
840 /* the action taken was the same as the current install state */
841 comp->Action = comp->Installed;
843 return ERROR_SUCCESS;
846 comp->Action = INSTALLSTATE_LOCAL;
848 file_key = MSI_RecordGetString(row,3);
851 ERR("Unable to get file key\n");
852 return ERROR_FUNCTION_FAILED;
855 rc = get_file_target(package,file_key,&file);
857 if (rc != ERROR_SUCCESS)
859 ERR("Original file unknown %s\n",debugstr_w(file_key));
860 return ERROR_SUCCESS;
863 if (MSI_RecordIsNull(row,4))
864 strcpyW(dest_name,strrchrW(file->TargetPath,'\\')+1);
868 MSI_RecordGetStringW(row,4,dest_name,&sz);
869 reduce_to_longfilename(dest_name);
872 if (MSI_RecordIsNull(row,5))
875 dest_path = strdupW(file->TargetPath);
876 p = strrchrW(dest_path,'\\');
883 destkey = MSI_RecordGetString(row,5);
884 dest_path = resolve_folder(package, destkey, FALSE, FALSE, TRUE, NULL);
888 dest_path = msi_dup_property( package, destkey );
891 FIXME("Unable to get destination folder, try AppSearch properties\n");
892 return ERROR_SUCCESS;
897 dest = build_directory_name(2, dest_path, dest_name);
899 TRACE("Duplicating file %s to %s\n",debugstr_w(file->TargetPath),
902 CreateDirectoryW(dest_path, NULL);
904 if (strcmpW(file->TargetPath,dest))
905 rc = !CopyFileW(file->TargetPath,dest,TRUE);
909 if (rc != ERROR_SUCCESS)
910 ERR("Failed to copy file %s -> %s, last error %d\n",
911 debugstr_w(file->TargetPath), debugstr_w(dest_path), GetLastError());
913 FIXME("We should track these duplicate files as well\n");
918 msi_file_update_ui(package, file, szDuplicateFiles);
920 return ERROR_SUCCESS;
923 UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
927 static const WCHAR ExecSeqQuery[] =
928 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
929 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
931 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
932 if (rc != ERROR_SUCCESS)
933 return ERROR_SUCCESS;
935 rc = MSI_IterateRecords(view, NULL, ITERATE_DuplicateFiles, package);
936 msiobj_release(&view->hdr);
941 /* compares the version of a file read from the filesystem and
942 * the version specified in the File table
944 static int msi_compare_file_version( MSIFILE *file )
946 WCHAR version[MAX_PATH];
952 r = MsiGetFileVersionW( file->TargetPath, version, &size, NULL, NULL );
953 if ( r != ERROR_SUCCESS )
956 return lstrcmpW( version, file->Version );
959 UINT ACTION_RemoveFiles( MSIPACKAGE *package )
963 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
968 if ( !file->Component )
970 if ( file->Component->Installed == INSTALLSTATE_LOCAL )
973 if ( file->state == msifs_installed )
974 ERR("removing installed file %s\n", debugstr_w(file->TargetPath));
976 if ( file->state != msifs_present )
979 /* only remove a file if the version to be installed
980 * is strictly newer than the old file
982 if ( msi_compare_file_version( file ) >= 0 )
985 TRACE("removing %s\n", debugstr_w(file->File) );
986 if ( !DeleteFileW( file->TargetPath ) )
987 ERR("failed to delete %s\n", debugstr_w(file->TargetPath) );
988 file->state = msifs_missing;
991 uirow = MSI_CreateRecord( 9 );
992 MSI_RecordSetStringW( uirow, 1, file->FileName );
993 uipath = strdupW( file->TargetPath );
994 p = strrchrW(uipath,'\\');
997 MSI_RecordSetStringW( uirow, 9, uipath);
998 ui_actiondata( package, szRemoveFiles, uirow);
999 msiobj_release( &uirow->hdr );
1001 /* FIXME: call ui_progress here? */
1004 return ERROR_SUCCESS;