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
|| f
->Component
->assembly
->application
)
191 msi_create_directory(package
, f
->Component
->Directory
);
193 *path
= strdupW(f
->TargetPath
);
194 *attrs
= f
->Attributes
;
196 else if (action
== MSICABEXTRACT_FILEEXTRACTED
)
198 f
->state
= msifs_installed
;
206 * ACTION_InstallFiles()
208 * For efficiency, this is done in two passes:
209 * 1) Correct all the TargetPaths and determine what files are to be installed.
210 * 2) Extract Cabinets and copy files.
212 UINT
ACTION_InstallFiles(MSIPACKAGE
*package
)
216 UINT rc
= ERROR_SUCCESS
;
219 /* increment progress bar each time action data is sent */
220 ui_progress(package
,1,1,0,0);
222 schedule_install_files(package
);
224 mi
= msi_alloc_zero( sizeof(MSIMEDIAINFO
) );
226 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
228 if (file
->state
!= msifs_missing
&& !mi
->is_continuous
&& file
->state
!= msifs_overwrite
)
231 if (file
->state
== msifs_overwrite
&&
232 (file
->Component
->Attributes
& msidbComponentAttributesNeverOverwrite
))
234 TRACE("not overwriting %s\n", debugstr_w(file
->TargetPath
));
235 file
->state
= msifs_skipped
;
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
->Enabled
&& comp
->assembly
&& !comp
->assembly
->installed
)
298 rc
= install_assembly( package
, comp
);
299 if (rc
!= ERROR_SUCCESS
)
301 ERR("Failed to install assembly\n");
302 rc
= ERROR_INSTALL_FAILURE
;
309 msi_free_media_info(mi
);
313 #define is_dot_dir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
324 static BOOL
msi_move_file(LPCWSTR source
, LPCWSTR dest
, int options
)
328 if (GetFileAttributesW(source
) == FILE_ATTRIBUTE_DIRECTORY
||
329 GetFileAttributesW(dest
) == FILE_ATTRIBUTE_DIRECTORY
)
331 WARN("Source or dest is directory, not moving\n");
335 if (options
== msidbMoveFileOptionsMove
)
337 TRACE("moving %s -> %s\n", debugstr_w(source
), debugstr_w(dest
));
338 ret
= MoveFileExW(source
, dest
, MOVEFILE_REPLACE_EXISTING
);
341 WARN("MoveFile failed: %d\n", GetLastError());
347 TRACE("copying %s -> %s\n", debugstr_w(source
), debugstr_w(dest
));
348 ret
= CopyFileW(source
, dest
, FALSE
);
351 WARN("CopyFile failed: %d\n", GetLastError());
359 static LPWSTR
wildcard_to_file(LPWSTR wildcard
, LPWSTR filename
)
362 DWORD dirlen
, pathlen
;
364 ptr
= strrchrW(wildcard
, '\\');
365 dirlen
= ptr
- wildcard
+ 1;
367 pathlen
= dirlen
+ lstrlenW(filename
) + 1;
368 path
= msi_alloc(pathlen
* sizeof(WCHAR
));
370 lstrcpynW(path
, wildcard
, dirlen
+ 1);
371 lstrcatW(path
, filename
);
376 static void free_file_entry(FILE_LIST
*file
)
378 msi_free(file
->source
);
379 msi_free(file
->dest
);
383 static void free_list(FILE_LIST
*list
)
385 while (!list_empty(&list
->entry
))
387 FILE_LIST
*file
= LIST_ENTRY(list_head(&list
->entry
), FILE_LIST
, entry
);
389 list_remove(&file
->entry
);
390 free_file_entry(file
);
394 static BOOL
add_wildcard(FILE_LIST
*files
, LPWSTR source
, LPWSTR dest
)
396 FILE_LIST
*new, *file
;
397 LPWSTR ptr
, filename
;
400 new = msi_alloc_zero(sizeof(FILE_LIST
));
404 new->source
= strdupW(source
);
405 ptr
= strrchrW(dest
, '\\') + 1;
406 filename
= strrchrW(new->source
, '\\') + 1;
408 new->sourcename
= filename
;
413 new->destname
= new->sourcename
;
415 size
= (ptr
- dest
) + lstrlenW(filename
) + 1;
416 new->dest
= msi_alloc(size
* sizeof(WCHAR
));
419 free_file_entry(new);
423 lstrcpynW(new->dest
, dest
, ptr
- dest
+ 1);
424 lstrcatW(new->dest
, filename
);
426 if (list_empty(&files
->entry
))
428 list_add_head(&files
->entry
, &new->entry
);
432 LIST_FOR_EACH_ENTRY(file
, &files
->entry
, FILE_LIST
, entry
)
434 if (strcmpW( source
, file
->source
) < 0)
436 list_add_before(&file
->entry
, &new->entry
);
441 list_add_after(&file
->entry
, &new->entry
);
445 static BOOL
move_files_wildcard(LPWSTR source
, LPWSTR dest
, int options
)
447 WIN32_FIND_DATAW wfd
;
451 FILE_LIST files
, *file
;
454 hfile
= FindFirstFileW(source
, &wfd
);
455 if (hfile
== INVALID_HANDLE_VALUE
) return FALSE
;
457 list_init(&files
.entry
);
459 for (res
= TRUE
; res
; res
= FindNextFileW(hfile
, &wfd
))
461 if (is_dot_dir(wfd
.cFileName
)) continue;
463 path
= wildcard_to_file(source
, wfd
.cFileName
);
470 add_wildcard(&files
, path
, dest
);
474 /* no files match the wildcard */
475 if (list_empty(&files
.entry
))
478 /* only the first wildcard match gets renamed to dest */
479 file
= LIST_ENTRY(list_head(&files
.entry
), FILE_LIST
, entry
);
480 size
= (strrchrW(file
->dest
, '\\') - file
->dest
) + lstrlenW(file
->destname
) + 2;
481 file
->dest
= msi_realloc(file
->dest
, size
* sizeof(WCHAR
));
488 /* file->dest may be shorter after the reallocation, so add a NULL
489 * terminator. This is needed for the call to strrchrW, as there will no
490 * longer be a NULL terminator within the bounds of the allocation in this case.
492 file
->dest
[size
- 1] = '\0';
493 lstrcpyW(strrchrW(file
->dest
, '\\') + 1, file
->destname
);
495 while (!list_empty(&files
.entry
))
497 file
= LIST_ENTRY(list_head(&files
.entry
), FILE_LIST
, entry
);
499 msi_move_file(file
->source
, file
->dest
, options
);
501 list_remove(&file
->entry
);
502 free_file_entry(file
);
513 static UINT
ITERATE_MoveFiles( MSIRECORD
*rec
, LPVOID param
)
515 MSIPACKAGE
*package
= param
;
518 LPCWSTR sourcename
, component
;
519 LPWSTR sourcedir
, destname
= NULL
, destdir
= NULL
, source
= NULL
, dest
= NULL
;
524 component
= MSI_RecordGetString(rec
, 2);
525 comp
= get_loaded_component(package
, component
);
527 return ERROR_SUCCESS
;
531 TRACE("component is disabled\n");
532 return ERROR_SUCCESS
;
535 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
&& comp
->ActionRequest
!= INSTALLSTATE_SOURCE
)
537 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
538 comp
->Action
= comp
->Installed
;
539 return ERROR_SUCCESS
;
541 comp
->Action
= comp
->ActionRequest
;
543 sourcename
= MSI_RecordGetString(rec
, 3);
544 options
= MSI_RecordGetInteger(rec
, 7);
546 sourcedir
= msi_dup_property(package
->db
, MSI_RecordGetString(rec
, 5));
550 destdir
= msi_dup_property(package
->db
, MSI_RecordGetString(rec
, 6));
556 if (GetFileAttributesW(sourcedir
) == INVALID_FILE_ATTRIBUTES
)
559 source
= strdupW(sourcedir
);
565 size
= lstrlenW(sourcedir
) + lstrlenW(sourcename
) + 2;
566 source
= msi_alloc(size
* sizeof(WCHAR
));
570 lstrcpyW(source
, sourcedir
);
571 if (source
[lstrlenW(source
) - 1] != '\\')
572 lstrcatW(source
, szBackSlash
);
573 lstrcatW(source
, sourcename
);
576 wildcards
= strchrW(source
, '*') || strchrW(source
, '?');
578 if (MSI_RecordIsNull(rec
, 4))
582 destname
= strdupW(sourcename
);
589 destname
= strdupW(MSI_RecordGetString(rec
, 4));
591 reduce_to_longfilename(destname
);
596 size
= lstrlenW(destname
);
598 size
+= lstrlenW(destdir
) + 2;
599 dest
= msi_alloc(size
* sizeof(WCHAR
));
603 lstrcpyW(dest
, destdir
);
604 if (dest
[lstrlenW(dest
) - 1] != '\\')
605 lstrcatW(dest
, szBackSlash
);
608 lstrcatW(dest
, destname
);
610 if (GetFileAttributesW(destdir
) == INVALID_FILE_ATTRIBUTES
)
612 ret
= CreateDirectoryW(destdir
, NULL
);
615 WARN("CreateDirectory failed: %d\n", GetLastError());
621 msi_move_file(source
, dest
, options
);
623 move_files_wildcard(source
, dest
, options
);
626 uirow
= MSI_CreateRecord( 9 );
627 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString(rec
, 1) );
628 MSI_RecordSetInteger( uirow
, 6, 1 ); /* FIXME */
629 MSI_RecordSetStringW( uirow
, 9, destdir
);
630 ui_actiondata( package
, szMoveFiles
, uirow
);
631 msiobj_release( &uirow
->hdr
);
639 return ERROR_SUCCESS
;
642 UINT
ACTION_MoveFiles( MSIPACKAGE
*package
)
647 static const WCHAR ExecSeqQuery
[] =
648 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
649 '`','M','o','v','e','F','i','l','e','`',0};
651 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
652 if (rc
!= ERROR_SUCCESS
)
653 return ERROR_SUCCESS
;
655 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_MoveFiles
, package
);
656 msiobj_release(&view
->hdr
);
661 static WCHAR
*get_duplicate_filename( MSIPACKAGE
*package
, MSIRECORD
*row
, const WCHAR
*file_key
, const WCHAR
*src
)
664 WCHAR
*dst_name
, *dst_path
, *dst
;
666 if (MSI_RecordIsNull( row
, 4 ))
668 len
= strlenW( src
) + 1;
669 if (!(dst_name
= msi_alloc( len
* sizeof(WCHAR
)))) return NULL
;
670 strcpyW( dst_name
, strrchrW( src
, '\\' ) + 1 );
674 MSI_RecordGetStringW( row
, 4, NULL
, &len
);
675 if (!(dst_name
= msi_alloc( ++len
* sizeof(WCHAR
) ))) return NULL
;
676 MSI_RecordGetStringW( row
, 4, dst_name
, &len
);
677 reduce_to_longfilename( dst_name
);
680 if (MSI_RecordIsNull( row
, 5 ))
683 dst_path
= strdupW( src
);
684 p
= strrchrW( dst_path
, '\\' );
689 const WCHAR
*dst_key
= MSI_RecordGetString( row
, 5 );
691 dst_path
= resolve_folder( package
, dst_key
, FALSE
, FALSE
, TRUE
, NULL
);
695 dst_path
= msi_dup_property( package
->db
, dst_key
);
698 FIXME("Unable to get destination folder, try AppSearch properties\n");
699 msi_free( dst_name
);
705 dst
= build_directory_name( 2, dst_path
, dst_name
);
706 create_full_pathW( dst_path
);
708 msi_free( dst_name
);
709 msi_free( dst_path
);
713 static UINT
ITERATE_DuplicateFiles(MSIRECORD
*row
, LPVOID param
)
715 MSIPACKAGE
*package
= param
;
717 LPCWSTR file_key
, component
;
722 component
= MSI_RecordGetString(row
,2);
723 comp
= get_loaded_component(package
,component
);
725 return ERROR_SUCCESS
;
729 TRACE("component is disabled\n");
730 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
;
817 TRACE("component is disabled\n");
818 return ERROR_SUCCESS
;
821 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
823 TRACE("Component not scheduled for removal %s\n", debugstr_w(component
));
824 comp
->Action
= comp
->Installed
;
825 return ERROR_SUCCESS
;
827 comp
->Action
= INSTALLSTATE_ABSENT
;
829 file_key
= MSI_RecordGetString( row
, 3 );
832 ERR("Unable to get file key\n");
833 return ERROR_FUNCTION_FAILED
;
836 file
= get_loaded_file( package
, file_key
);
839 ERR("Original file unknown %s\n", debugstr_w(file_key
));
840 return ERROR_SUCCESS
;
843 dest
= get_duplicate_filename( package
, row
, file_key
, file
->TargetPath
);
846 WARN("Unable to get duplicate filename\n");
847 return ERROR_SUCCESS
;
850 TRACE("Removing duplicate %s of %s\n", debugstr_w(dest
), debugstr_w(file
->TargetPath
));
852 if (!DeleteFileW( dest
))
854 WARN("Failed to delete duplicate file %s (%u)\n", debugstr_w(dest
), GetLastError());
857 uirow
= MSI_CreateRecord( 9 );
858 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString( row
, 1 ) );
859 MSI_RecordSetStringW( uirow
, 9, MSI_RecordGetString( row
, 5 ) );
860 ui_actiondata( package
, szRemoveDuplicateFiles
, uirow
);
861 msiobj_release( &uirow
->hdr
);
864 return ERROR_SUCCESS
;
867 UINT
ACTION_RemoveDuplicateFiles( MSIPACKAGE
*package
)
871 static const WCHAR query
[] =
872 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
873 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
875 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
876 if (rc
!= ERROR_SUCCESS
)
877 return ERROR_SUCCESS
;
879 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveDuplicateFiles
, package
);
880 msiobj_release( &view
->hdr
);
885 static BOOL
verify_comp_for_removal(MSICOMPONENT
*comp
, UINT install_mode
)
887 INSTALLSTATE request
= comp
->ActionRequest
;
889 if (request
== INSTALLSTATE_UNKNOWN
)
892 if (install_mode
== msidbRemoveFileInstallModeOnInstall
&&
893 (request
== INSTALLSTATE_LOCAL
|| request
== INSTALLSTATE_SOURCE
))
896 if (request
== INSTALLSTATE_ABSENT
)
898 if (!comp
->ComponentId
)
901 if (install_mode
== msidbRemoveFileInstallModeOnRemove
)
905 if (install_mode
== msidbRemoveFileInstallModeOnBoth
)
911 static UINT
ITERATE_RemoveFiles(MSIRECORD
*row
, LPVOID param
)
913 MSIPACKAGE
*package
= param
;
916 LPCWSTR component
, filename
, dirprop
;
918 LPWSTR dir
= NULL
, path
= NULL
;
920 UINT ret
= ERROR_SUCCESS
;
922 component
= MSI_RecordGetString(row
, 2);
923 filename
= MSI_RecordGetString(row
, 3);
924 dirprop
= MSI_RecordGetString(row
, 4);
925 install_mode
= MSI_RecordGetInteger(row
, 5);
927 comp
= get_loaded_component(package
, component
);
930 ERR("Invalid component: %s\n", debugstr_w(component
));
931 return ERROR_FUNCTION_FAILED
;
936 TRACE("component is disabled\n");
937 return ERROR_SUCCESS
;
940 if (!verify_comp_for_removal(comp
, install_mode
))
942 TRACE("Skipping removal due to missing conditions\n");
943 comp
->Action
= comp
->Installed
;
944 return ERROR_SUCCESS
;
947 dir
= msi_dup_property(package
->db
, dirprop
);
949 return ERROR_OUTOFMEMORY
;
951 size
= (filename
!= NULL
) ? lstrlenW(filename
) : 0;
952 size
+= lstrlenW(dir
) + 2;
953 path
= msi_alloc(size
* sizeof(WCHAR
));
956 ret
= ERROR_OUTOFMEMORY
;
963 PathAddBackslashW(path
);
964 lstrcatW(path
, filename
);
966 TRACE("Deleting misc file: %s\n", debugstr_w(path
));
971 TRACE("Removing misc directory: %s\n", debugstr_w(dir
));
972 RemoveDirectoryW(dir
);
976 uirow
= MSI_CreateRecord( 9 );
977 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString(row
, 1) );
978 MSI_RecordSetStringW( uirow
, 9, dir
);
979 ui_actiondata( package
, szRemoveFiles
, uirow
);
980 msiobj_release( &uirow
->hdr
);
987 UINT
ACTION_RemoveFiles( MSIPACKAGE
*package
)
993 static const WCHAR query
[] = {
994 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
995 '`','R','e','m','o','v','e','F','i','l','e','`',0};
996 static const WCHAR folder_query
[] = {
997 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
998 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0};
1000 r
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
1001 if (r
== ERROR_SUCCESS
)
1003 MSI_IterateRecords(view
, NULL
, ITERATE_RemoveFiles
, package
);
1004 msiobj_release(&view
->hdr
);
1007 r
= MSI_DatabaseOpenViewW(package
->db
, folder_query
, &view
);
1008 if (r
== ERROR_SUCCESS
)
1009 msiobj_release(&view
->hdr
);
1011 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
1015 VS_FIXEDFILEINFO
*ver
;
1017 if ( file
->state
== msifs_installed
)
1018 ERR("removing installed file %s\n", debugstr_w(file
->TargetPath
));
1020 if ( file
->Component
->ActionRequest
!= INSTALLSTATE_ABSENT
||
1021 file
->Component
->Installed
== INSTALLSTATE_SOURCE
)
1024 if (!file
->Component
->Enabled
)
1026 TRACE("component is disabled\n");
1032 ver
= msi_get_disk_file_version( file
->TargetPath
);
1033 if (ver
&& msi_compare_file_versions( ver
, file
->Version
) > 0)
1035 TRACE("newer version detected, not removing file\n");
1042 TRACE("removing %s\n", debugstr_w(file
->File
) );
1043 if (!DeleteFileW( file
->TargetPath
))
1045 WARN("failed to delete %s\n", debugstr_w(file
->TargetPath
));
1047 /* FIXME: check persistence for each directory */
1048 else if (r
&& (dir
= strdupW( file
->TargetPath
)))
1050 if ((p
= strrchrW( dir
, '\\' ))) *p
= 0;
1051 RemoveDirectoryW( dir
);
1054 file
->state
= msifs_missing
;
1056 uirow
= MSI_CreateRecord( 9 );
1057 MSI_RecordSetStringW( uirow
, 1, file
->FileName
);
1058 MSI_RecordSetStringW( uirow
, 9, file
->Component
->Directory
);
1059 ui_actiondata( package
, szRemoveFiles
, uirow
);
1060 msiobj_release( &uirow
->hdr
);
1061 /* FIXME: call ui_progress here? */
1064 return ERROR_SUCCESS
;