Fix uninstall home path normalization and cleanup diagnostics
This commit is contained in:
1 parent
a5d109cb0d
commit
9220db6c97
9 files changed
+107
-11
No files matched your search
@@ -54,8 +54,8 @@
|
||||
en: 7200a35dbed997c3
|
||||
zh: 511d6961530757f1
|
||||
/deepseek-harness-desktop/windows-installer-interface:
|
||||
en: 538f0a8158d3c61e
|
||||
zh: 0a4a1a37f8d511cd
|
||||
en: f816b98b0fde9d08
|
||||
zh: b69facb3b5fbe828
|
||||
/deepseek-harness-desktop/updates:
|
||||
en: 8b0b9efeb83727ef
|
||||
zh: 5ee95de48ceab392
|
||||
|
||||
@@ -267,7 +267,7 @@ Windows packaging compiles an x86 Win32/GDI+ helper with Visual C++ Build Tools
|
||||
|
||||
Run `pnpm --dir apps/desktop run test:installer` from the repository root on an interactive Windows x64 desktop to build and exercise a small native test payload through the production installer configuration. Each run uses a unique product identity and sequentially exercises English-only and Chinese-only installer variants, selecting test labels from the displayed welcome button. Both variants install into private directories and uninstall after testing; screenshots and results remain under `.desktop-build/installer-tests/`. The checks include restart-notice process cleanup, upgrades to registered paths with trailing separators and rejection of drive roots. The renderer receives caption colors from the NSIS theme; pixel checks print into an off-screen bitmap and also run with the progress child hidden. Native rendering checks cover light/dark palettes at 100% and 200% scale, the painted 100% completion state, caption-button hover/pressed colors and release/cancellation, minimize/restore geometry, and GDI resource release; repaint timings are diagnostics in `render-results.log`, not CI performance limits. Run the generated `ui/render-test.exe <brand.bmp> <dpi> <light|dark> <hover-argb> <pressed-argb> [interactive-title]` with a title to inspect the real progress page without installing a payload. The optional `--signed` flag uses the [Windows EV configuration](windows-signing/README.md#signing-configuration) to sign test executables and the helper before embedding them; it does not enable an update feed.
|
||||
|
||||
The Windows uninstaller removes the Electron user-data directory (browser storage and caches under `%APPDATA%`, nested under the package scope), the `%APPDATA%` product directory, and the updater download cache under `%LOCALAPPDATA%` together with the application, then removes ordinary empty scope directories below `%APPDATA%`. The Harness home (`~/.dsh` or `DSH_HOME`: sessions, settings, credentials, plugins) is never touched, and a `DSH_HOME` published as a Windows environment variable additionally protects any target overlapping it. Silent uninstalls remove the same data; an uninstaller started with `--updated` or `/KEEP_APP_DATA`, as electron-builder does for in-place updates and for replacing an older installation from another directory, retains it. Removal runs through the native helper, which refuses protected Windows folders and paths overlapping the installation or the home, requires a fixed local drive, leaves a linked root or ancestor in place, unlinks reparse points without entering their targets, clears read-only attributes, and keeps deleting siblings after a locked file; auxiliary residue does not stop uninstallation and is included in the cleanup report. Installation records `InstallLocation` on the Windows uninstall entry as standard inventory metadata; on Windows 11, Uninstall in the Start menu context menu opens the installed-apps list for every Win32 application, and only MSIX packages uninstall directly from there. The uninstaller declares DPI awareness and uses Microsoft YaHei UI for Chinese. Manual and silent uninstall also remove the owned command PATH entry and its ownership values, and remove `dsh://` only when its command still names this installation. When command ownership is missing, an additional cleanup removes only PATH entries matching the CLI directory of this installation after confirming the installation directory is absent; existing directories and failed checks retain those entries with a cleanup report. Other command installations are preserved. `--updated` preserves these registrations; `/KEEP_APP_DATA` alone does not. Cross-directory replacement passes only `/KEEP_APP_DATA`, so the old command registration is removed; the command can be enabled again from the new installation. When the installation record points elsewhere, interactive uninstall asks for confirmation and silent uninstall stops. If the location is missing or another installation is registered, cleanup removes commands, protocol handlers, shortcuts and Windows uninstall entries that still point to the directory being removed. Shared user data and shell settings are retained. The main executable is removed first: failure retains the remaining files and uninstall entry, with retry and report-saving actions. Unverifiable directory scope stops before deletion; incomplete removal results stop subsequent cleanup. Registry or auxiliary-file failures allow uninstall to finish with a residual-items notice. Native dialogs measure approximately 40 Chinese characters with the current font and fall back to 240 DLU. Reports list failed or unverified paths, registry key/value names, operations and available error codes, without registry values or the complete PATH. Reports are retained under `%TEMP%/DeepSeek-Harness-uninstall-<pid>.txt` when writable; interactive dialogs also offer Save cleanup report, and a failed save allows another location. This behavior is Windows-only.
|
||||
The Windows uninstaller removes the Electron user-data directory (browser storage and caches under `%APPDATA%`, nested under the package scope), the `%APPDATA%` product directory, and the updater download cache under `%LOCALAPPDATA%` together with the application, then removes ordinary empty scope directories below `%APPDATA%`. The Harness home (`~/.dsh` or `DSH_HOME`: sessions, settings, credentials, plugins) is never touched, and a `DSH_HOME` published as a Windows environment variable additionally protects any target overlapping it. Home paths accept `~/`, `~\` and forward slashes; relative paths remain unverifiable because the application working directory is unavailable to the uninstaller. A cancelled or silent refusal for a different registered installation records the reason and both directories in the cleanup report. Silent uninstalls remove the same data; an uninstaller started with `--updated` or `/KEEP_APP_DATA`, as electron-builder does for in-place updates and for replacing an older installation from another directory, retains it. Removal runs through the native helper, which refuses protected Windows folders and paths overlapping the installation or the home, requires a fixed local drive, leaves a linked root or ancestor in place, unlinks reparse points without entering their targets, clears read-only attributes, and keeps deleting siblings after a locked file; auxiliary residue does not stop uninstallation and is included in the cleanup report. Installation records `InstallLocation` on the Windows uninstall entry as standard inventory metadata; on Windows 11, Uninstall in the Start menu context menu opens the installed-apps list for every Win32 application, and only MSIX packages uninstall directly from there. The uninstaller declares DPI awareness and uses Microsoft YaHei UI for Chinese. Manual and silent uninstall also remove the owned command PATH entry and its ownership values, and remove `dsh://` only when its command still names this installation. When command ownership is missing, an additional cleanup removes only PATH entries matching the CLI directory of this installation after confirming the installation directory is absent; existing directories and failed checks retain those entries with a cleanup report. Other command installations are preserved. `--updated` preserves these registrations; `/KEEP_APP_DATA` alone does not. Cross-directory replacement passes only `/KEEP_APP_DATA`, so the old command registration is removed; the command can be enabled again from the new installation. When the installation record points elsewhere, interactive uninstall asks for confirmation and silent uninstall stops. If the location is missing or another installation is registered, cleanup removes commands, protocol handlers, shortcuts and Windows uninstall entries that still point to the directory being removed. Shared user data and shell settings are retained. The main executable is removed first: failure retains the remaining files and uninstall entry, with retry and report-saving actions. Unverifiable directory scope stops before deletion; incomplete removal results stop subsequent cleanup. Registry or auxiliary-file failures allow uninstall to finish with a residual-items notice. Native dialogs measure approximately 40 Chinese characters with the current font and fall back to 240 DLU. Reports list failed or unverified paths, registry key/value names, operations and available error codes, without registry values or the complete PATH. Reports are retained under `%TEMP%/DeepSeek-Harness-uninstall-<pid>.txt` when writable; interactive dialogs also offer Save cleanup report, and a failed save allows another location. This behavior is Windows-only.
|
||||
|
||||
Use `node apps/desktop/scripts/test-windows-installer.mjs --uninstall-only --compile-only` to compile isolated fixtures for all eight installer languages with a per-run scoped package name. Omit `--compile-only` to run the native remover regression and the interactive, silent, `--updated`, `/KEEP_APP_DATA`, `DSH_HOME`-inside-Electron-data, busy-executable retry, registration-error continuation and installation-takeover checks against seeded data. Compilation does not establish installed-uninstall behavior.
|
||||
|
||||
|
||||
@@ -267,7 +267,7 @@ Windows 打包使用 Visual C++ Build Tools 和 Windows SDK 编译 x86 Win32/GDI
|
||||
|
||||
在有交互式桌面的 Windows x64 上,从仓库根目录运行 `pnpm --dir apps/desktop run test:installer`,可将小型原生测试载荷接入正式安装配置并执行验证。每次运行使用独立产品身份,依次验证仅英文和仅中文的安装器变体,并根据实际显示的欢迎页按钮选择测试文案。两个变体均安装到私有目录并在测试后卸载;截图和结果保留在 `.desktop-build/installer-tests/` 下。检查包含重启提示窗的进程回收、末尾带分隔符的已登记路径升级,以及磁盘根目录拒绝。绘制器接收 NSIS 主题传入的标题栏颜色;像素检查绘制到离屏位图,并在隐藏进度子窗口时验证。原生绘制检查覆盖 100% 和 200% 缩放下的浅色/深色配色、绘制到 100% 的完成状态、标题栏按钮的悬停/按下颜色和松开触发与取消、最小化恢复后的窗口位置和尺寸,以及 GDI 资源释放;`render-results.log` 中的重绘耗时仅供诊断,不作为 CI 性能阈值。运行生成的 `ui/render-test.exe <brand.bmp> <dpi> <light|dark> <hover-argb> <pressed-argb> [interactive-title]` 并指定标题,可在不安装载荷的情况下查看真实进度页。可选的 `--signed` 标志使用[Windows EV 配置](windows-signing/README.zh.md#signing-configuration),在嵌入前对测试程序和辅助库签名;它不会启用更新源。
|
||||
|
||||
Windows 卸载程序会随应用一起删除 Electron 用户数据目录(`%APPDATA%` 下按包作用域嵌套的浏览器存储与缓存)、`%APPDATA%` 下的产品目录,以及 `%LOCALAPPDATA%` 下的更新下载缓存,随后移除 `%APPDATA%` 之下普通且已空的作用域目录。Harness 主目录(`~/.dsh` 或 `DSH_HOME`:会话、设置、凭据、插件)不会被触碰;以 Windows 环境变量发布的 `DSH_HOME` 还会保护所有与其重叠的目标。静默卸载删除相同的数据;以 `--updated` 或 `/KEEP_APP_DATA` 启动的卸载程序保留数据,electron-builder 在原地更新和从其他目录替换旧安装时正是这样启动它。删除通过原生辅助程序执行:它拒绝受保护的 Windows 目录以及与安装目录或主目录重叠的路径,要求固定的本地驱动器,链接的根目录或祖先目录原样保留,遇到重解析点只解除链接而不进入目标,清除只读属性,并在遇到被占用文件后继续删除其余兄弟项;辅助内容的残余不会中止卸载,并会记录到清理报告中。安装时在 Windows 卸载注册项上记录 `InstallLocation` 作为标准的清单元数据;在 Windows 11 上,开始菜单右键菜单中的“卸载”对所有 Win32 应用都会打开已安装应用列表,只有 MSIX 包能从那里直接卸载。卸载程序声明 DPI 感知,中文使用微软雅黑 UI。手动和静默卸载还会移除属于该安装的命令 PATH 条目和所有权值,仅当 `dsh://` 的命令仍指向该安装时才移除协议注册。命令所有权缺失时,额外清理只移除匹配本安装 CLI 目录的 PATH 条目,并先确认安装目录已不存在;目录仍存在或检查失败时保留条目并生成清理报告。其他命令安装保持不变。`--updated` 保留这些注册;单独使用 `/KEEP_APP_DATA` 不会保留。跨目录替换只传入 `/KEEP_APP_DATA`,因此移除旧命令注册;用户可从新安装中重新启用命令。安装登记指向其他目录时,交互式卸载请求确认,静默卸载停止。安装地址缺失或指向其他位置时,卸载会清理仍指向本目录的命令、协议、快捷方式和 Windows 卸载入口,保留共享用户数据和系统外壳设置。卸载先删除主程序:失败时保留其余文件和卸载入口,提供重试和保存报告。无法确认目录范围时,在删除前停止;删除结果不完整时,停止后续清理。注册表或辅助文件清理失败不阻止卸载完成,但会提示有内容未能清理。原生弹窗按当前字体测量约 40 个汉字的宽度,失败回退到 240 DLU。报告包含失败或结果未确认的路径、注册表键及值名称、操作和可用错误码,不包含注册表值内容或完整 PATH。可写时报告保留在 `%TEMP%/DeepSeek-Harness-uninstall-<pid>.txt`;交互弹窗另提供“保存清理报告”,保存失败时可以重新选择位置。此行为仅适用于 Windows。
|
||||
Windows 卸载程序会随应用一起删除 Electron 用户数据目录(`%APPDATA%` 下按包作用域嵌套的浏览器存储与缓存)、`%APPDATA%` 下的产品目录,以及 `%LOCALAPPDATA%` 下的更新下载缓存,随后移除 `%APPDATA%` 之下普通且已空的作用域目录。Harness 主目录(`~/.dsh` 或 `DSH_HOME`:会话、设置、凭据、插件)不会被触碰;以 Windows 环境变量发布的 `DSH_HOME` 还会保护所有与其重叠的目标。主目录路径支持 `~/`、`~\` 和正斜杠;卸载器无法获取应用的工作目录,因此仍无法确认相对路径。因登记指向其他安装而取消或静默拒绝卸载时,清理报告会记录原因和两个目录。静默卸载删除相同的数据;以 `--updated` 或 `/KEEP_APP_DATA` 启动的卸载程序保留数据,electron-builder 在原地更新和从其他目录替换旧安装时正是这样启动它。删除通过原生辅助程序执行:它拒绝受保护的 Windows 目录以及与安装目录或主目录重叠的路径,要求固定的本地驱动器,链接的根目录或祖先目录原样保留,遇到重解析点只解除链接而不进入目标,清除只读属性,并在遇到被占用文件后继续删除其余兄弟项;辅助内容的残余不会中止卸载,并会记录到清理报告中。安装时在 Windows 卸载注册项上记录 `InstallLocation` 作为标准的清单元数据;在 Windows 11 上,开始菜单右键菜单中的“卸载”对所有 Win32 应用都会打开已安装应用列表,只有 MSIX 包能从那里直接卸载。卸载程序声明 DPI 感知,中文使用微软雅黑 UI。手动和静默卸载还会移除属于该安装的命令 PATH 条目和所有权值,仅当 `dsh://` 的命令仍指向该安装时才移除协议注册。命令所有权缺失时,额外清理只移除匹配本安装 CLI 目录的 PATH 条目,并先确认安装目录已不存在;目录仍存在或检查失败时保留条目并生成清理报告。其他命令安装保持不变。`--updated` 保留这些注册;单独使用 `/KEEP_APP_DATA` 不会保留。跨目录替换只传入 `/KEEP_APP_DATA`,因此移除旧命令注册;用户可从新安装中重新启用命令。安装登记指向其他目录时,交互式卸载请求确认,静默卸载停止。安装地址缺失或指向其他位置时,卸载会清理仍指向本目录的命令、协议、快捷方式和 Windows 卸载入口,保留共享用户数据和系统外壳设置。卸载先删除主程序:失败时保留其余文件和卸载入口,提供重试和保存报告。无法确认目录范围时,在删除前停止;删除结果不完整时,停止后续清理。注册表或辅助文件清理失败不阻止卸载完成,但会提示有内容未能清理。原生弹窗按当前字体测量约 40 个汉字的宽度,失败回退到 240 DLU。报告包含失败或结果未确认的路径、注册表键及值名称、操作和可用错误码,不包含注册表值内容或完整 PATH。可写时报告保留在 `%TEMP%/DeepSeek-Harness-uninstall-<pid>.txt`;交互弹窗另提供“保存清理报告”,保存失败时可以重新选择位置。此行为仅适用于 Windows。
|
||||
|
||||
使用 `node apps/desktop/scripts/test-windows-installer.mjs --uninstall-only --compile-only` 以每次运行唯一的带作用域包名编译八种安装语言的独立夹具。省略 `--compile-only` 可对预置数据运行原生删除器回归,以及交互、静默、`--updated`、`/KEEP_APP_DATA` 、`DSH_HOME` 位于 Electron 数据内、主程序占用后重试、注册表失败后继续卸载及另一安装接管的检查。编译本身不能证明已安装卸载行为。
|
||||
|
||||
|
||||
@@ -45,6 +45,29 @@ inline bool Normalize(LPCWSTR input, std::wstring& result) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// DSH_HOME accepts Node's tilde and separator spellings; relative roots remain
|
||||
// unverifiable because the application's working directory is not available here.
|
||||
inline bool NormalizeHome(LPCWSTR input, std::wstring& result) {
|
||||
std::wstring value = input ? input : L"";
|
||||
if (value.find_first_not_of(L" \t\r\n") == std::wstring::npos) value = L"~/.dsh";
|
||||
if (value == L"~" || value.compare(0, 2, L"~/") == 0 || value.compare(0, 2, L"~\\") == 0) {
|
||||
WCHAR buffer[32768];
|
||||
DWORD length = GetEnvironmentVariableW(L"USERPROFILE", buffer, ARRAYSIZE(buffer));
|
||||
std::wstring profile;
|
||||
if (length && length < ARRAYSIZE(buffer)) profile.assign(buffer, length);
|
||||
else {
|
||||
if (length) return false;
|
||||
PWSTR folder = nullptr;
|
||||
if (FAILED(SHGetKnownFolderPath(FOLDERID_Profile, KF_FLAG_DONT_VERIFY, nullptr, &folder))) return false;
|
||||
profile = folder;
|
||||
CoTaskMemFree(folder);
|
||||
}
|
||||
value = profile + (value.size() > 1 ? L"\\" + value.substr(2) : L"");
|
||||
}
|
||||
for (auto& character : value) if (character == L'/') character = L'\\';
|
||||
return Normalize(value.c_str(), result);
|
||||
}
|
||||
|
||||
// Listing access takes part in share checks, so the open handle refuses the DELETE access a rename or removal needs.
|
||||
inline DWORD Pin(const std::wstring& path, Handles& handles) {
|
||||
HANDLE handle = CreateFileW((L"\\\\?\\" + path).c_str(), FILE_LIST_DIRECTORY | FILE_READ_ATTRIBUTES,
|
||||
@@ -109,7 +132,7 @@ inline DWORD Remove(LPCWSTR input, LPCWSTR installation, LPCWSTR protectedRoot,
|
||||
if (protectedRoot && *protectedRoot) {
|
||||
std::wstring home;
|
||||
// An unusable protected root cannot establish separation from retained data.
|
||||
if (!Normalize(protectedRoot, home)) return ERROR_INVALID_NAME;
|
||||
if (!NormalizeHome(protectedRoot, home)) return ERROR_INVALID_NAME;
|
||||
if (Contains(path, home) || Contains(home, path)) return ERROR_ACCESS_DENIED;
|
||||
}
|
||||
struct ComScope {
|
||||
|
||||
@@ -174,7 +174,7 @@ inline DWORD Prepare(Session& session, LPCWSTR directory, LPCWSTR protectedRoot)
|
||||
if (!uninstall_data::Normalize(directory, path)) return ERROR_INVALID_NAME;
|
||||
if (protectedRoot && *protectedRoot) {
|
||||
std::wstring home;
|
||||
if (!uninstall_data::Normalize(protectedRoot, home)) return ERROR_INVALID_NAME;
|
||||
if (!uninstall_data::NormalizeHome(protectedRoot, home)) return ERROR_INVALID_NAME;
|
||||
if (uninstall_data::Contains(path, home) || uninstall_data::Contains(home, path)) return ERROR_ACCESS_DENIED;
|
||||
}
|
||||
const KNOWNFOLDERID* folders[] = {&FOLDERID_Profile, &FOLDERID_RoamingAppData, &FOLDERID_LocalAppData,
|
||||
@@ -267,10 +267,14 @@ extern "C" __declspec(dllexport) int __cdecl UninstallShow(uninstall_report::Ses
|
||||
}
|
||||
extern "C" __declspec(dllexport) int __cdecl UninstallFinish(uninstall_report::Session* session, LPCWSTR directory, LPCWSTR uninstaller) {
|
||||
const std::wstring file = std::wstring(directory) + L"\\" + uninstaller;
|
||||
const DWORD attributes = GetFileAttributesW(file.c_str());
|
||||
const DWORD attributes = GetFileAttributesW((L"\\\\?\\" + file).c_str());
|
||||
if (attributes != INVALID_FILE_ATTRIBUTES) {
|
||||
const DWORD error = uninstall_data::Unlink(L"\\\\?\\" + file, attributes);
|
||||
if (error) uninstall_report::Add(*session, L"Remove uninstaller", file.c_str(), error);
|
||||
} else {
|
||||
const DWORD error = GetLastError();
|
||||
if (error != ERROR_FILE_NOT_FOUND && error != ERROR_PATH_NOT_FOUND)
|
||||
uninstall_report::Add(*session, L"Inspect uninstaller", file.c_str(), error);
|
||||
}
|
||||
for (HANDLE handle : session->pinned.values) CloseHandle(handle);
|
||||
session->pinned.values.clear();
|
||||
|
||||
@@ -61,6 +61,8 @@ Function un.BeginCleanup
|
||||
StrCpy $UnHeading "$(INSTALLER_UNINSTALL_OWNER)"
|
||||
Call un.ShowCleanup
|
||||
${If} $UnResult != 1001
|
||||
System::Call '$PLUGINSDIR\window-frame.dll::UninstallNote(p $UnSession, w "Removal not confirmed; no deletion started. Registered installation: $UnRegistered. Uninstall directory: $INSTDIR.") ?c'
|
||||
System::Call '$PLUGINSDIR\window-frame.dll::UninstallPersist(p $UnSession) ?c'
|
||||
SetErrorLevel 2
|
||||
Quit
|
||||
${EndIf}
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
"upgrade",
|
||||
"replaced",
|
||||
"home-inside",
|
||||
"home-slash",
|
||||
"home-tilde",
|
||||
"home-slash-inside",
|
||||
"registration-error",
|
||||
"main-locked",
|
||||
"self-copy",
|
||||
|
||||
@@ -51,6 +51,9 @@ int wmain(int argc, wchar_t** argv) {
|
||||
assert(uninstall_data::Remove(cache.c_str(), installation.c_str(), data.c_str()) == ERROR_ACCESS_DENIED);
|
||||
assert(uninstall_data::Remove(data.c_str(), installation.c_str(), cache.c_str()) == ERROR_ACCESS_DENIED);
|
||||
assert(uninstall_data::Remove(cache.c_str(), installation.c_str(), L"relative\\home") == ERROR_INVALID_NAME);
|
||||
std::wstring slashHome = cache;
|
||||
for (auto& character : slashHome) if (character == L'\\') character = L'/';
|
||||
assert(uninstall_data::Remove(data.c_str(), installation.c_str(), slashHome.c_str()) == ERROR_ACCESS_DENIED);
|
||||
assert(Exists(cache + L"\\CURRENT"));
|
||||
|
||||
// A pinned directory cannot be renamed or replaced while the helper holds it.
|
||||
@@ -124,5 +127,39 @@ int wmain(int argc, wchar_t** argv) {
|
||||
assert(DeleteFileW((installation + L"\\aux.log").c_str()));
|
||||
assert(DeleteFileW(report.c_str()));
|
||||
assert(RemoveDirectoryW(installation.c_str()));
|
||||
|
||||
for (auto home : {L"C:/HarnessHome", L"~/.dsh", L"~\\.dsh", L" \t "}) {
|
||||
assert(CreateDirectoryW(installation.c_str(), nullptr));
|
||||
void* alternate = UninstallBegin(report.c_str());
|
||||
assert(alternate);
|
||||
assert(UninstallPrepare(alternate, installation.c_str(), home) == ERROR_SUCCESS);
|
||||
assert(UninstallFinish(alternate, installation.c_str(), L"uninstall.exe") == 0);
|
||||
assert(!Exists(installation));
|
||||
}
|
||||
assert(CreateDirectoryW(installation.c_str(), nullptr));
|
||||
void* protectedSession = UninstallBegin(report.c_str());
|
||||
std::wstring slashInstall = installation;
|
||||
for (auto& character : slashInstall) if (character == L'\\') character = L'/';
|
||||
assert(UninstallPrepare(protectedSession, installation.c_str(), slashInstall.c_str()) == ERROR_ACCESS_DENIED);
|
||||
assert(UninstallPrepare(protectedSession, installation.c_str(), L"relative/home") == ERROR_INVALID_NAME);
|
||||
assert(RemoveDirectoryW(installation.c_str()));
|
||||
|
||||
std::vector<std::wstring> longDirectories;
|
||||
std::wstring longDirectory = root;
|
||||
while (longDirectory.size() < 280) {
|
||||
longDirectory += L"\\" + std::wstring(60, L'x');
|
||||
assert(CreateDirectoryW((L"\\\\?\\" + longDirectory).c_str(), nullptr));
|
||||
longDirectories.push_back(longDirectory);
|
||||
}
|
||||
const std::wstring longUninstaller = L"\\\\?\\" + longDirectory + L"\\uninstall.exe";
|
||||
File(longUninstaller);
|
||||
void* longSession = UninstallBegin(report.c_str());
|
||||
assert(UninstallPrepare(longSession, longDirectory.c_str(), nullptr) == ERROR_SUCCESS);
|
||||
assert(UninstallFinish(longSession, longDirectory.c_str(), L"uninstall.exe") == 0);
|
||||
assert(!Exists(longUninstaller));
|
||||
assert(!Exists(L"\\\\?\\" + longDirectory));
|
||||
longDirectories.pop_back();
|
||||
for (auto it = longDirectories.rbegin(); it != longDirectories.rend(); ++it)
|
||||
assert(RemoveDirectoryW((L"\\\\?\\" + *it).c_str()));
|
||||
assert(RemoveDirectoryW(root.c_str()));
|
||||
}
|
||||
@@ -25,6 +25,7 @@ $ownerKey = "Software\DSHUninstallTests\$RegistryKey\CommandOwner"
|
||||
$protocolKey = "Software\Classes\dsh-test-$RegistryKey"
|
||||
$process = $null
|
||||
$held = $null
|
||||
$originalHome = [Environment]::GetEnvironmentVariable('DSH_HOME', 'Process')
|
||||
$strings = (Get-Content (Join-Path $PSScriptRoot "../installer/locales/$Language.json") -Encoding UTF8 -Raw | ConvertFrom-Json).strings
|
||||
function Wait-Text([string]$Text) {
|
||||
$timer = [Diagnostics.Stopwatch]::StartNew()
|
||||
@@ -114,7 +115,7 @@ try {
|
||||
try { $key.SetValue('', '"' + (Join-Path $integrationRoot ($ProductName + '.exe')) + '" "%1"') } finally { $key.Dispose() }
|
||||
$launchUninstaller = $uninstaller
|
||||
$arguments = '_?=' + $installPath
|
||||
if ($mode -in @('silent', 'missing-location', 'missing-location-short', 'missing-location-foreign', 'unowned', 'owned-retained', 'home-inside', 'registration-error', 'main-locked', 'auxiliary-locked', 'unsafe-root')) { $arguments = '/S ' + $arguments }
|
||||
if ($mode -in @('silent', 'missing-location', 'missing-location-short', 'missing-location-foreign', 'unowned', 'owned-retained', 'home-inside', 'home-slash', 'home-tilde', 'home-slash-inside', 'registration-error', 'main-locked', 'auxiliary-locked', 'unsafe-root')) { $arguments = '/S ' + $arguments }
|
||||
# electron-builder's installUtil.nsh runs an older uninstaller with exactly these flags when replacing it.
|
||||
if ($mode -eq 'upgrade') {
|
||||
Set-ItemProperty -LiteralPath ('HKCU:\Software\' + $RegistryKey) -Name InstallLocation -Value ($installPath + '\')
|
||||
@@ -125,6 +126,12 @@ try {
|
||||
$arguments = '/S /KEEP_APP_DATA'
|
||||
}
|
||||
if ($mode -eq 'home-inside') { $env:DSH_HOME = Join-Path $userDataPath 'home' } else { Remove-Item Env:DSH_HOME -ErrorAction SilentlyContinue }
|
||||
if ($mode -eq 'home-slash') { $env:DSH_HOME = $homePath.Replace('\', '/') }
|
||||
if ($mode -eq 'home-tilde') {
|
||||
if (-not $homePath.StartsWith($env:USERPROFILE + '\', [StringComparison]::OrdinalIgnoreCase)) { throw 'Tilde fixture must be inside USERPROFILE' }
|
||||
$env:DSH_HOME = '~/' + $homePath.Substring($env:USERPROFILE.Length + 1).Replace('\', '/')
|
||||
}
|
||||
if ($mode -eq 'home-slash-inside') { $env:DSH_HOME = (Join-Path $userDataPath 'home').Replace('\', '/') }
|
||||
if ($mode -in @('registration-error', 'save-report')) {
|
||||
$key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($environmentKey, $true)
|
||||
try { $key.SetValue('Path', 42, [Microsoft.Win32.RegistryValueKind]::DWord) } finally { $key.Dispose() }
|
||||
@@ -217,7 +224,7 @@ try {
|
||||
Wait-Exit
|
||||
$retained = $missingLocation -or $mode -in @('upgrade', 'replaced', 'self-copy')
|
||||
# A DSH_HOME inside the Electron directory protects that directory (and its scope) but not the other roots.
|
||||
$userDataRetained = $retained -or $mode -eq 'home-inside'
|
||||
$userDataRetained = $retained -or $mode -in @('home-inside', 'home-slash-inside')
|
||||
if ([IO.File]::ReadAllText((Join-Path $externalPath 'keep.txt')) -ne 'outside data root') { throw 'Cleanup followed a junction into a project' }
|
||||
if (-not (Test-Path (Join-Path $homePath 'session.txt'))) { throw "Harness home retention failed: $mode" }
|
||||
if ((Test-Path (Join-Path $productDataPath 'state.txt')) -ne $retained) { throw "Product data retention failed: $mode" }
|
||||
@@ -250,6 +257,7 @@ try {
|
||||
$relocationData = Join-Path $userDataPath 'relocation-state.txt'
|
||||
[IO.File]::WriteAllText($relocationData, 'retained during relocation')
|
||||
$newPath = Join-Path $OutputDirectory 'Replacement App'
|
||||
$env:DSH_HOME = $homePath.Replace('\', '/')
|
||||
$setup = Start-Process $Installer -ArgumentList ('/S /D=' + $newPath) -PassThru -WindowStyle Hidden
|
||||
try { if (-not $setup.WaitForExit(30000) -or $setup.ExitCode -ne 0) { throw 'Takeover B setup failed' } } finally { $setup.Dispose() }
|
||||
if ((Get-ItemProperty ('HKCU:\' + $ownerKey)).Directory) { throw 'Relocation retained old command owner' }
|
||||
@@ -289,7 +297,26 @@ try {
|
||||
Set-ItemProperty ('HKCU:\' + $ownerKey) Directory $oldCommand
|
||||
Set-ItemProperty ('HKCU:\' + $environmentKey) Path ($oldCommand + ';C:\Windows')
|
||||
$bUninstall = $entry.UninstallString
|
||||
Copy-Item -LiteralPath $newPath -Destination $installPath -Recurse
|
||||
New-Item -ItemType Directory -Force -Path $installPath | Out-Null
|
||||
Get-ChildItem -LiteralPath $newPath | Copy-Item -Destination $installPath -Recurse
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $installPath ($ProductName + '.exe')))) { throw 'Partial takeover fixture lacks the A executable' }
|
||||
$process = Start-Process $uninstaller -ArgumentList ('/S /currentuser _?=' + $installPath) -PassThru -WindowStyle Hidden
|
||||
if (-not $process.WaitForExit(30000) -or $process.ExitCode -ne 2) { throw 'Existing stale directory was not rejected' }
|
||||
$report = Get-Content (Join-Path $env:TEMP ('DeepSeek-Harness-uninstall-' + $process.Id + '.txt')) -Raw
|
||||
if (-not $report.Contains('Removal not confirmed') -or -not $report.Contains($newPath) -or -not $report.Contains($installPath)) { throw 'Silent rejection report lacks reason and both paths' }
|
||||
$process.Dispose(); $process = $null
|
||||
$process = Start-Process $uninstaller -ArgumentList ('/currentuser _?=' + $installPath) -PassThru
|
||||
$welcome = Wait-Text $copy.welcome
|
||||
$window = [InstallerCapture]::TopLevel($welcome)
|
||||
[InstallerCapture]::Click([InstallerCapture]::GetDlgItem($window, 1))
|
||||
$continue = Wait-Text $strings.INSTALLER_UNINSTALL_CONTINUE
|
||||
# TaskDialog common buttons are nested DirectUI controls; use TDM_CLICK_BUTTON with IDCANCEL.
|
||||
if (-not [InstallerCapture]::PostMessage([InstallerCapture]::TopLevel($continue), 0x466, [IntPtr]2, [IntPtr]::Zero)) { throw 'Could not cancel owner dialog' }
|
||||
if (-not $process.WaitForExit(30000) -or $process.ExitCode -ne 2) { throw 'Owner dialog cancellation did not stop uninstall' }
|
||||
$report = Get-Content (Join-Path $env:TEMP ('DeepSeek-Harness-uninstall-' + $process.Id + '.txt')) -Raw
|
||||
if (-not $report.Contains('Removal not confirmed') -or -not $report.Contains($newPath) -or -not $report.Contains($installPath)) { throw 'Cancellation report lacks reason and both paths' }
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $installPath ($ProductName + '.exe')))) { throw 'Cancellation deleted A' }
|
||||
$process.Dispose(); $process = $null
|
||||
$process = Start-Process $uninstaller -ArgumentList ('/currentuser _?=' + $installPath) -PassThru
|
||||
$welcome = Wait-Text $copy.welcome
|
||||
$window = [InstallerCapture]::TopLevel($welcome)
|
||||
@@ -327,7 +354,7 @@ try {
|
||||
} finally {
|
||||
if ($held) { $held.Dispose() }
|
||||
foreach ($key in @("Software\DSHUninstallTests\$RegistryKey", $protocolKey)) { [Microsoft.Win32.Registry]::CurrentUser.DeleteSubKeyTree($key, $false) }
|
||||
Remove-Item Env:DSH_HOME -ErrorAction SilentlyContinue
|
||||
[Environment]::SetEnvironmentVariable('DSH_HOME', $originalHome, 'Process')
|
||||
if ($process) { if (-not $process.HasExited) { $process.Kill(); $process.WaitForExit() }; $process.Dispose() }
|
||||
# Only unique test identities below known application-data parents are removed.
|
||||
foreach ($pair in @(@($productDataPath, $roaming), @($scopePath, $roaming), @($cachePath, $local))) {
|
||||
|
||||
Reference in new issue
Block a user