move outfly.toml to src/data/
This commit is contained in:
parent
00ce509935
commit
c56ae18f5a
31
src/var.rs
31
src/var.rs
|
@ -76,27 +76,32 @@ fn get_prefs_path() -> Option<String> {
|
|||
}
|
||||
|
||||
pub fn load_prefs() -> Preferences {
|
||||
let prefs_path = match get_prefs_path() {
|
||||
Some(path) => path,
|
||||
None => {
|
||||
warn!("Found no preference file, using default preferences.");
|
||||
let (toml, path) = match get_prefs_path() {
|
||||
Some(path) => {
|
||||
let toml = fs::read_to_string(&path);
|
||||
match toml {
|
||||
Ok(toml) => (toml, Some(path)),
|
||||
Err(error) => {
|
||||
error!("Failed to open preferences file '{path}': {error}");
|
||||
return Preferences::default();
|
||||
}
|
||||
};
|
||||
let toml = fs::read_to_string(&prefs_path);
|
||||
let toml = match toml {
|
||||
Ok(toml) => toml,
|
||||
Err(error) => {
|
||||
error!("Failed to open preferences file '{prefs_path}': {error}");
|
||||
return Preferences::default();
|
||||
}
|
||||
}
|
||||
None => {
|
||||
warn!("Found no preference file, using default preferences.");
|
||||
(include_str!("data/outfly.toml").to_string(), None)
|
||||
}
|
||||
};
|
||||
match toml.parse::<DocumentMut>() {
|
||||
Ok(doc) => {
|
||||
match toml_edit::de::from_document::<Preferences>(doc) {
|
||||
Ok(mut pref) => {
|
||||
info!("Loaded preference file from {prefs_path}");
|
||||
pref.source_file = Some(prefs_path);
|
||||
if let Some(path) = &path {
|
||||
info!("Loaded preference file from {path}");
|
||||
} else {
|
||||
info!("Loaded preferences from internal defaults");
|
||||
}
|
||||
pref.source_file = path;
|
||||
dbg!(&pref);
|
||||
return pref;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue