extraction

This commit is contained in:
SpikeHD
2022-05-15 20:39:02 -07:00
parent bdee5c8906
commit f8af7caaff
6 changed files with 86 additions and 143 deletions

138
src-tauri/Cargo.lock generated
View File

@@ -14,18 +14,6 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
[[package]]
name = "aes"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8"
dependencies = [
"cfg-if 1.0.0",
"cipher",
"cpufeatures",
"opaque-debug",
]
[[package]]
name = "aho-corasick"
version = "0.7.18"
@@ -78,7 +66,7 @@ dependencies = [
"num-traits",
"rusticata-macros",
"thiserror",
"time",
"time 0.3.9",
]
[[package]]
@@ -213,12 +201,6 @@ version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "base64ct"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a32fd6af2b5827bce66c29053ba0e7c42b9dcab01835835058558c10851a46b"
[[package]]
name = "bincode"
version = "1.3.3"
@@ -460,15 +442,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cipher"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7"
dependencies = [
"generic-array",
]
[[package]]
name = "cocoa"
version = "0.24.0"
@@ -519,12 +492,6 @@ dependencies = [
"cache-padded",
]
[[package]]
name = "constant_time_eq"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]]
name = "convert_case"
version = "0.4.0"
@@ -707,7 +674,7 @@ dependencies = [
"tokio-rustls",
"tokio-tungstenite",
"tracing",
"zip",
"zip-extract",
]
[[package]]
@@ -851,7 +818,6 @@ checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
dependencies = [
"block-buffer",
"crypto-common",
"subtle",
]
[[package]]
@@ -1500,15 +1466,6 @@ dependencies = [
"libc",
]
[[package]]
name = "hmac"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
dependencies = [
"digest",
]
[[package]]
name = "html5ever"
version = "0.25.2"
@@ -1581,7 +1538,7 @@ dependencies = [
"rand 0.8.5",
"rcgen",
"thiserror",
"time",
"time 0.3.9",
"tokio",
"tokio-rustls",
"tokio-tungstenite",
@@ -1918,7 +1875,7 @@ dependencies = [
"dirs-next",
"objc-foundation",
"objc_id",
"time",
"time 0.3.9",
]
[[package]]
@@ -2295,12 +2252,6 @@ version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
[[package]]
name = "opaque-debug"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "open"
version = "2.1.2"
@@ -2456,35 +2407,12 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "password-hash"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d791538a6dcc1e7cb7fe6f6b58aca40e7f79403c45b2bc274008b5e647af1d8"
dependencies = [
"base64ct",
"rand_core 0.6.3",
"subtle",
]
[[package]]
name = "pathdiff"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
[[package]]
name = "pbkdf2"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271779f35b581956db91a3e55737327a03aa051e90b1c47aeb189508533adfd7"
dependencies = [
"digest",
"hmac",
"password-hash",
"sha2",
]
[[package]]
name = "pem"
version = "1.0.2"
@@ -2895,7 +2823,7 @@ checksum = "d7fa2d386df8533b02184941c76ae2e0d0c1d053f5d43339169d80f21275fc5e"
dependencies = [
"pem",
"ring",
"time",
"time 0.3.9",
"x509-parser",
"yasna",
]
@@ -3344,17 +3272,6 @@ dependencies = [
"digest",
]
[[package]]
name = "sha1"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c77f4e7f65455545c2153c1253d25056825e77ee2533f0e41deb65a93a34852f"
dependencies = [
"cfg-if 1.0.0",
"cpufeatures",
"digest",
]
[[package]]
name = "sha2"
version = "0.10.2"
@@ -3540,12 +3457,6 @@ dependencies = [
"syn",
]
[[package]]
name = "subtle"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
version = "1.0.92"
@@ -3910,6 +3821,16 @@ dependencies = [
"once_cell",
]
[[package]]
name = "time"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "time"
version = "0.3.9"
@@ -4851,7 +4772,7 @@ dependencies = [
"ring",
"rusticata-macros",
"thiserror",
"time",
"time 0.3.9",
]
[[package]]
@@ -4875,27 +4796,32 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "346d34a236c9d3e5f3b9b74563f238f955bbd05fa0b8b4efa53c130c43982f4c"
dependencies = [
"time",
"time 0.3.9",
]
[[package]]
name = "zip"
version = "0.6.2"
version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf225bcf73bb52cbb496e70475c7bd7a3f769df699c0020f6c7bd9a96dcf0b8d"
checksum = "93ab48844d61251bb3835145c521d88aa4031d7139e8485990f60ca911fa0815"
dependencies = [
"aes",
"byteorder",
"bzip2",
"constant_time_eq",
"crc32fast",
"crossbeam-utils 0.8.8",
"flate2",
"hmac",
"pbkdf2",
"sha1",
"time",
"zstd",
"thiserror",
"time 0.1.43",
]
[[package]]
name = "zip-extract"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c5cc0309f6e81ab96c2b43d5e935025f8732c886690be8f78f68e06bad1d274"
dependencies = [
"log",
"thiserror",
"zip",
]
[[package]]

View File

@@ -19,7 +19,7 @@ serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0-rc.9", features = ["api-all"] }
# zip library
zip = "0.6.2"
zip-extract = "0.1.1"
# For creating a "global" downloads list
lazy_static = "1.4.0"

View File

@@ -1,11 +1,12 @@
use zip;
use zip_extract;
use std::fs::File;
use std::io::Read;
use std::path;
use std::thread;
#[tauri::command]
pub fn unzip(zipfile: &str, zippath: &str, destpath: &str) {
// Read file
let f = match File::open(zipfile) {
pub fn unzip(window: tauri::Window, zipfile: String, destpath: String) {
// Read file TODO: replace test file
let f = match File::open(&zipfile) {
Ok(f) => f,
Err(e) => {
println!("Failed to open zip file: {}", e);
@@ -13,27 +14,27 @@ pub fn unzip(zipfile: &str, zippath: &str, destpath: &str) {
}
};
let reader = std::io::Cursor::new(&f);
let writePath = path::PathBuf::from(&destpath);
// Init zip reader
let mut zip = match zip::ZipArchive::new(&f) {
Ok(zip) => zip,
Err(e) => {
println!("Could not open zip file: {}", e);
return;
}
};
// Run extraction in seperate thread
thread::spawn(move || {
let fullPath = writePath;
let zipData = match zip.by_name(zippath) {
Ok(zipData) => zipData,
Err(e) => {
println!("Could not find zip file: {}", e);
println!("Path: {}", zippath);
return;
}
};
println!("Unzipping file! {}", &zipfile);
println!("Zip: {}", zipData.size());
println!("Name: {}", zipData.name());
println!("Directory? {}", zipData.is_dir());
window.emit("extract_start", &zipfile);
match zip_extract::extract(f, &fullPath, true) {
Ok(_) => {
println!("Extracted zip file to: {}", fullPath.to_str().unwrap_or("Error"));
},
Err(e) => {
println!("Failed to extract zip file: {}", e);
}
};
println!("Unzipping done!");
window.emit("extract_end", &zipfile);
});
}

View File

@@ -65,14 +65,18 @@ export default class Downloads extends React.Component<IProps, IState> {
async downloadGrasscutterStable() {
const folder = await this.getGrasscutterFolder()
this.props.downloadManager.addDownload(STABLE_DOWNLOAD, folder + '\\grasscutter.zip')
this.props.downloadManager.addDownload(STABLE_DOWNLOAD, folder + '\\grasscutter.zip', () =>{
unzip(folder + '\\grasscutter.zip', folder + '\\')
})
this.disableButtons()
}
async downloadGrasscutterLatest() {
const folder = await this.getGrasscutterFolder()
this.props.downloadManager.addDownload(DEV_DOWNLOAD, folder + '\\grasscutter.zip')
this.props.downloadManager.addDownload(DEV_DOWNLOAD, folder + '\\grasscutter.zip', () =>{
unzip(folder + '\\grasscutter.zip', folder + '\\')
})
this.disableButtons()
}
@@ -80,7 +84,7 @@ export default class Downloads extends React.Component<IProps, IState> {
async downloadResources() {
const folder = await this.getGrasscutterFolder()
this.props.downloadManager.addDownload(RESOURCES_DOWNLOAD, folder + '\\resources.zip', () => {
unzip(folder + '\\resources.zip', 'Grasscutter_Resources-main/Resources/', folder + '/resources')
unzip(folder + '\\resources.zip', folder + '\\')
})
this.disableButtons()

View File

@@ -18,13 +18,13 @@ export default class DownloadHandler {
constructor() {
this.downloads = []
listen('download_progress', (...payload) => {
listen('download_progress', ({ payload }) => {
// @ts-expect-error Payload may be unknown but backend always returns this object
const obj: {
downloaded: string,
total: string,
path: string,
} = payload[0].payload
} = payload
const index = this.downloads.findIndex(download => download.path === obj.path)
this.downloads[index].progress = parseInt(obj.downloaded, 10)
@@ -37,9 +37,9 @@ export default class DownloadHandler {
this.downloads[index].speed = byteToString(speed) + '/s'
})
listen('download_finished', (...payload) => {
listen('download_finished', ({ payload }) => {
// Remove from array
const filename = payload[0]?.payload
const filename = payload
// set status to finished
const index = this.downloads.findIndex(download => download.path === filename)
@@ -52,18 +52,31 @@ export default class DownloadHandler {
}
})
listen('download_error', (...payload) => {
listen('download_error', ({ payload }) => {
// @ts-expect-error shut up typescript
const errorData: {
path: string,
error: string,
} = payload[0]?.payload
} = payload
// Set download to error
const index = this.downloads.findIndex(download => download.path === errorData.path)
this.downloads[index].status = 'error'
this.downloads[index].error = errorData.error
})
// Extraction events
listen('extract_start', ({ payload }) => {
// Find the download that is no extracting and set it's status as such
const index = this.downloads.findIndex(download => download.path === payload)
this.downloads[index].status = 'extracting'
})
listen('extract_end', ({ payload }) => {
// Find the download that is no extracting and set it's status as such
const index = this.downloads.findIndex(download => download.path === payload)
this.downloads[index].status = 'finished'
})
}
getDownloads() {

View File

@@ -1,9 +1,8 @@
import { invoke } from '@tauri-apps/api'
export function unzip(file: string, zippath: string, dest: string) {
export function unzip(file: string, dest: string) {
invoke('unzip', {
zipfile: file,
zippath: zippath,
destpath: dest,
})
}