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};
69 WCHAR source[MAX_PATH];
72 static BOOL source_matches_volume(struct media_info *mi, LPWSTR source_root)
74 WCHAR volume_name[MAX_PATH + 1];
76 if (!GetVolumeInformationW(source_root, volume_name, MAX_PATH + 1,
77 NULL, NULL, NULL, NULL, 0))
79 ERR("Failed to get volume information\n");
83 return !lstrcmpW(mi->volume_label, volume_name);
86 static UINT msi_change_media( MSIPACKAGE *package, struct media_info *mi )
89 LPWSTR error, error_dialog;
91 UINT r = ERROR_SUCCESS;
93 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
94 static const WCHAR error_prop[] = {'E','r','r','o','r','D','i','a','l','o','g',0};
96 if ( (msi_get_property_int(package, szUILevel, 0) & INSTALLUILEVEL_MASK) == INSTALLUILEVEL_NONE && !gUIHandlerA )
99 error = generate_error_string( package, 1302, 1, mi->disk_prompt );
100 error_dialog = msi_dup_property( package, error_prop );
101 source_dir = msi_dup_property( package, cszSourceDir );
102 PathStripToRootW(source_dir);
104 while ( r == ERROR_SUCCESS &&
105 !source_matches_volume(mi, source_dir) )
107 r = msi_spawn_error_dialog( package, error_dialog, error );
111 msg = strdupWtoA( error );
112 gUIHandlerA( gUIContext, MB_RETRYCANCEL | INSTALLMESSAGE_ERROR, msg );
118 msi_free( error_dialog );
119 msi_free( source_dir );
125 * This is a helper function for handling embedded cabinet media
127 static UINT writeout_cabinet_stream(MSIPACKAGE *package, LPCWSTR stream_name,
137 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
138 if (rc != ERROR_SUCCESS)
142 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
143 GetTempPathW(MAX_PATH,tmp);
145 GetTempFileNameW(tmp,stream_name,0,source);
147 track_tempfile(package, source);
148 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
149 FILE_ATTRIBUTE_NORMAL, NULL);
151 if (the_file == INVALID_HANDLE_VALUE)
153 ERR("Unable to create file %s\n",debugstr_w(source));
154 rc = ERROR_FUNCTION_FAILED;
158 WriteFile(the_file,data,size,&write,NULL);
159 CloseHandle(the_file);
160 TRACE("wrote %i bytes to %s\n",write,debugstr_w(source));
167 /* Support functions for FDI functions */
171 struct media_info *mi;
174 static void * cabinet_alloc(ULONG cb)
176 return msi_alloc(cb);
179 static void cabinet_free(void *pv)
184 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
188 DWORD dwShareMode = 0;
189 DWORD dwCreateDisposition = OPEN_EXISTING;
190 switch (oflag & _O_ACCMODE)
193 dwAccess = GENERIC_READ;
194 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
197 dwAccess = GENERIC_WRITE;
198 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
201 dwAccess = GENERIC_READ | GENERIC_WRITE;
202 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
205 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
206 dwCreateDisposition = CREATE_NEW;
207 else if (oflag & _O_CREAT)
208 dwCreateDisposition = CREATE_ALWAYS;
209 handle = CreateFileA( pszFile, dwAccess, dwShareMode, NULL,
210 dwCreateDisposition, 0, NULL );
211 if (handle == INVALID_HANDLE_VALUE)
213 return (INT_PTR) handle;
216 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
218 HANDLE handle = (HANDLE) hf;
220 if (ReadFile(handle, pv, cb, &dwRead, NULL))
225 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
227 HANDLE handle = (HANDLE) hf;
229 if (WriteFile(handle, pv, cb, &dwWritten, NULL))
234 static int cabinet_close(INT_PTR hf)
236 HANDLE handle = (HANDLE) hf;
237 return CloseHandle(handle) ? 0 : -1;
240 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
242 HANDLE handle = (HANDLE) hf;
243 /* flags are compatible and so are passed straight through */
244 return SetFilePointer(handle, dist, NULL, seektype);
247 static void msi_file_update_ui( MSIPACKAGE *package, MSIFILE *f, const WCHAR *action )
253 uirow = MSI_CreateRecord( 9 );
254 MSI_RecordSetStringW( uirow, 1, f->FileName );
255 uipath = strdupW( f->TargetPath );
256 p = strrchrW(uipath,'\\');
259 MSI_RecordSetStringW( uirow, 9, uipath);
260 MSI_RecordSetInteger( uirow, 6, f->FileSize );
261 ui_actiondata( package, action, uirow);
262 msiobj_release( &uirow->hdr );
264 ui_progress( package, 2, f->FileSize, 0, 0);
267 static UINT msi_media_get_disk_info( MSIPACKAGE *package, struct media_info *mi )
272 static const WCHAR query[] =
273 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
274 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
275 '`','D','i','s','k','I','d','`',' ','=',' ','%','i',0};
277 row = MSI_QueryGetRecord(package->db, query, mi->disk_id);
280 TRACE("Unable to query row\n");
281 return ERROR_FUNCTION_FAILED;
284 mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
285 mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
286 mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
288 if (!mi->first_volume)
289 mi->first_volume = strdupW(mi->volume_label);
291 ptr = strrchrW(mi->source, '\\') + 1;
292 lstrcpyW(ptr, mi->cabinet);
293 msiobj_release(&row->hdr);
295 return ERROR_SUCCESS;
298 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
300 TRACE("(%d)\n", fdint);
304 case fdintPARTIAL_FILE:
306 CabData *data = (CabData *)pfdin->pv;
307 data->mi->is_continuous = FALSE;
310 case fdintNEXT_CABINET:
312 CabData *data = (CabData *)pfdin->pv;
313 struct media_info *mi = data->mi;
314 LPWSTR cab = strdupAtoW(pfdin->psz1);
317 msi_free(mi->disk_prompt);
318 msi_free(mi->cabinet);
319 msi_free(mi->volume_label);
320 mi->disk_prompt = NULL;
322 mi->volume_label = NULL;
325 mi->is_continuous = TRUE;
327 rc = msi_media_get_disk_info(data->package, mi);
328 if (rc != ERROR_SUCCESS)
330 ERR("Failed to get next cabinet information: %d\n", rc);
334 if (lstrcmpiW(mi->cabinet, cab))
337 ERR("Continuous cabinet does not match the next cabinet in the Media table\n");
343 TRACE("Searching for %s\n", debugstr_w(mi->source));
345 if (GetFileAttributesW(mi->source) == INVALID_FILE_ATTRIBUTES)
346 rc = msi_change_media(data->package, mi);
348 if (rc != ERROR_SUCCESS)
355 CabData *data = (CabData*) pfdin->pv;
361 file = strdupAtoW(pfdin->psz1);
362 f = get_loaded_file(data->package, file);
367 WARN("unknown file in cabinet (%s)\n",debugstr_a(pfdin->psz1));
371 if (f->state != msifs_missing && f->state != msifs_overwrite)
373 TRACE("Skipping extraction of %s\n",debugstr_a(pfdin->psz1));
377 msi_file_update_ui( data->package, f, szInstallFiles );
379 TRACE("extracting %s\n", debugstr_w(f->TargetPath) );
381 attrs = f->Attributes & (FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
382 if (!attrs) attrs = FILE_ATTRIBUTE_NORMAL;
384 handle = CreateFileW( f->TargetPath, GENERIC_READ | GENERIC_WRITE, 0,
385 NULL, CREATE_ALWAYS, attrs, NULL );
386 if ( handle == INVALID_HANDLE_VALUE )
388 if ( GetFileAttributesW( f->TargetPath ) != INVALID_FILE_ATTRIBUTES )
389 f->state = msifs_installed;
391 ERR("failed to create %s (error %d)\n",
392 debugstr_w( f->TargetPath ), GetLastError() );
397 f->state = msifs_installed;
398 return (INT_PTR) handle;
400 case fdintCLOSE_FILE_INFO:
404 HANDLE handle = (HANDLE) pfdin->hf;
406 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
408 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
410 if (!SetFileTime(handle, &ftLocal, 0, &ftLocal))
420 /***********************************************************************
421 * extract_cabinet_file
423 * Extract files from a cab file.
425 static BOOL extract_cabinet_file(MSIPACKAGE* package, struct media_info *mi)
427 LPSTR cabinet, cab_path = NULL;
434 TRACE("Extracting %s\n", debugstr_w(mi->source));
436 hfdi = FDICreate(cabinet_alloc, cabinet_free, cabinet_open, cabinet_read,
437 cabinet_write, cabinet_close, cabinet_seek, 0, &erf);
440 ERR("FDICreate failed\n");
444 ptr = strrchrW(mi->source, '\\') + 1;
445 cabinet = strdupWtoA(ptr);
449 cab_path = strdupWtoA(mi->source);
453 cab_path[ptr - mi->source] = '\0';
455 data.package = package;
458 ret = FDICopy(hfdi, cabinet, cab_path, 0, cabinet_notify, NULL, &data);
460 ERR("FDICopy failed\n");
468 mi->is_extracted = TRUE;
473 static VOID set_file_source(MSIPACKAGE* package, MSIFILE* file, LPCWSTR path)
475 if (!file->IsCompressed)
478 p = resolve_folder(package, file->Component->Directory, TRUE, FALSE, TRUE, NULL);
479 path = build_directory_name(2, p, file->ShortName);
480 if (file->LongName &&
481 INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
484 path = build_directory_name(2, p, file->LongName);
486 file->SourcePath = path;
490 file->SourcePath = build_directory_name(2, path, file->File);
493 static void free_media_info( struct media_info *mi )
495 msi_free( mi->disk_prompt );
496 msi_free( mi->cabinet );
497 msi_free( mi->volume_label );
498 msi_free( mi->first_volume );
502 static UINT download_remote_cabinet(MSIPACKAGE *package, struct media_info *mi)
504 WCHAR temppath[MAX_PATH];
508 src = strdupW(package->BaseURL);
510 return ERROR_OUTOFMEMORY;
512 ptr = strrchrW(src, '/');
516 return ERROR_FUNCTION_FAILED;
520 ptr = strrchrW(mi->source, '\\');
524 src = msi_realloc(src, (lstrlenW(src) + lstrlenW(ptr)) * sizeof(WCHAR));
526 return ERROR_OUTOFMEMORY;
528 lstrcatW(src, ptr + 1);
531 cab = msi_download_file(src, temppath);
532 lstrcpyW(mi->source, cab);
535 return ERROR_SUCCESS;
538 static UINT load_media_info(MSIPACKAGE *package, MSIFILE *file, struct media_info *mi)
544 static const WCHAR query[] = {
545 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
546 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
547 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',
548 ' ','%','i',' ','A','N','D',' ','`','D','i','s','k','I','d','`',' ','>','=',
549 ' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ',
550 '`','D','i','s','k','I','d','`',0
553 row = MSI_QueryGetRecord(package->db, query, file->Sequence, mi->disk_id);
556 TRACE("Unable to query row\n");
557 return ERROR_FUNCTION_FAILED;
560 mi->is_extracted = FALSE;
561 mi->disk_id = MSI_RecordGetInteger(row, 1);
562 mi->last_sequence = MSI_RecordGetInteger(row, 2);
563 msi_free(mi->disk_prompt);
564 mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
565 msi_free(mi->cabinet);
566 mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
567 msi_free(mi->volume_label);
568 mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
569 msiobj_release(&row->hdr);
571 if (!mi->first_volume)
572 mi->first_volume = strdupW(mi->volume_label);
574 source_dir = msi_dup_property(package, cszSourceDir);
576 if (mi->cabinet && mi->cabinet[0] == '#')
578 r = writeout_cabinet_stream(package, &mi->cabinet[1], mi->source);
579 if (r != ERROR_SUCCESS)
581 ERR("Failed to extract cabinet stream\n");
582 return ERROR_FUNCTION_FAILED;
587 lstrcpyW(mi->source, source_dir);
591 lstrcatW(mi->source, mi->cabinet);
594 msi_package_add_media_disk(package, MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT,
595 mi->disk_id, mi->volume_label, mi->disk_prompt);
597 msi_package_add_info(package, MSIINSTALLCONTEXT_USERMANAGED,
598 MSICODE_PRODUCT | MSISOURCETYPE_MEDIA,
599 INSTALLPROPERTY_LASTUSEDSOURCEW, mi->source);
601 msi_free(source_dir);
602 return ERROR_SUCCESS;
605 static UINT ready_media(MSIPACKAGE *package, MSIFILE *file, struct media_info *mi)
607 UINT rc = ERROR_SUCCESS;
609 /* media info for continuous cabinet is already loaded */
610 if (mi->is_continuous)
611 return ERROR_SUCCESS;
613 rc = load_media_info(package, file, mi);
614 if (rc != ERROR_SUCCESS)
616 ERR("Unable to load media info\n");
617 return ERROR_FUNCTION_FAILED;
620 /* cabinet is internal, no checks needed */
621 if (!mi->cabinet || mi->cabinet[0] == '#')
622 return ERROR_SUCCESS;
624 /* package should be downloaded */
625 if (file->IsCompressed &&
626 GetFileAttributesW(mi->source) == INVALID_FILE_ATTRIBUTES &&
627 package->BaseURL && UrlIsW(package->BaseURL, URLIS_URL))
629 return download_remote_cabinet(package, mi);
632 /* check volume matches, change media if not */
633 if (mi->volume_label && mi->disk_id > 1 &&
634 lstrcmpW(mi->first_volume, mi->volume_label))
636 LPWSTR source = msi_dup_property(package, cszSourceDir);
640 PathStripToRootW(source);
641 type = GetDriveTypeW(source);
642 matches = source_matches_volume(mi, source);
645 if ((type == DRIVE_CDROM || type == DRIVE_REMOVABLE) && !matches)
647 rc = msi_change_media(package, mi);
648 if (rc != ERROR_SUCCESS)
653 if (file->IsCompressed &&
654 GetFileAttributesW(mi->source) == INVALID_FILE_ATTRIBUTES)
656 ERR("Cabinet not found: %s\n", debugstr_w(mi->source));
657 return ERROR_INSTALL_FAILURE;
660 return ERROR_SUCCESS;
663 static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
666 LIST_FOR_EACH_ENTRY( *file, &package->files, MSIFILE, entry )
668 if (lstrcmpW( file_key, (*file)->File )==0)
670 if ((*file)->state >= msifs_overwrite)
671 return ERROR_SUCCESS;
673 return ERROR_FILE_NOT_FOUND;
677 return ERROR_FUNCTION_FAILED;
680 static void schedule_install_files(MSIPACKAGE *package)
684 LIST_FOR_EACH_ENTRY(file, &package->files, MSIFILE, entry)
686 if (!ACTION_VerifyComponentForAction(file->Component, INSTALLSTATE_LOCAL))
688 TRACE("File %s is not scheduled for install\n", debugstr_w(file->File));
690 ui_progress(package,2,file->FileSize,0,0);
691 file->state = msifs_skipped;
696 static UINT copy_file(MSIFILE *file)
700 ret = CopyFileW(file->SourcePath, file->TargetPath, FALSE);
703 file->state = msifs_installed;
704 return ERROR_SUCCESS;
707 return GetLastError();
710 static UINT copy_install_file(MSIFILE *file)
714 TRACE("Copying %s to %s\n", debugstr_w(file->SourcePath),
715 debugstr_w(file->TargetPath));
717 gle = copy_file(file);
718 if (gle == ERROR_SUCCESS)
721 if (gle == ERROR_ALREADY_EXISTS && file->state == msifs_overwrite)
723 TRACE("overwriting existing file\n");
726 else if (gle == ERROR_FILE_NOT_FOUND)
728 /* FIXME: this needs to be tested, I'm pretty sure it fails */
729 TRACE("Source file not found\n");
732 else if (gle == ERROR_ACCESS_DENIED)
734 SetFileAttributesW(file->TargetPath, FILE_ATTRIBUTE_NORMAL);
736 gle = copy_file(file);
737 TRACE("Overwriting existing file: %d\n", gle);
739 else if (!(file->Attributes & msidbFileAttributesVital))
741 TRACE("Ignoring error for nonvital\n");
748 static BOOL check_dest_hash_matches(MSIFILE *file)
750 MSIFILEHASHINFO hash;
753 if (!file->hash.dwFileHashInfoSize)
756 hash.dwFileHashInfoSize = sizeof(MSIFILEHASHINFO);
757 r = MsiGetFileHashW(file->TargetPath, 0, &hash);
758 if (r != ERROR_SUCCESS)
761 return !memcmp(&hash, &file->hash, sizeof(MSIFILEHASHINFO));
765 * ACTION_InstallFiles()
767 * For efficiency, this is done in two passes:
768 * 1) Correct all the TargetPaths and determine what files are to be installed.
769 * 2) Extract Cabinets and copy files.
771 UINT ACTION_InstallFiles(MSIPACKAGE *package)
773 struct media_info *mi;
774 UINT rc = ERROR_SUCCESS;
778 /* increment progress bar each time action data is sent */
779 ui_progress(package,1,1,0,0);
781 /* handle the keys for the SourceList */
782 ptr = strrchrW(package->PackagePath,'\\');
786 msi_package_add_info(package, MSIINSTALLCONTEXT_USERMANAGED,
787 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, ptr);
790 schedule_install_files(package);
793 * Despite MSDN specifying that the CreateFolders action
794 * should be called before InstallFiles, some installers don't
795 * do that, and they seem to work correctly. We need to create
796 * directories here to make sure that the files can be copied.
798 msi_create_component_directories( package );
800 mi = msi_alloc_zero( sizeof(struct media_info) );
802 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
804 if (file->state != msifs_missing && !mi->is_continuous && file->state != msifs_overwrite)
807 if (check_dest_hash_matches(file))
809 TRACE("File hashes match, not overwriting\n");
813 if (file->Sequence > mi->last_sequence || mi->is_continuous ||
814 (file->IsCompressed && !mi->is_extracted))
816 rc = ready_media(package, file, mi);
817 if (rc != ERROR_SUCCESS)
819 ERR("Failed to ready media\n");
823 if (file->IsCompressed && !extract_cabinet_file(package, mi))
825 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi->cabinet));
826 rc = ERROR_FUNCTION_FAILED;
831 set_file_source(package, file, mi->source);
833 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
834 debugstr_w(file->TargetPath));
836 if (!file->IsCompressed)
838 msi_file_update_ui(package, file, szInstallFiles);
839 rc = copy_install_file(file);
840 if (rc != ERROR_SUCCESS)
842 ERR("Failed to copy %s to %s (%d)\n", debugstr_w(file->SourcePath),
843 debugstr_w(file->TargetPath), rc);
844 rc = ERROR_INSTALL_FAILURE;
848 else if (file->state != msifs_installed)
850 ERR("compressed file wasn't extracted (%s)\n", debugstr_w(file->TargetPath));
851 rc = ERROR_INSTALL_FAILURE;
856 free_media_info( mi );
860 static UINT ITERATE_DuplicateFiles(MSIRECORD *row, LPVOID param)
862 MSIPACKAGE *package = (MSIPACKAGE*)param;
863 WCHAR dest_name[0x100];
864 LPWSTR dest_path, dest;
865 LPCWSTR file_key, component;
871 component = MSI_RecordGetString(row,2);
872 comp = get_loaded_component(package,component);
874 if (!ACTION_VerifyComponentForAction( comp, INSTALLSTATE_LOCAL ))
876 TRACE("Skipping copy due to disabled component %s\n",
877 debugstr_w(component));
879 /* the action taken was the same as the current install state */
880 comp->Action = comp->Installed;
882 return ERROR_SUCCESS;
885 comp->Action = INSTALLSTATE_LOCAL;
887 file_key = MSI_RecordGetString(row,3);
890 ERR("Unable to get file key\n");
891 return ERROR_FUNCTION_FAILED;
894 rc = get_file_target(package,file_key,&file);
896 if (rc != ERROR_SUCCESS)
898 ERR("Original file unknown %s\n",debugstr_w(file_key));
899 return ERROR_SUCCESS;
902 if (MSI_RecordIsNull(row,4))
903 strcpyW(dest_name,strrchrW(file->TargetPath,'\\')+1);
907 MSI_RecordGetStringW(row,4,dest_name,&sz);
908 reduce_to_longfilename(dest_name);
911 if (MSI_RecordIsNull(row,5))
914 dest_path = strdupW(file->TargetPath);
915 p = strrchrW(dest_path,'\\');
922 destkey = MSI_RecordGetString(row,5);
923 dest_path = resolve_folder(package, destkey, FALSE, FALSE, TRUE, NULL);
927 dest_path = msi_dup_property( package, destkey );
930 FIXME("Unable to get destination folder, try AppSearch properties\n");
931 return ERROR_SUCCESS;
936 dest = build_directory_name(2, dest_path, dest_name);
938 TRACE("Duplicating file %s to %s\n",debugstr_w(file->TargetPath),
941 CreateDirectoryW(dest_path, NULL);
943 if (strcmpW(file->TargetPath,dest))
944 rc = !CopyFileW(file->TargetPath,dest,TRUE);
948 if (rc != ERROR_SUCCESS)
949 ERR("Failed to copy file %s -> %s, last error %d\n",
950 debugstr_w(file->TargetPath), debugstr_w(dest_path), GetLastError());
952 FIXME("We should track these duplicate files as well\n");
957 msi_file_update_ui(package, file, szDuplicateFiles);
959 return ERROR_SUCCESS;
962 UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
966 static const WCHAR ExecSeqQuery[] =
967 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
968 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
970 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
971 if (rc != ERROR_SUCCESS)
972 return ERROR_SUCCESS;
974 rc = MSI_IterateRecords(view, NULL, ITERATE_DuplicateFiles, package);
975 msiobj_release(&view->hdr);
980 /* compares the version of a file read from the filesystem and
981 * the version specified in the File table
983 static int msi_compare_file_version( MSIFILE *file )
985 WCHAR version[MAX_PATH];
991 r = MsiGetFileVersionW( file->TargetPath, version, &size, NULL, NULL );
992 if ( r != ERROR_SUCCESS )
995 return lstrcmpW( version, file->Version );
998 UINT ACTION_RemoveFiles( MSIPACKAGE *package )
1002 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
1007 if ( !file->Component )
1009 if ( file->Component->Installed == INSTALLSTATE_LOCAL )
1012 if ( file->state == msifs_installed )
1013 ERR("removing installed file %s\n", debugstr_w(file->TargetPath));
1015 if ( file->state != msifs_present )
1018 /* only remove a file if the version to be installed
1019 * is strictly newer than the old file
1021 if ( msi_compare_file_version( file ) >= 0 )
1024 TRACE("removing %s\n", debugstr_w(file->File) );
1025 if ( !DeleteFileW( file->TargetPath ) )
1026 ERR("failed to delete %s\n", debugstr_w(file->TargetPath) );
1027 file->state = msifs_missing;
1030 uirow = MSI_CreateRecord( 9 );
1031 MSI_RecordSetStringW( uirow, 1, file->FileName );
1032 uipath = strdupW( file->TargetPath );
1033 p = strrchrW(uipath,'\\');
1036 MSI_RecordSetStringW( uirow, 9, uipath);
1037 ui_actiondata( package, szRemoveFiles, uirow);
1038 msiobj_release( &uirow->hdr );
1040 /* FIXME: call ui_progress here? */
1043 return ERROR_SUCCESS;