Added implementation of security.dll.
[wine/hacks.git] / dlls / msi / helpers.c
blob2b2ba06155de27b92a514b0011cfe1912f6b0fc7
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 DWORD build_version_dword(LPCWSTR version_string)
48 SHORT major,minor;
49 WORD build;
50 DWORD rc = 0x00000000;
51 LPCWSTR ptr1;
53 ptr1 = version_string;
55 if (!ptr1)
56 return rc;
57 else
58 major = atoiW(ptr1);
61 if(ptr1)
62 ptr1 = strchrW(ptr1,'.');
63 if (ptr1)
65 ptr1++;
66 minor = atoiW(ptr1);
68 else
69 minor = 0;
71 if (ptr1)
72 ptr1 = strchrW(ptr1,'.');
74 if (ptr1)
76 ptr1++;
77 build = atoiW(ptr1);
79 else
80 build = 0;
82 rc = MAKELONG(build,MAKEWORD(minor,major));
83 TRACE("%s -> 0x%lx\n",debugstr_w(version_string),rc);
84 return rc;
87 LPWSTR build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name )
89 LPWSTR SystemFolder, dest, FilePath;
91 static const WCHAR szInstaller[] =
92 {'M','i','c','r','o','s','o','f','t','\\',
93 'I','n','s','t','a','l','l','e','r','\\',0};
94 static const WCHAR szFolder[] =
95 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
97 SystemFolder = msi_dup_property( package, szFolder );
99 dest = build_directory_name(3, SystemFolder, szInstaller, package->ProductCode);
101 create_full_pathW(dest);
103 FilePath = build_directory_name(2, dest, icon_name);
105 msi_free(SystemFolder);
106 msi_free(dest);
107 return FilePath;
110 LPWSTR msi_dup_record_field( MSIRECORD *row, INT index )
112 return strdupW( MSI_RecordGetString(row,index) );
115 LPWSTR msi_dup_property(MSIPACKAGE *package, LPCWSTR prop)
117 DWORD sz = 0;
118 LPWSTR str;
119 UINT r;
121 r = MSI_GetPropertyW(package, prop, NULL, &sz);
122 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
123 return NULL;
125 sz++;
126 str = msi_alloc(sz*sizeof(WCHAR));
127 r = MSI_GetPropertyW(package, prop, str, &sz);
128 if (r != ERROR_SUCCESS)
130 msi_free(str);
131 str = NULL;
133 return str;
136 MSICOMPONENT* get_loaded_component( MSIPACKAGE* package, LPCWSTR Component )
138 MSICOMPONENT *comp;
140 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
142 if (lstrcmpW(Component,comp->Component)==0)
143 return comp;
145 return NULL;
148 MSIFEATURE* get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
150 MSIFEATURE *feature;
152 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
154 if (lstrcmpW( Feature, feature->Feature )==0)
155 return feature;
157 return NULL;
160 MSIFILE* get_loaded_file( MSIPACKAGE* package, LPCWSTR key )
162 MSIFILE *file;
164 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
166 if (lstrcmpW( key, file->File )==0)
167 return file;
169 return NULL;
172 int track_tempfile( MSIPACKAGE *package, LPCWSTR name, LPCWSTR path )
174 MSITEMPFILE *temp;
176 LIST_FOR_EACH_ENTRY( temp, &package->tempfiles, MSITEMPFILE, entry )
178 if (lstrcmpW( name, temp->File )==0)
180 TRACE("tempfile %s already exists with path %s\n",
181 debugstr_w(temp->File), debugstr_w(temp->Path));
182 return -1;
186 temp = msi_alloc_zero( sizeof (MSITEMPFILE) );
187 if (!temp)
188 return -1;
190 list_add_head( &package->tempfiles, &temp->entry );
192 temp->File = strdupW( name );
193 temp->Path = strdupW( path );
195 TRACE("adding tempfile %s with path %s\n",
196 debugstr_w(temp->File), debugstr_w(temp->Path));
198 return 0;
201 MSIFOLDER *get_loaded_folder( MSIPACKAGE *package, LPCWSTR dir )
203 MSIFOLDER *folder;
205 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
207 if (lstrcmpW( dir, folder->Directory )==0)
208 return folder;
210 return NULL;
213 static LPWSTR get_source_root( MSIPACKAGE *package )
215 LPWSTR path, p;
217 path = msi_dup_property( package, cszSourceDir );
218 if (path)
219 return path;
221 path = msi_dup_property( package, cszDatabase );
222 if (path)
224 p = strrchrW(path,'\\');
225 if (p)
226 *(p+1) = 0;
228 return path;
231 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
232 BOOL set_prop, MSIFOLDER **folder)
234 MSIFOLDER *f;
235 LPWSTR p, path = NULL;
237 TRACE("Working to resolve %s\n",debugstr_w(name));
239 if (!name)
240 return NULL;
242 /* special resolving for Target and Source root dir */
243 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
245 if (!source)
247 LPWSTR check_path;
248 check_path = msi_dup_property( package, cszTargetDir );
249 if (!check_path)
251 check_path = msi_dup_property( package, cszRootDrive );
252 if (set_prop)
253 MSI_SetPropertyW(package,cszTargetDir,check_path);
256 /* correct misbuilt target dir */
257 path = build_directory_name(2, check_path, NULL);
258 if (strcmpiW(path,check_path)!=0)
259 MSI_SetPropertyW(package,cszTargetDir,path);
260 msi_free(check_path);
262 else
263 path = get_source_root( package );
264 if (folder)
265 *folder = get_loaded_folder( package, name );
266 return path;
269 f = get_loaded_folder( package, name );
270 if (!f)
271 return NULL;
273 if (folder)
274 *folder = f;
276 if (!source && f->ResolvedTarget)
278 path = strdupW( f->ResolvedTarget );
279 TRACE(" already resolved to %s\n",debugstr_w(path));
280 return path;
282 else if (source && f->ResolvedSource)
284 path = strdupW( f->ResolvedSource );
285 TRACE(" (source)already resolved to %s\n",debugstr_w(path));
286 return path;
288 else if (!source && f->Property)
290 path = build_directory_name( 2, f->Property, NULL );
292 TRACE(" internally set to %s\n",debugstr_w(path));
293 if (set_prop)
294 MSI_SetPropertyW( package, name, path );
295 return path;
298 if (f->Parent)
300 LPWSTR parent = f->Parent->Directory;
302 TRACE(" ! Parent is %s\n", debugstr_w(parent));
304 p = resolve_folder(package, parent, source, set_prop, NULL);
305 if (!source)
307 TRACE(" TargetDefault = %s\n", debugstr_w(f->TargetDefault));
309 path = build_directory_name( 3, p, f->TargetDefault, NULL );
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 if (f->SourceDefault && f->SourceDefault[0]!='.')
318 path = build_directory_name( 3, p, f->SourceDefault, NULL );
319 else
320 path = strdupW(p);
321 TRACE("source -> %s\n", debugstr_w(path));
323 /* if the directory doesn't exist, use the root */
324 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
326 msi_free( path );
327 path = get_source_root( package );
328 TRACE("defaulting to %s\n", debugstr_w(path));
330 else
331 f->ResolvedSource = strdupW( path );
333 msi_free(p);
335 return path;
338 /* wrapper to resist a need for a full rewrite right now */
339 DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data )
341 if (ptr)
343 MSIRECORD *rec = MSI_CreateRecord(1);
344 DWORD size = 0;
346 MSI_RecordSetStringW(rec,0,ptr);
347 MSI_FormatRecordW(package,rec,NULL,&size);
348 if (size >= 0)
350 size++;
351 *data = msi_alloc(size*sizeof(WCHAR));
352 if (size > 1)
353 MSI_FormatRecordW(package,rec,*data,&size);
354 else
355 *data[0] = 0;
356 msiobj_release( &rec->hdr );
357 return sizeof(WCHAR)*size;
359 msiobj_release( &rec->hdr );
362 *data = NULL;
363 return 0;
366 UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action)
368 UINT count;
369 LPWSTR *newbuf = NULL;
370 if (script >= TOTAL_SCRIPTS)
372 FIXME("Unknown script requested %i\n",script);
373 return ERROR_FUNCTION_FAILED;
375 TRACE("Scheduling Action %s in script %i\n",debugstr_w(action), script);
377 count = package->script->ActionCount[script];
378 package->script->ActionCount[script]++;
379 if (count != 0)
380 newbuf = msi_realloc( package->script->Actions[script],
381 package->script->ActionCount[script]* sizeof(LPWSTR));
382 else
383 newbuf = msi_alloc( sizeof(LPWSTR));
385 newbuf[count] = strdupW(action);
386 package->script->Actions[script] = newbuf;
388 return ERROR_SUCCESS;
391 static void remove_tracked_tempfiles(MSIPACKAGE* package)
393 struct list *item, *cursor;
395 LIST_FOR_EACH_SAFE( item, cursor, &package->tempfiles )
397 MSITEMPFILE *temp = LIST_ENTRY( item, MSITEMPFILE, entry );
399 list_remove( &temp->entry );
400 TRACE("deleting temp file %s\n", debugstr_w( temp->Path ));
401 DeleteFileW( temp->Path );
402 msi_free( temp->File );
403 msi_free( temp->Path );
404 msi_free( temp );
408 static void free_feature( MSIFEATURE *feature )
410 struct list *item, *cursor;
412 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
414 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
415 list_remove( &cl->entry );
416 msi_free( cl );
418 msi_free( feature->Feature );
419 msi_free( feature->Feature_Parent );
420 msi_free( feature->Directory );
421 msi_free( feature->Description );
422 msi_free( feature->Title );
423 msi_free( feature );
426 void free_extension( MSIEXTENSION *ext )
428 struct list *item, *cursor;
430 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
432 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
434 list_remove( &verb->entry );
435 msi_free( verb->Verb );
436 msi_free( verb->Command );
437 msi_free( verb->Argument );
438 msi_free( verb );
441 msi_free( ext->Extension );
442 msi_free( ext->ProgIDText );
443 msi_free( ext );
446 /* Called when the package is being closed */
447 void ACTION_free_package_structures( MSIPACKAGE* package)
449 INT i;
450 struct list *item, *cursor;
452 TRACE("Freeing package action data\n");
454 remove_tracked_tempfiles(package);
456 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
458 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
459 list_remove( &feature->entry );
460 free_feature( feature );
463 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
465 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
467 list_remove( &folder->entry );
468 msi_free( folder->Directory );
469 msi_free( folder->TargetDefault );
470 msi_free( folder->SourceDefault );
471 msi_free( folder->ResolvedTarget );
472 msi_free( folder->ResolvedSource );
473 msi_free( folder->Property );
474 msi_free( folder );
477 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
479 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
481 list_remove( &comp->entry );
482 msi_free( comp->Component );
483 msi_free( comp->ComponentId );
484 msi_free( comp->Directory );
485 msi_free( comp->Condition );
486 msi_free( comp->KeyPath );
487 msi_free( comp->FullKeypath );
488 msi_free( comp );
491 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
493 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
495 list_remove( &file->entry );
496 msi_free( file->File );
497 msi_free( file->FileName );
498 msi_free( file->ShortName );
499 msi_free( file->Version );
500 msi_free( file->Language );
501 msi_free( file->SourcePath );
502 msi_free( file->TargetPath );
503 msi_free( file );
506 /* clean up extension, progid, class and verb structures */
507 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
509 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
511 list_remove( &cls->entry );
512 msi_free( cls->clsid );
513 msi_free( cls->Context );
514 msi_free( cls->Description );
515 msi_free( cls->FileTypeMask );
516 msi_free( cls->IconPath );
517 msi_free( cls->DefInprocHandler );
518 msi_free( cls->DefInprocHandler32 );
519 msi_free( cls->Argument );
520 msi_free( cls->ProgIDText );
521 msi_free( cls );
524 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
526 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
528 list_remove( &ext->entry );
529 free_extension( ext );
532 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
534 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
536 list_remove( &progid->entry );
537 msi_free( progid->ProgID );
538 msi_free( progid->Description );
539 msi_free( progid->IconPath );
540 msi_free( progid );
543 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
545 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
547 list_remove( &mt->entry );
548 msi_free( mt->clsid );
549 msi_free( mt->ContentType );
550 msi_free( mt );
553 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
555 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
557 list_remove( &appid->entry );
558 msi_free( appid->AppID );
559 msi_free( appid->RemoteServerName );
560 msi_free( appid->LocalServer );
561 msi_free( appid->ServiceParameters );
562 msi_free( appid->DllSurrogate );
563 msi_free( appid );
566 if (package->script)
568 for (i = 0; i < TOTAL_SCRIPTS; i++)
570 int j;
571 for (j = 0; j < package->script->ActionCount[i]; j++)
572 msi_free(package->script->Actions[i][j]);
574 msi_free(package->script->Actions[i]);
577 for (i = 0; i < package->script->UniqueActionsCount; i++)
578 msi_free(package->script->UniqueActions[i]);
580 msi_free(package->script->UniqueActions);
581 msi_free(package->script);
584 msi_free(package->PackagePath);
585 msi_free(package->ProductCode);
586 msi_free(package->ActionFormat);
587 msi_free(package->LastAction);
589 /* cleanup control event subscriptions */
590 ControlEvent_CleanupSubscriptions(package);
594 * build_directory_name()
596 * This function is to save messing round with directory names
597 * It handles adding backslashes between path segments,
598 * and can add \ at the end of the directory name if told to.
600 * It takes a variable number of arguments.
601 * It always allocates a new string for the result, so make sure
602 * to free the return value when finished with it.
604 * The first arg is the number of path segments that follow.
605 * The arguments following count are a list of path segments.
606 * A path segment may be NULL.
608 * Path segments will be added with a \ separating them.
609 * A \ will not be added after the last segment, however if the
610 * last segment is NULL, then the last character will be a \
613 LPWSTR build_directory_name(DWORD count, ...)
615 DWORD sz = 1, i;
616 LPWSTR dir;
617 va_list va;
619 va_start(va,count);
620 for(i=0; i<count; i++)
622 LPCWSTR str = va_arg(va,LPCWSTR);
623 if (str)
624 sz += strlenW(str) + 1;
626 va_end(va);
628 dir = msi_alloc(sz*sizeof(WCHAR));
629 dir[0]=0;
631 va_start(va,count);
632 for(i=0; i<count; i++)
634 LPCWSTR str = va_arg(va,LPCWSTR);
635 if (!str)
636 continue;
637 strcatW(dir, str);
638 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
639 strcatW(dir, cszbs);
641 return dir;
644 /***********************************************************************
645 * create_full_pathW
647 * Recursively create all directories in the path.
649 * shamelessly stolen from setupapi/queue.c
651 BOOL create_full_pathW(const WCHAR *path)
653 BOOL ret = TRUE;
654 int len;
655 WCHAR *new_path;
657 new_path = msi_alloc( (strlenW(path) + 1) * sizeof(WCHAR));
659 strcpyW(new_path, path);
661 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
662 new_path[len - 1] = 0;
664 while(!CreateDirectoryW(new_path, NULL))
666 WCHAR *slash;
667 DWORD last_error = GetLastError();
668 if(last_error == ERROR_ALREADY_EXISTS)
669 break;
671 if(last_error != ERROR_PATH_NOT_FOUND)
673 ret = FALSE;
674 break;
677 if(!(slash = strrchrW(new_path, '\\')))
679 ret = FALSE;
680 break;
683 len = slash - new_path;
684 new_path[len] = 0;
685 if(!create_full_pathW(new_path))
687 ret = FALSE;
688 break;
690 new_path[len] = '\\';
693 msi_free(new_path);
694 return ret;
697 void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
699 MSIRECORD * row;
701 row = MSI_CreateRecord(4);
702 MSI_RecordSetInteger(row,1,a);
703 MSI_RecordSetInteger(row,2,b);
704 MSI_RecordSetInteger(row,3,c);
705 MSI_RecordSetInteger(row,4,d);
706 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
707 msiobj_release(&row->hdr);
709 msi_dialog_check_messages(NULL);
712 void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
714 static const WCHAR Query_t[] =
715 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
716 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
717 'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=',
718 ' ','\'','%','s','\'',0};
719 WCHAR message[1024];
720 MSIRECORD * row = 0;
721 DWORD size;
722 static const WCHAR szActionData[] =
723 {'A','c','t','i','o','n','D','a','t','a',0};
725 if (!package->LastAction || strcmpW(package->LastAction,action))
727 row = MSI_QueryGetRecord(package->db, Query_t, action);
728 if (!row)
729 return;
731 if (MSI_RecordIsNull(row,3))
733 msiobj_release(&row->hdr);
734 return;
737 /* update the cached actionformat */
738 msi_free(package->ActionFormat);
739 package->ActionFormat = msi_dup_record_field(row,3);
741 msi_free(package->LastAction);
742 package->LastAction = strdupW(action);
744 msiobj_release(&row->hdr);
747 MSI_RecordSetStringW(record,0,package->ActionFormat);
748 size = 1024;
749 MSI_FormatRecordW(package,record,message,&size);
751 row = MSI_CreateRecord(1);
752 MSI_RecordSetStringW(row,1,message);
754 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
756 ControlEvent_FireSubscribedEvent(package,szActionData, row);
758 msiobj_release(&row->hdr);
761 BOOL ACTION_VerifyComponentForAction( MSICOMPONENT* comp, INSTALLSTATE check )
763 if (!comp)
764 return FALSE;
766 if (comp->Installed == check)
767 return FALSE;
769 if (comp->ActionRequest == check)
770 return TRUE;
771 else
772 return FALSE;
775 BOOL ACTION_VerifyFeatureForAction( MSIFEATURE* feature, INSTALLSTATE check )
777 if (!feature)
778 return FALSE;
780 if (feature->Installed == check)
781 return FALSE;
783 if (feature->ActionRequest == check)
784 return TRUE;
785 else
786 return FALSE;
789 void reduce_to_longfilename(WCHAR* filename)
791 LPWSTR p = strchrW(filename,'|');
792 if (p)
793 memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
796 void reduce_to_shortfilename(WCHAR* filename)
798 LPWSTR p = strchrW(filename,'|');
799 if (p)
800 *p = 0;
803 LPWSTR create_component_advertise_string(MSIPACKAGE* package,
804 MSICOMPONENT* component, LPCWSTR feature)
806 GUID clsid;
807 WCHAR productid_85[21];
808 WCHAR component_85[21];
810 * I have a fair bit of confusion as to when a < is used and when a > is
811 * used. I do not think i have it right...
813 * Ok it appears that the > is used if there is a guid for the compoenent
814 * and the < is used if not.
816 static WCHAR fmt1[] = {'%','s','%','s','<',0,0};
817 static WCHAR fmt2[] = {'%','s','%','s','>','%','s',0,0};
818 LPWSTR output = NULL;
819 DWORD sz = 0;
821 memset(productid_85,0,sizeof(productid_85));
822 memset(component_85,0,sizeof(component_85));
824 CLSIDFromString(package->ProductCode, &clsid);
826 encode_base85_guid(&clsid,productid_85);
828 CLSIDFromString(component->ComponentId, &clsid);
829 encode_base85_guid(&clsid,component_85);
831 TRACE("Doing something with this... %s %s %s\n",
832 debugstr_w(productid_85), debugstr_w(feature),
833 debugstr_w(component_85));
835 sz = lstrlenW(productid_85) + lstrlenW(feature);
836 if (component)
837 sz += lstrlenW(component_85);
839 sz+=3;
840 sz *= sizeof(WCHAR);
842 output = msi_alloc(sz);
843 memset(output,0,sz);
845 if (component)
846 sprintfW(output,fmt2,productid_85,feature,component_85);
847 else
848 sprintfW(output,fmt1,productid_85,feature);
850 return output;
853 /* update compoennt state based on a feature change */
854 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
856 INSTALLSTATE newstate;
857 MSIFEATURE *feature;
858 ComponentList *cl;
860 feature = get_loaded_feature(package,szFeature);
861 if (!feature)
862 return;
864 newstate = feature->ActionRequest;
866 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
868 MSICOMPONENT* component = cl->component;
870 TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
871 newstate, debugstr_w(component->Component), component->Installed,
872 component->Action, component->ActionRequest);
874 if (!component->Enabled)
875 continue;
877 if (newstate == INSTALLSTATE_LOCAL)
879 component->ActionRequest = INSTALLSTATE_LOCAL;
880 component->Action = INSTALLSTATE_LOCAL;
882 else
884 ComponentList *clist;
885 MSIFEATURE *f;
887 component->ActionRequest = newstate;
888 component->Action = newstate;
890 /*if any other feature wants is local we need to set it local*/
891 LIST_FOR_EACH_ENTRY( f, &package->features, MSIFEATURE, entry )
893 if ( component->ActionRequest != INSTALLSTATE_LOCAL )
894 break;
896 LIST_FOR_EACH_ENTRY( clist, &f->Components, ComponentList, entry )
898 if ( clist->component == component )
900 if (f->ActionRequest == INSTALLSTATE_LOCAL)
902 TRACE("Saved by %s\n", debugstr_w(f->Feature));
903 component->ActionRequest = INSTALLSTATE_LOCAL;
904 component->Action = INSTALLSTATE_LOCAL;
906 break;
911 TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
912 newstate, debugstr_w(component->Component), component->Installed,
913 component->Action, component->ActionRequest);
917 UINT register_unique_action(MSIPACKAGE *package, LPCWSTR action)
919 UINT count;
920 LPWSTR *newbuf = NULL;
922 if (!package->script)
923 return FALSE;
925 TRACE("Registering Action %s as having fun\n",debugstr_w(action));
927 count = package->script->UniqueActionsCount;
928 package->script->UniqueActionsCount++;
929 if (count != 0)
930 newbuf = msi_realloc( package->script->UniqueActions,
931 package->script->UniqueActionsCount* sizeof(LPWSTR));
932 else
933 newbuf = msi_alloc( sizeof(LPWSTR));
935 newbuf[count] = strdupW(action);
936 package->script->UniqueActions = newbuf;
938 return ERROR_SUCCESS;
941 BOOL check_unique_action(MSIPACKAGE *package, LPCWSTR action)
943 INT i;
945 if (!package->script)
946 return FALSE;
948 for (i = 0; i < package->script->UniqueActionsCount; i++)
949 if (!strcmpW(package->script->UniqueActions[i],action))
950 return TRUE;
952 return FALSE;
955 WCHAR* generate_error_string(MSIPACKAGE *package, UINT error, DWORD count, ... )
957 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};
959 MSIRECORD *rec;
960 MSIRECORD *row;
961 DWORD size = 0;
962 DWORD i;
963 va_list va;
964 LPCWSTR str;
965 LPWSTR data;
967 row = MSI_QueryGetRecord(package->db, query, error);
968 if (!row)
969 return 0;
971 rec = MSI_CreateRecord(count+2);
973 str = MSI_RecordGetString(row,1);
974 MSI_RecordSetStringW(rec,0,str);
975 msiobj_release( &row->hdr );
976 MSI_RecordSetInteger(rec,1,error);
978 va_start(va,count);
979 for (i = 0; i < count; i++)
981 str = va_arg(va,LPCWSTR);
982 MSI_RecordSetStringW(rec,(i+2),str);
984 va_end(va);
986 MSI_FormatRecordW(package,rec,NULL,&size);
987 if (size >= 0)
989 size++;
990 data = msi_alloc(size*sizeof(WCHAR));
991 if (size > 1)
992 MSI_FormatRecordW(package,rec,data,&size);
993 else
994 data[0] = 0;
995 msiobj_release( &rec->hdr );
996 return data;
999 msiobj_release( &rec->hdr );
1000 data = NULL;
1001 return data;