sys: Reset settings if it cannot be parsed anymore

This commit is contained in:
WerWolv
2022-07-30 11:19:56 +02:00
parent 5c3a0cc654
commit 24c243bcf6
3 changed files with 15 additions and 2 deletions

View File

@@ -14,10 +14,12 @@ namespace hex {
namespace ContentRegistry::Settings {
constexpr auto SettingsFile = "settings.json";
void load() {
bool loaded = false;
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) {
std::ifstream settingsFile(dir / "settings.json");
std::ifstream settingsFile(dir / SettingsFile);
if (settingsFile.good()) {
settingsFile >> getSettingsData();
@@ -32,7 +34,7 @@ namespace hex {
void store() {
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) {
std::ofstream settingsFile(dir / "settings.json", std::ios::trunc);
std::ofstream settingsFile(dir / SettingsFile, std::ios::trunc);
if (settingsFile.good()) {
settingsFile << getSettingsData();
@@ -41,6 +43,12 @@ namespace hex {
}
}
void clear() {
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Config)) {
hex::fs::remove(dir / SettingsFile);
}
}
static auto getCategoryEntry(const std::string &unlocalizedCategory) {
auto &entries = getEntries();
const size_t curSlot = entries.size();