2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2005 Aric Stewart for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define NONAMELESSUNION
32 #include "wine/debug.h"
36 #include "wine/unicode.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msi);
44 * This module will be all the helper functions for registry access by the
47 static const WCHAR szUserFeatures_fmt[] = {
48 'S','o','f','t','w','a','r','e','\\',
49 'M','i','c','r','o','s','o','f','t','\\',
50 'I','n','s','t','a','l','l','e','r','\\',
51 'F','e','a','t','u','r','e','s','\\',
54 static const WCHAR szInstaller_Features[] = {
55 'S','o','f','t','w','a','r','e','\\',
56 'M','i','c','r','o','s','o','f','t','\\',
57 'W','i','n','d','o','w','s','\\',
58 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
59 'I','n','s','t','a','l','l','e','r','\\',
60 'F','e','a','t','u','r','e','s',0 };
62 static const WCHAR szInstaller_Features_fmt[] = {
63 'S','o','f','t','w','a','r','e','\\',
64 'M','i','c','r','o','s','o','f','t','\\',
65 'W','i','n','d','o','w','s','\\',
66 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
67 'I','n','s','t','a','l','l','e','r','\\',
68 'F','e','a','t','u','r','e','s','\\',
71 static const WCHAR szInstaller_Components[] = {
72 'S','o','f','t','w','a','r','e','\\',
73 'M','i','c','r','o','s','o','f','t','\\',
74 'W','i','n','d','o','w','s','\\',
75 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
76 'I','n','s','t','a','l','l','e','r','\\',
77 'C','o','m','p','o','n','e','n','t','s',0 };
79 static const WCHAR szInstaller_Components_fmt[] = {
80 'S','o','f','t','w','a','r','e','\\',
81 'M','i','c','r','o','s','o','f','t','\\',
82 'W','i','n','d','o','w','s','\\',
83 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
84 'I','n','s','t','a','l','l','e','r','\\',
85 'C','o','m','p','o','n','e','n','t','s','\\',
88 static const WCHAR szUser_Components_fmt[] = {
89 'S','o','f','t','w','a','r','e','\\',
90 'M','i','c','r','o','s','o','f','t','\\',
91 'I','n','s','t','a','l','l','e','r','\\',
92 'C','o','m','p','o','n','e','n','t','s','\\',
95 static const WCHAR szUninstall_fmt[] = {
96 'S','o','f','t','w','a','r','e','\\',
97 'M','i','c','r','o','s','o','f','t','\\',
98 'W','i','n','d','o','w','s','\\',
99 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
100 'U','n','i','n','s','t','a','l','l','\\',
103 static const WCHAR szUserProduct_fmt[] = {
104 'S','o','f','t','w','a','r','e','\\',
105 'M','i','c','r','o','s','o','f','t','\\',
106 'I','n','s','t','a','l','l','e','r','\\',
107 'P','r','o','d','u','c','t','s','\\',
110 static const WCHAR szInstaller_Products[] = {
111 'S','o','f','t','w','a','r','e','\\',
112 'M','i','c','r','o','s','o','f','t','\\',
113 'W','i','n','d','o','w','s','\\',
114 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
115 'I','n','s','t','a','l','l','e','r','\\',
116 'P','r','o','d','u','c','t','s',0};
118 static const WCHAR szInstaller_Products_fmt[] = {
119 'S','o','f','t','w','a','r','e','\\',
120 'M','i','c','r','o','s','o','f','t','\\',
121 'W','i','n','d','o','w','s','\\',
122 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
123 'I','n','s','t','a','l','l','e','r','\\',
124 'P','r','o','d','u','c','t','s','\\',
127 static const WCHAR szInstaller_UpgradeCodes_fmt[] = {
128 'S','o','f','t','w','a','r','e','\\',
129 'M','i','c','r','o','s','o','f','t','\\',
130 'W','i','n','d','o','w','s','\\',
131 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
132 'I','n','s','t','a','l','l','e','r','\\',
133 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
136 static const WCHAR szInstaller_UserUpgradeCodes_fmt[] = {
137 'S','o','f','t','w','a','r','e','\\',
138 'M','i','c','r','o','s','o','f','t','\\',
139 'I','n','s','t','a','l','l','e','r','\\',
140 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
144 #define SQUISH_GUID_SIZE 33
146 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
162 out[n++] = in[17+i*2];
163 out[n++] = in[16+i*2];
168 out[n++] = in[17+i*2];
169 out[n++] = in[16+i*2];
176 BOOL squash_guid(LPCWSTR in, LPWSTR out)
181 if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
195 out[17+i*2] = in[n++];
196 out[16+i*2] = in[n++];
201 out[17+i*2] = in[n++];
202 out[16+i*2] = in[n++];
209 /* tables for encoding and decoding base85 */
210 static const unsigned char table_dec85[0x80] = {
211 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
212 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
213 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
214 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
215 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
216 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
217 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
218 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
221 static const char table_enc85[] =
222 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
223 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
227 * Converts a base85 encoded guid into a GUID pointer
228 * Base85 encoded GUIDs should be 20 characters long.
230 * returns TRUE if successful, FALSE if not
232 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
234 DWORD i, val = 0, base = 1, *p;
240 for( i=0; i<20; i++ )
247 val += table_dec85[str[i]] * base;
250 if( table_dec85[str[i]] == 0xff )
260 * Encodes a base85 guid given a GUID pointer
261 * Caller should provide a 21 character buffer for the encoded string.
263 * returns TRUE if successful, FALSE if not
265 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
267 unsigned int x, *p, i;
269 p = (unsigned int*) guid;
273 *str++ = table_enc85[x%85];
275 *str++ = table_enc85[x%85];
277 *str++ = table_enc85[x%85];
279 *str++ = table_enc85[x%85];
281 *str++ = table_enc85[x%85];
288 DWORD msi_version_str_to_dword(LPCWSTR p)
290 DWORD major, minor = 0, build = 0, version = 0;
301 p = strchrW(p+1, '.');
306 return MAKELONG(build, MAKEWORD(minor, major));
309 LPWSTR msi_version_dword_to_str(DWORD version)
311 const WCHAR fmt[] = { '%','u','.','%','u','.','%','u',0 };
312 LPWSTR str = msi_alloc(20);
314 (version&0xff000000)>>24,
315 (version&0x00ff0000)>>16,
320 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
322 DWORD len = value ? (lstrlenW(value) + 1) * sizeof (WCHAR) : 0;
323 return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len );
326 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
329 while (*p) p += lstrlenW(p) + 1;
330 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
331 (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) );
334 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
336 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
339 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
344 r = RegCreateKeyW( hkey, path, &hsubkey );
345 if (r != ERROR_SUCCESS)
347 r = msi_reg_set_val_str( hsubkey, name, val );
348 RegCloseKey( hsubkey );
352 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
358 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
359 if (r != ERROR_SUCCESS)
362 len += sizeof (WCHAR);
363 val = msi_alloc( len );
367 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
371 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
373 DWORD type, len = sizeof (DWORD);
374 LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
375 return r == ERROR_SUCCESS && type == REG_DWORD;
378 UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create)
381 WCHAR keypath[0x200];
382 TRACE("%s\n",debugstr_w(szProduct));
384 sprintfW(keypath,szUninstall_fmt,szProduct);
387 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
389 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
394 UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
397 WCHAR squished_pc[GUID_SIZE];
398 WCHAR keypath[0x200];
400 TRACE("%s\n",debugstr_w(szProduct));
401 squash_guid(szProduct,squished_pc);
402 TRACE("squished (%s)\n", debugstr_w(squished_pc));
404 sprintfW(keypath,szUserProduct_fmt,squished_pc);
407 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
409 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
414 UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
417 WCHAR squished_pc[GUID_SIZE];
418 WCHAR keypath[0x200];
420 TRACE("%s\n",debugstr_w(szProduct));
421 squash_guid(szProduct,squished_pc);
422 TRACE("squished (%s)\n", debugstr_w(squished_pc));
424 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
427 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
429 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
434 UINT MSIREG_OpenFeatures(HKEY* key)
436 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Features,key);
439 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
442 WCHAR squished_pc[GUID_SIZE];
443 WCHAR keypath[0x200];
445 TRACE("%s\n",debugstr_w(szProduct));
446 squash_guid(szProduct,squished_pc);
447 TRACE("squished (%s)\n", debugstr_w(squished_pc));
449 sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
452 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
454 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
459 UINT MSIREG_OpenComponents(HKEY* key)
461 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Components,key);
464 UINT MSIREG_OpenComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
467 WCHAR squished_cc[GUID_SIZE];
468 WCHAR keypath[0x200];
470 TRACE("%s\n",debugstr_w(szComponent));
471 squash_guid(szComponent,squished_cc);
472 TRACE("squished (%s)\n", debugstr_w(squished_cc));
474 sprintfW(keypath,szInstaller_Components_fmt,squished_cc);
477 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
479 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
484 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
487 WCHAR squished_cc[GUID_SIZE];
488 WCHAR keypath[0x200];
490 TRACE("%s\n",debugstr_w(szComponent));
491 squash_guid(szComponent,squished_cc);
492 TRACE("squished (%s)\n", debugstr_w(squished_cc));
494 sprintfW(keypath,szUser_Components_fmt,squished_cc);
497 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
499 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
504 UINT MSIREG_OpenProducts(HKEY* key)
506 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Products,key);
509 UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
512 WCHAR squished_pc[GUID_SIZE];
513 WCHAR keypath[0x200];
515 TRACE("%s\n",debugstr_w(szProduct));
516 squash_guid(szProduct,squished_pc);
517 TRACE("squished (%s)\n", debugstr_w(squished_pc));
519 sprintfW(keypath,szInstaller_Products_fmt,squished_pc);
522 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
524 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
529 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
532 WCHAR squished_pc[GUID_SIZE];
533 WCHAR keypath[0x200];
535 TRACE("%s\n",debugstr_w(szUpgradeCode));
536 squash_guid(szUpgradeCode,squished_pc);
537 TRACE("squished (%s)\n", debugstr_w(squished_pc));
539 sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
542 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
544 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
549 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
552 WCHAR squished_pc[GUID_SIZE];
553 WCHAR keypath[0x200];
555 TRACE("%s\n",debugstr_w(szUpgradeCode));
556 squash_guid(szUpgradeCode,squished_pc);
557 TRACE("squished (%s)\n", debugstr_w(squished_pc));
559 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
562 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
564 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
570 /*************************************************************************
571 * MsiDecomposeDescriptorW [MSI.@]
573 * Decomposes an MSI descriptor into product, feature and component parts.
574 * An MSI descriptor is a string of the form:
575 * [base 85 guid] [feature code] '>' [base 85 guid]
578 * szDescriptor [I] the descriptor to decompose
579 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
580 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
581 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
582 * pUsed [O] the length of the descriptor
585 * ERROR_SUCCESS if everything worked correctly
586 * ERROR_INVALID_PARAMETER if the descriptor was invalid
589 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
590 LPWSTR szFeature, LPWSTR szComponent, DWORD *pUsed )
594 GUID product, component;
596 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
597 szFeature, szComponent, pUsed);
599 r = decode_base85_guid( szDescriptor, &product );
601 return ERROR_INVALID_PARAMETER;
603 TRACE("product %s\n", debugstr_guid( &product ));
605 p = strchrW(&szDescriptor[20],'>');
607 return ERROR_INVALID_PARAMETER;
609 len = (p - &szDescriptor[20]);
610 if( len > MAX_FEATURE_CHARS )
611 return ERROR_INVALID_PARAMETER;
613 TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len ));
615 r = decode_base85_guid( p+1, &component );
617 return ERROR_INVALID_PARAMETER;
619 TRACE("component %s\n", debugstr_guid( &component ));
622 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
624 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
627 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
630 len = ( &p[21] - szDescriptor );
632 TRACE("length = %d\n", len);
635 return ERROR_SUCCESS;
638 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
639 LPSTR szFeature, LPSTR szComponent, DWORD *pUsed )
641 WCHAR product[MAX_FEATURE_CHARS+1];
642 WCHAR feature[MAX_FEATURE_CHARS+1];
643 WCHAR component[MAX_FEATURE_CHARS+1];
644 LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
647 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
648 szFeature, szComponent, pUsed);
650 str = strdupAtoW( szDescriptor );
651 if( szDescriptor && !str )
652 return ERROR_OUTOFMEMORY;
661 r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
663 if (r == ERROR_SUCCESS)
665 WideCharToMultiByte( CP_ACP, 0, p, -1,
666 szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
667 WideCharToMultiByte( CP_ACP, 0, f, -1,
668 szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
669 WideCharToMultiByte( CP_ACP, 0, c, -1,
670 szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
678 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
681 WCHAR szwGuid[GUID_SIZE];
683 TRACE("%d %p\n", index, lpguid);
686 return ERROR_INVALID_PARAMETER;
687 r = MsiEnumProductsW(index, szwGuid);
688 if( r == ERROR_SUCCESS )
689 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
694 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
696 HKEY hkeyProducts = 0;
698 WCHAR szKeyName[SQUISH_GUID_SIZE];
700 TRACE("%d %p\n", index, lpguid);
703 return ERROR_INVALID_PARAMETER;
705 r = MSIREG_OpenProducts(&hkeyProducts);
706 if( r != ERROR_SUCCESS )
707 return ERROR_NO_MORE_ITEMS;
709 r = RegEnumKeyW(hkeyProducts, index, szKeyName, SQUISH_GUID_SIZE);
710 if( r == ERROR_SUCCESS )
711 unsquash_guid(szKeyName, lpguid);
712 RegCloseKey(hkeyProducts);
717 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
718 LPSTR szFeature, LPSTR szParent)
721 WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
722 LPWSTR szwProduct = NULL;
724 TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent);
728 szwProduct = strdupAtoW( szProduct );
730 return ERROR_OUTOFMEMORY;
733 r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
734 if( r == ERROR_SUCCESS )
736 WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
737 szFeature, GUID_SIZE, NULL, NULL);
738 WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
739 szParent, GUID_SIZE, NULL, NULL);
742 msi_free( szwProduct);
747 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
748 LPWSTR szFeature, LPWSTR szParent)
750 HKEY hkeyProduct = 0;
753 TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
756 return ERROR_INVALID_PARAMETER;
758 r = MSIREG_OpenFeaturesKey(szProduct,&hkeyProduct,FALSE);
759 if( r != ERROR_SUCCESS )
760 return ERROR_NO_MORE_ITEMS;
763 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
764 RegCloseKey(hkeyProduct);
769 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
772 WCHAR szwGuid[GUID_SIZE];
774 TRACE("%d %p\n", index, lpguid);
776 r = MsiEnumComponentsW(index, szwGuid);
777 if( r == ERROR_SUCCESS )
778 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
783 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
785 HKEY hkeyComponents = 0;
787 WCHAR szKeyName[SQUISH_GUID_SIZE];
789 TRACE("%d %p\n", index, lpguid);
791 r = MSIREG_OpenComponents(&hkeyComponents);
792 if( r != ERROR_SUCCESS )
793 return ERROR_NO_MORE_ITEMS;
795 r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
796 if( r == ERROR_SUCCESS )
797 unsquash_guid(szKeyName, lpguid);
798 RegCloseKey(hkeyComponents);
803 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
806 WCHAR szwProduct[GUID_SIZE];
807 LPWSTR szwComponent = NULL;
809 TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
813 szwComponent = strdupAtoW( szComponent );
815 return ERROR_OUTOFMEMORY;
818 r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
819 if( r == ERROR_SUCCESS )
821 WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
822 szProduct, GUID_SIZE, NULL, NULL);
825 msi_free( szwComponent);
830 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
834 WCHAR szValName[SQUISH_GUID_SIZE];
836 TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct);
838 r = MSIREG_OpenComponentsKey(szComponent,&hkeyComp,FALSE);
839 if( r != ERROR_SUCCESS )
840 return ERROR_NO_MORE_ITEMS;
842 sz = SQUISH_GUID_SIZE;
843 r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
844 if( r == ERROR_SUCCESS )
845 unsquash_guid(szValName, szProduct);
847 RegCloseKey(hkeyComp);
852 static UINT WINAPI MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
853 awstring *lpQualBuf, DWORD* pcchQual,
854 awstring *lpAppBuf, DWORD* pcchAppBuf )
856 DWORD name_sz, val_sz, name_max, val_max, type, ofs;
857 LPWSTR name = NULL, val = NULL;
861 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
862 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
865 return ERROR_INVALID_PARAMETER;
867 r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
868 if (r != ERROR_SUCCESS)
869 return ERROR_UNKNOWN_COMPONENT;
871 /* figure out how big the name is we want to return */
873 r = ERROR_OUTOFMEMORY;
874 name = msi_alloc( name_max * sizeof(WCHAR) );
879 r = ERROR_OUTOFMEMORY;
880 val = msi_alloc( val_max );
884 /* loop until we allocate enough memory */
889 r = RegEnumValueW( key, iIndex, name, &name_sz,
890 NULL, &type, (LPBYTE)val, &val_sz );
891 if (r == ERROR_SUCCESS)
893 if (r != ERROR_MORE_DATA)
896 if (type != REG_MULTI_SZ)
898 ERR("component data has wrong type (%d)\n", type);
902 r = ERROR_OUTOFMEMORY;
903 if ((name_sz+1) >= name_max)
907 name = msi_alloc( name_max * sizeof (WCHAR) );
912 if (val_sz > val_max)
914 val_max = val_sz + sizeof (WCHAR);
916 val = msi_alloc( val_max * sizeof (WCHAR) );
921 ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
926 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
927 if (r != ERROR_SUCCESS)
930 TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
932 r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
933 r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
935 if (r2 != ERROR_SUCCESS)
946 /*************************************************************************
947 * MsiEnumComponentQualifiersA [MSI.@]
949 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
950 LPSTR lpQualifierBuf, DWORD* pcchQualifierBuf,
951 LPSTR lpApplicationDataBuf, DWORD* pcchApplicationDataBuf )
953 awstring qual, appdata;
957 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex,
958 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
959 pcchApplicationDataBuf);
961 comp = strdupAtoW( szComponent );
962 if (szComponent && !comp)
963 return ERROR_OUTOFMEMORY;
965 qual.unicode = FALSE;
966 qual.str.a = lpQualifierBuf;
968 appdata.unicode = FALSE;
969 appdata.str.a = lpApplicationDataBuf;
971 r = MSI_EnumComponentQualifiers( comp, iIndex,
972 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
977 /*************************************************************************
978 * MsiEnumComponentQualifiersW [MSI.@]
980 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
981 LPWSTR lpQualifierBuf, DWORD* pcchQualifierBuf,
982 LPWSTR lpApplicationDataBuf, DWORD* pcchApplicationDataBuf )
984 awstring qual, appdata;
986 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
987 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
988 pcchApplicationDataBuf);
991 qual.str.w = lpQualifierBuf;
993 appdata.unicode = TRUE;
994 appdata.str.w = lpApplicationDataBuf;
996 return MSI_EnumComponentQualifiers( szComponent, iIndex,
997 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1000 /*************************************************************************
1001 * MsiEnumRelatedProductsW [MSI.@]
1004 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
1005 DWORD iProductIndex, LPWSTR lpProductBuf)
1009 DWORD dwSize = SQUISH_GUID_SIZE;
1010 WCHAR szKeyName[SQUISH_GUID_SIZE];
1012 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved,
1013 iProductIndex, lpProductBuf);
1015 if (NULL == szUpgradeCode)
1016 return ERROR_INVALID_PARAMETER;
1017 if (NULL == lpProductBuf)
1018 return ERROR_INVALID_PARAMETER;
1020 r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1021 if (r != ERROR_SUCCESS)
1022 return ERROR_NO_MORE_ITEMS;
1024 r = RegEnumValueW(hkey, iProductIndex, szKeyName, &dwSize, NULL, NULL, NULL, NULL);
1025 if( r == ERROR_SUCCESS )
1026 unsquash_guid(szKeyName, lpProductBuf);
1032 /*************************************************************************
1033 * MsiEnumRelatedProductsA [MSI.@]
1036 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1037 DWORD iProductIndex, LPSTR lpProductBuf)
1039 LPWSTR szwUpgradeCode = NULL;
1040 WCHAR productW[GUID_SIZE];
1043 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1044 iProductIndex, lpProductBuf);
1048 szwUpgradeCode = strdupAtoW( szUpgradeCode );
1049 if( !szwUpgradeCode )
1050 return ERROR_OUTOFMEMORY;
1053 r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1054 iProductIndex, productW );
1055 if (r == ERROR_SUCCESS)
1057 WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1058 lpProductBuf, GUID_SIZE, NULL, NULL );
1060 msi_free( szwUpgradeCode);
1064 /***********************************************************************
1065 * MsiEnumPatchesA [MSI.@]
1067 UINT WINAPI MsiEnumPatchesA( LPCSTR szProduct, DWORD iPatchIndex,
1068 LPSTR lpPatchBuf, LPSTR lpTransformsBuf, DWORD* pcchTransformsBuf)
1070 FIXME("%s %d %p %p %p\n", debugstr_a(szProduct),
1071 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1072 return ERROR_NO_MORE_ITEMS;
1075 /***********************************************************************
1076 * MsiEnumPatchesW [MSI.@]
1078 UINT WINAPI MsiEnumPatchesW( LPCWSTR szProduct, DWORD iPatchIndex,
1079 LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, DWORD* pcchTransformsBuf)
1081 FIXME("%s %d %p %p %p\n", debugstr_w(szProduct),
1082 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1083 return ERROR_NO_MORE_ITEMS;
1086 UINT WINAPI MsiEnumProductsExA( LPCSTR szProductCode, LPCSTR szUserSid,
1087 DWORD dwContext, DWORD dwIndex, LPSTR szInstalledProductCode,
1088 MSIINSTALLCONTEXT* pdwInstalledContext, LPSTR szSid, LPDWORD pcchSid)
1090 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_a(szProductCode), debugstr_a(szUserSid),
1091 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1093 return ERROR_NO_MORE_ITEMS;
1096 UINT WINAPI MsiEnumProductsExW( LPCWSTR szProductCode, LPCWSTR szUserSid,
1097 DWORD dwContext, DWORD dwIndex, LPWSTR szInstalledProductCode,
1098 MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, LPDWORD pcchSid)
1100 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_w(szProductCode), debugstr_w(szUserSid),
1101 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1103 return ERROR_NO_MORE_ITEMS;