Statistiques
| Révision :

root / tmp / org.txm.setups / nsis / Include / WinVer.nsh @ 2107

Historique | Voir | Annoter | Télécharger (13,93 ko)

1
; ---------------------
2
;      WinVer.nsh
3
; ---------------------
4
;
5
; LogicLib extensions for handling Windows versions and service packs.
6
;
7
; IsNT checks if the installer is running on Windows NT family (NT4, 2000, XP, etc.)
8
;
9
;   ${If} ${IsNT}
10
;     DetailPrint "Running on NT. Installing Unicode enabled application."
11
;   ${Else}
12
;     DetailPrint "Not running on NT. Installing ANSI application."
13
;   ${EndIf}
14
;
15
; IsServer checks if the installer is running on a server version of Windows (NT4, 2003, 2008, etc.)
16
;
17
; AtLeastWin<version> checks if the installer is running on Windows version at least as specified.
18
; IsWin<version> checks if the installer is running on Windows version exactly as specified.
19
; AtMostWin<version> checks if the installer is running on Windows version at most as specified.
20
;
21
; <version> can be replaced with the following values:
22
;
23
;   95
24
;   98
25
;   ME
26
;
27
;   NT4
28
;   2000
29
;   XP
30
;   2003
31
;   Vista
32
;   2008
33
;   7
34
;   2008R2
35
;   8
36
;   2012
37
;
38
; AtLeastServicePack checks if the installer is running on Windows service pack version at least as specified.
39
; IsServicePack checks if the installer is running on Windows service pack version exactly as specified.
40
; AtMostServicePack checks if the installer is running on Windows service version pack at most as specified.
41
;
42
; Usage examples:
43
;
44
;   ${If} ${IsNT}
45
;   DetailPrint "Running on NT family."
46
;   DetailPrint "Surely not running on 95, 98 or ME."
47
;   ${AndIf} ${AtLeastWinNT4}
48
;     DetailPrint "Running on NT4 or better. Could even be 2003."
49
;   ${EndIf}
50
;
51
;   ${If} ${AtLeastWinXP}
52
;     DetailPrint "Running on XP or better."
53
;   ${EndIf}
54
;
55
;   ${If} ${IsWin2000}
56
;     DetailPrint "Running on 2000."
57
;   ${EndIf}
58
;
59
;   ${If} ${IsWin2000}
60
;   ${AndIf} ${AtLeastServicePack} 3
61
;   ${OrIf} ${AtLeastWinXP}
62
;     DetailPrint "Running Win2000 SP3 or above"
63
;   ${EndIf}
64
;
65
;   ${If} ${AtMostWinXP}
66
;     DetailPrint "Running on XP or older. Surely not running on Vista. Maybe 98, or even 95."
67
;   ${EndIf}
68
;
69
; Warning:
70
;
71
;   Windows 95 and NT both use the same version number. To avoid getting NT4 misidentified
72
;   as Windows 95 and vice-versa or 98 as a version higher than NT4, always use IsNT to
73
;   check if running on the NT family.
74
;
75
;     ${If} ${AtLeastWin95}
76
;     ${And} ${AtMostWinME}
77
;       DetailPrint "Running 95, 98 or ME."
78
;       DetailPrint "Actually, maybe it's NT4?"
79
;       ${If} ${IsNT}
80
;         DetailPrint "Yes, it's NT4! oops..."
81
;       ${Else}
82
;         DetailPrint "Nope, not NT4. phew..."
83
;       ${EndIf}
84
;     ${EndIf}
85
;
86
;
87
; Other useful extensions are:
88
;
89
;    * IsWin2003R2
90
;    * IsStarterEdition
91
;    * OSHasMediaCenter
92
;    * OSHasTabletSupport
93
;
94

    
95
!verbose push
96
!verbose 3
97

    
98
!ifndef ___WINVER__NSH___
99
!define ___WINVER__NSH___
100

    
101
!include LogicLib.nsh
102
!include Util.nsh
103

    
104
# masks for our variables
105

    
106
!define _WINVER_VERXBIT  0x00000001
107
!define _WINVER_MASKVMAJ 0x7F000000
108
!define _WINVER_MASKVMIN 0x00FF0000
109

    
110
!define _WINVER_NTBIT    0x80000000
111
!define _WINVER_NTMASK   0x7FFFFFFF
112
!define _WINVER_NTSRVBIT 0x40000000
113
!define _WINVER_MASKVBLD 0x0000FFFF
114
!define _WINVER_MASKSP   0x000F0000
115

    
116
# possible variable values for different versions
117

    
118
!define WINVER_95_NT     0x04000000 ;4.00.0950
119
!define WINVER_95        0x04000000 ;4.00.0950
120
!define WINVER_98_NT     0x040a0000 ;4.10.1998
121
!define WINVER_98        0x040a0000 ;4.10.1998
122
;define WINVER_98SE      0x040a0000 ;4.10.2222
123
!define WINVER_ME_NT     0x045a0000 ;4.90.3000
124
!define WINVER_ME        0x045a0000 ;4.90.3000
125
;define WINVER_NT3d51               ;3.51.1057
126
!define WINVER_NT4_NT    0x84000000 ;4.00.1381
127
!define WINVER_NT4       0x04000000 ;4.00.1381
128
!define WINVER_2000_NT   0x85000000 ;5.00.2195
129
!define WINVER_2000      0x05000000 ;5.00.2195
130
!define WINVER_XP_NT     0x85010000 ;5.01.2600
131
!define WINVER_XP        0x05010000 ;5.01.2600
132
;define WINVER_XP64                 ;5.02.3790
133
!define WINVER_2003_NT   0x85020000 ;5.02.3790
134
!define WINVER_2003      0x05020000 ;5.02.3790
135
!define WINVER_VISTA_NT  0x86000000 ;6.00.6000
136
!define WINVER_VISTA     0x06000000 ;6.00.6000
137
!define WINVER_2008_NT   0x86000001 ;6.00.6001
138
!define WINVER_2008      0x06000001 ;6.00.6001
139
!define WINVER_7_NT      0x86010000 ;6.01.7600
140
!define WINVER_7         0x06010000 ;6.01.7600
141
!define WINVER_2008R2_NT 0x86010001 ;6.01.7600
142
!define WINVER_2008R2    0x06010001 ;6.01.7600
143
!define WINVER_8_NT      0x86020000 ;6.02.9200
144
!define WINVER_8         0x06020000 ;6.02.9200
145
!define WINVER_2012_NT   0x86020001 ;6.02.9200
146
!define WINVER_2012      0x06020001 ;6.02.9200
147

    
148

    
149
# use this to make all nt > 9x
150

    
151
!ifdef WINVER_NT4_OVER_W95
152
  !define __WINVERTMP ${WINVER_NT4}
