summaryrefslogtreecommitdiffstats
path: root/src/launcher.rs
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2025-01-22 03:59:51 -0600
committerLibravatar bigfoot547 <[email protected]>2025-01-22 03:59:51 -0600
commit31207679094b378a2d4b35eb310f679960d6205f (patch)
tree2f750cf006ad1e5ff1bdaed908d7b6f621d018a9 /src/launcher.rs
parentget started on downloading JREs (diff)
wip: jre download stuff
Diffstat (limited to 'src/launcher.rs')
-rw-r--r--src/launcher.rs38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/launcher.rs b/src/launcher.rs
index 19a9fa7..d49556f 100644
--- a/src/launcher.rs
+++ b/src/launcher.rs
@@ -42,6 +42,7 @@ pub use crate::util::{EnsureFileError, FileVerifyError, IntegrityError};
use crate::assets::AssetIndex;
use runner::ArgumentType;
use strsub::SubFunc;
+use crate::launcher::jre::{JavaRuntimeError, JavaRuntimeRepository};
use crate::version::manifest::VersionType;
#[derive(Debug)]
@@ -103,7 +104,8 @@ pub struct Launcher {
system_info: SystemInfo,
libraries: LibraryRepository,
- assets: AssetRepository
+ assets: AssetRepository,
+ java_runtimes: JavaRuntimeRepository
}
#[derive(Debug)]
@@ -137,7 +139,8 @@ pub enum LaunchError {
// java runtime errors
ResolveJavaRuntime { what: &'static str, error: io::Error },
- MissingJavaRuntime
+ MissingJavaRuntime,
+ JavaRuntimeRepo(JavaRuntimeError)
}
impl Display for LaunchError {
@@ -161,7 +164,8 @@ impl Display for LaunchError {
LaunchError::InvalidLogId(None) => write!(f, "missing log id"),
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")
+ LaunchError::MissingJavaRuntime => f.write_str("suitable java executable not found"),
+ LaunchError::JavaRuntimeRepo(e) => write!(f, "runtime repository error: {e}")
}
}
}
@@ -180,6 +184,7 @@ impl Error for LaunchError {
LaunchError::EnsureFile(e) => Some(e),
LaunchError::Assets(e) => Some(e),
LaunchError::ResolveJavaRuntime { error: e, .. } => Some(e),
+ LaunchError::JavaRuntimeRepo(e) => Some(e),
_ => None
}
}
@@ -247,6 +252,8 @@ impl Launcher {
let assets_path = home.join("assets");
+ let java_runtimes = JavaRuntimeRepository::new(home.join("jre"), online).await.map_err(LaunchError::JavaRuntimeRepo)?;
+
Ok(Launcher {
online,
versions,
@@ -256,6 +263,7 @@ impl Launcher {
natives: home.join("natives")
},
assets: AssetRepository::new(online, &assets_path).await?,
+ java_runtimes,
home
})
}
@@ -288,7 +296,7 @@ impl Launcher {
debug!("Logger config {} is at {}", id, path.display());
- util::ensure_file(&path, dlinfo.url.as_ref().map(|s| s.as_str()), dlinfo.size, dlinfo.sha1, self.online).await
+ util::ensure_file(&path, dlinfo.url.as_ref().map(|s| s.as_str()), dlinfo.size, dlinfo.sha1, self.online, false).await
.map_err(|e| LaunchError::EnsureFile(e))?;
struct PathSub<'a>(&'a Path);
@@ -443,7 +451,7 @@ impl Launcher {
info!("Downloading client jar {}", client_path.display());
- util::ensure_file(client_path.as_path(), client.url.as_ref().map(|s| s.as_str()), client.size, client.sha1, self.online).await
+ util::ensure_file(client_path.as_path(), client.url.as_ref().map(|s| s.as_str()), client.size, client.sha1, self.online, false).await
.map_err(|e| LaunchError::EnsureFile(e))?;
client_jar_path = Some(client_path);
@@ -481,13 +489,29 @@ impl Launcher {
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 runtime_path;
+
+ if let Some(ref profile_jre) = profile.get_java_runtime() {
+ runtime_path = fs::canonicalize(profile_jre).await
+ .map_err(|e| LaunchError::ResolveJavaRuntime {what: "resolving jre path", error: e})?;
+ } else {
+ let Some(ref java_ver) = ver.java_version else {
+ warn!("Version {} does not specify java version information. You must select a runtime manually.", ver.id);
+ return Err(LaunchError::MissingJavaRuntime);
+ };
+
+ let runtime = self.java_runtimes.choose_runtime(java_ver.component.as_str()).await.map_err(LaunchError::JavaRuntimeRepo)?;
+ dbg!(runtime);
+
+ todo!("download it")
+ }
+
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");