2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installexecutesequence_table.asp
26 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/standard_actions_reference.asp
36 #include "wine/debug.h"
45 #include "wine/unicode.h"
48 #define CUSTOM_ACTION_TYPE_MASK 0x3F
50 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
52 typedef struct tagMSIFEATURE
55 WCHAR Feature_Parent
[96];
57 WCHAR Description
[0x100];
66 INT Components
[1024]; /* yes hardcoded limit.... I am bad */
70 typedef struct tagMSICOMPONENT
73 WCHAR ComponentId
[96];
76 WCHAR Condition
[0x100];
85 typedef struct tagMSIFOLDER
88 WCHAR TargetDefault
[96];
89 WCHAR SourceDefault
[96];
91 WCHAR ResolvedTarget
[MAX_PATH
];
92 WCHAR ResolvedSource
[MAX_PATH
];
93 WCHAR Property
[MAX_PATH
]; /* initially set property */
96 /* 0 = uninitialized */
98 /* 2 = created remove if empty */
99 /* 3 = created persist if empty */
104 typedef struct tagMSIFILE
108 WCHAR FileName
[MAX_PATH
];
116 /* 0 = uninitialize */
117 /* 1 = not present */
118 /* 2 = present but replace */
119 /* 3 = present do not replace */
121 WCHAR SourcePath
[MAX_PATH
];
122 WCHAR TargetPath
[MAX_PATH
];
129 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
);
130 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
);
132 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
);
134 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
);
135 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
);
136 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
);
137 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
);
138 static UINT
ACTION_FileCost(MSIPACKAGE
*package
);
139 static UINT
ACTION_InstallFiles(MSIPACKAGE
*package
);
140 static UINT
ACTION_DuplicateFiles(MSIPACKAGE
*package
);
141 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
);
142 static UINT
ACTION_CustomAction(MSIPACKAGE
*package
,const WCHAR
*action
);
143 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
);
144 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
);
145 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
);
146 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
);
147 static UINT
ACTION_RegisterClassInfo(MSIPACKAGE
*package
);
148 static UINT
ACTION_RegisterProgIdInfo(MSIPACKAGE
*package
);
149 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
);
150 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
);
152 static UINT
HANDLE_CustomType1(MSIPACKAGE
*package
, const LPWSTR source
,
153 const LPWSTR target
, const INT type
);
154 static UINT
HANDLE_CustomType2(MSIPACKAGE
*package
, const LPWSTR source
,
155 const LPWSTR target
, const INT type
);
157 static DWORD
deformat_string(MSIPACKAGE
*package
, WCHAR
* ptr
,WCHAR
** data
);
158 static UINT
resolve_folder(MSIPACKAGE
*package
, LPCWSTR name
, LPWSTR path
,
159 BOOL source
, BOOL set_prop
, MSIFOLDER
**folder
);
161 static int track_tempfile(MSIPACKAGE
*package
, LPCWSTR name
, LPCWSTR path
);
164 * consts and values used
166 static const WCHAR cszSourceDir
[] = {'S','o','u','r','c','e','D','i','r',0};
167 static const WCHAR cszRootDrive
[] = {'R','O','O','T','D','R','I','V','E',0};
168 static const WCHAR cszTargetDir
[] = {'T','A','R','G','E','T','D','I','R',0};
169 static const WCHAR cszTempFolder
[]= {'T','e','m','p','F','o','l','d','e','r',0};
170 static const WCHAR cszDatabase
[]={'D','A','T','A','B','A','S','E',0};
171 static const WCHAR c_collen
[] = {'C',':','\\',0};
173 static const WCHAR cszlsb
[]={'[',0};
174 static const WCHAR cszrsb
[]={']',0};
175 static const WCHAR cszbs
[]={'\\',0};
177 const static WCHAR szCreateFolders
[] =
178 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
179 const static WCHAR szCostFinalize
[] =
180 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
181 const static WCHAR szInstallFiles
[] =
182 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
183 const static WCHAR szDuplicateFiles
[] =
184 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
185 const static WCHAR szWriteRegistryValues
[] =
186 {'W','r','i','t','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
187 const static WCHAR szCostInitialize
[] =
188 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
189 const static WCHAR szFileCost
[] = {'F','i','l','e','C','o','s','t',0};
190 const static WCHAR szInstallInitialize
[] =
191 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
192 const static WCHAR szInstallValidate
[] =
193 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
194 const static WCHAR szLaunchConditions
[] =
195 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
196 const static WCHAR szProcessComponents
[] =
197 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
198 const static WCHAR szRegisterTypeLibraries
[] =
199 {'R','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r',
201 const static WCHAR szRegisterClassInfo
[] =
202 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
203 const static WCHAR szRegisterProgIdInfo
[] =
204 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
205 const static WCHAR szCreateShortcuts
[] =
206 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
207 const static WCHAR szPublishProduct
[] =
208 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
210 /********************************************************
211 * helper functions to get around current HACKS and such
212 ********************************************************/
213 inline static void reduce_to_longfilename(WCHAR
* filename
)
215 if (strchrW(filename
,'|'))
217 WCHAR newname
[MAX_PATH
];
218 strcpyW(newname
,strchrW(filename
,'|')+1);
219 strcpyW(filename
,newname
);
223 inline static char *strdupWtoA( const WCHAR
*str
)
228 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
230 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
)))
231 WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
236 inline static WCHAR
*strdupAtoW( const char *str
)
241 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
242 if ((ret
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
243 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
248 inline static WCHAR
*load_dynamic_stringW(MSIRECORD
*row
, INT index
)
255 rc
= MSI_RecordGetStringW(row
,index
,NULL
,&sz
);
260 ret
= HeapAlloc(GetProcessHeap(),0,sz
* sizeof (WCHAR
));
261 rc
= MSI_RecordGetStringW(row
,index
,ret
,&sz
);
265 inline static int get_loaded_component(MSIPACKAGE
* package
, LPCWSTR Component
)
270 for (i
= 0; i
< package
->loaded_components
; i
++)
272 if (strcmpW(Component
,package
->components
[i
].Component
)==0)
281 inline static int get_loaded_feature(MSIPACKAGE
* package
, LPCWSTR Feature
)
286 for (i
= 0; i
< package
->loaded_features
; i
++)
288 if (strcmpW(Feature
,package
->features
[i
].Feature
)==0)
297 inline static int get_loaded_file(MSIPACKAGE
* package
, LPCWSTR file
)
302 for (i
= 0; i
< package
->loaded_files
; i
++)
304 if (strcmpW(file
,package
->files
[i
].File
)==0)
313 static int track_tempfile(MSIPACKAGE
*package
, LPCWSTR name
, LPCWSTR path
)
321 for (i
=0; i
< package
->loaded_files
; i
++)
322 if (strcmpW(package
->files
[i
].File
,name
)==0)
325 index
= package
->loaded_files
;
326 package
->loaded_files
++;
327 if (package
->loaded_files
== 1)
328 package
->files
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE
));
330 package
->files
= HeapReAlloc(GetProcessHeap(),0,
331 package
->files
, package
->loaded_files
* sizeof(MSIFILE
));
333 memset(&package
->files
[index
],0,sizeof(MSIFILE
));
335 strcpyW(package
->files
[index
].File
,name
);
336 strcpyW(package
->files
[index
].TargetPath
,path
);
337 package
->files
[index
].Temporary
= TRUE
;
339 TRACE("Tracking tempfile (%s)\n",debugstr_w(package
->files
[index
].File
));
344 void ACTION_remove_tracked_tempfiles(MSIPACKAGE
* package
)
351 for (i
= 0; i
< package
->loaded_files
; i
++)
353 if (package
->files
[i
].Temporary
)
354 DeleteFileW(package
->files
[i
].TargetPath
);
359 static void ui_progress(MSIPACKAGE
*package
, int a
, int b
, int c
, int d
)
363 row
= MSI_CreateRecord(4);
364 MSI_RecordSetInteger(row
,1,a
);
365 MSI_RecordSetInteger(row
,2,b
);
366 MSI_RecordSetInteger(row
,3,c
);
367 MSI_RecordSetInteger(row
,4,d
);
368 MSI_ProcessMessage(package
, INSTALLMESSAGE_PROGRESS
, row
);
369 msiobj_release(&row
->hdr
);
372 static void ui_actiondata(MSIPACKAGE
*package
, LPCWSTR action
, MSIRECORD
* record
)
374 static const WCHAR Query_t
[] =
375 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
376 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
377 ' ','\'','%','s','\'',0};
382 static WCHAR
*ActionFormat
=NULL
;
383 static WCHAR LastAction
[0x100] = {0};
387 if (strcmpW(LastAction
,action
)!=0)
389 sprintfW(Query
,Query_t
,action
);
390 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
391 if (rc
!= ERROR_SUCCESS
)
393 rc
= MSI_ViewExecute(view
, 0);
394 if (rc
!= ERROR_SUCCESS
)
399 rc
= MSI_ViewFetch(view
,&row
);
400 if (rc
!= ERROR_SUCCESS
)
406 if (MSI_RecordIsNull(row
,3))
408 msiobj_release(&row
->hdr
);
410 msiobj_release(&view
->hdr
);
415 HeapFree(GetProcessHeap(),0,ActionFormat
);
417 ActionFormat
= load_dynamic_stringW(row
,3);
418 strcpyW(LastAction
,action
);
419 msiobj_release(&row
->hdr
);
421 msiobj_release(&view
->hdr
);
433 ptr2
= strchrW(ptr
,'[');
436 strncpyW(tmp
,ptr
,ptr2
-ptr
);
438 strcatW(message
,tmp
);
441 data
= load_dynamic_stringW(record
,field
);
444 strcatW(message
,data
);
445 HeapFree(GetProcessHeap(),0,data
);
447 ptr
=strchrW(ptr2
,']');
452 strcatW(message
,ptr
);
457 row
= MSI_CreateRecord(1);
458 MSI_RecordSetStringW(row
,1,message
);
460 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, row
);
461 msiobj_release(&row
->hdr
);
465 static void ui_actionstart(MSIPACKAGE
*package
, LPCWSTR action
)
467 static const WCHAR template_s
[]=
468 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ','%','s','.',0};
469 static const WCHAR format
[] =
470 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
471 static const WCHAR Query_t
[] =
472 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
473 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
474 ' ','\'','%','s','\'',0};
480 WCHAR
*ActionText
=NULL
;
483 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
485 sprintfW(Query
,Query_t
,action
);
486 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
487 if (rc
!= ERROR_SUCCESS
)
489 rc
= MSI_ViewExecute(view
, 0);
490 if (rc
!= ERROR_SUCCESS
)
493 msiobj_release(&view
->hdr
);
496 rc
= MSI_ViewFetch(view
,&row
);
497 if (rc
!= ERROR_SUCCESS
)
500 msiobj_release(&view
->hdr
);
504 ActionText
= load_dynamic_stringW(row
,2);
505 msiobj_release(&row
->hdr
);
507 msiobj_release(&view
->hdr
);
509 sprintfW(message
,template_s
,timet
,action
,ActionText
);
511 row
= MSI_CreateRecord(1);
512 MSI_RecordSetStringW(row
,1,message
);
514 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, row
);
515 msiobj_release(&row
->hdr
);
516 HeapFree(GetProcessHeap(),0,ActionText
);
519 static void ui_actioninfo(MSIPACKAGE
*package
, LPCWSTR action
, BOOL start
,
523 static const WCHAR template_s
[]=
524 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ','%','s',
526 static const WCHAR template_e
[]=
527 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ','%','s',
528 '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ','%','i','.',0};
529 static const WCHAR format
[] =
530 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
534 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
536 sprintfW(message
,template_s
,timet
,action
);
538 sprintfW(message
,template_e
,timet
,action
,rc
);
540 row
= MSI_CreateRecord(1);
541 MSI_RecordSetStringW(row
,1,message
);
543 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
544 msiobj_release(&row
->hdr
);
547 /****************************************************
548 * TOP level entry points
549 *****************************************************/
551 UINT
ACTION_DoTopLevelINSTALL(MSIPACKAGE
*package
, LPCWSTR szPackagePath
,
552 LPCWSTR szCommandLine
)
557 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
562 WCHAR check
[MAX_PATH
];
566 strcpyW(pth
,szPackagePath
);
567 p
= strrchrW(pth
,'\\');
575 if (MSI_GetPropertyW(package
,cszSourceDir
,check
,&size
)
577 MSI_SetPropertyW(package
, cszSourceDir
, pth
);
583 ptr
= (LPWSTR
)szCommandLine
;
590 TRACE("Looking at %s\n",debugstr_w(ptr
));
592 ptr2
= strchrW(ptr
,'=');
598 while (*ptr
== ' ') ptr
++;
599 strncpyW(prop
,ptr
,ptr2
-ptr
);
604 while (*ptr
&& (quote
|| (!quote
&& *ptr
!=' ')))
617 strncpyW(val
,ptr2
,len
);
620 if (strlenW(prop
) > 0)
622 TRACE("Found commandline property (%s) = (%s)\n", debugstr_w(prop
), debugstr_w(val
));
623 MSI_SetPropertyW(package
,prop
,val
);
631 if (MSI_GetPropertyW(package
,szUILevel
,buffer
,&sz
) == ERROR_SUCCESS
)
633 if (atoiW(buffer
) >= INSTALLUILEVEL_REDUCED
)
635 rc
= ACTION_ProcessUISequence(package
);
636 if (rc
== ERROR_SUCCESS
)
637 rc
= ACTION_ProcessExecSequence(package
,TRUE
);
640 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
643 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
649 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
)
653 static const WCHAR ExecSeqQuery
[] = {
654 's','e','l','e','c','t',' ','*',' ',
656 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
657 'S','e','q','u','e','n','c','e',' ',
658 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
659 '>',' ','%','i',' ','o','r','d','e','r',' ',
660 'b','y',' ','S','e','q','u','e','n','c','e',0 };
663 static const WCHAR IVQuery
[] = {
664 's','e','l','e','c','t',' ','S','e','q','u','e','n','c','e',' ',
665 'f','r','o','m',' ','I','n','s','t','a','l','l',
666 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
667 'w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',' ',
668 '`','I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`',
675 rc
= MSI_DatabaseOpenViewW(package
->db
, IVQuery
, &view
);
676 if (rc
!= ERROR_SUCCESS
)
678 rc
= MSI_ViewExecute(view
, 0);
679 if (rc
!= ERROR_SUCCESS
)
682 msiobj_release(&view
->hdr
);
685 rc
= MSI_ViewFetch(view
,&row
);
686 if (rc
!= ERROR_SUCCESS
)
689 msiobj_release(&view
->hdr
);
692 seq
= MSI_RecordGetInteger(row
,1);
693 msiobj_release(&row
->hdr
);
695 msiobj_release(&view
->hdr
);
696 sprintfW(Query
,ExecSeqQuery
,seq
);
699 sprintfW(Query
,ExecSeqQuery
,0);
701 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
702 if (rc
== ERROR_SUCCESS
)
704 rc
= MSI_ViewExecute(view
, 0);
706 if (rc
!= ERROR_SUCCESS
)
709 msiobj_release(&view
->hdr
);
713 TRACE("Running the actions \n");
720 rc
= MSI_ViewFetch(view
,&row
);
721 if (rc
!= ERROR_SUCCESS
)
727 /* check conditions */
728 if (!MSI_RecordIsNull(row
,2))
731 cond
= load_dynamic_stringW(row
,2);
735 /* this is a hack to skip errors in the condition code */
736 if (MSI_EvaluateConditionW(package
, cond
) ==
739 HeapFree(GetProcessHeap(),0,cond
);
740 msiobj_release(&row
->hdr
);
744 HeapFree(GetProcessHeap(),0,cond
);
749 rc
= MSI_RecordGetStringW(row
,1,buffer
,&sz
);
750 if (rc
!= ERROR_SUCCESS
)
752 ERR("Error is %x\n",rc
);
753 msiobj_release(&row
->hdr
);
757 rc
= ACTION_PerformAction(package
,buffer
);
759 if (rc
!= ERROR_SUCCESS
)
761 ERR("Execution halted due to error (%i)\n",rc
);
762 msiobj_release(&row
->hdr
);
766 msiobj_release(&row
->hdr
);
770 msiobj_release(&view
->hdr
);
778 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
)
782 static const WCHAR ExecSeqQuery
[] = {
783 's','e','l','e','c','t',' ','*',' ',
784 'f','r','o','m',' ','I','n','s','t','a','l','l',
785 'U','I','S','e','q','u','e','n','c','e',' ',
786 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ', '>',' ','0',' ',
787 'o','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e',0};
789 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
791 if (rc
== ERROR_SUCCESS
)
793 rc
= MSI_ViewExecute(view
, 0);
795 if (rc
!= ERROR_SUCCESS
)
798 msiobj_release(&view
->hdr
);
802 TRACE("Running the actions \n");
810 rc
= MSI_ViewFetch(view
,&row
);
811 if (rc
!= ERROR_SUCCESS
)
817 /* check conditions */
818 if (!MSI_RecordIsNull(row
,2))
821 cond
= load_dynamic_stringW(row
,2);
825 /* this is a hack to skip errors in the condition code */
826 if (MSI_EvaluateConditionW(package
, cond
) ==
829 HeapFree(GetProcessHeap(),0,cond
);
830 msiobj_release(&row
->hdr
);
834 HeapFree(GetProcessHeap(),0,cond
);
839 rc
= MSI_RecordGetStringW(row
,1,buffer
,&sz
);
840 if (rc
!= ERROR_SUCCESS
)
842 ERR("Error is %x\n",rc
);
843 msiobj_release(&row
->hdr
);
847 rc
= ACTION_PerformAction(package
,buffer
);
849 if (rc
!= ERROR_SUCCESS
)
851 ERR("Execution halted due to error (%i)\n",rc
);
852 msiobj_release(&row
->hdr
);
856 msiobj_release(&row
->hdr
);
860 msiobj_release(&view
->hdr
);
867 /********************************************************
868 * ACTION helper functions and functions that perform the actions
869 *******************************************************/
872 * Alot of actions are really important even if they don't do anything
873 * explicit.. Lots of properties are set at the beginning of the installation
874 * CostFinalize does a bunch of work to translated the directories and such
876 * But until I get write access to the database that is hard, so I am going to
877 * hack it to see if I can get something to run.
879 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
)
881 UINT rc
= ERROR_SUCCESS
;
883 TRACE("Performing action (%s)\n",debugstr_w(action
));
884 ui_actioninfo(package
, action
, TRUE
, 0);
885 ui_actionstart(package
, action
);
886 ui_progress(package
,2,1,0,0);
888 /* pre install, setup and configuration block */
889 if (strcmpW(action
,szLaunchConditions
)==0)
890 rc
= ACTION_LaunchConditions(package
);
891 else if (strcmpW(action
,szCostInitialize
)==0)
892 rc
= ACTION_CostInitialize(package
);
893 else if (strcmpW(action
,szFileCost
)==0)
894 rc
= ACTION_FileCost(package
);
895 else if (strcmpW(action
,szCostFinalize
)==0)
896 rc
= ACTION_CostFinalize(package
);
897 else if (strcmpW(action
,szInstallValidate
)==0)
898 rc
= ACTION_InstallValidate(package
);
901 else if (strcmpW(action
,szProcessComponents
)==0)
902 rc
= ACTION_ProcessComponents(package
);
903 else if (strcmpW(action
,szInstallInitialize
)==0)
904 rc
= ACTION_InstallInitialize(package
);
905 else if (strcmpW(action
,szCreateFolders
)==0)
906 rc
= ACTION_CreateFolders(package
);
907 else if (strcmpW(action
,szInstallFiles
)==0)
908 rc
= ACTION_InstallFiles(package
);
909 else if (strcmpW(action
,szDuplicateFiles
)==0)
910 rc
= ACTION_DuplicateFiles(package
);
911 else if (strcmpW(action
,szWriteRegistryValues
)==0)
912 rc
= ACTION_WriteRegistryValues(package
);
913 else if (strcmpW(action
,szRegisterTypeLibraries
)==0)
914 rc
= ACTION_RegisterTypeLibraries(package
);
915 else if (strcmpW(action
,szRegisterClassInfo
)==0)
916 rc
= ACTION_RegisterClassInfo(package
);
917 else if (strcmpW(action
,szRegisterProgIdInfo
)==0)
918 rc
= ACTION_RegisterProgIdInfo(package
);
919 else if (strcmpW(action
,szCreateShortcuts
)==0)
920 rc
= ACTION_CreateShortcuts(package
);
921 else if (strcmpW(action
,szPublishProduct
)==0)
922 rc
= ACTION_PublishProduct(package
);
925 Called during iTunes but unimplemented and seem important
927 ResolveSource (sets SourceDir)
931 else if ((rc
= ACTION_CustomAction(package
,action
)) != ERROR_SUCCESS
)
933 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action
));
937 ui_actioninfo(package
, action
, FALSE
, rc
);
942 static UINT
ACTION_CustomAction(MSIPACKAGE
*package
,const WCHAR
*action
)
944 UINT rc
= ERROR_SUCCESS
;
947 WCHAR ExecSeqQuery
[1024] =
948 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','C','u','s','t','o'
949 ,'m','A','c','t','i','o','n',' ','w','h','e','r','e',' ','`','A','c','t','i'
950 ,'o','n','`',' ','=',' ','`',0};
951 static const WCHAR end
[]={'`',0};
955 WCHAR
*deformated
=NULL
;
957 strcatW(ExecSeqQuery
,action
);
958 strcatW(ExecSeqQuery
,end
);
960 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
962 if (rc
!= ERROR_SUCCESS
)
965 rc
= MSI_ViewExecute(view
, 0);
966 if (rc
!= ERROR_SUCCESS
)
969 msiobj_release(&view
->hdr
);
973 rc
= MSI_ViewFetch(view
,&row
);
974 if (rc
!= ERROR_SUCCESS
)
977 msiobj_release(&view
->hdr
);
981 type
= MSI_RecordGetInteger(row
,2);
983 source
= load_dynamic_stringW(row
,3);
984 target
= load_dynamic_stringW(row
,4);
986 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action
),type
,
987 debugstr_w(source
), debugstr_w(target
));
989 /* we are ignoring ALOT of flags and important synchronization stuff */
990 switch (type
& CUSTOM_ACTION_TYPE_MASK
)
992 case 1: /* DLL file stored in a Binary table stream */
993 rc
= HANDLE_CustomType1(package
,source
,target
,type
);
995 case 2: /* EXE file stored in a Binary table strem */
996 rc
= HANDLE_CustomType2(package
,source
,target
,type
);
998 case 35: /* Directory set with formatted text. */
999 case 51: /* Property set with formatted text. */
1000 deformat_string(package
,target
,&deformated
);
1001 rc
= MSI_SetPropertyW(package
,source
,deformated
);
1002 HeapFree(GetProcessHeap(),0,deformated
);
1005 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
1006 type
& CUSTOM_ACTION_TYPE_MASK
, debugstr_w(source
),
1007 debugstr_w(target
));
1010 HeapFree(GetProcessHeap(),0,source
);
1011 HeapFree(GetProcessHeap(),0,target
);
1012 msiobj_release(&row
->hdr
);
1013 MSI_ViewClose(view
);
1014 msiobj_release(&view
->hdr
);
1018 static UINT
store_binary_to_temp(MSIPACKAGE
*package
, const LPWSTR source
,
1023 if (MSI_GetPropertyW(package
, cszTempFolder
, tmp_file
, &sz
)
1025 GetTempPathW(MAX_PATH
,tmp_file
);
1027 strcatW(tmp_file
,source
);
1029 if (GetFileAttributesW(tmp_file
) != INVALID_FILE_ATTRIBUTES
)
1031 TRACE("File already exists\n");
1032 return ERROR_SUCCESS
;
1036 /* write out the file */
1039 MSIRECORD
* row
= 0;
1041 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','B','i'
1042 ,'n','a','r','y',' ','w','h','e','r','e',' ','N','a','m','e','=','`',0};
1043 static const WCHAR end
[]={'`',0};
1047 if (track_tempfile(package
, source
, tmp_file
)!=0)
1048 FIXME("File Name in temp tracking collision\n");
1050 the_file
= CreateFileW(tmp_file
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
1051 FILE_ATTRIBUTE_NORMAL
, NULL
);
1053 if (the_file
== INVALID_HANDLE_VALUE
)
1054 return ERROR_FUNCTION_FAILED
;
1056 strcatW(Query
,source
);
1059 rc
= MSI_DatabaseOpenViewW( package
->db
, Query
, &view
);
1060 if (rc
!= ERROR_SUCCESS
)
1063 rc
= MSI_ViewExecute(view
, 0);
1064 if (rc
!= ERROR_SUCCESS
)
1066 MSI_ViewClose(view
);
1067 msiobj_release(&view
->hdr
);
1071 rc
= MSI_ViewFetch(view
,&row
);
1072 if (rc
!= ERROR_SUCCESS
)
1074 MSI_ViewClose(view
);
1075 msiobj_release(&view
->hdr
);
1083 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
1084 if (rc
!= ERROR_SUCCESS
)
1086 ERR("Failed to get stream\n");
1087 CloseHandle(the_file
);
1088 DeleteFileW(tmp_file
);
1091 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
1092 } while (sz
== 1024);
1094 CloseHandle(the_file
);
1096 msiobj_release(&row
->hdr
);
1097 MSI_ViewClose(view
);
1098 msiobj_release(&view
->hdr
);
1101 return ERROR_SUCCESS
;
1105 typedef UINT __stdcall
CustomEntry(MSIHANDLE
);
1108 MSIPACKAGE
*package
;
1109 WCHAR target
[MAX_PATH
];
1110 WCHAR source
[MAX_PATH
];
1114 static DWORD WINAPI
DllThread(LPVOID info
)
1118 thread_struct
*stuff
;
1121 stuff
= (thread_struct
*)info
;
1123 TRACE("Asynchronous start (%s, %s) \n", debugstr_w(stuff
->source
),
1124 debugstr_w(stuff
->target
));
1126 DLL
= LoadLibraryW(stuff
->source
);
1129 proc
= strdupWtoA( stuff
->target
);
1130 fn
= (CustomEntry
*)GetProcAddress(DLL
,proc
);
1134 MSIPACKAGE
*package
= stuff
->package
;
1136 TRACE("Calling function\n");
1137 hPackage
= msiobj_findhandle( &package
->hdr
);
1139 ERR("Handle for object %p not found\n", package
);
1141 msiobj_release( &package
->hdr
);
1144 ERR("Cannot load functon\n");
1146 HeapFree(GetProcessHeap(),0,proc
);
1150 ERR("Unable to load library\n");
1151 msiobj_release( &stuff
->package
->hdr
);
1152 HeapFree( GetProcessHeap(), 0, info
);
1157 static UINT
HANDLE_CustomType1(MSIPACKAGE
*package
, const LPWSTR source
,
1158 const LPWSTR target
, const INT type
)
1160 WCHAR tmp_file
[MAX_PATH
];
1165 store_binary_to_temp(package
, source
, tmp_file
);
1167 TRACE("Calling function %s from %s\n",debugstr_w(target
),
1168 debugstr_w(tmp_file
));
1170 if (!strchrW(tmp_file
,'.'))
1172 static const WCHAR dot
[]={'.',0};
1173 strcatW(tmp_file
,dot
);
1178 /* DWORD ThreadId; */
1179 thread_struct
*info
= HeapAlloc( GetProcessHeap(), 0, sizeof(*info
) );
1181 /* msiobj_addref( &package->hdr ); */
1182 info
->package
= package
;
1183 strcpyW(info
->target
,target
);
1184 strcpyW(info
->source
,tmp_file
);
1185 TRACE("Start Asynchronous execution\n");
1186 FIXME("DATABASE NOT THREADSAFE... not starting\n");
1187 /* CreateThread(NULL,0,DllThread,(LPVOID)&info,0,&ThreadId); */
1188 /* FIXME: release the package if the CreateThread fails */
1189 HeapFree( GetProcessHeap(), 0, info
);
1190 return ERROR_SUCCESS
;
1193 DLL
= LoadLibraryW(tmp_file
);
1196 proc
= strdupWtoA( target
);
1197 fn
= (CustomEntry
*)GetProcAddress(DLL
,proc
);
1202 TRACE("Calling function\n");
1203 hPackage
= msiobj_findhandle( &package
->hdr
);
1205 ERR("Handle for object %p not found\n", package
);
1207 msiobj_release( &package
->hdr
);
1210 ERR("Cannot load functon\n");
1212 HeapFree(GetProcessHeap(),0,proc
);
1216 ERR("Unable to load library\n");
1218 return ERROR_SUCCESS
;
1221 static UINT
HANDLE_CustomType2(MSIPACKAGE
*package
, const LPWSTR source
,
1222 const LPWSTR target
, const INT type
)
1224 WCHAR tmp_file
[MAX_PATH
*2];
1226 PROCESS_INFORMATION info
;
1229 static const WCHAR spc
[] = {' ',0};
1231 memset(&si
,0,sizeof(STARTUPINFOW
));
1232 memset(&info
,0,sizeof(PROCESS_INFORMATION
));
1234 store_binary_to_temp(package
, source
, tmp_file
);
1236 strcatW(tmp_file
,spc
);
1237 deformat_string(package
,target
,&deformated
);
1238 strcatW(tmp_file
,deformated
);
1240 HeapFree(GetProcessHeap(),0,deformated
);
1242 TRACE("executing exe %s \n",debugstr_w(tmp_file
));
1244 rc
= CreateProcessW(NULL
, tmp_file
, NULL
, NULL
, FALSE
, 0, NULL
,
1245 c_collen
, &si
, &info
);
1249 ERR("Unable to execute command\n");
1250 return ERROR_SUCCESS
;
1254 WaitForSingleObject(info
.hProcess
,INFINITE
);
1256 return ERROR_SUCCESS
;
1259 /***********************************************************************
1262 * Recursively create all directories in the path.
1264 * shamelessly stolen from setupapi/queue.c
1266 static BOOL
create_full_pathW(const WCHAR
*path
)
1272 new_path
= HeapAlloc(GetProcessHeap(), 0, (strlenW(path
) + 1) *
1274 strcpyW(new_path
, path
);
1276 while((len
= strlenW(new_path
)) && new_path
[len
- 1] == '\\')
1277 new_path
[len
- 1] = 0;
1279 while(!CreateDirectoryW(new_path
, NULL
))
1282 DWORD last_error
= GetLastError();
1283 if(last_error
== ERROR_ALREADY_EXISTS
)
1286 if(last_error
!= ERROR_PATH_NOT_FOUND
)
1292 if(!(slash
= strrchrW(new_path
, '\\')))
1298 len
= slash
- new_path
;
1300 if(!create_full_pathW(new_path
))
1305 new_path
[len
] = '\\';
1308 HeapFree(GetProcessHeap(), 0, new_path
);
1313 * Also we cannot enable/disable components either, so for now I am just going
1314 * to do all the directories for all the components.
1316 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
)
1318 static const WCHAR ExecSeqQuery
[] = {
1319 's','e','l','e','c','t',' ','D','i','r','e','c','t','o','r','y','_',' ',
1320 'f','r','o','m',' ','C','r','e','a','t','e','F','o','l','d','e','r',0 };
1325 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
1326 if (rc
!= ERROR_SUCCESS
)
1327 return ERROR_SUCCESS
;
1329 rc
= MSI_ViewExecute(view
, 0);
1330 if (rc
!= ERROR_SUCCESS
)
1332 MSI_ViewClose(view
);
1333 msiobj_release(&view
->hdr
);
1340 WCHAR full_path
[MAX_PATH
];
1342 MSIRECORD
*row
= NULL
, *uirow
;
1344 rc
= MSI_ViewFetch(view
,&row
);
1345 if (rc
!= ERROR_SUCCESS
)
1352 rc
= MSI_RecordGetStringW(row
,1,dir
,&sz
);
1354 if (rc
!= ERROR_SUCCESS
)
1356 ERR("Unable to get folder id \n");
1357 msiobj_release(&row
->hdr
);
1362 rc
= resolve_folder(package
,dir
,full_path
,FALSE
,FALSE
,&folder
);
1364 if (rc
!= ERROR_SUCCESS
)
1366 ERR("Unable to resolve folder id %s\n",debugstr_w(dir
));
1367 msiobj_release(&row
->hdr
);
1371 TRACE("Folder is %s\n",debugstr_w(full_path
));
1374 uirow
= MSI_CreateRecord(1);
1375 MSI_RecordSetStringW(uirow
,1,full_path
);
1376 ui_actiondata(package
,szCreateFolders
,uirow
);
1377 msiobj_release( &uirow
->hdr
);
1379 if (folder
->State
== 0)
1380 create_full_pathW(full_path
);
1384 msiobj_release(&row
->hdr
);
1386 MSI_ViewClose(view
);
1387 msiobj_release(&view
->hdr
);
1392 static int load_component(MSIPACKAGE
* package
, MSIRECORD
* row
)
1394 int index
= package
->loaded_components
;
1397 /* fill in the data */
1399 package
->loaded_components
++;
1400 if (package
->loaded_components
== 1)
1401 package
->components
= HeapAlloc(GetProcessHeap(),0,
1402 sizeof(MSICOMPONENT
));
1404 package
->components
= HeapReAlloc(GetProcessHeap(),0,
1405 package
->components
, package
->loaded_components
*
1406 sizeof(MSICOMPONENT
));
1408 memset(&package
->components
[index
],0,sizeof(MSICOMPONENT
));
1411 MSI_RecordGetStringW(row
,1,package
->components
[index
].Component
,&sz
);
1413 TRACE("Loading Component %s\n",
1414 debugstr_w(package
->components
[index
].Component
));
1417 if (!MSI_RecordIsNull(row
,2))
1418 MSI_RecordGetStringW(row
,2,package
->components
[index
].ComponentId
,&sz
);
1421 MSI_RecordGetStringW(row
,3,package
->components
[index
].Directory
,&sz
);
1423 package
->components
[index
].Attributes
= MSI_RecordGetInteger(row
,4);
1426 MSI_RecordGetStringW(row
,5,package
->components
[index
].Condition
,&sz
);
1429 MSI_RecordGetStringW(row
,6,package
->components
[index
].KeyPath
,&sz
);
1431 package
->components
[index
].State
= INSTALLSTATE_UNKNOWN
;
1432 package
->components
[index
].Enabled
= TRUE
;
1433 package
->components
[index
].FeatureState
= FALSE
;
1438 static void load_feature(MSIPACKAGE
* package
, MSIRECORD
* row
)
1440 int index
= package
->loaded_features
;
1442 static const WCHAR Query1
[] = {'S','E','L','E','C','T',' ','C','o','m','p',
1443 'o','n','e','n','t','_',' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1444 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ','F','e',
1445 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1446 static const WCHAR Query2
[] = {'S','E','L','E','C','T',' ','*',' ','F','R',
1447 'O','M',' ','C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ','C',
1448 'o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1456 /* fill in the data */
1458 package
->loaded_features
++;
1459 if (package
->loaded_features
== 1)
1460 package
->features
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE
));
1462 package
->features
= HeapReAlloc(GetProcessHeap(),0,package
->features
,
1463 package
->loaded_features
* sizeof(MSIFEATURE
));
1465 memset(&package
->features
[index
],0,sizeof(MSIFEATURE
));
1468 MSI_RecordGetStringW(row
,1,package
->features
[index
].Feature
,&sz
);
1470 TRACE("Loading feature %s\n",debugstr_w(package
->features
[index
].Feature
));
1473 if (!MSI_RecordIsNull(row
,2))
1474 MSI_RecordGetStringW(row
,2,package
->features
[index
].Feature_Parent
,&sz
);
1477 if (!MSI_RecordIsNull(row
,3))
1478 MSI_RecordGetStringW(row
,3,package
->features
[index
].Title
,&sz
);
1481 if (!MSI_RecordIsNull(row
,4))
1482 MSI_RecordGetStringW(row
,4,package
->features
[index
].Description
,&sz
);
1484 if (!MSI_RecordIsNull(row
,5))
1485 package
->features
[index
].Display
= MSI_RecordGetInteger(row
,5);
1487 package
->features
[index
].Level
= MSI_RecordGetInteger(row
,6);
1490 if (!MSI_RecordIsNull(row
,7))
1491 MSI_RecordGetStringW(row
,7,package
->features
[index
].Directory
,&sz
);
1493 package
->features
[index
].Attributes
= MSI_RecordGetInteger(row
,8);
1494 package
->features
[index
].State
= INSTALLSTATE_UNKNOWN
;
1496 /* load feature components */
1498 sprintfW(Query
,Query1
,package
->features
[index
].Feature
);
1499 rc
= MSI_DatabaseOpenViewW(package
->db
,Query
,&view
);
1500 if (rc
!= ERROR_SUCCESS
)
1502 rc
= MSI_ViewExecute(view
,0);
1503 if (rc
!= ERROR_SUCCESS
)
1505 MSI_ViewClose(view
);
1506 msiobj_release(&view
->hdr
);
1512 WCHAR buffer
[0x100];
1515 INT cnt
= package
->features
[index
].ComponentCount
;
1517 rc
= MSI_ViewFetch(view
,&row2
);
1518 if (rc
!= ERROR_SUCCESS
)
1522 MSI_RecordGetStringW(row2
,1,buffer
,&sz
);
1524 /* check to see if the component is already loaded */
1525 c_indx
= get_loaded_component(package
,buffer
);
1528 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer
),
1530 package
->features
[index
].Components
[cnt
] = c_indx
;
1531 package
->features
[index
].ComponentCount
++;
1534 sprintfW(Query
,Query2
,buffer
);
1536 rc
= MSI_DatabaseOpenViewW(package
->db
,Query
,&view2
);
1537 if (rc
!= ERROR_SUCCESS
)
1539 msiobj_release( &row2
->hdr
);
1542 rc
= MSI_ViewExecute(view2
,0);
1543 if (rc
!= ERROR_SUCCESS
)
1545 msiobj_release( &row2
->hdr
);
1546 MSI_ViewClose(view2
);
1547 msiobj_release( &view2
->hdr
);
1554 rc
= MSI_ViewFetch(view2
,&row3
);
1555 if (rc
!= ERROR_SUCCESS
)
1557 c_indx
= load_component(package
,row3
);
1558 msiobj_release( &row3
->hdr
);
1560 package
->features
[index
].Components
[cnt
] = c_indx
;
1561 package
->features
[index
].ComponentCount
++;
1563 MSI_ViewClose(view2
);
1564 msiobj_release( &view2
->hdr
);
1565 msiobj_release( &row2
->hdr
);
1567 MSI_ViewClose(view
);
1568 msiobj_release(&view
->hdr
);
1572 * I am not doing any of the costing functionality yet.
1573 * Mostly looking at doing the Component and Feature loading
1575 * The native MSI does ALOT of modification to tables here. Mostly adding alot
1576 * of temporary columns to the Feature and Component tables.
1578 * note: native msi also tracks the short filename. but I am only going to
1579 * track the long ones. Also looking at this directory table
1580 * it appears that the directory table does not get the parents
1581 * resolved base on property only based on their entrys in the
1584 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
)
1590 static const WCHAR Query_all
[] = {
1591 'S','E','L','E','C','T',' ','*',' ',
1592 'F','R','O','M',' ','F','e','a','t','u','r','e',0};
1593 static const WCHAR szCosting
[] = {
1594 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1595 static const WCHAR szZero
[] = { '0', 0 };
1597 MSI_SetPropertyW(package
, szCosting
, szZero
);
1598 MSI_SetPropertyW(package
, cszRootDrive
, c_collen
);
1601 rc
= MSI_DatabaseOpenViewW(package
->db
,Query_all
,&view
);
1602 if (rc
!= ERROR_SUCCESS
)
1604 rc
= MSI_ViewExecute(view
,0);
1605 if (rc
!= ERROR_SUCCESS
)
1607 MSI_ViewClose(view
);
1608 msiobj_release(&view
->hdr
);
1615 rc
= MSI_ViewFetch(view
,&row
);
1616 if (rc
!= ERROR_SUCCESS
)
1619 load_feature(package
,row
);
1620 msiobj_release(&row
->hdr
);
1622 MSI_ViewClose(view
);
1623 msiobj_release(&view
->hdr
);
1625 return ERROR_SUCCESS
;
1628 static UINT
load_file(MSIPACKAGE
* package
, MSIRECORD
* row
)
1630 DWORD index
= package
->loaded_files
;
1632 WCHAR buffer
[0x100];
1635 /* fill in the data */
1637 package
->loaded_files
++;
1638 if (package
->loaded_files
== 1)
1639 package
->files
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE
));
1641 package
->files
= HeapReAlloc(GetProcessHeap(),0,
1642 package
->files
, package
->loaded_files
* sizeof(MSIFILE
));
1644 memset(&package
->files
[index
],0,sizeof(MSIFILE
));
1647 MSI_RecordGetStringW(row
,1,package
->files
[index
].File
,&sz
);
1650 MSI_RecordGetStringW(row
,2,buffer
,&sz
);
1652 package
->files
[index
].ComponentIndex
= -1;
1653 for (i
= 0; i
< package
->loaded_components
; i
++)
1654 if (strcmpW(package
->components
[i
].Component
,buffer
)==0)
1656 package
->files
[index
].ComponentIndex
= i
;
1659 if (package
->files
[index
].ComponentIndex
== -1)
1660 ERR("Unfound Component %s\n",debugstr_w(buffer
));
1663 MSI_RecordGetStringW(row
,3,package
->files
[index
].FileName
,&sz
);
1665 reduce_to_longfilename(package
->files
[index
].FileName
);
1667 package
->files
[index
].FileSize
= MSI_RecordGetInteger(row
,4);
1670 if (!MSI_RecordIsNull(row
,5))
1671 MSI_RecordGetStringW(row
,5,package
->files
[index
].Version
,&sz
);
1674 if (!MSI_RecordIsNull(row
,6))
1675 MSI_RecordGetStringW(row
,6,package
->files
[index
].Language
,&sz
);
1677 if (!MSI_RecordIsNull(row
,7))
1678 package
->files
[index
].Attributes
= MSI_RecordGetInteger(row
,7);
1680 package
->files
[index
].Sequence
= MSI_RecordGetInteger(row
,8);
1682 package
->files
[index
].Temporary
= FALSE
;
1683 package
->files
[index
].State
= 0;
1685 TRACE("File Loaded (%s)\n",debugstr_w(package
->files
[index
].File
));
1687 return ERROR_SUCCESS
;
1690 static UINT
ACTION_FileCost(MSIPACKAGE
*package
)
1695 static const WCHAR Query
[] = {
1696 'S','E','L','E','C','T',' ','*',' ',
1697 'F','R','O','M',' ','F','i','l','e',' ',
1698 'O','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e', 0};
1701 return ERROR_INVALID_HANDLE
;
1703 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1704 if (rc
!= ERROR_SUCCESS
)
1705 return ERROR_SUCCESS
;
1707 rc
= MSI_ViewExecute(view
, 0);
1708 if (rc
!= ERROR_SUCCESS
)
1710 MSI_ViewClose(view
);
1711 msiobj_release(&view
->hdr
);
1712 return ERROR_SUCCESS
;
1717 rc
= MSI_ViewFetch(view
,&row
);
1718 if (rc
!= ERROR_SUCCESS
)
1723 load_file(package
,row
);
1724 msiobj_release(&row
->hdr
);
1726 MSI_ViewClose(view
);
1727 msiobj_release(&view
->hdr
);
1729 return ERROR_SUCCESS
;
1732 static INT
load_folder(MSIPACKAGE
*package
, const WCHAR
* dir
)
1736 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','D','i','r','e','c',
1737 't','o','r','y',' ','w','h','e','r','e',' ','`','D','i','r','e','c','t',
1738 'o','r','y','`',' ','=',' ','`',0};
1739 static const WCHAR end
[]={'`',0};
1742 WCHAR targetbuffer
[0x100];
1743 WCHAR
*srcdir
= NULL
;
1744 WCHAR
*targetdir
= NULL
;
1745 WCHAR parent
[0x100];
1747 MSIRECORD
* row
= 0;
1751 TRACE("Looking for dir %s\n",debugstr_w(dir
));
1753 for (i
= 0; i
< package
->loaded_folders
; i
++)
1755 if (strcmpW(package
->folders
[i
].Directory
,dir
)==0)
1757 TRACE(" %s retuning on index %lu\n",debugstr_w(dir
),i
);
1762 TRACE("Working to load %s\n",debugstr_w(dir
));
1764 index
= package
->loaded_folders
;
1766 package
->loaded_folders
++;
1767 if (package
->loaded_folders
== 1)
1768 package
->folders
= HeapAlloc(GetProcessHeap(),0,
1771 package
->folders
= HeapReAlloc(GetProcessHeap(),0,
1772 package
->folders
, package
->loaded_folders
*
1775 memset(&package
->folders
[index
],0,sizeof(MSIFOLDER
));
1777 strcpyW(package
->folders
[index
].Directory
,dir
);
1782 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1784 if (rc
!= ERROR_SUCCESS
)
1787 rc
= MSI_ViewExecute(view
, 0);
1788 if (rc
!= ERROR_SUCCESS
)
1790 MSI_ViewClose(view
);
1791 msiobj_release(&view
->hdr
);
1795 rc
= MSI_ViewFetch(view
,&row
);
1796 if (rc
!= ERROR_SUCCESS
)
1798 MSI_ViewClose(view
);
1799 msiobj_release(&view
->hdr
);
1804 MSI_RecordGetStringW(row
,3,targetbuffer
,&sz
);
1805 targetdir
=targetbuffer
;
1807 /* split src and target dir */
1808 if (strchrW(targetdir
,':'))
1810 srcdir
=strchrW(targetdir
,':');
1817 /* for now only pick long filename versions */
1818 if (strchrW(targetdir
,'|'))
1820 targetdir
= strchrW(targetdir
,'|');
1824 if (srcdir
&& strchrW(srcdir
,'|'))
1826 srcdir
= strchrW(srcdir
,'|');
1831 /* now check for root dirs */
1832 if (targetdir
[0] == '.' && targetdir
[1] == 0)
1835 if (srcdir
&& srcdir
[0] == '.' && srcdir
[1] == 0)
1839 strcpyW(package
->folders
[index
].TargetDefault
,targetdir
);
1842 strcpyW(package
->folders
[index
].SourceDefault
,srcdir
);
1844 strcpyW(package
->folders
[index
].SourceDefault
,targetdir
);
1846 if (MSI_RecordIsNull(row
,2))
1851 MSI_RecordGetStringW(row
,2,parent
,&sz
);
1856 i
= load_folder(package
,parent
);
1857 package
->folders
[index
].ParentIndex
= i
;
1858 TRACE("Parent is index %i... %s %s\n",
1859 package
->folders
[index
].ParentIndex
,
1860 debugstr_w(package
->folders
[package
->folders
[index
].ParentIndex
].Directory
),
1861 debugstr_w(parent
));
1864 package
->folders
[index
].ParentIndex
= -2;
1867 rc
= MSI_GetPropertyW(package
, dir
, package
->folders
[index
].Property
, &sz
);
1868 if (rc
!= ERROR_SUCCESS
)
1869 package
->folders
[index
].Property
[0]=0;
1871 msiobj_release(&row
->hdr
);
1872 MSI_ViewClose(view
);
1873 msiobj_release(&view
->hdr
);
1874 TRACE(" %s retuning on index %i\n",debugstr_w(dir
),index
);
1878 static UINT
resolve_folder(MSIPACKAGE
*package
, LPCWSTR name
, LPWSTR path
,
1879 BOOL source
, BOOL set_prop
, MSIFOLDER
**folder
)
1882 UINT rc
= ERROR_SUCCESS
;
1885 TRACE("Working to resolve %s\n",debugstr_w(name
));
1890 /* special resolving for Target and Source root dir */
1891 if (strcmpW(name
,cszTargetDir
)==0 || strcmpW(name
,cszSourceDir
)==0)
1896 rc
= MSI_GetPropertyW(package
,cszTargetDir
,path
,&sz
);
1897 if (rc
!= ERROR_SUCCESS
)
1900 rc
= MSI_GetPropertyW(package
,cszRootDrive
,path
,&sz
);
1902 MSI_SetPropertyW(package
,cszTargetDir
,path
);
1905 *folder
= &(package
->folders
[0]);
1911 rc
= MSI_GetPropertyW(package
,cszSourceDir
,path
,&sz
);
1912 if (rc
!= ERROR_SUCCESS
)
1915 rc
= MSI_GetPropertyW(package
,cszDatabase
,path
,&sz
);
1916 if (rc
== ERROR_SUCCESS
)
1918 LPWSTR ptr
= strrchrW(path
,'\\');
1927 *folder
= &(package
->folders
[0]);
1932 for (i
= 0; i
< package
->loaded_folders
; i
++)
1934 if (strcmpW(package
->folders
[i
].Directory
,name
)==0)
1938 if (i
>= package
->loaded_folders
)
1939 return ERROR_FUNCTION_FAILED
;
1942 *folder
= &(package
->folders
[i
]);
1944 if (!source
&& package
->folders
[i
].ResolvedTarget
[0])
1946 strcpyW(path
,package
->folders
[i
].ResolvedTarget
);
1947 TRACE(" already resolved to %s\n",debugstr_w(path
));
1948 return ERROR_SUCCESS
;
1950 else if (source
&& package
->folders
[i
].ResolvedSource
[0])
1952 strcpyW(path
,package
->folders
[i
].ResolvedSource
);
1953 return ERROR_SUCCESS
;
1955 else if (!source
&& package
->folders
[i
].Property
[0])
1957 strcpyW(path
,package
->folders
[i
].Property
);
1958 TRACE(" internally set to %s\n",debugstr_w(path
));
1960 MSI_SetPropertyW(package
,name
,path
);
1961 return ERROR_SUCCESS
;
1964 if (package
->folders
[i
].ParentIndex
>= 0)
1966 TRACE(" ! Parent is %s\n", debugstr_w(package
->folders
[
1967 package
->folders
[i
].ParentIndex
].Directory
));
1968 resolve_folder(package
, package
->folders
[
1969 package
->folders
[i
].ParentIndex
].Directory
, path
,source
,
1974 if (package
->folders
[i
].TargetDefault
[0])
1976 strcatW(path
,package
->folders
[i
].TargetDefault
);
1977 strcatW(path
,cszbs
);
1979 strcpyW(package
->folders
[i
].ResolvedTarget
,path
);
1980 TRACE(" resolved into %s\n",debugstr_w(path
));
1982 MSI_SetPropertyW(package
,name
,path
);
1986 if (package
->folders
[i
].SourceDefault
[0])
1988 strcatW(path
,package
->folders
[i
].SourceDefault
);
1989 strcatW(path
,cszbs
);
1991 strcpyW(package
->folders
[i
].ResolvedSource
,path
);
1998 * Alot is done in this function aside from just the costing.
1999 * The costing needs to be implemented at some point but for now I am going
2000 * to focus on the directory building
2003 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
)
2005 static const WCHAR ExecSeqQuery
[] = {
2006 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2007 'D','i','r','e','c','t','o','r','y',0};
2008 static const WCHAR ConditionQuery
[] = {
2009 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2010 'C','o','n','d','i','t','i','o','n',0};
2011 static const WCHAR szCosting
[] = {
2012 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2013 static const WCHAR szOne
[] = { '1', 0 };
2018 TRACE("Building Directory properties\n");
2020 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2021 if (rc
== ERROR_SUCCESS
)
2023 rc
= MSI_ViewExecute(view
, 0);
2024 if (rc
!= ERROR_SUCCESS
)
2026 MSI_ViewClose(view
);
2027 msiobj_release(&view
->hdr
);
2034 WCHAR path
[MAX_PATH
];
2035 MSIRECORD
* row
= 0;
2038 rc
= MSI_ViewFetch(view
,&row
);
2039 if (rc
!= ERROR_SUCCESS
)
2046 MSI_RecordGetStringW(row
,1,name
,&sz
);
2048 /* This helper function now does ALL the work */
2049 TRACE("Dir %s ...\n",debugstr_w(name
));
2050 load_folder(package
,name
);
2051 resolve_folder(package
,name
,path
,FALSE
,TRUE
,NULL
);
2052 TRACE("resolves to %s\n",debugstr_w(path
));
2054 msiobj_release(&row
->hdr
);
2056 MSI_ViewClose(view
);
2057 msiobj_release(&view
->hdr
);
2060 TRACE("File calculations %i files\n",package
->loaded_files
);
2062 for (i
= 0; i
< package
->loaded_files
; i
++)
2064 MSICOMPONENT
* comp
= NULL
;
2065 MSIFILE
* file
= NULL
;
2067 file
= &package
->files
[i
];
2068 if (file
->ComponentIndex
>= 0)
2069 comp
= &package
->components
[file
->ComponentIndex
];
2073 /* calculate target */
2074 resolve_folder(package
, comp
->Directory
, file
->TargetPath
, FALSE
,
2076 strcatW(file
->TargetPath
,file
->FileName
);
2078 TRACE("file %s resolves to %s\n",
2079 debugstr_w(file
->File
),debugstr_w(file
->TargetPath
));
2081 if (GetFileAttributesW(file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
2084 comp
->Cost
+= file
->FileSize
;
2088 if (file
->Version
[0])
2094 WCHAR filever
[0x100];
2095 static const WCHAR name
[] =
2096 {'\\','V','a','r','F','i','l','e','I','n','f','o',
2097 '\\','F','i','l','e','V','e','r','s','i','o','n',0};
2099 FIXME("Version comparison.. Untried Untested and most "
2100 "likely very very wrong\n");
2101 versize
= GetFileVersionInfoSizeW(file
->TargetPath
,&handle
);
2102 version
= HeapAlloc(GetProcessHeap(),0,versize
);
2103 GetFileVersionInfoW(file
->TargetPath
, 0, versize
, version
);
2105 VerQueryValueW(version
,name
,(LPVOID
)filever
,&sz
);
2106 HeapFree(GetProcessHeap(),0,version
);
2108 if (strcmpW(version
,file
->Version
)<0)
2111 FIXME("cost should be diff in size\n");
2112 comp
->Cost
+= file
->FileSize
;
2123 TRACE("Evaluating Condition Table\n");
2125 rc
= MSI_DatabaseOpenViewW(package
->db
, ConditionQuery
, &view
);
2126 if (rc
== ERROR_SUCCESS
)
2128 rc
= MSI_ViewExecute(view
, 0);
2129 if (rc
!= ERROR_SUCCESS
)
2131 MSI_ViewClose(view
);
2132 msiobj_release(&view
->hdr
);
2138 WCHAR Feature
[0x100];
2139 MSIRECORD
* row
= 0;
2143 rc
= MSI_ViewFetch(view
,&row
);
2145 if (rc
!= ERROR_SUCCESS
)
2152 MSI_RecordGetStringW(row
,1,Feature
,&sz
);
2154 feature_index
= get_loaded_feature(package
,Feature
);
2155 if (feature_index
< 0)
2156 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature
));
2160 Condition
= load_dynamic_stringW(row
,3);
2162 if (MSI_EvaluateConditionW(package
,Condition
) ==
2165 int level
= MSI_RecordGetInteger(row
,2);
2166 TRACE("Reseting feature %s to level %i\n",
2167 debugstr_w(Feature
), level
);
2168 package
->features
[feature_index
].Level
= level
;
2170 HeapFree(GetProcessHeap(),0,Condition
);
2173 msiobj_release(&row
->hdr
);
2175 MSI_ViewClose(view
);
2176 msiobj_release(&view
->hdr
);
2179 TRACE("Enabling or Disabling Components\n");
2180 for (i
= 0; i
< package
->loaded_components
; i
++)
2182 if (package
->components
[i
].Condition
[0])
2184 if (MSI_EvaluateConditionW(package
,
2185 package
->components
[i
].Condition
) == MSICONDITION_FALSE
)
2187 TRACE("Disabling component %s\n",
2188 debugstr_w(package
->components
[i
].Component
));
2189 package
->components
[i
].Enabled
= FALSE
;
2194 MSI_SetPropertyW(package
,szCosting
,szOne
);
2195 return ERROR_SUCCESS
;
2199 * This is a helper function for handling embedded cabinet media
2201 static UINT
writeout_cabinet_stream(MSIPACKAGE
*package
, WCHAR
* stream_name
,
2209 WCHAR tmp
[MAX_PATH
];
2211 rc
= read_raw_stream_data(package
->db
,stream_name
,&data
,&size
);
2212 if (rc
!= ERROR_SUCCESS
)
2216 if (MSI_GetPropertyW(package
, cszTempFolder
, tmp
, &write
))
2217 GetTempPathW(MAX_PATH
,tmp
);
2219 GetTempFileNameW(tmp
,stream_name
,0,source
);
2221 track_tempfile(package
,strrchrW(source
,'\\'), source
);
2222 the_file
= CreateFileW(source
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2223 FILE_ATTRIBUTE_NORMAL
, NULL
);
2225 if (the_file
== INVALID_HANDLE_VALUE
)
2227 rc
= ERROR_FUNCTION_FAILED
;
2231 WriteFile(the_file
,data
,size
,&write
,NULL
);
2232 CloseHandle(the_file
);
2233 TRACE("wrote %li bytes to %s\n",write
,debugstr_w(source
));
2235 HeapFree(GetProcessHeap(),0,data
);
2240 /***********************************************************************
2241 * extract_cabinet_file
2243 * Extract files from a cab file.
2245 static void (WINAPI
*pExtractFiles
)( LPSTR
, LPSTR
, DWORD
, DWORD
, DWORD
, DWORD
);
2247 static BOOL
extract_cabinet_file_advpack( const WCHAR
*cabinet
,
2250 static HMODULE advpack
;
2252 char *cab_path
, *cab_file
;
2256 if (!advpack
&& !(advpack
= LoadLibraryA( "advpack.dll" )))
2258 ERR( "could not load advpack.dll\n" );
2261 if (!(pExtractFiles
= (void *)GetProcAddress( advpack
, "ExtractFiles"
2264 ERR( "could not find ExtractFiles in advpack.dll\n" );
2269 if (!(cab_file
= strdupWtoA( cabinet
))) return FALSE
;
2270 if (!(cab_path
= strdupWtoA( root
))) return FALSE
;
2272 FIXME( "awful hack: extracting cabinet %s\n", debugstr_a(cab_file
) );
2273 pExtractFiles( cab_file
, cab_path
, 0, 0, 0, 0 );
2274 HeapFree( GetProcessHeap(), 0, cab_file
);
2275 HeapFree( GetProcessHeap(), 0, cab_path
);
2279 static BOOL
extract_cabinet_file_cabinet( const WCHAR
*cabinet
,
2283 /* from cabinet.h */
2285 struct ExtractFileList
{
2287 struct ExtractFileList
*next
;
2288 BOOL unknown
; /* always 1L */
2292 long result1
; /* 0x000 */
2293 long unknown1
[3]; /* 0x004 */
2294 struct ExtractFileList
* filelist
; /* 0x010 */
2295 long filecount
; /* 0x014 */
2296 long unknown2
; /* 0x018 */
2297 char directory
[0x104]; /* 0x01c */
2298 char lastfile
[0x20c]; /* 0x120 */
2301 HRESULT WINAPI
Extract(EXTRACTdest
*dest
, LPCSTR what
);
2303 char *cab_path
, *src_path
;
2305 struct ExtractFileList fl
;
2307 if (!(cab_path
= strdupWtoA( cabinet
))) return FALSE
;
2308 if (!(src_path
= strdupWtoA( root
))) return FALSE
;
2310 memset(&exd
,0,sizeof(exd
));
2311 strcpy(exd
.directory
,src_path
);
2313 fl
.filename
= cab_path
;
2317 FIXME( "more aweful hack: extracting cabinet %s\n", debugstr_a(cab_path
) );
2318 Extract(&exd
,cab_path
);
2320 HeapFree( GetProcessHeap(), 0, cab_path
);
2321 HeapFree( GetProcessHeap(), 0, src_path
);
2325 static BOOL
extract_cabinet_file(const WCHAR
* source
, const WCHAR
* path
)
2327 TRACE("Extracting %s to %s\n",debugstr_w(source
), debugstr_w(path
));
2328 if (!extract_cabinet_file_advpack(source
,path
))
2329 return extract_cabinet_file_cabinet(source
,path
);
2333 static UINT
ready_media_for_file(MSIPACKAGE
*package
, UINT sequence
,
2338 MSIRECORD
* row
= 0;
2339 WCHAR source
[MAX_PATH
];
2340 static const WCHAR ExecSeqQuery
[] = {
2341 's','e','l','e','c','t',' ','*',' ',
2342 'f','r','o','m',' ','M','e','d','i','a',' ',
2343 'w','h','e','r','e',' ','L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%','i',' ',
2344 'o','r','d','e','r',' ','b','y',' ','L','a','s','t','S','e','q','u','e','n','c','e',0};
2349 static UINT last_sequence
= 0;
2351 if (sequence
<= last_sequence
)
2353 TRACE("Media already ready (%u, %u)\n",sequence
,last_sequence
);
2354 return ERROR_SUCCESS
;
2357 sprintfW(Query
,ExecSeqQuery
,sequence
);
2359 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2360 if (rc
!= ERROR_SUCCESS
)
2363 rc
= MSI_ViewExecute(view
, 0);
2364 if (rc
!= ERROR_SUCCESS
)
2366 MSI_ViewClose(view
);
2367 msiobj_release(&view
->hdr
);
2371 rc
= MSI_ViewFetch(view
,&row
);
2372 if (rc
!= ERROR_SUCCESS
)
2374 MSI_ViewClose(view
);
2375 msiobj_release(&view
->hdr
);
2378 seq
= MSI_RecordGetInteger(row
,2);
2379 last_sequence
= seq
;
2381 if (!MSI_RecordIsNull(row
,4))
2384 MSI_RecordGetStringW(row
,4,cab
,&sz
);
2385 TRACE("Source is CAB %s\n",debugstr_w(cab
));
2386 /* the stream does not contain the # character */
2389 writeout_cabinet_stream(package
,&cab
[1],source
);
2390 strcpyW(path
,source
);
2391 *(strrchrW(path
,'\\')+1)=0;
2396 if (MSI_GetPropertyW(package
, cszSourceDir
, source
, &sz
))
2398 ERR("No Source dir defined \n");
2399 rc
= ERROR_FUNCTION_FAILED
;
2403 strcpyW(path
,source
);
2404 strcatW(source
,cab
);
2405 /* extract the cab file into a folder in the temp folder */
2407 if (MSI_GetPropertyW(package
, cszTempFolder
,path
, &sz
)
2409 GetTempPathW(MAX_PATH
,path
);
2412 rc
= !extract_cabinet_file(source
,path
);
2414 msiobj_release(&row
->hdr
);
2415 MSI_ViewClose(view
);
2416 msiobj_release(&view
->hdr
);
2420 inline static UINT
create_component_directory ( MSIPACKAGE
* package
, INT component
)
2424 WCHAR install_path
[MAX_PATH
];
2426 rc
= resolve_folder(package
, package
->components
[component
].Directory
,
2427 install_path
, FALSE
, FALSE
, &folder
);
2429 if (rc
!= ERROR_SUCCESS
)
2432 /* create the path */
2433 if (folder
->State
== 0)
2435 create_full_pathW(install_path
);
2442 static UINT
ACTION_InstallFiles(MSIPACKAGE
*package
)
2444 UINT rc
= ERROR_SUCCESS
;
2447 WCHAR uipath
[MAX_PATH
];
2450 return ERROR_INVALID_HANDLE
;
2452 /* increment progress bar each time action data is sent */
2453 ui_progress(package
,1,1,1,0);
2455 for (index
= 0; index
< package
->loaded_files
; index
++)
2457 WCHAR path_to_source
[MAX_PATH
];
2460 file
= &package
->files
[index
];
2462 if (file
->Temporary
)
2465 if (!package
->components
[file
->ComponentIndex
].Enabled
||
2466 !package
->components
[file
->ComponentIndex
].FeatureState
)
2468 TRACE("File %s is not scheduled for install\n",
2469 debugstr_w(file
->File
));
2473 if ((file
->State
== 1) || (file
->State
== 2))
2475 TRACE("Installing %s\n",debugstr_w(file
->File
));
2476 rc
= ready_media_for_file(package
,file
->Sequence
,path_to_source
);
2479 * our file table could change here because a new temp file
2480 * may have been created
2482 file
= &package
->files
[index
];
2483 if (rc
!= ERROR_SUCCESS
)
2485 ERR("Unable to ready media\n");
2486 rc
= ERROR_FUNCTION_FAILED
;
2490 create_component_directory( package
, file
->ComponentIndex
);
2492 strcpyW(file
->SourcePath
, path_to_source
);
2493 strcatW(file
->SourcePath
, file
->File
);
2495 TRACE("file paths %s to %s\n",debugstr_w(file
->SourcePath
),
2496 debugstr_w(file
->TargetPath
));
2499 uirow
=MSI_CreateRecord(9);
2500 MSI_RecordSetStringW(uirow
,1,file
->File
);
2501 strcpyW(uipath
,file
->TargetPath
);
2502 *(strrchrW(uipath
,'\\')+1)=0;
2503 MSI_RecordSetStringW(uirow
,9,uipath
);
2504 MSI_RecordSetInteger(uirow
,6,file
->FileSize
);
2505 ui_actiondata(package
,szInstallFiles
,uirow
);
2506 msiobj_release( &uirow
->hdr
);
2508 rc
= !MoveFileW(file
->SourcePath
,file
->TargetPath
);
2509 ui_progress(package
,2,0,0,0);
2513 ERR("Unable to move file (error %li)\n",GetLastError());
2524 inline static UINT
get_file_target(MSIPACKAGE
*package
, LPCWSTR file_key
,
2530 return ERROR_INVALID_HANDLE
;
2532 for (index
= 0; index
< package
->loaded_files
; index
++)
2534 if (strcmpW(file_key
,package
->files
[index
].File
)==0)
2536 if (package
->files
[index
].State
>= 3)
2538 strcpyW(file_source
,package
->files
[index
].TargetPath
);
2539 return ERROR_SUCCESS
;
2542 return ERROR_FILE_NOT_FOUND
;
2546 return ERROR_FUNCTION_FAILED
;
2549 static UINT
ACTION_DuplicateFiles(MSIPACKAGE
*package
)
2553 MSIRECORD
* row
= 0;
2554 static const WCHAR ExecSeqQuery
[] = {
2555 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2556 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
2559 return ERROR_INVALID_HANDLE
;
2561 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2562 if (rc
!= ERROR_SUCCESS
)
2563 return ERROR_SUCCESS
;
2565 rc
= MSI_ViewExecute(view
, 0);
2566 if (rc
!= ERROR_SUCCESS
)
2568 MSI_ViewClose(view
);
2569 msiobj_release(&view
->hdr
);
2575 WCHAR file_key
[0x100];
2576 WCHAR file_source
[MAX_PATH
];
2577 WCHAR dest_name
[0x100];
2578 WCHAR dest_path
[MAX_PATH
];
2579 WCHAR component
[0x100];
2580 INT component_index
;
2584 rc
= MSI_ViewFetch(view
,&row
);
2585 if (rc
!= ERROR_SUCCESS
)
2592 rc
= MSI_RecordGetStringW(row
,2,component
,&sz
);
2593 if (rc
!= ERROR_SUCCESS
)
2595 ERR("Unable to get component\n");
2596 msiobj_release(&row
->hdr
);
2600 component_index
= get_loaded_component(package
,component
);
2601 if (!package
->components
[component_index
].Enabled
||
2602 !package
->components
[component_index
].FeatureState
)
2604 TRACE("Skipping copy due to disabled component\n");
2605 msiobj_release(&row
->hdr
);
2610 rc
= MSI_RecordGetStringW(row
,3,file_key
,&sz
);
2611 if (rc
!= ERROR_SUCCESS
)
2613 ERR("Unable to get file key\n");
2614 msiobj_release(&row
->hdr
);
2618 rc
= get_file_target(package
,file_key
,file_source
);
2620 if (rc
!= ERROR_SUCCESS
)
2622 ERR("Original file unknown %s\n",debugstr_w(file_key
));
2623 msiobj_release(&row
->hdr
);
2627 if (MSI_RecordIsNull(row
,4))
2629 strcpyW(dest_name
,strrchrW(file_source
,'\\')+1);
2634 MSI_RecordGetStringW(row
,4,dest_name
,&sz
);
2635 reduce_to_longfilename(dest_name
);
2638 if (MSI_RecordIsNull(row
,5))
2640 strcpyW(dest_path
,file_source
);
2641 *strrchrW(dest_path
,'\\')=0;
2645 WCHAR destkey
[0x100];
2647 MSI_RecordGetStringW(row
,5,destkey
,&sz
);
2649 rc
= resolve_folder(package
, destkey
, dest_path
,FALSE
,FALSE
,NULL
);
2650 if (rc
!= ERROR_SUCCESS
)
2652 ERR("Unable to get destination folder\n");
2653 msiobj_release(&row
->hdr
);
2658 strcatW(dest_path
,dest_name
);
2660 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source
),
2661 debugstr_w(dest_path
));
2663 if (strcmpW(file_source
,dest_path
))
2664 rc
= !CopyFileW(file_source
,dest_path
,TRUE
);
2668 if (rc
!= ERROR_SUCCESS
)
2669 ERR("Failed to copy file\n");
2671 FIXME("We should track these duplicate files as well\n");
2673 msiobj_release(&row
->hdr
);
2675 MSI_ViewClose(view
);
2676 msiobj_release(&view
->hdr
);
2682 /* OK this value is "interpretted" and then formatted based on the
2683 first few characters */
2684 static LPSTR
parse_value(MSIPACKAGE
*package
, WCHAR
*value
, DWORD
*type
,
2688 if (value
[0]=='#' && value
[1]!='#' && value
[1]!='%')
2697 deformat_string(package
, &value
[2], &deformated
);
2699 /* binary value type */
2702 *size
= strlenW(ptr
)/2;
2703 data
= HeapAlloc(GetProcessHeap(),0,*size
);
2715 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
2718 HeapFree(GetProcessHeap(),0,deformated
);
2720 TRACE("Data %li bytes(%i)\n",*size
,count
);
2725 deformat_string(package
, &value
[1], &deformated
);
2728 *size
= sizeof(DWORD
);
2729 data
= HeapAlloc(GetProcessHeap(),0,*size
);
2730 *(LPDWORD
)data
= atoiW(deformated
);
2731 TRACE("DWORD %i\n",*data
);
2733 HeapFree(GetProcessHeap(),0,deformated
);
2746 *type
=REG_EXPAND_SZ
;
2754 *size
= deformat_string(package
, ptr
,(LPWSTR
*)&data
);
2759 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
)
2763 MSIRECORD
* row
= 0;
2764 static const WCHAR ExecSeqQuery
[] = {
2765 's','e','l','e','c','t',' ','*',' ',
2766 'f','r','o','m',' ','R','e','g','i','s','t','r','y',0 };
2769 return ERROR_INVALID_HANDLE
;
2771 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2772 if (rc
!= ERROR_SUCCESS
)
2773 return ERROR_SUCCESS
;
2775 rc
= MSI_ViewExecute(view
, 0);
2776 if (rc
!= ERROR_SUCCESS
)
2778 MSI_ViewClose(view
);
2779 msiobj_release(&view
->hdr
);
2783 /* increment progress bar each time action data is sent */
2784 ui_progress(package
,1,1,1,0);
2788 static const WCHAR szHCR
[] =
2789 {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T','\\',0};
2790 static const WCHAR szHCU
[] =
2791 {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',0};
2792 static const WCHAR szHLM
[] =
2793 {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',
2795 static const WCHAR szHU
[] =
2796 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
2801 LPSTR value_data
= NULL
;
2802 HKEY root_key
, hkey
;
2804 WCHAR component
[0x100];
2805 INT component_index
;
2812 rc
= MSI_ViewFetch(view
,&row
);
2813 if (rc
!= ERROR_SUCCESS
)
2820 MSI_RecordGetStringW(row
,6,component
,&sz
);
2821 component_index
= get_loaded_component(package
,component
);
2823 if (!package
->components
[component_index
].Enabled
||
2824 !package
->components
[component_index
].FeatureState
)
2826 TRACE("Skipping write due to disabled component\n");
2827 msiobj_release(&row
->hdr
);
2831 /* null values have special meanings during uninstalls and such */
2833 if(MSI_RecordIsNull(row
,5))
2835 msiobj_release(&row
->hdr
);
2839 root
= MSI_RecordGetInteger(row
,2);
2841 MSI_RecordGetStringW(row
,3,key
,&sz
);
2844 if (MSI_RecordIsNull(row
,4))
2847 MSI_RecordGetStringW(row
,4,name
,&sz
);
2849 /* get the root key */
2852 case 0: root_key
= HKEY_CLASSES_ROOT
;
2853 strcpyW(uikey
,szHCR
); break;
2854 case 1: root_key
= HKEY_CURRENT_USER
;
2855 strcpyW(uikey
,szHCU
); break;
2856 case 2: root_key
= HKEY_LOCAL_MACHINE
;
2857 strcpyW(uikey
,szHLM
); break;
2858 case 3: root_key
= HKEY_USERS
;
2859 strcpyW(uikey
,szHU
); break;
2861 ERR("Unknown root %i\n",root
);
2867 msiobj_release(&row
->hdr
);
2872 if (RegCreateKeyW( root_key
, key
, &hkey
))
2874 ERR("Could not create key %s\n",debugstr_w(key
));
2875 msiobj_release(&row
->hdr
);
2879 value
= load_dynamic_stringW(row
,5);
2880 value_data
= parse_value(package
, value
, &type
, &size
);
2884 TRACE("Setting value %s\n",debugstr_w(name
));
2885 RegSetValueExW(hkey
, name
, 0, type
, value_data
, size
);
2887 uirow
= MSI_CreateRecord(3);
2888 MSI_RecordSetStringW(uirow
,2,name
);
2889 MSI_RecordSetStringW(uirow
,1,uikey
);
2892 MSI_RecordSetStringW(uirow
,3,(LPWSTR
)value_data
);
2894 MSI_RecordSetStringW(uirow
,3,value
);
2896 ui_actiondata(package
,szWriteRegistryValues
,uirow
);
2897 ui_progress(package
,2,0,0,0);
2898 msiobj_release( &uirow
->hdr
);
2900 HeapFree(GetProcessHeap(),0,value_data
);
2902 HeapFree(GetProcessHeap(),0,value
);
2904 msiobj_release(&row
->hdr
);
2907 MSI_ViewClose(view
);
2908 msiobj_release(&view
->hdr
);
2913 * This helper function should probably go alot of places
2915 * Thinking about this, maybe this should become yet another Bison file
2917 static DWORD
deformat_string(MSIPACKAGE
*package
, WCHAR
* ptr
,WCHAR
** data
)
2927 /* scan for special characters */
2928 if (!strchrW(ptr
,'[') || (strchrW(ptr
,'[') && !strchrW(ptr
,']')))
2931 size
= (strlenW(ptr
)+1) * sizeof(WCHAR
);
2932 *data
= HeapAlloc(GetProcessHeap(),0,size
);
2937 /* formatted string located */
2938 mark
= strchrW(ptr
,'[');
2941 INT cnt
= (mark
- ptr
);
2942 TRACE("%i (%i) characters before marker\n",cnt
,(mark
-ptr
));
2943 size
= cnt
* sizeof(WCHAR
);
2944 size
+= sizeof(WCHAR
);
2945 *data
= HeapAlloc(GetProcessHeap(),0,size
);
2946 strncpyW(*data
,ptr
,cnt
);
2951 size
= sizeof(WCHAR
);
2952 *data
= HeapAlloc(GetProcessHeap(),0,size
);
2957 *strchrW(key
,']')=0;
2958 mark
= strchrW(mark
,']');
2960 TRACE("Current %s .. %s\n",debugstr_w(*data
),debugstr_w(mark
));
2962 rc
= MSI_GetPropertyW(package
, key
, NULL
, &sz
);
2963 if ((rc
== ERROR_SUCCESS
) || (rc
== ERROR_MORE_DATA
))
2968 value
= HeapAlloc(GetProcessHeap(),0,sz
* sizeof(WCHAR
));
2969 MSI_GetPropertyW(package
, key
, value
, &sz
);
2971 chunk
= (strlenW(value
)+1) * sizeof(WCHAR
);
2973 newdata
= HeapReAlloc(GetProcessHeap(),0,*data
,size
);
2975 strcatW(*data
,value
);
2977 TRACE("Current %s .. %s\n",debugstr_w(*data
),debugstr_w(mark
));
2981 chunk
= (strlenW(mark
)+1) * sizeof(WCHAR
);
2983 newdata
= HeapReAlloc(GetProcessHeap(),0,*data
,size
);
2985 strcatW(*data
,mark
);
2987 (*data
)[strlenW(*data
)]=0;
2988 TRACE("Current %s .. %s\n",debugstr_w(*data
),debugstr_w(mark
));
2990 /* recursively do this to clean up */
2991 mark
= HeapAlloc(GetProcessHeap(),0,size
);
2992 strcpyW(mark
,*data
);
2993 TRACE("String at this point %s\n",debugstr_w(mark
));
2994 size
= deformat_string(package
,mark
,data
);
2995 HeapFree(GetProcessHeap(),0,mark
);
2999 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
)
3007 LPWSTR override
= NULL
;
3008 static const WCHAR addlocal
[]={'A','D','D','L','O','C','A','L',0};
3009 static const WCHAR all
[]={'A','L','L',0};
3010 static const WCHAR szlevel
[] = {
3011 'I','N','S','T','A','L','L','L','E','V','E','L',0};
3012 static const WCHAR szAddLocal
[] = {
3013 'A','D','D','L','O','C','A','L',0};
3015 /* I do not know if this is where it should happen.. but */
3017 TRACE("Checking Install Level\n");
3020 if (MSI_GetPropertyW(package
,szlevel
,level
,&sz
)==ERROR_SUCCESS
)
3021 install_level
= atoiW(level
);
3026 rc
= MSI_GetPropertyW(package
,szAddLocal
,NULL
,&sz
);
3027 if (rc
== ERROR_SUCCESS
|| rc
== ERROR_MORE_DATA
)
3030 override
= HeapAlloc(GetProcessHeap(),0,sz
*sizeof(WCHAR
));
3031 MSI_GetPropertyW(package
, addlocal
,override
,&sz
);
3035 * Components FeatureState defaults to FALSE. The idea is we want to
3036 * enable the component is ANY feature that uses it is enabled to install
3038 for(i
= 0; i
< package
->loaded_features
; i
++)
3040 BOOL feature_state
= ((package
->features
[i
].Level
> 0) &&
3041 (package
->features
[i
].Level
<= install_level
));
3043 if (override
&& (strcmpiW(override
,all
)==0 ||
3044 strstrW(override
,package
->features
[i
].Feature
)))
3046 TRACE("Override of install level found\n");
3047 feature_state
= TRUE
;
3048 package
->features
[i
].Enabled
= feature_state
;
3051 TRACE("Feature %s has a state of %i\n",
3052 debugstr_w(package
->features
[i
].Feature
), feature_state
);
3053 for( j
= 0; j
< package
->features
[i
].ComponentCount
; j
++)
3055 package
->components
[package
->features
[i
].Components
[j
]].FeatureState
3059 if (override
!= NULL
)
3060 HeapFree(GetProcessHeap(),0,override
);
3062 * So basically we ONLY want to install a component if its Enabled AND
3063 * FeatureState are both TRUE
3065 return ERROR_SUCCESS
;
3068 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
)
3071 static const WCHAR q1
[]={
3072 'S','E','L','E','C','T',' ','*',' ',
3073 'F','R','O','M',' ','R','e','g','i','s','t','r','y',0};
3076 MSIRECORD
* row
= 0;
3078 TRACE(" InstallValidate \n");
3080 rc
= MSI_DatabaseOpenViewW(package
->db
, q1
, &view
);
3081 if (rc
!= ERROR_SUCCESS
)
3082 return ERROR_SUCCESS
;
3084 rc
= MSI_ViewExecute(view
, 0);
3085 if (rc
!= ERROR_SUCCESS
)
3087 MSI_ViewClose(view
);
3088 msiobj_release(&view
->hdr
);
3093 rc
= MSI_ViewFetch(view
,&row
);
3094 if (rc
!= ERROR_SUCCESS
)
3101 msiobj_release(&row
->hdr
);
3103 MSI_ViewClose(view
);
3104 msiobj_release(&view
->hdr
);
3106 ui_progress(package
,0,progress
+package
->loaded_files
,0,0);
3108 return ERROR_SUCCESS
;
3111 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
)
3114 MSIQUERY
* view
= NULL
;
3115 MSIRECORD
* row
= 0;
3116 static const WCHAR ExecSeqQuery
[] = {
3117 'S','E','L','E','C','T',' ','*',' ',
3118 'f','r','o','m',' ','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3119 static const WCHAR title
[]=
3120 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3122 TRACE("Checking launch conditions\n");
3124 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3125 if (rc
!= ERROR_SUCCESS
)
3126 return ERROR_SUCCESS
;
3128 rc
= MSI_ViewExecute(view
, 0);
3129 if (rc
!= ERROR_SUCCESS
)
3131 MSI_ViewClose(view
);
3132 msiobj_release(&view
->hdr
);
3137 while (rc
== ERROR_SUCCESS
)
3140 LPWSTR message
= NULL
;
3142 rc
= MSI_ViewFetch(view
,&row
);
3143 if (rc
!= ERROR_SUCCESS
)
3149 cond
= load_dynamic_stringW(row
,1);
3151 if (MSI_EvaluateConditionW(package
,cond
) != MSICONDITION_TRUE
)
3153 message
= load_dynamic_stringW(row
,2);
3154 MessageBoxW(NULL
,message
,title
,MB_OK
);
3155 HeapFree(GetProcessHeap(),0,message
);
3156 rc
= ERROR_FUNCTION_FAILED
;
3158 HeapFree(GetProcessHeap(),0,cond
);
3159 msiobj_release(&row
->hdr
);
3161 MSI_ViewClose(view
);
3162 msiobj_release(&view
->hdr
);
3166 static void resolve_keypath( MSIPACKAGE
* package
, INT
3167 component_index
, WCHAR
*keypath
)
3169 MSICOMPONENT
* cmp
= &package
->components
[component_index
];
3171 if (cmp
->KeyPath
[0]==0)
3173 resolve_folder(package
,cmp
->Directory
,keypath
,FALSE
,FALSE
,NULL
);
3176 if ((cmp
->Attributes
& 0x4) || (cmp
->Attributes
& 0x20))
3178 FIXME("UNIMPLEMENTED keypath as Registry or ODBC Source\n");
3184 j
= get_loaded_file(package
,cmp
->KeyPath
);
3187 strcpyW(keypath
,package
->files
[j
].TargetPath
);
3192 * Ok further analysis makes me think that this work is
3193 * actually done in the PublishComponents and PublishFeatures
3194 * step, and not here. It appears like the keypath and all that is
3195 * resolved in this step, however actually written in the Publish steps.
3196 * But we will leave it here for now because it is unclear
3198 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
)
3200 WCHAR productcode
[0x100];
3201 WCHAR squished_pc
[0x100];
3202 WCHAR squished_cc
[0x100];
3206 HKEY hkey
=0,hkey2
=0,hkey3
=0;
3207 static const WCHAR szProductCode
[]=
3208 {'P','r','o','d','u','c','t','C','o','d','e',0};
3209 static const WCHAR szInstaller
[] = {
3210 'S','o','f','t','w','a','r','e','\\',
3211 'M','i','c','r','o','s','o','f','t','\\',
3212 'W','i','n','d','o','w','s','\\',
3213 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3214 'I','n','s','t','a','l','l','e','r',0 };
3215 static const WCHAR szFeatures
[] = {
3216 'F','e','a','t','u','r','e','s',0 };
3217 static const WCHAR szComponents
[] = {
3218 'C','o','m','p','o','n','e','n','t','s',0 };
3221 return ERROR_INVALID_HANDLE
;
3223 /* writes the Component and Features values to the registry */
3225 rc
= MSI_GetPropertyW(package
,szProductCode
,productcode
,&sz
);
3226 if (rc
!= ERROR_SUCCESS
)
3227 return ERROR_SUCCESS
;
3229 squash_guid(productcode
,squished_pc
);
3230 rc
= RegCreateKeyW(HKEY_LOCAL_MACHINE
,szInstaller
,&hkey
);
3231 if (rc
!= ERROR_SUCCESS
)
3234 rc
= RegCreateKeyW(hkey
,szFeatures
,&hkey2
);
3235 if (rc
!= ERROR_SUCCESS
)
3238 rc
= RegCreateKeyW(hkey2
,squished_pc
,&hkey3
);
3239 if (rc
!= ERROR_SUCCESS
)
3242 /* here the guids are base 85 encoded */
3243 for (i
= 0; i
< package
->loaded_features
; i
++)
3250 size
= package
->features
[i
].ComponentCount
*21*sizeof(WCHAR
);
3251 data
= HeapAlloc(GetProcessHeap(), 0, size
);
3254 for (j
= 0; j
< package
->features
[i
].ComponentCount
; j
++)
3257 TRACE("From %s\n",debugstr_w(package
->components
3258 [package
->features
[i
].Components
[j
]].ComponentId
));
3259 CLSIDFromString(package
->components
3260 [package
->features
[i
].Components
[j
]].ComponentId
,
3262 encode_base85_guid(&clsid
,buf
);
3263 TRACE("to %s\n",debugstr_w(buf
));
3267 size
= strlenW(data
)*sizeof(WCHAR
);
3268 RegSetValueExW(hkey3
,package
->features
[i
].Feature
,0,REG_SZ
,
3270 HeapFree(GetProcessHeap(),0,data
);
3276 rc
= RegCreateKeyW(hkey
,szComponents
,&hkey2
);
3277 if (rc
!= ERROR_SUCCESS
)
3280 for (i
= 0; i
< package
->loaded_components
; i
++)
3282 if (package
->components
[i
].ComponentId
[0]!=0)
3284 WCHAR keypath
[0x1000];
3287 squash_guid(package
->components
[i
].ComponentId
,squished_cc
);
3288 rc
= RegCreateKeyW(hkey2
,squished_cc
,&hkey3
);
3289 if (rc
!= ERROR_SUCCESS
)
3292 resolve_keypath(package
,i
,keypath
);
3294 RegSetValueExW(hkey3
,squished_pc
,0,REG_SZ
,(LPVOID
)keypath
,
3295 (strlenW(keypath
)+1)*sizeof(WCHAR
));
3299 uirow
= MSI_CreateRecord(3);
3300 MSI_RecordSetStringW(uirow
,1,productcode
);
3301 MSI_RecordSetStringW(uirow
,2,package
->components
[i
].ComponentId
);
3302 MSI_RecordSetStringW(uirow
,3,keypath
);
3303 ui_actiondata(package
,szProcessComponents
,uirow
);
3304 msiobj_release( &uirow
->hdr
);
3313 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
)
3316 * OK this is a bit confusing.. I am given a _Component key and I believe
3317 * that the file that is being registered as a type library is the "key file
3318 * of that component" which I interpret to mean "The file in the KeyPath of
3323 MSIRECORD
* row
= 0;
3324 static const WCHAR Query
[] = {
3325 'S','E','L','E','C','T',' ','*',' ',
3326 'f','r','o','m',' ','T','y','p','e','L','i','b',0};
3331 return ERROR_INVALID_HANDLE
;
3333 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3334 if (rc
!= ERROR_SUCCESS
)
3335 return ERROR_SUCCESS
;
3337 rc
= MSI_ViewExecute(view
, 0);
3338 if (rc
!= ERROR_SUCCESS
)
3340 MSI_ViewClose(view
);
3341 msiobj_release(&view
->hdr
);
3347 WCHAR component
[0x100];
3351 rc
= MSI_ViewFetch(view
,&row
);
3352 if (rc
!= ERROR_SUCCESS
)
3359 MSI_RecordGetStringW(row
,3,component
,&sz
);
3361 index
= get_loaded_component(package
,component
);
3364 msiobj_release(&row
->hdr
);
3368 if (!package
->components
[index
].Enabled
||
3369 !package
->components
[index
].FeatureState
)
3371 TRACE("Skipping typelib reg due to disabled component\n");
3372 msiobj_release(&row
->hdr
);
3376 index
= get_loaded_file(package
,package
->components
[index
].KeyPath
);
3380 msiobj_release(&row
->hdr
);
3384 res
= LoadTypeLib(package
->files
[index
].TargetPath
,&ptLib
);
3387 WCHAR help
[MAX_PATH
];
3388 WCHAR helpid
[0x100];
3391 MSI_RecordGetStringW(row
,6,helpid
,&sz
);
3393 resolve_folder(package
,helpid
,help
,FALSE
,FALSE
,NULL
);
3395 res
= RegisterTypeLib(ptLib
,package
->files
[index
].TargetPath
,help
);
3396 if (!SUCCEEDED(res
))
3397 ERR("Failed to register type library %s\n",
3398 debugstr_w(package
->files
[index
].TargetPath
));
3401 /* Yes the row has more fields than I need, but #1 is
3402 correct and the only one I need. Why make a new row? */
3404 ui_actiondata(package
,szRegisterTypeLibraries
,row
);
3406 TRACE("Registered %s\n",
3407 debugstr_w(package
->files
[index
].TargetPath
));
3411 ITypeLib_Release(ptLib
);
3414 ERR("Failed to load type library %s\n",
3415 debugstr_w(package
->files
[index
].TargetPath
));
3417 msiobj_release(&row
->hdr
);
3419 MSI_ViewClose(view
);
3420 msiobj_release(&view
->hdr
);
3425 static UINT
register_appid(MSIPACKAGE
*package
, LPCWSTR clsid
, LPCWSTR app
)
3427 static const WCHAR szAppID
[] = { 'A','p','p','I','D',0 };
3430 MSIRECORD
* row
= 0;
3431 static const WCHAR ExecSeqQuery
[] =
3432 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','p','p','I'
3433 ,'d',' ','w','h','e','r','e',' ','A','p','p','I','d','=','`','%','s','`',0};
3434 WCHAR Query
[0x1000];
3439 return ERROR_INVALID_HANDLE
;
3441 sprintfW(Query
,ExecSeqQuery
,clsid
);
3443 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3444 if (rc
!= ERROR_SUCCESS
)
3447 rc
= MSI_ViewExecute(view
, 0);
3448 if (rc
!= ERROR_SUCCESS
)
3450 MSI_ViewClose(view
);
3451 msiobj_release(&view
->hdr
);
3455 RegCreateKeyW(HKEY_CLASSES_ROOT
,szAppID
,&hkey2
);
3456 RegCreateKeyW(hkey2
,clsid
,&hkey3
);
3457 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,(LPVOID
)app
,
3458 (strlenW(app
)+1)*sizeof(WCHAR
));
3460 rc
= MSI_ViewFetch(view
,&row
);
3461 if (rc
!= ERROR_SUCCESS
)
3463 MSI_ViewClose(view
);
3464 msiobj_release(&view
->hdr
);
3468 if (!MSI_RecordIsNull(row
,2))
3470 LPWSTR deformated
=0;
3472 static const WCHAR szRemoteServerName
[] =
3473 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
3474 buffer
= load_dynamic_stringW(row
,2);
3475 size
= deformat_string(package
,buffer
,&deformated
);
3476 RegSetValueExW(hkey3
,szRemoteServerName
,0,REG_SZ
,(LPVOID
)deformated
,
3478 HeapFree(GetProcessHeap(),0,deformated
);
3479 HeapFree(GetProcessHeap(),0,buffer
);
3482 if (!MSI_RecordIsNull(row
,3))
3484 static const WCHAR szLocalService
[] =
3485 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
3487 buffer
= load_dynamic_stringW(row
,3);
3488 size
= (strlenW(buffer
)+1) * sizeof(WCHAR
);
3489 RegSetValueExW(hkey3
,szLocalService
,0,REG_SZ
,(LPVOID
)buffer
,size
);
3490 HeapFree(GetProcessHeap(),0,buffer
);
3493 if (!MSI_RecordIsNull(row
,4))
3495 static const WCHAR szService
[] =
3496 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
3498 buffer
= load_dynamic_stringW(row
,4);
3499 size
= (strlenW(buffer
)+1) * sizeof(WCHAR
);
3500 RegSetValueExW(hkey3
,szService
,0,REG_SZ
,(LPVOID
)buffer
,size
);
3501 HeapFree(GetProcessHeap(),0,buffer
);
3504 if (!MSI_RecordIsNull(row
,5))
3506 static const WCHAR szDLL
[] =
3507 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
3509 buffer
= load_dynamic_stringW(row
,5);
3510 size
= (strlenW(buffer
)+1) * sizeof(WCHAR
);
3511 RegSetValueExW(hkey3
,szDLL
,0,REG_SZ
,(LPVOID
)buffer
,size
);
3512 HeapFree(GetProcessHeap(),0,buffer
);
3515 if (!MSI_RecordIsNull(row
,6))
3517 static const WCHAR szActivate
[] =
3518 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
3519 static const WCHAR szY
[] = {'Y',0};
3521 if (MSI_RecordGetInteger(row
,6))
3522 RegSetValueExW(hkey3
,szActivate
,0,REG_SZ
,(LPVOID
)szY
,4);
3525 if (!MSI_RecordIsNull(row
,7))
3527 static const WCHAR szRunAs
[] = {'R','u','n','A','s',0};
3528 static const WCHAR szUser
[] =
3529 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
3531 if (MSI_RecordGetInteger(row
,7))
3532 RegSetValueExW(hkey3
,szRunAs
,0,REG_SZ
,(LPVOID
)szUser
,34);
3535 msiobj_release(&row
->hdr
);
3536 MSI_ViewClose(view
);
3537 msiobj_release(&view
->hdr
);
3543 static UINT
ACTION_RegisterClassInfo(MSIPACKAGE
*package
)
3546 * Again I am assuming the words, "Whose key file represents" when referring
3547 * to a Component as to meaning that Components KeyPath file
3549 * Also there is a very strong connection between ClassInfo and ProgID
3550 * that I am mostly glossing over.
3551 * What would be more propper is to load the ClassInfo and the ProgID info
3552 * into memory data structures and then be able to enable and disable them
3553 * based on component.
3558 MSIRECORD
* row
= 0;
3559 static const WCHAR ExecSeqQuery
[] = {
3560 'S','E','L','E','C','T',' ','*',' ',
3561 'f','r','o','m',' ','C','l','a','s','s',0};
3562 static const WCHAR szCLSID
[] = { 'C','L','S','I','D',0 };
3563 static const WCHAR szProgID
[] = { 'P','r','o','g','I','D',0 };
3564 static const WCHAR szAppID
[] = { 'A','p','p','I','D',0 };
3565 HKEY hkey
,hkey2
,hkey3
;
3568 return ERROR_INVALID_HANDLE
;
3570 rc
= RegCreateKeyW(HKEY_CLASSES_ROOT
,szCLSID
,&hkey
);
3571 if (rc
!= ERROR_SUCCESS
)
3572 return ERROR_FUNCTION_FAILED
;
3574 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3575 if (rc
!= ERROR_SUCCESS
)
3581 rc
= MSI_ViewExecute(view
, 0);
3582 if (rc
!= ERROR_SUCCESS
)
3584 MSI_ViewClose(view
);
3585 msiobj_release(&view
->hdr
);
3592 WCHAR buffer
[0x100];
3597 rc
= MSI_ViewFetch(view
,&row
);
3598 if (rc
!= ERROR_SUCCESS
)
3605 MSI_RecordGetStringW(row
,3,buffer
,&sz
);
3607 index
= get_loaded_component(package
,buffer
);
3611 msiobj_release(&row
->hdr
);
3615 if (!package
->components
[index
].Enabled
||
3616 !package
->components
[index
].FeatureState
)
3618 TRACE("Skipping class reg due to disabled component\n");
3619 msiobj_release(&row
->hdr
);
3624 MSI_RecordGetStringW(row
,1,clsid
,&sz
);
3625 RegCreateKeyW(hkey
,clsid
,&hkey2
);
3627 if (!MSI_RecordIsNull(row
,5))
3630 MSI_RecordGetStringW(row
,5,desc
,&sz
);
3632 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)desc
,
3633 (strlenW(desc
)+1)*sizeof(WCHAR
));
3639 MSI_RecordGetStringW(row
,2,buffer
,&sz
);
3641 RegCreateKeyW(hkey2
,buffer
,&hkey3
);
3643 index
= get_loaded_file(package
,package
->components
[index
].KeyPath
);
3644 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,
3645 (LPVOID
)package
->files
[index
].TargetPath
,
3646 (strlenW(package
->files
[index
].TargetPath
)+1)
3651 if (!MSI_RecordIsNull(row
,4))
3654 MSI_RecordGetStringW(row
,4,buffer
,&sz
);
3656 RegCreateKeyW(hkey2
,szProgID
,&hkey3
);
3658 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,(LPVOID
)buffer
,
3659 (strlenW(buffer
)+1)*sizeof(WCHAR
));
3664 if (!MSI_RecordIsNull(row
,6))
3667 MSI_RecordGetStringW(row
,6,buffer
,&sz
);
3669 RegSetValueExW(hkey2
,szAppID
,0,REG_SZ
,(LPVOID
)buffer
,
3670 (strlenW(buffer
)+1)*sizeof(WCHAR
));
3672 register_appid(package
,buffer
,desc
);
3677 FIXME("Process the rest of the fields >7\n");
3679 ui_actiondata(package
,szRegisterClassInfo
,row
);
3681 msiobj_release(&row
->hdr
);
3683 MSI_ViewClose(view
);
3684 msiobj_release(&view
->hdr
);
3691 static UINT
register_progid_base(MSIRECORD
* row
, LPWSTR clsid
)
3693 static const WCHAR szCLSID
[] = { 'C','L','S','I','D',0 };
3695 WCHAR buffer
[0x100];
3700 MSI_RecordGetStringW(row
,1,buffer
,&sz
);
3701 RegCreateKeyW(HKEY_CLASSES_ROOT
,buffer
,&hkey
);
3703 if (!MSI_RecordIsNull(row
,4))
3706 MSI_RecordGetStringW(row
,4,buffer
,&sz
);
3707 RegSetValueExW(hkey
,NULL
,0,REG_SZ
,(LPVOID
)buffer
, (strlenW(buffer
)+1) *
3711 if (!MSI_RecordIsNull(row
,3))
3715 MSI_RecordGetStringW(row
,3,buffer
,&sz
);
3716 RegCreateKeyW(hkey
,szCLSID
,&hkey2
);
3717 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)buffer
, (strlenW(buffer
)+1) *
3721 strcpyW(clsid
,buffer
);
3727 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
3728 return ERROR_FUNCTION_FAILED
;
3730 if (!MSI_RecordIsNull(row
,5))
3731 FIXME ("UNHANDLED icon in Progid\n");
3732 return ERROR_SUCCESS
;
3735 static UINT
register_progid(MSIPACKAGE
*package
, MSIRECORD
* row
, LPWSTR clsid
);
3737 static UINT
register_parent_progid(MSIPACKAGE
*package
, LPCWSTR parent
,
3742 MSIRECORD
* row
= 0;
3743 static const WCHAR Query_t
[] =
3744 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','P','r','o','g'
3745 ,'I','d',' ','w','h','e','r','e',' ','P','r','o','g','I','d',' ','=',' ','`'
3747 WCHAR Query
[0x1000];
3750 return ERROR_INVALID_HANDLE
;
3752 sprintfW(Query
,Query_t
,parent
);
3754 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3755 if (rc
!= ERROR_SUCCESS
)
3758 rc
= MSI_ViewExecute(view
, 0);
3759 if (rc
!= ERROR_SUCCESS
)
3761 MSI_ViewClose(view
);
3762 msiobj_release(&view
->hdr
);
3766 rc
= MSI_ViewFetch(view
,&row
);
3767 if (rc
!= ERROR_SUCCESS
)
3769 MSI_ViewClose(view
);
3770 msiobj_release(&view
->hdr
);
3774 register_progid(package
,row
,clsid
);
3776 msiobj_release(&row
->hdr
);
3777 MSI_ViewClose(view
);
3778 msiobj_release(&view
->hdr
);
3782 static UINT
register_progid(MSIPACKAGE
*package
, MSIRECORD
* row
, LPWSTR clsid
)
3784 UINT rc
= ERROR_SUCCESS
;
3786 if (MSI_RecordIsNull(row
,2))
3787 rc
= register_progid_base(row
,clsid
);
3790 WCHAR buffer
[0x1000];
3793 static const WCHAR szCLSID
[] = { 'C','L','S','I','D',0 };
3796 MSI_RecordGetStringW(row
,2,buffer
,&sz
);
3797 rc
= register_parent_progid(package
,buffer
,clsid
);
3800 MSI_RecordGetStringW(row
,1,buffer
,&sz
);
3801 RegCreateKeyW(HKEY_CLASSES_ROOT
,buffer
,&hkey
);
3802 /* clasid is same as parent */
3803 RegCreateKeyW(hkey
,szCLSID
,&hkey2
);
3804 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)clsid
, (strlenW(clsid
)+1) *
3808 if (!MSI_RecordIsNull(row
,4))
3811 MSI_RecordGetStringW(row
,4,buffer
,&sz
);
3812 RegSetValueExW(hkey
,NULL
,0,REG_SZ
,(LPVOID
)buffer
,
3813 (strlenW(buffer
)+1) * sizeof(WCHAR
));
3816 if (!MSI_RecordIsNull(row
,5))
3817 FIXME ("UNHANDLED icon in Progid\n");
3824 static UINT
ACTION_RegisterProgIdInfo(MSIPACKAGE
*package
)
3827 * Sigh, here I am just brute force registering all progids
3828 * this needs to be linked to the Classes that have been registered
3829 * but the easiest way to do that is to load all these stuff into
3830 * memory for easy checking.
3832 * Gives me something to continue to work toward.
3836 MSIRECORD
* row
= 0;
3837 static const WCHAR Query
[] = {
3838 'S','E','L','E','C','T',' ','*',' ',
3839 'F','R','O','M',' ','P','r','o','g','I','d',0};
3842 return ERROR_INVALID_HANDLE
;
3844 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3845 if (rc
!= ERROR_SUCCESS
)
3846 return ERROR_SUCCESS
;
3848 rc
= MSI_ViewExecute(view
, 0);
3849 if (rc
!= ERROR_SUCCESS
)
3851 MSI_ViewClose(view
);
3852 msiobj_release(&view
->hdr
);
3858 WCHAR clsid
[0x1000];
3860 rc
= MSI_ViewFetch(view
,&row
);
3861 if (rc
!= ERROR_SUCCESS
)
3867 register_progid(package
,row
,clsid
);
3868 ui_actiondata(package
,szRegisterProgIdInfo
,row
);
3870 msiobj_release(&row
->hdr
);
3872 MSI_ViewClose(view
);
3873 msiobj_release(&view
->hdr
);
3877 static UINT
build_icon_path(MSIPACKAGE
*package
, LPCWSTR icon_name
,
3880 WCHAR ProductCode
[0x100];
3881 WCHAR SystemFolder
[MAX_PATH
];
3884 static const WCHAR szInstaller
[] =
3885 {'I','n','s','t','a','l','l','e','r','\\',0};
3886 static const WCHAR szProductCode
[] =
3887 {'P','r','o','d','u','c','t','C','o','d','e',0};
3888 static const WCHAR szFolder
[] =
3889 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3892 MSI_GetPropertyW(package
,szProductCode
,ProductCode
,&sz
);
3893 if (strlenW(ProductCode
)==0)
3894 return ERROR_FUNCTION_FAILED
;
3897 MSI_GetPropertyW(package
,szFolder
,SystemFolder
,&sz
);
3898 strcatW(SystemFolder
,szInstaller
);
3899 strcatW(SystemFolder
,ProductCode
);
3900 create_full_pathW(SystemFolder
);
3902 strcpyW(FilePath
,SystemFolder
);
3903 strcatW(FilePath
,cszbs
);
3904 strcatW(FilePath
,icon_name
);
3905 return ERROR_SUCCESS
;
3908 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
)
3912 MSIRECORD
* row
= 0;
3913 static const WCHAR Query
[] = {
3914 'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
3915 'S','h','o','r','t','c','u','t',0};
3921 return ERROR_INVALID_HANDLE
;
3923 res
= CoInitialize( NULL
);
3926 ERR("CoInitialize failed\n");
3927 return ERROR_FUNCTION_FAILED
;
3930 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
3931 if (rc
!= ERROR_SUCCESS
)
3932 return ERROR_SUCCESS
;
3934 rc
= MSI_ViewExecute(view
, 0);
3935 if (rc
!= ERROR_SUCCESS
)
3937 MSI_ViewClose(view
);
3938 msiobj_release(&view
->hdr
);
3944 WCHAR target_file
[MAX_PATH
];
3945 WCHAR buffer
[0x100];
3948 static const WCHAR szlnk
[]={'.','l','n','k',0};
3950 rc
= MSI_ViewFetch(view
,&row
);
3951 if (rc
!= ERROR_SUCCESS
)
3958 MSI_RecordGetStringW(row
,4,buffer
,&sz
);
3960 index
= get_loaded_component(package
,buffer
);
3964 msiobj_release(&row
->hdr
);
3968 if (!package
->components
[index
].Enabled
||
3969 !package
->components
[index
].FeatureState
)
3971 TRACE("Skipping shortcut creation due to disabled component\n");
3972 msiobj_release(&row
->hdr
);
3976 ui_actiondata(package
,szCreateShortcuts
,row
);
3978 res
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3979 &IID_IShellLinkW
, (LPVOID
*) &sl
);
3983 ERR("Is IID_IShellLink\n");
3984 msiobj_release(&row
->hdr
);
3988 res
= IShellLinkW_QueryInterface( sl
, &IID_IPersistFile
,(LPVOID
*) &pf
);
3991 ERR("Is IID_IPersistFile\n");
3992 msiobj_release(&row
->hdr
);
3997 MSI_RecordGetStringW(row
,2,buffer
,&sz
);
3998 resolve_folder(package
, buffer
,target_file
,FALSE
,FALSE
,NULL
);
4001 MSI_RecordGetStringW(row
,3,buffer
,&sz
);
4002 reduce_to_longfilename(buffer
);
4003 strcatW(target_file
,buffer
);
4004 if (!strchrW(target_file
,'.'))
4005 strcatW(target_file
,szlnk
);
4008 MSI_RecordGetStringW(row
,5,buffer
,&sz
);
4009 if (strchrW(buffer
,'['))
4012 deformat_string(package
,buffer
,&deformated
);
4013 IShellLinkW_SetPath(sl
,deformated
);
4014 HeapFree(GetProcessHeap(),0,deformated
);
4018 FIXME("UNHANDLED shortcut format, advertised shortcut\n");
4019 IPersistFile_Release( pf
);
4020 IShellLinkW_Release( sl
);
4021 msiobj_release(&row
->hdr
);
4025 if (!MSI_RecordIsNull(row
,6))
4029 MSI_RecordGetStringW(row
,6,buffer
,&sz
);
4030 deformat_string(package
,buffer
,&deformated
);
4031 IShellLinkW_SetArguments(sl
,deformated
);
4032 HeapFree(GetProcessHeap(),0,deformated
);
4035 if (!MSI_RecordIsNull(row
,7))
4038 deformated
= load_dynamic_stringW(row
,7);
4039 IShellLinkW_SetDescription(sl
,deformated
);
4040 HeapFree(GetProcessHeap(),0,deformated
);
4043 if (!MSI_RecordIsNull(row
,8))
4044 IShellLinkW_SetHotkey(sl
,MSI_RecordGetInteger(row
,8));
4046 if (!MSI_RecordIsNull(row
,9))
4048 WCHAR Path
[MAX_PATH
];
4052 MSI_RecordGetStringW(row
,9,buffer
,&sz
);
4054 build_icon_path(package
,buffer
,Path
);
4055 index
= MSI_RecordGetInteger(row
,10);
4057 IShellLinkW_SetIconLocation(sl
,Path
,index
);
4060 if (!MSI_RecordIsNull(row
,11))
4061 IShellLinkW_SetShowCmd(sl
,MSI_RecordGetInteger(row
,11));
4063 if (!MSI_RecordIsNull(row
,12))
4065 WCHAR Path
[MAX_PATH
];
4068 MSI_RecordGetStringW(row
,12,buffer
,&sz
);
4069 resolve_folder(package
, buffer
, Path
, FALSE
, FALSE
, NULL
);
4070 IShellLinkW_SetWorkingDirectory(sl
,Path
);
4073 TRACE("Writing shortcut to %s\n",debugstr_w(target_file
));
4074 IPersistFile_Save(pf
,target_file
,FALSE
);
4076 IPersistFile_Release( pf
);
4077 IShellLinkW_Release( sl
);
4079 msiobj_release(&row
->hdr
);
4081 MSI_ViewClose(view
);
4082 msiobj_release(&view
->hdr
);
4092 * 99% of the work done here is only done for
4093 * advertised installs. However this is where the
4094 * Icon table is processed and written out
4095 * so that is what I am going to do here.
4097 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
)
4101 MSIRECORD
* row
= 0;
4102 static const WCHAR Query
[]={
4103 'S','E','L','E','C','T',' ','*',' ',
4104 'f','r','o','m',' ','I','c','o','n',0};
4108 return ERROR_INVALID_HANDLE
;
4110 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
4111 if (rc
!= ERROR_SUCCESS
)
4112 return ERROR_SUCCESS
;
4114 rc
= MSI_ViewExecute(view
, 0);
4115 if (rc
!= ERROR_SUCCESS
)
4117 MSI_ViewClose(view
);
4118 msiobj_release(&view
->hdr
);
4125 WCHAR FilePath
[MAX_PATH
];
4126 WCHAR FileName
[MAX_PATH
];
4129 rc
= MSI_ViewFetch(view
,&row
);
4130 if (rc
!= ERROR_SUCCESS
)
4137 MSI_RecordGetStringW(row
,1,FileName
,&sz
);
4140 ERR("Unable to get FileName\n");
4141 msiobj_release(&row
->hdr
);
4145 build_icon_path(package
,FileName
,FilePath
);
4147 TRACE("Creating icon file at %s\n",debugstr_w(FilePath
));
4149 the_file
= CreateFileW(FilePath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
4150 FILE_ATTRIBUTE_NORMAL
, NULL
);
4152 if (the_file
== INVALID_HANDLE_VALUE
)
4154 ERR("Unable to create file %s\n",debugstr_w(FilePath
));
4155 msiobj_release(&row
->hdr
);
4163 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
4164 if (rc
!= ERROR_SUCCESS
)
4166 ERR("Failed to get stream\n");
4167 CloseHandle(the_file
);
4168 DeleteFileW(FilePath
);
4171 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
4172 } while (sz
== 1024);
4174 CloseHandle(the_file
);
4175 msiobj_release(&row
->hdr
);
4177 MSI_ViewClose(view
);
4178 msiobj_release(&view
->hdr
);
4183 /* Msi functions that seem appropriate here */
4184 UINT WINAPI
MsiDoActionA( MSIHANDLE hInstall
, LPCSTR szAction
)
4189 TRACE(" exteral attempt at action %s\n",szAction
);
4192 return ERROR_FUNCTION_FAILED
;
4194 return ERROR_FUNCTION_FAILED
;
4196 szwAction
= strdupAtoW(szAction
);
4199 return ERROR_FUNCTION_FAILED
;
4202 rc
= MsiDoActionW(hInstall
, szwAction
);
4203 HeapFree(GetProcessHeap(),0,szwAction
);
4207 UINT WINAPI
MsiDoActionW( MSIHANDLE hInstall
, LPCWSTR szAction
)
4209 MSIPACKAGE
*package
;
4210 UINT ret
= ERROR_INVALID_HANDLE
;
4212 TRACE(" external attempt at action %s \n",debugstr_w(szAction
));
4214 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
4217 ret
= ACTION_PerformAction(package
,szAction
);
4218 msiobj_release( &package
->hdr
);
4223 UINT WINAPI
MsiGetTargetPathA( MSIHANDLE hInstall
, LPCSTR szFolder
,
4224 LPSTR szPathBuf
, DWORD
* pcchPathBuf
)
4230 TRACE("getting folder %s %p %li\n",szFolder
,szPathBuf
, *pcchPathBuf
);
4233 return ERROR_FUNCTION_FAILED
;
4235 return ERROR_FUNCTION_FAILED
;
4237 szwFolder
= strdupAtoW(szFolder
);
4240 return ERROR_FUNCTION_FAILED
;
4242 szwPathBuf
= HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf
* sizeof(WCHAR
));
4244 rc
= MsiGetTargetPathW(hInstall
, szwFolder
, szwPathBuf
,pcchPathBuf
);
4246 WideCharToMultiByte( CP_ACP
, 0, szwPathBuf
, *pcchPathBuf
, szPathBuf
,
4247 *pcchPathBuf
, NULL
, NULL
);
4249 HeapFree(GetProcessHeap(),0,szwFolder
);
4250 HeapFree(GetProcessHeap(),0,szwPathBuf
);
4255 UINT WINAPI
MsiGetTargetPathW( MSIHANDLE hInstall
, LPCWSTR szFolder
, LPWSTR
4256 szPathBuf
, DWORD
* pcchPathBuf
)
4258 WCHAR path
[MAX_PATH
];
4260 MSIPACKAGE
*package
;
4262 TRACE("(%s %p %li)\n",debugstr_w(szFolder
),szPathBuf
,*pcchPathBuf
);
4264 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
4266 return ERROR_INVALID_HANDLE
;
4267 rc
= resolve_folder(package
, szFolder
, path
, FALSE
, FALSE
, NULL
);
4268 msiobj_release( &package
->hdr
);
4270 if (rc
== ERROR_SUCCESS
&& strlenW(path
) > *pcchPathBuf
)
4272 *pcchPathBuf
= strlenW(path
)+1;
4273 return ERROR_MORE_DATA
;
4275 else if (rc
== ERROR_SUCCESS
)
4277 *pcchPathBuf
= strlenW(path
)+1;
4278 strcpyW(szPathBuf
,path
);
4279 TRACE("Returning Path %s\n",debugstr_w(path
));
4286 UINT WINAPI
MsiGetSourcePathA( MSIHANDLE hInstall
, LPCSTR szFolder
,
4287 LPSTR szPathBuf
, DWORD
* pcchPathBuf
)
4293 TRACE("getting source %s %p %li\n",szFolder
,szPathBuf
, *pcchPathBuf
);
4296 return ERROR_FUNCTION_FAILED
;
4298 return ERROR_FUNCTION_FAILED
;
4300 szwFolder
= strdupAtoW(szFolder
);
4302 return ERROR_FUNCTION_FAILED
;
4304 szwPathBuf
= HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf
* sizeof(WCHAR
));
4306 rc
= MsiGetSourcePathW(hInstall
, szwFolder
, szwPathBuf
,pcchPathBuf
);
4308 WideCharToMultiByte( CP_ACP
, 0, szwPathBuf
, *pcchPathBuf
, szPathBuf
,
4309 *pcchPathBuf
, NULL
, NULL
);
4311 HeapFree(GetProcessHeap(),0,szwFolder
);
4312 HeapFree(GetProcessHeap(),0,szwPathBuf
);
4317 UINT WINAPI
MsiGetSourcePathW( MSIHANDLE hInstall
, LPCWSTR szFolder
, LPWSTR
4318 szPathBuf
, DWORD
* pcchPathBuf
)
4320 WCHAR path
[MAX_PATH
];
4322 MSIPACKAGE
*package
;
4324 TRACE("(%s %p %li)\n",debugstr_w(szFolder
),szPathBuf
,*pcchPathBuf
);
4326 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
4328 return ERROR_INVALID_HANDLE
;
4329 rc
= resolve_folder(package
, szFolder
, path
, TRUE
, FALSE
, NULL
);
4330 msiobj_release( &package
->hdr
);
4332 if (rc
== ERROR_SUCCESS
&& strlenW(path
) > *pcchPathBuf
)
4334 *pcchPathBuf
= strlenW(path
)+1;
4335 return ERROR_MORE_DATA
;
4337 else if (rc
== ERROR_SUCCESS
)
4339 *pcchPathBuf
= strlenW(path
)+1;
4340 strcpyW(szPathBuf
,path
);
4341 TRACE("Returning Path %s\n",debugstr_w(path
));
4348 UINT WINAPI
MsiSetTargetPathA(MSIHANDLE hInstall
, LPCSTR szFolder
,
4349 LPCSTR szFolderPath
)
4352 LPWSTR szwFolderPath
;
4356 return ERROR_FUNCTION_FAILED
;
4358 return ERROR_FUNCTION_FAILED
;
4360 szwFolder
= strdupAtoW(szFolder
);
4362 return ERROR_FUNCTION_FAILED
;
4364 szwFolderPath
= strdupAtoW(szFolderPath
);
4367 HeapFree(GetProcessHeap(),0,szwFolder
);
4368 return ERROR_FUNCTION_FAILED
;
4371 rc
= MsiSetTargetPathW(hInstall
, szwFolder
, szwFolderPath
);
4373 HeapFree(GetProcessHeap(),0,szwFolder
);
4374 HeapFree(GetProcessHeap(),0,szwFolderPath
);
4379 UINT
MSI_SetTargetPathW(MSIPACKAGE
*package
, LPCWSTR szFolder
,
4380 LPCWSTR szFolderPath
)
4383 WCHAR path
[MAX_PATH
];
4386 TRACE("(%p %s %s)\n",package
, debugstr_w(szFolder
),debugstr_w(szFolderPath
));
4389 return ERROR_INVALID_HANDLE
;
4391 if (szFolderPath
[0]==0)
4392 return ERROR_FUNCTION_FAILED
;
4394 if (GetFileAttributesW(szFolderPath
) == INVALID_FILE_ATTRIBUTES
)
4395 return ERROR_FUNCTION_FAILED
;
4397 resolve_folder(package
,szFolder
,path
,FALSE
,FALSE
,&folder
);
4400 return ERROR_INVALID_PARAMETER
;
4402 strcpyW(folder
->Property
,szFolderPath
);
4404 for (i
= 0; i
< package
->loaded_folders
; i
++)
4405 package
->folders
[i
].ResolvedTarget
[0]=0;
4407 for (i
= 0; i
< package
->loaded_folders
; i
++)
4408 resolve_folder(package
, package
->folders
[i
].Directory
, path
, FALSE
,
4411 return ERROR_SUCCESS
;
4414 UINT WINAPI
MsiSetTargetPathW(MSIHANDLE hInstall
, LPCWSTR szFolder
,
4415 LPCWSTR szFolderPath
)
4417 MSIPACKAGE
*package
;
4420 TRACE("(%s %s)\n",debugstr_w(szFolder
),debugstr_w(szFolderPath
));
4422 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
4423 ret
= MSI_SetTargetPathW( package
, szFolder
, szFolderPath
);
4424 msiobj_release( &package
->hdr
);
4428 BOOL WINAPI
MsiGetMode(MSIHANDLE hInstall
, DWORD iRunMode
)
4430 FIXME("STUB (%li)\n",iRunMode
);
4435 * according to the docs when this is called it immediently recalculates all the
4436 * components states as well
4438 UINT WINAPI
MsiSetFeatureStateA(MSIHANDLE hInstall
, LPCSTR szFeature
,
4439 INSTALLSTATE iState
)
4441 LPWSTR szwFeature
= NULL
;
4444 szwFeature
= strdupAtoW(szFeature
);
4447 return ERROR_FUNCTION_FAILED
;
4449 rc
= MsiSetFeatureStateW(hInstall
,szwFeature
, iState
);
4451 HeapFree(GetProcessHeap(),0,szwFeature
);
4456 UINT WINAPI
MsiSetFeatureStateW(MSIHANDLE hInstall
, LPCWSTR szFeature
,
4457 INSTALLSTATE iState
)
4459 MSIPACKAGE
* package
;
4462 TRACE(" %s to %i\n",debugstr_w(szFeature
), iState
);
4464 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
4466 return ERROR_INVALID_HANDLE
;
4468 index
= get_loaded_feature(package
,szFeature
);
4470 return ERROR_UNKNOWN_FEATURE
;
4472 package
->features
[index
].State
= iState
;
4474 return ERROR_SUCCESS
;
4477 UINT WINAPI
MsiGetFeatureStateA(MSIHANDLE hInstall
, LPSTR szFeature
,
4478 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
4480 LPWSTR szwFeature
= NULL
;
4483 szwFeature
= strdupAtoW(szFeature
);
4485 rc
= MsiGetFeatureStateW(hInstall
,szwFeature
,piInstalled
, piAction
);
4487 HeapFree( GetProcessHeap(), 0 , szwFeature
);
4492 UINT
MSI_GetFeatureStateW(MSIPACKAGE
*package
, LPWSTR szFeature
,
4493 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
4497 index
= get_loaded_feature(package
,szFeature
);
4499 return ERROR_UNKNOWN_FEATURE
;
4502 *piInstalled
= package
->features
[index
].State
;
4506 if (package
->features
[index
].Enabled
)
4507 *piAction
= INSTALLSTATE_LOCAL
;
4509 *piAction
= INSTALLSTATE_UNKNOWN
;
4512 return ERROR_SUCCESS
;
4515 UINT WINAPI
MsiGetFeatureStateW(MSIHANDLE hInstall
, LPWSTR szFeature
,
4516 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
4518 MSIPACKAGE
* package
;
4521 TRACE("%ld %s %p %p\n", hInstall
, debugstr_w(szFeature
), piInstalled
,
4524 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
4526 return ERROR_INVALID_HANDLE
;
4527 ret
= MSI_GetFeatureStateW(package
, szFeature
, piInstalled
, piAction
);
4528 msiobj_release( &package
->hdr
);
4532 UINT WINAPI
MsiGetComponentStateA(MSIHANDLE hInstall
, LPSTR szComponent
,
4533 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
4535 LPWSTR szwComponent
= NULL
;
4538 szwComponent
= strdupAtoW(szComponent
);
4540 rc
= MsiGetComponentStateW(hInstall
,szwComponent
,piInstalled
, piAction
);
4542 HeapFree( GetProcessHeap(), 0 , szwComponent
);
4547 UINT
MSI_GetComponentStateW(MSIPACKAGE
*package
, LPWSTR szComponent
,
4548 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
4552 TRACE("%p %s %p %p\n", package
, debugstr_w(szComponent
), piInstalled
,
4555 index
= get_loaded_component(package
,szComponent
);
4557 return ERROR_UNKNOWN_COMPONENT
;
4560 *piInstalled
= package
->components
[index
].State
;
4564 if (package
->components
[index
].Enabled
&&
4565 package
->components
[index
].FeatureState
)
4566 *piAction
= INSTALLSTATE_LOCAL
;
4568 *piAction
= INSTALLSTATE_UNKNOWN
;
4571 return ERROR_SUCCESS
;
4574 UINT WINAPI
MsiGetComponentStateW(MSIHANDLE hInstall
, LPWSTR szComponent
,
4575 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
4577 MSIPACKAGE
* package
;
4580 TRACE("%ld %s %p %p\n", hInstall
, debugstr_w(szComponent
),
4581 piInstalled
, piAction
);
4583 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
4585 return ERROR_INVALID_HANDLE
;
4586 ret
= MSI_GetComponentStateW( package
, szComponent
, piInstalled
, piAction
);
4587 msiobj_release( &package
->hdr
);
4592 static UINT
ACTION_Template(MSIPACKAGE
*package
)
4596 MSIRECORD
* row
= 0;
4597 static const WCHAR ExecSeqQuery
[] = {0};
4599 rc
= MsiDatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
4600 if (rc
!= ERROR_SUCCESS
)
4603 rc
= MsiViewExecute(view
, 0);
4604 if (rc
!= ERROR_SUCCESS
)
4607 msiobj_release(&view
->hdr
);
4613 rc
= MsiViewFetch(view
,&row
);
4614 if (rc
!= ERROR_SUCCESS
)
4620 msiobj_release(&row
->hdr
);
4623 msiobj_release(&view
->hdr
);