wined3d: The WineD3D_GLContext structure doesn't need to be exported.
[wine/testsucceed.git] / dlls / msi / registry.c
blob5ad5059714f926ed041d93b079c5c41bc81abe98
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=1;
193 GUID guid;
195 if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
196 return FALSE;
198 for(i=0; i<8; i++)
199 out[7-i] = in[n++];
200 n++;
201 for(i=0; i<4; i++)
202 out[11-i] = in[n++];
203 n++;
204 for(i=0; i<4; i++)
205 out[15-i] = in[n++];
206 n++;
207 for(i=0; i<2; i++)
209 out[17+i*2] = in[n++];
210 out[16+i*2] = in[n++];
212 n++;
213 for( ; i<8; i++)
215 out[17+i*2] = in[n++];
216 out[16+i*2] = in[n++];
218 out[32]=0;
219 return TRUE;
223 /* tables for encoding and decoding base85 */
224 static const unsigned char table_dec85[0x80] = {
225 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
226 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
227 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
228 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
229 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
230 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
231 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
232 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
235 static const char table_enc85[] =
236 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
237 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
238 "yz{}~";
241 * Converts a base85 encoded guid into a GUID pointer
242 * Base85 encoded GUIDs should be 20 characters long.
244 * returns TRUE if successful, FALSE if not
246 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
248 DWORD i, val = 0, base = 1, *p;
250 if (!str)
251 return FALSE;
253 p = (DWORD*) guid;
254 for( i=0; i<20; i++ )
256 if( (i%5) == 0 )
258 val = 0;
259 base = 1;
261 val += table_dec85[str[i]] * base;
262 if( str[i] >= 0x80 )
263 return FALSE;
264 if( table_dec85[str[i]] == 0xff )
265 return FALSE;
266 if( (i%5) == 4 )
267 p[i/5] = val;
268 base *= 85;
270 return TRUE;
274 * Encodes a base85 guid given a GUID pointer
275 * Caller should provide a 21 character buffer for the encoded string.
277 * returns TRUE if successful, FALSE if not
279 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
281 unsigned int x, *p, i;
283 p = (unsigned int*) guid;
284 for( i=0; i<4; i++ )
286 x = p[i];
287 *str++ = table_enc85[x%85];
288 x = x/85;
289 *str++ = table_enc85[x%85];
290 x = x/85;
291 *str++ = table_enc85[x%85];
292 x = x/85;
293 *str++ = table_enc85[x%85];
294 x = x/85;
295 *str++ = table_enc85[x%85];
297 *str = 0;
299 return TRUE;
302 DWORD msi_version_str_to_dword(LPCWSTR p)
304 DWORD major, minor = 0, build = 0, version = 0;
306 if (!p)
307 return version;
309 major = atoiW(p);
311 p = strchrW(p, '.');
312 if (p)
314 minor = atoiW(p+1);
315 p = strchrW(p+1, '.');
316 if (p)
317 build = atoiW(p+1);
320 return MAKELONG(build, MAKEWORD(minor, major));
323 LPWSTR msi_version_dword_to_str(DWORD version)
325 const WCHAR fmt[] = { '%','u','.','%','u','.','%','u',0 };
326 LPWSTR str = msi_alloc(20);
327 sprintfW(str, fmt,
328 (version&0xff000000)>>24,
329 (version&0x00ff0000)>>16,
330 version&0x0000ffff);
331 return str;
334 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
336 DWORD len = value ? (lstrlenW(value) + 1) * sizeof (WCHAR) : 0;
337 return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len );
340 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
342 LPCWSTR p = value;
343 while (*p) p += lstrlenW(p) + 1;
344 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
345 (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) );
348 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
350 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
353 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
355 HKEY hsubkey = 0;
356 LONG r;
358 r = RegCreateKeyW( hkey, path, &hsubkey );
359 if (r != ERROR_SUCCESS)
360 return r;
361 r = msi_reg_set_val_str( hsubkey, name, val );
362 RegCloseKey( hsubkey );
363 return r;
366 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
368 DWORD len = 0;
369 LPWSTR val;
370 LONG r;
372 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
373 if (r != ERROR_SUCCESS)
374 return NULL;
376 len += sizeof (WCHAR);
377 val = msi_alloc( len );
378 if (!val)
379 return NULL;
380 val[0] = 0;
381 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
382 return val;
385 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
387 DWORD type, len = sizeof (DWORD);
388 LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
389 return r == ERROR_SUCCESS && type == REG_DWORD;
392 UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create)
394 UINT rc;
395 WCHAR keypath[0x200];
396 TRACE("%s\n",debugstr_w(szProduct));
398 sprintfW(keypath,szUninstall_fmt,szProduct);
400 if (create)
401 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
402 else
403 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
405 return rc;
408 UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
410 UINT rc;
411 WCHAR squished_pc[GUID_SIZE];
412 WCHAR keypath[0x200];
414 TRACE("%s\n",debugstr_w(szProduct));
415 squash_guid(szProduct,squished_pc);
416 TRACE("squished (%s)\n", debugstr_w(squished_pc));
418 sprintfW(keypath,szUserProduct_fmt,squished_pc);
420 if (create)
421 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
422 else
423 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
425 return rc;
428 UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
430 UINT rc;
431 WCHAR squished_pc[GUID_SIZE];
432 WCHAR keypath[0x200];
434 TRACE("%s\n",debugstr_w(szProduct));
435 squash_guid(szProduct,squished_pc);
436 TRACE("squished (%s)\n", debugstr_w(squished_pc));
438 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
440 if (create)
441 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
442 else
443 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
445 return rc;
448 UINT MSIREG_OpenFeatures(HKEY* key)
450 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Features,key);
453 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
455 UINT rc;
456 WCHAR squished_pc[GUID_SIZE];
457 WCHAR keypath[0x200];
459 TRACE("%s\n",debugstr_w(szProduct));
460 squash_guid(szProduct,squished_pc);
461 TRACE("squished (%s)\n", debugstr_w(squished_pc));
463 sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
465 if (create)
466 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
467 else
468 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
470 return rc;
473 UINT MSIREG_OpenComponents(HKEY* key)
475 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Components,key);
478 UINT MSIREG_OpenComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
480 UINT rc;
481 WCHAR squished_cc[GUID_SIZE];
482 WCHAR keypath[0x200];
484 TRACE("%s\n",debugstr_w(szComponent));
485 squash_guid(szComponent,squished_cc);
486 TRACE("squished (%s)\n", debugstr_w(squished_cc));
488 sprintfW(keypath,szInstaller_Components_fmt,squished_cc);
490 if (create)
491 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
492 else
493 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
495 return rc;
498 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
500 UINT rc;
501 WCHAR squished_cc[GUID_SIZE];
502 WCHAR keypath[0x200];
504 TRACE("%s\n",debugstr_w(szComponent));
505 squash_guid(szComponent,squished_cc);
506 TRACE("squished (%s)\n", debugstr_w(squished_cc));
508 sprintfW(keypath,szUser_Components_fmt,squished_cc);
510 if (create)
511 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
512 else
513 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
515 return rc;
518 UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
520 UINT rc;
521 WCHAR squished_pc[GUID_SIZE];
522 WCHAR keypath[0x200];
524 TRACE("%s\n",debugstr_w(szProduct));
525 squash_guid(szProduct,squished_pc);
526 TRACE("squished (%s)\n", debugstr_w(squished_pc));
528 sprintfW(keypath,szInstaller_Products_fmt,squished_pc);
530 if (create)
531 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
532 else
533 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
535 return rc;
538 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
540 UINT rc;
541 WCHAR squished_pc[GUID_SIZE];
542 WCHAR keypath[0x200];
544 TRACE("%s\n",debugstr_w(szUpgradeCode));
545 squash_guid(szUpgradeCode,squished_pc);
546 TRACE("squished (%s)\n", debugstr_w(squished_pc));
548 sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
550 if (create)
551 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
552 else
553 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
555 return rc;
558 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
560 UINT rc;
561 WCHAR squished_pc[GUID_SIZE];
562 WCHAR keypath[0x200];
564 TRACE("%s\n",debugstr_w(szUpgradeCode));
565 squash_guid(szUpgradeCode,squished_pc);
566 TRACE("squished (%s)\n", debugstr_w(squished_pc));
568 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
570 if (create)
571 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
572 else
573 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
575 return rc;
579 /*************************************************************************
580 * MsiDecomposeDescriptorW [MSI.@]
582 * Decomposes an MSI descriptor into product, feature and component parts.
583 * An MSI descriptor is a string of the form:
584 * [base 85 guid] [feature code] '>' [base 85 guid]
586 * PARAMS
587 * szDescriptor [I] the descriptor to decompose
588 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
589 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
590 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
591 * pUsed [O] the length of the descriptor
593 * RETURNS
594 * ERROR_SUCCESS if everything worked correctly
595 * ERROR_INVALID_PARAMETER if the descriptor was invalid
598 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
599 LPWSTR szFeature, LPWSTR szComponent, DWORD *pUsed )
601 UINT r, len;
602 LPWSTR p;
603 GUID product, component;
605 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
606 szFeature, szComponent, pUsed);
608 r = decode_base85_guid( szDescriptor, &product );
609 if( !r )
610 return ERROR_INVALID_PARAMETER;
612 TRACE("product %s\n", debugstr_guid( &product ));
614 p = strchrW(&szDescriptor[20],'>');
615 if( !p )
616 return ERROR_INVALID_PARAMETER;
618 len = (p - &szDescriptor[20]);
619 if( len > MAX_FEATURE_CHARS )
620 return ERROR_INVALID_PARAMETER;
621 if (szFeature)
623 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
624 szFeature[len] = 0;
627 TRACE("feature %s\n", debugstr_w( &szDescriptor[20] ));
629 r = decode_base85_guid( p+1, &component );
630 if( !r )
631 return ERROR_INVALID_PARAMETER;
633 TRACE("component %s\n", debugstr_guid( &component ));
635 if (szProduct)
636 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
637 if (szComponent)
638 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
639 len = ( &p[21] - szDescriptor );
641 TRACE("length = %d\n", len);
642 *pUsed = len;
644 return ERROR_SUCCESS;
647 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
648 LPSTR szFeature, LPSTR szComponent, DWORD *pUsed )
650 WCHAR product[MAX_FEATURE_CHARS+1];
651 WCHAR feature[MAX_FEATURE_CHARS+1];
652 WCHAR component[MAX_FEATURE_CHARS+1];
653 LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
654 UINT r;
656 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
657 szFeature, szComponent, pUsed);
659 str = strdupAtoW( szDescriptor );
660 if( szDescriptor && !str )
661 return ERROR_OUTOFMEMORY;
663 if (szProduct)
664 p = product;
665 if (szFeature)
666 f = feature;
667 if (szComponent)
668 c = component;
670 r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
672 WideCharToMultiByte( CP_ACP, 0, p, MAX_FEATURE_CHARS+1,
673 szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
674 WideCharToMultiByte( CP_ACP, 0, f, MAX_FEATURE_CHARS+1,
675 szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
676 WideCharToMultiByte( CP_ACP, 0, c, MAX_FEATURE_CHARS+1,
677 szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
679 msi_free( str );
681 return r;
684 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
686 DWORD r;
687 WCHAR szwGuid[GUID_SIZE];
689 TRACE("%d %p\n", index, lpguid);
691 if (NULL == lpguid)
692 return ERROR_INVALID_PARAMETER;
693 r = MsiEnumProductsW(index, szwGuid);
694 if( r == ERROR_SUCCESS )
695 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
697 return r;
700 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
702 HKEY hkeyFeatures = 0;
703 DWORD r;
704 WCHAR szKeyName[SQUISH_GUID_SIZE];
706 TRACE("%d %p\n", index, lpguid);
708 if (NULL == lpguid)
709 return ERROR_INVALID_PARAMETER;
711 r = MSIREG_OpenFeatures(&hkeyFeatures);
712 if( r != ERROR_SUCCESS )
713 return ERROR_NO_MORE_ITEMS;
715 r = RegEnumKeyW(hkeyFeatures, index, szKeyName, SQUISH_GUID_SIZE);
716 if( r == ERROR_SUCCESS )
717 unsquash_guid(szKeyName, lpguid);
718 RegCloseKey(hkeyFeatures);
720 return r;
723 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
724 LPSTR szFeature, LPSTR szParent)
726 DWORD r;
727 WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
728 LPWSTR szwProduct = NULL;
730 TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent);
732 if( szProduct )
734 szwProduct = strdupAtoW( szProduct );
735 if( !szwProduct )
736 return ERROR_OUTOFMEMORY;
739 r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
740 if( r == ERROR_SUCCESS )
742 WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
743 szFeature, GUID_SIZE, NULL, NULL);
744 WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
745 szParent, GUID_SIZE, NULL, NULL);
748 msi_free( szwProduct);
750 return r;
753 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
754 LPWSTR szFeature, LPWSTR szParent)
756 HKEY hkeyProduct = 0;
757 DWORD r, sz;
759 TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
761 if( !szProduct )
762 return ERROR_INVALID_PARAMETER;
764 r = MSIREG_OpenFeaturesKey(szProduct,&hkeyProduct,FALSE);
765 if( r != ERROR_SUCCESS )
766 return ERROR_NO_MORE_ITEMS;
768 sz = GUID_SIZE;
769 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
770 RegCloseKey(hkeyProduct);
772 return r;
775 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
777 DWORD r;
778 WCHAR szwGuid[GUID_SIZE];
780 TRACE("%d %p\n", index, lpguid);
782 r = MsiEnumComponentsW(index, szwGuid);
783 if( r == ERROR_SUCCESS )
784 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
786 return r;
789 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
791 HKEY hkeyComponents = 0;
792 DWORD r;
793 WCHAR szKeyName[SQUISH_GUID_SIZE];
795 TRACE("%d %p\n", index, lpguid);
797 r = MSIREG_OpenComponents(&hkeyComponents);
798 if( r != ERROR_SUCCESS )
799 return ERROR_NO_MORE_ITEMS;
801 r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
802 if( r == ERROR_SUCCESS )
803 unsquash_guid(szKeyName, lpguid);
804 RegCloseKey(hkeyComponents);
806 return r;
809 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
811 DWORD r;
812 WCHAR szwProduct[GUID_SIZE];
813 LPWSTR szwComponent = NULL;
815 TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
817 if( szComponent )
819 szwComponent = strdupAtoW( szComponent );
820 if( !szwComponent )
821 return ERROR_OUTOFMEMORY;
824 r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
825 if( r == ERROR_SUCCESS )
827 WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
828 szProduct, GUID_SIZE, NULL, NULL);
831 msi_free( szwComponent);
833 return r;
836 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
838 HKEY hkeyComp = 0;
839 DWORD r, sz;
840 WCHAR szValName[SQUISH_GUID_SIZE];
842 TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct);
844 r = MSIREG_OpenComponentsKey(szComponent,&hkeyComp,FALSE);
845 if( r != ERROR_SUCCESS )
846 return ERROR_NO_MORE_ITEMS;
848 sz = SQUISH_GUID_SIZE;
849 r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
850 if( r == ERROR_SUCCESS )
851 unsquash_guid(szValName, szProduct);
853 RegCloseKey(hkeyComp);
855 return r;
858 static UINT WINAPI MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
859 awstring *lpQualBuf, DWORD* pcchQual,
860 awstring *lpAppBuf, DWORD* pcchAppBuf )
862 DWORD name_sz, val_sz, name_max, val_max, type, ofs;
863 LPWSTR name = NULL, val = NULL;
864 UINT r, r2;
865 HKEY key;
867 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
868 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
870 if (!szComponent)
871 return ERROR_INVALID_PARAMETER;
873 r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
874 if (r != ERROR_SUCCESS)
875 return ERROR_UNKNOWN_COMPONENT;
877 /* figure out how big the name is we want to return */
878 name_max = 0x10;
879 r = ERROR_OUTOFMEMORY;
880 name = msi_alloc( name_max * sizeof(WCHAR) );
881 if (!name)
882 goto end;
884 val_max = 0x10;
885 r = ERROR_OUTOFMEMORY;
886 val = msi_alloc( val_max );
887 if (!val)
888 goto end;
890 /* loop until we allocate enough memory */
891 while (1)
893 name_sz = name_max;
894 val_sz = val_max;
895 r = RegEnumValueW( key, iIndex, name, &name_sz,
896 NULL, &type, (LPBYTE)val, &val_sz );
897 if (r == ERROR_SUCCESS)
898 break;
899 if (r != ERROR_MORE_DATA)
900 goto end;
902 if (type != REG_MULTI_SZ)
904 ERR("component data has wrong type (%d)\n", type);
905 goto end;
908 r = ERROR_OUTOFMEMORY;
909 if ((name_sz+1) >= name_max)
911 name_max *= 2;
912 msi_free( name );
913 name = msi_alloc( name_max * sizeof (WCHAR) );
914 if (!name)
915 goto end;
916 continue;
918 if (val_sz > val_max)
920 val_max = val_sz + sizeof (WCHAR);
921 msi_free( val );
922 val = msi_alloc( val_max * sizeof (WCHAR) );
923 if (!val)
924 goto end;
925 continue;
927 ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
928 goto end;
931 ofs = 0;
932 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
933 if (r != ERROR_SUCCESS)
934 goto end;
936 TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
938 r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
939 r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
941 if (r2 != ERROR_SUCCESS)
942 r = r2;
944 end:
945 msi_free(val);
946 msi_free(name);
947 RegCloseKey(key);
949 return r;
952 /*************************************************************************
953 * MsiEnumComponentQualifiersA [MSI.@]
955 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
956 LPSTR lpQualifierBuf, DWORD* pcchQualifierBuf,
957 LPSTR lpApplicationDataBuf, DWORD* pcchApplicationDataBuf )
959 awstring qual, appdata;
960 LPWSTR comp;
961 UINT r;
963 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex,
964 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
965 pcchApplicationDataBuf);
967 comp = strdupAtoW( szComponent );
968 if (szComponent && !comp)
969 return ERROR_OUTOFMEMORY;
971 qual.unicode = FALSE;
972 qual.str.a = lpQualifierBuf;
974 appdata.unicode = FALSE;
975 appdata.str.a = lpApplicationDataBuf;
977 r = MSI_EnumComponentQualifiers( comp, iIndex,
978 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
979 msi_free( comp );
980 return r;
983 /*************************************************************************
984 * MsiEnumComponentQualifiersW [MSI.@]
986 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
987 LPWSTR lpQualifierBuf, DWORD* pcchQualifierBuf,
988 LPWSTR lpApplicationDataBuf, DWORD* pcchApplicationDataBuf )
990 awstring qual, appdata;
992 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
993 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
994 pcchApplicationDataBuf);
996 qual.unicode = TRUE;
997 qual.str.w = lpQualifierBuf;
999 appdata.unicode = TRUE;
1000 appdata.str.w = lpApplicationDataBuf;
1002 return MSI_EnumComponentQualifiers( szComponent, iIndex,
1003 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1006 /*************************************************************************
1007 * MsiEnumRelatedProductsW [MSI.@]
1010 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
1011 DWORD iProductIndex, LPWSTR lpProductBuf)
1013 UINT r;
1014 HKEY hkey;
1015 WCHAR szKeyName[SQUISH_GUID_SIZE];
1017 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved,
1018 iProductIndex, lpProductBuf);
1020 if (NULL == szUpgradeCode)
1021 return ERROR_INVALID_PARAMETER;
1022 if (NULL == lpProductBuf)
1023 return ERROR_INVALID_PARAMETER;
1025 r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1026 if (r != ERROR_SUCCESS)
1027 return ERROR_NO_MORE_ITEMS;
1029 r = RegEnumKeyW(hkey, iProductIndex, szKeyName, SQUISH_GUID_SIZE);
1030 if( r == ERROR_SUCCESS )
1031 unsquash_guid(szKeyName, lpProductBuf);
1032 RegCloseKey(hkey);
1034 return r;
1037 /*************************************************************************
1038 * MsiEnumRelatedProductsA [MSI.@]
1041 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1042 DWORD iProductIndex, LPSTR lpProductBuf)
1044 LPWSTR szwUpgradeCode = NULL;
1045 WCHAR productW[GUID_SIZE];
1046 UINT r;
1048 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1049 iProductIndex, lpProductBuf);
1051 if (szUpgradeCode)
1053 szwUpgradeCode = strdupAtoW( szUpgradeCode );
1054 if( !szwUpgradeCode )
1055 return ERROR_OUTOFMEMORY;
1058 r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1059 iProductIndex, productW );
1060 if (r == ERROR_SUCCESS)
1062 WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1063 lpProductBuf, GUID_SIZE, NULL, NULL );
1065 msi_free( szwUpgradeCode);
1066 return r;
1069 /***********************************************************************
1070 * MsiEnumPatchesA [MSI.@]
1072 UINT WINAPI MsiEnumPatchesA( LPCSTR szProduct, DWORD iPatchIndex,
1073 LPSTR lpPatchBuf, LPSTR lpTransformsBuf, DWORD* pcchTransformsBuf)
1075 FIXME("%s %d %p %p %p\n", debugstr_a(szProduct),
1076 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1077 return ERROR_NO_MORE_ITEMS;
1080 /***********************************************************************
1081 * MsiEnumPatchesW [MSI.@]
1083 UINT WINAPI MsiEnumPatchesW( LPCWSTR szProduct, DWORD iPatchIndex,
1084 LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, DWORD* pcchTransformsBuf)
1086 FIXME("%s %d %p %p %p\n", debugstr_w(szProduct),
1087 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1088 return ERROR_NO_MORE_ITEMS;