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;
102 file->Component->Action = INSTALLSTATE_LOCAL;
106 static UINT copy_file(MSIFILE *file, LPWSTR source)
110 ret = CopyFileW(source, file->TargetPath, FALSE);
112 return GetLastError();
114 SetFileAttributesW(file->TargetPath, FILE_ATTRIBUTE_NORMAL);
116 file->state = msifs_installed;
117 return ERROR_SUCCESS;
120 static UINT copy_install_file(MSIPACKAGE *package, MSIFILE *file, LPWSTR source)
124 TRACE("Copying %s to %s\n", debugstr_w(source),
125 debugstr_w(file->TargetPath));
127 gle = copy_file(file, source);
128 if (gle == ERROR_SUCCESS)
131 if (gle == ERROR_ALREADY_EXISTS && file->state == msifs_overwrite)
133 TRACE("overwriting existing file\n");
134 return ERROR_SUCCESS;
136 else if (gle == ERROR_ACCESS_DENIED)
138 SetFileAttributesW(file->TargetPath, FILE_ATTRIBUTE_NORMAL);
140 gle = copy_file(file, source);
141 TRACE("Overwriting existing file: %d\n", gle);
143 if (gle == ERROR_SHARING_VIOLATION || gle == ERROR_USER_MAPPED_FILE)
145 WCHAR tmpfileW[MAX_PATH], *pathW, *p;
148 TRACE("file in use, scheduling rename operation\n");
150 GetTempFileNameW(szBackSlash, szMsi, 0, tmpfileW);
151 len = strlenW(file->TargetPath) + strlenW(tmpfileW) + 1;
152 if (!(pathW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
153 return ERROR_OUTOFMEMORY;
155 strcpyW(pathW, file->TargetPath);
156 if ((p = strrchrW(pathW, '\\'))) *p = 0;
157 strcatW(pathW, tmpfileW);
159 if (CopyFileW(source, pathW, FALSE) &&
160 MoveFileExW(file->TargetPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT) &&
161 MoveFileExW(pathW, file->TargetPath, MOVEFILE_DELAY_UNTIL_REBOOT))
163 file->state = msifs_installed;
164 package->need_reboot = 1;
169 gle = GetLastError();
170 WARN("failed to schedule rename operation: %d)\n", gle);
172 HeapFree(GetProcessHeap(), 0, pathW);
178 static BOOL installfiles_cb(MSIPACKAGE *package, LPCWSTR file, DWORD action,
179 LPWSTR *path, DWORD *attrs, PVOID user)
181 static MSIFILE *f = NULL;
182 MSIMEDIAINFO *mi = user;
184 if (action == MSICABEXTRACT_BEGINEXTRACT)
186 f = get_loaded_file(package, file);
189 WARN("unknown file in cabinet (%s)\n", debugstr_w(file));
193 if (f->disk_id != mi->disk_id || (f->state != msifs_missing && f->state != msifs_overwrite))
196 msi_file_update_ui(package, f, szInstallFiles);
198 *path = strdupW(f->TargetPath);
199 *attrs = f->Attributes;
201 else if (action == MSICABEXTRACT_FILEEXTRACTED)
203 f->state = msifs_installed;
211 * ACTION_InstallFiles()
213 * For efficiency, this is done in two passes:
214 * 1) Correct all the TargetPaths and determine what files are to be installed.
215 * 2) Extract Cabinets and copy files.
217 UINT ACTION_InstallFiles(MSIPACKAGE *package)
220 UINT rc = ERROR_SUCCESS;
223 /* increment progress bar each time action data is sent */
224 ui_progress(package,1,1,0,0);
226 schedule_install_files(package);
229 * Despite MSDN specifying that the CreateFolders action
230 * should be called before InstallFiles, some installers don't
231 * do that, and they seem to work correctly. We need to create
232 * directories here to make sure that the files can be copied.
234 msi_create_component_directories( package );
236 mi = msi_alloc_zero( sizeof(MSIMEDIAINFO) );
238 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
240 if (file->state != msifs_missing && !mi->is_continuous && file->state != msifs_overwrite)
243 if (file->Sequence > mi->last_sequence || mi->is_continuous ||
244 (file->IsCompressed && !mi->is_extracted))
248 rc = ready_media(package, file, mi);
249 if (rc != ERROR_SUCCESS)
251 ERR("Failed to ready media\n");
256 data.package = package;
257 data.cb = installfiles_cb;
260 if (file->IsCompressed &&
261 !msi_cabextract(package, mi, &data))
263 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi->cabinet));
264 rc = ERROR_INSTALL_FAILURE;
269 if (!file->IsCompressed)
271 LPWSTR source = resolve_file_source(package, file);
273 TRACE("file paths %s to %s\n", debugstr_w(source),
274 debugstr_w(file->TargetPath));
276 msi_file_update_ui(package, file, szInstallFiles);
277 rc = copy_install_file(package, file, source);
278 if (rc != ERROR_SUCCESS)
280 ERR("Failed to copy %s to %s (%d)\n", debugstr_w(source),
281 debugstr_w(file->TargetPath), rc);
282 rc = ERROR_INSTALL_FAILURE;
289 else if (file->state != msifs_installed)
291 ERR("compressed file wasn't extracted (%s)\n",
292 debugstr_w(file->TargetPath));
293 rc = ERROR_INSTALL_FAILURE;
298 msi_free_media_info(mi);
302 #define is_dot_dir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
313 static BOOL msi_move_file(LPCWSTR source, LPCWSTR dest, int options)
317 if (GetFileAttributesW(source) == FILE_ATTRIBUTE_DIRECTORY ||
318 GetFileAttributesW(dest) == FILE_ATTRIBUTE_DIRECTORY)
320 WARN("Source or dest is directory, not moving\n");
324 if (options == msidbMoveFileOptionsMove)
326 TRACE("moving %s -> %s\n", debugstr_w(source), debugstr_w(dest));
327 ret = MoveFileExW(source, dest, MOVEFILE_REPLACE_EXISTING);
330 WARN("MoveFile failed: %d\n", GetLastError());
336 TRACE("copying %s -> %s\n", debugstr_w(source), debugstr_w(dest));
337 ret = CopyFileW(source, dest, FALSE);
340 WARN("CopyFile failed: %d\n", GetLastError());
348 static LPWSTR wildcard_to_file(LPWSTR wildcard, LPWSTR filename)
351 DWORD dirlen, pathlen;
353 ptr = strrchrW(wildcard, '\\');
354 dirlen = ptr - wildcard + 1;
356 pathlen = dirlen + lstrlenW(filename) + 1;
357 path = msi_alloc(pathlen * sizeof(WCHAR));
359 lstrcpynW(path, wildcard, dirlen + 1);
360 lstrcatW(path, filename);
365 static void free_file_entry(FILE_LIST *file)
367 msi_free(file->source);
368 msi_free(file->dest);
372 static void free_list(FILE_LIST *list)
374 while (!list_empty(&list->entry))
376 FILE_LIST *file = LIST_ENTRY(list_head(&list->entry), FILE_LIST, entry);
378 list_remove(&file->entry);
379 free_file_entry(file);
383 static BOOL add_wildcard(FILE_LIST *files, LPWSTR source, LPWSTR dest)
385 FILE_LIST *new, *file;
386 LPWSTR ptr, filename;
389 new = msi_alloc_zero(sizeof(FILE_LIST));
393 new->source = strdupW(source);
394 ptr = strrchrW(dest, '\\') + 1;
395 filename = strrchrW(new->source, '\\') + 1;
397 new->sourcename = filename;
402 new->destname = new->sourcename;
404 size = (ptr - dest) + lstrlenW(filename) + 1;
405 new->dest = msi_alloc(size * sizeof(WCHAR));
408 free_file_entry(new);
412 lstrcpynW(new->dest, dest, ptr - dest + 1);
413 lstrcatW(new->dest, filename);
415 if (list_empty(&files->entry))
417 list_add_head(&files->entry, &new->entry);
421 LIST_FOR_EACH_ENTRY(file, &files->entry, FILE_LIST, entry)
423 if (lstrcmpW(source, file->source) < 0)
425 list_add_before(&file->entry, &new->entry);
430 list_add_after(&file->entry, &new->entry);
434 static BOOL move_files_wildcard(LPWSTR source, LPWSTR dest, int options)
436 WIN32_FIND_DATAW wfd;
440 FILE_LIST files, *file;
443 hfile = FindFirstFileW(source, &wfd);
444 if (hfile == INVALID_HANDLE_VALUE) return FALSE;
446 list_init(&files.entry);
448 for (res = TRUE; res; res = FindNextFileW(hfile, &wfd))
450 if (is_dot_dir(wfd.cFileName)) continue;
452 path = wildcard_to_file(source, wfd.cFileName);
459 add_wildcard(&files, path, dest);
463 /* no files match the wildcard */
464 if (list_empty(&files.entry))
467 /* only the first wildcard match gets renamed to dest */
468 file = LIST_ENTRY(list_head(&files.entry), FILE_LIST, entry);
469 size = (strrchrW(file->dest, '\\') - file->dest) + lstrlenW(file->destname) + 2;
470 file->dest = msi_realloc(file->dest, size * sizeof(WCHAR));
477 /* file->dest may be shorter after the reallocation, so add a NULL
478 * terminator. This is needed for the call to strrchrW, as there will no
479 * longer be a NULL terminator within the bounds of the allocation in this case.
481 file->dest[size - 1] = '\0';
482 lstrcpyW(strrchrW(file->dest, '\\') + 1, file->destname);
484 while (!list_empty(&files.entry))
486 file = LIST_ENTRY(list_head(&files.entry), FILE_LIST, entry);
488 msi_move_file(file->source, file->dest, options);
490 list_remove(&file->entry);
491 free_file_entry(file);
502 static UINT ITERATE_MoveFiles( MSIRECORD *rec, LPVOID param )
504 MSIPACKAGE *package = param;
507 LPCWSTR sourcename, component;
508 LPWSTR sourcedir, destname = NULL, destdir = NULL, source = NULL, dest = NULL;
513 component = MSI_RecordGetString(rec, 2);
514 comp = get_loaded_component(package, component);
516 return ERROR_SUCCESS;
518 if (comp->ActionRequest != INSTALLSTATE_LOCAL && comp->ActionRequest != INSTALLSTATE_SOURCE)
520 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component));
521 comp->Action = comp->Installed;
522 return ERROR_SUCCESS;
524 comp->Action = comp->ActionRequest;
526 sourcename = MSI_RecordGetString(rec, 3);
527 options = MSI_RecordGetInteger(rec, 7);
529 sourcedir = msi_dup_property(package->db, MSI_RecordGetString(rec, 5));
533 destdir = msi_dup_property(package->db, MSI_RecordGetString(rec, 6));
539 if (GetFileAttributesW(sourcedir) == INVALID_FILE_ATTRIBUTES)
542 source = strdupW(sourcedir);
548 size = lstrlenW(sourcedir) + lstrlenW(sourcename) + 2;
549 source = msi_alloc(size * sizeof(WCHAR));
553 lstrcpyW(source, sourcedir);
554 if (source[lstrlenW(source) - 1] != '\\')
555 lstrcatW(source, szBackSlash);
556 lstrcatW(source, sourcename);
559 wildcards = strchrW(source, '*') || strchrW(source, '?');
561 if (MSI_RecordIsNull(rec, 4))
565 destname = strdupW(sourcename);
572 destname = strdupW(MSI_RecordGetString(rec, 4));
574 reduce_to_longfilename(destname);
579 size = lstrlenW(destname);
581 size += lstrlenW(destdir) + 2;
582 dest = msi_alloc(size * sizeof(WCHAR));
586 lstrcpyW(dest, destdir);
587 if (dest[lstrlenW(dest) - 1] != '\\')
588 lstrcatW(dest, szBackSlash);
591 lstrcatW(dest, destname);
593 if (GetFileAttributesW(destdir) == INVALID_FILE_ATTRIBUTES)
595 ret = CreateDirectoryW(destdir, NULL);
598 WARN("CreateDirectory failed: %d\n", GetLastError());
604 msi_move_file(source, dest, options);
606 move_files_wildcard(source, dest, options);
609 uirow = MSI_CreateRecord( 9 );
610 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString(rec, 1) );
611 MSI_RecordSetInteger( uirow, 6, 1 ); /* FIXME */
612 MSI_RecordSetStringW( uirow, 9, destdir );
613 ui_actiondata( package, szMoveFiles, uirow );
614 msiobj_release( &uirow->hdr );
622 return ERROR_SUCCESS;
625 UINT ACTION_MoveFiles( MSIPACKAGE *package )
630 static const WCHAR ExecSeqQuery[] =
631 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
632 '`','M','o','v','e','F','i','l','e','`',0};
634 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
635 if (rc != ERROR_SUCCESS)
636 return ERROR_SUCCESS;
638 rc = MSI_IterateRecords(view, NULL, ITERATE_MoveFiles, package);
639 msiobj_release(&view->hdr);
644 static WCHAR *get_duplicate_filename( MSIPACKAGE *package, MSIRECORD *row, const WCHAR *file_key, const WCHAR *src )
647 WCHAR *dst_name, *dst_path, *dst;
649 if (MSI_RecordIsNull( row, 4 ))
651 len = strlenW( src ) + 1;
652 if (!(dst_name = msi_alloc( len * sizeof(WCHAR)))) return NULL;
653 strcpyW( dst_name, strrchrW( src, '\\' ) + 1 );
657 MSI_RecordGetStringW( row, 4, NULL, &len );
658 if (!(dst_name = msi_alloc( ++len * sizeof(WCHAR) ))) return NULL;
659 MSI_RecordGetStringW( row, 4, dst_name, &len );
660 reduce_to_longfilename( dst_name );
663 if (MSI_RecordIsNull( row, 5 ))
666 dst_path = strdupW( src );
667 p = strrchrW( dst_path, '\\' );
672 const WCHAR *dst_key = MSI_RecordGetString( row, 5 );
674 dst_path = resolve_folder( package, dst_key, FALSE, FALSE, TRUE, NULL );
678 dst_path = msi_dup_property( package->db, dst_key );
681 FIXME("Unable to get destination folder, try AppSearch properties\n");
682 msi_free( dst_name );
688 dst = build_directory_name( 2, dst_path, dst_name );
689 create_full_pathW( dst_path );
691 msi_free( dst_name );
692 msi_free( dst_path );
696 static UINT ITERATE_DuplicateFiles(MSIRECORD *row, LPVOID param)
698 MSIPACKAGE *package = param;
700 LPCWSTR file_key, component;
705 component = MSI_RecordGetString(row,2);
706 comp = get_loaded_component(package,component);
708 return ERROR_SUCCESS;
710 if (comp->ActionRequest != INSTALLSTATE_LOCAL)
712 TRACE("Component not scheduled for installation %s\n", debugstr_w(component));
713 comp->Action = comp->Installed;
714 return ERROR_SUCCESS;
716 comp->Action = INSTALLSTATE_LOCAL;
718 file_key = MSI_RecordGetString(row,3);
721 ERR("Unable to get file key\n");
722 return ERROR_FUNCTION_FAILED;
725 file = get_loaded_file( package, file_key );
728 ERR("Original file unknown %s\n", debugstr_w(file_key));
729 return ERROR_SUCCESS;
732 dest = get_duplicate_filename( package, row, file_key, file->TargetPath );
735 WARN("Unable to get duplicate filename\n");
736 return ERROR_SUCCESS;
739 TRACE("Duplicating file %s to %s\n", debugstr_w(file->TargetPath), debugstr_w(dest));
741 if (!CopyFileW( file->TargetPath, dest, TRUE ))
743 WARN("Failed to copy file %s -> %s (%u)\n",
744 debugstr_w(file->TargetPath), debugstr_w(dest), GetLastError());
747 FIXME("We should track these duplicate files as well\n");
749 uirow = MSI_CreateRecord( 9 );
750 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString( row, 1 ) );
751 MSI_RecordSetInteger( uirow, 6, file->FileSize );
752 MSI_RecordSetStringW( uirow, 9, MSI_RecordGetString( row, 5 ) );
753 ui_actiondata( package, szDuplicateFiles, uirow );
754 msiobj_release( &uirow->hdr );
757 return ERROR_SUCCESS;
760 UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
764 static const WCHAR ExecSeqQuery[] =
765 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
766 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
768 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
769 if (rc != ERROR_SUCCESS)
770 return ERROR_SUCCESS;
772 rc = MSI_IterateRecords(view, NULL, ITERATE_DuplicateFiles, package);
773 msiobj_release(&view->hdr);
778 static UINT ITERATE_RemoveDuplicateFiles( MSIRECORD *row, LPVOID param )
780 MSIPACKAGE *package = param;
782 LPCWSTR file_key, component;
787 component = MSI_RecordGetString( row, 2 );
788 comp = get_loaded_component( package, component );
790 return ERROR_SUCCESS;
792 if (comp->ActionRequest != INSTALLSTATE_ABSENT)
794 TRACE("Component not scheduled for removal %s\n", debugstr_w(component));
795 comp->Action = comp->Installed;
796 return ERROR_SUCCESS;
798 comp->Action = INSTALLSTATE_ABSENT;
800 file_key = MSI_RecordGetString( row, 3 );
803 ERR("Unable to get file key\n");
804 return ERROR_FUNCTION_FAILED;
807 file = get_loaded_file( package, file_key );
810 ERR("Original file unknown %s\n", debugstr_w(file_key));
811 return ERROR_SUCCESS;
814 dest = get_duplicate_filename( package, row, file_key, file->TargetPath );
817 WARN("Unable to get duplicate filename\n");
818 return ERROR_SUCCESS;
821 TRACE("Removing duplicate %s of %s\n", debugstr_w(dest), debugstr_w(file->TargetPath));
823 if (!DeleteFileW( dest ))
825 WARN("Failed to delete duplicate file %s (%u)\n", debugstr_w(dest), GetLastError());
828 uirow = MSI_CreateRecord( 9 );
829 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString( row, 1 ) );
830 MSI_RecordSetStringW( uirow, 9, MSI_RecordGetString( row, 5 ) );
831 ui_actiondata( package, szRemoveDuplicateFiles, uirow );
832 msiobj_release( &uirow->hdr );
835 return ERROR_SUCCESS;
838 UINT ACTION_RemoveDuplicateFiles( MSIPACKAGE *package )
842 static const WCHAR query[] =
843 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
844 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
846 rc = MSI_DatabaseOpenViewW( package->db, query, &view );
847 if (rc != ERROR_SUCCESS)
848 return ERROR_SUCCESS;
850 rc = MSI_IterateRecords( view, NULL, ITERATE_RemoveDuplicateFiles, package );
851 msiobj_release( &view->hdr );
856 static BOOL verify_comp_for_removal(MSICOMPONENT *comp, UINT install_mode)
858 INSTALLSTATE request = comp->ActionRequest;
860 if (request == INSTALLSTATE_UNKNOWN)
863 if (install_mode == msidbRemoveFileInstallModeOnInstall &&
864 (request == INSTALLSTATE_LOCAL || request == INSTALLSTATE_SOURCE))
867 if (request == INSTALLSTATE_ABSENT)
869 if (!comp->ComponentId)
872 if (install_mode == msidbRemoveFileInstallModeOnRemove)
876 if (install_mode == msidbRemoveFileInstallModeOnBoth)
882 static UINT ITERATE_RemoveFiles(MSIRECORD *row, LPVOID param)
884 MSIPACKAGE *package = param;
887 LPCWSTR component, filename, dirprop;
889 LPWSTR dir = NULL, path = NULL;
891 UINT ret = ERROR_SUCCESS;
893 component = MSI_RecordGetString(row, 2);
894 filename = MSI_RecordGetString(row, 3);
895 dirprop = MSI_RecordGetString(row, 4);
896 install_mode = MSI_RecordGetInteger(row, 5);
898 comp = get_loaded_component(package, component);
901 ERR("Invalid component: %s\n", debugstr_w(component));
902 return ERROR_FUNCTION_FAILED;
905 if (!verify_comp_for_removal(comp, install_mode))
907 TRACE("Skipping removal due to missing conditions\n");
908 comp->Action = comp->Installed;
909 return ERROR_SUCCESS;
912 dir = msi_dup_property(package->db, dirprop);
914 return ERROR_OUTOFMEMORY;
916 size = (filename != NULL) ? lstrlenW(filename) : 0;
917 size += lstrlenW(dir) + 2;
918 path = msi_alloc(size * sizeof(WCHAR));
921 ret = ERROR_OUTOFMEMORY;
928 PathAddBackslashW(path);
929 lstrcatW(path, filename);
931 TRACE("Deleting misc file: %s\n", debugstr_w(path));
936 TRACE("Removing misc directory: %s\n", debugstr_w(dir));
937 RemoveDirectoryW(dir);
941 uirow = MSI_CreateRecord( 9 );
942 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString(row, 1) );
943 MSI_RecordSetStringW( uirow, 9, dir );
944 ui_actiondata( package, szRemoveFiles, uirow );
945 msiobj_release( &uirow->hdr );
952 UINT ACTION_RemoveFiles( MSIPACKAGE *package )
958 static const WCHAR query[] = {
959 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
960 '`','R','e','m','o','v','e','F','i','l','e','`',0};
961 static const WCHAR folder_query[] = {
962 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
963 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0};
965 r = MSI_DatabaseOpenViewW(package->db, query, &view);
966 if (r == ERROR_SUCCESS)
968 MSI_IterateRecords(view, NULL, ITERATE_RemoveFiles, package);
969 msiobj_release(&view->hdr);
972 r = MSI_DatabaseOpenViewW(package->db, folder_query, &view);
973 if (r == ERROR_SUCCESS)
974 msiobj_release(&view->hdr);
976 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
979 LPWSTR dir, uipath, p;
981 if ( file->state == msifs_installed )
982 ERR("removing installed file %s\n", debugstr_w(file->TargetPath));
984 if ( file->Component->ActionRequest != INSTALLSTATE_ABSENT ||
985 file->Component->Installed == INSTALLSTATE_SOURCE )
988 /* don't remove a file if the old file
989 * is strictly newer than the version to be installed
991 if ( msi_compare_file_version( file ) < 0 )
994 TRACE("removing %s\n", debugstr_w(file->File) );
995 if (!DeleteFileW( file->TargetPath ))
997 WARN("failed to delete %s\n", debugstr_w(file->TargetPath));
999 /* FIXME: check persistence for each directory */
1000 else if (r && (dir = strdupW( file->TargetPath )))
1002 if ((p = strrchrW( dir, '\\' ))) *p = 0;
1003 RemoveDirectoryW( dir );
1006 file->state = msifs_missing;
1009 uirow = MSI_CreateRecord( 9 );
1010 MSI_RecordSetStringW( uirow, 1, file->FileName );
1011 uipath = strdupW( file->TargetPath );
1012 p = strrchrW(uipath,'\\');
1015 MSI_RecordSetStringW( uirow, 9, uipath);
1016 ui_actiondata( package, szRemoveFiles, uirow);
1017 msiobj_release( &uirow->hdr );
1019 /* FIXME: call ui_progress here? */
1022 return ERROR_SUCCESS;