wined3d: Add UpdatOverlayZOrder.
[wine.git] / dlls / msi / helpers.c
blob868d737bd6147659a103d4e500d2b23f76386834
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
22 * Here are helper functions formally in action.c that are used by a variaty of
23 * actions and functions.
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winerror.h"
31 #include "wine/debug.h"
32 #include "msipriv.h"
33 #include "winuser.h"
34 #include "wine/unicode.h"
35 #include "action.h"
36 #include "msidefs.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(msi);
40 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
41 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
43 const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
44 const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
45 const WCHAR cszbs[]={'\\',0};
47 LPWSTR build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name )
49 LPWSTR SystemFolder, dest, FilePath;
51 static const WCHAR szInstaller[] =
52 {'M','i','c','r','o','s','o','f','t','\\',
53 'I','n','s','t','a','l','l','e','r','\\',0};
54 static const WCHAR szFolder[] =
55 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
57 SystemFolder = msi_dup_property( package, szFolder );
59 dest = build_directory_name(3, SystemFolder, szInstaller, package->ProductCode);
61 create_full_pathW(dest);
63 FilePath = build_directory_name(2, dest, icon_name);
65 msi_free(SystemFolder);
66 msi_free(dest);
67 return FilePath;
70 LPWSTR msi_dup_record_field( MSIRECORD *row, INT index )
72 return strdupW( MSI_RecordGetString(row,index) );
75 MSICOMPONENT* get_loaded_component( MSIPACKAGE* package, LPCWSTR Component )
77 MSICOMPONENT *comp;
79 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
81 if (lstrcmpW(Component,comp->Component)==0)
82 return comp;
84 return NULL;
87 MSIFEATURE* get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
89 MSIFEATURE *feature;
91 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
93 if (lstrcmpW( Feature, feature->Feature )==0)
94 return feature;
96 return NULL;
99 MSIFILE* get_loaded_file( MSIPACKAGE* package, LPCWSTR key )
101 MSIFILE *file;
103 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
105 if (lstrcmpW( key, file->File )==0)
106 return file;
108 return NULL;
111 int track_tempfile( MSIPACKAGE *package, LPCWSTR name, LPCWSTR path )
113 MSITEMPFILE *temp;
115 LIST_FOR_EACH_ENTRY( temp, &package->tempfiles, MSITEMPFILE, entry )
117 if (lstrcmpW( name, temp->File )==0)
119 TRACE("tempfile %s already exists with path %s\n",
120 debugstr_w(temp->File), debugstr_w(temp->Path));
121 return -1;
125 temp = msi_alloc_zero( sizeof (MSITEMPFILE) );
126 if (!temp)
127 return -1;
129 list_add_head( &package->tempfiles, &temp->entry );
131 temp->File = strdupW( name );
132 temp->Path = strdupW( path );
134 TRACE("adding tempfile %s with path %s\n",
135 debugstr_w(temp->File), debugstr_w(temp->Path));
137 return 0;
140 MSIFOLDER *get_loaded_folder( MSIPACKAGE *package, LPCWSTR dir )
142 MSIFOLDER *folder;
144 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
146 if (lstrcmpW( dir, folder->Directory )==0)
147 return folder;
149 return NULL;
152 static LPWSTR get_source_root( MSIPACKAGE *package )
154 LPWSTR path, p;
156 path = msi_dup_property( package, cszSourceDir );
157 if (path)
158 return path;
160 path = msi_dup_property( package, cszDatabase );
161 if (path)
163 p = strrchrW(path,'\\');
164 if (p)
165 *(p+1) = 0;
167 return path;
171 * clean_spaces_from_path()
173 * removes spaces from the beginning and end of path segments
174 * removes multiple \\ characters
176 static void clean_spaces_from_path( LPWSTR p )
178 LPWSTR q = p;
179 int n, len = 0;
181 while (1)
183 /* copy until the end of the string or a space */
184 while (*p != ' ' && (*q = *p))
186 p++, len++;
187 /* reduce many backslashes to one */
188 if (*p != '\\' || *q != '\\')
189 q++;
192 /* quit at the end of the string */
193 if (!*p)
194 break;
196 /* count the number of spaces */
197 n = 0;
198 while (p[n] == ' ')
199 n++;
201 /* if it's leading or trailing space, skip it */
202 if ( len == 0 || p[-1] == '\\' || p[n] == '\\' )
203 p += n;
204 else /* copy n spaces */
205 while (n && (*q++ = *p++)) n--;
209 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
210 BOOL set_prop, MSIFOLDER **folder)
212 MSIFOLDER *f;
213 LPWSTR p, path = NULL;
215 TRACE("Working to resolve %s\n",debugstr_w(name));
217 if (!name)
218 return NULL;
220 f = get_loaded_folder( package, name );
221 if (!f)
222 return NULL;
224 /* special resolving for Target and Source root dir */
225 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
227 if (!f->ResolvedTarget && !f->Property)
229 LPWSTR check_path;
230 check_path = msi_dup_property( package, cszTargetDir );
231 if (!check_path)
233 check_path = msi_dup_property( package, cszRootDrive );
234 if (set_prop)
235 MSI_SetPropertyW(package,cszTargetDir,check_path);
238 /* correct misbuilt target dir */
239 path = build_directory_name(2, check_path, NULL);
240 clean_spaces_from_path( path );
241 if (strcmpiW(path,check_path)!=0)
242 MSI_SetPropertyW(package,cszTargetDir,path);
243 msi_free(check_path);
245 f->ResolvedTarget = path;
248 if (!f->ResolvedSource)
249 f->ResolvedSource = get_source_root( package );
252 if (folder)
253 *folder = f;
255 if (!source && f->ResolvedTarget)
257 path = strdupW( f->ResolvedTarget );
258 TRACE(" already resolved to %s\n",debugstr_w(path));
259 return path;
261 else if (source && f->ResolvedSource)
263 path = strdupW( f->ResolvedSource );
264 TRACE(" (source)already resolved to %s\n",debugstr_w(path));
265 return path;
267 else if (!source && f->Property)
269 path = build_directory_name( 2, f->Property, NULL );
271 TRACE(" internally set to %s\n",debugstr_w(path));
272 if (set_prop)
273 MSI_SetPropertyW( package, name, path );
274 return path;
277 if (f->Parent)
279 LPWSTR parent = f->Parent->Directory;
281 TRACE(" ! Parent is %s\n", debugstr_w(parent));
283 p = resolve_folder(package, parent, source, set_prop, NULL);
284 if (!source)
286 TRACE(" TargetDefault = %s\n", debugstr_w(f->TargetDefault));
288 path = build_directory_name( 3, p, f->TargetDefault, NULL );
289 clean_spaces_from_path( path );
290 f->ResolvedTarget = strdupW( path );
291 TRACE("target -> %s\n", debugstr_w(path));
292 if (set_prop)
293 MSI_SetPropertyW(package,name,path);
295 else
297 /* source may be in a few different places ... check each of them */
298 path = NULL;
300 /* try the long path directory */
301 if (f->SourceLongPath)
303 path = build_directory_name( 3, p, f->SourceLongPath, NULL );
304 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
306 msi_free( path );
307 path = NULL;
311 /* try the short path directory */
312 if (!path && f->SourceShortPath)
314 path = build_directory_name( 3, p, f->SourceShortPath, NULL );
315 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
317 msi_free( path );
318 path = NULL;
322 /* try the root of the install */
323 if (!path)
324 path = get_source_root( package );
326 TRACE("source -> %s\n", debugstr_w(path));
327 f->ResolvedSource = strdupW( path );
329 msi_free(p);
331 return path;
334 /* wrapper to resist a need for a full rewrite right now */
335 DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data )
337 if (ptr)
339 MSIRECORD *rec = MSI_CreateRecord(1);
340 DWORD size = 0;
342 MSI_RecordSetStringW(rec,0,ptr);
343 MSI_FormatRecordW(package,rec,NULL,&size);
344 if (size >= 0)
346 size++;
347 *data = msi_alloc(size*sizeof(WCHAR));
348 if (size > 1)
349 MSI_FormatRecordW(package,rec,*data,&size);
350 else
351 *data[0] = 0;
352 msiobj_release( &rec->hdr );
353 return sizeof(WCHAR)*size;
355 msiobj_release( &rec->hdr );
358 *data = NULL;
359 return 0;
362 UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action)
364 UINT count;
365 LPWSTR *newbuf = NULL;
366 if (script >= TOTAL_SCRIPTS)
368 FIXME("Unknown script requested %i\n",script);
369 return ERROR_FUNCTION_FAILED;
371 TRACE("Scheduling Action %s in script %i\n",debugstr_w(action), script);
373 count = package->script->ActionCount[script];
374 package->script->ActionCount[script]++;
375 if (count != 0)
376 newbuf = msi_realloc( package->script->Actions[script],
377 package->script->ActionCount[script]* sizeof(LPWSTR));
378 else
379 newbuf = msi_alloc( sizeof(LPWSTR));
381 newbuf[count] = strdupW(action);
382 package->script->Actions[script] = newbuf;
384 return ERROR_SUCCESS;
387 static void remove_tracked_tempfiles(MSIPACKAGE* package)
389 struct list *item, *cursor;
391 LIST_FOR_EACH_SAFE( item, cursor, &package->tempfiles )
393 MSITEMPFILE *temp = LIST_ENTRY( item, MSITEMPFILE, entry );
395 list_remove( &temp->entry );
396 TRACE("deleting temp file %s\n", debugstr_w( temp->Path ));
397 DeleteFileW( temp->Path );
398 msi_free( temp->File );
399 msi_free( temp->Path );
400 msi_free( temp );
404 static void free_feature( MSIFEATURE *feature )
406 struct list *item, *cursor;
408 LIST_FOR_EACH_SAFE( item, cursor, &feature->Children )
410 FeatureList *fl = LIST_ENTRY( item, FeatureList, entry );
411 list_remove( &fl->entry );
412 msi_free( fl );
415 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
417 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
418 list_remove( &cl->entry );
419 msi_free( cl );
421 msi_free( feature->Feature );
422 msi_free( feature->Feature_Parent );
423 msi_free( feature->Directory );
424 msi_free( feature->Description );
425 msi_free( feature->Title );
426 msi_free( feature );
429 void free_extension( MSIEXTENSION *ext )
431 struct list *item, *cursor;
433 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
435 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
437 list_remove( &verb->entry );
438 msi_free( verb->Verb );
439 msi_free( verb->Command );
440 msi_free( verb->Argument );
441 msi_free( verb );
444 msi_free( ext->Extension );
445 msi_free( ext->ProgIDText );
446 msi_free( ext );
449 /* Called when the package is being closed */
450 void ACTION_free_package_structures( MSIPACKAGE* package)
452 INT i;
453 struct list *item, *cursor;
455 TRACE("Freeing package action data\n");
457 remove_tracked_tempfiles(package);
459 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
461 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
462 list_remove( &feature->entry );
463 free_feature( feature );
466 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
468 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
470 list_remove( &folder->entry );
471 msi_free( folder->Directory );
472 msi_free( folder->TargetDefault );
473 msi_free( folder->SourceLongPath );
474 msi_free( folder->SourceShortPath );
475 msi_free( folder->ResolvedTarget );
476 msi_free( folder->ResolvedSource );
477 msi_free( folder->Property );
478 msi_free( folder );
481 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
483 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
485 list_remove( &comp->entry );
486 msi_free( comp->Component );
487 msi_free( comp->ComponentId );
488 msi_free( comp->Directory );
489 msi_free( comp->Condition );
490 msi_free( comp->KeyPath );
491 msi_free( comp->FullKeypath );
492 msi_free( comp );
495 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
497 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
499 list_remove( &file->entry );
500 msi_free( file->File );
501 msi_free( file->FileName );
502 msi_free( file->ShortName );
503 msi_free( file->LongName );
504 msi_free( file->Version );
505 msi_free( file->Language );
506 msi_free( file->SourcePath );
507 msi_free( file->TargetPath );
508 msi_free( file );
511 /* clean up extension, progid, class and verb structures */
512 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
514 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
516 list_remove( &cls->entry );
517 msi_free( cls->clsid );
518 msi_free( cls->Context );
519 msi_free( cls->Description );
520 msi_free( cls->FileTypeMask );
521 msi_free( cls->IconPath );
522 msi_free( cls->DefInprocHandler );
523 msi_free( cls->DefInprocHandler32 );
524 msi_free( cls->Argument );
525 msi_free( cls->ProgIDText );
526 msi_free( cls );
529 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
531 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
533 list_remove( &ext->entry );
534 free_extension( ext );
537 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
539 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
541 list_remove( &progid->entry );
542 msi_free( progid->ProgID );
543 msi_free( progid->Description );
544 msi_free( progid->IconPath );
545 msi_free( progid );
548 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
550 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
552 list_remove( &mt->entry );
553 msi_free( mt->clsid );
554 msi_free( mt->ContentType );
555 msi_free( mt );
558 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
560 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
562 list_remove( &appid->entry );
563 msi_free( appid->AppID );
564 msi_free( appid->RemoteServerName );
565 msi_free( appid->LocalServer );
566 msi_free( appid->ServiceParameters );
567 msi_free( appid->DllSurrogate );
568 msi_free( appid );
571 if (package->script)
573 for (i = 0; i < TOTAL_SCRIPTS; i++)
575 int j;
576 for (j = 0; j < package->script->ActionCount[i]; j++)
577 msi_free(package->script->Actions[i][j]);
579 msi_free(package->script->Actions[i]);
582 for (i = 0; i < package->script->UniqueActionsCount; i++)
583 msi_free(package->script->UniqueActions[i]);
585 msi_free(package->script->UniqueActions);
586 msi_free(package->script);
589 msi_free(package->PackagePath);
590 msi_free(package->ProductCode);
591 msi_free(package->ActionFormat);
592 msi_free(package->LastAction);
594 /* cleanup control event subscriptions */
595 ControlEvent_CleanupSubscriptions(package);
599 * build_directory_name()
601 * This function is to save messing round with directory names
602 * It handles adding backslashes between path segments,
603 * and can add \ at the end of the directory name if told to.
605 * It takes a variable number of arguments.
606 * It always allocates a new string for the result, so make sure
607 * to free the return value when finished with it.
609 * The first arg is the number of path segments that follow.
610 * The arguments following count are a list of path segments.
611 * A path segment may be NULL.
613 * Path segments will be added with a \ separating them.
614 * A \ will not be added after the last segment, however if the
615 * last segment is NULL, then the last character will be a \
618 LPWSTR build_directory_name(DWORD count, ...)
620 DWORD sz = 1, i;
621 LPWSTR dir;
622 va_list va;
624 va_start(va,count);
625 for(i=0; i<count; i++)
627 LPCWSTR str = va_arg(va,LPCWSTR);
628 if (str)
629 sz += strlenW(str) + 1;
631 va_end(va);
633 dir = msi_alloc(sz*sizeof(WCHAR));
634 dir[0]=0;
636 va_start(va,count);
637 for(i=0; i<count; i++)
639 LPCWSTR str = va_arg(va,LPCWSTR);
640 if (!str)
641 continue;
642 strcatW(dir, str);
643 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
644 strcatW(dir, cszbs);
646 return dir;
649 /***********************************************************************
650 * create_full_pathW
652 * Recursively create all directories in the path.
654 * shamelessly stolen from setupapi/queue.c
656 BOOL create_full_pathW(const WCHAR *path)
658 BOOL ret = TRUE;
659 int len;
660 WCHAR *new_path;
662 new_path = msi_alloc( (strlenW(path) + 1) * sizeof(WCHAR));
664 strcpyW(new_path, path);
666 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
667 new_path[len - 1] = 0;
669 while(!CreateDirectoryW(new_path, NULL))
671 WCHAR *slash;
672 DWORD last_error = GetLastError();
673 if(last_error == ERROR_ALREADY_EXISTS)
674 break;
676 if(last_error != ERROR_PATH_NOT_FOUND)
678 ret = FALSE;
679 break;
682 if(!(slash = strrchrW(new_path, '\\')))
684 ret = FALSE;
685 break;
688 len = slash - new_path;
689 new_path[len] = 0;
690 if(!create_full_pathW(new_path))
692 ret = FALSE;
693 break;
695 new_path[len] = '\\';
698 msi_free(new_path);
699 return ret;
702 void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
704 MSIRECORD * row;
706 row = MSI_CreateRecord(4);
707 MSI_RecordSetInteger(row,1,a);
708 MSI_RecordSetInteger(row,2,b);
709 MSI_RecordSetInteger(row,3,c);
710 MSI_RecordSetInteger(row,4,d);
711 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
712 msiobj_release(&row->hdr);
714 msi_dialog_check_messages(NULL);
717 void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
719 static const WCHAR Query_t[] =
720 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
721 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
722 'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=',
723 ' ','\'','%','s','\'',0};
724 WCHAR message[1024];
725 MSIRECORD * row = 0;
726 DWORD size;
728 if (!package->LastAction || strcmpW(package->LastAction,action))
730 row = MSI_QueryGetRecord(package->db, Query_t, action);
731 if (!row)
732 return;
734 if (MSI_RecordIsNull(row,3))
736 msiobj_release(&row->hdr);
737 return;
740 /* update the cached actionformat */
741 msi_free(package->ActionFormat);
742 package->ActionFormat = msi_dup_record_field(row,3);
744 msi_free(package->LastAction);
745 package->LastAction = strdupW(action);
747 msiobj_release(&row->hdr);
750 MSI_RecordSetStringW(record,0,package->ActionFormat);
751 size = 1024;
752 MSI_FormatRecordW(package,record,message,&size);
754 row = MSI_CreateRecord(1);
755 MSI_RecordSetStringW(row,1,message);
757 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
759 msiobj_release(&row->hdr);
762 BOOL ACTION_VerifyComponentForAction( MSICOMPONENT* comp, INSTALLSTATE check )
764 if (!comp)
765 return FALSE;
767 if (comp->Installed == check)
768 return FALSE;
770 if (comp->ActionRequest == check)
771 return TRUE;
772 else
773 return FALSE;
776 BOOL ACTION_VerifyFeatureForAction( MSIFEATURE* feature, INSTALLSTATE check )
778 if (!feature)
779 return FALSE;
781 if (feature->Installed == check)
782 return FALSE;
784 if (feature->ActionRequest == check)
785 return TRUE;
786 else
787 return FALSE;
790 void reduce_to_longfilename(WCHAR* filename)
792 LPWSTR p = strchrW(filename,'|');
793 if (p)
794 memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
797 void reduce_to_shortfilename(WCHAR* filename)
799 LPWSTR p = strchrW(filename,'|');
800 if (p)
801 *p = 0;
804 LPWSTR create_component_advertise_string(MSIPACKAGE* package,
805 MSICOMPONENT* component, LPCWSTR feature)
807 static const WCHAR fmt[] = {'%','s','%','s','%','c','%','s',0};
808 WCHAR productid_85[21], component_85[21];
809 LPWSTR output = NULL;
810 DWORD sz = 0;
811 GUID clsid;
813 /* > is used if there is a component GUID and < if not. */
815 productid_85[0] = 0;
816 component_85[0] = 0;
818 CLSIDFromString(package->ProductCode, &clsid);
819 encode_base85_guid(&clsid, productid_85);
821 if (component)
823 CLSIDFromString(component->ComponentId, &clsid);
824 encode_base85_guid(&clsid, component_85);
827 TRACE("prod=%s feat=%s comp=%s\n", debugstr_w(productid_85),
828 debugstr_w(feature), debugstr_w(component_85));
830 sz = 20 + lstrlenW(feature) + 20 + 3;
832 output = msi_alloc_zero(sz*sizeof(WCHAR));
834 sprintfW(output, fmt, productid_85, feature,
835 component?'>':'<', component_85);
837 return output;
840 /* update compoennt state based on a feature change */
841 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
843 INSTALLSTATE newstate;
844 MSIFEATURE *feature;
845 ComponentList *cl;
847 feature = get_loaded_feature(package,szFeature);
848 if (!feature)
849 return;
851 newstate = feature->ActionRequest;
853 if (newstate == INSTALLSTATE_ABSENT)
854 newstate = INSTALLSTATE_UNKNOWN;
856 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
858 MSICOMPONENT* component = cl->component;
860 TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
861 newstate, debugstr_w(component->Component), component->Installed,
862 component->Action, component->ActionRequest);
864 if (!component->Enabled)
865 continue;
867 if (newstate == INSTALLSTATE_LOCAL)
869 component->ActionRequest = INSTALLSTATE_LOCAL;
870 component->Action = INSTALLSTATE_LOCAL;
872 else
874 ComponentList *clist;
875 MSIFEATURE *f;
877 component->ActionRequest = newstate;
878 component->Action = newstate;
880 /*if any other feature wants is local we need to set it local*/
881 LIST_FOR_EACH_ENTRY( f, &package->features, MSIFEATURE, entry )
883 if ( f->ActionRequest != INSTALLSTATE_LOCAL &&
884 f->ActionRequest != INSTALLSTATE_SOURCE )
886 continue;
889 LIST_FOR_EACH_ENTRY( clist, &f->Components, ComponentList, entry )
891 if ( clist->component == component &&
892 (f->ActionRequest == INSTALLSTATE_LOCAL ||
893 f->ActionRequest == INSTALLSTATE_SOURCE) )
895 TRACE("Saved by %s\n", debugstr_w(f->Feature));
897 if (component->Attributes & msidbComponentAttributesOptional)
899 if (f->Attributes & msidbFeatureAttributesFavorSource)
901 component->Action = INSTALLSTATE_SOURCE;
902 component->ActionRequest = INSTALLSTATE_SOURCE;
904 else
906 component->Action = INSTALLSTATE_LOCAL;
907 component->ActionRequest = INSTALLSTATE_LOCAL;
910 else if (component->Attributes & msidbComponentAttributesSourceOnly)
912 component->Action = INSTALLSTATE_SOURCE;
913 component->ActionRequest = INSTALLSTATE_SOURCE;
915 else
917 component->Action = INSTALLSTATE_LOCAL;
918 component->ActionRequest = INSTALLSTATE_LOCAL;
924 TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
925 newstate, debugstr_w(component->Component), component->Installed,
926 component->Action, component->ActionRequest);
930 UINT register_unique_action(MSIPACKAGE *package, LPCWSTR action)
932 UINT count;
933 LPWSTR *newbuf = NULL;
935 if (!package->script)
936 return FALSE;
938 TRACE("Registering Action %s as having fun\n",debugstr_w(action));
940 count = package->script->UniqueActionsCount;
941 package->script->UniqueActionsCount++;
942 if (count != 0)
943 newbuf = msi_realloc( package->script->UniqueActions,
944 package->script->UniqueActionsCount* sizeof(LPWSTR));
945 else
946 newbuf = msi_alloc( sizeof(LPWSTR));
948 newbuf[count] = strdupW(action);
949 package->script->UniqueActions = newbuf;
951 return ERROR_SUCCESS;
954 BOOL check_unique_action(MSIPACKAGE *package, LPCWSTR action)
956 INT i;
958 if (!package->script)
959 return FALSE;
961 for (i = 0; i < package->script->UniqueActionsCount; i++)
962 if (!strcmpW(package->script->UniqueActions[i],action))
963 return TRUE;
965 return FALSE;
968 WCHAR* generate_error_string(MSIPACKAGE *package, UINT error, DWORD count, ... )
970 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};
972 MSIRECORD *rec;
973 MSIRECORD *row;
974 DWORD size = 0;
975 DWORD i;
976 va_list va;
977 LPCWSTR str;
978 LPWSTR data;
980 row = MSI_QueryGetRecord(package->db, query, error);
981 if (!row)
982 return 0;
984 rec = MSI_CreateRecord(count+2);
986 str = MSI_RecordGetString(row,1);
987 MSI_RecordSetStringW(rec,0,str);
988 msiobj_release( &row->hdr );
989 MSI_RecordSetInteger(rec,1,error);
991 va_start(va,count);
992 for (i = 0; i < count; i++)
994 str = va_arg(va,LPCWSTR);
995 MSI_RecordSetStringW(rec,(i+2),str);
997 va_end(va);
999 MSI_FormatRecordW(package,rec,NULL,&size);
1000 if (size >= 0)
1002 size++;
1003 data = msi_alloc(size*sizeof(WCHAR));
1004 if (size > 1)
1005 MSI_FormatRecordW(package,rec,data,&size);
1006 else
1007 data[0] = 0;
1008 msiobj_release( &rec->hdr );
1009 return data;
1012 msiobj_release( &rec->hdr );
1013 data = NULL;
1014 return data;
1017 void msi_ui_error( DWORD msg_id, DWORD type )
1019 WCHAR text[2048];
1021 static const WCHAR title[] = {
1022 'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0
1025 if (!MsiLoadStringW( -1, msg_id, text, sizeof(text) / sizeof(text[0]),
1026 MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) ))
1027 return;
1029 MessageBoxW( NULL, text, title, type );