pub mod manifest; pub struct MinecraftVersion { pub version_json: manifest::VersionJson, } pub fn get_latest_version() -> Result { let response = ureq::get("https://launchermeta.mojang.com/mc/game/version_manifest.json").call(); let version_manifest = response.unwrap().into_string().unwrap(); let version_manifest: manifest::VersionManifest = serde_json::from_str(&version_manifest).unwrap(); let latest_release = &version_manifest.latest.release; fetch_version(latest_release) } pub fn fetch_version(version_name: &str) -> Result { let response = ureq::get("https://launchermeta.mojang.com/mc/game/version_manifest.json").call(); let version_manifest = response.unwrap().into_string().unwrap(); let version_manifest: manifest::VersionManifest = serde_json::from_str(&version_manifest).unwrap(); let selected_version = version_manifest.versions.iter().find( |version| version.id.as_str() == version_name) .unwrap(); let response = ureq::get(&selected_version.url).call(); let version_json = response.unwrap().into_string().unwrap(); let version_json: manifest::VersionJson = serde_json::from_str(&version_json).unwrap(); Ok(MinecraftVersion { version_json: version_json }) } impl MinecraftVersion { pub fn get_asset_index(&self) -> Result { let response = ureq::get(&self.version_json.asset_index.url).call(); let asset_index = response.unwrap().into_string().unwrap(); let asset_index: manifest::AssetIndex = serde_json::from_str(&asset_index).unwrap(); Ok(asset_index) } pub fn get_libraries_for_os(&self, os: &str) -> Vec { todo!("Stub; Needs filtering by os name, taking into account both the blacklist and whitelist"); } }