#![allow(clippy::doc_markdown)]
use std::path::PathBuf;
use std::process::ExitCode;
use tracing_subscriber::EnvFilter;
use zipatch_rs::{ApplyConfig, Platform, open_patch};
fn main() -> ExitCode {
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
)
.with_writer(std::io::stderr)
.init();
let mut args = std::env::args_os().skip(1);
let Some(patch_path) = args.next().map(PathBuf::from) else {
eprintln!("usage: apply_to_dir <patch_file> <install_dir>");
return ExitCode::from(2);
};
let Some(install_dir) = args.next().map(PathBuf::from) else {
eprintln!("usage: apply_to_dir <patch_file> <install_dir>");
return ExitCode::from(2);
};
if !install_dir.is_dir() {
eprintln!("install dir does not exist: {}", install_dir.display());
return ExitCode::FAILURE;
}
let ctx = ApplyConfig::new(&install_dir)
.with_platform(Platform::Win32)
.with_ignore_missing(true);
let reader = match open_patch(&patch_path) {
Ok(r) => r,
Err(e) => {
eprintln!("failed to open {}: {e}", patch_path.display());
return ExitCode::FAILURE;
}
};
match ctx.apply_patch(reader) {
Ok(()) => {
println!(
"applied {} to {}",
patch_path.display(),
install_dir.display()
);
ExitCode::SUCCESS
}
Err(e) => {
eprintln!("apply failed: {e}");
ExitCode::FAILURE
}
}
}