Skip to content

Commit ab6c56e

Browse files
committed
windows installer: improve many things
- add start menu entry - remove optional desktop shortcut - correctly track optional installed features - use registry keys better - don't make the app hidden
1 parent 2a025bb commit ab6c56e

File tree

1 file changed

+38
-24
lines changed

1 file changed

+38
-24
lines changed

tools/installer/setup.nsi

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
; Custom defines
2323
!define NAME "OOPetris"
2424
!define APPFILE "oopetris.exe"
25+
!define APP_UNINSTALLER_FILE "Uninstall.exe"
2526
!define SLUG "${NAME} v${VERSION}"
2627

2728
;--------------------------------
@@ -30,7 +31,7 @@
3031
Name "${NAME}"
3132
OutFile "${NAME} Setup.exe"
3233
InstallDir "$PROGRAMFILES\${NAME}"
33-
InstallDirRegKey HKCU "Software\${NAME}" ""
34+
InstallDirRegKey HKCU "Software\${NAME}" "InstallDir"
3435
RequestExecutionLevel admin
3536

3637
;--------------------------------
@@ -62,7 +63,7 @@ RequestExecutionLevel admin
6263
;--------------------------------
6364
; Section - Install App, always installed
6465

65-
Section "-hidden app"
66+
Section "Core App" CoreApp
6667
SectionIn RO ; Read only, always installed
6768

6869
; install assets
@@ -86,10 +87,14 @@ Section "-hidden app"
8687
SetOutPath "$INSTDIR"
8788
File /a "${PROJECT_SOURCE_DIR}\subprojects\discord_game_sdk-3.2.1\lib\x86_64\discord_game_sdk.dll"
8889

89-
WriteRegStr HKCU "Software\${NAME}" "" $INSTDIR
90-
WriteUninstaller "$INSTDIR\Uninstall.exe"
9190

91+
WriteRegStr HKCU "Software\${NAME}" "InstallDir" $INSTDIR
92+
WriteUninstaller "$INSTDIR\${APP_UNINSTALLER_FILE}"
9293

94+
; create start menu entry
95+
CreateDirectory '$SMPROGRAMS\${NAME}'
96+
CreateShortCut '$SMPROGRAMS\${NAME}\${NAME}.lnk' '$INSTDIR\${APPFILE}' "" '$INSTDIR\${APPFILE}' 0
97+
CreateShortCut '$SMPROGRAMS\${NAME}\Uninstall ${NAME}.lnk' '$INSTDIR\${APP_UNINSTALLER_FILE}' "" '$INSTDIR\${APP_UNINSTALLER_FILE}' 0
9398
SectionEnd
9499

95100

@@ -105,28 +110,22 @@ Section "Additional Binaries" AdditionalBinaries
105110
; add the bin dir to the path
106111
EnVar::SetHKCU
107112
EnVar::AddValue "Path" "$INSTDIR\bin"
108-
SectionEnd
109-
110-
111113

112-
;--------------------------------
113-
; Section - Shortcut; optional, can be selected by user if he wants to have one
114-
115-
Section "Desktop Shortcut" DeskShort
116-
CreateShortCut "$DESKTOP\${NAME}.lnk" "$INSTDIR\${APPFILE}"
114+
; store that this is installed
115+
WriteRegDWORD HKCU "Software\${NAME}" "AddBin" 1
117116
SectionEnd
118117

119118
;--------------------------------
120119
; Descriptions
121120

122121
;Language strings
123-
LangString DESC_DeskShort ${LANG_ENGLISH} "Create Shortcut on Desktop"
122+
LangString DESC_CoreApp ${LANG_ENGLISH} "Install Core App"
124123
LangString DESC_BinaryFiles ${LANG_ENGLISH} "Install (Optional) Additional Binaries"
125124

126125

127126
;Assign language strings to sections
128127
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
129-
!insertmacro MUI_DESCRIPTION_TEXT ${DeskShort} $(DESC_DeskShort)
128+
!insertmacro MUI_DESCRIPTION_TEXT ${CoreApp} $(DESC_CoreApp)
130129
!insertmacro MUI_DESCRIPTION_TEXT ${AdditionalBinaries} $(DESC_BinaryFiles)
131130
!insertmacro MUI_FUNCTION_DESCRIPTION_END
132131

@@ -153,28 +152,43 @@ Function un.RMDirUP
153152
Skip:
154153

155154
Pop $0
156-
157155
FunctionEnd
158156

159157
;--------------------------------
160158
; Section - Uninstaller
161159

162160
Section "Uninstall"
163161

164-
;Delete Shortcut
165-
Delete "$DESKTOP\${NAME}.lnk"
162+
; Delete assets
163+
RMDir /r "$INSTDIR\assets"
166164

167-
;Delete Uninstall
168-
Delete "$INSTDIR\Uninstall.exe"
165+
; Delete executable
166+
Delete "$INSTDIR\${APPFILE}"
169167

170-
;Delete Folder
168+
; Delete Uninstall file
169+
Delete "$INSTDIR\${APP_UNINSTALLER_FILE}"
170+
171+
; Delete the rest of the Folder
171172
RMDir /r "$INSTDIR"
172173
${RMDirUP} "$INSTDIR"
173174

174-
DeleteRegKey /ifempty HKCU "Software\${NAME}"
175+
; delete start menu entry
176+
Delete '$SMPROGRAMS\${NAME}\${NAME}.lnk'
177+
Delete '$SMPROGRAMS\${NAME}\Uninstall ${NAME}.lnk'
178+
179+
RMDir /r '$SMPROGRAMS\${NAME}'
180+
${RMDirUP} '$SMPROGRAMS\${NAME}'
181+
182+
ReadRegDWORD $0 HKCU "Software\${NAME}" "AddBin"
175183

176-
; remove the bin dir from the path
177-
EnVar::SetHKCU
178-
EnVar::DeleteValue "Path" "$INSTDIR\bin"
184+
${If} $0 != 0
185+
; we have additional binaries installed
186+
187+
; remove the bin dir from the path
188+
EnVar::SetHKCU
189+
EnVar::DeleteValue "Path" "$INSTDIR\bin"
190+
${EndIf}
179191

192+
; delete the whole reg key
193+
DeleteRegKey HKCU "Software\${NAME}"
180194
SectionEnd

0 commit comments

Comments
 (0)