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