From 1782b86d68ec923df965386acd98f80ef6bcaa46 Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Mon, 20 Jan 2025 00:53:39 -0600 Subject: get rid of wacky closure business --- src/launcher.rs | 86 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 30 deletions(-) (limited to 'src/launcher.rs') diff --git a/src/launcher.rs b/src/launcher.rs index 626bac9..a21a422 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -12,14 +12,13 @@ use std::borrow::Cow; use std::cmp::min; use std::env::consts::{ARCH, OS}; use std::error::Error; -use std::ffi::{OsStr, OsString}; +use std::ffi::OsStr; use std::fmt::{Display, Formatter}; use std::io::ErrorKind; use std::io::ErrorKind::AlreadyExists; use std::path::{Component, Path, PathBuf}; use std::{env, process}; use std::env::JoinPathsError; -use std::process::Command; use std::time::{SystemTime, UNIX_EPOCH}; use const_format::formatcp; use futures::{StreamExt, TryStreamExt}; @@ -34,13 +33,15 @@ use tokio_stream::wrappers::ReadDirStream; use download::{MultiDownloader, VerifiedDownload}; use rules::{CompatCheck, IncompatibleError}; use version::{VersionList, VersionResolveError, VersionResult}; -use crate::version::{Logging, Library, OSRestriction, OperatingSystem, DownloadType, DownloadInfo, LibraryExtractRule}; +use crate::version::{Logging, Library, OSRestriction, OperatingSystem, DownloadType, DownloadInfo, LibraryExtractRule, CompleteVersion, FeatureMatcher}; use assets::{AssetError, AssetRepository}; use crate::util::{self, FileVerifyError, IntegrityError}; pub use settings::*; use crate::assets::AssetIndex; +use crate::launcher::runner::ArgumentType; +use crate::launcher::strsub::SubFunc; use crate::version::manifest::VersionType; #[derive(Debug)] @@ -182,8 +183,10 @@ impl Error for LaunchError { } } -pub struct Launch<'l> { +struct LaunchInfo<'l, F: FeatureMatcher> { launcher: &'l Launcher, + feature_matcher: &'l F, + asset_index_name: Option, classpath: String, virtual_assets_path: Option, @@ -192,10 +195,14 @@ pub struct Launch<'l> { client_jar: Option, version_id: String, version_type: Option, - asset_index: Option, + asset_index: Option +} - jvm_arguments: Vec, - game_arguments: Vec, +struct FMTrivial; +impl FeatureMatcher for FMTrivial { + fn matches(&self, _feature: &str) -> bool { + false + } } impl Launcher { @@ -239,6 +246,10 @@ impl Launcher { lib.natives.as_ref().map_or(None, |n| n.get(&self.system_info.os)).map(|s| s.as_str()) } + fn get_feature_matcher(&self) -> &impl FeatureMatcher { + &FMTrivial + } + async fn ensure_file(&self, path: &Path, dlinfo: &DownloadInfo) -> Result<(), LaunchError> { // verify the file match util::verify_file(path, dlinfo.size, dlinfo.sha1).await { @@ -350,13 +361,20 @@ impl Launcher { self.ensure_file(&path, dlinfo).await?; - Ok(strsub::replace_string(config.client.argument.as_str(), |key| match key { - "path" => Some(path.to_string_lossy()), - _ => None - }).to_string()) + struct PathSub<'a>(&'a Path); + impl<'a> SubFunc<'a> for PathSub<'a> { + fn substitute(&self, key: &str) -> Option> { + match key { + "path" => Some(self.0.to_string_lossy()), + _ => None + } + } + } + + Ok(strsub::replace_string(config.client.argument.as_str(), &PathSub(path.as_ref())).to_string()) } - pub async fn prepare_launch(&self, version_id: &ProfileVersion, instance: &Instance) -> Result, LaunchError> { + pub async fn prepare_launch(&self, version_id: &ProfileVersion, instance: &Instance) -> Result<(), LaunchError> { /* tasks 2 l;aunch the gayme!!!! :3 * - java runtime * - normal process (good research, past figboot :3) @@ -411,7 +429,7 @@ impl Launcher { }; let ver = self.versions.resolve_version(ver.as_ref()).await.map_err(|e| LaunchError::ResolveVersion(e))?; - ver.rules_apply(&self.system_info, |_| false).map_err(|e| LaunchError::IncompatibleVersion(e))?; + ver.rules_apply(&self.system_info, self.get_feature_matcher()).map_err(|e| LaunchError::IncompatibleVersion(e))?; info!("Resolved launch version {}!", ver.id); @@ -420,7 +438,7 @@ impl Launcher { let mut downloads = Vec::new(); for lib in ver.libraries.values() { - if lib.rules_apply(&self.system_info, |_| false).is_err() { + if lib.rules_apply(&self.system_info, self.get_feature_matcher()).is_err() { continue; } @@ -527,8 +545,11 @@ impl Launcher { info!("Classpath: {classpath}"); - Ok(Launch { + info!("Deriving launch arguments"); + let info = LaunchInfo { launcher: self, + feature_matcher: self.get_feature_matcher(), + asset_index_name: asset_idx_name.map(|s| s.to_owned()), classpath, virtual_assets_path: game_assets, @@ -537,11 +558,13 @@ impl Launcher { client_jar: client_jar_path, version_id: ver.id.to_string(), version_type: ver.version_type.clone(), - asset_index: asset_idx, + asset_index: asset_idx + }; - jvm_arguments: Vec::new(), // TODO - game_arguments: Vec::new(), // TODO - }) + let jvm_args = runner::build_arguments(&info, ver.as_ref(), ArgumentType::JVM); + let game_args = runner::build_arguments(&info, ver.as_ref(), ArgumentType::Game); + + todo!() } } @@ -578,13 +601,6 @@ struct LibraryExtractJob { const ARCH_BITS: &'static str = formatcp!("{}", usize::BITS); impl LibraryRepository { - fn lib_replace(key: &str) -> Option> { - match key { - "arch" => Some(Cow::Borrowed(ARCH_BITS)), - _ => None - } - } - fn get_artifact_base_dir(name: &str) -> Option { let end_of_gid = name.find(':')?; @@ -594,16 +610,26 @@ impl LibraryRepository { fn get_artifact_filename(name: &str, classifier: Option<&str>) -> Option { let n: Vec<&str> = name.splitn(4, ':').skip(1).collect(); + struct LibReplace; + impl SubFunc<'static> for LibReplace { + fn substitute(&self, key: &str) -> Option> { + match key { + "arch" => Some(Cow::Borrowed(ARCH_BITS)), + _ => None + } + } + } + if let Some(classifier) = classifier { match n.len() { - 2 => Some(PathBuf::from(strsub::replace_string(format!("{}-{}-{}.jar", n[0], n[1], classifier).as_str(), Self::lib_replace).as_ref())), - 3 => Some(PathBuf::from(strsub::replace_string(format!("{}-{}-{}-{}.jar", n[0], n[1], classifier, n[2]).as_str(), Self::lib_replace).as_ref())), + 2 => Some(PathBuf::from(strsub::replace_string(format!("{}-{}-{}.jar", n[0], n[1], classifier).as_str(), &LibReplace).as_ref())), + 3 => Some(PathBuf::from(strsub::replace_string(format!("{}-{}-{}-{}.jar", n[0], n[1], classifier, n[2]).as_str(), &LibReplace).as_ref())), _ => None } } else { match n.len() { - 2 => Some(PathBuf::from(strsub::replace_string(format!("{}-{}.jar", n[0], n[1]).as_str(), Self::lib_replace).as_ref())), - 3 => Some(PathBuf::from(strsub::replace_string(format!("{}-{}-{}.jar", n[0], n[1], n[2]).as_str(), Self::lib_replace).as_ref())), + 2 => Some(PathBuf::from(strsub::replace_string(format!("{}-{}.jar", n[0], n[1]).as_str(), &LibReplace).as_ref())), + 3 => Some(PathBuf::from(strsub::replace_string(format!("{}-{}-{}.jar", n[0], n[1], n[2]).as_str(), &LibReplace).as_ref())), _ => None } } -- cgit v1.2.3-70-g09d2