Read the settings file once, keeping Dear ImGui's section as it parses

This commit is contained in:
shweet committed 2026-11-22 19:04:09 -05:00
1 parent 91cc11aa3b
commit 4b17e9b328
3 files changed
+8 -53

No files matched your search

+4 -49
View File
@@ -252,8 +252,12 @@ Settings::Settings(const std::filesystem::path& path)
{
if (line == "[Settings]" || line.empty())
continue;
// The rest of the file is Dear ImGui's own settings (window layout).
if (line == "# Dear ImGui")
{
std::getline(file, imguiData, '\0');
break;
}
auto eq = line.find('=');
if (eq == std::string::npos)
@@ -278,55 +282,6 @@ Settings::Settings(const std::filesystem::path& path)
*scale = std::clamp(*scale < min ? unit_to_percent(*scale) : *scale, min, max);
}
std::string Settings::imgui_data_load(const std::filesystem::path& path)
{
auto pathUtf8 = path_to_utf8(path);
std::string fileData;
if (!file_text_load(path, &fileData, "rb"))
{
logger.error(
std::format("Failed to open settings file for Dear ImGui data: {}; using Dear ImGui defaults", pathUtf8));
return {};
}
std::istringstream file(fileData);
std::string line;
std::ostringstream dataStream;
bool isImGuiSection = false;
bool isContent = false;
while (std::getline(file, line))
{
if (!isImGuiSection)
{
if (line == "# Dear ImGui")
isImGuiSection = true;
continue;
}
if (isContent)
dataStream << "\n";
dataStream << line;
isContent = true;
}
if (!isImGuiSection)
{
logger.warning(
std::format("Dear ImGui section missing from settings file: {}; using Dear ImGui defaults", pathUtf8));
return {};
}
if (!isContent)
{
logger.warning(
std::format("Dear ImGui section empty in settings file: {}; using Dear ImGui defaults", pathUtf8));
return {};
}
return dataStream.str();
}
void Settings::save(const std::filesystem::path& path, const std::string& imguiData)
{
auto pathUtf8 = path_to_utf8(path);