diff options
Diffstat (limited to 'src/database.rs')
-rwxr-xr-x | src/database.rs | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/database.rs b/src/database.rs index 1f7b762..589ff2d 100755 --- a/src/database.rs +++ b/src/database.rs @@ -27,6 +27,7 @@ use std::path::PathBuf; use std::time::Duration; use crate::ui::FurtheranceWindow; +use crate::settings_manager; #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct Task { @@ -121,12 +122,26 @@ impl TaskSort { } pub fn get_directory() -> PathBuf { - if let Some(proj_dirs) = ProjectDirs::from("com", "lakoliu", "Furtherance") { - let mut path = PathBuf::from(proj_dirs.data_dir()); - create_dir_all(path.clone()).expect("Unable to create database directory"); - path.extend(&["furtherance.db"]); - return path; + let dir_from_settings = settings_manager::get_string("database-loc"); + + if dir_from_settings != "default" && PathBuf::from(dir_from_settings.clone()).exists() { + return PathBuf::from(dir_from_settings); + } else { + if let Some(proj_dirs) = ProjectDirs::from("com", "lakoliu", "Furtherance") { + let mut path = PathBuf::from(proj_dirs.data_dir()); + create_dir_all(path.clone()).expect("Unable to create database directory"); + path.extend(&["furtherance.db"]); + + let path_str = path.to_string_lossy().to_string(); + if path_str != dir_from_settings { + let settings = settings_manager::get_settings(); + let _ = settings.set_string("database-loc", &path_str); + } + + return path; + } } + PathBuf::new() } |