summaryrefslogtreecommitdiffstats
path: root/src/launcher.rs
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2025-01-15 22:36:17 -0600
committerLibravatar bigfoot547 <[email protected]>2025-01-15 22:37:06 -0600
commite5d13bf03a3b7e8444ae367689852fcd6633e221 (patch)
tree9361fdfb51764d9c16092000552671afc25aaeb6 /src/launcher.rs
parentwip: asset index (diff)
assets done
Diffstat (limited to 'src/launcher.rs')
-rw-r--r--src/launcher.rs54
1 files changed, 32 insertions, 22 deletions
diff --git a/src/launcher.rs b/src/launcher.rs
index 184bcae..ccb84cb 100644
--- a/src/launcher.rs
+++ b/src/launcher.rs
@@ -10,6 +10,7 @@ use std::borrow::Cow;
use std::collections::HashMap;
use std::env::consts::{ARCH, OS};
use std::error::Error;
+use std::ffi::OsStr;
use std::fmt::{Display, Formatter};
use std::io::ErrorKind;
use std::path::{Component, Path, PathBuf};
@@ -28,6 +29,7 @@ use version::{VersionList, VersionResolveError, VersionResult};
use crate::version::{Logging, Library, OSRestriction, OperatingSystem};
pub use profile::{Instance, Profile};
+use crate::launcher::assets::{AssetError, AssetRepository};
use crate::util;
use crate::util::{FileVerifyError, IntegrityError};
@@ -135,7 +137,8 @@ pub struct Launcher {
system_info: SystemInfo,
- libraries: LibraryRepository
+ libraries: LibraryRepository,
+ assets: AssetRepository
}
#[derive(Debug)]
@@ -152,7 +155,10 @@ pub enum LaunchError {
LibraryDownloadError,
// log errors
- LogConfig(LogConfigError)
+ LogConfig(LogConfigError),
+
+ // asset errors
+ Assets(AssetError)
}
impl Display for LaunchError {
@@ -165,7 +171,8 @@ impl Display for LaunchError {
LaunchError::LibraryDirError(path, e) => write!(f, "failed to create library directory {}: {}", path.display(), e),
LaunchError::LibraryVerifyError(e) => write!(f, "failed to verify library: {}", e),
LaunchError::LibraryDownloadError => f.write_str("library download failed (see above logs for details)"), // TODO: booo this sucks
- LaunchError::LogConfig(e) => write!(f, "failed to configure logger: {}", e)
+ LaunchError::LogConfig(e) => write!(f, "failed to configure logger: {}", e),
+ LaunchError::Assets(e) => write!(f, "failed to fetch assets: {}", e)
}
}
}
@@ -179,6 +186,7 @@ impl Error for LaunchError {
LaunchError::LibraryDirError(_, e) => Some(e),
LaunchError::LibraryVerifyError(e) => Some(e),
LaunchError::LogConfig(e) => Some(e),
+ LaunchError::Assets(e) => Some(e),
_ => None
}
}
@@ -212,6 +220,8 @@ impl Launcher {
let settings_path = home.join("ozone.json");
let settings = Settings::load(&settings_path).await?;
+ let assets_path = home.join("assets");
+
Ok(Launcher {
online,
home: home.to_owned(),
@@ -221,7 +231,8 @@ impl Launcher {
system_info: SystemInfo::new(),
libraries: LibraryRepository {
home: home.join("libraries"),
- }
+ },
+ assets: AssetRepository::new(online, &assets_path).await?
})
}
@@ -350,16 +361,16 @@ impl Launcher {
* - (done) check which libraries we actually need (some have classifiers that don't apply to us)
* - (done) of the libraries we need, check which have correct size and sha1
* - (done) redownload necessary libraries
- * - (if offline mode and there are libraries to download, then explode violently)
+ * - (done) (if offline mode and there are libraries to download, then explode violently)
* - extract natives
* - (done) logging
* - (done) download the config if present and necessary
* - (done) (explode if offline mode and we need to download stuff)
* - assets
- * - get asset index (check if our local copy is good and redownload if not)
- * - check what ones are good and what needs to be downloaded
- * - download them
- * - (if offline mode, explode)
+ * - (done) get asset index (check if our local copy is good and redownload if not)
+ * - (done) check what ones are good and what needs to be downloaded
+ * - (done) download them
+ * - (done) (if offline mode, explode)
* - if virtual or resource-mapped, copy (or perhaps hardlink? that would be cool)
* - the actual client jar
* - check integriddy and download if needed
@@ -408,19 +419,11 @@ impl Launcher {
.map_err(|_| LaunchError::LibraryDownloadError)?;
} else {
info!("Verifying {} libraries...", downloads.len());
- stream::iter(downloads)
- .map(|dl| Ok(async move {
- debug!("Verifying library {}", dl.get_path().display());
- util::verify_file(dl.get_path(), dl.get_expect_size(), dl.get_expect_sha1()).await
- }))
- .try_buffer_unordered(8)
- .try_fold((), |_, _| async {Ok(())})
- .await
- .map_err(|e| {
- warn!("A library could not be verified: {}", e);
- warn!("Since the launcher is in offline mode, libraries cannot be downloaded. Please try again in online mode.");
- LaunchError::LibraryVerifyError(e)
- })?;
+ download::verify_files(downloads).await.map_err(|e| {
+ warn!("A library could not be verified: {}", e);
+ warn!("Since the launcher is in offline mode, libraries cannot be downloaded. Please try again in online mode.");
+ LaunchError::LibraryVerifyError(e)
+ })?;
}
let log_arg;
@@ -433,6 +436,13 @@ impl Launcher {
dbg!(log_arg);
+ if let Some(idx_download) = ver.asset_index.as_ref() {
+ let asset_idx = self.assets.load_index(idx_download, ver.assets.as_ref().map(|s| s.as_ref())).await
+ .map_err(|e| LaunchError::Assets(e))?;
+
+ self.assets.ensure_assets(&asset_idx).await.map_err(|e| LaunchError::Assets(e))?;
+ }
+
//todo!()
Ok(())
}