add unzip-all command

This commit is contained in:
Quaternions 2023-10-02 19:04:48 -07:00
parent fa69c53cfc
commit ff85efa54f

View File

@ -19,6 +19,7 @@ enum Commands {
Interactive, Interactive,
Replace, Replace,
Scan, Scan,
UnzipAll,
Upload, Upload,
} }
@ -878,6 +879,32 @@ fn interactive() -> AResult<()>{
Ok(()) 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<()> { fn main() -> AResult<()> {
let cli = Cli::parse(); let cli = Cli::parse();
match cli.command { match cli.command {
@ -888,6 +915,7 @@ fn main() -> AResult<()> {
Commands::Interactive=>interactive(), Commands::Interactive=>interactive(),
Commands::Replace=>replace(), Commands::Replace=>replace(),
Commands::Scan=>scan(), Commands::Scan=>scan(),
Commands::UnzipAll=>unzip_all(),
Commands::Upload=>upload(), Commands::Upload=>upload(),
} }
} }