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
38 #include "wine/debug.h"
46 #include "wine/unicode.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msi);
50 static void msi_file_update_ui( MSIPACKAGE *package, MSIFILE *f, const WCHAR *action )
56 uirow = MSI_CreateRecord( 9 );
57 MSI_RecordSetStringW( uirow, 1, f->FileName );
58 uipath = strdupW( f->TargetPath );
59 p = strrchrW(uipath,'\\');
62 MSI_RecordSetStringW( uirow, 9, uipath);
63 MSI_RecordSetInteger( uirow, 6, f->FileSize );
64 ui_actiondata( package, action, uirow);
65 msiobj_release( &uirow->hdr );
67 ui_progress( package, 2, f->FileSize, 0, 0);
70 /* compares the version of a file read from the filesystem and
71 * the version specified in the File table
73 static int msi_compare_file_version(MSIFILE *file)
75 WCHAR version[MAX_PATH];
81 r = MsiGetFileVersionW(file->TargetPath, version, &size, NULL, NULL);
82 if (r != ERROR_SUCCESS)
85 return lstrcmpW(version, file->Version);
88 static void schedule_install_files(MSIPACKAGE *package)
92 LIST_FOR_EACH_ENTRY(file, &package->files, MSIFILE, entry)
94 if (file->Component->ActionRequest != INSTALLSTATE_LOCAL)
96 TRACE("File %s is not scheduled for install\n", debugstr_w(file->File));
98 ui_progress(package,2,file->FileSize,0,0);
99 file->state = msifs_skipped;
104 static UINT copy_file(MSIFILE *file, LPWSTR source)
108 ret = CopyFileW(source, file->TargetPath, FALSE);
110 return GetLastError();
112 SetFileAttributesW(file->TargetPath, FILE_ATTRIBUTE_NORMAL);
114 file->state = msifs_installed;
115 return ERROR_SUCCESS;
118 static UINT copy_install_file(MSIPACKAGE *package, MSIFILE *file, LPWSTR source)
122 TRACE("Copying %s to %s\n", debugstr_w(source),
123 debugstr_w(file->TargetPath));
125 gle = copy_file(file, source);
126 if (gle == ERROR_SUCCESS)
129 if (gle == ERROR_ALREADY_EXISTS && file->state == msifs_overwrite)
131 TRACE("overwriting existing file\n");
132 return ERROR_SUCCESS;
134 else if (gle == ERROR_ACCESS_DENIED)
136 SetFileAttributesW(file->TargetPath, FILE_ATTRIBUTE_NORMAL);
138 gle = copy_file(file, source);
139 TRACE("Overwriting existing file: %d\n", gle);
141 if (gle == ERROR_SHARING_VIOLATION || gle == ERROR_USER_MAPPED_FILE)
143 WCHAR tmpfileW[MAX_PATH], *pathW, *p;
146 TRACE("file in use, scheduling rename operation\n");
148 GetTempFileNameW(szBackSlash, szMsi, 0, tmpfileW);
149 len = strlenW(file->TargetPath) + strlenW(tmpfileW) + 1;
150 if (!(pathW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
151 return ERROR_OUTOFMEMORY;
153 strcpyW(pathW, file->TargetPath);
154 if ((p = strrchrW(pathW, '\\'))) *p = 0;
155 strcatW(pathW, tmpfileW);
157 if (CopyFileW(source, pathW, FALSE) &&
158 MoveFileExW(file->TargetPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT) &&
159 MoveFileExW(pathW, file->TargetPath, MOVEFILE_DELAY_UNTIL_REBOOT))
161 file->state = msifs_installed;
162 package->need_reboot = 1;
167 gle = GetLastError();
168 WARN("failed to schedule rename operation: %d)\n", gle);
170 HeapFree(GetProcessHeap(), 0, pathW);
176 static BOOL check_dest_hash_matches(MSIFILE *file)
178 MSIFILEHASHINFO hash;
181 if (!file->hash.dwFileHashInfoSize)
184 hash.dwFileHashInfoSize = sizeof(MSIFILEHASHINFO);
185 r = MsiGetFileHashW(file->TargetPath, 0, &hash);
186 if (r != ERROR_SUCCESS)
189 return !memcmp(&hash, &file->hash, sizeof(MSIFILEHASHINFO));
192 static BOOL installfiles_cb(MSIPACKAGE *package, LPCWSTR file, DWORD action,
193 LPWSTR *path, DWORD *attrs, PVOID user)
195 static MSIFILE *f = NULL;
197 if (action == MSICABEXTRACT_BEGINEXTRACT)
199 f = get_loaded_file(package, file);
202 WARN("unknown file in cabinet (%s)\n", debugstr_w(file));
206 if (f->state != msifs_missing && f->state != msifs_overwrite)
208 TRACE("Skipping extraction of %s\n", debugstr_w(file));
212 msi_file_update_ui(package, f, szInstallFiles);
214 *path = strdupW(f->TargetPath);
215 *attrs = f->Attributes;
217 else if (action == MSICABEXTRACT_FILEEXTRACTED)
219 f->state = msifs_installed;
227 * ACTION_InstallFiles()
229 * For efficiency, this is done in two passes:
230 * 1) Correct all the TargetPaths and determine what files are to be installed.
231 * 2) Extract Cabinets and copy files.
233 UINT ACTION_InstallFiles(MSIPACKAGE *package)
236 UINT rc = ERROR_SUCCESS;
239 /* increment progress bar each time action data is sent */
240 ui_progress(package,1,1,0,0);
242 schedule_install_files(package);
245 * Despite MSDN specifying that the CreateFolders action
246 * should be called before InstallFiles, some installers don't
247 * do that, and they seem to work correctly. We need to create
248 * directories here to make sure that the files can be copied.
250 msi_create_component_directories( package );
252 mi = msi_alloc_zero( sizeof(MSIMEDIAINFO) );
254 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
256 if (file->state != msifs_missing && !mi->is_continuous && file->state != msifs_overwrite)
259 if (check_dest_hash_matches(file))
261 TRACE("File hashes match, not overwriting\n");
265 if (MsiGetFileVersionW(file->TargetPath, NULL, NULL, NULL, NULL) == ERROR_SUCCESS &&
266 msi_compare_file_version(file) >= 0)
268 TRACE("Destination file version greater, not overwriting\n");
272 if (file->Sequence > mi->last_sequence || mi->is_continuous ||
273 (file->IsCompressed && !mi->is_extracted))
277 rc = ready_media(package, file, mi);
278 if (rc != ERROR_SUCCESS)
280 ERR("Failed to ready media\n");
285 data.package = package;
286 data.cb = installfiles_cb;
289 if (file->IsCompressed &&
290 !msi_cabextract(package, mi, &data))
292 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi->cabinet));
293 rc = ERROR_FUNCTION_FAILED;
298 if (!file->IsCompressed)
300 LPWSTR source = resolve_file_source(package, file);
302 TRACE("file paths %s to %s\n", debugstr_w(source),
303 debugstr_w(file->TargetPath));
305 msi_file_update_ui(package, file, szInstallFiles);
306 rc = copy_install_file(package, file, source);
307 if (rc != ERROR_SUCCESS)
309 ERR("Failed to copy %s to %s (%d)\n", debugstr_w(source),
310 debugstr_w(file->TargetPath), rc);
311 rc = ERROR_INSTALL_FAILURE;
318 else if (file->state != msifs_installed)
320 ERR("compressed file wasn't extracted (%s)\n",
321 debugstr_w(file->TargetPath));
322 rc = ERROR_INSTALL_FAILURE;
327 msi_free_media_info(mi);
331 #define is_dot_dir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
342 static BOOL msi_move_file(LPCWSTR source, LPCWSTR dest, int options)
346 if (GetFileAttributesW(source) == FILE_ATTRIBUTE_DIRECTORY ||
347 GetFileAttributesW(dest) == FILE_ATTRIBUTE_DIRECTORY)
349 WARN("Source or dest is directory, not moving\n");
353 if (options == msidbMoveFileOptionsMove)
355 TRACE("moving %s -> %s\n", debugstr_w(source), debugstr_w(dest));
356 ret = MoveFileExW(source, dest, MOVEFILE_REPLACE_EXISTING);
359 WARN("MoveFile failed: %d\n", GetLastError());
365 TRACE("copying %s -> %s\n", debugstr_w(source), debugstr_w(dest));
366 ret = CopyFileW(source, dest, FALSE);
369 WARN("CopyFile failed: %d\n", GetLastError());
377 static LPWSTR wildcard_to_file(LPWSTR wildcard, LPWSTR filename)
380 DWORD dirlen, pathlen;
382 ptr = strrchrW(wildcard, '\\');
383 dirlen = ptr - wildcard + 1;
385 pathlen = dirlen + lstrlenW(filename) + 1;
386 path = msi_alloc(pathlen * sizeof(WCHAR));
388 lstrcpynW(path, wildcard, dirlen + 1);
389 lstrcatW(path, filename);
394 static void free_file_entry(FILE_LIST *file)
396 msi_free(file->source);
397 msi_free(file->dest);
401 static void free_list(FILE_LIST *list)
403 while (!list_empty(&list->entry))
405 FILE_LIST *file = LIST_ENTRY(list_head(&list->entry), FILE_LIST, entry);
407 list_remove(&file->entry);
408 free_file_entry(file);
412 static BOOL add_wildcard(FILE_LIST *files, LPWSTR source, LPWSTR dest)
414 FILE_LIST *new, *file;
415 LPWSTR ptr, filename;
418 new = msi_alloc_zero(sizeof(FILE_LIST));
422 new->source = strdupW(source);
423 ptr = strrchrW(dest, '\\') + 1;
424 filename = strrchrW(new->source, '\\') + 1;
426 new->sourcename = filename;
431 new->destname = new->sourcename;
433 size = (ptr - dest) + lstrlenW(filename) + 1;
434 new->dest = msi_alloc(size * sizeof(WCHAR));
437 free_file_entry(new);
441 lstrcpynW(new->dest, dest, ptr - dest + 1);
442 lstrcatW(new->dest, filename);
444 if (list_empty(&files->entry))
446 list_add_head(&files->entry, &new->entry);
450 LIST_FOR_EACH_ENTRY(file, &files->entry, FILE_LIST, entry)
452 if (lstrcmpW(source, file->source) < 0)
454 list_add_before(&file->entry, &new->entry);
459 list_add_after(&file->entry, &new->entry);
463 static BOOL move_files_wildcard(LPWSTR source, LPWSTR dest, int options)
465 WIN32_FIND_DATAW wfd;
469 FILE_LIST files, *file;
472 hfile = FindFirstFileW(source, &wfd);
473 if (hfile == INVALID_HANDLE_VALUE) return FALSE;
475 list_init(&files.entry);
477 for (res = TRUE; res; res = FindNextFileW(hfile, &wfd))
479 if (is_dot_dir(wfd.cFileName)) continue;
481 path = wildcard_to_file(source, wfd.cFileName);
488 add_wildcard(&files, path, dest);
492 /* no files match the wildcard */
493 if (list_empty(&files.entry))
496 /* only the first wildcard match gets renamed to dest */
497 file = LIST_ENTRY(list_head(&files.entry), FILE_LIST, entry);
498 size = (strrchrW(file->dest, '\\') - file->dest) + lstrlenW(file->destname) + 2;
499 file->dest = msi_realloc(file->dest, size * sizeof(WCHAR));
506 /* file->dest may be shorter after the reallocation, so add a NULL
507 * terminator. This is needed for the call to strrchrW, as there will no
508 * longer be a NULL terminator within the bounds of the allocation in this case.
510 file->dest[size - 1] = '\0';
511 lstrcpyW(strrchrW(file->dest, '\\') + 1, file->destname);
513 while (!list_empty(&files.entry))
515 file = LIST_ENTRY(list_head(&files.entry), FILE_LIST, entry);
517 msi_move_file(file->source, file->dest, options);
519 list_remove(&file->entry);
520 free_file_entry(file);
531 static UINT ITERATE_MoveFiles( MSIRECORD *rec, LPVOID param )
533 MSIPACKAGE *package = param;
535 LPCWSTR sourcename, component;
536 LPWSTR destname = NULL;
537 LPWSTR sourcedir = NULL, destdir = NULL;
538 LPWSTR source = NULL, dest = NULL;
543 component = MSI_RecordGetString(rec, 2);
544 comp = get_loaded_component(package, component);
546 return ERROR_SUCCESS;
548 if (comp->ActionRequest != INSTALLSTATE_LOCAL && comp->ActionRequest != INSTALLSTATE_SOURCE)
550 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component));
551 comp->Action = comp->Installed;
552 return ERROR_SUCCESS;
554 comp->Action = comp->ActionRequest;
556 sourcename = MSI_RecordGetString(rec, 3);
557 options = MSI_RecordGetInteger(rec, 7);
559 sourcedir = msi_dup_property(package, MSI_RecordGetString(rec, 5));
563 destdir = msi_dup_property(package, MSI_RecordGetString(rec, 6));
569 if (GetFileAttributesW(sourcedir) == INVALID_FILE_ATTRIBUTES)
572 source = strdupW(sourcedir);
578 size = lstrlenW(sourcedir) + lstrlenW(sourcename) + 2;
579 source = msi_alloc(size * sizeof(WCHAR));
583 lstrcpyW(source, sourcedir);
584 if (source[lstrlenW(source) - 1] != '\\')
585 lstrcatW(source, szBackSlash);
586 lstrcatW(source, sourcename);
589 wildcards = strchrW(source, '*') || strchrW(source, '?');
591 if (MSI_RecordIsNull(rec, 4))
595 destname = strdupW(sourcename);
602 destname = strdupW(MSI_RecordGetString(rec, 4));
604 reduce_to_longfilename(destname);
609 size = lstrlenW(destname);
611 size += lstrlenW(destdir) + 2;
612 dest = msi_alloc(size * sizeof(WCHAR));
616 lstrcpyW(dest, destdir);
617 if (dest[lstrlenW(dest) - 1] != '\\')
618 lstrcatW(dest, szBackSlash);
621 lstrcatW(dest, destname);
623 if (GetFileAttributesW(destdir) == INVALID_FILE_ATTRIBUTES)
625 ret = CreateDirectoryW(destdir, NULL);
628 WARN("CreateDirectory failed: %d\n", GetLastError());
629 return ERROR_SUCCESS;
634 msi_move_file(source, dest, options);
636 move_files_wildcard(source, dest, options);
645 return ERROR_SUCCESS;
648 UINT ACTION_MoveFiles( MSIPACKAGE *package )
653 static const WCHAR ExecSeqQuery[] =
654 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
655 '`','M','o','v','e','F','i','l','e','`',0};
657 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
658 if (rc != ERROR_SUCCESS)
659 return ERROR_SUCCESS;
661 rc = MSI_IterateRecords(view, NULL, ITERATE_MoveFiles, package);
662 msiobj_release(&view->hdr);
667 static WCHAR *get_duplicate_filename( MSIPACKAGE *package, MSIRECORD *row, const WCHAR *file_key, const WCHAR *src )
670 WCHAR *dst_name, *dst_path, *dst;
672 if (MSI_RecordIsNull( row, 4 ))
674 len = strlenW( src ) + 1;
675 if (!(dst_name = msi_alloc( len * sizeof(WCHAR)))) return NULL;
676 strcpyW( dst_name, strrchrW( src, '\\' ) + 1 );
680 MSI_RecordGetStringW( row, 4, NULL, &len );
681 if (!(dst_name = msi_alloc( ++len * sizeof(WCHAR) ))) return NULL;
682 MSI_RecordGetStringW( row, 4, dst_name, &len );
683 reduce_to_longfilename( dst_name );
686 if (MSI_RecordIsNull( row, 5 ))
689 dst_path = strdupW( src );
690 p = strrchrW( dst_path, '\\' );
695 const WCHAR *dst_key = MSI_RecordGetString( row, 5 );
697 dst_path = resolve_folder( package, dst_key, FALSE, FALSE, TRUE, NULL );
701 dst_path = msi_dup_property( package, dst_key );
704 FIXME("Unable to get destination folder, try AppSearch properties\n");
705 msi_free( dst_name );
711 dst = build_directory_name( 2, dst_path, dst_name );
712 create_full_pathW( dst_path );
714 msi_free( dst_name );
715 msi_free( dst_path );
719 static UINT ITERATE_DuplicateFiles(MSIRECORD *row, LPVOID param)
721 MSIPACKAGE *package = param;
723 LPCWSTR file_key, component;
728 component = MSI_RecordGetString(row,2);
729 comp = get_loaded_component(package,component);
731 return ERROR_SUCCESS;
733 if (comp->ActionRequest != INSTALLSTATE_LOCAL)
735 TRACE("Component not scheduled for installation %s\n", debugstr_w(component));
736 comp->Action = comp->Installed;
737 return ERROR_SUCCESS;
739 comp->Action = INSTALLSTATE_LOCAL;
741 file_key = MSI_RecordGetString(row,3);
744 ERR("Unable to get file key\n");
745 return ERROR_FUNCTION_FAILED;
748 file = get_loaded_file( package, file_key );
751 ERR("Original file unknown %s\n", debugstr_w(file_key));
752 return ERROR_SUCCESS;
755 dest = get_duplicate_filename( package, row, file_key, file->TargetPath );
758 WARN("Unable to get duplicate filename\n");
759 return ERROR_SUCCESS;
762 TRACE("Duplicating file %s to %s\n", debugstr_w(file->TargetPath), debugstr_w(dest));
764 if (!CopyFileW( file->TargetPath, dest, TRUE ))
766 WARN("Failed to copy file %s -> %s (%u)\n",
767 debugstr_w(file->TargetPath), debugstr_w(dest), GetLastError());
770 FIXME("We should track these duplicate files as well\n");
772 uirow = MSI_CreateRecord( 9 );
773 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString( row, 1 ) );
774 MSI_RecordSetInteger( uirow, 6, file->FileSize );
775 MSI_RecordSetStringW( uirow, 9, MSI_RecordGetString( row, 5 ) );
776 ui_actiondata( package, szDuplicateFiles, uirow );
777 msiobj_release( &uirow->hdr );
780 return ERROR_SUCCESS;
783 UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
787 static const WCHAR ExecSeqQuery[] =
788 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
789 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
791 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
792 if (rc != ERROR_SUCCESS)
793 return ERROR_SUCCESS;
795 rc = MSI_IterateRecords(view, NULL, ITERATE_DuplicateFiles, package);
796 msiobj_release(&view->hdr);
801 static UINT ITERATE_RemoveDuplicateFiles( MSIRECORD *row, LPVOID param )
803 MSIPACKAGE *package = param;
805 LPCWSTR file_key, component;
810 component = MSI_RecordGetString( row, 2 );
811 comp = get_loaded_component( package, component );
813 return ERROR_SUCCESS;
815 if (comp->ActionRequest != INSTALLSTATE_ABSENT)
817 TRACE("Component not scheduled for removal %s\n", debugstr_w(component));
818 comp->Action = comp->Installed;
819 return ERROR_SUCCESS;
821 comp->Action = INSTALLSTATE_ABSENT;
823 file_key = MSI_RecordGetString( row, 3 );
826 ERR("Unable to get file key\n");
827 return ERROR_FUNCTION_FAILED;
830 file = get_loaded_file( package, file_key );
833 ERR("Original file unknown %s\n", debugstr_w(file_key));
834 return ERROR_SUCCESS;
837 dest = get_duplicate_filename( package, row, file_key, file->TargetPath );
840 WARN("Unable to get duplicate filename\n");
841 return ERROR_SUCCESS;
844 TRACE("Removing duplicate %s of %s\n", debugstr_w(dest), debugstr_w(file->TargetPath));
846 if (!DeleteFileW( dest ))
848 WARN("Failed to delete duplicate file %s (%u)\n", debugstr_w(dest), GetLastError());
851 uirow = MSI_CreateRecord( 9 );
852 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString( row, 1 ) );
853 MSI_RecordSetStringW( uirow, 9, MSI_RecordGetString( row, 5 ) );
854 ui_actiondata( package, szRemoveDuplicateFiles, uirow );
855 msiobj_release( &uirow->hdr );
858 return ERROR_SUCCESS;
861 UINT ACTION_RemoveDuplicateFiles( MSIPACKAGE *package )
865 static const WCHAR query[] =
866 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
867 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
869 rc = MSI_DatabaseOpenViewW( package->db, query, &view );
870 if (rc != ERROR_SUCCESS)
871 return ERROR_SUCCESS;
873 rc = MSI_IterateRecords( view, NULL, ITERATE_RemoveDuplicateFiles, package );
874 msiobj_release( &view->hdr );
879 static BOOL verify_comp_for_removal(MSICOMPONENT *comp, UINT install_mode)
881 INSTALLSTATE request = comp->ActionRequest;
883 if (request == INSTALLSTATE_UNKNOWN)
886 if (install_mode == msidbRemoveFileInstallModeOnInstall &&
887 (request == INSTALLSTATE_LOCAL || request == INSTALLSTATE_SOURCE))
890 if (request == INSTALLSTATE_ABSENT)
892 if (!comp->ComponentId)
895 if (install_mode == msidbRemoveFileInstallModeOnRemove)
899 if (install_mode == msidbRemoveFileInstallModeOnBoth)
905 static UINT ITERATE_RemoveFiles(MSIRECORD *row, LPVOID param)
907 MSIPACKAGE *package = param;
909 LPCWSTR component, filename, dirprop;
911 LPWSTR dir = NULL, path = NULL;
915 component = MSI_RecordGetString(row, 2);
916 filename = MSI_RecordGetString(row, 3);
917 dirprop = MSI_RecordGetString(row, 4);
918 install_mode = MSI_RecordGetInteger(row, 5);
920 comp = get_loaded_component(package, component);
923 ERR("Invalid component: %s\n", debugstr_w(component));
924 return ERROR_FUNCTION_FAILED;
927 if (!verify_comp_for_removal(comp, install_mode))
929 TRACE("Skipping removal due to missing conditions\n");
930 comp->Action = comp->Installed;
931 return ERROR_SUCCESS;
934 dir = msi_dup_property(package, dirprop);
936 return ERROR_OUTOFMEMORY;
938 size = (filename != NULL) ? lstrlenW(filename) : 0;
939 size += lstrlenW(dir) + 2;
940 path = msi_alloc(size * sizeof(WCHAR));
943 r = ERROR_OUTOFMEMORY;
950 PathAddBackslashW(path);
951 lstrcatW(path, filename);
953 TRACE("Deleting misc file: %s\n", debugstr_w(path));
958 TRACE("Removing misc directory: %s\n", debugstr_w(dir));
959 RemoveDirectoryW(dir);
965 return ERROR_SUCCESS;
968 UINT ACTION_RemoveFiles( MSIPACKAGE *package )
974 static const WCHAR query[] = {
975 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
976 '`','R','e','m','o','v','e','F','i','l','e','`',0};
977 static const WCHAR folder_query[] = {
978 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
979 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0};
981 r = MSI_DatabaseOpenViewW(package->db, query, &view);
982 if (r == ERROR_SUCCESS)
984 MSI_IterateRecords(view, NULL, ITERATE_RemoveFiles, package);
985 msiobj_release(&view->hdr);
988 r = MSI_DatabaseOpenViewW(package->db, folder_query, &view);
989 if (r == ERROR_SUCCESS)
990 msiobj_release(&view->hdr);
992 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
995 LPWSTR dir, uipath, p;
997 if ( file->state == msifs_installed )
998 ERR("removing installed file %s\n", debugstr_w(file->TargetPath));
1000 if ( file->Component->ActionRequest != INSTALLSTATE_ABSENT ||
1001 file->Component->Installed == INSTALLSTATE_SOURCE )
1004 /* don't remove a file if the old file
1005 * is strictly newer than the version to be installed
1007 if ( msi_compare_file_version( file ) < 0 )
1010 TRACE("removing %s\n", debugstr_w(file->File) );
1011 if (!DeleteFileW( file->TargetPath ))
1013 WARN("failed to delete %s\n", debugstr_w(file->TargetPath));
1015 /* FIXME: check persistence for each directory */
1016 else if (r && (dir = strdupW( file->TargetPath )))
1018 if ((p = strrchrW( dir, '\\' ))) *p = 0;
1019 RemoveDirectoryW( dir );
1022 file->state = msifs_missing;
1025 uirow = MSI_CreateRecord( 9 );
1026 MSI_RecordSetStringW( uirow, 1, file->FileName );
1027 uipath = strdupW( file->TargetPath );
1028 p = strrchrW(uipath,'\\');
1031 MSI_RecordSetStringW( uirow, 9, uipath);
1032 ui_actiondata( package, szRemoveFiles, uirow);
1033 msiobj_release( &uirow->hdr );
1035 /* FIXME: call ui_progress here? */
1038 return ERROR_SUCCESS;