Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / msi / helpers.c
blob74665e57d5981774a54e92f17564120da8fba1ce
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, BOOL load_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 (!source && load_prop && (path = msi_dup_property( package, name )))
298 f->ResolvedTarget = strdupW( path );
299 TRACE(" property set to %s\n", debugstr_w(path));
300 return path;
303 if (!f->Parent)
304 return path;
306 parent = f->Parent;
308 TRACE(" ! Parent is %s\n", debugstr_w(parent));
310 p = resolve_folder(package, parent, source, set_prop, load_prop, NULL);
311 if (!source)
313 WCHAR szShellObjectFolder[] =
314 {'S','H','E','L','L','_','O','B','J','E','C','T','_','F','O','L','D','E','R',0};
316 TRACE(" TargetDefault = %s\n", debugstr_w(f->TargetDefault));
318 /* hack for GUPTA */
319 if (f->TargetDefault && strcmpW( f->TargetDefault, szShellObjectFolder)==0)
321 LPWSTR sof = msi_dup_property(package,szShellObjectFolder);
322 if (sof)
324 path = build_directory_name(3, p, sof, NULL);
325 msi_free(sof);
327 else
328 path = build_directory_name(3, p, f->TargetDefault, NULL);
330 else
331 path = build_directory_name(3, p, f->TargetDefault, NULL);
333 clean_spaces_from_path( path );
334 f->ResolvedTarget = strdupW( path );
335 TRACE("target -> %s\n", debugstr_w(path));
336 if (set_prop)
337 MSI_SetPropertyW(package,name,path);
339 else
341 /* source may be in a few different places ... check each of them */
342 path = NULL;
344 /* try the long path directory */
345 if (f->SourceLongPath)
347 path = build_directory_name( 3, p, f->SourceLongPath, NULL );
348 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
350 msi_free( path );
351 path = NULL;
355 /* try the short path directory */
356 if (!path && f->SourceShortPath)
358 path = build_directory_name( 3, p, f->SourceShortPath, NULL );
359 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
361 msi_free( path );
362 path = NULL;
366 /* try the root of the install */
367 if (!path)
368 path = get_source_root( package );
370 TRACE("source -> %s\n", debugstr_w(path));
371 f->ResolvedSource = strdupW( path );
373 msi_free(p);
375 return path;
378 /* wrapper to resist a need for a full rewrite right now */
379 DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data )
381 if (ptr)
383 MSIRECORD *rec = MSI_CreateRecord(1);
384 DWORD size = 0;
386 MSI_RecordSetStringW(rec,0,ptr);
387 MSI_FormatRecordW(package,rec,NULL,&size);
388 if (size >= 0)
390 size++;
391 *data = msi_alloc(size*sizeof(WCHAR));
392 if (size > 1)
393 MSI_FormatRecordW(package,rec,*data,&size);
394 else
395 *data[0] = 0;
396 msiobj_release( &rec->hdr );
397 return sizeof(WCHAR)*size;
399 msiobj_release( &rec->hdr );
402 *data = NULL;
403 return 0;
406 UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action)
408 UINT count;
409 LPWSTR *newbuf = NULL;
410 if (script >= TOTAL_SCRIPTS)
412 FIXME("Unknown script requested %i\n",script);
413 return ERROR_FUNCTION_FAILED;
415 TRACE("Scheduling Action %s in script %i\n",debugstr_w(action), script);
417 count = package->script->ActionCount[script];
418 package->script->ActionCount[script]++;
419 if (count != 0)
420 newbuf = msi_realloc( package->script->Actions[script],
421 package->script->ActionCount[script]* sizeof(LPWSTR));
422 else
423 newbuf = msi_alloc( sizeof(LPWSTR));
425 newbuf[count] = strdupW(action);
426 package->script->Actions[script] = newbuf;
428 return ERROR_SUCCESS;
431 void msi_free_action_script(MSIPACKAGE *package, UINT script)
433 int i;
434 for (i = 0; i < package->script->ActionCount[script]; i++)
435 msi_free(package->script->Actions[script][i]);
437 msi_free(package->script->Actions[script]);
438 package->script->Actions[script] = NULL;
439 package->script->ActionCount[script] = 0;
442 static void remove_tracked_tempfiles(MSIPACKAGE* package)
444 struct list *item, *cursor;
446 LIST_FOR_EACH_SAFE( item, cursor, &package->tempfiles )
448 MSITEMPFILE *temp = LIST_ENTRY( item, MSITEMPFILE, entry );
450 list_remove( &temp->entry );
451 TRACE("deleting temp file %s\n", debugstr_w( temp->Path ));
452 if (!DeleteFileW( temp->Path ))
453 ERR("failed to delete %s\n", debugstr_w( temp->Path ));
454 msi_free( temp->Path );
455 msi_free( temp );
459 static void free_feature( MSIFEATURE *feature )
461 struct list *item, *cursor;
463 LIST_FOR_EACH_SAFE( item, cursor, &feature->Children )
465 FeatureList *fl = LIST_ENTRY( item, FeatureList, entry );
466 list_remove( &fl->entry );
467 msi_free( fl );
470 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
472 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
473 list_remove( &cl->entry );
474 msi_free( cl );
476 msi_free( feature->Feature );
477 msi_free( feature->Feature_Parent );
478 msi_free( feature->Directory );
479 msi_free( feature->Description );
480 msi_free( feature->Title );
481 msi_free( feature );
484 static void free_extension( MSIEXTENSION *ext )
486 struct list *item, *cursor;
488 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
490 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
492 list_remove( &verb->entry );
493 msi_free( verb->Verb );
494 msi_free( verb->Command );
495 msi_free( verb->Argument );
496 msi_free( verb );
499 msi_free( ext->Extension );
500 msi_free( ext->ProgIDText );
501 msi_free( ext );
504 /* Called when the package is being closed */
505 void ACTION_free_package_structures( MSIPACKAGE* package)
507 INT i;
508 struct list *item, *cursor;
510 TRACE("Freeing package action data\n");
512 remove_tracked_tempfiles(package);
514 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
516 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
517 list_remove( &feature->entry );
518 free_feature( feature );
521 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
523 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
525 list_remove( &folder->entry );
526 msi_free( folder->Parent );
527 msi_free( folder->Directory );
528 msi_free( folder->TargetDefault );
529 msi_free( folder->SourceLongPath );
530 msi_free( folder->SourceShortPath );
531 msi_free( folder->ResolvedTarget );
532 msi_free( folder->ResolvedSource );
533 msi_free( folder->Property );
534 msi_free( folder );
537 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
539 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
541 list_remove( &comp->entry );
542 msi_free( comp->Component );
543 msi_free( comp->ComponentId );
544 msi_free( comp->Directory );
545 msi_free( comp->Condition );
546 msi_free( comp->KeyPath );
547 msi_free( comp->FullKeypath );
548 msi_free( comp );
551 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
553 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
555 list_remove( &file->entry );
556 msi_free( file->File );
557 msi_free( file->FileName );
558 msi_free( file->ShortName );
559 msi_free( file->LongName );
560 msi_free( file->Version );
561 msi_free( file->Language );
562 msi_free( file->SourcePath );
563 msi_free( file->TargetPath );
564 msi_free( file );
567 /* clean up extension, progid, class and verb structures */
568 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
570 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
572 list_remove( &cls->entry );
573 msi_free( cls->clsid );
574 msi_free( cls->Context );
575 msi_free( cls->Description );
576 msi_free( cls->FileTypeMask );
577 msi_free( cls->IconPath );
578 msi_free( cls->DefInprocHandler );
579 msi_free( cls->DefInprocHandler32 );
580 msi_free( cls->Argument );
581 msi_free( cls->ProgIDText );
582 msi_free( cls );
585 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
587 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
589 list_remove( &ext->entry );
590 free_extension( ext );
593 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
595 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
597 list_remove( &progid->entry );
598 msi_free( progid->ProgID );
599 msi_free( progid->Description );
600 msi_free( progid->IconPath );
601 msi_free( progid );
604 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
606 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
608 list_remove( &mt->entry );
609 msi_free( mt->clsid );
610 msi_free( mt->ContentType );
611 msi_free( mt );
614 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
616 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
618 list_remove( &appid->entry );
619 msi_free( appid->AppID );
620 msi_free( appid->RemoteServerName );
621 msi_free( appid->LocalServer );
622 msi_free( appid->ServiceParameters );
623 msi_free( appid->DllSurrogate );
624 msi_free( appid );
627 if (package->script)
629 for (i = 0; i < TOTAL_SCRIPTS; i++)
630 msi_free_action_script(package, i);
632 for (i = 0; i < package->script->UniqueActionsCount; i++)
633 msi_free(package->script->UniqueActions[i]);
635 msi_free(package->script->UniqueActions);
636 msi_free(package->script);
639 msi_free(package->BaseURL);
640 msi_free(package->PackagePath);
641 msi_free(package->ProductCode);
642 msi_free(package->ActionFormat);
643 msi_free(package->LastAction);
645 /* cleanup control event subscriptions */
646 ControlEvent_CleanupSubscriptions(package);
650 * build_directory_name()
652 * This function is to save messing round with directory names
653 * It handles adding backslashes between path segments,
654 * and can add \ at the end of the directory name if told to.
656 * It takes a variable number of arguments.
657 * It always allocates a new string for the result, so make sure
658 * to free the return value when finished with it.
660 * The first arg is the number of path segments that follow.
661 * The arguments following count are a list of path segments.
662 * A path segment may be NULL.
664 * Path segments will be added with a \ separating them.
665 * A \ will not be added after the last segment, however if the
666 * last segment is NULL, then the last character will be a \
669 LPWSTR build_directory_name(DWORD count, ...)
671 DWORD sz = 1, i;
672 LPWSTR dir;
673 va_list va;
675 va_start(va,count);
676 for(i=0; i<count; i++)
678 LPCWSTR str = va_arg(va,LPCWSTR);
679 if (str)
680 sz += strlenW(str) + 1;
682 va_end(va);
684 dir = msi_alloc(sz*sizeof(WCHAR));
685 dir[0]=0;
687 va_start(va,count);
688 for(i=0; i<count; i++)
690 LPCWSTR str = va_arg(va,LPCWSTR);
691 if (!str)
692 continue;
693 strcatW(dir, str);
694 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
695 strcatW(dir, cszbs);
697 return dir;
700 /***********************************************************************
701 * create_full_pathW
703 * Recursively create all directories in the path.
705 * shamelessly stolen from setupapi/queue.c
707 BOOL create_full_pathW(const WCHAR *path)
709 BOOL ret = TRUE;
710 int len;
711 WCHAR *new_path;
713 new_path = msi_alloc( (strlenW(path) + 1) * sizeof(WCHAR));
715 strcpyW(new_path, path);
717 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
718 new_path[len - 1] = 0;
720 while(!CreateDirectoryW(new_path, NULL))
722 WCHAR *slash;
723 DWORD last_error = GetLastError();
724 if(last_error == ERROR_ALREADY_EXISTS)
725 break;
727 if(last_error != ERROR_PATH_NOT_FOUND)
729 ret = FALSE;
730 break;
733 if(!(slash = strrchrW(new_path, '\\')))
735 ret = FALSE;
736 break;
739 len = slash - new_path;
740 new_path[len] = 0;
741 if(!create_full_pathW(new_path))
743 ret = FALSE;
744 break;
746 new_path[len] = '\\';
749 msi_free(new_path);
750 return ret;
753 void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
755 MSIRECORD * row;
757 row = MSI_CreateRecord(4);
758 MSI_RecordSetInteger(row,1,a);
759 MSI_RecordSetInteger(row,2,b);
760 MSI_RecordSetInteger(row,3,c);
761 MSI_RecordSetInteger(row,4,d);
762 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
763 msiobj_release(&row->hdr);
765 msi_dialog_check_messages(NULL);
768 void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
770 static const WCHAR Query_t[] =
771 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
772 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
773 'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=',
774 ' ','\'','%','s','\'',0};
775 WCHAR message[1024];
776 MSIRECORD * row = 0;
777 DWORD size;
779 if (!package->LastAction || strcmpW(package->LastAction,action))
781 row = MSI_QueryGetRecord(package->db, Query_t, action);
782 if (!row)
783 return;
785 if (MSI_RecordIsNull(row,3))
787 msiobj_release(&row->hdr);
788 return;
791 /* update the cached actionformat */
792 msi_free(package->ActionFormat);
793 package->ActionFormat = msi_dup_record_field(row,3);
795 msi_free(package->LastAction);
796 package->LastAction = strdupW(action);
798 msiobj_release(&row->hdr);
801 MSI_RecordSetStringW(record,0,package->ActionFormat);
802 size = 1024;
803 MSI_FormatRecordW(package,record,message,&size);
805 row = MSI_CreateRecord(1);
806 MSI_RecordSetStringW(row,1,message);
808 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
810 msiobj_release(&row->hdr);
813 BOOL ACTION_VerifyComponentForAction( MSICOMPONENT* comp, INSTALLSTATE check )
815 if (!comp)
816 return FALSE;
818 if (comp->Installed == check)
819 return FALSE;
821 if (comp->ActionRequest == check)
822 return TRUE;
823 else
824 return FALSE;
827 BOOL ACTION_VerifyFeatureForAction( MSIFEATURE* feature, INSTALLSTATE check )
829 if (!feature)
830 return FALSE;
832 if (feature->Installed == check)
833 return FALSE;
835 if (feature->ActionRequest == check)
836 return TRUE;
837 else
838 return FALSE;
841 void reduce_to_longfilename(WCHAR* filename)
843 LPWSTR p = strchrW(filename,'|');
844 if (p)
845 memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
848 void reduce_to_shortfilename(WCHAR* filename)
850 LPWSTR p = strchrW(filename,'|');
851 if (p)
852 *p = 0;
855 LPWSTR create_component_advertise_string(MSIPACKAGE* package,
856 MSICOMPONENT* component, LPCWSTR feature)
858 static const WCHAR fmt[] = {'%','s','%','s','%','c','%','s',0};
859 WCHAR productid_85[21], component_85[21];
860 LPWSTR output = NULL;
861 DWORD sz = 0;
862 GUID clsid;
864 /* > is used if there is a component GUID and < if not. */
866 productid_85[0] = 0;
867 component_85[0] = 0;
869 CLSIDFromString(package->ProductCode, &clsid);
870 encode_base85_guid(&clsid, productid_85);
872 if (component)
874 CLSIDFromString(component->ComponentId, &clsid);
875 encode_base85_guid(&clsid, component_85);
878 TRACE("prod=%s feat=%s comp=%s\n", debugstr_w(productid_85),
879 debugstr_w(feature), debugstr_w(component_85));
881 sz = 20 + lstrlenW(feature) + 20 + 3;
883 output = msi_alloc_zero(sz*sizeof(WCHAR));
885 sprintfW(output, fmt, productid_85, feature,
886 component?'>':'<', component_85);
888 return output;
891 /* update compoennt state based on a feature change */
892 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
894 INSTALLSTATE newstate;
895 MSIFEATURE *feature;
896 ComponentList *cl;
898 feature = get_loaded_feature(package,szFeature);
899 if (!feature)
900 return;
902 newstate = feature->ActionRequest;
904 if (newstate == INSTALLSTATE_ABSENT)
905 newstate = INSTALLSTATE_UNKNOWN;
907 LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
909 MSICOMPONENT* component = cl->component;
911 TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
912 newstate, debugstr_w(component->Component), component->Installed,
913 component->Action, component->ActionRequest);
915 if (!component->Enabled)
916 continue;
918 if (newstate == INSTALLSTATE_LOCAL)
919 msi_component_set_state( component, INSTALLSTATE_LOCAL );
920 else
922 ComponentList *clist;
923 MSIFEATURE *f;
925 msi_component_set_state( component, newstate );
927 /*if any other feature wants is local we need to set it local*/
928 LIST_FOR_EACH_ENTRY( f, &package->features, MSIFEATURE, entry )
930 if ( f->ActionRequest != INSTALLSTATE_LOCAL &&
931 f->ActionRequest != INSTALLSTATE_SOURCE )
933 continue;
936 LIST_FOR_EACH_ENTRY( clist, &f->Components, ComponentList, entry )
938 if ( clist->component == component &&
939 (f->ActionRequest == INSTALLSTATE_LOCAL ||
940 f->ActionRequest == INSTALLSTATE_SOURCE) )
942 TRACE("Saved by %s\n", debugstr_w(f->Feature));
944 if (component->Attributes & msidbComponentAttributesOptional)
946 if (f->Attributes & msidbFeatureAttributesFavorSource)
947 msi_component_set_state( component, INSTALLSTATE_SOURCE );
948 else
949 msi_component_set_state( component, INSTALLSTATE_LOCAL );
951 else if (component->Attributes & msidbComponentAttributesSourceOnly)
952 msi_component_set_state( component, INSTALLSTATE_SOURCE );
953 else
954 msi_component_set_state( component, INSTALLSTATE_LOCAL );
959 TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
960 newstate, debugstr_w(component->Component), component->Installed,
961 component->Action, component->ActionRequest);
965 UINT register_unique_action(MSIPACKAGE *package, LPCWSTR action)
967 UINT count;
968 LPWSTR *newbuf = NULL;
970 if (!package->script)
971 return FALSE;
973 TRACE("Registering Action %s as having fun\n",debugstr_w(action));
975 count = package->script->UniqueActionsCount;
976 package->script->UniqueActionsCount++;
977 if (count != 0)
978 newbuf = msi_realloc( package->script->UniqueActions,
979 package->script->UniqueActionsCount* sizeof(LPWSTR));
980 else
981 newbuf = msi_alloc( sizeof(LPWSTR));
983 newbuf[count] = strdupW(action);
984 package->script->UniqueActions = newbuf;
986 return ERROR_SUCCESS;
989 BOOL check_unique_action(MSIPACKAGE *package, LPCWSTR action)
991 INT i;
993 if (!package->script)
994 return FALSE;
996 for (i = 0; i < package->script->UniqueActionsCount; i++)
997 if (!strcmpW(package->script->UniqueActions[i],action))
998 return TRUE;
1000 return FALSE;
1003 WCHAR* generate_error_string(MSIPACKAGE *package, UINT error, DWORD count, ... )
1005 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};
1007 MSIRECORD *rec;
1008 MSIRECORD *row;
1009 DWORD size = 0;
1010 DWORD i;
1011 va_list va;
1012 LPCWSTR str;
1013 LPWSTR data;
1015 row = MSI_QueryGetRecord(package->db, query, error);
1016 if (!row)
1017 return 0;
1019 rec = MSI_CreateRecord(count+2);
1021 str = MSI_RecordGetString(row,1);
1022 MSI_RecordSetStringW(rec,0,str);
1023 msiobj_release( &row->hdr );
1024 MSI_RecordSetInteger(rec,1,error);
1026 va_start(va,count);
1027 for (i = 0; i < count; i++)
1029 str = va_arg(va,LPCWSTR);
1030 MSI_RecordSetStringW(rec,(i+2),str);
1032 va_end(va);
1034 MSI_FormatRecordW(package,rec,NULL,&size);
1035 if (size >= 0)
1037 size++;
1038 data = msi_alloc(size*sizeof(WCHAR));
1039 if (size > 1)
1040 MSI_FormatRecordW(package,rec,data,&size);
1041 else
1042 data[0] = 0;
1043 msiobj_release( &rec->hdr );
1044 return data;
1047 msiobj_release( &rec->hdr );
1048 data = NULL;
1049 return data;
1052 void msi_ui_error( DWORD msg_id, DWORD type )
1054 WCHAR text[2048];
1056 static const WCHAR title[] = {
1057 'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0
1060 if (!MsiLoadStringW( -1, msg_id, text, sizeof(text) / sizeof(text[0]),
1061 MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) ))
1062 return;
1064 MessageBoxW( NULL, text, title, type );