From 72ddd7b7704f2087a52c9c0552446682918c513b Mon Sep 17 00:00:00 2001 From: Filip Wandzio Date: Thu, 22 Jan 2026 23:14:08 +0100 Subject: Implement basic game files download logic Implement core clap arguments Respect XDG_BASE_DIR Currently library extraction is broken because it assumes every instace has it's own library folder. This should be refactored so instances share libraries Signed-off-by: Filip Wandzio --- src/minecraft/manifests.rs | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/minecraft/manifests.rs (limited to 'src/minecraft/manifests.rs') diff --git a/src/minecraft/manifests.rs b/src/minecraft/manifests.rs new file mode 100644 index 0000000..3cc59af --- /dev/null +++ b/src/minecraft/manifests.rs @@ -0,0 +1,80 @@ +#![allow(dead_code)] +use reqwest; +use serde::Deserialize; + +use crate::{constants::VERSION_MANIFEST_URL, errors::McError}; + +#[derive(Debug, Deserialize)] +pub struct Version { + pub id: String, + + #[serde(rename = "mainClass")] + pub main_class: String, + + pub downloads: Downloads, + pub libraries: Vec, +} + +#[derive(Debug, Deserialize)] +pub struct Downloads { + pub client: DownloadInfo, +} + +#[derive(Debug, Deserialize)] +pub struct DownloadInfo { + pub url: String, + pub sha1: String, + pub size: u64, +} + +#[derive(Debug, Deserialize)] +pub struct Library { + pub downloads: LibraryDownloads, +} + +#[derive(Debug, Deserialize)] +pub struct LibraryDownloads { + pub artifact: Option, +} + +#[derive(Debug, Deserialize)] +pub struct LibraryArtifact { + pub path: String, + pub url: String, + pub sha1: String, + pub size: u64, +} + +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 version_id = if cfg.version == "latest" { + root["latest"]["release"] + .as_str() + .ok_or_else(|| McError::Config("missing latest.release".into()))? + .to_string() + } else { + cfg.version.clone() + }; + + let versions = root["versions"] + .as_array() + .ok_or_else(|| McError::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)))?; + + let url = version_entry["url"] + .as_str() + .ok_or_else(|| McError::Config("missing version url".into()))?; + + let version_text = reqwest::get(url).await?.text().await?; + let version: Version = serde_json::from_str(&version_text)?; + + Ok(version) +} -- cgit v1.2.3