diff options
| author | 2025-01-13 03:05:17 -0600 | |
|---|---|---|
| committer | 2025-01-13 03:05:17 -0600 | |
| commit | 6d0fb7c0f2fc9bf144b50b6bb00328b3f7057832 (patch) | |
| tree | 38d2840748e5593522542a8fb1c48776afa855fa /src | |
| parent | add some logging and stuff (diff) | |
more stuff
Diffstat (limited to 'src')
| -rw-r--r-- | src/launcher.rs | 31 | ||||
| -rw-r--r-- | src/launcher/download.rs | 15 | ||||
| -rw-r--r-- | src/version.rs | 27 |
3 files changed, 60 insertions, 13 deletions
diff --git a/src/launcher.rs b/src/launcher.rs index a7ef8c9..a849cc5 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -22,8 +22,9 @@ use tokio::{fs, io}; use tokio::io::AsyncReadExt; use version::VersionList; use profile::{Instance, Profile}; +use crate::launcher::download::{Download, VerifiedDownload}; use crate::launcher::version::{VersionResolveError, VersionResult}; -use crate::version::{Library, OSRestriction, OperatingSystem}; +use crate::version::{DownloadInfo, Library, OSRestriction, OperatingSystem}; #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct Settings { @@ -72,8 +73,7 @@ impl Settings { struct SystemInfo { os: OperatingSystem, os_version: String, - arch: String, - arch_bits: usize + arch: String } struct LibraryRepository { @@ -155,7 +155,9 @@ impl Launcher { settings_path, settings, system_info: SystemInfo::new(), - libraries: LibraryRepository { home: home.join("libraries") } + libraries: LibraryRepository { + home: home.join("libraries"), + } }) } @@ -195,6 +197,8 @@ impl Launcher { let ver = self.versions.resolve_version(ver.as_ref()).await.map_err(|e| LaunchError::ResolveVersion(e))?; + // todo: make a list of all the required libraries + todo!() } } @@ -258,6 +262,22 @@ impl LibraryRepository { p.push(Self::get_artifact_filename(name, classifier)?); Some(p) } + + fn create_download(&self, lib: &Library, os: OperatingSystem) -> Option<VerifiedDownload> { + let classifier = lib.natives.as_ref()?.get(&os).map(|s| s.as_str()); + + if lib.url.is_some() || lib.downloads.is_none() { + // TODO: derive download URL in this situation? + warn!("BUG: Deprecated case for library {}: url present or downloads missing. The launcher does not support out-of-line checksums at this time. Not downloading this library.", lib.name); + return None; + } + + let dlinfo = lib.downloads.as_ref()?.get_download_info(classifier)?; + // drinking game: take a shot once per heap allocation + let path = self.home.join(dlinfo.path.as_ref().map(PathBuf::from).or_else(|| Self::get_artifact_path(lib.name.as_str(), classifier))?); + + Some(VerifiedDownload::new(dlinfo.url.as_ref()?, path.as_path(), dlinfo.size, dlinfo.sha1)) + } } impl SystemInfo { @@ -283,8 +303,7 @@ impl SystemInfo { SystemInfo { os, os_version, - arch, - arch_bits: size_of::<*const i32>() * 8 + arch } } diff --git a/src/launcher/download.rs b/src/launcher/download.rs index 8c24cae..ec89a15 100644 --- a/src/launcher/download.rs +++ b/src/launcher/download.rs @@ -8,7 +8,7 @@ use reqwest::{Client, IntoUrl, Method, RequestBuilder}; use sha1_smol::{Digest, Sha1}; use tokio::fs; use tokio::fs::File; -use tokio::io::{AsyncReadExt, AsyncWriteExt}; +use tokio::io::{self, AsyncReadExt, AsyncWriteExt}; use crate::launcher::constants::USER_AGENT; pub trait Download: Debug + Display { @@ -182,13 +182,14 @@ impl Display for VerifiedDownload { } impl VerifiedDownload { - pub fn new(url: &str, path: &Path) -> VerifiedDownload { + pub fn new(url: &str, path: &Path, expect_size: Option<usize>, expect_sha1: Option<Digest>) -> VerifiedDownload { VerifiedDownload { url: url.to_owned(), path: path.to_owned(), - expect_size: None, - expect_sha1: None, + expect_size, + expect_sha1, + file: None, sha1: Sha1::new(), tally: 0 @@ -205,7 +206,11 @@ impl VerifiedDownload { self } - async fn open_output(&mut self) -> Result<(), tokio::io::Error> { + pub async fn make_dirs(&self) -> Result<(), io::Error> { + fs::create_dir_all(self.path.parent().expect("download created with no containing directory (?)")).await + } + + async fn open_output(&mut self) -> Result<(), io::Error> { self.file.replace(File::create(&self.path).await?); Ok(()) } diff --git a/src/version.rs b/src/version.rs index 078927d..ae91149 100644 --- a/src/version.rs +++ b/src/version.rs @@ -81,11 +81,24 @@ pub struct CompatibilityRule { pub os: Option<OSRestriction> } +pub trait FeatureMatcher { + fn matches(&self, feature: &str) -> bool; +} + +impl<F> FeatureMatcher for F +where + F: Fn(&str) -> bool +{ + fn matches(&self, feature: &str) -> bool { + self(feature) + } +} + impl CompatibilityRule { - pub fn features_match(&self, checker: fn(&str) -> bool) -> bool { + pub fn features_match(&self, checker: impl FeatureMatcher) -> bool { if let Some(m) = self.features.as_ref() { for (feat, expect) in m { - if checker(feat) != *expect { + if checker.matches(feat) != *expect { return false; } } @@ -206,6 +219,16 @@ pub struct Library { pub url: Option<String> // old format } +impl LibraryDownloads { + pub fn get_download_info(&self, classifier: Option<&str>) -> Option<&DownloadInfo> { + if let Some(classifier) = classifier { + self.classifiers.as_ref()?.get(classifier) + } else { + self.artifact.as_ref() + } + } +} + #[derive(Deserialize, Debug, Clone)] pub struct ClientLogging { pub argument: String, |
