mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'songtronix/fix-assets-finding' into 'master'
fix: locate assets in hopefully all cases Closes #727 and #745 See merge request veloren/veloren!1347
This commit is contained in:
commit
5f350b2bea
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -4726,7 +4726,6 @@ dependencies = [
|
|||||||
"crossbeam",
|
"crossbeam",
|
||||||
"dot_vox",
|
"dot_vox",
|
||||||
"enum-iterator",
|
"enum-iterator",
|
||||||
"find_folder",
|
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
"image",
|
"image",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
|
@ -25,7 +25,6 @@ rand = "0.7"
|
|||||||
rayon = "1.3.0"
|
rayon = "1.3.0"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
hashbrown = { version = "0.7.2", features = ["rayon", "serde", "nightly"] }
|
hashbrown = { version = "0.7.2", features = ["rayon", "serde", "nightly"] }
|
||||||
find_folder = "0.3.0"
|
|
||||||
parking_lot = "0.9.0"
|
parking_lot = "0.9.0"
|
||||||
crossbeam = "0.7"
|
crossbeam = "0.7"
|
||||||
notify = "5.0.0-pre.3"
|
notify = "5.0.0-pre.3"
|
||||||
|
@ -337,6 +337,12 @@ where
|
|||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
/// Lazy static to find and cache where the asset directory is.
|
/// Lazy static to find and cache where the asset directory is.
|
||||||
|
/// Cases we need to account for:
|
||||||
|
/// 1. Running through airshipper (`assets` next to binary)
|
||||||
|
/// 2. Install with package manager and run (assets probably in `/usr/share/veloren/assets` while binary in `/usr/bin/`)
|
||||||
|
/// 3. Download & hopefully extract zip (`assets` next to binary)
|
||||||
|
/// 4. Running through cargo (`assets` in workspace root but not always in cwd incase you `cd voxygen && cargo r`)
|
||||||
|
/// 5. Running executable in the target dir (`assets` in workspace)
|
||||||
pub static ref ASSETS_PATH: PathBuf = {
|
pub static ref ASSETS_PATH: PathBuf = {
|
||||||
let mut paths = Vec::new();
|
let mut paths = Vec::new();
|
||||||
|
|
||||||
@ -347,49 +353,54 @@ lazy_static! {
|
|||||||
paths.push(var.into());
|
paths.push(var.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. System paths
|
// 2. Executable path
|
||||||
#[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") {
|
|
||||||
paths.push(format!("{}/veloren/assets", result).into());
|
|
||||||
} else if let Ok(result) = std::env::var("HOME") {
|
|
||||||
paths.push(format!("{}/.local/share/veloren/assets", result).into());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(result) = std::env::var("XDG_DATA_DIRS") {
|
|
||||||
result.split(':').for_each(|x| paths.push(format!("{}/veloren/assets", x).into()));
|
|
||||||
} else {
|
|
||||||
// Fallback
|
|
||||||
let fallback_paths = vec!["/usr/local/share", "/usr/share"];
|
|
||||||
for fallback_path in fallback_paths {
|
|
||||||
paths.push(format!("{}/veloren/assets", fallback_path).into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Executable path
|
|
||||||
if let Ok(mut path) = std::env::current_exe() {
|
if let Ok(mut path) = std::env::current_exe() {
|
||||||
path.pop();
|
path.pop();
|
||||||
paths.push(path);
|
paths.push(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Working path
|
// 3. Working path
|
||||||
if let Ok(path) = std::env::current_dir() {
|
if let Ok(path) = std::env::current_dir() {
|
||||||
paths.push(path);
|
paths.push(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4. Cargo Workspace (e.g. local development)
|
||||||
|
// https://github.com/rust-lang/cargo/issues/3946#issuecomment-359619839
|
||||||
|
if let Ok(Ok(path)) = std::env::var("CARGO_MANIFEST_DIR").map(|s| s.parse::<PathBuf>()) {
|
||||||
|
paths.push(path.parent().unwrap().to_path_buf());
|
||||||
|
paths.push(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 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") {
|
||||||
|
paths.push(format!("{}/veloren/", result).into());
|
||||||
|
} else if let Ok(result) = std::env::var("HOME") {
|
||||||
|
paths.push(format!("{}/.local/share/veloren/", result).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(result) = std::env::var("XDG_DATA_DIRS") {
|
||||||
|
result.split(':').for_each(|x| paths.push(format!("{}/veloren/", x).into()));
|
||||||
|
} else {
|
||||||
|
// Fallback
|
||||||
|
let fallback_paths = vec!["/usr/local/share", "/usr/share"];
|
||||||
|
for fallback_path in fallback_paths {
|
||||||
|
paths.push(format!("{}/veloren/", fallback_path).into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tracing::trace!("Possible asset locations paths={:?}", paths);
|
tracing::trace!("Possible asset locations paths={:?}", paths);
|
||||||
|
|
||||||
for path in paths.clone() {
|
for mut path in paths.clone() {
|
||||||
match find_folder::Search::ParentsThenKids(3, 1)
|
if !path.ends_with("assets") {
|
||||||
.of(path)
|
path = path.join("assets");
|
||||||
.for_folder("assets")
|
}
|
||||||
{
|
|
||||||
Ok(assets_path) => {
|
if path.is_dir() {
|
||||||
tracing::info!("Assets found path={}", assets_path.display());
|
tracing::info!("Assets found path={}", path.display());
|
||||||
return assets_path;
|
return path;
|
||||||
},
|
|
||||||
Err(_) => continue,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user