7z support

This commit is contained in:
Logan McNaughton
2023-10-11 22:08:22 -06:00
parent 861abeb5cc
commit e9ef941707
2 changed files with 25 additions and 0 deletions
+1
View File
@@ -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" }
+24
View File
@@ -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");
}