added: vanilla launch flow uses LaunchProfile with render + raw-byte storage

vanilla launches now read upstream mojang JSON via the new LaunchProfile
path, render game/JVM args through launch_profile::render with template
substitution, and store the cached meta.json byte-for-byte instead of
re-serializing through a narrow struct. legacy stripped meta.json files
are re-fetched on first launch. adds HttpClient::get_bytes and
fetch_version_meta_with_raw; collapses the two library-rule evaluators
into one shared launch_profile::rules::evaluate.
This commit is contained in:
objz committed 2026-05-25 14:51:34 +02:00
1 parent 22e4481a2b
commit 2029005c78
6 files changed
+629 -237

No files matched your search

+4
View File
@@ -71,6 +71,10 @@ impl HttpClient {
pub async fn get_json<T: DeserializeOwned>(&self, url: &str) -> Result<T, NetError> {
Ok(self.get(url).await?.json().await?)
}
pub async fn get_bytes(&self, url: &str) -> Result<Vec<u8>, NetError> {
Ok(self.get(url).await?.bytes().await?.to_vec())
}
}
const MAX_RETRIES: u32 = 3;
+34 -50
View File
@@ -76,7 +76,7 @@ pub struct Download {
pub struct Library {
pub name: String,
pub downloads: LibraryDownloads,
pub rules: Option<Vec<Rule>>,
pub rules: Option<Vec<crate::launch_profile::rules::Rule>>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
@@ -92,17 +92,6 @@ pub struct Artifact {
pub size: u64,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Rule {
pub action: String,
pub os: Option<OsRule>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct OsRule {
pub name: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct JavaVersion {
@@ -131,6 +120,20 @@ pub async fn fetch_version_meta(
client.get_json(&entry.url).await
}
// like fetch_version_meta but also returns the raw response bytes so the
// caller can write the upstream JSON byte-for-byte to disk. used by the
// install path so we don't lose data (e.g. arguments.jvm) by re-serializing
// through our narrow VersionMeta struct.
pub async fn fetch_version_meta_with_raw(
client: &HttpClient,
entry: &VersionEntry,
) -> Result<(VersionMeta, Vec<u8>), NetError> {
let raw = client.get_bytes(&entry.url).await?;
let parsed: VersionMeta = serde_json::from_slice(&raw)
.map_err(|e| NetError::Parse(format!("Failed to parse version meta: {e}")))?;
Ok((parsed, raw))
}
pub async fn download_client_jar(
client: &HttpClient,
meta: &VersionMeta,
@@ -169,9 +172,18 @@ pub async fn download_libraries(
) -> Result<(), NetError> {
set_action("Downloading libraries...");
let features = crate::launch_profile::rules::FeatureSet::default();
let rule_ctx = crate::launch_profile::rules::RuleContext {
os_name: mojang_os_name(),
arch: mojang_arch_name(),
features: &features,
};
let mut downloads = Vec::new();
for library in &meta.libraries {
if !library_allowed_for_current_os(library) {
if let Some(rules) = &library.rules
&& !crate::launch_profile::rules::evaluate(rules, &rule_ctx)
{
continue;
}
@@ -281,43 +293,6 @@ pub async fn download_assets(
result
}
// mojang's rule system is a bit quirky: no rules means "allow everywhere",
// and rules are evaluated in order where the last matching rule wins.
// a "disallow" for the current OS is an immediate reject though.
fn library_allowed_for_current_os(library: &Library) -> bool {
let rules = match &library.rules {
Some(rules) => rules,
None => return true,
};
let current_os = mojang_os_name();
let mut allowed = false;
for rule in rules {
let matches_os = match &rule.os {
Some(os_rule) => match &os_rule.name {
Some(name) => name == current_os,
None => true,
},
None => true,
};
if !matches_os {
continue;
}
if rule.action == "disallow" {
return false;
}
if rule.action == "allow" {
allowed = true;
}
}
allowed
}
// mojang calls macOS "osx" because apparently it's still 2012
fn mojang_os_name() -> &'static str {
match std::env::consts::OS {
@@ -326,6 +301,15 @@ fn mojang_os_name() -> &'static str {
}
}
fn mojang_arch_name() -> &'static str {
match std::env::consts::ARCH {
"x86" => "x86",
"x86_64" => "x86_64",
"aarch64" => "arm64",
other => other,
}
}
// bounded parallel downloader. spawns up to MAX_CONCURRENT_DOWNLOADS tasks
// and feeds new ones in as each completes. collects errors but keeps going
// so it downloads as much as possible before reporting the first failure.