ReactOS 0.4.16-dev-340-g0540c21
files.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "fdi.h"
#include "msi.h"
#include "msidefs.h"
#include "msipriv.h"
#include "winuser.h"
#include "winreg.h"
#include "shlwapi.h"
#include "patchapi.h"
#include "wine/debug.h"
Include dependency graph for files.c:

Go to the source code of this file.

Classes

struct  file_list
 

Macros

#define COBJMACROS
 
#define is_dot_dir(x)   ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (msi)
 
BOOL msi_get_temp_file_name (MSIPACKAGE *package, const WCHAR *tmp_path, const WCHAR *prefix, WCHAR *tmp_filename)
 
HANDLE msi_create_file (MSIPACKAGE *package, const WCHAR *filename, DWORD access, DWORD sharing, DWORD creation, DWORD flags)
 
static BOOL copy_file (MSIPACKAGE *package, const WCHAR *src, const WCHAR *dst, BOOL fail_if_exists)
 
BOOL msi_delete_file (MSIPACKAGE *package, const WCHAR *filename)
 
static BOOL create_directory (MSIPACKAGE *package, const WCHAR *path)
 
BOOL msi_remove_directory (MSIPACKAGE *package, const WCHAR *path)
 
BOOL msi_set_file_attributes (MSIPACKAGE *package, const WCHAR *filename, DWORD attrs)
 
DWORD msi_get_file_attributes (MSIPACKAGE *package, const WCHAR *path)
 
HANDLE msi_find_first_file (MSIPACKAGE *package, const WCHAR *filename, WIN32_FIND_DATAW *data)
 
BOOL msi_find_next_file (MSIPACKAGE *package, HANDLE handle, WIN32_FIND_DATAW *data)
 
BOOL msi_move_file (MSIPACKAGE *package, const WCHAR *from, const WCHAR *to, DWORD flags)
 
static BOOL apply_filepatch (MSIPACKAGE *package, const WCHAR *patch, const WCHAR *old, const WCHAR *new)
 
DWORD msi_get_file_version_info (MSIPACKAGE *package, const WCHAR *path, DWORD buflen, BYTE *buffer)
 
VS_FIXEDFILEINFOmsi_get_disk_file_version (MSIPACKAGE *package, const WCHAR *filename)
 
DWORD msi_get_disk_file_size (MSIPACKAGE *package, const WCHAR *filename)
 
BOOL msi_create_full_path (MSIPACKAGE *package, const WCHAR *path)
 
static void file_update_ui (MSIPACKAGE *package, MSIFILE *f, const WCHAR *action)
 
static BOOL is_registered_patch_media (MSIPACKAGE *package, UINT disk_id)
 
static BOOL is_obsoleted_by_patch (MSIPACKAGE *package, MSIFILE *file)
 
static BOOL file_hash_matches (MSIPACKAGE *package, MSIFILE *file)
 
static msi_file_state calculate_install_state (MSIPACKAGE *package, MSIFILE *file)
 
static void schedule_install_files (MSIPACKAGE *package)
 
static UINT copy_file_attributes (MSIPACKAGE *package, MSIFILE *file, WCHAR *source)
 
static UINT copy_install_file (MSIPACKAGE *package, MSIFILE *file, LPWSTR source)
 
static UINT create_folder (MSIPACKAGE *package, const WCHAR *dir)
 
static MSIFILEfind_file (MSIPACKAGE *package, UINT disk_id, const WCHAR *filename)
 
static BOOL installfiles_cb (MSIPACKAGE *package, LPCWSTR filename, DWORD action, LPWSTR *path, DWORD *attrs, PVOID user)
 
WCHARmsi_resolve_file_source (MSIPACKAGE *package, MSIFILE *file)
 
UINT ACTION_InstallFiles (MSIPACKAGE *package)
 
static MSIFILEPATCHfind_filepatch (MSIPACKAGE *package, UINT disk_id, const WCHAR *key)
 
static BOOL patchfiles_cb (MSIPACKAGE *package, LPCWSTR file, DWORD action, LPWSTR *path, DWORD *attrs, PVOID user)
 
static UINT patch_file (MSIPACKAGE *package, MSIFILEPATCH *patch)
 
UINT msi_patch_assembly (MSIPACKAGE *package, MSIASSEMBLY *assembly, MSIFILEPATCH *patch)
 
UINT ACTION_PatchFiles (MSIPACKAGE *package)
 
static BOOL move_file (MSIPACKAGE *package, const WCHAR *source, const WCHAR *dest, int options)
 
static WCHARwildcard_to_file (const WCHAR *wildcard, const WCHAR *filename)
 
static void free_file_entry (struct file_list *file)
 
static void free_list (struct file_list *list)
 
static BOOL add_wildcard (struct file_list *files, const WCHAR *source, WCHAR *dest)
 
static BOOL move_files_wildcard (MSIPACKAGE *package, const WCHAR *source, WCHAR *dest, int options)
 
void msi_reduce_to_long_filename (WCHAR *filename)
 
static UINT ITERATE_MoveFiles (MSIRECORD *rec, LPVOID param)
 
UINT ACTION_MoveFiles (MSIPACKAGE *package)
 
static WCHARget_duplicate_filename (MSIPACKAGE *package, MSIRECORD *row, const WCHAR *file_key, const WCHAR *src)
 
static UINT ITERATE_DuplicateFiles (MSIRECORD *row, LPVOID param)
 
UINT ACTION_DuplicateFiles (MSIPACKAGE *package)
 
static UINT ITERATE_RemoveDuplicateFiles (MSIRECORD *row, LPVOID param)
 
UINT ACTION_RemoveDuplicateFiles (MSIPACKAGE *package)
 
static BOOL verify_comp_for_removal (MSICOMPONENT *comp, UINT install_mode)
 
static UINT ITERATE_RemoveFiles (MSIRECORD *row, LPVOID param)
 
static void remove_folder (MSIFOLDER *folder)
 
UINT ACTION_RemoveFiles (MSIPACKAGE *package)
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 34 of file files.c.

◆ is_dot_dir

#define is_dot_dir (   x)    ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))

Definition at line 852 of file files.c.

Function Documentation

◆ ACTION_DuplicateFiles()

UINT ACTION_DuplicateFiles ( MSIPACKAGE package)

Definition at line 1315 of file files.c.

1316{
1317 MSIQUERY *view;
1318 UINT rc;
1319
1320 if (package->script == SCRIPT_NONE)
1321 return msi_schedule_action(package, SCRIPT_INSTALL, L"DuplicateFiles");
1322
1323 rc = MSI_DatabaseOpenViewW(package->db, L"SELECT * FROM `DuplicateFile`", &view);
1324 if (rc != ERROR_SUCCESS)
1325 return ERROR_SUCCESS;
1326
1328 msiobj_release(&view->hdr);
1329 return rc;
1330}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
UINT msi_schedule_action(MSIPACKAGE *package, UINT script, const WCHAR *action)
Definition: custom.c:90
static UINT ITERATE_DuplicateFiles(MSIRECORD *row, LPVOID param)
Definition: files.c:1254
int msiobj_release(MSIOBJECTHDR *info)
Definition: handle.c:241
@ SCRIPT_INSTALL
Definition: msipriv.h:385
@ SCRIPT_NONE
Definition: msipriv.h:384
UINT MSI_DatabaseOpenViewW(MSIDATABASE *, LPCWSTR, MSIQUERY **)
UINT MSI_IterateRecords(MSIQUERY *, LPDWORD, record_func, LPVOID)
Definition: msiquery.c:163
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
MSIDATABASE * db
Definition: msipriv.h:394
enum script script
Definition: msipriv.h:432

◆ ACTION_InstallFiles()

UINT ACTION_InstallFiles ( MSIPACKAGE package)

Definition at line 564 of file files.c.

