chore: improve rmcl diagnostic logging
This commit is contained in:
1 parent
a58e6fb76d
commit
09bc8f26fb
23 files changed
+925
-61
No files matched your search
@@ -153,12 +153,22 @@ pub fn scan_mods(instances_dir: &Path, instance_name: &str) -> Vec<ContentEntry>
|
||||
fn read_mod_metadata(jar_path: &Path) -> (String, String, Option<Vec<u8>>) {
|
||||
let file = match std::fs::File::open(jar_path) {
|
||||
Ok(file) => file,
|
||||
Err(_) => return (String::new(), String::new(), None),
|
||||
Err(e) => {
|
||||
tracing::trace!("Failed to open mod JAR {}: {}", jar_path.display(), e);
|
||||
return (String::new(), String::new(), None);
|
||||
}
|
||||
};
|
||||
|
||||
let mut archive = match zip::ZipArchive::new(file) {
|
||||
Ok(archive) => archive,
|
||||
Err(_) => return (String::new(), String::new(), None),
|
||||
Err(e) => {
|
||||
tracing::trace!(
|
||||
"Failed to read mod JAR as ZIP {}: {}",
|
||||
jar_path.display(),
|
||||
e
|
||||
);
|
||||
return (String::new(), String::new(), None);
|
||||
}
|
||||
};
|
||||
|
||||
// try each loader's metadata in order. if we get metadata but the
|
||||
@@ -180,12 +190,23 @@ fn read_mod_metadata(jar_path: &Path) -> (String, String, Option<Vec<u8>>) {
|
||||
read_zip_bytes(&mut archive, icon_path)
|
||||
}
|
||||
.or_else(|| try_fallback_icons(&mut archive));
|
||||
tracing::trace!(
|
||||
"Read mod metadata from {}: name='{}' icon_declared={}",
|
||||
jar_path.display(),
|
||||
name,
|
||||
!icon_path.is_empty()
|
||||
);
|
||||
return (name, description, icon);
|
||||
}
|
||||
}
|
||||
|
||||
// no recognized metadata at all, try common icon paths
|
||||
let icon_bytes = try_fallback_icons(&mut archive);
|
||||
tracing::trace!(
|
||||
"No recognized mod metadata in {}; fallback_icon={}",
|
||||
jar_path.display(),
|
||||
icon_bytes.is_some()
|
||||
);
|
||||
(String::new(), String::new(), icon_bytes)
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,11 @@ impl MmcPack {
|
||||
|
||||
pub fn build_summary(path: &Path) -> Result<ImportSummary, String> {
|
||||
let pack = parse_mmc_pack(path)?;
|
||||
tracing::debug!(
|
||||
"Parsed MultiMC pack {} with {} component(s)",
|
||||
path.display(),
|
||||
pack.components.len()
|
||||
);
|
||||
|
||||
let game_version = pack
|
||||
.game_version()
|
||||
@@ -62,6 +67,15 @@ pub fn build_summary(path: &Path) -> Result<ImportSummary, String> {
|
||||
let name = instance_name_from_cfg(path).unwrap_or_else(|| "Imported Pack".to_string());
|
||||
|
||||
let (mod_count, override_count) = count_content_files(path)?;
|
||||
tracing::trace!(
|
||||
"MultiMC summary: name='{}' game_version={} loader={:?} loader_version={:?} mods={} overrides={}",
|
||||
name,
|
||||
game_version,
|
||||
loader,
|
||||
loader_version,
|
||||
mod_count,
|
||||
override_count
|
||||
);
|
||||
|
||||
Ok(ImportSummary {
|
||||
name,
|
||||
@@ -81,6 +95,11 @@ pub async fn execute_import(
|
||||
manager: &InstanceManager,
|
||||
) -> Result<crate::instance::InstanceConfig, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let name = super::unique_instance_name(&summary.name, &manager.instances_dir);
|
||||
tracing::info!(
|
||||
"Importing MultiMC/Prism pack '{}' as instance '{}'",
|
||||
summary.name,
|
||||
name
|
||||
);
|
||||
|
||||
progress::set_action(format!("Importing '{name}'..."));
|
||||
progress::set_sub_action(format!("{} {}", summary.game_version, summary.loader));
|
||||
@@ -99,6 +118,11 @@ pub async fn execute_import(
|
||||
extract_mmc_archive(&summary.archive_path, &minecraft_dir)?;
|
||||
|
||||
progress::clear();
|
||||
tracing::info!(
|
||||
"Imported MultiMC/Prism pack '{}' as '{}'",
|
||||
summary.name,
|
||||
name
|
||||
);
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
@@ -117,8 +141,16 @@ fn extract_mmc_archive(
|
||||
|
||||
let prefix = find_archive_prefix(&archive);
|
||||
let minecraft_prefix = format!("{prefix}.minecraft/");
|
||||
tracing::debug!(
|
||||
"Extracting MultiMC archive {} with prefix '{}' into {}",
|
||||
archive_path.display(),
|
||||
prefix,
|
||||
minecraft_dir.display()
|
||||
);
|
||||
|
||||
let total = archive.len();
|
||||
let mut extracted = 0usize;
|
||||
let mut dirs = 0usize;
|
||||
for i in 0..total {
|
||||
let mut entry = archive.by_index(i)?;
|
||||
let entry_name = entry.name().to_string();
|
||||
@@ -129,6 +161,7 @@ fn extract_mmc_archive(
|
||||
|
||||
if relative.is_empty() || entry_name.ends_with('/') {
|
||||
std::fs::create_dir_all(minecraft_dir.join(relative))?;
|
||||
dirs += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -142,9 +175,22 @@ fn extract_mmc_archive(
|
||||
|
||||
let mut buf = Vec::new();
|
||||
entry.read_to_end(&mut buf)?;
|
||||
tracing::trace!(
|
||||
"Extracting MultiMC entry {} to {} ({} bytes)",
|
||||
entry_name,
|
||||
dest.display(),
|
||||
buf.len()
|
||||
);
|
||||
std::fs::write(&dest, &buf)?;
|
||||
extracted += 1;
|
||||
}
|
||||
|
||||
tracing::debug!(
|
||||
"Extracted {} files and {} directories from MultiMC archive {}",
|
||||
extracted,
|
||||
dirs,
|
||||
archive_path.display()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -167,6 +213,7 @@ fn instance_name_from_cfg(path: &Path) -> Option<String> {
|
||||
let mut archive = zip::ZipArchive::new(file).ok()?;
|
||||
|
||||
let entry_name = find_entry(&archive, "instance.cfg")?;
|
||||
tracing::trace!("Reading instance name from {}", entry_name);
|
||||
let entry = archive.by_name(&entry_name).ok()?;
|
||||
|
||||
let reader = std::io::BufRead::lines(std::io::BufReader::new(entry));
|
||||
@@ -174,6 +221,7 @@ fn instance_name_from_cfg(path: &Path) -> Option<String> {
|
||||
if let Some(value) = line.strip_prefix("name=") {
|
||||
let name = value.trim().to_string();
|
||||
if !name.is_empty() {
|
||||
tracing::debug!("Read MultiMC instance name '{}' from instance.cfg", name);
|
||||
return Some(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ pub fn parse_import_input(input: &str) -> ImportInput {
|
||||
|| input.starts_with('/')
|
||||
|| input.starts_with("~/")
|
||||
{
|
||||
tracing::debug!("Import input resolved as local file: {}", input);
|
||||
return ImportInput::LocalFile(input.to_string());
|
||||
}
|
||||
|
||||
@@ -41,7 +42,7 @@ pub fn parse_import_input(input: &str) -> ImportInput {
|
||||
.or_else(|| input.strip_prefix("http://modrinth.com/modpack/"))
|
||||
{
|
||||
let parts: Vec<&str> = rest.split('/').filter(|s| !s.is_empty()).collect();
|
||||
return match parts.as_slice() {
|
||||
let parsed = match parts.as_slice() {
|
||||
[slug, "version", version_id, ..] => ImportInput::VersionId {
|
||||
slug: slug.to_string(),
|
||||
version_id: version_id.to_string(),
|
||||
@@ -49,8 +50,11 @@ pub fn parse_import_input(input: &str) -> ImportInput {
|
||||
[slug, ..] => ImportInput::ProjectSlug(slug.to_string()),
|
||||
[] => ImportInput::ProjectSlug(String::new()),
|
||||
};
|
||||
tracing::debug!("Import input resolved as Modrinth URL: {:?}", parsed);
|
||||
return parsed;
|
||||
}
|
||||
|
||||
tracing::debug!("Import input resolved as Modrinth project slug: {}", input);
|
||||
ImportInput::ProjectSlug(input.to_string())
|
||||
}
|
||||
|
||||
@@ -70,12 +74,14 @@ pub struct ImportSummary {
|
||||
// peeks inside a zip to figure out what format it is.
|
||||
// checks for modrinth.index.json first, then mmc-pack.json.
|
||||
pub fn detect_format(path: &Path) -> Result<PackFormat, String> {
|
||||
tracing::debug!("Detecting modpack format for {}", path.display());
|
||||
let file =
|
||||
std::fs::File::open(path).map_err(|e| format!("Cannot open '{}': {e}", path.display()))?;
|
||||
let archive =
|
||||
zip::ZipArchive::new(file).map_err(|e| format!("Invalid ZIP '{}': {e}", path.display()))?;
|
||||
|
||||
if archive.file_names().any(|n| n == "modrinth.index.json") {
|
||||
tracing::debug!("Detected Modrinth .mrpack archive: {}", path.display());
|
||||
return Ok(PackFormat::Mrpack);
|
||||
}
|
||||
|
||||
@@ -84,21 +90,36 @@ pub fn detect_format(path: &Path) -> Result<PackFormat, String> {
|
||||
.file_names()
|
||||
.any(|n| n == "mmc-pack.json" || n.ends_with("/mmc-pack.json"))
|
||||
{
|
||||
tracing::debug!("Detected MultiMC/Prism archive: {}", path.display());
|
||||
return Ok(PackFormat::Mmc);
|
||||
}
|
||||
|
||||
tracing::warn!("Unknown modpack archive format: {}", path.display());
|
||||
Err("Unknown pack format: no modrinth.index.json or mmc-pack.json found".to_string())
|
||||
}
|
||||
|
||||
pub fn build_summary(path: &Path) -> Result<ImportSummary, String> {
|
||||
if !path.exists() {
|
||||
tracing::warn!("Cannot import missing file {}", path.display());
|
||||
return Err(format!("File not found: {}", path.display()));
|
||||
}
|
||||
let format = detect_format(path)?;
|
||||
match format {
|
||||
let summary = match format {
|
||||
PackFormat::Mrpack => mrpack::build_summary(path),
|
||||
PackFormat::Mmc => mmc::build_summary(path),
|
||||
}
|
||||
}?;
|
||||
tracing::debug!(
|
||||
"Built import summary for {}: name='{}' format={:?} mc={} loader={} loader_version={:?} mods={} overrides={}",
|
||||
path.display(),
|
||||
summary.name,
|
||||
summary.format,
|
||||
summary.game_version,
|
||||
summary.loader,
|
||||
summary.loader_version,
|
||||
summary.mod_count,
|
||||
summary.override_count
|
||||
);
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
pub fn unique_instance_name(base: &str, instances_dir: &Path) -> String {
|
||||
@@ -108,6 +129,7 @@ pub fn unique_instance_name(base: &str, instances_dir: &Path) -> String {
|
||||
.join("instance.json")
|
||||
.exists()
|
||||
{
|
||||
tracing::trace!("Import instance name '{}' is available", candidate);
|
||||
return candidate;
|
||||
}
|
||||
for n in 2..100 {
|
||||
@@ -117,9 +139,18 @@ pub fn unique_instance_name(base: &str, instances_dir: &Path) -> String {
|
||||
.join("instance.json")
|
||||
.exists()
|
||||
{
|
||||
tracing::debug!(
|
||||
"Import instance name '{}' collided; using '{}'",
|
||||
base,
|
||||
candidate
|
||||
);
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
tracing::warn!(
|
||||
"Import instance name '{}' had many collisions; using fallback suffix",
|
||||
base
|
||||
);
|
||||
format!("{base} (import)")
|
||||
}
|
||||
|
||||
@@ -127,6 +158,12 @@ pub async fn execute_import(
|
||||
summary: &ImportSummary,
|
||||
manager: &InstanceManager,
|
||||
) -> Result<crate::instance::InstanceConfig, Box<dyn std::error::Error + Send + Sync>> {
|
||||
tracing::info!(
|
||||
"Executing {:?} import '{}' from {}",
|
||||
summary.format,
|
||||
summary.name,
|
||||
summary.archive_path.display()
|
||||
);
|
||||
match summary.format {
|
||||
PackFormat::Mrpack => mrpack::execute_import(summary, manager).await,
|
||||
PackFormat::Mmc => mmc::execute_import(summary, manager).await,
|
||||
|
||||
@@ -12,6 +12,13 @@ use super::{ImportSummary, PackFormat};
|
||||
|
||||
pub fn build_summary(path: &Path) -> Result<ImportSummary, String> {
|
||||
let index = crate::net::modrinth::parse_mrpack(path)?;
|
||||
tracing::debug!(
|
||||
"Parsed .mrpack '{}' version_id={} files={} deps={}",
|
||||
index.name,
|
||||
index.version_id,
|
||||
index.files.len(),
|
||||
index.dependencies.len()
|
||||
);
|
||||
|
||||
let game_version = crate::net::modrinth::game_version_from_dependencies(&index.dependencies)
|
||||
.ok_or_else(|| "Manifest missing minecraft dependency".to_string())?;
|
||||
@@ -21,6 +28,13 @@ pub fn build_summary(path: &Path) -> Result<ImportSummary, String> {
|
||||
let loader = loader_opt.unwrap_or(ModLoader::Vanilla);
|
||||
|
||||
let override_count = count_overrides(path).unwrap_or(0);
|
||||
tracing::trace!(
|
||||
".mrpack summary: game_version={} loader={:?} loader_version={:?} overrides={}",
|
||||
game_version,
|
||||
loader,
|
||||
loader_version,
|
||||
override_count
|
||||
);
|
||||
|
||||
Ok(ImportSummary {
|
||||
name: index.name.clone(),
|
||||
@@ -54,6 +68,11 @@ pub async fn execute_import(
|
||||
manager: &InstanceManager,
|
||||
) -> Result<crate::instance::InstanceConfig, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let name = super::unique_instance_name(&summary.name, &manager.instances_dir);
|
||||
tracing::info!(
|
||||
"Importing Modrinth pack '{}' as instance '{}'",
|
||||
summary.name,
|
||||
name
|
||||
);
|
||||
|
||||
progress::set_action(format!("Importing '{name}'..."));
|
||||
progress::set_sub_action(format!("{} {}", summary.game_version, summary.loader));
|
||||
@@ -78,6 +97,7 @@ pub async fn execute_import(
|
||||
extract_overrides(&summary.archive_path, &minecraft_dir)?;
|
||||
|
||||
progress::clear();
|
||||
tracing::info!("Imported Modrinth pack '{}' as '{}'", summary.name, name);
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
@@ -93,6 +113,12 @@ async fn download_mod_files(
|
||||
let client = crate::net::HttpClient::new();
|
||||
let total = index.files.len();
|
||||
let completed = Arc::new(AtomicUsize::new(0));
|
||||
tracing::debug!(
|
||||
"Downloading {} file(s) from .mrpack '{}' into {}",
|
||||
total,
|
||||
index.name,
|
||||
minecraft_dir.display()
|
||||
);
|
||||
|
||||
progress::set_action(format!("Downloading mods... 0/{total}"));
|
||||
|
||||
@@ -107,6 +133,9 @@ async fn download_mod_files(
|
||||
let client = client.clone();
|
||||
let dest = minecraft_dir.join(&file.path);
|
||||
let url = file.downloads.first().cloned().unwrap_or_default();
|
||||
if url.is_empty() {
|
||||
tracing::warn!(".mrpack file '{}' has no download URL", file.path);
|
||||
}
|
||||
let filename = file
|
||||
.path
|
||||
.rsplit('/')
|
||||
@@ -116,9 +145,16 @@ async fn download_mod_files(
|
||||
let completed = completed.clone();
|
||||
tasks.spawn(async move {
|
||||
if let Some(parent) = dest.parent() {
|
||||
let _ = tokio::fs::create_dir_all(parent).await;
|
||||
if 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?;
|
||||
let done = completed.fetch_add(1, Ordering::Relaxed) + 1;
|
||||
progress::set_action(format!("Downloading mods... {done}/{total}"));
|
||||
@@ -136,6 +172,9 @@ async fn download_mod_files(
|
||||
let client = client.clone();
|
||||
let dest = minecraft_dir.join(&file.path);
|
||||
let url = file.downloads.first().cloned().unwrap_or_default();
|
||||
if url.is_empty() {
|
||||
tracing::warn!(".mrpack file '{}' has no download URL", file.path);
|
||||
}
|
||||
let filename = file
|
||||
.path
|
||||
.rsplit('/')
|
||||
@@ -145,9 +184,16 @@ async fn download_mod_files(
|
||||
let completed = completed.clone();
|
||||
tasks.spawn(async move {
|
||||
if let Some(parent) = dest.parent() {
|
||||
let _ = tokio::fs::create_dir_all(parent).await;
|
||||
if 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?;
|
||||
let done = completed.fetch_add(1, Ordering::Relaxed) + 1;
|
||||
progress::set_action(format!("Downloading mods... {done}/{total}"));
|
||||
@@ -175,6 +221,8 @@ fn extract_overrides(
|
||||
|
||||
let file = std::fs::File::open(mrpack_path)?;
|
||||
let mut archive = zip::ZipArchive::new(file)?;
|
||||
let mut extracted = 0usize;
|
||||
let mut dirs = 0usize;
|
||||
|
||||
for i in 0..archive.len() {
|
||||
let mut entry = archive.by_index(i)?;
|
||||
@@ -191,6 +239,7 @@ fn extract_overrides(
|
||||
if relative.is_empty() || entry_name.ends_with('/') {
|
||||
let dir = minecraft_dir.join(relative);
|
||||
std::fs::create_dir_all(dir)?;
|
||||
dirs += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -201,8 +250,21 @@ fn extract_overrides(
|
||||
|
||||
let mut buf = Vec::new();
|
||||
entry.read_to_end(&mut buf)?;
|
||||
tracing::trace!(
|
||||
"Extracting .mrpack override {} to {} ({} bytes)",
|
||||
entry_name,
|
||||
dest.display(),
|
||||
buf.len()
|
||||
);
|
||||
std::fs::write(&dest, &buf)?;
|
||||
extracted += 1;
|
||||
}
|
||||
|
||||
tracing::debug!(
|
||||
"Extracted {} override files and {} directories from {}",
|
||||
extracted,
|
||||
dirs,
|
||||
mrpack_path.display()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
@@ -523,6 +523,16 @@ pub async fn launch(
|
||||
};
|
||||
|
||||
let invocation = build_launch_invocation(config, instances_dir, meta_dir, &auth).await?;
|
||||
tracing::debug!(
|
||||
"[{}] Prepared launch invocation: working_dir={} classpath_entries={} jvm_args={} extra_args={} game_args={} main_class={}",
|
||||
name,
|
||||
invocation.working_dir.display(),
|
||||
invocation.classpath.len(),
|
||||
invocation.jvm_args.len(),
|
||||
invocation.extra_args.len(),
|
||||
invocation.game_args.len(),
|
||||
invocation.main_class
|
||||
);
|
||||
|
||||
let (kill_tx, kill_rx) = tokio::sync::oneshot::channel::<()>();
|
||||
crate::running::register_kill(&name, kill_tx);
|
||||
@@ -563,13 +573,23 @@ pub async fn launch(
|
||||
Err(e) => {
|
||||
crate::running::cleanup_kill_sender(&name);
|
||||
crate::running::remove(&name);
|
||||
tracing::error!("[{}] Failed to spawn Minecraft process: {}", name, e);
|
||||
return Err(LaunchError::Io(e));
|
||||
}
|
||||
};
|
||||
tracing::debug!("[{}] Spawned Minecraft process", name);
|
||||
|
||||
crate::running::set_state(&name, crate::running::RunState::Running);
|
||||
|
||||
let log_file_path = crate::instance::log_files::create_log_file(instances_dir, &name);
|
||||
match &log_file_path {
|
||||
Some(path) => tracing::debug!(
|
||||
"[{}] Writing Minecraft process log to {}",
|
||||
name,
|
||||
path.display()
|
||||
),
|
||||
None => tracing::warn!("[{}] Could not create Minecraft process log file", name),
|
||||
}
|
||||
|
||||
let name_for_task = name.clone();
|
||||
let instances_dir_owned = instances_dir.to_path_buf();
|
||||
@@ -636,6 +656,7 @@ pub async fn launch(
|
||||
break;
|
||||
}
|
||||
}
|
||||
tracing::trace!("Minecraft stdout capture task ended");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -654,6 +675,7 @@ pub async fn launch(
|
||||
break;
|
||||
}
|
||||
}
|
||||
tracing::trace!("Minecraft stderr capture task ended");
|
||||
});
|
||||
}
|
||||
drop(log_tx);
|
||||
@@ -675,6 +697,11 @@ pub async fn launch(
|
||||
|
||||
if code == Some(0) || killed_by_user {
|
||||
crate::running::remove(&name_for_task);
|
||||
tracing::debug!(
|
||||
"[{}] Cleared running state after normal exit (killed_by_user={})",
|
||||
name_for_task,
|
||||
killed_by_user
|
||||
);
|
||||
} else {
|
||||
crate::running::set_state(&name_for_task, crate::running::RunState::Crashed(code));
|
||||
crate::tui::error_buffer::push_error(crate::tui::error_buffer::ErrorEvent {
|
||||
|
||||
@@ -26,7 +26,16 @@ impl ModLoaderInstaller for FabricInstaller {
|
||||
client: &HttpClient,
|
||||
game_version: &str,
|
||||
) -> Result<Vec<String>, NetError> {
|
||||
tracing::debug!(
|
||||
"Fetching Fabric loader versions for Minecraft {}",
|
||||
game_version
|
||||
);
|
||||
let loader_versions = fabric_api::fetch_fabric_versions(client, game_version).await?;
|
||||
tracing::debug!(
|
||||
"Fetched {} Fabric loader version(s) for Minecraft {}",
|
||||
loader_versions.len(),
|
||||
game_version
|
||||
);
|
||||
Ok(loader_versions
|
||||
.into_iter()
|
||||
.map(|lv| lv.loader.version)
|
||||
@@ -41,14 +50,29 @@ impl ModLoaderInstaller for FabricInstaller {
|
||||
_instance_dir: &Path,
|
||||
meta_dir: &Path,
|
||||
) -> Result<(), NetError> {
|
||||
tracing::info!(
|
||||
"Installing Fabric {} for Minecraft {}",
|
||||
loader_version,
|
||||
game_version
|
||||
);
|
||||
let (profile, raw_bytes) =
|
||||
fabric_api::fetch_fabric_profile_with_raw(client, game_version, loader_version).await?;
|
||||
tracing::debug!(
|
||||
"Fetched Fabric profile {} with {} libraries",
|
||||
profile.id,
|
||||
profile.libraries.len()
|
||||
);
|
||||
fabric_api::download_fabric_libraries(client, &profile, meta_dir).await?;
|
||||
super::save_profile_bytes(
|
||||
meta_dir,
|
||||
&format!("fabric-{game_version}-{loader_version}.json"),
|
||||
&raw_bytes,
|
||||
)?;
|
||||
tracing::debug!(
|
||||
"Saved Fabric profile for Minecraft {} loader {}",
|
||||
game_version,
|
||||
loader_version
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,14 @@ impl ModLoaderInstaller for ForgeInstaller {
|
||||
client: &HttpClient,
|
||||
game_version: &str,
|
||||
) -> Result<Vec<String>, NetError> {
|
||||
forge_api::fetch_forge_versions(client, game_version).await
|
||||
tracing::debug!("Fetching Forge versions for Minecraft {}", game_version);
|
||||
let versions = forge_api::fetch_forge_versions(client, game_version).await?;
|
||||
tracing::debug!(
|
||||
"Fetched {} Forge version(s) for Minecraft {}",
|
||||
versions.len(),
|
||||
game_version
|
||||
);
|
||||
Ok(versions)
|
||||
}
|
||||
|
||||
async fn install(
|
||||
@@ -39,6 +46,12 @@ impl ModLoaderInstaller for ForgeInstaller {
|
||||
meta_dir: &Path,
|
||||
) -> Result<(), NetError> {
|
||||
let installer_jar = instance_dir.join(".minecraft").join("forge-installer.jar");
|
||||
tracing::info!(
|
||||
"Installing Forge {} for Minecraft {}",
|
||||
loader_version,
|
||||
game_version
|
||||
);
|
||||
tracing::debug!("Forge installer path: {}", installer_jar.display());
|
||||
|
||||
forge_api::download_forge_installer(client, game_version, loader_version, &installer_jar)
|
||||
.await?;
|
||||
@@ -47,6 +60,7 @@ impl ModLoaderInstaller for ForgeInstaller {
|
||||
|
||||
if forge_api::has_legacy_install_profile(&installer_jar) {
|
||||
// old forge: no --installClient support, extract directly from jar
|
||||
tracing::debug!("Forge installer uses legacy install_profile.json path");
|
||||
if let Err(e) = forge_api::install_forge_from_profile(
|
||||
client,
|
||||
&installer_jar,
|
||||
@@ -56,6 +70,7 @@ impl ModLoaderInstaller for ForgeInstaller {
|
||||
.await
|
||||
{
|
||||
let _ = tokio::fs::remove_file(&installer_jar).await;
|
||||
tracing::error!("Legacy Forge installation failed: {}", e);
|
||||
return Err(e);
|
||||
}
|
||||
} else {
|
||||
@@ -65,10 +80,12 @@ impl ModLoaderInstaller for ForgeInstaller {
|
||||
.effective_java_path()
|
||||
.map(str::to_owned)
|
||||
.unwrap_or_else(crate::net::detect_java_path);
|
||||
tracing::debug!("Running Forge installer with Java {}", java_path);
|
||||
if let Err(e) =
|
||||
forge_api::run_forge_installer(&installer_jar, instance_dir, &java_path).await
|
||||
{
|
||||
let _ = tokio::fs::remove_file(&installer_jar).await;
|
||||
tracing::error!("Modern Forge installer failed: {}", e);
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
@@ -80,6 +97,11 @@ impl ModLoaderInstaller for ForgeInstaller {
|
||||
tracing::warn!("Failed to remove Forge installer JAR: {}", e);
|
||||
}
|
||||
|
||||
tracing::debug!(
|
||||
"Installed Forge {} for Minecraft {}",
|
||||
loader_version,
|
||||
game_version
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,18 +79,32 @@ pub(crate) fn save_installer_profile(
|
||||
.join(format!("{version_dir_name}.json"));
|
||||
|
||||
if !ver_json_path.exists() {
|
||||
tracing::error!(
|
||||
"Installer profile JSON missing: {}",
|
||||
ver_json_path.display()
|
||||
);
|
||||
return Err(NetError::Parse(format!(
|
||||
"Version JSON not found at {}",
|
||||
ver_json_path.display()
|
||||
)));
|
||||
}
|
||||
|
||||
tracing::debug!(
|
||||
"Saving installer profile {} from {}",
|
||||
profile_filename,
|
||||
ver_json_path.display()
|
||||
);
|
||||
let raw = std::fs::read(&ver_json_path)?;
|
||||
|
||||
let profiles_dir = meta_dir.join("loader-profiles");
|
||||
std::fs::create_dir_all(&profiles_dir)?;
|
||||
let profile_path = profiles_dir.join(profile_filename);
|
||||
std::fs::write(&profile_path, &raw)?;
|
||||
tracing::debug!(
|
||||
"Saved installer profile to {} ({} bytes)",
|
||||
profile_path.display(),
|
||||
raw.len()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,14 @@ impl ModLoaderInstaller for NeoForgeInstaller {
|
||||
client: &HttpClient,
|
||||
game_version: &str,
|
||||
) -> Result<Vec<String>, NetError> {
|
||||
neoforge_api::fetch_neoforge_versions(client, game_version).await
|
||||
tracing::debug!("Fetching NeoForge versions for Minecraft {}", game_version);
|
||||
let versions = neoforge_api::fetch_neoforge_versions(client, game_version).await?;
|
||||
tracing::debug!(
|
||||
"Fetched {} NeoForge version(s) for Minecraft {}",
|
||||
versions.len(),
|
||||
game_version
|
||||
);
|
||||
Ok(versions)
|
||||
}
|
||||
|
||||
async fn install(
|
||||
@@ -40,6 +47,8 @@ impl ModLoaderInstaller for NeoForgeInstaller {
|
||||
let installer_jar = instance_dir
|
||||
.join(".minecraft")
|
||||
.join("neoforge-installer.jar");
|
||||
tracing::info!("Installing NeoForge {}", loader_version);
|
||||
tracing::debug!("NeoForge installer path: {}", installer_jar.display());
|
||||
|
||||
neoforge_api::download_neoforge_installer(client, loader_version, &installer_jar).await?;
|
||||
|
||||
@@ -48,10 +57,12 @@ impl ModLoaderInstaller for NeoForgeInstaller {
|
||||
.effective_java_path()
|
||||
.map(str::to_owned)
|
||||
.unwrap_or_else(crate::net::detect_java_path);
|
||||
tracing::debug!("Running NeoForge installer with Java {}", java_path);
|
||||
if let Err(e) =
|
||||
neoforge_api::run_neoforge_installer(&installer_jar, instance_dir, &java_path).await
|
||||
{
|
||||
let _ = tokio::fs::remove_file(&installer_jar).await;
|
||||
tracing::error!("NeoForge installer failed: {}", e);
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
@@ -61,6 +72,7 @@ impl ModLoaderInstaller for NeoForgeInstaller {
|
||||
|
||||
save_neoforge_profile(instance_dir, meta_dir, loader_version)?;
|
||||
|
||||
tracing::debug!("Installed NeoForge {}", loader_version);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,16 @@ impl ModLoaderInstaller for QuiltInstaller {
|
||||
client: &HttpClient,
|
||||
game_version: &str,
|
||||
) -> Result<Vec<String>, NetError> {
|
||||
tracing::debug!(
|
||||
"Fetching Quilt loader versions for Minecraft {}",
|
||||
game_version
|
||||
);
|
||||
let loader_versions = quilt_api::fetch_quilt_versions(client, game_version).await?;
|
||||
tracing::debug!(
|
||||
"Fetched {} Quilt loader version(s) for Minecraft {}",
|
||||
loader_versions.len(),
|
||||
game_version
|
||||
);
|
||||
Ok(loader_versions
|
||||
.into_iter()
|
||||
.map(|lv| lv.loader.version)
|
||||
@@ -41,14 +50,29 @@ impl ModLoaderInstaller for QuiltInstaller {
|
||||
_instance_dir: &Path,
|
||||
meta_dir: &Path,
|
||||
) -> Result<(), NetError> {
|
||||
tracing::info!(
|
||||
"Installing Quilt {} for Minecraft {}",
|
||||
loader_version,
|
||||
game_version
|
||||
);
|
||||
let (profile, raw_bytes) =
|
||||
quilt_api::fetch_quilt_profile_with_raw(client, game_version, loader_version).await?;
|
||||
tracing::debug!(
|
||||
"Fetched Quilt profile {} with {} libraries",
|
||||
profile.id,
|
||||
profile.libraries.len()
|
||||
);
|
||||
quilt_api::download_quilt_libraries(client, &profile, meta_dir).await?;
|
||||
super::save_profile_bytes(
|
||||
meta_dir,
|
||||
&format!("quilt-{game_version}-{loader_version}.json"),
|
||||
&raw_bytes,
|
||||
)?;
|
||||
tracing::debug!(
|
||||
"Saved Quilt profile for Minecraft {} loader {}",
|
||||
game_version,
|
||||
loader_version
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
+143
-9
@@ -33,11 +33,17 @@ pub struct InstanceManager {
|
||||
|
||||
impl InstanceManager {
|
||||
pub fn new(instances_dir: impl Into<PathBuf>, meta_dir: impl Into<PathBuf>) -> Self {
|
||||
InstanceManager {
|
||||
let manager = InstanceManager {
|
||||
instances_dir: instances_dir.into(),
|
||||
meta_dir: meta_dir.into(),
|
||||
client: crate::net::HttpClient::new(),
|
||||
}
|
||||
};
|
||||
tracing::trace!(
|
||||
"Created InstanceManager with instances_dir={} meta_dir={}",
|
||||
manager.instances_dir.display(),
|
||||
manager.meta_dir.display()
|
||||
);
|
||||
manager
|
||||
}
|
||||
|
||||
pub async fn create(
|
||||
@@ -51,13 +57,31 @@ impl InstanceManager {
|
||||
|
||||
let instance_dir = self.instances_dir.join(name);
|
||||
let instance_json = instance_dir.join("instance.json");
|
||||
tracing::info!(
|
||||
"Creating instance '{}' (Minecraft {}, loader {}, loader_version={})",
|
||||
name,
|
||||
game_version,
|
||||
loader,
|
||||
loader_version.unwrap_or("<none>")
|
||||
);
|
||||
tracing::debug!("Instance directory: {}", instance_dir.display());
|
||||
|
||||
if instance_json.exists() {
|
||||
tracing::warn!(
|
||||
"Cannot create instance '{}': {} already exists",
|
||||
name,
|
||||
instance_json.display()
|
||||
);
|
||||
return Err(InstanceError::AlreadyExists(name.to_string()));
|
||||
}
|
||||
|
||||
// leftover directory without config = botched previous creation, nuke it
|
||||
if instance_dir.exists() && !instance_json.exists() {
|
||||
tracing::warn!(
|
||||
"Removing incomplete instance directory before recreating '{}': {}",
|
||||
name,
|
||||
instance_dir.display()
|
||||
);
|
||||
std::fs::remove_dir_all(&instance_dir)?;
|
||||
}
|
||||
|
||||
@@ -68,8 +92,20 @@ impl InstanceManager {
|
||||
.await;
|
||||
|
||||
// clean up on failure so there's no half-baked instance left around
|
||||
if result.is_err() {
|
||||
let _ = std::fs::remove_dir_all(&instance_dir);
|
||||
if let Err(e) = &result {
|
||||
tracing::error!("Instance '{}' creation failed: {}", name, e);
|
||||
if let Err(cleanup_error) = std::fs::remove_dir_all(&instance_dir) {
|
||||
tracing::warn!(
|
||||
"Failed to clean up incomplete instance directory {}: {}",
|
||||
instance_dir.display(),
|
||||
cleanup_error
|
||||
);
|
||||
} else {
|
||||
tracing::debug!(
|
||||
"Cleaned up incomplete instance directory {}",
|
||||
instance_dir.display()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
@@ -84,14 +120,26 @@ impl InstanceManager {
|
||||
instance_dir: &std::path::Path,
|
||||
) -> Result<InstanceConfig, InstanceError> {
|
||||
let minecraft_dir = instance_dir.join(".minecraft");
|
||||
tracing::debug!(
|
||||
"Preparing Minecraft directory for '{}': {}",
|
||||
name,
|
||||
minecraft_dir.display()
|
||||
);
|
||||
for subdir in &["mods", "config", "resourcepacks", "shaderpacks", "saves"] {
|
||||
std::fs::create_dir_all(minecraft_dir.join(subdir))?;
|
||||
let path = minecraft_dir.join(subdir);
|
||||
std::fs::create_dir_all(&path)?;
|
||||
tracing::trace!("Ensured instance subdirectory {}", path.display());
|
||||
}
|
||||
|
||||
// forge insists on this file existing, even if it's empty json. thanks forge.
|
||||
let launcher_profiles_path = minecraft_dir.join("launcher_profiles.json");
|
||||
if !launcher_profiles_path.exists() {
|
||||
std::fs::write(&launcher_profiles_path, "{}")?;
|
||||
tracing::debug!(
|
||||
"Created launcher_profiles.json for '{}': {}",
|
||||
name,
|
||||
launcher_profiles_path.display()
|
||||
);
|
||||
}
|
||||
|
||||
for meta_subdir in &[
|
||||
@@ -101,13 +149,33 @@ impl InstanceManager {
|
||||
self.meta_dir.join("assets").join("indexes"),
|
||||
] {
|
||||
std::fs::create_dir_all(meta_subdir)?;
|
||||
tracing::trace!("Ensured metadata directory {}", meta_subdir.display());
|
||||
}
|
||||
|
||||
tracing::debug!("Fetching Mojang version manifest for '{}'", name);
|
||||
let manifest = crate::net::mojang::fetch_version_manifest(&self.client).await?;
|
||||
tracing::debug!(
|
||||
"Loaded Mojang manifest with {} version(s); latest release={} snapshot={}",
|
||||
manifest.versions.len(),
|
||||
manifest.latest.release,
|
||||
manifest.latest.snapshot
|
||||
);
|
||||
|
||||
let version_entry = match manifest.versions.iter().find(|v| v.id == game_version) {
|
||||
Some(v) => v,
|
||||
Some(v) => {
|
||||
tracing::debug!(
|
||||
"Resolved Minecraft version '{}' as {} entry",
|
||||
game_version,
|
||||
v.version_type
|
||||
);
|
||||
v
|
||||
}
|
||||
None => {
|
||||
tracing::warn!(
|
||||
"Minecraft version '{}' not found in manifest with {} entries",
|
||||
game_version,
|
||||
manifest.versions.len()
|
||||
);
|
||||
return Err(InstanceError::InvalidName(format!(
|
||||
"Minecraft version '{}' not found in manifest",
|
||||
game_version
|
||||
@@ -117,6 +185,12 @@ impl InstanceManager {
|
||||
|
||||
let (version_meta, raw_meta_bytes) =
|
||||
crate::net::mojang::fetch_version_meta_with_raw(&self.client, version_entry).await?;
|
||||
tracing::debug!(
|
||||
"Fetched version meta '{}' with {} libraries and asset index {}",
|
||||
version_meta.id,
|
||||
version_meta.libraries.len(),
|
||||
version_meta.asset_index.id
|
||||
);
|
||||
|
||||
crate::net::mojang::download_client_jar(&self.client, &version_meta, &self.meta_dir)
|
||||
.await?;
|
||||
@@ -129,10 +203,20 @@ impl InstanceManager {
|
||||
if let Some(parent) = meta_json_path.parent()
|
||||
&& let Err(e) = std::fs::create_dir_all(parent)
|
||||
{
|
||||
tracing::warn!("Failed to ensure meta dir exists: {}", e);
|
||||
tracing::warn!(
|
||||
"Failed to ensure meta dir {} exists: {}",
|
||||
parent.display(),
|
||||
e
|
||||
);
|
||||
}
|
||||
if let Err(e) = std::fs::write(&meta_json_path, &raw_meta_bytes) {
|
||||
tracing::warn!("Failed to save version meta: {}", e);
|
||||
tracing::warn!(
|
||||
"Failed to save version meta {}: {}",
|
||||
meta_json_path.display(),
|
||||
e
|
||||
);
|
||||
} else {
|
||||
tracing::debug!("Saved version meta to {}", meta_json_path.display());
|
||||
}
|
||||
|
||||
crate::net::mojang::download_libraries(&self.client, &version_meta, &self.meta_dir).await?;
|
||||
@@ -150,6 +234,12 @@ impl InstanceManager {
|
||||
)));
|
||||
}
|
||||
};
|
||||
tracing::debug!(
|
||||
"Installing loader {} {} for instance '{}'",
|
||||
loader,
|
||||
effective_loader_version,
|
||||
name
|
||||
);
|
||||
installer
|
||||
.install(
|
||||
&self.client,
|
||||
@@ -175,6 +265,7 @@ impl InstanceManager {
|
||||
};
|
||||
|
||||
self.save(&config)?;
|
||||
tracing::info!("Created instance '{}'", name);
|
||||
|
||||
crate::tui::progress::clear();
|
||||
Ok(config)
|
||||
@@ -183,8 +274,14 @@ impl InstanceManager {
|
||||
pub fn delete(&self, name: &str) -> Result<(), InstanceError> {
|
||||
let instance_dir = self.instances_dir.join(name);
|
||||
if !instance_dir.exists() {
|
||||
tracing::warn!(
|
||||
"Cannot delete missing instance '{}': {}",
|
||||
name,
|
||||
instance_dir.display()
|
||||
);
|
||||
return Err(InstanceError::NotFound(name.to_string()));
|
||||
}
|
||||
tracing::info!("Deleting instance '{}' at {}", name, instance_dir.display());
|
||||
std::fs::remove_dir_all(&instance_dir)?;
|
||||
if let Err(e) = crate::instance::desktop::remove(name) {
|
||||
tracing::warn!("Failed to remove desktop shortcut for '{}': {}", name, e);
|
||||
@@ -200,16 +297,29 @@ impl InstanceManager {
|
||||
));
|
||||
}
|
||||
if old_name == new_name {
|
||||
tracing::debug!("Ignoring no-op instance rename '{}'", old_name);
|
||||
return Ok(());
|
||||
}
|
||||
let old_dir = self.instances_dir.join(old_name);
|
||||
let new_dir = self.instances_dir.join(new_name);
|
||||
if !old_dir.exists() {
|
||||
tracing::warn!(
|
||||
"Cannot rename missing instance '{}': {}",
|
||||
old_name,
|
||||
old_dir.display()
|
||||
);
|
||||
return Err(InstanceError::NotFound(old_name.to_string()));
|
||||
}
|
||||
if new_dir.exists() {
|
||||
tracing::warn!(
|
||||
"Cannot rename instance '{}' to '{}': destination exists at {}",
|
||||
old_name,
|
||||
new_name,
|
||||
new_dir.display()
|
||||
);
|
||||
return Err(InstanceError::AlreadyExists(new_name.to_string()));
|
||||
}
|
||||
tracing::info!("Renaming instance '{}' to '{}'", old_name, new_name);
|
||||
std::fs::rename(&old_dir, &new_dir)?;
|
||||
|
||||
let config_path = new_dir.join("instance.json");
|
||||
@@ -223,6 +333,11 @@ impl InstanceManager {
|
||||
if let Err(e) = crate::instance::desktop::rename(old_name, &config) {
|
||||
tracing::warn!("Failed to rename desktop shortcut: {}", e);
|
||||
}
|
||||
} else {
|
||||
tracing::warn!(
|
||||
"Renamed instance directory but could not update config at {}",
|
||||
config_path.display()
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -230,10 +345,15 @@ impl InstanceManager {
|
||||
|
||||
pub fn load_all(&self) -> Vec<InstanceConfig> {
|
||||
let mut instances = vec![];
|
||||
tracing::debug!("Loading instances from {}", self.instances_dir.display());
|
||||
let read_dir = match std::fs::read_dir(&self.instances_dir) {
|
||||
Ok(rd) => rd,
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to read instances directory: {}", e);
|
||||
tracing::error!(
|
||||
"Failed to read instances directory {}: {}",
|
||||
self.instances_dir.display(),
|
||||
e
|
||||
);
|
||||
return instances;
|
||||
}
|
||||
};
|
||||
@@ -247,6 +367,7 @@ impl InstanceManager {
|
||||
};
|
||||
let config_path = entry.path().join("instance.json");
|
||||
if !config_path.exists() {
|
||||
tracing::trace!("Skipping non-instance directory {}", entry.path().display());
|
||||
continue;
|
||||
}
|
||||
let contents = match std::fs::read_to_string(&config_path) {
|
||||
@@ -263,6 +384,7 @@ impl InstanceManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
tracing::debug!("Loaded {} instance(s)", instances.len());
|
||||
instances
|
||||
}
|
||||
|
||||
@@ -271,9 +393,15 @@ impl InstanceManager {
|
||||
|
||||
let config_path = self.instances_dir.join(name).join("instance.json");
|
||||
if !config_path.exists() {
|
||||
tracing::warn!(
|
||||
"Instance '{}' config is missing at {}",
|
||||
name,
|
||||
config_path.display()
|
||||
);
|
||||
return Err(InstanceError::NotFound(name.to_string()));
|
||||
}
|
||||
|
||||
tracing::debug!("Loading instance '{}' from {}", name, config_path.display());
|
||||
let contents = std::fs::read_to_string(&config_path)?;
|
||||
Ok(serde_json::from_str::<InstanceConfig>(&contents)?)
|
||||
}
|
||||
@@ -283,12 +411,18 @@ impl InstanceManager {
|
||||
let config_path = instance_dir.join("instance.json");
|
||||
let json = serde_json::to_string_pretty(instance)?;
|
||||
std::fs::write(&config_path, &json)?;
|
||||
tracing::debug!(
|
||||
"Saved instance '{}' config to {}",
|
||||
instance.name,
|
||||
config_path.display()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn touch_last_played(&self, name: &str) -> Result<(), InstanceError> {
|
||||
let mut config = self.load_one(name)?;
|
||||
config.last_played = Some(chrono::Utc::now());
|
||||
tracing::debug!("Updating last_played for '{}'", name);
|
||||
self.save(&config)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user