refactor: share loader library downloads and validate settings
This commit is contained in:
1 parent
783fb76f06
commit
7e7e5c0c31
7 files changed
+126
-89
No files matched your search
+10
-32
@@ -5,9 +5,8 @@ use std::path::Path;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::feedback::progress::set_sub_action;
|
||||
use crate::instance::loader::GameVersion;
|
||||
use crate::net::{HttpClient, NetError, download_file};
|
||||
use crate::net::{HttpClient, NetError, download_loader_libraries};
|
||||
|
||||
const FABRIC_META_BASE: &str = "https://meta.fabricmc.net/v2";
|
||||
|
||||
@@ -150,40 +149,19 @@ pub async fn download_fabric_libraries(
|
||||
profile: &FabricProfile,
|
||||
meta_dir: &Path,
|
||||
) -> Result<(), NetError> {
|
||||
let libraries_dir = crate::storage::MetadataPaths::new(meta_dir).libraries();
|
||||
tracing::debug!(
|
||||
"Resolving {} Fabric libraries into {}",
|
||||
profile.libraries.len(),
|
||||
libraries_dir.display()
|
||||
crate::storage::MetadataPaths::new(meta_dir)
|
||||
.libraries()
|
||||
.display()
|
||||
);
|
||||
|
||||
for lib in &profile.libraries {
|
||||
let maven_path = match crate::instance::loader::maven::maven_coord_to_path(&lib.name) {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
return Err(NetError::Parse(format!(
|
||||
"Invalid Maven coordinate: {}",
|
||||
lib.name
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
let dest = libraries_dir.join(&maven_path);
|
||||
|
||||
if dest.exists() {
|
||||
tracing::debug!("Fabric library already exists: {}", lib.name);
|
||||
continue;
|
||||
}
|
||||
|
||||
let base_url = lib.url.trim_end_matches('/');
|
||||
let download_url = format!("{}/{}", base_url, maven_path);
|
||||
|
||||
set_sub_action(&lib.name);
|
||||
tracing::info!("Downloading Fabric library: {}", lib.name);
|
||||
tracing::trace!("Fabric library destination: {}", dest.display());
|
||||
|
||||
download_file(client, &download_url, &dest, |_, _| {}).await?;
|
||||
}
|
||||
let libraries: Vec<_> = profile
|
||||
.libraries
|
||||
.iter()
|
||||
.map(|lib| (lib.name.as_str(), lib.url.as_str()))
|
||||
.collect();
|
||||
download_loader_libraries(client, libraries, meta_dir, "Fabric").await?;
|
||||
|
||||
tracing::debug!("Fabric library resolution complete for {}", profile.id);
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user