move outfly.toml to src/data/

main
hut 2024-04-30 23:24:38 +02:00
parent 00ce509935
commit c56ae18f5a
2 changed files with 18 additions and 13 deletions

View File

@ -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,
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();
}
}
}
None => {
warn!("Found no preference file, using default preferences.");
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();
(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;
}