mc_bootstrap/
classpath.rs1use std::path::{Path, PathBuf};
2
3use crate::{manifest::Library, rules::is_all_rules_satisfied};
4
5pub fn should_use_library(lib: &Library) -> bool {
6 let rules_opt = &lib.rules;
7 if !rules_opt.is_some() {
8 return true;
9 }
10
11 let rules = rules_opt.as_ref().unwrap();
12 return is_all_rules_satisfied(rules);
13}
14
15pub fn create_classpath(
16 jar_file: PathBuf,
17 libraries_path: PathBuf,
18 libraries: Vec<Library>,
19) -> String {
20 let mut classpath = jar_file.to_str().unwrap().to_string();
21
22 for lib in libraries.iter() {
23 let should_use = should_use_library(lib);
24 if should_use {
25 let artifact = &lib.downloads.artifact;
26 let lib_path = artifact.path.clone();
27 let fixed_lib_path = Path::new(&libraries_path).join(lib_path.replace("/", "\\"));
28 classpath = format!("{};{}", classpath, fixed_lib_path.to_str().unwrap());
29 }
30 }
31
32 return classpath;
33}