diff options
| author | 2025-01-21 19:10:44 -0600 | |
|---|---|---|
| committer | 2025-01-21 19:10:44 -0600 | |
| commit | 601586bc1263cb0e746181f8750a443ab0d4aaf1 (patch) | |
| tree | 136b33558a29e26be9b68335d69a010c9f8e4777 /src/launcher.rs | |
| parent | use regular strings for jvm arguments (diff) | |
support jre specified in profile
Diffstat (limited to 'src/launcher.rs')
| -rw-r--r-- | src/launcher.rs | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/src/launcher.rs b/src/launcher.rs index 40d9742..f8be78b 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -22,7 +22,7 @@ use std::env::JoinPathsError; use std::time::{Instant, SystemTime, UNIX_EPOCH}; use const_format::formatcp; use futures::{StreamExt, TryStreamExt}; -use log::{debug, info, warn}; +use log::{debug, info, trace, warn}; use reqwest::Client; use sha1_smol::Sha1; use sysinfo::System; @@ -137,7 +137,11 @@ pub enum LaunchError { InvalidLogId(Option<String>), // asset errors - Assets(AssetError) + Assets(AssetError), + + // java runtime errors + ResolveJavaRuntime { what: &'static str, error: io::Error }, + MissingJavaRuntime } impl Display for LaunchError { @@ -162,7 +166,9 @@ impl Display for LaunchError { LaunchError::UnknownLogType(t) => write!(f, "unknown log type: {}", t), LaunchError::InvalidLogId(Some(id)) => write!(f, "invalid log id: {}", id), LaunchError::InvalidLogId(None) => write!(f, "missing log id"), - LaunchError::Assets(e) => write!(f, "failed to fetch assets: {}", e) + LaunchError::Assets(e) => write!(f, "failed to fetch assets: {}", e), + LaunchError::ResolveJavaRuntime { what, error } => write!(f, "failed to find java runtime ({}): {}", what, error), + LaunchError::MissingJavaRuntime => f.write_str("suitable java executable not found") } } } @@ -181,6 +187,7 @@ impl Error for LaunchError { LaunchError::Download { error: e, .. } => Some(e), LaunchError::Integrity(e) => Some(e), LaunchError::Assets(e) => Some(e), + LaunchError::ResolveJavaRuntime { error: e, .. } => Some(e), _ => None } } @@ -206,7 +213,9 @@ pub struct Launch { jvm_args: Vec<OsString>, game_args: Vec<OsString>, main_class: String, - instance_path: PathBuf + instance_path: PathBuf, + runtime_path: PathBuf, + runtime_legacy_launch: bool } struct ProfileFeatureMatcher<'prof> { @@ -560,7 +569,17 @@ impl Launcher { os.to_string_lossy().to_string() }); - info!("Classpath: {classpath}"); + trace!("Classpath: {classpath}"); + + info!("Resolving java runtime environment path"); + let runtime_path = fs::canonicalize(profile.get_java_runtime().expect("downloading JREs is not supported yet")).await + .map_err(|e| LaunchError::ResolveJavaRuntime {what: "resolving jre path", error: e})?; + let Some(runtime_exe_path) = runner::find_java(runtime_path.as_path(), profile.is_legacy_launch()).await + .map_err(|e| LaunchError::ResolveJavaRuntime {what: "finding java executable", error: e})? else { + return Err(LaunchError::MissingJavaRuntime); + }; + + debug!("Found runtime exe: {}", runtime_exe_path.display()); info!("Deriving launch arguments"); let info = LaunchInfo { @@ -593,7 +612,9 @@ impl Launcher { jvm_args, game_args, main_class: main_class.to_string(), - instance_path: inst_home + instance_path: inst_home, + runtime_path: runtime_exe_path, + runtime_legacy_launch: profile.is_legacy_launch() }) } } |
