summaryrefslogtreecommitdiffhomepage
path: root/mullvad-paths/src/resources.rs
blob: ed6845bdf08fe1ab4beedadbe242f3602a412223 (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
use std::{env, path::PathBuf};

pub fn get_resource_dir() -> PathBuf {
    match env::var_os("MULLVAD_RESOURCE_DIR") {
        Some(path) => PathBuf::from(path),
        None => get_default_resource_dir(),
    }
}

pub fn get_default_resource_dir() -> PathBuf {
    #[cfg(not(target_os = "android"))]
    {
        match env::current_exe() {
            Ok(mut path) => {
                path.pop();
                path
            }
            Err(e) => {
                log::error!(
                    "Failed finding the install directory. Using working directory: {}",
                    e
                );
                PathBuf::from(".")
            }
        }
    }
    #[cfg(target_os = "android")]
    {
        PathBuf::from(crate::APP_PATH)
    }
}