diff --git a/package.json b/package.json index 3abf19c..d41b12d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "endfield-cat", "private": true, - "version": "0.2.0", + "version": "0.2.1-pre.6988de34.ac631d6", "type": "module", "engines": { "node": ">=24 <25" diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 904ce6e..6772e63 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -878,7 +878,7 @@ checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7" [[package]] name = "endfield-cat" -version = "0.2.0-pre.6988755b.087703a" +version = "0.2.1" dependencies = [ "futures-util", "reqwest", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 26495d6..fbd39aa 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "endfield-cat" -version = "0.2.0" +version = "0.2.1-pre.6988de34.ac631d6" description = "A Tauri App" authors = ["you"] edition = "2021" diff --git a/src-tauri/src/services/update.rs b/src-tauri/src/services/update.rs index 193146b..509596b 100644 --- a/src-tauri/src/services/update.rs +++ b/src-tauri/src/services/update.rs @@ -24,7 +24,11 @@ pub fn prepare_paths(exe_name: &std::ffi::OsStr) -> Result let new_exe = temp_dir.join(exe_name); let batch_path = temp_dir.join("updater.bat"); - Ok(UpdatePaths { temp_dir, new_exe, batch_path }) + Ok(UpdatePaths { + temp_dir, + new_exe, + batch_path, + }) } pub async fn download_new_exe( @@ -101,7 +105,7 @@ echo 启动新版本... start "" /min "{current_exe}" echo 清理临时文件... -start "" /min cmd /c "timeout /t 3 /nobreak >nul & if exist \"{temp_dir}\" rd /s /q \"{temp_dir}\"" +start "" /min powershell -NoProfile -ExecutionPolicy Bypass -Command "param([string]$p) Start-Sleep -Seconds 3; if (Test-Path -LiteralPath $p) {{ Remove-Item -LiteralPath $p -Recurse -Force }}" "{temp_dir}" exit /b 0 "#, @@ -113,3 +117,35 @@ exit /b 0 batch_content.replace('\n', "\r\n") } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn build_updater_batch_uses_powershell_literalpath_cleanup() { + let content = build_updater_batch( + "endfield-cat.exe", + Path::new("C:\\Temp\\endfield-cat-update\\new.exe"), + Path::new("C:\\Program Files\\EndCat\\endfield-cat.exe"), + Path::new("C:\\Temp\\endfield-cat-update"), + ); + + // In cmd.exe, `\"` is not an escape; it can break parsing and lead to paths like `\\`. + assert!(!content.contains("\\\"")); + assert!(content.contains(r#"powershell -NoProfile -ExecutionPolicy Bypass -Command "param([string]$p) Start-Sleep -Seconds 3; if (Test-Path -LiteralPath $p) { Remove-Item -LiteralPath $p -Recurse -Force }""#)); + assert!(content.contains(r#""C:\Temp\endfield-cat-update""#)); + } + + #[test] + fn build_updater_batch_cleanup_quotes_ampersand_path() { + let content = build_updater_batch( + "endfield-cat.exe", + Path::new("C:\\Temp\\endfield-cat-update\\new.exe"), + Path::new("C:\\Program Files\\EndCat\\endfield-cat.exe"), + Path::new("C:\\Temp\\A&B\\endfield-cat-update"), + ); + + assert!(content.contains(r#""C:\Temp\A&B\endfield-cat-update""#)); + } +} diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 330a549..cccee58 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "endfield-cat", - "version": "0.2.0", + "version": "0.2.1-pre.6988de34.ac631d6", "identifier": "org.boxcat.endfield-cat", "build": { "beforeDevCommand": "yarn dev",