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
24 #define NONAMELESSUNION
31 #include "wine/debug.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)
51 LPWSTR szwProd = NULL;
53 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
57 szwProd = strdupAtoW( szProduct );
59 return ERROR_OUTOFMEMORY;
62 r = MsiOpenProductW( szwProd, phProduct );
69 static UINT MSI_OpenProductW( LPCWSTR szProduct, MSIPACKAGE **ppackage )
73 HKEY hKeyProduct = NULL;
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;
85 /* find the size of the path */
87 r = RegQueryValueExW( hKeyProduct, INSTALLPROPERTY_LOCALPACKAGEW,
88 NULL, &type, NULL, &count );
89 if( r != ERROR_SUCCESS )
91 r = ERROR_UNKNOWN_PRODUCT;
95 /* now alloc and fetch the path of the database to open */
96 path = msi_alloc( count );
100 r = RegQueryValueExW( hKeyProduct, INSTALLPROPERTY_LOCALPACKAGEW,
101 NULL, &type, (LPBYTE) path, &count );
102 if( r != ERROR_SUCCESS )
104 r = ERROR_UNKNOWN_PRODUCT;
108 r = MSI_OpenPackageW( path, ppackage );
113 RegCloseKey( hKeyProduct );
118 UINT WINAPI MsiOpenProductW( LPCWSTR szProduct, MSIHANDLE *phProduct )
120 MSIPACKAGE *package = NULL;
123 r = MSI_OpenProductW( szProduct, &package );
124 if( r == ERROR_SUCCESS )
126 *phProduct = alloc_msihandle( &package->hdr );
128 r = ERROR_NOT_ENOUGH_MEMORY;
129 msiobj_release( &package->hdr );
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));
177 szwPath = strdupAtoW( szPackagePath );
184 szwCommand = strdupAtoW( szCommandLine );
189 r = MsiInstallProductW( szwPath, szwCommand );
193 msi_free( szwCommand );
198 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
200 MSIPACKAGE *package = NULL;
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 );
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)))
241 if (szInstallPackage && !(install_package = strdupAtoW(szInstallPackage)))
244 if (szCommandLine && !(command_line = strdupAtoW(szCommandLine)))
247 r = MsiApplyPatchW(patch_package, install_package, eInstallType, command_line);
250 msi_free(patch_package);
251 msi_free(install_package);
252 msi_free(command_line);
257 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
258 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
260 MSIHANDLE patch, info;
263 LPCWSTR cmd_ptr = szCommandLine;
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)
285 r = MsiGetSummaryInformationW(patch, NULL, 0, &info);
286 if (r != ERROR_SUCCESS)
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");
296 codes = msi_alloc(++size * sizeof(WCHAR));
299 r = ERROR_OUTOFMEMORY;
303 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, codes, &size);
304 if (r != ERROR_SUCCESS)
310 size = lstrlenW(cmd_ptr) + lstrlenW(patcheq) + lstrlenW(szPatchPackage) + 1;
311 cmd = msi_alloc(size * sizeof(WCHAR));
314 r = ERROR_OUTOFMEMORY;
318 lstrcpyW(cmd, cmd_ptr);
319 if (szCommandLine) lstrcatW(cmd, space);
320 lstrcatW(cmd, patcheq);
321 lstrcatW(cmd, szPatchPackage);
324 while ((end = strchrW(beg, '}')))
328 r = MsiConfigureProductExW(beg, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
329 if (r != ERROR_SUCCESS)
339 MsiCloseHandle(info);
340 MsiCloseHandle(patch);
345 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
346 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
348 MSIPACKAGE* package = NULL;
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};
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,
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)
389 sz = lstrlenW(szInstalled) + 1;
392 sz += lstrlenW(szCommandLine);
394 commandline = msi_alloc(sz * sizeof(WCHAR));
397 r = ERROR_OUTOFMEMORY;
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);
413 msiobj_release( &package->hdr );
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;
427 szwProduct = strdupAtoW( szProduct );
434 szwCommandLine = strdupAtoW( szCommandLine );
439 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
442 msi_free( szwProduct );
443 msi_free( szwCommandLine);
448 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
449 INSTALLSTATE eInstallState)
451 LPWSTR szwProduct = NULL;
454 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
458 szwProduct = strdupAtoW( szProduct );
460 return ERROR_OUTOFMEMORY;
463 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
464 msi_free( szwProduct );
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;
479 WCHAR szwBuffer[GUID_SIZE];
481 TRACE("%s %s\n",debugstr_a(szComponent), debugstr_a(szBuffer));
485 szwComponent = strdupAtoW( szComponent );
487 return ERROR_OUTOFMEMORY;
491 r = MsiGetProductCodeW( szwComponent, szwBuffer );
494 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
496 msi_free( szwComponent );
501 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
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)
539 while ((rc = RegEnumValueW(compkey, index, squished_prod, &sz,
540 NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
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);
556 rc = ERROR_INSTALL_FAILURE;
559 RegCloseKey(compkey);
560 unsquash_guid(squished_prod, szBuffer);
564 static UINT WINAPI MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
565 awstring *szValue, LPDWORD pcchValueBuf)
567 UINT r = ERROR_UNKNOWN_PROPERTY;
568 HKEY prodkey, userdata, source;
570 WCHAR squished_pc[GUID_SIZE];
571 WCHAR packagecode[GUID_SIZE];
572 BOOL classes = FALSE;
573 BOOL badconfig = FALSE;
577 static WCHAR empty[] = {0};
578 static const WCHAR sourcelist[] = {
579 'S','o','u','r','c','e','L','i','s','t',0};
580 static const WCHAR display_name[] = {
581 'D','i','s','p','l','a','y','N','a','m','e',0};
582 static const WCHAR display_version[] = {
583 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
584 static const WCHAR assignment[] = {
585 'A','s','s','i','g','n','m','e','n','t',0};
587 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
588 debugstr_w(szAttribute), szValue, pcchValueBuf);
590 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
591 return ERROR_INVALID_PARAMETER;
593 if (!squash_guid(szProduct, squished_pc))
594 return ERROR_INVALID_PARAMETER;
596 r = MSIREG_OpenLocalManagedProductKey(szProduct, &prodkey, FALSE);
597 if (r != ERROR_SUCCESS)
599 r = MSIREG_OpenUserProductsKey(szProduct, &prodkey, FALSE);
600 if (r != ERROR_SUCCESS)
602 r = MSIREG_OpenLocalClassesProductKey(szProduct, &prodkey, FALSE);
603 if (r == ERROR_SUCCESS)
609 MSIREG_OpenLocalSystemProductKey(szProduct, &userdata, FALSE);
611 MSIREG_OpenInstallPropertiesKey(szProduct, &userdata, FALSE);
613 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_HELPLINKW) ||
614 !lstrcmpW(szAttribute, INSTALLPROPERTY_HELPTELEPHONEW) ||
615 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLDATEW) ||
616 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
617 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW) ||
618 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLSOURCEW) ||
619 !lstrcmpW(szAttribute, INSTALLPROPERTY_LOCALPACKAGEW) ||
620 !lstrcmpW(szAttribute, INSTALLPROPERTY_PUBLISHERW) ||
621 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLINFOABOUTW) ||
622 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLUPDATEINFOW) ||
623 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMINORW) ||
624 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMAJORW) ||
625 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW) ||
626 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTIDW) ||
627 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGCOMPANYW) ||
628 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGOWNERW))
632 r = ERROR_UNKNOWN_PRODUCT;
637 return ERROR_UNKNOWN_PROPERTY;
639 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
640 szAttribute = display_name;
641 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW))
642 szAttribute = display_version;
644 val = msi_reg_get_val_str(userdata, szAttribute);
648 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTANCETYPEW) ||
649 !lstrcmpW(szAttribute, INSTALLPROPERTY_TRANSFORMSW) ||
650 !lstrcmpW(szAttribute, INSTALLPROPERTY_LANGUAGEW) ||
651 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTNAMEW) ||
652 !lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW) ||
653 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW) ||
654 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONW) ||
655 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTICONW) ||
656 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW) ||
657 !lstrcmpW(szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
661 r = ERROR_UNKNOWN_PRODUCT;
665 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW))
666 szAttribute = assignment;
668 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW))
670 res = RegOpenKeyW(prodkey, sourcelist, &source);
671 if (res == ERROR_SUCCESS)
672 val = msi_reg_get_val_str(source, szAttribute);
678 val = msi_reg_get_val_str(prodkey, szAttribute);
683 if (val != empty && !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW))
685 if (lstrlenW(val) != SQUISH_GUID_SIZE - 1)
689 unsquash_guid(val, packagecode);
691 val = strdupW(packagecode);
698 r = ERROR_UNKNOWN_PROPERTY;
702 save = *pcchValueBuf;
704 if (lstrlenW(val) < *pcchValueBuf)
705 r = msi_strcpy_to_awstring(val, szValue, pcchValueBuf);
706 else if (szValue->str.a || szValue->str.w)
710 *pcchValueBuf = lstrlenW(val);
711 else if (r == ERROR_SUCCESS)
713 *pcchValueBuf = save;
714 r = ERROR_BAD_CONFIGURATION;
721 RegCloseKey(prodkey);
722 RegCloseKey(userdata);
726 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
727 LPSTR szBuffer, LPDWORD pcchValueBuf)
729 LPWSTR szwProduct, szwAttribute = NULL;
730 UINT r = ERROR_OUTOFMEMORY;
733 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
734 szBuffer, pcchValueBuf);
736 szwProduct = strdupAtoW( szProduct );
737 if( szProduct && !szwProduct )
740 szwAttribute = strdupAtoW( szAttribute );
741 if( szAttribute && !szwAttribute )
744 buffer.unicode = FALSE;
745 buffer.str.a = szBuffer;
747 r = MSI_GetProductInfo( szwProduct, szwAttribute,
748 &buffer, pcchValueBuf );
751 msi_free( szwProduct );
752 msi_free( szwAttribute );
757 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
758 LPWSTR szBuffer, LPDWORD pcchValueBuf)
762 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
763 szBuffer, pcchValueBuf);
765 buffer.unicode = TRUE;
766 buffer.str.w = szBuffer;
768 return MSI_GetProductInfo( szProduct, szAttribute,
769 &buffer, pcchValueBuf );
772 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
774 LPWSTR szwLogFile = NULL;
777 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
781 szwLogFile = strdupAtoW( szLogFile );
783 return ERROR_OUTOFMEMORY;
785 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
786 msi_free( szwLogFile );
790 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
792 HANDLE file = INVALID_HANDLE_VALUE;
794 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
798 lstrcpyW(gszLogFile,szLogFile);
799 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
800 DeleteFileW(szLogFile);
801 file = CreateFileW(szLogFile, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
802 FILE_ATTRIBUTE_NORMAL, NULL);
803 if (file != INVALID_HANDLE_VALUE)
806 ERR("Unable to enable log %s\n",debugstr_w(szLogFile));
809 gszLogFile[0] = '\0';
811 return ERROR_SUCCESS;
814 UINT WINAPI MsiEnumComponentCostsW(MSIHANDLE hInstall, LPCWSTR szComponent,
815 DWORD dwIndex, INSTALLSTATE iState,
816 LPWSTR lpDriveBuf, DWORD *pcchDriveBuf,
817 int *piCost, int *pTempCost)
819 FIXME("(%ld, %s, %d, %d, %p, %p, %p %p): stub!\n", hInstall,
820 debugstr_w(szComponent), dwIndex, iState, lpDriveBuf,
821 pcchDriveBuf, piCost, pTempCost);
823 return ERROR_NO_MORE_ITEMS;
826 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
827 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
828 LPCSTR szComponent, INSTALLSTATE *pdwState)
830 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
833 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
834 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
836 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
837 return ERROR_OUTOFMEMORY;
839 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
840 return ERROR_OUTOFMEMORY;
842 if (szComponent && !(comp = strdupAtoW(szComponent)))
843 return ERROR_OUTOFMEMORY;
845 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
854 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
859 if (context == MSIINSTALLCONTEXT_MACHINE)
860 r = MSIREG_OpenLocalClassesProductKey(prodcode, &hkey, FALSE);
861 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
862 r = MSIREG_OpenUserProductsKey(prodcode, &hkey, FALSE);
864 r = MSIREG_OpenLocalManagedProductKey(prodcode, &hkey, FALSE);
867 return (r == ERROR_SUCCESS);
870 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
878 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
879 static const WCHAR managed_local_package[] = {
880 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
883 if (context == MSIINSTALLCONTEXT_MACHINE)
884 r = MSIREG_OpenLocalSystemProductKey(prodcode, &hkey, FALSE);
886 r = MSIREG_OpenInstallPropertiesKey(prodcode, &hkey, FALSE);
888 if (r != ERROR_SUCCESS)
891 if (context == MSIINSTALLCONTEXT_USERMANAGED)
892 package = managed_local_package;
894 package = local_package;
897 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
900 return (res == ERROR_SUCCESS);
903 static BOOL msi_comp_find_prodcode(LPCWSTR prodcode, LPWSTR squished_pc,
904 MSIINSTALLCONTEXT context,
905 LPCWSTR comp, DWORD *sz)
911 if (context == MSIINSTALLCONTEXT_MACHINE)
912 r = MSIREG_OpenLocalSystemComponentKey(comp, &hkey, FALSE);
914 r = MSIREG_OpenUserDataComponentKey(comp, &hkey, FALSE);
916 if (r != ERROR_SUCCESS)
920 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, NULL, sz);
921 if (res != ERROR_SUCCESS)
928 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
929 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
930 LPCWSTR szComponent, INSTALLSTATE *pdwState)
932 WCHAR squished_pc[GUID_SIZE];
936 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
937 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
940 return ERROR_INVALID_PARAMETER;
942 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
943 return ERROR_INVALID_PARAMETER;
945 if (!squash_guid(szProductCode, squished_pc))
946 return ERROR_INVALID_PARAMETER;
948 found = msi_comp_find_prod_key(szProductCode, dwContext);
950 if (!msi_comp_find_package(szProductCode, dwContext))
954 *pdwState = INSTALLSTATE_UNKNOWN;
955 return ERROR_UNKNOWN_COMPONENT;
958 return ERROR_UNKNOWN_PRODUCT;
961 *pdwState = INSTALLSTATE_UNKNOWN;
963 if (!msi_comp_find_prodcode(szProductCode, squished_pc, dwContext, szComponent, &sz))
964 return ERROR_UNKNOWN_COMPONENT;
967 *pdwState = INSTALLSTATE_NOTUSED;
969 *pdwState = INSTALLSTATE_LOCAL;
971 return ERROR_SUCCESS;
974 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
976 LPWSTR szwProduct = NULL;
981 szwProduct = strdupAtoW( szProduct );
983 return ERROR_OUTOFMEMORY;
985 r = MsiQueryProductStateW( szwProduct );
986 msi_free( szwProduct );
990 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
993 INSTALLSTATE state = INSTALLSTATE_UNKNOWN;
994 HKEY hkey = 0, props = 0;
996 BOOL userkey_exists = FALSE;
998 static const int GUID_LEN = 38;
999 static const WCHAR szInstallProperties[] = {
1000 'I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0
1002 static const WCHAR szWindowsInstaller[] = {
1003 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0
1006 TRACE("%s\n", debugstr_w(szProduct));
1008 if (!szProduct || !*szProduct || lstrlenW(szProduct) != GUID_LEN)
1009 return INSTALLSTATE_INVALIDARG;
1011 rc = MSIREG_OpenUserProductsKey(szProduct,&hkey,FALSE);
1012 if (rc == ERROR_SUCCESS)
1014 userkey_exists = TRUE;
1015 state = INSTALLSTATE_ADVERTISED;
1019 rc = MSIREG_OpenUserDataProductKey(szProduct,&hkey,FALSE);
1020 if (rc != ERROR_SUCCESS)
1023 rc = RegOpenKeyW(hkey, szInstallProperties, &props);
1024 if (rc != ERROR_SUCCESS)
1028 rc = RegQueryValueExW(props,szWindowsInstaller,NULL,NULL,(LPVOID)&state, &sz);
1029 if (rc != ERROR_SUCCESS)
1033 state = INSTALLSTATE_DEFAULT;
1035 state = INSTALLSTATE_UNKNOWN;
1037 if (state == INSTALLSTATE_DEFAULT && !userkey_exists)
1038 state = INSTALLSTATE_ABSENT;
1046 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
1048 INSTALLUILEVEL old = gUILevel;
1049 HWND oldwnd = gUIhwnd;
1051 TRACE("%08x %p\n", dwUILevel, phWnd);
1053 gUILevel = dwUILevel;
1062 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
1063 DWORD dwMessageFilter, LPVOID pvContext)
1065 INSTALLUI_HANDLERA prev = gUIHandlerA;
1067 TRACE("%p %x %p\n",puiHandler, dwMessageFilter,pvContext);
1068 gUIHandlerA = puiHandler;
1069 gUIFilter = dwMessageFilter;
1070 gUIContext = pvContext;
1075 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
1076 DWORD dwMessageFilter, LPVOID pvContext)
1078 INSTALLUI_HANDLERW prev = gUIHandlerW;
1080 TRACE("%p %x %p\n",puiHandler,dwMessageFilter,pvContext);
1081 gUIHandlerW = puiHandler;
1082 gUIFilter = dwMessageFilter;
1083 gUIContext = pvContext;
1088 /******************************************************************
1089 * MsiLoadStringW [MSI.@]
1091 * Loads a string from MSI's string resources.
1095 * handle [I] only -1 is handled currently
1096 * id [I] id of the string to be loaded
1097 * lpBuffer [O] buffer for the string to be written to
1098 * nBufferMax [I] maximum size of the buffer in characters
1099 * lang [I] the preferred language for the string
1103 * If successful, this function returns the language id of the string loaded
1104 * If the function fails, the function returns zero.
1108 * The type of the first parameter is unknown. LoadString's prototype
1109 * suggests that it might be a module handle. I have made it an MSI handle
1110 * for starters, as -1 is an invalid MSI handle, but not an invalid module
1111 * handle. Maybe strings can be stored in an MSI database somehow.
1113 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
1114 int nBufferMax, LANGID lang )
1121 TRACE("%ld %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
1124 FIXME("don't know how to deal with handle = %08lx\n", handle);
1127 lang = GetUserDefaultLangID();
1129 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
1133 hResData = LoadResource( msi_hInstance, hres );
1136 p = LockResource( hResData );
1140 for (i = 0; i < (id&0xf); i++)
1144 if( nBufferMax <= len )
1147 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
1148 lpBuffer[ len ] = 0;
1150 TRACE("found -> %s\n", debugstr_w(lpBuffer));
1155 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
1156 int nBufferMax, LANGID lang )
1162 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
1163 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
1166 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
1167 if( len <= nBufferMax )
1168 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
1169 lpBuffer, nBufferMax, NULL, NULL );
1177 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
1180 char szProduct[GUID_SIZE];
1182 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
1184 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
1185 return INSTALLSTATE_UNKNOWN;
1187 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
1190 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
1193 WCHAR szProduct[GUID_SIZE];
1195 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
1197 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
1198 return INSTALLSTATE_UNKNOWN;
1200 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
1203 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
1204 WORD wLanguageId, DWORD f)
1206 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
1207 uType, wLanguageId, f);
1208 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
1211 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
1212 WORD wLanguageId, DWORD f)
1214 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
1215 uType, wLanguageId, f);
1216 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
1219 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
1220 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
1221 LPDWORD pcchPathBuf )
1223 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
1224 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
1226 return ERROR_CALL_NOT_IMPLEMENTED;
1229 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
1230 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
1231 LPDWORD pcchPathBuf )
1233 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
1234 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
1236 return ERROR_CALL_NOT_IMPLEMENTED;
1239 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
1240 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
1242 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
1243 return ERROR_CALL_NOT_IMPLEMENTED;
1246 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
1247 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
1249 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
1250 return ERROR_CALL_NOT_IMPLEMENTED;
1253 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath,
1254 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
1255 LPDWORD pcbHashData)
1257 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath), dwFlags,
1258 ppcCertContext, pbHashData, pcbHashData);
1259 return ERROR_CALL_NOT_IMPLEMENTED;
1262 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath,
1263 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
1264 LPDWORD pcbHashData)
1266 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath), dwFlags,
1267 ppcCertContext, pbHashData, pcbHashData);
1268 return ERROR_CALL_NOT_IMPLEMENTED;
1271 UINT WINAPI MsiGetProductPropertyA( MSIHANDLE hProduct, LPCSTR szProperty,
1272 LPSTR szValue, LPDWORD pccbValue )
1274 FIXME("%ld %s %p %p\n", hProduct, debugstr_a(szProperty), szValue, pccbValue);
1275 return ERROR_CALL_NOT_IMPLEMENTED;
1278 UINT WINAPI MsiGetProductPropertyW( MSIHANDLE hProduct, LPCWSTR szProperty,
1279 LPWSTR szValue, LPDWORD pccbValue )
1281 FIXME("%ld %s %p %p\n", hProduct, debugstr_w(szProperty), szValue, pccbValue);
1282 return ERROR_CALL_NOT_IMPLEMENTED;
1285 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
1288 LPWSTR szPack = NULL;
1290 TRACE("%s\n", debugstr_a(szPackage) );
1294 szPack = strdupAtoW( szPackage );
1296 return ERROR_OUTOFMEMORY;
1299 r = MsiVerifyPackageW( szPack );
1306 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
1311 TRACE("%s\n", debugstr_w(szPackage) );
1313 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
1314 MsiCloseHandle( handle );
1319 static INSTALLSTATE WINAPI MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
1320 awstring* lpPathBuf, LPDWORD pcchBuf)
1322 WCHAR squished_pc[GUID_SIZE];
1323 WCHAR squished_comp[GUID_SIZE];
1329 static const WCHAR wininstaller[] = {
1330 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
1332 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
1333 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
1335 if (!szProduct || !szComponent)
1336 return INSTALLSTATE_INVALIDARG;
1338 if (lpPathBuf->str.w && !pcchBuf)
1339 return INSTALLSTATE_INVALIDARG;
1341 if (!squash_guid(szProduct, squished_pc) ||
1342 !squash_guid(szComponent, squished_comp))
1343 return INSTALLSTATE_INVALIDARG;
1345 state = INSTALLSTATE_UNKNOWN;
1347 if (MSIREG_OpenLocalSystemComponentKey(szComponent, &hkey, FALSE) == ERROR_SUCCESS ||
1348 MSIREG_OpenUserDataComponentKey(szComponent, &hkey, FALSE) == ERROR_SUCCESS)
1350 path = msi_reg_get_val_str(hkey, squished_pc);
1353 state = INSTALLSTATE_ABSENT;
1355 if ((MSIREG_OpenLocalSystemProductKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS ||
1356 MSIREG_OpenUserDataProductKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS) &&
1357 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
1358 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
1361 state = INSTALLSTATE_LOCAL;
1365 if (state != INSTALLSTATE_LOCAL &&
1366 (MSIREG_OpenUserProductsKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS ||
1367 MSIREG_OpenLocalClassesProductKey(szProduct, &hkey, FALSE) == ERROR_SUCCESS))
1371 if (MSIREG_OpenLocalSystemComponentKey(szComponent, &hkey, FALSE) == ERROR_SUCCESS ||
1372 MSIREG_OpenUserDataComponentKey(szComponent, &hkey, FALSE) == ERROR_SUCCESS)
1375 path = msi_reg_get_val_str(hkey, squished_pc);
1378 state = INSTALLSTATE_ABSENT;
1380 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
1381 state = INSTALLSTATE_LOCAL;
1386 return INSTALLSTATE_UNKNOWN;
1388 if (state == INSTALLSTATE_LOCAL && !*path)
1389 state = INSTALLSTATE_NOTUSED;
1391 msi_strcpy_to_awstring(path, lpPathBuf, pcchBuf);
1396 /******************************************************************
1397 * MsiGetComponentPathW [MSI.@]
1399 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
1400 LPWSTR lpPathBuf, LPDWORD pcchBuf)
1404 path.unicode = TRUE;
1405 path.str.w = lpPathBuf;
1407 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
1410 /******************************************************************
1411 * MsiGetComponentPathA [MSI.@]
1413 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
1414 LPSTR lpPathBuf, LPDWORD pcchBuf)
1416 LPWSTR szwProduct, szwComponent = NULL;
1417 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
1420 szwProduct = strdupAtoW( szProduct );
1421 if( szProduct && !szwProduct)
1424 szwComponent = strdupAtoW( szComponent );
1425 if( szComponent && !szwComponent )
1428 path.unicode = FALSE;
1429 path.str.a = lpPathBuf;
1431 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
1434 msi_free( szwProduct );
1435 msi_free( szwComponent );
1440 /******************************************************************
1441 * MsiQueryFeatureStateA [MSI.@]
1443 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
1445 LPWSTR szwProduct = NULL, szwFeature= NULL;
1446 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
1448 szwProduct = strdupAtoW( szProduct );
1449 if ( szProduct && !szwProduct )
1452 szwFeature = strdupAtoW( szFeature );
1453 if ( szFeature && !szwFeature )
1456 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
1459 msi_free( szwProduct);
1460 msi_free( szwFeature);
1465 /******************************************************************
1466 * MsiQueryFeatureStateW [MSI.@]
1468 * Checks the state of a feature
1471 * szProduct [I] Product's GUID string
1472 * szFeature [I] Feature's GUID string
1475 * INSTALLSTATE_LOCAL Feature is installed and useable
1476 * INSTALLSTATE_ABSENT Feature is absent
1477 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
1478 * INSTALLSTATE_UNKNOWN An error occurred
1479 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
1482 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
1484 WCHAR squishProduct[33], comp[GUID_SIZE];
1486 LPWSTR components, p, parent_feature, path;
1490 BOOL missing = FALSE;
1492 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
1494 if (!szProduct || !szFeature)
1495 return INSTALLSTATE_INVALIDARG;
1497 if (!squash_guid( szProduct, squishProduct ))
1498 return INSTALLSTATE_INVALIDARG;
1500 /* check that it's installed at all */
1501 rc = MSIREG_OpenUserFeaturesKey(szProduct, &hkey, FALSE);
1502 if (rc != ERROR_SUCCESS)
1503 return INSTALLSTATE_UNKNOWN;
1505 parent_feature = msi_reg_get_val_str( hkey, szFeature );
1508 if (!parent_feature)
1509 return INSTALLSTATE_UNKNOWN;
1511 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
1512 msi_free(parent_feature);
1513 if (r == INSTALLSTATE_ABSENT)
1516 /* now check if it's complete or advertised */
1517 rc = MSIREG_OpenUserDataFeaturesKey(szProduct, &hkey, FALSE);
1518 if (rc != ERROR_SUCCESS)
1519 return INSTALLSTATE_ADVERTISED;
1521 components = msi_reg_get_val_str( hkey, szFeature );
1524 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
1527 return INSTALLSTATE_ADVERTISED;
1529 for( p = components; *p && *p != 2 ; p += 20)
1531 if (!decode_base85_guid( p, &guid ))
1533 if (p != components)
1536 msi_free(components);
1537 return INSTALLSTATE_BADCONFIG;
1540 StringFromGUID2(&guid, comp, GUID_SIZE);
1541 rc = MSIREG_OpenUserDataComponentKey(comp, &hkey, FALSE);
1542 if (rc != ERROR_SUCCESS)
1544 msi_free(components);
1545 return INSTALLSTATE_ADVERTISED;
1548 path = msi_reg_get_val_str(hkey, squishProduct);
1555 TRACE("%s %s -> %d\n", debugstr_w(szProduct), debugstr_w(szFeature), r);
1556 msi_free(components);
1559 return INSTALLSTATE_ADVERTISED;
1561 return INSTALLSTATE_LOCAL;
1564 /******************************************************************
1565 * MsiGetFileVersionA [MSI.@]
1567 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
1568 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
1570 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
1571 UINT ret = ERROR_OUTOFMEMORY;
1573 if ((lpVersionBuf && !pcchVersionBuf) ||
1574 (lpLangBuf && !pcchLangBuf))
1575 return ERROR_INVALID_PARAMETER;
1579 szwFilePath = strdupAtoW( szFilePath );
1584 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
1586 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
1587 if( !lpwVersionBuff )
1591 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
1593 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
1598 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
1599 lpwLangBuff, pcchLangBuf);
1601 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
1602 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
1603 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
1604 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
1605 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
1606 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
1609 msi_free(szwFilePath);
1610 msi_free(lpwVersionBuff);
1611 msi_free(lpwLangBuff);
1616 /******************************************************************
1617 * MsiGetFileVersionW [MSI.@]
1619 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
1620 LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
1622 static const WCHAR szVersionResource[] = {'\\',0};
1623 static const WCHAR szVersionFormat[] = {
1624 '%','d','.','%','d','.','%','d','.','%','d',0};
1625 static const WCHAR szLangFormat[] = {'%','d',0};
1627 DWORD dwVerLen, gle;
1628 LPVOID lpVer = NULL;
1629 VS_FIXEDFILEINFO *ffi;
1633 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
1634 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
1635 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
1637 if ((lpVersionBuf && !pcchVersionBuf) ||
1638 (lpLangBuf && !pcchLangBuf))
1639 return ERROR_INVALID_PARAMETER;
1641 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
1644 gle = GetLastError();
1645 if (gle == ERROR_BAD_PATHNAME)
1646 return ERROR_FILE_NOT_FOUND;
1647 else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND)
1648 return ERROR_FILE_INVALID;
1653 lpVer = msi_alloc(dwVerLen);
1656 ret = ERROR_OUTOFMEMORY;
1660 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
1662 ret = GetLastError();
1668 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
1671 wsprintfW(tmp, szVersionFormat,
1672 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
1673 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
1674 if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
1676 if (lstrlenW(tmp) >= *pcchVersionBuf)
1677 ret = ERROR_MORE_DATA;
1679 *pcchVersionBuf = lstrlenW(tmp);
1683 if (lpVersionBuf) *lpVersionBuf = 0;
1684 *pcchVersionBuf = 0;
1690 DWORD lang = GetUserDefaultLangID();
1692 FIXME("Retrieve language from file\n");
1693 wsprintfW(tmp, szLangFormat, lang);
1694 if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
1696 if (lstrlenW(tmp) >= *pcchLangBuf)
1697 ret = ERROR_MORE_DATA;
1699 *pcchLangBuf = lstrlenW(tmp);
1707 /***********************************************************************
1708 * MsiGetFeatureUsageW [MSI.@]
1710 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
1711 LPDWORD pdwUseCount, LPWORD pwDateUsed )
1713 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
1714 pdwUseCount, pwDateUsed);
1715 return ERROR_CALL_NOT_IMPLEMENTED;
1718 /***********************************************************************
1719 * MsiGetFeatureUsageA [MSI.@]
1721 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
1722 LPDWORD pdwUseCount, LPWORD pwDateUsed )
1724 LPWSTR prod = NULL, feat = NULL;
1725 UINT ret = ERROR_OUTOFMEMORY;
1727 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
1728 pdwUseCount, pwDateUsed);
1730 prod = strdupAtoW( szProduct );
1731 if (szProduct && !prod)
1734 feat = strdupAtoW( szFeature );
1735 if (szFeature && !feat)
1738 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
1747 /***********************************************************************
1748 * MsiUseFeatureExW [MSI.@]
1750 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
1751 DWORD dwInstallMode, DWORD dwReserved )
1755 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
1756 dwInstallMode, dwReserved);
1758 state = MsiQueryFeatureStateW( szProduct, szFeature );
1761 return INSTALLSTATE_INVALIDARG;
1763 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
1765 FIXME("mark product %s feature %s as used\n",
1766 debugstr_w(szProduct), debugstr_w(szFeature) );
1772 /***********************************************************************
1773 * MsiUseFeatureExA [MSI.@]
1775 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
1776 DWORD dwInstallMode, DWORD dwReserved )
1778 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
1779 LPWSTR prod = NULL, feat = NULL;
1781 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
1782 dwInstallMode, dwReserved);
1784 prod = strdupAtoW( szProduct );
1785 if (szProduct && !prod)
1788 feat = strdupAtoW( szFeature );
1789 if (szFeature && !feat)
1792 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
1801 /***********************************************************************
1802 * MsiUseFeatureW [MSI.@]
1804 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
1806 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
1809 /***********************************************************************
1810 * MsiUseFeatureA [MSI.@]
1812 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
1814 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
1817 /***********************************************************************
1818 * MSI_ProvideQualifiedComponentEx [internal]
1820 static UINT WINAPI MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
1821 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
1822 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
1823 LPDWORD pcchPathBuf)
1825 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
1826 feature[MAX_FEATURE_CHARS+1];
1832 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
1833 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
1834 Unused1, Unused2, lpPathBuf, pcchPathBuf);
1836 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
1837 if (rc != ERROR_SUCCESS)
1838 return ERROR_INDEX_ABSENT;
1840 info = msi_reg_get_val_str( hkey, szQualifier );
1844 return ERROR_INDEX_ABSENT;
1846 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
1849 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
1851 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
1855 if (rc != INSTALLSTATE_LOCAL)
1856 return ERROR_FILE_NOT_FOUND;
1858 return ERROR_SUCCESS;
1861 /***********************************************************************
1862 * MsiProvideQualifiedComponentExW [MSI.@]
1864 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
1865 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
1866 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
1867 LPDWORD pcchPathBuf)
1871 path.unicode = TRUE;
1872 path.str.w = lpPathBuf;
1874 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
1875 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
1878 /***********************************************************************
1879 * MsiProvideQualifiedComponentExA [MSI.@]
1881 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
1882 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
1883 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
1884 LPDWORD pcchPathBuf)
1886 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
1887 UINT r = ERROR_OUTOFMEMORY;
1890 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
1891 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
1892 Unused1, Unused2, lpPathBuf, pcchPathBuf);
1894 szwComponent = strdupAtoW( szComponent );
1895 if (szComponent && !szwComponent)
1898 szwQualifier = strdupAtoW( szQualifier );
1899 if (szQualifier && !szwQualifier)
1902 szwProduct = strdupAtoW( szProduct );
1903 if (szProduct && !szwProduct)
1906 path.unicode = FALSE;
1907 path.str.a = lpPathBuf;
1909 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
1910 dwInstallMode, szwProduct, Unused1,
1911 Unused2, &path, pcchPathBuf);
1913 msi_free(szwProduct);
1914 msi_free(szwComponent);
1915 msi_free(szwQualifier);
1920 /***********************************************************************
1921 * MsiProvideQualifiedComponentW [MSI.@]
1923 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
1924 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
1925 LPDWORD pcchPathBuf)
1927 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
1928 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
1931 /***********************************************************************
1932 * MsiProvideQualifiedComponentA [MSI.@]
1934 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
1935 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
1936 LPDWORD pcchPathBuf)
1938 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
1939 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
1942 /***********************************************************************
1943 * MSI_GetUserInfo [internal]
1945 static USERINFOSTATE WINAPI MSI_GetUserInfo(LPCWSTR szProduct,
1946 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
1947 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
1948 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
1951 LPWSTR user, org, serial;
1953 USERINFOSTATE state;
1955 TRACE("%s %p %p %p %p %p %p\n",debugstr_w(szProduct), lpUserNameBuf,
1956 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
1960 return USERINFOSTATE_INVALIDARG;
1962 r = MSIREG_OpenUninstallKey(szProduct, &hkey, FALSE);
1963 if (r != ERROR_SUCCESS)
1964 return USERINFOSTATE_UNKNOWN;
1966 user = msi_reg_get_val_str( hkey, INSTALLPROPERTY_REGOWNERW );
1967 org = msi_reg_get_val_str( hkey, INSTALLPROPERTY_REGCOMPANYW );
1968 serial = msi_reg_get_val_str( hkey, INSTALLPROPERTY_PRODUCTIDW );
1972 state = USERINFOSTATE_PRESENT;
1976 r = msi_strcpy_to_awstring( user, lpUserNameBuf, pcchUserNameBuf );
1977 if (r == ERROR_MORE_DATA)
1978 state = USERINFOSTATE_MOREDATA;
1981 state = USERINFOSTATE_ABSENT;
1984 r = msi_strcpy_to_awstring( org, lpOrgNameBuf, pcchOrgNameBuf );
1985 if (r == ERROR_MORE_DATA && state == USERINFOSTATE_PRESENT)
1986 state = USERINFOSTATE_MOREDATA;
1988 /* msdn states: The user information is considered to be present even in the absence of a company name. */
1991 r = msi_strcpy_to_awstring( serial, lpSerialBuf, pcchSerialBuf );
1992 if (r == ERROR_MORE_DATA && state == USERINFOSTATE_PRESENT)
1993 state = USERINFOSTATE_MOREDATA;
1996 state = USERINFOSTATE_ABSENT;
2005 /***********************************************************************
2006 * MsiGetUserInfoW [MSI.@]
2008 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
2009 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
2010 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
2011 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
2013 awstring user, org, serial;
2015 user.unicode = TRUE;
2016 user.str.w = lpUserNameBuf;
2018 org.str.w = lpOrgNameBuf;
2019 serial.unicode = TRUE;
2020 serial.str.w = lpSerialBuf;
2022 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
2023 &org, pcchOrgNameBuf,
2024 &serial, pcchSerialBuf );
2027 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
2028 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
2029 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
2030 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
2032 awstring user, org, serial;
2036 prod = strdupAtoW( szProduct );
2037 if (szProduct && !prod)
2038 return ERROR_OUTOFMEMORY;
2040 user.unicode = FALSE;
2041 user.str.a = lpUserNameBuf;
2042 org.unicode = FALSE;
2043 org.str.a = lpOrgNameBuf;
2044 serial.unicode = FALSE;
2045 serial.str.a = lpSerialBuf;
2047 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
2048 &org, pcchOrgNameBuf,
2049 &serial, pcchSerialBuf );
2056 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
2060 MSIPACKAGE *package;
2061 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
2063 TRACE("(%s)\n",debugstr_w(szProduct));
2065 rc = MsiOpenProductW(szProduct,&handle);
2066 if (rc != ERROR_SUCCESS)
2067 return ERROR_INVALID_PARAMETER;
2069 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
2070 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
2071 msiobj_release( &package->hdr );
2073 MsiCloseHandle(handle);
2078 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
2082 MSIPACKAGE *package;
2083 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
2085 TRACE("(%s)\n",debugstr_a(szProduct));
2087 rc = MsiOpenProductA(szProduct,&handle);
2088 if (rc != ERROR_SUCCESS)
2089 return ERROR_INVALID_PARAMETER;
2091 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
2092 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
2093 msiobj_release( &package->hdr );
2095 MsiCloseHandle(handle);
2100 /***********************************************************************
2101 * MsiConfigureFeatureA [MSI.@]
2103 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
2105 LPWSTR prod, feat = NULL;
2106 UINT r = ERROR_OUTOFMEMORY;
2108 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
2110 prod = strdupAtoW( szProduct );
2111 if (szProduct && !prod)
2114 feat = strdupAtoW( szFeature );
2115 if (szFeature && !feat)
2118 r = MsiConfigureFeatureW(prod, feat, eInstallState);
2127 /***********************************************************************
2128 * MsiConfigureFeatureW [MSI.@]
2130 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
2132 static const WCHAR szCostInit[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
2133 MSIPACKAGE *package = NULL;
2135 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
2138 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
2140 if (!szProduct || !szFeature)
2141 return ERROR_INVALID_PARAMETER;
2143 switch (eInstallState)
2145 case INSTALLSTATE_DEFAULT:
2146 /* FIXME: how do we figure out the default location? */
2147 eInstallState = INSTALLSTATE_LOCAL;
2149 case INSTALLSTATE_LOCAL:
2150 case INSTALLSTATE_SOURCE:
2151 case INSTALLSTATE_ABSENT:
2152 case INSTALLSTATE_ADVERTISED:
2155 return ERROR_INVALID_PARAMETER;
2158 r = MSI_OpenProductW( szProduct, &package );
2159 if (r != ERROR_SUCCESS)
2162 sz = sizeof(sourcepath);
2163 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2164 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
2166 sz = sizeof(filename);
2167 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2168 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
2170 lstrcatW( sourcepath, filename );
2172 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
2174 r = ACTION_PerformUIAction( package, szCostInit, -1 );
2175 if (r != ERROR_SUCCESS)
2178 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
2179 if (r != ERROR_SUCCESS)
2182 r = MSI_InstallPackage( package, sourcepath, NULL );
2185 msiobj_release( &package->hdr );
2190 /***********************************************************************
2191 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
2193 * Notes: undocumented
2195 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
2197 WCHAR path[MAX_PATH];
2199 TRACE("%d\n", dwReserved);
2203 FIXME("dwReserved=%d\n", dwReserved);
2204 return ERROR_INVALID_PARAMETER;
2207 if (!GetWindowsDirectoryW(path, MAX_PATH))
2208 return ERROR_FUNCTION_FAILED;
2210 lstrcatW(path, installerW);
2212 if (!CreateDirectoryW(path, NULL))
2213 return ERROR_FUNCTION_FAILED;
2215 return ERROR_SUCCESS;
2218 /***********************************************************************
2219 * MsiGetShortcutTargetA [MSI.@]
2221 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
2222 LPSTR szProductCode, LPSTR szFeatureId,
2223 LPSTR szComponentCode )
2226 const int len = MAX_FEATURE_CHARS+1;
2227 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
2230 target = strdupAtoW( szShortcutTarget );
2231 if (szShortcutTarget && !target )
2232 return ERROR_OUTOFMEMORY;
2236 r = MsiGetShortcutTargetW( target, product, feature, component );
2238 if (r == ERROR_SUCCESS)
2240 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
2241 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
2242 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
2247 /***********************************************************************
2248 * MsiGetShortcutTargetW [MSI.@]
2250 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
2251 LPWSTR szProductCode, LPWSTR szFeatureId,
2252 LPWSTR szComponentCode )
2254 IShellLinkDataList *dl = NULL;
2255 IPersistFile *pf = NULL;
2256 LPEXP_DARWIN_LINK darwin = NULL;
2259 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
2260 szProductCode, szFeatureId, szComponentCode );
2262 init = CoInitialize(NULL);
2264 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
2265 &IID_IPersistFile, (LPVOID*) &pf );
2266 if( SUCCEEDED( r ) )
2268 r = IPersistFile_Load( pf, szShortcutTarget,
2269 STGM_READ | STGM_SHARE_DENY_WRITE );
2270 if( SUCCEEDED( r ) )
2272 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
2274 if( SUCCEEDED( r ) )
2276 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
2278 IShellLinkDataList_Release( dl );
2281 IPersistFile_Release( pf );
2284 if (SUCCEEDED(init))
2287 TRACE("darwin = %p\n", darwin);
2294 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
2295 szProductCode, szFeatureId, szComponentCode, &sz );
2296 LocalFree( darwin );
2300 return ERROR_FUNCTION_FAILED;
2303 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
2304 DWORD dwReinstallMode )
2306 MSIPACKAGE* package = NULL;
2308 WCHAR sourcepath[MAX_PATH];
2309 WCHAR filename[MAX_PATH];
2310 static const WCHAR szLogVerbose[] = {
2311 ' ','L','O','G','V','E','R','B','O','S','E',0 };
2312 static const WCHAR szInstalled[] = { 'I','n','s','t','a','l','l','e','d',0};
2313 static const WCHAR szReinstall[] = {'R','E','I','N','S','T','A','L','L',0};
2314 static const WCHAR szReinstallMode[] = {'R','E','I','N','S','T','A','L','L','M','O','D','E',0};
2315 static const WCHAR szOne[] = {'1',0};
2316 WCHAR reinstallmode[11];
2320 FIXME("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
2323 ptr = reinstallmode;
2325 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
2327 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
2329 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
2331 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
2333 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
2335 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
2337 if (dwReinstallMode & REINSTALLMODE_USERDATA)
2339 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
2341 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
2343 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
2347 sz = sizeof(sourcepath);
2348 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2349 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
2351 sz = sizeof(filename);
2352 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2353 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
2355 lstrcatW( sourcepath, filename );
2357 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
2358 r = MSI_OpenPackageW( sourcepath, &package );
2360 r = MSI_OpenProductW( szProduct, &package );
2362 if (r != ERROR_SUCCESS)
2365 MSI_SetPropertyW( package, szReinstallMode, reinstallmode );
2366 MSI_SetPropertyW( package, szInstalled, szOne );
2367 MSI_SetPropertyW( package, szLogVerbose, szOne );
2368 MSI_SetPropertyW( package, szReinstall, szFeature );
2370 r = MSI_InstallPackage( package, sourcepath, NULL );
2372 msiobj_release( &package->hdr );
2377 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
2378 DWORD dwReinstallMode )
2384 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
2387 wszProduct = strdupAtoW(szProduct);
2388 wszFeature = strdupAtoW(szFeature);
2390 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
2392 msi_free(wszProduct);
2393 msi_free(wszFeature);
2400 unsigned int buf[4];
2401 unsigned char in[64];
2402 unsigned char digest[16];
2405 extern VOID WINAPI MD5Init( MD5_CTX *);
2406 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
2407 extern VOID WINAPI MD5Final( MD5_CTX *);
2409 /***********************************************************************
2410 * MsiGetFileHashW [MSI.@]
2412 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
2413 PMSIFILEHASHINFO pHash )
2415 HANDLE handle, mapping;
2418 UINT r = ERROR_FUNCTION_FAILED;
2420 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
2423 return ERROR_INVALID_PARAMETER;
2426 return ERROR_PATH_NOT_FOUND;
2429 return ERROR_INVALID_PARAMETER;
2431 return ERROR_INVALID_PARAMETER;
2432 if (pHash->dwFileHashInfoSize < sizeof *pHash)
2433 return ERROR_INVALID_PARAMETER;
2435 handle = CreateFileW( szFilePath, GENERIC_READ,
2436 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
2437 if (handle == INVALID_HANDLE_VALUE)
2438 return ERROR_FILE_NOT_FOUND;
2440 length = GetFileSize( handle, NULL );
2442 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
2445 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
2451 MD5Update( &ctx, p, length );
2453 UnmapViewOfFile( p );
2455 memcpy( pHash->dwData, &ctx.digest, sizeof pHash->dwData );
2458 CloseHandle( mapping );
2460 CloseHandle( handle );
2465 /***********************************************************************
2466 * MsiGetFileHashA [MSI.@]
2468 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
2469 PMSIFILEHASHINFO pHash )
2474 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
2476 file = strdupAtoW( szFilePath );
2477 if (szFilePath && !file)
2478 return ERROR_OUTOFMEMORY;
2480 r = MsiGetFileHashW( file, dwOptions, pHash );
2485 /***********************************************************************
2486 * MsiAdvertiseScriptW [MSI.@]
2488 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
2489 PHKEY phRegData, BOOL fRemoveItems )
2491 FIXME("%s %08x %p %d\n",
2492 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
2493 return ERROR_CALL_NOT_IMPLEMENTED;
2496 /***********************************************************************
2497 * MsiAdvertiseScriptA [MSI.@]
2499 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
2500 PHKEY phRegData, BOOL fRemoveItems )
2502 FIXME("%s %08x %p %d\n",
2503 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
2504 return ERROR_CALL_NOT_IMPLEMENTED;