fixed: review findings - robustness, dead code, missing tests
several smaller fixes from the code review: - add os_version to RuleContext + OsCondition for mojang rules that constrain natives selection by host version (rare, but in the spec). - factor mojang_os_name/arch/version into a shared launch_profile::system module instead of duplicating between net/mojang.rs and launch/mod.rs. - get_json and get_bytes now retry transient failures (5xx, connect, body decode) via a shared get_with_retry envelope; previously only download_file had retry logic. - migrate_legacy_meta_if_needed falls back to the stale cached profile with a warn log on network failure instead of erroring out (offline launches now work). - tightened legacy-loader detection by requiring the unique-to-rmcl gameArguments field; clearer error when loader_version is absent. - forge legacy versionInfo write uses compact serialization (no pretty-print key reorder). - deleted dead fetch_version_meta and save_profile_json. - documented quick-play templates omission in templates::lookup. - added end-to-end test that loads a vanilla profile from disk, loads a loader profile with inheritsFrom, resolves, renders, and snapshots.
This commit is contained in:
1 parent
19887643bc
commit
412e6ff91a
12 files changed
+395
-74
No files matched your search
@@ -0,0 +1,49 @@
|
||||
// system-detection helpers shared by launch and install paths. mojang
|
||||
// names some things differently from rust's std::env::consts (e.g. macOS
|
||||
// is "osx" in mojang profile rules), so this module is the single source
|
||||
// of truth for translating.
|
||||
|
||||
pub fn mojang_os_name() -> &'static str {
|
||||
match std::env::consts::OS {
|
||||
"macos" => "osx",
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mojang_arch_name() -> &'static str {
|
||||
match std::env::consts::ARCH {
|
||||
"x86" => "x86",
|
||||
"x86_64" => "x86_64",
|
||||
"aarch64" => "arm64",
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
// the host OS version string. mojang rules occasionally constrain natives
|
||||
// selection on os.version with a regex (e.g. macOS 10.x-only natives).
|
||||
// rust's stdlib doesn't expose this directly, so we synthesise something
|
||||
// useful per-platform. on linux we read the kernel version; on macOS the
|
||||
// product version is more useful but reading it requires shelling out so
|
||||
// we fall back to the kernel version. on windows we use a similar
|
||||
// approach. real-world profiles using os.version are rare; if this helper
|
||||
// returns an empty string the rule evaluator treats version constraints
|
||||
// as non-matching (defensive default).
|
||||
pub fn mojang_os_version() -> String {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::process::Command;
|
||||
if let Ok(out) = Command::new("uname").arg("-r").output()
|
||||
&& out.status.success()
|
||||
{
|
||||
return String::from_utf8_lossy(&out.stdout).trim().to_string();
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
{
|
||||
// crude - sufficient for the rare profile that needs windows version
|
||||
// gating. real launchers use GetVersionEx via winapi; we can add
|
||||
// that later if needed.
|
||||
return std::env::var("OS").unwrap_or_default();
|
||||
}
|
||||
String::new()
|
||||
}
|
||||
Reference in new issue
Block a user