msi: Use binary search to find the insert index for a row.
[wine] / dlls / msi / helpers.c
1 /*
2  * Implementation of the Microsoft Installer (msi.dll)
3  *
4  * Copyright 2005 Aric Stewart for CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
20
21 /*
22  * Here are helper functions formally in action.c that are used by a variety of
23  * actions and functions.
24  */
25
26 #include <stdarg.h>
27
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"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(msi);
36
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};
39
40 LPWSTR build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name )
41 {
42     LPWSTR SystemFolder, dest, FilePath;
43
44     static const WCHAR szMicrosoft[] =
45         {'M','i','c','r','o','s','o','f','t','\\',0};
46     static const WCHAR szInstaller[] = 
47         {'I','n','s','t','a','l','l','e','r','\\',0};
48     static const WCHAR szADFolder[] =
49         {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
50     static const WCHAR szWFolder[] =
51         {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
52
53     if(package->Context == MSIINSTALLCONTEXT_MACHINE)
54         SystemFolder = msi_dup_property( package->db, szWFolder );
55     else
56     {
57         LPWSTR ADTgt = msi_dup_property( package->db, szADFolder );
58         SystemFolder = build_directory_name(2, ADTgt, szMicrosoft);
59         msi_free(ADTgt);
60     }
61
62     dest = build_directory_name(3, SystemFolder, szInstaller, package->ProductCode);
63
64     create_full_pathW(dest);
65
66     FilePath = build_directory_name(2, dest, icon_name);
67
68     msi_free(SystemFolder);
69     msi_free(dest);
70     return FilePath;
71 }
72
73 LPWSTR msi_dup_record_field( MSIRECORD *rec, INT field )
74 {
75     DWORD sz = 0;
76     LPWSTR str;
77     UINT r;
78
79     if (MSI_RecordIsNull( rec, field ))
80         return NULL;
81
82     r = MSI_RecordGetStringW( rec, field, NULL, &sz );
83     if (r != ERROR_SUCCESS)
84         return NULL;
85
86     sz ++;
87     str = msi_alloc( sz * sizeof (WCHAR) );
88     if (!str)
89         return str;
90     str[0] = 0;
91     r = MSI_RecordGetStringW( rec, field, str, &sz );
92     if (r != ERROR_SUCCESS)
93     {
94         ERR("failed to get string!\n");
95         msi_free( str );
96         return NULL;
97     }
98     return str;
99 }
100
101 MSICOMPONENT* get_loaded_component( MSIPACKAGE* package, LPCWSTR Component )
102 {
103     MSICOMPONENT *comp;
104
105     LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
106     {
107         if (lstrcmpW(Component,comp->Component)==0)
108             return comp;
109     }
110     return NULL;
111 }
112
113 MSIFEATURE* get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
114 {
115     MSIFEATURE *feature;
116
117     LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
118     {
119         if (lstrcmpW( Feature, feature->Feature )==0)
120             return feature;
121     }
122     return NULL;
123 }
124
125 MSIFILE* get_loaded_file( MSIPACKAGE* package, LPCWSTR key )
126 {
127     MSIFILE *file;
128
129     LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
130     {
131         if (lstrcmpW( key, file->File )==0)
132             return file;
133     }
134     return NULL;
135 }
136
137 int track_tempfile( MSIPACKAGE *package, LPCWSTR path )
138 {
139     MSITEMPFILE *temp;
140
141     TRACE("%s\n", debugstr_w(path));
142
143     LIST_FOR_EACH_ENTRY( temp, &package->tempfiles, MSITEMPFILE, entry )
144         if (!lstrcmpW( path, temp->Path ))
145             return 0;
146
147     temp = msi_alloc_zero( sizeof (MSITEMPFILE) );
148     if (!temp)
149         return -1;
150
151     list_add_head( &package->tempfiles, &temp->entry );
152     temp->Path = strdupW( path );
153
154     return 0;
155 }
156
157 MSIFOLDER *get_loaded_folder( MSIPACKAGE *package, LPCWSTR dir )
158 {
159     MSIFOLDER *folder;
160
161     LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
162     {
163         if (lstrcmpW( dir, folder->Directory )==0)
164             return folder;
165     }
166     return NULL;
167 }
168
169 static LPWSTR get_source_root( MSIPACKAGE *package )
170 {
171     LPWSTR path, p;
172
173     path = msi_dup_property( package->db, cszSourceDir );
174     if (path)
175         return path;
176
177     path = msi_dup_property( package->db, cszDatabase );
178     if (path)
179     {
180         p = strrchrW(path,'\\');
181         if (p)
182             *(p+1) = 0;
183     }
184     return path;
185 }
186
187 /*
188  * clean_spaces_from_path()
189  *
190  * removes spaces from the beginning and end of path segments
191  * removes multiple \\ characters
192  */
193 static void clean_spaces_from_path( LPWSTR p )
194 {
195     LPWSTR q = p;
196     int n, len = 0;
197
198     while (1)
199     {
200         /* copy until the end of the string or a space */
201         while (*p != ' ' && (*q = *p))
202         {
203             p++, len++;
204             /* reduce many backslashes to one */
205             if (*p != '\\' || *q != '\\')
206                 q++;
207         }
208
209         /* quit at the end of the string */
210         if (!*p)
211             break;
212
213         /* count the number of spaces */
214         n = 0;
215         while (p[n] == ' ')
216             n++;
217
218         /* if it's leading or trailing space, skip it */
219         if ( len == 0 || p[-1] == '\\' || p[n] == '\\' )
220             p += n;
221         else  /* copy n spaces */
222             while (n && (*q++ = *p++)) n--;
223     }
224 }
225
226 LPWSTR resolve_file_source(MSIPACKAGE *package, MSIFILE *file)
227 {
228     LPWSTR p, path;
229
230     TRACE("Working to resolve source of file %s\n", debugstr_w(file->File));
231
232     if (file->IsCompressed)
233         return NULL;
234
235     p = resolve_folder(package, file->Component->Directory,
236                        TRUE, FALSE, TRUE, NULL);
237     path = build_directory_name(2, p, file->ShortName);
238
239     if (file->LongName &&
240         GetFileAttributesW(path) == INVALID_FILE_ATTRIBUTES)
241     {
242         msi_free(path);
243         path = build_directory_name(2, p, file->LongName);
244     }
245
246     msi_free(p);
247
248     TRACE("file %s source resolves to %s\n", debugstr_w(file->File),
249           debugstr_w(path));
250
251     return path;
252 }
253
254 LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source, 
255                       BOOL set_prop, BOOL load_prop, MSIFOLDER **folder)
256 {
257     MSIFOLDER *f;
258     LPWSTR p, path = NULL, parent;
259
260     TRACE("Working to resolve %s\n",debugstr_w(name));
261
262     if (!name)
263         return NULL;
264
265     if (!lstrcmpW(name,cszSourceDir))
266         name = cszTargetDir;
267
268     f = get_loaded_folder( package, name );
269     if (!f)
270         return NULL;
271
272     /* special resolving for Target and Source root dir */
273     if (!strcmpW(name,cszTargetDir))
274     {
275         if (!f->ResolvedTarget && !f->Property)
276         {
277             LPWSTR check_path;
278             check_path = msi_dup_property( package->db, cszTargetDir );
279             if (!check_path)
280             {
281                 check_path = msi_dup_property( package->db, cszRootDrive );
282                 if (set_prop)
283                     msi_set_property( package->db, cszTargetDir, check_path );
284             }
285
286             /* correct misbuilt target dir */
287             path = build_directory_name(2, check_path, NULL);
288             clean_spaces_from_path( path );
289             if (strcmpiW(path,check_path)!=0)
290                 msi_set_property( package->db, cszTargetDir, path );
291             msi_free(check_path);
292
293             f->ResolvedTarget = path;
294         }
295
296         if (!f->ResolvedSource)
297             f->ResolvedSource = get_source_root( package );
298     }
299
300     if (folder)
301         *folder = f;
302
303     if (!source && f->ResolvedTarget)
304     {
305         path = strdupW( f->ResolvedTarget );
306         TRACE("   already resolved to %s\n",debugstr_w(path));
307         return path;
308     }
309
310     if (source && f->ResolvedSource)
311     {
312         path = strdupW( f->ResolvedSource );
313         TRACE("   (source)already resolved to %s\n",debugstr_w(path));
314         return path;
315     }
316
317     if (!source && f->Property)
318     {
319         path = build_directory_name( 2, f->Property, NULL );
320
321         TRACE("   internally set to %s\n",debugstr_w(path));
322         if (set_prop)
323             msi_set_property( package->db, name, path );
324         return path;
325     }
326
327     if (!source && load_prop && (path = msi_dup_property( package->db, name )))
328     {
329         f->ResolvedTarget = strdupW( path );
330         TRACE("   property set to %s\n", debugstr_w(path));
331         return path;
332     }
333
334     if (!f->Parent)
335         return path;
336
337     parent = f->Parent;
338
339     TRACE(" ! Parent is %s\n", debugstr_w(parent));
340
341     p = resolve_folder(package, parent, source, set_prop, load_prop, NULL);
342     if (!source)
343     {
344         TRACE("   TargetDefault = %s\n", debugstr_w(f->TargetDefault));
345
346         path = build_directory_name( 3, p, f->TargetDefault, NULL );
347         clean_spaces_from_path( path );
348         f->ResolvedTarget = strdupW( path );
349         TRACE("target -> %s\n", debugstr_w(path));
350         if (set_prop)
351             msi_set_property( package->db, name, path );
352     }
353     else
354     {
355         path = NULL;
356
357         if (package->WordCount & msidbSumInfoSourceTypeCompressed)
358             path = get_source_root( package );
359         else if (package->WordCount & msidbSumInfoSourceTypeSFN)
360             path = build_directory_name( 3, p, f->SourceShortPath, NULL );
361         else
362             path = build_directory_name( 3, p, f->SourceLongPath, NULL );
363
364         TRACE("source -> %s\n", debugstr_w(path));
365         f->ResolvedSource = strdupW( path );
366     }
367     msi_free(p);
368
369     return path;
370 }
371
372 /* wrapper to resist a need for a full rewrite right now */
373 DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data )
374 {
375     if (ptr)
376     {
377         MSIRECORD *rec = MSI_CreateRecord(1);
378         DWORD size = 0;
379
380         MSI_RecordSetStringW(rec,0,ptr);
381         MSI_FormatRecordW(package,rec,NULL,&size);
382
383         size++;
384         *data = msi_alloc(size*sizeof(WCHAR));
385         if (size > 1)
386             MSI_FormatRecordW(package,rec,*data,&size);
387         else
388             *data[0] = 0;
389
390         msiobj_release( &rec->hdr );
391         return sizeof(WCHAR)*size;
392     }
393
394     *data = NULL;
395     return 0;
396 }
397
398 UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action)
399 {
400     UINT count;
401     LPWSTR *newbuf = NULL;
402     if (script >= TOTAL_SCRIPTS)
403     {
404         FIXME("Unknown script requested %i\n",script);
405         return ERROR_FUNCTION_FAILED;
406     }
407     TRACE("Scheduling Action %s in script %i\n",debugstr_w(action), script);
408     
409     count = package->script->ActionCount[script];
410     package->script->ActionCount[script]++;
411     if (count != 0)
412         newbuf = msi_realloc( package->script->Actions[script],
413                         package->script->ActionCount[script]* sizeof(LPWSTR));
414     else
415         newbuf = msi_alloc( sizeof(LPWSTR));
416
417     newbuf[count] = strdupW(action);
418     package->script->Actions[script] = newbuf;
419
420    return ERROR_SUCCESS;
421 }
422
423 void msi_free_action_script(MSIPACKAGE *package, UINT script)
424 {
425     UINT i;
426     for (i = 0; i < package->script->ActionCount[script]; i++)
427         msi_free(package->script->Actions[script][i]);
428
429     msi_free(package->script->Actions[script]);
430     package->script->Actions[script] = NULL;
431     package->script->ActionCount[script] = 0;
432 }
433
434 /*
435  *  build_directory_name()
436  *
437  *  This function is to save messing round with directory names
438  *  It handles adding backslashes between path segments, 
439  *   and can add \ at the end of the directory name if told to.
440  *
441  *  It takes a variable number of arguments.
442  *  It always allocates a new string for the result, so make sure
443  *   to free the return value when finished with it.
444  *
445  *  The first arg is the number of path segments that follow.
446  *  The arguments following count are a list of path segments.
447  *  A path segment may be NULL.
448  *
449  *  Path segments will be added with a \ separating them.
450  *  A \ will not be added after the last segment, however if the
451  *    last segment is NULL, then the last character will be a \
452  * 
453  */
454 LPWSTR build_directory_name(DWORD count, ...)
455 {
456     DWORD sz = 1, i;
457     LPWSTR dir;
458     va_list va;
459
460     va_start(va,count);
461     for(i=0; i<count; i++)
462     {
463         LPCWSTR str = va_arg(va,LPCWSTR);
464         if (str)
465             sz += strlenW(str) + 1;
466     }
467     va_end(va);
468
469     dir = msi_alloc(sz*sizeof(WCHAR));
470     dir[0]=0;
471
472     va_start(va,count);
473     for(i=0; i<count; i++)
474     {
475         LPCWSTR str = va_arg(va,LPCWSTR);
476         if (!str)
477             continue;
478         strcatW(dir, str);
479         if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
480             strcatW(dir, szBackSlash);
481     }
482     return dir;
483 }
484
485 /***********************************************************************
486  *            create_full_pathW
487  *
488  * Recursively create all directories in the path.
489  *
490  * shamelessly stolen from setupapi/queue.c
491  */
492 BOOL create_full_pathW(const WCHAR *path)
493 {
494     BOOL ret = TRUE;
495     int len;
496     WCHAR *new_path;
497
498     new_path = msi_alloc( (strlenW(path) + 1) * sizeof(WCHAR));
499
500     strcpyW(new_path, path);
501
502     while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
503     new_path[len - 1] = 0;
504
505     while(!CreateDirectoryW(new_path, NULL))
506     {
507         WCHAR *slash;
508         DWORD last_error = GetLastError();
509         if(last_error == ERROR_ALREADY_EXISTS)
510             break;
511
512         if(last_error != ERROR_PATH_NOT_FOUND)
513         {
514             ret = FALSE;
515             break;
516         }
517
518         if(!(slash = strrchrW(new_path, '\\')))
519         {
520             ret = FALSE;
521             break;
522         }
523
524         len = slash - new_path;
525         new_path[len] = 0;
526         if(!create_full_pathW(new_path))
527         {
528             ret = FALSE;
529             break;
530         }
531         new_path[len] = '\\';
532     }
533
534     msi_free(new_path);
535     return ret;
536 }
537
538 void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
539 {
540     MSIRECORD * row;
541
542     row = MSI_CreateRecord(4);
543     MSI_RecordSetInteger(row,1,a);
544     MSI_RecordSetInteger(row,2,b);
545     MSI_RecordSetInteger(row,3,c);
546     MSI_RecordSetInteger(row,4,d);
547     MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
548     msiobj_release(&row->hdr);
549
550     msi_dialog_check_messages(NULL);
551 }
552
553 void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
554 {
555     static const WCHAR Query_t[] = 
556         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
557          '`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
558          'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=', 
559          ' ','\'','%','s','\'',0};
560     WCHAR message[1024];
561     MSIRECORD * row = 0;
562     DWORD size;
563
564     if (!package->LastAction || strcmpW(package->LastAction,action))
565     {
566         row = MSI_QueryGetRecord(package->db, Query_t, action);
567         if (!row)
568             return;
569
570         if (MSI_RecordIsNull(row,3))
571         {
572             msiobj_release(&row->hdr);
573             return;
574         }
575
576         /* update the cached actionformat */
577         msi_free(package->ActionFormat);
578         package->ActionFormat = msi_dup_record_field(row,3);
579
580         msi_free(package->LastAction);
581         package->LastAction = strdupW(action);
582
583         msiobj_release(&row->hdr);
584     }
585
586     MSI_RecordSetStringW(record,0,package->ActionFormat);
587     size = 1024;
588     MSI_FormatRecordW(package,record,message,&size);
589
590     row = MSI_CreateRecord(1);
591     MSI_RecordSetStringW(row,1,message);
592  
593     MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
594
595     msiobj_release(&row->hdr);
596 }
597
598 void reduce_to_longfilename(WCHAR* filename)
599 {
600     LPWSTR p = strchrW(filename,'|');
601     if (p)
602         memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
603 }
604
605 LPWSTR create_component_advertise_string(MSIPACKAGE* package, 
606                 MSICOMPONENT* component, LPCWSTR feature)
607 {
608     static const WCHAR fmt[] = {'%','s','%','s','%','c','%','s',0};
609     WCHAR productid_85[21], component_85[21];
610     LPWSTR output = NULL;
611     DWORD sz = 0;
612     GUID clsid;
613
614     /* > is used if there is a component GUID and < if not.  */
615
616     productid_85[0] = 0;
617     component_85[0] = 0;
618
619     CLSIDFromString(package->ProductCode, &clsid);
620     encode_base85_guid(&clsid, productid_85);
621
622     if (component)
623     {
624         CLSIDFromString(component->ComponentId, &clsid);
625         encode_base85_guid(&clsid, component_85);
626     }
627
628     TRACE("prod=%s feat=%s comp=%s\n", debugstr_w(productid_85),
629           debugstr_w(feature), debugstr_w(component_85));
630  
631     sz = 20 + lstrlenW(feature) + 20 + 3;
632
633     output = msi_alloc_zero(sz*sizeof(WCHAR));
634
635     sprintfW(output, fmt, productid_85, feature,
636              component?'>':'<', component_85);
637     
638     return output;
639 }
640
641 /* update component state based on a feature change */
642 void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
643 {
644     INSTALLSTATE newstate;
645     MSIFEATURE *feature;
646     ComponentList *cl;
647
648     feature = get_loaded_feature(package,szFeature);
649     if (!feature)
650         return;
651
652     newstate = feature->ActionRequest;
653
654     if (newstate == INSTALLSTATE_ABSENT)
655         newstate = INSTALLSTATE_UNKNOWN;
656
657     LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
658     {
659         MSICOMPONENT* component = cl->component;
660     
661         TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
662             newstate, debugstr_w(component->Component), component->Installed, 
663             component->Action, component->ActionRequest);
664         
665         if (!component->Enabled)
666             continue;
667  
668         if (newstate == INSTALLSTATE_LOCAL)
669             msi_component_set_state(package, component, INSTALLSTATE_LOCAL);
670         else 
671         {
672             ComponentList *clist;
673             MSIFEATURE *f;
674
675             component->hasLocalFeature = FALSE;
676
677             msi_component_set_state(package, component, newstate);
678
679             /*if any other feature wants is local we need to set it local*/
680             LIST_FOR_EACH_ENTRY( f, &package->features, MSIFEATURE, entry )
681             {
682                 if ( f->ActionRequest != INSTALLSTATE_LOCAL &&
683                      f->ActionRequest != INSTALLSTATE_SOURCE )
684                 {
685                     continue;
686                 }
687
688                 LIST_FOR_EACH_ENTRY( clist, &f->Components, ComponentList, entry )
689                 {
690                     if ( clist->component == component &&
691                          (f->ActionRequest == INSTALLSTATE_LOCAL ||
692                           f->ActionRequest == INSTALLSTATE_SOURCE) )
693                     {
694                         TRACE("Saved by %s\n", debugstr_w(f->Feature));
695                         component->hasLocalFeature = TRUE;
696
697                         if (component->Attributes & msidbComponentAttributesOptional)
698                         {
699                             if (f->Attributes & msidbFeatureAttributesFavorSource)
700                                 msi_component_set_state(package, component, INSTALLSTATE_SOURCE);
701                             else
702                                 msi_component_set_state(package, component, INSTALLSTATE_LOCAL);
703                         }
704                         else if (component->Attributes & msidbComponentAttributesSourceOnly)
705                             msi_component_set_state(package, component, INSTALLSTATE_SOURCE);
706                         else
707                             msi_component_set_state(package, component, INSTALLSTATE_LOCAL);
708                     }
709                 }
710             }
711         }
712         TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
713             newstate, debugstr_w(component->Component), component->Installed, 
714             component->Action, component->ActionRequest);
715     } 
716 }
717
718 UINT register_unique_action(MSIPACKAGE *package, LPCWSTR action)
719 {
720     UINT count;
721     LPWSTR *newbuf = NULL;
722
723     if (!package->script)
724         return FALSE;
725
726     TRACE("Registering %s as unique action\n", debugstr_w(action));
727     
728     count = package->script->UniqueActionsCount;
729     package->script->UniqueActionsCount++;
730     if (count != 0)
731         newbuf = msi_realloc( package->script->UniqueActions,
732                         package->script->UniqueActionsCount* sizeof(LPWSTR));
733     else
734         newbuf = msi_alloc( sizeof(LPWSTR));
735
736     newbuf[count] = strdupW(action);
737     package->script->UniqueActions = newbuf;
738
739     return ERROR_SUCCESS;
740 }
741
742 BOOL check_unique_action(const MSIPACKAGE *package, LPCWSTR action)
743 {
744     UINT i;
745
746     if (!package->script)
747         return FALSE;
748
749     for (i = 0; i < package->script->UniqueActionsCount; i++)
750         if (!strcmpW(package->script->UniqueActions[i],action))
751             return TRUE;
752
753     return FALSE;
754 }
755
756 WCHAR* generate_error_string(MSIPACKAGE *package, UINT error, DWORD count, ... )
757 {
758     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};
759
760     MSIRECORD *rec;
761     MSIRECORD *row;
762     DWORD size = 0;
763     DWORD i;
764     va_list va;
765     LPCWSTR str;
766     LPWSTR data;
767
768     row = MSI_QueryGetRecord(package->db, query, error);
769     if (!row)
770         return 0;
771
772     rec = MSI_CreateRecord(count+2);
773
774     str = MSI_RecordGetString(row,1);
775     MSI_RecordSetStringW(rec,0,str);
776     msiobj_release( &row->hdr );
777     MSI_RecordSetInteger(rec,1,error);
778
779     va_start(va,count);
780     for (i = 0; i < count; i++)
781     {
782         str = va_arg(va,LPCWSTR);
783         MSI_RecordSetStringW(rec,(i+2),str);
784     }
785     va_end(va);
786
787     MSI_FormatRecordW(package,rec,NULL,&size);
788
789     size++;
790     data = msi_alloc(size*sizeof(WCHAR));
791     if (size > 1)
792         MSI_FormatRecordW(package,rec,data,&size);
793     else
794         data[0] = 0;
795     msiobj_release( &rec->hdr );
796     return data;
797 }