diff --git a/CHANGELOG.md b/CHANGELOG.md index 764048e..df1a63f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,17 @@ Squid 的重要变更记录在这里。版本号使用语义化版本,日期为发布日。 -## [Unreleased] +## [0.1.15] - 2026-11-30 + +### 应用卸载 + +- Windows 应用卸载现在会调用应用自己的卸载程序:MSI 条目使用 `msiexec /x`,其他条目按注册表命令执行;卸载完成后自动清理残留的卸载注册表记录。 +- 修复 Windows 应用列表中没有 `InstallLocation` 的条目显示 0 B、无法卸载的问题。安装目录会依次从注册表、MSI `InstallLocation`、`DisplayIcon` 和卸载程序路径推断。 +- 修复 Program Files 下的应用被误判为“无权限”,导致只删除残留、应用本体仍在的问题。应用自己的卸载程序会负责提权。 +- 卸载程序已经删除的文件不再被当成失败;卸载完成后自动刷新应用列表,同时保留结果摘要。 +- Windows 应用图标优先使用扫描时解析到的 `DisplayIcon`、卸载程序或可执行文件,缺失图标的情况更少。 +- macOS 应用卸载列表现在也显示真实应用图标。 +- 应用条目的唯一键在没有 bundle id 时回退到注册表键,避免 Windows 条目互相覆盖或无法选中。 ### 文档 diff --git a/Cargo.lock b/Cargo.lock index 64596c8..fe27b98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3583,7 +3583,7 @@ dependencies = [ [[package]] name = "squid-cli" -version = "0.1.14" +version = "0.1.15" dependencies = [ "anyhow", "chrono", @@ -3603,7 +3603,7 @@ dependencies = [ [[package]] name = "squid-core" -version = "0.1.14" +version = "0.1.15" dependencies = [ "anyhow", "chrono", @@ -3622,7 +3622,7 @@ dependencies = [ [[package]] name = "squid-engine" -version = "0.1.14" +version = "0.1.15" dependencies = [ "anyhow", "chrono", @@ -3645,7 +3645,7 @@ dependencies = [ [[package]] name = "squid-guard" -version = "0.1.14" +version = "0.1.15" dependencies = [ "chrono", "hex", @@ -3661,7 +3661,7 @@ dependencies = [ [[package]] name = "squid-platform" -version = "0.1.14" +version = "0.1.15" dependencies = [ "dirs", "file_icon_provider", @@ -3681,7 +3681,7 @@ dependencies = [ [[package]] name = "squid-rules" -version = "0.1.14" +version = "0.1.15" dependencies = [ "globset", "serde", @@ -3693,7 +3693,7 @@ dependencies = [ [[package]] name = "squid-stats" -version = "0.1.14" +version = "0.1.15" dependencies = [ "chrono", "libc", @@ -3706,7 +3706,7 @@ dependencies = [ [[package]] name = "squid-tui" -version = "0.1.14" +version = "0.1.15" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 678d469..7995335 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ members = ["crates/*"] exclude = ["src-tauri"] [workspace.package] -version = "0.1.14" +version = "0.1.15" edition = "2021" rust-version = "1.95" license = "GPL-3.0-only" diff --git a/README.en.md b/README.en.md index 9960763..e628e5e 100644 --- a/README.en.md +++ b/README.en.md @@ -20,18 +20,18 @@ The desktop app supports macOS 12+ and Windows 10/11 x64. The CLI and TUI share ## Download and install -Current version **0.1.14** (2026-11-25). Desktop installers are published on the origin repository's `releases` branch: +Current version **0.1.15** (2026-11-30). Desktop installers are published on the origin repository's `releases` branch: | Platform | Installer | | --- | --- | -| macOS 12+ | [`Squid-0.1.14-macOS-universal.dmg`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-0.1.14-macOS-universal.dmg) | -| Windows 10/11 x64 | [`Squid-Setup-0.1.14-win-x64.exe`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-Setup-0.1.14-win-x64.exe) | +| macOS 12+ | [`Squid-0.1.15-macOS-universal.dmg`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-0.1.15-macOS-universal.dmg) | +| Windows 10/11 x64 | [`Squid-Setup-0.1.15-win-x64.exe`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-Setup-0.1.15-win-x64.exe) | Release directory: Both installers are unsigned builds. On macOS, right-click **Open** the first time; on Windows, choose **More info** > **Run anyway** when SmartScreen appears. See the [usage guide](docs/USAGE.md) for installation, daily use, uninstall, and troubleshooting. -The same installers are attached to the [GitHub release](https://github.com/VulpineLiu/squid/releases/tag/v0.1.14). The GitHub repository does not carry the `releases` branch. The app still checks the origin update channel. +The same installers are attached to the [GitHub release](https://github.com/VulpineLiu/squid/releases/tag/v0.1.15). The GitHub repository does not carry the `releases` branch. The app still checks the origin update channel. ## Features diff --git a/README.md b/README.md index df16934..e60a7a1 100644 --- a/README.md +++ b/README.md @@ -10,19 +10,19 @@ Squid 是面向 macOS 与 Windows 的本地系统维护工具。桌面端、CLI ## Download / 下载 -Latest release: **0.1.14** (2026-11-25). +Latest release: **0.1.15** (2026-11-30). | Platform | Package | | --- | --- | -| macOS 12+ | [`Squid-0.1.14-macOS-universal.dmg`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-0.1.14-macOS-universal.dmg) | -| Windows 10/11 x64 | [`Squid-Setup-0.1.14-win-x64.exe`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-Setup-0.1.14-win-x64.exe) | +| macOS 12+ | [`Squid-0.1.15-macOS-universal.dmg`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-0.1.15-macOS-universal.dmg) | +| Windows 10/11 x64 | [`Squid-Setup-0.1.15-win-x64.exe`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-Setup-0.1.15-win-x64.exe) | Installers live on the origin repository's `releases` branch: -The same installers are attached to the [GitHub release](https://github.com/VulpineLiu/squid/releases/tag/v0.1.14). The GitHub repository does not carry the `releases` branch, and the app's update feed still points at the origin channel. +The same installers are attached to the [GitHub release](https://github.com/VulpineLiu/squid/releases/tag/v0.1.15). The GitHub repository does not carry the `releases` branch, and the app's update feed still points at the origin channel. -安装包发布在 origin 仓库的 `releases` 分支,并同步附到 [GitHub Release](https://github.com/VulpineLiu/squid/releases/tag/v0.1.14)。GitHub 不承载 `releases` 分支;应用更新仍从 origin 的发布通道检查。 +安装包发布在 origin 仓库的 `releases` 分支,并同步附到 [GitHub Release](https://github.com/VulpineLiu/squid/releases/tag/v0.1.15)。GitHub 不承载 `releases` 分支;应用更新仍从 origin 的发布通道检查。 ## Highlights / 功能 diff --git a/README.zh-CN.md b/README.zh-CN.md index fc620dc..6a27e41 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -20,18 +20,18 @@ Squid 是面向 macOS 与 Windows 的本地系统维护工具:清理可重建 ## 下载与安装 -当前版本 **0.1.14**(2026-11-25)。桌面安装包发布在 origin 仓库的 `releases` 分支: +当前版本 **0.1.15**(2026-11-30)。桌面安装包发布在 origin 仓库的 `releases` 分支: | 平台 | 安装包 | | --- | --- | -| macOS 12+ | [`Squid-0.1.14-macOS-universal.dmg`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-0.1.14-macOS-universal.dmg) | -| Windows 10/11 x64 | [`Squid-Setup-0.1.14-win-x64.exe`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-Setup-0.1.14-win-x64.exe) | +| macOS 12+ | [`Squid-0.1.15-macOS-universal.dmg`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-0.1.15-macOS-universal.dmg) | +| Windows 10/11 x64 | [`Squid-Setup-0.1.15-win-x64.exe`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-Setup-0.1.15-win-x64.exe) | 发布目录: 两个安装包都是未签名构建。macOS 首次打开请在访达中右键选择“打开”;Windows SmartScreen 提示时选择“更多信息” > “仍要运行”。完整的安装、使用、卸载与故障排查见[使用帮助](docs/USAGE.zh-CN.md)。 -同一批安装包也会附到 [GitHub Release](https://github.com/VulpineLiu/squid/releases/tag/v0.1.14)。GitHub 不承载 `releases` 分支;应用更新仍从 origin 的发布通道检查。 +同一批安装包也会附到 [GitHub Release](https://github.com/VulpineLiu/squid/releases/tag/v0.1.15)。GitHub 不承载 `releases` 分支;应用更新仍从 origin 的发布通道检查。 ## 功能 diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 4de612f..9b2c3c2 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,10 +1,11 @@ -Squid 0.1.14 +Squid 0.1.15 -- 全站统一标准组件库:页签、卡片、行、状态标签、工具栏与搜索框使用同一套定义,不再由各模块自行实现。 -- 空间清理的“垃圾清理 / 重复文件 / 大文件”三个页签与设置页页签保持同一套样式。 -- 权限管理的开机启动项改用统一行布局,状态、来源、路径和操作位置与其他模块一致。 -- 精简设置页与各页面布局;一级标题下不再重复二级描述,标题末尾不再带句号。 -- 主界面的更新提示直接打开“设置 → 更新”分区。 -- macOS 隐藏仅支持 Windows 的系统维护模块;权限管理保留开机启动项。 +- Windows 应用卸载现在会调用应用自己的卸载程序:MSI 条目使用 `msiexec /x`,其他条目按注册表命令执行;卸载完成后自动清理残留的卸载注册表记录。 +- 修复 Windows 应用列表中没有 `InstallLocation` 的条目显示 0 B、无法卸载的问题。安装目录会依次从注册表、MSI `InstallLocation`、`DisplayIcon` 和卸载程序路径推断。 +- 修复 Program Files 下的应用被误判为“无权限”,导致只删除残留、应用本体仍在的问题。应用自己的卸载程序会负责提权。 +- 卸载程序已经删除的文件不再被当成失败;卸载完成后自动刷新应用列表,同时保留结果摘要。 +- Windows 应用图标优先使用扫描时解析到的 `DisplayIcon`、卸载程序或可执行文件,缺失图标的情况更少。 +- macOS 应用卸载列表现在也显示真实应用图标。 +- 应用条目的唯一键在没有 bundle id 时回退到注册表键,避免 Windows 条目互相覆盖或无法选中。 macOS 与 Windows 安装包均为未签名构建。macOS 首次打开请在访达中右键选择“打开”;Windows SmartScreen 提示时选择“更多信息” > “仍要运行”。 diff --git a/crates/squid-core/src/model.rs b/crates/squid-core/src/model.rs index 70dcd29..bf68ac7 100644 --- a/crates/squid-core/src/model.rs +++ b/crates/squid-core/src/model.rs @@ -442,6 +442,7 @@ impl AppInfo { pub fn key(&self) -> String { self.bundle_id .clone() + .or_else(|| self.reg_key.clone()) .unwrap_or_else(|| self.path.to_string_lossy().into_owned()) } } diff --git a/crates/squid-engine/src/uninstall.rs b/crates/squid-engine/src/uninstall.rs index 14e7045..2763432 100644 --- a/crates/squid-engine/src/uninstall.rs +++ b/crates/squid-engine/src/uninstall.rs @@ -124,9 +124,14 @@ pub fn build_plan( } // 1. The bundle itself. + let bundle_kind = if app.path.is_file() { + ItemKind::File + } else { + ItemKind::Path + }; let mut bundle_item = CleanupItem::new( app.path.clone(), - ItemKind::Path, + bundle_kind, Category::Leftovers, app.name.clone(), ) @@ -136,13 +141,28 @@ pub fn build_plan( Some(version) => format!("{} · {}", app.source, version), None => app.source.clone(), }); - if app.dead || app.path.as_os_str().is_empty() { + if app.dead { // 安装不完整: there is no bundle to move to the bin — the plan // carries only the leftovers and the registry record the page // offers to drop. bundle_item = bundle_item .locked(LockReason::Protected) .with_note("程序本体已不存在,仅需清理注册表记录与残留"); + } else if app.path.as_os_str().is_empty() { + // Windows Installer entries can be installed without exposing an + // install folder. Keep the row selectable so remove_plan runs the + // vendor uninstaller instead of pretending the app is missing. + if app + .uninstall_string + .as_deref() + .is_some_and(|raw| !raw.trim().is_empty()) + { + bundle_item.note = Some("由系统卸载程序卸载".into()); + } else { + bundle_item = bundle_item + .locked(LockReason::Protected) + .with_note("无法定位安装目录,且没有可用的卸载命令"); + } } else if system { bundle_item = bundle_item .locked(LockReason::Protected) @@ -151,7 +171,10 @@ pub fn build_plan( bundle_item = bundle_item .locked(LockReason::AppRunning) .with_note("quit the app first"); - } else if !crate::writable_by_us(&app.path) && !crate::is_root() { + } else if !cfg!(windows) && !crate::writable_by_us(&app.path) && !crate::is_root() { + // Windows apps in Program Files are not writable by the user, but + // their own uninstaller handles elevation. Locking the bundle here + // made Squid delete only leftovers and leave the app installed. bundle_item = bundle_item.locked(LockReason::NotOwned).with_note(format!( "{} to remove this copy", squid_core::elevation_hint() @@ -280,7 +303,17 @@ pub fn remove_plan( progress: &Progress, cancel: &CancelToken, ) -> squid_core::Result { - let prepared = engine.platform().prepare_uninstall(&plan.app); + // A plan may contain only leftovers. The platform uninstaller belongs to + // the app bundle, so run it only when the bundle itself is selected. + let uninstalling_app = plan + .items + .iter() + .any(|item| item.selected && item.lock.is_none() && item.rule_id == "uninstall-bundle"); + let prepared = if uninstalling_app { + engine.platform().prepare_uninstall(&plan.app) + } else { + squid_platform::LifecycleReport::default() + }; for note in &prepared.notes { progress.note(note.clone()); } @@ -294,8 +327,35 @@ pub fn remove_plan( )); } - let job = DeleteJob::new(plan.items.clone(), mode, "squid uninstall"); - let outcome = delete::execute(engine, &job, progress, cancel)?; + // The vendor uninstaller may already have removed some (or all) of the + // selected paths. Treat those as removed instead of reporting ENOENT as a + // failure — that made a successful Windows uninstall look broken. + let mut job_items = Vec::with_capacity(plan.items.len()); + let mut already_removed: Vec = Vec::new(); + for item in &plan.items { + let removable = item.selected && item.lock.is_none(); + let gone = removable + && std::fs::symlink_metadata(&item.path) + .is_err_and(|error| error.kind() == std::io::ErrorKind::NotFound); + if gone { + already_removed.push(item.clone()); + } else { + job_items.push(item.clone()); + } + } + let job = DeleteJob::new(job_items, mode, "squid uninstall"); + let mut outcome = if job.removable().is_empty() && !already_removed.is_empty() { + let mut outcome = DeleteOutcome::default(); + outcome.summary.mode = Some(mode); + outcome + } else { + delete::execute(engine, &job, progress, cancel)? + }; + for item in already_removed { + outcome.summary.freed += item.size; + outcome.summary.freed_allocated += item.allocated; + outcome.summary.removed += 1; + } let removed: Vec = outcome .summary @@ -304,7 +364,11 @@ pub fn remove_plan( .and_then(squid_core::ledger::load_session) .map(|session| session.entries.into_iter().map(|e| e.path).collect()) .unwrap_or_default(); - let finished = engine.platform().finish_uninstall(&plan.app, &removed); + let finished = if uninstalling_app { + engine.platform().finish_uninstall(&plan.app, &removed) + } else { + squid_platform::LifecycleReport::default() + }; for note in finished.notes { progress.note(note); } diff --git a/crates/squid-platform/src/permissions.rs b/crates/squid-platform/src/permissions.rs index 9c16963..e11b793 100644 --- a/crates/squid-platform/src/permissions.rs +++ b/crates/squid-platform/src/permissions.rs @@ -1233,6 +1233,14 @@ mod windows { } } } + // The scanner already resolved a usable icon file (DisplayIcon, the + // uninstaller, or the executable) for installs whose raw registry + // value is missing or unparsable. + if let Some(source) = app.icon_source.as_deref() { + if let Some(icon) = exe_icon_png(&source.to_string_lossy(), 0) { + return Some(icon); + } + } let target = primary_executable(app)?; exe_icon_png(&target, 0) } diff --git a/crates/squid-platform/src/windows.rs b/crates/squid-platform/src/windows.rs index c3ba5d2..61eeb79 100644 --- a/crates/squid-platform/src/windows.rs +++ b/crates/squid-platform/src/windows.rs @@ -48,11 +48,22 @@ fn open_uninstall_hives() -> Vec<(RegKey, &'static str, &'static str)> { /// record whose product state is Unknown/Broken/Removed means the MSI /// package itself is gone — the record is an orphan no msiexec can honour. mod msi { + use std::path::PathBuf; + #[link(name = "msi")] extern "system" { fn MsiQueryProductStateW(product: *const u16) -> i32; + fn MsiGetProductInfoW( + product: *const u16, + property: *const u16, + value: *mut u16, + value_len: *mut u32, + ) -> u32; } + const ERROR_SUCCESS: u32 = 0; + const ERROR_MORE_DATA: u32 = 234; + // INSTALLSTATE: 0 Unknown, 1 Broken, 2 Advertised, 3 Removed, // 4 Installed, 5 Local, 6 Source, 7 Default. fn wide(text: &str) -> Vec { @@ -65,6 +76,42 @@ mod msi { let state = unsafe { MsiQueryProductStateW(wide(&normalized).as_ptr()) }; matches!(state, 0 | 1 | 3) } + + /// The install folder recorded by Windows Installer. Some packages omit + /// `InstallLocation` from the registry but still expose it here, which is + /// what keeps their row from showing 0 KB and gives the uninstall plan a + /// real target. + pub fn install_location(guid: &str) -> Option { + let product = wide(&guid.to_ascii_uppercase()); + let property = wide("InstallLocation"); + let mut buffer = vec![0u16; 260]; + let mut length = buffer.len() as u32; + let mut status = unsafe { + MsiGetProductInfoW( + product.as_ptr(), + property.as_ptr(), + buffer.as_mut_ptr(), + &mut length, + ) + }; + if status == ERROR_MORE_DATA { + buffer.resize(length as usize, 0); + status = unsafe { + MsiGetProductInfoW( + product.as_ptr(), + property.as_ptr(), + buffer.as_mut_ptr(), + &mut length, + ) + }; + } + if status != ERROR_SUCCESS || length == 0 { + return None; + } + let text = String::from_utf16_lossy(&buffer[..length as usize]); + let text = text.trim().trim_matches('"').trim(); + (!text.is_empty()).then(|| PathBuf::from(super::expand_env_vars(text))) + } } /// The product GUID inside an `MsiExec.exe /X{GUID}` style command. @@ -163,6 +210,161 @@ fn dword_value(key: &RegKey, name: &str) -> Option { key.get_value::(name).ok() } +/// `EstimatedSize` is documented as a DWORD in KB, but some installers write +/// it as a string. Read both; zero is treated as "not reported" so the caller +/// can measure the install folder instead. +fn estimated_size_kb(key: &RegKey) -> Option { + if let Ok(kb) = key.get_value::("EstimatedSize") { + if kb > 0 { + return Some(u64::from(kb)); + } + } + if let Ok(kb) = key.get_value::("EstimatedSize") { + if kb > 0 { + return Some(kb); + } + } + if let Ok(text) = key.get_value::("EstimatedSize") { + let digits: String = text.chars().filter(|c| c.is_ascii_digit()).collect(); + if let Ok(kb) = digits.parse::() { + if kb > 0 { + return Some(kb); + } + } + } + None +} + +/// Expand the `%VAR%` spellings installers commonly write into registry paths. +fn expand_env_vars(text: &str) -> String { + let mut out = String::with_capacity(text.len()); + let mut rest = text; + while let Some(start) = rest.find('%') { + out.push_str(&rest[..start]); + let after = &rest[start + 1..]; + let Some(end) = after.find('%') else { + out.push_str(&rest[start..]); + return out; + }; + let name = &after[..end]; + match std::env::var(name) { + Ok(value) => out.push_str(&value), + Err(_) => { + out.push('%'); + out.push_str(name); + out.push('%'); + } + } + rest = &after[end + 1..]; + } + out.push_str(rest); + out +} + +/// A directory that is specific enough to be an application's install root. +/// Never return a drive root, Program Files itself, or a Windows system folder: +/// those are shared by every app and must not become an uninstall target. +fn plausible_install_dir(path: &Path) -> Option { + if !path.is_absolute() || !path.is_dir() { + return None; + } + let lower = path + .to_string_lossy() + .trim_end_matches(['\\', '/']) + .to_lowercase(); + if lower.len() <= 3 { + return None; + } + for key in [ + "ProgramFiles", + "ProgramFiles(x86)", + "SystemRoot", + "LOCALAPPDATA", + "APPDATA", + "ProgramData", + ] { + let Ok(root) = std::env::var(key) else { + continue; + }; + let root = root.trim_end_matches(['\\', '/']).to_lowercase(); + if lower == root { + return None; + } + if key == "SystemRoot" + && (lower.starts_with(&format!("{root}\\system32")) + || lower.starts_with(&format!("{root}\\syswow64")) + || lower.starts_with(&format!("{root}\\installer"))) + { + return None; + } + } + Some(path.to_path_buf()) +} + +/// Whether the app's uninstall registry record still exists. +pub fn uninstall_record_exists(reg_key: &str) -> bool { + let Some((tag, name)) = reg_key.split_once('|') else { + return false; + }; + let path = format!(r"{UNINSTALL_SUBKEY}\{name}"); + match tag { + "HKCU" => RegKey::predef(HKEY_CURRENT_USER) + .open_subkey_with_flags(&path, KEY_READ) + .is_ok(), + "HKLM64" => RegKey::predef(HKEY_LOCAL_MACHINE) + .open_subkey_with_flags(&path, KEY_READ | KEY_WOW64_64KEY) + .is_ok(), + "HKLM32" => RegKey::predef(HKEY_LOCAL_MACHINE) + .open_subkey_with_flags(&path, KEY_READ | KEY_WOW64_32KEY) + .is_ok(), + _ => false, + } +} + +/// Run the uninstaller the app registered with Windows. MSI entries often use +/// `/I{GUID}` for "modify/install"; `/X` is the uninstall verb. Non-MSI +/// commands are passed to `cmd.exe` exactly as recorded so vendor-specific +/// flags survive. +fn run_uninstaller(app: &AppInfo) -> std::result::Result<(), String> { + let raw = app + .uninstall_string + .as_deref() + .map(str::trim) + .filter(|s| !s.is_empty()) + .ok_or_else(|| "应用没有提供卸载命令".to_string())?; + let mut command = if let Some(guid) = msi_guid(raw) { + let mut command = Command::new("msiexec.exe"); + command.args(["/x", guid, "/qb", "/norestart"]); + command + } else { + let mut command = Command::new("cmd.exe"); + command.args(["/C", raw]); + command + }; + let cwd = if app.path.is_dir() { + Some(app.path.clone()) + } else { + app.path.parent().map(Path::to_path_buf) + }; + if let Some(cwd) = cwd.filter(|path| path.is_dir()) { + command.current_dir(cwd); + } + use std::os::windows::process::CommandExt; + command.creation_flags(0x0800_0000); // no console flash + let status = command + .status() + .map_err(|error| format!("无法启动卸载程序:{error}"))?; + // 3010/1641 are success-with-reboot-required codes from msiexec and + // installers built on it; treating them as failures made a completed + // uninstall look broken. + let code = status.code().unwrap_or(-1); + if status.success() || matches!(code, 3010 | 1641) { + Ok(()) + } else { + Err(format!("卸载程序退出码 {code}")) + } +} + /// The registry's `ProductName` freezes at "Windows 10 …" on every machine /// upgraded from 10 (Microsoft documents it as unreliable); Windows 11 keeps /// reporting API version 10.0 too. The build number is the real signal: @@ -245,7 +447,8 @@ fn days_since_epoch(y: i32, m: u32, d: u32) -> Option { /// Strip surrounding quotes and `cmd /c` wrappers from an uninstall string. fn uninstall_program(uninstall_string: &str) -> Option { - let s = uninstall_string.trim(); + let expanded = expand_env_vars(uninstall_string.trim()); + let s = expanded.as_str(); let path_part = if s.starts_with('"') { s.strip_prefix('"')?.split('"').next()? } else { @@ -254,14 +457,14 @@ fn uninstall_program(uninstall_string: &str) -> Option { s.split_whitespace().next()? }; let candidate = PathBuf::from(path_part); - candidate.exists().then_some(candidate) + (candidate.is_absolute() && candidate.exists()).then_some(candidate) } /// `DisplayIcon` is a path with an optional icon index, usually quoted: /// `"C:\Program Files\App\app.exe",0`. The file manager accepts the path /// without the index and returns the application's default icon. fn display_icon_path(value: Option) -> Option { - let raw = value?.trim().to_string(); + let raw = expand_env_vars(value?.trim()); let unquoted = raw .strip_prefix('"') .and_then(|value| value.split('"').next()) @@ -387,59 +590,95 @@ impl Platform for Windows { ) { continue; } - let install_location = str_value(&key, "InstallLocation") - .map(|l| l.trim_matches('"').to_string()) - .map(PathBuf::from) - .filter(|p| p.is_dir()); + let display_icon = str_value(&key, "DisplayIcon"); let uninstall_string = str_value(&key, "UninstallString"); - let path = install_location + let guid = uninstall_string.as_deref().and_then(msi_guid); + let install_location = str_value(&key, "InstallLocation") + .map(|location| { + PathBuf::from(expand_env_vars(location.trim().trim_matches('"'))) + }) + .and_then(|path| plausible_install_dir(&path)); + let msi_location = guid + .and_then(msi::install_location) + .and_then(|path| plausible_install_dir(&path)); + let uninstaller = uninstall_string.as_deref().and_then(uninstall_program); + let icon_file = display_icon_path(display_icon.clone()); + let install_dir = install_location .clone() - .or_else(|| uninstall_string.as_deref().and_then(uninstall_program)) + .or(msi_location) + .or_else(|| { + icon_file + .as_ref() + .and_then(|path| path.parent()) + .and_then(plausible_install_dir) + }) + .or_else(|| { + uninstaller + .as_ref() + .and_then(|path| path.parent()) + .and_then(plausible_install_dir) + }); + // Prefer the install folder; fall back to the uninstaller or + // the icon binary so the plan always points at something the + // user recognises rather than an empty path. + let path = install_dir + .clone() + .or_else(|| uninstaller.clone()) + .or_else(|| icon_file.clone()) .unwrap_or_default(); - let running_app = install_location + let running_app = install_dir .as_ref() - .map(|loc| { - let loc = loc.to_string_lossy().to_lowercase(); - running.iter().any(|exe| exe.starts_with(&loc)) + .map(|location| { + let location = location.to_string_lossy().to_lowercase(); + running.iter().any(|exe| exe.starts_with(&location)) }) .unwrap_or(false); // 安装不完整 detection (MangoDisk's cross-check): the record // exists but the product cannot be found any more — the MSI // state says gone, or neither the install folder nor the // uninstaller binary is on disk. - let dead = match uninstall_string.as_deref().and_then(msi_guid) { + let uninstaller_gone = uninstaller + .as_ref() + .map(|exe| !exe.exists()) + .unwrap_or(true); + let dead = match guid { Some(guid) => msi::product_broken(guid), - None => { - let uninstaller_gone = uninstall_string - .as_deref() - .and_then(uninstall_program) - .map(|exe| !exe.exists()) - .unwrap_or(true); - install_location.is_none() && uninstaller_gone - } + None => !path.exists() && uninstaller_gone, }; // Size: Windows installers report EstimatedSize (KB) for // Add/Remove Programs — the same number Settings shows. // Absent that, measure the install folder when asked. - let size = match dword_value(&key, "EstimatedSize") { - Some(kb) => Bytes(u64::from(kb) * 1024), - None if size => install_location - .as_ref() - .map(|loc| { - squid_core::fs::measure(loc, squid_core::ItemKind::Path).allocated - }) - .unwrap_or_default(), - None => Bytes::ZERO, - }; + let size = estimated_size_kb(&key) + .map(|kb| Bytes(kb.saturating_mul(1024))) + .or_else(|| { + if !size { + return None; + } + let target = install_dir + .as_ref() + .or_else(|| path.is_file().then_some(&path))?; + let kind = if target.is_dir() { + squid_core::ItemKind::Path + } else { + squid_core::ItemKind::File + }; + Some(squid_core::fs::measure(target, kind).allocated) + }) + .unwrap_or_default(); let mut source = package_source(&path, source); if dead { source.push_str(" · 安装不完整"); } + let icon_source = icon_file + .clone() + .or_else(|| path.is_file().then(|| path.clone())); apps.push(AppInfo { name: display_name, bundle_id: None, path, - icon_source: display_icon_path(str_value(&key, "DisplayIcon")), + // `icon_source` is the lazy path used by the shared icon + // helper; a file path is enough there. + icon_source, version: str_value(&key, "DisplayVersion"), size, source, @@ -447,7 +686,7 @@ impl Platform for Windows { has_sibling_install: false, publisher: str_value(&key, "Publisher"), installed_ms: install_date_ms(str_value(&key, "InstallDate")), - display_icon: str_value(&key, "DisplayIcon"), + display_icon, uninstall_string, reg_key: Some(format!("{tag}|{name}")), dead, @@ -472,14 +711,53 @@ impl Platform for Windows { } fn prepare_uninstall(&self, app: &AppInfo) -> LifecycleReport { let mut report = LifecycleReport::default(); - report.warnings.push(format!( - "{} ships its own uninstaller; squid only removes leftover data on Windows", - app.name - )); + if app + .uninstall_string + .as_deref() + .is_some_and(|raw| !raw.trim().is_empty()) + { + match run_uninstaller(app) { + Ok(()) => { + report + .notes + .push(format!("已运行 {} 的系统卸载程序", app.name)); + } + Err(error) => report.warnings.push(format!( + "系统卸载程序未能完成:{error}。Squid 将继续清理已选中的残留。" + )), + } + return report; + } + report + .warnings + .push("该应用没有提供卸载命令,Squid 只会移除已选中的文件。".into()); report } - fn finish_uninstall(&self, _app: &AppInfo, _removed: &[PathBuf]) -> LifecycleReport { - LifecycleReport::default() + fn finish_uninstall(&self, app: &AppInfo, _removed: &[PathBuf]) -> LifecycleReport { + let mut report = LifecycleReport::default(); + let bundle_gone = app.path.as_os_str().is_empty() || !app.path.exists(); + if !bundle_gone { + return report; + } + if let Some(guid) = app.uninstall_string.as_deref().and_then(msi_guid) { + if !msi::product_broken(guid) { + report + .warnings + .push("系统卸载程序未完成,已保留卸载注册表记录".into()); + return report; + } + } + if let Some(reg_key) = app.reg_key.as_deref() { + if uninstall_record_exists(reg_key) { + match remove_uninstall_record(reg_key) { + Ok(()) => report.notes.push("已清除卸载后残留的注册表记录".into()), + Err(error) => report + .warnings + .push(format!("残留注册表记录未能清除:{error}")), + } + } + } + report } fn volumes(&self) -> Result> { let system_drive = std::env::var("SystemDrive").unwrap_or_else(|_| "C:".into()); diff --git a/docs/USAGE.md b/docs/USAGE.md index 4a63a57..9bc7c02 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -1,6 +1,6 @@ # Squid Usage Guide -For Squid 0.1.14. See [`README.en.md`](../README.en.md) for the project overview and [`CHANGELOG.md`](../CHANGELOG.md) for version history. +For Squid 0.1.15. See [`README.en.md`](../README.en.md) for the project overview and [`CHANGELOG.md`](../CHANGELOG.md) for version history. ## 1. Download and install @@ -9,12 +9,12 @@ Desktop installers are published on the origin repository's `releases` branch an - Release directory: - Update manifest: -Current version 0.1.14: +Current version 0.1.15: | Platform | Installer | | --- | --- | -| macOS 12+ | [`Squid-0.1.14-macOS-universal.dmg`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-0.1.14-macOS-universal.dmg) | -| Windows 10/11 x64 | [`Squid-Setup-0.1.14-win-x64.exe`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-Setup-0.1.14-win-x64.exe) | +| macOS 12+ | [`Squid-0.1.15-macOS-universal.dmg`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-0.1.15-macOS-universal.dmg) | +| Windows 10/11 x64 | [`Squid-Setup-0.1.15-win-x64.exe`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-Setup-0.1.15-win-x64.exe) | Both installers are unsigned builds. Verify their exact size and SHA256 against `SHA256SUMS.txt` in the release directory. diff --git a/docs/USAGE.zh-CN.md b/docs/USAGE.zh-CN.md index 6d82d04..c89f5db 100644 --- a/docs/USAGE.zh-CN.md +++ b/docs/USAGE.zh-CN.md @@ -1,6 +1,6 @@ # Squid 使用帮助 -适用于 Squid 0.1.14。项目说明见 [`README.zh-CN.md`](../README.zh-CN.md),版本历史见 [`CHANGELOG.md`](../CHANGELOG.md)。 +适用于 Squid 0.1.15。项目说明见 [`README.zh-CN.md`](../README.zh-CN.md),版本历史见 [`CHANGELOG.md`](../CHANGELOG.md)。 ## 1. 下载与安装 @@ -9,12 +9,12 @@ Squid 的桌面安装包发布在 origin 仓库的 `releases` 分支,并同步 - 发布目录: - 更新清单: -当前版本 0.1.14: +当前版本 0.1.15: | 平台 | 安装包 | | --- | --- | -| macOS 12+ | [`Squid-0.1.14-macOS-universal.dmg`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-0.1.14-macOS-universal.dmg) | -| Windows 10/11 x64 | [`Squid-Setup-0.1.14-win-x64.exe`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-Setup-0.1.14-win-x64.exe) | +| macOS 12+ | [`Squid-0.1.15-macOS-universal.dmg`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-0.1.15-macOS-universal.dmg) | +| Windows 10/11 x64 | [`Squid-Setup-0.1.15-win-x64.exe`](https://git.unissense.tech/mula/nex_squid/raw/branch/releases/Squid-Setup-0.1.15-win-x64.exe) | 两个安装包都是未签名构建。校验文件大小和 SHA256 的方法见发布目录中的 `SHA256SUMS.txt`。 diff --git a/package.json b/package.json index df4eeb6..1535e4e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "squid-desktop", "private": true, - "version": "0.1.14", + "version": "0.1.15", "type": "module", "author": "mula.liu", "license": "GPL-3.0-only", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 4062fc2..9f9b1b3 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -4764,7 +4764,7 @@ dependencies = [ [[package]] name = "squid-core" -version = "0.1.14" +version = "0.1.15" dependencies = [ "anyhow", "chrono", @@ -4783,7 +4783,7 @@ dependencies = [ [[package]] name = "squid-desktop" -version = "0.1.14" +version = "0.1.15" dependencies = [ "base64 0.22.1", "chrono", @@ -4810,7 +4810,7 @@ dependencies = [ [[package]] name = "squid-engine" -version = "0.1.14" +version = "0.1.15" dependencies = [ "anyhow", "chrono", @@ -4833,7 +4833,7 @@ dependencies = [ [[package]] name = "squid-guard" -version = "0.1.14" +version = "0.1.15" dependencies = [ "chrono", "hex", @@ -4849,7 +4849,7 @@ dependencies = [ [[package]] name = "squid-platform" -version = "0.1.14" +version = "0.1.15" dependencies = [ "dirs 6.0.0", "file_icon_provider", @@ -4869,7 +4869,7 @@ dependencies = [ [[package]] name = "squid-rules" -version = "0.1.14" +version = "0.1.15" dependencies = [ "globset", "serde", @@ -4881,7 +4881,7 @@ dependencies = [ [[package]] name = "squid-stats" -version = "0.1.14" +version = "0.1.15" dependencies = [ "chrono", "libc", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index fd826e2..169f5ed 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "squid-desktop" -version = "0.1.14" +version = "0.1.15" description = "Squid — a CleanMyMac-inspired cleaner, uninstaller and system monitor." authors = ["mula.liu"] edition = "2021" diff --git a/src-tauri/src/app.rs b/src-tauri/src/app.rs index 032ed53..cf79daa 100644 --- a/src-tauri/src/app.rs +++ b/src-tauri/src/app.rs @@ -1037,10 +1037,25 @@ pub async fn tweaks_restore_all() -> Result, String> { pub struct AppEntry { #[serde(flatten)] app: AppInfo, - /// `data:image/png;base64,…` of the app's icon (Windows only). + /// `data:image/png;base64,…` of the app's icon. icon: Option, } +fn app_icon_png(entry: &AppInfo) -> Option> { + #[cfg(windows)] + { + squid_platform::permissions::app_icon(entry) + } + #[cfg(not(windows))] + { + squid_platform::apps::icon_png(entry, 64) + } +} + +fn app_icon_data_url(entry: &AppInfo) -> Option { + app_icon_png(entry).map(|png| format!("data:image/png;base64,{}", STANDARD.encode(png))) +} + #[derive(Clone, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct AppsView { @@ -1066,12 +1081,7 @@ pub async fn apps_scan(app: AppHandle, job_id: String) -> Result Result, let Some(chosen) = chosen else { return Ok(None); }; - let png = - tauri::async_runtime::spawn_blocking(move || squid_platform::apps::icon_png(&chosen, 64)) - .await - .map_err(|error| format!("Could not read the application icon: {error}"))?; + let png = tauri::async_runtime::spawn_blocking(move || app_icon_png(&chosen)) + .await + .map_err(|error| format!("Could not read the application icon: {error}"))?; let icon = png.map(|bytes| format!("data:image/png;base64,{}", STANDARD.encode(bytes))); AppState::lock(&app.state::().app_icons)?.insert(app_key, icon.clone()); Ok(icon) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 7490069..a2712e5 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": "Squid", - "version": "0.1.14", + "version": "0.1.15", "identifier": "app.nex.squid", "mainBinaryName": "squid-desktop", "build": { diff --git a/src/hooks/useAppsWorkspace.ts b/src/hooks/useAppsWorkspace.ts index 39834f7..5d9ca52 100644 --- a/src/hooks/useAppsWorkspace.ts +++ b/src/hooks/useAppsWorkspace.ts @@ -1,12 +1,13 @@ import { useCallback, useMemo, useState } from "react"; import { api, subscribeJobProgress } from "../lib/api"; import { isCancelled, messageFrom } from "../lib/format"; -import type { - AppInfo, - DeleteMode, - DeleteResult, - JobProgress, - PlanResult, +import { + appKey, + type AppInfo, + type DeleteMode, + type DeleteResult, + type JobProgress, + type PlanResult, } from "../types"; function jobId(): string { @@ -27,7 +28,7 @@ export interface AppsWorkspace { planSelected: Set; summary: DeleteResult | null; planSelectedTotal: number; - scan: () => Promise; + scan: (options?: { keepSummary?: boolean }) => Promise; chooseApp: (app: AppInfo | null) => void; buildPlan: (app: AppInfo) => Promise; togglePlanItem: (index: number) => void; @@ -54,13 +55,13 @@ export function useAppsWorkspace(): AppsWorkspace { const [summary, setSummary] = useState(null); const [activeJob, setActiveJob] = useState(null); - const scan = useCallback(async () => { - if (scanning || deleting) return; + const scan = useCallback(async (options?: { keepSummary?: boolean }) => { + if (scanning) return; const id = jobId(); setActiveJob(id); setScanning(true); setError(null); - setSummary(null); + if (!options?.keepSummary) setSummary(null); const stop = await subscribeJobProgress(id, setProgress); try { const result = await api.appsScan(id); @@ -75,7 +76,7 @@ export function useAppsWorkspace(): AppsWorkspace { setProgress(null); setActiveJob(null); } - }, [deleting, scanning]); + }, [scanning]); const chooseApp = useCallback((app: AppInfo | null) => { setSelectedApp(app); @@ -94,7 +95,7 @@ export function useAppsWorkspace(): AppsWorkspace { setError(null); const stop = await subscribeJobProgress(id, setProgress); try { - const next = await api.appPlan(id, app.bundle_id || app.path); + const next = await api.appPlan(id, appKey(app)); setPlan(next); setPlanSelected( new Set( @@ -152,31 +153,34 @@ export function useAppsWorkspace(): AppsWorkspace { setDeleting(true); setError(null); const stop = await subscribeJobProgress(id, setProgress); + let result: DeleteResult | null = null; try { - const result = await api.appUninstall(id, plan.planId, [...planSelected], mode); + result = await api.appUninstall(id, plan.planId, [...planSelected], mode); setSummary(result); setApps((current) => current.filter( - (app) => - (app.bundle_id || app.path) !== - (plan.app.bundle_id || plan.app.path), + (app) => appKey(app) !== appKey(plan.app), ), ); setPlan(null); setPlanSelected(new Set()); setSelectedApp(null); - return result; } catch (reason) { if (!isCancelled(reason)) setError(messageFrom(reason)); - return null; } finally { stop(); setDeleting(false); setProgress(null); setActiveJob(null); } + if (result) { + // The uninstaller and registry cleanup can leave the inventory stale; + // refresh it automatically while the result summary stays visible. + await scan({ keepSummary: true }); + } + return result; }, - [deleting, plan, planSelected], + [deleting, plan, planSelected, scan], ); const cancel = useCallback(async () => { diff --git a/src/pages/ApplicationsPage.tsx b/src/pages/ApplicationsPage.tsx index a23300c..d9c09a3 100644 --- a/src/pages/ApplicationsPage.tsx +++ b/src/pages/ApplicationsPage.tsx @@ -14,7 +14,7 @@ import { useMemo, useState } from "react"; import { useI18n } from "../i18n"; import { api } from "../lib/api"; import { formatBytes, formatCount, messageFrom, shortPath } from "../lib/format"; -import type { AppInfo, DeleteMode } from "../types"; +import { appKey, type AppInfo, type DeleteMode } from "../types"; import type { AppsWorkspace } from "../hooks/useAppsWorkspace"; import { Badge, @@ -140,8 +140,8 @@ export function ApplicationsPage({ const planIcon = useMemo(() => { const planApp = workspace.plan?.app; if (!planApp) return null; - const key = planApp.bundle_id || planApp.path; - return workspace.apps.find((a) => (a.bundle_id || a.path) === key)?.icon ?? null; + const key = appKey(planApp); + return workspace.apps.find((a) => appKey(a) === key)?.icon ?? null; }, [workspace.plan, workspace.apps]); const uninstall = async () => { @@ -182,14 +182,16 @@ export function ApplicationsPage({ eyebrow={t("Applications", "应用程序")} title={t("Uninstall completely", "卸载,干净彻底")} actions={ - + workspace.scanned ? ( + + ) : undefined } /> @@ -241,11 +243,12 @@ export function ApplicationsPage({
{apps.map((app) => ( void workspace.buildPlan(app)} /> diff --git a/src/types.ts b/src/types.ts index a990651..17df79b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -172,6 +172,10 @@ export interface AppInfo { icon?: string | null; } +export function appKey(app: Pick): string { + return app.bundle_id || app.reg_key || app.path; +} + export interface AppsResult { apps: AppInfo[]; total: number;