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 )
54 uirow = MSI_CreateRecord( 9 );
55 MSI_RecordSetStringW( uirow, 1, f->FileName );
56 MSI_RecordSetStringW( uirow, 9, f->Component->Directory );
57 MSI_RecordSetInteger( uirow, 6, f->FileSize );
58 ui_actiondata( package, action, uirow );
59 msiobj_release( &uirow->hdr );
60 ui_progress( package, 2, f->FileSize, 0, 0 );
63 static void schedule_install_files(MSIPACKAGE *package)
67 LIST_FOR_EACH_ENTRY(file, &package->files, MSIFILE, entry)
69 if (file->Component->ActionRequest != INSTALLSTATE_LOCAL || !file->Component->Enabled)
71 TRACE("File %s is not scheduled for install\n", debugstr_w(file->File));
73 ui_progress(package,2,file->FileSize,0,0);
74 file->state = msifs_skipped;
77 file->Component->Action = INSTALLSTATE_LOCAL;
81 static UINT copy_file(MSIFILE *file, LPWSTR source)
85 ret = CopyFileW(source, file->TargetPath, FALSE);
87 return GetLastError();
89 SetFileAttributesW(file->TargetPath, FILE_ATTRIBUTE_NORMAL);
91 file->state = msifs_installed;
95 static UINT copy_install_file(MSIPACKAGE *package, MSIFILE *file, LPWSTR source)
99 TRACE("Copying %s to %s\n", debugstr_w(source), debugstr_w(file->TargetPath));
101 gle = copy_file(file, source);
102 if (gle == ERROR_SUCCESS)
105 if (gle == ERROR_ALREADY_EXISTS && file->state == msifs_overwrite)
107 TRACE("overwriting existing file\n");
108 return ERROR_SUCCESS;
110 else if (gle == ERROR_ACCESS_DENIED)
112 SetFileAttributesW(file->TargetPath, FILE_ATTRIBUTE_NORMAL);
114 gle = copy_file(file, source);
115 TRACE("Overwriting existing file: %d\n", gle);
117 if (gle == ERROR_SHARING_VIOLATION || gle == ERROR_USER_MAPPED_FILE)
119 WCHAR tmpfileW[MAX_PATH], *pathW, *p;
122 TRACE("file in use, scheduling rename operation\n");
124 GetTempFileNameW(szBackSlash, szMsi, 0, tmpfileW);
125 len = strlenW(file->TargetPath) + strlenW(tmpfileW) + 1;
126 if (!(pathW = msi_alloc(len * sizeof(WCHAR))))
127 return ERROR_OUTOFMEMORY;
129 strcpyW(pathW, file->TargetPath);
130 if ((p = strrchrW(pathW, '\\'))) *p = 0;
131 strcatW(pathW, tmpfileW);
133 if (CopyFileW(source, pathW, FALSE) &&
134 MoveFileExW(file->TargetPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT) &&
135 MoveFileExW(pathW, file->TargetPath, MOVEFILE_DELAY_UNTIL_REBOOT))
137 file->state = msifs_installed;
138 package->need_reboot = 1;
143 gle = GetLastError();
144 WARN("failed to schedule rename operation: %d)\n", gle);
152 static UINT msi_create_directory( MSIPACKAGE *package, const WCHAR *dir )
157 install_path = resolve_folder( package, dir, FALSE, FALSE, TRUE, &folder );
159 return ERROR_FUNCTION_FAILED;
161 if (folder->State == 0)
163 create_full_pathW( install_path );
166 msi_free( install_path );
167 return ERROR_SUCCESS;
170 static BOOL installfiles_cb(MSIPACKAGE *package, LPCWSTR file, DWORD action,
171 LPWSTR *path, DWORD *attrs, PVOID user)
173 static MSIFILE *f = NULL;
174 UINT_PTR disk_id = (UINT_PTR)user;
176 if (action == MSICABEXTRACT_BEGINEXTRACT)
178 f = get_loaded_file(package, file);
181 WARN("unknown file in cabinet (%s)\n", debugstr_w(file));
185 if (f->disk_id != disk_id || (f->state != msifs_missing && f->state != msifs_overwrite))
188 msi_file_update_ui(package, f, szInstallFiles);
189 if (!f->Component->assembly)
190 msi_create_directory(package, f->Component->Directory);
192 *path = strdupW(f->TargetPath);
193 *attrs = f->Attributes;
195 else if (action == MSICABEXTRACT_FILEEXTRACTED)
197 f->state = msifs_installed;
205 * ACTION_InstallFiles()
207 * For efficiency, this is done in two passes:
208 * 1) Correct all the TargetPaths and determine what files are to be installed.
209 * 2) Extract Cabinets and copy files.
211 UINT ACTION_InstallFiles(MSIPACKAGE *package)
215 UINT rc = ERROR_SUCCESS;
218 /* increment progress bar each time action data is sent */
219 ui_progress(package,1,1,0,0);
221 schedule_install_files(package);
223 mi = msi_alloc_zero( sizeof(MSIMEDIAINFO) );
225 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
227 if (file->state != msifs_missing && !mi->is_continuous && file->state != msifs_overwrite)
230 if (file->state == msifs_overwrite &&
231 (file->Component->Attributes & msidbComponentAttributesNeverOverwrite))
233 TRACE("not overwriting %s\n", debugstr_w(file->TargetPath));
234 file->state = msifs_skipped;
238 if (file->Sequence > mi->last_sequence || mi->is_continuous ||
239 (file->IsCompressed && !mi->is_extracted))
243 rc = ready_media(package, file, mi);
244 if (rc != ERROR_SUCCESS)
246 ERR("Failed to ready media for %s\n", debugstr_w(file->File));
251 data.package = package;
252 data.cb = installfiles_cb;
253 data.user = (PVOID)(UINT_PTR)mi->disk_id;
255 if (file->IsCompressed &&
256 !msi_cabextract(package, mi, &data))
258 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi->cabinet));
259 rc = ERROR_INSTALL_FAILURE;
264 if (!file->IsCompressed)
266 LPWSTR source = resolve_file_source(package, file);
268 TRACE("copying %s to %s\n", debugstr_w(source), debugstr_w(file->TargetPath));
270 msi_file_update_ui(package, file, szInstallFiles);
271 if (!file->Component->assembly)
272 msi_create_directory(package, file->Component->Directory);
274 rc = copy_install_file(package, file, source);
275 if (rc != ERROR_SUCCESS)
277 ERR("Failed to copy %s to %s (%d)\n", debugstr_w(source),
278 debugstr_w(file->TargetPath), rc);
279 rc = ERROR_INSTALL_FAILURE;
285 else if (file->state != msifs_installed)
287 ERR("compressed file wasn't installed (%s)\n", debugstr_w(file->TargetPath));
288 rc = ERROR_INSTALL_FAILURE;
292 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
294 if (comp->Enabled && comp->assembly && !comp->assembly->installed)
296 rc = install_assembly( package, comp );
297 if (rc != ERROR_SUCCESS)
299 ERR("Failed to install assembly\n");
300 rc = ERROR_INSTALL_FAILURE;
307 msi_free_media_info(mi);
311 #define is_dot_dir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
322 static BOOL msi_move_file(LPCWSTR source, LPCWSTR dest, int options)
326 if (GetFileAttributesW(source) == FILE_ATTRIBUTE_DIRECTORY ||
327 GetFileAttributesW(dest) == FILE_ATTRIBUTE_DIRECTORY)
329 WARN("Source or dest is directory, not moving\n");
333 if (options == msidbMoveFileOptionsMove)
335 TRACE("moving %s -> %s\n", debugstr_w(source), debugstr_w(dest));
336 ret = MoveFileExW(source, dest, MOVEFILE_REPLACE_EXISTING);
339 WARN("MoveFile failed: %d\n", GetLastError());
345 TRACE("copying %s -> %s\n", debugstr_w(source), debugstr_w(dest));
346 ret = CopyFileW(source, dest, FALSE);
349 WARN("CopyFile failed: %d\n", GetLastError());
357 static LPWSTR wildcard_to_file(LPWSTR wildcard, LPWSTR filename)
360 DWORD dirlen, pathlen;
362 ptr = strrchrW(wildcard, '\\');
363 dirlen = ptr - wildcard + 1;
365 pathlen = dirlen + lstrlenW(filename) + 1;
366 path = msi_alloc(pathlen * sizeof(WCHAR));
368 lstrcpynW(path, wildcard, dirlen + 1);
369 lstrcatW(path, filename);
374 static void free_file_entry(FILE_LIST *file)
376 msi_free(file->source);
377 msi_free(file->dest);
381 static void free_list(FILE_LIST *list)
383 while (!list_empty(&list->entry))
385 FILE_LIST *file = LIST_ENTRY(list_head(&list->entry), FILE_LIST, entry);
387 list_remove(&file->entry);
388 free_file_entry(file);
392 static BOOL add_wildcard(FILE_LIST *files, LPWSTR source, LPWSTR dest)
394 FILE_LIST *new, *file;
395 LPWSTR ptr, filename;
398 new = msi_alloc_zero(sizeof(FILE_LIST));
402 new->source = strdupW(source);
403 ptr = strrchrW(dest, '\\') + 1;
404 filename = strrchrW(new->source, '\\') + 1;
406 new->sourcename = filename;
411 new->destname = new->sourcename;
413 size = (ptr - dest) + lstrlenW(filename) + 1;
414 new->dest = msi_alloc(size * sizeof(WCHAR));
417 free_file_entry(new);
421 lstrcpynW(new->dest, dest, ptr - dest + 1);
422 lstrcatW(new->dest, filename);
424 if (list_empty(&files->entry))
426 list_add_head(&files->entry, &new->entry);
430 LIST_FOR_EACH_ENTRY(file, &files->entry, FILE_LIST, entry)
432 if (strcmpW( source, file->source ) < 0)
434 list_add_before(&file->entry, &new->entry);
439 list_add_after(&file->entry, &new->entry);
443 static BOOL move_files_wildcard(LPWSTR source, LPWSTR dest, int options)
445 WIN32_FIND_DATAW wfd;
449 FILE_LIST files, *file;
452 hfile = FindFirstFileW(source, &wfd);
453 if (hfile == INVALID_HANDLE_VALUE) return FALSE;
455 list_init(&files.entry);
457 for (res = TRUE; res; res = FindNextFileW(hfile, &wfd))
459 if (is_dot_dir(wfd.cFileName)) continue;
461 path = wildcard_to_file(source, wfd.cFileName);
468 add_wildcard(&files, path, dest);
472 /* no files match the wildcard */
473 if (list_empty(&files.entry))
476 /* only the first wildcard match gets renamed to dest */
477 file = LIST_ENTRY(list_head(&files.entry), FILE_LIST, entry);
478 size = (strrchrW(file->dest, '\\') - file->dest) + lstrlenW(file->destname) + 2;
479 file->dest = msi_realloc(file->dest, size * sizeof(WCHAR));
486 /* file->dest may be shorter after the reallocation, so add a NULL
487 * terminator. This is needed for the call to strrchrW, as there will no
488 * longer be a NULL terminator within the bounds of the allocation in this case.
490 file->dest[size - 1] = '\0';
491 lstrcpyW(strrchrW(file->dest, '\\') + 1, file->destname);
493 while (!list_empty(&files.entry))
495 file = LIST_ENTRY(list_head(&files.entry), FILE_LIST, entry);
497 msi_move_file(file->source, file->dest, options);
499 list_remove(&file->entry);
500 free_file_entry(file);
511 static UINT ITERATE_MoveFiles( MSIRECORD *rec, LPVOID param )
513 MSIPACKAGE *package = param;
516 LPCWSTR sourcename, component;
517 LPWSTR sourcedir, destname = NULL, destdir = NULL, source = NULL, dest = NULL;
522 component = MSI_RecordGetString(rec, 2);
523 comp = get_loaded_component(package, component);
525 return ERROR_SUCCESS;
529 TRACE("component is disabled\n");
530 return ERROR_SUCCESS;
533 if (comp->ActionRequest != INSTALLSTATE_LOCAL && comp->ActionRequest != INSTALLSTATE_SOURCE)
535 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component));
536 comp->Action = comp->Installed;
537 return ERROR_SUCCESS;
539 comp->Action = comp->ActionRequest;
541 sourcename = MSI_RecordGetString(rec, 3);
542 options = MSI_RecordGetInteger(rec, 7);
544 sourcedir = msi_dup_property(package->db, MSI_RecordGetString(rec, 5));
548 destdir = msi_dup_property(package->db, MSI_RecordGetString(rec, 6));
554 if (GetFileAttributesW(sourcedir) == INVALID_FILE_ATTRIBUTES)
557 source = strdupW(sourcedir);
563 size = lstrlenW(sourcedir) + lstrlenW(sourcename) + 2;
564 source = msi_alloc(size * sizeof(WCHAR));
568 lstrcpyW(source, sourcedir);
569 if (source[lstrlenW(source) - 1] != '\\')
570 lstrcatW(source, szBackSlash);
571 lstrcatW(source, sourcename);
574 wildcards = strchrW(source, '*') || strchrW(source, '?');
576 if (MSI_RecordIsNull(rec, 4))
580 destname = strdupW(sourcename);
587 destname = strdupW(MSI_RecordGetString(rec, 4));
589 reduce_to_longfilename(destname);
594 size = lstrlenW(destname);
596 size += lstrlenW(destdir) + 2;
597 dest = msi_alloc(size * sizeof(WCHAR));
601 lstrcpyW(dest, destdir);
602 if (dest[lstrlenW(dest) - 1] != '\\')
603 lstrcatW(dest, szBackSlash);
606 lstrcatW(dest, destname);
608 if (GetFileAttributesW(destdir) == INVALID_FILE_ATTRIBUTES)
610 ret = CreateDirectoryW(destdir, NULL);
613 WARN("CreateDirectory failed: %d\n", GetLastError());
619 msi_move_file(source, dest, options);
621 move_files_wildcard(source, dest, options);
624 uirow = MSI_CreateRecord( 9 );
625 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString(rec, 1) );
626 MSI_RecordSetInteger( uirow, 6, 1 ); /* FIXME */
627 MSI_RecordSetStringW( uirow, 9, destdir );
628 ui_actiondata( package, szMoveFiles, uirow );
629 msiobj_release( &uirow->hdr );
637 return ERROR_SUCCESS;
640 UINT ACTION_MoveFiles( MSIPACKAGE *package )
645 static const WCHAR ExecSeqQuery[] =
646 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
647 '`','M','o','v','e','F','i','l','e','`',0};
649 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
650 if (rc != ERROR_SUCCESS)
651 return ERROR_SUCCESS;
653 rc = MSI_IterateRecords(view, NULL, ITERATE_MoveFiles, package);
654 msiobj_release(&view->hdr);
659 static WCHAR *get_duplicate_filename( MSIPACKAGE *package, MSIRECORD *row, const WCHAR *file_key, const WCHAR *src )
662 WCHAR *dst_name, *dst_path, *dst;
664 if (MSI_RecordIsNull( row, 4 ))
666 len = strlenW( src ) + 1;
667 if (!(dst_name = msi_alloc( len * sizeof(WCHAR)))) return NULL;
668 strcpyW( dst_name, strrchrW( src, '\\' ) + 1 );
672 MSI_RecordGetStringW( row, 4, NULL, &len );
673 if (!(dst_name = msi_alloc( ++len * sizeof(WCHAR) ))) return NULL;
674 MSI_RecordGetStringW( row, 4, dst_name, &len );
675 reduce_to_longfilename( dst_name );
678 if (MSI_RecordIsNull( row, 5 ))
681 dst_path = strdupW( src );
682 p = strrchrW( dst_path, '\\' );
687 const WCHAR *dst_key = MSI_RecordGetString( row, 5 );
689 dst_path = resolve_folder( package, dst_key, FALSE, FALSE, TRUE, NULL );
693 dst_path = msi_dup_property( package->db, dst_key );
696 FIXME("Unable to get destination folder, try AppSearch properties\n");
697 msi_free( dst_name );
703 dst = build_directory_name( 2, dst_path, dst_name );
704 create_full_pathW( dst_path );
706 msi_free( dst_name );
707 msi_free( dst_path );
711 static UINT ITERATE_DuplicateFiles(MSIRECORD *row, LPVOID param)
713 MSIPACKAGE *package = param;
715 LPCWSTR file_key, component;
720 component = MSI_RecordGetString(row,2);
721 comp = get_loaded_component(package,component);
723 return ERROR_SUCCESS;
727 TRACE("component is disabled\n");
728 return ERROR_SUCCESS;
731 if (comp->ActionRequest != INSTALLSTATE_LOCAL)
733 TRACE("Component not scheduled for installation %s\n", debugstr_w(component));
734 comp->Action = comp->Installed;
735 return ERROR_SUCCESS;
737 comp->Action = INSTALLSTATE_LOCAL;
739 file_key = MSI_RecordGetString(row,3);
742 ERR("Unable to get file key\n");
743 return ERROR_FUNCTION_FAILED;
746 file = get_loaded_file( package, file_key );
749 ERR("Original file unknown %s\n", debugstr_w(file_key));
750 return ERROR_SUCCESS;
753 dest = get_duplicate_filename( package, row, file_key, file->TargetPath );
756 WARN("Unable to get duplicate filename\n");
757 return ERROR_SUCCESS;
760 TRACE("Duplicating file %s to %s\n", debugstr_w(file->TargetPath), debugstr_w(dest));
762 if (!CopyFileW( file->TargetPath, dest, TRUE ))
764 WARN("Failed to copy file %s -> %s (%u)\n",
765 debugstr_w(file->TargetPath), debugstr_w(dest), GetLastError());
768 FIXME("We should track these duplicate files as well\n");
770 uirow = MSI_CreateRecord( 9 );
771 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString( row, 1 ) );
772 MSI_RecordSetInteger( uirow, 6, file->FileSize );
773 MSI_RecordSetStringW( uirow, 9, MSI_RecordGetString( row, 5 ) );
774 ui_actiondata( package, szDuplicateFiles, uirow );
775 msiobj_release( &uirow->hdr );
778 return ERROR_SUCCESS;
781 UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
785 static const WCHAR ExecSeqQuery[] =
786 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
787 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
789 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
790 if (rc != ERROR_SUCCESS)
791 return ERROR_SUCCESS;
793 rc = MSI_IterateRecords(view, NULL, ITERATE_DuplicateFiles, package);
794 msiobj_release(&view->hdr);
799 static UINT ITERATE_RemoveDuplicateFiles( MSIRECORD *row, LPVOID param )
801 MSIPACKAGE *package = param;
803 LPCWSTR file_key, component;
808 component = MSI_RecordGetString( row, 2 );
809 comp = get_loaded_component( package, component );
811 return ERROR_SUCCESS;
815 TRACE("component is disabled\n");
816 return ERROR_SUCCESS;
819 if (comp->ActionRequest != INSTALLSTATE_ABSENT)
821 TRACE("Component not scheduled for removal %s\n", debugstr_w(component));
822 comp->Action = comp->Installed;
823 return ERROR_SUCCESS;
825 comp->Action = INSTALLSTATE_ABSENT;
827 file_key = MSI_RecordGetString( row, 3 );
830 ERR("Unable to get file key\n");
831 return ERROR_FUNCTION_FAILED;
834 file = get_loaded_file( package, file_key );
837 ERR("Original file unknown %s\n", debugstr_w(file_key));
838 return ERROR_SUCCESS;
841 dest = get_duplicate_filename( package, row, file_key, file->TargetPath );
844 WARN("Unable to get duplicate filename\n");
845 return ERROR_SUCCESS;
848 TRACE("Removing duplicate %s of %s\n", debugstr_w(dest), debugstr_w(file->TargetPath));
850 if (!DeleteFileW( dest ))
852 WARN("Failed to delete duplicate file %s (%u)\n", debugstr_w(dest), GetLastError());
855 uirow = MSI_CreateRecord( 9 );
856 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString( row, 1 ) );
857 MSI_RecordSetStringW( uirow, 9, MSI_RecordGetString( row, 5 ) );
858 ui_actiondata( package, szRemoveDuplicateFiles, uirow );
859 msiobj_release( &uirow->hdr );
862 return ERROR_SUCCESS;
865 UINT ACTION_RemoveDuplicateFiles( MSIPACKAGE *package )
869 static const WCHAR query[] =
870 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
871 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
873 rc = MSI_DatabaseOpenViewW( package->db, query, &view );
874 if (rc != ERROR_SUCCESS)
875 return ERROR_SUCCESS;
877 rc = MSI_IterateRecords( view, NULL, ITERATE_RemoveDuplicateFiles, package );
878 msiobj_release( &view->hdr );
883 static BOOL verify_comp_for_removal(MSICOMPONENT *comp, UINT install_mode)
885 INSTALLSTATE request = comp->ActionRequest;
887 if (request == INSTALLSTATE_UNKNOWN)
890 if (install_mode == msidbRemoveFileInstallModeOnInstall &&
891 (request == INSTALLSTATE_LOCAL || request == INSTALLSTATE_SOURCE))
894 if (request == INSTALLSTATE_ABSENT)
896 if (!comp->ComponentId)
899 if (install_mode == msidbRemoveFileInstallModeOnRemove)
903 if (install_mode == msidbRemoveFileInstallModeOnBoth)
909 static UINT ITERATE_RemoveFiles(MSIRECORD *row, LPVOID param)
911 MSIPACKAGE *package = param;
914 LPCWSTR component, filename, dirprop;
916 LPWSTR dir = NULL, path = NULL;
918 UINT ret = ERROR_SUCCESS;
920 component = MSI_RecordGetString(row, 2);
921 filename = MSI_RecordGetString(row, 3);
922 dirprop = MSI_RecordGetString(row, 4);
923 install_mode = MSI_RecordGetInteger(row, 5);
925 comp = get_loaded_component(package, component);
928 ERR("Invalid component: %s\n", debugstr_w(component));
929 return ERROR_FUNCTION_FAILED;
934 TRACE("component is disabled\n");
935 return ERROR_SUCCESS;
938 if (!verify_comp_for_removal(comp, install_mode))
940 TRACE("Skipping removal due to missing conditions\n");
941 comp->Action = comp->Installed;
942 return ERROR_SUCCESS;
945 dir = msi_dup_property(package->db, dirprop);
947 return ERROR_OUTOFMEMORY;
949 size = (filename != NULL) ? lstrlenW(filename) : 0;
950 size += lstrlenW(dir) + 2;
951 path = msi_alloc(size * sizeof(WCHAR));
954 ret = ERROR_OUTOFMEMORY;
961 PathAddBackslashW(path);
962 lstrcatW(path, filename);
964 TRACE("Deleting misc file: %s\n", debugstr_w(path));
969 TRACE("Removing misc directory: %s\n", debugstr_w(dir));
970 RemoveDirectoryW(dir);
974 uirow = MSI_CreateRecord( 9 );
975 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString(row, 1) );
976 MSI_RecordSetStringW( uirow, 9, dir );
977 ui_actiondata( package, szRemoveFiles, uirow );
978 msiobj_release( &uirow->hdr );
985 UINT ACTION_RemoveFiles( MSIPACKAGE *package )
991 static const WCHAR query[] = {
992 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
993 '`','R','e','m','o','v','e','F','i','l','e','`',0};
994 static const WCHAR folder_query[] = {
995 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
996 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0};
998 r = MSI_DatabaseOpenViewW(package->db, query, &view);
999 if (r == ERROR_SUCCESS)
1001 MSI_IterateRecords(view, NULL, ITERATE_RemoveFiles, package);
1002 msiobj_release(&view->hdr);
1005 r = MSI_DatabaseOpenViewW(package->db, folder_query, &view);
1006 if (r == ERROR_SUCCESS)
1007 msiobj_release(&view->hdr);
1009 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
1013 VS_FIXEDFILEINFO *ver;
1015 if ( file->state == msifs_installed )
1016 ERR("removing installed file %s\n", debugstr_w(file->TargetPath));
1018 if ( file->Component->ActionRequest != INSTALLSTATE_ABSENT ||
1019 file->Component->Installed == INSTALLSTATE_SOURCE )
1022 if (!file->Component->Enabled)
1024 TRACE("component is disabled\n");
1030 ver = msi_get_disk_file_version( file->TargetPath );
1031 if (ver && msi_compare_file_versions( ver, file->Version ) > 0)
1033 TRACE("newer version detected, not removing file\n");
1040 TRACE("removing %s\n", debugstr_w(file->File) );
1041 if (!DeleteFileW( file->TargetPath ))
1043 WARN("failed to delete %s\n", debugstr_w(file->TargetPath));
1045 /* FIXME: check persistence for each directory */
1046 else if (r && (dir = strdupW( file->TargetPath )))
1048 if ((p = strrchrW( dir, '\\' ))) *p = 0;
1049 RemoveDirectoryW( dir );
1052 file->state = msifs_missing;
1054 uirow = MSI_CreateRecord( 9 );
1055 MSI_RecordSetStringW( uirow, 1, file->FileName );
1056 MSI_RecordSetStringW( uirow, 9, file->Component->Directory );
1057 ui_actiondata( package, szRemoveFiles, uirow );
1058 msiobj_release( &uirow->hdr );
1059 /* FIXME: call ui_progress here? */
1062 return ERROR_SUCCESS;