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
54 WINE_DEFAULT_DEBUG_CHANNEL(msi);
56 typedef struct tagMSIFEATURE
59 WCHAR Feature_Parent[96];
61 WCHAR Description[0x100];
70 INT Components[1024]; /* yes hardcoded limit.... I am bad */
74 typedef struct tagMSICOMPONENT
77 WCHAR ComponentId[96];
80 WCHAR Condition[0x100];
89 typedef struct tagMSIFOLDER
92 WCHAR TargetDefault[96];
93 WCHAR SourceDefault[96];
95 WCHAR ResolvedTarget[MAX_PATH];
96 WCHAR ResolvedSource[MAX_PATH];
97 WCHAR Property[MAX_PATH]; /* initially set property */
100 /* 0 = uninitialized */
102 /* 2 = created remove if empty */
103 /* 3 = created persist if empty */
108 typedef struct tagMSIFILE
112 WCHAR FileName[MAX_PATH];
120 /* 0 = uninitialize */
121 /* 1 = not present */
122 /* 2 = present but replace */
123 /* 3 = present do not replace */
125 WCHAR SourcePath[MAX_PATH];
126 WCHAR TargetPath[MAX_PATH];
133 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran);
134 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package);
136 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action);
138 static UINT ACTION_LaunchConditions(MSIPACKAGE *package);
139 static UINT ACTION_CostInitialize(MSIPACKAGE *package);
140 static UINT ACTION_CreateFolders(MSIPACKAGE *package);
141 static UINT ACTION_CostFinalize(MSIPACKAGE *package);
142 static UINT ACTION_FileCost(MSIPACKAGE *package);
143 static UINT ACTION_InstallFiles(MSIPACKAGE *package);
144 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package);
145 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package);
146 static UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action);
147 static UINT ACTION_InstallInitialize(MSIPACKAGE *package);
148 static UINT ACTION_InstallValidate(MSIPACKAGE *package);
149 static UINT ACTION_ProcessComponents(MSIPACKAGE *package);
150 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package);
151 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package);
152 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package);
153 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package);
154 static UINT ACTION_PublishProduct(MSIPACKAGE *package);
156 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
157 const LPWSTR target, const INT type);
158 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
159 const LPWSTR target, const INT type);
160 static UINT HANDLE_CustomType18(MSIPACKAGE *package, const LPWSTR source,
161 const LPWSTR target, const INT type);
162 static UINT HANDLE_CustomType50(MSIPACKAGE *package, const LPWSTR source,
163 const LPWSTR target, const INT type);
164 static UINT HANDLE_CustomType34(MSIPACKAGE *package, const LPWSTR source,
165 const LPWSTR target, const INT type);
167 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data);
168 static UINT resolve_folder(MSIPACKAGE *package, LPCWSTR name, LPWSTR path,
169 BOOL source, BOOL set_prop, MSIFOLDER **folder);
171 static int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path);
174 * consts and values used
176 static const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
177 static const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
178 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
179 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
180 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
181 static const WCHAR c_collen[] = {'C',':','\\',0};
183 static const WCHAR cszlsb[]={'[',0};
184 static const WCHAR cszrsb[]={']',0};
185 static const WCHAR cszbs[]={'\\',0};
187 const static WCHAR szCreateFolders[] =
188 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
189 const static WCHAR szCostFinalize[] =
190 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
191 const static WCHAR szInstallFiles[] =
192 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
193 const static WCHAR szDuplicateFiles[] =
194 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
195 const static WCHAR szWriteRegistryValues[] =
196 {'W','r','i','t','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
197 const static WCHAR szCostInitialize[] =
198 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
199 const static WCHAR szFileCost[] = {'F','i','l','e','C','o','s','t',0};
200 const static WCHAR szInstallInitialize[] =
201 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
202 const static WCHAR szInstallValidate[] =
203 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
204 const static WCHAR szLaunchConditions[] =
205 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
206 const static WCHAR szProcessComponents[] =
207 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
208 const static WCHAR szRegisterTypeLibraries[] =
209 {'R','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r',
211 const static WCHAR szRegisterClassInfo[] =
212 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
213 const static WCHAR szRegisterProgIdInfo[] =
214 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
215 const static WCHAR szCreateShortcuts[] =
216 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
217 const static WCHAR szPublishProduct[] =
218 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
220 /********************************************************
221 * helper functions to get around current HACKS and such
222 ********************************************************/
223 inline static void reduce_to_longfilename(WCHAR* filename)
225 if (strchrW(filename,'|'))
227 WCHAR newname[MAX_PATH];
228 strcpyW(newname,strchrW(filename,'|')+1);
229 strcpyW(filename,newname);
233 inline static char *strdupWtoA( const WCHAR *str )
238 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL
240 if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
241 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
246 inline static WCHAR *strdupAtoW( const char *str )
251 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
252 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
253 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
258 inline static WCHAR *load_dynamic_stringW(MSIRECORD *row, INT index)
265 rc = MSI_RecordGetStringW(row,index,NULL,&sz);
270 ret = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
271 rc = MSI_RecordGetStringW(row,index,ret,&sz);
275 inline static int get_loaded_component(MSIPACKAGE* package, LPCWSTR Component )
280 for (i = 0; i < package->loaded_components; i++)
282 if (strcmpW(Component,package->components[i].Component)==0)
291 inline static int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
296 for (i = 0; i < package->loaded_features; i++)
298 if (strcmpW(Feature,package->features[i].Feature)==0)
307 inline static int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
312 for (i = 0; i < package->loaded_files; i++)
314 if (strcmpW(file,package->files[i].File)==0)
323 static int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
331 for (i=0; i < package->loaded_files; i++)
332 if (strcmpW(package->files[i].File,name)==0)
335 index = package->loaded_files;
336 package->loaded_files++;
337 if (package->loaded_files== 1)
338 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
340 package->files = HeapReAlloc(GetProcessHeap(),0,
341 package->files , package->loaded_files * sizeof(MSIFILE));
343 memset(&package->files[index],0,sizeof(MSIFILE));
345 strcpyW(package->files[index].File,name);
346 strcpyW(package->files[index].TargetPath,path);
347 package->files[index].Temporary = TRUE;
349 TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
354 void ACTION_remove_tracked_tempfiles(MSIPACKAGE* package)
361 for (i = 0; i < package->loaded_files; i++)
363 if (package->files[i].Temporary)
364 DeleteFileW(package->files[i].TargetPath);
369 static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
373 row = MSI_CreateRecord(4);
374 MSI_RecordSetInteger(row,1,a);
375 MSI_RecordSetInteger(row,2,b);
376 MSI_RecordSetInteger(row,3,c);
377 MSI_RecordSetInteger(row,4,d);
378 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
379 msiobj_release(&row->hdr);
382 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
384 static const WCHAR Query_t[] =
385 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
386 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
387 ' ','\'','%','s','\'',0};
392 static WCHAR *ActionFormat=NULL;
393 static WCHAR LastAction[0x100] = {0};
397 if (strcmpW(LastAction,action)!=0)
399 sprintfW(Query,Query_t,action);
400 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
401 if (rc != ERROR_SUCCESS)
403 rc = MSI_ViewExecute(view, 0);
404 if (rc != ERROR_SUCCESS)
409 rc = MSI_ViewFetch(view,&row);
410 if (rc != ERROR_SUCCESS)
416 if (MSI_RecordIsNull(row,3))
418 msiobj_release(&row->hdr);
420 msiobj_release(&view->hdr);
425 HeapFree(GetProcessHeap(),0,ActionFormat);
427 ActionFormat = load_dynamic_stringW(row,3);
428 strcpyW(LastAction,action);
429 msiobj_release(&row->hdr);
431 msiobj_release(&view->hdr);
443 ptr2 = strchrW(ptr,'[');
446 strncpyW(tmp,ptr,ptr2-ptr);
448 strcatW(message,tmp);
451 data = load_dynamic_stringW(record,field);
454 strcatW(message,data);
455 HeapFree(GetProcessHeap(),0,data);
457 ptr=strchrW(ptr2,']');
462 strcatW(message,ptr);
467 row = MSI_CreateRecord(1);
468 MSI_RecordSetStringW(row,1,message);
470 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
471 msiobj_release(&row->hdr);
475 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
477 static const WCHAR template_s[]=
478 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ','%','s','.',0};
479 static const WCHAR format[] =
480 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
481 static const WCHAR Query_t[] =
482 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
483 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
484 ' ','\'','%','s','\'',0};
490 WCHAR *ActionText=NULL;
493 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
495 sprintfW(Query,Query_t,action);
496 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
497 if (rc != ERROR_SUCCESS)
499 rc = MSI_ViewExecute(view, 0);
500 if (rc != ERROR_SUCCESS)
503 msiobj_release(&view->hdr);
506 rc = MSI_ViewFetch(view,&row);
507 if (rc != ERROR_SUCCESS)
510 msiobj_release(&view->hdr);
514 ActionText = load_dynamic_stringW(row,2);
515 msiobj_release(&row->hdr);
517 msiobj_release(&view->hdr);
519 sprintfW(message,template_s,timet,action,ActionText);
521 row = MSI_CreateRecord(1);
522 MSI_RecordSetStringW(row,1,message);
524 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
525 msiobj_release(&row->hdr);
526 HeapFree(GetProcessHeap(),0,ActionText);
529 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
533 static const WCHAR template_s[]=
534 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ','%','s',
536 static const WCHAR template_e[]=
537 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ','%','s',
538 '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ','%','i','.',0};
539 static const WCHAR format[] =
540 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
544 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
546 sprintfW(message,template_s,timet,action);
548 sprintfW(message,template_e,timet,action,rc);
550 row = MSI_CreateRecord(1);
551 MSI_RecordSetStringW(row,1,message);
553 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
554 msiobj_release(&row->hdr);
557 /****************************************************
558 * TOP level entry points
559 *****************************************************/
561 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
562 LPCWSTR szCommandLine)
567 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
572 WCHAR check[MAX_PATH];
576 strcpyW(pth,szPackagePath);
577 p = strrchrW(pth,'\\');
585 if (MSI_GetPropertyW(package,cszSourceDir,check,&size)
587 MSI_SetPropertyW(package, cszSourceDir, pth);
593 ptr = (LPWSTR)szCommandLine;
600 TRACE("Looking at %s\n",debugstr_w(ptr));
602 ptr2 = strchrW(ptr,'=');
608 while (*ptr == ' ') ptr++;
609 strncpyW(prop,ptr,ptr2-ptr);
614 while (*ptr && (quote || (!quote && *ptr!=' ')))
627 strncpyW(val,ptr2,len);
630 if (strlenW(prop) > 0)
632 TRACE("Found commandline property (%s) = (%s)\n", debugstr_w(prop), debugstr_w(val));
633 MSI_SetPropertyW(package,prop,val);
641 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
643 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
645 rc = ACTION_ProcessUISequence(package);
646 if (rc == ERROR_SUCCESS)
647 rc = ACTION_ProcessExecSequence(package,TRUE);
650 rc = ACTION_ProcessExecSequence(package,FALSE);
653 rc = ACTION_ProcessExecSequence(package,FALSE);
659 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
663 static const WCHAR ExecSeqQuery[] = {
664 's','e','l','e','c','t',' ','*',' ',
666 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
667 'S','e','q','u','e','n','c','e',' ',
668 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
669 '>',' ','%','i',' ','o','r','d','e','r',' ',
670 'b','y',' ','S','e','q','u','e','n','c','e',0 };
673 static const WCHAR IVQuery[] = {
674 's','e','l','e','c','t',' ','S','e','q','u','e','n','c','e',' ',
675 'f','r','o','m',' ','I','n','s','t','a','l','l',
676 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
677 'w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',' ',
678 '`','I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`',
685 rc = MSI_DatabaseOpenViewW(package->db, IVQuery, &view);
686 if (rc != ERROR_SUCCESS)
688 rc = MSI_ViewExecute(view, 0);
689 if (rc != ERROR_SUCCESS)
692 msiobj_release(&view->hdr);
695 rc = MSI_ViewFetch(view,&row);
696 if (rc != ERROR_SUCCESS)
699 msiobj_release(&view->hdr);
702 seq = MSI_RecordGetInteger(row,1);
703 msiobj_release(&row->hdr);
705 msiobj_release(&view->hdr);
706 sprintfW(Query,ExecSeqQuery,seq);
709 sprintfW(Query,ExecSeqQuery,0);
711 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
712 if (rc == ERROR_SUCCESS)
714 rc = MSI_ViewExecute(view, 0);
716 if (rc != ERROR_SUCCESS)
719 msiobj_release(&view->hdr);
723 TRACE("Running the actions \n");
730 rc = MSI_ViewFetch(view,&row);
731 if (rc != ERROR_SUCCESS)
737 /* check conditions */
738 if (!MSI_RecordIsNull(row,2))
741 cond = load_dynamic_stringW(row,2);
745 /* this is a hack to skip errors in the condition code */
746 if (MSI_EvaluateConditionW(package, cond) ==
749 HeapFree(GetProcessHeap(),0,cond);
750 msiobj_release(&row->hdr);
754 HeapFree(GetProcessHeap(),0,cond);
759 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
760 if (rc != ERROR_SUCCESS)
762 ERR("Error is %x\n",rc);
763 msiobj_release(&row->hdr);
767 rc = ACTION_PerformAction(package,buffer);
769 if (rc == ERROR_FUNCTION_NOT_CALLED)
772 if (rc != ERROR_SUCCESS)
774 ERR("Execution halted due to error (%i)\n",rc);
775 msiobj_release(&row->hdr);
779 msiobj_release(&row->hdr);
783 msiobj_release(&view->hdr);
791 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
795 static const WCHAR ExecSeqQuery [] = {
796 's','e','l','e','c','t',' ','*',' ',
797 'f','r','o','m',' ','I','n','s','t','a','l','l',
798 'U','I','S','e','q','u','e','n','c','e',' ',
799 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ', '>',' ','0',' ',
800 'o','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e',0};
802 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
804 if (rc == ERROR_SUCCESS)
806 rc = MSI_ViewExecute(view, 0);
808 if (rc != ERROR_SUCCESS)
811 msiobj_release(&view->hdr);
815 TRACE("Running the actions \n");
823 rc = MSI_ViewFetch(view,&row);
824 if (rc != ERROR_SUCCESS)
830 /* check conditions */
831 if (!MSI_RecordIsNull(row,2))
834 cond = load_dynamic_stringW(row,2);
838 /* this is a hack to skip errors in the condition code */
839 if (MSI_EvaluateConditionW(package, cond) ==
842 HeapFree(GetProcessHeap(),0,cond);
843 msiobj_release(&row->hdr);
847 HeapFree(GetProcessHeap(),0,cond);
852 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
853 if (rc != ERROR_SUCCESS)
855 ERR("Error is %x\n",rc);
856 msiobj_release(&row->hdr);
860 rc = ACTION_PerformAction(package,buffer);
862 if (rc == ERROR_FUNCTION_NOT_CALLED)
865 if (rc != ERROR_SUCCESS)
867 ERR("Execution halted due to error (%i)\n",rc);
868 msiobj_release(&row->hdr);
872 msiobj_release(&row->hdr);
876 msiobj_release(&view->hdr);
883 /********************************************************
884 * ACTION helper functions and functions that perform the actions
885 *******************************************************/
888 * Alot of actions are really important even if they don't do anything
889 * explicit.. Lots of properties are set at the beginning of the installation
890 * CostFinalize does a bunch of work to translated the directories and such
892 * But until I get write access to the database that is hard, so I am going to
893 * hack it to see if I can get something to run.
895 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action)
897 UINT rc = ERROR_SUCCESS;
899 TRACE("Performing action (%s)\n",debugstr_w(action));
900 ui_actioninfo(package, action, TRUE, 0);
901 ui_actionstart(package, action);
902 ui_progress(package,2,1,0,0);
904 /* pre install, setup and configuration block */
905 if (strcmpW(action,szLaunchConditions)==0)
906 rc = ACTION_LaunchConditions(package);
907 else if (strcmpW(action,szCostInitialize)==0)
908 rc = ACTION_CostInitialize(package);
909 else if (strcmpW(action,szFileCost)==0)
910 rc = ACTION_FileCost(package);
911 else if (strcmpW(action,szCostFinalize)==0)
912 rc = ACTION_CostFinalize(package);
913 else if (strcmpW(action,szInstallValidate)==0)
914 rc = ACTION_InstallValidate(package);
917 else if (strcmpW(action,szProcessComponents)==0)
918 rc = ACTION_ProcessComponents(package);
919 else if (strcmpW(action,szInstallInitialize)==0)
920 rc = ACTION_InstallInitialize(package);
921 else if (strcmpW(action,szCreateFolders)==0)
922 rc = ACTION_CreateFolders(package);
923 else if (strcmpW(action,szInstallFiles)==0)
924 rc = ACTION_InstallFiles(package);
925 else if (strcmpW(action,szDuplicateFiles)==0)
926 rc = ACTION_DuplicateFiles(package);
927 else if (strcmpW(action,szWriteRegistryValues)==0)
928 rc = ACTION_WriteRegistryValues(package);
929 else if (strcmpW(action,szRegisterTypeLibraries)==0)
930 rc = ACTION_RegisterTypeLibraries(package);
931 else if (strcmpW(action,szRegisterClassInfo)==0)
932 rc = ACTION_RegisterClassInfo(package);
933 else if (strcmpW(action,szRegisterProgIdInfo)==0)
934 rc = ACTION_RegisterProgIdInfo(package);
935 else if (strcmpW(action,szCreateShortcuts)==0)
936 rc = ACTION_CreateShortcuts(package);
937 else if (strcmpW(action,szPublishProduct)==0)
938 rc = ACTION_PublishProduct(package);
941 Called during iTunes but unimplemented and seem important
943 ResolveSource (sets SourceDir)
947 else if ((rc = ACTION_CustomAction(package,action)) != ERROR_SUCCESS)
949 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
950 rc = ERROR_FUNCTION_NOT_CALLED;
953 ui_actioninfo(package, action, FALSE, rc);
958 static UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action)
960 UINT rc = ERROR_SUCCESS;
963 WCHAR ExecSeqQuery[1024] =
964 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','C','u','s','t','o'
965 ,'m','A','c','t','i','o','n',' ','w','h','e','r','e',' ','`','A','c','t','i'
966 ,'o','n','`',' ','=',' ','`',0};
967 static const WCHAR end[]={'`',0};
971 WCHAR *deformated=NULL;
973 strcatW(ExecSeqQuery,action);
974 strcatW(ExecSeqQuery,end);
976 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
978 if (rc != ERROR_SUCCESS)
981 rc = MSI_ViewExecute(view, 0);
982 if (rc != ERROR_SUCCESS)
985 msiobj_release(&view->hdr);
989 rc = MSI_ViewFetch(view,&row);
990 if (rc != ERROR_SUCCESS)
993 msiobj_release(&view->hdr);
997 type = MSI_RecordGetInteger(row,2);
999 source = load_dynamic_stringW(row,3);
1000 target = load_dynamic_stringW(row,4);
1002 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
1003 debugstr_w(source), debugstr_w(target));
1005 /* we are ignoring ALOT of flags and important synchronization stuff */
1006 switch (type & CUSTOM_ACTION_TYPE_MASK)
1008 case 1: /* DLL file stored in a Binary table stream */
1009 rc = HANDLE_CustomType1(package,source,target,type);
1011 case 2: /* EXE file stored in a Binary table strem */
1012 rc = HANDLE_CustomType2(package,source,target,type);
1014 case 18: /*EXE file installed with package */
1015 rc = HANDLE_CustomType18(package,source,target,type);
1017 case 50: /*EXE file specified by a property value */
1018 rc = HANDLE_CustomType50(package,source,target,type);
1020 case 34: /*EXE to be run in specified directory */
1021 rc = HANDLE_CustomType34(package,source,target,type);
1023 case 35: /* Directory set with formatted text. */
1024 case 51: /* Property set with formatted text. */
1025 deformat_string(package,target,&deformated);
1026 rc = MSI_SetPropertyW(package,source,deformated);
1027 HeapFree(GetProcessHeap(),0,deformated);
1030 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
1031 type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
1032 debugstr_w(target));
1035 HeapFree(GetProcessHeap(),0,source);
1036 HeapFree(GetProcessHeap(),0,target);
1037 msiobj_release(&row->hdr);
1038 MSI_ViewClose(view);
1039 msiobj_release(&view->hdr);
1043 static UINT store_binary_to_temp(MSIPACKAGE *package, const LPWSTR source,
1048 if (MSI_GetPropertyW(package, cszTempFolder, tmp_file, &sz)
1050 GetTempPathW(MAX_PATH,tmp_file);
1052 strcatW(tmp_file,source);
1054 if (GetFileAttributesW(tmp_file) != INVALID_FILE_ATTRIBUTES)
1056 TRACE("File already exists\n");
1057 return ERROR_SUCCESS;
1061 /* write out the file */
1064 MSIRECORD * row = 0;
1066 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','B','i'
1067 ,'n','a','r','y',' ','w','h','e','r','e',' ','N','a','m','e','=','`',0};
1068 static const WCHAR end[]={'`',0};
1072 if (track_tempfile(package, source, tmp_file)!=0)
1073 FIXME("File Name in temp tracking collision\n");
1075 the_file = CreateFileW(tmp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1076 FILE_ATTRIBUTE_NORMAL, NULL);
1078 if (the_file == INVALID_HANDLE_VALUE)
1079 return ERROR_FUNCTION_FAILED;
1081 strcatW(Query,source);
1084 rc = MSI_DatabaseOpenViewW( package->db, Query, &view);
1085 if (rc != ERROR_SUCCESS)
1088 rc = MSI_ViewExecute(view, 0);
1089 if (rc != ERROR_SUCCESS)
1091 MSI_ViewClose(view);
1092 msiobj_release(&view->hdr);
1096 rc = MSI_ViewFetch(view,&row);
1097 if (rc != ERROR_SUCCESS)
1099 MSI_ViewClose(view);
1100 msiobj_release(&view->hdr);
1108 rc = MSI_RecordReadStream(row,2,buffer,&sz);
1109 if (rc != ERROR_SUCCESS)
1111 ERR("Failed to get stream\n");
1112 CloseHandle(the_file);
1113 DeleteFileW(tmp_file);
1116 WriteFile(the_file,buffer,sz,&write,NULL);
1117 } while (sz == 1024);
1119 CloseHandle(the_file);
1121 msiobj_release(&row->hdr);
1122 MSI_ViewClose(view);
1123 msiobj_release(&view->hdr);
1126 return ERROR_SUCCESS;
1130 typedef UINT __stdcall CustomEntry(MSIHANDLE);
1133 MSIPACKAGE *package;
1134 WCHAR target[MAX_PATH];
1135 WCHAR source[MAX_PATH];
1139 static DWORD WINAPI DllThread(LPVOID info)
1143 thread_struct *stuff;
1146 stuff = (thread_struct*)info;
1148 TRACE("Asynchronous start (%s, %s) \n", debugstr_w(stuff->source),
1149 debugstr_w(stuff->target));
1151 DLL = LoadLibraryW(stuff->source);
1154 proc = strdupWtoA( stuff->target );
1155 fn = (CustomEntry*)GetProcAddress(DLL,proc);
1159 MSIPACKAGE *package = stuff->package;
1161 TRACE("Calling function\n");
1162 hPackage = msiobj_findhandle( &package->hdr );
1164 ERR("Handle for object %p not found\n", package );
1166 msiobj_release( &package->hdr );
1169 ERR("Cannot load functon\n");
1171 HeapFree(GetProcessHeap(),0,proc);
1175 ERR("Unable to load library\n");
1176 msiobj_release( &stuff->package->hdr );
1177 HeapFree( GetProcessHeap(), 0, info );
1182 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
1183 const LPWSTR target, const INT type)
1185 WCHAR tmp_file[MAX_PATH];
1190 store_binary_to_temp(package, source, tmp_file);
1192 TRACE("Calling function %s from %s\n",debugstr_w(target),
1193 debugstr_w(tmp_file));
1195 if (!strchrW(tmp_file,'.'))
1197 static const WCHAR dot[]={'.',0};
1198 strcatW(tmp_file,dot);
1203 /* DWORD ThreadId; */
1204 thread_struct *info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) );
1206 /* msiobj_addref( &package->hdr ); */
1207 info->package = package;
1208 strcpyW(info->target,target);
1209 strcpyW(info->source,tmp_file);
1210 TRACE("Start Asynchronous execution\n");
1211 FIXME("DATABASE NOT THREADSAFE... not starting\n");
1212 /* CreateThread(NULL,0,DllThread,(LPVOID)&info,0,&ThreadId); */
1213 /* FIXME: release the package if the CreateThread fails */
1214 HeapFree( GetProcessHeap(), 0, info );
1215 return ERROR_SUCCESS;
1218 DLL = LoadLibraryW(tmp_file);
1221 proc = strdupWtoA( target );
1222 fn = (CustomEntry*)GetProcAddress(DLL,proc);
1227 TRACE("Calling function\n");
1228 hPackage = msiobj_findhandle( &package->hdr );
1230 ERR("Handle for object %p not found\n", package );
1232 msiobj_release( &package->hdr );
1235 ERR("Cannot load functon\n");
1237 HeapFree(GetProcessHeap(),0,proc);
1241 ERR("Unable to load library\n");
1243 return ERROR_SUCCESS;
1246 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
1247 const LPWSTR target, const INT type)
1249 WCHAR tmp_file[MAX_PATH*2];
1251 PROCESS_INFORMATION info;
1254 static const WCHAR spc[] = {' ',0};
1256 memset(&si,0,sizeof(STARTUPINFOW));
1258 store_binary_to_temp(package, source, tmp_file);
1260 strcatW(tmp_file,spc);
1261 deformat_string(package,target,&deformated);
1262 strcatW(tmp_file,deformated);
1264 HeapFree(GetProcessHeap(),0,deformated);
1266 TRACE("executing exe %s \n",debugstr_w(tmp_file));
1268 rc = CreateProcessW(NULL, tmp_file, NULL, NULL, FALSE, 0, NULL,
1269 c_collen, &si, &info);
1273 ERR("Unable to execute command\n");
1274 return ERROR_SUCCESS;
1278 WaitForSingleObject(info.hProcess,INFINITE);
1280 CloseHandle( info.hProcess );
1281 CloseHandle( info.hThread );
1282 return ERROR_SUCCESS;
1285 static UINT HANDLE_CustomType18(MSIPACKAGE *package, const LPWSTR source,
1286 const LPWSTR target, const INT type)
1288 WCHAR filename[MAX_PATH*2];
1290 PROCESS_INFORMATION info;
1293 static const WCHAR spc[] = {' ',0};
1296 memset(&si,0,sizeof(STARTUPINFOW));
1298 index = get_loaded_file(package,source);
1299 strcpyW(filename,package->files[index].TargetPath);
1301 strcatW(filename,spc);
1302 deformat_string(package,target,&deformated);
1303 strcatW(filename,deformated);
1305 HeapFree(GetProcessHeap(),0,deformated);
1307 TRACE("executing exe %s \n",debugstr_w(filename));
1309 rc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
1310 c_collen, &si, &info);
1314 ERR("Unable to execute command\n");
1315 return ERROR_SUCCESS;
1319 WaitForSingleObject(info.hProcess,INFINITE);
1321 CloseHandle( info.hProcess );
1322 CloseHandle( info.hThread );
1323 return ERROR_SUCCESS;
1326 static UINT HANDLE_CustomType50(MSIPACKAGE *package, const LPWSTR source,
1327 const LPWSTR target, const INT type)
1329 WCHAR filename[MAX_PATH*2];
1331 PROCESS_INFORMATION info;
1334 static const WCHAR spc[] = {' ',0};
1337 memset(&si,0,sizeof(STARTUPINFOW));
1340 if (MSI_GetPropertyW(package,source,filename,&sz) != ERROR_SUCCESS)
1341 return ERROR_FUNCTION_FAILED;
1343 strcatW(filename,spc);
1344 deformat_string(package,target,&deformated);
1345 strcatW(filename,deformated);
1347 HeapFree(GetProcessHeap(),0,deformated);
1349 TRACE("executing exe %s \n",debugstr_w(filename));
1351 rc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
1352 c_collen, &si, &info);
1356 ERR("Unable to execute command\n");
1357 return ERROR_SUCCESS;
1361 WaitForSingleObject(info.hProcess,INFINITE);
1363 CloseHandle( info.hProcess );
1364 CloseHandle( info.hThread );
1365 return ERROR_SUCCESS;
1368 static UINT HANDLE_CustomType34(MSIPACKAGE *package, const LPWSTR source,
1369 const LPWSTR target, const INT type)
1371 WCHAR filename[MAX_PATH*2];
1373 PROCESS_INFORMATION info;
1377 memset(&si,0,sizeof(STARTUPINFOW));
1379 rc = resolve_folder(package, source, filename, FALSE, FALSE, NULL);
1380 if (rc != ERROR_SUCCESS)
1383 SetCurrentDirectoryW(filename);
1385 deformat_string(package,target,&deformated);
1386 strcpyW(filename,deformated);
1388 HeapFree(GetProcessHeap(),0,deformated);
1390 TRACE("executing exe %s \n",debugstr_w(filename));
1392 rc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
1393 c_collen, &si, &info);
1397 ERR("Unable to execute command\n");
1398 return ERROR_SUCCESS;
1402 WaitForSingleObject(info.hProcess,INFINITE);
1404 CloseHandle( info.hProcess );
1405 CloseHandle( info.hThread );
1406 return ERROR_SUCCESS;
1409 /***********************************************************************
1412 * Recursively create all directories in the path.
1414 * shamelessly stolen from setupapi/queue.c
1416 static BOOL create_full_pathW(const WCHAR *path)
1422 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1424 strcpyW(new_path, path);
1426 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1427 new_path[len - 1] = 0;
1429 while(!CreateDirectoryW(new_path, NULL))
1432 DWORD last_error = GetLastError();
1433 if(last_error == ERROR_ALREADY_EXISTS)
1436 if(last_error != ERROR_PATH_NOT_FOUND)
1442 if(!(slash = strrchrW(new_path, '\\')))
1448 len = slash - new_path;
1450 if(!create_full_pathW(new_path))
1455 new_path[len] = '\\';
1458 HeapFree(GetProcessHeap(), 0, new_path);
1463 * Also we cannot enable/disable components either, so for now I am just going
1464 * to do all the directories for all the components.
1466 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1468 static const WCHAR ExecSeqQuery[] = {
1469 's','e','l','e','c','t',' ','D','i','r','e','c','t','o','r','y','_',' ',
1470 'f','r','o','m',' ','C','r','e','a','t','e','F','o','l','d','e','r',0 };
1475 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1476 if (rc != ERROR_SUCCESS)
1477 return ERROR_SUCCESS;
1479 rc = MSI_ViewExecute(view, 0);
1480 if (rc != ERROR_SUCCESS)
1482 MSI_ViewClose(view);
1483 msiobj_release(&view->hdr);
1490 WCHAR full_path[MAX_PATH];
1492 MSIRECORD *row = NULL, *uirow;
1494 rc = MSI_ViewFetch(view,&row);
1495 if (rc != ERROR_SUCCESS)
1502 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1504 if (rc!= ERROR_SUCCESS)
1506 ERR("Unable to get folder id \n");
1507 msiobj_release(&row->hdr);
1512 rc = resolve_folder(package,dir,full_path,FALSE,FALSE,&folder);
1514 if (rc != ERROR_SUCCESS)
1516 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1517 msiobj_release(&row->hdr);
1521 TRACE("Folder is %s\n",debugstr_w(full_path));
1524 uirow = MSI_CreateRecord(1);
1525 MSI_RecordSetStringW(uirow,1,full_path);
1526 ui_actiondata(package,szCreateFolders,uirow);
1527 msiobj_release( &uirow->hdr );
1529 if (folder->State == 0)
1530 create_full_pathW(full_path);
1534 msiobj_release(&row->hdr);
1536 MSI_ViewClose(view);
1537 msiobj_release(&view->hdr);
1542 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1544 int index = package->loaded_components;
1547 /* fill in the data */
1549 package->loaded_components++;
1550 if (package->loaded_components == 1)
1551 package->components = HeapAlloc(GetProcessHeap(),0,
1552 sizeof(MSICOMPONENT));
1554 package->components = HeapReAlloc(GetProcessHeap(),0,
1555 package->components, package->loaded_components *
1556 sizeof(MSICOMPONENT));
1558 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1561 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1563 TRACE("Loading Component %s\n",
1564 debugstr_w(package->components[index].Component));
1567 if (!MSI_RecordIsNull(row,2))
1568 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1571 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1573 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1576 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1579 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1581 package->components[index].State = INSTALLSTATE_UNKNOWN;
1582 package->components[index].Enabled = TRUE;
1583 package->components[index].FeatureState= FALSE;
1588 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1590 int index = package->loaded_features;
1592 static const WCHAR Query1[] = {'S','E','L','E','C','T',' ','C','o','m','p',
1593 'o','n','e','n','t','_',' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1594 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ','F','e',
1595 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1596 static const WCHAR Query2[] = {'S','E','L','E','C','T',' ','*',' ','F','R',
1597 'O','M',' ','C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ','C',
1598 'o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1606 /* fill in the data */
1608 package->loaded_features ++;
1609 if (package->loaded_features == 1)
1610 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1612 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1613 package->loaded_features * sizeof(MSIFEATURE));
1615 memset(&package->features[index],0,sizeof(MSIFEATURE));
1618 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1620 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1623 if (!MSI_RecordIsNull(row,2))
1624 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1627 if (!MSI_RecordIsNull(row,3))
1628 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1631 if (!MSI_RecordIsNull(row,4))
1632 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1634 if (!MSI_RecordIsNull(row,5))
1635 package->features[index].Display = MSI_RecordGetInteger(row,5);
1637 package->features[index].Level= MSI_RecordGetInteger(row,6);
1640 if (!MSI_RecordIsNull(row,7))
1641 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1643 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1644 package->features[index].State = INSTALLSTATE_UNKNOWN;
1646 /* load feature components */
1648 sprintfW(Query,Query1,package->features[index].Feature);
1649 rc = MSI_DatabaseOpenViewW(package->db,Query,&view);
1650 if (rc != ERROR_SUCCESS)
1652 rc = MSI_ViewExecute(view,0);
1653 if (rc != ERROR_SUCCESS)
1655 MSI_ViewClose(view);
1656 msiobj_release(&view->hdr);
1662 WCHAR buffer[0x100];
1665 INT cnt = package->features[index].ComponentCount;
1667 rc = MSI_ViewFetch(view,&row2);
1668 if (rc != ERROR_SUCCESS)
1672 MSI_RecordGetStringW(row2,1,buffer,&sz);
1674 /* check to see if the component is already loaded */
1675 c_indx = get_loaded_component(package,buffer);
1678 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1680 package->features[index].Components[cnt] = c_indx;
1681 package->features[index].ComponentCount ++;
1684 sprintfW(Query,Query2,buffer);
1686 rc = MSI_DatabaseOpenViewW(package->db,Query,&view2);
1687 if (rc != ERROR_SUCCESS)
1689 msiobj_release( &row2->hdr );
1692 rc = MSI_ViewExecute(view2,0);
1693 if (rc != ERROR_SUCCESS)
1695 msiobj_release( &row2->hdr );
1696 MSI_ViewClose(view2);
1697 msiobj_release( &view2->hdr );
1704 rc = MSI_ViewFetch(view2,&row3);
1705 if (rc != ERROR_SUCCESS)
1707 c_indx = load_component(package,row3);
1708 msiobj_release( &row3->hdr );
1710 package->features[index].Components[cnt] = c_indx;
1711 package->features[index].ComponentCount ++;
1713 MSI_ViewClose(view2);
1714 msiobj_release( &view2->hdr );
1715 msiobj_release( &row2->hdr );
1717 MSI_ViewClose(view);
1718 msiobj_release(&view->hdr);
1722 * I am not doing any of the costing functionality yet.
1723 * Mostly looking at doing the Component and Feature loading
1725 * The native MSI does ALOT of modification to tables here. Mostly adding alot
1726 * of temporary columns to the Feature and Component tables.
1728 * note: native msi also tracks the short filename. but I am only going to
1729 * track the long ones. Also looking at this directory table
1730 * it appears that the directory table does not get the parents
1731 * resolved base on property only based on their entrys in the
1734 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1740 static const WCHAR Query_all[] = {
1741 'S','E','L','E','C','T',' ','*',' ',
1742 'F','R','O','M',' ','F','e','a','t','u','r','e',0};
1743 static const WCHAR szCosting[] = {
1744 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1745 static const WCHAR szZero[] = { '0', 0 };
1747 MSI_SetPropertyW(package, szCosting, szZero);
1748 MSI_SetPropertyW(package, cszRootDrive , c_collen);
1751 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1752 if (rc != ERROR_SUCCESS)
1754 rc = MSI_ViewExecute(view,0);
1755 if (rc != ERROR_SUCCESS)
1757 MSI_ViewClose(view);
1758 msiobj_release(&view->hdr);
1765 rc = MSI_ViewFetch(view,&row);
1766 if (rc != ERROR_SUCCESS)
1769 load_feature(package,row);
1770 msiobj_release(&row->hdr);
1772 MSI_ViewClose(view);
1773 msiobj_release(&view->hdr);
1775 return ERROR_SUCCESS;
1778 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1780 DWORD index = package->loaded_files;
1782 WCHAR buffer[0x100];
1785 /* fill in the data */
1787 package->loaded_files++;
1788 if (package->loaded_files== 1)
1789 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1791 package->files = HeapReAlloc(GetProcessHeap(),0,
1792 package->files , package->loaded_files * sizeof(MSIFILE));
1794 memset(&package->files[index],0,sizeof(MSIFILE));
1797 MSI_RecordGetStringW(row,1,package->files[index].File,&sz);
1800 MSI_RecordGetStringW(row,2,buffer,&sz);
1802 package->files[index].ComponentIndex = -1;
1803 for (i = 0; i < package->loaded_components; i++)
1804 if (strcmpW(package->components[i].Component,buffer)==0)
1806 package->files[index].ComponentIndex = i;
1809 if (package->files[index].ComponentIndex == -1)
1810 ERR("Unfound Component %s\n",debugstr_w(buffer));
1813 MSI_RecordGetStringW(row,3,package->files[index].FileName,&sz);
1815 reduce_to_longfilename(package->files[index].FileName);
1817 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1820 if (!MSI_RecordIsNull(row,5))
1821 MSI_RecordGetStringW(row,5,package->files[index].Version,&sz);
1824 if (!MSI_RecordIsNull(row,6))
1825 MSI_RecordGetStringW(row,6,package->files[index].Language,&sz);
1827 if (!MSI_RecordIsNull(row,7))
1828 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1830 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1832 package->files[index].Temporary = FALSE;
1833 package->files[index].State = 0;
1835 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1837 return ERROR_SUCCESS;
1840 static UINT ACTION_FileCost(MSIPACKAGE *package)
1845 static const WCHAR Query[] = {
1846 'S','E','L','E','C','T',' ','*',' ',
1847 'F','R','O','M',' ','F','i','l','e',' ',
1848 'O','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e', 0};
1851 return ERROR_INVALID_HANDLE;
1853 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1854 if (rc != ERROR_SUCCESS)
1855 return ERROR_SUCCESS;
1857 rc = MSI_ViewExecute(view, 0);
1858 if (rc != ERROR_SUCCESS)
1860 MSI_ViewClose(view);
1861 msiobj_release(&view->hdr);
1862 return ERROR_SUCCESS;
1867 rc = MSI_ViewFetch(view,&row);
1868 if (rc != ERROR_SUCCESS)
1873 load_file(package,row);
1874 msiobj_release(&row->hdr);
1876 MSI_ViewClose(view);
1877 msiobj_release(&view->hdr);
1879 return ERROR_SUCCESS;
1882 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1886 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','D','i','r','e','c',
1887 't','o','r','y',' ','w','h','e','r','e',' ','`','D','i','r','e','c','t',
1888 'o','r','y','`',' ','=',' ','`',0};
1889 static const WCHAR end[]={'`',0};
1892 WCHAR targetbuffer[0x100];
1893 WCHAR *srcdir = NULL;
1894 WCHAR *targetdir = NULL;
1895 WCHAR parent[0x100];
1897 MSIRECORD * row = 0;
1901 TRACE("Looking for dir %s\n",debugstr_w(dir));
1903 for (i = 0; i < package->loaded_folders; i++)
1905 if (strcmpW(package->folders[i].Directory,dir)==0)
1907 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
1912 TRACE("Working to load %s\n",debugstr_w(dir));
1914 index = package->loaded_folders;
1916 package->loaded_folders++;
1917 if (package->loaded_folders== 1)
1918 package->folders = HeapAlloc(GetProcessHeap(),0,
1921 package->folders= HeapReAlloc(GetProcessHeap(),0,
1922 package->folders, package->loaded_folders*
1925 memset(&package->folders[index],0,sizeof(MSIFOLDER));
1927 strcpyW(package->folders[index].Directory,dir);
1932 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1934 if (rc != ERROR_SUCCESS)
1937 rc = MSI_ViewExecute(view, 0);
1938 if (rc != ERROR_SUCCESS)
1940 MSI_ViewClose(view);
1941 msiobj_release(&view->hdr);
1945 rc = MSI_ViewFetch(view,&row);
1946 if (rc != ERROR_SUCCESS)
1948 MSI_ViewClose(view);
1949 msiobj_release(&view->hdr);
1954 MSI_RecordGetStringW(row,3,targetbuffer,&sz);
1955 targetdir=targetbuffer;
1957 /* split src and target dir */
1958 if (strchrW(targetdir,':'))
1960 srcdir=strchrW(targetdir,':');
1967 /* for now only pick long filename versions */
1968 if (strchrW(targetdir,'|'))
1970 targetdir = strchrW(targetdir,'|');
1974 if (srcdir && strchrW(srcdir,'|'))
1976 srcdir= strchrW(srcdir,'|');
1981 /* now check for root dirs */
1982 if (targetdir[0] == '.' && targetdir[1] == 0)
1985 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
1989 strcpyW(package->folders[index].TargetDefault,targetdir);
1992 strcpyW(package->folders[index].SourceDefault,srcdir);
1994 strcpyW(package->folders[index].SourceDefault,targetdir);
1996 if (MSI_RecordIsNull(row,2))
2001 MSI_RecordGetStringW(row,2,parent,&sz);
2006 i = load_folder(package,parent);
2007 package->folders[index].ParentIndex = i;
2008 TRACE("Parent is index %i... %s %s\n",
2009 package->folders[index].ParentIndex,
2010 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
2011 debugstr_w(parent));
2014 package->folders[index].ParentIndex = -2;
2017 rc = MSI_GetPropertyW(package, dir, package->folders[index].Property, &sz);
2018 if (rc != ERROR_SUCCESS)
2019 package->folders[index].Property[0]=0;
2021 msiobj_release(&row->hdr);
2022 MSI_ViewClose(view);
2023 msiobj_release(&view->hdr);
2024 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
2028 static UINT resolve_folder(MSIPACKAGE *package, LPCWSTR name, LPWSTR path,
2029 BOOL source, BOOL set_prop, MSIFOLDER **folder)
2032 UINT rc = ERROR_SUCCESS;
2035 TRACE("Working to resolve %s\n",debugstr_w(name));
2040 /* special resolving for Target and Source root dir */
2041 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
2046 rc = MSI_GetPropertyW(package,cszTargetDir,path,&sz);
2047 if (rc != ERROR_SUCCESS)
2050 rc = MSI_GetPropertyW(package,cszRootDrive,path,&sz);
2052 MSI_SetPropertyW(package,cszTargetDir,path);
2055 *folder = &(package->folders[0]);
2061 rc = MSI_GetPropertyW(package,cszSourceDir,path,&sz);
2062 if (rc != ERROR_SUCCESS)
2065 rc = MSI_GetPropertyW(package,cszDatabase,path,&sz);
2066 if (rc == ERROR_SUCCESS)
2068 LPWSTR ptr = strrchrW(path,'\\');
2077 *folder = &(package->folders[0]);
2082 for (i = 0; i < package->loaded_folders; i++)
2084 if (strcmpW(package->folders[i].Directory,name)==0)
2088 if (i >= package->loaded_folders)
2089 return ERROR_FUNCTION_FAILED;
2092 *folder = &(package->folders[i]);
2094 if (!source && package->folders[i].ResolvedTarget[0])
2096 strcpyW(path,package->folders[i].ResolvedTarget);
2097 TRACE(" already resolved to %s\n",debugstr_w(path));
2098 return ERROR_SUCCESS;
2100 else if (source && package->folders[i].ResolvedSource[0])
2102 strcpyW(path,package->folders[i].ResolvedSource);
2103 return ERROR_SUCCESS;
2105 else if (!source && package->folders[i].Property[0])
2107 strcpyW(path,package->folders[i].Property);
2108 TRACE(" internally set to %s\n",debugstr_w(path));
2110 MSI_SetPropertyW(package,name,path);
2111 return ERROR_SUCCESS;
2114 if (package->folders[i].ParentIndex >= 0)
2117 TRACE(" ! Parent is %s\n", debugstr_w(package->folders[
2118 package->folders[i].ParentIndex].Directory));
2119 resolve_folder(package, package->folders[
2120 package->folders[i].ParentIndex].Directory, path,source,
2123 len = strlenW(path);
2124 if (len && path[len-1] != '\\')
2125 strcatW(path, cszbs);
2129 if (package->folders[i].TargetDefault[0])
2131 strcatW(path,package->folders[i].TargetDefault);
2132 strcatW(path,cszbs);
2134 strcpyW(package->folders[i].ResolvedTarget,path);
2135 TRACE(" resolved into %s\n",debugstr_w(path));
2137 MSI_SetPropertyW(package,name,path);
2141 if (package->folders[i].SourceDefault[0])
2143 strcatW(path,package->folders[i].SourceDefault);
2144 strcatW(path,cszbs);
2146 strcpyW(package->folders[i].ResolvedSource,path);
2153 * Alot is done in this function aside from just the costing.
2154 * The costing needs to be implemented at some point but for now I am going
2155 * to focus on the directory building
2158 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2160 static const WCHAR ExecSeqQuery[] = {
2161 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2162 'D','i','r','e','c','t','o','r','y',0};
2163 static const WCHAR ConditionQuery[] = {
2164 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2165 'C','o','n','d','i','t','i','o','n',0};
2166 static const WCHAR szCosting[] = {
2167 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2168 static const WCHAR szOne[] = { '1', 0 };
2173 TRACE("Building Directory properties\n");
2175 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2176 if (rc == ERROR_SUCCESS)
2178 rc = MSI_ViewExecute(view, 0);
2179 if (rc != ERROR_SUCCESS)
2181 MSI_ViewClose(view);
2182 msiobj_release(&view->hdr);
2189 WCHAR path[MAX_PATH];
2190 MSIRECORD * row = 0;
2193 rc = MSI_ViewFetch(view,&row);
2194 if (rc != ERROR_SUCCESS)
2201 MSI_RecordGetStringW(row,1,name,&sz);
2203 /* This helper function now does ALL the work */
2204 TRACE("Dir %s ...\n",debugstr_w(name));
2205 load_folder(package,name);
2206 resolve_folder(package,name,path,FALSE,TRUE,NULL);
2207 TRACE("resolves to %s\n",debugstr_w(path));
2209 msiobj_release(&row->hdr);
2211 MSI_ViewClose(view);
2212 msiobj_release(&view->hdr);
2215 TRACE("File calculations %i files\n",package->loaded_files);
2217 for (i = 0; i < package->loaded_files; i++)
2219 MSICOMPONENT* comp = NULL;
2220 MSIFILE* file= NULL;
2222 file = &package->files[i];
2223 if (file->ComponentIndex >= 0)
2224 comp = &package->components[file->ComponentIndex];
2229 /* calculate target */
2230 resolve_folder(package, comp->Directory, file->TargetPath, FALSE,
2232 /* make sure that the path ends in a \ */
2233 len = strlenW(file->TargetPath);
2234 if (len && file->TargetPath[len-1] != '\\')
2235 strcatW(file->TargetPath, cszbs);
2236 strcatW(file->TargetPath,file->FileName);
2238 TRACE("file %s resolves to %s\n",
2239 debugstr_w(file->File),debugstr_w(file->TargetPath));
2241 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2244 comp->Cost += file->FileSize;
2248 if (file->Version[0])
2254 static const WCHAR name[] =
2256 static const WCHAR name_fmt[] =
2257 {'%','u','.','%','u','.','%','u','.','%','u',0};
2258 WCHAR filever[0x100];
2259 VS_FIXEDFILEINFO *lpVer;
2261 FIXME("Version comparison.. \n");
2262 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2263 version = HeapAlloc(GetProcessHeap(),0,versize);
2264 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2266 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2268 sprintfW(filever,name_fmt,
2269 HIWORD(lpVer->dwFileVersionMS),
2270 LOWORD(lpVer->dwFileVersionMS),
2271 HIWORD(lpVer->dwFileVersionLS),
2272 LOWORD(lpVer->dwFileVersionLS));
2274 TRACE("new %s old %s\n", debugstr_w(file->Version),
2275 debugstr_w(filever));
2276 if (strcmpiW(filever,file->Version)<0)
2279 FIXME("cost should be diff in size\n");
2280 comp->Cost += file->FileSize;
2284 HeapFree(GetProcessHeap(),0,version);
2292 TRACE("Evaluating Condition Table\n");
2294 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2295 if (rc == ERROR_SUCCESS)
2297 rc = MSI_ViewExecute(view, 0);
2298 if (rc != ERROR_SUCCESS)
2300 MSI_ViewClose(view);
2301 msiobj_release(&view->hdr);
2307 WCHAR Feature[0x100];
2308 MSIRECORD * row = 0;
2312 rc = MSI_ViewFetch(view,&row);
2314 if (rc != ERROR_SUCCESS)
2321 MSI_RecordGetStringW(row,1,Feature,&sz);
2323 feature_index = get_loaded_feature(package,Feature);
2324 if (feature_index < 0)
2325 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2329 Condition = load_dynamic_stringW(row,3);
2331 if (MSI_EvaluateConditionW(package,Condition) ==
2334 int level = MSI_RecordGetInteger(row,2);
2335 TRACE("Reseting feature %s to level %i\n",
2336 debugstr_w(Feature), level);
2337 package->features[feature_index].Level = level;
2339 HeapFree(GetProcessHeap(),0,Condition);
2342 msiobj_release(&row->hdr);
2344 MSI_ViewClose(view);
2345 msiobj_release(&view->hdr);
2348 TRACE("Enabling or Disabling Components\n");
2349 for (i = 0; i < package->loaded_components; i++)
2351 if (package->components[i].Condition[0])
2353 if (MSI_EvaluateConditionW(package,
2354 package->components[i].Condition) == MSICONDITION_FALSE)
2356 TRACE("Disabling component %s\n",
2357 debugstr_w(package->components[i].Component));
2358 package->components[i].Enabled = FALSE;
2363 MSI_SetPropertyW(package,szCosting,szOne);
2364 return ERROR_SUCCESS;
2368 * This is a helper function for handling embedded cabinet media
2370 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2378 WCHAR tmp[MAX_PATH];
2380 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2381 if (rc != ERROR_SUCCESS)
2385 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2386 GetTempPathW(MAX_PATH,tmp);
2388 GetTempFileNameW(tmp,stream_name,0,source);
2390 track_tempfile(package,strrchrW(source,'\\'), source);
2391 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2392 FILE_ATTRIBUTE_NORMAL, NULL);
2394 if (the_file == INVALID_HANDLE_VALUE)
2396 rc = ERROR_FUNCTION_FAILED;
2400 WriteFile(the_file,data,size,&write,NULL);
2401 CloseHandle(the_file);
2402 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2404 HeapFree(GetProcessHeap(),0,data);
2409 /* Support functions for FDI functions */
2411 static void * cabinet_alloc(ULONG cb)
2413 return HeapAlloc(GetProcessHeap(), 0, cb);
2416 static void cabinet_free(void *pv)
2418 HeapFree(GetProcessHeap(), 0, pv);
2421 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2424 DWORD dwShareMode = 0;
2425 DWORD dwCreateDisposition = OPEN_EXISTING;
2426 switch (oflag & _O_ACCMODE)
2429 dwAccess = GENERIC_READ;
2430 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2433 dwAccess = GENERIC_WRITE;
2434 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2437 dwAccess = GENERIC_READ | GENERIC_WRITE;
2438 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2441 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2442 dwCreateDisposition = CREATE_NEW;
2443 else if (oflag & _O_CREAT)
2444 dwCreateDisposition = CREATE_ALWAYS;
2445 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL, dwCreateDisposition, 0, NULL);
2448 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2451 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2456 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2459 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2464 static int cabinet_close(INT_PTR hf)
2466 return CloseHandle((HANDLE)hf) ? 0 : -1;
2469 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2471 /* flags are compatible and so are passed straight through */
2472 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2475 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2477 /* FIXME: try to do more processing in this function */
2480 case fdintCOPY_FILE:
2482 ULONG len = strlen((char*)pfdin->pv) + strlen(pfdin->psz1);
2483 char *file = cabinet_alloc((len+1)*sizeof(char));
2485 strcpy(file, (char*)pfdin->pv);
2486 strcat(file, pfdin->psz1);
2488 TRACE("file: %s\n", debugstr_a(file));
2490 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2492 case fdintCLOSE_FILE_INFO:
2496 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2498 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2500 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2503 cabinet_close(pfdin->hf);
2511 /***********************************************************************
2512 * extract_cabinet_file
2514 * Extract files from a cab file.
2516 static BOOL extract_cabinet_file(const WCHAR* source, const WCHAR* path)
2524 TRACE("Extracting %s to %s\n",debugstr_w(source), debugstr_w(path));
2526 hfdi = FDICreate(cabinet_alloc,
2537 ERR("FDICreate failed\n");
2541 if (!(cabinet = strdupWtoA( source )))
2546 if (!(cab_path = strdupWtoA( path )))
2549 HeapFree(GetProcessHeap(), 0, cabinet);
2553 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, cab_path);
2556 ERR("FDICopy failed\n");
2560 HeapFree(GetProcessHeap(), 0, cabinet);
2561 HeapFree(GetProcessHeap(), 0, cab_path);
2566 static UINT ready_media_for_file(MSIPACKAGE *package, UINT sequence,
2571 MSIRECORD * row = 0;
2572 WCHAR source[MAX_PATH];
2573 static const WCHAR ExecSeqQuery[] = {
2574 's','e','l','e','c','t',' ','*',' ',
2575 'f','r','o','m',' ','M','e','d','i','a',' ',
2576 'w','h','e','r','e',' ','L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%','i',' ',
2577 'o','r','d','e','r',' ','b','y',' ','L','a','s','t','S','e','q','u','e','n','c','e',0};
2582 static UINT last_sequence = 0;
2584 if (sequence <= last_sequence)
2586 TRACE("Media already ready (%u, %u)\n",sequence,last_sequence);
2587 return ERROR_SUCCESS;
2590 sprintfW(Query,ExecSeqQuery,sequence);
2592 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2593 if (rc != ERROR_SUCCESS)
2596 rc = MSI_ViewExecute(view, 0);
2597 if (rc != ERROR_SUCCESS)
2599 MSI_ViewClose(view);
2600 msiobj_release(&view->hdr);
2604 rc = MSI_ViewFetch(view,&row);
2605 if (rc != ERROR_SUCCESS)
2607 MSI_ViewClose(view);
2608 msiobj_release(&view->hdr);
2611 seq = MSI_RecordGetInteger(row,2);
2612 last_sequence = seq;
2614 if (!MSI_RecordIsNull(row,4))
2617 MSI_RecordGetStringW(row,4,cab,&sz);
2618 TRACE("Source is CAB %s\n",debugstr_w(cab));
2619 /* the stream does not contain the # character */
2622 writeout_cabinet_stream(package,&cab[1],source);
2623 strcpyW(path,source);
2624 *(strrchrW(path,'\\')+1)=0;
2629 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
2631 ERR("No Source dir defined \n");
2632 rc = ERROR_FUNCTION_FAILED;
2636 strcpyW(path,source);
2637 strcatW(source,cab);
2638 /* extract the cab file into a folder in the temp folder */
2640 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
2642 GetTempPathW(MAX_PATH,path);
2645 rc = !extract_cabinet_file(source,path);
2647 msiobj_release(&row->hdr);
2648 MSI_ViewClose(view);
2649 msiobj_release(&view->hdr);
2653 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
2657 WCHAR install_path[MAX_PATH];
2659 rc = resolve_folder(package, package->components[component].Directory,
2660 install_path, FALSE, FALSE, &folder);
2662 if (rc != ERROR_SUCCESS)
2665 /* create the path */
2666 if (folder->State == 0)
2668 create_full_pathW(install_path);
2675 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
2677 UINT rc = ERROR_SUCCESS;
2680 WCHAR uipath[MAX_PATH];
2683 return ERROR_INVALID_HANDLE;
2685 /* increment progress bar each time action data is sent */
2686 ui_progress(package,1,1,1,0);
2688 for (index = 0; index < package->loaded_files; index++)
2690 WCHAR path_to_source[MAX_PATH];
2693 file = &package->files[index];
2695 if (file->Temporary)
2698 if (!package->components[file->ComponentIndex].Enabled ||
2699 !package->components[file->ComponentIndex].FeatureState)
2701 TRACE("File %s is not scheduled for install\n",
2702 debugstr_w(file->File));
2706 if ((file->State == 1) || (file->State == 2))
2708 TRACE("Installing %s\n",debugstr_w(file->File));
2709 rc = ready_media_for_file(package,file->Sequence,path_to_source);
2712 * our file table could change here because a new temp file
2713 * may have been created
2715 file = &package->files[index];
2716 if (rc != ERROR_SUCCESS)
2718 ERR("Unable to ready media\n");
2719 rc = ERROR_FUNCTION_FAILED;
2723 create_component_directory( package, file->ComponentIndex);
2725 strcpyW(file->SourcePath, path_to_source);
2726 strcatW(file->SourcePath, file->File);
2728 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
2729 debugstr_w(file->TargetPath));
2732 uirow=MSI_CreateRecord(9);
2733 MSI_RecordSetStringW(uirow,1,file->File);
2734 strcpyW(uipath,file->TargetPath);
2735 *(strrchrW(uipath,'\\')+1)=0;
2736 MSI_RecordSetStringW(uirow,9,uipath);
2737 MSI_RecordSetInteger(uirow,6,file->FileSize);
2738 ui_actiondata(package,szInstallFiles,uirow);
2739 msiobj_release( &uirow->hdr );
2741 if (!MoveFileW(file->SourcePath,file->TargetPath))
2743 rc = GetLastError();
2744 ERR("Unable to move file (%s -> %s) (error %d)\n",
2745 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
2747 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
2749 CopyFileW(file->SourcePath,file->TargetPath,FALSE);
2750 DeleteFileW(file->SourcePath);
2759 ui_progress(package,2,0,0,0);
2766 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
2772 return ERROR_INVALID_HANDLE;
2774 for (index = 0; index < package->loaded_files; index ++)
2776 if (strcmpW(file_key,package->files[index].File)==0)
2778 if (package->files[index].State >= 3)
2780 strcpyW(file_source,package->files[index].TargetPath);
2781 return ERROR_SUCCESS;
2784 return ERROR_FILE_NOT_FOUND;
2788 return ERROR_FUNCTION_FAILED;
2791 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
2795 MSIRECORD * row = 0;
2796 static const WCHAR ExecSeqQuery[] = {
2797 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2798 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
2801 return ERROR_INVALID_HANDLE;
2803 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2804 if (rc != ERROR_SUCCESS)
2805 return ERROR_SUCCESS;
2807 rc = MSI_ViewExecute(view, 0);
2808 if (rc != ERROR_SUCCESS)
2810 MSI_ViewClose(view);
2811 msiobj_release(&view->hdr);
2817 WCHAR file_key[0x100];
2818 WCHAR file_source[MAX_PATH];
2819 WCHAR dest_name[0x100];
2820 WCHAR dest_path[MAX_PATH];
2821 WCHAR component[0x100];
2822 INT component_index;
2826 rc = MSI_ViewFetch(view,&row);
2827 if (rc != ERROR_SUCCESS)
2834 rc = MSI_RecordGetStringW(row,2,component,&sz);
2835 if (rc != ERROR_SUCCESS)
2837 ERR("Unable to get component\n");
2838 msiobj_release(&row->hdr);
2842 component_index = get_loaded_component(package,component);
2843 if (!package->components[component_index].Enabled ||
2844 !package->components[component_index].FeatureState)
2846 TRACE("Skipping copy due to disabled component\n");
2847 msiobj_release(&row->hdr);
2852 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
2853 if (rc != ERROR_SUCCESS)
2855 ERR("Unable to get file key\n");
2856 msiobj_release(&row->hdr);
2860 rc = get_file_target(package,file_key,file_source);
2862 if (rc != ERROR_SUCCESS)
2864 ERR("Original file unknown %s\n",debugstr_w(file_key));
2865 msiobj_release(&row->hdr);
2869 if (MSI_RecordIsNull(row,4))
2871 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
2876 MSI_RecordGetStringW(row,4,dest_name,&sz);
2877 reduce_to_longfilename(dest_name);
2880 if (MSI_RecordIsNull(row,5))
2882 strcpyW(dest_path,file_source);
2883 *strrchrW(dest_path,'\\')=0;
2887 WCHAR destkey[0x100];
2889 MSI_RecordGetStringW(row,5,destkey,&sz);
2891 rc = resolve_folder(package, destkey, dest_path,FALSE,FALSE,NULL);
2892 if (rc != ERROR_SUCCESS)
2894 ERR("Unable to get destination folder\n");
2895 msiobj_release(&row->hdr);
2900 strcatW(dest_path,dest_name);
2902 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
2903 debugstr_w(dest_path));
2905 if (strcmpW(file_source,dest_path))
2906 rc = !CopyFileW(file_source,dest_path,TRUE);
2910 if (rc != ERROR_SUCCESS)
2911 ERR("Failed to copy file\n");
2913 FIXME("We should track these duplicate files as well\n");
2915 msiobj_release(&row->hdr);
2917 MSI_ViewClose(view);
2918 msiobj_release(&view->hdr);
2924 /* OK this value is "interpretted" and then formatted based on the
2925 first few characters */
2926 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
2930 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
2939 deformat_string(package, &value[2], &deformated);
2941 /* binary value type */
2944 *size = strlenW(ptr)/2;
2945 data = HeapAlloc(GetProcessHeap(),0,*size);
2957 data[count] = (BYTE)strtol(byte,NULL,0);
2960 HeapFree(GetProcessHeap(),0,deformated);
2962 TRACE("Data %li bytes(%i)\n",*size,count);
2967 deformat_string(package, &value[1], &deformated);
2970 *size = sizeof(DWORD);
2971 data = HeapAlloc(GetProcessHeap(),0,*size);
2972 *(LPDWORD)data = atoiW(deformated);
2973 TRACE("DWORD %i\n",*data);
2975 HeapFree(GetProcessHeap(),0,deformated);
2988 *type=REG_EXPAND_SZ;
2996 *size = deformat_string(package, ptr,(LPWSTR*)&data);
3001 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3005 MSIRECORD * row = 0;
3006 static const WCHAR ExecSeqQuery[] = {
3007 's','e','l','e','c','t',' ','*',' ',
3008 'f','r','o','m',' ','R','e','g','i','s','t','r','y',0 };
3011 return ERROR_INVALID_HANDLE;
3013 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3014 if (rc != ERROR_SUCCESS)
3015 return ERROR_SUCCESS;
3017 rc = MSI_ViewExecute(view, 0);
3018 if (rc != ERROR_SUCCESS)
3020 MSI_ViewClose(view);
3021 msiobj_release(&view->hdr);
3025 /* increment progress bar each time action data is sent */
3026 ui_progress(package,1,1,1,0);
3030 static const WCHAR szHCR[] =
3031 {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T','\\',0};
3032 static const WCHAR szHCU[] =
3033 {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',0};
3034 static const WCHAR szHLM[] =
3035 {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',
3037 static const WCHAR szHU[] =
3038 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3043 LPSTR value_data = NULL;
3044 HKEY root_key, hkey;
3046 WCHAR component[0x100];
3047 INT component_index;
3054 rc = MSI_ViewFetch(view,&row);
3055 if (rc != ERROR_SUCCESS)
3062 MSI_RecordGetStringW(row,6,component,&sz);
3063 component_index = get_loaded_component(package,component);
3065 if (!package->components[component_index].Enabled ||
3066 !package->components[component_index].FeatureState)
3068 TRACE("Skipping write due to disabled component\n");
3069 msiobj_release(&row->hdr);
3073 /* null values have special meanings during uninstalls and such */
3075 if(MSI_RecordIsNull(row,5))
3077 msiobj_release(&row->hdr);
3081 root = MSI_RecordGetInteger(row,2);
3083 MSI_RecordGetStringW(row,3,key,&sz);
3086 if (MSI_RecordIsNull(row,4))
3089 MSI_RecordGetStringW(row,4,name,&sz);
3091 /* get the root key */
3094 case 0: root_key = HKEY_CLASSES_ROOT;
3095 strcpyW(uikey,szHCR); break;
3096 case 1: root_key = HKEY_CURRENT_USER;
3097 strcpyW(uikey,szHCU); break;
3098 case 2: root_key = HKEY_LOCAL_MACHINE;
3099 strcpyW(uikey,szHLM); break;
3100 case 3: root_key = HKEY_USERS;
3101 strcpyW(uikey,szHU); break;
3103 ERR("Unknown root %i\n",root);
3109 msiobj_release(&row->hdr);
3114 if (RegCreateKeyW( root_key, key, &hkey))
3116 ERR("Could not create key %s\n",debugstr_w(key));
3117 msiobj_release(&row->hdr);
3121 value = load_dynamic_stringW(row,5);
3122 value_data = parse_value(package, value, &type, &size);
3126 TRACE("Setting value %s\n",debugstr_w(name));
3127 RegSetValueExW(hkey, name, 0, type, value_data, size);
3129 uirow = MSI_CreateRecord(3);
3130 MSI_RecordSetStringW(uirow,2,name);
3131 MSI_RecordSetStringW(uirow,1,uikey);
3134 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3136 MSI_RecordSetStringW(uirow,3,value);
3138 ui_actiondata(package,szWriteRegistryValues,uirow);
3139 ui_progress(package,2,0,0,0);
3140 msiobj_release( &uirow->hdr );
3142 HeapFree(GetProcessHeap(),0,value_data);
3144 HeapFree(GetProcessHeap(),0,value);
3146 msiobj_release(&row->hdr);
3149 MSI_ViewClose(view);
3150 msiobj_release(&view->hdr);
3155 * This helper function should probably go alot of places
3157 * Thinking about this, maybe this should become yet another Bison file
3159 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data)
3169 /* scan for special characters */
3170 if (!strchrW(ptr,'[') || (strchrW(ptr,'[') && !strchrW(ptr,']')))
3173 size = (strlenW(ptr)+1) * sizeof(WCHAR);
3174 *data = HeapAlloc(GetProcessHeap(),0,size);
3179 /* formatted string located */
3180 mark = strchrW(ptr,'[');
3183 INT cnt = (mark - ptr);
3184 TRACE("%i (%i) characters before marker\n",cnt,(mark-ptr));
3185 size = cnt * sizeof(WCHAR);
3186 size += sizeof(WCHAR);
3187 *data = HeapAlloc(GetProcessHeap(),0,size);
3188 strncpyW(*data,ptr,cnt);
3193 size = sizeof(WCHAR);
3194 *data = HeapAlloc(GetProcessHeap(),0,size);
3199 *strchrW(key,']')=0;
3200 mark = strchrW(mark,']');
3202 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3204 rc = MSI_GetPropertyW(package, key, NULL, &sz);
3205 if ((rc == ERROR_SUCCESS) || (rc == ERROR_MORE_DATA))
3210 value = HeapAlloc(GetProcessHeap(),0,sz * sizeof(WCHAR));
3211 MSI_GetPropertyW(package, key, value, &sz);
3213 chunk = (strlenW(value)+1) * sizeof(WCHAR);
3215 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
3217 strcatW(*data,value);
3219 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3223 chunk = (strlenW(mark)+1) * sizeof(WCHAR);
3225 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
3227 strcatW(*data,mark);
3229 (*data)[strlenW(*data)]=0;
3230 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3232 /* recursively do this to clean up */
3233 mark = HeapAlloc(GetProcessHeap(),0,size);
3234 strcpyW(mark,*data);
3235 TRACE("String at this point %s\n",debugstr_w(mark));
3236 size = deformat_string(package,mark,data);
3237 HeapFree(GetProcessHeap(),0,mark);
3241 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3249 LPWSTR override = NULL;
3250 static const WCHAR addlocal[]={'A','D','D','L','O','C','A','L',0};
3251 static const WCHAR all[]={'A','L','L',0};
3252 static const WCHAR szlevel[] = {
3253 'I','N','S','T','A','L','L','L','E','V','E','L',0};
3254 static const WCHAR szAddLocal[] = {
3255 'A','D','D','L','O','C','A','L',0};
3257 /* I do not know if this is where it should happen.. but */
3259 TRACE("Checking Install Level\n");
3262 if (MSI_GetPropertyW(package,szlevel,level,&sz)==ERROR_SUCCESS)
3263 install_level = atoiW(level);
3268 rc = MSI_GetPropertyW(package,szAddLocal,NULL,&sz);
3269 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
3272 override = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
3273 MSI_GetPropertyW(package, addlocal,override,&sz);
3277 * Components FeatureState defaults to FALSE. The idea is we want to
3278 * enable the component is ANY feature that uses it is enabled to install
3280 for(i = 0; i < package->loaded_features; i++)
3282 BOOL feature_state= ((package->features[i].Level > 0) &&
3283 (package->features[i].Level <= install_level));
3285 if (override && (strcmpiW(override,all)==0 ||
3286 strstrW(override,package->features[i].Feature)))
3288 TRACE("Override of install level found\n");
3289 feature_state = TRUE;
3290 package->features[i].Enabled = feature_state;
3293 TRACE("Feature %s has a state of %i\n",
3294 debugstr_w(package->features[i].Feature), feature_state);
3295 for( j = 0; j < package->features[i].ComponentCount; j++)
3297 package->components[package->features[i].Components[j]].FeatureState
3301 if (override != NULL)
3302 HeapFree(GetProcessHeap(),0,override);
3304 * So basically we ONLY want to install a component if its Enabled AND
3305 * FeatureState are both TRUE
3307 return ERROR_SUCCESS;
3310 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3313 static const WCHAR q1[]={
3314 'S','E','L','E','C','T',' ','*',' ',
3315 'F','R','O','M',' ','R','e','g','i','s','t','r','y',0};
3318 MSIRECORD * row = 0;
3320 TRACE(" InstallValidate \n");
3322 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3323 if (rc != ERROR_SUCCESS)
3324 return ERROR_SUCCESS;
3326 rc = MSI_ViewExecute(view, 0);
3327 if (rc != ERROR_SUCCESS)
3329 MSI_ViewClose(view);
3330 msiobj_release(&view->hdr);
3335 rc = MSI_ViewFetch(view,&row);
3336 if (rc != ERROR_SUCCESS)
3343 msiobj_release(&row->hdr);
3345 MSI_ViewClose(view);
3346 msiobj_release(&view->hdr);
3348 ui_progress(package,0,progress+package->loaded_files,0,0);
3350 return ERROR_SUCCESS;
3353 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3356 MSIQUERY * view = NULL;
3357 MSIRECORD * row = 0;
3358 static const WCHAR ExecSeqQuery[] = {
3359 'S','E','L','E','C','T',' ','*',' ',
3360 'f','r','o','m',' ','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3361 static const WCHAR title[]=
3362 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3364 TRACE("Checking launch conditions\n");
3366 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3367 if (rc != ERROR_SUCCESS)
3368 return ERROR_SUCCESS;
3370 rc = MSI_ViewExecute(view, 0);
3371 if (rc != ERROR_SUCCESS)
3373 MSI_ViewClose(view);
3374 msiobj_release(&view->hdr);
3379 while (rc == ERROR_SUCCESS)
3382 LPWSTR message = NULL;
3384 rc = MSI_ViewFetch(view,&row);
3385 if (rc != ERROR_SUCCESS)
3391 cond = load_dynamic_stringW(row,1);
3393 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3395 message = load_dynamic_stringW(row,2);
3396 MessageBoxW(NULL,message,title,MB_OK);
3397 HeapFree(GetProcessHeap(),0,message);
3398 rc = ERROR_FUNCTION_FAILED;
3400 HeapFree(GetProcessHeap(),0,cond);
3401 msiobj_release(&row->hdr);
3403 MSI_ViewClose(view);
3404 msiobj_release(&view->hdr);
3408 static void resolve_keypath( MSIPACKAGE* package, INT
3409 component_index, WCHAR *keypath)
3411 MSICOMPONENT* cmp = &package->components[component_index];
3413 if (cmp->KeyPath[0]==0)
3415 resolve_folder(package,cmp->Directory,keypath,FALSE,FALSE,NULL);
3418 if ((cmp->Attributes & 0x4) || (cmp->Attributes & 0x20))
3420 FIXME("UNIMPLEMENTED keypath as Registry or ODBC Source\n");
3426 j = get_loaded_file(package,cmp->KeyPath);
3429 strcpyW(keypath,package->files[j].TargetPath);
3434 * Ok further analysis makes me think that this work is
3435 * actually done in the PublishComponents and PublishFeatures
3436 * step, and not here. It appears like the keypath and all that is
3437 * resolved in this step, however actually written in the Publish steps.
3438 * But we will leave it here for now because it is unclear
3440 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
3442 WCHAR productcode[0x100];
3443 WCHAR squished_pc[0x100];
3444 WCHAR squished_cc[0x100];
3448 HKEY hkey=0,hkey2=0,hkey3=0;
3449 static const WCHAR szProductCode[]=
3450 {'P','r','o','d','u','c','t','C','o','d','e',0};
3451 static const WCHAR szInstaller[] = {
3452 'S','o','f','t','w','a','r','e','\\',
3453 'M','i','c','r','o','s','o','f','t','\\',
3454 'W','i','n','d','o','w','s','\\',
3455 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3456 'I','n','s','t','a','l','l','e','r',0 };
3457 static const WCHAR szFeatures[] = {
3458 'F','e','a','t','u','r','e','s',0 };
3459 static const WCHAR szComponents[] = {
3460 'C','o','m','p','o','n','e','n','t','s',0 };
3463 return ERROR_INVALID_HANDLE;
3465 /* writes the Component and Features values to the registry */
3467 rc = MSI_GetPropertyW(package,szProductCode,productcode,&sz);
3468 if (rc != ERROR_SUCCESS)
3469 return ERROR_SUCCESS;
3471 squash_guid(productcode,squished_pc);
3472 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller,&hkey);
3473 if (rc != ERROR_SUCCESS)
3476 rc = RegCreateKeyW(hkey,szFeatures,&hkey2);
3477 if (rc != ERROR_SUCCESS)
3480 rc = RegCreateKeyW(hkey2,squished_pc,&hkey3);
3481 if (rc != ERROR_SUCCESS)
3484 /* here the guids are base 85 encoded */
3485 for (i = 0; i < package->loaded_features; i++)
3492 size = package->features[i].ComponentCount*21*sizeof(WCHAR);
3493 data = HeapAlloc(GetProcessHeap(), 0, size);
3496 for (j = 0; j < package->features[i].ComponentCount; j++)
3499 TRACE("From %s\n",debugstr_w(package->components
3500 [package->features[i].Components[j]].ComponentId));
3501 CLSIDFromString(package->components
3502 [package->features[i].Components[j]].ComponentId,
3504 encode_base85_guid(&clsid,buf);
3505 TRACE("to %s\n",debugstr_w(buf));
3509 size = strlenW(data)*sizeof(WCHAR);
3510 RegSetValueExW(hkey3,package->features[i].Feature,0,REG_SZ,
3512 HeapFree(GetProcessHeap(),0,data);
3518 rc = RegCreateKeyW(hkey,szComponents,&hkey2);
3519 if (rc != ERROR_SUCCESS)
3522 for (i = 0; i < package->loaded_components; i++)
3524 if (package->components[i].ComponentId[0]!=0)
3526 WCHAR keypath[0x1000];
3529 squash_guid(package->components[i].ComponentId,squished_cc);
3530 rc = RegCreateKeyW(hkey2,squished_cc,&hkey3);
3531 if (rc != ERROR_SUCCESS)
3534 resolve_keypath(package,i,keypath);
3536 RegSetValueExW(hkey3,squished_pc,0,REG_SZ,(LPVOID)keypath,
3537 (strlenW(keypath)+1)*sizeof(WCHAR));
3541 uirow = MSI_CreateRecord(3);
3542 MSI_RecordSetStringW(uirow,1,productcode);
3543 MSI_RecordSetStringW(uirow,2,package->components[i].ComponentId);
3544 MSI_RecordSetStringW(uirow,3,keypath);
3545 ui_actiondata(package,szProcessComponents,uirow);
3546 msiobj_release( &uirow->hdr );
3555 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
3558 * OK this is a bit confusing.. I am given a _Component key and I believe
3559 * that the file that is being registered as a type library is the "key file
3560 * of that component" which I interpret to mean "The file in the KeyPath of
3565 MSIRECORD * row = 0;
3566 static const WCHAR Query[] = {
3567 'S','E','L','E','C','T',' ','*',' ',
3568 'f','r','o','m',' ','T','y','p','e','L','i','b',0};
3573 return ERROR_INVALID_HANDLE;
3575 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3576 if (rc != ERROR_SUCCESS)
3577 return ERROR_SUCCESS;
3579 rc = MSI_ViewExecute(view, 0);
3580 if (rc != ERROR_SUCCESS)
3582 MSI_ViewClose(view);
3583 msiobj_release(&view->hdr);
3589 WCHAR component[0x100];
3593 rc = MSI_ViewFetch(view,&row);
3594 if (rc != ERROR_SUCCESS)
3601 MSI_RecordGetStringW(row,3,component,&sz);
3603 index = get_loaded_component(package,component);
3606 msiobj_release(&row->hdr);
3610 if (!package->components[index].Enabled ||
3611 !package->components[index].FeatureState)
3613 TRACE("Skipping typelib reg due to disabled component\n");
3614 msiobj_release(&row->hdr);
3618 index = get_loaded_file(package,package->components[index].KeyPath);
3622 msiobj_release(&row->hdr);
3626 res = LoadTypeLib(package->files[index].TargetPath,&ptLib);
3629 WCHAR help[MAX_PATH];
3630 WCHAR helpid[0x100];
3633 MSI_RecordGetStringW(row,6,helpid,&sz);
3635 resolve_folder(package,helpid,help,FALSE,FALSE,NULL);
3637 res = RegisterTypeLib(ptLib,package->files[index].TargetPath,help);
3638 if (!SUCCEEDED(res))
3639 ERR("Failed to register type library %s\n",
3640 debugstr_w(package->files[index].TargetPath));
3643 /* Yes the row has more fields than I need, but #1 is
3644 correct and the only one I need. Why make a new row? */
3646 ui_actiondata(package,szRegisterTypeLibraries,row);
3648 TRACE("Registered %s\n",
3649 debugstr_w(package->files[index].TargetPath));
3653 ITypeLib_Release(ptLib);
3656 ERR("Failed to load type library %s\n",
3657 debugstr_w(package->files[index].TargetPath));
3659 msiobj_release(&row->hdr);
3661 MSI_ViewClose(view);
3662 msiobj_release(&view->hdr);
3667 static UINT register_appid(MSIPACKAGE *package, LPCWSTR clsid, LPCWSTR app )
3669 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3672 MSIRECORD * row = 0;
3673 static const WCHAR ExecSeqQuery[] =
3674 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','p','p','I'
3675 ,'d',' ','w','h','e','r','e',' ','A','p','p','I','d','=','`','%','s','`',0};
3676 WCHAR Query[0x1000];
3681 return ERROR_INVALID_HANDLE;
3683 sprintfW(Query,ExecSeqQuery,clsid);
3685 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3686 if (rc != ERROR_SUCCESS)
3689 rc = MSI_ViewExecute(view, 0);
3690 if (rc != ERROR_SUCCESS)
3692 MSI_ViewClose(view);
3693 msiobj_release(&view->hdr);
3697 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
3698 RegCreateKeyW(hkey2,clsid,&hkey3);
3699 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
3700 (strlenW(app)+1)*sizeof(WCHAR));
3702 rc = MSI_ViewFetch(view,&row);
3703 if (rc != ERROR_SUCCESS)
3705 MSI_ViewClose(view);
3706 msiobj_release(&view->hdr);
3710 if (!MSI_RecordIsNull(row,2))
3712 LPWSTR deformated=0;
3714 static const WCHAR szRemoteServerName[] =
3715 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
3716 buffer = load_dynamic_stringW(row,2);
3717 size = deformat_string(package,buffer,&deformated);
3718 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
3720 HeapFree(GetProcessHeap(),0,deformated);
3721 HeapFree(GetProcessHeap(),0,buffer);
3724 if (!MSI_RecordIsNull(row,3))
3726 static const WCHAR szLocalService[] =
3727 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
3729 buffer = load_dynamic_stringW(row,3);
3730 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3731 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
3732 HeapFree(GetProcessHeap(),0,buffer);
3735 if (!MSI_RecordIsNull(row,4))
3737 static const WCHAR szService[] =
3738 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
3740 buffer = load_dynamic_stringW(row,4);
3741 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3742 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
3743 HeapFree(GetProcessHeap(),0,buffer);
3746 if (!MSI_RecordIsNull(row,5))
3748 static const WCHAR szDLL[] =
3749 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
3751 buffer = load_dynamic_stringW(row,5);
3752 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3753 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
3754 HeapFree(GetProcessHeap(),0,buffer);
3757 if (!MSI_RecordIsNull(row,6))
3759 static const WCHAR szActivate[] =
3760 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
3761 static const WCHAR szY[] = {'Y',0};
3763 if (MSI_RecordGetInteger(row,6))
3764 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
3767 if (!MSI_RecordIsNull(row,7))
3769 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
3770 static const WCHAR szUser[] =
3771 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
3773 if (MSI_RecordGetInteger(row,7))
3774 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
3777 msiobj_release(&row->hdr);
3778 MSI_ViewClose(view);
3779 msiobj_release(&view->hdr);
3785 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
3788 * Again I am assuming the words, "Whose key file represents" when referring
3789 * to a Component as to meaning that Components KeyPath file
3791 * Also there is a very strong connection between ClassInfo and ProgID
3792 * that I am mostly glossing over.
3793 * What would be more propper is to load the ClassInfo and the ProgID info
3794 * into memory data structures and then be able to enable and disable them
3795 * based on component.
3800 MSIRECORD * row = 0;
3801 static const WCHAR ExecSeqQuery[] = {
3802 'S','E','L','E','C','T',' ','*',' ',
3803 'f','r','o','m',' ','C','l','a','s','s',0};
3804 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3805 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
3806 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3807 HKEY hkey,hkey2,hkey3;
3810 return ERROR_INVALID_HANDLE;
3812 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
3813 if (rc != ERROR_SUCCESS)
3814 return ERROR_FUNCTION_FAILED;
3816 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3817 if (rc != ERROR_SUCCESS)
3823 rc = MSI_ViewExecute(view, 0);
3824 if (rc != ERROR_SUCCESS)
3826 MSI_ViewClose(view);
3827 msiobj_release(&view->hdr);
3834 WCHAR buffer[0x100];
3839 rc = MSI_ViewFetch(view,&row);
3840 if (rc != ERROR_SUCCESS)
3847 MSI_RecordGetStringW(row,3,buffer,&sz);
3849 index = get_loaded_component(package,buffer);
3853 msiobj_release(&row->hdr);
3857 if (!package->components[index].Enabled ||
3858 !package->components[index].FeatureState)
3860 TRACE("Skipping class reg due to disabled component\n");
3861 msiobj_release(&row->hdr);
3866 MSI_RecordGetStringW(row,1,clsid,&sz);
3867 RegCreateKeyW(hkey,clsid,&hkey2);
3869 if (!MSI_RecordIsNull(row,5))
3872 MSI_RecordGetStringW(row,5,desc,&sz);
3874 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
3875 (strlenW(desc)+1)*sizeof(WCHAR));
3881 MSI_RecordGetStringW(row,2,buffer,&sz);
3883 RegCreateKeyW(hkey2,buffer,&hkey3);
3885 index = get_loaded_file(package,package->components[index].KeyPath);
3886 RegSetValueExW(hkey3,NULL,0,REG_SZ,
3887 (LPVOID)package->files[index].TargetPath,
3888 (strlenW(package->files[index].TargetPath)+1)
3893 if (!MSI_RecordIsNull(row,4))
3896 MSI_RecordGetStringW(row,4,buffer,&sz);
3898 RegCreateKeyW(hkey2,szProgID,&hkey3);
3900 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
3901 (strlenW(buffer)+1)*sizeof(WCHAR));
3906 if (!MSI_RecordIsNull(row,6))
3909 MSI_RecordGetStringW(row,6,buffer,&sz);
3911 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
3912 (strlenW(buffer)+1)*sizeof(WCHAR));
3914 register_appid(package,buffer,desc);
3919 FIXME("Process the rest of the fields >7\n");
3921 ui_actiondata(package,szRegisterClassInfo,row);
3923 msiobj_release(&row->hdr);
3925 MSI_ViewClose(view);
3926 msiobj_release(&view->hdr);
3933 static UINT register_progid_base(MSIRECORD * row, LPWSTR clsid)
3935 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3937 WCHAR buffer[0x100];
3942 MSI_RecordGetStringW(row,1,buffer,&sz);
3943 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
3945 if (!MSI_RecordIsNull(row,4))
3948 MSI_RecordGetStringW(row,4,buffer,&sz);
3949 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
3953 if (!MSI_RecordIsNull(row,3))
3957 MSI_RecordGetStringW(row,3,buffer,&sz);
3958 RegCreateKeyW(hkey,szCLSID,&hkey2);
3959 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
3963 strcpyW(clsid,buffer);
3969 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
3970 return ERROR_FUNCTION_FAILED;
3972 if (!MSI_RecordIsNull(row,5))
3973 FIXME ("UNHANDLED icon in Progid\n");
3974 return ERROR_SUCCESS;
3977 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid);
3979 static UINT register_parent_progid(MSIPACKAGE *package, LPCWSTR parent,
3984 MSIRECORD * row = 0;
3985 static const WCHAR Query_t[] =
3986 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','P','r','o','g'
3987 ,'I','d',' ','w','h','e','r','e',' ','P','r','o','g','I','d',' ','=',' ','`'
3989 WCHAR Query[0x1000];
3992 return ERROR_INVALID_HANDLE;
3994 sprintfW(Query,Query_t,parent);
3996 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3997 if (rc != ERROR_SUCCESS)
4000 rc = MSI_ViewExecute(view, 0);
4001 if (rc != ERROR_SUCCESS)
4003 MSI_ViewClose(view);
4004 msiobj_release(&view->hdr);
4008 rc = MSI_ViewFetch(view,&row);
4009 if (rc != ERROR_SUCCESS)
4011 MSI_ViewClose(view);
4012 msiobj_release(&view->hdr);
4016 register_progid(package,row,clsid);
4018 msiobj_release(&row->hdr);
4019 MSI_ViewClose(view);
4020 msiobj_release(&view->hdr);
4024 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid)
4026 UINT rc = ERROR_SUCCESS;
4028 if (MSI_RecordIsNull(row,2))
4029 rc = register_progid_base(row,clsid);
4032 WCHAR buffer[0x1000];
4035 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4037 /* check if already registered */
4039 MSI_RecordGetStringW(row,1,buffer,&sz);
4040 RegCreateKeyExW(HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4041 KEY_ALL_ACCESS, NULL, &hkey, &disp );
4042 if (disp == REG_OPENED_EXISTING_KEY)
4044 TRACE("Key already registered\n");
4048 /* clsid is same as parent */
4049 RegCreateKeyW(hkey,szCLSID,&hkey2);
4050 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
4056 MSI_RecordGetStringW(row,2,buffer,&sz);
4057 rc = register_parent_progid(package,buffer,clsid);
4059 if (!MSI_RecordIsNull(row,4))
4062 MSI_RecordGetStringW(row,4,buffer,&sz);
4063 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
4064 (strlenW(buffer)+1) * sizeof(WCHAR));
4067 if (!MSI_RecordIsNull(row,5))
4068 FIXME ("UNHANDLED icon in Progid\n");
4075 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
4078 * Sigh, here I am just brute force registering all progids
4079 * this needs to be linked to the Classes that have been registered
4080 * but the easiest way to do that is to load all these stuff into
4081 * memory for easy checking.
4083 * Gives me something to continue to work toward.
4087 MSIRECORD * row = 0;
4088 static const WCHAR Query[] = {
4089 'S','E','L','E','C','T',' ','*',' ',
4090 'F','R','O','M',' ','P','r','o','g','I','d',0};
4093 return ERROR_INVALID_HANDLE;
4095 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4096 if (rc != ERROR_SUCCESS)
4097 return ERROR_SUCCESS;
4099 rc = MSI_ViewExecute(view, 0);
4100 if (rc != ERROR_SUCCESS)
4102 MSI_ViewClose(view);
4103 msiobj_release(&view->hdr);
4109 WCHAR clsid[0x1000];
4111 rc = MSI_ViewFetch(view,&row);
4112 if (rc != ERROR_SUCCESS)
4118 register_progid(package,row,clsid);
4119 ui_actiondata(package,szRegisterProgIdInfo,row);
4121 msiobj_release(&row->hdr);
4123 MSI_ViewClose(view);
4124 msiobj_release(&view->hdr);
4128 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
4131 WCHAR ProductCode[0x100];
4132 WCHAR SystemFolder[MAX_PATH];
4135 static const WCHAR szInstaller[] =
4136 {'I','n','s','t','a','l','l','e','r','\\',0};
4137 static const WCHAR szProductCode[] =
4138 {'P','r','o','d','u','c','t','C','o','d','e',0};
4139 static const WCHAR szFolder[] =
4140 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4143 MSI_GetPropertyW(package,szProductCode,ProductCode,&sz);
4144 if (strlenW(ProductCode)==0)
4145 return ERROR_FUNCTION_FAILED;
4148 MSI_GetPropertyW(package,szFolder,SystemFolder,&sz);
4149 strcatW(SystemFolder,szInstaller);
4150 strcatW(SystemFolder,ProductCode);
4151 create_full_pathW(SystemFolder);
4153 strcpyW(FilePath,SystemFolder);
4154 strcatW(FilePath,cszbs);
4155 strcatW(FilePath,icon_name);
4156 return ERROR_SUCCESS;
4159 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
4163 MSIRECORD * row = 0;
4164 static const WCHAR Query[] = {
4165 'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
4166 'S','h','o','r','t','c','u','t',0};
4172 return ERROR_INVALID_HANDLE;
4174 res = CoInitialize( NULL );
4177 ERR("CoInitialize failed\n");
4178 return ERROR_FUNCTION_FAILED;
4181 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4182 if (rc != ERROR_SUCCESS)
4183 return ERROR_SUCCESS;
4185 rc = MSI_ViewExecute(view, 0);
4186 if (rc != ERROR_SUCCESS)
4188 MSI_ViewClose(view);
4189 msiobj_release(&view->hdr);
4195 WCHAR target_file[MAX_PATH];
4196 WCHAR buffer[0x100];
4199 static const WCHAR szlnk[]={'.','l','n','k',0};
4201 rc = MSI_ViewFetch(view,&row);
4202 if (rc != ERROR_SUCCESS)
4209 MSI_RecordGetStringW(row,4,buffer,&sz);
4211 index = get_loaded_component(package,buffer);
4215 msiobj_release(&row->hdr);
4219 if (!package->components[index].Enabled ||
4220 !package->components[index].FeatureState)
4222 TRACE("Skipping shortcut creation due to disabled component\n");
4223 msiobj_release(&row->hdr);
4227 ui_actiondata(package,szCreateShortcuts,row);
4229 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
4230 &IID_IShellLinkW, (LPVOID *) &sl );
4234 ERR("Is IID_IShellLink\n");
4235 msiobj_release(&row->hdr);
4239 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
4242 ERR("Is IID_IPersistFile\n");
4243 msiobj_release(&row->hdr);
4248 MSI_RecordGetStringW(row,2,buffer,&sz);
4249 resolve_folder(package, buffer,target_file,FALSE,FALSE,NULL);
4252 MSI_RecordGetStringW(row,3,buffer,&sz);
4253 reduce_to_longfilename(buffer);
4254 strcatW(target_file,buffer);
4255 if (!strchrW(target_file,'.'))
4256 strcatW(target_file,szlnk);
4259 MSI_RecordGetStringW(row,5,buffer,&sz);
4260 if (strchrW(buffer,'['))
4263 deformat_string(package,buffer,&deformated);
4264 IShellLinkW_SetPath(sl,deformated);
4265 HeapFree(GetProcessHeap(),0,deformated);
4269 FIXME("UNHANDLED shortcut format, advertised shortcut\n");
4270 IPersistFile_Release( pf );
4271 IShellLinkW_Release( sl );
4272 msiobj_release(&row->hdr);
4276 if (!MSI_RecordIsNull(row,6))
4280 MSI_RecordGetStringW(row,6,buffer,&sz);
4281 deformat_string(package,buffer,&deformated);
4282 IShellLinkW_SetArguments(sl,deformated);
4283 HeapFree(GetProcessHeap(),0,deformated);
4286 if (!MSI_RecordIsNull(row,7))
4289 deformated = load_dynamic_stringW(row,7);
4290 IShellLinkW_SetDescription(sl,deformated);
4291 HeapFree(GetProcessHeap(),0,deformated);
4294 if (!MSI_RecordIsNull(row,8))
4295 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
4297 if (!MSI_RecordIsNull(row,9))
4299 WCHAR Path[MAX_PATH];
4303 MSI_RecordGetStringW(row,9,buffer,&sz);
4305 build_icon_path(package,buffer,Path);
4306 index = MSI_RecordGetInteger(row,10);
4308 IShellLinkW_SetIconLocation(sl,Path,index);
4311 if (!MSI_RecordIsNull(row,11))
4312 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
4314 if (!MSI_RecordIsNull(row,12))
4316 WCHAR Path[MAX_PATH];
4319 MSI_RecordGetStringW(row,12,buffer,&sz);
4320 resolve_folder(package, buffer, Path, FALSE, FALSE, NULL);
4321 IShellLinkW_SetWorkingDirectory(sl,Path);
4324 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
4325 IPersistFile_Save(pf,target_file,FALSE);
4327 IPersistFile_Release( pf );
4328 IShellLinkW_Release( sl );
4330 msiobj_release(&row->hdr);
4332 MSI_ViewClose(view);
4333 msiobj_release(&view->hdr);
4343 * 99% of the work done here is only done for
4344 * advertised installs. However this is where the
4345 * Icon table is processed and written out
4346 * so that is what I am going to do here.
4348 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
4352 MSIRECORD * row = 0;
4353 static const WCHAR Query[]={
4354 'S','E','L','E','C','T',' ','*',' ',
4355 'f','r','o','m',' ','I','c','o','n',0};
4359 return ERROR_INVALID_HANDLE;
4361 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4362 if (rc != ERROR_SUCCESS)
4363 return ERROR_SUCCESS;
4365 rc = MSI_ViewExecute(view, 0);
4366 if (rc != ERROR_SUCCESS)
4368 MSI_ViewClose(view);
4369 msiobj_release(&view->hdr);
4376 WCHAR FilePath[MAX_PATH];
4377 WCHAR FileName[MAX_PATH];
4380 rc = MSI_ViewFetch(view,&row);
4381 if (rc != ERROR_SUCCESS)
4388 MSI_RecordGetStringW(row,1,FileName,&sz);
4391 ERR("Unable to get FileName\n");
4392 msiobj_release(&row->hdr);
4396 build_icon_path(package,FileName,FilePath);
4398 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
4400 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
4401 FILE_ATTRIBUTE_NORMAL, NULL);
4403 if (the_file == INVALID_HANDLE_VALUE)
4405 ERR("Unable to create file %s\n",debugstr_w(FilePath));
4406 msiobj_release(&row->hdr);
4414 rc = MSI_RecordReadStream(row,2,buffer,&sz);
4415 if (rc != ERROR_SUCCESS)
4417 ERR("Failed to get stream\n");
4418 CloseHandle(the_file);
4419 DeleteFileW(FilePath);
4422 WriteFile(the_file,buffer,sz,&write,NULL);
4423 } while (sz == 1024);
4425 CloseHandle(the_file);
4426 msiobj_release(&row->hdr);
4428 MSI_ViewClose(view);
4429 msiobj_release(&view->hdr);
4434 /* Msi functions that seem appropriate here */
4435 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
4440 TRACE(" exteral attempt at action %s\n",szAction);
4443 return ERROR_FUNCTION_FAILED;
4445 return ERROR_FUNCTION_FAILED;
4447 szwAction = strdupAtoW(szAction);
4450 return ERROR_FUNCTION_FAILED;
4453 rc = MsiDoActionW(hInstall, szwAction);
4454 HeapFree(GetProcessHeap(),0,szwAction);
4458 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
4460 MSIPACKAGE *package;
4461 UINT ret = ERROR_INVALID_HANDLE;
4463 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
4465 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4468 ret = ACTION_PerformAction(package,szAction);
4469 msiobj_release( &package->hdr );
4474 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
4475 LPSTR szPathBuf, DWORD* pcchPathBuf)
4481 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
4484 return ERROR_FUNCTION_FAILED;
4486 return ERROR_FUNCTION_FAILED;
4488 szwFolder = strdupAtoW(szFolder);
4491 return ERROR_FUNCTION_FAILED;
4493 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
4495 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
4497 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
4498 *pcchPathBuf, NULL, NULL );
4500 HeapFree(GetProcessHeap(),0,szwFolder);
4501 HeapFree(GetProcessHeap(),0,szwPathBuf);
4506 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
4507 szPathBuf, DWORD* pcchPathBuf)
4509 WCHAR path[MAX_PATH];
4511 MSIPACKAGE *package;
4513 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
4515 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4517 return ERROR_INVALID_HANDLE;
4518 rc = resolve_folder(package, szFolder, path, FALSE, FALSE, NULL);
4519 msiobj_release( &package->hdr );
4521 if (rc == ERROR_SUCCESS && strlenW(path) > *pcchPathBuf)
4523 *pcchPathBuf = strlenW(path)+1;
4524 return ERROR_MORE_DATA;
4526 else if (rc == ERROR_SUCCESS)
4528 *pcchPathBuf = strlenW(path)+1;
4529 strcpyW(szPathBuf,path);
4530 TRACE("Returning Path %s\n",debugstr_w(path));
4537 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
4538 LPSTR szPathBuf, DWORD* pcchPathBuf)
4544 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
4547 return ERROR_FUNCTION_FAILED;
4549 return ERROR_FUNCTION_FAILED;
4551 szwFolder = strdupAtoW(szFolder);
4553 return ERROR_FUNCTION_FAILED;
4555 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
4557 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
4559 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
4560 *pcchPathBuf, NULL, NULL );
4562 HeapFree(GetProcessHeap(),0,szwFolder);
4563 HeapFree(GetProcessHeap(),0,szwPathBuf);
4568 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
4569 szPathBuf, DWORD* pcchPathBuf)
4571 WCHAR path[MAX_PATH];
4573 MSIPACKAGE *package;
4575 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
4577 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4579 return ERROR_INVALID_HANDLE;
4580 rc = resolve_folder(package, szFolder, path, TRUE, FALSE, NULL);
4581 msiobj_release( &package->hdr );
4583 if (rc == ERROR_SUCCESS && strlenW(path) > *pcchPathBuf)
4585 *pcchPathBuf = strlenW(path)+1;
4586 return ERROR_MORE_DATA;
4588 else if (rc == ERROR_SUCCESS)
4590 *pcchPathBuf = strlenW(path)+1;
4591 strcpyW(szPathBuf,path);
4592 TRACE("Returning Path %s\n",debugstr_w(path));
4599 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
4600 LPCSTR szFolderPath)
4603 LPWSTR szwFolderPath;
4607 return ERROR_FUNCTION_FAILED;
4609 return ERROR_FUNCTION_FAILED;
4611 szwFolder = strdupAtoW(szFolder);
4613 return ERROR_FUNCTION_FAILED;
4615 szwFolderPath = strdupAtoW(szFolderPath);
4618 HeapFree(GetProcessHeap(),0,szwFolder);
4619 return ERROR_FUNCTION_FAILED;
4622 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
4624 HeapFree(GetProcessHeap(),0,szwFolder);
4625 HeapFree(GetProcessHeap(),0,szwFolderPath);
4630 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
4631 LPCWSTR szFolderPath)
4634 WCHAR path[MAX_PATH];
4637 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
4640 return ERROR_INVALID_HANDLE;
4642 if (szFolderPath[0]==0)
4643 return ERROR_FUNCTION_FAILED;
4645 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
4646 return ERROR_FUNCTION_FAILED;
4648 resolve_folder(package,szFolder,path,FALSE,FALSE,&folder);
4651 return ERROR_INVALID_PARAMETER;
4653 strcpyW(folder->Property,szFolderPath);
4655 for (i = 0; i < package->loaded_folders; i++)
4656 package->folders[i].ResolvedTarget[0]=0;
4658 for (i = 0; i < package->loaded_folders; i++)
4659 resolve_folder(package, package->folders[i].Directory, path, FALSE,
4662 return ERROR_SUCCESS;
4665 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
4666 LPCWSTR szFolderPath)
4668 MSIPACKAGE *package;
4671 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
4673 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4674 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
4675 msiobj_release( &package->hdr );
4679 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, DWORD iRunMode)
4681 FIXME("STUB (%li)\n",iRunMode);
4686 * According to the docs, when this is called it immediately recalculates
4687 * all the component states as well
4689 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
4690 INSTALLSTATE iState)
4692 LPWSTR szwFeature = NULL;
4695 szwFeature = strdupAtoW(szFeature);
4698 return ERROR_FUNCTION_FAILED;
4700 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
4702 HeapFree(GetProcessHeap(),0,szwFeature);
4707 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
4708 INSTALLSTATE iState)
4710 MSIPACKAGE* package;
4713 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
4715 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4717 return ERROR_INVALID_HANDLE;
4719 index = get_loaded_feature(package,szFeature);
4721 return ERROR_UNKNOWN_FEATURE;
4723 package->features[index].State = iState;
4725 return ERROR_SUCCESS;
4728 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
4729 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4731 LPWSTR szwFeature = NULL;
4734 szwFeature = strdupAtoW(szFeature);
4736 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
4738 HeapFree( GetProcessHeap(), 0 , szwFeature);
4743 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
4744 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4748 index = get_loaded_feature(package,szFeature);
4750 return ERROR_UNKNOWN_FEATURE;
4753 *piInstalled = package->features[index].State;
4757 if (package->features[index].Enabled)
4758 *piAction = INSTALLSTATE_LOCAL;
4760 *piAction = INSTALLSTATE_UNKNOWN;
4763 return ERROR_SUCCESS;
4766 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
4767 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4769 MSIPACKAGE* package;
4772 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
4775 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4777 return ERROR_INVALID_HANDLE;
4778 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
4779 msiobj_release( &package->hdr );
4783 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
4784 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4786 LPWSTR szwComponent= NULL;
4789 szwComponent= strdupAtoW(szComponent);
4791 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
4793 HeapFree( GetProcessHeap(), 0 , szwComponent);
4798 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
4799 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4803 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
4806 index = get_loaded_component(package,szComponent);
4808 return ERROR_UNKNOWN_COMPONENT;
4811 *piInstalled = package->components[index].State;
4815 if (package->components[index].Enabled &&
4816 package->components[index].FeatureState)
4817 *piAction = INSTALLSTATE_LOCAL;
4819 *piAction = INSTALLSTATE_UNKNOWN;
4822 return ERROR_SUCCESS;
4825 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
4826 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4828 MSIPACKAGE* package;
4831 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
4832 piInstalled, piAction);
4834 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4836 return ERROR_INVALID_HANDLE;
4837 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
4838 msiobj_release( &package->hdr );
4843 static UINT ACTION_Template(MSIPACKAGE *package)
4847 MSIRECORD * row = 0;
4848 static const WCHAR ExecSeqQuery[] = {0};
4850 rc = MsiDatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4851 if (rc != ERROR_SUCCESS)
4854 rc = MsiViewExecute(view, 0);
4855 if (rc != ERROR_SUCCESS)
4858 msiobj_release(&view->hdr);
4864 rc = MsiViewFetch(view,&row);
4865 if (rc != ERROR_SUCCESS)
4871 msiobj_release(&row->hdr);
4874 msiobj_release(&view->hdr);