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/manifests.rs | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'src/minecraft/manifests.rs') diff --git a/src/minecraft/manifests.rs b/src/minecraft/manifests.rs index 8bdec26..64e38da 100644 --- a/src/minecraft/manifests.rs +++ b/src/minecraft/manifests.rs @@ -1,11 +1,18 @@ #![allow(dead_code)] -use std::collections::HashMap; - -use reqwest; +use crate::{constants::VERSION_MANIFEST_URL, errors::McError}; +use reqwest::get; use serde::Deserialize; +use serde_json::{from_str, Value}; +use std::collections::HashMap; +use McError::Config; -use crate::{constants::VERSION_MANIFEST_URL, errors::McError}; +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct JavaVersionInfo { + pub component: String, + pub major_version: u8, +} #[derive(Debug, Deserialize)] pub struct Version { @@ -19,6 +26,10 @@ pub struct Version { #[serde(rename = "assetIndex")] pub asset_index: Option, + + #[serde(default)] + #[serde(rename = "javaVersion")] + pub java_version: Option, } #[derive(Debug, Deserialize)] @@ -83,15 +94,13 @@ pub struct OsRule { pub async fn load_version( cfg: &crate::config::Config, ) -> Result { - let manifest_text = reqwest::get(VERSION_MANIFEST_URL) - .await? - .text() - .await?; - let root: serde_json::Value = serde_json::from_str(&manifest_text)?; + let manifest_text = get(VERSION_MANIFEST_URL).await?.text().await?; + let root: Value = from_str(&manifest_text)?; + let version_id = if cfg.version == "latest" { root["latest"]["release"] .as_str() - .ok_or_else(|| McError::Config("missing latest.release".into()))? + .ok_or_else(|| Config("missing latest.release".into()))? .to_string() } else { cfg.version.clone() @@ -99,21 +108,19 @@ pub async fn load_version( let versions = root["versions"] .as_array() - .ok_or_else(|| McError::Config("missing versions array".into()))?; + .ok_or_else(|| Config("missing versions array".into()))?; let version_entry = versions .iter() .find(|v| v["id"].as_str() == Some(&version_id)) - .ok_or_else(|| { - McError::Config(format!("version '{}' not found", version_id)) - })?; + .ok_or_else(|| Config(format!("version '{}' not found", version_id)))?; let url = version_entry["url"] .as_str() - .ok_or_else(|| McError::Config("missing version url".into()))?; + .ok_or_else(|| Config("missing version url".into()))?; - let version_text = reqwest::get(url).await?.text().await?; - let version: Version = serde_json::from_str(&version_text)?; + let version_text = get(url).await?.text().await?; + let version: Version = from_str(&version_text)?; Ok(version) } -- cgit v1.2.3