fix(runtime): validate and repair launch caches

This commit is contained in:
objz committed 2026-09-04 23:53:57 +02:00
1 parent 1079680513
commit a25f7d20c8
8 files changed
+301 -131

No files matched your search

+28 -6
View File
@@ -48,6 +48,26 @@ impl ModLoaderInstaller for ForgeInstaller {
loader_version: &str,
instance_dir: &Path,
meta_dir: &Path,
) -> Result<(), InstallError> {
self.install_with_java(
client,
game_version,
loader_version,
instance_dir,
meta_dir,
None,
)
.await
}
async fn install_with_java(
&self,
client: &HttpClient,
game_version: &str,
loader_version: &str,
instance_dir: &Path,
meta_dir: &Path,
java_path: Option<&str>,
) -> Result<(), InstallError> {
let installer_jar = instance_dir
.join(crate::storage::MINECRAFT_DIR_NAME)
@@ -76,12 +96,14 @@ impl ModLoaderInstaller for ForgeInstaller {
}
} else {
// modern forge: run the java installer
let java_path = crate::config::SETTINGS
.read()
.paths
.effective_java_path()
.map(str::to_owned)
.unwrap_or_else(crate::instance::java::detect_java_path);
let java_path = java_path.map(str::to_owned).unwrap_or_else(|| {
crate::config::SETTINGS
.read()
.paths
.effective_java_path()
.map(str::to_owned)
.unwrap_or_else(crate::instance::java::detect_java_path)
});
tracing::debug!("Running Forge installer with Java {}", java_path);
if let Err(e) = run_forge_installer(&installer_jar, instance_dir, &java_path).await {
let _ = tokio::fs::remove_file(&installer_jar).await;
+48 -2
View File
@@ -67,6 +67,20 @@ pub trait ModLoaderInstaller: Send + Sync {
instance_dir: &Path,
meta_dir: &Path,
) -> Result<(), InstallError>;
async fn install_with_java(
&self,
client: &HttpClient,
game_version: &str,
loader_version: &str,
instance_dir: &Path,
meta_dir: &Path,
java_path: Option<&str>,
) -> Result<(), InstallError> {
let _ = java_path;
self.install(client, game_version, loader_version, instance_dir, meta_dir)
.await
}
}
// writes raw profile JSON bytes to meta_dir/loader-profiles/<filename>.
@@ -80,7 +94,21 @@ pub(crate) fn save_profile_bytes(
) -> std::io::Result<()> {
let profiles_dir = crate::storage::MetadataPaths::new(meta_dir).loader_profiles();
std::fs::create_dir_all(&profiles_dir)?;
std::fs::write(profiles_dir.join(filename), bytes)
crate::storage::write_atomic(&profiles_dir.join(filename), bytes)
}
pub(crate) fn profile_filename(
loader: ModLoader,
game_version: &str,
loader_version: &str,
) -> Option<String> {
match loader {
ModLoader::Vanilla => None,
ModLoader::Fabric => Some(format!("fabric-{game_version}-{loader_version}.json")),
ModLoader::Quilt => Some(format!("quilt-{game_version}-{loader_version}.json")),
ModLoader::Forge => Some(format!("forge-{game_version}-{loader_version}.json")),
ModLoader::NeoForge => Some(format!("neoforge-{loader_version}.json")),
}
}
// used by forge/neoforge. their java installer drops a version json into
@@ -118,11 +146,29 @@ pub(crate) fn save_installer_profile(
ver_json_path.display()
);
let raw = std::fs::read(&ver_json_path)?;
let profile: crate::launch_profile::model::LaunchProfile = serde_json::from_slice(&raw)
.map_err(|error| {
InstallerError::Profile(format!(
"Invalid installer profile {}: {error}",
ver_json_path.display()
))
})?;
if profile.id.trim().is_empty()
|| profile
.main_class
.as_deref()
.is_none_or(|main_class| main_class.trim().is_empty())
{
return Err(InstallerError::Profile(format!(
"Installer profile {} is missing id or mainClass",
ver_json_path.display()
)));
}
let profiles_dir = crate::storage::MetadataPaths::new(meta_dir).loader_profiles();
std::fs::create_dir_all(&profiles_dir)?;
let profile_path = profiles_dir.join(profile_filename);
std::fs::write(&profile_path, &raw)?;
crate::storage::write_atomic(&profile_path, &raw)?;
tracing::debug!(
"Saved installer profile to {} ({} bytes)",
profile_path.display(),
+28 -6
View File
@@ -41,12 +41,32 @@ impl ModLoaderInstaller for NeoForgeInstaller {
}
async fn install(
&self,
client: &HttpClient,
game_version: &str,
loader_version: &str,
instance_dir: &Path,
meta_dir: &Path,
) -> Result<(), InstallError> {
self.install_with_java(
client,
game_version,
loader_version,
instance_dir,
meta_dir,
None,
)
.await
}
async fn install_with_java(
&self,
client: &HttpClient,
_game_version: &str,
loader_version: &str,
instance_dir: &Path,
meta_dir: &Path,
java_path: Option<&str>,
) -> Result<(), InstallError> {
let installer_jar = instance_dir
.join(crate::storage::MINECRAFT_DIR_NAME)
@@ -56,12 +76,14 @@ impl ModLoaderInstaller for NeoForgeInstaller {
neoforge_api::download_neoforge_installer(client, loader_version, &installer_jar).await?;
let java_path = crate::config::SETTINGS
.read()
.paths
.effective_java_path()
.map(str::to_owned)
.unwrap_or_else(crate::instance::java::detect_java_path);
let java_path = java_path.map(str::to_owned).unwrap_or_else(|| {
crate::config::SETTINGS
.read()
.paths
.effective_java_path()
.map(str::to_owned)
.unwrap_or_else(crate::instance::java::detect_java_path)
});
tracing::debug!("Running NeoForge installer with Java {}", java_path);
if let Err(e) = run_neoforge_installer(&installer_jar, instance_dir, &java_path).await {
let _ = tokio::fs::remove_file(&installer_jar).await;