diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index 34cd240ad..cfe7b11e4 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -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 diff --git a/internal/gui/installdir.go b/internal/gui/installdir.go index 53fb09cc1..0fcb84624 100644 --- a/internal/gui/installdir.go +++ b/internal/gui/installdir.go @@ -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 { diff --git a/internal/gui/installdir_test.go b/internal/gui/installdir_test.go index e5182c4d8..ffb06a30e 100644 --- a/internal/gui/installdir_test.go +++ b/internal/gui/installdir_test.go @@ -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 diff --git a/internal/gui/installdir_windows.go b/internal/gui/installdir_windows.go index 081cedf7b..c02644ae5 100644 --- a/internal/gui/installdir_windows.go +++ b/internal/gui/installdir_windows.go @@ -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)