installer.nsh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. !include "LogicLib.nsh"
  2. !define INSTALLER_SOURCE_DIR "${__FILEDIR__}\..\installer"
  3. !define /ifndef INSTALLER_BUILD_DIR "${__FILEDIR__}\..\.desktop-build\targets\win-x64\installer-ui"
  4. !ifndef BUILD_UNINSTALLER
  5. ManifestDPIAware true
  6. !define MUI_CUSTOMFUNCTION_GUIINIT InstallerGuiInit
  7. !endif
  8. !macro customHeader
  9. !include "${INSTALLER_SOURCE_DIR}\strings.nsh"
  10. !ifndef BUILD_UNINSTALLER
  11. !include "${INSTALLER_SOURCE_DIR}\theme.nsh"
  12. !include "${INSTALLER_SOURCE_DIR}\pages.nsh"
  13. !include "${INSTALLER_SOURCE_DIR}\lifecycle.nsh"
  14. !endif
  15. !macroend
  16. !macro customInit
  17. ${If} ${isForAllUsers}
  18. MessageBox MB_OK|MB_ICONEXCLAMATION "$(INSTALLER_PER_USER)" /SD IDOK
  19. SetErrorLevel 2
  20. Quit
  21. ${EndIf}
  22. ReadRegStr $0 HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation
  23. ${If} $0 != ""
  24. MessageBox MB_OK|MB_ICONEXCLAMATION "$(INSTALLER_PER_USER)" /SD IDOK
  25. SetErrorLevel 2
  26. Quit
  27. ${EndIf}
  28. !insertmacro setInstallModePerUser
  29. StrCpy $hasPerMachineInstallation 0
  30. StrCpy $hasPerUserInstallation 1
  31. StrCpy $InstallerPath $INSTDIR
  32. StrCpy $InstallerTheme "auto"
  33. ${GetParameters} $0
  34. ${GetOptions} $0 "/THEME=" $1
  35. ${IfNot} ${Errors}
  36. ${If} $1 == "light"
  37. ${OrIf} $1 == "dark"
  38. ${OrIf} $1 == "auto"
  39. StrCpy $InstallerTheme $1
  40. ${Else}
  41. MessageBox MB_OK|MB_ICONEXCLAMATION "$(INSTALLER_THEME_ERROR)" /SD IDOK
  42. SetErrorLevel 2
  43. Quit
  44. ${EndIf}
  45. ${EndIf}
  46. Call InstallerResolveTheme
  47. InitPluginsDir
  48. File "/oname=$PLUGINSDIR\brand.bmp" "${INSTALLER_BUILD_DIR}\brand.bmp"
  49. File "/oname=$PLUGINSDIR\brand-2x.bmp" "${INSTALLER_BUILD_DIR}\brand-2x.bmp"
  50. File "/oname=$PLUGINSDIR\brand-dark.bmp" "${INSTALLER_BUILD_DIR}\brand-dark.bmp"
  51. File "/oname=$PLUGINSDIR\brand-dark-2x.bmp" "${INSTALLER_BUILD_DIR}\brand-dark-2x.bmp"
  52. File "/oname=$PLUGINSDIR\window-frame.dll" "${INSTALLER_BUILD_DIR}\window-frame.dll"
  53. ${If} ${Silent}
  54. Call InstallerPreflight
  55. ${If} $InstallerError != ""
  56. SetErrorLevel 2
  57. Quit
  58. ${EndIf}
  59. ${EndIf}
  60. !macroend
  61. !macro customInstallMode
  62. ; Preserve the directory selected on the custom welcome page.
  63. StrCpy $installMode CurrentUser
  64. SetShellVarContext current
  65. Abort
  66. !macroend
  67. !macro customWelcomePage
  68. Page custom InstallerWelcome InstallerWelcomeLeave
  69. !macroend
  70. !macro customPageAfterChangeDir
  71. !define MUI_PAGE_CUSTOMFUNCTION_PRE InstallerBeforeInstall
  72. !define MUI_PAGE_CUSTOMFUNCTION_SHOW InstallerProgressShow
  73. !macroend
  74. !macro customFinishPage
  75. Page custom InstallerFinish InstallerFinishLeave
  76. !macroend
  77. ; The pinned builder's extraction hooks only publish stages; its worker owns all file operations.
  78. !macro InstallerPublishStage Stage
  79. ; Extraction owns the stack and error flag across these callbacks.
  80. Push $0
  81. StrCpy $0 0
  82. ${If} ${Errors}
  83. StrCpy $0 1
  84. ${EndIf}
  85. System::Store /NOUNLOAD "S"
  86. System::Call /NOUNLOAD 'user32::SetPropW(p $HWNDPARENT, w "HarnessInstaller.Stage", p ${Stage})'
  87. System::Store "L"
  88. ${If} $0 == 1
  89. SetErrors
  90. ${Else}
  91. ClearErrors
  92. ${EndIf}
  93. Pop $0
  94. !macroend
  95. !macro customInstallerExtractStart
  96. !insertmacro InstallerPublishStage 1
  97. !macroend
  98. !macro customInstallerCopyStart
  99. !insertmacro InstallerPublishStage 2
  100. !macroend
  101. !macro customInstallerFilesReady
  102. !insertmacro InstallerPublishStage 3
  103. !macroend
  104. !macro customCheckAppRunning
  105. !ifdef BUILD_UNINSTALLER
  106. InitPluginsDir
  107. File "/oname=$PLUGINSDIR\window-frame.dll" "${INSTALLER_BUILD_DIR}\window-frame.dll"
  108. !endif
  109. System::Call '$PLUGINSDIR\window-frame.dll::InstallerFindProcess(w "$INSTDIR\${APP_EXECUTABLE_FILENAME}") i.R0 ?c'
  110. ${If} $R0 == 0
  111. ${If} ${isUpdated}
  112. StrCpy $R1 0
  113. ${DoWhile} $R0 == 0
  114. Sleep 250
  115. System::Call '$PLUGINSDIR\window-frame.dll::InstallerFindProcess(w "$INSTDIR\${APP_EXECUTABLE_FILENAME}") i.R0 ?c'
  116. IntOp $R1 $R1 + 1
  117. ${If} $R1 >= 40
  118. ${ExitDo}
  119. ${EndIf}
  120. ${Loop}
  121. ${EndIf}
  122. ${If} $R0 == 0
  123. MessageBox MB_OK|MB_ICONINFORMATION "$(INSTALLER_RUNNING)" /SD IDOK
  124. SetErrorLevel 2
  125. Quit
  126. ${EndIf}
  127. ${EndIf}
  128. ${If} $R0 < 0
  129. MessageBox MB_OK|MB_ICONEXCLAMATION "$(INSTALLER_UI_ERROR)" /SD IDOK
  130. SetErrorLevel 2
  131. Quit
  132. ${EndIf}
  133. !macroend
  134. !ifndef BUILD_UNINSTALLER
  135. !include "${__FILEDIR__}\installer-directories.nsh"
  136. !endif
  137. !macro customInstall
  138. Push $0
  139. StrCpy $0 0
  140. ${If} ${Errors}
  141. StrCpy $0 1
  142. ${EndIf}
  143. ; Finish can launch the app while NSIS removes its remaining plugin directory.
  144. !insertmacro InstallerPublishStage 4
  145. !insertmacro dshFinishDirectories
  146. RMDir /r "$PLUGINSDIR\7z-out"
  147. ${If} $0 == 1
  148. SetErrors
  149. ${Else}
  150. ClearErrors
  151. ${EndIf}
  152. Pop $0
  153. !macroend