horizon-prepare sounds: the sound copy in Rust, run by the launcher
tools/fetch_sounds.py (and the lab.py functions it used) becomes `horizon-prepare sounds` (horizon_prepare::sounds): the pinned asset index, sounds.json and every .ogg from the player's own launcher install, each SHA-1 checked, into .local/horizon-client/<version>. The launcher runs it as part of Prepare (in-process, the version's own binary when its sources differ and it knows the subcommand, in-process for older versions), and a launcher install without the assets only logs that the game will be silent. Player docs no longer mention Python for sound. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+48
-1
@@ -441,7 +441,7 @@ fn resources_compatible(from: &Path, to: &Path, manifest: &serde_json::Value) ->
|
||||
sources.iter().all(|s| same(s))
|
||||
}
|
||||
|
||||
/// Where a version folder keeps the preparer's sources (packaging/package.sh copies them).
|
||||
/// Where a version folder keeps the preparer's sources (the release package copies them).
|
||||
const PREPARER_CRATE: &str = "crates/horizon-prepare";
|
||||
|
||||
/// The files under `dir/relative`, as paths relative to `dir`.
|
||||
@@ -679,6 +679,53 @@ pub fn preparer(tag: &str, minecraft: &Path, log: &dyn Fn(String)) -> Result<Pre
|
||||
Ok(Preparer::Process(cmd))
|
||||
}
|
||||
|
||||
/// Copies the pinned version's sounds from the player's own launcher install into the version's
|
||||
/// resources (`horizon-prepare sounds`), each line to `log`. Sound is optional, so a launcher
|
||||
/// install without them is a line in the log, never a failed preparation. The version's own
|
||||
/// preparer does it when it is not the launcher's and knows how; versions from before it read
|
||||
/// the sounds where the launcher's preparer puts them.
|
||||
pub fn sounds(tag: &str, minecraft: &Path, log: &dyn Fn(String)) {
|
||||
let dir = version_dir(tag);
|
||||
let own = horizon_prepare::sources_sha256(&dir.join(PREPARER_CRATE)).as_deref()
|
||||
== Some(horizon_prepare::SOURCES_SHA256);
|
||||
let binary = preparer_binary(&dir).filter(|binary| {
|
||||
!own && Command::new(binary)
|
||||
.arg("--help")
|
||||
.output()
|
||||
.is_ok_and(|o| String::from_utf8_lossy(&o.stdout).contains("horizon-prepare sounds"))
|
||||
});
|
||||
log("Copying the sounds from your Minecraft install".into());
|
||||
let result = match binary {
|
||||
Some(binary) => Command::new(binary)
|
||||
.current_dir(&dir)
|
||||
.arg("sounds")
|
||||
.arg("--root")
|
||||
.arg(&dir)
|
||||
.arg("--minecraft-dir")
|
||||
.arg(minecraft)
|
||||
.output()
|
||||
.map_err(|e| e.to_string())
|
||||
.and_then(|o| {
|
||||
let text = |b: &[u8]| String::from_utf8_lossy(b).trim().to_string();
|
||||
for line in text(&o.stdout).lines() {
|
||||
log(line.to_string());
|
||||
}
|
||||
match o.status.success() {
|
||||
true => Ok(()),
|
||||
false => Err(text(&o.stderr).trim_start_matches("error: ").to_string()),
|
||||
}
|
||||
}),
|
||||
None => std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
horizon_prepare::sounds(&dir, Some(minecraft), &|line| log(line.to_string()))
|
||||
}))
|
||||
.unwrap_or_else(|_| Err("The sound copy stopped unexpectedly".into()))
|
||||
.map(|_| ()),
|
||||
};
|
||||
if let Err(e) = result {
|
||||
log(format!("No sound (the game will be silent): {e}"));
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs `Preparer::InProcess` on this thread, each progress line to `log`. A panic is an
|
||||
/// error like any other, so the window never waits on a preparation that died.
|
||||
pub fn prepare_in_process(
|
||||
|
||||
+3
-1
@@ -215,7 +215,9 @@ fn execute(command: Cmd, as_json: bool) -> Result<(), String> {
|
||||
Cmd::Prepare { minecraft, version } => {
|
||||
let tag = backend::resolve_version(version.as_deref())?;
|
||||
let minecraft = backend::minecraft_dir(minecraft)?;
|
||||
match backend::preparer(&tag, &minecraft, &|line| eprintln!("{line}"))? {
|
||||
let preparer = backend::preparer(&tag, &minecraft, &|line| eprintln!("{line}"))?;
|
||||
backend::sounds(&tag, &minecraft, &|line| println!("{line}"));
|
||||
match preparer {
|
||||
backend::Preparer::Process(cmd) => attached(cmd)?,
|
||||
backend::Preparer::InProcess(options) => {
|
||||
backend::prepare_in_process(&options, &|line| println!("{line}"))?
|
||||
|
||||
+10
-8
@@ -515,14 +515,16 @@ impl Launcher {
|
||||
let log = |line| {
|
||||
let _ = tx.send(Msg::Line(Job::Prepare, line));
|
||||
};
|
||||
let result = backend::preparer(&tag, &minecraft, &log).and_then(|p| match p {
|
||||
backend::Preparer::Process(cmd) => {
|
||||
backend::spawn(Job::Prepare, cmd, tx.clone()).map(|_running| false)
|
||||
}
|
||||
backend::Preparer::InProcess(options) => {
|
||||
backend::prepare_in_process(&options, &log).map(|_| true)
|
||||
}
|
||||
});
|
||||
let result = backend::preparer(&tag, &minecraft, &log)
|
||||
.inspect(|_| backend::sounds(&tag, &minecraft, &log))
|
||||
.and_then(|p| match p {
|
||||
backend::Preparer::Process(cmd) => {
|
||||
backend::spawn(Job::Prepare, cmd, tx.clone()).map(|_running| false)
|
||||
}
|
||||
backend::Preparer::InProcess(options) => {
|
||||
backend::prepare_in_process(&options, &log).map(|_| true)
|
||||
}
|
||||
});
|
||||
match result {
|
||||
// A process sends its own Exit when it ends.
|
||||
Ok(false) => {}
|
||||
|
||||
+5
-1
@@ -97,7 +97,10 @@ impl Session {
|
||||
let tag = backend::resolve_version(arg_str(args, "version"))?;
|
||||
let minecraft =
|
||||
backend::minecraft_dir(arg_str(args, "minecraft_dir").map(PathBuf::from))?;
|
||||
let (result, tail) = match backend::preparer(&tag, &minecraft, &|_| {})? {
|
||||
let preparer = backend::preparer(&tag, &minecraft, &|_| {})?;
|
||||
let sound = std::cell::RefCell::new(Vec::new());
|
||||
backend::sounds(&tag, &minecraft, &|line| sound.borrow_mut().push(line));
|
||||
let (result, tail) = match preparer {
|
||||
backend::Preparer::Process(cmd) => {
|
||||
let run = Logged::start(Job::Prepare, cmd)?;
|
||||
let result = run.wait();
|
||||
@@ -120,6 +123,7 @@ impl Session {
|
||||
(result, tail)
|
||||
}
|
||||
};
|
||||
let tail = format!("{}\n{tail}", sound.into_inner().join("\n"));
|
||||
result
|
||||
.map(|_| format!("{tag} is prepared.\n{tail}"))
|
||||
.map_err(|e| format!("{e}\n{tail}"))
|
||||
|
||||
Reference in New Issue
Block a user