Skip to content

Commit 9451cac

Browse files
committed
Working alpha version
1 parent af507cc commit 9451cac

File tree

1 file changed

+118
-60
lines changed

1 file changed

+118
-60
lines changed

cmder_inst.nsi

Lines changed: 118 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,20 @@
3030

3131
!include "MUI2.nsh"
3232
!include "FileFunc.nsh"
33+
!include "x64.nsh"
34+
35+
36+
;--------------------------------
37+
; UAC
38+
39+
; Request application privileges
40+
RequestExecutionLevel admin
41+
3342

3443
;--------------------------------
3544
; General
3645

37-
!define INSTALLER_VERSION "0.0.1"
46+
!define INSTALLER_VERSION "0.0.1-alpha"
3847
!define CMDER_VERSION "1.3.0"
3948
!define APP_NAME "Cmder"
4049
!define CMDER_DLURL "http://github.com/cmderdev/cmder/releases/download/v${CMDER_VERSION}/cmder_mini.zip"
@@ -44,18 +53,16 @@
4453
BrandingText "${APP_INSTALLER_TEXT}"
4554

4655
; Name / File
47-
Name "${APP_NAME} v${CMDER_VERSION} Installer"
56+
Name "${APP_NAME} v${CMDER_VERSION}"
4857
OutFile "cmder_inst_${INSTALLER_VERSION}.exe"
49-
58+
5059
; Default Installation Folder
51-
InstallDir $PROGRAMFILES\Cmder
60+
InstallDir $PROGRAMFILES\${APP_NAME}
5261

53-
; Registry Key to check for directory
62+
; Registry Set Up
5463
!define REGLOC "Software\${APP_NAME}"
55-
InstallDirRegKey HKLM "${REGLOC}" "InstallPath"
56-
57-
; Request application privileges for Windows Vista
58-
RequestExecutionLevel admin
64+
!define REGROOT "HKLM"
65+
InstallDirRegKey ${REGROOT} "${REGLOC}" "InstallPath"
5966

6067
; Uninstall Info
6168
!define ARP "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}"
@@ -65,20 +72,16 @@
6572
ShowUninstDetails show
6673
SpaceTexts none
6774

68-
;--------------------------------
69-
; Variables
70-
71-
Var STARTMENUFOLDER
7275

7376
;--------------------------------
7477
; Interface Configuration
7578

7679
!define MUI_WELCOMEFINISHPAGE_BITMAP "img\cmder-side.bmp"
77-
!define MUI_ABORTWARNING
7880
!define MUI_ICON "img\cmder.ico"
7981
!define MUI_UNICON "img\cmder.ico"
8082

81-
!define MUI_WELCOMEPAGE_TITLE "Welcome to the Cmder set up for Windows."
83+
!define MUI_WELCOMEPAGE_TITLE "Welcome to the ${APP_NAME} v${CMDER_VERSION} Installation Tool for Windows."
84+
!define MUI_WELCOMEPAGE_TITLE_3LINES
8285
!define MUI_WELCOMEPAGE_TEXT "This wizard will guide you through the installation the latest version of Cmder \
8386
for Windows.$\r$\n$\r$\nClick Next to continue."
8487

@@ -88,32 +91,44 @@
8891

8992
!define MUI_COMPONENTSPAGE_NODESC
9093

91-
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "${APP_NAME}"
92-
9394
!define MUI_FINISHPAGE_NOAUTOCLOSE
9495
!define MUI_FINISHPAGE_TITLE "Congratulations! You have installed Cmder."
95-
!define MUI_FINISHPAGE_TEXT "You can now use Cmder. Start menu and/or desktop shortcuts have been created if you chose to do so."
96+
!define MUI_FINISHPAGE_TITLE_3LINES
97+
!define MUI_FINISHPAGE_TEXT "You can now use Cmder. Start menu and/or desktop shortcuts have been created \
98+
if you chose to do so.$\r$\n$\r$\nPLEASE NOTE THAT YOU MUST EITHER RUN CMDER WITH THE CHECKBOX BELOW, \
99+
OR RUN AS ADMINISTRATOR FOR THE FIRST TIME."
96100
!define MUI_FINISHPAGE_RUN_TEXT "Run ${APP_NAME} v${CMDER_VERSION}"
97101
!define MUI_FINISHPAGE_RUN "$INSTDIR\${APP_NAME}.exe"
98-
!define MUI_FINISHPAGE_RUN_NOTCHECKED
99102

