user32: Fix a message test that would only pass on wine.
[wine.git] / dlls / msi / registry.c
blob5c9c25185f3a20c767f51e6b0f85d02f683fe3d4
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};
218 static const WCHAR szInstaller_LocalClassesProd_fmt[] = {
219 'S','o','f','t','w','a','r','e','\\',
220 'C','l','a','s','s','e','s','\\',
221 'I','n','s','t','a','l','l','e','r','\\',
222 'P','r','o','d','u','c','t','s','\\','%','s',0};
224 static const WCHAR szInstaller_LocalManagedProd_fmt[] = {
225 'S','o','f','t','w','a','r','e','\\',
226 'M','i','c','r','o','s','o','f','t','\\',
227 'W','i','n','d','o','w','s','\\',
228 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
229 'I','n','s','t','a','l','l','e','r','\\',
230 'M','a','n','a','g','e','d','\\','%','s','\\',
231 'I','n','s','t','a','l','l','e','r','\\',
232 'P','r','o','d','u','c','t','s','\\','%','s',0};
234 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
236 DWORD i,n=0;
238 out[n++]='{';
239 for(i=0; i<8; i++)
240 out[n++] = in[7-i];
241 out[n++]='-';
242 for(i=0; i<4; i++)
243 out[n++] = in[11-i];
244 out[n++]='-';
245 for(i=0; i<4; i++)
246 out[n++] = in[15-i];
247 out[n++]='-';
248 for(i=0; i<2; i++)
250 out[n++] = in[17+i*2];
251 out[n++] = in[16+i*2];
253 out[n++]='-';
254 for( ; i<8; i++)
256 out[n++] = in[17+i*2];
257 out[n++] = in[16+i*2];
259 out[n++]='}';
260 out[n]=0;
261 return TRUE;
264 BOOL squash_guid(LPCWSTR in, LPWSTR out)
266 DWORD i,n=1;
267 GUID guid;
269 out[0] = 0;
271 if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
272 return FALSE;
274 for(i=0; i<8; i++)
275 out[7-i] = in[n++];
276 n++;
277 for(i=0; i<4; i++)
278 out[11-i] = in[n++];
279 n++;
280 for(i=0; i<4; i++)
281 out[15-i] = in[n++];
282 n++;
283 for(i=0; i<2; i++)
285 out[17+i*2] = in[n++];
286 out[16+i*2] = in[n++];
288 n++;
289 for( ; i<8; i++)
291 out[17+i*2] = in[n++];
292 out[16+i*2] = in[n++];
294 out[32]=0;
295 return TRUE;
299 /* tables for encoding and decoding base85 */
300 static const unsigned char table_dec85[0x80] = {
301 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
302 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
303 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
304 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
305 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
306 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
307 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
308 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
311 static const char table_enc85[] =
312 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
313 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
314 "yz{}~";
317 * Converts a base85 encoded guid into a GUID pointer
318 * Base85 encoded GUIDs should be 20 characters long.
320 * returns TRUE if successful, FALSE if not
322 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
324 DWORD i, val = 0, base = 1, *p;
326 if (!str)
327 return FALSE;
329 p = (DWORD*) guid;
330 for( i=0; i<20; i++ )
332 if( (i%5) == 0 )
334 val = 0;
335 base = 1;
337 val += table_dec85[str[i]] * base;
338 if( str[i] >= 0x80 )
339 return FALSE;
340 if( table_dec85[str[i]] == 0xff )
341 return FALSE;
342 if( (i%5) == 4 )
343 p[i/5] = val;
344 base *= 85;
346 return TRUE;
350 * Encodes a base85 guid given a GUID pointer
351 * Caller should provide a 21 character buffer for the encoded string.
353 * returns TRUE if successful, FALSE if not
355 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
357 unsigned int x, *p, i;
359 p = (unsigned int*) guid;
360 for( i=0; i<4; i++ )
362 x = p[i];
363 *str++ = table_enc85[x%85];
364 x = x/85;
365 *str++ = table_enc85[x%85];
366 x = x/85;
367 *str++ = table_enc85[x%85];
368 x = x/85;
369 *str++ = table_enc85[x%85];
370 x = x/85;
371 *str++ = table_enc85[x%85];
373 *str = 0;
375 return TRUE;
378 DWORD msi_version_str_to_dword(LPCWSTR p)
380 DWORD major, minor = 0, build = 0, version = 0;
382 if (!p)
383 return version;
385 major = atoiW(p);
387 p = strchrW(p, '.');
388 if (p)
390 minor = atoiW(p+1);
391 p = strchrW(p+1, '.');
392 if (p)
393 build = atoiW(p+1);
396 return MAKELONG(build, MAKEWORD(minor, major));
399 LPWSTR msi_version_dword_to_str(DWORD version)
401 const WCHAR fmt[] = { '%','u','.','%','u','.','%','u',0 };
402 LPWSTR str = msi_alloc(20);
403 sprintfW(str, fmt,
404 (version&0xff000000)>>24,
405 (version&0x00ff0000)>>16,
406 version&0x0000ffff);
407 return str;
410 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
412 DWORD len = value ? (lstrlenW(value) + 1) * sizeof (WCHAR) : 0;
413 return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len );
416 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
418 LPCWSTR p = value;
419 while (*p) p += lstrlenW(p) + 1;
420 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
421 (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) );
424 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
426 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
429 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
431 HKEY hsubkey = 0;
432 LONG r;
434 r = RegCreateKeyW( hkey, path, &hsubkey );
435 if (r != ERROR_SUCCESS)
436 return r;
437 r = msi_reg_set_val_str( hsubkey, name, val );
438 RegCloseKey( hsubkey );
439 return r;
442 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
444 DWORD len = 0;
445 LPWSTR val;
446 LONG r;
448 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
449 if (r != ERROR_SUCCESS)
450 return NULL;
452 len += sizeof (WCHAR);
453 val = msi_alloc( len );
454 if (!val)
455 return NULL;
456 val[0] = 0;
457 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
458 return val;
461 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
463 DWORD type, len = sizeof (DWORD);
464 LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
465 return r == ERROR_SUCCESS && type == REG_DWORD;
468 static UINT get_user_sid(LPWSTR *usersid)
470 HANDLE token;
471 BYTE buf[1024];
472 DWORD size;
473 PTOKEN_USER user;
475 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
476 return ERROR_FUNCTION_FAILED;
478 size = sizeof(buf);
479 if (!GetTokenInformation(token, TokenUser, (void *)buf, size, &size)) {
480 CloseHandle(token);
481 return ERROR_FUNCTION_FAILED;
484 user = (PTOKEN_USER)buf;
485 if (!ConvertSidToStringSidW(user->User.Sid, usersid)) {
486 CloseHandle(token);
487 return ERROR_FUNCTION_FAILED;
489 CloseHandle(token);
490 return ERROR_SUCCESS;
493 UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create)
495 UINT rc;
496 WCHAR keypath[0x200];
497 TRACE("%s\n",debugstr_w(szProduct));
499 sprintfW(keypath,szUninstall_fmt,szProduct);
501 if (create)
502 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
503 else
504 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
506 return rc;
509 UINT MSIREG_DeleteUninstallKey(LPCWSTR szProduct)
511 WCHAR keypath[0x200];
512 TRACE("%s\n",debugstr_w(szProduct));
514 sprintfW(keypath,szUninstall_fmt,szProduct);
516 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
519 UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
521 UINT rc;
522 WCHAR squished_pc[GUID_SIZE];
523 WCHAR keypath[0x200];
525 TRACE("%s\n",debugstr_w(szProduct));
526 if (!squash_guid(szProduct,squished_pc))
527 return ERROR_FUNCTION_FAILED;
528 TRACE("squished (%s)\n", debugstr_w(squished_pc));
530 sprintfW(keypath,szUserProduct_fmt,squished_pc);
532 if (create)
533 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
534 else
535 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
537 return rc;
540 UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct)
542 WCHAR squished_pc[GUID_SIZE];
543 WCHAR keypath[0x200];
545 TRACE("%s\n",debugstr_w(szProduct));
546 if (!squash_guid(szProduct,squished_pc))
547 return ERROR_FUNCTION_FAILED;
548 TRACE("squished (%s)\n", debugstr_w(squished_pc));
550 sprintfW(keypath,szUserProduct_fmt,squished_pc);
552 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
555 UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
557 UINT rc;
558 WCHAR squished_pc[GUID_SIZE];
559 WCHAR keypath[0x200];
561 TRACE("%s\n",debugstr_w(szPatch));
562 if (!squash_guid(szPatch,squished_pc))
563 return ERROR_FUNCTION_FAILED;
564 TRACE("squished (%s)\n", debugstr_w(squished_pc));
566 sprintfW(keypath,szUserPatch_fmt,squished_pc);
568 if (create)
569 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
570 else
571 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
573 return rc;
576 UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
578 UINT rc;
579 WCHAR squished_pc[GUID_SIZE];
580 WCHAR keypath[0x200];
582 TRACE("%s\n",debugstr_w(szProduct));
583 if (!squash_guid(szProduct,squished_pc))
584 return ERROR_FUNCTION_FAILED;
585 TRACE("squished (%s)\n", debugstr_w(squished_pc));
587 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
589 if (create)
590 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
591 else
592 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
594 return rc;
597 UINT MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct)
599 WCHAR squished_pc[GUID_SIZE];
600 WCHAR keypath[0x200];
602 TRACE("%s\n",debugstr_w(szProduct));
603 if (!squash_guid(szProduct,squished_pc))
604 return ERROR_FUNCTION_FAILED;
605 TRACE("squished (%s)\n", debugstr_w(squished_pc));
607 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
608 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
611 UINT MSIREG_OpenFeatures(HKEY* key)
613 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Features,key);
616 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
618 UINT rc;
619 WCHAR squished_pc[GUID_SIZE];
620 WCHAR keypath[0x200];
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 sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
629 if (create)
630 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
631 else
632 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
634 return rc;
637 UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL create)
639 UINT rc;
640 WCHAR squished_pc[GUID_SIZE];
641 WCHAR keypath[0x200];
642 LPWSTR usersid;
644 TRACE("%s\n", debugstr_w(szProduct));
645 if (!squash_guid(szProduct, squished_pc))
646 return ERROR_FUNCTION_FAILED;
647 TRACE("squished (%s)\n", debugstr_w(squished_pc));
649 rc = get_user_sid(&usersid);
650 if (rc != ERROR_SUCCESS || !usersid)
652 ERR("Failed to retrieve user SID: %d\n", rc);
653 return rc;
656 sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc);
658 if (create)
659 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
660 else
661 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
663 LocalFree(usersid);
664 return rc;
667 UINT MSIREG_OpenComponents(HKEY* key)
669 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Components,key);
672 UINT MSIREG_OpenComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
674 UINT rc;
675 WCHAR squished_cc[GUID_SIZE];
676 WCHAR keypath[0x200];
678 TRACE("%s\n",debugstr_w(szComponent));
679 if (!squash_guid(szComponent,squished_cc))
680 return ERROR_FUNCTION_FAILED;
681 TRACE("squished (%s)\n", debugstr_w(squished_cc));
683 sprintfW(keypath,szInstaller_Components_fmt,squished_cc);
685 if (create)
686 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
687 else
688 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
690 return rc;
693 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
695 UINT rc;
696 WCHAR squished_cc[GUID_SIZE];
697 WCHAR keypath[0x200];
699 TRACE("%s\n",debugstr_w(szComponent));
700 if (!squash_guid(szComponent,squished_cc))
701 return ERROR_FUNCTION_FAILED;
702 TRACE("squished (%s)\n", debugstr_w(squished_cc));
704 sprintfW(keypath,szUser_Components_fmt,squished_cc);
706 if (create)
707 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
708 else
709 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
711 return rc;
714 UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create)
716 UINT rc;
717 WCHAR comp[GUID_SIZE];
718 WCHAR keypath[0x200];
719 LPWSTR usersid;
721 TRACE("%s\n", debugstr_w(szComponent));
722 if (!squash_guid(szComponent, comp))
723 return ERROR_FUNCTION_FAILED;
724 TRACE("squished (%s)\n", debugstr_w(comp));
726 rc = get_user_sid(&usersid);
727 if (rc != ERROR_SUCCESS || !usersid)
729 ERR("Failed to retrieve user SID: %d\n", rc);
730 return rc;
733 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
735 if (create)
736 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
737 else
738 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
740 LocalFree(usersid);
741 return rc;
744 UINT MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent)
746 UINT rc;
747 WCHAR comp[GUID_SIZE];
748 WCHAR keypath[0x200];
749 LPWSTR usersid;
751 TRACE("%s\n", debugstr_w(szComponent));
752 if (!squash_guid(szComponent, comp))
753 return ERROR_FUNCTION_FAILED;
754 TRACE("squished (%s)\n", debugstr_w(comp));
756 rc = get_user_sid(&usersid);
757 if (rc != ERROR_SUCCESS || !usersid)
759 ERR("Failed to retrieve user SID: %d\n", rc);
760 return rc;
763 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
765 LocalFree(usersid);
766 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
769 UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, HKEY *key, BOOL create)
771 UINT rc;
772 WCHAR squished_pc[GUID_SIZE];
773 WCHAR keypath[0x200];
774 LPWSTR usersid;
776 TRACE("%s\n", debugstr_w(szProduct));
777 if (!squash_guid(szProduct, squished_pc))
778 return ERROR_FUNCTION_FAILED;
779 TRACE("squished (%s)\n", debugstr_w(squished_pc));
781 rc = get_user_sid(&usersid);
782 if (rc != ERROR_SUCCESS || !usersid)
784 ERR("Failed to retrieve user SID: %d\n", rc);
785 return rc;
788 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
790 if (create)
791 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
792 else
793 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
795 LocalFree(usersid);
796 return rc;
799 UINT MSIREG_OpenInstallPropertiesKey(LPCWSTR szProduct, HKEY *key, BOOL create)
801 UINT rc;
802 WCHAR squished_pc[GUID_SIZE];
803 WCHAR keypath[0x200];
804 LPWSTR usersid;
806 TRACE("%s\n", debugstr_w(szProduct));
807 if (!squash_guid(szProduct, squished_pc))
808 return ERROR_FUNCTION_FAILED;
809 TRACE("squished (%s)\n", debugstr_w(squished_pc));
811 rc = get_user_sid(&usersid);
812 if (rc != ERROR_SUCCESS || !usersid)
814 ERR("Failed to retrieve user SID: %d\n", rc);
815 return rc;
818 sprintfW(keypath, szInstallProperties_fmt, usersid, squished_pc);
820 if (create)
821 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
822 else
823 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
825 LocalFree(usersid);
826 return rc;
829 UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)
831 UINT rc;
832 WCHAR squished_pc[GUID_SIZE];
833 WCHAR keypath[0x200];
834 LPWSTR usersid;
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 rc = get_user_sid(&usersid);
842 if (rc != ERROR_SUCCESS || !usersid)
844 ERR("Failed to retrieve user SID: %d\n", rc);
845 return rc;
848 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
850 LocalFree(usersid);
851 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
854 UINT MSIREG_OpenProducts(HKEY* key)
856 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Products,key);
859 UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
861 UINT rc;
862 WCHAR squished_pc[GUID_SIZE];
863 WCHAR keypath[0x200];
865 TRACE("%s\n",debugstr_w(szProduct));
866 if (!squash_guid(szProduct,squished_pc))
867 return ERROR_FUNCTION_FAILED;
868 TRACE("squished (%s)\n", debugstr_w(squished_pc));
870 sprintfW(keypath,szInstaller_Products_fmt,squished_pc);
872 if (create)
873 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
874 else
875 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
877 return rc;
880 UINT MSIREG_DeleteProductKey(LPCWSTR szProduct)
882 WCHAR squished_pc[GUID_SIZE];
883 WCHAR keypath[0x200];
885 TRACE("%s\n", debugstr_w(szProduct));
886 if (!squash_guid(szProduct, squished_pc))
887 return ERROR_FUNCTION_FAILED;
888 TRACE("squished (%s)\n", debugstr_w(squished_pc));
890 sprintfW(keypath, szInstaller_Products_fmt, squished_pc);
892 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
895 UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
897 UINT rc;
898 WCHAR squished_pc[GUID_SIZE];
899 WCHAR keypath[0x200];
901 TRACE("%s\n",debugstr_w(szPatch));
902 if (!squash_guid(szPatch,squished_pc))
903 return ERROR_FUNCTION_FAILED;
904 TRACE("squished (%s)\n", debugstr_w(squished_pc));
906 sprintfW(keypath,szInstaller_Patches_fmt,squished_pc);
908 if (create)
909 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
910 else
911 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
913 return rc;
916 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
918 UINT rc;
919 WCHAR squished_pc[GUID_SIZE];
920 WCHAR keypath[0x200];
922 TRACE("%s\n",debugstr_w(szUpgradeCode));
923 if (!squash_guid(szUpgradeCode,squished_pc))
924 return ERROR_FUNCTION_FAILED;
925 TRACE("squished (%s)\n", debugstr_w(squished_pc));
927 sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
929 if (create)
930 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
931 else
932 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
934 return rc;
937 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
939 UINT rc;
940 WCHAR squished_pc[GUID_SIZE];
941 WCHAR keypath[0x200];
943 TRACE("%s\n",debugstr_w(szUpgradeCode));
944 if (!squash_guid(szUpgradeCode,squished_pc))
945 return ERROR_FUNCTION_FAILED;
946 TRACE("squished (%s)\n", debugstr_w(squished_pc));
948 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
950 if (create)
951 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
952 else
953 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
955 return rc;
958 UINT MSIREG_OpenLocalSystemProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create)
960 WCHAR squished_pc[GUID_SIZE];
961 WCHAR keypath[0x200];
963 TRACE("%s\n", debugstr_w(szProductCode));
965 if (!squash_guid(szProductCode, squished_pc))
966 return ERROR_FUNCTION_FAILED;
968 TRACE("squished (%s)\n", debugstr_w(squished_pc));
970 sprintfW(keypath, szInstaller_LocalSystemProductCodes_fmt, squished_pc);
972 if (create)
973 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
975 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
978 UINT MSIREG_OpenLocalSystemComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create)
980 WCHAR squished_pc[GUID_SIZE];
981 WCHAR keypath[0x200];
983 TRACE("%s\n", debugstr_w(szComponent));
985 if (!squash_guid(szComponent, squished_pc))
986 return ERROR_FUNCTION_FAILED;
988 TRACE("squished (%s)\n", debugstr_w(squished_pc));
990 sprintfW(keypath, szInstaller_LocalSystemComponent_fmt, squished_pc);
992 if (create)
993 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
995 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
998 UINT MSIREG_OpenLocalClassesProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create)
1000 WCHAR squished_pc[GUID_SIZE];
1001 WCHAR keypath[0x200];
1003 TRACE("%s\n", debugstr_w(szProductCode));
1005 if (!squash_guid(szProductCode, squished_pc))
1006 return ERROR_FUNCTION_FAILED;
1008 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1010 sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc);
1012 if (create)
1013 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1015 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1018 UINT MSIREG_OpenLocalManagedProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create)
1020 WCHAR squished_pc[GUID_SIZE];
1021 WCHAR keypath[0x200];
1022 LPWSTR usersid;
1023 UINT r;
1025 TRACE("%s\n", debugstr_w(szProductCode));
1027 if (!squash_guid(szProductCode, squished_pc))
1028 return ERROR_FUNCTION_FAILED;
1030 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1032 r = get_user_sid(&usersid);
1033 if (r != ERROR_SUCCESS || !usersid)
1035 ERR("Failed to retrieve user SID: %d\n", r);
1036 return r;
1039 sprintfW(keypath, szInstaller_LocalManagedProd_fmt, usersid, squished_pc);
1040 LocalFree(usersid);
1042 if (create)
1043 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1045 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1048 /*************************************************************************
1049 * MsiDecomposeDescriptorW [MSI.@]
1051 * Decomposes an MSI descriptor into product, feature and component parts.
1052 * An MSI descriptor is a string of the form:
1053 * [base 85 guid] [feature code] '>' [base 85 guid]
1055 * PARAMS
1056 * szDescriptor [I] the descriptor to decompose
1057 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
1058 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
1059 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
1060 * pUsed [O] the length of the descriptor
1062 * RETURNS
1063 * ERROR_SUCCESS if everything worked correctly
1064 * ERROR_INVALID_PARAMETER if the descriptor was invalid
1067 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
1068 LPWSTR szFeature, LPWSTR szComponent, LPDWORD pUsed )
1070 UINT r, len;
1071 LPWSTR p;
1072 GUID product, component;
1074 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
1075 szFeature, szComponent, pUsed);
1077 r = decode_base85_guid( szDescriptor, &product );
1078 if( !r )
1079 return ERROR_INVALID_PARAMETER;
1081 TRACE("product %s\n", debugstr_guid( &product ));
1083 p = strchrW(&szDescriptor[20],'>');
1084 if( !p )
1085 return ERROR_INVALID_PARAMETER;
1087 len = (p - &szDescriptor[20]);
1088 if( len > MAX_FEATURE_CHARS )
1089 return ERROR_INVALID_PARAMETER;
1091 TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len ));
1093 r = decode_base85_guid( p+1, &component );
1094 if( !r )
1095 return ERROR_INVALID_PARAMETER;
1097 TRACE("component %s\n", debugstr_guid( &component ));
1099 if (szProduct)
1100 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
1101 if (szComponent)
1102 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
1103 if (szFeature)
1105 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
1106 szFeature[len] = 0;
1108 len = ( &p[21] - szDescriptor );
1110 TRACE("length = %d\n", len);
1111 *pUsed = len;
1113 return ERROR_SUCCESS;
1116 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
1117 LPSTR szFeature, LPSTR szComponent, LPDWORD pUsed )
1119 WCHAR product[MAX_FEATURE_CHARS+1];
1120 WCHAR feature[MAX_FEATURE_CHARS+1];
1121 WCHAR component[MAX_FEATURE_CHARS+1];
1122 LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
1123 UINT r;
1125 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
1126 szFeature, szComponent, pUsed);
1128 str = strdupAtoW( szDescriptor );
1129 if( szDescriptor && !str )
1130 return ERROR_OUTOFMEMORY;
1132 if (szProduct)
1133 p = product;
1134 if (szFeature)
1135 f = feature;
1136 if (szComponent)
1137 c = component;
1139 r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
1141 if (r == ERROR_SUCCESS)
1143 WideCharToMultiByte( CP_ACP, 0, p, -1,
1144 szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
1145 WideCharToMultiByte( CP_ACP, 0, f, -1,
1146 szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
1147 WideCharToMultiByte( CP_ACP, 0, c, -1,
1148 szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
1151 msi_free( str );
1153 return r;
1156 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
1158 DWORD r;
1159 WCHAR szwGuid[GUID_SIZE];
1161 TRACE("%d %p\n", index, lpguid);
1163 if (NULL == lpguid)
1164 return ERROR_INVALID_PARAMETER;
1165 r = MsiEnumProductsW(index, szwGuid);
1166 if( r == ERROR_SUCCESS )
1167 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1169 return r;
1172 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
1174 HKEY hkeyProducts = 0;
1175 DWORD r;
1176 WCHAR szKeyName[SQUISH_GUID_SIZE];
1178 TRACE("%d %p\n", index, lpguid);
1180 if (NULL == lpguid)
1181 return ERROR_INVALID_PARAMETER;
1183 r = MSIREG_OpenProducts(&hkeyProducts);
1184 if( r != ERROR_SUCCESS )
1185 return ERROR_NO_MORE_ITEMS;
1187 r = RegEnumKeyW(hkeyProducts, index, szKeyName, SQUISH_GUID_SIZE);
1188 if( r == ERROR_SUCCESS )
1189 unsquash_guid(szKeyName, lpguid);
1190 RegCloseKey(hkeyProducts);
1192 return r;
1195 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
1196 LPSTR szFeature, LPSTR szParent)
1198 DWORD r;
1199 WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
1200 LPWSTR szwProduct = NULL;
1202 TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent);
1204 if( szProduct )
1206 szwProduct = strdupAtoW( szProduct );
1207 if( !szwProduct )
1208 return ERROR_OUTOFMEMORY;
1211 r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
1212 if( r == ERROR_SUCCESS )
1214 WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
1215 szFeature, GUID_SIZE, NULL, NULL);
1216 WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
1217 szParent, GUID_SIZE, NULL, NULL);
1220 msi_free( szwProduct);
1222 return r;
1225 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
1226 LPWSTR szFeature, LPWSTR szParent)
1228 HKEY hkeyProduct = 0;
1229 DWORD r, sz;
1231 TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
1233 if( !szProduct )
1234 return ERROR_INVALID_PARAMETER;
1236 r = MSIREG_OpenFeaturesKey(szProduct,&hkeyProduct,FALSE);
1237 if( r != ERROR_SUCCESS )
1238 return ERROR_NO_MORE_ITEMS;
1240 sz = GUID_SIZE;
1241 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
1242 RegCloseKey(hkeyProduct);
1244 return r;
1247 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
1249 DWORD r;
1250 WCHAR szwGuid[GUID_SIZE];
1252 TRACE("%d %p\n", index, lpguid);
1254 r = MsiEnumComponentsW(index, szwGuid);
1255 if( r == ERROR_SUCCESS )
1256 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1258 return r;
1261 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
1263 HKEY hkeyComponents = 0;
1264 DWORD r;
1265 WCHAR szKeyName[SQUISH_GUID_SIZE];
1267 TRACE("%d %p\n", index, lpguid);
1269 r = MSIREG_OpenComponents(&hkeyComponents);
1270 if( r != ERROR_SUCCESS )
1271 return ERROR_NO_MORE_ITEMS;
1273 r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
1274 if( r == ERROR_SUCCESS )
1275 unsquash_guid(szKeyName, lpguid);
1276 RegCloseKey(hkeyComponents);
1278 return r;
1281 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
1283 DWORD r;
1284 WCHAR szwProduct[GUID_SIZE];
1285 LPWSTR szwComponent = NULL;
1287 TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
1289 if ( !szProduct )
1290 return ERROR_INVALID_PARAMETER;
1292 if( szComponent )
1294 szwComponent = strdupAtoW( szComponent );
1295 if( !szwComponent )
1296 return ERROR_OUTOFMEMORY;
1299 r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
1300 if( r == ERROR_SUCCESS )
1302 WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
1303 szProduct, GUID_SIZE, NULL, NULL);
1306 msi_free( szwComponent);
1308 return r;
1311 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
1313 HKEY hkeyComp = 0;
1314 DWORD r, sz;
1315 WCHAR szValName[SQUISH_GUID_SIZE];
1317 TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct);
1319 if (!szComponent || !*szComponent || !szProduct)
1320 return ERROR_INVALID_PARAMETER;
1322 if (MSIREG_OpenUserDataComponentKey(szComponent, &hkeyComp, FALSE) != ERROR_SUCCESS &&
1323 MSIREG_OpenLocalSystemComponentKey(szComponent, &hkeyComp, FALSE) != ERROR_SUCCESS)
1324 return ERROR_UNKNOWN_COMPONENT;
1326 /* see if there are any products at all */
1327 sz = SQUISH_GUID_SIZE;
1328 r = RegEnumValueW(hkeyComp, 0, szValName, &sz, NULL, NULL, NULL, NULL);
1329 if (r != ERROR_SUCCESS)
1331 RegCloseKey(hkeyComp);
1333 if (index != 0)
1334 return ERROR_INVALID_PARAMETER;
1336 return ERROR_UNKNOWN_COMPONENT;
1339 sz = SQUISH_GUID_SIZE;
1340 r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
1341 if( r == ERROR_SUCCESS )
1342 unsquash_guid(szValName, szProduct);
1344 RegCloseKey(hkeyComp);
1346 return r;
1349 static UINT WINAPI MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
1350 awstring *lpQualBuf, LPDWORD pcchQual,
1351 awstring *lpAppBuf, LPDWORD pcchAppBuf )
1353 DWORD name_sz, val_sz, name_max, val_max, type, ofs;
1354 LPWSTR name = NULL, val = NULL;
1355 UINT r, r2;
1356 HKEY key;
1358 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1359 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
1361 if (!szComponent)
1362 return ERROR_INVALID_PARAMETER;
1364 r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
1365 if (r != ERROR_SUCCESS)
1366 return ERROR_UNKNOWN_COMPONENT;
1368 /* figure out how big the name is we want to return */
1369 name_max = 0x10;
1370 r = ERROR_OUTOFMEMORY;
1371 name = msi_alloc( name_max * sizeof(WCHAR) );
1372 if (!name)
1373 goto end;
1375 val_max = 0x10;
1376 r = ERROR_OUTOFMEMORY;
1377 val = msi_alloc( val_max );
1378 if (!val)
1379 goto end;
1381 /* loop until we allocate enough memory */
1382 while (1)
1384 name_sz = name_max;
1385 val_sz = val_max;
1386 r = RegEnumValueW( key, iIndex, name, &name_sz,
1387 NULL, &type, (LPBYTE)val, &val_sz );
1388 if (r == ERROR_SUCCESS)
1389 break;
1390 if (r != ERROR_MORE_DATA)
1391 goto end;
1393 if (type != REG_MULTI_SZ)
1395 ERR("component data has wrong type (%d)\n", type);
1396 goto end;
1399 r = ERROR_OUTOFMEMORY;
1400 if ((name_sz+1) >= name_max)
1402 name_max *= 2;
1403 msi_free( name );
1404 name = msi_alloc( name_max * sizeof (WCHAR) );
1405 if (!name)
1406 goto end;
1407 continue;
1409 if (val_sz > val_max)
1411 val_max = val_sz + sizeof (WCHAR);
1412 msi_free( val );
1413 val = msi_alloc( val_max * sizeof (WCHAR) );
1414 if (!val)
1415 goto end;
1416 continue;
1418 ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
1419 goto end;
1422 ofs = 0;
1423 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
1424 if (r != ERROR_SUCCESS)
1425 goto end;
1427 TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
1429 r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
1430 r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
1432 if (r2 != ERROR_SUCCESS)
1433 r = r2;
1435 end:
1436 msi_free(val);
1437 msi_free(name);
1438 RegCloseKey(key);
1440 return r;
1443 /*************************************************************************
1444 * MsiEnumComponentQualifiersA [MSI.@]
1446 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
1447 LPSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1448 LPSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1450 awstring qual, appdata;
1451 LPWSTR comp;
1452 UINT r;
1454 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex,
1455 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1456 pcchApplicationDataBuf);
1458 comp = strdupAtoW( szComponent );
1459 if (szComponent && !comp)
1460 return ERROR_OUTOFMEMORY;
1462 qual.unicode = FALSE;
1463 qual.str.a = lpQualifierBuf;
1465 appdata.unicode = FALSE;
1466 appdata.str.a = lpApplicationDataBuf;
1468 r = MSI_EnumComponentQualifiers( comp, iIndex,
1469 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1470 msi_free( comp );
1471 return r;
1474 /*************************************************************************
1475 * MsiEnumComponentQualifiersW [MSI.@]
1477 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
1478 LPWSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1479 LPWSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1481 awstring qual, appdata;
1483 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1484 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1485 pcchApplicationDataBuf);
1487 qual.unicode = TRUE;
1488 qual.str.w = lpQualifierBuf;
1490 appdata.unicode = TRUE;
1491 appdata.str.w = lpApplicationDataBuf;
1493 return MSI_EnumComponentQualifiers( szComponent, iIndex,
1494 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1497 /*************************************************************************
1498 * MsiEnumRelatedProductsW [MSI.@]
1501 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
1502 DWORD iProductIndex, LPWSTR lpProductBuf)
1504 UINT r;
1505 HKEY hkey;
1506 DWORD dwSize = SQUISH_GUID_SIZE;
1507 WCHAR szKeyName[SQUISH_GUID_SIZE];
1509 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved,
1510 iProductIndex, lpProductBuf);
1512 if (NULL == szUpgradeCode)
1513 return ERROR_INVALID_PARAMETER;
1514 if (NULL == lpProductBuf)
1515 return ERROR_INVALID_PARAMETER;
1517 r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1518 if (r != ERROR_SUCCESS)
1519 return ERROR_NO_MORE_ITEMS;
1521 r = RegEnumValueW(hkey, iProductIndex, szKeyName, &dwSize, NULL, NULL, NULL, NULL);
1522 if( r == ERROR_SUCCESS )
1523 unsquash_guid(szKeyName, lpProductBuf);
1524 RegCloseKey(hkey);
1526 return r;
1529 /*************************************************************************
1530 * MsiEnumRelatedProductsA [MSI.@]
1533 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1534 DWORD iProductIndex, LPSTR lpProductBuf)
1536 LPWSTR szwUpgradeCode = NULL;
1537 WCHAR productW[GUID_SIZE];
1538 UINT r;
1540 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1541 iProductIndex, lpProductBuf);
1543 if (szUpgradeCode)
1545 szwUpgradeCode = strdupAtoW( szUpgradeCode );
1546 if( !szwUpgradeCode )
1547 return ERROR_OUTOFMEMORY;
1550 r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1551 iProductIndex, productW );
1552 if (r == ERROR_SUCCESS)
1554 WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1555 lpProductBuf, GUID_SIZE, NULL, NULL );
1557 msi_free( szwUpgradeCode);
1558 return r;
1561 /***********************************************************************
1562 * MsiEnumPatchesA [MSI.@]
1564 UINT WINAPI MsiEnumPatchesA( LPCSTR szProduct, DWORD iPatchIndex,
1565 LPSTR lpPatchBuf, LPSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
1567 FIXME("%s %d %p %p %p\n", debugstr_a(szProduct),
1568 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1569 return ERROR_NO_MORE_ITEMS;
1572 /***********************************************************************
1573 * MsiEnumPatchesW [MSI.@]
1575 UINT WINAPI MsiEnumPatchesW( LPCWSTR szProduct, DWORD iPatchIndex,
1576 LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
1578 FIXME("%s %d %p %p %p\n", debugstr_w(szProduct),
1579 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1580 return ERROR_NO_MORE_ITEMS;
1583 UINT WINAPI MsiEnumProductsExA( LPCSTR szProductCode, LPCSTR szUserSid,
1584 DWORD dwContext, DWORD dwIndex, CHAR szInstalledProductCode[39],
1585 MSIINSTALLCONTEXT* pdwInstalledContext, LPSTR szSid, LPDWORD pcchSid)
1587 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_a(szProductCode), debugstr_a(szUserSid),
1588 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1589 szSid, pcchSid);
1590 return ERROR_NO_MORE_ITEMS;
1593 UINT WINAPI MsiEnumProductsExW( LPCWSTR szProductCode, LPCWSTR szUserSid,
1594 DWORD dwContext, DWORD dwIndex, WCHAR szInstalledProductCode[39],
1595 MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, LPDWORD pcchSid)
1597 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_w(szProductCode), debugstr_w(szUserSid),
1598 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1599 szSid, pcchSid);
1600 return ERROR_NO_MORE_ITEMS;