565{
567 UINT rc = ERROR_SUCCESS;
568 MSIFILE *file;
569
571
572 if (package->script == SCRIPT_NONE)
573 return msi_schedule_action(package, SCRIPT_INSTALL, L"InstallFiles");
574
575 schedule_install_files(package);
576 mi = calloc(1, sizeof(MSIMEDIAINFO));
577
579 {
580 BOOL is_global_assembly = msi_is_global_assembly( file->Component );
581
582 file_update_ui( package, file, L"InstallFiles" );
583
584 rc = msi_load_media_info( package, file->Sequence, mi );
585 if (rc != ERROR_SUCCESS)
586 {
587 ERR("Unable to load media info for %s (%u)\n", debugstr_w(file->File), rc);
589 goto done;
590 }
591
592 if (file->state != msifs_hashmatch &&
593 file->state != msifs_skipped &&
594 (file->state != msifs_present || !msi_get_property_int( package->db, L"Installed", 0 )) &&
595 (rc = ready_media( package, file->IsCompressed, mi )))
596 {
597 ERR("Failed to ready media for %s\n", debugstr_w(file->File));
598 goto done;
599 }
600
601 if (file->state != msifs_missing && !mi->is_continuous && file->state != msifs_overwrite)
602 continue;
603
604 if (file->Sequence > mi->last_sequence || mi->is_continuous ||
605 (file->IsCompressed && !mi->is_extracted))
606 {
609
610 data.mi = mi;
611 data.package = package;
613 data.user = &cursor;
614
615 if (file->IsCompressed && !msi_cabextract(package, mi, &data))
616 {
617 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi->cabinet));
619 goto done;
620 }
621 }
622
623 if (!file->IsCompressed)
624 {
626
627 TRACE("copying %s to %s\n", debugstr_w(source), debugstr_w(file->TargetPath));
628
629 if (!is_global_assembly)
630 {
631 create_folder(package, file->Component->Directory);
632 }
633 rc = copy_install_file(package, file, source);
634 if (rc != ERROR_SUCCESS)
635 {
636 ERR("Failed to copy %s to %s (%u)\n", debugstr_w(source), debugstr_w(file->TargetPath), rc);
638 free(source);
639 goto done;
640 }
641 if (!is_global_assembly) file->state = msifs_installed;
642 free(source);
643 }
644 else if (!is_global_assembly && file->state != msifs_installed &&
645 !(file->Attributes & msidbFileAttributesPatchAdded))
646 {
647 ERR("compressed file wasn't installed (%s)\n", debugstr_w(file->File));
649 goto done;
650 }
651 }
652
653done:
655 return rc;
656}
#define ERR(fmt,...)
Definition: precomp.h:57
#define free
Definition: debug_ros.c:5
#define FALSE
Definition: types.h:117
BOOL msi_is_global_assembly(MSICOMPONENT *comp)
Definition: action.c:2036
UINT msi_set_sourcedir_props(MSIPACKAGE *package, BOOL replace)
Definition: action.c:352
WCHAR * msi_resolve_file_source(MSIPACKAGE *package, MSIFILE *file)
Definition: files.c:536
static BOOL installfiles_cb(MSIPACKAGE *package, LPCWSTR filename, DWORD action, LPWSTR *path, DWORD *attrs, PVOID user)
Definition: files.c:505
static void schedule_install_files(MSIPACKAGE *package)
Definition: files.c:387
static UINT copy_install_file(MSIPACKAGE *package, MSIFILE *file, LPWSTR source)
Definition: files.c:416
static void file_update_ui(MSIPACKAGE *package, MSIFILE *f, const WCHAR *action)
Definition: files.c:251
static UINT create_folder(MSIPACKAGE *package, const WCHAR *dir)
Definition: files.c:475
UINT ready_media(MSIPACKAGE *package, BOOL compressed, MSIMEDIAINFO *mi)
Definition: media.c:838
void msi_free_media_info(MSIMEDIAINFO *mi)
Definition: media.c:649
BOOL msi_cabextract(MSIPACKAGE *package, MSIMEDIAINFO *mi, LPVOID data)
Definition: media.c:640
UINT msi_load_media_info(MSIPACKAGE *package, UINT Sequence, MSIMEDIAINFO *mi)
Definition: media.c:677
unsigned int BOOL
Definition: ntddk_ex.h:94
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
const char cursor[]
Definition: icontest.c:13
uint32_t entry
Definition: isohybrid.c:63
#define debugstr_w
Definition: kernel32.h:32
@ msidbFileAttributesPatchAdded
Definition: msidefs.h:37
int msi_get_property_int(MSIDATABASE *package, LPCWSTR prop, int def)
Definition: package.c:2305
@ msifs_missing
Definition: msipriv.h:595
@ msifs_skipped
Definition: msipriv.h:599
@ msifs_installed
Definition: msipriv.h:598
@ msifs_present
Definition: msipriv.h:597
@ msifs_hashmatch
Definition: msipriv.h:600
@ msifs_overwrite
Definition: msipriv.h:596
#define calloc
Definition: rosglue.h:14
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define TRACE(s)
Definition: solgame.cpp:4
Definition: fci.c:127
struct list files
Definition: msipriv.h:403
static MONITORINFO mi
Definition: win.c:7338
#define ERROR_INSTALL_FAILURE
Definition: winerror.h:961
#define ERROR_FUNCTION_FAILED
Definition: winerror.h:985
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ ACTION_MoveFiles()

UINT ACTION_MoveFiles ( MSIPACKAGE package)

Definition at line 1185 of file files.c.

1186{
1187 MSIQUERY *view;
1188 UINT rc;
1189
1190 if (package->script == SCRIPT_NONE)
1191 return msi_schedule_action(package, SCRIPT_INSTALL, L"MoveFiles");
1192
1193 rc = MSI_DatabaseOpenViewW(package->db, L"SELECT * FROM `MoveFile`", &view);
1194 if (rc != ERROR_SUCCESS)
1195 return ERROR_SUCCESS;
1196
1198 msiobj_release(&view->hdr);
1199 return rc;
1200}
static UINT ITERATE_MoveFiles(MSIRECORD *rec, LPVOID param)
Definition: files.c:1059

◆ ACTION_PatchFiles()

UINT ACTION_PatchFiles ( MSIPACKAGE package)

Definition at line 776 of file files.c.

777{
778 MSIFILEPATCH *patch;
780 UINT rc = ERROR_SUCCESS;
781
782 TRACE("%p\n", package);
783
784 if (package->script == SCRIPT_NONE)
785 return msi_schedule_action(package, SCRIPT_INSTALL, L"PatchFiles");
786
787 mi = calloc( 1, sizeof(MSIMEDIAINFO) );
788
789 TRACE("extracting files\n");
790
792 {
793 MSIFILE *file = patch->File;
794 MSICOMPONENT *comp = file->Component;
795
796 rc = msi_load_media_info( package, patch->Sequence, mi );
797 if (rc != ERROR_SUCCESS)
798 {
799 ERR("Unable to load media info for %s (%u)\n", debugstr_w(file->File), rc);
801 goto done;
802 }
803 comp->Action = msi_get_component_action( package, comp );
804 if (!comp->Enabled || comp->Action != INSTALLSTATE_LOCAL) continue;
805
806 if (!patch->extracted)
807 {
809 MSIFILEPATCH *cursor = patch;
810
811 rc = ready_media( package, TRUE, mi );
812 if (rc != ERROR_SUCCESS)
813 {
814 ERR("Failed to ready media for %s\n", debugstr_w(file->File));
815 goto done;
816 }
817 data.mi = mi;
818 data.package = package;
819 data.cb = patchfiles_cb;
820 data.user = &cursor;
821
822 if (!msi_cabextract( package, mi, &data ))
823 {
824 ERR("Failed to extract cabinet: %s\n", debugstr_w(mi->cabinet));
826 goto done;
827 }
828 }
829 }
830
831 TRACE("applying patches\n");
832
834 {
835 MSICOMPONENT *comp = patch->File->Component;
836
837 if (msi_is_global_assembly( comp ) || !patch->path) continue;
838
839 rc = patch_file( package, patch );
840 if (rc && !(patch->Attributes & msidbPatchAttributesNonVital))
841 {
842 ERR("Failed to apply patch to file: %s\n", debugstr_w(patch->File->File));
843 break;
844 }
845 }
846
847done:
849 return rc;
850}
#define TRUE
Definition: types.h:120
INSTALLSTATE msi_get_component_action(MSIPACKAGE *package, MSICOMPONENT *comp)
Definition: action.c:609
static UINT patch_file(MSIPACKAGE *package, MSIFILEPATCH *patch)
Definition: files.c:704
static BOOL patchfiles_cb(MSIPACKAGE *package, LPCWSTR file, DWORD action, LPWSTR *path, DWORD *attrs, PVOID user)
Definition: files.c:670
@ INSTALLSTATE_LOCAL
Definition: msi.h:46
@ msidbPatchAttributesNonVital
Definition: msidefs.h:43
INSTALLSTATE Action
Definition: msipriv.h:532
MSIFILE * File
Definition: msipriv.h:626
BOOL extracted
Definition: msipriv.h:630
WCHAR * path
Definition: msipriv.h:632
LPWSTR File
Definition: msipriv.h:606
MSICOMPONENT * Component
Definition: msipriv.h:607
struct list filepatches
Definition: msipriv.h:404

◆ ACTION_RemoveDuplicateFiles()

UINT ACTION_RemoveDuplicateFiles ( MSIPACKAGE package)

Definition at line 1390 of file files.c.

1391{
1392 MSIQUERY *view;
1393 UINT rc;
1394
1395 if (package->script == SCRIPT_NONE)
1396 return msi_schedule_action(package, SCRIPT_INSTALL, L"RemoveDuplicateFiles");
1397
1398 rc = MSI_DatabaseOpenViewW( package->db, L"SELECT * FROM `DuplicateFile`", &view );
1399 if (rc != ERROR_SUCCESS)
1400 return ERROR_SUCCESS;
1401
1403 msiobj_release( &view->hdr );
1404 return rc;
1405}
static UINT ITERATE_RemoveDuplicateFiles(MSIRECORD *row, LPVOID param)
Definition: files.c:1332

◆ ACTION_RemoveFiles()

UINT ACTION_RemoveFiles ( MSIPACKAGE package)

Definition at line 1528 of file files.c.

