summaryrefslogtreecommitdiffstats
path: root/src/launcher.rs
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2025-01-14 02:51:02 -0600
committerLibravatar bigfoot547 <[email protected]>2025-01-14 02:51:02 -0600
commit7a42235af574a3a8f07db8ccc3189ce735213ce8 (patch)
tree275b230cb93ed70ee7b0aadd1e5e1dc7da9eccef /src/launcher.rs
parentlibrary downloads complete (diff)
verify libraries when offline
Diffstat (limited to 'src/launcher.rs')
-rw-r--r--src/launcher.rs53
1 files changed, 38 insertions, 15 deletions
diff --git a/src/launcher.rs b/src/launcher.rs
index 83ec342..1f28257 100644
--- a/src/launcher.rs
+++ b/src/launcher.rs
@@ -13,18 +13,20 @@ use std::fmt::{Display, Formatter};
use std::io::ErrorKind;
use std::path::{Path, PathBuf};
use const_format::formatcp;
-use futures::StreamExt;
+use futures::{stream, StreamExt, TryStreamExt};
use log::{debug, info, warn};
use serde::{Deserialize, Serialize};
use sysinfo::System;
use tokio::{fs, io};
use version::VersionList;
-use download::{MultiDownloader, PhaseDownloadError, VerifiedDownload};
+use download::{MultiDownloader, VerifiedDownload};
use rules::{CompatCheck, IncompatibleError};
use version::{VersionResolveError, VersionResult};
use crate::version::{Library, OSRestriction, OperatingSystem};
pub use profile::{Instance, Profile};
+use crate::util;
+use crate::util::FileVerifyError;
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Settings {
@@ -102,7 +104,9 @@ pub enum LaunchError {
IncompatibleVersion(IncompatibleError),
// library errors
- LibraryDirError(PathBuf, io::Error)
+ LibraryDirError(PathBuf, io::Error),
+ LibraryVerifyError(FileVerifyError),
+ LibraryDownloadError
}
impl Display for LaunchError {
@@ -112,7 +116,9 @@ impl Display for LaunchError {
LaunchError::LoadVersion(e) => write!(f, "error loading remote version: {e}"),
LaunchError::ResolveVersion(e) => write!(f, "error resolving remote version: {e}"),
LaunchError::IncompatibleVersion(e) => e.fmt(f),
- LaunchError::LibraryDirError(path, e) => write!(f, "failed to create library directory {}: {}", path.display(), e)
+ 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
}
}
}
@@ -124,6 +130,7 @@ impl Error for LaunchError {
LaunchError::ResolveVersion(e) => Some(e),
LaunchError::IncompatibleVersion(e) => Some(e),
LaunchError::LibraryDirError(_, e) => Some(e),
+ LaunchError::LibraryVerifyError(e) => Some(e),
_ => None
}
}
@@ -175,9 +182,9 @@ impl Launcher {
* - java runtime
* - normal process (good research, past figboot :3)
* - libraries
- * - check which libraries we actually need (some have classifiers that don't apply to us)
- * - of the libraries we need, check which have correct size and sha1
- * - redownload necessary libraries
+ * - (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)
* - extract natives
* - logging
@@ -222,14 +229,30 @@ impl Launcher {
}
}
- // TODO: offline
- info!("Downloading {} libraries...", downloads.len());
-
- let mut multi = MultiDownloader::new(downloads);
- let dl: Vec<_> = multi.perform().await.collect().await;
- info!("amogus: {dl:?}");
-
- // todo: offline mode
+ if self.online {
+ info!("Downloading {} libraries...", downloads.len());
+ let mut multi = MultiDownloader::new(downloads);
+ multi.perform().await
+ .inspect_err(|e| warn!("library download failed: {e}"))
+ .try_fold((), |_, _| async {Ok(())})
+ .await
+ .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(5)
+ .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)
+ })?;
+ }
//todo!()
Ok(())