[svn-upgrade] Integrating new upstream version, jabref (2.3~beta1)
[debian/jabref.git] / src / windows / nsis / setup.nsi
index be360a00cad59583e4529e20c83f10827e6941eb..3d38bb00ab2282bbe4a45f0d342d356551503ffa 100644 (file)
-# Auto-generated by EclipseNSIS Script Wizard
-# 29.12.2005 01:09:51
+# owner        JabRef Team
+# license      GPL version 2
+# author       Uwe Stöhr
+# file version 1.0     date    18-01-2007
 
+; To compile this script NSIS 2.23 and newer are required
+; http://nsis.sourceforge.net/
+
+
+; Do a Cyclic Redundancy Check to make sure the installer
+; was not corrupted by the download.
+CRCCheck force
+
+; Make the installer as small as possible.
+SetCompressor lzma
+
+
+# general definitions
+; you only need to change this section for new releases
+VIProductVersion "2.2.0.0" ; file version for the installer in the scheme "x.x.x.x"
 !ifndef VERSION
-       !define VERSION "2.1"
+       !define VERSION "2.2"
 !endif
-
 Name "JabRef ${VERSION}"
-
-!define REGKEY "SOFTWARE\$(^Name)"
+!define REGKEY "SOFTWARE\JabRef"
 !define COMPANY "JabRef Team"
-!define URL http://jabref.sourceforge.net/
+!define URL "http://jabref.sourceforge.net"
+!define PRODUCT_EXE "JabRef.exe"
+!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
+!define PRODUCT_LICENSE_FILE "dist\gpl.txt"
+
+
+# Variables
+Var StartmenuFolder
+Var CreateDesktopIcon
+Var Answer
+Var UserName
 
-# MUI defines
-!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install-full.ico"
-!define MUI_FINISHPAGE_NOAUTOCLOSE
-!define MUI_STARTMENUPAGE_REGISTRY_ROOT HKLM
-!define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\JabRef"
-!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME StartMenuGroup
-!define MUI_STARTMENUPAGE_DEFAULT_FOLDER "JabRef"
-!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall-full.ico"
-!define MUI_FINISHPAGE_RUN $INSTDIR/JabRef.exe
-!define MUI_UNFINISHPAGE_NOAUTOCLOSE
-!define MUI_COMPONENTSPAGE_SMALLDESC
 
 # Included files
-!include Sections.nsh
-!include MUI.nsh
-!include fileassoc.nsh
+!include "MUI.nsh"
+!include "fileassoc.nsh"
+!include "LogicLib.nsh"
 
-# Reserved Files
 
-# Variables
-Var StartMenuGroup
+# macros
+!macro IsUserAdmin Result UName
+
+ ClearErrors
+ UserInfo::GetName
+ IfErrors Win9x
+ Pop $0
+ StrCpy ${UName} $0
+ UserInfo::GetAccountType
+ Pop $1
+ ${if} $1 == "Admin"
+  StrCpy ${Result} "yes"
+ ${else}
+  StrCpy ${Result} "no"
+ ${endif}
+ Goto done
+
+ Win9x:
+  StrCpy ${Result} "yes"
+ done:
+
+!macroend
+
 
 # Installer pages
+; Remember the installer language
+!define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
+!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
+!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
+
+; let warning appear when installation is canceled
+!define MUI_ABORTWARNING
+
+; Icons for the installer program
+!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install-full.ico"
+!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall-full.ico"
+
+; Welcome page
+!define MUI_WELCOMEPAGE_TEXT "$(WelcomePageText)"
 !insertmacro MUI_PAGE_WELCOME
-!insertmacro MUI_PAGE_LICENSE dist/GPL.txt
+
+; Show the license.
+!insertmacro MUI_PAGE_LICENSE "${PRODUCT_LICENSE_FILE}"
+
+; Specify the installation directory.
 !insertmacro MUI_PAGE_DIRECTORY
-!insertmacro MUI_PAGE_STARTMENU Application $StartMenuGroup
+
+; choose the components to install.
 !insertmacro MUI_PAGE_COMPONENTS
