|
| 1 | +use super::check_mod_translation_exists; |
| 2 | +use std::path::Path; |
| 3 | + |
| 4 | +/// Debug function to test translation detection on a real mod file |
| 5 | +pub async fn debug_check_translation(mod_path: &str, mod_id: &str) { |
| 6 | + println!("\n=== Debug Translation Check ==="); |
| 7 | + println!("Mod Path: {}", mod_path); |
| 8 | + println!("Mod ID: {}", mod_id); |
| 9 | + println!("File exists: {}", Path::new(mod_path).exists()); |
| 10 | + |
| 11 | + let test_languages = vec![ |
| 12 | + "ja_jp", "JA_JP", "ja_JP", // Test case variations |
| 13 | + "zh_cn", "ko_kr", "de_de", "fr_fr", "es_es", |
| 14 | + ]; |
| 15 | + |
| 16 | + println!("\nChecking translations:"); |
| 17 | + for lang in test_languages { |
| 18 | + match check_mod_translation_exists(mod_path, mod_id, lang).await { |
| 19 | + Ok(exists) => { |
| 20 | + println!( |
| 21 | + " {} - {}", |
| 22 | + lang, |
| 23 | + if exists { "EXISTS" } else { "NOT FOUND" } |
| 24 | + ); |
| 25 | + } |
| 26 | + Err(e) => { |
| 27 | + println!(" {} - ERROR: {}", lang, e); |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + // Additional debug: List all files in the JAR that match lang pattern |
| 33 | + println!("\nAttempting to list language files in JAR:"); |
| 34 | + if let Ok(file) = std::fs::File::open(mod_path) { |
| 35 | + if let Ok(mut archive) = zip::ZipArchive::new(file) { |
| 36 | + for i in 0..archive.len() { |
| 37 | + if let Ok(file) = archive.by_index(i) { |
| 38 | + let name = file.name(); |
| 39 | + if name.contains("/lang/") |
| 40 | + && (name.ends_with(".json") || name.ends_with(".lang")) |
| 41 | + { |
| 42 | + println!(" Found: {}", name); |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + } else { |
| 47 | + println!(" ERROR: Failed to read as ZIP archive"); |
| 48 | + } |
| 49 | + } else { |
| 50 | + println!(" ERROR: Failed to open file"); |
| 51 | + } |
| 52 | + |
| 53 | + println!("==============================\n"); |
| 54 | +} |
| 55 | + |
| 56 | +/// Command to run debug check from CLI |
| 57 | +#[tauri::command] |
| 58 | +pub async fn debug_mod_translation_check( |
| 59 | + mod_path: String, |
| 60 | + mod_id: String, |
| 61 | +) -> Result<String, String> { |
| 62 | + let mut output = String::new(); |
| 63 | + |
| 64 | + output.push_str(&format!("Debug Translation Check for: {}\n", mod_path)); |
| 65 | + output.push_str(&format!("Mod ID: {}\n", mod_id)); |
| 66 | + output.push_str(&format!( |
| 67 | + "File exists: {}\n\n", |
| 68 | + Path::new(&mod_path).exists() |
| 69 | + )); |
| 70 | + |
| 71 | + // Check various language codes |
| 72 | + let languages = vec!["ja_jp", "JA_JP", "zh_cn", "ko_kr", "en_us"]; |
| 73 | + |
| 74 | + for lang in languages { |
| 75 | + match check_mod_translation_exists(&mod_path, &mod_id, lang).await { |
| 76 | + Ok(exists) => { |
| 77 | + output.push_str(&format!( |
| 78 | + "{}: {}\n", |
| 79 | + lang, |
| 80 | + if exists { "EXISTS" } else { "NOT FOUND" } |
| 81 | + )); |
| 82 | + } |
| 83 | + Err(e) => { |
| 84 | + output.push_str(&format!("{}: ERROR - {}\n", lang, e)); |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + // List all language files |
| 90 | + output.push_str("\nLanguage files in JAR:\n"); |
| 91 | + if let Ok(file) = std::fs::File::open(&mod_path) { |
| 92 | + if let Ok(mut archive) = zip::ZipArchive::new(file) { |
| 93 | + let mut found_any = false; |
| 94 | + for i in 0..archive.len() { |
| 95 | + if let Ok(file) = archive.by_index(i) { |
| 96 | + let name = file.name(); |
| 97 | + if name.contains("/lang/") |
| 98 | + && (name.ends_with(".json") || name.ends_with(".lang")) |
| 99 | + { |
| 100 | + output.push_str(&format!(" - {}\n", name)); |
| 101 | + found_any = true; |
| 102 | + |
| 103 | + // Check if this matches the expected pattern |
| 104 | + let expected_pattern = format!("assets/{}/lang/", mod_id); |
| 105 | + if name.starts_with(&expected_pattern) { |
| 106 | + output.push_str(" ✓ Matches expected pattern\n"); |
| 107 | + } else { |
| 108 | + output.push_str(" ✗ Does NOT match expected pattern\n"); |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + if !found_any { |
| 114 | + output.push_str(" No language files found\n"); |
| 115 | + } |
| 116 | + } else { |
| 117 | + output.push_str(" ERROR: Not a valid ZIP/JAR file\n"); |
| 118 | + } |
| 119 | + } else { |
| 120 | + output.push_str(" ERROR: File not found or cannot be opened\n"); |
| 121 | + } |
| 122 | + |
| 123 | + Ok(output) |
| 124 | +} |
0 commit comments