| 1 |
;NSIS Modern User Interface version 1.65 |
| 2 |
;InstallOptions Example Script |
| 3 |
;Written by Joost Verburg |
| 4 |
|
| 5 |
!define MUI_BUTTONTEXT_NEXT "Execute" |
| 6 |
|
| 7 |
;--------------------- |
| 8 |
;Include Modern UI |
| 9 |
|
| 10 |
!include "MUI.nsh" |
| 11 |
|
| 12 |
;-------------------------------- |
| 13 |
;Product Info |
| 14 |
|
| 15 |
Name "Math::Script Test" |
| 16 |
|
| 17 |
;-------------------------------- |
| 18 |
;Configuration |
| 19 |
|
| 20 |
;General |
| 21 |
OutFile "MathTest.exe" |
| 22 |
|
| 23 |
;-------------------------------- |
| 24 |
;Variables |
| 25 |
|
| 26 |
Var TEMP1 |
| 27 |
Var TEMP2 |
| 28 |
Var TEMP3 |
| 29 |
|
| 30 |
;-------------------------------- |
| 31 |
;Pages |
| 32 |
|
| 33 |
!insertmacro MUI_PAGE_LICENSE "mathtest.txt" |
| 34 |
Page custom ScriptPageEnter |
| 35 |
Page instfiles |
| 36 |
|
| 37 |
;-------------------------------- |
| 38 |
;Modern UI Configuration |
| 39 |
|
| 40 |
; !define MUI_ABORTWARNING |
| 41 |
|
| 42 |
;-------------------------------- |
| 43 |
;Languages |
| 44 |
|
| 45 |
!insertmacro MUI_LANGUAGE "English" |
| 46 |
|
| 47 |
;-------------------------------- |
| 48 |
;Reserve Files |
| 49 |
|
| 50 |
;Things that need to be extracted on first (keep these lines before any File command!) |
| 51 |
;Only for BZIP2 compression |
| 52 |
|
| 53 |
ReserveFile "MathTest.ini" |
| 54 |
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS |
| 55 |
|
| 56 |
;-------------------------------- |
| 57 |
;Installer Functions |
| 58 |
|
| 59 |
LangString SCRIPTSAMPLE0 ${LANG_ENGLISH} "r0 = 'Hello'; r1 = 'Math::Script'\r\nr0 += ' from the ' + r1 + '!'; r1=''" |
| 60 |
LangString SCRIPTSAMPLE1 ${LANG_ENGLISH} "a =0; b=1.0\r\n#{a++ < 100, b *= a}\r\nr0 = a; R0 = b; R1 = ff(b, 15)\r\nr1 = (a-1) + '! = ' + b" |
| 61 |
LangString SCRIPTSAMPLE2 ${LANG_ENGLISH} 'pi=3.14159; \r\nangle = pi/4;\r\ntext = "x = " + ff(angle,16+3) \r\nr0 = text += ", sin x = " + sin(angle)' |
| 62 |
LangString SCRIPTSAMPLE3 ${LANG_ENGLISH} "v1 = 123.456; v2 = 123456789.1011\r\nr0 = v1; r1 = v2\r\nr2 = ff(v1, 3); r3 = ff(v2, 3); r4 = ff(v1, 3+16); r5 = ff(v2, 3+16)\r\nr6 = ff(v1, 3+32); r7 = ff(v2, 3+32); r8 = ff(v1, 3+32+64); r9 = ff(v2, 3+32+64)\r\n" |
| 63 |
LangString SCRIPTSAMPLE4 ${LANG_ENGLISH} "a = 10000; b = 0; #{--a > 0, b+= a}; r0 = a; r1 = b\r\nz = 1.55; r2 = #[z > 1.5, 'Its greater', 'Its lower']\r\nz = 1.45; r3 = #[z > 1.5, 'Its greater', 'Its lower']" |
| 64 |
LangString SCRIPTSAMPLE5 ${LANG_ENGLISH} 'r0 = "123a123"\r\nr1 = r0; \r\nr2 = s(r0); r3 = f(r0); r4 = i(r0); r5 = l(r0)' |
| 65 |
|
| 66 |
Function .onInit |
| 67 |
|
| 68 |
;Extract InstallOptions INI files |
| 69 |
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "MathTest.ini" |
| 70 |
|
| 71 |
Strcpy "$TEMP1" "$(SCRIPTSAMPLE0)" |
| 72 |
!insertmacro MUI_INSTALLOPTIONS_WRITE "MathTest.ini" "Field 2" "State" $TEMP1 |
| 73 |
|
| 74 |
FunctionEnd |
| 75 |
|
| 76 |
LangString TEXT_IO_TITLE ${LANG_ENGLISH} "MathTest Script Page" |
| 77 |
LangString TEXT_IO_SUBTITLE ${LANG_ENGLISH} "Try your scripting capapibilites or test one of sample scripts" |
| 78 |
|
| 79 |
|
| 80 |
Function DumpVariables |
| 81 |
Strcpy "$TEMP1" "$$0='$0'\r\n$$1='$1'\r\n$$2='$2'\r\n$$3='$3'\r\n$$4='$4'\r\n$$5='$5'\r\n$$6='$6'\r\n$$7='$7'\r\n$$8='$8'\r\n$$9='$9'" |
| 82 |
!insertmacro MUI_INSTALLOPTIONS_WRITE "MathTest.ini" "Field 3" "State" $TEMP1 |
| 83 |
Strcpy "$TEMP1" "$$R0='$R0'\r\n$$R1='$R1'\r\n$$R2='$R2'\r\n$$R3='$R3'\r\n$$R4='$R4'\r\n$$R5='$R5'\r\n$$R6='$R6'\r\n$$R7='$R7'\r\n$$R8='$R8'\r\n$$R9='$R9'" |
| 84 |
!insertmacro MUI_INSTALLOPTIONS_WRITE "MathTest.ini" "Field 4" "State" $TEMP1 |
| 85 |
FunctionEnd |
| 86 |
|
| 87 |
Function ClearVariables |
| 88 |
Math::Script "r0=r1=r2=r3=r4=r5=r6=r7=r8=r9=R0=R1=R2=R3=R4=R5=R6=R7=R8=R9=''" |
| 89 |
FunctionEnd |
| 90 |
|
| 91 |
Function GetLine |
| 92 |
push $TEMP1 |
| 93 |
Math::Script "mtsDL()" |
| 94 |
pop $TEMP2 |
| 95 |
pop $TEMP1 |
| 96 |
FunctionEnd |
| 97 |
|
| 98 |
Function ExecuteScript |
| 99 |
!insertmacro MUI_INSTALLOPTIONS_READ $TEMP1 "MathTest.ini" "Field 2" "State" |
| 100 |
|
| 101 |
Math::Script "mtsTQ(s) (s = s(NS); #[s[0]=='$\"',s=s[1,]]; #[s[-1]=='$\"',s=s[,-2]]; NS = s)" |
| 102 |
Math::Script "mtsP(s,e, p,i) (p=-1;i=0; #{(i<l(s))&&(p<0), #[s[i,i+l(e)-1]==e, p=i]; i++}; p)" |
| 103 |
Math::Script "mtsDL(s) (s=s(NS); p=mtsP(s,'\r\n'); #[p>=0, (NS=s[p+4,]; NS=#[p>0,s[,p-1],'']), (NS='';NS=s)])" |
| 104 |
|
| 105 |
push $TEMP1 |
| 106 |
; remove "" |
| 107 |
Math::Script "mtsTQ()" |
| 108 |
pop $TEMP1 |
| 109 |
|
| 110 |
; script at $TEMP1 |
| 111 |
Go: |
| 112 |
StrLen $TEMP3 $TEMP1 |
| 113 |
IntCmp $TEMP3 0 End |
| 114 |
; get single line to $TEMP2 |
| 115 |
Call GetLine |
| 116 |
; MessageBox MB_OK "'$TEMP2' '$TEMP1'" |
| 117 |
Math::Script "$TEMP2" |
| 118 |
goto Go |
| 119 |
End: |
| 120 |
Math::Script "" |
| 121 |
FunctionEnd |
| 122 |
|
| 123 |
Function ScriptPageEnter |
| 124 |
|
| 125 |
!insertmacro MUI_HEADER_TEXT "$(TEXT_IO_TITLE)" "$(TEXT_IO_SUBTITLE)" |
| 126 |
|
| 127 |
Again: |
| 128 |
Call ClearVariables |
| 129 |
Call ExecuteScript |
| 130 |
Call DumpVariables |
| 131 |
|
| 132 |
!insertmacro MUI_INSTALLOPTIONS_DISPLAY_RETURN "mathtest.ini" |
| 133 |
pop $TEMP3 |
| 134 |
|
| 135 |
!insertmacro MUI_INSTALLOPTIONS_READ $TEMP1 "MathTest.ini" "Field 5" "State" |
| 136 |
IntCmp $TEMP1 1 Test |
| 137 |
|
| 138 |
Strcpy "$TEMP2" "$(SCRIPTSAMPLE1)" |
| 139 |
!insertmacro MUI_INSTALLOPTIONS_READ $TEMP1 "MathTest.ini" "Field 6" "State" |
| 140 |
IntCmp $TEMP1 1 Write |
| 141 |
|
| 142 |
Strcpy "$TEMP2" "$(SCRIPTSAMPLE2)" |
| 143 |
!insertmacro MUI_INSTALLOPTIONS_READ $TEMP1 "MathTest.ini" "Field 7" "State" |
| 144 |
IntCmp $TEMP1 1 Write |
| 145 |
|
| 146 |
Strcpy "$TEMP2" "$(SCRIPTSAMPLE3)" |
| 147 |
!insertmacro MUI_INSTALLOPTIONS_READ $TEMP1 "MathTest.ini" "Field 8" "State" |
| 148 |
IntCmp $TEMP1 1 Write |
| 149 |
|
| 150 |
Strcpy "$TEMP2" "$(SCRIPTSAMPLE4)" |
| 151 |
!insertmacro MUI_INSTALLOPTIONS_READ $TEMP1 "MathTest.ini" "Field 9" "State" |
| 152 |
IntCmp $TEMP1 1 Write |
| 153 |
|
| 154 |
Strcpy "$TEMP2" "$(SCRIPTSAMPLE5)" |
| 155 |
|
| 156 |
Write: |
| 157 |
!insertmacro MUI_INSTALLOPTIONS_WRITE "MathTest.ini" "Field 2" "State" "$TEMP2" |
| 158 |
!insertmacro MUI_INSTALLOPTIONS_WRITE "MathTest.ini" "Field 5" "State" "1" |
| 159 |
!insertmacro MUI_INSTALLOPTIONS_WRITE "MathTest.ini" "Field 6" "State" "0" |
| 160 |
!insertmacro MUI_INSTALLOPTIONS_WRITE "MathTest.ini" "Field 7" "State" "0" |
| 161 |
!insertmacro MUI_INSTALLOPTIONS_WRITE "MathTest.ini" "Field 8" "State" "0" |
| 162 |
!insertmacro MUI_INSTALLOPTIONS_WRITE "MathTest.ini" "Field 9" "State" "0" |
| 163 |
!insertmacro MUI_INSTALLOPTIONS_WRITE "MathTest.ini" "Field 10" "State" "0" |
| 164 |
|
| 165 |
Test: |
| 166 |
Strcmp $TEMP3 "success" Again |
| 167 |
|
| 168 |
FunctionEnd |
| 169 |
|
| 170 |
Section "Dummy Section" SecDummy |
| 171 |
SectionEnd |