1529{
1530 MSIQUERY *view;
1531 MSICOMPONENT *comp;
1532 MSIFILE *file;
1533 UINT r;
1534
1535 if (package->script == SCRIPT_NONE)
1536 return msi_schedule_action(package, SCRIPT_INSTALL, L"RemoveFiles");
1537
1538 r = MSI_DatabaseOpenViewW(package->db, L"SELECT * FROM `RemoveFile`", &view);
1539 if (r == ERROR_SUCCESS)
1540 {
1542 msiobj_release(&view->hdr);
1543 if (r != ERROR_SUCCESS)
1544 return r;
1545 }
1546
1548 {
1549 MSIRECORD *uirow;
1550 VS_FIXEDFILEINFO *ver;
1551
1552 comp = file->Component;
1553 file_update_ui( package, file, L"RemoveFiles" );
1554
1555 comp->Action = msi_get_component_action( package, comp );
1557 continue;
1558
1559 if (comp->assembly && !comp->assembly->application)
1560 continue;
1561
1563 {
1564 TRACE("permanent component, not removing file\n");
1565 continue;
1566 }
1567
1568 if (file->Version)
1569 {
1570 ver = msi_get_disk_file_version( package, file->TargetPath );
1571 if (ver && msi_compare_file_versions( ver, file->Version ) > 0)
1572 {
1573 TRACE("newer version detected, not removing file\n");
1574 free( ver );
1575 continue;
1576 }
1577 free( ver );
1578 }
1579
1580 if (file->state == msifs_installed)
1581 WARN("removing installed file %s\n", debugstr_w(file->TargetPath));
1582
1583 TRACE("removing %s\n", debugstr_w(file->File) );
1584
1585 msi_set_file_attributes( package, file->TargetPath, FILE_ATTRIBUTE_NORMAL );
1586 if (!msi_delete_file( package, file->TargetPath ))
1587 {
1588 WARN( "failed to delete %s (%lu)\n", debugstr_w(file->TargetPath), GetLastError() );
1589 }
1590 file->state = msifs_missing;
1591
1592 uirow = MSI_CreateRecord( 9 );
1593 MSI_RecordSetStringW( uirow, 1, file->FileName );
1594 MSI_RecordSetStringW( uirow, 9, comp->Directory );
1596 msiobj_release( &uirow->hdr );
1597 }
1598
1600 {
1601 comp->Action = msi_get_component_action( package, comp );
1602 if (comp->Action != INSTALLSTATE_ABSENT) continue;
1603
1605 {
1606 TRACE("permanent component, not removing directory\n");
1607 continue;
1608 }
1609 if (comp->assembly && !comp->assembly->application)
1610 msi_uninstall_assembly( package, comp );
1611 else
1612 {
1613 MSIFOLDER *folder = msi_get_loaded_folder( package, comp->Directory );
1614 if (folder) remove_folder( folder );
1615 }
1616 }
1617 return ERROR_SUCCESS;
1618}
#define WARN(fmt,...)
Definition: precomp.h:61
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
int msi_compare_file_versions(VS_FIXEDFILEINFO *fi, const WCHAR *version)
Definition: action.c:1929
MSIFOLDER * msi_get_loaded_folder(MSIPACKAGE *package, const WCHAR *dir)
Definition: action.c:583
BOOL msi_set_file_attributes(MSIPACKAGE *package, const WCHAR *filename, DWORD attrs)
Definition: files.c:106
BOOL msi_delete_file(MSIPACKAGE *package, const WCHAR *filename)
Definition: files.c:79
VS_FIXEDFILEINFO * msi_get_disk_file_version(MSIPACKAGE *package, const WCHAR *filename)
Definition: files.c:170
static UINT ITERATE_RemoveFiles(MSIRECORD *row, LPVOID param)
Definition: files.c:1431
static void remove_folder(MSIFOLDER *folder)
Definition: files.c:1514
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
UINT msi_uninstall_assembly(MSIPACKAGE *package, MSICOMPONENT *comp)
Definition: assembly.c:402
@ INSTALLMESSAGE_ACTIONDATA
Definition: msi.h:103
@ INSTALLSTATE_ABSENT
Definition: msi.h:45
@ INSTALLSTATE_SOURCE
Definition: msi.h:47
@ msidbComponentAttributesPermanent
Definition: msidefs.h:164
INT MSI_ProcessMessage(MSIPACKAGE *, INSTALLMESSAGE, MSIRECORD *)
Definition: package.c:1909
UINT MSI_RecordSetStringW(MSIRECORD *, UINT, LPCWSTR)
Definition: record.c:597
MSIRECORD * MSI_CreateRecord(UINT)
Definition: record.c:76
Definition: fci.c:116
LPWSTR application
Definition: msipriv.h:514
MSIASSEMBLY * assembly
Definition: msipriv.h:540
INSTALLSTATE Installed
Definition: msipriv.h:530
LPWSTR Directory
Definition: msipriv.h:526
struct list components
Definition: msipriv.h:401
MSIOBJECTHDR hdr
Definition: msipriv.h:151
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

◆ add_wildcard()

static BOOL add_wildcard ( struct file_list files,
const WCHAR source,
WCHAR dest 
)
static

Definition at line 934 of file files.c.

935{
936 struct file_list *new, *file;
937 WCHAR *ptr, *filename;
938 DWORD size;
939
940 new = calloc(1, sizeof(*new));
941 if (!new)
942 return FALSE;
943
944 new->source = wcsdup(source);
945 ptr = wcsrchr(dest, '\\') + 1;
946 filename = wcsrchr(new->source, '\\') + 1;
947
948 new->sourcename = filename;
949
950 if (*ptr)
951 new->destname = ptr;
952 else
953 new->destname = new->sourcename;
954
955 size = (ptr - dest) + lstrlenW(filename) + 1;
956 new->dest = malloc(size * sizeof(WCHAR));
957 if (!new->dest)
958 {
959 free_file_entry(new);
960 return FALSE;
961 }
962
963 lstrcpynW(new->dest, dest, ptr - dest + 1);
964 lstrcatW(new->dest, filename);
965
966 if (list_empty(&files->entry))
967 {
968 list_add_head(&files->entry, &new->entry);
969 return TRUE;
970 }
971
972 LIST_FOR_EACH_ENTRY(file, &files->entry, struct file_list, entry)
973 {
974 if (wcscmp( source, file->source ) < 0)
975 {
976 list_add_before(&file->entry, &new->entry);
977 return TRUE;
978 }
979 }
980
981 list_add_after(&file->entry, &new->entry);
982 return TRUE;
983}
static int list_empty(struct list_entry *head)
Definition: list.h:58
static void list_add_head(struct list_entry *head, struct list_entry *entry)
Definition: list.h:76
#define malloc
Definition: debug_ros.c:4
#define wcsrchr
Definition: compat.h:16
#define lstrcpynW
Definition: compat.h:738
#define lstrlenW
Definition: compat.h:750
static void free_file_entry(struct file_list *file)
Definition: files.c:916
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
const char * filename
Definition: ioapi.h:137
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
static PVOID ptr
Definition: dispmode.c:27
static char * dest
Definition: rtl.c:135
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_Check_return_ _CRTIMP wchar_t *__cdecl wcsdup(_In_z_ const wchar_t *_Str)
__WINE_SERVER_LIST_INLINE void list_add_before(struct list *elem, struct list *to_add)
Definition: list.h:87
__WINE_SERVER_LIST_INLINE void list_add_after(struct list *elem, struct list *to_add)
Definition: list.h:78
struct list entry
Definition: files.c:856
struct list entry
Definition: fci.c:128
#define new(TYPE, numElems)
Definition: treelist.c:54

Referenced by move_files_wildcard().

◆ apply_filepatch()

static BOOL apply_filepatch ( MSIPACKAGE package,
const WCHAR patch,
const WCHAR old,
const WCHAR new 
)
static

Definition at line 151 of file files.c.

152{
153 BOOL ret;
155 ret = ApplyPatchToFileW( patch, old, new, 0 );
156 msi_revert_fs_redirection( package );
157 return ret;
158}
static void msi_revert_fs_redirection(MSIPACKAGE *package)
Definition: msipriv.h:1076
static void msi_disable_fs_redirection(MSIPACKAGE *package)
Definition: msipriv.h:1072
BOOL WINAPI ApplyPatchToFileW(LPCWSTR patch_file, LPCWSTR old_file, LPCWSTR new_file, ULONG apply_flags)
int ret

Referenced by patch_file().

◆ calculate_install_state()

static msi_file_state calculate_install_state ( MSIPACKAGE package,
MSIFILE file 
)
static

Definition at line 299 of file files.c.