+
+; Specify where to install program shortcuts.
+!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
+!define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
+!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
+!define MUI_STARTMENUPAGE_DEFAULTFOLDER "$(^Name)"
+!insertmacro MUI_PAGE_STARTMENU ${PRODUCT_NAME} $StartmenuFolder
+
+; Watch the components being installed.
 !insertmacro MUI_PAGE_INSTFILES
+
+; Finish page
+!define MUI_FINISHPAGE_RUN "$INSTDIR\${PRODUCT_EXE}"
+!define MUI_FINISHPAGE_TEXT "$(FinishPageMessage)"
+!define MUI_FINISHPAGE_RUN_TEXT "$(FinishPageRun)"
 !insertmacro MUI_PAGE_FINISH
 
+; The uninstaller
 !insertmacro MUI_UNPAGE_CONFIRM
 !insertmacro MUI_UNPAGE_INSTFILES
 
+
 # Installer languages
-!insertmacro MUI_LANGUAGE English
+!insertmacro MUI_LANGUAGE "English" # first language is the default language
+!insertmacro MUI_LANGUAGE "German"
+!insertmacro MUI_LANGUAGE "French"
+!insertmacro MUI_LANGUAGE "Italian"
+
+!include "installer_languages\english.nsh"
+!include "installer_languages\german.nsh"
+!include "installer_languages\french.nsh"
+!include "installer_languages\italian.nsh"
 
 # Installer attributes
 OutFile JabRefSetup.exe
 InstallDir "$PROGRAMFILES\JabRef"
-CRCCheck on
-XPStyle on
-ShowInstDetails show
-VIProductVersion 1.3.0.0
+BrandingText "$(^Name) installer" ; appear at the bottom of the installer windows
+XPStyle on ; use XP style for installer windows
+InstallDirRegKey HKLM "${REGKEY}" Path
+LicenseData "$(JabRefLicenseData)"
+
+; creates file informations for the JabRefSetup.exe
 VIAddVersionKey ProductName "JabRef"
 VIAddVersionKey ProductVersion "${VERSION}"
 VIAddVersionKey CompanyName "${COMPANY}"
 VIAddVersionKey CompanyWebsite "${URL}"
+VIAddVersionKey FileDescription "JabRef installation program"
+VIAddVersionKey LegalCopyright "under the GPL version 2"
 VIAddVersionKey FileVersion ""
-VIAddVersionKey FileDescription ""
-VIAddVersionKey LegalCopyright ""
-InstallDirRegKey HKLM "${REGKEY}" Path
-ShowUninstDetails show
+
 
 # Installer sections
-Section -Main SEC0000
-    SetOutPath $INSTDIR
-    SetOverwrite on
-    File /r dist\*.*
-    WriteRegStr HKLM "${REGKEY}\Components" Main 1
+Section "!JabRef" SecCore
+ SectionIn RO
 SectionEnd
 
-Section "Associate .bib with JabRef" AssociateBib
   !insertmacro APP_ASSOCIATE "bib" "JabRef.BibTeX" "BibTeX File" "$INSTDIR\JabRef.exe,0" "Open in JabRef" "$INSTDIR\JabRef.exe $\"%1$\""
+Section "$(SecAssociateBibTitle)" SecAssociateBib
!insertmacro APP_ASSOCIATE "bib" "JabRef.BibTeX" "$(FileTypeTitle)" "$INSTDIR\${PRODUCT_EXE},0" "$(OpenIn)" "$INSTDIR\${PRODUCT_EXE} $\"%1$\""
 SectionEnd
 
-LangString DESC_AssociateBib {LANG_ENGLISH} "Will associate files of extension .bib with JabRef."
+Section "$(SecDesktopTitle)" SecDesktop
+ StrCpy $CreateDesktopIcon "true"
+SectionEnd
 
+; section descriptions
 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
