Start of a refactor

Added a schema + some tests and light wrapper functions.
master
itycodes 1 week ago
parent 23d5e8cc29
commit 220a2b4553

344
Cargo.lock generated

@ -8,12 +8,39 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]]
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]]
name = "autocfg"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "base64"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
[[package]]
name = "bumpalo"
version = "3.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
[[package]]
name = "cc"
version = "1.2.3"
@ -29,6 +56,25 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825"
dependencies = [
"android-tzdata",
"iana-time-zone",
"num-traits",
"serde",
"windows-targets",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "crc32fast"
version = "1.4.2"
@ -63,6 +109,51 @@ version = "0.8.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
[[package]]
name = "darling"
version = "0.20.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.20.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.20.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806"
dependencies = [
"darling_core",
"quote",
"syn",
]
[[package]]
name = "deranged"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"
dependencies = [
"powerfmt",
"serde",
]
[[package]]
name = "displaydoc"
version = "0.2.5"
@ -80,6 +171,12 @@ version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "flate2"
version = "1.0.35"
@ -90,6 +187,12 @@ dependencies = [
"miniz_oxide",
]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "form_urlencoded"
version = "1.2.1"
@ -110,6 +213,47 @@ dependencies = [
"wasi",
]
[[package]]
name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hashbrown"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "iana-time-zone"
version = "0.1.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"windows-core",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]]
name = "icu_collections"
version = "1.5.0"
@ -228,6 +372,12 @@ dependencies = [
"syn",
]
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "idna"
version = "1.0.3"
@ -249,12 +399,44 @@ dependencies = [
"icu_properties",
]
[[package]]
name = "indexmap"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
"autocfg",
"hashbrown 0.12.3",
"serde",
]
[[package]]
name = "indexmap"
version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652"
dependencies = [
"equivalent",
"hashbrown 0.15.2",
"serde",
]
[[package]]
name = "itoa"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
[[package]]
name = "js-sys"
version = "0.3.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
dependencies = [
"once_cell",
"wasm-bindgen",
]
[[package]]
name = "libc"
version = "0.2.168"
@ -280,6 +462,7 @@ dependencies = [
"rayon",
"serde",
"serde_json",
"serde_with",
"ureq",
]
@ -298,6 +481,21 @@ dependencies = [
"adler2",
]
[[package]]
name = "num-conv"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]]
name = "once_cell"
version = "1.20.2"
@ -310,6 +508,12 @@ version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "powerfmt"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "proc-macro2"
version = "1.0.92"
@ -395,6 +599,12 @@ dependencies = [
"untrusted",
]
[[package]]
name = "rustversion"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4"
[[package]]
name = "ryu"
version = "1.0.18"
@ -433,6 +643,36 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_with"
version = "3.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6b6f7f2fcb69f747921f79f3926bd1e203fce4fef62c268dd3abfb6d86029aa"
dependencies = [
"base64",
"chrono",
"hex",
"indexmap 1.9.3",
"indexmap 2.7.1",
"serde",
"serde_derive",
"serde_json",
"serde_with_macros",
"time",
]
[[package]]
name = "serde_with_macros"
version = "3.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d00caa5193a3c8362ac2b73be6b9e768aa5a4b2f721d8f4b339600c3cb51f8e"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "shlex"
version = "1.3.0"
@ -457,6 +697,12 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "subtle"
version = "2.6.1"
@ -485,6 +731,37 @@ dependencies = [
"syn",
]
[[package]]
name = "time"
version = "0.3.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21"
dependencies = [
"deranged",
"itoa",
"num-conv",
"powerfmt",
"serde",
"time-core",
"time-macros",
]
[[package]]
name = "time-core"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
[[package]]
name = "time-macros"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de"
dependencies = [
"num-conv",
"time-core",
]
[[package]]
name = "tinystr"
version = "0.7.6"
@ -552,6 +829,64 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
dependencies = [
"cfg-if",
"once_cell",
"rustversion",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
dependencies = [
"bumpalo",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
dependencies = [
"unicode-ident",
]
[[package]]
name = "webpki-roots"
version = "0.26.7"
@ -561,6 +896,15 @@ dependencies = [
"rustls-pki-types",
]
[[package]]
name = "windows-core"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-sys"
version = "0.52.0"

@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
rayon = "1.10.0"
serde = "1.0.216"
serde = { version = "1.0.216", features = ["derive"] }
serde_json = "1.0.133"
serde_with = "3.12.0"
ureq = "2.12.1"

@ -0,0 +1,39 @@
pub mod manifest;
pub struct MinecraftVersion {
pub version_json: manifest::VersionJson,
}
pub fn get_latest_version() -> Result<MinecraftVersion, ureq::Error> {
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<MinecraftVersion, ureq::Error> {
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<manifest::AssetIndex, ureq::Error> {
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<manifest::Library> {
todo!("Stub; Needs filtering by os name, taking into account both the blacklist and whitelist");
}
}

@ -0,0 +1,232 @@
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use std::collections::HashMap;
#[derive(Serialize, Deserialize, Debug)]
pub struct VersionManifest {
pub latest: Latest,
pub versions: Vec<Version>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Latest {
pub release: String,
pub snapshot: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Version {
pub id: String,
#[serde(rename = "type")]
pub type_: String,
pub url: String,
pub time: String,
#[serde(rename = "releaseTime")]
pub release_time: String,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug)]
pub struct AssetIndexUrl {
pub id: String,
pub sha1: String,
pub size: u64,
pub url: String,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug)]
pub struct VersionJson {
pub arguments: Option<Arguments>,
#[serde(rename = "assetIndex")]
pub asset_index: AssetIndexUrl,
pub assets: String,
#[serde(rename = "complianceLevel")]
pub compliance_level: Option<u32>,
pub downloads: Downloads,
pub id: String,
#[serde(rename = "javaVersion")]
pub java_version: Option<JavaVersion>,
pub libraries: Vec<Library>,
pub logging: Option<Logging>,
#[serde(rename = "mainClass")]
pub main_class: String,
#[serde(rename = "minimumLauncherVersion")]
pub minimum_launcher_version: u32,
#[serde(rename = "releaseTime")]
pub release_time: String,
pub time: String,
#[serde(rename = "type")]
pub type_: String,
#[serde(rename = "minecraftArguments")]
pub minecraft_arguments: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Arguments {
pub game: Option<Vec<GameArgument>>,
pub jvm: Option<Vec<JVMArgument>>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum GameArgument {
String(String),
Complex(GameArgumentComplex),
}
#[derive(Serialize, Deserialize, Debug)]
pub struct GameArgumentComplex {
pub rules: Option<Vec<Rule>>,
pub value: ValueType,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum JVMArgument {
String(String),
Complex(JVMArgumentComplex),
}
#[derive(Serialize, Deserialize, Debug)]
pub struct JVMArgumentComplex {
pub rules: Option<Vec<Rule>>,
pub value: ValueType,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum ValueType {
String(String),
VecString(Vec<String>),
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Rule {
pub action: String,
pub os: Option<OS>,
pub features: Option<HashMap<String, bool>>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct OS {
pub arch: Option<String>,
pub name: Option<String>,
pub version: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct AssetIndex {
pub objects: HashMap<String, AssetObject>,
#[serde(rename = "virtual")]
pub virtual_: Option<bool>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct AssetObject {
pub hash: String,
pub size: u64,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Downloads {
pub client: DownloadFile,
#[serde(rename = "client_mappings")]
pub client_mappings: Option<DownloadFile>,
pub server: DownloadFile,
#[serde(rename = "server_mappings")]
pub server_mappings: Option<DownloadFile>,
#[serde(rename = "windows_server")]
pub windows_server: Option<DownloadFile>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct DownloadFile {
pub sha1: String,
pub size: u64,
pub url: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct JavaVersion {
pub component: String,
#[serde(rename = "majorVersion")]
pub major_version: u32,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Library {
pub downloads: LibraryDownloads,
pub name: String,
pub rules: Option<Vec<Rule>>,
pub extract: Option<Extract>,
pub natives: Option<Natives>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum LibraryDownloads {
Artifact(LibraryArtifact),
Classifiers(LibraryClassifiers),
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LibraryArtifact {
pub artifact: LibraryFile,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LibraryClassifiers {
pub classifiers: Classifiers,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Classifiers {
#[serde(rename = "natives-linux")]
pub natives_linux: Option<LibraryFile>,
#[serde(rename = "natives-osx")]
pub natives_osx: Option<LibraryFile>,
#[serde(rename = "natives-windows")]
pub natives_windows: Option<LibraryFile>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LibraryFile {
pub path: String,
pub sha1: String,
pub size: u64,
pub url: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Extract {
pub exclude: Vec<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Natives {
pub linux: String,
pub osx: String,
pub windows: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Logging {
pub client: LoggingClient,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LoggingClient {
pub argument: String,
pub file: LoggingFile,
#[serde(rename = "type")]
pub type_: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LoggingFile {
pub id: String,
pub sha1: String,
pub size: u64,
pub url: String,
}

@ -0,0 +1,119 @@
use mclaunch::manifest::*;
#[test]
fn test_arguments() {
let src = r#"
{
"game": [
{
"rules": [
],
"value": [
"--quickPlayRealms",
"${quickPlayRealms}"
]
}
],
"jvm": [
]
}
"#;
let arguments: Arguments = serde_json::from_str(src).unwrap();
println!("{:#?}", arguments);
}
#[test]
fn test_basic_decode() {
// Grab minecraft version manifest
let response = ureq::get("https://launchermeta.mojang.com/mc/game/version_manifest.json").call();
let version_manifest = response.unwrap().into_string().unwrap();
// Deserialize the version manifest
let version_manifest: VersionManifest = serde_json::from_str(&version_manifest).unwrap();
// Print the version manifest
println!("{:#?}", version_manifest);
// fetch the latest release version
let latest_release = &version_manifest.latest.release;
// Print the latest release version
println!("Latest release version: {}", latest_release);
// Fetch the Version struct for the latest release version
let latest_release_version = version_manifest.versions.iter().find(
|version| version.id.as_str() == latest_release.as_str())
.unwrap();
// Print the latest release version struct
println!("{:#?}", latest_release_version);
// Fetch the version manifest for the latest release version
let response = ureq::get(&latest_release_version.url).call();
let version_json = response.unwrap().into_string().unwrap();
// Print the version manifest for the latest release version
println!("{}", version_json);
// Deserialize the version manifest for the latest release version
let version_json: VersionJson = serde_json::from_str(&version_json).unwrap();
// Print the version manifest for the latest release version
println!("{:#?}", version_json);
// Grab the asset index url
let asset_index_url = &version_json.asset_index.url;
// Print the asset index url
println!("Asset index url: {}", asset_index_url);
// Fetch the asset index
let response = ureq::get(asset_index_url).call();
let asset_index = response.unwrap().into_string().unwrap();
// Print the asset index
println!("{}", asset_index);
// Deserialize the asset index
let asset_index: AssetIndex = serde_json::from_str(&asset_index).unwrap();
// Print the asset index
println!("{:#?}", asset_index);
}
#[test]
fn test_164_decode() {
// Grab minecraft version manifest
let response = ureq::get("https://launchermeta.mojang.com/mc/game/version_manifest.json").call();
let version_manifest = response.unwrap().into_string().unwrap();
// Deserialize the version manifest
let version_manifest: VersionManifest = serde_json::from_str(&version_manifest).unwrap();
// Print the version manifest
println!("{:#?}", version_manifest);
// fetch the 1.6.4 version
let version_164 = version_manifest.versions.iter().find(
|version| version.id.as_str() == "1.6.4")
.unwrap();
// Print the 1.6.4 version
println!("{:#?}", version_164);
// Fetch the version manifest for the 1.6.4 version
let response = ureq::get(&version_164.url).call();
let version_json = response.unwrap().into_string().unwrap();
// Print the version manifest for the 1.6.4 version
println!("{}", version_json);
// Deserialize the version manifest for the 1.6.4 version
let version_json: VersionJson = serde_json::from_str(&version_json).unwrap();
// Print the version manifest for the 1.6.4 version
println!("{:#?}", version_json);
// Grab the asset index url
let asset_index_url = &version_json.asset_index.url;
// Print the asset index url
println!("Asset index url: {}", asset_index_url);
// Fetch the asset index
let response = ureq::get(asset_index_url).call();
let asset_index = response.unwrap().into_string().unwrap();
// Print the asset index
println!("{}", asset_index);
// Deserialize the asset index
let asset_index: AssetIndex = serde_json::from_str(&asset_index).unwrap();
// Print the asset index
println!("{:#?}", asset_index);
}
#[test]
fn test_latest_decode() {
let latest = mclaunch::get_latest_version().unwrap();
let _asset_index = latest.get_asset_index().unwrap();
}
#[test]
fn test_164_decode_latest() {
let version_164 = mclaunch::fetch_version("1.6.4").unwrap();
let _asset_index = version_164.get_asset_index().unwrap();
}
Loading…
Cancel
Save