From 0f5f92d447682bb6fcb3aa3b92a37e8cf7371ea7 Mon Sep 17 00:00:00 2001 From: VirtualHotBar Date: Tue, 2 Jun 2026 02:24:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20#38=20=E4=BF=AE=E6=94=B9Windows=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=90=8D=E5=90=8E=E5=BA=94=E7=94=A8=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rust端:将配置目录创建的expect改为match错误处理,失败时尝试使用临时目录作为后备方案。 TypeScript端:增强validateAndFixPaths()函数,添加挂载路径中旧用户名的检测逻辑。 --- src-tauri/src/lib.rs | 13 +++++++++++-- src/controller/mainInit.ts | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 4fe121a..a60f552 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -249,8 +249,17 @@ pub fn init() -> anyhow::Result<()> { //判断配置目录是否存在,如不存在创建配置目录 let config_dir = app.app_data_dir(); if !config_dir.exists() { - std::fs::create_dir_all(&config_dir).expect("创建配置目录失败"); - println!("创建配置目录成功"); + match std::fs::create_dir_all(&config_dir) { + Ok(_) => println!("创建配置目录成功"), + Err(e) => { + eprintln!("创建配置目录失败: {} (路径: {})", e, config_dir.display()); + // 尝试使用临时目录作为后备方案 + let fallback_dir = std::env::temp_dir().join(".netmount"); + if !fallback_dir.exists() { + let _ = std::fs::create_dir_all(&fallback_dir); + } + } + } } //配置文件 diff --git a/src/controller/mainInit.ts b/src/controller/mainInit.ts index 382a70e..5c9e695 100644 --- a/src/controller/mainInit.ts +++ b/src/controller/mainInit.ts @@ -46,6 +46,21 @@ async function validateAndFixPaths(): Promise { logger.warn('Home directory not resolved, using fallback', 'MainInit') runtimeEnv.path.homeDir = await homeDir() } + + // 检查挂载路径是否包含旧的用户名路径 + // 当 Windows 用户名变更时,挂载路径可能失效 + if (nmConfig.mount && nmConfig.mount.lists) { + for (const mount of nmConfig.mount.lists) { + if (mount.mountPath && mount.mountPath.includes('/Users/') || mount.mountPath.includes('\\Users\\')) { + // 检查挂载路径是否包含当前用户的 home 目录 + const normalizedHome = currentHome.replace(/\\/g, '/').toLowerCase() + const normalizedMount = mount.mountPath.replace(/\\/g, '/').toLowerCase() + if (!normalizedMount.startsWith(normalizedHome)) { + logger.warn(`Mount path may contain old username: ${mount.mountPath}`, 'MainInit') + } + } + } + } } export async function init(setStartStr: SetStartStrFn) {