100-
!define MUI_STARTMENUPAGE_REGISTRY_ROOT
103+
!define MUI_FINISHPAGE_NOREBOOTSUPPORT
104+
105+
!define MUI_ABORTWARNING
106+
!define MUI_ABORTWARNING_TEXT "Are you sure you want to cancel the installation of ${APP_NAME} v${CMDER_VERSION}?"
107+
!define MUI_ABORTWARNING_CANCEL_DEFAULT
101108

102-
!define MUI_UNCONFIRMPAGE_TEXT_TOP "All files will be removed from the install directory."
109+
!define MUI_UNCONFIRMPAGE_TEXT_TOP "This wizard will guide you through the uninstallation of ${APP_NAME} \
110+
v${CMDER_VERSION}.$\r$\n$\r$\nBefore starting the uninstallation, please make sure that ${APP_NAME} \
111+
is not running.$\r$\n$\r$\nClick Next to continue."
112+
!define MUI_UNFINISHPAGE_NOAUTOCLOSE
103113

104114
;--------------------------------
105115
; Pages
106116

117+
; Installer Pages
118+
!define MUI_PAGE_CUSTOMFUNCTION_PRE wel_pre
107119
!insertmacro MUI_PAGE_WELCOME
108120
!insertmacro MUI_PAGE_LICENSE LICENSE
121+
!define MUI_PAGE_CUSTOMFUNCTION_PRE dir_pre
109122
!insertmacro MUI_PAGE_DIRECTORY
110123
!insertmacro MUI_PAGE_COMPONENTS
111-
!insertmacro MUI_PAGE_STARTMENU Application $STARTMENUFOLDER
112124
!insertmacro MUI_PAGE_INSTFILES
113125
!insertmacro MUI_PAGE_FINISH
114126

127+
; Uninstaller Pages
115128
!insertmacro MUI_UNPAGE_CONFIRM
129+
!define MUI_PAGE_CUSTOMFUNCTION_PRE un.dir_pre
116130
!insertmacro MUI_UNPAGE_INSTFILES
131+
!insertmacro MUI_UNPAGE_FINISH
117132

118133
;--------------------------------
119134
; Languages
@@ -129,7 +144,9 @@
129144

130145
Section "!Cmder ${CMDER_VERSION}" CmderInst
131146
SectionIn 1 RO
147+
132148
SetOutPath "$INSTDIR"
149+
DetailPrint "Setting InstallDir: $INSTDIR"
133150

134151
; ADD FILES
135152
DetailPrint "Downloading latest Cmder (mini) from ${CMDER_DLURL}"
@@ -140,61 +157,64 @@
140157
Abort
141158

142159
dlok:
160+
DetailPrint "Download OK"
143161
!insertmacro ZIPDLL_EXTRACT "$TEMP/cmder_mini.zip" "$INSTDIR" "<ALL>"
144162
Pop $0
163+
DetailPrint "Unzipping Files"
145164
StrCmp "$0" "success" unzipok
146165
DetailPrint "Failed to Unzip Cmder Files"
147166
Abort
148167

149168

150169
unzipok:
170+
DetailPrint "Unzip OK"
171+
; Delete Zip
172+
DetailPrint "Removing Temp File"
173+
delete $TEMP/cmder_mini.zip
151174

175+
DetailPrint "Writing Registry Keys"
152176
; Store Installation Folder
153-
WriteRegStr HKLM "${REGLOC}" "InstallPath" $INSTDIR
154-
WriteRegStr HKLM "${REGLOC}" "Version" ${CMDER_VERSION}
177+
WriteRegStr ${REGROOT} "${REGLOC}" "InstallPath" $INSTDIR
178+
WriteRegStr ${REGROOT} "${REGLOC}" "Version" ${CMDER_VERSION}
155179

156-
; Start Menu items
157-
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
158-
CreateDirectory "$SMPROGRAMS\$STARTMENUFOLDER"
159-
CreateShortCut "$SMPROGRAMS\$STARTMENUFOLDER\${APP_NAME}" "$INSTDIR\${APP_NAME}.exe" "" "$INSTDIR\icons\cmder.ico"
160-
CreateShortCut "$SMPROGRAMS\$STARTMENUFOLDER\Uninstall.lnk" "$INSTDIR\uninstall.exe"
161-
!insertmacro MUI_STARTMENU_WRITE_END
180+
; Create Uninstaller
181+
WriteUninstaller "$INSTDIR\Uninstall.exe"
162182

