Conflicting libraries fix
This commit is contained in:
+16
-4
@@ -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}")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user