33
44!include " MUI2.nsh"
55!include " logiclib.nsh"
6+ !include " FileFunc.nsh"
67
78; test if required arguments were given in the command line
89!ifndef VERSION
3031!define APPFILE " oopetris.exe"
3132!define APP_UNINSTALLER_FILE " Uninstall.exe"
3233!define SLUG " ${NAME} v${VERSION}"
33-
34+ !define ARP " Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME} "
3435; --------------------------------
3536; General
3637
@@ -66,6 +67,34 @@ RequestExecutionLevel admin
6667; Set UI language
6768!insertmacro MUI_LANGUAGE " English"
6869
70+
71+ ; Return on top of stack the total size of the selected (installed) sections, formated as DWORD
72+ ; Assumes no more than 256 sections are defined
73+ ; ; source: https://nsis.sourceforge.io/Add_uninstall_information_to_Add/Remove_Programs
74+ Var GetInstalledSize.total
75+ Function GetInstalledSize
76+ Push $0
77+ Push $1
78+ StrCpy $GetInstalledSize .total 0
79+ ${ForEach} $1 0 256 + 1
80+ ${if} ${SectionIsSelected} $1
81+ SectionGetSize $1 $0
82+ IntOp $GetInstalledSize .total $GetInstalledSize .total + $0
83+ ${Endif}
84+
85+ ; Error flag is set when an out-of-bound section is referenced
86+ ${if} ${errors}
87+ ${break}
88+ ${Endif}
89+ ${Next}
90+
91+ ClearErrors
92+ Pop $1
93+ Pop $0
94+ IntFmt $GetInstalledSize .total " 0x%08X" $GetInstalledSize .total
95+ Push $GetInstalledSize .total
96+ FunctionEnd
97+
6998; --------------------------------
7099; Section - Install App, always installed
71100
@@ -81,34 +110,71 @@ Section "Core App" CoreApp
81110
82111 SetOutPath " $INSTDIR\assets\icons"
83112 File /r " ${PROJECT_SOURCE_DIR}\assets\icons\*.*"
84-
85- SetOutPath " $INSTDIR\assets\music"
86- File /r " ${PROJECT_SOURCE_DIR}\assets\music\*.*"
113+
114+ ; install the windows icon to use it
115+ SetOutPath " $INSTDIR"
116+ File " /oname=${NAME}.ico" " ${PROJECT_SOURCE_DIR}\assets\icon\icon.ico"
87117
88118 ; install executable
89119 SetOutPath " $INSTDIR"
90120 File /a " ${PROJECT_BUILD_DIR}\${APPFILE}"
91121
92122 ; install dynamic libraries
93123 SetOutPath " $INSTDIR"
94- File /a " ${PROJECT_SOURCE_DIR}\subprojects\discord_game_sdk-3.2.1\lib\x86_64\discord_game_sdk.dll"
124+ File " ${PROJECT_SOURCE_DIR}\subprojects\discord_game_sdk-3.2.1\lib\x86_64\discord_game_sdk.dll"
95125
96126 ; install default settings (DO NOT Override)
97127 SetOutPath " $APPDATA\${AUTHOR}\${NAME}"
98128 SetOverwrite off
99- File " ${PROJECT_SOURCE_DIR}\settings.json"
129+ File " ${PROJECT_SOURCE_DIR}\settings.json"
100130 SetOverwrite on
101131
132+ ; write some regestry keys, just for information
133+ WriteRegStr HKCU " Software\${NAME}" " Version" " ${VERSION}"
134+
135+ ; write the uninstaller and needed information
102136 WriteRegStr HKCU " Software\${NAME}" " InstallDir" $INSTDIR
103137 WriteUninstaller " $INSTDIR\${APP_UNINSTALLER_FILE}"
104138
105139 ; create start menu entry
106140 CreateDirectory ' $SMPROGRAMS\${NAME}'
107141 CreateShortCut ' $SMPROGRAMS\${NAME}\${NAME}.lnk' ' $INSTDIR\${APPFILE}' " " ' $INSTDIR\${APPFILE}' 0
108142 CreateShortCut ' $SMPROGRAMS\${NAME}\Uninstall ${NAME}.lnk' ' $INSTDIR\${APP_UNINSTALLER_FILE}' " " ' $INSTDIR\${APP_UNINSTALLER_FILE}' 0
143+
144+ ; create metadata for some windows features to work correctly
145+
146+ ; Write the uninstall keys for Windows
147+ WriteRegStr HKCU " ${ARP}" " UninstallString" ' "$INSTDIR\${APP_UNINSTALLER_FILE}"'
148+ WriteRegStr HKCU " ${ARP}" " QuietUninstallString" ' "$INSTDIR\${APP_UNINSTALLER_FILE}"'
149+
150+ ; write some generic metadata about the uninstaller
151+ WriteRegStr HKCU " ${ARP}" " DisplayName" " ${NAME}"
152+ WriteRegStr HKCU " ${ARP}" " DisplayVersion" " ${VERSION}"
153+ WriteRegStr HKCU " ${ARP}" " Publisher" " ${AUTHOR}"
154+ WriteRegStr HKCU " ${ARP}" " DisplayIcon" " $INSTDIR\${NAME}.ico"
155+
156+ ; get the estimated size and use it
157+ Call GetInstalledSize
158+ WriteRegDWORD HKCU " ${ARP}" " EstimatedSize" " $GetInstalledSize.total"
159+
160+ ; no modify or repair functionality given
161+ WriteRegDWORD HKCU " ${ARP}" " NoModify" 1
162+ WriteRegDWORD HKCU " ${ARP}" " NoRepair" 1
109163SectionEnd
110164
111165
166+ ; --------------------------------
167+ ; Section - Install Music assets, optional, can be selected by user if he wants to have music
168+
169+ Section " Music" Music
170+ ; install music assets (these are larger)
171+ SetOutPath " $INSTDIR\assets\music"
172+ File /r " ${PROJECT_SOURCE_DIR}\assets\music\*.*"
173+
174+ ; store that this is installed
175+ WriteRegDWORD HKCU " Software\${NAME}" " MusicInstalled" 1
176+ SectionEnd
177+
112178
113179; --------------------------------
114180; Section - Install Binary helper, optional, can be selected by user if he wants to have one
@@ -131,13 +197,14 @@ SectionEnd
131197
132198; Language strings
133199LangString DESC_CoreApp ${LANG_ENGLISH} " Install Core App"
134- LangString DESC_BinaryFiles ${LANG_ENGLISH} " Install (Optional) Additional Binaries"
135-
200+ LangString DESC_BinaryFiles ${LANG_ENGLISH} " Install Additional Binaries"
201+ LangString DESC_Music ${LANG_ENGLISH} " Install Music Assets "
136202
137203; Assign language strings to sections
138204!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
139205 !insertmacro MUI_DESCRIPTION_TEXT ${CoreApp} $(DESC_CoreApp)
140206 !insertmacro MUI_DESCRIPTION_TEXT ${AdditionalBinaries} $(DESC_BinaryFiles)
207+ !insertmacro MUI_DESCRIPTION_TEXT ${Music} $(DESC_Music)
141208!insertmacro MUI_FUNCTION_DESCRIPTION_END
142209
143210; --------------------------------
@@ -204,4 +271,7 @@ Section "Uninstall"
204271
205272 ; delete the whole reg key
206273 DeleteRegKey HKCU " Software\${NAME}"
274+
275+ ; delete the whole reg keyfor the uninstaller
276+ DeleteRegKey HKCU " ${ARP}"
207277SectionEnd
0 commit comments