mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add code path for invalid settings file
This commit is contained in:
parent
c423cabbc6
commit
57eb3b2de4
@ -233,13 +233,26 @@ impl Default for Settings {
|
||||
impl Settings {
|
||||
pub fn load() -> Self {
|
||||
let path = Settings::get_settings_path();
|
||||
|
||||
// If file doesn't exist, use the default settings.
|
||||
if let Ok(file) = fs::File::open(path) {
|
||||
ron::de::from_reader(file).expect("Error parsing settings")
|
||||
} else {
|
||||
Self::default()
|
||||
|
||||
if let Ok(file) = fs::File::open(&path) {
|
||||
match ron::de::from_reader(file) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
log::warn!("Failed to parse setting file! Fallback to default. {}", e);
|
||||
// Rename the corrupted settings file
|
||||
let mut new_path = path.to_owned();
|
||||
new_path.pop();
|
||||
new_path.push("settings.invalid.ron");
|
||||
if let Err(err) = std::fs::rename(path, new_path) {
|
||||
log::warn!("Failed to rename settings file. {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let default_settings = Self::default();
|
||||
default_settings.save_to_file_warn();
|
||||
default_settings
|
||||
|
||||
}
|
||||
|
||||
pub fn save_to_file_warn(&self) {
|
||||
|
Loading…
Reference in New Issue
Block a user