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

Side by Side Diff: base/registry_store.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 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 | « base/registry_store.h ('k') | base/registry_store_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2005-2009 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // ========================================================================
15
16 #include "omaha/base/registry_store.h"
17 #include <vector>
18 #include "omaha/base/debug.h"
19 #include "omaha/base/reg_key.h"
20
21 namespace omaha {
22
23 bool RegistryStore::Open(const TCHAR* key_path) {
24 key_path_ = key_path;
25 return true;
26 }
27
28 bool RegistryStore::Close() {
29 key_path_.Empty();
30 return true;
31 }
32
33 bool RegistryStore::Clear() {
34 if (RegKey::HasKey(key_path_)) {
35 return SUCCEEDED(RegKey::DeleteKey(key_path_, false));
36 } else {
37 return true;
38 }
39 }
40
41 bool RegistryStore::Read(const TCHAR* name, std::vector<byte>* data) const {
42 ASSERT1(name);
43 ASSERT1(data);
44
45 byte* sdata = NULL;
46 DWORD sdata_size = 0;
47 HRESULT hr = RegKey::GetValue(key_path_, name, &sdata, &sdata_size);
48 if (FAILED(hr) || !sdata || !sdata_size)
49 return false;
50
51 data->resize(sdata_size);
52 memcpy(&data->front(), sdata, sdata_size);
53
54 delete[] sdata;
55
56 return true;
57 }
58
59 bool RegistryStore::Write(const TCHAR* name, byte* data, int data_size) {
60 ASSERT1(name);
61 ASSERT1(data);
62 ASSERT1(data_size);
63
64 return SUCCEEDED(RegKey::SetValue(key_path_, name, data, data_size));
65 }
66
67 bool RegistryStore::Exists(const TCHAR* name) {
68 ASSERT1(name);
69
70 return RegKey::HasValue(key_path_, name);
71 }
72
73 bool RegistryStore::Remove(const TCHAR* name) {
74 ASSERT1(name);
75
76 return SUCCEEDED(RegKey::DeleteValue(key_path_, name));
77 }
78
79 bool RegistryStore::GetValueCount(uint32* value_count) {
80 ASSERT1(value_count);
81
82 CString key_name(key_path_);
83 HKEY h_key = RegKey::GetRootKeyInfo(&key_name);
84
85 RegKey reg_key;
86 if (FAILED(reg_key.Open(h_key, key_name.GetString(), KEY_READ)))
87 return false;
88
89 *value_count = reg_key.GetValueCount();
90
91 reg_key.Close();
92
93 return true;
94 }
95
96 bool RegistryStore::GetValueNameAt(int index, CString* value_name) {
97 ASSERT1(index >= 0);
98 ASSERT1(value_name);
99
100 CString key_name(key_path_);
101 HKEY h_key = RegKey::GetRootKeyInfo(&key_name);
102
103 RegKey reg_key;
104 if (FAILED(reg_key.Open(h_key, key_name.GetString(), KEY_READ)))
105 return false;
106
107 HRESULT hr = reg_key.GetValueNameAt(index, value_name, NULL);
108
109 reg_key.Close();
110
111 return SUCCEEDED(hr);
112 }
113
114 } // namespace omaha
115
OLDNEW
« no previous file with comments | « base/registry_store.h ('k') | base/registry_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698