mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 19:04:07 +00:00
Better status messages
This commit is contained in:
parent
1f679b8878
commit
27e69115a3
1 changed files with 20 additions and 7 deletions
|
@ -203,9 +203,11 @@ fn unpack(args: ActionUnpack) -> Result<(), repak::Error> {
|
||||||
.map(|i| prefix.join(Path::new(i)))
|
.map(|i| prefix.join(Path::new(i)))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let counter = std::sync::Arc::new(std::sync::atomic::AtomicU32::new(0));
|
||||||
|
|
||||||
pak.files().into_par_iter().try_for_each_init(
|
pak.files().into_par_iter().try_for_each_init(
|
||||||
|| (File::open(&args.input), includes.clone()),
|
|| (File::open(&args.input), includes.clone(), counter.clone()),
|
||||||
|(file, includes), path| -> Result<(), repak::Error> {
|
|(file, includes, counter), path| -> Result<(), repak::Error> {
|
||||||
let full_path = mount_point.join(&path);
|
let full_path = mount_point.join(&path);
|
||||||
if !includes.is_empty() && !includes.iter().any(|i| full_path.starts_with(i)) {
|
if !includes.is_empty() && !includes.iter().any(|i| full_path.starts_with(i)) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -224,13 +226,22 @@ fn unpack(args: ActionUnpack) -> Result<(), repak::Error> {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
fs::create_dir_all(file_path.parent().expect("will be a file"))?;
|
fs::create_dir_all(file_path.parent().expect("will be a file"))?;
|
||||||
|
counter.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||||
pak.read_file(
|
pak.read_file(
|
||||||
&path,
|
&path,
|
||||||
&mut BufReader::new(file.as_ref().unwrap()), // TODO: avoid this unwrap
|
&mut BufReader::new(file.as_ref().unwrap()), // TODO: avoid this unwrap
|
||||||
&mut fs::File::create(file_path)?,
|
&mut fs::File::create(file_path)?,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)?;
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Unpacked {} files to {}",
|
||||||
|
counter.load(std::sync::atomic::Ordering::Relaxed),
|
||||||
|
output.display()
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pack(args: ActionPack) -> Result<(), repak::Error> {
|
fn pack(args: ActionPack) -> Result<(), repak::Error> {
|
||||||
|
@ -260,14 +271,14 @@ fn pack(args: ActionPack) -> Result<(), repak::Error> {
|
||||||
paths.sort();
|
paths.sort();
|
||||||
|
|
||||||
let mut pak = repak::PakWriter::new(
|
let mut pak = repak::PakWriter::new(
|
||||||
BufWriter::new(File::create(output)?),
|
BufWriter::new(File::create(&output)?),
|
||||||
None,
|
None,
|
||||||
args.version,
|
args.version,
|
||||||
args.mount_point,
|
args.mount_point,
|
||||||
Some(args.path_hash_seed),
|
Some(args.path_hash_seed),
|
||||||
);
|
);
|
||||||
|
|
||||||
for p in paths {
|
for p in &paths {
|
||||||
let rel = &p
|
let rel = &p
|
||||||
.strip_prefix(input_path)
|
.strip_prefix(input_path)
|
||||||
.expect("file not in input directory")
|
.expect("file not in input directory")
|
||||||
|
@ -276,11 +287,13 @@ fn pack(args: ActionPack) -> Result<(), repak::Error> {
|
||||||
if args.verbose {
|
if args.verbose {
|
||||||
println!("packing {}", &rel);
|
println!("packing {}", &rel);
|
||||||
}
|
}
|
||||||
pak.write_file(rel, &mut BufReader::new(File::open(&p)?))?;
|
pak.write_file(rel, &mut BufReader::new(File::open(p)?))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pak.write_index()?;
|
pak.write_index()?;
|
||||||
|
|
||||||
|
println!("Packed {} files to {}", paths.len(), output.display());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +308,7 @@ fn get(args: ActionGet) -> Result<(), repak::Error> {
|
||||||
|
|
||||||
let full_path = mount_point.join(args.file);
|
let full_path = mount_point.join(args.file);
|
||||||
let file = full_path
|
let file = full_path
|
||||||
.strip_prefix(&prefix)
|
.strip_prefix(prefix)
|
||||||
.map_err(|_| repak::Error::Other("prefix does not match"))?;
|
.map_err(|_| repak::Error::Other("prefix does not match"))?;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
Loading…
Reference in a new issue