msi: Create files with the correct file attributes.
[wine/wine64.git] / dlls / msi / files.c
blobba36a0d9d16724fdd9db40343b2a093cfc451b3f
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * Actions dealing with files These are
25 * InstallFiles
26 * DuplicateFiles
27 * MoveFiles (TODO)
28 * PatchFiles (TODO)
29 * RemoveDuplicateFiles(TODO)
30 * RemoveFiles(TODO)
33 #include <stdarg.h>
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winerror.h"
38 #include "wine/debug.h"
39 #include "fdi.h"
40 #include "msi.h"
41 #include "msidefs.h"
42 #include "msvcrt/fcntl.h"
43 #include "msipriv.h"
44 #include "winuser.h"
45 #include "wine/unicode.h"
46 #include "action.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msi);
50 extern const WCHAR szInstallFiles[];
51 extern const WCHAR szDuplicateFiles[];
52 extern const WCHAR szMoveFiles[];
53 extern const WCHAR szPatchFiles[];
54 extern const WCHAR szRemoveDuplicateFiles[];
55 extern const WCHAR szRemoveFiles[];
57 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
61 * This is a helper function for handling embedded cabinet media
63 static UINT writeout_cabinet_stream(MSIPACKAGE *package, LPCWSTR stream_name,
64 WCHAR* source)
66 UINT rc;
67 USHORT* data;
68 UINT size;
69 DWORD write;
70 HANDLE the_file;
71 WCHAR tmp[MAX_PATH];
73 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
74 if (rc != ERROR_SUCCESS)
75 return rc;
77 write = MAX_PATH;
78 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
79 GetTempPathW(MAX_PATH,tmp);
81 GetTempFileNameW(tmp,stream_name,0,source);
83 track_tempfile(package,strrchrW(source,'\\'), source);
84 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
85 FILE_ATTRIBUTE_NORMAL, NULL);
87 if (the_file == INVALID_HANDLE_VALUE)
89 ERR("Unable to create file %s\n",debugstr_w(source));
90 rc = ERROR_FUNCTION_FAILED;
91 goto end;
94 WriteFile(the_file,data,size,&write,NULL);
95 CloseHandle(the_file);
96 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
97 end:
98 msi_free(data);
99 return rc;
103 /* Support functions for FDI functions */
104 typedef struct
106 MSIPACKAGE* package;
107 LPCSTR cab_path;
108 } CabData;
110 static void * cabinet_alloc(ULONG cb)
112 return msi_alloc(cb);
115 static void cabinet_free(void *pv)
117 msi_free(pv);
120 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
122 HANDLE handle;
123 DWORD dwAccess = 0;
124 DWORD dwShareMode = 0;
125 DWORD dwCreateDisposition = OPEN_EXISTING;
126 switch (oflag & _O_ACCMODE)
128 case _O_RDONLY:
129 dwAccess = GENERIC_READ;
130 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
131 break;
132 case _O_WRONLY:
133 dwAccess = GENERIC_WRITE;
134 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
135 break;
136 case _O_RDWR:
137 dwAccess = GENERIC_READ | GENERIC_WRITE;
138 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
139 break;
141 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
142 dwCreateDisposition = CREATE_NEW;
143 else if (oflag & _O_CREAT)
144 dwCreateDisposition = CREATE_ALWAYS;
145 handle = CreateFileA( pszFile, dwAccess, dwShareMode, NULL,
146 dwCreateDisposition, 0, NULL );
147 if (handle == INVALID_HANDLE_VALUE)
148 return 0;
149 return (INT_PTR) handle;
152 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
154 HANDLE handle = (HANDLE) hf;
155 DWORD dwRead;
156 if (ReadFile(handle, pv, cb, &dwRead, NULL))
157 return dwRead;
158 return 0;
161 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
163 HANDLE handle = (HANDLE) hf;
164 DWORD dwWritten;
165 if (WriteFile(handle, pv, cb, &dwWritten, NULL))
166 return dwWritten;
167 return 0;
170 static int cabinet_close(INT_PTR hf)
172 HANDLE handle = (HANDLE) hf;
173 return CloseHandle(handle) ? 0 : -1;
176 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
178 HANDLE handle = (HANDLE) hf;
179 /* flags are compatible and so are passed straight through */
180 return SetFilePointer(handle, dist, NULL, seektype);
183 static void msi_file_update_ui( MSIPACKAGE *package, MSIFILE *f, const WCHAR *action )
185 MSIRECORD *uirow;
186 LPWSTR uipath, p;
188 /* the UI chunk */
189 uirow = MSI_CreateRecord( 9 );
190 MSI_RecordSetStringW( uirow, 1, f->FileName );
191 uipath = strdupW( f->TargetPath );
192 p = strrchrW(uipath,'\\');
193 if (p)
194 p[1]=0;
195 MSI_RecordSetStringW( uirow, 9, uipath);
196 MSI_RecordSetInteger( uirow, 6, f->FileSize );
197 ui_actiondata( package, action, uirow);
198 msiobj_release( &uirow->hdr );
199 msi_free( uipath );
200 ui_progress( package, 2, f->FileSize, 0, 0);
203 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
205 switch (fdint)
207 case fdintCOPY_FILE:
209 CabData *data = (CabData*) pfdin->pv;
210 HANDLE handle;
211 LPWSTR file;
212 MSIFILE *f;
213 DWORD attrs;
215 file = strdupAtoW(pfdin->psz1);
216 f = get_loaded_file(data->package, file);
217 msi_free(file);
219 if (!f)
221 ERR("Unknown File in Cabinet (%s)\n",debugstr_a(pfdin->psz1));
222 return 0;
225 if (f->state != msifs_missing && f->state != msifs_overwrite)
227 TRACE("Skipping extraction of %s\n",debugstr_a(pfdin->psz1));
228 return 0;
231 msi_file_update_ui( data->package, f, szInstallFiles );
233 TRACE("extracting %s\n", debugstr_w(f->TargetPath) );
235 attrs = f->Attributes & (FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
236 if (!attrs) attrs = FILE_ATTRIBUTE_NORMAL;
238 handle = CreateFileW( f->TargetPath, GENERIC_READ | GENERIC_WRITE, 0,
239 NULL, CREATE_ALWAYS, attrs, NULL );
240 if ( handle == INVALID_HANDLE_VALUE )
242 ERR("failed to create %s (error %ld)\n",
243 debugstr_w( f->TargetPath ), GetLastError() );
244 return 0;
247 f->state = msifs_installed;
248 return (INT_PTR) handle;
250 case fdintCLOSE_FILE_INFO:
252 FILETIME ft;
253 FILETIME ftLocal;
254 HANDLE handle = (HANDLE) pfdin->hf;
256 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
257 return -1;
258 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
259 return -1;
260 if (!SetFileTime(handle, &ftLocal, 0, &ftLocal))
261 return -1;
262 CloseHandle(handle);
263 return 1;
265 default:
266 return 0;
270 /***********************************************************************
271 * extract_cabinet_file
273 * Extract files from a cab file.
275 static BOOL extract_cabinet_file(MSIPACKAGE* package, LPCWSTR source,
276 LPCWSTR path)
278 HFDI hfdi;
279 ERF erf;
280 BOOL ret;
281 char *cabinet;
282 char *cab_path;
283 CabData data;
285 TRACE("Extracting %s to %s\n",debugstr_w(source), debugstr_w(path));
287 hfdi = FDICreate(cabinet_alloc,
288 cabinet_free,
289 cabinet_open,
290 cabinet_read,
291 cabinet_write,
292 cabinet_close,
293 cabinet_seek,
295 &erf);
296 if (!hfdi)
298 ERR("FDICreate failed\n");
299 return FALSE;
302 if (!(cabinet = strdupWtoA( source )))
304 FDIDestroy(hfdi);
305 return FALSE;
307 if (!(cab_path = strdupWtoA( path )))
309 FDIDestroy(hfdi);
310 msi_free(cabinet);
311 return FALSE;
314 data.package = package;
315 data.cab_path = cab_path;
317 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, &data);
319 if (!ret)
320 ERR("FDICopy failed\n");
322 FDIDestroy(hfdi);
324 msi_free(cabinet);
325 msi_free(cab_path);
327 return ret;
330 static VOID set_file_source(MSIPACKAGE* package, MSIFILE* file, MSICOMPONENT*
331 comp, LPCWSTR path)
333 if (file->Attributes & msidbFileAttributesNoncompressed)
335 LPWSTR p, path;
336 p = resolve_folder(package, comp->Directory, TRUE, FALSE, NULL);
337 path = build_directory_name(2, p, file->ShortName);
338 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
340 msi_free(path);
341 path = build_directory_name(2, p, file->LongName);
343 file->SourcePath = path;
344 msi_free(p);
346 else
347 file->SourcePath = build_directory_name(2, path, file->File);
350 struct media_info {
351 UINT last_sequence;
352 LPWSTR last_volume;
353 LPWSTR last_path;
354 DWORD count;
355 WCHAR source[MAX_PATH];
358 static struct media_info *create_media_info( void )
360 struct media_info *mi;
362 mi = msi_alloc( sizeof *mi );
363 if (mi)
365 mi->last_sequence = 0;
366 mi->last_volume = NULL;
367 mi->last_path = NULL;
368 mi->count = 0;
369 mi->source[0] = 0;
372 return mi;
375 static void free_media_info( struct media_info *mi )
377 msi_free( mi->last_path );
378 msi_free( mi );
381 static UINT ready_media_for_file( MSIPACKAGE *package, struct media_info *mi,
382 MSIFILE *file )
384 UINT rc = ERROR_SUCCESS;
385 MSIRECORD * row = 0;
386 static const WCHAR ExecSeqQuery[] =
387 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
388 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
389 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',
390 ' ','%', 'i',' ','O','R','D','E','R',' ','B','Y',' ',
391 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',0};
392 LPCWSTR cab, volume;
393 DWORD sz;
394 INT seq;
395 LPCWSTR prompt;
396 MSICOMPONENT *comp = file->Component;
398 if (file->Sequence <= mi->last_sequence)
400 set_file_source(package,file,comp,mi->last_path);
401 TRACE("Media already ready (%u, %u)\n",file->Sequence,mi->last_sequence);
402 return ERROR_SUCCESS;
405 mi->count ++;
406 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, file->Sequence);
407 if (!row)
409 TRACE("Unable to query row\n");
410 return ERROR_FUNCTION_FAILED;
413 seq = MSI_RecordGetInteger(row,2);
414 mi->last_sequence = seq;
416 volume = MSI_RecordGetString(row, 5);
417 prompt = MSI_RecordGetString(row, 3);
419 msi_free(mi->last_path);
420 mi->last_path = NULL;
422 if (file->Attributes & msidbFileAttributesNoncompressed)
424 mi->last_path = resolve_folder(package, comp->Directory, TRUE, FALSE, NULL);
425 set_file_source(package,file,comp,mi->last_path);
427 MsiSourceListAddMediaDiskW(package->ProductCode, NULL,
428 MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT, mi->count, volume,
429 prompt);
431 MsiSourceListSetInfoW(package->ProductCode, NULL,
432 MSIINSTALLCONTEXT_USERMANAGED,
433 MSICODE_PRODUCT|MSISOURCETYPE_MEDIA,
434 INSTALLPROPERTY_LASTUSEDSOURCEW, mi->last_path);
435 msiobj_release(&row->hdr);
436 return rc;
439 cab = MSI_RecordGetString(row,4);
440 if (cab)
442 TRACE("Source is CAB %s\n",debugstr_w(cab));
443 /* the stream does not contain the # character */
444 if (cab[0]=='#')
446 LPWSTR path;
448 writeout_cabinet_stream(package,&cab[1],mi->source);
449 mi->last_path = strdupW(mi->source);
450 *(strrchrW(mi->last_path,'\\')+1)=0;
452 path = msi_dup_property( package, cszSourceDir );
454 MsiSourceListAddMediaDiskW(package->ProductCode, NULL,
455 MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT, mi->count,
456 volume, prompt);
458 MsiSourceListSetInfoW(package->ProductCode, NULL,
459 MSIINSTALLCONTEXT_USERMANAGED,
460 MSICODE_PRODUCT|MSISOURCETYPE_NETWORK,
461 INSTALLPROPERTY_LASTUSEDSOURCEW, path);
463 msi_free(path);
465 else
467 sz = MAX_PATH;
468 mi->last_path = msi_alloc(MAX_PATH*sizeof(WCHAR));
469 if (MSI_GetPropertyW(package, cszSourceDir, mi->source, &sz))
471 ERR("No Source dir defined\n");
472 rc = ERROR_FUNCTION_FAILED;
474 else
476 strcpyW(mi->last_path,mi->source);
477 strcatW(mi->source,cab);
479 MsiSourceListSetInfoW(package->ProductCode, NULL,
480 MSIINSTALLCONTEXT_USERMANAGED,
481 MSICODE_PRODUCT|MSISOURCETYPE_MEDIA,
482 INSTALLPROPERTY_LASTUSEDSOURCEW, mi->last_path);
484 /* extract the cab file into a folder in the temp folder */
485 sz = MAX_PATH;
486 if (MSI_GetPropertyW(package, cszTempFolder,mi->last_path, &sz)
487 != ERROR_SUCCESS)
488 GetTempPathW(MAX_PATH,mi->last_path);
491 rc = !extract_cabinet_file(package, mi->source, mi->last_path);
493 else
495 sz = MAX_PATH;
496 mi->last_path = msi_alloc(MAX_PATH*sizeof(WCHAR));
497 MSI_GetPropertyW(package,cszSourceDir,mi->source,&sz);
498 strcpyW(mi->last_path,mi->source);
500 MsiSourceListSetInfoW(package->ProductCode, NULL,
501 MSIINSTALLCONTEXT_USERMANAGED,
502 MSICODE_PRODUCT|MSISOURCETYPE_MEDIA,
503 INSTALLPROPERTY_LASTUSEDSOURCEW, mi->last_path);
505 set_file_source(package, file, comp, mi->last_path);
507 MsiSourceListAddMediaDiskW(package->ProductCode, NULL,
508 MSIINSTALLCONTEXT_USERMANAGED, MSICODE_PRODUCT, mi->count, volume,
509 prompt);
511 msiobj_release(&row->hdr);
513 return rc;
516 static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
517 MSIFILE** file)
519 LIST_FOR_EACH_ENTRY( *file, &package->files, MSIFILE, entry )
521 if (lstrcmpW( file_key, (*file)->File )==0)
523 if ((*file)->state >= msifs_overwrite)
524 return ERROR_SUCCESS;
525 else
526 return ERROR_FILE_NOT_FOUND;
530 return ERROR_FUNCTION_FAILED;
534 * ACTION_InstallFiles()
536 * For efficiency, this is done in two passes:
537 * 1) Correct all the TargetPaths and determine what files are to be installed.
538 * 2) Extract Cabinets and copy files.
540 UINT ACTION_InstallFiles(MSIPACKAGE *package)
542 struct media_info *mi;
543 UINT rc = ERROR_SUCCESS;
544 LPWSTR ptr;
545 MSIFILE *file;
547 /* increment progress bar each time action data is sent */
548 ui_progress(package,1,1,0,0);
550 /* handle the keys for the SourceList */
551 ptr = strrchrW(package->PackagePath,'\\');
552 if (ptr)
554 ptr ++;
555 MsiSourceListSetInfoW(package->ProductCode, NULL,
556 MSIINSTALLCONTEXT_USERMANAGED,
557 MSICODE_PRODUCT,
558 INSTALLPROPERTY_PACKAGENAMEW, ptr);
560 /* FIXME("Write DiskPrompt\n"); */
562 /* Pass 1 */
563 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
565 if (!ACTION_VerifyComponentForAction( file->Component, INSTALLSTATE_LOCAL ))
567 ui_progress(package,2,file->FileSize,0,0);
568 TRACE("File %s is not scheduled for install\n",
569 debugstr_w(file->File));
571 file->state = msifs_skipped;
576 * Despite MSDN specifying that the CreateFolders action
577 * should be called before InstallFiles, some installers don't
578 * do that, and they seem to work correctly. We need to create
579 * directories here to make sure that the files can be copied.
581 msi_create_component_directories( package );
583 mi = create_media_info();
585 /* Pass 2 */
586 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
588 if (file->state != msifs_missing && file->state != msifs_overwrite)
589 continue;
591 TRACE("Pass 2: %s\n",debugstr_w(file->File));
593 rc = ready_media_for_file( package, mi, file );
594 if (rc != ERROR_SUCCESS)
596 ERR("Unable to ready media\n");
597 rc = ERROR_FUNCTION_FAILED;
598 break;
601 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
602 debugstr_w(file->TargetPath));
604 if (file->state != msifs_missing && file->state != msifs_overwrite)
605 continue;
607 /* compressed files are extracted in ready_media_for_file */
608 if (~file->Attributes & msidbFileAttributesNoncompressed)
610 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW(file->TargetPath))
611 ERR("compressed file wasn't extracted (%s)\n",
612 debugstr_w(file->TargetPath));
613 continue;
616 rc = CopyFileW(file->SourcePath,file->TargetPath,FALSE);
617 if (!rc)
619 rc = GetLastError();
620 ERR("Unable to copy file (%s -> %s) (error %d)\n",
621 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath), rc);
622 if (rc == ERROR_ALREADY_EXISTS && file->state == msifs_overwrite)
624 rc = 0;
626 else if (rc == ERROR_FILE_NOT_FOUND)
628 ERR("Source File Not Found! Continuing\n");
629 rc = 0;
631 else if (file->Attributes & msidbFileAttributesVital)
633 ERR("Ignoring Error and continuing (nonvital file)...\n");
634 rc = 0;
637 else
639 file->state = msifs_installed;
640 rc = ERROR_SUCCESS;
644 /* cleanup */
645 free_media_info( mi );
646 return rc;
649 static UINT ITERATE_DuplicateFiles(MSIRECORD *row, LPVOID param)
651 MSIPACKAGE *package = (MSIPACKAGE*)param;
652 WCHAR dest_name[0x100];
653 LPWSTR dest_path, dest;
654 LPCWSTR file_key, component;
655 DWORD sz;
656 DWORD rc;
657 MSICOMPONENT *comp;
658 MSIFILE *file;
660 component = MSI_RecordGetString(row,2);
661 comp = get_loaded_component(package,component);
663 if (!ACTION_VerifyComponentForAction( comp, INSTALLSTATE_LOCAL ))
665 TRACE("Skipping copy due to disabled component %s\n",
666 debugstr_w(component));
668 /* the action taken was the same as the current install state */
669 comp->Action = comp->Installed;
671 return ERROR_SUCCESS;
674 comp->Action = INSTALLSTATE_LOCAL;
676 file_key = MSI_RecordGetString(row,3);
677 if (!file_key)
679 ERR("Unable to get file key\n");
680 return ERROR_FUNCTION_FAILED;
683 rc = get_file_target(package,file_key,&file);
685 if (rc != ERROR_SUCCESS)
687 ERR("Original file unknown %s\n",debugstr_w(file_key));
688 return ERROR_SUCCESS;
691 if (MSI_RecordIsNull(row,4))
692 strcpyW(dest_name,strrchrW(file->TargetPath,'\\')+1);
693 else
695 sz=0x100;
696 MSI_RecordGetStringW(row,4,dest_name,&sz);
697 reduce_to_longfilename(dest_name);
700 if (MSI_RecordIsNull(row,5))
702 LPWSTR p;
703 dest_path = strdupW(file->TargetPath);
704 p = strrchrW(dest_path,'\\');
705 if (p)
706 *p=0;
708 else
710 LPCWSTR destkey;
711 destkey = MSI_RecordGetString(row,5);
712 dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
713 if (!dest_path)
715 /* try a Property */
716 dest_path = msi_dup_property( package, destkey );
717 if (!dest_path)
719 FIXME("Unable to get destination folder, try AppSearch properties\n");
720 return ERROR_SUCCESS;
725 dest = build_directory_name(2, dest_path, dest_name);
727 TRACE("Duplicating file %s to %s\n",debugstr_w(file->TargetPath),
728 debugstr_w(dest));
730 if (strcmpW(file->TargetPath,dest))
731 rc = !CopyFileW(file->TargetPath,dest,TRUE);
732 else
733 rc = ERROR_SUCCESS;
735 if (rc != ERROR_SUCCESS)
736 ERR("Failed to copy file %s -> %s, last error %ld\n",
737 debugstr_w(file->TargetPath), debugstr_w(dest_path), GetLastError());
739 FIXME("We should track these duplicate files as well\n");
741 msi_free(dest_path);
742 msi_free(dest);
744 msi_file_update_ui(package, file, szDuplicateFiles);
746 return ERROR_SUCCESS;
749 UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
751 UINT rc;
752 MSIQUERY * view;
753 static const WCHAR ExecSeqQuery[] =
754 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
755 '`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
757 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
758 if (rc != ERROR_SUCCESS)
759 return ERROR_SUCCESS;
761 rc = MSI_IterateRecords(view, NULL, ITERATE_DuplicateFiles, package);
762 msiobj_release(&view->hdr);
764 return rc;
767 UINT ACTION_RemoveFiles( MSIPACKAGE *package )
769 MSIFILE *file;
771 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
773 MSIRECORD *uirow;
774 LPWSTR uipath, p;
776 if ( !file->Component )
777 continue;
778 if ( file->Component->Installed == INSTALLSTATE_LOCAL )
779 continue;
781 if ( file->state == msifs_installed )
782 ERR("removing installed file %s\n", debugstr_w(file->TargetPath));
784 if ( file->state != msifs_present )
785 continue;
787 TRACE("removing %s\n", debugstr_w(file->File) );
788 if ( !DeleteFileW( file->TargetPath ) )
789 ERR("failed to delete %s\n", debugstr_w(file->TargetPath) );
790 file->state = msifs_missing;
792 /* the UI chunk */
793 uirow = MSI_CreateRecord( 9 );
794 MSI_RecordSetStringW( uirow, 1, file->FileName );
795 uipath = strdupW( file->TargetPath );
796 p = strrchrW(uipath,'\\');
797 if (p)
798 p[1]=0;
799 MSI_RecordSetStringW( uirow, 9, uipath);
800 ui_actiondata( package, szRemoveFiles, uirow);
801 msiobj_release( &uirow->hdr );
802 msi_free( uipath );
803 /* FIXME: call ui_progress here? */
806 return ERROR_SUCCESS;