forked from StrafesNET/map-tool
add unzip-all command
This commit is contained in:
parent
fa69c53cfc
commit
ff85efa54f
28
src/main.rs
28
src/main.rs
@ -19,6 +19,7 @@ enum Commands {
|
||||
Interactive,
|
||||
Replace,
|
||||
Scan,
|
||||
UnzipAll,
|
||||
Upload,
|
||||
}
|
||||
|
||||
@ -878,6 +879,32 @@ fn interactive() -> AResult<()>{
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn unzip_all()->AResult<()>{
|
||||
for entry in std::fs::read_dir("maps/unprocessed")? {
|
||||
let file_thing=entry?;
|
||||
println!("processing map={:?}",file_thing.file_name());
|
||||
let mut input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
|
||||
match maybe_gzip_decode(&mut input){
|
||||
Ok(ReaderType::GZip(mut readable)) => {
|
||||
//gzip
|
||||
let mut extracted:Vec<u8>=Vec::new();
|
||||
//read the entire thing to the end so that I can clone the data and write a png to processed images
|
||||
readable.read_to_end(&mut extracted)?;
|
||||
//write extracted
|
||||
let mut dest=std::path::PathBuf::from("maps/unzipped");
|
||||
dest.push(file_thing.file_name());
|
||||
std::fs::write(dest, &mut extracted)?;
|
||||
//delete ugly gzip file
|
||||
std::fs::remove_file(file_thing.path())?;
|
||||
},
|
||||
Ok(ReaderType::Raw(_)) => (),
|
||||
Err(e) => Err(e)?,
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> AResult<()> {
|
||||
let cli = Cli::parse();
|
||||
match cli.command {
|
||||
@ -888,6 +915,7 @@ fn main() -> AResult<()> {
|
||||
Commands::Interactive=>interactive(),
|
||||
Commands::Replace=>replace(),
|
||||
Commands::Scan=>scan(),
|
||||
Commands::UnzipAll=>unzip_all(),
|
||||
Commands::Upload=>upload(),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user