2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 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
24 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installexecutesequence_table.asp
26 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/standard_actions_reference.asp
38 #include "wine/debug.h"
42 #include "msvcrt/fcntl.h"
49 #include "wine/unicode.h"
52 #define CUSTOM_ACTION_TYPE_MASK 0x3F
53 #define REG_PROGRESS_VALUE 13200
54 #define COMPONENT_PROGRESS_VALUE 24000
56 WINE_DEFAULT_DEBUG_CHANNEL(msi);
58 typedef struct tagMSIFEATURE
61 WCHAR Feature_Parent[96];
63 WCHAR Description[0x100];
69 INSTALLSTATE Installed;
70 INSTALLSTATE ActionRequest;
74 INT Components[1024]; /* yes hardcoded limit.... I am bad */
78 typedef struct tagMSICOMPONENT
81 WCHAR ComponentId[96];
84 WCHAR Condition[0x100];
87 INSTALLSTATE Installed;
88 INSTALLSTATE ActionRequest;
95 typedef struct tagMSIFOLDER
101 LPWSTR ResolvedTarget;
102 LPWSTR ResolvedSource;
103 LPWSTR Property; /* initially set property */
106 /* 0 = uninitialized */
108 /* 2 = created remove if empty */
109 /* 3 = created persist if empty */
114 typedef struct tagMSIFILE
126 /* 0 = uninitialize */
127 /* 1 = not present */
128 /* 2 = present but replace */
129 /* 3 = present do not replace */
139 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran);
140 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package);
142 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq);
143 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action);
145 static UINT ACTION_LaunchConditions(MSIPACKAGE *package);
146 static UINT ACTION_CostInitialize(MSIPACKAGE *package);
147 static UINT ACTION_CreateFolders(MSIPACKAGE *package);
148 static UINT ACTION_CostFinalize(MSIPACKAGE *package);
149 static UINT ACTION_FileCost(MSIPACKAGE *package);
150 static UINT ACTION_InstallFiles(MSIPACKAGE *package);
151 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package);
152 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package);
153 static UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action);
154 static UINT ACTION_InstallInitialize(MSIPACKAGE *package);
155 static UINT ACTION_InstallValidate(MSIPACKAGE *package);
156 static UINT ACTION_ProcessComponents(MSIPACKAGE *package);
157 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package);
158 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package);
159 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package);
160 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package);
161 static UINT ACTION_PublishProduct(MSIPACKAGE *package);
163 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
164 const LPWSTR target, const INT type);
165 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
166 const LPWSTR target, const INT type);
167 static UINT HANDLE_CustomType18(MSIPACKAGE *package, const LPWSTR source,
168 const LPWSTR target, const INT type);
169 static UINT HANDLE_CustomType50(MSIPACKAGE *package, const LPWSTR source,
170 const LPWSTR target, const INT type);
171 static UINT HANDLE_CustomType34(MSIPACKAGE *package, const LPWSTR source,
172 const LPWSTR target, const INT type);
174 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data);
175 static LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name,
176 BOOL source, BOOL set_prop, MSIFOLDER **folder);
178 static int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path);
181 * consts and values used
183 static const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
184 static const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
185 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
186 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
187 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
188 static const WCHAR c_collen[] = {'C',':','\\',0};
190 static const WCHAR cszlsb[]={'[',0};
191 static const WCHAR cszrsb[]={']',0};
192 static const WCHAR cszbs[]={'\\',0};
194 const static WCHAR szCreateFolders[] =
195 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
196 const static WCHAR szCostFinalize[] =
197 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
198 const static WCHAR szInstallFiles[] =
199 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
200 const static WCHAR szDuplicateFiles[] =
201 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
202 const static WCHAR szWriteRegistryValues[] =
203 {'W','r','i','t','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
204 const static WCHAR szCostInitialize[] =
205 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
206 const static WCHAR szFileCost[] = {'F','i','l','e','C','o','s','t',0};
207 const static WCHAR szInstallInitialize[] =
208 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
209 const static WCHAR szInstallValidate[] =
210 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
211 const static WCHAR szLaunchConditions[] =
212 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
213 const static WCHAR szProcessComponents[] =
214 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
215 const static WCHAR szRegisterTypeLibraries[] =
216 {'R','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r',
218 const static WCHAR szRegisterClassInfo[] =
219 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
220 const static WCHAR szRegisterProgIdInfo[] =
221 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
222 const static WCHAR szCreateShortcuts[] =
223 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
224 const static WCHAR szPublishProduct[] =
225 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
227 /********************************************************
228 * helper functions to get around current HACKS and such
229 ********************************************************/
230 inline static void reduce_to_longfilename(WCHAR* filename)
232 LPWSTR p = strchrW(filename,'|');
234 memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
237 inline static char *strdupWtoA( const WCHAR *str )
242 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL
244 if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
245 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
250 inline static WCHAR *strdupAtoW( const char *str )
255 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
256 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
257 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
262 static LPWSTR dupstrW(LPCWSTR src)
265 if (!src) return NULL;
266 dest = HeapAlloc(GetProcessHeap(), 0, (strlenW(src)+1)*sizeof(WCHAR));
271 inline static WCHAR *load_dynamic_stringW(MSIRECORD *row, INT index)
278 if (MSI_RecordIsNull(row,index))
281 rc = MSI_RecordGetStringW(row,index,NULL,&sz);
283 /* having an empty string is different than NULL */
286 ret = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR));
292 ret = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
293 rc = MSI_RecordGetStringW(row,index,ret,&sz);
294 if (rc!=ERROR_SUCCESS)
296 ERR("Unable to load dynamic string\n");
297 HeapFree(GetProcessHeap(), 0, ret);
303 inline static LPWSTR load_dynamic_property(MSIPACKAGE *package, LPCWSTR prop,
310 r = MSI_GetPropertyW(package, prop, NULL, &sz);
311 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
318 str = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
319 r = MSI_GetPropertyW(package, prop, str, &sz);
320 if (r != ERROR_SUCCESS)
322 HeapFree(GetProcessHeap(),0,str);
330 inline static int get_loaded_component(MSIPACKAGE* package, LPCWSTR Component )
335 for (i = 0; i < package->loaded_components; i++)
337 if (strcmpW(Component,package->components[i].Component)==0)
346 inline static int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
351 for (i = 0; i < package->loaded_features; i++)
353 if (strcmpW(Feature,package->features[i].Feature)==0)
362 inline static int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
367 for (i = 0; i < package->loaded_files; i++)
369 if (strcmpW(file,package->files[i].File)==0)
379 static int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
387 for (i=0; i < package->loaded_files; i++)
388 if (strcmpW(package->files[i].File,name)==0)
391 index = package->loaded_files;
392 package->loaded_files++;
393 if (package->loaded_files== 1)
394 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
396 package->files = HeapReAlloc(GetProcessHeap(),0,
397 package->files , package->loaded_files * sizeof(MSIFILE));
399 memset(&package->files[index],0,sizeof(MSIFILE));
401 package->files[index].File = dupstrW(name);
402 package->files[index].TargetPath = dupstrW(path);
403 package->files[index].Temporary = TRUE;
405 TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
410 void ACTION_remove_tracked_tempfiles(MSIPACKAGE* package)
417 for (i = 0; i < package->loaded_files; i++)
419 if (package->files[i].Temporary)
421 TRACE("Cleaning up %s\n",debugstr_w(package->files[i].TargetPath));
422 DeleteFileW(package->files[i].TargetPath);
428 /* Called when the package is being closed */
429 extern void ACTION_free_package_structures( MSIPACKAGE* package)
433 TRACE("Freeing package action data\n");
435 /* No dynamic buffers in features */
436 if (package->features && package->loaded_features > 0)
437 HeapFree(GetProcessHeap(),0,package->features);
439 for (i = 0; i < package->loaded_folders; i++)
441 HeapFree(GetProcessHeap(),0,package->folders[i].Directory);
442 HeapFree(GetProcessHeap(),0,package->folders[i].TargetDefault);
443 HeapFree(GetProcessHeap(),0,package->folders[i].SourceDefault);
444 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
445 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedSource);
446 HeapFree(GetProcessHeap(),0,package->folders[i].Property);
448 if (package->folders && package->loaded_folders > 0)
449 HeapFree(GetProcessHeap(),0,package->folders);
451 /* no dynamic buffers in components */
452 if (package->components && package->loaded_components > 0)
453 HeapFree(GetProcessHeap(),0,package->components);
455 for (i = 0; i < package->loaded_files; i++)
457 HeapFree(GetProcessHeap(),0,package->files[i].File);
458 HeapFree(GetProcessHeap(),0,package->files[i].FileName);
459 HeapFree(GetProcessHeap(),0,package->files[i].Version);
460 HeapFree(GetProcessHeap(),0,package->files[i].Language);
461 HeapFree(GetProcessHeap(),0,package->files[i].SourcePath);
462 HeapFree(GetProcessHeap(),0,package->files[i].TargetPath);
465 if (package->files && package->loaded_files > 0)
466 HeapFree(GetProcessHeap(),0,package->files);
469 static UINT ACTION_OpenQuery( MSIDATABASE *db, MSIQUERY **view, LPCWSTR fmt, ... )
476 /* figure out how much space we need to allocate */
478 sz = strlenW(fmt) + 1;
488 case 's': /* a string */
489 sz += strlenW(va_arg(va,LPCWSTR));
492 case 'i': /* an integer -2147483648 seems to be longest */
494 (void)va_arg(va,int);
496 case '%': /* a single % - leave it alone */
499 FIXME("Unhandled character type %c\n",*p);
505 /* construct the string */
506 szQuery = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
508 vsnprintfW(szQuery, sz, fmt, va);
511 /* perform the query */
512 rc = MSI_DatabaseOpenViewW(db, szQuery, view);
513 HeapFree(GetProcessHeap(), 0, szQuery);
517 static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
521 row = MSI_CreateRecord(4);
522 MSI_RecordSetInteger(row,1,a);
523 MSI_RecordSetInteger(row,2,b);
524 MSI_RecordSetInteger(row,3,c);
525 MSI_RecordSetInteger(row,4,d);
526 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
527 msiobj_release(&row->hdr);
530 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
532 static const WCHAR Query_t[] =
533 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
534 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
535 ' ','\'','%','s','\'',0};
542 if (!package->LastAction || strcmpW(package->LastAction,action))
544 rc = ACTION_OpenQuery(package->db, &view, Query_t, action);
545 if (rc != ERROR_SUCCESS)
548 rc = MSI_ViewExecute(view, 0);
549 if (rc != ERROR_SUCCESS)
554 rc = MSI_ViewFetch(view,&row);
555 if (rc != ERROR_SUCCESS)
561 if (MSI_RecordIsNull(row,3))
563 msiobj_release(&row->hdr);
565 msiobj_release(&view->hdr);
569 /* update the cached actionformat */
570 if (package->ActionFormat)
571 HeapFree(GetProcessHeap(),0,package->ActionFormat);
572 package->ActionFormat = load_dynamic_stringW(row,3);
574 if (package->LastAction)
575 HeapFree(GetProcessHeap(),0,package->LastAction);
576 package->LastAction = dupstrW(action);
578 msiobj_release(&row->hdr);
580 msiobj_release(&view->hdr);
584 ptr = package->ActionFormat;
592 ptr2 = strchrW(ptr,'[');
595 strncpyW(tmp,ptr,ptr2-ptr);
597 strcatW(message,tmp);
600 data = load_dynamic_stringW(record,field);
603 strcatW(message,data);
604 HeapFree(GetProcessHeap(),0,data);
606 ptr=strchrW(ptr2,']');
611 strcatW(message,ptr);
616 row = MSI_CreateRecord(1);
617 MSI_RecordSetStringW(row,1,message);
619 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
620 msiobj_release(&row->hdr);
624 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
626 static const WCHAR template_s[]=
627 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ','%','s','.',0};
628 static const WCHAR format[] =
629 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
630 static const WCHAR Query_t[] =
631 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
632 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
633 ' ','\'','%','s','\'',0};
639 WCHAR *ActionText=NULL;
641 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
643 rc = ACTION_OpenQuery(package->db, &view, Query_t, action);
644 if (rc != ERROR_SUCCESS)
646 rc = MSI_ViewExecute(view, 0);
647 if (rc != ERROR_SUCCESS)
650 msiobj_release(&view->hdr);
653 rc = MSI_ViewFetch(view,&row);
654 if (rc != ERROR_SUCCESS)
657 msiobj_release(&view->hdr);
661 ActionText = load_dynamic_stringW(row,2);
662 msiobj_release(&row->hdr);
664 msiobj_release(&view->hdr);
666 sprintfW(message,template_s,timet,action,ActionText);
668 row = MSI_CreateRecord(1);
669 MSI_RecordSetStringW(row,1,message);
671 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
672 msiobj_release(&row->hdr);
673 HeapFree(GetProcessHeap(),0,ActionText);
676 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
680 static const WCHAR template_s[]=
681 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ','%','s',
683 static const WCHAR template_e[]=
684 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ','%','s',
685 '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ','%','i','.',0};
686 static const WCHAR format[] =
687 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
691 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
693 sprintfW(message,template_s,timet,action);
695 sprintfW(message,template_e,timet,action,rc);
697 row = MSI_CreateRecord(1);
698 MSI_RecordSetStringW(row,1,message);
700 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
701 msiobj_release(&row->hdr);
705 * build_directory_name()
707 * This function is to save messing round with directory names
708 * It handles adding backslashes between path segments,
709 * and can add \ at the end of the directory name if told to.
711 * It takes a variable number of arguments.
712 * It always allocates a new string for the result, so make sure
713 * to free the return value when finished with it.
715 * The first arg is the number of path segments that follow.
716 * The arguments following count are a list of path segments.
717 * A path segment may be NULL.
719 * Path segments will be added with a \ seperating them.
720 * A \ will not be added after the last segment, however if the
721 * last segment is NULL, then the last character will be a \
724 static LPWSTR build_directory_name(DWORD count, ...)
731 for(i=0; i<count; i++)
733 LPCWSTR str = va_arg(va,LPCWSTR);
735 sz += strlenW(str) + 1;
739 dir = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
743 for(i=0; i<count; i++)
745 LPCWSTR str = va_arg(va,LPCWSTR);
749 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
756 /****************************************************
757 * TOP level entry points
758 *****************************************************/
760 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
761 LPCWSTR szCommandLine)
766 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
770 LPWSTR p, check, path;
772 path = dupstrW(szPackagePath);
773 p = strrchrW(path,'\\');
780 check = load_dynamic_property(package, cszSourceDir,NULL);
782 MSI_SetPropertyW(package, cszSourceDir, path);
784 HeapFree(GetProcessHeap(), 0, check);
786 HeapFree(GetProcessHeap(), 0, path);
792 ptr = (LPWSTR)szCommandLine;
799 TRACE("Looking at %s\n",debugstr_w(ptr));
801 ptr2 = strchrW(ptr,'=');
807 while (*ptr == ' ') ptr++;
809 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
810 strncpyW(prop,ptr,len);
816 while (*ptr && (quote || (!quote && *ptr!=' ')))
829 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
830 strncpyW(val,ptr2,len);
833 if (strlenW(prop) > 0)
835 TRACE("Found commandline property (%s) = (%s)\n",
836 debugstr_w(prop), debugstr_w(val));
837 MSI_SetPropertyW(package,prop,val);
839 HeapFree(GetProcessHeap(),0,val);
840 HeapFree(GetProcessHeap(),0,prop);
847 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
849 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
851 rc = ACTION_ProcessUISequence(package);
852 if (rc == ERROR_SUCCESS)
853 rc = ACTION_ProcessExecSequence(package,TRUE);
856 rc = ACTION_ProcessExecSequence(package,FALSE);
859 rc = ACTION_ProcessExecSequence(package,FALSE);
861 /* process the ending type action */
862 if (rc == ERROR_SUCCESS)
863 rc = ACTION_PerformActionSequence(package,-1);
864 else if (rc == ERROR_FUNCTION_FAILED)
865 rc = ACTION_PerformActionSequence(package,-3);
870 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq)
877 static const WCHAR ExecSeqQuery[] = {
878 's','e','l','e','c','t',' ','*',' ',
880 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
881 'S','e','q','u','e','n','c','e',' ',
882 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
885 rc = ACTION_OpenQuery(package->db, &view, ExecSeqQuery, seq);
887 if (rc == ERROR_SUCCESS)
889 rc = MSI_ViewExecute(view, 0);
891 if (rc != ERROR_SUCCESS)
894 msiobj_release(&view->hdr);
898 TRACE("Running the actions\n");
900 rc = MSI_ViewFetch(view,&row);
901 if (rc != ERROR_SUCCESS)
907 /* check conditions */
908 if (!MSI_RecordIsNull(row,2))
911 cond = load_dynamic_stringW(row,2);
915 /* this is a hack to skip errors in the condition code */
916 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
918 HeapFree(GetProcessHeap(),0,cond);
919 msiobj_release(&row->hdr);
923 HeapFree(GetProcessHeap(),0,cond);
928 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
929 if (rc != ERROR_SUCCESS)
931 ERR("Error is %x\n",rc);
932 msiobj_release(&row->hdr);
936 rc = ACTION_PerformAction(package,buffer);
937 msiobj_release(&row->hdr);
940 msiobj_release(&view->hdr);
948 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
952 static const WCHAR ExecSeqQuery[] = {
953 's','e','l','e','c','t',' ','*',' ',
955 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
956 'S','e','q','u','e','n','c','e',' ',
957 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
958 '>',' ','%','i',' ','o','r','d','e','r',' ',
959 'b','y',' ','S','e','q','u','e','n','c','e',0 };
961 static const WCHAR IVQuery[] = {
962 's','e','l','e','c','t',' ','S','e','q','u','e','n','c','e',' ',
963 'f','r','o','m',' ','I','n','s','t','a','l','l',
964 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
965 'w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',' ',
966 '`','I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`',
970 /* get the sequence number */
973 rc = MSI_DatabaseOpenViewW(package->db, IVQuery, &view);
974 if (rc != ERROR_SUCCESS)
976 rc = MSI_ViewExecute(view, 0);
977 if (rc != ERROR_SUCCESS)
980 msiobj_release(&view->hdr);
983 rc = MSI_ViewFetch(view,&row);
984 if (rc != ERROR_SUCCESS)
987 msiobj_release(&view->hdr);
990 seq = MSI_RecordGetInteger(row,1);
991 msiobj_release(&row->hdr);
993 msiobj_release(&view->hdr);
996 rc = ACTION_OpenQuery(package->db, &view, ExecSeqQuery, seq);
997 if (rc == ERROR_SUCCESS)
999 rc = MSI_ViewExecute(view, 0);
1001 if (rc != ERROR_SUCCESS)
1003 MSI_ViewClose(view);
1004 msiobj_release(&view->hdr);
1008 TRACE("Running the actions\n");
1012 WCHAR buffer[0x100];
1015 rc = MSI_ViewFetch(view,&row);
1016 if (rc != ERROR_SUCCESS)
1022 /* check conditions */
1023 if (!MSI_RecordIsNull(row,2))
1026 cond = load_dynamic_stringW(row,2);
1030 /* this is a hack to skip errors in the condition code */
1031 if (MSI_EvaluateConditionW(package, cond) ==
1034 HeapFree(GetProcessHeap(),0,cond);
1035 msiobj_release(&row->hdr);
1039 HeapFree(GetProcessHeap(),0,cond);
1044 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1045 if (rc != ERROR_SUCCESS)
1047 ERR("Error is %x\n",rc);
1048 msiobj_release(&row->hdr);
1052 rc = ACTION_PerformAction(package,buffer);
1054 if (rc == ERROR_FUNCTION_NOT_CALLED)
1057 if (rc != ERROR_SUCCESS)
1059 ERR("Execution halted due to error (%i)\n",rc);
1060 msiobj_release(&row->hdr);
1064 msiobj_release(&row->hdr);
1067 MSI_ViewClose(view);
1068 msiobj_release(&view->hdr);
1076 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
1080 static const WCHAR ExecSeqQuery [] = {
1081 's','e','l','e','c','t',' ','*',' ',
1082 'f','r','o','m',' ','I','n','s','t','a','l','l',
1083 'U','I','S','e','q','u','e','n','c','e',' ',
1084 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ', '>',' ','0',' ',
1085 'o','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e',0};
1087 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1089 if (rc == ERROR_SUCCESS)
1091 rc = MSI_ViewExecute(view, 0);
1093 if (rc != ERROR_SUCCESS)
1095 MSI_ViewClose(view);
1096 msiobj_release(&view->hdr);
1100 TRACE("Running the actions \n");
1104 WCHAR buffer[0x100];
1106 MSIRECORD * row = 0;
1108 rc = MSI_ViewFetch(view,&row);
1109 if (rc != ERROR_SUCCESS)
1115 /* check conditions */
1116 if (!MSI_RecordIsNull(row,2))
1119 cond = load_dynamic_stringW(row,2);
1123 /* this is a hack to skip errors in the condition code */
1124 if (MSI_EvaluateConditionW(package, cond) ==
1127 HeapFree(GetProcessHeap(),0,cond);
1128 msiobj_release(&row->hdr);
1132 HeapFree(GetProcessHeap(),0,cond);
1137 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1138 if (rc != ERROR_SUCCESS)
1140 ERR("Error is %x\n",rc);
1141 msiobj_release(&row->hdr);
1145 rc = ACTION_PerformAction(package,buffer);
1147 if (rc == ERROR_FUNCTION_NOT_CALLED)
1150 if (rc != ERROR_SUCCESS)
1152 ERR("Execution halted due to error (%i)\n",rc);
1153 msiobj_release(&row->hdr);
1157 msiobj_release(&row->hdr);
1160 MSI_ViewClose(view);
1161 msiobj_release(&view->hdr);
1168 /********************************************************
1169 * ACTION helper functions and functions that perform the actions
1170 *******************************************************/
1173 * Alot of actions are really important even if they don't do anything
1174 * explicit.. Lots of properties are set at the beginning of the installation
1175 * CostFinalize does a bunch of work to translated the directories and such
1177 * But until I get write access to the database that is hard, so I am going to
1178 * hack it to see if I can get something to run.
1180 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action)
1182 UINT rc = ERROR_SUCCESS;
1184 TRACE("Performing action (%s)\n",debugstr_w(action));
1185 ui_actioninfo(package, action, TRUE, 0);
1186 ui_actionstart(package, action);
1188 /* pre install, setup and configuration block */
1189 if (strcmpW(action,szLaunchConditions)==0)
1190 rc = ACTION_LaunchConditions(package);
1191 else if (strcmpW(action,szCostInitialize)==0)
1192 rc = ACTION_CostInitialize(package);
1193 else if (strcmpW(action,szFileCost)==0)
1194 rc = ACTION_FileCost(package);
1195 else if (strcmpW(action,szCostFinalize)==0)
1196 rc = ACTION_CostFinalize(package);
1197 else if (strcmpW(action,szInstallValidate)==0)
1198 rc = ACTION_InstallValidate(package);
1201 else if (strcmpW(action,szProcessComponents)==0)
1202 rc = ACTION_ProcessComponents(package);
1203 else if (strcmpW(action,szInstallInitialize)==0)
1204 rc = ACTION_InstallInitialize(package);
1205 else if (strcmpW(action,szCreateFolders)==0)
1206 rc = ACTION_CreateFolders(package);
1207 else if (strcmpW(action,szInstallFiles)==0)
1208 rc = ACTION_InstallFiles(package);
1209 else if (strcmpW(action,szDuplicateFiles)==0)
1210 rc = ACTION_DuplicateFiles(package);
1211 else if (strcmpW(action,szWriteRegistryValues)==0)
1212 rc = ACTION_WriteRegistryValues(package);
1213 else if (strcmpW(action,szRegisterTypeLibraries)==0)
1214 rc = ACTION_RegisterTypeLibraries(package);
1215 else if (strcmpW(action,szRegisterClassInfo)==0)
1216 rc = ACTION_RegisterClassInfo(package);
1217 else if (strcmpW(action,szRegisterProgIdInfo)==0)
1218 rc = ACTION_RegisterProgIdInfo(package);
1219 else if (strcmpW(action,szCreateShortcuts)==0)
1220 rc = ACTION_CreateShortcuts(package);
1221 else if (strcmpW(action,szPublishProduct)==0)
1222 rc = ACTION_PublishProduct(package);
1225 Called during iTunes but unimplemented and seem important
1227 ResolveSource (sets SourceDir)
1231 else if ((rc = ACTION_CustomAction(package,action)) != ERROR_SUCCESS)
1233 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1234 rc = ERROR_FUNCTION_NOT_CALLED;
1237 ui_actioninfo(package, action, FALSE, rc);
1242 static UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action)
1244 UINT rc = ERROR_SUCCESS;
1246 MSIRECORD * row = 0;
1247 static const WCHAR ExecSeqQuery[] =
1248 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','C','u','s','t','o'
1249 ,'m','A','c','t','i','o','n',' ','w','h','e','r','e',' ','`','A','c','t','i'
1250 ,'o','n','`',' ','=',' ','`','%','s','`',0};
1254 WCHAR *deformated=NULL;
1256 rc = ACTION_OpenQuery(package->db, &view, ExecSeqQuery, action);
1257 if (rc != ERROR_SUCCESS)
1260 rc = MSI_ViewExecute(view, 0);
1261 if (rc != ERROR_SUCCESS)
1263 MSI_ViewClose(view);
1264 msiobj_release(&view->hdr);
1268 rc = MSI_ViewFetch(view,&row);
1269 if (rc != ERROR_SUCCESS)
1271 MSI_ViewClose(view);
1272 msiobj_release(&view->hdr);
1276 type = MSI_RecordGetInteger(row,2);
1278 source = load_dynamic_stringW(row,3);
1279 target = load_dynamic_stringW(row,4);
1281 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
1282 debugstr_w(source), debugstr_w(target));
1284 /* we are ignoring ALOT of flags and important synchronization stuff */
1285 switch (type & CUSTOM_ACTION_TYPE_MASK)
1287 case 1: /* DLL file stored in a Binary table stream */
1288 rc = HANDLE_CustomType1(package,source,target,type);
1290 case 2: /* EXE file stored in a Binary table strem */
1291 rc = HANDLE_CustomType2(package,source,target,type);
1293 case 18: /*EXE file installed with package */
1294 rc = HANDLE_CustomType18(package,source,target,type);
1296 case 50: /*EXE file specified by a property value */
1297 rc = HANDLE_CustomType50(package,source,target,type);
1299 case 34: /*EXE to be run in specified directory */
1300 rc = HANDLE_CustomType34(package,source,target,type);
1302 case 35: /* Directory set with formatted text. */
1303 deformat_string(package,target,&deformated);
1304 MSI_SetTargetPathW(package, source, deformated);
1305 HeapFree(GetProcessHeap(),0,deformated);
1307 case 51: /* Property set with formatted text. */
1308 deformat_string(package,target,&deformated);
1309 rc = MSI_SetPropertyW(package,source,deformated);
1310 HeapFree(GetProcessHeap(),0,deformated);
1313 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
1314 type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
1315 debugstr_w(target));
1318 HeapFree(GetProcessHeap(),0,source);
1319 HeapFree(GetProcessHeap(),0,target);
1320 msiobj_release(&row->hdr);
1321 MSI_ViewClose(view);
1322 msiobj_release(&view->hdr);
1326 static UINT store_binary_to_temp(MSIPACKAGE *package, const LPWSTR source,
1331 if (MSI_GetPropertyW(package, cszTempFolder, tmp_file, &sz)
1333 GetTempPathW(MAX_PATH,tmp_file);
1335 strcatW(tmp_file,source);
1337 if (GetFileAttributesW(tmp_file) != INVALID_FILE_ATTRIBUTES)
1339 TRACE("File already exists\n");
1340 return ERROR_SUCCESS;
1344 /* write out the file */
1347 MSIRECORD * row = 0;
1348 static const WCHAR fmt[] =
1349 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','B','i'
1350 ,'n','a','r','y',' ','w','h','e','r','e',' ','N','a','m','e','=','`','%','s','`',0};
1354 if (track_tempfile(package, source, tmp_file)!=0)
1355 FIXME("File Name in temp tracking collision\n");
1357 the_file = CreateFileW(tmp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1358 FILE_ATTRIBUTE_NORMAL, NULL);
1360 if (the_file == INVALID_HANDLE_VALUE)
1361 return ERROR_FUNCTION_FAILED;
1363 rc = ACTION_OpenQuery(package->db, &view, fmt, source);
1364 if (rc != ERROR_SUCCESS)
1367 rc = MSI_ViewExecute(view, 0);
1368 if (rc != ERROR_SUCCESS)
1370 MSI_ViewClose(view);
1371 msiobj_release(&view->hdr);
1375 rc = MSI_ViewFetch(view,&row);
1376 if (rc != ERROR_SUCCESS)
1378 MSI_ViewClose(view);
1379 msiobj_release(&view->hdr);
1387 rc = MSI_RecordReadStream(row,2,buffer,&sz);
1388 if (rc != ERROR_SUCCESS)
1390 ERR("Failed to get stream\n");
1391 CloseHandle(the_file);
1392 DeleteFileW(tmp_file);
1395 WriteFile(the_file,buffer,sz,&write,NULL);
1396 } while (sz == 1024);
1398 CloseHandle(the_file);
1400 msiobj_release(&row->hdr);
1401 MSI_ViewClose(view);
1402 msiobj_release(&view->hdr);
1405 return ERROR_SUCCESS;
1408 typedef UINT __stdcall CustomEntry(MSIHANDLE);
1411 MSIPACKAGE *package;
1416 static DWORD WINAPI DllThread(LPVOID info)
1420 thread_struct *stuff;
1423 stuff = (thread_struct*)info;
1425 TRACE("Asynchronous start (%s, %s) \n", debugstr_w(stuff->source),
1426 debugstr_w(stuff->target));
1428 DLL = LoadLibraryW(stuff->source);
1431 proc = strdupWtoA( stuff->target );
1432 fn = (CustomEntry*)GetProcAddress(DLL,proc);
1436 MSIPACKAGE *package = stuff->package;
1438 TRACE("Calling function\n");
1439 hPackage = msiobj_findhandle( &package->hdr );
1441 ERR("Handle for object %p not found\n", package );
1443 msiobj_release( &package->hdr );
1446 ERR("Cannot load functon\n");
1448 HeapFree(GetProcessHeap(),0,proc);
1452 ERR("Unable to load library\n");
1453 msiobj_release( &stuff->package->hdr );
1454 HeapFree(GetProcessHeap(),0,stuff->source);
1455 HeapFree(GetProcessHeap(),0,stuff->target);
1456 HeapFree(GetProcessHeap(), 0, stuff);
1460 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
1461 const LPWSTR target, const INT type)
1463 WCHAR tmp_file[MAX_PATH];
1468 store_binary_to_temp(package, source, tmp_file);
1470 TRACE("Calling function %s from %s\n",debugstr_w(target),
1471 debugstr_w(tmp_file));
1473 if (!strchrW(tmp_file,'.'))
1475 static const WCHAR dot[]={'.',0};
1476 strcatW(tmp_file,dot);
1482 HANDLE ThreadHandle;
1483 thread_struct *info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) );
1485 msiobj_addref( &package->hdr );
1486 info->package = package;
1487 info->target = dupstrW(target);
1488 info->source = dupstrW(tmp_file);
1489 TRACE("Start Asynchronous execution of dll\n");
1490 ThreadHandle = CreateThread(NULL,0,DllThread,(LPVOID)info,0,&ThreadId);
1491 CloseHandle(ThreadHandle);
1492 /* FIXME: release the package if the CreateThread fails */
1493 return ERROR_SUCCESS;
1496 DLL = LoadLibraryW(tmp_file);
1499 proc = strdupWtoA( target );
1500 fn = (CustomEntry*)GetProcAddress(DLL,proc);
1505 TRACE("Calling function\n");
1506 hPackage = msiobj_findhandle( &package->hdr );
1508 ERR("Handle for object %p not found\n", package );
1510 msiobj_release( &package->hdr );
1513 ERR("Cannot load functon\n");
1515 HeapFree(GetProcessHeap(),0,proc);
1519 ERR("Unable to load library\n");
1521 return ERROR_SUCCESS;
1524 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
1525 const LPWSTR target, const INT type)
1527 WCHAR tmp_file[MAX_PATH];
1529 PROCESS_INFORMATION info;
1534 static const WCHAR spc[] = {' ',0};
1536 memset(&si,0,sizeof(STARTUPINFOW));
1538 store_binary_to_temp(package, source, tmp_file);
1540 deformat_string(package,target,&deformated);
1542 len = strlenW(tmp_file) + strlenW(deformated) + 2;
1544 cmd = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*len);
1546 strcpyW(cmd,tmp_file);
1548 strcatW(cmd,deformated);
1550 HeapFree(GetProcessHeap(),0,deformated);
1552 TRACE("executing exe %s \n",debugstr_w(cmd));
1554 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1555 c_collen, &si, &info);
1557 HeapFree(GetProcessHeap(),0,cmd);
1561 ERR("Unable to execute command\n");
1562 return ERROR_SUCCESS;
1566 WaitForSingleObject(info.hProcess,INFINITE);
1568 CloseHandle( info.hProcess );
1569 CloseHandle( info.hThread );
1570 return ERROR_SUCCESS;
1573 static UINT HANDLE_CustomType18(MSIPACKAGE *package, const LPWSTR source,
1574 const LPWSTR target, const INT type)
1577 PROCESS_INFORMATION info;
1582 static const WCHAR spc[] = {' ',0};
1585 memset(&si,0,sizeof(STARTUPINFOW));
1587 index = get_loaded_file(package,source);
1589 len = strlenW(package->files[index].TargetPath);
1591 deformat_string(package,target,&deformated);
1592 len += strlenW(deformated);
1595 cmd = (WCHAR*)HeapAlloc(GetProcessHeap(),0,len * sizeof(WCHAR));
1597 strcpyW(cmd, package->files[index].TargetPath);
1599 strcatW(cmd, deformated);
1601 HeapFree(GetProcessHeap(),0,deformated);
1603 TRACE("executing exe %s \n",debugstr_w(cmd));
1605 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1606 c_collen, &si, &info);
1608 HeapFree(GetProcessHeap(),0,cmd);
1612 ERR("Unable to execute command\n");
1613 return ERROR_SUCCESS;
1617 WaitForSingleObject(info.hProcess,INFINITE);
1619 CloseHandle( info.hProcess );
1620 CloseHandle( info.hThread );
1621 return ERROR_SUCCESS;
1624 static UINT HANDLE_CustomType50(MSIPACKAGE *package, const LPWSTR source,
1625 const LPWSTR target, const INT type)
1628 PROCESS_INFORMATION info;
1635 static const WCHAR spc[] = {' ',0};
1637 memset(&si,0,sizeof(STARTUPINFOW));
1638 memset(&info,0,sizeof(PROCESS_INFORMATION));
1640 prop = load_dynamic_property(package,source,&prc);
1644 deformat_string(package,target,&deformated);
1645 len = strlenW(prop) + strlenW(deformated) + 2;
1646 cmd = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*len);
1650 strcatW(cmd,deformated);
1652 HeapFree(GetProcessHeap(),0,deformated);
1654 TRACE("executing exe %s \n",debugstr_w(cmd));
1656 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1657 c_collen, &si, &info);
1659 HeapFree(GetProcessHeap(),0,cmd);
1663 ERR("Unable to execute command\n");
1664 return ERROR_SUCCESS;
1668 WaitForSingleObject(info.hProcess,INFINITE);
1670 CloseHandle( info.hProcess );
1671 CloseHandle( info.hThread );
1672 return ERROR_SUCCESS;
1675 static UINT HANDLE_CustomType34(MSIPACKAGE *package, const LPWSTR source,
1676 const LPWSTR target, const INT type)
1678 LPWSTR filename, deformated;
1680 PROCESS_INFORMATION info;
1683 memset(&si,0,sizeof(STARTUPINFOW));
1685 filename = resolve_folder(package, source, FALSE, FALSE, NULL);
1688 return ERROR_FUNCTION_FAILED;
1690 SetCurrentDirectoryW(filename);
1691 HeapFree(GetProcessHeap(),0,filename);
1693 deformat_string(package,target,&deformated);
1695 TRACE("executing exe %s \n",debugstr_w(deformated));
1697 rc = CreateProcessW(NULL, deformated, NULL, NULL, FALSE, 0, NULL,
1698 c_collen, &si, &info);
1699 HeapFree(GetProcessHeap(),0,deformated);
1703 ERR("Unable to execute command\n");
1704 return ERROR_SUCCESS;
1708 WaitForSingleObject(info.hProcess,INFINITE);
1710 CloseHandle( info.hProcess );
1711 CloseHandle( info.hThread );
1712 return ERROR_SUCCESS;
1715 /***********************************************************************
1718 * Recursively create all directories in the path.
1720 * shamelessly stolen from setupapi/queue.c
1722 static BOOL create_full_pathW(const WCHAR *path)
1728 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1731 strcpyW(new_path, path);
1733 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1734 new_path[len - 1] = 0;
1736 while(!CreateDirectoryW(new_path, NULL))
1739 DWORD last_error = GetLastError();
1740 if(last_error == ERROR_ALREADY_EXISTS)
1743 if(last_error != ERROR_PATH_NOT_FOUND)
1749 if(!(slash = strrchrW(new_path, '\\')))
1755 len = slash - new_path;
1757 if(!create_full_pathW(new_path))
1762 new_path[len] = '\\';
1765 HeapFree(GetProcessHeap(), 0, new_path);
1770 * Also we cannot enable/disable components either, so for now I am just going
1771 * to do all the directories for all the components.
1773 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1775 static const WCHAR ExecSeqQuery[] = {
1776 's','e','l','e','c','t',' ','D','i','r','e','c','t','o','r','y','_',' ',
1777 'f','r','o','m',' ','C','r','e','a','t','e','F','o','l','d','e','r',0 };
1782 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1783 if (rc != ERROR_SUCCESS)
1784 return ERROR_SUCCESS;
1786 rc = MSI_ViewExecute(view, 0);
1787 if (rc != ERROR_SUCCESS)
1789 MSI_ViewClose(view);
1790 msiobj_release(&view->hdr);
1799 MSIRECORD *row = NULL, *uirow;
1801 rc = MSI_ViewFetch(view,&row);
1802 if (rc != ERROR_SUCCESS)
1809 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1811 if (rc!= ERROR_SUCCESS)
1813 ERR("Unable to get folder id \n");
1814 msiobj_release(&row->hdr);
1819 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
1822 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1823 msiobj_release(&row->hdr);
1827 TRACE("Folder is %s\n",debugstr_w(full_path));
1830 uirow = MSI_CreateRecord(1);
1831 MSI_RecordSetStringW(uirow,1,full_path);
1832 ui_actiondata(package,szCreateFolders,uirow);
1833 msiobj_release( &uirow->hdr );
1835 if (folder->State == 0)
1836 create_full_pathW(full_path);
1840 msiobj_release(&row->hdr);
1841 HeapFree(GetProcessHeap(),0,full_path);
1843 MSI_ViewClose(view);
1844 msiobj_release(&view->hdr);
1849 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1851 int index = package->loaded_components;
1854 /* fill in the data */
1856 package->loaded_components++;
1857 if (package->loaded_components == 1)
1858 package->components = HeapAlloc(GetProcessHeap(),0,
1859 sizeof(MSICOMPONENT));
1861 package->components = HeapReAlloc(GetProcessHeap(),0,
1862 package->components, package->loaded_components *
1863 sizeof(MSICOMPONENT));
1865 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1868 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1870 TRACE("Loading Component %s\n",
1871 debugstr_w(package->components[index].Component));
1874 if (!MSI_RecordIsNull(row,2))
1875 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1878 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1880 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1883 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1886 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1888 package->components[index].Installed = INSTALLSTATE_ABSENT;
1889 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1890 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1892 package->components[index].Enabled = TRUE;
1897 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1899 int index = package->loaded_features;
1901 static const WCHAR Query1[] = {'S','E','L','E','C','T',' ','C','o','m','p',
1902 'o','n','e','n','t','_',' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1903 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ','F','e',
1904 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1905 static const WCHAR Query2[] = {'S','E','L','E','C','T',' ','*',' ','F','R',
1906 'O','M',' ','C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ','C',
1907 'o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1914 /* fill in the data */
1916 package->loaded_features ++;
1917 if (package->loaded_features == 1)
1918 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1920 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1921 package->loaded_features * sizeof(MSIFEATURE));
1923 memset(&package->features[index],0,sizeof(MSIFEATURE));
1926 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1928 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1931 if (!MSI_RecordIsNull(row,2))
1932 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1935 if (!MSI_RecordIsNull(row,3))
1936 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1939 if (!MSI_RecordIsNull(row,4))
1940 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1942 if (!MSI_RecordIsNull(row,5))
1943 package->features[index].Display = MSI_RecordGetInteger(row,5);
1945 package->features[index].Level= MSI_RecordGetInteger(row,6);
1948 if (!MSI_RecordIsNull(row,7))
1949 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1951 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1953 package->features[index].Installed = INSTALLSTATE_ABSENT;
1954 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1955 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1957 /* load feature components */
1959 rc = ACTION_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1960 if (rc != ERROR_SUCCESS)
1962 rc = MSI_ViewExecute(view,0);
1963 if (rc != ERROR_SUCCESS)
1965 MSI_ViewClose(view);
1966 msiobj_release(&view->hdr);
1972 WCHAR buffer[0x100];
1975 INT cnt = package->features[index].ComponentCount;
1977 rc = MSI_ViewFetch(view,&row2);
1978 if (rc != ERROR_SUCCESS)
1982 MSI_RecordGetStringW(row2,1,buffer,&sz);
1984 /* check to see if the component is already loaded */
1985 c_indx = get_loaded_component(package,buffer);
1988 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1990 package->features[index].Components[cnt] = c_indx;
1991 package->features[index].ComponentCount ++;
1995 rc = ACTION_OpenQuery(package->db, &view2, Query2, buffer);
1996 if (rc != ERROR_SUCCESS)
1998 msiobj_release( &row2->hdr );
2001 rc = MSI_ViewExecute(view2,0);
2002 if (rc != ERROR_SUCCESS)
2004 msiobj_release( &row2->hdr );
2005 MSI_ViewClose(view2);
2006 msiobj_release( &view2->hdr );
2013 rc = MSI_ViewFetch(view2,&row3);
2014 if (rc != ERROR_SUCCESS)
2016 c_indx = load_component(package,row3);
2017 msiobj_release( &row3->hdr );
2019 package->features[index].Components[cnt] = c_indx;
2020 package->features[index].ComponentCount ++;
2021 TRACE("Loaded new component to index %i\n",c_indx);
2023 MSI_ViewClose(view2);
2024 msiobj_release( &view2->hdr );
2025 msiobj_release( &row2->hdr );
2027 MSI_ViewClose(view);
2028 msiobj_release(&view->hdr);
2032 * I am not doing any of the costing functionality yet.
2033 * Mostly looking at doing the Component and Feature loading
2035 * The native MSI does ALOT of modification to tables here. Mostly adding alot
2036 * of temporary columns to the Feature and Component tables.
2038 * note: native msi also tracks the short filename. but I am only going to
2039 * track the long ones. Also looking at this directory table
2040 * it appears that the directory table does not get the parents
2041 * resolved base on property only based on their entrys in the
2044 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
2049 static const WCHAR Query_all[] = {
2050 'S','E','L','E','C','T',' ','*',' ',
2051 'F','R','O','M',' ','F','e','a','t','u','r','e',0};
2052 static const WCHAR szCosting[] = {
2053 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2054 static const WCHAR szZero[] = { '0', 0 };
2056 MSI_SetPropertyW(package, szCosting, szZero);
2057 MSI_SetPropertyW(package, cszRootDrive , c_collen);
2059 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
2060 if (rc != ERROR_SUCCESS)
2062 rc = MSI_ViewExecute(view,0);
2063 if (rc != ERROR_SUCCESS)
2065 MSI_ViewClose(view);
2066 msiobj_release(&view->hdr);
2073 rc = MSI_ViewFetch(view,&row);
2074 if (rc != ERROR_SUCCESS)
2077 load_feature(package,row);
2078 msiobj_release(&row->hdr);
2080 MSI_ViewClose(view);
2081 msiobj_release(&view->hdr);
2083 return ERROR_SUCCESS;
2086 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
2088 DWORD index = package->loaded_files;
2092 /* fill in the data */
2094 package->loaded_files++;
2095 if (package->loaded_files== 1)
2096 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
2098 package->files = HeapReAlloc(GetProcessHeap(),0,
2099 package->files , package->loaded_files * sizeof(MSIFILE));
2101 memset(&package->files[index],0,sizeof(MSIFILE));
2103 package->files[index].File = load_dynamic_stringW(row, 1);
2104 buffer = load_dynamic_stringW(row, 2);
2106 package->files[index].ComponentIndex = -1;
2107 for (i = 0; i < package->loaded_components; i++)
2108 if (strcmpW(package->components[i].Component,buffer)==0)
2110 package->files[index].ComponentIndex = i;
2113 if (package->files[index].ComponentIndex == -1)
2114 ERR("Unfound Component %s\n",debugstr_w(buffer));
2115 HeapFree(GetProcessHeap(), 0, buffer);
2117 package->files[index].FileName = load_dynamic_stringW(row,3);
2119 reduce_to_longfilename(package->files[index].FileName);
2121 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
2122 package->files[index].Version = load_dynamic_stringW(row, 5);
2123 package->files[index].Language = load_dynamic_stringW(row, 6);
2124 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
2125 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
2127 package->files[index].Temporary = FALSE;
2128 package->files[index].State = 0;
2130 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
2132 return ERROR_SUCCESS;
2135 static UINT ACTION_FileCost(MSIPACKAGE *package)
2140 static const WCHAR Query[] = {
2141 'S','E','L','E','C','T',' ','*',' ',
2142 'F','R','O','M',' ','F','i','l','e',' ',
2143 'O','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e', 0};
2146 return ERROR_INVALID_HANDLE;
2148 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2149 if (rc != ERROR_SUCCESS)
2150 return ERROR_SUCCESS;
2152 rc = MSI_ViewExecute(view, 0);
2153 if (rc != ERROR_SUCCESS)
2155 MSI_ViewClose(view);
2156 msiobj_release(&view->hdr);
2157 return ERROR_SUCCESS;
2162 rc = MSI_ViewFetch(view,&row);
2163 if (rc != ERROR_SUCCESS)
2168 load_file(package,row);
2169 msiobj_release(&row->hdr);
2171 MSI_ViewClose(view);
2172 msiobj_release(&view->hdr);
2174 return ERROR_SUCCESS;
2177 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
2180 static const WCHAR Query[] =
2181 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','D','i','r','e','c',
2182 't','o','r','y',' ','w','h','e','r','e',' ','`','D','i','r','e','c','t',
2183 'o','r','y','`',' ','=',' ','`','%','s','`',0};
2186 LPWSTR targetdir, parent, srcdir;
2187 MSIRECORD * row = 0;
2191 TRACE("Looking for dir %s\n",debugstr_w(dir));
2193 for (i = 0; i < package->loaded_folders; i++)
2195 if (strcmpW(package->folders[i].Directory,dir)==0)
2197 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
2202 TRACE("Working to load %s\n",debugstr_w(dir));
2204 index = package->loaded_folders++;
2205 if (package->loaded_folders==1)
2206 package->folders = HeapAlloc(GetProcessHeap(),0,
2209 package->folders= HeapReAlloc(GetProcessHeap(),0,
2210 package->folders, package->loaded_folders*
2213 memset(&package->folders[index],0,sizeof(MSIFOLDER));
2215 package->folders[index].Directory = dupstrW(dir);
2217 rc = ACTION_OpenQuery(package->db, &view, Query, dir);
2218 if (rc != ERROR_SUCCESS)
2221 rc = MSI_ViewExecute(view, 0);
2222 if (rc != ERROR_SUCCESS)
2224 MSI_ViewClose(view);
2225 msiobj_release(&view->hdr);
2229 rc = MSI_ViewFetch(view,&row);
2230 if (rc != ERROR_SUCCESS)
2232 MSI_ViewClose(view);
2233 msiobj_release(&view->hdr);
2237 targetdir = load_dynamic_stringW(row,3);
2239 /* split src and target dir */
2240 if (strchrW(targetdir,':'))
2242 srcdir=strchrW(targetdir,':');
2249 /* for now only pick long filename versions */
2250 if (strchrW(targetdir,'|'))
2252 targetdir = strchrW(targetdir,'|');
2256 if (srcdir && strchrW(srcdir,'|'))
2258 srcdir= strchrW(srcdir,'|');
2263 /* now check for root dirs */
2264 if (targetdir[0] == '.' && targetdir[1] == 0)
2267 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
2272 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
2273 if (package->folders[index].TargetDefault)
2274 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
2275 package->folders[index].TargetDefault = dupstrW(targetdir);
2279 package->folders[index].SourceDefault = dupstrW(srcdir);
2281 package->folders[index].SourceDefault = dupstrW(targetdir);
2282 HeapFree(GetProcessHeap(), 0, targetdir);
2284 parent = load_dynamic_stringW(row,2);
2287 i = load_folder(package,parent);
2288 package->folders[index].ParentIndex = i;
2289 TRACE("Parent is index %i... %s %s\n",
2290 package->folders[index].ParentIndex,
2291 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
2292 debugstr_w(parent));
2295 package->folders[index].ParentIndex = -2;
2296 HeapFree(GetProcessHeap(), 0, parent);
2298 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
2300 msiobj_release(&row->hdr);
2301 MSI_ViewClose(view);
2302 msiobj_release(&view->hdr);
2303 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
2308 static LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name,
2309 BOOL source, BOOL set_prop, MSIFOLDER **folder)
2312 LPWSTR p, path = NULL;
2314 TRACE("Working to resolve %s\n",debugstr_w(name));
2316 /* special resolving for Target and Source root dir */
2317 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
2321 path = load_dynamic_property(package,cszTargetDir,NULL);
2324 path = load_dynamic_property(package,cszRootDrive,NULL);
2326 MSI_SetPropertyW(package,cszTargetDir,path);
2330 for (i = 0; i < package->loaded_folders; i++)
2332 if (strcmpW(package->folders[i].Directory,name)==0)
2335 *folder = &(package->folders[i]);
2341 path = load_dynamic_property(package,cszSourceDir,NULL);
2344 path = load_dynamic_property(package,cszDatabase,NULL);
2347 p = strrchrW(path,'\\');
2354 for (i = 0; i < package->loaded_folders; i++)
2356 if (strcmpW(package->folders[i].Directory,name)==0)
2359 *folder = &(package->folders[i]);
2365 for (i = 0; i < package->loaded_folders; i++)
2367 if (strcmpW(package->folders[i].Directory,name)==0)
2371 if (i >= package->loaded_folders)
2375 *folder = &(package->folders[i]);
2377 if (!source && package->folders[i].ResolvedTarget)
2379 path = dupstrW(package->folders[i].ResolvedTarget);
2380 TRACE(" already resolved to %s\n",debugstr_w(path));
2383 else if (source && package->folders[i].ResolvedSource)
2385 path = dupstrW(package->folders[i].ResolvedSource);
2388 else if (!source && package->folders[i].Property)
2390 path = dupstrW(package->folders[i].Property);
2391 TRACE(" internally set to %s\n",debugstr_w(path));
2393 MSI_SetPropertyW(package,name,path);
2397 if (package->folders[i].ParentIndex >= 0)
2399 LPWSTR parent = package->folders[package->folders[i].ParentIndex].Directory;
2401 TRACE(" ! Parent is %s\n", debugstr_w(parent));
2403 p = resolve_folder(package, parent, source, set_prop, NULL);
2406 TRACE(" TargetDefault = %s\n",debugstr_w(package->folders[i].TargetDefault));
2407 path = build_directory_name(3, p, package->folders[i].TargetDefault, NULL);
2408 package->folders[i].ResolvedTarget = dupstrW(path);
2409 TRACE(" resolved into %s\n",debugstr_w(path));
2411 MSI_SetPropertyW(package,name,path);
2415 path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
2416 package->folders[i].ResolvedSource = dupstrW(path);
2418 HeapFree(GetProcessHeap(),0,p);
2423 static UINT SetFeatureStates(MSIPACKAGE *package)
2429 LPWSTR override = NULL;
2430 static const WCHAR all[]={'A','L','L',0};
2431 static const WCHAR szlevel[] = {
2432 'I','N','S','T','A','L','L','L','E','V','E','L',0};
2433 static const WCHAR szAddLocal[] = {
2434 'A','D','D','L','O','C','A','L',0};
2436 /* I do not know if this is where it should happen.. but */
2438 TRACE("Checking Install Level\n");
2440 level = load_dynamic_property(package,szlevel,NULL);
2443 install_level = atoiW(level);
2444 HeapFree(GetProcessHeap(), 0, level);
2449 /* ok hereis the rub
2450 * ADDLOCAL and its friend OVERRIDE INSTALLLEVLE
2451 * I have confirmed this if ADDLOCALis stated then the INSTALLLEVEL is
2452 * itnored for all the features. seems strange, epsecially since it is not
2453 * documented anywhere, but it is how it works.
2456 override = load_dynamic_property(package,szAddLocal,NULL);
2460 for(i = 0; i < package->loaded_features; i++)
2462 if (strcmpiW(override,all)==0)
2464 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2465 package->features[i].Action = INSTALLSTATE_LOCAL;
2469 LPWSTR ptr = override;
2470 LPWSTR ptr2 = strchrW(override,',');
2475 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
2477 strcmpW(ptr,package->features[i].Feature)==0))
2479 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2480 package->features[i].Action = INSTALLSTATE_LOCAL;
2486 ptr2 = strchrW(ptr,',');
2493 HeapFree(GetProcessHeap(),0,override);
2497 for(i = 0; i < package->loaded_features; i++)
2499 BOOL feature_state= ((package->features[i].Level > 0) &&
2500 (package->features[i].Level <= install_level));
2504 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2505 package->features[i].Action = INSTALLSTATE_LOCAL;
2511 * now we want to enable or disable components base on feature
2514 for(i = 0; i < package->loaded_features; i++)
2516 MSIFEATURE* feature = &package->features[i];
2517 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2518 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2519 feature->ActionRequest);
2521 for( j = 0; j < feature->ComponentCount; j++)
2523 MSICOMPONENT* component = &package->components[
2524 feature->Components[j]];
2526 if (!component->Enabled)
2528 component->Action = INSTALLSTATE_ABSENT;
2529 component->ActionRequest = INSTALLSTATE_ABSENT;
2533 if (feature->Action == INSTALLSTATE_LOCAL)
2534 component->Action = INSTALLSTATE_LOCAL;
2535 if (feature->ActionRequest == INSTALLSTATE_LOCAL)
2536 component->ActionRequest = INSTALLSTATE_LOCAL;
2541 for(i = 0; i < package->loaded_components; i++)
2543 MSICOMPONENT* component= &package->components[i];
2545 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2546 debugstr_w(component->Component), component->Installed,
2547 component->Action, component->ActionRequest);
2551 return ERROR_SUCCESS;
2555 * Alot is done in this function aside from just the costing.
2556 * The costing needs to be implemented at some point but for now I am going
2557 * to focus on the directory building
2560 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2562 static const WCHAR ExecSeqQuery[] = {
2563 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2564 'D','i','r','e','c','t','o','r','y',0};
2565 static const WCHAR ConditionQuery[] = {
2566 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2567 'C','o','n','d','i','t','i','o','n',0};
2568 static const WCHAR szCosting[] = {
2569 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2570 static const WCHAR szlevel[] = {
2571 'I','N','S','T','A','L','L','L','E','V','E','L',0};
2572 static const WCHAR szOne[] = { '1', 0 };
2578 TRACE("Building Directory properties\n");
2580 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2581 if (rc == ERROR_SUCCESS)
2583 rc = MSI_ViewExecute(view, 0);
2584 if (rc != ERROR_SUCCESS)
2586 MSI_ViewClose(view);
2587 msiobj_release(&view->hdr);
2595 MSIRECORD * row = 0;
2598 rc = MSI_ViewFetch(view,&row);
2599 if (rc != ERROR_SUCCESS)
2606 MSI_RecordGetStringW(row,1,name,&sz);
2608 /* This helper function now does ALL the work */
2609 TRACE("Dir %s ...\n",debugstr_w(name));
2610 load_folder(package,name);
2611 path = resolve_folder(package,name,FALSE,TRUE,NULL);
2612 TRACE("resolves to %s\n",debugstr_w(path));
2613 HeapFree( GetProcessHeap(), 0, path);
2615 msiobj_release(&row->hdr);
2617 MSI_ViewClose(view);
2618 msiobj_release(&view->hdr);
2621 TRACE("File calculations %i files\n",package->loaded_files);
2623 for (i = 0; i < package->loaded_files; i++)
2625 MSICOMPONENT* comp = NULL;
2626 MSIFILE* file= NULL;
2628 file = &package->files[i];
2629 if (file->ComponentIndex >= 0)
2630 comp = &package->components[file->ComponentIndex];
2632 if (file->Temporary == TRUE)
2639 /* calculate target */
2640 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
2642 if (file->TargetPath)
2643 HeapFree(GetProcessHeap(),0,file->TargetPath);
2645 TRACE("file %s is named %s\n",
2646 debugstr_w(file->File),debugstr_w(file->FileName));
2648 file->TargetPath = build_directory_name(2, p, file->FileName);
2650 HeapFree(GetProcessHeap(),0,p);
2652 TRACE("file %s resolves to %s\n",
2653 debugstr_w(file->File),debugstr_w(file->TargetPath));
2655 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2658 comp->Cost += file->FileSize;
2668 static const WCHAR name[] =
2670 static const WCHAR name_fmt[] =
2671 {'%','u','.','%','u','.','%','u','.','%','u',0};
2672 WCHAR filever[0x100];
2673 VS_FIXEDFILEINFO *lpVer;
2675 FIXME("Version comparison.. \n");
2676 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2677 version = HeapAlloc(GetProcessHeap(),0,versize);
2678 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2680 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2682 sprintfW(filever,name_fmt,
2683 HIWORD(lpVer->dwFileVersionMS),
2684 LOWORD(lpVer->dwFileVersionMS),
2685 HIWORD(lpVer->dwFileVersionLS),
2686 LOWORD(lpVer->dwFileVersionLS));
2688 TRACE("new %s old %s\n", debugstr_w(file->Version),
2689 debugstr_w(filever));
2690 if (strcmpiW(filever,file->Version)<0)
2693 FIXME("cost should be diff in size\n");
2694 comp->Cost += file->FileSize;
2698 HeapFree(GetProcessHeap(),0,version);
2706 TRACE("Evaluating Condition Table\n");
2708 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2709 if (rc == ERROR_SUCCESS)
2711 rc = MSI_ViewExecute(view, 0);
2712 if (rc != ERROR_SUCCESS)
2714 MSI_ViewClose(view);
2715 msiobj_release(&view->hdr);
2721 WCHAR Feature[0x100];
2722 MSIRECORD * row = 0;
2726 rc = MSI_ViewFetch(view,&row);
2728 if (rc != ERROR_SUCCESS)
2735 MSI_RecordGetStringW(row,1,Feature,&sz);
2737 feature_index = get_loaded_feature(package,Feature);
2738 if (feature_index < 0)
2739 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2743 Condition = load_dynamic_stringW(row,3);
2745 if (MSI_EvaluateConditionW(package,Condition) ==
2748 int level = MSI_RecordGetInteger(row,2);
2749 TRACE("Reseting feature %s to level %i\n",
2750 debugstr_w(Feature), level);
2751 package->features[feature_index].Level = level;
2753 HeapFree(GetProcessHeap(),0,Condition);
2756 msiobj_release(&row->hdr);
2758 MSI_ViewClose(view);
2759 msiobj_release(&view->hdr);
2762 TRACE("Enabling or Disabling Components\n");
2763 for (i = 0; i < package->loaded_components; i++)
2765 if (package->components[i].Condition[0])
2767 if (MSI_EvaluateConditionW(package,
2768 package->components[i].Condition) == MSICONDITION_FALSE)
2770 TRACE("Disabling component %s\n",
2771 debugstr_w(package->components[i].Component));
2772 package->components[i].Enabled = FALSE;
2777 MSI_SetPropertyW(package,szCosting,szOne);
2778 /* set default run level if not set */
2779 level = load_dynamic_property(package,szlevel,NULL);
2781 MSI_SetPropertyW(package,szlevel, szOne);
2783 HeapFree(GetProcessHeap(),0,level);
2785 return SetFeatureStates(package);
2790 * This is a helper function for handling embedded cabinet media
2792 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2800 WCHAR tmp[MAX_PATH];
2802 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2803 if (rc != ERROR_SUCCESS)
2807 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2808 GetTempPathW(MAX_PATH,tmp);
2810 GetTempFileNameW(tmp,stream_name,0,source);
2812 track_tempfile(package,strrchrW(source,'\\'), source);
2813 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2814 FILE_ATTRIBUTE_NORMAL, NULL);
2816 if (the_file == INVALID_HANDLE_VALUE)
2818 rc = ERROR_FUNCTION_FAILED;
2822 WriteFile(the_file,data,size,&write,NULL);
2823 CloseHandle(the_file);
2824 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2826 HeapFree(GetProcessHeap(),0,data);
2831 /* Support functions for FDI functions */
2834 MSIPACKAGE* package;
2839 static void * cabinet_alloc(ULONG cb)
2841 return HeapAlloc(GetProcessHeap(), 0, cb);
2844 static void cabinet_free(void *pv)
2846 HeapFree(GetProcessHeap(), 0, pv);
2849 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2852 DWORD dwShareMode = 0;
2853 DWORD dwCreateDisposition = OPEN_EXISTING;
2854 switch (oflag & _O_ACCMODE)
2857 dwAccess = GENERIC_READ;
2858 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2861 dwAccess = GENERIC_WRITE;
2862 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2865 dwAccess = GENERIC_READ | GENERIC_WRITE;
2866 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2869 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2870 dwCreateDisposition = CREATE_NEW;
2871 else if (oflag & _O_CREAT)
2872 dwCreateDisposition = CREATE_ALWAYS;
2873 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL, dwCreateDisposition, 0, NULL);
2876 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2879 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2884 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2887 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2892 static int cabinet_close(INT_PTR hf)
2894 return CloseHandle((HANDLE)hf) ? 0 : -1;
2897 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2899 /* flags are compatible and so are passed straight through */
2900 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2903 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2905 /* FIXME: try to do more processing in this function */
2908 case fdintCOPY_FILE:
2910 CabData *data = (CabData*) pfdin->pv;
2911 ULONG len = strlen(data->cab_path) + strlen(pfdin->psz1);
2916 LPWSTR tracknametmp;
2917 static const WCHAR tmpprefix[] = {'C','A','B','T','M','P','_',0};
2919 if (data->file_name && strcmp(data->file_name,pfdin->psz1))
2922 file = cabinet_alloc((len+1)*sizeof(char));
2923 strcpy(file, data->cab_path);
2924 strcat(file, pfdin->psz1);
2926 TRACE("file: %s\n", debugstr_a(file));
2928 /* track this file so it can be deleted if not installed */
2929 trackpath=strdupAtoW(file);
2930 tracknametmp=strdupAtoW(strrchr(file,'\\')+1);
2931 trackname = HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp) +
2932 strlenW(tmpprefix)+1) * sizeof(WCHAR));
2934 strcpyW(trackname,tmpprefix);
2935 strcatW(trackname,tracknametmp);
2937 track_tempfile(data->package, trackname, trackpath);
2939 HeapFree(GetProcessHeap(),0,trackpath);
2940 HeapFree(GetProcessHeap(),0,trackname);
2941 HeapFree(GetProcessHeap(),0,tracknametmp);
2943 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2945 case fdintCLOSE_FILE_INFO:
2949 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2951 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2953 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2956 cabinet_close(pfdin->hf);
2964 /***********************************************************************
2965 * extract_cabinet_file
2967 * Extract files from a cab file.
2969 static BOOL extract_a_cabinet_file(MSIPACKAGE* package, const WCHAR* source,
2970 const WCHAR* path, const WCHAR* file)
2980 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source),
2981 debugstr_w(file), debugstr_w(path));
2983 hfdi = FDICreate(cabinet_alloc,
2994 ERR("FDICreate failed\n");
2998 if (!(cabinet = strdupWtoA( source )))
3003 if (!(cab_path = strdupWtoA( path )))
3006 HeapFree(GetProcessHeap(), 0, cabinet);
3010 data.package = package;
3011 data.cab_path = cab_path;
3012 file_name = strdupWtoA(file);
3013 data.file_name = file_name;
3015 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, &data);
3018 ERR("FDICopy failed\n");
3022 HeapFree(GetProcessHeap(), 0, cabinet);
3023 HeapFree(GetProcessHeap(), 0, cab_path);
3024 HeapFree(GetProcessHeap(), 0, file_name);
3029 static UINT ready_media_for_file(MSIPACKAGE *package, UINT sequence,
3030 WCHAR* path, WCHAR* file)
3034 MSIRECORD * row = 0;
3035 static WCHAR source[MAX_PATH];
3036 static const WCHAR ExecSeqQuery[] = {
3037 's','e','l','e','c','t',' ','*',' ',
3038 'f','r','o','m',' ','M','e','d','i','a',' ',
3039 'w','h','e','r','e',' ','L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%','i',' ',
3040 'o','r','d','e','r',' ','b','y',' ','L','a','s','t','S','e','q','u','e','n','c','e',0};
3045 static UINT last_sequence = 0;
3047 if (sequence <= last_sequence)
3049 TRACE("Media already ready (%u, %u)\n",sequence,last_sequence);
3050 extract_a_cabinet_file(package, source,path,file);
3051 return ERROR_SUCCESS;
3054 sprintfW(Query,ExecSeqQuery,sequence);
3056 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3057 if (rc != ERROR_SUCCESS)
3060 rc = MSI_ViewExecute(view, 0);
3061 if (rc != ERROR_SUCCESS)
3063 MSI_ViewClose(view);
3064 msiobj_release(&view->hdr);
3068 rc = MSI_ViewFetch(view,&row);
3069 if (rc != ERROR_SUCCESS)
3071 MSI_ViewClose(view);
3072 msiobj_release(&view->hdr);
3075 seq = MSI_RecordGetInteger(row,2);
3076 last_sequence = seq;
3078 if (!MSI_RecordIsNull(row,4))
3081 MSI_RecordGetStringW(row,4,cab,&sz);
3082 TRACE("Source is CAB %s\n",debugstr_w(cab));
3083 /* the stream does not contain the # character */
3086 writeout_cabinet_stream(package,&cab[1],source);
3087 strcpyW(path,source);
3088 *(strrchrW(path,'\\')+1)=0;
3093 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
3095 ERR("No Source dir defined \n");
3096 rc = ERROR_FUNCTION_FAILED;
3100 strcpyW(path,source);
3101 strcatW(source,cab);
3102 /* extract the cab file into a folder in the temp folder */
3104 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
3106 GetTempPathW(MAX_PATH,path);
3109 rc = !extract_a_cabinet_file(package, source,path,file);
3111 msiobj_release(&row->hdr);
3112 MSI_ViewClose(view);
3113 msiobj_release(&view->hdr);
3117 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
3121 LPWSTR install_path;
3123 install_path = resolve_folder(package, package->components[component].Directory,
3124 FALSE, FALSE, &folder);
3126 return ERROR_FUNCTION_FAILED;
3128 /* create the path */
3129 if (folder->State == 0)
3131 create_full_pathW(install_path);
3134 HeapFree(GetProcessHeap(), 0, install_path);
3139 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
3141 UINT rc = ERROR_SUCCESS;
3144 WCHAR uipath[MAX_PATH];
3147 return ERROR_INVALID_HANDLE;
3149 /* increment progress bar each time action data is sent */
3150 ui_progress(package,1,1,0,0);
3152 for (index = 0; index < package->loaded_files; index++)
3154 WCHAR path_to_source[MAX_PATH];
3157 file = &package->files[index];
3159 if (file->Temporary)
3162 if (package->components[file->ComponentIndex].ActionRequest !=
3165 ui_progress(package,2,file->FileSize,0,0);
3166 TRACE("File %s is not scheduled for install\n",
3167 debugstr_w(file->File));
3172 if ((file->State == 1) || (file->State == 2))
3176 MSICOMPONENT* comp = NULL;
3178 TRACE("Installing %s\n",debugstr_w(file->File));
3179 rc = ready_media_for_file(package,file->Sequence,path_to_source,
3183 * our file table could change here because a new temp file
3184 * may have been created
3186 file = &package->files[index];
3187 if (rc != ERROR_SUCCESS)
3189 ERR("Unable to ready media\n");
3190 rc = ERROR_FUNCTION_FAILED;
3194 create_component_directory( package, file->ComponentIndex);
3196 /* recalculate file paths because things may have changed */
3198 if (file->ComponentIndex >= 0)
3199 comp = &package->components[file->ComponentIndex];
3201 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
3202 if (file->TargetPath)
3203 HeapFree(GetProcessHeap(),0,file->TargetPath);
3205 file->TargetPath = build_directory_name(2, p, file->FileName);
3207 len = strlenW(path_to_source) + strlenW(file->File) + 2;
3208 file->SourcePath = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
3209 strcpyW(file->SourcePath, path_to_source);
3210 strcatW(file->SourcePath, file->File);
3212 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
3213 debugstr_w(file->TargetPath));
3216 uirow=MSI_CreateRecord(9);
3217 MSI_RecordSetStringW(uirow,1,file->File);
3218 strcpyW(uipath,file->TargetPath);
3219 *(strrchrW(uipath,'\\')+1)=0;
3220 MSI_RecordSetStringW(uirow,9,uipath);
3221 MSI_RecordSetInteger(uirow,6,file->FileSize);
3222 ui_actiondata(package,szInstallFiles,uirow);
3223 msiobj_release( &uirow->hdr );
3224 ui_progress(package,2,file->FileSize,0,0);
3226 if (!MoveFileW(file->SourcePath,file->TargetPath))
3228 rc = GetLastError();
3229 ERR("Unable to move file (%s -> %s) (error %d)\n",
3230 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
3232 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
3234 CopyFileW(file->SourcePath,file->TargetPath,FALSE);
3235 DeleteFileW(file->SourcePath);
3238 else if (rc == ERROR_FILE_NOT_FOUND)
3240 ERR("Source File Not Found! Continueing\n");
3245 ERR("Ignoring Error and continuing...\n");
3257 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
3258 LPWSTR* file_source)
3263 return ERROR_INVALID_HANDLE;
3265 for (index = 0; index < package->loaded_files; index ++)
3267 if (strcmpW(file_key,package->files[index].File)==0)
3269 if (package->files[index].State >= 3)
3271 *file_source = dupstrW(package->files[index].TargetPath);
3272 return ERROR_SUCCESS;
3275 return ERROR_FILE_NOT_FOUND;
3279 return ERROR_FUNCTION_FAILED;
3282 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
3286 MSIRECORD * row = 0;
3287 static const WCHAR ExecSeqQuery[] = {
3288 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
3289 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
3292 return ERROR_INVALID_HANDLE;
3294 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3295 if (rc != ERROR_SUCCESS)
3296 return ERROR_SUCCESS;
3298 rc = MSI_ViewExecute(view, 0);
3299 if (rc != ERROR_SUCCESS)
3301 MSI_ViewClose(view);
3302 msiobj_release(&view->hdr);
3308 WCHAR file_key[0x100];
3309 WCHAR *file_source = NULL;
3310 WCHAR dest_name[0x100];
3311 LPWSTR dest_path, dest;
3312 WCHAR component[0x100];
3313 INT component_index;
3317 rc = MSI_ViewFetch(view,&row);
3318 if (rc != ERROR_SUCCESS)
3325 rc = MSI_RecordGetStringW(row,2,component,&sz);
3326 if (rc != ERROR_SUCCESS)
3328 ERR("Unable to get component\n");
3329 msiobj_release(&row->hdr);
3333 component_index = get_loaded_component(package,component);
3334 if (package->components[component_index].ActionRequest !=
3337 TRACE("Skipping copy due to disabled component\n");
3338 msiobj_release(&row->hdr);
3343 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
3344 if (rc != ERROR_SUCCESS)
3346 ERR("Unable to get file key\n");
3347 msiobj_release(&row->hdr);
3351 rc = get_file_target(package,file_key,&file_source);
3353 if (rc != ERROR_SUCCESS)
3355 ERR("Original file unknown %s\n",debugstr_w(file_key));
3356 msiobj_release(&row->hdr);
3358 HeapFree(GetProcessHeap(),0,file_source);
3362 if (MSI_RecordIsNull(row,4))
3364 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
3369 MSI_RecordGetStringW(row,4,dest_name,&sz);
3370 reduce_to_longfilename(dest_name);
3373 if (MSI_RecordIsNull(row,5))
3376 dest_path = dupstrW(file_source);
3377 p = strrchrW(dest_path,'\\');
3383 WCHAR destkey[0x100];
3385 MSI_RecordGetStringW(row,5,destkey,&sz);
3387 dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
3390 ERR("Unable to get destination folder\n");
3391 msiobj_release(&row->hdr);
3393 HeapFree(GetProcessHeap(),0,file_source);
3398 dest = build_directory_name(2, dest_path, dest_name);
3399 HeapFree(GetProcessHeap(), 0, dest_path);
3401 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
3404 if (strcmpW(file_source,dest))
3405 rc = !CopyFileW(file_source,dest,TRUE);
3409 if (rc != ERROR_SUCCESS)
3410 ERR("Failed to copy file\n");
3412 FIXME("We should track these duplicate files as well\n");
3414 msiobj_release(&row->hdr);
3415 HeapFree(GetProcessHeap(),0,dest);
3416 HeapFree(GetProcessHeap(),0,file_source);
3418 MSI_ViewClose(view);
3419 msiobj_release(&view->hdr);
3424 /* OK this value is "interpretted" and then formatted based on the
3425 first few characters */
3426 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
3430 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
3439 deformat_string(package, &value[2], &deformated);
3441 /* binary value type */
3444 *size = strlenW(ptr)/2;
3445 data = HeapAlloc(GetProcessHeap(),0,*size);
3457 data[count] = (BYTE)strtol(byte,NULL,0);
3460 HeapFree(GetProcessHeap(),0,deformated);
3462 TRACE("Data %li bytes(%i)\n",*size,count);
3467 deformat_string(package, &value[1], &deformated);
3470 *size = sizeof(DWORD);
3471 data = HeapAlloc(GetProcessHeap(),0,*size);
3472 *(LPDWORD)data = atoiW(deformated);
3473 TRACE("DWORD %i\n",*data);
3475 HeapFree(GetProcessHeap(),0,deformated);
3488 *type=REG_EXPAND_SZ;
3496 *size = deformat_string(package, ptr,(LPWSTR*)&data);
3501 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3505 MSIRECORD * row = 0;
3506 static const WCHAR ExecSeqQuery[] = {
3507 's','e','l','e','c','t',' ','*',' ',
3508 'f','r','o','m',' ','R','e','g','i','s','t','r','y',0 };
3511 return ERROR_INVALID_HANDLE;
3513 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3514 if (rc != ERROR_SUCCESS)
3515 return ERROR_SUCCESS;
3517 rc = MSI_ViewExecute(view, 0);
3518 if (rc != ERROR_SUCCESS)
3520 MSI_ViewClose(view);
3521 msiobj_release(&view->hdr);
3525 /* increment progress bar each time action data is sent */
3526 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
3530 static const WCHAR szHCR[] =
3531 {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T','\\',0};
3532 static const WCHAR szHCU[] =
3533 {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',0};
3534 static const WCHAR szHLM[] =
3535 {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',
3537 static const WCHAR szHU[] =
3538 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3540 LPSTR value_data = NULL;
3541 HKEY root_key, hkey;
3543 LPWSTR value, key, name, component, deformated;
3545 INT component_index;
3550 rc = MSI_ViewFetch(view,&row);
3551 if (rc != ERROR_SUCCESS)
3556 ui_progress(package,2,0,0,0);
3563 component = load_dynamic_stringW(row, 6);
3564 component_index = get_loaded_component(package,component);
3566 if (package->components[component_index].ActionRequest !=
3569 TRACE("Skipping write due to disabled component\n");
3570 msiobj_release(&row->hdr);
3574 /* null values have special meanings during uninstalls and such */
3576 if(MSI_RecordIsNull(row,5))
3578 msiobj_release(&row->hdr);
3582 root = MSI_RecordGetInteger(row,2);
3583 key = load_dynamic_stringW(row, 3);
3585 name = load_dynamic_stringW(row, 4);
3587 /* get the root key */
3590 case 0: root_key = HKEY_CLASSES_ROOT;
3593 case 1: root_key = HKEY_CURRENT_USER;
3596 case 2: root_key = HKEY_LOCAL_MACHINE;
3599 case 3: root_key = HKEY_USERS;
3603 ERR("Unknown root %i\n",root);
3610 msiobj_release(&row->hdr);
3614 deformat_string(package, key , &deformated);
3615 size = strlenW(deformated) + strlenW(szRoot) + 1;
3616 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
3617 strcpyW(uikey,szRoot);
3618 strcatW(uikey,deformated);
3620 if (RegCreateKeyW( root_key, deformated, &hkey))
3622 ERR("Could not create key %s\n",debugstr_w(deformated));
3623 msiobj_release(&row->hdr);
3624 HeapFree(GetProcessHeap(),0,deformated);
3627 HeapFree(GetProcessHeap(),0,deformated);
3629 value = load_dynamic_stringW(row,5);
3630 value_data = parse_value(package, value, &type, &size);
3632 deformat_string(package, name, &deformated);
3636 TRACE("Setting value %s\n",debugstr_w(deformated));
3637 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3639 uirow = MSI_CreateRecord(3);
3640 MSI_RecordSetStringW(uirow,2,deformated);
3641 MSI_RecordSetStringW(uirow,1,uikey);
3644 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3646 MSI_RecordSetStringW(uirow,3,value);
3648 ui_actiondata(package,szWriteRegistryValues,uirow);
3649 msiobj_release( &uirow->hdr );
3651 HeapFree(GetProcessHeap(),0,value_data);
3653 HeapFree(GetProcessHeap(),0,value);
3654 HeapFree(GetProcessHeap(),0,deformated);
3656 msiobj_release(&row->hdr);
3660 HeapFree(GetProcessHeap(),0,uikey);
3662 HeapFree(GetProcessHeap(),0,key);
3664 HeapFree(GetProcessHeap(),0,name);
3666 HeapFree(GetProcessHeap(),0,component);
3668 MSI_ViewClose(view);
3669 msiobj_release(&view->hdr);
3674 * This helper function should probably go alot of places
3676 * Thinking about this, maybe this should become yet another Bison file
3678 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data)
3690 TRACE("Deformatting NULL string\n");
3694 /* scan for special characters */
3695 if (!strchrW(ptr,'[') || (strchrW(ptr,'[') && !strchrW(ptr,']')))
3698 size = (strlenW(ptr)+1) * sizeof(WCHAR);
3699 *data = HeapAlloc(GetProcessHeap(),0,size);
3704 /* formatted string located */
3705 mark = strchrW(ptr,'[');
3708 INT cnt = (mark - ptr);
3709 TRACE("%i (%i) characters before marker\n",cnt,(mark-ptr));
3710 size = cnt * sizeof(WCHAR);
3711 size += sizeof(WCHAR);
3712 *data = HeapAlloc(GetProcessHeap(),0,size);
3713 strncpyW(*data,ptr,cnt);
3718 size = sizeof(WCHAR);
3719 *data = HeapAlloc(GetProcessHeap(),0,size);
3724 *strchrW(key,']')=0;
3725 mark = strchrW(mark,']');
3727 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3729 rc = MSI_GetPropertyW(package, key, NULL, &sz);
3730 if ((rc == ERROR_SUCCESS) || (rc == ERROR_MORE_DATA))
3735 value = HeapAlloc(GetProcessHeap(),0,sz * sizeof(WCHAR));
3736 MSI_GetPropertyW(package, key, value, &sz);
3738 chunk = (strlenW(value)+1) * sizeof(WCHAR);
3740 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
3742 strcatW(*data,value);
3744 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3748 chunk = (strlenW(mark)+1) * sizeof(WCHAR);
3750 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
3752 strcatW(*data,mark);
3754 (*data)[strlenW(*data)]=0;
3755 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3757 /* recursively do this to clean up */
3758 mark = HeapAlloc(GetProcessHeap(),0,size);
3759 strcpyW(mark,*data);
3760 TRACE("String at this point %s\n",debugstr_w(mark));
3761 size = deformat_string(package,mark,data);
3762 HeapFree(GetProcessHeap(),0,mark);
3766 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3768 return ERROR_SUCCESS;
3772 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3776 static const WCHAR q1[]={
3777 'S','E','L','E','C','T',' ','*',' ',
3778 'F','R','O','M',' ','R','e','g','i','s','t','r','y',0};
3781 MSIRECORD * row = 0;
3784 TRACE(" InstallValidate \n");
3786 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3787 if (rc != ERROR_SUCCESS)
3788 return ERROR_SUCCESS;
3790 rc = MSI_ViewExecute(view, 0);
3791 if (rc != ERROR_SUCCESS)
3793 MSI_ViewClose(view);
3794 msiobj_release(&view->hdr);
3799 rc = MSI_ViewFetch(view,&row);
3800 if (rc != ERROR_SUCCESS)
3807 msiobj_release(&row->hdr);
3809 MSI_ViewClose(view);
3810 msiobj_release(&view->hdr);
3812 total = total + progress * REG_PROGRESS_VALUE;
3813 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
3814 for (i=0; i < package->loaded_files; i++)
3815 total += package->files[i].FileSize;
3816 ui_progress(package,0,total,0,0);
3818 return ERROR_SUCCESS;
3821 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3824 MSIQUERY * view = NULL;
3825 MSIRECORD * row = 0;
3826 static const WCHAR ExecSeqQuery[] = {
3827 'S','E','L','E','C','T',' ','*',' ',
3828 'f','r','o','m',' ','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3829 static const WCHAR title[]=
3830 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3832 TRACE("Checking launch conditions\n");
3834 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3835 if (rc != ERROR_SUCCESS)
3836 return ERROR_SUCCESS;
3838 rc = MSI_ViewExecute(view, 0);
3839 if (rc != ERROR_SUCCESS)
3841 MSI_ViewClose(view);
3842 msiobj_release(&view->hdr);
3847 while (rc == ERROR_SUCCESS)
3850 LPWSTR message = NULL;
3852 rc = MSI_ViewFetch(view,&row);
3853 if (rc != ERROR_SUCCESS)
3859 cond = load_dynamic_stringW(row,1);
3861 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3863 message = load_dynamic_stringW(row,2);
3864 MessageBoxW(NULL,message,title,MB_OK);
3865 HeapFree(GetProcessHeap(),0,message);
3866 rc = ERROR_FUNCTION_FAILED;
3868 HeapFree(GetProcessHeap(),0,cond);
3869 msiobj_release(&row->hdr);
3871 MSI_ViewClose(view);
3872 msiobj_release(&view->hdr);
3876 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
3879 MSICOMPONENT* cmp = &package->components[component_index];
3881 if (cmp->KeyPath[0]==0)
3883 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
3886 if ((cmp->Attributes & 0x4) || (cmp->Attributes & 0x20))
3888 FIXME("UNIMPLEMENTED keypath as Registry or ODBC Source\n");
3894 j = get_loaded_file(package,cmp->KeyPath);
3898 LPWSTR p = dupstrW(package->files[j].TargetPath);
3906 * Ok further analysis makes me think that this work is
3907 * actually done in the PublishComponents and PublishFeatures
3908 * step, and not here. It appears like the keypath and all that is
3909 * resolved in this step, however actually written in the Publish steps.
3910 * But we will leave it here for now because it is unclear
3912 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
3915 WCHAR squished_pc[0x100];
3916 WCHAR squished_cc[0x100];
3919 HKEY hkey=0,hkey2=0,hkey3=0;
3920 static const WCHAR szProductCode[]=
3921 {'P','r','o','d','u','c','t','C','o','d','e',0};
3922 static const WCHAR szInstaller[] = {
3923 'S','o','f','t','w','a','r','e','\\',
3924 'M','i','c','r','o','s','o','f','t','\\',
3925 'W','i','n','d','o','w','s','\\',
3926 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3927 'I','n','s','t','a','l','l','e','r',0 };
3928 static const WCHAR szFeatures[] = {
3929 'F','e','a','t','u','r','e','s',0 };
3930 static const WCHAR szComponents[] = {
3931 'C','o','m','p','o','n','e','n','t','s',0 };
3934 return ERROR_INVALID_HANDLE;
3936 /* writes the Component and Features values to the registry */
3937 productcode = load_dynamic_property(package,szProductCode,&rc);
3941 squash_guid(productcode,squished_pc);
3942 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller,&hkey);
3943 if (rc != ERROR_SUCCESS)
3946 rc = RegCreateKeyW(hkey,szFeatures,&hkey2);
3947 if (rc != ERROR_SUCCESS)
3950 rc = RegCreateKeyW(hkey2,squished_pc,&hkey3);
3951 if (rc != ERROR_SUCCESS)
3954 /* here the guids are base 85 encoded */
3955 for (i = 0; i < package->loaded_features; i++)
3962 size = package->features[i].ComponentCount*21*sizeof(WCHAR);
3963 data = HeapAlloc(GetProcessHeap(), 0, size);
3966 for (j = 0; j < package->features[i].ComponentCount; j++)
3969 TRACE("From %s\n",debugstr_w(package->components
3970 [package->features[i].Components[j]].ComponentId));
3971 CLSIDFromString(package->components
3972 [package->features[i].Components[j]].ComponentId,
3974 encode_base85_guid(&clsid,buf);
3975 TRACE("to %s\n",debugstr_w(buf));
3979 size = strlenW(data)*sizeof(WCHAR);
3980 RegSetValueExW(hkey3,package->features[i].Feature,0,REG_SZ,
3982 HeapFree(GetProcessHeap(),0,data);
3988 rc = RegCreateKeyW(hkey,szComponents,&hkey2);
3989 if (rc != ERROR_SUCCESS)
3992 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
3993 for (i = 0; i < package->loaded_components; i++)
3995 ui_progress(package,2,0,0,0);
3996 if (package->components[i].ComponentId[0]!=0)
3998 WCHAR *keypath = NULL;
4001 squash_guid(package->components[i].ComponentId,squished_cc);
4002 rc = RegCreateKeyW(hkey2,squished_cc,&hkey3);
4003 if (rc != ERROR_SUCCESS)
4006 keypath = resolve_keypath(package,i);
4009 RegSetValueExW(hkey3,squished_pc,0,REG_SZ,(LPVOID)keypath,
4010 (strlenW(keypath)+1)*sizeof(WCHAR));
4014 uirow = MSI_CreateRecord(3);
4015 MSI_RecordSetStringW(uirow,1,productcode);
4016 MSI_RecordSetStringW(uirow,2,package->components[i].
4018 MSI_RecordSetStringW(uirow,3,keypath);
4019 ui_actiondata(package,szProcessComponents,uirow);
4020 msiobj_release( &uirow->hdr );
4021 HeapFree(GetProcessHeap(),0,keypath);
4026 HeapFree(GetProcessHeap(), 0, productcode);
4032 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
4035 * OK this is a bit confusing.. I am given a _Component key and I believe
4036 * that the file that is being registered as a type library is the "key file
4037 * of that component" which I interpret to mean "The file in the KeyPath of
4042 MSIRECORD * row = 0;
4043 static const WCHAR Query[] = {
4044 'S','E','L','E','C','T',' ','*',' ',
4045 'f','r','o','m',' ','T','y','p','e','L','i','b',0};
4050 return ERROR_INVALID_HANDLE;
4052 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4053 if (rc != ERROR_SUCCESS)
4054 return ERROR_SUCCESS;
4056 rc = MSI_ViewExecute(view, 0);
4057 if (rc != ERROR_SUCCESS)
4059 MSI_ViewClose(view);
4060 msiobj_release(&view->hdr);
4066 WCHAR component[0x100];
4070 rc = MSI_ViewFetch(view,&row);
4071 if (rc != ERROR_SUCCESS)
4078 MSI_RecordGetStringW(row,3,component,&sz);
4080 index = get_loaded_component(package,component);
4083 msiobj_release(&row->hdr);
4087 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
4089 TRACE("Skipping typelib reg due to disabled component\n");
4090 msiobj_release(&row->hdr);
4094 index = get_loaded_file(package,package->components[index].KeyPath);
4098 msiobj_release(&row->hdr);
4102 res = LoadTypeLib(package->files[index].TargetPath,&ptLib);
4106 WCHAR helpid[0x100];
4109 MSI_RecordGetStringW(row,6,helpid,&sz);
4111 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
4112 res = RegisterTypeLib(ptLib,package->files[index].TargetPath,help);
4113 HeapFree(GetProcessHeap(),0,help);
4115 if (!SUCCEEDED(res))
4116 ERR("Failed to register type library %s\n",
4117 debugstr_w(package->files[index].TargetPath));
4120 /* Yes the row has more fields than I need, but #1 is
4121 correct and the only one I need. Why make a new row? */
4123 ui_actiondata(package,szRegisterTypeLibraries,row);
4125 TRACE("Registered %s\n",
4126 debugstr_w(package->files[index].TargetPath));
4130 ITypeLib_Release(ptLib);
4133 ERR("Failed to load type library %s\n",
4134 debugstr_w(package->files[index].TargetPath));
4136 msiobj_release(&row->hdr);
4138 MSI_ViewClose(view);
4139 msiobj_release(&view->hdr);
4144 static UINT register_appid(MSIPACKAGE *package, LPCWSTR clsid, LPCWSTR app )
4146 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
4149 MSIRECORD * row = 0;
4150 static const WCHAR ExecSeqQuery[] =
4151 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','p','p','I'
4152 ,'d',' ','w','h','e','r','e',' ','A','p','p','I','d','=','`','%','s','`',0};
4157 return ERROR_INVALID_HANDLE;
4159 rc = ACTION_OpenQuery(package->db, &view, ExecSeqQuery, clsid);
4160 if (rc != ERROR_SUCCESS)
4163 rc = MSI_ViewExecute(view, 0);
4164 if (rc != ERROR_SUCCESS)
4166 MSI_ViewClose(view);
4167 msiobj_release(&view->hdr);
4171 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
4172 RegCreateKeyW(hkey2,clsid,&hkey3);
4173 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
4174 (strlenW(app)+1)*sizeof(WCHAR));
4176 rc = MSI_ViewFetch(view,&row);
4177 if (rc != ERROR_SUCCESS)
4179 MSI_ViewClose(view);
4180 msiobj_release(&view->hdr);
4184 if (!MSI_RecordIsNull(row,2))
4186 LPWSTR deformated=0;
4188 static const WCHAR szRemoteServerName[] =
4189 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
4190 buffer = load_dynamic_stringW(row,2);
4191 size = deformat_string(package,buffer,&deformated);
4192 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
4194 HeapFree(GetProcessHeap(),0,deformated);
4195 HeapFree(GetProcessHeap(),0,buffer);
4198 if (!MSI_RecordIsNull(row,3))
4200 static const WCHAR szLocalService[] =
4201 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
4203 buffer = load_dynamic_stringW(row,3);
4204 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4205 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
4206 HeapFree(GetProcessHeap(),0,buffer);
4209 if (!MSI_RecordIsNull(row,4))
4211 static const WCHAR szService[] =
4212 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
4214 buffer = load_dynamic_stringW(row,4);
4215 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4216 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
4217 HeapFree(GetProcessHeap(),0,buffer);
4220 if (!MSI_RecordIsNull(row,5))
4222 static const WCHAR szDLL[] =
4223 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
4225 buffer = load_dynamic_stringW(row,5);
4226 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4227 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
4228 HeapFree(GetProcessHeap(),0,buffer);
4231 if (!MSI_RecordIsNull(row,6))
4233 static const WCHAR szActivate[] =
4234 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
4235 static const WCHAR szY[] = {'Y',0};
4237 if (MSI_RecordGetInteger(row,6))
4238 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
4241 if (!MSI_RecordIsNull(row,7))
4243 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
4244 static const WCHAR szUser[] =
4245 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
4247 if (MSI_RecordGetInteger(row,7))
4248 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
4251 msiobj_release(&row->hdr);
4252 MSI_ViewClose(view);
4253 msiobj_release(&view->hdr);
4259 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
4262 * Again I am assuming the words, "Whose key file represents" when referring
4263 * to a Component as to meaning that Components KeyPath file
4265 * Also there is a very strong connection between ClassInfo and ProgID
4266 * that I am mostly glossing over.
4267 * What would be more propper is to load the ClassInfo and the ProgID info
4268 * into memory data structures and then be able to enable and disable them
4269 * based on component.
4274 MSIRECORD * row = 0;
4275 static const WCHAR ExecSeqQuery[] = {
4276 'S','E','L','E','C','T',' ','*',' ',
4277 'f','r','o','m',' ','C','l','a','s','s',0};
4278 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4279 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
4280 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
4281 HKEY hkey,hkey2,hkey3;
4284 return ERROR_INVALID_HANDLE;
4286 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
4287 if (rc != ERROR_SUCCESS)
4288 return ERROR_FUNCTION_FAILED;
4290 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4291 if (rc != ERROR_SUCCESS)
4297 rc = MSI_ViewExecute(view, 0);
4298 if (rc != ERROR_SUCCESS)
4300 MSI_ViewClose(view);
4301 msiobj_release(&view->hdr);
4308 WCHAR buffer[0x100];
4313 rc = MSI_ViewFetch(view,&row);
4314 if (rc != ERROR_SUCCESS)
4321 MSI_RecordGetStringW(row,3,buffer,&sz);
4323 index = get_loaded_component(package,buffer);
4327 msiobj_release(&row->hdr);
4331 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
4333 TRACE("Skipping class reg due to disabled component\n");
4334 msiobj_release(&row->hdr);
4339 MSI_RecordGetStringW(row,1,clsid,&sz);
4340 RegCreateKeyW(hkey,clsid,&hkey2);
4342 if (!MSI_RecordIsNull(row,5))
4345 MSI_RecordGetStringW(row,5,desc,&sz);
4347 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
4348 (strlenW(desc)+1)*sizeof(WCHAR));
4354 MSI_RecordGetStringW(row,2,buffer,&sz);
4356 RegCreateKeyW(hkey2,buffer,&hkey3);
4358 index = get_loaded_file(package,package->components[index].KeyPath);
4359 RegSetValueExW(hkey3,NULL,0,REG_SZ,
4360 (LPVOID)package->files[index].TargetPath,
4361 (strlenW(package->files[index].TargetPath)+1)
4366 if (!MSI_RecordIsNull(row,4))
4369 MSI_RecordGetStringW(row,4,buffer,&sz);
4371 RegCreateKeyW(hkey2,szProgID,&hkey3);
4373 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
4374 (strlenW(buffer)+1)*sizeof(WCHAR));
4379 if (!MSI_RecordIsNull(row,6))
4382 MSI_RecordGetStringW(row,6,buffer,&sz);
4384 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
4385 (strlenW(buffer)+1)*sizeof(WCHAR));
4387 register_appid(package,buffer,desc);
4392 FIXME("Process the rest of the fields >7\n");
4394 ui_actiondata(package,szRegisterClassInfo,row);
4396 msiobj_release(&row->hdr);
4398 MSI_ViewClose(view);
4399 msiobj_release(&view->hdr);
4406 static UINT register_progid_base(MSIRECORD * row, LPWSTR clsid)
4408 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4410 WCHAR buffer[0x100];
4415 MSI_RecordGetStringW(row,1,buffer,&sz);
4416 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
4418 if (!MSI_RecordIsNull(row,4))
4421 MSI_RecordGetStringW(row,4,buffer,&sz);
4422 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4426 if (!MSI_RecordIsNull(row,3))
4430 MSI_RecordGetStringW(row,3,buffer,&sz);
4431 RegCreateKeyW(hkey,szCLSID,&hkey2);
4432 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4436 strcpyW(clsid,buffer);
4442 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
4443 return ERROR_FUNCTION_FAILED;
4445 if (!MSI_RecordIsNull(row,5))
4446 FIXME ("UNHANDLED icon in Progid\n");
4447 return ERROR_SUCCESS;
4450 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid);
4452 static UINT register_parent_progid(MSIPACKAGE *package, LPCWSTR parent,
4457 MSIRECORD * row = 0;
4458 static const WCHAR Query_t[] =
4459 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','P','r','o','g'
4460 ,'I','d',' ','w','h','e','r','e',' ','P','r','o','g','I','d',' ','=',' ','`'
4464 return ERROR_INVALID_HANDLE;
4466 rc = ACTION_OpenQuery(package->db, &view, Query_t, parent);
4467 if (rc != ERROR_SUCCESS)
4470 rc = MSI_ViewExecute(view, 0);
4471 if (rc != ERROR_SUCCESS)
4473 MSI_ViewClose(view);
4474 msiobj_release(&view->hdr);
4478 rc = MSI_ViewFetch(view,&row);
4479 if (rc != ERROR_SUCCESS)
4481 MSI_ViewClose(view);
4482 msiobj_release(&view->hdr);
4486 register_progid(package,row,clsid);
4488 msiobj_release(&row->hdr);
4489 MSI_ViewClose(view);
4490 msiobj_release(&view->hdr);
4494 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid)
4496 UINT rc = ERROR_SUCCESS;
4498 if (MSI_RecordIsNull(row,2))
4499 rc = register_progid_base(row,clsid);
4502 WCHAR buffer[0x1000];
4505 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4507 /* check if already registered */
4509 MSI_RecordGetStringW(row,1,buffer,&sz);
4510 RegCreateKeyExW(HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4511 KEY_ALL_ACCESS, NULL, &hkey, &disp );
4512 if (disp == REG_OPENED_EXISTING_KEY)
4514 TRACE("Key already registered\n");
4518 /* clsid is same as parent */
4519 RegCreateKeyW(hkey,szCLSID,&hkey2);
4520 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
4526 MSI_RecordGetStringW(row,2,buffer,&sz);
4527 rc = register_parent_progid(package,buffer,clsid);
4529 if (!MSI_RecordIsNull(row,4))
4532 MSI_RecordGetStringW(row,4,buffer,&sz);
4533 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
4534 (strlenW(buffer)+1) * sizeof(WCHAR));
4537 if (!MSI_RecordIsNull(row,5))
4538 FIXME ("UNHANDLED icon in Progid\n");
4545 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
4548 * Sigh, here I am just brute force registering all progids
4549 * this needs to be linked to the Classes that have been registered
4550 * but the easiest way to do that is to load all these stuff into
4551 * memory for easy checking.
4553 * Gives me something to continue to work toward.
4557 MSIRECORD * row = 0;
4558 static const WCHAR Query[] = {
4559 'S','E','L','E','C','T',' ','*',' ',
4560 'F','R','O','M',' ','P','r','o','g','I','d',0};
4563 return ERROR_INVALID_HANDLE;
4565 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4566 if (rc != ERROR_SUCCESS)
4567 return ERROR_SUCCESS;
4569 rc = MSI_ViewExecute(view, 0);
4570 if (rc != ERROR_SUCCESS)
4572 MSI_ViewClose(view);
4573 msiobj_release(&view->hdr);
4579 WCHAR clsid[0x1000];
4581 rc = MSI_ViewFetch(view,&row);
4582 if (rc != ERROR_SUCCESS)
4588 register_progid(package,row,clsid);
4589 ui_actiondata(package,szRegisterProgIdInfo,row);
4591 msiobj_release(&row->hdr);
4593 MSI_ViewClose(view);
4594 msiobj_release(&view->hdr);
4598 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
4602 LPWSTR SystemFolder;
4606 static const WCHAR szInstaller[] =
4607 {'I','n','s','t','a','l','l','e','r','\\',0};
4608 static const WCHAR szProductCode[] =
4609 {'P','r','o','d','u','c','t','C','o','d','e',0};
4610 static const WCHAR szFolder[] =
4611 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4613 ProductCode = load_dynamic_property(package,szProductCode,&rc);
4617 SystemFolder = load_dynamic_property(package,szFolder,NULL);
4619 dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
4621 create_full_pathW(dest);
4623 *FilePath = build_directory_name(2, dest, icon_name);
4625 HeapFree(GetProcessHeap(),0,SystemFolder);
4626 HeapFree(GetProcessHeap(),0,ProductCode);
4627 HeapFree(GetProcessHeap(),0,dest);
4628 return ERROR_SUCCESS;
4631 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
4635 MSIRECORD * row = 0;
4636 static const WCHAR Query[] = {
4637 'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
4638 'S','h','o','r','t','c','u','t',0};
4644 return ERROR_INVALID_HANDLE;
4646 res = CoInitialize( NULL );
4649 ERR("CoInitialize failed\n");
4650 return ERROR_FUNCTION_FAILED;
4653 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4654 if (rc != ERROR_SUCCESS)
4655 return ERROR_SUCCESS;
4657 rc = MSI_ViewExecute(view, 0);
4658 if (rc != ERROR_SUCCESS)
4660 MSI_ViewClose(view);
4661 msiobj_release(&view->hdr);
4667 LPWSTR target_file, target_folder;
4668 WCHAR buffer[0x100];
4671 static const WCHAR szlnk[]={'.','l','n','k',0};
4673 rc = MSI_ViewFetch(view,&row);
4674 if (rc != ERROR_SUCCESS)
4681 MSI_RecordGetStringW(row,4,buffer,&sz);
4683 index = get_loaded_component(package,buffer);
4687 msiobj_release(&row->hdr);
4691 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
4693 TRACE("Skipping shortcut creation due to disabled component\n");
4694 msiobj_release(&row->hdr);
4698 ui_actiondata(package,szCreateShortcuts,row);
4700 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
4701 &IID_IShellLinkW, (LPVOID *) &sl );
4705 ERR("Is IID_IShellLink\n");
4706 msiobj_release(&row->hdr);
4710 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
4713 ERR("Is IID_IPersistFile\n");
4714 msiobj_release(&row->hdr);
4719 MSI_RecordGetStringW(row,2,buffer,&sz);
4720 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
4722 /* may be needed because of a bug somehwere else */
4723 create_full_pathW(target_folder);
4726 MSI_RecordGetStringW(row,3,buffer,&sz);
4727 reduce_to_longfilename(buffer);
4728 if (!strchrW(buffer,'.') || strcmpiW(strchrW(buffer,'.'),szlnk))
4729 strcatW(buffer,szlnk);
4730 target_file = build_directory_name(2, target_folder, buffer);
4731 HeapFree(GetProcessHeap(),0,target_folder);
4734 MSI_RecordGetStringW(row,5,buffer,&sz);
4735 if (strchrW(buffer,'['))
4738 deformat_string(package,buffer,&deformated);
4739 IShellLinkW_SetPath(sl,deformated);
4740 HeapFree(GetProcessHeap(),0,deformated);
4744 FIXME("UNHANDLED shortcut format, advertised shortcut\n");
4745 IPersistFile_Release( pf );
4746 IShellLinkW_Release( sl );
4747 msiobj_release(&row->hdr);
4751 if (!MSI_RecordIsNull(row,6))
4755 MSI_RecordGetStringW(row,6,buffer,&sz);
4756 deformat_string(package,buffer,&deformated);
4757 IShellLinkW_SetArguments(sl,deformated);
4758 HeapFree(GetProcessHeap(),0,deformated);
4761 if (!MSI_RecordIsNull(row,7))
4764 deformated = load_dynamic_stringW(row,7);
4765 IShellLinkW_SetDescription(sl,deformated);
4766 HeapFree(GetProcessHeap(),0,deformated);
4769 if (!MSI_RecordIsNull(row,8))
4770 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
4772 if (!MSI_RecordIsNull(row,9))
4778 MSI_RecordGetStringW(row,9,buffer,&sz);
4780 build_icon_path(package,buffer,&Path);
4781 index = MSI_RecordGetInteger(row,10);
4783 IShellLinkW_SetIconLocation(sl,Path,index);
4784 HeapFree(GetProcessHeap(),0,Path);
4787 if (!MSI_RecordIsNull(row,11))
4788 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
4790 if (!MSI_RecordIsNull(row,12))
4794 MSI_RecordGetStringW(row,12,buffer,&sz);
4795 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
4796 IShellLinkW_SetWorkingDirectory(sl,Path);
4797 HeapFree(GetProcessHeap(), 0, Path);
4800 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
4801 IPersistFile_Save(pf,target_file,FALSE);
4803 HeapFree(GetProcessHeap(),0,target_file);
4805 IPersistFile_Release( pf );
4806 IShellLinkW_Release( sl );
4808 msiobj_release(&row->hdr);
4810 MSI_ViewClose(view);
4811 msiobj_release(&view->hdr);
4821 * 99% of the work done here is only done for
4822 * advertised installs. However this is where the
4823 * Icon table is processed and written out
4824 * so that is what I am going to do here.
4826 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
4830 MSIRECORD * row = 0;
4831 static const WCHAR Query[]={
4832 'S','E','L','E','C','T',' ','*',' ',
4833 'f','r','o','m',' ','I','c','o','n',0};
4837 return ERROR_INVALID_HANDLE;
4839 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4840 if (rc != ERROR_SUCCESS)
4841 return ERROR_SUCCESS;
4843 rc = MSI_ViewExecute(view, 0);
4844 if (rc != ERROR_SUCCESS)
4846 MSI_ViewClose(view);
4847 msiobj_release(&view->hdr);
4854 WCHAR *FilePath=NULL;
4855 WCHAR *FileName=NULL;
4858 rc = MSI_ViewFetch(view,&row);
4859 if (rc != ERROR_SUCCESS)
4865 FileName = load_dynamic_stringW(row,1);
4868 ERR("Unable to get FileName\n");
4869 msiobj_release(&row->hdr);
4873 build_icon_path(package,FileName,&FilePath);
4875 HeapFree(GetProcessHeap(),0,FileName);
4877 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
4879 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
4880 FILE_ATTRIBUTE_NORMAL, NULL);
4882 if (the_file == INVALID_HANDLE_VALUE)
4884 ERR("Unable to create file %s\n",debugstr_w(FilePath));
4885 msiobj_release(&row->hdr);
4886 HeapFree(GetProcessHeap(),0,FilePath);
4894 rc = MSI_RecordReadStream(row,2,buffer,&sz);
4895 if (rc != ERROR_SUCCESS)
4897 ERR("Failed to get stream\n");
4898 CloseHandle(the_file);
4899 DeleteFileW(FilePath);
4902 WriteFile(the_file,buffer,sz,&write,NULL);
4903 } while (sz == 1024);
4905 HeapFree(GetProcessHeap(),0,FilePath);
4907 CloseHandle(the_file);
4908 msiobj_release(&row->hdr);
4910 MSI_ViewClose(view);
4911 msiobj_release(&view->hdr);
4916 /* Msi functions that seem appropriate here */
4917 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
4922 TRACE(" exteral attempt at action %s\n",szAction);
4925 return ERROR_FUNCTION_FAILED;
4927 return ERROR_FUNCTION_FAILED;
4929 szwAction = strdupAtoW(szAction);
4932 return ERROR_FUNCTION_FAILED;
4935 rc = MsiDoActionW(hInstall, szwAction);
4936 HeapFree(GetProcessHeap(),0,szwAction);
4940 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
4942 MSIPACKAGE *package;
4943 UINT ret = ERROR_INVALID_HANDLE;
4945 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
4947 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4950 ret = ACTION_PerformAction(package,szAction);
4951 msiobj_release( &package->hdr );
4956 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
4957 LPSTR szPathBuf, DWORD* pcchPathBuf)
4963 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
4966 return ERROR_FUNCTION_FAILED;
4968 return ERROR_FUNCTION_FAILED;
4970 szwFolder = strdupAtoW(szFolder);
4973 return ERROR_FUNCTION_FAILED;
4975 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
4977 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
4979 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
4980 *pcchPathBuf, NULL, NULL );
4982 HeapFree(GetProcessHeap(),0,szwFolder);
4983 HeapFree(GetProcessHeap(),0,szwPathBuf);
4988 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
4989 szPathBuf, DWORD* pcchPathBuf)
4992 UINT rc = ERROR_FUNCTION_FAILED;
4993 MSIPACKAGE *package;
4995 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
4997 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4999 return ERROR_INVALID_HANDLE;
5000 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
5001 msiobj_release( &package->hdr );
5003 if (path && (strlenW(path) > *pcchPathBuf))
5005 *pcchPathBuf = strlenW(path)+1;
5006 rc = ERROR_MORE_DATA;
5010 *pcchPathBuf = strlenW(path)+1;
5011 strcpyW(szPathBuf,path);
5012 TRACE("Returning Path %s\n",debugstr_w(path));
5015 HeapFree(GetProcessHeap(),0,path);
5021 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
5022 LPSTR szPathBuf, DWORD* pcchPathBuf)
5028 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
5031 return ERROR_FUNCTION_FAILED;
5033 return ERROR_FUNCTION_FAILED;
5035 szwFolder = strdupAtoW(szFolder);
5037 return ERROR_FUNCTION_FAILED;
5039 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
5041 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
5043 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
5044 *pcchPathBuf, NULL, NULL );
5046 HeapFree(GetProcessHeap(),0,szwFolder);
5047 HeapFree(GetProcessHeap(),0,szwPathBuf);
5052 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
5053 szPathBuf, DWORD* pcchPathBuf)
5056 UINT rc = ERROR_FUNCTION_FAILED;
5057 MSIPACKAGE *package;
5059 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
5061 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5063 return ERROR_INVALID_HANDLE;
5064 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
5065 msiobj_release( &package->hdr );
5067 if (path && strlenW(path) > *pcchPathBuf)
5069 *pcchPathBuf = strlenW(path)+1;
5070 rc = ERROR_MORE_DATA;
5074 *pcchPathBuf = strlenW(path)+1;
5075 strcpyW(szPathBuf,path);
5076 TRACE("Returning Path %s\n",debugstr_w(path));
5079 HeapFree(GetProcessHeap(),0,path);
5085 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
5086 LPCSTR szFolderPath)
5089 LPWSTR szwFolderPath;
5093 return ERROR_FUNCTION_FAILED;
5095 return ERROR_FUNCTION_FAILED;
5097 szwFolder = strdupAtoW(szFolder);
5099 return ERROR_FUNCTION_FAILED;
5101 szwFolderPath = strdupAtoW(szFolderPath);
5104 HeapFree(GetProcessHeap(),0,szwFolder);
5105 return ERROR_FUNCTION_FAILED;
5108 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
5110 HeapFree(GetProcessHeap(),0,szwFolder);
5111 HeapFree(GetProcessHeap(),0,szwFolderPath);
5116 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
5117 LPCWSTR szFolderPath)
5121 LPWSTR path2 = NULL;
5125 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
5128 return ERROR_INVALID_HANDLE;
5130 if (szFolderPath[0]==0)
5131 return ERROR_FUNCTION_FAILED;
5133 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
5134 return ERROR_FUNCTION_FAILED;
5136 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
5139 return ERROR_INVALID_PARAMETER;
5141 if (folder->Property)
5142 HeapFree(GetProcessHeap(),0,folder->Property);
5144 len = strlenW(szFolderPath);
5146 if (szFolderPath[len-1]!='\\')
5149 folder->Property = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
5150 strcpyW(folder->Property,szFolderPath);
5151 strcatW(folder->Property,cszbs);
5154 folder->Property = dupstrW(szFolderPath);
5156 if (strcmpiW(path, szFolderPath) == 0)
5159 * Resolved Target has not really changed, so just
5160 * set this folder and do not recalculate everything.
5162 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
5163 folder->ResolvedTarget = NULL;
5164 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
5165 HeapFree(GetProcessHeap(),0,path2);
5169 for (i = 0; i < package->loaded_folders; i++)
5171 if (package->folders[i].ResolvedTarget)
5172 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
5173 package->folders[i].ResolvedTarget=NULL;
5176 for (i = 0; i < package->loaded_folders; i++)
5178 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
5180 HeapFree(GetProcessHeap(),0,path2);
5183 HeapFree(GetProcessHeap(),0,path);
5185 return ERROR_SUCCESS;
5188 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
5189 LPCWSTR szFolderPath)
5191 MSIPACKAGE *package;
5194 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
5196 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5197 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
5198 msiobj_release( &package->hdr );
5202 /***********************************************************************
5203 * MsiGetMode (MSI.@)
5205 * Returns an internal installer state (if it is running in a mode iRunMode)
5208 * hInstall [I] Handle to the installation
5209 * hRunMode [I] Checking run mode
5210 * MSIRUNMODE_ADMIN Administrative mode
5211 * MSIRUNMODE_ADVERTISE Advertisement mode
5212 * MSIRUNMODE_MAINTENANCE Maintenance mode
5213 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
5214 * MSIRUNMODE_LOGENABLED Log file is writing
5215 * MSIRUNMODE_OPERATIONS Operations in progress??
5216 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
5217 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
5218 * MSIRUNMODE_CABINET Files from cabinet are installed
5219 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is supressed
5220 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is supressed
5221 * MSIRUNMODE_RESERVED11 Reserved
5222 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
5223 * MSIRUNMODE_ZAWENABLED Demand installation is supported
5224 * MSIRUNMODE_RESERVED14 Reserved
5225 * MSIRUNMODE_RESERVED15 Reserved
5226 * MSIRUNMODE_SCHEDULED called from install script
5227 * MSIRUNMODE_ROLLBACK called from rollback script
5228 * MSIRUNMODE_COMMIT called from commit script
5231 * In the state: TRUE
5232 * Not in the state: FALSE
5236 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
5238 FIXME("STUB (iRunMode=%i)\n",iRunMode);
5243 * According to the docs, when this is called it immediately recalculates
5244 * all the component states as well
5246 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
5247 INSTALLSTATE iState)
5249 LPWSTR szwFeature = NULL;
5252 szwFeature = strdupAtoW(szFeature);
5255 return ERROR_FUNCTION_FAILED;
5257 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
5259 HeapFree(GetProcessHeap(),0,szwFeature);
5264 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
5265 INSTALLSTATE iState)
5267 MSIPACKAGE* package;
5270 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
5272 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5274 return ERROR_INVALID_HANDLE;
5276 index = get_loaded_feature(package,szFeature);
5278 return ERROR_UNKNOWN_FEATURE;
5280 package->features[index].ActionRequest= iState;
5282 return ERROR_SUCCESS;
5285 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
5286 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5288 LPWSTR szwFeature = NULL;
5291 szwFeature = strdupAtoW(szFeature);
5293 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
5295 HeapFree( GetProcessHeap(), 0 , szwFeature);
5300 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
5301 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5305 index = get_loaded_feature(package,szFeature);
5307 return ERROR_UNKNOWN_FEATURE;
5310 *piInstalled = package->features[index].Installed;
5313 *piAction = package->features[index].Action;
5315 TRACE("returning %i %i\n",*piInstalled,*piAction);
5317 return ERROR_SUCCESS;
5320 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
5321 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5323 MSIPACKAGE* package;
5326 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
5329 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5331 return ERROR_INVALID_HANDLE;
5332 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
5333 msiobj_release( &package->hdr );
5337 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
5338 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5340 LPWSTR szwComponent= NULL;
5343 szwComponent= strdupAtoW(szComponent);
5345 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
5347 HeapFree( GetProcessHeap(), 0 , szwComponent);
5352 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
5353 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5357 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
5360 index = get_loaded_component(package,szComponent);
5362 return ERROR_UNKNOWN_COMPONENT;
5365 *piInstalled = package->components[index].Installed;
5368 *piInstalled = package->components[index].Action;
5370 return ERROR_SUCCESS;
5373 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
5374 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5376 MSIPACKAGE* package;
5379 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
5380 piInstalled, piAction);
5382 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5384 return ERROR_INVALID_HANDLE;
5385 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
5386 msiobj_release( &package->hdr );
5391 static UINT ACTION_Template(MSIPACKAGE *package)
5395 MSIRECORD * row = 0;
5396 static const WCHAR ExecSeqQuery[] = {0};
5398 rc = MsiDatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5399 if (rc != ERROR_SUCCESS)
5402 rc = MsiViewExecute(view, 0);
5403 if (rc != ERROR_SUCCESS)
5406 msiobj_release(&view->hdr);
5412 rc = MsiViewFetch(view,&row);
5413 if (rc != ERROR_SUCCESS)
5419 msiobj_release(&row->hdr);
5422 msiobj_release(&view->hdr);