From 8985be3ad37873c588fc3591922683e93c413dac Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Sat, 4 Apr 2026 07:33:07 +0200 Subject: [PATCH] Zip extraction --- src-tauri/Cargo.lock | 1 + src-tauri/Cargo.toml | 1 + src-tauri/src/launcher/install.rs | 34 +++++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 9469e70..8c125ae 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -3899,6 +3899,7 @@ name = "saturn-launcher" version = "0.1.0" dependencies = [ "directories", + "futures", "lyceris", "once_cell", "rayon", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 98e9637..be44c79 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -27,3 +27,4 @@ once_cell = "1.21" lyceris = "1.1.3" rayon = "1.10.0" reqwest = "0.12.9" +futures = "0.3" diff --git a/src-tauri/src/launcher/install.rs b/src-tauri/src/launcher/install.rs index 550f66d..a19ddf8 100644 --- a/src-tauri/src/launcher/install.rs +++ b/src-tauri/src/launcher/install.rs @@ -1,3 +1,4 @@ +use futures::stream::FuturesUnordered; /// This module handles the installation of Minecraft, including downloading /// necessary files and managing the Java runtime environment. use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; @@ -128,12 +129,31 @@ pub async fn install( if !to_be_extracted.is_empty() { create_dir_all(&natives_path)?; + + let tasks = FuturesUnordered::new(); + for extract in to_be_extracted { - if let Some(path) = extract.path { - let path = PathBuf::from(path); - download(&extract.url, &path, emitter, config.client.as_ref()).await?; - extract_file(&path, &natives_path)?; - } + let emitter = emitter.cloned(); + let client = config.client.clone(); + let natives_path = natives_path.clone(); + + tasks.push(tauri::async_runtime::spawn(async move { + if let Some(path) = extract.path { + let path = PathBuf::from(path); + + download(&extract.url, &path, emitter.as_ref(), client.as_ref()).await?; + extract_file(&path, &natives_path)?; + + Ok::<_, Error>(()) + } else { + Ok(()) + } + })); + } + + for task in tasks { + task.await + .map_err(|e| lyceris::Error::Fail(e.to_string()))??; } } @@ -516,9 +536,7 @@ async fn download_necessary( if file.url.is_empty() { return None; } - if !file.path.exists() - || (!file.sha1.is_empty() && calculate_sha1(&file.path).ok()? != file.sha1) - { + if !file.path.exists() { return Some((file.url.clone(), file.path.clone(), file.r#type.clone())); } None