You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
5.0KB

  1. !include "MUI2.nsh"
  2. !define NAME_FULL "VCV Rack Free ${VERSION}"
  3. !define NAME "VCV Rack ${VERSION_MAJOR} Free"
  4. !define RACK_DIR "Rack${VERSION_MAJOR}Free"
  5. !define INSTALL_REG "Software\VCV\Rack${VERSION_MAJOR}Free"
  6. !define UNINSTALL_REG "Software\Microsoft\Windows\CurrentVersion\Uninstall\VCVRack${VERSION_MAJOR}Free"
  7. Name "${NAME_FULL}"
  8. Unicode True
  9. SetCompressor /solid "lzma"
  10. SetCompressorDictSize 8
  11. CRCCheck On
  12. ; Default installation folder
  13. InstallDir "$PROGRAMFILES\VCV\${RACK_DIR}"
  14. ; Get installation folder from registry if available
  15. InstallDirRegKey HKLM "${INSTALL_REG}" ""
  16. ; Request admin permissions so we can install to Program Files and add a registry entry
  17. RequestExecutionLevel admin
  18. ; MUI installer pages
  19. !define MUI_ICON "icon.ico"
  20. ;!define MUI_HEADERIMAGE
  21. ;!define MUI_HEADERIMAGE_BITMAP "installer-banner.bmp" ; 150x57
  22. ;!define MUI_WELCOMEFINISHPAGE_BITMAP "$NSISDIR\Contrib\Graphics\Wizard\win.bmp" ; 164x314
  23. ;!define MUI_UNWELCOMEFINISHPAGE_BITMAP "$NSISDIR\Contrib\Graphics\Wizard\win.bmp" ; 164x314
  24. !define MUI_COMPONENTSPAGE_NODESC
  25. ;!insertmacro MUI_PAGE_COMPONENTS
  26. ; Prevent user from choosing an installation directory that already exists, such as C:\Program Files.
  27. ; This is necessary because the uninstaller removes the installation directory, which is dangerous for directories that existed before Rack was installed.
  28. !define MUI_PAGE_CUSTOMFUNCTION_LEAVE directoryLeave
  29. Function directoryLeave
  30. StrCmp "$INSTDIR" "$PROGRAMFILES" directoryBad
  31. StrCmp "$INSTDIR" "$PROGRAMFILES32" directoryBad
  32. StrCmp "$INSTDIR" "$PROGRAMFILES64" directoryBad
  33. StrCmp "$INSTDIR" "$COMMONFILES" directoryBad
  34. StrCmp "$INSTDIR" "$COMMONFILES32" directoryBad
  35. StrCmp "$INSTDIR" "$COMMONFILES64" directoryBad
  36. StrCmp "$INSTDIR" "$DESKTOP" directoryBad
  37. StrCmp "$INSTDIR" "$WINDIR" directoryBad
  38. StrCmp "$INSTDIR" "$SYSDIR" directoryBad
  39. StrCmp "$INSTDIR" "$DOCUMENTS" directoryBad
  40. StrCmp "$INSTDIR" "$MUSIC" directoryBad
  41. StrCmp "$INSTDIR" "$PICTURES" directoryBad
  42. StrCmp "$INSTDIR" "$VIDEOS" directoryBad
  43. StrCmp "$INSTDIR" "$APPDATA" directoryBad
  44. StrCmp "$INSTDIR" "$LOCALAPPDATA" directoryBad
  45. Return
  46. directoryBad:
  47. MessageBox MB_OK|MB_ICONSTOP "Cannot install to $INSTDIR."
  48. Abort
  49. FunctionEnd
  50. !insertmacro MUI_PAGE_DIRECTORY
  51. !insertmacro MUI_PAGE_INSTFILES
  52. !define MUI_FINISHPAGE_RUN "$INSTDIR\Rack.exe"
  53. !define MUI_FINISHPAGE_RUN_TEXT "Launch ${NAME}"
  54. !insertmacro MUI_PAGE_FINISH
  55. ; MUI uninstaller pages
  56. !insertmacro MUI_UNPAGE_CONFIRM
  57. !insertmacro MUI_UNPAGE_INSTFILES
  58. !insertmacro MUI_LANGUAGE "English"
  59. ; Sections
  60. Section "${NAME}" INSTALL_SECTION
  61. SectionIn RO
  62. SetOutPath "$INSTDIR"
  63. # Uninstall existing version silently before installing.
  64. # This is needed because the VST3 adapter used to be a file, and now it is a bundle (folder), and NSIS can't overwrite files with folders.
  65. # "_?=" makes the uninstaller block until exit. Explanation at bottom of page:
  66. # https://nsis.sourceforge.io/Docs/Chapter3.html
  67. # Fails gracefully if uninstaller does not exist.
  68. DetailPrint "Uninstalling existing version"
  69. ExecWait '"$INSTDIR\Uninstall.exe" /S _?=$INSTDIR'
  70. File /r "dist\${RACK_DIR}\*"
  71. ; Store installation folder
  72. WriteRegStr HKLM "${INSTALL_REG}" "" "$INSTDIR"
  73. ; Write uninstaller info
  74. WriteRegStr HKLM "${UNINSTALL_REG}" "DisplayName" "${NAME}"
  75. WriteRegStr HKLM "${UNINSTALL_REG}" "DisplayIcon" '"$INSTDIR\Rack.exe"'
  76. WriteRegStr HKLM "${UNINSTALL_REG}" "DisplayVersion" "${VERSION}"
  77. WriteRegStr HKLM "${UNINSTALL_REG}" "UninstallString" '"$INSTDIR\Uninstall.exe"'
  78. WriteRegStr HKLM "${UNINSTALL_REG}" "QuietUninstallString" '"$INSTDIR\Uninstall.exe" /S'
  79. WriteRegStr HKLM "${UNINSTALL_REG}" "InstallLocation" '"$INSTDIR"'
  80. WriteRegStr HKLM "${UNINSTALL_REG}" "Publisher" "VCV"
  81. SectionGetSize ${INSTALL_SECTION} $0
  82. WriteRegDWORD HKLM "${UNINSTALL_REG}" "EstimatedSize" $0
  83. WriteRegDWORD HKLM "${UNINSTALL_REG}" "NoModify" 1
  84. WriteRegDWORD HKLM "${UNINSTALL_REG}" "NoRepair" 1
  85. ; Create uninstaller
  86. WriteUninstaller "$INSTDIR\Uninstall.exe"
  87. ; Associate file type
  88. WriteRegStr HKLM "Software\Classes\.vcv" "" "VCVRack.Patch"
  89. WriteRegStr HKLM "Software\Classes\VCVRack.Patch" "" "VCV Rack patch"
  90. WriteRegStr HKLM "Software\Classes\VCVRack.Patch\shell\open\command" "" '"$INSTDIR\Rack.exe" "%1"'
  91. ; Create shortcuts
  92. CreateShortcut "$DESKTOP\${NAME}.lnk" "$INSTDIR\Rack.exe"
  93. CreateShortcut "$SMPROGRAMS\${NAME}.lnk" "$INSTDIR\Rack.exe"
  94. ; Add allowed app to Controlled Folder Access
  95. ExpandEnvStrings $0 "%COMSPEC%"
  96. ExecShellWait "" '"$0"' "/C powershell -ExecutionPolicy Bypass -WindowStyle Hidden $\"Add-MpPreference -ControlledFolderAccessAllowedApplications '$INSTDIR\Rack.exe'$\"" SW_HIDE
  97. SectionEnd
  98. Section "Uninstall"
  99. ; directoryLeave above ensures that INSTDIR is safe to remove.
  100. RMDir /r "$INSTDIR"
  101. ; Attempt to remove C:\Program Files\VCV if empty
  102. RMDir "$INSTDIR\.."
  103. Delete "$DESKTOP\${NAME}.lnk"
  104. Delete "$SMPROGRAMS\${NAME}.lnk"
  105. DeleteRegKey HKLM "${INSTALL_REG}"
  106. DeleteRegKey /ifempty HKLM "Software\VCV"
  107. DeleteRegKey HKLM "${UNINSTALL_REG}"
  108. DeleteRegKey HKLM "Software\Classes\.vcv"
  109. DeleteRegKey HKLM "Software\Classes\VCVRack.Patch"
  110. SectionEnd