diff options
| author | 2026-01-18 12:19:43 +0800 | |
|---|---|---|
| committer | 2026-01-18 12:19:43 +0800 | |
| commit | 76086e65a7caf1bb8aa54a9404c70a714bc00da8 (patch) | |
| tree | afb2f9c8719888827933e209f4dace74f3e83341 /src-tauri/src/core | |
| parent | af7f8aec576b34d11bf136a75542822a74d7f335 (diff) | |
| download | DropOut-76086e65a7caf1bb8aa54a9404c70a714bc00da8.tar.gz DropOut-76086e65a7caf1bb8aa54a9404c70a714bc00da8.zip | |
fix(manifest): add find_root_version for nested inheritance resolution
Add find_root_version() function to walk the inheritance chain and find
the root vanilla Minecraft version from a modded version (Fabric/Forge).
This is useful for determining which vanilla version's client.jar should
be used when launching modded versions, as modded versions inherit from
vanilla versions but don't contain their own client.jar.
The function follows the inheritsFrom field recursively until reaching
a version without a parent (the root vanilla version).
Diffstat (limited to 'src-tauri/src/core')
| -rw-r--r-- | src-tauri/src/core/manifest.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src-tauri/src/core/manifest.rs b/src-tauri/src/core/manifest.rs index 637b935..e792071 100644 --- a/src-tauri/src/core/manifest.rs +++ b/src-tauri/src/core/manifest.rs @@ -97,6 +97,43 @@ pub async fn fetch_vanilla_version( Ok(resp) } +/// Find the root vanilla version by following the inheritance chain. +/// +/// For modded versions (Fabric, Forge), this walks up the `inheritsFrom` +/// chain to find the base vanilla Minecraft version. +/// +/// # Arguments +/// * `game_dir` - The .minecraft directory path +/// * `version_id` - The version ID to start from +/// +/// # Returns +/// The ID of the root vanilla version (the version without `inheritsFrom`) +pub async fn find_root_version( + game_dir: &std::path::Path, + version_id: &str, +) -> Result<String, Box<dyn Error + Send + Sync>> { + let mut current_id = version_id.to_string(); + + // Keep following the inheritance chain + loop { + let version = match load_local_version(game_dir, ¤t_id).await { + Ok(v) => v, + Err(_) => { + // If not found locally, assume it's a vanilla version (root) + return Ok(current_id); + } + }; + + // If this version has no parent, it's the root + if let Some(parent_id) = version.inherits_from { + current_id = parent_id; + } else { + // This is the root + return Ok(current_id); + } + } +} + /// Load a version, checking local first, then fetching from remote if needed. /// /// For modded versions (those with `inheritsFrom`), this will also resolve |