Skip to content

Commit

Permalink
fix installer to write registry keys for add/remove software (#44)
Browse files Browse the repository at this point in the history
* fix installer to write registry keys for add/remove software

* uncomment line to delete makensis file after creation

* test workflow

* add rye config to set author of projects
  • Loading branch information
trappitsch authored Apr 12, 2024
1 parent 5ce5a52 commit 12bb03e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
uses: eifinger/setup-rye@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup rye config - required for tests
run: |
rye config --set default.author="Firstname Lastname <email@domain.com>"
- name: Sync Rye
run: |
rye pin ${{ matrix.python-version }}
Expand Down
5 changes: 5 additions & 0 deletions src/box/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def app_entry_type(self):
"""Return the entry type of the project for PyApp."""
return self._pyproject["tool"]["box"]["entry_type"]

@property
def author(self) -> str:
"""Return the (first) author of the project."""
return self._project["authors"][0]["name"]

@property
def builder(self) -> str:
"""Return the builder of the project."""
Expand Down
9 changes: 8 additions & 1 deletion src/box/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,14 @@ def windows_gui(self):
nsis_script_name = Path("make_installer.nsi")
with open(nsis_script_name, "w") as f:
f.write(
nsis_gui_script(name_pkg, installer_name, self._release_file, icon)
nsis_gui_script(
name_pkg,
installer_name,
self._config.author,
self._config.version,
self._release_file,
icon,
)
)

# make the installer
Expand Down
38 changes: 27 additions & 11 deletions src/box/installer_utils/windows_hlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@


def nsis_gui_script(
project_name: str, installer_name: str, binary_path: Path, icon_path: Path
project_name: str,
installer_name: str,
author: str,
version: str,
binary_path: Path,
icon_path: Path,
):
"""Create NSIS script for GUI installer.
:param project_name: Name of the project
:param installer_name: Name of the installer to be produced by NSIS
:param author: Author of the project
:param version: Version of the project
:param binary_path: Path to the binary to be installed
:param icon_path: Path to the icon file to be used in the installer
"""
Expand All @@ -19,6 +26,8 @@ def nsis_gui_script(
;Include Modern UI

!include "MUI2.nsh"
!define MUI_ICON "{icon_path.absolute()}"
!define MUI_UNICON "{icon_path.absolute()}"

;--------------------------------
;General
Expand Down Expand Up @@ -86,34 +95,40 @@ def nsis_gui_script(
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall-{project_name}.exe"

; Add uninstaller key information for add/remove software entry
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\{project_name}" "DisplayName" "{project_name}"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\{project_name}" "UninstallString" "$INSTDIR\Uninstall-{project_name}.exe"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\{project_name}" "Publisher" "{author}"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\{project_name}" "DisplayIcon" "$INSTDIR\Uninstall-{project_name}.exe"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\{project_name}" "DisplayVersion" "{version}"

!insertmacro MUI_STARTMENU_WRITE_BEGIN Application

;Create shortcuts - if icon file is empty, leave that part away
CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
CreateShortcut "$SMPROGRAMS\$StartMenuFolder\{project_name}.lnk" "$INSTDIR\{binary_path.name}" "" "{str(icon_path.absolute())}"
CreateShortcut "$SMPROGRAMS\$StartMenuFolder\Uninstall-{project_name}.lnk" "$INSTDIR\Uninstall-{project_name}.exe"
;Create shortcuts - if icon file is empty, leave that part away
CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
CreateShortcut "$SMPROGRAMS\$StartMenuFolder\{project_name}.lnk" "$INSTDIR\{binary_path.name}" "" "{str(icon_path.absolute())}"
CreateShortcut "$SMPROGRAMS\$StartMenuFolder\Uninstall-{project_name}.lnk" "$INSTDIR\Uninstall-{project_name}.exe"

!insertmacro MUI_STARTMENU_WRITE_END

SectionEnd

;--------------------------------
;Descriptions

;Language strings


;-------------------------------- ;Language strings
LangString DESC_SecInst ${{LANG_ENGLISH}} "Selection."

;Assign language strings to sections
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${{SecInst}} $(DESC_SecInst)
!insertmacro MUI_DESCRIPTION_TEXT ${{SecInst}} $(DESC_SecInst)
!insertmacro MUI_FUNCTION_DESCRIPTION_END

;--------------------------------
;Uninstaller Section

Section "Uninstall"


; Delete {project_name} folder
Delete "$INSTDIR\{binary_path.name}"
Delete "$INSTDIR\Uninstall-{project_name}.exe"
Expand All @@ -131,7 +146,8 @@ def nsis_gui_script(
RMDir "$SMPROGRAMS\$StartMenuFolder"

; Delete registry key
DeleteRegKey /ifempty HKCU "Software\{project_name}"
DeleteRegKey HKCU "Software\{project_name}"
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\{project_name}"

SectionEnd
"""

0 comments on commit 12bb03e

Please sign in to comment.