| 63 | } |
| 64 | |
| 65 | bool Settings::LoadFromFile(PCWSTR path) { |
| 66 | if (path == nullptr) |
| 67 | path = _path.c_str(); |
| 68 | |
| 69 | ATLASSERT(path); |
| 70 | if (path == nullptr) |
| 71 | return false; |
| 72 | else |
| 73 | _path = path; |
| 74 | |
| 75 | IniFile file(path); |
| 76 | if (!file.IsValid()) |
| 77 | return false; |
| 78 | |
| 79 | PCWSTR section = L"General"; |
| 80 | for (auto& [name, setting] : _settings) { |
| 81 | switch (setting.Type) { |
| 82 | case SettingType::String: |
| 83 | setting.SetString(file.ReadString(section, name.c_str())); |
| 84 | break; |
| 85 | |
| 86 | case SettingType::Int32: |
| 87 | setting.Set<int>(file.ReadInt(section, name.c_str())); |
| 88 | break; |
| 89 | |
| 90 | default: |
| 91 | unsigned size; |
| 92 | auto data = file.ReadBinary(section, name.c_str(), size); |
| 93 | if (data && size > 0) |
| 94 | setting.Set(data.get(), size); |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | bool Settings::SaveToFile(PCWSTR path) const { |
| 103 | if (path == nullptr) |
nothing calls this directly
no test coverage detected