163183
; Write Uninstaller Registry Keys
164-
WriteRegStr HKLM "${ARP}" "DisplayName" "Cmder"
165-
WriteRegExpandStr HKLM "${ARP}" "UninstallString" "$INSTDIR\uninstall.exe"
166-
WriteRegExpandStr HKLM "${ARP}" "QuietUninstallString" "$INSTDIR\uninstall.exe /S"
167-
WriteRegExpandStr HKLM "${ARP}" "InstallLocation" "$INSTDIR"
168-
WriteRegStr HKLM "${ARP}" "DisplayIcon" "$INSTDIR\icons\cmder.ico"
169-
WriteRegStr HKLM "${ARP}" "DisplayVersion" "${CMDER_VERSION}"
170-
WriteRegStr HKLM "${ARP}" "URLInfoAbout" "${CMDER_URL}"
171-
WriteRegStr HKLM "${ARP}" "NoModify" 1
172-
WriteRegStr HKLM "${ARP}" "NoRepair" 1
184+
WriteRegStr ${REGROOT} "${ARP}" "DisplayName" "Cmder"
185+
WriteRegExpandStr ${REGROOT} "${ARP}" "UninstallString" "$INSTDIR\uninstall.exe"
186+
WriteRegExpandStr ${REGROOT} "${ARP}" "QuietUninstallString" "$INSTDIR\uninstall.exe /S"
187+
WriteRegExpandStr ${REGROOT} "${ARP}" "InstallLocation" "$INSTDIR"
188+
WriteRegStr ${REGROOT} "${ARP}" "DisplayIcon" "$INSTDIR\icons\${APP_NAME}.ico"
189+
WriteRegStr ${REGROOT} "${ARP}" "DisplayVersion" "${CMDER_VERSION}"
190+
WriteRegStr ${REGROOT} "${ARP}" "URLInfoAbout" "${CMDER_URL}"
191+
WriteRegStr ${REGROOT} "${ARP}" "NoModify" 1
192+
WriteRegStr ${REGROOT} "${ARP}" "NoRepair" 1
173193

174194
; Get Size
175195
${GetSize} "$INSTDIR" "/S=OK" $0 $1 $2
176-
IntFmt $0 "0x$08X" $0
177-
WriteRegDWORD HKLM "${ARP}" "EstimatedSize" "$0"
178-
179-
; Create Uninstaller
180-
WriteUninstaller "$INSTDIR\Uninstall.exe"
196+
IntFmt $0 "0x%08X" $0
197+
WriteRegDWORD ${REGROOT} "${ARP}" "EstimatedSize" "$0"
181198

182199
SectionEnd
183200

184201
; Shortcuts
185202
SectionGroup /e "Shortcuts"
186203
Section "Start Menu"
187-
; Start Menu items
188-
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
189-
CreateDirectory "$SMPROGRAMS\$STARTMENUFOLDER"
190-
CreateShortCut "$SMPROGRAMS\$STARTMENUFOLDER\${APP_NAME}.lnk" "$INSTDIR\${APP_NAME}.exe" "" "$INSTDIR\icons\cmder.ico"
191-
CreateShortCut "$SMPROGRAMS\$STARTMENUFOLDER\Uninstall.lnk" "$INSTDIR\uninstall.exe"
192-
!insertmacro MUI_STARTMENU_WRITE_END
204+
DetailPrint "Writing StartMenu Shortcut"
205+
; Start Menu item
206+
CreateShortCut "$SMPROGRAMS\${APP_NAME}.lnk" "$INSTDIR\${APP_NAME}.exe" "" "$INSTDIR\icons\${APP_NAME}.ico" 0
207+
193208
SectionEnd
194209

195210
Section /o "Create Desktop Icon"
196211
;Create Desktop Shortcut
197-
CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${APP_NAME}.exe" ""
212+
DetailPrint "Writing Desktop Shorcut"
213+
SetOutPath $INSTDIR
214+
SetShellVarContext all
215+
SetOverwrite on
216+
CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${APP_NAME}.exe" "" "$INSTDIR\icons\${APP_NAME}.ico" 0
217+
SetOverwrite off
198218
SectionEnd
199219
SectionGroupEnd
200220

@@ -203,13 +223,13 @@
203223

