| 9 | } |
| 10 | |
| 11 | bool Settings::LoadFromKey(PCWSTR registryPath) { |
| 12 | if (registryPath == nullptr) |
| 13 | registryPath = _path.c_str(); |
| 14 | else |
| 15 | _path = registryPath; |
| 16 | |
| 17 | ATLASSERT(registryPath); |
| 18 | if (registryPath == nullptr) |
| 19 | return false; |
| 20 | |
| 21 | CRegKey key; |
| 22 | if (ERROR_SUCCESS != key.Open(HKEY_CURRENT_USER, registryPath)) |
| 23 | return false; |
| 24 | |
| 25 | WCHAR name[64]; |
| 26 | BYTE value[512]; |
| 27 | DWORD type; |
| 28 | for (DWORD i = 0;; ++i) { |
| 29 | DWORD lname = _countof(name), lvalue = sizeof(value); |
| 30 | auto error = ::RegEnumValue(key, i, name, &lname, nullptr, &type, value, &lvalue); |
| 31 | if (ERROR_NO_MORE_ITEMS == error) |
| 32 | break; |
| 33 | |
| 34 | if (error != ERROR_SUCCESS) |
| 35 | continue; |
| 36 | |
| 37 | auto it = _settings.find(name); |
| 38 | if (it == _settings.end()) |
| 39 | _settings.insert({ name,Setting(name,(BYTE*)value,lvalue,(SettingType)type) }); |
| 40 | else |
| 41 | it->second.Set(value, lvalue); |
| 42 | } |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | bool Settings::SaveToKey(PCWSTR registryPath) const { |
| 47 | if (registryPath == nullptr) |