300{
301 MSICOMPONENT *comp = file->Component;
302 VS_FIXEDFILEINFO *file_version;
303 WCHAR *font_version;
305 DWORD size;
306
307 comp->Action = msi_get_component_action( package, comp );
308 if (!comp->Enabled || comp->Action != INSTALLSTATE_LOCAL)
309 {
310 TRACE("skipping %s (not scheduled for install)\n", debugstr_w(file->File));
311 return msifs_skipped;
312 }
313 if (is_obsoleted_by_patch( package, file ))
314 {
315 TRACE("skipping %s (obsoleted by patch)\n", debugstr_w(file->File));
316 return msifs_skipped;
317 }
318 if (msi_get_file_attributes( package, file->TargetPath ) == INVALID_FILE_ATTRIBUTES)
319 {
320 TRACE("installing %s (missing)\n", debugstr_w(file->File));
321 return msifs_missing;
322 }
323 if (file->Version)
324 {
325 if ((file_version = msi_get_disk_file_version( package, file->TargetPath )))
326 {
327 if (msi_compare_file_versions( file_version, file->Version ) < 0)
328 {
329 TRACE("overwriting %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));
334 }
335 else
336 {
337 TRACE("keeping %s (new version %s old version %u.%u.%u.%u)\n",
338 debugstr_w(file->File), debugstr_w(file->Version),
339 HIWORD(file_version->dwFileVersionMS), LOWORD(file_version->dwFileVersionMS),
340 HIWORD(file_version->dwFileVersionLS), LOWORD(file_version->dwFileVersionLS));
342 }
343 free( file_version );
344 return state;
345 }
346 else if ((font_version = msi_get_font_file_version( package, file->TargetPath )))
347 {
348 if (msi_compare_font_versions( font_version, file->Version ) < 0)
349 {
350 TRACE("overwriting %s (new version %s old version %s)\n",
351 debugstr_w(file->File), debugstr_w(file->Version), debugstr_w(font_version));
353 }
354 else
355 {
356 TRACE("keeping %s (new version %s old version %s)\n",
357 debugstr_w(file->File), debugstr_w(file->Version), debugstr_w(font_version));
359 }
360 free( font_version );
361 return state;
362 }
363 }
364 if ((size = msi_get_disk_file_size( package, file->TargetPath )) != file->FileSize)
365 {
366 TRACE("overwriting %s (old size %lu new size %d)\n", debugstr_w(file->File), size, file->FileSize);
367 return msifs_overwrite;
368 }
369 if (file->hash.dwFileHashInfoSize)
370 {
371 if (file_hash_matches( package, file ))
372 {
373 TRACE("keeping %s (hash match)\n", debugstr_w(file->File));
374 return msifs_hashmatch;
375 }
376 else
377 {
378 TRACE("overwriting %s (hash mismatch)\n", debugstr_w(file->File));
379 return msifs_overwrite;
380 }
381 }
382 /* assume present */
383 TRACE("keeping %s\n", debugstr_w(file->File));
384 return msifs_present;
385}
static int state
Definition: maze.c:121
int msi_compare_font_versions(const WCHAR *ver1, const WCHAR *ver2)
Definition: action.c:1942
DWORD msi_get_file_attributes(MSIPACKAGE *package, const WCHAR *path)
Definition: files.c:115
static BOOL file_hash_matches(MSIPACKAGE *package, MSIFILE *file)
Definition: files.c:286
static BOOL is_obsoleted_by_patch(MSIPACKAGE *package, MSIFILE *file)
Definition: files.c:275
DWORD msi_get_disk_file_size(MSIPACKAGE *package, const WCHAR *filename)
Definition: files.c:199
WCHAR * msi_get_font_file_version(MSIPACKAGE *package, const WCHAR *filename)
Definition: font.c:189
enum _msi_file_state msi_file_state
#define LOWORD(l)
Definition: pedump.c:82
DWORD dwFileVersionLS
Definition: compat.h:903
DWORD dwFileVersionMS
Definition: compat.h:902
#define HIWORD(l)
Definition: typedefs.h:247
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23

Referenced by schedule_install_files().

◆ copy_file()

static BOOL copy_file ( MSIPACKAGE package,
const WCHAR src,
const WCHAR dst,
BOOL  fail_if_exists 
)
static

Definition at line 70 of file files.c.

71{
72 BOOL ret;
74 ret = CopyFileW( src, dst, fail_if_exists );
76 return ret;
77}
BOOL WINAPI CopyFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copy.c:439
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by copy_file_attributes(), copy_install_file(), move_file(), and msi_patch_assembly().

◆ copy_file_attributes()

static UINT copy_file_attributes ( MSIPACKAGE package,
MSIFILE file,
WCHAR source 
)
static

Definition at line 404 of file files.c.

405{
406 BOOL ret;
407
408 ret = copy_file( package, source, file->TargetPath, FALSE );
409 if (!ret)
410 return GetLastError();
411
412 msi_set_file_attributes( package, file->TargetPath, FILE_ATTRIBUTE_NORMAL );
413 return ERROR_SUCCESS;
414}
static BOOL copy_file(MSIPACKAGE *package, const WCHAR *src, const WCHAR *dst, BOOL fail_if_exists)
Definition: files.c:70

Referenced by copy_install_file().

◆ copy_install_file()

static UINT copy_install_file ( MSIPACKAGE package,
MSIFILE file,
LPWSTR  source 
)
static

Definition at line 416 of file files.c.

417{
418 UINT gle;
419
420 TRACE("Copying %s to %s\n", debugstr_w(source), debugstr_w(file->TargetPath));
421
422 gle = copy_file_attributes( package, file, source );
423 if (gle == ERROR_SUCCESS)
424 return gle;
425
426 if (gle == ERROR_ALREADY_EXISTS && file->state == msifs_overwrite)
427 {
428 TRACE("overwriting existing file\n");
429 return ERROR_SUCCESS;
430 }
431 else if (gle == ERROR_ACCESS_DENIED)
432 {
433 msi_set_file_attributes( package, file->TargetPath, FILE_ATTRIBUTE_NORMAL );
434
435 gle = copy_file_attributes( package, file, source );
436 TRACE("Overwriting existing file: %d\n", gle);
437 }
439 {
440 WCHAR *tmpfileW, *pathW, *p;
441 DWORD len;
442
443 TRACE("file in use, scheduling rename operation\n");
444
445 if (!(pathW = wcsdup( file->TargetPath ))) return ERROR_OUTOFMEMORY;
446 if ((p = wcsrchr(pathW, '\\'))) *p = 0;
447 len = lstrlenW( pathW ) + 16;
448 if (!(tmpfileW = malloc(len * sizeof(WCHAR))))
449 {
450 free( pathW );
451 return ERROR_OUTOFMEMORY;
452 }
453 if (!GetTempFileNameW( pathW, L"msi", 0, tmpfileW )) tmpfileW[0] = 0;
454 free( pathW );
455
456 if (copy_file( package, source, tmpfileW, FALSE ) &&
457 msi_move_file( package, file->TargetPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT ) &&
458 msi_move_file( package, tmpfileW, file->TargetPath, MOVEFILE_DELAY_UNTIL_REBOOT ))
459 {
460 package->need_reboot_at_end = 1;
461 gle = ERROR_SUCCESS;
462 }
463 else
464 {
465 gle = GetLastError();
466 WARN("failed to schedule rename operation: %d)\n", gle);
467 DeleteFileW( tmpfileW );
468 }
469 free(tmpfileW);
470 }
471
472 return gle;
473}
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
static UINT copy_file_attributes(MSIPACKAGE *package, MSIFILE *file, WCHAR *source)
Definition: files.c:404
BOOL msi_move_file(MSIPACKAGE *package, const WCHAR *from, const WCHAR *to, DWORD flags)
Definition: files.c:142
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
unsigned char need_reboot_at_end
Definition: msipriv.h:469
#define MOVEFILE_DELAY_UNTIL_REBOOT
Definition: winbase.h:426
#define ERROR_SHARING_VIOLATION
Definition: winerror.h:135
#define ERROR_USER_MAPPED_FILE
Definition: winerror.h:727

Referenced by ACTION_InstallFiles().

◆ create_directory()

static BOOL create_directory ( MSIPACKAGE package,
const WCHAR path 
)
static

Definition at line 88 of file files.c.

89{
90 BOOL ret;
94 return ret;
95}
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90

Referenced by msi_create_full_path().

◆ create_folder()

static UINT create_folder ( MSIPACKAGE package,
const WCHAR dir 
)
static

Definition at line 475 of file files.c.

476{
478 const WCHAR *install_path;
479
480 install_path = msi_get_target_folder( package, dir );
481 if (!install_path) return ERROR_FUNCTION_FAILED;
482
483 folder = msi_get_loaded_folder( package, dir );
485 {
486 msi_create_full_path( package, install_path );
488 }
489 return ERROR_SUCCESS;
490}
unsigned int dir
Definition: maze.c:112
BOOL msi_create_full_path(MSIPACKAGE *package, const WCHAR *path)
Definition: files.c:211
const WCHAR * msi_get_target_folder(MSIPACKAGE *package, const WCHAR *name)
Definition: install.c:232
@ FOLDER_STATE_UNINITIALIZED
Definition: msipriv.h:565
@ FOLDER_STATE_CREATED
Definition: msipriv.h:567

Referenced by ACTION_InstallFiles(), and installfiles_cb().

◆ file_hash_matches()

static BOOL file_hash_matches ( MSIPACKAGE package,
MSIFILE file 
)
static

Definition at line 286 of file files.c.

287{
288 UINT r;
290
291 hash.dwFileHashInfoSize = sizeof(hash);
292 r = msi_get_filehash( package, file->TargetPath, &hash );
293 if (r != ERROR_SUCCESS)
294 return FALSE;
295
296 return !memcmp( &hash, &file->hash, sizeof(hash) );
297}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
UINT msi_get_filehash(MSIPACKAGE *package, const WCHAR *path, MSIFILEHASHINFO *hash)
Definition: msi.c:4018
Definition: _hash_fun.h:40

Referenced by calculate_install_state().

◆ file_update_ui()

static void file_update_ui ( MSIPACKAGE package,
MSIFILE f,
const WCHAR action 
)
static

Definition at line 251 of file files.c.

252{
253 MSIRECORD *uirow;
254
255 uirow = MSI_CreateRecord( 9 );
256 MSI_RecordSetStringW( uirow, 1, f->FileName );
257 MSI_RecordSetStringW( uirow, 9, f->Component->Directory );
258 MSI_RecordSetInteger( uirow, 6, f->FileSize );
260 msiobj_release( &uirow->hdr );
261 msi_ui_progress( package, 2, f->FileSize, 0, 0 );
262}
void msi_ui_progress(MSIPACKAGE *package, int a, int b, int c, int d)
Definition: action.c:594
GLfloat f
Definition: glext.h:7540
UINT MSI_RecordSetInteger(MSIRECORD *, UINT, int)
Definition: record.c:280

Referenced by ACTION_InstallFiles(), and ACTION_RemoveFiles().

◆ find_file()

static MSIFILE * find_file ( MSIPACKAGE package,
UINT  disk_id,
const WCHAR filename 
)
static

Definition at line 492 of file files.c.

493{
494 MSIFILE *file;
495
497 {
498 if (file->disk_id == disk_id &&
499 file->state != msifs_installed &&
500 !wcsicmp( filename, file->File )) return file;
501 }
502 return NULL;
503}
#define wcsicmp
Definition: compat.h:15

Referenced by installfiles_cb().

◆ find_filepatch()

static MSIFILEPATCH * find_filepatch ( MSIPACKAGE package,
UINT  disk_id,
const WCHAR key 
)
static

Definition at line 658 of file files.c.

659{
660 MSIFILEPATCH *patch;
661
663 {
664 if (!patch->extracted && patch->disk_id == disk_id && !wcscmp( key, patch->File->File ))
665 return patch;
666 }
667 return NULL;
668}
Definition: copy.c:22

Referenced by patchfiles_cb().

◆ free_file_entry()

static void free_file_entry ( struct file_list file)
static

Definition at line 916 of file files.c.

917{
918 free(file->source);
919 free(file->dest);
920 free(file);
921}

Referenced by add_wildcard(), free_list(), and move_files_wildcard().

◆ free_list()

static void free_list ( struct file_list list)
static

Definition at line 923 of file files.c.

924{
925 while (!list_empty(&list->entry))
926 {
927 struct file_list *file = LIST_ENTRY(list_head(&list->entry), struct file_list, entry);
928
931 }
932}
static void list_remove(struct list_entry *entry)
Definition: list.h:90
Definition: list.h:37
Definition: list.h:15
#define LIST_ENTRY(type)
Definition: queue.h:175

Referenced by move_files_wildcard().

◆ get_duplicate_filename()

static WCHAR * get_duplicate_filename ( MSIPACKAGE package,
MSIRECORD row,
const WCHAR file_key,
const WCHAR src 
)
static

Definition at line 1202 of file files.c.

1203{
1204 DWORD len;
1205 WCHAR *dst_name, *dst_path, *dst;
1206
1207 if (MSI_RecordIsNull( row, 4 ))
1208 {
1209 len = lstrlenW( src ) + 1;
1210 if (!(dst_name = malloc( len * sizeof(WCHAR)))) return NULL;
1211 lstrcpyW( dst_name, wcsrchr( src, '\\' ) + 1 );
1212 }
1213 else
1214 {
1216 if (!(dst_name = malloc( ++len * sizeof(WCHAR) ))) return NULL;
1217 MSI_RecordGetStringW( row, 4, dst_name, &len );
1218 msi_reduce_to_long_filename( dst_name );
1219 }
1220
1221 if (MSI_RecordIsNull( row, 5 ))
1222 {
1223 WCHAR *p;
1224 dst_path = wcsdup( src );
1225 p = wcsrchr( dst_path, '\\' );
1226 if (p) *p = 0;
1227 }
1228 else
1229 {
1230 const WCHAR *dst_key = MSI_RecordGetString( row, 5 );
1231
1232 dst_path = wcsdup( msi_get_target_folder( package, dst_key ) );
1233 if (!dst_path)
1234 {
1235 /* try a property */
1236 dst_path = msi_dup_property( package->db, dst_key );
1237 if (!dst_path)
1238 {
1239 FIXME("Unable to get destination folder, try AppSearch properties\n");
1240 free( dst_name );
1241 return NULL;
1242 }
1243 }
1244 }
1245
1246 dst = msi_build_directory_name( 2, dst_path, dst_name );
1247 msi_create_full_path( package, dst_path );
1248
1249 free( dst_name );
1250 free( dst_path );
1251 return dst;
1252}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define lstrcpyW
Definition: compat.h:749
WCHAR *WINAPIV msi_build_directory_name(DWORD count,...)
Definition: action.c:2007
void msi_reduce_to_long_filename(WCHAR *filename)
Definition: files.c:1053
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:78
const WCHAR * MSI_RecordGetString(const MSIRECORD *, UINT)
Definition: record.c:433
BOOL MSI_RecordIsNull(MSIRECORD *, UINT)
Definition: record.c:321
WCHAR * msi_dup_property(MSIDATABASE *db, const WCHAR *prop)
UINT MSI_RecordGetStringW(MSIRECORD *, UINT, LPWSTR, LPDWORD)

Referenced by ITERATE_DuplicateFiles(), and ITERATE_RemoveDuplicateFiles().

◆ installfiles_cb()

static BOOL installfiles_cb ( MSIPACKAGE package,
LPCWSTR  filename,
DWORD  action,
LPWSTR path,
DWORD attrs,
PVOID  user 
)
static

Definition at line 505 of file files.c.

507{
508 MSIFILE *file = *(MSIFILE **)user;
509
511 {
512 if (!(file = find_file( package, file->disk_id, filename )))
513 {
514 TRACE("unknown file in cabinet (%s)\n", debugstr_w(filename));
515 return FALSE;
516 }
517 if (file->state != msifs_missing && file->state != msifs_overwrite)
518 return FALSE;
519
520 if (!msi_is_global_assembly( file->Component ))
521 {
522 create_folder( package, file->Component->Directory );
523 }
524 *path = wcsdup( file->TargetPath );
525 *attrs = file->Attributes;
526 *(MSIFILE **)user = file;
527 }
529 {
530 if (!msi_is_global_assembly( file->Component )) file->state = msifs_installed;
531 }
532
533 return TRUE;
534}
void user(int argc, const char *argv[])
Definition: cmds.c:1350
const WCHAR * action
Definition: action.c:7509
static MSIFILE * find_file(MSIPACKAGE *package, UINT disk_id, const WCHAR *filename)
Definition: files.c:492
#define MSICABEXTRACT_BEGINEXTRACT
Definition: msipriv.h:1101
#define MSICABEXTRACT_FILEEXTRACTED
Definition: msipriv.h:1102

Referenced by ACTION_InstallFiles().

◆ is_obsoleted_by_patch()

static BOOL is_obsoleted_by_patch ( MSIPACKAGE package,
MSIFILE file 
)
static

Definition at line 275 of file files.c.

276{
277 if (!list_empty( &package->patches ) && file->disk_id < MSI_INITIAL_MEDIA_TRANSFORM_DISKID)
278 {
279 if (!msi_get_property_int( package->db, L"Installed", 0 )) return FALSE;
280 return TRUE;
281 }
282 if (is_registered_patch_media( package, file->disk_id )) return TRUE;
283 return FALSE;
284}
static BOOL is_registered_patch_media(MSIPACKAGE *package, UINT disk_id)
Definition: files.c:264
#define MSI_INITIAL_MEDIA_TRANSFORM_DISKID
Definition: msipriv.h:84
struct list patches
Definition: msipriv.h:400

Referenced by calculate_install_state().

◆ is_registered_patch_media()

static BOOL is_registered_patch_media ( MSIPACKAGE package,
UINT  disk_id 
)
static

Definition at line 264 of file files.c.

265{
266 MSIPATCHINFO *patch;
267
268 LIST_FOR_EACH_ENTRY( patch, &package->patches, MSIPATCHINFO, entry )
269 {
270 if (patch->disk_id == disk_id && patch->registered) return TRUE;
271 }
272 return FALSE;
273}
BOOL registered
Definition: msipriv.h:209

Referenced by is_obsoleted_by_patch(), and patchfiles_cb().

◆ ITERATE_DuplicateFiles()

static UINT ITERATE_DuplicateFiles ( MSIRECORD row,
LPVOID  param 
)
static

Definition at line 1254 of file files.c.

1255{
1256 MSIPACKAGE *package = param;
1257 LPWSTR dest;
1258 LPCWSTR file_key, component;
1259 MSICOMPONENT *comp;
1260 MSIRECORD *uirow;
1261 MSIFILE *file;
1262
1263 component = MSI_RecordGetString(row,2);
1264 comp = msi_get_loaded_component(package, component);
1265 if (!comp)
1266 return ERROR_SUCCESS;
1267
1268 comp->Action = msi_get_component_action( package, comp );
1269 if (comp->Action != INSTALLSTATE_LOCAL)
1270 {
1271 TRACE("component not scheduled for installation %s\n", debugstr_w(component));
1272 return ERROR_SUCCESS;
1273 }
1274
1275 file_key = MSI_RecordGetString(row,3);
1276 if (!file_key)
1277 {
1278 ERR("Unable to get file key\n");
1279 return ERROR_FUNCTION_FAILED;
1280 }
1281
1282 file = msi_get_loaded_file( package, file_key );
1283 if (!file)
1284 {
1285 ERR("Original file unknown %s\n", debugstr_w(file_key));
1286 return ERROR_SUCCESS;
1287 }
1288
1289 dest = get_duplicate_filename( package, row, file_key, file->TargetPath );
1290 if (!dest)
1291 {
1292 WARN("Unable to get duplicate filename\n");
1293 return ERROR_SUCCESS;
1294 }
1295
1296 TRACE("Duplicating file %s to %s\n", debugstr_w(file->TargetPath), debugstr_w(dest));
1297 if (!copy_file( package, file->TargetPath, dest, TRUE ))
1298 {
1299 WARN( "failed to copy file %s -> %s (%lu)\n",
1300 debugstr_w(file->TargetPath), debugstr_w(dest), GetLastError() );
1301 }
1302 FIXME("We should track these duplicate files as well\n");
1303
1304 uirow = MSI_CreateRecord( 9 );
1305 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString( row, 1 ) );
1306 MSI_RecordSetInteger( uirow, 6, file->FileSize );
1307 MSI_RecordSetStringW( uirow, 9, MSI_RecordGetString( row, 5 ) );
1309 msiobj_release( &uirow->hdr );
1310
1311 free(dest);
1312 return ERROR_SUCCESS;
1313}
MSICOMPONENT * msi_get_loaded_component(MSIPACKAGE *package, const WCHAR *Component)
Definition: action.c:550
MSIFILE * msi_get_loaded_file(MSIPACKAGE *package, const WCHAR *key)
Definition: action.c:572
static WCHAR * get_duplicate_filename(MSIPACKAGE *package, MSIRECORD *row, const WCHAR *file_key, const WCHAR *src)
Definition: files.c:1202
static void copy_file(LPCWSTR source, LPCWSTR destination)
Definition: extrac32.c:105
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by ACTION_DuplicateFiles().

