Skip to content

Commit

Permalink
impr: Reorder achievement save routine to never accidentally clear th…
Browse files Browse the repository at this point in the history
…e file
  • Loading branch information
WerWolv committed Feb 19, 2024
1 parent ca35c90 commit a2ffac9
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/libimhex/source/api/achievement_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,26 +234,26 @@ namespace hex {
}

void AchievementManager::storeProgress() {
for (const auto &directory : fs::getDefaultPaths(fs::ImHexPath::Config)) {
auto path = directory / AchievementsFile;
nlohmann::json json;
for (const auto &[categoryName, achievements] : getAchievements()) {
json[categoryName] = nlohmann::json::object();

wolv::io::File file(path, wolv::io::File::Mode::Create);
if (!file.isValid()) {
continue;
for (const auto &[achievementName, achievement] : achievements) {
json[categoryName][achievementName] = achievement->getProgress();
}
}

nlohmann::json json;
if (json.empty())
return;

for (const auto &[categoryName, achievements] : getAchievements()) {
json[categoryName] = nlohmann::json::object();
for (const auto &directory : fs::getDefaultPaths(fs::ImHexPath::Config)) {
auto path = directory / AchievementsFile;

for (const auto &[achievementName, achievement] : achievements) {
json[categoryName][achievementName] = achievement->getProgress();
}
}
wolv::io::File file(path, wolv::io::File::Mode::Create);
if (!file.isValid())
continue;

const auto result = json.dump(4);
file.writeString(result);
file.writeString(json.dump(4));
break;
}
}
Expand Down

0 comments on commit a2ffac9

Please sign in to comment.