gdi: Fix test for GetGlyphIndicesW on non Unicode systems.
[wine/hacks.git] / dlls / msi / helpers.c
blob45d3ebe86e81603d33c354920a166e4dc19f0090
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"
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 cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
44 const WCHAR cszbs[]={'\\',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);
65 msi_free(dest);
66 return FilePath;
69 LPWSTR msi_dup_record_field( MSIRECORD *row, INT index )
71 return strdupW( MSI_RecordGetString(row,index) );
74 MSICOMPONENT* get_loaded_component( MSIPACKAGE* package, LPCWSTR Component )
76 MSICOMPONENT *comp;
78 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
80 if (lstrcmpW(Component,comp->Component)==0)
81 return comp;
83 return NULL;
86 MSIFEATURE* get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
88 MSIFEATURE *feature;
90 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
92 if (lstrcmpW( Feature, feature->Feature )==0)
93 return feature;
95 return NULL;
98 MSIFILE* get_loaded_file( MSIPACKAGE* package, LPCWSTR key )
100 MSIFILE *file;
102 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
104 if (lstrcmpW( key, file->File )==0)
105 return file;
107 return NULL;
110 int track_tempfile( MSIPACKAGE *package, LPCWSTR name, LPCWSTR path )
112 MSITEMPFILE *temp;
114 LIST_FOR_EACH_ENTRY( temp, &package->tempfiles, MSITEMPFILE, entry )
116 if (lstrcmpW( name, temp->File )==0)
118 TRACE("tempfile %s already exists with path %s\n",
119 debugstr_w(temp->File), debugstr_w(temp->Path));
120 return -1;
124 temp = msi_alloc_zero( sizeof (MSITEMPFILE) );
125 if (!temp)
126 return -1;
128 list_add_head( &package->tempfiles, &temp->entry );
130 temp->File = strdupW( name );
131 temp->Path = strdupW( path );
133 TRACE("adding tempfile %s with path %s\n",
134 debugstr_w(temp->File), debugstr_w(temp->Path));
136 return 0;
139 MSIFOLDER *get_loaded_folder( MSIPACKAGE *package, LPCWSTR dir )
141 MSIFOLDER *folder;
143 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
145 if (lstrcmpW( dir, folder->Directory )==0)
146 return folder;
148 return NULL;
151 static LPWSTR get_source_root( MSIPACKAGE *package )
153 LPWSTR path, p;
155 path = msi_dup_property( package, cszSourceDir );
156 if (path)
157 return path;
159 path = msi_dup_property( package, cszDatabase );
160 if (path)
162 p = strrchrW(path,'\\');
163 if (p)
164 *(p+1) = 0;
166 return path;
170 * clean_spaces_from_path()
172 * removes spaces from the beginning and end of path segments
173 * removes multiple \\ characters
175 static void clean_spaces_from_path( LPWSTR p )
177 LPWSTR q = p;
178 int n, len = 0;
180 while (1)
182 /* copy until the end of the string or a space */
183 while (*p != ' ' && (*q = *p))
185 p++, len++;
186 /* reduce many backslashes to one */
187 if (*p != '\\' || *q != '\\')
188 q++;
191 /* quit at the end of the string */
192 if (!*p)
193 break;
195 /* count the number of spaces */
196 n = 0;
197 while (p[n] == ' ')
198 n++;
200 /* if it's leading or trailing space, skip it */
201 if ( len == 0 || p[-1] == '\\' || p[n] == '\\' )
202 p += n;
203 else /* copy n spaces */
204 while (n && (*q++ = *p++)) n--;
208 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
209 BOOL set_prop, MSIFOLDER **folder)
211 MSIFOLDER *f;
212 LPWSTR p, path = NULL;
214 TRACE("Working to resolve %s\n",debugstr_w(name));
216 if (!name)
217 return NULL;
219 /* special resolving for Target and Source root dir */
220 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
222 if (!source)
224 LPWSTR check_path;
225 check_path = msi_dup_property( package, cszTargetDir );
226 if (!check_path)
228 check_path = msi_dup_property( package, cszRootDrive );
229 if (set_prop)
230 MSI_SetPropertyW(package,cszTargetDir,check_path);
233 /* correct misbuilt target dir */
234 path = build_directory_name(2, check_path, NULL);
235 clean_spaces_from_path( path );
236 if (strcmpiW(path,check_path)!=0)
237 MSI_SetPropertyW(package,cszTargetDir,path);
238 msi_free(check_path);
240 else
241 path = get_source_root( package );
242 if (folder)
243 *folder = get_loaded_folder( package, name );
244 return path;
247 f = get_loaded_folder( package, name );
248 if (!f)
249 return NULL;
251 if (folder)
252 *folder = f;
254 if (!source && f->ResolvedTarget)
256 path = strdupW( f->ResolvedTarget );
257 TRACE(" already resolved to %s\n",debugstr_w(path));
258 return path;
260 else if (source && f->ResolvedSource)
262 path = strdupW( f->ResolvedSource );
263 TRACE(" (source)already resolved to %s\n",debugstr_w(path));
264 return path;
266 else if (!source && f->Property)
268 path = build_directory_name( 2, f->Property, NULL );
270 TRACE(" internally set to %s\n",debugstr_w(path));
271 if (set_prop)
272 MSI_SetPropertyW( package, name, path );
273 return path;
276 if (f->Parent)
278 LPWSTR parent = f->Parent->Directory;
280 TRACE(" ! Parent is %s\n", debugstr_w(parent));
282 p = resolve_folder(package, parent, source, set_prop, NULL);
283 if (!source)
285 TRACE(" TargetDefault = %s\n", debugstr_w(f->TargetDefault));
287 path = build_directory_name( 3, p, f->TargetDefault, NULL );
288 clean_spaces_from_path( path );
289 f->ResolvedTarget = strdupW( path );
290 TRACE("target -> %s\n", debugstr_w(path));
291 if (set_prop)
292 MSI_SetPropertyW(package,name,path);
294 else
296 /* source may be in a few different places ... check each of them */
297 path = NULL;
299 /* try the long path directory */
300 if (f->SourceLongPath)
302 path = build_directory_name( 3, p, f->SourceLongPath, NULL );
303 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
305 msi_free( path );
306 path = NULL;
310 /* try the short path directory */
311 if (!path && f->SourceShortPath)
313 path = build_directory_name( 3, p, f->SourceShortPath, NULL );
314 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
316 msi_free( path );
317 path = NULL;
321 /* try the root of the install */
322 if (!path)
323 path = get_source_root( package );
325 TRACE("source -> %s\n", debugstr_w(path));
326 f->ResolvedSource = strdupW( path );
328 msi_free(p);
330 return path;
333 /* wrapper to resist a need for a full rewrite right now */
334 DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data )
336 if (ptr)
338 MSIRECORD *rec = MSI_CreateRecord(1);
339 DWORD size = 0;
341 MSI_RecordSetStringW(rec,0,ptr);
342 MSI_FormatRecordW(package,rec,NULL,&size);
343 if (size >= 0)
345 size++;
346 *data = msi_alloc(size*sizeof(WCHAR));
347 if (size > 1)
348 MSI_FormatRecordW(package,rec,*data,&size);
349 else
350 *data[0] = 0;
351 msiobj_release( &rec->hdr );
352 return sizeof(WCHAR)*size;
354 msiobj_release( &rec->hdr );
357 *data = NULL;
358 return 0;
361 UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action)
363 UINT count;
364 LPWSTR *newbuf = NULL;
365 if (script >= TOTAL_SCRIPTS)
367 FIXME("Unknown script requested %i\n",script);
368 return ERROR_FUNCTION_FAILED;
370 TRACE("Scheduling Action %s in script %i\n",debugstr_w(action), script);
372 count = package->script->ActionCount[script];
373 package->script->ActionCount[script]++;
374 if (count != 0)
375 newbuf = msi_realloc( package->script->Actions[script],
376 package->script->ActionCount[script]* sizeof(LPWSTR));
377 else
378 newbuf = msi_alloc( sizeof(LPWSTR));
380 newbuf[count] = strdupW(action);
381 package->script->Actions[script] = newbuf;
383 return ERROR_SUCCESS;
386 static void remove_tracked_tempfiles(MSIPACKAGE* package)
388 struct list *item, *cursor;
390 LIST_FOR_EACH_SAFE( item, cursor, &package->tempfiles )
392 MSITEMPFILE *temp = LIST_ENTRY( item, MSITEMPFILE, entry );
394 list_remove( &temp->entry );
395 TRACE("deleting temp file %s\n", debugstr_w( temp->Path ));
396 DeleteFileW( temp->Path );
397 msi_free( temp->File );
398 msi_free( temp->Path );
399 msi_free( temp );
403 static void free_feature( MSIFEATURE *feature )
405 struct list *item, *cursor;
407 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
409 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
410 list_remove( &cl->entry );
411 msi_free( cl );
413 msi_free( feature->Feature );
414 msi_free( feature->Feature_Parent );
415 msi_free( feature->Directory );
416 msi_free( feature->Description );
417 msi_free( feature->Title );
418 msi_free( feature );
421 void free_extension( MSIEXTENSION *ext )
423 struct list *item, *cursor;
425 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
427 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
429 list_remove( &verb->entry );
430 msi_free( verb->Verb );
431 msi_free( verb->Command );
432 msi_free( verb->Argument );
433 msi_free( verb );
436 msi_free( ext->Extension );
437 msi_free( ext->ProgIDText );
438 msi_free( ext );
441 /* Called when the package is being closed */
442 void ACTION_free_package_structures( MSIPACKAGE* package)
444 INT i;
445 struct list *item, *cursor;
447 TRACE("Freeing package action data\n");
449 remove_tracked_tempfiles(package);
451 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
453 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
454 list_remove( &feature->entry );
455 free_feature( feature );
458 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
460 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
462 list_remove( &folder->entry );
463 msi_free( folder->Directory );
464 msi_free( folder->TargetDefault );
465 msi_free( folder->SourceLongPath );
466 msi_free( folder->SourceShortPath );
467 msi_free( folder->ResolvedTarget );
468 msi_free( folder->ResolvedSource );
469 msi_free( folder->Property );
470 msi_free( folder );
473 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
475 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
477 list_remove( &comp->entry );
478 msi_free( comp->Component );
479 msi_free( comp->ComponentId );
480 msi_free( comp->Directory );
481 msi_free( comp->Condition );
482 msi_free( comp->KeyPath );
483 msi_free( comp->FullKeypath );
484 msi_free( comp );
487 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
489 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
491 list_remove( &file->entry );
492 msi_free( file->File );
493 msi_free( file->FileName );
494 msi_free( file->ShortName );
495 msi_free( file->LongName );
496 msi_free( file->Version );
497 msi_free( file->Language );
498 msi_free( file->SourcePath );
499 msi_free( file->TargetPath );
500 msi_free( file );
503 /* clean up extension, progid, class and verb structures */
504 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
506 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
508 list_remove( &cls->entry );
509 msi_free( cls->clsid );
510 msi_free( cls->Context );
511 msi_free( cls->Description );
512 msi_free( cls->FileTypeMask );
513 msi_free( cls->IconPath );
514 msi_free( cls->DefInprocHandler );
515 msi_free( cls->DefInprocHandler32 );
516 msi_free( cls->Argument );
517 msi_free( cls->ProgIDText );
518 msi_free( cls );
521 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
523 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
525 list_remove( &ext->entry );
526 free_extension( ext );
529 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
531 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
533 list_remove( &progid->entry );
534 msi_free( progid->ProgID );
535 msi_free( progid->Description );
536 msi_free( progid->IconPath );
537 msi_free( progid );
540 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
542 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
544 list_remove( &mt->entry );
545 msi_free( mt->clsid );
546 msi_free( mt->ContentType );
547 msi_free( mt );
550 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
552 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
554 list_remove( &appid->entry );
555 msi_free( appid->AppID );
556 msi_free( appid->RemoteServerName );
557 msi_free( appid->LocalServer );
558 msi_free( appid->ServiceParameters );
559 msi_free( appid->DllSurrogate );
560 msi_free( appid );
563 if (package->script)
565 for (i = 0; i < TOTAL_SCRIPTS; i++)
567 int j;
568 for (j = 0; j < package->script->ActionCount[i]; j++)
569 msi_free(package->script->Actions[i][j]);
571 msi_free(package->script->Actions[i]);
574 for (i = 0; i < package->script->UniqueActionsCount; i++)
575 msi_free(package->script->UniqueActions[i]);
577 msi_free(package->script->UniqueActions);
578 msi_free(package->script);
581 msi_free(package->PackagePath);
582 msi_free(package->ProductCode);
583 msi_free(package->ActionFormat);
584 msi_free(package->LastAction);
586 /* cleanup control event subscriptions */
587 ControlEvent_CleanupSubscriptions(package);
591 * build_directory_name()
593 * This function is to save messing round with directory names
594 * It handles adding backslashes between path segments,
595 * and can add \ at the end of the directory name if told to.
597 * It takes a variable number of arguments.
598 * It always allocates a new string for the result, so make sure
599 * to free the return value when finished with it.
601 * The first arg is the number of path segments that follow.
602 * The arguments following count are a list of path segments.
603 * A path segment may be NULL.
605 * Path segments will be added with a \ separating them.
606 * A \ will not be added after the last segment, however if the
607 * last segment is NULL, then the last character will be a \
610 LPWSTR build_directory_name(DWORD count, ...)
612 DWORD sz = 1, i;
613 LPWSTR dir;
614 va_list va;
616 va_start(va,count);
617 for(i=0; i<count; i++)
619 LPCWSTR str = va_arg(va,LPCWSTR);
620 if (str)
621 sz += strlenW(str) + 1;
623 va_end(va);
625 dir = msi_alloc(sz*sizeof(WCHAR));
626 dir[0]=0;
628 va_start(va,count);
629 for(i=0; i<count; i++)
631 LPCWSTR str = va_arg(va,LPCWSTR);
632 if (!str)
633 continue;
634 strcatW(dir, str);
635 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
636 strcatW(dir, cszbs);
638 return dir;
641 /***********************************************************************
642 * create_full_pathW
644 * Recursively create all directories in the path.
646 * shamelessly stolen from setupapi/queue.c
648 BOOL create_full_pathW(const WCHAR *path)
650 BOOL ret = TRUE;
651 int len;
652 WCHAR *new_path;
654 new_path = msi_alloc( (strlenW(path) + 1) * sizeof(WCHAR));
656 strcpyW(new_path, path);
658 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
659 new_path[len - 1] = 0;
661 while(!CreateDirectoryW(new_path, NULL))
663 WCHAR *slash;
664 DWORD last_error = GetLastError();
665 if(last_error == ERROR_ALREADY_EXISTS)
666 break;
668 if(last_error != ERROR_PATH_NOT_FOUND)
670 ret = FALSE;
671 break;
674 if(!(slash = strrchrW(new_path, '\\')))
676 ret = FALSE;
677 break;
680 len = slash - new_path;
681 new_path[len] = 0;
682 if(!create_full_pathW(new_path))
684 ret = FALSE;
685 break;
687 new_path[len] = '\\';
690 msi_free(new_path);
691 return ret;
694 void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
696 MSIRECORD * row;
698 row = MSI_CreateRecord(4);
699 MSI_RecordSetInteger(row,1,a);
700 MSI_RecordSetInteger(row,2,b);
701 MSI_RecordSetInteger(row,3,c);
702 MSI_RecordSetInteger(row,4,d);
703 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
704 msiobj_release(&row->hdr);
706 msi_dialog_check_messages(NULL);
709 void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
711 static const WCHAR Query_t[] =
712 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
713 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
714 'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=',
715 ' ','\'','%','s','\'',0};
716 WCHAR message[1024];
717 MSIRECORD * row = 0;
718 DWORD size;
720 if (!package->LastAction || strcmpW(package->LastAction,action))
722 row = MSI_QueryGetRecord(package->db, Query_t, action);
723 if (!row)
724 return;
726 if (MSI_RecordIsNull(row,3))
728 msiobj_release(&row->hdr);
729 return;
732 /* update the cached actionformat */
733 msi_free(package->ActionFormat);
734 package->ActionFormat = msi_dup_record_field(row,3);
736 msi_free(package->LastAction);
737 package->LastAction = strdupW(action);
739 msiobj_release(&row->hdr);
742 MSI_RecordSetStringW(record,0,package->ActionFormat);
743 size = 1024;
744 MSI_FormatRecordW(package,record,message,&size);
746 row = MSI_CreateRecord(1);
747 MSI_RecordSetStringW(row,1,message);
749 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
751 msiobj_release(&row->hdr);
754 BOOL ACTION_VerifyComponentForAction( MSICOMPONENT* comp, INSTALLSTATE check )
756 if (!comp)
757 return FALSE;
759 if (comp->Installed == check)
760 return FALSE;
762 if (comp->ActionRequest == check)
763 return TRUE;
764 else
765 return FALSE;
768 BOOL ACTION_VerifyFeatureForAction( MSIFEATURE* feature, INSTALLSTATE check )
770 if (!feature)
771 return FALSE;
773 if (feature->Installed == check)
774 return FALSE;
776 if (feature->ActionRequest == check)
777 return TRUE;
778 else
779 return FALSE;
782 void reduce_to_longfilename(WCHAR* filename)
784 LPWSTR p = strchrW(filename,'|');
785 if (p)
786 memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
789 void reduce_to_shortfilename(WCHAR* filename)
791 LPWSTR p = strchrW(filename,'|');
792 if (p)
793 *p = 0;
796 LPWSTR create_component_advertise_string(MSIPACKAGE* package,
797 MSICOMPONENT* component, LPCWSTR feature)
799 static const WCHAR fmt[] = {'%','s','%','s','%','c','%','s',0};
800 WCHAR productid_85[21], component_85[21];
801 LPWSTR output = NULL;
802 DWORD sz = 0;
803 GUID clsid;
805 /* > is used if there is a component GUID and < if not. */
807 productid_85[0] = 0;
808 component_85[0] = 0;
810 CLSIDFromString(package->ProductCode, &clsid);
811 encode_base85_guid(&clsid, productid_85);
813 if (component)
815 CLSIDFromString(component->ComponentId, &clsid);
816 encode_base85_guid(&clsid, component_85);
819 TRACE("prod=%s feat=%s comp=%s\n", debugstr_w(productid_85),
820 debugstr_w(feature), debugstr_w(component_85));
822 sz = 20 + lstrlenW(feature) + 20 + 3;
824 output = msi_alloc_zero(sz*sizeof(WCHAR));
826 sprintfW(output, fmt, productid_85, feature,
827 component?'>':'<', component_85);
829 return output;
832 /* update compoennt state based on a feature change */
833 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
835 INSTALLSTATE newstate;
836 MSIFEATURE *feature;
837 ComponentList *cl;
839 feature = get_loaded_feature(package,szFeature);
840 if (!feature)
841 return;
843 newstate = feature->ActionRequest;
845 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
847 MSICOMPONENT* component = cl->component;
849 TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
850 newstate, debugstr_w(component->Component), component->Installed,
851 component->Action, component->ActionRequest);
853 if (!component->Enabled)
854 continue;
856 if (newstate == INSTALLSTATE_LOCAL)
858 component->ActionRequest = INSTALLSTATE_LOCAL;
859 component->Action = INSTALLSTATE_LOCAL;
861 else
863 ComponentList *clist;
864 MSIFEATURE *f;
866 component->ActionRequest = newstate;
867 component->Action = newstate;
869 /*if any other feature wants is local we need to set it local*/
870 LIST_FOR_EACH_ENTRY( f, &package->features, MSIFEATURE, entry )
872 if ( component->ActionRequest != INSTALLSTATE_LOCAL )
873 break;
875 LIST_FOR_EACH_ENTRY( clist, &f->Components, ComponentList, entry )
877 if ( clist->component == component )
879 if (f->ActionRequest == INSTALLSTATE_LOCAL)
881 TRACE("Saved by %s\n", debugstr_w(f->Feature));
882 component->ActionRequest = INSTALLSTATE_LOCAL;
883 component->Action = INSTALLSTATE_LOCAL;
885 break;
890 TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
891 newstate, debugstr_w(component->Component), component->Installed,
892 component->Action, component->ActionRequest);
896 UINT register_unique_action(MSIPACKAGE *package, LPCWSTR action)
898 UINT count;
899 LPWSTR *newbuf = NULL;
901 if (!package->script)
902 return FALSE;
904 TRACE("Registering Action %s as having fun\n",debugstr_w(action));
906 count = package->script->UniqueActionsCount;
907 package->script->UniqueActionsCount++;
908 if (count != 0)
909 newbuf = msi_realloc( package->script->UniqueActions,
910 package->script->UniqueActionsCount* sizeof(LPWSTR));
911 else
912 newbuf = msi_alloc( sizeof(LPWSTR));
914 newbuf[count] = strdupW(action);
915 package->script->UniqueActions = newbuf;
917 return ERROR_SUCCESS;
920 BOOL check_unique_action(MSIPACKAGE *package, LPCWSTR action)
922 INT i;
924 if (!package->script)
925 return FALSE;
927 for (i = 0; i < package->script->UniqueActionsCount; i++)
928 if (!strcmpW(package->script->UniqueActions[i],action))
929 return TRUE;
931 return FALSE;
934 WCHAR* generate_error_string(MSIPACKAGE *package, UINT error, DWORD count, ... )
936 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};
938 MSIRECORD *rec;
939 MSIRECORD *row;
940 DWORD size = 0;
941 DWORD i;
942 va_list va;
943 LPCWSTR str;
944 LPWSTR data;
946 row = MSI_QueryGetRecord(package->db, query, error);
947 if (!row)
948 return 0;
950 rec = MSI_CreateRecord(count+2);
952 str = MSI_RecordGetString(row,1);
953 MSI_RecordSetStringW(rec,0,str);
954 msiobj_release( &row->hdr );
955 MSI_RecordSetInteger(rec,1,error);
957 va_start(va,count);
958 for (i = 0; i < count; i++)
960 str = va_arg(va,LPCWSTR);
961 MSI_RecordSetStringW(rec,(i+2),str);
963 va_end(va);
965 MSI_FormatRecordW(package,rec,NULL,&size);
966 if (size >= 0)
968 size++;
969 data = msi_alloc(size*sizeof(WCHAR));
970 if (size > 1)
971 MSI_FormatRecordW(package,rec,data,&size);
972 else
973 data[0] = 0;
974 msiobj_release( &rec->hdr );
975 return data;
978 msiobj_release( &rec->hdr );
979 data = NULL;
980 return data;
983 void msi_ui_error( DWORD msg_id, DWORD type )
985 WCHAR text[2048];
987 static const WCHAR title[] = {
988 'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0
991 if (!MsiLoadStringW( -1, msg_id, text, sizeof(text) / sizeof(text[0]),
992 MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) ))
993 return;
995 MessageBoxW( NULL, text, title, type );