wined3d: Fix the texm3x3tex instruction to sample properly.
[wine/dibdrv.git] / dlls / msi / helpers.c
blobb2968f1c2648307936ec47666257da98859f7590
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 "msidefs.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msi);
39 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
40 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
42 const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',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 *rec, INT field )
72 DWORD sz = 0;
73 LPWSTR str;
74 UINT r;
76 if (MSI_RecordIsNull( rec, field ))
77 return NULL;
79 r = MSI_RecordGetStringW( rec, field, NULL, &sz );
80 if (r != ERROR_SUCCESS)
81 return NULL;
83 sz ++;
84 str = msi_alloc( sz * sizeof (WCHAR) );
85 if (!str)
86 return str;
87 str[0] = 0;
88 r = MSI_RecordGetStringW( rec, field, str, &sz );
89 if (r != ERROR_SUCCESS)
91 ERR("failed to get string!\n");
92 msi_free( str );
93 return NULL;
95 return str;
98 MSICOMPONENT* get_loaded_component( MSIPACKAGE* package, LPCWSTR Component )
100 MSICOMPONENT *comp;
102 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
104 if (lstrcmpW(Component,comp->Component)==0)
105 return comp;
107 return NULL;
110 MSIFEATURE* get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
112 MSIFEATURE *feature;
114 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
116 if (lstrcmpW( Feature, feature->Feature )==0)
117 return feature;
119 return NULL;
122 MSIFILE* get_loaded_file( MSIPACKAGE* package, LPCWSTR key )
124 MSIFILE *file;
126 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
128 if (lstrcmpW( key, file->File )==0)
129 return file;
131 return NULL;
134 int track_tempfile( MSIPACKAGE *package, LPCWSTR path )
136 MSITEMPFILE *temp;
138 TRACE("%s\n", debugstr_w(path));
140 LIST_FOR_EACH_ENTRY( temp, &package->tempfiles, MSITEMPFILE, entry )
141 if (!lstrcmpW( path, temp->Path ))
142 return 0;
144 temp = msi_alloc_zero( sizeof (MSITEMPFILE) );
145 if (!temp)
146 return -1;
148 list_add_head( &package->tempfiles, &temp->entry );
149 temp->Path = strdupW( path );
151 return 0;
154 MSIFOLDER *get_loaded_folder( MSIPACKAGE *package, LPCWSTR dir )
156 MSIFOLDER *folder;
158 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
160 if (lstrcmpW( dir, folder->Directory )==0)
161 return folder;
163 return NULL;
166 static LPWSTR get_source_root( MSIPACKAGE *package )
168 LPWSTR path, p;
170 path = msi_dup_property( package, cszSourceDir );
171 if (path)
172 return path;
174 path = msi_dup_property( package, cszDatabase );
175 if (path)
177 p = strrchrW(path,'\\');
178 if (p)
179 *(p+1) = 0;
181 return path;
185 * clean_spaces_from_path()
187 * removes spaces from the beginning and end of path segments
188 * removes multiple \\ characters
190 static void clean_spaces_from_path( LPWSTR p )
192 LPWSTR q = p;
193 int n, len = 0;
195 while (1)
197 /* copy until the end of the string or a space */
198 while (*p != ' ' && (*q = *p))
200 p++, len++;
201 /* reduce many backslashes to one */
202 if (*p != '\\' || *q != '\\')
203 q++;
206 /* quit at the end of the string */
207 if (!*p)
208 break;
210 /* count the number of spaces */
211 n = 0;
212 while (p[n] == ' ')
213 n++;
215 /* if it's leading or trailing space, skip it */
216 if ( len == 0 || p[-1] == '\\' || p[n] == '\\' )
217 p += n;
218 else /* copy n spaces */
219 while (n && (*q++ = *p++)) n--;
223 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
224 BOOL set_prop, MSIFOLDER **folder)
226 MSIFOLDER *f;
227 LPWSTR p, path = NULL, parent;
229 TRACE("Working to resolve %s\n",debugstr_w(name));
231 if (!name)
232 return NULL;
234 if (!lstrcmpW(name,cszSourceDir))
235 name = cszTargetDir;
237 f = get_loaded_folder( package, name );
238 if (!f)
239 return NULL;
241 /* special resolving for Target and Source root dir */
242 if (!strcmpW(name,cszTargetDir))
244 if (!f->ResolvedTarget && !f->Property)
246 LPWSTR check_path;
247 check_path = msi_dup_property( package, cszTargetDir );
248 if (!check_path)
250 check_path = msi_dup_property( package, cszRootDrive );
251 if (set_prop)
252 MSI_SetPropertyW(package,cszTargetDir,check_path);
255 /* correct misbuilt target dir */
256 path = build_directory_name(2, check_path, NULL);
257 clean_spaces_from_path( path );
258 if (strcmpiW(path,check_path)!=0)
259 MSI_SetPropertyW(package,cszTargetDir,path);
260 msi_free(check_path);
262 f->ResolvedTarget = path;
265 if (!f->ResolvedSource)
266 f->ResolvedSource = get_source_root( package );
269 if (folder)
270 *folder = f;
272 if (!source && f->ResolvedTarget)
274 path = strdupW( f->ResolvedTarget );
275 TRACE(" already resolved to %s\n",debugstr_w(path));
276 return path;
279 if (source && f->ResolvedSource)
281 path = strdupW( f->ResolvedSource );
282 TRACE(" (source)already resolved to %s\n",debugstr_w(path));
283 return path;
286 if (!source && f->Property)
288 path = build_directory_name( 2, f->Property, NULL );
290 TRACE(" internally set to %s\n",debugstr_w(path));
291 if (set_prop)
292 MSI_SetPropertyW( package, name, path );
293 return path;
296 if (!f->Parent)
297 return path;
299 parent = f->Parent;
301 TRACE(" ! Parent is %s\n", debugstr_w(parent));
303 p = resolve_folder(package, parent, source, set_prop, NULL);
304 if (!source)
306 TRACE(" TargetDefault = %s\n", debugstr_w(f->TargetDefault));
308 path = build_directory_name( 3, p, f->TargetDefault, NULL );
309 clean_spaces_from_path( path );
310 f->ResolvedTarget = strdupW( path );
311 TRACE("target -> %s\n", debugstr_w(path));
312 if (set_prop)
313 MSI_SetPropertyW(package,name,path);
315 else
317 /* source may be in a few different places ... check each of them */
318 path = NULL;
320 /* try the long path directory */
321 if (f->SourceLongPath)
323 path = build_directory_name( 3, p, f->SourceLongPath, NULL );
324 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
326 msi_free( path );
327 path = NULL;
331 /* try the short path directory */
332 if (!path && f->SourceShortPath)
334 path = build_directory_name( 3, p, f->SourceShortPath, NULL );
335 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
337 msi_free( path );
338 path = NULL;
342 /* try the root of the install */
343 if (!path)
344 path = get_source_root( package );
346 TRACE("source -> %s\n", debugstr_w(path));
347 f->ResolvedSource = strdupW( path );
349 msi_free(p);
351 return path;
354 /* wrapper to resist a need for a full rewrite right now */
355 DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data )
357 if (ptr)
359 MSIRECORD *rec = MSI_CreateRecord(1);
360 DWORD size = 0;
362 MSI_RecordSetStringW(rec,0,ptr);
363 MSI_FormatRecordW(package,rec,NULL,&size);
364 if (size >= 0)
366 size++;
367 *data = msi_alloc(size*sizeof(WCHAR));
368 if (size > 1)
369 MSI_FormatRecordW(package,rec,*data,&size);
370 else
371 *data[0] = 0;
372 msiobj_release( &rec->hdr );
373 return sizeof(WCHAR)*size;
375 msiobj_release( &rec->hdr );
378 *data = NULL;
379 return 0;
382 UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action)
384 UINT count;
385 LPWSTR *newbuf = NULL;
386 if (script >= TOTAL_SCRIPTS)
388 FIXME("Unknown script requested %i\n",script);
389 return ERROR_FUNCTION_FAILED;
391 TRACE("Scheduling Action %s in script %i\n",debugstr_w(action), script);
393 count = package->script->ActionCount[script];
394 package->script->ActionCount[script]++;
395 if (count != 0)
396 newbuf = msi_realloc( package->script->Actions[script],
397 package->script->ActionCount[script]* sizeof(LPWSTR));
398 else
399 newbuf = msi_alloc( sizeof(LPWSTR));
401 newbuf[count] = strdupW(action);
402 package->script->Actions[script] = newbuf;
404 return ERROR_SUCCESS;
407 void msi_free_action_script(MSIPACKAGE *package, UINT script)
409 int i;
410 for (i = 0; i < package->script->ActionCount[script]; i++)
411 msi_free(package->script->Actions[script][i]);
413 msi_free(package->script->Actions[script]);
414 package->script->Actions[script] = NULL;
415 package->script->ActionCount[script] = 0;
418 static void remove_tracked_tempfiles(MSIPACKAGE* package)
420 struct list *item, *cursor;
422 LIST_FOR_EACH_SAFE( item, cursor, &package->tempfiles )
424 MSITEMPFILE *temp = LIST_ENTRY( item, MSITEMPFILE, entry );
426 list_remove( &temp->entry );
427 TRACE("deleting temp file %s\n", debugstr_w( temp->Path ));
428 if (!DeleteFileW( temp->Path ))
429 ERR("failed to delete %s\n", debugstr_w( temp->Path ));
430 msi_free( temp->Path );
431 msi_free( temp );
435 static void free_feature( MSIFEATURE *feature )
437 struct list *item, *cursor;
439 LIST_FOR_EACH_SAFE( item, cursor, &feature->Children )
441 FeatureList *fl = LIST_ENTRY( item, FeatureList, entry );
442 list_remove( &fl->entry );
443 msi_free( fl );
446 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
448 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
449 list_remove( &cl->entry );
450 msi_free( cl );
452 msi_free( feature->Feature );
453 msi_free( feature->Feature_Parent );
454 msi_free( feature->Directory );
455 msi_free( feature->Description );
456 msi_free( feature->Title );
457 msi_free( feature );
460 static void free_extension( MSIEXTENSION *ext )
462 struct list *item, *cursor;
464 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
466 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
468 list_remove( &verb->entry );
469 msi_free( verb->Verb );
470 msi_free( verb->Command );
471 msi_free( verb->Argument );
472 msi_free( verb );
475 msi_free( ext->Extension );
476 msi_free( ext->ProgIDText );
477 msi_free( ext );
480 /* Called when the package is being closed */
481 void ACTION_free_package_structures( MSIPACKAGE* package)
483 INT i;
484 struct list *item, *cursor;
486 TRACE("Freeing package action data\n");
488 remove_tracked_tempfiles(package);
490 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
492 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
493 list_remove( &feature->entry );
494 free_feature( feature );
497 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
499 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
501 list_remove( &folder->entry );
502 msi_free( folder->Parent );
503 msi_free( folder->Directory );
504 msi_free( folder->TargetDefault );
505 msi_free( folder->SourceLongPath );
506 msi_free( folder->SourceShortPath );
507 msi_free( folder->ResolvedTarget );
508 msi_free( folder->ResolvedSource );
509 msi_free( folder->Property );
510 msi_free( folder );
513 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
515 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
517 list_remove( &comp->entry );
518 msi_free( comp->Component );
519 msi_free( comp->ComponentId );
520 msi_free( comp->Directory );
521 msi_free( comp->Condition );
522 msi_free( comp->KeyPath );
523 msi_free( comp->FullKeypath );
524 msi_free( comp );
527 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
529 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
531 list_remove( &file->entry );
532 msi_free( file->File );
533 msi_free( file->FileName );
534 msi_free( file->ShortName );
535 msi_free( file->LongName );
536 msi_free( file->Version );
537 msi_free( file->Language );
538 msi_free( file->SourcePath );
539 msi_free( file->TargetPath );
540 msi_free( file );
543 /* clean up extension, progid, class and verb structures */
544 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
546 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
548 list_remove( &cls->entry );
549 msi_free( cls->clsid );
550 msi_free( cls->Context );
551 msi_free( cls->Description );
552 msi_free( cls->FileTypeMask );
553 msi_free( cls->IconPath );
554 msi_free( cls->DefInprocHandler );
555 msi_free( cls->DefInprocHandler32 );
556 msi_free( cls->Argument );
557 msi_free( cls->ProgIDText );
558 msi_free( cls );
561 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
563 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
565 list_remove( &ext->entry );
566 free_extension( ext );
569 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
571 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
573 list_remove( &progid->entry );
574 msi_free( progid->ProgID );
575 msi_free( progid->Description );
576 msi_free( progid->IconPath );
577 msi_free( progid );
580 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
582 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
584 list_remove( &mt->entry );
585 msi_free( mt->clsid );
586 msi_free( mt->ContentType );
587 msi_free( mt );
590 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
592 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
594 list_remove( &appid->entry );
595 msi_free( appid->AppID );
596 msi_free( appid->RemoteServerName );
597 msi_free( appid->LocalServer );
598 msi_free( appid->ServiceParameters );
599 msi_free( appid->DllSurrogate );
600 msi_free( appid );
603 if (package->script)
605 for (i = 0; i < TOTAL_SCRIPTS; i++)
606 msi_free_action_script(package, i);
608 for (i = 0; i < package->script->UniqueActionsCount; i++)
609 msi_free(package->script->UniqueActions[i]);
611 msi_free(package->script->UniqueActions);
612 msi_free(package->script);
615 msi_free(package->BaseURL);
616 msi_free(package->PackagePath);
617 msi_free(package->ProductCode);
618 msi_free(package->ActionFormat);
619 msi_free(package->LastAction);
621 /* cleanup control event subscriptions */
622 ControlEvent_CleanupSubscriptions(package);
626 * build_directory_name()
628 * This function is to save messing round with directory names
629 * It handles adding backslashes between path segments,
630 * and can add \ at the end of the directory name if told to.
632 * It takes a variable number of arguments.
633 * It always allocates a new string for the result, so make sure
634 * to free the return value when finished with it.
636 * The first arg is the number of path segments that follow.
637 * The arguments following count are a list of path segments.
638 * A path segment may be NULL.
640 * Path segments will be added with a \ separating them.
641 * A \ will not be added after the last segment, however if the
642 * last segment is NULL, then the last character will be a \
645 LPWSTR build_directory_name(DWORD count, ...)
647 DWORD sz = 1, i;
648 LPWSTR dir;
649 va_list va;
651 va_start(va,count);
652 for(i=0; i<count; i++)
654 LPCWSTR str = va_arg(va,LPCWSTR);
655 if (str)
656 sz += strlenW(str) + 1;
658 va_end(va);
660 dir = msi_alloc(sz*sizeof(WCHAR));
661 dir[0]=0;
663 va_start(va,count);
664 for(i=0; i<count; i++)
666 LPCWSTR str = va_arg(va,LPCWSTR);
667 if (!str)
668 continue;
669 strcatW(dir, str);
670 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
671 strcatW(dir, cszbs);
673 return dir;
676 /***********************************************************************
677 * create_full_pathW
679 * Recursively create all directories in the path.
681 * shamelessly stolen from setupapi/queue.c
683 BOOL create_full_pathW(const WCHAR *path)
685 BOOL ret = TRUE;
686 int len;
687 WCHAR *new_path;
689 new_path = msi_alloc( (strlenW(path) + 1) * sizeof(WCHAR));
691 strcpyW(new_path, path);
693 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
694 new_path[len - 1] = 0;
696 while(!CreateDirectoryW(new_path, NULL))
698 WCHAR *slash;
699 DWORD last_error = GetLastError();
700 if(last_error == ERROR_ALREADY_EXISTS)
701 break;
703 if(last_error != ERROR_PATH_NOT_FOUND)
705 ret = FALSE;
706 break;
709 if(!(slash = strrchrW(new_path, '\\')))
711 ret = FALSE;
712 break;
715 len = slash - new_path;
716 new_path[len] = 0;
717 if(!create_full_pathW(new_path))
719 ret = FALSE;
720 break;
722 new_path[len] = '\\';
725 msi_free(new_path);
726 return ret;
729 void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
731 MSIRECORD * row;
733 row = MSI_CreateRecord(4);
734 MSI_RecordSetInteger(row,1,a);
735 MSI_RecordSetInteger(row,2,b);
736 MSI_RecordSetInteger(row,3,c);
737 MSI_RecordSetInteger(row,4,d);
738 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
739 msiobj_release(&row->hdr);
741 msi_dialog_check_messages(NULL);
744 void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
746 static const WCHAR Query_t[] =
747 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
748 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
749 'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=',
750 ' ','\'','%','s','\'',0};
751 WCHAR message[1024];
752 MSIRECORD * row = 0;
753 DWORD size;
755 if (!package->LastAction || strcmpW(package->LastAction,action))
757 row = MSI_QueryGetRecord(package->db, Query_t, action);
758 if (!row)
759 return;
761 if (MSI_RecordIsNull(row,3))
763 msiobj_release(&row->hdr);
764 return;
767 /* update the cached actionformat */
768 msi_free(package->ActionFormat);
769 package->ActionFormat = msi_dup_record_field(row,3);
771 msi_free(package->LastAction);
772 package->LastAction = strdupW(action);
774 msiobj_release(&row->hdr);
777 MSI_RecordSetStringW(record,0,package->ActionFormat);
778 size = 1024;
779 MSI_FormatRecordW(package,record,message,&size);
781 row = MSI_CreateRecord(1);
782 MSI_RecordSetStringW(row,1,message);
784 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
786 msiobj_release(&row->hdr);
789 BOOL ACTION_VerifyComponentForAction( MSICOMPONENT* comp, INSTALLSTATE check )
791 if (!comp)
792 return FALSE;
794 if (comp->Installed == check)
795 return FALSE;
797 if (comp->ActionRequest == check)
798 return TRUE;
799 else
800 return FALSE;
803 BOOL ACTION_VerifyFeatureForAction( MSIFEATURE* feature, INSTALLSTATE check )
805 if (!feature)
806 return FALSE;
808 if (feature->Installed == check)
809 return FALSE;
811 if (feature->ActionRequest == check)
812 return TRUE;
813 else
814 return FALSE;
817 void reduce_to_longfilename(WCHAR* filename)
819 LPWSTR p = strchrW(filename,'|');
820 if (p)
821 memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
824 void reduce_to_shortfilename(WCHAR* filename)
826 LPWSTR p = strchrW(filename,'|');
827 if (p)
828 *p = 0;
831 LPWSTR create_component_advertise_string(MSIPACKAGE* package,
832 MSICOMPONENT* component, LPCWSTR feature)
834 static const WCHAR fmt[] = {'%','s','%','s','%','c','%','s',0};
835 WCHAR productid_85[21], component_85[21];
836 LPWSTR output = NULL;
837 DWORD sz = 0;
838 GUID clsid;
840 /* > is used if there is a component GUID and < if not. */
842 productid_85[0] = 0;
843 component_85[0] = 0;
845 CLSIDFromString(package->ProductCode, &clsid);
846 encode_base85_guid(&clsid, productid_85);
848 if (component)
850 CLSIDFromString(component->ComponentId, &clsid);
851 encode_base85_guid(&clsid, component_85);
854 TRACE("prod=%s feat=%s comp=%s\n", debugstr_w(productid_85),
855 debugstr_w(feature), debugstr_w(component_85));
857 sz = 20 + lstrlenW(feature) + 20 + 3;
859 output = msi_alloc_zero(sz*sizeof(WCHAR));
861 sprintfW(output, fmt, productid_85, feature,
862 component?'>':'<', component_85);
864 return output;
867 /* update compoennt state based on a feature change */
868 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
870 INSTALLSTATE newstate;
871 MSIFEATURE *feature;
872 ComponentList *cl;
874 feature = get_loaded_feature(package,szFeature);
875 if (!feature)
876 return;
878 newstate = feature->ActionRequest;
880 if (newstate == INSTALLSTATE_ABSENT)
881 newstate = INSTALLSTATE_UNKNOWN;
883 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
885 MSICOMPONENT* component = cl->component;
887 TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
888 newstate, debugstr_w(component->Component), component->Installed,
889 component->Action, component->ActionRequest);
891 if (!component->Enabled)
892 continue;
894 if (newstate == INSTALLSTATE_LOCAL)
895 msi_component_set_state( component, INSTALLSTATE_LOCAL );
896 else
898 ComponentList *clist;
899 MSIFEATURE *f;
901 msi_component_set_state( component, newstate );
903 /*if any other feature wants is local we need to set it local*/
904 LIST_FOR_EACH_ENTRY( f, &package->features, MSIFEATURE, entry )
906 if ( f->ActionRequest != INSTALLSTATE_LOCAL &&
907 f->ActionRequest != INSTALLSTATE_SOURCE )
909 continue;
912 LIST_FOR_EACH_ENTRY( clist, &f->Components, ComponentList, entry )
914 if ( clist->component == component &&
915 (f->ActionRequest == INSTALLSTATE_LOCAL ||
916 f->ActionRequest == INSTALLSTATE_SOURCE) )
918 TRACE("Saved by %s\n", debugstr_w(f->Feature));
920 if (component->Attributes & msidbComponentAttributesOptional)
922 if (f->Attributes & msidbFeatureAttributesFavorSource)
923 msi_component_set_state( component, INSTALLSTATE_SOURCE );
924 else
925 msi_component_set_state( component, INSTALLSTATE_LOCAL );
927 else if (component->Attributes & msidbComponentAttributesSourceOnly)
928 msi_component_set_state( component, INSTALLSTATE_SOURCE );
929 else
930 msi_component_set_state( component, INSTALLSTATE_LOCAL );
935 TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
936 newstate, debugstr_w(component->Component), component->Installed,
937 component->Action, component->ActionRequest);
941 UINT register_unique_action(MSIPACKAGE *package, LPCWSTR action)
943 UINT count;
944 LPWSTR *newbuf = NULL;
946 if (!package->script)
947 return FALSE;
949 TRACE("Registering Action %s as having fun\n",debugstr_w(action));
951 count = package->script->UniqueActionsCount;
952 package->script->UniqueActionsCount++;
953 if (count != 0)
954 newbuf = msi_realloc( package->script->UniqueActions,
955 package->script->UniqueActionsCount* sizeof(LPWSTR));
956 else
957 newbuf = msi_alloc( sizeof(LPWSTR));
959 newbuf[count] = strdupW(action);
960 package->script->UniqueActions = newbuf;
962 return ERROR_SUCCESS;
965 BOOL check_unique_action(MSIPACKAGE *package, LPCWSTR action)
967 INT i;
969 if (!package->script)
970 return FALSE;
972 for (i = 0; i < package->script->UniqueActionsCount; i++)
973 if (!strcmpW(package->script->UniqueActions[i],action))
974 return TRUE;
976 return FALSE;
979 WCHAR* generate_error_string(MSIPACKAGE *package, UINT error, DWORD count, ... )
981 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};
983 MSIRECORD *rec;
984 MSIRECORD *row;
985 DWORD size = 0;
986 DWORD i;
987 va_list va;
988 LPCWSTR str;
989 LPWSTR data;
991 row = MSI_QueryGetRecord(package->db, query, error);
992 if (!row)
993 return 0;
995 rec = MSI_CreateRecord(count+2);
997 str = MSI_RecordGetString(row,1);
998 MSI_RecordSetStringW(rec,0,str);
999 msiobj_release( &row->hdr );
1000 MSI_RecordSetInteger(rec,1,error);
1002 va_start(va,count);
1003 for (i = 0; i < count; i++)
1005 str = va_arg(va,LPCWSTR);
1006 MSI_RecordSetStringW(rec,(i+2),str);
1008 va_end(va);
1010 MSI_FormatRecordW(package,rec,NULL,&size);
1011 if (size >= 0)
1013 size++;
1014 data = msi_alloc(size*sizeof(WCHAR));
1015 if (size > 1)
1016 MSI_FormatRecordW(package,rec,data,&size);
1017 else
1018 data[0] = 0;
1019 msiobj_release( &rec->hdr );
1020 return data;
1023 msiobj_release( &rec->hdr );
1024 data = NULL;
1025 return data;
1028 void msi_ui_error( DWORD msg_id, DWORD type )
1030 WCHAR text[2048];
1032 static const WCHAR title[] = {
1033 'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0
1036 if (!MsiLoadStringW( -1, msg_id, text, sizeof(text) / sizeof(text[0]),
1037 MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) ))
1038 return;
1040 MessageBoxW( NULL, text, title, type );