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/util/fs.rs | 26 +++++++++++++++++++++++++- src/util/sha1.rs | 7 ++++--- 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'src/util') diff --git a/src/util/fs.rs b/src/util/fs.rs index 8ecd0d0..b1e9152 100644 --- a/src/util/fs.rs +++ b/src/util/fs.rs @@ -4,7 +4,10 @@ use std::path::Path; use tokio::fs::remove_file; -use crate::errors::McError; +use crate::{ + errors::McError, + minecraft::manifests::{Library, Rule}, +}; pub async fn remove_if_exists(path: &Path) -> Result<(), McError> { if path.exists() { @@ -12,3 +15,24 @@ pub async fn remove_if_exists(path: &Path) -> Result<(), McError> { } Ok(()) } + +pub fn library_allowed(lib: &Library) -> bool { + let rules: &Vec = match &lib.rules { + | Some(r) => r, + | None => return true, + }; + + let mut allowed: bool = false; + + for rule in rules { + let os_match: bool = match &rule.os { + | Some(os) => os.name == "linux", + | None => true, + }; + if os_match { + allowed = rule.action == "allow"; + } + } + + allowed +} diff --git a/src/util/sha1.rs b/src/util/sha1.rs index 6684963..6fed18d 100644 --- a/src/util/sha1.rs +++ b/src/util/sha1.rs @@ -2,14 +2,15 @@ use std::path::Path; -use sha1::{Digest, Sha1}; +use sha1::{Digest, Sha1, Sha1Core}; +use sha1::digest::core_api::CoreWrapper; use tokio::fs::read; use crate::errors::McError; pub async fn sha1_hex(path: &Path) -> Result { - let data = read(path).await?; - let mut hasher = Sha1::new(); + let data: Vec = read(path).await?; + let mut hasher: CoreWrapper = Sha1::new(); hasher.update(&data); Ok(format!("{:x}", hasher.finalize())) } -- cgit v1.2.3