1use std::{fs, path::PathBuf};
2
3use anyhow::Result;
4
5pub struct OxidePaths {
6 pub home: PathBuf,
7 pub config: PathBuf,
8 pub cache: PathBuf,
9 pub templates: PathBuf,
10 pub auth: PathBuf,
11 pub addons: PathBuf,
12 pub addons_index: PathBuf,
13}
14
15impl OxidePaths {
16 pub fn new() -> Result<Self> {
17 let home_dir =
18 dirs::home_dir().ok_or_else(|| anyhow::anyhow!("Could not find home directory"))?;
19
20 let oxide_home = home_dir.join(".oxide");
21
22 Ok(Self {
23 home: oxide_home.clone(),
24 config: oxide_home.join("config.json"),
25 cache: oxide_home.join("cache"),
26 templates: oxide_home.join("cache").join("templates"),
27 auth: oxide_home.join("auth.json"),
28 addons: oxide_home.join("cache").join("addons"),
29 addons_index: oxide_home.join("cache").join("addons").join("oxide-addons.json"),
30 })
31 }
32
33 pub fn ensure_directories(&self) -> Result<()> {
34 fs::create_dir_all(&self.home)?;
35 fs::create_dir_all(&self.cache)?;
36 fs::create_dir_all(&self.templates)?;
37 fs::create_dir_all(&self.addons)?;
38 Ok(())
39 }
40}