Locate data dir on Linux and Windows
This commit is contained in:
parent
a132a9bcdf
commit
c80325ea40
8 changed files with 77 additions and 32 deletions
7
gdn/src/lib.rs
Normal file
7
gdn/src/lib.rs
Normal 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
27
gdn/src/paths.rs
Normal 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"))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue