diff --git a/launcher/src/backend.rs b/launcher/src/backend.rs index 00c0db163..6e4d9b51b 100644 --- a/launcher/src/backend.rs +++ b/launcher/src/backend.rs @@ -644,6 +644,43 @@ fn preparer_binary(dir: &Path) -> Option { binary.is_file().then_some(binary) } +/// What a Minecraft folder lacks of `version`'s files in the official launcher's layout, or +/// None when it has them. +fn missing_game_files(minecraft: &Path, version: &str) -> Option { + if !minecraft.is_dir() { + return Some("the folder doesn't exist".into()); + } + let files = [format!("{version}.json"), format!("{version}.jar")]; + let missing: Vec = files + .iter() + .filter(|file| { + !minecraft + .join("versions") + .join(version) + .join(file) + .is_file() + }) + .map(|file| format!("versions/{version}/{file}")) + .collect(); + (!missing.is_empty()).then(|| format!("no {}", missing.join(" or "))) +} + +/// The error when no folder has Minecraft `version`: every folder looked in with what it +/// lacks, and what the player can do about it (#419). +fn not_found(version: &str, checked: &[(PathBuf, String)]) -> String { + let mut text = format!("Minecraft {version} was not found. Horizon looked in:"); + for (dir, missing) in checked { + text += &format!("\n {} ({missing})", dir.display()); + } + text += &format!( + "\nTo fix it:\n \ + • Play {version} once in the official Minecraft launcher, then prepare again.\n \ + • Or choose the folder where your launcher keeps Minecraft {version} (Minecraft folder › \ + Choose… in the launcher, --minecraft on the command line)." + ); + text +} + /// Checks what the preparation needs and picks how to run it. PLAY.txt describes the same /// steps: the player's own launcher install, the server jar from that version's own json, and /// Java (and Python, for versions before horizon-prepare). @@ -655,11 +692,10 @@ pub fn preparer(tag: &str, minecraft: &Path, log: &dyn Fn(String)) -> Result