all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Corwin Brust <corwin@bru.st>
To: 75013@debbugs.gnu.org
Subject: bug#75013: Windows binary installer ignores user options for Start menu shortcuts
Date: Sun, 22 Dec 2024 12:29:11 -0600	[thread overview]
Message-ID: <CAJf-WoTfVwZApW9Hwx4Sj-2knxSvO6Hs8SoWN5crXhaJw=9tpA@mail.gmail.com> (raw)
In-Reply-To: <CAJf-WoSe3Nz37aYiPtUU6AHSB5ZzPyTujWmAyOk6y-qZUeRtHA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

Tags: patch

Francis reported that a binary built from the previous version of the
patch sent to this bug ticket worked but noted that Emacs (unlike many
other programs when running on Windows) cannot be uninstalled via Add
Remove Programs in the Windows Control Panel.  The updated patch
(additionally) enables this method of uninstallation as well as
removing empty Program Files parent folders when uninstalling.

[-- Attachment #2: emacs.nsi.patch --]
[-- Type: application/octet-stream, Size: 5030 bytes --]

--- emacs.nsi.STABLE	2024-12-21 16:21:09.921280300 -0600
+++ emacs.nsi	2024-12-22 12:02:04.577320200 -0600
@@ -8,7 +8,10 @@
 SetCompressor /solid lzma
 
 Var StartMenuFolder
+Var UninstallerPath
 
+!define UNINST_KEY \
+    "Software\Microsoft\Windows\CurrentVersion\Uninstall\emacs-${VERSION_BRANCH}"
 
 !define MUI_WELCOMEPAGE_TITLE "Emacs"
 !define MUI_WELCOMEPAGE_TITLE_3LINES
@@ -20,16 +23,27 @@
 
 !insertmacro MUI_PAGE_WELCOME
 
-
-!define MUI_LICENSEPAGE_TEXT_TOP "The GNU General Public License"
+# licensing/about click-though page
+!define MUI_PAGE_HEADER_TEXT "Emacs is Free Software"
+!define MUI_PAGE_HEADER_SUBTEXT "A component of the GNU operating system."
+!define MUI_LICENSEPAGE_TEXT_TOP "This program is free software."
+!define MUI_LICENSEPAGE_TEXT_BOTTOM "You can redistribute this program and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License (as above), or (at your option) any later version."
+!define MUI_LICENSEPAGE_BUTTON "OK"
 !insertmacro MUI_PAGE_LICENSE "emacs-${VERSION_BRANCH}\share\emacs\${EMACS_VERSION}\lisp\COPYING"
 
+# user option page: installation path
 !insertmacro MUI_PAGE_DIRECTORY
-!insertmacro MUI_PAGE_INSTFILES
 
+# user option page: start menu shortcut
 !insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder
 
+# user option confirm/begin install
+!insertmacro MUI_PAGE_INSTFILES
+
+# uninstaller confirmation/options (no options)
 !insertmacro MUI_UNPAGE_CONFIRM
+
+# uninstaller begin
 !insertmacro MUI_UNPAGE_INSTFILES
 
 !insertmacro MUI_LANGUAGE "English"
@@ -39,23 +53,35 @@
     StrCpy $INSTDIR "$PROGRAMFILES64\Emacs"
 functionend
 
-
+# main section logic, run after confirming installation
 Section
 
-  SetOutPath $INSTDIR
+  # insisting on installing shortcuts for "all users"
+  # might ensure uninstall can remove shortcuts we created
+  # SetShellVarContext all
 
+  # extract program files
+  SetOutPath $INSTDIR
   File /r emacs-${VERSION_BRANCH}
 
   # define uninstaller name
-  WriteUninstaller $INSTDIR\Uninstall.exe
+  StrCpy $UninstallerPath "$INSTDIR\Uninstall-${VERSION_BRANCH}.exe"
+
+  # create uninstaller
+  WriteUninstaller "$UninstallerPath"
+
+  # add registry key to enable uninstall from control panel
+  WriteRegStr HKLM "${UNINST_KEY}" "DisplayName" "GNU Emacs ${VERSION_BRANCH}"
+  WriteRegStr HKLM "${UNINST_KEY}" "UninstallString" "$\"$UninstallerPath$\""
 
-  !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
   ;Create shortcuts
+  !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
   CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
-  CreateShortcut "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
-
+  CreateShortcut "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" \
+      "$UninstallerPath"
+  CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Emacs.lnk" \
+      "$INSTDIR\emacs-${VERSION_BRANCH}\bin\runemacs.exe"
   !insertmacro MUI_STARTMENU_WRITE_END
-  CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Emacs.lnk" "$INSTDIR\emacs-${VERSION_BRANCH}\bin\runemacs.exe"
 SectionEnd
 
 
@@ -63,15 +89,50 @@
 # the section will always be named "Uninstall"
 Section "Uninstall"
 
-  # Always delete uninstaller first
-  Delete "$INSTDIR\Uninstall.exe"
+  # remove All Users shortcuts only
+  # SetShellVarContext all
 
-  # now delete installed directory
-  RMDir /r "$INSTDIR"
-  RMDir "$INSTDIR"
+  # retreive/recalculate uninstaller location
+  StrCpy $UninstallerPath "$INSTDIR\Uninstall-${VERSION_BRANCH}.exe"
 
+  # remove registry key
+  DeleteRegKey HKLM "${UNINST_KEY}"
+
+  # delete uninstaller
+  Delete "$INSTDIR\Uninstall-${VERSION_BRANCH}.exe"
+
+  # retreive/reclculate startmenu shortcuts location
   !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
+  StrCpy $StartMenuFolder "$SMPROGRAMS\$StartMenuFolder"
+
+  # remove Start Menu Program shortcuts
+  Delete "$StartMenuFolder\Emacs.lnk"
+  Delete "$StartMenuFolder\Uninstall.lnk"
+
+  # remove empty startmenu parents up to $SMPROGRAMS
+  startMenuDeleteLoop:
+    ClearErrors
+    RMDir $StartMenuFolder
+    GetFullPathName $StartMenuFolder "$StartMenuFolder\.."
+    IfErrors startMenuDeleteLoopDone
+    StrCmp $StartMenuFolder $SMPROGRAMS startMenuDeleteLoopDone startMenuDeleteLoop
+
+  # we're basically using GOTO, above, so we should get here..
+  startMenuDeleteLoopDone:
+
+  # next we remove stuff from program-files/instalation path
+  # start with recursive delete of the Emacs we installed
+  RMDir /r "$INSTDIR\emacs-${VERSION_BRANCH}"
+
+  # now walk parents of installation directory, deleting if empty
+  instDirDeleteLoop:
+    ClearErrors
+    RMDir $INSTDIR
+    GetFullPathName $INSTDIR "$INSTDIR\.."
+    IfErrors instDirDeleteLoopDone
+    StrCmp $INSTDIR $PROGRAMFILES64 instDirDeleteLoopDone instDirDeleteLoop
+
+  # final clean-up (after removing from startmenu and progfiles)
+  instDirDeleteLoopDone:
 
-  Delete "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk"
-  RMDir "$SMPROGRAMS\$StartMenuFolder"
 SectionEnd

  reply	other threads:[~2024-12-22 18:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-21 17:44 Windows binaries and installer fixes for 30.0.93 Corwin Brust
2024-12-21 18:29 ` Francis Wright
2024-12-21 19:46   ` Windows binary installer ignores user options for Start menu shortcuts Corwin Brust
2024-12-21 19:53     ` Corwin Brust
2024-12-21 23:05     ` bug#75013: " Corwin Brust
2024-12-22 18:29       ` Corwin Brust [this message]
2024-12-21 23:20   ` Windows binaries and installer fixes for 30.0.93 Corwin Brust
2024-12-22 12:03     ` Francis Wright
2024-12-22 18:24       ` Corwin Brust

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJf-WoTfVwZApW9Hwx4Sj-2knxSvO6Hs8SoWN5crXhaJw=9tpA@mail.gmail.com' \
    --to=corwin@bru.st \
    --cc=75013@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.