VirtualBox

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

Last change on this file since 40866 was 40738, checked in by vboxsync, 13 years ago

Logging.

  • Property svn:eol-style set to native
File size: 25.9 KB
Line 
1; $Id$
2; @file
3; VBoxGuestAdditionsCommon.nsh - Common / shared utility functions.
4;
5
6;
7; Copyright (C) 2006-2012 Oracle Corporation
8;
9; This file is part of VirtualBox Open Source Edition (OSE), as
10; available from http://www.virtualbox.org. This file is free software;
11; you can redistribute it and/or modify it under the terms of the GNU
12; General Public License (GPL) as published by the Free Software
13; Foundation, in version 2 as it comes in the "COPYING" file of the
14; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16;
17
18Function Common_CopyFiles
19
20 SetOutPath "$INSTDIR"
21 SetOverwrite on
22
23!ifdef VBOX_WITH_LICENSE_INSTALL_RTF
24 ; Copy license file (if any) into the installation directory
25 FILE "/oname=${LICENSE_FILE_RTF}" "$%VBOX_BRAND_LICENSE_RTF%"
26!endif
27
28 FILE "$%VBOX_PATH_DIFX%\DIFxAPI.dll"
29 FILE "$%PATH_OUT%\bin\additions\VBoxDrvInst.exe"
30
31 FILE "$%PATH_OUT%\bin\additions\VBoxVideo.inf"
32!ifdef VBOX_SIGN_ADDITIONS
33 FILE "$%PATH_OUT%\bin\additions\VBoxVideo.cat"
34!endif
35
36 FILE "iexplore.ico"
37
38FunctionEnd
39
40!ifndef UNINSTALLER_ONLY
41Function ExtractFiles
42
43 ; @todo: Use a define for all the file specs to group the files per module
44 ; and keep the redundancy low
45
46 Push $0
47 StrCpy "$0" "$INSTDIR\$%BUILD_TARGET_ARCH%"
48
49 ; Root files
50 SetOutPath "$0"
51!if $%VBOX_WITH_LICENSE_INSTALL_RTF% == "1"
52 FILE "/oname=${LICENSE_FILE_RTF}" "$%VBOX_BRAND_LICENSE_RTF%"
53!endif
54
55 ; Video driver
56 SetOutPath "$0\VBoxVideo"
57 FILE "$%PATH_OUT%\bin\additions\VBoxVideo.sys"
58 FILE "$%PATH_OUT%\bin\additions\VBoxVideo.inf"
59!ifdef VBOX_SIGN_ADDITIONS
60 FILE "$%PATH_OUT%\bin\additions\VBoxVideo.cat"
61!endif
62 FILE "$%PATH_OUT%\bin\additions\VBoxDisp.dll"
63
64!if $%VBOX_WITH_CROGL% == "1"
65 ; crOpenGL
66 FILE "$%PATH_OUT%\bin\additions\VBoxOGLarrayspu.dll"
67 FILE "$%PATH_OUT%\bin\additions\VBoxOGLcrutil.dll"
68 FILE "$%PATH_OUT%\bin\additions\VBoxOGLerrorspu.dll"
69 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpackspu.dll"
70 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpassthroughspu.dll"
71 FILE "$%PATH_OUT%\bin\additions\VBoxOGLfeedbackspu.dll"
72 FILE "$%PATH_OUT%\bin\additions\VBoxOGL.dll"
73
74 SetOutPath "$0\VBoxVideo\OpenGL"
75 FILE "$%PATH_OUT%\bin\additions\d3d8.dll"
76 FILE "$%PATH_OUT%\bin\additions\d3d9.dll"
77 !if $%BUILD_TARGET_ARCH% == "x86"
78 ; libWine is used for 32bit d3d only
79 ; @todo: remove it for 32bit as well
80 FILE "$%PATH_OUT%\bin\additions\libWine.dll"
81 !endif
82 FILE "$%PATH_OUT%\bin\additions\VBoxD3D8.dll"
83 FILE "$%PATH_OUT%\bin\additions\VBoxD3D9.dll"
84 FILE "$%PATH_OUT%\bin\additions\wined3d.dll"
85
86 !if $%BUILD_TARGET_ARCH% == "amd64"
87 ; Only 64-bit installer: Also copy 32-bit DLLs on 64-bit target
88 SetOutPath "$0\VBoxVideo\OpenGL\SysWow64"
89 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d8.dll"
90 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d9.dll"
91 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\libWine.dll"
92 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxOGLarrayspu.dll"
93 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxOGLcrutil.dll"
94 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxOGLerrorspu.dll"
95 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxOGLpackspu.dll"
96 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxOGLpassthroughspu.dll"
97 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxOGLfeedbackspu.dll"
98 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxOGL.dll"
99 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxD3D8.dll"
100 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxD3D9.dll"
101 FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\wined3d.dll"
102 !endif
103!endif
104
105!if $%VBOX_WITH_WDDM% == "1"
106 ; WDDM Video driver
107 SetOutPath "$0\VBoxVideoWddm"
108
109 !ifdef VBOX_SIGN_ADDITIONS
110 FILE "$%PATH_OUT%\bin\additions\VBoxVideoWddm.cat"
111 !endif
112 FILE "$%PATH_OUT%\bin\additions\VBoxVideoWddm.sys"
113 FILE "$%PATH_OUT%\bin\additions\VBoxVideoWddm.inf"
114 FILE "$%PATH_OUT%\bin\additions\VBoxDispD3D.dll"
115
116 !if $%VBOX_WITH_CROGL% == "1"
117 FILE "$%PATH_OUT%\bin\additions\VBoxOGLarrayspu.dll"
118 FILE "$%PATH_OUT%\bin\additions\VBoxOGLcrutil.dll"
119 FILE "$%PATH_OUT%\bin\additions\VBoxOGLerrorspu.dll"
120 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpackspu.dll"
121 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpassthroughspu.dll"
122 FILE "$%PATH_OUT%\bin\additions\VBoxOGLfeedbackspu.dll"
123 FILE "$%PATH_OUT%\bin\additions\VBoxOGL.dll"
124
125 FILE "$%PATH_OUT%\bin\additions\VBoxD3D9wddm.dll"
126 FILE "$%PATH_OUT%\bin\additions\wined3dwddm.dll"
127 !endif ; $%VBOX_WITH_CROGL% == "1"
128
129 !if $%BUILD_TARGET_ARCH% == "amd64"
130 FILE "$%PATH_OUT%\bin\additions\VBoxDispD3D-x86.dll"
131
132 !if $%VBOX_WITH_CROGL% == "1"
133 FILE "$%PATH_OUT%\bin\additions\VBoxOGLarrayspu-x86.dll"
134 FILE "$%PATH_OUT%\bin\additions\VBoxOGLcrutil-x86.dll"
135 FILE "$%PATH_OUT%\bin\additions\VBoxOGLerrorspu-x86.dll"
136 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpackspu-x86.dll"
137 FILE "$%PATH_OUT%\bin\additions\VBoxOGLpassthroughspu-x86.dll"
138 FILE "$%PATH_OUT%\bin\additions\VBoxOGLfeedbackspu-x86.dll"
139 FILE "$%PATH_OUT%\bin\additions\VBoxOGL-x86.dll"
140
141 FILE "$%PATH_OUT%\bin\additions\VBoxD3D9wddm-x86.dll"
142 FILE "$%PATH_OUT%\bin\additions\wined3dwddm-x86.dll"
143 !endif ; $%VBOX_WITH_CROGL% == "1"
144 !endif ; $%BUILD_TARGET_ARCH% == "amd64"
145!endif ; $%VBOX_WITH_WDDM% == "1"
146
147 ; Mouse driver
148 SetOutPath "$0\VBoxMouse"
149 FILE "$%PATH_OUT%\bin\additions\VBoxMouse.sys"
150 FILE "$%PATH_OUT%\bin\additions\VBoxMouse.inf"
151!ifdef VBOX_SIGN_ADDITIONS
152 FILE "$%PATH_OUT%\bin\additions\VBoxMouse.cat"
153!endif
154
155!if $%BUILD_TARGET_ARCH% == "x86"
156 SetOutPath "$0\VBoxMouse\NT4"
157 FILE "$%PATH_OUT%\bin\additions\VBoxMouseNT.sys"
158!endif
159
160 ; Guest driver
161 SetOutPath "$0\VBoxGuest"
162 FILE "$%PATH_OUT%\bin\additions\VBoxGuest.sys"
163 FILE "$%PATH_OUT%\bin\additions\VBoxGuest.inf"
164!ifdef VBOX_SIGN_ADDITIONS
165 FILE "$%PATH_OUT%\bin\additions\VBoxGuest.cat"
166!endif
167 FILE "$%PATH_OUT%\bin\additions\VBoxTray.exe"
168 FILE "$%PATH_OUT%\bin\additions\VBoxHook.dll"
169 FILE "$%PATH_OUT%\bin\additions\VBoxControl.exe"
170
171!if $%BUILD_TARGET_ARCH% == "x86"
172 SetOutPath "$0\VBoxGuest\NT4"
173 FILE "$%PATH_OUT%\bin\additions\VBoxGuestNT.sys"
174!endif
175
176 ; VBoxService
177 SetOutPath "$0\Bin"
178 FILE "$%PATH_OUT%\bin\additions\VBoxService.exe"
179!if $%BUILD_TARGET_ARCH% == "x86"
180 FILE "$%PATH_OUT%\bin\additions\VBoxServiceNT.exe"
181!endif
182
183 ; Shared Folders
184 SetOutPath "$0\VBoxSF"
185 FILE "$%PATH_OUT%\bin\additions\VBoxSF.sys"
186 FILE "$%PATH_OUT%\bin\additions\VBoxMRXNP.dll"
187 !if $%BUILD_TARGET_ARCH% == "amd64"
188 ; Only 64-bit installer: Also copy 32-bit DLLs on 64-bit target
189 FILE "$%PATH_OUT%\bin\additions\VBoxMRXNP-x86.dll"
190 !endif
191
192 ; Auto-Logon
193 SetOutPath "$0\AutoLogon"
194 FILE "$%PATH_OUT%\bin\additions\VBoxGINA.dll"
195 FILE "$%PATH_OUT%\bin\additions\VBoxCredProv.dll"
196
197 ; Misc tools
198 SetOutPath "$0\Tools"
199 FILE "$%PATH_OUT%\bin\additions\VBoxDrvInst.exe"
200 FILE "$%VBOX_PATH_DIFX%\DIFxAPI.dll"
201
202!if $%BUILD_TARGET_ARCH% == "x86"
203 SetOutPath "$0\Tools\NT4"
204 FILE "$%PATH_OUT%\bin\additions\VBoxGuestDrvInst.exe"
205 FILE "$%PATH_OUT%\bin\additions\RegCleanup.exe"
206!endif
207
208 Pop $0
209
210FunctionEnd
211!endif ; UNINSTALLER_ONLY
212
213!macro EnableLog un
214Function ${un}EnableLog
215
216!ifdef _DEBUG
217 Goto log
218!endif
219
220 StrCmp $g_bLogEnable "true" log
221 Goto exit
222
223log:
224
225 LogSet on
226 LogText "Start logging."
227
228exit:
229
230FunctionEnd
231!macroend
232!insertmacro EnableLog ""
233!insertmacro EnableLog "un."
234
235!macro WriteLogUI un
236Function ${un}WriteLogUI
237
238 IfSilent exit
239
240!ifdef _DEBUG
241 Goto log
242!endif
243
244 StrCmp $g_bLogEnable "true" log
245 Goto exit
246
247log:
248
249 ; Dump log to see what happened
250 StrCpy $0 "$INSTDIR\${un}install_ui.log"
251 Push $0
252 Call ${un}DumpLog
253
254exit:
255
256FunctionEnd
257!macroend
258!insertmacro WriteLogUI ""
259!insertmacro WriteLogUI "un."
260
261!macro WriteLogVBoxTray un
262Function ${un}WriteLogVBoxTray
263
264 ; Pop function parameters off the stack
265 ; in reverse order
266 Exch $1 ; Message type (0=Info, 1=Warning, 2=Error)
267 Exch
268 Exch $0 ; Body string
269
270 ; @todo Add more paramters here!
271!if $%VBOX_WITH_GUEST_INSTALL_HELPER% == "1"
272 ${If} $g_bPostInstallStatus == "true"
273 ; Parameters:
274 ; - String: Description / Body
275 ; - String: Title / Name of application
276 ; - Integer: Type of message: 0 (Info), 1 (Warning), 2 (Error)
277 ; - Integer: Time (in msec) to show the notification
278 VBoxGuestInstallHelper::VBoxTrayShowBallonMsg "$0" "VirtualBox Guest Additions Setup" $1 5000
279 Pop $0 ; Get return value (ignored for now)
280 ${EndIf}
281!endif
282 Pop $0
283 Pop $1
284
285FunctionEnd
286!macroend
287!insertmacro WriteLogVBoxTray ""
288!insertmacro WriteLogVBoxTray "un."
289
290!macro CheckArchitecture un
291Function ${un}CheckArchitecture
292
293 Push $0
294
295 System::Call "kernel32::GetCurrentProcess() i .s"
296 System::Call "kernel32::IsWow64Process(i s, *i .r0)"
297 ; R0 now contains 1 if we're a 64-bit process, or 0 if not
298
299!if $%BUILD_TARGET_ARCH% == "amd64"
300 IntCmp $0 0 wrong_platform
301!else ; 32-bit
302 IntCmp $0 1 wrong_platform
303!endif
304
305 Push 0
306 Goto exit
307
308wrong_platform:
309
310 Push 1
311 Goto exit
312
313exit:
314
315FunctionEnd
316!macroend
317!insertmacro CheckArchitecture ""
318!insertmacro CheckArchitecture "un."
319
320!macro GetWindowsVer un
321Function ${un}GetWindowsVer
322
323 ; Check if we are running on w2k or above
324 ; For other windows versions (>XP) it may be necessary to change winver.nsh
325 Call ${un}GetWindowsVersion
326 Pop $R3 ; Windows Version
327
328 Push $R3 ; The windows version string
329 Push "NT" ; String to search for. Win 2k family returns no string containing 'NT'
330 Call ${un}StrStr
331 Pop $R0
332 StrCmp $R0 '' nt5plus ; Not NT 3.XX or 4.XX
333
334 ; Ok we know it is NT. Must be a string like NT X.XX
335 Push $R3 ; The windows version string
336 Push "4." ; String to search for
337 Call ${un}StrStr
338 Pop $R0
339 StrCmp $R0 "" nt5plus nt4 ; If empty -> not NT 4
340
341nt5plus: ; Windows 2000+ (XP, Vista, ...)
342
343 StrCpy $g_strWinVersion $R3
344 goto exit
345
346nt4: ; NT 4.0
347
348 StrCpy $g_strWinVersion "NT4"
349 goto exit
350
351exit:
352
353FunctionEnd
354!macroend
355!insertmacro GetWindowsVer ""
356!insertmacro GetWindowsVer "un."
357
358!macro GetAdditionsVersion un
359Function ${un}GetAdditionsVersion
360
361 Push $0
362 Push $1
363
364 ; Get additions version
365 ReadRegStr $0 HKLM "SOFTWARE\$%VBOX_VENDOR_SHORT%\VirtualBox Guest Additions" "Version"
366
367 ; Get revision
368 ReadRegStr $g_strAddVerRev HKLM "SOFTWARE\$%VBOX_VENDOR_SHORT%\VirtualBox Guest Additions" "Revision"
369
370 ; Extract major version
371 Push "$0" ; String
372 Push "." ; SubString
373 Push ">" ; SearchDirection
374 Push "<" ; StrInclusionDirection
375 Push "0" ; IncludeSubString
376 Push "0" ; Loops
377 Push "0" ; CaseSensitive
378 Call ${un}StrStrAdv
379 Pop $g_strAddVerMaj
380
381 ; Extract minor version
382 Push "$0" ; String
383 Push "." ; SubString
384 Push ">" ; SearchDirection
385 Push ">" ; StrInclusionDirection
386 Push "0" ; IncludeSubString
387 Push "0" ; Loops
388 Push "0" ; CaseSensitive
389 Call ${un}StrStrAdv
390 Pop $1 ; Got first part (e.g. "1.5")
391
392 Push "$1" ; String
393 Push "." ; SubString
394 Push ">" ; SearchDirection
395 Push "<" ; StrInclusionDirection
396 Push "0" ; IncludeSubString
397 Push "0" ; Loops
398 Push "0" ; CaseSensitive
399 Call ${un}StrStrAdv
400 Pop $g_strAddVerMin ; Extracted second part (e.g. "5" from "1.5")
401
402 ; Extract build number
403 Push "$0" ; String
404 Push "." ; SubString
405 Push "<" ; SearchDirection
406 Push ">" ; StrInclusionDirection
407 Push "0" ; IncludeSubString
408 Push "0" ; Loops
409 Push "0" ; CaseSensitive
410 Call ${un}StrStrAdv
411 Pop $g_strAddVerBuild
412
413exit:
414
415 Pop $1
416 Pop $0
417
418FunctionEnd
419!macroend
420!insertmacro GetAdditionsVersion ""
421!insertmacro GetAdditionsVersion "un."
422
423!macro StopVBoxService un
424Function ${un}StopVBoxService
425
426 Push $0 ; Temp results
427 Push $1
428 Push $2 ; Image name of VBoxService
429 Push $3 ; Safety counter
430
431 StrCpy $3 "0" ; Init counter
432 DetailPrint "Stopping VBoxService ..."
433
434svc_stop:
435
436 LogText "Stopping VBoxService (as service) ..."
437 ${If} $g_strWinVersion == "NT4"
438 nsExec::Exec '"$SYSDIR\net.exe" stop VBoxService'
439 ${Else}
440 nsExec::Exec '"$SYSDIR\SC.exe" stop VBoxService'
441 ${EndIf}
442 Sleep "1000" ; Wait a bit
443
444exe_stop:
445
446!ifdef _DEBUG
447 DetailPrint "Stopping VBoxService (as exe) ..."
448!endif
449
450exe_stop_loop:
451
452 IntCmp $3 10 exit ; Only try this loop 10 times max
453 IntOp $3 $3 + 1 ; Increment
454
455 LogText "Try: $3"
456
457 ${If} $g_strWinVersion == "NT4"
458 StrCpy $2 "VBoxServiceNT.exe"
459 ${Else}
460 StrCpy $2 "VBoxService.exe"
461 ${EndIf}
462
463 ${nsProcess::FindProcess} $2 $0
464 StrCmp $0 0 0 exit
465
466 ${nsProcess::KillProcess} $2 $0
467 Sleep "1000" ; Wait a bit
468 Goto exe_stop_loop
469
470exit:
471
472 DetailPrint "Stopping VBoxService done."
473
474 Pop $3
475 Pop $2
476 Pop $1
477 Pop $0
478
479FunctionEnd
480!macroend
481!insertmacro StopVBoxService ""
482!insertmacro StopVBoxService "un."
483
484!macro StopVBoxTray un
485Function ${un}StopVBoxTray
486
487 Push $0 ; Temp results
488 Push $1 ; Safety counter
489
490 StrCpy $1 "0" ; Init counter
491 DetailPrint "Stopping VBoxTray ..."
492
493exe_stop:
494
495 IntCmp $1 10 exit ; Only try this loop 10 times max
496 IntOp $1 $1 + 1 ; Increment
497
498 ${nsProcess::FindProcess} "VBoxTray.exe" $0
499 StrCmp $0 0 0 exit
500
501 ${nsProcess::KillProcess} "VBoxTray.exe" $0
502 Sleep "1000" ; Wait a bit
503 Goto exe_stop
504
505exit:
506
507 DetailPrint "Stopping VBoxTray done."
508
509 Pop $1
510 Pop $0
511
512FunctionEnd
513!macroend
514!insertmacro StopVBoxTray ""
515!insertmacro StopVBoxTray "un."
516
517!macro WriteRegBinR ROOT KEY NAME VALUE
518 WriteRegBin "${ROOT}" "${KEY}" "${NAME}" "${VALUE}"
519!macroend
520
521!macro AbortShutdown un
522Function ${un}AbortShutdown
523
524 Push $0
525
526 ; Try to abort the shutdown
527 nsExec::ExecToLog '"$g_strSystemDir\shutdown.exe" -a' $0
528
529 Pop $0
530
531FunctionEnd
532!macroend
533!insertmacro AbortShutdown ""
534!insertmacro AbortShutdown "un."
535
536!macro CheckForWDDMCapability un
537Function ${un}CheckForWDDMCapability
538
539!if $%VBOX_WITH_WDDM% == "1"
540 ; If we're on a 32-bit Windows Vista / 7 / 8 we can use the WDDM driver
541 ${If} $g_strWinVersion == "Vista"
542 ${OrIf} $g_strWinVersion == "7"
543 ${OrIf} $g_strWinVersion == "8"
544 StrCpy $g_bCapWDDM "true"
545 ${EndIf}
546 ; If we're on Windows 8 we *have* to use the WDDM driver, so select it
547 ; by default
548 ${If} $g_strWinVersion == "8"
549 StrCpy $g_bWithWDDM "true"
550 ${EndIf}
551!endif
552
553FunctionEnd
554!macroend
555!insertmacro CheckForWDDMCapability ""
556!insertmacro CheckForWDDMCapability "un."
557
558!macro CheckForCapabilities un
559Function ${un}CheckForCapabilities
560
561 Push $0
562
563 ; Retrieve system mode and store result in
564 System::Call 'user32::GetSystemMetrics(i ${SM_CLEANBOOT}) i .r0'
565 StrCpy $g_iSystemMode $0
566
567 ; Does the guest have a DLL cache?
568 ${If} $g_strWinVersion == "Vista"
569 ${OrIf} $g_strWinVersion == "7"
570 ${OrIf} $g_strWinVersion == "8"
571 StrCpy $g_bCapDllCache "true"
572 ${EndIf}
573
574 ; Check whether this OS is capable of handling WDDM drivers
575 Call ${un}CheckForWDDMCapability
576
577 Pop $0
578
579FunctionEnd
580!macroend
581!insertmacro CheckForCapabilities ""
582!insertmacro CheckForCapabilities "un."
583
584; Switches (back) the path + registry view to
585; 32-bit mode (SysWOW64) on 64-bit guests
586!macro SetAppMode32 un
587Function ${un}SetAppMode32
588 !if $%BUILD_TARGET_ARCH% == "amd64"
589 ${EnableX64FSRedirection}
590 SetRegView 32
591 !endif
592FunctionEnd
593!macroend
594!insertmacro SetAppMode32 ""
595!insertmacro SetAppMode32 "un."
596
597; Because this NSIS installer is always built in 32-bit mode, we have to
598; do some tricks for the Windows paths + registry on 64-bit guests
599!macro SetAppMode64 un
600Function ${un}SetAppMode64
601 !if $%BUILD_TARGET_ARCH% == "amd64"
602 ${DisableX64FSRedirection}
603 SetRegView 64
604 !endif
605FunctionEnd
606!macroend
607!insertmacro SetAppMode64 ""
608!insertmacro SetAppMode64 "un."
609
610;
611; Retrieves the vendor ("CompanyName" of FILEINFO structure)
612; of a given file.
613; @return Stack: Company name, or "" on error/if not found.
614; @param Stack: File name to retrieve vendor for.
615;
616!macro GetFileVendor un
617Function ${un}GetFileVendor
618
619 ; Preserve values
620 Exch $0 ; Stack: $0 <filename> (Get file name into $0)
621 Push $1
622
623 IfFileExists "$0" found
624 Goto not_found
625
626found:
627
628 VBoxGuestInstallHelper::FileGetVendor "$0"
629 ; Stack: <vendor> $1 $0
630 Pop $0 ; Get vendor
631 Pop $1 ; Restore $1
632 Exch $0 ; Restore $0, push vendor on top of stack
633 Goto end
634
635not_found:
636
637 Pop $1
638 Pop $0
639 Push "File not found"
640 Goto end
641
642end:
643
644FunctionEnd
645!macroend
646!insertmacro GetFileVendor ""
647!insertmacro GetFileVendor "un."
648
649;
650; Retrieves the architecture of a given file.
651; @return Stack: Architecture ("x86", "amd64") or error message.
652; @param Stack: File name to retrieve architecture for.
653;
654!macro GetFileArchitecture un
655Function ${un}GetFileArchitecture
656
657 ; Preserve values
658 Exch $0 ; Stack: $0 <filename> (Get file name into $0)
659 Push $1
660
661 IfFileExists "$0" found
662 Goto not_found
663
664found:
665
666 VBoxGuestInstallHelper::FileGetArchitecture "$0"
667 ; Stack: <architecture> $1 $0
668 Pop $0 ; Get architecture string
669 Pop $1 ; Restore $1
670 Exch $0 ; Restore $0, push vendor on top of stack
671 Goto end
672
673not_found:
674
675 Pop $1
676 Pop $0
677 Push "File not found"
678 Goto end
679
680end:
681
682FunctionEnd
683!macroend
684!insertmacro GetFileArchitecture ""
685!insertmacro GetFileArchitecture "un."
686
687;
688; Verifies a given file by checking its file vendor and target
689; architecture.
690; @return Stack: "0" if valid, "1" if not, "2" on error / not found.
691; @param Stack: Architecture ("x86" or "amd64").
692; @param Stack: Vendor.
693; @param Stack: File name to verify.
694;
695!macro VerifyFile un
696Function ${un}VerifyFile
697
698 ; Preserve values
699 Exch $0 ; File; S: old$0 vendor arch
700 Exch ; S: vendor old$0 arch
701 Exch $1 ; Vendor; S: old$1 old$0 arch
702 Exch ; S: old$0 old$1 arch
703 Exch 2 ; S: arch old$1 old$0
704 Exch $2 ; Architecture; S: old$2 old$1 old$0
705 Push $3 ; S: old$3 old$2 old$1 old$0
706
707 IfFileExists "$0" check_vendor
708 Goto not_found
709
710check_vendor:
711
712 Push $0
713 Call ${un}GetFileVendor
714 Pop $3
715
716 ${If} $3 == $1
717 Goto check_arch
718 ${EndIf}
719 StrCpy $3 "1" ; Invalid
720 Goto end
721
722check_arch:
723
724 Push $0
725 Call ${un}GetFileArchitecture
726 Pop $3
727
728 ${If} $3 == $2
729 StrCpy $3 "0" ; Valid
730 ${Else}
731 StrCpy $3 "1" ; Invalid
732 ${EndIf}
733 Goto end
734
735not_found:
736
737 StrCpy $3 "2" ; Not found
738 Goto end
739
740end:
741
742 ; S: old$3 old$2 old$1 old$0
743 Exch $3 ; S: $3 old$2 old$1 old$0
744 Exch ; S: old$2 $3 old$1
745 Pop $2 ; S: $3 old$1 old$0
746 Exch ; S: old$1 $3 old$0
747 Pop $1 ; S: $3 old$0
748 Exch ; S: old$0 $3
749 Pop $0 ; S: $3
750
751FunctionEnd
752!macroend
753!insertmacro VerifyFile ""
754!insertmacro VerifyFile "un."
755
756;
757; Macro for accessing VerifyFile in a more convenient way by using
758; a parameter list.
759; @return Stack: "0" if valid, "1" if not, "2" on error / not found.
760; @param Un/Installer prefix; either "" or "un".
761; @param Name of file to verify.
762; @param Vendor to check for.
763; @param Architecture ("x86" or "amd64") to check for.
764;
765!macro VerifyFileEx un File Vendor Architecture
766 Push $0
767 Push "${Architecture}"
768 Push "${Vendor}"
769 Push "${File}"
770 DetailPrint "Verifying file $\"${File}$\" ..."
771 Call ${un}VerifyFile
772 Pop $0
773 ${If} $0 == "0"
774 DetailPrint "Verification of file $\"${File}$\" successful (Vendor: ${Vendor}, Architecture: ${Architecture})"
775 ${ElseIf} $0 == "1"
776 DetailPrint "Verification of file $\"${File}$\" failed (not Vendor: ${Vendor}, and/or not Architecture: ${Architecture})"
777 ${Else}
778 DetailPrint "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 ${If} $0 == "0"
803 DetailPrint "Copying verified file $\"${FileSrc}$\" to $\"${FileDest}$\" ..."
804 CopyFiles /SILENT "${FileSrc}" "${FileDest}"
805 ${Else}
806 DetailPrint "Skipping to copy file $\"${FileSrc}$\" to $\"${FileDest}$\" (not Vendor: ${Vendor}, Architecture: ${Architecture})"
807 ${EndIf}
808 ; Push result popped off the stack to stack again
809 Push $0
810!macroend
811!define CopyFileEx "!insertmacro CopyFileEx"
812
813;
814; Macro for installing a library/DLL.
815; @return Stack: "0" if copied, "1" if not, "2" on error / not found.
816; @param Un/Installer prefix; either "" or "un".
817; @param Name of lib/DLL to verify and copy to destination.
818; @param Destination name to copy verified file to.
819; @param Temporary folder used for exchanging the (locked) lib/DLL after a reboot.
820;
821!macro InstallFileEx un FileSrc FileDest DirTemp
822 DetailPrint "Installing library $\"${FileSrc}$\" to $\"${FileDest}$\" ..."
823 ; Try the gentle way and replace the file instantly
824 !insertmacro InstallLib DLL NOTSHARED NOREBOOT_NOTPROTECTED "${FileSrc}" "${FileDest}" "${DirTemp}"
825 ; If the above call didn't help, use a (later) reboot to replace the file
826 !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "${FileSrc}" "${FileDest}" "${DirTemp}"
827!macroend
828!define InstallFileEx "!insertmacro InstallFileEx"
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 verify and copy to destination.
835; @param Destination name to copy verified file to.
836; @param Temporary folder used for exchanging the (locked) lib/DLL after a reboot.
837; @param Vendor to check for.
838; @param Architecture ("x86" or "amd64") to check for.
839;
840!macro InstallFileVerify un FileSrc FileDest DirTemp Vendor Architecture
841 Push $0
842 Push "${Architecture}"
843 Push "${Vendor}"
844 Push "${FileSrc}"
845 DetailPrint "Verifying library $\"${FileSrc}$\" ..."
846 Call ${un}VerifyFile
847 Pop $0
848 ${If} $0 == "0"
849 ${InstallFileEx} ${un} ${FileSrc} ${FileDest} ${DirTemp}
850 ${Else}
851 DetailPrint "File $\"${FileSrc}$\" did not pass verification (Vendor: ${Vendor}, Architecture: ${Architecture})"
852 ${EndIf}
853 ; Push result popped off the stack to stack again.
854 Push $0
855!macroend
856!define InstallFileVerify "!insertmacro InstallFileVerify"
857
858;
859; Validates backed up and replaced Direct3D files; either the d3d*.dll have
860; to be from Microsoft or the (already) backed up msd3d*.dll files. If both
861; don't match we have a corrupted / invalid installation.
862; @return Stack: "0" if files are valid; otherwise "1".
863;
864!macro ValidateFilesDirect3D un
865Function ${un}ValidateD3DFiles
866
867 Push $0
868
869 ; We need to switch to 64-bit app mode to handle the "real" 64-bit files in
870 ; ""system32" on a 64-bit guest
871 Call ${un}SetAppMode64
872
873 ; Note: Not finding a file (like *d3d8.dll) on Windows Vista/7 is fine;
874 ; it simply is not present there.
875
876 ; Note 2: On 64-bit systems there are no 64-bit *d3d8 DLLs, only 32-bit ones
877 ; in SysWOW64 (or in system32 on 32-bit systems).
878
879!if $%BUILD_TARGET_ARCH% == "x86"
880 ${VerifyFileEx} "${un}" "$SYSDIR\d3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
881 Pop $0
882 ${If} $0 == "1"
883 Goto verify_msd3d
884 ${EndIf}
885!endif
886
887 ${VerifyFileEx} "${un}" "$SYSDIR\d3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
888 Pop $0
889 ${If} $0 == "1"
890 Goto verify_msd3d
891 ${EndIf}
892
893 ${If} $g_bCapDllCache == "true"
894!if $%BUILD_TARGET_ARCH% == "x86"
895 ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\d3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
896 Pop $0
897 ${If} $0 == "1"
898 Goto verify_msd3d
899 ${EndIf}
900!endif
901 ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\d3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
902 Pop $0
903 ${If} $0 == "1"
904 Goto verify_msd3d
905 ${EndIf}
906 ${EndIf}
907
908!if $%BUILD_TARGET_ARCH% == "amd64"
909 ${VerifyFileEx} "${un}" "$g_strSysWow64\d3d8.dll" "Microsoft Corporation" "x86"
910 Pop $0
911 ${If} $0 == "1"
912 Goto verify_msd3d
913 ${EndIf}
914 ${VerifyFileEx} "${un}" "$g_strSysWow64\d3d9.dll" "Microsoft Corporation" "x86"
915 Pop $0
916 ${If} $0 == "1"
917 Goto verify_msd3d
918 ${EndIf}
919
920 ${If} $g_bCapDllCache == "true"
921 ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\d3d8.dll" "Microsoft Corporation" "x86"
922 Pop $0
923 ${If} $0 == "1"
924 Goto verify_msd3d
925 ${EndIf}
926 ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\d3d9.dll" "Microsoft Corporation" "x86"
927 Pop $0
928 ${If} $0 == "1"
929 Goto verify_msd3d
930 ${EndIf}
931 ${EndIf}
932
933!endif
934
935 Goto valid
936
937verify_msd3d:
938
939!if $%BUILD_TARGET_ARCH% == "x86"
940 ${VerifyFileEx} "${un}" "$SYSDIR\msd3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
941 Pop $0
942 ${If} $0 == "1"
943 Goto invalid
944 ${EndIf}
945!endif
946 ${VerifyFileEx} "${un}" "$SYSDIR\msd3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
947 Pop $0
948 ${If} $0 == "1"
949 Goto invalid
950 ${EndIf}
951
952 ${If} $g_bCapDllCache == "true"
953!if $%BUILD_TARGET_ARCH% == "x86"
954 ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\msd3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
955 Pop $0
956 ${If} $0 == "1"
957 Goto invalid
958 ${EndIf}
959!endif
960 ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\msd3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
961 Pop $0
962 ${If} $0 == "1"
963 Goto invalid
964 ${EndIf}
965 ${EndIf}
966
967!if $%BUILD_TARGET_ARCH% == "amd64"
968 ${VerifyFileEx} "${un}" "$g_strSysWow64\msd3d8.dll" "Microsoft Corporation" "x86"
969 Pop $0
970 ${If} $0 == "1"
971 Goto invalid
972 ${EndIf}
973 ${VerifyFileEx} "${un}" "$g_strSysWow64\msd3d9.dll" "Microsoft Corporation" "x86"
974 Pop $0
975 ${If} $0 == "1"
976 Goto invalid
977 ${EndIf}
978
979 ${If} $g_bCapDllCache == "true"
980 ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\msd3d8.dll" "Microsoft Corporation" "x86"
981 Pop $0
982 ${If} $0 == "1"
983 Goto invalid
984 ${EndIf}
985 ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\msd3d9.dll" "Microsoft Corporation" "x86"
986 Pop $0
987 ${If} $0 == "1"
988 Goto invalid
989 ${EndIf}
990 ${EndIf}
991!endif
992
993 Goto valid
994
995valid:
996
997 StrCpy $0 "0" ; Installation valid
998 Goto end
999
1000invalid:
1001
1002 StrCpy $0 "1" ; Installation invalid / corrupted
1003 Goto end
1004
1005end:
1006
1007 Exch $0
1008
1009FunctionEnd
1010!macroend
1011!insertmacro ValidateFilesDirect3D ""
1012!insertmacro ValidateFilesDirect3D "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