msi: Reimplement MsiGetUserInfo.
[wine/wine-kai.git] / dlls / msi / msi.c
blobf903d058fda12876feb57c7e84a813b17fc31031
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_USERUNMANAGED,
369 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath,
370 &sz);
372 sz = sizeof(filename);
373 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
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 = REG_NONE;
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_OpenCurrentUserInstallProps(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 if (pcchValueBuf)
727 save = *pcchValueBuf;
729 if (lstrlenW(val) < *pcchValueBuf)
730 r = msi_strcpy_to_awstring(val, szValue, pcchValueBuf);
731 else if (szValue->str.a || szValue->str.w)
732 r = ERROR_MORE_DATA;
734 if (!badconfig)
735 *pcchValueBuf = lstrlenW(val);
736 else if (r == ERROR_SUCCESS)
738 *pcchValueBuf = save;
739 r = ERROR_BAD_CONFIGURATION;
742 else if (badconfig)
743 r = ERROR_BAD_CONFIGURATION;
745 if (val != empty)
746 msi_free(val);
748 done:
749 RegCloseKey(prodkey);
750 RegCloseKey(userdata);
751 return r;
754 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
755 LPSTR szBuffer, LPDWORD pcchValueBuf)
757 LPWSTR szwProduct, szwAttribute = NULL;
758 UINT r = ERROR_OUTOFMEMORY;
759 awstring buffer;
761 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
762 szBuffer, pcchValueBuf);
764 szwProduct = strdupAtoW( szProduct );
765 if( szProduct && !szwProduct )
766 goto end;
768 szwAttribute = strdupAtoW( szAttribute );
769 if( szAttribute && !szwAttribute )
770 goto end;
772 buffer.unicode = FALSE;
773 buffer.str.a = szBuffer;
775 r = MSI_GetProductInfo( szwProduct, szwAttribute,
776 &buffer, pcchValueBuf );
778 end:
779 msi_free( szwProduct );
780 msi_free( szwAttribute );
782 return r;
785 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
786 LPWSTR szBuffer, LPDWORD pcchValueBuf)
788 awstring buffer;
790 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
791 szBuffer, pcchValueBuf);
793 buffer.unicode = TRUE;
794 buffer.str.w = szBuffer;
796 return MSI_GetProductInfo( szProduct, szAttribute,
797 &buffer, pcchValueBuf );
800 UINT WINAPI MsiGetProductInfoExA(LPCSTR szProductCode, LPCSTR szUserSid,
801 MSIINSTALLCONTEXT dwContext, LPCSTR szProperty,
802 LPSTR szValue, LPDWORD pcchValue)
804 LPWSTR product = NULL;
805 LPWSTR usersid = NULL;
806 LPWSTR property = NULL;
807 LPWSTR value = NULL;
808 DWORD len = 0;
809 UINT r;
811 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode),
812 debugstr_a(szUserSid), dwContext, debugstr_a(szProperty),
813 szValue, pcchValue);
815 if (szValue && !pcchValue)
816 return ERROR_INVALID_PARAMETER;
818 if (szProductCode) product = strdupAtoW(szProductCode);
819 if (szUserSid) usersid = strdupAtoW(szUserSid);
820 if (szProperty) property = strdupAtoW(szProperty);
822 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
823 NULL, &len);
824 if (r != ERROR_SUCCESS)
825 goto done;
827 value = msi_alloc(++len * sizeof(WCHAR));
828 if (!value)
830 r = ERROR_OUTOFMEMORY;
831 goto done;
834 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
835 value, &len);
836 if (r != ERROR_SUCCESS)
837 goto done;
839 if (!pcchValue)
840 goto done;
842 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
843 if (*pcchValue >= len)
844 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
845 else if (szValue)
847 r = ERROR_MORE_DATA;
848 if (*pcchValue > 0)
849 *szValue = '\0';
852 if (*pcchValue <= len || !szValue)
853 len = len * sizeof(WCHAR) - 1;
855 *pcchValue = len - 1;
857 done:
858 msi_free(product);
859 msi_free(usersid);
860 msi_free(property);
861 msi_free(value);
863 return r;
866 static UINT msi_copy_outval(LPWSTR val, LPWSTR out, LPDWORD size)
868 UINT r;
870 if (!val)
871 return ERROR_UNKNOWN_PROPERTY;
873 if (out)
875 if (lstrlenW(val) >= *size)
877 r = ERROR_MORE_DATA;
878 if (*size > 0)
879 *out = '\0';
881 else
882 lstrcpyW(out, val);
885 if (size)
886 *size = lstrlenW(val);
888 return ERROR_SUCCESS;
891 UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
892 MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty,
893 LPWSTR szValue, LPDWORD pcchValue)
895 WCHAR squished_pc[GUID_SIZE];
896 LPWSTR val = NULL;
897 LPCWSTR package = NULL;
898 HKEY props = NULL, prod;
899 HKEY classes = NULL, managed;
900 HKEY hkey = NULL;
901 DWORD type;
902 UINT r = ERROR_UNKNOWN_PRODUCT;
904 static const WCHAR one[] = {'1',0};
905 static const WCHAR five[] = {'5',0};
906 static const WCHAR empty[] = {0};
907 static const WCHAR displayname[] = {
908 'D','i','s','p','l','a','y','N','a','m','e',0};
909 static const WCHAR displayversion[] = {
910 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
911 static const WCHAR managed_local_package[] = {
912 'M','a','n','a','g','e','d','L','o','c','a','l',
913 'P','a','c','k','a','g','e',0};
915 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
916 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
917 szValue, pcchValue);
919 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
920 return ERROR_INVALID_PARAMETER;
922 if (szValue && !pcchValue)
923 return ERROR_INVALID_PARAMETER;
925 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
926 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
927 dwContext != MSIINSTALLCONTEXT_MACHINE)
928 return ERROR_INVALID_PARAMETER;
930 if (!szProperty || !*szProperty)
931 return ERROR_INVALID_PARAMETER;
933 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
934 return ERROR_INVALID_PARAMETER;
936 MSIREG_OpenLocalManagedProductKey(szProductCode, &managed, FALSE);
937 MSIREG_OpenUserProductsKey(szProductCode, &prod, FALSE);
939 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
941 package = INSTALLPROPERTY_LOCALPACKAGEW;
942 MSIREG_OpenCurrentUserInstallProps(szProductCode, &props, FALSE);
944 if (!props && !prod)
945 goto done;
947 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
949 package = managed_local_package;
950 MSIREG_OpenCurrentUserInstallProps(szProductCode, &props, FALSE);
952 if (!props && !managed)
953 goto done;
955 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
957 package = INSTALLPROPERTY_LOCALPACKAGEW;
958 MSIREG_OpenLocalSystemProductKey(szProductCode, &props, FALSE);
959 MSIREG_OpenLocalClassesProductKey(szProductCode, &classes, FALSE);
961 if (!props && !classes)
962 goto done;
965 if (!lstrcmpW(szProperty, INSTALLPROPERTY_HELPLINKW) ||
966 !lstrcmpW(szProperty, INSTALLPROPERTY_HELPTELEPHONEW) ||
967 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLDATEW) ||
968 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
969 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLLOCATIONW) ||
970 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLSOURCEW) ||
971 !lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW) ||
972 !lstrcmpW(szProperty, INSTALLPROPERTY_PUBLISHERW) ||
973 !lstrcmpW(szProperty, INSTALLPROPERTY_URLINFOABOUTW) ||
974 !lstrcmpW(szProperty, INSTALLPROPERTY_URLUPDATEINFOW) ||
975 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONMINORW) ||
976 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONMAJORW) ||
977 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONSTRINGW) ||
978 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTIDW) ||
979 !lstrcmpW(szProperty, INSTALLPROPERTY_REGCOMPANYW) ||
980 !lstrcmpW(szProperty, INSTALLPROPERTY_REGOWNERW) ||
981 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTANCETYPEW))
983 val = msi_reg_get_value(props, package, &type);
984 if (!val)
986 if (prod || classes)
987 r = ERROR_UNKNOWN_PROPERTY;
989 goto done;
992 msi_free(val);
994 if (!lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
995 szProperty = displayname;
996 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONSTRINGW))
997 szProperty = displayversion;
999 val = msi_reg_get_value(props, szProperty, &type);
1000 if (!val)
1001 val = strdupW(empty);
1003 r = msi_copy_outval(val, szValue, pcchValue);
1005 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_TRANSFORMSW) ||
1006 !lstrcmpW(szProperty, INSTALLPROPERTY_LANGUAGEW) ||
1007 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTNAMEW) ||
1008 !lstrcmpW(szProperty, INSTALLPROPERTY_PACKAGECODEW) ||
1009 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONW) ||
1010 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTICONW) ||
1011 !lstrcmpW(szProperty, INSTALLPROPERTY_PACKAGENAMEW) ||
1012 !lstrcmpW(szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
1014 if (!prod && !classes)
1015 goto done;
1017 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1018 hkey = prod;
1019 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1020 hkey = managed;
1021 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1022 hkey = classes;
1024 val = msi_reg_get_value(hkey, szProperty, &type);
1025 if (!val)
1026 val = strdupW(empty);
1028 r = msi_copy_outval(val, szValue, pcchValue);
1030 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTSTATEW))
1032 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1034 if (props)
1036 val = msi_reg_get_value(props, package, &type);
1037 if (!val)
1038 goto done;
1040 msi_free(val);
1041 val = strdupW(five);
1043 else
1044 val = strdupW(one);
1046 r = msi_copy_outval(val, szValue, pcchValue);
1047 goto done;
1049 else if (props && (val = msi_reg_get_value(props, package, &type)))
1051 msi_free(val);
1052 val = strdupW(five);
1053 r = msi_copy_outval(val, szValue, pcchValue);
1054 goto done;
1057 if (prod || managed)
1058 val = strdupW(one);
1059 else
1060 goto done;
1062 r = msi_copy_outval(val, szValue, pcchValue);
1064 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW))
1066 if (!prod && !classes)
1067 goto done;
1069 /* FIXME */
1070 val = strdupW(empty);
1071 r = msi_copy_outval(val, szValue, pcchValue);
1073 else
1074 r = ERROR_UNKNOWN_PROPERTY;
1076 done:
1077 RegCloseKey(props);
1078 RegCloseKey(prod);
1079 RegCloseKey(managed);
1080 RegCloseKey(classes);
1081 msi_free(val);
1083 return r;
1086 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1088 LPWSTR szwLogFile = NULL;
1089 UINT r;
1091 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1093 if( szLogFile )
1095 szwLogFile = strdupAtoW( szLogFile );
1096 if( !szwLogFile )
1097 return ERROR_OUTOFMEMORY;
1099 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1100 msi_free( szwLogFile );
1101 return r;
1104 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1106 HANDLE file = INVALID_HANDLE_VALUE;
1108 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1110 if (szLogFile)
1112 lstrcpyW(gszLogFile,szLogFile);
1113 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1114 DeleteFileW(szLogFile);
1115 file = CreateFileW(szLogFile, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
1116 FILE_ATTRIBUTE_NORMAL, NULL);
1117 if (file != INVALID_HANDLE_VALUE)
1118 CloseHandle(file);
1119 else
1120 ERR("Unable to enable log %s\n",debugstr_w(szLogFile));
1122 else
1123 gszLogFile[0] = '\0';
1125 return ERROR_SUCCESS;
1128 UINT WINAPI MsiEnumComponentCostsW(MSIHANDLE hInstall, LPCWSTR szComponent,
1129 DWORD dwIndex, INSTALLSTATE iState,
1130 LPWSTR lpDriveBuf, DWORD *pcchDriveBuf,
1131 int *piCost, int *pTempCost)
1133 FIXME("(%ld, %s, %d, %d, %p, %p, %p %p): stub!\n", hInstall,
1134 debugstr_w(szComponent), dwIndex, iState, lpDriveBuf,
1135 pcchDriveBuf, piCost, pTempCost);
1137 return ERROR_NO_MORE_ITEMS;
1140 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
1141 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1142 LPCSTR szComponent, INSTALLSTATE *pdwState)
1144 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
1145 UINT r;
1147 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
1148 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
1150 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
1151 return ERROR_OUTOFMEMORY;
1153 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
1154 return ERROR_OUTOFMEMORY;
1156 if (szComponent && !(comp = strdupAtoW(szComponent)))
1157 return ERROR_OUTOFMEMORY;
1159 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
1161 msi_free(prodcode);
1162 msi_free(usersid);
1163 msi_free(comp);
1165 return r;
1168 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1170 UINT r;
1171 HKEY hkey;
1173 if (context == MSIINSTALLCONTEXT_MACHINE)
1174 r = MSIREG_OpenLocalClassesProductKey(prodcode, &hkey, FALSE);
1175 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
1176 r = MSIREG_OpenUserProductsKey(prodcode, &hkey, FALSE);
1177 else
1178 r = MSIREG_OpenLocalManagedProductKey(prodcode, &hkey, FALSE);
1180 RegCloseKey(hkey);
1181 return (r == ERROR_SUCCESS);
1184 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1186 LPCWSTR package;
1187 HKEY hkey;
1188 DWORD sz;
1189 LONG res;
1190 UINT r;
1192 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1193 static const WCHAR managed_local_package[] = {
1194 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1197 if (context == MSIINSTALLCONTEXT_MACHINE)
1198 r = MSIREG_OpenLocalSystemProductKey(prodcode, &hkey, FALSE);
1199 else
1200 r = MSIREG_OpenCurrentUserInstallProps(prodcode, &hkey, FALSE);
1202 if (r != ERROR_SUCCESS)
1203 return FALSE;
1205 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1206 package = managed_local_package;
1207 else
1208 package = local_package;
1210 sz = 0;
1211 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
1212 RegCloseKey(hkey);
1214 return (res == ERROR_SUCCESS);
1217 static BOOL msi_comp_find_prodcode(LPWSTR squished_pc,
1218 MSIINSTALLCONTEXT context,
1219 LPCWSTR comp, DWORD *sz)
1221 HKEY hkey;
1222 LONG res;
1223 UINT r;
1225 if (context == MSIINSTALLCONTEXT_MACHINE)
1226 r = MSIREG_OpenLocalSystemComponentKey(comp, &hkey, FALSE);
1227 else
1228 r = MSIREG_OpenUserDataComponentKey(comp, &hkey, FALSE);
1230 if (r != ERROR_SUCCESS)
1231 return FALSE;
1233 *sz = 0;
1234 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, NULL, sz);
1235 if (res != ERROR_SUCCESS)
1236 return FALSE;
1238 RegCloseKey(hkey);
1239 return TRUE;
1242 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
1243 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1244 LPCWSTR szComponent, INSTALLSTATE *pdwState)
1246 WCHAR squished_pc[GUID_SIZE];
1247 BOOL found;
1248 DWORD sz;
1250 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
1251 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
1253 if (!pdwState)
1254 return ERROR_INVALID_PARAMETER;
1256 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
1257 return ERROR_INVALID_PARAMETER;
1259 if (!squash_guid(szProductCode, squished_pc))
1260 return ERROR_INVALID_PARAMETER;
1262 found = msi_comp_find_prod_key(szProductCode, dwContext);
1264 if (!msi_comp_find_package(szProductCode, dwContext))
1266 if (found)
1268 *pdwState = INSTALLSTATE_UNKNOWN;
1269 return ERROR_UNKNOWN_COMPONENT;
1272 return ERROR_UNKNOWN_PRODUCT;
1275 *pdwState = INSTALLSTATE_UNKNOWN;
1277 if (!msi_comp_find_prodcode(squished_pc, dwContext, szComponent, &sz))
1278 return ERROR_UNKNOWN_COMPONENT;
1280 if (sz == 0)
1281 *pdwState = INSTALLSTATE_NOTUSED;
1282 else
1283 *pdwState = INSTALLSTATE_LOCAL;
1285 return ERROR_SUCCESS;
1288 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
1290 LPWSTR szwProduct = NULL;
1291 INSTALLSTATE r;
1293 if( szProduct )
1295 szwProduct = strdupAtoW( szProduct );
1296 if( !szwProduct )
1297 return ERROR_OUTOFMEMORY;
1299 r = MsiQueryProductStateW( szwProduct );
1300 msi_free( szwProduct );
1301 return r;
1304 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
1306 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
1307 HKEY prodkey = 0, userdata = 0;
1308 BOOL user = TRUE;
1309 DWORD val;
1310 UINT r;
1312 static const WCHAR szWindowsInstaller[] = {
1313 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
1315 TRACE("%s\n", debugstr_w(szProduct));
1317 if (!szProduct || !*szProduct)
1318 return INSTALLSTATE_INVALIDARG;
1320 if (lstrlenW(szProduct) != GUID_SIZE - 1)
1321 return INSTALLSTATE_INVALIDARG;
1323 r = MSIREG_OpenLocalManagedProductKey(szProduct, &prodkey, FALSE);
1324 if (r != ERROR_SUCCESS)
1326 r = MSIREG_OpenUserProductsKey(szProduct, &prodkey, FALSE);
1327 if (r != ERROR_SUCCESS)
1329 r = MSIREG_OpenLocalClassesProductKey(szProduct, &prodkey, FALSE);
1330 if (r == ERROR_SUCCESS)
1331 user = FALSE;
1335 if (user)
1337 r = MSIREG_OpenCurrentUserInstallProps(szProduct, &userdata, FALSE);
1338 if (r != ERROR_SUCCESS)
1339 goto done;
1341 else
1343 r = MSIREG_OpenLocalSystemInstallProps(szProduct, &userdata, FALSE);
1344 if (r != ERROR_SUCCESS)
1345 goto done;
1348 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
1349 goto done;
1351 if (val)
1352 state = INSTALLSTATE_DEFAULT;
1353 else
1354 state = INSTALLSTATE_UNKNOWN;
1356 done:
1357 if (!prodkey)
1359 state = INSTALLSTATE_UNKNOWN;
1361 if (userdata)
1362 state = INSTALLSTATE_ABSENT;
1365 RegCloseKey(prodkey);
1366 RegCloseKey(userdata);
1367 return state;
1370 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
1372 INSTALLUILEVEL old = gUILevel;
1373 HWND oldwnd = gUIhwnd;
1375 TRACE("%08x %p\n", dwUILevel, phWnd);
1377 gUILevel = dwUILevel;
1378 if (phWnd)
1380 gUIhwnd = *phWnd;
1381 *phWnd = oldwnd;
1383 return old;
1386 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
1387 DWORD dwMessageFilter, LPVOID pvContext)
1389 INSTALLUI_HANDLERA prev = gUIHandlerA;
1391 TRACE("%p %x %p\n",puiHandler, dwMessageFilter,pvContext);
1392 gUIHandlerA = puiHandler;
1393 gUIFilter = dwMessageFilter;
1394 gUIContext = pvContext;
1396 return prev;
1399 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
1400 DWORD dwMessageFilter, LPVOID pvContext)
1402 INSTALLUI_HANDLERW prev = gUIHandlerW;
1404 TRACE("%p %x %p\n",puiHandler,dwMessageFilter,pvContext);
1405 gUIHandlerW = puiHandler;
1406 gUIFilter = dwMessageFilter;
1407 gUIContext = pvContext;
1409 return prev;
1412 /******************************************************************
1413 * MsiLoadStringW [MSI.@]
1415 * Loads a string from MSI's string resources.
1417 * PARAMS
1419 * handle [I] only -1 is handled currently
1420 * id [I] id of the string to be loaded
1421 * lpBuffer [O] buffer for the string to be written to
1422 * nBufferMax [I] maximum size of the buffer in characters
1423 * lang [I] the preferred language for the string
1425 * RETURNS
1427 * If successful, this function returns the language id of the string loaded
1428 * If the function fails, the function returns zero.
1430 * NOTES
1432 * The type of the first parameter is unknown. LoadString's prototype
1433 * suggests that it might be a module handle. I have made it an MSI handle
1434 * for starters, as -1 is an invalid MSI handle, but not an invalid module
1435 * handle. Maybe strings can be stored in an MSI database somehow.
1437 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
1438 int nBufferMax, LANGID lang )
1440 HRSRC hres;
1441 HGLOBAL hResData;
1442 LPWSTR p;
1443 DWORD i, len;
1445 TRACE("%ld %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
1447 if( handle != -1 )
1448 FIXME("don't know how to deal with handle = %08lx\n", handle);
1450 if( !lang )
1451 lang = GetUserDefaultLangID();
1453 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
1454 (LPWSTR)1, lang );
1455 if( !hres )
1456 return 0;
1457 hResData = LoadResource( msi_hInstance, hres );
1458 if( !hResData )
1459 return 0;
1460 p = LockResource( hResData );
1461 if( !p )
1462 return 0;
1464 for (i = 0; i < (id&0xf); i++)
1465 p += *p + 1;
1466 len = *p;
1468 if( nBufferMax <= len )
1469 return 0;
1471 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
1472 lpBuffer[ len ] = 0;
1474 TRACE("found -> %s\n", debugstr_w(lpBuffer));
1476 return lang;
1479 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
1480 int nBufferMax, LANGID lang )
1482 LPWSTR bufW;
1483 LANGID r;
1484 DWORD len;
1486 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
1487 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
1488 if( r )
1490 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
1491 if( len <= nBufferMax )
1492 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
1493 lpBuffer, nBufferMax, NULL, NULL );
1494 else
1495 r = 0;
1497 msi_free(bufW);
1498 return r;
1501 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
1502 LPDWORD pcchBuf)
1504 char szProduct[GUID_SIZE];
1506 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
1508 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
1509 return INSTALLSTATE_UNKNOWN;
1511 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
1514 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
1515 LPDWORD pcchBuf)
1517 WCHAR szProduct[GUID_SIZE];
1519 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
1521 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
1522 return INSTALLSTATE_UNKNOWN;
1524 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
1527 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
1528 WORD wLanguageId, DWORD f)
1530 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
1531 uType, wLanguageId, f);
1532 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
1535 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
1536 WORD wLanguageId, DWORD f)
1538 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
1539 uType, wLanguageId, f);
1540 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
1543 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
1544 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
1545 LPDWORD pcchPathBuf )
1547 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
1548 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
1549 pcchPathBuf);
1550 return ERROR_CALL_NOT_IMPLEMENTED;
1553 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
1554 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
1555 LPDWORD pcchPathBuf )
1557 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
1558 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
1559 pcchPathBuf);
1560 return ERROR_CALL_NOT_IMPLEMENTED;
1563 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
1564 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
1566 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
1567 return ERROR_CALL_NOT_IMPLEMENTED;
1570 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
1571 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
1573 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
1574 return ERROR_CALL_NOT_IMPLEMENTED;
1577 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath,
1578 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
1579 LPDWORD pcbHashData)
1581 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath), dwFlags,
1582 ppcCertContext, pbHashData, pcbHashData);
1583 return ERROR_CALL_NOT_IMPLEMENTED;
1586 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath,
1587 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
1588 LPDWORD pcbHashData)
1590 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath), dwFlags,
1591 ppcCertContext, pbHashData, pcbHashData);
1592 return ERROR_CALL_NOT_IMPLEMENTED;
1595 UINT WINAPI MsiGetProductPropertyA( MSIHANDLE hProduct, LPCSTR szProperty,
1596 LPSTR szValue, LPDWORD pccbValue )
1598 FIXME("%ld %s %p %p\n", hProduct, debugstr_a(szProperty), szValue, pccbValue);
1599 return ERROR_CALL_NOT_IMPLEMENTED;
1602 UINT WINAPI MsiGetProductPropertyW( MSIHANDLE hProduct, LPCWSTR szProperty,
1603 LPWSTR szValue, LPDWORD pccbValue )
1605 FIXME("%ld %s %p %p\n", hProduct, debugstr_w(szProperty), szValue, pccbValue);
1606 return ERROR_CALL_NOT_IMPLEMENTED;
1609 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
1611 UINT r;
1612 LPWSTR szPack = NULL;
1614 TRACE("%s\n", debugstr_a(szPackage) );
1616 if( szPackage )
1618 szPack = strdupAtoW( szPackage );
1619 if( !szPack )
1620 return ERROR_OUTOFMEMORY;
1623 r = MsiVerifyPackageW( szPack );
1625 msi_free( szPack );
1627 return r;
1630 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
1632 MSIHANDLE handle;
1633 UINT r;
1635 TRACE("%s\n", debugstr_w(szPackage) );
1637 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
1638 MsiCloseHandle( handle );
1640 return r;
1643 static INSTALLSTATE WINAPI MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
1644 awstring* lpPathBuf, LPDWORD pcchBuf)
1646 WCHAR squished_pc[GUID_SIZE];
1647 WCHAR squished_comp[GUID_SIZE];
1648 HKEY hkey;
1649 LPWSTR path = NULL;
1650 INSTALLSTATE state;
1651 DWORD version;
1653 static const WCHAR wininstaller[] = {
1654 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
1656 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
1657 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
1659 if (!szProduct || !szComponent)
1660 return INSTALLSTATE_INVALIDARG;
1662 if (lpPathBuf->str.w && !pcchBuf)
1663 return INSTALLSTATE_INVALIDARG;
1665 if (!squash_guid(szProduct, squished_pc) ||
1666 !squash_guid(szComponent, squished_comp))
1667 return INSTALLSTATE_INVALIDARG;
1669 state = INSTALLSTATE_UNKNOWN;
1671 if (MSIREG_OpenLocalSystemComponentKey(szComponent, &hkey, FALSE) == ERROR_SUCCESS ||
1672 MSIREG_OpenUserDataComponentKey(szComponent, &hkey, FALSE) == ERROR_SUCCESS)
1674 path = msi_reg_get_val_str(hkey, squished_pc);
1675 RegCloseKey(hkey);
1677 state = INSTALLSTATE_ABSENT;
1679 if ((MSIREG_OpenLocalSystemProductKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS ||
1680 MSIREG_OpenUserDataProductKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS) &&
1681 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
1682 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
1684 RegCloseKey(hkey);
1685 state = INSTALLSTATE_LOCAL;
1689 if (state != INSTALLSTATE_LOCAL &&
1690 (MSIREG_OpenUserProductsKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS ||
1691 MSIREG_OpenLocalClassesProductKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS))
1693 RegCloseKey(hkey);
1695 if (MSIREG_OpenLocalSystemComponentKey(szComponent, &hkey, FALSE) == ERROR_SUCCESS ||
1696 MSIREG_OpenUserDataComponentKey(szComponent, &hkey, FALSE) == ERROR_SUCCESS)
1698 msi_free(path);
1699 path = msi_reg_get_val_str(hkey, squished_pc);
1700 RegCloseKey(hkey);
1702 state = INSTALLSTATE_ABSENT;
1704 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
1705 state = INSTALLSTATE_LOCAL;
1709 if (!path)
1710 return INSTALLSTATE_UNKNOWN;
1712 if (state == INSTALLSTATE_LOCAL && !*path)
1713 state = INSTALLSTATE_NOTUSED;
1715 msi_strcpy_to_awstring(path, lpPathBuf, pcchBuf);
1716 msi_free(path);
1717 return state;
1720 /******************************************************************
1721 * MsiGetComponentPathW [MSI.@]
1723 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
1724 LPWSTR lpPathBuf, LPDWORD pcchBuf)
1726 awstring path;
1728 path.unicode = TRUE;
1729 path.str.w = lpPathBuf;
1731 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
1734 /******************************************************************
1735 * MsiGetComponentPathA [MSI.@]
1737 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
1738 LPSTR lpPathBuf, LPDWORD pcchBuf)
1740 LPWSTR szwProduct, szwComponent = NULL;
1741 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
1742 awstring path;
1744 szwProduct = strdupAtoW( szProduct );
1745 if( szProduct && !szwProduct)
1746 goto end;
1748 szwComponent = strdupAtoW( szComponent );
1749 if( szComponent && !szwComponent )
1750 goto end;
1752 path.unicode = FALSE;
1753 path.str.a = lpPathBuf;
1755 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
1757 end:
1758 msi_free( szwProduct );
1759 msi_free( szwComponent );
1761 return r;
1764 /******************************************************************
1765 * MsiQueryFeatureStateA [MSI.@]
1767 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
1769 LPWSTR szwProduct = NULL, szwFeature= NULL;
1770 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
1772 szwProduct = strdupAtoW( szProduct );
1773 if ( szProduct && !szwProduct )
1774 goto end;
1776 szwFeature = strdupAtoW( szFeature );
1777 if ( szFeature && !szwFeature )
1778 goto end;
1780 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
1782 end:
1783 msi_free( szwProduct);
1784 msi_free( szwFeature);
1786 return rc;
1789 /******************************************************************
1790 * MsiQueryFeatureStateW [MSI.@]
1792 * Checks the state of a feature
1794 * PARAMS
1795 * szProduct [I] Product's GUID string
1796 * szFeature [I] Feature's GUID string
1798 * RETURNS
1799 * INSTALLSTATE_LOCAL Feature is installed and usable
1800 * INSTALLSTATE_ABSENT Feature is absent
1801 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
1802 * INSTALLSTATE_UNKNOWN An error occurred
1803 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
1806 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
1808 WCHAR squishProduct[33], comp[GUID_SIZE];
1809 GUID guid;
1810 LPWSTR components, p, parent_feature, path;
1811 UINT rc;
1812 HKEY hkey;
1813 INSTALLSTATE r;
1814 BOOL missing = FALSE;
1815 BOOL machine = FALSE;
1817 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
1819 if (!szProduct || !szFeature)
1820 return INSTALLSTATE_INVALIDARG;
1822 if (!squash_guid( szProduct, squishProduct ))
1823 return INSTALLSTATE_INVALIDARG;
1825 if (MSIREG_OpenManagedFeaturesKey(szProduct, &hkey, FALSE) != ERROR_SUCCESS &&
1826 MSIREG_OpenUserFeaturesKey(szProduct, &hkey, FALSE) != ERROR_SUCCESS)
1828 rc = MSIREG_OpenLocalClassesFeaturesKey(szProduct, &hkey, FALSE);
1829 if (rc != ERROR_SUCCESS)
1830 return INSTALLSTATE_UNKNOWN;
1832 machine = TRUE;
1835 parent_feature = msi_reg_get_val_str( hkey, szFeature );
1836 RegCloseKey(hkey);
1838 if (!parent_feature)
1839 return INSTALLSTATE_UNKNOWN;
1841 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
1842 msi_free(parent_feature);
1843 if (r == INSTALLSTATE_ABSENT)
1844 return r;
1846 if (machine)
1847 rc = MSIREG_OpenLocalUserDataFeaturesKey(szProduct, &hkey, FALSE);
1848 else
1849 rc = MSIREG_OpenUserDataFeaturesKey(szProduct, &hkey, FALSE);
1851 if (rc != ERROR_SUCCESS)
1852 return INSTALLSTATE_ADVERTISED;
1854 components = msi_reg_get_val_str( hkey, szFeature );
1855 RegCloseKey(hkey);
1857 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
1859 if (!components)
1860 return INSTALLSTATE_ADVERTISED;
1862 for( p = components; *p && *p != 2 ; p += 20)
1864 if (!decode_base85_guid( p, &guid ))
1866 if (p != components)
1867 break;
1869 msi_free(components);
1870 return INSTALLSTATE_BADCONFIG;
1873 StringFromGUID2(&guid, comp, GUID_SIZE);
1875 if (machine)
1876 rc = MSIREG_OpenLocalUserDataComponentKey(comp, &hkey, FALSE);
1877 else
1878 rc = MSIREG_OpenUserDataComponentKey(comp, &hkey, FALSE);
1880 if (rc != ERROR_SUCCESS)
1882 msi_free(components);
1883 return INSTALLSTATE_ADVERTISED;
1886 path = msi_reg_get_val_str(hkey, squishProduct);
1887 if (!path)
1888 missing = TRUE;
1890 msi_free(path);
1893 TRACE("%s %s -> %d\n", debugstr_w(szProduct), debugstr_w(szFeature), r);
1894 msi_free(components);
1896 if (missing)
1897 return INSTALLSTATE_ADVERTISED;
1899 return INSTALLSTATE_LOCAL;
1902 /******************************************************************
1903 * MsiGetFileVersionA [MSI.@]
1905 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
1906 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
1908 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
1909 UINT ret = ERROR_OUTOFMEMORY;
1911 if ((lpVersionBuf && !pcchVersionBuf) ||
1912 (lpLangBuf && !pcchLangBuf))
1913 return ERROR_INVALID_PARAMETER;
1915 if( szFilePath )
1917 szwFilePath = strdupAtoW( szFilePath );
1918 if( !szwFilePath )
1919 goto end;
1922 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
1924 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
1925 if( !lpwVersionBuff )
1926 goto end;
1929 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
1931 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
1932 if( !lpwLangBuff )
1933 goto end;
1936 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
1937 lpwLangBuff, pcchLangBuf);
1939 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
1940 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
1941 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
1942 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
1943 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
1944 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
1946 end:
1947 msi_free(szwFilePath);
1948 msi_free(lpwVersionBuff);
1949 msi_free(lpwLangBuff);
1951 return ret;
1954 /******************************************************************
1955 * MsiGetFileVersionW [MSI.@]
1957 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
1958 LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
1960 static const WCHAR szVersionResource[] = {'\\',0};
1961 static const WCHAR szVersionFormat[] = {
1962 '%','d','.','%','d','.','%','d','.','%','d',0};
1963 static const WCHAR szLangResource[] = {
1964 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
1965 'T','r','a','n','s','l','a','t','i','o','n',0};
1966 static const WCHAR szLangFormat[] = {'%','d',0};
1967 UINT ret = 0;
1968 DWORD dwVerLen, gle;
1969 LPVOID lpVer = NULL;
1970 VS_FIXEDFILEINFO *ffi;
1971 USHORT *lang;
1972 UINT puLen;
1973 WCHAR tmp[32];
1975 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
1976 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
1977 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
1979 if ((lpVersionBuf && !pcchVersionBuf) ||
1980 (lpLangBuf && !pcchLangBuf))
1981 return ERROR_INVALID_PARAMETER;
1983 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
1984 if( !dwVerLen )
1986 gle = GetLastError();
1987 if (gle == ERROR_BAD_PATHNAME)
1988 return ERROR_FILE_NOT_FOUND;
1989 else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND)
1990 return ERROR_FILE_INVALID;
1992 return gle;
1995 lpVer = msi_alloc(dwVerLen);
1996 if( !lpVer )
1998 ret = ERROR_OUTOFMEMORY;
1999 goto end;
2002 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
2004 ret = GetLastError();
2005 goto end;
2008 if (pcchVersionBuf)
2010 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
2011 (puLen > 0) )
2013 wsprintfW(tmp, szVersionFormat,
2014 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
2015 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
2016 if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
2018 if (lstrlenW(tmp) >= *pcchVersionBuf)
2019 ret = ERROR_MORE_DATA;
2021 *pcchVersionBuf = lstrlenW(tmp);
2023 else
2025 if (lpVersionBuf) *lpVersionBuf = 0;
2026 *pcchVersionBuf = 0;
2030 if (pcchLangBuf)
2032 if (VerQueryValueW(lpVer, szLangResource, (LPVOID*)&lang, &puLen) &&
2033 (puLen > 0))
2035 wsprintfW(tmp, szLangFormat, *lang);
2036 if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
2038 if (lstrlenW(tmp) >= *pcchLangBuf)
2039 ret = ERROR_MORE_DATA;
2041 *pcchLangBuf = lstrlenW(tmp);
2043 else
2045 if (lpLangBuf) *lpLangBuf = 0;
2046 *pcchLangBuf = 0;
2050 end:
2051 msi_free(lpVer);
2052 return ret;
2055 /***********************************************************************
2056 * MsiGetFeatureUsageW [MSI.@]
2058 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
2059 LPDWORD pdwUseCount, LPWORD pwDateUsed )
2061 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
2062 pdwUseCount, pwDateUsed);
2063 return ERROR_CALL_NOT_IMPLEMENTED;
2066 /***********************************************************************
2067 * MsiGetFeatureUsageA [MSI.@]
2069 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
2070 LPDWORD pdwUseCount, LPWORD pwDateUsed )
2072 LPWSTR prod = NULL, feat = NULL;
2073 UINT ret = ERROR_OUTOFMEMORY;
2075 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
2076 pdwUseCount, pwDateUsed);
2078 prod = strdupAtoW( szProduct );
2079 if (szProduct && !prod)
2080 goto end;
2082 feat = strdupAtoW( szFeature );
2083 if (szFeature && !feat)
2084 goto end;
2086 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
2088 end:
2089 msi_free( prod );
2090 msi_free( feat );
2092 return ret;
2095 /***********************************************************************
2096 * MsiUseFeatureExW [MSI.@]
2098 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
2099 DWORD dwInstallMode, DWORD dwReserved )
2101 INSTALLSTATE state;
2103 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
2104 dwInstallMode, dwReserved);
2106 state = MsiQueryFeatureStateW( szProduct, szFeature );
2108 if (dwReserved)
2109 return INSTALLSTATE_INVALIDARG;
2111 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
2113 FIXME("mark product %s feature %s as used\n",
2114 debugstr_w(szProduct), debugstr_w(szFeature) );
2117 return state;
2120 /***********************************************************************
2121 * MsiUseFeatureExA [MSI.@]
2123 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
2124 DWORD dwInstallMode, DWORD dwReserved )
2126 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
2127 LPWSTR prod = NULL, feat = NULL;
2129 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
2130 dwInstallMode, dwReserved);
2132 prod = strdupAtoW( szProduct );
2133 if (szProduct && !prod)
2134 goto end;
2136 feat = strdupAtoW( szFeature );
2137 if (szFeature && !feat)
2138 goto end;
2140 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
2142 end:
2143 msi_free( prod );
2144 msi_free( feat );
2146 return ret;
2149 /***********************************************************************
2150 * MsiUseFeatureW [MSI.@]
2152 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
2154 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
2157 /***********************************************************************
2158 * MsiUseFeatureA [MSI.@]
2160 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
2162 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
2165 /***********************************************************************
2166 * MSI_ProvideQualifiedComponentEx [internal]
2168 static UINT WINAPI MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
2169 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
2170 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
2171 LPDWORD pcchPathBuf)
2173 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
2174 feature[MAX_FEATURE_CHARS+1];
2175 LPWSTR info;
2176 HKEY hkey;
2177 DWORD sz;
2178 UINT rc;
2180 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
2181 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
2182 Unused1, Unused2, lpPathBuf, pcchPathBuf);
2184 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
2185 if (rc != ERROR_SUCCESS)
2186 return ERROR_INDEX_ABSENT;
2188 info = msi_reg_get_val_str( hkey, szQualifier );
2189 RegCloseKey(hkey);
2191 if (!info)
2192 return ERROR_INDEX_ABSENT;
2194 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
2196 if (!szProduct)
2197 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
2198 else
2199 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
2201 msi_free( info );
2203 if (rc != INSTALLSTATE_LOCAL)
2204 return ERROR_FILE_NOT_FOUND;
2206 return ERROR_SUCCESS;
2209 /***********************************************************************
2210 * MsiProvideQualifiedComponentExW [MSI.@]
2212 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
2213 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
2214 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
2215 LPDWORD pcchPathBuf)
2217 awstring path;
2219 path.unicode = TRUE;
2220 path.str.w = lpPathBuf;
2222 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
2223 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
2226 /***********************************************************************
2227 * MsiProvideQualifiedComponentExA [MSI.@]
2229 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
2230 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
2231 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
2232 LPDWORD pcchPathBuf)
2234 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
2235 UINT r = ERROR_OUTOFMEMORY;
2236 awstring path;
2238 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
2239 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
2240 Unused1, Unused2, lpPathBuf, pcchPathBuf);
2242 szwComponent = strdupAtoW( szComponent );
2243 if (szComponent && !szwComponent)
2244 goto end;
2246 szwQualifier = strdupAtoW( szQualifier );
2247 if (szQualifier && !szwQualifier)
2248 goto end;
2250 szwProduct = strdupAtoW( szProduct );
2251 if (szProduct && !szwProduct)
2252 goto end;
2254 path.unicode = FALSE;
2255 path.str.a = lpPathBuf;
2257 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
2258 dwInstallMode, szwProduct, Unused1,
2259 Unused2, &path, pcchPathBuf);
2260 end:
2261 msi_free(szwProduct);
2262 msi_free(szwComponent);
2263 msi_free(szwQualifier);
2265 return r;
2268 /***********************************************************************
2269 * MsiProvideQualifiedComponentW [MSI.@]
2271 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
2272 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
2273 LPDWORD pcchPathBuf)
2275 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
2276 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
2279 /***********************************************************************
2280 * MsiProvideQualifiedComponentA [MSI.@]
2282 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
2283 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
2284 LPDWORD pcchPathBuf)
2286 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
2287 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
2290 /***********************************************************************
2291 * MSI_GetUserInfo [internal]
2293 static USERINFOSTATE WINAPI MSI_GetUserInfo(LPCWSTR szProduct,
2294 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
2295 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
2296 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
2298 WCHAR squished_pc[SQUISH_GUID_SIZE];
2299 LPWSTR user, org, serial;
2300 USERINFOSTATE state;
2301 HKEY hkey, props;
2302 LPCWSTR orgptr;
2303 UINT r;
2305 static const WCHAR szEmpty[] = {0};
2307 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct), lpUserNameBuf,
2308 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
2309 pcchSerialBuf);
2311 if (!szProduct || !squash_guid(szProduct, squished_pc))
2312 return USERINFOSTATE_INVALIDARG;
2314 if (MSIREG_OpenLocalManagedProductKey(szProduct, &hkey, FALSE) != ERROR_SUCCESS &&
2315 MSIREG_OpenUserProductsKey(szProduct, &hkey, FALSE) != ERROR_SUCCESS &&
2316 MSIREG_OpenLocalClassesProductKey(szProduct, &hkey, FALSE) != ERROR_SUCCESS)
2318 return USERINFOSTATE_UNKNOWN;
2321 if (MSIREG_OpenCurrentUserInstallProps(szProduct, &props, FALSE) != ERROR_SUCCESS &&
2322 MSIREG_OpenLocalSystemInstallProps(szProduct, &props, FALSE) != ERROR_SUCCESS)
2324 RegCloseKey(hkey);
2325 return USERINFOSTATE_ABSENT;
2328 user = msi_reg_get_val_str(props, INSTALLPROPERTY_REGOWNERW);
2329 org = msi_reg_get_val_str(props, INSTALLPROPERTY_REGCOMPANYW);
2330 serial = msi_reg_get_val_str(props, INSTALLPROPERTY_PRODUCTIDW);
2331 state = USERINFOSTATE_ABSENT;
2333 RegCloseKey(hkey);
2334 RegCloseKey(props);
2336 if (user && serial)
2337 state = USERINFOSTATE_PRESENT;
2339 if (pcchUserNameBuf)
2341 if (lpUserNameBuf && !user)
2343 (*pcchUserNameBuf)--;
2344 goto done;
2347 r = msi_strcpy_to_awstring(user, lpUserNameBuf, pcchUserNameBuf);
2348 if (r == ERROR_MORE_DATA)
2350 state = USERINFOSTATE_MOREDATA;
2351 goto done;
2355 if (pcchOrgNameBuf)
2357 orgptr = org;
2358 if (!orgptr) orgptr = szEmpty;
2360 r = msi_strcpy_to_awstring(orgptr, lpOrgNameBuf, pcchOrgNameBuf);
2361 if (r == ERROR_MORE_DATA)
2363 state = USERINFOSTATE_MOREDATA;
2364 goto done;
2368 if (pcchSerialBuf)
2370 if (!serial)
2372 (*pcchSerialBuf)--;
2373 goto done;
2376 r = msi_strcpy_to_awstring(serial, lpSerialBuf, pcchSerialBuf);
2377 if (r == ERROR_MORE_DATA)
2378 state = USERINFOSTATE_MOREDATA;
2381 done:
2382 msi_free(user);
2383 msi_free(org);
2384 msi_free(serial);
2386 return state;
2389 /***********************************************************************
2390 * MsiGetUserInfoW [MSI.@]
2392 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
2393 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
2394 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
2395 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
2397 awstring user, org, serial;
2399 if ((lpUserNameBuf && !pcchUserNameBuf) ||
2400 (lpOrgNameBuf && !pcchOrgNameBuf) ||
2401 (lpSerialBuf && !pcchSerialBuf))
2402 return USERINFOSTATE_INVALIDARG;
2404 user.unicode = TRUE;
2405 user.str.w = lpUserNameBuf;
2406 org.unicode = TRUE;
2407 org.str.w = lpOrgNameBuf;
2408 serial.unicode = TRUE;
2409 serial.str.w = lpSerialBuf;
2411 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
2412 &org, pcchOrgNameBuf,
2413 &serial, pcchSerialBuf );
2416 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
2417 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
2418 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
2419 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
2421 awstring user, org, serial;
2422 LPWSTR prod;
2423 UINT r;
2425 if ((lpUserNameBuf && !pcchUserNameBuf) ||
2426 (lpOrgNameBuf && !pcchOrgNameBuf) ||
2427 (lpSerialBuf && !pcchSerialBuf))
2428 return USERINFOSTATE_INVALIDARG;
2430 prod = strdupAtoW( szProduct );
2431 if (szProduct && !prod)
2432 return ERROR_OUTOFMEMORY;
2434 user.unicode = FALSE;
2435 user.str.a = lpUserNameBuf;
2436 org.unicode = FALSE;
2437 org.str.a = lpOrgNameBuf;
2438 serial.unicode = FALSE;
2439 serial.str.a = lpSerialBuf;
2441 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
2442 &org, pcchOrgNameBuf,
2443 &serial, pcchSerialBuf );
2445 msi_free( prod );
2447 return r;
2450 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
2452 MSIHANDLE handle;
2453 UINT rc;
2454 MSIPACKAGE *package;
2455 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
2457 TRACE("(%s)\n",debugstr_w(szProduct));
2459 rc = MsiOpenProductW(szProduct,&handle);
2460 if (rc != ERROR_SUCCESS)
2461 return ERROR_INVALID_PARAMETER;
2463 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
2464 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
2465 msiobj_release( &package->hdr );
2467 MsiCloseHandle(handle);
2469 return rc;
2472 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
2474 MSIHANDLE handle;
2475 UINT rc;
2476 MSIPACKAGE *package;
2477 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
2479 TRACE("(%s)\n",debugstr_a(szProduct));
2481 rc = MsiOpenProductA(szProduct,&handle);
2482 if (rc != ERROR_SUCCESS)
2483 return ERROR_INVALID_PARAMETER;
2485 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
2486 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
2487 msiobj_release( &package->hdr );
2489 MsiCloseHandle(handle);
2491 return rc;
2494 /***********************************************************************
2495 * MsiConfigureFeatureA [MSI.@]
2497 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
2499 LPWSTR prod, feat = NULL;
2500 UINT r = ERROR_OUTOFMEMORY;
2502 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
2504 prod = strdupAtoW( szProduct );
2505 if (szProduct && !prod)
2506 goto end;
2508 feat = strdupAtoW( szFeature );
2509 if (szFeature && !feat)
2510 goto end;
2512 r = MsiConfigureFeatureW(prod, feat, eInstallState);
2514 end:
2515 msi_free(feat);
2516 msi_free(prod);
2518 return r;
2521 /***********************************************************************
2522 * MsiConfigureFeatureW [MSI.@]
2524 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
2526 static const WCHAR szCostInit[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
2527 MSIPACKAGE *package = NULL;
2528 UINT r;
2529 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
2530 DWORD sz;
2532 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
2534 if (!szProduct || !szFeature)
2535 return ERROR_INVALID_PARAMETER;
2537 switch (eInstallState)
2539 case INSTALLSTATE_DEFAULT:
2540 /* FIXME: how do we figure out the default location? */
2541 eInstallState = INSTALLSTATE_LOCAL;
2542 break;
2543 case INSTALLSTATE_LOCAL:
2544 case INSTALLSTATE_SOURCE:
2545 case INSTALLSTATE_ABSENT:
2546 case INSTALLSTATE_ADVERTISED:
2547 break;
2548 default:
2549 return ERROR_INVALID_PARAMETER;
2552 r = MSI_OpenProductW( szProduct, &package );
2553 if (r != ERROR_SUCCESS)
2554 return r;
2556 sz = sizeof(sourcepath);
2557 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2558 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
2560 sz = sizeof(filename);
2561 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2562 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
2564 lstrcatW( sourcepath, filename );
2566 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
2568 r = ACTION_PerformUIAction( package, szCostInit, -1 );
2569 if (r != ERROR_SUCCESS)
2570 goto end;
2572 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
2573 if (r != ERROR_SUCCESS)
2574 goto end;
2576 r = MSI_InstallPackage( package, sourcepath, NULL );
2578 end:
2579 msiobj_release( &package->hdr );
2581 return r;
2584 /***********************************************************************
2585 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
2587 * Notes: undocumented
2589 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
2591 WCHAR path[MAX_PATH];
2593 TRACE("%d\n", dwReserved);
2595 if (dwReserved)
2597 FIXME("dwReserved=%d\n", dwReserved);
2598 return ERROR_INVALID_PARAMETER;
2601 if (!GetWindowsDirectoryW(path, MAX_PATH))
2602 return ERROR_FUNCTION_FAILED;
2604 lstrcatW(path, installerW);
2606 if (!CreateDirectoryW(path, NULL))
2607 return ERROR_FUNCTION_FAILED;
2609 return ERROR_SUCCESS;
2612 /***********************************************************************
2613 * MsiGetShortcutTargetA [MSI.@]
2615 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
2616 LPSTR szProductCode, LPSTR szFeatureId,
2617 LPSTR szComponentCode )
2619 LPWSTR target;
2620 const int len = MAX_FEATURE_CHARS+1;
2621 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
2622 UINT r;
2624 target = strdupAtoW( szShortcutTarget );
2625 if (szShortcutTarget && !target )
2626 return ERROR_OUTOFMEMORY;
2627 product[0] = 0;
2628 feature[0] = 0;
2629 component[0] = 0;
2630 r = MsiGetShortcutTargetW( target, product, feature, component );
2631 msi_free( target );
2632 if (r == ERROR_SUCCESS)
2634 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
2635 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
2636 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
2638 return r;
2641 /***********************************************************************
2642 * MsiGetShortcutTargetW [MSI.@]
2644 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
2645 LPWSTR szProductCode, LPWSTR szFeatureId,
2646 LPWSTR szComponentCode )
2648 IShellLinkDataList *dl = NULL;
2649 IPersistFile *pf = NULL;
2650 LPEXP_DARWIN_LINK darwin = NULL;
2651 HRESULT r, init;
2653 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
2654 szProductCode, szFeatureId, szComponentCode );
2656 init = CoInitialize(NULL);
2658 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
2659 &IID_IPersistFile, (LPVOID*) &pf );
2660 if( SUCCEEDED( r ) )
2662 r = IPersistFile_Load( pf, szShortcutTarget,
2663 STGM_READ | STGM_SHARE_DENY_WRITE );
2664 if( SUCCEEDED( r ) )
2666 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
2667 (LPVOID*) &dl );
2668 if( SUCCEEDED( r ) )
2670 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
2671 (LPVOID) &darwin );
2672 IShellLinkDataList_Release( dl );
2675 IPersistFile_Release( pf );
2678 if (SUCCEEDED(init))
2679 CoUninitialize();
2681 TRACE("darwin = %p\n", darwin);
2683 if (darwin)
2685 DWORD sz;
2686 UINT ret;
2688 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
2689 szProductCode, szFeatureId, szComponentCode, &sz );
2690 LocalFree( darwin );
2691 return ret;
2694 return ERROR_FUNCTION_FAILED;
2697 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
2698 DWORD dwReinstallMode )
2700 MSIPACKAGE* package = NULL;
2701 UINT r;
2702 WCHAR sourcepath[MAX_PATH];
2703 WCHAR filename[MAX_PATH];
2704 static const WCHAR szLogVerbose[] = {
2705 ' ','L','O','G','V','E','R','B','O','S','E',0 };
2706 static const WCHAR szInstalled[] = { 'I','n','s','t','a','l','l','e','d',0};
2707 static const WCHAR szReinstall[] = {'R','E','I','N','S','T','A','L','L',0};
2708 static const WCHAR szReinstallMode[] = {'R','E','I','N','S','T','A','L','L','M','O','D','E',0};
2709 static const WCHAR szOne[] = {'1',0};
2710 WCHAR reinstallmode[11];
2711 LPWSTR ptr;
2712 DWORD sz;
2714 FIXME("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
2715 dwReinstallMode);
2717 ptr = reinstallmode;
2719 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
2720 *ptr++ = 'p';
2721 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
2722 *ptr++ = 'o';
2723 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
2724 *ptr++ = 'w';
2725 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
2726 *ptr++ = 'd';
2727 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
2728 *ptr++ = 'c';
2729 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
2730 *ptr++ = 'a';
2731 if (dwReinstallMode & REINSTALLMODE_USERDATA)
2732 *ptr++ = 'u';
2733 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
2734 *ptr++ = 'm';
2735 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
2736 *ptr++ = 's';
2737 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
2738 *ptr++ = 'v';
2739 *ptr = 0;
2741 sz = sizeof(sourcepath);
2742 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2743 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
2745 sz = sizeof(filename);
2746 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2747 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
2749 lstrcatW( sourcepath, filename );
2751 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
2752 r = MSI_OpenPackageW( sourcepath, &package );
2753 else
2754 r = MSI_OpenProductW( szProduct, &package );
2756 if (r != ERROR_SUCCESS)
2757 return r;
2759 MSI_SetPropertyW( package, szReinstallMode, reinstallmode );
2760 MSI_SetPropertyW( package, szInstalled, szOne );
2761 MSI_SetPropertyW( package, szLogVerbose, szOne );
2762 MSI_SetPropertyW( package, szReinstall, szFeature );
2764 r = MSI_InstallPackage( package, sourcepath, NULL );
2766 msiobj_release( &package->hdr );
2768 return r;
2771 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
2772 DWORD dwReinstallMode )
2774 LPWSTR wszProduct;
2775 LPWSTR wszFeature;
2776 UINT rc;
2778 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
2779 dwReinstallMode);
2781 wszProduct = strdupAtoW(szProduct);
2782 wszFeature = strdupAtoW(szFeature);
2784 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
2786 msi_free(wszProduct);
2787 msi_free(wszFeature);
2788 return rc;
2791 typedef struct
2793 unsigned int i[2];
2794 unsigned int buf[4];
2795 unsigned char in[64];
2796 unsigned char digest[16];
2797 } MD5_CTX;
2799 extern VOID WINAPI MD5Init( MD5_CTX *);
2800 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
2801 extern VOID WINAPI MD5Final( MD5_CTX *);
2803 /***********************************************************************
2804 * MsiGetFileHashW [MSI.@]
2806 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
2807 PMSIFILEHASHINFO pHash )
2809 HANDLE handle, mapping;
2810 void *p;
2811 DWORD length;
2812 UINT r = ERROR_FUNCTION_FAILED;
2814 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
2816 if (!szFilePath)
2817 return ERROR_INVALID_PARAMETER;
2819 if (!*szFilePath)
2820 return ERROR_PATH_NOT_FOUND;
2822 if (dwOptions)
2823 return ERROR_INVALID_PARAMETER;
2824 if (!pHash)
2825 return ERROR_INVALID_PARAMETER;
2826 if (pHash->dwFileHashInfoSize < sizeof *pHash)
2827 return ERROR_INVALID_PARAMETER;
2829 handle = CreateFileW( szFilePath, GENERIC_READ,
2830 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
2831 if (handle == INVALID_HANDLE_VALUE)
2832 return ERROR_FILE_NOT_FOUND;
2834 length = GetFileSize( handle, NULL );
2836 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
2837 if (mapping)
2839 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
2840 if (p)
2842 MD5_CTX ctx;
2844 MD5Init( &ctx );
2845 MD5Update( &ctx, p, length );
2846 MD5Final( &ctx );
2847 UnmapViewOfFile( p );
2849 memcpy( pHash->dwData, &ctx.digest, sizeof pHash->dwData );
2850 r = ERROR_SUCCESS;
2852 CloseHandle( mapping );
2854 CloseHandle( handle );
2856 return r;
2859 /***********************************************************************
2860 * MsiGetFileHashA [MSI.@]
2862 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
2863 PMSIFILEHASHINFO pHash )
2865 LPWSTR file;
2866 UINT r;
2868 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
2870 file = strdupAtoW( szFilePath );
2871 if (szFilePath && !file)
2872 return ERROR_OUTOFMEMORY;
2874 r = MsiGetFileHashW( file, dwOptions, pHash );
2875 msi_free( file );
2876 return r;
2879 /***********************************************************************
2880 * MsiAdvertiseScriptW [MSI.@]
2882 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
2883 PHKEY phRegData, BOOL fRemoveItems )
2885 FIXME("%s %08x %p %d\n",
2886 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
2887 return ERROR_CALL_NOT_IMPLEMENTED;
2890 /***********************************************************************
2891 * MsiAdvertiseScriptA [MSI.@]
2893 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
2894 PHKEY phRegData, BOOL fRemoveItems )
2896 FIXME("%s %08x %p %d\n",
2897 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
2898 return ERROR_CALL_NOT_IMPLEMENTED;
2901 /***********************************************************************
2902 * MsiIsProductElevatedW [MSI.@]
2904 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
2906 FIXME("%s %p - stub\n",
2907 debugstr_w( szProduct ), pfElevated );
2908 *pfElevated = TRUE;
2909 return ERROR_SUCCESS;
2912 /***********************************************************************
2913 * MsiIsProductElevatedA [MSI.@]
2915 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
2917 FIXME("%s %p - stub\n",
2918 debugstr_a( szProduct ), pfElevated );
2919 *pfElevated = TRUE;
2920 return ERROR_SUCCESS;