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
22 * Actions dealing with files:
28 * RemoveDuplicateFiles
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
51 HANDLE
msi_create_file( MSIPACKAGE
*package
, const WCHAR
*filename
, DWORD access
, DWORD sharing
, DWORD creation
,
55 msi_disable_fs_redirection( package
);
56 handle
= CreateFileW( filename
, access
, sharing
, NULL
, creation
, flags
, NULL
);
57 msi_revert_fs_redirection( package
);
61 static BOOL
msi_copy_file( MSIPACKAGE
*package
, const WCHAR
*src
, const WCHAR
*dst
, BOOL fail_if_exists
)
64 msi_disable_fs_redirection( package
);
65 ret
= CopyFileW( src
, dst
, fail_if_exists
);
66 msi_revert_fs_redirection( package
);
70 BOOL
msi_delete_file( MSIPACKAGE
*package
, const WCHAR
*filename
)
73 msi_disable_fs_redirection( package
);
74 ret
= DeleteFileW( filename
);
75 msi_revert_fs_redirection( package
);
79 static BOOL
msi_create_directory( MSIPACKAGE
*package
, const WCHAR
*path
)
82 msi_disable_fs_redirection( package
);
83 ret
= CreateDirectoryW( path
, NULL
);
84 msi_revert_fs_redirection( package
);
88 BOOL
msi_remove_directory( MSIPACKAGE
*package
, const WCHAR
*path
)
91 msi_disable_fs_redirection( package
);
92 ret
= RemoveDirectoryW( path
);
93 msi_revert_fs_redirection( package
);
97 BOOL
msi_set_file_attributes( MSIPACKAGE
*package
, const WCHAR
*filename
, DWORD attrs
)
100 msi_disable_fs_redirection( package
);
101 ret
= SetFileAttributesW( filename
, attrs
);
102 msi_revert_fs_redirection( package
);
106 DWORD
msi_get_file_attributes( MSIPACKAGE
*package
, const WCHAR
*path
)
109 msi_disable_fs_redirection( package
);
110 attrs
= GetFileAttributesW( path
);
111 msi_revert_fs_redirection( package
);
115 HANDLE
msi_find_first_file( MSIPACKAGE
*package
, const WCHAR
*filename
, WIN32_FIND_DATAW
*data
)
118 msi_disable_fs_redirection( package
);
119 handle
= FindFirstFileW( filename
, data
);
120 msi_revert_fs_redirection( package
);
124 BOOL
msi_find_next_file( MSIPACKAGE
*package
, HANDLE handle
, WIN32_FIND_DATAW
*data
)
127 msi_disable_fs_redirection( package
);
128 ret
= FindNextFileW( handle
, data
);
129 msi_revert_fs_redirection( package
);
133 BOOL
msi_move_file( MSIPACKAGE
*package
, const WCHAR
*from
, const WCHAR
*to
, DWORD flags
)
136 msi_disable_fs_redirection( package
);
137 ret
= MoveFileExW( from
, to
, flags
);
138 msi_revert_fs_redirection( package
);
142 static BOOL
msi_apply_filepatch( MSIPACKAGE
*package
, const WCHAR
*patch
, const WCHAR
*old
, const WCHAR
*new )
145 msi_disable_fs_redirection( package
);
146 ret
= ApplyPatchToFileW( patch
, old
, new, 0 );
147 msi_revert_fs_redirection( package
);
151 DWORD
msi_get_file_version_info( MSIPACKAGE
*package
, const WCHAR
*path
, DWORD buflen
, BYTE
*buffer
)
154 msi_disable_fs_redirection( package
);
155 if (buffer
) size
= GetFileVersionInfoW( path
, 0, buflen
, buffer
);
156 else size
= GetFileVersionInfoSizeW( path
, &handle
);
157 msi_revert_fs_redirection( package
);
161 VS_FIXEDFILEINFO
*msi_get_disk_file_version( MSIPACKAGE
*package
, const WCHAR
*filename
)
163 VS_FIXEDFILEINFO
*ptr
, *ret
;
164 DWORD version_size
, size
;
167 if (!(version_size
= msi_get_file_version_info( package
, filename
, 0, NULL
))) return NULL
;
168 if (!(version
= msi_alloc( version_size
))) return NULL
;
170 msi_get_file_version_info( package
, filename
, version_size
, version
);
172 if (!VerQueryValueW( version
, L
"\\", (void **)&ptr
, &size
))
178 if (!(ret
= msi_alloc( size
)))
184 memcpy( ret
, ptr
, size
);
189 DWORD
msi_get_disk_file_size( MSIPACKAGE
*package
, const WCHAR
*filename
)
193 file
= msi_create_file( package
, filename
, GENERIC_READ
, FILE_SHARE_READ
, OPEN_EXISTING
, 0 );
194 if (file
== INVALID_HANDLE_VALUE
) return INVALID_FILE_SIZE
;
195 size
= GetFileSize( file
, NULL
);
200 /* Recursively create all directories in the path. */
201 BOOL
msi_create_full_path( MSIPACKAGE
*package
, const WCHAR
*path
)
207 if (!(new_path
= msi_alloc( (lstrlenW( path
) + 1) * sizeof(WCHAR
) ))) return FALSE
;
208 lstrcpyW( new_path
, path
);
210 while ((len
= lstrlenW( new_path
)) && new_path
[len
- 1] == '\\')
211 new_path
[len
- 1] = 0;
213 while (!msi_create_directory( package
, new_path
))
216 DWORD last_error
= GetLastError();
217 if (last_error
== ERROR_ALREADY_EXISTS
) break;
218 if (last_error
!= ERROR_PATH_NOT_FOUND
)
223 if (!(slash
= wcsrchr( new_path
, '\\' )))
228 len
= slash
- new_path
;
230 if (!msi_create_full_path( package
, new_path
))
235 new_path
[len
] = '\\';
237 msi_free( new_path
);
241 static void msi_file_update_ui( MSIPACKAGE
*package
, MSIFILE
*f
, const WCHAR
*action
)
245 uirow
= MSI_CreateRecord( 9 );
246 MSI_RecordSetStringW( uirow
, 1, f
->FileName
);
247 MSI_RecordSetStringW( uirow
, 9, f
->Component
->Directory
);
248 MSI_RecordSetInteger( uirow
, 6, f
->FileSize
);
249 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
250 msiobj_release( &uirow
->hdr
);
251 msi_ui_progress( package
, 2, f
->FileSize
, 0, 0 );
254 static BOOL
is_registered_patch_media( MSIPACKAGE
*package
, UINT disk_id
)
258 LIST_FOR_EACH_ENTRY( patch
, &package
->patches
, MSIPATCHINFO
, entry
)
260 if (patch
->disk_id
== disk_id
&& patch
->registered
) return TRUE
;
265 static BOOL
is_obsoleted_by_patch( MSIPACKAGE
*package
, MSIFILE
*file
)
267 if (!list_empty( &package
->patches
) && file
->disk_id
< MSI_INITIAL_MEDIA_TRANSFORM_DISKID
)
269 if (!msi_get_property_int( package
->db
, L
"Installed", 0 )) return FALSE
;
272 if (is_registered_patch_media( package
, file
->disk_id
)) return TRUE
;
276 static BOOL
file_hash_matches( MSIPACKAGE
*package
, MSIFILE
*file
)
279 MSIFILEHASHINFO hash
;
281 hash
.dwFileHashInfoSize
= sizeof(hash
);
282 r
= msi_get_filehash( package
, file
->TargetPath
, &hash
);
283 if (r
!= ERROR_SUCCESS
)
286 return !memcmp( &hash
, &file
->hash
, sizeof(hash
) );
289 static msi_file_state
calculate_install_state( MSIPACKAGE
*package
, MSIFILE
*file
)
291 MSICOMPONENT
*comp
= file
->Component
;
292 VS_FIXEDFILEINFO
*file_version
;
294 msi_file_state state
;
297 comp
->Action
= msi_get_component_action( package
, comp
);
298 if (!comp
->Enabled
|| comp
->Action
!= INSTALLSTATE_LOCAL
|| (comp
->assembly
&& comp
->assembly
->installed
))
300 TRACE("skipping %s (not scheduled for install)\n", debugstr_w(file
->File
));
301 return msifs_skipped
;
303 if (is_obsoleted_by_patch( package
, file
))
305 TRACE("skipping %s (obsoleted by patch)\n", debugstr_w(file
->File
));
306 return msifs_skipped
;
308 if ((msi_is_global_assembly( comp
) && !comp
->assembly
->installed
) ||
309 msi_get_file_attributes( package
, file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
311 TRACE("installing %s (missing)\n", debugstr_w(file
->File
));
312 return msifs_missing
;
316 if ((file_version
= msi_get_disk_file_version( package
, file
->TargetPath
)))
318 if (msi_compare_file_versions( file_version
, file
->Version
) < 0)
320 TRACE("overwriting %s (new version %s old version %u.%u.%u.%u)\n",
321 debugstr_w(file
->File
), debugstr_w(file
->Version
),
322 HIWORD(file_version
->dwFileVersionMS
), LOWORD(file_version
->dwFileVersionMS
),
323 HIWORD(file_version
->dwFileVersionLS
), LOWORD(file_version
->dwFileVersionLS
));
324 state
= msifs_overwrite
;
328 TRACE("keeping %s (new version %s old version %u.%u.%u.%u)\n",
329 debugstr_w(file
->File
), debugstr_w(file
->Version
),
330 HIWORD(file_version
->dwFileVersionMS
), LOWORD(file_version
->dwFileVersionMS
),
331 HIWORD(file_version
->dwFileVersionLS
), LOWORD(file_version
->dwFileVersionLS
));
332 state
= msifs_present
;
334 msi_free( file_version
);
337 else if ((font_version
= msi_get_font_file_version( package
, file
->TargetPath
)))
339 if (msi_compare_font_versions( font_version
, file
->Version
) < 0)
341 TRACE("overwriting %s (new version %s old version %s)\n",
342 debugstr_w(file
->File
), debugstr_w(file
->Version
), debugstr_w(font_version
));
343 state
= msifs_overwrite
;
347 TRACE("keeping %s (new version %s old version %s)\n",
348 debugstr_w(file
->File
), debugstr_w(file
->Version
), debugstr_w(font_version
));
349 state
= msifs_present
;
351 msi_free( font_version
);
355 if ((size
= msi_get_disk_file_size( package
, file
->TargetPath
)) != file
->FileSize
)
357 TRACE("overwriting %s (old size %u new size %u)\n", debugstr_w(file
->File
), size
, file
->FileSize
);
358 return msifs_overwrite
;
360 if (file
->hash
.dwFileHashInfoSize
)
362 if (file_hash_matches( package
, file
))
364 TRACE("keeping %s (hash match)\n", debugstr_w(file
->File
));
365 return msifs_hashmatch
;
369 TRACE("overwriting %s (hash mismatch)\n", debugstr_w(file
->File
));
370 return msifs_overwrite
;
374 TRACE("keeping %s\n", debugstr_w(file
->File
));
375 return msifs_present
;
378 static void schedule_install_files(MSIPACKAGE
*package
)
382 LIST_FOR_EACH_ENTRY(file
, &package
->files
, MSIFILE
, entry
)
384 MSICOMPONENT
*comp
= file
->Component
;
386 file
->state
= calculate_install_state( package
, file
);
387 if (file
->state
== msifs_overwrite
&& (comp
->Attributes
& msidbComponentAttributesNeverOverwrite
))
389 TRACE("not overwriting %s\n", debugstr_w(file
->TargetPath
));
390 file
->state
= msifs_skipped
;
395 static UINT
copy_file( MSIPACKAGE
*package
, MSIFILE
*file
, WCHAR
*source
)
399 ret
= msi_copy_file( package
, source
, file
->TargetPath
, FALSE
);
401 return GetLastError();
403 msi_set_file_attributes( package
, file
->TargetPath
, FILE_ATTRIBUTE_NORMAL
);
404 return ERROR_SUCCESS
;
407 static UINT
copy_install_file(MSIPACKAGE
*package
, MSIFILE
*file
, LPWSTR source
)
411 TRACE("Copying %s to %s\n", debugstr_w(source
), debugstr_w(file
->TargetPath
));
413 gle
= copy_file( package
, file
, source
);
414 if (gle
== ERROR_SUCCESS
)
417 if (gle
== ERROR_ALREADY_EXISTS
&& file
->state
== msifs_overwrite
)
419 TRACE("overwriting existing file\n");
420 return ERROR_SUCCESS
;
422 else if (gle
== ERROR_ACCESS_DENIED
)
424 msi_set_file_attributes( package
, file
->TargetPath
, FILE_ATTRIBUTE_NORMAL
);
426 gle
= copy_file( package
, file
, source
);
427 TRACE("Overwriting existing file: %d\n", gle
);
429 if (gle
== ERROR_SHARING_VIOLATION
|| gle
== ERROR_USER_MAPPED_FILE
)
431 WCHAR
*tmpfileW
, *pathW
, *p
;
434 TRACE("file in use, scheduling rename operation\n");
436 if (!(pathW
= strdupW( file
->TargetPath
))) return ERROR_OUTOFMEMORY
;
437 if ((p
= wcsrchr(pathW
, '\\'))) *p
= 0;
438 len
= lstrlenW( pathW
) + 16;
439 if (!(tmpfileW
= msi_alloc(len
* sizeof(WCHAR
))))
442 return ERROR_OUTOFMEMORY
;
444 if (!GetTempFileNameW( pathW
, L
"msi", 0, tmpfileW
)) tmpfileW
[0] = 0;
447 if (msi_copy_file( package
, source
, tmpfileW
, FALSE
) &&
448 msi_move_file( package
, file
->TargetPath
, NULL
, MOVEFILE_DELAY_UNTIL_REBOOT
) &&
449 msi_move_file( package
, tmpfileW
, file
->TargetPath
, MOVEFILE_DELAY_UNTIL_REBOOT
))
451 package
->need_reboot_at_end
= 1;
456 gle
= GetLastError();
457 WARN("failed to schedule rename operation: %d)\n", gle
);
458 DeleteFileW( tmpfileW
);
466 static UINT
create_directory( MSIPACKAGE
*package
, const WCHAR
*dir
)
469 const WCHAR
*install_path
;
471 install_path
= msi_get_target_folder( package
, dir
);
472 if (!install_path
) return ERROR_FUNCTION_FAILED
;
474 folder
= msi_get_loaded_folder( package
, dir
);
475 if (folder
->State
== FOLDER_STATE_UNINITIALIZED
)
477 msi_create_full_path( package
, install_path
);
478 folder
->State
= FOLDER_STATE_CREATED
;
480 return ERROR_SUCCESS
;
483 static MSIFILE
*find_file( MSIPACKAGE
*package
, UINT disk_id
, const WCHAR
*filename
)
487 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
489 if (file
->disk_id
== disk_id
&&
490 file
->state
!= msifs_installed
&&
491 !wcsicmp( filename
, file
->File
)) return file
;
496 static BOOL
installfiles_cb(MSIPACKAGE
*package
, LPCWSTR filename
, DWORD action
,
497 LPWSTR
*path
, DWORD
*attrs
, PVOID user
)
499 MSIFILE
*file
= *(MSIFILE
**)user
;
501 if (action
== MSICABEXTRACT_BEGINEXTRACT
)
503 if (!(file
= find_file( package
, file
->disk_id
, filename
)))
505 TRACE("unknown file in cabinet (%s)\n", debugstr_w(filename
));
508 if (file
->state
!= msifs_missing
&& file
->state
!= msifs_overwrite
)
511 if (!msi_is_global_assembly( file
->Component
))
513 create_directory( package
, file
->Component
->Directory
);
515 *path
= strdupW( file
->TargetPath
);
516 *attrs
= file
->Attributes
;
517 *(MSIFILE
**)user
= file
;
519 else if (action
== MSICABEXTRACT_FILEEXTRACTED
)
521 if (!msi_is_global_assembly( file
->Component
)) file
->state
= msifs_installed
;
527 WCHAR
*msi_resolve_file_source( MSIPACKAGE
*package
, MSIFILE
*file
)
531 TRACE("Working to resolve source of file %s\n", debugstr_w(file
->File
));
533 if (file
->IsCompressed
) return NULL
;
535 p
= msi_resolve_source_folder( package
, file
->Component
->Directory
, NULL
);
536 path
= msi_build_directory_name( 2, p
, file
->ShortName
);
538 if (file
->LongName
&& msi_get_file_attributes( package
, path
) == INVALID_FILE_ATTRIBUTES
)
541 path
= msi_build_directory_name( 2, p
, file
->LongName
);
544 TRACE("file %s source resolves to %s\n", debugstr_w(file
->File
), debugstr_w(path
));
549 * ACTION_InstallFiles()
551 * For efficiency, this is done in two passes:
552 * 1) Correct all the TargetPaths and determine what files are to be installed.
553 * 2) Extract Cabinets and copy files.
555 UINT
ACTION_InstallFiles(MSIPACKAGE
*package
)
558 UINT rc
= ERROR_SUCCESS
;
561 msi_set_sourcedir_props(package
, FALSE
);
563 if (package
->script
== SCRIPT_NONE
)
564 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"InstallFiles");
566 schedule_install_files(package
);
567 mi
= msi_alloc_zero( sizeof(MSIMEDIAINFO
) );
569 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
571 BOOL is_global_assembly
= msi_is_global_assembly( file
->Component
);
573 msi_file_update_ui( package
, file
, L
"InstallFiles" );
575 rc
= msi_load_media_info( package
, file
->Sequence
, mi
);
576 if (rc
!= ERROR_SUCCESS
)
578 ERR("Unable to load media info for %s (%u)\n", debugstr_w(file
->File
), rc
);
579 rc
= ERROR_FUNCTION_FAILED
;
583 if (file
->state
!= msifs_hashmatch
&&
584 file
->state
!= msifs_skipped
&&
585 (file
->state
!= msifs_present
|| !msi_get_property_int( package
->db
, L
"Installed", 0 )) &&
586 (rc
= ready_media( package
, file
->IsCompressed
, mi
)))
588 ERR("Failed to ready media for %s\n", debugstr_w(file
->File
));
592 if (file
->state
!= msifs_missing
&& !mi
->is_continuous
&& file
->state
!= msifs_overwrite
)
595 if (file
->Sequence
> mi
->last_sequence
|| mi
->is_continuous
||
596 (file
->IsCompressed
&& !mi
->is_extracted
))
599 MSIFILE
*cursor
= file
;
602 data
.package
= package
;
603 data
.cb
= installfiles_cb
;
606 if (file
->IsCompressed
&& !msi_cabextract(package
, mi
, &data
))
608 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi
->cabinet
));
609 rc
= ERROR_INSTALL_FAILURE
;
614 if (!file
->IsCompressed
)
616 WCHAR
*source
= msi_resolve_file_source(package
, file
);
618 TRACE("copying %s to %s\n", debugstr_w(source
), debugstr_w(file
->TargetPath
));
620 if (!is_global_assembly
)
622 create_directory(package
, file
->Component
->Directory
);
624 rc
= copy_install_file(package
, file
, source
);
625 if (rc
!= ERROR_SUCCESS
)
627 ERR("Failed to copy %s to %s (%u)\n", debugstr_w(source
), debugstr_w(file
->TargetPath
), rc
);
628 rc
= ERROR_INSTALL_FAILURE
;
632 if (!is_global_assembly
) file
->state
= msifs_installed
;
635 else if (!is_global_assembly
&& file
->state
!= msifs_installed
&&
636 !(file
->Attributes
& msidbFileAttributesPatchAdded
))
638 ERR("compressed file wasn't installed (%s)\n", debugstr_w(file
->File
));
639 rc
= ERROR_INSTALL_FAILURE
;
643 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
645 MSICOMPONENT
*comp
= file
->Component
;
647 if (!msi_is_global_assembly( comp
) || comp
->assembly
->installed
||
648 (file
->state
!= msifs_missing
&& file
->state
!= msifs_overwrite
)) continue;
650 rc
= msi_install_assembly( package
, comp
);
651 if (rc
!= ERROR_SUCCESS
)
653 ERR("Failed to install assembly\n");
654 rc
= ERROR_INSTALL_FAILURE
;
657 file
->state
= msifs_installed
;
661 msi_free_media_info(mi
);
665 static MSIFILEPATCH
*find_filepatch( MSIPACKAGE
*package
, UINT disk_id
, const WCHAR
*key
)
669 LIST_FOR_EACH_ENTRY( patch
, &package
->filepatches
, MSIFILEPATCH
, entry
)
671 if (!patch
->extracted
&& patch
->disk_id
== disk_id
&& !wcscmp( key
, patch
->File
->File
))
677 static BOOL
patchfiles_cb(MSIPACKAGE
*package
, LPCWSTR file
, DWORD action
,
678 LPWSTR
*path
, DWORD
*attrs
, PVOID user
)
680 MSIFILEPATCH
*patch
= *(MSIFILEPATCH
**)user
;
682 if (action
== MSICABEXTRACT_BEGINEXTRACT
)
686 if (is_registered_patch_media( package
, patch
->disk_id
) ||
687 !(patch
= find_filepatch( package
, patch
->disk_id
, file
))) return FALSE
;
689 comp
= patch
->File
->Component
;
690 comp
->Action
= msi_get_component_action( package
, comp
);
691 if (!comp
->Enabled
|| comp
->Action
!= INSTALLSTATE_LOCAL
)
693 TRACE("file %s component %s not installed or disabled\n",
694 debugstr_w(patch
->File
->File
), debugstr_w(comp
->Component
));
698 patch
->path
= msi_create_temp_file( package
->db
);
699 *path
= strdupW( patch
->path
);
700 *attrs
= patch
->File
->Attributes
;
701 *(MSIFILEPATCH
**)user
= patch
;
703 else if (action
== MSICABEXTRACT_FILEEXTRACTED
)
705 patch
->extracted
= TRUE
;
711 static UINT
patch_file( MSIPACKAGE
*package
, MSIFILEPATCH
*patch
)
713 UINT r
= ERROR_SUCCESS
;
714 WCHAR
*tmpfile
= msi_create_temp_file( package
->db
);
716 if (!tmpfile
) return ERROR_INSTALL_FAILURE
;
717 if (msi_apply_filepatch( package
, patch
->path
, patch
->File
->TargetPath
, tmpfile
))
719 msi_delete_file( package
, patch
->File
->TargetPath
);
720 msi_move_file( package
, tmpfile
, patch
->File
->TargetPath
, 0 );
724 WARN("failed to patch %s: %08x\n", debugstr_w(patch
->File
->TargetPath
), GetLastError());
725 r
= ERROR_INSTALL_FAILURE
;
727 DeleteFileW( patch
->path
);
728 DeleteFileW( tmpfile
);
733 static UINT
patch_assembly( MSIPACKAGE
*package
, MSIASSEMBLY
*assembly
, MSIFILEPATCH
*patch
)
735 UINT r
= ERROR_FUNCTION_FAILED
;
739 if (!(iter
= msi_create_assembly_enum( package
, assembly
->display_name
)))
740 return ERROR_FUNCTION_FAILED
;
742 while ((IAssemblyEnum_GetNextAssembly( iter
, NULL
, &name
, 0 ) == S_OK
))
744 WCHAR
*displayname
, *path
;
748 hr
= IAssemblyName_GetDisplayName( name
, NULL
, &len
, 0 );
749 if (hr
!= E_NOT_SUFFICIENT_BUFFER
|| !(displayname
= msi_alloc( len
* sizeof(WCHAR
) )))
752 hr
= IAssemblyName_GetDisplayName( name
, displayname
, &len
, 0 );
755 msi_free( displayname
);
759 if ((path
= msi_get_assembly_path( package
, displayname
)))
761 if (!msi_copy_file( package
, path
, patch
->File
->TargetPath
, FALSE
))
763 ERR("Failed to copy file %s -> %s (%u)\n", debugstr_w(path
),
764 debugstr_w(patch
->File
->TargetPath
), GetLastError() );
766 msi_free( displayname
);
767 IAssemblyName_Release( name
);
770 r
= patch_file( package
, patch
);
774 msi_free( displayname
);
775 IAssemblyName_Release( name
);
776 if (r
== ERROR_SUCCESS
) break;
779 IAssemblyEnum_Release( iter
);
783 UINT
ACTION_PatchFiles( MSIPACKAGE
*package
)
787 UINT rc
= ERROR_SUCCESS
;
789 TRACE("%p\n", package
);
791 if (package
->script
== SCRIPT_NONE
)
792 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"PatchFiles");
794 mi
= msi_alloc_zero( sizeof(MSIMEDIAINFO
) );
796 TRACE("extracting files\n");
798 LIST_FOR_EACH_ENTRY( patch
, &package
->filepatches
, MSIFILEPATCH
, entry
)
800 MSIFILE
*file
= patch
->File
;
801 MSICOMPONENT
*comp
= file
->Component
;
803 rc
= msi_load_media_info( package
, patch
->Sequence
, mi
);
804 if (rc
!= ERROR_SUCCESS
)
806 ERR("Unable to load media info for %s (%u)\n", debugstr_w(file
->File
), rc
);
807 rc
= ERROR_FUNCTION_FAILED
;
810 comp
->Action
= msi_get_component_action( package
, comp
);
811 if (!comp
->Enabled
|| comp
->Action
!= INSTALLSTATE_LOCAL
) continue;
813 if (!patch
->extracted
)
816 MSIFILEPATCH
*cursor
= patch
;
818 rc
= ready_media( package
, TRUE
, mi
);
819 if (rc
!= ERROR_SUCCESS
)
821 ERR("Failed to ready media for %s\n", debugstr_w(file
->File
));
825 data
.package
= package
;
826 data
.cb
= patchfiles_cb
;
829 if (!msi_cabextract( package
, mi
, &data
))
831 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi
->cabinet
));
832 rc
= ERROR_INSTALL_FAILURE
;
838 TRACE("applying patches\n");
840 LIST_FOR_EACH_ENTRY( patch
, &package
->filepatches
, MSIFILEPATCH
, entry
)
842 MSICOMPONENT
*comp
= patch
->File
->Component
;
844 if (!patch
->path
) continue;
846 if (msi_is_global_assembly( comp
))
847 rc
= patch_assembly( package
, comp
->assembly
, patch
);
849 rc
= patch_file( package
, patch
);
851 if (rc
&& !(patch
->Attributes
& msidbPatchAttributesNonVital
))
853 ERR("Failed to apply patch to file: %s\n", debugstr_w(patch
->File
->File
));
857 if (msi_is_global_assembly( comp
))
859 if ((rc
= msi_install_assembly( package
, comp
)))
861 ERR("Failed to install patched assembly\n");
868 msi_free_media_info(mi
);
872 #define is_dot_dir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
883 static BOOL
move_file( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*dest
, int options
)
887 if (msi_get_file_attributes( package
, source
) == FILE_ATTRIBUTE_DIRECTORY
||
888 msi_get_file_attributes( package
, dest
) == FILE_ATTRIBUTE_DIRECTORY
)
890 WARN("Source or dest is directory, not moving\n");
894 if (options
== msidbMoveFileOptionsMove
)
896 TRACE("moving %s -> %s\n", debugstr_w(source
), debugstr_w(dest
));
897 ret
= msi_move_file( package
, source
, dest
, MOVEFILE_REPLACE_EXISTING
);
900 WARN("msi_move_file failed: %u\n", GetLastError());
906 TRACE("copying %s -> %s\n", debugstr_w(source
), debugstr_w(dest
));
907 ret
= msi_copy_file( package
, source
, dest
, FALSE
);
910 WARN("msi_copy_file failed: %u\n", GetLastError());
918 static WCHAR
*wildcard_to_file( const WCHAR
*wildcard
, const WCHAR
*filename
)
922 DWORD dirlen
, pathlen
;
924 ptr
= wcsrchr(wildcard
, '\\');
925 dirlen
= ptr
- wildcard
+ 1;
927 pathlen
= dirlen
+ lstrlenW(filename
) + 1;
928 if (!(path
= msi_alloc(pathlen
* sizeof(WCHAR
)))) return NULL
;
930 lstrcpynW(path
, wildcard
, dirlen
+ 1);
931 lstrcatW(path
, filename
);
936 static void free_file_entry(FILE_LIST
*file
)
938 msi_free(file
->source
);
939 msi_free(file
->dest
);
943 static void free_list(FILE_LIST
*list
)
945 while (!list_empty(&list
->entry
))
947 FILE_LIST
*file
= LIST_ENTRY(list_head(&list
->entry
), FILE_LIST
, entry
);
949 list_remove(&file
->entry
);
950 free_file_entry(file
);
954 static BOOL
add_wildcard( FILE_LIST
*files
, const WCHAR
*source
, WCHAR
*dest
)
956 FILE_LIST
*new, *file
;
957 WCHAR
*ptr
, *filename
;
960 new = msi_alloc_zero(sizeof(FILE_LIST
));
964 new->source
= strdupW(source
);
965 ptr
= wcsrchr(dest
, '\\') + 1;
966 filename
= wcsrchr(new->source
, '\\') + 1;
968 new->sourcename
= filename
;
973 new->destname
= new->sourcename
;
975 size
= (ptr
- dest
) + lstrlenW(filename
) + 1;
976 new->dest
= msi_alloc(size
* sizeof(WCHAR
));
979 free_file_entry(new);
983 lstrcpynW(new->dest
, dest
, ptr
- dest
+ 1);
984 lstrcatW(new->dest
, filename
);
986 if (list_empty(&files
->entry
))
988 list_add_head(&files
->entry
, &new->entry
);
992 LIST_FOR_EACH_ENTRY(file
, &files
->entry
, FILE_LIST
, entry
)
994 if (wcscmp( source
, file
->source
) < 0)
996 list_add_before(&file
->entry
, &new->entry
);
1001 list_add_after(&file
->entry
, &new->entry
);
1005 static BOOL
move_files_wildcard( MSIPACKAGE
*package
, const WCHAR
*source
, WCHAR
*dest
, int options
)
1007 WIN32_FIND_DATAW wfd
;
1011 FILE_LIST files
, *file
;
1014 hfile
= msi_find_first_file( package
, source
, &wfd
);
1015 if (hfile
== INVALID_HANDLE_VALUE
) return FALSE
;
1017 list_init(&files
.entry
);
1019 for (res
= TRUE
; res
; res
= msi_find_next_file( package
, hfile
, &wfd
))
1021 if (is_dot_dir(wfd
.cFileName
)) continue;
1023 path
= wildcard_to_file( source
, wfd
.cFileName
);
1030 add_wildcard(&files
, path
, dest
);
1034 /* no files match the wildcard */
1035 if (list_empty(&files
.entry
))
1038 /* only the first wildcard match gets renamed to dest */
1039 file
= LIST_ENTRY(list_head(&files
.entry
), FILE_LIST
, entry
);
1040 size
= (wcsrchr(file
->dest
, '\\') - file
->dest
) + lstrlenW(file
->destname
) + 2;
1041 file
->dest
= msi_realloc(file
->dest
, size
* sizeof(WCHAR
));
1048 /* file->dest may be shorter after the reallocation, so add a NULL
1049 * terminator. This is needed for the call to wcsrchr, as there will no
1050 * longer be a NULL terminator within the bounds of the allocation in this case.
1052 file
->dest
[size
- 1] = '\0';
1053 lstrcpyW(wcsrchr(file
->dest
, '\\') + 1, file
->destname
);
1055 while (!list_empty(&files
.entry
))
1057 file
= LIST_ENTRY(list_head(&files
.entry
), FILE_LIST
, entry
);
1059 move_file( package
, file
->source
, file
->dest
, options
);
1061 list_remove(&file
->entry
);
1062 free_file_entry(file
);
1073 void msi_reduce_to_long_filename( WCHAR
*filename
)
1075 WCHAR
*p
= wcschr( filename
, '|' );
1076 if (p
) memmove( filename
, p
+ 1, (lstrlenW( p
+ 1 ) + 1) * sizeof(WCHAR
) );
1079 static UINT
ITERATE_MoveFiles( MSIRECORD
*rec
, LPVOID param
)
1081 MSIPACKAGE
*package
= param
;
1084 LPCWSTR sourcename
, component
;
1085 LPWSTR sourcedir
, destname
= NULL
, destdir
= NULL
, source
= NULL
, dest
= NULL
;
1090 component
= MSI_RecordGetString(rec
, 2);
1091 comp
= msi_get_loaded_component(package
, component
);
1093 return ERROR_SUCCESS
;
1095 comp
->Action
= msi_get_component_action( package
, comp
);
1096 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
1098 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
1099 return ERROR_SUCCESS
;
1102 sourcename
= MSI_RecordGetString(rec
, 3);
1103 options
= MSI_RecordGetInteger(rec
, 7);
1105 sourcedir
= msi_dup_property(package
->db
, MSI_RecordGetString(rec
, 5));
1109 destdir
= msi_dup_property(package
->db
, MSI_RecordGetString(rec
, 6));
1115 if (msi_get_file_attributes( package
, sourcedir
) == INVALID_FILE_ATTRIBUTES
)
1118 source
= strdupW(sourcedir
);
1124 size
= lstrlenW(sourcedir
) + lstrlenW(sourcename
) + 2;
1125 source
= msi_alloc(size
* sizeof(WCHAR
));
1129 lstrcpyW(source
, sourcedir
);
1130 if (source
[lstrlenW(source
) - 1] != '\\')
1131 lstrcatW(source
, L
"\\");
1132 lstrcatW(source
, sourcename
);
1135 wildcards
= wcschr(source
, '*') || wcschr(source
, '?');
1137 if (MSI_RecordIsNull(rec
, 4))
1143 destname
= strdupW(sourcename
);
1144 else if ((p
= wcsrchr(sourcedir
, '\\')))
1145 destname
= strdupW(p
+ 1);
1147 destname
= strdupW(sourcedir
);
1154 destname
= strdupW(MSI_RecordGetString(rec
, 4));
1155 if (destname
) msi_reduce_to_long_filename(destname
);
1160 size
= lstrlenW(destname
);
1162 size
+= lstrlenW(destdir
) + 2;
1163 dest
= msi_alloc(size
* sizeof(WCHAR
));
1167 lstrcpyW(dest
, destdir
);
1168 if (dest
[lstrlenW(dest
) - 1] != '\\')
1169 lstrcatW(dest
, L
"\\");
1172 lstrcatW(dest
, destname
);
1174 if (msi_get_file_attributes( package
, destdir
) == INVALID_FILE_ATTRIBUTES
)
1176 if (!msi_create_full_path( package
, destdir
))
1178 WARN("failed to create directory %u\n", GetLastError());
1184 move_file( package
, source
, dest
, options
);
1186 move_files_wildcard( package
, source
, dest
, options
);
1189 uirow
= MSI_CreateRecord( 9 );
1190 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString(rec
, 1) );
1191 MSI_RecordSetInteger( uirow
, 6, 1 ); /* FIXME */
1192 MSI_RecordSetStringW( uirow
, 9, destdir
);
1193 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1194 msiobj_release( &uirow
->hdr
);
1196 msi_free(sourcedir
);
1202 return ERROR_SUCCESS
;
1205 UINT
ACTION_MoveFiles( MSIPACKAGE
*package
)
1210 if (package
->script
== SCRIPT_NONE
)
1211 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"MoveFiles");
1213 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `MoveFile`", &view
);
1214 if (rc
!= ERROR_SUCCESS
)
1215 return ERROR_SUCCESS
;
1217 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_MoveFiles
, package
);
1218 msiobj_release(&view
->hdr
);
1222 static WCHAR
*get_duplicate_filename( MSIPACKAGE
*package
, MSIRECORD
*row
, const WCHAR
*file_key
, const WCHAR
*src
)
1225 WCHAR
*dst_name
, *dst_path
, *dst
;
1227 if (MSI_RecordIsNull( row
, 4 ))
1229 len
= lstrlenW( src
) + 1;
1230 if (!(dst_name
= msi_alloc( len
* sizeof(WCHAR
)))) return NULL
;
1231 lstrcpyW( dst_name
, wcsrchr( src
, '\\' ) + 1 );
1235 MSI_RecordGetStringW( row
, 4, NULL
, &len
);
1236 if (!(dst_name
= msi_alloc( ++len
* sizeof(WCHAR
) ))) return NULL
;
1237 MSI_RecordGetStringW( row
, 4, dst_name
, &len
);
1238 msi_reduce_to_long_filename( dst_name
);
1241 if (MSI_RecordIsNull( row
, 5 ))
1244 dst_path
= strdupW( src
);
1245 p
= wcsrchr( dst_path
, '\\' );
1250 const WCHAR
*dst_key
= MSI_RecordGetString( row
, 5 );
1252 dst_path
= strdupW( msi_get_target_folder( package
, dst_key
) );
1255 /* try a property */
1256 dst_path
= msi_dup_property( package
->db
, dst_key
);
1259 FIXME("Unable to get destination folder, try AppSearch properties\n");
1260 msi_free( dst_name
);
1266 dst
= msi_build_directory_name( 2, dst_path
, dst_name
);
1267 msi_create_full_path( package
, dst_path
);
1269 msi_free( dst_name
);
1270 msi_free( dst_path
);
1274 static UINT
ITERATE_DuplicateFiles(MSIRECORD
*row
, LPVOID param
)
1276 MSIPACKAGE
*package
= param
;
1278 LPCWSTR file_key
, component
;
1283 component
= MSI_RecordGetString(row
,2);
1284 comp
= msi_get_loaded_component(package
, component
);
1286 return ERROR_SUCCESS
;
1288 comp
->Action
= msi_get_component_action( package
, comp
);
1289 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
1291 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
1292 return ERROR_SUCCESS
;
1295 file_key
= MSI_RecordGetString(row
,3);
1298 ERR("Unable to get file key\n");
1299 return ERROR_FUNCTION_FAILED
;
1302 file
= msi_get_loaded_file( package
, file_key
);
1305 ERR("Original file unknown %s\n", debugstr_w(file_key
));
1306 return ERROR_SUCCESS
;
1309 dest
= get_duplicate_filename( package
, row
, file_key
, file
->TargetPath
);
1312 WARN("Unable to get duplicate filename\n");
1313 return ERROR_SUCCESS
;
1316 TRACE("Duplicating file %s to %s\n", debugstr_w(file
->TargetPath
), debugstr_w(dest
));
1317 if (!msi_copy_file( package
, file
->TargetPath
, dest
, TRUE
))
1319 WARN("Failed to copy file %s -> %s (%u)\n",
1320 debugstr_w(file
->TargetPath
), debugstr_w(dest
), GetLastError());
1322 FIXME("We should track these duplicate files as well\n");
1324 uirow
= MSI_CreateRecord( 9 );
1325 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString( row
, 1 ) );
1326 MSI_RecordSetInteger( uirow
, 6, file
->FileSize
);
1327 MSI_RecordSetStringW( uirow
, 9, MSI_RecordGetString( row
, 5 ) );
1328 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1329 msiobj_release( &uirow
->hdr
);
1332 return ERROR_SUCCESS
;
1335 UINT
ACTION_DuplicateFiles(MSIPACKAGE
*package
)
1340 if (package
->script
== SCRIPT_NONE
)
1341 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"DuplicateFiles");
1343 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `DuplicateFile`", &view
);
1344 if (rc
!= ERROR_SUCCESS
)
1345 return ERROR_SUCCESS
;
1347 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_DuplicateFiles
, package
);
1348 msiobj_release(&view
->hdr
);
1352 static UINT
ITERATE_RemoveDuplicateFiles( MSIRECORD
*row
, LPVOID param
)
1354 MSIPACKAGE
*package
= param
;
1356 LPCWSTR file_key
, component
;
1361 component
= MSI_RecordGetString( row
, 2 );
1362 comp
= msi_get_loaded_component( package
, component
);
1364 return ERROR_SUCCESS
;
1366 comp
->Action
= msi_get_component_action( package
, comp
);
1367 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
1369 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
1370 return ERROR_SUCCESS
;
1373 file_key
= MSI_RecordGetString( row
, 3 );
1376 ERR("Unable to get file key\n");
1377 return ERROR_FUNCTION_FAILED
;
1380 file
= msi_get_loaded_file( package
, file_key
);
1383 ERR("Original file unknown %s\n", debugstr_w(file_key
));
1384 return ERROR_SUCCESS
;
1387 dest
= get_duplicate_filename( package
, row
, file_key
, file
->TargetPath
);
1390 WARN("Unable to get duplicate filename\n");
1391 return ERROR_SUCCESS
;
1394 TRACE("Removing duplicate %s of %s\n", debugstr_w(dest
), debugstr_w(file
->TargetPath
));
1395 if (!msi_delete_file( package
, dest
))
1397 WARN("Failed to delete duplicate file %s (%u)\n", debugstr_w(dest
), GetLastError());
1400 uirow
= MSI_CreateRecord( 9 );
1401 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString( row
, 1 ) );
1402 MSI_RecordSetStringW( uirow
, 9, MSI_RecordGetString( row
, 5 ) );
1403 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1404 msiobj_release( &uirow
->hdr
);
1407 return ERROR_SUCCESS
;
1410 UINT
ACTION_RemoveDuplicateFiles( MSIPACKAGE
*package
)
1415 if (package
->script
== SCRIPT_NONE
)
1416 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"RemoveDuplicateFiles");
1418 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `DuplicateFile`", &view
);
1419 if (rc
!= ERROR_SUCCESS
)
1420 return ERROR_SUCCESS
;
1422 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveDuplicateFiles
, package
);
1423 msiobj_release( &view
->hdr
);
1427 static BOOL
verify_comp_for_removal(MSICOMPONENT
*comp
, UINT install_mode
)
1430 if (comp
->Action
!= INSTALLSTATE_SOURCE
&&
1431 comp
->Attributes
& msidbComponentAttributesSourceOnly
&&
1432 (install_mode
== msidbRemoveFileInstallModeOnRemove
||
1433 install_mode
== msidbRemoveFileInstallModeOnBoth
)) return TRUE
;
1435 switch (comp
->Action
)
1437 case INSTALLSTATE_LOCAL
:
1438 case INSTALLSTATE_SOURCE
:
1439 if (install_mode
== msidbRemoveFileInstallModeOnInstall
||
1440 install_mode
== msidbRemoveFileInstallModeOnBoth
) return TRUE
;
1442 case INSTALLSTATE_ABSENT
:
1443 if (install_mode
== msidbRemoveFileInstallModeOnRemove
||
1444 install_mode
== msidbRemoveFileInstallModeOnBoth
) return TRUE
;
1451 static UINT
ITERATE_RemoveFiles(MSIRECORD
*row
, LPVOID param
)
1453 MSIPACKAGE
*package
= param
;
1456 LPCWSTR component
, dirprop
;
1458 LPWSTR dir
= NULL
, path
= NULL
, filename
= NULL
;
1460 UINT ret
= ERROR_SUCCESS
;
1462 component
= MSI_RecordGetString(row
, 2);
1463 dirprop
= MSI_RecordGetString(row
, 4);
1464 install_mode
= MSI_RecordGetInteger(row
, 5);
1466 comp
= msi_get_loaded_component(package
, component
);
1468 return ERROR_SUCCESS
;
1470 comp
->Action
= msi_get_component_action( package
, comp
);
1471 if (!verify_comp_for_removal(comp
, install_mode
))
1473 TRACE("Skipping removal due to install mode\n");
1474 return ERROR_SUCCESS
;
1476 if (comp
->assembly
&& !comp
->assembly
->application
)
1478 return ERROR_SUCCESS
;
1480 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
1482 TRACE("permanent component, not removing file\n");
1483 return ERROR_SUCCESS
;
1486 dir
= msi_dup_property(package
->db
, dirprop
);
1489 WARN("directory property has no value\n");
1490 return ERROR_SUCCESS
;
1493 if ((filename
= strdupW( MSI_RecordGetString(row
, 3) )))
1495 msi_reduce_to_long_filename( filename
);
1496 size
= lstrlenW( filename
);
1498 size
+= lstrlenW(dir
) + 2;
1499 path
= msi_alloc(size
* sizeof(WCHAR
));
1502 ret
= ERROR_OUTOFMEMORY
;
1508 lstrcpyW(path
, dir
);
1509 PathAddBackslashW(path
);
1510 lstrcatW(path
, filename
);
1512 TRACE("Deleting misc file: %s\n", debugstr_w(path
));
1513 msi_delete_file( package
, path
);
1517 TRACE("Removing misc directory: %s\n", debugstr_w(dir
));
1518 msi_remove_directory( package
, dir
);
1522 uirow
= MSI_CreateRecord( 9 );
1523 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString(row
, 1) );
1524 MSI_RecordSetStringW( uirow
, 9, dir
);
1525 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1526 msiobj_release( &uirow
->hdr
);
1534 static void remove_folder( MSIFOLDER
*folder
)
1538 LIST_FOR_EACH_ENTRY( fl
, &folder
->children
, FolderList
, entry
)
1540 remove_folder( fl
->folder
);
1542 if (!folder
->persistent
&& folder
->State
!= FOLDER_STATE_REMOVED
)
1544 if (RemoveDirectoryW( folder
->ResolvedTarget
)) folder
->State
= FOLDER_STATE_REMOVED
;
1548 UINT
ACTION_RemoveFiles( MSIPACKAGE
*package
)
1555 if (package
->script
== SCRIPT_NONE
)
1556 return msi_schedule_action(package
, SCRIPT_INSTALL
, L
"RemoveFiles");
1558 r
= MSI_DatabaseOpenViewW(package
->db
, L
"SELECT * FROM `RemoveFile`", &view
);
1559 if (r
== ERROR_SUCCESS
)
1561 r
= MSI_IterateRecords(view
, NULL
, ITERATE_RemoveFiles
, package
);
1562 msiobj_release(&view
->hdr
);
1563 if (r
!= ERROR_SUCCESS
)
1567 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
1570 VS_FIXEDFILEINFO
*ver
;
1572 comp
= file
->Component
;
1573 msi_file_update_ui( package
, file
, L
"RemoveFiles" );
1575 comp
->Action
= msi_get_component_action( package
, comp
);
1576 if (comp
->Action
!= INSTALLSTATE_ABSENT
|| comp
->Installed
== INSTALLSTATE_SOURCE
)
1579 if (comp
->assembly
&& !comp
->assembly
->application
)
1582 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
1584 TRACE("permanent component, not removing file\n");
1590 ver
= msi_get_disk_file_version( package
, file
->TargetPath
);
1591 if (ver
&& msi_compare_file_versions( ver
, file
->Version
) > 0)
1593 TRACE("newer version detected, not removing file\n");
1600 if (file
->state
== msifs_installed
)
1601 WARN("removing installed file %s\n", debugstr_w(file
->TargetPath
));
1603 TRACE("removing %s\n", debugstr_w(file
->File
) );
1605 msi_set_file_attributes( package
, file
->TargetPath
, FILE_ATTRIBUTE_NORMAL
);
1606 if (!msi_delete_file( package
, file
->TargetPath
))
1608 WARN("failed to delete %s (%u)\n", debugstr_w(file
->TargetPath
), GetLastError());
1610 file
->state
= msifs_missing
;
1612 uirow
= MSI_CreateRecord( 9 );
1613 MSI_RecordSetStringW( uirow
, 1, file
->FileName
);
1614 MSI_RecordSetStringW( uirow
, 9, comp
->Directory
);
1615 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1616 msiobj_release( &uirow
->hdr
);
1619 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
1621 comp
->Action
= msi_get_component_action( package
, comp
);
1622 if (comp
->Action
!= INSTALLSTATE_ABSENT
) continue;
1624 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
1626 TRACE("permanent component, not removing directory\n");
1629 if (comp
->assembly
&& !comp
->assembly
->application
)
1630 msi_uninstall_assembly( package
, comp
);
1633 MSIFOLDER
*folder
= msi_get_loaded_folder( package
, comp
->Directory
);
1634 if (folder
) remove_folder( folder
);
1637 return ERROR_SUCCESS
;