1- !include " MUI2.nsh"
1+ # NSIS docs: http://nsis.sourceforge.net/Docs
2+ ; # MultiUser docs: http://nsis.sourceforge.net/Docs/MultiUser/Readme.html
3+ # MUI2 docs: http://nsis.sourceforge.net/Docs/Modern%20UI%202/Readme.html
4+
5+ !include " LogicLib.nsh"
26!include " FileFunc.nsh"
37
4- Name " Koala"
5- BrandingText " koala-app.com"
8+ ; !define MULTIUSER_EXECUTIONLEVEL Highest
9+ ; !define MULTIUSER_MUI
10+ ; !define MULTIUSER_INSTALLMODE_COMMANDLINE
11+ ; !define MULTIUSER_INSTALLMODE_INSTDIR "Koala"
12+ ; !define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_KEY "Software\Koala"
13+ ; !define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUENAME "InstallLocation"
14+ ; !include "MultiUser.nsh"
15+ !include " MUI2.nsh"
616
717# Add/Remove Programs
818!define ARP " Software\Microsoft\Windows\CurrentVersion\Uninstall\Koala"
919
10- # set the icon
11- !define MUI_ICON " icon.ico"
20+ Name " Koala"
21+ BrandingText " koala-app.com"
22+
23+ VIAddVersionKey /LANG= 0 " ProductName" " Koala"
24+ VIAddVersionKey /LANG= 0 " Comments" " A cool tool for web developers"
25+ VIAddVersionKey /LANG= 0 " CompanyName" " koala-app.com"
26+ VIAddVersionKey /LANG= 0 " FileDescription" " Koala installer"
27+ VIAddVersionKey /LANG= 0 " FileVersion" " 2017.11.19"
28+ VIAddVersionKey /LANG= 0 " ProductVersion" " 2.3.0"
29+ VIProductVersion 2.3 .0.0
30+ VIFileVersion 2017.11 .19.0
31+
32+ SetCompressor /SOLID /FINAL lzma
1233
1334# define the resulting installer's name:
1435OutFile " ..\dist\KoalaSetup.exe"
1536
16- # set the installation directory
37+ # Default installation folder
1738InstallDir " $PROGRAMFILES\Koala\"
1839
19- # app dialogs
40+ # Get installation folder from registry if available
41+ InstallDirRegKey HKLM " ${ARP}" " InstallLocation"
42+
43+ Var StartMenuFolder
44+
45+ # The icon for the installer.
46+ !define MUI_ICON " icon.ico"
47+
48+ # Show a message box with a warning when the user wants to close the installer.
49+ !define MUI_ABORTWARNING
50+
51+ # Pages
2052!insertmacro MUI_PAGE_WELCOME
53+ ; !insertmacro MULTIUSER_PAGE_INSTALLMODE
54+
55+ !define MUI_PAGE_CUSTOMFUNCTION_LEAVE VerifyDir
2156!insertmacro MUI_PAGE_DIRECTORY
57+
58+ !define MUI_STARTMENUPAGE_REGISTRY_ROOT " HKLM"
59+ !define MUI_STARTMENUPAGE_REGISTRY_KEY " ${ARP}"
60+ !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME " Start Menu Folder"
61+ !insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder
62+
2263!insertmacro MUI_PAGE_INSTFILES
2364
2465!define MUI_FINISHPAGE_RUN_TEXT " Start Koala"
2566!define MUI_FINISHPAGE_RUN " $INSTDIR\Koala.exe"
26-
2767!insertmacro MUI_PAGE_FINISH
68+
69+ !insertmacro MUI_UNPAGE_WELCOME
70+ !insertmacro MUI_UNPAGE_CONFIRM
71+ !insertmacro MUI_UNPAGE_INSTFILES
72+ !insertmacro MUI_UNPAGE_FINISH
73+
2874!insertmacro MUI_LANGUAGE " English"
2975
76+ ; Function .onInit
77+ ; !insertmacro MULTIUSER_INIT
78+ ; FunctionEnd
79+
80+ ; Function un.onInit
81+ ; !insertmacro MULTIUSER_UNINIT
82+ ; FunctionEnd
83+
84+ # From http://nsis.sourceforge.net/Check_if_dir_is_empty
85+ # And https://stackoverflow.com/a/29569614/2168921
86+ Function VerifyDir
87+ Push $INSTDIR
88+ Call isEmptyDir
89+ Pop $0
90+ ${If} $0 == 0
91+ # ${If} ${FileExists} "$INSTDIR\*"
92+ # MessageBox MB_ICONEXCLAMATION|MB_YESNO \
93+ # `"$INSTDIR" already exists, delete it's content and continue installing?` \
94+ # /SD IDYES \
95+ # IDYES yep
96+ MessageBox MB_ICONEXCLAMATION |MB_YESNO \
97+ " The selected directory already exists and is not empty.$\n \
98+ This installer will delete all files and folders in that directory before \
99+ installing Koala!$\n \
100+ Do you want to continue?" \
101+ /SD IDYES \
102+ IDYES yep
103+ Abort
104+ yep:
105+ ${EndIf}
106+ FunctionEnd
107+
30108# default section start
31109Section
110+ ReadRegStr $R0 HKLM " ${ARP}" " UninstallString"
111+ ${If} $R0 != " "
112+ MessageBox MB_OKCANCEL |MB_ICONEXCLAMATION \
113+ " Koala is already installed. $\n$\n Click `OK` to remove the previous version or `Cancel` to cancel this upgrade." \
114+ IDOK uninst
115+ Abort
32116
33- # delete the installed files
34- RMDir /r $INSTDIR
117+ ; Run the uninstaller
118+ uninst:
119+ ClearErrors
120+ Exec $R0
121+ ${EndIf}
122+
123+ RMDir /r " $INSTDIR"
35124
36125 # define the path to which the installer should install
37- SetOutPath $INSTDIR
126+ SetOutPath " $INSTDIR"
38127
39128 # specify the files to go in the output path
40129 File /r ..\build\Koala\win32\*
@@ -48,7 +137,7 @@ Section
48137 # add uninstall information to Add/Remove Programs
49138 WriteRegStr HKLM " ${ARP}" " DisplayName" " Koala -- A cool tool for web developers"
50139 WriteRegStr HKLM " ${ARP}" " InstallLocation" " $INSTDIR"
51- WriteRegStr HKLM " ${ARP}" " DisplayIcon" " $\" $ INSTDIR\Koala.exe$\ " ,0"
140+ WriteRegStr HKLM " ${ARP}" " DisplayIcon" ` "$ INSTDIR\Koala.exe",0`
52141 WriteRegStr HKLM " ${ARP}" " Publisher" " koala-app.com"
53142 WriteRegStr HKLM " ${ARP}" " URLUpdateInfo" " koala-app.com"
54143 WriteRegStr HKLM " ${ARP}" " URLInfoAbout" " koala-app.com"
@@ -59,28 +148,62 @@ Section
59148 WriteRegDWORD HKLM " ${ARP}" " NoModify" " 1"
60149 WriteRegDWORD HKLM " ${ARP}" " NoRepair" " 1"
61150 WriteRegDWORD HKLM " ${ARP}" " EstimatedSize" " $0"
62- WriteRegStr HKLM " ${ARP}" " UninstallString" " $\" $ INSTDIR\Uninstall Koala.exe$\" "
63- WriteRegStr HKLM " ${ARP}" " QuietUninstallString" " $\" $ INSTDIR\Uninstall Koala.exe$\ " /S"
151+ WriteRegStr HKLM " ${ARP}" " UninstallString" ` $ INSTDIR\Uninstall Koala.exe" `
152+ WriteRegStr HKLM " ${ARP}" " QuietUninstallString" ` "$ INSTDIR\Uninstall Koala.exe" /S`
64153
65154 # create shortcuts in the start menu and on the desktop
66- CreateShortCut " $SMPROGRAMS\Koala.lnk" " $INSTDIR\Koala.exe"
67- CreateShortCut " $SMPROGRAMS\Uninstall Koala.lnk" " $INSTDIR\Uninstall Koala.exe"
68- CreateShortCut " $DESKTOP\Koala.lnk" " $INSTDIR\Koala.exe"
155+ !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
156+
157+ CreateDirectory " $SMPROGRAMS\$StartMenuFolder"
158+ CreateShortcut " $SMPROGRAMS\$StartMenuFolder\Koala.lnk" " $INSTDIR\Koala.exe"
159+ CreateShortcut " $SMPROGRAMS\$StartMenuFolder\Uninstall Koala.lnk" " $INSTDIR\Uninstall Koala.exe"
160+ CreateShortcut " $DESKTOP\Koala.lnk" " $INSTDIR\Koala.exe"
161+
162+ !insertmacro MUI_STARTMENU_WRITE_END
69163
70164SectionEnd
71165
72166# create a section to define what the uninstaller does
73167Section " Uninstall"
74168
75169 # delete the installed files
76- RMDir /r $INSTDIR
170+ RMDir /r " $INSTDIR"
77171
78172 # delete the name from Add/Remove Programs when your uninstaller completes
79173 DeleteRegKey HKLM " ${ARP}"
80174
81175 # delete the shortcuts
82- Delete " $SMPROGRAMS\Koala.lnk"
83- Delete " $SMPROGRAMS\Uninstall Koala.lnk"
176+ !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
177+
178+ Delete " $SMPROGRAMS\$StartMenuFolder\Koala.lnk"
179+ Delete " $SMPROGRAMS\$StartMenuFolder\Uninstall Koala.lnk"
180+ RMDir " $SMPROGRAMS\$StartMenuFolder"
84181 Delete " $DESKTOP\Koala.lnk"
85182
86183SectionEnd
184+
185+ # From http://nsis.sourceforge.net/Check_if_dir_is_empty
186+ Function isEmptyDir
187+ # Stack -> # Stack: <directory>
188+ Exch $0 # Stack: $0
189+ Push $1 # Stack: $1, $0
190+ FindFirst $0 $1 " $0\*.*"
191+ strcmp $1 " ." 0 _notempty
192+ FindNext $0 $1
193+ strcmp $1 " .." 0 _notempty
194+ ClearErrors
195+ FindNext $0 $1
196+ IfErrors 0 _notempty
197+ FindClose $0
198+ Pop $1 # Stack: $0
199+ StrCpy $0 1
200+ Exch $0 # Stack: 1 (true)
201+ goto _end
202+ _notempty:
203+ FindClose $0
204+ ClearErrors
205+ Pop $1 # Stack: $0
206+ StrCpy $0 0
207+ Exch $0 # Stack: 0 (false)
208+ _end:
209+ FunctionEnd
0 commit comments