mirror of
https://github.com/gopher64/gopher64.git
synced 2026-07-11 01:25:20 +02:00
zip support
This commit is contained in:
+2
-1
@@ -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" }
|
||||
|
||||
|
||||
+22
-2
@@ -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<u8>) -> Vec<u8> {
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = 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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user