From e9ef94170764c5ca0dfe4e1f1af71428eb7e4b06 Mon Sep 17 00:00:00 2001 From: Logan McNaughton <848146+loganmc10@users.noreply.github.com> Date: Wed, 11 Oct 2023 22:08:22 -0600 Subject: [PATCH] 7z support --- Cargo.toml | 1 + src/main.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 90251e1..f9672de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" dirs = "5.0" zip = "0.6" governor = "0.6" +sevenz-rust = "0.5" 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 50b4721..ecc1732 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,6 +52,30 @@ fn main() { break; } } + } else if file_path.extension().unwrap().to_ascii_lowercase() == "7z" { + let mut archive = + sevenz_rust::SevenZReader::open(file_path, sevenz_rust::Password::empty()).unwrap(); + + let mut found = false; + archive + .for_each_entries( + &mut |entry: &sevenz_rust::SevenZArchiveEntry, reader: &mut dyn std::io::Read| { + let name = entry.name().to_ascii_lowercase(); + if !found + && (name.ends_with("z64") || name.ends_with("n64") || name.ends_with("v64")) + { + reader + .read_to_end(&mut contents) + .expect("could not read zip file"); + found = true; + } else { + //skip other files + std::io::copy(reader, &mut std::io::sink())?; + } + Ok(true) + }, + ) + .expect("ok"); } else { contents = fs::read(file_path).expect("Should have been able to read the file"); }