diff options
author | Rahul Sharma <rsconceptx@gmail.com> | 2016-04-04 17:46:35 +0530 |
---|---|---|
committer | Rahul Sharma <rsconceptx@gmail.com> | 2016-05-25 10:55:07 +0530 |
commit | b4885fef9a88474737f46b43021acc5800b5cf08 (patch) | |
tree | e28a7c0f4d17201de5d18110e1435681f25ef232 /components/util/prefs.rs | |
parent | aa9f50a1d406e72d8b443f79439aaf9fd2ba4425 (diff) | |
download | servo-b4885fef9a88474737f46b43021acc5800b5cf08.tar.gz servo-b4885fef9a88474737f46b43021acc5800b5cf08.zip |
adding default config dirs
Diffstat (limited to 'components/util/prefs.rs')
-rw-r--r-- | components/util/prefs.rs | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/components/util/prefs.rs b/components/util/prefs.rs index 43286f2137f..3d4492dd8f7 100644 --- a/components/util/prefs.rs +++ b/components/util/prefs.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use basedir::default_config_dir; use opts; use resource_files::resources_dir_path; use rustc_serialize::json::{Json, ToJson}; @@ -166,20 +167,32 @@ pub fn extend_prefs(extension: HashMap<String, Pref>) { } pub fn add_user_prefs() { - if let Some(ref dir) = opts::get().profile_dir { - let mut path = PathBuf::from(dir); - path.push("prefs.json"); - if let Ok(file) = File::open(path) { - if let Ok(prefs) = read_prefs_from_file(file) { - extend_prefs(prefs); + match opts::get().config_dir { + Some(ref config_path) => { + let mut path = PathBuf::from(config_path); + init_user_prefs(&mut path); + } + None => { + let mut path = default_config_dir().unwrap(); + if path.join("prefs.json").exists() { + init_user_prefs(&mut path); } - } else { - writeln!(&mut stderr(), "Error opening prefs.json from profile_dir") - .expect("failed printing to stderr"); } } } +fn init_user_prefs(path: &mut PathBuf) { + path.push("prefs.json"); + if let Ok(file) = File::open(path) { + if let Ok(prefs) = read_prefs_from_file(file) { + extend_prefs(prefs); + } + } else { + writeln!(&mut stderr(), "Error opening prefs.json from config directory") + .expect("failed printing to stderr"); + } +} + fn read_prefs() -> Result<HashMap<String, Pref>, ()> { let mut path = resources_dir_path(); path.push("prefs.json"); |