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
), debugstr_w(file
->TargetPath
));
126 gle
= copy_file(file
, source
);
127 if (gle
== ERROR_SUCCESS
)
130 if (gle
== ERROR_ALREADY_EXISTS
&& file
->state
== msifs_overwrite
)
132 TRACE("overwriting existing file\n");
133 return ERROR_SUCCESS
;
135 else if (gle
== ERROR_ACCESS_DENIED
)
137 SetFileAttributesW(file
->TargetPath
, FILE_ATTRIBUTE_NORMAL
);
139 gle
= copy_file(file
, source
);
140 TRACE("Overwriting existing file: %d\n", gle
);
142 if (gle
== ERROR_SHARING_VIOLATION
|| gle
== ERROR_USER_MAPPED_FILE
)
144 WCHAR tmpfileW
[MAX_PATH
], *pathW
, *p
;
147 TRACE("file in use, scheduling rename operation\n");
149 GetTempFileNameW(szBackSlash
, szMsi
, 0, tmpfileW
);
150 len
= strlenW(file
->TargetPath
) + strlenW(tmpfileW
) + 1;
151 if (!(pathW
= msi_alloc(len
* sizeof(WCHAR
))))
152 return ERROR_OUTOFMEMORY
;
154 strcpyW(pathW
, file
->TargetPath
);
155 if ((p
= strrchrW(pathW
, '\\'))) *p
= 0;
156 strcatW(pathW
, tmpfileW
);
158 if (CopyFileW(source
, pathW
, FALSE
) &&
159 MoveFileExW(file
->TargetPath
, NULL
, MOVEFILE_DELAY_UNTIL_REBOOT
) &&
160 MoveFileExW(pathW
, file
->TargetPath
, MOVEFILE_DELAY_UNTIL_REBOOT
))
162 file
->state
= msifs_installed
;
163 package
->need_reboot
= 1;
168 gle
= GetLastError();
169 WARN("failed to schedule rename operation: %d)\n", gle
);
177 static BOOL
installfiles_cb(MSIPACKAGE
*package
, LPCWSTR file
, DWORD action
,
178 LPWSTR
*path
, DWORD
*attrs
, PVOID user
)
180 static MSIFILE
*f
= NULL
;
181 MSIMEDIAINFO
*mi
= user
;
183 if (action
== MSICABEXTRACT_BEGINEXTRACT
)
185 f
= get_loaded_file(package
, file
);
188 WARN("unknown file in cabinet (%s)\n", debugstr_w(file
));
192 if (f
->disk_id
!= mi
->disk_id
|| (f
->state
!= msifs_missing
&& f
->state
!= msifs_overwrite
))
195 msi_file_update_ui(package
, f
, szInstallFiles
);
197 *path
= strdupW(f
->TargetPath
);
198 *attrs
= f
->Attributes
;
200 else if (action
== MSICABEXTRACT_FILEEXTRACTED
)
202 f
->state
= msifs_installed
;
210 * ACTION_InstallFiles()
212 * For efficiency, this is done in two passes:
213 * 1) Correct all the TargetPaths and determine what files are to be installed.
214 * 2) Extract Cabinets and copy files.
216 UINT
ACTION_InstallFiles(MSIPACKAGE
*package
)
219 UINT rc
= ERROR_SUCCESS
;
222 /* increment progress bar each time action data is sent */
223 ui_progress(package
,1,1,0,0);
225 schedule_install_files(package
);
228 * Despite MSDN specifying that the CreateFolders action
229 * should be called before InstallFiles, some installers don't
230 * do that, and they seem to work correctly. We need to create
231 * directories here to make sure that the files can be copied.
233 msi_create_component_directories( package
);
235 mi
= msi_alloc_zero( sizeof(MSIMEDIAINFO
) );
237 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
239 if (file
->state
!= msifs_missing
&& !mi
->is_continuous
&& file
->state
!= msifs_overwrite
)
242 if (file
->Sequence
> mi
->last_sequence
|| mi
->is_continuous
||
243 (file
->IsCompressed
&& !mi
->is_extracted
))
247 rc
= ready_media(package
, file
, mi
);
248 if (rc
!= ERROR_SUCCESS
)
250 ERR("Failed to ready media for %s\n", debugstr_w(file
->File
));
255 data
.package
= package
;
256 data
.cb
= installfiles_cb
;
259 if (file
->IsCompressed
&&
260 !msi_cabextract(package
, mi
, &data
))
262 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi
->cabinet
));
263 rc
= ERROR_INSTALL_FAILURE
;
268 if (!file
->IsCompressed
)
270 LPWSTR source
= resolve_file_source(package
, file
);
272 TRACE("file paths %s to %s\n", debugstr_w(source
),
273 debugstr_w(file
->TargetPath
));
275 msi_file_update_ui(package
, file
, szInstallFiles
);
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
;
288 else if (file
->state
!= msifs_installed
)
290 ERR("compressed file wasn't installed (%s)\n", debugstr_w(file
->TargetPath
));
291 rc
= ERROR_INSTALL_FAILURE
;
296 msi_free_media_info(mi
);
300 #define is_dot_dir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
311 static BOOL
msi_move_file(LPCWSTR source
, LPCWSTR dest
, int options
)
315 if (GetFileAttributesW(source
) == FILE_ATTRIBUTE_DIRECTORY
||
316 GetFileAttributesW(dest
) == FILE_ATTRIBUTE_DIRECTORY
)
318 WARN("Source or dest is directory, not moving\n");
322 if (options
== msidbMoveFileOptionsMove
)
324 TRACE("moving %s -> %s\n", debugstr_w(source
), debugstr_w(dest
));
325 ret
= MoveFileExW(source
, dest
, MOVEFILE_REPLACE_EXISTING
);
328 WARN("MoveFile failed: %d\n", GetLastError());
334 TRACE("copying %s -> %s\n", debugstr_w(source
), debugstr_w(dest
));
335 ret
= CopyFileW(source
, dest
, FALSE
);
338 WARN("CopyFile failed: %d\n", GetLastError());
346 static LPWSTR
wildcard_to_file(LPWSTR wildcard
, LPWSTR filename
)
349 DWORD dirlen
, pathlen
;
351 ptr
= strrchrW(wildcard
, '\\');
352 dirlen
= ptr
- wildcard
+ 1;
354 pathlen
= dirlen
+ lstrlenW(filename
) + 1;
355 path
= msi_alloc(pathlen
* sizeof(WCHAR
));
357 lstrcpynW(path
, wildcard
, dirlen
+ 1);
358 lstrcatW(path
, filename
);
363 static void free_file_entry(FILE_LIST
*file
)
365 msi_free(file
->source
);
366 msi_free(file
->dest
);
370 static void free_list(FILE_LIST
*list
)
372 while (!list_empty(&list
->entry
))
374 FILE_LIST
*file
= LIST_ENTRY(list_head(&list
->entry
), FILE_LIST
, entry
);
376 list_remove(&file
->entry
);
377 free_file_entry(file
);
381 static BOOL
add_wildcard(FILE_LIST
*files
, LPWSTR source
, LPWSTR dest
)
383 FILE_LIST
*new, *file
;
384 LPWSTR ptr
, filename
;
387 new = msi_alloc_zero(sizeof(FILE_LIST
));
391 new->source
= strdupW(source
);
392 ptr
= strrchrW(dest
, '\\') + 1;
393 filename
= strrchrW(new->source
, '\\') + 1;
395 new->sourcename
= filename
;
400 new->destname
= new->sourcename
;
402 size
= (ptr
- dest
) + lstrlenW(filename
) + 1;
403 new->dest
= msi_alloc(size
* sizeof(WCHAR
));
406 free_file_entry(new);
410 lstrcpynW(new->dest
, dest
, ptr
- dest
+ 1);
411 lstrcatW(new->dest
, filename
);
413 if (list_empty(&files
->entry
))
415 list_add_head(&files
->entry
, &new->entry
);
419 LIST_FOR_EACH_ENTRY(file
, &files
->entry
, FILE_LIST
, entry
)
421 if (lstrcmpW(source
, file
->source
) < 0)
423 list_add_before(&file
->entry
, &new->entry
);
428 list_add_after(&file
->entry
, &new->entry
);
432 static BOOL
move_files_wildcard(LPWSTR source
, LPWSTR dest
, int options
)
434 WIN32_FIND_DATAW wfd
;
438 FILE_LIST files
, *file
;
441 hfile
= FindFirstFileW(source
, &wfd
);
442 if (hfile
== INVALID_HANDLE_VALUE
) return FALSE
;
444 list_init(&files
.entry
);
446 for (res
= TRUE
; res
; res
= FindNextFileW(hfile
, &wfd
))
448 if (is_dot_dir(wfd
.cFileName
)) continue;
450 path
= wildcard_to_file(source
, wfd
.cFileName
);
457 add_wildcard(&files
, path
, dest
);
461 /* no files match the wildcard */
462 if (list_empty(&files
.entry
))
465 /* only the first wildcard match gets renamed to dest */
466 file
= LIST_ENTRY(list_head(&files
.entry
), FILE_LIST
, entry
);
467 size
= (strrchrW(file
->dest
, '\\') - file
->dest
) + lstrlenW(file
->destname
) + 2;
468 file
->dest
= msi_realloc(file
->dest
, size
* sizeof(WCHAR
));
475 /* file->dest may be shorter after the reallocation, so add a NULL
476 * terminator. This is needed for the call to strrchrW, as there will no
477 * longer be a NULL terminator within the bounds of the allocation in this case.
479 file
->dest
[size
- 1] = '\0';
480 lstrcpyW(strrchrW(file
->dest
, '\\') + 1, file
->destname
);
482 while (!list_empty(&files
.entry
))
484 file
= LIST_ENTRY(list_head(&files
.entry
), FILE_LIST
, entry
);
486 msi_move_file(file
->source
, file
->dest
, options
);
488 list_remove(&file
->entry
);
489 free_file_entry(file
);
500 static UINT
ITERATE_MoveFiles( MSIRECORD
*rec
, LPVOID param
)
502 MSIPACKAGE
*package
= param
;
505 LPCWSTR sourcename
, component
;
506 LPWSTR sourcedir
, destname
= NULL
, destdir
= NULL
, source
= NULL
, dest
= NULL
;
511 component
= MSI_RecordGetString(rec
, 2);
512 comp
= get_loaded_component(package
, component
);
514 return ERROR_SUCCESS
;
516 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
&& comp
->ActionRequest
!= INSTALLSTATE_SOURCE
)
518 TRACE("Component not scheduled for installation: %s\n", debugstr_w(component
));
519 comp
->Action
= comp
->Installed
;
520 return ERROR_SUCCESS
;
522 comp
->Action
= comp
->ActionRequest
;
524 sourcename
= MSI_RecordGetString(rec
, 3);
525 options
= MSI_RecordGetInteger(rec
, 7);
527 sourcedir
= msi_dup_property(package
->db
, MSI_RecordGetString(rec
, 5));
531 destdir
= msi_dup_property(package
->db
, MSI_RecordGetString(rec
, 6));
537 if (GetFileAttributesW(sourcedir
) == INVALID_FILE_ATTRIBUTES
)
540 source
= strdupW(sourcedir
);
546 size
= lstrlenW(sourcedir
) + lstrlenW(sourcename
) + 2;
547 source
= msi_alloc(size
* sizeof(WCHAR
));
551 lstrcpyW(source
, sourcedir
);
552 if (source
[lstrlenW(source
) - 1] != '\\')
553 lstrcatW(source
, szBackSlash
);
554 lstrcatW(source
, sourcename
);
557 wildcards
= strchrW(source
, '*') || strchrW(source
, '?');
559 if (MSI_RecordIsNull(rec
, 4))
563 destname
= strdupW(sourcename
);
570 destname
= strdupW(MSI_RecordGetString(rec
, 4));
572 reduce_to_longfilename(destname
);
577 size
= lstrlenW(destname
);
579 size
+= lstrlenW(destdir
) + 2;
580 dest
= msi_alloc(size
* sizeof(WCHAR
));
584 lstrcpyW(dest
, destdir
);
585 if (dest
[lstrlenW(dest
) - 1] != '\\')
586 lstrcatW(dest
, szBackSlash
);
589 lstrcatW(dest
, destname
);
591 if (GetFileAttributesW(destdir
) == INVALID_FILE_ATTRIBUTES
)
593 ret
= CreateDirectoryW(destdir
, NULL
);
596 WARN("CreateDirectory failed: %d\n", GetLastError());
602 msi_move_file(source
, dest
, options
);
604 move_files_wildcard(source
, dest
, options
);
607 uirow
= MSI_CreateRecord( 9 );
608 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString(rec
, 1) );
609 MSI_RecordSetInteger( uirow
, 6, 1 ); /* FIXME */
610 MSI_RecordSetStringW( uirow
, 9, destdir
);
611 ui_actiondata( package
, szMoveFiles
, uirow
);
612 msiobj_release( &uirow
->hdr
);
620 return ERROR_SUCCESS
;
623 UINT
ACTION_MoveFiles( MSIPACKAGE
*package
)
628 static const WCHAR ExecSeqQuery
[] =
629 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
630 '`','M','o','v','e','F','i','l','e','`',0};
632 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
633 if (rc
!= ERROR_SUCCESS
)
634 return ERROR_SUCCESS
;
636 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_MoveFiles
, package
);
637 msiobj_release(&view
->hdr
);
642 static WCHAR
*get_duplicate_filename( MSIPACKAGE
*package
, MSIRECORD
*row
, const WCHAR
*file_key
, const WCHAR
*src
)
645 WCHAR
*dst_name
, *dst_path
, *dst
;
647 if (MSI_RecordIsNull( row
, 4 ))
649 len
= strlenW( src
) + 1;
650 if (!(dst_name
= msi_alloc( len
* sizeof(WCHAR
)))) return NULL
;
651 strcpyW( dst_name
, strrchrW( src
, '\\' ) + 1 );
655 MSI_RecordGetStringW( row
, 4, NULL
, &len
);
656 if (!(dst_name
= msi_alloc( ++len
* sizeof(WCHAR
) ))) return NULL
;
657 MSI_RecordGetStringW( row
, 4, dst_name
, &len
);
658 reduce_to_longfilename( dst_name
);
661 if (MSI_RecordIsNull( row
, 5 ))
664 dst_path
= strdupW( src
);
665 p
= strrchrW( dst_path
, '\\' );
670 const WCHAR
*dst_key
= MSI_RecordGetString( row
, 5 );
672 dst_path
= resolve_folder( package
, dst_key
, FALSE
, FALSE
, TRUE
, NULL
);
676 dst_path
= msi_dup_property( package
->db
, dst_key
);
679 FIXME("Unable to get destination folder, try AppSearch properties\n");
680 msi_free( dst_name
);
686 dst
= build_directory_name( 2, dst_path
, dst_name
);
687 create_full_pathW( dst_path
);
689 msi_free( dst_name
);
690 msi_free( dst_path
);
694 static UINT
ITERATE_DuplicateFiles(MSIRECORD
*row
, LPVOID param
)
696 MSIPACKAGE
*package
= param
;
698 LPCWSTR file_key
, component
;
703 component
= MSI_RecordGetString(row
,2);
704 comp
= get_loaded_component(package
,component
);
706 return ERROR_SUCCESS
;
708 if (comp
->ActionRequest
!= INSTALLSTATE_LOCAL
)
710 TRACE("Component not scheduled for installation %s\n", debugstr_w(component
));
711 comp
->Action
= comp
->Installed
;
712 return ERROR_SUCCESS
;
714 comp
->Action
= INSTALLSTATE_LOCAL
;
716 file_key
= MSI_RecordGetString(row
,3);
719 ERR("Unable to get file key\n");
720 return ERROR_FUNCTION_FAILED
;
723 file
= get_loaded_file( package
, file_key
);
726 ERR("Original file unknown %s\n", debugstr_w(file_key
));
727 return ERROR_SUCCESS
;
730 dest
= get_duplicate_filename( package
, row
, file_key
, file
->TargetPath
);
733 WARN("Unable to get duplicate filename\n");
734 return ERROR_SUCCESS
;
737 TRACE("Duplicating file %s to %s\n", debugstr_w(file
->TargetPath
), debugstr_w(dest
));
739 if (!CopyFileW( file
->TargetPath
, dest
, TRUE
))
741 WARN("Failed to copy file %s -> %s (%u)\n",
742 debugstr_w(file
->TargetPath
), debugstr_w(dest
), GetLastError());
745 FIXME("We should track these duplicate files as well\n");
747 uirow
= MSI_CreateRecord( 9 );
748 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString( row
, 1 ) );
749 MSI_RecordSetInteger( uirow
, 6, file
->FileSize
);
750 MSI_RecordSetStringW( uirow
, 9, MSI_RecordGetString( row
, 5 ) );
751 ui_actiondata( package
, szDuplicateFiles
, uirow
);
752 msiobj_release( &uirow
->hdr
);
755 return ERROR_SUCCESS
;
758 UINT
ACTION_DuplicateFiles(MSIPACKAGE
*package
)
762 static const WCHAR ExecSeqQuery
[] =
763 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
764 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
766 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
767 if (rc
!= ERROR_SUCCESS
)
768 return ERROR_SUCCESS
;
770 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_DuplicateFiles
, package
);
771 msiobj_release(&view
->hdr
);
776 static UINT
ITERATE_RemoveDuplicateFiles( MSIRECORD
*row
, LPVOID param
)
778 MSIPACKAGE
*package
= param
;
780 LPCWSTR file_key
, component
;
785 component
= MSI_RecordGetString( row
, 2 );
786 comp
= get_loaded_component( package
, component
);
788 return ERROR_SUCCESS
;
790 if (comp
->ActionRequest
!= INSTALLSTATE_ABSENT
)
792 TRACE("Component not scheduled for removal %s\n", debugstr_w(component
));
793 comp
->Action
= comp
->Installed
;
794 return ERROR_SUCCESS
;
796 comp
->Action
= INSTALLSTATE_ABSENT
;
798 file_key
= MSI_RecordGetString( row
, 3 );
801 ERR("Unable to get file key\n");
802 return ERROR_FUNCTION_FAILED
;
805 file
= get_loaded_file( package
, file_key
);
808 ERR("Original file unknown %s\n", debugstr_w(file_key
));
809 return ERROR_SUCCESS
;
812 dest
= get_duplicate_filename( package
, row
, file_key
, file
->TargetPath
);
815 WARN("Unable to get duplicate filename\n");
816 return ERROR_SUCCESS
;
819 TRACE("Removing duplicate %s of %s\n", debugstr_w(dest
), debugstr_w(file
->TargetPath
));
821 if (!DeleteFileW( dest
))
823 WARN("Failed to delete duplicate file %s (%u)\n", debugstr_w(dest
), GetLastError());
826 uirow
= MSI_CreateRecord( 9 );
827 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString( row
, 1 ) );
828 MSI_RecordSetStringW( uirow
, 9, MSI_RecordGetString( row
, 5 ) );
829 ui_actiondata( package
, szRemoveDuplicateFiles
, uirow
);
830 msiobj_release( &uirow
->hdr
);
833 return ERROR_SUCCESS
;
836 UINT
ACTION_RemoveDuplicateFiles( MSIPACKAGE
*package
)
840 static const WCHAR query
[] =
841 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
842 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
844 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
845 if (rc
!= ERROR_SUCCESS
)
846 return ERROR_SUCCESS
;
848 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveDuplicateFiles
, package
);
849 msiobj_release( &view
->hdr
);
854 static BOOL
verify_comp_for_removal(MSICOMPONENT
*comp
, UINT install_mode
)
856 INSTALLSTATE request
= comp
->ActionRequest
;
858 if (request
== INSTALLSTATE_UNKNOWN
)
861 if (install_mode
== msidbRemoveFileInstallModeOnInstall
&&
862 (request
== INSTALLSTATE_LOCAL
|| request
== INSTALLSTATE_SOURCE
))
865 if (request
== INSTALLSTATE_ABSENT
)
867 if (!comp
->ComponentId
)
870 if (install_mode
== msidbRemoveFileInstallModeOnRemove
)
874 if (install_mode
== msidbRemoveFileInstallModeOnBoth
)
880 static UINT
ITERATE_RemoveFiles(MSIRECORD
*row
, LPVOID param
)
882 MSIPACKAGE
*package
= param
;
885 LPCWSTR component
, filename
, dirprop
;
887 LPWSTR dir
= NULL
, path
= NULL
;
889 UINT ret
= ERROR_SUCCESS
;
891 component
= MSI_RecordGetString(row
, 2);
892 filename
= MSI_RecordGetString(row
, 3);
893 dirprop
= MSI_RecordGetString(row
, 4);
894 install_mode
= MSI_RecordGetInteger(row
, 5);
896 comp
= get_loaded_component(package
, component
);
899 ERR("Invalid component: %s\n", debugstr_w(component
));
900 return ERROR_FUNCTION_FAILED
;
903 if (!verify_comp_for_removal(comp
, install_mode
))
905 TRACE("Skipping removal due to missing conditions\n");
906 comp
->Action
= comp
->Installed
;
907 return ERROR_SUCCESS
;
910 dir
= msi_dup_property(package
->db
, dirprop
);
912 return ERROR_OUTOFMEMORY
;
914 size
= (filename
!= NULL
) ? lstrlenW(filename
) : 0;
915 size
+= lstrlenW(dir
) + 2;
916 path
= msi_alloc(size
* sizeof(WCHAR
));
919 ret
= ERROR_OUTOFMEMORY
;
926 PathAddBackslashW(path
);
927 lstrcatW(path
, filename
);
929 TRACE("Deleting misc file: %s\n", debugstr_w(path
));
934 TRACE("Removing misc directory: %s\n", debugstr_w(dir
));
935 RemoveDirectoryW(dir
);
939 uirow
= MSI_CreateRecord( 9 );
940 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString(row
, 1) );
941 MSI_RecordSetStringW( uirow
, 9, dir
);
942 ui_actiondata( package
, szRemoveFiles
, uirow
);
943 msiobj_release( &uirow
->hdr
);
950 UINT
ACTION_RemoveFiles( MSIPACKAGE
*package
)
956 static const WCHAR query
[] = {
957 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
958 '`','R','e','m','o','v','e','F','i','l','e','`',0};
959 static const WCHAR folder_query
[] = {
960 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
961 '`','C','r','e','a','t','e','F','o','l','d','e','r','`',0};
963 r
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
964 if (r
== ERROR_SUCCESS
)
966 MSI_IterateRecords(view
, NULL
, ITERATE_RemoveFiles
, package
);
967 msiobj_release(&view
->hdr
);
970 r
= MSI_DatabaseOpenViewW(package
->db
, folder_query
, &view
);
971 if (r
== ERROR_SUCCESS
)
972 msiobj_release(&view
->hdr
);
974 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
977 LPWSTR dir
, uipath
, p
;
979 if ( file
->state
== msifs_installed
)
980 ERR("removing installed file %s\n", debugstr_w(file
->TargetPath
));
982 if ( file
->Component
->ActionRequest
!= INSTALLSTATE_ABSENT
||
983 file
->Component
->Installed
== INSTALLSTATE_SOURCE
)
986 /* don't remove a file if the old file
987 * is strictly newer than the version to be installed
989 if ( msi_compare_file_version( file
) < 0 )
992 TRACE("removing %s\n", debugstr_w(file
->File
) );
993 if (!DeleteFileW( file
->TargetPath
))
995 WARN("failed to delete %s\n", debugstr_w(file
->TargetPath
));
997 /* FIXME: check persistence for each directory */
998 else if (r
&& (dir
= strdupW( file
->TargetPath
)))
1000 if ((p
= strrchrW( dir
, '\\' ))) *p
= 0;
1001 RemoveDirectoryW( dir
);
1004 file
->state
= msifs_missing
;
1007 uirow
= MSI_CreateRecord( 9 );
1008 MSI_RecordSetStringW( uirow
, 1, file
->FileName
);
1009 uipath
= strdupW( file
->TargetPath
);
1010 p
= strrchrW(uipath
,'\\');
1013 MSI_RecordSetStringW( uirow
, 9, uipath
);
1014 ui_actiondata( package
, szRemoveFiles
, uirow
);
1015 msiobj_release( &uirow
->hdr
);
1017 /* FIXME: call ui_progress here? */
1020 return ERROR_SUCCESS
;