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 \ separating 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 ACTION_CallDllFunction(thread_struct *stuff)
1422 TRACE("calling function (%s, %s) \n", debugstr_w(stuff->source),
1423 debugstr_w(stuff->target));
1425 hModule = LoadLibraryW(stuff->source);
1428 proc = strdupWtoA( stuff->target );
1429 fn = (CustomEntry*)GetProcAddress(hModule,proc);
1433 MSIPACKAGE *package = stuff->package;
1435 TRACE("Calling function %s\n", proc);
1436 hPackage = msiobj_findhandle( &package->hdr );
1440 msiobj_release( &package->hdr );
1443 ERR("Handle for object %p not found\n", package );
1446 ERR("Cannot load functon\n");
1448 HeapFree(GetProcessHeap(),0,proc);
1449 FreeLibrary(hModule);
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 DWORD WINAPI DllThread(LPVOID info)
1462 thread_struct *stuff;
1465 TRACE("MSI Thread (0x%lx) started for custom action\n",
1466 GetCurrentThreadId());
1468 stuff = (thread_struct*)info;
1469 rc = ACTION_CallDllFunction(stuff);
1471 TRACE("MSI Thread (0x%lx) finished\n",GetCurrentThreadId());
1472 /* clse all handles for this thread */
1473 MsiCloseAllHandles();
1477 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
1478 const LPWSTR target, const INT type)
1480 WCHAR tmp_file[MAX_PATH];
1481 thread_struct *info;
1483 HANDLE ThreadHandle;
1485 store_binary_to_temp(package, source, tmp_file);
1487 TRACE("Calling function %s from %s\n",debugstr_w(target),
1488 debugstr_w(tmp_file));
1490 if (!strchrW(tmp_file,'.'))
1492 static const WCHAR dot[]={'.',0};
1493 strcatW(tmp_file,dot);
1496 info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) );
1497 msiobj_addref( &package->hdr );
1498 info->package = package;
1499 info->target = dupstrW(target);
1500 info->source = dupstrW(tmp_file);
1502 ThreadHandle = CreateThread(NULL,0,DllThread,(LPVOID)info,0,&ThreadId);
1505 WaitForSingleObject(ThreadHandle,INFINITE);
1507 CloseHandle(ThreadHandle);
1509 return ERROR_SUCCESS;
1512 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
1513 const LPWSTR target, const INT type)
1515 WCHAR tmp_file[MAX_PATH];
1517 PROCESS_INFORMATION info;
1522 static const WCHAR spc[] = {' ',0};
1524 memset(&si,0,sizeof(STARTUPINFOW));
1526 store_binary_to_temp(package, source, tmp_file);
1528 deformat_string(package,target,&deformated);
1530 len = strlenW(tmp_file)+2;
1533 len += strlenW(deformated);
1535 cmd = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*len);
1537 strcpyW(cmd,tmp_file);
1541 strcatW(cmd,deformated);
1543 HeapFree(GetProcessHeap(),0,deformated);
1546 TRACE("executing exe %s \n",debugstr_w(cmd));
1548 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1549 c_collen, &si, &info);
1551 HeapFree(GetProcessHeap(),0,cmd);
1555 ERR("Unable to execute command\n");
1556 return ERROR_SUCCESS;
1560 WaitForSingleObject(info.hProcess,INFINITE);
1562 CloseHandle( info.hProcess );
1563 CloseHandle( info.hThread );
1564 return ERROR_SUCCESS;
1567 static UINT HANDLE_CustomType18(MSIPACKAGE *package, const LPWSTR source,
1568 const LPWSTR target, const INT type)
1571 PROCESS_INFORMATION info;
1576 static const WCHAR spc[] = {' ',0};
1579 memset(&si,0,sizeof(STARTUPINFOW));
1581 index = get_loaded_file(package,source);
1583 len = strlenW(package->files[index].TargetPath);
1585 deformat_string(package,target,&deformated);
1587 len += strlenW(deformated);
1590 cmd = (WCHAR*)HeapAlloc(GetProcessHeap(),0,len * sizeof(WCHAR));
1592 strcpyW(cmd, package->files[index].TargetPath);
1596 strcatW(cmd, deformated);
1598 HeapFree(GetProcessHeap(),0,deformated);
1601 TRACE("executing exe %s \n",debugstr_w(cmd));
1603 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1604 c_collen, &si, &info);
1606 HeapFree(GetProcessHeap(),0,cmd);
1610 ERR("Unable to execute command\n");
1611 return ERROR_SUCCESS;
1615 WaitForSingleObject(info.hProcess,INFINITE);
1617 CloseHandle( info.hProcess );
1618 CloseHandle( info.hThread );
1619 return ERROR_SUCCESS;
1622 static UINT HANDLE_CustomType50(MSIPACKAGE *package, const LPWSTR source,
1623 const LPWSTR target, const INT type)
1626 PROCESS_INFORMATION info;
1633 static const WCHAR spc[] = {' ',0};
1635 memset(&si,0,sizeof(STARTUPINFOW));
1636 memset(&info,0,sizeof(PROCESS_INFORMATION));
1638 prop = load_dynamic_property(package,source,&prc);
1642 deformat_string(package,target,&deformated);
1643 len = strlenW(prop) + 2;
1645 len += strlenW(deformated);
1647 cmd = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*len);
1653 strcatW(cmd,deformated);
1655 HeapFree(GetProcessHeap(),0,deformated);
1658 TRACE("executing exe %s \n",debugstr_w(cmd));
1660 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1661 c_collen, &si, &info);
1663 HeapFree(GetProcessHeap(),0,cmd);
1667 ERR("Unable to execute command\n");
1668 return ERROR_SUCCESS;
1672 WaitForSingleObject(info.hProcess,INFINITE);
1674 CloseHandle( info.hProcess );
1675 CloseHandle( info.hThread );
1676 return ERROR_SUCCESS;
1679 static UINT HANDLE_CustomType34(MSIPACKAGE *package, const LPWSTR source,
1680 const LPWSTR target, const INT type)
1682 LPWSTR filename, deformated;
1684 PROCESS_INFORMATION info;
1687 memset(&si,0,sizeof(STARTUPINFOW));
1689 filename = resolve_folder(package, source, FALSE, FALSE, NULL);
1692 return ERROR_FUNCTION_FAILED;
1694 SetCurrentDirectoryW(filename);
1695 HeapFree(GetProcessHeap(),0,filename);
1697 deformat_string(package,target,&deformated);
1700 return ERROR_FUNCTION_FAILED;
1702 TRACE("executing exe %s \n",debugstr_w(deformated));
1704 rc = CreateProcessW(NULL, deformated, NULL, NULL, FALSE, 0, NULL,
1705 c_collen, &si, &info);
1706 HeapFree(GetProcessHeap(),0,deformated);
1710 ERR("Unable to execute command\n");
1711 return ERROR_SUCCESS;
1715 WaitForSingleObject(info.hProcess,INFINITE);
1717 CloseHandle( info.hProcess );
1718 CloseHandle( info.hThread );
1719 return ERROR_SUCCESS;
1722 /***********************************************************************
1725 * Recursively create all directories in the path.
1727 * shamelessly stolen from setupapi/queue.c
1729 static BOOL create_full_pathW(const WCHAR *path)
1735 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1738 strcpyW(new_path, path);
1740 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1741 new_path[len - 1] = 0;
1743 while(!CreateDirectoryW(new_path, NULL))
1746 DWORD last_error = GetLastError();
1747 if(last_error == ERROR_ALREADY_EXISTS)
1750 if(last_error != ERROR_PATH_NOT_FOUND)
1756 if(!(slash = strrchrW(new_path, '\\')))
1762 len = slash - new_path;
1764 if(!create_full_pathW(new_path))
1769 new_path[len] = '\\';
1772 HeapFree(GetProcessHeap(), 0, new_path);
1777 * Also we cannot enable/disable components either, so for now I am just going
1778 * to do all the directories for all the components.
1780 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1782 static const WCHAR ExecSeqQuery[] = {
1783 's','e','l','e','c','t',' ','D','i','r','e','c','t','o','r','y','_',' ',
1784 'f','r','o','m',' ','C','r','e','a','t','e','F','o','l','d','e','r',0 };
1789 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1790 if (rc != ERROR_SUCCESS)
1791 return ERROR_SUCCESS;
1793 rc = MSI_ViewExecute(view, 0);
1794 if (rc != ERROR_SUCCESS)
1796 MSI_ViewClose(view);
1797 msiobj_release(&view->hdr);
1806 MSIRECORD *row = NULL, *uirow;
1808 rc = MSI_ViewFetch(view,&row);
1809 if (rc != ERROR_SUCCESS)
1816 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1818 if (rc!= ERROR_SUCCESS)
1820 ERR("Unable to get folder id \n");
1821 msiobj_release(&row->hdr);
1826 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
1829 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1830 msiobj_release(&row->hdr);
1834 TRACE("Folder is %s\n",debugstr_w(full_path));
1837 uirow = MSI_CreateRecord(1);
1838 MSI_RecordSetStringW(uirow,1,full_path);
1839 ui_actiondata(package,szCreateFolders,uirow);
1840 msiobj_release( &uirow->hdr );
1842 if (folder->State == 0)
1843 create_full_pathW(full_path);
1847 msiobj_release(&row->hdr);
1848 HeapFree(GetProcessHeap(),0,full_path);
1850 MSI_ViewClose(view);
1851 msiobj_release(&view->hdr);
1856 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1858 int index = package->loaded_components;
1861 /* fill in the data */
1863 package->loaded_components++;
1864 if (package->loaded_components == 1)
1865 package->components = HeapAlloc(GetProcessHeap(),0,
1866 sizeof(MSICOMPONENT));
1868 package->components = HeapReAlloc(GetProcessHeap(),0,
1869 package->components, package->loaded_components *
1870 sizeof(MSICOMPONENT));
1872 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1875 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1877 TRACE("Loading Component %s\n",
1878 debugstr_w(package->components[index].Component));
1881 if (!MSI_RecordIsNull(row,2))
1882 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1885 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1887 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1890 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1893 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1895 package->components[index].Installed = INSTALLSTATE_ABSENT;
1896 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1897 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1899 package->components[index].Enabled = TRUE;
1904 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1906 int index = package->loaded_features;
1908 static const WCHAR Query1[] = {'S','E','L','E','C','T',' ','C','o','m','p',
1909 'o','n','e','n','t','_',' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1910 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ','F','e',
1911 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1912 static const WCHAR Query2[] = {'S','E','L','E','C','T',' ','*',' ','F','R',
1913 'O','M',' ','C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ','C',
1914 'o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1921 /* fill in the data */
1923 package->loaded_features ++;
1924 if (package->loaded_features == 1)
1925 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1927 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1928 package->loaded_features * sizeof(MSIFEATURE));
1930 memset(&package->features[index],0,sizeof(MSIFEATURE));
1933 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1935 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1938 if (!MSI_RecordIsNull(row,2))
1939 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1942 if (!MSI_RecordIsNull(row,3))
1943 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1946 if (!MSI_RecordIsNull(row,4))
1947 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1949 if (!MSI_RecordIsNull(row,5))
1950 package->features[index].Display = MSI_RecordGetInteger(row,5);
1952 package->features[index].Level= MSI_RecordGetInteger(row,6);
1955 if (!MSI_RecordIsNull(row,7))
1956 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1958 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1960 package->features[index].Installed = INSTALLSTATE_ABSENT;
1961 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1962 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1964 /* load feature components */
1966 rc = ACTION_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1967 if (rc != ERROR_SUCCESS)
1969 rc = MSI_ViewExecute(view,0);
1970 if (rc != ERROR_SUCCESS)
1972 MSI_ViewClose(view);
1973 msiobj_release(&view->hdr);
1979 WCHAR buffer[0x100];
1982 INT cnt = package->features[index].ComponentCount;
1984 rc = MSI_ViewFetch(view,&row2);
1985 if (rc != ERROR_SUCCESS)
1989 MSI_RecordGetStringW(row2,1,buffer,&sz);
1991 /* check to see if the component is already loaded */
1992 c_indx = get_loaded_component(package,buffer);
1995 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1997 package->features[index].Components[cnt] = c_indx;
1998 package->features[index].ComponentCount ++;
2002 rc = ACTION_OpenQuery(package->db, &view2, Query2, buffer);
2003 if (rc != ERROR_SUCCESS)
2005 msiobj_release( &row2->hdr );
2008 rc = MSI_ViewExecute(view2,0);
2009 if (rc != ERROR_SUCCESS)
2011 msiobj_release( &row2->hdr );
2012 MSI_ViewClose(view2);
2013 msiobj_release( &view2->hdr );
2020 rc = MSI_ViewFetch(view2,&row3);
2021 if (rc != ERROR_SUCCESS)
2023 c_indx = load_component(package,row3);
2024 msiobj_release( &row3->hdr );
2026 package->features[index].Components[cnt] = c_indx;
2027 package->features[index].ComponentCount ++;
2028 TRACE("Loaded new component to index %i\n",c_indx);
2030 MSI_ViewClose(view2);
2031 msiobj_release( &view2->hdr );
2032 msiobj_release( &row2->hdr );
2034 MSI_ViewClose(view);
2035 msiobj_release(&view->hdr);
2039 * I am not doing any of the costing functionality yet.
2040 * Mostly looking at doing the Component and Feature loading
2042 * The native MSI does ALOT of modification to tables here. Mostly adding alot
2043 * of temporary columns to the Feature and Component tables.
2045 * note: native msi also tracks the short filename. but I am only going to
2046 * track the long ones. Also looking at this directory table
2047 * it appears that the directory table does not get the parents
2048 * resolved base on property only based on their entrys in the
2051 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
2056 static const WCHAR Query_all[] = {
2057 'S','E','L','E','C','T',' ','*',' ',
2058 'F','R','O','M',' ','F','e','a','t','u','r','e',0};
2059 static const WCHAR szCosting[] = {
2060 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2061 static const WCHAR szZero[] = { '0', 0 };
2063 MSI_SetPropertyW(package, szCosting, szZero);
2064 MSI_SetPropertyW(package, cszRootDrive , c_collen);
2066 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
2067 if (rc != ERROR_SUCCESS)
2069 rc = MSI_ViewExecute(view,0);
2070 if (rc != ERROR_SUCCESS)
2072 MSI_ViewClose(view);
2073 msiobj_release(&view->hdr);
2080 rc = MSI_ViewFetch(view,&row);
2081 if (rc != ERROR_SUCCESS)
2084 load_feature(package,row);
2085 msiobj_release(&row->hdr);
2087 MSI_ViewClose(view);
2088 msiobj_release(&view->hdr);
2090 return ERROR_SUCCESS;
2093 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
2095 DWORD index = package->loaded_files;
2099 /* fill in the data */
2101 package->loaded_files++;
2102 if (package->loaded_files== 1)
2103 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
2105 package->files = HeapReAlloc(GetProcessHeap(),0,
2106 package->files , package->loaded_files * sizeof(MSIFILE));
2108 memset(&package->files[index],0,sizeof(MSIFILE));
2110 package->files[index].File = load_dynamic_stringW(row, 1);
2111 buffer = load_dynamic_stringW(row, 2);
2113 package->files[index].ComponentIndex = -1;
2114 for (i = 0; i < package->loaded_components; i++)
2115 if (strcmpW(package->components[i].Component,buffer)==0)
2117 package->files[index].ComponentIndex = i;
2120 if (package->files[index].ComponentIndex == -1)
2121 ERR("Unfound Component %s\n",debugstr_w(buffer));
2122 HeapFree(GetProcessHeap(), 0, buffer);
2124 package->files[index].FileName = load_dynamic_stringW(row,3);
2126 reduce_to_longfilename(package->files[index].FileName);
2128 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
2129 package->files[index].Version = load_dynamic_stringW(row, 5);
2130 package->files[index].Language = load_dynamic_stringW(row, 6);
2131 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
2132 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
2134 package->files[index].Temporary = FALSE;
2135 package->files[index].State = 0;
2137 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
2139 return ERROR_SUCCESS;
2142 static UINT ACTION_FileCost(MSIPACKAGE *package)
2147 static const WCHAR Query[] = {
2148 'S','E','L','E','C','T',' ','*',' ',
2149 'F','R','O','M',' ','F','i','l','e',' ',
2150 'O','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e', 0};
2153 return ERROR_INVALID_HANDLE;
2155 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2156 if (rc != ERROR_SUCCESS)
2157 return ERROR_SUCCESS;
2159 rc = MSI_ViewExecute(view, 0);
2160 if (rc != ERROR_SUCCESS)
2162 MSI_ViewClose(view);
2163 msiobj_release(&view->hdr);
2164 return ERROR_SUCCESS;
2169 rc = MSI_ViewFetch(view,&row);
2170 if (rc != ERROR_SUCCESS)
2175 load_file(package,row);
2176 msiobj_release(&row->hdr);
2178 MSI_ViewClose(view);
2179 msiobj_release(&view->hdr);
2181 return ERROR_SUCCESS;
2184 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
2187 static const WCHAR Query[] =
2188 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','D','i','r','e','c',
2189 't','o','r','y',' ','w','h','e','r','e',' ','`','D','i','r','e','c','t',
2190 'o','r','y','`',' ','=',' ','`','%','s','`',0};
2193 LPWSTR targetdir, parent, srcdir;
2194 MSIRECORD * row = 0;
2198 TRACE("Looking for dir %s\n",debugstr_w(dir));
2200 for (i = 0; i < package->loaded_folders; i++)
2202 if (strcmpW(package->folders[i].Directory,dir)==0)
2204 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
2209 TRACE("Working to load %s\n",debugstr_w(dir));
2211 index = package->loaded_folders++;
2212 if (package->loaded_folders==1)
2213 package->folders = HeapAlloc(GetProcessHeap(),0,
2216 package->folders= HeapReAlloc(GetProcessHeap(),0,
2217 package->folders, package->loaded_folders*
2220 memset(&package->folders[index],0,sizeof(MSIFOLDER));
2222 package->folders[index].Directory = dupstrW(dir);
2224 rc = ACTION_OpenQuery(package->db, &view, Query, dir);
2225 if (rc != ERROR_SUCCESS)
2228 rc = MSI_ViewExecute(view, 0);
2229 if (rc != ERROR_SUCCESS)
2231 MSI_ViewClose(view);
2232 msiobj_release(&view->hdr);
2236 rc = MSI_ViewFetch(view,&row);
2237 if (rc != ERROR_SUCCESS)
2239 MSI_ViewClose(view);
2240 msiobj_release(&view->hdr);
2244 targetdir = load_dynamic_stringW(row,3);
2246 /* split src and target dir */
2247 if (strchrW(targetdir,':'))
2249 srcdir=strchrW(targetdir,':');
2256 /* for now only pick long filename versions */
2257 if (strchrW(targetdir,'|'))
2259 targetdir = strchrW(targetdir,'|');
2263 if (srcdir && strchrW(srcdir,'|'))
2265 srcdir= strchrW(srcdir,'|');
2270 /* now check for root dirs */
2271 if (targetdir[0] == '.' && targetdir[1] == 0)
2274 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
2279 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
2280 if (package->folders[index].TargetDefault)
2281 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
2282 package->folders[index].TargetDefault = dupstrW(targetdir);
2286 package->folders[index].SourceDefault = dupstrW(srcdir);
2288 package->folders[index].SourceDefault = dupstrW(targetdir);
2289 HeapFree(GetProcessHeap(), 0, targetdir);
2291 parent = load_dynamic_stringW(row,2);
2294 i = load_folder(package,parent);
2295 package->folders[index].ParentIndex = i;
2296 TRACE("Parent is index %i... %s %s\n",
2297 package->folders[index].ParentIndex,
2298 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
2299 debugstr_w(parent));
2302 package->folders[index].ParentIndex = -2;
2303 HeapFree(GetProcessHeap(), 0, parent);
2305 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
2307 msiobj_release(&row->hdr);
2308 MSI_ViewClose(view);
2309 msiobj_release(&view->hdr);
2310 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
2315 static LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name,
2316 BOOL source, BOOL set_prop, MSIFOLDER **folder)
2319 LPWSTR p, path = NULL;
2321 TRACE("Working to resolve %s\n",debugstr_w(name));
2323 /* special resolving for Target and Source root dir */
2324 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
2328 path = load_dynamic_property(package,cszTargetDir,NULL);
2331 path = load_dynamic_property(package,cszRootDrive,NULL);
2333 MSI_SetPropertyW(package,cszTargetDir,path);
2337 for (i = 0; i < package->loaded_folders; i++)
2339 if (strcmpW(package->folders[i].Directory,name)==0)
2342 *folder = &(package->folders[i]);
2348 path = load_dynamic_property(package,cszSourceDir,NULL);
2351 path = load_dynamic_property(package,cszDatabase,NULL);
2354 p = strrchrW(path,'\\');
2361 for (i = 0; i < package->loaded_folders; i++)
2363 if (strcmpW(package->folders[i].Directory,name)==0)
2366 *folder = &(package->folders[i]);
2372 for (i = 0; i < package->loaded_folders; i++)
2374 if (strcmpW(package->folders[i].Directory,name)==0)
2378 if (i >= package->loaded_folders)
2382 *folder = &(package->folders[i]);
2384 if (!source && package->folders[i].ResolvedTarget)
2386 path = dupstrW(package->folders[i].ResolvedTarget);
2387 TRACE(" already resolved to %s\n",debugstr_w(path));
2390 else if (source && package->folders[i].ResolvedSource)
2392 path = dupstrW(package->folders[i].ResolvedSource);
2395 else if (!source && package->folders[i].Property)
2397 path = dupstrW(package->folders[i].Property);
2398 TRACE(" internally set to %s\n",debugstr_w(path));
2400 MSI_SetPropertyW(package,name,path);
2404 if (package->folders[i].ParentIndex >= 0)
2406 LPWSTR parent = package->folders[package->folders[i].ParentIndex].Directory;
2408 TRACE(" ! Parent is %s\n", debugstr_w(parent));
2410 p = resolve_folder(package, parent, source, set_prop, NULL);
2413 TRACE(" TargetDefault = %s\n",debugstr_w(package->folders[i].TargetDefault));
2414 path = build_directory_name(3, p, package->folders[i].TargetDefault, NULL);
2415 package->folders[i].ResolvedTarget = dupstrW(path);
2416 TRACE(" resolved into %s\n",debugstr_w(path));
2418 MSI_SetPropertyW(package,name,path);
2422 path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
2423 package->folders[i].ResolvedSource = dupstrW(path);
2425 HeapFree(GetProcessHeap(),0,p);
2430 static UINT SetFeatureStates(MSIPACKAGE *package)
2436 LPWSTR override = NULL;
2437 static const WCHAR all[]={'A','L','L',0};
2438 static const WCHAR szlevel[] = {
2439 'I','N','S','T','A','L','L','L','E','V','E','L',0};
2440 static const WCHAR szAddLocal[] = {
2441 'A','D','D','L','O','C','A','L',0};
2443 /* I do not know if this is where it should happen.. but */
2445 TRACE("Checking Install Level\n");
2447 level = load_dynamic_property(package,szlevel,NULL);
2450 install_level = atoiW(level);
2451 HeapFree(GetProcessHeap(), 0, level);
2456 /* ok hereis the rub
2457 * ADDLOCAL and its friend OVERRIDE INSTALLLEVLE
2458 * I have confirmed this if ADDLOCALis stated then the INSTALLLEVEL is
2459 * itnored for all the features. seems strange, epsecially since it is not
2460 * documented anywhere, but it is how it works.
2463 override = load_dynamic_property(package,szAddLocal,NULL);
2467 for(i = 0; i < package->loaded_features; i++)
2469 if (strcmpiW(override,all)==0)
2471 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2472 package->features[i].Action = INSTALLSTATE_LOCAL;
2476 LPWSTR ptr = override;
2477 LPWSTR ptr2 = strchrW(override,',');
2482 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
2484 strcmpW(ptr,package->features[i].Feature)==0))
2486 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2487 package->features[i].Action = INSTALLSTATE_LOCAL;
2493 ptr2 = strchrW(ptr,',');
2500 HeapFree(GetProcessHeap(),0,override);
2504 for(i = 0; i < package->loaded_features; i++)
2506 BOOL feature_state= ((package->features[i].Level > 0) &&
2507 (package->features[i].Level <= install_level));
2511 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2512 package->features[i].Action = INSTALLSTATE_LOCAL;
2518 * now we want to enable or disable components base on feature
2521 for(i = 0; i < package->loaded_features; i++)
2523 MSIFEATURE* feature = &package->features[i];
2524 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2525 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2526 feature->ActionRequest);
2528 for( j = 0; j < feature->ComponentCount; j++)
2530 MSICOMPONENT* component = &package->components[
2531 feature->Components[j]];
2533 if (!component->Enabled)
2535 component->Action = INSTALLSTATE_ABSENT;
2536 component->ActionRequest = INSTALLSTATE_ABSENT;
2540 if (feature->Action == INSTALLSTATE_LOCAL)
2541 component->Action = INSTALLSTATE_LOCAL;
2542 if (feature->ActionRequest == INSTALLSTATE_LOCAL)
2543 component->ActionRequest = INSTALLSTATE_LOCAL;
2548 for(i = 0; i < package->loaded_components; i++)
2550 MSICOMPONENT* component= &package->components[i];
2552 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2553 debugstr_w(component->Component), component->Installed,
2554 component->Action, component->ActionRequest);
2558 return ERROR_SUCCESS;
2562 * Alot is done in this function aside from just the costing.
2563 * The costing needs to be implemented at some point but for now I am going
2564 * to focus on the directory building
2567 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2569 static const WCHAR ExecSeqQuery[] = {
2570 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2571 'D','i','r','e','c','t','o','r','y',0};
2572 static const WCHAR ConditionQuery[] = {
2573 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2574 'C','o','n','d','i','t','i','o','n',0};
2575 static const WCHAR szCosting[] = {
2576 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2577 static const WCHAR szlevel[] = {
2578 'I','N','S','T','A','L','L','L','E','V','E','L',0};
2579 static const WCHAR szOne[] = { '1', 0 };
2585 TRACE("Building Directory properties\n");
2587 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2588 if (rc == ERROR_SUCCESS)
2590 rc = MSI_ViewExecute(view, 0);
2591 if (rc != ERROR_SUCCESS)
2593 MSI_ViewClose(view);
2594 msiobj_release(&view->hdr);
2602 MSIRECORD * row = 0;
2605 rc = MSI_ViewFetch(view,&row);
2606 if (rc != ERROR_SUCCESS)
2613 MSI_RecordGetStringW(row,1,name,&sz);
2615 /* This helper function now does ALL the work */
2616 TRACE("Dir %s ...\n",debugstr_w(name));
2617 load_folder(package,name);
2618 path = resolve_folder(package,name,FALSE,TRUE,NULL);
2619 TRACE("resolves to %s\n",debugstr_w(path));
2620 HeapFree( GetProcessHeap(), 0, path);
2622 msiobj_release(&row->hdr);
2624 MSI_ViewClose(view);
2625 msiobj_release(&view->hdr);
2628 TRACE("File calculations %i files\n",package->loaded_files);
2630 for (i = 0; i < package->loaded_files; i++)
2632 MSICOMPONENT* comp = NULL;
2633 MSIFILE* file= NULL;
2635 file = &package->files[i];
2636 if (file->ComponentIndex >= 0)
2637 comp = &package->components[file->ComponentIndex];
2639 if (file->Temporary == TRUE)
2646 /* calculate target */
2647 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
2649 if (file->TargetPath)
2650 HeapFree(GetProcessHeap(),0,file->TargetPath);
2652 TRACE("file %s is named %s\n",
2653 debugstr_w(file->File),debugstr_w(file->FileName));
2655 file->TargetPath = build_directory_name(2, p, file->FileName);
2657 HeapFree(GetProcessHeap(),0,p);
2659 TRACE("file %s resolves to %s\n",
2660 debugstr_w(file->File),debugstr_w(file->TargetPath));
2662 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2665 comp->Cost += file->FileSize;
2675 static const WCHAR name[] =
2677 static const WCHAR name_fmt[] =
2678 {'%','u','.','%','u','.','%','u','.','%','u',0};
2679 WCHAR filever[0x100];
2680 VS_FIXEDFILEINFO *lpVer;
2682 FIXME("Version comparison.. \n");
2683 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2684 version = HeapAlloc(GetProcessHeap(),0,versize);
2685 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2687 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2689 sprintfW(filever,name_fmt,
2690 HIWORD(lpVer->dwFileVersionMS),
2691 LOWORD(lpVer->dwFileVersionMS),
2692 HIWORD(lpVer->dwFileVersionLS),
2693 LOWORD(lpVer->dwFileVersionLS));
2695 TRACE("new %s old %s\n", debugstr_w(file->Version),
2696 debugstr_w(filever));
2697 if (strcmpiW(filever,file->Version)<0)
2700 FIXME("cost should be diff in size\n");
2701 comp->Cost += file->FileSize;
2705 HeapFree(GetProcessHeap(),0,version);
2713 TRACE("Evaluating Condition Table\n");
2715 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2716 if (rc == ERROR_SUCCESS)
2718 rc = MSI_ViewExecute(view, 0);
2719 if (rc != ERROR_SUCCESS)
2721 MSI_ViewClose(view);
2722 msiobj_release(&view->hdr);
2728 WCHAR Feature[0x100];
2729 MSIRECORD * row = 0;
2733 rc = MSI_ViewFetch(view,&row);
2735 if (rc != ERROR_SUCCESS)
2742 MSI_RecordGetStringW(row,1,Feature,&sz);
2744 feature_index = get_loaded_feature(package,Feature);
2745 if (feature_index < 0)
2746 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2750 Condition = load_dynamic_stringW(row,3);
2752 if (MSI_EvaluateConditionW(package,Condition) ==
2755 int level = MSI_RecordGetInteger(row,2);
2756 TRACE("Reseting feature %s to level %i\n",
2757 debugstr_w(Feature), level);
2758 package->features[feature_index].Level = level;
2760 HeapFree(GetProcessHeap(),0,Condition);
2763 msiobj_release(&row->hdr);
2765 MSI_ViewClose(view);
2766 msiobj_release(&view->hdr);
2769 TRACE("Enabling or Disabling Components\n");
2770 for (i = 0; i < package->loaded_components; i++)
2772 if (package->components[i].Condition[0])
2774 if (MSI_EvaluateConditionW(package,
2775 package->components[i].Condition) == MSICONDITION_FALSE)
2777 TRACE("Disabling component %s\n",
2778 debugstr_w(package->components[i].Component));
2779 package->components[i].Enabled = FALSE;
2784 MSI_SetPropertyW(package,szCosting,szOne);
2785 /* set default run level if not set */
2786 level = load_dynamic_property(package,szlevel,NULL);
2788 MSI_SetPropertyW(package,szlevel, szOne);
2790 HeapFree(GetProcessHeap(),0,level);
2792 return SetFeatureStates(package);
2797 * This is a helper function for handling embedded cabinet media
2799 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2807 WCHAR tmp[MAX_PATH];
2809 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2810 if (rc != ERROR_SUCCESS)
2814 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2815 GetTempPathW(MAX_PATH,tmp);
2817 GetTempFileNameW(tmp,stream_name,0,source);
2819 track_tempfile(package,strrchrW(source,'\\'), source);
2820 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2821 FILE_ATTRIBUTE_NORMAL, NULL);
2823 if (the_file == INVALID_HANDLE_VALUE)
2825 rc = ERROR_FUNCTION_FAILED;
2829 WriteFile(the_file,data,size,&write,NULL);
2830 CloseHandle(the_file);
2831 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2833 HeapFree(GetProcessHeap(),0,data);
2838 /* Support functions for FDI functions */
2841 MSIPACKAGE* package;
2846 static void * cabinet_alloc(ULONG cb)
2848 return HeapAlloc(GetProcessHeap(), 0, cb);
2851 static void cabinet_free(void *pv)
2853 HeapFree(GetProcessHeap(), 0, pv);
2856 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2859 DWORD dwShareMode = 0;
2860 DWORD dwCreateDisposition = OPEN_EXISTING;
2861 switch (oflag & _O_ACCMODE)
2864 dwAccess = GENERIC_READ;
2865 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2868 dwAccess = GENERIC_WRITE;
2869 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2872 dwAccess = GENERIC_READ | GENERIC_WRITE;
2873 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2876 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2877 dwCreateDisposition = CREATE_NEW;
2878 else if (oflag & _O_CREAT)
2879 dwCreateDisposition = CREATE_ALWAYS;
2880 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL, dwCreateDisposition, 0, NULL);
2883 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2886 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2891 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2894 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2899 static int cabinet_close(INT_PTR hf)
2901 return CloseHandle((HANDLE)hf) ? 0 : -1;
2904 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2906 /* flags are compatible and so are passed straight through */
2907 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2910 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2912 /* FIXME: try to do more processing in this function */
2915 case fdintCOPY_FILE:
2917 CabData *data = (CabData*) pfdin->pv;
2918 ULONG len = strlen(data->cab_path) + strlen(pfdin->psz1);
2923 LPWSTR tracknametmp;
2924 static const WCHAR tmpprefix[] = {'C','A','B','T','M','P','_',0};
2926 if (data->file_name && strcmp(data->file_name,pfdin->psz1))
2929 file = cabinet_alloc((len+1)*sizeof(char));
2930 strcpy(file, data->cab_path);
2931 strcat(file, pfdin->psz1);
2933 TRACE("file: %s\n", debugstr_a(file));
2935 /* track this file so it can be deleted if not installed */
2936 trackpath=strdupAtoW(file);
2937 tracknametmp=strdupAtoW(strrchr(file,'\\')+1);
2938 trackname = HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp) +
2939 strlenW(tmpprefix)+1) * sizeof(WCHAR));
2941 strcpyW(trackname,tmpprefix);
2942 strcatW(trackname,tracknametmp);
2944 track_tempfile(data->package, trackname, trackpath);
2946 HeapFree(GetProcessHeap(),0,trackpath);
2947 HeapFree(GetProcessHeap(),0,trackname);
2948 HeapFree(GetProcessHeap(),0,tracknametmp);
2950 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2952 case fdintCLOSE_FILE_INFO:
2956 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2958 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2960 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2963 cabinet_close(pfdin->hf);
2971 /***********************************************************************
2972 * extract_cabinet_file
2974 * Extract files from a cab file.
2976 static BOOL extract_a_cabinet_file(MSIPACKAGE* package, const WCHAR* source,
2977 const WCHAR* path, const WCHAR* file)
2987 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source),
2988 debugstr_w(file), debugstr_w(path));
2990 hfdi = FDICreate(cabinet_alloc,
3001 ERR("FDICreate failed\n");
3005 if (!(cabinet = strdupWtoA( source )))
3010 if (!(cab_path = strdupWtoA( path )))
3013 HeapFree(GetProcessHeap(), 0, cabinet);
3017 data.package = package;
3018 data.cab_path = cab_path;
3019 file_name = strdupWtoA(file);
3020 data.file_name = file_name;
3022 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, &data);
3025 ERR("FDICopy failed\n");
3029 HeapFree(GetProcessHeap(), 0, cabinet);
3030 HeapFree(GetProcessHeap(), 0, cab_path);
3031 HeapFree(GetProcessHeap(), 0, file_name);
3036 static UINT ready_media_for_file(MSIPACKAGE *package, UINT sequence,
3037 WCHAR* path, WCHAR* file)
3041 MSIRECORD * row = 0;
3042 static WCHAR source[MAX_PATH];
3043 static const WCHAR ExecSeqQuery[] = {
3044 's','e','l','e','c','t',' ','*',' ',
3045 'f','r','o','m',' ','M','e','d','i','a',' ',
3046 'w','h','e','r','e',' ','L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%','i',' ',
3047 'o','r','d','e','r',' ','b','y',' ','L','a','s','t','S','e','q','u','e','n','c','e',0};
3052 static UINT last_sequence = 0;
3054 if (sequence <= last_sequence)
3056 TRACE("Media already ready (%u, %u)\n",sequence,last_sequence);
3057 extract_a_cabinet_file(package, source,path,file);
3058 return ERROR_SUCCESS;
3061 sprintfW(Query,ExecSeqQuery,sequence);
3063 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3064 if (rc != ERROR_SUCCESS)
3067 rc = MSI_ViewExecute(view, 0);
3068 if (rc != ERROR_SUCCESS)
3070 MSI_ViewClose(view);
3071 msiobj_release(&view->hdr);
3075 rc = MSI_ViewFetch(view,&row);
3076 if (rc != ERROR_SUCCESS)
3078 MSI_ViewClose(view);
3079 msiobj_release(&view->hdr);
3082 seq = MSI_RecordGetInteger(row,2);
3083 last_sequence = seq;
3085 if (!MSI_RecordIsNull(row,4))
3088 MSI_RecordGetStringW(row,4,cab,&sz);
3089 TRACE("Source is CAB %s\n",debugstr_w(cab));
3090 /* the stream does not contain the # character */
3093 writeout_cabinet_stream(package,&cab[1],source);
3094 strcpyW(path,source);
3095 *(strrchrW(path,'\\')+1)=0;
3100 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
3102 ERR("No Source dir defined \n");
3103 rc = ERROR_FUNCTION_FAILED;
3107 strcpyW(path,source);
3108 strcatW(source,cab);
3109 /* extract the cab file into a folder in the temp folder */
3111 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
3113 GetTempPathW(MAX_PATH,path);
3116 rc = !extract_a_cabinet_file(package, source,path,file);
3118 msiobj_release(&row->hdr);
3119 MSI_ViewClose(view);
3120 msiobj_release(&view->hdr);
3124 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
3128 LPWSTR install_path;
3130 install_path = resolve_folder(package, package->components[component].Directory,
3131 FALSE, FALSE, &folder);
3133 return ERROR_FUNCTION_FAILED;
3135 /* create the path */
3136 if (folder->State == 0)
3138 create_full_pathW(install_path);
3141 HeapFree(GetProcessHeap(), 0, install_path);
3146 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
3148 UINT rc = ERROR_SUCCESS;
3151 WCHAR uipath[MAX_PATH];
3154 return ERROR_INVALID_HANDLE;
3156 /* increment progress bar each time action data is sent */
3157 ui_progress(package,1,1,0,0);
3159 for (index = 0; index < package->loaded_files; index++)
3161 WCHAR path_to_source[MAX_PATH];
3164 file = &package->files[index];
3166 if (file->Temporary)
3169 if (package->components[file->ComponentIndex].ActionRequest !=
3172 ui_progress(package,2,file->FileSize,0,0);
3173 TRACE("File %s is not scheduled for install\n",
3174 debugstr_w(file->File));
3179 if ((file->State == 1) || (file->State == 2))
3183 MSICOMPONENT* comp = NULL;
3185 TRACE("Installing %s\n",debugstr_w(file->File));
3186 rc = ready_media_for_file(package,file->Sequence,path_to_source,
3190 * our file table could change here because a new temp file
3191 * may have been created
3193 file = &package->files[index];
3194 if (rc != ERROR_SUCCESS)
3196 ERR("Unable to ready media\n");
3197 rc = ERROR_FUNCTION_FAILED;
3201 create_component_directory( package, file->ComponentIndex);
3203 /* recalculate file paths because things may have changed */
3205 if (file->ComponentIndex >= 0)
3206 comp = &package->components[file->ComponentIndex];
3208 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
3209 if (file->TargetPath)
3210 HeapFree(GetProcessHeap(),0,file->TargetPath);
3212 file->TargetPath = build_directory_name(2, p, file->FileName);
3214 len = strlenW(path_to_source) + strlenW(file->File) + 2;
3215 file->SourcePath = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
3216 strcpyW(file->SourcePath, path_to_source);
3217 strcatW(file->SourcePath, file->File);
3219 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
3220 debugstr_w(file->TargetPath));
3223 uirow=MSI_CreateRecord(9);
3224 MSI_RecordSetStringW(uirow,1,file->File);
3225 strcpyW(uipath,file->TargetPath);
3226 *(strrchrW(uipath,'\\')+1)=0;
3227 MSI_RecordSetStringW(uirow,9,uipath);
3228 MSI_RecordSetInteger(uirow,6,file->FileSize);
3229 ui_actiondata(package,szInstallFiles,uirow);
3230 msiobj_release( &uirow->hdr );
3231 ui_progress(package,2,file->FileSize,0,0);
3233 if (!MoveFileW(file->SourcePath,file->TargetPath))
3235 rc = GetLastError();
3236 ERR("Unable to move file (%s -> %s) (error %d)\n",
3237 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
3239 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
3241 CopyFileW(file->SourcePath,file->TargetPath,FALSE);
3242 DeleteFileW(file->SourcePath);
3245 else if (rc == ERROR_FILE_NOT_FOUND)
3247 ERR("Source File Not Found! Continueing\n");
3252 ERR("Ignoring Error and continuing...\n");
3264 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
3265 LPWSTR* file_source)
3270 return ERROR_INVALID_HANDLE;
3272 for (index = 0; index < package->loaded_files; index ++)
3274 if (strcmpW(file_key,package->files[index].File)==0)
3276 if (package->files[index].State >= 3)
3278 *file_source = dupstrW(package->files[index].TargetPath);
3279 return ERROR_SUCCESS;
3282 return ERROR_FILE_NOT_FOUND;
3286 return ERROR_FUNCTION_FAILED;
3289 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
3293 MSIRECORD * row = 0;
3294 static const WCHAR ExecSeqQuery[] = {
3295 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
3296 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
3299 return ERROR_INVALID_HANDLE;
3301 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3302 if (rc != ERROR_SUCCESS)
3303 return ERROR_SUCCESS;
3305 rc = MSI_ViewExecute(view, 0);
3306 if (rc != ERROR_SUCCESS)
3308 MSI_ViewClose(view);
3309 msiobj_release(&view->hdr);
3315 WCHAR file_key[0x100];
3316 WCHAR *file_source = NULL;
3317 WCHAR dest_name[0x100];
3318 LPWSTR dest_path, dest;
3319 WCHAR component[0x100];
3320 INT component_index;
3324 rc = MSI_ViewFetch(view,&row);
3325 if (rc != ERROR_SUCCESS)
3332 rc = MSI_RecordGetStringW(row,2,component,&sz);
3333 if (rc != ERROR_SUCCESS)
3335 ERR("Unable to get component\n");
3336 msiobj_release(&row->hdr);
3340 component_index = get_loaded_component(package,component);
3341 if (package->components[component_index].ActionRequest !=
3344 TRACE("Skipping copy due to disabled component\n");
3345 msiobj_release(&row->hdr);
3350 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
3351 if (rc != ERROR_SUCCESS)
3353 ERR("Unable to get file key\n");
3354 msiobj_release(&row->hdr);
3358 rc = get_file_target(package,file_key,&file_source);
3360 if (rc != ERROR_SUCCESS)
3362 ERR("Original file unknown %s\n",debugstr_w(file_key));
3363 msiobj_release(&row->hdr);
3365 HeapFree(GetProcessHeap(),0,file_source);
3369 if (MSI_RecordIsNull(row,4))
3371 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
3376 MSI_RecordGetStringW(row,4,dest_name,&sz);
3377 reduce_to_longfilename(dest_name);
3380 if (MSI_RecordIsNull(row,5))
3383 dest_path = dupstrW(file_source);
3384 p = strrchrW(dest_path,'\\');
3390 WCHAR destkey[0x100];
3392 MSI_RecordGetStringW(row,5,destkey,&sz);
3394 dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
3397 ERR("Unable to get destination folder\n");
3398 msiobj_release(&row->hdr);
3400 HeapFree(GetProcessHeap(),0,file_source);
3405 dest = build_directory_name(2, dest_path, dest_name);
3406 HeapFree(GetProcessHeap(), 0, dest_path);
3408 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
3411 if (strcmpW(file_source,dest))
3412 rc = !CopyFileW(file_source,dest,TRUE);
3416 if (rc != ERROR_SUCCESS)
3417 ERR("Failed to copy file\n");
3419 FIXME("We should track these duplicate files as well\n");
3421 msiobj_release(&row->hdr);
3422 HeapFree(GetProcessHeap(),0,dest);
3423 HeapFree(GetProcessHeap(),0,file_source);
3425 MSI_ViewClose(view);
3426 msiobj_release(&view->hdr);
3431 /* OK this value is "interpretted" and then formatted based on the
3432 first few characters */
3433 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
3437 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
3446 deformat_string(package, &value[2], &deformated);
3448 /* binary value type */
3451 *size = strlenW(ptr)/2;
3452 data = HeapAlloc(GetProcessHeap(),0,*size);
3464 data[count] = (BYTE)strtol(byte,NULL,0);
3467 HeapFree(GetProcessHeap(),0,deformated);
3469 TRACE("Data %li bytes(%i)\n",*size,count);
3474 deformat_string(package, &value[1], &deformated);
3477 *size = sizeof(DWORD);
3478 data = HeapAlloc(GetProcessHeap(),0,*size);
3479 *(LPDWORD)data = atoiW(deformated);
3480 TRACE("DWORD %i\n",*data);
3482 HeapFree(GetProcessHeap(),0,deformated);
3495 *type=REG_EXPAND_SZ;
3503 *size = deformat_string(package, ptr,(LPWSTR*)&data);
3508 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3512 MSIRECORD * row = 0;
3513 static const WCHAR ExecSeqQuery[] = {
3514 's','e','l','e','c','t',' ','*',' ',
3515 'f','r','o','m',' ','R','e','g','i','s','t','r','y',0 };
3518 return ERROR_INVALID_HANDLE;
3520 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3521 if (rc != ERROR_SUCCESS)
3522 return ERROR_SUCCESS;
3524 rc = MSI_ViewExecute(view, 0);
3525 if (rc != ERROR_SUCCESS)
3527 MSI_ViewClose(view);
3528 msiobj_release(&view->hdr);
3532 /* increment progress bar each time action data is sent */
3533 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
3537 static const WCHAR szHCR[] =
3538 {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T','\\',0};
3539 static const WCHAR szHCU[] =
3540 {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',0};
3541 static const WCHAR szHLM[] =
3542 {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',
3544 static const WCHAR szHU[] =
3545 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3547 LPSTR value_data = NULL;
3548 HKEY root_key, hkey;
3550 LPWSTR value, key, name, component, deformated;
3552 INT component_index;
3557 rc = MSI_ViewFetch(view,&row);
3558 if (rc != ERROR_SUCCESS)
3563 ui_progress(package,2,0,0,0);
3570 component = load_dynamic_stringW(row, 6);
3571 component_index = get_loaded_component(package,component);
3573 if (package->components[component_index].ActionRequest !=
3576 TRACE("Skipping write due to disabled component\n");
3577 msiobj_release(&row->hdr);
3581 /* null values have special meanings during uninstalls and such */
3583 if(MSI_RecordIsNull(row,5))
3585 msiobj_release(&row->hdr);
3589 root = MSI_RecordGetInteger(row,2);
3590 key = load_dynamic_stringW(row, 3);
3592 name = load_dynamic_stringW(row, 4);
3594 /* get the root key */
3597 case 0: root_key = HKEY_CLASSES_ROOT;
3600 case 1: root_key = HKEY_CURRENT_USER;
3603 case 2: root_key = HKEY_LOCAL_MACHINE;
3606 case 3: root_key = HKEY_USERS;
3610 ERR("Unknown root %i\n",root);
3617 msiobj_release(&row->hdr);
3621 deformat_string(package, key , &deformated);
3622 size = strlenW(deformated) + strlenW(szRoot) + 1;
3623 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
3624 strcpyW(uikey,szRoot);
3625 strcatW(uikey,deformated);
3627 if (RegCreateKeyW( root_key, deformated, &hkey))
3629 ERR("Could not create key %s\n",debugstr_w(deformated));
3630 msiobj_release(&row->hdr);
3631 HeapFree(GetProcessHeap(),0,deformated);
3634 HeapFree(GetProcessHeap(),0,deformated);
3636 value = load_dynamic_stringW(row,5);
3637 value_data = parse_value(package, value, &type, &size);
3639 deformat_string(package, name, &deformated);
3643 TRACE("Setting value %s\n",debugstr_w(deformated));
3644 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3646 uirow = MSI_CreateRecord(3);
3647 MSI_RecordSetStringW(uirow,2,deformated);
3648 MSI_RecordSetStringW(uirow,1,uikey);
3651 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3653 MSI_RecordSetStringW(uirow,3,value);
3655 ui_actiondata(package,szWriteRegistryValues,uirow);
3656 msiobj_release( &uirow->hdr );
3658 HeapFree(GetProcessHeap(),0,value_data);
3660 HeapFree(GetProcessHeap(),0,value);
3661 HeapFree(GetProcessHeap(),0,deformated);
3663 msiobj_release(&row->hdr);
3667 HeapFree(GetProcessHeap(),0,uikey);
3669 HeapFree(GetProcessHeap(),0,key);
3671 HeapFree(GetProcessHeap(),0,name);
3673 HeapFree(GetProcessHeap(),0,component);
3675 MSI_ViewClose(view);
3676 msiobj_release(&view->hdr);
3681 * This helper function should probably go alot of places
3683 * Thinking about this, maybe this should become yet another Bison file
3685 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data)
3698 TRACE("Deformatting NULL string\n");
3702 TRACE("Starting with %s\n",debugstr_w(ptr));
3703 /* scan for special characters */
3704 if (!strchrW(ptr,'[') || (strchrW(ptr,'[') && !strchrW(ptr,']')))
3707 size = (strlenW(ptr)+1) * sizeof(WCHAR);
3708 *data = HeapAlloc(GetProcessHeap(),0,size);
3713 /* formatted string located */
3714 mark = strchrW(ptr,'[');
3717 INT cnt = (mark - ptr);
3718 TRACE("%i (%i) characters before marker\n",cnt,(mark-ptr));
3719 size = cnt * sizeof(WCHAR);
3720 size += sizeof(WCHAR);
3721 *data = HeapAlloc(GetProcessHeap(),0,size);
3722 strncpyW(*data,ptr,cnt);
3727 size = sizeof(WCHAR);
3728 *data = HeapAlloc(GetProcessHeap(),0,size);
3732 mark2 = strchrW(mark,']');
3733 strncpyW(key,mark,mark2-mark);
3734 key[mark2-mark] = 0;
3735 mark = strchrW(mark,']');
3737 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3739 rc = MSI_GetPropertyW(package, key, NULL, &sz);
3740 if ((rc == ERROR_SUCCESS) || (rc == ERROR_MORE_DATA))
3745 value = HeapAlloc(GetProcessHeap(),0,sz * sizeof(WCHAR));
3746 MSI_GetPropertyW(package, key, value, &sz);
3748 chunk = (strlenW(value)+1) * sizeof(WCHAR);
3750 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
3752 strcatW(*data,value);
3754 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3758 chunk = (strlenW(mark)+1) * sizeof(WCHAR);
3760 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
3762 strcatW(*data,mark);
3764 (*data)[strlenW(*data)]=0;
3765 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3767 /* recursively do this to clean up */
3768 mark = HeapAlloc(GetProcessHeap(),0,size);
3769 strcpyW(mark,*data);
3770 TRACE("String at this point %s\n",debugstr_w(mark));
3771 size = deformat_string(package,mark,data);
3772 HeapFree(GetProcessHeap(),0,mark);
3776 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3778 return ERROR_SUCCESS;
3782 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3786 static const WCHAR q1[]={
3787 'S','E','L','E','C','T',' ','*',' ',
3788 'F','R','O','M',' ','R','e','g','i','s','t','r','y',0};
3791 MSIRECORD * row = 0;
3794 TRACE(" InstallValidate \n");
3796 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3797 if (rc != ERROR_SUCCESS)
3798 return ERROR_SUCCESS;
3800 rc = MSI_ViewExecute(view, 0);
3801 if (rc != ERROR_SUCCESS)
3803 MSI_ViewClose(view);
3804 msiobj_release(&view->hdr);
3809 rc = MSI_ViewFetch(view,&row);
3810 if (rc != ERROR_SUCCESS)
3817 msiobj_release(&row->hdr);
3819 MSI_ViewClose(view);
3820 msiobj_release(&view->hdr);
3822 total = total + progress * REG_PROGRESS_VALUE;
3823 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
3824 for (i=0; i < package->loaded_files; i++)
3825 total += package->files[i].FileSize;
3826 ui_progress(package,0,total,0,0);
3828 return ERROR_SUCCESS;
3831 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3834 MSIQUERY * view = NULL;
3835 MSIRECORD * row = 0;
3836 static const WCHAR ExecSeqQuery[] = {
3837 'S','E','L','E','C','T',' ','*',' ',
3838 'f','r','o','m',' ','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3839 static const WCHAR title[]=
3840 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3842 TRACE("Checking launch conditions\n");
3844 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3845 if (rc != ERROR_SUCCESS)
3846 return ERROR_SUCCESS;
3848 rc = MSI_ViewExecute(view, 0);
3849 if (rc != ERROR_SUCCESS)
3851 MSI_ViewClose(view);
3852 msiobj_release(&view->hdr);
3857 while (rc == ERROR_SUCCESS)
3860 LPWSTR message = NULL;
3862 rc = MSI_ViewFetch(view,&row);
3863 if (rc != ERROR_SUCCESS)
3869 cond = load_dynamic_stringW(row,1);
3871 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3873 message = load_dynamic_stringW(row,2);
3874 MessageBoxW(NULL,message,title,MB_OK);
3875 HeapFree(GetProcessHeap(),0,message);
3876 rc = ERROR_FUNCTION_FAILED;
3878 HeapFree(GetProcessHeap(),0,cond);
3879 msiobj_release(&row->hdr);
3881 MSI_ViewClose(view);
3882 msiobj_release(&view->hdr);
3886 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
3889 MSICOMPONENT* cmp = &package->components[component_index];
3891 if (cmp->KeyPath[0]==0)
3893 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
3896 if ((cmp->Attributes & 0x4) || (cmp->Attributes & 0x20))
3898 FIXME("UNIMPLEMENTED keypath as Registry or ODBC Source\n");
3904 j = get_loaded_file(package,cmp->KeyPath);
3908 LPWSTR p = dupstrW(package->files[j].TargetPath);
3916 * Ok further analysis makes me think that this work is
3917 * actually done in the PublishComponents and PublishFeatures
3918 * step, and not here. It appears like the keypath and all that is
3919 * resolved in this step, however actually written in the Publish steps.
3920 * But we will leave it here for now because it is unclear
3922 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
3925 WCHAR squished_pc[0x100];
3926 WCHAR squished_cc[0x100];
3929 HKEY hkey=0,hkey2=0,hkey3=0;
3930 static const WCHAR szProductCode[]=
3931 {'P','r','o','d','u','c','t','C','o','d','e',0};
3932 static const WCHAR szInstaller[] = {
3933 'S','o','f','t','w','a','r','e','\\',
3934 'M','i','c','r','o','s','o','f','t','\\',
3935 'W','i','n','d','o','w','s','\\',
3936 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3937 'I','n','s','t','a','l','l','e','r',0 };
3938 static const WCHAR szFeatures[] = {
3939 'F','e','a','t','u','r','e','s',0 };
3940 static const WCHAR szComponents[] = {
3941 'C','o','m','p','o','n','e','n','t','s',0 };
3944 return ERROR_INVALID_HANDLE;
3946 /* writes the Component and Features values to the registry */
3947 productcode = load_dynamic_property(package,szProductCode,&rc);
3951 squash_guid(productcode,squished_pc);
3952 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller,&hkey);
3953 if (rc != ERROR_SUCCESS)
3956 rc = RegCreateKeyW(hkey,szFeatures,&hkey2);
3957 if (rc != ERROR_SUCCESS)
3960 rc = RegCreateKeyW(hkey2,squished_pc,&hkey3);
3961 if (rc != ERROR_SUCCESS)
3964 /* here the guids are base 85 encoded */
3965 for (i = 0; i < package->loaded_features; i++)
3972 size = package->features[i].ComponentCount*21*sizeof(WCHAR);
3973 data = HeapAlloc(GetProcessHeap(), 0, size);
3976 for (j = 0; j < package->features[i].ComponentCount; j++)
3979 TRACE("From %s\n",debugstr_w(package->components
3980 [package->features[i].Components[j]].ComponentId));
3981 CLSIDFromString(package->components
3982 [package->features[i].Components[j]].ComponentId,
3984 encode_base85_guid(&clsid,buf);
3985 TRACE("to %s\n",debugstr_w(buf));
3989 size = strlenW(data)*sizeof(WCHAR);
3990 RegSetValueExW(hkey3,package->features[i].Feature,0,REG_SZ,
3992 HeapFree(GetProcessHeap(),0,data);
3998 rc = RegCreateKeyW(hkey,szComponents,&hkey2);
3999 if (rc != ERROR_SUCCESS)
4002 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
4003 for (i = 0; i < package->loaded_components; i++)
4005 ui_progress(package,2,0,0,0);
4006 if (package->components[i].ComponentId[0]!=0)
4008 WCHAR *keypath = NULL;
4011 squash_guid(package->components[i].ComponentId,squished_cc);
4012 rc = RegCreateKeyW(hkey2,squished_cc,&hkey3);
4013 if (rc != ERROR_SUCCESS)
4016 keypath = resolve_keypath(package,i);
4019 RegSetValueExW(hkey3,squished_pc,0,REG_SZ,(LPVOID)keypath,
4020 (strlenW(keypath)+1)*sizeof(WCHAR));
4024 uirow = MSI_CreateRecord(3);
4025 MSI_RecordSetStringW(uirow,1,productcode);
4026 MSI_RecordSetStringW(uirow,2,package->components[i].
4028 MSI_RecordSetStringW(uirow,3,keypath);
4029 ui_actiondata(package,szProcessComponents,uirow);
4030 msiobj_release( &uirow->hdr );
4031 HeapFree(GetProcessHeap(),0,keypath);
4036 HeapFree(GetProcessHeap(), 0, productcode);
4042 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
4045 * OK this is a bit confusing.. I am given a _Component key and I believe
4046 * that the file that is being registered as a type library is the "key file
4047 * of that component" which I interpret to mean "The file in the KeyPath of
4052 MSIRECORD * row = 0;
4053 static const WCHAR Query[] = {
4054 'S','E','L','E','C','T',' ','*',' ',
4055 'f','r','o','m',' ','T','y','p','e','L','i','b',0};
4060 return ERROR_INVALID_HANDLE;
4062 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4063 if (rc != ERROR_SUCCESS)
4064 return ERROR_SUCCESS;
4066 rc = MSI_ViewExecute(view, 0);
4067 if (rc != ERROR_SUCCESS)
4069 MSI_ViewClose(view);
4070 msiobj_release(&view->hdr);
4076 WCHAR component[0x100];
4080 rc = MSI_ViewFetch(view,&row);
4081 if (rc != ERROR_SUCCESS)
4088 MSI_RecordGetStringW(row,3,component,&sz);
4090 index = get_loaded_component(package,component);
4093 msiobj_release(&row->hdr);
4097 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
4099 TRACE("Skipping typelib reg due to disabled component\n");
4100 msiobj_release(&row->hdr);
4104 index = get_loaded_file(package,package->components[index].KeyPath);
4108 msiobj_release(&row->hdr);
4112 res = LoadTypeLib(package->files[index].TargetPath,&ptLib);
4116 WCHAR helpid[0x100];
4119 MSI_RecordGetStringW(row,6,helpid,&sz);
4121 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
4122 res = RegisterTypeLib(ptLib,package->files[index].TargetPath,help);
4123 HeapFree(GetProcessHeap(),0,help);
4125 if (!SUCCEEDED(res))
4126 ERR("Failed to register type library %s\n",
4127 debugstr_w(package->files[index].TargetPath));
4130 /* Yes the row has more fields than I need, but #1 is
4131 correct and the only one I need. Why make a new row? */
4133 ui_actiondata(package,szRegisterTypeLibraries,row);
4135 TRACE("Registered %s\n",
4136 debugstr_w(package->files[index].TargetPath));
4140 ITypeLib_Release(ptLib);
4143 ERR("Failed to load type library %s\n",
4144 debugstr_w(package->files[index].TargetPath));
4146 msiobj_release(&row->hdr);
4148 MSI_ViewClose(view);
4149 msiobj_release(&view->hdr);
4154 static UINT register_appid(MSIPACKAGE *package, LPCWSTR clsid, LPCWSTR app )
4156 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
4159 MSIRECORD * row = 0;
4160 static const WCHAR ExecSeqQuery[] =
4161 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','p','p','I'
4162 ,'d',' ','w','h','e','r','e',' ','A','p','p','I','d','=','`','%','s','`',0};
4167 return ERROR_INVALID_HANDLE;
4169 rc = ACTION_OpenQuery(package->db, &view, ExecSeqQuery, clsid);
4170 if (rc != ERROR_SUCCESS)
4173 rc = MSI_ViewExecute(view, 0);
4174 if (rc != ERROR_SUCCESS)
4176 MSI_ViewClose(view);
4177 msiobj_release(&view->hdr);
4181 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
4182 RegCreateKeyW(hkey2,clsid,&hkey3);
4183 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
4184 (strlenW(app)+1)*sizeof(WCHAR));
4186 rc = MSI_ViewFetch(view,&row);
4187 if (rc != ERROR_SUCCESS)
4189 MSI_ViewClose(view);
4190 msiobj_release(&view->hdr);
4194 if (!MSI_RecordIsNull(row,2))
4196 LPWSTR deformated=0;
4198 static const WCHAR szRemoteServerName[] =
4199 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
4200 buffer = load_dynamic_stringW(row,2);
4201 size = deformat_string(package,buffer,&deformated);
4202 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
4204 HeapFree(GetProcessHeap(),0,deformated);
4205 HeapFree(GetProcessHeap(),0,buffer);
4208 if (!MSI_RecordIsNull(row,3))
4210 static const WCHAR szLocalService[] =
4211 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
4213 buffer = load_dynamic_stringW(row,3);
4214 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4215 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
4216 HeapFree(GetProcessHeap(),0,buffer);
4219 if (!MSI_RecordIsNull(row,4))
4221 static const WCHAR szService[] =
4222 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
4224 buffer = load_dynamic_stringW(row,4);
4225 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4226 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
4227 HeapFree(GetProcessHeap(),0,buffer);
4230 if (!MSI_RecordIsNull(row,5))
4232 static const WCHAR szDLL[] =
4233 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
4235 buffer = load_dynamic_stringW(row,5);
4236 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4237 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
4238 HeapFree(GetProcessHeap(),0,buffer);
4241 if (!MSI_RecordIsNull(row,6))
4243 static const WCHAR szActivate[] =
4244 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
4245 static const WCHAR szY[] = {'Y',0};
4247 if (MSI_RecordGetInteger(row,6))
4248 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
4251 if (!MSI_RecordIsNull(row,7))
4253 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
4254 static const WCHAR szUser[] =
4255 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
4257 if (MSI_RecordGetInteger(row,7))
4258 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
4261 msiobj_release(&row->hdr);
4262 MSI_ViewClose(view);
4263 msiobj_release(&view->hdr);
4269 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
4272 * Again I am assuming the words, "Whose key file represents" when referring
4273 * to a Component as to meaning that Components KeyPath file
4275 * Also there is a very strong connection between ClassInfo and ProgID
4276 * that I am mostly glossing over.
4277 * What would be more propper is to load the ClassInfo and the ProgID info
4278 * into memory data structures and then be able to enable and disable them
4279 * based on component.
4284 MSIRECORD * row = 0;
4285 static const WCHAR ExecSeqQuery[] = {
4286 'S','E','L','E','C','T',' ','*',' ',
4287 'f','r','o','m',' ','C','l','a','s','s',0};
4288 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4289 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
4290 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
4291 HKEY hkey,hkey2,hkey3;
4294 return ERROR_INVALID_HANDLE;
4296 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
4297 if (rc != ERROR_SUCCESS)
4298 return ERROR_FUNCTION_FAILED;
4300 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4301 if (rc != ERROR_SUCCESS)
4307 rc = MSI_ViewExecute(view, 0);
4308 if (rc != ERROR_SUCCESS)
4310 MSI_ViewClose(view);
4311 msiobj_release(&view->hdr);
4318 WCHAR buffer[0x100];
4323 rc = MSI_ViewFetch(view,&row);
4324 if (rc != ERROR_SUCCESS)
4331 MSI_RecordGetStringW(row,3,buffer,&sz);
4333 index = get_loaded_component(package,buffer);
4337 msiobj_release(&row->hdr);
4341 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
4343 TRACE("Skipping class reg due to disabled component\n");
4344 msiobj_release(&row->hdr);
4349 MSI_RecordGetStringW(row,1,clsid,&sz);
4350 RegCreateKeyW(hkey,clsid,&hkey2);
4352 if (!MSI_RecordIsNull(row,5))
4355 MSI_RecordGetStringW(row,5,desc,&sz);
4357 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
4358 (strlenW(desc)+1)*sizeof(WCHAR));
4364 MSI_RecordGetStringW(row,2,buffer,&sz);
4366 RegCreateKeyW(hkey2,buffer,&hkey3);
4368 index = get_loaded_file(package,package->components[index].KeyPath);
4369 RegSetValueExW(hkey3,NULL,0,REG_SZ,
4370 (LPVOID)package->files[index].TargetPath,
4371 (strlenW(package->files[index].TargetPath)+1)
4376 if (!MSI_RecordIsNull(row,4))
4379 MSI_RecordGetStringW(row,4,buffer,&sz);
4381 RegCreateKeyW(hkey2,szProgID,&hkey3);
4383 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
4384 (strlenW(buffer)+1)*sizeof(WCHAR));
4389 if (!MSI_RecordIsNull(row,6))
4392 MSI_RecordGetStringW(row,6,buffer,&sz);
4394 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
4395 (strlenW(buffer)+1)*sizeof(WCHAR));
4397 register_appid(package,buffer,desc);
4402 FIXME("Process the rest of the fields >7\n");
4404 ui_actiondata(package,szRegisterClassInfo,row);
4406 msiobj_release(&row->hdr);
4408 MSI_ViewClose(view);
4409 msiobj_release(&view->hdr);
4416 static UINT register_progid_base(MSIRECORD * row, LPWSTR clsid)
4418 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4420 WCHAR buffer[0x100];
4425 MSI_RecordGetStringW(row,1,buffer,&sz);
4426 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
4428 if (!MSI_RecordIsNull(row,4))
4431 MSI_RecordGetStringW(row,4,buffer,&sz);
4432 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4436 if (!MSI_RecordIsNull(row,3))
4440 MSI_RecordGetStringW(row,3,buffer,&sz);
4441 RegCreateKeyW(hkey,szCLSID,&hkey2);
4442 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4446 strcpyW(clsid,buffer);
4452 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
4453 return ERROR_FUNCTION_FAILED;
4455 if (!MSI_RecordIsNull(row,5))
4456 FIXME ("UNHANDLED icon in Progid\n");
4457 return ERROR_SUCCESS;
4460 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid);
4462 static UINT register_parent_progid(MSIPACKAGE *package, LPCWSTR parent,
4467 MSIRECORD * row = 0;
4468 static const WCHAR Query_t[] =
4469 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','P','r','o','g'
4470 ,'I','d',' ','w','h','e','r','e',' ','P','r','o','g','I','d',' ','=',' ','`'
4474 return ERROR_INVALID_HANDLE;
4476 rc = ACTION_OpenQuery(package->db, &view, Query_t, parent);
4477 if (rc != ERROR_SUCCESS)
4480 rc = MSI_ViewExecute(view, 0);
4481 if (rc != ERROR_SUCCESS)
4483 MSI_ViewClose(view);
4484 msiobj_release(&view->hdr);
4488 rc = MSI_ViewFetch(view,&row);
4489 if (rc != ERROR_SUCCESS)
4491 MSI_ViewClose(view);
4492 msiobj_release(&view->hdr);
4496 register_progid(package,row,clsid);
4498 msiobj_release(&row->hdr);
4499 MSI_ViewClose(view);
4500 msiobj_release(&view->hdr);
4504 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid)
4506 UINT rc = ERROR_SUCCESS;
4508 if (MSI_RecordIsNull(row,2))
4509 rc = register_progid_base(row,clsid);
4512 WCHAR buffer[0x1000];
4515 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4517 /* check if already registered */
4519 MSI_RecordGetStringW(row,1,buffer,&sz);
4520 RegCreateKeyExW(HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4521 KEY_ALL_ACCESS, NULL, &hkey, &disp );
4522 if (disp == REG_OPENED_EXISTING_KEY)
4524 TRACE("Key already registered\n");
4528 /* clsid is same as parent */
4529 RegCreateKeyW(hkey,szCLSID,&hkey2);
4530 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
4536 MSI_RecordGetStringW(row,2,buffer,&sz);
4537 rc = register_parent_progid(package,buffer,clsid);
4539 if (!MSI_RecordIsNull(row,4))
4542 MSI_RecordGetStringW(row,4,buffer,&sz);
4543 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
4544 (strlenW(buffer)+1) * sizeof(WCHAR));
4547 if (!MSI_RecordIsNull(row,5))
4548 FIXME ("UNHANDLED icon in Progid\n");
4555 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
4558 * Sigh, here I am just brute force registering all progids
4559 * this needs to be linked to the Classes that have been registered
4560 * but the easiest way to do that is to load all these stuff into
4561 * memory for easy checking.
4563 * Gives me something to continue to work toward.
4567 MSIRECORD * row = 0;
4568 static const WCHAR Query[] = {
4569 'S','E','L','E','C','T',' ','*',' ',
4570 'F','R','O','M',' ','P','r','o','g','I','d',0};
4573 return ERROR_INVALID_HANDLE;
4575 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4576 if (rc != ERROR_SUCCESS)
4577 return ERROR_SUCCESS;
4579 rc = MSI_ViewExecute(view, 0);
4580 if (rc != ERROR_SUCCESS)
4582 MSI_ViewClose(view);
4583 msiobj_release(&view->hdr);
4589 WCHAR clsid[0x1000];
4591 rc = MSI_ViewFetch(view,&row);
4592 if (rc != ERROR_SUCCESS)
4598 register_progid(package,row,clsid);
4599 ui_actiondata(package,szRegisterProgIdInfo,row);
4601 msiobj_release(&row->hdr);
4603 MSI_ViewClose(view);
4604 msiobj_release(&view->hdr);
4608 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
4612 LPWSTR SystemFolder;
4616 static const WCHAR szInstaller[] =
4617 {'I','n','s','t','a','l','l','e','r','\\',0};
4618 static const WCHAR szProductCode[] =
4619 {'P','r','o','d','u','c','t','C','o','d','e',0};
4620 static const WCHAR szFolder[] =
4621 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4623 ProductCode = load_dynamic_property(package,szProductCode,&rc);
4627 SystemFolder = load_dynamic_property(package,szFolder,NULL);
4629 dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
4631 create_full_pathW(dest);
4633 *FilePath = build_directory_name(2, dest, icon_name);
4635 HeapFree(GetProcessHeap(),0,SystemFolder);
4636 HeapFree(GetProcessHeap(),0,ProductCode);
4637 HeapFree(GetProcessHeap(),0,dest);
4638 return ERROR_SUCCESS;
4641 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
4645 MSIRECORD * row = 0;
4646 static const WCHAR Query[] = {
4647 'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
4648 'S','h','o','r','t','c','u','t',0};
4654 return ERROR_INVALID_HANDLE;
4656 res = CoInitialize( NULL );
4659 ERR("CoInitialize failed\n");
4660 return ERROR_FUNCTION_FAILED;
4663 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4664 if (rc != ERROR_SUCCESS)
4665 return ERROR_SUCCESS;
4667 rc = MSI_ViewExecute(view, 0);
4668 if (rc != ERROR_SUCCESS)
4670 MSI_ViewClose(view);
4671 msiobj_release(&view->hdr);
4677 LPWSTR target_file, target_folder;
4678 WCHAR buffer[0x100];
4681 static const WCHAR szlnk[]={'.','l','n','k',0};
4683 rc = MSI_ViewFetch(view,&row);
4684 if (rc != ERROR_SUCCESS)
4691 MSI_RecordGetStringW(row,4,buffer,&sz);
4693 index = get_loaded_component(package,buffer);
4697 msiobj_release(&row->hdr);
4701 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
4703 TRACE("Skipping shortcut creation due to disabled component\n");
4704 msiobj_release(&row->hdr);
4708 ui_actiondata(package,szCreateShortcuts,row);
4710 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
4711 &IID_IShellLinkW, (LPVOID *) &sl );
4715 ERR("Is IID_IShellLink\n");
4716 msiobj_release(&row->hdr);
4720 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
4723 ERR("Is IID_IPersistFile\n");
4724 msiobj_release(&row->hdr);
4729 MSI_RecordGetStringW(row,2,buffer,&sz);
4730 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
4732 /* may be needed because of a bug somehwere else */
4733 create_full_pathW(target_folder);
4736 MSI_RecordGetStringW(row,3,buffer,&sz);
4737 reduce_to_longfilename(buffer);
4738 if (!strchrW(buffer,'.') || strcmpiW(strchrW(buffer,'.'),szlnk))
4739 strcatW(buffer,szlnk);
4740 target_file = build_directory_name(2, target_folder, buffer);
4741 HeapFree(GetProcessHeap(),0,target_folder);
4744 MSI_RecordGetStringW(row,5,buffer,&sz);
4745 if (strchrW(buffer,'['))
4748 deformat_string(package,buffer,&deformated);
4749 IShellLinkW_SetPath(sl,deformated);
4750 HeapFree(GetProcessHeap(),0,deformated);
4754 FIXME("UNHANDLED shortcut format, advertised shortcut\n");
4755 IPersistFile_Release( pf );
4756 IShellLinkW_Release( sl );
4757 msiobj_release(&row->hdr);
4761 if (!MSI_RecordIsNull(row,6))
4765 MSI_RecordGetStringW(row,6,buffer,&sz);
4766 deformat_string(package,buffer,&deformated);
4767 IShellLinkW_SetArguments(sl,deformated);
4768 HeapFree(GetProcessHeap(),0,deformated);
4771 if (!MSI_RecordIsNull(row,7))
4774 deformated = load_dynamic_stringW(row,7);
4775 IShellLinkW_SetDescription(sl,deformated);
4776 HeapFree(GetProcessHeap(),0,deformated);
4779 if (!MSI_RecordIsNull(row,8))
4780 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
4782 if (!MSI_RecordIsNull(row,9))
4788 MSI_RecordGetStringW(row,9,buffer,&sz);
4790 build_icon_path(package,buffer,&Path);
4791 index = MSI_RecordGetInteger(row,10);
4793 IShellLinkW_SetIconLocation(sl,Path,index);
4794 HeapFree(GetProcessHeap(),0,Path);
4797 if (!MSI_RecordIsNull(row,11))
4798 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
4800 if (!MSI_RecordIsNull(row,12))
4804 MSI_RecordGetStringW(row,12,buffer,&sz);
4805 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
4806 IShellLinkW_SetWorkingDirectory(sl,Path);
4807 HeapFree(GetProcessHeap(), 0, Path);
4810 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
4811 IPersistFile_Save(pf,target_file,FALSE);
4813 HeapFree(GetProcessHeap(),0,target_file);
4815 IPersistFile_Release( pf );
4816 IShellLinkW_Release( sl );
4818 msiobj_release(&row->hdr);
4820 MSI_ViewClose(view);
4821 msiobj_release(&view->hdr);
4831 * 99% of the work done here is only done for
4832 * advertised installs. However this is where the
4833 * Icon table is processed and written out
4834 * so that is what I am going to do here.
4836 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
4840 MSIRECORD * row = 0;
4841 static const WCHAR Query[]={
4842 'S','E','L','E','C','T',' ','*',' ',
4843 'f','r','o','m',' ','I','c','o','n',0};
4847 return ERROR_INVALID_HANDLE;
4849 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4850 if (rc != ERROR_SUCCESS)
4851 return ERROR_SUCCESS;
4853 rc = MSI_ViewExecute(view, 0);
4854 if (rc != ERROR_SUCCESS)
4856 MSI_ViewClose(view);
4857 msiobj_release(&view->hdr);
4864 WCHAR *FilePath=NULL;
4865 WCHAR *FileName=NULL;
4868 rc = MSI_ViewFetch(view,&row);
4869 if (rc != ERROR_SUCCESS)
4875 FileName = load_dynamic_stringW(row,1);
4878 ERR("Unable to get FileName\n");
4879 msiobj_release(&row->hdr);
4883 build_icon_path(package,FileName,&FilePath);
4885 HeapFree(GetProcessHeap(),0,FileName);
4887 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
4889 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
4890 FILE_ATTRIBUTE_NORMAL, NULL);
4892 if (the_file == INVALID_HANDLE_VALUE)
4894 ERR("Unable to create file %s\n",debugstr_w(FilePath));
4895 msiobj_release(&row->hdr);
4896 HeapFree(GetProcessHeap(),0,FilePath);
4904 rc = MSI_RecordReadStream(row,2,buffer,&sz);
4905 if (rc != ERROR_SUCCESS)
4907 ERR("Failed to get stream\n");
4908 CloseHandle(the_file);
4909 DeleteFileW(FilePath);
4912 WriteFile(the_file,buffer,sz,&write,NULL);
4913 } while (sz == 1024);
4915 HeapFree(GetProcessHeap(),0,FilePath);
4917 CloseHandle(the_file);
4918 msiobj_release(&row->hdr);
4920 MSI_ViewClose(view);
4921 msiobj_release(&view->hdr);
4926 /* Msi functions that seem appropriate here */
4927 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
4932 TRACE(" exteral attempt at action %s\n",szAction);
4935 return ERROR_FUNCTION_FAILED;
4937 return ERROR_FUNCTION_FAILED;
4939 szwAction = strdupAtoW(szAction);
4942 return ERROR_FUNCTION_FAILED;
4945 rc = MsiDoActionW(hInstall, szwAction);
4946 HeapFree(GetProcessHeap(),0,szwAction);
4950 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
4952 MSIPACKAGE *package;
4953 UINT ret = ERROR_INVALID_HANDLE;
4955 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
4957 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4960 ret = ACTION_PerformAction(package,szAction);
4961 msiobj_release( &package->hdr );
4966 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
4967 LPSTR szPathBuf, DWORD* pcchPathBuf)
4973 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
4976 return ERROR_FUNCTION_FAILED;
4978 return ERROR_FUNCTION_FAILED;
4980 szwFolder = strdupAtoW(szFolder);
4983 return ERROR_FUNCTION_FAILED;
4985 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
4987 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
4989 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
4990 *pcchPathBuf, NULL, NULL );
4992 HeapFree(GetProcessHeap(),0,szwFolder);
4993 HeapFree(GetProcessHeap(),0,szwPathBuf);
4998 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
4999 szPathBuf, DWORD* pcchPathBuf)
5002 UINT rc = ERROR_FUNCTION_FAILED;
5003 MSIPACKAGE *package;
5005 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
5007 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5009 return ERROR_INVALID_HANDLE;
5010 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
5011 msiobj_release( &package->hdr );
5013 if (path && (strlenW(path) > *pcchPathBuf))
5015 *pcchPathBuf = strlenW(path)+1;
5016 rc = ERROR_MORE_DATA;
5020 *pcchPathBuf = strlenW(path)+1;
5021 strcpyW(szPathBuf,path);
5022 TRACE("Returning Path %s\n",debugstr_w(path));
5025 HeapFree(GetProcessHeap(),0,path);
5031 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
5032 LPSTR szPathBuf, DWORD* pcchPathBuf)
5038 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
5041 return ERROR_FUNCTION_FAILED;
5043 return ERROR_FUNCTION_FAILED;
5045 szwFolder = strdupAtoW(szFolder);
5047 return ERROR_FUNCTION_FAILED;
5049 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
5051 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
5053 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
5054 *pcchPathBuf, NULL, NULL );
5056 HeapFree(GetProcessHeap(),0,szwFolder);
5057 HeapFree(GetProcessHeap(),0,szwPathBuf);
5062 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
5063 szPathBuf, DWORD* pcchPathBuf)
5066 UINT rc = ERROR_FUNCTION_FAILED;
5067 MSIPACKAGE *package;
5069 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
5071 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5073 return ERROR_INVALID_HANDLE;
5074 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
5075 msiobj_release( &package->hdr );
5077 if (path && strlenW(path) > *pcchPathBuf)
5079 *pcchPathBuf = strlenW(path)+1;
5080 rc = ERROR_MORE_DATA;
5084 *pcchPathBuf = strlenW(path)+1;
5085 strcpyW(szPathBuf,path);
5086 TRACE("Returning Path %s\n",debugstr_w(path));
5089 HeapFree(GetProcessHeap(),0,path);
5095 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
5096 LPCSTR szFolderPath)
5099 LPWSTR szwFolderPath;
5103 return ERROR_FUNCTION_FAILED;
5105 return ERROR_FUNCTION_FAILED;
5107 szwFolder = strdupAtoW(szFolder);
5109 return ERROR_FUNCTION_FAILED;
5111 szwFolderPath = strdupAtoW(szFolderPath);
5114 HeapFree(GetProcessHeap(),0,szwFolder);
5115 return ERROR_FUNCTION_FAILED;
5118 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
5120 HeapFree(GetProcessHeap(),0,szwFolder);
5121 HeapFree(GetProcessHeap(),0,szwFolderPath);
5126 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
5127 LPCWSTR szFolderPath)
5131 LPWSTR path2 = NULL;
5135 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
5138 return ERROR_INVALID_HANDLE;
5140 if (szFolderPath[0]==0)
5141 return ERROR_FUNCTION_FAILED;
5143 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
5144 return ERROR_FUNCTION_FAILED;
5146 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
5149 return ERROR_INVALID_PARAMETER;
5151 if (folder->Property)
5152 HeapFree(GetProcessHeap(),0,folder->Property);
5154 len = strlenW(szFolderPath);
5156 if (szFolderPath[len-1]!='\\')
5159 folder->Property = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
5160 strcpyW(folder->Property,szFolderPath);
5161 strcatW(folder->Property,cszbs);
5164 folder->Property = dupstrW(szFolderPath);
5166 if (strcmpiW(path, szFolderPath) == 0)
5169 * Resolved Target has not really changed, so just
5170 * set this folder and do not recalculate everything.
5172 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
5173 folder->ResolvedTarget = NULL;
5174 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
5175 HeapFree(GetProcessHeap(),0,path2);
5179 for (i = 0; i < package->loaded_folders; i++)
5181 if (package->folders[i].ResolvedTarget)
5182 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
5183 package->folders[i].ResolvedTarget=NULL;
5186 for (i = 0; i < package->loaded_folders; i++)
5188 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
5190 HeapFree(GetProcessHeap(),0,path2);
5193 HeapFree(GetProcessHeap(),0,path);
5195 return ERROR_SUCCESS;
5198 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
5199 LPCWSTR szFolderPath)
5201 MSIPACKAGE *package;
5204 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
5206 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5207 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
5208 msiobj_release( &package->hdr );
5212 /***********************************************************************
5213 * MsiGetMode (MSI.@)
5215 * Returns an internal installer state (if it is running in a mode iRunMode)
5218 * hInstall [I] Handle to the installation
5219 * hRunMode [I] Checking run mode
5220 * MSIRUNMODE_ADMIN Administrative mode
5221 * MSIRUNMODE_ADVERTISE Advertisement mode
5222 * MSIRUNMODE_MAINTENANCE Maintenance mode
5223 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
5224 * MSIRUNMODE_LOGENABLED Log file is writing
5225 * MSIRUNMODE_OPERATIONS Operations in progress??
5226 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
5227 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
5228 * MSIRUNMODE_CABINET Files from cabinet are installed
5229 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is supressed
5230 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is supressed
5231 * MSIRUNMODE_RESERVED11 Reserved
5232 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
5233 * MSIRUNMODE_ZAWENABLED Demand installation is supported
5234 * MSIRUNMODE_RESERVED14 Reserved
5235 * MSIRUNMODE_RESERVED15 Reserved
5236 * MSIRUNMODE_SCHEDULED called from install script
5237 * MSIRUNMODE_ROLLBACK called from rollback script
5238 * MSIRUNMODE_COMMIT called from commit script
5241 * In the state: TRUE
5242 * Not in the state: FALSE
5246 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
5248 FIXME("STUB (iRunMode=%i)\n",iRunMode);
5253 * According to the docs, when this is called it immediately recalculates
5254 * all the component states as well
5256 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
5257 INSTALLSTATE iState)
5259 LPWSTR szwFeature = NULL;
5262 szwFeature = strdupAtoW(szFeature);
5265 return ERROR_FUNCTION_FAILED;
5267 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
5269 HeapFree(GetProcessHeap(),0,szwFeature);
5274 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
5275 INSTALLSTATE iState)
5277 MSIPACKAGE* package;
5280 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
5282 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5284 return ERROR_INVALID_HANDLE;
5286 index = get_loaded_feature(package,szFeature);
5288 return ERROR_UNKNOWN_FEATURE;
5290 package->features[index].ActionRequest= iState;
5292 return ERROR_SUCCESS;
5295 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
5296 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5298 LPWSTR szwFeature = NULL;
5301 szwFeature = strdupAtoW(szFeature);
5303 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
5305 HeapFree( GetProcessHeap(), 0 , szwFeature);
5310 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
5311 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5315 index = get_loaded_feature(package,szFeature);
5317 return ERROR_UNKNOWN_FEATURE;
5320 *piInstalled = package->features[index].Installed;
5323 *piAction = package->features[index].Action;
5325 TRACE("returning %i %i\n",*piInstalled,*piAction);
5327 return ERROR_SUCCESS;
5330 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
5331 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5333 MSIPACKAGE* package;
5336 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
5339 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5341 return ERROR_INVALID_HANDLE;
5342 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
5343 msiobj_release( &package->hdr );
5347 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
5348 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5350 LPWSTR szwComponent= NULL;
5353 szwComponent= strdupAtoW(szComponent);
5355 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
5357 HeapFree( GetProcessHeap(), 0 , szwComponent);
5362 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
5363 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5367 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
5370 index = get_loaded_component(package,szComponent);
5372 return ERROR_UNKNOWN_COMPONENT;
5375 *piInstalled = package->components[index].Installed;
5378 *piInstalled = package->components[index].Action;
5380 return ERROR_SUCCESS;
5383 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
5384 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5386 MSIPACKAGE* package;
5389 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
5390 piInstalled, piAction);
5392 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5394 return ERROR_INVALID_HANDLE;
5395 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
5396 msiobj_release( &package->hdr );
5401 static UINT ACTION_Template(MSIPACKAGE *package)
5405 MSIRECORD * row = 0;
5406 static const WCHAR ExecSeqQuery[] = {0};
5408 rc = MsiDatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5409 if (rc != ERROR_SUCCESS)
5412 rc = MsiViewExecute(view, 0);
5413 if (rc != ERROR_SUCCESS)
5416 msiobj_release(&view->hdr);
5422 rc = MsiViewFetch(view,&row);
5423 if (rc != ERROR_SUCCESS)
5429 msiobj_release(&row->hdr);
5432 msiobj_release(&view->hdr);