about summary refs log tree commit diff
path: root/src/database.rs
diff options
context:
space:
mode:
authorRicky Kresslein <rk@lakoliu.com>2022-09-24 00:34:54 +0200
committerRicky Kresslein <rk@lakoliu.com>2022-09-24 00:34:54 +0200
commit87c05770789958e6786e6490eb1fa25cd116b361 (patch)
tree959c6344c99a0f85657759fd21618dff2e9673a1 /src/database.rs
parent54e7ba5b16045d4e653f392d38f045a4f7183732 (diff)
downloadFurtherance-87c05770789958e6786e6490eb1fa25cd116b361.tar.zst
Ability to change database location - #29
Diffstat (limited to 'src/database.rs')
-rwxr-xr-xsrc/database.rs25
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()
 }