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 MSICOMPONENT *comp = file->Component;
71 if (comp->ActionRequest != INSTALLSTATE_LOCAL || !comp->Enabled)
73 TRACE("File %s is not scheduled for install\n", debugstr_w(file->File));
74 file->state = msifs_skipped;
77 comp->Action = INSTALLSTATE_LOCAL;
78 ui_progress( package, 2, file->FileSize, 0, 0 );
80 if (file->state == msifs_overwrite &&
81 (comp->Attributes & msidbComponentAttributesNeverOverwrite))
83 TRACE("not overwriting %s\n", debugstr_w(file->TargetPath));
84 file->state = msifs_skipped;
89 static UINT copy_file(MSIFILE *file, LPWSTR source)
93 ret = CopyFileW(source, file->TargetPath, FALSE);
95 return GetLastError();
97 SetFileAttributesW(file->TargetPath, FILE_ATTRIBUTE_NORMAL);
99 file->state = msifs_installed;
100 return ERROR_SUCCESS;
103 static UINT copy_install_file(MSIPACKAGE *package, MSIFILE *file, LPWSTR source)
107 TRACE("Copying %s to %s\n", debugstr_w(source), debugstr_w(file->TargetPath));
109 gle = copy_file(file, source);
110 if (gle == ERROR_SUCCESS)
113 if (gle == ERROR_ALREADY_EXISTS && file->state == msifs_overwrite)
115 TRACE("overwriting existing file\n");
116 return ERROR_SUCCESS;
118 else if (gle == ERROR_ACCESS_DENIED)
120 SetFileAttributesW(file->TargetPath, FILE_ATTRIBUTE_NORMAL);
122 gle = copy_file(file, source);
123 TRACE("Overwriting existing file: %d\n", gle);
125 if (gle == ERROR_SHARING_VIOLATION || gle == ERROR_USER_MAPPED_FILE)
127 WCHAR tmpfileW[MAX_PATH], *pathW, *p;
130 TRACE("file in use, scheduling rename operation\n");
132 GetTempFileNameW(szBackSlash, szMsi, 0, tmpfileW);
133 len = strlenW(file->TargetPath) + strlenW(tmpfileW) + 1;
134 if (!(pathW = msi_alloc(len * sizeof(WCHAR))))
135 return ERROR_OUTOFMEMORY;
137 strcpyW(pathW, file->TargetPath);
138 if ((p = strrchrW(pathW, '\\'))) *p = 0;
139 strcatW(pathW, tmpfileW);
141 if (CopyFileW(source, pathW, FALSE) &&
142 MoveFileExW(file->TargetPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT) &&
143 MoveFileExW(pathW, file->TargetPath, MOVEFILE_DELAY_UNTIL_REBOOT))
145 file->state = msifs_installed;
146 package->need_reboot = 1;
151 gle = GetLastError();
152 WARN("failed to schedule rename operation: %d)\n", gle);
160 static UINT msi_create_directory( MSIPACKAGE *package, const WCHAR *dir )
165 install_path = resolve_folder( package, dir, FALSE, FALSE, TRUE, &folder );
167 return ERROR_FUNCTION_FAILED;
169 if (folder->State == 0)
171 create_full_pathW( install_path );
174 msi_free( install_path );
175 return ERROR_SUCCESS;
178 static BOOL installfiles_cb(MSIPACKAGE *package, LPCWSTR file, DWORD action,
179 LPWSTR *path, DWORD *attrs, PVOID user)
181 static MSIFILE *f = NULL;
182 UINT_PTR disk_id = (UINT_PTR)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 != disk_id || (f->state != msifs_missing && f->state != msifs_overwrite))
196 msi_file_update_ui(package, f, szInstallFiles);
197 if (!f->Component->assembly || f->Component->assembly->application)
199 msi_create_directory(package, f->Component->Directory);
201 *path = strdupW(f->TargetPath);
202 *attrs = f->Attributes;
204 else if (action == MSICABEXTRACT_FILEEXTRACTED)
206 f->state = msifs_installed;
214 * ACTION_InstallFiles()
216 * For efficiency, this is done in two passes:
217 * 1) Correct all the TargetPaths and determine what files are to be installed.
218 * 2) Extract Cabinets and copy files.
220 UINT ACTION_InstallFiles(MSIPACKAGE *package)
224 UINT rc = ERROR_SUCCESS;
227 /* increment progress bar each time action data is sent */
228 ui_progress(package,1,1,0,0);
230 schedule_install_files(package);
232 mi = msi_alloc_zero( sizeof(MSIMEDIAINFO) );
234 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
236 if (file->state != msifs_missing && !mi->is_continuous && file->state != msifs_overwrite)
239 if (file->Sequence > mi->last_sequence || mi->is_continuous ||
240 (file->IsCompressed && !mi->is_extracted))
244 rc = ready_media(package, file, mi);
245 if (rc != ERROR_SUCCESS)
247 ERR("Failed to ready media for %s\n", debugstr_w(file->File));
252 data.package = package;
253 data.cb = installfiles_cb;
254 data.user = (PVOID)(UINT_PTR)mi->disk_id;
256 if (file->IsCompressed &&
257 !msi_cabextract(package, mi, &data))
259 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi->cabinet));
260 rc = ERROR_INSTALL_FAILURE;
265 if (!file->IsCompressed)
267 LPWSTR source = resolve_file_source(package, file);
269 TRACE("copying %s to %s\n", debugstr_w(source), debugstr_w(file->TargetPath));
271 msi_file_update_ui(package, file, szInstallFiles);
272 if (!file->Component->assembly || file->Component->assembly->application)
274 msi_create_directory(package, file->Component->Directory);
276 rc = copy_install_file(package, file, source);
277 if (rc != ERROR_SUCCESS)
279 ERR("Failed to copy %s to %s (%d)\n", debugstr_w(source),
280 debugstr_w(file->TargetPath), rc);
281 rc = ERROR_INSTALL_FAILURE;
287 else if (file->state != msifs_installed)
289 ERR("compressed file wasn't installed (%s)\n", debugstr_w(file->TargetPath));
290 rc = ERROR_INSTALL_FAILURE;
294 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
296 if (comp->ActionRequest == INSTALLSTATE_LOCAL && comp->Enabled &&
297 comp->assembly && !comp->assembly->installed)
299 rc = install_assembly( package, comp );
300 if (rc != ERROR_SUCCESS)
302 ERR("Failed to install assembly\n");
303 rc = ERROR_INSTALL_FAILURE;
310 msi_free_media_info(mi);
314 #define is_dot_dir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
325 static BOOL msi_move_file(LPCWSTR source, LPCWSTR dest, int options)
329 if (GetFileAttributesW(source) == FILE_ATTRIBUTE_DIRECTORY ||
330 GetFileAttributesW(dest) == FILE_ATTRIBUTE_DIRECTORY)
332 WARN("Source or dest is directory, not moving\n");
336 if (options == msidbMoveFileOptionsMove)
338 TRACE("moving %s -> %s\n", debugstr_w(source), debugstr_w(dest));
339 ret = MoveFileExW(source, dest, MOVEFILE_REPLACE_EXISTING);
342 WARN("MoveFile failed: %d\n", GetLastError());
348 TRACE("copying %s -> %s\n", debugstr_w(source), debugstr_w(dest));
349 ret = CopyFileW(source, dest, FALSE);
352 WARN("CopyFile failed: %d\n", GetLastError());
360 static LPWSTR wildcard_to_file(LPWSTR wildcard, LPWSTR filename)
363 DWORD dirlen, pathlen;
365 ptr = strrchrW(wildcard, '\\');
366 dirlen = ptr - wildcard + 1;
368 pathlen = dirlen + lstrlenW(filename) + 1;
369 path = msi_alloc(pathlen * sizeof(WCHAR));
371 lstrcpynW(path, wildcard, dirlen + 1);
372 lstrcatW(path, filename);
377 static void free_file_entry(FILE_LIST *file)
379 msi_free(file->source);
380 msi_free(file->dest);
384 static void free_list(FILE_LIST *list)
386 while (!list_empty(&list->entry))
388 FILE_LIST *file = LIST_ENTRY(list_head(&list->entry), FILE_LIST, entry);
390 list_remove(&file->entry);
391 free_file_entry(file);
395 static BOOL add_wildcard(FILE_LIST *files, LPWSTR source, LPWSTR dest)
397 FILE_LIST *new, *file;
398 LPWSTR ptr, filename;
401 new = msi_alloc_zero(sizeof(FILE_LIST));
405 new->source = strdupW(source);
406 ptr = strrchrW(dest, '\\') + 1;
407 filename = strrchrW(new->source, '\\') + 1;
409 new->sourcename = filename;
414 new->destname = new->sourcename;
416 size = (ptr - dest) + lstrlenW(filename) + 1;
417 new->dest = msi_alloc(size * sizeof(WCHAR));
420 free_file_entry(new);
424 lstrcpynW(new->dest, dest, ptr - dest + 1);
425 lstrcatW(new->dest, filename);
427 if (list_empty(&files->entry))
429 list_add_head(&files->entry, &new->entry);
433 LIST_FOR_EACH_ENTRY(file, &files->entry, FILE_LIST, entry)
435 if (strcmpW( source, file->source ) < 0)
437 list_add_before(&file->entry, &new->entry);
442 list_add_after(&file->entry, &new->entry);
446 static BOOL move_files_wildcard(LPWSTR source, LPWSTR dest, int options)
448 WIN32_FIND_DATAW wfd;
452 FILE_LIST files, *file;
455 hfile = FindFirstFileW(source, &wfd);
456 if (hfile == INVALID_HANDLE_VALUE) return FALSE;
458 list_init(&files.entry);
460 for (res = TRUE; res; res = FindNextFileW(hfile, &wfd))
462 if (is_dot_dir(wfd.cFileName)) continue;
464 path = wildcard_to_file(source, wfd.cFileName);
471 add_wildcard(&files, path, dest);
475 /* no files match the wildcard */
476 if (list_empty(&files.entry))
479 /* only the first wildcard match gets renamed to dest */
480 file = LIST_ENTRY(list_head(&files.entry), FILE_LIST, entry);
481 size = (strrchrW(file->dest, '\\') - file->dest) + lstrlenW(file->destname) + 2;
482 file->dest = msi_realloc(file->dest, size * sizeof(WCHAR));
489 /* file->dest may be shorter after the reallocation, so add a NULL
490 * terminator. This is needed for the call to strrchrW, as there will no
491 * longer be a NULL terminator within the bounds of the allocation in this case.
493 file->dest[size - 1] = '\0';
494 lstrcpyW(strrchrW(file->dest, '\\') + 1, file->destname);
496 while (!list_empty(&files.entry))
498 file = LIST_ENTRY(list_head(&files.entry), FILE_LIST, entry);
500 msi_move_file(file->source, file->dest, options);
502 list_remove(&file->entry);
503 free_file_entry(file);
514 static UINT ITERATE_MoveFiles( MSIRECORD *rec, LPVOID param )
516 MSIPACKAGE *package = param;
519 LPCWSTR sourcename, component;
520 LPWSTR sourcedir, destname = NULL, destdir = NULL, source = NULL, dest = NULL;
525 component = MSI_RecordGetString(rec, 2);
526 comp = get_loaded_component(package, component);
528 return ERROR_SUCCESS;
532 TRACE("component is disabled\n");
533 return ERROR_SUCCESS;
536 if (comp->ActionRequest != INSTALLSTATE_LOCAL && comp->ActionRequest != INSTALLSTATE_SOURCE)
538 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component));
539 comp->Action = comp->Installed;
540 return ERROR_SUCCESS;
542 comp->Action = comp->ActionRequest;
544 sourcename = MSI_RecordGetString(rec, 3);
545 options = MSI_RecordGetInteger(rec, 7);
547 sourcedir = msi_dup_property(package->db, MSI_RecordGetString(rec, 5));
551 destdir = msi_dup_property(package->db, MSI_RecordGetString(rec, 6));
557 if (GetFileAttributesW(sourcedir) == INVALID_FILE_ATTRIBUTES)
560 source = strdupW(sourcedir);
566 size = lstrlenW(sourcedir) + lstrlenW(sourcename) + 2;
567 source = msi_alloc(size * sizeof(WCHAR));
571 lstrcpyW(source, sourcedir);
572 if (source[lstrlenW(source) - 1] != '\\')
573 lstrcatW(source, szBackSlash);
574 lstrcatW(source, sourcename);
577 wildcards = strchrW(source, '*') || strchrW(source, '?');
579 if (MSI_RecordIsNull(rec, 4))
583 destname = strdupW(sourcename);
590 destname = strdupW(MSI_RecordGetString(rec, 4));
592 reduce_to_longfilename(destname);
597 size = lstrlenW(destname);
599 size += lstrlenW(destdir) + 2;
600 dest = msi_alloc(size * sizeof(WCHAR));
604 lstrcpyW(dest, destdir);
605 if (dest[lstrlenW(dest) - 1] != '\\')
606 lstrcatW(dest, szBackSlash);
609 lstrcatW(dest, destname);
611 if (GetFileAttributesW(destdir) == INVALID_FILE_ATTRIBUTES)
613 ret = CreateDirectoryW(destdir, NULL);
616 WARN("CreateDirectory failed: %d\n", GetLastError());
622 msi_move_file(source, dest, options);
624 move_files_wildcard(source, dest, options);
627 uirow = MSI_CreateRecord( 9 );
628 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString(rec, 1) );
629 MSI_RecordSetInteger( uirow, 6, 1 ); /* FIXME */
630 MSI_RecordSetStringW( uirow, 9, destdir );
631 ui_actiondata( package, szMoveFiles, uirow );
632 msiobj_release( &uirow->hdr );
640 return ERROR_SUCCESS;
643 UINT ACTION_MoveFiles( MSIPACKAGE *package )
648 static const WCHAR ExecSeqQuery[] =
649 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
650 '`','M','o','v','e','F','i','l','e','`',0};
652 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
653 if (rc != ERROR_SUCCESS)
654 return ERROR_SUCCESS;
656 rc = MSI_IterateRecords(view, NULL, ITERATE_MoveFiles, package);
657 msiobj_release(&view->hdr);
662 static WCHAR *get_duplicate_filename( MSIPACKAGE *package, MSIRECORD *row, const WCHAR *file_key, const WCHAR *src )
665 WCHAR *dst_name, *dst_path, *dst;
667 if (MSI_RecordIsNull( row, 4 ))
669 len = strlenW( src ) + 1;
670 if (!(dst_name = msi_alloc( len * sizeof(WCHAR)))) return NULL;
671 strcpyW( dst_name, strrchrW( src, '\\' ) + 1 );
675 MSI_RecordGetStringW( row, 4, NULL, &len );
676 if (!(dst_name = msi_alloc( ++len * sizeof(WCHAR) ))) return NULL;
677 MSI_RecordGetStringW( row, 4, dst_name, &len );
678 reduce_to_longfilename( dst_name );
681 if (MSI_RecordIsNull( row, 5 ))
684 dst_path = strdupW( src );
685 p = strrchrW( dst_path, '\\' );
690 const WCHAR *dst_key = MSI_RecordGetString( row, 5 );
692 dst_path = resolve_folder( package, dst_key, FALSE, FALSE, TRUE, NULL );
696 dst_path = msi_dup_property( package->db, dst_key );
699 FIXME("Unable to get destination folder, try AppSearch properties\n");
700 msi_free( dst_name );
706 dst = build_directory_name( 2, dst_path, dst_name );
707 create_full_pathW( dst_path );
709 msi_free( dst_name );
710 msi_free( dst_path );
714 static UINT ITERATE_DuplicateFiles(MSIRECORD *row, LPVOID param)
716 MSIPACKAGE *package = param;
718 LPCWSTR file_key, component;
723 component = MSI_RecordGetString(row,2);
724 comp = get_loaded_component(package,component);
726 return ERROR_SUCCESS;
730 TRACE("component is disabled\n");
731 return ERROR_SUCCESS;
734 if (comp->ActionRequest != INSTALLSTATE_LOCAL)
736 TRACE("Component not scheduled for installation %s\n", debugstr_w(component));
737 comp->Action = comp->Installed;
738 return ERROR_SUCCESS;
740 comp->Action = INSTALLSTATE_LOCAL;
742 file_key = MSI_RecordGetString(row,3);
745 ERR("Unable to get file key\n");
746 return ERROR_FUNCTION_FAILED;
749 file = get_loaded_file( package, file_key );
752 ERR("Original file unknown %s\n", debugstr_w(file_key));
753 return ERROR_SUCCESS;
756 dest = get_duplicate_filename( package, row, file_key, file->TargetPath );
759 WARN("Unable to get duplicate filename\n");
760 return ERROR_SUCCESS;
763 TRACE("Duplicating file %s to %s\n", debugstr_w(file->TargetPath), debugstr_w(dest));
765 if (!CopyFileW( file->TargetPath, dest, TRUE ))
767 WARN("Failed to copy file %s -> %s (%u)\n",
768 debugstr_w(file->TargetPath), debugstr_w(dest), GetLastError());
771 FIXME("We should track these duplicate files as well\n");
773 uirow = MSI_CreateRecord( 9 );
774 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString( row, 1 ) );
775 MSI_RecordSetInteger( uirow, 6, file->FileSize );
776 MSI_RecordSetStringW( uirow, 9, MSI_RecordGetString( row, 5 ) );
777 ui_actiondata( package, szDuplicateFiles, uirow );
778 msiobj_release( &uirow->hdr );
781 return ERROR_SUCCESS;
784 UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
788 static const WCHAR ExecSeqQuery[] =
789 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
790 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
792 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
793 if (rc != ERROR_SUCCESS)
794 return ERROR_SUCCESS;
796 rc = MSI_IterateRecords(view, NULL, ITERATE_DuplicateFiles, package);
797 msiobj_release(&view->hdr);
802 static UINT ITERATE_RemoveDuplicateFiles( MSIRECORD *row, LPVOID param )
804 MSIPACKAGE *package = param;
806 LPCWSTR file_key, component;
811 component = MSI_RecordGetString( row, 2 );
812 comp = get_loaded_component( package, component );
814 return ERROR_SUCCESS;
818 TRACE("component is disabled\n");
819 return ERROR_SUCCESS;
822 if (comp->ActionRequest != INSTALLSTATE_ABSENT)
824 TRACE("Component not scheduled for removal %s\n", debugstr_w(component));
825 comp->Action = comp->Installed;
826 return ERROR_SUCCESS;
828 comp->Action = INSTALLSTATE_ABSENT;
830 file_key = MSI_RecordGetString( row, 3 );
833 ERR("Unable to get file key\n");
834 return ERROR_FUNCTION_FAILED;
837 file = get_loaded_file( package, file_key );
840 ERR("Original file unknown %s\n", debugstr_w(file_key));
841 return ERROR_SUCCESS;
844 dest = get_duplicate_filename( package, row, file_key, file->TargetPath );
847 WARN("Unable to get duplicate filename\n");
848 return ERROR_SUCCESS;
851 TRACE("Removing duplicate %s of %s\n", debugstr_w(dest), debugstr_w(file->TargetPath));
853 if (!DeleteFileW( dest ))
855 WARN("Failed to delete duplicate file %s (%u)\n", debugstr_w(dest), GetLastError());
858 uirow = MSI_CreateRecord( 9 );
859 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString( row, 1 ) );
860 MSI_RecordSetStringW( uirow, 9, MSI_RecordGetString( row, 5 ) );
861 ui_actiondata( package, szRemoveDuplicateFiles, uirow );
862 msiobj_release( &uirow->hdr );
865 return ERROR_SUCCESS;
868 UINT ACTION_RemoveDuplicateFiles( MSIPACKAGE *package )
872 static const WCHAR query[] =
873 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
874 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
876 rc = MSI_DatabaseOpenViewW( package->db, query, &view );
877 if (rc != ERROR_SUCCESS)
878 return ERROR_SUCCESS;
880 rc = MSI_IterateRecords( view, NULL, ITERATE_RemoveDuplicateFiles, package );
881 msiobj_release( &view->hdr );
886 static BOOL verify_comp_for_removal(MSICOMPONENT *comp, UINT install_mode)
888 INSTALLSTATE request = comp->ActionRequest;
890 if (request == INSTALLSTATE_UNKNOWN)
893 if (install_mode == msidbRemoveFileInstallModeOnInstall &&
894 (request == INSTALLSTATE_LOCAL || request == INSTALLSTATE_SOURCE))
897 if (request == INSTALLSTATE_ABSENT)
899 if (!comp->ComponentId)
902 if (install_mode == msidbRemoveFileInstallModeOnRemove)
906 if (install_mode == msidbRemoveFileInstallModeOnBoth)
912 static UINT ITERATE_RemoveFiles(MSIRECORD *row, LPVOID param)
914 MSIPACKAGE *package = param;
917 LPCWSTR component, filename, dirprop;
919 LPWSTR dir = NULL, path = NULL;
921 UINT ret = ERROR_SUCCESS;
923 component = MSI_RecordGetString(row, 2);
924 filename = MSI_RecordGetString(row, 3);
925 dirprop = MSI_RecordGetString(row, 4);
926 install_mode = MSI_RecordGetInteger(row, 5);
928 comp = get_loaded_component(package, component);
931 TRACE("component is disabled\n");
932 return ERROR_SUCCESS;
935 if (!verify_comp_for_removal(comp, install_mode))
937 TRACE("Skipping removal due to missing conditions\n");
938 comp->Action = comp->Installed;
939 return ERROR_SUCCESS;
942 if (comp->Attributes & msidbComponentAttributesPermanent)
944 TRACE("permanent component, not removing file\n");
945 return ERROR_SUCCESS;
948 dir = msi_dup_property(package->db, dirprop);
950 return ERROR_OUTOFMEMORY;
952 size = (filename != NULL) ? lstrlenW(filename) : 0;
953 size += lstrlenW(dir) + 2;
954 path = msi_alloc(size * sizeof(WCHAR));
957 ret = ERROR_OUTOFMEMORY;
964 PathAddBackslashW(path);
965 lstrcatW(path, filename);
967 TRACE("Deleting misc file: %s\n", debugstr_w(path));
972 TRACE("Removing misc directory: %s\n", debugstr_w(dir));
973 RemoveDirectoryW(dir);
977 uirow = MSI_CreateRecord( 9 );
978 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString(row, 1) );
979 MSI_RecordSetStringW( uirow, 9, dir );
980 ui_actiondata( package, szRemoveFiles, uirow );
981 msiobj_release( &uirow->hdr );
988 UINT ACTION_RemoveFiles( MSIPACKAGE *package )
994 static const WCHAR query[] = {
995 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
996 '`','R','e','m','o','v','e','F','i','l','e','`',0};
997 static const WCHAR folder_query[] = {
998 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
999 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0};
1001 r = MSI_DatabaseOpenViewW(package->db, query, &view);
1002 if (r == ERROR_SUCCESS)
1004 MSI_IterateRecords(view, NULL, ITERATE_RemoveFiles, package);
1005 msiobj_release(&view->hdr);
1008 r = MSI_DatabaseOpenViewW(package->db, folder_query, &view);
1009 if (r == ERROR_SUCCESS)
1010 msiobj_release(&view->hdr);
1012 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
1016 VS_FIXEDFILEINFO *ver;
1018 if ( file->state == msifs_installed )
1019 ERR("removing installed file %s\n", debugstr_w(file->TargetPath));
1021 if ( file->Component->ActionRequest != INSTALLSTATE_ABSENT ||
1022 file->Component->Installed == INSTALLSTATE_SOURCE )
1025 if (!file->Component->Enabled)
1027 TRACE("component is disabled\n");
1031 if (file->Component->Attributes & msidbComponentAttributesPermanent)
1033 TRACE("permanent component, not removing file\n");
1039 ver = msi_get_disk_file_version( file->TargetPath );
1040 if (ver && msi_compare_file_versions( ver, file->Version ) > 0)
1042 TRACE("newer version detected, not removing file\n");
1049 TRACE("removing %s\n", debugstr_w(file->File) );
1050 if (!DeleteFileW( file->TargetPath ))
1052 WARN("failed to delete %s\n", debugstr_w(file->TargetPath));
1054 /* FIXME: check persistence for each directory */
1055 else if (r && (dir = strdupW( file->TargetPath )))
1057 if ((p = strrchrW( dir, '\\' ))) *p = 0;
1058 RemoveDirectoryW( dir );
1061 file->state = msifs_missing;
1063 uirow = MSI_CreateRecord( 9 );
1064 MSI_RecordSetStringW( uirow, 1, file->FileName );
1065 MSI_RecordSetStringW( uirow, 9, file->Component->Directory );
1066 ui_actiondata( package, szRemoveFiles, uirow );
1067 msiobj_release( &uirow->hdr );
1068 /* FIXME: call ui_progress here? */
1071 return ERROR_SUCCESS;