move from xdg crate to cross-platform directories crate

closes #38
This commit is contained in:
Henrik Friedrichsen
2019-03-20 23:37:56 +01:00
parent 2b45778196
commit cdf63ba9ac
4 changed files with 58 additions and 39 deletions

View File

@@ -1,4 +1,8 @@
use std::collections::HashMap;
use std::fs;
use std::path::PathBuf;
use directories::ProjectDirs;
pub const CLIENT_ID: &str = "d420a117a32841c2b3474932e49fb54b";
@@ -8,3 +12,25 @@ pub struct Config {
pub password: String,
pub keybindings: Option<HashMap<String, String>>,
}
pub fn config_path() -> PathBuf {
let dirs = directories::BaseDirs::new().expect("can't determine config path");
PathBuf::from(format!(
"{0}/ncspot",
dirs.config_dir()
.to_str()
.expect("can't convert path to string")
))
}
pub fn cache_path() -> PathBuf {
let proj_dirs =
ProjectDirs::from("org", "affekt", "ncspot").expect("can't determine project paths");
let cache_dir = proj_dirs.cache_dir();
if !cache_dir.exists() {
fs::create_dir(cache_dir).expect("can't create cache folder");
}
let mut pb = proj_dirs.cache_dir().to_path_buf();
pb.push("playlists.db");
pb
}