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_LocalClassesProd_fmt[] = {
191 'S','o','f','t','w','a','r','e','\\',
192 'C','l','a','s','s','e','s','\\',
193 'I','n','s','t','a','l','l','e','r','\\',
194 'P','r','o','d','u','c','t','s','\\','%','s',0};
196 static const WCHAR szInstaller_LocalClassesFeat_fmt[] = {
197 'S','o','f','t','w','a','r','e','\\',
198 'C','l','a','s','s','e','s','\\',
199 'I','n','s','t','a','l','l','e','r','\\',
200 'F','e','a','t','u','r','e','s','\\','%','s',0};
202 static const WCHAR szInstaller_LocalManagedProd_fmt[] = {
203 'S','o','f','t','w','a','r','e','\\',
204 'M','i','c','r','o','s','o','f','t','\\',
205 'W','i','n','d','o','w','s','\\',
206 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
207 'I','n','s','t','a','l','l','e','r','\\',
208 'M','a','n','a','g','e','d','\\','%','s','\\',
209 'I','n','s','t','a','l','l','e','r','\\',
210 'P','r','o','d','u','c','t','s','\\','%','s',0};
212 static const WCHAR szInstaller_LocalManagedFeat_fmt[] = {
213 'S','o','f','t','w','a','r','e','\\',
214 'M','i','c','r','o','s','o','f','t','\\',
215 'W','i','n','d','o','w','s','\\',
216 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
217 'I','n','s','t','a','l','l','e','r','\\',
218 'M','a','n','a','g','e','d','\\','%','s','\\',
219 'I','n','s','t','a','l','l','e','r','\\',
220 'F','e','a','t','u','r','e','s','\\','%','s',0};
222 static const WCHAR szInstaller_ClassesUpgrade_fmt[] = {
223 'I','n','s','t','a','l','l','e','r','\\',
224 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
227 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
231 if (lstrlenW(in) != 32)
246 out[n++] = in[17+i*2];
247 out[n++] = in[16+i*2];
252 out[n++] = in[17+i*2];
253 out[n++] = in[16+i*2];
260 BOOL squash_guid(LPCWSTR in, LPWSTR out)
267 if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
281 out[17+i*2] = in[n++];
282 out[16+i*2] = in[n++];
287 out[17+i*2] = in[n++];
288 out[16+i*2] = in[n++];
295 /* tables for encoding and decoding base85 */
296 static const unsigned char table_dec85[0x80] = {
297 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
298 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
299 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
300 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
301 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
302 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
303 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
304 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
307 static const char table_enc85[] =
308 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
309 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
313 * Converts a base85 encoded guid into a GUID pointer
314 * Base85 encoded GUIDs should be 20 characters long.
316 * returns TRUE if successful, FALSE if not
318 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
320 DWORD i, val = 0, base = 1, *p;
326 for( i=0; i<20; i++ )
333 val += table_dec85[str[i]] * base;
336 if( table_dec85[str[i]] == 0xff )
346 * Encodes a base85 guid given a GUID pointer
347 * Caller should provide a 21 character buffer for the encoded string.
349 * returns TRUE if successful, FALSE if not
351 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
353 unsigned int x, *p, i;
355 p = (unsigned int*) guid;
359 *str++ = table_enc85[x%85];
361 *str++ = table_enc85[x%85];
363 *str++ = table_enc85[x%85];
365 *str++ = table_enc85[x%85];
367 *str++ = table_enc85[x%85];
374 DWORD msi_version_str_to_dword(LPCWSTR p)
376 DWORD major, minor = 0, build = 0, version = 0;
387 p = strchrW(p+1, '.');
392 return MAKELONG(build, MAKEWORD(minor, major));
395 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
397 static const WCHAR emptyW[] = {0};
399 if (!value) value = emptyW;
400 len = (lstrlenW(value) + 1) * sizeof (WCHAR);
401 return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len );
404 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
407 while (*p) p += lstrlenW(p) + 1;
408 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
409 (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) );
412 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
414 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
417 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
422 r = RegCreateKeyW( hkey, path, &hsubkey );
423 if (r != ERROR_SUCCESS)
425 r = msi_reg_set_val_str( hsubkey, name, val );
426 RegCloseKey( hsubkey );
430 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
436 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
437 if (r != ERROR_SUCCESS)
440 len += sizeof (WCHAR);
441 val = msi_alloc( len );
445 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
449 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
451 DWORD type, len = sizeof (DWORD);
452 LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
453 return r == ERROR_SUCCESS && type == REG_DWORD;
456 static UINT get_user_sid(LPWSTR *usersid)
463 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
464 return ERROR_FUNCTION_FAILED;
467 if (!GetTokenInformation(token, TokenUser, buf, size, &size)) {
469 return ERROR_FUNCTION_FAILED;
472 user = (PTOKEN_USER)buf;
473 if (!ConvertSidToStringSidW(user->User.Sid, usersid)) {
475 return ERROR_FUNCTION_FAILED;
478 return ERROR_SUCCESS;
481 UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create)
484 WCHAR keypath[0x200];
485 TRACE("%s\n",debugstr_w(szProduct));
487 sprintfW(keypath,szUninstall_fmt,szProduct);
490 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
492 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
497 UINT MSIREG_DeleteUninstallKey(LPCWSTR szProduct)
499 WCHAR keypath[0x200];
500 TRACE("%s\n",debugstr_w(szProduct));
502 sprintfW(keypath,szUninstall_fmt,szProduct);
504 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
507 UINT MSIREG_OpenProductKey(LPCWSTR szProduct, LPCWSTR szUserSid,
508 MSIINSTALLCONTEXT context, HKEY *key, BOOL create)
511 LPWSTR usersid = NULL;
512 HKEY root = HKEY_LOCAL_MACHINE;
513 WCHAR squished_pc[GUID_SIZE];
514 WCHAR keypath[MAX_PATH];
516 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create);
518 if (!squash_guid(szProduct, squished_pc))
519 return ERROR_FUNCTION_FAILED;
521 TRACE("squished (%s)\n", debugstr_w(squished_pc));
523 if (context == MSIINSTALLCONTEXT_MACHINE)
525 sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc);
527 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
529 root = HKEY_CURRENT_USER;
530 sprintfW(keypath, szUserProduct_fmt, squished_pc);
536 r = get_user_sid(&usersid);
537 if (r != ERROR_SUCCESS || !usersid)
539 ERR("Failed to retrieve user SID: %d\n", r);
546 sprintfW(keypath, szInstaller_LocalManagedProd_fmt,
547 szUserSid, squished_pc);
552 return RegCreateKeyW(root, keypath, key);
554 return RegOpenKeyW(root, keypath, key);
557 UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct)
559 WCHAR squished_pc[GUID_SIZE];
560 WCHAR keypath[0x200];
562 TRACE("%s\n",debugstr_w(szProduct));
563 if (!squash_guid(szProduct,squished_pc))
564 return ERROR_FUNCTION_FAILED;
565 TRACE("squished (%s)\n", debugstr_w(squished_pc));
567 sprintfW(keypath,szUserProduct_fmt,squished_pc);
569 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
572 UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
575 WCHAR squished_pc[GUID_SIZE];
576 WCHAR keypath[0x200];
578 TRACE("%s\n",debugstr_w(szPatch));
579 if (!squash_guid(szPatch,squished_pc))
580 return ERROR_FUNCTION_FAILED;
581 TRACE("squished (%s)\n", debugstr_w(squished_pc));
583 sprintfW(keypath,szUserPatch_fmt,squished_pc);
586 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
588 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
593 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
594 HKEY *key, BOOL create)
598 HKEY root = HKEY_LOCAL_MACHINE;
599 WCHAR squished_pc[GUID_SIZE];
600 WCHAR keypath[MAX_PATH];
602 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create);
604 if (!squash_guid(szProduct, squished_pc))
605 return ERROR_FUNCTION_FAILED;
607 TRACE("squished (%s)\n", debugstr_w(squished_pc));
609 if (context == MSIINSTALLCONTEXT_MACHINE)
611 sprintfW(keypath, szInstaller_LocalClassesFeat_fmt, squished_pc);
613 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
615 root = HKEY_CURRENT_USER;
616 sprintfW(keypath, szUserFeatures_fmt, squished_pc);
620 r = get_user_sid(&usersid);
621 if (r != ERROR_SUCCESS || !usersid)
623 ERR("Failed to retrieve user SID: %d\n", r);
627 sprintfW(keypath, szInstaller_LocalManagedFeat_fmt, usersid, squished_pc);
632 return RegCreateKeyW(root, keypath, key);
634 return RegOpenKeyW(root, keypath, key);
637 UINT MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct)
639 WCHAR squished_pc[GUID_SIZE];
640 WCHAR keypath[0x200];
642 TRACE("%s\n",debugstr_w(szProduct));
643 if (!squash_guid(szProduct,squished_pc))
644 return ERROR_FUNCTION_FAILED;
645 TRACE("squished (%s)\n", debugstr_w(squished_pc));
647 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
648 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
651 static UINT MSIREG_OpenInstallerFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
654 WCHAR squished_pc[GUID_SIZE];
655 WCHAR keypath[0x200];
657 TRACE("%s\n",debugstr_w(szProduct));
658 if (!squash_guid(szProduct,squished_pc))
659 return ERROR_FUNCTION_FAILED;
660 TRACE("squished (%s)\n", debugstr_w(squished_pc));
662 sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
665 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
667 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
672 UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context,
673 HKEY *key, BOOL create)
677 WCHAR squished_pc[GUID_SIZE];
678 WCHAR keypath[0x200];
680 TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create);
682 if (!squash_guid(szProduct, squished_pc))
683 return ERROR_FUNCTION_FAILED;
685 TRACE("squished (%s)\n", debugstr_w(squished_pc));
687 if (context == MSIINSTALLCONTEXT_MACHINE)
689 sprintfW(keypath, szUserDataFeatures_fmt, szLocalSid, squished_pc);
693 r = get_user_sid(&usersid);
694 if (r != ERROR_SUCCESS || !usersid)
696 ERR("Failed to retrieve user SID: %d\n", r);
700 sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc);
705 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
707 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
710 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
713 WCHAR squished_cc[GUID_SIZE];
714 WCHAR keypath[0x200];
716 TRACE("%s\n",debugstr_w(szComponent));
717 if (!squash_guid(szComponent,squished_cc))
718 return ERROR_FUNCTION_FAILED;
719 TRACE("squished (%s)\n", debugstr_w(squished_cc));
721 sprintfW(keypath,szUser_Components_fmt,squished_cc);
724 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
726 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
731 UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid,
732 HKEY *key, BOOL create)
735 WCHAR comp[GUID_SIZE];
736 WCHAR keypath[0x200];
739 TRACE("%s\n", debugstr_w(szComponent));
740 if (!squash_guid(szComponent, comp))
741 return ERROR_FUNCTION_FAILED;
742 TRACE("squished (%s)\n", debugstr_w(comp));
746 rc = get_user_sid(&usersid);
747 if (rc != ERROR_SUCCESS || !usersid)
749 ERR("Failed to retrieve user SID: %d\n", rc);
753 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
757 sprintfW(keypath, szUserDataComp_fmt, szUserSid, comp);
760 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
762 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
767 UINT MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid)
770 WCHAR comp[GUID_SIZE];
771 WCHAR keypath[0x200];
774 TRACE("%s\n", debugstr_w(szComponent));
775 if (!squash_guid(szComponent, comp))
776 return ERROR_FUNCTION_FAILED;
777 TRACE("squished (%s)\n", debugstr_w(comp));
781 rc = get_user_sid(&usersid);
782 if (rc != ERROR_SUCCESS || !usersid)
784 ERR("Failed to retrieve user SID: %d\n", rc);
788 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
792 sprintfW(keypath, szUserDataComp_fmt, szUserSid, comp);
794 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
797 UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContext,
798 LPCWSTR szUserSid, HKEY *key, BOOL create)
801 WCHAR squished_pc[GUID_SIZE];
802 WCHAR keypath[0x200];
805 TRACE("%s\n", debugstr_w(szProduct));
806 if (!squash_guid(szProduct, squished_pc))
807 return ERROR_FUNCTION_FAILED;
808 TRACE("squished (%s)\n", debugstr_w(squished_pc));
810 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
811 sprintfW(keypath, szUserDataProd_fmt, szLocalSid, squished_pc);
813 sprintfW(keypath, szUserDataProd_fmt, szUserSid, squished_pc);
816 rc = get_user_sid(&usersid);
817 if (rc != ERROR_SUCCESS || !usersid)
819 ERR("Failed to retrieve user SID: %d\n", rc);
823 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
828 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
830 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
835 UINT MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch, MSIINSTALLCONTEXT dwContext,
836 HKEY *key, BOOL create)
839 WCHAR squished_patch[GUID_SIZE];
840 WCHAR keypath[0x200];
843 TRACE("%s\n", debugstr_w(szPatch));
844 if (!squash_guid(szPatch, squished_patch))
845 return ERROR_FUNCTION_FAILED;
846 TRACE("squished (%s)\n", debugstr_w(squished_patch));
848 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
849 sprintfW(keypath, szUserDataPatch_fmt, szLocalSid, squished_patch);
852 rc = get_user_sid(&usersid);
853 if (rc != ERROR_SUCCESS || !usersid)
855 ERR("Failed to retrieve user SID: %d\n", rc);
859 sprintfW(keypath, szUserDataPatch_fmt, usersid, squished_patch);
864 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
866 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
869 UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContext,
870 LPCWSTR szUserSid, HKEY *key, BOOL create)
874 WCHAR squished_pc[GUID_SIZE];
875 WCHAR keypath[0x200];
877 TRACE("%s\n", debugstr_w(szProduct));
878 if (!squash_guid(szProduct, squished_pc))
879 return ERROR_FUNCTION_FAILED;
880 TRACE("squished (%s)\n", debugstr_w(squished_pc));
882 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
883 sprintfW(keypath, szInstallProperties_fmt, szLocalSid, squished_pc);
885 sprintfW(keypath, szInstallProperties_fmt, szUserSid, squished_pc);
888 rc = get_user_sid(&usersid);
889 if (rc != ERROR_SUCCESS || !usersid)
891 ERR("Failed to retrieve user SID: %d\n", rc);
895 sprintfW(keypath, szInstallProperties_fmt, usersid, squished_pc);
900 return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
902 return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
905 UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)
908 WCHAR squished_pc[GUID_SIZE];
909 WCHAR keypath[0x200];
912 TRACE("%s\n", debugstr_w(szProduct));
913 if (!squash_guid(szProduct, squished_pc))
914 return ERROR_FUNCTION_FAILED;
915 TRACE("squished (%s)\n", debugstr_w(squished_pc));
917 rc = get_user_sid(&usersid);
918 if (rc != ERROR_SUCCESS || !usersid)
920 ERR("Failed to retrieve user SID: %d\n", rc);
924 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
927 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
930 UINT MSIREG_DeleteProductKey(LPCWSTR szProduct)
932 WCHAR squished_pc[GUID_SIZE];
933 WCHAR keypath[0x200];
935 TRACE("%s\n", debugstr_w(szProduct));
936 if (!squash_guid(szProduct, squished_pc))
937 return ERROR_FUNCTION_FAILED;
938 TRACE("squished (%s)\n", debugstr_w(squished_pc));
940 sprintfW(keypath, szInstaller_Products_fmt, squished_pc);
942 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
945 UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
948 WCHAR squished_pc[GUID_SIZE];
949 WCHAR keypath[0x200];
951 TRACE("%s\n",debugstr_w(szPatch));
952 if (!squash_guid(szPatch,squished_pc))
953 return ERROR_FUNCTION_FAILED;
954 TRACE("squished (%s)\n", debugstr_w(squished_pc));
956 sprintfW(keypath,szInstaller_Patches_fmt,squished_pc);
959 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
961 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
966 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
969 WCHAR squished_pc[GUID_SIZE];
970 WCHAR keypath[0x200];
972 TRACE("%s\n",debugstr_w(szUpgradeCode));
973 if (!squash_guid(szUpgradeCode,squished_pc))
974 return ERROR_FUNCTION_FAILED;
975 TRACE("squished (%s)\n", debugstr_w(squished_pc));
977 sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
980 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
982 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
987 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
990 WCHAR squished_pc[GUID_SIZE];
991 WCHAR keypath[0x200];
993 TRACE("%s\n",debugstr_w(szUpgradeCode));
994 if (!squash_guid(szUpgradeCode,squished_pc))
995 return ERROR_FUNCTION_FAILED;
996 TRACE("squished (%s)\n", debugstr_w(squished_pc));
998 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
1001 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
1003 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
1008 UINT MSIREG_DeleteUserUpgradeCodesKey(LPCWSTR szUpgradeCode)
1010 WCHAR squished_pc[GUID_SIZE];
1011 WCHAR keypath[0x200];
1013 TRACE("%s\n",debugstr_w(szUpgradeCode));
1014 if (!squash_guid(szUpgradeCode,squished_pc))
1015 return ERROR_FUNCTION_FAILED;
1016 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1018 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
1020 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
1023 UINT MSIREG_DeleteLocalClassesProductKey(LPCWSTR szProductCode)
1025 WCHAR squished_pc[GUID_SIZE];
1026 WCHAR keypath[0x200];
1028 TRACE("%s\n", debugstr_w(szProductCode));
1030 if (!squash_guid(szProductCode, squished_pc))
1031 return ERROR_FUNCTION_FAILED;
1033 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1035 sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc);
1037 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
1040 UINT MSIREG_DeleteLocalClassesFeaturesKey(LPCWSTR szProductCode)
1042 WCHAR squished_pc[GUID_SIZE];
1043 WCHAR keypath[0x200];
1045 TRACE("%s\n", debugstr_w(szProductCode));
1047 if (!squash_guid(szProductCode, squished_pc))
1048 return ERROR_FUNCTION_FAILED;
1050 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1052 sprintfW(keypath, szInstaller_LocalClassesFeat_fmt, squished_pc);
1054 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
1057 UINT MSIREG_OpenClassesUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
1059 WCHAR squished_pc[GUID_SIZE];
1060 WCHAR keypath[0x200];
1062 TRACE("%s\n", debugstr_w(szUpgradeCode));
1063 if (!squash_guid(szUpgradeCode, squished_pc))
1064 return ERROR_FUNCTION_FAILED;
1065 TRACE("squished (%s)\n", debugstr_w(squished_pc));
1067 sprintfW(keypath, szInstaller_ClassesUpgrade_fmt, squished_pc);
1070 return RegCreateKeyW(HKEY_CLASSES_ROOT, keypath, key);
1072 return RegOpenKeyW(HKEY_CLASSES_ROOT, keypath, key);
1075 /*************************************************************************
1076 * MsiDecomposeDescriptorW [MSI.@]
1078 * Decomposes an MSI descriptor into product, feature and component parts.
1079 * An MSI descriptor is a string of the form:
1080 * [base 85 guid] [feature code] '>' [base 85 guid]
1083 * szDescriptor [I] the descriptor to decompose
1084 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
1085 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
1086 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
1087 * pUsed [O] the length of the descriptor
1090 * ERROR_SUCCESS if everything worked correctly
1091 * ERROR_INVALID_PARAMETER if the descriptor was invalid
1094 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
1095 LPWSTR szFeature, LPWSTR szComponent, LPDWORD pUsed )
1099 GUID product, component;
1101 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
1102 szFeature, szComponent, pUsed);
1104 r = decode_base85_guid( szDescriptor, &product );
1106 return ERROR_INVALID_PARAMETER;
1108 TRACE("product %s\n", debugstr_guid( &product ));
1110 p = strchrW(&szDescriptor[20],'>');
1112 return ERROR_INVALID_PARAMETER;
1114 len = (p - &szDescriptor[20]);
1115 if( len > MAX_FEATURE_CHARS )
1116 return ERROR_INVALID_PARAMETER;
1118 TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len ));
1120 r = decode_base85_guid( p+1, &component );
1122 return ERROR_INVALID_PARAMETER;
1124 TRACE("component %s\n", debugstr_guid( &component ));
1127 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
1129 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
1132 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
1135 len = ( &p[21] - szDescriptor );
1137 TRACE("length = %d\n", len);
1140 return ERROR_SUCCESS;
1143 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
1144 LPSTR szFeature, LPSTR szComponent, LPDWORD pUsed )
1146 WCHAR product[MAX_FEATURE_CHARS+1];
1147 WCHAR feature[MAX_FEATURE_CHARS+1];
1148 WCHAR component[MAX_FEATURE_CHARS+1];
1149 LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
1152 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
1153 szFeature, szComponent, pUsed);
1155 str = strdupAtoW( szDescriptor );
1156 if( szDescriptor && !str )
1157 return ERROR_OUTOFMEMORY;
1166 r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
1168 if (r == ERROR_SUCCESS)
1170 WideCharToMultiByte( CP_ACP, 0, p, -1,
1171 szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
1172 WideCharToMultiByte( CP_ACP, 0, f, -1,
1173 szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
1174 WideCharToMultiByte( CP_ACP, 0, c, -1,
1175 szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
1183 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
1186 WCHAR szwGuid[GUID_SIZE];
1188 TRACE("%d %p\n", index, lpguid);
1191 return ERROR_INVALID_PARAMETER;
1192 r = MsiEnumProductsW(index, szwGuid);
1193 if( r == ERROR_SUCCESS )
1194 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1199 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
1201 HKEY hkeyProducts = 0;
1203 WCHAR szKeyName[SQUISH_GUID_SIZE];
1205 TRACE("%d %p\n", index, lpguid);
1208 return ERROR_INVALID_PARAMETER;
1210 r = RegCreateKeyW(HKEY_LOCAL_MACHINE, szInstaller_Products, &hkeyProducts);
1211 if( r != ERROR_SUCCESS )
1212 return ERROR_NO_MORE_ITEMS;
1214 r = RegEnumKeyW(hkeyProducts, index, szKeyName, SQUISH_GUID_SIZE);
1215 if( r == ERROR_SUCCESS )
1216 unsquash_guid(szKeyName, lpguid);
1217 RegCloseKey(hkeyProducts);
1222 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
1223 LPSTR szFeature, LPSTR szParent)
1226 WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
1227 LPWSTR szwProduct = NULL;
1229 TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent);
1233 szwProduct = strdupAtoW( szProduct );
1235 return ERROR_OUTOFMEMORY;
1238 r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
1239 if( r == ERROR_SUCCESS )
1241 WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
1242 szFeature, GUID_SIZE, NULL, NULL);
1243 WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
1244 szParent, GUID_SIZE, NULL, NULL);
1247 msi_free( szwProduct);
1252 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
1253 LPWSTR szFeature, LPWSTR szParent)
1255 HKEY hkeyProduct = 0;
1258 TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
1261 return ERROR_INVALID_PARAMETER;
1263 r = MSIREG_OpenInstallerFeaturesKey(szProduct,&hkeyProduct,FALSE);
1264 if( r != ERROR_SUCCESS )
1265 return ERROR_NO_MORE_ITEMS;
1268 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
1269 RegCloseKey(hkeyProduct);
1274 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
1277 WCHAR szwGuid[GUID_SIZE];
1279 TRACE("%d %p\n", index, lpguid);
1281 r = MsiEnumComponentsW(index, szwGuid);
1282 if( r == ERROR_SUCCESS )
1283 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1288 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
1290 HKEY hkeyComponents = 0;
1292 WCHAR szKeyName[SQUISH_GUID_SIZE];
1294 TRACE("%d %p\n", index, lpguid);
1296 r = RegCreateKeyW(HKEY_LOCAL_MACHINE, szInstaller_Components, &hkeyComponents);
1297 if( r != ERROR_SUCCESS )
1298 return ERROR_NO_MORE_ITEMS;
1300 r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
1301 if( r == ERROR_SUCCESS )
1302 unsquash_guid(szKeyName, lpguid);
1303 RegCloseKey(hkeyComponents);
1308 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
1311 WCHAR szwProduct[GUID_SIZE];
1312 LPWSTR szwComponent = NULL;
1314 TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
1317 return ERROR_INVALID_PARAMETER;
1321 szwComponent = strdupAtoW( szComponent );
1323 return ERROR_OUTOFMEMORY;
1326 r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
1327 if( r == ERROR_SUCCESS )
1329 WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
1330 szProduct, GUID_SIZE, NULL, NULL);
1333 msi_free( szwComponent);
1338 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
1342 WCHAR szValName[SQUISH_GUID_SIZE];
1344 TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct);
1346 if (!szComponent || !*szComponent || !szProduct)
1347 return ERROR_INVALID_PARAMETER;
1349 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkeyComp, FALSE) != ERROR_SUCCESS &&
1350 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkeyComp, FALSE) != ERROR_SUCCESS)
1351 return ERROR_UNKNOWN_COMPONENT;
1353 /* see if there are any products at all */
1354 sz = SQUISH_GUID_SIZE;
1355 r = RegEnumValueW(hkeyComp, 0, szValName, &sz, NULL, NULL, NULL, NULL);
1356 if (r != ERROR_SUCCESS)
1358 RegCloseKey(hkeyComp);
1361 return ERROR_INVALID_PARAMETER;
1363 return ERROR_UNKNOWN_COMPONENT;
1366 sz = SQUISH_GUID_SIZE;
1367 r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
1368 if( r == ERROR_SUCCESS )
1369 unsquash_guid(szValName, szProduct);
1371 RegCloseKey(hkeyComp);
1376 static UINT MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
1377 awstring *lpQualBuf, LPDWORD pcchQual,
1378 awstring *lpAppBuf, LPDWORD pcchAppBuf )
1380 DWORD name_sz, val_sz, name_max, val_max, type, ofs;
1381 LPWSTR name = NULL, val = NULL;
1385 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1386 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
1389 return ERROR_INVALID_PARAMETER;
1391 r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
1392 if (r != ERROR_SUCCESS)
1393 return ERROR_UNKNOWN_COMPONENT;
1395 /* figure out how big the name is we want to return */
1397 r = ERROR_OUTOFMEMORY;
1398 name = msi_alloc( name_max * sizeof(WCHAR) );
1403 r = ERROR_OUTOFMEMORY;
1404 val = msi_alloc( val_max );
1408 /* loop until we allocate enough memory */
1413 r = RegEnumValueW( key, iIndex, name, &name_sz,
1414 NULL, &type, (LPBYTE)val, &val_sz );
1415 if (r == ERROR_SUCCESS)
1417 if (r != ERROR_MORE_DATA)
1420 if (type != REG_MULTI_SZ)
1422 ERR("component data has wrong type (%d)\n", type);
1426 r = ERROR_OUTOFMEMORY;
1427 if ((name_sz+1) >= name_max)
1431 name = msi_alloc( name_max * sizeof (WCHAR) );
1436 if (val_sz > val_max)
1438 val_max = val_sz + sizeof (WCHAR);
1440 val = msi_alloc( val_max * sizeof (WCHAR) );
1445 ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
1450 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
1451 if (r != ERROR_SUCCESS)
1454 TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
1456 r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
1457 r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
1459 if (r2 != ERROR_SUCCESS)
1470 /*************************************************************************
1471 * MsiEnumComponentQualifiersA [MSI.@]
1473 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
1474 LPSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1475 LPSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1477 awstring qual, appdata;
1481 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex,
1482 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1483 pcchApplicationDataBuf);
1485 comp = strdupAtoW( szComponent );
1486 if (szComponent && !comp)
1487 return ERROR_OUTOFMEMORY;
1489 qual.unicode = FALSE;
1490 qual.str.a = lpQualifierBuf;
1492 appdata.unicode = FALSE;
1493 appdata.str.a = lpApplicationDataBuf;
1495 r = MSI_EnumComponentQualifiers( comp, iIndex,
1496 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1501 /*************************************************************************
1502 * MsiEnumComponentQualifiersW [MSI.@]
1504 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
1505 LPWSTR lpQualifierBuf, LPDWORD pcchQualifierBuf,
1506 LPWSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf )
1508 awstring qual, appdata;
1510 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1511 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1512 pcchApplicationDataBuf);
1514 qual.unicode = TRUE;
1515 qual.str.w = lpQualifierBuf;
1517 appdata.unicode = TRUE;
1518 appdata.str.w = lpApplicationDataBuf;
1520 return MSI_EnumComponentQualifiers( szComponent, iIndex,
1521 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1524 /*************************************************************************
1525 * MsiEnumRelatedProductsW [MSI.@]
1528 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
1529 DWORD iProductIndex, LPWSTR lpProductBuf)
1533 DWORD dwSize = SQUISH_GUID_SIZE;
1534 WCHAR szKeyName[SQUISH_GUID_SIZE];
1536 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved,
1537 iProductIndex, lpProductBuf);
1539 if (NULL == szUpgradeCode)
1540 return ERROR_INVALID_PARAMETER;
1541 if (NULL == lpProductBuf)
1542 return ERROR_INVALID_PARAMETER;
1544 r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1545 if (r != ERROR_SUCCESS)
1546 return ERROR_NO_MORE_ITEMS;
1548 r = RegEnumValueW(hkey, iProductIndex, szKeyName, &dwSize, NULL, NULL, NULL, NULL);
1549 if( r == ERROR_SUCCESS )
1550 unsquash_guid(szKeyName, lpProductBuf);
1556 /*************************************************************************
1557 * MsiEnumRelatedProductsA [MSI.@]
1560 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1561 DWORD iProductIndex, LPSTR lpProductBuf)
1563 LPWSTR szwUpgradeCode = NULL;
1564 WCHAR productW[GUID_SIZE];
1567 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1568 iProductIndex, lpProductBuf);
1572 szwUpgradeCode = strdupAtoW( szUpgradeCode );
1573 if( !szwUpgradeCode )
1574 return ERROR_OUTOFMEMORY;
1577 r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1578 iProductIndex, productW );
1579 if (r == ERROR_SUCCESS)
1581 WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1582 lpProductBuf, GUID_SIZE, NULL, NULL );
1584 msi_free( szwUpgradeCode);
1588 /***********************************************************************
1589 * MsiEnumPatchesExA [MSI.@]
1591 UINT WINAPI MsiEnumPatchesExA(LPCSTR szProductCode, LPCSTR szUserSid,
1592 DWORD dwContext, DWORD dwFilter, DWORD dwIndex, LPSTR szPatchCode,
1593 LPSTR szTargetProductCode, MSIINSTALLCONTEXT *pdwTargetProductContext,
1594 LPSTR szTargetUserSid, LPDWORD pcchTargetUserSid)
1596 LPWSTR prodcode = NULL;
1597 LPWSTR usersid = NULL;
1598 LPWSTR targsid = NULL;
1599 WCHAR patch[GUID_SIZE];
1600 WCHAR targprod[GUID_SIZE];
1604 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
1605 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext, dwFilter,
1606 dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext,
1607 szTargetUserSid, pcchTargetUserSid);
1609 if (szTargetUserSid && !pcchTargetUserSid)
1610 return ERROR_INVALID_PARAMETER;
1612 if (szProductCode) prodcode = strdupAtoW(szProductCode);
1613 if (szUserSid) usersid = strdupAtoW(szUserSid);
1615 r = MsiEnumPatchesExW(prodcode, usersid, dwContext, dwFilter, dwIndex,
1616 patch, targprod, pdwTargetProductContext,
1618 if (r != ERROR_SUCCESS)
1621 WideCharToMultiByte(CP_ACP, 0, patch, -1, szPatchCode,
1622 GUID_SIZE, NULL, NULL);
1623 WideCharToMultiByte(CP_ACP, 0, targprod, -1, szTargetProductCode,
1624 GUID_SIZE, NULL, NULL);
1626 if (!szTargetUserSid)
1628 if (pcchTargetUserSid)
1629 *pcchTargetUserSid = len;
1634 targsid = msi_alloc(++len * sizeof(WCHAR));
1637 r = ERROR_OUTOFMEMORY;
1641 r = MsiEnumPatchesExW(prodcode, usersid, dwContext, dwFilter, dwIndex,
1642 patch, targprod, pdwTargetProductContext,
1644 if (r != ERROR_SUCCESS || !szTargetUserSid)
1647 WideCharToMultiByte(CP_ACP, 0, targsid, -1, szTargetUserSid,
1648 *pcchTargetUserSid, NULL, NULL);
1650 len = lstrlenW(targsid);
1651 if (*pcchTargetUserSid < len + 1)
1653 r = ERROR_MORE_DATA;
1654 *pcchTargetUserSid = len * sizeof(WCHAR);
1657 *pcchTargetUserSid = len;
1667 static UINT msi_get_patch_state(LPCWSTR prodcode, LPCWSTR usersid,
1668 MSIINSTALLCONTEXT context,
1669 LPWSTR patch, MSIPATCHSTATE *state)
1671 DWORD type, val, size;
1672 HKEY prod, hkey = 0;
1675 UINT r = ERROR_NO_MORE_ITEMS;
1677 static const WCHAR szPatches[] = {'P','a','t','c','h','e','s',0};
1678 static const WCHAR szState[] = {'S','t','a','t','e',0};
1680 *state = MSIPATCHSTATE_INVALID;
1682 r = MSIREG_OpenUserDataProductKey(prodcode, context,
1683 usersid, &prod, FALSE);
1684 if (r != ERROR_SUCCESS)
1685 return ERROR_NO_MORE_ITEMS;
1687 res = RegOpenKeyExW(prod, szPatches, 0, KEY_READ, &hkey);
1688 if (res != ERROR_SUCCESS)
1691 res = RegOpenKeyExW(hkey, patch, 0, KEY_READ, &udpatch);
1692 if (res != ERROR_SUCCESS)
1695 size = sizeof(DWORD);
1696 res = RegGetValueW(udpatch, NULL, szState, RRF_RT_DWORD, &type, &val, &size);
1697 if (res != ERROR_SUCCESS ||
1698 val < MSIPATCHSTATE_APPLIED || val > MSIPATCHSTATE_REGISTERED)
1700 r = ERROR_BAD_CONFIGURATION;
1708 RegCloseKey(udpatch);
1715 static UINT msi_check_product_patches(LPCWSTR prodcode, LPCWSTR usersid,
1716 MSIINSTALLCONTEXT context, DWORD filter, DWORD index, DWORD *idx,
1717 LPWSTR patch, LPWSTR targetprod, MSIINSTALLCONTEXT *targetctx,
1718 LPWSTR targetsid, DWORD *sidsize, LPWSTR *transforms)
1720 MSIPATCHSTATE state;
1721 LPWSTR ptr, patches = NULL;
1722 HKEY prod, patchkey = 0;
1723 HKEY localprod = 0, localpatch = 0;
1726 UINT temp, r = ERROR_NO_MORE_ITEMS;
1728 static const WCHAR szPatches[] = {'P','a','t','c','h','e','s',0};
1729 static const WCHAR szState[] = {'S','t','a','t','e',0};
1730 static const WCHAR szEmpty[] = {0};
1732 if (MSIREG_OpenProductKey(prodcode, usersid, context,
1733 &prod, FALSE) != ERROR_SUCCESS)
1734 return ERROR_NO_MORE_ITEMS;
1737 res = RegGetValueW(prod, szPatches, szPatches, RRF_RT_ANY, &type, NULL,
1739 if (res != ERROR_SUCCESS)
1742 if (type != REG_MULTI_SZ)
1744 r = ERROR_BAD_CONFIGURATION;
1748 patches = msi_alloc(size);
1751 r = ERROR_OUTOFMEMORY;
1755 res = RegGetValueW(prod, szPatches, szPatches, RRF_RT_ANY, &type,
1757 if (res != ERROR_SUCCESS)
1761 for (ptr = patches; *ptr && r == ERROR_NO_MORE_ITEMS; ptr += lstrlenW(ptr))
1763 if (!unsquash_guid(ptr, patch))
1765 r = ERROR_BAD_CONFIGURATION;
1770 res = RegGetValueW(prod, szPatches, ptr, RRF_RT_REG_SZ,
1771 &type, NULL, &size);
1772 if (res != ERROR_SUCCESS)
1777 *transforms = msi_alloc(size);
1780 r = ERROR_OUTOFMEMORY;
1784 res = RegGetValueW(prod, szPatches, ptr, RRF_RT_REG_SZ,
1785 &type, *transforms, &size);
1786 if (res != ERROR_SUCCESS)
1790 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1792 if (!(filter & MSIPATCHSTATE_APPLIED))
1794 temp = msi_get_patch_state(prodcode, usersid, context,
1796 if (temp == ERROR_BAD_CONFIGURATION)
1798 r = ERROR_BAD_CONFIGURATION;
1802 if (temp != ERROR_SUCCESS || !(filter & state))
1806 else if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
1808 if (!(filter & MSIPATCHSTATE_APPLIED))
1810 temp = msi_get_patch_state(prodcode, usersid, context,
1812 if (temp == ERROR_BAD_CONFIGURATION)
1814 r = ERROR_BAD_CONFIGURATION;
1818 if (temp != ERROR_SUCCESS || !(filter & state))
1823 temp = MSIREG_OpenUserDataPatchKey(patch, context,
1825 RegCloseKey(patchkey);
1826 if (temp != ERROR_SUCCESS)
1830 else if (context == MSIINSTALLCONTEXT_MACHINE)
1834 if (MSIREG_OpenUserDataProductKey(prodcode, context, NULL, &localprod, FALSE) == ERROR_SUCCESS &&
1835 RegOpenKeyExW(localprod, szPatches, 0, KEY_READ, &localpatch) == ERROR_SUCCESS &&
1836 RegOpenKeyExW(localpatch, ptr, 0, KEY_READ, &patchkey) == ERROR_SUCCESS)
1838 res = RegGetValueW(patchkey, NULL, szState, RRF_RT_REG_DWORD,
1839 &type, &state, &size);
1841 if (!(filter & state))
1842 res = ERROR_NO_MORE_ITEMS;
1844 RegCloseKey(patchkey);
1847 RegCloseKey(localpatch);
1848 RegCloseKey(localprod);
1850 if (res != ERROR_SUCCESS)
1862 lstrcpyW(targetprod, prodcode);
1865 *targetctx = context;
1869 lstrcpynW(targetsid, usersid, *sidsize);
1870 if (lstrlenW(usersid) >= *sidsize)
1871 r = ERROR_MORE_DATA;
1876 *sidsize = lstrlenW(usersid);
1878 *sidsize *= sizeof(WCHAR);
1889 static UINT msi_enum_patches(LPCWSTR szProductCode, LPCWSTR szUserSid,
1890 DWORD dwContext, DWORD dwFilter, DWORD dwIndex, DWORD *idx,
1891 LPWSTR szPatchCode, LPWSTR szTargetProductCode,
1892 MSIINSTALLCONTEXT *pdwTargetProductContext, LPWSTR szTargetUserSid,
1893 LPDWORD pcchTargetUserSid, LPWSTR *szTransforms)
1895 LPWSTR usersid = NULL;
1896 UINT r = ERROR_INVALID_PARAMETER;
1900 get_user_sid(&usersid);
1901 szUserSid = usersid;
1904 if (dwContext & MSIINSTALLCONTEXT_USERMANAGED)
1906 r = msi_check_product_patches(szProductCode, szUserSid,
1907 MSIINSTALLCONTEXT_USERMANAGED, dwFilter,
1908 dwIndex, idx, szPatchCode,
1909 szTargetProductCode,
1910 pdwTargetProductContext, szTargetUserSid,
1911 pcchTargetUserSid, szTransforms);
1912 if (r != ERROR_NO_MORE_ITEMS)
1916 if (dwContext & MSIINSTALLCONTEXT_USERUNMANAGED)
1918 r = msi_check_product_patches(szProductCode, szUserSid,
1919 MSIINSTALLCONTEXT_USERUNMANAGED, dwFilter,
1920 dwIndex, idx, szPatchCode,
1921 szTargetProductCode,
1922 pdwTargetProductContext, szTargetUserSid,
1923 pcchTargetUserSid, szTransforms);
1924 if (r != ERROR_NO_MORE_ITEMS)
1928 if (dwContext & MSIINSTALLCONTEXT_MACHINE)
1930 r = msi_check_product_patches(szProductCode, szUserSid,
1931 MSIINSTALLCONTEXT_MACHINE, dwFilter,
1932 dwIndex, idx, szPatchCode,
1933 szTargetProductCode,
1934 pdwTargetProductContext, szTargetUserSid,
1935 pcchTargetUserSid, szTransforms);
1936 if (r != ERROR_NO_MORE_ITEMS)
1945 /***********************************************************************
1946 * MsiEnumPatchesExW [MSI.@]
1948 UINT WINAPI MsiEnumPatchesExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1949 DWORD dwContext, DWORD dwFilter, DWORD dwIndex, LPWSTR szPatchCode,
1950 LPWSTR szTargetProductCode, MSIINSTALLCONTEXT *pdwTargetProductContext,
1951 LPWSTR szTargetUserSid, LPDWORD pcchTargetUserSid)
1953 WCHAR squished_pc[GUID_SIZE];
1957 static int last_index = 0;
1959 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n",
1960 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext, dwFilter,
1961 dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext,
1962 szTargetUserSid, pcchTargetUserSid);
1964 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1965 return ERROR_INVALID_PARAMETER;
1967 if (!lstrcmpW(szUserSid, szLocalSid))
1968 return ERROR_INVALID_PARAMETER;
1970 if (dwContext & MSIINSTALLCONTEXT_MACHINE && szUserSid)
1971 return ERROR_INVALID_PARAMETER;
1973 if (dwContext <= MSIINSTALLCONTEXT_NONE ||
1974 dwContext > MSIINSTALLCONTEXT_ALL)
1975 return ERROR_INVALID_PARAMETER;
1977 if (dwFilter <= MSIPATCHSTATE_INVALID || dwFilter > MSIPATCHSTATE_ALL)
1978 return ERROR_INVALID_PARAMETER;
1980 if (dwIndex && dwIndex - last_index != 1)
1981 return ERROR_INVALID_PARAMETER;
1986 r = msi_enum_patches(szProductCode, szUserSid, dwContext, dwFilter,
1987 dwIndex, &idx, szPatchCode, szTargetProductCode,
1988 pdwTargetProductContext, szTargetUserSid,
1989 pcchTargetUserSid, NULL);
1991 if (r == ERROR_SUCCESS)
1992 last_index = dwIndex;
1997 /***********************************************************************
1998 * MsiEnumPatchesA [MSI.@]
2000 UINT WINAPI MsiEnumPatchesA(LPCSTR szProduct, DWORD iPatchIndex,
2001 LPSTR lpPatchBuf, LPSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
2003 LPWSTR product, transforms;
2004 WCHAR patch[GUID_SIZE];
2008 TRACE("(%s %d %p %p %p)\n", debugstr_a(szProduct), iPatchIndex,
2009 lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
2011 if (!szProduct || !lpPatchBuf || !lpTransformsBuf || !pcchTransformsBuf)
2012 return ERROR_INVALID_PARAMETER;
2014 product = strdupAtoW(szProduct);
2016 return ERROR_OUTOFMEMORY;
2018 len = *pcchTransformsBuf;
2019 transforms = msi_alloc( len * sizeof(WCHAR) );
2022 r = ERROR_OUTOFMEMORY;
2026 r = MsiEnumPatchesW(product, iPatchIndex, patch, transforms, &len);
2027 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2030 WideCharToMultiByte(CP_ACP, 0, patch, -1, lpPatchBuf,
2031 GUID_SIZE, NULL, NULL);
2033 if (!WideCharToMultiByte(CP_ACP, 0, transforms, -1, lpTransformsBuf,
2034 *pcchTransformsBuf, NULL, NULL))
2035 r = ERROR_MORE_DATA;
2037 if (r == ERROR_MORE_DATA)
2039 lpTransformsBuf[*pcchTransformsBuf - 1] = '\0';
2040 *pcchTransformsBuf = len * 2;
2043 *pcchTransformsBuf = strlen( lpTransformsBuf );
2046 msi_free(transforms);
2052 /***********************************************************************
2053 * MsiEnumPatchesW [MSI.@]
2055 UINT WINAPI MsiEnumPatchesW(LPCWSTR szProduct, DWORD iPatchIndex,
2056 LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, LPDWORD pcchTransformsBuf)
2058 WCHAR squished_pc[GUID_SIZE];
2059 LPWSTR transforms = NULL;
2064 TRACE("(%s %d %p %p %p)\n", debugstr_w(szProduct), iPatchIndex,
2065 lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
2067 if (!szProduct || !squash_guid(szProduct, squished_pc))
2068 return ERROR_INVALID_PARAMETER;
2070 if (!lpPatchBuf || !lpTransformsBuf || !pcchTransformsBuf)
2071 return ERROR_INVALID_PARAMETER;
2073 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2074 &prod, FALSE) != ERROR_SUCCESS &&
2075 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2076 &prod, FALSE) != ERROR_SUCCESS &&
2077 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2078 &prod, FALSE) != ERROR_SUCCESS)
2079 return ERROR_UNKNOWN_PRODUCT;
2083 r = msi_enum_patches(szProduct, NULL, MSIINSTALLCONTEXT_ALL,
2084 MSIPATCHSTATE_ALL, iPatchIndex, &idx, lpPatchBuf,
2085 NULL, NULL, NULL, NULL, &transforms);
2086 if (r != ERROR_SUCCESS)
2089 lstrcpynW(lpTransformsBuf, transforms, *pcchTransformsBuf);
2090 if (*pcchTransformsBuf <= lstrlenW(transforms))
2092 r = ERROR_MORE_DATA;
2093 *pcchTransformsBuf = lstrlenW(transforms);
2096 *pcchTransformsBuf = lstrlenW(transforms);
2099 msi_free(transforms);
2103 UINT WINAPI MsiEnumProductsExA( LPCSTR szProductCode, LPCSTR szUserSid,
2104 DWORD dwContext, DWORD dwIndex, CHAR szInstalledProductCode[39],
2105 MSIINSTALLCONTEXT* pdwInstalledContext, LPSTR szSid, LPDWORD pcchSid)
2107 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_a(szProductCode), debugstr_a(szUserSid),
2108 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
2110 return ERROR_NO_MORE_ITEMS;
2113 UINT WINAPI MsiEnumProductsExW( LPCWSTR szProductCode, LPCWSTR szUserSid,
2114 DWORD dwContext, DWORD dwIndex, WCHAR szInstalledProductCode[39],
2115 MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, LPDWORD pcchSid)
2117 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_w(szProductCode), debugstr_w(szUserSid),
2118 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
2120 return ERROR_NO_MORE_ITEMS;