fix: locate assets more reliably

This commit is contained in:
Songtronix 2020-08-19 08:52:14 +02:00
parent e09c1a87aa
commit 1067e679ee

View File

@ -280,23 +280,14 @@ lazy_static! {
pub static ref ASSETS_PATH: PathBuf = {
let mut paths = Vec::new();
// VELOREN_ASSETS environment variable
// Note: Ordering matters here!
// 1. VELOREN_ASSETS environment variable
if let Ok(var) = std::env::var("VELOREN_ASSETS") {
paths.push(var.into());
}
// Executable path
if let Ok(mut path) = std::env::current_exe() {
path.pop();
paths.push(path);
}
// Working path
if let Ok(path) = std::env::current_dir() {
paths.push(path);
}
// System paths
// 2. System paths
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
{
if let Ok(result) = std::env::var("XDG_DATA_HOME") {
@ -316,6 +307,17 @@ lazy_static! {
}
}
// 3. Executable path
if let Ok(mut path) = std::env::current_exe() {
path.pop();
paths.push(path);
}
// 4. Working path
if let Ok(path) = std::env::current_dir() {
paths.push(path);
}
tracing::trace!("Possible asset locations paths={:?}", paths);
for path in paths.clone() {
@ -324,7 +326,7 @@ lazy_static! {
.for_folder("assets")
{
Ok(assets_path) => {
tracing::info!("Assets located path={}", assets_path.display());
tracing::info!("Assets found path={}", assets_path.display());
return assets_path;
},
Err(_) => continue,