153
  !undef WINVER_NT4
154
  !define /math WINVER_NT4 ${__WINVERTMP} | ${_WINVER_VERXBIT}
155
  !undef __WINVERTMP
156
!endif
157

    
158
# some definitions from header files
159

    
160
!define OSVERSIONINFOA_SIZE   148
161
!define OSVERSIONINFOEXA_SIZE 156
162
!define VER_PLATFORM_WIN32_NT 2
163
!define VER_NT_WORKSTATION    1
164

    
165
!define SM_TABLETPC    86
166
!define SM_MEDIACENTER 87
167
!define SM_STARTER     88
168
!define SM_SERVERR2    89
169

    
170
# variable declaration
171

    
172
!macro __WinVer_DeclareVars
173

    
174
  !ifndef __WINVER_VARS_DECLARED
175

    
176
    !define __WINVER_VARS_DECLARED
177

    
178
    Var /GLOBAL __WINVERV
179
    Var /GLOBAL __WINVERSP
180

    
181
  !endif
182

    
183
!macroend
184

    
185
# lazy initialization macro
186

    
187
!ifmacrondef __WinVer_Call_GetVersionEx
188

    
189
  !macro __WinVer_Call_GetVersionEx STRUCT_SIZE
190

    
191
    System::Call '*$0(i ${STRUCT_SIZE})'
192
    System::Call kernel32::GetVersionEx(ir0)i.r3
193

    
194
  !macroend
195

    
196
!endif
197

    
198
!macro __WinVer_InitVars
199
  # variables
200
  !insertmacro __WinVer_DeclareVars
201

    
202
  # only calculate version once
203
  StrCmp $__WINVERV "" _winver_noveryet
204
    Return
205
  _winver_noveryet:
206

    
207
  # push used registers on the stack
208
  Push $0
209
  Push $1 ;maj
