mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
adding default config dirs
This commit is contained in:
parent
aa9f50a1d4
commit
b4885fef9a
13 changed files with 171 additions and 45 deletions
|
@ -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,17 +167,29 @@ 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);
|
||||
}
|
||||
} else {
|
||||
writeln!(&mut stderr(), "Error opening prefs.json from profile_dir")
|
||||
.expect("failed printing to stderr");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue