New upstream release.
[debian/jabref.git] / src / windows / nsis / setup.nsi
1 # owner         JabRef Team
2 # license       GPL version 2
3 # author        Uwe Stöhr
4 # file version  2.0     date    20-11-2007
5
6 ; To compile this script NSIS 2.30 or newer are required
7 ; http://nsis.sourceforge.net/
8
9
10 ; Do a Cyclic Redundancy Check to make sure the installer
11 ; was not corrupted by the download.
12 CRCCheck force
13
14 ; Make the installer as small as possible.
15 SetCompressor lzma
16
17 ; set execution level for Windows Vista
18 RequestExecutionLevel user
19
20 # general definitions
21 ; you only need to change this section for new releases
22 ; you only need to change this section for new releases
23 VIProductVersion "2.4.0.0" ; file version for the installer in the scheme "x.x.x.x"
24 !ifndef VERSION
25         !define VERSION "2.4"
26 !endif
27 Name "JabRef ${VERSION}"
28 !define REGKEY "SOFTWARE\JabRef"
29 !define COMPANY "JabRef Team"
30 !define URL "http://jabref.sourceforge.net"
31 !define PRODUCT_NAME "JabRef"
32 !define PRODUCT_EXE "$INSTDIR\JabRef.exe"
33 !define PRODUCT_EXE2 "JabRef.exe"
34 !define PRODUCT_REGNAME "BibTeX.Document"
35 !define PRODUCT_EXT ".bib"
36 !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
37 !define PRODUCT_LICENSE_FILE "dist\gpl.txt"
38
39
40 ; registry preparations
41 !define SHCNE_ASSOCCHANGED 0x08000000
42 !define SHCNF_IDLIST 0
43
44
45 # Variables
46 Var StartmenuFolder
47 Var CreateFileAssociations
48 Var CreateDesktopIcon
49 Var Answer
50 Var UserName
51
52
53 # Included files
54 !include "MUI.nsh"
55 !include "LogicLib.nsh"
56
57
58 # macros
59 !macro IsUserAdmin Result UName
60
61  ClearErrors
62  UserInfo::GetName
63  IfErrors Win9x
64  Pop $0
65  StrCpy ${UName} $0
66  UserInfo::GetAccountType
67  Pop $1
68  ${if} $1 == "Admin"
69   StrCpy ${Result} "yes"
70  ${else}
71   StrCpy ${Result} "no"
72  ${endif}
73  Goto done
74
75  Win9x:
76   StrCpy ${Result} "yes"
77  done:
78
79 !macroend
80
81
82 # Installer pages
83 ; Remember the installer language
84 !define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
85 !define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
86 !define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
87
88 ; let warning appear when installation is canceled
89 !define MUI_ABORTWARNING
90
91 ; Icons for the installer program
92 !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install-full.ico"
93 !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall-full.ico"
94
95 ; Welcome page
96 !define MUI_WELCOMEPAGE_TEXT "$(WelcomePageText)"
97 !insertmacro MUI_PAGE_WELCOME
98
99 ; Show the license.
100 !insertmacro MUI_PAGE_LICENSE "${PRODUCT_LICENSE_FILE}"
101
102 ; Specify the installation directory.
103 !insertmacro MUI_PAGE_DIRECTORY
104
105 ; choose the components to install.
106 !insertmacro MUI_PAGE_COMPONENTS
107
108 ; Specify where to install program shortcuts.
109 !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
110 !define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
111 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
112 !define MUI_STARTMENUPAGE_DEFAULTFOLDER "$(^Name)"
113 !insertmacro MUI_PAGE_STARTMENU ${PRODUCT_NAME} $StartmenuFolder
114
115 ; Watch the components being installed.
116 !insertmacro MUI_PAGE_INSTFILES
117
118 ; Finish page
119 !define MUI_FINISHPAGE_RUN "${PRODUCT_EXE}"
120 !define MUI_FINISHPAGE_TEXT "$(FinishPageMessage)"
121 !define MUI_FINISHPAGE_RUN_TEXT "$(FinishPageRun)"
122 !insertmacro MUI_PAGE_FINISH
123
124 ; The uninstaller
125 !insertmacro MUI_UNPAGE_CONFIRM
126 !insertmacro MUI_UNPAGE_INSTFILES
127
128
129 # Installer languages
130 !insertmacro MUI_LANGUAGE "English" # first language is the default language
131 !insertmacro MUI_LANGUAGE "German"
132
133 !include "installer_languages\english.nsh"
134 !include "installer_languages\german.nsh"
135
136
137 # Installer attributes
138 OutFile JabRefSetup.exe
139 InstallDir "$PROGRAMFILES\JabRef"
140 BrandingText "$(^Name) installer" ; appear at the bottom of the installer windows
141 XPStyle on ; use XP style for installer windows
142 LicenseData "$(JabRefLicenseData)"
143
144 ; creates file informations for the JabRefSetup.exe
145 VIAddVersionKey ProductName "JabRef"
146 VIAddVersionKey ProductVersion "${VERSION}"
147 VIAddVersionKey CompanyName "${COMPANY}"
148 VIAddVersionKey CompanyWebsite "${URL}"
149 VIAddVersionKey FileDescription "JabRef installation program"
150 VIAddVersionKey LegalCopyright "under the GPL version 2"
151 VIAddVersionKey FileVersion ""
152
153
154 # Installer sections
155 Section "!JabRef" SecCore
156  SectionIn RO
157 SectionEnd
158
159 Section "$(SecAssociateBibTitle)" SecAssociateBib
160  StrCpy $CreateFileAssociations "true"
161 SectionEnd
162
163 Section "$(SecDesktopTitle)" SecDesktop
164  StrCpy $CreateDesktopIcon "true"
165 SectionEnd
166
167 ; section descriptions
168 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
169 !insertmacro MUI_DESCRIPTION_TEXT ${SecAssociateBib} "$(SecAssociateBibDescription)"
170 !insertmacro MUI_DESCRIPTION_TEXT ${SecDesktop} "$(SecDesktopDescription)"
171 !insertmacro MUI_FUNCTION_DESCRIPTION_END
172
173 Section "-Installation actions" SecInstallation
174
175   ; copy files
176   SetOutPath "$INSTDIR"
177   SetOverwrite on
178   File /r dist\*.*
179   WriteRegStr SHCTX "${REGKEY}\Components" Main 1
180   
181   ; register JabRef
182   WriteRegStr SHCTX "${REGKEY}" Path $INSTDIR
183   WriteUninstaller $INSTDIR\uninstall.exe
184   
185   ; create shortcuts to startmenu
186   SetOutPath "$INSTDIR"
187   CreateDirectory "$SMPROGRAMS\$StartmenuFolder"
188   CreateShortCut "$SMPROGRAMS\$StartmenuFolder\$(^Name).lnk" "${PRODUCT_EXE}" "" "$INSTDIR\JabRef.exe"
189   CreateShortCut "$SMPROGRAMS\$StartmenuFolder\Uninstall $(^Name).lnk" "$INSTDIR\uninstall.exe"
190   
191   ; create desktop icon
192   ${if} $CreateDesktopIcon == "true"
193    SetOutPath "$INSTDIR"
194    CreateShortCut "$DESKTOP\$(^Name).lnk" "${PRODUCT_EXE}" "" "${PRODUCT_EXE}" ;$(^Name).lnk
195   ${endif}
196   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "StartMenu" "$SMPROGRAMS\$StartmenuFolder"
197   ${if} $Answer == "yes" ; if user is admin
198   
199    ; register information that appear in Windows' software listing
200    WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
201    WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${VERSION}"
202    WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "Publisher" "${COMPANY}"
203    WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${URL}"
204    WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "DisplayIcon" "${PRODUCT_EXE}"
205    WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninstall.exe"   
206    WriteRegDWORD SHCTX "${PRODUCT_UNINST_KEY}" "NoModify" 0x00000001
207    WriteRegDWORD SHCTX "${PRODUCT_UNINST_KEY}" "NoRepair" 0x00000001
208   ${endif}
209   
210   # register the extension .bib
211   ${if} $CreateFileAssociations == "true"
212    # write informations about file type
213    WriteRegStr SHCTX "Software\Classes\${PRODUCT_REGNAME}" "" "${PRODUCT_NAME} Document"
214    WriteRegStr SHCTX "Software\Classes\${PRODUCT_REGNAME}\DefaultIcon" "" "${PRODUCT_EXE},0"
215    WriteRegStr SHCTX "Software\Classes\${PRODUCT_REGNAME}\Shell\open\command" "" '"${PRODUCT_EXE}" "%1"'
216    # write informations about file extensions
217    WriteRegStr SHCTX "Software\Classes\${PRODUCT_EXT}" "" "${PRODUCT_REGNAME}"
218    # refresh shell
219    System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) (${SHCNE_ASSOCCHANGED}, ${SHCNF_IDLIST}, 0, 0)'
220   ${endif}
221
222 SectionEnd
223
224
225 # Uninstaller sections
226 Section "un.JabRef" un.SecUnProgramFiles
227
228   SectionIn RO
229   ; delete installation folder
230   RMDir /r $INSTDIR     
231   ; delete start menu entry
232   ReadRegStr $0 SHCTX "${PRODUCT_UNINST_KEY}" "StartMenu"
233   RMDir /r "$0"
234   
235   ; delete desktop icon
236   Delete "$DESKTOP\$(^Name).lnk"
237   
238   # remove file extension 
239   ReadRegStr $R0 SHCTX "Software\Classes\${PRODUCT_EXT}" ""
240   ${if} $R0 == "${PRODUCT_REGNAME}"
241    DeleteRegKey SHCTX "Software\Classes\${PRODUCT_EXT}"
242    DeleteRegKey SHCTX "Software\Classes\${PRODUCT_REGNAME}"
243   ${endif}
244   
245   ; delete remaining registry entries
246   DeleteRegKey HKCU "${PRODUCT_UNINST_KEY}"
247   DeleteRegKey SHCTX "${PRODUCT_UNINST_KEY}"
248   DeleteRegKey HKCR "Applications\${PRODUCT_EXE2}"
249   DeleteRegKey HKCU "${REGKEY}"
250   DeleteRegKey SHCTX "${REGKEY}"
251   
252   ; close uninstaller automatically
253   SetAutoClose true
254
255 SectionEnd
256
257
258 # Installer functions
259 Function .onInit
260
261   StrCpy $StartmenuFolder ${PRODUCT_NAME}
262
263  # check if the same Jabref version is already installed
264   ReadRegStr $0 SHCTX "${PRODUCT_UNINST_KEY}" "Publisher"
265   ${if} $0 != ""
266    MessageBox MB_OK|MB_ICONSTOP "$(StillInstalled)" /SD IDOK
267    Abort
268   ${endif}
269   
270  InitPluginsDir
271   ; If the user does *not* have administrator privileges, abort
272   StrCpy $Answer ""
273   StrCpy $UserName ""
274   !insertmacro IsUserAdmin $Answer $UserName ; macro from LyXUtils.nsh
275   ${if} $Answer == "yes"
276    SetShellVarContext all ; set that e.g. shortcuts will be created for all users
277   ${else}
278    SetShellVarContext current
279    StrCpy $INSTDIR "$APPDATA\$(^Name)"
280   ${endif}
281
282 FunctionEnd
283
284
285 # Uninstaller functions
286 Function un.onInit
287
288   ; If the user does *not* have administrator privileges, abort
289   StrCpy $Answer ""
290   !insertmacro IsUserAdmin $Answer $UserName
291   ${if} $Answer == "yes"
292    SetShellVarContext all
293   ${else}
294    # check if the Jabref has been installed with admin permisions
295    ReadRegStr $0 HKLM "${PRODUCT_UNINST_KEY}" "Publisher"
296    ${if} $0 != ""
297     MessageBox MB_OK|MB_ICONSTOP "$(UnNotAdminLabel)" /SD IDOK
298     Abort
299    ${endif}
300    SetShellVarContext current
301   ${endif}
302   
303   ; ask if it should really be removed
304   MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "$(UnReallyRemoveLabel)" /SD IDYES IDYES +2
305   Abort
306
307 FunctionEnd
308
309 Function un.onUninstSuccess
310
311   HideWindow
312   MessageBox MB_ICONINFORMATION|MB_OK "$(UnRemoveSuccessLabel)" /SD IDOK
313
314 FunctionEnd
315