-  !insertmacro MUI_DESCRIPTION_TEXT ${AssociateBib} $(DESC_AssociateBib)
+!insertmacro MUI_DESCRIPTION_TEXT ${SecAssociateBib} "$(SecAssociateBibDescription)"
+!insertmacro MUI_DESCRIPTION_TEXT ${SecDesktop} "$(SecDesktopDescription)"
 !insertmacro MUI_FUNCTION_DESCRIPTION_END
 
-Section "un.Associate .bib with JabRef" un.AssociateBib
-
-   !insertmacro APP_UNASSOCIATE "bib" "JabRef.BibTeX"
+Section "-Installation actions" SecInstallation
 
-SectionEnd
-
-
-
-Section -post SEC0001
-    WriteRegStr HKLM "${REGKEY}" Path $INSTDIR
-    WriteUninstaller $INSTDIR\uninstall.exe
-    !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
-    SetOutPath $SMPROGRAMS\$StartMenuGroup
-    CreateShortCut "$SMPROGRAMS\$StartMenuGroup\Start $(^Name).lnk" $INSTDIR\JabRef.exe
-    CreateShortCut "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk" $INSTDIR\uninstall.exe
-    !insertmacro MUI_STARTMENU_WRITE_END
-    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayName "$(^Name)"
-    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayVersion "${VERSION}"
-    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" Publisher "${COMPANY}"
-    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" URLInfoAbout "${URL}"
-    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayIcon $INSTDIR\uninstall.exe
-    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" UninstallString $INSTDIR\uninstall.exe
-    WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoModify 1
-    WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoRepair 1
+  ; create shortcuts for all users
+  SetShellVarContext all
+  ; copy files
+  SetOutPath "$INSTDIR"
+  SetOverwrite on
+  File /r dist\*.*
+  WriteRegStr HKLM "${REGKEY}\Components" Main 1
+  ; register JabRef
+  WriteRegStr HKLM "${REGKEY}" Path $INSTDIR
+  WriteUninstaller $INSTDIR\uninstall.exe
+  ; create shortcuts to startmenu
+  SetOutPath "$INSTDIR"
+  CreateDirectory "$SMPROGRAMS\$StartmenuFolder"
+  CreateShortCut "$SMPROGRAMS\$StartmenuFolder\$(^Name).lnk" "$INSTDIR\${PRODUCT_EXE}" "" "$INSTDIR\JabRef.exe"
+  CreateShortCut "$SMPROGRAMS\$StartmenuFolder\Uninstall $(^Name).lnk" "$INSTDIR\uninstall.exe"
+  ; create desktop icon
+  ${if} $CreateDesktopIcon == "true"
+   SetOutPath "$INSTDIR"
+   CreateShortCut "$DESKTOP\$(^Name).lnk" "$INSTDIR\${PRODUCT_EXE}" "" "$INSTDIR\${PRODUCT_EXE}" ;$(^Name).lnk
+  ${endif}
+  ; register information that appear in Windows' software listing
+  WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
+  WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${VERSION}"
+  WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "Publisher" "${COMPANY}"
+  WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${URL}"
+  WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\${PRODUCT_EXE}"
+  WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "StartMenu" "$SMPROGRAMS\$StartmenuFolder"
+  WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninstall.exe"
+  WriteRegDWORD HKLM "${PRODUCT_UNINST_KEY}" "NoModify" 0x00000001
+  WriteRegDWORD HKLM "${PRODUCT_UNINST_KEY}" "NoRepair" 0x00000001
        
 SectionEnd
 
-# Macro for selecting uninstaller sections
-!macro SELECT_UNSECTION SECTION_NAME UNSECTION_ID
-    Push $R0
-    ReadRegStr $R0 HKLM "${REGKEY}\Components" "${SECTION_NAME}"
-    StrCmp $R0 1 0 next${UNSECTION_ID}
-    !insertmacro SelectSection "${UNSECTION_ID}"
-    Goto done${UNSECTION_ID}
-next${UNSECTION_ID}:
-    !insertmacro UnselectSection "${UNSECTION_ID}"
-done${UNSECTION_ID}:
-    Pop $R0
-!macroend
 
 # Uninstaller sections