210
  Push $2 ;min
211
  Push $3 ;bld
212
  Push $R0 ;temp
213

    
214
  # allocate memory
215
  System::Alloc ${OSVERSIONINFOEXA_SIZE}
216
  Pop $0
217

    
218
  # use OSVERSIONINFOEX
219
  !insertmacro __WinVer_Call_GetVersionEx ${OSVERSIONINFOEXA_SIZE}
220

    
221
  IntCmp $3 0 "" _winver_ex _winver_ex
222
    # OSVERSIONINFOEX not allowed (Win9x or NT4 w/SP < 6), use OSVERSIONINFO
223
    !insertmacro __WinVer_Call_GetVersionEx ${OSVERSIONINFOA_SIZE}
224
  _winver_ex:
225

    
226
  # get results from struct
227
  System::Call '*$0(i.s,i.r1,i.r2,i.r3,i.s,&t128.s,&i2.s,&i2,&i2,&i1.s,&i1)'
228

    
229
  # free struct
230
  System::Free $0
231

    
232
  # win9x has major and minor info in high word of dwBuildNumber - remove it
233
  IntOp $3 $3 & 0xFFFF
234

    
235
  # get dwOSVersionInfoSize
236
  Pop $R0
237

    
238
  # get dwPlatformId
239
  Pop $0
240

    
241
  # NT?
242
  IntCmp $0 ${VER_PLATFORM_WIN32_NT} "" _winver_notnt _winver_notnt
243
    IntOp $__WINVERSP $__WINVERSP | ${_WINVER_NTBIT}
244
    IntOp $__WINVERV  $__WINVERV  | ${_WINVER_NTBIT}
245
  _winver_notnt:
246

    
247
  # get service pack information
248
  IntCmp $0 ${VER_PLATFORM_WIN32_NT} _winver_nt "" _winver_nt  # win9x
249

    
250
    # get szCSDVersion
251
    Pop $0
252

    
253
    # copy second char
254
    StrCpy $0 $0 1 1
255

    
256
    # discard invalid wServicePackMajor and wProductType
257
    Pop $R0
258
    Pop $R0
259

    
260
    # switch
261
    StrCmp $0 'A' "" +3
262
      StrCpy $0 1
263
      Goto _winver_sp_done
264
    StrCmp $0 'B' "" +3
265
      StrCpy $0 2
266
      Goto _winver_sp_done
267
    StrCmp $0 'C' "" +3
268
      StrCpy $0 3
269
      Goto _winver_sp_done
270
    StrCpy $0 0
271
    Goto _winver_sp_done
272

    
273
  _winver_nt: # nt
274

    
275
    IntCmp $R0 ${OSVERSIONINFOEXA_SIZE} "" _winver_sp_noex _winver_sp_noex
276

    
277
      # discard szCSDVersion
278
      Pop $0
279

    
280
      # get wProductType
281
      Exch
282
      Pop $0
283

    
284
      # is server?
285
      IntCmp $0 ${VER_NT_WORKSTATION} _winver_noserver _winver_noserver ""
286
        IntOp $__WINVERSP $__WINVERSP | ${_WINVER_NTSRVBIT}
287
      _winver_noserver:
288

    
289
      # get wServicePackMajor
290
      Pop $0
291

    
292
      # done with sp
293
      Goto _winver_sp_done
294

    
295
    _winver_sp_noex: # OSVERSIONINFO, not OSVERSIONINFOEX
296

    
297
      ####  TODO
298
      ## For IsServer to support < NT4SP6, we need to check the registry
299
      ## here to see if we are a server and/or DC
300

    
301
      # get szCSDVersion
302
      Pop $0
303

    
304
      # discard invalid wServicePackMajor and wProductType
305
      Pop $R0
306
      Pop $R0
307

    
308
      # get service pack number from text
309
      StrCpy $R0 $0 13
310
      StrCmp $R0 "Service Pack " "" +3
311
        StrCpy $0 $0 "" 13 # cut "Service Pack "
312
        Goto +2
313
        StrCpy $0 0 # no service pack
314

    
315
!ifdef WINVER_NT4_OVER_W95
316
      IntOp $__WINVERV $__WINVERV | ${_WINVER_VERXBIT}
317
!endif
318

    
319
  _winver_sp_done:
320

    
321
  # store service pack
322
  IntOp $0 $0 << 16
