From 853f40dc13e6463bedf30e2471a71bd011be425b Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Fri, 16 Jan 2026 20:24:53 +0800 Subject: feat: implement instance management features and enhance game launch process Added functionality for managing game instances, including creating, deleting, updating, and duplicating instances. Integrated instance selection into the game launch process, allowing users to specify the instance when starting a game. Updated the main application logic to handle instance states and paths, ensuring proper directory management for each instance. Introduced a new module for instance management and updated relevant commands to support instance-specific operations. --- src-tauri/src/utils/path.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src-tauri/src/utils/path.rs') diff --git a/src-tauri/src/utils/path.rs b/src-tauri/src/utils/path.rs index deaebb5..1db6e5b 100644 --- a/src-tauri/src/utils/path.rs +++ b/src-tauri/src/utils/path.rs @@ -59,7 +59,7 @@ pub fn normalize_java_path(java_path: &str) -> Result { } } } - + // If still not found after PATH search, return specific error if !path.exists() { return Err( @@ -80,7 +80,7 @@ pub fn normalize_java_path(java_path: &str) -> Result { // Canonicalize and strip UNC prefix for clean path let canonical = std::fs::canonicalize(&path) .map_err(|e| format!("Failed to resolve Java path '{}': {}", path.display(), e))?; - + Ok(strip_unc_prefix(canonical)) } @@ -98,7 +98,7 @@ pub fn normalize_java_path(java_path: &str) -> Result { } } } - + // If still not found after PATH search, return specific error if !path.exists() { return Err( @@ -119,7 +119,7 @@ pub fn normalize_java_path(java_path: &str) -> Result { // Canonicalize to resolve symlinks and get absolute path let canonical = std::fs::canonicalize(&path) .map_err(|e| format!("Failed to resolve Java path '{}': {}", path.display(), e))?; - + Ok(strip_unc_prefix(canonical)) } @@ -196,23 +196,23 @@ mod tests { fn test_normalize_with_temp_file() { // Create a temporary file to test with an actual existing path let temp_dir = std::env::temp_dir(); - + #[cfg(target_os = "windows")] let temp_file = temp_dir.join("test_java_normalize.exe"); #[cfg(not(target_os = "windows"))] let temp_file = temp_dir.join("test_java_normalize"); - + // Create the file if let Ok(mut file) = fs::File::create(&temp_file) { let _ = file.write_all(b"#!/bin/sh\necho test"); drop(file); - + // Test normalization let result = normalize_java_path(temp_file.to_str().unwrap()); - + // Clean up let _ = fs::remove_file(&temp_file); - + // Verify result assert!(result.is_ok(), "Failed to normalize temp file path"); let normalized = result.unwrap(); @@ -227,12 +227,12 @@ mod tests { let unc_path = PathBuf::from(r"\\?\C:\Windows\System32\cmd.exe"); let stripped = strip_unc_prefix(unc_path); assert_eq!(stripped.to_string_lossy(), r"C:\Windows\System32\cmd.exe"); - + let normal_path = PathBuf::from(r"C:\Windows\System32\cmd.exe"); let unchanged = strip_unc_prefix(normal_path.clone()); assert_eq!(unchanged, normal_path); } - + #[cfg(not(target_os = "windows"))] { let path = PathBuf::from("/usr/bin/java"); -- cgit v1.2.3-70-g09d2 From 535f82514e38261688a15f1564638d6957129cc7 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Fri, 16 Jan 2026 20:31:10 +0800 Subject: fix: improve Java path normalization logic Enhanced the normalization logic for Java paths by ensuring that the search for "java.exe" in the PATH only occurs for relative paths or the name "java", excluding absolute paths that do not exist. This change improves the reliability of locating the Java executable in various environments. --- src-tauri/src/utils/path.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src-tauri/src/utils/path.rs') diff --git a/src-tauri/src/utils/path.rs b/src-tauri/src/utils/path.rs index 1db6e5b..ab14c12 100644 --- a/src-tauri/src/utils/path.rs +++ b/src-tauri/src/utils/path.rs @@ -48,8 +48,12 @@ pub fn normalize_java_path(java_path: &str) -> Result { path.set_extension("exe"); } - // If still not found and it's just "java.exe", try to find it in PATH - if !path.exists() && path.file_name() == Some(std::ffi::OsStr::new("java.exe")) { + // If still not found and it's just "java.exe" (not an absolute path), try to find it in PATH + // Only search PATH for relative paths or just "java", not for absolute paths that don't exist + if !path.exists() + && !path.is_absolute() + && path.file_name() == Some(std::ffi::OsStr::new("java.exe")) + { // Try to locate java.exe in PATH if let Ok(output) = std::process::Command::new("where").arg("java").output() { if output.status.success() { -- cgit v1.2.3-70-g09d2