push b59ba84f7e04af9ef068bd4c6e96701941f0256e
[wine/hacks.git] / dlls / msi / registry.c
blobac89186eb3bdd3324e1593282ca0786db0060a25
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 #define SQUISH_GUID_SIZE 33
236 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
238 DWORD i,n=0;
240 out[n++]='{';
241 for(i=0; i<8; i++)
242 out[n++] = in[7-i];
243 out[n++]='-';
244 for(i=0; i<4; i++)
245 out[n++] = in[11-i];
246 out[n++]='-';
247 for(i=0; i<4; i++)
248 out[n++] = in[15-i];
249 out[n++]='-';
250 for(i=0; i<2; i++)
252 out[n++] = in[17+i*2];
253 out[n++] = in[16+i*2];
255 out[n++]='-';
256 for( ; i<8; i++)
258 out[n++] = in[17+i*2];
259 out[n++] = in[16+i*2];
261 out[n++]='}';
262 out[n]=0;
263 return TRUE;
266 BOOL squash_guid(LPCWSTR in, LPWSTR out)
268 DWORD i,n=1;
269 GUID guid;
271 out[0] = 0;
273 if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
274 return FALSE;
276 for(i=0; i<8; i++)
277 out[7-i] = in[n++];
278 n++;
279 for(i=0; i<4; i++)
280 out[11-i] = in[n++];
281 n++;
282 for(i=0; i<4; i++)
283 out[15-i] = in[n++];
284 n++;
285 for(i=0; i<2; i++)
287 out[17+i*2] = in[n++];
288 out[16+i*2] = in[n++];
290 n++;
291 for( ; i<8; i++)
293 out[17+i*2] = in[n++];
294 out[16+i*2] = in[n++];
296 out[32]=0;
297 return TRUE;
301 /* tables for encoding and decoding base85 */
302 static const unsigned char table_dec85[0x80] = {
303 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
304 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
305 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
306 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
307 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
308 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
309 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
310 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
313 static const char table_enc85[] =
314 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
315 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
316 "yz{}~";
319 * Converts a base85 encoded guid into a GUID pointer
320 * Base85 encoded GUIDs should be 20 characters long.
322 * returns TRUE if successful, FALSE if not
324 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
326 DWORD i, val = 0, base = 1, *p;
328 if (!str)
329 return FALSE;
331 p = (DWORD*) guid;
332 for( i=0; i<20; i++ )
334 if( (i%5) == 0 )
336 val = 0;
337 base = 1;
339 val += table_dec85[str[i]] * base;
340 if( str[i] >= 0x80 )
341 return FALSE;
342 if( table_dec85[str[i]] == 0xff )
343 return FALSE;
344 if( (i%5) == 4 )
345 p[i/5] = val;
346 base *= 85;
348 return TRUE;
352 * Encodes a base85 guid given a GUID pointer
353 * Caller should provide a 21 character buffer for the encoded string.
355 * returns TRUE if successful, FALSE if not
357 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
359 unsigned int x, *p, i;
361 p = (unsigned int*) guid;
362 for( i=0; i<4; i++ )
364 x = p[i];
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];
372 x = x/85;
373 *str++ = table_enc85[x%85];
375 *str = 0;
377 return TRUE;
380 DWORD msi_version_str_to_dword(LPCWSTR p)
382 DWORD major, minor = 0, build = 0, version = 0;
384 if (!p)
385 return version;
387 major = atoiW(p);
389 p = strchrW(p, '.');
390 if (p)
392 minor = atoiW(p+1);
393 p = strchrW(p+1, '.');
394 if (p)
395 build = atoiW(p+1);
398 return MAKELONG(build, MAKEWORD(minor, major));
401 LPWSTR msi_version_dword_to_str(DWORD version)
403 const WCHAR fmt[] = { '%','u','.','%','u','.','%','u',0 };
404 LPWSTR str = msi_alloc(20);
405 sprintfW(str, fmt,
406 (version&0xff000000)>>24,
407 (version&0x00ff0000)>>16,
408 version&0x0000ffff);
409 return str;
412 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
414 DWORD len = value ? (lstrlenW(value) + 1) * sizeof (WCHAR) : 0;
415 return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len );
418 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
420 LPCWSTR p = value;
421 while (*p) p += lstrlenW(p) + 1;
422 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
423 (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) );
426 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
428 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
431 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
433 HKEY hsubkey = 0;
434 LONG r;
436 r = RegCreateKeyW( hkey, path, &hsubkey );
437 if (r != ERROR_SUCCESS)
438 return r;
439 r = msi_reg_set_val_str( hsubkey, name, val );
440 RegCloseKey( hsubkey );
441 return r;
444 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
446 DWORD len = 0;
447 LPWSTR val;
448 LONG r;
450 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
451 if (r != ERROR_SUCCESS)
452 return NULL;
454 len += sizeof (WCHAR);
455 val = msi_alloc( len );
456 if (!val)
457 return NULL;
458 val[0] = 0;
459 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
460 return val;
463 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
465 DWORD type, len = sizeof (DWORD);
466 LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
467 return r == ERROR_SUCCESS && type == REG_DWORD;
470 static UINT get_user_sid(LPWSTR *usersid)
472 HANDLE token;
473 BYTE buf[1024];
474 DWORD size;
475 PTOKEN_USER user;
477 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
478 return ERROR_FUNCTION_FAILED;
480 size = sizeof(buf);
481 if (!GetTokenInformation(token, TokenUser, (void *)buf, size, &size)) {
482 CloseHandle(token);
483 return ERROR_FUNCTION_FAILED;
486 user = (PTOKEN_USER)buf;
487 if (!ConvertSidToStringSidW(user->User.Sid, usersid)) {
488 CloseHandle(token);
489 return ERROR_FUNCTION_FAILED;
491 CloseHandle(token);
492 return ERROR_SUCCESS;
495 UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create)
497 UINT rc;
498 WCHAR keypath[0x200];
499 TRACE("%s\n",debugstr_w(szProduct));
501 sprintfW(keypath,szUninstall_fmt,szProduct);
503 if (create)
504 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
505 else
506 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
508 return rc;
511 UINT MSIREG_DeleteUninstallKey(LPCWSTR szProduct)
513 WCHAR keypath[0x200];
514 TRACE("%s\n",debugstr_w(szProduct));
516 sprintfW(keypath,szUninstall_fmt,szProduct);
518 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
521 UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
523 UINT rc;
524 WCHAR squished_pc[GUID_SIZE];
525 WCHAR keypath[0x200];
527 TRACE("%s\n",debugstr_w(szProduct));
528 if (!squash_guid(szProduct,squished_pc))
529 return ERROR_FUNCTION_FAILED;
530 TRACE("squished (%s)\n", debugstr_w(squished_pc));
532 sprintfW(keypath,szUserProduct_fmt,squished_pc);
534 if (create)
535 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
536 else
537 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
539 return rc;
542 UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct)
544 WCHAR squished_pc[GUID_SIZE];
545 WCHAR keypath[0x200];
547 TRACE("%s\n",debugstr_w(szProduct));
548 if (!squash_guid(szProduct,squished_pc))
549 return ERROR_FUNCTION_FAILED;
550 TRACE("squished (%s)\n", debugstr_w(squished_pc));
552 sprintfW(keypath,szUserProduct_fmt,squished_pc);
554 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
557 UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
559 UINT rc;
560 WCHAR squished_pc[GUID_SIZE];
561 WCHAR keypath[0x200];
563 TRACE("%s\n",debugstr_w(szPatch));
564 if (!squash_guid(szPatch,squished_pc))
565 return ERROR_FUNCTION_FAILED;
566 TRACE("squished (%s)\n", debugstr_w(squished_pc));
568 sprintfW(keypath,szUserPatch_fmt,squished_pc);
570 if (create)
571 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
572 else
573 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
575 return rc;
578 UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
580 UINT rc;
581 WCHAR squished_pc[GUID_SIZE];
582 WCHAR keypath[0x200];
584 TRACE("%s\n",debugstr_w(szProduct));
585 if (!squash_guid(szProduct,squished_pc))
586 return ERROR_FUNCTION_FAILED;
587 TRACE("squished (%s)\n", debugstr_w(squished_pc));
589 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
591 if (create)
592 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
593 else
594 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
596 return rc;
599 UINT MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct)
601 WCHAR squished_pc[GUID_SIZE];
602 WCHAR keypath[0x200];
604 TRACE("%s\n",debugstr_w(szProduct));
605 if (!squash_guid(szProduct,squished_pc))
606 return ERROR_FUNCTION_FAILED;
607 TRACE("squished (%s)\n", debugstr_w(squished_pc));
609 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
610 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
613 UINT MSIREG_OpenFeatures(HKEY* key)
615 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Features,key);
618 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
620 UINT rc;
621 WCHAR squished_pc[GUID_SIZE];
622 WCHAR keypath[0x200];
624 TRACE("%s\n",debugstr_w(szProduct));
625 if (!squash_guid(szProduct,squished_pc))
626 return ERROR_FUNCTION_FAILED;
627 TRACE("squished (%s)\n", debugstr_w(squished_pc));
629 sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
631 if (create)
632 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
633 else
634 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
636 return rc;
639 UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL create)
641 UINT rc;
642 WCHAR squished_pc[GUID_SIZE];
643 WCHAR keypath[0x200];
644 LPWSTR usersid;
646 TRACE("%s\n", debugstr_w(szProduct));
647 if (!squash_guid(szProduct, squished_pc))
648 return ERROR_FUNCTION_FAILED;
649 TRACE("squished (%s)\n", debugstr_w(squished_pc));
651 rc = get_user_sid(&usersid);
652 if (rc != ERROR_SUCCESS || !usersid)
654 ERR("Failed to retrieve user SID: %d\n", rc);
655 return rc;
658 sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc);
660 if (create)
661 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
662 else
663 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
665 LocalFree(usersid);
666 return rc;
669 UINT MSIREG_OpenComponents(HKEY* key)
671 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Components,key);
674 UINT MSIREG_OpenComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
676 UINT rc;
677 WCHAR squished_cc[GUID_SIZE];
678 WCHAR keypath[0x200];
680 TRACE("%s\n",debugstr_w(szComponent));
681 if (!squash_guid(szComponent,squished_cc))
682 return ERROR_FUNCTION_FAILED;
683 TRACE("squished (%s)\n", debugstr_w(squished_cc));
685 sprintfW(keypath,szInstaller_Components_fmt,squished_cc);
687 if (create)
688 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
689 else
690 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
692 return rc;
695 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
697 UINT rc;
698 WCHAR squished_cc[GUID_SIZE];
699 WCHAR keypath[0x200];
701 TRACE("%s\n",debugstr_w(szComponent));
702 if (!squash_guid(szComponent,squished_cc))
703 return ERROR_FUNCTION_FAILED;
704 TRACE("squished (%s)\n", debugstr_w(squished_cc));
706 sprintfW(keypath,szUser_Components_fmt,squished_cc);
708 if (create)
709 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
710 else
711 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
713 return rc;
716 UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create)
718 UINT rc;
719 WCHAR comp[GUID_SIZE];
720 WCHAR keypath[0x200];
721 LPWSTR usersid;
723 TRACE("%s\n", debugstr_w(szComponent));
724 if (!squash_guid(szComponent, comp))
725 return ERROR_FUNCTION_FAILED;
726 TRACE("squished (%s)\n", debugstr_w(comp));
728 rc = get_user_sid(&usersid);
729 if (rc != ERROR_SUCCESS || !usersid)
731 ERR("Failed to retrieve user SID: %d\n", rc);
732 return rc;
735 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
737 if (create)
738 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
739 else
740 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
742 LocalFree(usersid);
743 return rc;
746 UINT MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent)
748 UINT rc;
749 WCHAR comp[GUID_SIZE];
750 WCHAR keypath[0x200];
751 LPWSTR usersid;
753 TRACE("%s\n", debugstr_w(szComponent));
754 if (!squash_guid(szComponent, comp))
755 return ERROR_FUNCTION_FAILED;
756 TRACE("squished (%s)\n", debugstr_w(comp));
758 rc = get_user_sid(&usersid);
759 if (rc != ERROR_SUCCESS || !usersid)
761 ERR("Failed to retrieve user SID: %d\n", rc);
762 return rc;
765 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
767 LocalFree(usersid);
768 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
771 UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, HKEY *key, BOOL create)
773 UINT rc;
774 WCHAR squished_pc[GUID_SIZE];
775 WCHAR keypath[0x200];
776 LPWSTR usersid;
778 TRACE("%s\n", debugstr_w(szProduct));
779 if (!squash_guid(szProduct, squished_pc))
780 return ERROR_FUNCTION_FAILED;
781 TRACE("squished (%s)\n", debugstr_w(squished_pc));
783 rc = get_user_sid(&usersid);
784 if (rc != ERROR_SUCCESS || !usersid)
786 ERR("Failed to retrieve user SID: %d\n", rc);
787 return rc;
790 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
792 if (create)
793 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
794 else
795 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
797 LocalFree(usersid);
798 return rc;
801 UINT MSIREG_OpenInstallPropertiesKey(LPCWSTR szProduct, HKEY *key, BOOL create)
803 UINT rc;
804 WCHAR squished_pc[GUID_SIZE];
805 WCHAR keypath[0x200];
806 LPWSTR usersid;
808 TRACE("%s\n", debugstr_w(szProduct));
809 if (!squash_guid(szProduct, squished_pc))
810 return ERROR_FUNCTION_FAILED;
811 TRACE("squished (%s)\n", debugstr_w(squished_pc));
813 rc = get_user_sid(&usersid);
814 if (rc != ERROR_SUCCESS || !usersid)
816 ERR("Failed to retrieve user SID: %d\n", rc);
817 return rc;
820 sprintfW(keypath, szInstallProperties_fmt, usersid, squished_pc);
822 if (create)
823 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
824 else
825 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
827 LocalFree(usersid);
828 return rc;
831 UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)
833 UINT rc;
834 WCHAR squished_pc[GUID_SIZE];
835 WCHAR keypath[0x200];
836 LPWSTR usersid;
838 TRACE("%s\n", debugstr_w(szProduct));
839 if (!squash_guid(szProduct, squished_pc))
840 return ERROR_FUNCTION_FAILED;
841 TRACE("squished (%s)\n", debugstr_w(squished_pc));
843 rc = get_user_sid(&usersid);
844 if (rc != ERROR_SUCCESS || !usersid)
846 ERR("Failed to retrieve user SID: %d\n", rc);
847 return rc;
850 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
852 LocalFree(usersid);
853 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
856 UINT MSIREG_OpenProducts(HKEY* key)
858 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Products,key);
861 UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
863 UINT rc;
864 WCHAR squished_pc[GUID_SIZE];
865 WCHAR keypath[0x200];
867 TRACE("%s\n",debugstr_w(szProduct));
868 if (!squash_guid(szProduct,squished_pc))
869 return ERROR_FUNCTION_FAILED;
870 TRACE("squished (%s)\n", debugstr_w(squished_pc));
872 sprintfW(keypath,szInstaller_Products_fmt,squished_pc);
874 if (create)
875 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
876 else
877 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
879 return rc;
882 UINT MSIREG_DeleteProductKey(LPCWSTR szProduct)
884 WCHAR squished_pc[GUID_SIZE];
885 WCHAR keypath[0x200];
887 TRACE("%s\n", debugstr_w(szProduct));
888 if (!squash_guid(szProduct, squished_pc))
889 return ERROR_FUNCTION_FAILED;
890 TRACE("squished (%s)\n", debugstr_w(squished_pc));
892 sprintfW(keypath, szInstaller_Products_fmt, squished_pc);
894 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
897 UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
899 UINT rc;
900 WCHAR squished_pc[GUID_SIZE];
901 WCHAR keypath[0x200];
903 TRACE("%s\n",debugstr_w(szPatch));
904 if (!squash_guid(szPatch,squished_pc))
905 return ERROR_FUNCTION_FAILED;
906 TRACE("squished (%s)\n", debugstr_w(squished_pc));
908 sprintfW(keypath,szInstaller_Patches_fmt,squished_pc);
910 if (create)
911 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
912 else
913 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
915 return rc;
918 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
920 UINT rc;
921 WCHAR squished_pc[GUID_SIZE];
922 WCHAR keypath[0x200];
924 TRACE("%s\n",debugstr_w(szUpgradeCode));
925 if (!squash_guid(szUpgradeCode,squished_pc))
926 return ERROR_FUNCTION_FAILED;
927 TRACE("squished (%s)\n", debugstr_w(squished_pc));
929 sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
931 if (create)
932 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
933 else
934 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
936 return rc;
939 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
941 UINT rc;
942 WCHAR squished_pc[GUID_SIZE];
943 WCHAR keypath[0x200];
945 TRACE("%s\n",debugstr_w(szUpgradeCode));
946 if (!squash_guid(szUpgradeCode,squished_pc))
947 return ERROR_FUNCTION_FAILED;
948 TRACE("squished (%s)\n", debugstr_w(squished_pc));
950 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
952 if (create)
953 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
954 else
955 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
957 return rc;
960 UINT MSIREG_OpenLocalSystemProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create)
962 WCHAR squished_pc[GUID_SIZE];
963 WCHAR keypath[0x200];
965 TRACE("%s\n", debugstr_w(szProductCode));
967 if (!squash_guid(szProductCode, squished_pc))
968 return ERROR_FUNCTION_FAILED;
970 TRACE("squished (%s)\n", debugstr_w(squished_pc));
972 sprintfW(keypath, szInstaller_LocalSystemProductCodes_fmt, squished_pc);
974 if (create)
975 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
977 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
980 UINT MSIREG_OpenLocalSystemComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create)
982 WCHAR squished_pc[GUID_SIZE];
983 WCHAR keypath[0x200];
985 TRACE("%s\n", debugstr_w(szComponent));
987 if (!squash_guid(szComponent, squished_pc))
988 return ERROR_FUNCTION_FAILED;
990 TRACE("squished (%s)\n", debugstr_w(squished_pc));
992 sprintfW(keypath, szInstaller_LocalSystemComponent_fmt, squished_pc);
994 if (create)
995 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
997 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1000 UINT MSIREG_OpenLocalClassesProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create)
1002 WCHAR squished_pc[GUID_SIZE];
1003 WCHAR keypath[0x200];
1005 TRACE("%s\n", debugstr_w(szProductCode));
1007 if (!squash_guid(szProductCode, squished_pc))
1008 return ERROR_FUNCTION_FAILED;
1010 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1012 sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc);
1014 if (create)
1015 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1017 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1020 UINT MSIREG_OpenLocalManagedProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create)
1022 WCHAR squished_pc[GUID_SIZE];
1023 WCHAR keypath[0x200];
1024 LPWSTR usersid;
1025 UINT r;
1027 TRACE("%s\n", debugstr_w(szProductCode));
1029 if (!squash_guid(szProductCode, squished_pc))
1030 return ERROR_FUNCTION_FAILED;
1032 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1034 r = get_user_sid(&usersid);
1035 if (r != ERROR_SUCCESS || !usersid)
1037 ERR("Failed to retrieve user SID: %d\n", r);
1038 return r;
1041 sprintfW(keypath, szInstaller_LocalManagedProd_fmt, usersid, squished_pc);
1042 LocalFree(usersid);
1044 if (create)
1045 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1047 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1050 /*************************************************************************
1051 * MsiDecomposeDescriptorW [MSI.@]
1053 * Decomposes an MSI descriptor into product, feature and component parts.
1054 * An MSI descriptor is a string of the form:
1055 * [base 85 guid] [feature code] '>' [base 85 guid]
1057 * PARAMS
1058 * szDescriptor [I] the descriptor to decompose
1059 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
1060 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
1061 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
1062 * pUsed [O] the length of the descriptor
1064 * RETURNS
1065 * ERROR_SUCCESS if everything worked correctly
1066 * ERROR_INVALID_PARAMETER if the descriptor was invalid
1069 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
1070 LPWSTR szFeature, LPWSTR szComponent, LPDWORD pUsed )
1072 UINT r, len;
1073 LPWSTR p;
1074 GUID product, component;
1076 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
1077 szFeature, szComponent, pUsed);
1079 r = decode_base85_guid( szDescriptor, &product );
1080 if( !r )
1081 return ERROR_INVALID_PARAMETER;
1083 TRACE("product %s\n", debugstr_guid( &product ));
1085 p = strchrW(&szDescriptor[20],'>');
1086 if( !p )
1087 return ERROR_INVALID_PARAMETER;
1089 len = (p - &szDescriptor[20]);
1090 if( len > MAX_FEATURE_CHARS )
1091 return ERROR_INVALID_PARAMETER;
1093 TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len ));
1095 r = decode_base85_guid( p+1, &component );
1096 if( !r )
1097 return ERROR_INVALID_PARAMETER;
1099 TRACE("component %s\n", debugstr_guid( &component ));
1101 if (szProduct)
1102 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
1103 if (szComponent)
1104 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
1105 if (szFeature)
1107 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
1108 szFeature[len] = 0;
1110 len = ( &p[21] - szDescriptor );
1112 TRACE("length = %d\n", len);
1113 *pUsed = len;
1115 return ERROR_SUCCESS;
1118 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
1119 LPSTR szFeature, LPSTR szComponent, LPDWORD pUsed )
1121 WCHAR product[MAX_FEATURE_CHARS+1];
1122 WCHAR feature[MAX_FEATURE_CHARS+1];
1123 WCHAR component[MAX_FEATURE_CHARS+1];
1124 LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
1125 UINT r;
1127 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
1128 szFeature, szComponent, pUsed);
1130 str = strdupAtoW( szDescriptor );
1131 if( szDescriptor && !str )
1132 return ERROR_OUTOFMEMORY;
1134 if (szProduct)
1135 p = product;
1136 if (szFeature)
1137 f = feature;
1138 if (szComponent)
1139 c = component;
1141 r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
1143 if (r == ERROR_SUCCESS)
1145 WideCharToMultiByte( CP_ACP, 0, p, -1,
1146 szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
1147 WideCharToMultiByte( CP_ACP, 0, f, -1,
1148 szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
1149 WideCharToMultiByte( CP_ACP, 0, c, -1,
1150 szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
1153 msi_free( str );
1155 return r;
1158 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
1160 DWORD r;
1161 WCHAR szwGuid[GUID_SIZE];
1163 TRACE("%d %p\n", index, lpguid);
1165 if (NULL == lpguid)
1166 return ERROR_INVALID_PARAMETER;
1167 r = MsiEnumProductsW(index, szwGuid);
1168 if( r == ERROR_SUCCESS )
1169 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1171 return r;
1174 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
1176 HKEY hkeyProducts = 0;
1177 DWORD r;
1178 WCHAR szKeyName[SQUISH_GUID_SIZE];
1180 TRACE("%d %p\n", index, lpguid);
1182 if (NULL == lpguid)
1183 return ERROR_INVALID_PARAMETER;
1185 r = MSIREG_OpenProducts(&hkeyProducts);
1186 if( r != ERROR_SUCCESS )
1187 return ERROR_NO_MORE_ITEMS;
1189 r = RegEnumKeyW(hkeyProducts, index, szKeyName, SQUISH_GUID_SIZE);
1190 if( r == ERROR_SUCCESS )
1191 unsquash_guid(szKeyName, lpguid);
1192 RegCloseKey(hkeyProducts);
1194 return r;
1197 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
1198 LPSTR szFeature, LPSTR szParent)
1200 DWORD r;
1201 WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
1202 LPWSTR szwProduct = NULL;
1204 TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent);
1206 if( szProduct )
1208 szwProduct = strdupAtoW( szProduct );
1209 if( !szwProduct )
1210 return ERROR_OUTOFMEMORY;
1213 r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
1214 if( r == ERROR_SUCCESS )
1216 WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
1217 szFeature, GUID_SIZE, NULL, NULL);
1218 WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
1219 szParent, GUID_SIZE, NULL, NULL);
1222 msi_free( szwProduct);
1224 return r;
1227 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
1228 LPWSTR szFeature, LPWSTR szParent)
1230 HKEY hkeyProduct = 0;
1231 DWORD r, sz;
1233 TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
1235 if( !szProduct )
1236 return ERROR_INVALID_PARAMETER;
1238 r = MSIREG_OpenFeaturesKey(szProduct,&hkeyProduct,FALSE);
1239 if( r != ERROR_SUCCESS )
1240 return ERROR_NO_MORE_ITEMS;
1242 sz = GUID_SIZE;
1243 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
1244 RegCloseKey(hkeyProduct);
1246 return r;
1249 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
1251 DWORD r;
1252 WCHAR szwGuid[GUID_SIZE];
1254 TRACE("%d %p\n", index, lpguid);
1256 r = MsiEnumComponentsW(index, szwGuid);
1257 if( r == ERROR_SUCCESS )
1258 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1260 return r;
1263 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
1265 HKEY hkeyComponents = 0;
1266 DWORD r;
1267 WCHAR szKeyName[SQUISH_GUID_SIZE];
1269 TRACE("%d %p\n", index, lpguid);
1271 r = MSIREG_OpenComponents(&hkeyComponents);
1272 if( r != ERROR_SUCCESS )
1273 return ERROR_NO_MORE_ITEMS;
1275 r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
1276 if( r == ERROR_SUCCESS )
1277 unsquash_guid(szKeyName, lpguid);
1278 RegCloseKey(hkeyComponents);
1280 return r;
1283 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
1285 DWORD r;
1286 WCHAR szwProduct[GUID_SIZE];
1287 LPWSTR szwComponent = NULL;
1289 TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
1291 if ( !szProduct )
1292 return ERROR_INVALID_PARAMETER;
1294 if( szComponent )
1296 szwComponent = strdupAtoW( szComponent );
1297 if( !szwComponent )
1298 return ERROR_OUTOFMEMORY;
1301 r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
1302 if( r == ERROR_SUCCESS )
1304 WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
1305 szProduct, GUID_SIZE, NULL, NULL);
1308 msi_free( szwComponent);
1310 return r;
1313 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
1315 HKEY hkeyComp = 0;
1316 DWORD r, sz;
1317 WCHAR szValName[SQUISH_GUID_SIZE];
1319 TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct);
1321 if (!szComponent || !*szComponent || !szProduct)
1322 return ERROR_INVALID_PARAMETER;
1324 if (MSIREG_OpenUserDataComponentKey(szComponent, &hkeyComp, FALSE) != ERROR_SUCCESS &&
1325 MSIREG_OpenLocalSystemComponentKey(szComponent, &hkeyComp, FALSE) != ERROR_SUCCESS)
1326 return ERROR_UNKNOWN_COMPONENT;
1328 /* see if there are any products at all */
1329 sz = SQUISH_GUID_SIZE;
1330 r = RegEnumValueW(hkeyComp, 0, szValName, &sz, NULL, NULL, NULL, NULL);
1331 if (r != ERROR_SUCCESS)
1333 RegCloseKey(hkeyComp);
1335 if (index != 0)
1336 return ERROR_INVALID_PARAMETER;
1338 return ERROR_UNKNOWN_COMPONENT;
1341 sz = SQUISH_GUID_SIZE;
1342 r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
1343 if( r == ERROR_SUCCESS )
1344 unsquash_guid(szValName, szProduct);
1346 RegCloseKey(hkeyComp);
1348 return r;
1351 static UINT WINAPI MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
1352 awstring *lpQualBuf, LPDWORD pcchQual,
1353 awstring *lpAppBuf, LPDWORD pcchAppBuf )
1355 DWORD name_sz, val_sz, name_max, val_max, type, ofs;
1356 LPWSTR name = NULL, val = NULL;
1357 UINT r, r2;
1358 HKEY key;
1360 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1361 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
1363 if (!szComponent)
1364 return ERROR_INVALID_PARAMETER;
1366 r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
1367 if (r != ERROR_SUCCESS)
1368 return ERROR_UNKNOWN_COMPONENT;
1370 /* figure out how big the name is we want to return */
1371 name_max = 0x10;
1372 r = ERROR_OUTOFMEMORY;
1373 name = msi_alloc( name_max * sizeof(WCHAR) );
1374 if (!name)
1375 goto end;
1377 val_max = 0x10;
1378 r = ERROR_OUTOFMEMORY;
1379 val = msi_alloc( val_max );
1380 if (!val)
1381 goto end;
1383 /* loop until we allocate enough memory */
1384 while (1)
1386 name_sz = name_max;
1387 val_sz = val_max;
1388 r = RegEnumValueW( key, iIndex, name, &name_sz,
1389 NULL, &type, (LPBYTE)val, &val_sz );
1390 if (r == ERROR_SUCCESS)
1391 break;
1392 if (r != ERROR_MORE_DATA)
1393 goto end;
1395 if (type != REG_MULTI_SZ)
1397 ERR("component data has wrong type (%d)\n", type);
1398 goto end;
1401 r = ERROR_OUTOFMEMORY;
1402 if ((name_sz+1) >= name_max)
1404 name_max *= 2;
1405 msi_free( name );
1406 name = msi_alloc( name_max * sizeof (WCHAR) );
1407 if (!name)
1408 goto end;
1409 continue;
1411 if (val_sz > val_max)
1413 val_max = val_sz + sizeof (WCHAR);
1414 msi_free( val );
1415 val = msi_alloc( val_max * sizeof (WCHAR) );
1416 if (!val)
1417 goto end;
1418 continue;
1420 ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
1421 goto end;
1424 ofs = 0;
1425 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
1426 if (r != ERROR_SUCCESS)
1427 goto end;
1429 TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
1431 r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
1432 r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
1434 if (r2 != ERROR_SUCCESS)
1435 r = r2;
1437 end:
1438 msi_free(val);
1439 msi_free(name);
1440 RegCloseKey(key);
1442 return r;
1445 /*************************************************************************
1446 * MsiEnumComponentQualifiersA [MSI.@]
1448 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
1449 LPSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1450 LPSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1452 awstring qual, appdata;
1453 LPWSTR comp;
1454 UINT r;
1456 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex,
1457 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1458 pcchApplicationDataBuf);
1460 comp = strdupAtoW( szComponent );
1461 if (szComponent && !comp)
1462 return ERROR_OUTOFMEMORY;
1464 qual.unicode = FALSE;
1465 qual.str.a = lpQualifierBuf;
1467 appdata.unicode = FALSE;
1468 appdata.str.a = lpApplicationDataBuf;
1470 r = MSI_EnumComponentQualifiers( comp, iIndex,
1471 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1472 msi_free( comp );
1473 return r;
1476 /*************************************************************************
1477 * MsiEnumComponentQualifiersW [MSI.@]
1479 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
1480 LPWSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1481 LPWSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1483 awstring qual, appdata;
1485 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1486 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1487 pcchApplicationDataBuf);
1489 qual.unicode = TRUE;
1490 qual.str.w = lpQualifierBuf;
1492 appdata.unicode = TRUE;
1493 appdata.str.w = lpApplicationDataBuf;
1495 return MSI_EnumComponentQualifiers( szComponent, iIndex,
1496 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1499 /*************************************************************************
1500 * MsiEnumRelatedProductsW [MSI.@]
1503 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
1504 DWORD iProductIndex, LPWSTR lpProductBuf)
1506 UINT r;
1507 HKEY hkey;
1508 DWORD dwSize = SQUISH_GUID_SIZE;
1509 WCHAR szKeyName[SQUISH_GUID_SIZE];
1511 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved,
1512 iProductIndex, lpProductBuf);
1514 if (NULL == szUpgradeCode)
1515 return ERROR_INVALID_PARAMETER;
1516 if (NULL == lpProductBuf)
1517 return ERROR_INVALID_PARAMETER;
1519 r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1520 if (r != ERROR_SUCCESS)
1521 return ERROR_NO_MORE_ITEMS;
1523 r = RegEnumValueW(hkey, iProductIndex, szKeyName, &dwSize, NULL, NULL, NULL, NULL);
1524 if( r == ERROR_SUCCESS )
1525 unsquash_guid(szKeyName, lpProductBuf);
1526 RegCloseKey(hkey);
1528 return r;
1531 /*************************************************************************
1532 * MsiEnumRelatedProductsA [MSI.@]
1535 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1536 DWORD iProductIndex, LPSTR lpProductBuf)
1538 LPWSTR szwUpgradeCode = NULL;
1539 WCHAR productW[GUID_SIZE];
1540 UINT r;
1542 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1543 iProductIndex, lpProductBuf);
1545 if (szUpgradeCode)
1547 szwUpgradeCode = strdupAtoW( szUpgradeCode );
1548 if( !szwUpgradeCode )
1549 return ERROR_OUTOFMEMORY;
1552 r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1553 iProductIndex, productW );
1554 if (r == ERROR_SUCCESS)
1556 WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1557 lpProductBuf, GUID_SIZE, NULL, NULL );
1559 msi_free( szwUpgradeCode);
1560 return r;
1563 /***********************************************************************
1564 * MsiEnumPatchesA [MSI.@]
1566 UINT WINAPI MsiEnumPatchesA( LPCSTR szProduct, DWORD iPatchIndex,
1567 LPSTR lpPatchBuf, LPSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
1569 FIXME("%s %d %p %p %p\n", debugstr_a(szProduct),
1570 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1571 return ERROR_NO_MORE_ITEMS;
1574 /***********************************************************************
1575 * MsiEnumPatchesW [MSI.@]
1577 UINT WINAPI MsiEnumPatchesW( LPCWSTR szProduct, DWORD iPatchIndex,
1578 LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
1580 FIXME("%s %d %p %p %p\n", debugstr_w(szProduct),
1581 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1582 return ERROR_NO_MORE_ITEMS;
1585 UINT WINAPI MsiEnumProductsExA( LPCSTR szProductCode, LPCSTR szUserSid,
1586 DWORD dwContext, DWORD dwIndex, CHAR szInstalledProductCode[39],
1587 MSIINSTALLCONTEXT* pdwInstalledContext, LPSTR szSid, LPDWORD pcchSid)
1589 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_a(szProductCode), debugstr_a(szUserSid),
1590 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1591 szSid, pcchSid);
1592 return ERROR_NO_MORE_ITEMS;
1595 UINT WINAPI MsiEnumProductsExW( LPCWSTR szProductCode, LPCWSTR szUserSid,
1596 DWORD dwContext, DWORD dwIndex, WCHAR szInstalledProductCode[39],
1597 MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, LPDWORD pcchSid)
1599 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_w(szProductCode), debugstr_w(szUserSid),
1600 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1601 szSid, pcchSid);
1602 return ERROR_NO_MORE_ITEMS;