crypt32: Add stubs for CertDuplicateCRLContext and CertDuplicateCTLContext.
[wine/multimedia.git] / dlls / msi / helpers.c
blob6d3d7e33881b06c091f54dcdaa9adc720350d198
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;
232 * clean_spaces_from_path()
234 * removes spaces from the beginning and end of path segments
235 * removes multiple \\ characters
237 static void clean_spaces_from_path( LPWSTR p )
239 LPWSTR q = p;
240 int n, len = 0;
242 while (1)
244 /* copy until the end of the string or a space */
245 while (*p != ' ' && (*q = *p))
247 p++, len++;
248 /* reduce many backslashes to one */
249 if (*p != '\\' || *q != '\\')
250 q++;
253 /* quit at the end of the string */
254 if (!*p)
255 break;
257 /* count the number of spaces */
258 n = 0;
259 while (p[n] == ' ')
260 n++;
262 /* if it's leading or trailing space, skip it */
263 if ( len == 0 || p[-1] == '\\' || p[n] == '\\' )
264 p += n;
265 else /* copy n spaces */
266 while (n && (*q++ = *p++)) n--;
270 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
271 BOOL set_prop, MSIFOLDER **folder)
273 MSIFOLDER *f;
274 LPWSTR p, path = NULL;
276 TRACE("Working to resolve %s\n",debugstr_w(name));
278 if (!name)
279 return NULL;
281 /* special resolving for Target and Source root dir */
282 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
284 if (!source)
286 LPWSTR check_path;
287 check_path = msi_dup_property( package, cszTargetDir );
288 if (!check_path)
290 check_path = msi_dup_property( package, cszRootDrive );
291 if (set_prop)
292 MSI_SetPropertyW(package,cszTargetDir,check_path);
295 /* correct misbuilt target dir */
296 path = build_directory_name(2, check_path, NULL);
297 clean_spaces_from_path( path );
298 if (strcmpiW(path,check_path)!=0)
299 MSI_SetPropertyW(package,cszTargetDir,path);
300 msi_free(check_path);
302 else
303 path = get_source_root( package );
304 if (folder)
305 *folder = get_loaded_folder( package, name );
306 return path;
309 f = get_loaded_folder( package, name );
310 if (!f)
311 return NULL;
313 if (folder)
314 *folder = f;
316 if (!source && f->ResolvedTarget)
318 path = strdupW( f->ResolvedTarget );
319 TRACE(" already resolved to %s\n",debugstr_w(path));
320 return path;
322 else if (source && f->ResolvedSource)
324 path = strdupW( f->ResolvedSource );
325 TRACE(" (source)already resolved to %s\n",debugstr_w(path));
326 return path;
328 else if (!source && f->Property)
330 path = build_directory_name( 2, f->Property, NULL );
332 TRACE(" internally set to %s\n",debugstr_w(path));
333 if (set_prop)
334 MSI_SetPropertyW( package, name, path );
335 return path;
338 if (f->Parent)
340 LPWSTR parent = f->Parent->Directory;
342 TRACE(" ! Parent is %s\n", debugstr_w(parent));
344 p = resolve_folder(package, parent, source, set_prop, NULL);
345 if (!source)
347 TRACE(" TargetDefault = %s\n", debugstr_w(f->TargetDefault));
349 path = build_directory_name( 3, p, f->TargetDefault, NULL );
350 clean_spaces_from_path( path );
351 f->ResolvedTarget = strdupW( path );
352 TRACE("target -> %s\n", debugstr_w(path));
353 if (set_prop)
354 MSI_SetPropertyW(package,name,path);
356 else
358 /* source may be in a few different places ... check each of them */
359 path = NULL;
361 /* try the long path directory */
362 if (f->SourceLongPath)
364 path = build_directory_name( 3, p, f->SourceLongPath, NULL );
365 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
367 msi_free( path );
368 path = NULL;
372 /* try the short path directory */
373 if (!path && f->SourceShortPath)
375 path = build_directory_name( 3, p, f->SourceShortPath, NULL );
376 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
378 msi_free( path );
379 path = NULL;
383 /* try the root of the install */
384 if (!path)
385 path = get_source_root( package );
387 TRACE("source -> %s\n", debugstr_w(path));
388 f->ResolvedSource = strdupW( path );
390 msi_free(p);
392 return path;
395 /* wrapper to resist a need for a full rewrite right now */
396 DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data )
398 if (ptr)
400 MSIRECORD *rec = MSI_CreateRecord(1);
401 DWORD size = 0;
403 MSI_RecordSetStringW(rec,0,ptr);
404 MSI_FormatRecordW(package,rec,NULL,&size);
405 if (size >= 0)
407 size++;
408 *data = msi_alloc(size*sizeof(WCHAR));
409 if (size > 1)
410 MSI_FormatRecordW(package,rec,*data,&size);
411 else
412 *data[0] = 0;
413 msiobj_release( &rec->hdr );
414 return sizeof(WCHAR)*size;
416 msiobj_release( &rec->hdr );
419 *data = NULL;
420 return 0;
423 UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action)
425 UINT count;
426 LPWSTR *newbuf = NULL;
427 if (script >= TOTAL_SCRIPTS)
429 FIXME("Unknown script requested %i\n",script);
430 return ERROR_FUNCTION_FAILED;
432 TRACE("Scheduling Action %s in script %i\n",debugstr_w(action), script);
434 count = package->script->ActionCount[script];
435 package->script->ActionCount[script]++;
436 if (count != 0)
437 newbuf = msi_realloc( package->script->Actions[script],
438 package->script->ActionCount[script]* sizeof(LPWSTR));
439 else
440 newbuf = msi_alloc( sizeof(LPWSTR));
442 newbuf[count] = strdupW(action);
443 package->script->Actions[script] = newbuf;
445 return ERROR_SUCCESS;
448 static void remove_tracked_tempfiles(MSIPACKAGE* package)
450 struct list *item, *cursor;
452 LIST_FOR_EACH_SAFE( item, cursor, &package->tempfiles )
454 MSITEMPFILE *temp = LIST_ENTRY( item, MSITEMPFILE, entry );
456 list_remove( &temp->entry );
457 TRACE("deleting temp file %s\n", debugstr_w( temp->Path ));
458 DeleteFileW( temp->Path );
459 msi_free( temp->File );
460 msi_free( temp->Path );
461 msi_free( temp );
465 static void free_feature( MSIFEATURE *feature )
467 struct list *item, *cursor;
469 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
471 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
472 list_remove( &cl->entry );
473 msi_free( cl );
475 msi_free( feature->Feature );
476 msi_free( feature->Feature_Parent );
477 msi_free( feature->Directory );
478 msi_free( feature->Description );
479 msi_free( feature->Title );
480 msi_free( feature );
483 void free_extension( MSIEXTENSION *ext )
485 struct list *item, *cursor;
487 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
489 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
491 list_remove( &verb->entry );
492 msi_free( verb->Verb );
493 msi_free( verb->Command );
494 msi_free( verb->Argument );
495 msi_free( verb );
498 msi_free( ext->Extension );
499 msi_free( ext->ProgIDText );
500 msi_free( ext );
503 /* Called when the package is being closed */
504 void ACTION_free_package_structures( MSIPACKAGE* package)
506 INT i;
507 struct list *item, *cursor;
509 TRACE("Freeing package action data\n");
511 remove_tracked_tempfiles(package);
513 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
515 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
516 list_remove( &feature->entry );
517 free_feature( feature );
520 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
522 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
524 list_remove( &folder->entry );
525 msi_free( folder->Directory );
526 msi_free( folder->TargetDefault );
527 msi_free( folder->SourceLongPath );
528 msi_free( folder->SourceShortPath );
529 msi_free( folder->ResolvedTarget );
530 msi_free( folder->ResolvedSource );
531 msi_free( folder->Property );
532 msi_free( folder );
535 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
537 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
539 list_remove( &comp->entry );
540 msi_free( comp->Component );
541 msi_free( comp->ComponentId );
542 msi_free( comp->Directory );
543 msi_free( comp->Condition );
544 msi_free( comp->KeyPath );
545 msi_free( comp->FullKeypath );
546 msi_free( comp );
549 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
551 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
553 list_remove( &file->entry );
554 msi_free( file->File );
555 msi_free( file->FileName );
556 msi_free( file->ShortName );
557 msi_free( file->LongName );
558 msi_free( file->Version );
559 msi_free( file->Language );
560 msi_free( file->SourcePath );
561 msi_free( file->TargetPath );
562 msi_free( file );
565 /* clean up extension, progid, class and verb structures */
566 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
568 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
570 list_remove( &cls->entry );
571 msi_free( cls->clsid );
572 msi_free( cls->Context );
573 msi_free( cls->Description );
574 msi_free( cls->FileTypeMask );
575 msi_free( cls->IconPath );
576 msi_free( cls->DefInprocHandler );
577 msi_free( cls->DefInprocHandler32 );
578 msi_free( cls->Argument );
579 msi_free( cls->ProgIDText );
580 msi_free( cls );
583 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
585 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
587 list_remove( &ext->entry );
588 free_extension( ext );
591 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
593 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
595 list_remove( &progid->entry );
596 msi_free( progid->ProgID );
597 msi_free( progid->Description );
598 msi_free( progid->IconPath );
599 msi_free( progid );
602 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
604 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
606 list_remove( &mt->entry );
607 msi_free( mt->clsid );
608 msi_free( mt->ContentType );
609 msi_free( mt );
612 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
614 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
616 list_remove( &appid->entry );
617 msi_free( appid->AppID );
618 msi_free( appid->RemoteServerName );
619 msi_free( appid->LocalServer );
620 msi_free( appid->ServiceParameters );
621 msi_free( appid->DllSurrogate );
622 msi_free( appid );
625 if (package->script)
627 for (i = 0; i < TOTAL_SCRIPTS; i++)
629 int j;
630 for (j = 0; j < package->script->ActionCount[i]; j++)
631 msi_free(package->script->Actions[i][j]);
633 msi_free(package->script->Actions[i]);
636 for (i = 0; i < package->script->UniqueActionsCount; i++)
637 msi_free(package->script->UniqueActions[i]);
639 msi_free(package->script->UniqueActions);
640 msi_free(package->script);
643 msi_free(package->PackagePath);
644 msi_free(package->ProductCode);
645 msi_free(package->ActionFormat);
646 msi_free(package->LastAction);
648 /* cleanup control event subscriptions */
649 ControlEvent_CleanupSubscriptions(package);
653 * build_directory_name()
655 * This function is to save messing round with directory names
656 * It handles adding backslashes between path segments,
657 * and can add \ at the end of the directory name if told to.
659 * It takes a variable number of arguments.
660 * It always allocates a new string for the result, so make sure
661 * to free the return value when finished with it.
663 * The first arg is the number of path segments that follow.
664 * The arguments following count are a list of path segments.
665 * A path segment may be NULL.
667 * Path segments will be added with a \ separating them.
668 * A \ will not be added after the last segment, however if the
669 * last segment is NULL, then the last character will be a \
672 LPWSTR build_directory_name(DWORD count, ...)
674 DWORD sz = 1, i;
675 LPWSTR dir;
676 va_list va;
678 va_start(va,count);
679 for(i=0; i<count; i++)
681 LPCWSTR str = va_arg(va,LPCWSTR);
682 if (str)
683 sz += strlenW(str) + 1;
685 va_end(va);
687 dir = msi_alloc(sz*sizeof(WCHAR));
688 dir[0]=0;
690 va_start(va,count);
691 for(i=0; i<count; i++)
693 LPCWSTR str = va_arg(va,LPCWSTR);
694 if (!str)
695 continue;
696 strcatW(dir, str);
697 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
698 strcatW(dir, cszbs);
700 return dir;
703 /***********************************************************************
704 * create_full_pathW
706 * Recursively create all directories in the path.
708 * shamelessly stolen from setupapi/queue.c
710 BOOL create_full_pathW(const WCHAR *path)
712 BOOL ret = TRUE;
713 int len;
714 WCHAR *new_path;
716 new_path = msi_alloc( (strlenW(path) + 1) * sizeof(WCHAR));
718 strcpyW(new_path, path);
720 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
721 new_path[len - 1] = 0;
723 while(!CreateDirectoryW(new_path, NULL))
725 WCHAR *slash;
726 DWORD last_error = GetLastError();
727 if(last_error == ERROR_ALREADY_EXISTS)
728 break;
730 if(last_error != ERROR_PATH_NOT_FOUND)
732 ret = FALSE;
733 break;
736 if(!(slash = strrchrW(new_path, '\\')))
738 ret = FALSE;
739 break;
742 len = slash - new_path;
743 new_path[len] = 0;
744 if(!create_full_pathW(new_path))
746 ret = FALSE;
747 break;
749 new_path[len] = '\\';
752 msi_free(new_path);
753 return ret;
756 void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
758 MSIRECORD * row;
760 row = MSI_CreateRecord(4);
761 MSI_RecordSetInteger(row,1,a);
762 MSI_RecordSetInteger(row,2,b);
763 MSI_RecordSetInteger(row,3,c);
764 MSI_RecordSetInteger(row,4,d);
765 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
766 msiobj_release(&row->hdr);
768 msi_dialog_check_messages(NULL);
771 void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
773 static const WCHAR Query_t[] =
774 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
775 '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
776 'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=',
777 ' ','\'','%','s','\'',0};
778 WCHAR message[1024];
779 MSIRECORD * row = 0;
780 DWORD size;
782 if (!package->LastAction || strcmpW(package->LastAction,action))
784 row = MSI_QueryGetRecord(package->db, Query_t, action);
785 if (!row)
786 return;
788 if (MSI_RecordIsNull(row,3))
790 msiobj_release(&row->hdr);
791 return;
794 /* update the cached actionformat */
795 msi_free(package->ActionFormat);
796 package->ActionFormat = msi_dup_record_field(row,3);
798 msi_free(package->LastAction);
799 package->LastAction = strdupW(action);
801 msiobj_release(&row->hdr);
804 MSI_RecordSetStringW(record,0,package->ActionFormat);
805 size = 1024;
806 MSI_FormatRecordW(package,record,message,&size);
808 row = MSI_CreateRecord(1);
809 MSI_RecordSetStringW(row,1,message);
811 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
813 msiobj_release(&row->hdr);
816 BOOL ACTION_VerifyComponentForAction( MSICOMPONENT* comp, INSTALLSTATE check )
818 if (!comp)
819 return FALSE;
821 if (comp->Installed == check)
822 return FALSE;
824 if (comp->ActionRequest == check)
825 return TRUE;
826 else
827 return FALSE;
830 BOOL ACTION_VerifyFeatureForAction( MSIFEATURE* feature, INSTALLSTATE check )
832 if (!feature)
833 return FALSE;
835 if (feature->Installed == check)
836 return FALSE;
838 if (feature->ActionRequest == check)
839 return TRUE;
840 else
841 return FALSE;
844 void reduce_to_longfilename(WCHAR* filename)
846 LPWSTR p = strchrW(filename,'|');
847 if (p)
848 memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
851 void reduce_to_shortfilename(WCHAR* filename)
853 LPWSTR p = strchrW(filename,'|');
854 if (p)
855 *p = 0;
858 LPWSTR create_component_advertise_string(MSIPACKAGE* package,
859 MSICOMPONENT* component, LPCWSTR feature)
861 static const WCHAR fmt[] = {'%','s','%','s','%','c','%','s',0};
862 WCHAR productid_85[21], component_85[21];
863 LPWSTR output = NULL;
864 DWORD sz = 0;
865 GUID clsid;
867 /* > is used if there is a component GUID and < if not. */
869 productid_85[0] = 0;
870 component_85[0] = 0;
872 CLSIDFromString(package->ProductCode, &clsid);
873 encode_base85_guid(&clsid, productid_85);
875 if (component)
877 CLSIDFromString(component->ComponentId, &clsid);
878 encode_base85_guid(&clsid, component_85);
881 TRACE("prod=%s feat=%s comp=%s\n", debugstr_w(productid_85),
882 debugstr_w(feature), debugstr_w(component_85));
884 sz = 20 + lstrlenW(feature) + 20 + 3;
886 output = msi_alloc_zero(sz*sizeof(WCHAR));
888 sprintfW(output, fmt, productid_85, feature,
889 component?'>':'<', component_85);
891 return output;
894 /* update compoennt state based on a feature change */
895 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
897 INSTALLSTATE newstate;
898 MSIFEATURE *feature;
899 ComponentList *cl;
901 feature = get_loaded_feature(package,szFeature);
902 if (!feature)
903 return;
905 newstate = feature->ActionRequest;
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)
920 component->ActionRequest = INSTALLSTATE_LOCAL;
921 component->Action = INSTALLSTATE_LOCAL;
923 else
925 ComponentList *clist;
926 MSIFEATURE *f;
928 component->ActionRequest = newstate;
929 component->Action = newstate;
931 /*if any other feature wants is local we need to set it local*/
932 LIST_FOR_EACH_ENTRY( f, &package->features, MSIFEATURE, entry )
934 if ( component->ActionRequest != INSTALLSTATE_LOCAL )
935 break;
937 LIST_FOR_EACH_ENTRY( clist, &f->Components, ComponentList, entry )
939 if ( clist->component == component )
941 if (f->ActionRequest == INSTALLSTATE_LOCAL)
943 TRACE("Saved by %s\n", debugstr_w(f->Feature));
944 component->ActionRequest = INSTALLSTATE_LOCAL;
945 component->Action = INSTALLSTATE_LOCAL;
947 break;
952 TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
953 newstate, debugstr_w(component->Component), component->Installed,
954 component->Action, component->ActionRequest);
958 UINT register_unique_action(MSIPACKAGE *package, LPCWSTR action)
960 UINT count;
961 LPWSTR *newbuf = NULL;
963 if (!package->script)
964 return FALSE;
966 TRACE("Registering Action %s as having fun\n",debugstr_w(action));
968 count = package->script->UniqueActionsCount;
969 package->script->UniqueActionsCount++;
970 if (count != 0)
971 newbuf = msi_realloc( package->script->UniqueActions,
972 package->script->UniqueActionsCount* sizeof(LPWSTR));
973 else
974 newbuf = msi_alloc( sizeof(LPWSTR));
976 newbuf[count] = strdupW(action);
977 package->script->UniqueActions = newbuf;
979 return ERROR_SUCCESS;
982 BOOL check_unique_action(MSIPACKAGE *package, LPCWSTR action)
984 INT i;
986 if (!package->script)
987 return FALSE;
989 for (i = 0; i < package->script->UniqueActionsCount; i++)
990 if (!strcmpW(package->script->UniqueActions[i],action))
991 return TRUE;
993 return FALSE;
996 WCHAR* generate_error_string(MSIPACKAGE *package, UINT error, DWORD count, ... )
998 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};
1000 MSIRECORD *rec;
1001 MSIRECORD *row;
1002 DWORD size = 0;
1003 DWORD i;
1004 va_list va;
1005 LPCWSTR str;
1006 LPWSTR data;
1008 row = MSI_QueryGetRecord(package->db, query, error);
1009 if (!row)
1010 return 0;
1012 rec = MSI_CreateRecord(count+2);
1014 str = MSI_RecordGetString(row,1);
1015 MSI_RecordSetStringW(rec,0,str);
1016 msiobj_release( &row->hdr );
1017 MSI_RecordSetInteger(rec,1,error);
1019 va_start(va,count);
1020 for (i = 0; i < count; i++)
1022 str = va_arg(va,LPCWSTR);
1023 MSI_RecordSetStringW(rec,(i+2),str);
1025 va_end(va);
1027 MSI_FormatRecordW(package,rec,NULL,&size);
1028 if (size >= 0)
1030 size++;
1031 data = msi_alloc(size*sizeof(WCHAR));
1032 if (size > 1)
1033 MSI_FormatRecordW(package,rec,data,&size);
1034 else
1035 data[0] = 0;
1036 msiobj_release( &rec->hdr );
1037 return data;
1040 msiobj_release( &rec->hdr );
1041 data = NULL;
1042 return data;