VirtualBox

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

Last change on this file since 98103 was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use