From e4de326b41dc48dbf8e6b0fbdf0e96a3ec7573c4 Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Mon, 18 Dec 2023 16:51:20 +0100 Subject: [PATCH] v0.6.4 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/fileop.rs | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/fileop.rs diff --git a/Cargo.lock b/Cargo.lock index 6f03082..2eb3eee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,7 +28,7 @@ dependencies = [ [[package]] name = "alterware-launcher" -version = "0.6.3" +version = "0.6.4" dependencies = [ "colored", "futures-util", diff --git a/Cargo.toml b/Cargo.toml index ef0d2d6..f262a21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "alterware-launcher" -version = "0.6.3" +version = "0.6.4" edition = "2021" build = "res/build.rs" diff --git a/src/fileop.rs b/src/fileop.rs new file mode 100644 index 0000000..f2f1f1b --- /dev/null +++ b/src/fileop.rs @@ -0,0 +1,22 @@ +use std::{fs, path::Path}; + +pub fn unzip(zip_path: &Path, out_path: &Path) { + let mut archive = zip::ZipArchive::new(fs::File::open(zip_path).unwrap()).unwrap(); + for i in 0..archive.len() { + let mut file = archive.by_index(i).unwrap(); + let outpath = out_path.join(file.name()); + + if (*file.name()).ends_with('/') { + fs::create_dir_all(outpath).unwrap(); + } else { + println!("Unpacking {}", file.name()); + if let Some(p) = outpath.parent() { + if !p.exists() { + fs::create_dir_all(p).unwrap(); + } + } + let mut outfile = fs::File::create(&outpath).unwrap(); + std::io::copy(&mut file, &mut outfile).unwrap(); + } + } +} \ No newline at end of file