From f7b4b643ebc52a4d72d90d9adbdddc9aa0721e4a Mon Sep 17 00:00:00 2001 From: Filip Wandzio Date: Wed, 25 Feb 2026 16:10:23 +0100 Subject: Feat: Refactor core download logic with concurrency and async features Implement basic unit testing Implement automatic java executable switching based on game version Split loader module into smaller modules Implement basic documentation --- src/minecraft/extraction.rs | 70 ++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 45 deletions(-) (limited to 'src/minecraft/extraction.rs') diff --git a/src/minecraft/extraction.rs b/src/minecraft/extraction.rs index b58fd2e..292566f 100644 --- a/src/minecraft/extraction.rs +++ b/src/minecraft/extraction.rs @@ -1,11 +1,17 @@ -use std::{fs, io, path::Path}; +use std::{ + collections::HashMap, + fs, + fs::File, + io, + path::{Path, PathBuf}, +}; -use log::info; -use zip::ZipArchive; +use zip::{read::ZipFile, ZipArchive}; use crate::{ errors::McError, - minecraft::manifests::{Library, Version}, + minecraft::manifests::{LibraryArtifact, Version}, + util::fs::library_allowed, }; pub fn extract_natives( @@ -19,8 +25,6 @@ pub fn extract_natives( .join(&version.id) .join("natives"); - info!("Extracting natives for {} into {:?}", version.id, natives_dir); - if natives_dir.exists() { fs::remove_dir_all(&natives_dir)?; } @@ -31,75 +35,51 @@ pub fn extract_natives( continue; } - let natives = match &lib.natives { + let natives: &HashMap = match &lib.natives { | Some(n) => n, | None => continue, }; - let classifier = match natives.get("linux") { + let classifier: &String = match natives.get("linux") { | Some(c) => c, | None => continue, }; - let classifiers = match &lib.downloads.classifiers { - | Some(c) => c, - | None => continue, - }; + let classifiers: &HashMap = + match &lib.downloads.classifiers { + | Some(c) => c, + | None => continue, + }; - let artifact = match classifiers.get(classifier) { + let artifact: &LibraryArtifact = match classifiers.get(classifier) { | Some(a) => a, | None => continue, }; - let jar_path = cfg + let jar_path: PathBuf = cfg .data_dir .join("minecraft") .join("libraries") .join(&artifact.path); - info!("Extracting natives from {:?}", jar_path); - extract_zip(&jar_path, &natives_dir)?; } Ok(()) } - -fn library_allowed(lib: &Library) -> bool { - let rules = match &lib.rules { - | Some(r) => r, - | None => return true, - }; - - let mut allowed = false; - - for rule in rules { - let os_match = match &rule.os { - | Some(os) => os.name == "linux", - | None => true, - }; - - if os_match { - allowed = rule.action == "allow"; - } - } - - allowed -} - fn extract_zip(jar_path: &Path, out_dir: &Path) -> Result<(), McError> { - let file = fs::File::open(jar_path)?; - let mut zip = ZipArchive::new(file)?; + let file: File = File::open(jar_path)?; + let mut zip: ZipArchive = ZipArchive::new(file)?; for i in 0..zip.len() { - let mut entry = zip.by_index(i)?; - let name = entry.name(); + let mut entry: ZipFile = zip.by_index(i)?; + let name: &str = entry.name(); if name.starts_with("META-INF/") { continue; } - let out_path = out_dir.join(name); + let out_path: PathBuf = out_dir.join(name); if entry.is_dir() { fs::create_dir_all(&out_path)?; @@ -110,7 +90,7 @@ fn extract_zip(jar_path: &Path, out_dir: &Path) -> Result<(), McError> { fs::create_dir_all(parent)?; } - let mut out_file = fs::File::create(&out_path)?; + let mut out_file: File = File::create(&out_path)?; io::copy(&mut entry, &mut out_file)?; } -- cgit v1.2.3