mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-15 00:24:45 +01:00
comments
This commit is contained in:
@@ -4,7 +4,8 @@ use std::io::Read;
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn unzip(zipfile: &str, zippath: &str, destpath: &str) {
|
pub fn unzip(zipfile: &str, zippath: &str, destpath: &str) {
|
||||||
let mut f = match File::open(zipfile) {
|
// Read file
|
||||||
|
let f = match File::open(zipfile) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Failed to open zip file: {}", e);
|
println!("Failed to open zip file: {}", e);
|
||||||
@@ -12,8 +13,9 @@ pub fn unzip(zipfile: &str, zippath: &str, destpath: &str) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut reader = std::io::Cursor::new(&f);
|
let reader = std::io::Cursor::new(&f);
|
||||||
|
|
||||||
|
// Init zip reader
|
||||||
let mut zip = match zip::ZipArchive::new(&f) {
|
let mut zip = match zip::ZipArchive::new(&f) {
|
||||||
Ok(zip) => zip,
|
Ok(zip) => zip,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -22,8 +24,10 @@ pub fn unzip(zipfile: &str, zippath: &str, destpath: &str) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Iterate zip files
|
||||||
for i in 0..zip.len()
|
for i in 0..zip.len()
|
||||||
{
|
{
|
||||||
|
// Get file
|
||||||
let mut file = match zip.by_index(i) {
|
let mut file = match zip.by_index(i) {
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -33,13 +37,17 @@ pub fn unzip(zipfile: &str, zippath: &str, destpath: &str) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
println!("Filename: {}", file.name());
|
println!("Filename: {}", file.name());
|
||||||
|
|
||||||
|
// Read the first byte if it is a file
|
||||||
let first_byte = match file.bytes().next() {
|
let first_byte = match file.bytes().next() {
|
||||||
Some(b) => b.unwrap(),
|
Some(b) => b,
|
||||||
None => {
|
None => {
|
||||||
println!("File is empty: {}", &zipfile);
|
println!("Could not read first byte of file");
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Output first byte
|
||||||
println!("{:?}", first_byte);
|
println!("{:?}", first_byte);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user