VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Installer/VBoxGuestAdditionsCommon.nsh@ 44824

Last change on this file since 44824 was 44493, checked in by vboxsync, 12 years ago

Fixed NT4 detection.

  • Property svn:eol-style set to native
File size: 26.7 KB
Line 
1; $Id$
2; @file
3; VBoxGuestAdditionsCommon.nsh - Common / shared utility functions.
4;
5
6;
7; Copyright (C) 2006-2013 Oracle Corporation
8;
9; This file is part of VirtualBox Open Source Edition (OSE), as
10; available from http://www.virtualbox.org. This file is free software;
11; you can redistribute it and/or modify it under the terms of the GNU
12; General Public License (GPL) as published by the Free Software
13; Foundation, in version 2 as it comes in the "COPYING" file of the
14; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16;
17
18Function Common_CopyFiles
19
20 SetOutPath "$INSTDIR"
21 SetOverwrite on
22
23!ifdef VBOX_WITH_LICENSE_INSTALL_RTF
24 ; Copy license file (if any) into the installation directory
25 FILE "/oname=${LICENSE_FILE_RTF}" "$%VBOX_BRAND_LICENSE_RTF%"
26!endif
27
28 FILE "$%VBOX_PATH_DIFX%\DIFxAPI.dll"
29 FILE "$%PATH_OUT%\bin\additions\VBoxDrvInst.exe"
30
31 FILE "$%PATH_OUT%\bin\additions\VBoxVideo.inf"
32!ifdef VBOX_SIGN_ADDITIONS
33 FILE "$%PATH_OUT%\bin\additions\VBoxVideo.cat"
34!endif
35
36 FILE "iexplore.ico"
37
38FunctionEnd
39
40!ifndef UNINSTALLER_ONLY
41Function ExtractFiles
42
43 ; @todo: Use a define for all the file specs to group the files per module
44 ; and keep the redundancy low
45
46 Push $0
47 StrCpy "$0" "$INSTDIR\$%BUILD_TARGET_ARCH%"
48
49 ; Root files
50 SetOutPath "$0"
51!if $%VBOX_WITH_LICENSE_INSTALL_RTF% == "1"
52 FILE "/oname=${LICENSE_FILE_RTF}" "$%VBOX_BRAND_LICENSE_RTF%"
53!endif
54
55 ; Video driver
56 SetOutPath "$0\VBoxVideo"
57 FILE "$%PATH_OUT%\bin\additions\VBoxVideo.sys"
58 FILE "$%PATH_OUT%\bin\additions\VBoxVideo.inf"
59!ifdef VBOX_SIGN_ADDITIONS
60 FILE "$%PATH_OUT%\bin\additions\VBoxVideo.cat"
61!endif
62 FILE "$%PATH_OUT%\bin\additions\VBoxDisp.dll"
63
64!if $%VBOX_WITH_CROGL% == "1"
65 ; crOpenGL
66 FILE "$%PATH_OUT%\bin\additions\VBoxOGLarrayspu.dll"
67 FILE "$%PATH_OUT%\bin\additions\VBoxOGLcrutil.dll"
68 FILE "$%PATH_OUT%\bin\additions\VBoxOGLerrorspu.dll"
69 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpackspu.dll"
70 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpassthroughspu.dll"
71 FILE "$%PATH_OUT%\bin\additions\VBoxOGLfeedbackspu.dll"
72 FILE "$%PATH_OUT%\bin\additions\VBoxOGL.dll"
73
74 SetOutPath "$0\VBoxVideo\OpenGL"
75 FILE "$%PATH_OUT%\bin\additions\d3d8.dll"
76 FILE "$%PATH_OUT%\bin\additions\d3d9.dll"
77 FILE "$%PATH_OUT%\bin\additions\VBoxD3D8.dll"
78 FILE "$%PATH_OUT%\bin\additions\VBoxD3D9.dll"
79 FILE "$%PATH_OUT%\bin\additions\wined3d.dll"
80
81 !if $%BUILD_TARGET_ARCH% == "amd64"
82 ; Only 64-bit installer: Also copy 32-bit DLLs on 64-bit target
83 SetOutPath "$0\VBoxVideo\OpenGL\SysWow64"
84 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d8.dll"
85 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d9.dll"
86 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxOGLarrayspu.dll"
87 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxOGLcrutil.dll"
88 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxOGLerrorspu.dll"
89 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxOGLpackspu.dll"
90 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxOGLpassthroughspu.dll"
91 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxOGLfeedbackspu.dll"
92 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxOGL.dll"
93 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxD3D8.dll"
94 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxD3D9.dll"
95 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\wined3d.dll"
96 !endif
97!endif
98
99!if $%VBOX_WITH_WDDM% == "1"
100 ; WDDM Video driver for Vista and 7
101 SetOutPath "$0\VBoxVideoWddm"
102
103 !ifdef VBOX_SIGN_ADDITIONS
104 FILE "$%PATH_OUT%\bin\additions\VBoxVideoWddm.cat"
105 !endif
106 FILE "$%PATH_OUT%\bin\additions\VBoxVideoWddm.sys"
107 FILE "$%PATH_OUT%\bin\additions\VBoxVideoWddm.inf"
108 FILE "$%PATH_OUT%\bin\additions\VBoxDispD3D.dll"
109
110 !if $%VBOX_WITH_CROGL% == "1"
111 FILE "$%PATH_OUT%\bin\additions\VBoxOGLarrayspu.dll"
112 FILE "$%PATH_OUT%\bin\additions\VBoxOGLcrutil.dll"
113 FILE "$%PATH_OUT%\bin\additions\VBoxOGLerrorspu.dll"
114 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpackspu.dll"
115 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpassthroughspu.dll"
116 FILE "$%PATH_OUT%\bin\additions\VBoxOGLfeedbackspu.dll"
117 FILE "$%PATH_OUT%\bin\additions\VBoxOGL.dll"
118
119 FILE "$%PATH_OUT%\bin\additions\VBoxD3D9wddm.dll"
120 FILE "$%PATH_OUT%\bin\additions\wined3dwddm.dll"
121 !endif ; $%VBOX_WITH_CROGL% == "1"
122
123 !if $%BUILD_TARGET_ARCH% == "amd64"
124 FILE "$%PATH_OUT%\bin\additions\VBoxDispD3D-x86.dll"
125
126 !if $%VBOX_WITH_CROGL% == "1"
127 FILE "$%PATH_OUT%\bin\additions\VBoxOGLarrayspu-x86.dll"
128 FILE "$%PATH_OUT%\bin\additions\VBoxOGLcrutil-x86.dll"
129 FILE "$%PATH_OUT%\bin\additions\VBoxOGLerrorspu-x86.dll"
130 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpackspu-x86.dll"
131 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpassthroughspu-x86.dll"
132 FILE "$%PATH_OUT%\bin\additions\VBoxOGLfeedbackspu-x86.dll"
133 FILE "$%PATH_OUT%\bin\additions\VBoxOGL-x86.dll"
134
135 FILE "$%PATH_OUT%\bin\additions\VBoxD3D9wddm-x86.dll"
136 FILE "$%PATH_OUT%\bin\additions\wined3dwddm-x86.dll"
137 !endif ; $%VBOX_WITH_CROGL% == "1"
138 !endif ; $%BUILD_TARGET_ARCH% == "amd64"
139
140 !if $%VBOX_WITH_WDDM_W8% == "1"
141 ; WDDM Video driver for Win8
142 SetOutPath "$0\VBoxVideoW8"
143
144 !ifdef VBOX_SIGN_ADDITIONS
145 FILE "$%PATH_OUT%\bin\additions\VBoxVideoW8.cat"
146 !endif
147 FILE "$%PATH_OUT%\bin\additions\VBoxVideoW8.sys"
148 FILE "$%PATH_OUT%\bin\additions\VBoxVideoW8.inf"
149 FILE "$%PATH_OUT%\bin\additions\VBoxDispD3D.dll"
150
151 !if $%VBOX_WITH_CROGL% == "1"
152 FILE "$%PATH_OUT%\bin\additions\VBoxOGLarrayspu.dll"
153 FILE "$%PATH_OUT%\bin\additions\VBoxOGLcrutil.dll"
154 FILE "$%PATH_OUT%\bin\additions\VBoxOGLerrorspu.dll"
155 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpackspu.dll"
156 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpassthroughspu.dll"
157 FILE "$%PATH_OUT%\bin\additions\VBoxOGLfeedbackspu.dll"
158 FILE "$%PATH_OUT%\bin\additions\VBoxOGL.dll"
159
160 FILE "$%PATH_OUT%\bin\additions\VBoxD3D9wddm.dll"
161 FILE "$%PATH_OUT%\bin\additions\wined3dwddm.dll"
162 !endif ; $%VBOX_WITH_CROGL% == "1"
163
164 !if $%BUILD_TARGET_ARCH% == "amd64"
165 FILE "$%PATH_OUT%\bin\additions\VBoxDispD3D-x86.dll"
166
167 !if $%VBOX_WITH_CROGL% == "1"
168 FILE "$%PATH_OUT%\bin\additions\VBoxOGLarrayspu-x86.dll"
169 FILE "$%PATH_OUT%\bin\additions\VBoxOGLcrutil-x86.dll"
170 FILE "$%PATH_OUT%\bin\additions\VBoxOGLerrorspu-x86.dll"
171 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpackspu-x86.dll"
172 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpassthroughspu-x86.dll"
173 FILE "$%PATH_OUT%\bin\additions\VBoxOGLfeedbackspu-x86.dll"
174 FILE "$%PATH_OUT%\bin\additions\VBoxOGL-x86.dll"
175
176 FILE "$%PATH_OUT%\bin\additions\VBoxD3D9wddm-x86.dll"
177 FILE "$%PATH_OUT%\bin\additions\wined3dwddm-x86.dll"
178 !endif ; $%VBOX_WITH_CROGL% == "1"
179 !endif ; $%BUILD_TARGET_ARCH% == "amd64"
180 !endif ; $%VBOX_WITH_WDDM_W8% == "1"
181!endif ; $%VBOX_WITH_WDDM% == "1"
182
183 ; Mouse driver
184 SetOutPath "$0\VBoxMouse"
185 FILE "$%PATH_OUT%\bin\additions\VBoxMouse.sys"
186 FILE "$%PATH_OUT%\bin\additions\VBoxMouse.inf"
187!ifdef VBOX_SIGN_ADDITIONS
188 FILE "$%PATH_OUT%\bin\additions\VBoxMouse.cat"
189!endif
190
191!if $%BUILD_TARGET_ARCH% == "x86"
192 SetOutPath "$0\VBoxMouse\NT4"
193 FILE "$%PATH_OUT%\bin\additions\VBoxMouseNT.sys"
194!endif
195
196 ; Guest driver
197 SetOutPath "$0\VBoxGuest"
198 FILE "$%PATH_OUT%\bin\additions\VBoxGuest.sys"
199 FILE "$%PATH_OUT%\bin\additions\VBoxGuest.inf"
200!ifdef VBOX_SIGN_ADDITIONS
201 FILE "$%PATH_OUT%\bin\additions\VBoxGuest.cat"
202!endif
203 FILE "$%PATH_OUT%\bin\additions\VBoxTray.exe"
204 FILE "$%PATH_OUT%\bin\additions\VBoxHook.dll"
205 FILE "$%PATH_OUT%\bin\additions\VBoxControl.exe"
206
207!if $%BUILD_TARGET_ARCH% == "x86"
208 SetOutPath "$0\VBoxGuest\NT4"
209 FILE "$%PATH_OUT%\bin\additions\VBoxGuestNT.sys"
210!endif
211
212 ; VBoxService
213 SetOutPath "$0\Bin"
214 FILE "$%PATH_OUT%\bin\additions\VBoxService.exe"
215!if $%BUILD_TARGET_ARCH% == "x86"
216 FILE "$%PATH_OUT%\bin\additions\VBoxServiceNT.exe"
217!endif
218
219 ; Shared Folders
220 SetOutPath "$0\VBoxSF"
221 FILE "$%PATH_OUT%\bin\additions\VBoxSF.sys"
222 FILE "$%PATH_OUT%\bin\additions\VBoxMRXNP.dll"
223 !if $%BUILD_TARGET_ARCH% == "amd64"
224 ; Only 64-bit installer: Also copy 32-bit DLLs on 64-bit target
225 FILE "$%PATH_OUT%\bin\additions\VBoxMRXNP-x86.dll"
226 !endif
227
228 ; Auto-Logon
229 SetOutPath "$0\AutoLogon"
230 FILE "$%PATH_OUT%\bin\additions\VBoxGINA.dll"
231 FILE "$%PATH_OUT%\bin\additions\VBoxCredProv.dll"
232
233 ; Misc tools
234 SetOutPath "$0\Tools"
235 FILE "$%PATH_OUT%\bin\additions\VBoxDrvInst.exe"
236 FILE "$%VBOX_PATH_DIFX%\DIFxAPI.dll"
237
238!if $%BUILD_TARGET_ARCH% == "x86"
239 SetOutPath "$0\Tools\NT4"
240 FILE "$%PATH_OUT%\bin\additions\VBoxGuestDrvInst.exe"
241 FILE "$%PATH_OUT%\bin\additions\RegCleanup.exe"
242!endif
243
244 Pop $0
245
246FunctionEnd
247!endif ; UNINSTALLER_ONLY
248
249!macro CheckArchitecture un
250Function ${un}CheckArchitecture
251
252 Push $0
253
254 System::Call "kernel32::GetCurrentProcess() i .s"
255 System::Call "kernel32::IsWow64Process(i s, *i .r0)"
256 ; R0 now contains 1 if we're a 64-bit process, or 0 if not
257
258!if $%BUILD_TARGET_ARCH% == "amd64"
259 IntCmp $0 0 wrong_platform
260!else ; 32-bit
261 IntCmp $0 1 wrong_platform
262!endif
263
264 Push 0
265 Goto exit
266
267wrong_platform:
268
269 Push 1
270 Goto exit
271
272exit:
273
274FunctionEnd
275!macroend
276!insertmacro CheckArchitecture ""
277!insertmacro CheckArchitecture "un."
278
279;
280; Macro for retrieving the Windows version this installer is running on.
281;
282; @return Stack: Windows version string. Empty on error /
283; if not able to identify.
284;
285!macro GetWindowsVersionEx un
286Function ${un}GetWindowsVersionEx
287
288 Push $0
289 Push $1
290
291 ; Check if we are running on Windows 2000 or above
292 ; For other windows versions (> XP) it may be necessary to change winver.nsh
293 Call ${un}GetWindowsVersion
294 Pop $0 ; Windows Version
295
296 Push $0 ; The windows version string
297 Push "NT" ; String to search for. W2K+ returns no string containing "NT"
298 Call ${un}StrStr
299 Pop $1
300
301 ${If} $1 == "" ; If empty -> not NT 3.XX or 4.XX
302 ; $0 contains the original version string
303 ${Else}
304 ; Ok we know it is NT. Must be a string like NT X.XX
305 Push $0 ; The windows version string
306 Push "4." ; String to search for
307 Call ${un}StrStr
308 Pop $1
309 ${If} $1 == "" ; If empty -> not NT 4
310 ;; @todo NT <= 3.x ?
311 ; $0 contains the original version string
312 ${Else}
313 StrCpy $0 "NT4"
314 ${EndIf}
315 ${EndIf}
316
317 Pop $1
318 Exch $0
319
320FunctionEnd
321!macroend
322!insertmacro GetWindowsVersionEx ""
323!insertmacro GetWindowsVersionEx "un."
324
325!macro GetAdditionsVersion un
326Function ${un}GetAdditionsVersion
327
328 Push $0
329 Push $1
330
331 ; Get additions version
332 ReadRegStr $0 HKLM "SOFTWARE\$%VBOX_VENDOR_SHORT%\VirtualBox Guest Additions" "Version"
333
334 ; Get revision
335 ReadRegStr $g_strAddVerRev HKLM "SOFTWARE\$%VBOX_VENDOR_SHORT%\VirtualBox Guest Additions" "Revision"
336
337 ; Extract major version
338 Push "$0" ; String
339 Push "." ; SubString
340 Push ">" ; SearchDirection
341 Push "<" ; StrInclusionDirection
342 Push "0" ; IncludeSubString
343 Push "0" ; Loops
344 Push "0" ; CaseSensitive
345 Call ${un}StrStrAdv
346 Pop $g_strAddVerMaj
347
348 ; Extract minor version
349 Push "$0" ; String
350 Push "." ; SubString
351 Push ">" ; SearchDirection
352 Push ">" ; StrInclusionDirection
353 Push "0" ; IncludeSubString
354 Push "0" ; Loops
355 Push "0" ; CaseSensitive
356 Call ${un}StrStrAdv
357 Pop $1 ; Got first part (e.g. "1.5")
358
359 Push "$1" ; String
360 Push "." ; SubString
361 Push ">" ; SearchDirection
362 Push "<" ; StrInclusionDirection
363 Push "0" ; IncludeSubString
364 Push "0" ; Loops
365 Push "0" ; CaseSensitive
366 Call ${un}StrStrAdv
367 Pop $g_strAddVerMin ; Extracted second part (e.g. "5" from "1.5")
368
369 ; Extract build number
370 Push "$0" ; String
371 Push "." ; SubString
372 Push "<" ; SearchDirection
373 Push ">" ; StrInclusionDirection
374 Push "0" ; IncludeSubString
375 Push "0" ; Loops
376 Push "0" ; CaseSensitive
377 Call ${un}StrStrAdv
378 Pop $g_strAddVerBuild
379
380exit:
381
382 Pop $1
383 Pop $0
384
385FunctionEnd
386!macroend
387!insertmacro GetAdditionsVersion ""
388!insertmacro GetAdditionsVersion "un."
389
390!macro StopVBoxService un
391Function ${un}StopVBoxService
392
393 Push $0 ; Temp results
394 Push $1
395 Push $2 ; Image name of VBoxService
396 Push $3 ; Safety counter
397
398 StrCpy $3 "0" ; Init counter
399 ${LogVerbose} "Stopping VBoxService ..."
400
401svc_stop:
402
403 ${LogVerbose} "Stopping VBoxService via SCM ..."
404 ${If} $g_strWinVersion == "NT4"
405 nsExec::Exec '"$SYSDIR\net.exe" stop VBoxService'
406 ${Else}
407 nsExec::Exec '"$SYSDIR\SC.exe" stop VBoxService'
408 ${EndIf}
409 Sleep "1000" ; Wait a bit
410
411exe_stop:
412
413!ifdef _DEBUG
414 ${LogVerbose} "Stopping VBoxService (as exe) ..."
415!endif
416
417exe_stop_loop:
418
419 IntCmp $3 10 exit ; Only try this loop 10 times max
420 IntOp $3 $3 + 1 ; Increment
421
422!ifdef _DEBUG
423 ${LogVerbose} "Stopping attempt #$3"
424!endif
425
426 ${If} $g_strWinVersion == "NT4"
427 StrCpy $2 "VBoxServiceNT.exe"
428 ${Else}
429 StrCpy $2 "VBoxService.exe"
430 ${EndIf}
431
432 ${nsProcess::FindProcess} $2 $0
433 StrCmp $0 0 0 exit
434
435 ${nsProcess::KillProcess} $2 $0
436 Sleep "1000" ; Wait a bit
437 Goto exe_stop_loop
438
439exit:
440
441 ${LogVerbose} "Stopping VBoxService done"
442
443 Pop $3
444 Pop $2
445 Pop $1
446 Pop $0
447
448FunctionEnd
449!macroend
450!insertmacro StopVBoxService ""
451!insertmacro StopVBoxService "un."
452
453!macro StopVBoxTray un
454Function ${un}StopVBoxTray
455
456 Push $0 ; Temp results
457 Push $1 ; Safety counter
458
459 StrCpy $1 "0" ; Init counter
460 ${LogVerbose} "Stopping VBoxTray ..."
461
462exe_stop:
463
464 IntCmp $1 10 exit ; Only try this loop 10 times max
465 IntOp $1 $1 + 1 ; Increment
466
467 ${nsProcess::FindProcess} "VBoxTray.exe" $0
468 StrCmp $0 0 0 exit
469
470 ${nsProcess::KillProcess} "VBoxTray.exe" $0
471 Sleep "1000" ; Wait a bit
472 Goto exe_stop
473
474exit:
475
476 ${LogVerbose} "Stopping VBoxTray done"
477
478 Pop $1
479 Pop $0
480
481FunctionEnd
482!macroend
483!insertmacro StopVBoxTray ""
484!insertmacro StopVBoxTray "un."
485
486!macro WriteRegBinR ROOT KEY NAME VALUE
487 WriteRegBin "${ROOT}" "${KEY}" "${NAME}" "${VALUE}"
488!macroend
489
490!macro AbortShutdown un
491Function ${un}AbortShutdown
492
493 ${If} ${FileExists} "$g_strSystemDir\shutdown.exe"
494 ; Try to abort the shutdown
495 ${CmdExecute} "$\"$g_strSystemDir\shutdown.exe$\" -a" "true"
496 ${Else}
497 ${LogVerbose} "Shutting down not supported: Binary $\"$g_strSystemDir\shutdown.exe$\" not found"
498 ${EndIf}
499
500FunctionEnd
501!macroend
502!insertmacro AbortShutdown ""
503!insertmacro AbortShutdown "un."
504
505!macro CheckForWDDMCapability un
506Function ${un}CheckForWDDMCapability
507
508!if $%VBOX_WITH_WDDM% == "1"
509 ; If we're on a 32-bit Windows Vista / 7 / 8 we can use the WDDM driver
510 ${If} $g_strWinVersion == "Vista"
511 ${OrIf} $g_strWinVersion == "7"
512 ${OrIf} $g_strWinVersion == "8"
513 StrCpy $g_bCapWDDM "true"
514 ${LogVerbose} "OS is WDDM driver capable"
515 ${EndIf}
516 ; If we're on Windows 8 we *have* to use the WDDM driver, so select it
517 ; by default
518 ${If} $g_strWinVersion == "8"
519 StrCpy $g_bWithWDDM "true"
520 ${LogVerbose} "OS needs WDDM driver by default"
521 ${EndIf}
522!endif
523
524FunctionEnd
525!macroend
526!insertmacro CheckForWDDMCapability ""
527!insertmacro CheckForWDDMCapability "un."
528
529!macro CheckForCapabilities un
530Function ${un}CheckForCapabilities
531
532 Push $0
533
534 ; Retrieve system mode and store result in
535 System::Call 'user32::GetSystemMetrics(i ${SM_CLEANBOOT}) i .r0'
536 StrCpy $g_iSystemMode $0
537
538 ; Does the guest have a DLL cache?
539 ${If} $g_strWinVersion == "Vista"
540 ${OrIf} $g_strWinVersion == "7"
541 ${OrIf} $g_strWinVersion == "8"
542 StrCpy $g_bCapDllCache "true"
543 ${LogVerbose} "OS has a DLL cache"
544 ${EndIf}
545
546 ; Check whether this OS is capable of handling WDDM drivers
547 Call ${un}CheckForWDDMCapability
548
549 Pop $0
550
551FunctionEnd
552!macroend
553!insertmacro CheckForCapabilities ""
554!insertmacro CheckForCapabilities "un."
555
556; Switches (back) the path + registry view to
557; 32-bit mode (SysWOW64) on 64-bit guests
558!macro SetAppMode32 un
559Function ${un}SetAppMode32
560 !if $%BUILD_TARGET_ARCH% == "amd64"
561 ${EnableX64FSRedirection}
562 SetRegView 32
563 !endif
564FunctionEnd
565!macroend
566!insertmacro SetAppMode32 ""
567!insertmacro SetAppMode32 "un."
568
569; Because this NSIS installer is always built in 32-bit mode, we have to
570; do some tricks for the Windows paths + registry on 64-bit guests
571!macro SetAppMode64 un
572Function ${un}SetAppMode64
573 !if $%BUILD_TARGET_ARCH% == "amd64"
574 ${DisableX64FSRedirection}
575 SetRegView 64
576 !endif
577FunctionEnd
578!macroend
579!insertmacro SetAppMode64 ""
580!insertmacro SetAppMode64 "un."
581
582;
583; Retrieves the vendor ("CompanyName" of FILEINFO structure)
584; of a given file.
585; @return Stack: Company name, or "" on error/if not found.
586; @param Stack: File name to retrieve vendor for.
587;
588!macro GetFileVendor un
589Function ${un}GetFileVendor
590
591 ; Preserve values
592 Exch $0 ; Stack: $0 <filename> (Get file name into $0)
593 Push $1
594
595 IfFileExists "$0" found
596 Goto not_found
597
598found:
599
600 VBoxGuestInstallHelper::FileGetVendor "$0"
601 ; Stack: <vendor> $1 $0
602 Pop $0 ; Get vendor
603 Pop $1 ; Restore $1
604 Exch $0 ; Restore $0, push vendor on top of stack
605 Goto end
606
607not_found:
608
609 Pop $1
610 Pop $0
611 Push "File not found"
612 Goto end
613
614end:
615
616FunctionEnd
617!macroend
618!insertmacro GetFileVendor ""
619!insertmacro GetFileVendor "un."
620
621;
622; Retrieves the architecture of a given file.
623; @return Stack: Architecture ("x86", "amd64") or error message.
624; @param Stack: File name to retrieve architecture for.
625;
626!macro GetFileArchitecture un
627Function ${un}GetFileArchitecture
628
629 ; Preserve values
630 Exch $0 ; Stack: $0 <filename> (Get file name into $0)
631 Push $1
632
633 IfFileExists "$0" found
634 Goto not_found
635
636found:
637
638 VBoxGuestInstallHelper::FileGetArchitecture "$0"
639 ; Stack: <architecture> $1 $0
640 Pop $0 ; Get architecture string
641 Pop $1 ; Restore $1
642 Exch $0 ; Restore $0, push vendor on top of stack
643 Goto end
644
645not_found:
646
647 Pop $1
648 Pop $0
649 Push "File not found"
650 Goto end
651
652end:
653
654FunctionEnd
655!macroend
656!insertmacro GetFileArchitecture ""
657!insertmacro GetFileArchitecture "un."
658
659;
660; Verifies a given file by checking its file vendor and target
661; architecture.
662; @return Stack: "0" if valid, "1" if not, "2" on error / not found.
663; @param Stack: Architecture ("x86" or "amd64").
664; @param Stack: Vendor.
665; @param Stack: File name to verify.
666;
667!macro VerifyFile un
668Function ${un}VerifyFile
669
670 ; Preserve values
671 Exch $0 ; File; S: old$0 vendor arch
672 Exch ; S: vendor old$0 arch
673 Exch $1 ; Vendor; S: old$1 old$0 arch
674 Exch ; S: old$0 old$1 arch
675 Exch 2 ; S: arch old$1 old$0
676 Exch $2 ; Architecture; S: old$2 old$1 old$0
677 Push $3 ; S: old$3 old$2 old$1 old$0
678
679 IfFileExists "$0" check_vendor
680 Goto not_found
681
682check_vendor:
683
684 Push $0
685 Call ${un}GetFileVendor
686 Pop $3
687
688 ${If} $3 == $1
689 Goto check_arch
690 ${EndIf}
691 StrCpy $3 "1" ; Invalid
692 Goto end
693
694check_arch:
695
696 Push $0
697 Call ${un}GetFileArchitecture
698 Pop $3
699
700 ${If} $3 == $2
701 StrCpy $3 "0" ; Valid
702 ${Else}
703 StrCpy $3 "1" ; Invalid
704 ${EndIf}
705 Goto end
706
707not_found:
708
709 StrCpy $3 "2" ; Not found
710 Goto end
711
712end:
713
714 ; S: old$3 old$2 old$1 old$0
715 Exch $3 ; S: $3 old$2 old$1 old$0
716 Exch ; S: old$2 $3 old$1
717 Pop $2 ; S: $3 old$1 old$0
718 Exch ; S: old$1 $3 old$0
719 Pop $1 ; S: $3 old$0
720 Exch ; S: old$0 $3
721 Pop $0 ; S: $3
722
723FunctionEnd
724!macroend
725!insertmacro VerifyFile ""
726!insertmacro VerifyFile "un."
727
728;
729; Macro for accessing VerifyFile in a more convenient way by using
730; a parameter list.
731; @return Stack: "0" if valid, "1" if not, "2" on error / not found.
732; @param Un/Installer prefix; either "" or "un".
733; @param Name of file to verify.
734; @param Vendor to check for.
735; @param Architecture ("x86" or "amd64") to check for.
736;
737!macro VerifyFileEx un File Vendor Architecture
738 Push $0
739 Push "${Architecture}"
740 Push "${Vendor}"
741 Push "${File}"
742 ${LogVerbose} "Verifying file $\"${File}$\" ..."
743 Call ${un}VerifyFile
744 Pop $0
745 ${If} $0 == "0"
746 ${LogVerbose} "Verification of file $\"${File}$\" successful (Vendor: ${Vendor}, Architecture: ${Architecture})"
747 ${ElseIf} $0 == "1"
748 ${LogVerbose} "Verification of file $\"${File}$\" failed (not Vendor: ${Vendor}, and/or not Architecture: ${Architecture})"
749 ${Else}
750 ${LogVerbose} "Skipping to file $\"${File}$\"; not found"
751 ${EndIf}
752 ; Push result popped off the stack to stack again
753 Push $0
754!macroend
755!define VerifyFileEx "!insertmacro VerifyFileEx"
756
757;
758; Macro for copying a file only if the source file is verified
759; to be from a certain vendor and architecture.
760; @return Stack: "0" if copied, "1" if not, "2" on error / not found.
761; @param Un/Installer prefix; either "" or "un".
762; @param Name of file to verify and copy to destination.
763; @param Destination name to copy verified file to.
764; @param Vendor to check for.
765; @param Architecture ("x86" or "amd64") to check for.
766;
767!macro CopyFileEx un FileSrc FileDest Vendor Architecture
768 Push $0
769 Push "${Architecture}"
770 Push "${Vendor}"
771 Push "${FileSrc}"
772 Call ${un}VerifyFile
773 Pop $0
774 ${If} $0 == "0"
775 ${LogVerbose} "Copying verified file $\"${FileSrc}$\" to $\"${FileDest}$\" ..."
776 CopyFiles /SILENT "${FileSrc}" "${FileDest}"
777 ${Else}
778 ${LogVerbose} "Skipping to copy file $\"${FileSrc}$\" to $\"${FileDest}$\" (not Vendor: ${Vendor}, Architecture: ${Architecture})"
779 ${EndIf}
780 ; Push result popped off the stack to stack again
781 Push $0
782!macroend
783!define CopyFileEx "!insertmacro CopyFileEx"
784
785;
786; Macro for installing a library/DLL.
787; @return Stack: "0" if copied, "1" if not, "2" on error / not found.
788; @param Un/Installer prefix; either "" or "un".
789; @param Name of lib/DLL to verify and copy to destination.
790; @param Destination name to copy verified file to.
791; @param Temporary folder used for exchanging the (locked) lib/DLL after a reboot.
792;
793!macro InstallFileEx un FileSrc FileDest DirTemp
794 ${LogVerbose} "Installing library $\"${FileSrc}$\" to $\"${FileDest}$\" ..."
795 ; Try the gentle way and replace the file instantly
796 !insertmacro InstallLib DLL NOTSHARED NOREBOOT_NOTPROTECTED "${FileSrc}" "${FileDest}" "${DirTemp}"
797 ; If the above call didn't help, use a (later) reboot to replace the file
798 !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "${FileSrc}" "${FileDest}" "${DirTemp}"
799!macroend
800!define InstallFileEx "!insertmacro InstallFileEx"
801
802;
803; Macro for installing a library/DLL.
804; @return Stack: "0" if copied, "1" if not, "2" on error / not found.
805; @param Un/Installer prefix; either "" or "un".
806; @param Name of lib/DLL to verify and copy to destination.
807; @param Destination name to copy verified file to.
808; @param Temporary folder used for exchanging the (locked) lib/DLL after a reboot.
809; @param Vendor to check for.
810; @param Architecture ("x86" or "amd64") to check for.
811;
812!macro InstallFileVerify un FileSrc FileDest DirTemp Vendor Architecture
813 Push $0
814 Push "${Architecture}"
815 Push "${Vendor}"
816 Push "${FileSrc}"
817 ${LogVerbose} "Verifying library $\"${FileSrc}$\" ..."
818 Call ${un}VerifyFile
819 Pop $0
820 ${If} $0 == "0"
821 ${InstallFileEx} ${un} ${FileSrc} ${FileDest} ${DirTemp}
822 ${Else}
823 ${LogVerbose} "File $\"${FileSrc}$\" did not pass verification (Vendor: ${Vendor}, Architecture: ${Architecture})"
824 ${EndIf}
825 ; Push result popped off the stack to stack again.
826 Push $0
827!macroend
828!define InstallFileVerify "!insertmacro InstallFileVerify"
829
830;
831; Validates backed up and replaced Direct3D files; either the d3d*.dll have
832; to be from Microsoft or the (already) backed up msd3d*.dll files. If both
833; don't match we have a corrupted / invalid installation.
834; @return Stack: "0" if files are valid; otherwise "1".
835;
836!macro ValidateFilesDirect3D un
837Function ${un}ValidateD3DFiles
838
839 Push $0
840
841 ; We need to switch to 64-bit app mode to handle the "real" 64-bit files in
842 ; ""system32" on a 64-bit guest
843 Call ${un}SetAppMode64
844
845 ; Note: Not finding a file (like *d3d8.dll) on Windows Vista/7 is fine;
846 ; it simply is not present there.
847
848 ; Note 2: On 64-bit systems there are no 64-bit *d3d8 DLLs, only 32-bit ones
849 ; in SysWOW64 (or in system32 on 32-bit systems).
850
851!if $%BUILD_TARGET_ARCH% == "x86"
852 ${VerifyFileEx} "${un}" "$SYSDIR\d3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
853 Pop $0
854 ${If} $0 == "1"
855 Goto verify_msd3d
856 ${EndIf}
857!endif
858
859 ${VerifyFileEx} "${un}" "$SYSDIR\d3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
860 Pop $0
861 ${If} $0 == "1"
862 Goto verify_msd3d
863 ${EndIf}
864
865 ${If} $g_bCapDllCache == "true"
866!if $%BUILD_TARGET_ARCH% == "x86"
867 ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\d3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
868 Pop $0
869 ${If} $0 == "1"
870 Goto verify_msd3d
871 ${EndIf}
872!endif
873 ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\d3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
874 Pop $0
875 ${If} $0 == "1"
876 Goto verify_msd3d
877 ${EndIf}
878 ${EndIf}
879
880!if $%BUILD_TARGET_ARCH% == "amd64"
881 ${VerifyFileEx} "${un}" "$g_strSysWow64\d3d8.dll" "Microsoft Corporation" "x86"
882 Pop $0
883 ${If} $0 == "1"
884 Goto verify_msd3d
885 ${EndIf}
886 ${VerifyFileEx} "${un}" "$g_strSysWow64\d3d9.dll" "Microsoft Corporation" "x86"
887 Pop $0
888 ${If} $0 == "1"
889 Goto verify_msd3d
890 ${EndIf}
891
892 ${If} $g_bCapDllCache == "true"
893 ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\d3d8.dll" "Microsoft Corporation" "x86"
894 Pop $0
895 ${If} $0 == "1"
896 Goto verify_msd3d
897 ${EndIf}
898 ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\d3d9.dll" "Microsoft Corporation" "x86"
899 Pop $0
900 ${If} $0 == "1"
901 Goto verify_msd3d
902 ${EndIf}
903 ${EndIf}
904
905!endif
906
907 Goto valid
908
909verify_msd3d:
910
911!if $%BUILD_TARGET_ARCH% == "x86"
912 ${VerifyFileEx} "${un}" "$SYSDIR\msd3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
913 Pop $0
914 ${If} $0 == "1"
915 Goto invalid
916 ${EndIf}
917!endif
918 ${VerifyFileEx} "${un}" "$SYSDIR\msd3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
919 Pop $0
920 ${If} $0 == "1"
921 Goto invalid
922 ${EndIf}
923
924 ${If} $g_bCapDllCache == "true"
925!if $%BUILD_TARGET_ARCH% == "x86"
926 ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\msd3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
927 Pop $0
928 ${If} $0 == "1"
929 Goto invalid
930 ${EndIf}
931!endif
932 ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\msd3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
933 Pop $0
934 ${If} $0 == "1"
935 Goto invalid
936 ${EndIf}
937 ${EndIf}
938
939!if $%BUILD_TARGET_ARCH% == "amd64"
940 ${VerifyFileEx} "${un}" "$g_strSysWow64\msd3d8.dll" "Microsoft Corporation" "x86"
941 Pop $0
942 ${If} $0 == "1"
943 Goto invalid
944 ${EndIf}
945 ${VerifyFileEx} "${un}" "$g_strSysWow64\msd3d9.dll" "Microsoft Corporation" "x86"
946 Pop $0
947 ${If} $0 == "1"
948 Goto invalid
949 ${EndIf}
950
951 ${If} $g_bCapDllCache == "true"
952 ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\msd3d8.dll" "Microsoft Corporation" "x86"
953 Pop $0
954 ${If} $0 == "1"
955 Goto invalid
956 ${EndIf}
957 ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\msd3d9.dll" "Microsoft Corporation" "x86"
958 Pop $0
959 ${If} $0 == "1"
960 Goto invalid
961 ${EndIf}
962 ${EndIf}
963!endif
964
965 Goto valid
966
967valid:
968
969 StrCpy $0 "0" ; Installation valid
970 Goto end
971
972invalid:
973
974 StrCpy $0 "1" ; Installation invalid / corrupted
975 Goto end
976
977end:
978
979 Exch $0
980
981FunctionEnd
982!macroend
983!insertmacro ValidateFilesDirect3D ""
984!insertmacro ValidateFilesDirect3D "un."
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette