[MSI] Sync with Wine Staging 1.7.37. CORE-9246
[reactos.git] / reactos / dll / win32 / msi / msi.c
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
3 *
4 * Copyright 2002,2003,2004,2005 Mike McCormack for CodeWeavers
5 *
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.
10 *
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.
15 *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "msipriv.h"
22
23 #include <softpub.h>
24 #include <initguid.h>
25 #include <msxml2.h>
26
27 WINE_DEFAULT_DEBUG_CHANNEL(msi);
28
29 static const WCHAR installerW[] = {'\\','I','n','s','t','a','l','l','e','r',0};
30
31 UINT msi_locate_product(LPCWSTR szProduct, MSIINSTALLCONTEXT *context)
32 {
33 HKEY hkey = NULL;
34
35 *context = MSIINSTALLCONTEXT_NONE;
36 if (!szProduct) return ERROR_UNKNOWN_PRODUCT;
37
38 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
39 &hkey, FALSE) == ERROR_SUCCESS)
40 *context = MSIINSTALLCONTEXT_USERMANAGED;
41 else if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
42 &hkey, FALSE) == ERROR_SUCCESS)
43 *context = MSIINSTALLCONTEXT_MACHINE;
44 else if (MSIREG_OpenProductKey(szProduct, NULL,
45 MSIINSTALLCONTEXT_USERUNMANAGED,
46 &hkey, FALSE) == ERROR_SUCCESS)
47 *context = MSIINSTALLCONTEXT_USERUNMANAGED;
48
49 RegCloseKey(hkey);
50
51 if (*context == MSIINSTALLCONTEXT_NONE)
52 return ERROR_UNKNOWN_PRODUCT;
53
54 return ERROR_SUCCESS;
55 }
56
57 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
58 {
59 UINT r;
60 LPWSTR szwProd = NULL;
61
62 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
63
64 if( szProduct )
65 {
66 szwProd = strdupAtoW( szProduct );
67 if( !szwProd )
68 return ERROR_OUTOFMEMORY;
69 }
70
71 r = MsiOpenProductW( szwProd, phProduct );
72
73 msi_free( szwProd );
74
75 return r;
76 }
77
78 static UINT MSI_OpenProductW(LPCWSTR szProduct, MSIPACKAGE **package)
79 {
80 UINT r;
81 HKEY props;
82 LPWSTR path;
83 MSIINSTALLCONTEXT context;
84
85 static const WCHAR managed[] = {
86 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
87 static const WCHAR local[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
88
89 TRACE("%s %p\n", debugstr_w(szProduct), package);
90
91 r = msi_locate_product(szProduct, &context);
92 if (r != ERROR_SUCCESS)
93 return r;
94
95 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &props, FALSE);
96 if (r != ERROR_SUCCESS)
97 return ERROR_UNKNOWN_PRODUCT;
98
99 if (context == MSIINSTALLCONTEXT_USERMANAGED)
100 path = msi_reg_get_val_str(props, managed);
101 else
102 path = msi_reg_get_val_str(props, local);
103
104 r = ERROR_UNKNOWN_PRODUCT;
105
106 if (!path || GetFileAttributesW(path) == INVALID_FILE_ATTRIBUTES)
107 goto done;
108
109 if (PathIsRelativeW(path))
110 {
111 r = ERROR_INSTALL_PACKAGE_OPEN_FAILED;
112 goto done;
113 }
114
115 r = MSI_OpenPackageW(path, package);
116
117 done:
118 RegCloseKey(props);
119 msi_free(path);
120 return r;
121 }
122
123 UINT WINAPI MsiOpenProductW(LPCWSTR szProduct, MSIHANDLE *phProduct)
124 {
125 MSIPACKAGE *package = NULL;
126 WCHAR squished_pc[GUID_SIZE];
127 UINT r;
128
129 if (!szProduct || !squash_guid(szProduct, squished_pc))
130 return ERROR_INVALID_PARAMETER;
131
132 if (!phProduct)
133 return ERROR_INVALID_PARAMETER;
134
135 r = MSI_OpenProductW(szProduct, &package);
136 if (r != ERROR_SUCCESS)
137 return r;
138
139 *phProduct = alloc_msihandle(&package->hdr);
140 if (!*phProduct)
141 r = ERROR_NOT_ENOUGH_MEMORY;
142
143 msiobj_release(&package->hdr);
144 return r;
145 }
146
147 UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
148 LPCSTR szTransforms, LANGID lgidLanguage)
149 {
150 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath),
151 debugstr_a(szScriptfilePath), debugstr_a(szTransforms), lgidLanguage);
152 return ERROR_CALL_NOT_IMPLEMENTED;
153 }
154
155 UINT WINAPI MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
156 LPCWSTR szTransforms, LANGID lgidLanguage)
157 {
158 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath),
159 debugstr_w(szScriptfilePath), debugstr_w(szTransforms), lgidLanguage);
160 return ERROR_CALL_NOT_IMPLEMENTED;
161 }
162
163 UINT WINAPI MsiAdvertiseProductExA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
164 LPCSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
165 {
166 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath),
167 debugstr_a(szScriptfilePath), debugstr_a(szTransforms),
168 lgidLanguage, dwPlatform, dwOptions);
169 return ERROR_CALL_NOT_IMPLEMENTED;
170 }
171
172 UINT WINAPI MsiAdvertiseProductExW( LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
173 LPCWSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
174 {
175 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath),
176 debugstr_w(szScriptfilePath), debugstr_w(szTransforms),
177 lgidLanguage, dwPlatform, dwOptions);
178 return ERROR_CALL_NOT_IMPLEMENTED;
179 }
180
181 UINT WINAPI MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)
182 {
183 LPWSTR szwPath = NULL, szwCommand = NULL;
184 UINT r = ERROR_OUTOFMEMORY;
185
186 TRACE("%s %s\n",debugstr_a(szPackagePath), debugstr_a(szCommandLine));
187
188 if( szPackagePath )
189 {
190 szwPath = strdupAtoW( szPackagePath );
191 if( !szwPath )
192 goto end;
193 }
194
195 if( szCommandLine )
196 {
197 szwCommand = strdupAtoW( szCommandLine );
198 if( !szwCommand )
199 goto end;
200 }
201
202 r = MsiInstallProductW( szwPath, szwCommand );
203
204 end:
205 msi_free( szwPath );
206 msi_free( szwCommand );
207
208 return r;
209 }
210
211 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
212 {
213 MSIPACKAGE *package = NULL;
214 UINT r;
215
216 TRACE("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
217
218 if (!szPackagePath)
219 return ERROR_INVALID_PARAMETER;
220
221 if (!*szPackagePath)
222 return ERROR_PATH_NOT_FOUND;
223
224 r = MSI_OpenPackageW( szPackagePath, &package );
225 if (r == ERROR_SUCCESS)
226 {
227 r = MSI_InstallPackage( package, szPackagePath, szCommandLine );
228 msiobj_release( &package->hdr );
229 }
230
231 return r;
232 }
233
234 UINT WINAPI MsiReinstallProductA(LPCSTR szProduct, DWORD dwReinstallMode)
235 {
236 LPWSTR wszProduct;
237 UINT rc;
238
239 TRACE("%s %08x\n", debugstr_a(szProduct), dwReinstallMode);
240
241 wszProduct = strdupAtoW(szProduct);
242
243 rc = MsiReinstallProductW(wszProduct, dwReinstallMode);
244
245 msi_free(wszProduct);
246 return rc;
247 }
248
249 UINT WINAPI MsiReinstallProductW(LPCWSTR szProduct, DWORD dwReinstallMode)
250 {
251 TRACE("%s %08x\n", debugstr_w(szProduct), dwReinstallMode);
252
253 return MsiReinstallFeatureW(szProduct, szAll, dwReinstallMode);
254 }
255
256 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
257 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
258 {
259 LPWSTR patch_package = NULL;
260 LPWSTR install_package = NULL;
261 LPWSTR command_line = NULL;
262 UINT r = ERROR_OUTOFMEMORY;
263
264 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
265 eInstallType, debugstr_a(szCommandLine));
266
267 if (szPatchPackage && !(patch_package = strdupAtoW(szPatchPackage)))
268 goto done;
269
270 if (szInstallPackage && !(install_package = strdupAtoW(szInstallPackage)))
271 goto done;
272
273 if (szCommandLine && !(command_line = strdupAtoW(szCommandLine)))
274 goto done;
275
276 r = MsiApplyPatchW(patch_package, install_package, eInstallType, command_line);
277
278 done:
279 msi_free(patch_package);
280 msi_free(install_package);
281 msi_free(command_line);
282
283 return r;
284 }
285
286 static UINT get_patch_product_codes( LPCWSTR szPatchPackage, WCHAR ***product_codes )
287 {
288 MSIHANDLE patch, info = 0;
289 UINT r, type;
290 DWORD size;
291 static WCHAR empty[] = {0};
292 WCHAR *codes = NULL;
293
294 r = MsiOpenDatabaseW( szPatchPackage, MSIDBOPEN_READONLY, &patch );
295 if (r != ERROR_SUCCESS)
296 return r;
297
298 r = MsiGetSummaryInformationW( patch, NULL, 0, &info );
299 if (r != ERROR_SUCCESS)
300 goto done;
301
302 size = 0;
303 r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, empty, &size );
304 if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
305 {
306 ERR("Failed to read product codes from patch\n");
307 r = ERROR_FUNCTION_FAILED;
308 goto done;
309 }
310
311 codes = msi_alloc( ++size * sizeof(WCHAR) );
312 if (!codes)
313 {
314 r = ERROR_OUTOFMEMORY;
315 goto done;
316 }
317
318 r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, codes, &size );
319 if (r == ERROR_SUCCESS)
320 *product_codes = msi_split_string( codes, ';' );
321
322 done:
323 MsiCloseHandle( info );
324 MsiCloseHandle( patch );
325 msi_free( codes );
326 return r;
327 }
328
329 static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWSTR szCommandLine)
330 {
331 UINT i, r = ERROR_FUNCTION_FAILED;
332 DWORD size;
333 LPCWSTR cmd_ptr = szCommandLine;
334 LPWSTR cmd, *codes = NULL;
335 BOOL succeeded = FALSE;
336
337 static const WCHAR fmt[] = {'%','s',' ','P','A','T','C','H','=','"','%','s','"',0};
338 static const WCHAR empty[] = {0};
339
340 if (!szPatchPackage || !szPatchPackage[0])
341 return ERROR_INVALID_PARAMETER;
342
343 if (!szProductCode && (r = get_patch_product_codes( szPatchPackage, &codes )))
344 return r;
345
346 if (!szCommandLine)
347 cmd_ptr = empty;
348
349 size = strlenW(cmd_ptr) + strlenW(fmt) + strlenW(szPatchPackage) + 1;
350 cmd = msi_alloc(size * sizeof(WCHAR));
351 if (!cmd)
352 {
353 msi_free(codes);
354 return ERROR_OUTOFMEMORY;
355 }
356 sprintfW(cmd, fmt, cmd_ptr, szPatchPackage);
357
358 if (szProductCode)
359 r = MsiConfigureProductExW(szProductCode, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
360 else
361 {
362 for (i = 0; codes[i]; i++)
363 {
364 r = MsiConfigureProductExW(codes[i], INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
365 if (r == ERROR_SUCCESS)
366 {
367 TRACE("patch applied\n");
368 succeeded = TRUE;
369 }
370 }
371
372 if (succeeded)
373 r = ERROR_SUCCESS;
374 }
375
376 msi_free(cmd);
377 msi_free(codes);
378 return r;
379 }
380
381 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
382 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
383 {
384 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
385 eInstallType, debugstr_w(szCommandLine));
386
387 if (szInstallPackage || eInstallType == INSTALLTYPE_NETWORK_IMAGE ||
388 eInstallType == INSTALLTYPE_SINGLE_INSTANCE)
389 {
390 FIXME("Only reading target products from patch\n");
391 return ERROR_CALL_NOT_IMPLEMENTED;
392 }
393
394 return MSI_ApplyPatchW(szPatchPackage, NULL, szCommandLine);
395 }
396
397 UINT WINAPI MsiApplyMultiplePatchesA(LPCSTR szPatchPackages,
398 LPCSTR szProductCode, LPCSTR szPropertiesList)
399 {
400 LPWSTR patch_packages = NULL;
401 LPWSTR product_code = NULL;
402 LPWSTR properties_list = NULL;
403 UINT r = ERROR_OUTOFMEMORY;
404
405 TRACE("%s %s %s\n", debugstr_a(szPatchPackages), debugstr_a(szProductCode),
406 debugstr_a(szPropertiesList));
407
408 if (!szPatchPackages || !szPatchPackages[0])
409 return ERROR_INVALID_PARAMETER;
410
411 if (!(patch_packages = strdupAtoW(szPatchPackages)))
412 return ERROR_OUTOFMEMORY;
413
414 if (szProductCode && !(product_code = strdupAtoW(szProductCode)))
415 goto done;
416
417 if (szPropertiesList && !(properties_list = strdupAtoW(szPropertiesList)))
418 goto done;
419
420 r = MsiApplyMultiplePatchesW(patch_packages, product_code, properties_list);
421
422 done:
423 msi_free(patch_packages);
424 msi_free(product_code);
425 msi_free(properties_list);
426
427 return r;
428 }
429
430 UINT WINAPI MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages,
431 LPCWSTR szProductCode, LPCWSTR szPropertiesList)
432 {
433 UINT r = ERROR_SUCCESS;
434 LPCWSTR beg, end;
435
436 TRACE("%s %s %s\n", debugstr_w(szPatchPackages), debugstr_w(szProductCode),
437 debugstr_w(szPropertiesList));
438
439 if (!szPatchPackages || !szPatchPackages[0])
440 return ERROR_INVALID_PARAMETER;
441
442 beg = end = szPatchPackages;
443 while (*beg)
444 {
445 DWORD len;
446 LPWSTR patch;
447
448 while (*beg == ' ') beg++;
449 while (*end && *end != ';') end++;
450
451 len = end - beg;
452 while (len && beg[len - 1] == ' ') len--;
453
454 if (!len) return ERROR_INVALID_NAME;
455
456 patch = msi_alloc((len + 1) * sizeof(WCHAR));
457 if (!patch)
458 return ERROR_OUTOFMEMORY;
459
460 memcpy(patch, beg, len * sizeof(WCHAR));
461 patch[len] = '\0';
462
463 r = MSI_ApplyPatchW(patch, szProductCode, szPropertiesList);
464 msi_free(patch);
465
466 if (r != ERROR_SUCCESS)
467 break;
468
469 beg = ++end;
470 }
471 return r;
472 }
473
474 static void free_patchinfo( DWORD count, MSIPATCHSEQUENCEINFOW *info )
475 {
476 DWORD i;
477 for (i = 0; i < count; i++) msi_free( (WCHAR *)info[i].szPatchData );
478 msi_free( info );
479 }
480
481 static MSIPATCHSEQUENCEINFOW *patchinfoAtoW( DWORD count, const MSIPATCHSEQUENCEINFOA *info )
482 {
483 DWORD i;
484 MSIPATCHSEQUENCEINFOW *ret;
485
486 if (!(ret = msi_alloc( count * sizeof(MSIPATCHSEQUENCEINFOW) ))) return NULL;
487 for (i = 0; i < count; i++)
488 {
489 if (info[i].szPatchData && !(ret[i].szPatchData = strdupAtoW( info[i].szPatchData )))
490 {
491 free_patchinfo( i, ret );
492 return NULL;
493 }
494 ret[i].ePatchDataType = info[i].ePatchDataType;
495 ret[i].dwOrder = info[i].dwOrder;
496 ret[i].uStatus = info[i].uStatus;
497 }
498 return ret;
499 }
500
501 UINT WINAPI MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath,
502 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
503 {
504 UINT i, r;
505 WCHAR *package_path = NULL;
506 MSIPATCHSEQUENCEINFOW *psi;
507
508 TRACE("%s, %u, %p\n", debugstr_a(szProductPackagePath), cPatchInfo, pPatchInfo);
509
510 if (szProductPackagePath && !(package_path = strdupAtoW( szProductPackagePath )))
511 return ERROR_OUTOFMEMORY;
512
513 if (!(psi = patchinfoAtoW( cPatchInfo, pPatchInfo )))
514 {
515 msi_free( package_path );
516 return ERROR_OUTOFMEMORY;
517 }
518 r = MsiDetermineApplicablePatchesW( package_path, cPatchInfo, psi );
519 if (r == ERROR_SUCCESS)
520 {
521 for (i = 0; i < cPatchInfo; i++)
522 {
523 pPatchInfo[i].dwOrder = psi[i].dwOrder;
524 pPatchInfo[i].uStatus = psi[i].uStatus;
525 }
526 }
527 msi_free( package_path );
528 free_patchinfo( cPatchInfo, psi );
529 return r;
530 }
531
532 static UINT MSI_ApplicablePatchW( MSIPACKAGE *package, LPCWSTR patch )
533 {
534 MSISUMMARYINFO *si;
535 MSIDATABASE *patch_db;
536 UINT r = ERROR_SUCCESS;
537
538 r = MSI_OpenDatabaseW( patch, MSIDBOPEN_READONLY, &patch_db );
539 if (r != ERROR_SUCCESS)
540 {
541 WARN("failed to open patch file %s\n", debugstr_w(patch));
542 return r;
543 }
544
545 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
546 if (!si)
547 {
548 msiobj_release( &patch_db->hdr );
549 return ERROR_FUNCTION_FAILED;
550 }
551
552 r = msi_check_patch_applicable( package, si );
553 if (r != ERROR_SUCCESS)
554 TRACE("patch not applicable\n");
555
556 msiobj_release( &patch_db->hdr );
557 msiobj_release( &si->hdr );
558 return r;
559 }
560
561 /* IXMLDOMDocument should be set to XPath mode already */
562 static UINT MSI_ApplicablePatchXML( MSIPACKAGE *package, IXMLDOMDocument *desc )
563 {
564 static const WCHAR queryW[] = {'M','s','i','P','a','t','c','h','/',
565 'T','a','r','g','e','t','P','r','o','d','u','c','t','/',
566 'T','a','r','g','e','t','P','r','o','d','u','c','t','C','o','d','e',0};
567 UINT r = ERROR_FUNCTION_FAILED;
568 IXMLDOMNodeList *list;
569 LPWSTR product_code;
570 IXMLDOMNode *node;
571 HRESULT hr;
572 BSTR s;
573
574 product_code = msi_dup_property( package->db, szProductCode );
575 if (!product_code)
576 {
577 /* FIXME: the property ProductCode should be written into the DB somewhere */
578 ERR("no product code to check\n");
579 return ERROR_SUCCESS;
580 }
581
582 s = SysAllocString(queryW);
583 hr = IXMLDOMDocument_selectNodes( desc, s, &list );
584 SysFreeString(s);
585 if (hr != S_OK)
586 return ERROR_INVALID_PATCH_XML;
587
588 while (IXMLDOMNodeList_nextNode( list, &node ) == S_OK && r != ERROR_SUCCESS)
589 {
590 hr = IXMLDOMNode_get_text( node, &s );
591 IXMLDOMNode_Release( node );
592 if (hr == S_OK)
593 {
594 if (!strcmpW( s, product_code )) r = ERROR_SUCCESS;
595 SysFreeString( s );
596 }
597 }
598 IXMLDOMNodeList_Release( list );
599
600 if (r != ERROR_SUCCESS)
601 TRACE("patch not applicable\n");
602
603 msi_free( product_code );
604 return r;
605 }
606
607 static UINT determine_patch_sequence( MSIPACKAGE *package, DWORD count, MSIPATCHSEQUENCEINFOW *info )
608 {
609 IXMLDOMDocument *desc = NULL;
610 DWORD i;
611
612 if (count > 1)
613 FIXME("patch ordering not supported\n");
614
615 for (i = 0; i < count; i++)
616 {
617 switch (info[i].ePatchDataType)
618 {
619 case MSIPATCH_DATATYPE_PATCHFILE:
620 {
621 if (MSI_ApplicablePatchW( package, info[i].szPatchData ) != ERROR_SUCCESS)
622 {
623 info[i].dwOrder = ~0u;
624 info[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
625 }
626 else
627 {
628 info[i].dwOrder = i;
629 info[i].uStatus = ERROR_SUCCESS;
630 }
631 break;
632 }
633 case MSIPATCH_DATATYPE_XMLPATH:
634 case MSIPATCH_DATATYPE_XMLBLOB:
635 {
636 VARIANT_BOOL b;
637 HRESULT hr;
638 BSTR s;
639
640 if (!desc)
641 {
642 hr = CoCreateInstance( &CLSID_DOMDocument30, NULL, CLSCTX_INPROC_SERVER,
643 &IID_IXMLDOMDocument, (void**)&desc );
644 if (hr != S_OK)
645 {
646 ERR("failed to create DOMDocument30 instance, 0x%08x\n", hr);
647 return ERROR_FUNCTION_FAILED;
648 }
649 }
650
651 s = SysAllocString( info[i].szPatchData );
652 if (info[i].ePatchDataType == MSIPATCH_DATATYPE_XMLPATH)
653 {
654 VARIANT src;
655
656 V_VT(&src) = VT_BSTR;
657 V_BSTR(&src) = s;
658 hr = IXMLDOMDocument_load( desc, src, &b );
659 }
660 else
661 hr = IXMLDOMDocument_loadXML( desc, s, &b );
662 SysFreeString( s );
663 if ( hr != S_OK )
664 {
665 ERR("failed to parse patch description\n");
666 IXMLDOMDocument_Release( desc );
667 break;
668 }
669
670 if (MSI_ApplicablePatchXML( package, desc ) != ERROR_SUCCESS)
671 {
672 info[i].dwOrder = ~0u;
673 info[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
674 }
675 else
676 {
677 info[i].dwOrder = i;
678 info[i].uStatus = ERROR_SUCCESS;
679 }
680 break;
681 }
682 default:
683 {
684 FIXME("unknown patch data type %u\n", info[i].ePatchDataType);
685 info[i].dwOrder = i;
686 info[i].uStatus = ERROR_SUCCESS;
687 break;
688 }
689 }
690
691 TRACE("szPatchData: %s\n", debugstr_w(info[i].szPatchData));
692 TRACE("ePatchDataType: %u\n", info[i].ePatchDataType);
693 TRACE("dwOrder: %u\n", info[i].dwOrder);
694 TRACE("uStatus: %u\n", info[i].uStatus);
695 }
696
697 if (desc) IXMLDOMDocument_Release( desc );
698
699 return ERROR_SUCCESS;
700 }
701
702 UINT WINAPI MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath,
703 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
704 {
705 UINT r;
706 MSIPACKAGE *package;
707
708 TRACE("%s, %u, %p\n", debugstr_w(szProductPackagePath), cPatchInfo, pPatchInfo);
709
710 r = MSI_OpenPackageW( szProductPackagePath, &package );
711 if (r != ERROR_SUCCESS)
712 {
713 ERR("failed to open package %u\n", r);
714 return r;
715 }
716 r = determine_patch_sequence( package, cPatchInfo, pPatchInfo );
717 msiobj_release( &package->hdr );
718 return r;
719 }
720
721 UINT WINAPI MsiDeterminePatchSequenceA( LPCSTR product, LPCSTR usersid,
722 MSIINSTALLCONTEXT context, DWORD count, PMSIPATCHSEQUENCEINFOA patchinfo )
723 {
724 UINT i, r;
725 WCHAR *productW, *usersidW = NULL;
726 MSIPATCHSEQUENCEINFOW *patchinfoW;
727
728 TRACE("%s, %s, %d, %d, %p\n", debugstr_a(product), debugstr_a(usersid),
729 context, count, patchinfo);
730
731 if (!product) return ERROR_INVALID_PARAMETER;
732 if (!(productW = strdupAtoW( product ))) return ERROR_OUTOFMEMORY;
733 if (usersid && !(usersidW = strdupAtoW( usersid )))
734 {
735 msi_free( productW );
736 return ERROR_OUTOFMEMORY;
737 }
738 if (!(patchinfoW = patchinfoAtoW( count, patchinfo )))
739 {
740 msi_free( productW );
741 msi_free( usersidW );
742 return ERROR_OUTOFMEMORY;
743 }
744 r = MsiDeterminePatchSequenceW( productW, usersidW, context, count, patchinfoW );
745 if (r == ERROR_SUCCESS)
746 {
747 for (i = 0; i < count; i++)
748 {
749 patchinfo[i].dwOrder = patchinfoW[i].dwOrder;
750 patchinfo[i].uStatus = patchinfoW[i].uStatus;
751 }
752 }
753 msi_free( productW );
754 msi_free( usersidW );
755 free_patchinfo( count, patchinfoW );
756 return r;
757 }
758
759 static UINT open_package( const WCHAR *product, const WCHAR *usersid,
760 MSIINSTALLCONTEXT context, MSIPACKAGE **package )
761 {
762 UINT r;
763 HKEY props;
764 WCHAR *localpath, sourcepath[MAX_PATH], filename[MAX_PATH];
765
766 r = MSIREG_OpenInstallProps( product, context, usersid, &props, FALSE );
767 if (r != ERROR_SUCCESS) return ERROR_BAD_CONFIGURATION;
768
769 if ((localpath = msi_reg_get_val_str( props, szLocalPackage )))
770 {
771 strcpyW( sourcepath, localpath );
772 msi_free( localpath );
773 }
774 RegCloseKey( props );
775 if (!localpath || GetFileAttributesW( sourcepath ) == INVALID_FILE_ATTRIBUTES)
776 {
777 DWORD sz = sizeof(sourcepath);
778 MsiSourceListGetInfoW( product, usersid, context, MSICODE_PRODUCT,
779 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz );
780 sz = sizeof(filename);
781 MsiSourceListGetInfoW( product, usersid, context, MSICODE_PRODUCT,
782 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz );
783 strcatW( sourcepath, filename );
784 }
785 if (GetFileAttributesW( sourcepath ) == INVALID_FILE_ATTRIBUTES)
786 return ERROR_INSTALL_SOURCE_ABSENT;
787
788 return MSI_OpenPackageW( sourcepath, package );
789 }
790
791 UINT WINAPI MsiDeterminePatchSequenceW( LPCWSTR product, LPCWSTR usersid,
792 MSIINSTALLCONTEXT context, DWORD count, PMSIPATCHSEQUENCEINFOW patchinfo )
793 {
794 UINT r;
795 MSIPACKAGE *package;
796
797 TRACE("%s, %s, %d, %d, %p\n", debugstr_w(product), debugstr_w(usersid),
798 context, count, patchinfo);
799
800 if (!product) return ERROR_INVALID_PARAMETER;
801 r = open_package( product, usersid, context, &package );
802 if (r != ERROR_SUCCESS) return r;
803
804 r = determine_patch_sequence( package, count, patchinfo );
805 msiobj_release( &package->hdr );
806 return r;
807 }
808
809 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
810 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
811 {
812 MSIPACKAGE* package = NULL;
813 MSIINSTALLCONTEXT context;
814 UINT r;
815 DWORD sz;
816 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
817 LPWSTR commandline;
818
819 static const WCHAR szInstalled[] = {
820 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
821 static const WCHAR szMaxInstallLevel[] = {
822 ' ','I','N','S','T','A','L','L','L','E','V','E','L','=','3','2','7','6','7',0};
823 static const WCHAR szRemoveAll[] = {
824 ' ','R','E','M','O','V','E','=','A','L','L',0};
825 static const WCHAR szMachine[] = {
826 ' ','A','L','L','U','S','E','R','S','=','1',0};
827
828 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
829 debugstr_w(szCommandLine));
830
831 if (!szProduct || lstrlenW(szProduct) != GUID_SIZE - 1)
832 return ERROR_INVALID_PARAMETER;
833
834 if (eInstallState == INSTALLSTATE_ADVERTISED ||
835 eInstallState == INSTALLSTATE_SOURCE)
836 {
837 FIXME("State %d not implemented\n", eInstallState);
838 return ERROR_CALL_NOT_IMPLEMENTED;
839 }
840
841 r = msi_locate_product(szProduct, &context);
842 if (r != ERROR_SUCCESS)
843 return r;
844
845 r = open_package(szProduct, NULL, context, &package);
846 if (r != ERROR_SUCCESS)
847 return r;
848
849 sz = lstrlenW(szInstalled) + 1;
850
851 if (szCommandLine)
852 sz += lstrlenW(szCommandLine);
853
854 if (eInstallState != INSTALLSTATE_DEFAULT)
855 sz += lstrlenW(szMaxInstallLevel);
856
857 if (eInstallState == INSTALLSTATE_ABSENT)
858 sz += lstrlenW(szRemoveAll);
859
860 if (context == MSIINSTALLCONTEXT_MACHINE)
861 sz += lstrlenW(szMachine);
862
863 commandline = msi_alloc(sz * sizeof(WCHAR));
864 if (!commandline)
865 {
866 r = ERROR_OUTOFMEMORY;
867 goto end;
868 }
869
870 commandline[0] = 0;
871 if (szCommandLine)
872 lstrcpyW(commandline,szCommandLine);
873
874 if (eInstallState != INSTALLSTATE_DEFAULT)
875 lstrcatW(commandline, szMaxInstallLevel);
876
877 if (eInstallState == INSTALLSTATE_ABSENT)
878 lstrcatW(commandline, szRemoveAll);
879
880 if (context == MSIINSTALLCONTEXT_MACHINE)
881 lstrcatW(commandline, szMachine);
882
883 sz = sizeof(sourcepath);
884 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
885 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
886
887 sz = sizeof(filename);
888 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
889 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
890
891 strcatW(sourcepath, filename);
892
893 r = MSI_InstallPackage( package, sourcepath, commandline );
894
895 msi_free(commandline);
896
897 end:
898 msiobj_release( &package->hdr );
899
900 return r;
901 }
902
903 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
904 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
905 {
906 LPWSTR szwProduct = NULL;
907 LPWSTR szwCommandLine = NULL;
908 UINT r = ERROR_OUTOFMEMORY;
909
910 if( szProduct )
911 {
912 szwProduct = strdupAtoW( szProduct );
913 if( !szwProduct )
914 goto end;
915 }
916
917 if( szCommandLine)
918 {
919 szwCommandLine = strdupAtoW( szCommandLine );
920 if( !szwCommandLine)
921 goto end;
922 }
923
924 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
925 szwCommandLine );
926 end:
927 msi_free( szwProduct );
928 msi_free( szwCommandLine);
929
930 return r;
931 }
932
933 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
934 INSTALLSTATE eInstallState)
935 {
936 LPWSTR szwProduct = NULL;
937 UINT r;
938
939 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
940
941 if( szProduct )
942 {
943 szwProduct = strdupAtoW( szProduct );
944 if( !szwProduct )
945 return ERROR_OUTOFMEMORY;
946 }
947
948 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
949 msi_free( szwProduct );
950
951 return r;
952 }
953
954 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
955 INSTALLSTATE eInstallState)
956 {
957 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
958 }
959
960 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
961 {
962 LPWSTR szwComponent = NULL;
963 UINT r;
964 WCHAR szwBuffer[GUID_SIZE];
965
966 TRACE("%s %p\n", debugstr_a(szComponent), szBuffer);
967
968 if( szComponent )
969 {
970 szwComponent = strdupAtoW( szComponent );
971 if( !szwComponent )
972 return ERROR_OUTOFMEMORY;
973 }
974
975 *szwBuffer = '\0';
976 r = MsiGetProductCodeW( szwComponent, szwBuffer );
977
978 if(*szwBuffer)
979 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
980
981 msi_free( szwComponent );
982
983 return r;
984 }
985
986 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
987 {
988 UINT rc, index;
989 HKEY compkey, prodkey;
990 WCHAR squished_comp[GUID_SIZE];
991 WCHAR squished_prod[GUID_SIZE];
992 DWORD sz = GUID_SIZE;
993
994 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
995
996 if (!szComponent || !*szComponent)
997 return ERROR_INVALID_PARAMETER;
998
999 if (!squash_guid(szComponent, squished_comp))
1000 return ERROR_INVALID_PARAMETER;
1001
1002 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &compkey, FALSE) != ERROR_SUCCESS &&
1003 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &compkey, FALSE) != ERROR_SUCCESS)
1004 {
1005 return ERROR_UNKNOWN_COMPONENT;
1006 }
1007
1008 rc = RegEnumValueW(compkey, 0, squished_prod, &sz, NULL, NULL, NULL, NULL);
1009 if (rc != ERROR_SUCCESS)
1010 {
1011 RegCloseKey(compkey);
1012 return ERROR_UNKNOWN_COMPONENT;
1013 }
1014
1015 /* check simple case, only one product */
1016 rc = RegEnumValueW(compkey, 1, squished_prod, &sz, NULL, NULL, NULL, NULL);
1017 if (rc == ERROR_NO_MORE_ITEMS)
1018 {
1019 rc = ERROR_SUCCESS;
1020 goto done;
1021 }
1022
1023 index = 0;
1024 while ((rc = RegEnumValueW(compkey, index, squished_prod, &sz,
1025 NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
1026 {
1027 index++;
1028 sz = GUID_SIZE;
1029 unsquash_guid(squished_prod, szBuffer);
1030
1031 if (MSIREG_OpenProductKey(szBuffer, NULL,
1032 MSIINSTALLCONTEXT_USERMANAGED,
1033 &prodkey, FALSE) == ERROR_SUCCESS ||
1034 MSIREG_OpenProductKey(szBuffer, NULL,
1035 MSIINSTALLCONTEXT_USERUNMANAGED,
1036 &prodkey, FALSE) == ERROR_SUCCESS ||
1037 MSIREG_OpenProductKey(szBuffer, NULL,
1038 MSIINSTALLCONTEXT_MACHINE,
1039 &prodkey, FALSE) == ERROR_SUCCESS)
1040 {
1041 RegCloseKey(prodkey);
1042 rc = ERROR_SUCCESS;
1043 goto done;
1044 }
1045 }
1046
1047 rc = ERROR_INSTALL_FAILURE;
1048
1049 done:
1050 RegCloseKey(compkey);
1051 unsquash_guid(squished_prod, szBuffer);
1052 return rc;
1053 }
1054
1055 static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
1056 {
1057 DWORD dval;
1058 LONG res;
1059 WCHAR temp[20];
1060
1061 static const WCHAR format[] = {'%','d',0};
1062
1063 res = RegQueryValueExW(hkey, name, NULL, type, NULL, NULL);
1064 if (res != ERROR_SUCCESS)
1065 return NULL;
1066
1067 if (*type == REG_SZ)
1068 return msi_reg_get_val_str(hkey, name);
1069
1070 if (!msi_reg_get_val_dword(hkey, name, &dval))
1071 return NULL;
1072
1073 sprintfW(temp, format, dval);
1074 return strdupW(temp);
1075 }
1076
1077 static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
1078 awstring *szValue, LPDWORD pcchValueBuf)
1079 {
1080 static WCHAR empty[] = {0};
1081 static const WCHAR sourcelist[] = {'S','o','u','r','c','e','L','i','s','t',0};
1082 static const WCHAR display_name[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
1083 static const WCHAR display_version[] = {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1084 static const WCHAR assignment[] = {'A','s','s','i','g','n','m','e','n','t',0};
1085 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
1086 UINT r = ERROR_UNKNOWN_PROPERTY;
1087 HKEY prodkey, userdata, source;
1088 LPWSTR val = NULL;
1089 WCHAR squished_pc[GUID_SIZE];
1090 WCHAR packagecode[GUID_SIZE];
1091 BOOL badconfig = FALSE;
1092 LONG res;
1093 DWORD type = REG_NONE;
1094
1095 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
1096 debugstr_w(szAttribute), szValue, pcchValueBuf);
1097
1098 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
1099 return ERROR_INVALID_PARAMETER;
1100
1101 if (!squash_guid(szProduct, squished_pc))
1102 return ERROR_INVALID_PARAMETER;
1103
1104 if ((r = MSIREG_OpenProductKey(szProduct, NULL,
1105 MSIINSTALLCONTEXT_USERMANAGED,
1106 &prodkey, FALSE)) != ERROR_SUCCESS &&
1107 (r = MSIREG_OpenProductKey(szProduct, NULL,
1108 MSIINSTALLCONTEXT_USERUNMANAGED,
1109 &prodkey, FALSE)) != ERROR_SUCCESS &&
1110 (r = MSIREG_OpenProductKey(szProduct, NULL,
1111 MSIINSTALLCONTEXT_MACHINE,
1112 &prodkey, FALSE)) == ERROR_SUCCESS)
1113 {
1114 context = MSIINSTALLCONTEXT_MACHINE;
1115 }
1116
1117 if (!strcmpW( szAttribute, INSTALLPROPERTY_HELPLINKW ) ||
1118 !strcmpW( szAttribute, INSTALLPROPERTY_HELPTELEPHONEW ) ||
1119 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLDATEW ) ||
1120 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
1121 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
1122 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLSOURCEW ) ||
1123 !strcmpW( szAttribute, INSTALLPROPERTY_LOCALPACKAGEW ) ||
1124 !strcmpW( szAttribute, INSTALLPROPERTY_PUBLISHERW ) ||
1125 !strcmpW( szAttribute, INSTALLPROPERTY_URLINFOABOUTW ) ||
1126 !strcmpW( szAttribute, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1127 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONMINORW ) ||
1128 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONMAJORW ) ||
1129 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1130 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTIDW ) ||
1131 !strcmpW( szAttribute, INSTALLPROPERTY_REGCOMPANYW ) ||
1132 !strcmpW( szAttribute, INSTALLPROPERTY_REGOWNERW ))
1133 {
1134 if (!prodkey)
1135 {
1136 r = ERROR_UNKNOWN_PRODUCT;
1137 goto done;
1138 }
1139 if (MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE))
1140 {
1141 r = ERROR_UNKNOWN_PROPERTY;
1142 goto done;
1143 }
1144
1145 if (!strcmpW( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1146 szAttribute = display_name;
1147 else if (!strcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ))
1148 szAttribute = display_version;
1149
1150 val = msi_reg_get_value(userdata, szAttribute, &type);
1151 if (!val)
1152 val = empty;
1153 RegCloseKey(userdata);
1154 }
1155 else if (!strcmpW( szAttribute, INSTALLPROPERTY_INSTANCETYPEW ) ||
1156 !strcmpW( szAttribute, INSTALLPROPERTY_TRANSFORMSW ) ||
1157 !strcmpW( szAttribute, INSTALLPROPERTY_LANGUAGEW ) ||
1158 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1159 !strcmpW( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ) ||
1160 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGECODEW ) ||
1161 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONW ) ||
1162 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTICONW ) ||
1163 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ) ||
1164 !strcmpW( szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1165 {
1166 if (!prodkey)
1167 {
1168 r = ERROR_UNKNOWN_PRODUCT;
1169 goto done;
1170 }
1171
1172 if (!strcmpW( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1173 szAttribute = assignment;
1174
1175 if (!strcmpW( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ))
1176 {
1177 res = RegOpenKeyW(prodkey, sourcelist, &source);
1178 if (res != ERROR_SUCCESS)
1179 {
1180 r = ERROR_UNKNOWN_PRODUCT;
1181 goto done;
1182 }
1183
1184 val = msi_reg_get_value(source, szAttribute, &type);
1185 if (!val)
1186 val = empty;
1187
1188 RegCloseKey(source);
1189 }
1190 else
1191 {
1192 val = msi_reg_get_value(prodkey, szAttribute, &type);
1193 if (!val)
1194 val = empty;
1195 }
1196
1197 if (val != empty && type != REG_DWORD &&
1198 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGECODEW ))
1199 {
1200 if (lstrlenW(val) != SQUISH_GUID_SIZE - 1)
1201 badconfig = TRUE;
1202 else
1203 {
1204 unsquash_guid(val, packagecode);
1205 msi_free(val);
1206 val = strdupW(packagecode);
1207 }
1208 }
1209 }
1210
1211 if (!val)
1212 {
1213 r = ERROR_UNKNOWN_PROPERTY;
1214 goto done;
1215 }
1216
1217 if (pcchValueBuf)
1218 {
1219 int len = strlenW( val );
1220
1221 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1222 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1223 * can't rely on its value.
1224 */
1225 if (szValue->str.a || szValue->str.w)
1226 {
1227 DWORD size = *pcchValueBuf;
1228 if (len < size)
1229 r = msi_strcpy_to_awstring( val, len, szValue, &size );
1230 else
1231 r = ERROR_MORE_DATA;
1232 }
1233
1234 if (!badconfig)
1235 *pcchValueBuf = len;
1236 }
1237
1238 if (badconfig)
1239 r = ERROR_BAD_CONFIGURATION;
1240
1241 if (val != empty)
1242 msi_free(val);
1243
1244 done:
1245 RegCloseKey(prodkey);
1246 return r;
1247 }
1248
1249 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
1250 LPSTR szBuffer, LPDWORD pcchValueBuf)
1251 {
1252 LPWSTR szwProduct, szwAttribute = NULL;
1253 UINT r = ERROR_OUTOFMEMORY;
1254 awstring buffer;
1255
1256 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
1257 szBuffer, pcchValueBuf);
1258
1259 szwProduct = strdupAtoW( szProduct );
1260 if( szProduct && !szwProduct )
1261 goto end;
1262
1263 szwAttribute = strdupAtoW( szAttribute );
1264 if( szAttribute && !szwAttribute )
1265 goto end;
1266
1267 buffer.unicode = FALSE;
1268 buffer.str.a = szBuffer;
1269
1270 r = MSI_GetProductInfo( szwProduct, szwAttribute,
1271 &buffer, pcchValueBuf );
1272
1273 end:
1274 msi_free( szwProduct );
1275 msi_free( szwAttribute );
1276
1277 return r;
1278 }
1279
1280 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
1281 LPWSTR szBuffer, LPDWORD pcchValueBuf)
1282 {
1283 awstring buffer;
1284
1285 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
1286 szBuffer, pcchValueBuf);
1287
1288 buffer.unicode = TRUE;
1289 buffer.str.w = szBuffer;
1290
1291 return MSI_GetProductInfo( szProduct, szAttribute,
1292 &buffer, pcchValueBuf );
1293 }
1294
1295 UINT WINAPI MsiGetProductInfoExA(LPCSTR szProductCode, LPCSTR szUserSid,
1296 MSIINSTALLCONTEXT dwContext, LPCSTR szProperty,
1297 LPSTR szValue, LPDWORD pcchValue)
1298 {
1299 LPWSTR product = NULL;
1300 LPWSTR usersid = NULL;
1301 LPWSTR property = NULL;
1302 LPWSTR value = NULL;
1303 DWORD len = 0;
1304 UINT r;
1305
1306 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode),
1307 debugstr_a(szUserSid), dwContext, debugstr_a(szProperty),
1308 szValue, pcchValue);
1309
1310 if (szValue && !pcchValue)
1311 return ERROR_INVALID_PARAMETER;
1312
1313 if (szProductCode) product = strdupAtoW(szProductCode);
1314 if (szUserSid) usersid = strdupAtoW(szUserSid);
1315 if (szProperty) property = strdupAtoW(szProperty);
1316
1317 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1318 NULL, &len);
1319 if (r != ERROR_SUCCESS)
1320 goto done;
1321
1322 value = msi_alloc(++len * sizeof(WCHAR));
1323 if (!value)
1324 {
1325 r = ERROR_OUTOFMEMORY;
1326 goto done;
1327 }
1328
1329 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1330 value, &len);
1331 if (r != ERROR_SUCCESS)
1332 goto done;
1333
1334 if (!pcchValue)
1335 goto done;
1336
1337 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
1338 if (*pcchValue >= len)
1339 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
1340 else if (szValue)
1341 {
1342 r = ERROR_MORE_DATA;
1343 if (*pcchValue > 0)
1344 *szValue = '\0';
1345 }
1346
1347 if (*pcchValue <= len || !szValue)
1348 len = len * sizeof(WCHAR) - 1;
1349
1350 *pcchValue = len - 1;
1351
1352 done:
1353 msi_free(product);
1354 msi_free(usersid);
1355 msi_free(property);
1356 msi_free(value);
1357
1358 return r;
1359 }
1360
1361 static UINT msi_copy_outval(LPWSTR val, LPWSTR out, LPDWORD size)
1362 {
1363 UINT r = ERROR_SUCCESS;
1364
1365 if (!val)
1366 return ERROR_UNKNOWN_PROPERTY;
1367
1368 if (out)
1369 {
1370 if (strlenW(val) >= *size)
1371 {
1372 r = ERROR_MORE_DATA;
1373 if (*size > 0)
1374 *out = '\0';
1375 }
1376 else
1377 lstrcpyW(out, val);
1378 }
1379
1380 if (size)
1381 *size = lstrlenW(val);
1382
1383 return r;
1384 }
1385
1386 UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1387 MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty,
1388 LPWSTR szValue, LPDWORD pcchValue)
1389 {
1390 WCHAR squished_pc[GUID_SIZE];
1391 LPWSTR val = NULL;
1392 LPCWSTR package = NULL;
1393 HKEY props = NULL, prod;
1394 HKEY classes = NULL, managed;
1395 HKEY hkey = NULL;
1396 DWORD type;
1397 UINT r = ERROR_UNKNOWN_PRODUCT;
1398
1399 static const WCHAR five[] = {'5',0};
1400 static const WCHAR displayname[] = {
1401 'D','i','s','p','l','a','y','N','a','m','e',0};
1402 static const WCHAR displayversion[] = {
1403 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1404 static const WCHAR managed_local_package[] = {
1405 'M','a','n','a','g','e','d','L','o','c','a','l',
1406 'P','a','c','k','a','g','e',0};
1407
1408 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
1409 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
1410 szValue, pcchValue);
1411
1412 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1413 return ERROR_INVALID_PARAMETER;
1414
1415 if (szValue && !pcchValue)
1416 return ERROR_INVALID_PARAMETER;
1417
1418 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1419 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1420 dwContext != MSIINSTALLCONTEXT_MACHINE)
1421 return ERROR_INVALID_PARAMETER;
1422
1423 if (!szProperty || !*szProperty)
1424 return ERROR_INVALID_PARAMETER;
1425
1426 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1427 return ERROR_INVALID_PARAMETER;
1428
1429 /* FIXME: dwContext is provided, no need to search for it */
1430 MSIREG_OpenProductKey(szProductCode, NULL,MSIINSTALLCONTEXT_USERMANAGED,
1431 &managed, FALSE);
1432 MSIREG_OpenProductKey(szProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1433 &prod, FALSE);
1434
1435 MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
1436
1437 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1438 {
1439 package = INSTALLPROPERTY_LOCALPACKAGEW;
1440
1441 if (!props && !prod)
1442 goto done;
1443 }
1444 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1445 {
1446 package = managed_local_package;
1447
1448 if (!props && !managed)
1449 goto done;
1450 }
1451 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1452 {
1453 package = INSTALLPROPERTY_LOCALPACKAGEW;
1454 MSIREG_OpenProductKey(szProductCode, NULL, dwContext, &classes, FALSE);
1455
1456 if (!props && !classes)
1457 goto done;
1458 }
1459
1460 if (!strcmpW( szProperty, INSTALLPROPERTY_HELPLINKW ) ||
1461 !strcmpW( szProperty, INSTALLPROPERTY_HELPTELEPHONEW ) ||
1462 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLDATEW ) ||
1463 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
1464 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
1465 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLSOURCEW ) ||
1466 !strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ) ||
1467 !strcmpW( szProperty, INSTALLPROPERTY_PUBLISHERW ) ||
1468 !strcmpW( szProperty, INSTALLPROPERTY_URLINFOABOUTW ) ||
1469 !strcmpW( szProperty, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1470 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONMINORW ) ||
1471 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONMAJORW ) ||
1472 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1473 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTIDW ) ||
1474 !strcmpW( szProperty, INSTALLPROPERTY_REGCOMPANYW ) ||
1475 !strcmpW( szProperty, INSTALLPROPERTY_REGOWNERW ) ||
1476 !strcmpW( szProperty, INSTALLPROPERTY_INSTANCETYPEW ))
1477 {
1478 val = msi_reg_get_value(props, package, &type);
1479 if (!val)
1480 {
1481 if (prod || classes)
1482 r = ERROR_UNKNOWN_PROPERTY;
1483
1484 goto done;
1485 }
1486
1487 msi_free(val);
1488
1489 if (!strcmpW( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1490 szProperty = displayname;
1491 else if (!strcmpW( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ))
1492 szProperty = displayversion;
1493
1494 val = msi_reg_get_value(props, szProperty, &type);
1495 if (!val)
1496 val = strdupW(szEmpty);
1497
1498 r = msi_copy_outval(val, szValue, pcchValue);
1499 }
1500 else if (!strcmpW( szProperty, INSTALLPROPERTY_TRANSFORMSW ) ||
1501 !strcmpW( szProperty, INSTALLPROPERTY_LANGUAGEW ) ||
1502 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1503 !strcmpW( szProperty, INSTALLPROPERTY_PACKAGECODEW ) ||
1504 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONW ) ||
1505 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTICONW ) ||
1506 !strcmpW( szProperty, INSTALLPROPERTY_PACKAGENAMEW ) ||
1507 !strcmpW( szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1508 {
1509 if (!prod && !classes)
1510 goto done;
1511
1512 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1513 hkey = prod;
1514 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1515 hkey = managed;
1516 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1517 hkey = classes;
1518
1519 val = msi_reg_get_value(hkey, szProperty, &type);
1520 if (!val)
1521 val = strdupW(szEmpty);
1522
1523 r = msi_copy_outval(val, szValue, pcchValue);
1524 }
1525 else if (!strcmpW( szProperty, INSTALLPROPERTY_PRODUCTSTATEW ))
1526 {
1527 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1528 {
1529 if (props)
1530 {
1531 val = msi_reg_get_value(props, package, &type);
1532 if (!val)
1533 goto done;
1534
1535 msi_free(val);
1536 val = strdupW(five);
1537 }
1538 else
1539 val = strdupW(szOne);
1540
1541 r = msi_copy_outval(val, szValue, pcchValue);
1542 goto done;
1543 }
1544 else if (props && (val = msi_reg_get_value(props, package, &type)))
1545 {
1546 msi_free(val);
1547 val = strdupW(five);
1548 r = msi_copy_outval(val, szValue, pcchValue);
1549 goto done;
1550 }
1551
1552 if (prod || managed)
1553 val = strdupW(szOne);
1554 else
1555 goto done;
1556
1557 r = msi_copy_outval(val, szValue, pcchValue);
1558 }
1559 else if (!strcmpW( szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1560 {
1561 if (!prod && !classes)
1562 goto done;
1563
1564 /* FIXME */
1565 val = strdupW(szEmpty);
1566 r = msi_copy_outval(val, szValue, pcchValue);
1567 }
1568 else
1569 r = ERROR_UNKNOWN_PROPERTY;
1570
1571 done:
1572 RegCloseKey(props);
1573 RegCloseKey(prod);
1574 RegCloseKey(managed);
1575 RegCloseKey(classes);
1576 msi_free(val);
1577
1578 return r;
1579 }
1580
1581 UINT WINAPI MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode,
1582 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1583 LPCSTR szProperty, LPSTR lpValue, DWORD *pcchValue)
1584 {
1585 LPWSTR patch = NULL, product = NULL, usersid = NULL;
1586 LPWSTR property = NULL, val = NULL;
1587 DWORD len;
1588 UINT r;
1589
1590 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode),
1591 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext,
1592 debugstr_a(szProperty), lpValue, pcchValue);
1593
1594 if (lpValue && !pcchValue)
1595 return ERROR_INVALID_PARAMETER;
1596
1597 if (szPatchCode) patch = strdupAtoW(szPatchCode);
1598 if (szProductCode) product = strdupAtoW(szProductCode);
1599 if (szUserSid) usersid = strdupAtoW(szUserSid);
1600 if (szProperty) property = strdupAtoW(szProperty);
1601
1602 len = 0;
1603 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1604 NULL, &len);
1605 if (r != ERROR_SUCCESS)
1606 goto done;
1607
1608 val = msi_alloc(++len * sizeof(WCHAR));
1609 if (!val)
1610 {
1611 r = ERROR_OUTOFMEMORY;
1612 goto done;
1613 }
1614
1615 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1616 val, &len);
1617 if (r != ERROR_SUCCESS || !pcchValue)
1618 goto done;
1619
1620 if (lpValue)
1621 WideCharToMultiByte(CP_ACP, 0, val, -1, lpValue,
1622 *pcchValue - 1, NULL, NULL);
1623
1624 len = lstrlenW(val);
1625 if ((*val && *pcchValue < len + 1) || !lpValue)
1626 {
1627 if (lpValue)
1628 {
1629 r = ERROR_MORE_DATA;
1630 lpValue[*pcchValue - 1] = '\0';
1631 }
1632
1633 *pcchValue = len * sizeof(WCHAR);
1634 }
1635 else
1636 *pcchValue = len;
1637
1638 done:
1639 msi_free(val);
1640 msi_free(patch);
1641 msi_free(product);
1642 msi_free(usersid);
1643 msi_free(property);
1644
1645 return r;
1646 }
1647
1648 UINT WINAPI MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode,
1649 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1650 LPCWSTR szProperty, LPWSTR lpValue, DWORD *pcchValue)
1651 {
1652 WCHAR squished_pc[GUID_SIZE];
1653 WCHAR squished_patch[GUID_SIZE];
1654 HKEY udprod = 0, prod = 0, props = 0;
1655 HKEY patch = 0, patches = 0;
1656 HKEY udpatch = 0, datakey = 0;
1657 HKEY prodpatches = 0;
1658 LPWSTR val = NULL;
1659 UINT r = ERROR_UNKNOWN_PRODUCT;
1660 DWORD len;
1661 LONG res;
1662
1663 static const WCHAR szManagedPackage[] = {'M','a','n','a','g','e','d',
1664 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1665
1666 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode),
1667 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext,
1668 debugstr_w(szProperty), lpValue, pcchValue);
1669
1670 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1671 return ERROR_INVALID_PARAMETER;
1672
1673 if (!szPatchCode || !squash_guid(szPatchCode, squished_patch))
1674 return ERROR_INVALID_PARAMETER;
1675
1676 if (!szProperty)
1677 return ERROR_INVALID_PARAMETER;
1678
1679 if (lpValue && !pcchValue)
1680 return ERROR_INVALID_PARAMETER;
1681
1682 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1683 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1684 dwContext != MSIINSTALLCONTEXT_MACHINE)
1685 return ERROR_INVALID_PARAMETER;
1686
1687 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1688 return ERROR_INVALID_PARAMETER;
1689
1690 if (szUserSid && !strcmpW( szUserSid, szLocalSid ))
1691 return ERROR_INVALID_PARAMETER;
1692
1693 if (MSIREG_OpenUserDataProductKey(szProductCode, dwContext, NULL,
1694 &udprod, FALSE) != ERROR_SUCCESS)
1695 goto done;
1696
1697 if (MSIREG_OpenInstallProps(szProductCode, dwContext, NULL,
1698 &props, FALSE) != ERROR_SUCCESS)
1699 goto done;
1700
1701 r = ERROR_UNKNOWN_PATCH;
1702
1703 res = RegOpenKeyExW(udprod, szPatches, 0, KEY_WOW64_64KEY|KEY_READ, &patches);
1704 if (res != ERROR_SUCCESS)
1705 goto done;
1706
1707 res = RegOpenKeyExW(patches, squished_patch, 0, KEY_WOW64_64KEY|KEY_READ, &patch);
1708 if (res != ERROR_SUCCESS)
1709 goto done;
1710
1711 if (!strcmpW( szProperty, INSTALLPROPERTY_TRANSFORMSW ))
1712 {
1713 if (MSIREG_OpenProductKey(szProductCode, NULL, dwContext,
1714 &prod, FALSE) != ERROR_SUCCESS)
1715 goto done;
1716
1717 res = RegOpenKeyExW(prod, szPatches, 0, KEY_WOW64_64KEY|KEY_ALL_ACCESS, &prodpatches);
1718 if (res != ERROR_SUCCESS)
1719 goto done;
1720
1721 datakey = prodpatches;
1722 szProperty = squished_patch;
1723 }
1724 else
1725 {
1726 if (MSIREG_OpenUserDataPatchKey(szPatchCode, dwContext,
1727 &udpatch, FALSE) != ERROR_SUCCESS)
1728 goto done;
1729
1730 if (!strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ))
1731 {
1732 if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1733 szProperty = szManagedPackage;
1734 datakey = udpatch;
1735 }
1736 else if (!strcmpW( szProperty, INSTALLPROPERTY_INSTALLDATEW ))
1737 {
1738 datakey = patch;
1739 szProperty = szInstalled;
1740 }
1741 else if (!strcmpW( szProperty, INSTALLPROPERTY_UNINSTALLABLEW ) ||
1742 !strcmpW( szProperty, INSTALLPROPERTY_PATCHSTATEW ) ||
1743 !strcmpW( szProperty, INSTALLPROPERTY_DISPLAYNAMEW ) ||
1744 !strcmpW( szProperty, INSTALLPROPERTY_MOREINFOURLW ))
1745 {
1746 datakey = patch;
1747 }
1748 else
1749 {
1750 r = ERROR_UNKNOWN_PROPERTY;
1751 goto done;
1752 }
1753 }
1754
1755 val = msi_reg_get_val_str(datakey, szProperty);
1756 if (!val)
1757 val = strdupW(szEmpty);
1758
1759 r = ERROR_SUCCESS;
1760
1761 if (!pcchValue)
1762 goto done;
1763
1764 if (lpValue)
1765 lstrcpynW(lpValue, val, *pcchValue);
1766
1767 len = lstrlenW(val);
1768 if ((*val && *pcchValue < len + 1) || !lpValue)
1769 {
1770 if (lpValue)
1771 r = ERROR_MORE_DATA;
1772
1773 *pcchValue = len * sizeof(WCHAR);
1774 }
1775
1776 *pcchValue = len;
1777
1778 done:
1779 msi_free(val);
1780 RegCloseKey(prodpatches);
1781 RegCloseKey(prod);
1782 RegCloseKey(patch);
1783 RegCloseKey(patches);
1784 RegCloseKey(udpatch);
1785 RegCloseKey(props);
1786 RegCloseKey(udprod);
1787
1788 return r;
1789 }
1790
1791 UINT WINAPI MsiGetPatchInfoA( LPCSTR patch, LPCSTR attr, LPSTR buffer, LPDWORD buflen )
1792 {
1793 UINT r = ERROR_OUTOFMEMORY;
1794 DWORD size;
1795 LPWSTR patchW = NULL, attrW = NULL, bufferW = NULL;
1796
1797 TRACE("%s %s %p %p\n", debugstr_a(patch), debugstr_a(attr), buffer, buflen);
1798
1799 if (!patch || !attr)
1800 return ERROR_INVALID_PARAMETER;
1801
1802 if (!(patchW = strdupAtoW( patch )))
1803 goto done;
1804
1805 if (!(attrW = strdupAtoW( attr )))
1806 goto done;
1807
1808 size = 0;
1809 r = MsiGetPatchInfoW( patchW, attrW, NULL, &size );
1810 if (r != ERROR_SUCCESS)
1811 goto done;
1812
1813 size++;
1814 if (!(bufferW = msi_alloc( size * sizeof(WCHAR) )))
1815 {
1816 r = ERROR_OUTOFMEMORY;
1817 goto done;
1818 }
1819
1820 r = MsiGetPatchInfoW( patchW, attrW, bufferW, &size );
1821 if (r == ERROR_SUCCESS)
1822 {
1823 int len = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
1824 if (len > *buflen)
1825 r = ERROR_MORE_DATA;
1826 else if (buffer)
1827 WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, *buflen, NULL, NULL );
1828
1829 *buflen = len - 1;
1830 }
1831
1832 done:
1833 msi_free( patchW );
1834 msi_free( attrW );
1835 msi_free( bufferW );
1836 return r;
1837 }
1838
1839 UINT WINAPI MsiGetPatchInfoW( LPCWSTR patch, LPCWSTR attr, LPWSTR buffer, LPDWORD buflen )
1840 {
1841 UINT r;
1842 WCHAR product[GUID_SIZE];
1843 DWORD index;
1844
1845 TRACE("%s %s %p %p\n", debugstr_w(patch), debugstr_w(attr), buffer, buflen);
1846
1847 if (!patch || !attr)
1848 return ERROR_INVALID_PARAMETER;
1849
1850 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW, attr ))
1851 return ERROR_UNKNOWN_PROPERTY;
1852
1853 index = 0;
1854 while (1)
1855 {
1856 r = MsiEnumProductsW( index, product );
1857 if (r != ERROR_SUCCESS)
1858 break;
1859
1860 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERMANAGED, attr, buffer, buflen );
1861 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1862 return r;
1863
1864 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, attr, buffer, buflen );
1865 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1866 return r;
1867
1868 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_MACHINE, attr, buffer, buflen );
1869 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1870 return r;
1871
1872 index++;
1873 }
1874
1875 return ERROR_UNKNOWN_PRODUCT;
1876 }
1877
1878 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1879 {
1880 LPWSTR szwLogFile = NULL;
1881 UINT r;
1882
1883 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1884
1885 if( szLogFile )
1886 {
1887 szwLogFile = strdupAtoW( szLogFile );
1888 if( !szwLogFile )
1889 return ERROR_OUTOFMEMORY;
1890 }
1891 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1892 msi_free( szwLogFile );
1893 return r;
1894 }
1895
1896 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1897 {
1898 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1899
1900 msi_free(gszLogFile);
1901 gszLogFile = NULL;
1902 if (szLogFile)
1903 {
1904 HANDLE file;
1905
1906 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1907 DeleteFileW(szLogFile);
1908 file = CreateFileW(szLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
1909 FILE_ATTRIBUTE_NORMAL, NULL);
1910 if (file != INVALID_HANDLE_VALUE)
1911 {
1912 gszLogFile = strdupW(szLogFile);
1913 CloseHandle(file);
1914 }
1915 else
1916 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile), GetLastError());
1917 }
1918
1919 return ERROR_SUCCESS;
1920 }
1921
1922 UINT WINAPI MsiEnumComponentCostsA( MSIHANDLE handle, LPCSTR component, DWORD index,
1923 INSTALLSTATE state, LPSTR drive, DWORD *buflen,
1924 int *cost, int *temp )
1925 {
1926 UINT r;
1927 DWORD len;
1928 WCHAR *driveW, *componentW = NULL;
1929
1930 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_a(component), index,
1931 state, drive, buflen, cost, temp);
1932
1933 if (!drive || !buflen) return ERROR_INVALID_PARAMETER;
1934 if (component && !(componentW = strdupAtoW( component ))) return ERROR_OUTOFMEMORY;
1935
1936 len = *buflen;
1937 if (!(driveW = msi_alloc( len * sizeof(WCHAR) )))
1938 {
1939 msi_free( componentW );
1940 return ERROR_OUTOFMEMORY;
1941 }
1942 r = MsiEnumComponentCostsW( handle, componentW, index, state, driveW, buflen, cost, temp );
1943 if (!r)
1944 {
1945 WideCharToMultiByte( CP_ACP, 0, driveW, -1, drive, len, NULL, NULL );
1946 }
1947 msi_free( componentW );
1948 msi_free( driveW );
1949 return r;
1950 }
1951
1952 static UINT set_drive( WCHAR *buffer, WCHAR letter )
1953 {
1954 buffer[0] = letter;
1955 buffer[1] = ':';
1956 buffer[2] = 0;
1957 return 2;
1958 }
1959
1960 UINT WINAPI MsiEnumComponentCostsW( MSIHANDLE handle, LPCWSTR component, DWORD index,
1961 INSTALLSTATE state, LPWSTR drive, DWORD *buflen,
1962 int *cost, int *temp )
1963 {
1964 UINT r = ERROR_NO_MORE_ITEMS;
1965 MSICOMPONENT *comp = NULL;
1966 MSIPACKAGE *package;
1967 MSIFILE *file;
1968 STATSTG stat = {0};
1969 WCHAR path[MAX_PATH];
1970
1971 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_w(component), index,
1972 state, drive, buflen, cost, temp);
1973
1974 if (!drive || !buflen || !cost || !temp) return ERROR_INVALID_PARAMETER;
1975 if (!(package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE )))
1976 {
1977 HRESULT hr;
1978 IWineMsiRemotePackage *remote_package;
1979 BSTR bname = NULL;
1980
1981 if (!(remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle )))
1982 return ERROR_INVALID_HANDLE;
1983
1984 if (component && !(bname = SysAllocString( component )))
1985 {
1986 IWineMsiRemotePackage_Release( remote_package );
1987 return ERROR_OUTOFMEMORY;
1988 }
1989 hr = IWineMsiRemotePackage_EnumComponentCosts( remote_package, bname, index, state, drive, buflen, cost, temp );
1990 IWineMsiRemotePackage_Release( remote_package );
1991 SysFreeString( bname );
1992 if (FAILED(hr))
1993 {
1994 if (HRESULT_FACILITY(hr) == FACILITY_WIN32) return HRESULT_CODE(hr);
1995 return ERROR_FUNCTION_FAILED;
1996 }
1997 return ERROR_SUCCESS;
1998 }
1999
2000 if (!msi_get_property_int( package->db, szCostingComplete, 0 ))
2001 {
2002 msiobj_release( &package->hdr );
2003 return ERROR_FUNCTION_NOT_CALLED;
2004 }
2005 if (component && component[0] && !(comp = msi_get_loaded_component( package, component )))
2006 {
2007 msiobj_release( &package->hdr );
2008 return ERROR_UNKNOWN_COMPONENT;
2009 }
2010 if (*buflen < 3)
2011 {
2012 *buflen = 2;
2013 msiobj_release( &package->hdr );
2014 return ERROR_MORE_DATA;
2015 }
2016 if (index)
2017 {
2018 msiobj_release( &package->hdr );
2019 return ERROR_NO_MORE_ITEMS;
2020 }
2021
2022 drive[0] = 0;
2023 *cost = *temp = 0;
2024 GetWindowsDirectoryW( path, MAX_PATH );
2025 if (component && component[0])
2026 {
2027 if (comp->assembly && !comp->assembly->application) *temp = comp->Cost;
2028 if (!comp->Enabled || !comp->KeyPath)
2029 {
2030 *cost = 0;
2031 *buflen = set_drive( drive, path[0] );
2032 r = ERROR_SUCCESS;
2033 }
2034 else if ((file = msi_get_loaded_file( package, comp->KeyPath )))
2035 {
2036 *cost = max( 8, comp->Cost / 512 );
2037 *buflen = set_drive( drive, file->TargetPath[0] );
2038 r = ERROR_SUCCESS;
2039 }
2040 }
2041 else if (IStorage_Stat( package->db->storage, &stat, STATFLAG_NONAME ) == S_OK)
2042 {
2043 *temp = max( 8, stat.cbSize.QuadPart / 512 );
2044 *buflen = set_drive( drive, path[0] );
2045 r = ERROR_SUCCESS;
2046 }
2047 msiobj_release( &package->hdr );
2048 return r;
2049 }
2050
2051 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
2052 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
2053 LPCSTR szComponent, INSTALLSTATE *pdwState)
2054 {
2055 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
2056 UINT r;
2057
2058 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
2059 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
2060
2061 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
2062 return ERROR_OUTOFMEMORY;
2063
2064 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
2065 return ERROR_OUTOFMEMORY;
2066
2067 if (szComponent && !(comp = strdupAtoW(szComponent)))
2068 return ERROR_OUTOFMEMORY;
2069
2070 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
2071
2072 msi_free(prodcode);
2073 msi_free(usersid);
2074 msi_free(comp);
2075
2076 return r;
2077 }
2078
2079 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
2080 {
2081 UINT r;
2082 HKEY hkey = NULL;
2083
2084 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
2085 RegCloseKey(hkey);
2086 return (r == ERROR_SUCCESS);
2087 }
2088
2089 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
2090 {
2091 LPCWSTR package;
2092 HKEY hkey;
2093 DWORD sz;
2094 LONG res;
2095 UINT r;
2096
2097 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
2098 static const WCHAR managed_local_package[] = {
2099 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
2100 };
2101
2102 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
2103 if (r != ERROR_SUCCESS)
2104 return FALSE;
2105
2106 if (context == MSIINSTALLCONTEXT_USERMANAGED)
2107 package = managed_local_package;
2108 else
2109 package = local_package;
2110
2111 sz = 0;
2112 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
2113 RegCloseKey(hkey);
2114
2115 return (res == ERROR_SUCCESS);
2116 }
2117
2118 static UINT msi_comp_find_prodcode(LPWSTR squished_pc,
2119 MSIINSTALLCONTEXT context,
2120 LPCWSTR comp, LPWSTR val, DWORD *sz)
2121 {
2122 HKEY hkey;
2123 LONG res;
2124 UINT r;
2125
2126 if (context == MSIINSTALLCONTEXT_MACHINE)
2127 r = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2128 else
2129 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2130
2131 if (r != ERROR_SUCCESS)
2132 return r;
2133
2134 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, (BYTE *)val, sz);
2135 if (res != ERROR_SUCCESS)
2136 return res;
2137
2138 RegCloseKey(hkey);
2139 return res;
2140 }
2141
2142 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
2143 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
2144 LPCWSTR szComponent, INSTALLSTATE *pdwState)
2145 {
2146 WCHAR squished_pc[GUID_SIZE];
2147 BOOL found;
2148 DWORD sz;
2149
2150 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
2151 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
2152
2153 if (!pdwState || !szComponent)
2154 return ERROR_INVALID_PARAMETER;
2155
2156 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
2157 return ERROR_INVALID_PARAMETER;
2158
2159 if (!squash_guid(szProductCode, squished_pc))
2160 return ERROR_INVALID_PARAMETER;
2161
2162 found = msi_comp_find_prod_key(szProductCode, dwContext);
2163
2164 if (!msi_comp_find_package(szProductCode, dwContext))
2165 {
2166 if (found)
2167 {
2168 *pdwState = INSTALLSTATE_UNKNOWN;
2169 return ERROR_UNKNOWN_COMPONENT;
2170 }
2171
2172 return ERROR_UNKNOWN_PRODUCT;
2173 }
2174
2175 *pdwState = INSTALLSTATE_UNKNOWN;
2176
2177 sz = 0;
2178 if (msi_comp_find_prodcode(squished_pc, dwContext, szComponent, NULL, &sz))
2179 return ERROR_UNKNOWN_COMPONENT;
2180
2181 if (sz == 0)
2182 *pdwState = INSTALLSTATE_NOTUSED;
2183 else
2184 {
2185 WCHAR *val;
2186 UINT r;
2187
2188 if (!(val = msi_alloc( sz ))) return ERROR_OUTOFMEMORY;
2189 if ((r = msi_comp_find_prodcode(squished_pc, dwContext, szComponent, val, &sz)))
2190 {
2191 msi_free(val);
2192 return r;
2193 }
2194
2195 if (lstrlenW(val) > 2 &&
2196 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9' && val[2] != ':')
2197 {
2198 *pdwState = INSTALLSTATE_SOURCE;
2199 }
2200 else
2201 *pdwState = INSTALLSTATE_LOCAL;
2202 msi_free( val );
2203 }
2204
2205 TRACE("-> %d\n", *pdwState);
2206 return ERROR_SUCCESS;
2207 }
2208
2209 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
2210 {
2211 LPWSTR szwProduct = NULL;
2212 INSTALLSTATE r;
2213
2214 if( szProduct )
2215 {
2216 szwProduct = strdupAtoW( szProduct );
2217 if( !szwProduct )
2218 return ERROR_OUTOFMEMORY;
2219 }
2220 r = MsiQueryProductStateW( szwProduct );
2221 msi_free( szwProduct );
2222 return r;
2223 }
2224
2225 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
2226 {
2227 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
2228 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
2229 HKEY prodkey = 0, userdata = 0;
2230 DWORD val;
2231 UINT r;
2232
2233 TRACE("%s\n", debugstr_w(szProduct));
2234
2235 if (!szProduct || !*szProduct)
2236 return INSTALLSTATE_INVALIDARG;
2237
2238 if (lstrlenW(szProduct) != GUID_SIZE - 1)
2239 return INSTALLSTATE_INVALIDARG;
2240
2241 if (szProduct[0] != '{' || szProduct[37] != '}')
2242 return INSTALLSTATE_UNKNOWN;
2243
2244 SetLastError( ERROR_SUCCESS );
2245
2246 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2247 &prodkey, FALSE) != ERROR_SUCCESS &&
2248 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2249 &prodkey, FALSE) != ERROR_SUCCESS &&
2250 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2251 &prodkey, FALSE) == ERROR_SUCCESS)
2252 {
2253 context = MSIINSTALLCONTEXT_MACHINE;
2254 }
2255
2256 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
2257 if (r != ERROR_SUCCESS)
2258 goto done;
2259
2260 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
2261 goto done;
2262
2263 if (val)
2264 state = INSTALLSTATE_DEFAULT;
2265 else
2266 state = INSTALLSTATE_UNKNOWN;
2267
2268 done:
2269 if (!prodkey)
2270 {
2271 state = INSTALLSTATE_UNKNOWN;
2272
2273 if (userdata)
2274 state = INSTALLSTATE_ABSENT;
2275 }
2276
2277 RegCloseKey(prodkey);
2278 RegCloseKey(userdata);
2279 TRACE("-> %d\n", state);
2280 return state;
2281 }
2282
2283 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
2284 {
2285 INSTALLUILEVEL old = gUILevel;
2286 HWND oldwnd = gUIhwnd;
2287
2288 TRACE("%08x %p\n", dwUILevel, phWnd);
2289
2290 gUILevel = dwUILevel;
2291 if (phWnd)
2292 {
2293 gUIhwnd = *phWnd;
2294 *phWnd = oldwnd;
2295 }
2296 return old;
2297 }
2298
2299 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
2300 DWORD dwMessageFilter, LPVOID pvContext)
2301 {
2302 INSTALLUI_HANDLERA prev = gUIHandlerA;
2303
2304 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2305
2306 gUIHandlerA = puiHandler;
2307 gUIHandlerW = NULL;
2308 gUIFilter = dwMessageFilter;
2309 gUIContext = pvContext;
2310
2311 return prev;
2312 }
2313
2314 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
2315 DWORD dwMessageFilter, LPVOID pvContext)
2316 {
2317 INSTALLUI_HANDLERW prev = gUIHandlerW;
2318
2319 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2320
2321 gUIHandlerA = NULL;
2322 gUIHandlerW = puiHandler;
2323 gUIFilter = dwMessageFilter;
2324 gUIContext = pvContext;
2325
2326 return prev;
2327 }
2328
2329 /******************************************************************
2330 * MsiLoadStringW [MSI.@]
2331 *
2332 * Loads a string from MSI's string resources.
2333 *
2334 * PARAMS
2335 *
2336 * handle [I] only -1 is handled currently
2337 * id [I] id of the string to be loaded
2338 * lpBuffer [O] buffer for the string to be written to
2339 * nBufferMax [I] maximum size of the buffer in characters
2340 * lang [I] the preferred language for the string
2341 *
2342 * RETURNS
2343 *
2344 * If successful, this function returns the language id of the string loaded
2345 * If the function fails, the function returns zero.
2346 *
2347 * NOTES
2348 *
2349 * The type of the first parameter is unknown. LoadString's prototype
2350 * suggests that it might be a module handle. I have made it an MSI handle
2351 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2352 * handle. Maybe strings can be stored in an MSI database somehow.
2353 */
2354 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
2355 int nBufferMax, LANGID lang )
2356 {
2357 HRSRC hres;
2358 HGLOBAL hResData;
2359 LPWSTR p;
2360 DWORD i, len;
2361
2362 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
2363
2364 if( handle != -1 )
2365 FIXME("don't know how to deal with handle = %08x\n", handle);
2366
2367 if( !lang )
2368 lang = GetUserDefaultLangID();
2369
2370 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
2371 (LPWSTR)1, lang );
2372 if( !hres )
2373 return 0;
2374 hResData = LoadResource( msi_hInstance, hres );
2375 if( !hResData )
2376 return 0;
2377 p = LockResource( hResData );
2378 if( !p )
2379 return 0;
2380
2381 for (i = 0; i < (id & 0xf); i++) p += *p + 1;
2382 len = *p;
2383
2384 if( nBufferMax <= len )
2385 return 0;
2386
2387 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
2388 lpBuffer[ len ] = 0;
2389
2390 TRACE("found -> %s\n", debugstr_w(lpBuffer));
2391 return lang;
2392 }
2393
2394 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
2395 int nBufferMax, LANGID lang )
2396 {
2397 LPWSTR bufW;
2398 LANGID r;
2399 INT len;
2400
2401 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
2402 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
2403 if( r )
2404 {
2405 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
2406 if( len <= nBufferMax )
2407 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
2408 lpBuffer, nBufferMax, NULL, NULL );
2409 else
2410 r = 0;
2411 }
2412 msi_free(bufW);
2413 return r;
2414 }
2415
2416 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
2417 LPDWORD pcchBuf)
2418 {
2419 char szProduct[GUID_SIZE];
2420
2421 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
2422
2423 if (!szComponent || !pcchBuf)
2424 return INSTALLSTATE_INVALIDARG;
2425
2426 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
2427 return INSTALLSTATE_UNKNOWN;
2428
2429 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
2430 }
2431
2432 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
2433 LPDWORD pcchBuf)
2434 {
2435 WCHAR szProduct[GUID_SIZE];
2436
2437 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
2438
2439 if (!szComponent || !pcchBuf)
2440 return INSTALLSTATE_INVALIDARG;
2441
2442 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
2443 return INSTALLSTATE_UNKNOWN;
2444
2445 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
2446 }
2447
2448 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2449 WORD wLanguageId, DWORD f)
2450 {
2451 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
2452 uType, wLanguageId, f);
2453 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
2454 }
2455
2456 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2457 WORD wLanguageId, DWORD f)
2458 {
2459 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
2460 uType, wLanguageId, f);
2461 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
2462 }
2463
2464 UINT WINAPI MsiMessageBoxExA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2465 DWORD unknown, WORD wLanguageId, DWORD f)
2466 {
2467 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_a(lpText),
2468 debugstr_a(lpCaption), uType, unknown, wLanguageId, f);
2469 return MessageBoxExA(hWnd, lpText, lpCaption, uType, wLanguageId);
2470 }
2471
2472 UINT WINAPI MsiMessageBoxExW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2473 DWORD unknown, WORD wLanguageId, DWORD f)
2474 {
2475 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_w(lpText),
2476 debugstr_w(lpCaption), uType, unknown, wLanguageId, f);
2477 return MessageBoxExW(hWnd, lpText, lpCaption, uType, wLanguageId);
2478 }
2479
2480 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
2481 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
2482 LPDWORD pcchPathBuf )
2483 {
2484 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
2485 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2486 pcchPathBuf);
2487 return ERROR_CALL_NOT_IMPLEMENTED;
2488 }
2489
2490 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2491 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2492 LPDWORD pcchPathBuf )
2493 {
2494 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2495 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2496 pcchPathBuf);
2497 return ERROR_CALL_NOT_IMPLEMENTED;
2498 }
2499
2500 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2501 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2502 {
2503 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2504 return ERROR_CALL_NOT_IMPLEMENTED;
2505 }
2506
2507 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2508 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2509 {
2510 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2511 return ERROR_CALL_NOT_IMPLEMENTED;
2512 }
2513
2514 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2515 LPBYTE hash, LPDWORD hashlen )
2516 {
2517 UINT r;
2518 WCHAR *pathW = NULL;
2519
2520 TRACE("%s %08x %p %p %p\n", debugstr_a(path), flags, cert, hash, hashlen);
2521
2522 if (path && !(pathW = strdupAtoW( path ))) return ERROR_OUTOFMEMORY;
2523 r = MsiGetFileSignatureInformationW( pathW, flags, cert, hash, hashlen );
2524 msi_free( pathW );
2525 return r;
2526 }
2527
2528 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2529 LPBYTE hash, LPDWORD hashlen )
2530 {
2531 static GUID generic_verify_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
2532 HRESULT hr;
2533 WINTRUST_DATA data;
2534 WINTRUST_FILE_INFO info;
2535 CRYPT_PROVIDER_SGNR *signer;
2536 CRYPT_PROVIDER_CERT *provider;
2537
2538 TRACE("%s %08x %p %p %p\n", debugstr_w(path), flags, cert, hash, hashlen);
2539
2540 if (!path || !cert) return E_INVALIDARG;
2541
2542 info.cbStruct = sizeof(info);
2543 info.pcwszFilePath = path;
2544 info.hFile = NULL;
2545 info.pgKnownSubject = NULL;
2546
2547 data.cbStruct = sizeof(data);
2548 data.pPolicyCallbackData = NULL;
2549 data.pSIPClientData = NULL;
2550 data.dwUIChoice = WTD_UI_NONE;
2551 data.fdwRevocationChecks = WTD_REVOKE_WHOLECHAIN;
2552 data.dwUnionChoice = WTD_CHOICE_FILE;
2553 data.u.pFile = &info;
2554 data.dwStateAction = WTD_STATEACTION_VERIFY;
2555 data.hWVTStateData = NULL;
2556 data.pwszURLReference = NULL;
2557 data.dwProvFlags = 0;
2558 data.dwUIContext = WTD_UICONTEXT_INSTALL;
2559 hr = WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2560 *cert = NULL;
2561 if (FAILED(hr)) goto done;
2562
2563 if (!(signer = WTHelperGetProvSignerFromChain( data.hWVTStateData, 0, FALSE, 0 )))
2564 {
2565 hr = TRUST_E_NOSIGNATURE;
2566 goto done;
2567 }
2568 if (hash)
2569 {
2570 DWORD len = signer->psSigner->EncryptedHash.cbData;
2571 if (*hashlen < len)
2572 {
2573 *hashlen = len;
2574 hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
2575 goto done;
2576 }
2577 memcpy( hash, signer->psSigner->EncryptedHash.pbData, len );
2578 *hashlen = len;
2579 }
2580 if (!(provider = WTHelperGetProvCertFromChain( signer, 0 )))
2581 {
2582 hr = TRUST_E_PROVIDER_UNKNOWN;
2583 goto done;
2584 }
2585 *cert = CertDuplicateCertificateContext( provider->pCert );
2586
2587 done:
2588 data.dwStateAction = WTD_STATEACTION_CLOSE;
2589 WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2590 return hr;
2591 }
2592
2593 /******************************************************************
2594 * MsiGetProductPropertyA [MSI.@]
2595 */
2596 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2597 LPSTR szValue, LPDWORD pccbValue)
2598 {
2599 LPWSTR prop = NULL, val = NULL;
2600 DWORD len;
2601 UINT r;
2602
2603 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2604 szValue, pccbValue);
2605
2606 if (szValue && !pccbValue)
2607 return ERROR_INVALID_PARAMETER;
2608
2609 if (szProperty) prop = strdupAtoW(szProperty);
2610
2611 len = 0;
2612 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2613 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2614 goto done;
2615
2616 if (r == ERROR_SUCCESS)
2617 {
2618 if (szValue) *szValue = '\0';
2619 if (pccbValue) *pccbValue = 0;
2620 goto done;
2621 }
2622
2623 val = msi_alloc(++len * sizeof(WCHAR));
2624 if (!val)
2625 {
2626 r = ERROR_OUTOFMEMORY;
2627 goto done;
2628 }
2629
2630 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2631 if (r != ERROR_SUCCESS)
2632 goto done;
2633
2634 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2635
2636 if (szValue)
2637 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2638 *pccbValue, NULL, NULL);
2639
2640 if (pccbValue)
2641 {
2642 if (len > *pccbValue)
2643 r = ERROR_MORE_DATA;
2644
2645 *pccbValue = len - 1;
2646 }
2647
2648 done:
2649 msi_free(prop);
2650 msi_free(val);
2651
2652 return r;
2653 }
2654
2655 /******************************************************************
2656 * MsiGetProductPropertyW [MSI.@]
2657 */
2658 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2659 LPWSTR szValue, LPDWORD pccbValue)
2660 {
2661 MSIPACKAGE *package;
2662 MSIQUERY *view = NULL;
2663 MSIRECORD *rec = NULL;
2664 LPCWSTR val;
2665 UINT r;
2666
2667 static const WCHAR query[] = {
2668 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2669 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2670 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2671
2672 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2673 szValue, pccbValue);
2674
2675 if (!szProperty)
2676 return ERROR_INVALID_PARAMETER;
2677
2678 if (szValue && !pccbValue)
2679 return ERROR_INVALID_PARAMETER;
2680
2681 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2682 if (!package)
2683 return ERROR_INVALID_HANDLE;
2684
2685 r = MSI_OpenQuery(package->db, &view, query, szProperty);
2686 if (r != ERROR_SUCCESS)
2687 goto done;
2688
2689 r = MSI_ViewExecute(view, 0);
2690 if (r != ERROR_SUCCESS)
2691 goto done;
2692
2693 r = MSI_ViewFetch(view, &rec);
2694 if (r != ERROR_SUCCESS)
2695 goto done;
2696
2697 val = MSI_RecordGetString(rec, 2);
2698 if (!val)
2699 goto done;
2700
2701 if (lstrlenW(val) >= *pccbValue)
2702 {
2703 lstrcpynW(szValue, val, *pccbValue);
2704 *pccbValue = lstrlenW(val);
2705 r = ERROR_MORE_DATA;
2706 }
2707 else
2708 {
2709 lstrcpyW(szValue, val);
2710 *pccbValue = lstrlenW(val);
2711 r = ERROR_SUCCESS;
2712 }
2713
2714 done:
2715 if (view)
2716 {
2717 MSI_ViewClose(view);
2718 msiobj_release(&view->hdr);
2719 if (rec) msiobj_release(&rec->hdr);
2720 }
2721
2722 if (!rec)
2723 {
2724 if (szValue) *szValue = '\0';
2725 if (pccbValue) *pccbValue = 0;
2726 r = ERROR_SUCCESS;
2727 }
2728
2729 msiobj_release(&package->hdr);
2730 return r;
2731 }
2732
2733 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
2734 {
2735 UINT r;
2736 LPWSTR szPack = NULL;
2737
2738 TRACE("%s\n", debugstr_a(szPackage) );
2739
2740 if( szPackage )
2741 {
2742 szPack = strdupAtoW( szPackage );
2743 if( !szPack )
2744 return ERROR_OUTOFMEMORY;
2745 }
2746
2747 r = MsiVerifyPackageW( szPack );
2748
2749 msi_free( szPack );
2750
2751 return r;
2752 }
2753
2754 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
2755 {
2756 MSIHANDLE handle;
2757 UINT r;
2758
2759 TRACE("%s\n", debugstr_w(szPackage) );
2760
2761 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
2762 MsiCloseHandle( handle );
2763
2764 return r;
2765 }
2766
2767 static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
2768 awstring* lpPathBuf, LPDWORD pcchBuf)
2769 {
2770 static const WCHAR wininstaller[] =
2771 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2772 WCHAR squished_pc[GUID_SIZE];
2773 WCHAR squished_comp[GUID_SIZE];
2774 HKEY hkey;
2775 LPWSTR path = NULL;
2776 INSTALLSTATE state;
2777 DWORD version;
2778
2779 if (!szProduct || !szComponent)
2780 return INSTALLSTATE_INVALIDARG;
2781
2782 if (lpPathBuf->str.w && !pcchBuf)
2783 return INSTALLSTATE_INVALIDARG;
2784
2785 if (!squash_guid(szProduct, squished_pc) ||
2786 !squash_guid(szComponent, squished_comp))
2787 return INSTALLSTATE_INVALIDARG;
2788
2789 state = INSTALLSTATE_UNKNOWN;
2790
2791 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2792 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2793 {
2794 path = msi_reg_get_val_str(hkey, squished_pc);
2795 RegCloseKey(hkey);
2796
2797 state = INSTALLSTATE_ABSENT;
2798
2799 if ((MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL,
2800 &hkey, FALSE) == ERROR_SUCCESS ||
2801 MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2802 NULL, &hkey, FALSE) == ERROR_SUCCESS) &&
2803 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
2804 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2805 {
2806 RegCloseKey(hkey);
2807 state = INSTALLSTATE_LOCAL;
2808 }
2809 }
2810
2811 if (state != INSTALLSTATE_LOCAL &&
2812 (MSIREG_OpenProductKey(szProduct, NULL,
2813 MSIINSTALLCONTEXT_USERUNMANAGED,
2814 &hkey, FALSE) == ERROR_SUCCESS ||
2815 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2816 &hkey, FALSE) == ERROR_SUCCESS))
2817 {
2818 RegCloseKey(hkey);
2819
2820 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2821 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2822 {
2823 msi_free(path);
2824 path = msi_reg_get_val_str(hkey, squished_pc);
2825 RegCloseKey(hkey);
2826
2827 state = INSTALLSTATE_ABSENT;
2828
2829 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2830 state = INSTALLSTATE_LOCAL;
2831 }
2832 }
2833
2834 if (!path)
2835 return INSTALLSTATE_UNKNOWN;
2836
2837 if (state == INSTALLSTATE_LOCAL && !*path)
2838 state = INSTALLSTATE_NOTUSED;
2839
2840 if (msi_strcpy_to_awstring(path, -1, lpPathBuf, pcchBuf) == ERROR_MORE_DATA)
2841 state = INSTALLSTATE_MOREDATA;
2842
2843 msi_free(path);
2844 return state;
2845 }
2846
2847 /******************************************************************
2848 * MsiGetComponentPathW [MSI.@]
2849 */
2850 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
2851 LPWSTR lpPathBuf, LPDWORD pcchBuf)
2852 {
2853 awstring path;
2854
2855 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szComponent), lpPathBuf, pcchBuf);
2856
2857 path.unicode = TRUE;
2858 path.str.w = lpPathBuf;
2859
2860 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
2861 }
2862
2863 /******************************************************************
2864 * MsiGetComponentPathA [MSI.@]
2865 */
2866 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
2867 LPSTR lpPathBuf, LPDWORD pcchBuf)
2868 {
2869 LPWSTR szwProduct, szwComponent = NULL;
2870 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
2871 awstring path;
2872
2873 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szComponent), lpPathBuf, pcchBuf);
2874
2875 szwProduct = strdupAtoW( szProduct );
2876 if( szProduct && !szwProduct)
2877 goto end;
2878
2879 szwComponent = strdupAtoW( szComponent );
2880 if( szComponent && !szwComponent )
2881 goto end;
2882
2883 path.unicode = FALSE;
2884 path.str.a = lpPathBuf;
2885
2886 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
2887
2888 end:
2889 msi_free( szwProduct );
2890 msi_free( szwComponent );
2891
2892 return r;
2893 }
2894
2895 static UINT query_feature_state( const WCHAR *product, const WCHAR *squashed, const WCHAR *usersid,
2896 MSIINSTALLCONTEXT ctx, const WCHAR *feature, INSTALLSTATE *state )
2897 {
2898 UINT r;
2899 HKEY hkey;
2900 WCHAR *parent, *components, *path;
2901 const WCHAR *p;
2902 BOOL missing = FALSE, source = FALSE;
2903 WCHAR comp[GUID_SIZE];
2904 GUID guid;
2905
2906 if (ctx != MSIINSTALLCONTEXT_MACHINE) SetLastError( ERROR_SUCCESS );
2907
2908 if (MSIREG_OpenFeaturesKey( product, usersid, ctx, &hkey, FALSE )) return ERROR_UNKNOWN_PRODUCT;
2909
2910 parent = msi_reg_get_val_str( hkey, feature );
2911 RegCloseKey( hkey );
2912 if (!parent) return ERROR_UNKNOWN_FEATURE;
2913
2914 *state = (parent[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
2915 msi_free( parent );
2916 if (*state == INSTALLSTATE_ABSENT)
2917 return ERROR_SUCCESS;
2918
2919 r = MSIREG_OpenUserDataFeaturesKey( product, usersid, ctx, &hkey, FALSE );
2920 if (r != ERROR_SUCCESS)
2921 {
2922 *state = INSTALLSTATE_ADVERTISED;
2923 return ERROR_SUCCESS;
2924 }
2925 components = msi_reg_get_val_str( hkey, feature );
2926 RegCloseKey( hkey );
2927
2928 TRACE("buffer = %s\n", debugstr_w(components));
2929
2930 if (!components)
2931 {
2932 *state = INSTALLSTATE_ADVERTISED;
2933 return ERROR_SUCCESS;
2934 }
2935 for (p = components; *p && *p != 2 ; p += 20)
2936 {
2937 if (!decode_base85_guid( p, &guid ))
2938 {
2939 if (p != components) break;
2940 msi_free( components );
2941 *state = INSTALLSTATE_BADCONFIG;
2942 return ERROR_BAD_CONFIGURATION;
2943 }
2944 StringFromGUID2( &guid, comp, GUID_SIZE );
2945 if (ctx == MSIINSTALLCONTEXT_MACHINE)
2946 r = MSIREG_OpenUserDataComponentKey( comp, szLocalSid, &hkey, FALSE );
2947 else
2948 r = MSIREG_OpenUserDataComponentKey( comp, usersid, &hkey, FALSE );
2949
2950 if (r != ERROR_SUCCESS)
2951 {
2952 msi_free( components );
2953 *state = INSTALLSTATE_ADVERTISED;
2954 return ERROR_SUCCESS;
2955 }
2956 path = msi_reg_get_val_str( hkey, squashed );
2957 if (!path) missing = TRUE;
2958 else if (strlenW( path ) > 2 &&
2959 path[0] >= '0' && path[0] <= '9' &&
2960 path[1] >= '0' && path[1] <= '9')
2961 {
2962 source = TRUE;
2963 }
2964 msi_free( path );
2965 }
2966 msi_free( components );
2967
2968 if (missing)
2969 *state = INSTALLSTATE_ADVERTISED;
2970 else if (source)
2971 *state = INSTALLSTATE_SOURCE;
2972 else
2973 *state = INSTALLSTATE_LOCAL;
2974
2975 TRACE("returning state %d\n", *state);
2976 return ERROR_SUCCESS;
2977 }
2978
2979 UINT WINAPI MsiQueryFeatureStateExA( LPCSTR product, LPCSTR usersid, MSIINSTALLCONTEXT ctx,
2980 LPCSTR feature, INSTALLSTATE *state )
2981 {
2982 UINT r;
2983 WCHAR *productW = NULL, *usersidW = NULL, *featureW = NULL;
2984
2985 if (product && !(productW = strdupAtoW( product ))) return ERROR_OUTOFMEMORY;
2986 if (usersid && !(usersidW = strdupAtoW( usersid )))
2987 {
2988 msi_free( productW );
2989 return ERROR_OUTOFMEMORY;
2990 }
2991 if (feature && !(featureW = strdupAtoW( feature )))
2992 {
2993 msi_free( productW );
2994 msi_free( usersidW );
2995 return ERROR_OUTOFMEMORY;
2996 }
2997 r = MsiQueryFeatureStateExW( productW, usersidW, ctx, featureW, state );
2998 msi_free( productW );
2999 msi_free( usersidW );
3000 msi_free( featureW );
3001 return r;
3002 }
3003
3004 UINT WINAPI MsiQueryFeatureStateExW( LPCWSTR product, LPCWSTR usersid, MSIINSTALLCONTEXT ctx,
3005 LPCWSTR feature, INSTALLSTATE *state )
3006 {
3007 WCHAR squashed[33];
3008 if (!squash_guid( product, squashed )) return ERROR_INVALID_PARAMETER;
3009 return query_feature_state( product, squashed, usersid, ctx, feature, state );
3010 }
3011
3012 /******************************************************************
3013 * MsiQueryFeatureStateA [MSI.@]
3014 */
3015 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
3016 {
3017 LPWSTR szwProduct = NULL, szwFeature= NULL;
3018 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
3019
3020 szwProduct = strdupAtoW( szProduct );
3021 if ( szProduct && !szwProduct )
3022 goto end;
3023
3024 szwFeature = strdupAtoW( szFeature );
3025 if ( szFeature && !szwFeature )
3026 goto end;
3027
3028 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
3029
3030 end:
3031 msi_free( szwProduct);
3032 msi_free( szwFeature);
3033
3034 return rc;
3035 }
3036
3037 /******************************************************************
3038 * MsiQueryFeatureStateW [MSI.@]
3039 *
3040 * Checks the state of a feature
3041 *
3042 * PARAMS
3043 * szProduct [I] Product's GUID string
3044 * szFeature [I] Feature's GUID string
3045 *
3046 * RETURNS
3047 * INSTALLSTATE_LOCAL Feature is installed and usable
3048 * INSTALLSTATE_ABSENT Feature is absent
3049 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
3050 * INSTALLSTATE_UNKNOWN An error occurred
3051 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
3052 *
3053 */
3054 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
3055 {
3056 UINT r;
3057 INSTALLSTATE state;
3058 WCHAR squashed[33];
3059
3060 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
3061
3062 if (!szProduct || !szFeature || !squash_guid( szProduct, squashed ))
3063 return INSTALLSTATE_INVALIDARG;
3064
3065 r = query_feature_state( szProduct, squashed, NULL, MSIINSTALLCONTEXT_USERMANAGED, szFeature, &state );
3066 if (r == ERROR_SUCCESS || r == ERROR_BAD_CONFIGURATION) return state;
3067
3068 r = query_feature_state( szProduct, squashed, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, szFeature, &state );
3069 if (r == ERROR_SUCCESS || r == ERROR_BAD_CONFIGURATION) return state;
3070
3071 r = query_feature_state( szProduct, squashed, NULL, MSIINSTALLCONTEXT_MACHINE, szFeature, &state );
3072 if (r == ERROR_SUCCESS || r == ERROR_BAD_CONFIGURATION) return state;
3073
3074 return INSTALLSTATE_UNKNOWN;
3075 }
3076
3077 /******************************************************************
3078 * MsiGetFileVersionA [MSI.@]
3079 */
3080 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
3081 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
3082 {
3083 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
3084 UINT ret = ERROR_OUTOFMEMORY;
3085
3086 if ((lpVersionBuf && !pcchVersionBuf) ||
3087 (lpLangBuf && !pcchLangBuf))
3088 return ERROR_INVALID_PARAMETER;
3089
3090 if( szFilePath )
3091 {
3092 szwFilePath = strdupAtoW( szFilePath );
3093 if( !szwFilePath )
3094 goto end;
3095 }
3096
3097 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
3098 {
3099 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
3100 if( !lpwVersionBuff )
3101 goto end;
3102 }
3103
3104 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
3105 {
3106 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
3107 if( !lpwLangBuff )
3108 goto end;
3109 }
3110
3111 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
3112 lpwLangBuff, pcchLangBuf);
3113
3114 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
3115 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
3116 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
3117 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
3118 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
3119 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
3120
3121 end:
3122 msi_free(szwFilePath);
3123 msi_free(lpwVersionBuff);
3124 msi_free(lpwLangBuff);
3125
3126 return ret;
3127 }
3128
3129 static UINT get_file_version( const WCHAR *path, WCHAR *verbuf, DWORD *verlen,
3130 WCHAR *langbuf, DWORD *langlen )
3131 {
3132 static const WCHAR szVersionResource[] = {'\\',0};
3133 static const WCHAR szVersionFormat[] = {'%','d','.','%','d','.','%','d','.','%','d',0};
3134 static const WCHAR szLangFormat[] = {'%','d',0};
3135 UINT ret = ERROR_MORE_DATA;
3136 DWORD len, error;
3137 LPVOID version;
3138 VS_FIXEDFILEINFO *ffi;
3139 USHORT *lang;
3140 WCHAR tmp[32];
3141
3142 if (!(len = GetFileVersionInfoSizeW( path, NULL )))
3143 {
3144 error = GetLastError();
3145 if (error == ERROR_BAD_PATHNAME) return ERROR_FILE_NOT_FOUND;
3146 if (error == ERROR_RESOURCE_DATA_NOT_FOUND) return ERROR_FILE_INVALID;
3147 return error;
3148 }
3149 if (!(version = msi_alloc( len ))) return ERROR_OUTOFMEMORY;
3150 if (!GetFileVersionInfoW( path, 0, len, version ))
3151 {
3152 msi_free( version );
3153 return GetLastError();
3154 }
3155 if (!verbuf && !verlen && !langbuf && !langlen)
3156 {
3157 msi_free( version );
3158 return ERROR_SUCCESS;
3159 }
3160 if (verlen)
3161 {
3162 if (VerQueryValueW( version, szVersionResource, (LPVOID *)&ffi, &len ) && len > 0)
3163 {
3164 sprintfW( tmp, szVersionFormat,
3165 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
3166 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS) );
3167 if (verbuf) lstrcpynW( verbuf, tmp, *verlen );
3168 len = strlenW( tmp );
3169 if (*verlen > len) ret = ERROR_SUCCESS;
3170 *verlen = len;
3171 }
3172 else
3173 {
3174 if (verbuf) *verbuf = 0;