On top of #2279's commit (041e99063), which reads the folder DeepSeek
Harness Desktop's installer registers under HKCU\Software\<guid>.
cjyrainbow installed it to D:\tools\dsh; magpie 0.1.1248 showed
"未找到 CLI" with no switch. Since d0fcb8bcd (#2177) an agent whose folder
(~/.dsh) has no CLI and no app magpie can find is shown as gone, so a
desktop app outside %LOCALAPPDATA%\Programs, listed before by its ~/.dsh
alone, lost its row's settings ("it used to be recognised").
electron-builder's installer writes Software\<guid> InstallLocation and
an Uninstall\<guid> entry under HKCU for a per-user install and under HKLM
for an all-users one. #2279 read HKCU only. registeredIn now reads both
hives (64-bit view, then 32-bit), and when InstallLocation is missing the
Uninstall entry's InstallLocation, else the folder of its DisplayIcon
("…\DeepSeek Harness.exe,0") or UninstallString. The exe must still be in
that folder (registered(), from #2279).
Test: TestDshDesktopRegisteredAnyHive (per user, all users, the Uninstall
entry's folder, icon and uninstaller; an icon that is no exe finds nothing).
Run in this worktree:
- gofmt -l internal/agent: clean
- go vet -tags nogui ./internal/agent/ (darwin), GOOS=linux -tags nogui,
GOOS=windows: clean
- go test: NOT run. The disk had 300-750 MB free (the session rule is
1 GB before any go test), so the new test and the package were not run
and nothing was broken by hand yet. Run before landing:
go test -tags nogui -p 1 -run 'TestDshDesktop' ./internal/agent/
Not tried: no real Windows install; the registry reader was not run on
the Windows box. The reporter's hive (HKCU or HKLM) is not known.
Full suite: SUITE_LINE
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
//go:build windows
|
|
|
|
package agent
|
|
|
|
import "golang.org/x/sys/windows/registry"
|
|
|
|
const appxPackagesKey = `Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages`
|
|
|
|
// installedWindowsStorePackages returns package full names registered for the
|
|
// current user. Reading this key needs no access to the protected WindowsApps
|
|
// folder and does not start PowerShell.
|
|
func installedWindowsStorePackages() []string {
|
|
key, err := registry.OpenKey(registry.CURRENT_USER, appxPackagesKey, registry.ENUMERATE_SUB_KEYS)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
defer key.Close()
|
|
names, _ := key.ReadSubKeyNames(-1)
|
|
return names
|
|
}
|
|
|
|
// registeredWindowsApp reads what an electron-builder installer
|
|
// registered for the app with guid (registeredIn), for the current user
|
|
// or for all users, in the 64-bit view and then the 32-bit one.
|
|
func registeredWindowsApp(guid string) (dir, version string) {
|
|
return registeredIn(guid, readRegistry)
|
|
}
|
|
|
|
func readRegistry(hive, path, name string) string {
|
|
root := registry.CURRENT_USER
|
|
if hive == "HKLM" {
|
|
root = registry.LOCAL_MACHINE
|
|
}
|
|
for _, view := range []uint32{registry.WOW64_64KEY, registry.WOW64_32KEY} {
|
|
k, err := registry.OpenKey(root, path, registry.QUERY_VALUE|view)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
v, _, _ := k.GetStringValue(name)
|
|
k.Close()
|
|
if v != "" {
|
|
return v
|
|
}
|
|
}
|
|
return ""
|
|
}
|