VirtualBox

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

Last change on this file since 107381 was 107234, checked in by vboxsync, 2 months ago

Windows Guest Additions installer: Skip installing VBoxDrvInst.exe on NT4 guests (not supported there). bugref:10762

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