!include "Installer.nsh" !include "MUI.nsh" !include "LogicLib.nsh" !define WEBSITE_LINK "$INSTDIR\${PRODUCT_NAME} HomePage.url" var ICONS_GROUP !define MUI_STARTMENUPAGE_NODISABLE !define MUI_STARTMENUPAGE_DEFAULTFOLDER "${PRODUCT_NAME}" !define MUI_STARTMENUPAGE_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}" !define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}" !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${PRODUCT_STARTMENU_REGVAL}" ; MUI Settings !define MUI_ABORTWARNING !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico" !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico" !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_COMPONENTS !define MUI_PAGE_CUSTOMFUNCTION_PRE OldInstall_InstallDir !insertmacro MUI_PAGE_DIRECTORY !define MUI_PAGE_CUSTOMFUNCTION_PRE OldInstall_StartMenu !insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH ; Uninstaller !insertmacro MUI_UNPAGE_INSTFILES ; Language files !insertmacro MUI_LANGUAGE "English" ; MUI end ------ ; Check to see if an older version is already installed. Function OldInstall_InstallDir call RetrieveInstallDir ${If} $0 == "" ; this is the first time we're installing ; do nothing special ${Else} MessageBox MB_OKCANCEL \ "A previous ${PRODUCT_NAME} install was detected at $0. \ All ${PRODUCT_NAME} versions must be located in the same root directory. \ Do you want to proceed installing the current version in the old root directory? \ (Note: you can remove old installs through control panel->add remove programs->${PRODUCT_NAME})" \ IDOK OK IDCANCEL Cancel Cancel: Quit OK: StrCpy $INSTDIR $0 ; override whatever install directory we had with the one from the registry Abort ; //skip the "choose directory" page. ${EndIf} FunctionEnd Function OldInstall_StartMenu call RetrieveInstallDir ${If} $0 == "" ; do nothing special ${Else} abort ${EndIf} FunctionEnd Name "${PRODUCT_NAME}${PRODUCT_VERSION}" OutFile "${SCRIPT_OUTPUT_DIR}\Setup_${PRODUCT_NAME}${PRODUCT_VERSION}.exe" InstallDir "$PROGRAMFILES\Darwinbots3" InstallDirRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstallationDir" ; retrieve registry keys left behind by previous Darwinbots installs, if they exist ShowInstDetails show ShowUnInstDetails show Section -AdditionalIcons SetOutPath $INSTDIR !insertmacro MUI_STARTMENU_WRITE_BEGIN Application WriteIniStr "${WEBSITE_LINK}" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}" CreateDirectory "$SMPROGRAMS\$ICONS_GROUP" CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Homepage.lnk" "${WEBSITE_LINK}" CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\uninst.exe" !insertmacro MUI_STARTMENU_WRITE_END SectionEnd Section -Post WriteUninstaller "$INSTDIR\uninst.exe" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstallationDir" "$INSTDIR" SectionEnd Section "Darwinbots" SEC01 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application CreateDirectory "${DIR_SHARING}" !insertmacro MUI_STARTMENU_WRITE_END SectionEnd Section "Default Bots" SEC02 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application CreateDirectory "${DIR_BOTS}" SetOutPath "${DIR_BOTS}" File /nonfatal ${DEFAULT_ASSETS}\Bots\*.* !insertmacro MUI_STARTMENU_WRITE_END SectionEnd Section "Default Settings" SEC03 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application CreateDirectory "${DIR_SETTINGS}" SetOutPath "${DIR_SETTINGS}" File /nonfatal ${DEFAULT_ASSETS}\Settings\*.* !insertmacro MUI_STARTMENU_WRITE_END SectionEnd Section "Default Simulations" SEC04 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application CreateDirectory "${DIR_SIMS}" SetOutPath "${DIR_SIMS}" File /nonfatal ${DEFAULT_ASSETS}\Sims\*.* !insertmacro MUI_STARTMENU_WRITE_END SectionEnd ; Section descriptions !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${SEC01} "The main program." !insertmacro MUI_DESCRIPTION_TEXT ${SEC02} "Some bots written by the community to get you started." !insertmacro MUI_DESCRIPTION_TEXT ${SEC03} "Some default settings to get you started." !insertmacro MUI_DESCRIPTION_TEXT ${SEC04} "Some already running simulations to get you started." !insertmacro MUI_FUNCTION_DESCRIPTION_END Function un.onUninstSuccess HideWindow MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer." FunctionEnd Function un.onInit MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2 Abort FunctionEnd Section Uninstall !insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP Delete "${WEBSITE_LINK}" Delete "$INSTDIR\uninst.exe" RMDir "${DIR_BOTS}" RMDir /r "${DIR_SHARING}" ; force removal of the sharing directory since there's nothing in there we need RMDir "${DIR_SETTINGS}" RMDir "${DIR_SIMS}" RMDir $INSTDIR ; // remove only if it's not empty (the user might have installed it somewhere weird. like c:\) RMDir /r "$SMPROGRAMS\$ICONS_GROUP" DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" SetAutoClose true SectionEnd