2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installexecutesequence_table.asp
26 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/standard_actions_reference.asp
36 #include "wine/debug.h"
40 #include "msvcrt/fcntl.h"
47 #include "wine/unicode.h"
50 #define CUSTOM_ACTION_TYPE_MASK 0x3F
52 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
54 typedef struct tagMSIFEATURE
57 WCHAR Feature_Parent
[96];
59 WCHAR Description
[0x100];
68 INT Components
[1024]; /* yes hardcoded limit.... I am bad */
72 typedef struct tagMSICOMPONENT
75 WCHAR ComponentId
[96];
78 WCHAR Condition
[0x100];
87 typedef struct tagMSIFOLDER
90 WCHAR TargetDefault
[96];
91 WCHAR SourceDefault
[96];
93 WCHAR ResolvedTarget
[MAX_PATH
];
94 WCHAR ResolvedSource
[MAX_PATH
];
95 WCHAR Property
[MAX_PATH
]; /* initially set property */
98 /* 0 = uninitialized */
100 /* 2 = created remove if empty */
101 /* 3 = created persist if empty */
106 typedef struct tagMSIFILE
110 WCHAR FileName
[MAX_PATH
];
118 /* 0 = uninitialize */
119 /* 1 = not present */
120 /* 2 = present but replace */
121 /* 3 = present do not replace */
123 WCHAR SourcePath
[MAX_PATH
];
124 WCHAR TargetPath
[MAX_PATH
];
131 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
);
132 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
);
134 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
);
136 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
);
137 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
);
138 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
);
139 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
);
140 static UINT
ACTION_FileCost(MSIPACKAGE
*package
);
141 static UINT
ACTION_InstallFiles(MSIPACKAGE
*package
);
142 static UINT
ACTION_DuplicateFiles(MSIPACKAGE
*package
);
143 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
);
144 static UINT
ACTION_CustomAction(MSIPACKAGE
*package
,const WCHAR
*action
);
145 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
);
146 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
);
147 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
);
148 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
);
149 static UINT
ACTION_RegisterClassInfo(MSIPACKAGE
*package
);
150 static UINT
ACTION_RegisterProgIdInfo(MSIPACKAGE
*package
);
151 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
);
152 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
);
154 static UINT
HANDLE_CustomType1(MSIPACKAGE
*package
, const LPWSTR source
,
155 const LPWSTR target
, const INT type
);
156 static UINT
HANDLE_CustomType2(MSIPACKAGE
*package
, const LPWSTR source
,
157 const LPWSTR target
, const INT type
);
159 static DWORD
deformat_string(MSIPACKAGE
*package
, WCHAR
* ptr
,WCHAR
** data
);
160 static UINT
resolve_folder(MSIPACKAGE
*package
, LPCWSTR name
, LPWSTR path
,
161 BOOL source
, BOOL set_prop
, MSIFOLDER
**folder
);
163 static int track_tempfile(MSIPACKAGE
*package
, LPCWSTR name
, LPCWSTR path
);
166 * consts and values used
168 static const WCHAR cszSourceDir
[] = {'S','o','u','r','c','e','D','i','r',0};
169 static const WCHAR cszRootDrive
[] = {'R','O','O','T','D','R','I','V','E',0};
170 static const WCHAR cszTargetDir
[] = {'T','A','R','G','E','T','D','I','R',0};
171 static const WCHAR cszTempFolder
[]= {'T','e','m','p','F','o','l','d','e','r',0};
172 static const WCHAR cszDatabase
[]={'D','A','T','A','B','A','S','E',0};
173 static const WCHAR c_collen
[] = {'C',':','\\',0};
175 static const WCHAR cszlsb
[]={'[',0};
176 static const WCHAR cszrsb
[]={']',0};
177 static const WCHAR cszbs
[]={'\\',0};
179 const static WCHAR szCreateFolders
[] =
180 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
181 const static WCHAR szCostFinalize
[] =
182 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
183 const static WCHAR szInstallFiles
[] =
184 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
185 const static WCHAR szDuplicateFiles
[] =
186 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
187 const static WCHAR szWriteRegistryValues
[] =
188 {'W','r','i','t','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
189 const static WCHAR szCostInitialize
[] =
190 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
191 const static WCHAR szFileCost
[] = {'F','i','l','e','C','o','s','t',0};
192 const static WCHAR szInstallInitialize
[] =
193 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
194 const static WCHAR szInstallValidate
[] =
195 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
196 const static WCHAR szLaunchConditions
[] =
197 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
198 const static WCHAR szProcessComponents
[] =
199 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
200 const static WCHAR szRegisterTypeLibraries
[] =
201 {'R','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r',
203 const static WCHAR szRegisterClassInfo
[] =
204 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
205 const static WCHAR szRegisterProgIdInfo
[] =
206 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
207 const static WCHAR szCreateShortcuts
[] =
208 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
209 const static WCHAR szPublishProduct
[] =
210 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
212 /********************************************************
213 * helper functions to get around current HACKS and such
214 ********************************************************/
215 inline static void reduce_to_longfilename(WCHAR
* filename
)
217 if (strchrW(filename
,'|'))
219 WCHAR newname
[MAX_PATH
];
220 strcpyW(newname
,strchrW(filename
,'|')+1);
221 strcpyW(filename
,newname
);
225 inline static char *strdupWtoA( const WCHAR
*str
)
230 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
232 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
)))
233 WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
238 inline static WCHAR
*strdupAtoW( const char *str
)
243 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
244 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
245 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
250 inline static WCHAR
*load_dynamic_stringW(MSIRECORD
*row
, INT index
)
257 rc
= MSI_RecordGetStringW(row
,index
,NULL
,&sz
);
262 ret
= HeapAlloc(GetProcessHeap(),0,sz
* sizeof (WCHAR
));
263 rc
= MSI_RecordGetStringW(row
,index
,ret
,&sz
);
267 inline static int get_loaded_component(MSIPACKAGE
* package
, LPCWSTR Component
)
272 for (i
= 0; i
< package
->loaded_components
; i
++)
274 if (strcmpW(Component
,package
->components
[i
].Component
)==0)
283 inline static int get_loaded_feature(MSIPACKAGE
* package
, LPCWSTR Feature
)
288 for (i
= 0; i
< package
->loaded_features
; i
++)
290 if (strcmpW(Feature
,package
->features
[i
].Feature
)==0)
299 inline static int get_loaded_file(MSIPACKAGE
* package
, LPCWSTR file
)
304 for (i
= 0; i
< package
->loaded_files
; i
++)
306 if (strcmpW(file
,package
->files
[i
].File
)==0)
315 static int track_tempfile(MSIPACKAGE
*package
, LPCWSTR name
, LPCWSTR path
)
323 for (i
=0; i
< package
->loaded_files
; i
++)
324 if (strcmpW(package
->files
[i
].File
,name
)==0)
327 index
= package
->loaded_files
;
328 package
->loaded_files
++;
329 if (package
->loaded_files
== 1)
330 package
->files
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE
));
332 package
->files
= HeapReAlloc(GetProcessHeap(),0,
333 package
->files
, package
->loaded_files
* sizeof(MSIFILE
));
335 memset(&package
->files
[index
],0,sizeof(MSIFILE
));
337 strcpyW(package
->files
[index
].File
,name
);
338 strcpyW(package
->files
[index
].TargetPath
,path
);
339 package
->files
[index
].Temporary
= TRUE
;
341 TRACE("Tracking tempfile (%s)\n",debugstr_w(package
->files
[index
].File
));
346 void ACTION_remove_tracked_tempfiles(MSIPACKAGE
* package
)
353 for (i
= 0; i
< package
->loaded_files
; i
++)
355 if (package
->files
[i
].Temporary
)
356 DeleteFileW(package
->files
[i
].TargetPath
);
361 static void ui_progress(MSIPACKAGE
*package
, int a
, int b
, int c
, int d
)
365 row
= MSI_CreateRecord(4);
366 MSI_RecordSetInteger(row
,1,a
);
367 MSI_RecordSetInteger(row
,2,b
);
368 MSI_RecordSetInteger(row
,3,c
);
369 MSI_RecordSetInteger(row
,4,d
);
370 MSI_ProcessMessage(package
, INSTALLMESSAGE_PROGRESS
, row
);
371 msiobj_release(&row
->hdr
);
374 static void ui_actiondata(MSIPACKAGE
*package
, LPCWSTR action
, MSIRECORD
* record
)
376 static const WCHAR Query_t
[] =
377 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
378 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
379 ' ','\'','%','s','\'',0};
384 static WCHAR
*ActionFormat
=NULL
;
385 static WCHAR LastAction
[0x100] = {0};
389 if (strcmpW(LastAction
,action
)!=0)
391 sprintfW(Query
,Query_t
,action
);
392 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
393 if (rc
!= ERROR_SUCCESS
)
395 rc
= MSI_ViewExecute(view
, 0);
396 if (rc
!= ERROR_SUCCESS
)
401 rc
= MSI_ViewFetch(view
,&row
);
402 if (rc
!= ERROR_SUCCESS
)
408 if (MSI_RecordIsNull(row
,3))
410 msiobj_release(&row
->hdr
);
412 msiobj_release(&view
->hdr
);
417 HeapFree(GetProcessHeap(),0,ActionFormat
);
419 ActionFormat
= load_dynamic_stringW(row
,3);
420 strcpyW(LastAction
,action
);
421 msiobj_release(&row
->hdr
);
423 msiobj_release(&view
->hdr
);
435 ptr2
= strchrW(ptr
,'[');
438 strncpyW(tmp
,ptr
,ptr2
-ptr
);
440 strcatW(message
,tmp
);
443 data
= load_dynamic_stringW(record
,field
);
446 strcatW(message
,data
);
447 HeapFree(GetProcessHeap(),0,data
);
449 ptr
=strchrW(ptr2
,']');
454 strcatW(message
,ptr
);
459 row
= MSI_CreateRecord(1);
460 MSI_RecordSetStringW(row
,1,message
);
462 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, row
);
463 msiobj_release(&row
->hdr
);
467 static void ui_actionstart(MSIPACKAGE
*package
, LPCWSTR action
)
469 static const WCHAR template_s
[]=
470 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ','%','s','.',0};
471 static const WCHAR format
[] =
472 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
473 static const WCHAR Query_t
[] =
474 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
475 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
476 ' ','\'','%','s','\'',0};
482 WCHAR
*ActionText
=NULL
;
485 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
487 sprintfW(Query
,Query_t
,action
);
488 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
489 if (rc
!= ERROR_SUCCESS
)
491 rc
= MSI_ViewExecute(view
, 0);
492 if (rc
!= ERROR_SUCCESS
)
495 msiobj_release(&view
->hdr
);
498 rc
= MSI_ViewFetch(view
,&row
);
499 if (rc
!= ERROR_SUCCESS
)
502 msiobj_release(&view
->hdr
);
506 ActionText
= load_dynamic_stringW(row
,2);
507 msiobj_release(&row
->hdr
);
509 msiobj_release(&view
->hdr
);
511 sprintfW(message
,template_s
,timet
,action
,ActionText
);
513 row
= MSI_CreateRecord(1);
514 MSI_RecordSetStringW(row
,1,message
);
516 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, row
);
517 msiobj_release(&row
->hdr
);
518 HeapFree(GetProcessHeap(),0,ActionText
);
521 static void ui_actioninfo(MSIPACKAGE
*package
, LPCWSTR action
, BOOL start
,
525 static const WCHAR template_s
[]=
526 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ','%','s',
528 static const WCHAR template_e
[]=
529 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ','%','s',
530 '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ','%','i','.',0};
531 static const WCHAR format
[] =
532 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
536 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
538 sprintfW(message
,template_s
,timet
,action
);
540 sprintfW(message
,template_e
,timet
,action
,rc
);
542 row
= MSI_CreateRecord(1);
543 MSI_RecordSetStringW(row
,1,message
);
545 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
546 msiobj_release(&row
->hdr
);
549 /****************************************************
550 * TOP level entry points
551 *****************************************************/
553 UINT
ACTION_DoTopLevelINSTALL(MSIPACKAGE
*package
, LPCWSTR szPackagePath
,
554 LPCWSTR szCommandLine
)
559 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
564 WCHAR check
[MAX_PATH
];
568 strcpyW(pth
,szPackagePath
);
569 p
= strrchrW(pth
,'\\');
577 if (MSI_GetPropertyW(package
,cszSourceDir
,check
,&size
)
579 MSI_SetPropertyW(package
, cszSourceDir
, pth
);
585 ptr
= (LPWSTR
)szCommandLine
;
592 TRACE("Looking at %s\n",debugstr_w(ptr
));
594 ptr2
= strchrW(ptr
,'=');
600 while (*ptr
== ' ') ptr
++;
601 strncpyW(prop
,ptr
,ptr2
-ptr
);
606 while (*ptr
&& (quote
|| (!quote
&& *ptr
!=' ')))
619 strncpyW(val
,ptr2
,len
);
622 if (strlenW(prop
) > 0)
624 TRACE("Found commandline property (%s) = (%s)\n", debugstr_w(prop
), debugstr_w(val
));
625 MSI_SetPropertyW(package
,prop
,val
);
633 if (MSI_GetPropertyW(package
,szUILevel
,buffer
,&sz
) == ERROR_SUCCESS
)
635 if (atoiW(buffer
) >= INSTALLUILEVEL_REDUCED
)
637 rc
= ACTION_ProcessUISequence(package
);
638 if (rc
== ERROR_SUCCESS
)
639 rc
= ACTION_ProcessExecSequence(package
,TRUE
);
642 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
645 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
651 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
)
655 static const WCHAR ExecSeqQuery
[] = {
656 's','e','l','e','c','t',' ','*',' ',
658 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
659 'S','e','q','u','e','n','c','e',' ',
660 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
661 '>',' ','%','i',' ','o','r','d','e','r',' ',
662 'b','y',' ','S','e','q','u','e','n','c','e',0 };
665 static const WCHAR IVQuery
[] = {
666 's','e','l','e','c','t',' ','S','e','q','u','e','n','c','e',' ',
667 'f','r','o','m',' ','I','n','s','t','a','l','l',
668 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
669 'w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',' ',
670 '`','I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`',
677 rc
= MSI_DatabaseOpenViewW(package
->db
, IVQuery
, &view
);
678 if (rc
!= ERROR_SUCCESS
)
680 rc
= MSI_ViewExecute(view
, 0);
681 if (rc
!= ERROR_SUCCESS
)
684 msiobj_release(&view
->hdr
);
687 rc
= MSI_ViewFetch(view
,&row
);
688 if (rc
!= ERROR_SUCCESS
)
691 msiobj_release(&view
->hdr
);
694 seq
= MSI_RecordGetInteger(row
,1);
695 msiobj_release(&row
->hdr
);
697 msiobj_release(&view
->hdr
);
698 sprintfW(Query
,ExecSeqQuery
,seq
);
701 sprintfW(Query
,ExecSeqQuery
,0);
703 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
704 if (rc
== ERROR_SUCCESS
)
706 rc
= MSI_ViewExecute(view
, 0);
708 if (rc
!= ERROR_SUCCESS
)
711 msiobj_release(&view
->hdr
);
715 TRACE("Running the actions \n");
722 rc
= MSI_ViewFetch(view
,&row
);
723 if (rc
!= ERROR_SUCCESS
)
729 /* check conditions */
730 if (!MSI_RecordIsNull(row
,2))
733 cond
= load_dynamic_stringW(row
,2);
737 /* this is a hack to skip errors in the condition code */
738 if (MSI_EvaluateConditionW(package
, cond
) ==
741 HeapFree(GetProcessHeap(),0,cond
);
742 msiobj_release(&row
->hdr
);
746 HeapFree(GetProcessHeap(),0,cond
);
751 rc
= MSI_RecordGetStringW(row
,1,buffer
,&sz
);
752 if (rc
!= ERROR_SUCCESS
)
754 ERR("Error is %x\n",rc
);
755 msiobj_release(&row
->hdr
);
759 rc
= ACTION_PerformAction(package
,buffer
);
761 if (rc
!= ERROR_SUCCESS
)
763 ERR("Execution halted due to error (%i)\n",rc
);
764 msiobj_release(&row
->hdr
);
768 msiobj_release(&row
->hdr
);
772 msiobj_release(&view
->hdr
);
780 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
)
784 static const WCHAR ExecSeqQuery
[] = {
785 's','e','l','e','c','t',' ','*',' ',
786 'f','r','o','m',' ','I','n','s','t','a','l','l',
787 'U','I','S','e','q','u','e','n','c','e',' ',
788 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ', '>',' ','0',' ',
789 'o','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e',0};
791 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
793 if (rc
== ERROR_SUCCESS
)
795 rc
= MSI_ViewExecute(view
, 0);
797 if (rc
!= ERROR_SUCCESS
)
800 msiobj_release(&view
->hdr
);
804 TRACE("Running the actions \n");
812 rc
= MSI_ViewFetch(view
,&row
);
813 if (rc
!= ERROR_SUCCESS
)
819 /* check conditions */
820 if (!MSI_RecordIsNull(row
,2))
823 cond
= load_dynamic_stringW(row
,2);
827 /* this is a hack to skip errors in the condition code */
828 if (MSI_EvaluateConditionW(package
, cond
) ==
831 HeapFree(GetProcessHeap(),0,cond
);
832 msiobj_release(&row
->hdr
);
836 HeapFree(GetProcessHeap(),0,cond
);
841 rc
= MSI_RecordGetStringW(row
,1,buffer
,&sz
);
842 if (rc
!= ERROR_SUCCESS
)
844 ERR("Error is %x\n",rc
);
845 msiobj_release(&row
->hdr
);
849 rc
= ACTION_PerformAction(package
,buffer
);
851 if (rc
!= ERROR_SUCCESS
)
853 ERR("Execution halted due to error (%i)\n",rc
);
854 msiobj_release(&row
->hdr
);
858 msiobj_release(&row
->hdr
);
862 msiobj_release(&view
->hdr
);
869 /********************************************************
870 * ACTION helper functions and functions that perform the actions
871 *******************************************************/
874 * Alot of actions are really important even if they don't do anything
875 * explicit.. Lots of properties are set at the beginning of the installation
876 * CostFinalize does a bunch of work to translated the directories and such
878 * But until I get write access to the database that is hard, so I am going to
879 * hack it to see if I can get something to run.
881 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
)
883 UINT rc
= ERROR_SUCCESS
;
885 TRACE("Performing action (%s)\n",debugstr_w(action
));
886 ui_actioninfo(package
, action
, TRUE
, 0);
887 ui_actionstart(package
, action
);
888 ui_progress(package
,2,1,0,0);
890 /* pre install, setup and configuration block */
891 if (strcmpW(action
,szLaunchConditions
)==0)
892 rc
= ACTION_LaunchConditions(package
);
893 else if (strcmpW(action
,szCostInitialize
)==0)
894 rc
= ACTION_CostInitialize(package
);
895 else if (strcmpW(action
,szFileCost
)==0)
896 rc
= ACTION_FileCost(package
);
897 else if (strcmpW(action
,szCostFinalize
)==0)
898 rc
= ACTION_CostFinalize(package
);
899 else if (strcmpW(action
,szInstallValidate
)==0)
900 rc
= ACTION_InstallValidate(package
);
903 else if (strcmpW(action
,szProcessComponents
)==0)
904 rc
= ACTION_ProcessComponents(package
);
905 else if (strcmpW(action
,szInstallInitialize
)==0)
906 rc
= ACTION_InstallInitialize(package
);
907 else if (strcmpW(action
,szCreateFolders
)==0)
908 rc
= ACTION_CreateFolders(package
);
909 else if (strcmpW(action
,szInstallFiles
)==0)
910 rc
= ACTION_InstallFiles(package
);
911 else if (strcmpW(action
,szDuplicateFiles
)==0)
912 rc
= ACTION_DuplicateFiles(package
);
913 else if (strcmpW(action
,szWriteRegistryValues
)==0)
914 rc
= ACTION_WriteRegistryValues(package
);
915 else if (strcmpW(action
,szRegisterTypeLibraries
)==0)
916 rc
= ACTION_RegisterTypeLibraries(package
);
917 else if (strcmpW(action
,szRegisterClassInfo
)==0)
918 rc
= ACTION_RegisterClassInfo(package
);
919 else if (strcmpW(action
,szRegisterProgIdInfo
)==0)
920 rc
= ACTION_RegisterProgIdInfo(package
);
921 else if (strcmpW(action
,szCreateShortcuts
)==0)
922 rc
= ACTION_CreateShortcuts(package
);
923 else if (strcmpW(action
,szPublishProduct
)==0)
924 rc
= ACTION_PublishProduct(package
);
927 Called during iTunes but unimplemented and seem important
929 ResolveSource (sets SourceDir)
933 else if ((rc
= ACTION_CustomAction(package
,action
)) != ERROR_SUCCESS
)
935 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action
));
939 ui_actioninfo(package
, action
, FALSE
, rc
);
944 static UINT
ACTION_CustomAction(MSIPACKAGE
*package
,const WCHAR
*action
)
946 UINT rc
= ERROR_SUCCESS
;
949 WCHAR ExecSeqQuery
[1024] =
950 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','C','u','s','t','o'
951 ,'m','A','c','t','i','o','n',' ','w','h','e','r','e',' ','`','A','c','t','i'
952 ,'o','n','`',' ','=',' ','`',0};
953 static const WCHAR end
[]={'`',0};
957 WCHAR
*deformated
=NULL
;
959 strcatW(ExecSeqQuery
,action
);
960 strcatW(ExecSeqQuery
,end
);
962 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
964 if (rc
!= ERROR_SUCCESS
)
967 rc
= MSI_ViewExecute(view
, 0);
968 if (rc
!= ERROR_SUCCESS
)
971 msiobj_release(&view
->hdr
);
975 rc
= MSI_ViewFetch(view
,&row
);
976 if (rc
!= ERROR_SUCCESS
)
979 msiobj_release(&view
->hdr
);
983 type
= MSI_RecordGetInteger(row
,2);
985 source
= load_dynamic_stringW(row
,3);
986 target
= load_dynamic_stringW(row
,4);
988 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action
),type
,
989 debugstr_w(source
), debugstr_w(target
));
991 /* we are ignoring ALOT of flags and important synchronization stuff */
992 switch (type
& CUSTOM_ACTION_TYPE_MASK
)
994 case 1: /* DLL file stored in a Binary table stream */
995 rc
= HANDLE_CustomType1(package
,source
,target
,type
);
997 case 2: /* EXE file stored in a Binary table strem */
998 rc
= HANDLE_CustomType2(package
,source
,target
,type
);
1000 case 35: /* Directory set with formatted text. */
1001 case 51: /* Property set with formatted text. */
1002 deformat_string(package
,target
,&deformated
);
1003 rc
= MSI_SetPropertyW(package
,source
,deformated
);
1004 HeapFree(GetProcessHeap(),0,deformated
);
1007 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
1008 type
& CUSTOM_ACTION_TYPE_MASK
, debugstr_w(source
),
1009 debugstr_w(target
));
1012 HeapFree(GetProcessHeap(),0,source
);
1013 HeapFree(GetProcessHeap(),0,target
);
1014 msiobj_release(&row
->hdr
);
1015 MSI_ViewClose(view
);
1016 msiobj_release(&view
->hdr
);
1020 static UINT
store_binary_to_temp(MSIPACKAGE
*package
, const LPWSTR source
,
1025 if (MSI_GetPropertyW(package
, cszTempFolder
, tmp_file
, &sz
)
1027 GetTempPathW(MAX_PATH
,tmp_file
);
1029 strcatW(tmp_file
,source
);
1031 if (GetFileAttributesW(tmp_file
) != INVALID_FILE_ATTRIBUTES
)
1033 TRACE("File already exists\n");
1034 return ERROR_SUCCESS
;
1038 /* write out the file */
1041 MSIRECORD
* row
= 0;
1043 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','B','i'
1044 ,'n','a','r','y',' ','w','h','e','r','e',' ','N','a','m','e','=','`',0};
1045 static const WCHAR end
[]={'`',0};
1049 if (track_tempfile(package
, source
, tmp_file
)!=0)
1050 FIXME("File Name in temp tracking collision\n");
1052 the_file
= CreateFileW(tmp_file
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
1053 FILE_ATTRIBUTE_NORMAL
, NULL
);
1055 if (the_file
== INVALID_HANDLE_VALUE
)
1056 return ERROR_FUNCTION_FAILED
;
1058 strcatW(Query
,source
);
1061 rc
= MSI_DatabaseOpenViewW( package
->db
, Query
, &view
);
1062 if (rc
!= ERROR_SUCCESS
)
1065 rc
= MSI_ViewExecute(view
, 0);
1066 if (rc
!= ERROR_SUCCESS
)
1068 MSI_ViewClose(view
);
1069 msiobj_release(&view
->hdr
);
1073 rc
= MSI_ViewFetch(view
,&row
);
1074 if (rc
!= ERROR_SUCCESS
)
1076 MSI_ViewClose(view
);
1077 msiobj_release(&view
->hdr
);
1085 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
1086 if (rc
!= ERROR_SUCCESS
)
1088 ERR("Failed to get stream\n");
1089 CloseHandle(the_file
);
1090 DeleteFileW(tmp_file
);
1093 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
1094 } while (sz
== 1024);
1096 CloseHandle(the_file
);
1098 msiobj_release(&row
->hdr
);
1099 MSI_ViewClose(view
);
1100 msiobj_release(&view
->hdr
);
1103 return ERROR_SUCCESS
;
1107 typedef UINT __stdcall
CustomEntry(MSIHANDLE
);
1110 MSIPACKAGE
*package
;
1111 WCHAR target
[MAX_PATH
];
1112 WCHAR source
[MAX_PATH
];
1116 static DWORD WINAPI
DllThread(LPVOID info
)
1120 thread_struct
*stuff
;
1123 stuff
= (thread_struct
*)info
;
1125 TRACE("Asynchronous start (%s, %s) \n", debugstr_w(stuff
->source
),
1126 debugstr_w(stuff
->target
));
1128 DLL
= LoadLibraryW(stuff
->source
);
1131 proc
= strdupWtoA( stuff
->target
);
1132 fn
= (CustomEntry
*)GetProcAddress(DLL
,proc
);
1136 MSIPACKAGE
*package
= stuff
->package
;
1138 TRACE("Calling function\n");
1139 hPackage
= msiobj_findhandle( &package
->hdr
);
1141 ERR("Handle for object %p not found\n", package
);
1143 msiobj_release( &package
->hdr
);
1146 ERR("Cannot load functon\n");
1148 HeapFree(GetProcessHeap(),0,proc
);
1152 ERR("Unable to load library\n");
1153 msiobj_release( &stuff
->package
->hdr
);
1154 HeapFree( GetProcessHeap(), 0, info
);
1159 static UINT
HANDLE_CustomType1(MSIPACKAGE
*package
, const LPWSTR source
,
1160 const LPWSTR target
, const INT type
)
1162 WCHAR tmp_file
[MAX_PATH
];
1167 store_binary_to_temp(package
, source
, tmp_file
);
1169 TRACE("Calling function %s from %s\n",debugstr_w(target
),
1170 debugstr_w(tmp_file
));
1172 if (!strchrW(tmp_file
,'.'))
1174 static const WCHAR dot
[]={'.',0};
1175 strcatW(tmp_file
,dot
);
1180 /* DWORD ThreadId; */
1181 thread_struct
*info
= HeapAlloc( GetProcessHeap(), 0, sizeof(*info
) );
1183 /* msiobj_addref( &package->hdr ); */
1184 info
->package
= package
;
1185 strcpyW(info
->target
,target
);
1186 strcpyW(info
->source
,tmp_file
);
1187 TRACE("Start Asynchronous execution\n");
1188 FIXME("DATABASE NOT THREADSAFE... not starting\n");
1189 /* CreateThread(NULL,0,DllThread,(LPVOID)&info,0,&ThreadId); */
1190 /* FIXME: release the package if the CreateThread fails */
1191 HeapFree( GetProcessHeap(), 0, info
);
1192 return ERROR_SUCCESS
;
1195 DLL
= LoadLibraryW(tmp_file
);
1198 proc
= strdupWtoA( target
);
1199 fn
= (CustomEntry
*)GetProcAddress(DLL
,proc
);
1204 TRACE("Calling function\n");
1205 hPackage
= msiobj_findhandle( &package
->hdr
);
1207 ERR("Handle for object %p not found\n", package
);
1209 msiobj_release( &package
->hdr
);
1212 ERR("Cannot load functon\n");
1214 HeapFree(GetProcessHeap(),0,proc
);
1218 ERR("Unable to load library\n");
1220 return ERROR_SUCCESS
;
1223 static UINT
HANDLE_CustomType2(MSIPACKAGE
*package
, const LPWSTR source
,
1224 const LPWSTR target
, const INT type
)
1226 WCHAR tmp_file
[MAX_PATH
*2];
1228 PROCESS_INFORMATION info
;
1231 static const WCHAR spc
[] = {' ',0};
1233 memset(&si
,0,sizeof(STARTUPINFOW
));
1234 memset(&info
,0,sizeof(PROCESS_INFORMATION
));
1236 store_binary_to_temp(package
, source
, tmp_file
);
1238 strcatW(tmp_file
,spc
);
1239 deformat_string(package
,target
,&deformated
);
1240 strcatW(tmp_file
,deformated
);
1242 HeapFree(GetProcessHeap(),0,deformated
);
1244 TRACE("executing exe %s \n",debugstr_w(tmp_file
));
1246 rc
= CreateProcessW(NULL
, tmp_file
, NULL
, NULL
, FALSE
, 0, NULL
,
1247 c_collen
, &si
, &info
);
1251 ERR("Unable to execute command\n");
1252 return ERROR_SUCCESS
;
1256 WaitForSingleObject(info
.hProcess
,INFINITE
);
1258 return ERROR_SUCCESS
;
1261 /***********************************************************************
1264 * Recursively create all directories in the path.
1266 * shamelessly stolen from setupapi/queue.c
1268 static BOOL
create_full_pathW(const WCHAR
*path
)
1274 new_path
= HeapAlloc(GetProcessHeap(), 0, (strlenW(path
) + 1) *
1276 strcpyW(new_path
, path
);
1278 while((len
= strlenW(new_path
)) && new_path
[len
- 1] == '\\')
1279 new_path
[len
- 1] = 0;
1281 while(!CreateDirectoryW(new_path
, NULL
))
1284 DWORD last_error
= GetLastError();
1285 if(last_error
== ERROR_ALREADY_EXISTS
)
1288 if(last_error
!= ERROR_PATH_NOT_FOUND
)
1294 if(!(slash
= strrchrW(new_path
, '\\')))
1300 len
= slash
- new_path
;
1302 if(!create_full_pathW(new_path
))
1307 new_path
[len
] = '\\';
1310 HeapFree(GetProcessHeap(), 0, new_path
);
1315 * Also we cannot enable/disable components either, so for now I am just going
1316 * to do all the directories for all the components.
1318 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
)
1320 static const WCHAR ExecSeqQuery
[] = {
1321 's','e','l','e','c','t',' ','D','i','r','e','c','t','o','r','y','_',' ',
1322 'f','r','o','m',' ','C','r','e','a','t','e','F','o','l','d','e','r',0 };
1327 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
1328 if (rc
!= ERROR_SUCCESS
)
1329 return ERROR_SUCCESS
;
1331 rc
= MSI_ViewExecute(view
, 0);
1332 if (rc
!= ERROR_SUCCESS
)
1334 MSI_ViewClose(view
);
1335 msiobj_release(&view
->hdr
);
1342 WCHAR full_path
[MAX_PATH
];
1344 MSIRECORD
*row
= NULL
, *uirow
;
1346 rc
= MSI_ViewFetch(view
,&row
);
1347 if (rc
!= ERROR_SUCCESS
)
1354 rc
= MSI_RecordGetStringW(row
,1,dir
,&sz
);
1356 if (rc
!= ERROR_SUCCESS
)
1358 ERR("Unable to get folder id \n");
1359 msiobj_release(&row
->hdr
);
1364 rc
= resolve_folder(package
,dir
,full_path
,FALSE
,FALSE
,&folder
);
1366 if (rc
!= ERROR_SUCCESS
)
1368 ERR("Unable to resolve folder id %s\n",debugstr_w(dir
));
1369 msiobj_release(&row
->hdr
);
1373 TRACE("Folder is %s\n",debugstr_w(full_path
));
1376 uirow
= MSI_CreateRecord(1);
1377 MSI_RecordSetStringW(uirow
,1,full_path
);
1378 ui_actiondata(package
,szCreateFolders
,uirow
);
1379 msiobj_release( &uirow
->hdr
);
1381 if (folder
->State
== 0)
1382 create_full_pathW(full_path
);
1386 msiobj_release(&row
->hdr
);
1388 MSI_ViewClose(view
);
1389 msiobj_release(&view
->hdr
);
1394 static int load_component(MSIPACKAGE
* package
, MSIRECORD
* row
)
1396 int index
= package
->loaded_components
;
1399 /* fill in the data */
1401 package
->loaded_components
++;
1402 if (package
->loaded_components
== 1)
1403 package
->components
= HeapAlloc(GetProcessHeap(),0,
1404 sizeof(MSICOMPONENT
));
1406 package
->components
= HeapReAlloc(GetProcessHeap(),0,
1407 package
->components
, package
->loaded_components
*
1408 sizeof(MSICOMPONENT
));
1410 memset(&package
->components
[index
],0,sizeof(MSICOMPONENT
));
1413 MSI_RecordGetStringW(row
,1,package
->components
[index
].Component
,&sz
);
1415 TRACE("Loading Component %s\n",
1416 debugstr_w(package
->components
[index
].Component
));
1419 if (!MSI_RecordIsNull(row
,2))
1420 MSI_RecordGetStringW(row
,2,package
->components
[index
].ComponentId
,&sz
);
1423 MSI_RecordGetStringW(row
,3,package
->components
[index
].Directory
,&sz
);
1425 package
->components
[index
].Attributes
= MSI_RecordGetInteger(row
,4);
1428 MSI_RecordGetStringW(row
,5,package
->components
[index
].Condition
,&sz
);
1431 MSI_RecordGetStringW(row
,6,package
->components
[index
].KeyPath
,&sz
);
1433 package
->components
[index
].State
= INSTALLSTATE_UNKNOWN
;
1434 package
->components
[index
].Enabled
= TRUE
;
1435 package
->components
[index
].FeatureState
= FALSE
;
1440 static void load_feature(MSIPACKAGE
* package
, MSIRECORD
* row
)
1442 int index
= package
->loaded_features
;
1444 static const WCHAR Query1
[] = {'S','E','L','E','C','T',' ','C','o','m','p',
1445 'o','n','e','n','t','_',' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1446 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ','F','e',
1447 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1448 static const WCHAR Query2
[] = {'S','E','L','E','C','T',' ','*',' ','F','R',
1449 'O','M',' ','C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ','C',
1450 'o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1458 /* fill in the data */
1460 package
->loaded_features
++;
1461 if (package
->loaded_features
== 1)
1462 package
->features
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE
));
1464 package
->features
= HeapReAlloc(GetProcessHeap(),0,package
->features
,
1465 package
->loaded_features
* sizeof(MSIFEATURE
));
1467 memset(&package
->features
[index
],0,sizeof(MSIFEATURE
));
1470 MSI_RecordGetStringW(row
,1,package
->features
[index
].Feature
,&sz
);
1472 TRACE("Loading feature %s\n",debugstr_w(package
->features
[index
].Feature
));
1475 if (!MSI_RecordIsNull(row
,2))
1476 MSI_RecordGetStringW(row
,2,package
->features
[index
].Feature_Parent
,&sz
);
1479 if (!MSI_RecordIsNull(row
,3))
1480 MSI_RecordGetStringW(row
,3,package
->features
[index
].Title
,&sz
);
1483 if (!MSI_RecordIsNull(row
,4))
1484 MSI_RecordGetStringW(row
,4,package
->features
[index
].Description
,&sz
);
1486 if (!MSI_RecordIsNull(row
,5))
1487 package
->features
[index
].Display
= MSI_RecordGetInteger(row
,5);
1489 package
->features
[index
].Level
= MSI_RecordGetInteger(row
,6);
1492 if (!MSI_RecordIsNull(row
,7))
1493 MSI_RecordGetStringW(row
,7,package
->features
[index
].Directory
,&sz
);
1495 package
->features
[index
].Attributes
= MSI_RecordGetInteger(row
,8);
1496 package
->features
[index
].State
= INSTALLSTATE_UNKNOWN
;
1498 /* load feature components */
1500 sprintfW(Query
,Query1
,package
->features
[index
].Feature
);
1501 rc
= MSI_DatabaseOpenViewW(package
->db
,Query
,&view
);
1502 if (rc
!= ERROR_SUCCESS
)
1504 rc
= MSI_ViewExecute(view
,0);
1505 if (rc
!= ERROR_SUCCESS
)
1507 MSI_ViewClose(view
);
1508 msiobj_release(&view
->hdr
);
1514 WCHAR buffer
[0x100];
1517 INT cnt
= package
->features
[index
].ComponentCount
;
1519 rc
= MSI_ViewFetch(view
,&row2
);
1520 if (rc
!= ERROR_SUCCESS
)
1524 MSI_RecordGetStringW(row2
,1,buffer
,&sz
);
1526 /* check to see if the component is already loaded */
1527 c_indx
= get_loaded_component(package
,buffer
);
1530 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer
),
1532 package
->features
[index
].Components
[cnt
] = c_indx
;
1533 package
->features
[index
].ComponentCount
++;
1536 sprintfW(Query
,Query2
,buffer
);
1538 rc
= MSI_DatabaseOpenViewW(package
->db
,Query
,&view2
);
1539 if (rc
!= ERROR_SUCCESS
)
1541 msiobj_release( &row2
->hdr
);
1544 rc
= MSI_ViewExecute(view2
,0);
1545 if (rc
!= ERROR_SUCCESS
)
1547 msiobj_release( &row2
->hdr
);
1548 MSI_ViewClose(view2
);
1549 msiobj_release( &view2
->hdr
);
1556 rc
= MSI_ViewFetch(view2
,&row3
);
1557 if (rc
!= ERROR_SUCCESS
)
1559 c_indx
= load_component(package
,row3
);
1560 msiobj_release( &row3
->hdr
);
1562 package
->features
[index
].Components
[cnt
] = c_indx
;
1563 package
->features
[index
].ComponentCount
++;
1565 MSI_ViewClose(view2
);
1566 msiobj_release( &view2
->hdr
);
1567 msiobj_release( &row2
->hdr
);
1569 MSI_ViewClose(view
);
1570 msiobj_release(&view
->hdr
);
1574 * I am not doing any of the costing functionality yet.
1575 * Mostly looking at doing the Component and Feature loading
1577 * The native MSI does ALOT of modification to tables here. Mostly adding alot
1578 * of temporary columns to the Feature and Component tables.
1580 * note: native msi also tracks the short filename. but I am only going to
1581 * track the long ones. Also looking at this directory table
1582 * it appears that the directory table does not get the parents
1583 * resolved base on property only based on their entrys in the
1586 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
)
1592 static const WCHAR Query_all
[] = {
1593 'S','E','L','E','C','T',' ','*',' ',
1594 'F','R','O','M',' ','F','e','a','t','u','r','e',0};
1595 static const WCHAR szCosting
[] = {
1596 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1597 static const WCHAR szZero
[] = { '0', 0 };
1599 MSI_SetPropertyW(package
, szCosting
, szZero
);
1600 MSI_SetPropertyW(package
, cszRootDrive
, c_collen
);
1603 rc
= MSI_DatabaseOpenViewW(package
->db
,Query_all
,&view
);
1604 if (rc
!= ERROR_SUCCESS
)
1606 rc
= MSI_ViewExecute(view
,0);
1607 if (rc
!= ERROR_SUCCESS
)
1609 MSI_ViewClose(view
);
1610 msiobj_release(&view
->hdr
);
1617 rc
= MSI_ViewFetch(view
,&row
);
1618 if (rc
!= ERROR_SUCCESS
)
1621 load_feature(package
,row
);
1622 msiobj_release(&row
->hdr
);
1624 MSI_ViewClose(view
);
1625 msiobj_release(&view
->hdr
);
1627 return ERROR_SUCCESS
;
1630 static UINT
load_file(MSIPACKAGE
* package
, MSIRECORD
* row
)
1632 DWORD index
= package
->loaded_files
;
1634 WCHAR buffer
[0x100];
1637 /* fill in the data */
1639 package
->loaded_files
++;
1640 if (package
->loaded_files
== 1)
1641 package
->files
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE
));
1643 package
->files
= HeapReAlloc(GetProcessHeap(),0,
1644 package
->files
, package
->loaded_files
* sizeof(MSIFILE
));
1646 memset(&package
->files
[index
],0,sizeof(MSIFILE
));
1649 MSI_RecordGetStringW(row
,1,package
->files
[index
].File
,&sz
);
1652 MSI_RecordGetStringW(row
,2,buffer
,&sz
);
1654 package
->files
[index
].ComponentIndex
= -1;
1655 for (i
= 0; i
< package
->loaded_components
; i
++)
1656 if (strcmpW(package
->components
[i
].Component
,buffer
)==0)
1658 package
->files
[index
].ComponentIndex
= i
;
1661 if (package
->files
[index
].ComponentIndex
== -1)
1662 ERR("Unfound Component %s\n",debugstr_w(buffer
));
1665 MSI_RecordGetStringW(row
,3,package
->files
[index
].FileName
,&sz
);
1667 reduce_to_longfilename(package
->files
[index
].FileName
);
1669 package
->files
[index
].FileSize
= MSI_RecordGetInteger(row
,4);
1672 if (!MSI_RecordIsNull(row
,5))
1673 MSI_RecordGetStringW(row
,5,package
->files
[index
].Version
,&sz
);
1676 if (!MSI_RecordIsNull(row
,6))
1677 MSI_RecordGetStringW(row
,6,package
->files
[index
].Language
,&sz
);
1679 if (!MSI_RecordIsNull(row
,7))
1680 package
->files
[index
].Attributes
= MSI_RecordGetInteger(row
,7);
1682 package
->files
[index
].Sequence
= MSI_RecordGetInteger(row
,8);
1684 package
->files
[index
].Temporary
= FALSE
;
1685 package
->files
[index
].State
= 0;
1687 TRACE("File Loaded (%s)\n",debugstr_w(package
->files
[index
].File
));
1689 return ERROR_SUCCESS
;
1692 static UINT
ACTION_FileCost(MSIPACKAGE
*package
)
1697 static const WCHAR Query
[] = {
1698 'S','E','L','E','C','T',' ','*',' ',
1699 'F','R','O','M',' ','F','i','l','e',' ',
1700 'O','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e', 0};
1703 return ERROR_INVALID_HANDLE
;
1705 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1706 if (rc
!= ERROR_SUCCESS
)
1707 return ERROR_SUCCESS
;
1709 rc
= MSI_ViewExecute(view
, 0);
1710 if (rc
!= ERROR_SUCCESS
)
1712 MSI_ViewClose(view
);
1713 msiobj_release(&view
->hdr
);
1714 return ERROR_SUCCESS
;
1719 rc
= MSI_ViewFetch(view
,&row
);
1720 if (rc
!= ERROR_SUCCESS
)
1725 load_file(package
,row
);
1726 msiobj_release(&row
->hdr
);
1728 MSI_ViewClose(view
);
1729 msiobj_release(&view
->hdr
);
1731 return ERROR_SUCCESS
;
1734 static INT
load_folder(MSIPACKAGE
*package
, const WCHAR
* dir
)
1738 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','D','i','r','e','c',
1739 't','o','r','y',' ','w','h','e','r','e',' ','`','D','i','r','e','c','t',
1740 'o','r','y','`',' ','=',' ','`',0};
1741 static const WCHAR end
[]={'`',0};
1744 WCHAR targetbuffer
[0x100];
1745 WCHAR
*srcdir
= NULL
;
1746 WCHAR
*targetdir
= NULL
;
1747 WCHAR parent
[0x100];
1749 MSIRECORD
* row
= 0;
1753 TRACE("Looking for dir %s\n",debugstr_w(dir
));
1755 for (i
= 0; i
< package
->loaded_folders
; i
++)
1757 if (strcmpW(package
->folders
[i
].Directory
,dir
)==0)
1759 TRACE(" %s retuning on index %lu\n",debugstr_w(dir
),i
);
1764 TRACE("Working to load %s\n",debugstr_w(dir
));
1766 index
= package
->loaded_folders
;
1768 package
->loaded_folders
++;
1769 if (package
->loaded_folders
== 1)
1770 package
->folders
= HeapAlloc(GetProcessHeap(),0,
1773 package
->folders
= HeapReAlloc(GetProcessHeap(),0,
1774 package
->folders
, package
->loaded_folders
*
1777 memset(&package
->folders
[index
],0,sizeof(MSIFOLDER
));
1779 strcpyW(package
->folders
[index
].Directory
,dir
);
1784 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1786 if (rc
!= ERROR_SUCCESS
)
1789 rc
= MSI_ViewExecute(view
, 0);
1790 if (rc
!= ERROR_SUCCESS
)
1792 MSI_ViewClose(view
);
1793 msiobj_release(&view
->hdr
);
1797 rc
= MSI_ViewFetch(view
,&row
);
1798 if (rc
!= ERROR_SUCCESS
)
1800 MSI_ViewClose(view
);
1801 msiobj_release(&view
->hdr
);
1806 MSI_RecordGetStringW(row
,3,targetbuffer
,&sz
);
1807 targetdir
=targetbuffer
;
1809 /* split src and target dir */
1810 if (strchrW(targetdir
,':'))
1812 srcdir
=strchrW(targetdir
,':');
1819 /* for now only pick long filename versions */
1820 if (strchrW(targetdir
,'|'))
1822 targetdir
= strchrW(targetdir
,'|');
1826 if (srcdir
&& strchrW(srcdir
,'|'))
1828 srcdir
= strchrW(srcdir
,'|');
1833 /* now check for root dirs */
1834 if (targetdir
[0] == '.' && targetdir
[1] == 0)
1837 if (srcdir
&& srcdir
[0] == '.' && srcdir
[1] == 0)
1841 strcpyW(package
->folders
[index
].TargetDefault
,targetdir
);
1844 strcpyW(package
->folders
[index
].SourceDefault
,srcdir
);
1846 strcpyW(package
->folders
[index
].SourceDefault
,targetdir
);
1848 if (MSI_RecordIsNull(row
,2))
1853 MSI_RecordGetStringW(row
,2,parent
,&sz
);
1858 i
= load_folder(package
,parent
);
1859 package
->folders
[index
].ParentIndex
= i
;
1860 TRACE("Parent is index %i... %s %s\n",
1861 package
->folders
[index
].ParentIndex
,
1862 debugstr_w(package
->folders
[package
->folders
[index
].ParentIndex
].Directory
),
1863 debugstr_w(parent
));
1866 package
->folders
[index
].ParentIndex
= -2;
1869 rc
= MSI_GetPropertyW(package
, dir
, package
->folders
[index
].Property
, &sz
);
1870 if (rc
!= ERROR_SUCCESS
)
1871 package
->folders
[index
].Property
[0]=0;
1873 msiobj_release(&row
->hdr
);
1874 MSI_ViewClose(view
);
1875 msiobj_release(&view
->hdr
);
1876 TRACE(" %s retuning on index %i\n",debugstr_w(dir
),index
);
1880 static UINT
resolve_folder(MSIPACKAGE
*package
, LPCWSTR name
, LPWSTR path
,
1881 BOOL source
, BOOL set_prop
, MSIFOLDER
**folder
)
1884 UINT rc
= ERROR_SUCCESS
;
1887 TRACE("Working to resolve %s\n",debugstr_w(name
));
1892 /* special resolving for Target and Source root dir */
1893 if (strcmpW(name
,cszTargetDir
)==0 || strcmpW(name
,cszSourceDir
)==0)
1898 rc
= MSI_GetPropertyW(package
,cszTargetDir
,path
,&sz
);
1899 if (rc
!= ERROR_SUCCESS
)
1902 rc
= MSI_GetPropertyW(package
,cszRootDrive
,path
,&sz
);
1904 MSI_SetPropertyW(package
,cszTargetDir
,path
);
1907 *folder
= &(package
->folders
[0]);
1913 rc
= MSI_GetPropertyW(package
,cszSourceDir
,path
,&sz
);
1914 if (rc
!= ERROR_SUCCESS
)
1917 rc
= MSI_GetPropertyW(package
,cszDatabase
,path
,&sz
);
1918 if (rc
== ERROR_SUCCESS
)
1920 LPWSTR ptr
= strrchrW(path
,'\\');
1929 *folder
= &(package
->folders
[0]);
1934 for (i
= 0; i
< package
->loaded_folders
; i
++)
1936 if (strcmpW(package
->folders
[i
].Directory
,name
)==0)
1940 if (i
>= package
->loaded_folders
)
1941 return ERROR_FUNCTION_FAILED
;
1944 *folder
= &(package
->folders
[i
]);
1946 if (!source
&& package
->folders
[i
].ResolvedTarget
[0])
1948 strcpyW(path
,package
->folders
[i
].ResolvedTarget
);
1949 TRACE(" already resolved to %s\n",debugstr_w(path
));
1950 return ERROR_SUCCESS
;
1952 else if (source
&& package
->folders
[i
].ResolvedSource
[0])
1954 strcpyW(path
,package
->folders
[i
].ResolvedSource
);
1955 return ERROR_SUCCESS
;
1957 else if (!source
&& package
->folders
[i
].Property
[0])
1959 strcpyW(path
,package
->folders
[i
].Property
);
1960 TRACE(" internally set to %s\n",debugstr_w(path
));
1962 MSI_SetPropertyW(package
,name
,path
);
1963 return ERROR_SUCCESS
;
1966 if (package
->folders
[i
].ParentIndex
>= 0)
1968 TRACE(" ! Parent is %s\n", debugstr_w(package
->folders
[
1969 package
->folders
[i
].ParentIndex
].Directory
));
1970 resolve_folder(package
, package
->folders
[
1971 package
->folders
[i
].ParentIndex
].Directory
, path
,source
,
1976 if (package
->folders
[i
].TargetDefault
[0])
1978 strcatW(path
,package
->folders
[i
].TargetDefault
);
1979 strcatW(path
,cszbs
);
1981 strcpyW(package
->folders
[i
].ResolvedTarget
,path
);
1982 TRACE(" resolved into %s\n",debugstr_w(path
));
1984 MSI_SetPropertyW(package
,name
,path
);
1988 if (package
->folders
[i
].SourceDefault
[0])
1990 strcatW(path
,package
->folders
[i
].SourceDefault
);
1991 strcatW(path
,cszbs
);
1993 strcpyW(package
->folders
[i
].ResolvedSource
,path
);
2000 * Alot is done in this function aside from just the costing.
2001 * The costing needs to be implemented at some point but for now I am going
2002 * to focus on the directory building
2005 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
)
2007 static const WCHAR ExecSeqQuery
[] = {
2008 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2009 'D','i','r','e','c','t','o','r','y',0};
2010 static const WCHAR ConditionQuery
[] = {
2011 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2012 'C','o','n','d','i','t','i','o','n',0};
2013 static const WCHAR szCosting
[] = {
2014 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2015 static const WCHAR szOne
[] = { '1', 0 };
2020 TRACE("Building Directory properties\n");
2022 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2023 if (rc
== ERROR_SUCCESS
)
2025 rc
= MSI_ViewExecute(view
, 0);
2026 if (rc
!= ERROR_SUCCESS
)
2028 MSI_ViewClose(view
);
2029 msiobj_release(&view
->hdr
);
2036 WCHAR path
[MAX_PATH
];
2037 MSIRECORD
* row
= 0;
2040 rc
= MSI_ViewFetch(view
,&row
);
2041 if (rc
!= ERROR_SUCCESS
)
2048 MSI_RecordGetStringW(row
,1,name
,&sz
);
2050 /* This helper function now does ALL the work */
2051 TRACE("Dir %s ...\n",debugstr_w(name
));
2052 load_folder(package
,name
);
2053 resolve_folder(package
,name
,path
,FALSE
,TRUE
,NULL
);
2054 TRACE("resolves to %s\n",debugstr_w(path
));
2056 msiobj_release(&row
->hdr
);
2058 MSI_ViewClose(view
);
2059 msiobj_release(&view
->hdr
);
2062 TRACE("File calculations %i files\n",package
->loaded_files
);
2064 for (i
= 0; i
< package
->loaded_files
; i
++)
2066 MSICOMPONENT
* comp
= NULL
;
2067 MSIFILE
* file
= NULL
;
2069 file
= &package
->files
[i
];
2070 if (file
->ComponentIndex
>= 0)
2071 comp
= &package
->components
[file
->ComponentIndex
];
2075 /* calculate target */
2076 resolve_folder(package
, comp
->Directory
, file
->TargetPath
, FALSE
,
2078 strcatW(file
->TargetPath
,file
->FileName
);
2080 TRACE("file %s resolves to %s\n",
2081 debugstr_w(file
->File
),debugstr_w(file
->TargetPath
));
2083 if (GetFileAttributesW(file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
2086 comp
->Cost
+= file
->FileSize
;
2090 if (file
->Version
[0])
2096 WCHAR filever
[0x100];
2097 static const WCHAR name
[] =
2098 {'\\','V','a','r','F','i','l','e','I','n','f','o',
2099 '\\','F','i','l','e','V','e','r','s','i','o','n',0};
2101 FIXME("Version comparison.. Untried Untested and most "
2102 "likely very very wrong\n");
2103 versize
= GetFileVersionInfoSizeW(file
->TargetPath
,&handle
);
2104 version
= HeapAlloc(GetProcessHeap(),0,versize
);
2105 GetFileVersionInfoW(file
->TargetPath
, 0, versize
, version
);
2107 VerQueryValueW(version
,name
,(LPVOID
)filever
,&sz
);
2108 HeapFree(GetProcessHeap(),0,version
);
2110 if (strcmpW(version
,file
->Version
)<0)
2113 FIXME("cost should be diff in size\n");
2114 comp
->Cost
+= file
->FileSize
;
2125 TRACE("Evaluating Condition Table\n");
2127 rc
= MSI_DatabaseOpenViewW(package
->db
, ConditionQuery
, &view
);
2128 if (rc
== ERROR_SUCCESS
)
2130 rc
= MSI_ViewExecute(view
, 0);
2131 if (rc
!= ERROR_SUCCESS
)
2133 MSI_ViewClose(view
);
2134 msiobj_release(&view
->hdr
);
2140 WCHAR Feature
[0x100];
2141 MSIRECORD
* row
= 0;
2145 rc
= MSI_ViewFetch(view
,&row
);
2147 if (rc
!= ERROR_SUCCESS
)
2154 MSI_RecordGetStringW(row
,1,Feature
,&sz
);
2156 feature_index
= get_loaded_feature(package
,Feature
);
2157 if (feature_index
< 0)
2158 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature
));
2162 Condition
= load_dynamic_stringW(row
,3);
2164 if (MSI_EvaluateConditionW(package
,Condition
) ==
2167 int level
= MSI_RecordGetInteger(row
,2);
2168 TRACE("Reseting feature %s to level %i\n",
2169 debugstr_w(Feature
), level
);
2170 package
->features
[feature_index
].Level
= level
;
2172 HeapFree(GetProcessHeap(),0,Condition
);
2175 msiobj_release(&row
->hdr
);
2177 MSI_ViewClose(view
);
2178 msiobj_release(&view
->hdr
);
2181 TRACE("Enabling or Disabling Components\n");
2182 for (i
= 0; i
< package
->loaded_components
; i
++)
2184 if (package
->components
[i
].Condition
[0])
2186 if (MSI_EvaluateConditionW(package
,
2187 package
->components
[i
].Condition
) == MSICONDITION_FALSE
)
2189 TRACE("Disabling component %s\n",
2190 debugstr_w(package
->components
[i
].Component
));
2191 package
->components
[i
].Enabled
= FALSE
;
2196 MSI_SetPropertyW(package
,szCosting
,szOne
);
2197 return ERROR_SUCCESS
;
2201 * This is a helper function for handling embedded cabinet media
2203 static UINT
writeout_cabinet_stream(MSIPACKAGE
*package
, WCHAR
* stream_name
,
2211 WCHAR tmp
[MAX_PATH
];
2213 rc
= read_raw_stream_data(package
->db
,stream_name
,&data
,&size
);
2214 if (rc
!= ERROR_SUCCESS
)
2218 if (MSI_GetPropertyW(package
, cszTempFolder
, tmp
, &write
))
2219 GetTempPathW(MAX_PATH
,tmp
);
2221 GetTempFileNameW(tmp
,stream_name
,0,source
);
2223 track_tempfile(package
,strrchrW(source
,'\\'), source
);
2224 the_file
= CreateFileW(source
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2225 FILE_ATTRIBUTE_NORMAL
, NULL
);
2227 if (the_file
== INVALID_HANDLE_VALUE
)
2229 rc
= ERROR_FUNCTION_FAILED
;
2233 WriteFile(the_file
,data
,size
,&write
,NULL
);
2234 CloseHandle(the_file
);
2235 TRACE("wrote %li bytes to %s\n",write
,debugstr_w(source
));
2237 HeapFree(GetProcessHeap(),0,data
);
2242 /* Support functions for FDI functions */
2244 static void * cabinet_alloc(ULONG cb
)
2246 return HeapAlloc(GetProcessHeap(), 0, cb
);
2249 static void cabinet_free(void *pv
)
2251 HeapFree(GetProcessHeap(), 0, pv
);
2254 static INT_PTR
cabinet_open(char *pszFile
, int oflag
, int pmode
)
2257 DWORD dwShareMode
= 0;
2258 DWORD dwCreateDisposition
= OPEN_EXISTING
;
2259 switch (oflag
& _O_ACCMODE
)
2262 dwAccess
= GENERIC_READ
;
2263 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_DELETE
;
2266 dwAccess
= GENERIC_WRITE
;
2267 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
2270 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
2271 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
2274 if ((oflag
& (_O_CREAT
| _O_EXCL
)) == (_O_CREAT
| _O_EXCL
))
2275 dwCreateDisposition
= CREATE_NEW
;
2276 else if (oflag
& _O_CREAT
)
2277 dwCreateDisposition
= CREATE_ALWAYS
;
2278 return (INT_PTR
)CreateFileA(pszFile
, dwAccess
, dwShareMode
, NULL
, dwCreateDisposition
, 0, NULL
);
2281 static UINT
cabinet_read(INT_PTR hf
, void *pv
, UINT cb
)
2284 if (ReadFile((HANDLE
)hf
, pv
, cb
, &dwRead
, NULL
))
2289 static UINT
cabinet_write(INT_PTR hf
, void *pv
, UINT cb
)
2292 if (WriteFile((HANDLE
)hf
, pv
, cb
, &dwWritten
, NULL
))
2297 static int cabinet_close(INT_PTR hf
)
2299 return CloseHandle((HANDLE
)hf
) ? 0 : -1;
2302 static long cabinet_seek(INT_PTR hf
, long dist
, int seektype
)
2304 /* flags are compatible and so are passed straight through */
2305 return SetFilePointer((HANDLE
)hf
, dist
, NULL
, seektype
);
2308 static INT_PTR
cabinet_notify(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
2310 /* FIXME: try to do more processing in this function */
2313 case fdintCOPY_FILE
:
2315 ULONG len
= strlen((char*)pfdin
->pv
) + strlen(pfdin
->psz1
);
2316 char *file
= cabinet_alloc((len
+1)*sizeof(char));
2318 strcpy(file
, (char*)pfdin
->pv
);
2319 strcat(file
, pfdin
->psz1
);
2321 TRACE("file: %s\n", debugstr_a(file
));
2323 return cabinet_open(file
, _O_WRONLY
| _O_CREAT
, 0);
2325 case fdintCLOSE_FILE_INFO
:
2329 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
2331 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
2333 if (!SetFileTime((HANDLE
)pfdin
->hf
, &ftLocal
, 0, &ftLocal
))
2336 cabinet_close(pfdin
->hf
);
2344 /***********************************************************************
2345 * extract_cabinet_file
2347 * Extract files from a cab file.
2349 static BOOL
extract_cabinet_file(const WCHAR
* source
, const WCHAR
* path
)
2357 TRACE("Extracting %s to %s\n",debugstr_w(source
), debugstr_w(path
));
2359 hfdi
= FDICreate(cabinet_alloc
,
2370 ERR("FDICreate failed\n");
2374 if (!(cabinet
= strdupWtoA( source
)))
2379 if (!(cab_path
= strdupWtoA( path
)))
2382 HeapFree(GetProcessHeap(), 0, cabinet
);
2386 ret
= FDICopy(hfdi
, cabinet
, "", 0, cabinet_notify
, NULL
, cab_path
);
2389 ERR("FDICopy failed\n");
2393 HeapFree(GetProcessHeap(), 0, cabinet
);
2394 HeapFree(GetProcessHeap(), 0, cab_path
);
2399 static UINT
ready_media_for_file(MSIPACKAGE
*package
, UINT sequence
,
2404 MSIRECORD
* row
= 0;
2405 WCHAR source
[MAX_PATH
];
2406 static const WCHAR ExecSeqQuery
[] = {
2407 's','e','l','e','c','t',' ','*',' ',
2408 'f','r','o','m',' ','M','e','d','i','a',' ',
2409 'w','h','e','r','e',' ','L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%','i',' ',
2410 'o','r','d','e','r',' ','b','y',' ','L','a','s','t','S','e','q','u','e','n','c','e',0};
2415 static UINT last_sequence
= 0;
2417 if (sequence
<= last_sequence
)
2419 TRACE("Media already ready (%u, %u)\n",sequence
,last_sequence
);
2420 return ERROR_SUCCESS
;
2423 sprintfW(Query
,ExecSeqQuery
,sequence
);
2425 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2426 if (rc
!= ERROR_SUCCESS
)
2429 rc
= MSI_ViewExecute(view
, 0);
2430 if (rc
!= ERROR_SUCCESS
)
2432 MSI_ViewClose(view
);
2433 msiobj_release(&view
->hdr
);
2437 rc
= MSI_ViewFetch(view
,&row
);
2438 if (rc
!= ERROR_SUCCESS
)
2440 MSI_ViewClose(view
);
2441 msiobj_release(&view
->hdr
);
2444 seq
= MSI_RecordGetInteger(row
,2);
2445 last_sequence
= seq
;
2447 if (!MSI_RecordIsNull(row
,4))
2450 MSI_RecordGetStringW(row
,4,cab
,&sz
);
2451 TRACE("Source is CAB %s\n",debugstr_w(cab
));
2452 /* the stream does not contain the # character */
2455 writeout_cabinet_stream(package
,&cab
[1],source
);
2456 strcpyW(path
,source
);
2457 *(strrchrW(path
,'\\')+1)=0;
2462 if (MSI_GetPropertyW(package
, cszSourceDir
, source
, &sz
))
2464 ERR("No Source dir defined \n");
2465 rc
= ERROR_FUNCTION_FAILED
;
2469 strcpyW(path
,source
);
2470 strcatW(source
,cab
);
2471 /* extract the cab file into a folder in the temp folder */
2473 if (MSI_GetPropertyW(package
, cszTempFolder
,path
, &sz
)
2475 GetTempPathW(MAX_PATH
,path
);
2478 rc
= !extract_cabinet_file(source
,path
);
2480 msiobj_release(&row
->hdr
);
2481 MSI_ViewClose(view
);
2482 msiobj_release(&view
->hdr
);
2486 inline static UINT
create_component_directory ( MSIPACKAGE
* package
, INT component
)
2490 WCHAR install_path
[MAX_PATH
];
2492 rc
= resolve_folder(package
, package
->components
[component
].Directory
,
2493 install_path
, FALSE
, FALSE
, &folder
);
2495 if (rc
!= ERROR_SUCCESS
)
2498 /* create the path */
2499 if (folder
->State
== 0)
2501 create_full_pathW(install_path
);
2508 static UINT
ACTION_InstallFiles(MSIPACKAGE
*package
)
2510 UINT rc
= ERROR_SUCCESS
;
2513 WCHAR uipath
[MAX_PATH
];
2516 return ERROR_INVALID_HANDLE
;
2518 /* increment progress bar each time action data is sent */
2519 ui_progress(package
,1,1,1,0);
2521 for (index
= 0; index
< package
->loaded_files
; index
++)
2523 WCHAR path_to_source
[MAX_PATH
];
2526 file
= &package
->files
[index
];
2528 if (file
->Temporary
)
2531 if (!package
->components
[file
->ComponentIndex
].Enabled
||
2532 !package
->components
[file
->ComponentIndex
].FeatureState
)
2534 TRACE("File %s is not scheduled for install\n",
2535 debugstr_w(file
->File
));
2539 if ((file
->State
== 1) || (file
->State
== 2))
2541 TRACE("Installing %s\n",debugstr_w(file
->File
));
2542 rc
= ready_media_for_file(package
,file
->Sequence
,path_to_source
);
2545 * our file table could change here because a new temp file
2546 * may have been created
2548 file
= &package
->files
[index
];
2549 if (rc
!= ERROR_SUCCESS
)
2551 ERR("Unable to ready media\n");
2552 rc
= ERROR_FUNCTION_FAILED
;
2556 create_component_directory( package
, file
->ComponentIndex
);
2558 strcpyW(file
->SourcePath
, path_to_source
);
2559 strcatW(file
->SourcePath
, file
->File
);
2561 TRACE("file paths %s to %s\n",debugstr_w(file
->SourcePath
),
2562 debugstr_w(file
->TargetPath
));
2565 uirow
=MSI_CreateRecord(9);
2566 MSI_RecordSetStringW(uirow
,1,file
->File
);
2567 strcpyW(uipath
,file
->TargetPath
);
2568 *(strrchrW(uipath
,'\\')+1)=0;
2569 MSI_RecordSetStringW(uirow
,9,uipath
);
2570 MSI_RecordSetInteger(uirow
,6,file
->FileSize
);
2571 ui_actiondata(package
,szInstallFiles
,uirow
);
2572 msiobj_release( &uirow
->hdr
);
2574 if (!MoveFileW(file
->SourcePath
,file
->TargetPath
))
2576 rc
= GetLastError();
2577 ERR("Unable to move file (error %d)\n", rc
);
2583 ui_progress(package
,2,0,0,0);
2590 inline static UINT
get_file_target(MSIPACKAGE
*package
, LPCWSTR file_key
,
2596 return ERROR_INVALID_HANDLE
;
2598 for (index
= 0; index
< package
->loaded_files
; index
++)
2600 if (strcmpW(file_key
,package
->files
[index
].File
)==0)
2602 if (package
->files
[index
].State
>= 3)
2604 strcpyW(file_source
,package
->files
[index
].TargetPath
);
2605 return ERROR_SUCCESS
;
2608 return ERROR_FILE_NOT_FOUND
;
2612 return ERROR_FUNCTION_FAILED
;
2615 static UINT
ACTION_DuplicateFiles(MSIPACKAGE
*package
)
2619 MSIRECORD
* row
= 0;
2620 static const WCHAR ExecSeqQuery
[] = {
2621 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2622 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
2625 return ERROR_INVALID_HANDLE
;
2627 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2628 if (rc
!= ERROR_SUCCESS
)
2629 return ERROR_SUCCESS
;
2631 rc
= MSI_ViewExecute(view
, 0);
2632 if (rc
!= ERROR_SUCCESS
)
2634 MSI_ViewClose(view
);
2635 msiobj_release(&view
->hdr
);
2641 WCHAR file_key
[0x100];
2642 WCHAR file_source
[MAX_PATH
];
2643 WCHAR dest_name
[0x100];
2644 WCHAR dest_path
[MAX_PATH
];
2645 WCHAR component
[0x100];
2646 INT component_index
;
2650 rc
= MSI_ViewFetch(view
,&row
);
2651 if (rc
!= ERROR_SUCCESS
)
2658 rc
= MSI_RecordGetStringW(row
,2,component
,&sz
);
2659 if (rc
!= ERROR_SUCCESS
)
2661 ERR("Unable to get component\n");
2662 msiobj_release(&row
->hdr
);
2666 component_index
= get_loaded_component(package
,component
);
2667 if (!package
->components
[component_index
].Enabled
||
2668 !package
->components
[component_index
].FeatureState
)
2670 TRACE("Skipping copy due to disabled component\n");
2671 msiobj_release(&row
->hdr
);
2676 rc
= MSI_RecordGetStringW(row
,3,file_key
,&sz
);
2677 if (rc
!= ERROR_SUCCESS
)
2679 ERR("Unable to get file key\n");
2680 msiobj_release(&row
->hdr
);
2684 rc
= get_file_target(package
,file_key
,file_source
);
2686 if (rc
!= ERROR_SUCCESS
)
2688 ERR("Original file unknown %s\n",debugstr_w(file_key
));
2689 msiobj_release(&row
->hdr
);
2693 if (MSI_RecordIsNull(row
,4))
2695 strcpyW(dest_name
,strrchrW(file_source
,'\\')+1);
2700 MSI_RecordGetStringW(row
,4,dest_name
,&sz
);
2701 reduce_to_longfilename(dest_name
);
2704 if (MSI_RecordIsNull(row
,5))
2706 strcpyW(dest_path
,file_source
);
2707 *strrchrW(dest_path
,'\\')=0;
2711 WCHAR destkey
[0x100];
2713 MSI_RecordGetStringW(row
,5,destkey
,&sz
);
2715 rc
= resolve_folder(package
, destkey
, dest_path
,FALSE
,FALSE
,NULL
);
2716 if (rc
!= ERROR_SUCCESS
)
2718 ERR("Unable to get destination folder\n");
2719 msiobj_release(&row
->hdr
);
2724 strcatW(dest_path
,dest_name
);
2726 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source
),
2727 debugstr_w(dest_path
));
2729 if (strcmpW(file_source
,dest_path
))
2730 rc
= !CopyFileW(file_source
,dest_path
,TRUE
);
2734 if (rc
!= ERROR_SUCCESS
)
2735 ERR("Failed to copy file\n");
2737 FIXME("We should track these duplicate files as well\n");
2739 msiobj_release(&row
->hdr
);
2741 MSI_ViewClose(view
);
2742 msiobj_release(&view
->hdr
);
2748 /* OK this value is "interpretted" and then formatted based on the
2749 first few characters */
2750 static LPSTR
parse_value(MSIPACKAGE
*package
, WCHAR
*value
, DWORD
*type
,
2754 if (value
[0]=='#' && value
[1]!='#' && value
[1]!='%')
2763 deformat_string(package
, &value
[2], &deformated
);
2765 /* binary value type */
2768 *size
= strlenW(ptr
)/2;
2769 data
= HeapAlloc(GetProcessHeap(),0,*size
);
2781 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
2784 HeapFree(GetProcessHeap(),0,deformated
);
2786 TRACE("Data %li bytes(%i)\n",*size
,count
);
2791 deformat_string(package
, &value
[1], &deformated
);
2794 *size
= sizeof(DWORD
);
2795 data
= HeapAlloc(GetProcessHeap(),0,*size
);
2796 *(LPDWORD
)data
= atoiW(deformated
);
2797 TRACE("DWORD %i\n",*data
);
2799 HeapFree(GetProcessHeap(),0,deformated
);
2812 *type
=REG_EXPAND_SZ
;
2820 *size
= deformat_string(package
, ptr
,(LPWSTR
*)&data
);
2825 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
)
2829 MSIRECORD
* row
= 0;
2830 static const WCHAR ExecSeqQuery
[] = {
2831 's','e','l','e','c','t',' ','*',' ',
2832 'f','r','o','m',' ','R','e','g','i','s','t','r','y',0 };
2835 return ERROR_INVALID_HANDLE
;
2837 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2838 if (rc
!= ERROR_SUCCESS
)
2839 return ERROR_SUCCESS
;
2841 rc
= MSI_ViewExecute(view
, 0);
2842 if (rc
!= ERROR_SUCCESS
)
2844 MSI_ViewClose(view
);
2845 msiobj_release(&view
->hdr
);
2849 /* increment progress bar each time action data is sent */
2850 ui_progress(package
,1,1,1,0);
2854 static const WCHAR szHCR
[] =
2855 {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T','\\',0};
2856 static const WCHAR szHCU
[] =
2857 {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',0};
2858 static const WCHAR szHLM
[] =
2859 {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',
2861 static const WCHAR szHU
[] =
2862 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
2867 LPSTR value_data
= NULL
;
2868 HKEY root_key
, hkey
;
2870 WCHAR component
[0x100];
2871 INT component_index
;
2878 rc
= MSI_ViewFetch(view
,&row
);
2879 if (rc
!= ERROR_SUCCESS
)
2886 MSI_RecordGetStringW(row
,6,component
,&sz
);
2887 component_index
= get_loaded_component(package
,component
);
2889 if (!package
->components
[component_index
].Enabled
||
2890 !package
->components
[component_index
].FeatureState
)
2892 TRACE("Skipping write due to disabled component\n");
2893 msiobj_release(&row
->hdr
);
2897 /* null values have special meanings during uninstalls and such */
2899 if(MSI_RecordIsNull(row
,5))
2901 msiobj_release(&row
->hdr
);
2905 root
= MSI_RecordGetInteger(row
,2);
2907 MSI_RecordGetStringW(row
,3,key
,&sz
);
2910 if (MSI_RecordIsNull(row
,4))
2913 MSI_RecordGetStringW(row
,4,name
,&sz
);
2915 /* get the root key */
2918 case 0: root_key
= HKEY_CLASSES_ROOT
;
2919 strcpyW(uikey
,szHCR
); break;
2920 case 1: root_key
= HKEY_CURRENT_USER
;
2921 strcpyW(uikey
,szHCU
); break;
2922 case 2: root_key
= HKEY_LOCAL_MACHINE
;
2923 strcpyW(uikey
,szHLM
); break;
2924 case 3: root_key
= HKEY_USERS
;
2925 strcpyW(uikey
,szHU
); break;
2927 ERR("Unknown root %i\n",root
);
2933 msiobj_release(&row
->hdr
);
2938 if (RegCreateKeyW( root_key
, key
, &hkey
))
2940 ERR("Could not create key %s\n",debugstr_w(key
));
2941 msiobj_release(&row
->hdr
);
2945 value
= load_dynamic_stringW(row
,5);
2946 value_data
= parse_value(package
, value
, &type
, &size
);
2950 TRACE("Setting value %s\n",debugstr_w(name
));
2951 RegSetValueExW(hkey
, name
, 0, type
, value_data
, size
);
2953 uirow
= MSI_CreateRecord(3);
2954 MSI_RecordSetStringW(uirow
,2,name
);
2955 MSI_RecordSetStringW(uirow
,1,uikey
);
2958 MSI_RecordSetStringW(uirow
,3,(LPWSTR
)value_data
);
2960 MSI_RecordSetStringW(uirow
,3,value
);
2962 ui_actiondata(package
,szWriteRegistryValues
,uirow
);
2963 ui_progress(package
,2,0,0,0);
2964 msiobj_release( &uirow
->hdr
);
2966 HeapFree(GetProcessHeap(),0,value_data
);
2968 HeapFree(GetProcessHeap(),0,value
);
2970 msiobj_release(&row
->hdr
);
2973 MSI_ViewClose(view
);
2974 msiobj_release(&view
->hdr
);
2979 * This helper function should probably go alot of places
2981 * Thinking about this, maybe this should become yet another Bison file
2983 static DWORD
deformat_string(MSIPACKAGE
*package
, WCHAR
* ptr
,WCHAR
** data
)
2993 /* scan for special characters */
2994 if (!strchrW(ptr
,'[') || (strchrW(ptr
,'[') && !strchrW(ptr
,']')))
2997 size
= (strlenW(ptr
)+1) * sizeof(WCHAR
);
2998 *data
= HeapAlloc(GetProcessHeap(),0,size
);
3003 /* formatted string located */
3004 mark
= strchrW(ptr
,'[');
3007 INT cnt
= (mark
- ptr
);
3008 TRACE("%i (%i) characters before marker\n",cnt
,(mark
-ptr
));
3009 size
= cnt
* sizeof(WCHAR
);
3010 size
+= sizeof(WCHAR
);
3011 *data
= HeapAlloc(GetProcessHeap(),0,size
);
3012 strncpyW(*data
,ptr
,cnt
);
3017 size
= sizeof(WCHAR
);
3018 *data
= HeapAlloc(GetProcessHeap(),0,size
);
3023 *strchrW(key
,']')=0;
3024 mark
= strchrW(mark
,']');
3026 TRACE("Current %s .. %s\n",debugstr_w(*data
),debugstr_w(mark
));
3028 rc
= MSI_GetPropertyW(package
, key
, NULL
, &sz
);
3029 if ((rc
== ERROR_SUCCESS
) || (rc
== ERROR_MORE_DATA
))
3034 value
= HeapAlloc(GetProcessHeap(),0,sz
* sizeof(WCHAR
));
3035 MSI_GetPropertyW(package
, key
, value
, &sz
);
3037 chunk
= (strlenW(value
)+1) * sizeof(WCHAR
);
3039 newdata
= HeapReAlloc(GetProcessHeap(),0,*data
,size
);
3041 strcatW(*data
,value
);
3043 TRACE("Current %s .. %s\n",debugstr_w(*data
),debugstr_w(mark
));
3047 chunk
= (strlenW(mark
)+1) * sizeof(WCHAR
);
3049 newdata
= HeapReAlloc(GetProcessHeap(),0,*data
,size
);
3051 strcatW(*data
,mark
);
3053 (*data
)[strlenW(*data
)]=0;
3054 TRACE("Current %s .. %s\n",debugstr_w(*data
),debugstr_w(mark
));
3056 /* recursively do this to clean up */
3057 mark
= HeapAlloc(GetProcessHeap(),0,size
);
3058 strcpyW(mark
,*data
);
3059 TRACE("String at this point %s\n",debugstr_w(mark
));
3060 size
= deformat_string(package
,mark
,data
);
3061 HeapFree(GetProcessHeap(),0,mark
);
3065 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
)
3073 LPWSTR override
= NULL
;
3074 static const WCHAR addlocal
[]={'A','D','D','L','O','C','A','L',0};
3075 static const WCHAR all
[]={'A','L','L',0};
3076 static const WCHAR szlevel
[] = {
3077 'I','N','S','T','A','L','L','L','E','V','E','L',0};
3078 static const WCHAR szAddLocal
[] = {
3079 'A','D','D','L','O','C','A','L',0};
3081 /* I do not know if this is where it should happen.. but */
3083 TRACE("Checking Install Level\n");
3086 if (MSI_GetPropertyW(package
,szlevel
,level
,&sz
)==ERROR_SUCCESS
)
3087 install_level
= atoiW(level
);
3092 rc
= MSI_GetPropertyW(package
,szAddLocal
,NULL
,&sz
);
3093 if (rc
== ERROR_SUCCESS
|| rc
== ERROR_MORE_DATA
)
3096 override
= HeapAlloc(GetProcessHeap(),0,sz
*sizeof(WCHAR
));
3097 MSI_GetPropertyW(package
, addlocal
,override
,&sz
);
3101 * Components FeatureState defaults to FALSE. The idea is we want to
3102 * enable the component is ANY feature that uses it is enabled to install
3104 for(i
= 0; i
< package
->loaded_features
; i
++)
3106 BOOL feature_state
= ((package
->features
[i
].Level
> 0) &&
3107 (package
->features
[i
].Level
<= install_level
));
3109 if (override
&& (strcmpiW(override
,all
)==0 ||
3110 strstrW(override
,package
->features
[i
].Feature
)))
3112 TRACE("Override of install level found\n");
3113 feature_state
= TRUE
;
3114 package
->features
[i
].Enabled
= feature_state
;
3117 TRACE("Feature %s has a state of %i\n",
3118 debugstr_w(package
->features
[i
].Feature
), feature_state
);
3119 for( j
= 0; j
< package
->features
[i
].ComponentCount
; j
++)
3121 package
->components
[package
->features
[i
].Components
[j
]].FeatureState
3125 if (override
!= NULL
)
3126 HeapFree(GetProcessHeap(),0,override
);
3128 * So basically we ONLY want to install a component if its Enabled AND
3129 * FeatureState are both TRUE
3131 return ERROR_SUCCESS
;
3134 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
)
3137 static const WCHAR q1
[]={
3138 'S','E','L','E','C','T',' ','*',' ',
3139 'F','R','O','M',' ','R','e','g','i','s','t','r','y',0};
3142 MSIRECORD
* row
= 0;
3144 TRACE(" InstallValidate \n");
3146 rc
= MSI_DatabaseOpenViewW(package
->db
, q1
, &view
);
3147 if (rc
!= ERROR_SUCCESS
)
3148 return ERROR_SUCCESS
;
3150 rc
= MSI_ViewExecute(view
, 0);
3151 if (rc
!= ERROR_SUCCESS
)
3153 MSI_ViewClose(view
);
3154 msiobj_release(&view
->hdr
);
3159 rc
= MSI_ViewFetch(view
,&row
);
3160 if (rc
!= ERROR_SUCCESS
)
3167 msiobj_release(&row
->hdr
);
3169 MSI_ViewClose(view
);
3170 msiobj_release(&view
->hdr
);
3172 ui_progress(package
,0,progress
+package
->loaded_files
,0,0);
3174 return ERROR_SUCCESS
;
3177 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
)
3180 MSIQUERY
* view
= NULL
;
3181 MSIRECORD
* row
= 0;
3182 static const WCHAR ExecSeqQuery
[] = {
3183 'S','E','L','E','C','T',' ','*',' ',
3184 'f','r','o','m',' ','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3185 static const WCHAR title
[]=
3186 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3188 TRACE("Checking launch conditions\n");
3190 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3191 if (rc
!= ERROR_SUCCESS
)
3192 return ERROR_SUCCESS
;
3194 rc
= MSI_ViewExecute(view
, 0);
3195 if (rc
!= ERROR_SUCCESS
)
3197 MSI_ViewClose(view
);
3198 msiobj_release(&view
->hdr
);
3203 while (rc
== ERROR_SUCCESS
)
3206 LPWSTR message
= NULL
;
3208 rc
= MSI_ViewFetch(view
,&row
);
3209 if (rc
!= ERROR_SUCCESS
)
3215 cond
= load_dynamic_stringW(row
,1);
3217 if (MSI_EvaluateConditionW(package
,cond
) != MSICONDITION_TRUE
)
3219 message
= load_dynamic_stringW(row
,2);
3220 MessageBoxW(NULL
,message
,title
,MB_OK
);
3221 HeapFree(GetProcessHeap(),0,message
);
3222 rc
= ERROR_FUNCTION_FAILED
;
3224 HeapFree(GetProcessHeap(),0,cond
);
3225 msiobj_release(&row
->hdr
);
3227 MSI_ViewClose(view
);
3228 msiobj_release(&view
->hdr
);
3232 static void resolve_keypath( MSIPACKAGE
* package
, INT
3233 component_index
, WCHAR
*keypath
)
3235 MSICOMPONENT
* cmp
= &package
->components
[component_index
];
3237 if (cmp
->KeyPath
[0]==0)
3239 resolve_folder(package
,cmp
->Directory
,keypath
,FALSE
,FALSE
,NULL
);
3242 if ((cmp
->Attributes
& 0x4) || (cmp
->Attributes
& 0x20))
3244 FIXME("UNIMPLEMENTED keypath as Registry or ODBC Source\n");
3250 j
= get_loaded_file(package
,cmp
->KeyPath
);
3253 strcpyW(keypath
,package
->files
[j
].TargetPath
);
3258 * Ok further analysis makes me think that this work is
3259 * actually done in the PublishComponents and PublishFeatures
3260 * step, and not here. It appears like the keypath and all that is
3261 * resolved in this step, however actually written in the Publish steps.
3262 * But we will leave it here for now because it is unclear
3264 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
)
3266 WCHAR productcode
[0x100];
3267 WCHAR squished_pc
[0x100];
3268 WCHAR squished_cc
[0x100];
3272 HKEY hkey
=0,hkey2
=0,hkey3
=0;
3273 static const WCHAR szProductCode
[]=
3274 {'P','r','o','d','u','c','t','C','o','d','e',0};
3275 static const WCHAR szInstaller
[] = {
3276 'S','o','f','t','w','a','r','e','\\',
3277 'M','i','c','r','o','s','o','f','t','\\',
3278 'W','i','n','d','o','w','s','\\',
3279 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3280 'I','n','s','t','a','l','l','e','r',0 };
3281 static const WCHAR szFeatures
[] = {
3282 'F','e','a','t','u','r','e','s',0 };
3283 static const WCHAR szComponents
[] = {
3284 'C','o','m','p','o','n','e','n','t','s',0 };
3287 return ERROR_INVALID_HANDLE
;
3289 /* writes the Component and Features values to the registry */
3291 rc
= MSI_GetPropertyW(package
,szProductCode
,productcode
,&sz
);
3292 if (rc
!= ERROR_SUCCESS
)
3293 return ERROR_SUCCESS
;
3295 squash_guid(productcode
,squished_pc
);
3296 rc
= RegCreateKeyW(HKEY_LOCAL_MACHINE
,szInstaller
,&hkey
);
3297 if (rc
!= ERROR_SUCCESS
)
3300 rc
= RegCreateKeyW(hkey
,szFeatures
,&hkey2
);
3301 if (rc
!= ERROR_SUCCESS
)
3304 rc
= RegCreateKeyW(hkey2
,squished_pc
,&hkey3
);
3305 if (rc
!= ERROR_SUCCESS
)
3308 /* here the guids are base 85 encoded */
3309 for (i
= 0; i
< package
->loaded_features
; i
++)
3316 size
= package
->features
[i
].ComponentCount
*21*sizeof(WCHAR
);
3317 data
= HeapAlloc(GetProcessHeap(), 0, size
);
3320 for (j
= 0; j
< package
->features
[i
].ComponentCount
; j
++)
3323 TRACE("From %s\n",debugstr_w(package
->components
3324 [package
->features
[i
].Components
[j
]].ComponentId
));
3325 CLSIDFromString(package
->components
3326 [package
->features
[i
].Components
[j
]].ComponentId
,
3328 encode_base85_guid(&clsid
,buf
);
3329 TRACE("to %s\n",debugstr_w(buf
));
3333 size
= strlenW(data
)*sizeof(WCHAR
);
3334 RegSetValueExW(hkey3
,package
->features
[i
].Feature
,0,REG_SZ
,
3336 HeapFree(GetProcessHeap(),0,data
);
3342 rc
= RegCreateKeyW(hkey
,szComponents
,&hkey2
);
3343 if (rc
!= ERROR_SUCCESS
)
3346 for (i
= 0; i
< package
->loaded_components
; i
++)
3348 if (package
->components
[i
].ComponentId
[0]!=0)
3350 WCHAR keypath
[0x1000];
3353 squash_guid(package
->components
[i
].ComponentId
,squished_cc
);
3354 rc
= RegCreateKeyW(hkey2
,squished_cc
,&hkey3
);
3355 if (rc
!= ERROR_SUCCESS
)
3358 resolve_keypath(package
,i
,keypath
);
3360 RegSetValueExW(hkey3
,squished_pc
,0,REG_SZ
,(LPVOID
)keypath
,
3361 (strlenW(keypath
)+1)*sizeof(WCHAR
));
3365 uirow
= MSI_CreateRecord(3);
3366 MSI_RecordSetStringW(uirow
,1,productcode
);
3367 MSI_RecordSetStringW(uirow
,2,package
->components
[i
].ComponentId
);
3368 MSI_RecordSetStringW(uirow
,3,keypath
);
3369 ui_actiondata(package
,szProcessComponents
,uirow
);
3370 msiobj_release( &uirow
->hdr
);
3379 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
)
3382 * OK this is a bit confusing.. I am given a _Component key and I believe
3383 * that the file that is being registered as a type library is the "key file
3384 * of that component" which I interpret to mean "The file in the KeyPath of
3389 MSIRECORD
* row
= 0;
3390 static const WCHAR Query
[] = {
3391 'S','E','L','E','C','T',' ','*',' ',
3392 'f','r','o','m',' ','T','y','p','e','L','i','b',0};
3397 return ERROR_INVALID_HANDLE
;
3399 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3400 if (rc
!= ERROR_SUCCESS
)
3401 return ERROR_SUCCESS
;
3403 rc
= MSI_ViewExecute(view
, 0);
3404 if (rc
!= ERROR_SUCCESS
)
3406 MSI_ViewClose(view
);
3407 msiobj_release(&view
->hdr
);
3413 WCHAR component
[0x100];
3417 rc
= MSI_ViewFetch(view
,&row
);
3418 if (rc
!= ERROR_SUCCESS
)
3425 MSI_RecordGetStringW(row
,3,component
,&sz
);
3427 index
= get_loaded_component(package
,component
);
3430 msiobj_release(&row
->hdr
);
3434 if (!package
->components
[index
].Enabled
||
3435 !package
->components
[index
].FeatureState
)
3437 TRACE("Skipping typelib reg due to disabled component\n");
3438 msiobj_release(&row
->hdr
);
3442 index
= get_loaded_file(package
,package
->components
[index
].KeyPath
);
3446 msiobj_release(&row
->hdr
);
3450 res
= LoadTypeLib(package
->files
[index
].TargetPath
,&ptLib
);
3453 WCHAR help
[MAX_PATH
];
3454 WCHAR helpid
[0x100];
3457 MSI_RecordGetStringW(row
,6,helpid
,&sz
);
3459 resolve_folder(package
,helpid
,help
,FALSE
,FALSE
,NULL
);
3461 res
= RegisterTypeLib(ptLib
,package
->files
[index
].TargetPath
,help
);
3462 if (!SUCCEEDED(res
))
3463 ERR("Failed to register type library %s\n",
3464 debugstr_w(package
->files
[index
].TargetPath
));
3467 /* Yes the row has more fields than I need, but #1 is
3468 correct and the only one I need. Why make a new row? */
3470 ui_actiondata(package
,szRegisterTypeLibraries
,row
);
3472 TRACE("Registered %s\n",
3473 debugstr_w(package
->files
[index
].TargetPath
));
3477 ITypeLib_Release(ptLib
);
3480 ERR("Failed to load type library %s\n",
3481 debugstr_w(package
->files
[index
].TargetPath
));
3483 msiobj_release(&row
->hdr
);
3485 MSI_ViewClose(view
);
3486 msiobj_release(&view
->hdr
);
3491 static UINT
register_appid(MSIPACKAGE
*package
, LPCWSTR clsid
, LPCWSTR app
)
3493 static const WCHAR szAppID
[] = { 'A','p','p','I','D',0 };
3496 MSIRECORD
* row
= 0;
3497 static const WCHAR ExecSeqQuery
[] =
3498 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','p','p','I'
3499 ,'d',' ','w','h','e','r','e',' ','A','p','p','I','d','=','`','%','s','`',0};
3500 WCHAR Query
[0x1000];
3505 return ERROR_INVALID_HANDLE
;
3507 sprintfW(Query
,ExecSeqQuery
,clsid
);
3509 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3510 if (rc
!= ERROR_SUCCESS
)
3513 rc
= MSI_ViewExecute(view
, 0);
3514 if (rc
!= ERROR_SUCCESS
)
3516 MSI_ViewClose(view
);
3517 msiobj_release(&view
->hdr
);
3521 RegCreateKeyW(HKEY_CLASSES_ROOT
,szAppID
,&hkey2
);
3522 RegCreateKeyW(hkey2
,clsid
,&hkey3
);
3523 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,(LPVOID
)app
,
3524 (strlenW(app
)+1)*sizeof(WCHAR
));
3526 rc
= MSI_ViewFetch(view
,&row
);
3527 if (rc
!= ERROR_SUCCESS
)
3529 MSI_ViewClose(view
);
3530 msiobj_release(&view
->hdr
);
3534 if (!MSI_RecordIsNull(row
,2))
3536 LPWSTR deformated
=0;
3538 static const WCHAR szRemoteServerName
[] =
3539 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
3540 buffer
= load_dynamic_stringW(row
,2);
3541 size
= deformat_string(package
,buffer
,&deformated
);
3542 RegSetValueExW(hkey3
,szRemoteServerName
,0,REG_SZ
,(LPVOID
)deformated
,
3544 HeapFree(GetProcessHeap(),0,deformated
);
3545 HeapFree(GetProcessHeap(),0,buffer
);
3548 if (!MSI_RecordIsNull(row
,3))
3550 static const WCHAR szLocalService
[] =
3551 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
3553 buffer
= load_dynamic_stringW(row
,3);
3554 size
= (strlenW(buffer
)+1) * sizeof(WCHAR
);
3555 RegSetValueExW(hkey3
,szLocalService
,0,REG_SZ
,(LPVOID
)buffer
,size
);
3556 HeapFree(GetProcessHeap(),0,buffer
);
3559 if (!MSI_RecordIsNull(row
,4))
3561 static const WCHAR szService
[] =
3562 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
3564 buffer
= load_dynamic_stringW(row
,4);
3565 size
= (strlenW(buffer
)+1) * sizeof(WCHAR
);
3566 RegSetValueExW(hkey3
,szService
,0,REG_SZ
,(LPVOID
)buffer
,size
);
3567 HeapFree(GetProcessHeap(),0,buffer
);
3570 if (!MSI_RecordIsNull(row
,5))
3572 static const WCHAR szDLL
[] =
3573 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
3575 buffer
= load_dynamic_stringW(row
,5);
3576 size
= (strlenW(buffer
)+1) * sizeof(WCHAR
);
3577 RegSetValueExW(hkey3
,szDLL
,0,REG_SZ
,(LPVOID
)buffer
,size
);
3578 HeapFree(GetProcessHeap(),0,buffer
);
3581 if (!MSI_RecordIsNull(row
,6))
3583 static const WCHAR szActivate
[] =
3584 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
3585 static const WCHAR szY
[] = {'Y',0};
3587 if (MSI_RecordGetInteger(row
,6))
3588 RegSetValueExW(hkey3
,szActivate
,0,REG_SZ
,(LPVOID
)szY
,4);
3591 if (!MSI_RecordIsNull(row
,7))
3593 static const WCHAR szRunAs
[] = {'R','u','n','A','s',0};
3594 static const WCHAR szUser
[] =
3595 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
3597 if (MSI_RecordGetInteger(row
,7))
3598 RegSetValueExW(hkey3
,szRunAs
,0,REG_SZ
,(LPVOID
)szUser
,34);
3601 msiobj_release(&row
->hdr
);
3602 MSI_ViewClose(view
);
3603 msiobj_release(&view
->hdr
);
3609 static UINT
ACTION_RegisterClassInfo(MSIPACKAGE
*package
)
3612 * Again I am assuming the words, "Whose key file represents" when referring
3613 * to a Component as to meaning that Components KeyPath file
3615 * Also there is a very strong connection between ClassInfo and ProgID
3616 * that I am mostly glossing over.
3617 * What would be more propper is to load the ClassInfo and the ProgID info
3618 * into memory data structures and then be able to enable and disable them
3619 * based on component.
3624 MSIRECORD
* row
= 0;
3625 static const WCHAR ExecSeqQuery
[] = {
3626 'S','E','L','E','C','T',' ','*',' ',
3627 'f','r','o','m',' ','C','l','a','s','s',0};
3628 static const WCHAR szCLSID
[] = { 'C','L','S','I','D',0 };
3629 static const WCHAR szProgID
[] = { 'P','r','o','g','I','D',0 };
3630 static const WCHAR szAppID
[] = { 'A','p','p','I','D',0 };
3631 HKEY hkey
,hkey2
,hkey3
;
3634 return ERROR_INVALID_HANDLE
;
3636 rc
= RegCreateKeyW(HKEY_CLASSES_ROOT
,szCLSID
,&hkey
);
3637 if (rc
!= ERROR_SUCCESS
)
3638 return ERROR_FUNCTION_FAILED
;
3640 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3641 if (rc
!= ERROR_SUCCESS
)
3647 rc
= MSI_ViewExecute(view
, 0);
3648 if (rc
!= ERROR_SUCCESS
)
3650 MSI_ViewClose(view
);
3651 msiobj_release(&view
->hdr
);
3658 WCHAR buffer
[0x100];
3663 rc
= MSI_ViewFetch(view
,&row
);
3664 if (rc
!= ERROR_SUCCESS
)
3671 MSI_RecordGetStringW(row
,3,buffer
,&sz
);
3673 index
= get_loaded_component(package
,buffer
);
3677 msiobj_release(&row
->hdr
);
3681 if (!package
->components
[index
].Enabled
||
3682 !package
->components
[index
].FeatureState
)
3684 TRACE("Skipping class reg due to disabled component\n");
3685 msiobj_release(&row
->hdr
);
3690 MSI_RecordGetStringW(row
,1,clsid
,&sz
);
3691 RegCreateKeyW(hkey
,clsid
,&hkey2
);
3693 if (!MSI_RecordIsNull(row
,5))
3696 MSI_RecordGetStringW(row
,5,desc
,&sz
);
3698 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)desc
,
3699 (strlenW(desc
)+1)*sizeof(WCHAR
));
3705 MSI_RecordGetStringW(row
,2,buffer
,&sz
);
3707 RegCreateKeyW(hkey2
,buffer
,&hkey3
);
3709 index
= get_loaded_file(package
,package
->components
[index
].KeyPath
);
3710 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,
3711 (LPVOID
)package
->files
[index
].TargetPath
,
3712 (strlenW(package
->files
[index
].TargetPath
)+1)
3717 if (!MSI_RecordIsNull(row
,4))
3720 MSI_RecordGetStringW(row
,4,buffer
,&sz
);
3722 RegCreateKeyW(hkey2
,szProgID
,&hkey3
);
3724 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,(LPVOID
)buffer
,
3725 (strlenW(buffer
)+1)*sizeof(WCHAR
));
3730 if (!MSI_RecordIsNull(row
,6))
3733 MSI_RecordGetStringW(row
,6,buffer
,&sz
);
3735 RegSetValueExW(hkey2
,szAppID
,0,REG_SZ
,(LPVOID
)buffer
,
3736 (strlenW(buffer
)+1)*sizeof(WCHAR
));
3738 register_appid(package
,buffer
,desc
);
3743 FIXME("Process the rest of the fields >7\n");
3745 ui_actiondata(package
,szRegisterClassInfo
,row
);
3747 msiobj_release(&row
->hdr
);
3749 MSI_ViewClose(view
);
3750 msiobj_release(&view
->hdr
);
3757 static UINT
register_progid_base(MSIRECORD
* row
, LPWSTR clsid
)
3759 static const WCHAR szCLSID
[] = { 'C','L','S','I','D',0 };
3761 WCHAR buffer
[0x100];
3766 MSI_RecordGetStringW(row
,1,buffer
,&sz
);
3767 RegCreateKeyW(HKEY_CLASSES_ROOT
,buffer
,&hkey
);
3769 if (!MSI_RecordIsNull(row
,4))
3772 MSI_RecordGetStringW(row
,4,buffer
,&sz
);
3773 RegSetValueExW(hkey
,NULL
,0,REG_SZ
,(LPVOID
)buffer
, (strlenW(buffer
)+1) *
3777 if (!MSI_RecordIsNull(row
,3))
3781 MSI_RecordGetStringW(row
,3,buffer
,&sz
);
3782 RegCreateKeyW(hkey
,szCLSID
,&hkey2
);
3783 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)buffer
, (strlenW(buffer
)+1) *
3787 strcpyW(clsid
,buffer
);
3793 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
3794 return ERROR_FUNCTION_FAILED
;
3796 if (!MSI_RecordIsNull(row
,5))
3797 FIXME ("UNHANDLED icon in Progid\n");
3798 return ERROR_SUCCESS
;
3801 static UINT
register_progid(MSIPACKAGE
*package
, MSIRECORD
* row
, LPWSTR clsid
);
3803 static UINT
register_parent_progid(MSIPACKAGE
*package
, LPCWSTR parent
,
3808 MSIRECORD
* row
= 0;
3809 static const WCHAR Query_t
[] =
3810 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','P','r','o','g'
3811 ,'I','d',' ','w','h','e','r','e',' ','P','r','o','g','I','d',' ','=',' ','`'
3813 WCHAR Query
[0x1000];
3816 return ERROR_INVALID_HANDLE
;
3818 sprintfW(Query
,Query_t
,parent
);
3820 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3821 if (rc
!= ERROR_SUCCESS
)
3824 rc
= MSI_ViewExecute(view
, 0);
3825 if (rc
!= ERROR_SUCCESS
)
3827 MSI_ViewClose(view
);
3828 msiobj_release(&view
->hdr
);
3832 rc
= MSI_ViewFetch(view
,&row
);
3833 if (rc
!= ERROR_SUCCESS
)
3835 MSI_ViewClose(view
);
3836 msiobj_release(&view
->hdr
);
3840 register_progid(package
,row
,clsid
);
3842 msiobj_release(&row
->hdr
);
3843 MSI_ViewClose(view
);
3844 msiobj_release(&view
->hdr
);
3848 static UINT
register_progid(MSIPACKAGE
*package
, MSIRECORD
* row
, LPWSTR clsid
)
3850 UINT rc
= ERROR_SUCCESS
;
3852 if (MSI_RecordIsNull(row
,2))
3853 rc
= register_progid_base(row
,clsid
);
3856 WCHAR buffer
[0x1000];
3859 static const WCHAR szCLSID
[] = { 'C','L','S','I','D',0 };
3862 MSI_RecordGetStringW(row
,2,buffer
,&sz
);
3863 rc
= register_parent_progid(package
,buffer
,clsid
);
3866 MSI_RecordGetStringW(row
,1,buffer
,&sz
);
3867 RegCreateKeyW(HKEY_CLASSES_ROOT
,buffer
,&hkey
);
3868 /* clasid is same as parent */
3869 RegCreateKeyW(hkey
,szCLSID
,&hkey2
);
3870 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)clsid
, (strlenW(clsid
)+1) *
3874 if (!MSI_RecordIsNull(row
,4))
3877 MSI_RecordGetStringW(row
,4,buffer
,&sz
);
3878 RegSetValueExW(hkey
,NULL
,0,REG_SZ
,(LPVOID
)buffer
,
3879 (strlenW(buffer
)+1) * sizeof(WCHAR
));
3882 if (!MSI_RecordIsNull(row
,5))
3883 FIXME ("UNHANDLED icon in Progid\n");
3890 static UINT
ACTION_RegisterProgIdInfo(MSIPACKAGE
*package
)
3893 * Sigh, here I am just brute force registering all progids
3894 * this needs to be linked to the Classes that have been registered
3895 * but the easiest way to do that is to load all these stuff into
3896 * memory for easy checking.
3898 * Gives me something to continue to work toward.
3902 MSIRECORD
* row
= 0;
3903 static const WCHAR Query
[] = {
3904 'S','E','L','E','C','T',' ','*',' ',
3905 'F','R','O','M',' ','P','r','o','g','I','d',0};
3908 return ERROR_INVALID_HANDLE
;
3910 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3911 if (rc
!= ERROR_SUCCESS
)
3912 return ERROR_SUCCESS
;
3914 rc
= MSI_ViewExecute(view
, 0);
3915 if (rc
!= ERROR_SUCCESS
)
3917 MSI_ViewClose(view
);
3918 msiobj_release(&view
->hdr
);
3924 WCHAR clsid
[0x1000];
3926 rc
= MSI_ViewFetch(view
,&row
);
3927 if (rc
!= ERROR_SUCCESS
)
3933 register_progid(package
,row
,clsid
);
3934 ui_actiondata(package
,szRegisterProgIdInfo
,row
);
3936 msiobj_release(&row
->hdr
);
3938 MSI_ViewClose(view
);
3939 msiobj_release(&view
->hdr
);
3943 static UINT
build_icon_path(MSIPACKAGE
*package
, LPCWSTR icon_name
,
3946 WCHAR ProductCode
[0x100];
3947 WCHAR SystemFolder
[MAX_PATH
];
3950 static const WCHAR szInstaller
[] =
3951 {'I','n','s','t','a','l','l','e','r','\\',0};
3952 static const WCHAR szProductCode
[] =
3953 {'P','r','o','d','u','c','t','C','o','d','e',0};
3954 static const WCHAR szFolder
[] =
3955 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3958 MSI_GetPropertyW(package
,szProductCode
,ProductCode
,&sz
);
3959 if (strlenW(ProductCode
)==0)
3960 return ERROR_FUNCTION_FAILED
;
3963 MSI_GetPropertyW(package
,szFolder
,SystemFolder
,&sz
);
3964 strcatW(SystemFolder
,szInstaller
);
3965 strcatW(SystemFolder
,ProductCode
);
3966 create_full_pathW(SystemFolder
);
3968 strcpyW(FilePath
,SystemFolder
);
3969 strcatW(FilePath
,cszbs
);
3970 strcatW(FilePath
,icon_name
);
3971 return ERROR_SUCCESS
;
3974 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
)
3978 MSIRECORD
* row
= 0;
3979 static const WCHAR Query
[] = {
3980 'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
3981 'S','h','o','r','t','c','u','t',0};
3987 return ERROR_INVALID_HANDLE
;
3989 res
= CoInitialize( NULL
);
3992 ERR("CoInitialize failed\n");
3993 return ERROR_FUNCTION_FAILED
;
3996 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3997 if (rc
!= ERROR_SUCCESS
)
3998 return ERROR_SUCCESS
;
4000 rc
= MSI_ViewExecute(view
, 0);
4001 if (rc
!= ERROR_SUCCESS
)
4003 MSI_ViewClose(view
);
4004 msiobj_release(&view
->hdr
);
4010 WCHAR target_file
[MAX_PATH
];
4011 WCHAR buffer
[0x100];
4014 static const WCHAR szlnk
[]={'.','l','n','k',0};
4016 rc
= MSI_ViewFetch(view
,&row
);
4017 if (rc
!= ERROR_SUCCESS
)
4024 MSI_RecordGetStringW(row
,4,buffer
,&sz
);
4026 index
= get_loaded_component(package
,buffer
);
4030 msiobj_release(&row
->hdr
);
4034 if (!package
->components
[index
].Enabled
||
4035 !package
->components
[index
].FeatureState
)
4037 TRACE("Skipping shortcut creation due to disabled component\n");
4038 msiobj_release(&row
->hdr
);
4042 ui_actiondata(package
,szCreateShortcuts
,row
);
4044 res
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
4045 &IID_IShellLinkW
, (LPVOID
*) &sl
);
4049 ERR("Is IID_IShellLink\n");
4050 msiobj_release(&row
->hdr
);
4054 res
= IShellLinkW_QueryInterface( sl
, &IID_IPersistFile
,(LPVOID
*) &pf
);
4057 ERR("Is IID_IPersistFile\n");
4058 msiobj_release(&row
->hdr
);
4063 MSI_RecordGetStringW(row
,2,buffer
,&sz
);
4064 resolve_folder(package
, buffer
,target_file
,FALSE
,FALSE
,NULL
);
4067 MSI_RecordGetStringW(row
,3,buffer
,&sz
);
4068 reduce_to_longfilename(buffer
);
4069 strcatW(target_file
,buffer
);
4070 if (!strchrW(target_file
,'.'))
4071 strcatW(target_file
,szlnk
);
4074 MSI_RecordGetStringW(row
,5,buffer
,&sz
);
4075 if (strchrW(buffer
,'['))
4078 deformat_string(package
,buffer
,&deformated
);
4079 IShellLinkW_SetPath(sl
,deformated
);
4080 HeapFree(GetProcessHeap(),0,deformated
);
4084 FIXME("UNHANDLED shortcut format, advertised shortcut\n");
4085 IPersistFile_Release( pf
);
4086 IShellLinkW_Release( sl
);
4087 msiobj_release(&row
->hdr
);
4091 if (!MSI_RecordIsNull(row
,6))
4095 MSI_RecordGetStringW(row
,6,buffer
,&sz
);
4096 deformat_string(package
,buffer
,&deformated
);
4097 IShellLinkW_SetArguments(sl
,deformated
);
4098 HeapFree(GetProcessHeap(),0,deformated
);
4101 if (!MSI_RecordIsNull(row
,7))
4104 deformated
= load_dynamic_stringW(row
,7);
4105 IShellLinkW_SetDescription(sl
,deformated
);
4106 HeapFree(GetProcessHeap(),0,deformated
);
4109 if (!MSI_RecordIsNull(row
,8))
4110 IShellLinkW_SetHotkey(sl
,MSI_RecordGetInteger(row
,8));
4112 if (!MSI_RecordIsNull(row
,9))
4114 WCHAR Path
[MAX_PATH
];
4118 MSI_RecordGetStringW(row
,9,buffer
,&sz
);
4120 build_icon_path(package
,buffer
,Path
);
4121 index
= MSI_RecordGetInteger(row
,10);
4123 IShellLinkW_SetIconLocation(sl
,Path
,index
);
4126 if (!MSI_RecordIsNull(row
,11))
4127 IShellLinkW_SetShowCmd(sl
,MSI_RecordGetInteger(row
,11));
4129 if (!MSI_RecordIsNull(row
,12))
4131 WCHAR Path
[MAX_PATH
];
4134 MSI_RecordGetStringW(row
,12,buffer
,&sz
);
4135 resolve_folder(package
, buffer
, Path
, FALSE
, FALSE
, NULL
);
4136 IShellLinkW_SetWorkingDirectory(sl
,Path
);
4139 TRACE("Writing shortcut to %s\n",debugstr_w(target_file
));
4140 IPersistFile_Save(pf
,target_file
,FALSE
);
4142 IPersistFile_Release( pf
);
4143 IShellLinkW_Release( sl
);
4145 msiobj_release(&row
->hdr
);
4147 MSI_ViewClose(view
);
4148 msiobj_release(&view
->hdr
);
4158 * 99% of the work done here is only done for
4159 * advertised installs. However this is where the
4160 * Icon table is processed and written out
4161 * so that is what I am going to do here.
4163 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
)
4167 MSIRECORD
* row
= 0;
4168 static const WCHAR Query
[]={
4169 'S','E','L','E','C','T',' ','*',' ',
4170 'f','r','o','m',' ','I','c','o','n',0};
4174 return ERROR_INVALID_HANDLE
;
4176 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
4177 if (rc
!= ERROR_SUCCESS
)
4178 return ERROR_SUCCESS
;
4180 rc
= MSI_ViewExecute(view
, 0);
4181 if (rc
!= ERROR_SUCCESS
)
4183 MSI_ViewClose(view
);
4184 msiobj_release(&view
->hdr
);
4191 WCHAR FilePath
[MAX_PATH
];
4192 WCHAR FileName
[MAX_PATH
];
4195 rc
= MSI_ViewFetch(view
,&row
);
4196 if (rc
!= ERROR_SUCCESS
)
4203 MSI_RecordGetStringW(row
,1,FileName
,&sz
);
4206 ERR("Unable to get FileName\n");
4207 msiobj_release(&row
->hdr
);
4211 build_icon_path(package
,FileName
,FilePath
);
4213 TRACE("Creating icon file at %s\n",debugstr_w(FilePath
));
4215 the_file
= CreateFileW(FilePath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
4216 FILE_ATTRIBUTE_NORMAL
, NULL
);
4218 if (the_file
== INVALID_HANDLE_VALUE
)
4220 ERR("Unable to create file %s\n",debugstr_w(FilePath
));
4221 msiobj_release(&row
->hdr
);
4229 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
4230 if (rc
!= ERROR_SUCCESS
)
4232 ERR("Failed to get stream\n");
4233 CloseHandle(the_file
);
4234 DeleteFileW(FilePath
);
4237 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
4238 } while (sz
== 1024);
4240 CloseHandle(the_file
);
4241 msiobj_release(&row
->hdr
);
4243 MSI_ViewClose(view
);
4244 msiobj_release(&view
->hdr
);
4249 /* Msi functions that seem appropriate here */
4250 UINT WINAPI
MsiDoActionA( MSIHANDLE hInstall
, LPCSTR szAction
)
4255 TRACE(" exteral attempt at action %s\n",szAction
);
4258 return ERROR_FUNCTION_FAILED
;
4260 return ERROR_FUNCTION_FAILED
;
4262 szwAction
= strdupAtoW(szAction
);
4265 return ERROR_FUNCTION_FAILED
;
4268 rc
= MsiDoActionW(hInstall
, szwAction
);
4269 HeapFree(GetProcessHeap(),0,szwAction
);
4273 UINT WINAPI
MsiDoActionW( MSIHANDLE hInstall
, LPCWSTR szAction
)
4275 MSIPACKAGE
*package
;
4276 UINT ret
= ERROR_INVALID_HANDLE
;
4278 TRACE(" external attempt at action %s \n",debugstr_w(szAction
));
4280 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
4283 ret
= ACTION_PerformAction(package
,szAction
);
4284 msiobj_release( &package
->hdr
);
4289 UINT WINAPI
MsiGetTargetPathA( MSIHANDLE hInstall
, LPCSTR szFolder
,
4290 LPSTR szPathBuf
, DWORD
* pcchPathBuf
)
4296 TRACE("getting folder %s %p %li\n",szFolder
,szPathBuf
, *pcchPathBuf
);
4299 return ERROR_FUNCTION_FAILED
;
4301 return ERROR_FUNCTION_FAILED
;
4303 szwFolder
= strdupAtoW(szFolder
);
4306 return ERROR_FUNCTION_FAILED
;
4308 szwPathBuf
= HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf
* sizeof(WCHAR
));
4310 rc
= MsiGetTargetPathW(hInstall
, szwFolder
, szwPathBuf
,pcchPathBuf
);
4312 WideCharToMultiByte( CP_ACP
, 0, szwPathBuf
, *pcchPathBuf
, szPathBuf
,
4313 *pcchPathBuf
, NULL
, NULL
);
4315 HeapFree(GetProcessHeap(),0,szwFolder
);
4316 HeapFree(GetProcessHeap(),0,szwPathBuf
);
4321 UINT WINAPI
MsiGetTargetPathW( MSIHANDLE hInstall
, LPCWSTR szFolder
, LPWSTR
4322 szPathBuf
, DWORD
* pcchPathBuf
)
4324 WCHAR path
[MAX_PATH
];
4326 MSIPACKAGE
*package
;
4328 TRACE("(%s %p %li)\n",debugstr_w(szFolder
),szPathBuf
,*pcchPathBuf
);
4330 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
4332 return ERROR_INVALID_HANDLE
;
4333 rc
= resolve_folder(package
, szFolder
, path
, FALSE
, FALSE
, NULL
);
4334 msiobj_release( &package
->hdr
);
4336 if (rc
== ERROR_SUCCESS
&& strlenW(path
) > *pcchPathBuf
)
4338 *pcchPathBuf
= strlenW(path
)+1;
4339 return ERROR_MORE_DATA
;
4341 else if (rc
== ERROR_SUCCESS
)
4343 *pcchPathBuf
= strlenW(path
)+1;
4344 strcpyW(szPathBuf
,path
);
4345 TRACE("Returning Path %s\n",debugstr_w(path
));
4352 UINT WINAPI
MsiGetSourcePathA( MSIHANDLE hInstall
, LPCSTR szFolder
,
4353 LPSTR szPathBuf
, DWORD
* pcchPathBuf
)
4359 TRACE("getting source %s %p %li\n",szFolder
,szPathBuf
, *pcchPathBuf
);
4362 return ERROR_FUNCTION_FAILED
;
4364 return ERROR_FUNCTION_FAILED
;
4366 szwFolder
= strdupAtoW(szFolder
);
4368 return ERROR_FUNCTION_FAILED
;
4370 szwPathBuf
= HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf
* sizeof(WCHAR
));
4372 rc
= MsiGetSourcePathW(hInstall
, szwFolder
, szwPathBuf
,pcchPathBuf
);
4374 WideCharToMultiByte( CP_ACP
, 0, szwPathBuf
, *pcchPathBuf
, szPathBuf
,
4375 *pcchPathBuf
, NULL
, NULL
);
4377 HeapFree(GetProcessHeap(),0,szwFolder
);
4378 HeapFree(GetProcessHeap(),0,szwPathBuf
);
4383 UINT WINAPI
MsiGetSourcePathW( MSIHANDLE hInstall
, LPCWSTR szFolder
, LPWSTR
4384 szPathBuf
, DWORD
* pcchPathBuf
)
4386 WCHAR path
[MAX_PATH
];
4388 MSIPACKAGE
*package
;
4390 TRACE("(%s %p %li)\n",debugstr_w(szFolder
),szPathBuf
,*pcchPathBuf
);
4392 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
4394 return ERROR_INVALID_HANDLE
;
4395 rc
= resolve_folder(package
, szFolder
, path
, TRUE
, FALSE
, NULL
);
4396 msiobj_release( &package
->hdr
);
4398 if (rc
== ERROR_SUCCESS
&& strlenW(path
) > *pcchPathBuf
)
4400 *pcchPathBuf
= strlenW(path
)+1;
4401 return ERROR_MORE_DATA
;
4403 else if (rc
== ERROR_SUCCESS
)
4405 *pcchPathBuf
= strlenW(path
)+1;
4406 strcpyW(szPathBuf
,path
);
4407 TRACE("Returning Path %s\n",debugstr_w(path
));
4414 UINT WINAPI
MsiSetTargetPathA(MSIHANDLE hInstall
, LPCSTR szFolder
,
4415 LPCSTR szFolderPath
)
4418 LPWSTR szwFolderPath
;
4422 return ERROR_FUNCTION_FAILED
;
4424 return ERROR_FUNCTION_FAILED
;
4426 szwFolder
= strdupAtoW(szFolder
);
4428 return ERROR_FUNCTION_FAILED
;
4430 szwFolderPath
= strdupAtoW(szFolderPath
);
4433 HeapFree(GetProcessHeap(),0,szwFolder
);
4434 return ERROR_FUNCTION_FAILED
;
4437 rc
= MsiSetTargetPathW(hInstall
, szwFolder
, szwFolderPath
);
4439 HeapFree(GetProcessHeap(),0,szwFolder
);
4440 HeapFree(GetProcessHeap(),0,szwFolderPath
);
4445 UINT
MSI_SetTargetPathW(MSIPACKAGE
*package
, LPCWSTR szFolder
,
4446 LPCWSTR szFolderPath
)
4449 WCHAR path
[MAX_PATH
];
4452 TRACE("(%p %s %s)\n",package
, debugstr_w(szFolder
),debugstr_w(szFolderPath
));
4455 return ERROR_INVALID_HANDLE
;
4457 if (szFolderPath
[0]==0)
4458 return ERROR_FUNCTION_FAILED
;
4460 if (GetFileAttributesW(szFolderPath
) == INVALID_FILE_ATTRIBUTES
)
4461 return ERROR_FUNCTION_FAILED
;
4463 resolve_folder(package
,szFolder
,path
,FALSE
,FALSE
,&folder
);
4466 return ERROR_INVALID_PARAMETER
;
4468 strcpyW(folder
->Property
,szFolderPath
);
4470 for (i
= 0; i
< package
->loaded_folders
; i
++)
4471 package
->folders
[i
].ResolvedTarget
[0]=0;
4473 for (i
= 0; i
< package
->loaded_folders
; i
++)
4474 resolve_folder(package
, package
->folders
[i
].Directory
, path
, FALSE
,
4477 return ERROR_SUCCESS
;
4480 UINT WINAPI
MsiSetTargetPathW(MSIHANDLE hInstall
, LPCWSTR szFolder
,
4481 LPCWSTR szFolderPath
)
4483 MSIPACKAGE
*package
;
4486 TRACE("(%s %s)\n",debugstr_w(szFolder
),debugstr_w(szFolderPath
));
4488 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
4489 ret
= MSI_SetTargetPathW( package
, szFolder
, szFolderPath
);
4490 msiobj_release( &package
->hdr
);
4494 BOOL WINAPI
MsiGetMode(MSIHANDLE hInstall
, DWORD iRunMode
)
4496 FIXME("STUB (%li)\n",iRunMode
);
4501 * according to the docs when this is called it immediently recalculates all the
4502 * components states as well
4504 UINT WINAPI
MsiSetFeatureStateA(MSIHANDLE hInstall
, LPCSTR szFeature
,
4505 INSTALLSTATE iState
)
4507 LPWSTR szwFeature
= NULL
;
4510 szwFeature
= strdupAtoW(szFeature
);
4513 return ERROR_FUNCTION_FAILED
;
4515 rc
= MsiSetFeatureStateW(hInstall
,szwFeature
, iState
);
4517 HeapFree(GetProcessHeap(),0,szwFeature
);
4522 UINT WINAPI
MsiSetFeatureStateW(MSIHANDLE hInstall
, LPCWSTR szFeature
,
4523 INSTALLSTATE iState
)
4525 MSIPACKAGE
* package
;
4528 TRACE(" %s to %i\n",debugstr_w(szFeature
), iState
);
4530 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
4532 return ERROR_INVALID_HANDLE
;
4534 index
= get_loaded_feature(package
,szFeature
);
4536 return ERROR_UNKNOWN_FEATURE
;
4538 package
->features
[index
].State
= iState
;
4540 return ERROR_SUCCESS
;
4543 UINT WINAPI
MsiGetFeatureStateA(MSIHANDLE hInstall
, LPSTR szFeature
,
4544 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
4546 LPWSTR szwFeature
= NULL
;
4549 szwFeature
= strdupAtoW(szFeature
);
4551 rc
= MsiGetFeatureStateW(hInstall
,szwFeature
,piInstalled
, piAction
);
4553 HeapFree( GetProcessHeap(), 0 , szwFeature
);
4558 UINT
MSI_GetFeatureStateW(MSIPACKAGE
*package
, LPWSTR szFeature
,
4559 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
4563 index
= get_loaded_feature(package
,szFeature
);
4565 return ERROR_UNKNOWN_FEATURE
;
4568 *piInstalled
= package
->features
[index
].State
;
4572 if (package
->features
[index
].Enabled
)
4573 *piAction
= INSTALLSTATE_LOCAL
;
4575 *piAction
= INSTALLSTATE_UNKNOWN
;
4578 return ERROR_SUCCESS
;
4581 UINT WINAPI
MsiGetFeatureStateW(MSIHANDLE hInstall
, LPWSTR szFeature
,
4582 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
4584 MSIPACKAGE
* package
;
4587 TRACE("%ld %s %p %p\n", hInstall
, debugstr_w(szFeature
), piInstalled
,
4590 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
4592 return ERROR_INVALID_HANDLE
;
4593 ret
= MSI_GetFeatureStateW(package
, szFeature
, piInstalled
, piAction
);
4594 msiobj_release( &package
->hdr
);
4598 UINT WINAPI
MsiGetComponentStateA(MSIHANDLE hInstall
, LPSTR szComponent
,
4599 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
4601 LPWSTR szwComponent
= NULL
;
4604 szwComponent
= strdupAtoW(szComponent
);
4606 rc
= MsiGetComponentStateW(hInstall
,szwComponent
,piInstalled
, piAction
);
4608 HeapFree( GetProcessHeap(), 0 , szwComponent
);
4613 UINT
MSI_GetComponentStateW(MSIPACKAGE
*package
, LPWSTR szComponent
,
4614 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
4618 TRACE("%p %s %p %p\n", package
, debugstr_w(szComponent
), piInstalled
,
4621 index
= get_loaded_component(package
,szComponent
);
4623 return ERROR_UNKNOWN_COMPONENT
;
4626 *piInstalled
= package
->components
[index
].State
;
4630 if (package
->components
[index
].Enabled
&&
4631 package
->components
[index
].FeatureState
)
4632 *piAction
= INSTALLSTATE_LOCAL
;
4634 *piAction
= INSTALLSTATE_UNKNOWN
;
4637 return ERROR_SUCCESS
;
4640 UINT WINAPI
MsiGetComponentStateW(MSIHANDLE hInstall
, LPWSTR szComponent
,
4641 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
4643 MSIPACKAGE
* package
;
4646 TRACE("%ld %s %p %p\n", hInstall
, debugstr_w(szComponent
),
4647 piInstalled
, piAction
);
4649 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
4651 return ERROR_INVALID_HANDLE
;
4652 ret
= MSI_GetComponentStateW( package
, szComponent
, piInstalled
, piAction
);
4653 msiobj_release( &package
->hdr
);
4658 static UINT
ACTION_Template(MSIPACKAGE
*package
)
4662 MSIRECORD
* row
= 0;
4663 static const WCHAR ExecSeqQuery
[] = {0};
4665 rc
= MsiDatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
4666 if (rc
!= ERROR_SUCCESS
)
4669 rc
= MsiViewExecute(view
, 0);
4670 if (rc
!= ERROR_SUCCESS
)
4673 msiobj_release(&view
->hdr
);
4679 rc
= MsiViewFetch(view
,&row
);
4680 if (rc
!= ERROR_SUCCESS
)
4686 msiobj_release(&row
->hdr
);
4689 msiobj_release(&view
->hdr
);