summaryrefslogtreecommitdiffstats
path: root/src/launcher.rs
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2025-01-31 02:32:19 -0600
committerLibravatar bigfoot547 <[email protected]>2025-01-31 02:32:19 -0600
commitcdeee17c2be5b8b9a333b977b3e2d373b94dfe0a (patch)
tree58ec48b5bfa9afe03ebbd9716f1f90841af914e9 /src/launcher.rs
parentRemove some unused imports but not all of them (diff)
do clippy stuff and change line endings
Diffstat (limited to 'src/launcher.rs')
-rw-r--r--src/launcher.rs59
1 files changed, 28 insertions, 31 deletions
diff --git a/src/launcher.rs b/src/launcher.rs
index d414305..0f2b442 100644
--- a/src/launcher.rs
+++ b/src/launcher.rs
@@ -32,7 +32,7 @@ use tokio_stream::wrappers::ReadDirStream;
use download::{MultiDownloader, VerifiedDownload};
use rules::{CompatCheck, IncompatibleError};
use version::{VersionList, VersionResolveError, VersionResult};
-use crate::version::{Library, OSRestriction, OperatingSystem, DownloadType, DownloadInfo, LibraryExtractRule, CompleteVersion, FeatureMatcher, ClientLogging};
+use crate::version::{Library, OSRestriction, OperatingSystem, DownloadType, LibraryExtractRule, FeatureMatcher, ClientLogging};
use assets::{AssetError, AssetRepository};
use crate::util::{self, AsJavaPath};
@@ -243,14 +243,13 @@ impl Launcher {
let home = fs::canonicalize(home.as_ref()).await?;
let versions_home = home.join("versions");
- let versions;
debug!("Version list online?: {online}");
- if online {
- versions = VersionList::online(versions_home.as_ref()).await?;
+ let versions = if online {
+ VersionList::online(versions_home.as_ref()).await?
} else {
- versions = VersionList::offline(versions_home.as_ref()).await?;
- }
+ VersionList::offline(versions_home.as_ref()).await?
+ };
let assets_path = home.join("assets");
@@ -271,7 +270,7 @@ impl Launcher {
}
fn choose_lib_classifier<'lib>(&self, lib: &'lib Library) -> Option<&'lib str> {
- lib.natives.as_ref().map_or(None, |n| n.get(&self.system_info.os)).map(|s| s.as_str())
+ lib.natives.as_ref().and_then(|n| n.get(&self.system_info.os)).map(|s| s.as_str())
}
async fn log_config_ensure(&self, config: &ClientLogging) -> Result<String, LaunchError> {
@@ -298,8 +297,8 @@ impl Launcher {
debug!("Logger config {} is at {}", id, path.display());
- util::ensure_file(&path, dlinfo.url.as_ref().map(|s| s.as_str()), dlinfo.size, dlinfo.sha1, self.online, false).await
- .map_err(|e| LaunchError::EnsureFile(e))?;
+ util::ensure_file(&path, dlinfo.url.as_deref(), dlinfo.size, dlinfo.sha1, self.online, false).await
+ .map_err(LaunchError::EnsureFile)?;
struct PathSub<'a>(&'a Path);
impl<'a> SubFunc<'a> for PathSub<'a> {
@@ -345,15 +344,15 @@ impl Launcher {
let ver_res = self.versions.get_version_lazy(version_id.as_ref());
let ver = match ver_res {
- VersionResult::Remote(mv) => Cow::Owned(self.versions.load_remote_version(mv).await.map_err(|e| LaunchError::LoadVersion(e))?),
+ VersionResult::Remote(mv) => Cow::Owned(self.versions.load_remote_version(mv).await.map_err(LaunchError::LoadVersion)?),
VersionResult::Complete(cv) => Cow::Borrowed(cv),
VersionResult::None => {
- return Err(LaunchError::UnknownVersion(version_id.into_owned()).into())
+ return Err(LaunchError::UnknownVersion(version_id.into_owned()))
}
};
- let ver = self.versions.resolve_version(ver.as_ref()).await.map_err(|e| LaunchError::ResolveVersion(e))?;
- ver.rules_apply(&self.system_info, &feature_matcher).map_err(|e| LaunchError::IncompatibleVersion(e))?;
+ let ver = self.versions.resolve_version(ver.as_ref()).await.map_err(LaunchError::ResolveVersion)?;
+ ver.rules_apply(&self.system_info, &feature_matcher).map_err(LaunchError::IncompatibleVersion)?;
info!("Resolved launch version {}!", ver.id);
@@ -409,7 +408,7 @@ impl Launcher {
}
let log_arg;
- if let Some(logging) = ver.logging.as_ref().map_or(None, |l| l.client.as_ref()) {
+ if let Some(logging) = ver.logging.as_ref().and_then(|l| l.client.as_ref()) {
log_arg = Some(self.log_config_ensure(logging).await?);
} else {
log_arg = None;
@@ -421,9 +420,9 @@ impl Launcher {
if let Some(idx_download) = ver.asset_index.as_ref() {
let asset_idx_name = idx_download.id.as_ref().or(ver.assets.as_ref()).map(String::as_str);
let asset_idx = self.assets.load_index(idx_download, asset_idx_name).await
- .map_err(|e| LaunchError::Assets(e))?;
+ .map_err(LaunchError::Assets)?;
- self.assets.ensure_assets(&asset_idx).await.map_err(|e| LaunchError::Assets(e))?;
+ self.assets.ensure_assets(&asset_idx).await.map_err(LaunchError::Assets)?;
(asset_idx_name, Some(asset_idx))
} else {
@@ -441,8 +440,8 @@ impl Launcher {
info!("Downloading client jar {}", client_path.display());
- util::ensure_file(client_path.as_path(), client.url.as_ref().map(|s| s.as_str()), client.size, client.sha1, self.online, false).await
- .map_err(|e| LaunchError::EnsureFile(e))?;
+ util::ensure_file(client_path.as_path(), client.url.as_deref(), client.size, client.sha1, self.online, false).await
+ .map_err(LaunchError::EnsureFile)?;
client_jar_path = Some(client_path);
} else {
@@ -460,7 +459,7 @@ impl Launcher {
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).await
- .map_err(|e| LaunchError::Assets(e))?
+ .map_err(LaunchError::Assets)?
} else {
None
};
@@ -469,7 +468,7 @@ impl Launcher {
let classpath = env::join_paths(downloads.values()
.map(|job| job.get_path().as_java_path())
.chain(client_jar_path.iter().map(|p| p.as_path().as_java_path())))
- .map_err(|e| LaunchError::LibraryClasspathError(e))?
+ .map_err(LaunchError::LibraryClasspathError)?
.into_string()
.unwrap_or_else(|os| {
warn!("Classpath contains invalid UTF-8. The game may not launch correctly.");
@@ -524,7 +523,7 @@ impl Launcher {
// yuck
let jvm_args = profile.iter_arguments().map(OsString::from)
- .chain(runner::build_arguments(&info, ver.as_ref(), ArgumentType::JVM).drain(..))
+ .chain(runner::build_arguments(&info, ver.as_ref(), ArgumentType::Jvm).drain(..))
.chain(log_arg.iter().map(OsString::from)).collect();
let game_args = runner::build_arguments(&info, ver.as_ref(), ArgumentType::Game);
@@ -572,7 +571,7 @@ struct LibraryExtractJob {
rule: Option<LibraryExtractRule>
}
-const ARCH_BITS: &'static str = formatcp!("{}", usize::BITS);
+const ARCH_BITS: &str = formatcp!("{}", usize::BITS);
impl LibraryRepository {
fn get_artifact_base_dir(name: &str) -> Option<PathBuf> {
@@ -610,9 +609,7 @@ impl LibraryRepository {
}
fn get_artifact_path(name: &str, classifier: Option<&str>) -> Option<PathBuf> {
- let Some(mut p) = Self::get_artifact_base_dir(name) else {
- return None;
- };
+ let mut p = Self::get_artifact_base_dir(name)?;
p.push(Self::get_artifact_filename(name, classifier)?);
Some(p)
@@ -655,9 +652,9 @@ impl LibraryRepository {
if !ftype.is_dir() { return Ok(false); }
let Some(ftime) = entry.file_name().to_str()
- .map_or(None, |s| constants::NATIVES_DIR_PATTERN.captures(s))
- .map_or(None, |c| c.get(1))
- .map_or(None, |cap| cap.as_str().parse::<u64>().ok()) else {
+ .and_then(|s| constants::NATIVES_DIR_PATTERN.captures(s))
+ .and_then(|c| c.get(1))
+ .and_then(|cap| cap.as_str().parse::<u64>().ok()) else {
return Ok(false);
};
@@ -684,7 +681,7 @@ impl LibraryRepository {
}).await
}
- async fn extract_natives<'lib>(&self, libs: Vec<LibraryExtractJob>) -> Result<PathBuf, LaunchError> {
+ async fn extract_natives(&self, libs: Vec<LibraryExtractJob>) -> Result<PathBuf, LaunchError> {
fs::create_dir_all(&self.natives).await.map_err(|e| LaunchError::IO {
what: "creating natives directory",
error: e
@@ -706,8 +703,8 @@ impl LibraryRepository {
debug!("Extracting natives for {}", job.source.display());
tally += extract::extract_zip(&job.source, &natives_dir, |name|
job.rule.as_ref().is_none_or(|rules|
- rules.exclude.iter().filter(|ex|
- name.starts_with(ex.as_str())).next().is_none()))?;
+ rules.exclude.iter().any(|ex|
+ name.starts_with(ex.as_str()))))?;
}
Ok((natives_dir, tally))