msvcrt: Add a prototype for _atoldbl() & co and declare _LDOUBLE & co in stdlib.h.
[wine/wine64.git] / dlls / msi / msi.c
blob7faccaf3afdf653e721a8dce49630047d10a48cb
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, LPDWORD 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, LPDWORD 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, LPDWORD 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(LPCSTR szProductCode,
736 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
737 LPCSTR szComponent, INSTALLSTATE *pdwState)
739 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
740 UINT r;
742 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
743 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
745 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
746 return ERROR_OUTOFMEMORY;
748 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
749 return ERROR_OUTOFMEMORY;
751 if (szComponent && !(comp = strdupAtoW(szComponent)))
752 return ERROR_OUTOFMEMORY;
754 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
756 msi_free(prodcode);
757 msi_free(usersid);
758 msi_free(comp);
760 return r;
763 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
765 UINT r;
766 HKEY hkey;
768 if (context == MSIINSTALLCONTEXT_MACHINE)
769 r = MSIREG_OpenLocalClassesProductKey(prodcode, &hkey, FALSE);
770 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
771 r = MSIREG_OpenUserProductsKey(prodcode, &hkey, FALSE);
772 else
773 r = MSIREG_OpenLocalManagedProductKey(prodcode, &hkey, FALSE);
775 RegCloseKey(hkey);
776 return (r == ERROR_SUCCESS);
779 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
781 LPCWSTR package;
782 HKEY hkey;
783 DWORD sz;
784 LONG res;
785 UINT r;
787 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
788 static const WCHAR managed_local_package[] = {
789 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
792 if (context == MSIINSTALLCONTEXT_MACHINE)
793 r = MSIREG_OpenLocalSystemProductKey(prodcode, &hkey, FALSE);
794 else
795 r = MSIREG_OpenInstallPropertiesKey(prodcode, &hkey, FALSE);
797 if (r != ERROR_SUCCESS)
798 return FALSE;
800 if (context == MSIINSTALLCONTEXT_USERMANAGED)
801 package = managed_local_package;
802 else
803 package = local_package;
805 sz = 0;
806 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
807 RegCloseKey(hkey);
809 return (res == ERROR_SUCCESS);
812 static BOOL msi_comp_find_prodcode(LPCWSTR prodcode, LPWSTR squished_pc,
813 MSIINSTALLCONTEXT context,
814 LPCWSTR comp, DWORD *sz)
816 HKEY hkey;
817 LONG res;
818 UINT r;
820 if (context == MSIINSTALLCONTEXT_MACHINE)
821 r = MSIREG_OpenLocalSystemComponentKey(comp, &hkey, FALSE);
822 else
823 r = MSIREG_OpenUserDataComponentKey(comp, &hkey, FALSE);
825 if (r != ERROR_SUCCESS)
826 return FALSE;
828 *sz = 0;
829 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, NULL, sz);
830 if (res != ERROR_SUCCESS)
831 return FALSE;
833 RegCloseKey(hkey);
834 return TRUE;
837 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
838 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
839 LPCWSTR szComponent, INSTALLSTATE *pdwState)
841 WCHAR squished_pc[GUID_SIZE];
842 BOOL found;
843 DWORD sz;
845 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
846 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
848 if (!pdwState)
849 return ERROR_INVALID_PARAMETER;
851 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
852 return ERROR_INVALID_PARAMETER;
854 if (!squash_guid(szProductCode, squished_pc))
855 return ERROR_INVALID_PARAMETER;
857 found = msi_comp_find_prod_key(szProductCode, dwContext);
859 if (!msi_comp_find_package(szProductCode, dwContext))
861 if (found)
863 *pdwState = INSTALLSTATE_UNKNOWN;
864 return ERROR_UNKNOWN_COMPONENT;
867 return ERROR_UNKNOWN_PRODUCT;
870 *pdwState = INSTALLSTATE_UNKNOWN;
872 if (!msi_comp_find_prodcode(szProductCode, squished_pc, dwContext, szComponent, &sz))
873 return ERROR_UNKNOWN_COMPONENT;
875 if (sz == 0)
876 *pdwState = INSTALLSTATE_NOTUSED;
877 else
878 *pdwState = INSTALLSTATE_LOCAL;
880 return ERROR_SUCCESS;
883 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
885 LPWSTR szwProduct = NULL;
886 INSTALLSTATE r;
888 if( szProduct )
890 szwProduct = strdupAtoW( szProduct );
891 if( !szwProduct )
892 return ERROR_OUTOFMEMORY;
894 r = MsiQueryProductStateW( szwProduct );
895 msi_free( szwProduct );
896 return r;
899 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
901 UINT rc;
902 INSTALLSTATE state = INSTALLSTATE_UNKNOWN;
903 HKEY hkey = 0, props = 0;
904 DWORD sz;
905 BOOL userkey_exists = FALSE;
907 static const int GUID_LEN = 38;
908 static const WCHAR szInstallProperties[] = {
909 'I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0
911 static const WCHAR szWindowsInstaller[] = {
912 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0
915 TRACE("%s\n", debugstr_w(szProduct));
917 if (!szProduct || !*szProduct || lstrlenW(szProduct) != GUID_LEN)
918 return INSTALLSTATE_INVALIDARG;
920 rc = MSIREG_OpenUserProductsKey(szProduct,&hkey,FALSE);
921 if (rc == ERROR_SUCCESS)
923 userkey_exists = TRUE;
924 state = INSTALLSTATE_ADVERTISED;
925 RegCloseKey(hkey);
928 rc = MSIREG_OpenUserDataProductKey(szProduct,&hkey,FALSE);
929 if (rc != ERROR_SUCCESS)
930 goto end;
932 rc = RegOpenKeyW(hkey, szInstallProperties, &props);
933 if (rc != ERROR_SUCCESS)
934 goto end;
936 sz = sizeof(state);
937 rc = RegQueryValueExW(props,szWindowsInstaller,NULL,NULL,(LPVOID)&state, &sz);
938 if (rc != ERROR_SUCCESS)
939 goto end;
941 if (state)
942 state = INSTALLSTATE_DEFAULT;
943 else
944 state = INSTALLSTATE_UNKNOWN;
946 if (state == INSTALLSTATE_DEFAULT && !userkey_exists)
947 state = INSTALLSTATE_ABSENT;
949 end:
950 RegCloseKey(props);
951 RegCloseKey(hkey);
952 return state;
955 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
957 INSTALLUILEVEL old = gUILevel;
958 HWND oldwnd = gUIhwnd;
960 TRACE("%08x %p\n", dwUILevel, phWnd);
962 gUILevel = dwUILevel;
963 if (phWnd)
965 gUIhwnd = *phWnd;
966 *phWnd = oldwnd;
968 return old;
971 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
972 DWORD dwMessageFilter, LPVOID pvContext)
974 INSTALLUI_HANDLERA prev = gUIHandlerA;
976 TRACE("%p %x %p\n",puiHandler, dwMessageFilter,pvContext);
977 gUIHandlerA = puiHandler;
978 gUIFilter = dwMessageFilter;
979 gUIContext = pvContext;
981 return prev;
984 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
985 DWORD dwMessageFilter, LPVOID pvContext)
987 INSTALLUI_HANDLERW prev = gUIHandlerW;
989 TRACE("%p %x %p\n",puiHandler,dwMessageFilter,pvContext);
990 gUIHandlerW = puiHandler;
991 gUIFilter = dwMessageFilter;
992 gUIContext = pvContext;
994 return prev;
997 /******************************************************************
998 * MsiLoadStringW [MSI.@]
1000 * Loads a string from MSI's string resources.
1002 * PARAMS
1004 * handle [I] only -1 is handled currently
1005 * id [I] id of the string to be loaded
1006 * lpBuffer [O] buffer for the string to be written to
1007 * nBufferMax [I] maximum size of the buffer in characters
1008 * lang [I] the preferred language for the string
1010 * RETURNS
1012 * If successful, this function returns the language id of the string loaded
1013 * If the function fails, the function returns zero.
1015 * NOTES
1017 * The type of the first parameter is unknown. LoadString's prototype
1018 * suggests that it might be a module handle. I have made it an MSI handle
1019 * for starters, as -1 is an invalid MSI handle, but not an invalid module
1020 * handle. Maybe strings can be stored in an MSI database somehow.
1022 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
1023 int nBufferMax, LANGID lang )
1025 HRSRC hres;
1026 HGLOBAL hResData;
1027 LPWSTR p;
1028 DWORD i, len;
1030 TRACE("%ld %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
1032 if( handle != -1 )
1033 FIXME("don't know how to deal with handle = %08lx\n", handle);
1035 if( !lang )
1036 lang = GetUserDefaultLangID();
1038 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
1039 (LPWSTR)1, lang );
1040 if( !hres )
1041 return 0;
1042 hResData = LoadResource( msi_hInstance, hres );
1043 if( !hResData )
1044 return 0;
1045 p = LockResource( hResData );
1046 if( !p )
1047 return 0;
1049 for (i = 0; i < (id&0xf); i++)
1050 p += *p + 1;
1051 len = *p;
1053 if( nBufferMax <= len )
1054 return 0;
1056 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
1057 lpBuffer[ len ] = 0;
1059 TRACE("found -> %s\n", debugstr_w(lpBuffer));
1061 return lang;
1064 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
1065 int nBufferMax, LANGID lang )
1067 LPWSTR bufW;
1068 LANGID r;
1069 DWORD len;
1071 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
1072 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
1073 if( r )
1075 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
1076 if( len <= nBufferMax )
1077 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
1078 lpBuffer, nBufferMax, NULL, NULL );
1079 else
1080 r = 0;
1082 msi_free(bufW);
1083 return r;
1086 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
1087 LPDWORD pcchBuf)
1089 char szProduct[GUID_SIZE];
1091 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
1093 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
1094 return INSTALLSTATE_UNKNOWN;
1096 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
1099 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
1100 LPDWORD pcchBuf)
1102 WCHAR szProduct[GUID_SIZE];
1104 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
1106 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
1107 return INSTALLSTATE_UNKNOWN;
1109 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
1112 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
1113 WORD wLanguageId, DWORD f)
1115 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
1116 uType, wLanguageId, f);
1117 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
1120 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
1121 WORD wLanguageId, DWORD f)
1123 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
1124 uType, wLanguageId, f);
1125 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
1128 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
1129 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
1130 LPDWORD pcchPathBuf )
1132 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
1133 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
1134 pcchPathBuf);
1135 return ERROR_CALL_NOT_IMPLEMENTED;
1138 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
1139 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
1140 LPDWORD pcchPathBuf )
1142 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
1143 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
1144 pcchPathBuf);
1145 return ERROR_CALL_NOT_IMPLEMENTED;
1148 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
1149 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
1151 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
1152 return ERROR_CALL_NOT_IMPLEMENTED;
1155 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
1156 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
1158 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
1159 return ERROR_CALL_NOT_IMPLEMENTED;
1162 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath,
1163 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
1164 LPDWORD pcbHashData)
1166 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath), dwFlags,
1167 ppcCertContext, pbHashData, pcbHashData);
1168 return ERROR_CALL_NOT_IMPLEMENTED;
1171 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath,
1172 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
1173 LPDWORD pcbHashData)
1175 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath), dwFlags,
1176 ppcCertContext, pbHashData, pcbHashData);
1177 return ERROR_CALL_NOT_IMPLEMENTED;
1180 UINT WINAPI MsiGetProductPropertyA( MSIHANDLE hProduct, LPCSTR szProperty,
1181 LPSTR szValue, LPDWORD pccbValue )
1183 FIXME("%ld %s %p %p\n", hProduct, debugstr_a(szProperty), szValue, pccbValue);
1184 return ERROR_CALL_NOT_IMPLEMENTED;
1187 UINT WINAPI MsiGetProductPropertyW( MSIHANDLE hProduct, LPCWSTR szProperty,
1188 LPWSTR szValue, LPDWORD pccbValue )
1190 FIXME("%ld %s %p %p\n", hProduct, debugstr_w(szProperty), szValue, pccbValue);
1191 return ERROR_CALL_NOT_IMPLEMENTED;
1194 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
1196 UINT r;
1197 LPWSTR szPack = NULL;
1199 TRACE("%s\n", debugstr_a(szPackage) );
1201 if( szPackage )
1203 szPack = strdupAtoW( szPackage );
1204 if( !szPack )
1205 return ERROR_OUTOFMEMORY;
1208 r = MsiVerifyPackageW( szPack );
1210 msi_free( szPack );
1212 return r;
1215 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
1217 MSIHANDLE handle;
1218 UINT r;
1220 TRACE("%s\n", debugstr_w(szPackage) );
1222 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
1223 MsiCloseHandle( handle );
1225 return r;
1228 static INSTALLSTATE WINAPI MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
1229 awstring* lpPathBuf, LPDWORD pcchBuf)
1231 WCHAR squished_pc[GUID_SIZE], squished_comp[GUID_SIZE];
1232 UINT rc;
1233 HKEY hkey = 0;
1234 LPWSTR path = NULL;
1235 INSTALLSTATE r;
1237 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
1238 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
1240 if( !szProduct || !szComponent )
1241 return INSTALLSTATE_INVALIDARG;
1242 if( lpPathBuf->str.w && !pcchBuf )
1243 return INSTALLSTATE_INVALIDARG;
1245 if (!squash_guid( szProduct, squished_pc ) ||
1246 !squash_guid( szComponent, squished_comp ))
1247 return INSTALLSTATE_INVALIDARG;
1249 rc = MSIREG_OpenProductsKey( szProduct, &hkey, FALSE);
1250 if( rc != ERROR_SUCCESS )
1251 return INSTALLSTATE_UNKNOWN;
1253 RegCloseKey(hkey);
1255 rc = MSIREG_OpenComponentsKey( szComponent, &hkey, FALSE);
1256 if( rc != ERROR_SUCCESS )
1257 return INSTALLSTATE_UNKNOWN;
1259 path = msi_reg_get_val_str( hkey, squished_pc );
1260 RegCloseKey(hkey);
1262 TRACE("found path of (%s:%s)(%s)\n", debugstr_w(szComponent),
1263 debugstr_w(szProduct), debugstr_w(path));
1265 if (!path)
1266 return INSTALLSTATE_UNKNOWN;
1268 if (path[0])
1269 r = INSTALLSTATE_LOCAL;
1270 else
1271 r = INSTALLSTATE_NOTUSED;
1273 msi_strcpy_to_awstring( path, lpPathBuf, pcchBuf );
1275 msi_free( path );
1276 return r;
1279 /******************************************************************
1280 * MsiGetComponentPathW [MSI.@]
1282 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
1283 LPWSTR lpPathBuf, LPDWORD pcchBuf)
1285 awstring path;
1287 path.unicode = TRUE;
1288 path.str.w = lpPathBuf;
1290 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
1293 /******************************************************************
1294 * MsiGetComponentPathA [MSI.@]
1296 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
1297 LPSTR lpPathBuf, LPDWORD pcchBuf)
1299 LPWSTR szwProduct, szwComponent = NULL;
1300 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
1301 awstring path;
1303 szwProduct = strdupAtoW( szProduct );
1304 if( szProduct && !szwProduct)
1305 goto end;
1307 szwComponent = strdupAtoW( szComponent );
1308 if( szComponent && !szwComponent )
1309 goto end;
1311 path.unicode = FALSE;
1312 path.str.a = lpPathBuf;
1314 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
1316 end:
1317 msi_free( szwProduct );
1318 msi_free( szwComponent );
1320 return r;
1323 /******************************************************************
1324 * MsiQueryFeatureStateA [MSI.@]
1326 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
1328 LPWSTR szwProduct = NULL, szwFeature= NULL;
1329 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
1331 szwProduct = strdupAtoW( szProduct );
1332 if ( szProduct && !szwProduct )
1333 goto end;
1335 szwFeature = strdupAtoW( szFeature );
1336 if ( szFeature && !szwFeature )
1337 goto end;
1339 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
1341 end:
1342 msi_free( szwProduct);
1343 msi_free( szwFeature);
1345 return rc;
1348 /******************************************************************
1349 * MsiQueryFeatureStateW [MSI.@]
1351 * Checks the state of a feature
1353 * PARAMS
1354 * szProduct [I] Product's GUID string
1355 * szFeature [I] Feature's GUID string
1357 * RETURNS
1358 * INSTALLSTATE_LOCAL Feature is installed and useable
1359 * INSTALLSTATE_ABSENT Feature is absent
1360 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
1361 * INSTALLSTATE_UNKNOWN An error occurred
1362 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
1365 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
1367 WCHAR squishProduct[33], comp[GUID_SIZE];
1368 GUID guid;
1369 LPWSTR components, p, parent_feature, path;
1370 UINT rc;
1371 HKEY hkey;
1372 INSTALLSTATE r;
1373 BOOL missing = FALSE;
1375 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
1377 if (!szProduct || !szFeature)
1378 return INSTALLSTATE_INVALIDARG;
1380 if (!squash_guid( szProduct, squishProduct ))
1381 return INSTALLSTATE_INVALIDARG;
1383 /* check that it's installed at all */
1384 rc = MSIREG_OpenUserFeaturesKey(szProduct, &hkey, FALSE);
1385 if (rc != ERROR_SUCCESS)
1386 return INSTALLSTATE_UNKNOWN;
1388 parent_feature = msi_reg_get_val_str( hkey, szFeature );
1389 RegCloseKey(hkey);
1391 if (!parent_feature)
1392 return INSTALLSTATE_UNKNOWN;
1394 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
1395 msi_free(parent_feature);
1396 if (r == INSTALLSTATE_ABSENT)
1397 return r;
1399 /* now check if it's complete or advertised */
1400 rc = MSIREG_OpenUserDataFeaturesKey(szProduct, &hkey, FALSE);
1401 if (rc != ERROR_SUCCESS)
1402 return INSTALLSTATE_ADVERTISED;
1404 components = msi_reg_get_val_str( hkey, szFeature );
1405 RegCloseKey(hkey);
1407 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
1409 if (!components)
1410 return INSTALLSTATE_ADVERTISED;
1412 for( p = components; *p && *p != 2 ; p += 20)
1414 if (!decode_base85_guid( p, &guid ))
1416 if (p != components)
1417 break;
1419 msi_free(components);
1420 return INSTALLSTATE_BADCONFIG;
1423 StringFromGUID2(&guid, comp, GUID_SIZE);
1424 rc = MSIREG_OpenUserDataComponentKey(comp, &hkey, FALSE);
1425 if (rc != ERROR_SUCCESS)
1427 msi_free(components);
1428 return INSTALLSTATE_ADVERTISED;
1431 path = msi_reg_get_val_str(hkey, squishProduct);
1432 if (!path)
1433 missing = TRUE;
1435 msi_free(path);
1438 TRACE("%s %s -> %d\n", debugstr_w(szProduct), debugstr_w(szFeature), r);
1439 msi_free(components);
1441 if (missing)
1442 return INSTALLSTATE_ADVERTISED;
1444 return INSTALLSTATE_LOCAL;
1447 /******************************************************************
1448 * MsiGetFileVersionA [MSI.@]
1450 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
1451 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
1453 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
1454 UINT ret = ERROR_OUTOFMEMORY;
1456 if( szFilePath )
1458 szwFilePath = strdupAtoW( szFilePath );
1459 if( !szwFilePath )
1460 goto end;
1463 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
1465 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
1466 if( !lpwVersionBuff )
1467 goto end;
1470 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
1472 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
1473 if( !lpwLangBuff )
1474 goto end;
1477 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
1478 lpwLangBuff, pcchLangBuf);
1480 if( lpwVersionBuff )
1481 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
1482 lpVersionBuf, *pcchVersionBuf, NULL, NULL);
1483 if( lpwLangBuff )
1484 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
1485 lpLangBuf, *pcchLangBuf, NULL, NULL);
1487 end:
1488 msi_free(szwFilePath);
1489 msi_free(lpwVersionBuff);
1490 msi_free(lpwLangBuff);
1492 return ret;
1495 /******************************************************************
1496 * MsiGetFileVersionW [MSI.@]
1498 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
1499 LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
1501 static const WCHAR szVersionResource[] = {'\\',0};
1502 static const WCHAR szVersionFormat[] = {
1503 '%','d','.','%','d','.','%','d','.','%','d',0};
1504 static const WCHAR szLangFormat[] = {'%','d',0};
1505 UINT ret = 0;
1506 DWORD dwVerLen;
1507 LPVOID lpVer = NULL;
1508 VS_FIXEDFILEINFO *ffi;
1509 UINT puLen;
1510 WCHAR tmp[32];
1512 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
1513 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
1514 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
1516 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
1517 if( !dwVerLen )
1518 return GetLastError();
1520 lpVer = msi_alloc(dwVerLen);
1521 if( !lpVer )
1523 ret = ERROR_OUTOFMEMORY;
1524 goto end;
1527 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
1529 ret = GetLastError();
1530 goto end;
1532 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
1534 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
1535 (puLen > 0) )
1537 wsprintfW(tmp, szVersionFormat,
1538 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
1539 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
1540 lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
1541 *pcchVersionBuf = lstrlenW(lpVersionBuf);
1543 else
1545 *lpVersionBuf = 0;
1546 *pcchVersionBuf = 0;
1550 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
1552 DWORD lang = GetUserDefaultLangID();
1554 FIXME("Retrieve language from file\n");
1555 wsprintfW(tmp, szLangFormat, lang);
1556 lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
1557 *pcchLangBuf = lstrlenW(lpLangBuf);
1560 end:
1561 msi_free(lpVer);
1562 return ret;
1565 /***********************************************************************
1566 * MsiGetFeatureUsageW [MSI.@]
1568 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
1569 LPDWORD pdwUseCount, LPWORD pwDateUsed )
1571 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
1572 pdwUseCount, pwDateUsed);
1573 return ERROR_CALL_NOT_IMPLEMENTED;
1576 /***********************************************************************
1577 * MsiGetFeatureUsageA [MSI.@]
1579 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
1580 LPDWORD pdwUseCount, LPWORD pwDateUsed )
1582 LPWSTR prod = NULL, feat = NULL;
1583 UINT ret = ERROR_OUTOFMEMORY;
1585 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
1586 pdwUseCount, pwDateUsed);
1588 prod = strdupAtoW( szProduct );
1589 if (szProduct && !prod)
1590 goto end;
1592 feat = strdupAtoW( szFeature );
1593 if (szFeature && !feat)
1594 goto end;
1596 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
1598 end:
1599 msi_free( prod );
1600 msi_free( feat );
1602 return ret;
1605 /***********************************************************************
1606 * MsiUseFeatureExW [MSI.@]
1608 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
1609 DWORD dwInstallMode, DWORD dwReserved )
1611 INSTALLSTATE state;
1613 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
1614 dwInstallMode, dwReserved);
1616 state = MsiQueryFeatureStateW( szProduct, szFeature );
1618 if (dwReserved)
1619 return INSTALLSTATE_INVALIDARG;
1621 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
1623 FIXME("mark product %s feature %s as used\n",
1624 debugstr_w(szProduct), debugstr_w(szFeature) );
1627 return state;
1630 /***********************************************************************
1631 * MsiUseFeatureExA [MSI.@]
1633 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
1634 DWORD dwInstallMode, DWORD dwReserved )
1636 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
1637 LPWSTR prod = NULL, feat = NULL;
1639 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
1640 dwInstallMode, dwReserved);
1642 prod = strdupAtoW( szProduct );
1643 if (szProduct && !prod)
1644 goto end;
1646 feat = strdupAtoW( szFeature );
1647 if (szFeature && !feat)
1648 goto end;
1650 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
1652 end:
1653 msi_free( prod );
1654 msi_free( feat );
1656 return ret;
1659 /***********************************************************************
1660 * MsiUseFeatureW [MSI.@]
1662 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
1664 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
1667 /***********************************************************************
1668 * MsiUseFeatureA [MSI.@]
1670 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
1672 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
1675 /***********************************************************************
1676 * MSI_ProvideQualifiedComponentEx [internal]
1678 static UINT WINAPI MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
1679 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
1680 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
1681 LPDWORD pcchPathBuf)
1683 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
1684 feature[MAX_FEATURE_CHARS+1];
1685 LPWSTR info;
1686 HKEY hkey;
1687 DWORD sz;
1688 UINT rc;
1690 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
1691 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
1692 Unused1, Unused2, lpPathBuf, pcchPathBuf);
1694 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
1695 if (rc != ERROR_SUCCESS)
1696 return ERROR_INDEX_ABSENT;
1698 info = msi_reg_get_val_str( hkey, szQualifier );
1699 RegCloseKey(hkey);
1701 if (!info)
1702 return ERROR_INDEX_ABSENT;
1704 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
1706 if (!szProduct)
1707 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
1708 else
1709 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
1711 msi_free( info );
1713 if (rc != INSTALLSTATE_LOCAL)
1714 return ERROR_FILE_NOT_FOUND;
1716 return ERROR_SUCCESS;
1719 /***********************************************************************
1720 * MsiProvideQualifiedComponentExW [MSI.@]
1722 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
1723 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
1724 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
1725 LPDWORD pcchPathBuf)
1727 awstring path;
1729 path.unicode = TRUE;
1730 path.str.w = lpPathBuf;
1732 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
1733 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
1736 /***********************************************************************
1737 * MsiProvideQualifiedComponentExA [MSI.@]
1739 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
1740 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
1741 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
1742 LPDWORD pcchPathBuf)
1744 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
1745 UINT r = ERROR_OUTOFMEMORY;
1746 awstring path;
1748 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
1749 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
1750 Unused1, Unused2, lpPathBuf, pcchPathBuf);
1752 szwComponent = strdupAtoW( szComponent );
1753 if (szComponent && !szwComponent)
1754 goto end;
1756 szwQualifier = strdupAtoW( szQualifier );
1757 if (szQualifier && !szwQualifier)
1758 goto end;
1760 szwProduct = strdupAtoW( szProduct );
1761 if (szProduct && !szwProduct)
1762 goto end;
1764 path.unicode = FALSE;
1765 path.str.a = lpPathBuf;
1767 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
1768 dwInstallMode, szwProduct, Unused1,
1769 Unused2, &path, pcchPathBuf);
1770 end:
1771 msi_free(szwProduct);
1772 msi_free(szwComponent);
1773 msi_free(szwQualifier);
1775 return r;
1778 /***********************************************************************
1779 * MsiProvideQualifiedComponentW [MSI.@]
1781 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
1782 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
1783 LPDWORD pcchPathBuf)
1785 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
1786 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
1789 /***********************************************************************
1790 * MsiProvideQualifiedComponentA [MSI.@]
1792 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
1793 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
1794 LPDWORD pcchPathBuf)
1796 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
1797 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
1800 /***********************************************************************
1801 * MSI_GetUserInfo [internal]
1803 static USERINFOSTATE WINAPI MSI_GetUserInfo(LPCWSTR szProduct,
1804 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
1805 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
1806 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
1808 HKEY hkey;
1809 LPWSTR user, org, serial;
1810 UINT r;
1811 USERINFOSTATE state;
1813 TRACE("%s %p %p %p %p %p %p\n",debugstr_w(szProduct), lpUserNameBuf,
1814 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
1815 pcchSerialBuf);
1817 if (!szProduct)
1818 return USERINFOSTATE_INVALIDARG;
1820 r = MSIREG_OpenUninstallKey(szProduct, &hkey, FALSE);
1821 if (r != ERROR_SUCCESS)
1822 return USERINFOSTATE_UNKNOWN;
1824 user = msi_reg_get_val_str( hkey, INSTALLPROPERTY_REGOWNERW );
1825 org = msi_reg_get_val_str( hkey, INSTALLPROPERTY_REGCOMPANYW );
1826 serial = msi_reg_get_val_str( hkey, INSTALLPROPERTY_PRODUCTIDW );
1828 RegCloseKey(hkey);
1830 state = USERINFOSTATE_PRESENT;
1832 if (user)
1834 r = msi_strcpy_to_awstring( user, lpUserNameBuf, pcchUserNameBuf );
1835 if (r == ERROR_MORE_DATA)
1836 state = USERINFOSTATE_MOREDATA;
1838 else
1839 state = USERINFOSTATE_ABSENT;
1840 if (org)
1842 r = msi_strcpy_to_awstring( org, lpOrgNameBuf, pcchOrgNameBuf );
1843 if (r == ERROR_MORE_DATA && state == USERINFOSTATE_PRESENT)
1844 state = USERINFOSTATE_MOREDATA;
1846 /* msdn states: The user information is considered to be present even in the absence of a company name. */
1847 if (serial)
1849 r = msi_strcpy_to_awstring( serial, lpSerialBuf, pcchSerialBuf );
1850 if (r == ERROR_MORE_DATA && state == USERINFOSTATE_PRESENT)
1851 state = USERINFOSTATE_MOREDATA;
1853 else
1854 state = USERINFOSTATE_ABSENT;
1856 msi_free( user );
1857 msi_free( org );
1858 msi_free( serial );
1860 return state;
1863 /***********************************************************************
1864 * MsiGetUserInfoW [MSI.@]
1866 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
1867 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
1868 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
1869 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
1871 awstring user, org, serial;
1873 user.unicode = TRUE;
1874 user.str.w = lpUserNameBuf;
1875 org.unicode = TRUE;
1876 org.str.w = lpOrgNameBuf;
1877 serial.unicode = TRUE;
1878 serial.str.w = lpSerialBuf;
1880 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
1881 &org, pcchOrgNameBuf,
1882 &serial, pcchSerialBuf );
1885 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
1886 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
1887 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
1888 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
1890 awstring user, org, serial;
1891 LPWSTR prod;
1892 UINT r;
1894 prod = strdupAtoW( szProduct );
1895 if (szProduct && !prod)
1896 return ERROR_OUTOFMEMORY;
1898 user.unicode = FALSE;
1899 user.str.a = lpUserNameBuf;
1900 org.unicode = FALSE;
1901 org.str.a = lpOrgNameBuf;
1902 serial.unicode = FALSE;
1903 serial.str.a = lpSerialBuf;
1905 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
1906 &org, pcchOrgNameBuf,
1907 &serial, pcchSerialBuf );
1909 msi_free( prod );
1911 return r;
1914 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
1916 MSIHANDLE handle;
1917 UINT rc;
1918 MSIPACKAGE *package;
1919 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
1921 TRACE("(%s)\n",debugstr_w(szProduct));
1923 rc = MsiOpenProductW(szProduct,&handle);
1924 if (rc != ERROR_SUCCESS)
1925 return ERROR_INVALID_PARAMETER;
1927 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
1928 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
1929 msiobj_release( &package->hdr );
1931 MsiCloseHandle(handle);
1933 return rc;
1936 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
1938 MSIHANDLE handle;
1939 UINT rc;
1940 MSIPACKAGE *package;
1941 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
1943 TRACE("(%s)\n",debugstr_a(szProduct));
1945 rc = MsiOpenProductA(szProduct,&handle);
1946 if (rc != ERROR_SUCCESS)
1947 return ERROR_INVALID_PARAMETER;
1949 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
1950 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
1951 msiobj_release( &package->hdr );
1953 MsiCloseHandle(handle);
1955 return rc;
1958 /***********************************************************************
1959 * MsiConfigureFeatureA [MSI.@]
1961 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
1963 LPWSTR prod, feat = NULL;
1964 UINT r = ERROR_OUTOFMEMORY;
1966 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
1968 prod = strdupAtoW( szProduct );
1969 if (szProduct && !prod)
1970 goto end;
1972 feat = strdupAtoW( szFeature );
1973 if (szFeature && !feat)
1974 goto end;
1976 r = MsiConfigureFeatureW(prod, feat, eInstallState);
1978 end:
1979 msi_free(feat);
1980 msi_free(prod);
1982 return r;
1985 /***********************************************************************
1986 * MsiConfigureFeatureW [MSI.@]
1988 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
1990 static const WCHAR szCostInit[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
1991 MSIPACKAGE *package = NULL;
1992 UINT r;
1993 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
1994 DWORD sz;
1996 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
1998 if (!szProduct || !szFeature)
1999 return ERROR_INVALID_PARAMETER;
2001 switch (eInstallState)
2003 case INSTALLSTATE_DEFAULT:
2004 /* FIXME: how do we figure out the default location? */
2005 eInstallState = INSTALLSTATE_LOCAL;
2006 break;
2007 case INSTALLSTATE_LOCAL:
2008 case INSTALLSTATE_SOURCE:
2009 case INSTALLSTATE_ABSENT:
2010 case INSTALLSTATE_ADVERTISED:
2011 break;
2012 default:
2013 return ERROR_INVALID_PARAMETER;
2016 r = MSI_OpenProductW( szProduct, &package );
2017 if (r != ERROR_SUCCESS)
2018 return r;
2020 sz = sizeof(sourcepath);
2021 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2022 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
2024 sz = sizeof(filename);
2025 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2026 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
2028 lstrcatW( sourcepath, filename );
2030 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
2032 r = ACTION_PerformUIAction( package, szCostInit, -1 );
2033 if (r != ERROR_SUCCESS)
2034 goto end;
2036 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
2037 if (r != ERROR_SUCCESS)
2038 goto end;
2040 r = MSI_InstallPackage( package, sourcepath, NULL );
2042 end:
2043 msiobj_release( &package->hdr );
2045 return r;
2048 /***********************************************************************
2049 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
2051 * Notes: undocumented
2053 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
2055 WCHAR path[MAX_PATH];
2057 TRACE("%d\n", dwReserved);
2059 if (dwReserved)
2061 FIXME("dwReserved=%d\n", dwReserved);
2062 return ERROR_INVALID_PARAMETER;
2065 if (!GetWindowsDirectoryW(path, MAX_PATH))
2066 return ERROR_FUNCTION_FAILED;
2068 lstrcatW(path, installerW);
2070 if (!CreateDirectoryW(path, NULL))
2071 return ERROR_FUNCTION_FAILED;
2073 return ERROR_SUCCESS;
2076 /***********************************************************************
2077 * MsiGetShortcutTargetA [MSI.@]
2079 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
2080 LPSTR szProductCode, LPSTR szFeatureId,
2081 LPSTR szComponentCode )
2083 LPWSTR target;
2084 const int len = MAX_FEATURE_CHARS+1;
2085 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
2086 UINT r;
2088 target = strdupAtoW( szShortcutTarget );
2089 if (szShortcutTarget && !target )
2090 return ERROR_OUTOFMEMORY;
2091 product[0] = 0;
2092 feature[0] = 0;
2093 component[0] = 0;
2094 r = MsiGetShortcutTargetW( target, product, feature, component );
2095 msi_free( target );
2096 if (r == ERROR_SUCCESS)
2098 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
2099 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
2100 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
2102 return r;
2105 /***********************************************************************
2106 * MsiGetShortcutTargetW [MSI.@]
2108 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
2109 LPWSTR szProductCode, LPWSTR szFeatureId,
2110 LPWSTR szComponentCode )
2112 IShellLinkDataList *dl = NULL;
2113 IPersistFile *pf = NULL;
2114 LPEXP_DARWIN_LINK darwin = NULL;
2115 HRESULT r, init;
2117 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
2118 szProductCode, szFeatureId, szComponentCode );
2120 init = CoInitialize(NULL);
2122 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
2123 &IID_IPersistFile, (LPVOID*) &pf );
2124 if( SUCCEEDED( r ) )
2126 r = IPersistFile_Load( pf, szShortcutTarget,
2127 STGM_READ | STGM_SHARE_DENY_WRITE );
2128 if( SUCCEEDED( r ) )
2130 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
2131 (LPVOID*) &dl );
2132 if( SUCCEEDED( r ) )
2134 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
2135 (LPVOID) &darwin );
2136 IShellLinkDataList_Release( dl );
2139 IPersistFile_Release( pf );
2142 if (SUCCEEDED(init))
2143 CoUninitialize();
2145 TRACE("darwin = %p\n", darwin);
2147 if (darwin)
2149 DWORD sz;
2150 UINT ret;
2152 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
2153 szProductCode, szFeatureId, szComponentCode, &sz );
2154 LocalFree( darwin );
2155 return ret;
2158 return ERROR_FUNCTION_FAILED;
2161 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
2162 DWORD dwReinstallMode )
2164 MSIPACKAGE* package = NULL;
2165 UINT r;
2166 WCHAR sourcepath[MAX_PATH];
2167 WCHAR filename[MAX_PATH];
2168 static const WCHAR szLogVerbose[] = {
2169 ' ','L','O','G','V','E','R','B','O','S','E',0 };
2170 static const WCHAR szInstalled[] = { 'I','n','s','t','a','l','l','e','d',0};
2171 static const WCHAR szReinstall[] = {'R','E','I','N','S','T','A','L','L',0};
2172 static const WCHAR szReinstallMode[] = {'R','E','I','N','S','T','A','L','L','M','O','D','E',0};
2173 static const WCHAR szOne[] = {'1',0};
2174 WCHAR reinstallmode[11];
2175 LPWSTR ptr;
2176 DWORD sz;
2178 FIXME("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
2179 dwReinstallMode);
2181 ptr = reinstallmode;
2183 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
2184 *ptr++ = 'p';
2185 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
2186 *ptr++ = 'o';
2187 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
2188 *ptr++ = 'w';
2189 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
2190 *ptr++ = 'd';
2191 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
2192 *ptr++ = 'c';
2193 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
2194 *ptr++ = 'a';
2195 if (dwReinstallMode & REINSTALLMODE_USERDATA)
2196 *ptr++ = 'u';
2197 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
2198 *ptr++ = 'm';
2199 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
2200 *ptr++ = 's';
2201 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
2202 *ptr++ = 'v';
2203 *ptr = 0;
2205 sz = sizeof(sourcepath);
2206 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2207 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
2209 sz = sizeof(filename);
2210 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2211 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
2213 lstrcatW( sourcepath, filename );
2215 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
2216 r = MSI_OpenPackageW( sourcepath, &package );
2217 else
2218 r = MSI_OpenProductW( szProduct, &package );
2220 if (r != ERROR_SUCCESS)
2221 return r;
2223 MSI_SetPropertyW( package, szReinstallMode, reinstallmode );
2224 MSI_SetPropertyW( package, szInstalled, szOne );
2225 MSI_SetPropertyW( package, szLogVerbose, szOne );
2226 MSI_SetPropertyW( package, szReinstall, szFeature );
2228 r = MSI_InstallPackage( package, sourcepath, NULL );
2230 msiobj_release( &package->hdr );
2232 return r;
2235 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
2236 DWORD dwReinstallMode )
2238 LPWSTR wszProduct;
2239 LPWSTR wszFeature;
2240 UINT rc;
2242 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
2243 dwReinstallMode);
2245 wszProduct = strdupAtoW(szProduct);
2246 wszFeature = strdupAtoW(szFeature);
2248 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
2250 msi_free(wszProduct);
2251 msi_free(wszFeature);
2252 return rc;
2255 typedef struct
2257 unsigned int i[2];
2258 unsigned int buf[4];
2259 unsigned char in[64];
2260 unsigned char digest[16];
2261 } MD5_CTX;
2263 extern VOID WINAPI MD5Init( MD5_CTX *);
2264 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
2265 extern VOID WINAPI MD5Final( MD5_CTX *);
2267 /***********************************************************************
2268 * MsiGetFileHashW [MSI.@]
2270 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
2271 PMSIFILEHASHINFO pHash )
2273 HANDLE handle, mapping;
2274 void *p;
2275 DWORD length;
2276 UINT r = ERROR_FUNCTION_FAILED;
2278 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
2280 if (dwOptions)
2281 return ERROR_INVALID_PARAMETER;
2282 if (!pHash)
2283 return ERROR_INVALID_PARAMETER;
2284 if (pHash->dwFileHashInfoSize < sizeof *pHash)
2285 return ERROR_INVALID_PARAMETER;
2287 handle = CreateFileW( szFilePath, GENERIC_READ,
2288 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
2289 if (handle == INVALID_HANDLE_VALUE)
2290 return ERROR_FILE_NOT_FOUND;
2292 length = GetFileSize( handle, NULL );
2294 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
2295 if (mapping)
2297 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
2298 if (p)
2300 MD5_CTX ctx;
2302 MD5Init( &ctx );
2303 MD5Update( &ctx, p, length );
2304 MD5Final( &ctx );
2305 UnmapViewOfFile( p );
2307 memcpy( pHash->dwData, &ctx.digest, sizeof pHash->dwData );
2308 r = ERROR_SUCCESS;
2310 CloseHandle( mapping );
2312 CloseHandle( handle );
2314 return r;
2317 /***********************************************************************
2318 * MsiGetFileHashA [MSI.@]
2320 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
2321 PMSIFILEHASHINFO pHash )
2323 LPWSTR file;
2324 UINT r;
2326 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
2328 file = strdupAtoW( szFilePath );
2329 if (szFilePath && !file)
2330 return ERROR_OUTOFMEMORY;
2332 r = MsiGetFileHashW( file, dwOptions, pHash );
2333 msi_free( file );
2334 return r;
2337 /***********************************************************************
2338 * MsiAdvertiseScriptW [MSI.@]
2340 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
2341 PHKEY phRegData, BOOL fRemoveItems )
2343 FIXME("%s %08x %p %d\n",
2344 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
2345 return ERROR_CALL_NOT_IMPLEMENTED;
2348 /***********************************************************************
2349 * MsiAdvertiseScriptA [MSI.@]
2351 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
2352 PHKEY phRegData, BOOL fRemoveItems )
2354 FIXME("%s %08x %p %d\n",
2355 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
2356 return ERROR_CALL_NOT_IMPLEMENTED;