1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
extern crate xdg;
use AppDataType::*;
use common::*;
use self::xdg::BaseDirectories as Xdg;
use std::path::PathBuf;
pub const USE_AUTHOR: bool = false;
pub fn get_app_dir(t: AppDataType) -> Result<PathBuf, AppDirsError> {
Xdg::new()
.ok()
.as_ref()
.and_then(|x| match t {
UserConfig => Some(x.get_config_home()),
UserData => Some(x.get_data_home()),
UserCache => Some(x.get_cache_home()),
SharedData => x.get_data_dirs().into_iter().next(),
SharedConfig => x.get_config_dirs().into_iter().next(),
})
.ok_or_else(|| AppDirsError::NotSupported)
}