From 7dc087fe9370eb72a9ce1ee6aa3e843f177d82cc Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Mon, 20 May 2019 15:32:16 -0600 Subject: [PATCH] Create config dir if needed Former-commit-id: 280e49f428207d5dc9a88607252df4b9f155d018 --- voxygen/src/settings.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 0fab421cd9..22950cb6d2 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -2,7 +2,7 @@ use config::{Config, ConfigError}; use directories::ProjectDirs; use glutin::VirtualKeyCode; use serde_derive::{Deserialize, Serialize}; -use std::{fs::File, io::prelude::*, path::PathBuf}; +use std::{fs, io::prelude::*, path::PathBuf}; use toml; /// `Settings` contains everything that can be configured in the Settings.toml file. @@ -124,7 +124,11 @@ impl Settings { pub fn save_to_file(&self) -> std::io::Result<()> { let path = Settings::get_settings_path(); - let mut config_file = File::create(path)?; + if let Some(dir) = path.parent() { + fs::create_dir_all(dir)?; + } + + let mut config_file = fs::File::create(path)?; let s: &str = &toml::to_string_pretty(self).unwrap(); config_file.write_all(s.as_bytes()).unwrap(); Ok(())