diff options
Diffstat (limited to 'src/launcher.rs')
| -rw-r--r-- | src/launcher.rs | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/src/launcher.rs b/src/launcher.rs index eac79bb..0b1ea90 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -268,18 +268,6 @@ impl Launcher { lib.natives.as_ref().map_or(None, |n| n.get(&self.system_info.os)).map(|s| s.as_str()) } - fn create_extract_job(&self, lib: &Library) -> Option<LibraryExtractJob> { - if lib.natives.is_none() { - debug!("Not extracting natives for {}, no \"natives\".", lib.name); - return None; // do not extract this one - } - - Some(LibraryExtractJob { - source: self.libraries.get_full_artifact_path(lib.name.as_str(), self.choose_lib_classifier(lib))?, - rule: lib.extract.clone() - }) - } - async fn ensure_file(&self, path: &Path, dlinfo: &DownloadInfo) -> Result<(), LaunchError> { // verify the file match util::verify_file(path, dlinfo.size, dlinfo.sha1).await { @@ -406,7 +394,7 @@ impl Launcher { * - (done) of the libraries we need, check which have correct size and sha1 * - (done) redownload necessary libraries * - (done) (if offline mode and there are libraries to download, then explode violently) - * - extract natives + * - (done) extract natives * - (done) logging * - (done) download the config if present and necessary * - (done) (explode if offline mode and we need to download stuff) @@ -439,6 +427,7 @@ impl Launcher { info!("Resolved launch version {}!", ver.id); let mut libs = Vec::new(); + let mut extract_jobs = Vec::new(); let mut downloads = Vec::new(); for lib in ver.libraries.values() { @@ -449,6 +438,14 @@ impl Launcher { libs.push(lib); if let Some(dl) = self.libraries.create_download(lib, self.choose_lib_classifier(lib)) { dl.make_dirs().await.map_err(|e| LaunchError::LibraryDirError(dl.get_path().to_path_buf(), e))?; + + if lib.natives.is_some() { + extract_jobs.push(LibraryExtractJob { + source: dl.get_path().to_owned(), + rule: lib.extract.clone() + }); + } + downloads.push(dl); } } @@ -512,9 +509,7 @@ impl Launcher { // extract natives (execute this function unconditionally because we still need the natives dir to exist) info!("Extracting natives."); - let natives_dir = self.libraries.extract_natives(libs.iter().filter_map(|lib| { - self.create_extract_job(*lib) - }).collect::<Vec<_>>()).await?; + let natives_dir = self.libraries.extract_natives(extract_jobs).await?; //todo!() Ok(()) @@ -545,6 +540,7 @@ impl Error for LibraryError { } } +#[derive(Debug)] struct LibraryExtractJob { source: PathBuf, rule: Option<LibraryExtractRule> @@ -571,14 +567,14 @@ impl LibraryRepository { if let Some(classifier) = classifier { match n.len() { - 3 => Some(PathBuf::from(strsub::replace_thru(format!("{}-{}-{}.jar", n[1], n[2], classifier), Self::lib_replace))), - 4 => Some(PathBuf::from(strsub::replace_thru(format!("{}-{}-{}-{}.jar", n[1], n[2], classifier, n[3]), Self::lib_replace))), + 2 => Some(PathBuf::from(strsub::replace_thru(format!("{}-{}-{}.jar", n[0], n[1], classifier), Self::lib_replace))), + 3 => Some(PathBuf::from(strsub::replace_thru(format!("{}-{}-{}-{}.jar", n[0], n[1], classifier, n[2]), Self::lib_replace))), _ => None } } else { match n.len() { - 3 => Some(PathBuf::from(strsub::replace_thru(format!("{}-{}.jar", n[1], n[2]), Self::lib_replace))), - 4 => Some(PathBuf::from(strsub::replace_thru(format!("{}-{}-{}.jar", n[1], n[2], n[3]), Self::lib_replace))), + 2 => Some(PathBuf::from(strsub::replace_thru(format!("{}-{}.jar", n[0], n[1]), Self::lib_replace))), + 3 => Some(PathBuf::from(strsub::replace_thru(format!("{}-{}-{}.jar", n[0], n[1], n[2]), Self::lib_replace))), _ => None } } @@ -592,10 +588,6 @@ impl LibraryRepository { p.push(Self::get_artifact_filename(name, classifier)?); Some(p) } - - fn get_full_artifact_path(&self, name: &str, classifier: Option<&str>) -> Option<PathBuf> { - Some(self.home.join(Self::get_artifact_path(name, classifier)?)) - } fn create_download(&self, lib: &Library, classifier: Option<&str>) -> Option<VerifiedDownload> { if lib.url.is_some() || lib.downloads.is_none() { @@ -660,6 +652,7 @@ impl LibraryRepository { } async fn extract_natives<'lib>(&self, libs: Vec<LibraryExtractJob>) -> Result<PathBuf, LaunchError> { + let libs = libs; fs::create_dir_all(&self.natives).await.map_err(|e| LaunchError::IO { what: "creating natives directory", error: e @@ -678,10 +671,11 @@ impl LibraryRepository { let mut tally = 0usize; for job in libs { + debug!("Extracting natives for {}", job.source.display()); tally += extract::extract_zip(&job.source, &natives_dir, |name| job.rule.as_ref().is_some_and(|rules| rules.exclude.iter().filter(|ex| - name.starts_with(ex.as_str())).next().is_some()))?; + name.starts_with(ex.as_str())).next().is_none()))?; } Ok((natives_dir, tally)) |
