forked from Pich78/docfetcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-win-installer.nsi
executable file
·227 lines (196 loc) · 7.55 KB
/
build-win-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
; NSIS script for building the Windows installer
;
; This script must be run after running build.py, because it expects to find the
; DocFetcher jar in the build folder.
;
; DEPENDENCIES
; All dependencies of this script can be found in dev/nsis-dependencies, BUT
; those files might be out of date, so try the latest versions of the
; dependencies first, if any are available. They can be found here:
; - http://nsis.sourceforge.net/Inetc_plug-in
; - http://nsis.sourceforge.net/Java_Runtime_Environment_Dynamic_Installer
; - https://nsis.sourceforge.io/ApplicationID_plug-in
; - https://nsis.sourceforge.io/Processes_plug-in
; In case of errors, try updating NSIS. Also, in the local JREDyna_Inetc.nsh
; file everything related to CUSTOM_PAGE_JREINFO was deleted in order to work
; around compilation errors which may or may not show up in your case.
RequestExecutionLevel admin ; without this, the startmenu links won't be removed on Windows Vista and later
SetCompress force
SetCompressor /FINAL zlib
!define /file VERSION "current-version.txt"
!define PORTABLE_PATH build\DocFetcher-${VERSION}
!define JRE_VERSION "1.7"
!define JRE_URL "http://javadl.oracle.com/webapps/download/AutoDL?BundleId=216432"
!include "JREDyna_Inetc.nsh"
Name "DocFetcher ${VERSION}"
XPStyle on
OutFile build\docfetcher_${VERSION}_win32_setup.exe
InstallDir $PROGRAMFILES\DocFetcher
Page directory
Page instfiles
Page custom finalPage
UninstPage uninstConfirm
UninstPage instfiles
AllowSkipFiles off
ShowInstDetails show
ShowUninstDetails show
AutoCloseWindow true
!addplugindir dev
!include "FileFunc.nsh"
!include "nsDialogs.nsh"
!insertmacro GetTime
; Follow the list of languages on the wiki:
; http://sourceforge.net/apps/mediawiki/docfetcher/index.php?title=How_to_translate_DocFetcher#Translations_that_are_already_finished_or_in_progress
LoadLanguageFile "${NSISDIR}\Contrib\Language files\English.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\Portuguese.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\German.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\Romanian.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\French.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\Russian.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\Greek.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\Japanese.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\SimpChinese.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\TradChinese.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\Spanish.nlf"
Function .onInit
startinst:
Processes::FindProcess "DocFetcher.exe"
StrCmp $R0 0 done
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION \
"DocFetcher is running! Please close it before reinstalling." \
IDRETRY startinst
Abort
done:
FunctionEnd
Var CHECKBOX
Var boolCHECKBOX
Var Image
Var ImageHandle
; --------------------------------
; The final install page that asks to run the application
Function finalPage
IfRebootFlag 0 noreboot
MessageBox MB_YESNO "A reboot is required to finish the installation.$\n$\n Do you wish to reboot now?" IDNO endfinalpage
Reboot
noreboot:
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 75u 30u 80% 8u "DocFetcher was succesfully installed on your computer."
Pop $0
${NSD_CreateCheckbox} 80u 50u 50% 8u "Run DocFetcher ${VERSION}"
Pop $CHECKBOX
SendMessage $CHECKBOX ${BM_SETCHECK} ${BST_CHECKED} 0
GetFunctionAddress $1 OnCheckbox
nsDialogs::OnClick $CHECKBOX $1
; Add an image
${NSD_CreateBitmap} 0 0 100% 40% ""
Pop $Image
${NSD_SetImage} $Image "$INSTDIR\img\setup.bmp" $ImageHandle
nsDialogs::Show
${NSD_freeImage} $ImageHandle
endfinalpage:
FunctionEnd
Function OnCheckbox
SendMessage $CHECKBOX ${BM_GETSTATE} 0 0 $1
${If} $1 != 520
StrCpy $boolCHECKBOX "True"
${Else}
StrCpy $boolCHECKBOX "False"
${EndIf}
FunctionEnd
Function .onInstSuccess
IfRebootFlag endpage 0
${If} $boolCHECKBOX != "False"
Exec "$INSTDIR\DocFetcher.exe"
${EndIf}
endpage:
FunctionEnd
Function .onInstFailed
DetailPrint " --- "
DetailPrint " Make sure DocFetcher is not running and try installing again."
MessageBox MB_OK|MB_ICONEXCLAMATION "Please restart your computer and try the installation again."
FunctionEnd
Section "DocFetcher"
SetShellVarContext all
Call DownloadAndInstallJREIfNecessary
killdaemon:
Processes::FindProcess "docfetcher-daemon-windows"
StrCmp $R0 0 nodaemon
DetailPrint "Attempting to kill DocFetcher daemon..."
Processes::KillProcess "docfetcher-daemon-windows"
Sleep 250
Goto killdaemon
nodaemon:
; Remove the existing program folder. This is necessary because:
; - Otherwise the uninstaller might not work cleanly.
; - Loading different versions of the same library might crash the program. See bug #3558268.
RMDir /r $INSTDIR
; Copy files
SetOutPath $INSTDIR
File ${PORTABLE_PATH}\*.exe
File ${PORTABLE_PATH}\*.txt
File ${PORTABLE_PATH}\*.py
SetOutPath $INSTDIR\misc
File ${PORTABLE_PATH}\misc\*.bat
File ${PORTABLE_PATH}\misc\*.exe
File ${PORTABLE_PATH}\misc\licenses.zip
File ${PORTABLE_PATH}\misc\paths.txt
SetOutPath $INSTDIR\help
File /r ${PORTABLE_PATH}\help\*.*
SetOutPath $INSTDIR\img
File /r ${PORTABLE_PATH}\img\*.*
SetOutPath $INSTDIR\lang
File /r ${PORTABLE_PATH}\lang\*.*
;SetOutPath $INSTDIR\templates
;File /r ${PORTABLE_PATH}\templates\*.xml
Delete /REBOOTOK "$INSTDIR\lib\net.sourceforge.docfetcher_*.*"
SetOutPath $INSTDIR\lib
File /r /x *.so /x *.dylib /x *linux* /x *macosx* /x *docfetcher*.jar ${PORTABLE_PATH}\lib\*.*
File build\tmp\net.sourceforge.docfetcher*.jar
; Uninstaller
WriteUninstaller $INSTDIR\uninstaller.exe
; Write to registry
Var /GLOBAL regkey
Var /GLOBAL homepage
StrCpy $regkey "Software\Microsoft\Windows\CurrentVersion\Uninstall\DocFetcher"
StrCpy $homepage "http://docfetcher.sourceforge.net"
WriteRegStr HKLM $regkey "DisplayName" "DocFetcher"
WriteRegStr HKLM $regkey "UninstallString" "$INSTDIR\uninstaller.exe"
WriteRegStr HKLM $regkey "InstallLocation" $INSTDIR
WriteRegStr HKLM $regkey "DisplayIcon" "$INSTDIR\DocFetcher.exe,0"
WriteRegStr HKLM $regkey "HelpLink" $homepage
WriteRegStr HKLM $regkey "URLUpdateInfo" $homepage
WriteRegStr HKLM $regkey "URLInfoAbout" $homepage
WriteRegStr HKLM $regkey "DisplayVersion" "${VERSION}"
WriteRegDWORD HKLM $regkey "NoModify" 1
WriteRegDWORD HKLM $regkey "NoRepair" 1
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "DocFetcher-Daemon" "$INSTDIR\docfetcher-daemon-windows.exe"
SetShellVarContext current
; Start menu entries
CreateDirectory $SMPROGRAMS\DocFetcher
CreateShortCut $SMPROGRAMS\DocFetcher\DocFetcher.lnk $INSTDIR\DocFetcher.exe
CreateShortCut "$SMPROGRAMS\DocFetcher\Uninstall DocFetcher.lnk" $INSTDIR\uninstaller.exe
CreateShortCut $SMPROGRAMS\DocFetcher\Readme.lnk $INSTDIR\Readme.txt
ApplicationID::Set "$SMPROGRAMS\DocFetcher\DocFetcher.lnk" "DocFetcher"
; Launch daemon
Exec '"$INSTDIR\docfetcher-daemon-windows.exe"'
SectionEnd
Section "un.Uninstall"
SetShellVarContext all
; Kill daemon
Processes::KillProcess "docfetcher-daemon-windows"
Sleep 1000
; Remove program folder
RMDir /r /REBOOTOK $INSTDIR
; Remove registry key
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\DocFetcher"
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "DocFetcher-Daemon"
SetShellVarContext current
; Remove application data folder
RMDir /r /REBOOTOK $APPDATA\DocFetcher
; Remove start menu entries
Delete /REBOOTOK $SMPROGRAMS\DocFetcher\DocFetcher.lnk
Delete /REBOOTOK "$SMPROGRAMS\DocFetcher\Uninstall DocFetcher.lnk"
Delete $SMPROGRAMS\DocFetcher\Readme.lnk
RMDir $SMPROGRAMS\DocFetcher
SectionEnd