2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installexecutesequence_table.asp
26 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/standard_actions_reference.asp
36 #include "wine/debug.h"
45 #include "wine/unicode.h"
48 #define CUSTOM_ACTION_TYPE_MASK 0x3F
50 WINE_DEFAULT_DEBUG_CHANNEL(msi);
52 typedef struct tagMSIFEATURE
55 WCHAR Feature_Parent[96];
57 WCHAR Description[0x100];
66 INT Components[1024]; /* yes hardcoded limit.... I am bad */
70 typedef struct tagMSICOMPONENT
73 WCHAR ComponentId[96];
76 WCHAR Condition[0x100];
85 typedef struct tagMSIFOLDER
88 WCHAR TargetDefault[96];
89 WCHAR SourceDefault[96];
91 WCHAR ResolvedTarget[MAX_PATH];
92 WCHAR ResolvedSource[MAX_PATH];
93 WCHAR Property[MAX_PATH]; /* initially set property */
96 /* 0 = uninitialized */
98 /* 2 = created remove if empty */
99 /* 3 = created persist if empty */
104 typedef struct tagMSIFILE
108 WCHAR FileName[MAX_PATH];
116 /* 0 = uninitialize */
117 /* 1 = not present */
118 /* 2 = present but replace */
119 /* 3 = present do not replace */
121 WCHAR SourcePath[MAX_PATH];
122 WCHAR TargetPath[MAX_PATH];
129 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran);
130 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package);
132 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action);
134 static UINT ACTION_LaunchConditions(MSIPACKAGE *package);
135 static UINT ACTION_CostInitialize(MSIPACKAGE *package);
136 static UINT ACTION_CreateFolders(MSIPACKAGE *package);
137 static UINT ACTION_CostFinalize(MSIPACKAGE *package);
138 static UINT ACTION_FileCost(MSIPACKAGE *package);
139 static UINT ACTION_InstallFiles(MSIPACKAGE *package);
140 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package);
141 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package);
142 static UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action);
143 static UINT ACTION_InstallInitialize(MSIPACKAGE *package);
144 static UINT ACTION_InstallValidate(MSIPACKAGE *package);
145 static UINT ACTION_ProcessComponents(MSIPACKAGE *package);
146 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package);
147 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package);
148 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package);
149 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package);
150 static UINT ACTION_PublishProduct(MSIPACKAGE *package);
152 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
153 const LPWSTR target, const INT type);
154 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
155 const LPWSTR target, const INT type);
157 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data);
158 static UINT resolve_folder(MSIPACKAGE *package, LPCWSTR name, LPWSTR path,
159 BOOL source, BOOL set_prop, MSIFOLDER **folder);
161 static UINT track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path);
164 * consts and values used
166 static const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
167 static const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
168 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
169 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
170 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
171 static const WCHAR c_collen[] = {'C',':','\\',0};
173 static const WCHAR cszlsb[]={'[',0};
174 static const WCHAR cszrsb[]={']',0};
175 static const WCHAR cszbs[]={'\\',0};
177 const static WCHAR szCreateFolders[] =
178 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
179 const static WCHAR szCostFinalize[] =
180 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
181 const static WCHAR szInstallFiles[] =
182 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
183 const static WCHAR szDuplicateFiles[] =
184 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
185 const static WCHAR szWriteRegistryValues[] =
186 {'W','r','i','t','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
187 const static WCHAR szCostInitialize[] =
188 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
189 const static WCHAR szFileCost[] = {'F','i','l','e','C','o','s','t',0};
190 const static WCHAR szInstallInitialize[] =
191 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
192 const static WCHAR szInstallValidate[] =
193 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
194 const static WCHAR szLaunchConditions[] =
195 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
196 const static WCHAR szProcessComponents[] =
197 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
198 const static WCHAR szRegisterTypeLibraries[] =
199 {'R','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r',
201 const static WCHAR szRegisterClassInfo[] =
202 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
203 const static WCHAR szRegisterProgIdInfo[] =
204 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
205 const static WCHAR szCreateShortcuts[] =
206 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
207 const static WCHAR szPublishProduct[] =
208 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
210 /********************************************************
211 * helper functions to get around current HACKS and such
212 ********************************************************/
213 inline static void reduce_to_longfilename(WCHAR* filename)
215 if (strchrW(filename,'|'))
217 WCHAR newname[MAX_PATH];
218 strcpyW(newname,strchrW(filename,'|')+1);
219 strcpyW(filename,newname);
223 inline static char *strdupWtoA( const WCHAR *str )
228 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL
230 if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
231 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
236 inline static WCHAR *strdupAtoW( const char *str )
241 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
242 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
243 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
248 inline static WCHAR *load_dynamic_stringW(MSIRECORD *row, INT index)
255 rc = MSI_RecordGetStringW(row,index,NULL,&sz);
260 ret = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
261 rc = MSI_RecordGetStringW(row,index,ret,&sz);
265 inline static int get_loaded_component(MSIPACKAGE* package, LPCWSTR Component )
270 for (i = 0; i < package->loaded_components; i++)
272 if (strcmpW(Component,package->components[i].Component)==0)
281 inline static int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
286 for (i = 0; i < package->loaded_features; i++)
288 if (strcmpW(Feature,package->features[i].Feature)==0)
297 inline static int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
302 for (i = 0; i < package->loaded_files; i++)
304 if (strcmpW(file,package->files[i].File)==0)
313 static UINT track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
321 for (i=0; i < package->loaded_files; i++)
322 if (strcmpW(package->files[i].File,name)==0)
325 index = package->loaded_files;
326 package->loaded_files++;
327 if (package->loaded_files== 1)
328 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
330 package->files = HeapReAlloc(GetProcessHeap(),0,
331 package->files , package->loaded_files * sizeof(MSIFILE));
333 memset(&package->files[index],0,sizeof(MSIFILE));
335 strcpyW(package->files[index].File,name);
336 strcpyW(package->files[index].TargetPath,path);
337 package->files[index].Temporary = TRUE;
339 TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
344 void ACTION_remove_tracked_tempfiles(MSIPACKAGE* package)
351 for (i = 0; i < package->loaded_files; i++)
353 if (package->files[i].Temporary)
354 DeleteFileW(package->files[i].TargetPath);
359 static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
363 row = MSI_CreateRecord(4);
364 MSI_RecordSetInteger(row,1,a);
365 MSI_RecordSetInteger(row,2,b);
366 MSI_RecordSetInteger(row,3,c);
367 MSI_RecordSetInteger(row,4,d);
368 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
369 msiobj_release(&row->hdr);
372 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
374 static const WCHAR Query_t[] =
375 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
376 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
377 ' ','\'','%','s','\'',0};
382 static WCHAR *ActionFormat=NULL;
383 static WCHAR LastAction[0x100] = {0};
387 if (strcmpW(LastAction,action)!=0)
389 sprintfW(Query,Query_t,action);
390 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
391 if (rc != ERROR_SUCCESS)
393 rc = MSI_ViewExecute(view, 0);
394 if (rc != ERROR_SUCCESS)
399 rc = MSI_ViewFetch(view,&row);
400 if (rc != ERROR_SUCCESS)
406 if (MSI_RecordIsNull(row,3))
408 msiobj_release(&row->hdr);
410 msiobj_release(&view->hdr);
415 HeapFree(GetProcessHeap(),0,ActionFormat);
417 ActionFormat = load_dynamic_stringW(row,3);
418 strcpyW(LastAction,action);
419 msiobj_release(&row->hdr);
421 msiobj_release(&view->hdr);
433 ptr2 = strchrW(ptr,'[');
436 strncpyW(tmp,ptr,ptr2-ptr);
438 strcatW(message,tmp);
441 data = load_dynamic_stringW(record,field);
444 strcatW(message,data);
445 HeapFree(GetProcessHeap(),0,data);
447 ptr=strchrW(ptr2,']');
452 strcatW(message,ptr);
457 row = MSI_CreateRecord(1);
458 MSI_RecordSetStringW(row,1,message);
460 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
461 msiobj_release(&row->hdr);
465 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
467 static const WCHAR template_s[]=
468 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ','%','s','.',0};
469 static const WCHAR format[] =
470 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
471 static const WCHAR Query_t[] =
472 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
473 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
474 ' ','\'','%','s','\'',0};
480 WCHAR *ActionText=NULL;
483 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
485 sprintfW(Query,Query_t,action);
486 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
487 if (rc != ERROR_SUCCESS)
489 rc = MSI_ViewExecute(view, 0);
490 if (rc != ERROR_SUCCESS)
493 msiobj_release(&view->hdr);
496 rc = MSI_ViewFetch(view,&row);
497 if (rc != ERROR_SUCCESS)
500 msiobj_release(&view->hdr);
504 ActionText = load_dynamic_stringW(row,2);
505 msiobj_release(&row->hdr);
507 msiobj_release(&view->hdr);
509 sprintfW(message,template_s,timet,action,ActionText);
511 row = MSI_CreateRecord(1);
512 MSI_RecordSetStringW(row,1,message);
514 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
515 msiobj_release(&row->hdr);
516 HeapFree(GetProcessHeap(),0,ActionText);
519 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
523 static const WCHAR template_s[]=
524 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ','%','s',
526 static const WCHAR template_e[]=
527 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ','%','s',
528 '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ','%','i','.',0};
529 static const WCHAR format[] =
530 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
534 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
536 sprintfW(message,template_s,timet,action);
538 sprintfW(message,template_e,timet,action,rc);
540 row = MSI_CreateRecord(1);
541 MSI_RecordSetStringW(row,1,message);
543 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
544 msiobj_release(&row->hdr);
547 /****************************************************
548 * TOP level entry points
549 *****************************************************/
551 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
552 LPCWSTR szCommandLine)
557 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
562 WCHAR check[MAX_PATH];
566 strcpyW(pth,szPackagePath);
567 p = strrchrW(pth,'\\');
575 if (MSI_GetPropertyW(package,cszSourceDir,check,&size)
577 MSI_SetPropertyW(package, cszSourceDir, pth);
583 ptr = (LPWSTR)szCommandLine;
590 TRACE("Looking at %s\n",debugstr_w(ptr));
592 ptr2 = strchrW(ptr,'=');
598 while (*ptr == ' ') ptr++;
599 strncpyW(prop,ptr,ptr2-ptr);
604 while (*ptr && (quote || (!quote && *ptr!=' ')))
617 strncpyW(val,ptr2,len);
620 if (strlenW(prop) > 0)
622 TRACE("Found commandline property (%s) = (%s)\n", debugstr_w(prop), debugstr_w(val));
623 MSI_SetPropertyW(package,prop,val);
631 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
633 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
635 rc = ACTION_ProcessUISequence(package);
636 if (rc == ERROR_SUCCESS)
637 rc = ACTION_ProcessExecSequence(package,TRUE);
640 rc = ACTION_ProcessExecSequence(package,FALSE);
643 rc = ACTION_ProcessExecSequence(package,FALSE);
649 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
653 static const WCHAR ExecSeqQuery[] = {
654 's','e','l','e','c','t',' ','*',' ',
656 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
657 'S','e','q','u','e','n','c','e',' ',
658 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
659 '>',' ','%','i',' ','o','r','d','e','r',' ',
660 'b','y',' ','S','e','q','u','e','n','c','e',0 };
663 static const WCHAR IVQuery[] = {
664 's','e','l','e','c','t',' ','S','e','q','u','e','n','c','e',' ',
665 'f','r','o','m',' ','I','n','s','t','a','l','l',
666 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
667 'w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',' ',
668 '`','I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`',
675 rc = MSI_DatabaseOpenViewW(package->db, IVQuery, &view);
676 if (rc != ERROR_SUCCESS)
678 rc = MSI_ViewExecute(view, 0);
679 if (rc != ERROR_SUCCESS)
682 msiobj_release(&view->hdr);
685 rc = MSI_ViewFetch(view,&row);
686 if (rc != ERROR_SUCCESS)
689 msiobj_release(&view->hdr);
692 seq = MSI_RecordGetInteger(row,1);
693 msiobj_release(&row->hdr);
695 msiobj_release(&view->hdr);
696 sprintfW(Query,ExecSeqQuery,seq);
699 sprintfW(Query,ExecSeqQuery,0);
701 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
702 if (rc == ERROR_SUCCESS)
704 rc = MSI_ViewExecute(view, 0);
706 if (rc != ERROR_SUCCESS)
709 msiobj_release(&view->hdr);
713 TRACE("Running the actions \n");
720 rc = MSI_ViewFetch(view,&row);
721 if (rc != ERROR_SUCCESS)
727 /* check conditions */
728 if (!MSI_RecordIsNull(row,2))
731 cond = load_dynamic_stringW(row,2);
735 /* this is a hack to skip errors in the condition code */
736 if (MSI_EvaluateConditionW(package, cond) ==
739 HeapFree(GetProcessHeap(),0,cond);
740 msiobj_release(&row->hdr);
744 HeapFree(GetProcessHeap(),0,cond);
749 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
750 if (rc != ERROR_SUCCESS)
752 ERR("Error is %x\n",rc);
753 msiobj_release(&row->hdr);
757 rc = ACTION_PerformAction(package,buffer);
759 if (rc != ERROR_SUCCESS)
761 ERR("Execution halted due to error (%i)\n",rc);
762 msiobj_release(&row->hdr);
766 msiobj_release(&row->hdr);
770 msiobj_release(&view->hdr);
778 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
782 static const WCHAR ExecSeqQuery [] = {
783 's','e','l','e','c','t',' ','*',' ',
784 'f','r','o','m',' ','I','n','s','t','a','l','l',
785 'U','I','S','e','q','u','e','n','c','e',' ',
786 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ', '>',' ','0',' ',
787 'o','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e',0};
789 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
791 if (rc == ERROR_SUCCESS)
793 rc = MSI_ViewExecute(view, 0);
795 if (rc != ERROR_SUCCESS)
798 msiobj_release(&view->hdr);
802 TRACE("Running the actions \n");
810 rc = MSI_ViewFetch(view,&row);
811 if (rc != ERROR_SUCCESS)
817 /* check conditions */
818 if (!MSI_RecordIsNull(row,2))
821 cond = load_dynamic_stringW(row,2);
825 /* this is a hack to skip errors in the condition code */
826 if (MSI_EvaluateConditionW(package, cond) ==
829 HeapFree(GetProcessHeap(),0,cond);
830 msiobj_release(&row->hdr);
834 HeapFree(GetProcessHeap(),0,cond);
839 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
840 if (rc != ERROR_SUCCESS)
842 ERR("Error is %x\n",rc);
843 msiobj_release(&row->hdr);
847 rc = ACTION_PerformAction(package,buffer);
849 if (rc != ERROR_SUCCESS)
851 ERR("Execution halted due to error (%i)\n",rc);
852 msiobj_release(&row->hdr);
856 msiobj_release(&row->hdr);
860 msiobj_release(&view->hdr);
867 /********************************************************
868 * ACTION helper functions and functions that perform the actions
869 *******************************************************/
872 * Alot of actions are really important even if they don't do anything
873 * explicit.. Lots of properties are set at the beginning of the installation
874 * CostFinalize does a bunch of work to translated the directories and such
876 * But until I get write access to the database that is hard, so I am going to
877 * hack it to see if I can get something to run.
879 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action)
881 UINT rc = ERROR_SUCCESS;
883 TRACE("Performing action (%s)\n",debugstr_w(action));
884 ui_actioninfo(package, action, TRUE, 0);
885 ui_actionstart(package, action);
886 ui_progress(package,2,1,0,0);
888 /* pre install, setup and configuration block */
889 if (strcmpW(action,szLaunchConditions)==0)
890 rc = ACTION_LaunchConditions(package);
891 else if (strcmpW(action,szCostInitialize)==0)
892 rc = ACTION_CostInitialize(package);
893 else if (strcmpW(action,szFileCost)==0)
894 rc = ACTION_FileCost(package);
895 else if (strcmpW(action,szCostFinalize)==0)
896 rc = ACTION_CostFinalize(package);
897 else if (strcmpW(action,szInstallValidate)==0)
898 rc = ACTION_InstallValidate(package);
901 else if (strcmpW(action,szProcessComponents)==0)
902 rc = ACTION_ProcessComponents(package);
903 else if (strcmpW(action,szInstallInitialize)==0)
904 rc = ACTION_InstallInitialize(package);
905 else if (strcmpW(action,szCreateFolders)==0)
906 rc = ACTION_CreateFolders(package);
907 else if (strcmpW(action,szInstallFiles)==0)
908 rc = ACTION_InstallFiles(package);
909 else if (strcmpW(action,szDuplicateFiles)==0)
910 rc = ACTION_DuplicateFiles(package);
911 else if (strcmpW(action,szWriteRegistryValues)==0)
912 rc = ACTION_WriteRegistryValues(package);
913 else if (strcmpW(action,szRegisterTypeLibraries)==0)
914 rc = ACTION_RegisterTypeLibraries(package);
915 else if (strcmpW(action,szRegisterClassInfo)==0)
916 rc = ACTION_RegisterClassInfo(package);
917 else if (strcmpW(action,szRegisterProgIdInfo)==0)
918 rc = ACTION_RegisterProgIdInfo(package);
919 else if (strcmpW(action,szCreateShortcuts)==0)
920 rc = ACTION_CreateShortcuts(package);
921 else if (strcmpW(action,szPublishProduct)==0)
922 rc = ACTION_PublishProduct(package);
925 Called during iTunes but unimplemented and seem important
927 ResolveSource (sets SourceDir)
931 else if ((rc = ACTION_CustomAction(package,action)) != ERROR_SUCCESS)
933 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
937 ui_actioninfo(package, action, FALSE, rc);
942 static UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action)
944 UINT rc = ERROR_SUCCESS;
947 WCHAR ExecSeqQuery[1024] =
948 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','C','u','s','t','o'
949 ,'m','A','c','t','i','o','n',' ','w','h','e','r','e',' ','`','A','c','t','i'
950 ,'o','n','`',' ','=',' ','`',0};
951 static const WCHAR end[]={'`',0};
955 WCHAR *deformated=NULL;
957 strcatW(ExecSeqQuery,action);
958 strcatW(ExecSeqQuery,end);
960 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
962 if (rc != ERROR_SUCCESS)
965 rc = MSI_ViewExecute(view, 0);
966 if (rc != ERROR_SUCCESS)
969 msiobj_release(&view->hdr);
973 rc = MSI_ViewFetch(view,&row);
974 if (rc != ERROR_SUCCESS)
977 msiobj_release(&view->hdr);
981 type = MSI_RecordGetInteger(row,2);
983 source = load_dynamic_stringW(row,3);
984 target = load_dynamic_stringW(row,4);
986 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
987 debugstr_w(source), debugstr_w(target));
989 /* we are ignoring ALOT of flags and important synchronization stuff */
990 switch (type & CUSTOM_ACTION_TYPE_MASK)
992 case 1: /* DLL file stored in a Binary table stream */
993 rc = HANDLE_CustomType1(package,source,target,type);
995 case 2: /* EXE file stored in a Binary table strem */
996 rc = HANDLE_CustomType2(package,source,target,type);
998 case 35: /* Directory set with formatted text. */
999 case 51: /* Property set with formatted text. */
1000 deformat_string(package,target,&deformated);
1001 rc = MSI_SetPropertyW(package,source,deformated);
1002 HeapFree(GetProcessHeap(),0,deformated);
1005 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
1006 type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
1007 debugstr_w(target));
1010 HeapFree(GetProcessHeap(),0,source);
1011 HeapFree(GetProcessHeap(),0,target);
1012 msiobj_release(&row->hdr);
1013 MSI_ViewClose(view);
1014 msiobj_release(&view->hdr);
1018 static UINT store_binary_to_temp(MSIPACKAGE *package, const LPWSTR source,
1023 if (MSI_GetPropertyW(package, cszTempFolder, tmp_file, &sz)
1025 GetTempPathW(MAX_PATH,tmp_file);
1027 strcatW(tmp_file,source);
1029 if (GetFileAttributesW(tmp_file) != INVALID_FILE_ATTRIBUTES)
1031 TRACE("File already exists\n");
1032 return ERROR_SUCCESS;
1036 /* write out the file */
1039 MSIRECORD * row = 0;
1041 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','B','i'
1042 ,'n','a','r','y',' ','w','h','e','r','e',' ','N','a','m','e','=','`',0};
1043 static const WCHAR end[]={'`',0};
1047 if (track_tempfile(package, source, tmp_file)!=0)
1048 FIXME("File Name in temp tracking collision\n");
1050 the_file = CreateFileW(tmp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1051 FILE_ATTRIBUTE_NORMAL, NULL);
1053 if (the_file == INVALID_HANDLE_VALUE)
1054 return ERROR_FUNCTION_FAILED;
1056 strcatW(Query,source);
1059 rc = MSI_DatabaseOpenViewW( package->db, Query, &view);
1060 if (rc != ERROR_SUCCESS)
1063 rc = MSI_ViewExecute(view, 0);
1064 if (rc != ERROR_SUCCESS)
1066 MSI_ViewClose(view);
1067 msiobj_release(&view->hdr);
1071 rc = MSI_ViewFetch(view,&row);
1072 if (rc != ERROR_SUCCESS)
1074 MSI_ViewClose(view);
1075 msiobj_release(&view->hdr);
1083 rc = MSI_RecordReadStream(row,2,buffer,&sz);
1084 if (rc != ERROR_SUCCESS)
1086 ERR("Failed to get stream\n");
1087 CloseHandle(the_file);
1088 DeleteFileW(tmp_file);
1091 WriteFile(the_file,buffer,sz,&write,NULL);
1092 } while (sz == 1024);
1094 CloseHandle(the_file);
1096 msiobj_release(&row->hdr);
1097 MSI_ViewClose(view);
1098 msiobj_release(&view->hdr);
1101 return ERROR_SUCCESS;
1105 typedef UINT CustomEntry(MSIHANDLE);
1108 MSIPACKAGE *package;
1109 WCHAR target[MAX_PATH];
1110 WCHAR source[MAX_PATH];
1114 static DWORD WINAPI DllThread(LPVOID info)
1118 thread_struct *stuff;
1121 stuff = (thread_struct*)info;
1123 TRACE("Asyncronous start (%s, %s) \n", debugstr_w(stuff->source),
1124 debugstr_w(stuff->target));
1126 DLL = LoadLibraryW(stuff->source);
1129 proc = strdupWtoA( stuff->target );
1130 fn = (CustomEntry*)GetProcAddress(DLL,proc);
1134 MSIPACKAGE *package = stuff->package;
1136 TRACE("Calling function\n");
1137 hPackage = msiobj_findhandle( &package->hdr );
1139 ERR("Handle for object %p not found\n", package );
1141 msiobj_release( &package->hdr );
1144 ERR("Cannot load functon\n");
1146 HeapFree(GetProcessHeap(),0,proc);
1150 ERR("Unable to load library\n");
1151 msiobj_release( &stuff->package->hdr );
1152 HeapFree( GetProcessHeap(), 0, info );
1157 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
1158 const LPWSTR target, const INT type)
1160 WCHAR tmp_file[MAX_PATH];
1165 store_binary_to_temp(package, source, tmp_file);
1167 TRACE("Calling function %s from %s\n",debugstr_w(target),
1168 debugstr_w(tmp_file));
1170 if (!strchrW(tmp_file,'.'))
1172 static const WCHAR dot[]={'.',0};
1173 strcatW(tmp_file,dot);
1178 /* DWORD ThreadId; */
1179 thread_struct *info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) );
1181 /* msiobj_addref( &package->hdr ); */
1182 info->package = package;
1183 strcpyW(info->target,target);
1184 strcpyW(info->source,tmp_file);
1185 TRACE("Start Asyncronous execution\n");
1186 FIXME("DATABASE NOT THREADSAFE... not starting\n");
1187 /* CreateThread(NULL,0,DllThread,(LPVOID)&info,0,&ThreadId); */
1188 /* FIXME: release the package if the CreateThread fails */
1189 HeapFree( GetProcessHeap(), 0, info );
1190 return ERROR_SUCCESS;
1193 DLL = LoadLibraryW(tmp_file);
1196 proc = strdupWtoA( target );
1197 fn = (CustomEntry*)GetProcAddress(DLL,proc);
1202 TRACE("Calling function\n");
1203 hPackage = msiobj_findhandle( &package->hdr );
1205 ERR("Handle for object %p not found\n", package );
1207 msiobj_release( &package->hdr );
1210 ERR("Cannot load functon\n");
1212 HeapFree(GetProcessHeap(),0,proc);
1216 ERR("Unable to load library\n");
1218 return ERROR_SUCCESS;
1221 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
1222 const LPWSTR target, const INT type)
1224 WCHAR tmp_file[MAX_PATH*2];
1226 PROCESS_INFORMATION info;
1229 static const WCHAR spc[] = {' ',0};
1231 memset(&si,0,sizeof(STARTUPINFOW));
1232 memset(&info,0,sizeof(PROCESS_INFORMATION));
1234 store_binary_to_temp(package, source, tmp_file);
1236 strcatW(tmp_file,spc);
1237 deformat_string(package,target,&deformated);
1238 strcatW(tmp_file,deformated);
1240 HeapFree(GetProcessHeap(),0,deformated);
1242 TRACE("executing exe %s \n",debugstr_w(tmp_file));
1244 rc = CreateProcessW(NULL, tmp_file, NULL, NULL, FALSE, 0, NULL,
1245 c_collen, &si, &info);
1249 ERR("Unable to execute command\n");
1250 return ERROR_SUCCESS;
1254 WaitForSingleObject(info.hProcess,INFINITE);
1256 return ERROR_SUCCESS;
1259 /***********************************************************************
1262 * Recursively create all directories in the path.
1264 * shamelessly stolen from setupapi/queue.c
1266 static BOOL create_full_pathW(const WCHAR *path)
1272 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1274 strcpyW(new_path, path);
1276 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1277 new_path[len - 1] = 0;
1279 while(!CreateDirectoryW(new_path, NULL))
1282 DWORD last_error = GetLastError();
1283 if(last_error == ERROR_ALREADY_EXISTS)
1286 if(last_error != ERROR_PATH_NOT_FOUND)
1292 if(!(slash = strrchrW(new_path, '\\')))
1298 len = slash - new_path;
1300 if(!create_full_pathW(new_path))
1305 new_path[len] = '\\';
1308 HeapFree(GetProcessHeap(), 0, new_path);
1313 * Also we cannot enable/disable components either, so for now I am just going
1314 * to do all the directories for all the components.
1316 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1318 static const WCHAR ExecSeqQuery[] = {
1319 's','e','l','e','c','t',' ','D','i','r','e','c','t','o','r','y','_',' ',
1320 'f','r','o','m',' ','C','r','e','a','t','e','F','o','l','d','e','r',0 };
1325 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1326 if (rc != ERROR_SUCCESS)
1329 rc = MSI_ViewExecute(view, 0);
1330 if (rc != ERROR_SUCCESS)
1332 MSI_ViewClose(view);
1333 msiobj_release(&view->hdr);
1340 WCHAR full_path[MAX_PATH];
1342 MSIRECORD *row = NULL, *uirow;
1344 rc = MSI_ViewFetch(view,&row);
1345 if (rc != ERROR_SUCCESS)
1352 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1354 if (rc!= ERROR_SUCCESS)
1356 ERR("Unable to get folder id \n");
1357 msiobj_release(&row->hdr);
1362 rc = resolve_folder(package,dir,full_path,FALSE,FALSE,&folder);
1364 if (rc != ERROR_SUCCESS)
1366 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1367 msiobj_release(&row->hdr);
1371 TRACE("Folder is %s\n",debugstr_w(full_path));
1374 uirow = MSI_CreateRecord(1);
1375 MSI_RecordSetStringW(uirow,1,full_path);
1376 ui_actiondata(package,szCreateFolders,uirow);
1377 msiobj_release( &uirow->hdr );
1379 if (folder->State == 0)
1380 create_full_pathW(full_path);
1384 msiobj_release(&row->hdr);
1386 MSI_ViewClose(view);
1387 msiobj_release(&view->hdr);
1392 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1394 int index = package->loaded_components;
1397 /* fill in the data */
1399 package->loaded_components++;
1400 if (package->loaded_components == 1)
1401 package->components = HeapAlloc(GetProcessHeap(),0,
1402 sizeof(MSICOMPONENT));
1404 package->components = HeapReAlloc(GetProcessHeap(),0,
1405 package->components, package->loaded_components *
1406 sizeof(MSICOMPONENT));
1408 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1411 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1413 TRACE("Loading Component %s\n",
1414 debugstr_w(package->components[index].Component));
1417 if (!MSI_RecordIsNull(row,2))
1418 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1421 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1423 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1426 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1429 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1431 package->components[index].State = INSTALLSTATE_UNKNOWN;
1432 package->components[index].Enabled = TRUE;
1433 package->components[index].FeatureState= FALSE;
1438 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1440 int index = package->loaded_features;
1442 static const WCHAR Query1[] = {'S','E','L','E','C','T',' ','C','o','m','p',
1443 'o','n','e','n','t','_',' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1444 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ','F','e',
1445 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1446 static const WCHAR Query2[] = {'S','E','L','E','C','T',' ','*',' ','F','R',
1447 'O','M',' ','C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ','C',
1448 'o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1456 /* fill in the data */
1458 package->loaded_features ++;
1459 if (package->loaded_features == 1)
1460 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1462 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1463 package->loaded_features * sizeof(MSIFEATURE));
1465 memset(&package->features[index],0,sizeof(MSIFEATURE));
1468 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1470 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1473 if (!MSI_RecordIsNull(row,2))
1474 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1477 if (!MSI_RecordIsNull(row,3))
1478 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1481 if (!MSI_RecordIsNull(row,4))
1482 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1484 if (!MSI_RecordIsNull(row,5))
1485 package->features[index].Display = MSI_RecordGetInteger(row,5);
1487 package->features[index].Level= MSI_RecordGetInteger(row,6);
1490 if (!MSI_RecordIsNull(row,7))
1491 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1493 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1494 package->features[index].State = INSTALLSTATE_UNKNOWN;
1496 /* load feature components */
1498 sprintfW(Query,Query1,package->features[index].Feature);
1499 rc = MSI_DatabaseOpenViewW(package->db,Query,&view);
1500 if (rc != ERROR_SUCCESS)
1502 rc = MSI_ViewExecute(view,0);
1503 if (rc != ERROR_SUCCESS)
1505 MSI_ViewClose(view);
1506 msiobj_release(&view->hdr);
1512 WCHAR buffer[0x100];
1515 INT cnt = package->features[index].ComponentCount;
1517 rc = MSI_ViewFetch(view,&row2);
1518 if (rc != ERROR_SUCCESS)
1522 MSI_RecordGetStringW(row2,1,buffer,&sz);
1524 /* check to see if the component is already loaded */
1525 c_indx = get_loaded_component(package,buffer);
1528 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1530 package->features[index].Components[cnt] = c_indx;
1531 package->features[index].ComponentCount ++;
1534 sprintfW(Query,Query2,buffer);
1536 rc = MSI_DatabaseOpenViewW(package->db,Query,&view2);
1537 if (rc != ERROR_SUCCESS)
1539 msiobj_release( &row2->hdr );
1542 rc = MSI_ViewExecute(view2,0);
1543 if (rc != ERROR_SUCCESS)
1545 msiobj_release( &row2->hdr );
1546 MSI_ViewClose(view2);
1547 msiobj_release( &view2->hdr );
1554 rc = MSI_ViewFetch(view2,&row3);
1555 if (rc != ERROR_SUCCESS)
1557 c_indx = load_component(package,row3);
1558 msiobj_release( &row3->hdr );
1560 package->features[index].Components[cnt] = c_indx;
1561 package->features[index].ComponentCount ++;
1563 MSI_ViewClose(view2);
1564 msiobj_release( &view2->hdr );
1565 msiobj_release( &row2->hdr );
1567 MSI_ViewClose(view);
1568 msiobj_release(&view->hdr);
1572 * I am not doing any of the costing functionality yet.
1573 * Mostly looking at doing the Component and Feature loading
1575 * The native MSI does ALOT of modification to tables here. Mostly adding alot
1576 * of temporary columns to the Feature and Component tables.
1578 * note: native msi also tracks the short filename. but I am only going to
1579 * track the long ones. Also looking at this directory table
1580 * it appears that the directory table does not get the parents
1581 * resolved base on property only based on their entrys in the
1584 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1590 static const WCHAR Query_all[] = {
1591 'S','E','L','E','C','T',' ','*',' ',
1592 'F','R','O','M',' ','F','e','a','t','u','r','e',0};
1593 static const WCHAR szCosting[] = {
1594 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1595 static const WCHAR szZero[] = { '0', 0 };
1597 MSI_SetPropertyW(package, szCosting, szZero);
1598 MSI_SetPropertyW(package, cszRootDrive , c_collen);
1601 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1602 if (rc != ERROR_SUCCESS)
1604 rc = MSI_ViewExecute(view,0);
1605 if (rc != ERROR_SUCCESS)
1607 MSI_ViewClose(view);
1608 msiobj_release(&view->hdr);
1615 rc = MSI_ViewFetch(view,&row);
1616 if (rc != ERROR_SUCCESS)
1619 load_feature(package,row);
1620 msiobj_release(&row->hdr);
1622 MSI_ViewClose(view);
1623 msiobj_release(&view->hdr);
1625 return ERROR_SUCCESS;
1628 static int load_file(MSIPACKAGE* package, MSIRECORD * row)
1630 int index = package->loaded_files;
1632 WCHAR buffer[0x100];
1635 /* fill in the data */
1637 package->loaded_files++;
1638 if (package->loaded_files== 1)
1639 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1641 package->files = HeapReAlloc(GetProcessHeap(),0,
1642 package->files , package->loaded_files * sizeof(MSIFILE));
1644 memset(&package->files[index],0,sizeof(MSIFILE));
1647 MSI_RecordGetStringW(row,1,package->files[index].File,&sz);
1650 MSI_RecordGetStringW(row,2,buffer,&sz);
1652 package->files[index].ComponentIndex = -1;
1653 for (i = 0; i < package->loaded_components; i++)
1654 if (strcmpW(package->components[i].Component,buffer)==0)
1656 package->files[index].ComponentIndex = i;
1659 if (package->files[index].ComponentIndex == -1)
1660 ERR("Unfound Component %s\n",debugstr_w(buffer));
1663 MSI_RecordGetStringW(row,3,package->files[index].FileName,&sz);
1665 reduce_to_longfilename(package->files[index].FileName);
1667 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1670 if (!MSI_RecordIsNull(row,5))
1671 MSI_RecordGetStringW(row,5,package->files[index].Version,&sz);
1674 if (!MSI_RecordIsNull(row,6))
1675 MSI_RecordGetStringW(row,6,package->files[index].Language,&sz);
1677 if (!MSI_RecordIsNull(row,7))
1678 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1680 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1682 package->files[index].Temporary = FALSE;
1683 package->files[index].State = 0;
1685 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1687 return ERROR_SUCCESS;
1690 static UINT ACTION_FileCost(MSIPACKAGE *package)
1695 static const WCHAR Query[] = {
1696 'S','E','L','E','C','T',' ','*',' ',
1697 'F','R','O','M',' ','F','i','l','e',' ',
1698 'O','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e', 0};
1701 return ERROR_INVALID_HANDLE;
1703 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1704 if (rc != ERROR_SUCCESS)
1707 rc = MSI_ViewExecute(view, 0);
1708 if (rc != ERROR_SUCCESS)
1710 MSI_ViewClose(view);
1711 msiobj_release(&view->hdr);
1717 rc = MSI_ViewFetch(view,&row);
1718 if (rc != ERROR_SUCCESS)
1723 load_file(package,row);
1724 msiobj_release(&row->hdr);
1726 MSI_ViewClose(view);
1727 msiobj_release(&view->hdr);
1729 return ERROR_SUCCESS;
1732 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1736 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','D','i','r','e','c',
1737 't','o','r','y',' ','w','h','e','r','e',' ','`','D','i','r','e','c','t',
1738 'o','r','y','`',' ','=',' ','`',0};
1739 static const WCHAR end[]={'`',0};
1742 WCHAR targetbuffer[0x100];
1743 WCHAR *srcdir = NULL;
1744 WCHAR *targetdir = NULL;
1745 WCHAR parent[0x100];
1747 MSIRECORD * row = 0;
1750 TRACE("Looking for dir %s\n",debugstr_w(dir));
1752 for (i = 0; i < package->loaded_folders; i++)
1754 if (strcmpW(package->folders[i].Directory,dir)==0)
1756 TRACE(" %s retuning on index %i\n",debugstr_w(dir),i);
1761 TRACE("Working to load %s\n",debugstr_w(dir));
1763 index = package->loaded_folders;
1765 package->loaded_folders++;
1766 if (package->loaded_folders== 1)
1767 package->folders = HeapAlloc(GetProcessHeap(),0,
1770 package->folders= HeapReAlloc(GetProcessHeap(),0,
1771 package->folders, package->loaded_folders*
1774 memset(&package->folders[index],0,sizeof(MSIFOLDER));
1776 strcpyW(package->folders[index].Directory,dir);
1781 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1783 if (rc != ERROR_SUCCESS)
1786 rc = MSI_ViewExecute(view, 0);
1787 if (rc != ERROR_SUCCESS)
1789 MSI_ViewClose(view);
1790 msiobj_release(&view->hdr);
1794 rc = MSI_ViewFetch(view,&row);
1795 if (rc != ERROR_SUCCESS)
1797 MSI_ViewClose(view);
1798 msiobj_release(&view->hdr);
1803 MSI_RecordGetStringW(row,3,targetbuffer,&sz);
1804 targetdir=targetbuffer;
1806 /* split src and target dir */
1807 if (strchrW(targetdir,':'))
1809 srcdir=strchrW(targetdir,':');
1816 /* for now only pick long filename versions */
1817 if (strchrW(targetdir,'|'))
1819 targetdir = strchrW(targetdir,'|');
1823 if (srcdir && strchrW(srcdir,'|'))
1825 srcdir= strchrW(srcdir,'|');
1830 /* now check for root dirs */
1831 if (targetdir[0] == '.' && targetdir[1] == 0)
1834 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
1838 strcpyW(package->folders[index].TargetDefault,targetdir);
1841 strcpyW(package->folders[index].SourceDefault,srcdir);
1843 strcpyW(package->folders[index].SourceDefault,targetdir);
1845 if (MSI_RecordIsNull(row,2))
1850 MSI_RecordGetStringW(row,2,parent,&sz);
1855 i = load_folder(package,parent);
1856 package->folders[index].ParentIndex = i;
1857 TRACE("Parent is index %i... %s %s\n",
1858 package->folders[index].ParentIndex,
1859 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
1860 debugstr_w(parent));
1863 package->folders[index].ParentIndex = -2;
1866 rc = MSI_GetPropertyW(package, dir, package->folders[index].Property, &sz);
1867 if (rc != ERROR_SUCCESS)
1868 package->folders[index].Property[0]=0;
1870 msiobj_release(&row->hdr);
1871 MSI_ViewClose(view);
1872 msiobj_release(&view->hdr);
1873 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
1877 static UINT resolve_folder(MSIPACKAGE *package, LPCWSTR name, LPWSTR path,
1878 BOOL source, BOOL set_prop, MSIFOLDER **folder)
1881 UINT rc = ERROR_SUCCESS;
1884 TRACE("Working to resolve %s\n",debugstr_w(name));
1889 /* special resolving for Target and Source root dir */
1890 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
1895 rc = MSI_GetPropertyW(package,cszTargetDir,path,&sz);
1896 if (rc != ERROR_SUCCESS)
1899 rc = MSI_GetPropertyW(package,cszRootDrive,path,&sz);
1901 MSI_SetPropertyW(package,cszTargetDir,path);
1904 *folder = &(package->folders[0]);
1910 rc = MSI_GetPropertyW(package,cszSourceDir,path,&sz);
1911 if (rc != ERROR_SUCCESS)
1914 rc = MSI_GetPropertyW(package,cszDatabase,path,&sz);
1915 if (rc == ERROR_SUCCESS)
1917 LPWSTR ptr = strrchrW(path,'\\');
1926 *folder = &(package->folders[0]);
1931 for (i = 0; i < package->loaded_folders; i++)
1933 if (strcmpW(package->folders[i].Directory,name)==0)
1937 if (i >= package->loaded_folders)
1938 return ERROR_FUNCTION_FAILED;
1941 *folder = &(package->folders[i]);
1943 if (!source && package->folders[i].ResolvedTarget[0])
1945 strcpyW(path,package->folders[i].ResolvedTarget);
1946 TRACE(" already resolved to %s\n",debugstr_w(path));
1947 return ERROR_SUCCESS;
1949 else if (source && package->folders[i].ResolvedSource[0])
1951 strcpyW(path,package->folders[i].ResolvedSource);
1952 return ERROR_SUCCESS;
1954 else if (!source && package->folders[i].Property[0])
1956 strcpyW(path,package->folders[i].Property);
1957 TRACE(" internally set to %s\n",debugstr_w(path));
1959 MSI_SetPropertyW(package,name,path);
1960 return ERROR_SUCCESS;
1963 if (package->folders[i].ParentIndex >= 0)
1965 TRACE(" ! Parent is %s\n", debugstr_w(package->folders[
1966 package->folders[i].ParentIndex].Directory));
1967 resolve_folder(package, package->folders[
1968 package->folders[i].ParentIndex].Directory, path,source,
1973 if (package->folders[i].TargetDefault[0])
1975 strcatW(path,package->folders[i].TargetDefault);
1976 strcatW(path,cszbs);
1978 strcpyW(package->folders[i].ResolvedTarget,path);
1979 TRACE(" resolved into %s\n",debugstr_w(path));
1981 MSI_SetPropertyW(package,name,path);
1985 if (package->folders[i].SourceDefault[0])
1987 strcatW(path,package->folders[i].SourceDefault);
1988 strcatW(path,cszbs);
1990 strcpyW(package->folders[i].ResolvedSource,path);
1997 * Alot is done in this function aside from just the costing.
1998 * The costing needs to be implemented at some point but for now I am going
1999 * to focus on the directory building
2002 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2004 static const WCHAR ExecSeqQuery[] = {
2005 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2006 'D','i','r','e','c','t','o','r','y',0};
2007 static const WCHAR ConditionQuery[] = {
2008 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2009 'C','o','n','d','i','t','i','o','n',0};
2010 static const WCHAR szCosting[] = {
2011 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2012 static const WCHAR szOne[] = { '1', 0 };
2017 TRACE("Building Directory properties\n");
2019 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2020 if (rc != ERROR_SUCCESS)
2023 rc = MSI_ViewExecute(view, 0);
2024 if (rc != ERROR_SUCCESS)
2026 MSI_ViewClose(view);
2027 msiobj_release(&view->hdr);
2034 WCHAR path[MAX_PATH];
2035 MSIRECORD * row = 0;
2038 rc = MSI_ViewFetch(view,&row);
2039 if (rc != ERROR_SUCCESS)
2046 MSI_RecordGetStringW(row,1,name,&sz);
2048 /* This helper function now does ALL the work */
2049 TRACE("Dir %s ...\n",debugstr_w(name));
2050 load_folder(package,name);
2051 resolve_folder(package,name,path,FALSE,TRUE,NULL);
2052 TRACE("resolves to %s\n",debugstr_w(path));
2054 msiobj_release(&row->hdr);
2056 MSI_ViewClose(view);
2057 msiobj_release(&view->hdr);
2059 TRACE("File calculations %i files\n",package->loaded_files);
2061 for (i = 0; i < package->loaded_files; i++)
2063 MSICOMPONENT* comp = NULL;
2064 MSIFILE* file= NULL;
2066 file = &package->files[i];
2067 if (file->ComponentIndex >= 0)
2068 comp = &package->components[file->ComponentIndex];
2072 /* calculate target */
2073 resolve_folder(package, comp->Directory, file->TargetPath, FALSE,
2075 strcatW(file->TargetPath,file->FileName);
2077 TRACE("file %s resolves to %s\n",
2078 debugstr_w(file->File),debugstr_w(file->TargetPath));
2080 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2083 comp->Cost += file->FileSize;
2087 if (file->Version[0])
2093 WCHAR filever[0x100];
2094 static const WCHAR name[] =
2095 {'\\','V','a','r','F','i','l','e','I','n','f','o',
2096 '\\','F','i','l','e','V','e','r','s','i','o','n',0};
2098 FIXME("Version comparison.. Untried Untested and most "
2099 "likely very very wrong\n");
2100 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2101 version = HeapAlloc(GetProcessHeap(),0,versize);
2102 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2104 VerQueryValueW(version,name,(LPVOID)filever,&sz);
2105 HeapFree(GetProcessHeap(),0,version);
2107 if (strcmpW(version,file->Version)<0)
2110 FIXME("cost should be diff in size\n");
2111 comp->Cost += file->FileSize;
2122 TRACE("Evaluating Condition Table\n");
2124 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2125 if (rc != ERROR_SUCCESS)
2128 rc = MSI_ViewExecute(view, 0);
2129 if (rc != ERROR_SUCCESS)
2131 MSI_ViewClose(view);
2132 msiobj_release(&view->hdr);
2138 WCHAR Feature[0x100];
2139 MSIRECORD * row = 0;
2143 rc = MSI_ViewFetch(view,&row);
2145 if (rc != ERROR_SUCCESS)
2152 MSI_RecordGetStringW(row,1,Feature,&sz);
2154 feature_index = get_loaded_feature(package,Feature);
2155 if (feature_index < 0)
2156 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2160 Condition = load_dynamic_stringW(row,3);
2162 if (MSI_EvaluateConditionW(package,Condition) == MSICONDITION_TRUE)
2164 int level = MSI_RecordGetInteger(row,2);
2165 TRACE("Reseting feature %s to level %i\n",debugstr_w(Feature),
2167 package->features[feature_index].Level = level;
2169 HeapFree(GetProcessHeap(),0,Condition);
2172 msiobj_release(&row->hdr);
2174 MSI_ViewClose(view);
2175 msiobj_release(&view->hdr);
2177 TRACE("Enabling or Disabling Components\n");
2178 for (i = 0; i < package->loaded_components; i++)
2180 if (package->components[i].Condition[0])
2182 if (MSI_EvaluateConditionW(package,
2183 package->components[i].Condition) == MSICONDITION_FALSE)
2185 TRACE("Disabling component %s\n",
2186 debugstr_w(package->components[i].Component));
2187 package->components[i].Enabled = FALSE;
2192 MSI_SetPropertyW(package,szCosting,szOne);
2193 return ERROR_SUCCESS;
2197 * This is a helper function for handling embedded cabinet media
2199 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2207 WCHAR tmp[MAX_PATH];
2209 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2210 if (rc != ERROR_SUCCESS)
2214 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2215 GetTempPathW(MAX_PATH,tmp);
2217 GetTempFileNameW(tmp,stream_name,0,source);
2219 track_tempfile(package,strrchrW(source,'\\'), source);
2220 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2221 FILE_ATTRIBUTE_NORMAL, NULL);
2223 if (the_file == INVALID_HANDLE_VALUE)
2225 rc = ERROR_FUNCTION_FAILED;
2229 WriteFile(the_file,data,size,&write,NULL);
2230 CloseHandle(the_file);
2231 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2233 HeapFree(GetProcessHeap(),0,data);
2238 /***********************************************************************
2239 * extract_cabinet_file
2241 * Extract files from a cab file.
2243 static void (WINAPI *pExtractFiles)( LPSTR, LPSTR, DWORD, DWORD, DWORD, DWORD );
2245 static BOOL extract_cabinet_file_advpack( const WCHAR *cabinet,
2248 static HMODULE advpack;
2250 char *cab_path, *cab_file;
2254 if (!advpack && !(advpack = LoadLibraryA( "advpack.dll" )))
2256 ERR( "could not load advpack.dll\n" );
2259 if (!(pExtractFiles = (void *)GetProcAddress( advpack, "ExtractFiles"
2262 ERR( "could not find ExtractFiles in advpack.dll\n" );
2267 if (!(cab_file = strdupWtoA( cabinet ))) return FALSE;
2268 if (!(cab_path = strdupWtoA( root ))) return FALSE;
2270 FIXME( "awful hack: extracting cabinet %s\n", debugstr_a(cab_file) );
2271 pExtractFiles( cab_file, cab_path, 0, 0, 0, 0 );
2272 HeapFree( GetProcessHeap(), 0, cab_file );
2273 HeapFree( GetProcessHeap(), 0, cab_path );
2277 static BOOL extract_cabinet_file_cabinet( const WCHAR *cabinet,
2281 /* from cabinet.h */
2283 struct ExtractFileList {
2285 struct ExtractFileList *next;
2286 BOOL unknown; /* always 1L */
2290 long result1; /* 0x000 */
2291 long unknown1[3]; /* 0x004 */
2292 struct ExtractFileList* filelist; /* 0x010 */
2293 long filecount; /* 0x014 */
2294 long unknown2; /* 0x018 */
2295 char directory[0x104]; /* 0x01c */
2296 char lastfile[0x20c]; /* 0x120 */
2299 HRESULT WINAPI Extract(EXTRACTdest *dest, LPCSTR what);
2301 char *cab_path, *src_path;
2303 struct ExtractFileList fl;
2305 if (!(cab_path = strdupWtoA( cabinet ))) return FALSE;
2306 if (!(src_path = strdupWtoA( root ))) return FALSE;
2308 memset(&exd,0,sizeof(exd));
2309 strcpy(exd.directory,src_path);
2311 fl.filename = cab_path;
2315 FIXME( "more aweful hack: extracting cabinet %s\n", debugstr_a(cab_path) );
2316 Extract(&exd,cab_path);
2318 HeapFree( GetProcessHeap(), 0, cab_path );
2319 HeapFree( GetProcessHeap(), 0, src_path );
2323 static BOOL extract_cabinet_file(const WCHAR* source, const WCHAR* path)
2325 TRACE("Extracting %s to %s\n",debugstr_w(source), debugstr_w(path));
2326 if (!extract_cabinet_file_advpack(source,path))
2327 return extract_cabinet_file_cabinet(source,path);
2331 static UINT ready_media_for_file(MSIPACKAGE *package, UINT sequence,
2336 MSIRECORD * row = 0;
2337 WCHAR source[MAX_PATH];
2338 static const WCHAR ExecSeqQuery[] = {
2339 's','e','l','e','c','t',' ','*',' ',
2340 'f','r','o','m',' ','M','e','d','i','a',' ',
2341 'w','h','e','r','e',' ','L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%','i',' ',
2342 'o','r','d','e','r',' ','b','y',' ','L','a','s','t','S','e','q','u','e','n','c','e',0};
2347 static INT last_sequence = 0;
2349 if (sequence <= last_sequence)
2351 TRACE("Media already ready (%i, %i)\n",sequence,last_sequence);
2352 return ERROR_SUCCESS;
2355 sprintfW(Query,ExecSeqQuery,sequence);
2357 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2358 if (rc != ERROR_SUCCESS)
2361 rc = MSI_ViewExecute(view, 0);
2362 if (rc != ERROR_SUCCESS)
2364 MSI_ViewClose(view);
2365 msiobj_release(&view->hdr);
2369 rc = MSI_ViewFetch(view,&row);
2370 if (rc != ERROR_SUCCESS)
2372 MSI_ViewClose(view);
2373 msiobj_release(&view->hdr);
2376 seq = MSI_RecordGetInteger(row,2);
2377 last_sequence = seq;
2379 if (!MSI_RecordIsNull(row,4))
2382 MSI_RecordGetStringW(row,4,cab,&sz);
2383 TRACE("Source is CAB %s\n",debugstr_w(cab));
2384 /* the stream does not contain the # character */
2387 writeout_cabinet_stream(package,&cab[1],source);
2388 strcpyW(path,source);
2389 *(strrchrW(path,'\\')+1)=0;
2394 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
2396 ERR("No Source dir defined \n");
2397 rc = ERROR_FUNCTION_FAILED;
2401 strcpyW(path,source);
2402 strcatW(source,cab);
2403 /* extract the cab file into a folder in the temp folder */
2405 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
2407 GetTempPathW(MAX_PATH,path);
2410 rc = !extract_cabinet_file(source,path);
2412 msiobj_release(&row->hdr);
2413 MSI_ViewClose(view);
2414 msiobj_release(&view->hdr);
2418 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
2422 WCHAR install_path[MAX_PATH];
2424 rc = resolve_folder(package, package->components[component].Directory,
2425 install_path, FALSE, FALSE, &folder);
2427 if (rc != ERROR_SUCCESS)
2430 /* create the path */
2431 if (folder->State == 0)
2433 create_full_pathW(install_path);
2440 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
2442 UINT rc = ERROR_SUCCESS;
2445 WCHAR uipath[MAX_PATH];
2448 return ERROR_INVALID_HANDLE;
2450 /* increment progress bar each time action data is sent */
2451 ui_progress(package,1,1,1,0);
2453 for (index = 0; index < package->loaded_files; index++)
2455 WCHAR path_to_source[MAX_PATH];
2458 file = &package->files[index];
2460 if (file->Temporary)
2463 if (!package->components[file->ComponentIndex].Enabled ||
2464 !package->components[file->ComponentIndex].FeatureState)
2466 TRACE("File %s is not scheduled for install\n",
2467 debugstr_w(file->File));
2471 if ((file->State == 1) || (file->State == 2))
2473 TRACE("Installing %s\n",debugstr_w(file->File));
2474 rc = ready_media_for_file(package,file->Sequence,path_to_source);
2477 * our file table could change here because a new temp file
2478 * may have been created
2480 file = &package->files[index];
2481 if (rc != ERROR_SUCCESS)
2483 ERR("Unable to ready media\n");
2484 rc = ERROR_FUNCTION_FAILED;
2488 create_component_directory( package, file->ComponentIndex);
2490 strcpyW(file->SourcePath, path_to_source);
2491 strcatW(file->SourcePath, file->File);
2493 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
2494 debugstr_w(file->TargetPath));
2497 uirow=MSI_CreateRecord(9);
2498 MSI_RecordSetStringW(uirow,1,file->File);
2499 strcpyW(uipath,file->TargetPath);
2500 *(strrchrW(uipath,'\\')+1)=0;
2501 MSI_RecordSetStringW(uirow,9,uipath);
2502 MSI_RecordSetInteger(uirow,6,file->FileSize);
2503 ui_actiondata(package,szInstallFiles,uirow);
2504 msiobj_release( &uirow->hdr );
2506 rc = !MoveFileW(file->SourcePath,file->TargetPath);
2507 ui_progress(package,2,0,0,0);
2511 ERR("Unable to move file (error %li)\n",GetLastError());
2522 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
2528 return ERROR_INVALID_HANDLE;
2530 for (index = 0; index < package->loaded_files; index ++)
2532 if (strcmpW(file_key,package->files[index].File)==0)
2534 if (package->files[index].State >= 3)
2536 strcpyW(file_source,package->files[index].TargetPath);
2537 return ERROR_SUCCESS;
2540 return ERROR_FILE_NOT_FOUND;
2544 return ERROR_FUNCTION_FAILED;
2547 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
2551 MSIRECORD * row = 0;
2552 static const WCHAR ExecSeqQuery[] = {
2553 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2554 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
2557 return ERROR_INVALID_HANDLE;
2559 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2560 if (rc != ERROR_SUCCESS)
2563 rc = MSI_ViewExecute(view, 0);
2564 if (rc != ERROR_SUCCESS)
2566 MSI_ViewClose(view);
2567 msiobj_release(&view->hdr);
2573 WCHAR file_key[0x100];
2574 WCHAR file_source[MAX_PATH];
2575 WCHAR dest_name[0x100];
2576 WCHAR dest_path[MAX_PATH];
2577 WCHAR component[0x100];
2578 INT component_index;
2582 rc = MSI_ViewFetch(view,&row);
2583 if (rc != ERROR_SUCCESS)
2590 rc = MSI_RecordGetStringW(row,2,component,&sz);
2591 if (rc != ERROR_SUCCESS)
2593 ERR("Unable to get component\n");
2594 msiobj_release(&row->hdr);
2598 component_index = get_loaded_component(package,component);
2599 if (!package->components[component_index].Enabled ||
2600 !package->components[component_index].FeatureState)
2602 TRACE("Skipping copy due to disabled component\n");
2603 msiobj_release(&row->hdr);
2608 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
2609 if (rc != ERROR_SUCCESS)
2611 ERR("Unable to get file key\n");
2612 msiobj_release(&row->hdr);
2616 rc = get_file_target(package,file_key,file_source);
2618 if (rc != ERROR_SUCCESS)
2620 ERR("Original file unknown %s\n",debugstr_w(file_key));
2621 msiobj_release(&row->hdr);
2625 if (MSI_RecordIsNull(row,4))
2627 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
2632 MSI_RecordGetStringW(row,4,dest_name,&sz);
2633 reduce_to_longfilename(dest_name);
2636 if (MSI_RecordIsNull(row,5))
2638 strcpyW(dest_path,file_source);
2639 *strrchrW(dest_path,'\\')=0;
2643 WCHAR destkey[0x100];
2645 MSI_RecordGetStringW(row,5,destkey,&sz);
2647 rc = resolve_folder(package, destkey, dest_path,FALSE,FALSE,NULL);
2648 if (rc != ERROR_SUCCESS)
2650 ERR("Unable to get destination folder\n");
2651 msiobj_release(&row->hdr);
2656 strcatW(dest_path,dest_name);
2658 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
2659 debugstr_w(dest_path));
2661 if (strcmpW(file_source,dest_path))
2662 rc = !CopyFileW(file_source,dest_path,TRUE);
2666 if (rc != ERROR_SUCCESS)
2667 ERR("Failed to copy file\n");
2669 FIXME("We should track these duplicate files as well\n");
2671 msiobj_release(&row->hdr);
2673 MSI_ViewClose(view);
2674 msiobj_release(&view->hdr);
2680 /* OK this value is "interpretted" and then formatted based on the
2681 first few characters */
2682 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
2686 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
2695 deformat_string(package, &value[2], &deformated);
2697 /* binary value type */
2700 *size = strlenW(ptr)/2;
2701 data = HeapAlloc(GetProcessHeap(),0,*size);
2713 data[count] = (BYTE)strtol(byte,NULL,0);
2716 HeapFree(GetProcessHeap(),0,deformated);
2718 TRACE("Data %li bytes(%i)\n",*size,count);
2723 deformat_string(package, &value[1], &deformated);
2726 *size = sizeof(DWORD);
2727 data = HeapAlloc(GetProcessHeap(),0,*size);
2728 *(LPDWORD)data = atoiW(deformated);
2729 TRACE("DWORD %i\n",*data);
2731 HeapFree(GetProcessHeap(),0,deformated);
2744 *type=REG_EXPAND_SZ;
2752 *size = deformat_string(package, ptr,(LPWSTR*)&data);
2757 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
2761 MSIRECORD * row = 0;
2762 static const WCHAR ExecSeqQuery[] = {
2763 's','e','l','e','c','t',' ','*',' ',
2764 'f','r','o','m',' ','R','e','g','i','s','t','r','y',0 };
2767 return ERROR_INVALID_HANDLE;
2769 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2770 if (rc != ERROR_SUCCESS)
2773 rc = MSI_ViewExecute(view, 0);
2774 if (rc != ERROR_SUCCESS)
2776 MSI_ViewClose(view);
2777 msiobj_release(&view->hdr);
2781 /* increment progress bar each time action data is sent */
2782 ui_progress(package,1,1,1,0);
2786 static const WCHAR szHCR[] =
2787 {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T','\\',0};
2788 static const WCHAR szHCU[] =
2789 {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',0};
2790 static const WCHAR szHLM[] =
2791 {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',
2793 static const WCHAR szHU[] =
2794 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
2799 LPSTR value_data = NULL;
2800 HKEY root_key, hkey;
2802 WCHAR component[0x100];
2803 INT component_index;
2810 rc = MSI_ViewFetch(view,&row);
2811 if (rc != ERROR_SUCCESS)
2818 MSI_RecordGetStringW(row,6,component,&sz);
2819 component_index = get_loaded_component(package,component);
2821 if (!package->components[component_index].Enabled ||
2822 !package->components[component_index].FeatureState)
2824 TRACE("Skipping write due to disabled component\n");
2825 msiobj_release(&row->hdr);
2829 /* null values have special meanings during uninstalls and such */
2831 if(MSI_RecordIsNull(row,5))
2833 msiobj_release(&row->hdr);
2837 root = MSI_RecordGetInteger(row,2);
2839 MSI_RecordGetStringW(row,3,key,&sz);
2842 if (MSI_RecordIsNull(row,4))
2845 MSI_RecordGetStringW(row,4,name,&sz);
2847 /* get the root key */
2850 case 0: root_key = HKEY_CLASSES_ROOT;
2851 strcpyW(uikey,szHCR); break;
2852 case 1: root_key = HKEY_CURRENT_USER;
2853 strcpyW(uikey,szHCU); break;
2854 case 2: root_key = HKEY_LOCAL_MACHINE;
2855 strcpyW(uikey,szHLM); break;
2856 case 3: root_key = HKEY_USERS;
2857 strcpyW(uikey,szHU); break;
2859 ERR("Unknown root %i\n",root);
2865 msiobj_release(&row->hdr);
2870 if (RegCreateKeyW( root_key, key, &hkey))
2872 ERR("Could not create key %s\n",debugstr_w(key));
2873 msiobj_release(&row->hdr);
2877 value = load_dynamic_stringW(row,5);
2878 value_data = parse_value(package, value, &type, &size);
2882 TRACE("Setting value %s\n",debugstr_w(name));
2883 RegSetValueExW(hkey, name, 0, type, value_data, size);
2885 uirow = MSI_CreateRecord(3);
2886 MSI_RecordSetStringW(uirow,2,name);
2887 MSI_RecordSetStringW(uirow,1,uikey);
2890 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
2892 MSI_RecordSetStringW(uirow,3,value);
2894 ui_actiondata(package,szWriteRegistryValues,uirow);
2895 ui_progress(package,2,0,0,0);
2896 msiobj_release( &uirow->hdr );
2898 HeapFree(GetProcessHeap(),0,value_data);
2900 HeapFree(GetProcessHeap(),0,value);
2902 msiobj_release(&row->hdr);
2905 MSI_ViewClose(view);
2906 msiobj_release(&view->hdr);
2911 * This helper function should probably go alot of places
2913 * Thinking about this, maybe this should become yet another Bison file
2915 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data)
2925 /* scan for special characters */
2926 if (!strchrW(ptr,'[') || (strchrW(ptr,'[') && !strchrW(ptr,']')))
2929 size = (strlenW(ptr)+1) * sizeof(WCHAR);
2930 *data = HeapAlloc(GetProcessHeap(),0,size);
2935 /* formatted string located */
2936 mark = strchrW(ptr,'[');
2939 INT cnt = (mark - ptr);
2940 TRACE("%i (%i) characters before marker\n",cnt,(mark-ptr));
2941 size = cnt * sizeof(WCHAR);
2942 size += sizeof(WCHAR);
2943 *data = HeapAlloc(GetProcessHeap(),0,size);
2944 strncpyW(*data,ptr,cnt);
2949 size = sizeof(WCHAR);
2950 *data = HeapAlloc(GetProcessHeap(),0,size);
2955 *strchrW(key,']')=0;
2956 mark = strchrW(mark,']');
2958 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
2960 rc = MSI_GetPropertyW(package, key, NULL, &sz);
2961 if ((rc == ERROR_SUCCESS) || (rc == ERROR_MORE_DATA))
2966 value = HeapAlloc(GetProcessHeap(),0,sz * sizeof(WCHAR));
2967 MSI_GetPropertyW(package, key, value, &sz);
2969 chunk = (strlenW(value)+1) * sizeof(WCHAR);
2971 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
2973 strcatW(*data,value);
2975 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
2979 chunk = (strlenW(mark)+1) * sizeof(WCHAR);
2981 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
2983 strcatW(*data,mark);
2985 (*data)[strlenW(*data)]=0;
2986 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
2988 /* recursively do this to clean up */
2989 mark = HeapAlloc(GetProcessHeap(),0,size);
2990 strcpyW(mark,*data);
2991 TRACE("String at this point %s\n",debugstr_w(mark));
2992 size = deformat_string(package,mark,data);
2993 HeapFree(GetProcessHeap(),0,mark);
2997 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3004 LPWSTR override = NULL;
3005 static const WCHAR addlocal[]={'A','D','D','L','O','C','A','L',0};
3006 static const WCHAR all[]={'A','L','L',0};
3007 static const WCHAR szlevel[] = {
3008 'I','N','S','T','A','L','L','L','E','V','E','L',0};
3009 static const WCHAR szAddLocal[] = {
3010 'A','D','D','L','O','C','A','L',0};
3012 /* I do not know if this is where it should happen.. but */
3014 TRACE("Checking Install Level\n");
3017 if (MSI_GetPropertyW(package,szlevel,level,&sz)==ERROR_SUCCESS)
3018 install_level = atoiW(level);
3023 rc = MSI_GetPropertyW(package,szAddLocal,NULL,&sz);
3024 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
3027 override = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
3028 MSI_GetPropertyW(package, addlocal,override,&sz);
3032 * Components FeatureState defaults to FALSE. The idea is we want to
3033 * enable the component is ANY feature that uses it is enabled to install
3035 for(i = 0; i < package->loaded_features; i++)
3037 BOOL feature_state= ((package->features[i].Level > 0) &&
3038 (package->features[i].Level <= install_level));
3040 if (override && (strcmpiW(override,all)==0 ||
3041 strstrW(override,package->features[i].Feature)))
3043 TRACE("Override of install level found\n");
3044 feature_state = TRUE;
3045 package->features[i].Enabled = feature_state;
3048 TRACE("Feature %s has a state of %i\n",
3049 debugstr_w(package->features[i].Feature), feature_state);
3050 for( j = 0; j < package->features[i].ComponentCount; j++)
3052 package->components[package->features[i].Components[j]].FeatureState
3056 if (override != NULL)
3057 HeapFree(GetProcessHeap(),0,override);
3059 * So basically we ONLY want to install a component if its Enabled AND
3060 * FeatureState are both TRUE
3062 return ERROR_SUCCESS;
3065 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3068 static const WCHAR q1[]={
3069 'S','E','L','E','C','T',' ','*',' ',
3070 'F','R','O','M',' ','R','e','g','i','s','t','r','y',0};
3073 MSIRECORD * row = 0;
3075 TRACE(" InstallValidate \n");
3077 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3078 if (rc != ERROR_SUCCESS)
3080 rc = MSI_ViewExecute(view, 0);
3081 if (rc != ERROR_SUCCESS)
3083 MSI_ViewClose(view);
3084 msiobj_release(&view->hdr);
3089 rc = MSI_ViewFetch(view,&row);
3090 if (rc != ERROR_SUCCESS)
3097 msiobj_release(&row->hdr);
3099 MSI_ViewClose(view);
3100 msiobj_release(&view->hdr);
3102 ui_progress(package,0,progress+package->loaded_files,0,0);
3104 return ERROR_SUCCESS;
3107 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3111 MSIRECORD * row = 0;
3112 static const WCHAR ExecSeqQuery[] = {
3113 'S','E','L','E','C','T',' ','*',' ',
3114 'f','r','o','m',' ','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3115 static const WCHAR title[]=
3116 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3118 TRACE("Checking launch conditions\n");
3120 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3121 if (rc != ERROR_SUCCESS)
3124 rc = MSI_ViewExecute(view, 0);
3125 if (rc != ERROR_SUCCESS)
3127 MSI_ViewClose(view);
3128 msiobj_release(&view->hdr);
3133 while (rc == ERROR_SUCCESS)
3136 LPWSTR message = NULL;
3138 rc = MSI_ViewFetch(view,&row);
3139 if (rc != ERROR_SUCCESS)
3145 cond = load_dynamic_stringW(row,1);
3147 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3149 message = load_dynamic_stringW(row,2);
3150 MessageBoxW(NULL,message,title,MB_OK);
3151 HeapFree(GetProcessHeap(),0,message);
3152 rc = ERROR_FUNCTION_FAILED;
3154 HeapFree(GetProcessHeap(),0,cond);
3155 msiobj_release(&row->hdr);
3157 MSI_ViewClose(view);
3158 msiobj_release(&view->hdr);
3162 static void resolve_keypath( MSIPACKAGE* package, INT
3163 component_index, WCHAR *keypath)
3165 MSICOMPONENT* cmp = &package->components[component_index];
3167 if (cmp->KeyPath[0]==0)
3169 resolve_folder(package,cmp->Directory,keypath,FALSE,FALSE,NULL);
3172 if ((cmp->Attributes & 0x4) || (cmp->Attributes & 0x20))
3174 FIXME("UNIMPLEMENTED keypath as Registry or ODBC Source\n");
3180 j = get_loaded_file(package,cmp->KeyPath);
3183 strcpyW(keypath,package->files[j].TargetPath);
3188 * Ok further analysis makes me think that this work is
3189 * actually done in the PublishComponents and PublishFeatures
3190 * step, and not here. It appears like the keypath and all that is
3191 * resolved in this step, however actually written in the Publish steps.
3192 * But we will leave it here for now because it is unclear
3194 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
3196 WCHAR productcode[0x100];
3197 WCHAR squished_pc[0x100];
3198 WCHAR squished_cc[0x100];
3202 HKEY hkey=0,hkey2=0,hkey3=0;
3203 static const WCHAR szProductCode[]=
3204 {'P','r','o','d','u','c','t','C','o','d','e',0};
3205 static const WCHAR szInstaller[] = {
3206 'S','o','f','t','w','a','r','e','\\',
3207 'M','i','c','r','o','s','o','f','t','\\',
3208 'W','i','n','d','o','w','s','\\',
3209 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3210 'I','n','s','t','a','l','l','e','r',0 };
3211 static const WCHAR szFeatures[] = {
3212 'F','e','a','t','u','r','e','s',0 };
3213 static const WCHAR szComponents[] = {
3214 'C','o','m','p','o','n','e','n','t','s',0 };
3217 return ERROR_INVALID_HANDLE;
3219 /* writes the Component and Features values to the registry */
3221 rc = MSI_GetPropertyW(package,szProductCode,productcode,&sz);
3222 if (rc != ERROR_SUCCESS)
3223 return ERROR_SUCCESS;
3225 squash_guid(productcode,squished_pc);
3226 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller,&hkey);
3227 if (rc != ERROR_SUCCESS)
3230 rc = RegCreateKeyW(hkey,szFeatures,&hkey2);
3231 if (rc != ERROR_SUCCESS)
3234 rc = RegCreateKeyW(hkey2,squished_pc,&hkey3);
3235 if (rc != ERROR_SUCCESS)
3238 /* here the guids are base 85 encoded */
3239 for (i = 0; i < package->loaded_features; i++)
3246 size = package->features[i].ComponentCount*21*sizeof(WCHAR);
3247 data = HeapAlloc(GetProcessHeap(), 0, size);
3250 for (j = 0; j < package->features[i].ComponentCount; j++)
3253 TRACE("From %s\n",debugstr_w(package->components
3254 [package->features[i].Components[j]].ComponentId));
3255 CLSIDFromString(package->components
3256 [package->features[i].Components[j]].ComponentId,
3258 encode_base85_guid(&clsid,buf);
3259 TRACE("to %s\n",debugstr_w(buf));
3263 size = strlenW(data)*sizeof(WCHAR);
3264 RegSetValueExW(hkey3,package->features[i].Feature,0,REG_SZ,
3266 HeapFree(GetProcessHeap(),0,data);
3272 rc = RegCreateKeyW(hkey,szComponents,&hkey2);
3273 if (rc != ERROR_SUCCESS)
3276 for (i = 0; i < package->loaded_components; i++)
3278 if (package->components[i].ComponentId[0]!=0)
3280 WCHAR keypath[0x1000];
3283 squash_guid(package->components[i].ComponentId,squished_cc);
3284 rc = RegCreateKeyW(hkey2,squished_cc,&hkey3);
3285 if (rc != ERROR_SUCCESS)
3288 resolve_keypath(package,i,keypath);
3290 RegSetValueExW(hkey3,squished_pc,0,REG_SZ,(LPVOID)keypath,
3291 (strlenW(keypath)+1)*sizeof(WCHAR));
3295 uirow = MSI_CreateRecord(3);
3296 MSI_RecordSetStringW(uirow,1,productcode);
3297 MSI_RecordSetStringW(uirow,2,package->components[i].ComponentId);
3298 MSI_RecordSetStringW(uirow,3,keypath);
3299 ui_actiondata(package,szProcessComponents,uirow);
3300 msiobj_release( &uirow->hdr );
3309 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
3312 * OK this is a bit confusing.. I am given a _Component key and I believe
3313 * that the file that is being registered as a type library is the "key file
3314 * of that component" which I interpret to mean "The file in the KeyPath of
3319 MSIRECORD * row = 0;
3320 static const WCHAR Query[] = {
3321 'S','E','L','E','C','T',' ','*',' ',
3322 'f','r','o','m',' ','T','y','p','e','L','i','b',0};
3327 return ERROR_INVALID_HANDLE;
3329 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3330 if (rc != ERROR_SUCCESS)
3333 rc = MSI_ViewExecute(view, 0);
3334 if (rc != ERROR_SUCCESS)
3336 MSI_ViewClose(view);
3337 msiobj_release(&view->hdr);
3343 WCHAR component[0x100];
3347 rc = MSI_ViewFetch(view,&row);
3348 if (rc != ERROR_SUCCESS)
3355 MSI_RecordGetStringW(row,3,component,&sz);
3357 index = get_loaded_component(package,component);
3360 msiobj_release(&row->hdr);
3364 if (!package->components[index].Enabled ||
3365 !package->components[index].FeatureState)
3367 TRACE("Skipping typelib reg due to disabled component\n");
3368 msiobj_release(&row->hdr);
3372 index = get_loaded_file(package,package->components[index].KeyPath);
3376 msiobj_release(&row->hdr);
3380 res = LoadTypeLib(package->files[index].TargetPath,&ptLib);
3383 WCHAR help[MAX_PATH];
3384 WCHAR helpid[0x100];
3387 MSI_RecordGetStringW(row,6,helpid,&sz);
3389 resolve_folder(package,helpid,help,FALSE,FALSE,NULL);
3391 res = RegisterTypeLib(ptLib,package->files[index].TargetPath,help);
3392 if (!SUCCEEDED(res))
3393 ERR("Failed to register type library %s\n",
3394 debugstr_w(package->files[index].TargetPath));
3397 /* Yes the row has more fields than I need, but #1 is
3398 correct and the only one I need. Why make a new row? */
3400 ui_actiondata(package,szRegisterTypeLibraries,row);
3402 TRACE("Registered %s\n",
3403 debugstr_w(package->files[index].TargetPath));
3407 ITypeLib_Release(ptLib);
3410 ERR("Failed to load type library %s\n",
3411 debugstr_w(package->files[index].TargetPath));
3413 msiobj_release(&row->hdr);
3415 MSI_ViewClose(view);
3416 msiobj_release(&view->hdr);
3421 static UINT register_appid(MSIPACKAGE *package, LPCWSTR clsid, LPCWSTR app )
3423 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3426 MSIRECORD * row = 0;
3427 static const WCHAR ExecSeqQuery[] =
3428 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','p','p','I'
3429 ,'d',' ','w','h','e','r','e',' ','A','p','p','I','d','=','`','%','s','`',0};
3430 WCHAR Query[0x1000];
3435 return ERROR_INVALID_HANDLE;
3437 sprintfW(Query,ExecSeqQuery,clsid);
3439 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3440 if (rc != ERROR_SUCCESS)
3443 rc = MSI_ViewExecute(view, 0);
3444 if (rc != ERROR_SUCCESS)
3446 MSI_ViewClose(view);
3447 msiobj_release(&view->hdr);
3451 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
3452 RegCreateKeyW(hkey2,clsid,&hkey3);
3453 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
3454 (strlenW(app)+1)*sizeof(WCHAR));
3456 rc = MSI_ViewFetch(view,&row);
3457 if (rc != ERROR_SUCCESS)
3459 MSI_ViewClose(view);
3460 msiobj_release(&view->hdr);
3464 if (!MSI_RecordIsNull(row,2))
3466 LPWSTR deformated=0;
3468 static const WCHAR szRemoteServerName[] =
3469 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
3470 buffer = load_dynamic_stringW(row,2);
3471 size = deformat_string(package,buffer,&deformated);
3472 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
3474 HeapFree(GetProcessHeap(),0,deformated);
3475 HeapFree(GetProcessHeap(),0,buffer);
3478 if (!MSI_RecordIsNull(row,3))
3480 static const WCHAR szLocalService[] =
3481 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
3483 buffer = load_dynamic_stringW(row,3);
3484 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3485 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
3486 HeapFree(GetProcessHeap(),0,buffer);
3489 if (!MSI_RecordIsNull(row,4))
3491 static const WCHAR szService[] =
3492 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
3494 buffer = load_dynamic_stringW(row,4);
3495 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3496 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
3497 HeapFree(GetProcessHeap(),0,buffer);
3500 if (!MSI_RecordIsNull(row,5))
3502 static const WCHAR szDLL[] =
3503 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
3505 buffer = load_dynamic_stringW(row,5);
3506 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3507 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
3508 HeapFree(GetProcessHeap(),0,buffer);
3511 if (!MSI_RecordIsNull(row,6))
3513 static const WCHAR szActivate[] =
3514 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
3515 static const WCHAR szY[] = {'Y',0};
3517 if (MSI_RecordGetInteger(row,6))
3518 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
3521 if (!MSI_RecordIsNull(row,7))
3523 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
3524 static const WCHAR szUser[] =
3525 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
3527 if (MSI_RecordGetInteger(row,7))
3528 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
3531 msiobj_release(&row->hdr);
3532 MSI_ViewClose(view);
3533 msiobj_release(&view->hdr);
3539 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
3542 * Again I am assuming the words, "Whose key file represents" when refering
3543 * to a Component as to meaning that Components KeyPath file
3545 * Also there is a very strong connection between ClassInfo and ProgID
3546 * that I am mostly glossing over.
3547 * What would be more propper is to load the ClassInfo and the ProgID info
3548 * into memory data structures and then be able to enable and disable them
3549 * based on component.
3554 MSIRECORD * row = 0;
3555 static const WCHAR ExecSeqQuery[] = {
3556 'S','E','L','E','C','T',' ','*',' ',
3557 'f','r','o','m',' ','C','l','a','s','s',0};
3558 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3559 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
3560 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3561 HKEY hkey,hkey2,hkey3;
3564 return ERROR_INVALID_HANDLE;
3566 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
3567 if (rc != ERROR_SUCCESS)
3568 return ERROR_FUNCTION_FAILED;
3570 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3571 if (rc != ERROR_SUCCESS)
3574 rc = MSI_ViewExecute(view, 0);
3575 if (rc != ERROR_SUCCESS)
3577 MSI_ViewClose(view);
3578 msiobj_release(&view->hdr);
3585 WCHAR buffer[0x100];
3590 rc = MSI_ViewFetch(view,&row);
3591 if (rc != ERROR_SUCCESS)
3598 MSI_RecordGetStringW(row,3,buffer,&sz);
3600 index = get_loaded_component(package,buffer);
3604 msiobj_release(&row->hdr);
3608 if (!package->components[index].Enabled ||
3609 !package->components[index].FeatureState)
3611 TRACE("Skipping class reg due to disabled component\n");
3612 msiobj_release(&row->hdr);
3617 MSI_RecordGetStringW(row,1,clsid,&sz);
3618 RegCreateKeyW(hkey,clsid,&hkey2);
3620 if (!MSI_RecordIsNull(row,5))
3623 MSI_RecordGetStringW(row,5,desc,&sz);
3625 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
3626 (strlenW(desc)+1)*sizeof(WCHAR));
3632 MSI_RecordGetStringW(row,2,buffer,&sz);
3634 RegCreateKeyW(hkey2,buffer,&hkey3);
3636 index = get_loaded_file(package,package->components[index].KeyPath);
3637 RegSetValueExW(hkey3,NULL,0,REG_SZ,
3638 (LPVOID)package->files[index].TargetPath,
3639 (strlenW(package->files[index].TargetPath)+1)
3644 if (!MSI_RecordIsNull(row,4))
3647 MSI_RecordGetStringW(row,4,buffer,&sz);
3649 RegCreateKeyW(hkey2,szProgID,&hkey3);
3651 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
3652 (strlenW(buffer)+1)*sizeof(WCHAR));
3657 if (!MSI_RecordIsNull(row,6))
3660 MSI_RecordGetStringW(row,6,buffer,&sz);
3662 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
3663 (strlenW(buffer)+1)*sizeof(WCHAR));
3665 register_appid(package,buffer,desc);
3670 FIXME("Process the rest of the fields >7\n");
3672 ui_actiondata(package,szRegisterClassInfo,row);
3674 msiobj_release(&row->hdr);
3676 MSI_ViewClose(view);
3677 msiobj_release(&view->hdr);
3684 static UINT register_progid_base(MSIRECORD * row, LPWSTR clsid)
3686 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3688 WCHAR buffer[0x100];
3693 MSI_RecordGetStringW(row,1,buffer,&sz);
3694 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
3696 if (!MSI_RecordIsNull(row,4))
3699 MSI_RecordGetStringW(row,4,buffer,&sz);
3700 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
3704 if (!MSI_RecordIsNull(row,3))
3708 MSI_RecordGetStringW(row,3,buffer,&sz);
3709 RegCreateKeyW(hkey,szCLSID,&hkey2);
3710 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
3714 strcpyW(clsid,buffer);
3720 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
3721 return ERROR_FUNCTION_FAILED;
3723 if (!MSI_RecordIsNull(row,5))
3724 FIXME ("UNHANDLED icon in Progid\n");
3725 return ERROR_SUCCESS;
3728 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid);
3730 static UINT register_parent_progid(MSIPACKAGE *package, LPCWSTR parent,
3735 MSIRECORD * row = 0;
3736 static const WCHAR Query_t[] =
3737 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','P','r','o','g'
3738 ,'I','d',' ','w','h','e','r','e',' ','P','r','o','g','I','d',' ','=',' ','`'
3740 WCHAR Query[0x1000];
3743 return ERROR_INVALID_HANDLE;
3745 sprintfW(Query,Query_t,parent);
3747 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3748 if (rc != ERROR_SUCCESS)
3751 rc = MSI_ViewExecute(view, 0);
3752 if (rc != ERROR_SUCCESS)
3754 MSI_ViewClose(view);
3755 msiobj_release(&view->hdr);
3759 rc = MSI_ViewFetch(view,&row);
3760 if (rc != ERROR_SUCCESS)
3762 MSI_ViewClose(view);
3763 msiobj_release(&view->hdr);
3767 register_progid(package,row,clsid);
3769 msiobj_release(&row->hdr);
3770 MSI_ViewClose(view);
3771 msiobj_release(&view->hdr);
3775 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid)
3777 UINT rc = ERROR_SUCCESS;
3779 if (MSI_RecordIsNull(row,2))
3780 rc = register_progid_base(row,clsid);
3783 WCHAR buffer[0x1000];
3786 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3789 MSI_RecordGetStringW(row,2,buffer,&sz);
3790 rc = register_parent_progid(package,buffer,clsid);
3793 MSI_RecordGetStringW(row,1,buffer,&sz);
3794 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
3795 /* clasid is same as parent */
3796 RegCreateKeyW(hkey,szCLSID,&hkey2);
3797 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
3801 if (!MSI_RecordIsNull(row,4))
3804 MSI_RecordGetStringW(row,4,buffer,&sz);
3805 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
3806 (strlenW(buffer)+1) * sizeof(WCHAR));
3809 if (!MSI_RecordIsNull(row,5))
3810 FIXME ("UNHANDLED icon in Progid\n");
3817 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
3820 * Sigh, here I am just brute force registering all progids
3821 * this needs to be linked to the Classes that have been registerd
3822 * but the easiest way to do that is to load all these stuff into
3823 * memory for easy checking.
3825 * Gives me something to continue to work toward.
3829 MSIRECORD * row = 0;
3830 static const WCHAR Query[] = {
3831 'S','E','L','E','C','T',' ','*',' ',
3832 'F','R','O','M',' ','P','r','o','g','I','d',0};
3835 return ERROR_INVALID_HANDLE;
3837 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3838 if (rc != ERROR_SUCCESS)
3841 rc = MSI_ViewExecute(view, 0);
3842 if (rc != ERROR_SUCCESS)
3844 MSI_ViewClose(view);
3845 msiobj_release(&view->hdr);
3851 WCHAR clsid[0x1000];
3853 rc = MSI_ViewFetch(view,&row);
3854 if (rc != ERROR_SUCCESS)
3860 register_progid(package,row,clsid);
3861 ui_actiondata(package,szRegisterProgIdInfo,row);
3863 msiobj_release(&row->hdr);
3865 MSI_ViewClose(view);
3866 msiobj_release(&view->hdr);
3870 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
3873 WCHAR ProductCode[0x100];
3874 WCHAR SystemFolder[MAX_PATH];
3877 static const WCHAR szInstaller[] =
3878 {'I','n','s','t','a','l','l','e','r','\\',0};
3879 static const WCHAR szProductCode[] =
3880 {'P','r','o','d','u','c','t','C','o','d','e',0};
3881 static const WCHAR szFolder[] =
3882 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3885 MSI_GetPropertyW(package,szProductCode,ProductCode,&sz);
3886 if (strlenW(ProductCode)==0)
3887 return ERROR_FUNCTION_FAILED;
3890 MSI_GetPropertyW(package,szFolder,SystemFolder,&sz);
3891 strcatW(SystemFolder,szInstaller);
3892 strcatW(SystemFolder,ProductCode);
3893 create_full_pathW(SystemFolder);
3895 strcpyW(FilePath,SystemFolder);
3896 strcatW(FilePath,cszbs);
3897 strcatW(FilePath,icon_name);
3898 return ERROR_SUCCESS;
3901 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
3905 MSIRECORD * row = 0;
3906 static const WCHAR Query[] = {
3907 'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
3908 'S','h','o','r','t','c','u','t',0};
3914 return ERROR_INVALID_HANDLE;
3916 res = CoInitialize( NULL );
3919 ERR("CoInitialize failed\n");
3920 return ERROR_FUNCTION_FAILED;
3923 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3924 if (rc != ERROR_SUCCESS)
3927 rc = MSI_ViewExecute(view, 0);
3928 if (rc != ERROR_SUCCESS)
3930 MSI_ViewClose(view);
3931 msiobj_release(&view->hdr);
3937 WCHAR target_file[MAX_PATH];
3938 WCHAR buffer[0x100];
3941 static const WCHAR szlnk[]={'.','l','n','k',0};
3943 rc = MSI_ViewFetch(view,&row);
3944 if (rc != ERROR_SUCCESS)
3951 MSI_RecordGetStringW(row,4,buffer,&sz);
3953 index = get_loaded_component(package,buffer);
3957 msiobj_release(&row->hdr);
3961 if (!package->components[index].Enabled ||
3962 !package->components[index].FeatureState)
3964 TRACE("Skipping shortcut creation due to disabled component\n");
3965 msiobj_release(&row->hdr);
3969 ui_actiondata(package,szCreateShortcuts,row);
3971 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3972 &IID_IShellLinkW, (LPVOID *) &sl );
3976 ERR("Is IID_IShellLink\n");
3977 msiobj_release(&row->hdr);
3981 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
3984 ERR("Is IID_IPersistFile\n");
3985 msiobj_release(&row->hdr);
3990 MSI_RecordGetStringW(row,2,buffer,&sz);
3991 resolve_folder(package, buffer,target_file,FALSE,FALSE,NULL);
3994 MSI_RecordGetStringW(row,3,buffer,&sz);
3995 reduce_to_longfilename(buffer);
3996 strcatW(target_file,buffer);
3997 if (!strchrW(target_file,'.'))
3998 strcatW(target_file,szlnk);
4001 MSI_RecordGetStringW(row,5,buffer,&sz);
4002 if (strchrW(buffer,'['))
4005 deformat_string(package,buffer,&deformated);
4006 IShellLinkW_SetPath(sl,deformated);
4007 HeapFree(GetProcessHeap(),0,deformated);
4011 FIXME("UNHANDLED shortcut format, advertised shortcut\n");
4012 IPersistFile_Release( pf );
4013 IShellLinkW_Release( sl );
4014 msiobj_release(&row->hdr);
4018 if (!MSI_RecordIsNull(row,6))
4022 MSI_RecordGetStringW(row,6,buffer,&sz);
4023 deformat_string(package,buffer,&deformated);
4024 IShellLinkW_SetArguments(sl,deformated);
4025 HeapFree(GetProcessHeap(),0,deformated);
4028 if (!MSI_RecordIsNull(row,7))
4031 deformated = load_dynamic_stringW(row,7);
4032 IShellLinkW_SetDescription(sl,deformated);
4033 HeapFree(GetProcessHeap(),0,deformated);
4036 if (!MSI_RecordIsNull(row,8))
4037 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
4039 if (!MSI_RecordIsNull(row,9))
4041 WCHAR Path[MAX_PATH];
4045 MSI_RecordGetStringW(row,9,buffer,&sz);
4047 build_icon_path(package,buffer,Path);
4048 index = MSI_RecordGetInteger(row,10);
4050 IShellLinkW_SetIconLocation(sl,Path,index);
4053 if (!MSI_RecordIsNull(row,11))
4054 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
4056 if (!MSI_RecordIsNull(row,12))
4058 WCHAR Path[MAX_PATH];
4061 MSI_RecordGetStringW(row,12,buffer,&sz);
4062 resolve_folder(package, buffer, Path, FALSE, FALSE, NULL);
4063 IShellLinkW_SetWorkingDirectory(sl,Path);
4066 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
4067 IPersistFile_Save(pf,target_file,FALSE);
4069 IPersistFile_Release( pf );
4070 IShellLinkW_Release( sl );
4072 msiobj_release(&row->hdr);
4074 MSI_ViewClose(view);
4075 msiobj_release(&view->hdr);
4085 * 99% of the work done here is only done for
4086 * advertised installs. However this is where the
4087 * Icon table is processed and written out
4088 * so that is waht I am going to do here.
4090 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
4094 MSIRECORD * row = 0;
4095 static const WCHAR Query[]={
4096 'S','E','L','E','C','T',' ','*',' ',
4097 'f','r','o','m',' ','I','c','o','n',0};
4101 return ERROR_INVALID_HANDLE;
4103 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4104 if (rc != ERROR_SUCCESS)
4107 rc = MSI_ViewExecute(view, 0);
4108 if (rc != ERROR_SUCCESS)
4110 MSI_ViewClose(view);
4111 msiobj_release(&view->hdr);
4118 WCHAR FilePath[MAX_PATH];
4119 WCHAR FileName[MAX_PATH];
4122 rc = MSI_ViewFetch(view,&row);
4123 if (rc != ERROR_SUCCESS)
4130 MSI_RecordGetStringW(row,1,FileName,&sz);
4133 ERR("Unable to get FileName\n");
4134 msiobj_release(&row->hdr);
4138 build_icon_path(package,FileName,FilePath);
4140 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
4142 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
4143 FILE_ATTRIBUTE_NORMAL, NULL);
4145 if (the_file == INVALID_HANDLE_VALUE)
4147 ERR("Unable to create file %s\n",debugstr_w(FilePath));
4148 msiobj_release(&row->hdr);
4156 rc = MSI_RecordReadStream(row,2,buffer,&sz);
4157 if (rc != ERROR_SUCCESS)
4159 ERR("Failed to get stream\n");
4160 CloseHandle(the_file);
4161 DeleteFileW(FilePath);
4164 WriteFile(the_file,buffer,sz,&write,NULL);
4165 } while (sz == 1024);
4167 CloseHandle(the_file);
4168 msiobj_release(&row->hdr);
4170 MSI_ViewClose(view);
4171 msiobj_release(&view->hdr);
4176 /* Msi functions that seem appropriate here */
4177 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
4182 TRACE(" exteral attempt at action %s\n",szAction);
4185 return ERROR_FUNCTION_FAILED;
4187 return ERROR_FUNCTION_FAILED;
4189 szwAction = strdupAtoW(szAction);
4192 return ERROR_FUNCTION_FAILED;
4195 rc = MsiDoActionW(hInstall, szwAction);
4196 HeapFree(GetProcessHeap(),0,szwAction);
4200 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
4202 MSIPACKAGE *package;
4203 UINT ret = ERROR_INVALID_HANDLE;
4205 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
4207 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4210 ret = ACTION_PerformAction(package,szAction);
4211 msiobj_release( &package->hdr );
4216 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
4217 LPSTR szPathBuf, DWORD* pcchPathBuf)
4223 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
4226 return ERROR_FUNCTION_FAILED;
4228 return ERROR_FUNCTION_FAILED;
4230 szwFolder = strdupAtoW(szFolder);
4233 return ERROR_FUNCTION_FAILED;
4235 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
4237 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
4239 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
4240 *pcchPathBuf, NULL, NULL );
4242 HeapFree(GetProcessHeap(),0,szwFolder);
4243 HeapFree(GetProcessHeap(),0,szwPathBuf);
4248 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
4249 szPathBuf, DWORD* pcchPathBuf)
4251 WCHAR path[MAX_PATH];
4253 MSIPACKAGE *package;
4255 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
4257 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4259 return ERROR_INVALID_HANDLE;
4260 rc = resolve_folder(package, szFolder, path, FALSE, FALSE, NULL);
4261 msiobj_release( &package->hdr );
4263 if (rc == ERROR_SUCCESS && strlenW(path) > *pcchPathBuf)
4265 *pcchPathBuf = strlenW(path)+1;
4266 return ERROR_MORE_DATA;
4268 else if (rc == ERROR_SUCCESS)
4270 *pcchPathBuf = strlenW(path)+1;
4271 strcpyW(szPathBuf,path);
4272 TRACE("Returning Path %s\n",debugstr_w(path));
4279 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
4280 LPSTR szPathBuf, DWORD* pcchPathBuf)
4286 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
4289 return ERROR_FUNCTION_FAILED;
4291 return ERROR_FUNCTION_FAILED;
4293 szwFolder = strdupAtoW(szFolder);
4295 return ERROR_FUNCTION_FAILED;
4297 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
4299 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
4301 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
4302 *pcchPathBuf, NULL, NULL );
4304 HeapFree(GetProcessHeap(),0,szwFolder);
4305 HeapFree(GetProcessHeap(),0,szwPathBuf);
4310 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
4311 szPathBuf, DWORD* pcchPathBuf)
4313 WCHAR path[MAX_PATH];
4315 MSIPACKAGE *package;
4317 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
4319 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4321 return ERROR_INVALID_HANDLE;
4322 rc = resolve_folder(package, szFolder, path, TRUE, FALSE, NULL);
4323 msiobj_release( &package->hdr );
4325 if (rc == ERROR_SUCCESS && strlenW(path) > *pcchPathBuf)
4327 *pcchPathBuf = strlenW(path)+1;
4328 return ERROR_MORE_DATA;
4330 else if (rc == ERROR_SUCCESS)
4332 *pcchPathBuf = strlenW(path)+1;
4333 strcpyW(szPathBuf,path);
4334 TRACE("Returning Path %s\n",debugstr_w(path));
4341 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
4342 LPCSTR szFolderPath)
4345 LPWSTR szwFolderPath;
4349 return ERROR_FUNCTION_FAILED;
4351 return ERROR_FUNCTION_FAILED;
4353 szwFolder = strdupAtoW(szFolder);
4355 return ERROR_FUNCTION_FAILED;
4357 szwFolderPath = strdupAtoW(szFolderPath);
4360 HeapFree(GetProcessHeap(),0,szwFolder);
4361 return ERROR_FUNCTION_FAILED;
4364 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
4366 HeapFree(GetProcessHeap(),0,szwFolder);
4367 HeapFree(GetProcessHeap(),0,szwFolderPath);
4372 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
4373 LPCWSTR szFolderPath)
4376 WCHAR path[MAX_PATH];
4379 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
4382 return ERROR_INVALID_HANDLE;
4384 if (szFolderPath[0]==0)
4385 return ERROR_FUNCTION_FAILED;
4387 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
4388 return ERROR_FUNCTION_FAILED;
4390 resolve_folder(package,szFolder,path,FALSE,FALSE,&folder);
4393 return ERROR_INVALID_PARAMETER;
4395 strcpyW(folder->Property,szFolderPath);
4397 for (i = 0; i < package->loaded_folders; i++)
4398 package->folders[i].ResolvedTarget[0]=0;
4400 for (i = 0; i < package->loaded_folders; i++)
4401 resolve_folder(package, package->folders[i].Directory, path, FALSE,
4404 return ERROR_SUCCESS;
4407 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
4408 LPCWSTR szFolderPath)
4410 MSIPACKAGE *package;
4413 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
4415 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4416 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
4417 msiobj_release( &package->hdr );
4421 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, DWORD iRunMode)
4423 FIXME("STUB (%li)\n",iRunMode);
4428 * according to the docs when this is called it immediently recalculates all the
4429 * components states as well
4431 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
4432 INSTALLSTATE iState)
4434 LPWSTR szwFeature = NULL;
4437 szwFeature = strdupAtoW(szFeature);
4440 return ERROR_FUNCTION_FAILED;
4442 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
4444 HeapFree(GetProcessHeap(),0,szwFeature);
4449 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
4450 INSTALLSTATE iState)
4452 MSIPACKAGE* package;
4455 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
4457 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4459 return ERROR_INVALID_HANDLE;
4461 index = get_loaded_feature(package,szFeature);
4463 return ERROR_UNKNOWN_FEATURE;
4465 package->features[index].State = iState;
4467 return ERROR_SUCCESS;
4470 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
4471 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4473 LPWSTR szwFeature = NULL;
4476 szwFeature = strdupAtoW(szFeature);
4478 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
4480 HeapFree( GetProcessHeap(), 0 , szwFeature);
4485 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
4486 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4490 index = get_loaded_feature(package,szFeature);
4492 return ERROR_UNKNOWN_FEATURE;
4495 *piInstalled = package->features[index].State;
4499 if (package->features[index].Enabled)
4500 *piAction = INSTALLSTATE_LOCAL;
4502 *piAction = INSTALLSTATE_UNKNOWN;
4505 return ERROR_SUCCESS;
4508 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
4509 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4511 MSIPACKAGE* package;
4514 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
4517 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4519 return ERROR_INVALID_HANDLE;
4520 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
4521 msiobj_release( &package->hdr );
4525 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
4526 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4528 LPWSTR szwComponent= NULL;
4531 szwComponent= strdupAtoW(szComponent);
4533 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
4535 HeapFree( GetProcessHeap(), 0 , szwComponent);
4540 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
4541 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4545 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
4548 index = get_loaded_component(package,szComponent);
4550 return ERROR_UNKNOWN_COMPONENT;
4553 *piInstalled = package->components[index].State;
4557 if (package->components[index].Enabled &&
4558 package->components[index].FeatureState)
4559 *piAction = INSTALLSTATE_LOCAL;
4561 *piAction = INSTALLSTATE_UNKNOWN;
4564 return ERROR_SUCCESS;
4567 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
4568 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4570 MSIPACKAGE* package;
4573 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
4574 piInstalled, piAction);
4576 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4578 return ERROR_INVALID_HANDLE;
4579 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
4580 msiobj_release( &package->hdr );
4585 static UINT ACTION_Template(MSIPACKAGE *package)
4589 MSIRECORD * row = 0;
4590 static const WCHAR ExecSeqQuery[] = {0};
4592 rc = MsiDatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4593 if (rc != ERROR_SUCCESS)
4596 rc = MsiViewExecute(view, 0);
4597 if (rc != ERROR_SUCCESS)
4600 msiobj_release(&view->hdr);
4606 rc = MsiViewFetch(view,&row);
4607 if (rc != ERROR_SUCCESS)
4613 msiobj_release(&row->hdr);
4616 msiobj_release(&view->hdr);