msi: If the user product key exists, the product's state is advertised.
[wine.git] / dlls / msi / msi.c
blob7240ea4fd64f3ec927831b1a7ea99d6bcc58dc6a
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002,2003,2004,2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #define COBJMACROS
24 #define NONAMELESSUNION
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winnls.h"
30 #include "shlwapi.h"
31 #include "wine/debug.h"
32 #include "msi.h"
33 #include "msidefs.h"
34 #include "msiquery.h"
35 #include "msipriv.h"
36 #include "wincrypt.h"
37 #include "winver.h"
38 #include "winuser.h"
39 #include "shlobj.h"
40 #include "shobjidl.h"
41 #include "objidl.h"
42 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msi);
46 static const WCHAR installerW[] = {'\\','I','n','s','t','a','l','l','e','r',0};
48 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
50 UINT r;
51 LPWSTR szwProd = NULL;
53 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
55 if( szProduct )
57 szwProd = strdupAtoW( szProduct );
58 if( !szwProd )
59 return ERROR_OUTOFMEMORY;
62 r = MsiOpenProductW( szwProd, phProduct );
64 msi_free( szwProd );
66 return r;
69 static UINT MSI_OpenProductW( LPCWSTR szProduct, MSIPACKAGE **ppackage )
71 LPWSTR path = NULL;
72 UINT r;
73 HKEY hKeyProduct = NULL;
74 DWORD count, type;
76 TRACE("%s %p\n", debugstr_w(szProduct), ppackage );
78 r = MSIREG_OpenUninstallKey(szProduct,&hKeyProduct,FALSE);
79 if( r != ERROR_SUCCESS )
81 r = ERROR_UNKNOWN_PRODUCT;
82 goto end;
85 /* find the size of the path */
86 type = count = 0;
87 r = RegQueryValueExW( hKeyProduct, INSTALLPROPERTY_LOCALPACKAGEW,
88 NULL, &type, NULL, &count );
89 if( r != ERROR_SUCCESS )
91 r = ERROR_UNKNOWN_PRODUCT;
92 goto end;
95 /* now alloc and fetch the path of the database to open */
96 path = msi_alloc( count );
97 if( !path )
98 goto end;
100 r = RegQueryValueExW( hKeyProduct, INSTALLPROPERTY_LOCALPACKAGEW,
101 NULL, &type, (LPBYTE) path, &count );
102 if( r != ERROR_SUCCESS )
104 r = ERROR_UNKNOWN_PRODUCT;
105 goto end;
108 r = MSI_OpenPackageW( path, ppackage );
110 end:
111 msi_free( path );
112 if( hKeyProduct )
113 RegCloseKey( hKeyProduct );
115 return r;
118 UINT WINAPI MsiOpenProductW( LPCWSTR szProduct, MSIHANDLE *phProduct )
120 MSIPACKAGE *package = NULL;
121 UINT r;
123 r = MSI_OpenProductW( szProduct, &package );
124 if( r == ERROR_SUCCESS )
126 *phProduct = alloc_msihandle( &package->hdr );
127 if (! *phProduct)
128 r = ERROR_NOT_ENOUGH_MEMORY;
129 msiobj_release( &package->hdr );
131 return r;
134 UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
135 LPCSTR szTransforms, LANGID lgidLanguage)
137 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath),
138 debugstr_a(szScriptfilePath), debugstr_a(szTransforms), lgidLanguage);
139 return ERROR_CALL_NOT_IMPLEMENTED;
142 UINT WINAPI MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
143 LPCWSTR szTransforms, LANGID lgidLanguage)
145 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath),
146 debugstr_w(szScriptfilePath), debugstr_w(szTransforms), lgidLanguage);
147 return ERROR_CALL_NOT_IMPLEMENTED;
150 UINT WINAPI MsiAdvertiseProductExA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
151 LPCSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
153 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath),
154 debugstr_a(szScriptfilePath), debugstr_a(szTransforms),
155 lgidLanguage, dwPlatform, dwOptions);
156 return ERROR_CALL_NOT_IMPLEMENTED;
159 UINT WINAPI MsiAdvertiseProductExW( LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
160 LPCWSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
162 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath),
163 debugstr_w(szScriptfilePath), debugstr_w(szTransforms),
164 lgidLanguage, dwPlatform, dwOptions);
165 return ERROR_CALL_NOT_IMPLEMENTED;
168 UINT WINAPI MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)
170 LPWSTR szwPath = NULL, szwCommand = NULL;
171 UINT r = ERROR_OUTOFMEMORY;
173 TRACE("%s %s\n",debugstr_a(szPackagePath), debugstr_a(szCommandLine));
175 if( szPackagePath )
177 szwPath = strdupAtoW( szPackagePath );
178 if( !szwPath )
179 goto end;
182 if( szCommandLine )
184 szwCommand = strdupAtoW( szCommandLine );
185 if( !szwCommand )
186 goto end;
189 r = MsiInstallProductW( szwPath, szwCommand );
191 end:
192 msi_free( szwPath );
193 msi_free( szwCommand );
195 return r;
198 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
200 MSIPACKAGE *package = NULL;
201 UINT r;
203 TRACE("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
205 r = MSI_OpenPackageW( szPackagePath, &package );
206 if (r == ERROR_SUCCESS)
208 r = MSI_InstallPackage( package, szPackagePath, szCommandLine );
209 msiobj_release( &package->hdr );
212 return r;
215 UINT WINAPI MsiReinstallProductA(LPCSTR szProduct, DWORD dwReinstallMode)
217 FIXME("%s %08x\n", debugstr_a(szProduct), dwReinstallMode);
218 return ERROR_CALL_NOT_IMPLEMENTED;
221 UINT WINAPI MsiReinstallProductW(LPCWSTR szProduct, DWORD dwReinstallMode)
223 FIXME("%s %08x\n", debugstr_w(szProduct), dwReinstallMode);
224 return ERROR_CALL_NOT_IMPLEMENTED;
227 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
228 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
230 LPWSTR patch_package = NULL;
231 LPWSTR install_package = NULL;
232 LPWSTR command_line = NULL;
233 UINT r = ERROR_OUTOFMEMORY;
235 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
236 eInstallType, debugstr_a(szCommandLine));
238 if (szPatchPackage && !(patch_package = strdupAtoW(szPatchPackage)))
239 goto done;
241 if (szInstallPackage && !(install_package = strdupAtoW(szInstallPackage)))
242 goto done;
244 if (szCommandLine && !(command_line = strdupAtoW(szCommandLine)))
245 goto done;
247 r = MsiApplyPatchW(patch_package, install_package, eInstallType, command_line);
249 done:
250 msi_free(patch_package);
251 msi_free(install_package);
252 msi_free(command_line);
254 return r;
257 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
258 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
260 MSIHANDLE patch, info;
261 UINT r, type;
262 DWORD size = 0;
263 LPCWSTR cmd_ptr = szCommandLine;
264 LPWSTR beg, end;
265 LPWSTR cmd = NULL, codes = NULL;
267 static const WCHAR space[] = {' ',0};
268 static const WCHAR patcheq[] = {'P','A','T','C','H','=',0};
269 static WCHAR empty[] = {0};
271 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
272 eInstallType, debugstr_w(szCommandLine));
274 if (szInstallPackage || eInstallType == INSTALLTYPE_NETWORK_IMAGE ||
275 eInstallType == INSTALLTYPE_SINGLE_INSTANCE)
277 FIXME("Only reading target products from patch\n");
278 return ERROR_CALL_NOT_IMPLEMENTED;
281 r = MsiOpenDatabaseW(szPatchPackage, MSIDBOPEN_READONLY, &patch);
282 if (r != ERROR_SUCCESS)
283 return r;
285 r = MsiGetSummaryInformationW(patch, NULL, 0, &info);
286 if (r != ERROR_SUCCESS)
287 goto done;
289 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, empty, &size);
290 if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
292 ERR("Failed to read product codes from patch\n");
293 goto done;
296 codes = msi_alloc(++size * sizeof(WCHAR));
297 if (!codes)
299 r = ERROR_OUTOFMEMORY;
300 goto done;
303 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, codes, &size);
304 if (r != ERROR_SUCCESS)
305 goto done;
307 if (!szCommandLine)
308 cmd_ptr = empty;
310 size = lstrlenW(cmd_ptr) + lstrlenW(patcheq) + lstrlenW(szPatchPackage) + 1;
311 cmd = msi_alloc(size * sizeof(WCHAR));
312 if (!cmd)
314 r = ERROR_OUTOFMEMORY;
315 goto done;
318 lstrcpyW(cmd, cmd_ptr);
319 if (szCommandLine) lstrcatW(cmd, space);
320 lstrcatW(cmd, patcheq);
321 lstrcatW(cmd, szPatchPackage);
323 beg = codes;
324 while ((end = strchrW(beg, '}')))
326 *(end + 1) = '\0';
328 r = MsiConfigureProductExW(beg, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
329 if (r != ERROR_SUCCESS)
330 goto done;
332 beg = end + 2;
335 done:
336 msi_free(cmd);
337 msi_free(codes);
339 MsiCloseHandle(info);
340 MsiCloseHandle(patch);
342 return r;
345 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
346 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
348 MSIPACKAGE* package = NULL;
349 UINT r;
350 DWORD sz;
351 WCHAR sourcepath[MAX_PATH];
352 WCHAR filename[MAX_PATH];
353 static const WCHAR szInstalled[] = {
354 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
355 LPWSTR commandline;
357 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
358 debugstr_w(szCommandLine));
360 if (eInstallState != INSTALLSTATE_LOCAL &&
361 eInstallState != INSTALLSTATE_DEFAULT)
363 FIXME("Not implemented for anything other than local installs\n");
364 return ERROR_CALL_NOT_IMPLEMENTED;
367 sz = sizeof(sourcepath);
368 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
369 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath,
370 &sz);
372 sz = sizeof(filename);
373 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
374 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
376 lstrcatW(sourcepath,filename);
379 * ok 1, we need to find the msi file for this product.
380 * 2, find the source dir for the files
381 * 3, do the configure/install.
382 * 4, cleanupany runonce entry.
385 r = MSI_OpenProductW( szProduct, &package );
386 if (r != ERROR_SUCCESS)
387 return r;
389 sz = lstrlenW(szInstalled) + 1;
391 if (szCommandLine)
392 sz += lstrlenW(szCommandLine);
394 commandline = msi_alloc(sz * sizeof(WCHAR));
395 if (!commandline )
397 r = ERROR_OUTOFMEMORY;
398 goto end;
401 commandline[0] = 0;
402 if (szCommandLine)
403 lstrcpyW(commandline,szCommandLine);
405 if (MsiQueryProductStateW(szProduct) != INSTALLSTATE_UNKNOWN)
406 lstrcatW(commandline,szInstalled);
408 r = MSI_InstallPackage( package, sourcepath, commandline );
410 msi_free(commandline);
412 end:
413 msiobj_release( &package->hdr );
415 return r;
418 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
419 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
421 LPWSTR szwProduct = NULL;
422 LPWSTR szwCommandLine = NULL;
423 UINT r = ERROR_OUTOFMEMORY;
425 if( szProduct )
427 szwProduct = strdupAtoW( szProduct );
428 if( !szwProduct )
429 goto end;
432 if( szCommandLine)
434 szwCommandLine = strdupAtoW( szCommandLine );
435 if( !szwCommandLine)
436 goto end;
439 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
440 szwCommandLine );
441 end:
442 msi_free( szwProduct );
443 msi_free( szwCommandLine);
445 return r;
448 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
449 INSTALLSTATE eInstallState)
451 LPWSTR szwProduct = NULL;
452 UINT r;
454 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
456 if( szProduct )
458 szwProduct = strdupAtoW( szProduct );
459 if( !szwProduct )
460 return ERROR_OUTOFMEMORY;
463 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
464 msi_free( szwProduct );
466 return r;
469 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
470 INSTALLSTATE eInstallState)
472 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
475 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
477 LPWSTR szwComponent = NULL;
478 UINT r;
479 WCHAR szwBuffer[GUID_SIZE];
481 TRACE("%s %s\n",debugstr_a(szComponent), debugstr_a(szBuffer));
483 if( szComponent )
485 szwComponent = strdupAtoW( szComponent );
486 if( !szwComponent )
487 return ERROR_OUTOFMEMORY;
490 r = MsiGetProductCodeW( szwComponent, szwBuffer );
492 if( ERROR_SUCCESS == r )
493 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
495 msi_free( szwComponent );
497 return r;
500 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
502 UINT rc;
503 HKEY hkey;
504 WCHAR szSquished[GUID_SIZE];
505 DWORD sz = GUID_SIZE;
506 static const WCHAR szPermKey[] =
507 { '0','0','0','0','0','0','0','0','0','0','0','0',
508 '0','0','0','0','0','0','0','0','0','0','0','0',
509 '0','0','0','0','0','0','0','0',0};
511 TRACE("%s %p\n",debugstr_w(szComponent), szBuffer);
513 if (NULL == szComponent)
514 return ERROR_INVALID_PARAMETER;
516 rc = MSIREG_OpenComponentsKey( szComponent, &hkey, FALSE);
517 if (rc != ERROR_SUCCESS)
518 return ERROR_UNKNOWN_COMPONENT;
520 rc = RegEnumValueW(hkey, 0, szSquished, &sz, NULL, NULL, NULL, NULL);
521 if (rc == ERROR_SUCCESS && strcmpW(szSquished,szPermKey)==0)
523 sz = GUID_SIZE;
524 rc = RegEnumValueW(hkey, 1, szSquished, &sz, NULL, NULL, NULL, NULL);
527 RegCloseKey(hkey);
529 if (rc != ERROR_SUCCESS)
530 return ERROR_INSTALL_FAILURE;
532 unsquash_guid(szSquished, szBuffer);
533 return ERROR_SUCCESS;
536 static UINT WINAPI MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
537 awstring *szValue, DWORD *pcchValueBuf)
539 UINT r;
540 HKEY hkey;
541 LPWSTR val = NULL;
543 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
544 debugstr_w(szAttribute), szValue, pcchValueBuf);
547 * FIXME: Values seem scattered/duplicated in the registry. Is there a system?
550 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szProduct[0] || !szAttribute)
551 return ERROR_INVALID_PARAMETER;
553 /* check for special properties */
554 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW))
556 LPWSTR regval;
557 WCHAR packagecode[35];
559 r = MSIREG_OpenUserProductsKey(szProduct, &hkey, FALSE);
560 if (r != ERROR_SUCCESS)
561 return ERROR_UNKNOWN_PRODUCT;
563 regval = msi_reg_get_val_str( hkey, szAttribute );
564 if (regval)
566 if (unsquash_guid(regval, packagecode))
567 val = strdupW(packagecode);
568 msi_free(regval);
571 RegCloseKey(hkey);
573 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW))
575 static const WCHAR one[] = { '1',0 };
577 * FIXME: should be in the Product key (user or system?)
578 * but isn't written yet...
580 val = strdupW( one );
582 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_LANGUAGEW) ||
583 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONW))
585 static const WCHAR fmt[] = { '%','u',0 };
586 WCHAR szVal[16];
587 DWORD regval;
589 r = MSIREG_OpenUninstallKey(szProduct, &hkey, FALSE);
590 if (r != ERROR_SUCCESS)
591 return ERROR_UNKNOWN_PRODUCT;
593 if (msi_reg_get_val_dword( hkey, szAttribute, &regval))
595 sprintfW(szVal, fmt, regval);
596 val = strdupW( szVal );
599 RegCloseKey(hkey);
601 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTNAMEW))
603 r = MSIREG_OpenUserProductsKey(szProduct, &hkey, FALSE);
604 if (r != ERROR_SUCCESS)
605 return ERROR_UNKNOWN_PRODUCT;
607 val = msi_reg_get_val_str( hkey, szAttribute );
609 RegCloseKey(hkey);
611 else if (!szAttribute[0])
613 return ERROR_UNKNOWN_PROPERTY;
615 else
617 static const WCHAR szDisplayVersion[] = {
618 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0 };
620 FIXME("%s\n", debugstr_w(szAttribute));
621 /* FIXME: some attribute values not tested... */
623 if (!lstrcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ))
624 szAttribute = szDisplayVersion;
626 r = MSIREG_OpenUninstallKey( szProduct, &hkey, FALSE );
627 if (r != ERROR_SUCCESS)
628 return ERROR_UNKNOWN_PRODUCT;
630 val = msi_reg_get_val_str( hkey, szAttribute );
632 RegCloseKey(hkey);
635 TRACE("returning %s\n", debugstr_w(val));
637 if (!val)
638 return ERROR_UNKNOWN_PROPERTY;
640 r = msi_strcpy_to_awstring( val, szValue, pcchValueBuf );
642 msi_free(val);
644 return r;
647 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
648 LPSTR szBuffer, DWORD *pcchValueBuf)
650 LPWSTR szwProduct, szwAttribute = NULL;
651 UINT r = ERROR_OUTOFMEMORY;
652 awstring buffer;
654 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
655 szBuffer, pcchValueBuf);
657 szwProduct = strdupAtoW( szProduct );
658 if( szProduct && !szwProduct )
659 goto end;
661 szwAttribute = strdupAtoW( szAttribute );
662 if( szAttribute && !szwAttribute )
663 goto end;
665 buffer.unicode = FALSE;
666 buffer.str.a = szBuffer;
668 r = MSI_GetProductInfo( szwProduct, szwAttribute,
669 &buffer, pcchValueBuf );
671 end:
672 msi_free( szwProduct );
673 msi_free( szwAttribute );
675 return r;
678 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
679 LPWSTR szBuffer, DWORD *pcchValueBuf)
681 awstring buffer;
683 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
684 szBuffer, pcchValueBuf);
686 buffer.unicode = TRUE;
687 buffer.str.w = szBuffer;
689 return MSI_GetProductInfo( szProduct, szAttribute,
690 &buffer, pcchValueBuf );
693 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
695 LPWSTR szwLogFile = NULL;
696 UINT r;
698 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
700 if( szLogFile )
702 szwLogFile = strdupAtoW( szLogFile );
703 if( !szwLogFile )
704 return ERROR_OUTOFMEMORY;
706 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
707 msi_free( szwLogFile );
708 return r;
711 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
713 HANDLE file = INVALID_HANDLE_VALUE;
715 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
717 if (szLogFile)
719 lstrcpyW(gszLogFile,szLogFile);
720 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
721 DeleteFileW(szLogFile);
722 file = CreateFileW(szLogFile, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
723 FILE_ATTRIBUTE_NORMAL, NULL);
724 if (file != INVALID_HANDLE_VALUE)
725 CloseHandle(file);
726 else
727 ERR("Unable to enable log %s\n",debugstr_w(szLogFile));
729 else
730 gszLogFile[0] = '\0';
732 return ERROR_SUCCESS;
735 UINT WINAPI MsiQueryComponentStateA(LPSTR szProductCode, LPSTR szUserSid, MSIINSTALLCONTEXT dwContext, LPCSTR szComponent, INSTALLSTATE *pdwState)
737 FIXME("(%s, %s, %d, %s, %p): stub!\n", debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
739 if (!pdwState)
740 return ERROR_INVALID_PARAMETER;
742 *pdwState = INSTALLSTATE_UNKNOWN;
743 return ERROR_UNKNOWN_PRODUCT;
746 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
748 LPWSTR szwProduct = NULL;
749 INSTALLSTATE r;
751 if( szProduct )
753 szwProduct = strdupAtoW( szProduct );
754 if( !szwProduct )
755 return ERROR_OUTOFMEMORY;
757 r = MsiQueryProductStateW( szwProduct );
758 msi_free( szwProduct );
759 return r;
762 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
764 UINT rc;
765 INSTALLSTATE state = INSTALLSTATE_UNKNOWN;
766 HKEY hkey = 0;
767 DWORD sz;
769 static const int GUID_LEN = 38;
770 static const WCHAR szWindowsInstaller[] = {
771 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0
774 TRACE("%s\n", debugstr_w(szProduct));
776 if (!szProduct || !*szProduct || lstrlenW(szProduct) != GUID_LEN)
777 return INSTALLSTATE_INVALIDARG;
779 rc = MSIREG_OpenUserProductsKey(szProduct,&hkey,FALSE);
780 if (rc != ERROR_SUCCESS)
781 goto end;
783 state = INSTALLSTATE_ADVERTISED;
784 RegCloseKey(hkey);
786 rc = MSIREG_OpenUninstallKey(szProduct,&hkey,FALSE);
787 if (rc != ERROR_SUCCESS)
788 goto end;
790 sz = sizeof(state);
791 rc = RegQueryValueExW(hkey,szWindowsInstaller,NULL,NULL,(LPVOID)&state, &sz);
792 if (rc != ERROR_SUCCESS)
793 goto end;
795 switch (state)
797 case 1:
798 /* default */
799 state = INSTALLSTATE_DEFAULT;
800 break;
801 default:
802 FIXME("Unknown install state read from registry (%i)\n",state);
803 state = INSTALLSTATE_UNKNOWN;
804 break;
806 end:
807 RegCloseKey(hkey);
808 return state;
811 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
813 INSTALLUILEVEL old = gUILevel;
814 HWND oldwnd = gUIhwnd;
816 TRACE("%08x %p\n", dwUILevel, phWnd);
818 gUILevel = dwUILevel;
819 if (phWnd)
821 gUIhwnd = *phWnd;
822 *phWnd = oldwnd;
824 return old;
827 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
828 DWORD dwMessageFilter, LPVOID pvContext)
830 INSTALLUI_HANDLERA prev = gUIHandlerA;
832 TRACE("%p %x %p\n",puiHandler, dwMessageFilter,pvContext);
833 gUIHandlerA = puiHandler;
834 gUIFilter = dwMessageFilter;
835 gUIContext = pvContext;
837 return prev;
840 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
841 DWORD dwMessageFilter, LPVOID pvContext)
843 INSTALLUI_HANDLERW prev = gUIHandlerW;
845 TRACE("%p %x %p\n",puiHandler,dwMessageFilter,pvContext);
846 gUIHandlerW = puiHandler;
847 gUIFilter = dwMessageFilter;
848 gUIContext = pvContext;
850 return prev;
853 /******************************************************************
854 * MsiLoadStringW [MSI.@]
856 * Loads a string from MSI's string resources.
858 * PARAMS
860 * handle [I] only -1 is handled currently
861 * id [I] id of the string to be loaded
862 * lpBuffer [O] buffer for the string to be written to
863 * nBufferMax [I] maximum size of the buffer in characters
864 * lang [I] the preferred language for the string
866 * RETURNS
868 * If successful, this function returns the language id of the string loaded
869 * If the function fails, the function returns zero.
871 * NOTES
873 * The type of the first parameter is unknown. LoadString's prototype
874 * suggests that it might be a module handle. I have made it an MSI handle
875 * for starters, as -1 is an invalid MSI handle, but not an invalid module
876 * handle. Maybe strings can be stored in an MSI database somehow.
878 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
879 int nBufferMax, LANGID lang )
881 HRSRC hres;
882 HGLOBAL hResData;
883 LPWSTR p;
884 DWORD i, len;
886 TRACE("%ld %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
888 if( handle != -1 )
889 FIXME("don't know how to deal with handle = %08lx\n", handle);
891 if( !lang )
892 lang = GetUserDefaultLangID();
894 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
895 (LPWSTR)1, lang );
896 if( !hres )
897 return 0;
898 hResData = LoadResource( msi_hInstance, hres );
899 if( !hResData )
900 return 0;
901 p = LockResource( hResData );
902 if( !p )
903 return 0;
905 for (i = 0; i < (id&0xf); i++)
906 p += *p + 1;
907 len = *p;
909 if( nBufferMax <= len )
910 return 0;
912 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
913 lpBuffer[ len ] = 0;
915 TRACE("found -> %s\n", debugstr_w(lpBuffer));
917 return lang;
920 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
921 int nBufferMax, LANGID lang )
923 LPWSTR bufW;
924 LANGID r;
925 DWORD len;
927 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
928 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
929 if( r )
931 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
932 if( len <= nBufferMax )
933 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
934 lpBuffer, nBufferMax, NULL, NULL );
935 else
936 r = 0;
938 msi_free(bufW);
939 return r;
942 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
943 DWORD *pcchBuf)
945 char szProduct[GUID_SIZE];
947 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
949 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
950 return INSTALLSTATE_UNKNOWN;
952 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
955 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
956 DWORD *pcchBuf)
958 WCHAR szProduct[GUID_SIZE];
960 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
962 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
963 return INSTALLSTATE_UNKNOWN;
965 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
968 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
969 WORD wLanguageId, DWORD f)
971 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
972 uType, wLanguageId, f);
973 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
976 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
977 WORD wLanguageId, DWORD f)
979 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
980 uType, wLanguageId, f);
981 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
984 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
985 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
986 DWORD* pcchPathBuf )
988 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
989 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
990 pcchPathBuf);
991 return ERROR_CALL_NOT_IMPLEMENTED;
994 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
995 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
996 DWORD* pcchPathBuf )
998 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
999 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
1000 pcchPathBuf);
1001 return ERROR_CALL_NOT_IMPLEMENTED;
1004 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
1005 LPSTR szPath, DWORD *pcchPath, DWORD *pcchArgs )
1007 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
1008 return ERROR_CALL_NOT_IMPLEMENTED;
1011 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
1012 LPWSTR szPath, DWORD *pcchPath, DWORD *pcchArgs )
1014 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
1015 return ERROR_CALL_NOT_IMPLEMENTED;
1018 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath,
1019 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, BYTE* pbHashData,
1020 DWORD* pcbHashData)
1022 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath), dwFlags,
1023 ppcCertContext, pbHashData, pcbHashData);
1024 return ERROR_CALL_NOT_IMPLEMENTED;
1027 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath,
1028 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, BYTE* pbHashData,
1029 DWORD* pcbHashData)
1031 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath), dwFlags,
1032 ppcCertContext, pbHashData, pcbHashData);
1033 return ERROR_CALL_NOT_IMPLEMENTED;
1036 UINT WINAPI MsiGetProductPropertyA( MSIHANDLE hProduct, LPCSTR szProperty,
1037 LPSTR szValue, DWORD *pccbValue )
1039 FIXME("%ld %s %p %p\n", hProduct, debugstr_a(szProperty), szValue, pccbValue);
1040 return ERROR_CALL_NOT_IMPLEMENTED;
1043 UINT WINAPI MsiGetProductPropertyW( MSIHANDLE hProduct, LPCWSTR szProperty,
1044 LPWSTR szValue, DWORD *pccbValue )
1046 FIXME("%ld %s %p %p\n", hProduct, debugstr_w(szProperty), szValue, pccbValue);
1047 return ERROR_CALL_NOT_IMPLEMENTED;
1050 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
1052 UINT r;
1053 LPWSTR szPack = NULL;
1055 TRACE("%s\n", debugstr_a(szPackage) );
1057 if( szPackage )
1059 szPack = strdupAtoW( szPackage );
1060 if( !szPack )
1061 return ERROR_OUTOFMEMORY;
1064 r = MsiVerifyPackageW( szPack );
1066 msi_free( szPack );
1068 return r;
1071 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
1073 MSIHANDLE handle;
1074 UINT r;
1076 TRACE("%s\n", debugstr_w(szPackage) );
1078 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
1079 MsiCloseHandle( handle );
1081 return r;
1084 static INSTALLSTATE WINAPI MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
1085 awstring* lpPathBuf, DWORD* pcchBuf)
1087 WCHAR squished_pc[GUID_SIZE], squished_comp[GUID_SIZE];
1088 UINT rc;
1089 HKEY hkey = 0;
1090 LPWSTR path = NULL;
1091 INSTALLSTATE r;
1093 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
1094 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
1096 if( !szProduct || !szComponent )
1097 return INSTALLSTATE_INVALIDARG;
1098 if( lpPathBuf->str.w && !pcchBuf )
1099 return INSTALLSTATE_INVALIDARG;
1101 if (!squash_guid( szProduct, squished_pc ) ||
1102 !squash_guid( szComponent, squished_comp ))
1103 return INSTALLSTATE_INVALIDARG;
1105 rc = MSIREG_OpenProductsKey( szProduct, &hkey, FALSE);
1106 if( rc != ERROR_SUCCESS )
1107 return INSTALLSTATE_UNKNOWN;
1109 RegCloseKey(hkey);
1111 rc = MSIREG_OpenComponentsKey( szComponent, &hkey, FALSE);
1112 if( rc != ERROR_SUCCESS )
1113 return INSTALLSTATE_UNKNOWN;
1115 path = msi_reg_get_val_str( hkey, squished_pc );
1116 RegCloseKey(hkey);
1118 TRACE("found path of (%s:%s)(%s)\n", debugstr_w(szComponent),
1119 debugstr_w(szProduct), debugstr_w(path));
1121 if (!path)
1122 return INSTALLSTATE_UNKNOWN;
1124 if (path[0])
1125 r = INSTALLSTATE_LOCAL;
1126 else
1127 r = INSTALLSTATE_NOTUSED;
1129 msi_strcpy_to_awstring( path, lpPathBuf, pcchBuf );
1131 msi_free( path );
1132 return r;
1135 /******************************************************************
1136 * MsiGetComponentPathW [MSI.@]
1138 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
1139 LPWSTR lpPathBuf, DWORD* pcchBuf)
1141 awstring path;
1143 path.unicode = TRUE;
1144 path.str.w = lpPathBuf;
1146 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
1149 /******************************************************************
1150 * MsiGetComponentPathA [MSI.@]
1152 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
1153 LPSTR lpPathBuf, DWORD* pcchBuf)
1155 LPWSTR szwProduct, szwComponent = NULL;
1156 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
1157 awstring path;
1159 szwProduct = strdupAtoW( szProduct );
1160 if( szProduct && !szwProduct)
1161 goto end;
1163 szwComponent = strdupAtoW( szComponent );
1164 if( szComponent && !szwComponent )
1165 goto end;
1167 path.unicode = FALSE;
1168 path.str.a = lpPathBuf;
1170 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
1172 end:
1173 msi_free( szwProduct );
1174 msi_free( szwComponent );
1176 return r;
1179 /******************************************************************
1180 * MsiQueryFeatureStateA [MSI.@]
1182 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
1184 LPWSTR szwProduct = NULL, szwFeature= NULL;
1185 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
1187 szwProduct = strdupAtoW( szProduct );
1188 if ( szProduct && !szwProduct )
1189 goto end;
1191 szwFeature = strdupAtoW( szFeature );
1192 if ( szFeature && !szwFeature )
1193 goto end;
1195 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
1197 end:
1198 msi_free( szwProduct);
1199 msi_free( szwFeature);
1201 return rc;
1204 /******************************************************************
1205 * MsiQueryFeatureStateW [MSI.@]
1207 * Checks the state of a feature
1209 * PARAMS
1210 * szProduct [I] Product's GUID string
1211 * szFeature [I] Feature's GUID string
1213 * RETURNS
1214 * INSTALLSTATE_LOCAL Feature is installed and useable
1215 * INSTALLSTATE_ABSENT Feature is absent
1216 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
1217 * INSTALLSTATE_UNKNOWN An error occurred
1218 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
1221 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
1223 WCHAR squishProduct[33], comp[GUID_SIZE];
1224 GUID guid;
1225 LPWSTR components, p, parent_feature;
1226 UINT rc;
1227 HKEY hkey;
1228 INSTALLSTATE r;
1229 BOOL missing = FALSE;
1231 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
1233 if (!szProduct || !szFeature)
1234 return INSTALLSTATE_INVALIDARG;
1236 if (!squash_guid( szProduct, squishProduct ))
1237 return INSTALLSTATE_INVALIDARG;
1239 /* check that it's installed at all */
1240 rc = MSIREG_OpenUserFeaturesKey(szProduct, &hkey, FALSE);
1241 if (rc != ERROR_SUCCESS)
1242 return INSTALLSTATE_UNKNOWN;
1244 parent_feature = msi_reg_get_val_str( hkey, szFeature );
1245 RegCloseKey(hkey);
1247 if (!parent_feature)
1248 return INSTALLSTATE_UNKNOWN;
1250 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
1251 msi_free(parent_feature);
1252 if (r == INSTALLSTATE_ABSENT)
1253 return r;
1255 /* now check if it's complete or advertised */
1256 rc = MSIREG_OpenFeaturesKey(szProduct, &hkey, FALSE);
1257 if (rc != ERROR_SUCCESS)
1258 return INSTALLSTATE_UNKNOWN;
1260 components = msi_reg_get_val_str( hkey, szFeature );
1261 RegCloseKey(hkey);
1263 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
1265 if (!components)
1267 ERR("components missing %s %s\n",
1268 debugstr_w(szProduct), debugstr_w(szFeature));
1269 return INSTALLSTATE_UNKNOWN;
1272 for( p = components; *p != 2 ; p += 20)
1274 if (!decode_base85_guid( p, &guid ))
1276 ERR("%s\n", debugstr_w(p));
1277 break;
1279 StringFromGUID2(&guid, comp, GUID_SIZE);
1280 r = MsiGetComponentPathW(szProduct, comp, NULL, 0);
1281 TRACE("component %s state %d\n", debugstr_guid(&guid), r);
1282 switch (r)
1284 case INSTALLSTATE_NOTUSED:
1285 case INSTALLSTATE_LOCAL:
1286 case INSTALLSTATE_SOURCE:
1287 break;
1288 default:
1289 missing = TRUE;
1293 TRACE("%s %s -> %d\n", debugstr_w(szProduct), debugstr_w(szFeature), r);
1294 msi_free(components);
1296 if (missing)
1297 return INSTALLSTATE_ADVERTISED;
1299 return INSTALLSTATE_LOCAL;
1302 /******************************************************************
1303 * MsiGetFileVersionA [MSI.@]
1305 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
1306 DWORD* pcchVersionBuf, LPSTR lpLangBuf, DWORD* pcchLangBuf)
1308 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
1309 UINT ret = ERROR_OUTOFMEMORY;
1311 if( szFilePath )
1313 szwFilePath = strdupAtoW( szFilePath );
1314 if( !szwFilePath )
1315 goto end;
1318 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
1320 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
1321 if( !lpwVersionBuff )
1322 goto end;
1325 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
1327 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
1328 if( !lpwLangBuff )
1329 goto end;
1332 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
1333 lpwLangBuff, pcchLangBuf);
1335 if( lpwVersionBuff )
1336 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
1337 lpVersionBuf, *pcchVersionBuf, NULL, NULL);
1338 if( lpwLangBuff )
1339 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
1340 lpLangBuf, *pcchLangBuf, NULL, NULL);
1342 end:
1343 msi_free(szwFilePath);
1344 msi_free(lpwVersionBuff);
1345 msi_free(lpwLangBuff);
1347 return ret;
1350 /******************************************************************
1351 * MsiGetFileVersionW [MSI.@]
1353 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
1354 DWORD* pcchVersionBuf, LPWSTR lpLangBuf, DWORD* pcchLangBuf)
1356 static const WCHAR szVersionResource[] = {'\\',0};
1357 static const WCHAR szVersionFormat[] = {
1358 '%','d','.','%','d','.','%','d','.','%','d',0};
1359 static const WCHAR szLangFormat[] = {'%','d',0};
1360 UINT ret = 0;
1361 DWORD dwVerLen;
1362 LPVOID lpVer = NULL;
1363 VS_FIXEDFILEINFO *ffi;
1364 UINT puLen;
1365 WCHAR tmp[32];
1367 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
1368 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
1369 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
1371 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
1372 if( !dwVerLen )
1373 return GetLastError();
1375 lpVer = msi_alloc(dwVerLen);
1376 if( !lpVer )
1378 ret = ERROR_OUTOFMEMORY;
1379 goto end;
1382 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
1384 ret = GetLastError();
1385 goto end;
1387 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
1389 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
1390 (puLen > 0) )
1392 wsprintfW(tmp, szVersionFormat,
1393 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
1394 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
1395 lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
1396 *pcchVersionBuf = lstrlenW(lpVersionBuf);
1398 else
1400 *lpVersionBuf = 0;
1401 *pcchVersionBuf = 0;
1405 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
1407 DWORD lang = GetUserDefaultLangID();
1409 FIXME("Retrieve language from file\n");
1410 wsprintfW(tmp, szLangFormat, lang);
1411 lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
1412 *pcchLangBuf = lstrlenW(lpLangBuf);
1415 end:
1416 msi_free(lpVer);
1417 return ret;
1420 /***********************************************************************
1421 * MsiGetFeatureUsageW [MSI.@]
1423 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
1424 DWORD* pdwUseCount, WORD* pwDateUsed )
1426 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
1427 pdwUseCount, pwDateUsed);
1428 return ERROR_CALL_NOT_IMPLEMENTED;
1431 /***********************************************************************
1432 * MsiGetFeatureUsageA [MSI.@]
1434 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
1435 DWORD* pdwUseCount, WORD* pwDateUsed )
1437 LPWSTR prod = NULL, feat = NULL;
1438 UINT ret = ERROR_OUTOFMEMORY;
1440 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
1441 pdwUseCount, pwDateUsed);
1443 prod = strdupAtoW( szProduct );
1444 if (szProduct && !prod)
1445 goto end;
1447 feat = strdupAtoW( szFeature );
1448 if (szFeature && !feat)
1449 goto end;
1451 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
1453 end:
1454 msi_free( prod );
1455 msi_free( feat );
1457 return ret;
1460 /***********************************************************************
1461 * MsiUseFeatureExW [MSI.@]
1463 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
1464 DWORD dwInstallMode, DWORD dwReserved )
1466 INSTALLSTATE state;
1468 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
1469 dwInstallMode, dwReserved);
1471 state = MsiQueryFeatureStateW( szProduct, szFeature );
1473 if (dwReserved)
1474 return INSTALLSTATE_INVALIDARG;
1476 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
1478 FIXME("mark product %s feature %s as used\n",
1479 debugstr_w(szProduct), debugstr_w(szFeature) );
1482 return state;
1485 /***********************************************************************
1486 * MsiUseFeatureExA [MSI.@]
1488 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
1489 DWORD dwInstallMode, DWORD dwReserved )
1491 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
1492 LPWSTR prod = NULL, feat = NULL;
1494 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
1495 dwInstallMode, dwReserved);
1497 prod = strdupAtoW( szProduct );
1498 if (szProduct && !prod)
1499 goto end;
1501 feat = strdupAtoW( szFeature );
1502 if (szFeature && !feat)
1503 goto end;
1505 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
1507 end:
1508 msi_free( prod );
1509 msi_free( feat );
1511 return ret;
1514 /***********************************************************************
1515 * MsiUseFeatureW [MSI.@]
1517 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
1519 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
1522 /***********************************************************************
1523 * MsiUseFeatureA [MSI.@]
1525 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
1527 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
1530 /***********************************************************************
1531 * MSI_ProvideQualifiedComponentEx [internal]
1533 static UINT WINAPI MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
1534 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
1535 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
1536 DWORD* pcchPathBuf)
1538 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
1539 feature[MAX_FEATURE_CHARS+1];
1540 LPWSTR info;
1541 HKEY hkey;
1542 DWORD sz;
1543 UINT rc;
1545 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
1546 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
1547 Unused1, Unused2, lpPathBuf, pcchPathBuf);
1549 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
1550 if (rc != ERROR_SUCCESS)
1551 return ERROR_INDEX_ABSENT;
1553 info = msi_reg_get_val_str( hkey, szQualifier );
1554 RegCloseKey(hkey);
1556 if (!info)
1557 return ERROR_INDEX_ABSENT;
1559 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
1561 if (!szProduct)
1562 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
1563 else
1564 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
1566 msi_free( info );
1568 if (rc != INSTALLSTATE_LOCAL)
1569 return ERROR_FILE_NOT_FOUND;
1571 return ERROR_SUCCESS;
1574 /***********************************************************************
1575 * MsiProvideQualifiedComponentExW [MSI.@]
1577 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
1578 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR szProduct,
1579 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
1580 DWORD* pcchPathBuf)
1582 awstring path;
1584 path.unicode = TRUE;
1585 path.str.w = lpPathBuf;
1587 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
1588 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
1591 /***********************************************************************
1592 * MsiProvideQualifiedComponentExA [MSI.@]
1594 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
1595 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR szProduct,
1596 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
1597 DWORD* pcchPathBuf)
1599 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
1600 UINT r = ERROR_OUTOFMEMORY;
1601 awstring path;
1603 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
1604 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
1605 Unused1, Unused2, lpPathBuf, pcchPathBuf);
1607 szwComponent = strdupAtoW( szComponent );
1608 if (szComponent && !szwComponent)
1609 goto end;
1611 szwQualifier = strdupAtoW( szQualifier );
1612 if (szQualifier && !szwQualifier)
1613 goto end;
1615 szwProduct = strdupAtoW( szProduct );
1616 if (szProduct && !szwProduct)
1617 goto end;
1619 path.unicode = FALSE;
1620 path.str.a = lpPathBuf;
1622 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
1623 dwInstallMode, szwProduct, Unused1,
1624 Unused2, &path, pcchPathBuf);
1625 end:
1626 msi_free(szwProduct);
1627 msi_free(szwComponent);
1628 msi_free(szwQualifier);
1630 return r;
1633 /***********************************************************************
1634 * MsiProvideQualifiedComponentW [MSI.@]
1636 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
1637 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
1638 DWORD* pcchPathBuf)
1640 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
1641 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
1644 /***********************************************************************
1645 * MsiProvideQualifiedComponentA [MSI.@]
1647 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
1648 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
1649 DWORD* pcchPathBuf)
1651 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
1652 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
1655 /***********************************************************************
1656 * MSI_GetUserInfo [internal]
1658 static USERINFOSTATE WINAPI MSI_GetUserInfo(LPCWSTR szProduct,
1659 awstring *lpUserNameBuf, DWORD* pcchUserNameBuf,
1660 awstring *lpOrgNameBuf, DWORD* pcchOrgNameBuf,
1661 awstring *lpSerialBuf, DWORD* pcchSerialBuf)
1663 HKEY hkey;
1664 LPWSTR user, org, serial;
1665 UINT r;
1666 USERINFOSTATE state;
1668 TRACE("%s %p %p %p %p %p %p\n",debugstr_w(szProduct), lpUserNameBuf,
1669 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
1670 pcchSerialBuf);
1672 if (!szProduct)
1673 return USERINFOSTATE_INVALIDARG;
1675 r = MSIREG_OpenUninstallKey(szProduct, &hkey, FALSE);
1676 if (r != ERROR_SUCCESS)
1677 return USERINFOSTATE_UNKNOWN;
1679 user = msi_reg_get_val_str( hkey, INSTALLPROPERTY_REGOWNERW );
1680 org = msi_reg_get_val_str( hkey, INSTALLPROPERTY_REGCOMPANYW );
1681 serial = msi_reg_get_val_str( hkey, INSTALLPROPERTY_PRODUCTIDW );
1683 RegCloseKey(hkey);
1685 state = USERINFOSTATE_PRESENT;
1687 if (user)
1689 r = msi_strcpy_to_awstring( user, lpUserNameBuf, pcchUserNameBuf );
1690 if (r == ERROR_MORE_DATA)
1691 state = USERINFOSTATE_MOREDATA;
1693 else
1694 state = USERINFOSTATE_ABSENT;
1695 if (org)
1697 r = msi_strcpy_to_awstring( org, lpOrgNameBuf, pcchOrgNameBuf );
1698 if (r == ERROR_MORE_DATA && state == USERINFOSTATE_PRESENT)
1699 state = USERINFOSTATE_MOREDATA;
1701 /* msdn states: The user information is considered to be present even in the absence of a company name. */
1702 if (serial)
1704 r = msi_strcpy_to_awstring( serial, lpSerialBuf, pcchSerialBuf );
1705 if (r == ERROR_MORE_DATA && state == USERINFOSTATE_PRESENT)
1706 state = USERINFOSTATE_MOREDATA;
1708 else
1709 state = USERINFOSTATE_ABSENT;
1711 msi_free( user );
1712 msi_free( org );
1713 msi_free( serial );
1715 return state;
1718 /***********************************************************************
1719 * MsiGetUserInfoW [MSI.@]
1721 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
1722 LPWSTR lpUserNameBuf, DWORD* pcchUserNameBuf,
1723 LPWSTR lpOrgNameBuf, DWORD* pcchOrgNameBuf,
1724 LPWSTR lpSerialBuf, DWORD* pcchSerialBuf)
1726 awstring user, org, serial;
1728 user.unicode = TRUE;
1729 user.str.w = lpUserNameBuf;
1730 org.unicode = TRUE;
1731 org.str.w = lpOrgNameBuf;
1732 serial.unicode = TRUE;
1733 serial.str.w = lpSerialBuf;
1735 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
1736 &org, pcchOrgNameBuf,
1737 &serial, pcchSerialBuf );
1740 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
1741 LPSTR lpUserNameBuf, DWORD* pcchUserNameBuf,
1742 LPSTR lpOrgNameBuf, DWORD* pcchOrgNameBuf,
1743 LPSTR lpSerialBuf, DWORD* pcchSerialBuf)
1745 awstring user, org, serial;
1746 LPWSTR prod;
1747 UINT r;
1749 prod = strdupAtoW( szProduct );
1750 if (szProduct && !prod)
1751 return ERROR_OUTOFMEMORY;
1753 user.unicode = FALSE;
1754 user.str.a = lpUserNameBuf;
1755 org.unicode = FALSE;
1756 org.str.a = lpOrgNameBuf;
1757 serial.unicode = FALSE;
1758 serial.str.a = lpSerialBuf;
1760 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
1761 &org, pcchOrgNameBuf,
1762 &serial, pcchSerialBuf );
1764 msi_free( prod );
1766 return r;
1769 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
1771 MSIHANDLE handle;
1772 UINT rc;
1773 MSIPACKAGE *package;
1774 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
1776 TRACE("(%s)\n",debugstr_w(szProduct));
1778 rc = MsiOpenProductW(szProduct,&handle);
1779 if (rc != ERROR_SUCCESS)
1780 return ERROR_INVALID_PARAMETER;
1782 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
1783 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
1784 msiobj_release( &package->hdr );
1786 MsiCloseHandle(handle);
1788 return rc;
1791 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
1793 MSIHANDLE handle;
1794 UINT rc;
1795 MSIPACKAGE *package;
1796 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
1798 TRACE("(%s)\n",debugstr_a(szProduct));
1800 rc = MsiOpenProductA(szProduct,&handle);
1801 if (rc != ERROR_SUCCESS)
1802 return ERROR_INVALID_PARAMETER;
1804 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
1805 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
1806 msiobj_release( &package->hdr );
1808 MsiCloseHandle(handle);
1810 return rc;
1813 /***********************************************************************
1814 * MsiConfigureFeatureA [MSI.@]
1816 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
1818 LPWSTR prod, feat = NULL;
1819 UINT r = ERROR_OUTOFMEMORY;
1821 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
1823 prod = strdupAtoW( szProduct );
1824 if (szProduct && !prod)
1825 goto end;
1827 feat = strdupAtoW( szFeature );
1828 if (szFeature && !feat)
1829 goto end;
1831 r = MsiConfigureFeatureW(prod, feat, eInstallState);
1833 end:
1834 msi_free(feat);
1835 msi_free(prod);
1837 return r;
1840 /***********************************************************************
1841 * MsiConfigureFeatureW [MSI.@]
1843 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
1845 static const WCHAR szCostInit[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
1846 MSIPACKAGE *package = NULL;
1847 UINT r;
1848 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
1849 DWORD sz;
1851 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
1853 if (!szProduct || !szFeature)
1854 return ERROR_INVALID_PARAMETER;
1856 switch (eInstallState)
1858 case INSTALLSTATE_DEFAULT:
1859 /* FIXME: how do we figure out the default location? */
1860 eInstallState = INSTALLSTATE_LOCAL;
1861 break;
1862 case INSTALLSTATE_LOCAL:
1863 case INSTALLSTATE_SOURCE:
1864 case INSTALLSTATE_ABSENT:
1865 case INSTALLSTATE_ADVERTISED:
1866 break;
1867 default:
1868 return ERROR_INVALID_PARAMETER;
1871 r = MSI_OpenProductW( szProduct, &package );
1872 if (r != ERROR_SUCCESS)
1873 return r;
1875 sz = sizeof(sourcepath);
1876 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
1877 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
1879 sz = sizeof(filename);
1880 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
1881 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
1883 lstrcatW( sourcepath, filename );
1885 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
1887 r = ACTION_PerformUIAction( package, szCostInit, -1 );
1888 if (r != ERROR_SUCCESS)
1889 goto end;
1891 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
1892 if (r != ERROR_SUCCESS)
1893 goto end;
1895 r = MSI_InstallPackage( package, sourcepath, NULL );
1897 end:
1898 msiobj_release( &package->hdr );
1900 return r;
1903 /***********************************************************************
1904 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
1906 * Notes: undocumented
1908 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
1910 WCHAR path[MAX_PATH];
1912 TRACE("%d\n", dwReserved);
1914 if (dwReserved)
1916 FIXME("dwReserved=%d\n", dwReserved);
1917 return ERROR_INVALID_PARAMETER;
1920 if (!GetWindowsDirectoryW(path, MAX_PATH))
1921 return ERROR_FUNCTION_FAILED;
1923 lstrcatW(path, installerW);
1925 if (!CreateDirectoryW(path, NULL))
1926 return ERROR_FUNCTION_FAILED;
1928 return ERROR_SUCCESS;
1931 /***********************************************************************
1932 * MsiGetShortcutTargetA [MSI.@]
1934 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
1935 LPSTR szProductCode, LPSTR szFeatureId,
1936 LPSTR szComponentCode )
1938 LPWSTR target;
1939 const int len = MAX_FEATURE_CHARS+1;
1940 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
1941 UINT r;
1943 target = strdupAtoW( szShortcutTarget );
1944 if (szShortcutTarget && !target )
1945 return ERROR_OUTOFMEMORY;
1946 product[0] = 0;
1947 feature[0] = 0;
1948 component[0] = 0;
1949 r = MsiGetShortcutTargetW( target, product, feature, component );
1950 msi_free( target );
1951 if (r == ERROR_SUCCESS)
1953 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
1954 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
1955 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
1957 return r;
1960 /***********************************************************************
1961 * MsiGetShortcutTargetW [MSI.@]
1963 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
1964 LPWSTR szProductCode, LPWSTR szFeatureId,
1965 LPWSTR szComponentCode )
1967 IShellLinkDataList *dl = NULL;
1968 IPersistFile *pf = NULL;
1969 LPEXP_DARWIN_LINK darwin = NULL;
1970 HRESULT r, init;
1972 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
1973 szProductCode, szFeatureId, szComponentCode );
1975 init = CoInitialize(NULL);
1977 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
1978 &IID_IPersistFile, (LPVOID*) &pf );
1979 if( SUCCEEDED( r ) )
1981 r = IPersistFile_Load( pf, szShortcutTarget,
1982 STGM_READ | STGM_SHARE_DENY_WRITE );
1983 if( SUCCEEDED( r ) )
1985 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
1986 (LPVOID*) &dl );
1987 if( SUCCEEDED( r ) )
1989 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
1990 (LPVOID) &darwin );
1991 IShellLinkDataList_Release( dl );
1994 IPersistFile_Release( pf );
1997 if (SUCCEEDED(init))
1998 CoUninitialize();
2000 TRACE("darwin = %p\n", darwin);
2002 if (darwin)
2004 DWORD sz;
2005 UINT ret;
2007 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
2008 szProductCode, szFeatureId, szComponentCode, &sz );
2009 LocalFree( darwin );
2010 return ret;
2013 return ERROR_FUNCTION_FAILED;
2016 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
2017 DWORD dwReinstallMode )
2019 MSIPACKAGE* package = NULL;
2020 UINT r;
2021 WCHAR sourcepath[MAX_PATH];
2022 WCHAR filename[MAX_PATH];
2023 static const WCHAR szLogVerbose[] = {
2024 ' ','L','O','G','V','E','R','B','O','S','E',0 };
2025 static const WCHAR szInstalled[] = { 'I','n','s','t','a','l','l','e','d',0};
2026 static const WCHAR szReinstall[] = {'R','E','I','N','S','T','A','L','L',0};
2027 static const WCHAR szReinstallMode[] = {'R','E','I','N','S','T','A','L','L','M','O','D','E',0};
2028 static const WCHAR szOne[] = {'1',0};
2029 WCHAR reinstallmode[11];
2030 LPWSTR ptr;
2031 DWORD sz;
2033 FIXME("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
2034 dwReinstallMode);
2036 ptr = reinstallmode;
2038 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
2039 *ptr++ = 'p';
2040 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
2041 *ptr++ = 'o';
2042 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
2043 *ptr++ = 'w';
2044 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
2045 *ptr++ = 'd';
2046 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
2047 *ptr++ = 'c';
2048 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
2049 *ptr++ = 'a';
2050 if (dwReinstallMode & REINSTALLMODE_USERDATA)
2051 *ptr++ = 'u';
2052 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
2053 *ptr++ = 'm';
2054 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
2055 *ptr++ = 's';
2056 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
2057 *ptr++ = 'v';
2058 *ptr = 0;
2060 sz = sizeof(sourcepath);
2061 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2062 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
2064 sz = sizeof(filename);
2065 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2066 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
2068 lstrcatW( sourcepath, filename );
2070 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
2071 r = MSI_OpenPackageW( sourcepath, &package );
2072 else
2073 r = MSI_OpenProductW( szProduct, &package );
2075 if (r != ERROR_SUCCESS)
2076 return r;
2078 MSI_SetPropertyW( package, szReinstallMode, reinstallmode );
2079 MSI_SetPropertyW( package, szInstalled, szOne );
2080 MSI_SetPropertyW( package, szLogVerbose, szOne );
2081 MSI_SetPropertyW( package, szReinstall, szFeature );
2083 r = MSI_InstallPackage( package, sourcepath, NULL );
2085 msiobj_release( &package->hdr );
2087 return r;
2090 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
2091 DWORD dwReinstallMode )
2093 LPWSTR wszProduct;
2094 LPWSTR wszFeature;
2095 UINT rc;
2097 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
2098 dwReinstallMode);
2100 wszProduct = strdupAtoW(szProduct);
2101 wszFeature = strdupAtoW(szFeature);
2103 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
2105 msi_free(wszProduct);
2106 msi_free(wszFeature);
2107 return rc;
2110 typedef struct
2112 unsigned int i[2];
2113 unsigned int buf[4];
2114 unsigned char in[64];
2115 unsigned char digest[16];
2116 } MD5_CTX;
2118 extern VOID WINAPI MD5Init( MD5_CTX *);
2119 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
2120 extern VOID WINAPI MD5Final( MD5_CTX *);
2122 /***********************************************************************
2123 * MsiGetFileHashW [MSI.@]
2125 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
2126 PMSIFILEHASHINFO pHash )
2128 HANDLE handle, mapping;
2129 void *p;
2130 DWORD length;
2131 UINT r = ERROR_FUNCTION_FAILED;
2133 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
2135 if (dwOptions)
2136 return ERROR_INVALID_PARAMETER;
2137 if (!pHash)
2138 return ERROR_INVALID_PARAMETER;
2139 if (pHash->dwFileHashInfoSize < sizeof *pHash)
2140 return ERROR_INVALID_PARAMETER;
2142 handle = CreateFileW( szFilePath, GENERIC_READ,
2143 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
2144 if (handle == INVALID_HANDLE_VALUE)
2145 return ERROR_FILE_NOT_FOUND;
2147 length = GetFileSize( handle, NULL );
2149 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
2150 if (mapping)
2152 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
2153 if (p)
2155 MD5_CTX ctx;
2157 MD5Init( &ctx );
2158 MD5Update( &ctx, p, length );
2159 MD5Final( &ctx );
2160 UnmapViewOfFile( p );
2162 memcpy( pHash->dwData, &ctx.digest, sizeof pHash->dwData );
2163 r = ERROR_SUCCESS;
2165 CloseHandle( mapping );
2167 CloseHandle( handle );
2169 return r;
2172 /***********************************************************************
2173 * MsiGetFileHashA [MSI.@]
2175 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
2176 PMSIFILEHASHINFO pHash )
2178 LPWSTR file;
2179 UINT r;
2181 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
2183 file = strdupAtoW( szFilePath );
2184 if (szFilePath && !file)
2185 return ERROR_OUTOFMEMORY;
2187 r = MsiGetFileHashW( file, dwOptions, pHash );
2188 msi_free( file );
2189 return r;
2192 /***********************************************************************
2193 * MsiAdvertiseScriptW [MSI.@]
2195 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
2196 PHKEY phRegData, BOOL fRemoveItems )
2198 FIXME("%s %08x %p %d\n",
2199 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
2200 return ERROR_CALL_NOT_IMPLEMENTED;
2203 /***********************************************************************
2204 * MsiAdvertiseScriptA [MSI.@]
2206 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
2207 PHKEY phRegData, BOOL fRemoveItems )
2209 FIXME("%s %08x %p %d\n",
2210 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
2211 return ERROR_CALL_NOT_IMPLEMENTED;