◆ ITERATE_MoveFiles()

static UINT ITERATE_MoveFiles ( MSIRECORD rec,
LPVOID  param 
)
static

Definition at line 1059 of file files.c.

1060{
1061 MSIPACKAGE *package = param;
1062 MSIRECORD *uirow;
1063 MSICOMPONENT *comp;
1064 LPCWSTR sourcename, component;
1065 LPWSTR sourcedir, destname = NULL, destdir = NULL, source = NULL, dest = NULL;
1066 int options;
1067 DWORD size;
1068 BOOL wildcards;
1069
1070 component = MSI_RecordGetString(rec, 2);
1071 comp = msi_get_loaded_component(package, component);
1072 if (!comp)
1073 return ERROR_SUCCESS;
1074
1075 comp->Action = msi_get_component_action( package, comp );
1076 if (comp->Action != INSTALLSTATE_LOCAL)
1077 {
1078 TRACE("component not scheduled for installation %s\n", debugstr_w(component));
1079 return ERROR_SUCCESS;
1080 }
1081
1082 sourcename = MSI_RecordGetString(rec, 3);
1083 options = MSI_RecordGetInteger(rec, 7);
1084
1085 sourcedir = msi_dup_property(package->db, MSI_RecordGetString(rec, 5));
1086 if (!sourcedir)
1087 goto done;
1088
1089 destdir = msi_dup_property(package->db, MSI_RecordGetString(rec, 6));
1090 if (!destdir)
1091 goto done;
1092
1093 if (!sourcename)
1094 {
1095 if (msi_get_file_attributes( package, sourcedir ) == INVALID_FILE_ATTRIBUTES)
1096 goto done;
1097
1098 source = wcsdup(sourcedir);
1099 if (!source)
1100 goto done;
1101 }
1102 else
1103 {
1104 size = lstrlenW(sourcedir) + lstrlenW(sourcename) + 2;
1105 source = malloc(size * sizeof(WCHAR));
1106 if (!source)
1107 goto done;
1108
1109 lstrcpyW(source, sourcedir);
1110 if (source[lstrlenW(source) - 1] != '\\')
1111 lstrcatW(source, L"\\");
1112 lstrcatW(source, sourcename);
1113 }
1114
1115 wildcards = wcschr(source, '*') || wcschr(source, '?');
1116
1117 if (MSI_RecordIsNull(rec, 4))
1118 {
1119 if (!wildcards)
1120 {
1121 WCHAR *p;
1122 if (sourcename)
1123 destname = wcsdup(sourcename);
1124 else if ((p = wcsrchr(sourcedir, '\\')))
1125 destname = wcsdup(p + 1);
1126 else
1127 destname = wcsdup(sourcedir);
1128 if (!destname)
1129 goto done;
1130 }
1131 }
1132 else
1133 {
1134 destname = wcsdup(MSI_RecordGetString(rec, 4));
1135 if (destname) msi_reduce_to_long_filename(destname);
1136 }
1137
1138 size = 0;
1139 if (destname)
1140 size = lstrlenW(destname);
1141
1142 size += lstrlenW(destdir) + 2;
1143 dest = malloc(size * sizeof(WCHAR));
1144 if (!dest)
1145 goto done;
1146
1147 lstrcpyW(dest, destdir);
1148 if (dest[lstrlenW(dest) - 1] != '\\')
1149 lstrcatW(dest, L"\\");
1150
1151 if (destname)
1152 lstrcatW(dest, destname);
1153
1154 if (msi_get_file_attributes( package, destdir ) == INVALID_FILE_ATTRIBUTES)
1155 {
1156 if (!msi_create_full_path( package, destdir ))
1157 {
1158 WARN( "failed to create directory %lu\n", GetLastError() );
1159 goto done;
1160 }
1161 }
1162
1163 if (!wildcards)
1164 move_file( package, source, dest, options );
1165 else
1166 move_files_wildcard( package, source, dest, options );
1167
1168done:
1169 uirow = MSI_CreateRecord( 9 );
1170 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString(rec, 1) );
1171 MSI_RecordSetInteger( uirow, 6, 1 ); /* FIXME */
1172 MSI_RecordSetStringW( uirow, 9, destdir );
1174 msiobj_release( &uirow->hdr );
1175
1176 free(sourcedir);
1177 free(destdir);
1178 free(destname);
1179 free(source);
1180 free(dest);
1181
1182 return ERROR_SUCCESS;
1183}
#define wcschr
Definition: compat.h:17
static BOOL move_files_wildcard(MSIPACKAGE *package, const WCHAR *source, WCHAR *dest, int options)
Definition: files.c:985
static BOOL move_file(MSIPACKAGE *package, const WCHAR *source, const WCHAR *dest, int options)
Definition: files.c:863
int MSI_RecordGetInteger(MSIRECORD *, UINT)
Definition: record.c:213

