msi: Add more tests for MsiSourceListGetInfo.
[wine.git] / dlls / msi / msi.c
blob13b693fa750a64078c68939798e76bdbc5667f91
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002,2003,2004,2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #define COBJMACROS
24 #define NONAMELESSUNION
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winnls.h"
30 #include "shlwapi.h"
31 #include "wine/debug.h"
32 #include "msi.h"
33 #include "msidefs.h"
34 #include "msiquery.h"
35 #include "msipriv.h"
36 #include "wincrypt.h"
37 #include "winver.h"
38 #include "winuser.h"
39 #include "shlobj.h"
40 #include "shobjidl.h"
41 #include "objidl.h"
42 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msi);
46 static const WCHAR installerW[] = {'\\','I','n','s','t','a','l','l','e','r',0};
48 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
50 UINT r;
51 LPWSTR szwProd = NULL;
53 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
55 if( szProduct )
57 szwProd = strdupAtoW( szProduct );
58 if( !szwProd )
59 return ERROR_OUTOFMEMORY;
62 r = MsiOpenProductW( szwProd, phProduct );
64 msi_free( szwProd );
66 return r;
69 static UINT MSI_OpenProductW( LPCWSTR szProduct, MSIPACKAGE **ppackage )
71 LPWSTR path = NULL;
72 UINT r;
73 HKEY hKeyProduct = NULL;
74 DWORD count, type;
76 TRACE("%s %p\n", debugstr_w(szProduct), ppackage );
78 r = MSIREG_OpenUninstallKey(szProduct,&hKeyProduct,FALSE);
79 if( r != ERROR_SUCCESS )
81 r = ERROR_UNKNOWN_PRODUCT;
82 goto end;
85 /* find the size of the path */
86 type = count = 0;
87 r = RegQueryValueExW( hKeyProduct, INSTALLPROPERTY_LOCALPACKAGEW,
88 NULL, &type, NULL, &count );
89 if( r != ERROR_SUCCESS )
91 r = ERROR_UNKNOWN_PRODUCT;
92 goto end;
95 /* now alloc and fetch the path of the database to open */
96 path = msi_alloc( count );
97 if( !path )
98 goto end;
100 r = RegQueryValueExW( hKeyProduct, INSTALLPROPERTY_LOCALPACKAGEW,
101 NULL, &type, (LPBYTE) path, &count );
102 if( r != ERROR_SUCCESS )
104 r = ERROR_UNKNOWN_PRODUCT;
105 goto end;
108 r = MSI_OpenPackageW( path, ppackage );
110 end:
111 msi_free( path );
112 if( hKeyProduct )
113 RegCloseKey( hKeyProduct );
115 return r;
118 UINT WINAPI MsiOpenProductW( LPCWSTR szProduct, MSIHANDLE *phProduct )
120 MSIPACKAGE *package = NULL;
121 UINT r;
123 r = MSI_OpenProductW( szProduct, &package );
124 if( r == ERROR_SUCCESS )
126 *phProduct = alloc_msihandle( &package->hdr );
127 if (! *phProduct)
128 r = ERROR_NOT_ENOUGH_MEMORY;
129 msiobj_release( &package->hdr );
131 return r;
134 UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
135 LPCSTR szTransforms, LANGID lgidLanguage)
137 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath),
138 debugstr_a(szScriptfilePath), debugstr_a(szTransforms), lgidLanguage);
139 return ERROR_CALL_NOT_IMPLEMENTED;
142 UINT WINAPI MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
143 LPCWSTR szTransforms, LANGID lgidLanguage)
145 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath),
146 debugstr_w(szScriptfilePath), debugstr_w(szTransforms), lgidLanguage);
147 return ERROR_CALL_NOT_IMPLEMENTED;
150 UINT WINAPI MsiAdvertiseProductExA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
151 LPCSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
153 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath),
154 debugstr_a(szScriptfilePath), debugstr_a(szTransforms),
155 lgidLanguage, dwPlatform, dwOptions);
156 return ERROR_CALL_NOT_IMPLEMENTED;
159 UINT WINAPI MsiAdvertiseProductExW( LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
160 LPCWSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
162 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath),
163 debugstr_w(szScriptfilePath), debugstr_w(szTransforms),
164 lgidLanguage, dwPlatform, dwOptions);
165 return ERROR_CALL_NOT_IMPLEMENTED;
168 UINT WINAPI MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)
170 LPWSTR szwPath = NULL, szwCommand = NULL;
171 UINT r = ERROR_OUTOFMEMORY;
173 TRACE("%s %s\n",debugstr_a(szPackagePath), debugstr_a(szCommandLine));
175 if( szPackagePath )
177 szwPath = strdupAtoW( szPackagePath );
178 if( !szwPath )
179 goto end;
182 if( szCommandLine )
184 szwCommand = strdupAtoW( szCommandLine );
185 if( !szwCommand )
186 goto end;
189 r = MsiInstallProductW( szwPath, szwCommand );
191 end:
192 msi_free( szwPath );
193 msi_free( szwCommand );
195 return r;
198 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
200 MSIPACKAGE *package = NULL;
201 UINT r;
203 TRACE("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
205 r = MSI_OpenPackageW( szPackagePath, &package );
206 if (r == ERROR_SUCCESS)
208 r = MSI_InstallPackage( package, szPackagePath, szCommandLine );
209 msiobj_release( &package->hdr );
212 return r;
215 UINT WINAPI MsiReinstallProductA(LPCSTR szProduct, DWORD dwReinstallMode)
217 FIXME("%s %08x\n", debugstr_a(szProduct), dwReinstallMode);
218 return ERROR_CALL_NOT_IMPLEMENTED;
221 UINT WINAPI MsiReinstallProductW(LPCWSTR szProduct, DWORD dwReinstallMode)
223 FIXME("%s %08x\n", debugstr_w(szProduct), dwReinstallMode);
224 return ERROR_CALL_NOT_IMPLEMENTED;
227 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
228 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
230 LPWSTR patch_package = NULL;
231 LPWSTR install_package = NULL;
232 LPWSTR command_line = NULL;
233 UINT r = ERROR_OUTOFMEMORY;
235 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
236 eInstallType, debugstr_a(szCommandLine));
238 if (szPatchPackage && !(patch_package = strdupAtoW(szPatchPackage)))
239 goto done;
241 if (szInstallPackage && !(install_package = strdupAtoW(szInstallPackage)))
242 goto done;
244 if (szCommandLine && !(command_line = strdupAtoW(szCommandLine)))
245 goto done;
247 r = MsiApplyPatchW(patch_package, install_package, eInstallType, command_line);
249 done:
250 msi_free(patch_package);
251 msi_free(install_package);
252 msi_free(command_line);
254 return r;
257 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
258 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
260 MSIHANDLE patch, info;
261 UINT r, type;
262 DWORD size = 0;
263 LPCWSTR cmd_ptr = szCommandLine;
264 LPWSTR beg, end;
265 LPWSTR cmd = NULL, codes = NULL;
267 static const WCHAR space[] = {' ',0};
268 static const WCHAR patcheq[] = {'P','A','T','C','H','=',0};
269 static WCHAR empty[] = {0};
271 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
272 eInstallType, debugstr_w(szCommandLine));
274 if (szInstallPackage || eInstallType == INSTALLTYPE_NETWORK_IMAGE ||
275 eInstallType == INSTALLTYPE_SINGLE_INSTANCE)
277 FIXME("Only reading target products from patch\n");
278 return ERROR_CALL_NOT_IMPLEMENTED;
281 r = MsiOpenDatabaseW(szPatchPackage, MSIDBOPEN_READONLY, &patch);
282 if (r != ERROR_SUCCESS)
283 return r;
285 r = MsiGetSummaryInformationW(patch, NULL, 0, &info);
286 if (r != ERROR_SUCCESS)
287 goto done;
289 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, empty, &size);
290 if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
292 ERR("Failed to read product codes from patch\n");
293 goto done;
296 codes = msi_alloc(++size * sizeof(WCHAR));
297 if (!codes)
299 r = ERROR_OUTOFMEMORY;
300 goto done;
303 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, codes, &size);
304 if (r != ERROR_SUCCESS)
305 goto done;
307 if (!szCommandLine)
308 cmd_ptr = empty;
310 size = lstrlenW(cmd_ptr) + lstrlenW(patcheq) + lstrlenW(szPatchPackage) + 1;
311 cmd = msi_alloc(size * sizeof(WCHAR));
312 if (!cmd)
314 r = ERROR_OUTOFMEMORY;
315 goto done;
318 lstrcpyW(cmd, cmd_ptr);
319 if (szCommandLine) lstrcatW(cmd, space);
320 lstrcatW(cmd, patcheq);
321 lstrcatW(cmd, szPatchPackage);
323 beg = codes;
324 while ((end = strchrW(beg, '}')))
326 *(end + 1) = '\0';
328 r = MsiConfigureProductExW(beg, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
329 if (r != ERROR_SUCCESS)
330 goto done;
332 beg = end + 2;
335 done:
336 msi_free(cmd);
337 msi_free(codes);
339 MsiCloseHandle(info);
340 MsiCloseHandle(patch);
342 return r;
345 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
346 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
348 MSIPACKAGE* package = NULL;
349 UINT r;
350 DWORD sz;
351 WCHAR sourcepath[MAX_PATH];
352 WCHAR filename[MAX_PATH];
353 static const WCHAR szInstalled[] = {
354 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
355 LPWSTR commandline;
357 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
358 debugstr_w(szCommandLine));
360 if (eInstallState != INSTALLSTATE_LOCAL &&
361 eInstallState != INSTALLSTATE_DEFAULT)
363 FIXME("Not implemented for anything other than local installs\n");
364 return ERROR_CALL_NOT_IMPLEMENTED;
367 sz = sizeof(sourcepath);
368 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
369 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath,
370 &sz);
372 sz = sizeof(filename);
373 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
374 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
376 lstrcatW(sourcepath,filename);
379 * ok 1, we need to find the msi file for this product.
380 * 2, find the source dir for the files
381 * 3, do the configure/install.
382 * 4, cleanupany runonce entry.
385 r = MSI_OpenProductW( szProduct, &package );
386 if (r != ERROR_SUCCESS)
387 return r;
389 sz = lstrlenW(szInstalled) + 1;
391 if (szCommandLine)
392 sz += lstrlenW(szCommandLine);
394 commandline = msi_alloc(sz * sizeof(WCHAR));
395 if (!commandline )
397 r = ERROR_OUTOFMEMORY;
398 goto end;
401 commandline[0] = 0;
402 if (szCommandLine)
403 lstrcpyW(commandline,szCommandLine);
405 if (MsiQueryProductStateW(szProduct) != INSTALLSTATE_UNKNOWN)
406 lstrcatW(commandline,szInstalled);
408 r = MSI_InstallPackage( package, sourcepath, commandline );
410 msi_free(commandline);
412 end:
413 msiobj_release( &package->hdr );
415 return r;
418 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
419 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
421 LPWSTR szwProduct = NULL;
422 LPWSTR szwCommandLine = NULL;
423 UINT r = ERROR_OUTOFMEMORY;
425 if( szProduct )
427 szwProduct = strdupAtoW( szProduct );
428 if( !szwProduct )
429 goto end;
432 if( szCommandLine)
434 szwCommandLine = strdupAtoW( szCommandLine );
435 if( !szwCommandLine)
436 goto end;
439 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
440 szwCommandLine );
441 end:
442 msi_free( szwProduct );
443 msi_free( szwCommandLine);
445 return r;
448 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
449 INSTALLSTATE eInstallState)
451 LPWSTR szwProduct = NULL;
452 UINT r;
454 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
456 if( szProduct )
458 szwProduct = strdupAtoW( szProduct );
459 if( !szwProduct )
460 return ERROR_OUTOFMEMORY;
463 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
464 msi_free( szwProduct );
466 return r;
469 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
470 INSTALLSTATE eInstallState)
472 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
475 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
477 LPWSTR szwComponent = NULL;
478 UINT r;
479 WCHAR szwBuffer[GUID_SIZE];
481 TRACE("%s %s\n",debugstr_a(szComponent), debugstr_a(szBuffer));
483 if( szComponent )
485 szwComponent = strdupAtoW( szComponent );
486 if( !szwComponent )
487 return ERROR_OUTOFMEMORY;
490 *szwBuffer = '\0';
491 r = MsiGetProductCodeW( szwComponent, szwBuffer );
493 if(*szwBuffer)
494 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
496 msi_free( szwComponent );
498 return r;
501 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
503 UINT rc, index;
504 HKEY compkey, prodkey;
505 WCHAR squished_comp[GUID_SIZE];
506 WCHAR squished_prod[GUID_SIZE];
507 DWORD sz = GUID_SIZE;
509 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
511 if (!szComponent || !*szComponent)
512 return ERROR_INVALID_PARAMETER;
514 if (!squash_guid(szComponent, squished_comp))
515 return ERROR_INVALID_PARAMETER;
517 if (MSIREG_OpenUserDataComponentKey(szComponent, &compkey, FALSE) != ERROR_SUCCESS &&
518 MSIREG_OpenLocalSystemComponentKey(szComponent, &compkey, FALSE) != ERROR_SUCCESS)
520 return ERROR_UNKNOWN_COMPONENT;
523 rc = RegEnumValueW(compkey, 0, squished_prod, &sz, NULL, NULL, NULL, NULL);
524 if (rc != ERROR_SUCCESS)
526 RegCloseKey(compkey);
527 return ERROR_UNKNOWN_COMPONENT;
530 /* check simple case, only one product */
531 rc = RegEnumValueW(compkey, 1, squished_prod, &sz, NULL, NULL, NULL, NULL);
532 if (rc == ERROR_NO_MORE_ITEMS)
534 rc = ERROR_SUCCESS;
535 goto done;
538 index = 0;
539 while ((rc = RegEnumValueW(compkey, index, squished_prod, &sz,
540 NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
542 index++;
543 sz = GUID_SIZE;
544 unsquash_guid(squished_prod, szBuffer);
546 if (MSIREG_OpenLocalManagedProductKey(szBuffer, &prodkey, FALSE) == ERROR_SUCCESS ||
547 MSIREG_OpenUserProductsKey(szBuffer, &prodkey, FALSE) == ERROR_SUCCESS ||
548 MSIREG_OpenLocalClassesProductKey(szBuffer, &prodkey, FALSE) == ERROR_SUCCESS)
550 RegCloseKey(prodkey);
551 rc = ERROR_SUCCESS;
552 goto done;
556 rc = ERROR_INSTALL_FAILURE;
558 done:
559 RegCloseKey(compkey);
560 unsquash_guid(squished_prod, szBuffer);
561 return rc;
564 static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
566 DWORD dval;
567 LONG res;
568 WCHAR temp[20];
570 static const WCHAR format[] = {'%','d',0};
572 res = RegQueryValueExW(hkey, name, NULL, type, NULL, NULL);
573 if (res != ERROR_SUCCESS)
574 return NULL;
576 if (*type == REG_SZ)
577 return msi_reg_get_val_str(hkey, name);
579 if (!msi_reg_get_val_dword(hkey, name, &dval))
580 return NULL;
582 sprintfW(temp, format, dval);
583 return strdupW(temp);
586 static UINT WINAPI MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
587 awstring *szValue, LPDWORD pcchValueBuf)
589 UINT r = ERROR_UNKNOWN_PROPERTY;
590 HKEY prodkey, userdata, source;
591 LPWSTR val = NULL;
592 WCHAR squished_pc[GUID_SIZE];
593 WCHAR packagecode[GUID_SIZE];
594 BOOL classes = FALSE;
595 BOOL badconfig = FALSE;
596 LONG res;
597 DWORD save, type;
599 static WCHAR empty[] = {0};
600 static const WCHAR sourcelist[] = {
601 'S','o','u','r','c','e','L','i','s','t',0};
602 static const WCHAR display_name[] = {
603 'D','i','s','p','l','a','y','N','a','m','e',0};
604 static const WCHAR display_version[] = {
605 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
606 static const WCHAR assignment[] = {
607 'A','s','s','i','g','n','m','e','n','t',0};
609 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
610 debugstr_w(szAttribute), szValue, pcchValueBuf);
612 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
613 return ERROR_INVALID_PARAMETER;
615 if (!squash_guid(szProduct, squished_pc))
616 return ERROR_INVALID_PARAMETER;
618 r = MSIREG_OpenLocalManagedProductKey(szProduct, &prodkey, FALSE);
619 if (r != ERROR_SUCCESS)
621 r = MSIREG_OpenUserProductsKey(szProduct, &prodkey, FALSE);
622 if (r != ERROR_SUCCESS)
624 r = MSIREG_OpenLocalClassesProductKey(szProduct, &prodkey, FALSE);
625 if (r == ERROR_SUCCESS)
626 classes = TRUE;
630 if (classes)
631 MSIREG_OpenLocalSystemProductKey(szProduct, &userdata, FALSE);
632 else
633 MSIREG_OpenInstallPropertiesKey(szProduct, &userdata, FALSE);
635 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_HELPLINKW) ||
636 !lstrcmpW(szAttribute, INSTALLPROPERTY_HELPTELEPHONEW) ||
637 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLDATEW) ||
638 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
639 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW) ||
640 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLSOURCEW) ||
641 !lstrcmpW(szAttribute, INSTALLPROPERTY_LOCALPACKAGEW) ||
642 !lstrcmpW(szAttribute, INSTALLPROPERTY_PUBLISHERW) ||
643 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLINFOABOUTW) ||
644 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLUPDATEINFOW) ||
645 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMINORW) ||
646 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMAJORW) ||
647 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW) ||
648 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTIDW) ||
649 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGCOMPANYW) ||
650 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGOWNERW))
652 if (!prodkey)
654 r = ERROR_UNKNOWN_PRODUCT;
655 goto done;
658 if (!userdata)
659 return ERROR_UNKNOWN_PROPERTY;
661 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
662 szAttribute = display_name;
663 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW))
664 szAttribute = display_version;
666 val = msi_reg_get_value(userdata, szAttribute, &type);
667 if (!val)
668 val = empty;
670 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTANCETYPEW) ||
671 !lstrcmpW(szAttribute, INSTALLPROPERTY_TRANSFORMSW) ||
672 !lstrcmpW(szAttribute, INSTALLPROPERTY_LANGUAGEW) ||
673 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTNAMEW) ||
674 !lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW) ||
675 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW) ||
676 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONW) ||
677 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTICONW) ||
678 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW) ||
679 !lstrcmpW(szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
681 if (!prodkey)
683 r = ERROR_UNKNOWN_PRODUCT;
684 goto done;
687 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW))
688 szAttribute = assignment;
690 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW))
692 res = RegOpenKeyW(prodkey, sourcelist, &source);
693 if (res == ERROR_SUCCESS)
694 val = msi_reg_get_value(source, szAttribute, &type);
696 RegCloseKey(source);
698 else
700 val = msi_reg_get_value(prodkey, szAttribute, &type);
701 if (!val)
702 val = empty;
705 if (val != empty && type != REG_DWORD &&
706 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW))
708 if (lstrlenW(val) != SQUISH_GUID_SIZE - 1)
709 badconfig = TRUE;
710 else
712 unsquash_guid(val, packagecode);
713 msi_free(val);
714 val = strdupW(packagecode);
719 if (!val)
721 r = ERROR_UNKNOWN_PROPERTY;
722 goto done;
725 save = *pcchValueBuf;
727 if (lstrlenW(val) < *pcchValueBuf)
728 r = msi_strcpy_to_awstring(val, szValue, pcchValueBuf);
729 else if (szValue->str.a || szValue->str.w)
730 r = ERROR_MORE_DATA;
732 if (!badconfig)
733 *pcchValueBuf = lstrlenW(val);
734 else if (r == ERROR_SUCCESS)
736 *pcchValueBuf = save;
737 r = ERROR_BAD_CONFIGURATION;
740 if (val != empty)
741 msi_free(val);
743 done:
744 RegCloseKey(prodkey);
745 RegCloseKey(userdata);
746 return r;
749 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
750 LPSTR szBuffer, LPDWORD pcchValueBuf)
752 LPWSTR szwProduct, szwAttribute = NULL;
753 UINT r = ERROR_OUTOFMEMORY;
754 awstring buffer;
756 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
757 szBuffer, pcchValueBuf);
759 szwProduct = strdupAtoW( szProduct );
760 if( szProduct && !szwProduct )
761 goto end;
763 szwAttribute = strdupAtoW( szAttribute );
764 if( szAttribute && !szwAttribute )
765 goto end;
767 buffer.unicode = FALSE;
768 buffer.str.a = szBuffer;
770 r = MSI_GetProductInfo( szwProduct, szwAttribute,
771 &buffer, pcchValueBuf );
773 end:
774 msi_free( szwProduct );
775 msi_free( szwAttribute );
777 return r;
780 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
781 LPWSTR szBuffer, LPDWORD pcchValueBuf)
783 awstring buffer;
785 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
786 szBuffer, pcchValueBuf);
788 buffer.unicode = TRUE;
789 buffer.str.w = szBuffer;
791 return MSI_GetProductInfo( szProduct, szAttribute,
792 &buffer, pcchValueBuf );
795 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
797 LPWSTR szwLogFile = NULL;
798 UINT r;
800 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
802 if( szLogFile )
804 szwLogFile = strdupAtoW( szLogFile );
805 if( !szwLogFile )
806 return ERROR_OUTOFMEMORY;
808 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
809 msi_free( szwLogFile );
810 return r;
813 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
815 HANDLE file = INVALID_HANDLE_VALUE;
817 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
819 if (szLogFile)
821 lstrcpyW(gszLogFile,szLogFile);
822 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
823 DeleteFileW(szLogFile);
824 file = CreateFileW(szLogFile, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
825 FILE_ATTRIBUTE_NORMAL, NULL);
826 if (file != INVALID_HANDLE_VALUE)
827 CloseHandle(file);
828 else
829 ERR("Unable to enable log %s\n",debugstr_w(szLogFile));
831 else
832 gszLogFile[0] = '\0';
834 return ERROR_SUCCESS;
837 UINT WINAPI MsiEnumComponentCostsW(MSIHANDLE hInstall, LPCWSTR szComponent,
838 DWORD dwIndex, INSTALLSTATE iState,
839 LPWSTR lpDriveBuf, DWORD *pcchDriveBuf,
840 int *piCost, int *pTempCost)
842 FIXME("(%ld, %s, %d, %d, %p, %p, %p %p): stub!\n", hInstall,
843 debugstr_w(szComponent), dwIndex, iState, lpDriveBuf,
844 pcchDriveBuf, piCost, pTempCost);
846 return ERROR_NO_MORE_ITEMS;
849 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
850 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
851 LPCSTR szComponent, INSTALLSTATE *pdwState)
853 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
854 UINT r;
856 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
857 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
859 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
860 return ERROR_OUTOFMEMORY;
862 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
863 return ERROR_OUTOFMEMORY;
865 if (szComponent && !(comp = strdupAtoW(szComponent)))
866 return ERROR_OUTOFMEMORY;
868 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
870 msi_free(prodcode);
871 msi_free(usersid);
872 msi_free(comp);
874 return r;
877 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
879 UINT r;
880 HKEY hkey;
882 if (context == MSIINSTALLCONTEXT_MACHINE)
883 r = MSIREG_OpenLocalClassesProductKey(prodcode, &hkey, FALSE);
884 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
885 r = MSIREG_OpenUserProductsKey(prodcode, &hkey, FALSE);
886 else
887 r = MSIREG_OpenLocalManagedProductKey(prodcode, &hkey, FALSE);
889 RegCloseKey(hkey);
890 return (r == ERROR_SUCCESS);
893 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
895 LPCWSTR package;
896 HKEY hkey;
897 DWORD sz;
898 LONG res;
899 UINT r;
901 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
902 static const WCHAR managed_local_package[] = {
903 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
906 if (context == MSIINSTALLCONTEXT_MACHINE)
907 r = MSIREG_OpenLocalSystemProductKey(prodcode, &hkey, FALSE);
908 else
909 r = MSIREG_OpenInstallPropertiesKey(prodcode, &hkey, FALSE);
911 if (r != ERROR_SUCCESS)
912 return FALSE;
914 if (context == MSIINSTALLCONTEXT_USERMANAGED)
915 package = managed_local_package;
916 else
917 package = local_package;
919 sz = 0;
920 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
921 RegCloseKey(hkey);
923 return (res == ERROR_SUCCESS);
926 static BOOL msi_comp_find_prodcode(LPWSTR squished_pc,
927 MSIINSTALLCONTEXT context,
928 LPCWSTR comp, DWORD *sz)
930 HKEY hkey;
931 LONG res;
932 UINT r;
934 if (context == MSIINSTALLCONTEXT_MACHINE)
935 r = MSIREG_OpenLocalSystemComponentKey(comp, &hkey, FALSE);
936 else
937 r = MSIREG_OpenUserDataComponentKey(comp, &hkey, FALSE);
939 if (r != ERROR_SUCCESS)
940 return FALSE;
942 *sz = 0;
943 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, NULL, sz);
944 if (res != ERROR_SUCCESS)
945 return FALSE;
947 RegCloseKey(hkey);
948 return TRUE;
951 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
952 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
953 LPCWSTR szComponent, INSTALLSTATE *pdwState)
955 WCHAR squished_pc[GUID_SIZE];
956 BOOL found;
957 DWORD sz;
959 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
960 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
962 if (!pdwState)
963 return ERROR_INVALID_PARAMETER;
965 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
966 return ERROR_INVALID_PARAMETER;
968 if (!squash_guid(szProductCode, squished_pc))
969 return ERROR_INVALID_PARAMETER;
971 found = msi_comp_find_prod_key(szProductCode, dwContext);
973 if (!msi_comp_find_package(szProductCode, dwContext))
975 if (found)
977 *pdwState = INSTALLSTATE_UNKNOWN;
978 return ERROR_UNKNOWN_COMPONENT;
981 return ERROR_UNKNOWN_PRODUCT;
984 *pdwState = INSTALLSTATE_UNKNOWN;
986 if (!msi_comp_find_prodcode(squished_pc, dwContext, szComponent, &sz))
987 return ERROR_UNKNOWN_COMPONENT;
989 if (sz == 0)
990 *pdwState = INSTALLSTATE_NOTUSED;
991 else
992 *pdwState = INSTALLSTATE_LOCAL;
994 return ERROR_SUCCESS;
997 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
999 LPWSTR szwProduct = NULL;
1000 INSTALLSTATE r;
1002 if( szProduct )
1004 szwProduct = strdupAtoW( szProduct );
1005 if( !szwProduct )
1006 return ERROR_OUTOFMEMORY;
1008 r = MsiQueryProductStateW( szwProduct );
1009 msi_free( szwProduct );
1010 return r;
1013 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
1015 UINT rc;
1016 INSTALLSTATE state = INSTALLSTATE_UNKNOWN;
1017 HKEY hkey = 0, props = 0;
1018 DWORD sz;
1019 BOOL userkey_exists = FALSE;
1021 static const int GUID_LEN = 38;
1022 static const WCHAR szInstallProperties[] = {
1023 'I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0
1025 static const WCHAR szWindowsInstaller[] = {
1026 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0
1029 TRACE("%s\n", debugstr_w(szProduct));
1031 if (!szProduct || !*szProduct || lstrlenW(szProduct) != GUID_LEN)
1032 return INSTALLSTATE_INVALIDARG;
1034 rc = MSIREG_OpenUserProductsKey(szProduct,&hkey,FALSE);
1035 if (rc == ERROR_SUCCESS)
1037 userkey_exists = TRUE;
1038 state = INSTALLSTATE_ADVERTISED;
1039 RegCloseKey(hkey);
1042 rc = MSIREG_OpenUserDataProductKey(szProduct,&hkey,FALSE);
1043 if (rc != ERROR_SUCCESS)
1044 goto end;
1046 rc = RegOpenKeyW(hkey, szInstallProperties, &props);
1047 if (rc != ERROR_SUCCESS)
1048 goto end;
1050 sz = sizeof(state);
1051 rc = RegQueryValueExW(props,szWindowsInstaller,NULL,NULL,(LPVOID)&state, &sz);
1052 if (rc != ERROR_SUCCESS)
1053 goto end;
1055 if (state)
1056 state = INSTALLSTATE_DEFAULT;
1057 else
1058 state = INSTALLSTATE_UNKNOWN;
1060 if (state == INSTALLSTATE_DEFAULT && !userkey_exists)
1061 state = INSTALLSTATE_ABSENT;
1063 end:
1064 RegCloseKey(props);
1065 RegCloseKey(hkey);
1066 return state;
1069 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
1071 INSTALLUILEVEL old = gUILevel;
1072 HWND oldwnd = gUIhwnd;
1074 TRACE("%08x %p\n", dwUILevel, phWnd);
1076 gUILevel = dwUILevel;
1077 if (phWnd)
1079 gUIhwnd = *phWnd;
1080 *phWnd = oldwnd;
1082 return old;
1085 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
1086 DWORD dwMessageFilter, LPVOID pvContext)
1088 INSTALLUI_HANDLERA prev = gUIHandlerA;
1090 TRACE("%p %x %p\n",puiHandler, dwMessageFilter,pvContext);
1091 gUIHandlerA = puiHandler;
1092 gUIFilter = dwMessageFilter;
1093 gUIContext = pvContext;
1095 return prev;
1098 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
1099 DWORD dwMessageFilter, LPVOID pvContext)
1101 INSTALLUI_HANDLERW prev = gUIHandlerW;
1103 TRACE("%p %x %p\n",puiHandler,dwMessageFilter,pvContext);
1104 gUIHandlerW = puiHandler;
1105 gUIFilter = dwMessageFilter;
1106 gUIContext = pvContext;
1108 return prev;
1111 /******************************************************************
1112 * MsiLoadStringW [MSI.@]
1114 * Loads a string from MSI's string resources.
1116 * PARAMS
1118 * handle [I] only -1 is handled currently
1119 * id [I] id of the string to be loaded
1120 * lpBuffer [O] buffer for the string to be written to
1121 * nBufferMax [I] maximum size of the buffer in characters
1122 * lang [I] the preferred language for the string
1124 * RETURNS
1126 * If successful, this function returns the language id of the string loaded
1127 * If the function fails, the function returns zero.
1129 * NOTES
1131 * The type of the first parameter is unknown. LoadString's prototype
1132 * suggests that it might be a module handle. I have made it an MSI handle
1133 * for starters, as -1 is an invalid MSI handle, but not an invalid module
1134 * handle. Maybe strings can be stored in an MSI database somehow.
1136 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
1137 int nBufferMax, LANGID lang )
1139 HRSRC hres;
1140 HGLOBAL hResData;
1141 LPWSTR p;
1142 DWORD i, len;
1144 TRACE("%ld %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
1146 if( handle != -1 )
1147 FIXME("don't know how to deal with handle = %08lx\n", handle);
1149 if( !lang )
1150 lang = GetUserDefaultLangID();
1152 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
1153 (LPWSTR)1, lang );
1154 if( !hres )
1155 return 0;
1156 hResData = LoadResource( msi_hInstance, hres );
1157 if( !hResData )
1158 return 0;
1159 p = LockResource( hResData );
1160 if( !p )
1161 return 0;
1163 for (i = 0; i < (id&0xf); i++)
1164 p += *p + 1;
1165 len = *p;
1167 if( nBufferMax <= len )
1168 return 0;
1170 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
1171 lpBuffer[ len ] = 0;
1173 TRACE("found -> %s\n", debugstr_w(lpBuffer));
1175 return lang;
1178 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
1179 int nBufferMax, LANGID lang )
1181 LPWSTR bufW;
1182 LANGID r;
1183 DWORD len;
1185 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
1186 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
1187 if( r )
1189 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
1190 if( len <= nBufferMax )
1191 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
1192 lpBuffer, nBufferMax, NULL, NULL );
1193 else
1194 r = 0;
1196 msi_free(bufW);
1197 return r;
1200 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
1201 LPDWORD pcchBuf)
1203 char szProduct[GUID_SIZE];
1205 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
1207 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
1208 return INSTALLSTATE_UNKNOWN;
1210 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
1213 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
1214 LPDWORD pcchBuf)
1216 WCHAR szProduct[GUID_SIZE];
1218 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
1220 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
1221 return INSTALLSTATE_UNKNOWN;
1223 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
1226 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
1227 WORD wLanguageId, DWORD f)
1229 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
1230 uType, wLanguageId, f);
1231 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
1234 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
1235 WORD wLanguageId, DWORD f)
1237 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
1238 uType, wLanguageId, f);
1239 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
1242 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
1243 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
1244 LPDWORD pcchPathBuf )
1246 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
1247 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
1248 pcchPathBuf);
1249 return ERROR_CALL_NOT_IMPLEMENTED;
1252 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
1253 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
1254 LPDWORD pcchPathBuf )
1256 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
1257 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
1258 pcchPathBuf);
1259 return ERROR_CALL_NOT_IMPLEMENTED;
1262 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
1263 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
1265 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
1266 return ERROR_CALL_NOT_IMPLEMENTED;
1269 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
1270 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
1272 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
1273 return ERROR_CALL_NOT_IMPLEMENTED;
1276 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath,
1277 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
1278 LPDWORD pcbHashData)
1280 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath), dwFlags,
1281 ppcCertContext, pbHashData, pcbHashData);
1282 return ERROR_CALL_NOT_IMPLEMENTED;
1285 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath,
1286 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
1287 LPDWORD pcbHashData)
1289 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath), dwFlags,
1290 ppcCertContext, pbHashData, pcbHashData);
1291 return ERROR_CALL_NOT_IMPLEMENTED;
1294 UINT WINAPI MsiGetProductPropertyA( MSIHANDLE hProduct, LPCSTR szProperty,
1295 LPSTR szValue, LPDWORD pccbValue )
1297 FIXME("%ld %s %p %p\n", hProduct, debugstr_a(szProperty), szValue, pccbValue);
1298 return ERROR_CALL_NOT_IMPLEMENTED;
1301 UINT WINAPI MsiGetProductPropertyW( MSIHANDLE hProduct, LPCWSTR szProperty,
1302 LPWSTR szValue, LPDWORD pccbValue )
1304 FIXME("%ld %s %p %p\n", hProduct, debugstr_w(szProperty), szValue, pccbValue);
1305 return ERROR_CALL_NOT_IMPLEMENTED;
1308 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
1310 UINT r;
1311 LPWSTR szPack = NULL;
1313 TRACE("%s\n", debugstr_a(szPackage) );
1315 if( szPackage )
1317 szPack = strdupAtoW( szPackage );
1318 if( !szPack )
1319 return ERROR_OUTOFMEMORY;
1322 r = MsiVerifyPackageW( szPack );
1324 msi_free( szPack );
1326 return r;
1329 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
1331 MSIHANDLE handle;
1332 UINT r;
1334 TRACE("%s\n", debugstr_w(szPackage) );
1336 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
1337 MsiCloseHandle( handle );
1339 return r;
1342 static INSTALLSTATE WINAPI MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
1343 awstring* lpPathBuf, LPDWORD pcchBuf)
1345 WCHAR squished_pc[GUID_SIZE];
1346 WCHAR squished_comp[GUID_SIZE];
1347 HKEY hkey;
1348 LPWSTR path = NULL;
1349 INSTALLSTATE state;
1350 DWORD version;
1352 static const WCHAR wininstaller[] = {
1353 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
1355 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
1356 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
1358 if (!szProduct || !szComponent)
1359 return INSTALLSTATE_INVALIDARG;
1361 if (lpPathBuf->str.w && !pcchBuf)
1362 return INSTALLSTATE_INVALIDARG;
1364 if (!squash_guid(szProduct, squished_pc) ||
1365 !squash_guid(szComponent, squished_comp))
1366 return INSTALLSTATE_INVALIDARG;
1368 state = INSTALLSTATE_UNKNOWN;
1370 if (MSIREG_OpenLocalSystemComponentKey(szComponent, &hkey, FALSE) == ERROR_SUCCESS ||
1371 MSIREG_OpenUserDataComponentKey(szComponent, &hkey, FALSE) == ERROR_SUCCESS)
1373 path = msi_reg_get_val_str(hkey, squished_pc);
1374 RegCloseKey(hkey);
1376 state = INSTALLSTATE_ABSENT;
1378 if ((MSIREG_OpenLocalSystemProductKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS ||
1379 MSIREG_OpenUserDataProductKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS) &&
1380 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
1381 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
1383 RegCloseKey(hkey);
1384 state = INSTALLSTATE_LOCAL;
1388 if (state != INSTALLSTATE_LOCAL &&
1389 (MSIREG_OpenUserProductsKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS ||
1390 MSIREG_OpenLocalClassesProductKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS))
1392 RegCloseKey(hkey);
1394 if (MSIREG_OpenLocalSystemComponentKey(szComponent, &hkey, FALSE) == ERROR_SUCCESS ||
1395 MSIREG_OpenUserDataComponentKey(szComponent, &hkey, FALSE) == ERROR_SUCCESS)
1397 msi_free(path);
1398 path = msi_reg_get_val_str(hkey, squished_pc);
1399 RegCloseKey(hkey);
1401 state = INSTALLSTATE_ABSENT;
1403 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
1404 state = INSTALLSTATE_LOCAL;
1408 if (!path)
1409 return INSTALLSTATE_UNKNOWN;
1411 if (state == INSTALLSTATE_LOCAL && !*path)
1412 state = INSTALLSTATE_NOTUSED;
1414 msi_strcpy_to_awstring(path, lpPathBuf, pcchBuf);
1415 msi_free(path);
1416 return state;
1419 /******************************************************************
1420 * MsiGetComponentPathW [MSI.@]
1422 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
1423 LPWSTR lpPathBuf, LPDWORD pcchBuf)
1425 awstring path;
1427 path.unicode = TRUE;
1428 path.str.w = lpPathBuf;
1430 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
1433 /******************************************************************
1434 * MsiGetComponentPathA [MSI.@]
1436 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
1437 LPSTR lpPathBuf, LPDWORD pcchBuf)
1439 LPWSTR szwProduct, szwComponent = NULL;
1440 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
1441 awstring path;
1443 szwProduct = strdupAtoW( szProduct );
1444 if( szProduct && !szwProduct)
1445 goto end;
1447 szwComponent = strdupAtoW( szComponent );
1448 if( szComponent && !szwComponent )
1449 goto end;
1451 path.unicode = FALSE;
1452 path.str.a = lpPathBuf;
1454 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
1456 end:
1457 msi_free( szwProduct );
1458 msi_free( szwComponent );
1460 return r;
1463 /******************************************************************
1464 * MsiQueryFeatureStateA [MSI.@]
1466 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
1468 LPWSTR szwProduct = NULL, szwFeature= NULL;
1469 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
1471 szwProduct = strdupAtoW( szProduct );
1472 if ( szProduct && !szwProduct )
1473 goto end;
1475 szwFeature = strdupAtoW( szFeature );
1476 if ( szFeature && !szwFeature )
1477 goto end;
1479 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
1481 end:
1482 msi_free( szwProduct);
1483 msi_free( szwFeature);
1485 return rc;
1488 /******************************************************************
1489 * MsiQueryFeatureStateW [MSI.@]
1491 * Checks the state of a feature
1493 * PARAMS
1494 * szProduct [I] Product's GUID string
1495 * szFeature [I] Feature's GUID string
1497 * RETURNS
1498 * INSTALLSTATE_LOCAL Feature is installed and useable
1499 * INSTALLSTATE_ABSENT Feature is absent
1500 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
1501 * INSTALLSTATE_UNKNOWN An error occurred
1502 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
1505 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
1507 WCHAR squishProduct[33], comp[GUID_SIZE];
1508 GUID guid;
1509 LPWSTR components, p, parent_feature, path;
1510 UINT rc;
1511 HKEY hkey;
1512 INSTALLSTATE r;
1513 BOOL missing = FALSE;
1515 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
1517 if (!szProduct || !szFeature)
1518 return INSTALLSTATE_INVALIDARG;
1520 if (!squash_guid( szProduct, squishProduct ))
1521 return INSTALLSTATE_INVALIDARG;
1523 /* check that it's installed at all */
1524 rc = MSIREG_OpenUserFeaturesKey(szProduct, &hkey, FALSE);
1525 if (rc != ERROR_SUCCESS)
1526 return INSTALLSTATE_UNKNOWN;
1528 parent_feature = msi_reg_get_val_str( hkey, szFeature );
1529 RegCloseKey(hkey);
1531 if (!parent_feature)
1532 return INSTALLSTATE_UNKNOWN;
1534 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
1535 msi_free(parent_feature);
1536 if (r == INSTALLSTATE_ABSENT)
1537 return r;
1539 /* now check if it's complete or advertised */
1540 rc = MSIREG_OpenUserDataFeaturesKey(szProduct, &hkey, FALSE);
1541 if (rc != ERROR_SUCCESS)
1542 return INSTALLSTATE_ADVERTISED;
1544 components = msi_reg_get_val_str( hkey, szFeature );
1545 RegCloseKey(hkey);
1547 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
1549 if (!components)
1550 return INSTALLSTATE_ADVERTISED;
1552 for( p = components; *p && *p != 2 ; p += 20)
1554 if (!decode_base85_guid( p, &guid ))
1556 if (p != components)
1557 break;
1559 msi_free(components);
1560 return INSTALLSTATE_BADCONFIG;
1563 StringFromGUID2(&guid, comp, GUID_SIZE);
1564 rc = MSIREG_OpenUserDataComponentKey(comp, &hkey, FALSE);
1565 if (rc != ERROR_SUCCESS)
1567 msi_free(components);
1568 return INSTALLSTATE_ADVERTISED;
1571 path = msi_reg_get_val_str(hkey, squishProduct);
1572 if (!path)
1573 missing = TRUE;
1575 msi_free(path);
1578 TRACE("%s %s -> %d\n", debugstr_w(szProduct), debugstr_w(szFeature), r);
1579 msi_free(components);
1581 if (missing)
1582 return INSTALLSTATE_ADVERTISED;
1584 return INSTALLSTATE_LOCAL;
1587 /******************************************************************
1588 * MsiGetFileVersionA [MSI.@]
1590 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
1591 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
1593 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
1594 UINT ret = ERROR_OUTOFMEMORY;
1596 if ((lpVersionBuf && !pcchVersionBuf) ||
1597 (lpLangBuf && !pcchLangBuf))
1598 return ERROR_INVALID_PARAMETER;
1600 if( szFilePath )
1602 szwFilePath = strdupAtoW( szFilePath );
1603 if( !szwFilePath )
1604 goto end;
1607 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
1609 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
1610 if( !lpwVersionBuff )
1611 goto end;
1614 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
1616 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
1617 if( !lpwLangBuff )
1618 goto end;
1621 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
1622 lpwLangBuff, pcchLangBuf);
1624 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
1625 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
1626 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
1627 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
1628 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
1629 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
1631 end:
1632 msi_free(szwFilePath);
1633 msi_free(lpwVersionBuff);
1634 msi_free(lpwLangBuff);
1636 return ret;
1639 /******************************************************************
1640 * MsiGetFileVersionW [MSI.@]
1642 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
1643 LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
1645 static const WCHAR szVersionResource[] = {'\\',0};
1646 static const WCHAR szVersionFormat[] = {
1647 '%','d','.','%','d','.','%','d','.','%','d',0};
1648 static const WCHAR szLangResource[] = {
1649 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
1650 'T','r','a','n','s','l','a','t','i','o','n',0};
1651 static const WCHAR szLangFormat[] = {'%','d',0};
1652 UINT ret = 0;
1653 DWORD dwVerLen, gle;
1654 LPVOID lpVer = NULL;
1655 VS_FIXEDFILEINFO *ffi;
1656 USHORT *lang;
1657 UINT puLen;
1658 WCHAR tmp[32];
1660 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
1661 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
1662 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
1664 if ((lpVersionBuf && !pcchVersionBuf) ||
1665 (lpLangBuf && !pcchLangBuf))
1666 return ERROR_INVALID_PARAMETER;
1668 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
1669 if( !dwVerLen )
1671 gle = GetLastError();
1672 if (gle == ERROR_BAD_PATHNAME)
1673 return ERROR_FILE_NOT_FOUND;
1674 else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND)
1675 return ERROR_FILE_INVALID;
1677 return gle;
1680 lpVer = msi_alloc(dwVerLen);
1681 if( !lpVer )
1683 ret = ERROR_OUTOFMEMORY;
1684 goto end;
1687 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
1689 ret = GetLastError();
1690 goto end;
1693 if (pcchVersionBuf)
1695 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
1696 (puLen > 0) )
1698 wsprintfW(tmp, szVersionFormat,
1699 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
1700 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
1701 if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
1703 if (lstrlenW(tmp) >= *pcchVersionBuf)
1704 ret = ERROR_MORE_DATA;
1706 *pcchVersionBuf = lstrlenW(tmp);
1708 else
1710 if (lpVersionBuf) *lpVersionBuf = 0;
1711 *pcchVersionBuf = 0;
1715 if (pcchLangBuf)
1717 if (VerQueryValueW(lpVer, szLangResource, (LPVOID*)&lang, &puLen) &&
1718 (puLen > 0))
1720 wsprintfW(tmp, szLangFormat, *lang);
1721 if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
1723 if (lstrlenW(tmp) >= *pcchLangBuf)
1724 ret = ERROR_MORE_DATA;
1726 *pcchLangBuf = lstrlenW(tmp);
1728 else
1730 if (lpLangBuf) *lpLangBuf = 0;
1731 *pcchLangBuf = 0;
1735 end:
1736 msi_free(lpVer);
1737 return ret;
1740 /***********************************************************************
1741 * MsiGetFeatureUsageW [MSI.@]
1743 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
1744 LPDWORD pdwUseCount, LPWORD pwDateUsed )
1746 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
1747 pdwUseCount, pwDateUsed);
1748 return ERROR_CALL_NOT_IMPLEMENTED;
1751 /***********************************************************************
1752 * MsiGetFeatureUsageA [MSI.@]
1754 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
1755 LPDWORD pdwUseCount, LPWORD pwDateUsed )
1757 LPWSTR prod = NULL, feat = NULL;
1758 UINT ret = ERROR_OUTOFMEMORY;
1760 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
1761 pdwUseCount, pwDateUsed);
1763 prod = strdupAtoW( szProduct );
1764 if (szProduct && !prod)
1765 goto end;
1767 feat = strdupAtoW( szFeature );
1768 if (szFeature && !feat)
1769 goto end;
1771 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
1773 end:
1774 msi_free( prod );
1775 msi_free( feat );
1777 return ret;
1780 /***********************************************************************
1781 * MsiUseFeatureExW [MSI.@]
1783 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
1784 DWORD dwInstallMode, DWORD dwReserved )
1786 INSTALLSTATE state;
1788 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
1789 dwInstallMode, dwReserved);
1791 state = MsiQueryFeatureStateW( szProduct, szFeature );
1793 if (dwReserved)
1794 return INSTALLSTATE_INVALIDARG;
1796 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
1798 FIXME("mark product %s feature %s as used\n",
1799 debugstr_w(szProduct), debugstr_w(szFeature) );
1802 return state;
1805 /***********************************************************************
1806 * MsiUseFeatureExA [MSI.@]
1808 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
1809 DWORD dwInstallMode, DWORD dwReserved )
1811 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
1812 LPWSTR prod = NULL, feat = NULL;
1814 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
1815 dwInstallMode, dwReserved);
1817 prod = strdupAtoW( szProduct );
1818 if (szProduct && !prod)
1819 goto end;
1821 feat = strdupAtoW( szFeature );
1822 if (szFeature && !feat)
1823 goto end;
1825 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
1827 end:
1828 msi_free( prod );
1829 msi_free( feat );
1831 return ret;
1834 /***********************************************************************
1835 * MsiUseFeatureW [MSI.@]
1837 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
1839 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
1842 /***********************************************************************
1843 * MsiUseFeatureA [MSI.@]
1845 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
1847 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
1850 /***********************************************************************
1851 * MSI_ProvideQualifiedComponentEx [internal]
1853 static UINT WINAPI MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
1854 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
1855 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
1856 LPDWORD pcchPathBuf)
1858 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
1859 feature[MAX_FEATURE_CHARS+1];
1860 LPWSTR info;
1861 HKEY hkey;
1862 DWORD sz;
1863 UINT rc;
1865 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
1866 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
1867 Unused1, Unused2, lpPathBuf, pcchPathBuf);
1869 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
1870 if (rc != ERROR_SUCCESS)
1871 return ERROR_INDEX_ABSENT;
1873 info = msi_reg_get_val_str( hkey, szQualifier );
1874 RegCloseKey(hkey);
1876 if (!info)
1877 return ERROR_INDEX_ABSENT;
1879 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
1881 if (!szProduct)
1882 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
1883 else
1884 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
1886 msi_free( info );
1888 if (rc != INSTALLSTATE_LOCAL)
1889 return ERROR_FILE_NOT_FOUND;
1891 return ERROR_SUCCESS;
1894 /***********************************************************************
1895 * MsiProvideQualifiedComponentExW [MSI.@]
1897 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
1898 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
1899 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
1900 LPDWORD pcchPathBuf)
1902 awstring path;
1904 path.unicode = TRUE;
1905 path.str.w = lpPathBuf;
1907 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
1908 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
1911 /***********************************************************************
1912 * MsiProvideQualifiedComponentExA [MSI.@]
1914 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
1915 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
1916 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
1917 LPDWORD pcchPathBuf)
1919 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
1920 UINT r = ERROR_OUTOFMEMORY;
1921 awstring path;
1923 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
1924 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
1925 Unused1, Unused2, lpPathBuf, pcchPathBuf);
1927 szwComponent = strdupAtoW( szComponent );
1928 if (szComponent && !szwComponent)
1929 goto end;
1931 szwQualifier = strdupAtoW( szQualifier );
1932 if (szQualifier && !szwQualifier)
1933 goto end;
1935 szwProduct = strdupAtoW( szProduct );
1936 if (szProduct && !szwProduct)
1937 goto end;
1939 path.unicode = FALSE;
1940 path.str.a = lpPathBuf;
1942 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
1943 dwInstallMode, szwProduct, Unused1,
1944 Unused2, &path, pcchPathBuf);
1945 end:
1946 msi_free(szwProduct);
1947 msi_free(szwComponent);
1948 msi_free(szwQualifier);
1950 return r;
1953 /***********************************************************************
1954 * MsiProvideQualifiedComponentW [MSI.@]
1956 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
1957 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
1958 LPDWORD pcchPathBuf)
1960 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
1961 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
1964 /***********************************************************************
1965 * MsiProvideQualifiedComponentA [MSI.@]
1967 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
1968 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
1969 LPDWORD pcchPathBuf)
1971 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
1972 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
1975 /***********************************************************************
1976 * MSI_GetUserInfo [internal]
1978 static USERINFOSTATE WINAPI MSI_GetUserInfo(LPCWSTR szProduct,
1979 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
1980 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
1981 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
1983 HKEY hkey;
1984 LPWSTR user, org, serial;
1985 UINT r;
1986 USERINFOSTATE state;
1988 TRACE("%s %p %p %p %p %p %p\n",debugstr_w(szProduct), lpUserNameBuf,
1989 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
1990 pcchSerialBuf);
1992 if (!szProduct)
1993 return USERINFOSTATE_INVALIDARG;
1995 r = MSIREG_OpenUninstallKey(szProduct, &hkey, FALSE);
1996 if (r != ERROR_SUCCESS)
1997 return USERINFOSTATE_UNKNOWN;
1999 user = msi_reg_get_val_str( hkey, INSTALLPROPERTY_REGOWNERW );
2000 org = msi_reg_get_val_str( hkey, INSTALLPROPERTY_REGCOMPANYW );
2001 serial = msi_reg_get_val_str( hkey, INSTALLPROPERTY_PRODUCTIDW );
2003 RegCloseKey(hkey);
2005 state = USERINFOSTATE_PRESENT;
2007 if (user)
2009 r = msi_strcpy_to_awstring( user, lpUserNameBuf, pcchUserNameBuf );
2010 if (r == ERROR_MORE_DATA)
2011 state = USERINFOSTATE_MOREDATA;
2013 else
2014 state = USERINFOSTATE_ABSENT;
2015 if (org)
2017 r = msi_strcpy_to_awstring( org, lpOrgNameBuf, pcchOrgNameBuf );
2018 if (r == ERROR_MORE_DATA && state == USERINFOSTATE_PRESENT)
2019 state = USERINFOSTATE_MOREDATA;
2021 /* msdn states: The user information is considered to be present even in the absence of a company name. */
2022 if (serial)
2024 r = msi_strcpy_to_awstring( serial, lpSerialBuf, pcchSerialBuf );
2025 if (r == ERROR_MORE_DATA && state == USERINFOSTATE_PRESENT)
2026 state = USERINFOSTATE_MOREDATA;
2028 else
2029 state = USERINFOSTATE_ABSENT;
2031 msi_free( user );
2032 msi_free( org );
2033 msi_free( serial );
2035 return state;
2038 /***********************************************************************
2039 * MsiGetUserInfoW [MSI.@]
2041 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
2042 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
2043 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
2044 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
2046 awstring user, org, serial;
2048 user.unicode = TRUE;
2049 user.str.w = lpUserNameBuf;
2050 org.unicode = TRUE;
2051 org.str.w = lpOrgNameBuf;
2052 serial.unicode = TRUE;
2053 serial.str.w = lpSerialBuf;
2055 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
2056 &org, pcchOrgNameBuf,
2057 &serial, pcchSerialBuf );
2060 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
2061 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
2062 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
2063 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
2065 awstring user, org, serial;
2066 LPWSTR prod;
2067 UINT r;
2069 prod = strdupAtoW( szProduct );
2070 if (szProduct && !prod)
2071 return ERROR_OUTOFMEMORY;
2073 user.unicode = FALSE;
2074 user.str.a = lpUserNameBuf;
2075 org.unicode = FALSE;
2076 org.str.a = lpOrgNameBuf;
2077 serial.unicode = FALSE;
2078 serial.str.a = lpSerialBuf;
2080 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
2081 &org, pcchOrgNameBuf,
2082 &serial, pcchSerialBuf );
2084 msi_free( prod );
2086 return r;
2089 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
2091 MSIHANDLE handle;
2092 UINT rc;
2093 MSIPACKAGE *package;
2094 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
2096 TRACE("(%s)\n",debugstr_w(szProduct));
2098 rc = MsiOpenProductW(szProduct,&handle);
2099 if (rc != ERROR_SUCCESS)
2100 return ERROR_INVALID_PARAMETER;
2102 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
2103 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
2104 msiobj_release( &package->hdr );
2106 MsiCloseHandle(handle);
2108 return rc;
2111 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
2113 MSIHANDLE handle;
2114 UINT rc;
2115 MSIPACKAGE *package;
2116 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
2118 TRACE("(%s)\n",debugstr_a(szProduct));
2120 rc = MsiOpenProductA(szProduct,&handle);
2121 if (rc != ERROR_SUCCESS)
2122 return ERROR_INVALID_PARAMETER;
2124 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
2125 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
2126 msiobj_release( &package->hdr );
2128 MsiCloseHandle(handle);
2130 return rc;
2133 /***********************************************************************
2134 * MsiConfigureFeatureA [MSI.@]
2136 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
2138 LPWSTR prod, feat = NULL;
2139 UINT r = ERROR_OUTOFMEMORY;
2141 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
2143 prod = strdupAtoW( szProduct );
2144 if (szProduct && !prod)
2145 goto end;
2147 feat = strdupAtoW( szFeature );
2148 if (szFeature && !feat)
2149 goto end;
2151 r = MsiConfigureFeatureW(prod, feat, eInstallState);
2153 end:
2154 msi_free(feat);
2155 msi_free(prod);
2157 return r;
2160 /***********************************************************************
2161 * MsiConfigureFeatureW [MSI.@]
2163 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
2165 static const WCHAR szCostInit[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
2166 MSIPACKAGE *package = NULL;
2167 UINT r;
2168 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
2169 DWORD sz;
2171 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
2173 if (!szProduct || !szFeature)
2174 return ERROR_INVALID_PARAMETER;
2176 switch (eInstallState)
2178 case INSTALLSTATE_DEFAULT:
2179 /* FIXME: how do we figure out the default location? */
2180 eInstallState = INSTALLSTATE_LOCAL;
2181 break;
2182 case INSTALLSTATE_LOCAL:
2183 case INSTALLSTATE_SOURCE:
2184 case INSTALLSTATE_ABSENT:
2185 case INSTALLSTATE_ADVERTISED:
2186 break;
2187 default:
2188 return ERROR_INVALID_PARAMETER;
2191 r = MSI_OpenProductW( szProduct, &package );
2192 if (r != ERROR_SUCCESS)
2193 return r;
2195 sz = sizeof(sourcepath);
2196 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2197 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
2199 sz = sizeof(filename);
2200 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2201 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
2203 lstrcatW( sourcepath, filename );
2205 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
2207 r = ACTION_PerformUIAction( package, szCostInit, -1 );
2208 if (r != ERROR_SUCCESS)
2209 goto end;
2211 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
2212 if (r != ERROR_SUCCESS)
2213 goto end;
2215 r = MSI_InstallPackage( package, sourcepath, NULL );
2217 end:
2218 msiobj_release( &package->hdr );
2220 return r;
2223 /***********************************************************************
2224 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
2226 * Notes: undocumented
2228 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
2230 WCHAR path[MAX_PATH];
2232 TRACE("%d\n", dwReserved);
2234 if (dwReserved)
2236 FIXME("dwReserved=%d\n", dwReserved);
2237 return ERROR_INVALID_PARAMETER;
2240 if (!GetWindowsDirectoryW(path, MAX_PATH))
2241 return ERROR_FUNCTION_FAILED;
2243 lstrcatW(path, installerW);
2245 if (!CreateDirectoryW(path, NULL))
2246 return ERROR_FUNCTION_FAILED;
2248 return ERROR_SUCCESS;
2251 /***********************************************************************
2252 * MsiGetShortcutTargetA [MSI.@]
2254 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
2255 LPSTR szProductCode, LPSTR szFeatureId,
2256 LPSTR szComponentCode )
2258 LPWSTR target;
2259 const int len = MAX_FEATURE_CHARS+1;
2260 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
2261 UINT r;
2263 target = strdupAtoW( szShortcutTarget );
2264 if (szShortcutTarget && !target )
2265 return ERROR_OUTOFMEMORY;
2266 product[0] = 0;
2267 feature[0] = 0;
2268 component[0] = 0;
2269 r = MsiGetShortcutTargetW( target, product, feature, component );
2270 msi_free( target );
2271 if (r == ERROR_SUCCESS)
2273 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
2274 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
2275 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
2277 return r;
2280 /***********************************************************************
2281 * MsiGetShortcutTargetW [MSI.@]
2283 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
2284 LPWSTR szProductCode, LPWSTR szFeatureId,
2285 LPWSTR szComponentCode )
2287 IShellLinkDataList *dl = NULL;
2288 IPersistFile *pf = NULL;
2289 LPEXP_DARWIN_LINK darwin = NULL;
2290 HRESULT r, init;
2292 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
2293 szProductCode, szFeatureId, szComponentCode );
2295 init = CoInitialize(NULL);
2297 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
2298 &IID_IPersistFile, (LPVOID*) &pf );
2299 if( SUCCEEDED( r ) )
2301 r = IPersistFile_Load( pf, szShortcutTarget,
2302 STGM_READ | STGM_SHARE_DENY_WRITE );
2303 if( SUCCEEDED( r ) )
2305 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
2306 (LPVOID*) &dl );
2307 if( SUCCEEDED( r ) )
2309 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
2310 (LPVOID) &darwin );
2311 IShellLinkDataList_Release( dl );
2314 IPersistFile_Release( pf );
2317 if (SUCCEEDED(init))
2318 CoUninitialize();
2320 TRACE("darwin = %p\n", darwin);
2322 if (darwin)
2324 DWORD sz;
2325 UINT ret;
2327 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
2328 szProductCode, szFeatureId, szComponentCode, &sz );
2329 LocalFree( darwin );
2330 return ret;
2333 return ERROR_FUNCTION_FAILED;
2336 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
2337 DWORD dwReinstallMode )
2339 MSIPACKAGE* package = NULL;
2340 UINT r;
2341 WCHAR sourcepath[MAX_PATH];
2342 WCHAR filename[MAX_PATH];
2343 static const WCHAR szLogVerbose[] = {
2344 ' ','L','O','G','V','E','R','B','O','S','E',0 };
2345 static const WCHAR szInstalled[] = { 'I','n','s','t','a','l','l','e','d',0};
2346 static const WCHAR szReinstall[] = {'R','E','I','N','S','T','A','L','L',0};
2347 static const WCHAR szReinstallMode[] = {'R','E','I','N','S','T','A','L','L','M','O','D','E',0};
2348 static const WCHAR szOne[] = {'1',0};
2349 WCHAR reinstallmode[11];
2350 LPWSTR ptr;
2351 DWORD sz;
2353 FIXME("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
2354 dwReinstallMode);
2356 ptr = reinstallmode;
2358 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
2359 *ptr++ = 'p';
2360 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
2361 *ptr++ = 'o';
2362 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
2363 *ptr++ = 'w';
2364 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
2365 *ptr++ = 'd';
2366 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
2367 *ptr++ = 'c';
2368 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
2369 *ptr++ = 'a';
2370 if (dwReinstallMode & REINSTALLMODE_USERDATA)
2371 *ptr++ = 'u';
2372 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
2373 *ptr++ = 'm';
2374 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
2375 *ptr++ = 's';
2376 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
2377 *ptr++ = 'v';
2378 *ptr = 0;
2380 sz = sizeof(sourcepath);
2381 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2382 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
2384 sz = sizeof(filename);
2385 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2386 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
2388 lstrcatW( sourcepath, filename );
2390 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
2391 r = MSI_OpenPackageW( sourcepath, &package );
2392 else
2393 r = MSI_OpenProductW( szProduct, &package );
2395 if (r != ERROR_SUCCESS)
2396 return r;
2398 MSI_SetPropertyW( package, szReinstallMode, reinstallmode );
2399 MSI_SetPropertyW( package, szInstalled, szOne );
2400 MSI_SetPropertyW( package, szLogVerbose, szOne );
2401 MSI_SetPropertyW( package, szReinstall, szFeature );
2403 r = MSI_InstallPackage( package, sourcepath, NULL );
2405 msiobj_release( &package->hdr );
2407 return r;
2410 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
2411 DWORD dwReinstallMode )
2413 LPWSTR wszProduct;
2414 LPWSTR wszFeature;
2415 UINT rc;
2417 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
2418 dwReinstallMode);
2420 wszProduct = strdupAtoW(szProduct);
2421 wszFeature = strdupAtoW(szFeature);
2423 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
2425 msi_free(wszProduct);
2426 msi_free(wszFeature);
2427 return rc;
2430 typedef struct
2432 unsigned int i[2];
2433 unsigned int buf[4];
2434 unsigned char in[64];
2435 unsigned char digest[16];
2436 } MD5_CTX;
2438 extern VOID WINAPI MD5Init( MD5_CTX *);
2439 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
2440 extern VOID WINAPI MD5Final( MD5_CTX *);
2442 /***********************************************************************
2443 * MsiGetFileHashW [MSI.@]
2445 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
2446 PMSIFILEHASHINFO pHash )
2448 HANDLE handle, mapping;
2449 void *p;
2450 DWORD length;
2451 UINT r = ERROR_FUNCTION_FAILED;
2453 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
2455 if (!szFilePath)
2456 return ERROR_INVALID_PARAMETER;
2458 if (!*szFilePath)
2459 return ERROR_PATH_NOT_FOUND;
2461 if (dwOptions)
2462 return ERROR_INVALID_PARAMETER;
2463 if (!pHash)
2464 return ERROR_INVALID_PARAMETER;
2465 if (pHash->dwFileHashInfoSize < sizeof *pHash)
2466 return ERROR_INVALID_PARAMETER;
2468 handle = CreateFileW( szFilePath, GENERIC_READ,
2469 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
2470 if (handle == INVALID_HANDLE_VALUE)
2471 return ERROR_FILE_NOT_FOUND;
2473 length = GetFileSize( handle, NULL );
2475 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
2476 if (mapping)
2478 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
2479 if (p)
2481 MD5_CTX ctx;
2483 MD5Init( &ctx );
2484 MD5Update( &ctx, p, length );
2485 MD5Final( &ctx );
2486 UnmapViewOfFile( p );
2488 memcpy( pHash->dwData, &ctx.digest, sizeof pHash->dwData );
2489 r = ERROR_SUCCESS;
2491 CloseHandle( mapping );
2493 CloseHandle( handle );
2495 return r;
2498 /***********************************************************************
2499 * MsiGetFileHashA [MSI.@]
2501 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
2502 PMSIFILEHASHINFO pHash )
2504 LPWSTR file;
2505 UINT r;
2507 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
2509 file = strdupAtoW( szFilePath );
2510 if (szFilePath && !file)
2511 return ERROR_OUTOFMEMORY;
2513 r = MsiGetFileHashW( file, dwOptions, pHash );
2514 msi_free( file );
2515 return r;
2518 /***********************************************************************
2519 * MsiAdvertiseScriptW [MSI.@]
2521 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
2522 PHKEY phRegData, BOOL fRemoveItems )
2524 FIXME("%s %08x %p %d\n",
2525 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
2526 return ERROR_CALL_NOT_IMPLEMENTED;
2529 /***********************************************************************
2530 * MsiAdvertiseScriptA [MSI.@]
2532 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
2533 PHKEY phRegData, BOOL fRemoveItems )
2535 FIXME("%s %08x %p %d\n",
2536 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
2537 return ERROR_CALL_NOT_IMPLEMENTED;
2540 /***********************************************************************
2541 * MsiIsProductElevatedW [MSI.@]
2543 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
2545 FIXME("%s %p - stub\n",
2546 debugstr_w( szProduct ), pfElevated );
2547 *pfElevated = TRUE;
2548 return ERROR_SUCCESS;
2551 /***********************************************************************
2552 * MsiIsProductElevatedA [MSI.@]
2554 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
2556 FIXME("%s %p - stub\n",
2557 debugstr_a( szProduct ), pfElevated );
2558 *pfElevated = TRUE;
2559 return ERROR_SUCCESS;