Prompt Before Compilation: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Initial Release)
 
(Rewrite as macro and to make it self contained.. no longer requires external vbscript file.)
Line 2: Line 2:


== Description ==
== Description ==
With a simple VBScript dropped on the system path, you can allow your NSIS scripts to prompt prior to compilation.  I've found this useful to alert me to packages that require a significant amount of time to compile.
Using a dynamic vbscript created at compile time, you can allow your NSIS scripts to prompt prior to compilation.  I've found this useful to alert me to packages that require a significant amount of time to compile.


== Usage ==
== Usage ==
<highlight-nsis>
<highlight-nsis>
!system 'MsgBox.vbs "Package will take a long time to compile.\n\n \
${!MsgBox} "WARNING: Package will take a long time to compile.\n\
     Average Compilation Time: 54 min 35 sec\n\n\tContinue?" "NSIS Compilation"' = 1
     Average Compilation Time: 54 min 35 sec" "NSIS Compilation"
</highlight-nsis>
</highlight-nsis>


== VB Script ==
== NSIS Macro ==
Save the following VBScript as "MsgBox.vbs" in a location that is listed in the %PATH%.
Save the following VBScript as "MsgBox.vbs" in a location that is listed in the %PATH%.
<highlight-vb>
<highlight-nsis>
'vbscript
!define !MsgBox `!insertmacro _!MsgBox`
'MsgBox.vbs
!macro _!MsgBox _Message _Caption
 
    ;!verbose push
Dim Caption 'As String
    ;!verbose 0
Dim Prompt 'As String
    !tempfile MsgBox
 
    !appendfile "${MsgBox}" `WScript.Quit MsgBox(Replace(Replace(Replace("${_Message}","\t",vbTab),"\n",vbLf),"\r",vbCr),289,"${_Caption}")`
'** Defaults
    !system `wscript.exe "${MsgBox}" //E:vbscript` = 1
Caption = "What do you want to do?"
    !delfile "${MsgBox}"
Prompt = "Proceed?"
    !undef MsgBox
 
    ;!verbose pop
'** Apply CmdLine Arguments
!macroend
If WScript.Arguments.Count => 1 Then _
</highlight-nsis>
Prompt = WScript.Arguments.Item(0)
 
If WScript.Arguments.Count => 2 Then _
Caption = WScript.Arguments.Item(1)
 
'** Allow Meta characters
Prompt = Replace(Prompt, "\r", vbCr)
Prompt = Replace(Prompt, "\n", vbLf)
Prompt = Replace(Prompt, "\t", vbTab)
 
'** Display Prompt
WScript.Quit MsgBox(Prompt, 289, Caption)
</highlight-vb>


[[Category:Compile-Time Macros]]
[[Category:Compile-Time Macros]]

Revision as of 20:16, 10 November 2009

Author: Zinthose (talk, contrib)


Description

Using a dynamic vbscript created at compile time, you can allow your NSIS scripts to prompt prior to compilation. I've found this useful to alert me to packages that require a significant amount of time to compile.

Usage

${!MsgBox} "WARNING: Package will take a long time to compile.\n\
    Average Compilation Time: 54 min 35 sec" "NSIS Compilation"

NSIS Macro

Save the following VBScript as "MsgBox.vbs" in a location that is listed in the %PATH%.

!define !MsgBox `!insertmacro _!MsgBox`
!macro _!MsgBox _Message _Caption
    ;!verbose push
    ;!verbose 0
    !tempfile MsgBox
    !appendfile "${MsgBox}" `WScript.Quit MsgBox(Replace(Replace(Replace("${_Message}","\t",vbTab),"\n",vbLf),"\r",vbCr),289,"${_Caption}")`
    !system `wscript.exe "${MsgBox}" //E:vbscript` = 1
    !delfile "${MsgBox}"
    !undef MsgBox
    ;!verbose pop
!macroend