fix: allow UNIX systems to search for Java on PATH
This commit is contained in:
parent
3390110397
commit
6cbc0aaea8
2 changed files with 32 additions and 5 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use std::collections::HashMap;
|
||||
use std::path::{self, PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use async_zip::base::read::mem::ZipFileReader;
|
||||
use interpulse::api::minecraft::VersionInfo;
|
||||
|
|
@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
|
|||
use crate::api::ingress::{init_ingress, init_ingress_opt, send_ingress};
|
||||
use crate::error::LauncherResult;
|
||||
use crate::store::ingress::{IngressType, SubIngress};
|
||||
use crate::store::{Dirs, State};
|
||||
use crate::store::Dirs;
|
||||
use crate::utils::http::{fetch_advanced, fetch_json};
|
||||
use crate::utils::io::{self, IOError};
|
||||
|
||||
|
|
@ -94,7 +94,6 @@ pub async fn check_java_runtime(
|
|||
|
||||
io::write(&file, JAVA_INFO_CLASS).await?;
|
||||
id.map(async |id| send_ingress(id, 25.0).await);
|
||||
|
||||
let java_info = tokio::process::Command::new(absolute_path)
|
||||
.arg("-cp")
|
||||
.arg(dir.path())
|
||||
|
|
@ -194,6 +193,29 @@ pub async fn prepare_java(major: u32) -> LauncherResult<java_versions::Model> {
|
|||
Err(JavaError::MissingJava.into())
|
||||
}
|
||||
|
||||
// share the code that I stole from the windows one anyway to use in UNIX settings
|
||||
|
||||
#[cfg(unix)]
|
||||
fn find_java_in_path(mut found: Vec<PathBuf>) -> Vec<PathBuf> {
|
||||
if let Ok(path) = std::env::var("PATH") {
|
||||
for path_entry in path.split(':') {
|
||||
let java = PathBuf::from(path_entry).join("java");
|
||||
if java.exists() {
|
||||
if let Some(bin_dir) = java.parent() {
|
||||
if let Some(java_home) = bin_dir.parent() {
|
||||
let java_home_path = java_home.to_path_buf();
|
||||
// java executable should always be under bin/java of root
|
||||
let java_path = java_home_path.join("bin").join("java");
|
||||
if !found.contains(&java_path) {
|
||||
found.push(java_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
found
|
||||
}
|
||||
/// Attempts to scan common paths for Java installations.
|
||||
///
|
||||
/// **Can be heavy on I/O, don't run often!**
|
||||
|
|
@ -219,7 +241,6 @@ pub async fn locate_java() -> LauncherResult<HashMap<PathBuf, JavaInfo>> {
|
|||
tracing::warn!("java installation at '{}' is not valid", path.display());
|
||||
continue;
|
||||
};
|
||||
|
||||
valid.insert(path, info);
|
||||
}
|
||||
|
||||
|
|
@ -299,6 +320,9 @@ fn internal_locate_java() -> Vec<PathBuf> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
find_java_in_path(found);
|
||||
|
||||
found
|
||||
}
|
||||
|
||||
|
|
@ -333,6 +357,10 @@ fn internal_locate_java() -> Vec<PathBuf> {
|
|||
}
|
||||
}
|
||||
|
||||
// check env vars
|
||||
// woowoooo mutation
|
||||
let found = find_java_in_path(found);
|
||||
|
||||
found
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(let_chains)]
|
||||
#![feature(slice_as_array)]
|
||||
|
||||
use api::proxy::LauncherProxy;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue