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
25 #define NONAMELESSUNION
32 #include "wine/debug.h"
36 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi);
45 * This module will be all the helper functions for registry access by the
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','\\',
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','\\',
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','\\',
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','\\',
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','\\',
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','\\',
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','\\',
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','\\',
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','\\',
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','\\',
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_LocalSystemProductCodes_fmt[] = {
191 'S','o','f','t','w','a','r','e','\\',
192 'M','i','c','r','o','s','o','f','t','\\',
193 'W','i','n','d','o','w','s','\\',
194 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
195 'I','n','s','t','a','l','l','e','r','\\',
196 'U','s','e','r','D','a','t','a','\\',
197 'S','-','1','-','5','-','1','8','\\','P','r','o','d','u','c','t','s','\\',
198 '%','s','\\','I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0};
200 static const WCHAR szInstaller_LocalSystemComponent_fmt[] = {
201 'S','o','f','t','w','a','r','e','\\',
202 'M','i','c','r','o','s','o','f','t','\\',
203 'W','i','n','d','o','w','s','\\',
204 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
205 'I','n','s','t','a','l','l','e','r','\\',
206 'U','s','e','r','D','a','t','a','\\',
207 'S','-','1','-','5','-','1','8','\\',
208 'C','o','m','p','o','n','e','n','t','s','\\','%','s',0};
210 static const WCHAR szInstaller_LocalClassesProd_fmt[] = {
211 'S','o','f','t','w','a','r','e','\\',
212 'C','l','a','s','s','e','s','\\',
213 'I','n','s','t','a','l','l','e','r','\\',
214 'P','r','o','d','u','c','t','s','\\','%','s',0};
216 static const WCHAR szInstaller_LocalClassesFeat_fmt[] = {
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 'F','e','a','t','u','r','e','s','\\','%','s',0};
222 static const WCHAR szInstaller_LocalManagedProd_fmt[] = {
223 'S','o','f','t','w','a','r','e','\\',
224 'M','i','c','r','o','s','o','f','t','\\',
225 'W','i','n','d','o','w','s','\\',
226 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
227 'I','n','s','t','a','l','l','e','r','\\',
228 'M','a','n','a','g','e','d','\\','%','s','\\',
229 'I','n','s','t','a','l','l','e','r','\\',
230 'P','r','o','d','u','c','t','s','\\','%','s',0};
232 static const WCHAR szInstaller_LocalManagedFeat_fmt[] = {
233 'S','o','f','t','w','a','r','e','\\',
234 'M','i','c','r','o','s','o','f','t','\\',
235 'W','i','n','d','o','w','s','\\',
236 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
237 'I','n','s','t','a','l','l','e','r','\\',
238 'M','a','n','a','g','e','d','\\','%','s','\\',
239 'I','n','s','t','a','l','l','e','r','\\',
240 'F','e','a','t','u','r','e','s','\\','%','s',0};
242 static const WCHAR szInstaller_ClassesUpgrade_fmt[] = {
243 'I','n','s','t','a','l','l','e','r','\\',
244 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
247 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
251 if (lstrlenW(in) != 32)
266 out[n++] = in[17+i*2];
267 out[n++] = in[16+i*2];
272 out[n++] = in[17+i*2];
273 out[n++] = in[16+i*2];
280 BOOL squash_guid(LPCWSTR in, LPWSTR out)
287 if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
301 out[17+i*2] = in[n++];
302 out[16+i*2] = in[n++];
307 out[17+i*2] = in[n++];
308 out[16+i*2] = in[n++];
315 /* tables for encoding and decoding base85 */
316 static const unsigned char table_dec85[0x80] = {
317 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
318 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
319 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
320 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
321 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
322 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
323 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
324 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
327 static const char table_enc85[] =
328 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
329 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
333 * Converts a base85 encoded guid into a GUID pointer
334 * Base85 encoded GUIDs should be 20 characters long.
336 * returns TRUE if successful, FALSE if not
338 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
340 DWORD i, val = 0, base = 1, *p;
346 for( i=0; i<20; i++ )
353 val += table_dec85[str[i]] * base;
356 if( table_dec85[str[i]] == 0xff )
366 * Encodes a base85 guid given a GUID pointer
367 * Caller should provide a 21 character buffer for the encoded string.
369 * returns TRUE if successful, FALSE if not
371 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
373 unsigned int x, *p, i;
375 p = (unsigned int*) guid;
379 *str++ = table_enc85[x%85];
381 *str++ = table_enc85[x%85];
383 *str++ = table_enc85[x%85];
385 *str++ = table_enc85[x%85];
387 *str++ = table_enc85[x%85];
394 DWORD msi_version_str_to_dword(LPCWSTR p)
396 DWORD major, minor = 0, build = 0, version = 0;
407 p = strchrW(p+1, '.');
412 return MAKELONG(build, MAKEWORD(minor, major));
415 LPWSTR msi_version_dword_to_str(DWORD version)
417 static const WCHAR fmt[] = { '%','u','.','%','u','.','%','u',0 };
418 LPWSTR str = msi_alloc(20);
420 (version&0xff000000)>>24,
421 (version&0x00ff0000)>>16,
426 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
428 static const WCHAR emptyW[] = {0};
430 if (!value) value = emptyW;
431 len = (lstrlenW(value) + 1) * sizeof (WCHAR);
432 return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len );
435 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
438 while (*p) p += lstrlenW(p) + 1;
439 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
440 (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) );
443 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
445 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
448 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
453 r = RegCreateKeyW( hkey, path, &hsubkey );
454 if (r != ERROR_SUCCESS)
456 r = msi_reg_set_val_str( hsubkey, name, val );
457 RegCloseKey( hsubkey );
461 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
467 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
468 if (r != ERROR_SUCCESS)
471 len += sizeof (WCHAR);
472 val = msi_alloc( len );
476 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
480 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
482 DWORD type, len = sizeof (DWORD);
483 LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
484 return r == ERROR_SUCCESS && type == REG_DWORD;
487 static UINT get_user_sid(LPWSTR *usersid)
494 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
495 return ERROR_FUNCTION_FAILED;
498 if (!GetTokenInformation(token, TokenUser, (void *)buf, size, &size)) {
500 return ERROR_FUNCTION_FAILED;
503 user = (PTOKEN_USER)buf;
504 if (!ConvertSidToStringSidW(user->User.Sid, usersid)) {
506 return ERROR_FUNCTION_FAILED;
509 return ERROR_SUCCESS;
512 UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create)
515 WCHAR keypath[0x200];
516 TRACE("%s\n",debugstr_w(szProduct));
518 sprintfW(keypath,szUninstall_fmt,szProduct);
521 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
523 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
528 UINT MSIREG_DeleteUninstallKey(LPCWSTR szProduct)
530 WCHAR keypath[0x200];
531 TRACE("%s\n",debugstr_w(szProduct));
533 sprintfW(keypath,szUninstall_fmt,szProduct);
535 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
538 UINT MSIREG_OpenProductKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
539 HKEY *key, BOOL create)
543 HKEY root = HKEY_LOCAL_MACHINE;
544 WCHAR squished_pc[GUID_SIZE];
545 WCHAR keypath[MAX_PATH];
547 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create);
549 if (!squash_guid(szProduct, squished_pc))
550 return ERROR_FUNCTION_FAILED;
552 TRACE("squished (%s)\n", debugstr_w(squished_pc));
554 if (context == MSIINSTALLCONTEXT_MACHINE)
556 sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc);
558 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
560 root = HKEY_CURRENT_USER;
561 sprintfW(keypath, szUserProduct_fmt, squished_pc);
565 r = get_user_sid(&usersid);
566 if (r != ERROR_SUCCESS || !usersid)
568 ERR("Failed to retrieve user SID: %d\n", r);
572 sprintfW(keypath, szInstaller_LocalManagedProd_fmt, usersid, squished_pc);
577 return RegCreateKeyW(root, keypath, key);
579 return RegOpenKeyW(root, keypath, key);
582 UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct)
584 WCHAR squished_pc[GUID_SIZE];
585 WCHAR keypath[0x200];
587 TRACE("%s\n",debugstr_w(szProduct));
588 if (!squash_guid(szProduct,squished_pc))
589 return ERROR_FUNCTION_FAILED;
590 TRACE("squished (%s)\n", debugstr_w(squished_pc));
592 sprintfW(keypath,szUserProduct_fmt,squished_pc);
594 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
597 UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
600 WCHAR squished_pc[GUID_SIZE];
601 WCHAR keypath[0x200];
603 TRACE("%s\n",debugstr_w(szPatch));
604 if (!squash_guid(szPatch,squished_pc))
605 return ERROR_FUNCTION_FAILED;
606 TRACE("squished (%s)\n", debugstr_w(squished_pc));
608 sprintfW(keypath,szUserPatch_fmt,squished_pc);
611 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
613 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
618 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
619 HKEY *key, BOOL create)
623 HKEY root = HKEY_LOCAL_MACHINE;
624 WCHAR squished_pc[GUID_SIZE];
625 WCHAR keypath[MAX_PATH];
627 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create);
629 if (!squash_guid(szProduct, squished_pc))
630 return ERROR_FUNCTION_FAILED;
632 TRACE("squished (%s)\n", debugstr_w(squished_pc));
634 if (context == MSIINSTALLCONTEXT_MACHINE)
636 sprintfW(keypath, szInstaller_LocalClassesFeat_fmt, squished_pc);
638 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
640 root = HKEY_CURRENT_USER;
641 sprintfW(keypath, szUserFeatures_fmt, squished_pc);
645 r = get_user_sid(&usersid);
646 if (r != ERROR_SUCCESS || !usersid)
648 ERR("Failed to retrieve user SID: %d\n", r);
652 sprintfW(keypath, szInstaller_LocalManagedFeat_fmt, usersid, squished_pc);
657 return RegCreateKeyW(root, keypath, key);
659 return RegOpenKeyW(root, keypath, key);
662 UINT MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct)
664 WCHAR squished_pc[GUID_SIZE];
665 WCHAR keypath[0x200];
667 TRACE("%s\n",debugstr_w(szProduct));
668 if (!squash_guid(szProduct,squished_pc))
669 return ERROR_FUNCTION_FAILED;
670 TRACE("squished (%s)\n", debugstr_w(squished_pc));
672 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
673 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
676 UINT MSIREG_OpenInstallerFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
679 WCHAR squished_pc[GUID_SIZE];
680 WCHAR keypath[0x200];
682 TRACE("%s\n",debugstr_w(szProduct));
683 if (!squash_guid(szProduct,squished_pc))
684 return ERROR_FUNCTION_FAILED;
685 TRACE("squished (%s)\n", debugstr_w(squished_pc));
687 sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
690 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
692 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
697 UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
698 HKEY *key, BOOL create)
702 WCHAR squished_pc[GUID_SIZE];
703 WCHAR keypath[0x200];
705 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create);
707 if (!squash_guid(szProduct, squished_pc))
708 return ERROR_FUNCTION_FAILED;
710 TRACE("squished (%s)\n", debugstr_w(squished_pc));
712 if (context == MSIINSTALLCONTEXT_MACHINE)
714 sprintfW(keypath, szUserDataFeatures_fmt, szLocalSid, squished_pc);
718 r = get_user_sid(&usersid);
719 if (r != ERROR_SUCCESS || !usersid)
721 ERR("Failed to retrieve user SID: %d\n", r);
725 sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc);
730 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
732 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
735 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
738 WCHAR squished_cc[GUID_SIZE];
739 WCHAR keypath[0x200];
741 TRACE("%s\n",debugstr_w(szComponent));
742 if (!squash_guid(szComponent,squished_cc))
743 return ERROR_FUNCTION_FAILED;
744 TRACE("squished (%s)\n", debugstr_w(squished_cc));
746 sprintfW(keypath,szUser_Components_fmt,squished_cc);
749 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
751 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
756 UINT MSIREG_DeleteLocalUserDataComponentKey(LPCWSTR szComponent)
758 WCHAR comp[GUID_SIZE];
759 WCHAR keypath[0x200];
761 TRACE("%s\n", debugstr_w(szComponent));
762 if (!squash_guid(szComponent, comp))
763 return ERROR_FUNCTION_FAILED;
764 TRACE("squished (%s)\n", debugstr_w(comp));
766 sprintfW(keypath, szUserDataComp_fmt, szLocalSid, comp);
767 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
770 UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid,
771 HKEY *key, BOOL create)
774 WCHAR comp[GUID_SIZE];
775 WCHAR keypath[0x200];
778 TRACE("%s\n", debugstr_w(szComponent));
779 if (!squash_guid(szComponent, comp))
780 return ERROR_FUNCTION_FAILED;
781 TRACE("squished (%s)\n", debugstr_w(comp));
785 rc = get_user_sid(&usersid);
786 if (rc != ERROR_SUCCESS || !usersid)
788 ERR("Failed to retrieve user SID: %d\n", rc);
792 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
796 sprintfW(keypath, szUserDataComp_fmt, szUserSid, comp);
799 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
801 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
806 UINT MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent)
809 WCHAR comp[GUID_SIZE];
810 WCHAR keypath[0x200];
813 TRACE("%s\n", debugstr_w(szComponent));
814 if (!squash_guid(szComponent, comp))
815 return ERROR_FUNCTION_FAILED;
816 TRACE("squished (%s)\n", debugstr_w(comp));
818 rc = get_user_sid(&usersid);
819 if (rc != ERROR_SUCCESS || !usersid)
821 ERR("Failed to retrieve user SID: %d\n", rc);
825 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
828 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
831 UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, LPCWSTR szUserSid,
832 HKEY *key, BOOL create)
835 WCHAR squished_pc[GUID_SIZE];
836 WCHAR keypath[0x200];
839 TRACE("%s\n", debugstr_w(szProduct));
840 if (!squash_guid(szProduct, squished_pc))
841 return ERROR_FUNCTION_FAILED;
842 TRACE("squished (%s)\n", debugstr_w(squished_pc));
846 rc = get_user_sid(&usersid);
847 if (rc != ERROR_SUCCESS || !usersid)
849 ERR("Failed to retrieve user SID: %d\n", rc);
853 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
857 sprintfW(keypath, szUserDataProd_fmt, szUserSid, squished_pc);
860 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
862 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
867 UINT MSIREG_OpenUserDataPatchKey(LPWSTR patch, HKEY *key, BOOL create)
870 WCHAR keypath[0x200];
875 rc = get_user_sid(&usersid);
876 if (rc != ERROR_SUCCESS || !usersid)
878 ERR("Failed to retrieve user SID: %d\n", rc);
882 sprintfW(keypath, szUserDataPatch_fmt, usersid, patch);
885 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
887 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
893 UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, LPCWSTR szUserSID,
894 HKEY *key, BOOL create)
897 WCHAR squished_pc[GUID_SIZE];
898 WCHAR keypath[0x200];
900 TRACE("%s\n", debugstr_w(szProduct));
901 if (!squash_guid(szProduct, squished_pc))
902 return ERROR_FUNCTION_FAILED;
903 TRACE("squished (%s)\n", debugstr_w(squished_pc));
905 sprintfW(keypath, szInstallProperties_fmt, szUserSID, squished_pc);
908 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
910 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
915 UINT MSIREG_OpenCurrentUserInstallProps(LPCWSTR szProduct, HKEY *key,
921 rc = get_user_sid(&usersid);
922 if (rc != ERROR_SUCCESS || !usersid)
924 ERR("Failed to retrieve user SID: %d\n", rc);
928 rc = MSIREG_OpenInstallProps(szProduct, usersid, key, create);
934 UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)
937 WCHAR squished_pc[GUID_SIZE];
938 WCHAR keypath[0x200];
941 TRACE("%s\n", debugstr_w(szProduct));
942 if (!squash_guid(szProduct, squished_pc))
943 return ERROR_FUNCTION_FAILED;
944 TRACE("squished (%s)\n", debugstr_w(squished_pc));
946 rc = get_user_sid(&usersid);
947 if (rc != ERROR_SUCCESS || !usersid)
949 ERR("Failed to retrieve user SID: %d\n", rc);
953 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
956 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
959 UINT MSIREG_DeleteProductKey(LPCWSTR szProduct)
961 WCHAR squished_pc[GUID_SIZE];
962 WCHAR keypath[0x200];
964 TRACE("%s\n", debugstr_w(szProduct));
965 if (!squash_guid(szProduct, squished_pc))
966 return ERROR_FUNCTION_FAILED;
967 TRACE("squished (%s)\n", debugstr_w(squished_pc));
969 sprintfW(keypath, szInstaller_Products_fmt, squished_pc);
971 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
974 UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
977 WCHAR squished_pc[GUID_SIZE];
978 WCHAR keypath[0x200];
980 TRACE("%s\n",debugstr_w(szPatch));
981 if (!squash_guid(szPatch,squished_pc))
982 return ERROR_FUNCTION_FAILED;
983 TRACE("squished (%s)\n", debugstr_w(squished_pc));
985 sprintfW(keypath,szInstaller_Patches_fmt,squished_pc);
988 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
990 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
995 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
998 WCHAR squished_pc[GUID_SIZE];
999 WCHAR keypath[0x200];
1001 TRACE("%s\n",debugstr_w(szUpgradeCode));
1002 if (!squash_guid(szUpgradeCode,squished_pc))
1003 return ERROR_FUNCTION_FAILED;
1004 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1006 sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
1009 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
1011 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
1016 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
1019 WCHAR squished_pc[GUID_SIZE];
1020 WCHAR keypath[0x200];
1022 TRACE("%s\n",debugstr_w(szUpgradeCode));
1023 if (!squash_guid(szUpgradeCode,squished_pc))
1024 return ERROR_FUNCTION_FAILED;
1025 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1027 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
1030 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
1032 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
1037 UINT MSIREG_DeleteUserUpgradeCodesKey(LPCWSTR szUpgradeCode)
1039 WCHAR squished_pc[GUID_SIZE];
1040 WCHAR keypath[0x200];
1042 TRACE("%s\n",debugstr_w(szUpgradeCode));
1043 if (!squash_guid(szUpgradeCode,squished_pc))
1044 return ERROR_FUNCTION_FAILED;
1045 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1047 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
1049 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
1052 UINT MSIREG_OpenLocalSystemProductKey(LPCWSTR szProductCode, HKEY *key, BOOL create)
1054 WCHAR squished_pc[GUID_SIZE];
1055 WCHAR keypath[0x200];
1057 TRACE("%s\n", debugstr_w(szProductCode));
1059 if (!squash_guid(szProductCode, squished_pc))
1060 return ERROR_FUNCTION_FAILED;
1062 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1064 sprintfW(keypath, szInstaller_LocalSystemProductCodes_fmt, squished_pc);
1067 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1069 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1072 UINT MSIREG_OpenLocalSystemComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create)
1074 WCHAR squished_pc[GUID_SIZE];
1075 WCHAR keypath[0x200];
1077 TRACE("%s\n", debugstr_w(szComponent));
1079 if (!squash_guid(szComponent, squished_pc))
1080 return ERROR_FUNCTION_FAILED;
1082 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1084 sprintfW(keypath, szInstaller_LocalSystemComponent_fmt, squished_pc);
1087 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1089 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
1092 UINT MSIREG_DeleteLocalClassesProductKey(LPCWSTR szProductCode)
1094 WCHAR squished_pc[GUID_SIZE];
1095 WCHAR keypath[0x200];
1097 TRACE("%s\n", debugstr_w(szProductCode));
1099 if (!squash_guid(szProductCode, squished_pc))
1100 return ERROR_FUNCTION_FAILED;
1102 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1104 sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc);
1106 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
1109 UINT MSIREG_DeleteLocalClassesFeaturesKey(LPCWSTR szProductCode)
1111 WCHAR squished_pc[GUID_SIZE];
1112 WCHAR keypath[0x200];
1114 TRACE("%s\n", debugstr_w(szProductCode));
1116 if (!squash_guid(szProductCode, squished_pc))
1117 return ERROR_FUNCTION_FAILED;
1119 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1121 sprintfW(keypath, szInstaller_LocalClassesFeat_fmt, squished_pc);
1123 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
1126 UINT MSIREG_OpenClassesUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
1128 WCHAR squished_pc[GUID_SIZE];
1129 WCHAR keypath[0x200];
1131 TRACE("%s\n", debugstr_w(szUpgradeCode));
1132 if (!squash_guid(szUpgradeCode, squished_pc))
1133 return ERROR_FUNCTION_FAILED;
1134 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1136 sprintfW(keypath, szInstaller_ClassesUpgrade_fmt, squished_pc);
1139 return RegCreateKeyW(HKEY_CLASSES_ROOT, keypath, key);
1141 return RegOpenKeyW(HKEY_CLASSES_ROOT, keypath, key);
1144 /*************************************************************************
1145 * MsiDecomposeDescriptorW [MSI.@]
1147 * Decomposes an MSI descriptor into product, feature and component parts.
1148 * An MSI descriptor is a string of the form:
1149 * [base 85 guid] [feature code] '>' [base 85 guid]
1152 * szDescriptor [I] the descriptor to decompose
1153 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
1154 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
1155 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
1156 * pUsed [O] the length of the descriptor
1159 * ERROR_SUCCESS if everything worked correctly
1160 * ERROR_INVALID_PARAMETER if the descriptor was invalid
1163 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
1164 LPWSTR szFeature, LPWSTR szComponent, LPDWORD pUsed )
1168 GUID product, component;
1170 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
1171 szFeature, szComponent, pUsed);
1173 r = decode_base85_guid( szDescriptor, &product );
1175 return ERROR_INVALID_PARAMETER;
1177 TRACE("product %s\n", debugstr_guid( &product ));
1179 p = strchrW(&szDescriptor[20],'>');
1181 return ERROR_INVALID_PARAMETER;
1183 len = (p - &szDescriptor[20]);
1184 if( len > MAX_FEATURE_CHARS )
1185 return ERROR_INVALID_PARAMETER;
1187 TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len ));
1189 r = decode_base85_guid( p+1, &component );
1191 return ERROR_INVALID_PARAMETER;
1193 TRACE("component %s\n", debugstr_guid( &component ));
1196 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
1198 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
1201 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
1204 len = ( &p[21] - szDescriptor );
1206 TRACE("length = %d\n", len);
1209 return ERROR_SUCCESS;
1212 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
1213 LPSTR szFeature, LPSTR szComponent, LPDWORD pUsed )
1215 WCHAR product[MAX_FEATURE_CHARS+1];
1216 WCHAR feature[MAX_FEATURE_CHARS+1];
1217 WCHAR component[MAX_FEATURE_CHARS+1];
1218 LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
1221 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
1222 szFeature, szComponent, pUsed);
1224 str = strdupAtoW( szDescriptor );
1225 if( szDescriptor && !str )
1226 return ERROR_OUTOFMEMORY;
1235 r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
1237 if (r == ERROR_SUCCESS)
1239 WideCharToMultiByte( CP_ACP, 0, p, -1,
1240 szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
1241 WideCharToMultiByte( CP_ACP, 0, f, -1,
1242 szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
1243 WideCharToMultiByte( CP_ACP, 0, c, -1,
1244 szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
1252 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
1255 WCHAR szwGuid[GUID_SIZE];
1257 TRACE("%d %p\n", index, lpguid);
1260 return ERROR_INVALID_PARAMETER;
1261 r = MsiEnumProductsW(index, szwGuid);
1262 if( r == ERROR_SUCCESS )
1263 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1268 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
1270 HKEY hkeyProducts = 0;
1272 WCHAR szKeyName[SQUISH_GUID_SIZE];
1274 TRACE("%d %p\n", index, lpguid);
1277 return ERROR_INVALID_PARAMETER;
1279 r = RegCreateKeyW(HKEY_LOCAL_MACHINE, szInstaller_Products, &hkeyProducts);
1280 if( r != ERROR_SUCCESS )
1281 return ERROR_NO_MORE_ITEMS;
1283 r = RegEnumKeyW(hkeyProducts, index, szKeyName, SQUISH_GUID_SIZE);
1284 if( r == ERROR_SUCCESS )
1285 unsquash_guid(szKeyName, lpguid);
1286 RegCloseKey(hkeyProducts);
1291 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
1292 LPSTR szFeature, LPSTR szParent)
1295 WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
1296 LPWSTR szwProduct = NULL;
1298 TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent);
1302 szwProduct = strdupAtoW( szProduct );
1304 return ERROR_OUTOFMEMORY;
1307 r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
1308 if( r == ERROR_SUCCESS )
1310 WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
1311 szFeature, GUID_SIZE, NULL, NULL);
1312 WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
1313 szParent, GUID_SIZE, NULL, NULL);
1316 msi_free( szwProduct);
1321 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
1322 LPWSTR szFeature, LPWSTR szParent)
1324 HKEY hkeyProduct = 0;
1327 TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
1330 return ERROR_INVALID_PARAMETER;
1332 r = MSIREG_OpenInstallerFeaturesKey(szProduct,&hkeyProduct,FALSE);
1333 if( r != ERROR_SUCCESS )
1334 return ERROR_NO_MORE_ITEMS;
1337 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
1338 RegCloseKey(hkeyProduct);
1343 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
1346 WCHAR szwGuid[GUID_SIZE];
1348 TRACE("%d %p\n", index, lpguid);
1350 r = MsiEnumComponentsW(index, szwGuid);
1351 if( r == ERROR_SUCCESS )
1352 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1357 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
1359 HKEY hkeyComponents = 0;
1361 WCHAR szKeyName[SQUISH_GUID_SIZE];
1363 TRACE("%d %p\n", index, lpguid);
1365 r = RegCreateKeyW(HKEY_LOCAL_MACHINE, szInstaller_Components, &hkeyComponents);
1366 if( r != ERROR_SUCCESS )
1367 return ERROR_NO_MORE_ITEMS;
1369 r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
1370 if( r == ERROR_SUCCESS )
1371 unsquash_guid(szKeyName, lpguid);
1372 RegCloseKey(hkeyComponents);
1377 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
1380 WCHAR szwProduct[GUID_SIZE];
1381 LPWSTR szwComponent = NULL;
1383 TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
1386 return ERROR_INVALID_PARAMETER;
1390 szwComponent = strdupAtoW( szComponent );
1392 return ERROR_OUTOFMEMORY;
1395 r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
1396 if( r == ERROR_SUCCESS )
1398 WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
1399 szProduct, GUID_SIZE, NULL, NULL);
1402 msi_free( szwComponent);
1407 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
1411 WCHAR szValName[SQUISH_GUID_SIZE];
1413 TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct);
1415 if (!szComponent || !*szComponent || !szProduct)
1416 return ERROR_INVALID_PARAMETER;
1418 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkeyComp, FALSE) != ERROR_SUCCESS &&
1419 MSIREG_OpenLocalSystemComponentKey(szComponent, &hkeyComp, FALSE) != ERROR_SUCCESS)
1420 return ERROR_UNKNOWN_COMPONENT;
1422 /* see if there are any products at all */
1423 sz = SQUISH_GUID_SIZE;
1424 r = RegEnumValueW(hkeyComp, 0, szValName, &sz, NULL, NULL, NULL, NULL);
1425 if (r != ERROR_SUCCESS)
1427 RegCloseKey(hkeyComp);
1430 return ERROR_INVALID_PARAMETER;
1432 return ERROR_UNKNOWN_COMPONENT;
1435 sz = SQUISH_GUID_SIZE;
1436 r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
1437 if( r == ERROR_SUCCESS )
1438 unsquash_guid(szValName, szProduct);
1440 RegCloseKey(hkeyComp);
1445 static UINT MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
1446 awstring *lpQualBuf, LPDWORD pcchQual,
1447 awstring *lpAppBuf, LPDWORD pcchAppBuf )
1449 DWORD name_sz, val_sz, name_max, val_max, type, ofs;
1450 LPWSTR name = NULL, val = NULL;
1454 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1455 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
1458 return ERROR_INVALID_PARAMETER;
1460 r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
1461 if (r != ERROR_SUCCESS)
1462 return ERROR_UNKNOWN_COMPONENT;
1464 /* figure out how big the name is we want to return */
1466 r = ERROR_OUTOFMEMORY;
1467 name = msi_alloc( name_max * sizeof(WCHAR) );
1472 r = ERROR_OUTOFMEMORY;
1473 val = msi_alloc( val_max );
1477 /* loop until we allocate enough memory */
1482 r = RegEnumValueW( key, iIndex, name, &name_sz,
1483 NULL, &type, (LPBYTE)val, &val_sz );
1484 if (r == ERROR_SUCCESS)
1486 if (r != ERROR_MORE_DATA)
1489 if (type != REG_MULTI_SZ)
1491 ERR("component data has wrong type (%d)\n", type);
1495 r = ERROR_OUTOFMEMORY;
1496 if ((name_sz+1) >= name_max)
1500 name = msi_alloc( name_max * sizeof (WCHAR) );
1505 if (val_sz > val_max)
1507 val_max = val_sz + sizeof (WCHAR);
1509 val = msi_alloc( val_max * sizeof (WCHAR) );
1514 ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
1519 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
1520 if (r != ERROR_SUCCESS)
1523 TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
1525 r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
1526 r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
1528 if (r2 != ERROR_SUCCESS)
1539 /*************************************************************************
1540 * MsiEnumComponentQualifiersA [MSI.@]
1542 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
1543 LPSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1544 LPSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1546 awstring qual, appdata;
1550 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex,
1551 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1552 pcchApplicationDataBuf);
1554 comp = strdupAtoW( szComponent );
1555 if (szComponent && !comp)
1556 return ERROR_OUTOFMEMORY;
1558 qual.unicode = FALSE;
1559 qual.str.a = lpQualifierBuf;
1561 appdata.unicode = FALSE;
1562 appdata.str.a = lpApplicationDataBuf;
1564 r = MSI_EnumComponentQualifiers( comp, iIndex,
1565 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1570 /*************************************************************************
1571 * MsiEnumComponentQualifiersW [MSI.@]
1573 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
1574 LPWSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1575 LPWSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1577 awstring qual, appdata;
1579 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1580 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1581 pcchApplicationDataBuf);
1583 qual.unicode = TRUE;
1584 qual.str.w = lpQualifierBuf;
1586 appdata.unicode = TRUE;
1587 appdata.str.w = lpApplicationDataBuf;
1589 return MSI_EnumComponentQualifiers( szComponent, iIndex,
1590 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1593 /*************************************************************************
1594 * MsiEnumRelatedProductsW [MSI.@]
1597 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
1598 DWORD iProductIndex, LPWSTR lpProductBuf)
1602 DWORD dwSize = SQUISH_GUID_SIZE;
1603 WCHAR szKeyName[SQUISH_GUID_SIZE];
1605 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved,
1606 iProductIndex, lpProductBuf);
1608 if (NULL == szUpgradeCode)
1609 return ERROR_INVALID_PARAMETER;
1610 if (NULL == lpProductBuf)
1611 return ERROR_INVALID_PARAMETER;
1613 r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1614 if (r != ERROR_SUCCESS)
1615 return ERROR_NO_MORE_ITEMS;
1617 r = RegEnumValueW(hkey, iProductIndex, szKeyName, &dwSize, NULL, NULL, NULL, NULL);
1618 if( r == ERROR_SUCCESS )
1619 unsquash_guid(szKeyName, lpProductBuf);
1625 /*************************************************************************
1626 * MsiEnumRelatedProductsA [MSI.@]
1629 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1630 DWORD iProductIndex, LPSTR lpProductBuf)
1632 LPWSTR szwUpgradeCode = NULL;
1633 WCHAR productW[GUID_SIZE];
1636 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1637 iProductIndex, lpProductBuf);
1641 szwUpgradeCode = strdupAtoW( szUpgradeCode );
1642 if( !szwUpgradeCode )
1643 return ERROR_OUTOFMEMORY;
1646 r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1647 iProductIndex, productW );
1648 if (r == ERROR_SUCCESS)
1650 WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1651 lpProductBuf, GUID_SIZE, NULL, NULL );
1653 msi_free( szwUpgradeCode);
1657 /***********************************************************************
1658 * MsiEnumPatchesExA [MSI.@]
1660 UINT WINAPI MsiEnumPatchesExA(LPCSTR szProductCode, LPCSTR szUserSid,
1661 DWORD dwContext, DWORD dwFilter, DWORD dwIndex, LPSTR szPatchCode,
1662 LPSTR szTargetProductCode, MSIINSTALLCONTEXT *pdwTargetProductContext,
1663 LPSTR szTargetUserSid, LPDWORD pcchTargetUserSid)
1665 LPWSTR prodcode = NULL;
1666 LPWSTR usersid = NULL;
1667 LPWSTR targsid = NULL;
1668 WCHAR patch[GUID_SIZE];
1669 WCHAR targprod[GUID_SIZE];
1673 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
1674 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext, dwFilter,
1675 dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext,
1676 szTargetUserSid, pcchTargetUserSid);
1678 if (szTargetUserSid && !pcchTargetUserSid)
1679 return ERROR_INVALID_PARAMETER;
1681 if (szProductCode) prodcode = strdupAtoW(szProductCode);
1682 if (szUserSid) usersid = strdupAtoW(szUserSid);
1684 r = MsiEnumPatchesExW(prodcode, usersid, dwContext, dwFilter, dwIndex,
1685 patch, targprod, pdwTargetProductContext,
1687 if (r != ERROR_SUCCESS)
1690 WideCharToMultiByte(CP_ACP, 0, patch, -1, szPatchCode,
1691 GUID_SIZE, NULL, NULL);
1692 WideCharToMultiByte(CP_ACP, 0, targprod, -1, szTargetProductCode,
1693 GUID_SIZE, NULL, NULL);
1695 if (!szTargetUserSid)
1697 if (pcchTargetUserSid)
1698 *pcchTargetUserSid = len;
1703 targsid = msi_alloc(++len * sizeof(WCHAR));
1706 r = ERROR_OUTOFMEMORY;
1710 r = MsiEnumPatchesExW(prodcode, usersid, dwContext, dwFilter, dwIndex,
1711 patch, targprod, pdwTargetProductContext,
1713 if (r != ERROR_SUCCESS || !szTargetUserSid)
1716 WideCharToMultiByte(CP_ACP, 0, targsid, -1, szTargetUserSid,
1717 *pcchTargetUserSid, NULL, NULL);
1719 len = lstrlenW(targsid);
1720 if (*pcchTargetUserSid < len + 1)
1722 r = ERROR_MORE_DATA;
1723 *pcchTargetUserSid = len * sizeof(WCHAR);
1726 *pcchTargetUserSid = len;
1736 static UINT msi_get_patch_state(LPCWSTR prodcode, LPCWSTR usersid,
1737 LPWSTR patch, MSIPATCHSTATE *state)
1739 DWORD type, val, size;
1740 HKEY prod, hkey = 0;
1743 UINT r = ERROR_NO_MORE_ITEMS;
1745 static const WCHAR szPatches[] = {'P','a','t','c','h','e','s',0};
1746 static const WCHAR szState[] = {'S','t','a','t','e',0};
1748 *state = MSIPATCHSTATE_INVALID;
1750 /* FIXME: usersid might not be current user */
1751 r = MSIREG_OpenUserDataProductKey(prodcode, NULL, &prod, FALSE);
1752 if (r != ERROR_SUCCESS)
1753 return ERROR_NO_MORE_ITEMS;
1755 res = RegOpenKeyExW(prod, szPatches, 0, KEY_READ, &hkey);
1756 if (res != ERROR_SUCCESS)
1759 res = RegOpenKeyExW(hkey, patch, 0, KEY_READ, &udpatch);
1760 if (res != ERROR_SUCCESS)
1763 size = sizeof(DWORD);
1764 res = RegGetValueW(udpatch, NULL, szState, RRF_RT_DWORD, &type, &val, &size);
1765 if (res != ERROR_SUCCESS ||
1766 val < MSIPATCHSTATE_APPLIED || val > MSIPATCHSTATE_REGISTERED)
1768 r = ERROR_BAD_CONFIGURATION;
1776 RegCloseKey(udpatch);
1783 static UINT msi_check_product_patches(LPCWSTR prodcode, LPCWSTR usersid,
1784 MSIINSTALLCONTEXT context, DWORD filter, DWORD index, DWORD *idx,
1785 LPWSTR patch, LPWSTR targetprod, MSIINSTALLCONTEXT *targetctx,
1786 LPWSTR targetsid, DWORD *sidsize)
1788 MSIPATCHSTATE state;
1789 LPWSTR ptr, patches = NULL;
1790 HKEY prod, patchkey = 0;
1791 HKEY localprod = 0, localpatch = 0;
1794 UINT temp, r = ERROR_NO_MORE_ITEMS;
1796 static const WCHAR szPatches[] = {'P','a','t','c','h','e','s',0};
1797 static const WCHAR szState[] = {'S','t','a','t','e',0};
1798 static const WCHAR szEmpty[] = {0};
1800 if (MSIREG_OpenProductKey(prodcode, context, &prod, FALSE) != ERROR_SUCCESS)
1801 return ERROR_NO_MORE_ITEMS;
1804 res = RegGetValueW(prod, szPatches, szPatches, RRF_RT_ANY, &type, NULL,
1806 if (res != ERROR_SUCCESS)
1809 if (type != REG_MULTI_SZ)
1811 r = ERROR_BAD_CONFIGURATION;
1815 patches = msi_alloc(size);
1818 r = ERROR_OUTOFMEMORY;
1822 res = RegGetValueW(prod, szPatches, szPatches, RRF_RT_ANY, &type,
1824 if (res != ERROR_SUCCESS)
1828 for (ptr = patches; *ptr && r == ERROR_NO_MORE_ITEMS; ptr += lstrlenW(ptr))
1830 if (!unsquash_guid(ptr, patch))
1832 r = ERROR_BAD_CONFIGURATION;
1837 res = RegGetValueW(prod, szPatches, ptr, RRF_RT_REG_SZ,
1838 &type, NULL, &size);
1839 if (res != ERROR_SUCCESS)
1842 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1844 if (!(filter & MSIPATCHSTATE_APPLIED))
1846 temp = msi_get_patch_state(prodcode, usersid, ptr, &state);
1847 if (temp == ERROR_BAD_CONFIGURATION)
1849 r = ERROR_BAD_CONFIGURATION;
1853 if (temp != ERROR_SUCCESS || !(filter & state))
1857 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
1859 if (!(filter & MSIPATCHSTATE_APPLIED))
1861 temp = msi_get_patch_state(prodcode, usersid, ptr, &state);
1862 if (temp == ERROR_BAD_CONFIGURATION)
1864 r = ERROR_BAD_CONFIGURATION;
1868 if (temp != ERROR_SUCCESS || !(filter & state))
1873 temp = MSIREG_OpenUserDataPatchKey(ptr, &patchkey, FALSE);
1874 RegCloseKey(patchkey);
1875 if (temp != ERROR_SUCCESS)
1879 else if (context == MSIINSTALLCONTEXT_MACHINE)
1883 if (MSIREG_OpenUserDataProductKey(prodcode, szLocalSid, &localprod, FALSE) == ERROR_SUCCESS &&
1884 RegOpenKeyExW(localprod, szPatches, 0, KEY_READ, &localpatch) == ERROR_SUCCESS &&
1885 RegOpenKeyExW(localpatch, ptr, 0, KEY_READ, &patchkey) == ERROR_SUCCESS)
1887 res = RegGetValueW(patchkey, NULL, szState, RRF_RT_REG_DWORD,
1888 &type, &state, &size);
1890 if (!(filter & state))
1891 res = ERROR_NO_MORE_ITEMS;
1893 RegCloseKey(patchkey);
1896 RegCloseKey(localpatch);
1897 RegCloseKey(localprod);
1899 if (res != ERROR_SUCCESS)
1910 lstrcpyW(targetprod, prodcode);
1913 *targetctx = context;
1917 lstrcpynW(targetsid, usersid, *sidsize);
1918 if (lstrlenW(usersid) >= *sidsize)
1919 r = ERROR_MORE_DATA;
1924 *sidsize = lstrlenW(usersid);
1926 *sidsize *= sizeof(WCHAR);
1937 /***********************************************************************
1938 * MsiEnumPatchesExW [MSI.@]
1940 UINT WINAPI MsiEnumPatchesExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1941 DWORD dwContext, DWORD dwFilter, DWORD dwIndex, LPWSTR szPatchCode,
1942 LPWSTR szTargetProductCode, MSIINSTALLCONTEXT *pdwTargetProductContext,
1943 LPWSTR szTargetUserSid, LPDWORD pcchTargetUserSid)
1945 WCHAR squished_pc[GUID_SIZE];
1949 static int last_index = 0;
1951 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
1952 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext, dwFilter,
1953 dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext,
1954 szTargetUserSid, pcchTargetUserSid);
1956 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1957 return ERROR_INVALID_PARAMETER;
1959 if (!lstrcmpW(szUserSid, szLocalSid))
1960 return ERROR_INVALID_PARAMETER;
1962 if (dwContext & MSIINSTALLCONTEXT_MACHINE && szUserSid)
1963 return ERROR_INVALID_PARAMETER;
1965 if (dwContext <= MSIINSTALLCONTEXT_NONE ||
1966 dwContext > MSIINSTALLCONTEXT_ALL)
1967 return ERROR_INVALID_PARAMETER;
1969 if (dwFilter <= MSIPATCHSTATE_INVALID || dwFilter > MSIPATCHSTATE_ALL)
1970 return ERROR_INVALID_PARAMETER;
1972 if (dwIndex && dwIndex - last_index != 1)
1973 return ERROR_INVALID_PARAMETER;
1978 if (dwContext & MSIINSTALLCONTEXT_USERMANAGED)
1980 r = msi_check_product_patches(szProductCode, szUserSid,
1981 MSIINSTALLCONTEXT_USERMANAGED, dwFilter,
1982 dwIndex, &idx, szPatchCode,
1983 szTargetProductCode,
1984 pdwTargetProductContext,
1985 szTargetUserSid, pcchTargetUserSid);
1986 if (r != ERROR_NO_MORE_ITEMS)
1990 if (dwContext & MSIINSTALLCONTEXT_USERUNMANAGED)
1992 r = msi_check_product_patches(szProductCode, szUserSid,
1993 MSIINSTALLCONTEXT_USERUNMANAGED, dwFilter,
1994 dwIndex, &idx, szPatchCode,
1995 szTargetProductCode,
1996 pdwTargetProductContext,
1997 szTargetUserSid, pcchTargetUserSid);
1998 if (r != ERROR_NO_MORE_ITEMS)
2002 if (dwContext & MSIINSTALLCONTEXT_MACHINE)
2004 r = msi_check_product_patches(szProductCode, szUserSid,
2005 MSIINSTALLCONTEXT_MACHINE, dwFilter,
2006 dwIndex, &idx, szPatchCode,
2007 szTargetProductCode,
2008 pdwTargetProductContext,
2009 szTargetUserSid, pcchTargetUserSid);
2010 if (r != ERROR_NO_MORE_ITEMS)
2015 if (r == ERROR_SUCCESS)
2016 last_index = dwIndex;
2021 /***********************************************************************
2022 * MsiEnumPatchesA [MSI.@]
2024 UINT WINAPI MsiEnumPatchesA( LPCSTR szProduct, DWORD iPatchIndex,
2025 LPSTR lpPatchBuf, LPSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
2027 FIXME("%s %d %p %p %p\n", debugstr_a(szProduct),
2028 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
2029 return ERROR_NO_MORE_ITEMS;
2032 /***********************************************************************
2033 * MsiEnumPatchesW [MSI.@]
2035 UINT WINAPI MsiEnumPatchesW( LPCWSTR szProduct, DWORD iPatchIndex,
2036 LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
2038 FIXME("%s %d %p %p %p\n", debugstr_w(szProduct),
2039 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
2040 return ERROR_NO_MORE_ITEMS;
2043 UINT WINAPI MsiEnumProductsExA( LPCSTR szProductCode, LPCSTR szUserSid,
2044 DWORD dwContext, DWORD dwIndex, CHAR szInstalledProductCode[39],
2045 MSIINSTALLCONTEXT* pdwInstalledContext, LPSTR szSid, LPDWORD pcchSid)
2047 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_a(szProductCode), debugstr_a(szUserSid),
2048 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
2050 return ERROR_NO_MORE_ITEMS;
2053 UINT WINAPI MsiEnumProductsExW( LPCWSTR szProductCode, LPCWSTR szUserSid,
2054 DWORD dwContext, DWORD dwIndex, WCHAR szInstalledProductCode[39],
2055 MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, LPDWORD pcchSid)
2057 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_w(szProductCode), debugstr_w(szUserSid),
2058 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
2060 return ERROR_NO_MORE_ITEMS;