Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Implementation of the Microsoft Installer (msi.dll) |
| 3 | * |
Aric Stewart | 475a81a | 2005-01-26 19:41:13 +0000 | [diff] [blame] | 4 | * Copyright 2005 Mike McCormack for CodeWeavers |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 5 | * Copyright 2005 Aric Stewart for CodeWeavers |
| 6 | * |
| 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. |
| 11 | * |
| 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. |
| 16 | * |
| 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 |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <stdarg.h> |
| 23 | |
| 24 | #define COBJMACROS |
| 25 | #define NONAMELESSUNION |
| 26 | |
| 27 | #include "windef.h" |
| 28 | #include "winbase.h" |
| 29 | #include "winreg.h" |
| 30 | #include "winnls.h" |
| 31 | #include "shlwapi.h" |
| 32 | #include "wine/debug.h" |
| 33 | #include "msi.h" |
| 34 | #include "msipriv.h" |
| 35 | #include "wincrypt.h" |
| 36 | #include "wine/unicode.h" |
| 37 | #include "winver.h" |
| 38 | #include "winuser.h" |
James Hawkins | 7da89f4 | 2007-06-26 19:01:03 -0700 | [diff] [blame] | 39 | #include "sddl.h" |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 40 | |
| 41 | WINE_DEFAULT_DEBUG_CHANNEL(msi); |
| 42 | |
| 43 | |
| 44 | /* |
| 45 | * This module will be all the helper functions for registry access by the |
| 46 | * installer bits. |
| 47 | */ |
| 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','\\', |
| 53 | '%','s',0}; |
| 54 | |
James Hawkins | 1130d59 | 2007-07-02 20:22:57 -0700 | [diff] [blame] | 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}; |
| 64 | |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 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','\\', |
| 72 | '%','s',0}; |
| 73 | |
| 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 }; |
| 81 | |
Aric Stewart | 072c5e5 | 2005-04-20 12:50:05 +0000 | [diff] [blame] | 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','\\', |
| 87 | '%','s',0}; |
| 88 | |
James Hawkins | 39a5638 | 2007-07-02 20:24:40 -0700 | [diff] [blame] | 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}; |
| 97 | |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 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','\\', |
| 104 | '%','s',0 }; |
| 105 | |
Hans Leidekker | 9163b0d | 2009-03-27 13:40:16 +0100 | [diff] [blame] | 106 | static const WCHAR szUserProduct[] = { |
| 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',0}; |
| 111 | |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 112 | static const WCHAR szUserProduct_fmt[] = { |
| 113 | 'S','o','f','t','w','a','r','e','\\', |
| 114 | 'M','i','c','r','o','s','o','f','t','\\', |
| 115 | 'I','n','s','t','a','l','l','e','r','\\', |
| 116 | 'P','r','o','d','u','c','t','s','\\', |
| 117 | '%','s',0}; |
| 118 | |
James Hawkins | 04c67c2 | 2007-07-02 20:18:34 -0700 | [diff] [blame] | 119 | static const WCHAR szUserPatch_fmt[] = { |
| 120 | 'S','o','f','t','w','a','r','e','\\', |
| 121 | 'M','i','c','r','o','s','o','f','t','\\', |
| 122 | 'I','n','s','t','a','l','l','e','r','\\', |
| 123 | 'P','a','t','c','h','e','s','\\', |
| 124 | '%','s',0}; |
| 125 | |
Misha Koshelev | 74de3e1 | 2007-05-20 14:31:54 -0500 | [diff] [blame] | 126 | static const WCHAR szInstaller_Products[] = { |
| 127 | 'S','o','f','t','w','a','r','e','\\', |
| 128 | 'M','i','c','r','o','s','o','f','t','\\', |
| 129 | 'W','i','n','d','o','w','s','\\', |
| 130 | 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', |
| 131 | 'I','n','s','t','a','l','l','e','r','\\', |
| 132 | 'P','r','o','d','u','c','t','s',0}; |
| 133 | |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 134 | static const WCHAR szInstaller_Products_fmt[] = { |
| 135 | 'S','o','f','t','w','a','r','e','\\', |
| 136 | 'M','i','c','r','o','s','o','f','t','\\', |
| 137 | 'W','i','n','d','o','w','s','\\', |
| 138 | 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', |
| 139 | 'I','n','s','t','a','l','l','e','r','\\', |
| 140 | 'P','r','o','d','u','c','t','s','\\', |
| 141 | '%','s',0}; |
| 142 | |
James Hawkins | 04c67c2 | 2007-07-02 20:18:34 -0700 | [diff] [blame] | 143 | static const WCHAR szInstaller_Patches_fmt[] = { |
| 144 | 'S','o','f','t','w','a','r','e','\\', |
| 145 | 'M','i','c','r','o','s','o','f','t','\\', |
| 146 | 'W','i','n','d','o','w','s','\\', |
| 147 | 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', |
| 148 | 'I','n','s','t','a','l','l','e','r','\\', |
| 149 | 'P','a','t','c','h','e','s','\\', |
| 150 | '%','s',0}; |
| 151 | |
Juan Lang | 3d4ce5c | 2005-03-10 17:24:05 +0000 | [diff] [blame] | 152 | static const WCHAR szInstaller_UpgradeCodes_fmt[] = { |
| 153 | 'S','o','f','t','w','a','r','e','\\', |
| 154 | 'M','i','c','r','o','s','o','f','t','\\', |
| 155 | 'W','i','n','d','o','w','s','\\', |
| 156 | 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', |
| 157 | 'I','n','s','t','a','l','l','e','r','\\', |
| 158 | 'U','p','g','r','a','d','e','C','o','d','e','s','\\', |
| 159 | '%','s',0}; |
| 160 | |
Aric Stewart | 19ba432 | 2005-06-07 20:02:27 +0000 | [diff] [blame] | 161 | static const WCHAR szInstaller_UserUpgradeCodes_fmt[] = { |
| 162 | 'S','o','f','t','w','a','r','e','\\', |
| 163 | 'M','i','c','r','o','s','o','f','t','\\', |
| 164 | 'I','n','s','t','a','l','l','e','r','\\', |
| 165 | 'U','p','g','r','a','d','e','C','o','d','e','s','\\', |
| 166 | '%','s',0}; |
| 167 | |
James Hawkins | 7da89f4 | 2007-06-26 19:01:03 -0700 | [diff] [blame] | 168 | static const WCHAR szUserDataProd_fmt[] = { |
| 169 | 'S','o','f','t','w','a','r','e','\\', |
| 170 | 'M','i','c','r','o','s','o','f','t','\\', |
| 171 | 'W','i','n','d','o','w','s','\\', |
| 172 | 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', |
| 173 | 'I','n','s','t','a','l','l','e','r','\\', |
| 174 | 'U','s','e','r','D','a','t','a','\\', |
| 175 | '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s',0}; |
| 176 | |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 177 | static const WCHAR szUserDataPatch_fmt[] = { |
| 178 | 'S','o','f','t','w','a','r','e','\\', |
| 179 | 'M','i','c','r','o','s','o','f','t','\\', |
| 180 | 'W','i','n','d','o','w','s','\\', |
| 181 | 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', |
| 182 | 'I','n','s','t','a','l','l','e','r','\\', |
| 183 | 'U','s','e','r','D','a','t','a','\\', |
| 184 | '%','s','\\','P','a','t','c','h','e','s','\\','%','s',0}; |
| 185 | |
James Hawkins | 0e44e09 | 2007-07-02 20:21:58 -0700 | [diff] [blame] | 186 | static const WCHAR szInstallProperties_fmt[] = { |
| 187 | 'S','o','f','t','w','a','r','e','\\', |
| 188 | 'M','i','c','r','o','s','o','f','t','\\', |
| 189 | 'W','i','n','d','o','w','s','\\', |
| 190 | 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', |
| 191 | 'I','n','s','t','a','l','l','e','r','\\', |
| 192 | 'U','s','e','r','D','a','t','a','\\', |
| 193 | '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\', |
| 194 | 'I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0}; |
| 195 | |
Hans Leidekker | 9163b0d | 2009-03-27 13:40:16 +0100 | [diff] [blame] | 196 | static const WCHAR szInstaller_LocalClassesProd[] = { |
| 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 | 'P','r','o','d','u','c','t','s',0}; |
| 201 | |
James Hawkins | 511bdd9 | 2007-08-08 18:42:30 -0700 | [diff] [blame] | 202 | static const WCHAR szInstaller_LocalClassesProd_fmt[] = { |
| 203 | 'S','o','f','t','w','a','r','e','\\', |
| 204 | 'C','l','a','s','s','e','s','\\', |
| 205 | 'I','n','s','t','a','l','l','e','r','\\', |
| 206 | 'P','r','o','d','u','c','t','s','\\','%','s',0}; |
| 207 | |
James Hawkins | 2a180e0 | 2008-06-19 00:32:59 -0500 | [diff] [blame] | 208 | static const WCHAR szInstaller_LocalClassesFeat_fmt[] = { |
| 209 | 'S','o','f','t','w','a','r','e','\\', |
| 210 | 'C','l','a','s','s','e','s','\\', |
| 211 | 'I','n','s','t','a','l','l','e','r','\\', |
| 212 | 'F','e','a','t','u','r','e','s','\\','%','s',0}; |
| 213 | |
Hans Leidekker | 9163b0d | 2009-03-27 13:40:16 +0100 | [diff] [blame] | 214 | static const WCHAR szInstaller_LocalManaged_fmt[] = { |
| 215 | 'S','o','f','t','w','a','r','e','\\', |
| 216 | 'M','i','c','r','o','s','o','f','t','\\', |
| 217 | 'W','i','n','d','o','w','s','\\', |
| 218 | 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', |
| 219 | 'I','n','s','t','a','l','l','e','r','\\', |
| 220 | 'M','a','n','a','g','e','d','\\','%','s','\\', |
| 221 | 'I','n','s','t','a','l','l','e','r','\\', |
| 222 | 'P','r','o','d','u','c','t','s',0}; |
| 223 | |
James Hawkins | 511bdd9 | 2007-08-08 18:42:30 -0700 | [diff] [blame] | 224 | static const WCHAR szInstaller_LocalManagedProd_fmt[] = { |
| 225 | 'S','o','f','t','w','a','r','e','\\', |
| 226 | 'M','i','c','r','o','s','o','f','t','\\', |
| 227 | 'W','i','n','d','o','w','s','\\', |
| 228 | 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', |
| 229 | 'I','n','s','t','a','l','l','e','r','\\', |
| 230 | 'M','a','n','a','g','e','d','\\','%','s','\\', |
| 231 | 'I','n','s','t','a','l','l','e','r','\\', |
| 232 | 'P','r','o','d','u','c','t','s','\\','%','s',0}; |
Aric Stewart | 19ba432 | 2005-06-07 20:02:27 +0000 | [diff] [blame] | 233 | |
James Hawkins | 200eba3 | 2008-06-23 23:06:37 -0500 | [diff] [blame] | 234 | static const WCHAR szInstaller_LocalManagedFeat_fmt[] = { |
| 235 | 'S','o','f','t','w','a','r','e','\\', |
| 236 | 'M','i','c','r','o','s','o','f','t','\\', |
| 237 | 'W','i','n','d','o','w','s','\\', |
| 238 | 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', |
| 239 | 'I','n','s','t','a','l','l','e','r','\\', |
| 240 | 'M','a','n','a','g','e','d','\\','%','s','\\', |
| 241 | 'I','n','s','t','a','l','l','e','r','\\', |
| 242 | 'F','e','a','t','u','r','e','s','\\','%','s',0}; |
| 243 | |
James Hawkins | 58e1543 | 2008-06-23 23:04:46 -0500 | [diff] [blame] | 244 | static const WCHAR szInstaller_ClassesUpgrade_fmt[] = { |
| 245 | 'I','n','s','t','a','l','l','e','r','\\', |
| 246 | 'U','p','g','r','a','d','e','C','o','d','e','s','\\', |
| 247 | '%','s',0}; |
| 248 | |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 249 | BOOL unsquash_guid(LPCWSTR in, LPWSTR out) |
| 250 | { |
| 251 | DWORD i,n=0; |
| 252 | |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 253 | if (lstrlenW(in) != 32) |
| 254 | return FALSE; |
| 255 | |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 256 | out[n++]='{'; |
| 257 | for(i=0; i<8; i++) |
| 258 | out[n++] = in[7-i]; |
| 259 | out[n++]='-'; |
| 260 | for(i=0; i<4; i++) |
| 261 | out[n++] = in[11-i]; |
| 262 | out[n++]='-'; |
| 263 | for(i=0; i<4; i++) |
| 264 | out[n++] = in[15-i]; |
| 265 | out[n++]='-'; |
| 266 | for(i=0; i<2; i++) |
| 267 | { |
| 268 | out[n++] = in[17+i*2]; |
| 269 | out[n++] = in[16+i*2]; |
| 270 | } |
| 271 | out[n++]='-'; |
| 272 | for( ; i<8; i++) |
| 273 | { |
| 274 | out[n++] = in[17+i*2]; |
| 275 | out[n++] = in[16+i*2]; |
| 276 | } |
| 277 | out[n++]='}'; |
| 278 | out[n]=0; |
| 279 | return TRUE; |
| 280 | } |
| 281 | |
| 282 | BOOL squash_guid(LPCWSTR in, LPWSTR out) |
| 283 | { |
Mike McCormack | 9f89427 | 2006-07-24 20:34:05 +0900 | [diff] [blame] | 284 | DWORD i,n=1; |
| 285 | GUID guid; |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 286 | |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 287 | out[0] = 0; |
| 288 | |
Mike McCormack | 9f89427 | 2006-07-24 20:34:05 +0900 | [diff] [blame] | 289 | if (FAILED(CLSIDFromString((LPOLESTR)in, &guid))) |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 290 | return FALSE; |
Mike McCormack | 9f89427 | 2006-07-24 20:34:05 +0900 | [diff] [blame] | 291 | |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 292 | for(i=0; i<8; i++) |
| 293 | out[7-i] = in[n++]; |
Mike McCormack | 9f89427 | 2006-07-24 20:34:05 +0900 | [diff] [blame] | 294 | n++; |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 295 | for(i=0; i<4; i++) |
| 296 | out[11-i] = in[n++]; |
Mike McCormack | 9f89427 | 2006-07-24 20:34:05 +0900 | [diff] [blame] | 297 | n++; |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 298 | for(i=0; i<4; i++) |
| 299 | out[15-i] = in[n++]; |
Mike McCormack | 9f89427 | 2006-07-24 20:34:05 +0900 | [diff] [blame] | 300 | n++; |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 301 | for(i=0; i<2; i++) |
| 302 | { |
| 303 | out[17+i*2] = in[n++]; |
| 304 | out[16+i*2] = in[n++]; |
| 305 | } |
Mike McCormack | 9f89427 | 2006-07-24 20:34:05 +0900 | [diff] [blame] | 306 | n++; |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 307 | for( ; i<8; i++) |
| 308 | { |
| 309 | out[17+i*2] = in[n++]; |
| 310 | out[16+i*2] = in[n++]; |
| 311 | } |
| 312 | out[32]=0; |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 313 | return TRUE; |
| 314 | } |
| 315 | |
| 316 | |
| 317 | /* tables for encoding and decoding base85 */ |
| 318 | static const unsigned char table_dec85[0x80] = { |
| 319 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
| 320 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
| 321 | 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff, |
| 322 | 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17, |
| 323 | 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27, |
| 324 | 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36, |
| 325 | 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46, |
| 326 | 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff, |
| 327 | }; |
| 328 | |
| 329 | static const char table_enc85[] = |
| 330 | "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO" |
| 331 | "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx" |
| 332 | "yz{}~"; |
| 333 | |
| 334 | /* |
| 335 | * Converts a base85 encoded guid into a GUID pointer |
| 336 | * Base85 encoded GUIDs should be 20 characters long. |
| 337 | * |
| 338 | * returns TRUE if successful, FALSE if not |
| 339 | */ |
| 340 | BOOL decode_base85_guid( LPCWSTR str, GUID *guid ) |
| 341 | { |
| 342 | DWORD i, val = 0, base = 1, *p; |
| 343 | |
Mike McCormack | 5c63332 | 2005-11-09 10:59:20 +0000 | [diff] [blame] | 344 | if (!str) |
| 345 | return FALSE; |
| 346 | |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 347 | p = (DWORD*) guid; |
| 348 | for( i=0; i<20; i++ ) |
| 349 | { |
| 350 | if( (i%5) == 0 ) |
| 351 | { |
| 352 | val = 0; |
| 353 | base = 1; |
| 354 | } |
| 355 | val += table_dec85[str[i]] * base; |
| 356 | if( str[i] >= 0x80 ) |
| 357 | return FALSE; |
| 358 | if( table_dec85[str[i]] == 0xff ) |
| 359 | return FALSE; |
| 360 | if( (i%5) == 4 ) |
| 361 | p[i/5] = val; |
| 362 | base *= 85; |
| 363 | } |
| 364 | return TRUE; |
| 365 | } |
| 366 | |
| 367 | /* |
| 368 | * Encodes a base85 guid given a GUID pointer |
| 369 | * Caller should provide a 21 character buffer for the encoded string. |
| 370 | * |
| 371 | * returns TRUE if successful, FALSE if not |
| 372 | */ |
| 373 | BOOL encode_base85_guid( GUID *guid, LPWSTR str ) |
| 374 | { |
| 375 | unsigned int x, *p, i; |
| 376 | |
| 377 | p = (unsigned int*) guid; |
| 378 | for( i=0; i<4; i++ ) |
| 379 | { |
| 380 | x = p[i]; |
| 381 | *str++ = table_enc85[x%85]; |
| 382 | x = x/85; |
| 383 | *str++ = table_enc85[x%85]; |
| 384 | x = x/85; |
| 385 | *str++ = table_enc85[x%85]; |
| 386 | x = x/85; |
| 387 | *str++ = table_enc85[x%85]; |
| 388 | x = x/85; |
| 389 | *str++ = table_enc85[x%85]; |
| 390 | } |
| 391 | *str = 0; |
| 392 | |
| 393 | return TRUE; |
| 394 | } |
| 395 | |
Mike McCormack | 230af9d | 2006-07-14 15:19:08 +0900 | [diff] [blame] | 396 | DWORD msi_version_str_to_dword(LPCWSTR p) |
| 397 | { |
| 398 | DWORD major, minor = 0, build = 0, version = 0; |
| 399 | |
| 400 | if (!p) |
| 401 | return version; |
| 402 | |
| 403 | major = atoiW(p); |
| 404 | |
| 405 | p = strchrW(p, '.'); |
| 406 | if (p) |
| 407 | { |
| 408 | minor = atoiW(p+1); |
| 409 | p = strchrW(p+1, '.'); |
| 410 | if (p) |
| 411 | build = atoiW(p+1); |
| 412 | } |
| 413 | |
| 414 | return MAKELONG(build, MAKEWORD(minor, major)); |
| 415 | } |
| 416 | |
Mike McCormack | 9917250 | 2006-07-14 15:18:35 +0900 | [diff] [blame] | 417 | LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value ) |
| 418 | { |
Alexandre Julliard | 06bf8ea | 2008-04-22 17:05:05 +0200 | [diff] [blame] | 419 | DWORD len; |
Hans Leidekker | 843382f | 2009-10-15 12:46:27 +0200 | [diff] [blame] | 420 | if (!value) value = szEmpty; |
Alexandre Julliard | 06bf8ea | 2008-04-22 17:05:05 +0200 | [diff] [blame] | 421 | len = (lstrlenW(value) + 1) * sizeof (WCHAR); |
Andrew Talbot | 2e372c0 | 2006-09-17 08:52:49 +0100 | [diff] [blame] | 422 | return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len ); |
Mike McCormack | 9917250 | 2006-07-14 15:18:35 +0900 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value ) |
| 426 | { |
| 427 | LPCWSTR p = value; |
| 428 | while (*p) p += lstrlenW(p) + 1; |
| 429 | return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ, |
Andrew Talbot | 2e372c0 | 2006-09-17 08:52:49 +0100 | [diff] [blame] | 430 | (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) ); |
Mike McCormack | 9917250 | 2006-07-14 15:18:35 +0900 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val ) |
| 434 | { |
| 435 | return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) ); |
| 436 | } |
| 437 | |
| 438 | LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val ) |
| 439 | { |
| 440 | HKEY hsubkey = 0; |
| 441 | LONG r; |
| 442 | |
| 443 | r = RegCreateKeyW( hkey, path, &hsubkey ); |
| 444 | if (r != ERROR_SUCCESS) |
| 445 | return r; |
| 446 | r = msi_reg_set_val_str( hsubkey, name, val ); |
| 447 | RegCloseKey( hsubkey ); |
| 448 | return r; |
| 449 | } |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 450 | |
Mike McCormack | a3c03fe | 2006-07-14 15:19:32 +0900 | [diff] [blame] | 451 | LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name ) |
| 452 | { |
| 453 | DWORD len = 0; |
| 454 | LPWSTR val; |
| 455 | LONG r; |
| 456 | |
| 457 | r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len); |
| 458 | if (r != ERROR_SUCCESS) |
| 459 | return NULL; |
| 460 | |
| 461 | len += sizeof (WCHAR); |
| 462 | val = msi_alloc( len ); |
| 463 | if (!val) |
| 464 | return NULL; |
| 465 | val[0] = 0; |
| 466 | RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len); |
| 467 | return val; |
| 468 | } |
| 469 | |
| 470 | BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val) |
| 471 | { |
| 472 | DWORD type, len = sizeof (DWORD); |
| 473 | LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len); |
| 474 | return r == ERROR_SUCCESS && type == REG_DWORD; |
| 475 | } |
| 476 | |
James Hawkins | 1130d59 | 2007-07-02 20:22:57 -0700 | [diff] [blame] | 477 | static UINT get_user_sid(LPWSTR *usersid) |
| 478 | { |
| 479 | HANDLE token; |
| 480 | BYTE buf[1024]; |
| 481 | DWORD size; |
| 482 | PTOKEN_USER user; |
| 483 | |
| 484 | if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) |
| 485 | return ERROR_FUNCTION_FAILED; |
| 486 | |
| 487 | size = sizeof(buf); |
Michael Stefaniuc | 5f3ac30 | 2009-01-15 09:46:57 +0100 | [diff] [blame] | 488 | if (!GetTokenInformation(token, TokenUser, buf, size, &size)) { |
Christoph von Wittich | 007833f | 2008-01-20 17:58:40 +0100 | [diff] [blame] | 489 | CloseHandle(token); |
James Hawkins | 1130d59 | 2007-07-02 20:22:57 -0700 | [diff] [blame] | 490 | return ERROR_FUNCTION_FAILED; |
Christoph von Wittich | 007833f | 2008-01-20 17:58:40 +0100 | [diff] [blame] | 491 | } |
James Hawkins | 1130d59 | 2007-07-02 20:22:57 -0700 | [diff] [blame] | 492 | |
| 493 | user = (PTOKEN_USER)buf; |
Christoph von Wittich | 007833f | 2008-01-20 17:58:40 +0100 | [diff] [blame] | 494 | if (!ConvertSidToStringSidW(user->User.Sid, usersid)) { |
| 495 | CloseHandle(token); |
James Hawkins | 1130d59 | 2007-07-02 20:22:57 -0700 | [diff] [blame] | 496 | return ERROR_FUNCTION_FAILED; |
Christoph von Wittich | 007833f | 2008-01-20 17:58:40 +0100 | [diff] [blame] | 497 | } |
| 498 | CloseHandle(token); |
James Hawkins | 1130d59 | 2007-07-02 20:22:57 -0700 | [diff] [blame] | 499 | return ERROR_SUCCESS; |
| 500 | } |
| 501 | |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 502 | UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create) |
| 503 | { |
| 504 | UINT rc; |
| 505 | WCHAR keypath[0x200]; |
| 506 | TRACE("%s\n",debugstr_w(szProduct)); |
| 507 | |
| 508 | sprintfW(keypath,szUninstall_fmt,szProduct); |
| 509 | |
| 510 | if (create) |
| 511 | rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); |
| 512 | else |
| 513 | rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); |
| 514 | |
| 515 | return rc; |
| 516 | } |
| 517 | |
James Hawkins | f6b2767 | 2007-11-13 00:47:21 -0600 | [diff] [blame] | 518 | UINT MSIREG_DeleteUninstallKey(LPCWSTR szProduct) |
| 519 | { |
| 520 | WCHAR keypath[0x200]; |
| 521 | TRACE("%s\n",debugstr_w(szProduct)); |
| 522 | |
| 523 | sprintfW(keypath,szUninstall_fmt,szProduct); |
| 524 | |
| 525 | return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath); |
| 526 | } |
| 527 | |
James Hawkins | c965d83 | 2009-03-22 14:30:16 -0700 | [diff] [blame] | 528 | UINT MSIREG_OpenProductKey(LPCWSTR szProduct, LPCWSTR szUserSid, |
| 529 | MSIINSTALLCONTEXT context, HKEY *key, BOOL create) |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 530 | { |
James Hawkins | 70be1e7 | 2008-11-03 22:16:43 -0600 | [diff] [blame] | 531 | UINT r; |
James Hawkins | c965d83 | 2009-03-22 14:30:16 -0700 | [diff] [blame] | 532 | LPWSTR usersid = NULL; |
James Hawkins | 70be1e7 | 2008-11-03 22:16:43 -0600 | [diff] [blame] | 533 | HKEY root = HKEY_LOCAL_MACHINE; |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 534 | WCHAR squished_pc[GUID_SIZE]; |
James Hawkins | 70be1e7 | 2008-11-03 22:16:43 -0600 | [diff] [blame] | 535 | WCHAR keypath[MAX_PATH]; |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 536 | |
James Hawkins | 70be1e7 | 2008-11-03 22:16:43 -0600 | [diff] [blame] | 537 | TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create); |
| 538 | |
| 539 | if (!squash_guid(szProduct, squished_pc)) |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 540 | return ERROR_FUNCTION_FAILED; |
James Hawkins | 70be1e7 | 2008-11-03 22:16:43 -0600 | [diff] [blame] | 541 | |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 542 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 543 | |
James Hawkins | 70be1e7 | 2008-11-03 22:16:43 -0600 | [diff] [blame] | 544 | if (context == MSIINSTALLCONTEXT_MACHINE) |
| 545 | { |
| 546 | sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc); |
| 547 | } |
| 548 | else if (context == MSIINSTALLCONTEXT_USERUNMANAGED) |
| 549 | { |
| 550 | root = HKEY_CURRENT_USER; |
| 551 | sprintfW(keypath, szUserProduct_fmt, squished_pc); |
| 552 | } |
| 553 | else |
| 554 | { |
James Hawkins | c965d83 | 2009-03-22 14:30:16 -0700 | [diff] [blame] | 555 | if (!szUserSid) |
James Hawkins | 70be1e7 | 2008-11-03 22:16:43 -0600 | [diff] [blame] | 556 | { |
James Hawkins | c965d83 | 2009-03-22 14:30:16 -0700 | [diff] [blame] | 557 | r = get_user_sid(&usersid); |
| 558 | if (r != ERROR_SUCCESS || !usersid) |
| 559 | { |
| 560 | ERR("Failed to retrieve user SID: %d\n", r); |
| 561 | return r; |
| 562 | } |
| 563 | |
| 564 | szUserSid = usersid; |
James Hawkins | 70be1e7 | 2008-11-03 22:16:43 -0600 | [diff] [blame] | 565 | } |
| 566 | |
James Hawkins | c965d83 | 2009-03-22 14:30:16 -0700 | [diff] [blame] | 567 | sprintfW(keypath, szInstaller_LocalManagedProd_fmt, |
| 568 | szUserSid, squished_pc); |
James Hawkins | 70be1e7 | 2008-11-03 22:16:43 -0600 | [diff] [blame] | 569 | LocalFree(usersid); |
| 570 | } |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 571 | |
| 572 | if (create) |
James Hawkins | 70be1e7 | 2008-11-03 22:16:43 -0600 | [diff] [blame] | 573 | return RegCreateKeyW(root, keypath, key); |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 574 | |
James Hawkins | 70be1e7 | 2008-11-03 22:16:43 -0600 | [diff] [blame] | 575 | return RegOpenKeyW(root, keypath, key); |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 576 | } |
| 577 | |
James Hawkins | 624bbbe | 2007-07-02 20:20:54 -0700 | [diff] [blame] | 578 | UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct) |
| 579 | { |
| 580 | WCHAR squished_pc[GUID_SIZE]; |
| 581 | WCHAR keypath[0x200]; |
| 582 | |
| 583 | TRACE("%s\n",debugstr_w(szProduct)); |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 584 | if (!squash_guid(szProduct,squished_pc)) |
| 585 | return ERROR_FUNCTION_FAILED; |
James Hawkins | 624bbbe | 2007-07-02 20:20:54 -0700 | [diff] [blame] | 586 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 587 | |
| 588 | sprintfW(keypath,szUserProduct_fmt,squished_pc); |
| 589 | |
| 590 | return RegDeleteTreeW(HKEY_CURRENT_USER, keypath); |
| 591 | } |
| 592 | |
James Hawkins | 04c67c2 | 2007-07-02 20:18:34 -0700 | [diff] [blame] | 593 | UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create) |
| 594 | { |
| 595 | UINT rc; |
| 596 | WCHAR squished_pc[GUID_SIZE]; |
| 597 | WCHAR keypath[0x200]; |
| 598 | |
| 599 | TRACE("%s\n",debugstr_w(szPatch)); |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 600 | if (!squash_guid(szPatch,squished_pc)) |
| 601 | return ERROR_FUNCTION_FAILED; |
James Hawkins | 04c67c2 | 2007-07-02 20:18:34 -0700 | [diff] [blame] | 602 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 603 | |
| 604 | sprintfW(keypath,szUserPatch_fmt,squished_pc); |
| 605 | |
| 606 | if (create) |
| 607 | rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key); |
| 608 | else |
| 609 | rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key); |
| 610 | |
| 611 | return rc; |
| 612 | } |
| 613 | |
James Hawkins | 0c01c58 | 2008-11-03 22:16:50 -0600 | [diff] [blame] | 614 | UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context, |
| 615 | HKEY *key, BOOL create) |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 616 | { |
James Hawkins | 0c01c58 | 2008-11-03 22:16:50 -0600 | [diff] [blame] | 617 | UINT r; |
| 618 | LPWSTR usersid; |
| 619 | HKEY root = HKEY_LOCAL_MACHINE; |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 620 | WCHAR squished_pc[GUID_SIZE]; |
James Hawkins | 0c01c58 | 2008-11-03 22:16:50 -0600 | [diff] [blame] | 621 | WCHAR keypath[MAX_PATH]; |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 622 | |
James Hawkins | 0c01c58 | 2008-11-03 22:16:50 -0600 | [diff] [blame] | 623 | TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create); |
| 624 | |
| 625 | if (!squash_guid(szProduct, squished_pc)) |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 626 | return ERROR_FUNCTION_FAILED; |
James Hawkins | 0c01c58 | 2008-11-03 22:16:50 -0600 | [diff] [blame] | 627 | |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 628 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 629 | |
James Hawkins | 0c01c58 | 2008-11-03 22:16:50 -0600 | [diff] [blame] | 630 | if (context == MSIINSTALLCONTEXT_MACHINE) |
| 631 | { |
| 632 | sprintfW(keypath, szInstaller_LocalClassesFeat_fmt, squished_pc); |
| 633 | } |
| 634 | else if (context == MSIINSTALLCONTEXT_USERUNMANAGED) |
| 635 | { |
| 636 | root = HKEY_CURRENT_USER; |
| 637 | sprintfW(keypath, szUserFeatures_fmt, squished_pc); |
| 638 | } |
| 639 | else |
| 640 | { |
| 641 | r = get_user_sid(&usersid); |
| 642 | if (r != ERROR_SUCCESS || !usersid) |
| 643 | { |
| 644 | ERR("Failed to retrieve user SID: %d\n", r); |
| 645 | return r; |
| 646 | } |
| 647 | |
| 648 | sprintfW(keypath, szInstaller_LocalManagedFeat_fmt, usersid, squished_pc); |
| 649 | LocalFree(usersid); |
| 650 | } |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 651 | |
| 652 | if (create) |
James Hawkins | 0c01c58 | 2008-11-03 22:16:50 -0600 | [diff] [blame] | 653 | return RegCreateKeyW(root, keypath, key); |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 654 | |
James Hawkins | 0c01c58 | 2008-11-03 22:16:50 -0600 | [diff] [blame] | 655 | return RegOpenKeyW(root, keypath, key); |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 656 | } |
| 657 | |
James Hawkins | 6ac0816 | 2007-08-09 11:38:48 -0700 | [diff] [blame] | 658 | UINT MSIREG_DeleteUserFeaturesKey(LPCWSTR szProduct) |
| 659 | { |
| 660 | WCHAR squished_pc[GUID_SIZE]; |
| 661 | WCHAR keypath[0x200]; |
| 662 | |
| 663 | TRACE("%s\n",debugstr_w(szProduct)); |
| 664 | if (!squash_guid(szProduct,squished_pc)) |
| 665 | return ERROR_FUNCTION_FAILED; |
| 666 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 667 | |
| 668 | sprintfW(keypath,szUserFeatures_fmt,squished_pc); |
| 669 | return RegDeleteTreeW(HKEY_CURRENT_USER, keypath); |
| 670 | } |
| 671 | |
Andrew Talbot | 668197a | 2009-01-10 14:20:03 +0000 | [diff] [blame] | 672 | static UINT MSIREG_OpenInstallerFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create) |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 673 | { |
| 674 | UINT rc; |
| 675 | WCHAR squished_pc[GUID_SIZE]; |
| 676 | WCHAR keypath[0x200]; |
| 677 | |
| 678 | TRACE("%s\n",debugstr_w(szProduct)); |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 679 | if (!squash_guid(szProduct,squished_pc)) |
| 680 | return ERROR_FUNCTION_FAILED; |
Aric Stewart | a26aa0a | 2005-01-25 10:58:36 +0000 | [diff] [blame] | 681 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 682 | |
| 683 | sprintfW(keypath,szInstaller_Features_fmt,squished_pc); |
| 684 | |
| 685 | if (create) |
| 686 | rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key); |
| 687 | else |
| 688 | rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key); |
| 689 | |
| 690 | return rc; |
| 691 | } |
| 692 | |
James Hawkins | e307434 | 2008-11-03 22:16:54 -0600 | [diff] [blame] | 693 | UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, MSIINSTALLCONTEXT context, |
| 694 | HKEY *key, BOOL create) |
James Hawkins | 1130d59 | 2007-07-02 20:22:57 -0700 | [diff] [blame] | 695 | { |
James Hawkins | e307434 | 2008-11-03 22:16:54 -0600 | [diff] [blame] | 696 | UINT r; |
James Hawkins | 1130d59 | 2007-07-02 20:22:57 -0700 | [diff] [blame] | 697 | LPWSTR usersid; |
James Hawkins | 2a180e0 | 2008-06-19 00:32:59 -0500 | [diff] [blame] | 698 | WCHAR squished_pc[GUID_SIZE]; |
| 699 | WCHAR keypath[0x200]; |
| 700 | |
James Hawkins | e307434 | 2008-11-03 22:16:54 -0600 | [diff] [blame] | 701 | TRACE("(%s, %d, %d)\n", debugstr_w(szProduct), context, create); |
| 702 | |
James Hawkins | 2a180e0 | 2008-06-19 00:32:59 -0500 | [diff] [blame] | 703 | if (!squash_guid(szProduct, squished_pc)) |
| 704 | return ERROR_FUNCTION_FAILED; |
James Hawkins | e307434 | 2008-11-03 22:16:54 -0600 | [diff] [blame] | 705 | |
James Hawkins | 2a180e0 | 2008-06-19 00:32:59 -0500 | [diff] [blame] | 706 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 707 | |
James Hawkins | e307434 | 2008-11-03 22:16:54 -0600 | [diff] [blame] | 708 | if (context == MSIINSTALLCONTEXT_MACHINE) |
| 709 | { |
James Hawkins | 930b429 | 2008-12-09 00:20:56 -0600 | [diff] [blame] | 710 | sprintfW(keypath, szUserDataFeatures_fmt, szLocalSid, squished_pc); |
James Hawkins | e307434 | 2008-11-03 22:16:54 -0600 | [diff] [blame] | 711 | } |
| 712 | else |
| 713 | { |
| 714 | r = get_user_sid(&usersid); |
| 715 | if (r != ERROR_SUCCESS || !usersid) |
| 716 | { |
| 717 | ERR("Failed to retrieve user SID: %d\n", r); |
| 718 | return r; |
| 719 | } |
| 720 | |
| 721 | sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc); |
| 722 | LocalFree(usersid); |
| 723 | } |
James Hawkins | 2a180e0 | 2008-06-19 00:32:59 -0500 | [diff] [blame] | 724 | |
| 725 | if (create) |
| 726 | return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); |
| 727 | |
| 728 | return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); |
| 729 | } |
| 730 | |
Aric Stewart | 072c5e5 | 2005-04-20 12:50:05 +0000 | [diff] [blame] | 731 | UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create) |
| 732 | { |
| 733 | UINT rc; |
| 734 | WCHAR squished_cc[GUID_SIZE]; |
| 735 | WCHAR keypath[0x200]; |
| 736 | |
| 737 | TRACE("%s\n",debugstr_w(szComponent)); |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 738 | if (!squash_guid(szComponent,squished_cc)) |
| 739 | return ERROR_FUNCTION_FAILED; |
Aric Stewart | 072c5e5 | 2005-04-20 12:50:05 +0000 | [diff] [blame] | 740 | TRACE("squished (%s)\n", debugstr_w(squished_cc)); |
| 741 | |
| 742 | sprintfW(keypath,szUser_Components_fmt,squished_cc); |
| 743 | |
| 744 | if (create) |
| 745 | rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key); |
| 746 | else |
| 747 | rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key); |
| 748 | |
| 749 | return rc; |
| 750 | } |
| 751 | |
James Hawkins | b198f4f | 2008-12-09 00:21:00 -0600 | [diff] [blame] | 752 | UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid, |
| 753 | HKEY *key, BOOL create) |
James Hawkins | 39a5638 | 2007-07-02 20:24:40 -0700 | [diff] [blame] | 754 | { |
| 755 | UINT rc; |
| 756 | WCHAR comp[GUID_SIZE]; |
| 757 | WCHAR keypath[0x200]; |
| 758 | LPWSTR usersid; |
| 759 | |
| 760 | TRACE("%s\n", debugstr_w(szComponent)); |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 761 | if (!squash_guid(szComponent, comp)) |
| 762 | return ERROR_FUNCTION_FAILED; |
James Hawkins | 39a5638 | 2007-07-02 20:24:40 -0700 | [diff] [blame] | 763 | TRACE("squished (%s)\n", debugstr_w(comp)); |
| 764 | |
James Hawkins | b198f4f | 2008-12-09 00:21:00 -0600 | [diff] [blame] | 765 | if (!szUserSid) |
James Hawkins | 39a5638 | 2007-07-02 20:24:40 -0700 | [diff] [blame] | 766 | { |
James Hawkins | b198f4f | 2008-12-09 00:21:00 -0600 | [diff] [blame] | 767 | rc = get_user_sid(&usersid); |
| 768 | if (rc != ERROR_SUCCESS || !usersid) |
| 769 | { |
| 770 | ERR("Failed to retrieve user SID: %d\n", rc); |
| 771 | return rc; |
| 772 | } |
James Hawkins | 39a5638 | 2007-07-02 20:24:40 -0700 | [diff] [blame] | 773 | |
James Hawkins | b198f4f | 2008-12-09 00:21:00 -0600 | [diff] [blame] | 774 | sprintfW(keypath, szUserDataComp_fmt, usersid, comp); |
| 775 | LocalFree(usersid); |
| 776 | } |
| 777 | else |
| 778 | sprintfW(keypath, szUserDataComp_fmt, szUserSid, comp); |
James Hawkins | 39a5638 | 2007-07-02 20:24:40 -0700 | [diff] [blame] | 779 | |
| 780 | if (create) |
| 781 | rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); |
| 782 | else |
| 783 | rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); |
| 784 | |
James Hawkins | 39a5638 | 2007-07-02 20:24:40 -0700 | [diff] [blame] | 785 | return rc; |
| 786 | } |
| 787 | |
James Hawkins | a9e0290 | 2008-12-09 00:21:19 -0600 | [diff] [blame] | 788 | UINT MSIREG_DeleteUserDataComponentKey(LPCWSTR szComponent, LPCWSTR szUserSid) |
James Hawkins | fc6b9dd | 2007-11-01 03:12:41 -0500 | [diff] [blame] | 789 | { |
| 790 | UINT rc; |
| 791 | WCHAR comp[GUID_SIZE]; |
| 792 | WCHAR keypath[0x200]; |
| 793 | LPWSTR usersid; |
| 794 | |
| 795 | TRACE("%s\n", debugstr_w(szComponent)); |
| 796 | if (!squash_guid(szComponent, comp)) |
| 797 | return ERROR_FUNCTION_FAILED; |
| 798 | TRACE("squished (%s)\n", debugstr_w(comp)); |
| 799 | |
James Hawkins | a9e0290 | 2008-12-09 00:21:19 -0600 | [diff] [blame] | 800 | if (!szUserSid) |
James Hawkins | fc6b9dd | 2007-11-01 03:12:41 -0500 | [diff] [blame] | 801 | { |
James Hawkins | a9e0290 | 2008-12-09 00:21:19 -0600 | [diff] [blame] | 802 | rc = get_user_sid(&usersid); |
| 803 | if (rc != ERROR_SUCCESS || !usersid) |
| 804 | { |
| 805 | ERR("Failed to retrieve user SID: %d\n", rc); |
| 806 | return rc; |
| 807 | } |
| 808 | |
| 809 | sprintfW(keypath, szUserDataComp_fmt, usersid, comp); |
| 810 | LocalFree(usersid); |
James Hawkins | fc6b9dd | 2007-11-01 03:12:41 -0500 | [diff] [blame] | 811 | } |
James Hawkins | a9e0290 | 2008-12-09 00:21:19 -0600 | [diff] [blame] | 812 | else |
| 813 | sprintfW(keypath, szUserDataComp_fmt, szUserSid, comp); |
James Hawkins | fc6b9dd | 2007-11-01 03:12:41 -0500 | [diff] [blame] | 814 | |
James Hawkins | fc6b9dd | 2007-11-01 03:12:41 -0500 | [diff] [blame] | 815 | return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath); |
| 816 | } |
| 817 | |
James Hawkins | 4a9f699 | 2008-12-14 21:07:06 -0600 | [diff] [blame] | 818 | UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContext, |
| 819 | LPCWSTR szUserSid, HKEY *key, BOOL create) |
James Hawkins | 7da89f4 | 2007-06-26 19:01:03 -0700 | [diff] [blame] | 820 | { |
| 821 | UINT rc; |
| 822 | WCHAR squished_pc[GUID_SIZE]; |
| 823 | WCHAR keypath[0x200]; |
| 824 | LPWSTR usersid; |
| 825 | |
| 826 | TRACE("%s\n", debugstr_w(szProduct)); |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 827 | if (!squash_guid(szProduct, squished_pc)) |
| 828 | return ERROR_FUNCTION_FAILED; |
James Hawkins | 7da89f4 | 2007-06-26 19:01:03 -0700 | [diff] [blame] | 829 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 830 | |
James Hawkins | 4a9f699 | 2008-12-14 21:07:06 -0600 | [diff] [blame] | 831 | if (dwContext == MSIINSTALLCONTEXT_MACHINE) |
| 832 | sprintfW(keypath, szUserDataProd_fmt, szLocalSid, squished_pc); |
| 833 | else if (szUserSid) |
James Hawkins | 3956bb5 | 2009-03-22 14:29:51 -0700 | [diff] [blame] | 834 | sprintfW(keypath, szUserDataProd_fmt, szUserSid, squished_pc); |
James Hawkins | 4a9f699 | 2008-12-14 21:07:06 -0600 | [diff] [blame] | 835 | else |
James Hawkins | 7da89f4 | 2007-06-26 19:01:03 -0700 | [diff] [blame] | 836 | { |
James Hawkins | 930b429 | 2008-12-09 00:20:56 -0600 | [diff] [blame] | 837 | rc = get_user_sid(&usersid); |
| 838 | if (rc != ERROR_SUCCESS || !usersid) |
| 839 | { |
| 840 | ERR("Failed to retrieve user SID: %d\n", rc); |
| 841 | return rc; |
| 842 | } |
James Hawkins | 7da89f4 | 2007-06-26 19:01:03 -0700 | [diff] [blame] | 843 | |
James Hawkins | 930b429 | 2008-12-09 00:20:56 -0600 | [diff] [blame] | 844 | sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc); |
| 845 | LocalFree(usersid); |
| 846 | } |
James Hawkins | 7da89f4 | 2007-06-26 19:01:03 -0700 | [diff] [blame] | 847 | |
| 848 | if (create) |
| 849 | rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); |
| 850 | else |
| 851 | rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); |
| 852 | |
| 853 | return rc; |
| 854 | } |
| 855 | |
James Hawkins | 880b919 | 2008-12-14 21:07:09 -0600 | [diff] [blame] | 856 | UINT MSIREG_OpenUserDataPatchKey(LPCWSTR szPatch, MSIINSTALLCONTEXT dwContext, |
| 857 | HKEY *key, BOOL create) |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 858 | { |
| 859 | UINT rc; |
James Hawkins | 880b919 | 2008-12-14 21:07:09 -0600 | [diff] [blame] | 860 | WCHAR squished_patch[GUID_SIZE]; |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 861 | WCHAR keypath[0x200]; |
| 862 | LPWSTR usersid; |
| 863 | |
James Hawkins | 880b919 | 2008-12-14 21:07:09 -0600 | [diff] [blame] | 864 | TRACE("%s\n", debugstr_w(szPatch)); |
| 865 | if (!squash_guid(szPatch, squished_patch)) |
| 866 | return ERROR_FUNCTION_FAILED; |
| 867 | TRACE("squished (%s)\n", debugstr_w(squished_patch)); |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 868 | |
James Hawkins | 880b919 | 2008-12-14 21:07:09 -0600 | [diff] [blame] | 869 | if (dwContext == MSIINSTALLCONTEXT_MACHINE) |
| 870 | sprintfW(keypath, szUserDataPatch_fmt, szLocalSid, squished_patch); |
| 871 | else |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 872 | { |
James Hawkins | 880b919 | 2008-12-14 21:07:09 -0600 | [diff] [blame] | 873 | rc = get_user_sid(&usersid); |
| 874 | if (rc != ERROR_SUCCESS || !usersid) |
| 875 | { |
| 876 | ERR("Failed to retrieve user SID: %d\n", rc); |
| 877 | return rc; |
| 878 | } |
| 879 | |
| 880 | sprintfW(keypath, szUserDataPatch_fmt, usersid, squished_patch); |
| 881 | LocalFree(usersid); |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 882 | } |
| 883 | |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 884 | if (create) |
James Hawkins | 880b919 | 2008-12-14 21:07:09 -0600 | [diff] [blame] | 885 | return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 886 | |
James Hawkins | 880b919 | 2008-12-14 21:07:09 -0600 | [diff] [blame] | 887 | return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 888 | } |
| 889 | |
James Hawkins | b5e3e19 | 2008-12-14 21:07:14 -0600 | [diff] [blame] | 890 | UINT MSIREG_OpenInstallProps(LPCWSTR szProduct, MSIINSTALLCONTEXT dwContext, |
| 891 | LPCWSTR szUserSid, HKEY *key, BOOL create) |
James Hawkins | 0e44e09 | 2007-07-02 20:21:58 -0700 | [diff] [blame] | 892 | { |
| 893 | UINT rc; |
James Hawkins | b5e3e19 | 2008-12-14 21:07:14 -0600 | [diff] [blame] | 894 | LPWSTR usersid; |
James Hawkins | 0e44e09 | 2007-07-02 20:21:58 -0700 | [diff] [blame] | 895 | WCHAR squished_pc[GUID_SIZE]; |
| 896 | WCHAR keypath[0x200]; |
James Hawkins | 0e44e09 | 2007-07-02 20:21:58 -0700 | [diff] [blame] | 897 | |
| 898 | TRACE("%s\n", debugstr_w(szProduct)); |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 899 | if (!squash_guid(szProduct, squished_pc)) |
| 900 | return ERROR_FUNCTION_FAILED; |
James Hawkins | 0e44e09 | 2007-07-02 20:21:58 -0700 | [diff] [blame] | 901 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 902 | |
James Hawkins | b5e3e19 | 2008-12-14 21:07:14 -0600 | [diff] [blame] | 903 | if (dwContext == MSIINSTALLCONTEXT_MACHINE) |
| 904 | sprintfW(keypath, szInstallProperties_fmt, szLocalSid, squished_pc); |
| 905 | else if (szUserSid) |
| 906 | sprintfW(keypath, szInstallProperties_fmt, szUserSid, squished_pc); |
James Hawkins | e21a26e | 2008-04-05 05:41:54 -0500 | [diff] [blame] | 907 | else |
James Hawkins | 0e44e09 | 2007-07-02 20:21:58 -0700 | [diff] [blame] | 908 | { |
James Hawkins | b5e3e19 | 2008-12-14 21:07:14 -0600 | [diff] [blame] | 909 | rc = get_user_sid(&usersid); |
| 910 | if (rc != ERROR_SUCCESS || !usersid) |
| 911 | { |
| 912 | ERR("Failed to retrieve user SID: %d\n", rc); |
| 913 | return rc; |
| 914 | } |
| 915 | |
| 916 | sprintfW(keypath, szInstallProperties_fmt, usersid, squished_pc); |
| 917 | LocalFree(usersid); |
James Hawkins | 0e44e09 | 2007-07-02 20:21:58 -0700 | [diff] [blame] | 918 | } |
| 919 | |
James Hawkins | b5e3e19 | 2008-12-14 21:07:14 -0600 | [diff] [blame] | 920 | if (create) |
| 921 | return RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key); |
James Hawkins | 0e44e09 | 2007-07-02 20:21:58 -0700 | [diff] [blame] | 922 | |
James Hawkins | b5e3e19 | 2008-12-14 21:07:14 -0600 | [diff] [blame] | 923 | return RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key); |
James Hawkins | 0e44e09 | 2007-07-02 20:21:58 -0700 | [diff] [blame] | 924 | } |
| 925 | |
James Hawkins | 624bbbe | 2007-07-02 20:20:54 -0700 | [diff] [blame] | 926 | UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct) |
| 927 | { |
| 928 | UINT rc; |
| 929 | WCHAR squished_pc[GUID_SIZE]; |
| 930 | WCHAR keypath[0x200]; |
| 931 | LPWSTR usersid; |
| 932 | |
| 933 | TRACE("%s\n", debugstr_w(szProduct)); |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 934 | if (!squash_guid(szProduct, squished_pc)) |
| 935 | return ERROR_FUNCTION_FAILED; |
James Hawkins | 624bbbe | 2007-07-02 20:20:54 -0700 | [diff] [blame] | 936 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 937 | |
| 938 | rc = get_user_sid(&usersid); |
| 939 | if (rc != ERROR_SUCCESS || !usersid) |
| 940 | { |
| 941 | ERR("Failed to retrieve user SID: %d\n", rc); |
| 942 | return rc; |
| 943 | } |
| 944 | |
| 945 | sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc); |
| 946 | |
Marcus Meissner | 943ac97 | 2008-01-20 21:11:19 +0100 | [diff] [blame] | 947 | LocalFree(usersid); |
James Hawkins | 624bbbe | 2007-07-02 20:20:54 -0700 | [diff] [blame] | 948 | return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath); |
| 949 | } |
| 950 | |
James Hawkins | 624bbbe | 2007-07-02 20:20:54 -0700 | [diff] [blame] | 951 | UINT MSIREG_DeleteProductKey(LPCWSTR szProduct) |
| 952 | { |
| 953 | WCHAR squished_pc[GUID_SIZE]; |
| 954 | WCHAR keypath[0x200]; |
| 955 | |
| 956 | TRACE("%s\n", debugstr_w(szProduct)); |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 957 | if (!squash_guid(szProduct, squished_pc)) |
| 958 | return ERROR_FUNCTION_FAILED; |
James Hawkins | 624bbbe | 2007-07-02 20:20:54 -0700 | [diff] [blame] | 959 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 960 | |
| 961 | sprintfW(keypath, szInstaller_Products_fmt, squished_pc); |
| 962 | |
| 963 | return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath); |
| 964 | } |
| 965 | |
James Hawkins | 04c67c2 | 2007-07-02 20:18:34 -0700 | [diff] [blame] | 966 | UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create) |
| 967 | { |
| 968 | UINT rc; |
| 969 | WCHAR squished_pc[GUID_SIZE]; |
| 970 | WCHAR keypath[0x200]; |
| 971 | |
| 972 | TRACE("%s\n",debugstr_w(szPatch)); |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 973 | if (!squash_guid(szPatch,squished_pc)) |
| 974 | return ERROR_FUNCTION_FAILED; |
James Hawkins | 04c67c2 | 2007-07-02 20:18:34 -0700 | [diff] [blame] | 975 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 976 | |
| 977 | sprintfW(keypath,szInstaller_Patches_fmt,squished_pc); |
| 978 | |
| 979 | if (create) |
| 980 | rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key); |
| 981 | else |
| 982 | rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key); |
| 983 | |
| 984 | return rc; |
| 985 | } |
| 986 | |
Juan Lang | 3d4ce5c | 2005-03-10 17:24:05 +0000 | [diff] [blame] | 987 | UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create) |
| 988 | { |
| 989 | UINT rc; |
| 990 | WCHAR squished_pc[GUID_SIZE]; |
| 991 | WCHAR keypath[0x200]; |
| 992 | |
| 993 | TRACE("%s\n",debugstr_w(szUpgradeCode)); |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 994 | if (!squash_guid(szUpgradeCode,squished_pc)) |
| 995 | return ERROR_FUNCTION_FAILED; |
Juan Lang | 3d4ce5c | 2005-03-10 17:24:05 +0000 | [diff] [blame] | 996 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 997 | |
| 998 | sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc); |
| 999 | |
| 1000 | if (create) |
| 1001 | rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key); |
| 1002 | else |
| 1003 | rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key); |
| 1004 | |
| 1005 | return rc; |
| 1006 | } |
| 1007 | |
Aric Stewart | 19ba432 | 2005-06-07 20:02:27 +0000 | [diff] [blame] | 1008 | UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create) |
| 1009 | { |
| 1010 | UINT rc; |
| 1011 | WCHAR squished_pc[GUID_SIZE]; |
| 1012 | WCHAR keypath[0x200]; |
| 1013 | |
| 1014 | TRACE("%s\n",debugstr_w(szUpgradeCode)); |
Paul Vriens | 5e7b31b | 2007-07-30 20:13:04 +0200 | [diff] [blame] | 1015 | if (!squash_guid(szUpgradeCode,squished_pc)) |
| 1016 | return ERROR_FUNCTION_FAILED; |
Aric Stewart | 19ba432 | 2005-06-07 20:02:27 +0000 | [diff] [blame] | 1017 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 1018 | |
| 1019 | sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc); |
| 1020 | |
| 1021 | if (create) |
| 1022 | rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key); |
| 1023 | else |
| 1024 | rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key); |
| 1025 | |
| 1026 | return rc; |
| 1027 | } |
| 1028 | |
James Hawkins | cdb33f8 | 2008-06-23 23:02:54 -0500 | [diff] [blame] | 1029 | UINT MSIREG_DeleteUserUpgradeCodesKey(LPCWSTR szUpgradeCode) |
| 1030 | { |
| 1031 | WCHAR squished_pc[GUID_SIZE]; |
| 1032 | WCHAR keypath[0x200]; |
| 1033 | |
| 1034 | TRACE("%s\n",debugstr_w(szUpgradeCode)); |
| 1035 | if (!squash_guid(szUpgradeCode,squished_pc)) |
| 1036 | return ERROR_FUNCTION_FAILED; |
| 1037 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 1038 | |
| 1039 | sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc); |
| 1040 | |
| 1041 | return RegDeleteTreeW(HKEY_CURRENT_USER, keypath); |
| 1042 | } |
| 1043 | |
James Hawkins | 38106ac | 2008-07-28 18:46:32 -0500 | [diff] [blame] | 1044 | UINT MSIREG_DeleteLocalClassesProductKey(LPCWSTR szProductCode) |
| 1045 | { |
| 1046 | WCHAR squished_pc[GUID_SIZE]; |
| 1047 | WCHAR keypath[0x200]; |
| 1048 | |
| 1049 | TRACE("%s\n", debugstr_w(szProductCode)); |
| 1050 | |
| 1051 | if (!squash_guid(szProductCode, squished_pc)) |
| 1052 | return ERROR_FUNCTION_FAILED; |
| 1053 | |
| 1054 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 1055 | |
| 1056 | sprintfW(keypath, szInstaller_LocalClassesProd_fmt, squished_pc); |
| 1057 | |
| 1058 | return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath); |
| 1059 | } |
| 1060 | |
James Hawkins | 38106ac | 2008-07-28 18:46:32 -0500 | [diff] [blame] | 1061 | UINT MSIREG_DeleteLocalClassesFeaturesKey(LPCWSTR szProductCode) |
| 1062 | { |
| 1063 | WCHAR squished_pc[GUID_SIZE]; |
| 1064 | WCHAR keypath[0x200]; |
| 1065 | |
| 1066 | TRACE("%s\n", debugstr_w(szProductCode)); |
| 1067 | |
| 1068 | if (!squash_guid(szProductCode, squished_pc)) |
| 1069 | return ERROR_FUNCTION_FAILED; |
| 1070 | |
| 1071 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 1072 | |
| 1073 | sprintfW(keypath, szInstaller_LocalClassesFeat_fmt, squished_pc); |
| 1074 | |
| 1075 | return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath); |
| 1076 | } |
| 1077 | |
James Hawkins | 58e1543 | 2008-06-23 23:04:46 -0500 | [diff] [blame] | 1078 | UINT MSIREG_OpenClassesUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create) |
| 1079 | { |
| 1080 | WCHAR squished_pc[GUID_SIZE]; |
| 1081 | WCHAR keypath[0x200]; |
| 1082 | |
| 1083 | TRACE("%s\n", debugstr_w(szUpgradeCode)); |
| 1084 | if (!squash_guid(szUpgradeCode, squished_pc)) |
| 1085 | return ERROR_FUNCTION_FAILED; |
| 1086 | TRACE("squished (%s)\n", debugstr_w(squished_pc)); |
| 1087 | |
| 1088 | sprintfW(keypath, szInstaller_ClassesUpgrade_fmt, squished_pc); |
| 1089 | |
| 1090 | if (create) |
| 1091 | return RegCreateKeyW(HKEY_CLASSES_ROOT, keypath, key); |
| 1092 | |
| 1093 | return RegOpenKeyW(HKEY_CLASSES_ROOT, keypath, key); |
| 1094 | } |
| 1095 | |
Mike McCormack | 5af66fe | 2005-01-25 16:41:33 +0000 | [diff] [blame] | 1096 | /************************************************************************* |
| 1097 | * MsiDecomposeDescriptorW [MSI.@] |
| 1098 | * |
| 1099 | * Decomposes an MSI descriptor into product, feature and component parts. |
| 1100 | * An MSI descriptor is a string of the form: |
| 1101 | * [base 85 guid] [feature code] '>' [base 85 guid] |
| 1102 | * |
| 1103 | * PARAMS |
| 1104 | * szDescriptor [I] the descriptor to decompose |
Robert Shearman | 2d5dc32 | 2005-11-30 12:02:06 +0100 | [diff] [blame] | 1105 | * szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid |
| 1106 | * szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code |
| 1107 | * szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid |
Mike McCormack | 5af66fe | 2005-01-25 16:41:33 +0000 | [diff] [blame] | 1108 | * pUsed [O] the length of the descriptor |
| 1109 | * |
| 1110 | * RETURNS |
| 1111 | * ERROR_SUCCESS if everything worked correctly |
| 1112 | * ERROR_INVALID_PARAMETER if the descriptor was invalid |
| 1113 | * |
| 1114 | */ |
| 1115 | UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct, |
Francois Gouget | 5771700 | 2007-08-09 10:41:41 +0200 | [diff] [blame] | 1116 | LPWSTR szFeature, LPWSTR szComponent, LPDWORD pUsed ) |
Mike McCormack | 5af66fe | 2005-01-25 16:41:33 +0000 | [diff] [blame] | 1117 | { |
| 1118 | UINT r, len; |
| 1119 | LPWSTR p; |
| 1120 | GUID product, component; |
| 1121 | |
| 1122 | TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct, |
| 1123 | szFeature, szComponent, pUsed); |
| 1124 | |
| 1125 | r = decode_base85_guid( szDescriptor, &product ); |
| 1126 | if( !r ) |
| 1127 | return ERROR_INVALID_PARAMETER; |
| 1128 | |
| 1129 | TRACE("product %s\n", debugstr_guid( &product )); |
| 1130 | |
| 1131 | p = strchrW(&szDescriptor[20],'>'); |
| 1132 | if( !p ) |
| 1133 | return ERROR_INVALID_PARAMETER; |
| 1134 | |
| 1135 | len = (p - &szDescriptor[20]); |
| 1136 | if( len > MAX_FEATURE_CHARS ) |
| 1137 | return ERROR_INVALID_PARAMETER; |
Mike McCormack | 5af66fe | 2005-01-25 16:41:33 +0000 | [diff] [blame] | 1138 | |
Eric Pouech | f2ee10a | 2006-11-08 21:47:04 +0100 | [diff] [blame] | 1139 | TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len )); |
Mike McCormack | 5af66fe | 2005-01-25 16:41:33 +0000 | [diff] [blame] | 1140 | |
| 1141 | r = decode_base85_guid( p+1, &component ); |
| 1142 | if( !r ) |
| 1143 | return ERROR_INVALID_PARAMETER; |
| 1144 | |
| 1145 | TRACE("component %s\n", debugstr_guid( &component )); |
| 1146 | |
Mike McCormack | 5c63332 | 2005-11-09 10:59:20 +0000 | [diff] [blame] | 1147 | if (szProduct) |
| 1148 | StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 ); |
| 1149 | if (szComponent) |
| 1150 | StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 ); |
Eric Pouech | f2ee10a | 2006-11-08 21:47:04 +0100 | [diff] [blame] | 1151 | if (szFeature) |
| 1152 | { |
| 1153 | memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) ); |
| 1154 | szFeature[len] = 0; |
| 1155 | } |
Mike McCormack | 5af66fe | 2005-01-25 16:41:33 +0000 | [diff] [blame] | 1156 | len = ( &p[21] - szDescriptor ); |
| 1157 | |
| 1158 | TRACE("length = %d\n", len); |
Hans Leidekker | 367c204 | 2010-03-23 11:48:02 +0100 | [diff] [blame] | 1159 | if (pUsed) *pUsed = len; |
Mike McCormack | 5af66fe | 2005-01-25 16:41:33 +0000 | [diff] [blame] | 1160 | |
| 1161 | return ERROR_SUCCESS; |
| 1162 | } |
| 1163 | |
| 1164 | UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct, |
Francois Gouget | 5771700 | 2007-08-09 10:41:41 +0200 | [diff] [blame] | 1165 | LPSTR szFeature, LPSTR szComponent, LPDWORD pUsed ) |
Mike McCormack | 5af66fe | 2005-01-25 16:41:33 +0000 | [diff] [blame] | 1166 | { |
| 1167 | WCHAR product[MAX_FEATURE_CHARS+1]; |
| 1168 | WCHAR feature[MAX_FEATURE_CHARS+1]; |
| 1169 | WCHAR component[MAX_FEATURE_CHARS+1]; |
Mike McCormack | 5c63332 | 2005-11-09 10:59:20 +0000 | [diff] [blame] | 1170 | LPWSTR str = NULL, p = NULL, f = NULL, c = NULL; |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1171 | UINT r; |
Mike McCormack | 5af66fe | 2005-01-25 16:41:33 +0000 | [diff] [blame] | 1172 | |
| 1173 | TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct, |
| 1174 | szFeature, szComponent, pUsed); |
| 1175 | |
Mike McCormack | 5c63332 | 2005-11-09 10:59:20 +0000 | [diff] [blame] | 1176 | str = strdupAtoW( szDescriptor ); |
| 1177 | if( szDescriptor && !str ) |
| 1178 | return ERROR_OUTOFMEMORY; |
Mike McCormack | 5af66fe | 2005-01-25 16:41:33 +0000 | [diff] [blame] | 1179 | |
Mike McCormack | 5c63332 | 2005-11-09 10:59:20 +0000 | [diff] [blame] | 1180 | if (szProduct) |
| 1181 | p = product; |
| 1182 | if (szFeature) |
| 1183 | f = feature; |
| 1184 | if (szComponent) |
| 1185 | c = component; |
Mike McCormack | 5af66fe | 2005-01-25 16:41:33 +0000 | [diff] [blame] | 1186 | |
Mike McCormack | 5c63332 | 2005-11-09 10:59:20 +0000 | [diff] [blame] | 1187 | r = MsiDecomposeDescriptorW( str, p, f, c, pUsed ); |
| 1188 | |
Eric Pouech | f2ee10a | 2006-11-08 21:47:04 +0100 | [diff] [blame] | 1189 | if (r == ERROR_SUCCESS) |
| 1190 | { |
| 1191 | WideCharToMultiByte( CP_ACP, 0, p, -1, |
| 1192 | szProduct, MAX_FEATURE_CHARS+1, NULL, NULL ); |
| 1193 | WideCharToMultiByte( CP_ACP, 0, f, -1, |
| 1194 | szFeature, MAX_FEATURE_CHARS+1, NULL, NULL ); |
| 1195 | WideCharToMultiByte( CP_ACP, 0, c, -1, |
| 1196 | szComponent, MAX_FEATURE_CHARS+1, NULL, NULL ); |
| 1197 | } |
Mike McCormack | 5af66fe | 2005-01-25 16:41:33 +0000 | [diff] [blame] | 1198 | |
Mike McCormack | 8dc28d5 | 2005-09-20 11:57:19 +0000 | [diff] [blame] | 1199 | msi_free( str ); |
Mike McCormack | 5af66fe | 2005-01-25 16:41:33 +0000 | [diff] [blame] | 1200 | |
| 1201 | return r; |
| 1202 | } |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1203 | |
| 1204 | UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid) |
| 1205 | { |
| 1206 | DWORD r; |
| 1207 | WCHAR szwGuid[GUID_SIZE]; |
| 1208 | |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1209 | TRACE("%d %p\n", index, lpguid); |
| 1210 | |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1211 | if (NULL == lpguid) |
| 1212 | return ERROR_INVALID_PARAMETER; |
| 1213 | r = MsiEnumProductsW(index, szwGuid); |
| 1214 | if( r == ERROR_SUCCESS ) |
| 1215 | WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL); |
| 1216 | |
| 1217 | return r; |
| 1218 | } |
| 1219 | |
| 1220 | UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid) |
| 1221 | { |
Hans Leidekker | 9163b0d | 2009-03-27 13:40:16 +0100 | [diff] [blame] | 1222 | UINT r; |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1223 | WCHAR szKeyName[SQUISH_GUID_SIZE]; |
Hans Leidekker | 9163b0d | 2009-03-27 13:40:16 +0100 | [diff] [blame] | 1224 | HKEY key; |
| 1225 | DWORD machine_count, managed_count, unmanaged_count; |
| 1226 | WCHAR keypath[MAX_PATH]; |
| 1227 | LPWSTR usersid = NULL; |
| 1228 | |
| 1229 | static DWORD last_index; |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1230 | |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1231 | TRACE("%d %p\n", index, lpguid); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1232 | |
| 1233 | if (NULL == lpguid) |
| 1234 | return ERROR_INVALID_PARAMETER; |
| 1235 | |
Hans Leidekker | 9163b0d | 2009-03-27 13:40:16 +0100 | [diff] [blame] | 1236 | if (index && index - last_index != 1) |
| 1237 | return ERROR_INVALID_PARAMETER; |
| 1238 | |
| 1239 | r = RegCreateKeyW(HKEY_LOCAL_MACHINE, szInstaller_LocalClassesProd, &key); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1240 | if( r != ERROR_SUCCESS ) |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1241 | return ERROR_NO_MORE_ITEMS; |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1242 | |
Hans Leidekker | 9163b0d | 2009-03-27 13:40:16 +0100 | [diff] [blame] | 1243 | r = RegQueryInfoKeyW(key, NULL, NULL, NULL, &machine_count, NULL, NULL, |
| 1244 | NULL, NULL, NULL, NULL, NULL); |
| 1245 | if( r != ERROR_SUCCESS ) |
| 1246 | { |
| 1247 | RegCloseKey(key); |
| 1248 | return ERROR_NO_MORE_ITEMS; |
| 1249 | } |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1250 | |
Hans Leidekker | 9163b0d | 2009-03-27 13:40:16 +0100 | [diff] [blame] | 1251 | if (machine_count && index <= machine_count) |
| 1252 | { |
| 1253 | r = RegEnumKeyW(key, index, szKeyName, SQUISH_GUID_SIZE); |
| 1254 | if( r == ERROR_SUCCESS ) |
| 1255 | { |
| 1256 | unsquash_guid(szKeyName, lpguid); |
| 1257 | last_index = index; |
| 1258 | RegCloseKey(key); |
| 1259 | return ERROR_SUCCESS; |
| 1260 | } |
| 1261 | } |
| 1262 | RegCloseKey(key); |
| 1263 | |
| 1264 | r = get_user_sid(&usersid); |
| 1265 | if (r != ERROR_SUCCESS || !usersid) |
| 1266 | { |
| 1267 | ERR("Failed to retrieve user SID: %d\n", r); |
| 1268 | return r; |
| 1269 | } |
| 1270 | sprintfW(keypath, szInstaller_LocalManaged_fmt, usersid); |
| 1271 | LocalFree(usersid); |
| 1272 | |
| 1273 | r = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, &key); |
| 1274 | if( r != ERROR_SUCCESS ) |
| 1275 | return ERROR_NO_MORE_ITEMS; |
| 1276 | |
| 1277 | r = RegQueryInfoKeyW(key, NULL, NULL, NULL, &managed_count, NULL, NULL, |
| 1278 | NULL, NULL, NULL, NULL, NULL); |
| 1279 | if( r != ERROR_SUCCESS ) |
| 1280 | { |
| 1281 | RegCloseKey(key); |
| 1282 | return ERROR_NO_MORE_ITEMS; |
| 1283 | } |
| 1284 | |
| 1285 | if (managed_count && index <= machine_count + managed_count) |
| 1286 | { |
| 1287 | r = RegEnumKeyW(key, index - machine_count, szKeyName, SQUISH_GUID_SIZE); |
| 1288 | if( r == ERROR_SUCCESS ) |
| 1289 | { |
| 1290 | unsquash_guid(szKeyName, lpguid); |
| 1291 | last_index = index; |
| 1292 | RegCloseKey(key); |
| 1293 | return ERROR_SUCCESS; |
| 1294 | } |
| 1295 | } |
| 1296 | RegCloseKey(key); |
| 1297 | |
| 1298 | r = RegCreateKeyW(HKEY_CURRENT_USER, szUserProduct, &key); |
| 1299 | if( r != ERROR_SUCCESS ) |
| 1300 | return ERROR_NO_MORE_ITEMS; |
| 1301 | |
| 1302 | r = RegQueryInfoKeyW(key, NULL, NULL, NULL, &unmanaged_count, NULL, NULL, |
| 1303 | NULL, NULL, NULL, NULL, NULL); |
| 1304 | if( r != ERROR_SUCCESS ) |
| 1305 | { |
| 1306 | RegCloseKey(key); |
| 1307 | return ERROR_NO_MORE_ITEMS; |
| 1308 | } |
| 1309 | |
| 1310 | if (unmanaged_count && index <= machine_count + managed_count + unmanaged_count) |
| 1311 | { |
| 1312 | r = RegEnumKeyW(key, index - machine_count - managed_count, szKeyName, SQUISH_GUID_SIZE); |
| 1313 | if( r == ERROR_SUCCESS ) |
| 1314 | { |
| 1315 | unsquash_guid(szKeyName, lpguid); |
| 1316 | last_index = index; |
| 1317 | RegCloseKey(key); |
| 1318 | return ERROR_SUCCESS; |
| 1319 | } |
| 1320 | } |
| 1321 | RegCloseKey(key); |
| 1322 | |
| 1323 | return ERROR_NO_MORE_ITEMS; |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index, |
| 1327 | LPSTR szFeature, LPSTR szParent) |
| 1328 | { |
| 1329 | DWORD r; |
| 1330 | WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE]; |
| 1331 | LPWSTR szwProduct = NULL; |
| 1332 | |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1333 | TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1334 | |
| 1335 | if( szProduct ) |
| 1336 | { |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1337 | szwProduct = strdupAtoW( szProduct ); |
| 1338 | if( !szwProduct ) |
| 1339 | return ERROR_OUTOFMEMORY; |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent); |
| 1343 | if( r == ERROR_SUCCESS ) |
| 1344 | { |
| 1345 | WideCharToMultiByte(CP_ACP, 0, szwFeature, -1, |
| 1346 | szFeature, GUID_SIZE, NULL, NULL); |
| 1347 | WideCharToMultiByte(CP_ACP, 0, szwParent, -1, |
| 1348 | szParent, GUID_SIZE, NULL, NULL); |
| 1349 | } |
| 1350 | |
Mike McCormack | 8dc28d5 | 2005-09-20 11:57:19 +0000 | [diff] [blame] | 1351 | msi_free( szwProduct); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1352 | |
| 1353 | return r; |
| 1354 | } |
| 1355 | |
| 1356 | UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index, |
| 1357 | LPWSTR szFeature, LPWSTR szParent) |
| 1358 | { |
| 1359 | HKEY hkeyProduct = 0; |
| 1360 | DWORD r, sz; |
| 1361 | |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1362 | TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1363 | |
Mike McCormack | a92fe55 | 2006-04-17 18:17:52 +0900 | [diff] [blame] | 1364 | if( !szProduct ) |
| 1365 | return ERROR_INVALID_PARAMETER; |
| 1366 | |
James Hawkins | 0c01c58 | 2008-11-03 22:16:50 -0600 | [diff] [blame] | 1367 | r = MSIREG_OpenInstallerFeaturesKey(szProduct,&hkeyProduct,FALSE); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1368 | if( r != ERROR_SUCCESS ) |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1369 | return ERROR_NO_MORE_ITEMS; |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1370 | |
| 1371 | sz = GUID_SIZE; |
| 1372 | r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL); |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1373 | RegCloseKey(hkeyProduct); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1374 | |
| 1375 | return r; |
| 1376 | } |
| 1377 | |
| 1378 | UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid) |
| 1379 | { |
| 1380 | DWORD r; |
| 1381 | WCHAR szwGuid[GUID_SIZE]; |
| 1382 | |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1383 | TRACE("%d %p\n", index, lpguid); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1384 | |
| 1385 | r = MsiEnumComponentsW(index, szwGuid); |
| 1386 | if( r == ERROR_SUCCESS ) |
| 1387 | WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL); |
| 1388 | |
| 1389 | return r; |
| 1390 | } |
| 1391 | |
| 1392 | UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid) |
| 1393 | { |
| 1394 | HKEY hkeyComponents = 0; |
| 1395 | DWORD r; |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1396 | WCHAR szKeyName[SQUISH_GUID_SIZE]; |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1397 | |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1398 | TRACE("%d %p\n", index, lpguid); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1399 | |
James Hawkins | 4aa3a99 | 2008-06-18 00:49:42 -0500 | [diff] [blame] | 1400 | r = RegCreateKeyW(HKEY_LOCAL_MACHINE, szInstaller_Components, &hkeyComponents); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1401 | if( r != ERROR_SUCCESS ) |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1402 | return ERROR_NO_MORE_ITEMS; |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1403 | |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1404 | r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE); |
| 1405 | if( r == ERROR_SUCCESS ) |
| 1406 | unsquash_guid(szKeyName, lpguid); |
| 1407 | RegCloseKey(hkeyComponents); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1408 | |
| 1409 | return r; |
| 1410 | } |
| 1411 | |
| 1412 | UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct) |
| 1413 | { |
| 1414 | DWORD r; |
| 1415 | WCHAR szwProduct[GUID_SIZE]; |
| 1416 | LPWSTR szwComponent = NULL; |
| 1417 | |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1418 | TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1419 | |
James Hawkins | 5f7b95d | 2007-12-16 20:27:22 -0600 | [diff] [blame] | 1420 | if ( !szProduct ) |
| 1421 | return ERROR_INVALID_PARAMETER; |
| 1422 | |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1423 | if( szComponent ) |
| 1424 | { |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1425 | szwComponent = strdupAtoW( szComponent ); |
| 1426 | if( !szwComponent ) |
| 1427 | return ERROR_OUTOFMEMORY; |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct); |
| 1431 | if( r == ERROR_SUCCESS ) |
| 1432 | { |
| 1433 | WideCharToMultiByte(CP_ACP, 0, szwProduct, -1, |
| 1434 | szProduct, GUID_SIZE, NULL, NULL); |
| 1435 | } |
| 1436 | |
Mike McCormack | 8dc28d5 | 2005-09-20 11:57:19 +0000 | [diff] [blame] | 1437 | msi_free( szwComponent); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1438 | |
| 1439 | return r; |
| 1440 | } |
| 1441 | |
| 1442 | UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct) |
| 1443 | { |
| 1444 | HKEY hkeyComp = 0; |
| 1445 | DWORD r, sz; |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1446 | WCHAR szValName[SQUISH_GUID_SIZE]; |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1447 | |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1448 | TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1449 | |
James Hawkins | 5f7b95d | 2007-12-16 20:27:22 -0600 | [diff] [blame] | 1450 | if (!szComponent || !*szComponent || !szProduct) |
James Hawkins | 64c75d1 | 2007-12-16 20:26:42 -0600 | [diff] [blame] | 1451 | return ERROR_INVALID_PARAMETER; |
| 1452 | |
James Hawkins | b198f4f | 2008-12-09 00:21:00 -0600 | [diff] [blame] | 1453 | if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkeyComp, FALSE) != ERROR_SUCCESS && |
James Hawkins | bdf7da9 | 2008-12-09 00:21:15 -0600 | [diff] [blame] | 1454 | MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkeyComp, FALSE) != ERROR_SUCCESS) |
James Hawkins | fced2fe | 2007-12-16 20:28:09 -0600 | [diff] [blame] | 1455 | return ERROR_UNKNOWN_COMPONENT; |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1456 | |
James Hawkins | 88d51ad | 2007-12-16 20:29:36 -0600 | [diff] [blame] | 1457 | /* see if there are any products at all */ |
| 1458 | sz = SQUISH_GUID_SIZE; |
| 1459 | r = RegEnumValueW(hkeyComp, 0, szValName, &sz, NULL, NULL, NULL, NULL); |
| 1460 | if (r != ERROR_SUCCESS) |
| 1461 | { |
| 1462 | RegCloseKey(hkeyComp); |
James Hawkins | 4295ce4 | 2007-12-16 20:30:14 -0600 | [diff] [blame] | 1463 | |
| 1464 | if (index != 0) |
| 1465 | return ERROR_INVALID_PARAMETER; |
| 1466 | |
James Hawkins | 88d51ad | 2007-12-16 20:29:36 -0600 | [diff] [blame] | 1467 | return ERROR_UNKNOWN_COMPONENT; |
| 1468 | } |
| 1469 | |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1470 | sz = SQUISH_GUID_SIZE; |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1471 | r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL); |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1472 | if( r == ERROR_SUCCESS ) |
| 1473 | unsquash_guid(szValName, szProduct); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1474 | |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1475 | RegCloseKey(hkeyComp); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1476 | |
| 1477 | return r; |
| 1478 | } |
| 1479 | |
Francois Gouget | d7119f2 | 2008-11-26 17:15:59 +0100 | [diff] [blame] | 1480 | static UINT MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex, |
Francois Gouget | 5771700 | 2007-08-09 10:41:41 +0200 | [diff] [blame] | 1481 | awstring *lpQualBuf, LPDWORD pcchQual, |
| 1482 | awstring *lpAppBuf, LPDWORD pcchAppBuf ) |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1483 | { |
Mike McCormack | 77da201 | 2005-11-21 11:59:54 +0000 | [diff] [blame] | 1484 | DWORD name_sz, val_sz, name_max, val_max, type, ofs; |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1485 | LPWSTR name = NULL, val = NULL; |
| 1486 | UINT r, r2; |
| 1487 | HKEY key; |
| 1488 | |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1489 | TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex, |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1490 | lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf); |
| 1491 | |
| 1492 | if (!szComponent) |
| 1493 | return ERROR_INVALID_PARAMETER; |
| 1494 | |
| 1495 | r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE ); |
| 1496 | if (r != ERROR_SUCCESS) |
| 1497 | return ERROR_UNKNOWN_COMPONENT; |
| 1498 | |
| 1499 | /* figure out how big the name is we want to return */ |
Mike McCormack | 77da201 | 2005-11-21 11:59:54 +0000 | [diff] [blame] | 1500 | name_max = 0x10; |
| 1501 | r = ERROR_OUTOFMEMORY; |
| 1502 | name = msi_alloc( name_max * sizeof(WCHAR) ); |
| 1503 | if (!name) |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1504 | goto end; |
| 1505 | |
Mike McCormack | 77da201 | 2005-11-21 11:59:54 +0000 | [diff] [blame] | 1506 | val_max = 0x10; |
| 1507 | r = ERROR_OUTOFMEMORY; |
| 1508 | val = msi_alloc( val_max ); |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1509 | if (!val) |
| 1510 | goto end; |
| 1511 | |
Mike McCormack | 77da201 | 2005-11-21 11:59:54 +0000 | [diff] [blame] | 1512 | /* loop until we allocate enough memory */ |
| 1513 | while (1) |
| 1514 | { |
| 1515 | name_sz = name_max; |
| 1516 | val_sz = val_max; |
| 1517 | r = RegEnumValueW( key, iIndex, name, &name_sz, |
| 1518 | NULL, &type, (LPBYTE)val, &val_sz ); |
| 1519 | if (r == ERROR_SUCCESS) |
| 1520 | break; |
| 1521 | if (r != ERROR_MORE_DATA) |
| 1522 | goto end; |
| 1523 | |
| 1524 | if (type != REG_MULTI_SZ) |
| 1525 | { |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1526 | ERR("component data has wrong type (%d)\n", type); |
Mike McCormack | 77da201 | 2005-11-21 11:59:54 +0000 | [diff] [blame] | 1527 | goto end; |
| 1528 | } |
| 1529 | |
| 1530 | r = ERROR_OUTOFMEMORY; |
| 1531 | if ((name_sz+1) >= name_max) |
| 1532 | { |
| 1533 | name_max *= 2; |
| 1534 | msi_free( name ); |
| 1535 | name = msi_alloc( name_max * sizeof (WCHAR) ); |
| 1536 | if (!name) |
| 1537 | goto end; |
| 1538 | continue; |
| 1539 | } |
| 1540 | if (val_sz > val_max) |
| 1541 | { |
| 1542 | val_max = val_sz + sizeof (WCHAR); |
Mike McCormack | 525ceb7 | 2006-07-27 23:17:57 +0900 | [diff] [blame] | 1543 | msi_free( val ); |
Mike McCormack | 77da201 | 2005-11-21 11:59:54 +0000 | [diff] [blame] | 1544 | val = msi_alloc( val_max * sizeof (WCHAR) ); |
| 1545 | if (!val) |
| 1546 | goto end; |
| 1547 | continue; |
| 1548 | } |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1549 | ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz ); |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1550 | goto end; |
Mike McCormack | 77da201 | 2005-11-21 11:59:54 +0000 | [diff] [blame] | 1551 | } |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1552 | |
| 1553 | ofs = 0; |
| 1554 | r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs ); |
| 1555 | if (r != ERROR_SUCCESS) |
| 1556 | goto end; |
| 1557 | |
| 1558 | TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs)); |
| 1559 | |
| 1560 | r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual ); |
| 1561 | r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf ); |
| 1562 | |
| 1563 | if (r2 != ERROR_SUCCESS) |
| 1564 | r = r2; |
| 1565 | |
| 1566 | end: |
| 1567 | msi_free(val); |
| 1568 | msi_free(name); |
| 1569 | RegCloseKey(key); |
| 1570 | |
| 1571 | return r; |
| 1572 | } |
| 1573 | |
Francois Gouget | 63b596d | 2005-05-06 14:33:02 +0000 | [diff] [blame] | 1574 | /************************************************************************* |
| 1575 | * MsiEnumComponentQualifiersA [MSI.@] |
Francois Gouget | 63b596d | 2005-05-06 14:33:02 +0000 | [diff] [blame] | 1576 | */ |
Mike McCormack | d78dce7 | 2005-11-15 16:55:04 +0000 | [diff] [blame] | 1577 | UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex, |
Francois Gouget | 5771700 | 2007-08-09 10:41:41 +0200 | [diff] [blame] | 1578 | LPSTR lpQualifierBuf, LPDWORD pcchQualifierBuf, |
| 1579 | LPSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf ) |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1580 | { |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1581 | awstring qual, appdata; |
| 1582 | LPWSTR comp; |
| 1583 | UINT r; |
Aric Stewart | 2b8bf59 | 2005-04-28 18:28:11 +0000 | [diff] [blame] | 1584 | |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1585 | TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex, |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1586 | lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf, |
| 1587 | pcchApplicationDataBuf); |
Aric Stewart | 2b8bf59 | 2005-04-28 18:28:11 +0000 | [diff] [blame] | 1588 | |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1589 | comp = strdupAtoW( szComponent ); |
| 1590 | if (szComponent && !comp) |
| 1591 | return ERROR_OUTOFMEMORY; |
Aric Stewart | 2b8bf59 | 2005-04-28 18:28:11 +0000 | [diff] [blame] | 1592 | |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1593 | qual.unicode = FALSE; |
| 1594 | qual.str.a = lpQualifierBuf; |
Aric Stewart | 2b8bf59 | 2005-04-28 18:28:11 +0000 | [diff] [blame] | 1595 | |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1596 | appdata.unicode = FALSE; |
| 1597 | appdata.str.a = lpApplicationDataBuf; |
Aric Stewart | 2b8bf59 | 2005-04-28 18:28:11 +0000 | [diff] [blame] | 1598 | |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1599 | r = MSI_EnumComponentQualifiers( comp, iIndex, |
| 1600 | &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf ); |
| 1601 | msi_free( comp ); |
| 1602 | return r; |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
Francois Gouget | 63b596d | 2005-05-06 14:33:02 +0000 | [diff] [blame] | 1605 | /************************************************************************* |
| 1606 | * MsiEnumComponentQualifiersW [MSI.@] |
Francois Gouget | 63b596d | 2005-05-06 14:33:02 +0000 | [diff] [blame] | 1607 | */ |
Mike McCormack | d78dce7 | 2005-11-15 16:55:04 +0000 | [diff] [blame] | 1608 | UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex, |
Francois Gouget | 5771700 | 2007-08-09 10:41:41 +0200 | [diff] [blame] | 1609 | LPWSTR lpQualifierBuf, LPDWORD pcchQualifierBuf, |
| 1610 | LPWSTR lpApplicationDataBuf, LPDWORD pcchApplicationDataBuf ) |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1611 | { |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1612 | awstring qual, appdata; |
Aric Stewart | 2b8bf59 | 2005-04-28 18:28:11 +0000 | [diff] [blame] | 1613 | |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1614 | TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex, |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1615 | lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf, |
| 1616 | pcchApplicationDataBuf); |
Aric Stewart | 2b8bf59 | 2005-04-28 18:28:11 +0000 | [diff] [blame] | 1617 | |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1618 | qual.unicode = TRUE; |
| 1619 | qual.str.w = lpQualifierBuf; |
Aric Stewart | 2b8bf59 | 2005-04-28 18:28:11 +0000 | [diff] [blame] | 1620 | |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1621 | appdata.unicode = TRUE; |
| 1622 | appdata.str.w = lpApplicationDataBuf; |
Aric Stewart | 2b8bf59 | 2005-04-28 18:28:11 +0000 | [diff] [blame] | 1623 | |
Mike McCormack | 26a6d59 | 2005-11-15 18:12:21 +0000 | [diff] [blame] | 1624 | return MSI_EnumComponentQualifiers( szComponent, iIndex, |
| 1625 | &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf ); |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
Francois Gouget | 63b596d | 2005-05-06 14:33:02 +0000 | [diff] [blame] | 1628 | /************************************************************************* |
| 1629 | * MsiEnumRelatedProductsW [MSI.@] |
| 1630 | * |
| 1631 | */ |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1632 | UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved, |
| 1633 | DWORD iProductIndex, LPWSTR lpProductBuf) |
| 1634 | { |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1635 | UINT r; |
Juan Lang | 3d4ce5c | 2005-03-10 17:24:05 +0000 | [diff] [blame] | 1636 | HKEY hkey; |
Misha Koshelev | 536b499 | 2007-05-14 12:15:46 -0500 | [diff] [blame] | 1637 | DWORD dwSize = SQUISH_GUID_SIZE; |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1638 | WCHAR szKeyName[SQUISH_GUID_SIZE]; |
Juan Lang | 3d4ce5c | 2005-03-10 17:24:05 +0000 | [diff] [blame] | 1639 | |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1640 | TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved, |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1641 | iProductIndex, lpProductBuf); |
Juan Lang | 3d4ce5c | 2005-03-10 17:24:05 +0000 | [diff] [blame] | 1642 | |
| 1643 | if (NULL == szUpgradeCode) |
| 1644 | return ERROR_INVALID_PARAMETER; |
| 1645 | if (NULL == lpProductBuf) |
| 1646 | return ERROR_INVALID_PARAMETER; |
Juan Lang | 3d4ce5c | 2005-03-10 17:24:05 +0000 | [diff] [blame] | 1647 | |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1648 | r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE); |
| 1649 | if (r != ERROR_SUCCESS) |
| 1650 | return ERROR_NO_MORE_ITEMS; |
Juan Lang | 3d4ce5c | 2005-03-10 17:24:05 +0000 | [diff] [blame] | 1651 | |
Misha Koshelev | 536b499 | 2007-05-14 12:15:46 -0500 | [diff] [blame] | 1652 | r = RegEnumValueW(hkey, iProductIndex, szKeyName, &dwSize, NULL, NULL, NULL, NULL); |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1653 | if( r == ERROR_SUCCESS ) |
| 1654 | unsquash_guid(szKeyName, lpProductBuf); |
Juan Lang | 3d4ce5c | 2005-03-10 17:24:05 +0000 | [diff] [blame] | 1655 | RegCloseKey(hkey); |
| 1656 | |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1657 | return r; |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
Francois Gouget | 63b596d | 2005-05-06 14:33:02 +0000 | [diff] [blame] | 1660 | /************************************************************************* |
| 1661 | * MsiEnumRelatedProductsA [MSI.@] |
| 1662 | * |
| 1663 | */ |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1664 | UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved, |
| 1665 | DWORD iProductIndex, LPSTR lpProductBuf) |
| 1666 | { |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1667 | LPWSTR szwUpgradeCode = NULL; |
| 1668 | WCHAR productW[GUID_SIZE]; |
| 1669 | UINT r; |
Juan Lang | 3d4ce5c | 2005-03-10 17:24:05 +0000 | [diff] [blame] | 1670 | |
Mike McCormack | f1d4646 | 2006-10-05 13:41:22 +0900 | [diff] [blame] | 1671 | TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved, |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1672 | iProductIndex, lpProductBuf); |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1673 | |
| 1674 | if (szUpgradeCode) |
Juan Lang | 3d4ce5c | 2005-03-10 17:24:05 +0000 | [diff] [blame] | 1675 | { |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1676 | szwUpgradeCode = strdupAtoW( szUpgradeCode ); |
| 1677 | if( !szwUpgradeCode ) |
| 1678 | return ERROR_OUTOFMEMORY; |
Juan Lang | 3d4ce5c | 2005-03-10 17:24:05 +0000 | [diff] [blame] | 1679 | } |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1680 | |
| 1681 | r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved, |
| 1682 | iProductIndex, productW ); |
| 1683 | if (r == ERROR_SUCCESS) |
| 1684 | { |
| 1685 | WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE, |
| 1686 | lpProductBuf, GUID_SIZE, NULL, NULL ); |
| 1687 | } |
Mike McCormack | 8dc28d5 | 2005-09-20 11:57:19 +0000 | [diff] [blame] | 1688 | msi_free( szwUpgradeCode); |
Mike McCormack | c3ab871 | 2005-03-24 15:09:18 +0000 | [diff] [blame] | 1689 | return r; |
Mike McCormack | 0b1b703 | 2005-02-16 17:52:53 +0000 | [diff] [blame] | 1690 | } |
Mike McCormack | dc4d5b0 | 2006-07-24 15:24:53 +0900 | [diff] [blame] | 1691 | |
| 1692 | /*********************************************************************** |
James Hawkins | 8782fdb | 2008-08-03 23:53:45 -0500 | [diff] [blame] | 1693 | * MsiEnumPatchesExA [MSI.@] |
| 1694 | */ |
| 1695 | UINT WINAPI MsiEnumPatchesExA(LPCSTR szProductCode, LPCSTR szUserSid, |
| 1696 | DWORD dwContext, DWORD dwFilter, DWORD dwIndex, LPSTR szPatchCode, |
| 1697 | LPSTR szTargetProductCode, MSIINSTALLCONTEXT *pdwTargetProductContext, |
James Hawkins | 7df94f3 | 2008-12-08 03:13:13 -0600 | [diff] [blame] | 1698 | LPSTR szTargetUserSid, LPDWORD pcchTargetUserSid) |
James Hawkins | 8782fdb | 2008-08-03 23:53:45 -0500 | [diff] [blame] | 1699 | { |
James Hawkins | a32fcfa | 2008-12-08 03:14:00 -0600 | [diff] [blame] | 1700 | LPWSTR prodcode = NULL; |
| 1701 | LPWSTR usersid = NULL; |
| 1702 | LPWSTR targsid = NULL; |
| 1703 | WCHAR patch[GUID_SIZE]; |
| 1704 | WCHAR targprod[GUID_SIZE]; |
| 1705 | DWORD len; |
| 1706 | UINT r; |
| 1707 | |
| 1708 | TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n", |
James Hawkins | 8782fdb | 2008-08-03 23:53:45 -0500 | [diff] [blame] | 1709 | debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext, dwFilter, |
| 1710 | dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext, |
| 1711 | szTargetUserSid, pcchTargetUserSid); |
James Hawkins | a32fcfa | 2008-12-08 03:14:00 -0600 | [diff] [blame] | 1712 | |
| 1713 | if (szTargetUserSid && !pcchTargetUserSid) |
| 1714 | return ERROR_INVALID_PARAMETER; |
| 1715 | |
| 1716 | if (szProductCode) prodcode = strdupAtoW(szProductCode); |
| 1717 | if (szUserSid) usersid = strdupAtoW(szUserSid); |
| 1718 | |
| 1719 | r = MsiEnumPatchesExW(prodcode, usersid, dwContext, dwFilter, dwIndex, |
| 1720 | patch, targprod, pdwTargetProductContext, |
| 1721 | NULL, &len); |
| 1722 | if (r != ERROR_SUCCESS) |
| 1723 | goto done; |
| 1724 | |
| 1725 | WideCharToMultiByte(CP_ACP, 0, patch, -1, szPatchCode, |
| 1726 | GUID_SIZE, NULL, NULL); |
| 1727 | WideCharToMultiByte(CP_ACP, 0, targprod, -1, szTargetProductCode, |
| 1728 | GUID_SIZE, NULL, NULL); |
| 1729 | |
| 1730 | if (!szTargetUserSid) |
| 1731 | { |
| 1732 | if (pcchTargetUserSid) |
| 1733 | *pcchTargetUserSid = len; |
| 1734 | |
| 1735 | goto done; |
| 1736 | } |
| 1737 | |
| 1738 | targsid = msi_alloc(++len * sizeof(WCHAR)); |
| 1739 | if (!targsid) |
| 1740 | { |
| 1741 | r = ERROR_OUTOFMEMORY; |
| 1742 | goto done; |
| 1743 | } |
| 1744 | |
| 1745 | r = MsiEnumPatchesExW(prodcode, usersid, dwContext, dwFilter, dwIndex, |
| 1746 | patch, targprod, pdwTargetProductContext, |
| 1747 | targsid, &len); |
| 1748 | if (r != ERROR_SUCCESS || !szTargetUserSid) |
| 1749 | goto done; |
| 1750 | |
| 1751 | WideCharToMultiByte(CP_ACP, 0, targsid, -1, szTargetUserSid, |
| 1752 | *pcchTargetUserSid, NULL, NULL); |
| 1753 | |
| 1754 | len = lstrlenW(targsid); |
| 1755 | if (*pcchTargetUserSid < len + 1) |
| 1756 | { |
| 1757 | r = ERROR_MORE_DATA; |
| 1758 | *pcchTargetUserSid = len * sizeof(WCHAR); |
| 1759 | } |
| 1760 | else |
| 1761 | *pcchTargetUserSid = len; |
| 1762 | |
| 1763 | done: |
| 1764 | msi_free(prodcode); |
| 1765 | msi_free(usersid); |
| 1766 | msi_free(targsid); |
| 1767 | |
| 1768 | return r; |
James Hawkins | 8782fdb | 2008-08-03 23:53:45 -0500 | [diff] [blame] | 1769 | } |
| 1770 | |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 1771 | static UINT msi_get_patch_state(LPCWSTR prodcode, LPCWSTR usersid, |
James Hawkins | c965d83 | 2009-03-22 14:30:16 -0700 | [diff] [blame] | 1772 | MSIINSTALLCONTEXT context, |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 1773 | LPWSTR patch, MSIPATCHSTATE *state) |
| 1774 | { |
| 1775 | DWORD type, val, size; |
| 1776 | HKEY prod, hkey = 0; |
| 1777 | HKEY udpatch = 0; |
| 1778 | LONG res; |
| 1779 | UINT r = ERROR_NO_MORE_ITEMS; |
| 1780 | |
James Hawkins | ff87f35 | 2008-12-09 00:20:29 -0600 | [diff] [blame] | 1781 | *state = MSIPATCHSTATE_INVALID; |
| 1782 | |
James Hawkins | c965d83 | 2009-03-22 14:30:16 -0700 | [diff] [blame] | 1783 | r = MSIREG_OpenUserDataProductKey(prodcode, context, |
| 1784 | usersid, &prod, FALSE); |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 1785 | if (r != ERROR_SUCCESS) |
| 1786 | return ERROR_NO_MORE_ITEMS; |
| 1787 | |
| 1788 | res = RegOpenKeyExW(prod, szPatches, 0, KEY_READ, &hkey); |
| 1789 | if (res != ERROR_SUCCESS) |
| 1790 | goto done; |
| 1791 | |
| 1792 | res = RegOpenKeyExW(hkey, patch, 0, KEY_READ, &udpatch); |
| 1793 | if (res != ERROR_SUCCESS) |
| 1794 | goto done; |
| 1795 | |
| 1796 | size = sizeof(DWORD); |
| 1797 | res = RegGetValueW(udpatch, NULL, szState, RRF_RT_DWORD, &type, &val, &size); |
| 1798 | if (res != ERROR_SUCCESS || |
| 1799 | val < MSIPATCHSTATE_APPLIED || val > MSIPATCHSTATE_REGISTERED) |
| 1800 | { |
| 1801 | r = ERROR_BAD_CONFIGURATION; |
| 1802 | goto done; |
| 1803 | } |
| 1804 | |
| 1805 | *state = val; |
| 1806 | r = ERROR_SUCCESS; |
| 1807 | |
| 1808 | done: |
| 1809 | RegCloseKey(udpatch); |
| 1810 | RegCloseKey(hkey); |
| 1811 | RegCloseKey(prod); |
| 1812 | |
| 1813 | return r; |
| 1814 | } |
| 1815 | |
| 1816 | static UINT msi_check_product_patches(LPCWSTR prodcode, LPCWSTR usersid, |
| 1817 | MSIINSTALLCONTEXT context, DWORD filter, DWORD index, DWORD *idx, |
| 1818 | LPWSTR patch, LPWSTR targetprod, MSIINSTALLCONTEXT *targetctx, |
James Hawkins | e07ed1a | 2008-12-09 00:21:28 -0600 | [diff] [blame] | 1819 | LPWSTR targetsid, DWORD *sidsize, LPWSTR *transforms) |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 1820 | { |
Hans Leidekker | d02dbf4 | 2009-06-04 10:12:56 +0200 | [diff] [blame] | 1821 | MSIPATCHSTATE state = MSIPATCHSTATE_INVALID; |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 1822 | LPWSTR ptr, patches = NULL; |
| 1823 | HKEY prod, patchkey = 0; |
| 1824 | HKEY localprod = 0, localpatch = 0; |
| 1825 | DWORD type, size; |
| 1826 | LONG res; |
| 1827 | UINT temp, r = ERROR_NO_MORE_ITEMS; |
| 1828 | |
James Hawkins | c965d83 | 2009-03-22 14:30:16 -0700 | [diff] [blame] | 1829 | if (MSIREG_OpenProductKey(prodcode, usersid, context, |
| 1830 | &prod, FALSE) != ERROR_SUCCESS) |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 1831 | return ERROR_NO_MORE_ITEMS; |
| 1832 | |
| 1833 | size = 0; |
| 1834 | res = RegGetValueW(prod, szPatches, szPatches, RRF_RT_ANY, &type, NULL, |
| 1835 | &size); |
| 1836 | if (res != ERROR_SUCCESS) |
| 1837 | goto done; |
| 1838 | |
| 1839 | if (type != REG_MULTI_SZ) |
| 1840 | { |
| 1841 | r = ERROR_BAD_CONFIGURATION; |
| 1842 | goto done; |
| 1843 | } |
| 1844 | |
| 1845 | patches = msi_alloc(size); |
| 1846 | if (!patches) |
| 1847 | { |
| 1848 | r = ERROR_OUTOFMEMORY; |
| 1849 | goto done; |
| 1850 | } |
| 1851 | |
| 1852 | res = RegGetValueW(prod, szPatches, szPatches, RRF_RT_ANY, &type, |
| 1853 | patches, &size); |
| 1854 | if (res != ERROR_SUCCESS) |
| 1855 | goto done; |
| 1856 | |
| 1857 | ptr = patches; |
| 1858 | for (ptr = patches; *ptr && r == ERROR_NO_MORE_ITEMS; ptr += lstrlenW(ptr)) |
| 1859 | { |
| 1860 | if (!unsquash_guid(ptr, patch)) |
| 1861 | { |
| 1862 | r = ERROR_BAD_CONFIGURATION; |
| 1863 | goto done; |
| 1864 | } |
| 1865 | |
| 1866 | size = 0; |
| 1867 | res = RegGetValueW(prod, szPatches, ptr, RRF_RT_REG_SZ, |
| 1868 | &type, NULL, &size); |
| 1869 | if (res != ERROR_SUCCESS) |
| 1870 | continue; |
| 1871 | |
James Hawkins | e07ed1a | 2008-12-09 00:21:28 -0600 | [diff] [blame] | 1872 | if (transforms) |
| 1873 | { |
| 1874 | *transforms = msi_alloc(size); |
| 1875 | if (!*transforms) |
| 1876 | { |
| 1877 | r = ERROR_OUTOFMEMORY; |
| 1878 | goto done; |
| 1879 | } |
| 1880 | |
| 1881 | res = RegGetValueW(prod, szPatches, ptr, RRF_RT_REG_SZ, |
| 1882 | &type, *transforms, &size); |
| 1883 | if (res != ERROR_SUCCESS) |
| 1884 | continue; |
| 1885 | } |
| 1886 | |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 1887 | if (context == MSIINSTALLCONTEXT_USERMANAGED) |
| 1888 | { |
| 1889 | if (!(filter & MSIPATCHSTATE_APPLIED)) |
| 1890 | { |
James Hawkins | c965d83 | 2009-03-22 14:30:16 -0700 | [diff] [blame] | 1891 | temp = msi_get_patch_state(prodcode, usersid, context, |
| 1892 | ptr, &state); |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 1893 | if (temp == ERROR_BAD_CONFIGURATION) |
| 1894 | { |
| 1895 | r = ERROR_BAD_CONFIGURATION; |
| 1896 | goto done; |
| 1897 | } |
| 1898 | |
| 1899 | if (temp != ERROR_SUCCESS || !(filter & state)) |
| 1900 | continue; |
| 1901 | } |
| 1902 | } |
| 1903 | else if (context == MSIINSTALLCONTEXT_USERUNMANAGED) |
| 1904 | { |
| 1905 | if (!(filter & MSIPATCHSTATE_APPLIED)) |
| 1906 | { |
James Hawkins | c965d83 | 2009-03-22 14:30:16 -0700 | [diff] [blame] | 1907 | temp = msi_get_patch_state(prodcode, usersid, context, |
| 1908 | ptr, &state); |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 1909 | if (temp == ERROR_BAD_CONFIGURATION) |
| 1910 | { |
| 1911 | r = ERROR_BAD_CONFIGURATION; |
| 1912 | goto done; |
| 1913 | } |
| 1914 | |
| 1915 | if (temp != ERROR_SUCCESS || !(filter & state)) |
| 1916 | continue; |
| 1917 | } |
| 1918 | else |
| 1919 | { |
James Hawkins | 880b919 | 2008-12-14 21:07:09 -0600 | [diff] [blame] | 1920 | temp = MSIREG_OpenUserDataPatchKey(patch, context, |
| 1921 | &patchkey, FALSE); |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 1922 | RegCloseKey(patchkey); |
| 1923 | if (temp != ERROR_SUCCESS) |
| 1924 | continue; |
| 1925 | } |
| 1926 | } |
| 1927 | else if (context == MSIINSTALLCONTEXT_MACHINE) |
| 1928 | { |
| 1929 | usersid = szEmpty; |
| 1930 | |
James Hawkins | 4a9f699 | 2008-12-14 21:07:06 -0600 | [diff] [blame] | 1931 | if (MSIREG_OpenUserDataProductKey(prodcode, context, NULL, &localprod, FALSE) == ERROR_SUCCESS && |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 1932 | RegOpenKeyExW(localprod, szPatches, 0, KEY_READ, &localpatch) == ERROR_SUCCESS && |
| 1933 | RegOpenKeyExW(localpatch, ptr, 0, KEY_READ, &patchkey) == ERROR_SUCCESS) |
| 1934 | { |
| 1935 | res = RegGetValueW(patchkey, NULL, szState, RRF_RT_REG_DWORD, |
| 1936 | &type, &state, &size); |
| 1937 | |
| 1938 | if (!(filter & state)) |
| 1939 | res = ERROR_NO_MORE_ITEMS; |
| 1940 | |
| 1941 | RegCloseKey(patchkey); |
| 1942 | } |
| 1943 | |
| 1944 | RegCloseKey(localpatch); |
| 1945 | RegCloseKey(localprod); |
| 1946 | |
| 1947 | if (res != ERROR_SUCCESS) |
| 1948 | continue; |
| 1949 | } |
| 1950 | |
| 1951 | if (*idx < index) |
| 1952 | { |
| 1953 | (*idx)++; |
| 1954 | continue; |
| 1955 | } |
| 1956 | |
| 1957 | r = ERROR_SUCCESS; |
James Hawkins | e07ed1a | 2008-12-09 00:21:28 -0600 | [diff] [blame] | 1958 | if (targetprod) |
| 1959 | lstrcpyW(targetprod, prodcode); |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 1960 | |
| 1961 | if (targetctx) |
| 1962 | *targetctx = context; |
| 1963 | |
| 1964 | if (targetsid) |
| 1965 | { |
| 1966 | lstrcpynW(targetsid, usersid, *sidsize); |
| 1967 | if (lstrlenW(usersid) >= *sidsize) |
| 1968 | r = ERROR_MORE_DATA; |
| 1969 | } |
| 1970 | |
| 1971 | if (sidsize) |
| 1972 | { |
| 1973 | *sidsize = lstrlenW(usersid); |
| 1974 | if (!targetsid) |
| 1975 | *sidsize *= sizeof(WCHAR); |
| 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | done: |
| 1980 | RegCloseKey(prod); |
| 1981 | msi_free(patches); |
| 1982 | |
| 1983 | return r; |
| 1984 | } |
| 1985 | |
James Hawkins | e07ed1a | 2008-12-09 00:21:28 -0600 | [diff] [blame] | 1986 | static UINT msi_enum_patches(LPCWSTR szProductCode, LPCWSTR szUserSid, |
| 1987 | DWORD dwContext, DWORD dwFilter, DWORD dwIndex, DWORD *idx, |
| 1988 | LPWSTR szPatchCode, LPWSTR szTargetProductCode, |
| 1989 | MSIINSTALLCONTEXT *pdwTargetProductContext, LPWSTR szTargetUserSid, |
| 1990 | LPDWORD pcchTargetUserSid, LPWSTR *szTransforms) |
| 1991 | { |
James Hawkins | f7c615b | 2009-03-22 14:30:03 -0700 | [diff] [blame] | 1992 | LPWSTR usersid = NULL; |
Alexandre Julliard | 8ca2aa3 | 2009-01-30 13:44:06 +0100 | [diff] [blame] | 1993 | UINT r = ERROR_INVALID_PARAMETER; |
James Hawkins | e07ed1a | 2008-12-09 00:21:28 -0600 | [diff] [blame] | 1994 | |
James Hawkins | f7c615b | 2009-03-22 14:30:03 -0700 | [diff] [blame] | 1995 | if (!szUserSid) |
| 1996 | { |
| 1997 | get_user_sid(&usersid); |
| 1998 | szUserSid = usersid; |
| 1999 | } |
| 2000 | |
James Hawkins | e07ed1a | 2008-12-09 00:21:28 -0600 | [diff] [blame] | 2001 | if (dwContext & MSIINSTALLCONTEXT_USERMANAGED) |
| 2002 | { |
| 2003 | r = msi_check_product_patches(szProductCode, szUserSid, |
| 2004 | MSIINSTALLCONTEXT_USERMANAGED, dwFilter, |
| 2005 | dwIndex, idx, szPatchCode, |
| 2006 | szTargetProductCode, |
| 2007 | pdwTargetProductContext, szTargetUserSid, |
| 2008 | pcchTargetUserSid, szTransforms); |
| 2009 | if (r != ERROR_NO_MORE_ITEMS) |
| 2010 | goto done; |
| 2011 | } |
| 2012 | |
| 2013 | if (dwContext & MSIINSTALLCONTEXT_USERUNMANAGED) |
| 2014 | { |
| 2015 | r = msi_check_product_patches(szProductCode, szUserSid, |
| 2016 | MSIINSTALLCONTEXT_USERUNMANAGED, dwFilter, |
| 2017 | dwIndex, idx, szPatchCode, |
| 2018 | szTargetProductCode, |
| 2019 | pdwTargetProductContext, szTargetUserSid, |
| 2020 | pcchTargetUserSid, szTransforms); |
| 2021 | if (r != ERROR_NO_MORE_ITEMS) |
| 2022 | goto done; |
| 2023 | } |
| 2024 | |
| 2025 | if (dwContext & MSIINSTALLCONTEXT_MACHINE) |
| 2026 | { |
| 2027 | r = msi_check_product_patches(szProductCode, szUserSid, |
| 2028 | MSIINSTALLCONTEXT_MACHINE, dwFilter, |
| 2029 | dwIndex, idx, szPatchCode, |
| 2030 | szTargetProductCode, |
| 2031 | pdwTargetProductContext, szTargetUserSid, |
| 2032 | pcchTargetUserSid, szTransforms); |
| 2033 | if (r != ERROR_NO_MORE_ITEMS) |
| 2034 | goto done; |
| 2035 | } |
| 2036 | |
| 2037 | done: |
James Hawkins | f7c615b | 2009-03-22 14:30:03 -0700 | [diff] [blame] | 2038 | LocalFree(usersid); |
James Hawkins | e07ed1a | 2008-12-09 00:21:28 -0600 | [diff] [blame] | 2039 | return r; |
| 2040 | } |
| 2041 | |
James Hawkins | 8782fdb | 2008-08-03 23:53:45 -0500 | [diff] [blame] | 2042 | /*********************************************************************** |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 2043 | * MsiEnumPatchesExW [MSI.@] |
James Hawkins | 8782fdb | 2008-08-03 23:53:45 -0500 | [diff] [blame] | 2044 | */ |
| 2045 | UINT WINAPI MsiEnumPatchesExW(LPCWSTR szProductCode, LPCWSTR szUserSid, |
| 2046 | DWORD dwContext, DWORD dwFilter, DWORD dwIndex, LPWSTR szPatchCode, |
| 2047 | LPWSTR szTargetProductCode, MSIINSTALLCONTEXT *pdwTargetProductContext, |
James Hawkins | 7df94f3 | 2008-12-08 03:13:13 -0600 | [diff] [blame] | 2048 | LPWSTR szTargetUserSid, LPDWORD pcchTargetUserSid) |
James Hawkins | 8782fdb | 2008-08-03 23:53:45 -0500 | [diff] [blame] | 2049 | { |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 2050 | WCHAR squished_pc[GUID_SIZE]; |
| 2051 | DWORD idx = 0; |
| 2052 | UINT r; |
| 2053 | |
| 2054 | static int last_index = 0; |
| 2055 | |
| 2056 | TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n", |
James Hawkins | 8782fdb | 2008-08-03 23:53:45 -0500 | [diff] [blame] | 2057 | debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext, dwFilter, |
| 2058 | dwIndex, szPatchCode, szTargetProductCode, pdwTargetProductContext, |
| 2059 | szTargetUserSid, pcchTargetUserSid); |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 2060 | |
| 2061 | if (!szProductCode || !squash_guid(szProductCode, squished_pc)) |
| 2062 | return ERROR_INVALID_PARAMETER; |
| 2063 | |
James Hawkins | 930b429 | 2008-12-09 00:20:56 -0600 | [diff] [blame] | 2064 | if (!lstrcmpW(szUserSid, szLocalSid)) |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 2065 | return ERROR_INVALID_PARAMETER; |
| 2066 | |
| 2067 | if (dwContext & MSIINSTALLCONTEXT_MACHINE && szUserSid) |
| 2068 | return ERROR_INVALID_PARAMETER; |
| 2069 | |
| 2070 | if (dwContext <= MSIINSTALLCONTEXT_NONE || |
| 2071 | dwContext > MSIINSTALLCONTEXT_ALL) |
| 2072 | return ERROR_INVALID_PARAMETER; |
| 2073 | |
| 2074 | if (dwFilter <= MSIPATCHSTATE_INVALID || dwFilter > MSIPATCHSTATE_ALL) |
| 2075 | return ERROR_INVALID_PARAMETER; |
| 2076 | |
| 2077 | if (dwIndex && dwIndex - last_index != 1) |
| 2078 | return ERROR_INVALID_PARAMETER; |
| 2079 | |
| 2080 | if (dwIndex == 0) |
| 2081 | last_index = 0; |
| 2082 | |
James Hawkins | e07ed1a | 2008-12-09 00:21:28 -0600 | [diff] [blame] | 2083 | r = msi_enum_patches(szProductCode, szUserSid, dwContext, dwFilter, |
| 2084 | dwIndex, &idx, szPatchCode, szTargetProductCode, |
| 2085 | pdwTargetProductContext, szTargetUserSid, |
| 2086 | pcchTargetUserSid, NULL); |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 2087 | |
James Hawkins | 87fef9f | 2008-12-08 03:14:21 -0600 | [diff] [blame] | 2088 | if (r == ERROR_SUCCESS) |
| 2089 | last_index = dwIndex; |
| 2090 | |
| 2091 | return r; |
James Hawkins | 8782fdb | 2008-08-03 23:53:45 -0500 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | /*********************************************************************** |
Mike McCormack | dc4d5b0 | 2006-07-24 15:24:53 +0900 | [diff] [blame] | 2095 | * MsiEnumPatchesA [MSI.@] |
| 2096 | */ |
James Hawkins | c46f210 | 2008-12-09 00:21:23 -0600 | [diff] [blame] | 2097 | UINT WINAPI MsiEnumPatchesA(LPCSTR szProduct, DWORD iPatchIndex, |
Francois Gouget | 5771700 | 2007-08-09 10:41:41 +0200 | [diff] [blame] | 2098 | LPSTR lpPatchBuf, LPSTR lpTransformsBuf, LPDWORD pcchTransformsBuf) |
Mike McCormack | dc4d5b0 | 2006-07-24 15:24:53 +0900 | [diff] [blame] | 2099 | { |
Alexandre Julliard | b4d81f8 | 2009-02-25 15:04:31 +0100 | [diff] [blame] | 2100 | LPWSTR product, transforms; |
James Hawkins | c46f210 | 2008-12-09 00:21:23 -0600 | [diff] [blame] | 2101 | WCHAR patch[GUID_SIZE]; |
| 2102 | DWORD len; |
| 2103 | UINT r; |
| 2104 | |
| 2105 | TRACE("(%s %d %p %p %p)\n", debugstr_a(szProduct), iPatchIndex, |
| 2106 | lpPatchBuf, lpTransformsBuf, pcchTransformsBuf); |
| 2107 | |
| 2108 | if (!szProduct || !lpPatchBuf || !lpTransformsBuf || !pcchTransformsBuf) |
| 2109 | return ERROR_INVALID_PARAMETER; |
| 2110 | |
| 2111 | product = strdupAtoW(szProduct); |
| 2112 | if (!product) |
| 2113 | return ERROR_OUTOFMEMORY; |
| 2114 | |
Alexandre Julliard | b4d81f8 | 2009-02-25 15:04:31 +0100 | [diff] [blame] | 2115 | len = *pcchTransformsBuf; |
| 2116 | transforms = msi_alloc( len * sizeof(WCHAR) ); |
James Hawkins | c46f210 | 2008-12-09 00:21:23 -0600 | [diff] [blame] | 2117 | if (!transforms) |
| 2118 | { |
| 2119 | r = ERROR_OUTOFMEMORY; |
| 2120 | goto done; |
| 2121 | } |
| 2122 | |
| 2123 | r = MsiEnumPatchesW(product, iPatchIndex, patch, transforms, &len); |
Alexandre Julliard | b4d81f8 | 2009-02-25 15:04:31 +0100 | [diff] [blame] | 2124 | if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA) |
James Hawkins | c46f210 | 2008-12-09 00:21:23 -0600 | [diff] [blame] | 2125 | goto done; |
| 2126 | |
| 2127 | WideCharToMultiByte(CP_ACP, 0, patch, -1, lpPatchBuf, |
| 2128 | GUID_SIZE, NULL, NULL); |
| 2129 | |
Alexandre Julliard | b4d81f8 | 2009-02-25 15:04:31 +0100 | [diff] [blame] | 2130 | if (!WideCharToMultiByte(CP_ACP, 0, transforms, -1, lpTransformsBuf, |
| 2131 | *pcchTransformsBuf, NULL, NULL)) |
James Hawkins | c46f210 | 2008-12-09 00:21:23 -0600 | [diff] [blame] | 2132 | r = ERROR_MORE_DATA; |
Alexandre Julliard | b4d81f8 | 2009-02-25 15:04:31 +0100 | [diff] [blame] | 2133 | |
| 2134 | if (r == ERROR_MORE_DATA) |
| 2135 | { |
James Hawkins | c46f210 | 2008-12-09 00:21:23 -0600 | [diff] [blame] | 2136 | lpTransformsBuf[*pcchTransformsBuf - 1] = '\0'; |
Alexandre Julliard | b4d81f8 | 2009-02-25 15:04:31 +0100 | [diff] [blame] | 2137 | *pcchTransformsBuf = len * 2; |
James Hawkins | c46f210 | 2008-12-09 00:21:23 -0600 | [diff] [blame] | 2138 | } |
| 2139 | else |
Alexandre Julliard | b4d81f8 | 2009-02-25 15:04:31 +0100 | [diff] [blame] | 2140 | *pcchTransformsBuf = strlen( lpTransformsBuf ); |
James Hawkins | c46f210 | 2008-12-09 00:21:23 -0600 | [diff] [blame] | 2141 | |
| 2142 | done: |
| 2143 | msi_free(transforms); |
| 2144 | msi_free(product); |
| 2145 | |
| 2146 | return r; |
Mike McCormack | dc4d5b0 | 2006-07-24 15:24:53 +0900 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | /*********************************************************************** |
| 2150 | * MsiEnumPatchesW [MSI.@] |
| 2151 | */ |
James Hawkins | e07ed1a | 2008-12-09 00:21:28 -0600 | [diff] [blame] | 2152 | UINT WINAPI MsiEnumPatchesW(LPCWSTR szProduct, DWORD iPatchIndex, |
Francois Gouget | 5771700 | 2007-08-09 10:41:41 +0200 | [diff] [blame] | 2153 | LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, LPDWORD pcchTransformsBuf) |
Mike McCormack | dc4d5b0 | 2006-07-24 15:24:53 +0900 | [diff] [blame] | 2154 | { |
James Hawkins | e07ed1a | 2008-12-09 00:21:28 -0600 | [diff] [blame] | 2155 | WCHAR squished_pc[GUID_SIZE]; |
| 2156 | LPWSTR transforms = NULL; |
| 2157 | HKEY prod; |
| 2158 | DWORD idx = 0; |
| 2159 | UINT r; |
| 2160 | |
| 2161 | TRACE("(%s %d %p %p %p)\n", debugstr_w(szProduct), iPatchIndex, |
| 2162 | lpPatchBuf, lpTransformsBuf, pcchTransformsBuf); |
| 2163 | |
| 2164 | if (!szProduct || !squash_guid(szProduct, squished_pc)) |
| 2165 | return ERROR_INVALID_PARAMETER; |
| 2166 | |
| 2167 | if (!lpPatchBuf || !lpTransformsBuf || !pcchTransformsBuf) |
| 2168 | return ERROR_INVALID_PARAMETER; |
| 2169 | |
James Hawkins | c965d83 | 2009-03-22 14:30:16 -0700 | [diff] [blame] | 2170 | if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED, |
James Hawkins | e07ed1a | 2008-12-09 00:21:28 -0600 | [diff] [blame] | 2171 | &prod, FALSE) != ERROR_SUCCESS && |
James Hawkins | c965d83 | 2009-03-22 14:30:16 -0700 | [diff] [blame] | 2172 | MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, |
James Hawkins | e07ed1a | 2008-12-09 00:21:28 -0600 | [diff] [blame] | 2173 | &prod, FALSE) != ERROR_SUCCESS && |
James Hawkins | c965d83 | 2009-03-22 14:30:16 -0700 | [diff] [blame] | 2174 | MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE, |
James Hawkins | e07ed1a | 2008-12-09 00:21:28 -0600 | [diff] [blame] | 2175 | &prod, FALSE) != ERROR_SUCCESS) |
| 2176 | return ERROR_UNKNOWN_PRODUCT; |
| 2177 | |
| 2178 | RegCloseKey(prod); |
| 2179 | |
| 2180 | r = msi_enum_patches(szProduct, NULL, MSIINSTALLCONTEXT_ALL, |
| 2181 | MSIPATCHSTATE_ALL, iPatchIndex, &idx, lpPatchBuf, |
| 2182 | NULL, NULL, NULL, NULL, &transforms); |
| 2183 | if (r != ERROR_SUCCESS) |
| 2184 | goto done; |
| 2185 | |
| 2186 | lstrcpynW(lpTransformsBuf, transforms, *pcchTransformsBuf); |
| 2187 | if (*pcchTransformsBuf <= lstrlenW(transforms)) |
| 2188 | { |
| 2189 | r = ERROR_MORE_DATA; |
Alexandre Julliard | b4d81f8 | 2009-02-25 15:04:31 +0100 | [diff] [blame] | 2190 | *pcchTransformsBuf = lstrlenW(transforms); |
James Hawkins | e07ed1a | 2008-12-09 00:21:28 -0600 | [diff] [blame] | 2191 | } |
| 2192 | else |
| 2193 | *pcchTransformsBuf = lstrlenW(transforms); |
| 2194 | |
| 2195 | done: |
| 2196 | msi_free(transforms); |
| 2197 | return r; |
Mike McCormack | dc4d5b0 | 2006-07-24 15:24:53 +0900 | [diff] [blame] | 2198 | } |
Hans Leidekker | 9eefc04 | 2007-04-25 20:49:43 +0200 | [diff] [blame] | 2199 | |
| 2200 | UINT WINAPI MsiEnumProductsExA( LPCSTR szProductCode, LPCSTR szUserSid, |
Francois Gouget | 4deb14a | 2007-08-04 03:14:53 +0200 | [diff] [blame] | 2201 | DWORD dwContext, DWORD dwIndex, CHAR szInstalledProductCode[39], |
Hans Leidekker | 9eefc04 | 2007-04-25 20:49:43 +0200 | [diff] [blame] | 2202 | MSIINSTALLCONTEXT* pdwInstalledContext, LPSTR szSid, LPDWORD pcchSid) |
| 2203 | { |
| 2204 | FIXME("%s %s %d %d %p %p %p %p\n", debugstr_a(szProductCode), debugstr_a(szUserSid), |
| 2205 | dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext, |
| 2206 | szSid, pcchSid); |
| 2207 | return ERROR_NO_MORE_ITEMS; |
| 2208 | } |
| 2209 | |
| 2210 | UINT WINAPI MsiEnumProductsExW( LPCWSTR szProductCode, LPCWSTR szUserSid, |
Francois Gouget | 4deb14a | 2007-08-04 03:14:53 +0200 | [diff] [blame] | 2211 | DWORD dwContext, DWORD dwIndex, WCHAR szInstalledProductCode[39], |
Hans Leidekker | 9eefc04 | 2007-04-25 20:49:43 +0200 | [diff] [blame] | 2212 | MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, LPDWORD pcchSid) |
| 2213 | { |
| 2214 | FIXME("%s %s %d %d %p %p %p %p\n", debugstr_w(szProductCode), debugstr_w(szUserSid), |
| 2215 | dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext, |
| 2216 | szSid, pcchSid); |
| 2217 | return ERROR_NO_MORE_ITEMS; |
| 2218 | } |