pyapp.nsi 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. !define PRODUCT_NAME "[[ib.appname]]"
  2. !define PRODUCT_VERSION "[[ib.version]]"
  3. !define PY_VERSION "[[ib.py_version]]"
  4. !define PY_MAJOR_VERSION "[[ib.py_major_version]]"
  5. !define BITNESS "[[ib.py_bitness]]"
  6. !define ARCH_TAG "[[arch_tag]]"
  7. !define INSTALLER_NAME "[[ib.installer_name]]"
  8. !define PRODUCT_ICON "[[icon]]"
  9. SetCompressor lzma
  10. RequestExecutionLevel admin
  11. [% block modernui %]
  12. ; Modern UI installer stuff
  13. !include "MUI2.nsh"
  14. !define MUI_ABORTWARNING
  15. !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
  16. ; UI pages
  17. [% block ui_pages %]
  18. !insertmacro MUI_PAGE_WELCOME
  19. !insertmacro MUI_PAGE_DIRECTORY
  20. !insertmacro MUI_PAGE_INSTFILES
  21. !insertmacro MUI_PAGE_FINISH
  22. [% endblock ui_pages %]
  23. !insertmacro MUI_LANGUAGE "English"
  24. [% endblock modernui %]
  25. Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
  26. OutFile "${INSTALLER_NAME}"
  27. InstallDir "$PROGRAMFILES${BITNESS}\${PRODUCT_NAME}"
  28. ShowInstDetails show
  29. Section -SETTINGS
  30. SetOutPath "$INSTDIR"
  31. SetOverwrite ifnewer
  32. SectionEnd
  33. [% block sections %]
  34. Section "!${PRODUCT_NAME}" sec_app
  35. SetRegView [[ib.py_bitness]]
  36. SectionIn RO
  37. SetShellVarContext all
  38. File ${PRODUCT_ICON}
  39. SetOutPath "$INSTDIR\pkgs"
  40. File /r "pkgs\*.*"
  41. SetOutPath "$INSTDIR"
  42. [% block install_files %]
  43. ; Install files
  44. [% for destination, group in grouped_files %]
  45. SetOutPath "[[destination]]"
  46. [% for file in group %]
  47. File "[[ file ]]"
  48. [% endfor %]
  49. [% endfor %]
  50. ; Install directories
  51. [% for dir, destination in ib.install_dirs %]
  52. SetOutPath "[[ pjoin(destination, dir) ]]"
  53. File /r "[[dir]]\*.*"
  54. [% endfor %]
  55. [% endblock install_files %]
  56. [% block install_shortcuts %]
  57. ; Install shortcuts
  58. ; The output path becomes the working directory for shortcuts
  59. SetOutPath "%HOMEDRIVE%\%HOMEPATH%"
  60. [% if single_shortcut %]
  61. [% for scname, sc in ib.shortcuts.items() %]
  62. CreateShortCut "$SMPROGRAMS\[[scname]].lnk" "[[sc['target'] ]]" \
  63. '[[ sc['parameters'] ]]' "$INSTDIR\[[ sc['icon'] ]]"
  64. [% endfor %]
  65. [% else %]
  66. [# Multiple shortcuts: create a directory for them #]
  67. CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
  68. [% for scname, sc in ib.shortcuts.items() %]
  69. CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\[[scname]].lnk" "[[sc['target'] ]]" \
  70. '[[ sc['parameters'] ]]' "$INSTDIR\[[ sc['icon'] ]]"
  71. [% endfor %]
  72. [% endif %]
  73. SetOutPath "$INSTDIR"
  74. [% endblock install_shortcuts %]
  75. [% block install_commands %]
  76. [% if has_commands %]
  77. nsExec::ExecToLog '[[ python ]] -Es "$INSTDIR\_rewrite_shebangs.py" "$INSTDIR\bin"'
  78. nsExec::ExecToLog '[[ python ]] -Es "$INSTDIR\_system_path.py" add "$INSTDIR\bin"'
  79. [% endif %]
  80. [% endblock install_commands %]
  81. ; Byte-compile Python files.
  82. DetailPrint "Byte-compiling Python modules..."
  83. nsExec::ExecToLog '[[ python ]] -m compileall -q "$INSTDIR\pkgs"'
  84. WriteUninstaller $INSTDIR\uninstall.exe
  85. ; Add ourselves to Add/remove programs
  86. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  87. "DisplayName" "${PRODUCT_NAME}"
  88. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  89. "UninstallString" '"$INSTDIR\uninstall.exe"'
  90. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  91. "InstallLocation" "$INSTDIR"
  92. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  93. "DisplayIcon" "$INSTDIR\${PRODUCT_ICON}"
  94. [% if ib.publisher is not none %]
  95. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  96. "Publisher" "[[ib.publisher]]"
  97. [% endif %]
  98. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  99. "DisplayVersion" "${PRODUCT_VERSION}"
  100. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  101. "NoModify" 1
  102. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  103. "NoRepair" 1
  104. ; Check if we need to reboot
  105. IfRebootFlag 0 noreboot
  106. MessageBox MB_YESNO "A reboot is required to finish the installation. Do you wish to reboot now?" \
  107. /SD IDNO IDNO noreboot
  108. Reboot
  109. noreboot:
  110. SectionEnd
  111. Section "Uninstall"
  112. SetRegView [[ib.py_bitness]]
  113. SetShellVarContext all
  114. Delete $INSTDIR\uninstall.exe
  115. Delete "$INSTDIR\${PRODUCT_ICON}"
  116. RMDir /r "$INSTDIR\pkgs"
  117. ; Remove ourselves from %PATH%
  118. [% block uninstall_commands %]
  119. [% if has_commands %]
  120. nsExec::ExecToLog '[[ python ]] -Es "$INSTDIR\_system_path.py" remove "$INSTDIR\bin"'
  121. [% endif %]
  122. [% endblock uninstall_commands %]
  123. [% block uninstall_files %]
  124. ; Uninstall files
  125. [% for file, destination in ib.install_files %]
  126. Delete "[[pjoin(destination, file)]]"
  127. [% endfor %]
  128. ; Uninstall directories
  129. [% for dir, destination in ib.install_dirs %]
  130. RMDir /r "[[pjoin(destination, dir)]]"
  131. [% endfor %]
  132. [% endblock uninstall_files %]
  133. [% block uninstall_shortcuts %]
  134. ; Uninstall shortcuts
  135. [% if single_shortcut %]
  136. [% for scname in ib.shortcuts %]
  137. Delete "$SMPROGRAMS\[[scname]].lnk"
  138. [% endfor %]
  139. [% else %]
  140. RMDir /r "$SMPROGRAMS\${PRODUCT_NAME}"
  141. [% endif %]
  142. [% endblock uninstall_shortcuts %]
  143. RMDir $INSTDIR
  144. DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
  145. SectionEnd
  146. [% endblock sections %]
  147. ; Functions
  148. Function .onMouseOverSection
  149. ; Find which section the mouse is over, and set the corresponding description.
  150. FindWindow $R0 "#32770" "" $HWNDPARENT
  151. GetDlgItem $R0 $R0 1043 ; description item (must be added to the UI)
  152. [% block mouseover_messages %]
  153. StrCmp $0 ${sec_app} "" +2
  154. SendMessage $R0 ${WM_SETTEXT} 0 "STR:${PRODUCT_NAME}"
  155. [% endblock mouseover_messages %]
  156. FunctionEnd