impr: Save data information view settings to projects

This commit is contained in:
WerWolv 2024-02-21 23:21:24 +01:00
parent 5ccb7a7b9a
commit 0a9dca5be7
1 changed files with 29 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/achievement_manager.hpp>
#include <hex/api/project_file_manager.hpp>
#include <hex/providers/provider.hpp>
@ -21,6 +22,34 @@ namespace hex::plugin::builtin {
data.informationSections.push_back(informationSectionConstructor());
}
});
ProjectFile::registerPerProviderHandler({
.basePath = "data_information.json",
.required = false,
.load = [this](prv::Provider *provider, const std::fs::path &basePath, const Tar &tar) {
std::string save = tar.readString(basePath);
nlohmann::json input = nlohmann::json::parse(save);
for (const auto &section : m_analysisData.get(provider).informationSections) {
if (!input.contains(section->getUnlocalizedName().get()))
continue;
section->load(input[section->getUnlocalizedName().get()]);
}
return true;
},
.store = [this](prv::Provider *provider, const std::fs::path &basePath, const Tar &tar) {
nlohmann::json output;
for (const auto &section : m_analysisData.get(provider).informationSections) {
output[section->getUnlocalizedName().get()] = section->store();
}
tar.writeString(basePath, output.dump(4));
return true;
}
});
}
void ViewInformation::analyze() {