Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / msi / msi.c
blobaeb9c6c97c76920090fbebde9062937299dcbd84
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 "msiquery.h"
34 #include "msipriv.h"
35 #include "wincrypt.h"
36 #include "winver.h"
37 #include "winuser.h"
38 #include "shlobj.h"
39 #include "shobjidl.h"
40 #include "objidl.h"
41 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msi);
45 static const WCHAR installerW[] = {'\\','I','n','s','t','a','l','l','e','r',0};
47 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
49 UINT r;
50 LPWSTR szwProd = NULL;
52 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
54 if( szProduct )
56 szwProd = strdupAtoW( szProduct );
57 if( !szwProd )
58 return ERROR_OUTOFMEMORY;
61 r = MsiOpenProductW( szwProd, phProduct );
63 msi_free( szwProd );
65 return r;
68 static UINT MSI_OpenProductW( LPCWSTR szProduct, MSIPACKAGE **ppackage )
70 LPWSTR path = NULL;
71 UINT r;
72 HKEY hKeyProduct = NULL;
73 DWORD count, type;
75 TRACE("%s %p\n", debugstr_w(szProduct), ppackage );
77 r = MSIREG_OpenUninstallKey(szProduct,&hKeyProduct,FALSE);
78 if( r != ERROR_SUCCESS )
80 r = ERROR_UNKNOWN_PRODUCT;
81 goto end;
84 /* find the size of the path */
85 type = count = 0;
86 r = RegQueryValueExW( hKeyProduct, INSTALLPROPERTY_LOCALPACKAGEW,
87 NULL, &type, NULL, &count );
88 if( r != ERROR_SUCCESS )
90 r = ERROR_UNKNOWN_PRODUCT;
91 goto end;
94 /* now alloc and fetch the path of the database to open */
95 path = msi_alloc( count );
96 if( !path )
97 goto end;
99 r = RegQueryValueExW( hKeyProduct, INSTALLPROPERTY_LOCALPACKAGEW,
100 NULL, &type, (LPBYTE) path, &count );
101 if( r != ERROR_SUCCESS )
103 r = ERROR_UNKNOWN_PRODUCT;
104 goto end;
107 r = MSI_OpenPackageW( path, ppackage );
109 end:
110 msi_free( path );
111 if( hKeyProduct )
112 RegCloseKey( hKeyProduct );
114 return r;
117 UINT WINAPI MsiOpenProductW( LPCWSTR szProduct, MSIHANDLE *phProduct )
119 MSIPACKAGE *package = NULL;
120 UINT r;
122 r = MSI_OpenProductW( szProduct, &package );
123 if( r == ERROR_SUCCESS )
125 *phProduct = alloc_msihandle( &package->hdr );
126 if (! *phProduct)
127 r = ERROR_NOT_ENOUGH_MEMORY;
128 msiobj_release( &package->hdr );
130 return r;
133 UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
134 LPCSTR szTransforms, LANGID lgidLanguage)
136 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath),
137 debugstr_a(szScriptfilePath), debugstr_a(szTransforms), lgidLanguage);
138 return ERROR_CALL_NOT_IMPLEMENTED;
141 UINT WINAPI MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
142 LPCWSTR szTransforms, LANGID lgidLanguage)
144 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath),
145 debugstr_w(szScriptfilePath), debugstr_w(szTransforms), lgidLanguage);
146 return ERROR_CALL_NOT_IMPLEMENTED;
149 UINT WINAPI MsiAdvertiseProductExA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
150 LPCSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
152 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath),
153 debugstr_a(szScriptfilePath), debugstr_a(szTransforms),
154 lgidLanguage, dwPlatform, dwOptions);
155 return ERROR_CALL_NOT_IMPLEMENTED;
158 UINT WINAPI MsiAdvertiseProductExW( LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
159 LPCWSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
161 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath),
162 debugstr_w(szScriptfilePath), debugstr_w(szTransforms),
163 lgidLanguage, dwPlatform, dwOptions);
164 return ERROR_CALL_NOT_IMPLEMENTED;
167 UINT WINAPI MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)
169 LPWSTR szwPath = NULL, szwCommand = NULL;
170 UINT r = ERROR_OUTOFMEMORY;
172 TRACE("%s %s\n",debugstr_a(szPackagePath), debugstr_a(szCommandLine));
174 if( szPackagePath )
176 szwPath = strdupAtoW( szPackagePath );
177 if( !szwPath )
178 goto end;
181 if( szCommandLine )
183 szwCommand = strdupAtoW( szCommandLine );
184 if( !szwCommand )
185 goto end;
188 r = MsiInstallProductW( szwPath, szwCommand );
190 end:
191 msi_free( szwPath );
192 msi_free( szwCommand );
194 return r;
197 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
199 MSIPACKAGE *package = NULL;
200 UINT r;
202 TRACE("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
204 r = MSI_OpenPackageW( szPackagePath, &package );
205 if (r == ERROR_SUCCESS)
207 r = MSI_InstallPackage( package, szPackagePath, szCommandLine );
208 msiobj_release( &package->hdr );
211 return r;
214 UINT WINAPI MsiReinstallProductA(LPCSTR szProduct, DWORD dwReinstallMode)
216 FIXME("%s %08x\n", debugstr_a(szProduct), dwReinstallMode);
217 return ERROR_CALL_NOT_IMPLEMENTED;
220 UINT WINAPI MsiReinstallProductW(LPCWSTR szProduct, DWORD dwReinstallMode)
222 FIXME("%s %08x\n", debugstr_w(szProduct), dwReinstallMode);
223 return ERROR_CALL_NOT_IMPLEMENTED;
226 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
227 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
229 FIXME("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
230 eInstallType, debugstr_a(szCommandLine));
231 return ERROR_CALL_NOT_IMPLEMENTED;
234 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
235 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
237 FIXME("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
238 eInstallType, debugstr_w(szCommandLine));
239 return ERROR_CALL_NOT_IMPLEMENTED;
242 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
243 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
245 MSIPACKAGE* package = NULL;
246 UINT r;
247 DWORD sz;
248 WCHAR sourcepath[MAX_PATH];
249 WCHAR filename[MAX_PATH];
250 static const WCHAR szInstalled[] = {
251 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
252 LPWSTR commandline;
254 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
255 debugstr_w(szCommandLine));
257 if (eInstallState != INSTALLSTATE_LOCAL &&
258 eInstallState != INSTALLSTATE_DEFAULT)
260 FIXME("Not implemented for anything other than local installs\n");
261 return ERROR_CALL_NOT_IMPLEMENTED;
264 sz = sizeof(sourcepath);
265 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
266 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath,
267 &sz);
269 sz = sizeof(filename);
270 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
271 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
273 lstrcatW(sourcepath,filename);
276 * ok 1, we need to find the msi file for this product.
277 * 2, find the source dir for the files
278 * 3, do the configure/install.
279 * 4, cleanupany runonce entry.
282 r = MSI_OpenProductW( szProduct, &package );
283 if (r != ERROR_SUCCESS)
284 return r;
286 sz = lstrlenW(szInstalled) + 1;
288 if (szCommandLine)
289 sz += lstrlenW(szCommandLine);
291 commandline = msi_alloc(sz * sizeof(WCHAR));
292 if (!commandline )
294 r = ERROR_OUTOFMEMORY;
295 goto end;
298 commandline[0] = 0;
299 if (szCommandLine)
300 lstrcpyW(commandline,szCommandLine);
302 if (MsiQueryProductStateW(szProduct) != INSTALLSTATE_UNKNOWN)
303 lstrcatW(commandline,szInstalled);
305 r = MSI_InstallPackage( package, sourcepath, commandline );
307 msi_free(commandline);
309 end:
310 msiobj_release( &package->hdr );
312 return r;
315 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
316 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
318 LPWSTR szwProduct = NULL;
319 LPWSTR szwCommandLine = NULL;
320 UINT r = ERROR_OUTOFMEMORY;
322 if( szProduct )
324 szwProduct = strdupAtoW( szProduct );
325 if( !szwProduct )
326 goto end;
329 if( szCommandLine)
331 szwCommandLine = strdupAtoW( szCommandLine );
332 if( !szwCommandLine)
333 goto end;
336 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
337 szwCommandLine );
338 end:
339 msi_free( szwProduct );
340 msi_free( szwCommandLine);
342 return r;
345 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
346 INSTALLSTATE eInstallState)
348 LPWSTR szwProduct = NULL;
349 UINT r;
351 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
353 if( szProduct )
355 szwProduct = strdupAtoW( szProduct );
356 if( !szwProduct )
357 return ERROR_OUTOFMEMORY;
360 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
361 msi_free( szwProduct );
363 return r;
366 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
367 INSTALLSTATE eInstallState)
369 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
372 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
374 LPWSTR szwComponent = NULL;
375 UINT r;
376 WCHAR szwBuffer[GUID_SIZE];
378 TRACE("%s %s\n",debugstr_a(szComponent), debugstr_a(szBuffer));
380 if( szComponent )
382 szwComponent = strdupAtoW( szComponent );
383 if( !szwComponent )
384 return ERROR_OUTOFMEMORY;
387 r = MsiGetProductCodeW( szwComponent, szwBuffer );
389 if( ERROR_SUCCESS == r )
390 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
392 msi_free( szwComponent );
394 return r;
397 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
399 UINT rc;
400 HKEY hkey;
401 WCHAR szSquished[GUID_SIZE];
402 DWORD sz = GUID_SIZE;
403 static const WCHAR szPermKey[] =
404 { '0','0','0','0','0','0','0','0','0','0','0','0',
405 '0','0','0','0','0','0','0','0','0','0','0','0',
406 '0','0','0','0','0','0','0','0',0};
408 TRACE("%s %p\n",debugstr_w(szComponent), szBuffer);
410 if (NULL == szComponent)
411 return ERROR_INVALID_PARAMETER;
413 rc = MSIREG_OpenComponentsKey( szComponent, &hkey, FALSE);
414 if (rc != ERROR_SUCCESS)
415 return ERROR_UNKNOWN_COMPONENT;
417 rc = RegEnumValueW(hkey, 0, szSquished, &sz, NULL, NULL, NULL, NULL);
418 if (rc == ERROR_SUCCESS && strcmpW(szSquished,szPermKey)==0)
420 sz = GUID_SIZE;
421 rc = RegEnumValueW(hkey, 1, szSquished, &sz, NULL, NULL, NULL, NULL);
424 RegCloseKey(hkey);
426 if (rc != ERROR_SUCCESS)
427 return ERROR_INSTALL_FAILURE;
429 unsquash_guid(szSquished, szBuffer);
430 return ERROR_SUCCESS;
433 static UINT WINAPI MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
434 awstring *szValue, DWORD *pcchValueBuf)
436 UINT r;
437 HKEY hkey;
438 LPWSTR val = NULL;
440 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
441 debugstr_w(szAttribute), szValue, pcchValueBuf);
444 * FIXME: Values seem scattered/duplicated in the registry. Is there a system?
447 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
448 return ERROR_INVALID_PARAMETER;
450 /* check for special properties */
451 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW))
453 LPWSTR regval;
454 WCHAR packagecode[35];
456 r = MSIREG_OpenUserProductsKey(szProduct, &hkey, FALSE);
457 if (r != ERROR_SUCCESS)
458 return ERROR_UNKNOWN_PRODUCT;
460 regval = msi_reg_get_val_str( hkey, szAttribute );
461 if (regval)
463 if (unsquash_guid(regval, packagecode))
464 val = strdupW(packagecode);
465 msi_free(regval);
468 RegCloseKey(hkey);
470 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW))
472 static const WCHAR one[] = { '1',0 };
474 * FIXME: should be in the Product key (user or system?)
475 * but isn't written yet...
477 val = strdupW( one );
479 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_LANGUAGEW) ||
480 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONW))
482 static const WCHAR fmt[] = { '%','u',0 };
483 WCHAR szVal[16];
484 DWORD regval;
486 r = MSIREG_OpenUninstallKey(szProduct, &hkey, FALSE);
487 if (r != ERROR_SUCCESS)
488 return ERROR_UNKNOWN_PRODUCT;
490 if (msi_reg_get_val_dword( hkey, szAttribute, &regval))
492 sprintfW(szVal, fmt, regval);
493 val = strdupW( szVal );
496 RegCloseKey(hkey);
498 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTNAMEW))
500 r = MSIREG_OpenUserProductsKey(szProduct, &hkey, FALSE);
501 if (r != ERROR_SUCCESS)
502 return ERROR_UNKNOWN_PRODUCT;
504 val = msi_reg_get_val_str( hkey, szAttribute );
506 RegCloseKey(hkey);
508 else
510 static const WCHAR szDisplayVersion[] = {
511 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0 };
513 FIXME("%s\n", debugstr_w(szAttribute));
514 /* FIXME: some attribute values not tested... */
516 if (!lstrcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ))
517 szAttribute = szDisplayVersion;
519 r = MSIREG_OpenUninstallKey( szProduct, &hkey, FALSE );
520 if (r != ERROR_SUCCESS)
521 return ERROR_UNKNOWN_PRODUCT;
523 val = msi_reg_get_val_str( hkey, szAttribute );
525 RegCloseKey(hkey);
528 TRACE("returning %s\n", debugstr_w(val));
530 if (!val)
531 return ERROR_UNKNOWN_PROPERTY;
533 r = msi_strcpy_to_awstring( val, szValue, pcchValueBuf );
535 msi_free(val);
537 return r;
540 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
541 LPSTR szBuffer, DWORD *pcchValueBuf)
543 LPWSTR szwProduct, szwAttribute = NULL;
544 UINT r = ERROR_OUTOFMEMORY;
545 awstring buffer;
547 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
548 szBuffer, pcchValueBuf);
550 szwProduct = strdupAtoW( szProduct );
551 if( szProduct && !szwProduct )
552 goto end;
554 szwAttribute = strdupAtoW( szAttribute );
555 if( szAttribute && !szwAttribute )
556 goto end;
558 buffer.unicode = FALSE;
559 buffer.str.a = szBuffer;
561 r = MSI_GetProductInfo( szwProduct, szwAttribute,
562 &buffer, pcchValueBuf );
564 end:
565 msi_free( szwProduct );
566 msi_free( szwAttribute );
568 return r;
571 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
572 LPWSTR szBuffer, DWORD *pcchValueBuf)
574 awstring buffer;
576 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
577 szBuffer, pcchValueBuf);
579 buffer.unicode = TRUE;
580 buffer.str.w = szBuffer;
582 return MSI_GetProductInfo( szProduct, szAttribute,
583 &buffer, pcchValueBuf );
586 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
588 LPWSTR szwLogFile = NULL;
589 UINT r;
591 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
593 if( szLogFile )
595 szwLogFile = strdupAtoW( szLogFile );
596 if( !szwLogFile )
597 return ERROR_OUTOFMEMORY;
599 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
600 msi_free( szwLogFile );
601 return r;
604 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
606 HANDLE file = INVALID_HANDLE_VALUE;
608 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
610 if (szLogFile)
612 lstrcpyW(gszLogFile,szLogFile);
613 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
614 DeleteFileW(szLogFile);
615 file = CreateFileW(szLogFile, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
616 FILE_ATTRIBUTE_NORMAL, NULL);
617 if (file != INVALID_HANDLE_VALUE)
618 CloseHandle(file);
619 else
620 ERR("Unable to enable log %s\n",debugstr_w(szLogFile));
622 else
623 gszLogFile[0] = '\0';
625 return ERROR_SUCCESS;
628 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
630 LPWSTR szwProduct = NULL;
631 INSTALLSTATE r;
633 if( szProduct )
635 szwProduct = strdupAtoW( szProduct );
636 if( !szwProduct )
637 return ERROR_OUTOFMEMORY;
639 r = MsiQueryProductStateW( szwProduct );
640 msi_free( szwProduct );
641 return r;
644 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
646 UINT rc;
647 INSTALLSTATE rrc = INSTALLSTATE_UNKNOWN;
648 HKEY hkey = 0;
649 static const WCHAR szWindowsInstaller[] = {
650 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0 };
651 DWORD sz;
653 TRACE("%s\n", debugstr_w(szProduct));
655 if (!szProduct)
656 return INSTALLSTATE_INVALIDARG;
658 rc = MSIREG_OpenUserProductsKey(szProduct,&hkey,FALSE);
659 if (rc != ERROR_SUCCESS)
660 goto end;
662 RegCloseKey(hkey);
664 rc = MSIREG_OpenUninstallKey(szProduct,&hkey,FALSE);
665 if (rc != ERROR_SUCCESS)
666 goto end;
668 sz = sizeof(rrc);
669 rc = RegQueryValueExW(hkey,szWindowsInstaller,NULL,NULL,(LPVOID)&rrc, &sz);
670 if (rc != ERROR_SUCCESS)
671 goto end;
673 switch (rrc)
675 case 1:
676 /* default */
677 rrc = INSTALLSTATE_DEFAULT;
678 break;
679 default:
680 FIXME("Unknown install state read from registry (%i)\n",rrc);
681 rrc = INSTALLSTATE_UNKNOWN;
682 break;
684 end:
685 RegCloseKey(hkey);
686 return rrc;
689 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
691 INSTALLUILEVEL old = gUILevel;
692 HWND oldwnd = gUIhwnd;
694 TRACE("%08x %p\n", dwUILevel, phWnd);
696 gUILevel = dwUILevel;
697 if (phWnd)
699 gUIhwnd = *phWnd;
700 *phWnd = oldwnd;
702 return old;
705 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
706 DWORD dwMessageFilter, LPVOID pvContext)
708 INSTALLUI_HANDLERA prev = gUIHandlerA;
710 TRACE("%p %x %p\n",puiHandler, dwMessageFilter,pvContext);
711 gUIHandlerA = puiHandler;
712 gUIFilter = dwMessageFilter;
713 gUIContext = pvContext;
715 return prev;
718 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
719 DWORD dwMessageFilter, LPVOID pvContext)
721 INSTALLUI_HANDLERW prev = gUIHandlerW;
723 TRACE("%p %x %p\n",puiHandler,dwMessageFilter,pvContext);
724 gUIHandlerW = puiHandler;
725 gUIFilter = dwMessageFilter;
726 gUIContext = pvContext;
728 return prev;
731 /******************************************************************
732 * MsiLoadStringW [MSI.@]
734 * Loads a string from MSI's string resources.
736 * PARAMS
738 * handle [I] only -1 is handled currently
739 * id [I] id of the string to be loaded
740 * lpBuffer [O] buffer for the string to be written to
741 * nBufferMax [I] maximum size of the buffer in characters
742 * lang [I] the preferred language for the string
744 * RETURNS
746 * If successful, this function returns the language id of the string loaded
747 * If the function fails, the function returns zero.
749 * NOTES
751 * The type of the first parameter is unknown. LoadString's prototype
752 * suggests that it might be a module handle. I have made it an MSI handle
753 * for starters, as -1 is an invalid MSI handle, but not an invalid module
754 * handle. Maybe strings can be stored in an MSI database somehow.
756 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
757 int nBufferMax, LANGID lang )
759 HRSRC hres;
760 HGLOBAL hResData;
761 LPWSTR p;
762 DWORD i, len;
764 TRACE("%ld %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
766 if( handle != -1 )
767 FIXME("don't know how to deal with handle = %08lx\n", handle);
769 if( !lang )
770 lang = GetUserDefaultLangID();
772 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
773 (LPWSTR)1, lang );
774 if( !hres )
775 return 0;
776 hResData = LoadResource( msi_hInstance, hres );
777 if( !hResData )
778 return 0;
779 p = LockResource( hResData );
780 if( !p )
781 return 0;
783 for (i = 0; i < (id&0xf); i++)
784 p += *p + 1;
785 len = *p;
787 if( nBufferMax <= len )
788 return 0;
790 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
791 lpBuffer[ len ] = 0;
793 TRACE("found -> %s\n", debugstr_w(lpBuffer));
795 return lang;
798 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
799 int nBufferMax, LANGID lang )
801 LPWSTR bufW;
802 LANGID r;
803 DWORD len;
805 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
806 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
807 if( r )
809 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
810 if( len <= nBufferMax )
811 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
812 lpBuffer, nBufferMax, NULL, NULL );
813 else
814 r = 0;
816 msi_free(bufW);
817 return r;
820 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
821 DWORD *pcchBuf)
823 char szProduct[GUID_SIZE];
825 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
827 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
828 return INSTALLSTATE_UNKNOWN;
830 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
833 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
834 DWORD *pcchBuf)
836 WCHAR szProduct[GUID_SIZE];
838 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
840 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
841 return INSTALLSTATE_UNKNOWN;
843 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
846 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
847 WORD wLanguageId, DWORD f)
849 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
850 uType, wLanguageId, f);
851 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
854 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
855 WORD wLanguageId, DWORD f)
857 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
858 uType, wLanguageId, f);
859 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
862 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
863 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
864 DWORD* pcchPathBuf )
866 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
867 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
868 pcchPathBuf);
869 return ERROR_CALL_NOT_IMPLEMENTED;
872 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
873 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
874 DWORD* pcchPathBuf )
876 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
877 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
878 pcchPathBuf);
879 return ERROR_CALL_NOT_IMPLEMENTED;
882 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
883 LPSTR szPath, DWORD *pcchPath, DWORD *pcchArgs )
885 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
886 return ERROR_CALL_NOT_IMPLEMENTED;
889 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
890 LPWSTR szPath, DWORD *pcchPath, DWORD *pcchArgs )
892 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
893 return ERROR_CALL_NOT_IMPLEMENTED;
896 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath,
897 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, BYTE* pbHashData,
898 DWORD* pcbHashData)
900 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath), dwFlags,
901 ppcCertContext, pbHashData, pcbHashData);
902 return ERROR_CALL_NOT_IMPLEMENTED;
905 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath,
906 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, BYTE* pbHashData,
907 DWORD* pcbHashData)
909 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath), dwFlags,
910 ppcCertContext, pbHashData, pcbHashData);
911 return ERROR_CALL_NOT_IMPLEMENTED;
914 UINT WINAPI MsiGetProductPropertyA( MSIHANDLE hProduct, LPCSTR szProperty,
915 LPSTR szValue, DWORD *pccbValue )
917 FIXME("%ld %s %p %p\n", hProduct, debugstr_a(szProperty), szValue, pccbValue);
918 return ERROR_CALL_NOT_IMPLEMENTED;
921 UINT WINAPI MsiGetProductPropertyW( MSIHANDLE hProduct, LPCWSTR szProperty,
922 LPWSTR szValue, DWORD *pccbValue )
924 FIXME("%ld %s %p %p\n", hProduct, debugstr_w(szProperty), szValue, pccbValue);
925 return ERROR_CALL_NOT_IMPLEMENTED;
928 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
930 UINT r;
931 LPWSTR szPack = NULL;
933 TRACE("%s\n", debugstr_a(szPackage) );
935 if( szPackage )
937 szPack = strdupAtoW( szPackage );
938 if( !szPack )
939 return ERROR_OUTOFMEMORY;
942 r = MsiVerifyPackageW( szPack );
944 msi_free( szPack );
946 return r;
949 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
951 MSIHANDLE handle;
952 UINT r;
954 TRACE("%s\n", debugstr_w(szPackage) );
956 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
957 MsiCloseHandle( handle );
959 return r;
962 static INSTALLSTATE WINAPI MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
963 awstring* lpPathBuf, DWORD* pcchBuf)
965 WCHAR squished_pc[GUID_SIZE], squished_comp[GUID_SIZE];
966 UINT rc;
967 HKEY hkey = 0;
968 LPWSTR path = NULL;
969 INSTALLSTATE r;
971 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
972 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
974 if( !szProduct || !szComponent )
975 return INSTALLSTATE_INVALIDARG;
976 if( lpPathBuf->str.w && !pcchBuf )
977 return INSTALLSTATE_INVALIDARG;
979 if (!squash_guid( szProduct, squished_pc ) ||
980 !squash_guid( szComponent, squished_comp ))
981 return INSTALLSTATE_INVALIDARG;
983 rc = MSIREG_OpenProductsKey( szProduct, &hkey, FALSE);
984 if( rc != ERROR_SUCCESS )
985 return INSTALLSTATE_UNKNOWN;
987 RegCloseKey(hkey);
989 rc = MSIREG_OpenComponentsKey( szComponent, &hkey, FALSE);
990 if( rc != ERROR_SUCCESS )
991 return INSTALLSTATE_UNKNOWN;
993 path = msi_reg_get_val_str( hkey, squished_pc );
994 RegCloseKey(hkey);
996 TRACE("found path of (%s:%s)(%s)\n", debugstr_w(szComponent),
997 debugstr_w(szProduct), debugstr_w(path));
999 if (!path)
1000 return INSTALLSTATE_UNKNOWN;
1002 if (path[0])
1003 r = INSTALLSTATE_LOCAL;
1004 else
1005 r = INSTALLSTATE_NOTUSED;
1007 msi_strcpy_to_awstring( path, lpPathBuf, pcchBuf );
1009 msi_free( path );
1010 return r;
1013 /******************************************************************
1014 * MsiGetComponentPathW [MSI.@]
1016 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
1017 LPWSTR lpPathBuf, DWORD* pcchBuf)
1019 awstring path;
1021 path.unicode = TRUE;
1022 path.str.w = lpPathBuf;
1024 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
1027 /******************************************************************
1028 * MsiGetComponentPathA [MSI.@]
1030 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
1031 LPSTR lpPathBuf, DWORD* pcchBuf)
1033 LPWSTR szwProduct, szwComponent = NULL;
1034 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
1035 awstring path;
1037 szwProduct = strdupAtoW( szProduct );
1038 if( szProduct && !szwProduct)
1039 goto end;
1041 szwComponent = strdupAtoW( szComponent );
1042 if( szComponent && !szwComponent )
1043 goto end;
1045 path.unicode = FALSE;
1046 path.str.a = lpPathBuf;
1048 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
1050 end:
1051 msi_free( szwProduct );
1052 msi_free( szwComponent );
1054 return r;
1057 /******************************************************************
1058 * MsiQueryFeatureStateA [MSI.@]
1060 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
1062 LPWSTR szwProduct = NULL, szwFeature= NULL;
1063 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
1065 szwProduct = strdupAtoW( szProduct );
1066 if ( szProduct && !szwProduct )
1067 goto end;
1069 szwFeature = strdupAtoW( szFeature );
1070 if ( szFeature && !szwFeature )
1071 goto end;
1073 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
1075 end:
1076 msi_free( szwProduct);
1077 msi_free( szwFeature);
1079 return rc;
1082 /******************************************************************
1083 * MsiQueryFeatureStateW [MSI.@]
1085 * Checks the state of a feature
1087 * PARAMS
1088 * szProduct [I] Product's GUID string
1089 * szFeature [I] Feature's GUID string
1091 * RETURNS
1092 * INSTALLSTATE_LOCAL Feature is installed and useable
1093 * INSTALLSTATE_ABSENT Feature is absent
1094 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
1095 * INSTALLSTATE_UNKNOWN An error occurred
1096 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
1099 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
1101 WCHAR squishProduct[33], comp[GUID_SIZE];
1102 GUID guid;
1103 LPWSTR components, p, parent_feature;
1104 UINT rc;
1105 HKEY hkey;
1106 INSTALLSTATE r;
1107 BOOL missing = FALSE;
1109 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
1111 if (!szProduct || !szFeature)
1112 return INSTALLSTATE_INVALIDARG;
1114 /* HACK: Pretend that the VBAFiles feature isn't present.
1115 VBAFiles seems to depend on Internet Explorer, and displays
1116 an error at Project startup "This feature depends on Internet Explorer..." */
1117 if (1) {
1118 static const WCHAR p[] = {
1119 '{','9','0','3','B','0','4','0','9','-',
1120 '6','0','0','0','-','1','1','D','3','-',
1121 '8','C','F','E','-','0','1','5','0','0',
1122 '4','8','3','8','3','C','9','}',0};
1123 static const WCHAR f[] = {
1124 'V','B','A','F','i','l','e','s',0};
1125 if ( !lstrcmpW(p, szProduct) && !lstrcmpW(f, szFeature))
1126 return INSTALLSTATE_UNKNOWN;
1129 if (!squash_guid( szProduct, squishProduct ))
1130 return INSTALLSTATE_INVALIDARG;
1132 /* check that it's installed at all */
1133 rc = MSIREG_OpenUserFeaturesKey(szProduct, &hkey, FALSE);
1134 if (rc != ERROR_SUCCESS)
1135 return INSTALLSTATE_UNKNOWN;
1137 parent_feature = msi_reg_get_val_str( hkey, szFeature );
1138 RegCloseKey(hkey);
1140 if (!parent_feature)
1141 return INSTALLSTATE_UNKNOWN;
1143 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
1144 msi_free(parent_feature);
1145 if (r == INSTALLSTATE_ABSENT)
1146 return r;
1148 /* now check if it's complete or advertised */
1149 rc = MSIREG_OpenFeaturesKey(szProduct, &hkey, FALSE);
1150 if (rc != ERROR_SUCCESS)
1151 return INSTALLSTATE_UNKNOWN;
1153 components = msi_reg_get_val_str( hkey, szFeature );
1154 RegCloseKey(hkey);
1156 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
1158 if (!components)
1160 ERR("components missing %s %s\n",
1161 debugstr_w(szProduct), debugstr_w(szFeature));
1162 return INSTALLSTATE_UNKNOWN;
1165 for( p = components; *p != 2 ; p += 20)
1167 if (!decode_base85_guid( p, &guid ))
1169 ERR("%s\n", debugstr_w(p));
1170 break;
1172 StringFromGUID2(&guid, comp, GUID_SIZE);
1173 r = MsiGetComponentPathW(szProduct, comp, NULL, 0);
1174 TRACE("component %s state %d\n", debugstr_guid(&guid), r);
1175 switch (r)
1177 case INSTALLSTATE_NOTUSED:
1178 case INSTALLSTATE_LOCAL:
1179 case INSTALLSTATE_SOURCE:
1180 break;
1181 default:
1182 missing = TRUE;
1186 TRACE("%s %s -> %d\n", debugstr_w(szProduct), debugstr_w(szFeature), r);
1187 msi_free(components);
1189 if (missing)
1190 return INSTALLSTATE_ADVERTISED;
1192 return INSTALLSTATE_LOCAL;
1195 /******************************************************************
1196 * MsiGetFileVersionA [MSI.@]
1198 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
1199 DWORD* pcchVersionBuf, LPSTR lpLangBuf, DWORD* pcchLangBuf)
1201 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
1202 UINT ret = ERROR_OUTOFMEMORY;
1204 if( szFilePath )
1206 szwFilePath = strdupAtoW( szFilePath );
1207 if( !szwFilePath )
1208 goto end;
1211 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
1213 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
1214 if( !lpwVersionBuff )
1215 goto end;
1218 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
1220 lpwLangBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
1221 if( !lpwLangBuff )
1222 goto end;
1225 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
1226 lpwLangBuff, pcchLangBuf);
1228 if( lpwVersionBuff )
1229 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
1230 lpVersionBuf, *pcchVersionBuf, NULL, NULL);
1231 if( lpwLangBuff )
1232 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
1233 lpLangBuf, *pcchLangBuf, NULL, NULL);
1235 end:
1236 msi_free(szwFilePath);
1237 msi_free(lpwVersionBuff);
1238 msi_free(lpwLangBuff);
1240 return ret;
1243 /******************************************************************
1244 * MsiGetFileVersionW [MSI.@]
1246 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
1247 DWORD* pcchVersionBuf, LPWSTR lpLangBuf, DWORD* pcchLangBuf)
1249 static const WCHAR szVersionResource[] = {'\\',0};
1250 static const WCHAR szVersionFormat[] = {
1251 '%','d','.','%','d','.','%','d','.','%','d',0};
1252 static const WCHAR szLangFormat[] = {'%','d',0};
1253 UINT ret = 0;
1254 DWORD dwVerLen;
1255 LPVOID lpVer = NULL;
1256 VS_FIXEDFILEINFO *ffi;
1257 UINT puLen;
1258 WCHAR tmp[32];
1260 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
1261 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
1262 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
1264 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
1265 if( !dwVerLen )
1266 return GetLastError();
1268 lpVer = msi_alloc(dwVerLen);
1269 if( !lpVer )
1271 ret = ERROR_OUTOFMEMORY;
1272 goto end;
1275 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
1277 ret = GetLastError();
1278 goto end;
1280 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
1282 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
1283 (puLen > 0) )
1285 wsprintfW(tmp, szVersionFormat,
1286 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
1287 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
1288 lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
1289 *pcchVersionBuf = lstrlenW(lpVersionBuf);
1291 else
1293 *lpVersionBuf = 0;
1294 *pcchVersionBuf = 0;
1298 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
1300 DWORD lang = GetUserDefaultLangID();
1302 FIXME("Retrieve language from file\n");
1303 wsprintfW(tmp, szLangFormat, lang);
1304 lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
1305 *pcchLangBuf = lstrlenW(lpLangBuf);
1308 end:
1309 msi_free(lpVer);
1310 return ret;
1313 /***********************************************************************
1314 * MsiGetFeatureUsageW [MSI.@]
1316 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
1317 DWORD* pdwUseCount, WORD* pwDateUsed )
1319 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
1320 pdwUseCount, pwDateUsed);
1321 return ERROR_CALL_NOT_IMPLEMENTED;
1324 /***********************************************************************
1325 * MsiGetFeatureUsageA [MSI.@]
1327 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
1328 DWORD* pdwUseCount, WORD* pwDateUsed )
1330 LPWSTR prod = NULL, feat = NULL;
1331 UINT ret = ERROR_OUTOFMEMORY;
1333 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
1334 pdwUseCount, pwDateUsed);
1336 prod = strdupAtoW( szProduct );
1337 if (szProduct && !prod)
1338 goto end;
1340 feat = strdupAtoW( szFeature );
1341 if (szFeature && !feat)
1342 goto end;
1344 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
1346 end:
1347 msi_free( prod );
1348 msi_free( feat );
1350 return ret;
1353 /***********************************************************************
1354 * MsiUseFeatureExW [MSI.@]
1356 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
1357 DWORD dwInstallMode, DWORD dwReserved )
1359 INSTALLSTATE state;
1361 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
1362 dwInstallMode, dwReserved);
1364 state = MsiQueryFeatureStateW( szProduct, szFeature );
1366 if (dwReserved)
1367 return INSTALLSTATE_INVALIDARG;
1369 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
1371 FIXME("mark product %s feature %s as used\n",
1372 debugstr_w(szProduct), debugstr_w(szFeature) );
1375 return state;
1378 /***********************************************************************
1379 * MsiUseFeatureExA [MSI.@]
1381 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
1382 DWORD dwInstallMode, DWORD dwReserved )
1384 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
1385 LPWSTR prod = NULL, feat = NULL;
1387 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
1388 dwInstallMode, dwReserved);
1390 prod = strdupAtoW( szProduct );
1391 if (szProduct && !prod)
1392 goto end;
1394 feat = strdupAtoW( szFeature );
1395 if (szFeature && !feat)
1396 goto end;
1398 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
1400 end:
1401 msi_free( prod );
1402 msi_free( feat );
1404 return ret;
1407 /***********************************************************************
1408 * MsiUseFeatureW [MSI.@]
1410 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
1412 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
1415 /***********************************************************************
1416 * MsiUseFeatureA [MSI.@]
1418 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
1420 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
1423 /***********************************************************************
1424 * MSI_ProvideQualifiedComponentEx [internal]
1426 static UINT WINAPI MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
1427 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR szProduct,
1428 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
1429 DWORD* pcchPathBuf)
1431 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
1432 feature[MAX_FEATURE_CHARS+1];
1433 LPWSTR info;
1434 HKEY hkey;
1435 DWORD sz;
1436 UINT rc;
1438 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
1439 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
1440 Unused1, Unused2, lpPathBuf, pcchPathBuf);
1442 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
1443 if (rc != ERROR_SUCCESS)
1444 return ERROR_INDEX_ABSENT;
1446 info = msi_reg_get_val_str( hkey, szQualifier );
1447 RegCloseKey(hkey);
1449 if (!info)
1450 return ERROR_INDEX_ABSENT;
1452 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
1454 if (!szProduct)
1455 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
1456 else
1457 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
1459 msi_free( info );
1461 if (rc != INSTALLSTATE_LOCAL)
1462 return ERROR_FILE_NOT_FOUND;
1464 return ERROR_SUCCESS;
1467 /***********************************************************************
1468 * MsiProvideQualifiedComponentExW [MSI.@]
1470 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
1471 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR szProduct,
1472 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
1473 DWORD* pcchPathBuf)
1475 awstring path;
1477 path.unicode = TRUE;
1478 path.str.w = lpPathBuf;
1480 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
1481 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
1484 /***********************************************************************
1485 * MsiProvideQualifiedComponentExA [MSI.@]
1487 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
1488 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR szProduct,
1489 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
1490 DWORD* pcchPathBuf)
1492 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
1493 UINT r = ERROR_OUTOFMEMORY;
1494 awstring path;
1496 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
1497 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
1498 Unused1, Unused2, lpPathBuf, pcchPathBuf);
1500 szwComponent = strdupAtoW( szComponent );
1501 if (szComponent && !szwComponent)
1502 goto end;
1504 szwQualifier = strdupAtoW( szQualifier );
1505 if (szQualifier && !szwQualifier)
1506 goto end;
1508 szwProduct = strdupAtoW( szProduct );
1509 if (szProduct && !szwProduct)
1510 goto end;
1512 path.unicode = FALSE;
1513 path.str.a = lpPathBuf;
1515 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
1516 dwInstallMode, szwProduct, Unused1,
1517 Unused2, &path, pcchPathBuf);
1518 end:
1519 msi_free(szwProduct);
1520 msi_free(szwComponent);
1521 msi_free(szwQualifier);
1523 return r;
1526 /***********************************************************************
1527 * MsiProvideQualifiedComponentW [MSI.@]
1529 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
1530 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
1531 DWORD* pcchPathBuf)
1533 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
1534 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
1537 /***********************************************************************
1538 * MsiProvideQualifiedComponentA [MSI.@]
1540 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
1541 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
1542 DWORD* pcchPathBuf)
1544 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
1545 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
1548 /***********************************************************************
1549 * MSI_GetUserInfo [internal]
1551 static USERINFOSTATE WINAPI MSI_GetUserInfo(LPCWSTR szProduct,
1552 awstring *lpUserNameBuf, DWORD* pcchUserNameBuf,
1553 awstring *lpOrgNameBuf, DWORD* pcchOrgNameBuf,
1554 awstring *lpSerialBuf, DWORD* pcchSerialBuf)
1556 HKEY hkey;
1557 LPWSTR user, org, serial;
1558 UINT r;
1559 USERINFOSTATE state;
1561 TRACE("%s %p %p %p %p %p %p\n",debugstr_w(szProduct), lpUserNameBuf,
1562 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
1563 pcchSerialBuf);
1565 if (!szProduct)
1566 return USERINFOSTATE_INVALIDARG;
1568 r = MSIREG_OpenUninstallKey(szProduct, &hkey, FALSE);
1569 if (r != ERROR_SUCCESS)
1570 return USERINFOSTATE_UNKNOWN;
1572 user = msi_reg_get_val_str( hkey, INSTALLPROPERTY_REGOWNERW );
1573 org = msi_reg_get_val_str( hkey, INSTALLPROPERTY_REGCOMPANYW );
1574 serial = msi_reg_get_val_str( hkey, INSTALLPROPERTY_PRODUCTIDW );
1576 RegCloseKey(hkey);
1578 state = USERINFOSTATE_PRESENT;
1580 if (user)
1582 r = msi_strcpy_to_awstring( user, lpUserNameBuf, pcchUserNameBuf );
1583 if (r == ERROR_MORE_DATA)
1584 state = USERINFOSTATE_MOREDATA;
1586 else
1587 state = USERINFOSTATE_ABSENT;
1588 if (org)
1590 r = msi_strcpy_to_awstring( org, lpOrgNameBuf, pcchOrgNameBuf );
1591 if (r == ERROR_MORE_DATA && state == USERINFOSTATE_PRESENT)
1592 state = USERINFOSTATE_MOREDATA;
1594 /* msdn states: The user information is considered to be present even in the absence of a company name. */
1595 if (serial)
1597 r = msi_strcpy_to_awstring( serial, lpSerialBuf, pcchSerialBuf );
1598 if (r == ERROR_MORE_DATA && state == USERINFOSTATE_PRESENT)
1599 state = USERINFOSTATE_MOREDATA;
1601 else
1602 state = USERINFOSTATE_ABSENT;
1604 msi_free( user );
1605 msi_free( org );
1606 msi_free( serial );
1608 return state;
1611 /***********************************************************************
1612 * MsiGetUserInfoW [MSI.@]
1614 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
1615 LPWSTR lpUserNameBuf, DWORD* pcchUserNameBuf,
1616 LPWSTR lpOrgNameBuf, DWORD* pcchOrgNameBuf,
1617 LPWSTR lpSerialBuf, DWORD* pcchSerialBuf)
1619 awstring user, org, serial;
1621 user.unicode = TRUE;
1622 user.str.w = lpUserNameBuf;
1623 org.unicode = TRUE;
1624 org.str.w = lpOrgNameBuf;
1625 serial.unicode = TRUE;
1626 serial.str.w = lpSerialBuf;
1628 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
1629 &org, pcchOrgNameBuf,
1630 &serial, pcchSerialBuf );
1633 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
1634 LPSTR lpUserNameBuf, DWORD* pcchUserNameBuf,
1635 LPSTR lpOrgNameBuf, DWORD* pcchOrgNameBuf,
1636 LPSTR lpSerialBuf, DWORD* pcchSerialBuf)
1638 awstring user, org, serial;
1639 LPWSTR prod;
1640 UINT r;
1642 prod = strdupAtoW( szProduct );
1643 if (szProduct && !prod)
1644 return ERROR_OUTOFMEMORY;
1646 user.unicode = FALSE;
1647 user.str.a = lpUserNameBuf;
1648 org.unicode = FALSE;
1649 org.str.a = lpOrgNameBuf;
1650 serial.unicode = FALSE;
1651 serial.str.a = lpSerialBuf;
1653 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
1654 &org, pcchOrgNameBuf,
1655 &serial, pcchSerialBuf );
1657 msi_free( prod );
1659 return r;
1662 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
1664 MSIHANDLE handle;
1665 UINT rc;
1666 MSIPACKAGE *package;
1667 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
1669 TRACE("(%s)\n",debugstr_w(szProduct));
1671 rc = MsiOpenProductW(szProduct,&handle);
1672 if (rc != ERROR_SUCCESS)
1673 return ERROR_INVALID_PARAMETER;
1675 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
1676 rc = ACTION_PerformUIAction(package, szFirstRun);
1677 msiobj_release( &package->hdr );
1679 MsiCloseHandle(handle);
1681 return rc;
1684 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
1686 MSIHANDLE handle;
1687 UINT rc;
1688 MSIPACKAGE *package;
1689 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
1691 TRACE("(%s)\n",debugstr_a(szProduct));
1693 rc = MsiOpenProductA(szProduct,&handle);
1694 if (rc != ERROR_SUCCESS)
1695 return ERROR_INVALID_PARAMETER;
1697 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
1698 rc = ACTION_PerformUIAction(package, szFirstRun);
1699 msiobj_release( &package->hdr );
1701 MsiCloseHandle(handle);
1703 return rc;
1706 /***********************************************************************
1707 * MsiConfigureFeatureA [MSI.@]
1709 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
1711 LPWSTR prod, feat = NULL;
1712 UINT r = ERROR_OUTOFMEMORY;
1714 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
1716 prod = strdupAtoW( szProduct );
1717 if (szProduct && !prod)
1718 goto end;
1720 feat = strdupAtoW( szFeature );
1721 if (szFeature && !feat)
1722 goto end;
1724 r = MsiConfigureFeatureW(prod, feat, eInstallState);
1726 end:
1727 msi_free(feat);
1728 msi_free(prod);
1730 return r;
1733 /***********************************************************************
1734 * MsiConfigureFeatureW [MSI.@]
1736 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
1738 static const WCHAR szCostInit[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
1739 MSIPACKAGE *package = NULL;
1740 UINT r;
1741 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
1742 DWORD sz;
1744 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
1746 if (!szProduct || !szFeature)
1747 return ERROR_INVALID_PARAMETER;
1749 switch (eInstallState)
1751 case INSTALLSTATE_DEFAULT:
1752 /* FIXME: how do we figure out the default location? */
1753 eInstallState = INSTALLSTATE_LOCAL;
1754 break;
1755 case INSTALLSTATE_LOCAL:
1756 case INSTALLSTATE_SOURCE:
1757 case INSTALLSTATE_ABSENT:
1758 case INSTALLSTATE_ADVERTISED:
1759 break;
1760 default:
1761 return ERROR_INVALID_PARAMETER;
1764 r = MSI_OpenProductW( szProduct, &package );
1765 if (r != ERROR_SUCCESS)
1766 return r;
1768 sz = sizeof(sourcepath);
1769 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
1770 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
1772 sz = sizeof(filename);
1773 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
1774 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
1776 lstrcatW( sourcepath, filename );
1778 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
1780 r = ACTION_PerformUIAction( package, szCostInit );
1781 if (r != ERROR_SUCCESS)
1782 goto end;
1784 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
1785 if (r != ERROR_SUCCESS)
1786 goto end;
1788 r = MSI_InstallPackage( package, sourcepath, NULL );
1790 end:
1791 msiobj_release( &package->hdr );
1793 return r;
1796 /***********************************************************************
1797 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
1799 * Notes: undocumented
1801 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
1803 WCHAR path[MAX_PATH];
1805 TRACE("%d\n", dwReserved);
1807 if (dwReserved)
1809 FIXME("dwReserved=%d\n", dwReserved);
1810 return ERROR_INVALID_PARAMETER;
1813 if (!GetWindowsDirectoryW(path, MAX_PATH))
1814 return ERROR_FUNCTION_FAILED;
1816 lstrcatW(path, installerW);
1818 if (!CreateDirectoryW(path, NULL))
1819 return ERROR_FUNCTION_FAILED;
1821 return ERROR_SUCCESS;
1824 /***********************************************************************
1825 * MsiGetShortcutTargetA [MSI.@]
1827 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
1828 LPSTR szProductCode, LPSTR szFeatureId,
1829 LPSTR szComponentCode )
1831 LPWSTR target;
1832 const int len = MAX_FEATURE_CHARS+1;
1833 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
1834 UINT r;
1836 target = strdupAtoW( szShortcutTarget );
1837 if (szShortcutTarget && !target )
1838 return ERROR_OUTOFMEMORY;
1839 product[0] = 0;
1840 feature[0] = 0;
1841 component[0] = 0;
1842 r = MsiGetShortcutTargetW( target, product, feature, component );
1843 msi_free( target );
1844 if (r == ERROR_SUCCESS)
1846 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
1847 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
1848 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
1850 return r;
1853 /***********************************************************************
1854 * MsiGetShortcutTargetW [MSI.@]
1856 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
1857 LPWSTR szProductCode, LPWSTR szFeatureId,
1858 LPWSTR szComponentCode )
1860 IShellLinkDataList *dl = NULL;
1861 IPersistFile *pf = NULL;
1862 LPEXP_DARWIN_LINK darwin = NULL;
1863 HRESULT r, init;
1865 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
1866 szProductCode, szFeatureId, szComponentCode );
1868 init = CoInitialize(NULL);
1870 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
1871 &IID_IPersistFile, (LPVOID*) &pf );
1872 if( SUCCEEDED( r ) )
1874 r = IPersistFile_Load( pf, szShortcutTarget,
1875 STGM_READ | STGM_SHARE_DENY_WRITE );
1876 if( SUCCEEDED( r ) )
1878 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
1879 (LPVOID*) &dl );
1880 if( SUCCEEDED( r ) )
1882 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
1883 (LPVOID) &darwin );
1884 IShellLinkDataList_Release( dl );
1887 IPersistFile_Release( pf );
1890 if (SUCCEEDED(init))
1891 CoUninitialize();
1893 TRACE("darwin = %p\n", darwin);
1895 if (darwin)
1897 DWORD sz;
1898 UINT ret;
1900 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
1901 szProductCode, szFeatureId, szComponentCode, &sz );
1902 LocalFree( darwin );
1903 return ret;
1906 return ERROR_FUNCTION_FAILED;
1909 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
1910 DWORD dwReinstallMode )
1912 MSIPACKAGE* package = NULL;
1913 UINT r;
1914 WCHAR sourcepath[MAX_PATH];
1915 WCHAR filename[MAX_PATH];
1916 static const WCHAR szLogVerbose[] = {
1917 ' ','L','O','G','V','E','R','B','O','S','E',0 };
1918 static const WCHAR szInstalled[] = { 'I','n','s','t','a','l','l','e','d',0};
1919 static const WCHAR szReinstall[] = {'R','E','I','N','S','T','A','L','L',0};
1920 static const WCHAR szReinstallMode[] = {'R','E','I','N','S','T','A','L','L','M','O','D','E',0};
1921 static const WCHAR szOne[] = {'1',0};
1922 WCHAR reinstallmode[11];
1923 LPWSTR ptr;
1924 DWORD sz;
1926 FIXME("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
1927 dwReinstallMode);
1929 ptr = reinstallmode;
1931 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
1932 *ptr++ = 'p';
1933 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
1934 *ptr++ = 'o';
1935 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
1936 *ptr++ = 'w';
1937 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
1938 *ptr++ = 'd';
1939 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
1940 *ptr++ = 'c';
1941 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
1942 *ptr++ = 'a';
1943 if (dwReinstallMode & REINSTALLMODE_USERDATA)
1944 *ptr++ = 'u';
1945 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
1946 *ptr++ = 'm';
1947 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
1948 *ptr++ = 's';
1949 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
1950 *ptr++ = 'v';
1951 *ptr = 0;
1953 sz = sizeof(sourcepath);
1954 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
1955 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
1957 sz = sizeof(filename);
1958 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
1959 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
1961 lstrcatW( sourcepath, filename );
1963 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
1964 r = MSI_OpenPackageW( sourcepath, &package );
1965 else
1966 r = MSI_OpenProductW( szProduct, &package );
1968 if (r != ERROR_SUCCESS)
1969 return r;
1971 MSI_SetPropertyW( package, szReinstallMode, reinstallmode );
1972 MSI_SetPropertyW( package, szInstalled, szOne );
1973 MSI_SetPropertyW( package, szLogVerbose, szOne );
1974 MSI_SetPropertyW( package, szReinstall, szFeature );
1976 r = MSI_InstallPackage( package, sourcepath, NULL );
1978 msiobj_release( &package->hdr );
1980 return r;
1983 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
1984 DWORD dwReinstallMode )
1986 LPWSTR wszProduct;
1987 LPWSTR wszFeature;
1988 UINT rc;
1990 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
1991 dwReinstallMode);
1993 wszProduct = strdupAtoW(szProduct);
1994 wszFeature = strdupAtoW(szFeature);
1996 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
1998 msi_free(wszProduct);
1999 msi_free(wszFeature);
2000 return rc;
2003 typedef struct
2005 unsigned int i[2];
2006 unsigned int buf[4];
2007 unsigned char in[64];
2008 unsigned char digest[16];
2009 } MD5_CTX;
2011 extern VOID WINAPI MD5Init( MD5_CTX *);
2012 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
2013 extern VOID WINAPI MD5Final( MD5_CTX *);
2015 /***********************************************************************
2016 * MsiGetFileHashW [MSI.@]
2018 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
2019 PMSIFILEHASHINFO pHash )
2021 HANDLE handle, mapping;
2022 void *p;
2023 DWORD length;
2024 UINT r = ERROR_FUNCTION_FAILED;
2026 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
2028 if (dwOptions)
2029 return ERROR_INVALID_PARAMETER;
2030 if (!pHash)
2031 return ERROR_INVALID_PARAMETER;
2032 if (pHash->dwFileHashInfoSize < sizeof *pHash)
2033 return ERROR_INVALID_PARAMETER;
2035 handle = CreateFileW( szFilePath, GENERIC_READ,
2036 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
2037 if (handle == INVALID_HANDLE_VALUE)
2038 return ERROR_FILE_NOT_FOUND;
2040 length = GetFileSize( handle, NULL );
2042 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
2043 if (mapping)
2045 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
2046 if (p)
2048 MD5_CTX ctx;
2050 MD5Init( &ctx );
2051 MD5Update( &ctx, p, length );
2052 MD5Final( &ctx );
2053 UnmapViewOfFile( p );
2055 memcpy( pHash->dwData, &ctx.digest, sizeof pHash->dwData );
2056 r = ERROR_SUCCESS;
2058 CloseHandle( mapping );
2060 CloseHandle( handle );
2062 return r;
2065 /***********************************************************************
2066 * MsiGetFileHashA [MSI.@]
2068 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
2069 PMSIFILEHASHINFO pHash )
2071 LPWSTR file;
2072 UINT r;
2074 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
2076 file = strdupAtoW( szFilePath );
2077 if (szFilePath && !file)
2078 return ERROR_OUTOFMEMORY;
2080 r = MsiGetFileHashW( file, dwOptions, pHash );
2081 msi_free( file );
2082 return r;
2085 /***********************************************************************
2086 * MsiAdvertiseScriptW [MSI.@]
2088 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
2089 PHKEY phRegData, BOOL fRemoveItems )
2091 FIXME("%s %08x %p %d\n",
2092 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
2093 return ERROR_CALL_NOT_IMPLEMENTED;
2096 /***********************************************************************
2097 * MsiAdvertiseScriptA [MSI.@]
2099 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
2100 PHKEY phRegData, BOOL fRemoveItems )
2102 FIXME("%s %08x %p %d\n",
2103 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
2104 return ERROR_CALL_NOT_IMPLEMENTED;