fix: formatting
This commit is contained in:
1 parent
6f5722aa02
commit
b94957a952
6 files changed
+87
-54
No files matched your search
+8
-7
@@ -23,13 +23,14 @@ fn ensure_config_exists() -> PathBuf {
|
||||
let config_path = get_config_path().join("config.toml");
|
||||
if !config_path.exists() {
|
||||
if let Some(parent) = config_path.parent()
|
||||
&& let Err(e) = fs::create_dir_all(parent) {
|
||||
tracing::warn!(
|
||||
"Failed to create config directory {}: {}",
|
||||
parent.display(),
|
||||
e
|
||||
);
|
||||
}
|
||||
&& let Err(e) = fs::create_dir_all(parent)
|
||||
{
|
||||
tracing::warn!(
|
||||
"Failed to create config directory {}: {}",
|
||||
parent.display(),
|
||||
e
|
||||
);
|
||||
}
|
||||
match fs::write(&config_path, include_str!("../../assets/config.toml")) {
|
||||
Ok(()) => tracing::debug!("Wrote default config to {}", config_path.display()),
|
||||
Err(e) => tracing::warn!(
|
||||
|
||||
@@ -462,13 +462,16 @@ fn quadrant_cell(pixels: [[u8; 3]; 4]) -> IconCell {
|
||||
|
||||
let bg = pixels[pair.0];
|
||||
let fg = pixels[pair.1];
|
||||
let mask = pixels.iter().enumerate().fold(0_u8, |mask, (index, pixel)| {
|
||||
if color_distance(*pixel, fg) <= color_distance(*pixel, bg) {
|
||||
mask | (1 << index)
|
||||
} else {
|
||||
mask
|
||||
}
|
||||
});
|
||||
let mask = pixels
|
||||
.iter()
|
||||
.enumerate()
|
||||
.fold(0_u8, |mask, (index, pixel)| {
|
||||
if color_distance(*pixel, fg) <= color_distance(*pixel, bg) {
|
||||
mask | (1 << index)
|
||||
} else {
|
||||
mask
|
||||
}
|
||||
});
|
||||
let symbol = match mask {
|
||||
0 => ' ',
|
||||
1 => '\u{2598}',
|
||||
|
||||
@@ -145,13 +145,14 @@ async fn download_mod_files(
|
||||
let completed = completed.clone();
|
||||
tasks.spawn(async move {
|
||||
if let Some(parent) = dest.parent()
|
||||
&& let Err(e) = tokio::fs::create_dir_all(parent).await {
|
||||
tracing::warn!(
|
||||
"Failed to create mod download directory {}: {}",
|
||||
parent.display(),
|
||||
e
|
||||
);
|
||||
}
|
||||
&& let Err(e) = tokio::fs::create_dir_all(parent).await
|
||||
{
|
||||
tracing::warn!(
|
||||
"Failed to create mod download directory {}: {}",
|
||||
parent.display(),
|
||||
e
|
||||
);
|
||||
}
|
||||
progress::set_sub_action(filename);
|
||||
tracing::trace!("Downloading .mrpack file to {}", dest.display());
|
||||
crate::net::download_file(&client, &url, &dest, |_, _| {}).await?;
|
||||
@@ -183,13 +184,14 @@ async fn download_mod_files(
|
||||
let completed = completed.clone();
|
||||
tasks.spawn(async move {
|
||||
if let Some(parent) = dest.parent()
|
||||
&& let Err(e) = tokio::fs::create_dir_all(parent).await {
|
||||
tracing::warn!(
|
||||
"Failed to create mod download directory {}: {}",
|
||||
parent.display(),
|
||||
e
|
||||
);
|
||||
}
|
||||
&& let Err(e) = tokio::fs::create_dir_all(parent).await
|
||||
{
|
||||
tracing::warn!(
|
||||
"Failed to create mod download directory {}: {}",
|
||||
parent.display(),
|
||||
e
|
||||
);
|
||||
}
|
||||
progress::set_sub_action(filename);
|
||||
tracing::trace!("Downloading .mrpack file to {}", dest.display());
|
||||
crate::net::download_file(&client, &url, &dest, |_, _| {}).await?;
|
||||
|
||||
@@ -28,17 +28,13 @@ pub enum LaunchError {
|
||||
Json(#[from] serde_json::Error),
|
||||
#[error("{0} launch is not yet supported")]
|
||||
NotSupported(String),
|
||||
#[error(
|
||||
"This instance requires Java {required}, but rmcl is using Java {detected}: {java}"
|
||||
)]
|
||||
#[error("This instance requires Java {required}, but rmcl is using Java {detected}: {java}")]
|
||||
JavaTooOld {
|
||||
java: String,
|
||||
required: u32,
|
||||
detected: u32,
|
||||
},
|
||||
#[error(
|
||||
"This instance requires Java {required}, but rmcl could not check {java}: {reason}"
|
||||
)]
|
||||
#[error("This instance requires Java {required}, but rmcl could not check {java}: {reason}")]
|
||||
JavaCheckFailed {
|
||||
java: String,
|
||||
required: u32,
|
||||
@@ -414,7 +410,11 @@ pub async fn build_launch_invocation(
|
||||
// so we check there first.
|
||||
let has_local_libs = matches!(config.loader, ModLoader::Forge | ModLoader::NeoForge);
|
||||
let local_lib_dir = minecraft_dir.join("libraries");
|
||||
let library_directory = if has_local_libs { &local_lib_dir } else { &lib_dir };
|
||||
let library_directory = if has_local_libs {
|
||||
&local_lib_dir
|
||||
} else {
|
||||
&lib_dir
|
||||
};
|
||||
|
||||
let mut classpath: Vec<PathBuf> = Vec::new();
|
||||
for lib in &merged_profile.libraries {
|
||||
|
||||
@@ -254,7 +254,9 @@ impl InstanceManager {
|
||||
.await
|
||||
.map_err(|e| match e {
|
||||
InstallError::Download(net_error) => InstanceError::Download(net_error),
|
||||
InstallError::Installer(installer_error) => InstanceError::InstallerError(installer_error),
|
||||
InstallError::Installer(installer_error) => {
|
||||
InstanceError::InstallerError(installer_error)
|
||||
}
|
||||
})?;
|
||||
|
||||
let config = InstanceConfig {
|
||||
|
||||
+43
-18
@@ -227,38 +227,58 @@ pub(crate) async fn install_forge_from_profile(
|
||||
|
||||
let file = std::fs::File::open(installer_path)
|
||||
.map_err(|e| InstallError::Installer(InstallerError::Io(e)))?;
|
||||
let mut archive = zip::ZipArchive::new(file)
|
||||
.map_err(|e| InstallError::Installer(InstallerError::Profile(format!("Failed to open installer as ZIP: {e}"))))?;
|
||||
let mut archive = zip::ZipArchive::new(file).map_err(|e| {
|
||||
InstallError::Installer(InstallerError::Profile(format!(
|
||||
"Failed to open installer as ZIP: {e}"
|
||||
)))
|
||||
})?;
|
||||
|
||||
let profile_data: serde_json::Value = {
|
||||
let entry = archive.by_name("install_profile.json").map_err(|e| {
|
||||
InstallError::Installer(InstallerError::Profile(format!("install_profile.json not found in installer: {e}")))
|
||||
InstallError::Installer(InstallerError::Profile(format!(
|
||||
"install_profile.json not found in installer: {e}"
|
||||
)))
|
||||
})?;
|
||||
serde_json::from_reader(entry)
|
||||
.map_err(|e| InstallError::Installer(InstallerError::Profile(format!("Failed to parse install_profile.json: {e}"))))?
|
||||
serde_json::from_reader(entry).map_err(|e| {
|
||||
InstallError::Installer(InstallerError::Profile(format!(
|
||||
"Failed to parse install_profile.json: {e}"
|
||||
)))
|
||||
})?
|
||||
};
|
||||
|
||||
let version_info = profile_data
|
||||
.get("versionInfo")
|
||||
.ok_or_else(|| InstallError::Installer(InstallerError::Profile("install_profile.json missing versionInfo".into())))?;
|
||||
let install_info = profile_data
|
||||
.get("install")
|
||||
.ok_or_else(|| InstallError::Installer(InstallerError::Profile("install_profile.json missing install section".into())))?;
|
||||
let version_info = profile_data.get("versionInfo").ok_or_else(|| {
|
||||
InstallError::Installer(InstallerError::Profile(
|
||||
"install_profile.json missing versionInfo".into(),
|
||||
))
|
||||
})?;
|
||||
let install_info = profile_data.get("install").ok_or_else(|| {
|
||||
InstallError::Installer(InstallerError::Profile(
|
||||
"install_profile.json missing install section".into(),
|
||||
))
|
||||
})?;
|
||||
|
||||
let libraries = version_info
|
||||
.get("libraries")
|
||||
.and_then(|v| v.as_array())
|
||||
.ok_or_else(|| InstallError::Installer(InstallerError::Profile("missing versionInfo.libraries".into())))?;
|
||||
.ok_or_else(|| {
|
||||
InstallError::Installer(InstallerError::Profile(
|
||||
"missing versionInfo.libraries".into(),
|
||||
))
|
||||
})?;
|
||||
|
||||
let file_path = install_info
|
||||
.get("filePath")
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or_else(|| InstallError::Installer(InstallerError::Profile("missing install.filePath".into())))?;
|
||||
.ok_or_else(|| {
|
||||
InstallError::Installer(InstallerError::Profile("missing install.filePath".into()))
|
||||
})?;
|
||||
|
||||
let install_path_coord = install_info
|
||||
.get("path")
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or_else(|| InstallError::Installer(InstallerError::Profile("missing install.path".into())))?;
|
||||
.ok_or_else(|| {
|
||||
InstallError::Installer(InstallerError::Profile("missing install.path".into()))
|
||||
})?;
|
||||
|
||||
// extract the universal jar to the correct maven location
|
||||
let universal_maven_path =
|
||||
@@ -300,12 +320,14 @@ pub(crate) async fn install_forge_from_profile(
|
||||
// in mojang's modern version metadata, so we fetch those too.
|
||||
let libraries_dir = meta_dir.join("libraries");
|
||||
for lib in libraries {
|
||||
let name = lib.get("name").and_then(|v| v.as_str()).unwrap_or_default();
|
||||
let name = lib.get("name").and_then(|v| v.as_str()).unwrap_or_default();
|
||||
|
||||
let maven_path = match crate::net::maven_coord_to_path(name) {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
return Err(InstallError::Installer(InstallerError::Profile(format!("Invalid Maven coordinate: {name}"))));
|
||||
return Err(InstallError::Installer(InstallerError::Profile(format!(
|
||||
"Invalid Maven coordinate: {name}"
|
||||
))));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -341,8 +363,11 @@ pub(crate) async fn install_forge_from_profile(
|
||||
// and whitespace may differ from the original installer JSON because
|
||||
// the source is a serde_json::Value (which doesn't preserve order),
|
||||
// but no field is silently dropped.
|
||||
let serialized = serde_json::to_vec(version_info)
|
||||
.map_err(|e| InstallError::Installer(InstallerError::Profile(format!("Failed to serialize Forge profile: {e}"))))?;
|
||||
let serialized = serde_json::to_vec(version_info).map_err(|e| {
|
||||
InstallError::Installer(InstallerError::Profile(format!(
|
||||
"Failed to serialize Forge profile: {e}"
|
||||
)))
|
||||
})?;
|
||||
crate::instance::loader::save_profile_bytes(meta_dir, profile_filename, &serialized)
|
||||
.map_err(|e| InstallError::Installer(InstallerError::Io(e)))?;
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user