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 szInstaller_Features[] = {
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 'F','e','a','t','u','r','e','s',0 };
63 static const WCHAR szUserDataFeatures_fmt[] = {
64 'S','o','f','t','w','a','r','e','\\',
65 'M','i','c','r','o','s','o','f','t','\\',
66 'W','i','n','d','o','w','s','\\',
67 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
68 'I','n','s','t','a','l','l','e','r','\\',
69 'U','s','e','r','D','a','t','a','\\',
70 '%','s','\\','P','r','o','d','u','c','t','s','\\',
71 '%','s','\\','F','e','a','t','u','r','e','s',0};
73 static const WCHAR szInstaller_Features_fmt[] = {
74 'S','o','f','t','w','a','r','e','\\',
75 'M','i','c','r','o','s','o','f','t','\\',
76 'W','i','n','d','o','w','s','\\',
77 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
78 'I','n','s','t','a','l','l','e','r','\\',
79 'F','e','a','t','u','r','e','s','\\',
82 static const WCHAR szInstaller_Components[] = {
83 'S','o','f','t','w','a','r','e','\\',
84 'M','i','c','r','o','s','o','f','t','\\',
85 'W','i','n','d','o','w','s','\\',
86 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
87 'I','n','s','t','a','l','l','e','r','\\',
88 'C','o','m','p','o','n','e','n','t','s',0 };
90 static const WCHAR szInstaller_Components_fmt[] = {
91 'S','o','f','t','w','a','r','e','\\',
92 'M','i','c','r','o','s','o','f','t','\\',
93 'W','i','n','d','o','w','s','\\',
94 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
95 'I','n','s','t','a','l','l','e','r','\\',
96 'C','o','m','p','o','n','e','n','t','s','\\',
99 static const WCHAR szUser_Components_fmt[] = {
100 'S','o','f','t','w','a','r','e','\\',
101 'M','i','c','r','o','s','o','f','t','\\',
102 'I','n','s','t','a','l','l','e','r','\\',
103 'C','o','m','p','o','n','e','n','t','s','\\',
106 static const WCHAR szUserDataComp_fmt[] = {
107 'S','o','f','t','w','a','r','e','\\',
108 'M','i','c','r','o','s','o','f','t','\\',
109 'W','i','n','d','o','w','s','\\',
110 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
111 'I','n','s','t','a','l','l','e','r','\\',
112 'U','s','e','r','D','a','t','a','\\',
113 '%','s','\\','C','o','m','p','o','n','e','n','t','s','\\','%','s',0};
115 static const WCHAR szUninstall_fmt[] = {
116 'S','o','f','t','w','a','r','e','\\',
117 'M','i','c','r','o','s','o','f','t','\\',
118 'W','i','n','d','o','w','s','\\',
119 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
120 'U','n','i','n','s','t','a','l','l','\\',
123 static const WCHAR szUserProduct_fmt[] = {
124 'S','o','f','t','w','a','r','e','\\',
125 'M','i','c','r','o','s','o','f','t','\\',
126 'I','n','s','t','a','l','l','e','r','\\',
127 'P','r','o','d','u','c','t','s','\\',
130 static const WCHAR szUserPatch_fmt[] = {
131 'S','o','f','t','w','a','r','e','\\',
132 'M','i','c','r','o','s','o','f','t','\\',
133 'I','n','s','t','a','l','l','e','r','\\',
134 'P','a','t','c','h','e','s','\\',
137 static const WCHAR szInstaller_Products[] = {
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','r','o','d','u','c','t','s',0};
145 static const WCHAR szInstaller_Products_fmt[] = {
146 'S','o','f','t','w','a','r','e','\\',
147 'M','i','c','r','o','s','o','f','t','\\',
148 'W','i','n','d','o','w','s','\\',
149 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
150 'I','n','s','t','a','l','l','e','r','\\',
151 'P','r','o','d','u','c','t','s','\\',
154 static const WCHAR szInstaller_Patches_fmt[] = {
155 'S','o','f','t','w','a','r','e','\\',
156 'M','i','c','r','o','s','o','f','t','\\',
157 'W','i','n','d','o','w','s','\\',
158 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
159 'I','n','s','t','a','l','l','e','r','\\',
160 'P','a','t','c','h','e','s','\\',
163 static const WCHAR szInstaller_UpgradeCodes_fmt[] = {
164 'S','o','f','t','w','a','r','e','\\',
165 'M','i','c','r','o','s','o','f','t','\\',
166 'W','i','n','d','o','w','s','\\',
167 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
168 'I','n','s','t','a','l','l','e','r','\\',
169 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
172 static const WCHAR szInstaller_UserUpgradeCodes_fmt[] = {
173 'S','o','f','t','w','a','r','e','\\',
174 'M','i','c','r','o','s','o','f','t','\\',
175 'I','n','s','t','a','l','l','e','r','\\',
176 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
179 static const WCHAR szUserDataProd_fmt[] = {
180 'S','o','f','t','w','a','r','e','\\',
181 'M','i','c','r','o','s','o','f','t','\\',
182 'W','i','n','d','o','w','s','\\',
183 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
184 'I','n','s','t','a','l','l','e','r','\\',
185 'U','s','e','r','D','a','t','a','\\',
186 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s',0};
188 static const WCHAR szInstallProperties_fmt[] = {
189 'S','o','f','t','w','a','r','e','\\',
190 'M','i','c','r','o','s','o','f','t','\\',
191 'W','i','n','d','o','w','s','\\',
192 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
193 'I','n','s','t','a','l','l','e','r','\\',
194 'U','s','e','r','D','a','t','a','\\',
195 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\',
196 'I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0};
199 #define SQUISH_GUID_SIZE 33
201 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
217 out[n++] = in[17+i*2];
218 out[n++] = in[16+i*2];
223 out[n++] = in[17+i*2];
224 out[n++] = in[16+i*2];
231 BOOL squash_guid(LPCWSTR in, LPWSTR out)
236 if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
250 out[17+i*2] = in[n++];
251 out[16+i*2] = in[n++];
256 out[17+i*2] = in[n++];
257 out[16+i*2] = in[n++];
264 /* tables for encoding and decoding base85 */
265 static const unsigned char table_dec85[0x80] = {
266 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
267 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
268 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
269 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
270 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
271 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
272 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
273 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
276 static const char table_enc85[] =
277 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
278 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
282 * Converts a base85 encoded guid into a GUID pointer
283 * Base85 encoded GUIDs should be 20 characters long.
285 * returns TRUE if successful, FALSE if not
287 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
289 DWORD i, val = 0, base = 1, *p;
295 for( i=0; i<20; i++ )
302 val += table_dec85[str[i]] * base;
305 if( table_dec85[str[i]] == 0xff )
315 * Encodes a base85 guid given a GUID pointer
316 * Caller should provide a 21 character buffer for the encoded string.
318 * returns TRUE if successful, FALSE if not
320 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
322 unsigned int x, *p, i;
324 p = (unsigned int*) guid;
328 *str++ = table_enc85[x%85];
330 *str++ = table_enc85[x%85];
332 *str++ = table_enc85[x%85];
334 *str++ = table_enc85[x%85];
336 *str++ = table_enc85[x%85];
343 DWORD msi_version_str_to_dword(LPCWSTR p)
345 DWORD major, minor = 0, build = 0, version = 0;
356 p = strchrW(p+1, '.');
361 return MAKELONG(build, MAKEWORD(minor, major));
364 LPWSTR msi_version_dword_to_str(DWORD version)
366 const WCHAR fmt[] = { '%','u','.','%','u','.','%','u',0 };
367 LPWSTR str = msi_alloc(20);
369 (version&0xff000000)>>24,
370 (version&0x00ff0000)>>16,
375 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
377 DWORD len = value ? (lstrlenW(value) + 1) * sizeof (WCHAR) : 0;
378 return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len );
381 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
384 while (*p) p += lstrlenW(p) + 1;
385 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
386 (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) );
389 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
391 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
394 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
399 r = RegCreateKeyW( hkey, path, &hsubkey );
400 if (r != ERROR_SUCCESS)
402 r = msi_reg_set_val_str( hsubkey, name, val );
403 RegCloseKey( hsubkey );
407 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
413 r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
414 if (r != ERROR_SUCCESS)
417 len += sizeof (WCHAR);
418 val = msi_alloc( len );
422 RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
426 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
428 DWORD type, len = sizeof (DWORD);
429 LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
430 return r == ERROR_SUCCESS && type == REG_DWORD;
433 static UINT get_user_sid(LPWSTR *usersid)
440 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
441 return ERROR_FUNCTION_FAILED;
444 if (!GetTokenInformation(token, TokenUser, (void *)buf, size, &size))
445 return ERROR_FUNCTION_FAILED;
447 user = (PTOKEN_USER)buf;
448 if (!ConvertSidToStringSidW(user->User.Sid, usersid))
449 return ERROR_FUNCTION_FAILED;
451 return ERROR_SUCCESS;
454 UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create)
457 WCHAR keypath[0x200];
458 TRACE("%s\n",debugstr_w(szProduct));
460 sprintfW(keypath,szUninstall_fmt,szProduct);
463 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
465 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
470 UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
473 WCHAR squished_pc[GUID_SIZE];
474 WCHAR keypath[0x200];
476 TRACE("%s\n",debugstr_w(szProduct));
477 squash_guid(szProduct,squished_pc);
478 TRACE("squished (%s)\n", debugstr_w(squished_pc));
480 sprintfW(keypath,szUserProduct_fmt,squished_pc);
483 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
485 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
490 UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct)
492 WCHAR squished_pc[GUID_SIZE];
493 WCHAR keypath[0x200];
495 TRACE("%s\n",debugstr_w(szProduct));
496 squash_guid(szProduct,squished_pc);
497 TRACE("squished (%s)\n", debugstr_w(squished_pc));
499 sprintfW(keypath,szUserProduct_fmt,squished_pc);
501 return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
504 UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
507 WCHAR squished_pc[GUID_SIZE];
508 WCHAR keypath[0x200];
510 TRACE("%s\n",debugstr_w(szPatch));
511 squash_guid(szPatch,squished_pc);
512 TRACE("squished (%s)\n", debugstr_w(squished_pc));
514 sprintfW(keypath,szUserPatch_fmt,squished_pc);
517 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
519 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
524 UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
527 WCHAR squished_pc[GUID_SIZE];
528 WCHAR keypath[0x200];
530 TRACE("%s\n",debugstr_w(szProduct));
531 squash_guid(szProduct,squished_pc);
532 TRACE("squished (%s)\n", debugstr_w(squished_pc));
534 sprintfW(keypath,szUserFeatures_fmt,squished_pc);
537 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
539 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
544 UINT MSIREG_OpenFeatures(HKEY* key)
546 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Features,key);
549 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
552 WCHAR squished_pc[GUID_SIZE];
553 WCHAR keypath[0x200];
555 TRACE("%s\n",debugstr_w(szProduct));
556 squash_guid(szProduct,squished_pc);
557 TRACE("squished (%s)\n", debugstr_w(squished_pc));
559 sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
562 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
564 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
569 UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL create)
572 WCHAR squished_pc[GUID_SIZE];
573 WCHAR keypath[0x200];
576 TRACE("%s\n", debugstr_w(szProduct));
577 squash_guid(szProduct, squished_pc);
578 TRACE("squished (%s)\n", debugstr_w(squished_pc));
580 rc = get_user_sid(&usersid);
581 if (rc != ERROR_SUCCESS || !usersid)
583 ERR("Failed to retrieve user SID: %d\n", rc);
587 sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc);
590 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
592 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
598 UINT MSIREG_OpenComponents(HKEY* key)
600 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Components,key);
603 UINT MSIREG_OpenComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
606 WCHAR squished_cc[GUID_SIZE];
607 WCHAR keypath[0x200];
609 TRACE("%s\n",debugstr_w(szComponent));
610 squash_guid(szComponent,squished_cc);
611 TRACE("squished (%s)\n", debugstr_w(squished_cc));
613 sprintfW(keypath,szInstaller_Components_fmt,squished_cc);
616 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
618 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
623 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
626 WCHAR squished_cc[GUID_SIZE];
627 WCHAR keypath[0x200];
629 TRACE("%s\n",debugstr_w(szComponent));
630 squash_guid(szComponent,squished_cc);
631 TRACE("squished (%s)\n", debugstr_w(squished_cc));
633 sprintfW(keypath,szUser_Components_fmt,squished_cc);
636 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
638 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
643 UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create)
646 WCHAR comp[GUID_SIZE];
647 WCHAR keypath[0x200];
650 TRACE("%s\n", debugstr_w(szComponent));
651 squash_guid(szComponent, comp);
652 TRACE("squished (%s)\n", debugstr_w(comp));
654 rc = get_user_sid(&usersid);
655 if (rc != ERROR_SUCCESS || !usersid)
657 ERR("Failed to retrieve user SID: %d\n", rc);
661 sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
664 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
666 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
672 UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, HKEY *key, BOOL create)
675 WCHAR squished_pc[GUID_SIZE];
676 WCHAR keypath[0x200];
679 TRACE("%s\n", debugstr_w(szProduct));
680 squash_guid(szProduct, squished_pc);
681 TRACE("squished (%s)\n", debugstr_w(squished_pc));
683 rc = get_user_sid(&usersid);
684 if (rc != ERROR_SUCCESS || !usersid)
686 ERR("Failed to retrieve user SID: %d\n", rc);
690 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
693 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
695 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
701 UINT MSIREG_OpenInstallPropertiesKey(LPCWSTR szProduct, HKEY *key, BOOL create)
704 WCHAR squished_pc[GUID_SIZE];
705 WCHAR keypath[0x200];
708 TRACE("%s\n", debugstr_w(szProduct));
709 squash_guid(szProduct, squished_pc);
710 TRACE("squished (%s)\n", debugstr_w(squished_pc));
712 rc = get_user_sid(&usersid);
713 if (rc != ERROR_SUCCESS || !usersid)
715 ERR("Failed to retrieve user SID: %d\n", rc);
719 sprintfW(keypath, szInstallProperties_fmt, usersid, squished_pc);
722 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
724 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
730 UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)
733 WCHAR squished_pc[GUID_SIZE];
734 WCHAR keypath[0x200];
737 TRACE("%s\n", debugstr_w(szProduct));
738 squash_guid(szProduct, squished_pc);
739 TRACE("squished (%s)\n", debugstr_w(squished_pc));
741 rc = get_user_sid(&usersid);
742 if (rc != ERROR_SUCCESS || !usersid)
744 ERR("Failed to retrieve user SID: %d\n", rc);
748 sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
751 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
754 UINT MSIREG_OpenProducts(HKEY* key)
756 return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Products,key);
759 UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
762 WCHAR squished_pc[GUID_SIZE];
763 WCHAR keypath[0x200];
765 TRACE("%s\n",debugstr_w(szProduct));
766 squash_guid(szProduct,squished_pc);
767 TRACE("squished (%s)\n", debugstr_w(squished_pc));
769 sprintfW(keypath,szInstaller_Products_fmt,squished_pc);
772 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
774 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
779 UINT MSIREG_DeleteProductKey(LPCWSTR szProduct)
781 WCHAR squished_pc[GUID_SIZE];
782 WCHAR keypath[0x200];
784 TRACE("%s\n", debugstr_w(szProduct));
785 squash_guid(szProduct, squished_pc);
786 TRACE("squished (%s)\n", debugstr_w(squished_pc));
788 sprintfW(keypath, szInstaller_Products_fmt, squished_pc);
790 return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
793 UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
796 WCHAR squished_pc[GUID_SIZE];
797 WCHAR keypath[0x200];
799 TRACE("%s\n",debugstr_w(szPatch));
800 squash_guid(szPatch,squished_pc);
801 TRACE("squished (%s)\n", debugstr_w(squished_pc));
803 sprintfW(keypath,szInstaller_Patches_fmt,squished_pc);
806 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
808 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
813 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
816 WCHAR squished_pc[GUID_SIZE];
817 WCHAR keypath[0x200];
819 TRACE("%s\n",debugstr_w(szUpgradeCode));
820 squash_guid(szUpgradeCode,squished_pc);
821 TRACE("squished (%s)\n", debugstr_w(squished_pc));
823 sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
826 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
828 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
833 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
836 WCHAR squished_pc[GUID_SIZE];
837 WCHAR keypath[0x200];
839 TRACE("%s\n",debugstr_w(szUpgradeCode));
840 squash_guid(szUpgradeCode,squished_pc);
841 TRACE("squished (%s)\n", debugstr_w(squished_pc));
843 sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
846 rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
848 rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
854 /*************************************************************************
855 * MsiDecomposeDescriptorW [MSI.@]
857 * Decomposes an MSI descriptor into product, feature and component parts.
858 * An MSI descriptor is a string of the form:
859 * [base 85 guid] [feature code] '>' [base 85 guid]
862 * szDescriptor [I] the descriptor to decompose
863 * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
864 * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
865 * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
866 * pUsed [O] the length of the descriptor
869 * ERROR_SUCCESS if everything worked correctly
870 * ERROR_INVALID_PARAMETER if the descriptor was invalid
873 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
874 LPWSTR szFeature, LPWSTR szComponent, DWORD *pUsed )
878 GUID product, component;
880 TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
881 szFeature, szComponent, pUsed);
883 r = decode_base85_guid( szDescriptor, &product );
885 return ERROR_INVALID_PARAMETER;
887 TRACE("product %s\n", debugstr_guid( &product ));
889 p = strchrW(&szDescriptor[20],'>');
891 return ERROR_INVALID_PARAMETER;
893 len = (p - &szDescriptor[20]);
894 if( len > MAX_FEATURE_CHARS )
895 return ERROR_INVALID_PARAMETER;
897 TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len ));
899 r = decode_base85_guid( p+1, &component );
901 return ERROR_INVALID_PARAMETER;
903 TRACE("component %s\n", debugstr_guid( &component ));
906 StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
908 StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
911 memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
914 len = ( &p[21] - szDescriptor );
916 TRACE("length = %d\n", len);
919 return ERROR_SUCCESS;
922 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
923 LPSTR szFeature, LPSTR szComponent, DWORD *pUsed )
925 WCHAR product[MAX_FEATURE_CHARS+1];
926 WCHAR feature[MAX_FEATURE_CHARS+1];
927 WCHAR component[MAX_FEATURE_CHARS+1];
928 LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
931 TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
932 szFeature, szComponent, pUsed);
934 str = strdupAtoW( szDescriptor );
935 if( szDescriptor && !str )
936 return ERROR_OUTOFMEMORY;
945 r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
947 if (r == ERROR_SUCCESS)
949 WideCharToMultiByte( CP_ACP, 0, p, -1,
950 szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
951 WideCharToMultiByte( CP_ACP, 0, f, -1,
952 szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
953 WideCharToMultiByte( CP_ACP, 0, c, -1,
954 szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
962 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
965 WCHAR szwGuid[GUID_SIZE];
967 TRACE("%d %p\n", index, lpguid);
970 return ERROR_INVALID_PARAMETER;
971 r = MsiEnumProductsW(index, szwGuid);
972 if( r == ERROR_SUCCESS )
973 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
978 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
980 HKEY hkeyProducts = 0;
982 WCHAR szKeyName[SQUISH_GUID_SIZE];
984 TRACE("%d %p\n", index, lpguid);
987 return ERROR_INVALID_PARAMETER;
989 r = MSIREG_OpenProducts(&hkeyProducts);
990 if( r != ERROR_SUCCESS )
991 return ERROR_NO_MORE_ITEMS;
993 r = RegEnumKeyW(hkeyProducts, index, szKeyName, SQUISH_GUID_SIZE);
994 if( r == ERROR_SUCCESS )
995 unsquash_guid(szKeyName, lpguid);
996 RegCloseKey(hkeyProducts);
1001 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
1002 LPSTR szFeature, LPSTR szParent)
1005 WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
1006 LPWSTR szwProduct = NULL;
1008 TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent);
1012 szwProduct = strdupAtoW( szProduct );
1014 return ERROR_OUTOFMEMORY;
1017 r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
1018 if( r == ERROR_SUCCESS )
1020 WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
1021 szFeature, GUID_SIZE, NULL, NULL);
1022 WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
1023 szParent, GUID_SIZE, NULL, NULL);
1026 msi_free( szwProduct);
1031 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index,
1032 LPWSTR szFeature, LPWSTR szParent)
1034 HKEY hkeyProduct = 0;
1037 TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
1040 return ERROR_INVALID_PARAMETER;
1042 r = MSIREG_OpenFeaturesKey(szProduct,&hkeyProduct,FALSE);
1043 if( r != ERROR_SUCCESS )
1044 return ERROR_NO_MORE_ITEMS;
1047 r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
1048 RegCloseKey(hkeyProduct);
1053 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
1056 WCHAR szwGuid[GUID_SIZE];
1058 TRACE("%d %p\n", index, lpguid);
1060 r = MsiEnumComponentsW(index, szwGuid);
1061 if( r == ERROR_SUCCESS )
1062 WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1067 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
1069 HKEY hkeyComponents = 0;
1071 WCHAR szKeyName[SQUISH_GUID_SIZE];
1073 TRACE("%d %p\n", index, lpguid);
1075 r = MSIREG_OpenComponents(&hkeyComponents);
1076 if( r != ERROR_SUCCESS )
1077 return ERROR_NO_MORE_ITEMS;
1079 r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
1080 if( r == ERROR_SUCCESS )
1081 unsquash_guid(szKeyName, lpguid);
1082 RegCloseKey(hkeyComponents);
1087 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
1090 WCHAR szwProduct[GUID_SIZE];
1091 LPWSTR szwComponent = NULL;
1093 TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
1097 szwComponent = strdupAtoW( szComponent );
1099 return ERROR_OUTOFMEMORY;
1102 r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
1103 if( r == ERROR_SUCCESS )
1105 WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
1106 szProduct, GUID_SIZE, NULL, NULL);
1109 msi_free( szwComponent);
1114 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
1118 WCHAR szValName[SQUISH_GUID_SIZE];
1120 TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct);
1122 r = MSIREG_OpenComponentsKey(szComponent,&hkeyComp,FALSE);
1123 if( r != ERROR_SUCCESS )
1124 return ERROR_NO_MORE_ITEMS;
1126 sz = SQUISH_GUID_SIZE;
1127 r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
1128 if( r == ERROR_SUCCESS )
1129 unsquash_guid(szValName, szProduct);
1131 RegCloseKey(hkeyComp);
1136 static UINT WINAPI MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
1137 awstring *lpQualBuf, DWORD* pcchQual,
1138 awstring *lpAppBuf, DWORD* pcchAppBuf )
1140 DWORD name_sz, val_sz, name_max, val_max, type, ofs;
1141 LPWSTR name = NULL, val = NULL;
1145 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1146 lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
1149 return ERROR_INVALID_PARAMETER;
1151 r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
1152 if (r != ERROR_SUCCESS)
1153 return ERROR_UNKNOWN_COMPONENT;
1155 /* figure out how big the name is we want to return */
1157 r = ERROR_OUTOFMEMORY;
1158 name = msi_alloc( name_max * sizeof(WCHAR) );
1163 r = ERROR_OUTOFMEMORY;
1164 val = msi_alloc( val_max );
1168 /* loop until we allocate enough memory */
1173 r = RegEnumValueW( key, iIndex, name, &name_sz,
1174 NULL, &type, (LPBYTE)val, &val_sz );
1175 if (r == ERROR_SUCCESS)
1177 if (r != ERROR_MORE_DATA)
1180 if (type != REG_MULTI_SZ)
1182 ERR("component data has wrong type (%d)\n", type);
1186 r = ERROR_OUTOFMEMORY;
1187 if ((name_sz+1) >= name_max)
1191 name = msi_alloc( name_max * sizeof (WCHAR) );
1196 if (val_sz > val_max)
1198 val_max = val_sz + sizeof (WCHAR);
1200 val = msi_alloc( val_max * sizeof (WCHAR) );
1205 ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
1210 r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
1211 if (r != ERROR_SUCCESS)
1214 TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
1216 r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
1217 r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
1219 if (r2 != ERROR_SUCCESS)
1230 /*************************************************************************
1231 * MsiEnumComponentQualifiersA [MSI.@]
1233 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
1234 LPSTR lpQualifierBuf, DWORD* pcchQualifierBuf,
1235 LPSTR lpApplicationDataBuf, DWORD* pcchApplicationDataBuf )
1237 awstring qual, appdata;
1241 TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex,
1242 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1243 pcchApplicationDataBuf);
1245 comp = strdupAtoW( szComponent );
1246 if (szComponent && !comp)
1247 return ERROR_OUTOFMEMORY;
1249 qual.unicode = FALSE;
1250 qual.str.a = lpQualifierBuf;
1252 appdata.unicode = FALSE;
1253 appdata.str.a = lpApplicationDataBuf;
1255 r = MSI_EnumComponentQualifiers( comp, iIndex,
1256 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1261 /*************************************************************************
1262 * MsiEnumComponentQualifiersW [MSI.@]
1264 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
1265 LPWSTR lpQualifierBuf, DWORD* pcchQualifierBuf,
1266 LPWSTR lpApplicationDataBuf, DWORD* pcchApplicationDataBuf )
1268 awstring qual, appdata;
1270 TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1271 lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1272 pcchApplicationDataBuf);
1274 qual.unicode = TRUE;
1275 qual.str.w = lpQualifierBuf;
1277 appdata.unicode = TRUE;
1278 appdata.str.w = lpApplicationDataBuf;
1280 return MSI_EnumComponentQualifiers( szComponent, iIndex,
1281 &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1284 /*************************************************************************
1285 * MsiEnumRelatedProductsW [MSI.@]
1288 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
1289 DWORD iProductIndex, LPWSTR lpProductBuf)
1293 DWORD dwSize = SQUISH_GUID_SIZE;
1294 WCHAR szKeyName[SQUISH_GUID_SIZE];
1296 TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved,
1297 iProductIndex, lpProductBuf);
1299 if (NULL == szUpgradeCode)
1300 return ERROR_INVALID_PARAMETER;
1301 if (NULL == lpProductBuf)
1302 return ERROR_INVALID_PARAMETER;
1304 r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1305 if (r != ERROR_SUCCESS)
1306 return ERROR_NO_MORE_ITEMS;
1308 r = RegEnumValueW(hkey, iProductIndex, szKeyName, &dwSize, NULL, NULL, NULL, NULL);
1309 if( r == ERROR_SUCCESS )
1310 unsquash_guid(szKeyName, lpProductBuf);
1316 /*************************************************************************
1317 * MsiEnumRelatedProductsA [MSI.@]
1320 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1321 DWORD iProductIndex, LPSTR lpProductBuf)
1323 LPWSTR szwUpgradeCode = NULL;
1324 WCHAR productW[GUID_SIZE];
1327 TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1328 iProductIndex, lpProductBuf);
1332 szwUpgradeCode = strdupAtoW( szUpgradeCode );
1333 if( !szwUpgradeCode )
1334 return ERROR_OUTOFMEMORY;
1337 r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1338 iProductIndex, productW );
1339 if (r == ERROR_SUCCESS)
1341 WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1342 lpProductBuf, GUID_SIZE, NULL, NULL );
1344 msi_free( szwUpgradeCode);
1348 /***********************************************************************
1349 * MsiEnumPatchesA [MSI.@]
1351 UINT WINAPI MsiEnumPatchesA( LPCSTR szProduct, DWORD iPatchIndex,
1352 LPSTR lpPatchBuf, LPSTR lpTransformsBuf, DWORD* pcchTransformsBuf)
1354 FIXME("%s %d %p %p %p\n", debugstr_a(szProduct),
1355 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1356 return ERROR_NO_MORE_ITEMS;
1359 /***********************************************************************
1360 * MsiEnumPatchesW [MSI.@]
1362 UINT WINAPI MsiEnumPatchesW( LPCWSTR szProduct, DWORD iPatchIndex,
1363 LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, DWORD* pcchTransformsBuf)
1365 FIXME("%s %d %p %p %p\n", debugstr_w(szProduct),
1366 iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1367 return ERROR_NO_MORE_ITEMS;
1370 UINT WINAPI MsiEnumProductsExA( LPCSTR szProductCode, LPCSTR szUserSid,
1371 DWORD dwContext, DWORD dwIndex, LPSTR szInstalledProductCode,
1372 MSIINSTALLCONTEXT* pdwInstalledContext, LPSTR szSid, LPDWORD pcchSid)
1374 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_a(szProductCode), debugstr_a(szUserSid),
1375 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1377 return ERROR_NO_MORE_ITEMS;
1380 UINT WINAPI MsiEnumProductsExW( LPCWSTR szProductCode, LPCWSTR szUserSid,
1381 DWORD dwContext, DWORD dwIndex, LPWSTR szInstalledProductCode,
1382 MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, LPDWORD pcchSid)
1384 FIXME("%s %s %d %d %p %p %p %p\n", debugstr_w(szProductCode), debugstr_w(szUserSid),
1385 dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1387 return ERROR_NO_MORE_ITEMS;