Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: chrome/installer/mini_installer/mini_installer.cc

Issue 1247993002: Return Windows error code when create-process fails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clean up of comments and formatting Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/installer/mini_installer/mini_installer_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // mini_installer.exe is the first exe that is run when chrome is being 5 // mini_installer.exe is the first exe that is run when chrome is being
6 // installed or upgraded. It is designed to be extremely small (~5KB with no 6 // installed or upgraded. It is designed to be extremely small (~5KB with no
7 // extra resources linked) and it has two main jobs: 7 // extra resources linked) and it has two main jobs:
8 // 1) unpack the resources (possibly decompressing some) 8 // 1) unpack the resources (possibly decompressing some)
9 // 2) run the real installer (setup.exe) with appropriate flags. 9 // 2) run the real installer (setup.exe) with appropriate flags.
10 // 10 //
(...skipping 21 matching lines...) Expand all
32 #include "chrome/installer/mini_installer/mini_installer_constants.h" 32 #include "chrome/installer/mini_installer/mini_installer_constants.h"
33 #include "chrome/installer/mini_installer/mini_string.h" 33 #include "chrome/installer/mini_installer/mini_string.h"
34 #include "chrome/installer/mini_installer/pe_resource.h" 34 #include "chrome/installer/mini_installer/pe_resource.h"
35 35
36 namespace mini_installer { 36 namespace mini_installer {
37 37
38 typedef DWORD ProcessExitCode; 38 typedef DWORD ProcessExitCode;
39 typedef StackString<MAX_PATH> PathString; 39 typedef StackString<MAX_PATH> PathString;
40 typedef StackString<MAX_PATH * 4> CommandString; 40 typedef StackString<MAX_PATH * 4> CommandString;
41 41
42 DWORD LastWindowsError = 0;
43
42 // This structure passes data back and forth for the processing 44 // This structure passes data back and forth for the processing
43 // of resource callbacks. 45 // of resource callbacks.
44 struct Context { 46 struct Context {
45 // Input to the call back method. Specifies the dir to save resources. 47 // Input to the call back method. Specifies the dir to save resources.
46 const wchar_t* base_path; 48 const wchar_t* base_path;
47 // First output from call back method. Full path of Chrome archive. 49 // First output from call back method. Full path of Chrome archive.
48 PathString* chrome_resource_path; 50 PathString* chrome_resource_path;
49 // Second output from call back method. Full path of Setup archive/exe. 51 // Second output from call back method. Full path of Setup archive/exe.
50 PathString* setup_resource_path; 52 PathString* setup_resource_path;
51 }; 53 };
52 54
53 // A helper class used to manipulate the Windows registry. Typically, members 55 // A helper class used to manipulate the Windows registry. Typically, members
54 // return Windows last-error codes a la the Win32 registry API. 56 // return Windows last-error codes a la the Win32 registry API.
55 class RegKey { 57 class RegKey {
56 public: 58 public:
57 RegKey() : key_(NULL) { } 59 RegKey() : key_(NULL) { }
58 ~RegKey() { Close(); } 60 ~RegKey() { Close(); }
59 61
60 // Opens the key named |sub_key| with given |access| rights. Returns 62 // Opens the key named |sub_key| with given |access| rights. Returns
61 // ERROR_SUCCESS or some other error. 63 // ERROR_SUCCESS or some other error.
62 LONG Open(HKEY key, const wchar_t* sub_key, REGSAM access); 64 LONG Open(HKEY key, const wchar_t* sub_key, REGSAM access);
63 65
64 // Returns true if a key is open. 66 // Returns true if a key is open.
65 bool is_valid() const { return key_ != NULL; } 67 bool is_valid() const { return key_ != NULL; }
66 68
67 // Read a REG_SZ value from the registry into the memory indicated by |value| 69 // Read a REG_SZ value from the registry into the memory indicated by |value|
68 // (of |value_size| wchar_t units). Returns ERROR_SUCCESS, 70 // (of |value_size| wchar_t units). Returns ERROR_SUCCESS,
69 // ERROR_FILE_NOT_FOUND, ERROR_MORE_DATA, or some other error. |value| is 71 // ERROR_FILE_NOT_FOUND, ERROR_MORE_DATA, or some other error. |value| is
70 // guaranteed to be null-terminated on success. 72 // guaranteed to be null-terminated on success.
71 LONG ReadValue(const wchar_t* value_name, 73 LONG ReadSZValue(const wchar_t* value_name,
72 wchar_t* value, 74 wchar_t* value,
73 size_t value_size) const; 75 size_t value_size) const;
74 76
75 // Write a REG_SZ value to the registry. |value| must be null-terminated. 77 // Write a value to the registry. SZ |value| must be null-terminated.
76 // Returns ERROR_SUCCESS or an error code. 78 // Returns ERROR_SUCCESS or an error code.
77 LONG WriteValue(const wchar_t* value_name, const wchar_t* value); 79 LONG WriteSZValue(const wchar_t* value_name, const wchar_t* value);
80 LONG WriteDWValue(const wchar_t* value_name, DWORD value);
78 81
79 // Closes the key if it was open. 82 // Closes the key if it was open.
80 void Close(); 83 void Close();
81 84
82 private: 85 private:
83 RegKey(const RegKey&); 86 RegKey(const RegKey&);
84 RegKey& operator=(const RegKey&); 87 RegKey& operator=(const RegKey&);
85 88
86 HKEY key_; 89 HKEY key_;
87 }; // class RegKey 90 }; // class RegKey
88 91
89 LONG RegKey::Open(HKEY key, const wchar_t* sub_key, REGSAM access) { 92 LONG RegKey::Open(HKEY key, const wchar_t* sub_key, REGSAM access) {
90 Close(); 93 Close();
91 return ::RegOpenKeyEx(key, sub_key, NULL, access, &key_); 94 return ::RegOpenKeyEx(key, sub_key, NULL, access, &key_);
92 } 95 }
93 96
94 LONG RegKey::ReadValue(const wchar_t* value_name, 97 LONG RegKey::ReadSZValue(const wchar_t* value_name,
95 wchar_t* value, 98 wchar_t* value,
96 size_t value_size) const { 99 size_t value_size) const {
97 DWORD type; 100 DWORD type;
98 DWORD byte_length = static_cast<DWORD>(value_size * sizeof(wchar_t)); 101 DWORD byte_length = static_cast<DWORD>(value_size * sizeof(wchar_t));
99 LONG result = ::RegQueryValueEx(key_, value_name, NULL, &type, 102 LONG result = ::RegQueryValueEx(key_, value_name, NULL, &type,
100 reinterpret_cast<BYTE*>(value), 103 reinterpret_cast<BYTE*>(value),
101 &byte_length); 104 &byte_length);
102 if (result == ERROR_SUCCESS) { 105 if (result == ERROR_SUCCESS) {
103 if (type != REG_SZ) { 106 if (type != REG_SZ) {
104 result = ERROR_NOT_SUPPORTED; 107 result = ERROR_NOT_SUPPORTED;
105 } else if (byte_length == 0) { 108 } else if (byte_length == 0) {
106 *value = L'\0'; 109 *value = L'\0';
107 } else if (value[byte_length/sizeof(wchar_t) - 1] != L'\0') { 110 } else if (value[byte_length/sizeof(wchar_t) - 1] != L'\0') {
108 if ((byte_length / sizeof(wchar_t)) < value_size) 111 if ((byte_length / sizeof(wchar_t)) < value_size)
109 value[byte_length / sizeof(wchar_t)] = L'\0'; 112 value[byte_length / sizeof(wchar_t)] = L'\0';
110 else 113 else
111 result = ERROR_MORE_DATA; 114 result = ERROR_MORE_DATA;
112 } 115 }
113 } 116 }
114 return result; 117 return result;
115 } 118 }
116 119
117 LONG RegKey::WriteValue(const wchar_t* value_name, const wchar_t* value) { 120 LONG RegKey::WriteSZValue(const wchar_t* value_name, const wchar_t* value) {
118 return ::RegSetValueEx(key_, value_name, 0, REG_SZ, 121 return ::RegSetValueEx(key_, value_name, 0, REG_SZ,
119 reinterpret_cast<const BYTE*>(value), 122 reinterpret_cast<const BYTE*>(value),
120 (lstrlen(value) + 1) * sizeof(wchar_t)); 123 (lstrlen(value) + 1) * sizeof(wchar_t));
121 } 124 }
122 125
126 LONG RegKey::WriteDWValue(const wchar_t* value_name, DWORD value) {
127 return ::RegSetValueEx(key_, value_name, 0, REG_DWORD,
128 reinterpret_cast<const BYTE*>(&value),
129 sizeof(value));
130 }
131
123 void RegKey::Close() { 132 void RegKey::Close() {
124 if (key_ != NULL) { 133 if (key_ != NULL) {
125 ::RegCloseKey(key_); 134 ::RegCloseKey(key_);
126 key_ = NULL; 135 key_ = NULL;
127 } 136 }
128 } 137 }
129 138
130 // Helper function to read a value from registry. Returns true if value 139 // Helper function to read a value from registry. Returns true if value
131 // is read successfully and stored in parameter value. Returns false otherwise. 140 // is read successfully and stored in parameter value. Returns false otherwise.
132 // |size| is measured in wchar_t units. 141 // |size| is measured in wchar_t units.
133 bool ReadValueFromRegistry(HKEY root_key, const wchar_t *sub_key, 142 bool ReadSZValueFromRegistry(HKEY root_key, const wchar_t *sub_key,
134 const wchar_t *value_name, wchar_t *value, 143 const wchar_t *value_name, wchar_t *value,
135 size_t size) { 144 size_t size) {
136 RegKey key; 145 RegKey key;
137 146
138 if (key.Open(root_key, sub_key, KEY_QUERY_VALUE) == ERROR_SUCCESS && 147 if (key.Open(root_key, sub_key, KEY_QUERY_VALUE) == ERROR_SUCCESS &&
139 key.ReadValue(value_name, value, size) == ERROR_SUCCESS) { 148 key.ReadSZValue(value_name, value, size) == ERROR_SUCCESS) {
140 return true; 149 return true;
141 } 150 }
142 return false; 151 return false;
143 } 152 }
144 153
145 // Opens the Google Update ClientState key for a product. This finds only 154 // Opens the Google Update ClientState key for a product. This finds only
146 // registry entries for Chrome; it does not support the Chromium registry 155 // registry entries for Chrome; it does not support the Chromium registry
147 // layout. 156 // layout.
148 bool OpenClientStateKey(HKEY root_key, const wchar_t* app_guid, REGSAM access, 157 bool OpenClientStateKey(HKEY root_key, const wchar_t* app_guid, REGSAM access,
149 RegKey* key) { 158 RegKey* key) {
150 PathString client_state_key; 159 PathString client_state_key;
151 return client_state_key.assign(kClientStateKeyBase) && 160 return client_state_key.assign(kClientStateKeyBase) &&
152 client_state_key.append(app_guid) && 161 client_state_key.append(app_guid) &&
153 (key->Open(root_key, 162 (key->Open(root_key,
154 client_state_key.get(), 163 client_state_key.get(),
155 access | KEY_WOW64_32KEY) == ERROR_SUCCESS); 164 access | KEY_WOW64_32KEY) == ERROR_SUCCESS);
156 } 165 }
157 166
158 // This function sets the flag in registry to indicate that Google Update 167 // Opens the Google Update ClientState key for the current install
159 // should try full installer next time. If the current installer works, this 168 // configuration. This includes locating the correct key in the face of
160 // flag is cleared by setup.exe at the end of install. The flag will by default 169 // multi-install. The flag will by default be written to HKCU, but if
161 // be written to HKCU, but if --system-level is included in the command line, 170 // --system-level is included in the command line, it will be written to
162 // it will be written to HKLM instead. 171 // HKLM instead.
163 // TODO(grt): Write a unit test for this that uses registry virtualization. 172 // TODO(bcwhite): Write a unit test for this that uses registry virtualization.
164 void SetInstallerFlags(const Configuration& configuration) { 173 bool OpenInstallStateKey(const Configuration& configuration, RegKey* key) {
165 RegKey key;
166 const REGSAM key_access = KEY_QUERY_VALUE | KEY_SET_VALUE;
167 const HKEY root_key = 174 const HKEY root_key =
168 configuration.is_system_level() ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 175 configuration.is_system_level() ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
169 // This is ignored if multi-install is true.
170 const wchar_t* app_guid = 176 const wchar_t* app_guid =
171 configuration.has_chrome_frame() ? 177 configuration.has_chrome_frame() ?
172 google_update::kChromeFrameAppGuid : 178 google_update::kChromeFrameAppGuid :
173 configuration.chrome_app_guid(); 179 configuration.chrome_app_guid();
174 StackString<128> value; 180 const REGSAM key_access = KEY_QUERY_VALUE | KEY_SET_VALUE;
175 LONG ret = ERROR_SUCCESS; 181 LONG ret = ERROR_SUCCESS;
176 182
177 // When multi_install is true, we are potentially: 183 // When multi_install is true, we are potentially:
178 // 1. Performing a multi-install of some product(s) on a clean machine. 184 // 1. Performing a multi-install of some product(s) on a clean machine.
179 // Neither the product(s) nor the multi-installer will have a ClientState 185 // Neither the product(s) nor the multi-installer will have a ClientState
180 // key in the registry, so there is nothing to be done. 186 // key in the registry, so there is no key to be modified.
181 // 2. Upgrading an existing multi-install. The multi-installer will have a 187 // 2. Upgrading an existing multi-install. The multi-installer will have a
182 // ClientState key in the registry. Only it need be modified. 188 // ClientState key in the registry. Only it need be modified.
183 // 3. Migrating a single-install into a multi-install. The product will have 189 // 3. Migrating a single-install into a multi-install. The product will have
184 // a ClientState key in the registry. Only it need be modified. 190 // a ClientState key in the registry. Only it need be modified.
185 // To handle all cases, we inspect the product's ClientState to see if it 191 // To handle all cases, we inspect the product's ClientState to see if it
186 // exists and its "ap" value does not contain "-multi". This is case 3, so we 192 // exists and its "ap" value does not contain "-multi". This is case 3, so we
187 // modify the product's ClientState. Otherwise, we check the 193 // modify the product's ClientState. Otherwise, we check the
188 // multi-installer's ClientState and modify it if it exists. 194 // multi-installer's ClientState and modify it if it exists.
189 if (configuration.is_multi_install()) { 195 if (configuration.is_multi_install()) {
190 if (OpenClientStateKey(root_key, app_guid, key_access, &key)) { 196 if (OpenClientStateKey(root_key, app_guid, key_access, key)) {
191 // The product has a client state key. See if it's a single-install. 197 // The product has a client state key. See if it's a single-install.
192 ret = key.ReadValue(kApRegistryValue, value.get(), value.capacity()); 198 StackString<128> value;
193 if (ret != ERROR_FILE_NOT_FOUND && 199 ret = key->ReadSZValue(kApRegistryValue, value.get(), value.capacity());
194 (ret != ERROR_SUCCESS || 200 if (ret == ERROR_FILE_NOT_FOUND ||
195 FindTagInStr(value.get(), kMultiInstallTag, NULL))) { 201 (ret == ERROR_SUCCESS &&
196 // Error or case 2: modify the multi-installer's value. 202 !FindTagInStr(value.get(), kMultiInstallTag, NULL))) {
197 key.Close(); 203 // yes -- case 3: modify this key.
198 app_guid = google_update::kMultiInstallAppGuid; 204 return true;
199 } // else case 3: modify this value. 205 }
200 } else {
201 // case 1 or 2: modify the multi-installer's value.
202 key.Close();
203 app_guid = google_update::kMultiInstallAppGuid;
204 } 206 }
207 // error, case 1, or case 2: modify the multi-installer's key.
208 key->Close();
209 app_guid = google_update::kMultiInstallAppGuid;
205 } 210 }
206 211
207 if (!key.is_valid()) { 212 return OpenClientStateKey(root_key, app_guid, key_access, key);
208 if (!OpenClientStateKey(root_key, app_guid, key_access, &key)) 213 }
209 return;
210 214
211 value.clear(); 215 // Writes install results into registry where it is read by Google Update.
212 ret = key.ReadValue(kApRegistryValue, value.get(), value.capacity()); 216 void WriteInstallResults(const Configuration& configuration,
217 DWORD exit_code, DWORD last_error) {
218 #if defined(GOOGLE_CHROME_BUILD)
219 RegKey key;
220 if (OpenInstallStateKey(configuration, &key)) {
221 key.WriteDWValue(kInstallerResultRegistryValue,
222 exit_code ? 1 /* FAILED_CUSTOM_ERROR */
223 : 0 /* SUCCESS */);
224 key.WriteDWValue(kInstallerErrorRegistryValue, exit_code);
225 key.WriteDWValue(kInstallerExtraCode1RegistryValue, last_error);
226 key.Close();
213 } 227 }
228 #endif
229 }
230
231 // This function sets the flag in registry to indicate that Google Update
232 // should try full installer next time. If the current installer works, this
233 // flag is cleared by setup.exe at the end of install.
234 void SetInstallerFlags(const Configuration& configuration) {
235 RegKey key;
236 StackString<128> value;
237 LONG ret = ERROR_SUCCESS;
238
239 if (!OpenInstallStateKey(configuration, &key))
240 return;
241
242 ret = key.ReadSZValue(kApRegistryValue, value.get(), value.capacity());
214 243
215 // The conditions below are handling two cases: 244 // The conditions below are handling two cases:
216 // 1. When ap value is present, we want to add the required tag only if it is 245 // 1. When ap value is present, we want to add the required tag only if it is
217 // not present. 246 // not present.
218 // 2. When ap value is missing, we are going to create it with the required 247 // 2. When ap value is missing, we are going to create it with the required
219 // tag. 248 // tag.
220 if ((ret == ERROR_SUCCESS) || (ret == ERROR_FILE_NOT_FOUND)) { 249 if ((ret == ERROR_SUCCESS) || (ret == ERROR_FILE_NOT_FOUND)) {
221 if (ret == ERROR_FILE_NOT_FOUND) 250 if (ret == ERROR_FILE_NOT_FOUND)
222 value.clear(); 251 value.clear();
223 252
224 if (!StrEndsWith(value.get(), kFullInstallerSuffix) && 253 if (!StrEndsWith(value.get(), kFullInstallerSuffix) &&
225 value.append(kFullInstallerSuffix)) { 254 value.append(kFullInstallerSuffix)) {
226 key.WriteValue(kApRegistryValue, value.get()); 255 key.WriteSZValue(kApRegistryValue, value.get());
227 } 256 }
228 } 257 }
229 } 258 }
230 259
231 // Gets the setup.exe path from Registry by looking at the value of Uninstall 260 // Gets the setup.exe path from Registry by looking at the value of Uninstall
232 // string. |size| is measured in wchar_t units. 261 // string. |size| is measured in wchar_t units.
233 ProcessExitCode GetSetupExePathForAppGuid(bool system_level, 262 ProcessExitCode GetSetupExePathForAppGuid(bool system_level,
234 const wchar_t* app_guid, 263 const wchar_t* app_guid,
235 const wchar_t* previous_version, 264 const wchar_t* previous_version,
236 wchar_t* path, 265 wchar_t* path,
237 size_t size) { 266 size_t size) {
238 const HKEY root_key = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 267 const HKEY root_key = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
239 RegKey key; 268 RegKey key;
240 if (!OpenClientStateKey(root_key, app_guid, KEY_QUERY_VALUE, &key) || 269 if (!OpenClientStateKey(root_key, app_guid, KEY_QUERY_VALUE, &key) ||
241 (key.ReadValue(kUninstallRegistryValue, path, size) != ERROR_SUCCESS)) { 270 (key.ReadSZValue(kUninstallRegistryValue, path, size) != ERROR_SUCCESS)) {
242 return UNABLE_TO_FIND_REGISTRY_KEY; 271 return UNABLE_TO_FIND_REGISTRY_KEY;
243 } 272 }
244 273
245 // Check that the path to the existing installer includes the expected 274 // Check that the path to the existing installer includes the expected
246 // version number. It's not necessary for accuracy to verify before/after 275 // version number. It's not necessary for accuracy to verify before/after
247 // delimiters. 276 // delimiters.
248 if (!SearchStringI(path, previous_version)) 277 if (!SearchStringI(path, previous_version))
249 return PATCH_NOT_FOR_INSTALLED_VERSION; 278 return PATCH_NOT_FOR_INSTALLED_VERSION;
250 279
251 return SUCCESS_EXIT_CODE; 280 return SUCCESS_EXIT_CODE;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 316 }
288 317
289 // Calls CreateProcess with good default parameters and waits for the process to 318 // Calls CreateProcess with good default parameters and waits for the process to
290 // terminate returning the process exit code. |exit_code|, if non-NULL, is 319 // terminate returning the process exit code. |exit_code|, if non-NULL, is
291 // populated with the process exit code. 320 // populated with the process exit code.
292 ProcessExitCode RunProcessAndWait(const wchar_t* exe_path, wchar_t* cmdline) { 321 ProcessExitCode RunProcessAndWait(const wchar_t* exe_path, wchar_t* cmdline) {
293 STARTUPINFOW si = {sizeof(si)}; 322 STARTUPINFOW si = {sizeof(si)};
294 PROCESS_INFORMATION pi = {0}; 323 PROCESS_INFORMATION pi = {0};
295 if (!::CreateProcess(exe_path, cmdline, NULL, NULL, FALSE, CREATE_NO_WINDOW, 324 if (!::CreateProcess(exe_path, cmdline, NULL, NULL, FALSE, CREATE_NO_WINDOW,
296 NULL, NULL, &si, &pi)) { 325 NULL, NULL, &si, &pi)) {
326 LastWindowsError = ::GetLastError();
297 return COULD_NOT_CREATE_PROCESS; 327 return COULD_NOT_CREATE_PROCESS;
298 } 328 }
299 329
300 ::CloseHandle(pi.hThread); 330 ::CloseHandle(pi.hThread);
301 331
302 ProcessExitCode exit_code = SUCCESS_EXIT_CODE; 332 ProcessExitCode exit_code = SUCCESS_EXIT_CODE;
303 DWORD wr = ::WaitForSingleObject(pi.hProcess, INFINITE); 333 DWORD wr = ::WaitForSingleObject(pi.hProcess, INFINITE);
304 if (WAIT_OBJECT_0 != wr || !::GetExitCodeProcess(pi.hProcess, &exit_code)) 334 if (WAIT_OBJECT_0 != wr || !::GetExitCodeProcess(pi.hProcess, &exit_code)) {
335 LastWindowsError = ::GetLastError();
305 exit_code = WAIT_FOR_PROCESS_FAILED; 336 exit_code = WAIT_FOR_PROCESS_FAILED;
337 }
306 338
307 ::CloseHandle(pi.hProcess); 339 ::CloseHandle(pi.hProcess);
308 340
309 return exit_code; 341 return exit_code;
310 } 342 }
311 343
312 // Appends any command line params passed to mini_installer to the given buffer 344 // Appends any command line params passed to mini_installer to the given buffer
313 // so that they can be passed on to setup.exe. 345 // so that they can be passed on to setup.exe.
314 // |buffer| is unchanged in case of error. 346 // |buffer| is unchanged in case of error.
315 void AppendCommandLineFlags(const Configuration& configuration, 347 void AppendCommandLineFlags(const Configuration& configuration,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 base_path, 476 base_path,
445 archive_path, 477 archive_path,
446 setup_path, 478 setup_path,
447 }; 479 };
448 480
449 // Get the resources of type 'B7' (7zip archive). 481 // Get the resources of type 'B7' (7zip archive).
450 // We need a chrome archive to do the installation. So if there 482 // We need a chrome archive to do the installation. So if there
451 // is a problem in fetching B7 resource, just return an error. 483 // is a problem in fetching B7 resource, just return an error.
452 if (!::EnumResourceNames(module, kLZMAResourceType, OnResourceFound, 484 if (!::EnumResourceNames(module, kLZMAResourceType, OnResourceFound,
453 reinterpret_cast<LONG_PTR>(&context)) || 485 reinterpret_cast<LONG_PTR>(&context)) ||
454 archive_path->length() == 0) 486 archive_path->length() == 0) {
487 LastWindowsError = ::GetLastError();
455 return UNABLE_TO_EXTRACT_CHROME_ARCHIVE; 488 return UNABLE_TO_EXTRACT_CHROME_ARCHIVE;
489 }
456 490
457 ProcessExitCode exit_code = SUCCESS_EXIT_CODE; 491 ProcessExitCode exit_code = SUCCESS_EXIT_CODE;
458 492
459 // If we found setup 'B7' resource (used for differential updates), handle 493 // If we found setup 'B7' resource (used for differential updates), handle
460 // it. Note that this is only for Chrome; Chromium installs are always 494 // it. Note that this is only for Chrome; Chromium installs are always
461 // "full" installs. 495 // "full" installs.
462 if (setup_path->length() > 0) { 496 if (setup_path->length() > 0) {
463 CommandString cmd_line; 497 CommandString cmd_line;
464 PathString exe_path; 498 PathString exe_path;
465 // Get the path to setup.exe first. 499 // Get the path to setup.exe first.
(...skipping 28 matching lines...) Expand all
494 else if (!setup_path->assign(setup_dest_path.get())) 528 else if (!setup_path->assign(setup_dest_path.get()))
495 exit_code = PATH_STRING_OVERFLOW; 529 exit_code = PATH_STRING_OVERFLOW;
496 530
497 return exit_code; 531 return exit_code;
498 } 532 }
499 533
500 // setup.exe wasn't sent as 'B7', lets see if it was sent as 'BL' 534 // setup.exe wasn't sent as 'B7', lets see if it was sent as 'BL'
501 // (compressed setup). 535 // (compressed setup).
502 if (!::EnumResourceNames(module, kLZCResourceType, OnResourceFound, 536 if (!::EnumResourceNames(module, kLZCResourceType, OnResourceFound,
503 reinterpret_cast<LONG_PTR>(&context)) && 537 reinterpret_cast<LONG_PTR>(&context)) &&
504 ::GetLastError() != ERROR_RESOURCE_TYPE_NOT_FOUND) 538 ::GetLastError() != ERROR_RESOURCE_TYPE_NOT_FOUND) {
539 LastWindowsError = ::GetLastError();
505 return UNABLE_TO_EXTRACT_SETUP_B7; 540 return UNABLE_TO_EXTRACT_SETUP_B7;
541 }
506 542
507 if (setup_path->length() > 0) { 543 if (setup_path->length() > 0) {
508 // Uncompress LZ compressed resource. Setup is packed with 'MSCF' 544 // Uncompress LZ compressed resource. Setup is packed with 'MSCF'
509 // as opposed to old DOS way of 'SZDD'. Hence we don't use LZCopy. 545 // as opposed to old DOS way of 'SZDD'. Hence we don't use LZCopy.
510 bool success = mini_installer::Expand(setup_path->get(), 546 bool success = mini_installer::Expand(setup_path->get(),
511 setup_dest_path.get()); 547 setup_dest_path.get());
512 ::DeleteFile(setup_path->get()); 548 ::DeleteFile(setup_path->get());
513 if (success) { 549 if (success) {
514 if (!setup_path->assign(setup_dest_path.get())) { 550 if (!setup_path->assign(setup_dest_path.get())) {
515 ::DeleteFile(setup_dest_path.get()); 551 ::DeleteFile(setup_dest_path.get());
516 exit_code = PATH_STRING_OVERFLOW; 552 exit_code = PATH_STRING_OVERFLOW;
517 } 553 }
518 } else { 554 } else {
519 exit_code = UNABLE_TO_EXTRACT_SETUP_EXE; 555 exit_code = UNABLE_TO_EXTRACT_SETUP_EXE;
520 } 556 }
521 557
522 #if defined(COMPONENT_BUILD) 558 #if defined(COMPONENT_BUILD)
523 // Extract the (uncompressed) modules required by setup.exe. 559 // Extract the (uncompressed) modules required by setup.exe.
524 if (!::EnumResourceNames(module, kBinResourceType, WriteResourceToDirectory, 560 if (!::EnumResourceNames(module, kBinResourceType, WriteResourceToDirectory,
525 reinterpret_cast<LONG_PTR>(base_path))) 561 reinterpret_cast<LONG_PTR>(base_path))) {
562 LastWindowsError = ::GetLastError();
526 return UNABLE_TO_EXTRACT_SETUP; 563 return UNABLE_TO_EXTRACT_SETUP;
564 }
527 #endif 565 #endif
528 566
529 return exit_code; 567 return exit_code;
530 } 568 }
531 569
532 // setup.exe still not found. So finally check if it was sent as 'BN' 570 // setup.exe still not found. So finally check if it was sent as 'BN'
533 // (uncompressed setup). 571 // (uncompressed setup).
534 // TODO(tommi): We don't need BN anymore so let's remove it (and remove 572 // TODO(tommi): We don't need BN anymore so let's remove it (and remove
535 // it from create_installer_archive.py). 573 // it from create_installer_archive.py).
536 if (!::EnumResourceNames(module, kBinResourceType, OnResourceFound, 574 if (!::EnumResourceNames(module, kBinResourceType, OnResourceFound,
537 reinterpret_cast<LONG_PTR>(&context)) && 575 reinterpret_cast<LONG_PTR>(&context)) &&
538 ::GetLastError() != ERROR_RESOURCE_TYPE_NOT_FOUND) 576 ::GetLastError() != ERROR_RESOURCE_TYPE_NOT_FOUND) {
577 LastWindowsError = ::GetLastError();
539 return UNABLE_TO_EXTRACT_SETUP_BN; 578 return UNABLE_TO_EXTRACT_SETUP_BN;
579 }
540 580
541 if (setup_path->length() > 0) { 581 if (setup_path->length() > 0) {
542 if (setup_path->comparei(setup_dest_path.get()) != 0) { 582 if (setup_path->comparei(setup_dest_path.get()) != 0) {
543 if (!::MoveFileEx(setup_path->get(), setup_dest_path.get(), 583 if (!::MoveFileEx(setup_path->get(), setup_dest_path.get(),
544 MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING)) { 584 MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING)) {
545 ::DeleteFile(setup_path->get()); 585 ::DeleteFile(setup_path->get());
546 setup_path->clear(); 586 setup_path->clear();
547 } else if (!setup_path->assign(setup_dest_path.get())) { 587 } else if (!setup_path->assign(setup_dest_path.get())) {
548 ::DeleteFile(setup_dest_path.get()); 588 ::DeleteFile(setup_dest_path.get());
549 } 589 }
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 860
821 // Returns true if we should delete the temp files we create (default). 861 // Returns true if we should delete the temp files we create (default).
822 // Returns false iff the user has manually created a ChromeInstallerCleanup 862 // Returns false iff the user has manually created a ChromeInstallerCleanup
823 // string value in the registry under HKCU\\Software\\[Google|Chromium] 863 // string value in the registry under HKCU\\Software\\[Google|Chromium]
824 // and set its value to "0". That explicitly forbids the mini installer from 864 // and set its value to "0". That explicitly forbids the mini installer from
825 // deleting these files. 865 // deleting these files.
826 // Support for this has been publicly mentioned in troubleshooting tips so 866 // Support for this has been publicly mentioned in troubleshooting tips so
827 // we continue to support it. 867 // we continue to support it.
828 bool ShouldDeleteExtractedFiles() { 868 bool ShouldDeleteExtractedFiles() {
829 wchar_t value[2] = {0}; 869 wchar_t value[2] = {0};
830 if (ReadValueFromRegistry(HKEY_CURRENT_USER, kCleanupRegistryKey, 870 if (ReadSZValueFromRegistry(HKEY_CURRENT_USER, kCleanupRegistryKey,
831 kCleanupRegistryValue, value, _countof(value)) && 871 kCleanupRegistryValue, value, _countof(value)) &&
832 value[0] == L'0') { 872 value[0] == L'0') {
833 return false; 873 return false;
834 } 874 }
835 875
836 return true; 876 return true;
837 } 877 }
838 878
839 // Main function. First gets a working dir, unpacks the resources and finally 879 // Main function. First gets a working dir, unpacks the resources and finally
840 // executes setup.exe to do the install/upgrade. 880 // executes setup.exe to do the install/upgrade.
841 ProcessExitCode WMain(HMODULE module) { 881 ProcessExitCode WMain(HMODULE module) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 // we don't need anymore. Let's give it back to the pool before running 919 // we don't need anymore. Let's give it back to the pool before running
880 // setup. 920 // setup.
881 ::SetProcessWorkingSetSize(::GetCurrentProcess(), -1, -1); 921 ::SetProcessWorkingSetSize(::GetCurrentProcess(), -1, -1);
882 922
883 if (exit_code == SUCCESS_EXIT_CODE) 923 if (exit_code == SUCCESS_EXIT_CODE)
884 exit_code = RunSetup(configuration, archive_path.get(), setup_path.get()); 924 exit_code = RunSetup(configuration, archive_path.get(), setup_path.get());
885 925
886 if (ShouldDeleteExtractedFiles()) 926 if (ShouldDeleteExtractedFiles())
887 DeleteExtractedFiles(base_path.get(), archive_path.get(), setup_path.get()); 927 DeleteExtractedFiles(base_path.get(), archive_path.get(), setup_path.get());
888 928
929 WriteInstallResults(configuration, exit_code, LastWindowsError);
grt (UTC plus 2) 2015/07/27 15:21:37 i had a thought over the weekend: mini_installer s
889 return exit_code; 930 return exit_code;
890 } 931 }
891 932
892 } // namespace mini_installer 933 } // namespace mini_installer
893 934
894 int MainEntryPoint() { 935 int MainEntryPoint() {
895 mini_installer::ProcessExitCode result = 936 mini_installer::ProcessExitCode result =
896 mini_installer::WMain(::GetModuleHandle(NULL)); 937 mini_installer::WMain(::GetModuleHandle(NULL));
938
897 ::ExitProcess(result); 939 ::ExitProcess(result);
898 } 940 }
899 941
900 // VC Express editions don't come with the memset CRT obj file and linking to 942 // VC Express editions don't come with the memset CRT obj file and linking to
901 // the obj files between versions becomes a bit problematic. Therefore, 943 // the obj files between versions becomes a bit problematic. Therefore,
902 // simply implement memset. 944 // simply implement memset.
903 // 945 //
904 // This also avoids having to explicitly set the __sse2_available hack when 946 // This also avoids having to explicitly set the __sse2_available hack when
905 // linking with both the x64 and x86 obj files which is required when not 947 // linking with both the x64 and x86 obj files which is required when not
906 // linking with the std C lib in certain instances (including Chromium) with 948 // linking with the std C lib in certain instances (including Chromium) with
907 // MSVC. __sse2_available determines whether to use SSE2 intructions with 949 // MSVC. __sse2_available determines whether to use SSE2 intructions with
908 // std C lib routines, and is set by MSVC's std C lib implementation normally. 950 // std C lib routines, and is set by MSVC's std C lib implementation normally.
909 extern "C" { 951 extern "C" {
910 #pragma function(memset) 952 #pragma function(memset)
911 void* memset(void* dest, int c, size_t count) { 953 void* memset(void* dest, int c, size_t count) {
912 void* start = dest; 954 void* start = dest;
913 while (count--) { 955 while (count--) {
914 *reinterpret_cast<char*>(dest) = static_cast<char>(c); 956 *reinterpret_cast<char*>(dest) = static_cast<char>(c);
915 dest = reinterpret_cast<char*>(dest) + 1; 957 dest = reinterpret_cast<char*>(dest) + 1;
916 } 958 }
917 return start; 959 return start;
918 } 960 }
919 } // extern "C" 961 } // extern "C"
OLDNEW
« no previous file with comments | « no previous file | chrome/installer/mini_installer/mini_installer_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698