|
| 1 | +#!Nsis Installer Command Script |
| 2 | +# |
| 3 | +# The following external defines are recognized: |
| 4 | +# ${VERSION} = YYYYMMDD |
| 5 | + |
| 6 | +!include "MUI2.nsh" |
| 7 | +!include "FileFunc.nsh" |
| 8 | + |
| 9 | +!define MUI_ICON "lammps.ico" |
| 10 | +!define MUI_UNICON "lammps.ico" |
| 11 | +!define MUI_HEADERIMAGE |
| 12 | +!define MUI_HEADERIMAGE_BITMAP "lammps-text-logo-wide.bmp" |
| 13 | +!define MUI_HEADERIMAGE_RIGHT |
| 14 | + |
| 15 | +Unicode true |
| 16 | +XPStyle on |
| 17 | + |
| 18 | +!include "LogicLib.nsh" |
| 19 | +!addplugindir "envvar/Plugins/x86-unicode" |
| 20 | +!include "x64.nsh" |
| 21 | + |
| 22 | +RequestExecutionLevel user |
| 23 | + |
| 24 | +!macro VerifyUserIsAdmin |
| 25 | +UserInfo::GetAccountType |
| 26 | +pop $0 |
| 27 | +${If} $0 != "admin" |
| 28 | + messageBox mb_iconstop "Administrator rights required!" |
| 29 | + setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED |
| 30 | + quit |
| 31 | +${EndIf} |
| 32 | +!macroend |
| 33 | + |
| 34 | +!define PACEPLUGIN "LAMMPS USER-AEAM Plugin ${VERSION}" |
| 35 | +OutFile "LAMMPS-USER-AEAM-plugin-${VERSION}.exe" |
| 36 | + |
| 37 | +Name "${PACEPLUGIN}" |
| 38 | +InstallDir "$LOCALAPPDATA\${PACEPLUGIN}" |
| 39 | + |
| 40 | +ShowInstDetails show |
| 41 | +ShowUninstDetails show |
| 42 | +SetCompressor lzma |
| 43 | + |
| 44 | +!define MUI_ABORTWARNING |
| 45 | + |
| 46 | +!insertmacro MUI_PAGE_DIRECTORY |
| 47 | +!insertmacro MUI_PAGE_INSTFILES |
| 48 | + |
| 49 | +!insertmacro MUI_UNPAGE_CONFIRM |
| 50 | +!insertmacro MUI_UNPAGE_INSTFILES |
| 51 | + |
| 52 | +!insertmacro MUI_LANGUAGE "English" |
| 53 | + |
| 54 | +function .onInit |
| 55 | + # Determine if LAMMPS was already installed and check whether it was in 32-bit |
| 56 | + # or 64-bit. Then look up path to uninstaller and offer to uninstall or quit |
| 57 | + SetRegView 32 |
| 58 | + ReadRegDWORD $0 HKCU "Software\LAMMPS-USER-AEAM" "Bits" |
| 59 | + SetRegView LastUsed |
| 60 | + ${If} $0 == "32" |
| 61 | + SetRegView 32 |
| 62 | + ${ElseIf} $0 == "64" |
| 63 | + SetRegView 64 |
| 64 | + ${Else} |
| 65 | + SetRegView 64 |
| 66 | + ${EndIf} |
| 67 | + ClearErrors |
| 68 | + ReadRegStr $R0 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" "UninstallString" |
| 69 | + SetRegView LastUsed |
| 70 | + ${If} ${Errors} |
| 71 | + DetailPrint "LAMMPS USER-AEAM plugin not (yet) installed" |
| 72 | + ${Else} |
| 73 | + MessageBox MB_YESNO "LAMMPS USER-AEAM plugin ($0 bit) is already installed. Uninstall existing version?" /SD IDYES IDNO Quit |
| 74 | + Pop $R1 |
| 75 | + StrCmp $R1 2 Quit +1 |
| 76 | + Exec $R0 |
| 77 | + Quit: |
| 78 | + Quit |
| 79 | + ${EndIf} |
| 80 | + setShellVarContext all |
| 81 | +functionEnd |
| 82 | + |
| 83 | +Section "${PACEPLUGIN}" SecPaceplugin |
| 84 | + SectionIn RO |
| 85 | + # Write LAMMPS installation bitness marker. Always use 32-bit registry view |
| 86 | + SetRegView 32 |
| 87 | + IntFmt $0 "0x%08X" 64 |
| 88 | + WriteRegDWORD HKCU "Software\LAMMPS-USER-AEAM" "Bits" $0 |
| 89 | + |
| 90 | + # Switch to "native" registry view |
| 91 | + SetRegView 64 |
| 92 | + SetShellVarContext current |
| 93 | + |
| 94 | + SetOutPath "$INSTDIR" |
| 95 | + File lammps.ico |
| 96 | + File aeamplugin.so |
| 97 | + |
| 98 | + # Register Application and its uninstaller |
| 99 | + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \ |
| 100 | + "DisplayName" "${PACEPLUGIN}" |
| 101 | + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \ |
| 102 | + "Publisher" "The LAMMPS and PACE Developers" |
| 103 | + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \ |
| 104 | + "URLInfoAbout" "lammps.org" |
| 105 | + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \ |
| 106 | + "DisplayIcon" "$INSTDIR\lammps.ico" |
| 107 | + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \ |
| 108 | + "DisplayVersion" "${VERSION}" |
| 109 | + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \ |
| 110 | + "InstallLocation" "$INSTDIR" |
| 111 | + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \ |
| 112 | + "UninstallString" "$\"$INSTDIR\uninstall.exe$\"" |
| 113 | + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \ |
| 114 | + "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S" |
| 115 | + |
| 116 | + ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2 |
| 117 | + IntFmt $0 "0x%08X" $0 |
| 118 | + WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" \ |
| 119 | + "EstimatedSize" "$0" |
| 120 | + |
| 121 | + # update path variables |
| 122 | + EnVar::SetHKCU |
| 123 | + # add to LAMMPS plugin search path |
| 124 | + EnVar::AddValue "LAMMPS_PLUGIN_PATH" "$INSTDIR" |
| 125 | + |
| 126 | + WriteUninstaller "$INSTDIR\Uninstall.exe" |
| 127 | +SectionEnd |
| 128 | + |
| 129 | +function un.onInit |
| 130 | + SetShellVarContext current |
| 131 | +functionEnd |
| 132 | + |
| 133 | +Section "Uninstall" |
| 134 | + # remove LAMMPS bitness/installation indicator always in 32-bit registry view |
| 135 | + SetRegView 32 |
| 136 | + DeleteRegKey HKCU "Software\LAMMPS-USER-AEAM" |
| 137 | + |
| 138 | + # unregister extension, and uninstall info |
| 139 | + SetRegView 64 |
| 140 | + SetShellVarContext current |
| 141 | + # unregister installation |
| 142 | + DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\LAMMPS-USER-AEAM" |
| 143 | + |
| 144 | + # update path variables |
| 145 | + EnVar::SetHKCU |
| 146 | + # remove entry from LAMMPS plugin search path |
| 147 | + EnVar::DeleteValue "LAMMPS_PLUGIN_PATH" "$INSTDIR" |
| 148 | + |
| 149 | + Delete /REBOOTOK "$INSTDIR\aeamplugin.so" |
| 150 | + Delete /REBOOTOK "$INSTDIR\Uninstall.exe" |
| 151 | + Delete /REBOOTOK "$INSTDIR\lammps.ico" |
| 152 | + RMDir /REBOOTOK "$INSTDIR" |
| 153 | +SectionEnd |
| 154 | + |
| 155 | +# Local Variables: |
| 156 | +# mode: sh |
| 157 | +# End: |
0 commit comments