NSISMenu.nsi 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. OutFile "NSIS.exe"
  2. Name "NSIS Menu"
  3. Unicode True
  4. RequestExecutionLevel User
  5. XPStyle On
  6. ManifestDPIAware System
  7. SetCompressor LZMA
  8. ChangeUI IDD_INST "${NSISDIR}\Contrib\UIs\modern_headerbmp.exe"
  9. Icon "${NSISDIR}\Contrib\Graphics\Icons\nsis-menu.ico"
  10. BrandingText " "
  11. MiscButtonText " " " " " " " "
  12. InstallButtonText " "
  13. CompletedText " "
  14. LangString ^ClickInstall 0 " "
  15. Caption "$(^Name)"
  16. !macro UNPACKVERFIELD out in shr mask fmt
  17. !define /redef /math ${out} ${in} >>> ${shr}
  18. !define /redef /math ${out} ${${out}} & ${mask}
  19. !define /redef /intfmt ${out} "${fmt}" ${${out}}
  20. !macroend
  21. !ifndef VER_MAJOR & VER_MINOR
  22. !ifdef NSIS_PACKEDVERSION
  23. !insertmacro UNPACKVERFIELD VER_MAJOR ${NSIS_PACKEDVERSION} 24 0x0ff "%X"
  24. !insertmacro UNPACKVERFIELD VER_MINOR ${NSIS_PACKEDVERSION} 12 0xfff "%X"
  25. !insertmacro UNPACKVERFIELD VER_REVISION ${NSIS_PACKEDVERSION} 4 255 "%X"
  26. !insertmacro UNPACKVERFIELD VER_BUILD ${NSIS_PACKEDVERSION} 00 0x00f "%X"
  27. !endif
  28. !endif
  29. !ifdef VER_MAJOR & VER_MINOR
  30. !define /ifndef VER_REVISION 0
  31. !define /ifndef VER_BUILD 0
  32. !searchreplace VERSTR "${NSIS_VERSION}" "v" ""
  33. VIProductVersion ${VER_MAJOR}.${VER_MINOR}.${VER_REVISION}.${VER_BUILD}
  34. VIAddVersionKey "ProductName" "NSIS"
  35. VIAddVersionKey "ProductVersion" "${VERSTR}"
  36. VIAddVersionKey "FileVersion" "${VERSTR}"
  37. VIAddVersionKey "FileDescription" "NSIS Menu"
  38. VIAddVersionKey "LegalCopyright" "http://nsis.sf.net/License"
  39. !endif
  40. !include nsDialogs.nsh
  41. !include WinMessages.nsh
  42. !include LogicLib.nsh
  43. !define /IfNDef IDC_CHILDRECT 1018
  44. !define QUIT_ON_EXECUTE
  45. !define PR $ExeDir ; Local root path
  46. !define PD "Docs" ; Local with WWW fallback (located at the same relative path)
  47. !define WWW "http://nsis.sf.net"
  48. !define CB_HEADER '0x755585 0x222222'
  49. !define UY_HEADER 28
  50. !define CT_PAGE '0x000000 0xaaaaaa'
  51. !define CB_PAGE '0xffffff 0x111111'
  52. !define CT_SECTION '0x666666 0xeeeeee'
  53. !define CB_SECTION '${CB_PAGE}'
  54. !define UY_SECTION 11 ; Height of a section
  55. !define UY_SECTIONBPAD 2 ; Extra padding on the bottom of section headers
  56. !define UY_TXT 9 ; Height of a normal item
  57. !define UY_TXTBPAD 1 ; Extra padding on the bottom of normal items
  58. !define UX_COLPAD 7 ; Spacing between columns
  59. !define UY_ROW2 104 ; Absolute position of the 2nd row
  60. !define CT_LINK '0x0c6e97 0x0c6e97' ; SYSCLR:HOTLIGHT
  61. !define /Math UX_PAGE 00 + ${UX_COLPAD}
  62. !define /Math UY_PAGE ${UY_HEADER} + 20
  63. !define UX ${UX_PAGE}
  64. !define CB_FOOTERLINE '0xc4c4c4 0x333333'
  65. !define CT_FOOTER '0xbbbbbb 0x444444'
  66. Var UseLightTheme
  67. Function .onGUIInit
  68. ReadRegDWORD $UseLightTheme HKCU "Software\NSIS" "UseLightTheme"
  69. StrCmp $UseLightTheme "" 0 +2
  70. ReadRegDWORD $UseLightTheme HKCU "Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" "AppsUseLightTheme"
  71. StrCmp $UseLightTheme "" 0 +2
  72. StrCpy $UseLightTheme 1 ; Default
  73. StrCmp $UseLightTheme "0" 0 +5
  74. System::Call 'DWMAPI::DwmSetWindowAttribute(p$hWndParent,i20,*i1,i4)i.r0' ; 20H1
  75. IntCmp $0 0 +3 +3
  76. System::Call 'DWMAPI::DwmSetWindowAttribute(p$hWndParent,i19,*i1,i4)i.r0' ; ; 19H1
  77. System::Call 'USER32::SetProp(p$hWndParent,t"UseImmersiveDarkModeColors",i1)' ; 1809
  78. FunctionEnd
  79. !define SetCtlColors "!insertmacro SetCtlColors "
  80. !macro SetCtlColors hWnd ctlig ctdar cblig cbdar
  81. StrCmp $UseLightTheme "0" 0 +3
  82. SetCtlColors ${hWnd} "${ctdar}" ${cbdar}
  83. Goto +2
  84. SetCtlColors ${hWnd} "${ctlig}" ${cblig}
  85. !macroend
  86. Function PageLeave
  87. System::Call 'USER32::GetFocus()p.r0'
  88. System::Call 'USER32::GetDlgCtrlID(pr0)i.r1'
  89. System::Call 'USER32::GetParent(pr0)p.r2'
  90. SendMessage $2 ${WM_COMMAND} $1 $0 ; Handle <ENTER> in dialog by pretending it was a click on the active control
  91. Abort
  92. FunctionEnd
  93. Function PageCreate
  94. GetDlgItem $0 $hWndParent 1
  95. ShowWindow $0 0
  96. GetDlgItem $0 $hWndParent 2
  97. ShowWindow $0 0
  98. System::Call 'USER32::GetClientRect(p$hWndParent,@r0)'
  99. System::Call '*$0(i,i,i.r3,i.r4)'
  100. GetDlgItem $0 $hWndParent ${IDC_CHILDRECT}
  101. System::Call 'USER32::MoveWindow(pr0,i0,i0,ir3,ir4,i0)'
  102. nsDialogs::Create ${IDC_CHILDRECT}
  103. Pop $R9
  104. ${SetCtlColors} $R9 ${CT_PAGE} ${CB_PAGE}
  105. !macro StartColumn W
  106. !define /ReDef UY ${UY_PAGE}
  107. !define /ReDef UX_W ${W}
  108. !ifdef UX_INTERNAL_PREV_W
  109. !define /ReDef /Math UX ${UX} + ${UX_INTERNAL_PREV_W}
  110. !define /ReDef /Math UX ${UX} + ${UX_COLPAD}
  111. !define /ReDef UX_INTERNAL_PREV_W ${UX_W}
  112. !else
  113. !define /Math UX_INTERNAL_PREV_W 0 + ${UX_W}
  114. !endif
  115. !macroend
  116. !macro CreateHeader Txt W
  117. !define /ReDef /Math W ${W} + 4 ; Make it slightly wider
  118. ${NSD_CreateLabel} ${UX}u ${UY}u ${W}u ${UY_SECTION}u "${Txt}"
  119. Pop $0
  120. ${SetCtlColors} $0 ${CT_SECTION} transparent transparent
  121. SendMessage $0 ${WM_SETFONT} ${HF_HEADER} 1
  122. !define /ReDef /Math UY ${UY} + ${UY_SECTION}
  123. !define /ReDef /Math UY ${UY} + ${UY_SECTIONBPAD}
  124. !macroend
  125. !macro CreateControl Class Txt W H
  126. ${NSD_Create${Class}} ${UX}u ${UY}u ${W}u ${H}u "${Txt}"
  127. !define /ReDef /Math UY ${UY} + ${H}
  128. !define /ReDef /Math UY ${UY} + ${UY_TXTBPAD}
  129. !macroend
  130. !macro CreateSimpleLinkHelper Txt Url W
  131. !insertmacro CreateControl Link "${Txt}|${Url}" ${W} ${UY_TXT}
  132. !macroend
  133. !macro CreateSimpleLink Txt Url W
  134. !insertmacro CreateSimpleLinkHelper "${Txt}" "${Url}" ${W}
  135. Call ConfigureLink
  136. !macroend
  137. ; --- Header ---
  138. !define HF_HEADER $R8
  139. CreateFont ${HF_HEADER} "Arial" ${UY_SECTION} 700
  140. nsDialogs::CreateControl ${__NSD_Label_CLASS} ${__NSD_Label_STYLE} ${__NSD_Label_EXSTYLE} 33u 0 -33u ${UY_HEADER}u ""
  141. Pop $0
  142. ${SetCtlColors} $0 0xffffff 0xffffff ${CB_HEADER}
  143. ; CCv5 does not paint the background outside of the icon correctly when SS_CENTERIMAGE is used so we have to overlay a small icon on top of the background
  144. nsDialogs::CreateControl ${__NSD_Icon_CLASS} ${__NSD_Icon_STYLE} ${__NSD_Icon_EXSTYLE} 4u 4u 33u ${UY_HEADER}u ""
  145. Pop $0
  146. ${SetCtlColors} $0 "" "" ${CB_HEADER}
  147. ${NSD_SetIconFromInstaller} $0 $1
  148. nsDialogs::CreateControl ${__NSD_Icon_CLASS} ${__NSD_Icon_STYLE}|${SS_CENTERIMAGE}|${SS_CENTER} ${__NSD_Icon_EXSTYLE} 0 0 33u ${UY_HEADER}u ""
  149. Pop $0
  150. ${SetCtlColors} $0 "" "" ${CB_HEADER}
  151. CreateFont $1 "Trebuchet MS" 17
  152. !searchreplace VERSTR "${NSIS_VERSION}" "v" ""
  153. nsDialogs::CreateControl ${__NSD_Label_CLASS} ${__NSD_Label_STYLE}|${SS_CENTERIMAGE}|${SS_ENDELLIPSIS} ${__NSD_Label_EXSTYLE} 34u 1u -34u ${UY_HEADER}u "nullsoft scriptable install system ${VERSTR}"
  154. Pop $0
  155. SetCtlColors $0 0x3A2A42 transparent
  156. SendMessage $0 ${WM_SETFONT} $1 1
  157. nsDialogs::CreateControl ${__NSD_Label_CLASS} ${__NSD_Label_STYLE}|${SS_CENTERIMAGE}|${SS_ENDELLIPSIS} ${__NSD_Label_EXSTYLE} 33u 0 -33u ${UY_HEADER}u "nullsoft scriptable install system ${VERSTR}"
  158. Pop $0
  159. SetCtlColors $0 0xffffff transparent
  160. SendMessage $0 ${WM_SETFONT} $1 1
  161. ; --- Page ---
  162. !insertmacro StartColumn 90
  163. !insertmacro CreateHeader "Compiler" ${UX_W}
  164. !insertmacro CreateSimpleLink "Compile NSI scripts" "${PR}\MakeNSISW" ${UX_W}
  165. !insertmacro CreateSimpleLink "Installer based on .ZIP file" "${PR}\bin\Zip2Exe" ${UX_W}
  166. !define /ReDef UY ${UY_ROW2}
  167. !insertmacro CreateHeader "Developer Center" ${UX_W}
  168. !define /ReDef UY_MULTILINE 42
  169. !insertmacro CreateControl Label "Many more examples, tutorials, plug-ins and NSIS-releted software are available at the online Developer Center." ${UX_W} ${UY_MULTILINE}
  170. Pop $0
  171. ${SetCtlColors} $0 ${CT_PAGE} ${CB_PAGE}
  172. !insertmacro StartColumn 80
  173. !insertmacro CreateHeader "Documentation" ${UX_W}
  174. !insertmacro CreateSimpleLink "NSIS Users Manual" "${PR}\NSIS.chm|${WWW}/Docs/" ${UX_W}
  175. !insertmacro CreateSimpleLink "Example scripts" "${PR}\Examples|${WWW}/Examples" ${UX_W}
  176. !insertmacro CreateSimpleLink "Modern UI 2" "${PD}\Modern UI 2\Readme.html" ${UX_W}
  177. !define /ReDef UY ${UY_ROW2}
  178. !insertmacro CreateHeader "Online Help" ${UX_W}
  179. !insertmacro CreateSimpleLink "Developer Center" "${WWW}/Developer_Center" ${UX_W}
  180. !insertmacro CreateSimpleLink "FAQ" "${WWW}/FAQ" ${UX_W}
  181. !insertmacro CreateSimpleLink "Forum" "http://forums.winamp.com/forumdisplay.php?forumid=65" ${UX_W}
  182. ;"Project Tracker" "http://sourceforge.net/tracker/?group_id=22049"
  183. !insertmacro CreateSimpleLink "Bug Tracker" "http://sourceforge.net/tracker/?group_id=22049&atid=373085" ${UX_W}
  184. !insertmacro CreateSimpleLink "Stackoverflow" "http://stackoverflow.com/questions/tagged/nsis" ${UX_W}
  185. !insertmacro CreateSimpleLink "Chat" "${WWW}/r/Chat" ${UX_W}
  186. ;insertmacro CreateSimpleLink "IRC channel" "irc://irc.landoleet.org/nsis" ${UX_W}
  187. ;"Pastebin" "http://nsis.pastebin.com/index/1FtyKP89"
  188. ;"Search" "http://www.google.com/cse/home?cx=005317984255499820329:c_glv1-6a6a"
  189. !insertmacro StartColumn 130
  190. !insertmacro CreateHeader "Plug-ins" ${UX_W}
  191. !macro CreatePluginLink Name Desc Url
  192. !define /ReDef SAVE_UY ${UY}
  193. !insertmacro CreateSimpleLinkHelper "${Name}" "${Url}" ${UX_W} ; AdjustLinkPair will configure this link
  194. !define /ReDef UY ${SAVE_UY}
  195. !insertmacro CreateControl Label "${Name} - ${Desc}" ${UX_W} ${UY_TXT}
  196. Call AdjustLinkPair
  197. !macroend
  198. !insertmacro CreatePluginLink "AdvSplash" "splash with fade in/out" "${PD}\AdvSplash\advsplash.txt"
  199. !insertmacro CreatePluginLink "Banner" "banner with custom text" "${PD}\Banner\Readme.txt"
  200. !insertmacro CreatePluginLink "BgImage" "background image" "${PD}\BgImage\BgImage.txt"
  201. !insertmacro CreatePluginLink "Dialer" "internet connection" "${PD}\Dialer\Dialer.txt"
  202. !insertmacro CreatePluginLink "Math" "math operations" "${PD}\Math\Math.txt"
  203. !insertmacro CreatePluginLink "nsDialogs" "custom wizard pages" "${PD}\nsDialogs\Readme.html"
  204. !insertmacro CreatePluginLink "nsExec" "launch command line tools" "${PD}\nsExec\nsExec.txt"
  205. !insertmacro CreatePluginLink "NSISdl" "download files" "${PD}\NSISdl\Readme.txt"
  206. !insertmacro CreatePluginLink "Splash" "splash screen" "${PD}\Splash\splash.txt"
  207. !insertmacro CreatePluginLink "StartMenu" "Start Menu folder selection" "${PD}\StartMenu\Readme.txt"
  208. !insertmacro CreatePluginLink "System" "Windows API calls" "${PD}\System\System.html"
  209. !insertmacro CreatePluginLink "VPatch" "update existing files" "${PD}\VPatch\Readme.html"
  210. ; --- Footer ---
  211. ${NSD_CreateLabel} 0 -22u 100% 1 ""
  212. Pop $0
  213. ${SetCtlColors} $0 000000 000000 ${CB_FOOTERLINE}
  214. nsDialogs::CreateControl ${__NSD_Label_CLASS} ${__NSD_Label_STYLE}|${SS_CENTERIMAGE}|${SS_NOTIFY} ${__NSD_Label_EXSTYLE} -110u -20u 100% 20u "nsis.sourceforge.net"
  215. Pop $0
  216. ${SetCtlColors} $0 ${CT_FOOTER} transparent transparent
  217. SendMessage $0 ${WM_SETFONT} ${HF_HEADER} 1
  218. nsDialogs::SetUserData $0 "https://nsis.sourceforge.io"
  219. ${NSD_OnClick} $0 OnLinkClick
  220. nsDialogs::Show
  221. FunctionEnd
  222. Function OnLinkClick
  223. Pop $1 ; HWND
  224. nsDialogs::GetUserData $1
  225. Call SplitPipe
  226. Pop $0 ; First URL in UserData from SplitPipe
  227. StrCpy $3 ""
  228. StrCpy $1 $0 4 ; Copy length of ${PD}
  229. ${IfThen} $1 == "${PD}" ${|} StrCpy $3 "${PR}\" ${|}
  230. !ifdef QUIT_ON_EXECUTE
  231. System::Call 'USER32::GetKeyState(i0x11)i.r9' ; VK_CONTROL
  232. !endif
  233. ClearErrors
  234. ExecShell "" "$3$0"
  235. Pop $1 ; ... the rest of SplitPipe ...
  236. ${If} $1 != "" ; ... might contain a fallback location
  237. StrCpy $0 $1
  238. StrCpy $3 ""
  239. ${ElseIf} $3 != "" ; Local docs path failed, use WWW fallback
  240. StrCpy $3 0
  241. slashconvloop:
  242. StrCpy $2 $0 1 $3
  243. ${If} $2 == "\"
  244. StrCpy $2 $0 $3
  245. IntOp $3 $3 + 1
  246. StrCpy $0 $0 "" $3
  247. StrCpy $0 "$2/$0"
  248. ${Else}
  249. IntOp $3 $3 + 1
  250. ${EndIf}
  251. StrCmp $2 "" 0 slashconvloop
  252. StrCpy $3 "${WWW}/"
  253. ${EndIf}
  254. ${If} "$3$1" != ""
  255. ${AndIf} ${Errors}
  256. ExecShell "" "$3$0"
  257. ${EndIf}
  258. ${If} ${Errors}
  259. !ifdef QUIT_ON_EXECUTE
  260. StrCpy $9 0 ; Don't allow close
  261. !endif
  262. MessageBox MB_IconStop 'Error: Unable to open "$0"!'
  263. ${EndIf}
  264. !ifdef QUIT_ON_EXECUTE
  265. ${IfThen} $9 < 0 ${|} SendMessage $hWndParent ${WM_CLOSE} 0 0 ${|}
  266. !endif
  267. FunctionEnd
  268. Function ConfigureLink
  269. Pop $1 ; HWND
  270. ${NSD_OnClick} $1 OnLinkClick
  271. ${SetCtlColors} $1 ${CT_LINK} ${CB_PAGE}
  272. ${NSD_GetText} $1 $4
  273. Push $4
  274. Call SplitPipe
  275. Pop $4
  276. Pop $2
  277. ${NSD_SetText} $1 $4
  278. nsDialogs::SetUserData $1 $2
  279. System::Call 'USER32::GetDC(pr1)p.r3'
  280. SendMessage $1 ${WM_GETFONT} 0 0 $5
  281. System::Call 'GDI32::SelectObject(pr3,pr5)p.s'
  282. StrLen $5 $4
  283. System::Call 'GDI32::GetTextExtentPoint32(pr3,tr4,ir5,@r5)'
  284. System::Call '*$5(i.r6)'
  285. System::Call 'GDI32::SelectObject(pr3,ps)'
  286. System::Call 'USER32::ReleaseDC(pr1,pr3)'
  287. System::Call 'USER32::GetWindowRect(pr1,@r3)'
  288. System::Call '*$3(i,i.r5,i,i.r7)'
  289. IntOp $7 $7 - $5
  290. IntOp $6 $6 + 4 ; Padding for focus rect
  291. System::Call 'USER32::SetWindowPos(pr1,p,i,i,ir6,ir7,i0x16)'
  292. FunctionEnd
  293. Function AdjustLinkPair
  294. Pop $2 ; Label
  295. ${SetCtlColors} $2 ${CT_PAGE} ${CB_PAGE}
  296. Call ConfigureLink
  297. FunctionEnd
  298. Function SplitPipe
  299. Exch $0
  300. Push $1
  301. Push $2
  302. StrCpy $2 0
  303. findSep:
  304. StrCpy $1 $0 1 $2
  305. IntOp $2 $2 + 1
  306. StrCmp $1 "" +2
  307. StrCmp $1 "|" "" findSep
  308. StrCpy $1 $0 "" $2
  309. IntOp $2 $2 - 1
  310. StrCpy $0 $0 $2
  311. Pop $2
  312. Exch $1
  313. Exch
  314. Exch $0
  315. FunctionEnd
  316. Section
  317. SectionEnd
  318. Page Custom PageCreate PageLeave
  319. !pragma warning disable 8000 ; Page instfiles not used