Ultimaker-Cura.nsi.jinja 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. # Copyright (c) 2022 UltiMaker B.V.
  2. # Cura's build system is released under the terms of the AGPLv3 or higher.
  3. !define APP_NAME "{{ app_name }}"
  4. !define COMP_NAME "{{ company }}"
  5. !define WEB_SITE "{{ web_site }}"
  6. !define VERSION "{{ version }}"
  7. !define VIVERSION "{{ version_major }}.{{ version_minor }}.{{ version_patch }}.0"
  8. !define COPYRIGHT "Copyright (c) {{ year }} {{ company }}"
  9. !define DESCRIPTION "Application"
  10. !define LICENSE_TXT "{{ cura_license_file }}"
  11. !define INSTALLER_NAME "{{ destination }}"
  12. !define MAIN_APP_EXE "{{ main_app }}"
  13. !define INSTALL_TYPE "SetShellVarContext all"
  14. !define REG_ROOT "HKLM"
  15. !define REG_APP_PATH "Software\Microsoft\Windows\CurrentVersion\App Paths\${APP_NAME}-${VERSION}"
  16. !define UNINSTALL_PATH "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}-${VERSION}"
  17. !define REG_START_MENU "Start Menu Folder"
  18. ;Require administrator access
  19. RequestExecutionLevel admin
  20. var SM_Folder
  21. ######################################################################
  22. VIProductVersion "${VIVERSION}"
  23. VIAddVersionKey "ProductName" "{{ app_name }}"
  24. VIAddVersionKey "CompanyName" "${COMP_NAME}"
  25. VIAddVersionKey "LegalCopyright" "${COPYRIGHT}"
  26. VIAddVersionKey "FileDescription" "${DESCRIPTION}"
  27. VIAddVersionKey "FileVersion" "${VIVERSION}"
  28. ######################################################################
  29. SetCompressor {{ compression_method }}
  30. Name "${APP_NAME}"
  31. Caption "${APP_NAME}"
  32. OutFile "${INSTALLER_NAME}"
  33. BrandingText "${APP_NAME}"
  34. InstallDir "$PROGRAMFILES64\${APP_NAME}"
  35. ######################################################################
  36. !include "MUI2.nsh"
  37. !include fileassoc.nsh
  38. !define MUI_ABORTWARNING
  39. !define MUI_UNABORTWARNING
  40. !define MUI_ICON "{{ cura_icon }}"
  41. !define MUI_WELCOMEFINISHPAGE_BITMAP "{{ cura_banner_img }}"
  42. !define MUI_UNWELCOMEFINISHPAGE_BITMAP "{{ cura_banner_img }}"
  43. !insertmacro MUI_PAGE_WELCOME
  44. !ifdef LICENSE_TXT
  45. !insertmacro MUI_PAGE_LICENSE "${LICENSE_TXT}"
  46. !endif
  47. !insertmacro MUI_PAGE_DIRECTORY
  48. !ifdef REG_START_MENU
  49. !define MUI_STARTMENUPAGE_NODISABLE
  50. !define MUI_STARTMENUPAGE_DEFAULTFOLDER "UltiMaker Cura"
  51. !define MUI_STARTMENUPAGE_REGISTRY_ROOT "${REG_ROOT}"
  52. !define MUI_STARTMENUPAGE_REGISTRY_KEY "${UNINSTALL_PATH}"
  53. !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${REG_START_MENU}"
  54. !insertmacro MUI_PAGE_STARTMENU Application $SM_Folder
  55. !endif
  56. !insertmacro MUI_PAGE_INSTFILES
  57. # Set up explorer to run Cura instead of directly, so it's not executed elevated (with all negative consequences that brings for an unelevated user).
  58. !define MUI_FINISHPAGE_RUN "$WINDIR\explorer.exe"
  59. !define MUI_FINISHPAGE_RUN_PARAMETERS "$INSTDIR\${MAIN_APP_EXE}"
  60. !insertmacro MUI_PAGE_FINISH
  61. !insertmacro MUI_UNPAGE_CONFIRM
  62. !insertmacro MUI_UNPAGE_INSTFILES
  63. !insertmacro MUI_UNPAGE_FINISH
  64. !insertmacro MUI_LANGUAGE "English"
  65. ######################################################################
  66. Section -MainProgram
  67. ${INSTALL_TYPE}
  68. SetOverwrite ifnewer
  69. {% for out_path, files in mapped_out_paths.items() %}SetOutPath "{{ out_path }}"{% for file in files %}
  70. File "{{ file[0] }}"{% endfor %}
  71. {% endfor %}SectionEnd
  72. ######################################################################
  73. Section -Extension_Reg
  74. !insertmacro APP_ASSOCIATE "stl" "Cura.model" "Standard Tessellation Language (STL) files" "$INSTDIR\${MAIN_APP_EXE},0" "Open with {{ app_name }}" "$INSTDIR\${MAIN_APP_EXE} $\"%1$\""
  75. !insertmacro APP_ASSOCIATE "3mf" "Cura.project" "3D Manufacturing Format (3MF) files" "$INSTDIR\${MAIN_APP_EXE},0" "Open with {{ app_name }}" "$INSTDIR\${MAIN_APP_EXE} $\"%1$\""
  76. SectionEnd
  77. Section -Icons_Reg
  78. SetOutPath "$INSTDIR"
  79. WriteUninstaller "$INSTDIR\uninstall.exe"
  80. !ifdef REG_START_MENU
  81. !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
  82. CreateDirectory "$SMPROGRAMS\$SM_Folder"
  83. CreateShortCut "$SMPROGRAMS\$SM_Folder\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}"
  84. CreateShortCut "$SMPROGRAMS\$SM_Folder\Uninstall ${APP_NAME}.lnk" "$INSTDIR\uninstall.exe"
  85. !ifdef WEB_SITE
  86. WriteIniStr "$INSTDIR\UltiMaker Cura website.url" "InternetShortcut" "URL" "${WEB_SITE}"
  87. CreateShortCut "$SMPROGRAMS\$SM_Folder\UltiMaker Cura website.lnk" "$INSTDIR\UltiMaker Cura website.url"
  88. !endif
  89. !insertmacro MUI_STARTMENU_WRITE_END
  90. !endif
  91. !ifndef REG_START_MENU
  92. CreateDirectory "$SMPROGRAMS\{{ app_name }}"
  93. CreateShortCut "$SMPROGRAMS\{{ app_name }}\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}"
  94. CreateShortCut "$SMPROGRAMS\{{ app_name }}\Uninstall ${APP_NAME}.lnk" "$INSTDIR\uninstall.exe"
  95. !ifdef WEB_SITE
  96. WriteIniStr "$INSTDIR\UltiMaker Cura website.url" "InternetShortcut" "URL" "${WEB_SITE}"
  97. CreateShortCut "$SMPROGRAMS\{{ app_name }}\UltiMaker Cura website.lnk" "$INSTDIR\UltiMaker Cura website.url"
  98. !endif
  99. !endif
  100. WriteRegStr ${REG_ROOT} "${REG_APP_PATH}" "" "$INSTDIR\${MAIN_APP_EXE}"
  101. WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayName" "${APP_NAME}"
  102. WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "UninstallString" "$INSTDIR\uninstall.exe"
  103. WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "QuietUninstallString" '"$INSTDIR\uninstall.exe" /S'
  104. WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayIcon" "$INSTDIR\${MAIN_APP_EXE}"
  105. WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayVersion" "${VERSION}"
  106. WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "Publisher" "${COMP_NAME}"
  107. !ifdef WEB_SITE
  108. WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "URLInfoAbout" "${WEB_SITE}"
  109. !endif
  110. SectionEnd
  111. ######################################################################
  112. Section UrlProtocol
  113. WriteRegStr HKCR "cura" "" "URL:cura"
  114. WriteRegStr HKCR "cura" "URL Protocol" ""
  115. WriteRegStr HKCR "cura\DefaultIcon" "" "$INSTDIR\${MAIN_APP_EXE},1"
  116. WriteRegStr HKCR "cura\shell" "" "open"
  117. WriteRegStr HKCR "cura\shell\open\command" "" '"$INSTDIR\${MAIN_APP_EXE}" "%1"'
  118. WriteRegStr HKCR "slicer" "" "URL:slicer"
  119. WriteRegStr HKCR "slicer" "URL Protocol" ""
  120. WriteRegStr HKCR "slicer\DefaultIcon" "" "$INSTDIR\${MAIN_APP_EXE},1"
  121. WriteRegStr HKCR "slicer\shell" "" "open"
  122. WriteRegStr HKCR "slicer\shell\open\command" "" '"$INSTDIR\${MAIN_APP_EXE}" "%1"'
  123. SectionEnd
  124. ######################################################################
  125. Section Uninstall
  126. ${INSTALL_TYPE}{% for files in mapped_out_paths.values() %}{% for file in files %}
  127. Delete "{{ file[1] }}"{% endfor %}{% endfor %}{% for rem_dir in rmdir_paths %}
  128. RmDir "{{ rem_dir }}"{% endfor %}
  129. # FIXME: dirty solution, but for some reason these directories aren't removed
  130. RmDir "$INSTDIR\share\cura\resources\scripts"
  131. RmDir "$INSTDIR\share\cura\resources"
  132. RmDir "$INSTDIR\share\cura"
  133. RmDir "$INSTDIR\share\uranium\resources\scripts"
  134. RmDir "$INSTDIR\share\uranium\resources"
  135. RmDir "$INSTDIR\share\uranium"
  136. RmDir "$INSTDIR\share"
  137. Delete "$INSTDIR\uninstall.exe"
  138. !ifdef WEB_SITE
  139. Delete "$INSTDIR\${APP_NAME} website.url"
  140. !endif
  141. RmDir /r /REBOOTOK "$INSTDIR"
  142. !ifdef REG_START_MENU
  143. !insertmacro MUI_STARTMENU_GETFOLDER "Application" $SM_Folder
  144. Delete "$SMPROGRAMS\$SM_Folder\${APP_NAME}.lnk"
  145. Delete "$SMPROGRAMS\$SM_Folder\Uninstall ${APP_NAME}.lnk"
  146. !ifdef WEB_SITE
  147. Delete "$SMPROGRAMS\$SM_Folder\UltiMaker Cura website.lnk"
  148. !endif
  149. RmDir "$SMPROGRAMS\$SM_Folder"
  150. !endif
  151. !ifndef REG_START_MENU
  152. Delete "$SMPROGRAMS\{{ app_name }}\${APP_NAME}.lnk"
  153. Delete "$SMPROGRAMS\{{ app_name }}\Uninstall ${APP_NAME}.lnk"
  154. !ifdef WEB_SITE
  155. Delete "$SMPROGRAMS\{{ app_name }}\UltiMaker Cura website.lnk"
  156. !endif
  157. RmDir "$SMPROGRAMS\{{ app_name }}"
  158. !endif
  159. !insertmacro APP_UNASSOCIATE "stl" "Cura.model"
  160. !insertmacro APP_UNASSOCIATE "3mf" "Cura.project"
  161. ; Unassociate file associations for 'cura' protocol
  162. DeleteRegKey HKCR "cura"
  163. ; Unassociate file associations for 'slicer' protocol
  164. DeleteRegKey HKCR "slicer"
  165. DeleteRegKey ${REG_ROOT} "${REG_APP_PATH}"
  166. DeleteRegKey ${REG_ROOT} "${UNINSTALL_PATH}"
  167. SectionEnd