1
0
mirror of synced 2024-11-24 15:50:16 +01:00

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

@ -68,6 +68,7 @@ namespace hex {
void load();
void store();
void clear();
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, i64 defaultValue, const Callback &callback, bool requiresRestart = false);
void add(const std::string &unlocalizedCategory, const std::string &unlocalizedName, const std::string &defaultValue, const Callback &callback, bool requiresRestart = false);

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();

View File

@ -282,6 +282,10 @@ namespace hex::init {
ContentRegistry::Settings::load();
} catch (std::exception &e) {
log::error("Failed to load configuration! {}", e.what());
ContentRegistry::Settings::clear();
ContentRegistry::Settings::store();
return false;
}