From 1e0905613a7b7b98daf6dfecffa87fc0096a8e55 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Fri, 16 Jan 2026 14:49:05 +0800 Subject: feat: add UNC prefix stripping for Windows paths in Java handling Implemented a helper function to strip the UNC prefix from file paths on Windows, ensuring cleaner path handling. Updated the Java candidate retrieval process to resolve symlinks and apply the new prefix stripping function, enhancing compatibility and usability on Windows systems. --- src-tauri/src/core/java.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src-tauri/src/core/java.rs') diff --git a/src-tauri/src/core/java.rs b/src-tauri/src/core/java.rs index 7aa43b8..3f7a1e4 100644 --- a/src-tauri/src/core/java.rs +++ b/src-tauri/src/core/java.rs @@ -13,6 +13,18 @@ use crate::utils::zip; const ADOPTIUM_API_BASE: &str = "https://api.adoptium.net/v3"; const CACHE_DURATION_SECS: u64 = 24 * 60 * 60; // 24 hours +/// Helper to strip UNC prefix on Windows (\\?\) +fn strip_unc_prefix(path: PathBuf) -> PathBuf { + #[cfg(target_os = "windows")] + { + let s = path.to_string_lossy().to_string(); + if s.starts_with(r"\\?\") { + return PathBuf::from(&s[4..]); + } + } + path +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct JavaInstallation { pub path: String, @@ -649,7 +661,11 @@ fn get_java_candidates() -> Vec { for line in paths.lines() { let path = PathBuf::from(line.trim()); if path.exists() { - candidates.push(path); + // Resolve symlinks (important for Windows javapath wrapper) + let resolved = std::fs::canonicalize(&path).unwrap_or(path); + // Strip UNC prefix if present to keep paths clean + let final_path = strip_unc_prefix(resolved); + candidates.push(final_path); } } } -- cgit v1.2.3-70-g09d2