323
  IntOp $__WINVERSP $__WINVERSP | $0
324

    
325
  ### now for the version
326

    
327
  # is server?
328
  IntOp $0 $__WINVERSP & ${_WINVER_NTSRVBIT}
329

    
330
  # windows xp x64?
331
  IntCmp $0 0 "" _winver_not_xp_x64 _winver_not_xp_x64 # not server
332
  IntCmp $1 5 "" _winver_not_xp_x64 _winver_not_xp_x64 # maj 5
333
  IntCmp $2 2 "" _winver_not_xp_x64 _winver_not_xp_x64 # min 2
334
    # change XP x64 from 5.2 to 5.1 so it's still XP
335
    StrCpy $2 1
336
  _winver_not_xp_x64:
337

    
338
  # server 2008?
339
  IntCmp $0 0 _winver_not_ntserver # server
340
  IntCmp 6 $1 "" "" _winver_not_ntserver # maj 6
341
    # extra bit so Server 2008 comes after Vista SP1 that has the same minor version, same for Win7 vs 2008R2
342
    IntOp $__WINVERV $__WINVERV | ${_WINVER_VERXBIT}
343
  _winver_not_ntserver:
344

    
345
  # pack version
346
  IntOp $1 $1 << 24 # VerMajor
347
  IntOp $__WINVERV $__WINVERV | $1
348
  IntOp $0 $2 << 16
349
  IntOp $__WINVERV $__WINVERV | $0 # VerMinor
350
  IntOp $__WINVERSP $__WINVERSP | $3 # VerBuild
351

    
352
  # restore registers
353
  Pop $R0
354
  Pop $3
355
  Pop $2
356
  Pop $1
357
  Pop $0
358

    
359
!macroend
360

    
361
# version comparison LogicLib macros
362

    
363
!macro _WinVerAtLeast _a _b _t _f
364
  !insertmacro _LOGICLIB_TEMP
365
  ${CallArtificialFunction} __WinVer_InitVars
366
  IntOp $_LOGICLIB_TEMP $__WINVERV & ${_WINVER_NTMASK}
367
  !insertmacro _>= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
368
!macroend
369
!macro _WinVerIs _a _b _t _f
370
  ${CallArtificialFunction} __WinVer_InitVars
371
  !insertmacro _= $__WINVERV `${_b}` `${_t}` `${_f}`
372
!macroend
373
!macro _WinVerAtMost _a _b _t _f
374
  !insertmacro _LOGICLIB_TEMP
375
  ${CallArtificialFunction} __WinVer_InitVars
376
  IntOp $_LOGICLIB_TEMP $__WINVERV & ${_WINVER_NTMASK}
377
  !insertmacro _<= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
378
!macroend
379

    
380
!macro __WinVer_DefineOSTest Test OS Suffix
381
  !define ${Test}Win${OS} `"" WinVer${Test} ${WINVER_${OS}${Suffix}}`
382
!macroend
383

    
384
!macro __WinVer_DefineOSTests Test Suffix
385
  !insertmacro __WinVer_DefineOSTest ${Test} 95     '${Suffix}'
386
  !insertmacro __WinVer_DefineOSTest ${Test} 98     '${Suffix}'
387
  !insertmacro __WinVer_DefineOSTest ${Test} ME     '${Suffix}'
388
  !insertmacro __WinVer_DefineOSTest ${Test} NT4    '${Suffix}'
389
  !insertmacro __WinVer_DefineOSTest ${Test} 2000   '${Suffix}'
390
  !insertmacro __WinVer_DefineOSTest ${Test} XP     '${Suffix}'
391
  !insertmacro __WinVer_DefineOSTest ${Test} 2003   '${Suffix}'
392
  !insertmacro __WinVer_DefineOSTest ${Test} VISTA  '${Suffix}'
393
  !insertmacro __WinVer_DefineOSTest ${Test} 2008   '${Suffix}'
394
  !insertmacro __WinVer_DefineOSTest ${Test} 7      '${Suffix}'
395
  !insertmacro __WinVer_DefineOSTest ${Test} 2008R2 '${Suffix}'
396
  !insertmacro __WinVer_DefineOSTest ${Test} 8      '${Suffix}'
397
  !insertmacro __WinVer_DefineOSTest ${Test} 2012   '${Suffix}'
