added: legacy Forge install_profile.json native pass-through
install_forge_from_profile now writes the upstream versionInfo as compact
JSON (no key reordering, no field stripping) instead of building a custom
{mainClass, libraries, gameArguments} shape. legacy 1.7.10-era Forge
profiles ride the same LaunchProfile + resolve + render pipeline as
modern Forge. drops the no-longer-needed extract_extra_game_args helper.
This commit is contained in:
1 parent
0d00678a7c
commit
8d2b5b9832
2 files changed
+67
-73
No files matched your search
@@ -193,4 +193,64 @@ mod tests {
|
|||||||
"saved profile should be byte-for-byte identical to installer output"
|
"saved profile should be byte-for-byte identical to installer output"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn legacy_forge_version_info_round_trips_through_save_profile_json() {
|
||||||
|
use tempfile::TempDir;
|
||||||
|
let tmp = TempDir::new().unwrap();
|
||||||
|
let meta_dir = tmp.path().to_path_buf();
|
||||||
|
|
||||||
|
// synthetic versionInfo shape from a 1.7.10 forge install_profile.json.
|
||||||
|
// legacy forge uses minecraftArguments (the flat string format) and
|
||||||
|
// typically omits inheritsFrom (the launch flow's implicit fallback
|
||||||
|
// handles that).
|
||||||
|
let version_info = serde_json::json!({
|
||||||
|
"id": "1.7.10-Forge10.13.4.1614-1.7.10",
|
||||||
|
"mainClass": "net.minecraft.launchwrapper.Launch",
|
||||||
|
"minecraftArguments": "--username ${auth_player_name} --tweakClass cpw.mods.fml.common.launcher.FMLTweaker",
|
||||||
|
"libraries": [
|
||||||
|
{ "name": "net.minecraftforge:forge:10.13.4.1614", "url": "http://files.minecraftforge.net/maven/" },
|
||||||
|
{ "name": "net.minecraft:launchwrapper:1.9" }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
save_profile_json(&meta_dir, "forge-1.7.10-10.13.4.1614.json", &version_info).unwrap();
|
||||||
|
|
||||||
|
let saved_bytes = std::fs::read(
|
||||||
|
meta_dir
|
||||||
|
.join("loader-profiles")
|
||||||
|
.join("forge-1.7.10-10.13.4.1614.json"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// the cached profile must parse as a LaunchProfile so the launch
|
||||||
|
// flow's render_args + resolve pipeline can consume it.
|
||||||
|
let profile: crate::launch_profile::model::LaunchProfile =
|
||||||
|
serde_json::from_slice(&saved_bytes).unwrap();
|
||||||
|
assert_eq!(profile.id, "1.7.10-Forge10.13.4.1614-1.7.10");
|
||||||
|
assert_eq!(
|
||||||
|
profile.main_class.as_deref(),
|
||||||
|
Some("net.minecraft.launchwrapper.Launch")
|
||||||
|
);
|
||||||
|
assert!(profile.inherits_from.is_none()); // launch flow's implicit fallback adds it
|
||||||
|
assert!(
|
||||||
|
profile
|
||||||
|
.minecraft_arguments
|
||||||
|
.as_deref()
|
||||||
|
.unwrap()
|
||||||
|
.contains("--tweakClass")
|
||||||
|
);
|
||||||
|
assert_eq!(profile.libraries.len(), 2);
|
||||||
|
assert_eq!(
|
||||||
|
profile.libraries[0].name,
|
||||||
|
"net.minecraftforge:forge:10.13.4.1614"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
profile.libraries[0].url.as_deref(),
|
||||||
|
Some("http://files.minecraftforge.net/maven/")
|
||||||
|
);
|
||||||
|
// legacy libs typically have no `downloads.artifact` - they're
|
||||||
|
// resolved at launch time via maven_coord_to_path(name).
|
||||||
|
assert!(profile.libraries[0].downloads.is_none());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+7
-73
@@ -194,12 +194,6 @@ pub(crate) async fn install_forge_from_profile(
|
|||||||
.get("install")
|
.get("install")
|
||||||
.ok_or_else(|| NetError::Parse("install_profile.json missing install section".into()))?;
|
.ok_or_else(|| NetError::Parse("install_profile.json missing install section".into()))?;
|
||||||
|
|
||||||
let main_class = version_info
|
|
||||||
.get("mainClass")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.ok_or_else(|| NetError::Parse("missing versionInfo.mainClass".into()))?
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let libraries = version_info
|
let libraries = version_info
|
||||||
.get("libraries")
|
.get("libraries")
|
||||||
.and_then(|v| v.as_array())
|
.and_then(|v| v.as_array())
|
||||||
@@ -271,78 +265,18 @@ pub(crate) async fn install_forge_from_profile(
|
|||||||
download_file(client, &download_url, &dest, |_, _| {}).await?;
|
download_file(client, &download_url, &dest, |_, _| {}).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// old forge profiles store game arguments (like --tweakClass) in
|
|
||||||
// minecraftArguments. extract non-template args to pass at launch.
|
|
||||||
let game_arguments: Vec<String> = version_info
|
|
||||||
.get("minecraftArguments")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.map(extract_extra_game_args)
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
set_action("Saving Forge profile...");
|
set_action("Saving Forge profile...");
|
||||||
let lib_entries: Vec<serde_json::Value> = libraries
|
// write the installer's versionInfo verbatim. it already has the
|
||||||
.iter()
|
// mainClass, the full library list (with name + url for forge-hosted
|
||||||
.filter_map(|l| {
|
// libs), and minecraftArguments (the legacy --tweakClass etc). the
|
||||||
l.get("name")
|
// launch flow parses this as a LaunchProfile and - if there's no
|
||||||
.and_then(|v| v.as_str())
|
// inheritsFrom field - implicitly inherits from the configured game
|
||||||
.map(|n| serde_json::json!({"name": n}))
|
// version so vanilla libraries layer in via resolve().
|
||||||
})
|
crate::instance::loader::save_profile_json(meta_dir, profile_filename, version_info)?;
|
||||||
.collect();
|
|
||||||
|
|
||||||
let profile_json = serde_json::json!({
|
|
||||||
"mainClass": main_class,
|
|
||||||
"libraries": lib_entries,
|
|
||||||
"gameArguments": game_arguments,
|
|
||||||
});
|
|
||||||
|
|
||||||
crate::instance::loader::save_profile_json(meta_dir, profile_filename, &profile_json)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// pulls out game arguments from old forge's minecraftArguments string that
|
|
||||||
// the launcher doesn't already handle. skips template variables (${...})
|
|
||||||
// and standard args like --username that we build ourselves.
|
|
||||||
fn extract_extra_game_args(minecraft_arguments: &str) -> Vec<String> {
|
|
||||||
let handled = [
|
|
||||||
"--username",
|
|
||||||
"--version",
|
|
||||||
"--gameDir",
|
|
||||||
"--assetsDir",
|
|
||||||
"--assetIndex",
|
|
||||||
"--uuid",
|
|
||||||
"--accessToken",
|
|
||||||
"--userProperties",
|
|
||||||
"--userType",
|
|
||||||
];
|
|
||||||
|
|
||||||
let tokens: Vec<&str> = minecraft_arguments.split_whitespace().collect();
|
|
||||||
let mut result = Vec::new();
|
|
||||||
let mut i = 0;
|
|
||||||
while i < tokens.len() {
|
|
||||||
let token = tokens[i];
|
|
||||||
if token.starts_with("--") {
|
|
||||||
if handled.contains(&token) {
|
|
||||||
// skip the flag and its value
|
|
||||||
i += 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
result.push(token.to_string());
|
|
||||||
// if the next token is a value (not a flag or template), include it
|
|
||||||
if i + 1 < tokens.len() && !tokens[i + 1].starts_with("--") {
|
|
||||||
let val = tokens[i + 1];
|
|
||||||
if !val.starts_with("${") {
|
|
||||||
result.push(val.to_string());
|
|
||||||
}
|
|
||||||
i += 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Reference in new issue
Block a user