diff options
Diffstat (limited to 'src/utils.rs')
-rw-r--r-- | src/utils.rs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/utils.rs b/src/utils.rs index 1d56377..e6ec6ac 100644 --- a/src/utils.rs +++ b/src/utils.rs | |||
@@ -34,13 +34,23 @@ pub fn load_configuration_file() -> AppConfig { | |||
34 | }; | 34 | }; |
35 | } | 35 | } |
36 | 36 | ||
37 | pub fn data_file() -> PathBuf { | 37 | fn project_dirs() -> ProjectDirs { |
38 | if let Some(proj_dirs) = ProjectDirs::from("rs", "nerdypepper", "dijo") { | 38 | ProjectDirs::from("rs", "nerdypepper", "dijo") |
39 | let mut data_file = PathBuf::from(proj_dirs.data_dir()); | 39 | .unwrap_or_else(|| panic!("Invalid home directory!")) |
40 | fs::create_dir_all(&data_file); | 40 | } |
41 | data_file.push("habit_record.json"); | 41 | |
42 | return data_file; | 42 | pub fn habit_file() -> PathBuf { |
43 | } else { | 43 | let proj_dirs = project_dirs(); |
44 | panic!("Invalid home directory!") | 44 | let mut data_file = PathBuf::from(proj_dirs.data_dir()); |
45 | }; | 45 | fs::create_dir_all(&data_file); |
46 | data_file.push("habit_record.json"); | ||
47 | return data_file; | ||
48 | } | ||
49 | |||
50 | pub fn auto_habit_file() -> PathBuf { | ||
51 | let proj_dirs = project_dirs(); | ||
52 | let mut data_file = PathBuf::from(proj_dirs.data_dir()); | ||
53 | fs::create_dir_all(&data_file); | ||
54 | data_file.push("habit_record[auto].json"); | ||
55 | return data_file; | ||
46 | } | 56 | } |