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,16 +234,7 @@ namespace hex {
}
void AchievementManager::storeProgress() {
for (const auto &directory : fs::getDefaultPaths(fs::ImHexPath::Config)) {
auto path = directory / AchievementsFile;
wolv::io::File file(path, wolv::io::File::Mode::Create);
if (!file.isValid()) {
continue;
}
nlohmann::json json;
for (const auto &[categoryName, achievements] : getAchievements()) {
json[categoryName] = nlohmann::json::object();
@ -252,8 +243,17 @@ namespace hex {
}
}
const auto result = json.dump(4);
file.writeString(result);
if (json.empty())
return;
for (const auto &directory : fs::getDefaultPaths(fs::ImHexPath::Config)) {
auto path = directory / AchievementsFile;
wolv::io::File file(path, wolv::io::File::Mode::Create);
if (!file.isValid())
continue;
file.writeString(json.dump(4));
break;
}
}