From b1e93fda4bac454f3e0201bb8ab1d18b2aaf9c1f Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 9 Aug 2022 09:39:04 +0200 Subject: [PATCH] sys: Format settings file more prettily --- lib/libimhex/source/api/content_registry.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index d97c8d51b..c7201bd5f 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -21,10 +22,10 @@ namespace hex { void load() { bool loaded = false; for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) { - std::ifstream settingsFile(dir / SettingsFile); + fs::File file(dir / SettingsFile, fs::File::Mode::Read); - if (settingsFile.good()) { - settingsFile >> getSettingsData(); + if (file.isValid()) { + getSettingsData() = nlohmann::json::parse(file.readString()); loaded = true; break; } @@ -36,10 +37,10 @@ namespace hex { void store() { for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) { - std::ofstream settingsFile(dir / SettingsFile, std::ios::trunc); + fs::File file(dir / SettingsFile, fs::File::Mode::Create); - if (settingsFile.good()) { - settingsFile << getSettingsData(); + if (file.isValid()) { + file.write(getSettingsData().dump(4)); break; } }