mirror of https://github.com/WerWolv/ImHex.git
impr: Reorder achievement save routine to never accidentally clear the file
This commit is contained in:
parent
ca35c90cbb
commit
a2ffac9424
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue