Update the NSIS Installer Script
This commit is contained in:
parent
d73d752187
commit
cdd5b503b4
2 changed files with 575 additions and 146 deletions
|
|
@ -3,170 +3,253 @@
|
|||
# result = "; NSIS script generated by niminst\n" &
|
||||
# "; To regenerate run ``niminst nsis`` or ``koch nsis``\n"
|
||||
|
||||
!define PRODUCT_NAME "?c.displayName"
|
||||
!define PRODUCT_VERSION "?c.version"
|
||||
!define PRODUCT_PUBLISHER "?c.authors"
|
||||
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\?{c.name}.exe"
|
||||
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
|
||||
!define PRODUCT_UNINST_ROOT_KEY "HKCU"
|
||||
!define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir"
|
||||
;--------------------------------
|
||||
; Included headers
|
||||
; Modern User Interface 2.0 Header
|
||||
!include "MUI2.nsh"
|
||||
|
||||
; MUI 1.67 compatible ------
|
||||
!include "MUI.nsh"
|
||||
!define MULTIUSER_EXECUTIONLEVEL Standard
|
||||
!include "MultiUser.nsh"
|
||||
!include "zipdll.nsh"
|
||||
; File Functions Header, used to get the current drive root.
|
||||
!include "FileFunc.nsh"
|
||||
|
||||
InstallDir "$LOCALAPPDATA\?{c.name}"
|
||||
; *Patched* Environment Variable Manipulation Header, used to add
|
||||
; tools to the user's PATH environment variable.
|
||||
!include "EnvVarUpdate.nsh"
|
||||
|
||||
; 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"
|
||||
|
||||
; Welcome page
|
||||
!insertmacro MUI_PAGE_WELCOME
|
||||
; License page
|
||||
!insertmacro MUI_PAGE_LICENSE "?{expandFilename(c.license)}"
|
||||
; Components page
|
||||
!insertmacro MUI_PAGE_COMPONENTS
|
||||
; Directory page
|
||||
!insertmacro MUI_PAGE_DIRECTORY
|
||||
; Start menu page
|
||||
var ICONS_GROUP
|
||||
!define MUI_STARTMENUPAGE_NODISABLE
|
||||
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "?c.displayName"
|
||||
!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}"
|
||||
!insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP
|
||||
; Instfiles page
|
||||
!insertmacro MUI_PAGE_INSTFILES
|
||||
; Finish page
|
||||
; !define MUI_FINISHPAGE_RUN "$INSTDIR\start.bat"
|
||||
!insertmacro MUI_PAGE_FINISH
|
||||
|
||||
; Uninstaller pages
|
||||
!insertmacro MUI_UNPAGE_INSTFILES
|
||||
|
||||
; Language files
|
||||
!insertmacro MUI_LANGUAGE "English"
|
||||
|
||||
; MUI end ------
|
||||
|
||||
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
|
||||
OutFile "?{c.name}_?{c.version}.exe"
|
||||
; InstallDir "$PROGRAMFILES\?c.displayName"
|
||||
InstallDirRegKey HKCU "${PRODUCT_DIR_REGKEY}" ""
|
||||
ShowInstDetails show
|
||||
ShowUnInstDetails show
|
||||
|
||||
Section "Core" SEC0
|
||||
SetOverwrite ifnewer
|
||||
SetOutPath "$INSTDIR"
|
||||
#for i in low(TFileCategory)..fcWindows:
|
||||
# for f in items(c.cat[i]):
|
||||
SetOutPath "$INSTDIR\?{splitFile(f).dir.toWin}"
|
||||
File "?{expandFilename(f).toWin}"
|
||||
# end for
|
||||
#end for
|
||||
;--------------------------------
|
||||
; Global variables and defines
|
||||
!define PRODUCT_NAME "?c.displayName"
|
||||
!define PRODUCT_VERSION "?c.version"
|
||||
!define PRODUCT_PUBLISHER "?c.authors"
|
||||
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\?{c.name}.exe"
|
||||
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
|
||||
!define PRODUCT_UNINST_ROOT_KEY "HKCU"
|
||||
!define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir"
|
||||
|
||||
|
||||
; Shortcuts
|
||||
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
|
||||
CreateDirectory "$SMPROGRAMS\$ICONS_GROUP"
|
||||
;--------------------------------
|
||||
; General Setup Information
|
||||
|
||||
#if c.app == appConsole:
|
||||
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\?{c.displayName}.lnk" "$INSTDIR\start.bat"
|
||||
CreateShortCut "$DESKTOP\?{c.displayName}.lnk" "$INSTDIR\start.bat"
|
||||
#else:
|
||||
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\?{c.displayName}.lnk" "$INSTDIR\?{c.name}.exe"
|
||||
CreateShortCut "$DESKTOP\?{c.displayName}.lnk" "$INSTDIR\?{c.name}.exe"
|
||||
#end if
|
||||
#for f in items(c.cat[fcDocStart]):
|
||||
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\?{splitFile(f).name}.lnk" "$INSTDIR\?{f.toWin}"
|
||||
#end for
|
||||
; Name and output file
|
||||
Name "?{c.name} ?{c.version}"
|
||||
OutFile "?{c.name}_?{c.version}.exe"
|
||||
|
||||
!insertmacro MUI_STARTMENU_WRITE_END
|
||||
SectionEnd
|
||||
; Default installation folder
|
||||
; This is changed later (in .onInit) to the root directory, if possible.
|
||||
InstallDir "$LOCALAPPDATA\?{c.name}"
|
||||
|
||||
; Get installation folder from registry if available
|
||||
InstallDirRegKey HKCU "Software\c.name\c.version" ""
|
||||
|
||||
#var i = 0
|
||||
#for download in c.downloads:
|
||||
# inc i
|
||||
# let d = download.split('|')
|
||||
# if d.len != 5 and d.len != 6:
|
||||
# quit("download string needs 5..6 parts: " & download)
|
||||
# end if
|
||||
# let sectionName = d[0]
|
||||
# let dir = d[1]
|
||||
# let zipName = d[2]
|
||||
# let size = d[3]
|
||||
# let url = d[4]
|
||||
Section /o "?sectionName" SEC?i
|
||||
; Request user level application privileges.
|
||||
RequestExecutionLevel user
|
||||
|
||||
AddSize ?size
|
||||
; Allow installation to the root drive directory.
|
||||
AllowRootDirInstall true
|
||||
|
||||
NSISdl::download "?url" "$INSTDIR\?zipName"
|
||||
Pop $0
|
||||
${If} $0 == "success"
|
||||
ZipDLL::extractall "$INSTDIR\?zipName" "$INSTDIR\?dir"
|
||||
Delete "$INSTDIR\?zipName"
|
||||
${Else}
|
||||
MessageBox mb_iconstop "Error: $0" ;Show cancel/error message
|
||||
${EndIf}
|
||||
; Maximum compression!
|
||||
SetCompressor /SOLID /FINAL lzma
|
||||
|
||||
# if d.len >= 6:
|
||||
# let startMenuEntry = d[5]
|
||||
# let e = splitFile(startMenuEntry).name.capitalize
|
||||
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\?{e}.lnk" "$INSTDIR\?dir\?{startMenuEntry.toWin}"
|
||||
# end if
|
||||
; Installer and Uninstaller Icons
|
||||
; Icon "nimrod.ico"
|
||||
; UninstallIcon "nimrod.ico"
|
||||
|
||||
; Shortcuts
|
||||
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
|
||||
!insertmacro MUI_STARTMENU_WRITE_END
|
||||
; Set installation details to be shown by default
|
||||
ShowInstDetails show
|
||||
ShowUnInstDetails show
|
||||
|
||||
;--------------------------------
|
||||
; Interface Settings
|
||||
|
||||
; Warn the user if aborting during installation/uninstallation
|
||||
!define MUI_ABORTWARNING
|
||||
!define MUI_UNABORTWARNING
|
||||
|
||||
; Don't show a description for sections
|
||||
!define MUI_COMPONENTSPAGE_NODESC
|
||||
|
||||
;--------------------------------
|
||||
; Pages
|
||||
|
||||
; Setup the installer pages
|
||||
!insertmacro MUI_PAGE_WELCOME
|
||||
!insertmacro MUI_PAGE_LICENSE "?{expandFilename(c.license)}"
|
||||
!insertmacro MUI_PAGE_COMPONENTS
|
||||
!insertmacro MUI_PAGE_DIRECTORY
|
||||
|
||||
; Setup the start menu entry page
|
||||
var ICONS_GROUP
|
||||
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "?{c.displayName}"
|
||||
!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}"
|
||||
!insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP
|
||||
|
||||
!insertmacro MUI_PAGE_INSTFILES
|
||||
!insertmacro MUI_PAGE_FINISH
|
||||
|
||||
; Setup the uninstaller pages
|
||||
!insertmacro MUI_UNPAGE_CONFIRM
|
||||
!insertmacro MUI_UNPAGE_INSTFILES
|
||||
|
||||
;--------------------------------
|
||||
;Languages
|
||||
|
||||
!insertmacro MUI_LANGUAGE "English"
|
||||
|
||||
;--------------------------------
|
||||
;Installer Sections
|
||||
|
||||
; The core section. This is comprised of a base Nim installation,
|
||||
; such as what would be retrieved via git, and an already bootstrapped
|
||||
; Nim binary.
|
||||
Section "Core Files" CoreSection
|
||||
; This is a mandotory section
|
||||
SectionIn RO
|
||||
|
||||
; Output files to the base installation directory
|
||||
SetOutPath "$INSTDIR"
|
||||
|
||||
; Only overwrite newer files
|
||||
SetOverwrite ifnewer
|
||||
|
||||
; Write all the files to the output directory.
|
||||
#for i in low(TFileCategory)..fcWindows:
|
||||
# for f in items(c.cat[i]):
|
||||
SetOutPath "$INSTDIR\?{splitFile(f).dir.toWin}"
|
||||
File "?{expandFilename(f).toWin}"
|
||||
# end for
|
||||
#end for
|
||||
|
||||
; Write out the uninstaller
|
||||
WriteUninstaller "$INSTDIR\uninstaller.exe"
|
||||
SectionEnd
|
||||
#end
|
||||
|
||||
Section -AdditionalIcons
|
||||
SetOutPath $INSTDIR
|
||||
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
|
||||
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\uninst.exe"
|
||||
!insertmacro MUI_STARTMENU_WRITE_END
|
||||
SectionEnd
|
||||
Section "-Add Registry Keys" RegistrySection
|
||||
; Write application registry keys
|
||||
WriteRegStr HKCU "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\bin\?{c.name}.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}" "DisplayIcon" "$INSTDIR\bin\?{c.name}.exe"
|
||||
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
|
||||
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
|
||||
; Reset the output path
|
||||
SetOutPath "$INSTDIR"
|
||||
SectionEnd
|
||||
|
||||
Section -Post
|
||||
WriteUninstaller "$INSTDIR\uninst.exe"
|
||||
WriteRegStr HKCU "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\bin\?{c.name}.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}" "DisplayIcon" "$INSTDIR\bin\?{c.name}.exe"
|
||||
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
|
||||
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
|
||||
SectionEnd
|
||||
; Section for adding the shortcuts related to files and applications
|
||||
Section "-Setup Shortcuts" ShortcutsSection
|
||||
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
|
||||
CreateDirectory "$SMPROGRAMS\$ICONS_GROUP"
|
||||
|
||||
Function .onInit
|
||||
!insertmacro MULTIUSER_INIT
|
||||
FunctionEnd
|
||||
#if c.app == appConsole:
|
||||
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\?{c.displayName}.lnk" "$INSTDIR\start.bat"
|
||||
CreateShortCut "$DESKTOP\?{c.displayName}.lnk" "$INSTDIR\start.bat"
|
||||
#else:
|
||||
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\?{c.displayName}.lnk" "$INSTDIR\?{c.name}.exe"
|
||||
CreateShortCut "$DESKTOP\?{c.displayName}.lnk" "$INSTDIR\?{c.name}.exe"
|
||||
#end if
|
||||
|
||||
Function un.onUninstSuccess
|
||||
HideWindow
|
||||
MessageBox MB_ICONINFORMATION|MB_OK "Uninstall was completed successfully."
|
||||
FunctionEnd
|
||||
; Add shortcuts for the documentation
|
||||
#for f in items(c.cat[fcDocStart]):
|
||||
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\?{splitFile(f).name}.lnk" "$INSTDIR\?{f.toWin}"
|
||||
#end for
|
||||
|
||||
Function un.onInit
|
||||
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Remove $(^Name) from your computer." IDYES +2
|
||||
Abort
|
||||
!insertmacro MULTIUSER_UNINIT
|
||||
FunctionEnd
|
||||
; Write the shortcut to the uninstaller
|
||||
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\uninstaller.exe"
|
||||
!insertmacro MUI_STARTMENU_WRITE_END
|
||||
SectionEnd
|
||||
|
||||
Section Uninstall
|
||||
!insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP
|
||||
Delete "$DESKTOP\?{c.displayName}.lnk"
|
||||
; Section for adding tools to the PATH variable
|
||||
Section "Setup Path Environment" PathSection
|
||||
${EnvVarUpdate} $R0 "PATH" "A" "HKCU" "$INSTDIR\dist\mingw"
|
||||
${EnvVarUpdate} $R0 "PATH" "A" "HKCU" "$INSTDIR\bin"
|
||||
${EnvVarUpdate} $R0 "PATH" "A" "HKCU" "$INSTDIR\dist\babel"
|
||||
SectionEnd
|
||||
|
||||
RMDir /r "$SMPROGRAMS\$ICONS_GROUP"
|
||||
RMDir /r "$INSTDIR"
|
||||
; The downloadable sections. These sections are automatically generated by
|
||||
; niminst and the template filters.
|
||||
#var i = 0
|
||||
#for download in c.downloads:
|
||||
# inc i
|
||||
# let d = download.split('|')
|
||||
# if d.len != 5 and d.len != 6:
|
||||
# quit("download string needs 5..6 parts: " & download)
|
||||
# end if
|
||||
# let sectionName = d[0]
|
||||
# let dir = d[1]
|
||||
# let zipName = d[2]
|
||||
# let size = d[3]
|
||||
# let url = d[4]
|
||||
Section /o "?sectionName" ?{i}Section
|
||||
; Add the section size to the total size.
|
||||
AddSize ?size
|
||||
|
||||
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
|
||||
DeleteRegKey HKCU "${PRODUCT_DIR_REGKEY}"
|
||||
SetAutoClose true
|
||||
SectionEnd
|
||||
; Download the file, and if successful, extract it to the given directory
|
||||
; otherwise,
|
||||
retry:
|
||||
NSISdl::download "?url" "$TEMP\?zipName"
|
||||
Pop $0
|
||||
${If} $0 == "success"
|
||||
ZipDLL::extractall "$TEMP\?zipName" "$INSTDIR\?dir"
|
||||
Delete "$TEMP\?zipName"
|
||||
${Else}
|
||||
MessageBox MB_ICONSTOP|MB_ABORTRETRYIGNORE "Error: $0" IDRETRY retry IDIGNORE ignore
|
||||
abort
|
||||
${EndIf}
|
||||
|
||||
# if d.len >= 6:
|
||||
# let startMenuEntry = d[5]
|
||||
# let e = splitFile(startMenuEntry).name.capitalize
|
||||
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\?{e}.lnk" "$INSTDIR\?dir\?{startMenuEntry.toWin}"
|
||||
# end if
|
||||
|
||||
; Shortcuts
|
||||
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
|
||||
!insertmacro MUI_STARTMENU_WRITE_END
|
||||
ignore:
|
||||
SectionEnd
|
||||
#end
|
||||
|
||||
;--------------------------------
|
||||
; Section Descriptions
|
||||
; Series of strings describing each section
|
||||
; LangString DESC_CoreSection ${LANG_ENGLISH} "Core Nim files"
|
||||
|
||||
; The macros to actually insert the descriptions into the sections.
|
||||
; Each description above should have a corresponding MUI_DESCRIPTION_TEXT
|
||||
; macro linking the section to the description.
|
||||
; !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
|
||||
; !insertmacro MUI_DESCRIPTION_TEXT ${CoreSection} $(DESC_CoreSection)
|
||||
; !insertmacro MUI_FUNCTION_DESCRIPTION_END
|
||||
|
||||
|
||||
;--------------------------------
|
||||
; Uninstaller Sections
|
||||
|
||||
Section "Uninstall"
|
||||
; Remove previously created shortcuts
|
||||
!insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP
|
||||
Delete "$DESKTOP\?{c.displayName}.lnk"
|
||||
|
||||
; Remove installed application files
|
||||
RMDir /r "$SMPROGRAMS\$ICONS_GROUP"
|
||||
RMDir /r "$INSTDIR"
|
||||
|
||||
; Remove the previously created registry key
|
||||
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
|
||||
DeleteRegKey HKCU "${PRODUCT_DIR_REGKEY}"
|
||||
SetAutoClose true
|
||||
|
||||
; Remove entries from the PATH environment variable
|
||||
${un.EnvVarUpdate} $R0 "PATH" "R" "HKCU" "$INSTDIR\dist\mingw"
|
||||
${un.EnvVarUpdate} $R0 "PATH" "R" "HKCU" "$INSTDIR\bin"
|
||||
${un.EnvVarUpdate} $R0 "PATH" "R" "HKCU" "$INSTDIR\dist\babel"
|
||||
SectionEnd
|
||||
|
||||
;--------------------------------
|
||||
; Function hooks
|
||||
|
||||
Function .onInit
|
||||
${GetRoot} "$EXEDIR" $R0
|
||||
strCpy $INSTDIR "$R0\?{c.name}"
|
||||
FunctionEnd
|
||||
Loading…
Add table
Add a link
Reference in a new issue