launcher: reach Prism's and MultiMC's shared libraries from an instance folder (#693)
A Prism or MultiMC instance keeps no jar of its own: the client sits in the launcher root's shared libraries, two or three folders above `instances/`, and the game is downloaded only once the instance is launched. Choosing `%APPDATA%\PrismLauncher\instances` (or an instance's `minecraft`/`.minecraft` folder) as the Minecraft folder failed Prepare when the jar was not there yet, and the error only listed every launcher without saying what to do. resolve now also looks in the launcher root above an `instances` folder, so a folder deeper than the four walked above the chosen one still finds the libraries. When nothing is found and the chosen folder is inside a launcher Horizon knows, the error names it and says to launch the instance once so it downloads the game. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -90,7 +90,7 @@ fn resolve_with(
|
||||
&|_| {},
|
||||
)? {
|
||||
Resolved::Folder(dir) => Ok(dir),
|
||||
Resolved::NotFound(checked) => Err(not_found("26.3", &checked)),
|
||||
Resolved::NotFound(checked) => Err(not_found("26.3", &checked, chosen)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,6 +273,75 @@ fn an_instance_folder_may_be_chosen() {
|
||||
assert_linked(&linked, &dir, jar);
|
||||
}
|
||||
|
||||
/// Every folder a Prism or MultiMC player naturally picks: the instance list, one instance, an
|
||||
/// instance's game folder and a folder below it. The shared `libraries` are in the launcher
|
||||
/// root, which the chosen folder's ancestors do not always reach (#693).
|
||||
#[test]
|
||||
fn a_prism_instances_folder_finds_the_launcher_root() {
|
||||
for (name, chosen) in [
|
||||
("list", "instances"),
|
||||
("instance", "instances/26.3"),
|
||||
("game", "instances/26.3/minecraft"),
|
||||
// Deeper than the four folders above it: only the `instances` root helps here.
|
||||
("deeper", "instances/26.3/minecraft/saves"),
|
||||
] {
|
||||
let s = Scratch::new(&format!("prism-tree-{name}"));
|
||||
let jar = "libraries/com/mojang/minecraft/26.3/minecraft-26.3-client.jar";
|
||||
let dir = s.launcher("PrismLauncher", "", jar);
|
||||
s.write(
|
||||
"PrismLauncher/meta/net.minecraft/26.3.json",
|
||||
br#"{"mainJar": {"name": "com.mojang:minecraft:26.3:client"}}"#,
|
||||
);
|
||||
fs::create_dir_all(dir.join(chosen)).unwrap();
|
||||
let linked = s.0.join("linked");
|
||||
let got = resolve_with(&dir.join(chosen), &[], &linked, &Mojang::new(MANIFEST)).unwrap();
|
||||
assert_eq!(got, linked, "{chosen}");
|
||||
assert_linked(&linked, &dir, jar);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_multimc_instances_folder_finds_the_launcher_root() {
|
||||
let s = Scratch::new("multimc-tree");
|
||||
let jar = "libraries/com/mojang/minecraft/26.3/minecraft-26.3-client.jar";
|
||||
let dir = s.launcher("multimc", "", jar);
|
||||
s.write(
|
||||
"multimc/meta/net.minecraft/26.3.json",
|
||||
br#"{"mainJar": {"name": "com.mojang:minecraft:26.3:client"}}"#,
|
||||
);
|
||||
let chosen = dir.join("instances/26.3/.minecraft");
|
||||
fs::create_dir_all(&chosen).unwrap();
|
||||
let linked = s.0.join("linked");
|
||||
let got = resolve_with(&chosen, &[], &linked, &Mojang::new(MANIFEST)).unwrap();
|
||||
assert_eq!(got, linked);
|
||||
assert_linked(&linked, &dir, jar);
|
||||
}
|
||||
|
||||
/// When the chosen folder is inside a launcher tree, the error names it and says to launch the
|
||||
/// instance once, instead of listing every launcher (#693).
|
||||
#[test]
|
||||
fn the_not_found_message_names_the_launcher_that_was_chosen() {
|
||||
let s = Scratch::new("prism-hint");
|
||||
let dir = s.0.join("PrismLauncher");
|
||||
let chosen = dir.join("instances/26.3/minecraft");
|
||||
fs::create_dir_all(&chosen).unwrap();
|
||||
let error =
|
||||
resolve_with(&chosen, &[], &s.0.join("linked"), &Mojang::new(MANIFEST)).unwrap_err();
|
||||
assert!(
|
||||
error.contains("Launch the 26.3 instance once in Prism Launcher"),
|
||||
"{error}"
|
||||
);
|
||||
assert!(!error.contains("or in Prism Launcher, MultiMC"), "{error}");
|
||||
// An unknown folder keeps the advice that names every launcher.
|
||||
let other = s.0.join("elsewhere");
|
||||
fs::create_dir_all(&other).unwrap();
|
||||
let error = resolve_with(&other, &[], &s.0.join("linked"), &Mojang::new(MANIFEST)).unwrap_err();
|
||||
assert!(
|
||||
error.contains("Prism Launcher, MultiMC, the Modrinth App, ATLauncher or GDLauncher"),
|
||||
"{error}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_known_folders_are_searched_after_the_chosen_one() {
|
||||
let s = Scratch::new("known");
|
||||
|
||||
Reference in New Issue
Block a user