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_fmt[] = {
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','\\',
119 static const WCHAR szInstaller_UpgradeCodes_fmt[] = {
120 'S','o','f','t','w','a','r','e','\\',
121 'M','i','c','r','o','s','o','f','t','\\',
122 'W','i','n','d','o','w','s','\\',
123 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
124 'I','n','s','t','a','l','l','e','r','\\',
125 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
128 static const WCHAR szInstaller_UserUpgradeCodes_fmt[] = {
129 'S','o','f','t','w','a','r','e','\\',
130 'M','i','c','r','o','s','o','f','t','\\',
131 'I','n','s','t','a','l','l','e','r','\\',
132 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
136 #define SQUISH_GUID_SIZE 33
138 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
154 out[n++] = in[17+i*2];
155 out[n++] = in[16+i*2];
160 out[n++] = in[17+i*2];
161 out[n++] = in[16+i*2];
168 BOOL squash_guid(LPCWSTR in, LPWSTR out)
173 if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
187 out[17+i*2] = in[n++];
188 out[16+i*2] = in[n++];
193 out[17+i*2] = in[n++];
194 out[16+i*2] = in[n++];
201 /* tables for encoding and decoding base85 */
202 static const unsigned char table_dec85[0x80] = {
203 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
204 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
205 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
206 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
207 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
208 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
209 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
210 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
213 static const char table_enc85[] =
214 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
215 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
219 * Converts a base85 encoded guid into a GUID pointer
220 * Base85 encoded GUIDs should be 20 characters long.
222 * returns TRUE if successful, FALSE if not
224 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
226 DWORD i, val = 0, base = 1, *p;
232 for( i=0; i<20; i++ )
239 val += table_dec85[str[i]] * base;
242 if( table_dec85[str[i]] == 0xff )
252 * Encodes a base85 guid given a GUID pointer
253 * Caller should provide a 21 character buffer for the encoded string.
255 * returns TRUE if successful, FALSE if not
257 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
259 unsigned int x, *p, i;
261 p = (unsigned int*) guid;
265 *str++ = table_enc85[x%85];
267 *str++ = table_enc85[x%85];
269 *str++ = table_enc85[x%85];
271 *str++ = table_enc85[x%85];
273 *str++ = table_enc85[x%85];
280 DWORD msi_version_str_to_dword(LPCWSTR p)
282 DWORD major, minor = 0, build = 0, version = 0;
293 p = strchrW(p+1, '.');
298 return MAKELONG(build, MAKEWORD(minor, major));
301 LPWSTR msi_version_dword_to_str(DWORD version)
303 const WCHAR fmt[] = { '%','u','.','%','u','.','%','u',0 };
304 LPWSTR str = msi_alloc(20);
306 (version&0xff000000)>>24,
307 (version&0x00ff0000)>>16,
312 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
314 DWORD len = value ? (lstrlenW(value) + 1) * sizeof (WCHAR) : 0;
315 return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len );
318 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
321 while (*p) p += lstrlenW(p) + 1;
322 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
323 (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) );
326 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
328 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
331 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
336 r = RegCreateKeyW( hkey, path, &hsubkey );
337 if (r != ERROR_SUCCESS)
339 r = msi_reg_set_val_str( hsubkey, name, val );
340 RegCloseKey( hsubkey );
344 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
350 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
351 if (r != ERROR_SUCCESS)
354 len += sizeof (WCHAR);
355 val = msi_alloc( len );
359 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
363 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
365 DWORD type, len = sizeof (DWORD);
366 LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
367 return r == ERROR_SUCCESS && type == REG_DWORD;
370 UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create)
373 WCHAR keypath[0x200];
374 TRACE("%s\n",debugstr_w(szProduct));
376 sprintfW(keypath,szUninstall_fmt,szProduct);
379 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
381 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
386 UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
389 WCHAR squished_pc[GUID_SIZE];
390 WCHAR keypath[0x200];
392 TRACE("%s\n",debugstr_w(szProduct));
393 squash_guid(szProduct,squished_pc);
394 TRACE("squished (%s)\n", debugstr_w(squished_pc));
396 sprintfW(keypath,szUserProduct_fmt,squished_pc);
399 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
401 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
406 UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
409 WCHAR squished_pc[GUID_SIZE];
410 WCHAR keypath[0x200];
412 TRACE("%s\n",debugstr_w(szProduct));
413 squash_guid(szProduct,squished_pc);
414 TRACE("squished (%s)\n", debugstr_w(squished_pc));
416 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
419 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
421 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
426 UINT MSIREG_OpenFeatures(HKEY* key)
428 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Features,key);
431 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
434 WCHAR squished_pc[GUID_SIZE];
435 WCHAR keypath[0x200];
437 TRACE("%s\n",debugstr_w(szProduct));
438 squash_guid(szProduct,squished_pc);
439 TRACE("squished (%s)\n", debugstr_w(squished_pc));
441 sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
444 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
446 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
451 UINT MSIREG_OpenComponents(HKEY* key)
453 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Components,key);
456 UINT MSIREG_OpenComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
459 WCHAR squished_cc[GUID_SIZE];
460 WCHAR keypath[0x200];
462 TRACE("%s\n",debugstr_w(szComponent));
463 squash_guid(szComponent,squished_cc);
464 TRACE("squished (%s)\n", debugstr_w(squished_cc));
466 sprintfW(keypath,szInstaller_Components_fmt,squished_cc);
469 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
471 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
476 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
479 WCHAR squished_cc[GUID_SIZE];
480 WCHAR keypath[0x200];
482 TRACE("%s\n",debugstr_w(szComponent));
483 squash_guid(szComponent,squished_cc);
484 TRACE("squished (%s)\n", debugstr_w(squished_cc));
486 sprintfW(keypath,szUser_Components_fmt,squished_cc);
489 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
491 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
496 UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
499 WCHAR squished_pc[GUID_SIZE];
500 WCHAR keypath[0x200];
502 TRACE("%s\n",debugstr_w(szProduct));
503 squash_guid(szProduct,squished_pc);
504 TRACE("squished (%s)\n", debugstr_w(squished_pc));
506 sprintfW(keypath,szInstaller_Products_fmt,squished_pc);
509 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
511 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
516 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
519 WCHAR squished_pc[GUID_SIZE];
520 WCHAR keypath[0x200];
522 TRACE("%s\n",debugstr_w(szUpgradeCode));
523 squash_guid(szUpgradeCode,squished_pc);
524 TRACE("squished (%s)\n", debugstr_w(squished_pc));
526 sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
529 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
531 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
536 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
539 WCHAR squished_pc[GUID_SIZE];
540 WCHAR keypath[0x200];
542 TRACE("%s\n",debugstr_w(szUpgradeCode));
543 squash_guid(szUpgradeCode,squished_pc);
544 TRACE("squished (%s)\n", debugstr_w(squished_pc));
546 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
549 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
551 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
557 /*************************************************************************
558 * MsiDecomposeDescriptorW [MSI.@]
560 * Decomposes an MSI descriptor into product, feature and component parts.
561 * An MSI descriptor is a string of the form:
562 * [base 85 guid] [feature code] '>' [base 85 guid]
565 * szDescriptor [I] the descriptor to decompose
566 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
567 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
568 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
569 * pUsed [O] the length of the descriptor
572 * ERROR_SUCCESS if everything worked correctly
573 * ERROR_INVALID_PARAMETER if the descriptor was invalid
576 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
577 LPWSTR szFeature, LPWSTR szComponent, DWORD *pUsed )
581 GUID product, component;
583 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
584 szFeature, szComponent, pUsed);
586 r = decode_base85_guid( szDescriptor, &product );
588 return ERROR_INVALID_PARAMETER;
590 TRACE("product %s\n", debugstr_guid( &product ));
592 p = strchrW(&szDescriptor[20],'>');
594 return ERROR_INVALID_PARAMETER;
596 len = (p - &szDescriptor[20]);
597 if( len > MAX_FEATURE_CHARS )
598 return ERROR_INVALID_PARAMETER;
600 TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len ));
602 r = decode_base85_guid( p+1, &component );
604 return ERROR_INVALID_PARAMETER;
606 TRACE("component %s\n", debugstr_guid( &component ));
609 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
611 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
614 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
617 len = ( &p[21] - szDescriptor );
619 TRACE("length = %d\n", len);
622 return ERROR_SUCCESS;
625 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
626 LPSTR szFeature, LPSTR szComponent, DWORD *pUsed )
628 WCHAR product[MAX_FEATURE_CHARS+1];
629 WCHAR feature[MAX_FEATURE_CHARS+1];
630 WCHAR component[MAX_FEATURE_CHARS+1];
631 LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
634 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
635 szFeature, szComponent, pUsed);
637 str = strdupAtoW( szDescriptor );
638 if( szDescriptor && !str )
639 return ERROR_OUTOFMEMORY;
648 r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
650 if (r == ERROR_SUCCESS)
652 WideCharToMultiByte( CP_ACP, 0, p, -1,
653 szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
654 WideCharToMultiByte( CP_ACP, 0, f, -1,
655 szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
656 WideCharToMultiByte( CP_ACP, 0, c, -1,
657 szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
665 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
668 WCHAR szwGuid[GUID_SIZE];
670 TRACE("%d %p\n", index, lpguid);
673 return ERROR_INVALID_PARAMETER;
674 r = MsiEnumProductsW(index, szwGuid);
675 if( r == ERROR_SUCCESS )
676 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
681 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
683 HKEY hkeyFeatures = 0;
685 WCHAR szKeyName[SQUISH_GUID_SIZE];
687 TRACE("%d %p\n", index, lpguid);
690 return ERROR_INVALID_PARAMETER;
692 r = MSIREG_OpenFeatures(&hkeyFeatures);
693 if( r != ERROR_SUCCESS )
694 return ERROR_NO_MORE_ITEMS;
696 r = RegEnumKeyW(hkeyFeatures, index, szKeyName, SQUISH_GUID_SIZE);
697 if( r == ERROR_SUCCESS )
698 unsquash_guid(szKeyName, lpguid);
699 RegCloseKey(hkeyFeatures);
704 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
705 LPSTR szFeature, LPSTR szParent)
708 WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
709 LPWSTR szwProduct = NULL;
711 TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent);
715 szwProduct = strdupAtoW( szProduct );
717 return ERROR_OUTOFMEMORY;
720 r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
721 if( r == ERROR_SUCCESS )
723 WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
724 szFeature, GUID_SIZE, NULL, NULL);
725 WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
726 szParent, GUID_SIZE, NULL, NULL);
729 msi_free( szwProduct);
734 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
735 LPWSTR szFeature, LPWSTR szParent)
737 HKEY hkeyProduct = 0;
740 TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
743 return ERROR_INVALID_PARAMETER;
745 r = MSIREG_OpenFeaturesKey(szProduct,&hkeyProduct,FALSE);
746 if( r != ERROR_SUCCESS )
747 return ERROR_NO_MORE_ITEMS;
750 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
751 RegCloseKey(hkeyProduct);
756 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
759 WCHAR szwGuid[GUID_SIZE];
761 TRACE("%d %p\n", index, lpguid);
763 r = MsiEnumComponentsW(index, szwGuid);
764 if( r == ERROR_SUCCESS )
765 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
770 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
772 HKEY hkeyComponents = 0;
774 WCHAR szKeyName[SQUISH_GUID_SIZE];
776 TRACE("%d %p\n", index, lpguid);
778 r = MSIREG_OpenComponents(&hkeyComponents);
779 if( r != ERROR_SUCCESS )
780 return ERROR_NO_MORE_ITEMS;
782 r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
783 if( r == ERROR_SUCCESS )
784 unsquash_guid(szKeyName, lpguid);
785 RegCloseKey(hkeyComponents);
790 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
793 WCHAR szwProduct[GUID_SIZE];
794 LPWSTR szwComponent = NULL;
796 TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
800 szwComponent = strdupAtoW( szComponent );
802 return ERROR_OUTOFMEMORY;
805 r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
806 if( r == ERROR_SUCCESS )
808 WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
809 szProduct, GUID_SIZE, NULL, NULL);
812 msi_free( szwComponent);
817 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
821 WCHAR szValName[SQUISH_GUID_SIZE];
823 TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct);
825 r = MSIREG_OpenComponentsKey(szComponent,&hkeyComp,FALSE);
826 if( r != ERROR_SUCCESS )
827 return ERROR_NO_MORE_ITEMS;
829 sz = SQUISH_GUID_SIZE;
830 r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
831 if( r == ERROR_SUCCESS )
832 unsquash_guid(szValName, szProduct);
834 RegCloseKey(hkeyComp);
839 static UINT WINAPI MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
840 awstring *lpQualBuf, DWORD* pcchQual,
841 awstring *lpAppBuf, DWORD* pcchAppBuf )
843 DWORD name_sz, val_sz, name_max, val_max, type, ofs;
844 LPWSTR name = NULL, val = NULL;
848 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
849 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
852 return ERROR_INVALID_PARAMETER;
854 r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
855 if (r != ERROR_SUCCESS)
856 return ERROR_UNKNOWN_COMPONENT;
858 /* figure out how big the name is we want to return */
860 r = ERROR_OUTOFMEMORY;
861 name = msi_alloc( name_max * sizeof(WCHAR) );
866 r = ERROR_OUTOFMEMORY;
867 val = msi_alloc( val_max );
871 /* loop until we allocate enough memory */
876 r = RegEnumValueW( key, iIndex, name, &name_sz,
877 NULL, &type, (LPBYTE)val, &val_sz );
878 if (r == ERROR_SUCCESS)
880 if (r != ERROR_MORE_DATA)
883 if (type != REG_MULTI_SZ)
885 ERR("component data has wrong type (%d)\n", type);
889 r = ERROR_OUTOFMEMORY;
890 if ((name_sz+1) >= name_max)
894 name = msi_alloc( name_max * sizeof (WCHAR) );
899 if (val_sz > val_max)
901 val_max = val_sz + sizeof (WCHAR);
903 val = msi_alloc( val_max * sizeof (WCHAR) );
908 ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
913 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
914 if (r != ERROR_SUCCESS)
917 TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
919 r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
920 r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
922 if (r2 != ERROR_SUCCESS)
933 /*************************************************************************
934 * MsiEnumComponentQualifiersA [MSI.@]
936 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
937 LPSTR lpQualifierBuf, DWORD* pcchQualifierBuf,
938 LPSTR lpApplicationDataBuf, DWORD* pcchApplicationDataBuf )
940 awstring qual, appdata;
944 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex,
945 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
946 pcchApplicationDataBuf);
948 comp = strdupAtoW( szComponent );
949 if (szComponent && !comp)
950 return ERROR_OUTOFMEMORY;
952 qual.unicode = FALSE;
953 qual.str.a = lpQualifierBuf;
955 appdata.unicode = FALSE;
956 appdata.str.a = lpApplicationDataBuf;
958 r = MSI_EnumComponentQualifiers( comp, iIndex,
959 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
964 /*************************************************************************
965 * MsiEnumComponentQualifiersW [MSI.@]
967 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
968 LPWSTR lpQualifierBuf, DWORD* pcchQualifierBuf,
969 LPWSTR lpApplicationDataBuf, DWORD* pcchApplicationDataBuf )
971 awstring qual, appdata;
973 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
974 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
975 pcchApplicationDataBuf);
978 qual.str.w = lpQualifierBuf;
980 appdata.unicode = TRUE;
981 appdata.str.w = lpApplicationDataBuf;
983 return MSI_EnumComponentQualifiers( szComponent, iIndex,
984 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
987 /*************************************************************************
988 * MsiEnumRelatedProductsW [MSI.@]
991 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
992 DWORD iProductIndex, LPWSTR lpProductBuf)
996 WCHAR szKeyName[SQUISH_GUID_SIZE];
998 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved,
999 iProductIndex, lpProductBuf);
1001 if (NULL == szUpgradeCode)
1002 return ERROR_INVALID_PARAMETER;
1003 if (NULL == lpProductBuf)
1004 return ERROR_INVALID_PARAMETER;
1006 r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1007 if (r != ERROR_SUCCESS)
1008 return ERROR_NO_MORE_ITEMS;
1010 r = RegEnumKeyW(hkey, iProductIndex, szKeyName, SQUISH_GUID_SIZE);
1011 if( r == ERROR_SUCCESS )
1012 unsquash_guid(szKeyName, lpProductBuf);
1018 /*************************************************************************
1019 * MsiEnumRelatedProductsA [MSI.@]
1022 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1023 DWORD iProductIndex, LPSTR lpProductBuf)
1025 LPWSTR szwUpgradeCode = NULL;
1026 WCHAR productW[GUID_SIZE];
1029 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1030 iProductIndex, lpProductBuf);
1034 szwUpgradeCode = strdupAtoW( szUpgradeCode );
1035 if( !szwUpgradeCode )
1036 return ERROR_OUTOFMEMORY;
1039 r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1040 iProductIndex, productW );
1041 if (r == ERROR_SUCCESS)
1043 WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1044 lpProductBuf, GUID_SIZE, NULL, NULL );
1046 msi_free( szwUpgradeCode);
1050 /***********************************************************************
1051 * MsiEnumPatchesA [MSI.@]
1053 UINT WINAPI MsiEnumPatchesA( LPCSTR szProduct, DWORD iPatchIndex,
1054 LPSTR lpPatchBuf, LPSTR lpTransformsBuf, DWORD* pcchTransformsBuf)
1056 FIXME("%s %d %p %p %p\n", debugstr_a(szProduct),
1057 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1058 return ERROR_NO_MORE_ITEMS;
1061 /***********************************************************************
1062 * MsiEnumPatchesW [MSI.@]
1064 UINT WINAPI MsiEnumPatchesW( LPCWSTR szProduct, DWORD iPatchIndex,
1065 LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, DWORD* pcchTransformsBuf)
1067 FIXME("%s %d %p %p %p\n", debugstr_w(szProduct),
1068 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1069 return ERROR_NO_MORE_ITEMS;