VirtualBox

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

Last change on this file was 106964, checked in by vboxsync, 3 weeks ago

Windows Guest Additions installer: Got rid of RegCleanup.exe by embedding those two lines into VBoxGuestInstallHelper.exe. bugref:10799

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