msi: Add the ability to query a specific context for a patch.
[wine/multimedia.git] / dlls / msi / registry.c
blobd8411ee03441a3987556f497134ceaa48696123b
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 szUserDataPatch_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','a','t','c','h','e','s','\\','%','s',0};
180 static const WCHAR szInstallProperties_fmt[] = {
181 'S','o','f','t','w','a','r','e','\\',
182 'M','i','c','r','o','s','o','f','t','\\',
183 'W','i','n','d','o','w','s','\\',
184 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
185 'I','n','s','t','a','l','l','e','r','\\',
186 'U','s','e','r','D','a','t','a','\\',
187 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\',
188 'I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0};
190 static const WCHAR szInstaller_LocalClassesProd_fmt[] = {
191 'S','o','f','t','w','a','r','e','\\',
192 'C','l','a','s','s','e','s','\\',
193 'I','n','s','t','a','l','l','e','r','\\',
194 'P','r','o','d','u','c','t','s','\\','%','s',0};
196 static const WCHAR szInstaller_LocalClassesFeat_fmt[] = {
197 'S','o','f','t','w','a','r','e','\\',
198 'C','l','a','s','s','e','s','\\',
199 'I','n','s','t','a','l','l','e','r','\\',
200 'F','e','a','t','u','r','e','s','\\','%','s',0};
202 static const WCHAR szInstaller_LocalManagedProd_fmt[] = {
203 'S','o','f','t','w','a','r','e','\\',
204 'M','i','c','r','o','s','o','f','t','\\',
205 'W','i','n','d','o','w','s','\\',
206 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
207 'I','n','s','t','a','l','l','e','r','\\',
208 'M','a','n','a','g','e','d','\\','%','s','\\',
209 'I','n','s','t','a','l','l','e','r','\\',
210 'P','r','o','d','u','c','t','s','\\','%','s',0};
212 static const WCHAR szInstaller_LocalManagedFeat_fmt[] = {
213 'S','o','f','t','w','a','r','e','\\',
214 'M','i','c','r','o','s','o','f','t','\\',
215 'W','i','n','d','o','w','s','\\',
216 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
217 'I','n','s','t','a','l','l','e','r','\\',
218 'M','a','n','a','g','e','d','\\','%','s','\\',
219 'I','n','s','t','a','l','l','e','r','\\',
220 'F','e','a','t','u','r','e','s','\\','%','s',0};
222 static const WCHAR szInstaller_ClassesUpgrade_fmt[] = {
223 'I','n','s','t','a','l','l','e','r','\\',
224 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
225 '%','s',0};
227 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
229 DWORD i,n=0;
231 if (lstrlenW(in) != 32)
232 return FALSE;
234 out[n++]='{';
235 for(i=0; i<8; i++)
236 out[n++] = in[7-i];
237 out[n++]='-';
238 for(i=0; i<4; i++)
239 out[n++] = in[11-i];
240 out[n++]='-';
241 for(i=0; i<4; i++)
242 out[n++] = in[15-i];
243 out[n++]='-';
244 for(i=0; i<2; i++)
246 out[n++] = in[17+i*2];
247 out[n++] = in[16+i*2];
249 out[n++]='-';
250 for( ; i<8; i++)
252 out[n++] = in[17+i*2];
253 out[n++] = in[16+i*2];
255 out[n++]='}';
256 out[n]=0;
257 return TRUE;
260 BOOL squash_guid(LPCWSTR in, LPWSTR out)
262 DWORD i,n=1;
263 GUID guid;
265 out[0] = 0;
267 if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
268 return FALSE;
270 for(i=0; i<8; i++)
271 out[7-i] = in[n++];
272 n++;
273 for(i=0; i<4; i++)
274 out[11-i] = in[n++];
275 n++;
276 for(i=0; i<4; i++)
277 out[15-i] = in[n++];
278 n++;
279 for(i=0; i<2; i++)
281 out[17+i*2] = in[n++];
282 out[16+i*2] = in[n++];
284 n++;
285 for( ; i<8; i++)
287 out[17+i*2] = in[n++];
288 out[16+i*2] = in[n++];
290 out[32]=0;
291 return TRUE;
295 /* tables for encoding and decoding base85 */
296 static const unsigned char table_dec85[0x80] = {
297 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
298 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
299 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
300 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
301 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
302 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
303 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
304 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
307 static const char table_enc85[] =
308 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
309 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
310 "yz{}~";
313 * Converts a base85 encoded guid into a GUID pointer
314 * Base85 encoded GUIDs should be 20 characters long.
316 * returns TRUE if successful, FALSE if not
318 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
320 DWORD i, val = 0, base = 1, *p;
322 if (!str)
323 return FALSE;
325 p = (DWORD*) guid;
326 for( i=0; i<20; i++ )
328 if( (i%5) == 0 )
330 val = 0;
331 base = 1;
333 val += table_dec85[str[i]] * base;
334 if( str[i] >= 0x80 )
335 return FALSE;
336 if( table_dec85[str[i]] == 0xff )
337 return FALSE;
338 if( (i%5) == 4 )
339 p[i/5] = val;
340 base *= 85;
342 return TRUE;
346 * Encodes a base85 guid given a GUID pointer
347 * Caller should provide a 21 character buffer for the encoded string.
349 * returns TRUE if successful, FALSE if not
351 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
353 unsigned int x, *p, i;
355 p = (unsigned int*) guid;
356 for( i=0; i<4; i++ )
358 x = p[i];
359 *str++ = table_enc85[x%85];
360 x = x/85;
361 *str++ = table_enc85[x%85];
362 x = x/85;
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];
369 *str = 0;
371 return TRUE;
374 DWORD msi_version_str_to_dword(LPCWSTR p)
376 DWORD major, minor = 0, build = 0, version = 0;
378 if (!p)
379 return version;
381 major = atoiW(p);
383 p = strchrW(p, '.');
384 if (p)
386 minor = atoiW(p+1);
387 p = strchrW(p+1, '.');
388 if (p)
389 build = atoiW(p+1);
392 return MAKELONG(build, MAKEWORD(minor, major));
395 LPWSTR msi_version_dword_to_str(DWORD version)
397 static const WCHAR fmt[] = { '%','u','.','%','u','.','%','u',0 };
398 LPWSTR str = msi_alloc(20);
399 sprintfW(str, fmt,
400 (version&0xff000000)>>24,
401 (version&0x00ff0000)>>16,
402 version&0x0000ffff);
403 return str;
406 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
408 static const WCHAR emptyW[] = {0};
409 DWORD len;
410 if (!value) value = emptyW;
411 len = (lstrlenW(value) + 1) * sizeof (WCHAR);
412 return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len );
415 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
417 LPCWSTR p = value;
418 while (*p) p += lstrlenW(p) + 1;
419 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
420 (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) );
423 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
425 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
428 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
430 HKEY hsubkey = 0;
431 LONG r;
433 r = RegCreateKeyW( hkey, path, &hsubkey );
434 if (r != ERROR_SUCCESS)
435 return r;
436 r = msi_reg_set_val_str( hsubkey, name, val );
437 RegCloseKey( hsubkey );
438 return r;
441 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
443 DWORD len = 0;
444 LPWSTR val;
445 LONG r;
447 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
448 if (r != ERROR_SUCCESS)
449 return NULL;
451 len += sizeof (WCHAR);
452 val = msi_alloc( len );
453 if (!val)
454 return NULL;
455 val[0] = 0;
456 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
457 return val;
460 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
462 DWORD type, len = sizeof (DWORD);
463 LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
464 return r == ERROR_SUCCESS && type == REG_DWORD;
467 static UINT get_user_sid(LPWSTR *usersid)
469 HANDLE token;
470 BYTE buf[1024];
471 DWORD size;
472 PTOKEN_USER user;
474 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
475 return ERROR_FUNCTION_FAILED;
477 size = sizeof(buf);
478 if (!GetTokenInformation(token, TokenUser, (void *)buf, size, &size)) {
479 CloseHandle(token);
480 return ERROR_FUNCTION_FAILED;
483 user = (PTOKEN_USER)buf;
484 if (!ConvertSidToStringSidW(user->User.Sid, usersid)) {
485 CloseHandle(token);
486 return ERROR_FUNCTION_FAILED;
488 CloseHandle(token);
489 return ERROR_SUCCESS;
492 UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create)
494 UINT rc;
495 WCHAR keypath[0x200];
496 TRACE("%s\n",debugstr_w(szProduct));
498 sprintfW(keypath,szUninstall_fmt,szProduct);
500 if (create)
501 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
502 else
503 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
505 return rc;
508 UINT MSIREG_DeleteUninstallKey(LPCWSTR szProduct)
510 WCHAR keypath[0x200];
511 TRACE("%s\n",debugstr_w(szProduct));
513 sprintfW(keypath,szUninstall_fmt,szProduct);
515 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
518 UINT MSIREG_OpenProductKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
519 HKEY *key, BOOL create)
521 UINT r;
522 LPWSTR usersid;
523 HKEY root = HKEY_LOCAL_MACHINE;
524 WCHAR squished_pc[GUID_SIZE];
525 WCHAR keypath[MAX_PATH];
527 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create);
529 if (!squash_guid(szProduct, squished_pc))
530 return ERROR_FUNCTION_FAILED;
532 TRACE("squished (%s)\n", debugstr_w(squished_pc));
534 if (context == MSIINSTALLCONTEXT_MACHINE)
536 sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc);
538 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
540 root = HKEY_CURRENT_USER;
541 sprintfW(keypath, szUserProduct_fmt, squished_pc);
543 else
545 r = get_user_sid(&usersid);
546 if (r != ERROR_SUCCESS || !usersid)
548 ERR("Failed to retrieve user SID: %d\n", r);
549 return r;
552 sprintfW(keypath, szInstaller_LocalManagedProd_fmt, usersid, squished_pc);
553 LocalFree(usersid);
556 if (create)
557 return RegCreateKeyW(root, keypath, key);
559 return RegOpenKeyW(root, keypath, key);
562 UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct)
564 WCHAR squished_pc[GUID_SIZE];
565 WCHAR keypath[0x200];
567 TRACE("%s\n",debugstr_w(szProduct));
568 if (!squash_guid(szProduct,squished_pc))
569 return ERROR_FUNCTION_FAILED;
570 TRACE("squished (%s)\n", debugstr_w(squished_pc));
572 sprintfW(keypath,szUserProduct_fmt,squished_pc);
574 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
577 UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
579 UINT rc;
580 WCHAR squished_pc[GUID_SIZE];
581 WCHAR keypath[0x200];
583 TRACE("%s\n",debugstr_w(szPatch));
584 if (!squash_guid(szPatch,squished_pc))
585 return ERROR_FUNCTION_FAILED;
586 TRACE("squished (%s)\n", debugstr_w(squished_pc));
588 sprintfW(keypath,szUserPatch_fmt,squished_pc);
590 if (create)
591 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
592 else
593 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
595 return rc;
598 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
599 HKEY *key, BOOL create)
601 UINT r;
602 LPWSTR usersid;
603 HKEY root = HKEY_LOCAL_MACHINE;
604 WCHAR squished_pc[GUID_SIZE];
605 WCHAR keypath[MAX_PATH];
607 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create);
609 if (!squash_guid(szProduct, squished_pc))
610 return ERROR_FUNCTION_FAILED;
612 TRACE("squished (%s)\n", debugstr_w(squished_pc));
614 if (context == MSIINSTALLCONTEXT_MACHINE)
616 sprintfW(keypath, szInstaller_LocalClassesFeat_fmt, squished_pc);
618 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
620 root = HKEY_CURRENT_USER;
621 sprintfW(keypath, szUserFeatures_fmt, squished_pc);
623 else
625 r = get_user_sid(&usersid);
626 if (r != ERROR_SUCCESS || !usersid)
628 ERR("Failed to retrieve user SID: %d\n", r);
629 return r;
632 sprintfW(keypath, szInstaller_LocalManagedFeat_fmt, usersid, squished_pc);
633 LocalFree(usersid);
636 if (create)
637 return RegCreateKeyW(root, keypath, key);
639 return RegOpenKeyW(root, keypath, key);
642 UINT MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct)
644 WCHAR squished_pc[GUID_SIZE];
645 WCHAR keypath[0x200];
647 TRACE("%s\n",debugstr_w(szProduct));
648 if (!squash_guid(szProduct,squished_pc))
649 return ERROR_FUNCTION_FAILED;
650 TRACE("squished (%s)\n", debugstr_w(squished_pc));
652 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
653 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
656 UINT MSIREG_OpenInstallerFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
658 UINT rc;
659 WCHAR squished_pc[GUID_SIZE];
660 WCHAR keypath[0x200];
662 TRACE("%s\n",debugstr_w(szProduct));
663 if (!squash_guid(szProduct,squished_pc))
664 return ERROR_FUNCTION_FAILED;
665 TRACE("squished (%s)\n", debugstr_w(squished_pc));
667 sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
669 if (create)
670 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
671 else
672 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
674 return rc;
677 UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
678 HKEY *key, BOOL create)
680 UINT r;
681 LPWSTR usersid;
682 WCHAR squished_pc[GUID_SIZE];
683 WCHAR keypath[0x200];
685 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create);
687 if (!squash_guid(szProduct, squished_pc))
688 return ERROR_FUNCTION_FAILED;
690 TRACE("squished (%s)\n", debugstr_w(squished_pc));
692 if (context == MSIINSTALLCONTEXT_MACHINE)
694 sprintfW(keypath, szUserDataFeatures_fmt, szLocalSid, squished_pc);
696 else
698 r = get_user_sid(&usersid);
699 if (r != ERROR_SUCCESS || !usersid)
701 ERR("Failed to retrieve user SID: %d\n", r);
702 return r;
705 sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc);
706 LocalFree(usersid);
709 if (create)
710 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
712 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
715 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
717 UINT rc;
718 WCHAR squished_cc[GUID_SIZE];
719 WCHAR keypath[0x200];
721 TRACE("%s\n",debugstr_w(szComponent));
722 if (!squash_guid(szComponent,squished_cc))
723 return ERROR_FUNCTION_FAILED;
724 TRACE("squished (%s)\n", debugstr_w(squished_cc));
726 sprintfW(keypath,szUser_Components_fmt,squished_cc);
728 if (create)
729 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
730 else
731 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
733 return rc;
736 UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid,
737 HKEY *key, BOOL create)
739 UINT rc;
740 WCHAR comp[GUID_SIZE];
741 WCHAR keypath[0x200];
742 LPWSTR usersid;
744 TRACE("%s\n", debugstr_w(szComponent));
745 if (!squash_guid(szComponent, comp))
746 return ERROR_FUNCTION_FAILED;
747 TRACE("squished (%s)\n", debugstr_w(comp));
749 if (!szUserSid)
751 rc = get_user_sid(&usersid);
752 if (rc != ERROR_SUCCESS || !usersid)
754 ERR("Failed to retrieve user SID: %d\n", rc);
755 return rc;
758 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
759 LocalFree(usersid);
761 else
762 sprintfW(keypath, szUserDataComp_fmt, szUserSid, comp);
764 if (create)
765 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
766 else
767 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
769 return rc;
772 UINT MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid)
774 UINT rc;
775 WCHAR comp[GUID_SIZE];
776 WCHAR keypath[0x200];
777 LPWSTR usersid;
779 TRACE("%s\n", debugstr_w(szComponent));
780 if (!squash_guid(szComponent, comp))
781 return ERROR_FUNCTION_FAILED;
782 TRACE("squished (%s)\n", debugstr_w(comp));
784 if (!szUserSid)
786 rc = get_user_sid(&usersid);
787 if (rc != ERROR_SUCCESS || !usersid)
789 ERR("Failed to retrieve user SID: %d\n", rc);
790 return rc;
793 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
794 LocalFree(usersid);
796 else
797 sprintfW(keypath, szUserDataComp_fmt, szUserSid, comp);
799 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
802 UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContext,
803 LPCWSTR szUserSid, HKEY *key, BOOL create)
805 UINT rc;
806 WCHAR squished_pc[GUID_SIZE];
807 WCHAR keypath[0x200];
808 LPWSTR usersid;
810 TRACE("%s\n", debugstr_w(szProduct));
811 if (!squash_guid(szProduct, squished_pc))
812 return ERROR_FUNCTION_FAILED;
813 TRACE("squished (%s)\n", debugstr_w(squished_pc));
815 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
816 sprintfW(keypath, szUserDataProd_fmt, szLocalSid, squished_pc);
817 else if (szUserSid)
818 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
819 else
821 rc = get_user_sid(&usersid);
822 if (rc != ERROR_SUCCESS || !usersid)
824 ERR("Failed to retrieve user SID: %d\n", rc);
825 return rc;
828 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
829 LocalFree(usersid);
832 if (create)
833 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
834 else
835 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
837 return rc;
840 UINT MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch, MSIINSTALLCONTEXT dwContext,
841 HKEY *key, BOOL create)
843 UINT rc;
844 WCHAR squished_patch[GUID_SIZE];
845 WCHAR keypath[0x200];
846 LPWSTR usersid;
848 TRACE("%s\n", debugstr_w(szPatch));
849 if (!squash_guid(szPatch, squished_patch))
850 return ERROR_FUNCTION_FAILED;
851 TRACE("squished (%s)\n", debugstr_w(squished_patch));
853 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
854 sprintfW(keypath, szUserDataPatch_fmt, szLocalSid, squished_patch);
855 else
857 rc = get_user_sid(&usersid);
858 if (rc != ERROR_SUCCESS || !usersid)
860 ERR("Failed to retrieve user SID: %d\n", rc);
861 return rc;
864 sprintfW(keypath, szUserDataPatch_fmt, usersid, squished_patch);
865 LocalFree(usersid);
868 if (create)
869 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
871 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
874 UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, LPCWSTR szUserSID,
875 HKEY *key, BOOL create)
877 UINT rc;
878 WCHAR squished_pc[GUID_SIZE];
879 WCHAR keypath[0x200];
881 TRACE("%s\n", debugstr_w(szProduct));
882 if (!squash_guid(szProduct, squished_pc))
883 return ERROR_FUNCTION_FAILED;
884 TRACE("squished (%s)\n", debugstr_w(squished_pc));
886 sprintfW(keypath, szInstallProperties_fmt, szUserSID, squished_pc);
888 if (create)
889 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
890 else
891 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
893 return rc;
896 UINT MSIREG_OpenCurrentUserInstallProps(LPCWSTR szProduct, HKEY *key,
897 BOOL create)
899 UINT rc;
900 LPWSTR usersid;
902 rc = get_user_sid(&usersid);
903 if (rc != ERROR_SUCCESS || !usersid)
905 ERR("Failed to retrieve user SID: %d\n", rc);
906 return rc;
909 rc = MSIREG_OpenInstallProps(szProduct, usersid, key, create);
911 LocalFree(usersid);
912 return rc;
915 UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)
917 UINT rc;
918 WCHAR squished_pc[GUID_SIZE];
919 WCHAR keypath[0x200];
920 LPWSTR usersid;
922 TRACE("%s\n", debugstr_w(szProduct));
923 if (!squash_guid(szProduct, squished_pc))
924 return ERROR_FUNCTION_FAILED;
925 TRACE("squished (%s)\n", debugstr_w(squished_pc));
927 rc = get_user_sid(&usersid);
928 if (rc != ERROR_SUCCESS || !usersid)
930 ERR("Failed to retrieve user SID: %d\n", rc);
931 return rc;
934 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
936 LocalFree(usersid);
937 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
940 UINT MSIREG_DeleteProductKey(LPCWSTR szProduct)
942 WCHAR squished_pc[GUID_SIZE];
943 WCHAR keypath[0x200];
945 TRACE("%s\n", debugstr_w(szProduct));
946 if (!squash_guid(szProduct, squished_pc))
947 return ERROR_FUNCTION_FAILED;
948 TRACE("squished (%s)\n", debugstr_w(squished_pc));
950 sprintfW(keypath, szInstaller_Products_fmt, squished_pc);
952 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
955 UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
957 UINT rc;
958 WCHAR squished_pc[GUID_SIZE];
959 WCHAR keypath[0x200];
961 TRACE("%s\n",debugstr_w(szPatch));
962 if (!squash_guid(szPatch,squished_pc))
963 return ERROR_FUNCTION_FAILED;
964 TRACE("squished (%s)\n", debugstr_w(squished_pc));
966 sprintfW(keypath,szInstaller_Patches_fmt,squished_pc);
968 if (create)
969 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
970 else
971 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
973 return rc;
976 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
978 UINT rc;
979 WCHAR squished_pc[GUID_SIZE];
980 WCHAR keypath[0x200];
982 TRACE("%s\n",debugstr_w(szUpgradeCode));
983 if (!squash_guid(szUpgradeCode,squished_pc))
984 return ERROR_FUNCTION_FAILED;
985 TRACE("squished (%s)\n", debugstr_w(squished_pc));
987 sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
989 if (create)
990 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
991 else
992 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
994 return rc;
997 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
999 UINT rc;
1000 WCHAR squished_pc[GUID_SIZE];
1001 WCHAR keypath[0x200];
1003 TRACE("%s\n",debugstr_w(szUpgradeCode));
1004 if (!squash_guid(szUpgradeCode,squished_pc))
1005 return ERROR_FUNCTION_FAILED;
1006 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1008 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
1010 if (create)
1011 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
1012 else
1013 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
1015 return rc;
1018 UINT MSIREG_DeleteUserUpgradeCodesKey(LPCWSTR szUpgradeCode)
1020 WCHAR squished_pc[GUID_SIZE];
1021 WCHAR keypath[0x200];
1023 TRACE("%s\n",debugstr_w(szUpgradeCode));
1024 if (!squash_guid(szUpgradeCode,squished_pc))
1025 return ERROR_FUNCTION_FAILED;
1026 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1028 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
1030 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
1033 UINT MSIREG_DeleteLocalClassesProductKey(LPCWSTR szProductCode)
1035 WCHAR squished_pc[GUID_SIZE];
1036 WCHAR keypath[0x200];
1038 TRACE("%s\n", debugstr_w(szProductCode));
1040 if (!squash_guid(szProductCode, squished_pc))
1041 return ERROR_FUNCTION_FAILED;
1043 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1045 sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc);
1047 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
1050 UINT MSIREG_DeleteLocalClassesFeaturesKey(LPCWSTR szProductCode)
1052 WCHAR squished_pc[GUID_SIZE];
1053 WCHAR keypath[0x200];
1055 TRACE("%s\n", debugstr_w(szProductCode));
1057 if (!squash_guid(szProductCode, squished_pc))
1058 return ERROR_FUNCTION_FAILED;
1060 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1062 sprintfW(keypath, szInstaller_LocalClassesFeat_fmt, squished_pc);
1064 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
1067 UINT MSIREG_OpenClassesUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
1069 WCHAR squished_pc[GUID_SIZE];
1070 WCHAR keypath[0x200];
1072 TRACE("%s\n", debugstr_w(szUpgradeCode));
1073 if (!squash_guid(szUpgradeCode, squished_pc))
1074 return ERROR_FUNCTION_FAILED;
1075 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1077 sprintfW(keypath, szInstaller_ClassesUpgrade_fmt, squished_pc);
1079 if (create)
1080 return RegCreateKeyW(HKEY_CLASSES_ROOT, keypath, key);
1082 return RegOpenKeyW(HKEY_CLASSES_ROOT, keypath, key);
1085 /*************************************************************************
1086 * MsiDecomposeDescriptorW [MSI.@]
1088 * Decomposes an MSI descriptor into product, feature and component parts.
1089 * An MSI descriptor is a string of the form:
1090 * [base 85 guid] [feature code] '>' [base 85 guid]
1092 * PARAMS
1093 * szDescriptor [I] the descriptor to decompose
1094 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
1095 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
1096 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
1097 * pUsed [O] the length of the descriptor
1099 * RETURNS
1100 * ERROR_SUCCESS if everything worked correctly
1101 * ERROR_INVALID_PARAMETER if the descriptor was invalid
1104 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
1105 LPWSTR szFeature, LPWSTR szComponent, LPDWORD pUsed )
1107 UINT r, len;
1108 LPWSTR p;
1109 GUID product, component;
1111 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
1112 szFeature, szComponent, pUsed);
1114 r = decode_base85_guid( szDescriptor, &product );
1115 if( !r )
1116 return ERROR_INVALID_PARAMETER;
1118 TRACE("product %s\n", debugstr_guid( &product ));
1120 p = strchrW(&szDescriptor[20],'>');
1121 if( !p )
1122 return ERROR_INVALID_PARAMETER;
1124 len = (p - &szDescriptor[20]);
1125 if( len > MAX_FEATURE_CHARS )
1126 return ERROR_INVALID_PARAMETER;
1128 TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len ));
1130 r = decode_base85_guid( p+1, &component );
1131 if( !r )
1132 return ERROR_INVALID_PARAMETER;
1134 TRACE("component %s\n", debugstr_guid( &component ));
1136 if (szProduct)
1137 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
1138 if (szComponent)
1139 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
1140 if (szFeature)
1142 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
1143 szFeature[len] = 0;
1145 len = ( &p[21] - szDescriptor );
1147 TRACE("length = %d\n", len);
1148 *pUsed = len;
1150 return ERROR_SUCCESS;
1153 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
1154 LPSTR szFeature, LPSTR szComponent, LPDWORD pUsed )
1156 WCHAR product[MAX_FEATURE_CHARS+1];
1157 WCHAR feature[MAX_FEATURE_CHARS+1];
1158 WCHAR component[MAX_FEATURE_CHARS+1];
1159 LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
1160 UINT r;
1162 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
1163 szFeature, szComponent, pUsed);
1165 str = strdupAtoW( szDescriptor );
1166 if( szDescriptor && !str )
1167 return ERROR_OUTOFMEMORY;
1169 if (szProduct)
1170 p = product;
1171 if (szFeature)
1172 f = feature;
1173 if (szComponent)
1174 c = component;
1176 r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
1178 if (r == ERROR_SUCCESS)
1180 WideCharToMultiByte( CP_ACP, 0, p, -1,
1181 szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
1182 WideCharToMultiByte( CP_ACP, 0, f, -1,
1183 szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
1184 WideCharToMultiByte( CP_ACP, 0, c, -1,
1185 szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
1188 msi_free( str );
1190 return r;
1193 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
1195 DWORD r;
1196 WCHAR szwGuid[GUID_SIZE];
1198 TRACE("%d %p\n", index, lpguid);
1200 if (NULL == lpguid)
1201 return ERROR_INVALID_PARAMETER;
1202 r = MsiEnumProductsW(index, szwGuid);
1203 if( r == ERROR_SUCCESS )
1204 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1206 return r;
1209 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
1211 HKEY hkeyProducts = 0;
1212 DWORD r;
1213 WCHAR szKeyName[SQUISH_GUID_SIZE];
1215 TRACE("%d %p\n", index, lpguid);
1217 if (NULL == lpguid)
1218 return ERROR_INVALID_PARAMETER;
1220 r = RegCreateKeyW(HKEY_LOCAL_MACHINE, szInstaller_Products, &hkeyProducts);
1221 if( r != ERROR_SUCCESS )
1222 return ERROR_NO_MORE_ITEMS;
1224 r = RegEnumKeyW(hkeyProducts, index, szKeyName, SQUISH_GUID_SIZE);
1225 if( r == ERROR_SUCCESS )
1226 unsquash_guid(szKeyName, lpguid);
1227 RegCloseKey(hkeyProducts);
1229 return r;
1232 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
1233 LPSTR szFeature, LPSTR szParent)
1235 DWORD r;
1236 WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
1237 LPWSTR szwProduct = NULL;
1239 TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent);
1241 if( szProduct )
1243 szwProduct = strdupAtoW( szProduct );
1244 if( !szwProduct )
1245 return ERROR_OUTOFMEMORY;
1248 r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
1249 if( r == ERROR_SUCCESS )
1251 WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
1252 szFeature, GUID_SIZE, NULL, NULL);
1253 WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
1254 szParent, GUID_SIZE, NULL, NULL);
1257 msi_free( szwProduct);
1259 return r;
1262 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
1263 LPWSTR szFeature, LPWSTR szParent)
1265 HKEY hkeyProduct = 0;
1266 DWORD r, sz;
1268 TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
1270 if( !szProduct )
1271 return ERROR_INVALID_PARAMETER;
1273 r = MSIREG_OpenInstallerFeaturesKey(szProduct,&hkeyProduct,FALSE);
1274 if( r != ERROR_SUCCESS )
1275 return ERROR_NO_MORE_ITEMS;
1277 sz = GUID_SIZE;
1278 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
1279 RegCloseKey(hkeyProduct);
1281 return r;
1284 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
1286 DWORD r;
1287 WCHAR szwGuid[GUID_SIZE];
1289 TRACE("%d %p\n", index, lpguid);
1291 r = MsiEnumComponentsW(index, szwGuid);
1292 if( r == ERROR_SUCCESS )
1293 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1295 return r;
1298 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
1300 HKEY hkeyComponents = 0;
1301 DWORD r;
1302 WCHAR szKeyName[SQUISH_GUID_SIZE];
1304 TRACE("%d %p\n", index, lpguid);
1306 r = RegCreateKeyW(HKEY_LOCAL_MACHINE, szInstaller_Components, &hkeyComponents);
1307 if( r != ERROR_SUCCESS )
1308 return ERROR_NO_MORE_ITEMS;
1310 r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
1311 if( r == ERROR_SUCCESS )
1312 unsquash_guid(szKeyName, lpguid);
1313 RegCloseKey(hkeyComponents);
1315 return r;
1318 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
1320 DWORD r;
1321 WCHAR szwProduct[GUID_SIZE];
1322 LPWSTR szwComponent = NULL;
1324 TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
1326 if ( !szProduct )
1327 return ERROR_INVALID_PARAMETER;
1329 if( szComponent )
1331 szwComponent = strdupAtoW( szComponent );
1332 if( !szwComponent )
1333 return ERROR_OUTOFMEMORY;
1336 r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
1337 if( r == ERROR_SUCCESS )
1339 WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
1340 szProduct, GUID_SIZE, NULL, NULL);
1343 msi_free( szwComponent);
1345 return r;
1348 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
1350 HKEY hkeyComp = 0;
1351 DWORD r, sz;
1352 WCHAR szValName[SQUISH_GUID_SIZE];
1354 TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct);
1356 if (!szComponent || !*szComponent || !szProduct)
1357 return ERROR_INVALID_PARAMETER;
1359 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkeyComp, FALSE) != ERROR_SUCCESS &&
1360 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkeyComp, FALSE) != ERROR_SUCCESS)
1361 return ERROR_UNKNOWN_COMPONENT;
1363 /* see if there are any products at all */
1364 sz = SQUISH_GUID_SIZE;
1365 r = RegEnumValueW(hkeyComp, 0, szValName, &sz, NULL, NULL, NULL, NULL);
1366 if (r != ERROR_SUCCESS)
1368 RegCloseKey(hkeyComp);
1370 if (index != 0)
1371 return ERROR_INVALID_PARAMETER;
1373 return ERROR_UNKNOWN_COMPONENT;
1376 sz = SQUISH_GUID_SIZE;
1377 r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
1378 if( r == ERROR_SUCCESS )
1379 unsquash_guid(szValName, szProduct);
1381 RegCloseKey(hkeyComp);
1383 return r;
1386 static UINT MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
1387 awstring *lpQualBuf, LPDWORD pcchQual,
1388 awstring *lpAppBuf, LPDWORD pcchAppBuf )
1390 DWORD name_sz, val_sz, name_max, val_max, type, ofs;
1391 LPWSTR name = NULL, val = NULL;
1392 UINT r, r2;
1393 HKEY key;
1395 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1396 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
1398 if (!szComponent)
1399 return ERROR_INVALID_PARAMETER;
1401 r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
1402 if (r != ERROR_SUCCESS)
1403 return ERROR_UNKNOWN_COMPONENT;
1405 /* figure out how big the name is we want to return */
1406 name_max = 0x10;
1407 r = ERROR_OUTOFMEMORY;
1408 name = msi_alloc( name_max * sizeof(WCHAR) );
1409 if (!name)
1410 goto end;
1412 val_max = 0x10;
1413 r = ERROR_OUTOFMEMORY;
1414 val = msi_alloc( val_max );
1415 if (!val)
1416 goto end;
1418 /* loop until we allocate enough memory */
1419 while (1)
1421 name_sz = name_max;
1422 val_sz = val_max;
1423 r = RegEnumValueW( key, iIndex, name, &name_sz,
1424 NULL, &type, (LPBYTE)val, &val_sz );
1425 if (r == ERROR_SUCCESS)
1426 break;
1427 if (r != ERROR_MORE_DATA)
1428 goto end;
1430 if (type != REG_MULTI_SZ)
1432 ERR("component data has wrong type (%d)\n", type);
1433 goto end;
1436 r = ERROR_OUTOFMEMORY;
1437 if ((name_sz+1) >= name_max)
1439 name_max *= 2;
1440 msi_free( name );
1441 name = msi_alloc( name_max * sizeof (WCHAR) );
1442 if (!name)
1443 goto end;
1444 continue;
1446 if (val_sz > val_max)
1448 val_max = val_sz + sizeof (WCHAR);
1449 msi_free( val );
1450 val = msi_alloc( val_max * sizeof (WCHAR) );
1451 if (!val)
1452 goto end;
1453 continue;
1455 ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
1456 goto end;
1459 ofs = 0;
1460 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
1461 if (r != ERROR_SUCCESS)
1462 goto end;
1464 TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
1466 r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
1467 r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
1469 if (r2 != ERROR_SUCCESS)
1470 r = r2;
1472 end:
1473 msi_free(val);
1474 msi_free(name);
1475 RegCloseKey(key);
1477 return r;
1480 /*************************************************************************
1481 * MsiEnumComponentQualifiersA [MSI.@]
1483 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
1484 LPSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1485 LPSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1487 awstring qual, appdata;
1488 LPWSTR comp;
1489 UINT r;
1491 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex,
1492 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1493 pcchApplicationDataBuf);
1495 comp = strdupAtoW( szComponent );
1496 if (szComponent && !comp)
1497 return ERROR_OUTOFMEMORY;
1499 qual.unicode = FALSE;
1500 qual.str.a = lpQualifierBuf;
1502 appdata.unicode = FALSE;
1503 appdata.str.a = lpApplicationDataBuf;
1505 r = MSI_EnumComponentQualifiers( comp, iIndex,
1506 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1507 msi_free( comp );
1508 return r;
1511 /*************************************************************************
1512 * MsiEnumComponentQualifiersW [MSI.@]
1514 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
1515 LPWSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1516 LPWSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1518 awstring qual, appdata;
1520 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1521 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1522 pcchApplicationDataBuf);
1524 qual.unicode = TRUE;
1525 qual.str.w = lpQualifierBuf;
1527 appdata.unicode = TRUE;
1528 appdata.str.w = lpApplicationDataBuf;
1530 return MSI_EnumComponentQualifiers( szComponent, iIndex,
1531 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1534 /*************************************************************************
1535 * MsiEnumRelatedProductsW [MSI.@]
1538 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
1539 DWORD iProductIndex, LPWSTR lpProductBuf)
1541 UINT r;
1542 HKEY hkey;
1543 DWORD dwSize = SQUISH_GUID_SIZE;
1544 WCHAR szKeyName[SQUISH_GUID_SIZE];
1546 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved,
1547 iProductIndex, lpProductBuf);
1549 if (NULL == szUpgradeCode)
1550 return ERROR_INVALID_PARAMETER;
1551 if (NULL == lpProductBuf)
1552 return ERROR_INVALID_PARAMETER;
1554 r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1555 if (r != ERROR_SUCCESS)
1556 return ERROR_NO_MORE_ITEMS;
1558 r = RegEnumValueW(hkey, iProductIndex, szKeyName, &dwSize, NULL, NULL, NULL, NULL);
1559 if( r == ERROR_SUCCESS )
1560 unsquash_guid(szKeyName, lpProductBuf);
1561 RegCloseKey(hkey);
1563 return r;
1566 /*************************************************************************
1567 * MsiEnumRelatedProductsA [MSI.@]
1570 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1571 DWORD iProductIndex, LPSTR lpProductBuf)
1573 LPWSTR szwUpgradeCode = NULL;
1574 WCHAR productW[GUID_SIZE];
1575 UINT r;
1577 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1578 iProductIndex, lpProductBuf);
1580 if (szUpgradeCode)
1582 szwUpgradeCode = strdupAtoW( szUpgradeCode );
1583 if( !szwUpgradeCode )
1584 return ERROR_OUTOFMEMORY;
1587 r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1588 iProductIndex, productW );
1589 if (r == ERROR_SUCCESS)
1591 WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1592 lpProductBuf, GUID_SIZE, NULL, NULL );
1594 msi_free( szwUpgradeCode);
1595 return r;
1598 /***********************************************************************
1599 * MsiEnumPatchesExA [MSI.@]
1601 UINT WINAPI MsiEnumPatchesExA(LPCSTR szProductCode, LPCSTR szUserSid,
1602 DWORD dwContext, DWORD dwFilter, DWORD dwIndex, LPSTR szPatchCode,
1603 LPSTR szTargetProductCode, MSIINSTALLCONTEXT *pdwTargetProductContext,
1604 LPSTR szTargetUserSid, LPDWORD pcchTargetUserSid)
1606 LPWSTR prodcode = NULL;
1607 LPWSTR usersid = NULL;
1608 LPWSTR targsid = NULL;
1609 WCHAR patch[GUID_SIZE];
1610 WCHAR targprod[GUID_SIZE];
1611 DWORD len;
1612 UINT r;
1614 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
1615 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext, dwFilter,
1616 dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext,
1617 szTargetUserSid, pcchTargetUserSid);
1619 if (szTargetUserSid && !pcchTargetUserSid)
1620 return ERROR_INVALID_PARAMETER;
1622 if (szProductCode) prodcode = strdupAtoW(szProductCode);
1623 if (szUserSid) usersid = strdupAtoW(szUserSid);
1625 r = MsiEnumPatchesExW(prodcode, usersid, dwContext, dwFilter, dwIndex,
1626 patch, targprod, pdwTargetProductContext,
1627 NULL, &len);
1628 if (r != ERROR_SUCCESS)
1629 goto done;
1631 WideCharToMultiByte(CP_ACP, 0, patch, -1, szPatchCode,
1632 GUID_SIZE, NULL, NULL);
1633 WideCharToMultiByte(CP_ACP, 0, targprod, -1, szTargetProductCode,
1634 GUID_SIZE, NULL, NULL);
1636 if (!szTargetUserSid)
1638 if (pcchTargetUserSid)
1639 *pcchTargetUserSid = len;
1641 goto done;
1644 targsid = msi_alloc(++len * sizeof(WCHAR));
1645 if (!targsid)
1647 r = ERROR_OUTOFMEMORY;
1648 goto done;
1651 r = MsiEnumPatchesExW(prodcode, usersid, dwContext, dwFilter, dwIndex,
1652 patch, targprod, pdwTargetProductContext,
1653 targsid, &len);
1654 if (r != ERROR_SUCCESS || !szTargetUserSid)
1655 goto done;
1657 WideCharToMultiByte(CP_ACP, 0, targsid, -1, szTargetUserSid,
1658 *pcchTargetUserSid, NULL, NULL);
1660 len = lstrlenW(targsid);
1661 if (*pcchTargetUserSid < len + 1)
1663 r = ERROR_MORE_DATA;
1664 *pcchTargetUserSid = len * sizeof(WCHAR);
1666 else
1667 *pcchTargetUserSid = len;
1669 done:
1670 msi_free(prodcode);
1671 msi_free(usersid);
1672 msi_free(targsid);
1674 return r;
1677 static UINT msi_get_patch_state(LPCWSTR prodcode, LPCWSTR usersid,
1678 LPWSTR patch, MSIPATCHSTATE *state)
1680 DWORD type, val, size;
1681 HKEY prod, hkey = 0;
1682 HKEY udpatch = 0;
1683 LONG res;
1684 UINT r = ERROR_NO_MORE_ITEMS;
1686 static const WCHAR szPatches[] = {'P','a','t','c','h','e','s',0};
1687 static const WCHAR szState[] = {'S','t','a','t','e',0};
1689 *state = MSIPATCHSTATE_INVALID;
1691 /* FIXME: usersid might not be current user */
1692 r = MSIREG_OpenUserDataProductKey(prodcode, MSIINSTALLCONTEXT_USERUNMANAGED,
1693 NULL, &prod, FALSE);
1694 if (r != ERROR_SUCCESS)
1695 return ERROR_NO_MORE_ITEMS;
1697 res = RegOpenKeyExW(prod, szPatches, 0, KEY_READ, &hkey);
1698 if (res != ERROR_SUCCESS)
1699 goto done;
1701 res = RegOpenKeyExW(hkey, patch, 0, KEY_READ, &udpatch);
1702 if (res != ERROR_SUCCESS)
1703 goto done;
1705 size = sizeof(DWORD);
1706 res = RegGetValueW(udpatch, NULL, szState, RRF_RT_DWORD, &type, &val, &size);
1707 if (res != ERROR_SUCCESS ||
1708 val < MSIPATCHSTATE_APPLIED || val > MSIPATCHSTATE_REGISTERED)
1710 r = ERROR_BAD_CONFIGURATION;
1711 goto done;
1714 *state = val;
1715 r = ERROR_SUCCESS;
1717 done:
1718 RegCloseKey(udpatch);
1719 RegCloseKey(hkey);
1720 RegCloseKey(prod);
1722 return r;
1725 static UINT msi_check_product_patches(LPCWSTR prodcode, LPCWSTR usersid,
1726 MSIINSTALLCONTEXT context, DWORD filter, DWORD index, DWORD *idx,
1727 LPWSTR patch, LPWSTR targetprod, MSIINSTALLCONTEXT *targetctx,
1728 LPWSTR targetsid, DWORD *sidsize, LPWSTR *transforms)
1730 MSIPATCHSTATE state;
1731 LPWSTR ptr, patches = NULL;
1732 HKEY prod, patchkey = 0;
1733 HKEY localprod = 0, localpatch = 0;
1734 DWORD type, size;
1735 LONG res;
1736 UINT temp, r = ERROR_NO_MORE_ITEMS;
1738 static const WCHAR szPatches[] = {'P','a','t','c','h','e','s',0};
1739 static const WCHAR szState[] = {'S','t','a','t','e',0};
1740 static const WCHAR szEmpty[] = {0};
1742 if (MSIREG_OpenProductKey(prodcode, context, &prod, FALSE) != ERROR_SUCCESS)
1743 return ERROR_NO_MORE_ITEMS;
1745 size = 0;
1746 res = RegGetValueW(prod, szPatches, szPatches, RRF_RT_ANY, &type, NULL,
1747 &size);
1748 if (res != ERROR_SUCCESS)
1749 goto done;
1751 if (type != REG_MULTI_SZ)
1753 r = ERROR_BAD_CONFIGURATION;
1754 goto done;
1757 patches = msi_alloc(size);
1758 if (!patches)
1760 r = ERROR_OUTOFMEMORY;
1761 goto done;
1764 res = RegGetValueW(prod, szPatches, szPatches, RRF_RT_ANY, &type,
1765 patches, &size);
1766 if (res != ERROR_SUCCESS)
1767 goto done;
1769 ptr = patches;
1770 for (ptr = patches; *ptr && r == ERROR_NO_MORE_ITEMS; ptr += lstrlenW(ptr))
1772 if (!unsquash_guid(ptr, patch))
1774 r = ERROR_BAD_CONFIGURATION;
1775 goto done;
1778 size = 0;
1779 res = RegGetValueW(prod, szPatches, ptr, RRF_RT_REG_SZ,
1780 &type, NULL, &size);
1781 if (res != ERROR_SUCCESS)
1782 continue;
1784 if (transforms)
1786 *transforms = msi_alloc(size);
1787 if (!*transforms)
1789 r = ERROR_OUTOFMEMORY;
1790 goto done;
1793 res = RegGetValueW(prod, szPatches, ptr, RRF_RT_REG_SZ,
1794 &type, *transforms, &size);
1795 if (res != ERROR_SUCCESS)
1796 continue;
1799 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1801 if (!(filter & MSIPATCHSTATE_APPLIED))
1803 temp = msi_get_patch_state(prodcode, usersid, ptr, &state);
1804 if (temp == ERROR_BAD_CONFIGURATION)
1806 r = ERROR_BAD_CONFIGURATION;
1807 goto done;
1810 if (temp != ERROR_SUCCESS || !(filter & state))
1811 continue;
1814 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
1816 if (!(filter & MSIPATCHSTATE_APPLIED))
1818 temp = msi_get_patch_state(prodcode, usersid, ptr, &state);
1819 if (temp == ERROR_BAD_CONFIGURATION)
1821 r = ERROR_BAD_CONFIGURATION;
1822 goto done;
1825 if (temp != ERROR_SUCCESS || !(filter & state))
1826 continue;
1828 else
1830 temp = MSIREG_OpenUserDataPatchKey(patch, context,
1831 &patchkey, FALSE);
1832 RegCloseKey(patchkey);
1833 if (temp != ERROR_SUCCESS)
1834 continue;
1837 else if (context == MSIINSTALLCONTEXT_MACHINE)
1839 usersid = szEmpty;
1841 if (MSIREG_OpenUserDataProductKey(prodcode, context, NULL, &localprod, FALSE) == ERROR_SUCCESS &&
1842 RegOpenKeyExW(localprod, szPatches, 0, KEY_READ, &localpatch) == ERROR_SUCCESS &&
1843 RegOpenKeyExW(localpatch, ptr, 0, KEY_READ, &patchkey) == ERROR_SUCCESS)
1845 res = RegGetValueW(patchkey, NULL, szState, RRF_RT_REG_DWORD,
1846 &type, &state, &size);
1848 if (!(filter & state))
1849 res = ERROR_NO_MORE_ITEMS;
1851 RegCloseKey(patchkey);
1854 RegCloseKey(localpatch);
1855 RegCloseKey(localprod);
1857 if (res != ERROR_SUCCESS)
1858 continue;
1861 if (*idx < index)
1863 (*idx)++;
1864 continue;
1867 r = ERROR_SUCCESS;
1868 if (targetprod)
1869 lstrcpyW(targetprod, prodcode);
1871 if (targetctx)
1872 *targetctx = context;
1874 if (targetsid)
1876 lstrcpynW(targetsid, usersid, *sidsize);
1877 if (lstrlenW(usersid) >= *sidsize)
1878 r = ERROR_MORE_DATA;
1881 if (sidsize)
1883 *sidsize = lstrlenW(usersid);
1884 if (!targetsid)
1885 *sidsize *= sizeof(WCHAR);
1889 done:
1890 RegCloseKey(prod);
1891 msi_free(patches);
1893 return r;
1896 static UINT msi_enum_patches(LPCWSTR szProductCode, LPCWSTR szUserSid,
1897 DWORD dwContext, DWORD dwFilter, DWORD dwIndex, DWORD *idx,
1898 LPWSTR szPatchCode, LPWSTR szTargetProductCode,
1899 MSIINSTALLCONTEXT *pdwTargetProductContext, LPWSTR szTargetUserSid,
1900 LPDWORD pcchTargetUserSid, LPWSTR *szTransforms)
1902 UINT r;
1904 if (dwContext & MSIINSTALLCONTEXT_USERMANAGED)
1906 r = msi_check_product_patches(szProductCode, szUserSid,
1907 MSIINSTALLCONTEXT_USERMANAGED, dwFilter,
1908 dwIndex, idx, szPatchCode,
1909 szTargetProductCode,
1910 pdwTargetProductContext, szTargetUserSid,
1911 pcchTargetUserSid, szTransforms);
1912 if (r != ERROR_NO_MORE_ITEMS)
1913 goto done;
1916 if (dwContext & MSIINSTALLCONTEXT_USERUNMANAGED)
1918 r = msi_check_product_patches(szProductCode, szUserSid,
1919 MSIINSTALLCONTEXT_USERUNMANAGED, dwFilter,
1920 dwIndex, idx, szPatchCode,
1921 szTargetProductCode,
1922 pdwTargetProductContext, szTargetUserSid,
1923 pcchTargetUserSid, szTransforms);
1924 if (r != ERROR_NO_MORE_ITEMS)
1925 goto done;
1928 if (dwContext & MSIINSTALLCONTEXT_MACHINE)
1930 r = msi_check_product_patches(szProductCode, szUserSid,
1931 MSIINSTALLCONTEXT_MACHINE, dwFilter,
1932 dwIndex, idx, szPatchCode,
1933 szTargetProductCode,
1934 pdwTargetProductContext, szTargetUserSid,
1935 pcchTargetUserSid, szTransforms);
1936 if (r != ERROR_NO_MORE_ITEMS)
1937 goto done;
1940 done:
1941 return r;
1944 /***********************************************************************
1945 * MsiEnumPatchesExW [MSI.@]
1947 UINT WINAPI MsiEnumPatchesExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1948 DWORD dwContext, DWORD dwFilter, DWORD dwIndex, LPWSTR szPatchCode,
1949 LPWSTR szTargetProductCode, MSIINSTALLCONTEXT *pdwTargetProductContext,
1950 LPWSTR szTargetUserSid, LPDWORD pcchTargetUserSid)
1952 WCHAR squished_pc[GUID_SIZE];
1953 DWORD idx = 0;
1954 UINT r;
1956 static int last_index = 0;
1958 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
1959 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext, dwFilter,
1960 dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext,
1961 szTargetUserSid, pcchTargetUserSid);
1963 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1964 return ERROR_INVALID_PARAMETER;
1966 if (!lstrcmpW(szUserSid, szLocalSid))
1967 return ERROR_INVALID_PARAMETER;
1969 if (dwContext & MSIINSTALLCONTEXT_MACHINE && szUserSid)
1970 return ERROR_INVALID_PARAMETER;
1972 if (dwContext <= MSIINSTALLCONTEXT_NONE ||
1973 dwContext > MSIINSTALLCONTEXT_ALL)
1974 return ERROR_INVALID_PARAMETER;
1976 if (dwFilter <= MSIPATCHSTATE_INVALID || dwFilter > MSIPATCHSTATE_ALL)
1977 return ERROR_INVALID_PARAMETER;
1979 if (dwIndex && dwIndex - last_index != 1)
1980 return ERROR_INVALID_PARAMETER;
1982 if (dwIndex == 0)
1983 last_index = 0;
1985 r = msi_enum_patches(szProductCode, szUserSid, dwContext, dwFilter,
1986 dwIndex, &idx, szPatchCode, szTargetProductCode,
1987 pdwTargetProductContext, szTargetUserSid,
1988 pcchTargetUserSid, NULL);
1990 if (r == ERROR_SUCCESS)
1991 last_index = dwIndex;
1993 return r;
1996 /***********************************************************************
1997 * MsiEnumPatchesA [MSI.@]
1999 UINT WINAPI MsiEnumPatchesA(LPCSTR szProduct, DWORD iPatchIndex,
2000 LPSTR lpPatchBuf, LPSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
2002 LPWSTR product, transforms = NULL;
2003 WCHAR patch[GUID_SIZE];
2004 DWORD len;
2005 UINT r;
2007 TRACE("(%s %d %p %p %p)\n", debugstr_a(szProduct), iPatchIndex,
2008 lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
2010 if (!szProduct || !lpPatchBuf || !lpTransformsBuf || !pcchTransformsBuf)
2011 return ERROR_INVALID_PARAMETER;
2013 product = strdupAtoW(szProduct);
2014 if (!product)
2015 return ERROR_OUTOFMEMORY;
2017 len = 0;
2018 r = MsiEnumPatchesW(product, iPatchIndex, patch, patch, &len);
2019 if (r != ERROR_MORE_DATA)
2020 goto done;
2022 transforms = msi_alloc(len);
2023 if (!transforms)
2025 r = ERROR_OUTOFMEMORY;
2026 goto done;
2029 r = MsiEnumPatchesW(product, iPatchIndex, patch, transforms, &len);
2030 if (r != ERROR_SUCCESS)
2031 goto done;
2033 WideCharToMultiByte(CP_ACP, 0, patch, -1, lpPatchBuf,
2034 GUID_SIZE, NULL, NULL);
2036 WideCharToMultiByte(CP_ACP, 0, transforms, -1, lpTransformsBuf,
2037 *pcchTransformsBuf - 1, NULL, NULL);
2039 len = lstrlenW(transforms);
2040 if (*pcchTransformsBuf < len + 1)
2042 r = ERROR_MORE_DATA;
2043 lpTransformsBuf[*pcchTransformsBuf - 1] = '\0';
2044 *pcchTransformsBuf = len * sizeof(WCHAR);
2046 else
2047 *pcchTransformsBuf = len;
2049 done:
2050 msi_free(transforms);
2051 msi_free(product);
2053 return r;
2056 /***********************************************************************
2057 * MsiEnumPatchesW [MSI.@]
2059 UINT WINAPI MsiEnumPatchesW(LPCWSTR szProduct, DWORD iPatchIndex,
2060 LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
2062 WCHAR squished_pc[GUID_SIZE];
2063 LPWSTR transforms = NULL;
2064 HKEY prod;
2065 DWORD idx = 0;
2066 UINT r;
2068 TRACE("(%s %d %p %p %p)\n", debugstr_w(szProduct), iPatchIndex,
2069 lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
2071 if (!szProduct || !squash_guid(szProduct, squished_pc))
2072 return ERROR_INVALID_PARAMETER;
2074 if (!lpPatchBuf || !lpTransformsBuf || !pcchTransformsBuf)
2075 return ERROR_INVALID_PARAMETER;
2077 if (MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED,
2078 &prod, FALSE) != ERROR_SUCCESS &&
2079 MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2080 &prod, FALSE) != ERROR_SUCCESS &&
2081 MSIREG_OpenProductKey(szProduct, MSIINSTALLCONTEXT_MACHINE,
2082 &prod, FALSE) != ERROR_SUCCESS)
2083 return ERROR_UNKNOWN_PRODUCT;
2085 RegCloseKey(prod);
2087 r = msi_enum_patches(szProduct, NULL, MSIINSTALLCONTEXT_ALL,
2088 MSIPATCHSTATE_ALL, iPatchIndex, &idx, lpPatchBuf,
2089 NULL, NULL, NULL, NULL, &transforms);
2090 if (r != ERROR_SUCCESS)
2091 goto done;
2093 lstrcpynW(lpTransformsBuf, transforms, *pcchTransformsBuf);
2094 if (*pcchTransformsBuf <= lstrlenW(transforms))
2096 r = ERROR_MORE_DATA;
2097 *pcchTransformsBuf = lstrlenW(transforms) * sizeof(WCHAR);
2099 else
2100 *pcchTransformsBuf = lstrlenW(transforms);
2102 done:
2103 msi_free(transforms);
2104 return r;
2107 UINT WINAPI MsiEnumProductsExA( LPCSTR szProductCode, LPCSTR szUserSid,
2108 DWORD dwContext, DWORD dwIndex, CHAR szInstalledProductCode[39],
2109 MSIINSTALLCONTEXT* pdwInstalledContext, LPSTR szSid, LPDWORD pcchSid)
2111 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_a(szProductCode), debugstr_a(szUserSid),
2112 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
2113 szSid, pcchSid);
2114 return ERROR_NO_MORE_ITEMS;
2117 UINT WINAPI MsiEnumProductsExW( LPCWSTR szProductCode, LPCWSTR szUserSid,
2118 DWORD dwContext, DWORD dwIndex, WCHAR szInstalledProductCode[39],
2119 MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, LPDWORD pcchSid)
2121 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_w(szProductCode), debugstr_w(szUserSid),
2122 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
2123 szSid, pcchSid);
2124 return ERROR_NO_MORE_ITEMS;