1use std::{error::Error, path::PathBuf};
2
3use directories::ProjectDirs;
4
5pub fn get_data_directory(path: Option<&str>) -> Result<PathBuf, Box<dyn Error>> {
6 if let Some(project_directories) = ProjectDirs::from("com", "s9tpepper", "FerrisTwitch") {
7 let mut data_directory = project_directories.data_dir().to_path_buf();
8 if let Some(path) = path {
9 data_directory.push(path);
10 }
11
12 if !data_directory.exists() {
13 std::fs::create_dir_all(&data_directory)?;
14 }
15
16 return Ok(data_directory);
17 }
18
19 Err("Could not get data directory".into())
20}