install: the Windows install dialog says the download can be deleted
@jiangshangmuyun on X updated on Windows and found a new magpie while "the original is still there". That is by design since14807bcf2: a magpie-windows-amd64.exe kept in a folder of the user's own is asked about and installed to <folder>\magpie\magpie.exe, a copy, and the download is left where it was. Nothing said it could go. Now the install dialog (installDialog, Windows' task dialog) has a footer naming the exe it was opened from: "Once magpie is installed, you can delete D:\Tools\magpie-windows-amd64.exe." It is in each language the dialog speaks (en, zh, zh-TW, ja, de), and stays under a refusal too. The file is never deleted by magpie; only the words are new. The footer is TASKDIALOGCONFIG's pszFooter (offset 132 in the packed 64-bit layout), left empty when the exe can't be told. Tests: TestInstallDialogSaysTheDownloadCanGo (every language names the exe once, no format error; none without an exe). Broken by hand: zh's text without %s goes red with %!(EXTRA ...). Run: go test ./internal/gui/ ./internal/update/ on mote (ok) and on the Windows box: the new and existing install tests ok; 11 reds there (TestGatewayHeldByAContainer, the four %AppData% import rows, TestProviderSaveClientCert, TestPageAwayLetsStatsGo, TestPluginAgentMissingSaysSo, TestGatewayModeStatsNameTheGatewaySessions, TestUpdateThatWontStart, TestPackagedByDpkg) fail the same at a fresh origin/main9dcec6751and are open (#6068, #4603, #6810, #5928, #6059); GOOS=windows go vet (amd64, arm64) of internal/gui and internal/update on mote; gofmt -l clean. Real dialog: a throwaway test (not committed) opened taskDialog on xiaomi-gpu's console session with comctl32 6 and read it back through UI Automation, en and zh: the footer is there under the buttons, full path included. Not run: a Linux go vet of internal/gui (the box has no gtk4/webkit headers; installdir.go is pure Go and compiles on darwin). Not tried: the real installed app's first start from D:\, or a screenshot of the dialog (the console renders black over SSH-started captures).
This commit is contained in:
@@ -1312,7 +1312,10 @@ one in its place. A copy renamed (`D:\Tools\magpie.exe`) is left alone.
|
||||
The first time, with nothing installed, it asks where in Windows' task
|
||||
dialog (`installDialog` in
|
||||
[`installdir_windows.go`](../../internal/gui/installdir_windows.go)): the
|
||||
folder, Install, Change… and Cancel, in the tray's language. Change… opens
|
||||
folder, Install, Change… and Cancel, in the tray's language, with a footer
|
||||
naming the exe it was opened from, which can be deleted once installed:
|
||||
the install copies it and never deletes it (@jiangshangmuyun on X: "the
|
||||
original is still there"). Change… opens
|
||||
the folder picker, and a folder picked gets `magpie` added unless it is
|
||||
named that already (`update.InstallDir`). The default is
|
||||
`%LOCALAPPDATA%\Programs\magpie`; another folder is recorded at
|
||||
@@ -1337,8 +1340,8 @@ v0.1.4166's release check waited on the dialog with no gateway
|
||||
`TestSettleDeclinedElsewhereIsKept`, `TestDeclinedRecord`,
|
||||
`TestSettleInstallsWhereTheUserChose`,
|
||||
`TestSettleOffersTheChosenFolderAgain`, `TestInstallableRefuses` in
|
||||
[`install_test.go`](../../internal/update/install_test.go) and
|
||||
`TestInstallWordsEveryLanguage`.
|
||||
[`install_test.go`](../../internal/update/install_test.go),
|
||||
`TestInstallWordsEveryLanguage` and `TestInstallDialogSaysTheDownloadCanGo`.
|
||||
|
||||
## Verification
|
||||
|
||||
|
||||
@@ -18,10 +18,14 @@ import (
|
||||
// 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.
|
||||
// to, one downloads land in, and any other failure; and, under it all,
|
||||
// that the download it was started from can be deleted once installed
|
||||
// (keep): the install copies it and leaves it where it is
|
||||
// (@jiangshangmuyun on X found "the original is still there").
|
||||
type installWords struct {
|
||||
title, ask, install, change, pick string
|
||||
admin, downloads, failed string
|
||||
keep string
|
||||
}
|
||||
|
||||
var installText = map[string]installWords{
|
||||
@@ -31,6 +35,7 @@ var installText = map[string]installWords{
|
||||
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",
|
||||
keep: "Once magpie is installed, you can delete %s.",
|
||||
},
|
||||
"zh": {
|
||||
title: "magpie", ask: "把 magpie 安装到这个文件夹?", install: "安装", change: "更改…",
|
||||
@@ -38,6 +43,7 @@ var installText = map[string]installWords{
|
||||
admin: "只有管理员才能写入 %s。magpie 只为你安装,并会自己更新,请选择一个你自己的文件夹。",
|
||||
downloads: "%s 是下载存放的地方,请选择另一个文件夹。",
|
||||
failed: "magpie 无法安装到 %s:%v",
|
||||
keep: "安装完成后,可以删除 %s。",
|
||||
},
|
||||
"zh-TW": {
|
||||
title: "magpie", ask: "把 magpie 安裝到這個資料夾?", install: "安裝", change: "變更…",
|
||||
@@ -45,6 +51,7 @@ var installText = map[string]installWords{
|
||||
admin: "只有系統管理員才能寫入 %s。magpie 只為你安裝,並會自己更新,請選擇一個你自己的資料夾。",
|
||||
downloads: "%s 是下載存放的地方,請選擇另一個資料夾。",
|
||||
failed: "magpie 無法安裝到 %s:%v",
|
||||
keep: "安裝完成後,可以刪除 %s。",
|
||||
},
|
||||
"ja": {
|
||||
title: "magpie", ask: "このフォルダーに magpie をインストールしますか?", install: "インストール", change: "変更…",
|
||||
@@ -52,6 +59,7 @@ var installText = map[string]installWords{
|
||||
admin: "%s に書き込めるのは管理者だけです。magpie はあなた専用にインストールされ、自分で更新するので、あなた自身のフォルダーを選んでください。",
|
||||
downloads: "%s はダウンロードの保存先です。別のフォルダーを選んでください。",
|
||||
failed: "%s に magpie をインストールできません:%v",
|
||||
keep: "インストール後は %s を削除してかまいません。",
|
||||
},
|
||||
"de": {
|
||||
title: "magpie", ask: "magpie in diesem Ordner installieren?", install: "Installieren", change: "Ändern…",
|
||||
@@ -59,6 +67,7 @@ var installText = map[string]installWords{
|
||||
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",
|
||||
keep: "Nach der Installation können Sie %s löschen.",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -71,6 +80,15 @@ func installWordsFor(lang string) installWords {
|
||||
return installText["en"]
|
||||
}
|
||||
|
||||
// footer says that exe, the download the dialog was opened from, can be
|
||||
// deleted once magpie is installed; "" when exe isn't known.
|
||||
func (w installWords) footer(exe string) string {
|
||||
if exe == "" {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf(w.keep, exe)
|
||||
}
|
||||
|
||||
// refusal is what the dialog says about dir, which check refused with err.
|
||||
func (w installWords) refusal(dir string, err error) string {
|
||||
switch {
|
||||
|
||||
@@ -48,6 +48,23 @@ func TestInstallWordsEveryLanguage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestInstallDialogSaysTheDownloadCanGo: the install copies the download
|
||||
// and leaves it where it was (@jiangshangmuyun on X: "the original is
|
||||
// still there"), so the dialog says, in every language, that the file
|
||||
// it was opened from can be deleted once installed, naming it.
|
||||
func TestInstallDialogSaysTheDownloadCanGo(t *testing.T) {
|
||||
exe := `D:\Tools\magpie-windows-amd64.exe`
|
||||
for lang, w := range installText {
|
||||
got := w.footer(exe)
|
||||
if !strings.Contains(got, exe) || strings.Contains(got, "%!") || strings.Count(got, exe) != 1 {
|
||||
t.Errorf("%s: footer %q doesn't name %s once", lang, got, exe)
|
||||
}
|
||||
}
|
||||
if got := installText["en"].footer(""); got != "" {
|
||||
t.Errorf("no exe known: footer %q, want none", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestInstallQuestionNeedsSomeoneToAnswer: a CI runner's start (any CI
|
||||
// service's CI variable) or one on a desktop no one sees is never asked
|
||||
// where to install, so nothing waits on a dialog with the gateway not
|
||||
|
||||
@@ -38,6 +38,10 @@ func askInstallFolder() {
|
||||
}
|
||||
update.AskFolder = func(suggest string, check func(string) error) string {
|
||||
w := installWordsFor(trayLang(settings.Shared().Lang, systemLang))
|
||||
exe, err := update.Executable()
|
||||
if err != nil {
|
||||
exe = ""
|
||||
}
|
||||
var out string
|
||||
done := make(chan struct{})
|
||||
// COM and the dialogs on a thread of their own, which ends with
|
||||
@@ -45,7 +49,7 @@ func askInstallFolder() {
|
||||
go func() {
|
||||
runtime.LockOSThread()
|
||||
defer close(done)
|
||||
out = installDialog(w, suggest, check)
|
||||
out = installDialog(w, suggest, w.footer(exe), check)
|
||||
}()
|
||||
<-done
|
||||
return out
|
||||
@@ -58,12 +62,12 @@ const (
|
||||
)
|
||||
|
||||
// installDialog asks until the user installs in a folder check accepts,
|
||||
// or cancels (""). With no dialog to be had, dir is taken, as before
|
||||
// there was a choice.
|
||||
func installDialog(w installWords, dir string, check func(string) error) string {
|
||||
// or cancels (""), with footer under it all. With no dialog to be had,
|
||||
// dir is taken, as before there was a choice.
|
||||
func installDialog(w installWords, dir, footer string, check func(string) error) string {
|
||||
note := ""
|
||||
for {
|
||||
btn, err := taskDialog(w, dir, note)
|
||||
btn, err := taskDialog(w, dir, note, footer)
|
||||
if err != nil {
|
||||
log.Println("install: the folder dialog:", err)
|
||||
return dir
|
||||
@@ -122,9 +126,10 @@ var (
|
||||
|
||||
// taskDialog shows Windows' task dialog (comctl32 6, which the exe's
|
||||
// manifest asks for): the folder under the question, Install, Change…
|
||||
// and Cancel, and note, a refusal, with a warning icon above. It answers
|
||||
// the button pressed.
|
||||
func taskDialog(w installWords, dir, note string) (int, error) {
|
||||
// and Cancel, and note, a refusal, with a warning icon above; footer,
|
||||
// when there is one, in the dialog's footer. It answers the button
|
||||
// pressed.
|
||||
func taskDialog(w installWords, dir, note, footer string) (int, error) {
|
||||
if err := procTaskDialogIndi.Find(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -173,6 +178,9 @@ func taskDialog(w installWords, dir, note string) (int, error) {
|
||||
le.PutUint32(cfg[60:], 2)
|
||||
le.PutUint64(cfg[64:], uint64(uintptr(unsafe.Pointer(&buttons[0]))))
|
||||
le.PutUint32(cfg[72:], idInstall)
|
||||
if footer != "" {
|
||||
le.PutUint64(cfg[132:], uint64(str(footer))) // pszFooter
|
||||
}
|
||||
var pressed int32
|
||||
hr, _, _ := procTaskDialogIndi.Call(uintptr(unsafe.Pointer(&cfg[0])), uintptr(unsafe.Pointer(&pressed)), 0, 0)
|
||||
runtime.KeepAlive(cfg)
|
||||
|
||||
Reference in New Issue
Block a user