msi: Publish the UpgradeCode in PublishProduct.
[wine.git] / dlls / msi / registry.c
blobc3d425d7d2098538f5993a7906630beef1b0381e
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_LocalClassesFeat_fmt[] = {
208 'S','o','f','t','w','a','r','e','\\',
209 'C','l','a','s','s','e','s','\\',
210 'I','n','s','t','a','l','l','e','r','\\',
211 'F','e','a','t','u','r','e','s','\\','%','s',0};
213 static const WCHAR szInstaller_LocalManagedProd_fmt[] = {
214 'S','o','f','t','w','a','r','e','\\',
215 'M','i','c','r','o','s','o','f','t','\\',
216 'W','i','n','d','o','w','s','\\',
217 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
218 'I','n','s','t','a','l','l','e','r','\\',
219 'M','a','n','a','g','e','d','\\','%','s','\\',
220 'I','n','s','t','a','l','l','e','r','\\',
221 'P','r','o','d','u','c','t','s','\\','%','s',0};
223 static const WCHAR localsid[] = {'S','-','1','-','5','-','1','8',0};
225 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
227 DWORD i,n=0;
229 out[n++]='{';
230 for(i=0; i<8; i++)
231 out[n++] = in[7-i];
232 out[n++]='-';
233 for(i=0; i<4; i++)
234 out[n++] = in[11-i];
235 out[n++]='-';
236 for(i=0; i<4; i++)
237 out[n++] = in[15-i];
238 out[n++]='-';
239 for(i=0; i<2; i++)
241 out[n++] = in[17+i*2];
242 out[n++] = in[16+i*2];
244 out[n++]='-';
245 for( ; i<8; i++)
247 out[n++] = in[17+i*2];
248 out[n++] = in[16+i*2];
250 out[n++]='}';
251 out[n]=0;
252 return TRUE;
255 BOOL squash_guid(LPCWSTR in, LPWSTR out)
257 DWORD i,n=1;
258 GUID guid;
260 out[0] = 0;
262 if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
263 return FALSE;
265 for(i=0; i<8; i++)
266 out[7-i] = in[n++];
267 n++;
268 for(i=0; i<4; i++)
269 out[11-i] = in[n++];
270 n++;
271 for(i=0; i<4; i++)
272 out[15-i] = in[n++];
273 n++;
274 for(i=0; i<2; i++)
276 out[17+i*2] = in[n++];
277 out[16+i*2] = in[n++];
279 n++;
280 for( ; i<8; i++)
282 out[17+i*2] = in[n++];
283 out[16+i*2] = in[n++];
285 out[32]=0;
286 return TRUE;
290 /* tables for encoding and decoding base85 */
291 static const unsigned char table_dec85[0x80] = {
292 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
293 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
294 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
295 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
296 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
297 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
298 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
299 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
302 static const char table_enc85[] =
303 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
304 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
305 "yz{}~";
308 * Converts a base85 encoded guid into a GUID pointer
309 * Base85 encoded GUIDs should be 20 characters long.
311 * returns TRUE if successful, FALSE if not
313 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
315 DWORD i, val = 0, base = 1, *p;
317 if (!str)
318 return FALSE;
320 p = (DWORD*) guid;
321 for( i=0; i<20; i++ )
323 if( (i%5) == 0 )
325 val = 0;
326 base = 1;
328 val += table_dec85[str[i]] * base;
329 if( str[i] >= 0x80 )
330 return FALSE;
331 if( table_dec85[str[i]] == 0xff )
332 return FALSE;
333 if( (i%5) == 4 )
334 p[i/5] = val;
335 base *= 85;
337 return TRUE;
341 * Encodes a base85 guid given a GUID pointer
342 * Caller should provide a 21 character buffer for the encoded string.
344 * returns TRUE if successful, FALSE if not
346 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
348 unsigned int x, *p, i;
350 p = (unsigned int*) guid;
351 for( i=0; i<4; i++ )
353 x = p[i];
354 *str++ = table_enc85[x%85];
355 x = x/85;
356 *str++ = table_enc85[x%85];
357 x = x/85;
358 *str++ = table_enc85[x%85];
359 x = x/85;
360 *str++ = table_enc85[x%85];
361 x = x/85;
362 *str++ = table_enc85[x%85];
364 *str = 0;
366 return TRUE;
369 DWORD msi_version_str_to_dword(LPCWSTR p)
371 DWORD major, minor = 0, build = 0, version = 0;
373 if (!p)
374 return version;
376 major = atoiW(p);
378 p = strchrW(p, '.');
379 if (p)
381 minor = atoiW(p+1);
382 p = strchrW(p+1, '.');
383 if (p)
384 build = atoiW(p+1);
387 return MAKELONG(build, MAKEWORD(minor, major));
390 LPWSTR msi_version_dword_to_str(DWORD version)
392 static const WCHAR fmt[] = { '%','u','.','%','u','.','%','u',0 };
393 LPWSTR str = msi_alloc(20);
394 sprintfW(str, fmt,
395 (version&0xff000000)>>24,
396 (version&0x00ff0000)>>16,
397 version&0x0000ffff);
398 return str;
401 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
403 static const WCHAR emptyW[] = {0};
404 DWORD len;
405 if (!value) value = emptyW;
406 len = (lstrlenW(value) + 1) * sizeof (WCHAR);
407 return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len );
410 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
412 LPCWSTR p = value;
413 while (*p) p += lstrlenW(p) + 1;
414 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
415 (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) );
418 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
420 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
423 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
425 HKEY hsubkey = 0;
426 LONG r;
428 r = RegCreateKeyW( hkey, path, &hsubkey );
429 if (r != ERROR_SUCCESS)
430 return r;
431 r = msi_reg_set_val_str( hsubkey, name, val );
432 RegCloseKey( hsubkey );
433 return r;
436 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
438 DWORD len = 0;
439 LPWSTR val;
440 LONG r;
442 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
443 if (r != ERROR_SUCCESS)
444 return NULL;
446 len += sizeof (WCHAR);
447 val = msi_alloc( len );
448 if (!val)
449 return NULL;
450 val[0] = 0;
451 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
452 return val;
455 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
457 DWORD type, len = sizeof (DWORD);
458 LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
459 return r == ERROR_SUCCESS && type == REG_DWORD;
462 static UINT get_user_sid(LPWSTR *usersid)
464 HANDLE token;
465 BYTE buf[1024];
466 DWORD size;
467 PTOKEN_USER user;
469 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
470 return ERROR_FUNCTION_FAILED;
472 size = sizeof(buf);
473 if (!GetTokenInformation(token, TokenUser, (void *)buf, size, &size)) {
474 CloseHandle(token);
475 return ERROR_FUNCTION_FAILED;
478 user = (PTOKEN_USER)buf;
479 if (!ConvertSidToStringSidW(user->User.Sid, usersid)) {
480 CloseHandle(token);
481 return ERROR_FUNCTION_FAILED;
483 CloseHandle(token);
484 return ERROR_SUCCESS;
487 UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create)
489 UINT rc;
490 WCHAR keypath[0x200];
491 TRACE("%s\n",debugstr_w(szProduct));
493 sprintfW(keypath,szUninstall_fmt,szProduct);
495 if (create)
496 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
497 else
498 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
500 return rc;
503 UINT MSIREG_DeleteUninstallKey(LPCWSTR szProduct)
505 WCHAR keypath[0x200];
506 TRACE("%s\n",debugstr_w(szProduct));
508 sprintfW(keypath,szUninstall_fmt,szProduct);
510 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
513 UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
515 UINT rc;
516 WCHAR squished_pc[GUID_SIZE];
517 WCHAR keypath[0x200];
519 TRACE("%s\n",debugstr_w(szProduct));
520 if (!squash_guid(szProduct,squished_pc))
521 return ERROR_FUNCTION_FAILED;
522 TRACE("squished (%s)\n", debugstr_w(squished_pc));
524 sprintfW(keypath,szUserProduct_fmt,squished_pc);
526 if (create)
527 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
528 else
529 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
531 return rc;
534 UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct)
536 WCHAR squished_pc[GUID_SIZE];
537 WCHAR keypath[0x200];
539 TRACE("%s\n",debugstr_w(szProduct));
540 if (!squash_guid(szProduct,squished_pc))
541 return ERROR_FUNCTION_FAILED;
542 TRACE("squished (%s)\n", debugstr_w(squished_pc));
544 sprintfW(keypath,szUserProduct_fmt,squished_pc);
546 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
549 UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
551 UINT rc;
552 WCHAR squished_pc[GUID_SIZE];
553 WCHAR keypath[0x200];
555 TRACE("%s\n",debugstr_w(szPatch));
556 if (!squash_guid(szPatch,squished_pc))
557 return ERROR_FUNCTION_FAILED;
558 TRACE("squished (%s)\n", debugstr_w(squished_pc));
560 sprintfW(keypath,szUserPatch_fmt,squished_pc);
562 if (create)
563 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
564 else
565 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
567 return rc;
570 UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
572 UINT rc;
573 WCHAR squished_pc[GUID_SIZE];
574 WCHAR keypath[0x200];
576 TRACE("%s\n",debugstr_w(szProduct));
577 if (!squash_guid(szProduct,squished_pc))
578 return ERROR_FUNCTION_FAILED;
579 TRACE("squished (%s)\n", debugstr_w(squished_pc));
581 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
583 if (create)
584 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
585 else
586 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
588 return rc;
591 UINT MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct)
593 WCHAR squished_pc[GUID_SIZE];
594 WCHAR keypath[0x200];
596 TRACE("%s\n",debugstr_w(szProduct));
597 if (!squash_guid(szProduct,squished_pc))
598 return ERROR_FUNCTION_FAILED;
599 TRACE("squished (%s)\n", debugstr_w(squished_pc));
601 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
602 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
605 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
607 UINT rc;
608 WCHAR squished_pc[GUID_SIZE];
609 WCHAR keypath[0x200];
611 TRACE("%s\n",debugstr_w(szProduct));
612 if (!squash_guid(szProduct,squished_pc))
613 return ERROR_FUNCTION_FAILED;
614 TRACE("squished (%s)\n", debugstr_w(squished_pc));
616 sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
618 if (create)
619 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
620 else
621 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
623 return rc;
626 UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL create)
628 UINT rc;
629 WCHAR squished_pc[GUID_SIZE];
630 WCHAR keypath[0x200];
631 LPWSTR usersid;
633 TRACE("%s\n", debugstr_w(szProduct));
634 if (!squash_guid(szProduct, squished_pc))
635 return ERROR_FUNCTION_FAILED;
636 TRACE("squished (%s)\n", debugstr_w(squished_pc));
638 rc = get_user_sid(&usersid);
639 if (rc != ERROR_SUCCESS || !usersid)
641 ERR("Failed to retrieve user SID: %d\n", rc);
642 return rc;
645 sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc);
647 if (create)
648 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
649 else
650 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
652 LocalFree(usersid);
653 return rc;
656 UINT MSIREG_OpenLocalUserDataFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL create)
658 WCHAR squished_pc[GUID_SIZE];
659 WCHAR keypath[0x200];
661 TRACE("%s\n", debugstr_w(szProduct));
662 if (!squash_guid(szProduct, squished_pc))
663 return ERROR_FUNCTION_FAILED;
664 TRACE("squished (%s)\n", debugstr_w(squished_pc));
666 sprintfW(keypath, szUserDataFeatures_fmt, localsid, squished_pc);
668 if (create)
669 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
671 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
674 UINT MSIREG_OpenUserComponentsKey(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,szUser_Components_fmt,squished_cc);
687 if (create)
688 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
689 else
690 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
692 return rc;
695 UINT MSIREG_OpenLocalUserDataComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create)
697 WCHAR comp[GUID_SIZE];
698 WCHAR keypath[0x200];
700 TRACE("%s\n", debugstr_w(szComponent));
701 if (!squash_guid(szComponent, comp))
702 return ERROR_FUNCTION_FAILED;
703 TRACE("squished (%s)\n", debugstr_w(comp));
705 sprintfW(keypath, szUserDataComp_fmt, localsid, comp);
707 if (create)
708 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
710 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
713 UINT MSIREG_DeleteLocalUserDataComponentKey(LPCWSTR szComponent)
715 WCHAR comp[GUID_SIZE];
716 WCHAR keypath[0x200];
718 TRACE("%s\n", debugstr_w(szComponent));
719 if (!squash_guid(szComponent, comp))
720 return ERROR_FUNCTION_FAILED;
721 TRACE("squished (%s)\n", debugstr_w(comp));
723 sprintfW(keypath, szUserDataComp_fmt, localsid, comp);
724 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
727 UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create)
729 UINT rc;
730 WCHAR comp[GUID_SIZE];
731 WCHAR keypath[0x200];
732 LPWSTR usersid;
734 TRACE("%s\n", debugstr_w(szComponent));
735 if (!squash_guid(szComponent, comp))
736 return ERROR_FUNCTION_FAILED;
737 TRACE("squished (%s)\n", debugstr_w(comp));
739 rc = get_user_sid(&usersid);
740 if (rc != ERROR_SUCCESS || !usersid)
742 ERR("Failed to retrieve user SID: %d\n", rc);
743 return rc;
746 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
748 if (create)
749 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
750 else
751 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
753 LocalFree(usersid);
754 return rc;
757 UINT MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent)
759 UINT rc;
760 WCHAR comp[GUID_SIZE];
761 WCHAR keypath[0x200];
762 LPWSTR usersid;
764 TRACE("%s\n", debugstr_w(szComponent));
765 if (!squash_guid(szComponent, comp))
766 return ERROR_FUNCTION_FAILED;
767 TRACE("squished (%s)\n", debugstr_w(comp));
769 rc = get_user_sid(&usersid);
770 if (rc != ERROR_SUCCESS || !usersid)
772 ERR("Failed to retrieve user SID: %d\n", rc);
773 return rc;
776 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
778 LocalFree(usersid);
779 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
782 UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, HKEY *key, BOOL create)
784 UINT rc;
785 WCHAR squished_pc[GUID_SIZE];
786 WCHAR keypath[0x200];
787 LPWSTR usersid;
789 TRACE("%s\n", debugstr_w(szProduct));
790 if (!squash_guid(szProduct, squished_pc))
791 return ERROR_FUNCTION_FAILED;
792 TRACE("squished (%s)\n", debugstr_w(squished_pc));
794 rc = get_user_sid(&usersid);
795 if (rc != ERROR_SUCCESS || !usersid)
797 ERR("Failed to retrieve user SID: %d\n", rc);
798 return rc;
801 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
803 if (create)
804 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
805 else
806 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
808 LocalFree(usersid);
809 return rc;
812 static UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, LPCWSTR szUserSID,
813 HKEY *key, BOOL create)
815 UINT rc;
816 WCHAR squished_pc[GUID_SIZE];
817 WCHAR keypath[0x200];
819 TRACE("%s\n", debugstr_w(szProduct));
820 if (!squash_guid(szProduct, squished_pc))
821 return ERROR_FUNCTION_FAILED;
822 TRACE("squished (%s)\n", debugstr_w(squished_pc));
824 sprintfW(keypath, szInstallProperties_fmt, szUserSID, squished_pc);
826 if (create)
827 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
828 else
829 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
831 return rc;
834 UINT MSIREG_OpenCurrentUserInstallProps(LPCWSTR szProduct, HKEY *key,
835 BOOL create)
837 UINT rc;
838 LPWSTR usersid;
840 rc = get_user_sid(&usersid);
841 if (rc != ERROR_SUCCESS || !usersid)
843 ERR("Failed to retrieve user SID: %d\n", rc);
844 return rc;
847 rc = MSIREG_OpenInstallProps(szProduct, usersid, key, create);
849 LocalFree(usersid);
850 return rc;
853 UINT MSIREG_OpenLocalSystemInstallProps(LPCWSTR szProduct, HKEY *key,
854 BOOL create)
856 return MSIREG_OpenInstallProps(szProduct, localsid, key, create);
859 UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)
861 UINT rc;
862 WCHAR squished_pc[GUID_SIZE];
863 WCHAR keypath[0x200];
864 LPWSTR usersid;
866 TRACE("%s\n", debugstr_w(szProduct));
867 if (!squash_guid(szProduct, squished_pc))
868 return ERROR_FUNCTION_FAILED;
869 TRACE("squished (%s)\n", debugstr_w(squished_pc));
871 rc = get_user_sid(&usersid);
872 if (rc != ERROR_SUCCESS || !usersid)
874 ERR("Failed to retrieve user SID: %d\n", rc);
875 return rc;
878 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
880 LocalFree(usersid);
881 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
884 UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
886 UINT rc;
887 WCHAR squished_pc[GUID_SIZE];
888 WCHAR keypath[0x200];
890 TRACE("%s\n",debugstr_w(szProduct));
891 if (!squash_guid(szProduct,squished_pc))
892 return ERROR_FUNCTION_FAILED;
893 TRACE("squished (%s)\n", debugstr_w(squished_pc));
895 sprintfW(keypath,szInstaller_Products_fmt,squished_pc);
897 if (create)
898 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
899 else
900 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
902 return rc;
905 UINT MSIREG_DeleteProductKey(LPCWSTR szProduct)
907 WCHAR squished_pc[GUID_SIZE];
908 WCHAR keypath[0x200];
910 TRACE("%s\n", debugstr_w(szProduct));
911 if (!squash_guid(szProduct, squished_pc))
912 return ERROR_FUNCTION_FAILED;
913 TRACE("squished (%s)\n", debugstr_w(squished_pc));
915 sprintfW(keypath, szInstaller_Products_fmt, squished_pc);
917 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
920 UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
922 UINT rc;
923 WCHAR squished_pc[GUID_SIZE];
924 WCHAR keypath[0x200];
926 TRACE("%s\n",debugstr_w(szPatch));
927 if (!squash_guid(szPatch,squished_pc))
928 return ERROR_FUNCTION_FAILED;
929 TRACE("squished (%s)\n", debugstr_w(squished_pc));
931 sprintfW(keypath,szInstaller_Patches_fmt,squished_pc);
933 if (create)
934 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
935 else
936 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
938 return rc;
941 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
943 UINT rc;
944 WCHAR squished_pc[GUID_SIZE];
945 WCHAR keypath[0x200];
947 TRACE("%s\n",debugstr_w(szUpgradeCode));
948 if (!squash_guid(szUpgradeCode,squished_pc))
949 return ERROR_FUNCTION_FAILED;
950 TRACE("squished (%s)\n", debugstr_w(squished_pc));
952 sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
954 if (create)
955 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
956 else
957 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
959 return rc;
962 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
964 UINT rc;
965 WCHAR squished_pc[GUID_SIZE];
966 WCHAR keypath[0x200];
968 TRACE("%s\n",debugstr_w(szUpgradeCode));
969 if (!squash_guid(szUpgradeCode,squished_pc))
970 return ERROR_FUNCTION_FAILED;
971 TRACE("squished (%s)\n", debugstr_w(squished_pc));
973 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
975 if (create)
976 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
977 else
978 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
980 return rc;
983 UINT MSIREG_DeleteUserUpgradeCodesKey(LPCWSTR szUpgradeCode)
985 WCHAR squished_pc[GUID_SIZE];
986 WCHAR keypath[0x200];
988 TRACE("%s\n",debugstr_w(szUpgradeCode));
989 if (!squash_guid(szUpgradeCode,squished_pc))
990 return ERROR_FUNCTION_FAILED;
991 TRACE("squished (%s)\n", debugstr_w(squished_pc));
993 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
995 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
998 UINT MSIREG_OpenLocalSystemProductKey(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_LocalSystemProductCodes_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_OpenLocalSystemComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create)
1020 WCHAR squished_pc[GUID_SIZE];
1021 WCHAR keypath[0x200];
1023 TRACE("%s\n", debugstr_w(szComponent));
1025 if (!squash_guid(szComponent, squished_pc))
1026 return ERROR_FUNCTION_FAILED;
1028 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1030 sprintfW(keypath, szInstaller_LocalSystemComponent_fmt, squished_pc);
1032 if (create)
1033 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1035 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1038 UINT MSIREG_OpenLocalClassesProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create)
1040 WCHAR squished_pc[GUID_SIZE];
1041 WCHAR keypath[0x200];
1043 TRACE("%s\n", debugstr_w(szProductCode));
1045 if (!squash_guid(szProductCode, squished_pc))
1046 return ERROR_FUNCTION_FAILED;
1048 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1050 sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc);
1052 if (create)
1053 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1055 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1058 UINT MSIREG_OpenLocalClassesFeaturesKey(LPCWSTR szProductCode, HKEY *key, BOOL create)
1060 WCHAR squished_pc[GUID_SIZE];
1061 WCHAR keypath[0x200];
1063 TRACE("%s\n", debugstr_w(szProductCode));
1065 if (!squash_guid(szProductCode, squished_pc))
1066 return ERROR_FUNCTION_FAILED;
1068 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1070 sprintfW(keypath, szInstaller_LocalClassesFeat_fmt, squished_pc);
1072 if (create)
1073 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1075 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1078 UINT MSIREG_OpenLocalManagedProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create)
1080 WCHAR squished_pc[GUID_SIZE];
1081 WCHAR keypath[0x200];
1082 LPWSTR usersid;
1083 UINT r;
1085 TRACE("%s\n", debugstr_w(szProductCode));
1087 if (!squash_guid(szProductCode, squished_pc))
1088 return ERROR_FUNCTION_FAILED;
1090 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1092 r = get_user_sid(&usersid);
1093 if (r != ERROR_SUCCESS || !usersid)
1095 ERR("Failed to retrieve user SID: %d\n", r);
1096 return r;
1099 sprintfW(keypath, szInstaller_LocalManagedProd_fmt, usersid, squished_pc);
1100 LocalFree(usersid);
1102 if (create)
1103 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1105 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1108 /*************************************************************************
1109 * MsiDecomposeDescriptorW [MSI.@]
1111 * Decomposes an MSI descriptor into product, feature and component parts.
1112 * An MSI descriptor is a string of the form:
1113 * [base 85 guid] [feature code] '>' [base 85 guid]
1115 * PARAMS
1116 * szDescriptor [I] the descriptor to decompose
1117 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
1118 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
1119 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
1120 * pUsed [O] the length of the descriptor
1122 * RETURNS
1123 * ERROR_SUCCESS if everything worked correctly
1124 * ERROR_INVALID_PARAMETER if the descriptor was invalid
1127 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
1128 LPWSTR szFeature, LPWSTR szComponent, LPDWORD pUsed )
1130 UINT r, len;
1131 LPWSTR p;
1132 GUID product, component;
1134 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
1135 szFeature, szComponent, pUsed);
1137 r = decode_base85_guid( szDescriptor, &product );
1138 if( !r )
1139 return ERROR_INVALID_PARAMETER;
1141 TRACE("product %s\n", debugstr_guid( &product ));
1143 p = strchrW(&szDescriptor[20],'>');
1144 if( !p )
1145 return ERROR_INVALID_PARAMETER;
1147 len = (p - &szDescriptor[20]);
1148 if( len > MAX_FEATURE_CHARS )
1149 return ERROR_INVALID_PARAMETER;
1151 TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len ));
1153 r = decode_base85_guid( p+1, &component );
1154 if( !r )
1155 return ERROR_INVALID_PARAMETER;
1157 TRACE("component %s\n", debugstr_guid( &component ));
1159 if (szProduct)
1160 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
1161 if (szComponent)
1162 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
1163 if (szFeature)
1165 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
1166 szFeature[len] = 0;
1168 len = ( &p[21] - szDescriptor );
1170 TRACE("length = %d\n", len);
1171 *pUsed = len;
1173 return ERROR_SUCCESS;
1176 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
1177 LPSTR szFeature, LPSTR szComponent, LPDWORD pUsed )
1179 WCHAR product[MAX_FEATURE_CHARS+1];
1180 WCHAR feature[MAX_FEATURE_CHARS+1];
1181 WCHAR component[MAX_FEATURE_CHARS+1];
1182 LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
1183 UINT r;
1185 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
1186 szFeature, szComponent, pUsed);
1188 str = strdupAtoW( szDescriptor );
1189 if( szDescriptor && !str )
1190 return ERROR_OUTOFMEMORY;
1192 if (szProduct)
1193 p = product;
1194 if (szFeature)
1195 f = feature;
1196 if (szComponent)
1197 c = component;
1199 r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
1201 if (r == ERROR_SUCCESS)
1203 WideCharToMultiByte( CP_ACP, 0, p, -1,
1204 szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
1205 WideCharToMultiByte( CP_ACP, 0, f, -1,
1206 szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
1207 WideCharToMultiByte( CP_ACP, 0, c, -1,
1208 szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
1211 msi_free( str );
1213 return r;
1216 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
1218 DWORD r;
1219 WCHAR szwGuid[GUID_SIZE];
1221 TRACE("%d %p\n", index, lpguid);
1223 if (NULL == lpguid)
1224 return ERROR_INVALID_PARAMETER;
1225 r = MsiEnumProductsW(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 MsiEnumProductsW(DWORD index, LPWSTR lpguid)
1234 HKEY hkeyProducts = 0;
1235 DWORD r;
1236 WCHAR szKeyName[SQUISH_GUID_SIZE];
1238 TRACE("%d %p\n", index, lpguid);
1240 if (NULL == lpguid)
1241 return ERROR_INVALID_PARAMETER;
1243 r = RegCreateKeyW(HKEY_LOCAL_MACHINE, szInstaller_Products, &hkeyProducts);
1244 if( r != ERROR_SUCCESS )
1245 return ERROR_NO_MORE_ITEMS;
1247 r = RegEnumKeyW(hkeyProducts, index, szKeyName, SQUISH_GUID_SIZE);
1248 if( r == ERROR_SUCCESS )
1249 unsquash_guid(szKeyName, lpguid);
1250 RegCloseKey(hkeyProducts);
1252 return r;
1255 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
1256 LPSTR szFeature, LPSTR szParent)
1258 DWORD r;
1259 WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
1260 LPWSTR szwProduct = NULL;
1262 TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent);
1264 if( szProduct )
1266 szwProduct = strdupAtoW( szProduct );
1267 if( !szwProduct )
1268 return ERROR_OUTOFMEMORY;
1271 r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
1272 if( r == ERROR_SUCCESS )
1274 WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
1275 szFeature, GUID_SIZE, NULL, NULL);
1276 WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
1277 szParent, GUID_SIZE, NULL, NULL);
1280 msi_free( szwProduct);
1282 return r;
1285 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
1286 LPWSTR szFeature, LPWSTR szParent)
1288 HKEY hkeyProduct = 0;
1289 DWORD r, sz;
1291 TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
1293 if( !szProduct )
1294 return ERROR_INVALID_PARAMETER;
1296 r = MSIREG_OpenFeaturesKey(szProduct,&hkeyProduct,FALSE);
1297 if( r != ERROR_SUCCESS )
1298 return ERROR_NO_MORE_ITEMS;
1300 sz = GUID_SIZE;
1301 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
1302 RegCloseKey(hkeyProduct);
1304 return r;
1307 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
1309 DWORD r;
1310 WCHAR szwGuid[GUID_SIZE];
1312 TRACE("%d %p\n", index, lpguid);
1314 r = MsiEnumComponentsW(index, szwGuid);
1315 if( r == ERROR_SUCCESS )
1316 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1318 return r;
1321 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
1323 HKEY hkeyComponents = 0;
1324 DWORD r;
1325 WCHAR szKeyName[SQUISH_GUID_SIZE];
1327 TRACE("%d %p\n", index, lpguid);
1329 r = RegCreateKeyW(HKEY_LOCAL_MACHINE, szInstaller_Components, &hkeyComponents);
1330 if( r != ERROR_SUCCESS )
1331 return ERROR_NO_MORE_ITEMS;
1333 r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
1334 if( r == ERROR_SUCCESS )
1335 unsquash_guid(szKeyName, lpguid);
1336 RegCloseKey(hkeyComponents);
1338 return r;
1341 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
1343 DWORD r;
1344 WCHAR szwProduct[GUID_SIZE];
1345 LPWSTR szwComponent = NULL;
1347 TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
1349 if ( !szProduct )
1350 return ERROR_INVALID_PARAMETER;
1352 if( szComponent )
1354 szwComponent = strdupAtoW( szComponent );
1355 if( !szwComponent )
1356 return ERROR_OUTOFMEMORY;
1359 r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
1360 if( r == ERROR_SUCCESS )
1362 WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
1363 szProduct, GUID_SIZE, NULL, NULL);
1366 msi_free( szwComponent);
1368 return r;
1371 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
1373 HKEY hkeyComp = 0;
1374 DWORD r, sz;
1375 WCHAR szValName[SQUISH_GUID_SIZE];
1377 TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct);
1379 if (!szComponent || !*szComponent || !szProduct)
1380 return ERROR_INVALID_PARAMETER;
1382 if (MSIREG_OpenUserDataComponentKey(szComponent, &hkeyComp, FALSE) != ERROR_SUCCESS &&
1383 MSIREG_OpenLocalSystemComponentKey(szComponent, &hkeyComp, FALSE) != ERROR_SUCCESS)
1384 return ERROR_UNKNOWN_COMPONENT;
1386 /* see if there are any products at all */
1387 sz = SQUISH_GUID_SIZE;
1388 r = RegEnumValueW(hkeyComp, 0, szValName, &sz, NULL, NULL, NULL, NULL);
1389 if (r != ERROR_SUCCESS)
1391 RegCloseKey(hkeyComp);
1393 if (index != 0)
1394 return ERROR_INVALID_PARAMETER;
1396 return ERROR_UNKNOWN_COMPONENT;
1399 sz = SQUISH_GUID_SIZE;
1400 r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
1401 if( r == ERROR_SUCCESS )
1402 unsquash_guid(szValName, szProduct);
1404 RegCloseKey(hkeyComp);
1406 return r;
1409 static UINT WINAPI MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
1410 awstring *lpQualBuf, LPDWORD pcchQual,
1411 awstring *lpAppBuf, LPDWORD pcchAppBuf )
1413 DWORD name_sz, val_sz, name_max, val_max, type, ofs;
1414 LPWSTR name = NULL, val = NULL;
1415 UINT r, r2;
1416 HKEY key;
1418 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1419 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
1421 if (!szComponent)
1422 return ERROR_INVALID_PARAMETER;
1424 r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
1425 if (r != ERROR_SUCCESS)
1426 return ERROR_UNKNOWN_COMPONENT;
1428 /* figure out how big the name is we want to return */
1429 name_max = 0x10;
1430 r = ERROR_OUTOFMEMORY;
1431 name = msi_alloc( name_max * sizeof(WCHAR) );
1432 if (!name)
1433 goto end;
1435 val_max = 0x10;
1436 r = ERROR_OUTOFMEMORY;
1437 val = msi_alloc( val_max );
1438 if (!val)
1439 goto end;
1441 /* loop until we allocate enough memory */
1442 while (1)
1444 name_sz = name_max;
1445 val_sz = val_max;
1446 r = RegEnumValueW( key, iIndex, name, &name_sz,
1447 NULL, &type, (LPBYTE)val, &val_sz );
1448 if (r == ERROR_SUCCESS)
1449 break;
1450 if (r != ERROR_MORE_DATA)
1451 goto end;
1453 if (type != REG_MULTI_SZ)
1455 ERR("component data has wrong type (%d)\n", type);
1456 goto end;
1459 r = ERROR_OUTOFMEMORY;
1460 if ((name_sz+1) >= name_max)
1462 name_max *= 2;
1463 msi_free( name );
1464 name = msi_alloc( name_max * sizeof (WCHAR) );
1465 if (!name)
1466 goto end;
1467 continue;
1469 if (val_sz > val_max)
1471 val_max = val_sz + sizeof (WCHAR);
1472 msi_free( val );
1473 val = msi_alloc( val_max * sizeof (WCHAR) );
1474 if (!val)
1475 goto end;
1476 continue;
1478 ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
1479 goto end;
1482 ofs = 0;
1483 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
1484 if (r != ERROR_SUCCESS)
1485 goto end;
1487 TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
1489 r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
1490 r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
1492 if (r2 != ERROR_SUCCESS)
1493 r = r2;
1495 end:
1496 msi_free(val);
1497 msi_free(name);
1498 RegCloseKey(key);
1500 return r;
1503 /*************************************************************************
1504 * MsiEnumComponentQualifiersA [MSI.@]
1506 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
1507 LPSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1508 LPSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1510 awstring qual, appdata;
1511 LPWSTR comp;
1512 UINT r;
1514 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex,
1515 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1516 pcchApplicationDataBuf);
1518 comp = strdupAtoW( szComponent );
1519 if (szComponent && !comp)
1520 return ERROR_OUTOFMEMORY;
1522 qual.unicode = FALSE;
1523 qual.str.a = lpQualifierBuf;
1525 appdata.unicode = FALSE;
1526 appdata.str.a = lpApplicationDataBuf;
1528 r = MSI_EnumComponentQualifiers( comp, iIndex,
1529 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1530 msi_free( comp );
1531 return r;
1534 /*************************************************************************
1535 * MsiEnumComponentQualifiersW [MSI.@]
1537 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
1538 LPWSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1539 LPWSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1541 awstring qual, appdata;
1543 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1544 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1545 pcchApplicationDataBuf);
1547 qual.unicode = TRUE;
1548 qual.str.w = lpQualifierBuf;
1550 appdata.unicode = TRUE;
1551 appdata.str.w = lpApplicationDataBuf;
1553 return MSI_EnumComponentQualifiers( szComponent, iIndex,
1554 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1557 /*************************************************************************
1558 * MsiEnumRelatedProductsW [MSI.@]
1561 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
1562 DWORD iProductIndex, LPWSTR lpProductBuf)
1564 UINT r;
1565 HKEY hkey;
1566 DWORD dwSize = SQUISH_GUID_SIZE;
1567 WCHAR szKeyName[SQUISH_GUID_SIZE];
1569 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved,
1570 iProductIndex, lpProductBuf);
1572 if (NULL == szUpgradeCode)
1573 return ERROR_INVALID_PARAMETER;
1574 if (NULL == lpProductBuf)
1575 return ERROR_INVALID_PARAMETER;
1577 r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1578 if (r != ERROR_SUCCESS)
1579 return ERROR_NO_MORE_ITEMS;
1581 r = RegEnumValueW(hkey, iProductIndex, szKeyName, &dwSize, NULL, NULL, NULL, NULL);
1582 if( r == ERROR_SUCCESS )
1583 unsquash_guid(szKeyName, lpProductBuf);
1584 RegCloseKey(hkey);
1586 return r;
1589 /*************************************************************************
1590 * MsiEnumRelatedProductsA [MSI.@]
1593 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1594 DWORD iProductIndex, LPSTR lpProductBuf)
1596 LPWSTR szwUpgradeCode = NULL;
1597 WCHAR productW[GUID_SIZE];
1598 UINT r;
1600 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1601 iProductIndex, lpProductBuf);
1603 if (szUpgradeCode)
1605 szwUpgradeCode = strdupAtoW( szUpgradeCode );
1606 if( !szwUpgradeCode )
1607 return ERROR_OUTOFMEMORY;
1610 r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1611 iProductIndex, productW );
1612 if (r == ERROR_SUCCESS)
1614 WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1615 lpProductBuf, GUID_SIZE, NULL, NULL );
1617 msi_free( szwUpgradeCode);
1618 return r;
1621 /***********************************************************************
1622 * MsiEnumPatchesA [MSI.@]
1624 UINT WINAPI MsiEnumPatchesA( LPCSTR szProduct, DWORD iPatchIndex,
1625 LPSTR lpPatchBuf, LPSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
1627 FIXME("%s %d %p %p %p\n", debugstr_a(szProduct),
1628 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1629 return ERROR_NO_MORE_ITEMS;
1632 /***********************************************************************
1633 * MsiEnumPatchesW [MSI.@]
1635 UINT WINAPI MsiEnumPatchesW( LPCWSTR szProduct, DWORD iPatchIndex,
1636 LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
1638 FIXME("%s %d %p %p %p\n", debugstr_w(szProduct),
1639 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1640 return ERROR_NO_MORE_ITEMS;
1643 UINT WINAPI MsiEnumProductsExA( LPCSTR szProductCode, LPCSTR szUserSid,
1644 DWORD dwContext, DWORD dwIndex, CHAR szInstalledProductCode[39],
1645 MSIINSTALLCONTEXT* pdwInstalledContext, LPSTR szSid, LPDWORD pcchSid)
1647 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_a(szProductCode), debugstr_a(szUserSid),
1648 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1649 szSid, pcchSid);
1650 return ERROR_NO_MORE_ITEMS;
1653 UINT WINAPI MsiEnumProductsExW( LPCWSTR szProductCode, LPCWSTR szUserSid,
1654 DWORD dwContext, DWORD dwIndex, WCHAR szInstalledProductCode[39],
1655 MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, LPDWORD pcchSid)
1657 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_w(szProductCode), debugstr_w(szUserSid),
1658 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1659 szSid, pcchSid);
1660 return ERROR_NO_MORE_ITEMS;