msi: Add some registry reading macro functions.
[wine/wine-jacek.git] / dlls / msi / registry.c
blob7c6eca1b6321762291178e5c1d239799932e9ecf
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[] = {
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','\\',
125 '%','s',0};
127 static const WCHAR szInstaller_UpgradeCodes[] = {
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',0};
135 static const WCHAR szInstaller_UpgradeCodes_fmt[] = {
136 'S','o','f','t','w','a','r','e','\\',
137 'M','i','c','r','o','s','o','f','t','\\',
138 'W','i','n','d','o','w','s','\\',
139 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
140 'I','n','s','t','a','l','l','e','r','\\',
141 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
142 '%','s',0};
144 static const WCHAR szInstaller_UserUpgradeCodes[] = {
145 'S','o','f','t','w','a','r','e','\\',
146 'M','i','c','r','o','s','o','f','t','\\',
147 'I','n','s','t','a','l','l','e','r','\\',
148 'U','p','g','r','a','d','e','C','o','d','e','s',0};
150 static const WCHAR szInstaller_UserUpgradeCodes_fmt[] = {
151 'S','o','f','t','w','a','r','e','\\',
152 'M','i','c','r','o','s','o','f','t','\\',
153 'I','n','s','t','a','l','l','e','r','\\',
154 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
155 '%','s',0};
158 #define SQUISH_GUID_SIZE 33
160 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
162 DWORD i,n=0;
164 out[n++]='{';
165 for(i=0; i<8; i++)
166 out[n++] = in[7-i];
167 out[n++]='-';
168 for(i=0; i<4; i++)
169 out[n++] = in[11-i];
170 out[n++]='-';
171 for(i=0; i<4; i++)
172 out[n++] = in[15-i];
173 out[n++]='-';
174 for(i=0; i<2; i++)
176 out[n++] = in[17+i*2];
177 out[n++] = in[16+i*2];
179 out[n++]='-';
180 for( ; i<8; i++)
182 out[n++] = in[17+i*2];
183 out[n++] = in[16+i*2];
185 out[n++]='}';
186 out[n]=0;
187 return TRUE;
190 BOOL squash_guid(LPCWSTR in, LPWSTR out)
192 DWORD i,n=0;
194 if(in[n++] != '{')
195 return FALSE;
196 for(i=0; i<8; i++)
197 out[7-i] = in[n++];
198 if(in[n++] != '-')
199 return FALSE;
200 for(i=0; i<4; i++)
201 out[11-i] = in[n++];
202 if(in[n++] != '-')
203 return FALSE;
204 for(i=0; i<4; i++)
205 out[15-i] = in[n++];
206 if(in[n++] != '-')
207 return FALSE;
208 for(i=0; i<2; i++)
210 out[17+i*2] = in[n++];
211 out[16+i*2] = in[n++];
213 if(in[n++] != '-')
214 return FALSE;
215 for( ; i<8; i++)
217 out[17+i*2] = in[n++];
218 out[16+i*2] = in[n++];
220 out[32]=0;
221 if(in[n++] != '}')
222 return FALSE;
223 if(in[n])
224 return FALSE;
225 return TRUE;
229 /* tables for encoding and decoding base85 */
230 static const unsigned char table_dec85[0x80] = {
231 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
232 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
233 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
234 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
235 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
236 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
237 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
238 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
241 static const char table_enc85[] =
242 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
243 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
244 "yz{}~";
247 * Converts a base85 encoded guid into a GUID pointer
248 * Base85 encoded GUIDs should be 20 characters long.
250 * returns TRUE if successful, FALSE if not
252 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
254 DWORD i, val = 0, base = 1, *p;
256 if (!str)
257 return FALSE;
259 p = (DWORD*) guid;
260 for( i=0; i<20; i++ )
262 if( (i%5) == 0 )
264 val = 0;
265 base = 1;
267 val += table_dec85[str[i]] * base;
268 if( str[i] >= 0x80 )
269 return FALSE;
270 if( table_dec85[str[i]] == 0xff )
271 return FALSE;
272 if( (i%5) == 4 )
273 p[i/5] = val;
274 base *= 85;
276 return TRUE;
280 * Encodes a base85 guid given a GUID pointer
281 * Caller should provide a 21 character buffer for the encoded string.
283 * returns TRUE if successful, FALSE if not
285 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
287 unsigned int x, *p, i;
289 p = (unsigned int*) guid;
290 for( i=0; i<4; i++ )
292 x = p[i];
293 *str++ = table_enc85[x%85];
294 x = x/85;
295 *str++ = table_enc85[x%85];
296 x = x/85;
297 *str++ = table_enc85[x%85];
298 x = x/85;
299 *str++ = table_enc85[x%85];
300 x = x/85;
301 *str++ = table_enc85[x%85];
303 *str = 0;
305 return TRUE;
308 DWORD msi_version_str_to_dword(LPCWSTR p)
310 DWORD major, minor = 0, build = 0, version = 0;
312 if (!p)
313 return version;
315 major = atoiW(p);
317 p = strchrW(p, '.');
318 if (p)
320 minor = atoiW(p+1);
321 p = strchrW(p+1, '.');
322 if (p)
323 build = atoiW(p+1);
326 return MAKELONG(build, MAKEWORD(minor, major));
329 LPWSTR msi_version_dword_to_str(DWORD version)
331 const WCHAR fmt[] = { '%','u','.','%','u','.','%','u',0 };
332 LPWSTR str = msi_alloc(20);
333 sprintfW(str, fmt,
334 (version&0xff000000)>>24,
335 (version&0x00ff0000)>>16,
336 version&0x0000ffff);
337 return str;
340 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
342 DWORD len = value ? (lstrlenW(value) + 1) * sizeof (WCHAR) : 0;
343 return RegSetValueExW( hkey, name, 0, REG_SZ, (LPBYTE)value, len );
346 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
348 LPCWSTR p = value;
349 while (*p) p += lstrlenW(p) + 1;
350 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
351 (LPBYTE)value, (p + 1 - value) * sizeof(WCHAR) );
354 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
356 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
359 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
361 HKEY hsubkey = 0;
362 LONG r;
364 r = RegCreateKeyW( hkey, path, &hsubkey );
365 if (r != ERROR_SUCCESS)
366 return r;
367 r = msi_reg_set_val_str( hsubkey, name, val );
368 RegCloseKey( hsubkey );
369 return r;
372 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
374 DWORD len = 0;
375 LPWSTR val;
376 LONG r;
378 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
379 if (r != ERROR_SUCCESS)
380 return NULL;
382 len += sizeof (WCHAR);
383 val = msi_alloc( len );
384 if (!val)
385 return NULL;
386 val[0] = 0;
387 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
388 return val;
391 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
393 DWORD type, len = sizeof (DWORD);
394 LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
395 return r == ERROR_SUCCESS && type == REG_DWORD;
398 UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create)
400 UINT rc;
401 WCHAR keypath[0x200];
402 TRACE("%s\n",debugstr_w(szProduct));
404 sprintfW(keypath,szUninstall_fmt,szProduct);
406 if (create)
407 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
408 else
409 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
411 return rc;
414 UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
416 UINT rc;
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,szUserProduct_fmt,squished_pc);
426 if (create)
427 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
428 else
429 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
431 return rc;
434 UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
436 UINT rc;
437 WCHAR squished_pc[GUID_SIZE];
438 WCHAR keypath[0x200];
440 TRACE("%s\n",debugstr_w(szProduct));
441 squash_guid(szProduct,squished_pc);
442 TRACE("squished (%s)\n", debugstr_w(squished_pc));
444 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
446 if (create)
447 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
448 else
449 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
451 return rc;
454 UINT MSIREG_OpenFeatures(HKEY* key)
456 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Features,key);
459 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
461 UINT rc;
462 WCHAR squished_pc[GUID_SIZE];
463 WCHAR keypath[0x200];
465 TRACE("%s\n",debugstr_w(szProduct));
466 squash_guid(szProduct,squished_pc);
467 TRACE("squished (%s)\n", debugstr_w(squished_pc));
469 sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
471 if (create)
472 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
473 else
474 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
476 return rc;
479 UINT MSIREG_OpenComponents(HKEY* key)
481 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Components,key);
484 UINT MSIREG_OpenComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
486 UINT rc;
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,szInstaller_Components_fmt,squished_cc);
496 if (create)
497 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
498 else
499 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
501 return rc;
504 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
506 UINT rc;
507 WCHAR squished_cc[GUID_SIZE];
508 WCHAR keypath[0x200];
510 TRACE("%s\n",debugstr_w(szComponent));
511 squash_guid(szComponent,squished_cc);
512 TRACE("squished (%s)\n", debugstr_w(squished_cc));
514 sprintfW(keypath,szUser_Components_fmt,squished_cc);
516 if (create)
517 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
518 else
519 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
521 return rc;
524 UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
526 UINT rc;
527 WCHAR squished_pc[GUID_SIZE];
528 WCHAR keypath[0x200];
530 TRACE("%s\n",debugstr_w(szProduct));
531 squash_guid(szProduct,squished_pc);
532 TRACE("squished (%s)\n", debugstr_w(squished_pc));
534 sprintfW(keypath,szInstaller_Products_fmt,squished_pc);
536 if (create)
537 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
538 else
539 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
541 return rc;
544 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
546 UINT rc;
547 WCHAR squished_pc[GUID_SIZE];
548 WCHAR keypath[0x200];
550 TRACE("%s\n",debugstr_w(szUpgradeCode));
551 squash_guid(szUpgradeCode,squished_pc);
552 TRACE("squished (%s)\n", debugstr_w(squished_pc));
554 sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
556 if (create)
557 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
558 else
559 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
561 return rc;
564 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
566 UINT rc;
567 WCHAR squished_pc[GUID_SIZE];
568 WCHAR keypath[0x200];
570 TRACE("%s\n",debugstr_w(szUpgradeCode));
571 squash_guid(szUpgradeCode,squished_pc);
572 TRACE("squished (%s)\n", debugstr_w(squished_pc));
574 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
576 if (create)
577 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
578 else
579 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
581 return rc;
585 /*************************************************************************
586 * MsiDecomposeDescriptorW [MSI.@]
588 * Decomposes an MSI descriptor into product, feature and component parts.
589 * An MSI descriptor is a string of the form:
590 * [base 85 guid] [feature code] '>' [base 85 guid]
592 * PARAMS
593 * szDescriptor [I] the descriptor to decompose
594 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
595 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
596 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
597 * pUsed [O] the length of the descriptor
599 * RETURNS
600 * ERROR_SUCCESS if everything worked correctly
601 * ERROR_INVALID_PARAMETER if the descriptor was invalid
604 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
605 LPWSTR szFeature, LPWSTR szComponent, DWORD *pUsed )
607 UINT r, len;
608 LPWSTR p;
609 GUID product, component;
611 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
612 szFeature, szComponent, pUsed);
614 r = decode_base85_guid( szDescriptor, &product );
615 if( !r )
616 return ERROR_INVALID_PARAMETER;
618 TRACE("product %s\n", debugstr_guid( &product ));
620 p = strchrW(&szDescriptor[20],'>');
621 if( !p )
622 return ERROR_INVALID_PARAMETER;
624 len = (p - &szDescriptor[20]);
625 if( len > MAX_FEATURE_CHARS )
626 return ERROR_INVALID_PARAMETER;
627 if (szFeature)
629 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
630 szFeature[len] = 0;
633 TRACE("feature %s\n", debugstr_w( &szDescriptor[20] ));
635 r = decode_base85_guid( p+1, &component );
636 if( !r )
637 return ERROR_INVALID_PARAMETER;
639 TRACE("component %s\n", debugstr_guid( &component ));
641 if (szProduct)
642 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
643 if (szComponent)
644 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
645 len = ( &p[21] - szDescriptor );
647 TRACE("length = %d\n", len);
648 *pUsed = len;
650 return ERROR_SUCCESS;
653 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
654 LPSTR szFeature, LPSTR szComponent, DWORD *pUsed )
656 WCHAR product[MAX_FEATURE_CHARS+1];
657 WCHAR feature[MAX_FEATURE_CHARS+1];
658 WCHAR component[MAX_FEATURE_CHARS+1];
659 LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
660 UINT r;
662 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
663 szFeature, szComponent, pUsed);
665 str = strdupAtoW( szDescriptor );
666 if( szDescriptor && !str )
667 return ERROR_OUTOFMEMORY;
669 if (szProduct)
670 p = product;
671 if (szFeature)
672 f = feature;
673 if (szComponent)
674 c = component;
676 r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
678 WideCharToMultiByte( CP_ACP, 0, p, MAX_FEATURE_CHARS+1,
679 szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
680 WideCharToMultiByte( CP_ACP, 0, f, MAX_FEATURE_CHARS+1,
681 szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
682 WideCharToMultiByte( CP_ACP, 0, c, MAX_FEATURE_CHARS+1,
683 szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
685 msi_free( str );
687 return r;
690 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
692 DWORD r;
693 WCHAR szwGuid[GUID_SIZE];
695 TRACE("%ld %p\n",index,lpguid);
697 if (NULL == lpguid)
698 return ERROR_INVALID_PARAMETER;
699 r = MsiEnumProductsW(index, szwGuid);
700 if( r == ERROR_SUCCESS )
701 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
703 return r;
706 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
708 HKEY hkeyFeatures = 0;
709 DWORD r;
710 WCHAR szKeyName[SQUISH_GUID_SIZE];
712 TRACE("%ld %p\n",index,lpguid);
714 if (NULL == lpguid)
715 return ERROR_INVALID_PARAMETER;
717 r = MSIREG_OpenFeatures(&hkeyFeatures);
718 if( r != ERROR_SUCCESS )
719 return ERROR_NO_MORE_ITEMS;
721 r = RegEnumKeyW(hkeyFeatures, index, szKeyName, SQUISH_GUID_SIZE);
722 if( r == ERROR_SUCCESS )
723 unsquash_guid(szKeyName, lpguid);
724 RegCloseKey(hkeyFeatures);
726 return r;
729 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
730 LPSTR szFeature, LPSTR szParent)
732 DWORD r;
733 WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
734 LPWSTR szwProduct = NULL;
736 TRACE("%s %ld %p %p\n",debugstr_a(szProduct),index,szFeature,szParent);
738 if( szProduct )
740 szwProduct = strdupAtoW( szProduct );
741 if( !szwProduct )
742 return ERROR_OUTOFMEMORY;
745 r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
746 if( r == ERROR_SUCCESS )
748 WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
749 szFeature, GUID_SIZE, NULL, NULL);
750 WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
751 szParent, GUID_SIZE, NULL, NULL);
754 msi_free( szwProduct);
756 return r;
759 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
760 LPWSTR szFeature, LPWSTR szParent)
762 HKEY hkeyProduct = 0;
763 DWORD r, sz;
765 TRACE("%s %ld %p %p\n",debugstr_w(szProduct),index,szFeature,szParent);
767 if( !szProduct )
768 return ERROR_INVALID_PARAMETER;
770 r = MSIREG_OpenFeaturesKey(szProduct,&hkeyProduct,FALSE);
771 if( r != ERROR_SUCCESS )
772 return ERROR_NO_MORE_ITEMS;
774 sz = GUID_SIZE;
775 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
776 RegCloseKey(hkeyProduct);
778 return r;
781 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
783 DWORD r;
784 WCHAR szwGuid[GUID_SIZE];
786 TRACE("%ld %p\n",index,lpguid);
788 r = MsiEnumComponentsW(index, szwGuid);
789 if( r == ERROR_SUCCESS )
790 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
792 return r;
795 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
797 HKEY hkeyComponents = 0;
798 DWORD r;
799 WCHAR szKeyName[SQUISH_GUID_SIZE];
801 TRACE("%ld %p\n",index,lpguid);
803 r = MSIREG_OpenComponents(&hkeyComponents);
804 if( r != ERROR_SUCCESS )
805 return ERROR_NO_MORE_ITEMS;
807 r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
808 if( r == ERROR_SUCCESS )
809 unsquash_guid(szKeyName, lpguid);
810 RegCloseKey(hkeyComponents);
812 return r;
815 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
817 DWORD r;
818 WCHAR szwProduct[GUID_SIZE];
819 LPWSTR szwComponent = NULL;
821 TRACE("%s %ld %p\n",debugstr_a(szComponent),index,szProduct);
823 if( szComponent )
825 szwComponent = strdupAtoW( szComponent );
826 if( !szwComponent )
827 return ERROR_OUTOFMEMORY;
830 r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
831 if( r == ERROR_SUCCESS )
833 WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
834 szProduct, GUID_SIZE, NULL, NULL);
837 msi_free( szwComponent);
839 return r;
842 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
844 HKEY hkeyComp = 0;
845 DWORD r, sz;
846 WCHAR szValName[SQUISH_GUID_SIZE];
848 TRACE("%s %ld %p\n",debugstr_w(szComponent),index,szProduct);
850 r = MSIREG_OpenComponentsKey(szComponent,&hkeyComp,FALSE);
851 if( r != ERROR_SUCCESS )
852 return ERROR_NO_MORE_ITEMS;
854 sz = SQUISH_GUID_SIZE;
855 r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
856 if( r == ERROR_SUCCESS )
857 unsquash_guid(szValName, szProduct);
859 RegCloseKey(hkeyComp);
861 return r;
864 UINT WINAPI MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
865 awstring *lpQualBuf, DWORD* pcchQual,
866 awstring *lpAppBuf, DWORD* pcchAppBuf )
868 DWORD name_sz, val_sz, name_max, val_max, type, ofs;
869 LPWSTR name = NULL, val = NULL;
870 UINT r, r2;
871 HKEY key;
873 TRACE("%s %08lx %p %p %p %p\n", debugstr_w(szComponent), iIndex,
874 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
876 if (!szComponent)
877 return ERROR_INVALID_PARAMETER;
879 r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
880 if (r != ERROR_SUCCESS)
881 return ERROR_UNKNOWN_COMPONENT;
883 /* figure out how big the name is we want to return */
884 name_max = 0x10;
885 r = ERROR_OUTOFMEMORY;
886 name = msi_alloc( name_max * sizeof(WCHAR) );
887 if (!name)
888 goto end;
890 val_max = 0x10;
891 r = ERROR_OUTOFMEMORY;
892 val = msi_alloc( val_max );
893 if (!val)
894 goto end;
896 /* loop until we allocate enough memory */
897 while (1)
899 name_sz = name_max;
900 val_sz = val_max;
901 r = RegEnumValueW( key, iIndex, name, &name_sz,
902 NULL, &type, (LPBYTE)val, &val_sz );
903 if (r == ERROR_SUCCESS)
904 break;
905 if (r != ERROR_MORE_DATA)
906 goto end;
908 if (type != REG_MULTI_SZ)
910 ERR("component data has wrong type (%ld)\n", type);
911 goto end;
914 r = ERROR_OUTOFMEMORY;
915 if ((name_sz+1) >= name_max)
917 name_max *= 2;
918 msi_free( name );
919 name = msi_alloc( name_max * sizeof (WCHAR) );
920 if (!name)
921 goto end;
922 continue;
924 if (val_sz > val_max)
926 val_max = val_sz + sizeof (WCHAR);
927 val = msi_alloc( val_max * sizeof (WCHAR) );
928 if (!val)
929 goto end;
930 continue;
932 ERR("should be enough data, but isn't %ld %ld\n", name_sz, val_sz );
933 goto end;
936 ofs = 0;
937 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
938 if (r != ERROR_SUCCESS)
939 goto end;
941 TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
943 r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
944 r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
946 if (r2 != ERROR_SUCCESS)
947 r = r2;
949 end:
950 msi_free(val);
951 msi_free(name);
952 RegCloseKey(key);
954 return r;
957 /*************************************************************************
958 * MsiEnumComponentQualifiersA [MSI.@]
960 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
961 LPSTR lpQualifierBuf, DWORD* pcchQualifierBuf,
962 LPSTR lpApplicationDataBuf, DWORD* pcchApplicationDataBuf )
964 awstring qual, appdata;
965 LPWSTR comp;
966 UINT r;
968 TRACE("%s %08lx %p %p %p %p\n", debugstr_a(szComponent), iIndex,
969 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
970 pcchApplicationDataBuf);
972 comp = strdupAtoW( szComponent );
973 if (szComponent && !comp)
974 return ERROR_OUTOFMEMORY;
976 qual.unicode = FALSE;
977 qual.str.a = lpQualifierBuf;
979 appdata.unicode = FALSE;
980 appdata.str.a = lpApplicationDataBuf;
982 r = MSI_EnumComponentQualifiers( comp, iIndex,
983 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
984 msi_free( comp );
985 return r;
988 /*************************************************************************
989 * MsiEnumComponentQualifiersW [MSI.@]
991 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
992 LPWSTR lpQualifierBuf, DWORD* pcchQualifierBuf,
993 LPWSTR lpApplicationDataBuf, DWORD* pcchApplicationDataBuf )
995 awstring qual, appdata;
997 TRACE("%s %08lx %p %p %p %p\n", debugstr_w(szComponent), iIndex,
998 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
999 pcchApplicationDataBuf);
1001 qual.unicode = TRUE;
1002 qual.str.w = lpQualifierBuf;
1004 appdata.unicode = TRUE;
1005 appdata.str.w = lpApplicationDataBuf;
1007 return MSI_EnumComponentQualifiers( szComponent, iIndex,
1008 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1011 /*************************************************************************
1012 * MsiEnumRelatedProductsW [MSI.@]
1015 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
1016 DWORD iProductIndex, LPWSTR lpProductBuf)
1018 UINT r;
1019 HKEY hkey;
1020 WCHAR szKeyName[SQUISH_GUID_SIZE];
1022 TRACE("%s %lu %lu %p\n", debugstr_w(szUpgradeCode), dwReserved,
1023 iProductIndex, lpProductBuf);
1025 if (NULL == szUpgradeCode)
1026 return ERROR_INVALID_PARAMETER;
1027 if (NULL == lpProductBuf)
1028 return ERROR_INVALID_PARAMETER;
1030 r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1031 if (r != ERROR_SUCCESS)
1032 return ERROR_NO_MORE_ITEMS;
1034 r = RegEnumKeyW(hkey, iProductIndex, szKeyName, SQUISH_GUID_SIZE);
1035 if( r == ERROR_SUCCESS )
1036 unsquash_guid(szKeyName, lpProductBuf);
1037 RegCloseKey(hkey);
1039 return r;
1042 /*************************************************************************
1043 * MsiEnumRelatedProductsA [MSI.@]
1046 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1047 DWORD iProductIndex, LPSTR lpProductBuf)
1049 LPWSTR szwUpgradeCode = NULL;
1050 WCHAR productW[GUID_SIZE];
1051 UINT r;
1053 TRACE("%s %lu %lu %p\n", debugstr_a(szUpgradeCode), dwReserved,
1054 iProductIndex, lpProductBuf);
1056 if (szUpgradeCode)
1058 szwUpgradeCode = strdupAtoW( szUpgradeCode );
1059 if( !szwUpgradeCode )
1060 return ERROR_OUTOFMEMORY;
1063 r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1064 iProductIndex, productW );
1065 if (r == ERROR_SUCCESS)
1067 WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1068 lpProductBuf, GUID_SIZE, NULL, NULL );
1070 msi_free( szwUpgradeCode);
1071 return r;