Locate data dir on Linux and Windows

This commit is contained in:
Joscha 2025-01-25 12:01:21 +01:00
parent a132a9bcdf
commit c80325ea40
8 changed files with 77 additions and 32 deletions

10
gdn/Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[package]
name = "gdn"
version = { workspace = true }
edition = { workspace = true }
[dependencies]
directories.workspace = true
[lints]
workspace = true

7
gdn/src/lib.rs Normal file
View file

@ -0,0 +1,7 @@
mod paths;
pub use crate::paths::Paths;
pub const PROPER_NAME: &str = "GedächtNAS";
pub const TECHNICAL_NAME: &str = "gedaechtnas";
pub const ABBREVIATED_NAME: &str = "gdn";

27
gdn/src/paths.rs Normal file
View file

@ -0,0 +1,27 @@
use std::path::PathBuf;
use directories::ProjectDirs;
pub struct Paths(ProjectDirs);
impl Paths {
pub fn on_linux() -> Option<Self> {
ProjectDirs::from("de", "plugh", crate::TECHNICAL_NAME).map(Self)
}
pub fn on_windows() -> Option<Self> {
ProjectDirs::from("de", "plugh", crate::PROPER_NAME).map(Self)
}
pub fn state_file(&self) -> PathBuf {
self.0.data_local_dir().join("state.json")
}
pub fn repos_dir(&self) -> PathBuf {
self.0.data_local_dir().join("repos")
}
pub fn repo_dir(&self, name: &str) -> PathBuf {
self.repos_dir().join(format!("{name}.git"))
}
}