| 3 | #include "IniFile.h" |
| 4 | |
| 5 | bool LocationManager::LoadFromRegistry(PCWSTR path) { |
| 6 | path = GetPath(path); |
| 7 | if (!path) |
| 8 | return false; |
| 9 | |
| 10 | CRegKey key; |
| 11 | key.Open(HKEY_CURRENT_USER, path, KEY_QUERY_VALUE); |
| 12 | if (!key) |
| 13 | return false; |
| 14 | |
| 15 | ULONG chars = 0; |
| 16 | key.QueryStringValue(L"Locations", nullptr, &chars); |
| 17 | if (chars == 0) |
| 18 | return false; |
| 19 | |
| 20 | auto data = std::make_unique<WCHAR[]>(chars); |
| 21 | if (ERROR_SUCCESS != key.QueryStringValue(L"Locations", data.get(), &chars)) |
| 22 | return false; |
| 23 | |
| 24 | _items.clear(); |
| 25 | for (auto p = data.get(); *p;) { |
| 26 | auto semi = wcschr(p, L';'); |
| 27 | if (semi == nullptr) |
| 28 | return false; |
| 29 | |
| 30 | auto count = semi - p; |
| 31 | CString name((PCWSTR)p, (int)count); |
| 32 | auto cr = wcschr(semi + 1, L'\n'); |
| 33 | CString path(semi + 1, (int)(cr - semi - 1)); |
| 34 | if (name.IsEmpty()) |
| 35 | name = path; |
| 36 | _items.insert({ name,path }); |
| 37 | p = cr + 1; |
| 38 | } |
| 39 | |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | bool LocationManager::SaveToRegistry(PCWSTR path) const { |
| 44 | if (_items.empty()) |
nothing calls this directly
no test coverage detected