# Authors: Troy Griffits, Lynn Alan, DM Smith # License: GPL 2.0 # NSIS Engine: 2.20 # Date last modified: Sept 2006 ;-------------------------------- ; LZMA is a tight compressor. ; comment out for testing SetCompressor lzma # Variables Var StartMenuGroup Var ModuleDir # The location of our nsh files !addincludedir include # Included files !include LogicLib.nsh !include FileFunc.nsh !insertmacro GetParent !include Sections.nsh !define ALL_USERS ; parameter for WriteEnvStr.nsh !include WriteEnvStr.nsh !include SwordProduct.nsh !include SwordFinish.nsh !include SwordUtil.nsh !include SwordPath.nsh !include SwordMUI.nsh ; Change the working directory to the deployment directory ; !cd ${PRODUCT_DEPLOYDIR} ;-------------------------------- ; Installer attributes Name "${PRODUCT_TITLE}" ; Allow for the resulting installer to be renamed with /DSTYLE=CD !ifdef STYLE OutFile "${PRODUCT_NAME}Setup${STYLE}.exe" !else OutFile "${PRODUCT_NAME}Setup.exe" !endif ; Uncomment the following if installation and unstallation should be scroll by. ; Without these, there is a "details" button. ;ShowInstDetails show ;ShowUninstDetails show ; Establish the default install location InstallDir "$PROGRAMFILES\${FAMILY_NAME}\${PRODUCT_TITLE}" ; See if there was a prior install and use that location as the default InstallDirRegKey HKLM "${PRODUCT_INST_KEY}" Path ; Uncomment the following to put a full screen background up. ;BGGradient 000080 000000 FFFFFF ; Define various Windows friendly values ; for the Version Tab of the File Properties VIProductVersion "${PRODUCT_FULL_VERSION}" VIAddVersionKey ProductName "${PRODUCT_TITLE}" VIAddVersionKey ProductVersion "${PRODUCT_VERSION}" VIAddVersionKey CompanyName "${PRODUCT_PUBLISHER}" VIAddVersionKey CompanyWebsite "${PRODUCT_WEBSITE}" VIAddVersionKey FileVersion "" VIAddVersionKey FileDescription "" VIAddVersionKey LegalCopyright "${PRODUCT_COPYRIGHT}" # Installer functions Function .onInit ;-------------------------------- ; Shortcuts are for all users SetShellVarContext all ;System::Call "kernel32::GetCurrentDirectory(i ${NSIS_MAX_STRLEN}, t .r0)" ;${If} "$0" != "" ; StrCpy $CWD "$0" ;${EndIf} ; It is too difficult to allow non-administrators to install, so... ; Determine whether the user has privileges to install ; putting up a Sorry message if not. ClearErrors WriteRegStr HKLM "SOFTWARE\CrossWire\The SWORD Project" "Test" "Test" IfErrors LimitedUserDetected AdminLevelDetected LimitedUserDetected: MessageBox MB_OK "Please install with administrator privileges." abort AdminLevelDetected: DeleteRegValue HKLM "SOFTWARE\CrossWire\The SWORD Project" "Test" ; Put up a splash screen ; If we internationalize the splash, ; then put it after the language selection !insertmacro Splash ${PRODUCT_SPLASH} ; Let the user choose a language for the installer ; (Un)comment the following if more than one language is listed ; in SwordLang.nsh !insertmacro MUI_LANGDLL_DISPLAY FunctionEnd Function .onInstSuccess Call SwordFinish FunctionEnd # Uninstaller functions Function un.onInit ;-------------------------------- ; Shortcuts are for all users SetShellVarContext all !insertmacro Splash ${PRODUCT_SPLASH} ; Let the user choose a language for he uninstaller ; Uncomment the following if more than one language is listed ; in SwordLang.nsh !insertmacro MUI_UNGETLANGUAGE ; Get the user's chosen location for the install ReadRegStr $INSTDIR HKLM "${PRODUCT_INST_KEY}" Path ; Get the user's chosen location for the Start Menu Group !insertmacro MUI_STARTMENU_GETFOLDER Application $startMenuGroup FunctionEnd # Installer sections ; Copy files into the installer Section -InstallFiles secInstallFiles ;-------------------------------- ; Cleanup Sword 1.5.6 ; This can be removed in a later release. ${If} ${FileExists} "$INSTDIR\UninstCust.dll" Delete /REBOOTOK "$INSTDIR\UninstCust.dll" ${EndIf} ${If} ${FileExists} "$INSTDIR\InstallMgr.exe" Delete /REBOOTOK "$INSTDIR\InstallMgr.exe" ${EndIf} ${If} ${FileExists} "$INSTDIR\swicu20.dll" Delete /REBOOTOK "$INSTDIR\swicu20.dll" ${EndIf} ${If} ${FileExists} "$INSTDIR\Uninst.isu" Delete /REBOOTOK "$INSTDIR\Uninst.isu" ${EndIf} ${If} ${FileExists} "$SMPROGRAMS\$StartMenuGroup\SWORD Help.lnk" Delete "$SMPROGRAMS\$StartMenuGroup\SWORD Help.lnk" ${EndIf} SetOverwrite ifnewer SetOutPath $INSTDIR ;-------------------------------- ; Copy all the files in the deployment dir ; It is ok for the directory to be empty or missing File /nonfatal /r "${PRODUCT_DEPLOYDIR}\*" ; Copy files from a Windows dir in the same dir as the installer ; This is used when installing from CD ${If} ${FileExists} "$EXEDIR\Windows\sword.exe" CopyFiles "$EXEDIR\Windows\*" $INSTDIR ${EndIf} ; Establish ModuleDir as the directory containing mods.d ; Look for mods.d under $INSTDIR ; If it is there set ModulePath to it ; Otherwise use ..\Library ; ; This allows for an upgrade that does not ;${If} ${FileExists} "$INSTDIR\mods.d" StrCpy $ModuleDir "$INSTDIR" ;${Else} ; ${GetParent} $INSTDIR $R0 ; StrCpy $ModuleDir "$R0\Library" ;${EndIf} ;-------------------------------- ; Copy library files to the ModuleDir ; It is ok for the directory to be empty or missing SetOutPath "$ModuleDir" File /nonfatal /r "${LIBRARY_DEPLOYDIR}\*" SetOutPath "$INSTDIR" ;-------------------------------- ; Call InstallManager to initialize its notion of a CD install location. ; This should be a silent run. ExecWait '"$INSTDIR\InstallManager.exe" -init "$EXEDIR"' ;-------------------------------- ; Create a link to the product's web home WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEBSITE}" ;-------------------------------- ; Create the uninstaller WriteUninstaller $INSTDIR\SwordUninstall.exe ;-------------------------------- ; For now, let's leave this check commented out as we probably want ; to always advertise remote install features by running InstallManager.exe ; ; See if we have any modules to install ;${If} ${FileExists} "$EXEDIR\modules" ;-------------------------------- ; Show the InstallManager Readme ExecWait 'notepad "$INSTDIR\${PRODUCT_README}"' ExecWait "$INSTDIR\${PRODUCT_INSTALLMGR}" ;${EndIf} SectionEnd ; Write (un)installer registry entries Section -RegistryEntries secRegistryEntries ;-------------------------------- ; Write the registry strings ; This string allows future installers to know where the program is installed WriteRegStr HKLM "${PRODUCT_INST_KEY}" Path $INSTDIR ; The following are the uninstaller definition for the Control Panel Add/Remove Programs WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" DisplayName "${PRODUCT_TITLE}" WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" DisplayVersion "${PRODUCT_VERSION}" WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" Publisher "${PRODUCT_PUBLISHER}" WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" URLInfoAbout "${PRODUCT_WEBSITE}" WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" UninstallString "$INSTDIR\${PRODUCT_NAME}Uninstall.exe" WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" DisplayIcon "$INSTDIR\${PRODUCT_NAME}Uninstall.exe" WriteRegDWord HKLM "${PRODUCT_UNINST_KEY}" NoModify 1 WriteRegDWord HKLM "${PRODUCT_UNINST_KEY}" NoRepair 1 SectionEnd ; Write shortcuts Section -Shortcuts secShortcuts ;-------------------------------- ; Install the Start Menu Group !insertmacro MUI_STARTMENU_WRITE_BEGIN Application ;-------------------------------- ; Write the menu group shortcuts CreateDirectory "$SMPROGRAMS\$StartMenuGroup" CreateShortCut "$SMPROGRAMS\$StartMenuGroup\${PRODUCT_TITLE}.lnk" $INSTDIR\${PRODUCT_NAME}.exe CreateShortCut "$SMPROGRAMS\$StartMenuGroup\Install Manager.lnk" $INSTDIR\InstallManager.exe CreateShortCut "$SMPROGRAMS\$StartMenuGroup\Uninstall ${PRODUCT_TITLE}.lnk" $INSTDIR\${PRODUCT_NAME}Uninstall.exe CreateShortCut "$SMPROGRAMS\$StartMenuGroup\${PRODUCT_TITLE} on the Web.lnk" $INSTDIR\${PRODUCT_NAME}.url CreateShortCut "$SMPROGRAMS\$StartMenuGroup\${PRODUCT_TITLE} Help.lnk" $INSTDIR\help\${PRODUCT_NAME}.chm ;-------------------------------- ; Create a desktop shortcut CreateShortCut "$DESKTOP\${PRODUCT_TITLE}.lnk" $INSTDIR\${PRODUCT_NAME}.exe !insertmacro MUI_STARTMENU_WRITE_END SectionEnd ; Add the SWORD_PATH environment variable Section -SwordPath swordPath Call setSwordPath SectionEnd # Uninstaller sections in the reverse order of the installer sections ; Add the SWORD_PATH environment variable Section -un.SwordPath unSwordPath Call un.setSwordPath SectionEnd Section -un.Shortcuts unSecShortcuts ;-------------------------------- ; Use the InstallManager to uninstall modules ; This will ask the user whether they want to remove them. ExecWait "$INSTDIR\InstallManager.exe -uninstall" ;-------------------------------- ; Uninstall the shortcuts in the Start Menu and on the Desktop ; deleting what this installer added there Delete "$DESKTOP\${PRODUCT_TITLE}.lnk" Delete "$SMPROGRAMS\$StartMenuGroup\${PRODUCT_TITLE}.lnk" Delete "$SMPROGRAMS\$StartMenuGroup\Install Manager.lnk" Delete "$SMPROGRAMS\$StartMenuGroup\Uninstall ${PRODUCT_TITLE}.lnk" Delete "$SMPROGRAMS\$StartMenuGroup\${PRODUCT_TITLE} on the Web.lnk" Delete "$SMPROGRAMS\$StartMenuGroup\${PRODUCT_TITLE} Help.lnk" ; if this folder is empty then delete it ; and any other empty parent folders ${RMDirUP} "$SMPROGRAMS\$StartMenuGroup" SectionEnd Section -un.RegistryEntires unRegistryEntries ;-------------------------------- ; Uninstall the Registry Keys ; DeleteRegValue HKLM "${PRODUCT_INST_KEY}" Path DeleteRegKey /ifempty HKLM "${PRODUCT_INST_KEY}" DeleteRegKey /ifempty HKLM "${PRODUCT_UNINST_KEY}" DeleteRegValue HKLM "${PRODUCT_REGKEY}" StartMenuGroup DeleteRegKey /ifempty HKLM "${PRODUCT_REGKEY}" DeleteRegKey /ifempty HKLM "${FAMILY_REGKEY}" SectionEnd Section -un.InstallFiles unSecInstallFiles ; If the InstallMgr did not delete the modules ; then don't delete in mods.d ; InstallMgr may not delete all files in mods.d ${Unless} ${FileExists} "$INSTDIR\modules" RMDir /r /REBOOTOK $INSTDIR\mods.d ${EndUnless} RMDir /r /REBOOTOK $INSTDIR\uilocales.d RMDir /r /REBOOTOK $INSTDIR\locales.d RMDir /r /REBOOTOK $INSTDIR\colors RMDir /r /REBOOTOK $INSTDIR\help RMDir /r /REBOOTOK $INSTDIR\bookmarks RMDir /r /REBOOTOK $INSTDIR\installMgr Delete /REBOOTOK $INSTDIR\options.conf Delete /REBOOTOK $INSTDIR\layout.conf Delete /REBOOTOK $INSTDIR\${PRODUCT_FIRSTRUN} Delete /REBOOTOK $INSTDIR\${PRODUCT_README} Delete /REBOOTOK $INSTDIR\${PRODUCT_ICUDLL} Delete /REBOOTOK $INSTDIR\${PRODUCT_LICENSE} Delete /REBOOTOK $INSTDIR\${PRODUCT_EXECUTABLE} Delete /REBOOTOK $INSTDIR\${PRODUCT_SPLASH} Delete /REBOOTOK $INSTDIR\${PRODUCT_URL} Delete /REBOOTOK $INSTDIR\${PRODUCT_UNINSTALL} ; if this folder is empty then delete it ; and any other empty parent folders ${RMDirUP} $INSTDIR SectionEnd