installer.nsh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. ; Installation work publishes stage changes without disturbing the NSIS caller.
  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 customInstallerExtract Archive
  96. !insertmacro InstallerPublishStage 1
  97. System::Store /NOUNLOAD "S"
  98. 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'
  99. System::Store "L"
  100. Pop $R0
  101. StrCpy $R1 "$R0"
  102. ${If} $R0 != 0
  103. Push $0
  104. FileOpen $0 "$PLUGINSDIR\extract.log" r
  105. ${IfNot} ${Errors}
  106. FileRead $0 $R1
  107. FileClose $0
  108. ${EndIf}
  109. Pop $0
  110. ${EndIf}
  111. !macroend
  112. !macro customCheckAppRunning
  113. !ifdef BUILD_UNINSTALLER
  114. InitPluginsDir
  115. File "/oname=$PLUGINSDIR\window-frame.dll" "${INSTALLER_BUILD_DIR}\window-frame.dll"
  116. !endif
  117. System::Call '$PLUGINSDIR\window-frame.dll::InstallerFindProcess(w "$INSTDIR\${APP_EXECUTABLE_FILENAME}") i.R0 ?c'
  118. ${If} $R0 == 0
  119. ${If} ${isUpdated}
  120. StrCpy $R1 0
  121. ${DoWhile} $R0 == 0
  122. Sleep 250
  123. System::Call '$PLUGINSDIR\window-frame.dll::InstallerFindProcess(w "$INSTDIR\${APP_EXECUTABLE_FILENAME}") i.R0 ?c'
  124. IntOp $R1 $R1 + 1
  125. ${If} $R1 >= 40
  126. ${ExitDo}
  127. ${EndIf}
  128. ${Loop}
  129. ${EndIf}
  130. ${If} $R0 == 0
  131. MessageBox MB_OK|MB_ICONINFORMATION "$(INSTALLER_RUNNING)" /SD IDOK
  132. SetErrorLevel 2
  133. Quit
  134. ${EndIf}
  135. ${EndIf}
  136. ${If} $R0 < 0
  137. MessageBox MB_OK|MB_ICONEXCLAMATION "$(INSTALLER_UI_ERROR)" /SD IDOK
  138. SetErrorLevel 2
  139. Quit
  140. ${EndIf}
  141. !macroend
  142. !ifndef BUILD_UNINSTALLER
  143. !include "${__FILEDIR__}\installer-directories.nsh"
  144. !endif
  145. !macro customInstall
  146. Push $0
  147. StrCpy $0 0
  148. ${If} ${Errors}
  149. StrCpy $0 1
  150. ${EndIf}
  151. !insertmacro InstallerPublishStage 4
  152. !insertmacro dshFinishDirectories
  153. ${If} $0 == 1
  154. SetErrors
  155. ${Else}
  156. ClearErrors
  157. ${EndIf}
  158. Pop $0
  159. !macroend