204224
; Open Cmder Here
205225
Section 'Add "Open Cmder Here"'
206-
226+
DetailPrint "Adding Explorer Integrations"
207227
WriteRegStr HKCR "Directory\Background\shell\${APP_NAME}" "" "Open Cmder Here"
208228
WriteRegStr HKCR "Directory\Background\shell\${APP_NAME}" "Icon" "$INSTDIR\icons\cmder.ico"
209229
WriteRegStr HKCR "Directory\Background\shell\${APP_NAME}\command" "" '"$INSTDIR\${APP_NAME}.exe" "%V"'
210230

211231
WriteRegStr HKCR "Directory\shell\${APP_NAME}" "" "Open Cmder Here"
212-
WriteRegStr HkCR "Directory\shell\${APP_NAME}" "Icon" "$INSTDIR\icons\cmder.ico"
232+
WriteRegStr HKCR "Directory\shell\${APP_NAME}" "Icon" "$INSTDIR\icons\cmder.ico"
213233
WriteRegStr HKCR "Directory\shell\${APP_NAME}\command" "" '"$INSTDIR\${APP_NAME}.exe" "%1"'
214234

215235
SectionEnd
@@ -223,15 +243,17 @@
223243

224244
Section "Uninstall"
225245

226-
; Remove Start Menu Item
227-
delete "$SMPROGRAMS\$STARTMENUFOLDER\${APP_NAME}.lnk"
228-
delete "$SMPROGRAMS\$STARTMENUFOLDER\Uninstall.lnk"
229-
rmDir "$SMPROGRAMS\$STARTMENUFOLDER"
230-
246+
; Remove Start Menu Items
247+
SetShellVarContext all
248+
DetailPrint "Removing StartMenu Item"
249+
delete "$SMPROGRAMS\${APP_NAME}.lnk"
250+
231251
; Remove Desktop Link
252+
DetailPrint "Removing Desktop Shortcut"
232253
delete $DESKTOP\${APP_NAME}.lnk
233254

234255
; Remove Files
256+
DetailPrint "Removing Files"
235257
rmDir /r "$INSTDIR\bin"
236258
rmDir /r "$INSTDIR\config"
237259
rmDir /r "$INSTDIR\icons"
@@ -247,16 +269,18 @@
247269
rmDir $INSTDIR
248270

249271
; Remove Registry Keys
250-
DeleteRegKey HKLM "${REGLOC}"
272+
DetailPrint "Removing Registry Keys"
273+
DeleteRegKey ${REGROOT} "${REGLOC}"
251274
DeleteRegKey HKCR "Directory\Background\shell\${APP_NAME}"
252275
DeleteRegKey HKCR "Directory\shell\${APP_NAME}"
253-
DeleteRegKey HKLM "${ARP}"
276+
DeleteRegKey ${REGROOT} "${ARP}"
254277

255278
SectionEnd
256279

257280

258281
;--------------------------------
259282
; Extra Functions
283+
260284
Function .onInit
261285
InitPluginsDir
262286
File "/oname=$PluginsDir\spltmp.bmp" "img\cmder-splash.bmp"
@@ -269,4 +293,38 @@
269293

270294
FunctionEnd
271295

296+
297+
Function wel_pre
298+
messagebox MB_OK|MB_ICONEXCLAMATION|MB_TOPMOST|MB_SETFOREGROUND "NOTE: Please remember to run Cmder \
299+
from the final installation page OR run as administrator the first time."
300+
FunctionEnd
301+
302+
303+
Function dir_pre
304+
; x64 Setup
305+
${If} ${RunningX64}
306+
DetailPrint "Installer running on 64-bit host"
307+
308+
; Disable registry redirection
309+
SetRegView 64
310+
311+
; Set Install Dir Root
312+
StrCpy $INSTDIR "$PROGRAMFILES64\${APP_NAME}"
313+
${EndIf}
314+
FunctionEnd
315+
316+
Function un.dir_pre
317+
; x64 Setup
318+
${If} ${RunningX64}
319+
DetailPrint "Installer running on 64-bit host"
320+
321+
; Disable registry redirection
322+
SetRegView 64
323+
324+
; Set Install Dir Root
325+
StrCpy $INSTDIR "$PROGRAMFILES64\${APP_NAME}"
326+
${EndIf}
327+
FunctionEnd
328+
329+
272330
; END NSIS Script

0 commit comments

Comments
 (0)