VirtualBox

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

最後變更 在這個檔案從106844是 106844,由 vboxsync 提交於 5 月 前

Add/Nt/Installer: Some quick adjustments to make packing work when targeting win.arm64. jiraref:VBP-1253

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

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