blob: 96a4225f90a86bdb052767441ac2fc5eca04ed9a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#[cfg(any(windows, target_os = "macos"))]
extern crate dirs;
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate log;
use std::fs;
use std::path::PathBuf;
error_chain! {
errors {
CreateDirFailed(path: PathBuf) {
description("Failed to create directory")
display("Failed to create directory {}", path.display())
}
#[cfg(any(windows, target_os = "macos"))]
FindDirError { description("Not able to find requested directory" )}
#[cfg(windows)]
NoProgramDataDir { description("Missing %ALLUSERSPROFILE% environment variable") }
}
}
#[cfg(unix)]
const PRODUCT_NAME: &str = "mullvad-vpn";
#[cfg(windows)]
const PRODUCT_NAME: &str = "Mullvad VPN";
#[cfg(windows)]
fn get_allusersprofile_dir() -> Result<PathBuf> {
match std::env::var_os("ALLUSERSPROFILE") {
Some(dir) => Ok(PathBuf::from(&dir)),
None => bail!(ErrorKind::NoProgramDataDir),
}
}
fn create_and_return(dir_fn: fn() -> Result<PathBuf>) -> Result<PathBuf> {
let dir = dir_fn()?;
fs::create_dir_all(&dir).chain_err(|| ErrorKind::CreateDirFailed(dir.clone()))?;
Ok(dir)
}
mod cache;
pub use cache::cache_dir;
mod logs;
pub use logs::{get_log_dir, log_dir};
pub mod resources;
pub use resources::get_resource_dir;
mod rpc_socket;
pub use rpc_socket::get_rpc_socket_path;
mod settings;
pub use settings::settings_dir;
|