[Config] Gracefully handle type mismatches in cvars.
Detect cvar type mismatch and reset to default value, as well as show message to the user that the cvar from the config has been updated.
This commit is contained in:
committed by
Radosław Gliński
parent
70e44ab6ec
commit
93adb2bb95
@@ -16,6 +16,7 @@
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/string.h"
|
||||
#include "xenia/base/string_buffer.h"
|
||||
#include "xenia/base/system.h"
|
||||
|
||||
toml::parse_result ParseFile(const std::filesystem::path& filename) {
|
||||
return toml::parse_file(xe::path_to_utf8(filename));
|
||||
@@ -118,6 +119,26 @@ void ReadConfig(const std::filesystem::path& file_path,
|
||||
cvar::IConfigVarUpdate::ApplyUpdates(config_defaults_date);
|
||||
}
|
||||
|
||||
// Check for type mismatch warnings
|
||||
if (cvar::config_type_mismatch_warnings &&
|
||||
!cvar::config_type_mismatch_warnings->empty()) {
|
||||
std::string warning_message =
|
||||
"The following config values had invalid types and have been reset to "
|
||||
"defaults:\n\n";
|
||||
for (const auto& name : *cvar::config_type_mismatch_warnings) {
|
||||
warning_message += " - " + name + "\n";
|
||||
}
|
||||
warning_message +=
|
||||
"\nPlease check your config file. The config will be saved with the "
|
||||
"correct types.";
|
||||
|
||||
xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Warning,
|
||||
warning_message);
|
||||
|
||||
// Clear warnings
|
||||
cvar::config_type_mismatch_warnings->clear();
|
||||
}
|
||||
|
||||
XELOGI("Loaded config: {}", file_path);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user