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

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

Issue 1247993002: Return Windows error code when create-process fails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed configuration tests and added new ones Created 5 years, 4 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/installer/mini_installer/mini_installer_constants.h"
6 #include "chrome/installer/mini_installer/mini_string.h"
7 #include "chrome/installer/mini_installer/regkey.h"
robertshield 2015/08/04 03:11:36 This #include should go first. Do git cl format or
bcwhite 2015/08/04 19:34:31 Done.
8
9 namespace mini_installer {
10
11 LONG RegKey::Open(HKEY key, const wchar_t* sub_key, REGSAM access) {
12 Close();
13 return ::RegOpenKeyEx(key, sub_key, NULL, access, &key_);
14 }
15
16 LONG RegKey::ReadSZValue(const wchar_t* value_name,
17 wchar_t* value,
18 size_t value_size) const {
19 DWORD type;
robertshield 2015/08/04 03:11:36 please initialize type to 0
bcwhite 2015/08/04 19:34:31 Done.
20 DWORD byte_length = static_cast<DWORD>(value_size * sizeof(wchar_t));
21 LONG result = ::RegQueryValueEx(key_, value_name, NULL, &type,
22 reinterpret_cast<BYTE*>(value),
23 &byte_length);
24 if (result == ERROR_SUCCESS) {
25 if (type != REG_SZ) {
26 result = ERROR_NOT_SUPPORTED;
27 } else if (byte_length == 0) {
28 *value = L'\0';
29 } else if (value[byte_length/sizeof(wchar_t) - 1] != L'\0') {
30 if ((byte_length / sizeof(wchar_t)) < value_size)
31 value[byte_length / sizeof(wchar_t)] = L'\0';
32 else
33 result = ERROR_MORE_DATA;
34 }
35 }
36 return result;
37 }
38
39 LONG RegKey::ReadDWValue(const wchar_t* value_name, DWORD* value) const {
40 DWORD type;
robertshield 2015/08/04 03:11:36 initialize
bcwhite 2015/08/04 19:34:31 Done.
41 DWORD byte_length = sizeof(*value);
42 LONG result = ::RegQueryValueEx(key_, value_name, NULL, &type,
43 reinterpret_cast<BYTE*>(value),
44 &byte_length);
45 if (result == ERROR_SUCCESS) {
46 if (type != REG_DWORD) {
47 result = ERROR_NOT_SUPPORTED;
48 } else if (byte_length != sizeof(*value)) {
49 result = ERROR_NO_DATA;
50 }
51 }
52 return result;
53 }
54
55 LONG RegKey::WriteSZValue(const wchar_t* value_name, const wchar_t* value) {
56 return ::RegSetValueEx(key_, value_name, 0, REG_SZ,
57 reinterpret_cast<const BYTE*>(value),
58 (lstrlen(value) + 1) * sizeof(wchar_t));
59 }
60
61 LONG RegKey::WriteDWValue(const wchar_t* value_name, DWORD value) {
62 return ::RegSetValueEx(key_, value_name, 0, REG_DWORD,
63 reinterpret_cast<const BYTE*>(&value),
64 sizeof(value));
65 }
66
67 void RegKey::Close() {
68 if (key_ != NULL) {
69 ::RegCloseKey(key_);
70 key_ = NULL;
71 }
72 }
73
74
75 // static
76 bool RegKey::ReadSZValue(HKEY root_key, const wchar_t *sub_key,
77 const wchar_t *value_name, wchar_t *value,
78 size_t size) {
79 RegKey key;
80 return (key.Open(root_key, sub_key, KEY_QUERY_VALUE) == ERROR_SUCCESS &&
81 key.ReadSZValue(value_name, value, size) == ERROR_SUCCESS);
82 }
83
84 // static
85 // Opens the Google Update ClientState key for a product. This finds only
86 // registry entries for Chrome; it does not support the Chromium registry
87 // layout.
88 bool RegKey::OpenClientStateKey(HKEY root_key, const wchar_t* app_guid,
89 REGSAM access, RegKey* key) {
90 StackString<MAX_PATH> client_state_key;
91 return client_state_key.assign(kClientStateKeyBase) &&
92 client_state_key.append(app_guid) &&
93 (key->Open(root_key,
94 client_state_key.get(),
95 access | KEY_WOW64_32KEY) == ERROR_SUCCESS);
96 }
97
98 } // namespace mini_installer
OLDNEW
« chrome/installer/mini_installer/regkey.h ('K') | « chrome/installer/mini_installer/regkey.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698