45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
use std::fs;
|
|||
|
|
use std::path::PathBuf;
|
||
|
|
use crate::notification::NotificationData;
|
||
|
|
use crate::notification::NotificationData::PermissionDenied;
|
||
|
|
|
||
|
|
pub fn app_data_dir() -> PathBuf {
|
||
|
|
let mut dir = dirs::data_dir().unwrap();
|
||
|
|
dir.push("jap_learn");
|
||
|
|
if !dir.exists() {
|
||
|
|
fs::create_dir_all(dir.clone()).unwrap();
|
||
|
|
}
|
||
|
|
|
||
|
|
dir
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn db_path() -> PathBuf {
|
||
|
|
app_data_dir().join("data.db")
|
||
|
|
}
|
||
|
|
pub fn temp_db_path() -> PathBuf {
|
||
|
|
app_data_dir().join("data.db.tmp")
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn temp_import_path() -> PathBuf {
|
||
|
|
app_data_dir().join("import")
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn db_meta_path() -> PathBuf {
|
||
|
|
app_data_dir().join("data.meta")
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn history_dir() -> Result<PathBuf, NotificationData> {
|
||
|
|
let directory = app_data_dir().join("history");
|
||
|
|
if !directory.exists() {
|
||
|
|
fs::create_dir_all(directory.clone()).map_err(|_| PermissionDenied)?;
|
||
|
|
}
|
||
|
|
Ok(directory)
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn voice_dir() -> Result<PathBuf, NotificationData> {
|
||
|
|
let directory = app_data_dir().join("voice");
|
||
|
|
if !directory.exists() {
|
||
|
|
fs::create_dir_all(directory.clone()).map_err(|_| PermissionDenied)?;
|
||
|
|
}
|
||
|
|
Ok(directory)
|
||
|
|
}
|