Conflicting libraries fix

This commit is contained in:
2025-08-24 15:57:58 +02:00
parent 77280cd7d6
commit 63aae084e3
3 changed files with 46 additions and 4 deletions
Generated
+29
View File
@@ -831,6 +831,15 @@ version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "serde"
version = "1.0.219"
@@ -921,6 +930,7 @@ dependencies = [
"sha1",
"ureq",
"uuid",
"walkdir",
"zip",
]
@@ -1103,6 +1113,16 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "walkdir"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
dependencies = [
"same-file",
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
@@ -1194,6 +1214,15 @@ dependencies = [
"rustls-pki-types",
]
[[package]]
name = "winapi-util"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0978bf7171b3d90bac376700cb56d606feb40f251a475a5d6634613564460b22"
dependencies = [
"windows-sys",
]
[[package]]
name = "windows-core"
version = "0.61.2"
+1
View File
@@ -20,6 +20,7 @@ oauth2 = { version = "5.0.0", default-features = false }
open = "5"
uuid = "1.13.1"
md5 = "0.7"
walkdir = "2.5.0"
[lints.rust]
unsafe_code = "forbid"
+16 -4
View File
@@ -4,6 +4,7 @@ use std::{
};
use serde_json::Value;
use walkdir::WalkDir;
const META_SERVER: &str = "https://meta.fabricmc.net/";
const MAVEN_SERVER: &str = "https://maven.fabricmc.net/";
@@ -22,7 +23,7 @@ fn download_maven(url: &str, path: &Path) {
}
}
fn library_from_json(json: &Value) -> Option<(String, String)> {
fn library_from_json(json: &Value) -> Option<(String, String, String)> {
let name = json.get("name")?.as_str()?;
let url = json.get("url")?.as_str()?;
@@ -50,7 +51,7 @@ fn library_from_json(json: &Value) -> Option<(String, String)> {
.to_string_lossy()
.replace(' ', "_");
Some((full_url, local_path))
Some((name.to_string(), full_url, local_path))
}
pub fn install_fabric(minecraft_path: &Path, minecraft_version: &str, loader_version: &str) -> Result<(), crate::error::Error> {
@@ -60,6 +61,11 @@ pub fn install_fabric(minecraft_path: &Path, minecraft_version: &str, loader_ver
let profile_json = profile_dir.join(format!("{profile_name}.json"));
let libs_dir = minecraft_path.join("libraries");
let mut libs = WalkDir::new(&libs_dir)
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| e.file_type().is_file());
let mut json = query_meta_json(&format!("v2/versions/loader/{minecraft_version}/{loader_version}/profile/json"));
*json.get_mut("id").unwrap() = Value::String(profile_name.clone());
@@ -75,9 +81,15 @@ pub fn install_fabric(minecraft_path: &Path, minecraft_version: &str, loader_ver
.unwrap();
for lib_json in json.get("libraries").unwrap().as_array().unwrap() {
if let Some((url, path)) = library_from_json(lib_json) {
if let Some((name, url, path)) = library_from_json(lib_json) {
let lib_file = libs_dir.join(path);
download_maven(&url, &lib_file);
let lib_id = lib_file.parent().unwrap().parent().unwrap(); // Removes the version/lib.jar
if !libs.any(|e| e.path().starts_with(lib_id)) {
println!("Installing library '{name}'");
download_maven(&url, &lib_file);
} else {
println!("library '{name}' Already exists, skipping");
}
} else {
eprintln!("Failed to get json from {lib_json}")
}