`cargo fmt --all -- --check` has failed on every run in this repository's history, identically on `main` and on every branch. This is #12. Mechanical: `cargo fmt --all`, nothing else. 154 files, all `.rs`, no other extension touched. `cargo check --workspace` exits 0 afterwards, so nothing changed semantically. ON THE ORDERING, WHICH WAS THE REAL QUESTION. HANDOFF-2026-09-06 section 7 warns this is the expensive fix: a whole-tree reformat before #7 and #8 return "would put a conflict in every file of 861 commits and make the reviews those items exist to enable unreadable". That is measurably too pessimistic, and it had been reasoned rather than tested. Measured here by three-way merging a rustfmt'd `main` against both unmerged branches, file by file: file/branch pairs tested 32 merges CLEAN 28 merges CONFLICTING 4 (8 conflict hunks total) sylpheed-cli/src/main.rs 1 hunk sylpheed-export/src/check.rs 1 sylpheed-export/src/screen.rs 4 sylpheed-export/src/video.rs 2 All four are against `auto/frame-blend-draw-path` only; `auto/port-p6-audio` does not conflict anywhere. The earlier framing -- 154 dirty files, 133 that cannot collide, 21 that can, the collision set carrying 147 of 774 hunks (19%) -- reproduces exactly. What it did not say is that most of the 21 still merge cleanly, because rustfmt's edits and the branches' edits rarely land on the same lines. So the cost of sweeping now is 4 files and 8 hunks for one branch, against a check that is otherwise red forever. Deliberately NOT folded into the WASM PR: 154 reformatted files would make that one unreviewable. Closes #12
145 lines
5.3 KiB
Rust
145 lines
5.3 KiB
Rust
use std::fs;
|
|
use std::io::{Read, Seek, SeekFrom};
|
|
use std::process::Command;
|
|
use sylpheed_formats::{
|
|
hash::name_hash, movie_manifest, movie_subtitle as ms, movie_voice, slb, PakArchive,
|
|
};
|
|
fn rg(disc: &str, g: u64, n: usize) -> Vec<u8> {
|
|
let mut segs = vec![];
|
|
let mut cum = 0u64;
|
|
for i in 0..5 {
|
|
let p = format!("{disc}/dat/sound.p{i:02}");
|
|
if let Ok(m) = fs::metadata(&p) {
|
|
segs.push((cum, m.len(), p));
|
|
cum += m.len();
|
|
}
|
|
}
|
|
let mut out = vec![];
|
|
let (mut need, mut pos) = (n, g);
|
|
for (base, len, path) in &segs {
|
|
if need == 0 || pos >= base + len || pos < *base {
|
|
continue;
|
|
}
|
|
let local = pos - base;
|
|
let take = need.min((len - local) as usize);
|
|
let mut f = fs::File::open(path).unwrap();
|
|
f.seek(SeekFrom::Start(local)).unwrap();
|
|
let mut b = vec![0u8; take];
|
|
f.read_exact(&mut b).unwrap();
|
|
out.extend_from_slice(&b);
|
|
need -= take;
|
|
pos += take as u64;
|
|
}
|
|
out
|
|
}
|
|
fn ct(h: &[u8], n: &[u8]) -> bool {
|
|
h.windows(n.len()).any(|w| w == n)
|
|
}
|
|
fn dur(w: &str) -> String {
|
|
let o = Command::new("ffprobe")
|
|
.args([
|
|
"-v",
|
|
"error",
|
|
"-show_entries",
|
|
"format=duration",
|
|
"-of",
|
|
"default=nw=1:nk=1",
|
|
w,
|
|
])
|
|
.output()
|
|
.unwrap();
|
|
String::from_utf8_lossy(&o.stdout).trim().to_string()
|
|
}
|
|
fn main() {
|
|
let disc = std::env::var("SYLPHEED_DISC").unwrap();
|
|
let tpak = PakArchive::open(format!("{disc}/dat/tables.pak")).unwrap();
|
|
let man = tpak
|
|
.entries()
|
|
.iter()
|
|
.find_map(|e| tpak.read(e).ok().filter(|b| movie_manifest::is_manifest(b)))
|
|
.unwrap();
|
|
let lpak = PakArchive::open(format!("{disc}/dat/movie/eng.pak")).unwrap();
|
|
let reg = tpak
|
|
.entries()
|
|
.iter()
|
|
.find_map(|e| {
|
|
tpak.read(e)
|
|
.ok()
|
|
.filter(|b| ct(b, b"eng\\Movie\\VOICE_ADV.slb"))
|
|
})
|
|
.unwrap();
|
|
let ids = movie_voice::registry_voice_ids(®);
|
|
let stoc = fs::read(format!("{disc}/dat/sound.pak")).unwrap();
|
|
let ents = PakArchive::parse_toc(&stoc).unwrap();
|
|
// demo->token from bound hokyu
|
|
let hok: Vec<_> = movie_manifest::parse(&man)
|
|
.into_iter()
|
|
.filter(|m| m.movie.starts_with("hokyu_"))
|
|
.collect();
|
|
let resolve = |movie: &str| -> Option<String> {
|
|
movie_manifest::voice_token(&man, movie).or_else(|| {
|
|
let want = ms::track_voice_cues(&lpak, movie)
|
|
.first()
|
|
.map(|&(d, _)| d)?;
|
|
hok.iter().find_map(|e| {
|
|
let t = e
|
|
.voice_token
|
|
.clone()
|
|
.filter(|_| e.movie.starts_with("hokyu_"))?;
|
|
ms::track_voice_cues(&lpak, &e.movie)
|
|
.iter()
|
|
.any(|&(d, _)| d == want)
|
|
.then_some(t)
|
|
})
|
|
})
|
|
};
|
|
for e in &hok {
|
|
let mv = &e.movie;
|
|
let bound = e.voice_token.is_some();
|
|
let tok = resolve(mv);
|
|
let demo = ms::track_voice_cues(&lpak, mv).first().map(|&(d, _)| d);
|
|
let mut d = "—".to_string();
|
|
if let Some(tok) = &tok {
|
|
if let Some(&id) = ids.get(tok) {
|
|
if let Some(anchor) = ["Movie", "etc", "Voice"].iter().find_map(|dir| {
|
|
let h = name_hash(&format!("eng\\{dir}\\{tok}.slb"));
|
|
ents.binary_search_by_key(&h, |x| x.name_hash)
|
|
.ok()
|
|
.map(|i| ents[i].offset as u64)
|
|
}) {
|
|
let ws = (anchor.saturating_sub(2 * 1024 * 1024)) & !3;
|
|
let win = rg(&disc, ws, 8 * 1024 * 1024);
|
|
if let Some(el) = movie_voice::find_descriptor(&win, id) {
|
|
let end = ws + el as u64;
|
|
let start = movie_voice::find_descriptor(&win, id.wrapping_sub(1))
|
|
.or_else(|| movie_voice::find_descriptor_before(&win, el))
|
|
.map(|o| ws + o as u64)
|
|
.filter(|&s| s < end && end - s < 1_500_000)
|
|
.unwrap_or(anchor);
|
|
let region = rg(&disc, start, (end - start) as usize);
|
|
let mut rf = slb::to_xma_riffs(®ion);
|
|
if rf.is_empty() {
|
|
rf = slb::to_xma_riff_best(®ion).into_iter().collect();
|
|
}
|
|
if let Some(r) = rf.first() {
|
|
let xp = format!("/tmp/hd_{mv}.xma.wav");
|
|
let wp = format!("/tmp/hd_{mv}.wav");
|
|
fs::write(&xp, r).unwrap();
|
|
let _ = Command::new("ffmpeg")
|
|
.args(["-hide_banner", "-v", "error", "-y", "-i", &xp, &wp])
|
|
.status();
|
|
d = dur(&wp);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
println!(
|
|
"{mv:16} {:8} demo={:?} -> {:11} voice={d}s",
|
|
if bound { "BOUND" } else { "unbound" },
|
|
demo,
|
|
tok.unwrap_or("(silent)".into())
|
|
);
|
|
}
|
|
}
|