impr: Reorder achievement save routine to never accidentally clear the file

This commit is contained in:
WerWolv 2024-02-20 00:10:05 +01:00
parent ca35c90cbb
commit a2ffac9424
1 changed files with 14 additions and 14 deletions

View File

@ -234,26 +234,26 @@ namespace hex {
} }
void AchievementManager::storeProgress() { void AchievementManager::storeProgress() {
nlohmann::json json;
for (const auto &[categoryName, achievements] : getAchievements()) {
json[categoryName] = nlohmann::json::object();
for (const auto &[achievementName, achievement] : achievements) {
json[categoryName][achievementName] = achievement->getProgress();
}
}
if (json.empty())
return;
for (const auto &directory : fs::getDefaultPaths(fs::ImHexPath::Config)) { for (const auto &directory : fs::getDefaultPaths(fs::ImHexPath::Config)) {
auto path = directory / AchievementsFile; auto path = directory / AchievementsFile;
wolv::io::File file(path, wolv::io::File::Mode::Create); wolv::io::File file(path, wolv::io::File::Mode::Create);
if (!file.isValid()) { if (!file.isValid())
continue; continue;
}
nlohmann::json json; file.writeString(json.dump(4));
for (const auto &[categoryName, achievements] : getAchievements()) {
json[categoryName] = nlohmann::json::object();
for (const auto &[achievementName, achievement] : achievements) {
json[categoryName][achievementName] = achievement->getProgress();
}
}
const auto result = json.dump(4);
file.writeString(result);
break; break;
} }
} }