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 static const WCHAR name
[] = {'\\',0};
164 VS_FIXEDFILEINFO
*ptr
, *ret
;
165 DWORD version_size
, size
;
168 if (!(version_size
= msi_get_file_version_info( package
, filename
, 0, NULL
))) return NULL
;
169 if (!(version
= msi_alloc( version_size
))) return NULL
;
171 msi_get_file_version_info( package
, filename
, version_size
, version
);
173 if (!VerQueryValueW( version
, name
, (void **)&ptr
, &size
))
179 if (!(ret
= msi_alloc( size
)))
185 memcpy( ret
, ptr
, size
);
190 DWORD
msi_get_disk_file_size( MSIPACKAGE
*package
, const WCHAR
*filename
)
194 file
= msi_create_file( package
, filename
, GENERIC_READ
, FILE_SHARE_READ
, OPEN_EXISTING
, 0 );
195 if (file
== INVALID_HANDLE_VALUE
) return INVALID_FILE_SIZE
;
196 size
= GetFileSize( file
, NULL
);
201 /* Recursively create all directories in the path. */
202 BOOL
msi_create_full_path( MSIPACKAGE
*package
, const WCHAR
*path
)
208 if (!(new_path
= msi_alloc( (lstrlenW( path
) + 1) * sizeof(WCHAR
) ))) return FALSE
;
209 lstrcpyW( new_path
, path
);
211 while ((len
= lstrlenW( new_path
)) && new_path
[len
- 1] == '\\')
212 new_path
[len
- 1] = 0;
214 while (!msi_create_directory( package
, new_path
))
217 DWORD last_error
= GetLastError();
218 if (last_error
== ERROR_ALREADY_EXISTS
) break;
219 if (last_error
!= ERROR_PATH_NOT_FOUND
)
224 if (!(slash
= wcsrchr( new_path
, '\\' )))
229 len
= slash
- new_path
;
231 if (!msi_create_full_path( package
, new_path
))
236 new_path
[len
] = '\\';
238 msi_free( new_path
);
242 static void msi_file_update_ui( MSIPACKAGE
*package
, MSIFILE
*f
, const WCHAR
*action
)
246 uirow
= MSI_CreateRecord( 9 );
247 MSI_RecordSetStringW( uirow
, 1, f
->FileName
);
248 MSI_RecordSetStringW( uirow
, 9, f
->Component
->Directory
);
249 MSI_RecordSetInteger( uirow
, 6, f
->FileSize
);
250 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
251 msiobj_release( &uirow
->hdr
);
252 msi_ui_progress( package
, 2, f
->FileSize
, 0, 0 );
255 static BOOL
is_registered_patch_media( MSIPACKAGE
*package
, UINT disk_id
)
259 LIST_FOR_EACH_ENTRY( patch
, &package
->patches
, MSIPATCHINFO
, entry
)
261 if (patch
->disk_id
== disk_id
&& patch
->registered
) return TRUE
;
266 static BOOL
is_obsoleted_by_patch( MSIPACKAGE
*package
, MSIFILE
*file
)
268 if (!list_empty( &package
->patches
) && file
->disk_id
< MSI_INITIAL_MEDIA_TRANSFORM_DISKID
)
270 if (!msi_get_property_int( package
->db
, szInstalled
, 0 )) return FALSE
;
273 if (is_registered_patch_media( package
, file
->disk_id
)) return TRUE
;
277 static BOOL
file_hash_matches( MSIPACKAGE
*package
, MSIFILE
*file
)
280 MSIFILEHASHINFO hash
;
282 hash
.dwFileHashInfoSize
= sizeof(hash
);
283 r
= msi_get_filehash( package
, file
->TargetPath
, &hash
);
284 if (r
!= ERROR_SUCCESS
)
287 return !memcmp( &hash
, &file
->hash
, sizeof(hash
) );
290 static msi_file_state
calculate_install_state( MSIPACKAGE
*package
, MSIFILE
*file
)
292 MSICOMPONENT
*comp
= file
->Component
;
293 VS_FIXEDFILEINFO
*file_version
;
295 msi_file_state state
;
298 comp
->Action
= msi_get_component_action( package
, comp
);
299 if (!comp
->Enabled
|| comp
->Action
!= INSTALLSTATE_LOCAL
|| (comp
->assembly
&& comp
->assembly
->installed
))
301 TRACE("skipping %s (not scheduled for install)\n", debugstr_w(file
->File
));
302 return msifs_skipped
;
304 if (is_obsoleted_by_patch( package
, file
))
306 TRACE("skipping %s (obsoleted by patch)\n", debugstr_w(file
->File
));
307 return msifs_skipped
;
309 if ((msi_is_global_assembly( comp
) && !comp
->assembly
->installed
) ||
310 msi_get_file_attributes( package
, file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
312 TRACE("installing %s (missing)\n", debugstr_w(file
->File
));
313 return msifs_missing
;
317 if ((file_version
= msi_get_disk_file_version( package
, file
->TargetPath
)))
319 if (msi_compare_file_versions( file_version
, file
->Version
) < 0)
321 TRACE("overwriting %s (new version %s old version %u.%u.%u.%u)\n",
322 debugstr_w(file
->File
), debugstr_w(file
->Version
),
323 HIWORD(file_version
->dwFileVersionMS
), LOWORD(file_version
->dwFileVersionMS
),
324 HIWORD(file_version
->dwFileVersionLS
), LOWORD(file_version
->dwFileVersionLS
));
325 state
= msifs_overwrite
;
329 TRACE("keeping %s (new version %s old version %u.%u.%u.%u)\n",
330 debugstr_w(file
->File
), debugstr_w(file
->Version
),
331 HIWORD(file_version
->dwFileVersionMS
), LOWORD(file_version
->dwFileVersionMS
),
332 HIWORD(file_version
->dwFileVersionLS
), LOWORD(file_version
->dwFileVersionLS
));
333 state
= msifs_present
;
335 msi_free( file_version
);
338 else if ((font_version
= msi_get_font_file_version( package
, file
->TargetPath
)))
340 if (msi_compare_font_versions( font_version
, file
->Version
) < 0)
342 TRACE("overwriting %s (new version %s old version %s)\n",
343 debugstr_w(file
->File
), debugstr_w(file
->Version
), debugstr_w(font_version
));
344 state
= msifs_overwrite
;
348 TRACE("keeping %s (new version %s old version %s)\n",
349 debugstr_w(file
->File
), debugstr_w(file
->Version
), debugstr_w(font_version
));
350 state
= msifs_present
;
352 msi_free( font_version
);
356 if ((size
= msi_get_disk_file_size( package
, file
->TargetPath
)) != file
->FileSize
)
358 TRACE("overwriting %s (old size %u new size %u)\n", debugstr_w(file
->File
), size
, file
->FileSize
);
359 return msifs_overwrite
;
361 if (file
->hash
.dwFileHashInfoSize
)
363 if (file_hash_matches( package
, file
))
365 TRACE("keeping %s (hash match)\n", debugstr_w(file
->File
));
366 return msifs_hashmatch
;
370 TRACE("overwriting %s (hash mismatch)\n", debugstr_w(file
->File
));
371 return msifs_overwrite
;
375 TRACE("keeping %s\n", debugstr_w(file
->File
));
376 return msifs_present
;
379 static void schedule_install_files(MSIPACKAGE
*package
)
383 LIST_FOR_EACH_ENTRY(file
, &package
->files
, MSIFILE
, entry
)
385 MSICOMPONENT
*comp
= file
->Component
;
387 file
->state
= calculate_install_state( package
, file
);
388 if (file
->state
== msifs_overwrite
&& (comp
->Attributes
& msidbComponentAttributesNeverOverwrite
))
390 TRACE("not overwriting %s\n", debugstr_w(file
->TargetPath
));
391 file
->state
= msifs_skipped
;
396 static UINT
copy_file( MSIPACKAGE
*package
, MSIFILE
*file
, WCHAR
*source
)
400 ret
= msi_copy_file( package
, source
, file
->TargetPath
, FALSE
);
402 return GetLastError();
404 msi_set_file_attributes( package
, file
->TargetPath
, FILE_ATTRIBUTE_NORMAL
);
405 return ERROR_SUCCESS
;
408 static UINT
copy_install_file(MSIPACKAGE
*package
, MSIFILE
*file
, LPWSTR source
)
412 TRACE("Copying %s to %s\n", debugstr_w(source
), debugstr_w(file
->TargetPath
));
414 gle
= copy_file( package
, file
, source
);
415 if (gle
== ERROR_SUCCESS
)
418 if (gle
== ERROR_ALREADY_EXISTS
&& file
->state
== msifs_overwrite
)
420 TRACE("overwriting existing file\n");
421 return ERROR_SUCCESS
;
423 else if (gle
== ERROR_ACCESS_DENIED
)
425 msi_set_file_attributes( package
, file
->TargetPath
, FILE_ATTRIBUTE_NORMAL
);
427 gle
= copy_file( package
, file
, source
);
428 TRACE("Overwriting existing file: %d\n", gle
);
430 if (gle
== ERROR_SHARING_VIOLATION
|| gle
== ERROR_USER_MAPPED_FILE
)
432 WCHAR
*tmpfileW
, *pathW
, *p
;
435 TRACE("file in use, scheduling rename operation\n");
437 if (!(pathW
= strdupW( file
->TargetPath
))) return ERROR_OUTOFMEMORY
;
438 if ((p
= wcsrchr(pathW
, '\\'))) *p
= 0;
439 len
= lstrlenW( pathW
) + 16;
440 if (!(tmpfileW
= msi_alloc(len
* sizeof(WCHAR
))))
443 return ERROR_OUTOFMEMORY
;
445 if (!GetTempFileNameW( pathW
, szMsi
, 0, tmpfileW
)) tmpfileW
[0] = 0;
448 if (msi_copy_file( package
, source
, tmpfileW
, FALSE
) &&
449 msi_move_file( package
, file
->TargetPath
, NULL
, MOVEFILE_DELAY_UNTIL_REBOOT
) &&
450 msi_move_file( package
, tmpfileW
, file
->TargetPath
, MOVEFILE_DELAY_UNTIL_REBOOT
))
452 package
->need_reboot_at_end
= 1;
457 gle
= GetLastError();
458 WARN("failed to schedule rename operation: %d)\n", gle
);
459 DeleteFileW( tmpfileW
);
467 static UINT
create_directory( MSIPACKAGE
*package
, const WCHAR
*dir
)
470 const WCHAR
*install_path
;
472 install_path
= msi_get_target_folder( package
, dir
);
473 if (!install_path
) return ERROR_FUNCTION_FAILED
;
475 folder
= msi_get_loaded_folder( package
, dir
);
476 if (folder
->State
== FOLDER_STATE_UNINITIALIZED
)
478 msi_create_full_path( package
, install_path
);
479 folder
->State
= FOLDER_STATE_CREATED
;
481 return ERROR_SUCCESS
;
484 static MSIFILE
*find_file( MSIPACKAGE
*package
, UINT disk_id
, const WCHAR
*filename
)
488 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
490 if (file
->disk_id
== disk_id
&&
491 file
->state
!= msifs_installed
&&
492 !wcsicmp( filename
, file
->File
)) return file
;
497 static BOOL
installfiles_cb(MSIPACKAGE
*package
, LPCWSTR filename
, DWORD action
,
498 LPWSTR
*path
, DWORD
*attrs
, PVOID user
)
500 MSIFILE
*file
= *(MSIFILE
**)user
;
502 if (action
== MSICABEXTRACT_BEGINEXTRACT
)
504 if (!(file
= find_file( package
, file
->disk_id
, filename
)))
506 TRACE("unknown file in cabinet (%s)\n", debugstr_w(filename
));
509 if (file
->state
!= msifs_missing
&& file
->state
!= msifs_overwrite
)
512 if (!msi_is_global_assembly( file
->Component
))
514 create_directory( package
, file
->Component
->Directory
);
516 *path
= strdupW( file
->TargetPath
);
517 *attrs
= file
->Attributes
;
518 *(MSIFILE
**)user
= file
;
520 else if (action
== MSICABEXTRACT_FILEEXTRACTED
)
522 if (!msi_is_global_assembly( file
->Component
)) file
->state
= msifs_installed
;
528 WCHAR
*msi_resolve_file_source( MSIPACKAGE
*package
, MSIFILE
*file
)
532 TRACE("Working to resolve source of file %s\n", debugstr_w(file
->File
));
534 if (file
->IsCompressed
) return NULL
;
536 p
= msi_resolve_source_folder( package
, file
->Component
->Directory
, NULL
);
537 path
= msi_build_directory_name( 2, p
, file
->ShortName
);
539 if (file
->LongName
&& msi_get_file_attributes( package
, path
) == INVALID_FILE_ATTRIBUTES
)
542 path
= msi_build_directory_name( 2, p
, file
->LongName
);
545 TRACE("file %s source resolves to %s\n", debugstr_w(file
->File
), debugstr_w(path
));
550 * ACTION_InstallFiles()
552 * For efficiency, this is done in two passes:
553 * 1) Correct all the TargetPaths and determine what files are to be installed.
554 * 2) Extract Cabinets and copy files.
556 UINT
ACTION_InstallFiles(MSIPACKAGE
*package
)
559 UINT rc
= ERROR_SUCCESS
;
562 msi_set_sourcedir_props(package
, FALSE
);
564 if (package
->script
== SCRIPT_NONE
)
565 return msi_schedule_action(package
, SCRIPT_INSTALL
, szInstallFiles
);
567 schedule_install_files(package
);
568 mi
= msi_alloc_zero( sizeof(MSIMEDIAINFO
) );
570 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
572 BOOL is_global_assembly
= msi_is_global_assembly( file
->Component
);
574 msi_file_update_ui( package
, file
, szInstallFiles
);
576 rc
= msi_load_media_info( package
, file
->Sequence
, mi
);
577 if (rc
!= ERROR_SUCCESS
)
579 ERR("Unable to load media info for %s (%u)\n", debugstr_w(file
->File
), rc
);
580 rc
= ERROR_FUNCTION_FAILED
;
584 if (file
->state
!= msifs_hashmatch
&&
585 file
->state
!= msifs_skipped
&&
586 (file
->state
!= msifs_present
|| !msi_get_property_int( package
->db
, szInstalled
, 0 )) &&
587 (rc
= ready_media( package
, file
->IsCompressed
, mi
)))
589 ERR("Failed to ready media for %s\n", debugstr_w(file
->File
));
593 if (file
->state
!= msifs_missing
&& !mi
->is_continuous
&& file
->state
!= msifs_overwrite
)
596 if (file
->Sequence
> mi
->last_sequence
|| mi
->is_continuous
||
597 (file
->IsCompressed
&& !mi
->is_extracted
))
600 MSIFILE
*cursor
= file
;
603 data
.package
= package
;
604 data
.cb
= installfiles_cb
;
607 if (file
->IsCompressed
&& !msi_cabextract(package
, mi
, &data
))
609 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi
->cabinet
));
610 rc
= ERROR_INSTALL_FAILURE
;
615 if (!file
->IsCompressed
)
617 WCHAR
*source
= msi_resolve_file_source(package
, file
);
619 TRACE("copying %s to %s\n", debugstr_w(source
), debugstr_w(file
->TargetPath
));
621 if (!is_global_assembly
)
623 create_directory(package
, file
->Component
->Directory
);
625 rc
= copy_install_file(package
, file
, source
);
626 if (rc
!= ERROR_SUCCESS
)
628 ERR("Failed to copy %s to %s (%u)\n", debugstr_w(source
), debugstr_w(file
->TargetPath
), rc
);
629 rc
= ERROR_INSTALL_FAILURE
;
633 if (!is_global_assembly
) file
->state
= msifs_installed
;
636 else if (!is_global_assembly
&& file
->state
!= msifs_installed
&&
637 !(file
->Attributes
& msidbFileAttributesPatchAdded
))
639 ERR("compressed file wasn't installed (%s)\n", debugstr_w(file
->File
));
640 rc
= ERROR_INSTALL_FAILURE
;
644 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
646 MSICOMPONENT
*comp
= file
->Component
;
648 if (!msi_is_global_assembly( comp
) || comp
->assembly
->installed
||
649 (file
->state
!= msifs_missing
&& file
->state
!= msifs_overwrite
)) continue;
651 rc
= msi_install_assembly( package
, comp
);
652 if (rc
!= ERROR_SUCCESS
)
654 ERR("Failed to install assembly\n");
655 rc
= ERROR_INSTALL_FAILURE
;
658 file
->state
= msifs_installed
;
662 msi_free_media_info(mi
);
666 static MSIFILEPATCH
*find_filepatch( MSIPACKAGE
*package
, UINT disk_id
, const WCHAR
*key
)
670 LIST_FOR_EACH_ENTRY( patch
, &package
->filepatches
, MSIFILEPATCH
, entry
)
672 if (!patch
->extracted
&& patch
->disk_id
== disk_id
&& !wcscmp( key
, patch
->File
->File
))
678 static BOOL
patchfiles_cb(MSIPACKAGE
*package
, LPCWSTR file
, DWORD action
,
679 LPWSTR
*path
, DWORD
*attrs
, PVOID user
)
681 MSIFILEPATCH
*patch
= *(MSIFILEPATCH
**)user
;
683 if (action
== MSICABEXTRACT_BEGINEXTRACT
)
687 if (is_registered_patch_media( package
, patch
->disk_id
) ||
688 !(patch
= find_filepatch( package
, patch
->disk_id
, file
))) return FALSE
;
690 comp
= patch
->File
->Component
;
691 comp
->Action
= msi_get_component_action( package
, comp
);
692 if (!comp
->Enabled
|| comp
->Action
!= INSTALLSTATE_LOCAL
)
694 TRACE("file %s component %s not installed or disabled\n",
695 debugstr_w(patch
->File
->File
), debugstr_w(comp
->Component
));
699 patch
->path
= msi_create_temp_file( package
->db
);
700 *path
= strdupW( patch
->path
);
701 *attrs
= patch
->File
->Attributes
;
702 *(MSIFILEPATCH
**)user
= patch
;
704 else if (action
== MSICABEXTRACT_FILEEXTRACTED
)
706 patch
->extracted
= TRUE
;
712 static UINT
patch_file( MSIPACKAGE
*package
, MSIFILEPATCH
*patch
)
714 UINT r
= ERROR_SUCCESS
;
715 WCHAR
*tmpfile
= msi_create_temp_file( package
->db
);
717 if (!tmpfile
) return ERROR_INSTALL_FAILURE
;
718 if (msi_apply_filepatch( package
, patch
->path
, patch
->File
->TargetPath
, tmpfile
))
720 msi_delete_file( package
, patch
->File
->TargetPath
);
721 msi_move_file( package
, tmpfile
, patch
->File
->TargetPath
, 0 );
725 WARN("failed to patch %s: %08x\n", debugstr_w(patch
->File
->TargetPath
), GetLastError());
726 r
= ERROR_INSTALL_FAILURE
;
728 DeleteFileW( patch
->path
);
729 DeleteFileW( tmpfile
);
734 static UINT
patch_assembly( MSIPACKAGE
*package
, MSIASSEMBLY
*assembly
, MSIFILEPATCH
*patch
)
736 UINT r
= ERROR_FUNCTION_FAILED
;
740 if (!(iter
= msi_create_assembly_enum( package
, assembly
->display_name
)))
741 return ERROR_FUNCTION_FAILED
;
743 while ((IAssemblyEnum_GetNextAssembly( iter
, NULL
, &name
, 0 ) == S_OK
))
745 WCHAR
*displayname
, *path
;
749 hr
= IAssemblyName_GetDisplayName( name
, NULL
, &len
, 0 );
750 if (hr
!= E_NOT_SUFFICIENT_BUFFER
|| !(displayname
= msi_alloc( len
* sizeof(WCHAR
) )))
753 hr
= IAssemblyName_GetDisplayName( name
, displayname
, &len
, 0 );
756 msi_free( displayname
);
760 if ((path
= msi_get_assembly_path( package
, displayname
)))
762 if (!msi_copy_file( package
, path
, patch
->File
->TargetPath
, FALSE
))
764 ERR("Failed to copy file %s -> %s (%u)\n", debugstr_w(path
),
765 debugstr_w(patch
->File
->TargetPath
), GetLastError() );
767 msi_free( displayname
);
768 IAssemblyName_Release( name
);
771 r
= patch_file( package
, patch
);
775 msi_free( displayname
);
776 IAssemblyName_Release( name
);
777 if (r
== ERROR_SUCCESS
) break;
780 IAssemblyEnum_Release( iter
);
784 UINT
ACTION_PatchFiles( MSIPACKAGE
*package
)
788 UINT rc
= ERROR_SUCCESS
;
790 TRACE("%p\n", package
);
792 if (package
->script
== SCRIPT_NONE
)
793 return msi_schedule_action(package
, SCRIPT_INSTALL
, szPatchFiles
);
795 mi
= msi_alloc_zero( sizeof(MSIMEDIAINFO
) );
797 TRACE("extracting files\n");
799 LIST_FOR_EACH_ENTRY( patch
, &package
->filepatches
, MSIFILEPATCH
, entry
)
801 MSIFILE
*file
= patch
->File
;
802 MSICOMPONENT
*comp
= file
->Component
;
804 rc
= msi_load_media_info( package
, patch
->Sequence
, mi
);
805 if (rc
!= ERROR_SUCCESS
)
807 ERR("Unable to load media info for %s (%u)\n", debugstr_w(file
->File
), rc
);
808 rc
= ERROR_FUNCTION_FAILED
;
811 comp
->Action
= msi_get_component_action( package
, comp
);
812 if (!comp
->Enabled
|| comp
->Action
!= INSTALLSTATE_LOCAL
) continue;
814 if (!patch
->extracted
)
817 MSIFILEPATCH
*cursor
= patch
;
819 rc
= ready_media( package
, TRUE
, mi
);
820 if (rc
!= ERROR_SUCCESS
)
822 ERR("Failed to ready media for %s\n", debugstr_w(file
->File
));
826 data
.package
= package
;
827 data
.cb
= patchfiles_cb
;
830 if (!msi_cabextract( package
, mi
, &data
))
832 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi
->cabinet
));
833 rc
= ERROR_INSTALL_FAILURE
;
839 TRACE("applying patches\n");
841 LIST_FOR_EACH_ENTRY( patch
, &package
->filepatches
, MSIFILEPATCH
, entry
)
843 MSICOMPONENT
*comp
= patch
->File
->Component
;
845 if (!patch
->path
) continue;
847 if (msi_is_global_assembly( comp
))
848 rc
= patch_assembly( package
, comp
->assembly
, patch
);
850 rc
= patch_file( package
, patch
);
852 if (rc
&& !(patch
->Attributes
& msidbPatchAttributesNonVital
))
854 ERR("Failed to apply patch to file: %s\n", debugstr_w(patch
->File
->File
));
858 if (msi_is_global_assembly( comp
))
860 if ((rc
= msi_install_assembly( package
, comp
)))
862 ERR("Failed to install patched assembly\n");
869 msi_free_media_info(mi
);
873 #define is_dot_dir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
884 static BOOL
move_file( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*dest
, int options
)
888 if (msi_get_file_attributes( package
, source
) == FILE_ATTRIBUTE_DIRECTORY
||
889 msi_get_file_attributes( package
, dest
) == FILE_ATTRIBUTE_DIRECTORY
)
891 WARN("Source or dest is directory, not moving\n");
895 if (options
== msidbMoveFileOptionsMove
)
897 TRACE("moving %s -> %s\n", debugstr_w(source
), debugstr_w(dest
));
898 ret
= msi_move_file( package
, source
, dest
, MOVEFILE_REPLACE_EXISTING
);
901 WARN("msi_move_file failed: %u\n", GetLastError());
907 TRACE("copying %s -> %s\n", debugstr_w(source
), debugstr_w(dest
));
908 ret
= msi_copy_file( package
, source
, dest
, FALSE
);
911 WARN("msi_copy_file failed: %u\n", GetLastError());
919 static WCHAR
*wildcard_to_file( const WCHAR
*wildcard
, const WCHAR
*filename
)
923 DWORD dirlen
, pathlen
;
925 ptr
= wcsrchr(wildcard
, '\\');
926 dirlen
= ptr
- wildcard
+ 1;
928 pathlen
= dirlen
+ lstrlenW(filename
) + 1;
929 if (!(path
= msi_alloc(pathlen
* sizeof(WCHAR
)))) return NULL
;
931 lstrcpynW(path
, wildcard
, dirlen
+ 1);
932 lstrcatW(path
, filename
);
937 static void free_file_entry(FILE_LIST
*file
)
939 msi_free(file
->source
);
940 msi_free(file
->dest
);
944 static void free_list(FILE_LIST
*list
)
946 while (!list_empty(&list
->entry
))
948 FILE_LIST
*file
= LIST_ENTRY(list_head(&list
->entry
), FILE_LIST
, entry
);
950 list_remove(&file
->entry
);
951 free_file_entry(file
);
955 static BOOL
add_wildcard( FILE_LIST
*files
, const WCHAR
*source
, WCHAR
*dest
)
957 FILE_LIST
*new, *file
;
958 WCHAR
*ptr
, *filename
;
961 new = msi_alloc_zero(sizeof(FILE_LIST
));
965 new->source
= strdupW(source
);
966 ptr
= wcsrchr(dest
, '\\') + 1;
967 filename
= wcsrchr(new->source
, '\\') + 1;
969 new->sourcename
= filename
;
974 new->destname
= new->sourcename
;
976 size
= (ptr
- dest
) + lstrlenW(filename
) + 1;
977 new->dest
= msi_alloc(size
* sizeof(WCHAR
));
980 free_file_entry(new);
984 lstrcpynW(new->dest
, dest
, ptr
- dest
+ 1);
985 lstrcatW(new->dest
, filename
);
987 if (list_empty(&files
->entry
))
989 list_add_head(&files
->entry
, &new->entry
);
993 LIST_FOR_EACH_ENTRY(file
, &files
->entry
, FILE_LIST
, entry
)
995 if (wcscmp( source
, file
->source
) < 0)
997 list_add_before(&file
->entry
, &new->entry
);
1002 list_add_after(&file
->entry
, &new->entry
);
1006 static BOOL
move_files_wildcard( MSIPACKAGE
*package
, const WCHAR
*source
, WCHAR
*dest
, int options
)
1008 WIN32_FIND_DATAW wfd
;
1012 FILE_LIST files
, *file
;
1015 hfile
= msi_find_first_file( package
, source
, &wfd
);
1016 if (hfile
== INVALID_HANDLE_VALUE
) return FALSE
;
1018 list_init(&files
.entry
);
1020 for (res
= TRUE
; res
; res
= msi_find_next_file( package
, hfile
, &wfd
))
1022 if (is_dot_dir(wfd
.cFileName
)) continue;
1024 path
= wildcard_to_file( source
, wfd
.cFileName
);
1031 add_wildcard(&files
, path
, dest
);
1035 /* no files match the wildcard */
1036 if (list_empty(&files
.entry
))
1039 /* only the first wildcard match gets renamed to dest */
1040 file
= LIST_ENTRY(list_head(&files
.entry
), FILE_LIST
, entry
);
1041 size
= (wcsrchr(file
->dest
, '\\') - file
->dest
) + lstrlenW(file
->destname
) + 2;
1042 file
->dest
= msi_realloc(file
->dest
, size
* sizeof(WCHAR
));
1049 /* file->dest may be shorter after the reallocation, so add a NULL
1050 * terminator. This is needed for the call to wcsrchr, as there will no
1051 * longer be a NULL terminator within the bounds of the allocation in this case.
1053 file
->dest
[size
- 1] = '\0';
1054 lstrcpyW(wcsrchr(file
->dest
, '\\') + 1, file
->destname
);
1056 while (!list_empty(&files
.entry
))
1058 file
= LIST_ENTRY(list_head(&files
.entry
), FILE_LIST
, entry
);
1060 move_file( package
, file
->source
, file
->dest
, options
);
1062 list_remove(&file
->entry
);
1063 free_file_entry(file
);
1074 void msi_reduce_to_long_filename( WCHAR
*filename
)
1076 WCHAR
*p
= wcschr( filename
, '|' );
1077 if (p
) memmove( filename
, p
+ 1, (lstrlenW( p
+ 1 ) + 1) * sizeof(WCHAR
) );
1080 static UINT
ITERATE_MoveFiles( MSIRECORD
*rec
, LPVOID param
)
1082 MSIPACKAGE
*package
= param
;
1085 LPCWSTR sourcename
, component
;
1086 LPWSTR sourcedir
, destname
= NULL
, destdir
= NULL
, source
= NULL
, dest
= NULL
;
1091 component
= MSI_RecordGetString(rec
, 2);
1092 comp
= msi_get_loaded_component(package
, component
);
1094 return ERROR_SUCCESS
;
1096 comp
->Action
= msi_get_component_action( package
, comp
);
1097 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
1099 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
1100 return ERROR_SUCCESS
;
1103 sourcename
= MSI_RecordGetString(rec
, 3);
1104 options
= MSI_RecordGetInteger(rec
, 7);
1106 sourcedir
= msi_dup_property(package
->db
, MSI_RecordGetString(rec
, 5));
1110 destdir
= msi_dup_property(package
->db
, MSI_RecordGetString(rec
, 6));
1116 if (msi_get_file_attributes( package
, sourcedir
) == INVALID_FILE_ATTRIBUTES
)
1119 source
= strdupW(sourcedir
);
1125 size
= lstrlenW(sourcedir
) + lstrlenW(sourcename
) + 2;
1126 source
= msi_alloc(size
* sizeof(WCHAR
));
1130 lstrcpyW(source
, sourcedir
);
1131 if (source
[lstrlenW(source
) - 1] != '\\')
1132 lstrcatW(source
, szBackSlash
);
1133 lstrcatW(source
, sourcename
);
1136 wildcards
= wcschr(source
, '*') || wcschr(source
, '?');
1138 if (MSI_RecordIsNull(rec
, 4))
1144 destname
= strdupW(sourcename
);
1145 else if ((p
= wcsrchr(sourcedir
, '\\')))
1146 destname
= strdupW(p
+ 1);
1148 destname
= strdupW(sourcedir
);
1155 destname
= strdupW(MSI_RecordGetString(rec
, 4));
1156 if (destname
) msi_reduce_to_long_filename(destname
);
1161 size
= lstrlenW(destname
);
1163 size
+= lstrlenW(destdir
) + 2;
1164 dest
= msi_alloc(size
* sizeof(WCHAR
));
1168 lstrcpyW(dest
, destdir
);
1169 if (dest
[lstrlenW(dest
) - 1] != '\\')
1170 lstrcatW(dest
, szBackSlash
);
1173 lstrcatW(dest
, destname
);
1175 if (msi_get_file_attributes( package
, destdir
) == INVALID_FILE_ATTRIBUTES
)
1177 if (!msi_create_full_path( package
, destdir
))
1179 WARN("failed to create directory %u\n", GetLastError());
1185 move_file( package
, source
, dest
, options
);
1187 move_files_wildcard( package
, source
, dest
, options
);
1190 uirow
= MSI_CreateRecord( 9 );
1191 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString(rec
, 1) );
1192 MSI_RecordSetInteger( uirow
, 6, 1 ); /* FIXME */
1193 MSI_RecordSetStringW( uirow
, 9, destdir
);
1194 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1195 msiobj_release( &uirow
->hdr
);
1197 msi_free(sourcedir
);
1203 return ERROR_SUCCESS
;
1206 UINT
ACTION_MoveFiles( MSIPACKAGE
*package
)
1208 static const WCHAR query
[] = {
1209 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1210 '`','M','o','v','e','F','i','l','e','`',0};
1214 if (package
->script
== SCRIPT_NONE
)
1215 return msi_schedule_action(package
, SCRIPT_INSTALL
, szMoveFiles
);
1217 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
1218 if (rc
!= ERROR_SUCCESS
)
1219 return ERROR_SUCCESS
;
1221 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_MoveFiles
, package
);
1222 msiobj_release(&view
->hdr
);
1226 static WCHAR
*get_duplicate_filename( MSIPACKAGE
*package
, MSIRECORD
*row
, const WCHAR
*file_key
, const WCHAR
*src
)
1229 WCHAR
*dst_name
, *dst_path
, *dst
;
1231 if (MSI_RecordIsNull( row
, 4 ))
1233 len
= lstrlenW( src
) + 1;
1234 if (!(dst_name
= msi_alloc( len
* sizeof(WCHAR
)))) return NULL
;
1235 lstrcpyW( dst_name
, wcsrchr( src
, '\\' ) + 1 );
1239 MSI_RecordGetStringW( row
, 4, NULL
, &len
);
1240 if (!(dst_name
= msi_alloc( ++len
* sizeof(WCHAR
) ))) return NULL
;
1241 MSI_RecordGetStringW( row
, 4, dst_name
, &len
);
1242 msi_reduce_to_long_filename( dst_name
);
1245 if (MSI_RecordIsNull( row
, 5 ))
1248 dst_path
= strdupW( src
);
1249 p
= wcsrchr( dst_path
, '\\' );
1254 const WCHAR
*dst_key
= MSI_RecordGetString( row
, 5 );
1256 dst_path
= strdupW( msi_get_target_folder( package
, dst_key
) );
1259 /* try a property */
1260 dst_path
= msi_dup_property( package
->db
, dst_key
);
1263 FIXME("Unable to get destination folder, try AppSearch properties\n");
1264 msi_free( dst_name
);
1270 dst
= msi_build_directory_name( 2, dst_path
, dst_name
);
1271 msi_create_full_path( package
, dst_path
);
1273 msi_free( dst_name
);
1274 msi_free( dst_path
);
1278 static UINT
ITERATE_DuplicateFiles(MSIRECORD
*row
, LPVOID param
)
1280 MSIPACKAGE
*package
= param
;
1282 LPCWSTR file_key
, component
;
1287 component
= MSI_RecordGetString(row
,2);
1288 comp
= msi_get_loaded_component(package
, component
);
1290 return ERROR_SUCCESS
;
1292 comp
->Action
= msi_get_component_action( package
, comp
);
1293 if (comp
->Action
!= INSTALLSTATE_LOCAL
)
1295 TRACE("component not scheduled for installation %s\n", debugstr_w(component
));
1296 return ERROR_SUCCESS
;
1299 file_key
= MSI_RecordGetString(row
,3);
1302 ERR("Unable to get file key\n");
1303 return ERROR_FUNCTION_FAILED
;
1306 file
= msi_get_loaded_file( package
, file_key
);
1309 ERR("Original file unknown %s\n", debugstr_w(file_key
));
1310 return ERROR_SUCCESS
;
1313 dest
= get_duplicate_filename( package
, row
, file_key
, file
->TargetPath
);
1316 WARN("Unable to get duplicate filename\n");
1317 return ERROR_SUCCESS
;
1320 TRACE("Duplicating file %s to %s\n", debugstr_w(file
->TargetPath
), debugstr_w(dest
));
1321 if (!msi_copy_file( package
, file
->TargetPath
, dest
, TRUE
))
1323 WARN("Failed to copy file %s -> %s (%u)\n",
1324 debugstr_w(file
->TargetPath
), debugstr_w(dest
), GetLastError());
1326 FIXME("We should track these duplicate files as well\n");
1328 uirow
= MSI_CreateRecord( 9 );
1329 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString( row
, 1 ) );
1330 MSI_RecordSetInteger( uirow
, 6, file
->FileSize
);
1331 MSI_RecordSetStringW( uirow
, 9, MSI_RecordGetString( row
, 5 ) );
1332 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1333 msiobj_release( &uirow
->hdr
);
1336 return ERROR_SUCCESS
;
1339 UINT
ACTION_DuplicateFiles(MSIPACKAGE
*package
)
1341 static const WCHAR query
[] = {
1342 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1343 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
1347 if (package
->script
== SCRIPT_NONE
)
1348 return msi_schedule_action(package
, SCRIPT_INSTALL
, szDuplicateFiles
);
1350 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
1351 if (rc
!= ERROR_SUCCESS
)
1352 return ERROR_SUCCESS
;
1354 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_DuplicateFiles
, package
);
1355 msiobj_release(&view
->hdr
);
1359 static UINT
ITERATE_RemoveDuplicateFiles( MSIRECORD
*row
, LPVOID param
)
1361 MSIPACKAGE
*package
= param
;
1363 LPCWSTR file_key
, component
;
1368 component
= MSI_RecordGetString( row
, 2 );
1369 comp
= msi_get_loaded_component( package
, component
);
1371 return ERROR_SUCCESS
;
1373 comp
->Action
= msi_get_component_action( package
, comp
);
1374 if (comp
->Action
!= INSTALLSTATE_ABSENT
)
1376 TRACE("component not scheduled for removal %s\n", debugstr_w(component
));
1377 return ERROR_SUCCESS
;
1380 file_key
= MSI_RecordGetString( row
, 3 );
1383 ERR("Unable to get file key\n");
1384 return ERROR_FUNCTION_FAILED
;
1387 file
= msi_get_loaded_file( package
, file_key
);
1390 ERR("Original file unknown %s\n", debugstr_w(file_key
));
1391 return ERROR_SUCCESS
;
1394 dest
= get_duplicate_filename( package
, row
, file_key
, file
->TargetPath
);
1397 WARN("Unable to get duplicate filename\n");
1398 return ERROR_SUCCESS
;
1401 TRACE("Removing duplicate %s of %s\n", debugstr_w(dest
), debugstr_w(file
->TargetPath
));
1402 if (!msi_delete_file( package
, dest
))
1404 WARN("Failed to delete duplicate file %s (%u)\n", debugstr_w(dest
), GetLastError());
1407 uirow
= MSI_CreateRecord( 9 );
1408 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString( row
, 1 ) );
1409 MSI_RecordSetStringW( uirow
, 9, MSI_RecordGetString( row
, 5 ) );
1410 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1411 msiobj_release( &uirow
->hdr
);
1414 return ERROR_SUCCESS
;
1417 UINT
ACTION_RemoveDuplicateFiles( MSIPACKAGE
*package
)
1419 static const WCHAR query
[] = {
1420 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1421 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
1425 if (package
->script
== SCRIPT_NONE
)
1426 return msi_schedule_action(package
, SCRIPT_INSTALL
, szRemoveDuplicateFiles
);
1428 rc
= MSI_DatabaseOpenViewW( package
->db
, query
, &view
);
1429 if (rc
!= ERROR_SUCCESS
)
1430 return ERROR_SUCCESS
;
1432 rc
= MSI_IterateRecords( view
, NULL
, ITERATE_RemoveDuplicateFiles
, package
);
1433 msiobj_release( &view
->hdr
);
1437 static BOOL
verify_comp_for_removal(MSICOMPONENT
*comp
, UINT install_mode
)
1440 if (comp
->Action
!= INSTALLSTATE_SOURCE
&&
1441 comp
->Attributes
& msidbComponentAttributesSourceOnly
&&
1442 (install_mode
== msidbRemoveFileInstallModeOnRemove
||
1443 install_mode
== msidbRemoveFileInstallModeOnBoth
)) return TRUE
;
1445 switch (comp
->Action
)
1447 case INSTALLSTATE_LOCAL
:
1448 case INSTALLSTATE_SOURCE
:
1449 if (install_mode
== msidbRemoveFileInstallModeOnInstall
||
1450 install_mode
== msidbRemoveFileInstallModeOnBoth
) return TRUE
;
1452 case INSTALLSTATE_ABSENT
:
1453 if (install_mode
== msidbRemoveFileInstallModeOnRemove
||
1454 install_mode
== msidbRemoveFileInstallModeOnBoth
) return TRUE
;
1461 static UINT
ITERATE_RemoveFiles(MSIRECORD
*row
, LPVOID param
)
1463 MSIPACKAGE
*package
= param
;
1466 LPCWSTR component
, dirprop
;
1468 LPWSTR dir
= NULL
, path
= NULL
, filename
= NULL
;
1470 UINT ret
= ERROR_SUCCESS
;
1472 component
= MSI_RecordGetString(row
, 2);
1473 dirprop
= MSI_RecordGetString(row
, 4);
1474 install_mode
= MSI_RecordGetInteger(row
, 5);
1476 comp
= msi_get_loaded_component(package
, component
);
1478 return ERROR_SUCCESS
;
1480 comp
->Action
= msi_get_component_action( package
, comp
);
1481 if (!verify_comp_for_removal(comp
, install_mode
))
1483 TRACE("Skipping removal due to install mode\n");
1484 return ERROR_SUCCESS
;
1486 if (comp
->assembly
&& !comp
->assembly
->application
)
1488 return ERROR_SUCCESS
;
1490 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
1492 TRACE("permanent component, not removing file\n");
1493 return ERROR_SUCCESS
;
1496 dir
= msi_dup_property(package
->db
, dirprop
);
1499 WARN("directory property has no value\n");
1500 return ERROR_SUCCESS
;
1503 if ((filename
= strdupW( MSI_RecordGetString(row
, 3) )))
1505 msi_reduce_to_long_filename( filename
);
1506 size
= lstrlenW( filename
);
1508 size
+= lstrlenW(dir
) + 2;
1509 path
= msi_alloc(size
* sizeof(WCHAR
));
1512 ret
= ERROR_OUTOFMEMORY
;
1518 lstrcpyW(path
, dir
);
1519 PathAddBackslashW(path
);
1520 lstrcatW(path
, filename
);
1522 TRACE("Deleting misc file: %s\n", debugstr_w(path
));
1523 msi_delete_file( package
, path
);
1527 TRACE("Removing misc directory: %s\n", debugstr_w(dir
));
1528 msi_remove_directory( package
, dir
);
1532 uirow
= MSI_CreateRecord( 9 );
1533 MSI_RecordSetStringW( uirow
, 1, MSI_RecordGetString(row
, 1) );
1534 MSI_RecordSetStringW( uirow
, 9, dir
);
1535 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1536 msiobj_release( &uirow
->hdr
);
1544 static void remove_folder( MSIFOLDER
*folder
)
1548 LIST_FOR_EACH_ENTRY( fl
, &folder
->children
, FolderList
, entry
)
1550 remove_folder( fl
->folder
);
1552 if (!folder
->persistent
&& folder
->State
!= FOLDER_STATE_REMOVED
)
1554 if (RemoveDirectoryW( folder
->ResolvedTarget
)) folder
->State
= FOLDER_STATE_REMOVED
;
1558 UINT
ACTION_RemoveFiles( MSIPACKAGE
*package
)
1560 static const WCHAR query
[] = {
1561 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1562 '`','R','e','m','o','v','e','F','i','l','e','`',0};
1568 if (package
->script
== SCRIPT_NONE
)
1569 return msi_schedule_action(package
, SCRIPT_INSTALL
, szRemoveFiles
);
1571 r
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
1572 if (r
== ERROR_SUCCESS
)
1574 r
= MSI_IterateRecords(view
, NULL
, ITERATE_RemoveFiles
, package
);
1575 msiobj_release(&view
->hdr
);
1576 if (r
!= ERROR_SUCCESS
)
1580 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
1583 VS_FIXEDFILEINFO
*ver
;
1585 comp
= file
->Component
;
1586 msi_file_update_ui( package
, file
, szRemoveFiles
);
1588 comp
->Action
= msi_get_component_action( package
, comp
);
1589 if (comp
->Action
!= INSTALLSTATE_ABSENT
|| comp
->Installed
== INSTALLSTATE_SOURCE
)
1592 if (comp
->assembly
&& !comp
->assembly
->application
)
1595 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
1597 TRACE("permanent component, not removing file\n");
1603 ver
= msi_get_disk_file_version( package
, file
->TargetPath
);
1604 if (ver
&& msi_compare_file_versions( ver
, file
->Version
) > 0)
1606 TRACE("newer version detected, not removing file\n");
1613 if (file
->state
== msifs_installed
)
1614 WARN("removing installed file %s\n", debugstr_w(file
->TargetPath
));
1616 TRACE("removing %s\n", debugstr_w(file
->File
) );
1618 msi_set_file_attributes( package
, file
->TargetPath
, FILE_ATTRIBUTE_NORMAL
);
1619 if (!msi_delete_file( package
, file
->TargetPath
))
1621 WARN("failed to delete %s (%u)\n", debugstr_w(file
->TargetPath
), GetLastError());
1623 file
->state
= msifs_missing
;
1625 uirow
= MSI_CreateRecord( 9 );
1626 MSI_RecordSetStringW( uirow
, 1, file
->FileName
);
1627 MSI_RecordSetStringW( uirow
, 9, comp
->Directory
);
1628 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1629 msiobj_release( &uirow
->hdr
);
1632 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
1634 comp
->Action
= msi_get_component_action( package
, comp
);
1635 if (comp
->Action
!= INSTALLSTATE_ABSENT
) continue;
1637 if (comp
->Attributes
& msidbComponentAttributesPermanent
)
1639 TRACE("permanent component, not removing directory\n");
1642 if (comp
->assembly
&& !comp
->assembly
->application
)
1643 msi_uninstall_assembly( package
, comp
);
1646 MSIFOLDER
*folder
= msi_get_loaded_folder( package
, comp
->Directory
);
1647 if (folder
) remove_folder( folder
);
1650 return ERROR_SUCCESS
;