2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installexecutesequence_table.asp
26 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/standard_actions_reference.asp
38 #include "wine/debug.h"
43 #include "msvcrt/fcntl.h"
50 #include "wine/unicode.h"
54 #define REG_PROGRESS_VALUE 13200
55 #define COMPONENT_PROGRESS_VALUE 24000
57 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
62 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
);
63 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
);
64 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
);
65 static UINT
build_icon_path(MSIPACKAGE
*package
, LPCWSTR icon_name
,
71 typedef UINT (*STANDARDACTIONHANDLER
)(MSIPACKAGE
*);
73 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
);
74 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
);
75 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
);
76 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
);
77 static UINT
ACTION_FileCost(MSIPACKAGE
*package
);
78 static UINT
ACTION_InstallFiles(MSIPACKAGE
*package
);
79 static UINT
ACTION_DuplicateFiles(MSIPACKAGE
*package
);
80 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
);
81 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
);
82 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
);
83 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
);
84 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
);
85 static UINT
ACTION_RegisterClassInfo(MSIPACKAGE
*package
);
86 static UINT
ACTION_RegisterProgIdInfo(MSIPACKAGE
*package
);
87 static UINT
ACTION_RegisterExtensionInfo(MSIPACKAGE
*package
);
88 static UINT
ACTION_RegisterMIMEInfo(MSIPACKAGE
*package
);
89 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
);
90 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
);
91 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
);
92 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
);
93 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
);
94 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
);
95 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
);
96 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
);
97 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
);
98 static UINT
ACTION_ForceReboot(MSIPACKAGE
*package
);
99 static UINT
ACTION_ResolveSource(MSIPACKAGE
*package
);
100 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
);
101 static UINT
ACTION_RegisterFonts(MSIPACKAGE
*package
);
105 * consts and values used
107 static const WCHAR cszSourceDir
[] = {'S','o','u','r','c','e','D','i','r',0};
108 static const WCHAR cszRootDrive
[] = {'R','O','O','T','D','R','I','V','E',0};
109 static const WCHAR cszTargetDir
[] = {'T','A','R','G','E','T','D','I','R',0};
110 static const WCHAR cszTempFolder
[]= {'T','e','m','p','F','o','l','d','e','r',0};
111 static const WCHAR cszDatabase
[]={'D','A','T','A','B','A','S','E',0};
112 static const WCHAR c_colon
[] = {'C',':','\\',0};
113 static const WCHAR szProductCode
[]=
114 {'P','r','o','d','u','c','t','C','o','d','e',0};
115 static const WCHAR cszbs
[]={'\\',0};
116 const static WCHAR szCreateFolders
[] =
117 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
118 const static WCHAR szCostFinalize
[] =
119 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
120 const static WCHAR szInstallFiles
[] =
121 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
122 const static WCHAR szDuplicateFiles
[] =
123 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
124 const static WCHAR szWriteRegistryValues
[] =
125 {'W','r','i','t','e','R','e','g','i','s','t','r','y',
126 'V','a','l','u','e','s',0};
127 const static WCHAR szCostInitialize
[] =
128 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
129 const static WCHAR szFileCost
[] =
130 {'F','i','l','e','C','o','s','t',0};
131 const static WCHAR szInstallInitialize
[] =
132 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
133 const static WCHAR szInstallValidate
[] =
134 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
135 const static WCHAR szLaunchConditions
[] =
136 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
137 const static WCHAR szProcessComponents
[] =
138 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
139 const static WCHAR szRegisterTypeLibraries
[] =
140 {'R','e','g','i','s','t','e','r','T','y','p','e',
141 'L','i','b','r','a','r','i','e','s',0};
142 const static WCHAR szRegisterClassInfo
[] =
143 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
144 const static WCHAR szRegisterProgIdInfo
[] =
145 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
146 const static WCHAR szCreateShortcuts
[] =
147 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
148 const static WCHAR szPublishProduct
[] =
149 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
150 const static WCHAR szWriteIniValues
[] =
151 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
152 const static WCHAR szSelfRegModules
[] =
153 {'S','e','l','f','R','e','g','M','o','d','u','l','e','s',0};
154 const static WCHAR szPublishFeatures
[] =
155 {'P','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
156 const static WCHAR szRegisterProduct
[] =
157 {'R','e','g','i','s','t','e','r','P','r','o','d','u','c','t',0};
158 const static WCHAR szInstallExecute
[] =
159 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',0};
160 const static WCHAR szInstallExecuteAgain
[] =
161 {'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
162 'A','g','a','i','n',0};
163 const static WCHAR szInstallFinalize
[] =
164 {'I','n','s','t','a','l','l','F','i','n','a','l','i','z','e',0};
165 const static WCHAR szForceReboot
[] =
166 {'F','o','r','c','e','R','e','b','o','o','t',0};
167 const static WCHAR szResolveSource
[] =
168 {'R','e','s','o','l','v','e','S','o','u','r','c','e',0};
169 const static WCHAR szAppSearch
[] =
170 {'A','p','p','S','e','a','r','c','h',0};
171 const static WCHAR szAllocateRegistrySpace
[] =
172 {'A','l','l','o','c','a','t','e','R','e','g','i','s','t','r','y',
173 'S','p','a','c','e',0};
174 const static WCHAR szBindImage
[] =
175 {'B','i','n','d','I','m','a','g','e',0};
176 const static WCHAR szCCPSearch
[] =
177 {'C','C','P','S','e','a','r','c','h',0};
178 const static WCHAR szDeleteServices
[] =
179 {'D','e','l','e','t','e','S','e','r','v','i','c','e','s',0};
180 const static WCHAR szDisableRollback
[] =
181 {'D','i','s','a','b','l','e','R','o','l','l','b','a','c','k',0};
182 const static WCHAR szExecuteAction
[] =
183 {'E','x','e','c','u','t','e','A','c','t','i','o','n',0};
184 const static WCHAR szFindRelatedProducts
[] =
185 {'F','i','n','d','R','e','l','a','t','e','d',
186 'P','r','o','d','u','c','t','s',0};
187 const static WCHAR szInstallAdminPackage
[] =
188 {'I','n','s','t','a','l','l','A','d','m','i','n',
189 'P','a','c','k','a','g','e',0};
190 const static WCHAR szInstallSFPCatalogFile
[] =
191 {'I','n','s','t','a','l','l','S','F','P','C','a','t','a','l','o','g',
193 const static WCHAR szIsolateComponents
[] =
194 {'I','s','o','l','a','t','e','C','o','m','p','o','n','e','n','t','s',0};
195 const static WCHAR szMigrateFeatureStates
[] =
196 {'M','i','g','r','a','t','e','F','e','a','t','u','r','e',
197 'S','t','a','t','e','s',0};
198 const static WCHAR szMoveFiles
[] =
199 {'M','o','v','e','F','i','l','e','s',0};
200 const static WCHAR szMsiPublishAssemblies
[] =
201 {'M','s','i','P','u','b','l','i','s','h',
202 'A','s','s','e','m','b','l','i','e','s',0};
203 const static WCHAR szMsiUnpublishAssemblies
[] =
204 {'M','s','i','U','n','p','u','b','l','i','s','h',
205 'A','s','s','e','m','b','l','i','e','s',0};
206 const static WCHAR szInstallODBC
[] =
207 {'I','n','s','t','a','l','l','O','D','B','C',0};
208 const static WCHAR szInstallServices
[] =
209 {'I','n','s','t','a','l','l','S','e','r','v','i','c','e','s',0};
210 const static WCHAR szPatchFiles
[] =
211 {'P','a','t','c','h','F','i','l','e','s',0};
212 const static WCHAR szPublishComponents
[] =
213 {'P','u','b','l','i','s','h','C','o','m','p','o','n','e','n','t','s',0};
214 const static WCHAR szRegisterComPlus
[] =
215 {'R','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
216 const static WCHAR szRegisterExtensionInfo
[] =
217 {'R','e','g','i','s','t','e','r','E','x','t','e','n','s','i','o','n',
219 const static WCHAR szRegisterFonts
[] =
220 {'R','e','g','i','s','t','e','r','F','o','n','t','s',0};
221 const static WCHAR szRegisterMIMEInfo
[] =
222 {'R','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
223 const static WCHAR szRegisterUser
[] =
224 {'R','e','g','i','s','t','e','r','U','s','e','r',0};
225 const static WCHAR szRemoveDuplicateFiles
[] =
226 {'R','e','m','o','v','e','D','u','p','l','i','c','a','t','e',
227 'F','i','l','e','s',0};
228 const static WCHAR szRemoveEnvironmentStrings
[] =
229 {'R','e','m','o','v','e','E','n','v','i','r','o','n','m','e','n','t',
230 'S','t','r','i','n','g','s',0};
231 const static WCHAR szRemoveExistingProducts
[] =
232 {'R','e','m','o','v','e','E','x','i','s','t','i','n','g',
233 'P','r','o','d','u','c','t','s',0};
234 const static WCHAR szRemoveFiles
[] =
235 {'R','e','m','o','v','e','F','i','l','e','s',0};
236 const static WCHAR szRemoveFolders
[] =
237 {'R','e','m','o','v','e','F','o','l','d','e','r','s',0};
238 const static WCHAR szRemoveIniValues
[] =
239 {'R','e','m','o','v','e','I','n','i','V','a','l','u','e','s',0};
240 const static WCHAR szRemoveODBC
[] =
241 {'R','e','m','o','v','e','O','D','B','C',0};
242 const static WCHAR szRemoveRegistryValues
[] =
243 {'R','e','m','o','v','e','R','e','g','i','s','t','r','y',
244 'V','a','l','u','e','s',0};
245 const static WCHAR szRemoveShortcuts
[] =
246 {'R','e','m','o','v','e','S','h','o','r','t','c','u','t','s',0};
247 const static WCHAR szRMCCPSearch
[] =
248 {'R','M','C','C','P','S','e','a','r','c','h',0};
249 const static WCHAR szScheduleReboot
[] =
250 {'S','c','h','e','d','u','l','e','R','e','b','o','o','t',0};
251 const static WCHAR szSelfUnregModules
[] =
252 {'S','e','l','f','U','n','r','e','g','M','o','d','u','l','e','s',0};
253 const static WCHAR szSetODBCFolders
[] =
254 {'S','e','t','O','D','B','C','F','o','l','d','e','r','s',0};
255 const static WCHAR szStartServices
[] =
256 {'S','t','a','r','t','S','e','r','v','i','c','e','s',0};
257 const static WCHAR szStopServices
[] =
258 {'S','t','o','p','S','e','r','v','i','c','e','s',0};
259 const static WCHAR szUnpublishComponents
[] =
260 {'U','n','p','u','b','l','i','s','h',
261 'C','o','m','p','o','n','e','n','t','s',0};
262 const static WCHAR szUnpublishFeatures
[] =
263 {'U','n','p','u','b','l','i','s','h','F','e','a','t','u','r','e','s',0};
264 const static WCHAR szUnregisterClassInfo
[] =
265 {'U','n','r','e','g','i','s','t','e','r','C','l','a','s','s',
267 const static WCHAR szUnregisterComPlus
[] =
268 {'U','n','r','e','g','i','s','t','e','r','C','o','m','P','l','u','s',0};
269 const static WCHAR szUnregisterExtensionInfo
[] =
270 {'U','n','r','e','g','i','s','t','e','r',
271 'E','x','t','e','n','s','i','o','n','I','n','f','o',0};
272 const static WCHAR szUnregisterFonts
[] =
273 {'U','n','r','e','g','i','s','t','e','r','F','o','n','t','s',0};
274 const static WCHAR szUnregisterMIMEInfo
[] =
275 {'U','n','r','e','g','i','s','t','e','r','M','I','M','E','I','n','f','o',0};
276 const static WCHAR szUnregisterProgIdInfo
[] =
277 {'U','n','r','e','g','i','s','t','e','r','P','r','o','g','I','d',
279 const static WCHAR szUnregisterTypeLibraries
[] =
280 {'U','n','r','e','g','i','s','t','e','r','T','y','p','e',
281 'L','i','b','r','a','r','i','e','s',0};
282 const static WCHAR szValidateProductID
[] =
283 {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
284 const static WCHAR szWriteEnvironmentStrings
[] =
285 {'W','r','i','t','e','E','n','v','i','r','o','n','m','e','n','t',
286 'S','t','r','i','n','g','s',0};
290 STANDARDACTIONHANDLER handler
;
293 static struct _actions StandardActions
[] = {
294 { szAllocateRegistrySpace
, NULL
},
295 { szAppSearch
, ACTION_AppSearch
},
296 { szBindImage
, NULL
},
297 { szCCPSearch
, NULL
},
298 { szCostFinalize
, ACTION_CostFinalize
},
299 { szCostInitialize
, ACTION_CostInitialize
},
300 { szCreateFolders
, ACTION_CreateFolders
},
301 { szCreateShortcuts
, ACTION_CreateShortcuts
},
302 { szDeleteServices
, NULL
},
303 { szDisableRollback
, NULL
},
304 { szDuplicateFiles
, ACTION_DuplicateFiles
},
305 { szExecuteAction
, ACTION_ExecuteAction
},
306 { szFileCost
, ACTION_FileCost
},
307 { szFindRelatedProducts
, NULL
},
308 { szForceReboot
, ACTION_ForceReboot
},
309 { szInstallAdminPackage
, NULL
},
310 { szInstallExecute
, ACTION_InstallExecute
},
311 { szInstallExecuteAgain
, ACTION_InstallExecute
},
312 { szInstallFiles
, ACTION_InstallFiles
},
313 { szInstallFinalize
, ACTION_InstallFinalize
},
314 { szInstallInitialize
, ACTION_InstallInitialize
},
315 { szInstallSFPCatalogFile
, NULL
},
316 { szInstallValidate
, ACTION_InstallValidate
},
317 { szIsolateComponents
, NULL
},
318 { szLaunchConditions
, ACTION_LaunchConditions
},
319 { szMigrateFeatureStates
, NULL
},
320 { szMoveFiles
, NULL
},
321 { szMsiPublishAssemblies
, NULL
},
322 { szMsiUnpublishAssemblies
, NULL
},
323 { szInstallODBC
, NULL
},
324 { szInstallServices
, NULL
},
325 { szPatchFiles
, NULL
},
326 { szProcessComponents
, ACTION_ProcessComponents
},
327 { szPublishComponents
, NULL
},
328 { szPublishFeatures
, ACTION_PublishFeatures
},
329 { szPublishProduct
, ACTION_PublishProduct
},
330 { szRegisterClassInfo
, ACTION_RegisterClassInfo
},
331 { szRegisterComPlus
, NULL
},
332 { szRegisterExtensionInfo
, ACTION_RegisterExtensionInfo
},
333 { szRegisterFonts
, ACTION_RegisterFonts
},
334 { szRegisterMIMEInfo
, ACTION_RegisterMIMEInfo
},
335 { szRegisterProduct
, ACTION_RegisterProduct
},
336 { szRegisterProgIdInfo
, ACTION_RegisterProgIdInfo
},
337 { szRegisterTypeLibraries
, ACTION_RegisterTypeLibraries
},
338 { szRegisterUser
, ACTION_RegisterUser
},
339 { szRemoveDuplicateFiles
, NULL
},
340 { szRemoveEnvironmentStrings
, NULL
},
341 { szRemoveExistingProducts
, NULL
},
342 { szRemoveFiles
, NULL
},
343 { szRemoveFolders
, NULL
},
344 { szRemoveIniValues
, NULL
},
345 { szRemoveODBC
, NULL
},
346 { szRemoveRegistryValues
, NULL
},
347 { szRemoveShortcuts
, NULL
},
348 { szResolveSource
, ACTION_ResolveSource
},
349 { szRMCCPSearch
, NULL
},
350 { szScheduleReboot
, NULL
},
351 { szSelfRegModules
, ACTION_SelfRegModules
},
352 { szSelfUnregModules
, NULL
},
353 { szSetODBCFolders
, NULL
},
354 { szStartServices
, NULL
},
355 { szStopServices
, NULL
},
356 { szUnpublishComponents
, NULL
},
357 { szUnpublishFeatures
, NULL
},
358 { szUnregisterClassInfo
, NULL
},
359 { szUnregisterComPlus
, NULL
},
360 { szUnregisterExtensionInfo
, NULL
},
361 { szUnregisterFonts
, NULL
},
362 { szUnregisterMIMEInfo
, NULL
},
363 { szUnregisterProgIdInfo
, NULL
},
364 { szUnregisterTypeLibraries
, NULL
},
365 { szValidateProductID
, NULL
},
366 { szWriteEnvironmentStrings
, NULL
},
367 { szWriteIniValues
, ACTION_WriteIniValues
},
368 { szWriteRegistryValues
, ACTION_WriteRegistryValues
},
373 /********************************************************
374 * helper functions to get around current HACKS and such
375 ********************************************************/
376 inline static void reduce_to_longfilename(WCHAR
* filename
)
378 LPWSTR p
= strchrW(filename
,'|');
380 memmove(filename
, p
+1, (strlenW(p
+1)+1)*sizeof(WCHAR
));
383 WCHAR
*load_dynamic_stringW(MSIRECORD
*row
, INT index
)
390 if (MSI_RecordIsNull(row
,index
))
393 rc
= MSI_RecordGetStringW(row
,index
,NULL
,&sz
);
395 /* having an empty string is different than NULL */
398 ret
= HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
));
404 ret
= HeapAlloc(GetProcessHeap(),0,sz
* sizeof (WCHAR
));
405 rc
= MSI_RecordGetStringW(row
,index
,ret
,&sz
);
406 if (rc
!=ERROR_SUCCESS
)
408 ERR("Unable to load dynamic string\n");
409 HeapFree(GetProcessHeap(), 0, ret
);
415 LPWSTR
load_dynamic_property(MSIPACKAGE
*package
, LPCWSTR prop
, UINT
* rc
)
421 r
= MSI_GetPropertyW(package
, prop
, NULL
, &sz
);
422 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
429 str
= HeapAlloc(GetProcessHeap(),0,sz
*sizeof(WCHAR
));
430 r
= MSI_GetPropertyW(package
, prop
, str
, &sz
);
431 if (r
!= ERROR_SUCCESS
)
433 HeapFree(GetProcessHeap(),0,str
);
441 int get_loaded_component(MSIPACKAGE
* package
, LPCWSTR Component
)
446 for (i
= 0; i
< package
->loaded_components
; i
++)
448 if (strcmpW(Component
,package
->components
[i
].Component
)==0)
457 int get_loaded_feature(MSIPACKAGE
* package
, LPCWSTR Feature
)
462 for (i
= 0; i
< package
->loaded_features
; i
++)
464 if (strcmpW(Feature
,package
->features
[i
].Feature
)==0)
473 int get_loaded_file(MSIPACKAGE
* package
, LPCWSTR file
)
478 for (i
= 0; i
< package
->loaded_files
; i
++)
480 if (strcmpW(file
,package
->files
[i
].File
)==0)
489 int track_tempfile(MSIPACKAGE
*package
, LPCWSTR name
, LPCWSTR path
)
497 for (i
=0; i
< package
->loaded_files
; i
++)
498 if (strcmpW(package
->files
[i
].File
,name
)==0)
501 index
= package
->loaded_files
;
502 package
->loaded_files
++;
503 if (package
->loaded_files
== 1)
504 package
->files
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE
));
506 package
->files
= HeapReAlloc(GetProcessHeap(),0,
507 package
->files
, package
->loaded_files
* sizeof(MSIFILE
));
509 memset(&package
->files
[index
],0,sizeof(MSIFILE
));
511 package
->files
[index
].File
= dupstrW(name
);
512 package
->files
[index
].TargetPath
= dupstrW(path
);
513 package
->files
[index
].Temporary
= TRUE
;
515 TRACE("Tracking tempfile (%s)\n",debugstr_w(package
->files
[index
].File
));
520 static void remove_tracked_tempfiles(MSIPACKAGE
* package
)
527 for (i
= 0; i
< package
->loaded_files
; i
++)
529 if (package
->files
[i
].Temporary
)
531 TRACE("Cleaning up %s\n",debugstr_w(package
->files
[i
].TargetPath
));
532 DeleteFileW(package
->files
[i
].TargetPath
);
538 /* wrapper to resist a need for a full rewrite right now */
539 DWORD
deformat_string(MSIPACKAGE
*package
, LPCWSTR ptr
, WCHAR
** data
)
543 MSIRECORD
*rec
= MSI_CreateRecord(1);
546 MSI_RecordSetStringW(rec
,0,ptr
);
547 MSI_FormatRecordW(package
,rec
,NULL
,&size
);
551 *data
= HeapAlloc(GetProcessHeap(),0,size
*sizeof(WCHAR
));
553 MSI_FormatRecordW(package
,rec
,*data
,&size
);
556 msiobj_release( &rec
->hdr
);
557 return sizeof(WCHAR
)*size
;
559 msiobj_release( &rec
->hdr
);
566 /* Called when the package is being closed */
567 void ACTION_free_package_structures( MSIPACKAGE
* package
)
571 TRACE("Freeing package action data\n");
573 remove_tracked_tempfiles(package
);
575 /* No dynamic buffers in features */
576 if (package
->features
&& package
->loaded_features
> 0)
577 HeapFree(GetProcessHeap(),0,package
->features
);
579 for (i
= 0; i
< package
->loaded_folders
; i
++)
581 HeapFree(GetProcessHeap(),0,package
->folders
[i
].Directory
);
582 HeapFree(GetProcessHeap(),0,package
->folders
[i
].TargetDefault
);
583 HeapFree(GetProcessHeap(),0,package
->folders
[i
].SourceDefault
);
584 HeapFree(GetProcessHeap(),0,package
->folders
[i
].ResolvedTarget
);
585 HeapFree(GetProcessHeap(),0,package
->folders
[i
].ResolvedSource
);
586 HeapFree(GetProcessHeap(),0,package
->folders
[i
].Property
);
588 if (package
->folders
&& package
->loaded_folders
> 0)
589 HeapFree(GetProcessHeap(),0,package
->folders
);
591 for (i
= 0; i
< package
->loaded_components
; i
++)
592 HeapFree(GetProcessHeap(),0,package
->components
[i
].FullKeypath
);
594 if (package
->components
&& package
->loaded_components
> 0)
595 HeapFree(GetProcessHeap(),0,package
->components
);
597 for (i
= 0; i
< package
->loaded_files
; i
++)
599 HeapFree(GetProcessHeap(),0,package
->files
[i
].File
);
600 HeapFree(GetProcessHeap(),0,package
->files
[i
].FileName
);
601 HeapFree(GetProcessHeap(),0,package
->files
[i
].Version
);
602 HeapFree(GetProcessHeap(),0,package
->files
[i
].Language
);
603 HeapFree(GetProcessHeap(),0,package
->files
[i
].SourcePath
);
604 HeapFree(GetProcessHeap(),0,package
->files
[i
].TargetPath
);
607 if (package
->files
&& package
->loaded_files
> 0)
608 HeapFree(GetProcessHeap(),0,package
->files
);
610 for (i
= 0; i
< package
->DeferredActionCount
; i
++)
611 HeapFree(GetProcessHeap(),0,package
->DeferredAction
[i
]);
612 HeapFree(GetProcessHeap(),0,package
->DeferredAction
);
614 for (i
= 0; i
< package
->CommitActionCount
; i
++)
615 HeapFree(GetProcessHeap(),0,package
->CommitAction
[i
]);
616 HeapFree(GetProcessHeap(),0,package
->CommitAction
);
618 HeapFree(GetProcessHeap(),0,package
->PackagePath
);
621 static void ui_progress(MSIPACKAGE
*package
, int a
, int b
, int c
, int d
)
625 row
= MSI_CreateRecord(4);
626 MSI_RecordSetInteger(row
,1,a
);
627 MSI_RecordSetInteger(row
,2,b
);
628 MSI_RecordSetInteger(row
,3,c
);
629 MSI_RecordSetInteger(row
,4,d
);
630 MSI_ProcessMessage(package
, INSTALLMESSAGE_PROGRESS
, row
);
631 msiobj_release(&row
->hdr
);
633 msi_dialog_check_messages(package
->dialog
, NULL
);
636 static void ui_actiondata(MSIPACKAGE
*package
, LPCWSTR action
, MSIRECORD
* record
)
638 static const WCHAR Query_t
[] =
639 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
640 'A','c','t','i','o', 'n','T','e','x','t',' ','W','H','E','R','E',' ',
641 'A','c','t','i','o','n',' ','=', ' ','\'','%','s','\'',0};
648 if (!package
->LastAction
|| strcmpW(package
->LastAction
,action
))
650 rc
= MSI_OpenQuery(package
->db
, &view
, Query_t
, action
);
651 if (rc
!= ERROR_SUCCESS
)
654 rc
= MSI_ViewExecute(view
, 0);
655 if (rc
!= ERROR_SUCCESS
)
660 rc
= MSI_ViewFetch(view
,&row
);
661 if (rc
!= ERROR_SUCCESS
)
667 if (MSI_RecordIsNull(row
,3))
669 msiobj_release(&row
->hdr
);
671 msiobj_release(&view
->hdr
);
675 /* update the cached actionformat */
676 HeapFree(GetProcessHeap(),0,package
->ActionFormat
);
677 package
->ActionFormat
= load_dynamic_stringW(row
,3);
679 HeapFree(GetProcessHeap(),0,package
->LastAction
);
680 package
->LastAction
= dupstrW(action
);
682 msiobj_release(&row
->hdr
);
684 msiobj_release(&view
->hdr
);
687 MSI_RecordSetStringW(record
,0,package
->ActionFormat
);
689 MSI_FormatRecordW(package
,record
,message
,&size
);
691 row
= MSI_CreateRecord(1);
692 MSI_RecordSetStringW(row
,1,message
);
694 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, row
);
695 msiobj_release(&row
->hdr
);
699 static void ui_actionstart(MSIPACKAGE
*package
, LPCWSTR action
)
701 static const WCHAR template_s
[]=
702 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ', '%','s',
704 static const WCHAR format
[] =
705 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
706 static const WCHAR Query_t
[] =
707 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
708 'A','c','t','i','o', 'n','T','e','x','t',' ','W','H','E','R','E', ' ',
709 'A','c','t','i','o','n',' ','=', ' ','\'','%','s','\'',0};
715 WCHAR
*ActionText
=NULL
;
717 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
719 rc
= MSI_OpenQuery(package
->db
, &view
, Query_t
, action
);
720 if (rc
!= ERROR_SUCCESS
)
722 rc
= MSI_ViewExecute(view
, 0);
723 if (rc
!= ERROR_SUCCESS
)
726 msiobj_release(&view
->hdr
);
729 rc
= MSI_ViewFetch(view
,&row
);
730 if (rc
!= ERROR_SUCCESS
)
733 msiobj_release(&view
->hdr
);
737 ActionText
= load_dynamic_stringW(row
,2);
738 msiobj_release(&row
->hdr
);
740 msiobj_release(&view
->hdr
);
742 sprintfW(message
,template_s
,timet
,action
,ActionText
);
744 row
= MSI_CreateRecord(1);
745 MSI_RecordSetStringW(row
,1,message
);
747 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONSTART
, row
);
748 msiobj_release(&row
->hdr
);
749 HeapFree(GetProcessHeap(),0,ActionText
);
752 static void ui_actioninfo(MSIPACKAGE
*package
, LPCWSTR action
, BOOL start
,
756 static const WCHAR template_s
[]=
757 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ',
759 static const WCHAR template_e
[]=
760 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ',
761 '%','s', '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ',
763 static const WCHAR format
[] =
764 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
768 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
770 sprintfW(message
,template_s
,timet
,action
);
772 sprintfW(message
,template_e
,timet
,action
,rc
);
774 row
= MSI_CreateRecord(1);
775 MSI_RecordSetStringW(row
,1,message
);
777 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
, row
);
778 msiobj_release(&row
->hdr
);
782 * build_directory_name()
784 * This function is to save messing round with directory names
785 * It handles adding backslashes between path segments,
786 * and can add \ at the end of the directory name if told to.
788 * It takes a variable number of arguments.
789 * It always allocates a new string for the result, so make sure
790 * to free the return value when finished with it.
792 * The first arg is the number of path segments that follow.
793 * The arguments following count are a list of path segments.
794 * A path segment may be NULL.
796 * Path segments will be added with a \ separating them.
797 * A \ will not be added after the last segment, however if the
798 * last segment is NULL, then the last character will be a \
801 static LPWSTR
build_directory_name(DWORD count
, ...)
808 for(i
=0; i
<count
; i
++)
810 LPCWSTR str
= va_arg(va
,LPCWSTR
);
812 sz
+= strlenW(str
) + 1;
816 dir
= HeapAlloc(GetProcessHeap(), 0, sz
*sizeof(WCHAR
));
820 for(i
=0; i
<count
; i
++)
822 LPCWSTR str
= va_arg(va
,LPCWSTR
);
826 if( ((i
+1)!=count
) && dir
[strlenW(dir
)-1]!='\\')
832 static BOOL
ACTION_VerifyComponentForAction(MSIPACKAGE
* package
, INT index
,
835 if (package
->components
[index
].Installed
== check
)
838 if (package
->components
[index
].ActionRequest
== check
)
844 static BOOL
ACTION_VerifyFeatureForAction(MSIPACKAGE
* package
, INT index
,
847 if (package
->features
[index
].Installed
== check
)
850 if (package
->features
[index
].ActionRequest
== check
)
857 /****************************************************
858 * TOP level entry points
859 *****************************************************/
861 UINT
ACTION_DoTopLevelINSTALL(MSIPACKAGE
*package
, LPCWSTR szPackagePath
,
862 LPCWSTR szCommandLine
)
867 static const WCHAR szUILevel
[] = {'U','I','L','e','v','e','l',0};
868 static const WCHAR szAction
[] = {'A','C','T','I','O','N',0};
869 static const WCHAR szInstall
[] = {'I','N','S','T','A','L','L',0};
871 MSI_SetPropertyW(package
, szAction
, szInstall
);
872 package
->ExecuteSequenceRun
= FALSE
;
876 LPWSTR p
, check
, path
;
878 package
->PackagePath
= dupstrW(szPackagePath
);
879 path
= dupstrW(szPackagePath
);
880 p
= strrchrW(path
,'\\');
888 HeapFree(GetProcessHeap(),0,path
);
889 path
= HeapAlloc(GetProcessHeap(),0,MAX_PATH
*sizeof(WCHAR
));
890 GetCurrentDirectoryW(MAX_PATH
,path
);
894 check
= load_dynamic_property(package
, cszSourceDir
,NULL
);
896 MSI_SetPropertyW(package
, cszSourceDir
, path
);
898 HeapFree(GetProcessHeap(), 0, check
);
900 HeapFree(GetProcessHeap(), 0, path
);
906 ptr
= (LPWSTR
)szCommandLine
;
913 TRACE("Looking at %s\n",debugstr_w(ptr
));
915 ptr2
= strchrW(ptr
,'=');
921 while (*ptr
== ' ') ptr
++;
923 prop
= HeapAlloc(GetProcessHeap(),0,(len
+1)*sizeof(WCHAR
));
924 strncpyW(prop
,ptr
,len
);
930 while (*ptr
&& (quote
|| (!quote
&& *ptr
!=' ')))
943 val
= HeapAlloc(GetProcessHeap(),0,(len
+1)*sizeof(WCHAR
));
944 strncpyW(val
,ptr2
,len
);
947 if (strlenW(prop
) > 0)
949 TRACE("Found commandline property (%s) = (%s)\n",
950 debugstr_w(prop
), debugstr_w(val
));
951 MSI_SetPropertyW(package
,prop
,val
);
953 HeapFree(GetProcessHeap(),0,val
);
954 HeapFree(GetProcessHeap(),0,prop
);
961 if (MSI_GetPropertyW(package
,szUILevel
,buffer
,&sz
) == ERROR_SUCCESS
)
963 if (atoiW(buffer
) >= INSTALLUILEVEL_REDUCED
)
965 rc
= ACTION_ProcessUISequence(package
);
966 if (rc
== ERROR_SUCCESS
)
967 rc
= ACTION_ProcessExecSequence(package
,TRUE
);
970 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
973 rc
= ACTION_ProcessExecSequence(package
,FALSE
);
977 /* install was halted but should be considered a success */
981 /* process the ending type action */
982 if (rc
== ERROR_SUCCESS
)
983 ACTION_PerformActionSequence(package
,-1);
984 else if (rc
== ERROR_INSTALL_USEREXIT
)
985 ACTION_PerformActionSequence(package
,-2);
986 else if (rc
== ERROR_FUNCTION_FAILED
)
987 ACTION_PerformActionSequence(package
,-3);
988 else if (rc
== ERROR_INSTALL_SUSPEND
)
989 ACTION_PerformActionSequence(package
,-4);
991 /* finish up running custom actions */
992 ACTION_FinishCustomActions(package
);
997 static UINT
ACTION_PerformActionSequence(MSIPACKAGE
*package
, UINT seq
)
1001 WCHAR buffer
[0x100];
1003 MSIRECORD
* row
= 0;
1004 static const WCHAR ExecSeqQuery
[] =
1005 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1006 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1007 'S','e','q','u','e','n','c','e',' ', 'W','H','E','R','E',' ',
1008 'S','e','q','u','e','n','c','e',' ', '=',' ','%','i',0};
1010 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, seq
);
1012 if (rc
== ERROR_SUCCESS
)
1014 rc
= MSI_ViewExecute(view
, 0);
1016 if (rc
!= ERROR_SUCCESS
)
1018 MSI_ViewClose(view
);
1019 msiobj_release(&view
->hdr
);
1023 TRACE("Running the actions\n");
1025 rc
= MSI_ViewFetch(view
,&row
);
1026 if (rc
!= ERROR_SUCCESS
)
1032 /* check conditions */
1033 if (!MSI_RecordIsNull(row
,2))
1036 cond
= load_dynamic_stringW(row
,2);
1040 /* this is a hack to skip errors in the condition code */
1041 if (MSI_EvaluateConditionW(package
, cond
) == MSICONDITION_FALSE
)
1043 HeapFree(GetProcessHeap(),0,cond
);
1044 msiobj_release(&row
->hdr
);
1048 HeapFree(GetProcessHeap(),0,cond
);
1053 rc
= MSI_RecordGetStringW(row
,1,buffer
,&sz
);
1054 if (rc
!= ERROR_SUCCESS
)
1056 ERR("Error is %x\n",rc
);
1057 msiobj_release(&row
->hdr
);
1061 rc
= ACTION_PerformAction(package
,buffer
);
1062 msiobj_release(&row
->hdr
);
1064 MSI_ViewClose(view
);
1065 msiobj_release(&view
->hdr
);
1073 static UINT
ACTION_ProcessExecSequence(MSIPACKAGE
*package
, BOOL UIran
)
1077 static const WCHAR ExecSeqQuery
[] =
1078 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1079 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
1080 'S','e','q','u','e','n','c','e',' ', 'W','H','E','R','E',' ',
1081 'S','e','q','u','e','n','c','e',' ', '>',' ','%','i',' ',
1082 'O','R','D','E','R',' ', 'B','Y',' ',
1083 'S','e','q','u','e','n','c','e',0 };
1084 MSIRECORD
* row
= 0;
1085 static const WCHAR IVQuery
[] =
1086 {'S','E','L','E','C','T',' ','S','e','q','u','e','n','c','e',' ',
1087 'F','R','O','M',' ','I','n','s','t','a','l','l',
1088 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
1089 'W','H','E','R','E',' ','A','c','t','i','o','n',' ','=',' ','`',
1090 'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`', 0};
1094 if (package
->ExecuteSequenceRun
)
1096 TRACE("Execute Sequence already Run\n");
1097 return ERROR_SUCCESS
;
1100 package
->ExecuteSequenceRun
= TRUE
;
1102 /* get the sequence number */
1105 rc
= MSI_DatabaseOpenViewW(package
->db
, IVQuery
, &view
);
1106 if (rc
!= ERROR_SUCCESS
)
1108 rc
= MSI_ViewExecute(view
, 0);
1109 if (rc
!= ERROR_SUCCESS
)
1111 MSI_ViewClose(view
);
1112 msiobj_release(&view
->hdr
);
1115 rc
= MSI_ViewFetch(view
,&row
);
1116 if (rc
!= ERROR_SUCCESS
)
1118 MSI_ViewClose(view
);
1119 msiobj_release(&view
->hdr
);
1122 seq
= MSI_RecordGetInteger(row
,1);
1123 msiobj_release(&row
->hdr
);
1124 MSI_ViewClose(view
);
1125 msiobj_release(&view
->hdr
);
1128 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, seq
);
1129 if (rc
== ERROR_SUCCESS
)
1131 rc
= MSI_ViewExecute(view
, 0);
1133 if (rc
!= ERROR_SUCCESS
)
1135 MSI_ViewClose(view
);
1136 msiobj_release(&view
->hdr
);
1140 TRACE("Running the actions\n");
1144 WCHAR buffer
[0x100];
1147 rc
= MSI_ViewFetch(view
,&row
);
1148 if (rc
!= ERROR_SUCCESS
)
1154 /* check conditions */
1155 if (!MSI_RecordIsNull(row
,2))
1158 cond
= load_dynamic_stringW(row
,2);
1162 /* this is a hack to skip errors in the condition code */
1163 if (MSI_EvaluateConditionW(package
, cond
) ==
1166 HeapFree(GetProcessHeap(),0,cond
);
1167 msiobj_release(&row
->hdr
);
1171 HeapFree(GetProcessHeap(),0,cond
);
1176 rc
= MSI_RecordGetStringW(row
,1,buffer
,&sz
);
1177 if (rc
!= ERROR_SUCCESS
)
1179 ERR("Error is %x\n",rc
);
1180 msiobj_release(&row
->hdr
);
1184 rc
= ACTION_PerformAction(package
,buffer
);
1186 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
1189 if (rc
!= ERROR_SUCCESS
)
1191 ERR("Execution halted due to error (%i)\n",rc
);
1192 msiobj_release(&row
->hdr
);
1196 msiobj_release(&row
->hdr
);
1199 MSI_ViewClose(view
);
1200 msiobj_release(&view
->hdr
);
1208 static UINT
ACTION_ProcessUISequence(MSIPACKAGE
*package
)
1212 static const WCHAR ExecSeqQuery
[] =
1213 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1214 'I','n','s','t','a','l','l','U','I','S','e','q','u','e','n','c','e',
1215 ' ','W','H','E','R','E',' ', 'S','e','q','u','e','n','c','e',' ',
1216 '>',' ','0',' ','O','R','D','E','R',' ','B','Y',' ',
1217 'S','e','q','u','e','n','c','e',0};
1219 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
1221 if (rc
== ERROR_SUCCESS
)
1223 rc
= MSI_ViewExecute(view
, 0);
1225 if (rc
!= ERROR_SUCCESS
)
1227 MSI_ViewClose(view
);
1228 msiobj_release(&view
->hdr
);
1232 TRACE("Running the actions \n");
1236 WCHAR buffer
[0x100];
1238 MSIRECORD
* row
= 0;
1240 rc
= MSI_ViewFetch(view
,&row
);
1241 if (rc
!= ERROR_SUCCESS
)
1247 /* check conditions */
1248 if (!MSI_RecordIsNull(row
,2))
1251 cond
= load_dynamic_stringW(row
,2);
1255 /* this is a hack to skip errors in the condition code */
1256 if (MSI_EvaluateConditionW(package
, cond
) ==
1259 HeapFree(GetProcessHeap(),0,cond
);
1260 msiobj_release(&row
->hdr
);
1264 HeapFree(GetProcessHeap(),0,cond
);
1269 rc
= MSI_RecordGetStringW(row
,1,buffer
,&sz
);
1270 if (rc
!= ERROR_SUCCESS
)
1272 ERR("Error is %x\n",rc
);
1273 msiobj_release(&row
->hdr
);
1277 rc
= ACTION_PerformUIAction(package
,buffer
);
1279 if (rc
== ERROR_FUNCTION_NOT_CALLED
)
1282 if (rc
!= ERROR_SUCCESS
)
1284 ERR("Execution halted due to error (%i)\n",rc
);
1285 msiobj_release(&row
->hdr
);
1289 msiobj_release(&row
->hdr
);
1292 MSI_ViewClose(view
);
1293 msiobj_release(&view
->hdr
);
1300 /********************************************************
1301 * ACTION helper functions and functions that perform the actions
1302 *******************************************************/
1303 BOOL
ACTION_HandleStandardAction(MSIPACKAGE
*package
, LPCWSTR action
, UINT
* rc
)
1309 while (StandardActions
[i
].action
!= NULL
)
1311 if (strcmpW(StandardActions
[i
].action
, action
)==0)
1313 ui_actioninfo(package
, action
, TRUE
, 0);
1314 ui_actionstart(package
, action
);
1315 if (StandardActions
[i
].handler
)
1317 *rc
= StandardActions
[i
].handler(package
);
1321 FIXME("UNHANDLED Standard Action %s\n",debugstr_w(action
));
1322 *rc
= ERROR_SUCCESS
;
1324 ui_actioninfo(package
, action
, FALSE
, *rc
);
1333 BOOL
ACTION_HandleDialogBox(MSIPACKAGE
*package
, LPCWSTR dialog
, UINT
* rc
)
1338 * for the UI when we get that working
1340 if (ACTION_DialogBox(package,dialog) == ERROR_SUCCESS)
1342 *rc = package->CurrentInstallState;
1349 BOOL
ACTION_HandleCustomAction(MSIPACKAGE
* package
, LPCWSTR action
, UINT
* rc
)
1354 arc
= ACTION_CustomAction(package
,action
,FALSE
);
1356 if (arc
!= ERROR_CALL_NOT_IMPLEMENTED
)
1365 * A lot of actions are really important even if they don't do anything
1366 * explicit... Lots of properties are set at the beginning of the installation
1367 * CostFinalize does a bunch of work to translate the directories and such
1369 * But until I get write access to the database that is hard, so I am going to
1370 * hack it to see if I can get something to run.
1372 UINT
ACTION_PerformAction(MSIPACKAGE
*package
, const WCHAR
*action
)
1374 UINT rc
= ERROR_SUCCESS
;
1377 TRACE("Performing action (%s)\n",debugstr_w(action
));
1379 handled
= ACTION_HandleStandardAction(package
, action
, &rc
);
1382 handled
= ACTION_HandleCustomAction(package
, action
, &rc
);
1386 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action
));
1387 rc
= ERROR_FUNCTION_NOT_CALLED
;
1390 package
->CurrentInstallState
= rc
;
1394 UINT
ACTION_PerformUIAction(MSIPACKAGE
*package
, const WCHAR
*action
)
1396 UINT rc
= ERROR_SUCCESS
;
1397 BOOL handled
= FALSE
;
1399 TRACE("Performing action (%s)\n",debugstr_w(action
));
1401 handled
= ACTION_HandleStandardAction(package
, action
, &rc
);
1404 handled
= ACTION_HandleCustomAction(package
, action
, &rc
);
1407 handled
= ACTION_HandleDialogBox(package
, action
, &rc
);
1409 msi_dialog_check_messages( package
->dialog
, NULL
);
1413 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action
));
1414 rc
= ERROR_FUNCTION_NOT_CALLED
;
1417 package
->CurrentInstallState
= rc
;
1421 /***********************************************************************
1424 * Recursively create all directories in the path.
1426 * shamelessly stolen from setupapi/queue.c
1428 static BOOL
create_full_pathW(const WCHAR
*path
)
1434 new_path
= HeapAlloc(GetProcessHeap(), 0, (strlenW(path
) + 1) *
1437 strcpyW(new_path
, path
);
1439 while((len
= strlenW(new_path
)) && new_path
[len
- 1] == '\\')
1440 new_path
[len
- 1] = 0;
1442 while(!CreateDirectoryW(new_path
, NULL
))
1445 DWORD last_error
= GetLastError();
1446 if(last_error
== ERROR_ALREADY_EXISTS
)
1449 if(last_error
!= ERROR_PATH_NOT_FOUND
)
1455 if(!(slash
= strrchrW(new_path
, '\\')))
1461 len
= slash
- new_path
;
1463 if(!create_full_pathW(new_path
))
1468 new_path
[len
] = '\\';
1471 HeapFree(GetProcessHeap(), 0, new_path
);
1476 * Also we cannot enable/disable components either, so for now I am just going
1477 * to do all the directories for all the components.
1479 static UINT
ACTION_CreateFolders(MSIPACKAGE
*package
)
1481 static const WCHAR ExecSeqQuery
[] =
1482 {'S','E','L','E','C','T',' ','D','i','r','e','c','t','o','r','y','_',
1483 ' ','F','R','O','M',' ',
1484 'C','r','e','a','t','e','F','o','l','d','e','r',0 };
1489 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
1490 if (rc
!= ERROR_SUCCESS
)
1491 return ERROR_SUCCESS
;
1493 rc
= MSI_ViewExecute(view
, 0);
1494 if (rc
!= ERROR_SUCCESS
)
1496 MSI_ViewClose(view
);
1497 msiobj_release(&view
->hdr
);
1506 MSIRECORD
*row
= NULL
, *uirow
;
1508 rc
= MSI_ViewFetch(view
,&row
);
1509 if (rc
!= ERROR_SUCCESS
)
1516 rc
= MSI_RecordGetStringW(row
,1,dir
,&sz
);
1518 if (rc
!= ERROR_SUCCESS
)
1520 ERR("Unable to get folder id \n");
1521 msiobj_release(&row
->hdr
);
1526 full_path
= resolve_folder(package
,dir
,FALSE
,FALSE
,&folder
);
1529 ERR("Unable to resolve folder id %s\n",debugstr_w(dir
));
1530 msiobj_release(&row
->hdr
);
1534 TRACE("Folder is %s\n",debugstr_w(full_path
));
1537 uirow
= MSI_CreateRecord(1);
1538 MSI_RecordSetStringW(uirow
,1,full_path
);
1539 ui_actiondata(package
,szCreateFolders
,uirow
);
1540 msiobj_release( &uirow
->hdr
);
1542 if (folder
->State
== 0)
1543 create_full_pathW(full_path
);
1547 msiobj_release(&row
->hdr
);
1548 HeapFree(GetProcessHeap(),0,full_path
);
1550 MSI_ViewClose(view
);
1551 msiobj_release(&view
->hdr
);
1556 static int load_component(MSIPACKAGE
* package
, MSIRECORD
* row
)
1558 int index
= package
->loaded_components
;
1561 /* fill in the data */
1563 package
->loaded_components
++;
1564 if (package
->loaded_components
== 1)
1565 package
->components
= HeapAlloc(GetProcessHeap(),0,
1566 sizeof(MSICOMPONENT
));
1568 package
->components
= HeapReAlloc(GetProcessHeap(),0,
1569 package
->components
, package
->loaded_components
*
1570 sizeof(MSICOMPONENT
));
1572 memset(&package
->components
[index
],0,sizeof(MSICOMPONENT
));
1575 MSI_RecordGetStringW(row
,1,package
->components
[index
].Component
,&sz
);
1577 TRACE("Loading Component %s\n",
1578 debugstr_w(package
->components
[index
].Component
));
1581 if (!MSI_RecordIsNull(row
,2))
1582 MSI_RecordGetStringW(row
,2,package
->components
[index
].ComponentId
,&sz
);
1585 MSI_RecordGetStringW(row
,3,package
->components
[index
].Directory
,&sz
);
1587 package
->components
[index
].Attributes
= MSI_RecordGetInteger(row
,4);
1590 MSI_RecordGetStringW(row
,5,package
->components
[index
].Condition
,&sz
);
1593 MSI_RecordGetStringW(row
,6,package
->components
[index
].KeyPath
,&sz
);
1595 package
->components
[index
].Installed
= INSTALLSTATE_UNKNOWN
;
1596 package
->components
[index
].Action
= INSTALLSTATE_UNKNOWN
;
1597 package
->components
[index
].ActionRequest
= INSTALLSTATE_UNKNOWN
;
1599 package
->components
[index
].Enabled
= TRUE
;
1604 static void load_feature(MSIPACKAGE
* package
, MSIRECORD
* row
)
1606 int index
= package
->loaded_features
;
1608 static const WCHAR Query1
[] =
1609 {'S','E','L','E','C','T',' ','C','o','m','p','o','n','e','n','t','_',
1610 ' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1611 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ',
1612 'F','e', 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1613 static const WCHAR Query2
[] =
1614 {'S','E','L','E','C','T',' ','*',' ','F','R', 'O','M',' ',
1615 'C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ',
1616 'C','o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1623 /* fill in the data */
1625 package
->loaded_features
++;
1626 if (package
->loaded_features
== 1)
1627 package
->features
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE
));
1629 package
->features
= HeapReAlloc(GetProcessHeap(),0,package
->features
,
1630 package
->loaded_features
* sizeof(MSIFEATURE
));
1632 memset(&package
->features
[index
],0,sizeof(MSIFEATURE
));
1635 MSI_RecordGetStringW(row
,1,package
->features
[index
].Feature
,&sz
);
1637 TRACE("Loading feature %s\n",debugstr_w(package
->features
[index
].Feature
));
1640 if (!MSI_RecordIsNull(row
,2))
1641 MSI_RecordGetStringW(row
,2,package
->features
[index
].Feature_Parent
,&sz
);
1644 if (!MSI_RecordIsNull(row
,3))
1645 MSI_RecordGetStringW(row
,3,package
->features
[index
].Title
,&sz
);
1648 if (!MSI_RecordIsNull(row
,4))
1649 MSI_RecordGetStringW(row
,4,package
->features
[index
].Description
,&sz
);
1651 if (!MSI_RecordIsNull(row
,5))
1652 package
->features
[index
].Display
= MSI_RecordGetInteger(row
,5);
1654 package
->features
[index
].Level
= MSI_RecordGetInteger(row
,6);
1657 if (!MSI_RecordIsNull(row
,7))
1658 MSI_RecordGetStringW(row
,7,package
->features
[index
].Directory
,&sz
);
1660 package
->features
[index
].Attributes
= MSI_RecordGetInteger(row
,8);
1662 package
->features
[index
].Installed
= INSTALLSTATE_UNKNOWN
;
1663 package
->features
[index
].Action
= INSTALLSTATE_UNKNOWN
;
1664 package
->features
[index
].ActionRequest
= INSTALLSTATE_UNKNOWN
;
1666 /* load feature components */
1668 rc
= MSI_OpenQuery(package
->db
, &view
, Query1
, package
->features
[index
].Feature
);
1669 if (rc
!= ERROR_SUCCESS
)
1671 rc
= MSI_ViewExecute(view
,0);
1672 if (rc
!= ERROR_SUCCESS
)
1674 MSI_ViewClose(view
);
1675 msiobj_release(&view
->hdr
);
1681 WCHAR buffer
[0x100];
1684 INT cnt
= package
->features
[index
].ComponentCount
;
1686 rc
= MSI_ViewFetch(view
,&row2
);
1687 if (rc
!= ERROR_SUCCESS
)
1691 MSI_RecordGetStringW(row2
,1,buffer
,&sz
);
1693 /* check to see if the component is already loaded */
1694 c_indx
= get_loaded_component(package
,buffer
);
1697 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer
),
1699 package
->features
[index
].Components
[cnt
] = c_indx
;
1700 package
->features
[index
].ComponentCount
++;
1704 rc
= MSI_OpenQuery(package
->db
, &view2
, Query2
, buffer
);
1705 if (rc
!= ERROR_SUCCESS
)
1707 msiobj_release( &row2
->hdr
);
1710 rc
= MSI_ViewExecute(view2
,0);
1711 if (rc
!= ERROR_SUCCESS
)
1713 msiobj_release( &row2
->hdr
);
1714 MSI_ViewClose(view2
);
1715 msiobj_release( &view2
->hdr
);
1722 rc
= MSI_ViewFetch(view2
,&row3
);
1723 if (rc
!= ERROR_SUCCESS
)
1725 c_indx
= load_component(package
,row3
);
1726 msiobj_release( &row3
->hdr
);
1728 package
->features
[index
].Components
[cnt
] = c_indx
;
1729 package
->features
[index
].ComponentCount
++;
1730 TRACE("Loaded new component to index %i\n",c_indx
);
1732 MSI_ViewClose(view2
);
1733 msiobj_release( &view2
->hdr
);
1734 msiobj_release( &row2
->hdr
);
1736 MSI_ViewClose(view
);
1737 msiobj_release(&view
->hdr
);
1741 * I am not doing any of the costing functionality yet.
1742 * Mostly looking at doing the Component and Feature loading
1744 * The native MSI does A LOT of modification to tables here. Mostly adding
1745 * a lot of temporary columns to the Feature and Component tables.
1747 * note: Native msi also tracks the short filename. But I am only going to
1748 * track the long ones. Also looking at this directory table
1749 * it appears that the directory table does not get the parents
1750 * resolved base on property only based on their entries in the
1753 static UINT
ACTION_CostInitialize(MSIPACKAGE
*package
)
1758 static const WCHAR Query_all
[] =
1759 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1760 'F','e','a','t','u','r','e',0};
1761 static const WCHAR szCosting
[] =
1762 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1763 static const WCHAR szZero
[] = { '0', 0 };
1765 MSI_SetPropertyW(package
, szCosting
, szZero
);
1766 MSI_SetPropertyW(package
, cszRootDrive
, c_colon
);
1768 rc
= MSI_DatabaseOpenViewW(package
->db
,Query_all
,&view
);
1769 if (rc
!= ERROR_SUCCESS
)
1771 rc
= MSI_ViewExecute(view
,0);
1772 if (rc
!= ERROR_SUCCESS
)
1774 MSI_ViewClose(view
);
1775 msiobj_release(&view
->hdr
);
1782 rc
= MSI_ViewFetch(view
,&row
);
1783 if (rc
!= ERROR_SUCCESS
)
1786 load_feature(package
,row
);
1787 msiobj_release(&row
->hdr
);
1789 MSI_ViewClose(view
);
1790 msiobj_release(&view
->hdr
);
1792 return ERROR_SUCCESS
;
1795 static UINT
load_file(MSIPACKAGE
* package
, MSIRECORD
* row
)
1797 DWORD index
= package
->loaded_files
;
1801 /* fill in the data */
1803 package
->loaded_files
++;
1804 if (package
->loaded_files
== 1)
1805 package
->files
= HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE
));
1807 package
->files
= HeapReAlloc(GetProcessHeap(),0,
1808 package
->files
, package
->loaded_files
* sizeof(MSIFILE
));
1810 memset(&package
->files
[index
],0,sizeof(MSIFILE
));
1812 package
->files
[index
].File
= load_dynamic_stringW(row
, 1);
1813 buffer
= load_dynamic_stringW(row
, 2);
1815 package
->files
[index
].ComponentIndex
= -1;
1816 for (i
= 0; i
< package
->loaded_components
; i
++)
1817 if (strcmpW(package
->components
[i
].Component
,buffer
)==0)
1819 package
->files
[index
].ComponentIndex
= i
;
1822 if (package
->files
[index
].ComponentIndex
== -1)
1823 ERR("Unfound Component %s\n",debugstr_w(buffer
));
1824 HeapFree(GetProcessHeap(), 0, buffer
);
1826 package
->files
[index
].FileName
= load_dynamic_stringW(row
,3);
1828 reduce_to_longfilename(package
->files
[index
].FileName
);
1830 package
->files
[index
].FileSize
= MSI_RecordGetInteger(row
,4);
1831 package
->files
[index
].Version
= load_dynamic_stringW(row
, 5);
1832 package
->files
[index
].Language
= load_dynamic_stringW(row
, 6);
1833 package
->files
[index
].Attributes
= MSI_RecordGetInteger(row
,7);
1834 package
->files
[index
].Sequence
= MSI_RecordGetInteger(row
,8);
1836 package
->files
[index
].Temporary
= FALSE
;
1837 package
->files
[index
].State
= 0;
1839 TRACE("File Loaded (%s)\n",debugstr_w(package
->files
[index
].File
));
1841 return ERROR_SUCCESS
;
1844 static UINT
ACTION_FileCost(MSIPACKAGE
*package
)
1849 static const WCHAR Query
[] =
1850 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
1851 'F','i','l','e',' ', 'O','R','D','E','R',' ','B','Y',' ',
1852 'S','e','q','u','e','n','c','e', 0};
1855 return ERROR_INVALID_HANDLE
;
1857 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1858 if (rc
!= ERROR_SUCCESS
)
1859 return ERROR_SUCCESS
;
1861 rc
= MSI_ViewExecute(view
, 0);
1862 if (rc
!= ERROR_SUCCESS
)
1864 MSI_ViewClose(view
);
1865 msiobj_release(&view
->hdr
);
1866 return ERROR_SUCCESS
;
1871 rc
= MSI_ViewFetch(view
,&row
);
1872 if (rc
!= ERROR_SUCCESS
)
1877 load_file(package
,row
);
1878 msiobj_release(&row
->hdr
);
1880 MSI_ViewClose(view
);
1881 msiobj_release(&view
->hdr
);
1883 return ERROR_SUCCESS
;
1886 static INT
load_folder(MSIPACKAGE
*package
, const WCHAR
* dir
)
1888 static const WCHAR Query
[] =
1889 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1890 'D','i','r','e','c', 't','o','r','y',' ','W','H','E','R','E',' ','`',
1891 'D','i','r','e','c','t', 'o','r','y','`',' ','=',' ','`','%','s','`',
1895 LPWSTR targetdir
, parent
, srcdir
;
1896 MSIRECORD
* row
= 0;
1900 TRACE("Looking for dir %s\n",debugstr_w(dir
));
1902 for (i
= 0; i
< package
->loaded_folders
; i
++)
1904 if (strcmpW(package
->folders
[i
].Directory
,dir
)==0)
1906 TRACE(" %s retuning on index %lu\n",debugstr_w(dir
),i
);
1911 TRACE("Working to load %s\n",debugstr_w(dir
));
1913 index
= package
->loaded_folders
++;
1914 if (package
->loaded_folders
==1)
1915 package
->folders
= HeapAlloc(GetProcessHeap(),0,
1918 package
->folders
= HeapReAlloc(GetProcessHeap(),0,
1919 package
->folders
, package
->loaded_folders
*
1922 memset(&package
->folders
[index
],0,sizeof(MSIFOLDER
));
1924 package
->folders
[index
].Directory
= dupstrW(dir
);
1926 rc
= MSI_OpenQuery(package
->db
, &view
, Query
, dir
);
1927 if (rc
!= ERROR_SUCCESS
)
1930 rc
= MSI_ViewExecute(view
, 0);
1931 if (rc
!= ERROR_SUCCESS
)
1933 MSI_ViewClose(view
);
1934 msiobj_release(&view
->hdr
);
1938 rc
= MSI_ViewFetch(view
,&row
);
1939 if (rc
!= ERROR_SUCCESS
)
1941 MSI_ViewClose(view
);
1942 msiobj_release(&view
->hdr
);
1946 targetdir
= load_dynamic_stringW(row
,3);
1948 /* split src and target dir */
1949 if (strchrW(targetdir
,':'))
1951 srcdir
=strchrW(targetdir
,':');
1958 /* for now only pick long filename versions */
1959 if (strchrW(targetdir
,'|'))
1961 targetdir
= strchrW(targetdir
,'|');
1965 if (srcdir
&& strchrW(srcdir
,'|'))
1967 srcdir
= strchrW(srcdir
,'|');
1972 /* now check for root dirs */
1973 if (targetdir
[0] == '.' && targetdir
[1] == 0)
1976 if (srcdir
&& srcdir
[0] == '.' && srcdir
[1] == 0)
1981 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir
));
1982 HeapFree(GetProcessHeap(),0, package
->folders
[index
].TargetDefault
);
1983 package
->folders
[index
].TargetDefault
= dupstrW(targetdir
);
1987 package
->folders
[index
].SourceDefault
= dupstrW(srcdir
);
1989 package
->folders
[index
].SourceDefault
= dupstrW(targetdir
);
1990 HeapFree(GetProcessHeap(), 0, targetdir
);
1992 parent
= load_dynamic_stringW(row
,2);
1995 i
= load_folder(package
,parent
);
1996 package
->folders
[index
].ParentIndex
= i
;
1997 TRACE("Parent is index %i... %s %s\n",
1998 package
->folders
[index
].ParentIndex
,
1999 debugstr_w(package
->folders
[package
->folders
[index
].ParentIndex
].Directory
),
2000 debugstr_w(parent
));
2003 package
->folders
[index
].ParentIndex
= -2;
2004 HeapFree(GetProcessHeap(), 0, parent
);
2006 package
->folders
[index
].Property
= load_dynamic_property(package
, dir
,NULL
);
2008 msiobj_release(&row
->hdr
);
2009 MSI_ViewClose(view
);
2010 msiobj_release(&view
->hdr
);
2011 TRACE(" %s retuning on index %i\n",debugstr_w(dir
),index
);
2016 LPWSTR
resolve_folder(MSIPACKAGE
*package
, LPCWSTR name
, BOOL source
,
2017 BOOL set_prop
, MSIFOLDER
**folder
)
2020 LPWSTR p
, path
= NULL
;
2022 TRACE("Working to resolve %s\n",debugstr_w(name
));
2024 /* special resolving for Target and Source root dir */
2025 if (strcmpW(name
,cszTargetDir
)==0 || strcmpW(name
,cszSourceDir
)==0)
2029 path
= load_dynamic_property(package
,cszTargetDir
,NULL
);
2032 path
= load_dynamic_property(package
,cszRootDrive
,NULL
);
2034 MSI_SetPropertyW(package
,cszTargetDir
,path
);
2038 for (i
= 0; i
< package
->loaded_folders
; i
++)
2040 if (strcmpW(package
->folders
[i
].Directory
,name
)==0)
2043 *folder
= &(package
->folders
[i
]);
2049 path
= load_dynamic_property(package
,cszSourceDir
,NULL
);
2052 path
= load_dynamic_property(package
,cszDatabase
,NULL
);
2055 p
= strrchrW(path
,'\\');
2062 for (i
= 0; i
< package
->loaded_folders
; i
++)
2064 if (strcmpW(package
->folders
[i
].Directory
,name
)==0)
2067 *folder
= &(package
->folders
[i
]);
2073 for (i
= 0; i
< package
->loaded_folders
; i
++)
2075 if (strcmpW(package
->folders
[i
].Directory
,name
)==0)
2079 if (i
>= package
->loaded_folders
)
2083 *folder
= &(package
->folders
[i
]);
2085 if (!source
&& package
->folders
[i
].ResolvedTarget
)
2087 path
= dupstrW(package
->folders
[i
].ResolvedTarget
);
2088 TRACE(" already resolved to %s\n",debugstr_w(path
));
2091 else if (source
&& package
->folders
[i
].ResolvedSource
)
2093 path
= dupstrW(package
->folders
[i
].ResolvedSource
);
2096 else if (!source
&& package
->folders
[i
].Property
)
2098 path
= build_directory_name(2, package
->folders
[i
].Property
, NULL
);
2100 TRACE(" internally set to %s\n",debugstr_w(path
));
2102 MSI_SetPropertyW(package
,name
,path
);
2106 if (package
->folders
[i
].ParentIndex
>= 0)
2108 LPWSTR parent
= package
->folders
[package
->folders
[i
].ParentIndex
].Directory
;
2110 TRACE(" ! Parent is %s\n", debugstr_w(parent
));
2112 p
= resolve_folder(package
, parent
, source
, set_prop
, NULL
);
2115 TRACE(" TargetDefault = %s\n",debugstr_w(package
->folders
[i
].TargetDefault
));
2116 path
= build_directory_name(3, p
, package
->folders
[i
].TargetDefault
, NULL
);
2117 package
->folders
[i
].ResolvedTarget
= dupstrW(path
);
2118 TRACE(" resolved into %s\n",debugstr_w(path
));
2120 MSI_SetPropertyW(package
,name
,path
);
2124 path
= build_directory_name(3, p
, package
->folders
[i
].SourceDefault
, NULL
);
2125 package
->folders
[i
].ResolvedSource
= dupstrW(path
);
2127 HeapFree(GetProcessHeap(),0,p
);
2132 /* scan for and update current install states */
2133 void ACTION_UpdateInstallStates(MSIPACKAGE
*package
)
2138 productcode
= load_dynamic_property(package
,szProductCode
,NULL
);
2140 for (i
= 0; i
< package
->loaded_components
; i
++)
2143 res
= MsiGetComponentPathW(productcode
,
2144 package
->components
[i
].ComponentId
, NULL
, NULL
);
2146 res
= INSTALLSTATE_ABSENT
;
2147 package
->components
[i
].Installed
= res
;
2150 for (i
= 0; i
< package
->loaded_features
; i
++)
2152 INSTALLSTATE res
= -10;
2154 for (j
= 0; j
< package
->features
[i
].ComponentCount
; j
++)
2156 MSICOMPONENT
* component
= &package
->components
[package
->features
[i
].
2159 res
= component
->Installed
;
2162 if (res
== component
->Installed
)
2165 if (res
!= component
->Installed
)
2166 res
= INSTALLSTATE_INCOMPLETE
;
2172 /* update compoennt state based on a feature change */
2173 void ACTION_UpdateComponentStates(MSIPACKAGE
*package
, LPCWSTR szFeature
)
2176 INSTALLSTATE newstate
;
2177 MSIFEATURE
*feature
;
2179 i
= get_loaded_feature(package
,szFeature
);
2183 feature
= &package
->features
[i
];
2184 newstate
= feature
->ActionRequest
;
2186 for( i
= 0; i
< feature
->ComponentCount
; i
++)
2188 MSICOMPONENT
* component
= &package
->components
[feature
->Components
[i
]];
2190 if (!component
->Enabled
)
2194 if (newstate
== INSTALLSTATE_LOCAL
)
2195 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
2200 component
->ActionRequest
= newstate
;
2202 /*if any other feature wants is local we need to set it local*/
2204 j
< package
->loaded_features
&&
2205 component
->ActionRequest
!= INSTALLSTATE_LOCAL
;
2208 for (k
= 0; k
< package
->features
[j
].ComponentCount
; k
++)
2209 if ( package
->features
[j
].Components
[k
] ==
2210 feature
->Components
[i
] )
2212 if (package
->features
[j
].ActionRequest
==
2214 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
2223 static BOOL
process_state_property (MSIPACKAGE
* package
, LPCWSTR property
,
2226 static const WCHAR all
[]={'A','L','L',0};
2227 LPWSTR override
= NULL
;
2231 override
= load_dynamic_property(package
, property
, NULL
);
2235 for(i
= 0; i
< package
->loaded_features
; i
++)
2237 if (strcmpiW(override
,all
)==0)
2239 package
->features
[i
].ActionRequest
= state
;
2240 package
->features
[i
].Action
= state
;
2244 LPWSTR ptr
= override
;
2245 LPWSTR ptr2
= strchrW(override
,',');
2250 strncmpW(ptr
,package
->features
[i
].Feature
, ptr2
-ptr
)==0)
2252 strcmpW(ptr
,package
->features
[i
].Feature
)==0))
2254 package
->features
[i
].ActionRequest
= state
;
2255 package
->features
[i
].Action
= state
;
2261 ptr2
= strchrW(ptr
,',');
2268 HeapFree(GetProcessHeap(),0,override
);
2274 static UINT
SetFeatureStates(MSIPACKAGE
*package
)
2280 static const WCHAR szlevel
[] =
2281 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2282 static const WCHAR szAddLocal
[] =
2283 {'A','D','D','L','O','C','A','L',0};
2284 static const WCHAR szRemove
[] =
2285 {'R','E','M','O','V','E',0};
2286 BOOL override
= FALSE
;
2288 /* I do not know if this is where it should happen.. but */
2290 TRACE("Checking Install Level\n");
2292 level
= load_dynamic_property(package
,szlevel
,NULL
);
2295 install_level
= atoiW(level
);
2296 HeapFree(GetProcessHeap(), 0, level
);
2301 /* ok hereis the _real_ rub
2302 * all these activation/deactiontion things happen in order and things later
2303 * on the list override things earlier on the list.
2304 * 1) INSTALLLEVEL processing
2314 * 11) FILEADDDEFAULT
2315 * I have confirmed this if ADDLOCALis stated then the INSTALLLEVEL is
2316 * itnored for all the features. seems strange, epsecially since it is not
2317 * documented anywhere, but it is how it works.
2319 * I am still ignoring alot of these. But that is ok for now, ADDLOCAL and
2320 * REMOVE are the big ones, since we dont handle administrative installs yet
2323 override
|= process_state_property(package
,szAddLocal
,INSTALLSTATE_LOCAL
);
2324 override
|= process_state_property(package
,szRemove
,INSTALLSTATE_ABSENT
);
2328 for(i
= 0; i
< package
->loaded_features
; i
++)
2330 BOOL feature_state
= ((package
->features
[i
].Level
> 0) &&
2331 (package
->features
[i
].Level
<= install_level
));
2335 package
->features
[i
].ActionRequest
= INSTALLSTATE_LOCAL
;
2336 package
->features
[i
].Action
= INSTALLSTATE_LOCAL
;
2342 * now we want to enable or disable components base on feature
2345 for(i
= 0; i
< package
->loaded_features
; i
++)
2347 MSIFEATURE
* feature
= &package
->features
[i
];
2348 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2349 debugstr_w(feature
->Feature
), feature
->Installed
, feature
->Action
,
2350 feature
->ActionRequest
);
2352 for( j
= 0; j
< feature
->ComponentCount
; j
++)
2354 MSICOMPONENT
* component
= &package
->components
[
2355 feature
->Components
[j
]];
2357 if (!component
->Enabled
)
2359 component
->Action
= INSTALLSTATE_UNKNOWN
;
2360 component
->ActionRequest
= INSTALLSTATE_UNKNOWN
;
2364 if (feature
->Action
== INSTALLSTATE_LOCAL
)
2366 component
->Action
= INSTALLSTATE_LOCAL
;
2367 component
->ActionRequest
= INSTALLSTATE_LOCAL
;
2369 else if (feature
->ActionRequest
== INSTALLSTATE_ABSENT
)
2371 if (component
->Action
== INSTALLSTATE_UNKNOWN
)
2373 component
->Action
= INSTALLSTATE_ABSENT
;
2374 component
->ActionRequest
= INSTALLSTATE_ABSENT
;
2381 for(i
= 0; i
< package
->loaded_components
; i
++)
2383 MSICOMPONENT
* component
= &package
->components
[i
];
2385 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2386 debugstr_w(component
->Component
), component
->Installed
,
2387 component
->Action
, component
->ActionRequest
);
2391 return ERROR_SUCCESS
;
2395 * A lot is done in this function aside from just the costing.
2396 * The costing needs to be implemented at some point but for now I am going
2397 * to focus on the directory building
2400 static UINT
ACTION_CostFinalize(MSIPACKAGE
*package
)
2402 static const WCHAR ExecSeqQuery
[] =
2403 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2404 'D','i','r','e','c','t','o','r','y',0};
2405 static const WCHAR ConditionQuery
[] =
2406 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2407 'C','o','n','d','i','t','i','o','n',0};
2408 static const WCHAR szCosting
[] =
2409 {'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2410 static const WCHAR szlevel
[] =
2411 {'I','N','S','T','A','L','L','L','E','V','E','L',0};
2412 static const WCHAR szOne
[] = { '1', 0 };
2418 TRACE("Building Directory properties\n");
2420 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
2421 if (rc
== ERROR_SUCCESS
)
2423 rc
= MSI_ViewExecute(view
, 0);
2424 if (rc
!= ERROR_SUCCESS
)
2426 MSI_ViewClose(view
);
2427 msiobj_release(&view
->hdr
);
2435 MSIRECORD
* row
= 0;
2438 rc
= MSI_ViewFetch(view
,&row
);
2439 if (rc
!= ERROR_SUCCESS
)
2446 MSI_RecordGetStringW(row
,1,name
,&sz
);
2448 /* This helper function now does ALL the work */
2449 TRACE("Dir %s ...\n",debugstr_w(name
));
2450 load_folder(package
,name
);
2451 path
= resolve_folder(package
,name
,FALSE
,TRUE
,NULL
);
2452 TRACE("resolves to %s\n",debugstr_w(path
));
2453 HeapFree( GetProcessHeap(), 0, path
);
2455 msiobj_release(&row
->hdr
);
2457 MSI_ViewClose(view
);
2458 msiobj_release(&view
->hdr
);
2461 TRACE("File calculations %i files\n",package
->loaded_files
);
2463 for (i
= 0; i
< package
->loaded_files
; i
++)
2465 MSICOMPONENT
* comp
= NULL
;
2466 MSIFILE
* file
= NULL
;
2468 file
= &package
->files
[i
];
2469 if (file
->ComponentIndex
>= 0)
2470 comp
= &package
->components
[file
->ComponentIndex
];
2472 if (file
->Temporary
== TRUE
)
2479 /* calculate target */
2480 p
= resolve_folder(package
, comp
->Directory
, FALSE
, FALSE
, NULL
);
2482 HeapFree(GetProcessHeap(),0,file
->TargetPath
);
2484 TRACE("file %s is named %s\n",
2485 debugstr_w(file
->File
),debugstr_w(file
->FileName
));
2487 file
->TargetPath
= build_directory_name(2, p
, file
->FileName
);
2489 HeapFree(GetProcessHeap(),0,p
);
2491 TRACE("file %s resolves to %s\n",
2492 debugstr_w(file
->File
),debugstr_w(file
->TargetPath
));
2494 if (GetFileAttributesW(file
->TargetPath
) == INVALID_FILE_ATTRIBUTES
)
2497 comp
->Cost
+= file
->FileSize
;
2507 static const WCHAR name
[] =
2509 static const WCHAR name_fmt
[] =
2510 {'%','u','.','%','u','.','%','u','.','%','u',0};
2511 WCHAR filever
[0x100];
2512 VS_FIXEDFILEINFO
*lpVer
;
2514 TRACE("Version comparison.. \n");
2515 versize
= GetFileVersionInfoSizeW(file
->TargetPath
,&handle
);
2516 version
= HeapAlloc(GetProcessHeap(),0,versize
);
2517 GetFileVersionInfoW(file
->TargetPath
, 0, versize
, version
);
2519 VerQueryValueW(version
, name
, (LPVOID
*)&lpVer
, &sz
);
2521 sprintfW(filever
,name_fmt
,
2522 HIWORD(lpVer
->dwFileVersionMS
),
2523 LOWORD(lpVer
->dwFileVersionMS
),
2524 HIWORD(lpVer
->dwFileVersionLS
),
2525 LOWORD(lpVer
->dwFileVersionLS
));
2527 TRACE("new %s old %s\n", debugstr_w(file
->Version
),
2528 debugstr_w(filever
));
2529 if (strcmpiW(filever
,file
->Version
)<0)
2532 FIXME("cost should be diff in size\n");
2533 comp
->Cost
+= file
->FileSize
;
2537 HeapFree(GetProcessHeap(),0,version
);
2545 TRACE("Evaluating Condition Table\n");
2547 rc
= MSI_DatabaseOpenViewW(package
->db
, ConditionQuery
, &view
);
2548 if (rc
== ERROR_SUCCESS
)
2550 rc
= MSI_ViewExecute(view
, 0);
2551 if (rc
!= ERROR_SUCCESS
)
2553 MSI_ViewClose(view
);
2554 msiobj_release(&view
->hdr
);
2560 WCHAR Feature
[0x100];
2561 MSIRECORD
* row
= 0;
2565 rc
= MSI_ViewFetch(view
,&row
);
2567 if (rc
!= ERROR_SUCCESS
)
2574 MSI_RecordGetStringW(row
,1,Feature
,&sz
);
2576 feature_index
= get_loaded_feature(package
,Feature
);
2577 if (feature_index
< 0)
2578 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature
));
2582 Condition
= load_dynamic_stringW(row
,3);
2584 if (MSI_EvaluateConditionW(package
,Condition
) ==
2587 int level
= MSI_RecordGetInteger(row
,2);
2588 TRACE("Reseting feature %s to level %i\n",
2589 debugstr_w(Feature
), level
);
2590 package
->features
[feature_index
].Level
= level
;
2592 HeapFree(GetProcessHeap(),0,Condition
);
2595 msiobj_release(&row
->hdr
);
2597 MSI_ViewClose(view
);
2598 msiobj_release(&view
->hdr
);
2601 TRACE("Enabling or Disabling Components\n");
2602 for (i
= 0; i
< package
->loaded_components
; i
++)
2604 if (package
->components
[i
].Condition
[0])
2606 if (MSI_EvaluateConditionW(package
,
2607 package
->components
[i
].Condition
) == MSICONDITION_FALSE
)
2609 TRACE("Disabling component %s\n",
2610 debugstr_w(package
->components
[i
].Component
));
2611 package
->components
[i
].Enabled
= FALSE
;
2616 MSI_SetPropertyW(package
,szCosting
,szOne
);
2617 /* set default run level if not set */
2618 level
= load_dynamic_property(package
,szlevel
,NULL
);
2620 MSI_SetPropertyW(package
,szlevel
, szOne
);
2622 HeapFree(GetProcessHeap(),0,level
);
2624 ACTION_UpdateInstallStates(package
);
2626 return SetFeatureStates(package
);
2630 * This is a helper function for handling embedded cabinet media
2632 static UINT
writeout_cabinet_stream(MSIPACKAGE
*package
, WCHAR
* stream_name
,
2640 WCHAR tmp
[MAX_PATH
];
2642 rc
= read_raw_stream_data(package
->db
,stream_name
,&data
,&size
);
2643 if (rc
!= ERROR_SUCCESS
)
2647 if (MSI_GetPropertyW(package
, cszTempFolder
, tmp
, &write
))
2648 GetTempPathW(MAX_PATH
,tmp
);
2650 GetTempFileNameW(tmp
,stream_name
,0,source
);
2652 track_tempfile(package
,strrchrW(source
,'\\'), source
);
2653 the_file
= CreateFileW(source
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
2654 FILE_ATTRIBUTE_NORMAL
, NULL
);
2656 if (the_file
== INVALID_HANDLE_VALUE
)
2658 rc
= ERROR_FUNCTION_FAILED
;
2662 WriteFile(the_file
,data
,size
,&write
,NULL
);
2663 CloseHandle(the_file
);
2664 TRACE("wrote %li bytes to %s\n",write
,debugstr_w(source
));
2666 HeapFree(GetProcessHeap(),0,data
);
2671 /* Support functions for FDI functions */
2674 MSIPACKAGE
* package
;
2679 static void * cabinet_alloc(ULONG cb
)
2681 return HeapAlloc(GetProcessHeap(), 0, cb
);
2684 static void cabinet_free(void *pv
)
2686 HeapFree(GetProcessHeap(), 0, pv
);
2689 static INT_PTR
cabinet_open(char *pszFile
, int oflag
, int pmode
)
2692 DWORD dwShareMode
= 0;
2693 DWORD dwCreateDisposition
= OPEN_EXISTING
;
2694 switch (oflag
& _O_ACCMODE
)
2697 dwAccess
= GENERIC_READ
;
2698 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_DELETE
;
2701 dwAccess
= GENERIC_WRITE
;
2702 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
2705 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
2706 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
2709 if ((oflag
& (_O_CREAT
| _O_EXCL
)) == (_O_CREAT
| _O_EXCL
))
2710 dwCreateDisposition
= CREATE_NEW
;
2711 else if (oflag
& _O_CREAT
)
2712 dwCreateDisposition
= CREATE_ALWAYS
;
2713 return (INT_PTR
)CreateFileA(pszFile
, dwAccess
, dwShareMode
, NULL
,
2714 dwCreateDisposition
, 0, NULL
);
2717 static UINT
cabinet_read(INT_PTR hf
, void *pv
, UINT cb
)
2720 if (ReadFile((HANDLE
)hf
, pv
, cb
, &dwRead
, NULL
))
2725 static UINT
cabinet_write(INT_PTR hf
, void *pv
, UINT cb
)
2728 if (WriteFile((HANDLE
)hf
, pv
, cb
, &dwWritten
, NULL
))
2733 static int cabinet_close(INT_PTR hf
)
2735 return CloseHandle((HANDLE
)hf
) ? 0 : -1;
2738 static long cabinet_seek(INT_PTR hf
, long dist
, int seektype
)
2740 /* flags are compatible and so are passed straight through */
2741 return SetFilePointer((HANDLE
)hf
, dist
, NULL
, seektype
);
2744 static INT_PTR
cabinet_notify(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
2746 /* FIXME: try to do more processing in this function */
2749 case fdintCOPY_FILE
:
2751 CabData
*data
= (CabData
*) pfdin
->pv
;
2752 ULONG len
= strlen(data
->cab_path
) + strlen(pfdin
->psz1
);
2757 LPWSTR tracknametmp
;
2758 static const WCHAR tmpprefix
[] = {'C','A','B','T','M','P','_',0};
2760 if (data
->file_name
&& strcmp(data
->file_name
,pfdin
->psz1
))
2763 file
= cabinet_alloc((len
+1)*sizeof(char));
2764 strcpy(file
, data
->cab_path
);
2765 strcat(file
, pfdin
->psz1
);
2767 TRACE("file: %s\n", debugstr_a(file
));
2769 /* track this file so it can be deleted if not installed */
2770 trackpath
=strdupAtoW(file
);
2771 tracknametmp
=strdupAtoW(strrchr(file
,'\\')+1);
2772 trackname
= HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp
) +
2773 strlenW(tmpprefix
)+1) * sizeof(WCHAR
));
2775 strcpyW(trackname
,tmpprefix
);
2776 strcatW(trackname
,tracknametmp
);
2778 track_tempfile(data
->package
, trackname
, trackpath
);
2780 HeapFree(GetProcessHeap(),0,trackpath
);
2781 HeapFree(GetProcessHeap(),0,trackname
);
2782 HeapFree(GetProcessHeap(),0,tracknametmp
);
2784 return cabinet_open(file
, _O_WRONLY
| _O_CREAT
, 0);
2786 case fdintCLOSE_FILE_INFO
:
2790 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
2792 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
2794 if (!SetFileTime((HANDLE
)pfdin
->hf
, &ftLocal
, 0, &ftLocal
))
2797 cabinet_close(pfdin
->hf
);
2805 /***********************************************************************
2806 * extract_cabinet_file
2808 * Extract files from a cab file.
2810 static BOOL
extract_a_cabinet_file(MSIPACKAGE
* package
, const WCHAR
* source
,
2811 const WCHAR
* path
, const WCHAR
* file
)
2821 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source
),
2822 debugstr_w(file
), debugstr_w(path
));
2824 hfdi
= FDICreate(cabinet_alloc
,
2835 ERR("FDICreate failed\n");
2839 if (!(cabinet
= strdupWtoA( source
)))
2844 if (!(cab_path
= strdupWtoA( path
)))
2847 HeapFree(GetProcessHeap(), 0, cabinet
);
2851 data
.package
= package
;
2852 data
.cab_path
= cab_path
;
2854 file_name
= strdupWtoA(file
);
2857 data
.file_name
= file_name
;
2859 ret
= FDICopy(hfdi
, cabinet
, "", 0, cabinet_notify
, NULL
, &data
);
2862 ERR("FDICopy failed\n");
2866 HeapFree(GetProcessHeap(), 0, cabinet
);
2867 HeapFree(GetProcessHeap(), 0, cab_path
);
2868 HeapFree(GetProcessHeap(), 0, file_name
);
2873 static UINT
ready_media_for_file(MSIPACKAGE
*package
, UINT sequence
,
2874 WCHAR
* path
, WCHAR
* file
)
2878 MSIRECORD
* row
= 0;
2879 static WCHAR source
[MAX_PATH
];
2880 static const WCHAR ExecSeqQuery
[] =
2881 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
2882 'M','e','d','i','a',' ','W','H','E','R','E',' ',
2883 'L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%',
2884 'i',' ','O','R','D','E','R',' ','B','Y',' ',
2885 'L','a','s','t','S','e','q','u','e','n','c','e',0};
2890 static UINT last_sequence
= 0;
2892 if (sequence
<= last_sequence
)
2894 TRACE("Media already ready (%u, %u)\n",sequence
,last_sequence
);
2895 /*extract_a_cabinet_file(package, source,path,file); */
2896 return ERROR_SUCCESS
;
2899 sprintfW(Query
,ExecSeqQuery
,sequence
);
2901 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
2902 if (rc
!= ERROR_SUCCESS
)
2905 rc
= MSI_ViewExecute(view
, 0);
2906 if (rc
!= ERROR_SUCCESS
)
2908 MSI_ViewClose(view
);
2909 msiobj_release(&view
->hdr
);
2913 rc
= MSI_ViewFetch(view
,&row
);
2914 if (rc
!= ERROR_SUCCESS
)
2916 MSI_ViewClose(view
);
2917 msiobj_release(&view
->hdr
);
2920 seq
= MSI_RecordGetInteger(row
,2);
2921 last_sequence
= seq
;
2923 if (!MSI_RecordIsNull(row
,4))
2926 MSI_RecordGetStringW(row
,4,cab
,&sz
);
2927 TRACE("Source is CAB %s\n",debugstr_w(cab
));
2928 /* the stream does not contain the # character */
2931 writeout_cabinet_stream(package
,&cab
[1],source
);
2932 strcpyW(path
,source
);
2933 *(strrchrW(path
,'\\')+1)=0;
2938 if (MSI_GetPropertyW(package
, cszSourceDir
, source
, &sz
))
2940 ERR("No Source dir defined \n");
2941 rc
= ERROR_FUNCTION_FAILED
;
2945 strcpyW(path
,source
);
2946 strcatW(source
,cab
);
2947 /* extract the cab file into a folder in the temp folder */
2949 if (MSI_GetPropertyW(package
, cszTempFolder
,path
, &sz
)
2951 GetTempPathW(MAX_PATH
,path
);
2954 rc
= !extract_a_cabinet_file(package
, source
,path
,NULL
);
2959 MSI_GetPropertyW(package
,cszSourceDir
,source
,&sz
);
2960 strcpyW(path
,source
);
2962 msiobj_release(&row
->hdr
);
2963 MSI_ViewClose(view
);
2964 msiobj_release(&view
->hdr
);
2968 inline static UINT
create_component_directory ( MSIPACKAGE
* package
, INT component
)
2970 UINT rc
= ERROR_SUCCESS
;
2972 LPWSTR install_path
;
2974 install_path
= resolve_folder(package
, package
->components
[component
].Directory
,
2975 FALSE
, FALSE
, &folder
);
2977 return ERROR_FUNCTION_FAILED
;
2979 /* create the path */
2980 if (folder
->State
== 0)
2982 create_full_pathW(install_path
);
2985 HeapFree(GetProcessHeap(), 0, install_path
);
2990 static UINT
ACTION_InstallFiles(MSIPACKAGE
*package
)
2992 UINT rc
= ERROR_SUCCESS
;
2995 WCHAR uipath
[MAX_PATH
];
2998 return ERROR_INVALID_HANDLE
;
3000 /* increment progress bar each time action data is sent */
3001 ui_progress(package
,1,1,0,0);
3003 for (index
= 0; index
< package
->loaded_files
; index
++)
3005 WCHAR path_to_source
[MAX_PATH
];
3008 file
= &package
->files
[index
];
3010 if (file
->Temporary
)
3014 if (!ACTION_VerifyComponentForAction(package
, file
->ComponentIndex
,
3015 INSTALLSTATE_LOCAL
))
3017 ui_progress(package
,2,file
->FileSize
,0,0);
3018 TRACE("File %s is not scheduled for install\n",
3019 debugstr_w(file
->File
));
3024 if ((file
->State
== 1) || (file
->State
== 2))
3028 MSICOMPONENT
* comp
= NULL
;
3030 TRACE("Installing %s\n",debugstr_w(file
->File
));
3031 rc
= ready_media_for_file(package
,file
->Sequence
,path_to_source
,
3035 * our file table could change here because a new temp file
3036 * may have been created
3038 file
= &package
->files
[index
];
3039 if (rc
!= ERROR_SUCCESS
)
3041 ERR("Unable to ready media\n");
3042 rc
= ERROR_FUNCTION_FAILED
;
3046 create_component_directory( package
, file
->ComponentIndex
);
3048 /* recalculate file paths because things may have changed */
3050 if (file
->ComponentIndex
>= 0)
3051 comp
= &package
->components
[file
->ComponentIndex
];
3053 p
= resolve_folder(package
, comp
->Directory
, FALSE
, FALSE
, NULL
);
3054 HeapFree(GetProcessHeap(),0,file
->TargetPath
);
3056 file
->TargetPath
= build_directory_name(2, p
, file
->FileName
);
3058 len
= strlenW(path_to_source
) + strlenW(file
->File
) + 2;
3059 file
->SourcePath
= HeapAlloc(GetProcessHeap(),0,len
*sizeof(WCHAR
));
3060 strcpyW(file
->SourcePath
, path_to_source
);
3061 strcatW(file
->SourcePath
, file
->File
);
3063 TRACE("file paths %s to %s\n",debugstr_w(file
->SourcePath
),
3064 debugstr_w(file
->TargetPath
));
3067 uirow
=MSI_CreateRecord(9);
3068 MSI_RecordSetStringW(uirow
,1,file
->File
);
3069 strcpyW(uipath
,file
->TargetPath
);
3070 *(strrchrW(uipath
,'\\')+1)=0;
3071 MSI_RecordSetStringW(uirow
,9,uipath
);
3072 MSI_RecordSetInteger(uirow
,6,file
->FileSize
);
3073 ui_actiondata(package
,szInstallFiles
,uirow
);
3074 msiobj_release( &uirow
->hdr
);
3075 ui_progress(package
,2,file
->FileSize
,0,0);
3077 if (!MoveFileW(file
->SourcePath
,file
->TargetPath
))
3079 rc
= GetLastError();
3080 ERR("Unable to move file (%s -> %s) (error %d)\n",
3081 debugstr_w(file
->SourcePath
), debugstr_w(file
->TargetPath
),
3083 if (rc
== ERROR_ALREADY_EXISTS
&& file
->State
== 2)
3085 CopyFileW(file
->SourcePath
,file
->TargetPath
,FALSE
);
3086 DeleteFileW(file
->SourcePath
);
3089 else if (rc
== ERROR_FILE_NOT_FOUND
)
3091 ERR("Source File Not Found! Continuing\n");
3096 ERR("Ignoring Error and continuing...\n");
3108 inline static UINT
get_file_target(MSIPACKAGE
*package
, LPCWSTR file_key
,
3109 LPWSTR
* file_source
)
3114 return ERROR_INVALID_HANDLE
;
3116 for (index
= 0; index
< package
->loaded_files
; index
++)
3118 if (strcmpW(file_key
,package
->files
[index
].File
)==0)
3120 if (package
->files
[index
].State
>= 2)
3122 *file_source
= dupstrW(package
->files
[index
].TargetPath
);
3123 return ERROR_SUCCESS
;
3126 return ERROR_FILE_NOT_FOUND
;
3130 return ERROR_FUNCTION_FAILED
;
3133 static UINT
ACTION_DuplicateFiles(MSIPACKAGE
*package
)
3137 MSIRECORD
* row
= 0;
3138 static const WCHAR ExecSeqQuery
[] =
3139 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3140 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
3143 return ERROR_INVALID_HANDLE
;
3145 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3146 if (rc
!= ERROR_SUCCESS
)
3147 return ERROR_SUCCESS
;
3149 rc
= MSI_ViewExecute(view
, 0);
3150 if (rc
!= ERROR_SUCCESS
)
3152 MSI_ViewClose(view
);
3153 msiobj_release(&view
->hdr
);
3159 WCHAR file_key
[0x100];
3160 WCHAR
*file_source
= NULL
;
3161 WCHAR dest_name
[0x100];
3162 LPWSTR dest_path
, dest
;
3163 WCHAR component
[0x100];
3164 INT component_index
;
3168 rc
= MSI_ViewFetch(view
,&row
);
3169 if (rc
!= ERROR_SUCCESS
)
3176 rc
= MSI_RecordGetStringW(row
,2,component
,&sz
);
3177 if (rc
!= ERROR_SUCCESS
)
3179 ERR("Unable to get component\n");
3180 msiobj_release(&row
->hdr
);
3184 component_index
= get_loaded_component(package
,component
);
3186 if (!ACTION_VerifyComponentForAction(package
, component_index
,
3187 INSTALLSTATE_LOCAL
))
3189 TRACE("Skipping copy due to disabled component\n");
3191 /* the action taken was the same as the current install state */
3192 package
->components
[component_index
].Action
=
3193 package
->components
[component_index
].Installed
;
3195 msiobj_release(&row
->hdr
);
3199 package
->components
[component_index
].Action
= INSTALLSTATE_LOCAL
;
3202 rc
= MSI_RecordGetStringW(row
,3,file_key
,&sz
);
3203 if (rc
!= ERROR_SUCCESS
)
3205 ERR("Unable to get file key\n");
3206 msiobj_release(&row
->hdr
);
3210 rc
= get_file_target(package
,file_key
,&file_source
);
3212 if (rc
!= ERROR_SUCCESS
)
3214 ERR("Original file unknown %s\n",debugstr_w(file_key
));
3215 msiobj_release(&row
->hdr
);
3216 HeapFree(GetProcessHeap(),0,file_source
);
3220 if (MSI_RecordIsNull(row
,4))
3222 strcpyW(dest_name
,strrchrW(file_source
,'\\')+1);
3227 MSI_RecordGetStringW(row
,4,dest_name
,&sz
);
3228 reduce_to_longfilename(dest_name
);
3231 if (MSI_RecordIsNull(row
,5))
3234 dest_path
= dupstrW(file_source
);
3235 p
= strrchrW(dest_path
,'\\');
3241 WCHAR destkey
[0x100];
3243 MSI_RecordGetStringW(row
,5,destkey
,&sz
);
3245 dest_path
= resolve_folder(package
, destkey
, FALSE
,FALSE
,NULL
);
3248 ERR("Unable to get destination folder\n");
3249 msiobj_release(&row
->hdr
);
3250 HeapFree(GetProcessHeap(),0,file_source
);
3255 dest
= build_directory_name(2, dest_path
, dest_name
);
3257 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source
),
3260 if (strcmpW(file_source
,dest
))
3261 rc
= !CopyFileW(file_source
,dest
,TRUE
);
3265 if (rc
!= ERROR_SUCCESS
)
3266 ERR("Failed to copy file %s -> %s, last error %ld\n", debugstr_w(file_source
), debugstr_w(dest_path
), GetLastError());
3268 FIXME("We should track these duplicate files as well\n");
3270 msiobj_release(&row
->hdr
);
3271 HeapFree(GetProcessHeap(),0,dest_path
);
3272 HeapFree(GetProcessHeap(),0,dest
);
3273 HeapFree(GetProcessHeap(),0,file_source
);
3275 MSI_ViewClose(view
);
3276 msiobj_release(&view
->hdr
);
3281 /* OK this value is "interpreted" and then formatted based on the
3282 first few characters */
3283 static LPSTR
parse_value(MSIPACKAGE
*package
, WCHAR
*value
, DWORD
*type
,
3287 if (value
[0]=='#' && value
[1]!='#' && value
[1]!='%')
3296 deformat_string(package
, &value
[2], &deformated
);
3298 /* binary value type */
3301 *size
= strlenW(ptr
)/2;
3302 data
= HeapAlloc(GetProcessHeap(),0,*size
);
3314 data
[count
] = (BYTE
)strtol(byte
,NULL
,0);
3317 HeapFree(GetProcessHeap(),0,deformated
);
3319 TRACE("Data %li bytes(%i)\n",*size
,count
);
3326 deformat_string(package
, &value
[1], &deformated
);
3329 *size
= sizeof(DWORD
);
3330 data
= HeapAlloc(GetProcessHeap(),0,*size
);
3336 if ( (*p
< '0') || (*p
> '9') )
3342 if (deformated
[0] == '-')
3345 TRACE("DWORD %li\n",*(LPDWORD
)data
);
3347 HeapFree(GetProcessHeap(),0,deformated
);
3352 static const WCHAR szMulti
[] = {'[','~',']',0};
3361 *type
=REG_EXPAND_SZ
;
3369 if (strstrW(value
,szMulti
))
3370 *type
= REG_MULTI_SZ
;
3372 *size
= deformat_string(package
, ptr
,(LPWSTR
*)&data
);
3377 static UINT
ACTION_WriteRegistryValues(MSIPACKAGE
*package
)
3381 MSIRECORD
* row
= 0;
3382 static const WCHAR ExecSeqQuery
[] =
3383 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3384 'R','e','g','i','s','t','r','y',0 };
3387 return ERROR_INVALID_HANDLE
;
3389 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3390 if (rc
!= ERROR_SUCCESS
)
3391 return ERROR_SUCCESS
;
3393 rc
= MSI_ViewExecute(view
, 0);
3394 if (rc
!= ERROR_SUCCESS
)
3396 MSI_ViewClose(view
);
3397 msiobj_release(&view
->hdr
);
3401 /* increment progress bar each time action data is sent */
3402 ui_progress(package
,1,REG_PROGRESS_VALUE
,1,0);
3406 static const WCHAR szHCR
[] =
3407 {'H','K','E','Y','_','C','L','A','S','S','E','S','_',
3408 'R','O','O','T','\\',0};
3409 static const WCHAR szHCU
[] =
3410 {'H','K','E','Y','_','C','U','R','R','E','N','T','_',
3411 'U','S','E','R','\\',0};
3412 static const WCHAR szHLM
[] =
3413 {'H','K','E','Y','_','L','O','C','A','L','_',
3414 'M','A','C','H','I','N','E','\\',0};
3415 static const WCHAR szHU
[] =
3416 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3418 LPSTR value_data
= NULL
;
3419 HKEY root_key
, hkey
;
3421 LPWSTR value
, key
, name
, component
, deformated
;
3423 INT component_index
;
3428 rc
= MSI_ViewFetch(view
,&row
);
3429 if (rc
!= ERROR_SUCCESS
)
3434 ui_progress(package
,2,0,0,0);
3441 component
= load_dynamic_stringW(row
, 6);
3442 component_index
= get_loaded_component(package
,component
);
3444 if (!ACTION_VerifyComponentForAction(package
, component_index
,
3445 INSTALLSTATE_LOCAL
))
3447 TRACE("Skipping write due to disabled component\n");
3448 msiobj_release(&row
->hdr
);
3450 package
->components
[component_index
].Action
=
3451 package
->components
[component_index
].Installed
;
3456 package
->components
[component_index
].Action
= INSTALLSTATE_LOCAL
;
3458 name
= load_dynamic_stringW(row
, 4);
3459 if( MSI_RecordIsNull(row
,5) && name
)
3461 /* null values can have special meanings */
3462 if (name
[0]=='-' && name
[1] == 0)
3464 msiobj_release(&row
->hdr
);
3467 else if ((name
[0]=='+' && name
[1] == 0) ||
3468 (name
[0] == '*' && name
[1] == 0))
3470 HeapFree(GetProcessHeap(),0,name
);
3475 root
= MSI_RecordGetInteger(row
,2);
3476 key
= load_dynamic_stringW(row
, 3);
3479 /* get the root key */
3482 case 0: root_key
= HKEY_CLASSES_ROOT
;
3485 case 1: root_key
= HKEY_CURRENT_USER
;
3488 case 2: root_key
= HKEY_LOCAL_MACHINE
;
3491 case 3: root_key
= HKEY_USERS
;
3495 ERR("Unknown root %i\n",root
);
3502 msiobj_release(&row
->hdr
);
3506 deformat_string(package
, key
, &deformated
);
3507 size
= strlenW(deformated
) + strlenW(szRoot
) + 1;
3508 uikey
= HeapAlloc(GetProcessHeap(), 0, size
*sizeof(WCHAR
));
3509 strcpyW(uikey
,szRoot
);
3510 strcatW(uikey
,deformated
);
3512 if (RegCreateKeyW( root_key
, deformated
, &hkey
))
3514 ERR("Could not create key %s\n",debugstr_w(deformated
));
3515 msiobj_release(&row
->hdr
);
3516 HeapFree(GetProcessHeap(),0,deformated
);
3519 HeapFree(GetProcessHeap(),0,deformated
);
3521 value
= load_dynamic_stringW(row
,5);
3523 value_data
= parse_value(package
, value
, &type
, &size
);
3531 deformat_string(package
, name
, &deformated
);
3533 TRACE("Setting value %s\n",debugstr_w(deformated
));
3534 RegSetValueExW(hkey
, deformated
, 0, type
, value_data
, size
);
3536 uirow
= MSI_CreateRecord(3);
3537 MSI_RecordSetStringW(uirow
,2,deformated
);
3538 MSI_RecordSetStringW(uirow
,1,uikey
);
3541 MSI_RecordSetStringW(uirow
,3,(LPWSTR
)value_data
);
3543 MSI_RecordSetStringW(uirow
,3,value
);
3545 ui_actiondata(package
,szWriteRegistryValues
,uirow
);
3546 msiobj_release( &uirow
->hdr
);
3548 HeapFree(GetProcessHeap(),0,value_data
);
3549 HeapFree(GetProcessHeap(),0,value
);
3550 HeapFree(GetProcessHeap(),0,deformated
);
3552 msiobj_release(&row
->hdr
);
3555 HeapFree(GetProcessHeap(),0,uikey
);
3556 HeapFree(GetProcessHeap(),0,key
);
3557 HeapFree(GetProcessHeap(),0,name
);
3558 HeapFree(GetProcessHeap(),0,component
);
3560 MSI_ViewClose(view
);
3561 msiobj_release(&view
->hdr
);
3565 static UINT
ACTION_InstallInitialize(MSIPACKAGE
*package
)
3567 return ERROR_SUCCESS
;
3571 static UINT
ACTION_InstallValidate(MSIPACKAGE
*package
)
3575 static const WCHAR q1
[]=
3576 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
3577 'R','e','g','i','s','t','r','y',0};
3580 MSIRECORD
* row
= 0;
3583 TRACE(" InstallValidate \n");
3585 rc
= MSI_DatabaseOpenViewW(package
->db
, q1
, &view
);
3586 if (rc
!= ERROR_SUCCESS
)
3587 return ERROR_SUCCESS
;
3589 rc
= MSI_ViewExecute(view
, 0);
3590 if (rc
!= ERROR_SUCCESS
)
3592 MSI_ViewClose(view
);
3593 msiobj_release(&view
->hdr
);
3598 rc
= MSI_ViewFetch(view
,&row
);
3599 if (rc
!= ERROR_SUCCESS
)
3606 msiobj_release(&row
->hdr
);
3608 MSI_ViewClose(view
);
3609 msiobj_release(&view
->hdr
);
3611 total
= total
+ progress
* REG_PROGRESS_VALUE
;
3612 total
= total
+ package
->loaded_components
* COMPONENT_PROGRESS_VALUE
;
3613 for (i
=0; i
< package
->loaded_files
; i
++)
3614 total
+= package
->files
[i
].FileSize
;
3615 ui_progress(package
,0,total
,0,0);
3617 return ERROR_SUCCESS
;
3620 static UINT
ACTION_LaunchConditions(MSIPACKAGE
*package
)
3623 MSIQUERY
* view
= NULL
;
3624 MSIRECORD
* row
= 0;
3625 static const WCHAR ExecSeqQuery
[] =
3626 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3627 'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3628 static const WCHAR title
[]=
3629 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3631 TRACE("Checking launch conditions\n");
3633 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
3634 if (rc
!= ERROR_SUCCESS
)
3635 return ERROR_SUCCESS
;
3637 rc
= MSI_ViewExecute(view
, 0);
3638 if (rc
!= ERROR_SUCCESS
)
3640 MSI_ViewClose(view
);
3641 msiobj_release(&view
->hdr
);
3646 while (rc
== ERROR_SUCCESS
)
3649 LPWSTR message
= NULL
;
3651 rc
= MSI_ViewFetch(view
,&row
);
3652 if (rc
!= ERROR_SUCCESS
)
3658 cond
= load_dynamic_stringW(row
,1);
3660 if (MSI_EvaluateConditionW(package
,cond
) != MSICONDITION_TRUE
)
3663 message
= load_dynamic_stringW(row
,2);
3664 deformat_string(package
,message
,&deformated
);
3665 MessageBoxW(NULL
,deformated
,title
,MB_OK
);
3666 HeapFree(GetProcessHeap(),0,message
);
3667 HeapFree(GetProcessHeap(),0,deformated
);
3668 rc
= ERROR_FUNCTION_FAILED
;
3670 HeapFree(GetProcessHeap(),0,cond
);
3671 msiobj_release(&row
->hdr
);
3673 MSI_ViewClose(view
);
3674 msiobj_release(&view
->hdr
);
3678 static LPWSTR
resolve_keypath( MSIPACKAGE
* package
, INT
3681 MSICOMPONENT
* cmp
= &package
->components
[component_index
];
3683 if (cmp
->KeyPath
[0]==0)
3685 LPWSTR p
= resolve_folder(package
,cmp
->Directory
,FALSE
,FALSE
,NULL
);
3688 if (cmp
->Attributes
& msidbComponentAttributesRegistryKeyPath
)
3691 MSIRECORD
* row
= 0;
3693 LPWSTR key
,deformated
,buffer
,name
,deformated_name
;
3694 static const WCHAR ExecSeqQuery
[] =
3695 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
3696 'R','e','g','i','s','t','r','y',' ','W','H','E','R','E',' ',
3697 'R','e','g','i','s','t','r','y',' ','=',' ' ,'`','%','s','`',0 };
3698 static const WCHAR fmt
[]={'%','0','2','i',':','\\','%','s','\\',0};
3699 static const WCHAR fmt2
[]=
3700 {'%','0','2','i',':','\\','%','s','\\','%','s',0};
3702 rc
= MSI_OpenQuery(package
->db
,&view
,ExecSeqQuery
,cmp
->KeyPath
);
3704 if (rc
!=ERROR_SUCCESS
)
3707 rc
= MSI_ViewExecute(view
, 0);
3708 if (rc
!= ERROR_SUCCESS
)
3710 MSI_ViewClose(view
);
3711 msiobj_release(&view
->hdr
);
3715 rc
= MSI_ViewFetch(view
,&row
);
3716 if (rc
!= ERROR_SUCCESS
)
3718 MSI_ViewClose(view
);
3719 msiobj_release(&view
->hdr
);
3723 root
= MSI_RecordGetInteger(row
,2);
3724 key
= load_dynamic_stringW(row
, 3);
3725 name
= load_dynamic_stringW(row
, 4);
3726 deformat_string(package
, key
, &deformated
);
3727 deformat_string(package
, name
, &deformated_name
);
3729 len
= strlenW(deformated
) + 5;
3730 if (deformated_name
)
3731 len
+=strlenW(deformated_name
);
3733 buffer
= HeapAlloc(GetProcessHeap(),0, len
*sizeof(WCHAR
));
3735 if (deformated_name
)
3736 sprintfW(buffer
,fmt2
,root
,deformated
,deformated_name
);
3738 sprintfW(buffer
,fmt
,root
,deformated
);
3740 HeapFree(GetProcessHeap(),0,key
);
3741 HeapFree(GetProcessHeap(),0,deformated
);
3742 HeapFree(GetProcessHeap(),0,name
);
3743 HeapFree(GetProcessHeap(),0,deformated_name
);
3744 msiobj_release(&row
->hdr
);
3745 MSI_ViewClose(view
);
3746 msiobj_release(&view
->hdr
);
3750 else if (cmp
->Attributes
& msidbComponentAttributesODBCDataSource
)
3752 FIXME("UNIMPLEMENTED keypath as ODBC Source\n");
3758 j
= get_loaded_file(package
,cmp
->KeyPath
);
3762 LPWSTR p
= dupstrW(package
->files
[j
].TargetPath
);
3769 static HKEY
openSharedDLLsKey()
3772 static const WCHAR path
[] =
3773 {'S','o','f','t','w','a','r','e','\\',
3774 'M','i','c','r','o','s','o','f','t','\\',
3775 'W','i','n','d','o','w','s','\\',
3776 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3777 'S','h','a','r','e','d','D','L','L','s',0};
3779 RegCreateKeyW(HKEY_LOCAL_MACHINE
,path
,&hkey
);
3783 static UINT
ACTION_GetSharedDLLsCount(LPCWSTR dll
)
3788 DWORD sz
= sizeof(count
);
3791 hkey
= openSharedDLLsKey();
3792 rc
= RegQueryValueExW(hkey
, dll
, NULL
, &type
, (LPBYTE
)&count
, &sz
);
3793 if (rc
!= ERROR_SUCCESS
)
3799 static UINT
ACTION_WriteSharedDLLsCount(LPCWSTR path
, UINT count
)
3803 hkey
= openSharedDLLsKey();
3805 RegSetValueExW(hkey
,path
,0,REG_DWORD
,
3806 (LPBYTE
)&count
,sizeof(count
));
3808 RegDeleteValueW(hkey
,path
);
3814 * Return TRUE if the count should be written out and FALSE if not
3816 static void ACTION_RefCountComponent( MSIPACKAGE
* package
, UINT index
)
3822 /* only refcount DLLs */
3823 if (package
->components
[index
].KeyPath
[0]==0 ||
3824 package
->components
[index
].Attributes
&
3825 msidbComponentAttributesRegistryKeyPath
||
3826 package
->components
[index
].Attributes
&
3827 msidbComponentAttributesODBCDataSource
)
3831 count
= ACTION_GetSharedDLLsCount(package
->components
[index
].
3833 write
= (count
> 0);
3835 if (package
->components
[index
].Attributes
&
3836 msidbComponentAttributesSharedDllRefCount
)
3840 /* increment counts */
3841 for (j
= 0; j
< package
->loaded_features
; j
++)
3845 if (!ACTION_VerifyFeatureForAction(package
,j
,INSTALLSTATE_LOCAL
))
3848 for (i
= 0; i
< package
->features
[j
].ComponentCount
; i
++)
3850 if (package
->features
[j
].Components
[i
] == index
)
3854 /* decrement counts */
3855 for (j
= 0; j
< package
->loaded_features
; j
++)
3858 if (!ACTION_VerifyFeatureForAction(package
,j
,INSTALLSTATE_ABSENT
))
3861 for (i
= 0; i
< package
->features
[j
].ComponentCount
; i
++)
3863 if (package
->features
[j
].Components
[i
] == index
)
3868 /* ref count all the files in the component */
3870 for (j
= 0; j
< package
->loaded_files
; j
++)
3872 if (package
->files
[j
].Temporary
)
3874 if (package
->files
[j
].ComponentIndex
== index
)
3875 ACTION_WriteSharedDLLsCount(package
->files
[j
].TargetPath
,count
);
3878 /* add a count for permenent */
3879 if (package
->components
[index
].Attributes
&
3880 msidbComponentAttributesPermanent
)
3883 package
->components
[index
].RefCount
= count
;
3886 ACTION_WriteSharedDLLsCount(package
->components
[index
].FullKeypath
,
3887 package
->components
[index
].RefCount
);
3891 * Ok further analysis makes me think that this work is
3892 * actually done in the PublishComponents and PublishFeatures
3893 * step, and not here. It appears like the keypath and all that is
3894 * resolved in this step, however actually written in the Publish steps.
3895 * But we will leave it here for now because it is unclear
3897 static UINT
ACTION_ProcessComponents(MSIPACKAGE
*package
)
3900 WCHAR squished_pc
[GUID_SIZE
];
3901 WCHAR squished_cc
[GUID_SIZE
];
3904 HKEY hkey
=0,hkey2
=0;
3907 return ERROR_INVALID_HANDLE
;
3909 /* writes the Component and Features values to the registry */
3910 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
3914 rc
= MSIREG_OpenComponents(&hkey
);
3915 if (rc
!= ERROR_SUCCESS
)
3918 squash_guid(productcode
,squished_pc
);
3919 ui_progress(package
,1,COMPONENT_PROGRESS_VALUE
,1,0);
3920 for (i
= 0; i
< package
->loaded_components
; i
++)
3922 ui_progress(package
,2,0,0,0);
3923 if (package
->components
[i
].ComponentId
[0]!=0)
3925 WCHAR
*keypath
= NULL
;
3928 squash_guid(package
->components
[i
].ComponentId
,squished_cc
);
3929 rc
= RegCreateKeyW(hkey
,squished_cc
,&hkey2
);
3930 if (rc
!= ERROR_SUCCESS
)
3933 keypath
= resolve_keypath(package
,i
);
3934 package
->components
[i
].FullKeypath
= keypath
;
3936 /* do the refcounting */
3937 ACTION_RefCountComponent( package
, i
);
3939 TRACE("Component %s, Keypath=%s, RefCount=%i\n",
3940 debugstr_w(package
->components
[i
].Component
),
3941 debugstr_w(package
->components
[i
].FullKeypath
),
3942 package
->components
[i
].RefCount
);
3944 * Write the keypath out if the component is to be registered
3945 * and delete the key if the component is to be deregistered
3947 if (ACTION_VerifyComponentForAction(package
, i
,
3948 INSTALLSTATE_LOCAL
))
3952 RegSetValueExW(hkey2
,squished_pc
,0,REG_SZ
,(LPVOID
)keypath
,
3953 (strlenW(keypath
)+1)*sizeof(WCHAR
));
3955 if (package
->components
[i
].Attributes
&
3956 msidbComponentAttributesPermanent
)
3958 static const WCHAR szPermKey
[] =
3959 { '0','0','0','0','0','0','0','0','0','0','0','0',
3960 '0','0','0','0','0','0','0', '0','0','0','0','0',
3961 '0','0','0','0','0','0','0','0',0};
3963 RegSetValueExW(hkey2
,szPermKey
,0,REG_SZ
,
3965 (strlenW(keypath
)+1)*sizeof(WCHAR
));
3971 uirow
= MSI_CreateRecord(3);
3972 MSI_RecordSetStringW(uirow
,1,productcode
);
3973 MSI_RecordSetStringW(uirow
,2,package
->components
[i
].
3975 MSI_RecordSetStringW(uirow
,3,keypath
);
3976 ui_actiondata(package
,szProcessComponents
,uirow
);
3977 msiobj_release( &uirow
->hdr
);
3980 else if (ACTION_VerifyComponentForAction(package
, i
,
3981 INSTALLSTATE_ABSENT
))
3984 RegDeleteValueW(hkey2
,squished_pc
);
3986 /* if the key is empty delete it */
3987 res
= RegEnumKeyExW(hkey2
,0,NULL
,0,0,NULL
,0,NULL
);
3989 if (res
== ERROR_NO_MORE_ITEMS
)
3990 RegDeleteKeyW(hkey
,squished_cc
);
3993 uirow
= MSI_CreateRecord(2);
3994 MSI_RecordSetStringW(uirow
,1,productcode
);
3995 MSI_RecordSetStringW(uirow
,2,package
->components
[i
].
3997 ui_actiondata(package
,szProcessComponents
,uirow
);
3998 msiobj_release( &uirow
->hdr
);
4003 HeapFree(GetProcessHeap(), 0, productcode
);
4008 static UINT
ACTION_RegisterTypeLibraries(MSIPACKAGE
*package
)
4011 * OK this is a bit confusing.. I am given a _Component key and I believe
4012 * that the file that is being registered as a type library is the "key file
4013 * of that component" which I interpret to mean "The file in the KeyPath of
4018 MSIRECORD
* row
= 0;
4019 static const WCHAR Query
[] =
4020 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4021 'T','y','p','e','L','i','b',0};
4026 return ERROR_INVALID_HANDLE
;
4028 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
4029 if (rc
!= ERROR_SUCCESS
)
4030 return ERROR_SUCCESS
;
4032 rc
= MSI_ViewExecute(view
, 0);
4033 if (rc
!= ERROR_SUCCESS
)
4035 MSI_ViewClose(view
);
4036 msiobj_release(&view
->hdr
);
4042 WCHAR component
[0x100];
4046 rc
= MSI_ViewFetch(view
,&row
);
4047 if (rc
!= ERROR_SUCCESS
)
4054 MSI_RecordGetStringW(row
,3,component
,&sz
);
4056 index
= get_loaded_component(package
,component
);
4059 msiobj_release(&row
->hdr
);
4063 if (!ACTION_VerifyComponentForAction(package
, index
,
4064 INSTALLSTATE_LOCAL
))
4066 TRACE("Skipping typelib reg due to disabled component\n");
4067 msiobj_release(&row
->hdr
);
4069 package
->components
[index
].Action
=
4070 package
->components
[index
].Installed
;
4075 package
->components
[index
].Action
= INSTALLSTATE_LOCAL
;
4077 index
= get_loaded_file(package
,package
->components
[index
].KeyPath
);
4081 msiobj_release(&row
->hdr
);
4085 res
= LoadTypeLib(package
->files
[index
].TargetPath
,&ptLib
);
4089 WCHAR helpid
[0x100];
4092 MSI_RecordGetStringW(row
,6,helpid
,&sz
);
4094 help
= resolve_folder(package
,helpid
,FALSE
,FALSE
,NULL
);
4095 res
= RegisterTypeLib(ptLib
,package
->files
[index
].TargetPath
,help
);
4096 HeapFree(GetProcessHeap(),0,help
);
4098 if (!SUCCEEDED(res
))
4099 ERR("Failed to register type library %s\n",
4100 debugstr_w(package
->files
[index
].TargetPath
));
4103 /* Yes the row has more fields than I need, but #1 is
4104 correct and the only one I need. Why make a new row? */
4106 ui_actiondata(package
,szRegisterTypeLibraries
,row
);
4108 TRACE("Registered %s\n",
4109 debugstr_w(package
->files
[index
].TargetPath
));
4113 ITypeLib_Release(ptLib
);
4116 ERR("Failed to load type library %s\n",
4117 debugstr_w(package
->files
[index
].TargetPath
));
4119 msiobj_release(&row
->hdr
);
4121 MSI_ViewClose(view
);
4122 msiobj_release(&view
->hdr
);
4127 static UINT
register_appid(MSIPACKAGE
*package
, LPCWSTR clsid
, LPCWSTR app
)
4129 static const WCHAR szAppID
[] = { 'A','p','p','I','D',0 };
4132 MSIRECORD
* row
= 0;
4133 static const WCHAR ExecSeqQuery
[] =
4134 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4135 'A','p','p','I' ,'d',' ','w','h','e','r','e',' ',
4136 'A','p','p','I','d','=','`','%','s','`',0};
4141 return ERROR_INVALID_HANDLE
;
4143 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, clsid
);
4144 if (rc
!= ERROR_SUCCESS
)
4147 rc
= MSI_ViewExecute(view
, 0);
4148 if (rc
!= ERROR_SUCCESS
)
4150 MSI_ViewClose(view
);
4151 msiobj_release(&view
->hdr
);
4155 RegCreateKeyW(HKEY_CLASSES_ROOT
,szAppID
,&hkey2
);
4156 RegCreateKeyW(hkey2
,clsid
,&hkey3
);
4157 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,(LPVOID
)app
,
4158 (strlenW(app
)+1)*sizeof(WCHAR
));
4160 rc
= MSI_ViewFetch(view
,&row
);
4161 if (rc
!= ERROR_SUCCESS
)
4163 MSI_ViewClose(view
);
4164 msiobj_release(&view
->hdr
);
4168 if (!MSI_RecordIsNull(row
,2))
4170 LPWSTR deformated
=0;
4172 static const WCHAR szRemoteServerName
[] =
4173 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',
4175 buffer
= load_dynamic_stringW(row
,2);
4176 size
= deformat_string(package
,buffer
,&deformated
);
4177 RegSetValueExW(hkey3
,szRemoteServerName
,0,REG_SZ
,(LPVOID
)deformated
,
4179 HeapFree(GetProcessHeap(),0,deformated
);
4180 HeapFree(GetProcessHeap(),0,buffer
);
4183 if (!MSI_RecordIsNull(row
,3))
4185 static const WCHAR szLocalService
[] =
4186 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
4188 buffer
= load_dynamic_stringW(row
,3);
4189 size
= (strlenW(buffer
)+1) * sizeof(WCHAR
);
4190 RegSetValueExW(hkey3
,szLocalService
,0,REG_SZ
,(LPVOID
)buffer
,size
);
4191 HeapFree(GetProcessHeap(),0,buffer
);
4194 if (!MSI_RecordIsNull(row
,4))
4196 static const WCHAR szService
[] =
4197 {'S','e','r','v','i','c','e',
4198 'P','a','r','a','m','e','t','e','r','s',0};
4200 buffer
= load_dynamic_stringW(row
,4);
4201 size
= (strlenW(buffer
)+1) * sizeof(WCHAR
);
4202 RegSetValueExW(hkey3
,szService
,0,REG_SZ
,(LPVOID
)buffer
,size
);
4203 HeapFree(GetProcessHeap(),0,buffer
);
4206 if (!MSI_RecordIsNull(row
,5))
4208 static const WCHAR szDLL
[] =
4209 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
4211 buffer
= load_dynamic_stringW(row
,5);
4212 size
= (strlenW(buffer
)+1) * sizeof(WCHAR
);
4213 RegSetValueExW(hkey3
,szDLL
,0,REG_SZ
,(LPVOID
)buffer
,size
);
4214 HeapFree(GetProcessHeap(),0,buffer
);
4217 if (!MSI_RecordIsNull(row
,6))
4219 static const WCHAR szActivate
[] =
4220 {'A','c','t','i','v','a','t','e','A','s',
4221 'S','t','o','r','a','g','e',0};
4222 static const WCHAR szY
[] = {'Y',0};
4224 if (MSI_RecordGetInteger(row
,6))
4225 RegSetValueExW(hkey3
,szActivate
,0,REG_SZ
,(LPVOID
)szY
,4);
4228 if (!MSI_RecordIsNull(row
,7))
4230 static const WCHAR szRunAs
[] = {'R','u','n','A','s',0};
4231 static const WCHAR szUser
[] =
4232 {'I','n','t','e','r','a','c','t','i','v','e',' ',
4235 if (MSI_RecordGetInteger(row
,7))
4236 RegSetValueExW(hkey3
,szRunAs
,0,REG_SZ
,(LPVOID
)szUser
,34);
4239 msiobj_release(&row
->hdr
);
4240 MSI_ViewClose(view
);
4241 msiobj_release(&view
->hdr
);
4247 static UINT
ACTION_RegisterClassInfo(MSIPACKAGE
*package
)
4250 * Again I am assuming the words, "Whose key file represents" when referring
4251 * to a Component as to meaning that Components KeyPath file
4253 * Also there is a very strong connection between ClassInfo and ProgID
4254 * that I am mostly glossing over.
4255 * What would be more propper is to load the ClassInfo and the ProgID info
4256 * into memory data structures and then be able to enable and disable them
4257 * based on component.
4262 MSIRECORD
* row
= 0;
4263 static const WCHAR ExecSeqQuery
[] =
4264 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4265 'C','l','a','s','s',0};
4266 static const WCHAR szCLSID
[] = { 'C','L','S','I','D',0 };
4267 static const WCHAR szProgID
[] = { 'P','r','o','g','I','D',0 };
4268 static const WCHAR szAppID
[] = { 'A','p','p','I','D',0 };
4269 static const WCHAR szSpace
[] = {' ',0};
4270 HKEY hkey
,hkey2
,hkey3
;
4271 LPWSTR argument
,deformated
;
4274 return ERROR_INVALID_HANDLE
;
4276 rc
= RegCreateKeyW(HKEY_CLASSES_ROOT
,szCLSID
,&hkey
);
4277 if (rc
!= ERROR_SUCCESS
)
4278 return ERROR_FUNCTION_FAILED
;
4280 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
4281 if (rc
!= ERROR_SUCCESS
)
4287 rc
= MSI_ViewExecute(view
, 0);
4288 if (rc
!= ERROR_SUCCESS
)
4290 MSI_ViewClose(view
);
4291 msiobj_release(&view
->hdr
);
4298 WCHAR buffer
[0x100];
4304 rc
= MSI_ViewFetch(view
,&row
);
4305 if (rc
!= ERROR_SUCCESS
)
4312 MSI_RecordGetStringW(row
,3,buffer
,&sz
);
4314 index
= get_loaded_component(package
,buffer
);
4318 msiobj_release(&row
->hdr
);
4322 if (!ACTION_VerifyComponentForAction(package
, index
,
4323 INSTALLSTATE_LOCAL
))
4325 TRACE("Skipping class reg due to disabled component\n");
4326 msiobj_release(&row
->hdr
);
4328 package
->components
[index
].Action
=
4329 package
->components
[index
].Installed
;
4334 package
->components
[index
].Action
= INSTALLSTATE_LOCAL
;
4337 MSI_RecordGetStringW(row
,1,clsid
,&sz
);
4338 RegCreateKeyW(hkey
,clsid
,&hkey2
);
4340 if (!MSI_RecordIsNull(row
,5))
4343 MSI_RecordGetStringW(row
,5,desc
,&sz
);
4345 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)desc
,
4346 (strlenW(desc
)+1)*sizeof(WCHAR
));
4352 MSI_RecordGetStringW(row
,2,buffer
,&sz
);
4354 RegCreateKeyW(hkey2
,buffer
,&hkey3
);
4356 index
= get_loaded_file(package
,package
->components
[index
].KeyPath
);
4358 argument
= load_dynamic_stringW(row
,11);
4359 size
= deformat_string(package
,argument
,&deformated
);
4361 size
+=sizeof(WCHAR
);
4362 HeapFree(GetProcessHeap(),0,argument
);
4363 size
+= (strlenW(package
->files
[index
].TargetPath
))*sizeof(WCHAR
);
4365 argument
= (LPWSTR
)HeapAlloc(GetProcessHeap(),0,size
+sizeof(WCHAR
));
4366 strcpyW(argument
,package
->files
[index
].TargetPath
);
4369 strcatW(argument
,szSpace
);
4370 strcatW(argument
,deformated
);
4373 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
, (LPVOID
)argument
, size
);
4374 HeapFree(GetProcessHeap(),0,deformated
);
4375 HeapFree(GetProcessHeap(),0,argument
);
4379 if (!MSI_RecordIsNull(row
,4))
4382 MSI_RecordGetStringW(row
,4,buffer
,&sz
);
4384 RegCreateKeyW(hkey2
,szProgID
,&hkey3
);
4386 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,(LPVOID
)buffer
,
4387 (strlenW(buffer
)+1)*sizeof(WCHAR
));
4392 if (!MSI_RecordIsNull(row
,6))
4395 MSI_RecordGetStringW(row
,6,buffer
,&sz
);
4397 RegSetValueExW(hkey2
,szAppID
,0,REG_SZ
,(LPVOID
)buffer
,
4398 (strlenW(buffer
)+1)*sizeof(WCHAR
));
4400 register_appid(package
,buffer
,desc
);
4404 if (!MSI_RecordIsNull(row
,7))
4406 FIXME("Process field 7\n");
4409 if (!MSI_RecordIsNull(row
,8))
4411 static const WCHAR szDefaultIcon
[] =
4412 {'D','e','f','a','u','l','t','I','c','o','n',0};
4414 LPWSTR FileName
= load_dynamic_stringW(row
,8);
4418 RegCreateKeyW(hkey2
,szDefaultIcon
,&hkey3
);
4419 build_icon_path(package
,FileName
,&FilePath
);
4420 if (!MSI_RecordIsNull(row
,9))
4422 static const WCHAR index_fmt
[] = {',','%','i',0};
4423 WCHAR index_buf
[20];
4424 index
= MSI_RecordGetInteger(row
,9);
4425 sprintfW(index_buf
,index_fmt
,index
);
4426 size
= strlenW(FilePath
)+strlenW(index_buf
)+1;
4427 size
*= sizeof(WCHAR
);
4428 HeapReAlloc(GetProcessHeap(),0,FilePath
,size
);
4430 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
,(LPVOID
)FilePath
,
4431 (strlenW(FilePath
)+1) * sizeof(WCHAR
));
4432 HeapFree(GetProcessHeap(),0,FilePath
);
4433 HeapFree(GetProcessHeap(),0,FileName
);
4437 if (!MSI_RecordIsNull(row
,10))
4439 static const WCHAR szInproc32
[] =
4440 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',
4442 static const WCHAR szInproc
[] =
4443 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
4444 INT i
= MSI_RecordGetInteger(row
,10);
4445 if (i
!= MSI_NULL_INTEGER
&& i
> 0 && i
< 4)
4447 static const WCHAR ole2
[] = {'o','l','e','2','.','d','l','l',0};
4448 static const WCHAR ole32
[] =
4449 {'o','l','e','3','2','.','d','l','l',0};
4453 size
= strlenW(ole2
) * sizeof(WCHAR
);
4454 RegCreateKeyW(hkey2
,szInproc
,&hkey3
);
4455 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
, (LPVOID
)ole2
, size
);
4459 size
= strlenW(ole32
) * sizeof(WCHAR
);
4460 RegCreateKeyW(hkey2
,szInproc32
,&hkey3
);
4461 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
, (LPVOID
)ole32
,size
);
4465 size
= strlenW(ole2
) * sizeof(WCHAR
);
4466 RegCreateKeyW(hkey2
,szInproc
,&hkey3
);
4467 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
, (LPVOID
)ole2
, size
);
4469 size
= strlenW(ole32
) * sizeof(WCHAR
);
4470 RegCreateKeyW(hkey2
,szInproc32
,&hkey3
);
4471 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
, (LPVOID
)ole32
,size
);
4479 RegCreateKeyW(hkey2
,szInproc32
,&hkey3
);
4480 argument
= load_dynamic_stringW(row
,10);
4481 reduce_to_longfilename(argument
);
4482 size
= strlenW(argument
)*sizeof(WCHAR
);
4484 RegSetValueExW(hkey3
,NULL
,0,REG_SZ
, (LPVOID
)argument
, size
);
4485 HeapFree(GetProcessHeap(),0,argument
);
4493 ui_actiondata(package
,szRegisterClassInfo
,row
);
4495 msiobj_release(&row
->hdr
);
4497 MSI_ViewClose(view
);
4498 msiobj_release(&view
->hdr
);
4505 static UINT
register_progid_base(MSIPACKAGE
* package
, MSIRECORD
* row
,
4508 static const WCHAR szCLSID
[] = { 'C','L','S','I','D',0 };
4509 static const WCHAR szDefaultIcon
[] =
4510 {'D','e','f','a','u','l','t','I','c','o','n',0};
4512 WCHAR buffer
[0x100];
4517 MSI_RecordGetStringW(row
,1,buffer
,&sz
);
4518 RegCreateKeyW(HKEY_CLASSES_ROOT
,buffer
,&hkey
);
4520 if (!MSI_RecordIsNull(row
,4))
4523 MSI_RecordGetStringW(row
,4,buffer
,&sz
);
4524 RegSetValueExW(hkey
,NULL
,0,REG_SZ
,(LPVOID
)buffer
, (strlenW(buffer
)+1) *
4528 if (!MSI_RecordIsNull(row
,3))
4532 MSI_RecordGetStringW(row
,3,buffer
,&sz
);
4533 RegCreateKeyW(hkey
,szCLSID
,&hkey2
);
4534 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)buffer
, (strlenW(buffer
)+1) *
4538 strcpyW(clsid
,buffer
);
4544 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
4545 return ERROR_FUNCTION_FAILED
;
4547 if (!MSI_RecordIsNull(row
,5))
4549 INT index
= MSI_RecordGetInteger(row
,6);
4550 LPWSTR FileName
= load_dynamic_stringW(row
,5);
4551 LPWSTR FilePath
,IconPath
;
4552 static const WCHAR fmt
[] = {'%','s',',','%','i',0};
4554 RegCreateKeyW(hkey
,szDefaultIcon
,&hkey2
);
4555 build_icon_path(package
,FileName
,&FilePath
);
4557 IconPath
= HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath
)+5)*
4560 sprintfW(IconPath
,fmt
,FilePath
,index
);
4561 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)IconPath
,
4562 (strlenW(IconPath
)+1) * sizeof(WCHAR
));
4563 HeapFree(GetProcessHeap(),0,FilePath
);
4564 HeapFree(GetProcessHeap(),0,FileName
);
4567 return ERROR_SUCCESS
;
4570 static UINT
register_progid(MSIPACKAGE
*package
, MSIRECORD
* row
, LPWSTR clsid
);
4572 static UINT
register_parent_progid(MSIPACKAGE
*package
, LPCWSTR parent
,
4577 MSIRECORD
* row
= 0;
4578 static const WCHAR Query_t
[] =
4579 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4580 'P','r','o','g' ,'I','d',' ','W','H','E','R','E',' ',
4581 'P','r','o','g','I','d',' ','=',' ','`' ,'%','s','`',0};
4584 return ERROR_INVALID_HANDLE
;
4586 rc
= MSI_OpenQuery(package
->db
, &view
, Query_t
, parent
);
4587 if (rc
!= ERROR_SUCCESS
)
4590 rc
= MSI_ViewExecute(view
, 0);
4591 if (rc
!= ERROR_SUCCESS
)
4593 MSI_ViewClose(view
);
4594 msiobj_release(&view
->hdr
);
4598 rc
= MSI_ViewFetch(view
,&row
);
4599 if (rc
!= ERROR_SUCCESS
)
4601 MSI_ViewClose(view
);
4602 msiobj_release(&view
->hdr
);
4606 register_progid(package
,row
,clsid
);
4608 msiobj_release(&row
->hdr
);
4609 MSI_ViewClose(view
);
4610 msiobj_release(&view
->hdr
);
4614 static UINT
register_progid(MSIPACKAGE
*package
, MSIRECORD
* row
, LPWSTR clsid
)
4616 UINT rc
= ERROR_SUCCESS
;
4618 if (MSI_RecordIsNull(row
,2))
4619 rc
= register_progid_base(package
,row
,clsid
);
4622 WCHAR buffer
[0x1000];
4625 static const WCHAR szCLSID
[] = { 'C','L','S','I','D',0 };
4626 static const WCHAR szDefaultIcon
[] =
4627 {'D','e','f','a','u','l','t','I','c','o','n',0};
4629 /* check if already registered */
4631 MSI_RecordGetStringW(row
,1,buffer
,&sz
);
4632 RegCreateKeyExW(HKEY_CLASSES_ROOT
, buffer
, 0, NULL
, 0,
4633 KEY_ALL_ACCESS
, NULL
, &hkey
, &disp
);
4634 if (disp
== REG_OPENED_EXISTING_KEY
)
4636 TRACE("Key already registered\n");
4642 MSI_RecordGetStringW(row
,2,buffer
,&sz
);
4643 rc
= register_parent_progid(package
,buffer
,clsid
);
4645 /* clsid is same as parent */
4646 RegCreateKeyW(hkey
,szCLSID
,&hkey2
);
4647 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)clsid
, (strlenW(clsid
)+1) *
4653 if (!MSI_RecordIsNull(row
,4))
4656 MSI_RecordGetStringW(row
,4,buffer
,&sz
);
4657 RegSetValueExW(hkey
,NULL
,0,REG_SZ
,(LPVOID
)buffer
,
4658 (strlenW(buffer
)+1) * sizeof(WCHAR
));
4661 if (!MSI_RecordIsNull(row
,5))
4663 LPWSTR FileName
= load_dynamic_stringW(row
,5);
4665 RegCreateKeyW(hkey
,szDefaultIcon
,&hkey2
);
4666 build_icon_path(package
,FileName
,&FilePath
);
4667 RegSetValueExW(hkey2
,NULL
,0,REG_SZ
,(LPVOID
)FilePath
,
4668 (strlenW(FilePath
)+1) * sizeof(WCHAR
));
4669 HeapFree(GetProcessHeap(),0,FilePath
);
4670 HeapFree(GetProcessHeap(),0,FileName
);
4679 static UINT
ACTION_RegisterProgIdInfo(MSIPACKAGE
*package
)
4682 * Sigh, here I am just brute force registering all progids
4683 * this needs to be linked to the Classes that have been registered
4684 * but the easiest way to do that is to load all these stuff into
4685 * memory for easy checking.
4687 * Gives me something to continue to work toward.
4691 MSIRECORD
* row
= 0;
4692 static const WCHAR Query
[] =
4693 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
4694 'P','r','o','g','I','d',0};
4697 return ERROR_INVALID_HANDLE
;
4699 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
4700 if (rc
!= ERROR_SUCCESS
)
4701 return ERROR_SUCCESS
;
4703 rc
= MSI_ViewExecute(view
, 0);
4704 if (rc
!= ERROR_SUCCESS
)
4706 MSI_ViewClose(view
);
4707 msiobj_release(&view
->hdr
);
4713 WCHAR clsid
[0x1000];
4715 rc
= MSI_ViewFetch(view
,&row
);
4716 if (rc
!= ERROR_SUCCESS
)
4722 register_progid(package
,row
,clsid
);
4723 ui_actiondata(package
,szRegisterProgIdInfo
,row
);
4725 msiobj_release(&row
->hdr
);
4727 MSI_ViewClose(view
);
4728 msiobj_release(&view
->hdr
);
4732 static UINT
build_icon_path(MSIPACKAGE
*package
, LPCWSTR icon_name
,
4736 LPWSTR SystemFolder
;
4740 static const WCHAR szInstaller
[] =
4741 {'I','n','s','t','a','l','l','e','r','\\',0};
4742 static const WCHAR szFolder
[] =
4743 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4745 ProductCode
= load_dynamic_property(package
,szProductCode
,&rc
);
4749 SystemFolder
= load_dynamic_property(package
,szFolder
,NULL
);
4751 dest
= build_directory_name(3, SystemFolder
, szInstaller
, ProductCode
);
4753 create_full_pathW(dest
);
4755 *FilePath
= build_directory_name(2, dest
, icon_name
);
4757 HeapFree(GetProcessHeap(),0,SystemFolder
);
4758 HeapFree(GetProcessHeap(),0,ProductCode
);
4759 HeapFree(GetProcessHeap(),0,dest
);
4760 return ERROR_SUCCESS
;
4763 static UINT
ACTION_CreateShortcuts(MSIPACKAGE
*package
)
4767 MSIRECORD
* row
= 0;
4768 static const WCHAR Query
[] =
4769 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
4770 'S','h','o','r','t','c','u','t',0};
4776 return ERROR_INVALID_HANDLE
;
4778 res
= CoInitialize( NULL
);
4781 ERR("CoInitialize failed\n");
4782 return ERROR_FUNCTION_FAILED
;
4785 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
4786 if (rc
!= ERROR_SUCCESS
)
4787 return ERROR_SUCCESS
;
4789 rc
= MSI_ViewExecute(view
, 0);
4790 if (rc
!= ERROR_SUCCESS
)
4792 MSI_ViewClose(view
);
4793 msiobj_release(&view
->hdr
);
4799 LPWSTR target_file
, target_folder
;
4800 WCHAR buffer
[0x100];
4803 static const WCHAR szlnk
[]={'.','l','n','k',0};
4805 rc
= MSI_ViewFetch(view
,&row
);
4806 if (rc
!= ERROR_SUCCESS
)
4813 MSI_RecordGetStringW(row
,4,buffer
,&sz
);
4815 index
= get_loaded_component(package
,buffer
);
4819 msiobj_release(&row
->hdr
);
4823 if (!ACTION_VerifyComponentForAction(package
, index
,
4824 INSTALLSTATE_LOCAL
))
4826 TRACE("Skipping shortcut creation due to disabled component\n");
4827 msiobj_release(&row
->hdr
);
4829 package
->components
[index
].Action
=
4830 package
->components
[index
].Installed
;
4835 package
->components
[index
].Action
= INSTALLSTATE_LOCAL
;
4837 ui_actiondata(package
,szCreateShortcuts
,row
);
4839 res
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
4840 &IID_IShellLinkW
, (LPVOID
*) &sl
);
4844 ERR("Is IID_IShellLink\n");
4845 msiobj_release(&row
->hdr
);
4849 res
= IShellLinkW_QueryInterface( sl
, &IID_IPersistFile
,(LPVOID
*) &pf
);
4852 ERR("Is IID_IPersistFile\n");
4853 msiobj_release(&row
->hdr
);
4858 MSI_RecordGetStringW(row
,2,buffer
,&sz
);
4859 target_folder
= resolve_folder(package
, buffer
,FALSE
,FALSE
,NULL
);
4861 /* may be needed because of a bug somehwere else */
4862 create_full_pathW(target_folder
);
4865 MSI_RecordGetStringW(row
,3,buffer
,&sz
);
4866 reduce_to_longfilename(buffer
);
4867 if (!strchrW(buffer
,'.') || strcmpiW(strchrW(buffer
,'.'),szlnk
))
4868 strcatW(buffer
,szlnk
);
4869 target_file
= build_directory_name(2, target_folder
, buffer
);
4870 HeapFree(GetProcessHeap(),0,target_folder
);
4873 MSI_RecordGetStringW(row
,5,buffer
,&sz
);
4874 if (strchrW(buffer
,'['))
4877 deformat_string(package
,buffer
,&deformated
);
4878 IShellLinkW_SetPath(sl
,deformated
);
4879 HeapFree(GetProcessHeap(),0,deformated
);
4884 FIXME("poorly handled shortcut format, advertised shortcut\n");
4885 keypath
= dupstrW(package
->components
[index
].FullKeypath
);
4886 IShellLinkW_SetPath(sl
,keypath
);
4887 HeapFree(GetProcessHeap(),0,keypath
);
4890 if (!MSI_RecordIsNull(row
,6))
4894 MSI_RecordGetStringW(row
,6,buffer
,&sz
);
4895 deformat_string(package
,buffer
,&deformated
);
4896 IShellLinkW_SetArguments(sl
,deformated
);
4897 HeapFree(GetProcessHeap(),0,deformated
);
4900 if (!MSI_RecordIsNull(row
,7))
4903 deformated
= load_dynamic_stringW(row
,7);
4904 IShellLinkW_SetDescription(sl
,deformated
);
4905 HeapFree(GetProcessHeap(),0,deformated
);
4908 if (!MSI_RecordIsNull(row
,8))
4909 IShellLinkW_SetHotkey(sl
,MSI_RecordGetInteger(row
,8));
4911 if (!MSI_RecordIsNull(row
,9))
4917 MSI_RecordGetStringW(row
,9,buffer
,&sz
);
4919 build_icon_path(package
,buffer
,&Path
);
4920 index
= MSI_RecordGetInteger(row
,10);
4922 IShellLinkW_SetIconLocation(sl
,Path
,index
);
4923 HeapFree(GetProcessHeap(),0,Path
);
4926 if (!MSI_RecordIsNull(row
,11))
4927 IShellLinkW_SetShowCmd(sl
,MSI_RecordGetInteger(row
,11));
4929 if (!MSI_RecordIsNull(row
,12))
4933 MSI_RecordGetStringW(row
,12,buffer
,&sz
);
4934 Path
= resolve_folder(package
, buffer
, FALSE
, FALSE
, NULL
);
4935 IShellLinkW_SetWorkingDirectory(sl
,Path
);
4936 HeapFree(GetProcessHeap(), 0, Path
);
4939 TRACE("Writing shortcut to %s\n",debugstr_w(target_file
));
4940 IPersistFile_Save(pf
,target_file
,FALSE
);
4942 HeapFree(GetProcessHeap(),0,target_file
);
4944 IPersistFile_Release( pf
);
4945 IShellLinkW_Release( sl
);
4947 msiobj_release(&row
->hdr
);
4949 MSI_ViewClose(view
);
4950 msiobj_release(&view
->hdr
);
4960 * 99% of the work done here is only done for
4961 * advertised installs. However this is where the
4962 * Icon table is processed and written out
4963 * so that is what I am going to do here.
4965 static UINT
ACTION_PublishProduct(MSIPACKAGE
*package
)
4969 MSIRECORD
* row
= 0;
4970 static const WCHAR Query
[]=
4971 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
4974 /* for registry stuff */
4978 static const WCHAR szProductName
[] =
4979 {'P','r','o','d','u','c','t','N','a','m','e',0};
4980 static const WCHAR szPackageCode
[] =
4981 {'P','a','c','k','a','g','e','C','o','d','e',0};
4984 MSIHANDLE hDb
, hSumInfo
;
4987 return ERROR_INVALID_HANDLE
;
4989 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
4990 if (rc
!= ERROR_SUCCESS
)
4993 rc
= MSI_ViewExecute(view
, 0);
4994 if (rc
!= ERROR_SUCCESS
)
4996 MSI_ViewClose(view
);
4997 msiobj_release(&view
->hdr
);
5004 WCHAR
*FilePath
=NULL
;
5005 WCHAR
*FileName
=NULL
;
5008 rc
= MSI_ViewFetch(view
,&row
);
5009 if (rc
!= ERROR_SUCCESS
)
5015 FileName
= load_dynamic_stringW(row
,1);
5018 ERR("Unable to get FileName\n");
5019 msiobj_release(&row
->hdr
);
5023 build_icon_path(package
,FileName
,&FilePath
);
5025 HeapFree(GetProcessHeap(),0,FileName
);
5027 TRACE("Creating icon file at %s\n",debugstr_w(FilePath
));
5029 the_file
= CreateFileW(FilePath
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
5030 FILE_ATTRIBUTE_NORMAL
, NULL
);
5032 if (the_file
== INVALID_HANDLE_VALUE
)
5034 ERR("Unable to create file %s\n",debugstr_w(FilePath
));
5035 msiobj_release(&row
->hdr
);
5036 HeapFree(GetProcessHeap(),0,FilePath
);
5044 rc
= MSI_RecordReadStream(row
,2,buffer
,&sz
);
5045 if (rc
!= ERROR_SUCCESS
)
5047 ERR("Failed to get stream\n");
5048 CloseHandle(the_file
);
5049 DeleteFileW(FilePath
);
5052 WriteFile(the_file
,buffer
,sz
,&write
,NULL
);
5053 } while (sz
== 1024);
5055 HeapFree(GetProcessHeap(),0,FilePath
);
5057 CloseHandle(the_file
);
5058 msiobj_release(&row
->hdr
);
5060 MSI_ViewClose(view
);
5061 msiobj_release(&view
->hdr
);
5064 /* ok there is a lot more done here but i need to figure out what */
5065 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
5069 rc
= MSIREG_OpenProductsKey(productcode
,&hkey
,TRUE
);
5070 if (rc
!= ERROR_SUCCESS
)
5073 rc
= MSIREG_OpenUserProductsKey(productcode
,&hukey
,TRUE
);
5074 if (rc
!= ERROR_SUCCESS
)
5078 buffer
= load_dynamic_property(package
,szProductName
,NULL
);
5079 size
= strlenW(buffer
)*sizeof(WCHAR
);
5080 RegSetValueExW(hukey
,szProductName
,0,REG_SZ
, (LPSTR
)buffer
,size
);
5081 HeapFree(GetProcessHeap(),0,buffer
);
5082 FIXME("Need to write more keys to the user registry\n");
5084 hDb
= alloc_msihandle( &package
->db
->hdr
);
5085 rc
= MsiGetSummaryInformationW(hDb
, NULL
, 0, &hSumInfo
);
5086 MsiCloseHandle(hDb
);
5087 if (rc
== ERROR_SUCCESS
)
5089 WCHAR guidbuffer
[0x200];
5091 rc
= MsiSummaryInfoGetPropertyW(hSumInfo
, 9, NULL
, NULL
, NULL
,
5093 if (rc
== ERROR_SUCCESS
)
5095 WCHAR squashed
[GUID_SIZE
];
5096 /* for now we only care about the first guid */
5097 LPWSTR ptr
= strchrW(guidbuffer
,';');
5099 squash_guid(guidbuffer
,squashed
);
5100 size
= strlenW(squashed
)*sizeof(WCHAR
);
5101 RegSetValueExW(hukey
,szPackageCode
,0,REG_SZ
, (LPSTR
)squashed
,
5106 ERR("Unable to query Revision_Number... \n");
5109 MsiCloseHandle(hSumInfo
);
5113 ERR("Unable to open Summary Information\n");
5119 HeapFree(GetProcessHeap(),0,productcode
);
5126 static UINT
ACTION_WriteIniValues(MSIPACKAGE
*package
)
5130 MSIRECORD
* row
= 0;
5131 static const WCHAR ExecSeqQuery
[] =
5132 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5133 'I','n','i','F','i','l','e',0};
5134 static const WCHAR szWindowsFolder
[] =
5135 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
5137 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
5138 if (rc
!= ERROR_SUCCESS
)
5140 TRACE("no IniFile table\n");
5141 return ERROR_SUCCESS
;
5144 rc
= MSI_ViewExecute(view
, 0);
5145 if (rc
!= ERROR_SUCCESS
)
5147 MSI_ViewClose(view
);
5148 msiobj_release(&view
->hdr
);
5154 LPWSTR component
,filename
,dirproperty
,section
,key
,value
,identifier
;
5155 LPWSTR deformated_section
, deformated_key
, deformated_value
;
5156 LPWSTR folder
, fullname
= NULL
;
5158 INT component_index
,action
;
5160 rc
= MSI_ViewFetch(view
,&row
);
5161 if (rc
!= ERROR_SUCCESS
)
5167 component
= load_dynamic_stringW(row
, 8);
5168 component_index
= get_loaded_component(package
,component
);
5169 HeapFree(GetProcessHeap(),0,component
);
5171 if (!ACTION_VerifyComponentForAction(package
, component_index
,
5172 INSTALLSTATE_LOCAL
))
5174 TRACE("Skipping ini file due to disabled component\n");
5175 msiobj_release(&row
->hdr
);
5177 package
->components
[component_index
].Action
=
5178 package
->components
[component_index
].Installed
;
5183 package
->components
[component_index
].Action
= INSTALLSTATE_LOCAL
;
5185 identifier
= load_dynamic_stringW(row
,1);
5186 filename
= load_dynamic_stringW(row
,2);
5187 dirproperty
= load_dynamic_stringW(row
,3);
5188 section
= load_dynamic_stringW(row
,4);
5189 key
= load_dynamic_stringW(row
,5);
5190 value
= load_dynamic_stringW(row
,6);
5191 action
= MSI_RecordGetInteger(row
,7);
5193 deformat_string(package
,section
,&deformated_section
);
5194 deformat_string(package
,key
,&deformated_key
);
5195 deformat_string(package
,value
,&deformated_value
);
5199 folder
= resolve_folder(package
, dirproperty
, FALSE
, FALSE
, NULL
);
5201 folder
= load_dynamic_property(package
,dirproperty
,NULL
);
5204 folder
= load_dynamic_property(package
, szWindowsFolder
, NULL
);
5208 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty
));
5212 fullname
= build_directory_name(3, folder
, filename
, NULL
);
5216 TRACE("Adding value %s to section %s in %s\n",
5217 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
5218 debugstr_w(fullname
));
5219 WritePrivateProfileStringW(deformated_section
, deformated_key
,
5220 deformated_value
, fullname
);
5222 else if (action
== 1)
5225 GetPrivateProfileStringW(deformated_section
, deformated_key
, NULL
,
5226 returned
, 10, fullname
);
5227 if (returned
[0] == 0)
5229 TRACE("Adding value %s to section %s in %s\n",
5230 debugstr_w(deformated_key
), debugstr_w(deformated_section
),
5231 debugstr_w(fullname
));
5233 WritePrivateProfileStringW(deformated_section
, deformated_key
,
5234 deformated_value
, fullname
);
5237 else if (action
== 3)
5239 FIXME("Append to existing section not yet implemented\n");
5242 uirow
= MSI_CreateRecord(4);
5243 MSI_RecordSetStringW(uirow
,1,identifier
);
5244 MSI_RecordSetStringW(uirow
,2,deformated_section
);
5245 MSI_RecordSetStringW(uirow
,3,deformated_key
);
5246 MSI_RecordSetStringW(uirow
,4,deformated_value
);
5247 ui_actiondata(package
,szWriteIniValues
,uirow
);
5248 msiobj_release( &uirow
->hdr
);
5250 HeapFree(GetProcessHeap(),0,identifier
);
5251 HeapFree(GetProcessHeap(),0,fullname
);
5252 HeapFree(GetProcessHeap(),0,filename
);
5253 HeapFree(GetProcessHeap(),0,key
);
5254 HeapFree(GetProcessHeap(),0,value
);
5255 HeapFree(GetProcessHeap(),0,section
);
5256 HeapFree(GetProcessHeap(),0,dirproperty
);
5257 HeapFree(GetProcessHeap(),0,folder
);
5258 HeapFree(GetProcessHeap(),0,deformated_key
);
5259 HeapFree(GetProcessHeap(),0,deformated_value
);
5260 HeapFree(GetProcessHeap(),0,deformated_section
);
5261 msiobj_release(&row
->hdr
);
5263 MSI_ViewClose(view
);
5264 msiobj_release(&view
->hdr
);
5268 static UINT
ACTION_SelfRegModules(MSIPACKAGE
*package
)
5272 MSIRECORD
* row
= 0;
5273 static const WCHAR ExecSeqQuery
[] =
5274 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5275 'S','e','l','f','R','e','g',0};
5277 static const WCHAR ExeStr
[] =
5278 {'r','e','g','s','v','r','3','2','.','e','x','e',' ','/','s',' ',0};
5280 PROCESS_INFORMATION info
;
5283 memset(&si
,0,sizeof(STARTUPINFOW
));
5285 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
5286 if (rc
!= ERROR_SUCCESS
)
5288 TRACE("no SelfReg table\n");
5289 return ERROR_SUCCESS
;
5292 rc
= MSI_ViewExecute(view
, 0);
5293 if (rc
!= ERROR_SUCCESS
)
5295 MSI_ViewClose(view
);
5296 msiobj_release(&view
->hdr
);
5306 rc
= MSI_ViewFetch(view
,&row
);
5307 if (rc
!= ERROR_SUCCESS
)
5313 filename
= load_dynamic_stringW(row
,1);
5314 index
= get_loaded_file(package
,filename
);
5318 ERR("Unable to find file id %s\n",debugstr_w(filename
));
5319 HeapFree(GetProcessHeap(),0,filename
);
5320 msiobj_release(&row
->hdr
);
5323 HeapFree(GetProcessHeap(),0,filename
);
5325 len
= strlenW(ExeStr
);
5326 len
+= strlenW(package
->files
[index
].TargetPath
);
5329 filename
= HeapAlloc(GetProcessHeap(),0,len
*sizeof(WCHAR
));
5330 strcpyW(filename
,ExeStr
);
5331 strcatW(filename
,package
->files
[index
].TargetPath
);
5333 TRACE("Registering %s\n",debugstr_w(filename
));
5334 brc
= CreateProcessW(NULL
, filename
, NULL
, NULL
, FALSE
, 0, NULL
,
5335 c_colon
, &si
, &info
);
5338 msi_dialog_check_messages(package
->dialog
, info
.hProcess
);
5340 HeapFree(GetProcessHeap(),0,filename
);
5341 msiobj_release(&row
->hdr
);
5343 MSI_ViewClose(view
);
5344 msiobj_release(&view
->hdr
);
5348 static UINT
ACTION_PublishFeatures(MSIPACKAGE
*package
)
5357 return ERROR_INVALID_HANDLE
;
5359 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
5363 rc
= MSIREG_OpenFeaturesKey(productcode
,&hkey
,TRUE
);
5364 if (rc
!= ERROR_SUCCESS
)
5367 rc
= MSIREG_OpenUserFeaturesKey(productcode
,&hukey
,TRUE
);
5368 if (rc
!= ERROR_SUCCESS
)
5371 /* here the guids are base 85 encoded */
5372 for (i
= 0; i
< package
->loaded_features
; i
++)
5379 if (!ACTION_VerifyFeatureForAction(package
,i
,INSTALLSTATE_LOCAL
))
5382 size
= package
->features
[i
].ComponentCount
*21;
5384 if (package
->features
[i
].Feature_Parent
[0])
5385 size
+= strlenW(package
->features
[i
].Feature_Parent
)+2;
5387 data
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
5390 for (j
= 0; j
< package
->features
[i
].ComponentCount
; j
++)
5393 memset(buf
,0,sizeof(buf
));
5394 TRACE("From %s\n",debugstr_w(package
->components
5395 [package
->features
[i
].Components
[j
]].ComponentId
));
5396 CLSIDFromString(package
->components
5397 [package
->features
[i
].Components
[j
]].ComponentId
,
5399 encode_base85_guid(&clsid
,buf
);
5400 TRACE("to %s\n",debugstr_w(buf
));
5403 if (package
->features
[i
].Feature_Parent
[0])
5405 static const WCHAR sep
[] = {'\2',0};
5407 strcatW(data
,package
->features
[i
].Feature_Parent
);
5410 size
= (strlenW(data
)+1)*sizeof(WCHAR
);
5411 RegSetValueExW(hkey
,package
->features
[i
].Feature
,0,REG_SZ
,
5413 HeapFree(GetProcessHeap(),0,data
);
5415 size
= strlenW(package
->features
[i
].Feature_Parent
)*sizeof(WCHAR
);
5416 RegSetValueExW(hukey
,package
->features
[i
].Feature
,0,REG_SZ
,
5417 (LPSTR
)package
->features
[i
].Feature_Parent
,size
);
5423 HeapFree(GetProcessHeap(), 0, productcode
);
5427 static UINT
ACTION_RegisterProduct(MSIPACKAGE
*package
)
5434 static WCHAR szNONE
[] = {0};
5435 static const WCHAR szWindowsInstaler
[] =
5436 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
5437 static const WCHAR szPropKeys
[][80] =
5439 {'A','R','P','A','U','T','H','O','R','I','Z','E','D','C','D','F','P','R','E','F','I','X',0},
5440 {'A','R','P','C','O','N','T','A','C','T',0},
5441 {'A','R','P','C','O','M','M','E','N','T','S',0},
5442 {'P','r','o','d','u','c','t','N','a','m','e',0},
5443 {'P','r','o','d','u','c','t','V','e','r','s','i','o','n',0},
5444 {'A','R','P','H','E','L','P','L','I','N','K',0},
5445 {'A','R','P','H','E','L','P','T','E','L','E','P','H','O','N','E',0},
5446 {'A','R','P','I','N','S','T','A','L','L','L','O','C','A','T','I','O','N',0},
5447 {'S','o','u','r','c','e','D','i','r',0},
5448 {'M','a','n','u','f','a','c','t','u','r','e','r',0},
5449 {'A','R','P','R','E','A','D','M','E',0},
5450 {'A','R','P','S','I','Z','E',0},
5451 {'A','R','P','U','R','L','I','N','F','O','A','B','O','U','T',0},
5452 {'A','R','P','U','R','L','U','P','D','A','T','E','I','N','F','O',0},
5456 static const WCHAR szRegKeys
[][80] =
5458 {'A','u','t','h','o','r','i','z','e','d','C','D','F','P','r','e','f','i','x',0},
5459 {'C','o','n','t','a','c','t',0},
5460 {'C','o','m','m','e','n','t','s',0},
5461 {'D','i','s','p','l','a','y','N','a','m','e',0},
5462 {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0},
5463 {'H','e','l','p','L','i','n','k',0},
5464 {'H','e','l','p','T','e','l','e','p','h','o','n','e',0},
5465 {'I','n','s','t','a','l','l','L','o','c','a','t','i','o','n',0},
5466 {'I','n','s','t','a','l','l','S','o','u','r','c','e',0},
5467 {'P','u','b','l','i','s','h','e','r',0},
5468 {'R','e','a','d','m','e',0},
5469 {'S','i','z','e',0},
5470 {'U','R','L','I','n','f','o','A','b','o','u','t',0},
5471 {'U','R','L','U','p','d','a','t','e','I','n','f','o',0},
5475 static const WCHAR installerPathFmt
[] = {
5477 'I','n','s','t','a','l','l','e','r','\\',0};
5478 static const WCHAR fmt
[] = {
5480 'I','n','s','t','a','l','l','e','r','\\',
5481 '%','x','.','m','s','i',0};
5482 static const WCHAR szLocalPackage
[]=
5483 {'L','o','c','a','l','P','a','c','k','a','g','e',0};
5484 WCHAR windir
[MAX_PATH
], path
[MAX_PATH
], packagefile
[MAX_PATH
];
5488 return ERROR_INVALID_HANDLE
;
5490 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
5494 rc
= MSIREG_OpenUninstallKey(productcode
,&hkey
,TRUE
);
5495 if (rc
!= ERROR_SUCCESS
)
5498 /* dump all the info i can grab */
5499 FIXME("Flesh out more information \n");
5502 while (szPropKeys
[i
][0]!=0)
5504 buffer
= load_dynamic_property(package
,szPropKeys
[i
],&rc
);
5505 if (rc
!= ERROR_SUCCESS
)
5507 size
= strlenW(buffer
)*sizeof(WCHAR
);
5508 RegSetValueExW(hkey
,szRegKeys
[i
],0,REG_SZ
,(LPSTR
)buffer
,size
);
5514 RegSetValueExW(hkey
,szWindowsInstaler
,0,REG_DWORD
,(LPSTR
)&rc
,size
);
5516 /* copy the package locally */
5517 num
= GetTickCount() & 0xffff;
5521 GetWindowsDirectoryW(windir
, sizeof(windir
) / sizeof(windir
[0]));
5522 snprintfW(packagefile
,sizeof(packagefile
)/sizeof(packagefile
[0]),fmt
,
5526 HANDLE handle
= CreateFileW(packagefile
,GENERIC_WRITE
, 0, NULL
,
5527 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
5528 if (handle
!= INVALID_HANDLE_VALUE
)
5530 CloseHandle(handle
);
5533 if (GetLastError() != ERROR_FILE_EXISTS
&&
5534 GetLastError() != ERROR_SHARING_VIOLATION
)
5536 if (!(++num
& 0xffff)) num
= 1;
5537 sprintfW(packagefile
,fmt
,num
);
5538 } while (num
!= start
);
5540 snprintfW(path
,sizeof(path
)/sizeof(path
[0]),installerPathFmt
,windir
);
5541 create_full_pathW(path
);
5542 TRACE("Copying to local package %s\n",debugstr_w(packagefile
));
5543 CopyFileW(package
->PackagePath
,packagefile
,FALSE
);
5544 size
= strlenW(packagefile
)*sizeof(WCHAR
);
5545 RegSetValueExW(hkey
,szLocalPackage
,0,REG_SZ
,(LPSTR
)packagefile
,size
);
5548 HeapFree(GetProcessHeap(),0,productcode
);
5551 return ERROR_SUCCESS
;
5554 static UINT
ACTION_InstallExecute(MSIPACKAGE
*package
)
5558 return ERROR_INVALID_HANDLE
;
5560 for (i
= 0; i
< package
->DeferredActionCount
; i
++)
5563 action
= package
->DeferredAction
[i
];
5564 ui_actionstart(package
, action
);
5565 TRACE("Executing Action (%s)\n",debugstr_w(action
));
5566 ACTION_CustomAction(package
,action
,TRUE
);
5567 HeapFree(GetProcessHeap(),0,package
->DeferredAction
[i
]);
5569 HeapFree(GetProcessHeap(),0,package
->DeferredAction
);
5571 package
->DeferredActionCount
= 0;
5572 package
->DeferredAction
= NULL
;
5574 return ERROR_SUCCESS
;
5577 static UINT
ACTION_InstallFinalize(MSIPACKAGE
*package
)
5581 return ERROR_INVALID_HANDLE
;
5583 /* first do the same as an InstallExecute */
5584 ACTION_InstallExecute(package
);
5586 /* then handle Commit Actions */
5587 for (i
= 0; i
< package
->CommitActionCount
; i
++)
5590 action
= package
->CommitAction
[i
];
5591 ui_actionstart(package
, action
);
5592 TRACE("Executing Commit Action (%s)\n",debugstr_w(action
));
5593 ACTION_CustomAction(package
,action
,TRUE
);
5594 HeapFree(GetProcessHeap(),0,package
->CommitAction
[i
]);
5596 HeapFree(GetProcessHeap(),0,package
->CommitAction
);
5598 package
->CommitActionCount
= 0;
5599 package
->CommitAction
= NULL
;
5601 return ERROR_SUCCESS
;
5604 static UINT
ACTION_ForceReboot(MSIPACKAGE
*package
)
5606 static const WCHAR RunOnce
[] = {
5607 'S','o','f','t','w','a','r','e','\\',
5608 'M','i','c','r','o','s','o','f','t','\\',
5609 'W','i','n','d','o','w','s','\\',
5610 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5611 'R','u','n','O','n','c','e',0};
5612 static const WCHAR InstallRunOnce
[] = {
5613 'S','o','f','t','w','a','r','e','\\',
5614 'M','i','c','r','o','s','o','f','t','\\',
5615 'W','i','n','d','o','w','s','\\',
5616 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
5617 'I','n','s','t','a','l','l','e','r','\\',
5618 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
5620 static const WCHAR msiexec_fmt
[] = {
5622 '\\','M','s','i','E','x','e','c','.','e','x','e',' ','/','@',' ',
5623 '\"','%','s','\"',0};
5624 static const WCHAR install_fmt
[] = {
5625 '/','I',' ','\"','%','s','\"',' ',
5626 'A','F','T','E','R','R','E','B','O','O','T','=','1',' ',
5627 'R','U','N','O','N','C','E','E','N','T','R','Y','=','\"','%','s','\"',0};
5628 WCHAR buffer
[256], sysdir
[MAX_PATH
];
5631 WCHAR squished_pc
[100];
5634 static const WCHAR szLUS
[] = {
5635 'L','a','s','t','U','s','e','d','S','o','u','r','c','e',0};
5636 static const WCHAR szSourceList
[] = {
5637 'S','o','u','r','c','e','L','i','s','t',0};
5638 static const WCHAR szPackageName
[] = {
5639 'P','a','c','k','a','g','e','N','a','m','e',0};
5642 return ERROR_INVALID_HANDLE
;
5644 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
5648 squash_guid(productcode
,squished_pc
);
5650 GetSystemDirectoryW(sysdir
, sizeof(sysdir
)/sizeof(sysdir
[0]));
5651 RegCreateKeyW(HKEY_LOCAL_MACHINE
,RunOnce
,&hkey
);
5652 snprintfW(buffer
,sizeof(buffer
)/sizeof(buffer
[0]),msiexec_fmt
,sysdir
,
5655 size
= strlenW(buffer
)*sizeof(WCHAR
);
5656 RegSetValueExW(hkey
,squished_pc
,0,REG_SZ
,(LPSTR
)buffer
,size
);
5659 TRACE("Reboot command %s\n",debugstr_w(buffer
));
5661 RegCreateKeyW(HKEY_LOCAL_MACHINE
,InstallRunOnce
,&hkey
);
5662 sprintfW(buffer
,install_fmt
,productcode
,squished_pc
);
5664 size
= strlenW(buffer
)*sizeof(WCHAR
);
5665 RegSetValueExW(hkey
,squished_pc
,0,REG_SZ
,(LPSTR
)buffer
,size
);
5668 rc
= MSIREG_OpenUserProductsKey(productcode
,&hukey
,TRUE
);
5669 if (rc
== ERROR_SUCCESS
)
5673 RegCreateKeyW(hukey
, szSourceList
, &hukey2
);
5674 buf
= load_dynamic_property(package
,cszSourceDir
,NULL
);
5675 size
= strlenW(buf
)*sizeof(WCHAR
);
5676 RegSetValueExW(hukey2
,szLUS
,0,REG_SZ
,(LPSTR
)buf
,size
);
5677 HeapFree(GetProcessHeap(),0,buf
);
5679 buf
= strrchrW(package
->PackagePath
,'\\');
5683 size
= strlenW(buf
)*sizeof(WCHAR
);
5684 RegSetValueExW(hukey2
,szPackageName
,0,REG_SZ
,(LPSTR
)buf
,size
);
5687 RegCloseKey(hukey2
);
5689 HeapFree(GetProcessHeap(),0,productcode
);
5691 return ERROR_INSTALL_SUSPEND
;
5694 UINT
ACTION_ResolveSource(MSIPACKAGE
* package
)
5697 * we are currently doing what should be done here in the top level Install
5698 * however for Adminastrative and uninstalls this step will be needed
5700 return ERROR_SUCCESS
;
5704 static UINT
ACTION_RegisterExtensionInfo(MSIPACKAGE
*package
)
5708 MSIRECORD
* row
= 0;
5709 static const WCHAR ExecSeqQuery
[] =
5710 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5711 'E','x','t','e','n','s','i','o','n',0};
5712 static const WCHAR szContentType
[] =
5713 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
5717 return ERROR_INVALID_HANDLE
;
5719 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
5720 if (rc
!= ERROR_SUCCESS
)
5726 rc
= MSI_ViewExecute(view
, 0);
5727 if (rc
!= ERROR_SUCCESS
)
5729 MSI_ViewClose(view
);
5730 msiobj_release(&view
->hdr
);
5736 WCHAR buffer
[0x100];
5737 WCHAR extension
[257];
5742 rc
= MSI_ViewFetch(view
,&row
);
5743 if (rc
!= ERROR_SUCCESS
)
5750 MSI_RecordGetStringW(row
,2,buffer
,&sz
);
5752 index
= get_loaded_component(package
,buffer
);
5756 msiobj_release(&row
->hdr
);
5760 if (!ACTION_VerifyComponentForAction(package
, index
,
5761 INSTALLSTATE_LOCAL
))
5763 TRACE("Skipping extension reg due to disabled component\n");
5764 msiobj_release(&row
->hdr
);
5766 package
->components
[index
].Action
=
5767 package
->components
[index
].Installed
;
5772 package
->components
[index
].Action
= INSTALLSTATE_LOCAL
;
5774 exten
= load_dynamic_stringW(row
,1);
5777 strcatW(extension
,exten
);
5778 HeapFree(GetProcessHeap(),0,exten
);
5780 RegCreateKeyW(HKEY_CLASSES_ROOT
,extension
,&hkey
);
5782 if (!MSI_RecordIsNull(row
,4))
5784 LPWSTR mime
= load_dynamic_stringW(row
,4);
5785 RegSetValueExW(hkey
,szContentType
,0,REG_SZ
,(LPVOID
)mime
,
5786 (strlenW(mime
)+1)*sizeof(WCHAR
));
5787 HeapFree(GetProcessHeap(),0,mime
);
5790 if (!MSI_RecordIsNull(row
,3))
5792 static const WCHAR szSN
[] =
5793 {'\\','S','h','e','l','l','N','e','w',0};
5796 LPWSTR progid
= load_dynamic_stringW(row
,3);
5798 RegSetValueExW(hkey
,NULL
,0,REG_SZ
,(LPVOID
)progid
,
5799 (strlenW(progid
)+1)*sizeof(WCHAR
));
5801 newkey
= HeapAlloc(GetProcessHeap(),0,
5802 (strlenW(progid
)+strlenW(szSN
)+1) * sizeof(WCHAR
));
5804 strcpyW(newkey
,progid
);
5805 strcatW(newkey
,szSN
);
5806 RegCreateKeyW(hkey
,newkey
,&hkey2
);
5809 HeapFree(GetProcessHeap(),0,progid
);
5810 HeapFree(GetProcessHeap(),0,newkey
);
5816 ui_actiondata(package
,szRegisterExtensionInfo
,row
);
5818 msiobj_release(&row
->hdr
);
5820 MSI_ViewClose(view
);
5821 msiobj_release(&view
->hdr
);
5827 static UINT
ACTION_RegisterMIMEInfo(MSIPACKAGE
*package
)
5831 MSIRECORD
* row
= 0;
5832 static const WCHAR ExecSeqQuery
[] =
5833 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
5835 static const WCHAR szExten
[] =
5836 {'E','x','t','e','n','s','i','o','n',0 };
5840 return ERROR_INVALID_HANDLE
;
5842 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
5843 if (rc
!= ERROR_SUCCESS
)
5849 rc
= MSI_ViewExecute(view
, 0);
5850 if (rc
!= ERROR_SUCCESS
)
5852 MSI_ViewClose(view
);
5853 msiobj_release(&view
->hdr
);
5859 WCHAR extension
[257];
5862 static const WCHAR fmt
[] =
5863 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
5864 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
5867 rc
= MSI_ViewFetch(view
,&row
);
5868 if (rc
!= ERROR_SUCCESS
)
5874 mime
= load_dynamic_stringW(row
,1);
5875 exten
= load_dynamic_stringW(row
,2);
5878 strcatW(extension
,exten
);
5879 HeapFree(GetProcessHeap(),0,exten
);
5881 key
= HeapAlloc(GetProcessHeap(),0,(strlenW(mime
)+strlenW(fmt
)+1) *
5883 sprintfW(key
,fmt
,mime
);
5884 RegCreateKeyW(HKEY_CLASSES_ROOT
,key
,&hkey
);
5885 RegSetValueExW(hkey
,szExten
,0,REG_SZ
,(LPVOID
)extension
,
5886 (strlenW(extension
)+1)*sizeof(WCHAR
));
5888 HeapFree(GetProcessHeap(),0,mime
);
5889 HeapFree(GetProcessHeap(),0,key
);
5891 if (!MSI_RecordIsNull(row
,3))
5893 FIXME("Handle non null for field 3\n");
5898 ui_actiondata(package
,szRegisterMIMEInfo
,row
);
5900 msiobj_release(&row
->hdr
);
5902 MSI_ViewClose(view
);
5903 msiobj_release(&view
->hdr
);
5909 static UINT
ACTION_RegisterUser(MSIPACKAGE
*package
)
5911 static const WCHAR szProductID
[]=
5912 {'P','r','o','d','u','c','t','I','D',0};
5920 static const WCHAR szPropKeys
[][80] =
5922 {'P','r','o','d','u','c','t','I','D',0},
5923 {'U','S','E','R','N','A','M','E',0},
5924 {'C','O','M','P','A','N','Y','N','A','M','E',0},
5928 static const WCHAR szRegKeys
[][80] =
5930 {'P','r','o','d','u','c','t','I','D',0},
5931 {'R','e','g','O','w','n','e','r',0},
5932 {'R','e','g','C','o','m','p','a','n','y',0},
5937 return ERROR_INVALID_HANDLE
;
5939 productid
= load_dynamic_property(package
,szProductID
,&rc
);
5941 return ERROR_SUCCESS
;
5943 productcode
= load_dynamic_property(package
,szProductCode
,&rc
);
5947 rc
= MSIREG_OpenUninstallKey(productcode
,&hkey
,TRUE
);
5948 if (rc
!= ERROR_SUCCESS
)
5952 while (szPropKeys
[i
][0]!=0)
5954 buffer
= load_dynamic_property(package
,szPropKeys
[i
],&rc
);
5955 if (rc
== ERROR_SUCCESS
)
5957 size
= strlenW(buffer
)*sizeof(WCHAR
);
5958 RegSetValueExW(hkey
,szRegKeys
[i
],0,REG_SZ
,(LPSTR
)buffer
,size
);
5964 HeapFree(GetProcessHeap(),0,productcode
);
5965 HeapFree(GetProcessHeap(),0,productid
);
5968 return ERROR_SUCCESS
;
5972 static UINT
ACTION_ExecuteAction(MSIPACKAGE
*package
)
5975 rc
= ACTION_ProcessExecSequence(package
,TRUE
);
5981 * Code based off of code located here
5982 * http://www.codeproject.com/gdi/fontnamefromfile.asp
5984 * Using string index 4 (full font name) instead of 1 (family name)
5986 static LPWSTR
load_ttfname_from(LPCWSTR filename
)
5992 typedef struct _tagTT_OFFSET_TABLE
{
5993 USHORT uMajorVersion
;
5994 USHORT uMinorVersion
;
5995 USHORT uNumOfTables
;
5996 USHORT uSearchRange
;
5997 USHORT uEntrySelector
;
6001 typedef struct _tagTT_TABLE_DIRECTORY
{
6002 char szTag
[4]; /* table name */
6003 ULONG uCheckSum
; /* Check sum */
6004 ULONG uOffset
; /* Offset from beginning of file */
6005 ULONG uLength
; /* length of the table in bytes */
6006 }TT_TABLE_DIRECTORY
;
6008 typedef struct _tagTT_NAME_TABLE_HEADER
{
6009 USHORT uFSelector
; /* format selector. Always 0 */
6010 USHORT uNRCount
; /* Name Records count */
6011 USHORT uStorageOffset
; /* Offset for strings storage,
6012 * from start of the table */
6013 }TT_NAME_TABLE_HEADER
;
6015 typedef struct _tagTT_NAME_RECORD
{
6020 USHORT uStringLength
;
6021 USHORT uStringOffset
; /* from start of storage area */
6024 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
6025 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
6027 handle
= CreateFileW(filename
,GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
6028 FILE_ATTRIBUTE_NORMAL
, 0 );
6029 if (handle
!= INVALID_HANDLE_VALUE
)
6031 TT_TABLE_DIRECTORY tblDir
;
6032 BOOL bFound
= FALSE
;
6033 TT_OFFSET_TABLE ttOffsetTable
;
6035 ReadFile(handle
,&ttOffsetTable
, sizeof(TT_OFFSET_TABLE
),NULL
,NULL
);
6036 ttOffsetTable
.uNumOfTables
= SWAPWORD(ttOffsetTable
.uNumOfTables
);
6037 ttOffsetTable
.uMajorVersion
= SWAPWORD(ttOffsetTable
.uMajorVersion
);
6038 ttOffsetTable
.uMinorVersion
= SWAPWORD(ttOffsetTable
.uMinorVersion
);
6040 if (ttOffsetTable
.uMajorVersion
!= 1 ||
6041 ttOffsetTable
.uMinorVersion
!= 0)
6044 for (i
=0; i
< ttOffsetTable
.uNumOfTables
; i
++)
6046 ReadFile(handle
,&tblDir
, sizeof(TT_TABLE_DIRECTORY
),NULL
,NULL
);
6047 if (strncmp(tblDir
.szTag
,"name",4)==0)
6050 tblDir
.uLength
= SWAPLONG(tblDir
.uLength
);
6051 tblDir
.uOffset
= SWAPLONG(tblDir
.uOffset
);
6058 TT_NAME_TABLE_HEADER ttNTHeader
;
6059 TT_NAME_RECORD ttRecord
;
6061 SetFilePointer(handle
, tblDir
.uOffset
, NULL
, FILE_BEGIN
);
6062 ReadFile(handle
,&ttNTHeader
, sizeof(TT_NAME_TABLE_HEADER
),
6065 ttNTHeader
.uNRCount
= SWAPWORD(ttNTHeader
.uNRCount
);
6066 ttNTHeader
.uStorageOffset
= SWAPWORD(ttNTHeader
.uStorageOffset
);
6068 for(i
=0; i
<ttNTHeader
.uNRCount
; i
++)
6070 ReadFile(handle
,&ttRecord
, sizeof(TT_NAME_RECORD
),NULL
,NULL
);
6071 ttRecord
.uNameID
= SWAPWORD(ttRecord
.uNameID
);
6072 /* 4 is the Full Font Name */
6073 if(ttRecord
.uNameID
== 4)
6077 static const LPSTR tt
= " (TrueType)";
6079 ttRecord
.uStringLength
= SWAPWORD(ttRecord
.uStringLength
);
6080 ttRecord
.uStringOffset
= SWAPWORD(ttRecord
.uStringOffset
);
6081 nPos
= SetFilePointer(handle
, 0, NULL
, FILE_CURRENT
);
6082 SetFilePointer(handle
, tblDir
.uOffset
+
6083 ttRecord
.uStringOffset
+
6084 ttNTHeader
.uStorageOffset
,
6086 buf
= HeapAlloc(GetProcessHeap(), 0,
6087 ttRecord
.uStringLength
+ 1 + strlen(tt
));
6088 memset(buf
, 0, ttRecord
.uStringLength
+ 1 + strlen(tt
));
6089 ReadFile(handle
, buf
, ttRecord
.uStringLength
, NULL
, NULL
);
6090 if (strlen(buf
) > 0)
6093 ret
= strdupAtoW(buf
);
6094 HeapFree(GetProcessHeap(),0,buf
);
6098 HeapFree(GetProcessHeap(),0,buf
);
6099 SetFilePointer(handle
,nPos
, NULL
, FILE_BEGIN
);
6103 CloseHandle(handle
);
6106 TRACE("Returning fontname %s\n",debugstr_w(ret
));
6110 static UINT
ACTION_RegisterFonts(MSIPACKAGE
*package
)
6114 MSIRECORD
* row
= 0;
6115 static const WCHAR ExecSeqQuery
[] =
6116 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
6118 static const WCHAR regfont1
[] =
6119 {'S','o','f','t','w','a','r','e','\\',
6120 'M','i','c','r','o','s','o','f','t','\\',
6121 'W','i','n','d','o','w','s',' ','N','T','\\',
6122 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6123 'F','o','n','t','s',0};
6124 static const WCHAR regfont2
[] =
6125 {'S','o','f','t','w','a','r','e','\\',
6126 'M','i','c','r','o','s','o','f','t','\\',
6127 'W','i','n','d','o','w','s','\\',
6128 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
6129 'F','o','n','t','s',0};
6133 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
6134 if (rc
!= ERROR_SUCCESS
)
6137 rc
= MSI_ViewExecute(view
, 0);
6138 if (rc
!= ERROR_SUCCESS
)
6140 MSI_ViewClose(view
);
6141 msiobj_release(&view
->hdr
);
6145 RegCreateKeyW(HKEY_LOCAL_MACHINE
,regfont1
,&hkey1
);
6146 RegCreateKeyW(HKEY_LOCAL_MACHINE
,regfont2
,&hkey2
);
6155 rc
= MSI_ViewFetch(view
,&row
);
6156 if (rc
!= ERROR_SUCCESS
)
6162 file
= load_dynamic_stringW(row
,1);
6163 index
= get_loaded_file(package
,file
);
6166 ERR("Unable to load file\n");
6167 HeapFree(GetProcessHeap(),0,file
);
6171 /* check to make sure that component is installed */
6172 if (!ACTION_VerifyComponentForAction(package
,
6173 package
->files
[index
].ComponentIndex
, INSTALLSTATE_LOCAL
))
6175 TRACE("Skipping: Component not scheduled for install\n");
6176 HeapFree(GetProcessHeap(),0,file
);
6178 msiobj_release(&row
->hdr
);
6183 if (MSI_RecordIsNull(row
,2))
6184 name
= load_ttfname_from(package
->files
[index
].TargetPath
);
6186 name
= load_dynamic_stringW(row
,2);
6190 size
= strlenW(package
->files
[index
].FileName
) * sizeof(WCHAR
);
6191 RegSetValueExW(hkey1
,name
,0,REG_SZ
,
6192 (LPBYTE
)package
->files
[index
].FileName
,size
);
6193 RegSetValueExW(hkey2
,name
,0,REG_SZ
,
6194 (LPBYTE
)package
->files
[index
].FileName
,size
);
6197 HeapFree(GetProcessHeap(),0,file
);
6198 HeapFree(GetProcessHeap(),0,name
);
6199 msiobj_release(&row
->hdr
);
6201 MSI_ViewClose(view
);
6202 msiobj_release(&view
->hdr
);
6210 /* Msi functions that seem appropriate here */
6211 UINT WINAPI
MsiDoActionA( MSIHANDLE hInstall
, LPCSTR szAction
)
6216 TRACE(" exteral attempt at action %s\n",szAction
);
6219 return ERROR_FUNCTION_FAILED
;
6221 return ERROR_FUNCTION_FAILED
;
6223 szwAction
= strdupAtoW(szAction
);
6226 return ERROR_FUNCTION_FAILED
;
6229 rc
= MsiDoActionW(hInstall
, szwAction
);
6230 HeapFree(GetProcessHeap(),0,szwAction
);
6234 UINT WINAPI
MsiDoActionW( MSIHANDLE hInstall
, LPCWSTR szAction
)
6236 MSIPACKAGE
*package
;
6237 UINT ret
= ERROR_INVALID_HANDLE
;
6239 TRACE(" external attempt at action %s \n",debugstr_w(szAction
));
6241 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
6244 ret
= ACTION_PerformUIAction(package
,szAction
);
6245 msiobj_release( &package
->hdr
);
6250 UINT WINAPI
MsiGetTargetPathA( MSIHANDLE hInstall
, LPCSTR szFolder
,
6251 LPSTR szPathBuf
, DWORD
* pcchPathBuf
)
6257 TRACE("getting folder %s %p %li\n",szFolder
,szPathBuf
, *pcchPathBuf
);
6260 return ERROR_FUNCTION_FAILED
;
6262 return ERROR_FUNCTION_FAILED
;
6264 szwFolder
= strdupAtoW(szFolder
);
6267 return ERROR_FUNCTION_FAILED
;
6269 szwPathBuf
= HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf
* sizeof(WCHAR
));
6271 rc
= MsiGetTargetPathW(hInstall
, szwFolder
, szwPathBuf
,pcchPathBuf
);
6273 WideCharToMultiByte( CP_ACP
, 0, szwPathBuf
, *pcchPathBuf
, szPathBuf
,
6274 *pcchPathBuf
, NULL
, NULL
);
6276 HeapFree(GetProcessHeap(),0,szwFolder
);
6277 HeapFree(GetProcessHeap(),0,szwPathBuf
);
6282 UINT WINAPI
MsiGetTargetPathW( MSIHANDLE hInstall
, LPCWSTR szFolder
, LPWSTR
6283 szPathBuf
, DWORD
* pcchPathBuf
)
6286 UINT rc
= ERROR_FUNCTION_FAILED
;
6287 MSIPACKAGE
*package
;
6289 TRACE("(%s %p %li)\n",debugstr_w(szFolder
),szPathBuf
,*pcchPathBuf
);
6291 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
6293 return ERROR_INVALID_HANDLE
;
6294 path
= resolve_folder(package
, szFolder
, FALSE
, FALSE
, NULL
);
6295 msiobj_release( &package
->hdr
);
6297 if (path
&& (strlenW(path
) > *pcchPathBuf
))
6299 *pcchPathBuf
= strlenW(path
)+1;
6300 rc
= ERROR_MORE_DATA
;
6304 *pcchPathBuf
= strlenW(path
)+1;
6305 strcpyW(szPathBuf
,path
);
6306 TRACE("Returning Path %s\n",debugstr_w(path
));
6309 HeapFree(GetProcessHeap(),0,path
);
6315 UINT WINAPI
MsiGetSourcePathA( MSIHANDLE hInstall
, LPCSTR szFolder
,
6316 LPSTR szPathBuf
, DWORD
* pcchPathBuf
)
6322 TRACE("getting source %s %p %li\n",szFolder
,szPathBuf
, *pcchPathBuf
);
6325 return ERROR_FUNCTION_FAILED
;
6327 return ERROR_FUNCTION_FAILED
;
6329 szwFolder
= strdupAtoW(szFolder
);
6331 return ERROR_FUNCTION_FAILED
;
6333 szwPathBuf
= HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf
* sizeof(WCHAR
));
6335 rc
= MsiGetSourcePathW(hInstall
, szwFolder
, szwPathBuf
,pcchPathBuf
);
6337 WideCharToMultiByte( CP_ACP
, 0, szwPathBuf
, *pcchPathBuf
, szPathBuf
,
6338 *pcchPathBuf
, NULL
, NULL
);
6340 HeapFree(GetProcessHeap(),0,szwFolder
);
6341 HeapFree(GetProcessHeap(),0,szwPathBuf
);
6346 UINT WINAPI
MsiGetSourcePathW( MSIHANDLE hInstall
, LPCWSTR szFolder
, LPWSTR
6347 szPathBuf
, DWORD
* pcchPathBuf
)
6350 UINT rc
= ERROR_FUNCTION_FAILED
;
6351 MSIPACKAGE
*package
;
6353 TRACE("(%s %p %li)\n",debugstr_w(szFolder
),szPathBuf
,*pcchPathBuf
);
6355 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
6357 return ERROR_INVALID_HANDLE
;
6358 path
= resolve_folder(package
, szFolder
, TRUE
, FALSE
, NULL
);
6359 msiobj_release( &package
->hdr
);
6361 if (path
&& strlenW(path
) > *pcchPathBuf
)
6363 *pcchPathBuf
= strlenW(path
)+1;
6364 rc
= ERROR_MORE_DATA
;
6368 *pcchPathBuf
= strlenW(path
)+1;
6369 strcpyW(szPathBuf
,path
);
6370 TRACE("Returning Path %s\n",debugstr_w(path
));
6373 HeapFree(GetProcessHeap(),0,path
);
6379 UINT WINAPI
MsiSetTargetPathA(MSIHANDLE hInstall
, LPCSTR szFolder
,
6380 LPCSTR szFolderPath
)
6383 LPWSTR szwFolderPath
;
6387 return ERROR_FUNCTION_FAILED
;
6389 return ERROR_FUNCTION_FAILED
;
6391 szwFolder
= strdupAtoW(szFolder
);
6393 return ERROR_FUNCTION_FAILED
;
6395 szwFolderPath
= strdupAtoW(szFolderPath
);
6398 HeapFree(GetProcessHeap(),0,szwFolder
);
6399 return ERROR_FUNCTION_FAILED
;
6402 rc
= MsiSetTargetPathW(hInstall
, szwFolder
, szwFolderPath
);
6404 HeapFree(GetProcessHeap(),0,szwFolder
);
6405 HeapFree(GetProcessHeap(),0,szwFolderPath
);
6410 UINT
MSI_SetTargetPathW(MSIPACKAGE
*package
, LPCWSTR szFolder
,
6411 LPCWSTR szFolderPath
)
6415 LPWSTR path2
= NULL
;
6418 TRACE("(%p %s %s)\n",package
, debugstr_w(szFolder
),debugstr_w(szFolderPath
));
6421 return ERROR_INVALID_HANDLE
;
6423 if (szFolderPath
[0]==0)
6424 return ERROR_FUNCTION_FAILED
;
6426 if (GetFileAttributesW(szFolderPath
) == INVALID_FILE_ATTRIBUTES
)
6427 return ERROR_FUNCTION_FAILED
;
6429 path
= resolve_folder(package
,szFolder
,FALSE
,FALSE
,&folder
);
6432 return ERROR_INVALID_PARAMETER
;
6434 HeapFree(GetProcessHeap(),0,folder
->Property
);
6435 folder
->Property
= build_directory_name(2, szFolderPath
, NULL
);
6437 if (strcmpiW(path
, folder
->Property
) == 0)
6440 * Resolved Target has not really changed, so just
6441 * set this folder and do not recalculate everything.
6443 HeapFree(GetProcessHeap(),0,folder
->ResolvedTarget
);
6444 folder
->ResolvedTarget
= NULL
;
6445 path2
= resolve_folder(package
,szFolder
,FALSE
,TRUE
,NULL
);
6446 HeapFree(GetProcessHeap(),0,path2
);
6450 for (i
= 0; i
< package
->loaded_folders
; i
++)
6452 HeapFree(GetProcessHeap(),0,package
->folders
[i
].ResolvedTarget
);
6453 package
->folders
[i
].ResolvedTarget
=NULL
;
6456 for (i
= 0; i
< package
->loaded_folders
; i
++)
6458 path2
=resolve_folder(package
, package
->folders
[i
].Directory
, FALSE
,
6460 HeapFree(GetProcessHeap(),0,path2
);
6463 HeapFree(GetProcessHeap(),0,path
);
6465 return ERROR_SUCCESS
;
6468 UINT WINAPI
MsiSetTargetPathW(MSIHANDLE hInstall
, LPCWSTR szFolder
,
6469 LPCWSTR szFolderPath
)
6471 MSIPACKAGE
*package
;
6474 TRACE("(%s %s)\n",debugstr_w(szFolder
),debugstr_w(szFolderPath
));
6476 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
6477 ret
= MSI_SetTargetPathW( package
, szFolder
, szFolderPath
);
6478 msiobj_release( &package
->hdr
);
6482 /***********************************************************************
6483 * MsiGetMode (MSI.@)
6485 * Returns an internal installer state (if it is running in a mode iRunMode)
6488 * hInstall [I] Handle to the installation
6489 * hRunMode [I] Checking run mode
6490 * MSIRUNMODE_ADMIN Administrative mode
6491 * MSIRUNMODE_ADVERTISE Advertisement mode
6492 * MSIRUNMODE_MAINTENANCE Maintenance mode
6493 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
6494 * MSIRUNMODE_LOGENABLED Log file is writing
6495 * MSIRUNMODE_OPERATIONS Operations in progress??
6496 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
6497 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
6498 * MSIRUNMODE_CABINET Files from cabinet are installed
6499 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is suppressed
6500 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is suppressed
6501 * MSIRUNMODE_RESERVED11 Reserved
6502 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
6503 * MSIRUNMODE_ZAWENABLED Demand installation is supported
6504 * MSIRUNMODE_RESERVED14 Reserved
6505 * MSIRUNMODE_RESERVED15 Reserved
6506 * MSIRUNMODE_SCHEDULED called from install script
6507 * MSIRUNMODE_ROLLBACK called from rollback script
6508 * MSIRUNMODE_COMMIT called from commit script
6511 * In the state: TRUE
6512 * Not in the state: FALSE
6516 BOOL WINAPI
MsiGetMode(MSIHANDLE hInstall
, MSIRUNMODE iRunMode
)
6518 FIXME("STUB (iRunMode=%i)\n",iRunMode
);
6523 * According to the docs, when this is called it immediately recalculates
6524 * all the component states as well
6526 UINT WINAPI
MsiSetFeatureStateA(MSIHANDLE hInstall
, LPCSTR szFeature
,
6527 INSTALLSTATE iState
)
6529 LPWSTR szwFeature
= NULL
;
6532 szwFeature
= strdupAtoW(szFeature
);
6535 return ERROR_FUNCTION_FAILED
;
6537 rc
= MsiSetFeatureStateW(hInstall
,szwFeature
, iState
);
6539 HeapFree(GetProcessHeap(),0,szwFeature
);
6544 UINT WINAPI
MsiSetFeatureStateW(MSIHANDLE hInstall
, LPCWSTR szFeature
,
6545 INSTALLSTATE iState
)
6547 MSIPACKAGE
* package
;
6550 TRACE(" %s to %i\n",debugstr_w(szFeature
), iState
);
6552 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
6554 return ERROR_INVALID_HANDLE
;
6556 index
= get_loaded_feature(package
,szFeature
);
6558 return ERROR_UNKNOWN_FEATURE
;
6560 package
->features
[index
].ActionRequest
= iState
;
6561 ACTION_UpdateComponentStates(package
,szFeature
);
6563 return ERROR_SUCCESS
;
6566 UINT WINAPI
MsiGetFeatureStateA(MSIHANDLE hInstall
, LPSTR szFeature
,
6567 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
6569 LPWSTR szwFeature
= NULL
;
6572 szwFeature
= strdupAtoW(szFeature
);
6574 rc
= MsiGetFeatureStateW(hInstall
,szwFeature
,piInstalled
, piAction
);
6576 HeapFree( GetProcessHeap(), 0 , szwFeature
);
6581 UINT
MSI_GetFeatureStateW(MSIPACKAGE
*package
, LPWSTR szFeature
,
6582 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
6586 index
= get_loaded_feature(package
,szFeature
);
6588 return ERROR_UNKNOWN_FEATURE
;
6591 *piInstalled
= package
->features
[index
].Installed
;
6594 *piAction
= package
->features
[index
].Action
;
6596 TRACE("returning %i %i\n",*piInstalled
,*piAction
);
6598 return ERROR_SUCCESS
;
6601 UINT WINAPI
MsiGetFeatureStateW(MSIHANDLE hInstall
, LPWSTR szFeature
,
6602 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
6604 MSIPACKAGE
* package
;
6607 TRACE("%ld %s %p %p\n", hInstall
, debugstr_w(szFeature
), piInstalled
,
6610 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
6612 return ERROR_INVALID_HANDLE
;
6613 ret
= MSI_GetFeatureStateW(package
, szFeature
, piInstalled
, piAction
);
6614 msiobj_release( &package
->hdr
);
6618 UINT WINAPI
MsiGetComponentStateA(MSIHANDLE hInstall
, LPSTR szComponent
,
6619 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
6621 LPWSTR szwComponent
= NULL
;
6624 szwComponent
= strdupAtoW(szComponent
);
6626 rc
= MsiGetComponentStateW(hInstall
,szwComponent
,piInstalled
, piAction
);
6628 HeapFree( GetProcessHeap(), 0 , szwComponent
);
6633 UINT
MSI_GetComponentStateW(MSIPACKAGE
*package
, LPWSTR szComponent
,
6634 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
6638 TRACE("%p %s %p %p\n", package
, debugstr_w(szComponent
), piInstalled
,
6641 index
= get_loaded_component(package
,szComponent
);
6643 return ERROR_UNKNOWN_COMPONENT
;
6646 *piInstalled
= package
->components
[index
].Installed
;
6649 *piAction
= package
->components
[index
].Action
;
6651 TRACE("states (%i, %i)\n",
6652 (piInstalled
)?*piInstalled
:-1,(piAction
)?*piAction
:-1);
6654 return ERROR_SUCCESS
;
6657 UINT WINAPI
MsiGetComponentStateW(MSIHANDLE hInstall
, LPWSTR szComponent
,
6658 INSTALLSTATE
*piInstalled
, INSTALLSTATE
*piAction
)
6660 MSIPACKAGE
* package
;
6663 TRACE("%ld %s %p %p\n", hInstall
, debugstr_w(szComponent
),
6664 piInstalled
, piAction
);
6666 package
= msihandle2msiinfo(hInstall
, MSIHANDLETYPE_PACKAGE
);
6668 return ERROR_INVALID_HANDLE
;
6669 ret
= MSI_GetComponentStateW( package
, szComponent
, piInstalled
, piAction
);
6670 msiobj_release( &package
->hdr
);
6675 static UINT
ACTION_Template(MSIPACKAGE
*package
)
6679 MSIRECORD
* row
= 0;
6680 static const WCHAR ExecSeqQuery
[] = {0};
6682 rc
= MSI_DatabaseOpenViewW(package
->db
, ExecSeqQuery
, &view
);
6683 if (rc
!= ERROR_SUCCESS
)
6686 rc
= MSI_ViewExecute(view
, 0);
6687 if (rc
!= ERROR_SUCCESS
)
6689 MSI_ViewClose(view
);
6690 msiobj_release(&view
->hdr
);
6696 rc
= MSI_ViewFetch(view
,&row
);
6697 if (rc
!= ERROR_SUCCESS
)
6703 msiobj_release(&row
->hdr
);
6705 MSI_ViewClose(view
);
6706 msiobj_release(&view
->hdr
);