From 72ddd7b7704f2087a52c9c0552446682918c513b Mon Sep 17 00:00:00 2001 From: Filip Wandzio Date: Thu, 22 Jan 2026 23:14:08 +0100 Subject: Implement basic game files download logic Implement core clap arguments Respect XDG_BASE_DIR Currently library extraction is broken because it assumes every instace has it's own library folder. This should be refactored so instances share libraries Signed-off-by: Filip Wandzio --- src/minecraft/launcher.rs | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/minecraft/launcher.rs (limited to 'src/minecraft/launcher.rs') diff --git a/src/minecraft/launcher.rs b/src/minecraft/launcher.rs new file mode 100644 index 0000000..f7e3ecc --- /dev/null +++ b/src/minecraft/launcher.rs @@ -0,0 +1,73 @@ +use std::process::Command; + +use log::{debug, info}; + +use crate::{config::Config, errors::McError, minecraft::manifests::Version, platform::paths}; + +/// Build the full classpath +fn build_classpath(config: &Config, version: &Version) -> Result { + let sep = if cfg!(windows) { ";" } else { ":" }; + let mut entries = Vec::new(); + + for lib in &version.libraries { + if let Some(artifact) = &lib.downloads.artifact { + let path = paths::library_file(config, &artifact.path)?; + entries.push(path.to_string_lossy().to_string()); + } + } + + let client_jar = paths::client_jar(config, &version.id)?; + entries.push(client_jar.to_string_lossy().to_string()); + Ok(entries.join(sep)) +} + +/// Launch Minecraft +pub fn launch(config: &Config, version: &Version) -> Result<(), McError> { + let java = &config.java_path; + let classpath = build_classpath(config, version)?; + let natives_dir = paths::natives_dir(config, &version.id); + + if !natives_dir.exists() { + return Err(McError::Runtime(format!( + "Natives folder does not exist: {}", + natives_dir.display() + ))); + } + + info!("Launching Minecraft {}", version.id); + debug!("Classpath: {}", classpath); + debug!("Natives: {}", natives_dir.display()); + + let status = Command::new(java) + .arg(format!("-Xmx{}M", config.max_memory_mb)) + .arg(format!("-Djava.library.path={}", natives_dir.display())) + .arg("-cp") + .arg(classpath) + .arg(&version.main_class) + .arg("--username") + .arg(&config.username) + .arg("--version") + .arg(&version.id) + .arg("--gameDir") + .arg(paths::minecraft_root(config)) + .arg("--assetsDir") + .arg(paths::minecraft_root(config).join("assets")) + .arg("--assetIndex") + .arg(&version.id) + .arg("--uuid") + .arg(&config.uuid) + .arg("--userProperties") + .arg("{}") + .arg("--accessToken") + .arg("0") + .arg("--userType") + .arg("legacy") + .args(&config.jvm_args) + .status()?; + + if !status.success() { + return Err(McError::Process("Minecraft exited with error".into())); + } + + Ok(()) +} -- cgit v1.2.3