Referenced by ACTION_MoveFiles().

◆ ITERATE_RemoveDuplicateFiles()

static UINT ITERATE_RemoveDuplicateFiles ( MSIRECORD row,
LPVOID  param 
)
static

Definition at line 1332 of file files.c.

1333{
1334 MSIPACKAGE *package = param;
1335 LPWSTR dest;
1336 LPCWSTR file_key, component;
1337 MSICOMPONENT *comp;
1338 MSIRECORD *uirow;
1339 MSIFILE *file;
1340
1341 component = MSI_RecordGetString( row, 2 );
1342 comp = msi_get_loaded_component( package, component );
1343 if (!comp)
1344 return ERROR_SUCCESS;
1345
1346 comp->Action = msi_get_component_action( package, comp );
1347 if (comp->Action != INSTALLSTATE_ABSENT)
1348 {
1349 TRACE("component not scheduled for removal %s\n", debugstr_w(component));
1350 return ERROR_SUCCESS;
1351 }
1352
1353 file_key = MSI_RecordGetString( row, 3 );
1354 if (!file_key)
1355 {
1356 ERR("Unable to get file key\n");
1357 return ERROR_FUNCTION_FAILED;
1358 }
1359
1360 file = msi_get_loaded_file( package, file_key );
1361 if (!file)
1362 {
1363 ERR("Original file unknown %s\n", debugstr_w(file_key));
1364 return ERROR_SUCCESS;
1365 }
1366
1367 dest = get_duplicate_filename( package, row, file_key, file->TargetPath );
1368 if (!dest)
1369 {
1370 WARN("Unable to get duplicate filename\n");
1371 return ERROR_SUCCESS;
1372 }
1373
1374 TRACE("Removing duplicate %s of %s\n", debugstr_w(dest), debugstr_w(file->TargetPath));
1375 if (!msi_delete_file( package, dest ))
1376 {
1377 WARN( "failed to delete duplicate file %s (%lu)\n", debugstr_w(dest), GetLastError() );
1378 }
1379
1380 uirow = MSI_CreateRecord( 9 );
1381 MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString( row, 1 ) );
1382 MSI_RecordSetStringW( uirow, 9, MSI_RecordGetString( row, 5 ) );
1384 msiobj_release( &uirow->hdr );
1385
1386 free(dest);
1387 return ERROR_SUCCESS;
1388}

Referenced by ACTION_RemoveDuplicateFiles().

◆ ITERATE_RemoveFiles()

static UINT ITERATE_RemoveFiles ( MSIRECORD row,
LPVOID  param 
)
static

Definition at line 1431 of file files.c.

1432{
1433 MSIPACKAGE *package = param;
1434 MSICOMPONENT *comp;
1435 MSIRECORD *uirow;
1436 LPCWSTR component, dirprop;
1437 UINT install_mode;
1439 DWORD size;
1441
1442 component = MSI_RecordGetString(row, 2);
1443 dirprop = MSI_RecordGetString(row, 4);
1444 install_mode = MSI_RecordGetInteger(row, 5);
1445
1446 comp = msi_get_loaded_component(package, component);
1447 if (!comp)
1448 return ERROR_SUCCESS;
1449
1450 comp->Action = msi_get_component_action( package, comp );
1451 if (!verify_comp_for_removal(comp, install_mode))
1452 {
1453 TRACE("Skipping removal due to install mode\n");
1454 return ERROR_SUCCESS;
1455 }
1456 if (comp->assembly && !comp->assembly->application)
1457 {
1458 return ERROR_SUCCESS;
1459 }
1460 if (comp->Attributes & msidbComponentAttributesPermanent)
1461 {
1462 TRACE("permanent component, not removing file\n");
1463 return ERROR_SUCCESS;
1464 }
1465
1466 dir = msi_dup_property(package->db, dirprop);
1467 if (!dir)
1468 {
1469 WARN("directory property has no value\n");
1470 return ERROR_SUCCESS;
1471 }
1472 size = 0;
1473 if ((filename = wcsdup( MSI_RecordGetString(row, 3) )))
1474 {
1476 size = lstrlenW( filename );
1477 }
1478 size += lstrlenW(dir) + 2;
1479 path = malloc(size * sizeof(WCHAR));
1480 if (!path)
1481 {
1483 goto done;
1484 }
1485
1486 if (filename)
1487 {
1488 lstrcpyW(path, dir);
1491
1492 TRACE("Deleting misc file: %s\n", debugstr_w(path));
1493 msi_delete_file( package, path );
1494 }
1495 else
1496 {
1497 TRACE("Removing misc directory: %s\n", debugstr_w(dir));
1498 msi_remove_directory( package, dir );
1499 }
1500
1501done:
1502 uirow = MSI_CreateRecord( 9 );
1504 MSI_RecordSetStringW( uirow, 9, dir );
1506 msiobj_release( &uirow->hdr );
1507
1508 free(filename);
1509 free(path);
1510 free(dir);
1511 return ret;
1512}
BOOL msi_remove_directory(MSIPACKAGE *package, const WCHAR *path)
Definition: files.c:97
static BOOL verify_comp_for_removal(MSICOMPONENT *comp, UINT install_mode)
Definition: files.c:1407
#define PathAddBackslashW
Definition: pathcch.h:301

Referenced by ACTION_RemoveFiles().

◆ move_file()

static BOOL move_file ( MSIPACKAGE package,
const WCHAR source,
const WCHAR dest,
int  options 
)
static

Definition at line 863 of file files.c.

864{
865 BOOL ret;
866
869 {
870 WARN("Source or dest is directory, not moving\n");
871 return FALSE;
872 }
873
875 {
876 TRACE("moving %s -> %s\n", debugstr_w(source), debugstr_w(dest));
878 if (!ret)
879 {
880 WARN( "msi_move_file failed: %lu\n", GetLastError() );
881 return FALSE;
882 }
883 }
884 else
885 {
886 TRACE("copying %s -> %s\n", debugstr_w(source), debugstr_w(dest));
887 ret = copy_file( package, source, dest, FALSE );
888 if (!ret)
889 {
890 WARN( "copy_file failed: %lu\n", GetLastError() );
891 return FALSE;
892 }
893 }
894
895 return TRUE;
896}
#define MOVEFILE_REPLACE_EXISTING
Definition: filesup.h:28
@ msidbMoveFileOptionsMove
Definition: msidefs.h:210
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705

Referenced by ITERATE_MoveFiles(), and move_files_wildcard().

◆ move_files_wildcard()

static BOOL move_files_wildcard ( MSIPACKAGE package,
const WCHAR source,
WCHAR dest,
int  options 
)
static

Definition at line 985 of file files.c.

