Debian Codegraph @

Examples/NSISMenu.nsi

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