The Windows exe opened from Downloads (or the Desktop, or temp)
installed itself into %LOCALAPPDATA%\Programs\magpie without a word.
Now, the first time, with nothing installed yet, Windows' task dialog
asks "Install magpie in this folder?". It shows the folder and offers
Install, Change… and Cancel, in the tray's language (en, zh, zh-TW,
ja, de).
- Change… opens the system folder picker. A picked folder gets
"magpie" added unless it is already named that (update.InstallDir).
- A folder other than the default is recorded at HKCU\Software\magpie
InstallLocation. So the next exe downloaded replaces the copy there
in place and asks nothing (installed(), forwards()).
- Cancel runs the exe where it is, as a portable copy, and nothing is
recorded.
- Uninstall forgets the record (update.ForgetInstallDir, a new System
step).
- The shortcut, App Paths, autostart, magpie://, the PATH entry and
self-update already take the running exe's folder, so they follow
the choice.
Program Files and other folders only an administrator can write to
are refused in the dialog (update.Installable test-writes and maps a
permission error to ErrNeedsAdmin). They are not elevated into.
magpie installs per user (HKCU Run, the user's PATH), and its
self-update replaces the exe without elevation (CanElevate is false on
Windows). So an admin folder would make every update fail, or would
need a UAC prompt on each one. A downloads folder is refused too.
Refusing is the simplest correct choice: it costs a user nothing they
had before, and keeps updates silent. Any folders the test-write made
are removed again.
Docs: gui-shell.md, "Where Windows installs magpie".
Run (mote, at this head on origin/main f9e6061b8):
- gofmt -l is clean.
- go build ./... and go vet of update, uninstall and gui.
- GOOS=windows go vet of gui, update and uninstall.
- GOOS=windows GOARCH=arm64 go build ./....
- GOOS=linux go vet -tags nogui of the same packages.
- go test -count=1 ./internal/update ./internal/uninstall, and
-run TestInstallWords|TestTrayLang ./internal/gui: ok.
Run (win-run, xiaomi-gpu):
- internal/uninstall ok, and gui TestInstallWordsEveryLanguage ok.
- internal/update: one red, TestPackagedByDpkg. It is red on
origin/main too: an NTFS stream from the fixture name
magpie:amd64.list (#4603).
Real Windows 11 run (xiaomi-gpu, a sandbox USERPROFILE/LOCALAPPDATA
under C:\Users\yeton\magpie-idir, MAGPIE_ADDR on 3481, exe in its
Downloads, driven over UI Automation and TDM_CLICK_BUTTON):
- The dialog came up in Chinese, with the app icon and the default
folder.
- Change… → C:\Program Files was refused with the administrator note
and the warning icon, and no folder was left behind. C:\Windows was
refused the same way.
- Change… → …\Tools gave …\Tools\magpie. Install put magpie.exe and
magpie.com there, and the app ran from there.
- Afterwards InstallLocation, the user's PATH, App Paths and
magpie:// all named …\Tools\magpie. `magpie version` from a fresh
PATH resolved to …\Tools\magpie\magpie.com. `magpie autostart on`
wrote Run = "…\Tools\magpie\magpie.exe" tray.
- Upgrade: a 0.1.9001 build downloaded into Downloads asked nothing.
It replaced …\Tools\magpie\magpie.exe (FileVersion 0.1.9001) and ran
from there.
- `magpie uninstall --yes` removed autostart, App Paths, the scheme
and the record, and deleted the sandbox data. The next exe asked
again.
- Cancel ran the exe from Downloads and recorded nothing.
- The registry and folders were put back as they were before the run,
checked by a snapshot diff.
Broken by hand:
- recordedDir's lookup turned off: TestSettleInstallsWhereTheUserChose
and TestSettleOffersTheChosenFolderAgain went red.
- AskFolder skipped: those two and TestSettleDeclinedRunsHere went red.
Not tried:
- The in-app self-update download. There is no newer release to
download; the in-place replace path was run with a downloaded exe.
- The en, ja, de and zh-TW dialogs on screen. Their words are checked
by TestInstallWordsEveryLanguage only.
- arm64 Windows.
- A Downloads folder moved by OneDrive.
- The Start-menu shortcut. The box's real App Paths already held
another session's magpie, so shortcut.ensure took the shortcut as
removed by the user. This is existing behaviour.
Not changed: uninstall still leaves the PATH entry and the exe, as
before for every install (#5500). Related to #2663, which asks for a
first-run choice of where magpie lives.
Reported-by: feng_21795_78266 (Discord)
83 lines
3.7 KiB
Go
83 lines
3.7 KiB
Go
//go:build !nogui
|
||
|
||
package gui
|
||
|
||
import (
|
||
"errors"
|
||
"fmt"
|
||
|
||
"github.com/yetone/magpie/internal/update"
|
||
)
|
||
|
||
// The Windows app opened from Downloads installs itself (update.Settle),
|
||
// and the first time it asks where, in a dialog of Windows' own
|
||
// (installdir_windows.go): the folder, Install, Change… and Cancel, as an
|
||
// installer's folder page has them (feng_21795_78266 on Discord).
|
||
|
||
// installWords are the dialog's words in one language: its title, the
|
||
// question, the two buttons, the folder picker's title, and what is said
|
||
// when the folder can't be used: one only an administrator can write
|
||
// to, one downloads land in, and any other failure.
|
||
type installWords struct {
|
||
title, ask, install, change, pick string
|
||
admin, downloads, failed string
|
||
}
|
||
|
||
var installText = map[string]installWords{
|
||
"en": {
|
||
title: "magpie", ask: "Install magpie in this folder?", install: "Install", change: "Change…",
|
||
pick: "Choose where to install magpie",
|
||
admin: "Only an administrator can write to %s. magpie is installed for you alone and updates itself, so choose a folder of your own.",
|
||
downloads: "Downloads land in %s. Choose another folder.",
|
||
failed: "magpie can't be installed in %s: %v",
|
||
},
|
||
"zh": {
|
||
title: "magpie", ask: "把 magpie 安装到这个文件夹?", install: "安装", change: "更改…",
|
||
pick: "选择 magpie 的安装位置",
|
||
admin: "只有管理员才能写入 %s。magpie 只为你安装,并会自己更新,请选择一个你自己的文件夹。",
|
||
downloads: "%s 是下载存放的地方,请选择另一个文件夹。",
|
||
failed: "magpie 无法安装到 %s:%v",
|
||
},
|
||
"zh-TW": {
|
||
title: "magpie", ask: "把 magpie 安裝到這個資料夾?", install: "安裝", change: "變更…",
|
||
pick: "選擇 magpie 的安裝位置",
|
||
admin: "只有系統管理員才能寫入 %s。magpie 只為你安裝,並會自己更新,請選擇一個你自己的資料夾。",
|
||
downloads: "%s 是下載存放的地方,請選擇另一個資料夾。",
|
||
failed: "magpie 無法安裝到 %s:%v",
|
||
},
|
||
"ja": {
|
||
title: "magpie", ask: "このフォルダーに magpie をインストールしますか?", install: "インストール", change: "変更…",
|
||
pick: "magpie のインストール先を選択",
|
||
admin: "%s に書き込めるのは管理者だけです。magpie はあなた専用にインストールされ、自分で更新するので、あなた自身のフォルダーを選んでください。",
|
||
downloads: "%s はダウンロードの保存先です。別のフォルダーを選んでください。",
|
||
failed: "%s に magpie をインストールできません:%v",
|
||
},
|
||
"de": {
|
||
title: "magpie", ask: "magpie in diesem Ordner installieren?", install: "Installieren", change: "Ändern…",
|
||
pick: "Speicherort für magpie wählen",
|
||
admin: "Nur ein Administrator darf in %s schreiben. magpie wird nur für Sie installiert und aktualisiert sich selbst, wählen Sie also einen eigenen Ordner.",
|
||
downloads: "In %s landen Downloads. Wählen Sie einen anderen Ordner.",
|
||
failed: "magpie kann nicht in %s installiert werden: %v",
|
||
},
|
||
}
|
||
|
||
// installWordsFor is the dialog's words in lang (trayLang's), English
|
||
// where it has none.
|
||
func installWordsFor(lang string) installWords {
|
||
if w, ok := installText[lang]; ok {
|
||
return w
|
||
}
|
||
return installText["en"]
|
||
}
|
||
|
||
// refusal is what the dialog says about dir, which check refused with err.
|
||
func (w installWords) refusal(dir string, err error) string {
|
||
switch {
|
||
case errors.Is(err, update.ErrNeedsAdmin):
|
||
return fmt.Sprintf(w.admin, dir)
|
||
case errors.Is(err, update.ErrDownloadFolder):
|
||
return fmt.Sprintf(w.downloads, dir)
|
||
}
|
||
return fmt.Sprintf(w.failed, dir, err)
|
||
}
|