#![allow(clippy::unwrap_used, clippy::expect_used)]
use std::path::PathBuf;
fn main() {
let mut root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
root.pop();
let out_dir = std::env::args()
.nth(1)
.unwrap_or_else(|| "/tmp/pf_scca".to_string());
std::fs::create_dir_all(&out_dir).expect("mkdir out_dir");
for name in [
"COREUPDATER.EXE-157C54BB.pf",
"AUDIODG.EXE-AB22E9A6.pf",
"AM_DELTA.EXE-78CA83B0.pf",
] {
let p = root.join("tests/data").join(name);
let raw = std::fs::read(&p).expect("read fixture");
let scca = prefetch_core::decompress(&raw).expect("decompress");
std::fs::write(PathBuf::from(&out_dir).join(format!("{name}.scca")), &scca)
.expect("write scca");
let info = prefetch_core::parse(&raw).expect("parse");
let files: Vec<String> = info.filenames.iter().map(|f| escape(f)).collect();
let vols: Vec<String> = info
.volumes
.iter()
.map(|v| {
format!(
"{{\"serial\":{},\"device_path\":\"{}\",\"creation_time\":{}}}",
v.serial,
escape(&v.device_path),
v.creation_time
)
})
.collect();
println!(
"{{\"file\":\"{}\",\"scca_len\":{},\"version\":{},\"executable\":\"{}\",\"run_count\":{},\"last_run_times\":{:?},\"filenames_count\":{},\"filenames\":[{}],\"volumes\":[{}]}}",
name,
scca.len(),
info.version,
escape(&info.executable),
info.run_count,
info.last_run_times,
info.filenames.len(),
files.iter().map(|f| format!("\"{f}\"")).collect::<Vec<_>>().join(","),
vols.join(",")
);
}
}
fn escape(s: &str) -> String {
s.replace('\\', "\\\\")
}