Ultimaker-Cura.nsi.jinja 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. # Copyright (c) 2024 UltiMaker
  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 SIGN_SECRET "{{ sign_secret }}"
  18. !define REG_START_MENU "Start Menu Folder"
  19. ;Require administrator access
  20. RequestExecutionLevel admin
  21. var SM_Folder
  22. ######################################################################
  23. VIProductVersion "${VIVERSION}"
  24. VIAddVersionKey "ProductName" "{{ app_name }}"
  25. VIAddVersionKey "CompanyName" "${COMP_NAME}"
  26. VIAddVersionKey "LegalCopyright" "${COPYRIGHT}"
  27. VIAddVersionKey "FileDescription" "${DESCRIPTION}"
  28. VIAddVersionKey "FileVersion" "${VIVERSION}"
  29. ######################################################################
  30. SetCompressor {{ compression_method }}
  31. Name "${APP_NAME}"
  32. Caption "${APP_NAME}"
  33. OutFile "${INSTALLER_NAME}"
  34. BrandingText "${APP_NAME}"
  35. InstallDir "$PROGRAMFILES64\${APP_NAME}"
  36. ######################################################################
  37. !include "MUI2.nsh"
  38. !include fileassoc.nsh
  39. !define MUI_ABORTWARNING
  40. !define MUI_UNABORTWARNING
  41. !define MUI_ICON "{{ cura_icon }}"
  42. !define MUI_WELCOMEFINISHPAGE_BITMAP "{{ cura_banner_img }}"
  43. !define MUI_UNWELCOMEFINISHPAGE_BITMAP "{{ cura_banner_img }}"
  44. !insertmacro MUI_PAGE_WELCOME
  45. !ifdef LICENSE_TXT
  46. !insertmacro MUI_PAGE_LICENSE "${LICENSE_TXT}"
  47. !endif
  48. !insertmacro MUI_PAGE_DIRECTORY
  49. !ifdef REG_START_MENU
  50. !define MUI_STARTMENUPAGE_NODISABLE
  51. !define MUI_STARTMENUPAGE_DEFAULTFOLDER "UltiMaker Cura"
  52. !define MUI_STARTMENUPAGE_REGISTRY_ROOT "${REG_ROOT}"
  53. !define MUI_STARTMENUPAGE_REGISTRY_KEY "${UNINSTALL_PATH}"
  54. !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${REG_START_MENU}"
  55. !insertmacro MUI_PAGE_STARTMENU Application $SM_Folder
  56. !endif
  57. !insertmacro MUI_PAGE_INSTFILES
  58. # 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).
  59. !define MUI_FINISHPAGE_RUN "$WINDIR\explorer.exe"
  60. !define MUI_FINISHPAGE_RUN_PARAMETERS "$INSTDIR\${MAIN_APP_EXE}"
  61. !insertmacro MUI_PAGE_FINISH
  62. !insertmacro MUI_UNPAGE_CONFIRM
  63. !insertmacro MUI_UNPAGE_INSTFILES
  64. !insertmacro MUI_UNPAGE_FINISH
  65. !insertmacro MUI_LANGUAGE "English"
  66. ######################################################################
  67. Section -MainProgram
  68. ${INSTALL_TYPE}
  69. SetOverwrite ifnewer
  70. {% for out_path, files in mapped_out_paths.items() %}SetOutPath "{{ out_path }}"{% for file in files %}
  71. File "{{ file[0] }}"{% endfor %}
  72. {% endfor %}SectionEnd
  73. ######################################################################
  74. Section -Extension_Reg
  75. !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$\""
  76. !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$\""
  77. SectionEnd
  78. Section -Icons_Reg
  79. SetOutPath "$INSTDIR"
  80. WriteUninstaller "$INSTDIR\uninstall.exe"
  81. !ifdef REG_START_MENU
  82. !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
  83. CreateDirectory "$SMPROGRAMS\$SM_Folder"
  84. CreateShortCut "$SMPROGRAMS\$SM_Folder\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}"
  85. CreateShortCut "$SMPROGRAMS\$SM_Folder\Uninstall ${APP_NAME}.lnk" "$INSTDIR\uninstall.exe"
  86. !ifdef WEB_SITE
  87. WriteIniStr "$INSTDIR\UltiMaker Cura website.url" "InternetShortcut" "URL" "${WEB_SITE}"
  88. CreateShortCut "$SMPROGRAMS\$SM_Folder\UltiMaker Cura website.lnk" "$INSTDIR\UltiMaker Cura website.url"
  89. !endif
  90. !insertmacro MUI_STARTMENU_WRITE_END
  91. !endif
  92. !ifndef REG_START_MENU
  93. CreateDirectory "$SMPROGRAMS\{{ app_name }}"
  94. CreateShortCut "$SMPROGRAMS\{{ app_name }}\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}"
  95. CreateShortCut "$SMPROGRAMS\{{ app_name }}\Uninstall ${APP_NAME}.lnk" "$INSTDIR\uninstall.exe"
  96. !ifdef WEB_SITE
  97. WriteIniStr "$INSTDIR\UltiMaker Cura website.url" "InternetShortcut" "URL" "${WEB_SITE}"
  98. CreateShortCut "$SMPROGRAMS\{{ app_name }}\UltiMaker Cura website.lnk" "$INSTDIR\UltiMaker Cura website.url"
  99. !endif
  100. !endif
  101. WriteRegStr ${REG_ROOT} "${REG_APP_PATH}" "" "$INSTDIR\${MAIN_APP_EXE}"
  102. WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayName" "${APP_NAME}"
  103. WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "UninstallString" "$INSTDIR\uninstall.exe"
  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
  168. !ifdef SIGN_SECRET
  169. !uninstfinalize 'signtool sign /v /fd sha256 /tr http://timestamp.sectigo.com /td sha256 /f C:\actions-runner\code_sign.cer /csp "eToken Base Cryptographic Provider" /kc ${SIGN_SECRET} "${INSTDIR}\uninstall.exe"' = 0
  170. ; %1 is replaced by the uninstaller exe to be signed.
  171. !endif