From a88b46ad52f39d18916f8919b09f2bb5b7e5329f Mon Sep 17 00:00:00 2001 From: Logan McNaughton <848146+loganmc10@users.noreply.github.com> Date: Wed, 11 Oct 2023 21:21:39 -0600 Subject: [PATCH] zip support --- Cargo.toml | 3 ++- src/main.rs | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 73256c5..90251e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,8 @@ edition = "2021" [dependencies] dirs = "5.0" -governor = "0.6.0" +zip = "0.6" +governor = "0.6" sha2 = "0.10" sdl2-sys = { git = "https://github.com/Rust-SDL2/rust-sdl2.git" } diff --git a/src/main.rs b/src/main.rs index 1a23fb1..4787a61 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #![feature(round_ties_even)] use std::env; use std::fs; +use std::io::Read; mod device; mod ui; @@ -32,8 +33,27 @@ fn swap_rom(contents: Vec) -> Vec { fn main() { let args: Vec = env::args().collect(); - let file_path = &args[1]; - let mut contents = fs::read(file_path).expect("Should have been able to read the file"); + let file_path = std::path::Path::new(&args[1]); + let mut contents = vec![]; + if file_path.extension().unwrap().to_ascii_lowercase() == "zip" { + let zip_file = fs::File::open(file_path).unwrap(); + let mut archive = zip::ZipArchive::new(zip_file).unwrap(); + for i in 0..archive.len() { + let mut file = archive.by_index(i).unwrap(); + let extension = file + .enclosed_name() + .unwrap() + .extension() + .unwrap() + .to_ascii_lowercase(); + if extension == "z64" || extension == "n64" || extension == "v64" { + file.read_to_end(&mut contents) + .expect("could not read zip file"); + } + } + } else { + contents = fs::read(file_path).expect("Should have been able to read the file"); + } contents = swap_rom(contents);