sys: Reset settings if it cannot be parsed anymore
This commit is contained in:
parent
5c3a0cc654
commit
24c243bcf6
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user