-Section /o un.Main UNSEC0000
-    Delete /REBOOTOK $INSTDIR\jabref.jar
-    Delete /REBOOTOK $INSTDIR\JabRef.exe
-    Delete /REBOOTOK $INSTDIR\GPL.txt
-    Delete /REBOOTOK $INSTDIR\Credits.txt
-    DeleteRegValue HKLM "${REGKEY}\Components" Main
-SectionEnd
+Section "un.JabRef" un.SecUnProgramFiles
 
-Section un.post UNSEC0001
-    DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
-    Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk"
-    Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Start $(^Name).lnk"
-    Delete /REBOOTOK $INSTDIR\uninstall.exe
-    DeleteRegValue HKLM "${REGKEY}" StartMenuGroup
-    DeleteRegValue HKLM "${REGKEY}" Path
-    DeleteRegKey /ifempty HKLM "${REGKEY}\Components"
-    DeleteRegKey /ifempty HKLM "${REGKEY}"
-    RMDir /REBOOTOK $SMPROGRAMS\$StartMenuGroup
-    RMDir /REBOOTOK $INSTDIR
+  SectionIn RO
+  ; delete installation folder
+  RMDir /r $INSTDIR    
+  ; delete start menu entry
+  ReadRegStr $0 HKLM "${PRODUCT_UNINST_KEY}" "StartMenu"
+  RMDir /r "$0"
+  ; delete desktop icon
+  Delete "$DESKTOP\$(^Name).lnk"
+  ; delete registry entries
+  DeleteRegKey HKCU "${PRODUCT_UNINST_KEY}"
+  DeleteRegKey HKLM "${PRODUCT_UNINST_KEY}"
+  DeleteRegKey HKCR "Applications\${PRODUCT_EXE}"
+  DeleteRegValue HKCR ".bib" "JabRef.BibTeX_backup"
+  DeleteRegValue HKLM "Software\Classes\.bib" "JabRef.BibTeX_backup"
+  DeleteRegKey HKLM "${REGKEY}"
+  ; remove file association with .bib-files
+  !insertmacro APP_UNASSOCIATE "bib" "JabRef.BibTeX"
+  ; close uninstaller automatically
+  SetAutoClose true
+    
 SectionEnd
 
+
 # Installer functions
 Function .onInit
-    InitPluginsDir
+
+ InitPluginsDir
+  ; If the user does *not* have administrator privileges, abort
+  StrCpy $Answer ""
+  StrCpy $UserName ""
+  !insertmacro IsUserAdmin $Answer $UserName ; macro from LyXUtils.nsh
+  ${if} $Answer == "yes"
+   SetShellVarContext all ; set that e.g. shortcuts will be created for all users
+  ${else}
+   MessageBox MB_OK|MB_ICONSTOP "$(NotAdmin)"
+   Abort
+  ${endif}
+
 FunctionEnd
 
+
 # Uninstaller functions
 Function un.onInit
-    ReadRegStr $INSTDIR HKLM "${REGKEY}" Path
-    ReadRegStr $StartMenuGroup HKLM "${REGKEY}" StartMenuGroup
-    !insertmacro SELECT_UNSECTION Main ${UNSEC0000}
+       
+  ; If the user does *not* have administrator privileges, abort
+  StrCpy $Answer ""
+  !insertmacro IsUserAdmin $Answer $UserName
+  ${if} $Answer == "yes"
+   SetShellVarContext all
+  ${else}
+   MessageBox MB_OK|MB_ICONSTOP "$(UnNotAdminLabel)"
+   Abort
+  ${endif}
+  
+  ; ask if it should really be removed
+  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "$(UnReallyRemoveLabel)" IDYES +2
+  Abort
+  
+FunctionEnd
+
+Function un.onUninstSuccess
+       
+  HideWindow
+  MessageBox MB_ICONINFORMATION|MB_OK "$(UnRemoveSuccessLabel)"
+  
 FunctionEnd