986{
988 HANDLE hfile;
989 LPWSTR path;
990 BOOL res;
991 struct file_list files, *file;
992 DWORD size;
993
994 hfile = msi_find_first_file( package, source, &wfd );
995 if (hfile == INVALID_HANDLE_VALUE) return FALSE;
996
997 list_init(&files.entry);
998
999 for (res = TRUE; res; res = msi_find_next_file( package, hfile, &wfd ))
1000 {
1001 if (is_dot_dir(wfd.cFileName)) continue;
1002
1003 path = wildcard_to_file( source, wfd.cFileName );
1004 if (!path)
1005 {
1006 res = FALSE;
1007 goto done;
1008 }
1009
1010 add_wildcard(&files, path, dest);
1011 free(path);
1012 }
1013
1014 /* no files match the wildcard */
1015 if (list_empty(&files.entry))
1016 goto done;
1017
1018 /* only the first wildcard match gets renamed to dest */
1019 file = LIST_ENTRY(list_head(&files.entry), struct file_list, entry);
1020 size = (wcsrchr(file->dest, '\\') - file->dest) + lstrlenW(file->destname) + 2;
1021 file->dest = realloc(file->dest, size * sizeof(WCHAR));
1022 if (!file->dest)
1023 {
1024 res = FALSE;
1025 goto done;
1026 }
1027
1028 /* file->dest may be shorter after the reallocation, so add a NULL
1029 * terminator. This is needed for the call to wcsrchr, as there will no
1030 * longer be a NULL terminator within the bounds of the allocation in this case.
1031 */
1032 file->dest[size - 1] = '\0';
1033 lstrcpyW(wcsrchr(file->dest, '\\') + 1, file->destname);
1034
1035 while (!list_empty(&files.entry))
1036 {
1037 file = LIST_ENTRY(list_head(&files.entry), struct file_list, entry);
1038
1039 move_file( package, file->source, file->dest, options );
1040
1043 }
1044
1045 res = TRUE;
1046
1047done:
1048 free_list(&files);
1049 FindClose(hfile);
1050 return res;
1051}
static void list_init(struct list_entry *head)
Definition: list.h:51
#define realloc
Definition: debug_ros.c:6
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
HANDLE msi_find_first_file(MSIPACKAGE *package, const WCHAR *filename, WIN32_FIND_DATAW *data)
Definition: files.c:124
#define is_dot_dir(x)
Definition: files.c:852
static BOOL add_wildcard(struct file_list *files, const WCHAR *source, WCHAR *dest)
Definition: files.c:934
static WCHAR * wildcard_to_file(const WCHAR *wildcard, const WCHAR *filename)
Definition: files.c:898
BOOL msi_find_next_file(MSIPACKAGE *package, HANDLE handle, WIN32_FIND_DATAW *data)
Definition: files.c:133
static void free_list(struct file_list *list)
Definition: files.c:923
GLuint res
Definition: glext.h:9613

Referenced by ITERATE_MoveFiles().

◆ msi_create_file()

HANDLE msi_create_file ( MSIPACKAGE package,
const WCHAR filename,
DWORD  access,
DWORD  sharing,
DWORD  creation,
DWORD  flags 
)

Definition at line 60 of file files.c.

62{
67 return handle;
68}
#define CreateFileW
Definition: compat.h:741
GLbitfield flags
Definition: glext.h:7161
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
static ULONG POBJECT_ATTRIBUTES PIO_STATUS_BLOCK ULONG sharing
Definition: pipe.c:70

Referenced by cabinet_copy_file(), HANDLE_CustomType21_22(), ITERATE_PublishIcon(), load_ttf_name_id(), msi_get_disk_file_size(), and msi_get_filehash().

◆ msi_create_full_path()

BOOL msi_create_full_path ( MSIPACKAGE package,
const WCHAR path 
)

Definition at line 211 of file files.c.

212{
213 BOOL ret = TRUE;
214 WCHAR *new_path;
215 int len;
216
217 if (!(new_path = malloc( (wcslen( path ) + 1) * sizeof(WCHAR) ))) return FALSE;
218 lstrcpyW( new_path, path );
219
220 while ((len = lstrlenW( new_path )) && new_path[len - 1] == '\\')
221 new_path[len - 1] = 0;
222
223 while (!create_directory( package, new_path ))
224 {
225 WCHAR *slash;
227 if (last_error == ERROR_ALREADY_EXISTS) break;
229 {
230 ret = FALSE;
231 break;
232 }
233 if (!(slash = wcsrchr( new_path, '\\' )))
234 {
235 ret = FALSE;
236 break;
237 }
238 len = slash - new_path;
239 new_path[len] = 0;
240 if (!msi_create_full_path( package, new_path ))
241 {
242 ret = FALSE;
243 break;
244 }
245 new_path[len] = '\\';
246 }
247 free( new_path );
248 return ret;
249}
static BOOL create_directory(MSIPACKAGE *package, const WCHAR *path)
Definition: files.c:88
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106

Referenced by create_folder(), get_duplicate_filename(), get_link_file(), ITERATE_CreateFolders(), ITERATE_MoveFiles(), msi_build_icon_path(), and msi_create_full_path().

◆ msi_delete_file()

◆ msi_find_first_file()

HANDLE msi_find_first_file ( MSIPACKAGE package,
const WCHAR filename,
WIN32_FIND_DATAW data 
)

Definition at line 124 of file files.c.

125{
129 msi_revert_fs_redirection( package );
130 return handle;
131}
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320

Referenced by move_files_wildcard(), and recurse_search_directory().

◆ msi_find_next_file()

BOOL msi_find_next_file ( MSIPACKAGE package,
HANDLE  handle,
WIN32_FIND_DATAW data 
)

Definition at line 133 of file files.c.

134{
135 BOOL ret;
138 msi_revert_fs_redirection( package );
139 return ret;
140}
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382

Referenced by move_files_wildcard(), and recurse_search_directory().

◆ msi_get_disk_file_size()

DWORD msi_get_disk_file_size ( MSIPACKAGE package,
const WCHAR filename 
)

Definition at line 199 of file files.c.

200{
201 DWORD size;
202 HANDLE file;
206 CloseHandle( file );
207 return size;
208}
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
HANDLE msi_create_file(MSIPACKAGE *package, const WCHAR *filename, DWORD access, DWORD sharing, DWORD creation, DWORD flags)
Definition: files.c:60
#define INVALID_FILE_SIZE
Definition: winbase.h:574

Referenced by calculate_file_cost(), and calculate_install_state().

◆ msi_get_disk_file_version()

VS_FIXEDFILEINFO * msi_get_disk_file_version ( MSIPACKAGE package,
const WCHAR filename 
)

Definition at line 170 of file files.c.

171{
173 DWORD version_size;
174 UINT size;
175 void *version;
176
177 if (!(version_size = msi_get_file_version_info( package, filename, 0, NULL ))) return NULL;
178 if (!(version = malloc( version_size ))) return NULL;
179
180 msi_get_file_version_info( package, filename, version_size, version );
181
182 if (!VerQueryValueW( version, L"\\", (void **)&ptr, &size ))
183 {
184 free( version );
185 return NULL;
186 }
187
188 if (!(ret = malloc( size )))
189 {
190 free( version );
191 return NULL;
192 }
193
194 memcpy( ret, ptr, size );
195 free( version );
196 return ret;
197}
static const WCHAR version[]
Definition: asmname.c:66
DWORD msi_get_file_version_info(MSIPACKAGE *package, const WCHAR *path, DWORD buflen, BYTE *buffer)
Definition: files.c:160
BOOL WINAPI VerQueryValueW(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen)
Definition: version.c:1057
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by ACTION_RemoveFiles(), calculate_file_cost(), and calculate_install_state().

◆ msi_get_file_attributes()

DWORD msi_get_file_attributes ( MSIPACKAGE package,
const WCHAR path 
)

Definition at line 115 of file files.c.

116{
117 DWORD attrs;
119 attrs = GetFileAttributesW( path );
120 msi_revert_fs_redirection( package );
121 return attrs;
122}
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652

Referenced by cabinet_copy_file(), calculate_file_cost(), calculate_install_state(), check_directory(), ITERATE_MoveFiles(), move_file(), msi_resolve_file_source(), MSI_SetTargetPathW(), search_components(), search_directory(), search_dr(), and search_file().

◆ msi_get_file_version_info()

DWORD msi_get_file_version_info ( MSIPACKAGE package,
const WCHAR path,
DWORD  buflen,
BYTE buffer 
)

Definition at line 160 of file files.c.

161{
164 if (buffer) size = GetFileVersionInfoW( path, 0, buflen, buffer );
166 msi_revert_fs_redirection( package );
167 return size;
168}
BOOL WINAPI GetFileVersionInfoW(LPCWSTR filename, DWORD handle, DWORD datasize, LPVOID data)
Definition: version.c:845
DWORD WINAPI GetFileVersionInfoSizeW(LPCWSTR filename, LPDWORD handle)
Definition: version.c:611
GLuint buffer
Definition: glext.h:5915

Referenced by file_version_matches(), msi_get_disk_file_version(), and search_file().

◆ msi_get_temp_file_name()

BOOL msi_get_temp_file_name ( MSIPACKAGE package,
const WCHAR tmp_path,
const WCHAR prefix,
WCHAR tmp_filename 
)

Definition at line 51 of file files.c.

52{
53 BOOL ret;
55 ret = GetTempFileNameW( tmp_path, prefix, 0, tmp_filename );
57 return ret;
58}

Referenced by cabinet_copy_file().

◆ msi_move_file()

BOOL msi_move_file ( MSIPACKAGE package,
const WCHAR from,
const WCHAR to,
DWORD  flags 
)

Definition at line 142 of file files.c.

143{
144 BOOL ret;
146 ret = MoveFileExW( from, to, flags );
147 msi_revert_fs_redirection( package );
148 return ret;
149}
BOOL WINAPI MoveFileExW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName OPTIONAL, IN DWORD dwFlags)
Definition: move.c:1120
CardRegion * from
Definition: spigame.cpp:19

Referenced by cabinet_copy_file(), copy_install_file(), move_file(), and patch_file().

◆ msi_patch_assembly()

UINT msi_patch_assembly ( MSIPACKAGE package,
MSIASSEMBLY assembly,
MSIFILEPATCH patch 
)

Definition at line 726 of file files.c.

