VirtualBox

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

Last change on this file since 71872 was 71323, checked in by vboxsync, 7 years ago

WDDM: build and use VBoxWddm.sys. bugref:9133

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 30.1 KB
Line 
1; $Id: VBoxGuestAdditionsCommon.nsh 71323 2018-03-14 14:05:32Z vboxsync $
2;; @file
3; VBoxGuestAdditionsCommon.nsh - Common / shared utility functions.
4;
5
6;
7; Copyright (C) 2006-2017 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
101 SetOutPath "$0\VBoxWddm"
102
103 !ifdef VBOX_SIGN_ADDITIONS
104 FILE "$%PATH_OUT%\bin\additions\VBoxWddm.cat"
105 !endif
106 FILE "$%PATH_OUT%\bin\additions\VBoxWddm.sys"
107 FILE "$%PATH_OUT%\bin\additions\VBoxWddm.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!endif ; $%VBOX_WITH_WDDM% == "1"
140
141 ; Mouse driver
142 SetOutPath "$0\VBoxMouse"
143 FILE "$%PATH_OUT%\bin\additions\VBoxMouse.sys"
144 FILE "$%PATH_OUT%\bin\additions\VBoxMouse.inf"
145!ifdef VBOX_SIGN_ADDITIONS
146 FILE "$%PATH_OUT%\bin\additions\VBoxMouse.cat"
147!endif
148
149!if $%BUILD_TARGET_ARCH% == "x86"
150 SetOutPath "$0\VBoxMouse\NT4"
151 FILE "$%PATH_OUT%\bin\additions\VBoxMouseNT.sys"
152!endif
153
154 ; Guest driver
155 SetOutPath "$0\VBoxGuest"
156 FILE "$%PATH_OUT%\bin\additions\VBoxGuest.sys"
157 FILE "$%PATH_OUT%\bin\additions\VBoxGuest.inf"
158!ifdef VBOX_SIGN_ADDITIONS
159 FILE "$%PATH_OUT%\bin\additions\VBoxGuest.cat"
160!endif
161 FILE "$%PATH_OUT%\bin\additions\VBoxTray.exe"
162 FILE "$%PATH_OUT%\bin\additions\VBoxHook.dll"
163 FILE "$%PATH_OUT%\bin\additions\VBoxControl.exe"
164
165 ; VBoxService
166 SetOutPath "$0\Bin"
167 FILE "$%PATH_OUT%\bin\additions\VBoxService.exe"
168
169 ; Shared Folders
170 SetOutPath "$0\VBoxSF"
171 FILE "$%PATH_OUT%\bin\additions\VBoxSF.sys"
172 FILE "$%PATH_OUT%\bin\additions\VBoxMRXNP.dll"
173 !if $%BUILD_TARGET_ARCH% == "amd64"
174 ; Only 64-bit installer: Also copy 32-bit DLLs on 64-bit target
175 FILE "$%PATH_OUT%\bin\additions\VBoxMRXNP-x86.dll"
176 !endif
177
178 ; Auto-Logon
179 SetOutPath "$0\AutoLogon"
180 FILE "$%PATH_OUT%\bin\additions\VBoxGINA.dll"
181 FILE "$%PATH_OUT%\bin\additions\VBoxCredProv.dll"
182
183 ; Misc tools
184 SetOutPath "$0\Tools"
185 FILE "$%PATH_OUT%\bin\additions\VBoxDrvInst.exe"
186 FILE "$%VBOX_PATH_DIFX%\DIFxAPI.dll"
187
188!if $%BUILD_TARGET_ARCH% == "x86"
189 SetOutPath "$0\Tools\NT4"
190 FILE "$%PATH_OUT%\bin\additions\VBoxGuestDrvInst.exe"
191 FILE "$%PATH_OUT%\bin\additions\RegCleanup.exe"
192!endif
193
194 Pop $0
195
196FunctionEnd
197!endif ; UNINSTALLER_ONLY
198
199!macro CheckArchitecture un
200Function ${un}CheckArchitecture
201
202 Push $0
203
204 System::Call "kernel32::GetCurrentProcess() i .s"
205 System::Call "kernel32::IsWow64Process(i s, *i .r0)"
206 ; R0 now contains 1 if we're a 64-bit process, or 0 if not
207
208!if $%BUILD_TARGET_ARCH% == "amd64"
209 IntCmp $0 0 wrong_platform
210!else ; 32-bit
211 IntCmp $0 1 wrong_platform
212!endif
213
214 Push 0
215 Goto exit
216
217wrong_platform:
218
219 Push 1
220 Goto exit
221
222exit:
223
224FunctionEnd
225!macroend
226!insertmacro CheckArchitecture ""
227!insertmacro CheckArchitecture "un."
228
229;
230; Macro for retrieving the Windows version this installer is running on.
231;
232; @return Stack: Windows version string. Empty on error /
233; if not able to identify.
234;
235!macro GetWindowsVersionEx un
236Function ${un}GetWindowsVersionEx
237
238 Push $0
239 Push $1
240
241 ; Check if we are running on Windows 2000 or above
242 ; For other windows versions (> XP) it may be necessary to change winver.nsh
243 Call ${un}GetWindowsVersion
244 Pop $0 ; Windows Version
245
246 Push $0 ; The windows version string
247 Push "NT" ; String to search for. W2K+ returns no string containing "NT"
248 Call ${un}StrStr
249 Pop $1
250
251 ${If} $1 == "" ; If empty -> not NT 3.XX or 4.XX
252 ; $0 contains the original version string
253 ${Else}
254 ; Ok we know it is NT. Must be a string like NT X.XX
255 Push $0 ; The windows version string
256 Push "4." ; String to search for
257 Call ${un}StrStr
258 Pop $1
259 ${If} $1 == "" ; If empty -> not NT 4
260 ;; @todo NT <= 3.x ?
261 ; $0 contains the original version string
262 ${Else}
263 StrCpy $0 "NT4"
264 ${EndIf}
265 ${EndIf}
266
267 Pop $1
268 Exch $0
269
270FunctionEnd
271!macroend
272!insertmacro GetWindowsVersionEx ""
273!insertmacro GetWindowsVersionEx "un."
274
275!macro GetAdditionsVersion un
276Function ${un}GetAdditionsVersion
277
278 Push $0
279 Push $1
280
281 ; Get additions version
282 ReadRegStr $0 HKLM "SOFTWARE\$%VBOX_VENDOR_SHORT%\VirtualBox Guest Additions" "Version"
283
284 ; Get revision
285 ReadRegStr $g_strAddVerRev HKLM "SOFTWARE\$%VBOX_VENDOR_SHORT%\VirtualBox Guest Additions" "Revision"
286
287 ; Extract major version
288 Push "$0" ; String
289 Push "." ; SubString
290 Push ">" ; SearchDirection
291 Push "<" ; StrInclusionDirection
292 Push "0" ; IncludeSubString
293 Push "0" ; Loops
294 Push "0" ; CaseSensitive
295 Call ${un}StrStrAdv
296 Pop $g_strAddVerMaj
297
298 ; Extract minor version
299 Push "$0" ; String
300 Push "." ; SubString
301 Push ">" ; SearchDirection
302 Push ">" ; StrInclusionDirection
303 Push "0" ; IncludeSubString
304 Push "0" ; Loops
305 Push "0" ; CaseSensitive
306 Call ${un}StrStrAdv
307 Pop $1 ; Got first part (e.g. "1.5")
308
309 Push "$1" ; String
310 Push "." ; SubString
311 Push ">" ; SearchDirection
312 Push "<" ; StrInclusionDirection
313 Push "0" ; IncludeSubString
314 Push "0" ; Loops
315 Push "0" ; CaseSensitive
316 Call ${un}StrStrAdv
317 Pop $g_strAddVerMin ; Extracted second part (e.g. "5" from "1.5")
318
319 ; Extract build number
320 Push "$0" ; String
321 Push "." ; SubString
322 Push "<" ; SearchDirection
323 Push ">" ; StrInclusionDirection
324 Push "0" ; IncludeSubString
325 Push "0" ; Loops
326 Push "0" ; CaseSensitive
327 Call ${un}StrStrAdv
328 Pop $g_strAddVerBuild
329
330exit:
331
332 Pop $1
333 Pop $0
334
335FunctionEnd
336!macroend
337!insertmacro GetAdditionsVersion ""
338!insertmacro GetAdditionsVersion "un."
339
340!macro StopVBoxService un
341Function ${un}StopVBoxService
342
343 Push $0 ; Temp results
344 Push $1
345 Push $2 ; Image name of VBoxService
346 Push $3 ; Safety counter
347
348 StrCpy $3 "0" ; Init counter
349 ${LogVerbose} "Stopping VBoxService ..."
350
351svc_stop:
352
353 ${LogVerbose} "Stopping VBoxService via SCM ..."
354 ${If} $g_strWinVersion == "NT4"
355 nsExec::Exec '"$SYSDIR\net.exe" stop VBoxService'
356 ${Else}
357 nsExec::Exec '"$SYSDIR\SC.exe" stop VBoxService'
358 ${EndIf}
359 Sleep "1000" ; Wait a bit
360
361exe_stop:
362
363!ifdef _DEBUG
364 ${LogVerbose} "Stopping VBoxService (as exe) ..."
365!endif
366
367exe_stop_loop:
368
369 IntCmp $3 10 exit ; Only try this loop 10 times max
370 IntOp $3 $3 + 1 ; Increment
371
372!ifdef _DEBUG
373 ${LogVerbose} "Stopping attempt #$3"
374!endif
375
376 StrCpy $2 "VBoxService.exe"
377
378 ${nsProcess::FindProcess} $2 $0
379 StrCmp $0 0 0 exit
380
381 ${nsProcess::KillProcess} $2 $0
382 Sleep "1000" ; Wait a bit
383 Goto exe_stop_loop
384
385exit:
386
387 ${LogVerbose} "Stopping VBoxService done"
388
389 Pop $3
390 Pop $2
391 Pop $1
392 Pop $0
393
394FunctionEnd
395!macroend
396!insertmacro StopVBoxService ""
397!insertmacro StopVBoxService "un."
398
399!macro StopVBoxTray un
400Function ${un}StopVBoxTray
401
402 Push $0 ; Temp results
403 Push $1 ; Safety counter
404
405 StrCpy $1 "0" ; Init counter
406 ${LogVerbose} "Stopping VBoxTray ..."
407
408exe_stop:
409
410 IntCmp $1 10 exit ; Only try this loop 10 times max
411 IntOp $1 $1 + 1 ; Increment
412
413 ${nsProcess::FindProcess} "VBoxTray.exe" $0
414 StrCmp $0 0 0 exit
415
416 ${nsProcess::KillProcess} "VBoxTray.exe" $0
417 Sleep "1000" ; Wait a bit
418 Goto exe_stop
419
420exit:
421
422 ${LogVerbose} "Stopping VBoxTray done"
423
424 Pop $1
425 Pop $0
426
427FunctionEnd
428!macroend
429!insertmacro StopVBoxTray ""
430!insertmacro StopVBoxTray "un."
431
432!macro StopVBoxMMR un
433Function ${un}StopVBoxMMR
434
435 Push $0 ; Temp results
436 Push $1 ; Safety counter
437
438 StrCpy $1 "0" ; Init counter
439 DetailPrint "Stopping VBoxMMR ..."
440
441exe_stop:
442
443 IntCmp $1 10 exit ; Only try this loop 10 times max
444 IntOp $1 $1 + 1 ; Increment
445
446 ${nsProcess::FindProcess} "VBoxMMR.exe" $0
447 StrCmp $0 0 0 exit
448
449 ${nsProcess::KillProcess} "VBoxMMR.exe" $0
450 Sleep "1000" ; Wait a bit
451 Goto exe_stop
452
453exit:
454
455 DetailPrint "Stopping VBoxMMR done."
456
457 Pop $1
458 Pop $0
459
460FunctionEnd
461!macroend
462!insertmacro StopVBoxMMR ""
463!insertmacro StopVBoxMMR "un."
464
465!macro WriteRegBinR ROOT KEY NAME VALUE
466 WriteRegBin "${ROOT}" "${KEY}" "${NAME}" "${VALUE}"
467!macroend
468
469!macro AbortShutdown un
470Function ${un}AbortShutdown
471
472 ${If} ${FileExists} "$g_strSystemDir\shutdown.exe"
473 ; Try to abort the shutdown
474 ${CmdExecute} "$\"$g_strSystemDir\shutdown.exe$\" -a" "true"
475 ${Else}
476 ${LogVerbose} "Shutting down not supported: Binary $\"$g_strSystemDir\shutdown.exe$\" not found"
477 ${EndIf}
478
479FunctionEnd
480!macroend
481!insertmacro AbortShutdown ""
482!insertmacro AbortShutdown "un."
483
484!macro CheckForWDDMCapability un
485Function ${un}CheckForWDDMCapability
486
487!if $%VBOX_WITH_WDDM% == "1"
488 ; If we're on a 32-bit Windows Vista / 7 / 8 we can use the WDDM driver
489 ${If} $g_strWinVersion == "Vista"
490 ${OrIf} $g_strWinVersion == "7"
491 ${OrIf} $g_strWinVersion == "8"
492 ${OrIf} $g_strWinVersion == "8_1"
493 ${OrIf} $g_strWinVersion == "10"
494 StrCpy $g_bCapWDDM "true"
495 ${LogVerbose} "OS is WDDM driver capable"
496 ${EndIf}
497 ; If we're on Windows 8 we *have* to use the WDDM driver, so select it
498 ; by default
499 ${If} $g_strWinVersion == "8"
500 ${OrIf} $g_strWinVersion == "8_1"
501 ${OrIf} $g_strWinVersion == "10"
502 StrCpy $g_bWithWDDM "true"
503 ${LogVerbose} "OS needs WDDM driver by default"
504 ${EndIf}
505!endif
506
507FunctionEnd
508!macroend
509!insertmacro CheckForWDDMCapability ""
510!insertmacro CheckForWDDMCapability "un."
511
512!macro CheckForCapabilities un
513Function ${un}CheckForCapabilities
514
515 Push $0
516
517 ; Retrieve system mode and store result in
518 System::Call 'user32::GetSystemMetrics(i ${SM_CLEANBOOT}) i .r0'
519 StrCpy $g_iSystemMode $0
520
521 ; Does the guest have a DLL cache?
522 ${If} $g_strWinVersion == "NT4"
523 ${OrIf} $g_strWinVersion == "2000"
524 ${OrIf} $g_strWinVersion == "XP"
525 StrCpy $g_bCapDllCache "true"
526 ${LogVerbose} "OS has a DLL cache"
527 ${EndIf}
528
529 ; Check whether this OS is capable of handling WDDM drivers
530 Call ${un}CheckForWDDMCapability
531
532 Pop $0
533
534FunctionEnd
535!macroend
536!insertmacro CheckForCapabilities ""
537!insertmacro CheckForCapabilities "un."
538
539; Switches (back) the path + registry view to
540; 32-bit mode (SysWOW64) on 64-bit guests
541!macro SetAppMode32 un
542Function ${un}SetAppMode32
543 !if $%BUILD_TARGET_ARCH% == "amd64"
544 ${EnableX64FSRedirection}
545 SetRegView 32
546 !endif
547FunctionEnd
548!macroend
549!insertmacro SetAppMode32 ""
550!insertmacro SetAppMode32 "un."
551
552; Because this NSIS installer is always built in 32-bit mode, we have to
553; do some tricks for the Windows paths + registry on 64-bit guests
554!macro SetAppMode64 un
555Function ${un}SetAppMode64
556 !if $%BUILD_TARGET_ARCH% == "amd64"
557 ${DisableX64FSRedirection}
558 SetRegView 64
559 !endif
560FunctionEnd
561!macroend
562!insertmacro SetAppMode64 ""
563!insertmacro SetAppMode64 "un."
564
565;
566; Retrieves the vendor ("CompanyName" of FILEINFO structure)
567; of a given file.
568; @return Stack: Company name, or "" on error/if not found.
569; @param Stack: File name to retrieve vendor for.
570;
571!macro GetFileVendor un
572Function ${un}GetFileVendor
573
574 ; Preserve values
575 Exch $0 ; Stack: $0 <filename> (Get file name into $0)
576 Push $1
577
578 IfFileExists "$0" found
579 Goto not_found
580
581found:
582
583 VBoxGuestInstallHelper::FileGetVendor "$0"
584 ; Stack: <vendor> $1 $0
585 Pop $0 ; Get vendor
586 Pop $1 ; Restore $1
587 Exch $0 ; Restore $0, push vendor on top of stack
588 Goto end
589
590not_found:
591
592 Pop $1
593 Pop $0
594 Push "File not found"
595 Goto end
596
597end:
598
599FunctionEnd
600!macroend
601!insertmacro GetFileVendor ""
602!insertmacro GetFileVendor "un."
603
604;
605; Retrieves the architecture of a given file.
606; @return Stack: Architecture ("x86", "amd64") or error message.
607; @param Stack: File name to retrieve architecture for.
608;
609!macro GetFileArchitecture un
610Function ${un}GetFileArchitecture
611
612 ; Preserve values
613 Exch $0 ; Stack: $0 <filename> (Get file name into $0)
614 Push $1
615
616 IfFileExists "$0" found
617 Goto not_found
618
619found:
620
621 VBoxGuestInstallHelper::FileGetArchitecture "$0"
622 ; Stack: <architecture> $1 $0
623 Pop $0 ; Get architecture string
624 Pop $1 ; Restore $1
625 Exch $0 ; Restore $0, push vendor on top of stack
626 Goto end
627
628not_found:
629
630 Pop $1
631 Pop $0
632 Push "File not found"
633 Goto end
634
635end:
636
637FunctionEnd
638!macroend
639!insertmacro GetFileArchitecture ""
640!insertmacro GetFileArchitecture "un."
641
642;
643; Verifies a given file by checking its file vendor and target
644; architecture.
645; @return Stack: "0" if valid, "1" if not, "2" on error / not found.
646; @param Stack: Architecture ("x86" or "amd64").
647; @param Stack: Vendor.
648; @param Stack: File name to verify.
649;
650!macro VerifyFile un
651Function ${un}VerifyFile
652
653 ; Preserve values
654 Exch $0 ; File; S: old$0 vendor arch
655 Exch ; S: vendor old$0 arch
656 Exch $1 ; Vendor; S: old$1 old$0 arch
657 Exch ; S: old$0 old$1 arch
658 Exch 2 ; S: arch old$1 old$0
659 Exch $2 ; Architecture; S: old$2 old$1 old$0
660 Push $3 ; S: old$3 old$2 old$1 old$0
661
662 IfFileExists "$0" check_vendor
663 Goto not_found
664
665check_vendor:
666
667 Push $0
668 Call ${un}GetFileVendor
669 Pop $3
670
671 ${If} $3 == $1
672 Goto check_arch
673 ${EndIf}
674 StrCpy $3 "1" ; Invalid
675 Goto end
676
677check_arch:
678
679 Push $0
680 Call ${un}GetFileArchitecture
681 Pop $3
682
683 ${If} $3 == $2
684 StrCpy $3 "0" ; Valid
685 ${Else}
686 StrCpy $3 "1" ; Invalid
687 ${EndIf}
688 Goto end
689
690not_found:
691
692 StrCpy $3 "2" ; Not found
693 Goto end
694
695end:
696
697 ; S: old$3 old$2 old$1 old$0
698 Exch $3 ; S: $3 old$2 old$1 old$0
699 Exch ; S: old$2 $3 old$1
700 Pop $2 ; S: $3 old$1 old$0
701 Exch ; S: old$1 $3 old$0
702 Pop $1 ; S: $3 old$0
703 Exch ; S: old$0 $3
704 Pop $0 ; S: $3
705
706FunctionEnd
707!macroend
708!insertmacro VerifyFile ""
709!insertmacro VerifyFile "un."
710
711;
712; Macro for accessing VerifyFile in a more convenient way by using
713; a parameter list.
714; @return Stack: "0" if valid, "1" if not, "2" on error / not found.
715; @param Un/Installer prefix; either "" or "un".
716; @param Name of file to verify.
717; @param Vendor to check for.
718; @param Architecture ("x86" or "amd64") to check for.
719;
720!macro VerifyFileEx un File Vendor Architecture
721 Push $0
722 Push "${Architecture}"
723 Push "${Vendor}"
724 Push "${File}"
725 ${LogVerbose} "Verifying file $\"${File}$\" ..."
726 Call ${un}VerifyFile
727 Pop $0
728 ${If} $0 == "0"
729 ${LogVerbose} "Verification of file $\"${File}$\" successful (Vendor: ${Vendor}, Architecture: ${Architecture})"
730 ${ElseIf} $0 == "1"
731 ${LogVerbose} "Verification of file $\"${File}$\" failed (not Vendor: ${Vendor}, and/or not Architecture: ${Architecture})"
732 ${Else}
733 ${LogVerbose} "Skipping to file $\"${File}$\"; not found"
734 ${EndIf}
735 ; Push result popped off the stack to stack again
736 Push $0
737!macroend
738!define VerifyFileEx "!insertmacro VerifyFileEx"
739
740;
741; Macro for copying a file only if the source file is verified
742; to be from a certain vendor and architecture.
743; @return Stack: "0" if copied, "1" if not, "2" on error / not found.
744; @param Un/Installer prefix; either "" or "un".
745; @param Name of file to verify and copy to destination.
746; @param Destination name to copy verified file to.
747; @param Vendor to check for.
748; @param Architecture ("x86" or "amd64") to check for.
749;
750!macro CopyFileEx un FileSrc FileDest Vendor Architecture
751 Push $0
752 Push "${Architecture}"
753 Push "${Vendor}"
754 Push "${FileSrc}"
755 Call ${un}VerifyFile
756 Pop $0
757 ${If} $0 == "0"
758 ${LogVerbose} "Copying verified file $\"${FileSrc}$\" to $\"${FileDest}$\" ..."
759 ClearErrors
760 SetOverwrite on
761 CopyFiles /SILENT "${FileSrc}" "${FileDest}"
762 ${If} ${Errors}
763 CreateDirectory "$TEMP\${PRODUCT_NAME}"
764 ${GetFileName} "${FileSrc}" $0 ; Get the base name
765 CopyFiles /SILENT "${FileSrc}" "$TEMP\${PRODUCT_NAME}\$0"
766 ${LogVerbose} "Immediate installation failed, postponing to next reboot (temporary location is: $\"$TEMP\${PRODUCT_NAME}\$0$\") ..."
767 ;${InstallFileEx} "${un}" "${FileSrc}" "${FileDest}" "$TEMP" ; Only works with compile time files!
768 System::Call "kernel32::MoveFileEx(t '$TEMP\${PRODUCT_NAME}\$0', t '${FileDest}', i 5)"
769 ${EndIf}
770 ${Else}
771 ${LogVerbose} "Skipping to copy file $\"${FileSrc}$\" to $\"${FileDest}$\" (not Vendor: ${Vendor}, Architecture: ${Architecture})"
772 ${EndIf}
773 ; Push result popped off the stack to stack again
774 Push $0
775!macroend
776!define CopyFileEx "!insertmacro CopyFileEx"
777
778;
779; Macro for installing a library/DLL.
780; @return Stack: "0" if copied, "1" if not, "2" on error / not found.
781; @param Un/Installer prefix; either "" or "un".
782; @param Name of lib/DLL to copy to destination.
783; @param Destination name to copy the source file to.
784; @param Temporary folder used for exchanging the (locked) lib/DLL after a reboot.
785;
786!macro InstallFileEx un FileSrc FileDest DirTemp
787 ${LogVerbose} "Installing library $\"${FileSrc}$\" to $\"${FileDest}$\" ..."
788 ; Try the gentle way and replace the file instantly
789 !insertmacro InstallLib DLL NOTSHARED NOREBOOT_NOTPROTECTED "${FileSrc}" "${FileDest}" "${DirTemp}"
790 ; If the above call didn't help, use a (later) reboot to replace the file
791 !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "${FileSrc}" "${FileDest}" "${DirTemp}"
792!macroend
793!define InstallFileEx "!insertmacro InstallFileEx"
794
795;
796; Macro for installing a library/DLL.
797; @return Stack: "0" if copied, "1" if not, "2" on error / not found.
798; @param Un/Installer prefix; either "" or "un".
799; @param Name of lib/DLL to verify and copy to destination.
800; @param Destination name to copy verified file to.
801; @param Temporary folder used for exchanging the (locked) lib/DLL after a reboot.
802; @param Vendor to check for.
803; @param Architecture ("x86" or "amd64") to check for.
804;
805!macro InstallFileVerify un FileSrc FileDest DirTemp Vendor Architecture
806 Push $0
807 Push "${Architecture}"
808 Push "${Vendor}"
809 Push "${FileSrc}"
810 ${LogVerbose} "Verifying library $\"${FileSrc}$\" ..."
811 Call ${un}VerifyFile
812 Pop $0
813 ${If} $0 == "0"
814 ${InstallFileEx} ${un} ${FileSrc} ${FileDest} ${DirTemp}
815 ${Else}
816 ${LogVerbose} "File $\"${FileSrc}$\" did not pass verification (Vendor: ${Vendor}, Architecture: ${Architecture})"
817 ${EndIf}
818 ; Push result popped off the stack to stack again.
819 Push $0
820!macroend
821!define InstallFileVerify "!insertmacro InstallFileVerify"
822
823; Prepares the access rights for replacing
824; a WRP (Windows Resource Protection) protected file
825!macro PrepareWRPFile un
826Function ${un}PrepareWRPFile
827
828 Pop $0
829 Push $1
830
831 ${IfNot} ${FileExists} "$0"
832 ${LogVerbose} "WRP: File $\"$0$\" does not exist, skipping"
833 Return
834 ${EndIf}
835
836 ${Switch} $g_strWinVersion
837 ${Case} "NT4"
838 ${Case} "2000"
839 ${Case} "XP"
840 ${LogVerbose} "WRP: changing ownership or permissions is not required on NT4, 2000, XP."
841 ${Break}
842 ${Default}
843 ${CmdExecute} "$\"$g_strSystemDir\takeown.exe$\" /A /F $\"$0$\"" "true"
844 Pop $1
845 ${LogVerbose} "WRP: Changing ownership for $\"$0$\" returned: $1"
846
847 ${CmdExecute} "icacls.exe $\"$0$\" /grant *S-1-5-32-544:F" "true"
848 Pop $1
849 ${LogVerbose} "WRP: Changing DACL for $\"$0$\" returned: $1"
850
851 Sleep 1000 ; TrustedInstaller needs some time to forget about the file
852 ${EndSwitch}
853
854!if $%VBOX_WITH_GUEST_INSTALL_HELPER% == "1"
855 !ifdef WFP_FILE_EXCEPTION
856 VBoxGuestInstallHelper::DisableWFP "$0"
857 Pop $1 ; Get return value (ignored for now)
858 ${LogVerbose} "WRP: Setting WFP exception for $\"$0$\" returned: $1"
859 !endif
860!endif
861
862 Pop $1
863
864FunctionEnd
865!macroend
866!insertmacro PrepareWRPFile ""
867!insertmacro PrepareWRPFile "un."
868
869;
870; Macro for preparing the access rights for replacing
871; a WRP (Windows Resource Protection) protected file.
872; @return None.
873; @param Path of file to prepare.
874;
875!macro PrepareWRPFileEx un FileSrc
876 Push $0
877 Push "${FileSrc}"
878 Call ${un}PrepareWRPFile
879 Pop $0
880!macroend
881!define PrepareWRPFileEx "!insertmacro PrepareWRPFileEx"
882
883;
884; Validates backed up and replaced Direct3D files; either the d3d*.dll have
885; to be from Microsoft or the (already) backed up msd3d*.dll files. If both
886; don't match we have a corrupted / invalid installation.
887; @return Stack: "0" if files are valid; otherwise "1".
888;
889!macro ValidateFilesDirect3D un
890Function ${un}ValidateD3DFiles
891
892 Push $0
893
894 ; We need to switch to 64-bit app mode to handle the "real" 64-bit files in
895 ; "system32" on a 64-bit guest
896 Call ${un}SetAppMode64
897
898 ; Note: Not finding a file (like *d3d8.dll) on Windows Vista/7 is fine;
899 ; it simply is not present there.
900
901 ; Note 2: On 64-bit systems there are no 64-bit *d3d8 DLLs, only 32-bit ones
902 ; in SysWOW64 (or in system32 on 32-bit systems).
903
904!if $%BUILD_TARGET_ARCH% == "x86"
905 ${VerifyFileEx} "${un}" "$SYSDIR\d3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
906 Pop $0
907 ${If} $0 == "1"
908 Goto verify_msd3d
909 ${EndIf}
910!endif
911
912 ${VerifyFileEx} "${un}" "$SYSDIR\d3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
913 Pop $0
914 ${If} $0 == "1"
915 Goto verify_msd3d
916 ${EndIf}
917
918 ${If} $g_bCapDllCache == "true"
919!if $%BUILD_TARGET_ARCH% == "x86"
920 ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\d3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
921 Pop $0
922 ${If} $0 == "1"
923 Goto verify_msd3d
924 ${EndIf}
925!endif
926 ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\d3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
927 Pop $0
928 ${If} $0 == "1"
929 Goto verify_msd3d
930 ${EndIf}
931 ${EndIf}
932
933!if $%BUILD_TARGET_ARCH% == "amd64"
934 ${VerifyFileEx} "${un}" "$g_strSysWow64\d3d8.dll" "Microsoft Corporation" "x86"
935 Pop $0
936 ${If} $0 == "1"
937 Goto verify_msd3d
938 ${EndIf}
939 ${VerifyFileEx} "${un}" "$g_strSysWow64\d3d9.dll" "Microsoft Corporation" "x86"
940 Pop $0
941 ${If} $0 == "1"
942 Goto verify_msd3d
943 ${EndIf}
944
945 ${If} $g_bCapDllCache == "true"
946 ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\d3d8.dll" "Microsoft Corporation" "x86"
947 Pop $0
948 ${If} $0 == "1"
949 Goto verify_msd3d
950 ${EndIf}
951 ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\d3d9.dll" "Microsoft Corporation" "x86"
952 Pop $0
953 ${If} $0 == "1"
954 Goto verify_msd3d
955 ${EndIf}
956 ${EndIf}
957
958!endif
959
960 Goto valid
961
962verify_msd3d:
963
964!if $%BUILD_TARGET_ARCH% == "x86"
965 ${VerifyFileEx} "${un}" "$SYSDIR\msd3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
966 Pop $0
967 ${If} $0 == "1"
968 Goto invalid
969 ${EndIf}
970!endif
971 ${VerifyFileEx} "${un}" "$SYSDIR\msd3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
972 Pop $0
973 ${If} $0 == "1"
974 Goto invalid
975 ${EndIf}
976
977 ${If} $g_bCapDllCache == "true"
978!if $%BUILD_TARGET_ARCH% == "x86"
979 ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\msd3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
980 Pop $0
981 ${If} $0 == "1"
982 Goto invalid
983 ${EndIf}
984!endif
985 ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\msd3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
986 Pop $0
987 ${If} $0 == "1"
988 Goto invalid
989 ${EndIf}
990 ${EndIf}
991
992!if $%BUILD_TARGET_ARCH% == "amd64"
993 ${VerifyFileEx} "${un}" "$g_strSysWow64\msd3d8.dll" "Microsoft Corporation" "x86"
994 Pop $0
995 ${If} $0 == "1"
996 Goto invalid
997 ${EndIf}
998 ${VerifyFileEx} "${un}" "$g_strSysWow64\msd3d9.dll" "Microsoft Corporation" "x86"
999 Pop $0
1000 ${If} $0 == "1"
1001 Goto invalid
1002 ${EndIf}
1003
1004 ${If} $g_bCapDllCache == "true"
1005 ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\msd3d8.dll" "Microsoft Corporation" "x86"
1006 Pop $0
1007 ${If} $0 == "1"
1008 Goto invalid
1009 ${EndIf}
1010 ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\msd3d9.dll" "Microsoft Corporation" "x86"
1011 Pop $0
1012 ${If} $0 == "1"
1013 Goto invalid
1014 ${EndIf}
1015 ${EndIf}
1016!endif
1017
1018 Goto valid
1019
1020valid:
1021
1022 StrCpy $0 "0" ; Installation valid
1023 Goto end
1024
1025invalid:
1026
1027 StrCpy $0 "1" ; Installation invalid / corrupted
1028 Goto end
1029
1030end:
1031
1032 Exch $0
1033
1034FunctionEnd
1035!macroend
1036!insertmacro ValidateFilesDirect3D ""
1037!insertmacro ValidateFilesDirect3D "un."
1038
1039;
1040; Restores formerly backed up Direct3D original files, which were replaced by
1041; a VBox XPDM driver installation before. This might be necessary for upgrading a
1042; XPDM installation to a WDDM one.
1043; @return Stack: "0" if files were restored successfully; otherwise "1".
1044;
1045!macro RestoreFilesDirect3D un
1046Function ${un}RestoreFilesDirect3D
1047
1048 Push $0
1049
1050 ; We need to switch to 64-bit app mode to handle the "real" 64-bit files in
1051 ; "system32" on a 64-bit guest
1052 Call ${un}SetAppMode64
1053
1054 ; Note: Not finding a file (like *d3d8.dll) on Windows Vista/7 is fine;
1055 ; it simply is not present there.
1056
1057 ; Note 2: On 64-bit systems there are no 64-bit *d3d8 DLLs, only 32-bit ones
1058 ; in SysWOW64 (or in system32 on 32-bit systems).
1059
1060 ${LogVerbose} "Restoring original D3D files ..."
1061!if $%BUILD_TARGET_ARCH% == "x86"
1062 ${PrepareWRPFileEx} "${un}" "$SYSDIR\d3d8.dll"
1063 ${CopyFileEx} "${un}" "$SYSDIR\msd3d8.dll" "$SYSDIR\d3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
1064!endif
1065 ${PrepareWRPFileEx} "${un}" "$SYSDIR\d3d9.dll"
1066 ${CopyFileEx} "${un}" "$SYSDIR\msd3d9.dll" "$SYSDIR\d3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
1067
1068 ${If} $g_bCapDllCache == "true"
1069!if $%BUILD_TARGET_ARCH% == "x86"
1070 ${PrepareWRPFileEx} "${un}" "$SYSDIR\dllcache\d3d8.dll"
1071 ${CopyFileEx} "${un}" "$SYSDIR\dllcache\msd3d8.dll" "$SYSDIR\dllcache\d3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
1072!endif
1073 ${PrepareWRPFileEx} "${un}" "$SYSDIR\dllcache\d3d9.dll"
1074 ${CopyFileEx} "${un}" "$SYSDIR\dllcache\msd3d9.dll" "$SYSDIR\dllcache\d3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
1075 ${EndIf}
1076
1077!if $%BUILD_TARGET_ARCH% == "amd64"
1078 ${PrepareWRPFileEx} "${un}" "$g_strSysWow64\d3d8.dll"
1079 ${CopyFileEx} "${un}" "$g_strSysWow64\msd3d8.dll" "$g_strSysWow64\d3d8.dll" "Microsoft Corporation" "x86"
1080 ${PrepareWRPFileEx} "${un}" "$g_strSysWow64\d3d9.dll"
1081 ${CopyFileEx} "${un}" "$g_strSysWow64\msd3d9.dll" "$g_strSysWow64\d3d9.dll" "Microsoft Corporation" "x86"
1082
1083 ${If} $g_bCapDllCache == "true"
1084 ${PrepareWRPFileEx} "${un}" "$g_strSysWow64\dllcache\d3d8.dll"
1085 ${CopyFileEx} "${un}" "$g_strSysWow64\dllcache\msd3d8.dll" "$g_strSysWow64\dllcache\d3d8.dll" "Microsoft Corporation" "x86"
1086 ${PrepareWRPFileEx} "${un}" "$g_strSysWow64\dllcache\d3d9.dll"
1087 ${CopyFileEx} "${un}" "$g_strSysWow64\dllcache\msd3d9.dll" "$g_strSysWow64\dllcache\d3d9.dll" "Microsoft Corporation" "x86"
1088 ${EndIf}
1089!endif
1090
1091 ; Do a re-validation afterwards.
1092 Call ${un}ValidateD3DFiles
1093 Pop $0
1094 ${If} $0 == "1" ; D3D files are invalid
1095 ${LogVerbose} $(VBOX_UNINST_UNABLE_TO_RESTORE_D3D)
1096 MessageBox MB_ICONSTOP|MB_OK $(VBOX_UNINST_UNABLE_TO_RESTORE_D3D) /SD IDOK
1097 ${EndIf}
1098
1099 Exch $0
1100
1101FunctionEnd
1102!macroend
1103!insertmacro RestoreFilesDirect3D ""
1104!insertmacro RestoreFilesDirect3D "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