shlwapi: Handle URL_WININET_COMPATIBILITY flag in UrlCanonicalize.
[wine/multimedia.git] / dlls / msi / registry.c
blobf3580d2245f60cdcc65e7c48b7c3b7c04bc6b184
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);
43 static const BOOL is_64bit = sizeof(void *) > sizeof(int);
45 /*
46 * This module will be all the helper functions for registry access by the
47 * installer bits.
49 static const WCHAR szUserFeatures_fmt[] = {
50 'S','o','f','t','w','a','r','e','\\',
51 'M','i','c','r','o','s','o','f','t','\\',
52 'I','n','s','t','a','l','l','e','r','\\',
53 'F','e','a','t','u','r','e','s','\\',
54 '%','s',0};
56 static const WCHAR szUserDataFeatures_fmt[] = {
57 'S','o','f','t','w','a','r','e','\\',
58 'M','i','c','r','o','s','o','f','t','\\',
59 'W','i','n','d','o','w','s','\\',
60 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
61 'I','n','s','t','a','l','l','e','r','\\',
62 'U','s','e','r','D','a','t','a','\\',
63 '%','s','\\','P','r','o','d','u','c','t','s','\\',
64 '%','s','\\','F','e','a','t','u','r','e','s',0};
66 static const WCHAR szInstaller_Features_fmt[] = {
67 'S','o','f','t','w','a','r','e','\\',
68 'M','i','c','r','o','s','o','f','t','\\',
69 'W','i','n','d','o','w','s','\\',
70 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
71 'I','n','s','t','a','l','l','e','r','\\',
72 'F','e','a','t','u','r','e','s','\\',
73 '%','s',0};
75 static const WCHAR szInstaller_Components[] = {
76 'S','o','f','t','w','a','r','e','\\',
77 'M','i','c','r','o','s','o','f','t','\\',
78 'W','i','n','d','o','w','s','\\',
79 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
80 'I','n','s','t','a','l','l','e','r','\\',
81 'C','o','m','p','o','n','e','n','t','s',0 };
83 static const WCHAR szUser_Components_fmt[] = {
84 'S','o','f','t','w','a','r','e','\\',
85 'M','i','c','r','o','s','o','f','t','\\',
86 'I','n','s','t','a','l','l','e','r','\\',
87 'C','o','m','p','o','n','e','n','t','s','\\',
88 '%','s',0};
90 static const WCHAR szUserDataComp_fmt[] = {
91 'S','o','f','t','w','a','r','e','\\',
92 'M','i','c','r','o','s','o','f','t','\\',
93 'W','i','n','d','o','w','s','\\',
94 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
95 'I','n','s','t','a','l','l','e','r','\\',
96 'U','s','e','r','D','a','t','a','\\',
97 '%','s','\\','C','o','m','p','o','n','e','n','t','s','\\','%','s',0};
99 static const WCHAR szUninstall_fmt[] = {
100 'S','o','f','t','w','a','r','e','\\',
101 'M','i','c','r','o','s','o','f','t','\\',
102 'W','i','n','d','o','w','s','\\',
103 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
104 'U','n','i','n','s','t','a','l','l','\\',
105 '%','s',0 };
107 static const WCHAR szUninstall_32node_fmt[] = {
108 'S','o','f','t','w','a','r','e','\\',
109 'W','o','w','6','4','3','2','N','o','d','e','\\',
110 'M','i','c','r','o','s','o','f','t','\\',
111 'W','i','n','d','o','w','s','\\',
112 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
113 'U','n','i','n','s','t','a','l','l','\\',
114 '%','s',0 };
116 static const WCHAR szUserProduct[] = {
117 'S','o','f','t','w','a','r','e','\\',
118 'M','i','c','r','o','s','o','f','t','\\',
119 'I','n','s','t','a','l','l','e','r','\\',
120 'P','r','o','d','u','c','t','s',0};
122 static const WCHAR szUserProduct_fmt[] = {
123 'S','o','f','t','w','a','r','e','\\',
124 'M','i','c','r','o','s','o','f','t','\\',
125 'I','n','s','t','a','l','l','e','r','\\',
126 'P','r','o','d','u','c','t','s','\\',
127 '%','s',0};
129 static const WCHAR szUserPatch_fmt[] = {
130 'S','o','f','t','w','a','r','e','\\',
131 'M','i','c','r','o','s','o','f','t','\\',
132 'I','n','s','t','a','l','l','e','r','\\',
133 'P','a','t','c','h','e','s','\\',
134 '%','s',0};
136 static const WCHAR szInstaller_Products[] = {
137 'S','o','f','t','w','a','r','e','\\',
138 'M','i','c','r','o','s','o','f','t','\\',
139 'W','i','n','d','o','w','s','\\',
140 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
141 'I','n','s','t','a','l','l','e','r','\\',
142 'P','r','o','d','u','c','t','s',0};
144 static const WCHAR szInstaller_Products_fmt[] = {
145 'S','o','f','t','w','a','r','e','\\',
146 'M','i','c','r','o','s','o','f','t','\\',
147 'W','i','n','d','o','w','s','\\',
148 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
149 'I','n','s','t','a','l','l','e','r','\\',
150 'P','r','o','d','u','c','t','s','\\',
151 '%','s',0};
153 static const WCHAR szInstaller_Patches_fmt[] = {
154 'S','o','f','t','w','a','r','e','\\',
155 'M','i','c','r','o','s','o','f','t','\\',
156 'W','i','n','d','o','w','s','\\',
157 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
158 'I','n','s','t','a','l','l','e','r','\\',
159 'P','a','t','c','h','e','s','\\',
160 '%','s',0};
162 static const WCHAR szInstaller_UpgradeCodes_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','p','g','r','a','d','e','C','o','d','e','s','\\',
169 '%','s',0};
171 static const WCHAR szInstaller_UserUpgradeCodes_fmt[] = {
172 'S','o','f','t','w','a','r','e','\\',
173 'M','i','c','r','o','s','o','f','t','\\',
174 'I','n','s','t','a','l','l','e','r','\\',
175 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
176 '%','s',0};
178 static const WCHAR szUserDataProd_fmt[] = {
179 'S','o','f','t','w','a','r','e','\\',
180 'M','i','c','r','o','s','o','f','t','\\',
181 'W','i','n','d','o','w','s','\\',
182 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
183 'I','n','s','t','a','l','l','e','r','\\',
184 'U','s','e','r','D','a','t','a','\\',
185 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s',0};
187 static const WCHAR szUserDataPatch_fmt[] = {
188 'S','o','f','t','w','a','r','e','\\',
189 'M','i','c','r','o','s','o','f','t','\\',
190 'W','i','n','d','o','w','s','\\',
191 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
192 'I','n','s','t','a','l','l','e','r','\\',
193 'U','s','e','r','D','a','t','a','\\',
194 '%','s','\\','P','a','t','c','h','e','s','\\','%','s',0};
196 static const WCHAR szUserDataProductPatches_fmt[] = {
197 'S','o','f','t','w','a','r','e','\\',
198 'M','i','c','r','o','s','o','f','t','\\',
199 'W','i','n','d','o','w','s','\\',
200 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
201 'I','n','s','t','a','l','l','e','r','\\',
202 'U','s','e','r','D','a','t','a','\\',
203 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\',
204 'P','a','t','c','h','e','s',0};
206 static const WCHAR szInstallProperties_fmt[] = {
207 'S','o','f','t','w','a','r','e','\\',
208 'M','i','c','r','o','s','o','f','t','\\',
209 'W','i','n','d','o','w','s','\\',
210 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
211 'I','n','s','t','a','l','l','e','r','\\',
212 'U','s','e','r','D','a','t','a','\\',
213 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\',
214 'I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0};
216 static const WCHAR szInstaller_LocalClassesProd[] = {
217 'S','o','f','t','w','a','r','e','\\',
218 'C','l','a','s','s','e','s','\\',
219 'I','n','s','t','a','l','l','e','r','\\',
220 'P','r','o','d','u','c','t','s',0};
222 static const WCHAR szInstaller_LocalClassesProd_fmt[] = {
223 'S','o','f','t','w','a','r','e','\\',
224 'C','l','a','s','s','e','s','\\',
225 'I','n','s','t','a','l','l','e','r','\\',
226 'P','r','o','d','u','c','t','s','\\','%','s',0};
228 static const WCHAR szInstaller_LocalClassesFeat_fmt[] = {
229 'S','o','f','t','w','a','r','e','\\',
230 'C','l','a','s','s','e','s','\\',
231 'I','n','s','t','a','l','l','e','r','\\',
232 'F','e','a','t','u','r','e','s','\\','%','s',0};
234 static const WCHAR szInstaller_LocalManaged_fmt[] = {
235 'S','o','f','t','w','a','r','e','\\',
236 'M','i','c','r','o','s','o','f','t','\\',
237 'W','i','n','d','o','w','s','\\',
238 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
239 'I','n','s','t','a','l','l','e','r','\\',
240 'M','a','n','a','g','e','d','\\','%','s','\\',
241 'I','n','s','t','a','l','l','e','r','\\',
242 'P','r','o','d','u','c','t','s',0};
244 static const WCHAR szInstaller_LocalManagedProd_fmt[] = {
245 'S','o','f','t','w','a','r','e','\\',
246 'M','i','c','r','o','s','o','f','t','\\',
247 'W','i','n','d','o','w','s','\\',
248 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
249 'I','n','s','t','a','l','l','e','r','\\',
250 'M','a','n','a','g','e','d','\\','%','s','\\',
251 'I','n','s','t','a','l','l','e','r','\\',
252 'P','r','o','d','u','c','t','s','\\','%','s',0};
254 static const WCHAR szInstaller_LocalManagedFeat_fmt[] = {
255 'S','o','f','t','w','a','r','e','\\',
256 'M','i','c','r','o','s','o','f','t','\\',
257 'W','i','n','d','o','w','s','\\',
258 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
259 'I','n','s','t','a','l','l','e','r','\\',
260 'M','a','n','a','g','e','d','\\','%','s','\\',
261 'I','n','s','t','a','l','l','e','r','\\',
262 'F','e','a','t','u','r','e','s','\\','%','s',0};
264 static const WCHAR szInstaller_ClassesUpgrade_fmt[] = {
265 'I','n','s','t','a','l','l','e','r','\\',
266 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
267 '%','s',0};
269 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
271 DWORD i,n=0;
273 if (lstrlenW(in) != 32)
274 return FALSE;
276 out[n++]='{';
277 for(i=0; i<8; i++)
278 out[n++] = in[7-i];
279 out[n++]='-';
280 for(i=0; i<4; i++)
281 out[n++] = in[11-i];
282 out[n++]='-';
283 for(i=0; i<4; i++)
284 out[n++] = in[15-i];
285 out[n++]='-';
286 for(i=0; i<2; i++)
288 out[n++] = in[17+i*2];
289 out[n++] = in[16+i*2];
291 out[n++]='-';
292 for( ; i<8; i++)
294 out[n++] = in[17+i*2];
295 out[n++] = in[16+i*2];
297 out[n++]='}';
298 out[n]=0;
299 return TRUE;
302 BOOL squash_guid(LPCWSTR in, LPWSTR out)
304 DWORD i,n=1;
305 GUID guid;
307 out[0] = 0;
309 if (FAILED(CLSIDFromString((LPCOLESTR)in, &guid)))
310 return FALSE;
312 for(i=0; i<8; i++)
313 out[7-i] = in[n++];
314 n++;
315 for(i=0; i<4; i++)
316 out[11-i] = in[n++];
317 n++;
318 for(i=0; i<4; i++)
319 out[15-i] = in[n++];
320 n++;
321 for(i=0; i<2; i++)
323 out[17+i*2] = in[n++];
324 out[16+i*2] = in[n++];
326 n++;
327 for( ; i<8; i++)
329 out[17+i*2] = in[n++];
330 out[16+i*2] = in[n++];
332 out[32]=0;
333 return TRUE;
337 /* tables for encoding and decoding base85 */
338 static const unsigned char table_dec85[0x80] = {
339 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
340 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
341 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
342 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
343 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
344 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
345 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
346 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
349 static const char table_enc85[] =
350 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
351 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
352 "yz{}~";
355 * Converts a base85 encoded guid into a GUID pointer
356 * Base85 encoded GUIDs should be 20 characters long.
358 * returns TRUE if successful, FALSE if not
360 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
362 DWORD i, val = 0, base = 1, *p;
364 if (!str)
365 return FALSE;
367 p = (DWORD*) guid;
368 for( i=0; i<20; i++ )
370 if( (i%5) == 0 )
372 val = 0;
373 base = 1;
375 val += table_dec85[str[i]] * base;
376 if( str[i] >= 0x80 )
377 return FALSE;
378 if( table_dec85[str[i]] == 0xff )
379 return FALSE;
380 if( (i%5) == 4 )
381 p[i/5] = val;
382 base *= 85;
384 return TRUE;
388 * Encodes a base85 guid given a GUID pointer
389 * Caller should provide a 21 character buffer for the encoded string.
391 * returns TRUE if successful, FALSE if not
393 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
395 unsigned int x, *p, i;
397 p = (unsigned int*) guid;
398 for( i=0; i<4; i++ )
400 x = p[i];
401 *str++ = table_enc85[x%85];
402 x = x/85;
403 *str++ = table_enc85[x%85];
404 x = x/85;
405 *str++ = table_enc85[x%85];
406 x = x/85;
407 *str++ = table_enc85[x%85];
408 x = x/85;
409 *str++ = table_enc85[x%85];
411 *str = 0;
413 return TRUE;
416 DWORD msi_version_str_to_dword(LPCWSTR p)
418 DWORD major, minor = 0, build = 0, version = 0;
420 if (!p)
421 return version;
423 major = atoiW(p);
425 p = strchrW(p, '.');
426 if (p)
428 minor = atoiW(p+1);
429 p = strchrW(p+1, '.');
430 if (p)
431 build = atoiW(p+1);
434 return MAKELONG(build, MAKEWORD(minor, major));
437 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
439 DWORD len;
440 if (!value) value = szEmpty;
441 len = (lstrlenW(value) + 1) * sizeof (WCHAR);
442 return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len );
445 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
447 LPCWSTR p = value;
448 while (*p) p += lstrlenW(p) + 1;
449 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
450 (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) );
453 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
455 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
458 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
460 HKEY hsubkey = 0;
461 LONG r;
463 r = RegCreateKeyW( hkey, path, &hsubkey );
464 if (r != ERROR_SUCCESS)
465 return r;
466 r = msi_reg_set_val_str( hsubkey, name, val );
467 RegCloseKey( hsubkey );
468 return r;
471 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
473 DWORD len = 0;
474 LPWSTR val;
475 LONG r;
477 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
478 if (r != ERROR_SUCCESS)
479 return NULL;
481 len += sizeof (WCHAR);
482 val = msi_alloc( len );
483 if (!val)
484 return NULL;
485 val[0] = 0;
486 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
487 return val;
490 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
492 DWORD type, len = sizeof (DWORD);
493 LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
494 return r == ERROR_SUCCESS && type == REG_DWORD;
497 static UINT get_user_sid(LPWSTR *usersid)
499 HANDLE token;
500 BYTE buf[1024];
501 DWORD size;
502 PTOKEN_USER user;
504 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
505 return ERROR_FUNCTION_FAILED;
507 size = sizeof(buf);
508 if (!GetTokenInformation(token, TokenUser, buf, size, &size)) {
509 CloseHandle(token);
510 return ERROR_FUNCTION_FAILED;
513 user = (PTOKEN_USER)buf;
514 if (!ConvertSidToStringSidW(user->User.Sid, usersid)) {
515 CloseHandle(token);
516 return ERROR_FUNCTION_FAILED;
518 CloseHandle(token);
519 return ERROR_SUCCESS;
522 UINT MSIREG_OpenUninstallKey(MSIPACKAGE *package, HKEY *key, BOOL create)
524 UINT rc;
525 WCHAR keypath[0x200];
527 TRACE("%s\n", debugstr_w(package->ProductCode));
529 if (is_64bit && package->platform == PLATFORM_INTEL)
530 sprintfW(keypath, szUninstall_32node_fmt, package->ProductCode);
531 else
532 sprintfW(keypath, szUninstall_fmt, package->ProductCode);
534 if (create)
535 rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, keypath, 0, NULL, 0, KEY_ALL_ACCESS, NULL, key, NULL);
536 else
537 rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, keypath, 0, KEY_ALL_ACCESS, key);
539 return rc;
542 UINT MSIREG_DeleteUninstallKey(MSIPACKAGE *package)
544 WCHAR keypath[0x200];
546 TRACE("%s\n", debugstr_w(package->ProductCode));
548 if (is_64bit && package->platform == PLATFORM_INTEL)
549 sprintfW(keypath, szUninstall_32node_fmt, package->ProductCode);
550 else
551 sprintfW(keypath, szUninstall_fmt, package->ProductCode);
553 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
556 UINT MSIREG_OpenProductKey(LPCWSTR szProduct, LPCWSTR szUserSid,
557 MSIINSTALLCONTEXT context, HKEY *key, BOOL create)
559 UINT r;
560 LPWSTR usersid = NULL;
561 HKEY root = HKEY_LOCAL_MACHINE;
562 WCHAR squished_pc[GUID_SIZE];
563 WCHAR keypath[MAX_PATH];
565 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create);
567 if (!squash_guid(szProduct, squished_pc))
568 return ERROR_FUNCTION_FAILED;
570 TRACE("squished (%s)\n", debugstr_w(squished_pc));
572 if (context == MSIINSTALLCONTEXT_MACHINE)
574 sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc);
576 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
578 root = HKEY_CURRENT_USER;
579 sprintfW(keypath, szUserProduct_fmt, squished_pc);
581 else
583 if (!szUserSid)
585 r = get_user_sid(&usersid);
586 if (r != ERROR_SUCCESS || !usersid)
588 ERR("Failed to retrieve user SID: %d\n", r);
589 return r;
592 szUserSid = usersid;
595 sprintfW(keypath, szInstaller_LocalManagedProd_fmt,
596 szUserSid, squished_pc);
597 LocalFree(usersid);
600 if (create)
601 return RegCreateKeyW(root, keypath, key);
603 return RegOpenKeyW(root, keypath, key);
606 UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct)
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,szUserProduct_fmt,squished_pc);
618 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
621 UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
623 UINT rc;
624 WCHAR squished_pc[GUID_SIZE];
625 WCHAR keypath[0x200];
627 TRACE("%s\n",debugstr_w(szPatch));
628 if (!squash_guid(szPatch,squished_pc))
629 return ERROR_FUNCTION_FAILED;
630 TRACE("squished (%s)\n", debugstr_w(squished_pc));
632 sprintfW(keypath,szUserPatch_fmt,squished_pc);
634 if (create)
635 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
636 else
637 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
639 return rc;
642 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
643 HKEY *key, BOOL create)
645 UINT r;
646 LPWSTR usersid;
647 HKEY root = HKEY_LOCAL_MACHINE;
648 WCHAR squished_pc[GUID_SIZE];
649 WCHAR keypath[MAX_PATH];
651 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create);
653 if (!squash_guid(szProduct, squished_pc))
654 return ERROR_FUNCTION_FAILED;
656 TRACE("squished (%s)\n", debugstr_w(squished_pc));
658 if (context == MSIINSTALLCONTEXT_MACHINE)
660 sprintfW(keypath, szInstaller_LocalClassesFeat_fmt, squished_pc);
662 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
664 root = HKEY_CURRENT_USER;
665 sprintfW(keypath, szUserFeatures_fmt, squished_pc);
667 else
669 r = get_user_sid(&usersid);
670 if (r != ERROR_SUCCESS || !usersid)
672 ERR("Failed to retrieve user SID: %d\n", r);
673 return r;
676 sprintfW(keypath, szInstaller_LocalManagedFeat_fmt, usersid, squished_pc);
677 LocalFree(usersid);
680 if (create)
681 return RegCreateKeyW(root, keypath, key);
683 return RegOpenKeyW(root, keypath, key);
686 UINT MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct)
688 WCHAR squished_pc[GUID_SIZE];
689 WCHAR keypath[0x200];
691 TRACE("%s\n",debugstr_w(szProduct));
692 if (!squash_guid(szProduct,squished_pc))
693 return ERROR_FUNCTION_FAILED;
694 TRACE("squished (%s)\n", debugstr_w(squished_pc));
696 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
697 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
700 static UINT MSIREG_OpenInstallerFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
702 UINT rc;
703 WCHAR squished_pc[GUID_SIZE];
704 WCHAR keypath[0x200];
706 TRACE("%s\n",debugstr_w(szProduct));
707 if (!squash_guid(szProduct,squished_pc))
708 return ERROR_FUNCTION_FAILED;
709 TRACE("squished (%s)\n", debugstr_w(squished_pc));
711 sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
713 if (create)
714 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
715 else
716 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
718 return rc;
721 UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
722 HKEY *key, BOOL create)
724 UINT r;
725 LPWSTR usersid;
726 WCHAR squished_pc[GUID_SIZE];
727 WCHAR keypath[0x200];
729 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create);
731 if (!squash_guid(szProduct, squished_pc))
732 return ERROR_FUNCTION_FAILED;
734 TRACE("squished (%s)\n", debugstr_w(squished_pc));
736 if (context == MSIINSTALLCONTEXT_MACHINE)
738 sprintfW(keypath, szUserDataFeatures_fmt, szLocalSid, squished_pc);
740 else
742 r = get_user_sid(&usersid);
743 if (r != ERROR_SUCCESS || !usersid)
745 ERR("Failed to retrieve user SID: %d\n", r);
746 return r;
749 sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc);
750 LocalFree(usersid);
753 if (create)
754 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
756 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
759 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
761 UINT rc;
762 WCHAR squished_cc[GUID_SIZE];
763 WCHAR keypath[0x200];
765 TRACE("%s\n",debugstr_w(szComponent));
766 if (!squash_guid(szComponent,squished_cc))
767 return ERROR_FUNCTION_FAILED;
768 TRACE("squished (%s)\n", debugstr_w(squished_cc));
770 sprintfW(keypath,szUser_Components_fmt,squished_cc);
772 if (create)
773 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
774 else
775 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
777 return rc;
780 UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid,
781 HKEY *key, BOOL create)
783 UINT rc;
784 WCHAR comp[GUID_SIZE];
785 WCHAR keypath[0x200];
786 LPWSTR usersid;
788 TRACE("%s\n", debugstr_w(szComponent));
789 if (!squash_guid(szComponent, comp))
790 return ERROR_FUNCTION_FAILED;
791 TRACE("squished (%s)\n", debugstr_w(comp));
793 if (!szUserSid)
795 rc = get_user_sid(&usersid);
796 if (rc != ERROR_SUCCESS || !usersid)
798 ERR("Failed to retrieve user SID: %d\n", rc);
799 return rc;
802 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
803 LocalFree(usersid);
805 else
806 sprintfW(keypath, szUserDataComp_fmt, szUserSid, comp);
808 if (create)
809 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
810 else
811 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
813 return rc;
816 UINT MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid)
818 UINT rc;
819 WCHAR comp[GUID_SIZE];
820 WCHAR keypath[0x200];
821 LPWSTR usersid;
823 TRACE("%s\n", debugstr_w(szComponent));
824 if (!squash_guid(szComponent, comp))
825 return ERROR_FUNCTION_FAILED;
826 TRACE("squished (%s)\n", debugstr_w(comp));
828 if (!szUserSid)
830 rc = get_user_sid(&usersid);
831 if (rc != ERROR_SUCCESS || !usersid)
833 ERR("Failed to retrieve user SID: %d\n", rc);
834 return rc;
837 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
838 LocalFree(usersid);
840 else
841 sprintfW(keypath, szUserDataComp_fmt, szUserSid, comp);
843 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
846 UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContext,
847 LPCWSTR szUserSid, HKEY *key, BOOL create)
849 UINT rc;
850 WCHAR squished_pc[GUID_SIZE];
851 WCHAR keypath[0x200];
852 LPWSTR usersid;
854 TRACE("%s\n", debugstr_w(szProduct));
855 if (!squash_guid(szProduct, squished_pc))
856 return ERROR_FUNCTION_FAILED;
857 TRACE("squished (%s)\n", debugstr_w(squished_pc));
859 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
860 sprintfW(keypath, szUserDataProd_fmt, szLocalSid, squished_pc);
861 else if (szUserSid)
862 sprintfW(keypath, szUserDataProd_fmt, szUserSid, squished_pc);
863 else
865 rc = get_user_sid(&usersid);
866 if (rc != ERROR_SUCCESS || !usersid)
868 ERR("Failed to retrieve user SID: %d\n", rc);
869 return rc;
872 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
873 LocalFree(usersid);
876 if (create)
877 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
878 else
879 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
881 return rc;
884 UINT MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch, MSIINSTALLCONTEXT dwContext,
885 HKEY *key, BOOL create)
887 UINT rc;
888 WCHAR squished_patch[GUID_SIZE];
889 WCHAR keypath[0x200];
890 LPWSTR usersid;
892 TRACE("%s\n", debugstr_w(szPatch));
893 if (!squash_guid(szPatch, squished_patch))
894 return ERROR_FUNCTION_FAILED;
895 TRACE("squished (%s)\n", debugstr_w(squished_patch));
897 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
898 sprintfW(keypath, szUserDataPatch_fmt, szLocalSid, squished_patch);
899 else
901 rc = get_user_sid(&usersid);
902 if (rc != ERROR_SUCCESS || !usersid)
904 ERR("Failed to retrieve user SID: %d\n", rc);
905 return rc;
908 sprintfW(keypath, szUserDataPatch_fmt, usersid, squished_patch);
909 LocalFree(usersid);
912 if (create)
913 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
915 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
918 UINT MSIREG_DeleteUserDataPatchKey(LPCWSTR patch, MSIINSTALLCONTEXT context)
920 UINT r;
921 WCHAR squished_patch[GUID_SIZE];
922 WCHAR keypath[0x200];
923 LPWSTR usersid;
925 TRACE("%s\n", debugstr_w(patch));
926 if (!squash_guid(patch, squished_patch))
927 return ERROR_FUNCTION_FAILED;
928 TRACE("squished (%s)\n", debugstr_w(squished_patch));
930 if (context == MSIINSTALLCONTEXT_MACHINE)
931 sprintfW(keypath, szUserDataPatch_fmt, szLocalSid, squished_patch);
932 else
934 r = get_user_sid(&usersid);
935 if (r != ERROR_SUCCESS || !usersid)
937 ERR("Failed to retrieve user SID: %d\n", r);
938 return r;
941 sprintfW(keypath, szUserDataPatch_fmt, usersid, squished_patch);
942 LocalFree(usersid);
945 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
948 UINT MSIREG_OpenUserDataProductPatchesKey(LPCWSTR product, MSIINSTALLCONTEXT context,
949 HKEY *key, BOOL create)
951 UINT rc;
952 WCHAR squished_product[GUID_SIZE];
953 WCHAR keypath[0x200];
954 LPWSTR usersid;
956 TRACE("%s\n", debugstr_w(product));
957 if (!squash_guid(product, squished_product))
958 return ERROR_FUNCTION_FAILED;
960 if (context == MSIINSTALLCONTEXT_MACHINE)
961 sprintfW(keypath, szUserDataProductPatches_fmt, szLocalSid, squished_product);
962 else
964 rc = get_user_sid(&usersid);
965 if (rc != ERROR_SUCCESS || !usersid)
967 ERR("Failed to retrieve user SID: %d\n", rc);
968 return rc;
971 sprintfW(keypath, szUserDataProductPatches_fmt, usersid, squished_product);
972 LocalFree(usersid);
975 if (create)
976 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
978 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
981 UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContext,
982 LPCWSTR szUserSid, HKEY *key, BOOL create)
984 UINT rc;
985 LPWSTR usersid;
986 WCHAR squished_pc[GUID_SIZE];
987 WCHAR keypath[0x200];
989 TRACE("%s\n", debugstr_w(szProduct));
990 if (!squash_guid(szProduct, squished_pc))
991 return ERROR_FUNCTION_FAILED;
992 TRACE("squished (%s)\n", debugstr_w(squished_pc));
994 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
995 sprintfW(keypath, szInstallProperties_fmt, szLocalSid, squished_pc);
996 else if (szUserSid)
997 sprintfW(keypath, szInstallProperties_fmt, szUserSid, squished_pc);
998 else
1000 rc = get_user_sid(&usersid);
1001 if (rc != ERROR_SUCCESS || !usersid)
1003 ERR("Failed to retrieve user SID: %d\n", rc);
1004 return rc;
1007 sprintfW(keypath, szInstallProperties_fmt, usersid, squished_pc);
1008 LocalFree(usersid);
1011 if (create)
1012 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1014 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1017 UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)
1019 UINT rc;
1020 WCHAR squished_pc[GUID_SIZE];
1021 WCHAR keypath[0x200];
1022 LPWSTR usersid;
1024 TRACE("%s\n", debugstr_w(szProduct));
1025 if (!squash_guid(szProduct, squished_pc))
1026 return ERROR_FUNCTION_FAILED;
1027 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1029 rc = get_user_sid(&usersid);
1030 if (rc != ERROR_SUCCESS || !usersid)
1032 ERR("Failed to retrieve user SID: %d\n", rc);
1033 return rc;
1036 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
1038 LocalFree(usersid);
1039 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
1042 UINT MSIREG_DeleteProductKey(LPCWSTR szProduct)
1044 WCHAR squished_pc[GUID_SIZE];
1045 WCHAR keypath[0x200];
1047 TRACE("%s\n", debugstr_w(szProduct));
1048 if (!squash_guid(szProduct, squished_pc))
1049 return ERROR_FUNCTION_FAILED;
1050 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1052 sprintfW(keypath, szInstaller_Products_fmt, squished_pc);
1054 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
1057 UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
1059 UINT rc;
1060 WCHAR squished_pc[GUID_SIZE];
1061 WCHAR keypath[0x200];
1063 TRACE("%s\n",debugstr_w(szPatch));
1064 if (!squash_guid(szPatch,squished_pc))
1065 return ERROR_FUNCTION_FAILED;
1066 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1068 sprintfW(keypath,szInstaller_Patches_fmt,squished_pc);
1070 if (create)
1071 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
1072 else
1073 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
1075 return rc;
1078 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
1080 UINT rc;
1081 WCHAR squished_pc[GUID_SIZE];
1082 WCHAR keypath[0x200];
1084 TRACE("%s\n",debugstr_w(szUpgradeCode));
1085 if (!squash_guid(szUpgradeCode,squished_pc))
1086 return ERROR_FUNCTION_FAILED;
1087 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1089 sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
1091 if (create)
1092 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
1093 else
1094 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
1096 return rc;
1099 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
1101 UINT rc;
1102 WCHAR squished_pc[GUID_SIZE];
1103 WCHAR keypath[0x200];
1105 TRACE("%s\n",debugstr_w(szUpgradeCode));
1106 if (!squash_guid(szUpgradeCode,squished_pc))
1107 return ERROR_FUNCTION_FAILED;
1108 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1110 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
1112 if (create)
1113 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
1114 else
1115 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
1117 return rc;
1120 UINT MSIREG_DeleteUserUpgradeCodesKey(LPCWSTR szUpgradeCode)
1122 WCHAR squished_pc[GUID_SIZE];
1123 WCHAR keypath[0x200];
1125 TRACE("%s\n",debugstr_w(szUpgradeCode));
1126 if (!squash_guid(szUpgradeCode,squished_pc))
1127 return ERROR_FUNCTION_FAILED;
1128 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1130 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
1132 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
1135 UINT MSIREG_DeleteLocalClassesProductKey(LPCWSTR szProductCode)
1137 WCHAR squished_pc[GUID_SIZE];
1138 WCHAR keypath[0x200];
1140 TRACE("%s\n", debugstr_w(szProductCode));
1142 if (!squash_guid(szProductCode, squished_pc))
1143 return ERROR_FUNCTION_FAILED;
1145 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1147 sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc);
1149 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
1152 UINT MSIREG_DeleteLocalClassesFeaturesKey(LPCWSTR szProductCode)
1154 WCHAR squished_pc[GUID_SIZE];
1155 WCHAR keypath[0x200];
1157 TRACE("%s\n", debugstr_w(szProductCode));
1159 if (!squash_guid(szProductCode, squished_pc))
1160 return ERROR_FUNCTION_FAILED;
1162 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1164 sprintfW(keypath, szInstaller_LocalClassesFeat_fmt, squished_pc);
1166 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
1169 UINT MSIREG_OpenClassesUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
1171 WCHAR squished_pc[GUID_SIZE];
1172 WCHAR keypath[0x200];
1174 TRACE("%s\n", debugstr_w(szUpgradeCode));
1175 if (!squash_guid(szUpgradeCode, squished_pc))
1176 return ERROR_FUNCTION_FAILED;
1177 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1179 sprintfW(keypath, szInstaller_ClassesUpgrade_fmt, squished_pc);
1181 if (create)
1182 return RegCreateKeyW(HKEY_CLASSES_ROOT, keypath, key);
1184 return RegOpenKeyW(HKEY_CLASSES_ROOT, keypath, key);
1187 /*************************************************************************
1188 * MsiDecomposeDescriptorW [MSI.@]
1190 * Decomposes an MSI descriptor into product, feature and component parts.
1191 * An MSI descriptor is a string of the form:
1192 * [base 85 guid] [feature code] '>' [base 85 guid]
1194 * PARAMS
1195 * szDescriptor [I] the descriptor to decompose
1196 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
1197 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
1198 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
1199 * pUsed [O] the length of the descriptor
1201 * RETURNS
1202 * ERROR_SUCCESS if everything worked correctly
1203 * ERROR_INVALID_PARAMETER if the descriptor was invalid
1206 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
1207 LPWSTR szFeature, LPWSTR szComponent, LPDWORD pUsed )
1209 UINT r, len;
1210 LPWSTR p;
1211 GUID product, component;
1213 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
1214 szFeature, szComponent, pUsed);
1216 r = decode_base85_guid( szDescriptor, &product );
1217 if( !r )
1218 return ERROR_INVALID_PARAMETER;
1220 TRACE("product %s\n", debugstr_guid( &product ));
1222 p = strchrW(&szDescriptor[20],'>');
1223 if( !p )
1224 return ERROR_INVALID_PARAMETER;
1226 len = (p - &szDescriptor[20]);
1227 if( len > MAX_FEATURE_CHARS )
1228 return ERROR_INVALID_PARAMETER;
1230 TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len ));
1232 r = decode_base85_guid( p+1, &component );
1233 if( !r )
1234 return ERROR_INVALID_PARAMETER;
1236 TRACE("component %s\n", debugstr_guid( &component ));
1238 if (szProduct)
1239 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
1240 if (szComponent)
1241 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
1242 if (szFeature)
1244 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
1245 szFeature[len] = 0;
1247 len = ( &p[21] - szDescriptor );
1249 TRACE("length = %d\n", len);
1250 if (pUsed) *pUsed = len;
1252 return ERROR_SUCCESS;
1255 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
1256 LPSTR szFeature, LPSTR szComponent, LPDWORD pUsed )
1258 WCHAR product[MAX_FEATURE_CHARS+1];
1259 WCHAR feature[MAX_FEATURE_CHARS+1];
1260 WCHAR component[MAX_FEATURE_CHARS+1];
1261 LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
1262 UINT r;
1264 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
1265 szFeature, szComponent, pUsed);
1267 str = strdupAtoW( szDescriptor );
1268 if( szDescriptor && !str )
1269 return ERROR_OUTOFMEMORY;
1271 if (szProduct)
1272 p = product;
1273 if (szFeature)
1274 f = feature;
1275 if (szComponent)
1276 c = component;
1278 r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
1280 if (r == ERROR_SUCCESS)
1282 WideCharToMultiByte( CP_ACP, 0, p, -1,
1283 szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
1284 WideCharToMultiByte( CP_ACP, 0, f, -1,
1285 szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
1286 WideCharToMultiByte( CP_ACP, 0, c, -1,
1287 szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
1290 msi_free( str );
1292 return r;
1295 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
1297 DWORD r;
1298 WCHAR szwGuid[GUID_SIZE];
1300 TRACE("%d %p\n", index, lpguid);
1302 if (NULL == lpguid)
1303 return ERROR_INVALID_PARAMETER;
1304 r = MsiEnumProductsW(index, szwGuid);
1305 if( r == ERROR_SUCCESS )
1306 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1308 return r;
1311 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
1313 UINT r;
1314 WCHAR szKeyName[SQUISH_GUID_SIZE];
1315 HKEY key;
1316 DWORD machine_count, managed_count, unmanaged_count;
1317 WCHAR keypath[MAX_PATH];
1318 LPWSTR usersid = NULL;
1320 static DWORD last_index;
1322 TRACE("%d %p\n", index, lpguid);
1324 if (NULL == lpguid)
1325 return ERROR_INVALID_PARAMETER;
1327 if (index && index - last_index != 1)
1328 return ERROR_INVALID_PARAMETER;
1330 key = 0;
1331 r = RegCreateKeyW(HKEY_LOCAL_MACHINE, szInstaller_LocalClassesProd, &key);
1332 if( r != ERROR_SUCCESS ) goto failed;
1334 r = RegQueryInfoKeyW(key, NULL, NULL, NULL, &machine_count, NULL, NULL,
1335 NULL, NULL, NULL, NULL, NULL);
1336 if( r != ERROR_SUCCESS ) goto failed;
1338 if (machine_count && index <= machine_count)
1340 r = RegEnumKeyW(key, index, szKeyName, SQUISH_GUID_SIZE);
1341 if( r == ERROR_SUCCESS )
1343 unsquash_guid(szKeyName, lpguid);
1344 last_index = index;
1345 RegCloseKey(key);
1346 return ERROR_SUCCESS;
1349 RegCloseKey(key);
1351 key = 0;
1352 r = get_user_sid(&usersid);
1353 if (r != ERROR_SUCCESS || !usersid)
1355 ERR("Failed to retrieve user SID: %d\n", r);
1356 last_index = 0;
1357 return r;
1359 sprintfW(keypath, szInstaller_LocalManaged_fmt, usersid);
1360 LocalFree(usersid);
1362 r = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, &key);
1363 if( r != ERROR_SUCCESS ) goto failed;
1365 r = RegQueryInfoKeyW(key, NULL, NULL, NULL, &managed_count, NULL, NULL,
1366 NULL, NULL, NULL, NULL, NULL);
1367 if( r != ERROR_SUCCESS ) goto failed;
1369 if (managed_count && index <= machine_count + managed_count)
1371 r = RegEnumKeyW(key, index - machine_count, szKeyName, SQUISH_GUID_SIZE);
1372 if( r == ERROR_SUCCESS )
1374 unsquash_guid(szKeyName, lpguid);
1375 last_index = index;
1376 RegCloseKey(key);
1377 return ERROR_SUCCESS;
1380 RegCloseKey(key);
1382 key = 0;
1383 r = RegCreateKeyW(HKEY_CURRENT_USER, szUserProduct, &key);
1384 if( r != ERROR_SUCCESS ) goto failed;
1386 r = RegQueryInfoKeyW(key, NULL, NULL, NULL, &unmanaged_count, NULL, NULL,
1387 NULL, NULL, NULL, NULL, NULL);
1388 if( r != ERROR_SUCCESS ) goto failed;
1390 if (unmanaged_count && index <= machine_count + managed_count + unmanaged_count)
1392 r = RegEnumKeyW(key, index - machine_count - managed_count, szKeyName, SQUISH_GUID_SIZE);
1393 if( r == ERROR_SUCCESS )
1395 unsquash_guid(szKeyName, lpguid);
1396 last_index = index;
1397 RegCloseKey(key);
1398 return ERROR_SUCCESS;
1401 failed:
1402 RegCloseKey(key);
1403 last_index = 0;
1404 return ERROR_NO_MORE_ITEMS;
1407 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
1408 LPSTR szFeature, LPSTR szParent)
1410 DWORD r;
1411 WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
1412 LPWSTR szwProduct = NULL;
1414 TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent);
1416 if( szProduct )
1418 szwProduct = strdupAtoW( szProduct );
1419 if( !szwProduct )
1420 return ERROR_OUTOFMEMORY;
1423 r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
1424 if( r == ERROR_SUCCESS )
1426 WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
1427 szFeature, GUID_SIZE, NULL, NULL);
1428 WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
1429 szParent, GUID_SIZE, NULL, NULL);
1432 msi_free( szwProduct);
1434 return r;
1437 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
1438 LPWSTR szFeature, LPWSTR szParent)
1440 HKEY hkeyProduct = 0;
1441 DWORD r, sz;
1443 TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
1445 if( !szProduct )
1446 return ERROR_INVALID_PARAMETER;
1448 r = MSIREG_OpenInstallerFeaturesKey(szProduct,&hkeyProduct,FALSE);
1449 if( r != ERROR_SUCCESS )
1450 return ERROR_NO_MORE_ITEMS;
1452 sz = GUID_SIZE;
1453 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
1454 RegCloseKey(hkeyProduct);
1456 return r;
1459 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
1461 DWORD r;
1462 WCHAR szwGuid[GUID_SIZE];
1464 TRACE("%d %p\n", index, lpguid);
1466 r = MsiEnumComponentsW(index, szwGuid);
1467 if( r == ERROR_SUCCESS )
1468 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1470 return r;
1473 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
1475 HKEY hkeyComponents = 0;
1476 DWORD r;
1477 WCHAR szKeyName[SQUISH_GUID_SIZE];
1479 TRACE("%d %p\n", index, lpguid);
1481 r = RegCreateKeyW(HKEY_LOCAL_MACHINE, szInstaller_Components, &hkeyComponents);
1482 if( r != ERROR_SUCCESS )
1483 return ERROR_NO_MORE_ITEMS;
1485 r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
1486 if( r == ERROR_SUCCESS )
1487 unsquash_guid(szKeyName, lpguid);
1488 RegCloseKey(hkeyComponents);
1490 return r;
1493 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
1495 DWORD r;
1496 WCHAR szwProduct[GUID_SIZE];
1497 LPWSTR szwComponent = NULL;
1499 TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
1501 if ( !szProduct )
1502 return ERROR_INVALID_PARAMETER;
1504 if( szComponent )
1506 szwComponent = strdupAtoW( szComponent );
1507 if( !szwComponent )
1508 return ERROR_OUTOFMEMORY;
1511 r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
1512 if( r == ERROR_SUCCESS )
1514 WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
1515 szProduct, GUID_SIZE, NULL, NULL);
1518 msi_free( szwComponent);
1520 return r;
1523 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
1525 HKEY hkeyComp = 0;
1526 DWORD r, sz;
1527 WCHAR szValName[SQUISH_GUID_SIZE];
1529 TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct);
1531 if (!szComponent || !*szComponent || !szProduct)
1532 return ERROR_INVALID_PARAMETER;
1534 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkeyComp, FALSE) != ERROR_SUCCESS &&
1535 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkeyComp, FALSE) != ERROR_SUCCESS)
1536 return ERROR_UNKNOWN_COMPONENT;
1538 /* see if there are any products at all */
1539 sz = SQUISH_GUID_SIZE;
1540 r = RegEnumValueW(hkeyComp, 0, szValName, &sz, NULL, NULL, NULL, NULL);
1541 if (r != ERROR_SUCCESS)
1543 RegCloseKey(hkeyComp);
1545 if (index != 0)
1546 return ERROR_INVALID_PARAMETER;
1548 return ERROR_UNKNOWN_COMPONENT;
1551 sz = SQUISH_GUID_SIZE;
1552 r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
1553 if( r == ERROR_SUCCESS )
1554 unsquash_guid(szValName, szProduct);
1556 RegCloseKey(hkeyComp);
1558 return r;
1561 static UINT MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
1562 awstring *lpQualBuf, LPDWORD pcchQual,
1563 awstring *lpAppBuf, LPDWORD pcchAppBuf )
1565 DWORD name_sz, val_sz, name_max, val_max, type, ofs;
1566 LPWSTR name = NULL, val = NULL;
1567 UINT r, r2;
1568 HKEY key;
1570 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1571 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
1573 if (!szComponent)
1574 return ERROR_INVALID_PARAMETER;
1576 r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
1577 if (r != ERROR_SUCCESS)
1578 return ERROR_UNKNOWN_COMPONENT;
1580 /* figure out how big the name is we want to return */
1581 name_max = 0x10;
1582 r = ERROR_OUTOFMEMORY;
1583 name = msi_alloc( name_max * sizeof(WCHAR) );
1584 if (!name)
1585 goto end;
1587 val_max = 0x10;
1588 r = ERROR_OUTOFMEMORY;
1589 val = msi_alloc( val_max );
1590 if (!val)
1591 goto end;
1593 /* loop until we allocate enough memory */
1594 while (1)
1596 name_sz = name_max;
1597 val_sz = val_max;
1598 r = RegEnumValueW( key, iIndex, name, &name_sz,
1599 NULL, &type, (LPBYTE)val, &val_sz );
1600 if (r == ERROR_SUCCESS)
1601 break;
1602 if (r != ERROR_MORE_DATA)
1603 goto end;
1605 if (type != REG_MULTI_SZ)
1607 ERR("component data has wrong type (%d)\n", type);
1608 goto end;
1611 r = ERROR_OUTOFMEMORY;
1612 if ((name_sz+1) >= name_max)
1614 name_max *= 2;
1615 msi_free( name );
1616 name = msi_alloc( name_max * sizeof (WCHAR) );
1617 if (!name)
1618 goto end;
1619 continue;
1621 if (val_sz > val_max)
1623 val_max = val_sz + sizeof (WCHAR);
1624 msi_free( val );
1625 val = msi_alloc( val_max * sizeof (WCHAR) );
1626 if (!val)
1627 goto end;
1628 continue;
1630 ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
1631 goto end;
1634 ofs = 0;
1635 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
1636 if (r != ERROR_SUCCESS)
1637 goto end;
1639 TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
1641 r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
1642 r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
1644 if (r2 != ERROR_SUCCESS)
1645 r = r2;
1647 end:
1648 msi_free(val);
1649 msi_free(name);
1650 RegCloseKey(key);
1652 return r;
1655 /*************************************************************************
1656 * MsiEnumComponentQualifiersA [MSI.@]
1658 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
1659 LPSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1660 LPSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1662 awstring qual, appdata;
1663 LPWSTR comp;
1664 UINT r;
1666 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex,
1667 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1668 pcchApplicationDataBuf);
1670 comp = strdupAtoW( szComponent );
1671 if (szComponent && !comp)
1672 return ERROR_OUTOFMEMORY;
1674 qual.unicode = FALSE;
1675 qual.str.a = lpQualifierBuf;
1677 appdata.unicode = FALSE;
1678 appdata.str.a = lpApplicationDataBuf;
1680 r = MSI_EnumComponentQualifiers( comp, iIndex,
1681 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1682 msi_free( comp );
1683 return r;
1686 /*************************************************************************
1687 * MsiEnumComponentQualifiersW [MSI.@]
1689 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
1690 LPWSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1691 LPWSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1693 awstring qual, appdata;
1695 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1696 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1697 pcchApplicationDataBuf);
1699 qual.unicode = TRUE;
1700 qual.str.w = lpQualifierBuf;
1702 appdata.unicode = TRUE;
1703 appdata.str.w = lpApplicationDataBuf;
1705 return MSI_EnumComponentQualifiers( szComponent, iIndex,
1706 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1709 /*************************************************************************
1710 * MsiEnumRelatedProductsW [MSI.@]
1713 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
1714 DWORD iProductIndex, LPWSTR lpProductBuf)
1716 UINT r;
1717 HKEY hkey;
1718 DWORD dwSize = SQUISH_GUID_SIZE;
1719 WCHAR szKeyName[SQUISH_GUID_SIZE];
1721 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved,
1722 iProductIndex, lpProductBuf);
1724 if (NULL == szUpgradeCode)
1725 return ERROR_INVALID_PARAMETER;
1726 if (NULL == lpProductBuf)
1727 return ERROR_INVALID_PARAMETER;
1729 r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1730 if (r != ERROR_SUCCESS)
1731 return ERROR_NO_MORE_ITEMS;
1733 r = RegEnumValueW(hkey, iProductIndex, szKeyName, &dwSize, NULL, NULL, NULL, NULL);
1734 if( r == ERROR_SUCCESS )
1735 unsquash_guid(szKeyName, lpProductBuf);
1736 RegCloseKey(hkey);
1738 return r;
1741 /*************************************************************************
1742 * MsiEnumRelatedProductsA [MSI.@]
1745 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1746 DWORD iProductIndex, LPSTR lpProductBuf)
1748 LPWSTR szwUpgradeCode = NULL;
1749 WCHAR productW[GUID_SIZE];
1750 UINT r;
1752 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1753 iProductIndex, lpProductBuf);
1755 if (szUpgradeCode)
1757 szwUpgradeCode = strdupAtoW( szUpgradeCode );
1758 if( !szwUpgradeCode )
1759 return ERROR_OUTOFMEMORY;
1762 r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1763 iProductIndex, productW );
1764 if (r == ERROR_SUCCESS)
1766 WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1767 lpProductBuf, GUID_SIZE, NULL, NULL );
1769 msi_free( szwUpgradeCode);
1770 return r;
1773 /***********************************************************************
1774 * MsiEnumPatchesExA [MSI.@]
1776 UINT WINAPI MsiEnumPatchesExA(LPCSTR szProductCode, LPCSTR szUserSid,
1777 DWORD dwContext, DWORD dwFilter, DWORD dwIndex, LPSTR szPatchCode,
1778 LPSTR szTargetProductCode, MSIINSTALLCONTEXT *pdwTargetProductContext,
1779 LPSTR szTargetUserSid, LPDWORD pcchTargetUserSid)
1781 LPWSTR prodcode = NULL;
1782 LPWSTR usersid = NULL;
1783 LPWSTR targsid = NULL;
1784 WCHAR patch[GUID_SIZE];
1785 WCHAR targprod[GUID_SIZE];
1786 DWORD len;
1787 UINT r;
1789 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
1790 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext, dwFilter,
1791 dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext,
1792 szTargetUserSid, pcchTargetUserSid);
1794 if (szTargetUserSid && !pcchTargetUserSid)
1795 return ERROR_INVALID_PARAMETER;
1797 if (szProductCode) prodcode = strdupAtoW(szProductCode);
1798 if (szUserSid) usersid = strdupAtoW(szUserSid);
1800 r = MsiEnumPatchesExW(prodcode, usersid, dwContext, dwFilter, dwIndex,
1801 patch, targprod, pdwTargetProductContext,
1802 NULL, &len);
1803 if (r != ERROR_SUCCESS)
1804 goto done;
1806 WideCharToMultiByte(CP_ACP, 0, patch, -1, szPatchCode,
1807 GUID_SIZE, NULL, NULL);
1808 WideCharToMultiByte(CP_ACP, 0, targprod, -1, szTargetProductCode,
1809 GUID_SIZE, NULL, NULL);
1811 if (!szTargetUserSid)
1813 if (pcchTargetUserSid)
1814 *pcchTargetUserSid = len;
1816 goto done;
1819 targsid = msi_alloc(++len * sizeof(WCHAR));
1820 if (!targsid)
1822 r = ERROR_OUTOFMEMORY;
1823 goto done;
1826 r = MsiEnumPatchesExW(prodcode, usersid, dwContext, dwFilter, dwIndex,
1827 patch, targprod, pdwTargetProductContext,
1828 targsid, &len);
1829 if (r != ERROR_SUCCESS || !szTargetUserSid)
1830 goto done;
1832 WideCharToMultiByte(CP_ACP, 0, targsid, -1, szTargetUserSid,
1833 *pcchTargetUserSid, NULL, NULL);
1835 len = lstrlenW(targsid);
1836 if (*pcchTargetUserSid < len + 1)
1838 r = ERROR_MORE_DATA;
1839 *pcchTargetUserSid = len * sizeof(WCHAR);
1841 else
1842 *pcchTargetUserSid = len;
1844 done:
1845 msi_free(prodcode);
1846 msi_free(usersid);
1847 msi_free(targsid);
1849 return r;
1852 static UINT msi_get_patch_state(LPCWSTR prodcode, LPCWSTR usersid,
1853 MSIINSTALLCONTEXT context,
1854 LPWSTR patch, MSIPATCHSTATE *state)
1856 DWORD type, val, size;
1857 HKEY prod, hkey = 0;
1858 HKEY udpatch = 0;
1859 LONG res;
1860 UINT r = ERROR_NO_MORE_ITEMS;
1862 *state = MSIPATCHSTATE_INVALID;
1864 r = MSIREG_OpenUserDataProductKey(prodcode, context,
1865 usersid, &prod, FALSE);
1866 if (r != ERROR_SUCCESS)
1867 return ERROR_NO_MORE_ITEMS;
1869 res = RegOpenKeyExW(prod, szPatches, 0, KEY_READ, &hkey);
1870 if (res != ERROR_SUCCESS)
1871 goto done;
1873 res = RegOpenKeyExW(hkey, patch, 0, KEY_READ, &udpatch);
1874 if (res != ERROR_SUCCESS)
1875 goto done;
1877 size = sizeof(DWORD);
1878 res = RegGetValueW(udpatch, NULL, szState, RRF_RT_DWORD, &type, &val, &size);
1879 if (res != ERROR_SUCCESS ||
1880 val < MSIPATCHSTATE_APPLIED || val > MSIPATCHSTATE_REGISTERED)
1882 r = ERROR_BAD_CONFIGURATION;
1883 goto done;
1886 *state = val;
1887 r = ERROR_SUCCESS;
1889 done:
1890 RegCloseKey(udpatch);
1891 RegCloseKey(hkey);
1892 RegCloseKey(prod);
1894 return r;
1897 static UINT msi_check_product_patches(LPCWSTR prodcode, LPCWSTR usersid,
1898 MSIINSTALLCONTEXT context, DWORD filter, DWORD index, DWORD *idx,
1899 LPWSTR patch, LPWSTR targetprod, MSIINSTALLCONTEXT *targetctx,
1900 LPWSTR targetsid, DWORD *sidsize, LPWSTR *transforms)
1902 MSIPATCHSTATE state = MSIPATCHSTATE_INVALID;
1903 LPWSTR ptr, patches = NULL;
1904 HKEY prod, patchkey = 0;
1905 HKEY localprod = 0, localpatch = 0;
1906 DWORD type, size;
1907 LONG res;
1908 UINT temp, r = ERROR_NO_MORE_ITEMS;
1910 if (MSIREG_OpenProductKey(prodcode, usersid, context,
1911 &prod, FALSE) != ERROR_SUCCESS)
1912 return ERROR_NO_MORE_ITEMS;
1914 size = 0;
1915 res = RegGetValueW(prod, szPatches, szPatches, RRF_RT_ANY, &type, NULL,
1916 &size);
1917 if (res != ERROR_SUCCESS)
1918 goto done;
1920 if (type != REG_MULTI_SZ)
1922 r = ERROR_BAD_CONFIGURATION;
1923 goto done;
1926 patches = msi_alloc(size);
1927 if (!patches)
1929 r = ERROR_OUTOFMEMORY;
1930 goto done;
1933 res = RegGetValueW(prod, szPatches, szPatches, RRF_RT_ANY, &type,
1934 patches, &size);
1935 if (res != ERROR_SUCCESS)
1936 goto done;
1938 ptr = patches;
1939 for (ptr = patches; *ptr && r == ERROR_NO_MORE_ITEMS; ptr += lstrlenW(ptr) + 1)
1941 if (!unsquash_guid(ptr, patch))
1943 r = ERROR_BAD_CONFIGURATION;
1944 goto done;
1947 size = 0;
1948 res = RegGetValueW(prod, szPatches, ptr, RRF_RT_REG_SZ,
1949 &type, NULL, &size);
1950 if (res != ERROR_SUCCESS)
1951 continue;
1953 if (transforms)
1955 *transforms = msi_alloc(size);
1956 if (!*transforms)
1958 r = ERROR_OUTOFMEMORY;
1959 goto done;
1962 res = RegGetValueW(prod, szPatches, ptr, RRF_RT_REG_SZ,
1963 &type, *transforms, &size);
1964 if (res != ERROR_SUCCESS)
1965 continue;
1968 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1970 if (!(filter & MSIPATCHSTATE_APPLIED))
1972 temp = msi_get_patch_state(prodcode, usersid, context,
1973 ptr, &state);
1974 if (temp == ERROR_BAD_CONFIGURATION)
1976 r = ERROR_BAD_CONFIGURATION;
1977 goto done;
1980 if (temp != ERROR_SUCCESS || !(filter & state))
1981 continue;
1984 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
1986 if (!(filter & MSIPATCHSTATE_APPLIED))
1988 temp = msi_get_patch_state(prodcode, usersid, context,
1989 ptr, &state);
1990 if (temp == ERROR_BAD_CONFIGURATION)
1992 r = ERROR_BAD_CONFIGURATION;
1993 goto done;
1996 if (temp != ERROR_SUCCESS || !(filter & state))
1997 continue;
1999 else
2001 temp = MSIREG_OpenUserDataPatchKey(patch, context,
2002 &patchkey, FALSE);
2003 RegCloseKey(patchkey);
2004 if (temp != ERROR_SUCCESS)
2005 continue;
2008 else if (context == MSIINSTALLCONTEXT_MACHINE)
2010 usersid = szEmpty;
2012 if (MSIREG_OpenUserDataProductKey(prodcode, context, NULL, &localprod, FALSE) == ERROR_SUCCESS &&
2013 RegOpenKeyExW(localprod, szPatches, 0, KEY_READ, &localpatch) == ERROR_SUCCESS &&
2014 RegOpenKeyExW(localpatch, ptr, 0, KEY_READ, &patchkey) == ERROR_SUCCESS)
2016 res = RegGetValueW(patchkey, NULL, szState, RRF_RT_REG_DWORD,
2017 &type, &state, &size);
2019 if (!(filter & state))
2020 res = ERROR_NO_MORE_ITEMS;
2022 RegCloseKey(patchkey);
2025 RegCloseKey(localpatch);
2026 RegCloseKey(localprod);
2028 if (res != ERROR_SUCCESS)
2029 continue;
2032 if (*idx < index)
2034 (*idx)++;
2035 continue;
2038 r = ERROR_SUCCESS;
2039 if (targetprod)
2040 lstrcpyW(targetprod, prodcode);
2042 if (targetctx)
2043 *targetctx = context;
2045 if (targetsid)
2047 lstrcpynW(targetsid, usersid, *sidsize);
2048 if (lstrlenW(usersid) >= *sidsize)
2049 r = ERROR_MORE_DATA;
2052 if (sidsize)
2054 *sidsize = lstrlenW(usersid);
2055 if (!targetsid)
2056 *sidsize *= sizeof(WCHAR);
2060 done:
2061 RegCloseKey(prod);
2062 msi_free(patches);
2064 return r;
2067 static UINT msi_enum_patches(LPCWSTR szProductCode, LPCWSTR szUserSid,
2068 DWORD dwContext, DWORD dwFilter, DWORD dwIndex, DWORD *idx,
2069 LPWSTR szPatchCode, LPWSTR szTargetProductCode,
2070 MSIINSTALLCONTEXT *pdwTargetProductContext, LPWSTR szTargetUserSid,
2071 LPDWORD pcchTargetUserSid, LPWSTR *szTransforms)
2073 LPWSTR usersid = NULL;
2074 UINT r = ERROR_INVALID_PARAMETER;
2076 if (!szUserSid)
2078 get_user_sid(&usersid);
2079 szUserSid = usersid;
2082 if (dwContext & MSIINSTALLCONTEXT_USERMANAGED)
2084 r = msi_check_product_patches(szProductCode, szUserSid,
2085 MSIINSTALLCONTEXT_USERMANAGED, dwFilter,
2086 dwIndex, idx, szPatchCode,
2087 szTargetProductCode,
2088 pdwTargetProductContext, szTargetUserSid,
2089 pcchTargetUserSid, szTransforms);
2090 if (r != ERROR_NO_MORE_ITEMS)
2091 goto done;
2094 if (dwContext & MSIINSTALLCONTEXT_USERUNMANAGED)
2096 r = msi_check_product_patches(szProductCode, szUserSid,
2097 MSIINSTALLCONTEXT_USERUNMANAGED, dwFilter,
2098 dwIndex, idx, szPatchCode,
2099 szTargetProductCode,
2100 pdwTargetProductContext, szTargetUserSid,
2101 pcchTargetUserSid, szTransforms);
2102 if (r != ERROR_NO_MORE_ITEMS)
2103 goto done;
2106 if (dwContext & MSIINSTALLCONTEXT_MACHINE)
2108 r = msi_check_product_patches(szProductCode, szUserSid,
2109 MSIINSTALLCONTEXT_MACHINE, dwFilter,
2110 dwIndex, idx, szPatchCode,
2111 szTargetProductCode,
2112 pdwTargetProductContext, szTargetUserSid,
2113 pcchTargetUserSid, szTransforms);
2114 if (r != ERROR_NO_MORE_ITEMS)
2115 goto done;
2118 done:
2119 LocalFree(usersid);
2120 return r;
2123 /***********************************************************************
2124 * MsiEnumPatchesExW [MSI.@]
2126 UINT WINAPI MsiEnumPatchesExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
2127 DWORD dwContext, DWORD dwFilter, DWORD dwIndex, LPWSTR szPatchCode,
2128 LPWSTR szTargetProductCode, MSIINSTALLCONTEXT *pdwTargetProductContext,
2129 LPWSTR szTargetUserSid, LPDWORD pcchTargetUserSid)
2131 WCHAR squished_pc[GUID_SIZE];
2132 DWORD idx = 0;
2133 UINT r;
2135 static DWORD last_index;
2137 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
2138 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext, dwFilter,
2139 dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext,
2140 szTargetUserSid, pcchTargetUserSid);
2142 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
2143 return ERROR_INVALID_PARAMETER;
2145 if (!lstrcmpW(szUserSid, szLocalSid))
2146 return ERROR_INVALID_PARAMETER;
2148 if (dwContext & MSIINSTALLCONTEXT_MACHINE && szUserSid)
2149 return ERROR_INVALID_PARAMETER;
2151 if (dwContext <= MSIINSTALLCONTEXT_NONE ||
2152 dwContext > MSIINSTALLCONTEXT_ALL)
2153 return ERROR_INVALID_PARAMETER;
2155 if (dwFilter <= MSIPATCHSTATE_INVALID || dwFilter > MSIPATCHSTATE_ALL)
2156 return ERROR_INVALID_PARAMETER;
2158 if (dwIndex && dwIndex - last_index != 1)
2159 return ERROR_INVALID_PARAMETER;
2161 if (dwIndex == 0)
2162 last_index = 0;
2164 r = msi_enum_patches(szProductCode, szUserSid, dwContext, dwFilter,
2165 dwIndex, &idx, szPatchCode, szTargetProductCode,
2166 pdwTargetProductContext, szTargetUserSid,
2167 pcchTargetUserSid, NULL);
2169 if (r == ERROR_SUCCESS)
2170 last_index = dwIndex;
2171 else
2172 last_index = 0;
2174 return r;
2177 /***********************************************************************
2178 * MsiEnumPatchesA [MSI.@]
2180 UINT WINAPI MsiEnumPatchesA(LPCSTR szProduct, DWORD iPatchIndex,
2181 LPSTR lpPatchBuf, LPSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
2183 LPWSTR product, transforms;
2184 WCHAR patch[GUID_SIZE];
2185 DWORD len;
2186 UINT r;
2188 TRACE("(%s %d %p %p %p)\n", debugstr_a(szProduct), iPatchIndex,
2189 lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
2191 if (!szProduct || !lpPatchBuf || !lpTransformsBuf || !pcchTransformsBuf)
2192 return ERROR_INVALID_PARAMETER;
2194 product = strdupAtoW(szProduct);
2195 if (!product)
2196 return ERROR_OUTOFMEMORY;
2198 len = *pcchTransformsBuf;
2199 transforms = msi_alloc( len * sizeof(WCHAR) );
2200 if (!transforms)
2202 r = ERROR_OUTOFMEMORY;
2203 goto done;
2206 r = MsiEnumPatchesW(product, iPatchIndex, patch, transforms, &len);
2207 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2208 goto done;
2210 WideCharToMultiByte(CP_ACP, 0, patch, -1, lpPatchBuf,
2211 GUID_SIZE, NULL, NULL);
2213 if (!WideCharToMultiByte(CP_ACP, 0, transforms, -1, lpTransformsBuf,
2214 *pcchTransformsBuf, NULL, NULL))
2215 r = ERROR_MORE_DATA;
2217 if (r == ERROR_MORE_DATA)
2219 lpTransformsBuf[*pcchTransformsBuf - 1] = '\0';
2220 *pcchTransformsBuf = len * 2;
2222 else
2223 *pcchTransformsBuf = strlen( lpTransformsBuf );
2225 done:
2226 msi_free(transforms);
2227 msi_free(product);
2229 return r;
2232 /***********************************************************************
2233 * MsiEnumPatchesW [MSI.@]
2235 UINT WINAPI MsiEnumPatchesW(LPCWSTR szProduct, DWORD iPatchIndex,
2236 LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
2238 WCHAR squished_pc[GUID_SIZE];
2239 LPWSTR transforms = NULL;
2240 HKEY prod;
2241 DWORD idx = 0;
2242 UINT r;
2244 TRACE("(%s %d %p %p %p)\n", debugstr_w(szProduct), iPatchIndex,
2245 lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
2247 if (!szProduct || !squash_guid(szProduct, squished_pc))
2248 return ERROR_INVALID_PARAMETER;
2250 if (!lpPatchBuf || !lpTransformsBuf || !pcchTransformsBuf)
2251 return ERROR_INVALID_PARAMETER;
2253 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2254 &prod, FALSE) != ERROR_SUCCESS &&
2255 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2256 &prod, FALSE) != ERROR_SUCCESS &&
2257 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2258 &prod, FALSE) != ERROR_SUCCESS)
2259 return ERROR_UNKNOWN_PRODUCT;
2261 RegCloseKey(prod);
2263 r = msi_enum_patches(szProduct, NULL, MSIINSTALLCONTEXT_ALL,
2264 MSIPATCHSTATE_ALL, iPatchIndex, &idx, lpPatchBuf,
2265 NULL, NULL, NULL, NULL, &transforms);
2266 if (r != ERROR_SUCCESS)
2267 goto done;
2269 lstrcpynW(lpTransformsBuf, transforms, *pcchTransformsBuf);
2270 if (*pcchTransformsBuf <= lstrlenW(transforms))
2272 r = ERROR_MORE_DATA;
2273 *pcchTransformsBuf = lstrlenW(transforms);
2275 else
2276 *pcchTransformsBuf = lstrlenW(transforms);
2278 done:
2279 msi_free(transforms);
2280 return r;
2283 UINT WINAPI MsiEnumProductsExA( LPCSTR szProductCode, LPCSTR szUserSid,
2284 DWORD dwContext, DWORD dwIndex, CHAR szInstalledProductCode[39],
2285 MSIINSTALLCONTEXT* pdwInstalledContext, LPSTR szSid, LPDWORD pcchSid)
2287 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_a(szProductCode), debugstr_a(szUserSid),
2288 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
2289 szSid, pcchSid);
2290 return ERROR_NO_MORE_ITEMS;
2293 UINT WINAPI MsiEnumProductsExW( LPCWSTR szProductCode, LPCWSTR szUserSid,
2294 DWORD dwContext, DWORD dwIndex, WCHAR szInstalledProductCode[39],
2295 MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, LPDWORD pcchSid)
2297 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_w(szProductCode), debugstr_w(szUserSid),
2298 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
2299 szSid, pcchSid);
2300 return ERROR_NO_MORE_ITEMS;