727{
730 IAssemblyEnum *iter;
731
732 if (!(iter = msi_create_assembly_enum( package, assembly->display_name )))
734
735 while ((IAssemblyEnum_GetNextAssembly( iter, NULL, &name, 0 ) == S_OK))
736 {
737 WCHAR *displayname, *path;
738 DWORD len = 0;
739 HRESULT hr;
740
741 hr = IAssemblyName_GetDisplayName( name, NULL, &len, 0 );
742 if (hr != E_NOT_SUFFICIENT_BUFFER || !(displayname = malloc( len * sizeof(WCHAR) )))
743 break;
744
745 hr = IAssemblyName_GetDisplayName( name, displayname, &len, 0 );
746 if (FAILED( hr ))
747 {
748 free( displayname );
749 break;
750 }
751
752 if ((path = msi_get_assembly_path( package, displayname )))
753 {
754 if (!copy_file( package, path, patch->File->TargetPath, FALSE ))
755 {
756 ERR( "failed to copy file %s -> %s (%lu)\n", debugstr_w(path),
758 free( path );
759 free( displayname );
760 IAssemblyName_Release( name );
761 break;
762 }
763 r = patch_file( package, patch );
764 free( path );
765 }
766
767 free( displayname );
768 IAssemblyName_Release( name );
769 if (r == ERROR_SUCCESS) break;
770 }
771
772 IAssemblyEnum_Release( iter );
773 return r;
774}
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
IAssemblyEnum * msi_create_assembly_enum(MSIPACKAGE *package, const WCHAR *displayname)
Definition: assembly.c:244
WCHAR * msi_get_assembly_path(MSIPACKAGE *package, const WCHAR *displayname)
Definition: assembly.c:219
HRESULT hr
Definition: shlfolder.c:183
Definition: name.c:39
LPWSTR TargetPath
Definition: msipriv.h:617
#define E_NOT_SUFFICIENT_BUFFER
Definition: winerror.h:2345

Referenced by ACTION_InstallFinalize().

◆ msi_reduce_to_long_filename()

void msi_reduce_to_long_filename ( WCHAR filename)

Definition at line 1053 of file files.c.

1054{
1055 WCHAR *p = wcschr( filename, '|' );
1056 if (p) memmove( filename, p + 1, (lstrlenW( p + 1 ) + 1) * sizeof(WCHAR) );
1057}
#define memmove(s1, s2, n)
Definition: mkisofs.h:881

Referenced by get_duplicate_filename(), get_link_file(), ITERATE_MoveFiles(), ITERATE_RemoveFiles(), load_class(), and load_file().

◆ msi_remove_directory()

BOOL msi_remove_directory ( MSIPACKAGE package,
const WCHAR path 
)

Definition at line 97 of file files.c.

98{
99 BOOL ret;
102 msi_revert_fs_redirection( package );
103 return ret;
104}
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732

Referenced by ITERATE_RemoveFiles(), and ITERATE_UnpublishIcon().

◆ msi_resolve_file_source()

WCHAR * msi_resolve_file_source ( MSIPACKAGE package,
MSIFILE file 
)

Definition at line 536 of file files.c.

537{
538 WCHAR *p, *path;
539
540 TRACE("Working to resolve source of file %s\n", debugstr_w(file->File));
541
542 if (file->IsCompressed) return NULL;
543
544 p = msi_resolve_source_folder( package, file->Component->Directory, NULL );
545 path = msi_build_directory_name( 2, p, file->ShortName );
546
547 if (file->LongName && msi_get_file_attributes( package, path ) == INVALID_FILE_ATTRIBUTES)
548 {
549 free( path );
550 path = msi_build_directory_name( 2, p, file->LongName );
551 }
552 free( p );
553 TRACE("file %s source resolves to %s\n", debugstr_w(file->File), debugstr_w(path));
554 return path;
555}
WCHAR * msi_resolve_source_folder(MSIPACKAGE *package, const WCHAR *name, MSIFOLDER **folder)
Definition: install.c:364

Referenced by ACTION_InstallFiles(), and ACTION_ProcessComponents().

◆ msi_set_file_attributes()

BOOL msi_set_file_attributes ( MSIPACKAGE package,
const WCHAR filename,
DWORD  attrs 
)

Definition at line 106 of file files.c.

107{
108 BOOL ret;
110 ret = SetFileAttributesW( filename, attrs );
111 msi_revert_fs_redirection( package );
112 return ret;
113}
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:794

Referenced by ACTION_RemoveFiles(), cabinet_copy_file(), copy_file_attributes(), and copy_install_file().

◆ patch_file()

static UINT patch_file ( MSIPACKAGE package,
MSIFILEPATCH patch 
)
static

Definition at line 704 of file files.c.

705{
707 WCHAR *tmpfile = msi_create_temp_file( package->db );
708
709 if (!tmpfile) return ERROR_INSTALL_FAILURE;
710 if (apply_filepatch( package, patch->path, patch->File->TargetPath, tmpfile ))
711 {
712 msi_delete_file( package, patch->File->TargetPath );
713 msi_move_file( package, tmpfile, patch->File->TargetPath, 0 );
714 }
715 else
716 {
717 WARN( "failed to patch %s: %#lx\n", debugstr_w(patch->File->TargetPath), GetLastError() );
719 }
720 DeleteFileW( patch->path );
722 free( tmpfile );
723 return r;
724}
WCHAR * msi_create_temp_file(MSIDATABASE *db)
Definition: custom.c:215
static BOOL apply_filepatch(MSIPACKAGE *package, const WCHAR *patch, const WCHAR *old, const WCHAR *new)
Definition: files.c:151
_Check_return_ _CRTIMP FILE *__cdecl tmpfile(void)
Definition: file.c:3914

Referenced by ACTION_PatchFiles(), ApplyPatchToFileA(), ApplyPatchToFileByHandles(), ApplyPatchToFileW(), msi_apply_registered_patch(), msi_patch_assembly(), TestApplyPatchToFileA(), TestApplyPatchToFileByHandles(), and TestApplyPatchToFileW().

◆ patchfiles_cb()

static BOOL patchfiles_cb ( MSIPACKAGE package,
LPCWSTR  file,
DWORD  action,
LPWSTR path,
DWORD attrs,
PVOID  user 
)
static

Definition at line 670 of file files.c.

672{
673 MSIFILEPATCH *patch = *(MSIFILEPATCH **)user;
674
676 {
677 MSICOMPONENT *comp;
678
679 if (is_registered_patch_media( package, patch->disk_id ) ||
680 !(patch = find_filepatch( package, patch->disk_id, file ))) return FALSE;
681
682 comp = patch->File->Component;
683 comp->Action = msi_get_component_action( package, comp );
684 if (!comp->Enabled || comp->Action != INSTALLSTATE_LOCAL)
685 {
686 TRACE("file %s component %s not installed or disabled\n",
687 debugstr_w(patch->File->File), debugstr_w(comp->Component));
688 return FALSE;
689 }
690
691 patch->path = msi_create_temp_file( package->db );
692 *path = wcsdup( patch->path );
693 *attrs = patch->File->Attributes;
694 *(MSIFILEPATCH **)user = patch;
695 }
697 {
698 patch->extracted = TRUE;
699 }
700
701 return TRUE;
702}
static MSIFILEPATCH * find_filepatch(MSIPACKAGE *package, UINT disk_id, const WCHAR *key)
Definition: files.c:658
LPWSTR Component
Definition: msipriv.h:524
INT Attributes
Definition: msipriv.h:614

Referenced by ACTION_PatchFiles().

◆ remove_folder()

static void remove_folder ( MSIFOLDER folder)
static

Definition at line 1514 of file files.c.

1515{
1516 FolderList *fl;
1517
1519 {
1520 remove_folder( fl->folder );
1521 }
1522 if (!folder->persistent && folder->State != FOLDER_STATE_REMOVED)
1523 {
1524 if (RemoveDirectoryW( folder->ResolvedTarget )) folder->State = FOLDER_STATE_REMOVED;
1525 }
1526}
@ FOLDER_STATE_REMOVED
Definition: msipriv.h:569
_In_ FLONG fl
Definition: winddi.h:1279

Referenced by ACTION_RemoveFiles(), and remove_folder().

◆ schedule_install_files()

static void schedule_install_files ( MSIPACKAGE package)
static

Definition at line 387 of file files.c.

388{
389 MSIFILE *file;
390
392 {
393 MSICOMPONENT *comp = file->Component;
394
395 file->state = calculate_install_state( package, file );
397 {
398 TRACE("not overwriting %s\n", debugstr_w(file->TargetPath));
399 file->state = msifs_skipped;
400 }
401 }
402}
static msi_file_state calculate_install_state(MSIPACKAGE *package, MSIFILE *file)
Definition: files.c:299
@ msidbComponentAttributesNeverOverwrite
Definition: msidefs.h:167

Referenced by ACTION_InstallFiles().

◆ verify_comp_for_removal()

static BOOL verify_comp_for_removal ( MSICOMPONENT comp,
UINT  install_mode 
)
static

Definition at line 1407 of file files.c.

1408{
1409 /* special case */
1410 if (comp->Action != INSTALLSTATE_SOURCE &&
1412 (install_mode == msidbRemoveFileInstallModeOnRemove ||
1413 install_mode == msidbRemoveFileInstallModeOnBoth)) return TRUE;
1414
1415 switch (comp->Action)
1416 {
1417 case INSTALLSTATE_LOCAL:
1419 if (install_mode == msidbRemoveFileInstallModeOnInstall ||
1420 install_mode == msidbRemoveFileInstallModeOnBoth) return TRUE;
1421 break;
1423 if (install_mode == msidbRemoveFileInstallModeOnRemove ||
1424 install_mode == msidbRemoveFileInstallModeOnBoth) return TRUE;
1425 break;
1426 default: break;
1427 }
1428 return FALSE;
1429}
@ msidbComponentAttributesSourceOnly
Definition: msidefs.h:160
@ msidbRemoveFileInstallModeOnBoth
Definition: msidefs.h:231
@ msidbRemoveFileInstallModeOnInstall
Definition: msidefs.h:229
@ msidbRemoveFileInstallModeOnRemove
Definition: msidefs.h:230

Referenced by ITERATE_RemoveFiles().

◆ wildcard_to_file()

static WCHAR * wildcard_to_file ( const WCHAR wildcard,
const WCHAR filename 
)
static

Definition at line 898 of file files.c.

899{
900 const WCHAR *ptr;
901 WCHAR *path;
902 DWORD dirlen, pathlen;
903
904 ptr = wcsrchr(wildcard, '\\');
905 dirlen = ptr - wildcard + 1;
906
907 pathlen = dirlen + lstrlenW(filename) + 1;
908 if (!(path = malloc(pathlen * sizeof(WCHAR)))) return NULL;
909
910 lstrcpynW(path, wildcard, dirlen + 1);
912
913 return path;
914}

Referenced by move_files_wildcard().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( msi  )