installer.nsh 4.8 KB

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