-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDotNET.nsh
158 lines (140 loc) · 5.98 KB
/
DotNET.nsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# DotNET version checking macro.
# Written by AnarkiNet([email protected]) originally, modified by eyal0 (for use in http://www.sourceforge.net/projects/itwister)
# Downloads and runs the Microsoft .NET Framework version 2.0 Redistributable and runs it if the user does not have the correct version.
# To use, call the macro with a string:
# !insertmacro CheckDotNET "2"
# !insertmacro CheckDotNET "2.0.9"
# (Version 2.0.9 is less than version 2.0.10.)
# All register variables are saved and restored by CheckDotNet
# No output
!macro CheckDotNET DotNetReqVer
!define DOTNET_URL "http://www.microsoft.com/downloads/info.aspx?na=90&p=&SrcDisplayLang=en&SrcCategoryId=&SrcFamilyId=0856eacb-4362-4b0d-8edd-aab15c5e04f5&u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f5%2f6%2f7%2f567758a3-759e-473e-bf8f-52154438565a%2fdotnetfx.exe"
DetailPrint "Checking your .NET Framework version..."
;callee register save
Push $0
Push $1
Push $2
Push $3
Push $4
Push $5
Push $6 ;backup of intsalled ver
Push $7 ;backup of DoNetReqVer
StrCpy $7 ${DotNetReqVer}
System::Call "mscoree::GetCORVersion(w .r0, i ${NSIS_MAX_STRLEN}, *i r2r2) i .r1 ?u"
${If} $0 == 0
DetailPrint ".NET Framework not found, download is required for program to run."
Goto NoDotNET
${EndIf}
;at this point, $0 has maybe v2.345.678.
StrCpy $0 $0 $2 1 ;remove the starting "v", $0 has the installed version num as a string
StrCpy $6 $0
StrCpy $1 $7 ;$1 has the requested verison num as a string
;MessageBox MB_OKCANCEL "found $0" IDCANCEL GiveUpDotNET
;MessageBox MB_OKCANCEL "looking for $1" IDCANCEL GiveUpDotNET
;now let's compare the versions, installed against required <part0>.<part1>.<part2>.
${Do}
StrCpy $2 "" ;clear out the installed part
StrCpy $3 "" ;clear out the required part
${Do}
${If} $0 == "" ;if there are no more characters in the version
StrCpy $4 "." ;fake the end of the version string
${Else}
StrCpy $4 $0 1 0 ;$4 = character from the installed ver
${If} $4 != "."
StrCpy $0 $0 ${NSIS_MAX_STRLEN} 1 ;remove that first character from the remaining
${EndIf}
${EndIf}
${If} $1 == "" ;if there are no more characters in the version
StrCpy $5 "." ;fake the end of the version string
${Else}
StrCpy $5 $1 1 0 ;$5 = character from the required ver
${If} $5 != "."
StrCpy $1 $1 ${NSIS_MAX_STRLEN} 1 ;remove that first character from the remaining
${EndIf}
${EndIf}
;MessageBox MB_OKCANCEL "installed $2,$4,$0 required $3,$5,$1" IDCANCEL GiveUpDotNET
${If} $4 == "."
${AndIf} $5 == "."
${ExitDo} ;we're at the end of the part
${EndIf}
${If} $4 == "." ;if we're at the end of the current installed part
StrCpy $2 "0$2" ;put a zero on the front
${Else} ;we have another character
StrCpy $2 "$2$4" ;put the next character on the back
${EndIf}
${If} $5 == "." ;if we're at the end of the current required part
StrCpy $3 "0$3" ;put a zero on the front
${Else} ;we have another character
StrCpy $3 "$3$5" ;put the next character on the back
${EndIf}
${Loop}
;MessageBox MB_OKCANCEL "finished parts: installed $2,$4,$0 required $3,$5,$1" IDCANCEL GiveUpDotNET
${If} $0 != "" ;let's remove the leading period on installed part if it exists
StrCpy $0 $0 ${NSIS_MAX_STRLEN} 1
${EndIf}
${If} $1 != "" ;let's remove the leading period on required part if it exists
StrCpy $1 $1 ${NSIS_MAX_STRLEN} 1
${EndIf}
;$2 has the installed part, $3 has the required part
${If} $2 S< $3
IntOp $0 0 - 1 ;$0 = -1, installed less than required
${ExitDo}
${ElseIf} $2 S> $3
IntOp $0 0 + 1 ;$0 = 1, installed greater than required
${ExitDo}
${ElseIf} $2 == ""
${AndIf} $3 == ""
IntOp $0 0 + 0 ;$0 = 0, the versions are identical
${ExitDo}
${EndIf} ;otherwise we just keep looping through the parts
${Loop}
${If} $0 < 0
DetailPrint ".NET Framework Version found: $6, but is older than the required version: $7"
Goto OldDotNET
${Else}
DetailPrint ".NET Framework Version found: $6, equal or newer to required version: $7."
Goto NewDotNET
${EndIf}
NoDotNET:
MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION \
".NET Framework not installed.$\nRequired Version: $7 or greater.$\nDownload .NET Framework version from www.microsoft.com?" \
/SD IDYES IDYES DownloadDotNET IDNO NewDotNET
goto GiveUpDotNET ;IDCANCEL
OldDotNET:
MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION \
"Your .NET Framework version: $6.$\nRequired Version: $7 or greater.$\nDownload .NET Framework version from www.microsoft.com?" \
/SD IDYES IDYES DownloadDotNET IDNO NewDotNET
goto GiveUpDotNET ;IDCANCEL
DownloadDotNET:
DetailPrint "Beginning download of latest .NET Framework version."
NSISDL::download ${DOTNET_URL} "$TEMP\dotnetfx.exe"
DetailPrint "Completed download."
Pop $0
${If} $0 == "cancel"
MessageBox MB_YESNO|MB_ICONEXCLAMATION \
"Download cancelled. Continue Installation?" \
IDYES NewDotNET IDNO GiveUpDotNET
${ElseIf} $0 != "success"
MessageBox MB_YESNO|MB_ICONEXCLAMATION \
"Download failed:$\n$0$\n$\nContinue Installation?" \
IDYES NewDotNET IDNO GiveUpDotNET
${EndIf}
DetailPrint "Pausing installation while downloaded .NET Framework installer runs."
ExecWait '$TEMP\dotnetfx.exe /q /c:"install /q"'
DetailPrint "Completed .NET Framework install/update. Removing .NET Framework installer."
Delete "$TEMP\dotnetfx.exe"
DetailPrint ".NET Framework installer removed."
goto NewDotNet
GiveUpDotNET:
Abort "Installation cancelled by user."
NewDotNET:
DetailPrint "Proceeding with remainder of installation."
Pop $0
Pop $1
Pop $2
Pop $3
Pop $4
Pop $5
Pop $6 ;backup of intsalled ver
Pop $7 ;backup of DoNetReqVer
!macroend