msi: Implement the MSIINSTALLCONTEXT_MACHINE context for MsiQueryComponentState.
[wine/hacks.git] / dlls / msi / registry.c
blob67eae4b5b8cfb1b89f8f3311de149b6be13de1ef
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"
39 #include "sddl.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi);
44 /*
45 * This module will be all the helper functions for registry access by the
46 * installer bits.
48 static const WCHAR szUserFeatures_fmt[] = {
49 'S','o','f','t','w','a','r','e','\\',
50 'M','i','c','r','o','s','o','f','t','\\',
51 'I','n','s','t','a','l','l','e','r','\\',
52 'F','e','a','t','u','r','e','s','\\',
53 '%','s',0};
55 static const WCHAR szInstaller_Features[] = {
56 'S','o','f','t','w','a','r','e','\\',
57 'M','i','c','r','o','s','o','f','t','\\',
58 'W','i','n','d','o','w','s','\\',
59 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
60 'I','n','s','t','a','l','l','e','r','\\',
61 'F','e','a','t','u','r','e','s',0 };
63 static const WCHAR szUserDataFeatures_fmt[] = {
64 'S','o','f','t','w','a','r','e','\\',
65 'M','i','c','r','o','s','o','f','t','\\',
66 'W','i','n','d','o','w','s','\\',
67 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
68 'I','n','s','t','a','l','l','e','r','\\',
69 'U','s','e','r','D','a','t','a','\\',
70 '%','s','\\','P','r','o','d','u','c','t','s','\\',
71 '%','s','\\','F','e','a','t','u','r','e','s',0};
73 static const WCHAR szInstaller_Features_fmt[] = {
74 'S','o','f','t','w','a','r','e','\\',
75 'M','i','c','r','o','s','o','f','t','\\',
76 'W','i','n','d','o','w','s','\\',
77 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
78 'I','n','s','t','a','l','l','e','r','\\',
79 'F','e','a','t','u','r','e','s','\\',
80 '%','s',0};
82 static const WCHAR szInstaller_Components[] = {
83 'S','o','f','t','w','a','r','e','\\',
84 'M','i','c','r','o','s','o','f','t','\\',
85 'W','i','n','d','o','w','s','\\',
86 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
87 'I','n','s','t','a','l','l','e','r','\\',
88 'C','o','m','p','o','n','e','n','t','s',0 };
90 static const WCHAR szInstaller_Components_fmt[] = {
91 'S','o','f','t','w','a','r','e','\\',
92 'M','i','c','r','o','s','o','f','t','\\',
93 'W','i','n','d','o','w','s','\\',
94 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
95 'I','n','s','t','a','l','l','e','r','\\',
96 'C','o','m','p','o','n','e','n','t','s','\\',
97 '%','s',0};
99 static const WCHAR szUser_Components_fmt[] = {
100 'S','o','f','t','w','a','r','e','\\',
101 'M','i','c','r','o','s','o','f','t','\\',
102 'I','n','s','t','a','l','l','e','r','\\',
103 'C','o','m','p','o','n','e','n','t','s','\\',
104 '%','s',0};
106 static const WCHAR szUserDataComp_fmt[] = {
107 'S','o','f','t','w','a','r','e','\\',
108 'M','i','c','r','o','s','o','f','t','\\',
109 'W','i','n','d','o','w','s','\\',
110 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
111 'I','n','s','t','a','l','l','e','r','\\',
112 'U','s','e','r','D','a','t','a','\\',
113 '%','s','\\','C','o','m','p','o','n','e','n','t','s','\\','%','s',0};
115 static const WCHAR szUninstall_fmt[] = {
116 'S','o','f','t','w','a','r','e','\\',
117 'M','i','c','r','o','s','o','f','t','\\',
118 'W','i','n','d','o','w','s','\\',
119 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
120 'U','n','i','n','s','t','a','l','l','\\',
121 '%','s',0 };
123 static const WCHAR szUserProduct_fmt[] = {
124 'S','o','f','t','w','a','r','e','\\',
125 'M','i','c','r','o','s','o','f','t','\\',
126 'I','n','s','t','a','l','l','e','r','\\',
127 'P','r','o','d','u','c','t','s','\\',
128 '%','s',0};
130 static const WCHAR szUserPatch_fmt[] = {
131 'S','o','f','t','w','a','r','e','\\',
132 'M','i','c','r','o','s','o','f','t','\\',
133 'I','n','s','t','a','l','l','e','r','\\',
134 'P','a','t','c','h','e','s','\\',
135 '%','s',0};
137 static const WCHAR szInstaller_Products[] = {
138 'S','o','f','t','w','a','r','e','\\',
139 'M','i','c','r','o','s','o','f','t','\\',
140 'W','i','n','d','o','w','s','\\',
141 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
142 'I','n','s','t','a','l','l','e','r','\\',
143 'P','r','o','d','u','c','t','s',0};
145 static const WCHAR szInstaller_Products_fmt[] = {
146 'S','o','f','t','w','a','r','e','\\',
147 'M','i','c','r','o','s','o','f','t','\\',
148 'W','i','n','d','o','w','s','\\',
149 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
150 'I','n','s','t','a','l','l','e','r','\\',
151 'P','r','o','d','u','c','t','s','\\',
152 '%','s',0};
154 static const WCHAR szInstaller_Patches_fmt[] = {
155 'S','o','f','t','w','a','r','e','\\',
156 'M','i','c','r','o','s','o','f','t','\\',
157 'W','i','n','d','o','w','s','\\',
158 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
159 'I','n','s','t','a','l','l','e','r','\\',
160 'P','a','t','c','h','e','s','\\',
161 '%','s',0};
163 static const WCHAR szInstaller_UpgradeCodes_fmt[] = {
164 'S','o','f','t','w','a','r','e','\\',
165 'M','i','c','r','o','s','o','f','t','\\',
166 'W','i','n','d','o','w','s','\\',
167 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
168 'I','n','s','t','a','l','l','e','r','\\',
169 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
170 '%','s',0};
172 static const WCHAR szInstaller_UserUpgradeCodes_fmt[] = {
173 'S','o','f','t','w','a','r','e','\\',
174 'M','i','c','r','o','s','o','f','t','\\',
175 'I','n','s','t','a','l','l','e','r','\\',
176 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
177 '%','s',0};
179 static const WCHAR szUserDataProd_fmt[] = {
180 'S','o','f','t','w','a','r','e','\\',
181 'M','i','c','r','o','s','o','f','t','\\',
182 'W','i','n','d','o','w','s','\\',
183 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
184 'I','n','s','t','a','l','l','e','r','\\',
185 'U','s','e','r','D','a','t','a','\\',
186 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s',0};
188 static const WCHAR szInstallProperties_fmt[] = {
189 'S','o','f','t','w','a','r','e','\\',
190 'M','i','c','r','o','s','o','f','t','\\',
191 'W','i','n','d','o','w','s','\\',
192 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
193 'I','n','s','t','a','l','l','e','r','\\',
194 'U','s','e','r','D','a','t','a','\\',
195 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\',
196 'I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0};
198 static const WCHAR szInstaller_LocalSystemProductCodes_fmt[] = {
199 'S','o','f','t','w','a','r','e','\\',
200 'M','i','c','r','o','s','o','f','t','\\',
201 'W','i','n','d','o','w','s','\\',
202 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
203 'I','n','s','t','a','l','l','e','r','\\',
204 'U','s','e','r','D','a','t','a','\\',
205 'S','-','1','-','5','-','1','8','\\','P','r','o','d','u','c','t','s','\\',
206 '%','s','\\','I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0};
208 static const WCHAR szInstaller_LocalSystemComponent_fmt[] = {
209 'S','o','f','t','w','a','r','e','\\',
210 'M','i','c','r','o','s','o','f','t','\\',
211 'W','i','n','d','o','w','s','\\',
212 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
213 'I','n','s','t','a','l','l','e','r','\\',
214 'U','s','e','r','D','a','t','a','\\',
215 'S','-','1','-','5','-','1','8','\\',
216 'C','o','m','p','o','n','e','n','t','s','\\','%','s',0};
219 #define SQUISH_GUID_SIZE 33
221 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
223 DWORD i,n=0;
225 out[n++]='{';
226 for(i=0; i<8; i++)
227 out[n++] = in[7-i];
228 out[n++]='-';
229 for(i=0; i<4; i++)
230 out[n++] = in[11-i];
231 out[n++]='-';
232 for(i=0; i<4; i++)
233 out[n++] = in[15-i];
234 out[n++]='-';
235 for(i=0; i<2; i++)
237 out[n++] = in[17+i*2];
238 out[n++] = in[16+i*2];
240 out[n++]='-';
241 for( ; i<8; i++)
243 out[n++] = in[17+i*2];
244 out[n++] = in[16+i*2];
246 out[n++]='}';
247 out[n]=0;
248 return TRUE;
251 BOOL squash_guid(LPCWSTR in, LPWSTR out)
253 DWORD i,n=1;
254 GUID guid;
256 out[0] = 0;
258 if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
259 return FALSE;
261 for(i=0; i<8; i++)
262 out[7-i] = in[n++];
263 n++;
264 for(i=0; i<4; i++)
265 out[11-i] = in[n++];
266 n++;
267 for(i=0; i<4; i++)
268 out[15-i] = in[n++];
269 n++;
270 for(i=0; i<2; i++)
272 out[17+i*2] = in[n++];
273 out[16+i*2] = in[n++];
275 n++;
276 for( ; i<8; i++)
278 out[17+i*2] = in[n++];
279 out[16+i*2] = in[n++];
281 out[32]=0;
282 return TRUE;
286 /* tables for encoding and decoding base85 */
287 static const unsigned char table_dec85[0x80] = {
288 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
289 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
290 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
291 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
292 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
293 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
294 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
295 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
298 static const char table_enc85[] =
299 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
300 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
301 "yz{}~";
304 * Converts a base85 encoded guid into a GUID pointer
305 * Base85 encoded GUIDs should be 20 characters long.
307 * returns TRUE if successful, FALSE if not
309 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
311 DWORD i, val = 0, base = 1, *p;
313 if (!str)
314 return FALSE;
316 p = (DWORD*) guid;
317 for( i=0; i<20; i++ )
319 if( (i%5) == 0 )
321 val = 0;
322 base = 1;
324 val += table_dec85[str[i]] * base;
325 if( str[i] >= 0x80 )
326 return FALSE;
327 if( table_dec85[str[i]] == 0xff )
328 return FALSE;
329 if( (i%5) == 4 )
330 p[i/5] = val;
331 base *= 85;
333 return TRUE;
337 * Encodes a base85 guid given a GUID pointer
338 * Caller should provide a 21 character buffer for the encoded string.
340 * returns TRUE if successful, FALSE if not
342 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
344 unsigned int x, *p, i;
346 p = (unsigned int*) guid;
347 for( i=0; i<4; i++ )
349 x = p[i];
350 *str++ = table_enc85[x%85];
351 x = x/85;
352 *str++ = table_enc85[x%85];
353 x = x/85;
354 *str++ = table_enc85[x%85];
355 x = x/85;
356 *str++ = table_enc85[x%85];
357 x = x/85;
358 *str++ = table_enc85[x%85];
360 *str = 0;
362 return TRUE;
365 DWORD msi_version_str_to_dword(LPCWSTR p)
367 DWORD major, minor = 0, build = 0, version = 0;
369 if (!p)
370 return version;
372 major = atoiW(p);
374 p = strchrW(p, '.');
375 if (p)
377 minor = atoiW(p+1);
378 p = strchrW(p+1, '.');
379 if (p)
380 build = atoiW(p+1);
383 return MAKELONG(build, MAKEWORD(minor, major));
386 LPWSTR msi_version_dword_to_str(DWORD version)
388 const WCHAR fmt[] = { '%','u','.','%','u','.','%','u',0 };
389 LPWSTR str = msi_alloc(20);
390 sprintfW(str, fmt,
391 (version&0xff000000)>>24,
392 (version&0x00ff0000)>>16,
393 version&0x0000ffff);
394 return str;
397 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
399 DWORD len = value ? (lstrlenW(value) + 1) * sizeof (WCHAR) : 0;
400 return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len );
403 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
405 LPCWSTR p = value;
406 while (*p) p += lstrlenW(p) + 1;
407 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
408 (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) );
411 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
413 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
416 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
418 HKEY hsubkey = 0;
419 LONG r;
421 r = RegCreateKeyW( hkey, path, &hsubkey );
422 if (r != ERROR_SUCCESS)
423 return r;
424 r = msi_reg_set_val_str( hsubkey, name, val );
425 RegCloseKey( hsubkey );
426 return r;
429 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
431 DWORD len = 0;
432 LPWSTR val;
433 LONG r;
435 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
436 if (r != ERROR_SUCCESS)
437 return NULL;
439 len += sizeof (WCHAR);
440 val = msi_alloc( len );
441 if (!val)
442 return NULL;
443 val[0] = 0;
444 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
445 return val;
448 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
450 DWORD type, len = sizeof (DWORD);
451 LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
452 return r == ERROR_SUCCESS && type == REG_DWORD;
455 static UINT get_user_sid(LPWSTR *usersid)
457 HANDLE token;
458 BYTE buf[1024];
459 DWORD size;
460 PTOKEN_USER user;
462 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
463 return ERROR_FUNCTION_FAILED;
465 size = sizeof(buf);
466 if (!GetTokenInformation(token, TokenUser, (void *)buf, size, &size))
467 return ERROR_FUNCTION_FAILED;
469 user = (PTOKEN_USER)buf;
470 if (!ConvertSidToStringSidW(user->User.Sid, usersid))
471 return ERROR_FUNCTION_FAILED;
473 return ERROR_SUCCESS;
476 UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create)
478 UINT rc;
479 WCHAR keypath[0x200];
480 TRACE("%s\n",debugstr_w(szProduct));
482 sprintfW(keypath,szUninstall_fmt,szProduct);
484 if (create)
485 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
486 else
487 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
489 return rc;
492 UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
494 UINT rc;
495 WCHAR squished_pc[GUID_SIZE];
496 WCHAR keypath[0x200];
498 TRACE("%s\n",debugstr_w(szProduct));
499 if (!squash_guid(szProduct,squished_pc))
500 return ERROR_FUNCTION_FAILED;
501 TRACE("squished (%s)\n", debugstr_w(squished_pc));
503 sprintfW(keypath,szUserProduct_fmt,squished_pc);
505 if (create)
506 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
507 else
508 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
510 return rc;
513 UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct)
515 WCHAR squished_pc[GUID_SIZE];
516 WCHAR keypath[0x200];
518 TRACE("%s\n",debugstr_w(szProduct));
519 if (!squash_guid(szProduct,squished_pc))
520 return ERROR_FUNCTION_FAILED;
521 TRACE("squished (%s)\n", debugstr_w(squished_pc));
523 sprintfW(keypath,szUserProduct_fmt,squished_pc);
525 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
528 UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
530 UINT rc;
531 WCHAR squished_pc[GUID_SIZE];
532 WCHAR keypath[0x200];
534 TRACE("%s\n",debugstr_w(szPatch));
535 if (!squash_guid(szPatch,squished_pc))
536 return ERROR_FUNCTION_FAILED;
537 TRACE("squished (%s)\n", debugstr_w(squished_pc));
539 sprintfW(keypath,szUserPatch_fmt,squished_pc);
541 if (create)
542 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
543 else
544 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
546 return rc;
549 UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
551 UINT rc;
552 WCHAR squished_pc[GUID_SIZE];
553 WCHAR keypath[0x200];
555 TRACE("%s\n",debugstr_w(szProduct));
556 if (!squash_guid(szProduct,squished_pc))
557 return ERROR_FUNCTION_FAILED;
558 TRACE("squished (%s)\n", debugstr_w(squished_pc));
560 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
562 if (create)
563 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
564 else
565 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
567 return rc;
570 UINT MSIREG_OpenFeatures(HKEY* key)
572 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Features,key);
575 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
577 UINT rc;
578 WCHAR squished_pc[GUID_SIZE];
579 WCHAR keypath[0x200];
581 TRACE("%s\n",debugstr_w(szProduct));
582 if (!squash_guid(szProduct,squished_pc))
583 return ERROR_FUNCTION_FAILED;
584 TRACE("squished (%s)\n", debugstr_w(squished_pc));
586 sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
588 if (create)
589 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
590 else
591 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
593 return rc;
596 UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL create)
598 UINT rc;
599 WCHAR squished_pc[GUID_SIZE];
600 WCHAR keypath[0x200];
601 LPWSTR usersid;
603 TRACE("%s\n", debugstr_w(szProduct));
604 if (!squash_guid(szProduct, squished_pc))
605 return ERROR_FUNCTION_FAILED;
606 TRACE("squished (%s)\n", debugstr_w(squished_pc));
608 rc = get_user_sid(&usersid);
609 if (rc != ERROR_SUCCESS || !usersid)
611 ERR("Failed to retrieve user SID: %d\n", rc);
612 return rc;
615 sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc);
617 if (create)
618 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
619 else
620 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
622 msi_free(usersid);
623 return rc;
626 UINT MSIREG_OpenComponents(HKEY* key)
628 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Components,key);
631 UINT MSIREG_OpenComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
633 UINT rc;
634 WCHAR squished_cc[GUID_SIZE];
635 WCHAR keypath[0x200];
637 TRACE("%s\n",debugstr_w(szComponent));
638 if (!squash_guid(szComponent,squished_cc))
639 return ERROR_FUNCTION_FAILED;
640 TRACE("squished (%s)\n", debugstr_w(squished_cc));
642 sprintfW(keypath,szInstaller_Components_fmt,squished_cc);
644 if (create)
645 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
646 else
647 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
649 return rc;
652 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
654 UINT rc;
655 WCHAR squished_cc[GUID_SIZE];
656 WCHAR keypath[0x200];
658 TRACE("%s\n",debugstr_w(szComponent));
659 if (!squash_guid(szComponent,squished_cc))
660 return ERROR_FUNCTION_FAILED;
661 TRACE("squished (%s)\n", debugstr_w(squished_cc));
663 sprintfW(keypath,szUser_Components_fmt,squished_cc);
665 if (create)
666 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
667 else
668 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
670 return rc;
673 UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create)
675 UINT rc;
676 WCHAR comp[GUID_SIZE];
677 WCHAR keypath[0x200];
678 LPWSTR usersid;
680 TRACE("%s\n", debugstr_w(szComponent));
681 if (!squash_guid(szComponent, comp))
682 return ERROR_FUNCTION_FAILED;
683 TRACE("squished (%s)\n", debugstr_w(comp));
685 rc = get_user_sid(&usersid);
686 if (rc != ERROR_SUCCESS || !usersid)
688 ERR("Failed to retrieve user SID: %d\n", rc);
689 return rc;
692 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
694 if (create)
695 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
696 else
697 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
699 msi_free(usersid);
700 return rc;
703 UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, HKEY *key, BOOL create)
705 UINT rc;
706 WCHAR squished_pc[GUID_SIZE];
707 WCHAR keypath[0x200];
708 LPWSTR usersid;
710 TRACE("%s\n", debugstr_w(szProduct));
711 if (!squash_guid(szProduct, squished_pc))
712 return ERROR_FUNCTION_FAILED;
713 TRACE("squished (%s)\n", debugstr_w(squished_pc));
715 rc = get_user_sid(&usersid);
716 if (rc != ERROR_SUCCESS || !usersid)
718 ERR("Failed to retrieve user SID: %d\n", rc);
719 return rc;
722 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
724 if (create)
725 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
726 else
727 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
729 msi_free(usersid);
730 return rc;
733 UINT MSIREG_OpenInstallPropertiesKey(LPCWSTR szProduct, HKEY *key, BOOL create)
735 UINT rc;
736 WCHAR squished_pc[GUID_SIZE];
737 WCHAR keypath[0x200];
738 LPWSTR usersid;
740 TRACE("%s\n", debugstr_w(szProduct));
741 if (!squash_guid(szProduct, squished_pc))
742 return ERROR_FUNCTION_FAILED;
743 TRACE("squished (%s)\n", debugstr_w(squished_pc));
745 rc = get_user_sid(&usersid);
746 if (rc != ERROR_SUCCESS || !usersid)
748 ERR("Failed to retrieve user SID: %d\n", rc);
749 return rc;
752 sprintfW(keypath, szInstallProperties_fmt, usersid, squished_pc);
754 if (create)
755 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
756 else
757 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
759 msi_free(usersid);
760 return rc;
763 UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)
765 UINT rc;
766 WCHAR squished_pc[GUID_SIZE];
767 WCHAR keypath[0x200];
768 LPWSTR usersid;
770 TRACE("%s\n", debugstr_w(szProduct));
771 if (!squash_guid(szProduct, squished_pc))
772 return ERROR_FUNCTION_FAILED;
773 TRACE("squished (%s)\n", debugstr_w(squished_pc));
775 rc = get_user_sid(&usersid);
776 if (rc != ERROR_SUCCESS || !usersid)
778 ERR("Failed to retrieve user SID: %d\n", rc);
779 return rc;
782 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
784 msi_free(usersid);
785 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
788 UINT MSIREG_OpenProducts(HKEY* key)
790 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Products,key);
793 UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
795 UINT rc;
796 WCHAR squished_pc[GUID_SIZE];
797 WCHAR keypath[0x200];
799 TRACE("%s\n",debugstr_w(szProduct));
800 if (!squash_guid(szProduct,squished_pc))
801 return ERROR_FUNCTION_FAILED;
802 TRACE("squished (%s)\n", debugstr_w(squished_pc));
804 sprintfW(keypath,szInstaller_Products_fmt,squished_pc);
806 if (create)
807 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
808 else
809 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
811 return rc;
814 UINT MSIREG_DeleteProductKey(LPCWSTR szProduct)
816 WCHAR squished_pc[GUID_SIZE];
817 WCHAR keypath[0x200];
819 TRACE("%s\n", debugstr_w(szProduct));
820 if (!squash_guid(szProduct, squished_pc))
821 return ERROR_FUNCTION_FAILED;
822 TRACE("squished (%s)\n", debugstr_w(squished_pc));
824 sprintfW(keypath, szInstaller_Products_fmt, squished_pc);
826 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
829 UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
831 UINT rc;
832 WCHAR squished_pc[GUID_SIZE];
833 WCHAR keypath[0x200];
835 TRACE("%s\n",debugstr_w(szPatch));
836 if (!squash_guid(szPatch,squished_pc))
837 return ERROR_FUNCTION_FAILED;
838 TRACE("squished (%s)\n", debugstr_w(squished_pc));
840 sprintfW(keypath,szInstaller_Patches_fmt,squished_pc);
842 if (create)
843 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
844 else
845 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
847 return rc;
850 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
852 UINT rc;
853 WCHAR squished_pc[GUID_SIZE];
854 WCHAR keypath[0x200];
856 TRACE("%s\n",debugstr_w(szUpgradeCode));
857 if (!squash_guid(szUpgradeCode,squished_pc))
858 return ERROR_FUNCTION_FAILED;
859 TRACE("squished (%s)\n", debugstr_w(squished_pc));
861 sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
863 if (create)
864 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
865 else
866 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
868 return rc;
871 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
873 UINT rc;
874 WCHAR squished_pc[GUID_SIZE];
875 WCHAR keypath[0x200];
877 TRACE("%s\n",debugstr_w(szUpgradeCode));
878 if (!squash_guid(szUpgradeCode,squished_pc))
879 return ERROR_FUNCTION_FAILED;
880 TRACE("squished (%s)\n", debugstr_w(squished_pc));
882 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
884 if (create)
885 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
886 else
887 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
889 return rc;
892 UINT MSIREG_OpenLocalSystemProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create)
894 WCHAR squished_pc[GUID_SIZE];
895 WCHAR keypath[0x200];
897 TRACE("%s\n", debugstr_w(szProductCode));
899 if (!squash_guid(szProductCode, squished_pc))
900 return ERROR_FUNCTION_FAILED;
902 TRACE("squished (%s)\n", debugstr_w(squished_pc));
904 sprintfW(keypath, szInstaller_LocalSystemProductCodes_fmt, squished_pc);
906 if (create)
907 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
909 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
912 UINT MSIREG_OpenLocalSystemComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create)
914 WCHAR squished_pc[GUID_SIZE];
915 WCHAR keypath[0x200];
917 TRACE("%s\n", debugstr_w(szComponent));
919 if (!squash_guid(szComponent, squished_pc))
920 return ERROR_FUNCTION_FAILED;
922 TRACE("squished (%s)\n", debugstr_w(squished_pc));
924 sprintfW(keypath, szInstaller_LocalSystemComponent_fmt, squished_pc);
926 if (create)
927 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
929 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
933 /*************************************************************************
934 * MsiDecomposeDescriptorW [MSI.@]
936 * Decomposes an MSI descriptor into product, feature and component parts.
937 * An MSI descriptor is a string of the form:
938 * [base 85 guid] [feature code] '>' [base 85 guid]
940 * PARAMS
941 * szDescriptor [I] the descriptor to decompose
942 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
943 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
944 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
945 * pUsed [O] the length of the descriptor
947 * RETURNS
948 * ERROR_SUCCESS if everything worked correctly
949 * ERROR_INVALID_PARAMETER if the descriptor was invalid
952 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
953 LPWSTR szFeature, LPWSTR szComponent, DWORD *pUsed )
955 UINT r, len;
956 LPWSTR p;
957 GUID product, component;
959 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
960 szFeature, szComponent, pUsed);
962 r = decode_base85_guid( szDescriptor, &product );
963 if( !r )
964 return ERROR_INVALID_PARAMETER;
966 TRACE("product %s\n", debugstr_guid( &product ));
968 p = strchrW(&szDescriptor[20],'>');
969 if( !p )
970 return ERROR_INVALID_PARAMETER;
972 len = (p - &szDescriptor[20]);
973 if( len > MAX_FEATURE_CHARS )
974 return ERROR_INVALID_PARAMETER;
976 TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len ));
978 r = decode_base85_guid( p+1, &component );
979 if( !r )
980 return ERROR_INVALID_PARAMETER;
982 TRACE("component %s\n", debugstr_guid( &component ));
984 if (szProduct)
985 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
986 if (szComponent)
987 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
988 if (szFeature)
990 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
991 szFeature[len] = 0;
993 len = ( &p[21] - szDescriptor );
995 TRACE("length = %d\n", len);
996 *pUsed = len;
998 return ERROR_SUCCESS;
1001 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
1002 LPSTR szFeature, LPSTR szComponent, DWORD *pUsed )
1004 WCHAR product[MAX_FEATURE_CHARS+1];
1005 WCHAR feature[MAX_FEATURE_CHARS+1];
1006 WCHAR component[MAX_FEATURE_CHARS+1];
1007 LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
1008 UINT r;
1010 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
1011 szFeature, szComponent, pUsed);
1013 str = strdupAtoW( szDescriptor );
1014 if( szDescriptor && !str )
1015 return ERROR_OUTOFMEMORY;
1017 if (szProduct)
1018 p = product;
1019 if (szFeature)
1020 f = feature;
1021 if (szComponent)
1022 c = component;
1024 r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
1026 if (r == ERROR_SUCCESS)
1028 WideCharToMultiByte( CP_ACP, 0, p, -1,
1029 szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
1030 WideCharToMultiByte( CP_ACP, 0, f, -1,
1031 szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
1032 WideCharToMultiByte( CP_ACP, 0, c, -1,
1033 szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
1036 msi_free( str );
1038 return r;
1041 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
1043 DWORD r;
1044 WCHAR szwGuid[GUID_SIZE];
1046 TRACE("%d %p\n", index, lpguid);
1048 if (NULL == lpguid)
1049 return ERROR_INVALID_PARAMETER;
1050 r = MsiEnumProductsW(index, szwGuid);
1051 if( r == ERROR_SUCCESS )
1052 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1054 return r;
1057 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
1059 HKEY hkeyProducts = 0;
1060 DWORD r;
1061 WCHAR szKeyName[SQUISH_GUID_SIZE];
1063 TRACE("%d %p\n", index, lpguid);
1065 if (NULL == lpguid)
1066 return ERROR_INVALID_PARAMETER;
1068 r = MSIREG_OpenProducts(&hkeyProducts);
1069 if( r != ERROR_SUCCESS )
1070 return ERROR_NO_MORE_ITEMS;
1072 r = RegEnumKeyW(hkeyProducts, index, szKeyName, SQUISH_GUID_SIZE);
1073 if( r == ERROR_SUCCESS )
1074 unsquash_guid(szKeyName, lpguid);
1075 RegCloseKey(hkeyProducts);
1077 return r;
1080 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
1081 LPSTR szFeature, LPSTR szParent)
1083 DWORD r;
1084 WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
1085 LPWSTR szwProduct = NULL;
1087 TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent);
1089 if( szProduct )
1091 szwProduct = strdupAtoW( szProduct );
1092 if( !szwProduct )
1093 return ERROR_OUTOFMEMORY;
1096 r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
1097 if( r == ERROR_SUCCESS )
1099 WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
1100 szFeature, GUID_SIZE, NULL, NULL);
1101 WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
1102 szParent, GUID_SIZE, NULL, NULL);
1105 msi_free( szwProduct);
1107 return r;
1110 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
1111 LPWSTR szFeature, LPWSTR szParent)
1113 HKEY hkeyProduct = 0;
1114 DWORD r, sz;
1116 TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
1118 if( !szProduct )
1119 return ERROR_INVALID_PARAMETER;
1121 r = MSIREG_OpenFeaturesKey(szProduct,&hkeyProduct,FALSE);
1122 if( r != ERROR_SUCCESS )
1123 return ERROR_NO_MORE_ITEMS;
1125 sz = GUID_SIZE;
1126 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
1127 RegCloseKey(hkeyProduct);
1129 return r;
1132 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
1134 DWORD r;
1135 WCHAR szwGuid[GUID_SIZE];
1137 TRACE("%d %p\n", index, lpguid);
1139 r = MsiEnumComponentsW(index, szwGuid);
1140 if( r == ERROR_SUCCESS )
1141 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1143 return r;
1146 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
1148 HKEY hkeyComponents = 0;
1149 DWORD r;
1150 WCHAR szKeyName[SQUISH_GUID_SIZE];
1152 TRACE("%d %p\n", index, lpguid);
1154 r = MSIREG_OpenComponents(&hkeyComponents);
1155 if( r != ERROR_SUCCESS )
1156 return ERROR_NO_MORE_ITEMS;
1158 r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
1159 if( r == ERROR_SUCCESS )
1160 unsquash_guid(szKeyName, lpguid);
1161 RegCloseKey(hkeyComponents);
1163 return r;
1166 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
1168 DWORD r;
1169 WCHAR szwProduct[GUID_SIZE];
1170 LPWSTR szwComponent = NULL;
1172 TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
1174 if( szComponent )
1176 szwComponent = strdupAtoW( szComponent );
1177 if( !szwComponent )
1178 return ERROR_OUTOFMEMORY;
1181 r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
1182 if( r == ERROR_SUCCESS )
1184 WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
1185 szProduct, GUID_SIZE, NULL, NULL);
1188 msi_free( szwComponent);
1190 return r;
1193 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
1195 HKEY hkeyComp = 0;
1196 DWORD r, sz;
1197 WCHAR szValName[SQUISH_GUID_SIZE];
1199 TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct);
1201 r = MSIREG_OpenComponentsKey(szComponent,&hkeyComp,FALSE);
1202 if( r != ERROR_SUCCESS )
1203 return ERROR_NO_MORE_ITEMS;
1205 sz = SQUISH_GUID_SIZE;
1206 r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
1207 if( r == ERROR_SUCCESS )
1208 unsquash_guid(szValName, szProduct);
1210 RegCloseKey(hkeyComp);
1212 return r;
1215 static UINT WINAPI MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
1216 awstring *lpQualBuf, DWORD* pcchQual,
1217 awstring *lpAppBuf, DWORD* pcchAppBuf )
1219 DWORD name_sz, val_sz, name_max, val_max, type, ofs;
1220 LPWSTR name = NULL, val = NULL;
1221 UINT r, r2;
1222 HKEY key;
1224 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1225 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
1227 if (!szComponent)
1228 return ERROR_INVALID_PARAMETER;
1230 r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
1231 if (r != ERROR_SUCCESS)
1232 return ERROR_UNKNOWN_COMPONENT;
1234 /* figure out how big the name is we want to return */
1235 name_max = 0x10;
1236 r = ERROR_OUTOFMEMORY;
1237 name = msi_alloc( name_max * sizeof(WCHAR) );
1238 if (!name)
1239 goto end;
1241 val_max = 0x10;
1242 r = ERROR_OUTOFMEMORY;
1243 val = msi_alloc( val_max );
1244 if (!val)
1245 goto end;
1247 /* loop until we allocate enough memory */
1248 while (1)
1250 name_sz = name_max;
1251 val_sz = val_max;
1252 r = RegEnumValueW( key, iIndex, name, &name_sz,
1253 NULL, &type, (LPBYTE)val, &val_sz );
1254 if (r == ERROR_SUCCESS)
1255 break;
1256 if (r != ERROR_MORE_DATA)
1257 goto end;
1259 if (type != REG_MULTI_SZ)
1261 ERR("component data has wrong type (%d)\n", type);
1262 goto end;
1265 r = ERROR_OUTOFMEMORY;
1266 if ((name_sz+1) >= name_max)
1268 name_max *= 2;
1269 msi_free( name );
1270 name = msi_alloc( name_max * sizeof (WCHAR) );
1271 if (!name)
1272 goto end;
1273 continue;
1275 if (val_sz > val_max)
1277 val_max = val_sz + sizeof (WCHAR);
1278 msi_free( val );
1279 val = msi_alloc( val_max * sizeof (WCHAR) );
1280 if (!val)
1281 goto end;
1282 continue;
1284 ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
1285 goto end;
1288 ofs = 0;
1289 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
1290 if (r != ERROR_SUCCESS)
1291 goto end;
1293 TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
1295 r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
1296 r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
1298 if (r2 != ERROR_SUCCESS)
1299 r = r2;
1301 end:
1302 msi_free(val);
1303 msi_free(name);
1304 RegCloseKey(key);
1306 return r;
1309 /*************************************************************************
1310 * MsiEnumComponentQualifiersA [MSI.@]
1312 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
1313 LPSTR lpQualifierBuf, DWORD* pcchQualifierBuf,
1314 LPSTR lpApplicationDataBuf, DWORD* pcchApplicationDataBuf )
1316 awstring qual, appdata;
1317 LPWSTR comp;
1318 UINT r;
1320 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex,
1321 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1322 pcchApplicationDataBuf);
1324 comp = strdupAtoW( szComponent );
1325 if (szComponent && !comp)
1326 return ERROR_OUTOFMEMORY;
1328 qual.unicode = FALSE;
1329 qual.str.a = lpQualifierBuf;
1331 appdata.unicode = FALSE;
1332 appdata.str.a = lpApplicationDataBuf;
1334 r = MSI_EnumComponentQualifiers( comp, iIndex,
1335 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1336 msi_free( comp );
1337 return r;
1340 /*************************************************************************
1341 * MsiEnumComponentQualifiersW [MSI.@]
1343 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
1344 LPWSTR lpQualifierBuf, DWORD* pcchQualifierBuf,
1345 LPWSTR lpApplicationDataBuf, DWORD* pcchApplicationDataBuf )
1347 awstring qual, appdata;
1349 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1350 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1351 pcchApplicationDataBuf);
1353 qual.unicode = TRUE;
1354 qual.str.w = lpQualifierBuf;
1356 appdata.unicode = TRUE;
1357 appdata.str.w = lpApplicationDataBuf;
1359 return MSI_EnumComponentQualifiers( szComponent, iIndex,
1360 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1363 /*************************************************************************
1364 * MsiEnumRelatedProductsW [MSI.@]
1367 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
1368 DWORD iProductIndex, LPWSTR lpProductBuf)
1370 UINT r;
1371 HKEY hkey;
1372 DWORD dwSize = SQUISH_GUID_SIZE;
1373 WCHAR szKeyName[SQUISH_GUID_SIZE];
1375 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved,
1376 iProductIndex, lpProductBuf);
1378 if (NULL == szUpgradeCode)
1379 return ERROR_INVALID_PARAMETER;
1380 if (NULL == lpProductBuf)
1381 return ERROR_INVALID_PARAMETER;
1383 r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1384 if (r != ERROR_SUCCESS)
1385 return ERROR_NO_MORE_ITEMS;
1387 r = RegEnumValueW(hkey, iProductIndex, szKeyName, &dwSize, NULL, NULL, NULL, NULL);
1388 if( r == ERROR_SUCCESS )
1389 unsquash_guid(szKeyName, lpProductBuf);
1390 RegCloseKey(hkey);
1392 return r;
1395 /*************************************************************************
1396 * MsiEnumRelatedProductsA [MSI.@]
1399 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1400 DWORD iProductIndex, LPSTR lpProductBuf)
1402 LPWSTR szwUpgradeCode = NULL;
1403 WCHAR productW[GUID_SIZE];
1404 UINT r;
1406 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1407 iProductIndex, lpProductBuf);
1409 if (szUpgradeCode)
1411 szwUpgradeCode = strdupAtoW( szUpgradeCode );
1412 if( !szwUpgradeCode )
1413 return ERROR_OUTOFMEMORY;
1416 r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1417 iProductIndex, productW );
1418 if (r == ERROR_SUCCESS)
1420 WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1421 lpProductBuf, GUID_SIZE, NULL, NULL );
1423 msi_free( szwUpgradeCode);
1424 return r;
1427 /***********************************************************************
1428 * MsiEnumPatchesA [MSI.@]
1430 UINT WINAPI MsiEnumPatchesA( LPCSTR szProduct, DWORD iPatchIndex,
1431 LPSTR lpPatchBuf, LPSTR lpTransformsBuf, DWORD* pcchTransformsBuf)
1433 FIXME("%s %d %p %p %p\n", debugstr_a(szProduct),
1434 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1435 return ERROR_NO_MORE_ITEMS;
1438 /***********************************************************************
1439 * MsiEnumPatchesW [MSI.@]
1441 UINT WINAPI MsiEnumPatchesW( LPCWSTR szProduct, DWORD iPatchIndex,
1442 LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, DWORD* pcchTransformsBuf)
1444 FIXME("%s %d %p %p %p\n", debugstr_w(szProduct),
1445 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1446 return ERROR_NO_MORE_ITEMS;
1449 UINT WINAPI MsiEnumProductsExA( LPCSTR szProductCode, LPCSTR szUserSid,
1450 DWORD dwContext, DWORD dwIndex, CHAR szInstalledProductCode[39],
1451 MSIINSTALLCONTEXT* pdwInstalledContext, LPSTR szSid, LPDWORD pcchSid)
1453 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_a(szProductCode), debugstr_a(szUserSid),
1454 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1455 szSid, pcchSid);
1456 return ERROR_NO_MORE_ITEMS;
1459 UINT WINAPI MsiEnumProductsExW( LPCWSTR szProductCode, LPCWSTR szUserSid,
1460 DWORD dwContext, DWORD dwIndex, WCHAR szInstalledProductCode[39],
1461 MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, LPDWORD pcchSid)
1463 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_w(szProductCode), debugstr_w(szUserSid),
1464 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1465 szSid, pcchSid);
1466 return ERROR_NO_MORE_ITEMS;