398
!macroend
399

    
400
!insertmacro __WinVer_DefineOSTests AtLeast ""
401
!insertmacro __WinVer_DefineOSTests Is _NT
402
!insertmacro __WinVer_DefineOSTests AtMost ""
403

    
404
# version feature LogicLib macros
405

    
406
!macro _IsNT _a _b _t _f
407
  !insertmacro _LOGICLIB_TEMP
408
  ${CallArtificialFunction} __WinVer_InitVars
409
  IntOp $_LOGICLIB_TEMP $__WINVERSP & ${_WINVER_NTBIT}
410
  !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
411
!macroend
412
!define IsNT `"" IsNT ""`
413

    
414
!macro _IsServerOS _a _b _t _f
415
  !insertmacro _LOGICLIB_TEMP
416
  ${CallArtificialFunction} __WinVer_InitVars
417
  IntOp $_LOGICLIB_TEMP $__WINVERSP & ${_WINVER_NTSRVBIT}
418
  !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
419
!macroend
420
!define IsServerOS `"" IsServerOS ""`
421

    
422
# service pack macros
423

    
424
!macro _WinVer_GetServicePackLevel OUTVAR
425
  ${CallArtificialFunction} __WinVer_InitVars
426
  IntOp ${OUTVAR} $__WINVERSP & ${_WINVER_MASKSP}
427
  IntOp ${OUTVAR} ${OUTVAR} >> 16
428
!macroend
429
!define WinVerGetServicePackLevel '!insertmacro _WinVer_GetServicePackLevel '
430

    
431
!macro _AtLeastServicePack _a _b _t _f
432
  !insertmacro _LOGICLIB_TEMP
433
  ${WinVerGetServicePackLevel} $_LOGICLIB_TEMP
434
  !insertmacro _>= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
435
!macroend
436
!define AtLeastServicePack `"" AtLeastServicePack`
437

    
438
!macro _AtMostServicePack _a _b _t _f
439
  !insertmacro _LOGICLIB_TEMP
440
  ${WinVerGetServicePackLevel} $_LOGICLIB_TEMP
441
  !insertmacro _<= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
442
!macroend
443
!define AtMostServicePack `"" AtMostServicePack`
444

    
445
!macro _IsServicePack _a _b _t _f
446
  !insertmacro _LOGICLIB_TEMP
447
  ${WinVerGetServicePackLevel} $_LOGICLIB_TEMP
448
  !insertmacro _= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
449
!macroend
450
!define IsServicePack `"" IsServicePack`
451

    
452
# special feature LogicLib macros
453

    
454
!macro _WinVer_SysMetricCheck m _b _t _f
455
  !insertmacro _LOGICLIB_TEMP
456
  System::Call user32::GetSystemMetrics(i${m})i.s
457
  pop $_LOGICLIB_TEMP
458
  !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
459
!macroend
460

    
461
!define IsWin2003R2        `${SM_SERVERR2}    WinVer_SysMetricCheck ""`
462
!define IsStarterEdition   `${SM_STARTER}     WinVer_SysMetricCheck ""`
463
!define OSHasMediaCenter   `${SM_MEDIACENTER} WinVer_SysMetricCheck ""`
464
!define OSHasTabletSupport `${SM_TABLETPC}    WinVer_SysMetricCheck ""`
465

    
466
# version retrieval macros
467

    
468
!macro __WinVer_GetVer var rshift mask outvar
469
  ${CallArtificialFunction} __WinVer_InitVars
470
  !if "${mask}" != ""
471
    IntOp ${outvar} ${var} & ${mask}
472
    !if "${rshift}" != ""
473
      IntOp ${outvar} ${outvar} >> ${rshift}
474
    !endif
475
  !else
476
    IntOp ${outvar} ${var} >> ${rshift}
477
  !endif
478
!macroend
479

    
480
!define WinVerGetMajor '!insertmacro __WinVer_GetVer $__WINVERV  24 ${_WINVER_MASKVMAJ}'
481
!define WinVerGetMinor '!insertmacro __WinVer_GetVer $__WINVERV  16 ${_WINVER_MASKVMIN}'
482
!define WinVerGetBuild '!insertmacro __WinVer_GetVer $__WINVERSP "" ${_WINVER_MASKVBLD}'
483

    
484
# done
485

    
486
!endif # !___WINVER__NSH___
487

    
488
!verbose pop