pyapp.nsi 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. ; Marker file to tell the uninstaller that it's a user installation
  10. !define USER_INSTALL_MARKER _user_install_marker
  11. SetCompressor lzma
  12. !define MULTIUSER_EXECUTIONLEVEL Highest
  13. !define MULTIUSER_INSTALLMODE_DEFAULT_CURRENTUSER
  14. !define MULTIUSER_MUI
  15. !define MULTIUSER_INSTALLMODE_COMMANDLINE
  16. !define MULTIUSER_INSTALLMODE_INSTDIR "[[ib.appname]]"
  17. [% if ib.py_bitness == 64 %]
  18. !define MULTIUSER_INSTALLMODE_FUNCTION correct_prog_files
  19. [% endif %]
  20. !include MultiUser.nsh
  21. [% block modernui %]
  22. ; Modern UI installer stuff
  23. !include "MUI2.nsh"
  24. !define MUI_ABORTWARNING
  25. !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
  26. ; UI pages
  27. [% block ui_pages %]
  28. !insertmacro MUI_PAGE_WELCOME
  29. !insertmacro MULTIUSER_PAGE_INSTALLMODE
  30. !insertmacro MUI_PAGE_DIRECTORY
  31. !insertmacro MUI_PAGE_INSTFILES
  32. !insertmacro MUI_PAGE_FINISH
  33. [% endblock ui_pages %]
  34. !insertmacro MUI_LANGUAGE "English"
  35. [% endblock modernui %]
  36. Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
  37. OutFile "${INSTALLER_NAME}"
  38. ShowInstDetails show
  39. Section -SETTINGS
  40. SetOutPath "$INSTDIR"
  41. SetOverwrite ifnewer
  42. SectionEnd
  43. [% block sections %]
  44. Section "!${PRODUCT_NAME}" sec_app
  45. SetRegView [[ib.py_bitness]]
  46. SectionIn RO
  47. File ${PRODUCT_ICON}
  48. SetOutPath "$INSTDIR\pkgs"
  49. File /r "pkgs\*.*"
  50. SetOutPath "$INSTDIR"
  51. ; Marker file for per-user install
  52. StrCmp $MultiUser.InstallMode CurrentUser 0 +3
  53. FileOpen $0 "$INSTDIR\${USER_INSTALL_MARKER}" w
  54. FileClose $0
  55. SetFileAttributes "$INSTDIR\${USER_INSTALL_MARKER}" HIDDEN
  56. [% block install_files %]
  57. ; Install files
  58. [% for destination, group in grouped_files %]
  59. SetOutPath "[[destination]]"
  60. [% for file in group %]
  61. File "[[ file ]]"
  62. [% endfor %]
  63. [% endfor %]
  64. ; Install directories
  65. [% for dir, destination in ib.install_dirs %]
  66. SetOutPath "[[ pjoin(destination, dir) ]]"
  67. File /r "[[dir]]\*.*"
  68. [% endfor %]
  69. [% endblock install_files %]
  70. [% block install_shortcuts %]
  71. ; Install shortcuts
  72. ; The output path becomes the working directory for shortcuts
  73. SetOutPath "%HOMEDRIVE%\%HOMEPATH%"
  74. [% if single_shortcut %]
  75. [% for scname, sc in ib.shortcuts.items() %]
  76. CreateShortCut "$SMPROGRAMS\[[scname]].lnk" "[[sc['target'] ]]" \
  77. '[[ sc['parameters'] ]]' "$INSTDIR\[[ sc['icon'] ]]"
  78. [% endfor %]
  79. [% else %]
  80. [# Multiple shortcuts: create a directory for them #]
  81. CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
  82. [% for scname, sc in ib.shortcuts.items() %]
  83. CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\[[scname]].lnk" "[[sc['target'] ]]" \
  84. '[[ sc['parameters'] ]]' "$INSTDIR\[[ sc['icon'] ]]"
  85. [% endfor %]
  86. [% endif %]
  87. SetOutPath "$INSTDIR"
  88. [% endblock install_shortcuts %]
  89. [% block install_commands %]
  90. [% if has_commands %]
  91. nsExec::ExecToLog '[[ python ]] -Es "$INSTDIR\_rewrite_shebangs.py" "$INSTDIR\bin"'
  92. nsExec::ExecToLog '[[ python ]] -Es "$INSTDIR\_system_path.py" add "$INSTDIR\bin"'
  93. [% endif %]
  94. [% endblock install_commands %]
  95. ; Byte-compile Python files.
  96. DetailPrint "Byte-compiling Python modules..."
  97. nsExec::ExecToLog '[[ python ]] -m compileall -q "$INSTDIR\pkgs"'
  98. WriteUninstaller $INSTDIR\uninstall.exe
  99. ; Add ourselves to Add/remove programs
  100. WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  101. "DisplayName" "${PRODUCT_NAME}"
  102. WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  103. "UninstallString" '"$INSTDIR\uninstall.exe"'
  104. WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  105. "InstallLocation" "$INSTDIR"
  106. WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  107. "DisplayIcon" "$INSTDIR\${PRODUCT_ICON}"
  108. [% if ib.publisher is not none %]
  109. WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  110. "Publisher" "[[ib.publisher]]"
  111. [% endif %]
  112. WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  113. "DisplayVersion" "${PRODUCT_VERSION}"
  114. WriteRegDWORD SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  115. "NoModify" 1
  116. WriteRegDWORD SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  117. "NoRepair" 1
  118. ; Check if we need to reboot
  119. IfRebootFlag 0 noreboot
  120. MessageBox MB_YESNO "A reboot is required to finish the installation. Do you wish to reboot now?" \
  121. /SD IDNO IDNO noreboot
  122. Reboot
  123. noreboot:
  124. SectionEnd
  125. Section "Uninstall"
  126. SetRegView [[ib.py_bitness]]
  127. SetShellVarContext all
  128. IfFileExists "$INSTDIR\${USER_INSTALL_MARKER}" 0 +3
  129. SetShellVarContext current
  130. Delete "$INSTDIR\${USER_INSTALL_MARKER}"
  131. Delete $INSTDIR\uninstall.exe
  132. Delete "$INSTDIR\${PRODUCT_ICON}"
  133. RMDir /r "$INSTDIR\pkgs"
  134. ; Remove ourselves from %PATH%
  135. [% block uninstall_commands %]
  136. [% if has_commands %]
  137. nsExec::ExecToLog '[[ python ]] -Es "$INSTDIR\_system_path.py" remove "$INSTDIR\bin"'
  138. [% endif %]
  139. [% endblock uninstall_commands %]
  140. [% block uninstall_files %]
  141. ; Uninstall files
  142. [% for file, destination in ib.install_files %]
  143. Delete "[[pjoin(destination, file)]]"
  144. [% endfor %]
  145. ; Uninstall directories
  146. [% for dir, destination in ib.install_dirs %]
  147. RMDir /r "[[pjoin(destination, dir)]]"
  148. [% endfor %]
  149. [% endblock uninstall_files %]
  150. [% block uninstall_shortcuts %]
  151. ; Uninstall shortcuts
  152. [% if single_shortcut %]
  153. [% for scname in ib.shortcuts %]
  154. Delete "$SMPROGRAMS\[[scname]].lnk"
  155. [% endfor %]
  156. [% else %]
  157. RMDir /r "$SMPROGRAMS\${PRODUCT_NAME}"
  158. [% endif %]
  159. [% endblock uninstall_shortcuts %]
  160. RMDir $INSTDIR
  161. DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
  162. SectionEnd
  163. [% endblock sections %]
  164. ; Functions
  165. Function .onMouseOverSection
  166. ; Find which section the mouse is over, and set the corresponding description.
  167. FindWindow $R0 "#32770" "" $HWNDPARENT
  168. GetDlgItem $R0 $R0 1043 ; description item (must be added to the UI)
  169. [% block mouseover_messages %]
  170. StrCmp $0 ${sec_app} "" +2
  171. SendMessage $R0 ${WM_SETTEXT} 0 "STR:${PRODUCT_NAME}"
  172. [% endblock mouseover_messages %]
  173. FunctionEnd
  174. Function .onInit
  175. !insertmacro MULTIUSER_INIT
  176. FunctionEnd
  177. Function un.onInit
  178. !insertmacro MULTIUSER_UNINIT
  179. FunctionEnd
  180. [% if ib.py_bitness == 64 %]
  181. Function correct_prog_files
  182. ; The multiuser machinery doesn't know about the different Program files
  183. ; folder for 64-bit applications. Override the install dir it set.
  184. StrCmp $MultiUser.InstallMode AllUsers 0 +2
  185. StrCpy $INSTDIR "$PROGRAMFILES64\${MULTIUSER_INSTALLMODE_INSTDIR}"
  186. FunctionEnd
  187. [% endif %]