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 * Here are helper functions formally in action.c that are used by a variety of
23 * actions and functions.
29 #include "wine/debug.h"
32 #include "wine/unicode.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
37 static const WCHAR cszTargetDir
[] = {'T','A','R','G','E','T','D','I','R',0};
38 static const WCHAR cszDatabase
[]={'D','A','T','A','B','A','S','E',0};
40 const WCHAR cszSourceDir
[] = {'S','o','u','r','c','e','D','i','r',0};
41 const WCHAR cszSOURCEDIR
[] = {'S','O','U','R','C','E','D','I','R',0};
42 const WCHAR cszRootDrive
[] = {'R','O','O','T','D','R','I','V','E',0};
43 const WCHAR cszbs
[]={'\\',0};
44 const WCHAR szLocalSid
[] = {'S','-','1','-','5','-','1','8',0};
46 LPWSTR
build_icon_path(MSIPACKAGE
*package
, LPCWSTR icon_name
)
48 LPWSTR SystemFolder
, dest
, FilePath
;
50 static const WCHAR szInstaller
[] =
51 {'M','i','c','r','o','s','o','f','t','\\',
52 'I','n','s','t','a','l','l','e','r','\\',0};
53 static const WCHAR szFolder
[] =
54 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
56 SystemFolder
= msi_dup_property( package
, szFolder
);
58 dest
= build_directory_name(3, SystemFolder
, szInstaller
, package
->ProductCode
);
60 create_full_pathW(dest
);
62 FilePath
= build_directory_name(2, dest
, icon_name
);
64 msi_free(SystemFolder
);
69 LPWSTR
msi_dup_record_field( MSIRECORD
*rec
, INT field
)
75 if (MSI_RecordIsNull( rec
, field
))
78 r
= MSI_RecordGetStringW( rec
, field
, NULL
, &sz
);
79 if (r
!= ERROR_SUCCESS
)
83 str
= msi_alloc( sz
* sizeof (WCHAR
) );
87 r
= MSI_RecordGetStringW( rec
, field
, str
, &sz
);
88 if (r
!= ERROR_SUCCESS
)
90 ERR("failed to get string!\n");
97 MSICOMPONENT
* get_loaded_component( MSIPACKAGE
* package
, LPCWSTR Component
)
101 LIST_FOR_EACH_ENTRY( comp
, &package
->components
, MSICOMPONENT
, entry
)
103 if (lstrcmpW(Component
,comp
->Component
)==0)
109 MSIFEATURE
* get_loaded_feature(MSIPACKAGE
* package
, LPCWSTR Feature
)
113 LIST_FOR_EACH_ENTRY( feature
, &package
->features
, MSIFEATURE
, entry
)
115 if (lstrcmpW( Feature
, feature
->Feature
)==0)
121 MSIFILE
* get_loaded_file( MSIPACKAGE
* package
, LPCWSTR key
)
125 LIST_FOR_EACH_ENTRY( file
, &package
->files
, MSIFILE
, entry
)
127 if (lstrcmpW( key
, file
->File
)==0)
133 int track_tempfile( MSIPACKAGE
*package
, LPCWSTR path
)
137 TRACE("%s\n", debugstr_w(path
));
139 LIST_FOR_EACH_ENTRY( temp
, &package
->tempfiles
, MSITEMPFILE
, entry
)
140 if (!lstrcmpW( path
, temp
->Path
))
143 temp
= msi_alloc_zero( sizeof (MSITEMPFILE
) );
147 list_add_head( &package
->tempfiles
, &temp
->entry
);
148 temp
->Path
= strdupW( path
);
153 MSIFOLDER
*get_loaded_folder( MSIPACKAGE
*package
, LPCWSTR dir
)
157 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
159 if (lstrcmpW( dir
, folder
->Directory
)==0)
165 void msi_reset_folders( MSIPACKAGE
*package
, BOOL source
)
169 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
173 msi_free( folder
->ResolvedSource
);
174 folder
->ResolvedSource
= NULL
;
178 msi_free( folder
->ResolvedTarget
);
179 folder
->ResolvedTarget
= NULL
;
184 static LPWSTR
get_source_root( MSIPACKAGE
*package
)
188 path
= msi_dup_property( package
, cszSourceDir
);
192 path
= msi_dup_property( package
, cszDatabase
);
195 p
= strrchrW(path
,'\\');
203 * clean_spaces_from_path()
205 * removes spaces from the beginning and end of path segments
206 * removes multiple \\ characters
208 static void clean_spaces_from_path( LPWSTR p
)
215 /* copy until the end of the string or a space */
216 while (*p
!= ' ' && (*q
= *p
))
219 /* reduce many backslashes to one */
220 if (*p
!= '\\' || *q
!= '\\')
224 /* quit at the end of the string */
228 /* count the number of spaces */
233 /* if it's leading or trailing space, skip it */
234 if ( len
== 0 || p
[-1] == '\\' || p
[n
] == '\\' )
236 else /* copy n spaces */
237 while (n
&& (*q
++ = *p
++)) n
--;
241 LPWSTR
resolve_file_source(MSIPACKAGE
*package
, MSIFILE
*file
)
245 TRACE("Working to resolve source of file %s\n", debugstr_w(file
->File
));
247 if (file
->IsCompressed
)
250 p
= resolve_folder(package
, file
->Component
->Directory
,
251 TRUE
, FALSE
, TRUE
, NULL
);
252 path
= build_directory_name(2, p
, file
->ShortName
);
254 if (file
->LongName
&&
255 GetFileAttributesW(path
) == INVALID_FILE_ATTRIBUTES
)
258 path
= build_directory_name(2, p
, file
->LongName
);
263 TRACE("file %s source resolves to %s\n", debugstr_w(file
->File
),
269 LPWSTR
resolve_folder(MSIPACKAGE
*package
, LPCWSTR name
, BOOL source
,
270 BOOL set_prop
, BOOL load_prop
, MSIFOLDER
**folder
)
273 LPWSTR p
, path
= NULL
, parent
;
275 TRACE("Working to resolve %s\n",debugstr_w(name
));
280 if (!lstrcmpW(name
,cszSourceDir
))
283 f
= get_loaded_folder( package
, name
);
287 /* special resolving for Target and Source root dir */
288 if (!strcmpW(name
,cszTargetDir
))
290 if (!f
->ResolvedTarget
&& !f
->Property
)
293 check_path
= msi_dup_property( package
, cszTargetDir
);
296 check_path
= msi_dup_property( package
, cszRootDrive
);
298 MSI_SetPropertyW(package
,cszTargetDir
,check_path
);
301 /* correct misbuilt target dir */
302 path
= build_directory_name(2, check_path
, NULL
);
303 clean_spaces_from_path( path
);
304 if (strcmpiW(path
,check_path
)!=0)
305 MSI_SetPropertyW(package
,cszTargetDir
,path
);
306 msi_free(check_path
);
308 f
->ResolvedTarget
= path
;
311 if (!f
->ResolvedSource
)
312 f
->ResolvedSource
= get_source_root( package
);
318 if (!source
&& f
->ResolvedTarget
)
320 path
= strdupW( f
->ResolvedTarget
);
321 TRACE(" already resolved to %s\n",debugstr_w(path
));
325 if (source
&& f
->ResolvedSource
)
327 path
= strdupW( f
->ResolvedSource
);
328 TRACE(" (source)already resolved to %s\n",debugstr_w(path
));
332 if (!source
&& f
->Property
)
334 path
= build_directory_name( 2, f
->Property
, NULL
);
336 TRACE(" internally set to %s\n",debugstr_w(path
));
338 MSI_SetPropertyW( package
, name
, path
);
342 if (!source
&& load_prop
&& (path
= msi_dup_property( package
, name
)))
344 f
->ResolvedTarget
= strdupW( path
);
345 TRACE(" property set to %s\n", debugstr_w(path
));
354 TRACE(" ! Parent is %s\n", debugstr_w(parent
));
356 p
= resolve_folder(package
, parent
, source
, set_prop
, load_prop
, NULL
);
359 TRACE(" TargetDefault = %s\n", debugstr_w(f
->TargetDefault
));
361 path
= build_directory_name( 3, p
, f
->TargetDefault
, NULL
);
362 clean_spaces_from_path( path
);
363 f
->ResolvedTarget
= strdupW( path
);
364 TRACE("target -> %s\n", debugstr_w(path
));
366 MSI_SetPropertyW(package
,name
,path
);
372 if (package
->WordCount
& msidbSumInfoSourceTypeCompressed
)
373 path
= get_source_root( package
);
374 else if (package
->WordCount
& msidbSumInfoSourceTypeSFN
)
375 path
= build_directory_name( 3, p
, f
->SourceShortPath
, NULL
);
377 path
= build_directory_name( 3, p
, f
->SourceLongPath
, NULL
);
379 TRACE("source -> %s\n", debugstr_w(path
));
380 f
->ResolvedSource
= strdupW( path
);
387 /* wrapper to resist a need for a full rewrite right now */
388 DWORD
deformat_string(MSIPACKAGE
*package
, LPCWSTR ptr
, WCHAR
** data
)
392 MSIRECORD
*rec
= MSI_CreateRecord(1);
395 MSI_RecordSetStringW(rec
,0,ptr
);
396 MSI_FormatRecordW(package
,rec
,NULL
,&size
);
399 *data
= msi_alloc(size
*sizeof(WCHAR
));
401 MSI_FormatRecordW(package
,rec
,*data
,&size
);
405 msiobj_release( &rec
->hdr
);
406 return sizeof(WCHAR
)*size
;
413 UINT
schedule_action(MSIPACKAGE
*package
, UINT script
, LPCWSTR action
)
416 LPWSTR
*newbuf
= NULL
;
417 if (script
>= TOTAL_SCRIPTS
)
419 FIXME("Unknown script requested %i\n",script
);
420 return ERROR_FUNCTION_FAILED
;
422 TRACE("Scheduling Action %s in script %i\n",debugstr_w(action
), script
);
424 count
= package
->script
->ActionCount
[script
];
425 package
->script
->ActionCount
[script
]++;
427 newbuf
= msi_realloc( package
->script
->Actions
[script
],
428 package
->script
->ActionCount
[script
]* sizeof(LPWSTR
));
430 newbuf
= msi_alloc( sizeof(LPWSTR
));
432 newbuf
[count
] = strdupW(action
);
433 package
->script
->Actions
[script
] = newbuf
;
435 return ERROR_SUCCESS
;
438 void msi_free_action_script(MSIPACKAGE
*package
, UINT script
)
441 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
442 msi_free(package
->script
->Actions
[script
][i
]);
444 msi_free(package
->script
->Actions
[script
]);
445 package
->script
->Actions
[script
] = NULL
;
446 package
->script
->ActionCount
[script
] = 0;
449 static void remove_tracked_tempfiles(MSIPACKAGE
* package
)
451 struct list
*item
, *cursor
;
453 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->tempfiles
)
455 MSITEMPFILE
*temp
= LIST_ENTRY( item
, MSITEMPFILE
, entry
);
457 list_remove( &temp
->entry
);
458 TRACE("deleting temp file %s\n", debugstr_w( temp
->Path
));
459 if (!DeleteFileW( temp
->Path
))
460 ERR("failed to delete %s\n", debugstr_w( temp
->Path
));
461 msi_free( temp
->Path
);
466 static void free_feature( MSIFEATURE
*feature
)
468 struct list
*item
, *cursor
;
470 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Children
)
472 FeatureList
*fl
= LIST_ENTRY( item
, FeatureList
, entry
);
473 list_remove( &fl
->entry
);
477 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Components
)
479 ComponentList
*cl
= LIST_ENTRY( item
, ComponentList
, entry
);
480 list_remove( &cl
->entry
);
483 msi_free( feature
->Feature
);
484 msi_free( feature
->Feature_Parent
);
485 msi_free( feature
->Directory
);
486 msi_free( feature
->Description
);
487 msi_free( feature
->Title
);
491 static void free_extension( MSIEXTENSION
*ext
)
493 struct list
*item
, *cursor
;
495 LIST_FOR_EACH_SAFE( item
, cursor
, &ext
->verbs
)
497 MSIVERB
*verb
= LIST_ENTRY( item
, MSIVERB
, entry
);
499 list_remove( &verb
->entry
);
500 msi_free( verb
->Verb
);
501 msi_free( verb
->Command
);
502 msi_free( verb
->Argument
);
506 msi_free( ext
->Extension
);
507 msi_free( ext
->ProgIDText
);
511 /* Called when the package is being closed */
512 void ACTION_free_package_structures( MSIPACKAGE
* package
)
515 struct list
*item
, *cursor
;
517 TRACE("Freeing package action data\n");
519 remove_tracked_tempfiles(package
);
521 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->features
)
523 MSIFEATURE
*feature
= LIST_ENTRY( item
, MSIFEATURE
, entry
);
524 list_remove( &feature
->entry
);
525 free_feature( feature
);
528 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->folders
)
530 MSIFOLDER
*folder
= LIST_ENTRY( item
, MSIFOLDER
, entry
);
532 list_remove( &folder
->entry
);
533 msi_free( folder
->Parent
);
534 msi_free( folder
->Directory
);
535 msi_free( folder
->TargetDefault
);
536 msi_free( folder
->SourceLongPath
);
537 msi_free( folder
->SourceShortPath
);
538 msi_free( folder
->ResolvedTarget
);
539 msi_free( folder
->ResolvedSource
);
540 msi_free( folder
->Property
);
544 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->components
)
546 MSICOMPONENT
*comp
= LIST_ENTRY( item
, MSICOMPONENT
, entry
);
548 list_remove( &comp
->entry
);
549 msi_free( comp
->Component
);
550 msi_free( comp
->ComponentId
);
551 msi_free( comp
->Directory
);
552 msi_free( comp
->Condition
);
553 msi_free( comp
->KeyPath
);
554 msi_free( comp
->FullKeypath
);
558 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->files
)
560 MSIFILE
*file
= LIST_ENTRY( item
, MSIFILE
, entry
);
562 list_remove( &file
->entry
);
563 msi_free( file
->File
);
564 msi_free( file
->FileName
);
565 msi_free( file
->ShortName
);
566 msi_free( file
->LongName
);
567 msi_free( file
->Version
);
568 msi_free( file
->Language
);
569 msi_free( file
->TargetPath
);
573 /* clean up extension, progid, class and verb structures */
574 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->classes
)
576 MSICLASS
*cls
= LIST_ENTRY( item
, MSICLASS
, entry
);
578 list_remove( &cls
->entry
);
579 msi_free( cls
->clsid
);
580 msi_free( cls
->Context
);
581 msi_free( cls
->Description
);
582 msi_free( cls
->FileTypeMask
);
583 msi_free( cls
->IconPath
);
584 msi_free( cls
->DefInprocHandler
);
585 msi_free( cls
->DefInprocHandler32
);
586 msi_free( cls
->Argument
);
587 msi_free( cls
->ProgIDText
);
591 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->extensions
)
593 MSIEXTENSION
*ext
= LIST_ENTRY( item
, MSIEXTENSION
, entry
);
595 list_remove( &ext
->entry
);
596 free_extension( ext
);
599 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->progids
)
601 MSIPROGID
*progid
= LIST_ENTRY( item
, MSIPROGID
, entry
);
603 list_remove( &progid
->entry
);
604 msi_free( progid
->ProgID
);
605 msi_free( progid
->Description
);
606 msi_free( progid
->IconPath
);
610 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->mimes
)
612 MSIMIME
*mt
= LIST_ENTRY( item
, MSIMIME
, entry
);
614 list_remove( &mt
->entry
);
615 msi_free( mt
->clsid
);
616 msi_free( mt
->ContentType
);
620 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->appids
)
622 MSIAPPID
*appid
= LIST_ENTRY( item
, MSIAPPID
, entry
);
624 list_remove( &appid
->entry
);
625 msi_free( appid
->AppID
);
626 msi_free( appid
->RemoteServerName
);
627 msi_free( appid
->LocalServer
);
628 msi_free( appid
->ServiceParameters
);
629 msi_free( appid
->DllSurrogate
);
633 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_info
)
635 MSISOURCELISTINFO
*info
= LIST_ENTRY( item
, MSISOURCELISTINFO
, entry
);
637 list_remove( &info
->entry
);
638 msi_free( info
->value
);
642 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_media
)
644 MSIMEDIADISK
*info
= LIST_ENTRY( item
, MSIMEDIADISK
, entry
);
646 list_remove( &info
->entry
);
647 msi_free( info
->volume_label
);
648 msi_free( info
->disk_prompt
);
654 for (i
= 0; i
< TOTAL_SCRIPTS
; i
++)
655 msi_free_action_script(package
, i
);
657 for (i
= 0; i
< package
->script
->UniqueActionsCount
; i
++)
658 msi_free(package
->script
->UniqueActions
[i
]);
660 msi_free(package
->script
->UniqueActions
);
661 msi_free(package
->script
);
666 msi_free(package
->patch
->patchcode
);
667 msi_free(package
->patch
->transforms
);
668 msi_free(package
->patch
);
671 msi_free(package
->BaseURL
);
672 msi_free(package
->PackagePath
);
673 msi_free(package
->ProductCode
);
674 msi_free(package
->ActionFormat
);
675 msi_free(package
->LastAction
);
677 /* cleanup control event subscriptions */
678 ControlEvent_CleanupSubscriptions(package
);
682 * build_directory_name()
684 * This function is to save messing round with directory names
685 * It handles adding backslashes between path segments,
686 * and can add \ at the end of the directory name if told to.
688 * It takes a variable number of arguments.
689 * It always allocates a new string for the result, so make sure
690 * to free the return value when finished with it.
692 * The first arg is the number of path segments that follow.
693 * The arguments following count are a list of path segments.
694 * A path segment may be NULL.
696 * Path segments will be added with a \ separating them.
697 * A \ will not be added after the last segment, however if the
698 * last segment is NULL, then the last character will be a \
701 LPWSTR
build_directory_name(DWORD count
, ...)
708 for(i
=0; i
<count
; i
++)
710 LPCWSTR str
= va_arg(va
,LPCWSTR
);
712 sz
+= strlenW(str
) + 1;
716 dir
= msi_alloc(sz
*sizeof(WCHAR
));
720 for(i
=0; i
<count
; i
++)
722 LPCWSTR str
= va_arg(va
,LPCWSTR
);
726 if( ((i
+1)!=count
) && dir
[strlenW(dir
)-1]!='\\')
732 /***********************************************************************
735 * Recursively create all directories in the path.
737 * shamelessly stolen from setupapi/queue.c
739 BOOL
create_full_pathW(const WCHAR
*path
)
745 new_path
= msi_alloc( (strlenW(path
) + 1) * sizeof(WCHAR
));
747 strcpyW(new_path
, path
);
749 while((len
= strlenW(new_path
)) && new_path
[len
- 1] == '\\')
750 new_path
[len
- 1] = 0;
752 while(!CreateDirectoryW(new_path
, NULL
))
755 DWORD last_error
= GetLastError();
756 if(last_error
== ERROR_ALREADY_EXISTS
)
759 if(last_error
!= ERROR_PATH_NOT_FOUND
)
765 if(!(slash
= strrchrW(new_path
, '\\')))
771 len
= slash
- new_path
;
773 if(!create_full_pathW(new_path
))
778 new_path
[len
] = '\\';
785 void ui_progress(MSIPACKAGE
*package
, int a
, int b
, int c
, int d
)
789 row
= MSI_CreateRecord(4);
790 MSI_RecordSetInteger(row
,1,a
);
791 MSI_RecordSetInteger(row
,2,b
);
792 MSI_RecordSetInteger(row
,3,c
);
793 MSI_RecordSetInteger(row
,4,d
);
794 MSI_ProcessMessage(package
, INSTALLMESSAGE_PROGRESS
, row
);
795 msiobj_release(&row
->hdr
);
797 msi_dialog_check_messages(NULL
);
800 void ui_actiondata(MSIPACKAGE
*package
, LPCWSTR action
, MSIRECORD
* record
)
802 static const WCHAR Query_t
[] =
803 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
804 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
805 'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=',
806 ' ','\'','%','s','\'',0};
811 if (!package
->LastAction
|| strcmpW(package
->LastAction
,action
))
813 row
= MSI_QueryGetRecord(package
->db
, Query_t
, action
);
817 if (MSI_RecordIsNull(row
,3))
819 msiobj_release(&row
->hdr
);
823 /* update the cached actionformat */
824 msi_free(package
->ActionFormat
);
825 package
->ActionFormat
= msi_dup_record_field(row
,3);
827 msi_free(package
->LastAction
);
828 package
->LastAction
= strdupW(action
);
830 msiobj_release(&row
->hdr
);
833 MSI_RecordSetStringW(record
,0,package
->ActionFormat
);
835 MSI_FormatRecordW(package
,record
,message
,&size
);
837 row
= MSI_CreateRecord(1);
838 MSI_RecordSetStringW(row
,1,message
);
840 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, row
);
842 msiobj_release(&row
->hdr
);
845 BOOL
ACTION_VerifyComponentForAction( const MSICOMPONENT
* comp
, INSTALLSTATE check
)
850 if (comp
->ActionRequest
== check
)
856 BOOL
ACTION_VerifyFeatureForAction( const MSIFEATURE
* feature
, INSTALLSTATE check
)
861 if (feature
->ActionRequest
== check
)
867 void reduce_to_longfilename(WCHAR
* filename
)
869 LPWSTR p
= strchrW(filename
,'|');
871 memmove(filename
, p
+1, (strlenW(p
+1)+1)*sizeof(WCHAR
));
874 void reduce_to_shortfilename(WCHAR
* filename
)
876 LPWSTR p
= strchrW(filename
,'|');
881 LPWSTR
create_component_advertise_string(MSIPACKAGE
* package
,
882 MSICOMPONENT
* component
, LPCWSTR feature
)
884 static const WCHAR fmt
[] = {'%','s','%','s','%','c','%','s',0};
885 WCHAR productid_85
[21], component_85
[21];
886 LPWSTR output
= NULL
;
890 /* > is used if there is a component GUID and < if not. */
895 CLSIDFromString(package
->ProductCode
, &clsid
);
896 encode_base85_guid(&clsid
, productid_85
);
900 CLSIDFromString(component
->ComponentId
, &clsid
);
901 encode_base85_guid(&clsid
, component_85
);
904 TRACE("prod=%s feat=%s comp=%s\n", debugstr_w(productid_85
),
905 debugstr_w(feature
), debugstr_w(component_85
));
907 sz
= 20 + lstrlenW(feature
) + 20 + 3;
909 output
= msi_alloc_zero(sz
*sizeof(WCHAR
));
911 sprintfW(output
, fmt
, productid_85
, feature
,
912 component
?'>':'<', component_85
);
917 /* update component state based on a feature change */
918 void ACTION_UpdateComponentStates(MSIPACKAGE
*package
, LPCWSTR szFeature
)
920 INSTALLSTATE newstate
;
924 feature
= get_loaded_feature(package
,szFeature
);
928 newstate
= feature
->ActionRequest
;
930 if (newstate
== INSTALLSTATE_ABSENT
)
931 newstate
= INSTALLSTATE_UNKNOWN
;
933 LIST_FOR_EACH_ENTRY( cl
, &feature
->Components
, ComponentList
, entry
)
935 MSICOMPONENT
* component
= cl
->component
;
937 TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
938 newstate
, debugstr_w(component
->Component
), component
->Installed
,
939 component
->Action
, component
->ActionRequest
);
941 if (!component
->Enabled
)
944 if (newstate
== INSTALLSTATE_LOCAL
)
945 msi_component_set_state(package
, component
, INSTALLSTATE_LOCAL
);
948 ComponentList
*clist
;
951 component
->hasLocalFeature
= FALSE
;
953 msi_component_set_state(package
, component
, newstate
);
955 /*if any other feature wants is local we need to set it local*/
956 LIST_FOR_EACH_ENTRY( f
, &package
->features
, MSIFEATURE
, entry
)
958 if ( f
->ActionRequest
!= INSTALLSTATE_LOCAL
&&
959 f
->ActionRequest
!= INSTALLSTATE_SOURCE
)
964 LIST_FOR_EACH_ENTRY( clist
, &f
->Components
, ComponentList
, entry
)
966 if ( clist
->component
== component
&&
967 (f
->ActionRequest
== INSTALLSTATE_LOCAL
||
968 f
->ActionRequest
== INSTALLSTATE_SOURCE
) )
970 TRACE("Saved by %s\n", debugstr_w(f
->Feature
));
971 component
->hasLocalFeature
= TRUE
;
973 if (component
->Attributes
& msidbComponentAttributesOptional
)
975 if (f
->Attributes
& msidbFeatureAttributesFavorSource
)
976 msi_component_set_state(package
, component
, INSTALLSTATE_SOURCE
);
978 msi_component_set_state(package
, component
, INSTALLSTATE_LOCAL
);
980 else if (component
->Attributes
& msidbComponentAttributesSourceOnly
)
981 msi_component_set_state(package
, component
, INSTALLSTATE_SOURCE
);
983 msi_component_set_state(package
, component
, INSTALLSTATE_LOCAL
);
988 TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
989 newstate
, debugstr_w(component
->Component
), component
->Installed
,
990 component
->Action
, component
->ActionRequest
);
994 UINT
register_unique_action(MSIPACKAGE
*package
, LPCWSTR action
)
997 LPWSTR
*newbuf
= NULL
;
999 if (!package
->script
)
1002 TRACE("Registering Action %s as having fun\n",debugstr_w(action
));
1004 count
= package
->script
->UniqueActionsCount
;
1005 package
->script
->UniqueActionsCount
++;
1007 newbuf
= msi_realloc( package
->script
->UniqueActions
,
1008 package
->script
->UniqueActionsCount
* sizeof(LPWSTR
));
1010 newbuf
= msi_alloc( sizeof(LPWSTR
));
1012 newbuf
[count
] = strdupW(action
);
1013 package
->script
->UniqueActions
= newbuf
;
1015 return ERROR_SUCCESS
;
1018 BOOL
check_unique_action(const MSIPACKAGE
*package
, LPCWSTR action
)
1022 if (!package
->script
)
1025 for (i
= 0; i
< package
->script
->UniqueActionsCount
; i
++)
1026 if (!strcmpW(package
->script
->UniqueActions
[i
],action
))
1032 WCHAR
* generate_error_string(MSIPACKAGE
*package
, UINT error
, DWORD count
, ... )
1034 static const WCHAR query
[] = {'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ','F','R','O','M',' ','`','E','r','r','o','r','`',' ','W','H','E','R','E',' ','`','E','r','r','o','r','`',' ','=',' ','%','i',0};
1044 row
= MSI_QueryGetRecord(package
->db
, query
, error
);
1048 rec
= MSI_CreateRecord(count
+2);
1050 str
= MSI_RecordGetString(row
,1);
1051 MSI_RecordSetStringW(rec
,0,str
);
1052 msiobj_release( &row
->hdr
);
1053 MSI_RecordSetInteger(rec
,1,error
);
1056 for (i
= 0; i
< count
; i
++)
1058 str
= va_arg(va
,LPCWSTR
);
1059 MSI_RecordSetStringW(rec
,(i
+2),str
);
1063 MSI_FormatRecordW(package
,rec
,NULL
,&size
);
1066 data
= msi_alloc(size
*sizeof(WCHAR
));
1068 MSI_FormatRecordW(package
,rec
,data
,&size
);
1071 msiobj_release( &rec
->hdr
);
1075 void msi_ui_error( DWORD msg_id
, DWORD type
)
1079 static const WCHAR title
[] = {
1080 'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0
1083 if (!MsiLoadStringW( -1, msg_id
, text
, sizeof(text
) / sizeof(text
[0]),
1084 MAKELANGID(LANG_NEUTRAL
, SUBLANG_NEUTRAL
) ))
1087 MessageBoxW( NULL
, text
, title
, type
);