mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 16:14:48 +01:00
fix all sorts of zip stuff
This commit is contained in:
@@ -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) {
|
let response_data: APIQuery = match serde_json::from_str(&query) {
|
||||||
Ok(data) => data,
|
Ok(data) => data,
|
||||||
Err(e) => {
|
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();
|
return "".to_string();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -64,27 +64,16 @@ pub fn unzip(
|
|||||||
println!("Is rar file? {}", zipfile.ends_with(".rar"));
|
println!("Is rar file? {}", zipfile.ends_with(".rar"));
|
||||||
|
|
||||||
let name;
|
let name;
|
||||||
|
let mut success;
|
||||||
|
|
||||||
// If file ends in zip, OR is unknown, extract as zip, otherwise extract as rar
|
// If file ends in zip, OR is unknown, extract as zip, otherwise extract as rar
|
||||||
if zipfile.ends_with(".rar") {
|
if zipfile.ends_with(".rar") {
|
||||||
extract_rar(
|
success = extract_rar(&zipfile, &f, &full_path, top_level.unwrap_or(true));
|
||||||
&window,
|
|
||||||
&zipfile,
|
|
||||||
&f,
|
|
||||||
&full_path,
|
|
||||||
top_level.unwrap_or(false),
|
|
||||||
);
|
|
||||||
|
|
||||||
let archive = Archive::new(zipfile.clone());
|
let archive = Archive::new(zipfile.clone());
|
||||||
name = archive.list().unwrap().next().unwrap().unwrap().filename;
|
name = archive.list().unwrap().next().unwrap().unwrap().filename;
|
||||||
} else {
|
} else {
|
||||||
extract_zip(
|
success = extract_zip(&zipfile, &f, &full_path, top_level.unwrap_or(true));
|
||||||
&window,
|
|
||||||
&zipfile,
|
|
||||||
&f,
|
|
||||||
&full_path,
|
|
||||||
top_level.unwrap_or(false),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Get the name of the inenr file in the zip file
|
// Get the name of the inenr file in the zip file
|
||||||
let mut zip = zip::ZipArchive::new(&f).unwrap();
|
let mut zip = zip::ZipArchive::new(&f).unwrap();
|
||||||
@@ -92,6 +81,14 @@ pub fn unzip(
|
|||||||
name = file.name().to_string().clone();
|
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 the contents is a jar file, emit that we have extracted a new jar file
|
||||||
if name.ends_with(".jar") {
|
if name.ends_with(".jar") {
|
||||||
window
|
window
|
||||||
@@ -129,13 +126,7 @@ pub fn unzip(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_rar(
|
fn extract_rar(rarfile: &String, _f: &File, full_path: &path::PathBuf, _top_level: bool) -> bool {
|
||||||
window: &tauri::Window,
|
|
||||||
rarfile: &String,
|
|
||||||
_f: &File,
|
|
||||||
full_path: &path::PathBuf,
|
|
||||||
_top_level: bool,
|
|
||||||
) {
|
|
||||||
let archive = Archive::new(rarfile.clone());
|
let archive = Archive::new(rarfile.clone());
|
||||||
|
|
||||||
let mut open_archive = archive
|
let mut open_archive = archive
|
||||||
@@ -148,41 +139,29 @@ fn extract_rar(
|
|||||||
"Extracted rar file to: {}",
|
"Extracted rar file to: {}",
|
||||||
full_path.to_str().unwrap_or("Error")
|
full_path.to_str().unwrap_or("Error")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
true
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Failed to extract rar file: {}", e);
|
println!("Failed to extract rar file: {}", e);
|
||||||
let mut res_hash = std::collections::HashMap::new();
|
false
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_zip(
|
fn extract_zip(zipfile: &String, f: &File, full_path: &path::PathBuf, top_level: bool) -> bool {
|
||||||
window: &tauri::Window,
|
|
||||||
zipfile: &String,
|
|
||||||
f: &File,
|
|
||||||
full_path: &path::PathBuf,
|
|
||||||
top_level: bool,
|
|
||||||
) {
|
|
||||||
match zip_extract::extract(f, full_path, top_level) {
|
match zip_extract::extract(f, full_path, top_level) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
println!(
|
println!(
|
||||||
"Extracted zip file to: {}",
|
"Extracted zip file to: {}",
|
||||||
full_path.to_str().unwrap_or("Error")
|
full_path.to_str().unwrap_or("Error")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
true
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Failed to extract zip file: {}", e);
|
println!("Failed to extract zip file: {}", e);
|
||||||
let mut res_hash = std::collections::HashMap::new();
|
false
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,13 +78,16 @@ export default class DownloadHandler {
|
|||||||
// Extraction events
|
// Extraction events
|
||||||
listen('extract_start', ({ payload }) => {
|
listen('extract_start', ({ payload }) => {
|
||||||
// Find the download that is no extracting and set it's status as such
|
// 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'
|
this.downloads[index].status = 'extracting'
|
||||||
})
|
})
|
||||||
|
|
||||||
listen('extract_end', ({ payload }) => {
|
listen('extract_end', ({ payload }) => {
|
||||||
|
console.log(payload)
|
||||||
// Find the download that is no extracting and set it's status as such
|
// 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'
|
this.downloads[index].status = 'finished'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ export function unzip(
|
|||||||
})
|
})
|
||||||
|
|
||||||
listen('extract_end', ({ payload }) => {
|
listen('extract_end', ({ payload }) => {
|
||||||
|
console.log(payload)
|
||||||
|
console.log(file)
|
||||||
|
|
||||||
// @ts-expect-error Payload is an object
|
// @ts-expect-error Payload is an object
|
||||||
if (payload?.file === file) {
|
if (payload?.file === file) {
|
||||||
resolve(payload as UnzipPayload)
|
resolve(payload as UnzipPayload)
|
||||||
|
|||||||
Reference in New Issue
Block a user