added: Fabric/Quilt raw-bytes profile storage + migration fix
stop re-serializing FabricProfile/QuiltProfile through narrow structs; new fetch_X_profile_with_raw helpers return both the parsed shape (for library downloads) and the upstream bytes (written byte-for-byte to the loader-profiles cache). also fixes a latent issue surfaced by the change: the legacy-loader migration predicate now skips Fabric and Quilt explicitly since their upstream shape matches the predicate but they have no installer JSON to recover from.
This commit is contained in:
1 parent
8d2b5b9832
commit
a7b378b17d
6 files changed
+164
-13
No files matched your search
@@ -41,15 +41,15 @@ impl ModLoaderInstaller for FabricInstaller {
|
||||
_instance_dir: &Path,
|
||||
meta_dir: &Path,
|
||||
) -> Result<(), NetError> {
|
||||
let profile =
|
||||
fabric_api::fetch_fabric_profile(client, game_version, loader_version).await?;
|
||||
let (profile, raw_bytes) =
|
||||
fabric_api::fetch_fabric_profile_with_raw(client, game_version, loader_version).await?;
|
||||
fabric_api::download_fabric_libraries(client, &profile, meta_dir).await?;
|
||||
|
||||
super::save_profile_json(
|
||||
meta_dir,
|
||||
&format!("fabric-{game_version}-{loader_version}.json"),
|
||||
&profile,
|
||||
)?;
|
||||
let profiles_dir = meta_dir.join("loader-profiles");
|
||||
std::fs::create_dir_all(&profiles_dir)?;
|
||||
let profile_path =
|
||||
profiles_dir.join(format!("fabric-{game_version}-{loader_version}.json"));
|
||||
std::fs::write(&profile_path, &raw_bytes)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -253,4 +253,46 @@ mod tests {
|
||||
// resolved at launch time via maven_coord_to_path(name).
|
||||
assert!(profile.libraries[0].downloads.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_fabric_profile_bytes_parse_as_launch_profile() {
|
||||
use tempfile::TempDir;
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let meta_dir = tmp.path();
|
||||
|
||||
// a synthetic upstream fabric profile shape (id, mainClass,
|
||||
// libraries with name+url, no inheritsFrom, no arguments).
|
||||
// simulates what the install path will write verbatim.
|
||||
let upstream_bytes = br#"{
|
||||
"id": "fabric-loader-0.14.21-1.20.1",
|
||||
"mainClass": "net.fabricmc.loader.impl.launch.knot.KnotClient",
|
||||
"libraries": [
|
||||
{ "name": "net.fabricmc:fabric-loader:0.14.21", "url": "https://maven.fabricmc.net/" },
|
||||
{ "name": "net.fabricmc:intermediary:1.20.1", "url": "https://maven.fabricmc.net/" }
|
||||
]
|
||||
}"#;
|
||||
|
||||
let profiles_dir = meta_dir.join("loader-profiles");
|
||||
std::fs::create_dir_all(&profiles_dir).unwrap();
|
||||
let profile_path = profiles_dir.join("fabric-1.20.1-0.14.21.json");
|
||||
std::fs::write(&profile_path, upstream_bytes).unwrap();
|
||||
|
||||
let saved = std::fs::read(&profile_path).unwrap();
|
||||
assert_eq!(saved, upstream_bytes.to_vec());
|
||||
|
||||
let parsed: crate::launch_profile::model::LaunchProfile =
|
||||
serde_json::from_slice(&saved).unwrap();
|
||||
assert_eq!(parsed.id, "fabric-loader-0.14.21-1.20.1");
|
||||
assert_eq!(
|
||||
parsed.main_class.as_deref(),
|
||||
Some("net.fabricmc.loader.impl.launch.knot.KnotClient")
|
||||
);
|
||||
assert!(parsed.inherits_from.is_none()); // launch flow's implicit fallback handles it
|
||||
assert!(parsed.arguments.is_none());
|
||||
assert_eq!(parsed.libraries.len(), 2);
|
||||
assert_eq!(
|
||||
parsed.libraries[0].url.as_deref(),
|
||||
Some("https://maven.fabricmc.net/")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -41,14 +41,14 @@ impl ModLoaderInstaller for QuiltInstaller {
|
||||
_instance_dir: &Path,
|
||||
meta_dir: &Path,
|
||||
) -> Result<(), NetError> {
|
||||
let profile = quilt_api::fetch_quilt_profile(client, game_version, loader_version).await?;
|
||||
let (profile, raw_bytes) =
|
||||
quilt_api::fetch_quilt_profile_with_raw(client, game_version, loader_version).await?;
|
||||
quilt_api::download_quilt_libraries(client, &profile, meta_dir).await?;
|
||||
|
||||
super::save_profile_json(
|
||||
meta_dir,
|
||||
&format!("quilt-{game_version}-{loader_version}.json"),
|
||||
&profile,
|
||||
)?;
|
||||
let profiles_dir = meta_dir.join("loader-profiles");
|
||||
std::fs::create_dir_all(&profiles_dir)?;
|
||||
let profile_path = profiles_dir.join(format!("quilt-{game_version}-{loader_version}.json"));
|
||||
std::fs::write(&profile_path, &raw_bytes)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user