diff options
Diffstat (limited to 'tools/niminst/nsis.tmpl')
-rw-r--r-- | tools/niminst/nsis.tmpl | 255 |
1 files changed, 255 insertions, 0 deletions
diff --git a/tools/niminst/nsis.tmpl b/tools/niminst/nsis.tmpl new file mode 100644 index 000000000..c4270081e --- /dev/null +++ b/tools/niminst/nsis.tmpl @@ -0,0 +1,255 @@ +#! stdtmpl(subsChar='?') | standard +#proc generateNsisSetup(c: TConfigData): string = +# result = "; NSIS script generated by niminst\n" & +# "; To regenerate run ``niminst nsis`` or ``koch nsis``\n" + +;-------------------------------- +; Included headers + ; Modern User Interface 2.0 Header + !include "MUI2.nsh" + + ; File Functions Header, used to get the current drive root. + !include "FileFunc.nsh" + + ; *Patched* Environment Variable Manipulation Header, used to add + ; tools to the user's PATH environment variable. + !include "EnvVarUpdate.nsh" + +;-------------------------------- +; 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" + + +;-------------------------------- +; General Setup Information + + ; Name and output file + Name "?{c.name} ?{c.version}" + OutFile "?{c.name}_?{c.version}.exe" + + ; 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" "" + + ; Request user level application privileges. + RequestExecutionLevel user + + ; Allow installation to the root drive directory. + AllowRootDirInstall true + + ; Maximum compression! + SetCompressor /SOLID /FINAL lzma + + ; Installer and Uninstaller Icons + ; Icon "nimrod.ico" + ; UninstallIcon "nimrod.ico" + + ; 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 + + 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 for adding the shortcuts related to files and applications + Section "-Setup Shortcuts" ShortcutsSection + !insertmacro MUI_STARTMENU_WRITE_BEGIN Application + CreateDirectory "$SMPROGRAMS\$ICONS_GROUP" + + #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 + + ; 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 + + ; Write the shortcut to the uninstaller + CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\uninstaller.exe" + !insertmacro MUI_STARTMENU_WRITE_END + SectionEnd + + ; 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 + + ; 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 + + ; 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 \ No newline at end of file |