VirtualBox

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

Last change on this file since 106501 was 106321, checked in by vboxsync, 4 months ago

Windows installers: Big revamp for removing all DIFxApp-related / DIFxApi-related code and build dependencies for the host and guest installers. bugref:10762

This implements an own framework (VBoxWinDrvInst and VBoxWinDrvStore) for installing Windows drivers and querying / handling the Windows driver store,
along with testcases for the Windows guest and host installers.

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