move config to separate folder

this requires the previous config file to be deleted, as it has the same name of
the folder.
This commit is contained in:
Henrik Friedrichsen
2019-03-26 19:05:02 +01:00
parent cb753ea073
commit 3892ac07d0
2 changed files with 16 additions and 11 deletions

View File

@@ -80,7 +80,7 @@ username = "spotify_user"
password = "spotify_password" password = "spotify_password"
``` ```
Please save it to `~/.config/ncspot`. Please save it to `~/.config/ncspot/config.toml`.
### Theming ### Theming

View File

@@ -34,24 +34,29 @@ pub struct ConfigTheme {
pub cmdline_bg: Option<String>, pub cmdline_bg: Option<String>,
} }
fn proj_dirs () -> ProjectDirs {
ProjectDirs::from("org", "affekt", "ncspot").expect("can't determine project paths")
}
pub fn config_path() -> PathBuf { pub fn config_path() -> PathBuf {
let dirs = directories::BaseDirs::new().expect("can't determine config path"); let proj_dirs = proj_dirs();
PathBuf::from(format!( let cfg_dir = proj_dirs.config_dir();
"{0}/ncspot", trace!("{:?}", cfg_dir);
dirs.config_dir() if !cfg_dir.exists() || !cfg_dir.is_dir() {
.to_str() fs::create_dir(cfg_dir).expect("can't create config folder");
.expect("can't convert path to string") }
)) let mut cfg = cfg_dir.to_path_buf();
cfg.push("config.toml");
cfg
} }
pub fn cache_path() -> PathBuf { pub fn cache_path() -> PathBuf {
let proj_dirs = let proj_dirs = proj_dirs();
ProjectDirs::from("org", "affekt", "ncspot").expect("can't determine project paths");
let cache_dir = proj_dirs.cache_dir(); let cache_dir = proj_dirs.cache_dir();
if !cache_dir.exists() { if !cache_dir.exists() {
fs::create_dir(cache_dir).expect("can't create cache folder"); fs::create_dir(cache_dir).expect("can't create cache folder");
} }
let mut pb = proj_dirs.cache_dir().to_path_buf(); let mut pb = cache_dir.to_path_buf();
pb.push("playlists.db"); pb.push("playlists.db");
pb pb
} }