2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installexecutesequence_table.asp
26 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/standard_actions_reference.asp
38 #include "wine/debug.h"
42 #include "msvcrt/fcntl.h"
49 #include "wine/unicode.h"
52 #define CUSTOM_ACTION_TYPE_MASK 0x3F
54 WINE_DEFAULT_DEBUG_CHANNEL(msi);
56 typedef struct tagMSIFEATURE
59 WCHAR Feature_Parent[96];
61 WCHAR Description[0x100];
70 INT Components[1024]; /* yes hardcoded limit.... I am bad */
74 typedef struct tagMSICOMPONENT
77 WCHAR ComponentId[96];
80 WCHAR Condition[0x100];
89 typedef struct tagMSIFOLDER
92 WCHAR TargetDefault[96];
93 WCHAR SourceDefault[96];
95 WCHAR ResolvedTarget[MAX_PATH];
96 WCHAR ResolvedSource[MAX_PATH];
97 WCHAR Property[MAX_PATH]; /* initially set property */
100 /* 0 = uninitialized */
102 /* 2 = created remove if empty */
103 /* 3 = created persist if empty */
108 typedef struct tagMSIFILE
112 WCHAR FileName[MAX_PATH];
120 /* 0 = uninitialize */
121 /* 1 = not present */
122 /* 2 = present but replace */
123 /* 3 = present do not replace */
125 WCHAR SourcePath[MAX_PATH];
126 WCHAR TargetPath[MAX_PATH];
133 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran);
134 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package);
136 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action);
138 static UINT ACTION_LaunchConditions(MSIPACKAGE *package);
139 static UINT ACTION_CostInitialize(MSIPACKAGE *package);
140 static UINT ACTION_CreateFolders(MSIPACKAGE *package);
141 static UINT ACTION_CostFinalize(MSIPACKAGE *package);
142 static UINT ACTION_FileCost(MSIPACKAGE *package);
143 static UINT ACTION_InstallFiles(MSIPACKAGE *package);
144 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package);
145 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package);
146 static UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action);
147 static UINT ACTION_InstallInitialize(MSIPACKAGE *package);
148 static UINT ACTION_InstallValidate(MSIPACKAGE *package);
149 static UINT ACTION_ProcessComponents(MSIPACKAGE *package);
150 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package);
151 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package);
152 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package);
153 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package);
154 static UINT ACTION_PublishProduct(MSIPACKAGE *package);
156 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
157 const LPWSTR target, const INT type);
158 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
159 const LPWSTR target, const INT type);
161 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data);
162 static UINT resolve_folder(MSIPACKAGE *package, LPCWSTR name, LPWSTR path,
163 BOOL source, BOOL set_prop, MSIFOLDER **folder);
165 static int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path);
168 * consts and values used
170 static const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
171 static const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
172 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
173 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
174 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
175 static const WCHAR c_collen[] = {'C',':','\\',0};
177 static const WCHAR cszlsb[]={'[',0};
178 static const WCHAR cszrsb[]={']',0};
179 static const WCHAR cszbs[]={'\\',0};
181 const static WCHAR szCreateFolders[] =
182 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
183 const static WCHAR szCostFinalize[] =
184 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
185 const static WCHAR szInstallFiles[] =
186 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
187 const static WCHAR szDuplicateFiles[] =
188 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
189 const static WCHAR szWriteRegistryValues[] =
190 {'W','r','i','t','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
191 const static WCHAR szCostInitialize[] =
192 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
193 const static WCHAR szFileCost[] = {'F','i','l','e','C','o','s','t',0};
194 const static WCHAR szInstallInitialize[] =
195 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
196 const static WCHAR szInstallValidate[] =
197 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
198 const static WCHAR szLaunchConditions[] =
199 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
200 const static WCHAR szProcessComponents[] =
201 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
202 const static WCHAR szRegisterTypeLibraries[] =
203 {'R','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r',
205 const static WCHAR szRegisterClassInfo[] =
206 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
207 const static WCHAR szRegisterProgIdInfo[] =
208 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
209 const static WCHAR szCreateShortcuts[] =
210 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
211 const static WCHAR szPublishProduct[] =
212 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
214 /********************************************************
215 * helper functions to get around current HACKS and such
216 ********************************************************/
217 inline static void reduce_to_longfilename(WCHAR* filename)
219 if (strchrW(filename,'|'))
221 WCHAR newname[MAX_PATH];
222 strcpyW(newname,strchrW(filename,'|')+1);
223 strcpyW(filename,newname);
227 inline static char *strdupWtoA( const WCHAR *str )
232 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL
234 if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
235 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
240 inline static WCHAR *strdupAtoW( const char *str )
245 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
246 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
247 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
252 inline static WCHAR *load_dynamic_stringW(MSIRECORD *row, INT index)
259 rc = MSI_RecordGetStringW(row,index,NULL,&sz);
264 ret = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
265 rc = MSI_RecordGetStringW(row,index,ret,&sz);
269 inline static int get_loaded_component(MSIPACKAGE* package, LPCWSTR Component )
274 for (i = 0; i < package->loaded_components; i++)
276 if (strcmpW(Component,package->components[i].Component)==0)
285 inline static int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
290 for (i = 0; i < package->loaded_features; i++)
292 if (strcmpW(Feature,package->features[i].Feature)==0)
301 inline static int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
306 for (i = 0; i < package->loaded_files; i++)
308 if (strcmpW(file,package->files[i].File)==0)
317 static int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
325 for (i=0; i < package->loaded_files; i++)
326 if (strcmpW(package->files[i].File,name)==0)
329 index = package->loaded_files;
330 package->loaded_files++;
331 if (package->loaded_files== 1)
332 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
334 package->files = HeapReAlloc(GetProcessHeap(),0,
335 package->files , package->loaded_files * sizeof(MSIFILE));
337 memset(&package->files[index],0,sizeof(MSIFILE));
339 strcpyW(package->files[index].File,name);
340 strcpyW(package->files[index].TargetPath,path);
341 package->files[index].Temporary = TRUE;
343 TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
348 void ACTION_remove_tracked_tempfiles(MSIPACKAGE* package)
355 for (i = 0; i < package->loaded_files; i++)
357 if (package->files[i].Temporary)
358 DeleteFileW(package->files[i].TargetPath);
363 static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
367 row = MSI_CreateRecord(4);
368 MSI_RecordSetInteger(row,1,a);
369 MSI_RecordSetInteger(row,2,b);
370 MSI_RecordSetInteger(row,3,c);
371 MSI_RecordSetInteger(row,4,d);
372 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
373 msiobj_release(&row->hdr);
376 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
378 static const WCHAR Query_t[] =
379 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
380 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
381 ' ','\'','%','s','\'',0};
386 static WCHAR *ActionFormat=NULL;
387 static WCHAR LastAction[0x100] = {0};
391 if (strcmpW(LastAction,action)!=0)
393 sprintfW(Query,Query_t,action);
394 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
395 if (rc != ERROR_SUCCESS)
397 rc = MSI_ViewExecute(view, 0);
398 if (rc != ERROR_SUCCESS)
403 rc = MSI_ViewFetch(view,&row);
404 if (rc != ERROR_SUCCESS)
410 if (MSI_RecordIsNull(row,3))
412 msiobj_release(&row->hdr);
414 msiobj_release(&view->hdr);
419 HeapFree(GetProcessHeap(),0,ActionFormat);
421 ActionFormat = load_dynamic_stringW(row,3);
422 strcpyW(LastAction,action);
423 msiobj_release(&row->hdr);
425 msiobj_release(&view->hdr);
437 ptr2 = strchrW(ptr,'[');
440 strncpyW(tmp,ptr,ptr2-ptr);
442 strcatW(message,tmp);
445 data = load_dynamic_stringW(record,field);
448 strcatW(message,data);
449 HeapFree(GetProcessHeap(),0,data);
451 ptr=strchrW(ptr2,']');
456 strcatW(message,ptr);
461 row = MSI_CreateRecord(1);
462 MSI_RecordSetStringW(row,1,message);
464 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
465 msiobj_release(&row->hdr);
469 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
471 static const WCHAR template_s[]=
472 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ','%','s','.',0};
473 static const WCHAR format[] =
474 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
475 static const WCHAR Query_t[] =
476 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
477 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
478 ' ','\'','%','s','\'',0};
484 WCHAR *ActionText=NULL;
487 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
489 sprintfW(Query,Query_t,action);
490 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
491 if (rc != ERROR_SUCCESS)
493 rc = MSI_ViewExecute(view, 0);
494 if (rc != ERROR_SUCCESS)
497 msiobj_release(&view->hdr);
500 rc = MSI_ViewFetch(view,&row);
501 if (rc != ERROR_SUCCESS)
504 msiobj_release(&view->hdr);
508 ActionText = load_dynamic_stringW(row,2);
509 msiobj_release(&row->hdr);
511 msiobj_release(&view->hdr);
513 sprintfW(message,template_s,timet,action,ActionText);
515 row = MSI_CreateRecord(1);
516 MSI_RecordSetStringW(row,1,message);
518 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
519 msiobj_release(&row->hdr);
520 HeapFree(GetProcessHeap(),0,ActionText);
523 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
527 static const WCHAR template_s[]=
528 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ','%','s',
530 static const WCHAR template_e[]=
531 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ','%','s',
532 '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ','%','i','.',0};
533 static const WCHAR format[] =
534 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
538 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
540 sprintfW(message,template_s,timet,action);
542 sprintfW(message,template_e,timet,action,rc);
544 row = MSI_CreateRecord(1);
545 MSI_RecordSetStringW(row,1,message);
547 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
548 msiobj_release(&row->hdr);
551 /****************************************************
552 * TOP level entry points
553 *****************************************************/
555 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
556 LPCWSTR szCommandLine)
561 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
566 WCHAR check[MAX_PATH];
570 strcpyW(pth,szPackagePath);
571 p = strrchrW(pth,'\\');
579 if (MSI_GetPropertyW(package,cszSourceDir,check,&size)
581 MSI_SetPropertyW(package, cszSourceDir, pth);
587 ptr = (LPWSTR)szCommandLine;
594 TRACE("Looking at %s\n",debugstr_w(ptr));
596 ptr2 = strchrW(ptr,'=');
602 while (*ptr == ' ') ptr++;
603 strncpyW(prop,ptr,ptr2-ptr);
608 while (*ptr && (quote || (!quote && *ptr!=' ')))
621 strncpyW(val,ptr2,len);
624 if (strlenW(prop) > 0)
626 TRACE("Found commandline property (%s) = (%s)\n", debugstr_w(prop), debugstr_w(val));
627 MSI_SetPropertyW(package,prop,val);
635 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
637 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
639 rc = ACTION_ProcessUISequence(package);
640 if (rc == ERROR_SUCCESS)
641 rc = ACTION_ProcessExecSequence(package,TRUE);
644 rc = ACTION_ProcessExecSequence(package,FALSE);
647 rc = ACTION_ProcessExecSequence(package,FALSE);
653 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
657 static const WCHAR ExecSeqQuery[] = {
658 's','e','l','e','c','t',' ','*',' ',
660 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
661 'S','e','q','u','e','n','c','e',' ',
662 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
663 '>',' ','%','i',' ','o','r','d','e','r',' ',
664 'b','y',' ','S','e','q','u','e','n','c','e',0 };
667 static const WCHAR IVQuery[] = {
668 's','e','l','e','c','t',' ','S','e','q','u','e','n','c','e',' ',
669 'f','r','o','m',' ','I','n','s','t','a','l','l',
670 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
671 'w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',' ',
672 '`','I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`',
679 rc = MSI_DatabaseOpenViewW(package->db, IVQuery, &view);
680 if (rc != ERROR_SUCCESS)
682 rc = MSI_ViewExecute(view, 0);
683 if (rc != ERROR_SUCCESS)
686 msiobj_release(&view->hdr);
689 rc = MSI_ViewFetch(view,&row);
690 if (rc != ERROR_SUCCESS)
693 msiobj_release(&view->hdr);
696 seq = MSI_RecordGetInteger(row,1);
697 msiobj_release(&row->hdr);
699 msiobj_release(&view->hdr);
700 sprintfW(Query,ExecSeqQuery,seq);
703 sprintfW(Query,ExecSeqQuery,0);
705 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
706 if (rc == ERROR_SUCCESS)
708 rc = MSI_ViewExecute(view, 0);
710 if (rc != ERROR_SUCCESS)
713 msiobj_release(&view->hdr);
717 TRACE("Running the actions \n");
724 rc = MSI_ViewFetch(view,&row);
725 if (rc != ERROR_SUCCESS)
731 /* check conditions */
732 if (!MSI_RecordIsNull(row,2))
735 cond = load_dynamic_stringW(row,2);
739 /* this is a hack to skip errors in the condition code */
740 if (MSI_EvaluateConditionW(package, cond) ==
743 HeapFree(GetProcessHeap(),0,cond);
744 msiobj_release(&row->hdr);
748 HeapFree(GetProcessHeap(),0,cond);
753 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
754 if (rc != ERROR_SUCCESS)
756 ERR("Error is %x\n",rc);
757 msiobj_release(&row->hdr);
761 rc = ACTION_PerformAction(package,buffer);
763 if (rc != ERROR_SUCCESS)
765 ERR("Execution halted due to error (%i)\n",rc);
766 msiobj_release(&row->hdr);
770 msiobj_release(&row->hdr);
774 msiobj_release(&view->hdr);
782 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
786 static const WCHAR ExecSeqQuery [] = {
787 's','e','l','e','c','t',' ','*',' ',
788 'f','r','o','m',' ','I','n','s','t','a','l','l',
789 'U','I','S','e','q','u','e','n','c','e',' ',
790 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ', '>',' ','0',' ',
791 'o','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e',0};
793 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
795 if (rc == ERROR_SUCCESS)
797 rc = MSI_ViewExecute(view, 0);
799 if (rc != ERROR_SUCCESS)
802 msiobj_release(&view->hdr);
806 TRACE("Running the actions \n");
814 rc = MSI_ViewFetch(view,&row);
815 if (rc != ERROR_SUCCESS)
821 /* check conditions */
822 if (!MSI_RecordIsNull(row,2))
825 cond = load_dynamic_stringW(row,2);
829 /* this is a hack to skip errors in the condition code */
830 if (MSI_EvaluateConditionW(package, cond) ==
833 HeapFree(GetProcessHeap(),0,cond);
834 msiobj_release(&row->hdr);
838 HeapFree(GetProcessHeap(),0,cond);
843 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
844 if (rc != ERROR_SUCCESS)
846 ERR("Error is %x\n",rc);
847 msiobj_release(&row->hdr);
851 rc = ACTION_PerformAction(package,buffer);
853 if (rc != ERROR_SUCCESS)
855 ERR("Execution halted due to error (%i)\n",rc);
856 msiobj_release(&row->hdr);
860 msiobj_release(&row->hdr);
864 msiobj_release(&view->hdr);
871 /********************************************************
872 * ACTION helper functions and functions that perform the actions
873 *******************************************************/
876 * Alot of actions are really important even if they don't do anything
877 * explicit.. Lots of properties are set at the beginning of the installation
878 * CostFinalize does a bunch of work to translated the directories and such
880 * But until I get write access to the database that is hard, so I am going to
881 * hack it to see if I can get something to run.
883 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action)
885 UINT rc = ERROR_SUCCESS;
887 TRACE("Performing action (%s)\n",debugstr_w(action));
888 ui_actioninfo(package, action, TRUE, 0);
889 ui_actionstart(package, action);
890 ui_progress(package,2,1,0,0);
892 /* pre install, setup and configuration block */
893 if (strcmpW(action,szLaunchConditions)==0)
894 rc = ACTION_LaunchConditions(package);
895 else if (strcmpW(action,szCostInitialize)==0)
896 rc = ACTION_CostInitialize(package);
897 else if (strcmpW(action,szFileCost)==0)
898 rc = ACTION_FileCost(package);
899 else if (strcmpW(action,szCostFinalize)==0)
900 rc = ACTION_CostFinalize(package);
901 else if (strcmpW(action,szInstallValidate)==0)
902 rc = ACTION_InstallValidate(package);
905 else if (strcmpW(action,szProcessComponents)==0)
906 rc = ACTION_ProcessComponents(package);
907 else if (strcmpW(action,szInstallInitialize)==0)
908 rc = ACTION_InstallInitialize(package);
909 else if (strcmpW(action,szCreateFolders)==0)
910 rc = ACTION_CreateFolders(package);
911 else if (strcmpW(action,szInstallFiles)==0)
912 rc = ACTION_InstallFiles(package);
913 else if (strcmpW(action,szDuplicateFiles)==0)
914 rc = ACTION_DuplicateFiles(package);
915 else if (strcmpW(action,szWriteRegistryValues)==0)
916 rc = ACTION_WriteRegistryValues(package);
917 else if (strcmpW(action,szRegisterTypeLibraries)==0)
918 rc = ACTION_RegisterTypeLibraries(package);
919 else if (strcmpW(action,szRegisterClassInfo)==0)
920 rc = ACTION_RegisterClassInfo(package);
921 else if (strcmpW(action,szRegisterProgIdInfo)==0)
922 rc = ACTION_RegisterProgIdInfo(package);
923 else if (strcmpW(action,szCreateShortcuts)==0)
924 rc = ACTION_CreateShortcuts(package);
925 else if (strcmpW(action,szPublishProduct)==0)
926 rc = ACTION_PublishProduct(package);
929 Called during iTunes but unimplemented and seem important
931 ResolveSource (sets SourceDir)
935 else if ((rc = ACTION_CustomAction(package,action)) != ERROR_SUCCESS)
937 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
941 ui_actioninfo(package, action, FALSE, rc);
946 static UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action)
948 UINT rc = ERROR_SUCCESS;
951 WCHAR ExecSeqQuery[1024] =
952 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','C','u','s','t','o'
953 ,'m','A','c','t','i','o','n',' ','w','h','e','r','e',' ','`','A','c','t','i'
954 ,'o','n','`',' ','=',' ','`',0};
955 static const WCHAR end[]={'`',0};
959 WCHAR *deformated=NULL;
961 strcatW(ExecSeqQuery,action);
962 strcatW(ExecSeqQuery,end);
964 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
966 if (rc != ERROR_SUCCESS)
969 rc = MSI_ViewExecute(view, 0);
970 if (rc != ERROR_SUCCESS)
973 msiobj_release(&view->hdr);
977 rc = MSI_ViewFetch(view,&row);
978 if (rc != ERROR_SUCCESS)
981 msiobj_release(&view->hdr);
985 type = MSI_RecordGetInteger(row,2);
987 source = load_dynamic_stringW(row,3);
988 target = load_dynamic_stringW(row,4);
990 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
991 debugstr_w(source), debugstr_w(target));
993 /* we are ignoring ALOT of flags and important synchronization stuff */
994 switch (type & CUSTOM_ACTION_TYPE_MASK)
996 case 1: /* DLL file stored in a Binary table stream */
997 rc = HANDLE_CustomType1(package,source,target,type);
999 case 2: /* EXE file stored in a Binary table strem */
1000 rc = HANDLE_CustomType2(package,source,target,type);
1002 case 35: /* Directory set with formatted text. */
1003 case 51: /* Property set with formatted text. */
1004 deformat_string(package,target,&deformated);
1005 rc = MSI_SetPropertyW(package,source,deformated);
1006 HeapFree(GetProcessHeap(),0,deformated);
1009 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
1010 type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
1011 debugstr_w(target));
1014 HeapFree(GetProcessHeap(),0,source);
1015 HeapFree(GetProcessHeap(),0,target);
1016 msiobj_release(&row->hdr);
1017 MSI_ViewClose(view);
1018 msiobj_release(&view->hdr);
1022 static UINT store_binary_to_temp(MSIPACKAGE *package, const LPWSTR source,
1027 if (MSI_GetPropertyW(package, cszTempFolder, tmp_file, &sz)
1029 GetTempPathW(MAX_PATH,tmp_file);
1031 strcatW(tmp_file,source);
1033 if (GetFileAttributesW(tmp_file) != INVALID_FILE_ATTRIBUTES)
1035 TRACE("File already exists\n");
1036 return ERROR_SUCCESS;
1040 /* write out the file */
1043 MSIRECORD * row = 0;
1045 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','B','i'
1046 ,'n','a','r','y',' ','w','h','e','r','e',' ','N','a','m','e','=','`',0};
1047 static const WCHAR end[]={'`',0};
1051 if (track_tempfile(package, source, tmp_file)!=0)
1052 FIXME("File Name in temp tracking collision\n");
1054 the_file = CreateFileW(tmp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1055 FILE_ATTRIBUTE_NORMAL, NULL);
1057 if (the_file == INVALID_HANDLE_VALUE)
1058 return ERROR_FUNCTION_FAILED;
1060 strcatW(Query,source);
1063 rc = MSI_DatabaseOpenViewW( package->db, Query, &view);
1064 if (rc != ERROR_SUCCESS)
1067 rc = MSI_ViewExecute(view, 0);
1068 if (rc != ERROR_SUCCESS)
1070 MSI_ViewClose(view);
1071 msiobj_release(&view->hdr);
1075 rc = MSI_ViewFetch(view,&row);
1076 if (rc != ERROR_SUCCESS)
1078 MSI_ViewClose(view);
1079 msiobj_release(&view->hdr);
1087 rc = MSI_RecordReadStream(row,2,buffer,&sz);
1088 if (rc != ERROR_SUCCESS)
1090 ERR("Failed to get stream\n");
1091 CloseHandle(the_file);
1092 DeleteFileW(tmp_file);
1095 WriteFile(the_file,buffer,sz,&write,NULL);
1096 } while (sz == 1024);
1098 CloseHandle(the_file);
1100 msiobj_release(&row->hdr);
1101 MSI_ViewClose(view);
1102 msiobj_release(&view->hdr);
1105 return ERROR_SUCCESS;
1109 typedef UINT __stdcall CustomEntry(MSIHANDLE);
1112 MSIPACKAGE *package;
1113 WCHAR target[MAX_PATH];
1114 WCHAR source[MAX_PATH];
1118 static DWORD WINAPI DllThread(LPVOID info)
1122 thread_struct *stuff;
1125 stuff = (thread_struct*)info;
1127 TRACE("Asynchronous start (%s, %s) \n", debugstr_w(stuff->source),
1128 debugstr_w(stuff->target));
1130 DLL = LoadLibraryW(stuff->source);
1133 proc = strdupWtoA( stuff->target );
1134 fn = (CustomEntry*)GetProcAddress(DLL,proc);
1138 MSIPACKAGE *package = stuff->package;
1140 TRACE("Calling function\n");
1141 hPackage = msiobj_findhandle( &package->hdr );
1143 ERR("Handle for object %p not found\n", package );
1145 msiobj_release( &package->hdr );
1148 ERR("Cannot load functon\n");
1150 HeapFree(GetProcessHeap(),0,proc);
1154 ERR("Unable to load library\n");
1155 msiobj_release( &stuff->package->hdr );
1156 HeapFree( GetProcessHeap(), 0, info );
1161 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
1162 const LPWSTR target, const INT type)
1164 WCHAR tmp_file[MAX_PATH];
1169 store_binary_to_temp(package, source, tmp_file);
1171 TRACE("Calling function %s from %s\n",debugstr_w(target),
1172 debugstr_w(tmp_file));
1174 if (!strchrW(tmp_file,'.'))
1176 static const WCHAR dot[]={'.',0};
1177 strcatW(tmp_file,dot);
1182 /* DWORD ThreadId; */
1183 thread_struct *info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) );
1185 /* msiobj_addref( &package->hdr ); */
1186 info->package = package;
1187 strcpyW(info->target,target);
1188 strcpyW(info->source,tmp_file);
1189 TRACE("Start Asynchronous execution\n");
1190 FIXME("DATABASE NOT THREADSAFE... not starting\n");
1191 /* CreateThread(NULL,0,DllThread,(LPVOID)&info,0,&ThreadId); */
1192 /* FIXME: release the package if the CreateThread fails */
1193 HeapFree( GetProcessHeap(), 0, info );
1194 return ERROR_SUCCESS;
1197 DLL = LoadLibraryW(tmp_file);
1200 proc = strdupWtoA( target );
1201 fn = (CustomEntry*)GetProcAddress(DLL,proc);
1206 TRACE("Calling function\n");
1207 hPackage = msiobj_findhandle( &package->hdr );
1209 ERR("Handle for object %p not found\n", package );
1211 msiobj_release( &package->hdr );
1214 ERR("Cannot load functon\n");
1216 HeapFree(GetProcessHeap(),0,proc);
1220 ERR("Unable to load library\n");
1222 return ERROR_SUCCESS;
1225 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
1226 const LPWSTR target, const INT type)
1228 WCHAR tmp_file[MAX_PATH*2];
1230 PROCESS_INFORMATION info;
1233 static const WCHAR spc[] = {' ',0};
1235 memset(&si,0,sizeof(STARTUPINFOW));
1236 memset(&info,0,sizeof(PROCESS_INFORMATION));
1238 store_binary_to_temp(package, source, tmp_file);
1240 strcatW(tmp_file,spc);
1241 deformat_string(package,target,&deformated);
1242 strcatW(tmp_file,deformated);
1244 HeapFree(GetProcessHeap(),0,deformated);
1246 TRACE("executing exe %s \n",debugstr_w(tmp_file));
1248 rc = CreateProcessW(NULL, tmp_file, NULL, NULL, FALSE, 0, NULL,
1249 c_collen, &si, &info);
1253 ERR("Unable to execute command\n");
1254 return ERROR_SUCCESS;
1258 WaitForSingleObject(info.hProcess,INFINITE);
1260 return ERROR_SUCCESS;
1263 /***********************************************************************
1266 * Recursively create all directories in the path.
1268 * shamelessly stolen from setupapi/queue.c
1270 static BOOL create_full_pathW(const WCHAR *path)
1276 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1278 strcpyW(new_path, path);
1280 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1281 new_path[len - 1] = 0;
1283 while(!CreateDirectoryW(new_path, NULL))
1286 DWORD last_error = GetLastError();
1287 if(last_error == ERROR_ALREADY_EXISTS)
1290 if(last_error != ERROR_PATH_NOT_FOUND)
1296 if(!(slash = strrchrW(new_path, '\\')))
1302 len = slash - new_path;
1304 if(!create_full_pathW(new_path))
1309 new_path[len] = '\\';
1312 HeapFree(GetProcessHeap(), 0, new_path);
1317 * Also we cannot enable/disable components either, so for now I am just going
1318 * to do all the directories for all the components.
1320 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1322 static const WCHAR ExecSeqQuery[] = {
1323 's','e','l','e','c','t',' ','D','i','r','e','c','t','o','r','y','_',' ',
1324 'f','r','o','m',' ','C','r','e','a','t','e','F','o','l','d','e','r',0 };
1329 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1330 if (rc != ERROR_SUCCESS)
1331 return ERROR_SUCCESS;
1333 rc = MSI_ViewExecute(view, 0);
1334 if (rc != ERROR_SUCCESS)
1336 MSI_ViewClose(view);
1337 msiobj_release(&view->hdr);
1344 WCHAR full_path[MAX_PATH];
1346 MSIRECORD *row = NULL, *uirow;
1348 rc = MSI_ViewFetch(view,&row);
1349 if (rc != ERROR_SUCCESS)
1356 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1358 if (rc!= ERROR_SUCCESS)
1360 ERR("Unable to get folder id \n");
1361 msiobj_release(&row->hdr);
1366 rc = resolve_folder(package,dir,full_path,FALSE,FALSE,&folder);
1368 if (rc != ERROR_SUCCESS)
1370 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1371 msiobj_release(&row->hdr);
1375 TRACE("Folder is %s\n",debugstr_w(full_path));
1378 uirow = MSI_CreateRecord(1);
1379 MSI_RecordSetStringW(uirow,1,full_path);
1380 ui_actiondata(package,szCreateFolders,uirow);
1381 msiobj_release( &uirow->hdr );
1383 if (folder->State == 0)
1384 create_full_pathW(full_path);
1388 msiobj_release(&row->hdr);
1390 MSI_ViewClose(view);
1391 msiobj_release(&view->hdr);
1396 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1398 int index = package->loaded_components;
1401 /* fill in the data */
1403 package->loaded_components++;
1404 if (package->loaded_components == 1)
1405 package->components = HeapAlloc(GetProcessHeap(),0,
1406 sizeof(MSICOMPONENT));
1408 package->components = HeapReAlloc(GetProcessHeap(),0,
1409 package->components, package->loaded_components *
1410 sizeof(MSICOMPONENT));
1412 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1415 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1417 TRACE("Loading Component %s\n",
1418 debugstr_w(package->components[index].Component));
1421 if (!MSI_RecordIsNull(row,2))
1422 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1425 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1427 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1430 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1433 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1435 package->components[index].State = INSTALLSTATE_UNKNOWN;
1436 package->components[index].Enabled = TRUE;
1437 package->components[index].FeatureState= FALSE;
1442 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1444 int index = package->loaded_features;
1446 static const WCHAR Query1[] = {'S','E','L','E','C','T',' ','C','o','m','p',
1447 'o','n','e','n','t','_',' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1448 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ','F','e',
1449 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1450 static const WCHAR Query2[] = {'S','E','L','E','C','T',' ','*',' ','F','R',
1451 'O','M',' ','C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ','C',
1452 'o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1460 /* fill in the data */
1462 package->loaded_features ++;
1463 if (package->loaded_features == 1)
1464 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1466 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1467 package->loaded_features * sizeof(MSIFEATURE));
1469 memset(&package->features[index],0,sizeof(MSIFEATURE));
1472 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1474 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1477 if (!MSI_RecordIsNull(row,2))
1478 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1481 if (!MSI_RecordIsNull(row,3))
1482 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1485 if (!MSI_RecordIsNull(row,4))
1486 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1488 if (!MSI_RecordIsNull(row,5))
1489 package->features[index].Display = MSI_RecordGetInteger(row,5);
1491 package->features[index].Level= MSI_RecordGetInteger(row,6);
1494 if (!MSI_RecordIsNull(row,7))
1495 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1497 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1498 package->features[index].State = INSTALLSTATE_UNKNOWN;
1500 /* load feature components */
1502 sprintfW(Query,Query1,package->features[index].Feature);
1503 rc = MSI_DatabaseOpenViewW(package->db,Query,&view);
1504 if (rc != ERROR_SUCCESS)
1506 rc = MSI_ViewExecute(view,0);
1507 if (rc != ERROR_SUCCESS)
1509 MSI_ViewClose(view);
1510 msiobj_release(&view->hdr);
1516 WCHAR buffer[0x100];
1519 INT cnt = package->features[index].ComponentCount;
1521 rc = MSI_ViewFetch(view,&row2);
1522 if (rc != ERROR_SUCCESS)
1526 MSI_RecordGetStringW(row2,1,buffer,&sz);
1528 /* check to see if the component is already loaded */
1529 c_indx = get_loaded_component(package,buffer);
1532 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1534 package->features[index].Components[cnt] = c_indx;
1535 package->features[index].ComponentCount ++;
1538 sprintfW(Query,Query2,buffer);
1540 rc = MSI_DatabaseOpenViewW(package->db,Query,&view2);
1541 if (rc != ERROR_SUCCESS)
1543 msiobj_release( &row2->hdr );
1546 rc = MSI_ViewExecute(view2,0);
1547 if (rc != ERROR_SUCCESS)
1549 msiobj_release( &row2->hdr );
1550 MSI_ViewClose(view2);
1551 msiobj_release( &view2->hdr );
1558 rc = MSI_ViewFetch(view2,&row3);
1559 if (rc != ERROR_SUCCESS)
1561 c_indx = load_component(package,row3);
1562 msiobj_release( &row3->hdr );
1564 package->features[index].Components[cnt] = c_indx;
1565 package->features[index].ComponentCount ++;
1567 MSI_ViewClose(view2);
1568 msiobj_release( &view2->hdr );
1569 msiobj_release( &row2->hdr );
1571 MSI_ViewClose(view);
1572 msiobj_release(&view->hdr);
1576 * I am not doing any of the costing functionality yet.
1577 * Mostly looking at doing the Component and Feature loading
1579 * The native MSI does ALOT of modification to tables here. Mostly adding alot
1580 * of temporary columns to the Feature and Component tables.
1582 * note: native msi also tracks the short filename. but I am only going to
1583 * track the long ones. Also looking at this directory table
1584 * it appears that the directory table does not get the parents
1585 * resolved base on property only based on their entrys in the
1588 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1594 static const WCHAR Query_all[] = {
1595 'S','E','L','E','C','T',' ','*',' ',
1596 'F','R','O','M',' ','F','e','a','t','u','r','e',0};
1597 static const WCHAR szCosting[] = {
1598 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1599 static const WCHAR szZero[] = { '0', 0 };
1601 MSI_SetPropertyW(package, szCosting, szZero);
1602 MSI_SetPropertyW(package, cszRootDrive , c_collen);
1605 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1606 if (rc != ERROR_SUCCESS)
1608 rc = MSI_ViewExecute(view,0);
1609 if (rc != ERROR_SUCCESS)
1611 MSI_ViewClose(view);
1612 msiobj_release(&view->hdr);
1619 rc = MSI_ViewFetch(view,&row);
1620 if (rc != ERROR_SUCCESS)
1623 load_feature(package,row);
1624 msiobj_release(&row->hdr);
1626 MSI_ViewClose(view);
1627 msiobj_release(&view->hdr);
1629 return ERROR_SUCCESS;
1632 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1634 DWORD index = package->loaded_files;
1636 WCHAR buffer[0x100];
1639 /* fill in the data */
1641 package->loaded_files++;
1642 if (package->loaded_files== 1)
1643 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1645 package->files = HeapReAlloc(GetProcessHeap(),0,
1646 package->files , package->loaded_files * sizeof(MSIFILE));
1648 memset(&package->files[index],0,sizeof(MSIFILE));
1651 MSI_RecordGetStringW(row,1,package->files[index].File,&sz);
1654 MSI_RecordGetStringW(row,2,buffer,&sz);
1656 package->files[index].ComponentIndex = -1;
1657 for (i = 0; i < package->loaded_components; i++)
1658 if (strcmpW(package->components[i].Component,buffer)==0)
1660 package->files[index].ComponentIndex = i;
1663 if (package->files[index].ComponentIndex == -1)
1664 ERR("Unfound Component %s\n",debugstr_w(buffer));
1667 MSI_RecordGetStringW(row,3,package->files[index].FileName,&sz);
1669 reduce_to_longfilename(package->files[index].FileName);
1671 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1674 if (!MSI_RecordIsNull(row,5))
1675 MSI_RecordGetStringW(row,5,package->files[index].Version,&sz);
1678 if (!MSI_RecordIsNull(row,6))
1679 MSI_RecordGetStringW(row,6,package->files[index].Language,&sz);
1681 if (!MSI_RecordIsNull(row,7))
1682 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1684 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1686 package->files[index].Temporary = FALSE;
1687 package->files[index].State = 0;
1689 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1691 return ERROR_SUCCESS;
1694 static UINT ACTION_FileCost(MSIPACKAGE *package)
1699 static const WCHAR Query[] = {
1700 'S','E','L','E','C','T',' ','*',' ',
1701 'F','R','O','M',' ','F','i','l','e',' ',
1702 'O','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e', 0};
1705 return ERROR_INVALID_HANDLE;
1707 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1708 if (rc != ERROR_SUCCESS)
1709 return ERROR_SUCCESS;
1711 rc = MSI_ViewExecute(view, 0);
1712 if (rc != ERROR_SUCCESS)
1714 MSI_ViewClose(view);
1715 msiobj_release(&view->hdr);
1716 return ERROR_SUCCESS;
1721 rc = MSI_ViewFetch(view,&row);
1722 if (rc != ERROR_SUCCESS)
1727 load_file(package,row);
1728 msiobj_release(&row->hdr);
1730 MSI_ViewClose(view);
1731 msiobj_release(&view->hdr);
1733 return ERROR_SUCCESS;
1736 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1740 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','D','i','r','e','c',
1741 't','o','r','y',' ','w','h','e','r','e',' ','`','D','i','r','e','c','t',
1742 'o','r','y','`',' ','=',' ','`',0};
1743 static const WCHAR end[]={'`',0};
1746 WCHAR targetbuffer[0x100];
1747 WCHAR *srcdir = NULL;
1748 WCHAR *targetdir = NULL;
1749 WCHAR parent[0x100];
1751 MSIRECORD * row = 0;
1755 TRACE("Looking for dir %s\n",debugstr_w(dir));
1757 for (i = 0; i < package->loaded_folders; i++)
1759 if (strcmpW(package->folders[i].Directory,dir)==0)
1761 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
1766 TRACE("Working to load %s\n",debugstr_w(dir));
1768 index = package->loaded_folders;
1770 package->loaded_folders++;
1771 if (package->loaded_folders== 1)
1772 package->folders = HeapAlloc(GetProcessHeap(),0,
1775 package->folders= HeapReAlloc(GetProcessHeap(),0,
1776 package->folders, package->loaded_folders*
1779 memset(&package->folders[index],0,sizeof(MSIFOLDER));
1781 strcpyW(package->folders[index].Directory,dir);
1786 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1788 if (rc != ERROR_SUCCESS)
1791 rc = MSI_ViewExecute(view, 0);
1792 if (rc != ERROR_SUCCESS)
1794 MSI_ViewClose(view);
1795 msiobj_release(&view->hdr);
1799 rc = MSI_ViewFetch(view,&row);
1800 if (rc != ERROR_SUCCESS)
1802 MSI_ViewClose(view);
1803 msiobj_release(&view->hdr);
1808 MSI_RecordGetStringW(row,3,targetbuffer,&sz);
1809 targetdir=targetbuffer;
1811 /* split src and target dir */
1812 if (strchrW(targetdir,':'))
1814 srcdir=strchrW(targetdir,':');
1821 /* for now only pick long filename versions */
1822 if (strchrW(targetdir,'|'))
1824 targetdir = strchrW(targetdir,'|');
1828 if (srcdir && strchrW(srcdir,'|'))
1830 srcdir= strchrW(srcdir,'|');
1835 /* now check for root dirs */
1836 if (targetdir[0] == '.' && targetdir[1] == 0)
1839 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
1843 strcpyW(package->folders[index].TargetDefault,targetdir);
1846 strcpyW(package->folders[index].SourceDefault,srcdir);
1848 strcpyW(package->folders[index].SourceDefault,targetdir);
1850 if (MSI_RecordIsNull(row,2))
1855 MSI_RecordGetStringW(row,2,parent,&sz);
1860 i = load_folder(package,parent);
1861 package->folders[index].ParentIndex = i;
1862 TRACE("Parent is index %i... %s %s\n",
1863 package->folders[index].ParentIndex,
1864 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
1865 debugstr_w(parent));
1868 package->folders[index].ParentIndex = -2;
1871 rc = MSI_GetPropertyW(package, dir, package->folders[index].Property, &sz);
1872 if (rc != ERROR_SUCCESS)
1873 package->folders[index].Property[0]=0;
1875 msiobj_release(&row->hdr);
1876 MSI_ViewClose(view);
1877 msiobj_release(&view->hdr);
1878 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
1882 static UINT resolve_folder(MSIPACKAGE *package, LPCWSTR name, LPWSTR path,
1883 BOOL source, BOOL set_prop, MSIFOLDER **folder)
1886 UINT rc = ERROR_SUCCESS;
1889 TRACE("Working to resolve %s\n",debugstr_w(name));
1894 /* special resolving for Target and Source root dir */
1895 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
1900 rc = MSI_GetPropertyW(package,cszTargetDir,path,&sz);
1901 if (rc != ERROR_SUCCESS)
1904 rc = MSI_GetPropertyW(package,cszRootDrive,path,&sz);
1906 MSI_SetPropertyW(package,cszTargetDir,path);
1909 *folder = &(package->folders[0]);
1915 rc = MSI_GetPropertyW(package,cszSourceDir,path,&sz);
1916 if (rc != ERROR_SUCCESS)
1919 rc = MSI_GetPropertyW(package,cszDatabase,path,&sz);
1920 if (rc == ERROR_SUCCESS)
1922 LPWSTR ptr = strrchrW(path,'\\');
1931 *folder = &(package->folders[0]);
1936 for (i = 0; i < package->loaded_folders; i++)
1938 if (strcmpW(package->folders[i].Directory,name)==0)
1942 if (i >= package->loaded_folders)
1943 return ERROR_FUNCTION_FAILED;
1946 *folder = &(package->folders[i]);
1948 if (!source && package->folders[i].ResolvedTarget[0])
1950 strcpyW(path,package->folders[i].ResolvedTarget);
1951 TRACE(" already resolved to %s\n",debugstr_w(path));
1952 return ERROR_SUCCESS;
1954 else if (source && package->folders[i].ResolvedSource[0])
1956 strcpyW(path,package->folders[i].ResolvedSource);
1957 return ERROR_SUCCESS;
1959 else if (!source && package->folders[i].Property[0])
1961 strcpyW(path,package->folders[i].Property);
1962 TRACE(" internally set to %s\n",debugstr_w(path));
1964 MSI_SetPropertyW(package,name,path);
1965 return ERROR_SUCCESS;
1968 if (package->folders[i].ParentIndex >= 0)
1971 TRACE(" ! Parent is %s\n", debugstr_w(package->folders[
1972 package->folders[i].ParentIndex].Directory));
1973 resolve_folder(package, package->folders[
1974 package->folders[i].ParentIndex].Directory, path,source,
1977 len = strlenW(path);
1978 if (len && path[len-1] != '\\')
1979 strcatW(path, cszbs);
1983 if (package->folders[i].TargetDefault[0])
1985 strcatW(path,package->folders[i].TargetDefault);
1986 strcatW(path,cszbs);
1988 strcpyW(package->folders[i].ResolvedTarget,path);
1989 TRACE(" resolved into %s\n",debugstr_w(path));
1991 MSI_SetPropertyW(package,name,path);
1995 if (package->folders[i].SourceDefault[0])
1997 strcatW(path,package->folders[i].SourceDefault);
1998 strcatW(path,cszbs);
2000 strcpyW(package->folders[i].ResolvedSource,path);
2007 * Alot is done in this function aside from just the costing.
2008 * The costing needs to be implemented at some point but for now I am going
2009 * to focus on the directory building
2012 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2014 static const WCHAR ExecSeqQuery[] = {
2015 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2016 'D','i','r','e','c','t','o','r','y',0};
2017 static const WCHAR ConditionQuery[] = {
2018 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2019 'C','o','n','d','i','t','i','o','n',0};
2020 static const WCHAR szCosting[] = {
2021 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2022 static const WCHAR szOne[] = { '1', 0 };
2027 TRACE("Building Directory properties\n");
2029 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2030 if (rc == ERROR_SUCCESS)
2032 rc = MSI_ViewExecute(view, 0);
2033 if (rc != ERROR_SUCCESS)
2035 MSI_ViewClose(view);
2036 msiobj_release(&view->hdr);
2043 WCHAR path[MAX_PATH];
2044 MSIRECORD * row = 0;
2047 rc = MSI_ViewFetch(view,&row);
2048 if (rc != ERROR_SUCCESS)
2055 MSI_RecordGetStringW(row,1,name,&sz);
2057 /* This helper function now does ALL the work */
2058 TRACE("Dir %s ...\n",debugstr_w(name));
2059 load_folder(package,name);
2060 resolve_folder(package,name,path,FALSE,TRUE,NULL);
2061 TRACE("resolves to %s\n",debugstr_w(path));
2063 msiobj_release(&row->hdr);
2065 MSI_ViewClose(view);
2066 msiobj_release(&view->hdr);
2069 TRACE("File calculations %i files\n",package->loaded_files);
2071 for (i = 0; i < package->loaded_files; i++)
2073 MSICOMPONENT* comp = NULL;
2074 MSIFILE* file= NULL;
2076 file = &package->files[i];
2077 if (file->ComponentIndex >= 0)
2078 comp = &package->components[file->ComponentIndex];
2083 /* calculate target */
2084 resolve_folder(package, comp->Directory, file->TargetPath, FALSE,
2086 /* make sure that the path ends in a \ */
2087 len = strlenW(file->TargetPath);
2088 if (len && file->TargetPath[len-1] != '\\')
2089 strcatW(file->TargetPath, cszbs);
2090 strcatW(file->TargetPath,file->FileName);
2092 TRACE("file %s resolves to %s\n",
2093 debugstr_w(file->File),debugstr_w(file->TargetPath));
2095 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2098 comp->Cost += file->FileSize;
2102 if (file->Version[0])
2108 static const WCHAR name[] =
2110 static const WCHAR name_fmt[] =
2111 {'%','u','.','%','u','.','%','u','.','%','u',0};
2112 WCHAR filever[0x100];
2113 VS_FIXEDFILEINFO *lpVer;
2115 FIXME("Version comparison.. \n");
2116 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2117 version = HeapAlloc(GetProcessHeap(),0,versize);
2118 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2120 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2122 sprintfW(filever,name_fmt,
2123 HIWORD(lpVer->dwFileVersionMS),
2124 LOWORD(lpVer->dwFileVersionMS),
2125 HIWORD(lpVer->dwFileVersionLS),
2126 LOWORD(lpVer->dwFileVersionLS));
2128 TRACE("new %s old %s\n", debugstr_w(file->Version),
2129 debugstr_w(filever));
2130 if (strcmpiW(filever,file->Version)<0)
2133 FIXME("cost should be diff in size\n");
2134 comp->Cost += file->FileSize;
2138 HeapFree(GetProcessHeap(),0,version);
2146 TRACE("Evaluating Condition Table\n");
2148 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2149 if (rc == ERROR_SUCCESS)
2151 rc = MSI_ViewExecute(view, 0);
2152 if (rc != ERROR_SUCCESS)
2154 MSI_ViewClose(view);
2155 msiobj_release(&view->hdr);
2161 WCHAR Feature[0x100];
2162 MSIRECORD * row = 0;
2166 rc = MSI_ViewFetch(view,&row);
2168 if (rc != ERROR_SUCCESS)
2175 MSI_RecordGetStringW(row,1,Feature,&sz);
2177 feature_index = get_loaded_feature(package,Feature);
2178 if (feature_index < 0)
2179 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2183 Condition = load_dynamic_stringW(row,3);
2185 if (MSI_EvaluateConditionW(package,Condition) ==
2188 int level = MSI_RecordGetInteger(row,2);
2189 TRACE("Reseting feature %s to level %i\n",
2190 debugstr_w(Feature), level);
2191 package->features[feature_index].Level = level;
2193 HeapFree(GetProcessHeap(),0,Condition);
2196 msiobj_release(&row->hdr);
2198 MSI_ViewClose(view);
2199 msiobj_release(&view->hdr);
2202 TRACE("Enabling or Disabling Components\n");
2203 for (i = 0; i < package->loaded_components; i++)
2205 if (package->components[i].Condition[0])
2207 if (MSI_EvaluateConditionW(package,
2208 package->components[i].Condition) == MSICONDITION_FALSE)
2210 TRACE("Disabling component %s\n",
2211 debugstr_w(package->components[i].Component));
2212 package->components[i].Enabled = FALSE;
2217 MSI_SetPropertyW(package,szCosting,szOne);
2218 return ERROR_SUCCESS;
2222 * This is a helper function for handling embedded cabinet media
2224 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2232 WCHAR tmp[MAX_PATH];
2234 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2235 if (rc != ERROR_SUCCESS)
2239 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2240 GetTempPathW(MAX_PATH,tmp);
2242 GetTempFileNameW(tmp,stream_name,0,source);
2244 track_tempfile(package,strrchrW(source,'\\'), source);
2245 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2246 FILE_ATTRIBUTE_NORMAL, NULL);
2248 if (the_file == INVALID_HANDLE_VALUE)
2250 rc = ERROR_FUNCTION_FAILED;
2254 WriteFile(the_file,data,size,&write,NULL);
2255 CloseHandle(the_file);
2256 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2258 HeapFree(GetProcessHeap(),0,data);
2263 /* Support functions for FDI functions */
2265 static void * cabinet_alloc(ULONG cb)
2267 return HeapAlloc(GetProcessHeap(), 0, cb);
2270 static void cabinet_free(void *pv)
2272 HeapFree(GetProcessHeap(), 0, pv);
2275 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2278 DWORD dwShareMode = 0;
2279 DWORD dwCreateDisposition = OPEN_EXISTING;
2280 switch (oflag & _O_ACCMODE)
2283 dwAccess = GENERIC_READ;
2284 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2287 dwAccess = GENERIC_WRITE;
2288 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2291 dwAccess = GENERIC_READ | GENERIC_WRITE;
2292 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2295 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2296 dwCreateDisposition = CREATE_NEW;
2297 else if (oflag & _O_CREAT)
2298 dwCreateDisposition = CREATE_ALWAYS;
2299 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL, dwCreateDisposition, 0, NULL);
2302 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2305 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2310 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2313 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2318 static int cabinet_close(INT_PTR hf)
2320 return CloseHandle((HANDLE)hf) ? 0 : -1;
2323 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2325 /* flags are compatible and so are passed straight through */
2326 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2329 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2331 /* FIXME: try to do more processing in this function */
2334 case fdintCOPY_FILE:
2336 ULONG len = strlen((char*)pfdin->pv) + strlen(pfdin->psz1);
2337 char *file = cabinet_alloc((len+1)*sizeof(char));
2339 strcpy(file, (char*)pfdin->pv);
2340 strcat(file, pfdin->psz1);
2342 TRACE("file: %s\n", debugstr_a(file));
2344 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2346 case fdintCLOSE_FILE_INFO:
2350 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2352 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2354 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2357 cabinet_close(pfdin->hf);
2365 /***********************************************************************
2366 * extract_cabinet_file
2368 * Extract files from a cab file.
2370 static BOOL extract_cabinet_file(const WCHAR* source, const WCHAR* path)
2378 TRACE("Extracting %s to %s\n",debugstr_w(source), debugstr_w(path));
2380 hfdi = FDICreate(cabinet_alloc,
2391 ERR("FDICreate failed\n");
2395 if (!(cabinet = strdupWtoA( source )))
2400 if (!(cab_path = strdupWtoA( path )))
2403 HeapFree(GetProcessHeap(), 0, cabinet);
2407 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, cab_path);
2410 ERR("FDICopy failed\n");
2414 HeapFree(GetProcessHeap(), 0, cabinet);
2415 HeapFree(GetProcessHeap(), 0, cab_path);
2420 static UINT ready_media_for_file(MSIPACKAGE *package, UINT sequence,
2425 MSIRECORD * row = 0;
2426 WCHAR source[MAX_PATH];
2427 static const WCHAR ExecSeqQuery[] = {
2428 's','e','l','e','c','t',' ','*',' ',
2429 'f','r','o','m',' ','M','e','d','i','a',' ',
2430 'w','h','e','r','e',' ','L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%','i',' ',
2431 'o','r','d','e','r',' ','b','y',' ','L','a','s','t','S','e','q','u','e','n','c','e',0};
2436 static UINT last_sequence = 0;
2438 if (sequence <= last_sequence)
2440 TRACE("Media already ready (%u, %u)\n",sequence,last_sequence);
2441 return ERROR_SUCCESS;
2444 sprintfW(Query,ExecSeqQuery,sequence);
2446 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2447 if (rc != ERROR_SUCCESS)
2450 rc = MSI_ViewExecute(view, 0);
2451 if (rc != ERROR_SUCCESS)
2453 MSI_ViewClose(view);
2454 msiobj_release(&view->hdr);
2458 rc = MSI_ViewFetch(view,&row);
2459 if (rc != ERROR_SUCCESS)
2461 MSI_ViewClose(view);
2462 msiobj_release(&view->hdr);
2465 seq = MSI_RecordGetInteger(row,2);
2466 last_sequence = seq;
2468 if (!MSI_RecordIsNull(row,4))
2471 MSI_RecordGetStringW(row,4,cab,&sz);
2472 TRACE("Source is CAB %s\n",debugstr_w(cab));
2473 /* the stream does not contain the # character */
2476 writeout_cabinet_stream(package,&cab[1],source);
2477 strcpyW(path,source);
2478 *(strrchrW(path,'\\')+1)=0;
2483 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
2485 ERR("No Source dir defined \n");
2486 rc = ERROR_FUNCTION_FAILED;
2490 strcpyW(path,source);
2491 strcatW(source,cab);
2492 /* extract the cab file into a folder in the temp folder */
2494 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
2496 GetTempPathW(MAX_PATH,path);
2499 rc = !extract_cabinet_file(source,path);
2501 msiobj_release(&row->hdr);
2502 MSI_ViewClose(view);
2503 msiobj_release(&view->hdr);
2507 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
2511 WCHAR install_path[MAX_PATH];
2513 rc = resolve_folder(package, package->components[component].Directory,
2514 install_path, FALSE, FALSE, &folder);
2516 if (rc != ERROR_SUCCESS)
2519 /* create the path */
2520 if (folder->State == 0)
2522 create_full_pathW(install_path);
2529 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
2531 UINT rc = ERROR_SUCCESS;
2534 WCHAR uipath[MAX_PATH];
2537 return ERROR_INVALID_HANDLE;
2539 /* increment progress bar each time action data is sent */
2540 ui_progress(package,1,1,1,0);
2542 for (index = 0; index < package->loaded_files; index++)
2544 WCHAR path_to_source[MAX_PATH];
2547 file = &package->files[index];
2549 if (file->Temporary)
2552 if (!package->components[file->ComponentIndex].Enabled ||
2553 !package->components[file->ComponentIndex].FeatureState)
2555 TRACE("File %s is not scheduled for install\n",
2556 debugstr_w(file->File));
2560 if ((file->State == 1) || (file->State == 2))
2562 TRACE("Installing %s\n",debugstr_w(file->File));
2563 rc = ready_media_for_file(package,file->Sequence,path_to_source);
2566 * our file table could change here because a new temp file
2567 * may have been created
2569 file = &package->files[index];
2570 if (rc != ERROR_SUCCESS)
2572 ERR("Unable to ready media\n");
2573 rc = ERROR_FUNCTION_FAILED;
2577 create_component_directory( package, file->ComponentIndex);
2579 strcpyW(file->SourcePath, path_to_source);
2580 strcatW(file->SourcePath, file->File);
2582 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
2583 debugstr_w(file->TargetPath));
2586 uirow=MSI_CreateRecord(9);
2587 MSI_RecordSetStringW(uirow,1,file->File);
2588 strcpyW(uipath,file->TargetPath);
2589 *(strrchrW(uipath,'\\')+1)=0;
2590 MSI_RecordSetStringW(uirow,9,uipath);
2591 MSI_RecordSetInteger(uirow,6,file->FileSize);
2592 ui_actiondata(package,szInstallFiles,uirow);
2593 msiobj_release( &uirow->hdr );
2595 if (!MoveFileW(file->SourcePath,file->TargetPath))
2597 rc = GetLastError();
2598 ERR("Unable to move file (%s -> %s) (error %d)\n",
2599 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
2601 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
2603 CopyFileW(file->SourcePath,file->TargetPath,FALSE);
2604 DeleteFileW(file->SourcePath);
2613 ui_progress(package,2,0,0,0);
2620 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
2626 return ERROR_INVALID_HANDLE;
2628 for (index = 0; index < package->loaded_files; index ++)
2630 if (strcmpW(file_key,package->files[index].File)==0)
2632 if (package->files[index].State >= 3)
2634 strcpyW(file_source,package->files[index].TargetPath);
2635 return ERROR_SUCCESS;
2638 return ERROR_FILE_NOT_FOUND;
2642 return ERROR_FUNCTION_FAILED;
2645 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
2649 MSIRECORD * row = 0;
2650 static const WCHAR ExecSeqQuery[] = {
2651 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2652 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
2655 return ERROR_INVALID_HANDLE;
2657 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2658 if (rc != ERROR_SUCCESS)
2659 return ERROR_SUCCESS;
2661 rc = MSI_ViewExecute(view, 0);
2662 if (rc != ERROR_SUCCESS)
2664 MSI_ViewClose(view);
2665 msiobj_release(&view->hdr);
2671 WCHAR file_key[0x100];
2672 WCHAR file_source[MAX_PATH];
2673 WCHAR dest_name[0x100];
2674 WCHAR dest_path[MAX_PATH];
2675 WCHAR component[0x100];
2676 INT component_index;
2680 rc = MSI_ViewFetch(view,&row);
2681 if (rc != ERROR_SUCCESS)
2688 rc = MSI_RecordGetStringW(row,2,component,&sz);
2689 if (rc != ERROR_SUCCESS)
2691 ERR("Unable to get component\n");
2692 msiobj_release(&row->hdr);
2696 component_index = get_loaded_component(package,component);
2697 if (!package->components[component_index].Enabled ||
2698 !package->components[component_index].FeatureState)
2700 TRACE("Skipping copy due to disabled component\n");
2701 msiobj_release(&row->hdr);
2706 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
2707 if (rc != ERROR_SUCCESS)
2709 ERR("Unable to get file key\n");
2710 msiobj_release(&row->hdr);
2714 rc = get_file_target(package,file_key,file_source);
2716 if (rc != ERROR_SUCCESS)
2718 ERR("Original file unknown %s\n",debugstr_w(file_key));
2719 msiobj_release(&row->hdr);
2723 if (MSI_RecordIsNull(row,4))
2725 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
2730 MSI_RecordGetStringW(row,4,dest_name,&sz);
2731 reduce_to_longfilename(dest_name);
2734 if (MSI_RecordIsNull(row,5))
2736 strcpyW(dest_path,file_source);
2737 *strrchrW(dest_path,'\\')=0;
2741 WCHAR destkey[0x100];
2743 MSI_RecordGetStringW(row,5,destkey,&sz);
2745 rc = resolve_folder(package, destkey, dest_path,FALSE,FALSE,NULL);
2746 if (rc != ERROR_SUCCESS)
2748 ERR("Unable to get destination folder\n");
2749 msiobj_release(&row->hdr);
2754 strcatW(dest_path,dest_name);
2756 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
2757 debugstr_w(dest_path));
2759 if (strcmpW(file_source,dest_path))
2760 rc = !CopyFileW(file_source,dest_path,TRUE);
2764 if (rc != ERROR_SUCCESS)
2765 ERR("Failed to copy file\n");
2767 FIXME("We should track these duplicate files as well\n");
2769 msiobj_release(&row->hdr);
2771 MSI_ViewClose(view);
2772 msiobj_release(&view->hdr);
2778 /* OK this value is "interpretted" and then formatted based on the
2779 first few characters */
2780 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
2784 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
2793 deformat_string(package, &value[2], &deformated);
2795 /* binary value type */
2798 *size = strlenW(ptr)/2;
2799 data = HeapAlloc(GetProcessHeap(),0,*size);
2811 data[count] = (BYTE)strtol(byte,NULL,0);
2814 HeapFree(GetProcessHeap(),0,deformated);
2816 TRACE("Data %li bytes(%i)\n",*size,count);
2821 deformat_string(package, &value[1], &deformated);
2824 *size = sizeof(DWORD);
2825 data = HeapAlloc(GetProcessHeap(),0,*size);
2826 *(LPDWORD)data = atoiW(deformated);
2827 TRACE("DWORD %i\n",*data);
2829 HeapFree(GetProcessHeap(),0,deformated);
2842 *type=REG_EXPAND_SZ;
2850 *size = deformat_string(package, ptr,(LPWSTR*)&data);
2855 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
2859 MSIRECORD * row = 0;
2860 static const WCHAR ExecSeqQuery[] = {
2861 's','e','l','e','c','t',' ','*',' ',
2862 'f','r','o','m',' ','R','e','g','i','s','t','r','y',0 };
2865 return ERROR_INVALID_HANDLE;
2867 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2868 if (rc != ERROR_SUCCESS)
2869 return ERROR_SUCCESS;
2871 rc = MSI_ViewExecute(view, 0);
2872 if (rc != ERROR_SUCCESS)
2874 MSI_ViewClose(view);
2875 msiobj_release(&view->hdr);
2879 /* increment progress bar each time action data is sent */
2880 ui_progress(package,1,1,1,0);
2884 static const WCHAR szHCR[] =
2885 {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T','\\',0};
2886 static const WCHAR szHCU[] =
2887 {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',0};
2888 static const WCHAR szHLM[] =
2889 {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',
2891 static const WCHAR szHU[] =
2892 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
2897 LPSTR value_data = NULL;
2898 HKEY root_key, hkey;
2900 WCHAR component[0x100];
2901 INT component_index;
2908 rc = MSI_ViewFetch(view,&row);
2909 if (rc != ERROR_SUCCESS)
2916 MSI_RecordGetStringW(row,6,component,&sz);
2917 component_index = get_loaded_component(package,component);
2919 if (!package->components[component_index].Enabled ||
2920 !package->components[component_index].FeatureState)
2922 TRACE("Skipping write due to disabled component\n");
2923 msiobj_release(&row->hdr);
2927 /* null values have special meanings during uninstalls and such */
2929 if(MSI_RecordIsNull(row,5))
2931 msiobj_release(&row->hdr);
2935 root = MSI_RecordGetInteger(row,2);
2937 MSI_RecordGetStringW(row,3,key,&sz);
2940 if (MSI_RecordIsNull(row,4))
2943 MSI_RecordGetStringW(row,4,name,&sz);
2945 /* get the root key */
2948 case 0: root_key = HKEY_CLASSES_ROOT;
2949 strcpyW(uikey,szHCR); break;
2950 case 1: root_key = HKEY_CURRENT_USER;
2951 strcpyW(uikey,szHCU); break;
2952 case 2: root_key = HKEY_LOCAL_MACHINE;
2953 strcpyW(uikey,szHLM); break;
2954 case 3: root_key = HKEY_USERS;
2955 strcpyW(uikey,szHU); break;
2957 ERR("Unknown root %i\n",root);
2963 msiobj_release(&row->hdr);
2968 if (RegCreateKeyW( root_key, key, &hkey))
2970 ERR("Could not create key %s\n",debugstr_w(key));
2971 msiobj_release(&row->hdr);
2975 value = load_dynamic_stringW(row,5);
2976 value_data = parse_value(package, value, &type, &size);
2980 TRACE("Setting value %s\n",debugstr_w(name));
2981 RegSetValueExW(hkey, name, 0, type, value_data, size);
2983 uirow = MSI_CreateRecord(3);
2984 MSI_RecordSetStringW(uirow,2,name);
2985 MSI_RecordSetStringW(uirow,1,uikey);
2988 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
2990 MSI_RecordSetStringW(uirow,3,value);
2992 ui_actiondata(package,szWriteRegistryValues,uirow);
2993 ui_progress(package,2,0,0,0);
2994 msiobj_release( &uirow->hdr );
2996 HeapFree(GetProcessHeap(),0,value_data);
2998 HeapFree(GetProcessHeap(),0,value);
3000 msiobj_release(&row->hdr);
3003 MSI_ViewClose(view);
3004 msiobj_release(&view->hdr);
3009 * This helper function should probably go alot of places
3011 * Thinking about this, maybe this should become yet another Bison file
3013 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data)
3023 /* scan for special characters */
3024 if (!strchrW(ptr,'[') || (strchrW(ptr,'[') && !strchrW(ptr,']')))
3027 size = (strlenW(ptr)+1) * sizeof(WCHAR);
3028 *data = HeapAlloc(GetProcessHeap(),0,size);
3033 /* formatted string located */
3034 mark = strchrW(ptr,'[');
3037 INT cnt = (mark - ptr);
3038 TRACE("%i (%i) characters before marker\n",cnt,(mark-ptr));
3039 size = cnt * sizeof(WCHAR);
3040 size += sizeof(WCHAR);
3041 *data = HeapAlloc(GetProcessHeap(),0,size);
3042 strncpyW(*data,ptr,cnt);
3047 size = sizeof(WCHAR);
3048 *data = HeapAlloc(GetProcessHeap(),0,size);
3053 *strchrW(key,']')=0;
3054 mark = strchrW(mark,']');
3056 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3058 rc = MSI_GetPropertyW(package, key, NULL, &sz);
3059 if ((rc == ERROR_SUCCESS) || (rc == ERROR_MORE_DATA))
3064 value = HeapAlloc(GetProcessHeap(),0,sz * sizeof(WCHAR));
3065 MSI_GetPropertyW(package, key, value, &sz);
3067 chunk = (strlenW(value)+1) * sizeof(WCHAR);
3069 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
3071 strcatW(*data,value);
3073 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3077 chunk = (strlenW(mark)+1) * sizeof(WCHAR);
3079 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
3081 strcatW(*data,mark);
3083 (*data)[strlenW(*data)]=0;
3084 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3086 /* recursively do this to clean up */
3087 mark = HeapAlloc(GetProcessHeap(),0,size);
3088 strcpyW(mark,*data);
3089 TRACE("String at this point %s\n",debugstr_w(mark));
3090 size = deformat_string(package,mark,data);
3091 HeapFree(GetProcessHeap(),0,mark);
3095 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3103 LPWSTR override = NULL;
3104 static const WCHAR addlocal[]={'A','D','D','L','O','C','A','L',0};
3105 static const WCHAR all[]={'A','L','L',0};
3106 static const WCHAR szlevel[] = {
3107 'I','N','S','T','A','L','L','L','E','V','E','L',0};
3108 static const WCHAR szAddLocal[] = {
3109 'A','D','D','L','O','C','A','L',0};
3111 /* I do not know if this is where it should happen.. but */
3113 TRACE("Checking Install Level\n");
3116 if (MSI_GetPropertyW(package,szlevel,level,&sz)==ERROR_SUCCESS)
3117 install_level = atoiW(level);
3122 rc = MSI_GetPropertyW(package,szAddLocal,NULL,&sz);
3123 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
3126 override = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
3127 MSI_GetPropertyW(package, addlocal,override,&sz);
3131 * Components FeatureState defaults to FALSE. The idea is we want to
3132 * enable the component is ANY feature that uses it is enabled to install
3134 for(i = 0; i < package->loaded_features; i++)
3136 BOOL feature_state= ((package->features[i].Level > 0) &&
3137 (package->features[i].Level <= install_level));
3139 if (override && (strcmpiW(override,all)==0 ||
3140 strstrW(override,package->features[i].Feature)))
3142 TRACE("Override of install level found\n");
3143 feature_state = TRUE;
3144 package->features[i].Enabled = feature_state;
3147 TRACE("Feature %s has a state of %i\n",
3148 debugstr_w(package->features[i].Feature), feature_state);
3149 for( j = 0; j < package->features[i].ComponentCount; j++)
3151 package->components[package->features[i].Components[j]].FeatureState
3155 if (override != NULL)
3156 HeapFree(GetProcessHeap(),0,override);
3158 * So basically we ONLY want to install a component if its Enabled AND
3159 * FeatureState are both TRUE
3161 return ERROR_SUCCESS;
3164 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3167 static const WCHAR q1[]={
3168 'S','E','L','E','C','T',' ','*',' ',
3169 'F','R','O','M',' ','R','e','g','i','s','t','r','y',0};
3172 MSIRECORD * row = 0;
3174 TRACE(" InstallValidate \n");
3176 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3177 if (rc != ERROR_SUCCESS)
3178 return ERROR_SUCCESS;
3180 rc = MSI_ViewExecute(view, 0);
3181 if (rc != ERROR_SUCCESS)
3183 MSI_ViewClose(view);
3184 msiobj_release(&view->hdr);
3189 rc = MSI_ViewFetch(view,&row);
3190 if (rc != ERROR_SUCCESS)
3197 msiobj_release(&row->hdr);
3199 MSI_ViewClose(view);
3200 msiobj_release(&view->hdr);
3202 ui_progress(package,0,progress+package->loaded_files,0,0);
3204 return ERROR_SUCCESS;
3207 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3210 MSIQUERY * view = NULL;
3211 MSIRECORD * row = 0;
3212 static const WCHAR ExecSeqQuery[] = {
3213 'S','E','L','E','C','T',' ','*',' ',
3214 'f','r','o','m',' ','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3215 static const WCHAR title[]=
3216 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3218 TRACE("Checking launch conditions\n");
3220 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3221 if (rc != ERROR_SUCCESS)
3222 return ERROR_SUCCESS;
3224 rc = MSI_ViewExecute(view, 0);
3225 if (rc != ERROR_SUCCESS)
3227 MSI_ViewClose(view);
3228 msiobj_release(&view->hdr);
3233 while (rc == ERROR_SUCCESS)
3236 LPWSTR message = NULL;
3238 rc = MSI_ViewFetch(view,&row);
3239 if (rc != ERROR_SUCCESS)
3245 cond = load_dynamic_stringW(row,1);
3247 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3249 message = load_dynamic_stringW(row,2);
3250 MessageBoxW(NULL,message,title,MB_OK);
3251 HeapFree(GetProcessHeap(),0,message);
3252 rc = ERROR_FUNCTION_FAILED;
3254 HeapFree(GetProcessHeap(),0,cond);
3255 msiobj_release(&row->hdr);
3257 MSI_ViewClose(view);
3258 msiobj_release(&view->hdr);
3262 static void resolve_keypath( MSIPACKAGE* package, INT
3263 component_index, WCHAR *keypath)
3265 MSICOMPONENT* cmp = &package->components[component_index];
3267 if (cmp->KeyPath[0]==0)
3269 resolve_folder(package,cmp->Directory,keypath,FALSE,FALSE,NULL);
3272 if ((cmp->Attributes & 0x4) || (cmp->Attributes & 0x20))
3274 FIXME("UNIMPLEMENTED keypath as Registry or ODBC Source\n");
3280 j = get_loaded_file(package,cmp->KeyPath);
3283 strcpyW(keypath,package->files[j].TargetPath);
3288 * Ok further analysis makes me think that this work is
3289 * actually done in the PublishComponents and PublishFeatures
3290 * step, and not here. It appears like the keypath and all that is
3291 * resolved in this step, however actually written in the Publish steps.
3292 * But we will leave it here for now because it is unclear
3294 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
3296 WCHAR productcode[0x100];
3297 WCHAR squished_pc[0x100];
3298 WCHAR squished_cc[0x100];
3302 HKEY hkey=0,hkey2=0,hkey3=0;
3303 static const WCHAR szProductCode[]=
3304 {'P','r','o','d','u','c','t','C','o','d','e',0};
3305 static const WCHAR szInstaller[] = {
3306 'S','o','f','t','w','a','r','e','\\',
3307 'M','i','c','r','o','s','o','f','t','\\',
3308 'W','i','n','d','o','w','s','\\',
3309 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3310 'I','n','s','t','a','l','l','e','r',0 };
3311 static const WCHAR szFeatures[] = {
3312 'F','e','a','t','u','r','e','s',0 };
3313 static const WCHAR szComponents[] = {
3314 'C','o','m','p','o','n','e','n','t','s',0 };
3317 return ERROR_INVALID_HANDLE;
3319 /* writes the Component and Features values to the registry */
3321 rc = MSI_GetPropertyW(package,szProductCode,productcode,&sz);
3322 if (rc != ERROR_SUCCESS)
3323 return ERROR_SUCCESS;
3325 squash_guid(productcode,squished_pc);
3326 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller,&hkey);
3327 if (rc != ERROR_SUCCESS)
3330 rc = RegCreateKeyW(hkey,szFeatures,&hkey2);
3331 if (rc != ERROR_SUCCESS)
3334 rc = RegCreateKeyW(hkey2,squished_pc,&hkey3);
3335 if (rc != ERROR_SUCCESS)
3338 /* here the guids are base 85 encoded */
3339 for (i = 0; i < package->loaded_features; i++)
3346 size = package->features[i].ComponentCount*21*sizeof(WCHAR);
3347 data = HeapAlloc(GetProcessHeap(), 0, size);
3350 for (j = 0; j < package->features[i].ComponentCount; j++)
3353 TRACE("From %s\n",debugstr_w(package->components
3354 [package->features[i].Components[j]].ComponentId));
3355 CLSIDFromString(package->components
3356 [package->features[i].Components[j]].ComponentId,
3358 encode_base85_guid(&clsid,buf);
3359 TRACE("to %s\n",debugstr_w(buf));
3363 size = strlenW(data)*sizeof(WCHAR);
3364 RegSetValueExW(hkey3,package->features[i].Feature,0,REG_SZ,
3366 HeapFree(GetProcessHeap(),0,data);
3372 rc = RegCreateKeyW(hkey,szComponents,&hkey2);
3373 if (rc != ERROR_SUCCESS)
3376 for (i = 0; i < package->loaded_components; i++)
3378 if (package->components[i].ComponentId[0]!=0)
3380 WCHAR keypath[0x1000];
3383 squash_guid(package->components[i].ComponentId,squished_cc);
3384 rc = RegCreateKeyW(hkey2,squished_cc,&hkey3);
3385 if (rc != ERROR_SUCCESS)
3388 resolve_keypath(package,i,keypath);
3390 RegSetValueExW(hkey3,squished_pc,0,REG_SZ,(LPVOID)keypath,
3391 (strlenW(keypath)+1)*sizeof(WCHAR));
3395 uirow = MSI_CreateRecord(3);
3396 MSI_RecordSetStringW(uirow,1,productcode);
3397 MSI_RecordSetStringW(uirow,2,package->components[i].ComponentId);
3398 MSI_RecordSetStringW(uirow,3,keypath);
3399 ui_actiondata(package,szProcessComponents,uirow);
3400 msiobj_release( &uirow->hdr );
3409 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
3412 * OK this is a bit confusing.. I am given a _Component key and I believe
3413 * that the file that is being registered as a type library is the "key file
3414 * of that component" which I interpret to mean "The file in the KeyPath of
3419 MSIRECORD * row = 0;
3420 static const WCHAR Query[] = {
3421 'S','E','L','E','C','T',' ','*',' ',
3422 'f','r','o','m',' ','T','y','p','e','L','i','b',0};
3427 return ERROR_INVALID_HANDLE;
3429 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3430 if (rc != ERROR_SUCCESS)
3431 return ERROR_SUCCESS;
3433 rc = MSI_ViewExecute(view, 0);
3434 if (rc != ERROR_SUCCESS)
3436 MSI_ViewClose(view);
3437 msiobj_release(&view->hdr);
3443 WCHAR component[0x100];
3447 rc = MSI_ViewFetch(view,&row);
3448 if (rc != ERROR_SUCCESS)
3455 MSI_RecordGetStringW(row,3,component,&sz);
3457 index = get_loaded_component(package,component);
3460 msiobj_release(&row->hdr);
3464 if (!package->components[index].Enabled ||
3465 !package->components[index].FeatureState)
3467 TRACE("Skipping typelib reg due to disabled component\n");
3468 msiobj_release(&row->hdr);
3472 index = get_loaded_file(package,package->components[index].KeyPath);
3476 msiobj_release(&row->hdr);
3480 res = LoadTypeLib(package->files[index].TargetPath,&ptLib);
3483 WCHAR help[MAX_PATH];
3484 WCHAR helpid[0x100];
3487 MSI_RecordGetStringW(row,6,helpid,&sz);
3489 resolve_folder(package,helpid,help,FALSE,FALSE,NULL);
3491 res = RegisterTypeLib(ptLib,package->files[index].TargetPath,help);
3492 if (!SUCCEEDED(res))
3493 ERR("Failed to register type library %s\n",
3494 debugstr_w(package->files[index].TargetPath));
3497 /* Yes the row has more fields than I need, but #1 is
3498 correct and the only one I need. Why make a new row? */
3500 ui_actiondata(package,szRegisterTypeLibraries,row);
3502 TRACE("Registered %s\n",
3503 debugstr_w(package->files[index].TargetPath));
3507 ITypeLib_Release(ptLib);
3510 ERR("Failed to load type library %s\n",
3511 debugstr_w(package->files[index].TargetPath));
3513 msiobj_release(&row->hdr);
3515 MSI_ViewClose(view);
3516 msiobj_release(&view->hdr);
3521 static UINT register_appid(MSIPACKAGE *package, LPCWSTR clsid, LPCWSTR app )
3523 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3526 MSIRECORD * row = 0;
3527 static const WCHAR ExecSeqQuery[] =
3528 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','p','p','I'
3529 ,'d',' ','w','h','e','r','e',' ','A','p','p','I','d','=','`','%','s','`',0};
3530 WCHAR Query[0x1000];
3535 return ERROR_INVALID_HANDLE;
3537 sprintfW(Query,ExecSeqQuery,clsid);
3539 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3540 if (rc != ERROR_SUCCESS)
3543 rc = MSI_ViewExecute(view, 0);
3544 if (rc != ERROR_SUCCESS)
3546 MSI_ViewClose(view);
3547 msiobj_release(&view->hdr);
3551 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
3552 RegCreateKeyW(hkey2,clsid,&hkey3);
3553 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
3554 (strlenW(app)+1)*sizeof(WCHAR));
3556 rc = MSI_ViewFetch(view,&row);
3557 if (rc != ERROR_SUCCESS)
3559 MSI_ViewClose(view);
3560 msiobj_release(&view->hdr);
3564 if (!MSI_RecordIsNull(row,2))
3566 LPWSTR deformated=0;
3568 static const WCHAR szRemoteServerName[] =
3569 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
3570 buffer = load_dynamic_stringW(row,2);
3571 size = deformat_string(package,buffer,&deformated);
3572 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
3574 HeapFree(GetProcessHeap(),0,deformated);
3575 HeapFree(GetProcessHeap(),0,buffer);
3578 if (!MSI_RecordIsNull(row,3))
3580 static const WCHAR szLocalService[] =
3581 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
3583 buffer = load_dynamic_stringW(row,3);
3584 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3585 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
3586 HeapFree(GetProcessHeap(),0,buffer);
3589 if (!MSI_RecordIsNull(row,4))
3591 static const WCHAR szService[] =
3592 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
3594 buffer = load_dynamic_stringW(row,4);
3595 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3596 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
3597 HeapFree(GetProcessHeap(),0,buffer);
3600 if (!MSI_RecordIsNull(row,5))
3602 static const WCHAR szDLL[] =
3603 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
3605 buffer = load_dynamic_stringW(row,5);
3606 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3607 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
3608 HeapFree(GetProcessHeap(),0,buffer);
3611 if (!MSI_RecordIsNull(row,6))
3613 static const WCHAR szActivate[] =
3614 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
3615 static const WCHAR szY[] = {'Y',0};
3617 if (MSI_RecordGetInteger(row,6))
3618 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
3621 if (!MSI_RecordIsNull(row,7))
3623 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
3624 static const WCHAR szUser[] =
3625 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
3627 if (MSI_RecordGetInteger(row,7))
3628 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
3631 msiobj_release(&row->hdr);
3632 MSI_ViewClose(view);
3633 msiobj_release(&view->hdr);
3639 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
3642 * Again I am assuming the words, "Whose key file represents" when referring
3643 * to a Component as to meaning that Components KeyPath file
3645 * Also there is a very strong connection between ClassInfo and ProgID
3646 * that I am mostly glossing over.
3647 * What would be more propper is to load the ClassInfo and the ProgID info
3648 * into memory data structures and then be able to enable and disable them
3649 * based on component.
3654 MSIRECORD * row = 0;
3655 static const WCHAR ExecSeqQuery[] = {
3656 'S','E','L','E','C','T',' ','*',' ',
3657 'f','r','o','m',' ','C','l','a','s','s',0};
3658 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3659 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
3660 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3661 HKEY hkey,hkey2,hkey3;
3664 return ERROR_INVALID_HANDLE;
3666 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
3667 if (rc != ERROR_SUCCESS)
3668 return ERROR_FUNCTION_FAILED;
3670 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3671 if (rc != ERROR_SUCCESS)
3677 rc = MSI_ViewExecute(view, 0);
3678 if (rc != ERROR_SUCCESS)
3680 MSI_ViewClose(view);
3681 msiobj_release(&view->hdr);
3688 WCHAR buffer[0x100];
3693 rc = MSI_ViewFetch(view,&row);
3694 if (rc != ERROR_SUCCESS)
3701 MSI_RecordGetStringW(row,3,buffer,&sz);
3703 index = get_loaded_component(package,buffer);
3707 msiobj_release(&row->hdr);
3711 if (!package->components[index].Enabled ||
3712 !package->components[index].FeatureState)
3714 TRACE("Skipping class reg due to disabled component\n");
3715 msiobj_release(&row->hdr);
3720 MSI_RecordGetStringW(row,1,clsid,&sz);
3721 RegCreateKeyW(hkey,clsid,&hkey2);
3723 if (!MSI_RecordIsNull(row,5))
3726 MSI_RecordGetStringW(row,5,desc,&sz);
3728 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
3729 (strlenW(desc)+1)*sizeof(WCHAR));
3735 MSI_RecordGetStringW(row,2,buffer,&sz);
3737 RegCreateKeyW(hkey2,buffer,&hkey3);
3739 index = get_loaded_file(package,package->components[index].KeyPath);
3740 RegSetValueExW(hkey3,NULL,0,REG_SZ,
3741 (LPVOID)package->files[index].TargetPath,
3742 (strlenW(package->files[index].TargetPath)+1)
3747 if (!MSI_RecordIsNull(row,4))
3750 MSI_RecordGetStringW(row,4,buffer,&sz);
3752 RegCreateKeyW(hkey2,szProgID,&hkey3);
3754 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
3755 (strlenW(buffer)+1)*sizeof(WCHAR));
3760 if (!MSI_RecordIsNull(row,6))
3763 MSI_RecordGetStringW(row,6,buffer,&sz);
3765 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
3766 (strlenW(buffer)+1)*sizeof(WCHAR));
3768 register_appid(package,buffer,desc);
3773 FIXME("Process the rest of the fields >7\n");
3775 ui_actiondata(package,szRegisterClassInfo,row);
3777 msiobj_release(&row->hdr);
3779 MSI_ViewClose(view);
3780 msiobj_release(&view->hdr);
3787 static UINT register_progid_base(MSIRECORD * row, LPWSTR clsid)
3789 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3791 WCHAR buffer[0x100];
3796 MSI_RecordGetStringW(row,1,buffer,&sz);
3797 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
3799 if (!MSI_RecordIsNull(row,4))
3802 MSI_RecordGetStringW(row,4,buffer,&sz);
3803 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
3807 if (!MSI_RecordIsNull(row,3))
3811 MSI_RecordGetStringW(row,3,buffer,&sz);
3812 RegCreateKeyW(hkey,szCLSID,&hkey2);
3813 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
3817 strcpyW(clsid,buffer);
3823 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
3824 return ERROR_FUNCTION_FAILED;
3826 if (!MSI_RecordIsNull(row,5))
3827 FIXME ("UNHANDLED icon in Progid\n");
3828 return ERROR_SUCCESS;
3831 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid);
3833 static UINT register_parent_progid(MSIPACKAGE *package, LPCWSTR parent,
3838 MSIRECORD * row = 0;
3839 static const WCHAR Query_t[] =
3840 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','P','r','o','g'
3841 ,'I','d',' ','w','h','e','r','e',' ','P','r','o','g','I','d',' ','=',' ','`'
3843 WCHAR Query[0x1000];
3846 return ERROR_INVALID_HANDLE;
3848 sprintfW(Query,Query_t,parent);
3850 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3851 if (rc != ERROR_SUCCESS)
3854 rc = MSI_ViewExecute(view, 0);
3855 if (rc != ERROR_SUCCESS)
3857 MSI_ViewClose(view);
3858 msiobj_release(&view->hdr);
3862 rc = MSI_ViewFetch(view,&row);
3863 if (rc != ERROR_SUCCESS)
3865 MSI_ViewClose(view);
3866 msiobj_release(&view->hdr);
3870 register_progid(package,row,clsid);
3872 msiobj_release(&row->hdr);
3873 MSI_ViewClose(view);
3874 msiobj_release(&view->hdr);
3878 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid)
3880 UINT rc = ERROR_SUCCESS;
3882 if (MSI_RecordIsNull(row,2))
3883 rc = register_progid_base(row,clsid);
3886 WCHAR buffer[0x1000];
3889 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3892 MSI_RecordGetStringW(row,2,buffer,&sz);
3893 rc = register_parent_progid(package,buffer,clsid);
3896 MSI_RecordGetStringW(row,1,buffer,&sz);
3897 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
3898 /* clasid is same as parent */
3899 RegCreateKeyW(hkey,szCLSID,&hkey2);
3900 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
3904 if (!MSI_RecordIsNull(row,4))
3907 MSI_RecordGetStringW(row,4,buffer,&sz);
3908 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
3909 (strlenW(buffer)+1) * sizeof(WCHAR));
3912 if (!MSI_RecordIsNull(row,5))
3913 FIXME ("UNHANDLED icon in Progid\n");
3920 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
3923 * Sigh, here I am just brute force registering all progids
3924 * this needs to be linked to the Classes that have been registered
3925 * but the easiest way to do that is to load all these stuff into
3926 * memory for easy checking.
3928 * Gives me something to continue to work toward.
3932 MSIRECORD * row = 0;
3933 static const WCHAR Query[] = {
3934 'S','E','L','E','C','T',' ','*',' ',
3935 'F','R','O','M',' ','P','r','o','g','I','d',0};
3938 return ERROR_INVALID_HANDLE;
3940 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3941 if (rc != ERROR_SUCCESS)
3942 return ERROR_SUCCESS;
3944 rc = MSI_ViewExecute(view, 0);
3945 if (rc != ERROR_SUCCESS)
3947 MSI_ViewClose(view);
3948 msiobj_release(&view->hdr);
3954 WCHAR clsid[0x1000];
3956 rc = MSI_ViewFetch(view,&row);
3957 if (rc != ERROR_SUCCESS)
3963 register_progid(package,row,clsid);
3964 ui_actiondata(package,szRegisterProgIdInfo,row);
3966 msiobj_release(&row->hdr);
3968 MSI_ViewClose(view);
3969 msiobj_release(&view->hdr);
3973 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
3976 WCHAR ProductCode[0x100];
3977 WCHAR SystemFolder[MAX_PATH];
3980 static const WCHAR szInstaller[] =
3981 {'I','n','s','t','a','l','l','e','r','\\',0};
3982 static const WCHAR szProductCode[] =
3983 {'P','r','o','d','u','c','t','C','o','d','e',0};
3984 static const WCHAR szFolder[] =
3985 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3988 MSI_GetPropertyW(package,szProductCode,ProductCode,&sz);
3989 if (strlenW(ProductCode)==0)
3990 return ERROR_FUNCTION_FAILED;
3993 MSI_GetPropertyW(package,szFolder,SystemFolder,&sz);
3994 strcatW(SystemFolder,szInstaller);
3995 strcatW(SystemFolder,ProductCode);
3996 create_full_pathW(SystemFolder);
3998 strcpyW(FilePath,SystemFolder);
3999 strcatW(FilePath,cszbs);
4000 strcatW(FilePath,icon_name);
4001 return ERROR_SUCCESS;
4004 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
4008 MSIRECORD * row = 0;
4009 static const WCHAR Query[] = {
4010 'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
4011 'S','h','o','r','t','c','u','t',0};
4017 return ERROR_INVALID_HANDLE;
4019 res = CoInitialize( NULL );
4022 ERR("CoInitialize failed\n");
4023 return ERROR_FUNCTION_FAILED;
4026 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4027 if (rc != ERROR_SUCCESS)
4028 return ERROR_SUCCESS;
4030 rc = MSI_ViewExecute(view, 0);
4031 if (rc != ERROR_SUCCESS)
4033 MSI_ViewClose(view);
4034 msiobj_release(&view->hdr);
4040 WCHAR target_file[MAX_PATH];
4041 WCHAR buffer[0x100];
4044 static const WCHAR szlnk[]={'.','l','n','k',0};
4046 rc = MSI_ViewFetch(view,&row);
4047 if (rc != ERROR_SUCCESS)
4054 MSI_RecordGetStringW(row,4,buffer,&sz);
4056 index = get_loaded_component(package,buffer);
4060 msiobj_release(&row->hdr);
4064 if (!package->components[index].Enabled ||
4065 !package->components[index].FeatureState)
4067 TRACE("Skipping shortcut creation due to disabled component\n");
4068 msiobj_release(&row->hdr);
4072 ui_actiondata(package,szCreateShortcuts,row);
4074 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
4075 &IID_IShellLinkW, (LPVOID *) &sl );
4079 ERR("Is IID_IShellLink\n");
4080 msiobj_release(&row->hdr);
4084 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
4087 ERR("Is IID_IPersistFile\n");
4088 msiobj_release(&row->hdr);
4093 MSI_RecordGetStringW(row,2,buffer,&sz);
4094 resolve_folder(package, buffer,target_file,FALSE,FALSE,NULL);
4097 MSI_RecordGetStringW(row,3,buffer,&sz);
4098 reduce_to_longfilename(buffer);
4099 strcatW(target_file,buffer);
4100 if (!strchrW(target_file,'.'))
4101 strcatW(target_file,szlnk);
4104 MSI_RecordGetStringW(row,5,buffer,&sz);
4105 if (strchrW(buffer,'['))
4108 deformat_string(package,buffer,&deformated);
4109 IShellLinkW_SetPath(sl,deformated);
4110 HeapFree(GetProcessHeap(),0,deformated);
4114 FIXME("UNHANDLED shortcut format, advertised shortcut\n");
4115 IPersistFile_Release( pf );
4116 IShellLinkW_Release( sl );
4117 msiobj_release(&row->hdr);
4121 if (!MSI_RecordIsNull(row,6))
4125 MSI_RecordGetStringW(row,6,buffer,&sz);
4126 deformat_string(package,buffer,&deformated);
4127 IShellLinkW_SetArguments(sl,deformated);
4128 HeapFree(GetProcessHeap(),0,deformated);
4131 if (!MSI_RecordIsNull(row,7))
4134 deformated = load_dynamic_stringW(row,7);
4135 IShellLinkW_SetDescription(sl,deformated);
4136 HeapFree(GetProcessHeap(),0,deformated);
4139 if (!MSI_RecordIsNull(row,8))
4140 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
4142 if (!MSI_RecordIsNull(row,9))
4144 WCHAR Path[MAX_PATH];
4148 MSI_RecordGetStringW(row,9,buffer,&sz);
4150 build_icon_path(package,buffer,Path);
4151 index = MSI_RecordGetInteger(row,10);
4153 IShellLinkW_SetIconLocation(sl,Path,index);
4156 if (!MSI_RecordIsNull(row,11))
4157 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
4159 if (!MSI_RecordIsNull(row,12))
4161 WCHAR Path[MAX_PATH];
4164 MSI_RecordGetStringW(row,12,buffer,&sz);
4165 resolve_folder(package, buffer, Path, FALSE, FALSE, NULL);
4166 IShellLinkW_SetWorkingDirectory(sl,Path);
4169 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
4170 IPersistFile_Save(pf,target_file,FALSE);
4172 IPersistFile_Release( pf );
4173 IShellLinkW_Release( sl );
4175 msiobj_release(&row->hdr);
4177 MSI_ViewClose(view);
4178 msiobj_release(&view->hdr);
4188 * 99% of the work done here is only done for
4189 * advertised installs. However this is where the
4190 * Icon table is processed and written out
4191 * so that is what I am going to do here.
4193 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
4197 MSIRECORD * row = 0;
4198 static const WCHAR Query[]={
4199 'S','E','L','E','C','T',' ','*',' ',
4200 'f','r','o','m',' ','I','c','o','n',0};
4204 return ERROR_INVALID_HANDLE;
4206 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4207 if (rc != ERROR_SUCCESS)
4208 return ERROR_SUCCESS;
4210 rc = MSI_ViewExecute(view, 0);
4211 if (rc != ERROR_SUCCESS)
4213 MSI_ViewClose(view);
4214 msiobj_release(&view->hdr);
4221 WCHAR FilePath[MAX_PATH];
4222 WCHAR FileName[MAX_PATH];
4225 rc = MSI_ViewFetch(view,&row);
4226 if (rc != ERROR_SUCCESS)
4233 MSI_RecordGetStringW(row,1,FileName,&sz);
4236 ERR("Unable to get FileName\n");
4237 msiobj_release(&row->hdr);
4241 build_icon_path(package,FileName,FilePath);
4243 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
4245 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
4246 FILE_ATTRIBUTE_NORMAL, NULL);
4248 if (the_file == INVALID_HANDLE_VALUE)
4250 ERR("Unable to create file %s\n",debugstr_w(FilePath));
4251 msiobj_release(&row->hdr);
4259 rc = MSI_RecordReadStream(row,2,buffer,&sz);
4260 if (rc != ERROR_SUCCESS)
4262 ERR("Failed to get stream\n");
4263 CloseHandle(the_file);
4264 DeleteFileW(FilePath);
4267 WriteFile(the_file,buffer,sz,&write,NULL);
4268 } while (sz == 1024);
4270 CloseHandle(the_file);
4271 msiobj_release(&row->hdr);
4273 MSI_ViewClose(view);
4274 msiobj_release(&view->hdr);
4279 /* Msi functions that seem appropriate here */
4280 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
4285 TRACE(" exteral attempt at action %s\n",szAction);
4288 return ERROR_FUNCTION_FAILED;
4290 return ERROR_FUNCTION_FAILED;
4292 szwAction = strdupAtoW(szAction);
4295 return ERROR_FUNCTION_FAILED;
4298 rc = MsiDoActionW(hInstall, szwAction);
4299 HeapFree(GetProcessHeap(),0,szwAction);
4303 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
4305 MSIPACKAGE *package;
4306 UINT ret = ERROR_INVALID_HANDLE;
4308 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
4310 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4313 ret = ACTION_PerformAction(package,szAction);
4314 msiobj_release( &package->hdr );
4319 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
4320 LPSTR szPathBuf, DWORD* pcchPathBuf)
4326 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
4329 return ERROR_FUNCTION_FAILED;
4331 return ERROR_FUNCTION_FAILED;
4333 szwFolder = strdupAtoW(szFolder);
4336 return ERROR_FUNCTION_FAILED;
4338 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
4340 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
4342 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
4343 *pcchPathBuf, NULL, NULL );
4345 HeapFree(GetProcessHeap(),0,szwFolder);
4346 HeapFree(GetProcessHeap(),0,szwPathBuf);
4351 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
4352 szPathBuf, DWORD* pcchPathBuf)
4354 WCHAR path[MAX_PATH];
4356 MSIPACKAGE *package;
4358 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
4360 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4362 return ERROR_INVALID_HANDLE;
4363 rc = resolve_folder(package, szFolder, path, FALSE, FALSE, NULL);
4364 msiobj_release( &package->hdr );
4366 if (rc == ERROR_SUCCESS && strlenW(path) > *pcchPathBuf)
4368 *pcchPathBuf = strlenW(path)+1;
4369 return ERROR_MORE_DATA;
4371 else if (rc == ERROR_SUCCESS)
4373 *pcchPathBuf = strlenW(path)+1;
4374 strcpyW(szPathBuf,path);
4375 TRACE("Returning Path %s\n",debugstr_w(path));
4382 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
4383 LPSTR szPathBuf, DWORD* pcchPathBuf)
4389 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
4392 return ERROR_FUNCTION_FAILED;
4394 return ERROR_FUNCTION_FAILED;
4396 szwFolder = strdupAtoW(szFolder);
4398 return ERROR_FUNCTION_FAILED;
4400 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
4402 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
4404 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
4405 *pcchPathBuf, NULL, NULL );
4407 HeapFree(GetProcessHeap(),0,szwFolder);
4408 HeapFree(GetProcessHeap(),0,szwPathBuf);
4413 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
4414 szPathBuf, DWORD* pcchPathBuf)
4416 WCHAR path[MAX_PATH];
4418 MSIPACKAGE *package;
4420 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
4422 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4424 return ERROR_INVALID_HANDLE;
4425 rc = resolve_folder(package, szFolder, path, TRUE, FALSE, NULL);
4426 msiobj_release( &package->hdr );
4428 if (rc == ERROR_SUCCESS && strlenW(path) > *pcchPathBuf)
4430 *pcchPathBuf = strlenW(path)+1;
4431 return ERROR_MORE_DATA;
4433 else if (rc == ERROR_SUCCESS)
4435 *pcchPathBuf = strlenW(path)+1;
4436 strcpyW(szPathBuf,path);
4437 TRACE("Returning Path %s\n",debugstr_w(path));
4444 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
4445 LPCSTR szFolderPath)
4448 LPWSTR szwFolderPath;
4452 return ERROR_FUNCTION_FAILED;
4454 return ERROR_FUNCTION_FAILED;
4456 szwFolder = strdupAtoW(szFolder);
4458 return ERROR_FUNCTION_FAILED;
4460 szwFolderPath = strdupAtoW(szFolderPath);
4463 HeapFree(GetProcessHeap(),0,szwFolder);
4464 return ERROR_FUNCTION_FAILED;
4467 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
4469 HeapFree(GetProcessHeap(),0,szwFolder);
4470 HeapFree(GetProcessHeap(),0,szwFolderPath);
4475 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
4476 LPCWSTR szFolderPath)
4479 WCHAR path[MAX_PATH];
4482 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
4485 return ERROR_INVALID_HANDLE;
4487 if (szFolderPath[0]==0)
4488 return ERROR_FUNCTION_FAILED;
4490 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
4491 return ERROR_FUNCTION_FAILED;
4493 resolve_folder(package,szFolder,path,FALSE,FALSE,&folder);
4496 return ERROR_INVALID_PARAMETER;
4498 strcpyW(folder->Property,szFolderPath);
4500 for (i = 0; i < package->loaded_folders; i++)
4501 package->folders[i].ResolvedTarget[0]=0;
4503 for (i = 0; i < package->loaded_folders; i++)
4504 resolve_folder(package, package->folders[i].Directory, path, FALSE,
4507 return ERROR_SUCCESS;
4510 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
4511 LPCWSTR szFolderPath)
4513 MSIPACKAGE *package;
4516 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
4518 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4519 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
4520 msiobj_release( &package->hdr );
4524 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, DWORD iRunMode)
4526 FIXME("STUB (%li)\n",iRunMode);
4531 * according to the docs when this is called it immediently recalculates all the
4532 * components states as well
4534 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
4535 INSTALLSTATE iState)
4537 LPWSTR szwFeature = NULL;
4540 szwFeature = strdupAtoW(szFeature);
4543 return ERROR_FUNCTION_FAILED;
4545 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
4547 HeapFree(GetProcessHeap(),0,szwFeature);
4552 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
4553 INSTALLSTATE iState)
4555 MSIPACKAGE* package;
4558 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
4560 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4562 return ERROR_INVALID_HANDLE;
4564 index = get_loaded_feature(package,szFeature);
4566 return ERROR_UNKNOWN_FEATURE;
4568 package->features[index].State = iState;
4570 return ERROR_SUCCESS;
4573 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
4574 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4576 LPWSTR szwFeature = NULL;
4579 szwFeature = strdupAtoW(szFeature);
4581 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
4583 HeapFree( GetProcessHeap(), 0 , szwFeature);
4588 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
4589 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4593 index = get_loaded_feature(package,szFeature);
4595 return ERROR_UNKNOWN_FEATURE;
4598 *piInstalled = package->features[index].State;
4602 if (package->features[index].Enabled)
4603 *piAction = INSTALLSTATE_LOCAL;
4605 *piAction = INSTALLSTATE_UNKNOWN;
4608 return ERROR_SUCCESS;
4611 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
4612 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4614 MSIPACKAGE* package;
4617 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
4620 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4622 return ERROR_INVALID_HANDLE;
4623 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
4624 msiobj_release( &package->hdr );
4628 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
4629 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4631 LPWSTR szwComponent= NULL;
4634 szwComponent= strdupAtoW(szComponent);
4636 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
4638 HeapFree( GetProcessHeap(), 0 , szwComponent);
4643 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
4644 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4648 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
4651 index = get_loaded_component(package,szComponent);
4653 return ERROR_UNKNOWN_COMPONENT;
4656 *piInstalled = package->components[index].State;
4660 if (package->components[index].Enabled &&
4661 package->components[index].FeatureState)
4662 *piAction = INSTALLSTATE_LOCAL;
4664 *piAction = INSTALLSTATE_UNKNOWN;
4667 return ERROR_SUCCESS;
4670 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
4671 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4673 MSIPACKAGE* package;
4676 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
4677 piInstalled, piAction);
4679 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4681 return ERROR_INVALID_HANDLE;
4682 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
4683 msiobj_release( &package->hdr );
4688 static UINT ACTION_Template(MSIPACKAGE *package)
4692 MSIRECORD * row = 0;
4693 static const WCHAR ExecSeqQuery[] = {0};
4695 rc = MsiDatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4696 if (rc != ERROR_SUCCESS)
4699 rc = MsiViewExecute(view, 0);
4700 if (rc != ERROR_SUCCESS)
4703 msiobj_release(&view->hdr);
4709 rc = MsiViewFetch(view,&row);
4710 if (rc != ERROR_SUCCESS)
4716 msiobj_release(&row->hdr);
4719 msiobj_release(&view->hdr);