added support for old forge versions (pre-1.13)

old forge installers don't have --installClient, so we extract the
universal jar and library info directly from install_profile.json
inside the installer jar. also tries multiple maven URL formats since
forge naming is inconsistent across versions.
This commit is contained in:
objz committed 2026-04-20 19:24:54 +02:00
1 parent 5f3f7890aa
commit a29c90e86b
2 files changed
+223 -36

No files matched your search

+34 -18
View File
@@ -1,6 +1,6 @@
// forge installation. unlike fabric/quilt, forge ships a java-based installer
// that has to be downloaded and executed. yes, a jvm is needed just to install
// the thing that runs on a jvm. the installer jar gets cleaned up afterward.
// forge installation. modern forge runs a java installer, old forge (pre-1.13)
// can't run headless so we extract the profile and libraries from the jar
// directly. the installer jar gets cleaned up either way.
use std::path::Path;
@@ -43,27 +43,43 @@ impl ModLoaderInstaller for ForgeInstaller {
forge_api::download_forge_installer(client, game_version, loader_version, &installer_jar)
.await?;
// use configured java or try to find one on PATH
let java_path = crate::config::SETTINGS
.paths
.effective_java_path()
.map(str::to_owned)
.unwrap_or_else(crate::net::detect_java_path);
if let Err(e) =
forge_api::run_forge_installer(&installer_jar, instance_dir, &java_path).await
{
// still clean up even if installation failed
let _ = tokio::fs::remove_file(&installer_jar).await;
return Err(e);
let profile_filename = format!("forge-{game_version}-{loader_version}.json");
if forge_api::has_legacy_install_profile(&installer_jar) {
// old forge: no --installClient support, extract directly from jar
if let Err(e) = forge_api::install_forge_from_profile(
client,
&installer_jar,
meta_dir,
&profile_filename,
)
.await
{
let _ = tokio::fs::remove_file(&installer_jar).await;
return Err(e);
}
} else {
// modern forge: run the java installer
let java_path = crate::config::SETTINGS
.paths
.effective_java_path()
.map(str::to_owned)
.unwrap_or_else(crate::net::detect_java_path);
if let Err(e) =
forge_api::run_forge_installer(&installer_jar, instance_dir, &java_path).await
{
let _ = tokio::fs::remove_file(&installer_jar).await;
return Err(e);
}
// extract the profile from what the installer just wrote to disk
save_forge_profile(instance_dir, meta_dir, game_version, loader_version)?;
}
if let Err(e) = tokio::fs::remove_file(&installer_jar).await {
tracing::warn!("Failed to remove Forge installer JAR: {}", e);
}
// extract the profile from what the installer just wrote to disk
save_forge_profile(instance_dir, meta_dir, game_version, loader_version)?;
Ok(())
}
}