dplayx: Tests for checking the behaviour of groups in a p2p session.
[wine/gsoc_dplay.git] / dlls / msi / helpers.c
blob4e20a27d9322e42203829bbd65893fc384d006a0
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 variety of
23 * actions and functions.
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "wine/debug.h"
30 #include "msipriv.h"
31 #include "winuser.h"
32 #include "wine/unicode.h"
33 #include "msidefs.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(msi);
37 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
38 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
40 const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
41 const WCHAR cszSOURCEDIR[] = {'S','O','U','R','C','E','D','I','R',0};
42 const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
43 const WCHAR cszbs[]={'\\',0};
45 LPWSTR build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name )
47 LPWSTR SystemFolder, dest, FilePath;
49 static const WCHAR szInstaller[] =
50 {'M','i','c','r','o','s','o','f','t','\\',
51 'I','n','s','t','a','l','l','e','r','\\',0};
52 static const WCHAR szFolder[] =
53 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
55 SystemFolder = msi_dup_property( package, szFolder );
57 dest = build_directory_name(3, SystemFolder, szInstaller, package->ProductCode);
59 create_full_pathW(dest);
61 FilePath = build_directory_name(2, dest, icon_name);
63 msi_free(SystemFolder);
64 msi_free(dest);
65 return FilePath;
68 LPWSTR msi_dup_record_field( MSIRECORD *rec, INT field )
70 DWORD sz = 0;
71 LPWSTR str;
72 UINT r;
74 if (MSI_RecordIsNull( rec, field ))
75 return NULL;
77 r = MSI_RecordGetStringW( rec, field, NULL, &sz );
78 if (r != ERROR_SUCCESS)
79 return NULL;
81 sz ++;
82 str = msi_alloc( sz * sizeof (WCHAR) );
83 if (!str)
84 return str;
85 str[0] = 0;
86 r = MSI_RecordGetStringW( rec, field, str, &sz );
87 if (r != ERROR_SUCCESS)
89 ERR("failed to get string!\n");
90 msi_free( str );
91 return NULL;
93 return str;
96 MSICOMPONENT* get_loaded_component( MSIPACKAGE* package, LPCWSTR Component )
98 MSICOMPONENT *comp;
100 LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
102 if (lstrcmpW(Component,comp->Component)==0)
103 return comp;
105 return NULL;
108 MSIFEATURE* get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
110 MSIFEATURE *feature;
112 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
114 if (lstrcmpW( Feature, feature->Feature )==0)
115 return feature;
117 return NULL;
120 MSIFILE* get_loaded_file( MSIPACKAGE* package, LPCWSTR key )
122 MSIFILE *file;
124 LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
126 if (lstrcmpW( key, file->File )==0)
127 return file;
129 return NULL;
132 int track_tempfile( MSIPACKAGE *package, LPCWSTR path )
134 MSITEMPFILE *temp;
136 TRACE("%s\n", debugstr_w(path));
138 LIST_FOR_EACH_ENTRY( temp, &package->tempfiles, MSITEMPFILE, entry )
139 if (!lstrcmpW( path, temp->Path ))
140 return 0;
142 temp = msi_alloc_zero( sizeof (MSITEMPFILE) );
143 if (!temp)
144 return -1;
146 list_add_head( &package->tempfiles, &temp->entry );
147 temp->Path = strdupW( path );
149 return 0;
152 MSIFOLDER *get_loaded_folder( MSIPACKAGE *package, LPCWSTR dir )
154 MSIFOLDER *folder;
156 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
158 if (lstrcmpW( dir, folder->Directory )==0)
159 return folder;
161 return NULL;
164 static LPWSTR get_source_root( MSIPACKAGE *package )
166 LPWSTR path, p;
168 path = msi_dup_property( package, cszSourceDir );
169 if (path)
170 return path;
172 path = msi_dup_property( package, cszDatabase );
173 if (path)
175 p = strrchrW(path,'\\');
176 if (p)
177 *(p+1) = 0;
179 return path;
183 * clean_spaces_from_path()
185 * removes spaces from the beginning and end of path segments
186 * removes multiple \\ characters
188 static void clean_spaces_from_path( LPWSTR p )
190 LPWSTR q = p;
191 int n, len = 0;
193 while (1)
195 /* copy until the end of the string or a space */
196 while (*p != ' ' && (*q = *p))
198 p++, len++;
199 /* reduce many backslashes to one */
200 if (*p != '\\' || *q != '\\')
201 q++;
204 /* quit at the end of the string */
205 if (!*p)
206 break;
208 /* count the number of spaces */
209 n = 0;
210 while (p[n] == ' ')
211 n++;
213 /* if it's leading or trailing space, skip it */
214 if ( len == 0 || p[-1] == '\\' || p[n] == '\\' )
215 p += n;
216 else /* copy n spaces */
217 while (n && (*q++ = *p++)) n--;
221 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
222 BOOL set_prop, BOOL load_prop, MSIFOLDER **folder)
224 MSIFOLDER *f;
225 LPWSTR p, path = NULL, parent;
227 TRACE("Working to resolve %s\n",debugstr_w(name));
229 if (!name)
230 return NULL;
232 if (!lstrcmpW(name,cszSourceDir))
233 name = cszTargetDir;
235 f = get_loaded_folder( package, name );
236 if (!f)
237 return NULL;
239 /* special resolving for Target and Source root dir */
240 if (!strcmpW(name,cszTargetDir))
242 if (!f->ResolvedTarget && !f->Property)
244 LPWSTR check_path;
245 check_path = msi_dup_property( package, cszTargetDir );
246 if (!check_path)
248 check_path = msi_dup_property( package, cszRootDrive );
249 if (set_prop)
250 MSI_SetPropertyW(package,cszTargetDir,check_path);
253 /* correct misbuilt target dir */
254 path = build_directory_name(2, check_path, NULL);
255 clean_spaces_from_path( path );
256 if (strcmpiW(path,check_path)!=0)
257 MSI_SetPropertyW(package,cszTargetDir,path);
258 msi_free(check_path);
260 f->ResolvedTarget = path;
263 if (!f->ResolvedSource)
264 f->ResolvedSource = get_source_root( package );
267 if (folder)
268 *folder = f;
270 if (!source && f->ResolvedTarget)
272 path = strdupW( f->ResolvedTarget );
273 TRACE(" already resolved to %s\n",debugstr_w(path));
274 return path;
277 if (source && f->ResolvedSource)
279 path = strdupW( f->ResolvedSource );
280 TRACE(" (source)already resolved to %s\n",debugstr_w(path));
281 return path;
284 if (!source && f->Property)
286 path = build_directory_name( 2, f->Property, NULL );
288 TRACE(" internally set to %s\n",debugstr_w(path));
289 if (set_prop)
290 MSI_SetPropertyW( package, name, path );
291 return path;
294 if (!source && load_prop && (path = msi_dup_property( package, name )))
296 f->ResolvedTarget = strdupW( path );
297 TRACE(" property set to %s\n", debugstr_w(path));
298 return path;
301 if (!f->Parent)
302 return path;
304 parent = f->Parent;
306 TRACE(" ! Parent is %s\n", debugstr_w(parent));
308 p = resolve_folder(package, parent, source, set_prop, load_prop, NULL);
309 if (!source)
311 TRACE(" TargetDefault = %s\n", debugstr_w(f->TargetDefault));
313 path = build_directory_name( 3, p, f->TargetDefault, NULL );
314 clean_spaces_from_path( path );
315 f->ResolvedTarget = strdupW( path );
316 TRACE("target -> %s\n", debugstr_w(path));
317 if (set_prop)
318 MSI_SetPropertyW(package,name,path);
320 else
322 path = NULL;
324 if (package->WordCount & msidbSumInfoSourceTypeCompressed)
325 path = get_source_root( package );
326 else if (package->WordCount & msidbSumInfoSourceTypeSFN)
327 path = build_directory_name( 3, p, f->SourceShortPath, NULL );
328 else
329 path = build_directory_name( 3, p, f->SourceLongPath, NULL );
331 TRACE("source -> %s\n", debugstr_w(path));
332 f->ResolvedSource = strdupW( path );
334 msi_free(p);
336 return path;
339 /* wrapper to resist a need for a full rewrite right now */
340 DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data )
342 if (ptr)
344 MSIRECORD *rec = MSI_CreateRecord(1);
345 DWORD size = 0;
347 MSI_RecordSetStringW(rec,0,ptr);
348 MSI_FormatRecordW(package,rec,NULL,&size);
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;
357 msiobj_release( &rec->hdr );
358 return sizeof(WCHAR)*size;
361 *data = NULL;
362 return 0;
365 UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action)
367 UINT count;
368 LPWSTR *newbuf = NULL;
369 if (script >= TOTAL_SCRIPTS)
371 FIXME("Unknown script requested %i\n",script);
372 return ERROR_FUNCTION_FAILED;
374 TRACE("Scheduling Action %s in script %i\n",debugstr_w(action), script);
376 count = package->script->ActionCount[script];
377 package->script->ActionCount[script]++;
378 if (count != 0)
379 newbuf = msi_realloc( package->script->Actions[script],
380 package->script->ActionCount[script]* sizeof(LPWSTR));
381 else
382 newbuf = msi_alloc( sizeof(LPWSTR));
384 newbuf[count] = strdupW(action);
385 package->script->Actions[script] = newbuf;
387 return ERROR_SUCCESS;
390 void msi_free_action_script(MSIPACKAGE *package, UINT script)
392 int i;
393 for (i = 0; i < package->script->ActionCount[script]; i++)
394 msi_free(package->script->Actions[script][i]);
396 msi_free(package->script->Actions[script]);
397 package->script->Actions[script] = NULL;
398 package->script->ActionCount[script] = 0;
401 static void remove_tracked_tempfiles(MSIPACKAGE* package)
403 struct list *item, *cursor;
405 LIST_FOR_EACH_SAFE( item, cursor, &package->tempfiles )
407 MSITEMPFILE *temp = LIST_ENTRY( item, MSITEMPFILE, entry );
409 list_remove( &temp->entry );
410 TRACE("deleting temp file %s\n", debugstr_w( temp->Path ));
411 if (!DeleteFileW( temp->Path ))
412 ERR("failed to delete %s\n", debugstr_w( temp->Path ));
413 msi_free( temp->Path );
414 msi_free( temp );
418 static void free_feature( MSIFEATURE *feature )
420 struct list *item, *cursor;
422 LIST_FOR_EACH_SAFE( item, cursor, &feature->Children )
424 FeatureList *fl = LIST_ENTRY( item, FeatureList, entry );
425 list_remove( &fl->entry );
426 msi_free( fl );
429 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
431 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
432 list_remove( &cl->entry );
433 msi_free( cl );
435 msi_free( feature->Feature );
436 msi_free( feature->Feature_Parent );
437 msi_free( feature->Directory );
438 msi_free( feature->Description );
439 msi_free( feature->Title );
440 msi_free( feature );
443 static void free_extension( MSIEXTENSION *ext )
445 struct list *item, *cursor;
447 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
449 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
451 list_remove( &verb->entry );
452 msi_free( verb->Verb );
453 msi_free( verb->Command );
454 msi_free( verb->Argument );
455 msi_free( verb );
458 msi_free( ext->Extension );
459 msi_free( ext->ProgIDText );
460 msi_free( ext );
463 /* Called when the package is being closed */
464 void ACTION_free_package_structures( MSIPACKAGE* package)
466 INT i;
467 struct list *item, *cursor;
469 TRACE("Freeing package action data\n");
471 remove_tracked_tempfiles(package);
473 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
475 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
476 list_remove( &feature->entry );
477 free_feature( feature );
480 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
482 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
484 list_remove( &folder->entry );
485 msi_free( folder->Parent );
486 msi_free( folder->Directory );
487 msi_free( folder->TargetDefault );
488 msi_free( folder->SourceLongPath );
489 msi_free( folder->SourceShortPath );
490 msi_free( folder->ResolvedTarget );
491 msi_free( folder->ResolvedSource );
492 msi_free( folder->Property );
493 msi_free( folder );
496 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
498 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
500 list_remove( &comp->entry );
501 msi_free( comp->Component );
502 msi_free( comp->ComponentId );
503 msi_free( comp->Directory );
504 msi_free( comp->Condition );
505 msi_free( comp->KeyPath );
506 msi_free( comp->FullKeypath );
507 msi_free( comp );
510 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
512 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
514 list_remove( &file->entry );
515 msi_free( file->File );
516 msi_free( file->FileName );
517 msi_free( file->ShortName );
518 msi_free( file->LongName );
519 msi_free( file->Version );
520 msi_free( file->Language );
521 msi_free( file->SourcePath );
522 msi_free( file->TargetPath );
523 msi_free( file );
526 /* clean up extension, progid, class and verb structures */
527 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
529 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
531 list_remove( &cls->entry );
532 msi_free( cls->clsid );
533 msi_free( cls->Context );
534 msi_free( cls->Description );
535 msi_free( cls->FileTypeMask );
536 msi_free( cls->IconPath );
537 msi_free( cls->DefInprocHandler );
538 msi_free( cls->DefInprocHandler32 );
539 msi_free( cls->Argument );
540 msi_free( cls->ProgIDText );
541 msi_free( cls );
544 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
546 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
548 list_remove( &ext->entry );
549 free_extension( ext );
552 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
554 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
556 list_remove( &progid->entry );
557 msi_free( progid->ProgID );
558 msi_free( progid->Description );
559 msi_free( progid->IconPath );
560 msi_free( progid );
563 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
565 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
567 list_remove( &mt->entry );
568 msi_free( mt->clsid );
569 msi_free( mt->ContentType );
570 msi_free( mt );
573 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
575 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
577 list_remove( &appid->entry );
578 msi_free( appid->AppID );
579 msi_free( appid->RemoteServerName );
580 msi_free( appid->LocalServer );
581 msi_free( appid->ServiceParameters );
582 msi_free( appid->DllSurrogate );
583 msi_free( appid );
586 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_info )
588 MSISOURCELISTINFO *info = LIST_ENTRY( item, MSISOURCELISTINFO, entry );
590 list_remove( &info->entry );
591 msi_free( info->value );
592 msi_free( info );
595 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_media )
597 MSIMEDIADISK *info = LIST_ENTRY( item, MSIMEDIADISK, entry );
599 list_remove( &info->entry );
600 msi_free( info->volume_label );
601 msi_free( info->disk_prompt );
602 msi_free( info );
605 if (package->script)
607 for (i = 0; i < TOTAL_SCRIPTS; i++)
608 msi_free_action_script(package, i);
610 for (i = 0; i < package->script->UniqueActionsCount; i++)
611 msi_free(package->script->UniqueActions[i]);
613 msi_free(package->script->UniqueActions);
614 msi_free(package->script);
617 msi_free(package->BaseURL);
618 msi_free(package->PackagePath);
619 msi_free(package->ProductCode);
620 msi_free(package->ActionFormat);
621 msi_free(package->LastAction);
623 /* cleanup control event subscriptions */
624 ControlEvent_CleanupSubscriptions(package);
628 * build_directory_name()
630 * This function is to save messing round with directory names
631 * It handles adding backslashes between path segments,
632 * and can add \ at the end of the directory name if told to.
634 * It takes a variable number of arguments.
635 * It always allocates a new string for the result, so make sure
636 * to free the return value when finished with it.
638 * The first arg is the number of path segments that follow.
639 * The arguments following count are a list of path segments.
640 * A path segment may be NULL.
642 * Path segments will be added with a \ separating them.
643 * A \ will not be added after the last segment, however if the
644 * last segment is NULL, then the last character will be a \
647 LPWSTR build_directory_name(DWORD count, ...)
649 DWORD sz = 1, i;
650 LPWSTR dir;
651 va_list va;
653 va_start(va,count);
654 for(i=0; i<count; i++)
656 LPCWSTR str = va_arg(va,LPCWSTR);
657 if (str)
658 sz += strlenW(str) + 1;
660 va_end(va);
662 dir = msi_alloc(sz*sizeof(WCHAR));
663 dir[0]=0;
665 va_start(va,count);
666 for(i=0; i<count; i++)
668 LPCWSTR str = va_arg(va,LPCWSTR);
669 if (!str)
670 continue;
671 strcatW(dir, str);
672 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
673 strcatW(dir, cszbs);
675 return dir;
678 /***********************************************************************
679 * create_full_pathW
681 * Recursively create all directories in the path.
683 * shamelessly stolen from setupapi/queue.c
685 BOOL create_full_pathW(const WCHAR *path)
687 BOOL ret = TRUE;
688 int len;
689 WCHAR *new_path;
691 new_path = msi_alloc( (strlenW(path) + 1) * sizeof(WCHAR));
693 strcpyW(new_path, path);
695 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
696 new_path[len - 1] = 0;
698 while(!CreateDirectoryW(new_path, NULL))
700 WCHAR *slash;
701 DWORD last_error = GetLastError();
702 if(last_error == ERROR_ALREADY_EXISTS)
703 break;
705 if(last_error != ERROR_PATH_NOT_FOUND)
707 ret = FALSE;
708 break;
711 if(!(slash = strrchrW(new_path, '\\')))
713 ret = FALSE;
714 break;
717 len = slash - new_path;
718 new_path[len] = 0;
719 if(!create_full_pathW(new_path))
721 ret = FALSE;
722 break;
724 new_path[len] = '\\';
727 msi_free(new_path);
728 return ret;
731 void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
733 MSIRECORD * row;
735 row = MSI_CreateRecord(4);
736 MSI_RecordSetInteger(row,1,a);
737 MSI_RecordSetInteger(row,2,b);
738 MSI_RecordSetInteger(row,3,c);
739 MSI_RecordSetInteger(row,4,d);
740 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
741 msiobj_release(&row->hdr);
743 msi_dialog_check_messages(NULL);
746 void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
748 static const WCHAR Query_t[] =
749 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
750 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
751 'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=',
752 ' ','\'','%','s','\'',0};
753 WCHAR message[1024];
754 MSIRECORD * row = 0;
755 DWORD size;
757 if (!package->LastAction || strcmpW(package->LastAction,action))
759 row = MSI_QueryGetRecord(package->db, Query_t, action);
760 if (!row)
761 return;
763 if (MSI_RecordIsNull(row,3))
765 msiobj_release(&row->hdr);
766 return;
769 /* update the cached actionformat */
770 msi_free(package->ActionFormat);
771 package->ActionFormat = msi_dup_record_field(row,3);
773 msi_free(package->LastAction);
774 package->LastAction = strdupW(action);
776 msiobj_release(&row->hdr);
779 MSI_RecordSetStringW(record,0,package->ActionFormat);
780 size = 1024;
781 MSI_FormatRecordW(package,record,message,&size);
783 row = MSI_CreateRecord(1);
784 MSI_RecordSetStringW(row,1,message);
786 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
788 msiobj_release(&row->hdr);
791 BOOL ACTION_VerifyComponentForAction( const MSICOMPONENT* comp, INSTALLSTATE check )
793 if (!comp)
794 return FALSE;
796 if (comp->Installed == check)
797 return FALSE;
799 if (comp->ActionRequest == check)
800 return TRUE;
801 else
802 return FALSE;
805 BOOL ACTION_VerifyFeatureForAction( const MSIFEATURE* feature, INSTALLSTATE check )
807 if (!feature)
808 return FALSE;
810 if (feature->ActionRequest == check)
811 return TRUE;
812 else
813 return FALSE;
816 void reduce_to_longfilename(WCHAR* filename)
818 LPWSTR p = strchrW(filename,'|');
819 if (p)
820 memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
823 void reduce_to_shortfilename(WCHAR* filename)
825 LPWSTR p = strchrW(filename,'|');
826 if (p)
827 *p = 0;
830 LPWSTR create_component_advertise_string(MSIPACKAGE* package,
831 MSICOMPONENT* component, LPCWSTR feature)
833 static const WCHAR fmt[] = {'%','s','%','s','%','c','%','s',0};
834 WCHAR productid_85[21], component_85[21];
835 LPWSTR output = NULL;
836 DWORD sz = 0;
837 GUID clsid;
839 /* > is used if there is a component GUID and < if not. */
841 productid_85[0] = 0;
842 component_85[0] = 0;
844 CLSIDFromString(package->ProductCode, &clsid);
845 encode_base85_guid(&clsid, productid_85);
847 if (component)
849 CLSIDFromString(component->ComponentId, &clsid);
850 encode_base85_guid(&clsid, component_85);
853 TRACE("prod=%s feat=%s comp=%s\n", debugstr_w(productid_85),
854 debugstr_w(feature), debugstr_w(component_85));
856 sz = 20 + lstrlenW(feature) + 20 + 3;
858 output = msi_alloc_zero(sz*sizeof(WCHAR));
860 sprintfW(output, fmt, productid_85, feature,
861 component?'>':'<', component_85);
863 return output;
866 /* update component state based on a feature change */
867 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
869 INSTALLSTATE newstate;
870 MSIFEATURE *feature;
871 ComponentList *cl;
873 feature = get_loaded_feature(package,szFeature);
874 if (!feature)
875 return;
877 newstate = feature->ActionRequest;
879 if (newstate == INSTALLSTATE_ABSENT)
880 newstate = INSTALLSTATE_UNKNOWN;
882 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
884 MSICOMPONENT* component = cl->component;
886 TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
887 newstate, debugstr_w(component->Component), component->Installed,
888 component->Action, component->ActionRequest);
890 if (!component->Enabled)
891 continue;
893 if (newstate == INSTALLSTATE_LOCAL)
894 msi_component_set_state( component, INSTALLSTATE_LOCAL );
895 else
897 ComponentList *clist;
898 MSIFEATURE *f;
900 component->hasLocalFeature = FALSE;
902 msi_component_set_state( component, newstate );
904 /*if any other feature wants is local we need to set it local*/
905 LIST_FOR_EACH_ENTRY( f, &package->features, MSIFEATURE, entry )
907 if ( f->ActionRequest != INSTALLSTATE_LOCAL &&
908 f->ActionRequest != INSTALLSTATE_SOURCE )
910 continue;
913 LIST_FOR_EACH_ENTRY( clist, &f->Components, ComponentList, entry )
915 if ( clist->component == component &&
916 (f->ActionRequest == INSTALLSTATE_LOCAL ||
917 f->ActionRequest == INSTALLSTATE_SOURCE) )
919 TRACE("Saved by %s\n", debugstr_w(f->Feature));
920 component->hasLocalFeature = TRUE;
922 if (component->Attributes & msidbComponentAttributesOptional)
924 if (f->Attributes & msidbFeatureAttributesFavorSource)
925 msi_component_set_state( component, INSTALLSTATE_SOURCE );
926 else
927 msi_component_set_state( component, INSTALLSTATE_LOCAL );
929 else if (component->Attributes & msidbComponentAttributesSourceOnly)
930 msi_component_set_state( component, INSTALLSTATE_SOURCE );
931 else
932 msi_component_set_state( component, INSTALLSTATE_LOCAL );
937 TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
938 newstate, debugstr_w(component->Component), component->Installed,
939 component->Action, component->ActionRequest);
943 UINT register_unique_action(MSIPACKAGE *package, LPCWSTR action)
945 UINT count;
946 LPWSTR *newbuf = NULL;
948 if (!package->script)
949 return FALSE;
951 TRACE("Registering Action %s as having fun\n",debugstr_w(action));
953 count = package->script->UniqueActionsCount;
954 package->script->UniqueActionsCount++;
955 if (count != 0)
956 newbuf = msi_realloc( package->script->UniqueActions,
957 package->script->UniqueActionsCount* sizeof(LPWSTR));
958 else
959 newbuf = msi_alloc( sizeof(LPWSTR));
961 newbuf[count] = strdupW(action);
962 package->script->UniqueActions = newbuf;
964 return ERROR_SUCCESS;
967 BOOL check_unique_action(const MSIPACKAGE *package, LPCWSTR action)
969 INT i;
971 if (!package->script)
972 return FALSE;
974 for (i = 0; i < package->script->UniqueActionsCount; i++)
975 if (!strcmpW(package->script->UniqueActions[i],action))
976 return TRUE;
978 return FALSE;
981 WCHAR* generate_error_string(MSIPACKAGE *package, UINT error, DWORD count, ... )
983 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};
985 MSIRECORD *rec;
986 MSIRECORD *row;
987 DWORD size = 0;
988 DWORD i;
989 va_list va;
990 LPCWSTR str;
991 LPWSTR data;
993 row = MSI_QueryGetRecord(package->db, query, error);
994 if (!row)
995 return 0;
997 rec = MSI_CreateRecord(count+2);
999 str = MSI_RecordGetString(row,1);
1000 MSI_RecordSetStringW(rec,0,str);
1001 msiobj_release( &row->hdr );
1002 MSI_RecordSetInteger(rec,1,error);
1004 va_start(va,count);
1005 for (i = 0; i < count; i++)
1007 str = va_arg(va,LPCWSTR);
1008 MSI_RecordSetStringW(rec,(i+2),str);
1010 va_end(va);
1012 MSI_FormatRecordW(package,rec,NULL,&size);
1014 size++;
1015 data = msi_alloc(size*sizeof(WCHAR));
1016 if (size > 1)
1017 MSI_FormatRecordW(package,rec,data,&size);
1018 else
1019 data[0] = 0;
1020 msiobj_release( &rec->hdr );
1021 return data;
1024 void msi_ui_error( DWORD msg_id, DWORD type )
1026 WCHAR text[2048];
1028 static const WCHAR title[] = {
1029 'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0
1032 if (!MsiLoadStringW( -1, msg_id, text, sizeof(text) / sizeof(text[0]),
1033 MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) ))
1034 return;
1036 MessageBoxW( NULL, text, title, type );