delete zips after extraction and autoset jar file

This commit is contained in:
SpikeHD
2022-05-16 17:49:52 -07:00
parent f530ffdd2c
commit 3f9aa48bc2
4 changed files with 144 additions and 7 deletions

112
src-tauri/Cargo.lock generated
View File

@@ -14,6 +14,18 @@ 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"
@@ -201,6 +213,12 @@ 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"
@@ -442,6 +460,15 @@ 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"
@@ -492,6 +519,12 @@ 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"
@@ -675,6 +708,7 @@ dependencies = [
"tokio-rustls",
"tokio-tungstenite",
"tracing",
"zip 0.6.2",
"zip-extract",
]
@@ -819,6 +853,7 @@ checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
dependencies = [
"block-buffer",
"crypto-common",
"subtle",
]
[[package]]
@@ -1467,6 +1502,15 @@ 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"
@@ -2253,6 +2297,12 @@ 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"
@@ -2408,12 +2458,35 @@ 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"
@@ -3273,6 +3346,17 @@ 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"
@@ -3467,6 +3551,12 @@ 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"
@@ -4824,6 +4914,26 @@ dependencies = [
"time 0.1.43",
]
[[package]]
name = "zip"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf225bcf73bb52cbb496e70475c7bd7a3f769df699c0020f6c7bd9a96dcf0b8d"
dependencies = [
"aes",
"byteorder",
"bzip2",
"constant_time_eq",
"crc32fast",
"crossbeam-utils 0.8.8",
"flate2",
"hmac",
"pbkdf2",
"sha1",
"time 0.3.9",
"zstd",
]
[[package]]
name = "zip-extract"
version = "0.1.1"
@@ -4832,7 +4942,7 @@ checksum = "4c5cc0309f6e81ab96c2b43d5e935025f8732c886690be8f78f68e06bad1d274"
dependencies = [
"log",
"thiserror",
"zip",
"zip 0.5.13",
]
[[package]]

View File

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

View File

@@ -1,4 +1,5 @@
use zip_extract;
use zip;
use std::fs::File;
use std::path;
use std::thread;
@@ -14,17 +15,17 @@ pub fn unzip(window: tauri::Window, zipfile: String, destpath: String) {
}
};
let writePath = path::PathBuf::from(&destpath);
let write_path = path::PathBuf::from(&destpath);
// Run extraction in seperate thread
thread::spawn(move || {
let fullPath = writePath;
let full_path = write_path;
window.emit("extract_start", &zipfile);
window.emit("extract_start", &zipfile).unwrap();
match zip_extract::extract(f, &fullPath, true) {
match zip_extract::extract(&f, &full_path, true) {
Ok(_) => {
println!("Extracted zip file to: {}", fullPath.to_str().unwrap_or("Error"));
println!("Extracted zip file to: {}", full_path.to_str().unwrap_or("Error"));
},
Err(e) => {
println!("Failed to extract zip file: {}", e);
@@ -44,6 +45,26 @@ pub fn unzip(window: tauri::Window, zipfile: String, destpath: String) {
}
};
window.emit("extract_end", &zipfile);
// Get the name of the inenr file in the zip file
let mut zip = zip::ZipArchive::new(&f).unwrap();
let file = zip.by_index(0).unwrap();
let name = file.name();
// If the contents is a jar file, emit that we have extracted a new jar file
if name.ends_with(".jar") {
window.emit("jar_extracted", destpath.to_string() + name).unwrap();
}
// Delete zip file
match std::fs::remove_file(&zipfile) {
Ok(_) => {
println!("Deleted zip file: {}", zipfile);
},
Err(e) => {
println!("Failed to delete zip file: {}", e);
}
};
window.emit("extract_end", &zipfile).unwrap();
});
}

View File

@@ -14,6 +14,7 @@ import DownloadList from './components/common/DownloadList'
import Downloads from './components/menu/Downloads'
import NewsSection from './components/news/NewsSection'
import RightBar from './components/RightBar'
import { setConfigOption } from '../utils/configuration'
interface IProps {
[key: string]: never;
@@ -41,6 +42,10 @@ class App extends React.Component<IProps, IState> {
listen('lang_error', (payload) => {
console.log(payload)
})
listen('jar_extracted', ({ payload }) => {
setConfigOption('grasscutter_path', payload)
})
}
render() {