wined3d: Add a comment about D3D write masks and GLSL destination swizzles.
[wine/dibdrv.git] / dlls / msi / registry.c
blob1aa1303aa4a95be1bda26224a6baaac9d9b9e468
1 /*
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
22 #include <stdarg.h>
24 #define COBJMACROS
25 #define NONAMELESSUNION
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winreg.h"
30 #include "winnls.h"
31 #include "shlwapi.h"
32 #include "wine/debug.h"
33 #include "msi.h"
34 #include "msipriv.h"
35 #include "wincrypt.h"
36 #include "wine/unicode.h"
37 #include "winver.h"
38 #include "winuser.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msi);
43 /*
44 * This module will be all the helper functions for registry access by the
45 * installer bits.
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','\\',
52 '%','s',0};
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','\\',
69 '%','s',0};
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','\\',
86 '%','s',0};
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','\\',
93 '%','s',0};
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','\\',
101 '%','s',0 };
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','\\',
108 '%','s',0};
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','\\',
117 '%','s',0};
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','\\',
126 '%','s',0};
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','\\',
133 '%','s',0};
136 #define SQUISH_GUID_SIZE 33
138 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
140 DWORD i,n=0;
142 out[n++]='{';
143 for(i=0; i<8; i++)
144 out[n++] = in[7-i];
145 out[n++]='-';
146 for(i=0; i<4; i++)
147 out[n++] = in[11-i];
148 out[n++]='-';
149 for(i=0; i<4; i++)
150 out[n++] = in[15-i];
151 out[n++]='-';
152 for(i=0; i<2; i++)
154 out[n++] = in[17+i*2];
155 out[n++] = in[16+i*2];
157 out[n++]='-';
158 for( ; i<8; i++)
160 out[n++] = in[17+i*2];
161 out[n++] = in[16+i*2];
163 out[n++]='}';
164 out[n]=0;
165 return TRUE;
168 BOOL squash_guid(LPCWSTR in, LPWSTR out)
170 DWORD i,n=1;
171 GUID guid;
173 if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
174 return FALSE;
176 for(i=0; i<8; i++)
177 out[7-i] = in[n++];
178 n++;
179 for(i=0; i<4; i++)
180 out[11-i] = in[n++];
181 n++;
182 for(i=0; i<4; i++)
183 out[15-i] = in[n++];
184 n++;
185 for(i=0; i<2; i++)
187 out[17+i*2] = in[n++];
188 out[16+i*2] = in[n++];
190 n++;
191 for( ; i<8; i++)
193 out[17+i*2] = in[n++];
194 out[16+i*2] = in[n++];
196 out[32]=0;
197 return TRUE;
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"
216 "yz{}~";
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;
228 if (!str)
229 return FALSE;
231 p = (DWORD*) guid;
232 for( i=0; i<20; i++ )
234 if( (i%5) == 0 )
236 val = 0;
237 base = 1;
239 val += table_dec85[str[i]] * base;
240 if( str[i] >= 0x80 )
241 return FALSE;
242 if( table_dec85[str[i]] == 0xff )
243 return FALSE;
244 if( (i%5) == 4 )
245 p[i/5] = val;
246 base *= 85;
248 return TRUE;
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;
262 for( i=0; i<4; i++ )
264 x = p[i];
265 *str++ = table_enc85[x%85];
266 x = x/85;
267 *str++ = table_enc85[x%85];
268 x = x/85;
269 *str++ = table_enc85[x%85];
270 x = x/85;
271 *str++ = table_enc85[x%85];
272 x = x/85;
273 *str++ = table_enc85[x%85];
275 *str = 0;
277 return TRUE;
280 DWORD msi_version_str_to_dword(LPCWSTR p)
282 DWORD major, minor = 0, build = 0, version = 0;
284 if (!p)
285 return version;
287 major = atoiW(p);
289 p = strchrW(p, '.');
290 if (p)
292 minor = atoiW(p+1);
293 p = strchrW(p+1, '.');
294 if (p)
295 build = atoiW(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);
305 sprintfW(str, fmt,
306 (version&0xff000000)>>24,
307 (version&0x00ff0000)>>16,
308 version&0x0000ffff);
309 return str;
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 )
320 LPCWSTR p = 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 )
333 HKEY hsubkey = 0;
334 LONG r;
336 r = RegCreateKeyW( hkey, path, &hsubkey );
337 if (r != ERROR_SUCCESS)
338 return r;
339 r = msi_reg_set_val_str( hsubkey, name, val );
340 RegCloseKey( hsubkey );
341 return r;
344 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
346 DWORD len = 0;
347 LPWSTR val;
348 LONG r;
350 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
351 if (r != ERROR_SUCCESS)
352 return NULL;
354 len += sizeof (WCHAR);
355 val = msi_alloc( len );
356 if (!val)
357 return NULL;
358 val[0] = 0;
359 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
360 return val;
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)
372 UINT rc;
373 WCHAR keypath[0x200];
374 TRACE("%s\n",debugstr_w(szProduct));
376 sprintfW(keypath,szUninstall_fmt,szProduct);
378 if (create)
379 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
380 else
381 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
383 return rc;
386 UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
388 UINT rc;
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);
398 if (create)
399 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
400 else
401 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
403 return rc;
406 UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
408 UINT rc;
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);
418 if (create)
419 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
420 else
421 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
423 return rc;
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)
433 UINT rc;
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);
443 if (create)
444 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
445 else
446 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
448 return rc;
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)
458 UINT rc;
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);
468 if (create)
469 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
470 else
471 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
473 return rc;
476 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
478 UINT rc;
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);
488 if (create)
489 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
490 else
491 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
493 return rc;
496 UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
498 UINT rc;
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);
508 if (create)
509 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
510 else
511 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
513 return rc;
516 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
518 UINT rc;
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);
528 if (create)
529 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
530 else
531 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
533 return rc;
536 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
538 UINT rc;
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);
548 if (create)
549 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
550 else
551 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
553 return rc;
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]
564 * PARAMS
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
571 * RETURNS
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 )
579 UINT r, len;
580 LPWSTR p;
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 );
587 if( !r )
588 return ERROR_INVALID_PARAMETER;
590 TRACE("product %s\n", debugstr_guid( &product ));
592 p = strchrW(&szDescriptor[20],'>');
593 if( !p )
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 );
603 if( !r )
604 return ERROR_INVALID_PARAMETER;
606 TRACE("component %s\n", debugstr_guid( &component ));
608 if (szProduct)
609 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
610 if (szComponent)
611 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
612 if (szFeature)
614 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
615 szFeature[len] = 0;
617 len = ( &p[21] - szDescriptor );
619 TRACE("length = %d\n", len);
620 *pUsed = 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;
632 UINT r;
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;
641 if (szProduct)
642 p = product;
643 if (szFeature)
644 f = feature;
645 if (szComponent)
646 c = component;
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 );
660 msi_free( str );
662 return r;
665 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
667 DWORD r;
668 WCHAR szwGuid[GUID_SIZE];
670 TRACE("%d %p\n", index, lpguid);
672 if (NULL == 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);
678 return r;
681 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
683 HKEY hkeyFeatures = 0;
684 DWORD r;
685 WCHAR szKeyName[SQUISH_GUID_SIZE];
687 TRACE("%d %p\n", index, lpguid);
689 if (NULL == 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);
701 return r;
704 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
705 LPSTR szFeature, LPSTR szParent)
707 DWORD r;
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);
713 if( szProduct )
715 szwProduct = strdupAtoW( szProduct );
716 if( !szwProduct )
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);
731 return r;
734 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
735 LPWSTR szFeature, LPWSTR szParent)
737 HKEY hkeyProduct = 0;
738 DWORD r, sz;
740 TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
742 if( !szProduct )
743 return ERROR_INVALID_PARAMETER;
745 r = MSIREG_OpenFeaturesKey(szProduct,&hkeyProduct,FALSE);
746 if( r != ERROR_SUCCESS )
747 return ERROR_NO_MORE_ITEMS;
749 sz = GUID_SIZE;
750 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
751 RegCloseKey(hkeyProduct);
753 return r;
756 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
758 DWORD r;
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);
767 return r;
770 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
772 HKEY hkeyComponents = 0;
773 DWORD r;
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);
787 return r;
790 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
792 DWORD r;
793 WCHAR szwProduct[GUID_SIZE];
794 LPWSTR szwComponent = NULL;
796 TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
798 if( szComponent )
800 szwComponent = strdupAtoW( szComponent );
801 if( !szwComponent )
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);
814 return r;
817 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
819 HKEY hkeyComp = 0;
820 DWORD r, sz;
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);
836 return r;
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;
845 UINT r, r2;
846 HKEY key;
848 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
849 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
851 if (!szComponent)
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 */
859 name_max = 0x10;
860 r = ERROR_OUTOFMEMORY;
861 name = msi_alloc( name_max * sizeof(WCHAR) );
862 if (!name)
863 goto end;
865 val_max = 0x10;
866 r = ERROR_OUTOFMEMORY;
867 val = msi_alloc( val_max );
868 if (!val)
869 goto end;
871 /* loop until we allocate enough memory */
872 while (1)
874 name_sz = name_max;
875 val_sz = val_max;
876 r = RegEnumValueW( key, iIndex, name, &name_sz,
877 NULL, &type, (LPBYTE)val, &val_sz );
878 if (r == ERROR_SUCCESS)
879 break;
880 if (r != ERROR_MORE_DATA)
881 goto end;
883 if (type != REG_MULTI_SZ)
885 ERR("component data has wrong type (%d)\n", type);
886 goto end;
889 r = ERROR_OUTOFMEMORY;
890 if ((name_sz+1) >= name_max)
892 name_max *= 2;
893 msi_free( name );
894 name = msi_alloc( name_max * sizeof (WCHAR) );
895 if (!name)
896 goto end;
897 continue;
899 if (val_sz > val_max)
901 val_max = val_sz + sizeof (WCHAR);
902 msi_free( val );
903 val = msi_alloc( val_max * sizeof (WCHAR) );
904 if (!val)
905 goto end;
906 continue;
908 ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
909 goto end;
912 ofs = 0;
913 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
914 if (r != ERROR_SUCCESS)
915 goto end;
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)
923 r = r2;
925 end:
926 msi_free(val);
927 msi_free(name);
928 RegCloseKey(key);
930 return r;
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;
941 LPWSTR comp;
942 UINT r;
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 );
960 msi_free( comp );
961 return r;
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);
977 qual.unicode = TRUE;
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)
994 UINT r;
995 HKEY hkey;
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);
1013 RegCloseKey(hkey);
1015 return r;
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];
1027 UINT r;
1029 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1030 iProductIndex, lpProductBuf);
1032 if (szUpgradeCode)
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);
1047 return r;
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;