summaryrefslogtreecommitdiffstats
path: root/src/launcher.rs
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2025-01-19 21:07:40 -0600
committerLibravatar bigfoot547 <[email protected]>2025-01-19 21:07:40 -0600
commitcce48864a2338a11cf7b9585350a327f70b8376b (patch)
tree137a81b56dd7426701f492d978662dc46db649b9 /src/launcher.rs
parentmore stuff (diff)
update strsub
Diffstat (limited to 'src/launcher.rs')
-rw-r--r--src/launcher.rs63
1 files changed, 48 insertions, 15 deletions
diff --git a/src/launcher.rs b/src/launcher.rs
index 7611011..626bac9 100644
--- a/src/launcher.rs
+++ b/src/launcher.rs
@@ -6,18 +6,20 @@ mod rules;
mod assets;
mod extract;
mod settings;
+mod runner;
use std::borrow::Cow;
use std::cmp::min;
use std::env::consts::{ARCH, OS};
use std::error::Error;
-use std::ffi::OsStr;
+use std::ffi::{OsStr, OsString};
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};
@@ -38,6 +40,8 @@ use assets::{AssetError, AssetRepository};
use crate::util::{self, FileVerifyError, IntegrityError};
pub use settings::*;
+use crate::assets::AssetIndex;
+use crate::version::manifest::VersionType;
#[derive(Debug)]
pub enum LogConfigError {
@@ -178,6 +182,22 @@ impl Error for LaunchError {
}
}
+pub struct Launch<'l> {
+ launcher: &'l Launcher,
+ asset_index_name: Option<String>,
+ classpath: String,
+ virtual_assets_path: Option<PathBuf>,
+ instance_home: PathBuf,
+ natives_path: PathBuf,
+ client_jar: Option<PathBuf>,
+ version_id: String,
+ version_type: Option<VersionType>,
+ asset_index: Option<AssetIndex>,
+
+ jvm_arguments: Vec<OsString>,
+ game_arguments: Vec<OsString>,
+}
+
impl Launcher {
// FIXME: more descriptive error type por favor
pub async fn new(home: impl AsRef<Path>, online: bool) -> Result<Launcher, Box<dyn Error>> {
@@ -330,13 +350,13 @@ impl Launcher {
self.ensure_file(&path, dlinfo).await?;
- Ok(strsub::replace_str(config.client.argument.as_str(), |key| match key {
- "path" => Some(path.to_string_lossy().clone()),
+ Ok(strsub::replace_string(config.client.argument.as_str(), |key| match key {
+ "path" => Some(path.to_string_lossy()),
_ => None
- }))
+ }).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<Launch<'_>, LaunchError> {
/* tasks 2 l;aunch the gayme!!!! :3
* - java runtime
* - normal process (good research, past figboot :3)
@@ -362,7 +382,7 @@ impl Launcher {
* - build argument list and whatnot also
*/
let Some(version_id) = self.versions.get_profile_version_id(version_id) else {
- // idk how common this usecase actually is
+ // idk how common this use case actually is
warn!("Can't use latest release/snapshot profiles while offline!");
return Err(LaunchError::UnknownVersion("<latest>".into()));
};
@@ -455,7 +475,7 @@ impl Launcher {
self.assets.ensure_assets(&asset_idx).await.map_err(|e| LaunchError::Assets(e))?;
- (Some(asset_idx_name), Some(asset_idx))
+ (asset_idx_name, Some(asset_idx))
} else {
(None, None)
};
@@ -486,9 +506,9 @@ impl Launcher {
info!("Extracting natives from libraries");
let natives_dir = self.libraries.extract_natives(extract_jobs).await?;
- let assets_root = if let Some(asset_idx) = asset_idx {
+ let game_assets = if let Some(asset_idx) = asset_idx.as_ref() {
info!("Reconstructing assets");
- self.assets.reconstruct_assets(&asset_idx, inst_home.as_path(), asset_idx_name.unwrap()).await
+ self.assets.reconstruct_assets(asset_idx, inst_home.as_path(), asset_idx_name).await
.map_err(|e| LaunchError::Assets(e))?
} else {
None
@@ -507,8 +527,21 @@ impl Launcher {
info!("Classpath: {classpath}");
- //todo!()
- Ok(())
+ Ok(Launch {
+ launcher: self,
+ asset_index_name: asset_idx_name.map(|s| s.to_owned()),
+ classpath,
+ virtual_assets_path: game_assets,
+ instance_home: inst_home,
+ natives_path: natives_dir,
+ client_jar: client_jar_path,
+ version_id: ver.id.to_string(),
+ version_type: ver.version_type.clone(),
+ asset_index: asset_idx,
+
+ jvm_arguments: Vec::new(), // TODO
+ game_arguments: Vec::new(), // TODO
+ })
}
}
@@ -563,14 +596,14 @@ impl LibraryRepository {
if let Some(classifier) = classifier {
match n.len() {
- 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))),
+ 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())),
_ => None
}
} else {
match n.len() {
- 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))),
+ 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())),
_ => None
}
}