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
36 #include "wine/debug.h"
45 #include "wine/unicode.h"
48 #define CUSTOM_ACTION_TYPE_MASK 0x3F
50 WINE_DEFAULT_DEBUG_CHANNEL(msi);
52 typedef struct tagMSIFEATURE
55 WCHAR Feature_Parent[96];
57 WCHAR Description[0x100];
65 INT Components[1024]; /* yes hardcoded limit.... I am bad */
69 typedef struct tagMSICOMPONENT
72 WCHAR ComponentId[96];
75 WCHAR Condition[0x100];
84 typedef struct tagMSIFOLDER
87 WCHAR TargetDefault[96];
88 WCHAR SourceDefault[96];
90 WCHAR ResolvedTarget[MAX_PATH];
91 WCHAR ResolvedSource[MAX_PATH];
92 WCHAR Property[MAX_PATH]; /* initially set property */
95 /* 0 = uninitialized */
97 /* 2 = created remove if empty */
98 /* 3 = created persist if empty */
103 typedef struct tagMSIFILE
107 WCHAR FileName[MAX_PATH];
115 /* 0 = uninitialize */
116 /* 1 = not present */
117 /* 2 = present but replace */
118 /* 3 = present do not replace */
120 WCHAR SourcePath[MAX_PATH];
121 WCHAR TargetPath[MAX_PATH];
128 static UINT ACTION_ProcessExecSequence(MSIHANDLE hPackage, BOOL UIran);
129 static UINT ACTION_ProcessUISequence(MSIHANDLE hPackage);
131 UINT ACTION_PerformAction(MSIHANDLE hPackage, const WCHAR *action);
133 static UINT ACTION_LaunchConditions(MSIHANDLE hPackage);
134 static UINT ACTION_CostInitialize(MSIHANDLE hPackage);
135 static UINT ACTION_CreateFolders(MSIHANDLE hPackage);
136 static UINT ACTION_CostFinalize(MSIHANDLE hPackage);
137 static UINT ACTION_FileCost(MSIHANDLE hPackage);
138 static UINT ACTION_InstallFiles(MSIHANDLE hPackage);
139 static UINT ACTION_DuplicateFiles(MSIHANDLE hPackage);
140 static UINT ACTION_WriteRegistryValues(MSIHANDLE hPackage);
141 static UINT ACTION_CustomAction(MSIHANDLE hPackage,const WCHAR *action);
142 static UINT ACTION_InstallInitialize(MSIHANDLE hPackage);
143 static UINT ACTION_InstallValidate(MSIHANDLE hPackage);
144 static UINT ACTION_ProcessComponents(MSIHANDLE hPackage);
145 static UINT ACTION_RegisterTypeLibraries(MSIHANDLE hPackage);
146 static UINT ACTION_RegisterClassInfo(MSIHANDLE hPackage);
147 static UINT ACTION_RegisterProgIdInfo(MSIHANDLE hPackage);
148 static UINT ACTION_CreateShortcuts(MSIHANDLE hPackage);
149 static UINT ACTION_PublishProduct(MSIHANDLE hPackage);
151 static UINT HANDLE_CustomType1(MSIHANDLE hPackage, const LPWSTR source,
152 const LPWSTR target, const INT type);
153 static UINT HANDLE_CustomType2(MSIHANDLE hPackage, const LPWSTR source,
154 const LPWSTR target, const INT type);
156 static DWORD deformat_string(MSIHANDLE hPackage, WCHAR* ptr,WCHAR** data);
157 static UINT resolve_folder(MSIHANDLE hPackage, LPCWSTR name, LPWSTR path,
158 BOOL source, BOOL set_prop, MSIFOLDER **folder);
160 static UINT track_tempfile(MSIHANDLE hPackage, LPCWSTR name, LPCWSTR path);
163 * consts and values used
165 static const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
166 static const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
167 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
168 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
169 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
170 static const WCHAR c_collen[] = {'C',':','\\',0};
172 static const WCHAR cszlsb[]={'[',0};
173 static const WCHAR cszrsb[]={']',0};
174 static const WCHAR cszbs[]={'\\',0};
176 const static WCHAR szCreateFolders[] =
177 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
178 const static WCHAR szCostFinalize[] =
179 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
180 const static WCHAR szInstallFiles[] =
181 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
182 const static WCHAR szDuplicateFiles[] =
183 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
184 const static WCHAR szWriteRegistryValues[] =
185 {'W','r','i','t','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
186 const static WCHAR szCostInitialize[] =
187 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
188 const static WCHAR szFileCost[] = {'F','i','l','e','C','o','s','t',0};
189 const static WCHAR szInstallInitialize[] =
190 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
191 const static WCHAR szInstallValidate[] =
192 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
193 const static WCHAR szLaunchConditions[] =
194 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
195 const static WCHAR szProcessComponents[] =
196 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
197 const static WCHAR szRegisterTypeLibraries[] =
198 {'R','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r',
200 const static WCHAR szRegisterClassInfo[] =
201 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
202 const static WCHAR szRegisterProgIdInfo[] =
203 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
204 const static WCHAR szCreateShortcuts[] =
205 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
206 const static WCHAR szPublishProduct[] =
207 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
209 /********************************************************
210 * helper functions to get around current HACKS and such
211 ********************************************************/
212 inline static void reduce_to_longfilename(WCHAR* filename)
214 if (strchrW(filename,'|'))
216 WCHAR newname[MAX_PATH];
217 strcpyW(newname,strchrW(filename,'|')+1);
218 strcpyW(filename,newname);
222 inline static char *strdupWtoA( const WCHAR *str )
227 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL
229 if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
230 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
235 inline static int get_loaded_component(MSIPACKAGE* package, LPCWSTR Component )
240 for (i = 0; i < package->loaded_components; i++)
242 if (strcmpW(Component,package->components[i].Component)==0)
251 inline static int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
256 for (i = 0; i < package->loaded_features; i++)
258 if (strcmpW(Feature,package->features[i].Feature)==0)
267 inline static int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
272 for (i = 0; i < package->loaded_files; i++)
274 if (strcmpW(file,package->files[i].File)==0)
283 static UINT track_tempfile(MSIHANDLE hPackage, LPCWSTR name, LPCWSTR path)
289 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
294 for (i=0; i < package->loaded_files; i++)
295 if (strcmpW(package->files[i].File,name)==0)
298 index = package->loaded_files;
299 package->loaded_files++;
300 if (package->loaded_files== 1)
301 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
303 package->files = HeapReAlloc(GetProcessHeap(),0,
304 package->files , package->loaded_files * sizeof(MSIFILE));
306 memset(&package->files[index],0,sizeof(MSIFILE));
308 strcpyW(package->files[index].File,name);
309 strcpyW(package->files[index].TargetPath,path);
310 package->files[index].Temporary = TRUE;
312 TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
317 void ACTION_remove_tracked_tempfiles(MSIPACKAGE* package)
324 for (i = 0; i < package->loaded_files; i++)
326 if (package->files[i].Temporary)
327 DeleteFileW(package->files[i].TargetPath);
332 static void ui_progress(MSIHANDLE hPackage, int a, int b, int c, int d )
336 row = MsiCreateRecord(4);
337 MsiRecordSetInteger(row,1,a);
338 MsiRecordSetInteger(row,2,b);
339 MsiRecordSetInteger(row,3,c);
340 MsiRecordSetInteger(row,4,d);
341 MsiProcessMessage(hPackage, INSTALLMESSAGE_PROGRESS, row);
345 static void ui_actiondata(MSIHANDLE hPackage, LPCWSTR action, MSIHANDLE record)
347 static const WCHAR Query_t[] =
348 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
349 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
350 ' ','\'','%','s','\'',0};
355 WCHAR *ActionFormat=NULL;
361 sprintfW(Query,Query_t,action);
362 db = MsiGetActiveDatabase(hPackage);
363 rc = MsiDatabaseOpenViewW(db, Query, &view);
365 MsiViewExecute(view, 0);
366 rc = MsiViewFetch(view,&row);
367 if (rc != ERROR_SUCCESS)
370 MsiCloseHandle(view);
374 if (MsiRecordIsNull(row,3))
378 MsiCloseHandle(view);
382 MsiRecordGetStringW(row,3,NULL,&sz);
384 ActionFormat = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
385 MsiRecordGetStringW(row,3,ActionFormat,&sz);
388 MsiCloseHandle(view);
399 ptr2 = strchrW(ptr,'[');
402 strncpyW(tmp,ptr,ptr2-ptr);
404 strcatW(message,tmp);
408 MsiRecordGetStringW(record,field,NULL,&sz);
410 data = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
411 MsiRecordGetStringW(record,field,data,&sz);
412 strcatW(message,data);
413 HeapFree(GetProcessHeap(),0,data);
414 ptr=strchrW(ptr2,']');
419 strcatW(message,ptr);
424 row = MsiCreateRecord(1);
425 MsiRecordSetStringW(row,1,message);
427 MsiProcessMessage(hPackage, INSTALLMESSAGE_ACTIONDATA, row);
429 HeapFree(GetProcessHeap(),0,ActionFormat);
433 static void ui_actionstart(MSIHANDLE hPackage, LPCWSTR action)
435 static const WCHAR template_s[]=
436 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ','%','s','.',0};
437 static const WCHAR format[] =
438 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
439 static const WCHAR Query_t[] =
440 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
441 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
442 ' ','\'','%','s','\'',0};
448 WCHAR *ActionText=NULL;
453 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
455 sprintfW(Query,Query_t,action);
456 db = MsiGetActiveDatabase(hPackage);
457 rc = MsiDatabaseOpenViewW(db, Query, &view);
459 MsiViewExecute(view, 0);
460 rc = MsiViewFetch(view,&row);
461 if (rc != ERROR_SUCCESS)
464 MsiCloseHandle(view);
469 MsiRecordGetStringW(row,2,NULL,&sz);
471 ActionText = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
472 MsiRecordGetStringW(row,2,ActionText,&sz);
475 MsiCloseHandle(view);
477 sprintfW(message,template_s,timet,action,ActionText);
479 row = MsiCreateRecord(1);
480 MsiRecordSetStringW(row,1,message);
482 MsiProcessMessage(hPackage, INSTALLMESSAGE_ACTIONSTART, row);
484 HeapFree(GetProcessHeap(),0,ActionText);
487 static void ui_actioninfo(MSIHANDLE hPackage, LPCWSTR action, BOOL start,
491 static const WCHAR template_s[]=
492 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ','%','s',
494 static const WCHAR template_e[]=
495 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ','%','s',
496 '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ','%','i','.',0};
497 static const WCHAR format[] =
498 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
502 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
504 sprintfW(message,template_s,timet,action);
506 sprintfW(message,template_e,timet,action,rc);
508 row = MsiCreateRecord(1);
509 MsiRecordSetStringW(row,1,message);
511 MsiProcessMessage(hPackage, INSTALLMESSAGE_INFO, row);
515 /****************************************************
516 * TOP level entry points
517 *****************************************************/
519 UINT ACTION_DoTopLevelINSTALL(MSIHANDLE hPackage, LPCWSTR szPackagePath,
520 LPCWSTR szCommandLine)
529 WCHAR check[MAX_PATH];
533 strcpyW(pth,szPackagePath);
534 p = strrchrW(pth,'\\');
542 if (MsiGetPropertyW(hPackage,cszSourceDir,check,&size)
544 MsiSetPropertyW(hPackage, cszSourceDir, pth);
550 ptr = (LPWSTR)szCommandLine;
557 TRACE("Looking at %s\n",debugstr_w(ptr));
559 ptr2 = strchrW(ptr,'=');
564 strncpyW(prop,ptr,ptr2-ptr);
569 while (*ptr && (quote || (!quote && *ptr!=' ')))
582 strncpyW(val,ptr2,len);
588 TRACE("Found commandline property (%s) = (%s)\n", debugstr_w(prop),
590 MsiSetPropertyW(hPackage,prop,val);
595 if (MsiGetPropertyA(hPackage,"UILevel",buffer,&sz) == ERROR_SUCCESS)
597 if (atoi(buffer) >= INSTALLUILEVEL_REDUCED)
599 rc = ACTION_ProcessUISequence(hPackage);
600 if (rc == ERROR_SUCCESS)
601 rc = ACTION_ProcessExecSequence(hPackage,TRUE);
604 rc = ACTION_ProcessExecSequence(hPackage,FALSE);
607 rc = ACTION_ProcessExecSequence(hPackage,FALSE);
613 static UINT ACTION_ProcessExecSequence(MSIHANDLE hPackage, BOOL UIran)
617 static const CHAR *ExecSeqQuery =
618 "select * from InstallExecuteSequence where Sequence > %i order by Sequence";
623 db = MsiGetActiveDatabase(hPackage);
628 static const CHAR *IVQuery =
629 "select Sequence from InstallExecuteSequence where Action = `InstallValidate`" ;
631 MsiDatabaseOpenViewA(db, IVQuery, &view);
632 MsiViewExecute(view, 0);
633 MsiViewFetch(view,&row);
634 seq = MsiRecordGetInteger(row,1);
637 MsiCloseHandle(view);
638 sprintf(Query,ExecSeqQuery,0);
641 sprintf(Query,ExecSeqQuery,0);
643 rc = MsiDatabaseOpenViewA(db, Query, &view);
646 if (rc == ERROR_SUCCESS)
648 rc = MsiViewExecute(view, 0);
650 if (rc != ERROR_SUCCESS)
653 MsiCloseHandle(view);
657 TRACE("Running the actions \n");
664 rc = MsiViewFetch(view,&row);
665 if (rc != ERROR_SUCCESS)
671 /* check conditions */
672 if (!MsiRecordIsNull(row,2))
675 rc = MsiRecordGetStringW(row,2,buffer,&sz);
676 if (rc != ERROR_SUCCESS)
682 /* this is a hack to skip errors in the condition code */
683 if (MsiEvaluateConditionW(hPackage, buffer) ==
693 rc = MsiRecordGetStringW(row,1,buffer,&sz);
694 if (rc != ERROR_SUCCESS)
696 ERR("Error is %x\n",rc);
701 rc = ACTION_PerformAction(hPackage,buffer);
703 if (rc != ERROR_SUCCESS)
705 ERR("Execution halted due to error (%i)\n",rc);
714 MsiCloseHandle(view);
722 static UINT ACTION_ProcessUISequence(MSIHANDLE hPackage)
726 static const CHAR *ExecSeqQuery =
727 "select * from InstallUISequence where Sequence > 0 order by Sequence";
730 db = MsiGetActiveDatabase(hPackage);
731 rc = MsiDatabaseOpenViewA(db, ExecSeqQuery, &view);
734 if (rc == ERROR_SUCCESS)
736 rc = MsiViewExecute(view, 0);
738 if (rc != ERROR_SUCCESS)
741 MsiCloseHandle(view);
745 TRACE("Running the actions \n");
753 rc = MsiViewFetch(view,&row);
754 if (rc != ERROR_SUCCESS)
760 /* check conditions */
761 if (!MsiRecordIsNull(row,2))
764 rc = MsiRecordGetStringW(row,2,buffer,&sz);
765 if (rc != ERROR_SUCCESS)
771 if (MsiEvaluateConditionW(hPackage, buffer) ==
781 rc = MsiRecordGetStringW(row,1,buffer,&sz);
782 if (rc != ERROR_SUCCESS)
784 ERR("Error is %x\n",rc);
789 rc = ACTION_PerformAction(hPackage,buffer);
791 if (rc != ERROR_SUCCESS)
793 ERR("Execution halted due to error (%i)\n",rc);
802 MsiCloseHandle(view);
809 /********************************************************
810 * ACTION helper functions and functions that perform the actions
811 *******************************************************/
814 * Alot of actions are really important even if they don't do anything
815 * explicit.. Lots of properties are set at the beginning of the installation
816 * CostFinalize does a bunch of work to translated the directories and such
818 * But until I get write access to the database that is hard, so I am going to
819 * hack it to see if I can get something to run.
821 UINT ACTION_PerformAction(MSIHANDLE hPackage, const WCHAR *action)
823 UINT rc = ERROR_SUCCESS;
825 TRACE("Performing action (%s)\n",debugstr_w(action));
826 ui_actioninfo(hPackage, action, TRUE, 0);
827 ui_actionstart(hPackage, action);
828 ui_progress(hPackage,2,1,0,0);
830 /* pre install, setup and configuration block */
831 if (strcmpW(action,szLaunchConditions)==0)
832 rc = ACTION_LaunchConditions(hPackage);
833 else if (strcmpW(action,szCostInitialize)==0)
834 rc = ACTION_CostInitialize(hPackage);
835 else if (strcmpW(action,szFileCost)==0)
836 rc = ACTION_FileCost(hPackage);
837 else if (strcmpW(action,szCostFinalize)==0)
838 rc = ACTION_CostFinalize(hPackage);
839 else if (strcmpW(action,szInstallValidate)==0)
840 rc = ACTION_InstallValidate(hPackage);
843 else if (strcmpW(action,szProcessComponents)==0)
844 rc = ACTION_ProcessComponents(hPackage);
845 else if (strcmpW(action,szInstallInitialize)==0)
846 rc = ACTION_InstallInitialize(hPackage);
847 else if (strcmpW(action,szCreateFolders)==0)
848 rc = ACTION_CreateFolders(hPackage);
849 else if (strcmpW(action,szInstallFiles)==0)
850 rc = ACTION_InstallFiles(hPackage);
851 else if (strcmpW(action,szDuplicateFiles)==0)
852 rc = ACTION_DuplicateFiles(hPackage);
853 else if (strcmpW(action,szWriteRegistryValues)==0)
854 rc = ACTION_WriteRegistryValues(hPackage);
855 else if (strcmpW(action,szRegisterTypeLibraries)==0)
856 rc = ACTION_RegisterTypeLibraries(hPackage);
857 else if (strcmpW(action,szRegisterClassInfo)==0)
858 rc = ACTION_RegisterClassInfo(hPackage);
859 else if (strcmpW(action,szRegisterProgIdInfo)==0)
860 rc = ACTION_RegisterProgIdInfo(hPackage);
861 else if (strcmpW(action,szCreateShortcuts)==0)
862 rc = ACTION_CreateShortcuts(hPackage);
863 else if (strcmpW(action,szPublishProduct)==0)
864 rc = ACTION_PublishProduct(hPackage);
867 Called during itunes but unimplemented and seem important
869 ResolveSource (sets SourceDir)
873 else if ((rc = ACTION_CustomAction(hPackage,action)) != ERROR_SUCCESS)
875 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
879 ui_actioninfo(hPackage, action, FALSE, rc);
884 static UINT ACTION_CustomAction(MSIHANDLE hPackage,const WCHAR *action)
886 UINT rc = ERROR_SUCCESS;
889 WCHAR ExecSeqQuery[1024] =
890 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','C','u','s','t','o'
891 ,'m','A','c','t','i','o','n',' ','w','h','e','r','e',' ','`','A','c','t','i'
892 ,'o','n','`',' ','=',' ','`',0};
893 static const WCHAR end[]={'`',0};
898 WCHAR *deformated=NULL;
901 strcatW(ExecSeqQuery,action);
902 strcatW(ExecSeqQuery,end);
904 db = MsiGetActiveDatabase(hPackage);
905 rc = MsiDatabaseOpenViewW(db, ExecSeqQuery, &view);
908 if (rc != ERROR_SUCCESS)
911 rc = MsiViewExecute(view, 0);
912 if (rc != ERROR_SUCCESS)
915 MsiCloseHandle(view);
919 rc = MsiViewFetch(view,&row);
920 if (rc != ERROR_SUCCESS)
923 MsiCloseHandle(view);
927 type = MsiRecordGetInteger(row,2);
930 MsiRecordGetStringW(row,3,source,&sz);
932 MsiRecordGetStringW(row,4,target,&sz);
934 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
935 debugstr_w(source), debugstr_w(target));
937 /* we are ignoring ALOT of flags and important synchronization stuff */
938 switch (type & CUSTOM_ACTION_TYPE_MASK)
940 case 1: /* DLL file stored in a Binary table stream */
941 rc = HANDLE_CustomType1(hPackage,source,target,type);
943 case 2: /* EXE file stored in a Binary table strem */
944 rc = HANDLE_CustomType2(hPackage,source,target,type);
946 case 35: /* Directory set with formatted text. */
947 case 51: /* Property set with formatted text. */
948 deformat_string(hPackage,target,&deformated);
949 rc = MsiSetPropertyW(hPackage,source,deformated);
950 HeapFree(GetProcessHeap(),0,deformated);
953 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
954 type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
960 MsiCloseHandle(view);
964 static UINT store_binary_to_temp(MSIHANDLE hPackage, const LPWSTR source,
969 if (MsiGetPropertyW(hPackage, cszTempFolder, tmp_file, &sz)
971 GetTempPathW(MAX_PATH,tmp_file);
973 strcatW(tmp_file,source);
975 if (GetFileAttributesW(tmp_file) != INVALID_FILE_ATTRIBUTES)
977 TRACE("File already exists\n");
978 return ERROR_SUCCESS;
982 /* write out the file */
987 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','B','i'
988 ,'n','a','r','y',' ','w','h','e','r','e',' ','N','a','m','e','=','`',0};
989 static const WCHAR end[]={'`',0};
994 if (track_tempfile(hPackage, source, tmp_file)!=0)
995 FIXME("File Name in temp tracking collision\n");
997 the_file = CreateFileW(tmp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
998 FILE_ATTRIBUTE_NORMAL, NULL);
1000 if (the_file == INVALID_HANDLE_VALUE)
1001 return ERROR_FUNCTION_FAILED;
1003 strcatW(Query,source);
1006 db = MsiGetActiveDatabase(hPackage);
1007 rc = MsiDatabaseOpenViewW(db, Query, &view);
1010 if (rc != ERROR_SUCCESS)
1013 rc = MsiViewExecute(view, 0);
1014 if (rc != ERROR_SUCCESS)
1017 MsiCloseHandle(view);
1021 rc = MsiViewFetch(view,&row);
1022 if (rc != ERROR_SUCCESS)
1025 MsiCloseHandle(view);
1033 rc = MsiRecordReadStream(row,2,buffer,&sz);
1034 if (rc != ERROR_SUCCESS)
1036 ERR("Failed to get stream\n");
1037 CloseHandle(the_file);
1038 DeleteFileW(tmp_file);
1041 WriteFile(the_file,buffer,sz,&write,NULL);
1042 } while (sz == 1024);
1044 CloseHandle(the_file);
1046 MsiCloseHandle(row);
1048 MsiCloseHandle(view);
1051 return ERROR_SUCCESS;
1055 typedef UINT CustomEntry(MSIHANDLE);
1057 static UINT HANDLE_CustomType1(MSIHANDLE hPackage, const LPWSTR source,
1058 const LPWSTR target, const INT type)
1060 WCHAR tmp_file[MAX_PATH];
1065 store_binary_to_temp(hPackage, source, tmp_file);
1067 TRACE("Calling function %s from %s\n",debugstr_w(target),
1068 debugstr_w(tmp_file));
1072 FIXME("Asynchronous execution.. UNHANDLED\n");
1073 return ERROR_SUCCESS;
1076 if (!strchrW(tmp_file,'.'))
1078 static const WCHAR dot[]={'.',0};
1079 strcatW(tmp_file,dot);
1082 DLL = LoadLibraryW(tmp_file);
1085 proc = strdupWtoA( target );
1086 fn = (CustomEntry*)GetProcAddress(DLL,proc);
1089 TRACE("Calling function\n");
1093 ERR("Cannot load functon\n");
1095 HeapFree(GetProcessHeap(),0,proc);
1099 ERR("Unable to load library\n");
1101 return ERROR_SUCCESS;
1104 static UINT HANDLE_CustomType2(MSIHANDLE hPackage, const LPWSTR source,
1105 const LPWSTR target, const INT type)
1107 WCHAR tmp_file[MAX_PATH*2];
1109 PROCESS_INFORMATION info;
1112 static const WCHAR spc[] = {' ',0};
1114 memset(&si,0,sizeof(STARTUPINFOW));
1115 memset(&info,0,sizeof(PROCESS_INFORMATION));
1117 store_binary_to_temp(hPackage, source, tmp_file);
1119 strcatW(tmp_file,spc);
1120 deformat_string(hPackage,target,&deformated);
1121 strcatW(tmp_file,deformated);
1123 HeapFree(GetProcessHeap(),0,deformated);
1125 TRACE("executing exe %s \n",debugstr_w(tmp_file));
1127 rc = CreateProcessW(NULL, tmp_file, NULL, NULL, FALSE, 0, NULL,
1128 c_collen, &si, &info);
1132 ERR("Unable to execute command\n");
1133 return ERROR_SUCCESS;
1137 WaitForSingleObject(info.hProcess,INFINITE);
1139 return ERROR_SUCCESS;
1142 /***********************************************************************
1145 * Recursively create all directories in the path.
1147 * shamelessly stolen from setupapi/queue.c
1149 static BOOL create_full_pathW(const WCHAR *path)
1155 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1157 strcpyW(new_path, path);
1159 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1160 new_path[len - 1] = 0;
1162 while(!CreateDirectoryW(new_path, NULL))
1165 DWORD last_error = GetLastError();
1166 if(last_error == ERROR_ALREADY_EXISTS)
1169 if(last_error != ERROR_PATH_NOT_FOUND)
1175 if(!(slash = strrchrW(new_path, '\\')))
1181 len = slash - new_path;
1183 if(!create_full_pathW(new_path))
1188 new_path[len] = '\\';
1191 HeapFree(GetProcessHeap(), 0, new_path);
1196 * Also we cannot enable/disable components either, so for now I am just going
1197 * to do all the directories for all the components.
1199 static UINT ACTION_CreateFolders(MSIHANDLE hPackage)
1201 static const CHAR *ExecSeqQuery = "select Directory_ from CreateFolder";
1207 db = MsiGetActiveDatabase(hPackage);
1208 rc = MsiDatabaseOpenViewA(db, ExecSeqQuery, &view);
1211 if (rc != ERROR_SUCCESS)
1214 rc = MsiViewExecute(view, 0);
1215 if (rc != ERROR_SUCCESS)
1218 MsiCloseHandle(view);
1225 WCHAR full_path[MAX_PATH];
1230 rc = MsiViewFetch(view,&row);
1231 if (rc != ERROR_SUCCESS)
1238 rc = MsiRecordGetStringW(row,1,dir,&sz);
1240 if (rc!= ERROR_SUCCESS)
1242 ERR("Unable to get folder id \n");
1243 MsiCloseHandle(row);
1248 rc = resolve_folder(hPackage,dir,full_path,FALSE,FALSE,&folder);
1250 if (rc != ERROR_SUCCESS)
1252 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1253 MsiCloseHandle(row);
1257 TRACE("Folder is %s\n",debugstr_w(full_path));
1260 uirow = MsiCreateRecord(1);
1261 MsiRecordSetStringW(uirow,1,full_path);
1262 ui_actiondata(hPackage,szCreateFolders,uirow);
1263 MsiCloseHandle(uirow);
1265 if (folder->State == 0)
1266 create_full_pathW(full_path);
1270 MsiCloseHandle(row);
1273 MsiCloseHandle(view);
1278 static int load_component(MSIPACKAGE* package, MSIHANDLE row)
1280 int index = package->loaded_components;
1283 /* fill in the data */
1285 package->loaded_components++;
1286 if (package->loaded_components == 1)
1287 package->components = HeapAlloc(GetProcessHeap(),0,
1288 sizeof(MSICOMPONENT));
1290 package->components = HeapReAlloc(GetProcessHeap(),0,
1291 package->components, package->loaded_components *
1292 sizeof(MSICOMPONENT));
1294 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1297 MsiRecordGetStringW(row,1,package->components[index].Component,&sz);
1299 TRACE("Loading Component %s\n",
1300 debugstr_w(package->components[index].Component));
1303 if (!MsiRecordIsNull(row,2))
1304 MsiRecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1307 MsiRecordGetStringW(row,3,package->components[index].Directory,&sz);
1309 package->components[index].Attributes = MsiRecordGetInteger(row,4);
1312 MsiRecordGetStringW(row,5,package->components[index].Condition,&sz);
1315 MsiRecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1317 package->components[index].State = INSTALLSTATE_UNKNOWN;
1318 package->components[index].Enabled = TRUE;
1319 package->components[index].FeatureState= FALSE;
1324 static void load_feature(MSIPACKAGE* package, MSIHANDLE row)
1326 int index = package->loaded_features;
1328 static const WCHAR Query1[] = {'S','E','L','E','C','T',' ','C','o','m','p',
1329 'o','n','e','n','t','_',' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1330 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ','F','e',
1331 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1332 static const WCHAR Query2[] = {'S','E','L','E','C','T',' ','*',' ','F','R',
1333 'O','M',' ','C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ','C',
1334 'o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1341 /* fill in the data */
1343 package->loaded_features ++;
1344 if (package->loaded_features == 1)
1345 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1347 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1348 package->loaded_features * sizeof(MSIFEATURE));
1350 memset(&package->features[index],0,sizeof(MSIFEATURE));
1353 MsiRecordGetStringW(row,1,package->features[index].Feature,&sz);
1355 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1358 if (!MsiRecordIsNull(row,2))
1359 MsiRecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1362 if (!MsiRecordIsNull(row,3))
1363 MsiRecordGetStringW(row,3,package->features[index].Title,&sz);
1366 if (!MsiRecordIsNull(row,4))
1367 MsiRecordGetStringW(row,4,package->features[index].Description,&sz);
1369 if (!MsiRecordIsNull(row,5))
1370 package->features[index].Display = MsiRecordGetInteger(row,5);
1372 package->features[index].Level= MsiRecordGetInteger(row,6);
1375 if (!MsiRecordIsNull(row,7))
1376 MsiRecordGetStringW(row,7,package->features[index].Directory,&sz);
1378 package->features[index].Attributes= MsiRecordGetInteger(row,8);
1379 package->features[index].State = INSTALLSTATE_UNKNOWN;
1381 /* load feature components */
1383 sprintfW(Query,Query1,package->features[index].Feature);
1384 MsiDatabaseOpenViewW(package->db,Query,&view);
1385 MsiViewExecute(view,0);
1389 WCHAR buffer[0x100];
1392 INT cnt = package->features[index].ComponentCount;
1394 rc = MsiViewFetch(view,&row2);
1395 if (rc != ERROR_SUCCESS)
1399 MsiRecordGetStringW(row2,1,buffer,&sz);
1401 /* check to see if the component is already loaded */
1402 c_indx = get_loaded_component(package,buffer);
1405 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1407 package->features[index].Components[cnt] = c_indx;
1408 package->features[index].ComponentCount ++;
1411 sprintfW(Query,Query2,buffer);
1413 MsiDatabaseOpenViewW(package->db,Query,&view2);
1414 MsiViewExecute(view2,0);
1419 rc = MsiViewFetch(view2,&row3);
1420 if (rc != ERROR_SUCCESS)
1422 c_indx = load_component(package,row3);
1423 MsiCloseHandle(row3);
1425 package->features[index].Components[cnt] = c_indx;
1426 package->features[index].ComponentCount ++;
1428 MsiViewClose(view2);
1429 MsiCloseHandle(view2);
1430 MsiCloseHandle(row2);
1433 MsiCloseHandle(view);
1437 * I am not doing any of the costing functionality yet.
1438 * Mostly looking at doing the Component and Feature loading
1440 * The native MSI does ALOT of modification to tables here. Mostly adding alot
1441 * of temporary columns to the Feature and Component tables.
1443 * note: native msi also tracks the short filename. but I am only going to
1444 * track the long ones. Also looking at this directory table
1445 * it appears that the directory table does not get the parents
1446 * resolved base on property only based on their entrys in the
1449 static UINT ACTION_CostInitialize(MSIHANDLE hPackage)
1454 MSIPACKAGE *package;
1456 static const CHAR Query_all[] = "SELECT * FROM Feature";
1458 MsiSetPropertyA(hPackage,"CostingComplete","0");
1459 MsiSetPropertyW(hPackage, cszRootDrive , c_collen);
1461 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
1464 MsiDatabaseOpenViewA(package->db,Query_all,&view);
1465 MsiViewExecute(view,0);
1470 rc = MsiViewFetch(view,&row);
1471 if (rc != ERROR_SUCCESS)
1474 load_feature(package,row);
1475 MsiCloseHandle(row);
1478 MsiCloseHandle(view);
1480 return ERROR_SUCCESS;
1483 static int load_file(MSIPACKAGE* package, MSIHANDLE row)
1485 int index = package->loaded_files;
1487 WCHAR buffer[0x100];
1490 /* fill in the data */
1492 package->loaded_files++;
1493 if (package->loaded_files== 1)
1494 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1496 package->files = HeapReAlloc(GetProcessHeap(),0,
1497 package->files , package->loaded_files * sizeof(MSIFILE));
1499 memset(&package->files[index],0,sizeof(MSIFILE));
1502 MsiRecordGetStringW(row,1,package->files[index].File,&sz);
1505 MsiRecordGetStringW(row,2,buffer,&sz);
1507 package->files[index].ComponentIndex = -1;
1508 for (i = 0; i < package->loaded_components; i++)
1509 if (strcmpW(package->components[i].Component,buffer)==0)
1511 package->files[index].ComponentIndex = i;
1514 if (package->files[index].ComponentIndex == -1)
1515 ERR("Unfound Component %s\n",debugstr_w(buffer));
1518 MsiRecordGetStringW(row,3,package->files[index].FileName,&sz);
1520 reduce_to_longfilename(package->files[index].FileName);
1522 package->files[index].FileSize = MsiRecordGetInteger(row,4);
1525 if (!MsiRecordIsNull(row,5))
1526 MsiRecordGetStringW(row,5,package->files[index].Version,&sz);
1529 if (!MsiRecordIsNull(row,6))
1530 MsiRecordGetStringW(row,6,package->files[index].Language,&sz);
1532 if (!MsiRecordIsNull(row,7))
1533 package->files[index].Attributes= MsiRecordGetInteger(row,7);
1535 package->files[index].Sequence= MsiRecordGetInteger(row,8);
1537 package->files[index].Temporary = FALSE;
1538 package->files[index].State = 0;
1540 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1542 return ERROR_SUCCESS;
1545 static UINT ACTION_FileCost(MSIHANDLE hPackage)
1549 MSIPACKAGE *package;
1551 static const CHAR Query[] = "SELECT * FROM File Order by Sequence";
1553 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
1555 return ERROR_INVALID_HANDLE;
1557 rc = MsiDatabaseOpenViewA(package->db, Query, &view);
1558 if (rc != ERROR_SUCCESS)
1561 rc = MsiViewExecute(view, 0);
1562 if (rc != ERROR_SUCCESS)
1565 MsiCloseHandle(view);
1571 rc = MsiViewFetch(view,&row);
1572 if (rc != ERROR_SUCCESS)
1577 load_file(package,row);
1578 MsiCloseHandle(row);
1581 MsiCloseHandle(view);
1583 return ERROR_SUCCESS;
1586 static INT load_folder(MSIHANDLE hPackage, const WCHAR* dir)
1590 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','D','i','r','e','c',
1591 't','o','r','y',' ','w','h','e','r','e',' ','`','D','i','r','e','c','t',
1592 'o','r','y','`',' ','=',' ','`',0};
1593 static const WCHAR end[]={'`',0};
1596 WCHAR targetbuffer[0x100];
1597 WCHAR *srcdir = NULL;
1598 WCHAR *targetdir = NULL;
1599 WCHAR parent[0x100];
1602 MSIPACKAGE *package;
1605 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
1607 TRACE("Looking for dir %s\n",debugstr_w(dir));
1609 for (i = 0; i < package->loaded_folders; i++)
1611 if (strcmpW(package->folders[i].Directory,dir)==0)
1613 TRACE(" %s retuning on index %i\n",debugstr_w(dir),i);
1618 TRACE("Working to load %s\n",debugstr_w(dir));
1620 index = package->loaded_folders;
1622 package->loaded_folders++;
1623 if (package->loaded_folders== 1)
1624 package->folders = HeapAlloc(GetProcessHeap(),0,
1627 package->folders= HeapReAlloc(GetProcessHeap(),0,
1628 package->folders, package->loaded_folders*
1631 memset(&package->folders[index],0,sizeof(MSIFOLDER));
1633 strcpyW(package->folders[index].Directory,dir);
1638 rc = MsiDatabaseOpenViewW(package->db, Query, &view);
1640 if (rc != ERROR_SUCCESS)
1643 rc = MsiViewExecute(view, 0);
1644 if (rc != ERROR_SUCCESS)
1647 MsiCloseHandle(view);
1651 rc = MsiViewFetch(view,&row);
1652 if (rc != ERROR_SUCCESS)
1655 MsiCloseHandle(view);
1660 MsiRecordGetStringW(row,3,targetbuffer,&sz);
1661 targetdir=targetbuffer;
1663 /* split src and target dir */
1664 if (strchrW(targetdir,':'))
1666 srcdir=strchrW(targetdir,':');
1673 /* for now only pick long filename versions */
1674 if (strchrW(targetdir,'|'))
1676 targetdir = strchrW(targetdir,'|');
1680 if (srcdir && strchrW(srcdir,'|'))
1682 srcdir= strchrW(srcdir,'|');
1687 /* now check for root dirs */
1688 if (targetdir[0] == '.' && targetdir[1] == 0)
1691 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
1695 strcpyW(package->folders[index].TargetDefault,targetdir);
1698 strcpyW(package->folders[index].SourceDefault,srcdir);
1700 strcpyW(package->folders[index].SourceDefault,targetdir);
1702 if (MsiRecordIsNull(row,2))
1707 MsiRecordGetStringW(row,2,parent,&sz);
1712 i = load_folder(hPackage,parent);
1713 package->folders[index].ParentIndex = i;
1714 TRACE("Parent is index %i... %s %s\n",
1715 package->folders[index].ParentIndex,
1716 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
1717 debugstr_w(parent));
1720 package->folders[index].ParentIndex = -2;
1723 rc = MsiGetPropertyW(hPackage, dir, package->folders[index].Property, &sz);
1724 if (rc != ERROR_SUCCESS)
1725 package->folders[index].Property[0]=0;
1727 MsiCloseHandle(row);
1729 MsiCloseHandle(view);
1730 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
1734 static UINT resolve_folder(MSIHANDLE hPackage, LPCWSTR name, LPWSTR path,
1735 BOOL source, BOOL set_prop, MSIFOLDER **folder)
1737 MSIPACKAGE *package;
1739 UINT rc = ERROR_SUCCESS;
1742 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
1744 TRACE("Working to resolve %s\n",debugstr_w(name));
1749 /* special resolving for Target and Source root dir */
1750 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
1755 rc = MsiGetPropertyW(hPackage,cszTargetDir,path,&sz);
1756 if (rc != ERROR_SUCCESS)
1759 rc = MsiGetPropertyW(hPackage,cszRootDrive,path,&sz);
1761 MsiSetPropertyW(hPackage,cszTargetDir,path);
1764 *folder = &(package->folders[0]);
1770 rc = MsiGetPropertyW(hPackage,cszSourceDir,path,&sz);
1771 if (rc != ERROR_SUCCESS)
1774 rc = MsiGetPropertyW(hPackage,cszDatabase,path,&sz);
1775 if (rc == ERROR_SUCCESS)
1777 LPWSTR ptr = strrchrW(path,'\\');
1786 *folder = &(package->folders[0]);
1791 for (i = 0; i < package->loaded_folders; i++)
1793 if (strcmpW(package->folders[i].Directory,name)==0)
1797 if (i >= package->loaded_folders)
1798 return ERROR_FUNCTION_FAILED;
1801 *folder = &(package->folders[i]);
1803 if (!source && package->folders[i].ResolvedTarget[0])
1805 strcpyW(path,package->folders[i].ResolvedTarget);
1806 TRACE(" already resolved to %s\n",debugstr_w(path));
1807 return ERROR_SUCCESS;
1809 else if (source && package->folders[i].ResolvedSource[0])
1811 strcpyW(path,package->folders[i].ResolvedSource);
1812 return ERROR_SUCCESS;
1814 else if (!source && package->folders[i].Property[0])
1816 strcpyW(path,package->folders[i].Property);
1817 TRACE(" internally set to %s\n",debugstr_w(path));
1819 MsiSetPropertyW(hPackage,name,path);
1820 return ERROR_SUCCESS;
1823 if (package->folders[i].ParentIndex >= 0)
1825 TRACE(" ! Parent is %s\n", debugstr_w(package->folders[
1826 package->folders[i].ParentIndex].Directory));
1827 resolve_folder(hPackage, package->folders[
1828 package->folders[i].ParentIndex].Directory, path,source,
1833 if (package->folders[i].TargetDefault[0])
1835 strcatW(path,package->folders[i].TargetDefault);
1836 strcatW(path,cszbs);
1838 strcpyW(package->folders[i].ResolvedTarget,path);
1839 TRACE(" resolved into %s\n",debugstr_w(path));
1841 MsiSetPropertyW(hPackage,name,path);
1845 if (package->folders[i].SourceDefault[0])
1847 strcatW(path,package->folders[i].SourceDefault);
1848 strcatW(path,cszbs);
1850 strcpyW(package->folders[i].ResolvedSource,path);
1857 * Alot is done in this function aside from just the costing.
1858 * The costing needs to be implemented at some point but for now I am going
1859 * to focus on the directory building
1862 static UINT ACTION_CostFinalize(MSIHANDLE hPackage)
1864 static const CHAR *ExecSeqQuery = "select * from Directory";
1865 static const CHAR *ConditionQuery = "select * from Condition";
1868 MSIPACKAGE *package;
1871 TRACE("Building Directory properties\n");
1873 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
1875 rc = MsiDatabaseOpenViewA(package->db, ExecSeqQuery, &view);
1877 if (rc != ERROR_SUCCESS)
1880 rc = MsiViewExecute(view, 0);
1881 if (rc != ERROR_SUCCESS)
1884 MsiCloseHandle(view);
1891 WCHAR path[MAX_PATH];
1895 rc = MsiViewFetch(view,&row);
1897 if (rc != ERROR_SUCCESS)
1904 MsiRecordGetStringW(row,1,name,&sz);
1906 /* This helper function now does ALL the work */
1907 TRACE("Dir %s ...\n",debugstr_w(name));
1908 load_folder(hPackage,name);
1909 resolve_folder(hPackage,name,path,FALSE,TRUE,NULL);
1910 TRACE("resolves to %s\n",debugstr_w(path));
1912 MsiCloseHandle(row);
1915 MsiCloseHandle(view);
1917 TRACE("File calculations %i files\n",package->loaded_files);
1919 for (i = 0; i < package->loaded_files; i++)
1921 MSICOMPONENT* comp = NULL;
1922 MSIFILE* file= NULL;
1924 file = &package->files[i];
1925 if (file->ComponentIndex >= 0)
1926 comp = &package->components[file->ComponentIndex];
1930 /* calculate target */
1931 resolve_folder(hPackage, comp->Directory, file->TargetPath, FALSE,
1933 strcatW(file->TargetPath,file->FileName);
1935 TRACE("file %s resolves to %s\n",
1936 debugstr_w(file->File),debugstr_w(file->TargetPath));
1938 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
1941 comp->Cost += file->FileSize;
1945 if (file->Version[0])
1951 WCHAR filever[0x100];
1952 static const WCHAR name[] =
1953 {'\\','V','a','r','F','i','l','e','I','n','f','o',
1954 '\\','F','i','l','e','V','e','r','s','i','o','n',0};
1956 FIXME("Version comparison.. Untried Untested and most "
1957 "likely very very wrong\n");
1958 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
1959 version = HeapAlloc(GetProcessHeap(),0,versize);
1960 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
1962 VerQueryValueW(version,name,(LPVOID)filever,&sz);
1963 HeapFree(GetProcessHeap(),0,version);
1965 if (strcmpW(version,file->Version)<0)
1968 FIXME("cost should be diff in size\n");
1969 comp->Cost += file->FileSize;
1980 TRACE("Evaluating Condition Table\n");
1982 rc = MsiDatabaseOpenViewA(package->db, ConditionQuery, &view);
1984 if (rc != ERROR_SUCCESS)
1987 rc = MsiViewExecute(view, 0);
1988 if (rc != ERROR_SUCCESS)
1991 MsiCloseHandle(view);
1997 WCHAR Feature[0x100];
1998 WCHAR Condition[0x100];
2003 rc = MsiViewFetch(view,&row);
2005 if (rc != ERROR_SUCCESS)
2012 MsiRecordGetStringW(row,1,Feature,&sz);
2014 MsiRecordGetStringW(row,3,Condition,&sz);
2016 feature_index = get_loaded_feature(package,Feature);
2017 if (feature_index < 0)
2018 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2021 if (MsiEvaluateConditionW(hPackage,Condition) == MSICONDITION_TRUE)
2023 int level = MsiRecordGetInteger(row,2);
2024 TRACE("Reseting feature %s to level %i\n",debugstr_w(Feature),
2026 package->features[feature_index].Level = level;
2030 MsiCloseHandle(row);
2033 MsiCloseHandle(view);
2035 TRACE("Enabling or Disabling Components\n");
2036 for (i = 0; i < package->loaded_components; i++)
2038 if (package->components[i].Condition[0])
2040 if (MsiEvaluateConditionW(hPackage,
2041 package->components[i].Condition) == MSICONDITION_FALSE)
2043 TRACE("Disabling component %s\n",
2044 debugstr_w(package->components[i].Component));
2045 package->components[i].Enabled = FALSE;
2050 MsiSetPropertyA(hPackage,"CostingComplete","1");
2051 return ERROR_SUCCESS;
2055 * This is a helper function for handling embedded cabinet media
2057 static UINT writeout_cabinet_stream(MSIHANDLE hPackage, WCHAR* stream_name,
2066 WCHAR tmp[MAX_PATH];
2068 db = MsiGetActiveDatabase(hPackage);
2069 rc = read_raw_stream_data(db,stream_name,&data,&size);
2072 if (rc != ERROR_SUCCESS)
2076 if (MsiGetPropertyW(hPackage, cszTempFolder, tmp, &write))
2077 GetTempPathW(MAX_PATH,tmp);
2079 GetTempFileNameW(tmp,stream_name,0,source);
2081 track_tempfile(hPackage,strrchrW(source,'\\'), source);
2082 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2083 FILE_ATTRIBUTE_NORMAL, NULL);
2085 if (the_file == INVALID_HANDLE_VALUE)
2087 rc = ERROR_FUNCTION_FAILED;
2091 WriteFile(the_file,data,size,&write,NULL);
2092 CloseHandle(the_file);
2093 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2095 HeapFree(GetProcessHeap(),0,data);
2100 /***********************************************************************
2101 * extract_cabinet_file
2103 * Extract files from a cab file.
2105 static void (WINAPI *pExtractFiles)( LPSTR, LPSTR, DWORD, DWORD, DWORD, DWORD );
2107 static BOOL extract_cabinet_file_advpack( const WCHAR *cabinet,
2110 static HMODULE advpack;
2112 char *cab_path, *cab_file;
2116 if (!advpack && !(advpack = LoadLibraryA( "advpack.dll" )))
2118 ERR( "could not load advpack.dll\n" );
2121 if (!(pExtractFiles = (void *)GetProcAddress( advpack, "ExtractFiles"
2124 ERR( "could not find ExtractFiles in advpack.dll\n" );
2129 if (!(cab_file = strdupWtoA( cabinet ))) return FALSE;
2130 if (!(cab_path = strdupWtoA( root ))) return FALSE;
2132 FIXME( "awful hack: extracting cabinet %s\n", debugstr_a(cab_file) );
2133 pExtractFiles( cab_file, cab_path, 0, 0, 0, 0 );
2134 HeapFree( GetProcessHeap(), 0, cab_file );
2135 HeapFree( GetProcessHeap(), 0, cab_path );
2139 static BOOL extract_cabinet_file_cabinet( const WCHAR *cabinet,
2143 /* from cabinet.h */
2145 struct ExtractFileList {
2147 struct ExtractFileList *next;
2148 BOOL unknown; /* always 1L */
2152 long result1; /* 0x000 */
2153 long unknown1[3]; /* 0x004 */
2154 struct ExtractFileList* filelist; /* 0x010 */
2155 long filecount; /* 0x014 */
2156 long unknown2; /* 0x018 */
2157 char directory[0x104]; /* 0x01c */
2158 char lastfile[0x20c]; /* 0x120 */
2161 HRESULT WINAPI Extract(EXTRACTdest *dest, LPCSTR what);
2163 char *cab_path, *src_path;
2165 struct ExtractFileList fl;
2167 if (!(cab_path = strdupWtoA( cabinet ))) return FALSE;
2168 if (!(src_path = strdupWtoA( root ))) return FALSE;
2170 memset(&exd,0,sizeof(exd));
2171 strcpy(exd.directory,src_path);
2173 fl.filename = cab_path;
2177 FIXME( "more aweful hack: extracting cabinet %s\n", debugstr_a(cab_path) );
2178 Extract(&exd,cab_path);
2180 HeapFree( GetProcessHeap(), 0, cab_path );
2181 HeapFree( GetProcessHeap(), 0, src_path );
2185 static BOOL extract_cabinet_file(const WCHAR* source, const WCHAR* path)
2187 TRACE("Extracting %s to %s\n",debugstr_w(source), debugstr_w(path));
2188 if (!extract_cabinet_file_advpack(source,path))
2189 return extract_cabinet_file_cabinet(source,path);
2193 static UINT ready_media_for_file(MSIHANDLE hPackage, UINT sequence,
2199 WCHAR source[MAX_PATH];
2200 static const CHAR *ExecSeqQuery =
2201 "select * from Media where LastSequence >= %i order by LastSequence";
2206 static INT last_sequence = 0;
2209 if (sequence <= last_sequence)
2211 TRACE("Media already ready (%i, %i)\n",sequence,last_sequence);
2212 return ERROR_SUCCESS;
2215 sprintf(Query,ExecSeqQuery,sequence);
2217 db = MsiGetActiveDatabase(hPackage);
2218 rc = MsiDatabaseOpenViewA(db, Query, &view);
2221 if (rc != ERROR_SUCCESS)
2224 rc = MsiViewExecute(view, 0);
2225 if (rc != ERROR_SUCCESS)
2228 MsiCloseHandle(view);
2232 rc = MsiViewFetch(view,&row);
2233 if (rc != ERROR_SUCCESS)
2236 MsiCloseHandle(view);
2239 seq = MsiRecordGetInteger(row,2);
2240 last_sequence = seq;
2242 if (!MsiRecordIsNull(row,4))
2245 MsiRecordGetStringW(row,4,cab,&sz);
2246 TRACE("Source is CAB %s\n",debugstr_w(cab));
2247 /* the stream does not contain the # character */
2250 writeout_cabinet_stream(hPackage,&cab[1],source);
2251 strcpyW(path,source);
2252 *(strrchrW(path,'\\')+1)=0;
2257 if (MsiGetPropertyW(hPackage, cszSourceDir, source, &sz))
2259 ERR("No Source dir defined \n");
2260 rc = ERROR_FUNCTION_FAILED;
2264 strcpyW(path,source);
2265 strcatW(source,cab);
2266 /* extract the cab file into a folder in the temp folder */
2268 if (MsiGetPropertyW(hPackage, cszTempFolder,path, &sz)
2270 GetTempPathW(MAX_PATH,path);
2273 rc = !extract_cabinet_file(source,path);
2275 MsiCloseHandle(row);
2277 MsiCloseHandle(view);
2281 inline static UINT create_component_directory (MSIHANDLE hPackage, MSIPACKAGE*
2282 package, INT component)
2286 WCHAR install_path[MAX_PATH];
2288 rc = resolve_folder(hPackage, package->components[component].Directory,
2289 install_path, FALSE, FALSE, &folder);
2291 if (rc != ERROR_SUCCESS)
2294 /* create the path */
2295 if (folder->State == 0)
2297 create_full_pathW(install_path);
2304 static UINT ACTION_InstallFiles(MSIHANDLE hPackage)
2306 UINT rc = ERROR_SUCCESS;
2308 MSIPACKAGE *package;
2310 WCHAR uipath[MAX_PATH];
2312 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
2315 return ERROR_INVALID_HANDLE;
2317 /* increment progress bar each time action data is sent */
2318 ui_progress(hPackage,1,1,1,0);
2320 for (index = 0; index < package->loaded_files; index++)
2322 WCHAR path_to_source[MAX_PATH];
2325 file = &package->files[index];
2327 if (file->Temporary)
2330 if (!package->components[file->ComponentIndex].Enabled ||
2331 !package->components[file->ComponentIndex].FeatureState)
2333 TRACE("File %s is not scheduled for install\n",
2334 debugstr_w(file->File));
2338 if ((file->State == 1) || (file->State == 2))
2340 TRACE("Installing %s\n",debugstr_w(file->File));
2341 rc = ready_media_for_file(hPackage,file->Sequence,path_to_source);
2344 * our file table could change here because a new temp file
2345 * may have been created
2347 file = &package->files[index];
2348 if (rc != ERROR_SUCCESS)
2350 ERR("Unable to ready media\n");
2351 rc = ERROR_FUNCTION_FAILED;
2355 create_component_directory(hPackage, package, file->ComponentIndex);
2357 strcpyW(file->SourcePath, path_to_source);
2358 strcatW(file->SourcePath, file->File);
2360 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
2361 debugstr_w(file->TargetPath));
2364 uirow=MsiCreateRecord(9);
2365 MsiRecordSetStringW(uirow,1,file->File);
2366 strcpyW(uipath,file->TargetPath);
2367 *(strrchrW(uipath,'\\')+1)=0;
2368 MsiRecordSetStringW(uirow,9,uipath);
2369 MsiRecordSetInteger(uirow,6,file->FileSize);
2370 ui_actiondata(hPackage,szInstallFiles,uirow);
2371 MsiCloseHandle(uirow);
2373 rc = !MoveFileW(file->SourcePath,file->TargetPath);
2374 ui_progress(hPackage,2,0,0,0);
2378 ERR("Unable to move file (error %li)\n",GetLastError());
2389 inline static UINT get_file_target(MSIHANDLE hPackage, LPCWSTR file_key,
2392 MSIPACKAGE *package;
2395 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
2397 return ERROR_INVALID_HANDLE;
2399 for (index = 0; index < package->loaded_files; index ++)
2401 if (strcmpW(file_key,package->files[index].File)==0)
2403 if (package->files[index].State >= 3)
2405 strcpyW(file_source,package->files[index].TargetPath);
2406 return ERROR_SUCCESS;
2409 return ERROR_FILE_NOT_FOUND;
2413 return ERROR_FUNCTION_FAILED;
2416 static UINT ACTION_DuplicateFiles(MSIHANDLE hPackage)
2421 static const CHAR *ExecSeqQuery = "select * from DuplicateFile";
2422 MSIPACKAGE* package;
2424 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
2426 return ERROR_INVALID_HANDLE;
2428 rc = MsiDatabaseOpenViewA(package->db, ExecSeqQuery, &view);
2430 if (rc != ERROR_SUCCESS)
2433 rc = MsiViewExecute(view, 0);
2434 if (rc != ERROR_SUCCESS)
2437 MsiCloseHandle(view);
2443 WCHAR file_key[0x100];
2444 WCHAR file_source[MAX_PATH];
2445 WCHAR dest_name[0x100];
2446 WCHAR dest_path[MAX_PATH];
2447 WCHAR component[0x100];
2448 INT component_index;
2452 rc = MsiViewFetch(view,&row);
2453 if (rc != ERROR_SUCCESS)
2460 rc = MsiRecordGetStringW(row,2,component,&sz);
2461 if (rc != ERROR_SUCCESS)
2463 ERR("Unable to get component\n");
2464 MsiCloseHandle(row);
2468 component_index = get_loaded_component(package,component);
2469 if (!package->components[component_index].Enabled ||
2470 !package->components[component_index].FeatureState)
2472 TRACE("Skipping copy due to disabled component\n");
2473 MsiCloseHandle(row);
2478 rc = MsiRecordGetStringW(row,3,file_key,&sz);
2479 if (rc != ERROR_SUCCESS)
2481 ERR("Unable to get file key\n");
2482 MsiCloseHandle(row);
2486 rc = get_file_target(hPackage,file_key,file_source);
2488 if (rc != ERROR_SUCCESS)
2490 ERR("Original file unknown %s\n",debugstr_w(file_key));
2491 MsiCloseHandle(row);
2495 if (MsiRecordIsNull(row,4))
2497 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
2502 MsiRecordGetStringW(row,4,dest_name,&sz);
2503 reduce_to_longfilename(dest_name);
2506 if (MsiRecordIsNull(row,5))
2508 strcpyW(dest_path,file_source);
2509 *strrchrW(dest_path,'\\')=0;
2513 WCHAR destkey[0x100];
2515 MsiRecordGetStringW(row,5,destkey,&sz);
2517 rc = resolve_folder(hPackage, destkey, dest_path,FALSE,FALSE,NULL);
2518 if (rc != ERROR_SUCCESS)
2520 ERR("Unable to get destination folder\n");
2521 MsiCloseHandle(row);
2526 strcatW(dest_path,dest_name);
2528 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
2529 debugstr_w(dest_path));
2531 if (strcmpW(file_source,dest_path))
2532 rc = !CopyFileW(file_source,dest_path,TRUE);
2536 if (rc != ERROR_SUCCESS)
2537 ERR("Failed to copy file\n");
2539 FIXME("We should track these duplicate files as well\n");
2541 MsiCloseHandle(row);
2544 MsiCloseHandle(view);
2550 /* OK this value is "interpretted" and then formatted based on the
2551 first few characters */
2552 static LPSTR parse_value(MSIHANDLE hPackage, WCHAR *value, DWORD *type,
2556 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
2565 deformat_string(hPackage, &value[2], &deformated);
2567 /* binary value type */
2570 *size = strlenW(ptr)/2;
2571 data = HeapAlloc(GetProcessHeap(),0,*size);
2583 data[count] = (BYTE)strtol(byte,NULL,0);
2586 HeapFree(GetProcessHeap(),0,deformated);
2588 TRACE("Data %li bytes(%i)\n",*size,count);
2593 deformat_string(hPackage, &value[1], &deformated);
2596 *size = sizeof(DWORD);
2597 data = HeapAlloc(GetProcessHeap(),0,*size);
2598 *(LPDWORD)data = atoiW(deformated);
2599 TRACE("DWORD %i\n",*data);
2601 HeapFree(GetProcessHeap(),0,deformated);
2614 *type=REG_EXPAND_SZ;
2622 *size = deformat_string(hPackage, ptr,(LPWSTR*)&data);
2627 static UINT ACTION_WriteRegistryValues(MSIHANDLE hPackage)
2632 static const CHAR *ExecSeqQuery = "select * from Registry";
2633 MSIPACKAGE *package;
2635 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
2637 return ERROR_INVALID_HANDLE;
2639 rc = MsiDatabaseOpenViewA(package->db, ExecSeqQuery, &view);
2641 if (rc != ERROR_SUCCESS)
2644 rc = MsiViewExecute(view, 0);
2645 if (rc != ERROR_SUCCESS)
2648 MsiCloseHandle(view);
2652 /* increment progress bar each time action data is sent */
2653 ui_progress(hPackage,1,1,1,0);
2657 static const WCHAR szHCR[] =
2658 {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T','\\',0};
2659 static const WCHAR szHCU[] =
2660 {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',0};
2661 static const WCHAR szHLM[] =
2662 {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',
2664 static const WCHAR szHU[] =
2665 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
2670 LPSTR value_data = NULL;
2671 HKEY root_key, hkey;
2673 WCHAR component[0x100];
2674 INT component_index;
2681 rc = MsiViewFetch(view,&row);
2682 if (rc != ERROR_SUCCESS)
2689 MsiRecordGetStringW(row,6,component,&sz);
2690 component_index = get_loaded_component(package,component);
2692 if (!package->components[component_index].Enabled ||
2693 !package->components[component_index].FeatureState)
2695 TRACE("Skipping write due to disabled component\n");
2696 MsiCloseHandle(row);
2700 /* null values have special meanings during uninstalls and such */
2702 if(MsiRecordIsNull(row,5))
2704 MsiCloseHandle(row);
2708 root = MsiRecordGetInteger(row,2);
2710 MsiRecordGetStringW(row,3,key,&sz);
2713 if (MsiRecordIsNull(row,4))
2716 MsiRecordGetStringW(row,4,name,&sz);
2718 /* get the root key */
2721 case 0: root_key = HKEY_CLASSES_ROOT;
2722 strcpyW(uikey,szHCR); break;
2723 case 1: root_key = HKEY_CURRENT_USER;
2724 strcpyW(uikey,szHCU); break;
2725 case 2: root_key = HKEY_LOCAL_MACHINE;
2726 strcpyW(uikey,szHLM); break;
2727 case 3: root_key = HKEY_USERS;
2728 strcpyW(uikey,szHU); break;
2730 ERR("Unknown root %i\n",root);
2736 MsiCloseHandle(row);
2741 if (RegCreateKeyW( root_key, key, &hkey))
2743 ERR("Could not create key %s\n",debugstr_w(key));
2744 MsiCloseHandle(row);
2749 MsiRecordGetStringW(row,5,NULL,&sz);
2751 value = HeapAlloc(GetProcessHeap(),0,sz * sizeof(WCHAR));
2752 MsiRecordGetStringW(row,5,value,&sz);
2753 value_data = parse_value(hPackage, value, &type, &size);
2757 TRACE("Setting value %s\n",debugstr_w(name));
2758 RegSetValueExW(hkey, name, 0, type, value_data, size);
2760 uirow = MsiCreateRecord(3);
2761 MsiRecordSetStringW(uirow,2,name);
2762 MsiRecordSetStringW(uirow,1,uikey);
2765 MsiRecordSetStringW(uirow,3,(LPWSTR)value_data);
2767 MsiRecordSetStringW(uirow,3,value);
2769 ui_actiondata(hPackage,szWriteRegistryValues,uirow);
2770 ui_progress(hPackage,2,0,0,0);
2771 MsiCloseHandle(uirow);
2773 HeapFree(GetProcessHeap(),0,value_data);
2775 HeapFree(GetProcessHeap(),0,value);
2777 MsiCloseHandle(row);
2781 MsiCloseHandle(view);
2786 * This helper function should probably go alot of places
2788 * Thinking about this, maybe this should become yet another Bison file
2790 static DWORD deformat_string(MSIHANDLE hPackage, WCHAR* ptr,WCHAR** data)
2799 /* scan for special characters */
2800 if (!strchrW(ptr,'[') || (strchrW(ptr,'[') && !strchrW(ptr,']')))
2803 size = (strlenW(ptr)+1) * sizeof(WCHAR);
2804 *data = HeapAlloc(GetProcessHeap(),0,size);
2809 /* formatted string located */
2810 mark = strchrW(ptr,'[');
2813 INT cnt = (mark - ptr);
2814 TRACE("%i (%i) characters before marker\n",cnt,(mark-ptr));
2815 size = cnt * sizeof(WCHAR);
2816 size += sizeof(WCHAR);
2817 *data = HeapAlloc(GetProcessHeap(),0,size);
2818 strncpyW(*data,ptr,cnt);
2823 size = sizeof(WCHAR);
2824 *data = HeapAlloc(GetProcessHeap(),0,size);
2829 *strchrW(key,']')=0;
2830 mark = strchrW(mark,']');
2832 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
2834 if (MsiGetPropertyW(hPackage, key, value,&sz) == ERROR_SUCCESS)
2837 chunk = (strlenW(value)+1) * sizeof(WCHAR);
2839 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
2841 strcatW(*data,value);
2843 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
2847 chunk = (strlenW(mark)+1) * sizeof(WCHAR);
2849 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
2851 strcatW(*data,mark);
2853 (*data)[strlenW(*data)]=0;
2854 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
2856 /* recursively do this to clean up */
2857 mark = HeapAlloc(GetProcessHeap(),0,size);
2858 strcpyW(mark,*data);
2859 TRACE("String at this point %s\n",debugstr_w(mark));
2860 size = deformat_string(hPackage,mark,data);
2861 HeapFree(GetProcessHeap(),0,mark);
2865 static UINT ACTION_InstallInitialize(MSIHANDLE hPackage)
2870 MSIPACKAGE *package;
2873 LPWSTR override = NULL;
2874 static const WCHAR addlocal[]={'A','D','D','L','O','C','A','L',0};
2875 static const WCHAR all[]={'A','L','L',0};
2877 /* I do not know if this is where it should happen.. but */
2879 TRACE("Checking Install Level\n");
2882 if (MsiGetPropertyA(hPackage,"INSTALLLEVEL",level,&sz)==ERROR_SUCCESS)
2883 install_level = atoi(level);
2888 rc = MsiGetPropertyA(hPackage,"ADDLOCAL",NULL,&sz);
2889 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
2892 override = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
2893 MsiGetPropertyW(hPackage, addlocal,override,&sz);
2896 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
2898 return ERROR_INVALID_HANDLE;
2901 * components FeatureState defaults to FALSE. the idea is we want to
2902 * enable the component is ANY feature that uses it is enabled to install
2904 for(i = 0; i < package->loaded_features; i++)
2906 BOOL feature_state= ((package->features[i].Level > 0) &&
2907 (package->features[i].Level <= install_level));
2909 if (override && (strcmpiW(override,all)==0 ||
2910 strstrW(override,package->features[i].Feature)))
2912 TRACE("Override of install level found\n");
2913 feature_state = TRUE;
2916 TRACE("Feature %s has a state of %i\n",
2917 debugstr_w(package->features[i].Feature), feature_state);
2918 for( j = 0; j < package->features[i].ComponentCount; j++)
2920 package->components[package->features[i].Components[j]].FeatureState
2924 if (override != NULL)
2925 HeapFree(GetProcessHeap(),0,override);
2927 * so basically we ONLY want to install a component if its Enabled AND
2928 * FeatureState are both TRUE
2930 return ERROR_SUCCESS;
2933 static UINT ACTION_InstallValidate(MSIHANDLE hPackage)
2936 static const CHAR q1[]="SELECT * FROM Registry";
2941 MSIPACKAGE* package;
2943 TRACE(" InstallValidate \n");
2945 db = MsiGetActiveDatabase(hPackage);
2946 rc = MsiDatabaseOpenViewA(db, q1, &view);
2947 rc = MsiViewExecute(view, 0);
2950 rc = MsiViewFetch(view,&row);
2951 if (rc != ERROR_SUCCESS)
2958 MsiCloseHandle(row);
2961 MsiCloseHandle(view);
2964 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
2965 ui_progress(hPackage,0,progress+package->loaded_files,0,0);
2967 return ERROR_SUCCESS;
2970 static UINT ACTION_LaunchConditions(MSIHANDLE hPackage)
2975 static const CHAR *ExecSeqQuery = "SELECT * from LaunchCondition";
2977 static const WCHAR title[]=
2978 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
2980 TRACE("Checking launch conditions\n");
2982 db = MsiGetActiveDatabase(hPackage);
2983 rc = MsiDatabaseOpenViewA(db, ExecSeqQuery, &view);
2986 if (rc != ERROR_SUCCESS)
2989 rc = MsiViewExecute(view, 0);
2990 if (rc != ERROR_SUCCESS)
2993 MsiCloseHandle(view);
2998 while (rc == ERROR_SUCCESS)
3001 LPWSTR message = NULL;
3004 rc = MsiViewFetch(view,&row);
3005 if (rc != ERROR_SUCCESS)
3012 MsiRecordGetStringW(row,1,NULL,&sz);
3014 cond = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
3015 MsiRecordGetStringW(row,1,cond,&sz);
3017 if (MsiEvaluateConditionW(hPackage,cond) != MSICONDITION_TRUE)
3020 MsiRecordGetStringW(row,2,NULL,&sz);
3022 message = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
3023 MsiRecordGetStringW(row,2,message,&sz);
3024 MessageBoxW(NULL,message,title,MB_OK);
3025 HeapFree(GetProcessHeap(),0,message);
3026 rc = ERROR_FUNCTION_FAILED;
3028 HeapFree(GetProcessHeap(),0,cond);
3029 MsiCloseHandle(row);
3032 MsiCloseHandle(view);
3036 static void resolve_keypath(MSIHANDLE hPackage, MSIPACKAGE* package, INT
3037 component_index, WCHAR *keypath)
3039 MSICOMPONENT* cmp = &package->components[component_index];
3041 if (cmp->KeyPath[0]==0)
3043 resolve_folder(hPackage,cmp->Directory,keypath,FALSE,FALSE,NULL);
3046 if ((cmp->Attributes & 0x4) || (cmp->Attributes & 0x20))
3048 FIXME("UNIMPLEMENTED keypath as Registry or ODBC Source\n");
3054 j = get_loaded_file(package,cmp->KeyPath);
3057 strcpyW(keypath,package->files[j].TargetPath);
3062 * Ok further analysis makes me think that this work is
3063 * actually done in the PublishComponents and PublishFeatures
3064 * step. And not here. It appears like the keypath and all that is
3065 * resolved in this step, however actaully written in the Publish steps.
3066 * But we will leave it here for now
3068 static UINT ACTION_ProcessComponents(MSIHANDLE hPackage)
3070 MSIPACKAGE* package;
3071 WCHAR productcode[0x100];
3072 WCHAR squished_pc[0x100];
3073 WCHAR squished_cc[0x100];
3077 HKEY hkey=0,hkey2=0,hkey3=0;
3078 static const WCHAR szProductCode[]=
3079 {'P','r','o','d','u','c','t','C','o','d','e',0};
3080 static const WCHAR szInstaller[] = {
3081 'S','o','f','t','w','a','r','e','\\',
3082 'M','i','c','r','o','s','o','f','t','\\',
3083 'W','i','n','d','o','w','s','\\',
3084 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3085 'I','n','s','t','a','l','l','e','r',0 };
3086 static const WCHAR szFeatures[] = {
3087 'F','e','a','t','u','r','e','s',0 };
3088 static const WCHAR szComponents[] = {
3089 'C','o','m','p','o','n','e','n','t','s',0 };
3091 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
3093 return ERROR_INVALID_HANDLE;
3095 /* writes the Component and Features values to the registry */
3097 rc = MsiGetPropertyW(hPackage,szProductCode,productcode,&sz);
3099 if (rc != ERROR_SUCCESS)
3100 return ERROR_SUCCESS;
3102 squash_guid(productcode,squished_pc);
3103 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller,&hkey);
3104 if (rc != ERROR_SUCCESS)
3107 rc = RegCreateKeyW(hkey,szFeatures,&hkey2);
3108 if (rc != ERROR_SUCCESS)
3111 rc = RegCreateKeyW(hkey2,squished_pc,&hkey3);
3112 if (rc != ERROR_SUCCESS)
3115 /* I have no idea what goes in here */
3116 for (i = 0; i < package->loaded_features; i++)
3117 RegSetValueExW(hkey3,package->features[i].Feature,0,REG_SZ,NULL,0);
3122 rc = RegCreateKeyW(hkey,szComponents,&hkey2);
3123 if (rc != ERROR_SUCCESS)
3126 for (i = 0; i < package->loaded_components; i++)
3128 if (package->components[i].ComponentId[0]!=0)
3130 WCHAR keypath[0x1000];
3133 squash_guid(package->components[i].ComponentId,squished_cc);
3134 rc = RegCreateKeyW(hkey2,squished_cc,&hkey3);
3135 if (rc != ERROR_SUCCESS)
3138 resolve_keypath(hPackage,package,i,keypath);
3140 RegSetValueExW(hkey3,squished_pc,0,REG_SZ,(LPVOID)keypath,
3141 (strlenW(keypath)+1)*sizeof(WCHAR));
3145 uirow = MsiCreateRecord(3);
3146 MsiRecordSetStringW(uirow,1,productcode);
3147 MsiRecordSetStringW(uirow,2,package->components[i].ComponentId);
3148 MsiRecordSetStringW(uirow,3,keypath);
3149 ui_actiondata(hPackage,szProcessComponents,uirow);
3150 MsiCloseHandle(uirow);
3159 static UINT ACTION_RegisterTypeLibraries(MSIHANDLE hPackage)
3162 * ok this is a bit confusting.. I am given a _Component key and i believe
3163 * that the file that is being registered as a type library is the "key file
3164 * of that component" which i interpert to mean "The file in the KeyPath of
3170 static const CHAR *Query = "SELECT * from TypeLib";
3171 MSIPACKAGE* package;
3175 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
3177 return ERROR_INVALID_HANDLE;
3179 rc = MsiDatabaseOpenViewA(package->db, Query, &view);
3181 if (rc != ERROR_SUCCESS)
3184 rc = MsiViewExecute(view, 0);
3185 if (rc != ERROR_SUCCESS)
3188 MsiCloseHandle(view);
3194 WCHAR component[0x100];
3198 rc = MsiViewFetch(view,&row);
3199 if (rc != ERROR_SUCCESS)
3206 MsiRecordGetStringW(row,3,component,&sz);
3208 index = get_loaded_component(package,component);
3211 MsiCloseHandle(row);
3215 if (!package->components[index].Enabled ||
3216 !package->components[index].FeatureState)
3218 TRACE("Skipping typelib reg due to disabled component\n");
3219 MsiCloseHandle(row);
3223 index = get_loaded_file(package,package->components[index].KeyPath);
3227 MsiCloseHandle(row);
3231 res = LoadTypeLib(package->files[index].TargetPath,&ptLib);
3234 WCHAR help[MAX_PATH];
3235 WCHAR helpid[0x100];
3238 MsiRecordGetStringW(row,6,helpid,&sz);
3240 resolve_folder(hPackage,helpid,help,FALSE,FALSE,NULL);
3242 res = RegisterTypeLib(ptLib,package->files[index].TargetPath,help);
3243 if (!SUCCEEDED(res))
3244 ERR("Failed to register type library %s\n",
3245 debugstr_w(package->files[index].TargetPath));
3248 /* yes the row has more fields than i need, but #1 is
3249 correct and the only one i need. why make a new row */
3251 ui_actiondata(hPackage,szRegisterTypeLibraries,row);
3253 TRACE("Registered %s\n",
3254 debugstr_w(package->files[index].TargetPath));
3258 ITypeLib_Release(ptLib);
3261 ERR("Failed to load type library %s\n",
3262 debugstr_w(package->files[index].TargetPath));
3264 MsiCloseHandle(row);
3267 MsiCloseHandle(view);
3272 static UINT register_appid(MSIHANDLE hPackage, LPCWSTR clsid, LPCWSTR app )
3274 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3278 static const WCHAR ExecSeqQuery[] =
3279 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','p','p','I'
3280 ,'d',' ','w','h','e','r','e',' ','A','p','p','I','d','=','`','%','s','`',0};
3281 WCHAR Query[0x1000];
3282 MSIPACKAGE* package;
3287 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
3289 return ERROR_INVALID_HANDLE;
3292 sprintfW(Query,ExecSeqQuery,clsid);
3294 rc = MsiDatabaseOpenViewW(package->db, Query, &view);
3295 if (rc != ERROR_SUCCESS)
3298 rc = MsiViewExecute(view, 0);
3299 if (rc != ERROR_SUCCESS)
3302 MsiCloseHandle(view);
3306 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
3307 RegCreateKeyW(hkey2,clsid,&hkey3);
3308 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
3309 (strlenW(app)+1)*sizeof(WCHAR));
3311 MsiViewFetch(view,&row);
3313 if (!MsiRecordIsNull(row,2))
3315 LPWSTR deformated=0;
3317 static const WCHAR szRemoteServerName[] =
3318 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
3320 MsiRecordGetStringW(row,2,NULL,&sz);
3322 buffer = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
3323 MsiRecordGetStringW(row,2,buffer,&sz);
3324 size = deformat_string(hPackage,buffer,&deformated);
3325 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
3327 HeapFree(GetProcessHeap(),0,deformated);
3328 HeapFree(GetProcessHeap(),0,buffer);
3331 if (!MsiRecordIsNull(row,3))
3333 static const WCHAR szLocalService[] =
3334 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
3337 MsiRecordGetStringW(row,3,NULL,&sz);
3339 size = sz * sizeof(WCHAR);
3340 buffer = HeapAlloc(GetProcessHeap(),0,size);
3341 MsiRecordGetStringW(row,3,buffer,&sz);
3342 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
3343 HeapFree(GetProcessHeap(),0,buffer);
3346 if (!MsiRecordIsNull(row,4))
3348 static const WCHAR szService[] =
3349 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
3352 MsiRecordGetStringW(row,4,NULL,&sz);
3354 size = sz * sizeof(WCHAR);
3355 buffer = HeapAlloc(GetProcessHeap(),0,size);
3356 MsiRecordGetStringW(row,4,buffer,&sz);
3357 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
3358 HeapFree(GetProcessHeap(),0,buffer);
3361 if (!MsiRecordIsNull(row,5))
3363 static const WCHAR szDLL[] =
3364 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
3367 MsiRecordGetStringW(row,5,NULL,&sz);
3369 size = sz * sizeof(WCHAR);
3370 buffer = HeapAlloc(GetProcessHeap(),0,size);
3371 MsiRecordGetStringW(row,5,buffer,&sz);
3372 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
3373 HeapFree(GetProcessHeap(),0,buffer);
3376 if (!MsiRecordIsNull(row,6))
3378 static const WCHAR szActivate[] =
3379 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
3380 static const WCHAR szY[] = {'Y',0};
3382 if (MsiRecordGetInteger(row,6))
3383 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
3386 if (!MsiRecordIsNull(row,7))
3388 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
3389 static const WCHAR szUser[] =
3390 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
3392 if (MsiRecordGetInteger(row,7))
3393 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
3396 MsiCloseHandle(row);
3398 MsiCloseHandle(view);
3404 static UINT ACTION_RegisterClassInfo(MSIHANDLE hPackage)
3407 * again i am assuming the words, "Whose key file respesents" when refering
3408 * to a Component as to meanin that Components KeyPath file
3410 * Also there is a very strong connection between ClassInfo and ProgID
3411 * that i am mostly glossing over.
3412 * What would be more proper is to load the ClassInfo and the ProgID info
3413 * into memory data structures and then be able to enable and disable them
3414 * based on component.
3420 static const CHAR *ExecSeqQuery = "SELECT * from Class";
3421 MSIPACKAGE* package;
3422 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3423 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
3424 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3425 HKEY hkey,hkey2,hkey3;
3427 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
3429 return ERROR_INVALID_HANDLE;
3431 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
3432 if (rc != ERROR_SUCCESS)
3433 return ERROR_FUNCTION_FAILED;
3435 rc = MsiDatabaseOpenViewA(package->db, ExecSeqQuery, &view);
3437 if (rc != ERROR_SUCCESS)
3440 rc = MsiViewExecute(view, 0);
3441 if (rc != ERROR_SUCCESS)
3444 MsiCloseHandle(view);
3451 WCHAR buffer[0x100];
3456 rc = MsiViewFetch(view,&row);
3457 if (rc != ERROR_SUCCESS)
3464 MsiRecordGetStringW(row,3,buffer,&sz);
3466 index = get_loaded_component(package,buffer);
3470 MsiCloseHandle(row);
3474 if (!package->components[index].Enabled ||
3475 !package->components[index].FeatureState)
3477 TRACE("Skipping class reg due to disabled component\n");
3478 MsiCloseHandle(row);
3483 MsiRecordGetStringW(row,1,clsid,&sz);
3484 RegCreateKeyW(hkey,clsid,&hkey2);
3486 if (!MsiRecordIsNull(row,5))
3489 MsiRecordGetStringW(row,5,desc,&sz);
3491 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
3492 (strlenW(desc)+1)*sizeof(WCHAR));
3498 MsiRecordGetStringW(row,2,buffer,&sz);
3500 RegCreateKeyW(hkey2,buffer,&hkey3);
3502 index = get_loaded_file(package,package->components[index].KeyPath);
3503 RegSetValueExW(hkey3,NULL,0,REG_SZ,
3504 (LPVOID)package->files[index].TargetPath,
3505 (strlenW(package->files[index].TargetPath)+1)
3510 if (!MsiRecordIsNull(row,4))
3513 MsiRecordGetStringW(row,4,buffer,&sz);
3515 RegCreateKeyW(hkey2,szProgID,&hkey3);
3517 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
3518 (strlenW(buffer)+1)*sizeof(WCHAR));
3523 if (!MsiRecordIsNull(row,6))
3526 MsiRecordGetStringW(row,6,buffer,&sz);
3528 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
3529 (strlenW(buffer)+1)*sizeof(WCHAR));
3531 register_appid(hPackage,buffer,desc);
3536 FIXME("Process the rest of the fields >7\n");
3538 ui_actiondata(hPackage,szRegisterClassInfo,row);
3540 MsiCloseHandle(row);
3543 MsiCloseHandle(view);
3550 static UINT register_progid_base(MSIHANDLE row, LPWSTR clsid)
3552 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3554 WCHAR buffer[0x1000];
3559 MsiRecordGetStringW(row,1,buffer,&sz);
3560 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
3562 if (!MsiRecordIsNull(row,4))
3565 MsiRecordGetStringW(row,4,buffer,&sz);
3566 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
3570 if (!MsiRecordIsNull(row,3))
3574 MsiRecordGetStringW(row,3,buffer,&sz);
3575 RegCreateKeyW(hkey,szCLSID,&hkey2);
3576 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
3580 strcpyW(clsid,buffer);
3586 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
3587 return ERROR_FUNCTION_FAILED;
3589 if (!MsiRecordIsNull(row,5))
3590 FIXME ("UNHANDLED icon in Progid\n");
3591 return ERROR_SUCCESS;
3594 static UINT register_progid(MSIHANDLE hPackage, MSIHANDLE row, LPWSTR clsid);
3596 static UINT register_parent_progid(MSIHANDLE hPackage, LPCWSTR parent,
3602 static const WCHAR Query_t[] =
3603 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','P','r','o','g'
3604 ,'I','d',' ','w','h','e','r','e',' ','P','r','o','g','I','d',' ','=',' ','`'
3606 WCHAR Query[0x1000];
3607 MSIPACKAGE* package;
3609 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
3611 return ERROR_INVALID_HANDLE;
3613 sprintfW(Query,Query_t,parent);
3615 rc = MsiDatabaseOpenViewW(package->db, Query, &view);
3617 if (rc != ERROR_SUCCESS)
3620 rc = MsiViewExecute(view, 0);
3621 if (rc != ERROR_SUCCESS)
3624 MsiCloseHandle(view);
3628 rc = MsiViewFetch(view,&row);
3629 if (rc != ERROR_SUCCESS)
3632 MsiCloseHandle(view);
3636 register_progid(hPackage,row,clsid);
3638 MsiCloseHandle(row);
3640 MsiCloseHandle(view);
3644 static UINT register_progid(MSIHANDLE hPackage, MSIHANDLE row, LPWSTR clsid)
3646 UINT rc = ERROR_SUCCESS;
3648 if (MsiRecordIsNull(row,2))
3649 rc = register_progid_base(row,clsid);
3652 WCHAR buffer[0x1000];
3655 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3658 MsiRecordGetStringW(row,2,buffer,&sz);
3659 rc = register_parent_progid(hPackage,buffer,clsid);
3662 MsiRecordGetStringW(row,1,buffer,&sz);
3663 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
3664 /* clasid is same as parent */
3665 RegCreateKeyW(hkey,szCLSID,&hkey2);
3666 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
3670 if (!MsiRecordIsNull(row,4))
3673 MsiRecordGetStringW(row,4,buffer,&sz);
3674 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
3675 (strlenW(buffer)+1) * sizeof(WCHAR));
3678 if (!MsiRecordIsNull(row,5))
3679 FIXME ("UNHANDLED icon in Progid\n");
3686 static UINT ACTION_RegisterProgIdInfo(MSIHANDLE hPackage)
3689 * Sigh, here i am just brute force registering all progid
3690 * this needs to be linked to the Classes that have been registerd
3691 * but the easiest way to do that is to load all these stuff into
3692 * memory for easy checking.
3694 * gives me something to continue to work toward
3699 static const CHAR *Query = "SELECT * FROM ProgId";
3700 MSIPACKAGE* package;
3702 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
3704 return ERROR_INVALID_HANDLE;
3706 rc = MsiDatabaseOpenViewA(package->db, Query, &view);
3708 if (rc != ERROR_SUCCESS)
3711 rc = MsiViewExecute(view, 0);
3712 if (rc != ERROR_SUCCESS)
3715 MsiCloseHandle(view);
3721 WCHAR clsid[0x1000];
3723 rc = MsiViewFetch(view,&row);
3724 if (rc != ERROR_SUCCESS)
3730 register_progid(hPackage,row,clsid);
3731 ui_actiondata(hPackage,szRegisterProgIdInfo,row);
3733 MsiCloseHandle(row);
3736 MsiCloseHandle(view);
3740 static UINT build_icon_path(MSIHANDLE hPackage, LPCWSTR icon_name,
3743 WCHAR ProductCode[0x100];
3744 WCHAR SystemFolder[MAX_PATH];
3747 static const WCHAR szInstaller[] =
3748 {'I','n','s','t','a','l','l','e','r','\\',0};
3749 static const WCHAR szProductCode[] =
3750 {'P','r','o','d','u','c','t','C','o','d','e',0};
3751 static const WCHAR szFolder[] =
3752 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3755 MsiGetPropertyW(hPackage,szProductCode,ProductCode,&sz);
3756 if (strlenW(ProductCode)==0)
3757 return ERROR_FUNCTION_FAILED;
3760 MsiGetPropertyW(hPackage,szFolder,SystemFolder,&sz);
3761 strcatW(SystemFolder,szInstaller);
3762 strcatW(SystemFolder,ProductCode);
3763 create_full_pathW(SystemFolder);
3765 strcpyW(FilePath,SystemFolder);
3766 strcatW(FilePath,cszbs);
3767 strcatW(FilePath,icon_name);
3768 return ERROR_SUCCESS;
3771 static UINT ACTION_CreateShortcuts(MSIHANDLE hPackage)
3776 static const CHAR *Query = "SELECT * from Shortcut";
3777 MSIPACKAGE* package;
3783 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
3785 return ERROR_INVALID_HANDLE;
3787 res = CoInitialize( NULL );
3790 ERR("CoInitialize failed\n");
3791 return ERROR_FUNCTION_FAILED;
3794 rc = MsiDatabaseOpenViewA(package->db, Query, &view);
3796 if (rc != ERROR_SUCCESS)
3799 rc = MsiViewExecute(view, 0);
3800 if (rc != ERROR_SUCCESS)
3803 MsiCloseHandle(view);
3809 WCHAR target_file[MAX_PATH];
3810 WCHAR buffer[0x1000];
3813 static const WCHAR szlnk[]={'.','l','n','k',0};
3815 rc = MsiViewFetch(view,&row);
3816 if (rc != ERROR_SUCCESS)
3823 MsiRecordGetStringW(row,4,buffer,&sz);
3825 index = get_loaded_component(package,buffer);
3829 MsiCloseHandle(row);
3833 if (!package->components[index].Enabled ||
3834 !package->components[index].FeatureState)
3836 TRACE("Skipping shortcut creation due to disabled component\n");
3837 MsiCloseHandle(row);
3841 ui_actiondata(hPackage,szCreateShortcuts,row);
3843 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3844 &IID_IShellLinkW, (LPVOID *) &sl );
3848 ERR("Is IID_IShellLink\n");
3849 MsiCloseHandle(row);
3853 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
3856 ERR("Is IID_IPersistFile\n");
3857 MsiCloseHandle(row);
3862 MsiRecordGetStringW(row,2,buffer,&sz);
3863 resolve_folder(hPackage, buffer,target_file,FALSE,FALSE,NULL);
3866 MsiRecordGetStringW(row,3,buffer,&sz);
3867 reduce_to_longfilename(buffer);
3868 strcatW(target_file,buffer);
3869 if (!strchrW(target_file,'.'))
3870 strcatW(target_file,szlnk);
3873 MsiRecordGetStringW(row,5,buffer,&sz);
3874 if (strchrW(buffer,'['))
3877 deformat_string(hPackage,buffer,&deformated);
3878 IShellLinkW_SetPath(sl,deformated);
3879 HeapFree(GetProcessHeap(),0,deformated);
3883 FIXME("UNHANDLED shortcut format, advertised shortcut\n");
3884 IPersistFile_Release( pf );
3885 IShellLinkW_Release( sl );
3886 MsiCloseHandle(row);
3890 if (!MsiRecordIsNull(row,6))
3894 MsiRecordGetStringW(row,6,buffer,&sz);
3895 deformat_string(hPackage,buffer,&deformated);
3896 IShellLinkW_SetArguments(sl,deformated);
3897 HeapFree(GetProcessHeap(),0,deformated);
3900 if (!MsiRecordIsNull(row,7))
3904 MsiRecordGetStringW(row,7,NULL,&sz);
3906 deformated = HeapAlloc(GetProcessHeap(),0,sz * sizeof(WCHAR));
3907 MsiRecordGetStringW(row,7,deformated,&sz);
3908 IShellLinkW_SetDescription(sl,deformated);
3909 HeapFree(GetProcessHeap(),0,deformated);
3912 if (!MsiRecordIsNull(row,8))
3913 IShellLinkW_SetHotkey(sl,MsiRecordGetInteger(row,8));
3915 if (!MsiRecordIsNull(row,9))
3917 WCHAR Path[MAX_PATH];
3921 MsiRecordGetStringW(row,9,buffer,&sz);
3923 build_icon_path(hPackage,buffer,Path);
3924 index = MsiRecordGetInteger(row,10);
3926 IShellLinkW_SetIconLocation(sl,Path,index);
3929 if (!MsiRecordIsNull(row,11))
3930 IShellLinkW_SetShowCmd(sl,MsiRecordGetInteger(row,11));
3932 if (!MsiRecordIsNull(row,12))
3934 WCHAR Path[MAX_PATH];
3937 MsiRecordGetStringW(row,12,buffer,&sz);
3938 resolve_folder(hPackage, buffer, Path, FALSE, FALSE, NULL);
3939 IShellLinkW_SetWorkingDirectory(sl,Path);
3942 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
3943 IPersistFile_Save(pf,target_file,FALSE);
3945 IPersistFile_Release( pf );
3946 IShellLinkW_Release( sl );
3948 MsiCloseHandle(row);
3951 MsiCloseHandle(view);
3961 * 99% of the work done here is only done for
3962 * advertised installs. However this is where the
3963 * Icon table is processed and written out
3964 * so that is waht i am going to do here
3966 static UINT ACTION_PublishProduct(MSIHANDLE hPackage)
3971 static const CHAR *Query="SELECT * from Icon";
3972 MSIPACKAGE* package;
3975 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
3977 return ERROR_INVALID_HANDLE;
3979 rc = MsiDatabaseOpenViewA(package->db, Query, &view);
3981 if (rc != ERROR_SUCCESS)
3984 rc = MsiViewExecute(view, 0);
3985 if (rc != ERROR_SUCCESS)
3988 MsiCloseHandle(view);
3995 WCHAR FilePath[MAX_PATH];
3996 WCHAR FileName[MAX_PATH];
3999 rc = MsiViewFetch(view,&row);
4000 if (rc != ERROR_SUCCESS)
4007 MsiRecordGetStringW(row,1,FileName,&sz);
4010 ERR("Unable to get FileName\n");
4011 MsiCloseHandle(row);
4015 build_icon_path(hPackage,FileName,FilePath);
4017 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
4019 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
4020 FILE_ATTRIBUTE_NORMAL, NULL);
4022 if (the_file == INVALID_HANDLE_VALUE)
4024 ERR("Unable to create file %s\n",debugstr_w(FilePath));
4025 MsiCloseHandle(row);
4033 rc = MsiRecordReadStream(row,2,buffer,&sz);
4034 if (rc != ERROR_SUCCESS)
4036 ERR("Failed to get stream\n");
4037 CloseHandle(the_file);
4038 DeleteFileW(FilePath);
4041 WriteFile(the_file,buffer,sz,&write,NULL);
4042 } while (sz == 1024);
4044 CloseHandle(the_file);
4045 MsiCloseHandle(row);
4048 MsiCloseHandle(view);
4053 /* Msi functions that seem approperate here */
4054 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
4059 TRACE(" exteral attempt at action %s\n",szAction);
4062 return ERROR_FUNCTION_FAILED;
4064 return ERROR_FUNCTION_FAILED;
4066 len = MultiByteToWideChar( CP_ACP, 0, szAction, -1, NULL, 0);
4067 szwAction = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR));
4070 return ERROR_FUNCTION_FAILED;
4072 MultiByteToWideChar( CP_ACP, 0, szAction, -1, szwAction, len);
4074 rc = MsiDoActionW(hInstall, szwAction);
4075 HeapFree(GetProcessHeap(),0,szwAction);
4079 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
4081 TRACE(" exteral attempt at action %s \n",debugstr_w(szAction));
4082 return ACTION_PerformAction(hInstall,szAction);
4085 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
4086 LPSTR szPathBuf, DWORD* pcchPathBuf)
4092 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
4095 return ERROR_FUNCTION_FAILED;
4097 return ERROR_FUNCTION_FAILED;
4099 len = MultiByteToWideChar( CP_ACP, 0, szFolder, -1, NULL, 0);
4100 szwFolder= HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR));
4103 return ERROR_FUNCTION_FAILED;
4105 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
4107 MultiByteToWideChar( CP_ACP, 0, szFolder, -1, szwFolder, len);
4109 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
4111 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
4112 *pcchPathBuf, NULL, NULL );
4114 HeapFree(GetProcessHeap(),0,szwFolder);
4115 HeapFree(GetProcessHeap(),0,szwPathBuf);
4120 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
4121 szPathBuf, DWORD* pcchPathBuf)
4123 WCHAR path[MAX_PATH];
4126 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
4128 rc = resolve_folder(hInstall, szFolder, path, FALSE, FALSE, NULL);
4130 if (rc == ERROR_SUCCESS && strlenW(path) > *pcchPathBuf)
4132 *pcchPathBuf = strlenW(path)+1;
4133 return ERROR_MORE_DATA;
4135 else if (rc == ERROR_SUCCESS)
4137 *pcchPathBuf = strlenW(path)+1;
4138 strcpyW(szPathBuf,path);
4139 TRACE("Returning Path %s\n",debugstr_w(path));
4146 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
4147 LPSTR szPathBuf, DWORD* pcchPathBuf)
4153 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
4156 return ERROR_FUNCTION_FAILED;
4158 return ERROR_FUNCTION_FAILED;
4160 len = MultiByteToWideChar( CP_ACP, 0, szFolder, -1, NULL, 0);
4161 szwFolder= HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR));
4164 return ERROR_FUNCTION_FAILED;
4166 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
4168 MultiByteToWideChar( CP_ACP, 0, szFolder, -1, szwFolder, len);
4170 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
4172 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
4173 *pcchPathBuf, NULL, NULL );
4175 HeapFree(GetProcessHeap(),0,szwFolder);
4176 HeapFree(GetProcessHeap(),0,szwPathBuf);
4181 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
4182 szPathBuf, DWORD* pcchPathBuf)
4184 WCHAR path[MAX_PATH];
4187 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
4188 rc = resolve_folder(hInstall, szFolder, path, TRUE, FALSE, NULL);
4190 if (rc == ERROR_SUCCESS && strlenW(path) > *pcchPathBuf)
4192 *pcchPathBuf = strlenW(path)+1;
4193 return ERROR_MORE_DATA;
4195 else if (rc == ERROR_SUCCESS)
4197 *pcchPathBuf = strlenW(path)+1;
4198 strcpyW(szPathBuf,path);
4199 TRACE("Returning Path %s\n",debugstr_w(path));
4206 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
4207 LPCSTR szFolderPath)
4210 LPWSTR szwFolderPath;
4214 return ERROR_FUNCTION_FAILED;
4216 return ERROR_FUNCTION_FAILED;
4218 len = MultiByteToWideChar( CP_ACP, 0, szFolder, -1, NULL, 0);
4219 szwFolder= HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR));
4222 return ERROR_FUNCTION_FAILED;
4224 MultiByteToWideChar( CP_ACP, 0, szFolder, -1, szwFolder, len);
4226 len = MultiByteToWideChar( CP_ACP, 0, szFolderPath, -1, NULL, 0);
4227 szwFolderPath= HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR));
4231 HeapFree(GetProcessHeap(),0,szwFolder);
4232 return ERROR_FUNCTION_FAILED;
4235 MultiByteToWideChar( CP_ACP, 0, szFolderPath, -1, szwFolderPath, len);
4237 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
4239 HeapFree(GetProcessHeap(),0,szwFolder);
4240 HeapFree(GetProcessHeap(),0,szwFolderPath);
4245 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
4246 LPCWSTR szFolderPath)
4248 MSIPACKAGE *package;
4250 WCHAR path[MAX_PATH];
4253 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
4255 if (szFolderPath[0]==0)
4256 return ERROR_FUNCTION_FAILED;
4258 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
4259 return ERROR_FUNCTION_FAILED;
4261 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4264 return ERROR_INVALID_HANDLE;
4266 resolve_folder(hInstall,szFolder,path,FALSE,FALSE,&folder);
4269 return ERROR_INVALID_PARAMETER;
4271 strcpyW(folder->Property,szFolderPath);
4273 for (i = 0; i < package->loaded_folders; i++)
4274 package->folders[i].ResolvedTarget[0]=0;
4276 for (i = 0; i < package->loaded_folders; i++)
4277 resolve_folder(hInstall, package->folders[i].Directory, path, FALSE,
4280 return ERROR_SUCCESS;
4283 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, DWORD iRunMode)
4285 FIXME("STUB (%li)\n",iRunMode);
4290 static UINT ACTION_Template(MSIHANDLE hPackage)
4295 static const CHAR *ExecSeqQuery;
4296 MSIPACKAGE* package;
4298 package = msihandle2msiinfo(hPackage, MSIHANDLETYPE_PACKAGE);
4300 return ERROR_INVALID_HANDLE;
4302 rc = MsiDatabaseOpenViewA(package->db, ExecSeqQuery, &view);
4304 if (rc != ERROR_SUCCESS)
4307 rc = MsiViewExecute(view, 0);
4308 if (rc != ERROR_SUCCESS)
4311 MsiCloseHandle(view);
4317 rc = MsiViewFetch(view,&row);
4318 if (rc != ERROR_SUCCESS)
4324 MsiCloseHandle(row);
4327 MsiCloseHandle(view);