forked from syvaidya/openstego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.nsi
227 lines (176 loc) · 8.01 KB
/
installer.nsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
;----------------------------------------------------------------------------------------
; Steganography utility to hide messages into cover files
; Author: Samir Vaidya (mailto:[email protected])
; Copyright (c) 2007-2017 Samir Vaidya
;----------------------------------------------------------------------------------------
!define JRE_DOWNLOAD_URL "http://www.java.com/getjava/"
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\win-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\win-uninstall.ico"
!include MUI2.nsh
!include "FileFunc.nsh"
;Macro to determine whether installation should be for All Users or Current User
!macro DETERMINE_CONTEXT
UserInfo::getAccountType
Pop $0
StrCmp $0 "Admin" +3
SetShellVarContext current
Goto +2
SetShellVarContext all
!macroend
!macro READ_REGISTRY ret ctx node key
SetRegView 32
ReadRegStr ${ret} "${ctx}" "${node}" "${key}"
StrCmp ${ret} "" 0 +2
return
SetRegView 64
ReadRegStr ${ret} "${ctx}" "${node}" "${key}"
!macroend
;----------------------------------------------------------------------------------------
;General
;Name and file
Name "${AppName}"
OutFile "${AppDir}/../Setup-${AppName}-${AppVersion}.exe"
SetCompressor /SOLID LZMA
;Default installation folder
InstallDir "$PROGRAMFILES\${AppName}"
;Request application privileges for Windows Vista
RequestExecutionLevel highest
;----------------------------------------------------------------------------------------
;Interface Settings
!define MUI_ABORTWARNING
;----------------------------------------------------------------------------------------
;Pages
;!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "LICENSE"
Page custom CheckInstalledJRE
;!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
;!insertmacro MUI_PAGE_FINISH
;!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;!insertmacro MUI_UNPAGE_FINISH
;----------------------------------------------------------------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;----------------------------------------------------------------------------------------
;Installer Sections
Section "${AppName}"
!insertmacro DETERMINE_CONTEXT
SetOutPath "$INSTDIR"
File /r ${AppDir}\lib
File ${AppDir}\openstego.bat
File ${AppDir}\openstego.ico
File ${AppDir}\README
File ${AppDir}\LICENSE
;Write the uninstall keys for Windows
WriteRegStr SHELL_CONTEXT "Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppName}" "DisplayName" "${AppName}"
WriteRegStr SHELL_CONTEXT "Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppName}" "DisplayVersion" "${AppVersion}"
WriteRegStr SHELL_CONTEXT "Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppName}" "DisplayIcon" "$INSTDIR\openstego.ico"
WriteRegStr SHELL_CONTEXT "Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppName}" "UninstallString" '"$INSTDIR\Uninstall.exe"'
WriteRegStr SHELL_CONTEXT "Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppName}" "Publisher" "www.openstego.com"
WriteRegStr SHELL_CONTEXT "Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppName}" "URLInfoAbout" "http://www.openstego.com"
WriteRegDWORD SHELL_CONTEXT "Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppName}" "NoModify" 1
WriteRegDWORD SHELL_CONTEXT "Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppName}" "NoRepair" 1
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppName}" "EstimatedSize" "$0"
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd
Section "Start Menu Shortcuts"
!insertmacro DETERMINE_CONTEXT
CreateDirectory "$SMPROGRAMS\${AppName}"
CreateShortCut "$SMPROGRAMS\${AppName}\Run OpenStego.lnk" "javaw.exe" "-Xmx1024M -jar .\lib\openstego.jar" "$INSTDIR\openstego.ico" 0
CreateShortCut "$SMPROGRAMS\${AppName}\Uninstall OpenStego.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
SectionEnd
;----------------------------------------------------------------------------------------
;Language strings
LangString JRECheckFailed ${LANG_ENGLISH} "${AppName} needs Java Runtime Environment (JRE) version ${RequiredJREVersion} or above to run properly.$\n$\nWould you like to download it now? (Please restart this installer after installing Java).$\n$\nYou can also skip this step by clicking No."
LangString InstallWithoutJRE ${LANG_ENGLISH} "${AppName} will install even though you do not have required version of Java installed. Please don't complain later if it doesn't work."
;----------------------------------------------------------------------------------------
;Uninstaller Section
Section "Uninstall"
!insertmacro DETERMINE_CONTEXT
DeleteRegKey SHELL_CONTEXT "Software\Microsoft\Windows\CurrentVersion\Uninstall\${AppName}"
RMDir /r "$INSTDIR\lib"
Delete "$INSTDIR\openstego.bat"
Delete "$INSTDIR\openstego.ico"
Delete "$INSTDIR\README"
Delete "$INSTDIR\LICENSE"
Delete "$INSTDIR\Uninstall.exe"
RMDir "$INSTDIR"
;Remove shortcuts, if any
RMDir /r "$SMPROGRAMS\${AppName}"
SectionEnd
;----------------------------------------------------------------------------------------
;Helper functions to check installed JRE version
Function CheckInstalledJRE
Push "${RequiredJREVersion}"
Call DetectJRE
Exch $0 ; Get return value from stack
StrCmp $0 "0" AbortInstall
StrCmp $0 "-1" AbortInstall
Goto JREAlreadyInstalled
AbortInstall:
MessageBox MB_ICONEXCLAMATION|MB_YESNO $(JRECheckFailed) IDNO +3
ExecShell open "${JRE_DOWNLOAD_URL}"
Quit
MessageBox MB_ICONEXCLAMATION $(InstallWithoutJRE)
JREAlreadyInstalled:
Pop $0 ; Restore $0
Return
FunctionEnd
; Returns: 0 - JRE not found. -1 - JRE found but too old. Otherwise - Path to JAVA EXE
; DetectJRE. Version requested is on the stack.
; Returns (on stack) "0" on failure (java too old or not installed), otherwise path to java interpreter
; Stack value will be overwritten!
Function DetectJRE
Exch $0 ; Get version requested
; Now the previous value of $0 is on the stack, and the asked for version of JDK is in $0
Push $1 ; $1 = Java version string
Push $2 ; $2 = Javahome
Push $3 ; $3 and $4 are used for checking the major/minor version of java
Push $4
!insertmacro READ_REGISTRY $1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
StrCmp $1 "" DetectTry2
!insertmacro READ_REGISTRY $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$1" "JavaHome"
StrCmp $2 "" DetectTry2
Goto GetJRE
DetectTry2:
!insertmacro READ_REGISTRY $1 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion"
StrCmp $1 "" NoFound
!insertmacro READ_REGISTRY $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit\$1" "JavaHome"
StrCmp $2 "" NoFound
GetJRE:
; $0 = version requested. $1 = version found. $2 = javaHome
IfFileExists "$2\bin\java.exe" 0 NoFound
StrCpy $3 $0 1 ; Get major version. Example: $1 = 1.5.0, now $3 = 1
StrCpy $4 $1 1 ; $3 = major version requested, $4 = major version found
IntCmp $4 $3 0 FoundOld FoundNew
StrCpy $3 $0 1 2
StrCpy $4 $1 1 2 ; Same as above. $3 is minor version requested, $4 is minor version installed
IntCmp $4 $3 FoundNew FoundOld FoundNew
NoFound:
Push "0"
Goto DetectJREEnd
FoundOld:
Push "-1"
Goto DetectJREEnd
FoundNew:
Push "$2\bin\java.exe"
Goto DetectJREEnd
DetectJREEnd:
; Top of stack is return value, then r4,r3,r2,r1
Exch ; => r4,rv,r3,r2,r1,r0
Pop $4 ; => rv,r3,r2,r1r,r0
Exch ; => r3,rv,r2,r1,r0
Pop $3 ; => rv,r2,r1,r0
Exch ; => r2,rv,r1,r0
Pop $2 ; => rv,r1,r0
Exch ; => r1,rv,r0
Pop $1 ; => rv,r0
Exch ; => r0,rv
Pop $0 ; => rv
FunctionEnd