2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Mike McCormak 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #define NONAMELESSUNION
32 #include "wine/debug.h"
36 #include "wine/unicode.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
44 * This module will be all the helper functions for registry access by the
47 static const WCHAR szUserFeatures_fmt
[] = {
48 'S','o','f','t','w','a','r','e','\\',
49 'M','i','c','r','o','s','o','f','t','\\',
50 'I','n','s','t','a','l','l','e','r','\\',
51 'F','e','a','t','u','r','e','s','\\',
54 static const WCHAR szInstaller_Features
[] = {
55 'S','o','f','t','w','a','r','e','\\',
56 'M','i','c','r','o','s','o','f','t','\\',
57 'W','i','n','d','o','w','s','\\',
58 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
59 'I','n','s','t','a','l','l','e','r','\\',
60 'F','e','a','t','u','r','e','s',0 };
62 static const WCHAR szInstaller_Features_fmt
[] = {
63 'S','o','f','t','w','a','r','e','\\',
64 'M','i','c','r','o','s','o','f','t','\\',
65 'W','i','n','d','o','w','s','\\',
66 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
67 'I','n','s','t','a','l','l','e','r','\\',
68 'F','e','a','t','u','r','e','s','\\',
71 static const WCHAR szInstaller_Components
[] = {
72 'S','o','f','t','w','a','r','e','\\',
73 'M','i','c','r','o','s','o','f','t','\\',
74 'W','i','n','d','o','w','s','\\',
75 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
76 'I','n','s','t','a','l','l','e','r','\\',
77 'C','o','m','p','o','n','e','n','t','s',0 };
79 static const WCHAR szInstaller_Components_fmt
[] = {
80 'S','o','f','t','w','a','r','e','\\',
81 'M','i','c','r','o','s','o','f','t','\\',
82 'W','i','n','d','o','w','s','\\',
83 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
84 'I','n','s','t','a','l','l','e','r','\\',
85 'C','o','m','p','o','n','e','n','t','s','\\',
88 static const WCHAR szUninstall_fmt
[] = {
89 'S','o','f','t','w','a','r','e','\\',
90 'M','i','c','r','o','s','o','f','t','\\',
91 'W','i','n','d','o','w','s','\\',
92 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
93 'U','n','i','n','s','t','a','l','l','\\',
96 static const WCHAR szUserProduct_fmt
[] = {
97 'S','o','f','t','w','a','r','e','\\',
98 'M','i','c','r','o','s','o','f','t','\\',
99 'I','n','s','t','a','l','l','e','r','\\',
100 'P','r','o','d','u','c','t','s','\\',
103 static const WCHAR szInstaller_Products
[] = {
104 'S','o','f','t','w','a','r','e','\\',
105 'M','i','c','r','o','s','o','f','t','\\',
106 'W','i','n','d','o','w','s','\\',
107 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
108 'I','n','s','t','a','l','l','e','r','\\',
109 'P','r','o','d','u','c','t','s',0};
111 static const WCHAR szInstaller_Products_fmt
[] = {
112 'S','o','f','t','w','a','r','e','\\',
113 'M','i','c','r','o','s','o','f','t','\\',
114 'W','i','n','d','o','w','s','\\',
115 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
116 'I','n','s','t','a','l','l','e','r','\\',
117 'P','r','o','d','u','c','t','s','\\',
120 BOOL
unsquash_guid(LPCWSTR in
, LPWSTR out
)
136 out
[n
++] = in
[17+i
*2];
137 out
[n
++] = in
[16+i
*2];
142 out
[n
++] = in
[17+i
*2];
143 out
[n
++] = in
[16+i
*2];
150 BOOL
squash_guid(LPCWSTR in
, LPWSTR out
)
170 out
[17+i
*2] = in
[n
++];
171 out
[16+i
*2] = in
[n
++];
177 out
[17+i
*2] = in
[n
++];
178 out
[16+i
*2] = in
[n
++];
189 /* tables for encoding and decoding base85 */
190 static const unsigned char table_dec85
[0x80] = {
191 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
192 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
193 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
194 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
195 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
196 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
197 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
198 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
201 static const char table_enc85
[] =
202 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
203 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
207 * Converts a base85 encoded guid into a GUID pointer
208 * Base85 encoded GUIDs should be 20 characters long.
210 * returns TRUE if successful, FALSE if not
212 BOOL
decode_base85_guid( LPCWSTR str
, GUID
*guid
)
214 DWORD i
, val
= 0, base
= 1, *p
;
217 for( i
=0; i
<20; i
++ )
224 val
+= table_dec85
[str
[i
]] * base
;
227 if( table_dec85
[str
[i
]] == 0xff )
237 * Encodes a base85 guid given a GUID pointer
238 * Caller should provide a 21 character buffer for the encoded string.
240 * returns TRUE if successful, FALSE if not
242 BOOL
encode_base85_guid( GUID
*guid
, LPWSTR str
)
244 unsigned int x
, *p
, i
;
246 p
= (unsigned int*) guid
;
250 *str
++ = table_enc85
[x
%85];
252 *str
++ = table_enc85
[x
%85];
254 *str
++ = table_enc85
[x
%85];
256 *str
++ = table_enc85
[x
%85];
258 *str
++ = table_enc85
[x
%85];
266 UINT
MSIREG_OpenUninstallKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
)
269 WCHAR keypath
[0x200];
270 TRACE("%s\n",debugstr_w(szProduct
));
272 sprintfW(keypath
,szUninstall_fmt
,szProduct
);
275 rc
= RegCreateKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
277 rc
= RegOpenKeyW(HKEY_LOCAL_MACHINE
, keypath
, key
);
282 UINT
MSIREG_OpenUserProductsKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
)
285 WCHAR squished_pc
[GUID_SIZE
];
286 WCHAR keypath
[0x200];
288 TRACE("%s\n",debugstr_w(szProduct
));
289 squash_guid(szProduct
,squished_pc
);
290 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
292 sprintfW(keypath
,szUserProduct_fmt
,squished_pc
);
295 rc
= RegCreateKeyW(HKEY_CURRENT_USER
,keypath
,key
);
297 rc
= RegOpenKeyW(HKEY_CURRENT_USER
,keypath
,key
);
302 UINT
MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
)
305 WCHAR squished_pc
[GUID_SIZE
];
306 WCHAR keypath
[0x200];
308 TRACE("%s\n",debugstr_w(szProduct
));
309 squash_guid(szProduct
,squished_pc
);
310 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
312 sprintfW(keypath
,szUserFeatures_fmt
,squished_pc
);
315 rc
= RegCreateKeyW(HKEY_CURRENT_USER
,keypath
,key
);
317 rc
= RegOpenKeyW(HKEY_CURRENT_USER
,keypath
,key
);
322 UINT
MSIREG_OpenFeatures(HKEY
* key
)
324 return RegCreateKeyW(HKEY_LOCAL_MACHINE
,szInstaller_Features
,key
);
327 UINT
MSIREG_OpenFeaturesKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
)
330 WCHAR squished_pc
[GUID_SIZE
];
331 WCHAR keypath
[0x200];
333 TRACE("%s\n",debugstr_w(szProduct
));
334 squash_guid(szProduct
,squished_pc
);
335 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
337 sprintfW(keypath
,szInstaller_Features_fmt
,squished_pc
);
340 rc
= RegCreateKeyW(HKEY_LOCAL_MACHINE
,keypath
,key
);
342 rc
= RegOpenKeyW(HKEY_LOCAL_MACHINE
,keypath
,key
);
347 UINT
MSIREG_OpenComponents(HKEY
* key
)
349 return RegCreateKeyW(HKEY_LOCAL_MACHINE
,szInstaller_Components
,key
);
352 UINT
MSIREG_OpenComponentsKey(LPCWSTR szComponent
, HKEY
* key
, BOOL create
)
355 WCHAR squished_cc
[GUID_SIZE
];
356 WCHAR keypath
[0x200];
358 TRACE("%s\n",debugstr_w(szComponent
));
359 squash_guid(szComponent
,squished_cc
);
360 TRACE("squished (%s)\n", debugstr_w(squished_cc
));
362 sprintfW(keypath
,szInstaller_Components_fmt
,squished_cc
);
365 rc
= RegCreateKeyW(HKEY_LOCAL_MACHINE
,keypath
,key
);
367 rc
= RegOpenKeyW(HKEY_LOCAL_MACHINE
,keypath
,key
);
372 UINT
MSIREG_OpenProductsKey(LPCWSTR szProduct
, HKEY
* key
, BOOL create
)
375 WCHAR squished_pc
[GUID_SIZE
];
376 WCHAR keypath
[0x200];
378 TRACE("%s\n",debugstr_w(szProduct
));
379 squash_guid(szProduct
,squished_pc
);
380 TRACE("squished (%s)\n", debugstr_w(squished_pc
));
382 sprintfW(keypath
,szInstaller_Products_fmt
,squished_pc
);
385 rc
= RegCreateKeyW(HKEY_LOCAL_MACHINE
,keypath
,key
);
387 rc
= RegOpenKeyW(HKEY_LOCAL_MACHINE
,keypath
,key
);