move outfly.toml to src/data/

This commit is contained in:
yuni 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 { pub fn load_prefs() -> Preferences {
let prefs_path = match get_prefs_path() { let (toml, path) = match get_prefs_path() {
Some(path) => path, Some(path) => {
None => { let toml = fs::read_to_string(&path);
warn!("Found no preference file, using default preferences."); match toml {
Ok(toml) => (toml, Some(path)),
Err(error) => {
error!("Failed to open preferences file '{path}': {error}");
return Preferences::default(); return Preferences::default();
} }
}; }
let toml = fs::read_to_string(&prefs_path); }
let toml = match toml { None => {
Ok(toml) => toml, warn!("Found no preference file, using default preferences.");
Err(error) => { (include_str!("data/outfly.toml").to_string(), None)
error!("Failed to open preferences file '{prefs_path}': {error}");
return Preferences::default();
} }
}; };
match toml.parse::<DocumentMut>() { match toml.parse::<DocumentMut>() {
Ok(doc) => { Ok(doc) => {
match toml_edit::de::from_document::<Preferences>(doc) { match toml_edit::de::from_document::<Preferences>(doc) {
Ok(mut pref) => { Ok(mut pref) => {
info!("Loaded preference file from {prefs_path}"); if let Some(path) = &path {
pref.source_file = Some(prefs_path); info!("Loaded preference file from {path}");
} else {
info!("Loaded preferences from internal defaults");
}
pref.source_file = path;
dbg!(&pref); dbg!(&pref);
return pref; return pref;
} }