MCPcopy Create free account
hub / github.com/BeneficialCode/WinArk / OpenKey

Method OpenKey

WinArk/Registry.cpp:95–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93}
94
95RegistryKey Registry::OpenKey(const CString& path, DWORD access, bool* root) {
96 if (root)
97 *root = false;
98
99 RegistryKey key;
100 if (path.Left(2) == L"\\\\") {
101 // remote registry
102 auto index = path.Find(L"\\", 2);
103 if (index < 0)
104 return key;
105
106 auto name = path.Mid(2, index - 2);
107 auto& rr = _remotes[name];
108 index = path.Find(L"\\HKEY_LOCAL_MACHINE");
109 HKEY hRoot = index >= 0 ? rr.hLocal : rr.hUsers;
110 if (index < 0)
111 index = path.Find(L"\\HKEY_USERS");
112
113 ATLASSERT(index >= 0);
114 index = path.Find(L"\\", index + 1);
115 if (index < 0) {
116 key.Attach(hRoot, false);
117 }
118 else {
119 auto subpath = path.Mid(index + 1);
120 auto error = key.Open(hRoot, subpath, access);
121 ::SetLastError(error);
122 }
123 return key;
124 }
125 if (path[0] == L'\\') {
126 // real registry
127 key.Attach(OpenRealRegistryKey(path, access));
128 }
129 else {
130 auto bs = path.Find(L'\\');
131 CString keyname = path;
132 if (bs >= 0) {
133 ATLASSERT(bs >= 0);
134 keyname = path.Left(bs);
135 }
136 // c++11 std::begin
137 auto pair = std::find_if(std::begin(Keys), std::end(Keys), [&](auto& k) {
138 return _wcsicmp(k.text, keyname) == 0 || _wcsicmp(k.stext, keyname) == 0;
139 });
140 ATLASSERT(pair != std::end(Keys));
141 if (bs >= 0) {
142 auto error = key.Open(pair->hKey, path.Mid(bs + 1), access);
143 ::SetLastError(error);
144 }
145 else {
146 key.Attach(pair->hKey, false);
147 if (root)
148 *root = true;
149 }
150 }
151 return key;
152}

Callers

nothing calls this directly

Calls 3

FindMethod · 0.80
AttachMethod · 0.45
OpenMethod · 0.45

Tested by

no test coverage detected