1
0

pyapp.nsi 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 PY_QUALIFIER "[[ib.py_qualifier]]"
  6. !define BITNESS "[[ib.py_bitness]]"
  7. !define ARCH_TAG "[[arch_tag]]"
  8. !define INSTALLER_NAME "[[ib.installer_name]]"
  9. !define PRODUCT_ICON "[[icon]]"
  10. SetCompressor lzma
  11. RequestExecutionLevel admin
  12. [% block modernui %]
  13. ; Modern UI installer stuff
  14. !include "MUI2.nsh"
  15. !define MUI_ABORTWARNING
  16. !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
  17. ; UI pages
  18. !insertmacro MUI_PAGE_WELCOME
  19. !insertmacro MUI_PAGE_COMPONENTS
  20. !insertmacro MUI_PAGE_DIRECTORY
  21. !insertmacro MUI_PAGE_INSTFILES
  22. !insertmacro MUI_PAGE_FINISH
  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. [% block sections %]
  30. Section -SETTINGS
  31. SetOutPath "$INSTDIR"
  32. SetOverwrite ifnewer
  33. SectionEnd
  34. Section "Python ${PY_VERSION}" sec_py
  35. File "python-${PY_VERSION}${ARCH_TAG}.msi"
  36. DetailPrint "Installing Python ${PY_MAJOR_VERSION}, ${BITNESS} bit"
  37. ExecWait 'msiexec /i "$INSTDIR\python-${PY_VERSION}${ARCH_TAG}.msi" \
  38. /qb ALLUSERS=1 TARGETDIR="$COMMONFILES${BITNESS}\Python\${PY_MAJOR_VERSION}"'
  39. Delete $INSTDIR\python-${PY_VERSION}${ARCH_TAG}.msi
  40. SectionEnd
  41. Section "!${PRODUCT_NAME}" sec_app
  42. SectionIn RO
  43. SetShellVarContext all
  44. File ${PRODUCT_ICON}
  45. SetOutPath "$INSTDIR\pkgs"
  46. File /r "pkgs\*.*"
  47. SetOutPath "$INSTDIR"
  48. ; Install files
  49. [% for destination, group in grouped_files %]
  50. SetOutPath "[[destination]]"
  51. [% for file in group %]
  52. File "[[ file ]]"
  53. [% endfor %]
  54. [% endfor %]
  55. ; Install directories
  56. [% for dir, destination in ib.install_dirs %]
  57. SetOutPath "[[ pjoin(destination, dir) ]]"
  58. File /r "[[dir]]\*.*"
  59. [% endfor %]
  60. [% block install_shortcuts %]
  61. ; Install shortcuts
  62. ; The output path becomes the working directory for shortcuts
  63. SetOutPath "%HOMEDRIVE%\%HOMEPATH%"
  64. [% if single_shortcut %]
  65. [% for scname, sc in ib.shortcuts.items() %]
  66. CreateShortCut "$SMPROGRAMS\[[scname]].lnk" "[[sc['target'] ]]" \
  67. '[[ sc['parameters'] ]]' "$INSTDIR\[[ sc['icon'] ]]"
  68. [% endfor %]
  69. [% else %]
  70. [# Multiple shortcuts: create a directory for them #]
  71. CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
  72. [% for scname, sc in ib.shortcuts.items() %]
  73. CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\[[scname]].lnk" "[[sc['target'] ]]" \
  74. '[[ sc['parameters'] ]]' "$INSTDIR\[[ sc['icon'] ]]"
  75. [% endfor %]
  76. [% endif %]
  77. SetOutPath "$INSTDIR"
  78. [% endblock install_shortcuts %]
  79. ; Byte-compile Python files.
  80. DetailPrint "Byte-compiling Python modules..."
  81. nsExec::ExecToLog 'py -${PY_QUALIFIER} -m compileall -q "$INSTDIR\pkgs"'
  82. WriteUninstaller $INSTDIR\uninstall.exe
  83. ; Add ourselves to Add/remove programs
  84. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  85. "DisplayName" "${PRODUCT_NAME}"
  86. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  87. "UninstallString" '"$INSTDIR\uninstall.exe"'
  88. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  89. "InstallLocation" "$INSTDIR"
  90. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  91. "DisplayIcon" "$INSTDIR\${PRODUCT_ICON}"
  92. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  93. "NoModify" 1
  94. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
  95. "NoRepair" 1
  96. SectionEnd
  97. Section "Uninstall"
  98. SetShellVarContext all
  99. Delete $INSTDIR\uninstall.exe
  100. Delete "$INSTDIR\${PRODUCT_ICON}"
  101. RMDir /r "$INSTDIR\pkgs"
  102. ; Uninstall files
  103. [% for file, destination in ib.install_files %]
  104. Delete "[[pjoin(destination, file)]]"
  105. [% endfor %]
  106. ; Uninstall directories
  107. [% for dir, destination in ib.install_dirs %]
  108. RMDir /r "[[pjoin(destination, dir)]]"
  109. [% endfor %]
  110. [% block uninstall_shortcuts %]
  111. ; Uninstall shortcuts
  112. [% if single_shortcut %]
  113. [% for scname in ib.shortcuts %]
  114. Delete "$SMPROGRAMS\[[scname]].lnk"
  115. [% endfor %]
  116. [% else %]
  117. RMDir /r "$SMPROGRAMS\${PRODUCT_NAME}"
  118. [% endif %]
  119. [% endblock uninstall_shortcuts %]
  120. RMDir $INSTDIR
  121. DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
  122. SectionEnd
  123. [% endblock sections %]
  124. ; Functions
  125. Function .onMouseOverSection
  126. ; Find which section the mouse is over, and set the corresponding description.
  127. FindWindow $R0 "#32770" "" $HWNDPARENT
  128. GetDlgItem $R0 $R0 1043 ; description item (must be added to the UI)
  129. [% block mouseover_messages %]
  130. StrCmp $0 ${sec_py} 0 +2
  131. SendMessage $R0 ${WM_SETTEXT} 0 "STR:The Python interpreter. \
  132. This is required for ${PRODUCT_NAME} to run."
  133. StrCmp $0 ${sec_app} "" +2
  134. SendMessage $R0 ${WM_SETTEXT} 0 "STR:${PRODUCT_NAME}"
  135. [% endblock mouseover_messages %]
  136. FunctionEnd