From defc1b43bd040de7641235922c5192b05f00b9ea Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Thu, 25 Aug 2022 18:57:24 -0700 Subject: [PATCH] fix all sorts of zip stuff --- src-tauri/src/main.rs | 3 ++- src-tauri/src/unzip.rs | 61 ++++++++++++++---------------------------- src/utils/download.ts | 7 +++-- src/utils/zipUtils.ts | 3 +++ 4 files changed, 30 insertions(+), 44 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index e0d3971..80141c2 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -197,7 +197,8 @@ async fn get_bg_file(bg_path: String, appdata: String) -> String { let response_data: APIQuery = match serde_json::from_str(&query) { Ok(data) => data, Err(e) => { - println!("Failed to parse response: {}", e); + println!("Failed to get bg file response: {}", e); + println!("^ please stop reporting this as an error it's so annoying LMFAO"); return "".to_string(); } }; diff --git a/src-tauri/src/unzip.rs b/src-tauri/src/unzip.rs index 2680546..8e84d9f 100644 --- a/src-tauri/src/unzip.rs +++ b/src-tauri/src/unzip.rs @@ -64,27 +64,16 @@ pub fn unzip( println!("Is rar file? {}", zipfile.ends_with(".rar")); let name; + let mut success; // If file ends in zip, OR is unknown, extract as zip, otherwise extract as rar if zipfile.ends_with(".rar") { - extract_rar( - &window, - &zipfile, - &f, - &full_path, - top_level.unwrap_or(false), - ); + success = extract_rar(&zipfile, &f, &full_path, top_level.unwrap_or(true)); let archive = Archive::new(zipfile.clone()); name = archive.list().unwrap().next().unwrap().unwrap().filename; } else { - extract_zip( - &window, - &zipfile, - &f, - &full_path, - top_level.unwrap_or(false), - ); + success = extract_zip(&zipfile, &f, &full_path, top_level.unwrap_or(true)); // Get the name of the inenr file in the zip file let mut zip = zip::ZipArchive::new(&f).unwrap(); @@ -92,6 +81,14 @@ pub fn unzip( name = file.name().to_string().clone(); } + if !success { + let mut res_hash = std::collections::HashMap::new(); + + res_hash.insert("path".to_string(), zipfile.to_string()); + + window.emit("download_error", &res_hash).unwrap(); + } + // If the contents is a jar file, emit that we have extracted a new jar file if name.ends_with(".jar") { window @@ -129,13 +126,7 @@ pub fn unzip( }); } -fn extract_rar( - window: &tauri::Window, - rarfile: &String, - _f: &File, - full_path: &path::PathBuf, - _top_level: bool, -) { +fn extract_rar(rarfile: &String, _f: &File, full_path: &path::PathBuf, _top_level: bool) -> bool { let archive = Archive::new(rarfile.clone()); let mut open_archive = archive @@ -148,41 +139,29 @@ fn extract_rar( "Extracted rar file to: {}", full_path.to_str().unwrap_or("Error") ); + + true } Err(e) => { println!("Failed to extract rar file: {}", e); - let mut res_hash = std::collections::HashMap::new(); - - res_hash.insert("error".to_string(), e.to_string()); - res_hash.insert("path".to_string(), rarfile.to_string()); - - window.emit("download_error", &res_hash).unwrap(); + false } } } -fn extract_zip( - window: &tauri::Window, - zipfile: &String, - f: &File, - full_path: &path::PathBuf, - top_level: bool, -) { +fn extract_zip(zipfile: &String, f: &File, full_path: &path::PathBuf, top_level: bool) -> bool { match zip_extract::extract(f, full_path, top_level) { Ok(_) => { println!( "Extracted zip file to: {}", full_path.to_str().unwrap_or("Error") ); + + true } Err(e) => { println!("Failed to extract zip file: {}", e); - let mut res_hash = std::collections::HashMap::new(); - - res_hash.insert("error".to_string(), e.to_string()); - res_hash.insert("path".to_string(), zipfile.to_string()); - - window.emit("download_error", &res_hash).unwrap(); + false } - }; + } } diff --git a/src/utils/download.ts b/src/utils/download.ts index eb63419..2784bf5 100644 --- a/src/utils/download.ts +++ b/src/utils/download.ts @@ -78,13 +78,16 @@ export default class DownloadHandler { // 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) + // @ts-expect-error Too lazy to make an interface for payloads rn + const index = this.downloads.findIndex((download) => download.path === payload.file) this.downloads[index].status = 'extracting' }) listen('extract_end', ({ payload }) => { + console.log(payload) // Find the download that is no extracting and set it's status as such - const index = this.downloads.findIndex((download) => download.path === payload) + // @ts-expect-error Too lazy to make an interface for payloads rn + const index = this.downloads.findIndex((download) => download.path === payload.file) this.downloads[index].status = 'finished' }) } diff --git a/src/utils/zipUtils.ts b/src/utils/zipUtils.ts index 1b90554..bcea8bd 100644 --- a/src/utils/zipUtils.ts +++ b/src/utils/zipUtils.ts @@ -21,6 +21,9 @@ export function unzip( }) listen('extract_end', ({ payload }) => { + console.log(payload) + console.log(file) + // @ts-expect-error Payload is an object if (payload?.file === file) { resolve(payload as UnzipPayload)