wined3d: Add missing check for p8 primary in surface_download_data.
[wine.git] / dlls / msi / registry.c
blob74f84f7141da5c95c7f4238a9e17e362249c8ec9
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 szUserDataFeatures_fmt[] = {
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 'U','s','e','r','D','a','t','a','\\',
62 '%','s','\\','P','r','o','d','u','c','t','s','\\',
63 '%','s','\\','F','e','a','t','u','r','e','s',0};
65 static const WCHAR szInstaller_Features_fmt[] = {
66 'S','o','f','t','w','a','r','e','\\',
67 'M','i','c','r','o','s','o','f','t','\\',
68 'W','i','n','d','o','w','s','\\',
69 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
70 'I','n','s','t','a','l','l','e','r','\\',
71 'F','e','a','t','u','r','e','s','\\',
72 '%','s',0};
74 static const WCHAR szInstaller_Components[] = {
75 'S','o','f','t','w','a','r','e','\\',
76 'M','i','c','r','o','s','o','f','t','\\',
77 'W','i','n','d','o','w','s','\\',
78 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
79 'I','n','s','t','a','l','l','e','r','\\',
80 'C','o','m','p','o','n','e','n','t','s',0 };
82 static const WCHAR szUser_Components_fmt[] = {
83 'S','o','f','t','w','a','r','e','\\',
84 'M','i','c','r','o','s','o','f','t','\\',
85 'I','n','s','t','a','l','l','e','r','\\',
86 'C','o','m','p','o','n','e','n','t','s','\\',
87 '%','s',0};
89 static const WCHAR szUserDataComp_fmt[] = {
90 'S','o','f','t','w','a','r','e','\\',
91 'M','i','c','r','o','s','o','f','t','\\',
92 'W','i','n','d','o','w','s','\\',
93 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
94 'I','n','s','t','a','l','l','e','r','\\',
95 'U','s','e','r','D','a','t','a','\\',
96 '%','s','\\','C','o','m','p','o','n','e','n','t','s','\\','%','s',0};
98 static const WCHAR szUninstall_fmt[] = {
99 'S','o','f','t','w','a','r','e','\\',
100 'M','i','c','r','o','s','o','f','t','\\',
101 'W','i','n','d','o','w','s','\\',
102 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
103 'U','n','i','n','s','t','a','l','l','\\',
104 '%','s',0 };
106 static const WCHAR szUserProduct_fmt[] = {
107 'S','o','f','t','w','a','r','e','\\',
108 'M','i','c','r','o','s','o','f','t','\\',
109 'I','n','s','t','a','l','l','e','r','\\',
110 'P','r','o','d','u','c','t','s','\\',
111 '%','s',0};
113 static const WCHAR szUserPatch_fmt[] = {
114 'S','o','f','t','w','a','r','e','\\',
115 'M','i','c','r','o','s','o','f','t','\\',
116 'I','n','s','t','a','l','l','e','r','\\',
117 'P','a','t','c','h','e','s','\\',
118 '%','s',0};
120 static const WCHAR szInstaller_Products[] = {
121 'S','o','f','t','w','a','r','e','\\',
122 'M','i','c','r','o','s','o','f','t','\\',
123 'W','i','n','d','o','w','s','\\',
124 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
125 'I','n','s','t','a','l','l','e','r','\\',
126 'P','r','o','d','u','c','t','s',0};
128 static const WCHAR szInstaller_Products_fmt[] = {
129 'S','o','f','t','w','a','r','e','\\',
130 'M','i','c','r','o','s','o','f','t','\\',
131 'W','i','n','d','o','w','s','\\',
132 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
133 'I','n','s','t','a','l','l','e','r','\\',
134 'P','r','o','d','u','c','t','s','\\',
135 '%','s',0};
137 static const WCHAR szInstaller_Patches_fmt[] = {
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','a','t','c','h','e','s','\\',
144 '%','s',0};
146 static const WCHAR szInstaller_UpgradeCodes_fmt[] = {
147 'S','o','f','t','w','a','r','e','\\',
148 'M','i','c','r','o','s','o','f','t','\\',
149 'W','i','n','d','o','w','s','\\',
150 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
151 'I','n','s','t','a','l','l','e','r','\\',
152 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
153 '%','s',0};
155 static const WCHAR szInstaller_UserUpgradeCodes_fmt[] = {
156 'S','o','f','t','w','a','r','e','\\',
157 'M','i','c','r','o','s','o','f','t','\\',
158 'I','n','s','t','a','l','l','e','r','\\',
159 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
160 '%','s',0};
162 static const WCHAR szUserDataProd_fmt[] = {
163 'S','o','f','t','w','a','r','e','\\',
164 'M','i','c','r','o','s','o','f','t','\\',
165 'W','i','n','d','o','w','s','\\',
166 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
167 'I','n','s','t','a','l','l','e','r','\\',
168 'U','s','e','r','D','a','t','a','\\',
169 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s',0};
171 static const WCHAR szInstallProperties_fmt[] = {
172 'S','o','f','t','w','a','r','e','\\',
173 'M','i','c','r','o','s','o','f','t','\\',
174 'W','i','n','d','o','w','s','\\',
175 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
176 'I','n','s','t','a','l','l','e','r','\\',
177 'U','s','e','r','D','a','t','a','\\',
178 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\',
179 'I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0};
181 static const WCHAR szInstaller_LocalSystemProductCodes_fmt[] = {
182 'S','o','f','t','w','a','r','e','\\',
183 'M','i','c','r','o','s','o','f','t','\\',
184 'W','i','n','d','o','w','s','\\',
185 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
186 'I','n','s','t','a','l','l','e','r','\\',
187 'U','s','e','r','D','a','t','a','\\',
188 'S','-','1','-','5','-','1','8','\\','P','r','o','d','u','c','t','s','\\',
189 '%','s','\\','I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0};
191 static const WCHAR szInstaller_LocalSystemComponent_fmt[] = {
192 'S','o','f','t','w','a','r','e','\\',
193 'M','i','c','r','o','s','o','f','t','\\',
194 'W','i','n','d','o','w','s','\\',
195 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
196 'I','n','s','t','a','l','l','e','r','\\',
197 'U','s','e','r','D','a','t','a','\\',
198 'S','-','1','-','5','-','1','8','\\',
199 'C','o','m','p','o','n','e','n','t','s','\\','%','s',0};
201 static const WCHAR szInstaller_LocalClassesProd_fmt[] = {
202 'S','o','f','t','w','a','r','e','\\',
203 'C','l','a','s','s','e','s','\\',
204 'I','n','s','t','a','l','l','e','r','\\',
205 'P','r','o','d','u','c','t','s','\\','%','s',0};
207 static const WCHAR szInstaller_LocalManagedProd_fmt[] = {
208 'S','o','f','t','w','a','r','e','\\',
209 'M','i','c','r','o','s','o','f','t','\\',
210 'W','i','n','d','o','w','s','\\',
211 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
212 'I','n','s','t','a','l','l','e','r','\\',
213 'M','a','n','a','g','e','d','\\','%','s','\\',
214 'I','n','s','t','a','l','l','e','r','\\',
215 'P','r','o','d','u','c','t','s','\\','%','s',0};
217 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
219 DWORD i,n=0;
221 out[n++]='{';
222 for(i=0; i<8; i++)
223 out[n++] = in[7-i];
224 out[n++]='-';
225 for(i=0; i<4; i++)
226 out[n++] = in[11-i];
227 out[n++]='-';
228 for(i=0; i<4; i++)
229 out[n++] = in[15-i];
230 out[n++]='-';
231 for(i=0; i<2; i++)
233 out[n++] = in[17+i*2];
234 out[n++] = in[16+i*2];
236 out[n++]='-';
237 for( ; i<8; i++)
239 out[n++] = in[17+i*2];
240 out[n++] = in[16+i*2];
242 out[n++]='}';
243 out[n]=0;
244 return TRUE;
247 BOOL squash_guid(LPCWSTR in, LPWSTR out)
249 DWORD i,n=1;
250 GUID guid;
252 out[0] = 0;
254 if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
255 return FALSE;
257 for(i=0; i<8; i++)
258 out[7-i] = in[n++];
259 n++;
260 for(i=0; i<4; i++)
261 out[11-i] = in[n++];
262 n++;
263 for(i=0; i<4; i++)
264 out[15-i] = in[n++];
265 n++;
266 for(i=0; i<2; i++)
268 out[17+i*2] = in[n++];
269 out[16+i*2] = in[n++];
271 n++;
272 for( ; i<8; i++)
274 out[17+i*2] = in[n++];
275 out[16+i*2] = in[n++];
277 out[32]=0;
278 return TRUE;
282 /* tables for encoding and decoding base85 */
283 static const unsigned char table_dec85[0x80] = {
284 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
285 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
286 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
287 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
288 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
289 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
290 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
291 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
294 static const char table_enc85[] =
295 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
296 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
297 "yz{}~";
300 * Converts a base85 encoded guid into a GUID pointer
301 * Base85 encoded GUIDs should be 20 characters long.
303 * returns TRUE if successful, FALSE if not
305 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
307 DWORD i, val = 0, base = 1, *p;
309 if (!str)
310 return FALSE;
312 p = (DWORD*) guid;
313 for( i=0; i<20; i++ )
315 if( (i%5) == 0 )
317 val = 0;
318 base = 1;
320 val += table_dec85[str[i]] * base;
321 if( str[i] >= 0x80 )
322 return FALSE;
323 if( table_dec85[str[i]] == 0xff )
324 return FALSE;
325 if( (i%5) == 4 )
326 p[i/5] = val;
327 base *= 85;
329 return TRUE;
333 * Encodes a base85 guid given a GUID pointer
334 * Caller should provide a 21 character buffer for the encoded string.
336 * returns TRUE if successful, FALSE if not
338 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
340 unsigned int x, *p, i;
342 p = (unsigned int*) guid;
343 for( i=0; i<4; i++ )
345 x = p[i];
346 *str++ = table_enc85[x%85];
347 x = x/85;
348 *str++ = table_enc85[x%85];
349 x = x/85;
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];
356 *str = 0;
358 return TRUE;
361 DWORD msi_version_str_to_dword(LPCWSTR p)
363 DWORD major, minor = 0, build = 0, version = 0;
365 if (!p)
366 return version;
368 major = atoiW(p);
370 p = strchrW(p, '.');
371 if (p)
373 minor = atoiW(p+1);
374 p = strchrW(p+1, '.');
375 if (p)
376 build = atoiW(p+1);
379 return MAKELONG(build, MAKEWORD(minor, major));
382 LPWSTR msi_version_dword_to_str(DWORD version)
384 const WCHAR fmt[] = { '%','u','.','%','u','.','%','u',0 };
385 LPWSTR str = msi_alloc(20);
386 sprintfW(str, fmt,
387 (version&0xff000000)>>24,
388 (version&0x00ff0000)>>16,
389 version&0x0000ffff);
390 return str;
393 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
395 DWORD len = value ? (lstrlenW(value) + 1) * sizeof (WCHAR) : 0;
396 return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len );
399 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
401 LPCWSTR p = value;
402 while (*p) p += lstrlenW(p) + 1;
403 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
404 (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) );
407 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
409 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
412 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
414 HKEY hsubkey = 0;
415 LONG r;
417 r = RegCreateKeyW( hkey, path, &hsubkey );
418 if (r != ERROR_SUCCESS)
419 return r;
420 r = msi_reg_set_val_str( hsubkey, name, val );
421 RegCloseKey( hsubkey );
422 return r;
425 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
427 DWORD len = 0;
428 LPWSTR val;
429 LONG r;
431 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
432 if (r != ERROR_SUCCESS)
433 return NULL;
435 len += sizeof (WCHAR);
436 val = msi_alloc( len );
437 if (!val)
438 return NULL;
439 val[0] = 0;
440 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
441 return val;
444 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
446 DWORD type, len = sizeof (DWORD);
447 LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
448 return r == ERROR_SUCCESS && type == REG_DWORD;
451 static UINT get_user_sid(LPWSTR *usersid)
453 HANDLE token;
454 BYTE buf[1024];
455 DWORD size;
456 PTOKEN_USER user;
458 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
459 return ERROR_FUNCTION_FAILED;
461 size = sizeof(buf);
462 if (!GetTokenInformation(token, TokenUser, (void *)buf, size, &size)) {
463 CloseHandle(token);
464 return ERROR_FUNCTION_FAILED;
467 user = (PTOKEN_USER)buf;
468 if (!ConvertSidToStringSidW(user->User.Sid, usersid)) {
469 CloseHandle(token);
470 return ERROR_FUNCTION_FAILED;
472 CloseHandle(token);
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_DeleteUninstallKey(LPCWSTR szProduct)
494 WCHAR keypath[0x200];
495 TRACE("%s\n",debugstr_w(szProduct));
497 sprintfW(keypath,szUninstall_fmt,szProduct);
499 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
502 UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
504 UINT rc;
505 WCHAR squished_pc[GUID_SIZE];
506 WCHAR keypath[0x200];
508 TRACE("%s\n",debugstr_w(szProduct));
509 if (!squash_guid(szProduct,squished_pc))
510 return ERROR_FUNCTION_FAILED;
511 TRACE("squished (%s)\n", debugstr_w(squished_pc));
513 sprintfW(keypath,szUserProduct_fmt,squished_pc);
515 if (create)
516 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
517 else
518 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
520 return rc;
523 UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct)
525 WCHAR squished_pc[GUID_SIZE];
526 WCHAR keypath[0x200];
528 TRACE("%s\n",debugstr_w(szProduct));
529 if (!squash_guid(szProduct,squished_pc))
530 return ERROR_FUNCTION_FAILED;
531 TRACE("squished (%s)\n", debugstr_w(squished_pc));
533 sprintfW(keypath,szUserProduct_fmt,squished_pc);
535 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
538 UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
540 UINT rc;
541 WCHAR squished_pc[GUID_SIZE];
542 WCHAR keypath[0x200];
544 TRACE("%s\n",debugstr_w(szPatch));
545 if (!squash_guid(szPatch,squished_pc))
546 return ERROR_FUNCTION_FAILED;
547 TRACE("squished (%s)\n", debugstr_w(squished_pc));
549 sprintfW(keypath,szUserPatch_fmt,squished_pc);
551 if (create)
552 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
553 else
554 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
556 return rc;
559 UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
561 UINT rc;
562 WCHAR squished_pc[GUID_SIZE];
563 WCHAR keypath[0x200];
565 TRACE("%s\n",debugstr_w(szProduct));
566 if (!squash_guid(szProduct,squished_pc))
567 return ERROR_FUNCTION_FAILED;
568 TRACE("squished (%s)\n", debugstr_w(squished_pc));
570 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
572 if (create)
573 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
574 else
575 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
577 return rc;
580 UINT MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct)
582 WCHAR squished_pc[GUID_SIZE];
583 WCHAR keypath[0x200];
585 TRACE("%s\n",debugstr_w(szProduct));
586 if (!squash_guid(szProduct,squished_pc))
587 return ERROR_FUNCTION_FAILED;
588 TRACE("squished (%s)\n", debugstr_w(squished_pc));
590 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
591 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
594 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
596 UINT rc;
597 WCHAR squished_pc[GUID_SIZE];
598 WCHAR keypath[0x200];
600 TRACE("%s\n",debugstr_w(szProduct));
601 if (!squash_guid(szProduct,squished_pc))
602 return ERROR_FUNCTION_FAILED;
603 TRACE("squished (%s)\n", debugstr_w(squished_pc));
605 sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
607 if (create)
608 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
609 else
610 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
612 return rc;
615 UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL create)
617 UINT rc;
618 WCHAR squished_pc[GUID_SIZE];
619 WCHAR keypath[0x200];
620 LPWSTR usersid;
622 TRACE("%s\n", debugstr_w(szProduct));
623 if (!squash_guid(szProduct, squished_pc))
624 return ERROR_FUNCTION_FAILED;
625 TRACE("squished (%s)\n", debugstr_w(squished_pc));
627 rc = get_user_sid(&usersid);
628 if (rc != ERROR_SUCCESS || !usersid)
630 ERR("Failed to retrieve user SID: %d\n", rc);
631 return rc;
634 sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc);
636 if (create)
637 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
638 else
639 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
641 LocalFree(usersid);
642 return rc;
645 UINT MSIREG_OpenComponents(HKEY* key)
647 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Components,key);
650 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
652 UINT rc;
653 WCHAR squished_cc[GUID_SIZE];
654 WCHAR keypath[0x200];
656 TRACE("%s\n",debugstr_w(szComponent));
657 if (!squash_guid(szComponent,squished_cc))
658 return ERROR_FUNCTION_FAILED;
659 TRACE("squished (%s)\n", debugstr_w(squished_cc));
661 sprintfW(keypath,szUser_Components_fmt,squished_cc);
663 if (create)
664 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
665 else
666 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
668 return rc;
671 UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create)
673 UINT rc;
674 WCHAR comp[GUID_SIZE];
675 WCHAR keypath[0x200];
676 LPWSTR usersid;
678 TRACE("%s\n", debugstr_w(szComponent));
679 if (!squash_guid(szComponent, comp))
680 return ERROR_FUNCTION_FAILED;
681 TRACE("squished (%s)\n", debugstr_w(comp));
683 rc = get_user_sid(&usersid);
684 if (rc != ERROR_SUCCESS || !usersid)
686 ERR("Failed to retrieve user SID: %d\n", rc);
687 return rc;
690 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
692 if (create)
693 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
694 else
695 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
697 LocalFree(usersid);
698 return rc;
701 UINT MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent)
703 UINT rc;
704 WCHAR comp[GUID_SIZE];
705 WCHAR keypath[0x200];
706 LPWSTR usersid;
708 TRACE("%s\n", debugstr_w(szComponent));
709 if (!squash_guid(szComponent, comp))
710 return ERROR_FUNCTION_FAILED;
711 TRACE("squished (%s)\n", debugstr_w(comp));
713 rc = get_user_sid(&usersid);
714 if (rc != ERROR_SUCCESS || !usersid)
716 ERR("Failed to retrieve user SID: %d\n", rc);
717 return rc;
720 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
722 LocalFree(usersid);
723 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
726 UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, HKEY *key, BOOL create)
728 UINT rc;
729 WCHAR squished_pc[GUID_SIZE];
730 WCHAR keypath[0x200];
731 LPWSTR usersid;
733 TRACE("%s\n", debugstr_w(szProduct));
734 if (!squash_guid(szProduct, squished_pc))
735 return ERROR_FUNCTION_FAILED;
736 TRACE("squished (%s)\n", debugstr_w(squished_pc));
738 rc = get_user_sid(&usersid);
739 if (rc != ERROR_SUCCESS || !usersid)
741 ERR("Failed to retrieve user SID: %d\n", rc);
742 return rc;
745 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
747 if (create)
748 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
749 else
750 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
752 LocalFree(usersid);
753 return rc;
756 static UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, LPCWSTR szUserSID,
757 HKEY *key, BOOL create)
759 UINT rc;
760 WCHAR squished_pc[GUID_SIZE];
761 WCHAR keypath[0x200];
763 TRACE("%s\n", debugstr_w(szProduct));
764 if (!squash_guid(szProduct, squished_pc))
765 return ERROR_FUNCTION_FAILED;
766 TRACE("squished (%s)\n", debugstr_w(squished_pc));
768 sprintfW(keypath, szInstallProperties_fmt, szUserSID, squished_pc);
770 if (create)
771 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
772 else
773 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
775 return rc;
778 UINT MSIREG_OpenCurrentUserInstallProps(LPCWSTR szProduct, HKEY *key,
779 BOOL create)
781 UINT rc;
782 LPWSTR usersid;
784 rc = get_user_sid(&usersid);
785 if (rc != ERROR_SUCCESS || !usersid)
787 ERR("Failed to retrieve user SID: %d\n", rc);
788 return rc;
791 rc = MSIREG_OpenInstallProps(szProduct, usersid, key, create);
793 LocalFree(usersid);
794 return rc;
797 UINT MSIREG_OpenLocalSystemInstallProps(LPCWSTR szProduct, HKEY *key,
798 BOOL create)
800 static const WCHAR localsid[] = {'S','-','1','-','5','-','1','8',0};
802 return MSIREG_OpenInstallProps(szProduct, localsid, key, create);
805 UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)
807 UINT rc;
808 WCHAR squished_pc[GUID_SIZE];
809 WCHAR keypath[0x200];
810 LPWSTR usersid;
812 TRACE("%s\n", debugstr_w(szProduct));
813 if (!squash_guid(szProduct, squished_pc))
814 return ERROR_FUNCTION_FAILED;
815 TRACE("squished (%s)\n", debugstr_w(squished_pc));
817 rc = get_user_sid(&usersid);
818 if (rc != ERROR_SUCCESS || !usersid)
820 ERR("Failed to retrieve user SID: %d\n", rc);
821 return rc;
824 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
826 LocalFree(usersid);
827 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
830 UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
832 UINT rc;
833 WCHAR squished_pc[GUID_SIZE];
834 WCHAR keypath[0x200];
836 TRACE("%s\n",debugstr_w(szProduct));
837 if (!squash_guid(szProduct,squished_pc))
838 return ERROR_FUNCTION_FAILED;
839 TRACE("squished (%s)\n", debugstr_w(squished_pc));
841 sprintfW(keypath,szInstaller_Products_fmt,squished_pc);
843 if (create)
844 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
845 else
846 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
848 return rc;
851 UINT MSIREG_DeleteProductKey(LPCWSTR szProduct)
853 WCHAR squished_pc[GUID_SIZE];
854 WCHAR keypath[0x200];
856 TRACE("%s\n", debugstr_w(szProduct));
857 if (!squash_guid(szProduct, squished_pc))
858 return ERROR_FUNCTION_FAILED;
859 TRACE("squished (%s)\n", debugstr_w(squished_pc));
861 sprintfW(keypath, szInstaller_Products_fmt, squished_pc);
863 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
866 UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
868 UINT rc;
869 WCHAR squished_pc[GUID_SIZE];
870 WCHAR keypath[0x200];
872 TRACE("%s\n",debugstr_w(szPatch));
873 if (!squash_guid(szPatch,squished_pc))
874 return ERROR_FUNCTION_FAILED;
875 TRACE("squished (%s)\n", debugstr_w(squished_pc));
877 sprintfW(keypath,szInstaller_Patches_fmt,squished_pc);
879 if (create)
880 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
881 else
882 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
884 return rc;
887 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
889 UINT rc;
890 WCHAR squished_pc[GUID_SIZE];
891 WCHAR keypath[0x200];
893 TRACE("%s\n",debugstr_w(szUpgradeCode));
894 if (!squash_guid(szUpgradeCode,squished_pc))
895 return ERROR_FUNCTION_FAILED;
896 TRACE("squished (%s)\n", debugstr_w(squished_pc));
898 sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
900 if (create)
901 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
902 else
903 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
905 return rc;
908 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
910 UINT rc;
911 WCHAR squished_pc[GUID_SIZE];
912 WCHAR keypath[0x200];
914 TRACE("%s\n",debugstr_w(szUpgradeCode));
915 if (!squash_guid(szUpgradeCode,squished_pc))
916 return ERROR_FUNCTION_FAILED;
917 TRACE("squished (%s)\n", debugstr_w(squished_pc));
919 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
921 if (create)
922 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
923 else
924 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
926 return rc;
929 UINT MSIREG_OpenLocalSystemProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create)
931 WCHAR squished_pc[GUID_SIZE];
932 WCHAR keypath[0x200];
934 TRACE("%s\n", debugstr_w(szProductCode));
936 if (!squash_guid(szProductCode, squished_pc))
937 return ERROR_FUNCTION_FAILED;
939 TRACE("squished (%s)\n", debugstr_w(squished_pc));
941 sprintfW(keypath, szInstaller_LocalSystemProductCodes_fmt, squished_pc);
943 if (create)
944 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
946 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
949 UINT MSIREG_OpenLocalSystemComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create)
951 WCHAR squished_pc[GUID_SIZE];
952 WCHAR keypath[0x200];
954 TRACE("%s\n", debugstr_w(szComponent));
956 if (!squash_guid(szComponent, squished_pc))
957 return ERROR_FUNCTION_FAILED;
959 TRACE("squished (%s)\n", debugstr_w(squished_pc));
961 sprintfW(keypath, szInstaller_LocalSystemComponent_fmt, squished_pc);
963 if (create)
964 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
966 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
969 UINT MSIREG_OpenLocalClassesProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create)
971 WCHAR squished_pc[GUID_SIZE];
972 WCHAR keypath[0x200];
974 TRACE("%s\n", debugstr_w(szProductCode));
976 if (!squash_guid(szProductCode, squished_pc))
977 return ERROR_FUNCTION_FAILED;
979 TRACE("squished (%s)\n", debugstr_w(squished_pc));
981 sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc);
983 if (create)
984 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
986 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
989 UINT MSIREG_OpenLocalManagedProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create)
991 WCHAR squished_pc[GUID_SIZE];
992 WCHAR keypath[0x200];
993 LPWSTR usersid;
994 UINT r;
996 TRACE("%s\n", debugstr_w(szProductCode));
998 if (!squash_guid(szProductCode, squished_pc))
999 return ERROR_FUNCTION_FAILED;
1001 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1003 r = get_user_sid(&usersid);
1004 if (r != ERROR_SUCCESS || !usersid)
1006 ERR("Failed to retrieve user SID: %d\n", r);
1007 return r;
1010 sprintfW(keypath, szInstaller_LocalManagedProd_fmt, usersid, squished_pc);
1011 LocalFree(usersid);
1013 if (create)
1014 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1016 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1019 /*************************************************************************
1020 * MsiDecomposeDescriptorW [MSI.@]
1022 * Decomposes an MSI descriptor into product, feature and component parts.
1023 * An MSI descriptor is a string of the form:
1024 * [base 85 guid] [feature code] '>' [base 85 guid]
1026 * PARAMS
1027 * szDescriptor [I] the descriptor to decompose
1028 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
1029 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
1030 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
1031 * pUsed [O] the length of the descriptor
1033 * RETURNS
1034 * ERROR_SUCCESS if everything worked correctly
1035 * ERROR_INVALID_PARAMETER if the descriptor was invalid
1038 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
1039 LPWSTR szFeature, LPWSTR szComponent, LPDWORD pUsed )
1041 UINT r, len;
1042 LPWSTR p;
1043 GUID product, component;
1045 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
1046 szFeature, szComponent, pUsed);
1048 r = decode_base85_guid( szDescriptor, &product );
1049 if( !r )
1050 return ERROR_INVALID_PARAMETER;
1052 TRACE("product %s\n", debugstr_guid( &product ));
1054 p = strchrW(&szDescriptor[20],'>');
1055 if( !p )
1056 return ERROR_INVALID_PARAMETER;
1058 len = (p - &szDescriptor[20]);
1059 if( len > MAX_FEATURE_CHARS )
1060 return ERROR_INVALID_PARAMETER;
1062 TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len ));
1064 r = decode_base85_guid( p+1, &component );
1065 if( !r )
1066 return ERROR_INVALID_PARAMETER;
1068 TRACE("component %s\n", debugstr_guid( &component ));
1070 if (szProduct)
1071 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
1072 if (szComponent)
1073 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
1074 if (szFeature)
1076 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
1077 szFeature[len] = 0;
1079 len = ( &p[21] - szDescriptor );
1081 TRACE("length = %d\n", len);
1082 *pUsed = len;
1084 return ERROR_SUCCESS;
1087 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
1088 LPSTR szFeature, LPSTR szComponent, LPDWORD pUsed )
1090 WCHAR product[MAX_FEATURE_CHARS+1];
1091 WCHAR feature[MAX_FEATURE_CHARS+1];
1092 WCHAR component[MAX_FEATURE_CHARS+1];
1093 LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
1094 UINT r;
1096 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
1097 szFeature, szComponent, pUsed);
1099 str = strdupAtoW( szDescriptor );
1100 if( szDescriptor && !str )
1101 return ERROR_OUTOFMEMORY;
1103 if (szProduct)
1104 p = product;
1105 if (szFeature)
1106 f = feature;
1107 if (szComponent)
1108 c = component;
1110 r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
1112 if (r == ERROR_SUCCESS)
1114 WideCharToMultiByte( CP_ACP, 0, p, -1,
1115 szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
1116 WideCharToMultiByte( CP_ACP, 0, f, -1,
1117 szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
1118 WideCharToMultiByte( CP_ACP, 0, c, -1,
1119 szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
1122 msi_free( str );
1124 return r;
1127 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
1129 DWORD r;
1130 WCHAR szwGuid[GUID_SIZE];
1132 TRACE("%d %p\n", index, lpguid);
1134 if (NULL == lpguid)
1135 return ERROR_INVALID_PARAMETER;
1136 r = MsiEnumProductsW(index, szwGuid);
1137 if( r == ERROR_SUCCESS )
1138 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1140 return r;
1143 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
1145 HKEY hkeyProducts = 0;
1146 DWORD r;
1147 WCHAR szKeyName[SQUISH_GUID_SIZE];
1149 TRACE("%d %p\n", index, lpguid);
1151 if (NULL == lpguid)
1152 return ERROR_INVALID_PARAMETER;
1154 r = RegCreateKeyW(HKEY_LOCAL_MACHINE, szInstaller_Products, &hkeyProducts);
1155 if( r != ERROR_SUCCESS )
1156 return ERROR_NO_MORE_ITEMS;
1158 r = RegEnumKeyW(hkeyProducts, index, szKeyName, SQUISH_GUID_SIZE);
1159 if( r == ERROR_SUCCESS )
1160 unsquash_guid(szKeyName, lpguid);
1161 RegCloseKey(hkeyProducts);
1163 return r;
1166 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
1167 LPSTR szFeature, LPSTR szParent)
1169 DWORD r;
1170 WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
1171 LPWSTR szwProduct = NULL;
1173 TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent);
1175 if( szProduct )
1177 szwProduct = strdupAtoW( szProduct );
1178 if( !szwProduct )
1179 return ERROR_OUTOFMEMORY;
1182 r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
1183 if( r == ERROR_SUCCESS )
1185 WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
1186 szFeature, GUID_SIZE, NULL, NULL);
1187 WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
1188 szParent, GUID_SIZE, NULL, NULL);
1191 msi_free( szwProduct);
1193 return r;
1196 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
1197 LPWSTR szFeature, LPWSTR szParent)
1199 HKEY hkeyProduct = 0;
1200 DWORD r, sz;
1202 TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
1204 if( !szProduct )
1205 return ERROR_INVALID_PARAMETER;
1207 r = MSIREG_OpenFeaturesKey(szProduct,&hkeyProduct,FALSE);
1208 if( r != ERROR_SUCCESS )
1209 return ERROR_NO_MORE_ITEMS;
1211 sz = GUID_SIZE;
1212 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
1213 RegCloseKey(hkeyProduct);
1215 return r;
1218 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
1220 DWORD r;
1221 WCHAR szwGuid[GUID_SIZE];
1223 TRACE("%d %p\n", index, lpguid);
1225 r = MsiEnumComponentsW(index, szwGuid);
1226 if( r == ERROR_SUCCESS )
1227 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1229 return r;
1232 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
1234 HKEY hkeyComponents = 0;
1235 DWORD r;
1236 WCHAR szKeyName[SQUISH_GUID_SIZE];
1238 TRACE("%d %p\n", index, lpguid);
1240 r = MSIREG_OpenComponents(&hkeyComponents);
1241 if( r != ERROR_SUCCESS )
1242 return ERROR_NO_MORE_ITEMS;
1244 r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
1245 if( r == ERROR_SUCCESS )
1246 unsquash_guid(szKeyName, lpguid);
1247 RegCloseKey(hkeyComponents);
1249 return r;
1252 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
1254 DWORD r;
1255 WCHAR szwProduct[GUID_SIZE];
1256 LPWSTR szwComponent = NULL;
1258 TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
1260 if ( !szProduct )
1261 return ERROR_INVALID_PARAMETER;
1263 if( szComponent )
1265 szwComponent = strdupAtoW( szComponent );
1266 if( !szwComponent )
1267 return ERROR_OUTOFMEMORY;
1270 r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
1271 if( r == ERROR_SUCCESS )
1273 WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
1274 szProduct, GUID_SIZE, NULL, NULL);
1277 msi_free( szwComponent);
1279 return r;
1282 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
1284 HKEY hkeyComp = 0;
1285 DWORD r, sz;
1286 WCHAR szValName[SQUISH_GUID_SIZE];
1288 TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct);
1290 if (!szComponent || !*szComponent || !szProduct)
1291 return ERROR_INVALID_PARAMETER;
1293 if (MSIREG_OpenUserDataComponentKey(szComponent, &hkeyComp, FALSE) != ERROR_SUCCESS &&
1294 MSIREG_OpenLocalSystemComponentKey(szComponent, &hkeyComp, FALSE) != ERROR_SUCCESS)
1295 return ERROR_UNKNOWN_COMPONENT;
1297 /* see if there are any products at all */
1298 sz = SQUISH_GUID_SIZE;
1299 r = RegEnumValueW(hkeyComp, 0, szValName, &sz, NULL, NULL, NULL, NULL);
1300 if (r != ERROR_SUCCESS)
1302 RegCloseKey(hkeyComp);
1304 if (index != 0)
1305 return ERROR_INVALID_PARAMETER;
1307 return ERROR_UNKNOWN_COMPONENT;
1310 sz = SQUISH_GUID_SIZE;
1311 r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
1312 if( r == ERROR_SUCCESS )
1313 unsquash_guid(szValName, szProduct);
1315 RegCloseKey(hkeyComp);
1317 return r;
1320 static UINT WINAPI MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
1321 awstring *lpQualBuf, LPDWORD pcchQual,
1322 awstring *lpAppBuf, LPDWORD pcchAppBuf )
1324 DWORD name_sz, val_sz, name_max, val_max, type, ofs;
1325 LPWSTR name = NULL, val = NULL;
1326 UINT r, r2;
1327 HKEY key;
1329 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1330 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
1332 if (!szComponent)
1333 return ERROR_INVALID_PARAMETER;
1335 r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
1336 if (r != ERROR_SUCCESS)
1337 return ERROR_UNKNOWN_COMPONENT;
1339 /* figure out how big the name is we want to return */
1340 name_max = 0x10;
1341 r = ERROR_OUTOFMEMORY;
1342 name = msi_alloc( name_max * sizeof(WCHAR) );
1343 if (!name)
1344 goto end;
1346 val_max = 0x10;
1347 r = ERROR_OUTOFMEMORY;
1348 val = msi_alloc( val_max );
1349 if (!val)
1350 goto end;
1352 /* loop until we allocate enough memory */
1353 while (1)
1355 name_sz = name_max;
1356 val_sz = val_max;
1357 r = RegEnumValueW( key, iIndex, name, &name_sz,
1358 NULL, &type, (LPBYTE)val, &val_sz );
1359 if (r == ERROR_SUCCESS)
1360 break;
1361 if (r != ERROR_MORE_DATA)
1362 goto end;
1364 if (type != REG_MULTI_SZ)
1366 ERR("component data has wrong type (%d)\n", type);
1367 goto end;
1370 r = ERROR_OUTOFMEMORY;
1371 if ((name_sz+1) >= name_max)
1373 name_max *= 2;
1374 msi_free( name );
1375 name = msi_alloc( name_max * sizeof (WCHAR) );
1376 if (!name)
1377 goto end;
1378 continue;
1380 if (val_sz > val_max)
1382 val_max = val_sz + sizeof (WCHAR);
1383 msi_free( val );
1384 val = msi_alloc( val_max * sizeof (WCHAR) );
1385 if (!val)
1386 goto end;
1387 continue;
1389 ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
1390 goto end;
1393 ofs = 0;
1394 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
1395 if (r != ERROR_SUCCESS)
1396 goto end;
1398 TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
1400 r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
1401 r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
1403 if (r2 != ERROR_SUCCESS)
1404 r = r2;
1406 end:
1407 msi_free(val);
1408 msi_free(name);
1409 RegCloseKey(key);
1411 return r;
1414 /*************************************************************************
1415 * MsiEnumComponentQualifiersA [MSI.@]
1417 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
1418 LPSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1419 LPSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1421 awstring qual, appdata;
1422 LPWSTR comp;
1423 UINT r;
1425 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex,
1426 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1427 pcchApplicationDataBuf);
1429 comp = strdupAtoW( szComponent );
1430 if (szComponent && !comp)
1431 return ERROR_OUTOFMEMORY;
1433 qual.unicode = FALSE;
1434 qual.str.a = lpQualifierBuf;
1436 appdata.unicode = FALSE;
1437 appdata.str.a = lpApplicationDataBuf;
1439 r = MSI_EnumComponentQualifiers( comp, iIndex,
1440 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1441 msi_free( comp );
1442 return r;
1445 /*************************************************************************
1446 * MsiEnumComponentQualifiersW [MSI.@]
1448 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
1449 LPWSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1450 LPWSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1452 awstring qual, appdata;
1454 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1455 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1456 pcchApplicationDataBuf);
1458 qual.unicode = TRUE;
1459 qual.str.w = lpQualifierBuf;
1461 appdata.unicode = TRUE;
1462 appdata.str.w = lpApplicationDataBuf;
1464 return MSI_EnumComponentQualifiers( szComponent, iIndex,
1465 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1468 /*************************************************************************
1469 * MsiEnumRelatedProductsW [MSI.@]
1472 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
1473 DWORD iProductIndex, LPWSTR lpProductBuf)
1475 UINT r;
1476 HKEY hkey;
1477 DWORD dwSize = SQUISH_GUID_SIZE;
1478 WCHAR szKeyName[SQUISH_GUID_SIZE];
1480 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved,
1481 iProductIndex, lpProductBuf);
1483 if (NULL == szUpgradeCode)
1484 return ERROR_INVALID_PARAMETER;
1485 if (NULL == lpProductBuf)
1486 return ERROR_INVALID_PARAMETER;
1488 r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1489 if (r != ERROR_SUCCESS)
1490 return ERROR_NO_MORE_ITEMS;
1492 r = RegEnumValueW(hkey, iProductIndex, szKeyName, &dwSize, NULL, NULL, NULL, NULL);
1493 if( r == ERROR_SUCCESS )
1494 unsquash_guid(szKeyName, lpProductBuf);
1495 RegCloseKey(hkey);
1497 return r;
1500 /*************************************************************************
1501 * MsiEnumRelatedProductsA [MSI.@]
1504 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1505 DWORD iProductIndex, LPSTR lpProductBuf)
1507 LPWSTR szwUpgradeCode = NULL;
1508 WCHAR productW[GUID_SIZE];
1509 UINT r;
1511 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1512 iProductIndex, lpProductBuf);
1514 if (szUpgradeCode)
1516 szwUpgradeCode = strdupAtoW( szUpgradeCode );
1517 if( !szwUpgradeCode )
1518 return ERROR_OUTOFMEMORY;
1521 r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1522 iProductIndex, productW );
1523 if (r == ERROR_SUCCESS)
1525 WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1526 lpProductBuf, GUID_SIZE, NULL, NULL );
1528 msi_free( szwUpgradeCode);
1529 return r;
1532 /***********************************************************************
1533 * MsiEnumPatchesA [MSI.@]
1535 UINT WINAPI MsiEnumPatchesA( LPCSTR szProduct, DWORD iPatchIndex,
1536 LPSTR lpPatchBuf, LPSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
1538 FIXME("%s %d %p %p %p\n", debugstr_a(szProduct),
1539 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1540 return ERROR_NO_MORE_ITEMS;
1543 /***********************************************************************
1544 * MsiEnumPatchesW [MSI.@]
1546 UINT WINAPI MsiEnumPatchesW( LPCWSTR szProduct, DWORD iPatchIndex,
1547 LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
1549 FIXME("%s %d %p %p %p\n", debugstr_w(szProduct),
1550 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1551 return ERROR_NO_MORE_ITEMS;
1554 UINT WINAPI MsiEnumProductsExA( LPCSTR szProductCode, LPCSTR szUserSid,
1555 DWORD dwContext, DWORD dwIndex, CHAR szInstalledProductCode[39],
1556 MSIINSTALLCONTEXT* pdwInstalledContext, LPSTR szSid, LPDWORD pcchSid)
1558 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_a(szProductCode), debugstr_a(szUserSid),
1559 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1560 szSid, pcchSid);
1561 return ERROR_NO_MORE_ITEMS;
1564 UINT WINAPI MsiEnumProductsExW( LPCWSTR szProductCode, LPCWSTR szUserSid,
1565 DWORD dwContext, DWORD dwIndex, WCHAR szInstalledProductCode[39],
1566 MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, LPDWORD pcchSid)
1568 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_w(szProductCode), debugstr_w(szUserSid),
1569 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1570 szSid, pcchSid);
1571 return ERROR_NO_MORE_ITEMS;