VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/SystemPropertiesImpl.cpp@ 77744

Last change on this file since 77744 was 76592, checked in by vboxsync, 6 years ago

Main: Don't use Logging.h.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.6 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 76592 2019-01-01 20:13:07Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2019 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
18#define LOG_GROUP LOG_GROUP_MAIN_SYSTEMPROPERTIES
19#include "SystemPropertiesImpl.h"
20#include "VirtualBoxImpl.h"
21#include "MachineImpl.h"
22#ifdef VBOX_WITH_EXTPACK
23# include "ExtPackManagerImpl.h"
24#endif
25#include "AutoCaller.h"
26#include "Global.h"
27#include "LoggingNew.h"
28#include "AutostartDb.h"
29
30// generated header
31#include "SchemaDefs.h"
32
33#include <iprt/dir.h>
34#include <iprt/ldr.h>
35#include <iprt/path.h>
36#include <iprt/string.h>
37#include <iprt/uri.h>
38#include <iprt/cpp/utils.h>
39
40#include <iprt/errcore.h>
41#include <VBox/param.h>
42#include <VBox/settings.h>
43#include <VBox/vd.h>
44
45// defines
46/////////////////////////////////////////////////////////////////////////////
47
48// constructor / destructor
49/////////////////////////////////////////////////////////////////////////////
50
51SystemProperties::SystemProperties()
52 : mParent(NULL),
53 m(new settings::SystemProperties)
54{
55}
56
57SystemProperties::~SystemProperties()
58{
59 delete m;
60}
61
62
63HRESULT SystemProperties::FinalConstruct()
64{
65 return BaseFinalConstruct();
66}
67
68void SystemProperties::FinalRelease()
69{
70 uninit();
71 BaseFinalRelease();
72}
73
74// public methods only for internal purposes
75/////////////////////////////////////////////////////////////////////////////
76
77/**
78 * Initializes the system information object.
79 *
80 * @returns COM result indicator
81 */
82HRESULT SystemProperties::init(VirtualBox *aParent)
83{
84 LogFlowThisFunc(("aParent=%p\n", aParent));
85
86 ComAssertRet(aParent, E_FAIL);
87
88 /* Enclose the state transition NotReady->InInit->Ready */
89 AutoInitSpan autoInitSpan(this);
90 AssertReturn(autoInitSpan.isOk(), E_FAIL);
91
92 unconst(mParent) = aParent;
93
94 i_setDefaultMachineFolder(Utf8Str::Empty);
95 i_setLoggingLevel(Utf8Str::Empty);
96 i_setDefaultHardDiskFormat(Utf8Str::Empty);
97
98 i_setVRDEAuthLibrary(Utf8Str::Empty);
99 i_setDefaultVRDEExtPack(Utf8Str::Empty);
100
101 m->uLogHistoryCount = 3;
102
103
104 /* On Windows, OS X and Solaris, HW virtualization use isn't exclusive
105 * by default so that VT-x or AMD-V can be shared with other
106 * hypervisors without requiring user intervention.
107 * NB: See also SystemProperties constructor in settings.h
108 */
109#if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS)
110 m->fExclusiveHwVirt = false;
111#else
112 m->fExclusiveHwVirt = true;
113#endif
114
115 HRESULT rc = S_OK;
116
117 /* Fetch info of all available hd backends. */
118
119 /// @todo NEWMEDIA VDBackendInfo needs to be improved to let us enumerate
120 /// any number of backends
121
122 VDBACKENDINFO aVDInfo[100];
123 unsigned cEntries;
124 int vrc = VDBackendInfo(RT_ELEMENTS(aVDInfo), aVDInfo, &cEntries);
125 AssertRC(vrc);
126 if (RT_SUCCESS(vrc))
127 {
128 for (unsigned i = 0; i < cEntries; ++ i)
129 {
130 ComObjPtr<MediumFormat> hdf;
131 rc = hdf.createObject();
132 if (FAILED(rc)) break;
133
134 rc = hdf->init(&aVDInfo[i]);
135 if (FAILED(rc)) break;
136
137 m_llMediumFormats.push_back(hdf);
138 }
139 }
140
141 /* Confirm a successful initialization */
142 if (SUCCEEDED(rc))
143 autoInitSpan.setSucceeded();
144
145 return rc;
146}
147
148/**
149 * Uninitializes the instance and sets the ready flag to FALSE.
150 * Called either from FinalRelease() or by the parent when it gets destroyed.
151 */
152void SystemProperties::uninit()
153{
154 LogFlowThisFunc(("\n"));
155
156 /* Enclose the state transition Ready->InUninit->NotReady */
157 AutoUninitSpan autoUninitSpan(this);
158 if (autoUninitSpan.uninitDone())
159 return;
160
161 unconst(mParent) = NULL;
162}
163
164// wrapped ISystemProperties properties
165/////////////////////////////////////////////////////////////////////////////
166
167HRESULT SystemProperties::getMinGuestRAM(ULONG *minRAM)
168
169{
170 /* no need to lock, this is const */
171 AssertCompile(MM_RAM_MIN_IN_MB >= SchemaDefs::MinGuestRAM);
172 *minRAM = MM_RAM_MIN_IN_MB;
173
174 return S_OK;
175}
176
177HRESULT SystemProperties::getMaxGuestRAM(ULONG *maxRAM)
178{
179 /* no need to lock, this is const */
180 AssertCompile(MM_RAM_MAX_IN_MB <= SchemaDefs::MaxGuestRAM);
181 ULONG maxRAMSys = MM_RAM_MAX_IN_MB;
182 ULONG maxRAMArch = maxRAMSys;
183 *maxRAM = RT_MIN(maxRAMSys, maxRAMArch);
184
185 return S_OK;
186}
187
188HRESULT SystemProperties::getMinGuestVRAM(ULONG *minVRAM)
189{
190 /* no need to lock, this is const */
191 *minVRAM = SchemaDefs::MinGuestVRAM;
192
193 return S_OK;
194}
195
196HRESULT SystemProperties::getMaxGuestVRAM(ULONG *maxVRAM)
197{
198 /* no need to lock, this is const */
199 *maxVRAM = SchemaDefs::MaxGuestVRAM;
200
201 return S_OK;
202}
203
204HRESULT SystemProperties::getMinGuestCPUCount(ULONG *minCPUCount)
205{
206 /* no need to lock, this is const */
207 *minCPUCount = SchemaDefs::MinCPUCount; // VMM_MIN_CPU_COUNT
208
209 return S_OK;
210}
211
212HRESULT SystemProperties::getMaxGuestCPUCount(ULONG *maxCPUCount)
213{
214 /* no need to lock, this is const */
215 *maxCPUCount = SchemaDefs::MaxCPUCount; // VMM_MAX_CPU_COUNT
216
217 return S_OK;
218}
219
220HRESULT SystemProperties::getMaxGuestMonitors(ULONG *maxMonitors)
221{
222
223 /* no need to lock, this is const */
224 *maxMonitors = SchemaDefs::MaxGuestMonitors;
225
226 return S_OK;
227}
228
229
230HRESULT SystemProperties::getInfoVDSize(LONG64 *infoVDSize)
231{
232 /*
233 * The BIOS supports currently 32 bit LBA numbers (implementing the full
234 * 48 bit range is in theory trivial, but the crappy compiler makes things
235 * more difficult). This translates to almost 2 TiBytes (to be on the safe
236 * side, the reported limit is 1 MiByte less than that, as the total number
237 * of sectors should fit in 32 bits, too), which should be enough for the
238 * moment. Since the MBR partition tables support only 32bit sector numbers
239 * and thus the BIOS can only boot from disks smaller than 2T this is a
240 * rather hard limit.
241 *
242 * The virtual ATA/SATA disks support complete LBA48, and SCSI supports
243 * LBA64 (almost, more like LBA55 in practice), so the theoretical maximum
244 * disk size is 128 PiByte/16 EiByte. The GUI works nicely with 6 orders
245 * of magnitude, but not with 11..13 orders of magnitude.
246 */
247 /* no need to lock, this is const */
248 *infoVDSize = 2 * _1T - _1M;
249
250 return S_OK;
251}
252
253
254HRESULT SystemProperties::getSerialPortCount(ULONG *count)
255{
256 /* no need to lock, this is const */
257 *count = SchemaDefs::SerialPortCount;
258
259 return S_OK;
260}
261
262
263HRESULT SystemProperties::getParallelPortCount(ULONG *count)
264{
265 /* no need to lock, this is const */
266 *count = SchemaDefs::ParallelPortCount;
267
268 return S_OK;
269}
270
271
272HRESULT SystemProperties::getMaxBootPosition(ULONG *aMaxBootPosition)
273{
274 /* no need to lock, this is const */
275 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
276
277 return S_OK;
278}
279
280
281HRESULT SystemProperties::getRawModeSupported(BOOL *aRawModeSupported)
282{
283#ifdef VBOX_WITH_RAW_MODE
284 *aRawModeSupported = TRUE;
285#else
286 *aRawModeSupported = FALSE;
287#endif
288 return S_OK;
289}
290
291
292HRESULT SystemProperties::getExclusiveHwVirt(BOOL *aExclusiveHwVirt)
293{
294 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
295
296 *aExclusiveHwVirt = m->fExclusiveHwVirt;
297
298 return S_OK;
299}
300
301HRESULT SystemProperties::setExclusiveHwVirt(BOOL aExclusiveHwVirt)
302{
303 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
304 m->fExclusiveHwVirt = !!aExclusiveHwVirt;
305 alock.release();
306
307 // VirtualBox::i_saveSettings() needs vbox write lock
308 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
309 HRESULT rc = mParent->i_saveSettings();
310
311 return rc;
312}
313
314HRESULT SystemProperties::getMaxNetworkAdapters(ChipsetType_T aChipset, ULONG *aMaxNetworkAdapters)
315{
316 /* no need for locking, no state */
317 uint32_t uResult = Global::getMaxNetworkAdapters(aChipset);
318 if (uResult == 0)
319 AssertMsgFailed(("Invalid chipset type %d\n", aChipset));
320 *aMaxNetworkAdapters = uResult;
321 return S_OK;
322}
323
324HRESULT SystemProperties::getMaxNetworkAdaptersOfType(ChipsetType_T aChipset, NetworkAttachmentType_T aType, ULONG *count)
325{
326 /* no need for locking, no state */
327 uint32_t uResult = Global::getMaxNetworkAdapters(aChipset);
328 if (uResult == 0)
329 AssertMsgFailed(("Invalid chipset type %d\n", aChipset));
330
331 switch (aType)
332 {
333 case NetworkAttachmentType_NAT:
334 case NetworkAttachmentType_Internal:
335 case NetworkAttachmentType_NATNetwork:
336 /* chipset default is OK */
337 break;
338 case NetworkAttachmentType_Bridged:
339 /* Maybe use current host interface count here? */
340 break;
341 case NetworkAttachmentType_HostOnly:
342 uResult = RT_MIN(uResult, 8);
343 break;
344 default:
345 AssertMsgFailed(("Unhandled attachment type %d\n", aType));
346 }
347
348 *count = uResult;
349
350 return S_OK;
351}
352
353
354HRESULT SystemProperties::getMaxDevicesPerPortForStorageBus(StorageBus_T aBus,
355 ULONG *aMaxDevicesPerPort)
356{
357 /* no need to lock, this is const */
358 switch (aBus)
359 {
360 case StorageBus_SATA:
361 case StorageBus_SCSI:
362 case StorageBus_SAS:
363 case StorageBus_USB:
364 case StorageBus_PCIe:
365 {
366 /* SATA and both SCSI controllers only support one device per port. */
367 *aMaxDevicesPerPort = 1;
368 break;
369 }
370 case StorageBus_IDE:
371 case StorageBus_Floppy:
372 {
373 /* The IDE and Floppy controllers support 2 devices. One as master
374 * and one as slave (or floppy drive 0 and 1). */
375 *aMaxDevicesPerPort = 2;
376 break;
377 }
378 default:
379 AssertMsgFailed(("Invalid bus type %d\n", aBus));
380 }
381
382 return S_OK;
383}
384
385HRESULT SystemProperties::getMinPortCountForStorageBus(StorageBus_T aBus,
386 ULONG *aMinPortCount)
387{
388 /* no need to lock, this is const */
389 switch (aBus)
390 {
391 case StorageBus_SATA:
392 case StorageBus_SAS:
393 case StorageBus_PCIe:
394 {
395 *aMinPortCount = 1;
396 break;
397 }
398 case StorageBus_SCSI:
399 {
400 *aMinPortCount = 16;
401 break;
402 }
403 case StorageBus_IDE:
404 {
405 *aMinPortCount = 2;
406 break;
407 }
408 case StorageBus_Floppy:
409 {
410 *aMinPortCount = 1;
411 break;
412 }
413 case StorageBus_USB:
414 {
415 *aMinPortCount = 8;
416 break;
417 }
418 default:
419 AssertMsgFailed(("Invalid bus type %d\n", aBus));
420 }
421
422 return S_OK;
423}
424
425HRESULT SystemProperties::getMaxPortCountForStorageBus(StorageBus_T aBus,
426 ULONG *aMaxPortCount)
427{
428 /* no need to lock, this is const */
429 switch (aBus)
430 {
431 case StorageBus_SATA:
432 {
433 *aMaxPortCount = 30;
434 break;
435 }
436 case StorageBus_SCSI:
437 {
438 *aMaxPortCount = 16;
439 break;
440 }
441 case StorageBus_IDE:
442 {
443 *aMaxPortCount = 2;
444 break;
445 }
446 case StorageBus_Floppy:
447 {
448 *aMaxPortCount = 1;
449 break;
450 }
451 case StorageBus_SAS:
452 case StorageBus_PCIe:
453 {
454 *aMaxPortCount = 255;
455 break;
456 }
457 case StorageBus_USB:
458 {
459 *aMaxPortCount = 8;
460 break;
461 }
462 default:
463 AssertMsgFailed(("Invalid bus type %d\n", aBus));
464 }
465
466 return S_OK;
467}
468
469HRESULT SystemProperties::getMaxInstancesOfStorageBus(ChipsetType_T aChipset,
470 StorageBus_T aBus,
471 ULONG *aMaxInstances)
472{
473 ULONG cCtrs = 0;
474
475 /* no need to lock, this is const */
476 switch (aBus)
477 {
478 case StorageBus_SATA:
479 case StorageBus_SCSI:
480 case StorageBus_SAS:
481 case StorageBus_PCIe:
482 cCtrs = aChipset == ChipsetType_ICH9 ? 8 : 1;
483 break;
484 case StorageBus_USB:
485 case StorageBus_IDE:
486 case StorageBus_Floppy:
487 {
488 cCtrs = 1;
489 break;
490 }
491 default:
492 AssertMsgFailed(("Invalid bus type %d\n", aBus));
493 }
494
495 *aMaxInstances = cCtrs;
496
497 return S_OK;
498}
499
500HRESULT SystemProperties::getDeviceTypesForStorageBus(StorageBus_T aBus,
501 std::vector<DeviceType_T> &aDeviceTypes)
502{
503 aDeviceTypes.resize(0);
504
505 /* no need to lock, this is const */
506 switch (aBus)
507 {
508 case StorageBus_IDE:
509 case StorageBus_SATA:
510 case StorageBus_SCSI:
511 case StorageBus_SAS:
512 case StorageBus_USB:
513 {
514 aDeviceTypes.resize(2);
515 aDeviceTypes[0] = DeviceType_DVD;
516 aDeviceTypes[1] = DeviceType_HardDisk;
517 break;
518 }
519 case StorageBus_Floppy:
520 {
521 aDeviceTypes.resize(1);
522 aDeviceTypes[0] = DeviceType_Floppy;
523 break;
524 }
525 case StorageBus_PCIe:
526 {
527 aDeviceTypes.resize(1);
528 aDeviceTypes[0] = DeviceType_HardDisk;
529 break;
530 }
531 default:
532 AssertMsgFailed(("Invalid bus type %d\n", aBus));
533 }
534
535 return S_OK;
536}
537
538HRESULT SystemProperties::getDefaultIoCacheSettingForStorageController(StorageControllerType_T aControllerType,
539 BOOL *aEnabled)
540{
541 /* no need to lock, this is const */
542 switch (aControllerType)
543 {
544 case StorageControllerType_LsiLogic:
545 case StorageControllerType_BusLogic:
546 case StorageControllerType_IntelAhci:
547 case StorageControllerType_LsiLogicSas:
548 case StorageControllerType_USB:
549 case StorageControllerType_NVMe:
550 *aEnabled = false;
551 break;
552 case StorageControllerType_PIIX3:
553 case StorageControllerType_PIIX4:
554 case StorageControllerType_ICH6:
555 case StorageControllerType_I82078:
556 *aEnabled = true;
557 break;
558 default:
559 AssertMsgFailed(("Invalid controller type %d\n", aControllerType));
560 }
561 return S_OK;
562}
563
564HRESULT SystemProperties::getStorageControllerHotplugCapable(StorageControllerType_T aControllerType,
565 BOOL *aHotplugCapable)
566{
567 switch (aControllerType)
568 {
569 case StorageControllerType_IntelAhci:
570 case StorageControllerType_USB:
571 *aHotplugCapable = true;
572 break;
573 case StorageControllerType_LsiLogic:
574 case StorageControllerType_LsiLogicSas:
575 case StorageControllerType_BusLogic:
576 case StorageControllerType_NVMe:
577 case StorageControllerType_PIIX3:
578 case StorageControllerType_PIIX4:
579 case StorageControllerType_ICH6:
580 case StorageControllerType_I82078:
581 *aHotplugCapable = false;
582 break;
583 default:
584 AssertMsgFailedReturn(("Invalid controller type %d\n", aControllerType), E_FAIL);
585 }
586
587 return S_OK;
588}
589
590HRESULT SystemProperties::getMaxInstancesOfUSBControllerType(ChipsetType_T aChipset,
591 USBControllerType_T aType,
592 ULONG *aMaxInstances)
593{
594 NOREF(aChipset);
595 ULONG cCtrs = 0;
596
597 /* no need to lock, this is const */
598 switch (aType)
599 {
600 case USBControllerType_OHCI:
601 case USBControllerType_EHCI:
602 case USBControllerType_XHCI:
603 {
604 cCtrs = 1;
605 break;
606 }
607 default:
608 AssertMsgFailed(("Invalid bus type %d\n", aType));
609 }
610
611 *aMaxInstances = cCtrs;
612
613 return S_OK;
614}
615
616HRESULT SystemProperties::getDefaultMachineFolder(com::Utf8Str &aDefaultMachineFolder)
617{
618 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
619 aDefaultMachineFolder = m->strDefaultMachineFolder;
620 return S_OK;
621}
622
623HRESULT SystemProperties::setDefaultMachineFolder(const com::Utf8Str &aDefaultMachineFolder)
624{
625 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
626 HRESULT rc = i_setDefaultMachineFolder(aDefaultMachineFolder);
627 alock.release();
628 if (SUCCEEDED(rc))
629 {
630 // VirtualBox::i_saveSettings() needs vbox write lock
631 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
632 rc = mParent->i_saveSettings();
633 }
634
635 return rc;
636}
637
638HRESULT SystemProperties::getLoggingLevel(com::Utf8Str &aLoggingLevel)
639{
640 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
641
642 aLoggingLevel = m->strLoggingLevel;
643
644 if (aLoggingLevel.isEmpty())
645 aLoggingLevel = VBOXSVC_LOG_DEFAULT;
646
647 return S_OK;
648}
649
650
651HRESULT SystemProperties::setLoggingLevel(const com::Utf8Str &aLoggingLevel)
652{
653 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
654 HRESULT rc = i_setLoggingLevel(aLoggingLevel);
655 alock.release();
656
657 if (SUCCEEDED(rc))
658 {
659 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
660 rc = mParent->i_saveSettings();
661 }
662 else
663 LogRel(("Cannot set passed logging level=%s, or the default one - Error=%Rhrc \n", aLoggingLevel.c_str(), rc));
664
665 return rc;
666}
667
668HRESULT SystemProperties::getMediumFormats(std::vector<ComPtr<IMediumFormat> > &aMediumFormats)
669{
670 MediumFormatList mediumFormats(m_llMediumFormats);
671 aMediumFormats.resize(mediumFormats.size());
672 size_t i = 0;
673 for (MediumFormatList::const_iterator it = mediumFormats.begin(); it != mediumFormats.end(); ++it, ++i)
674 (*it).queryInterfaceTo(aMediumFormats[i].asOutParam());
675 return S_OK;
676}
677
678HRESULT SystemProperties::getDefaultHardDiskFormat(com::Utf8Str &aDefaultHardDiskFormat)
679{
680 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
681 aDefaultHardDiskFormat = m->strDefaultHardDiskFormat;
682 return S_OK;
683}
684
685
686HRESULT SystemProperties::setDefaultHardDiskFormat(const com::Utf8Str &aDefaultHardDiskFormat)
687{
688 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
689 HRESULT rc = i_setDefaultHardDiskFormat(aDefaultHardDiskFormat);
690 alock.release();
691 if (SUCCEEDED(rc))
692 {
693 // VirtualBox::i_saveSettings() needs vbox write lock
694 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
695 rc = mParent->i_saveSettings();
696 }
697
698 return rc;
699}
700
701HRESULT SystemProperties::getFreeDiskSpaceWarning(LONG64 *aFreeSpace)
702{
703 NOREF(aFreeSpace);
704 ReturnComNotImplemented();
705}
706
707HRESULT SystemProperties::setFreeDiskSpaceWarning(LONG64 /* aFreeSpace */)
708{
709 ReturnComNotImplemented();
710}
711
712HRESULT SystemProperties::getFreeDiskSpacePercentWarning(ULONG *aFreeSpacePercent)
713{
714 NOREF(aFreeSpacePercent);
715 ReturnComNotImplemented();
716}
717
718HRESULT SystemProperties::setFreeDiskSpacePercentWarning(ULONG /* aFreeSpacePercent */)
719{
720 ReturnComNotImplemented();
721}
722
723HRESULT SystemProperties::getFreeDiskSpaceError(LONG64 *aFreeSpace)
724{
725 NOREF(aFreeSpace);
726 ReturnComNotImplemented();
727}
728
729HRESULT SystemProperties::setFreeDiskSpaceError(LONG64 /* aFreeSpace */)
730{
731 ReturnComNotImplemented();
732}
733
734HRESULT SystemProperties::getFreeDiskSpacePercentError(ULONG *aFreeSpacePercent)
735{
736 NOREF(aFreeSpacePercent);
737 ReturnComNotImplemented();
738}
739
740HRESULT SystemProperties::setFreeDiskSpacePercentError(ULONG /* aFreeSpacePercent */)
741{
742 ReturnComNotImplemented();
743}
744
745HRESULT SystemProperties::getVRDEAuthLibrary(com::Utf8Str &aVRDEAuthLibrary)
746{
747 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
748
749 aVRDEAuthLibrary = m->strVRDEAuthLibrary;
750
751 return S_OK;
752}
753
754HRESULT SystemProperties::setVRDEAuthLibrary(const com::Utf8Str &aVRDEAuthLibrary)
755{
756 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
757 HRESULT rc = i_setVRDEAuthLibrary(aVRDEAuthLibrary);
758 alock.release();
759 if (SUCCEEDED(rc))
760 {
761 // VirtualBox::i_saveSettings() needs vbox write lock
762 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
763 rc = mParent->i_saveSettings();
764 }
765
766 return rc;
767}
768
769HRESULT SystemProperties::getWebServiceAuthLibrary(com::Utf8Str &aWebServiceAuthLibrary)
770{
771 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
772
773 aWebServiceAuthLibrary = m->strWebServiceAuthLibrary;
774
775 return S_OK;
776}
777
778HRESULT SystemProperties::setWebServiceAuthLibrary(const com::Utf8Str &aWebServiceAuthLibrary)
779{
780 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
781 HRESULT rc = i_setWebServiceAuthLibrary(aWebServiceAuthLibrary);
782 alock.release();
783
784 if (SUCCEEDED(rc))
785 {
786 // VirtualBox::i_saveSettings() needs vbox write lock
787 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
788 rc = mParent->i_saveSettings();
789 }
790
791 return rc;
792}
793
794HRESULT SystemProperties::getDefaultVRDEExtPack(com::Utf8Str &aExtPack)
795{
796 HRESULT hrc = S_OK;
797 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
798 Utf8Str strExtPack(m->strDefaultVRDEExtPack);
799 if (strExtPack.isNotEmpty())
800 {
801 if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
802 hrc = S_OK;
803 else
804#ifdef VBOX_WITH_EXTPACK
805 hrc = mParent->i_getExtPackManager()->i_checkVrdeExtPack(&strExtPack);
806#else
807 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
808#endif
809 }
810 else
811 {
812#ifdef VBOX_WITH_EXTPACK
813 hrc = mParent->i_getExtPackManager()->i_getDefaultVrdeExtPack(&strExtPack);
814#endif
815 if (strExtPack.isEmpty())
816 {
817 /*
818 * Klugde - check if VBoxVRDP.dll/.so/.dylib is installed.
819 * This is hardcoded uglyness, sorry.
820 */
821 char szPath[RTPATH_MAX];
822 int vrc = RTPathAppPrivateArch(szPath, sizeof(szPath));
823 if (RT_SUCCESS(vrc))
824 vrc = RTPathAppend(szPath, sizeof(szPath), "VBoxVRDP");
825 if (RT_SUCCESS(vrc))
826 vrc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
827 if (RT_SUCCESS(vrc) && RTFileExists(szPath))
828 {
829 /* Illegal extpack name, so no conflict. */
830 strExtPack = VBOXVRDP_KLUDGE_EXTPACK_NAME;
831 }
832 }
833 }
834
835 if (SUCCEEDED(hrc))
836 aExtPack = strExtPack;
837
838 return S_OK;
839}
840
841
842HRESULT SystemProperties::setDefaultVRDEExtPack(const com::Utf8Str &aExtPack)
843{
844 HRESULT hrc = S_OK;
845 if (aExtPack.isNotEmpty())
846 {
847 if (aExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
848 hrc = S_OK;
849 else
850#ifdef VBOX_WITH_EXTPACK
851 hrc = mParent->i_getExtPackManager()->i_checkVrdeExtPack(&aExtPack);
852#else
853 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), aExtPack.c_str());
854#endif
855 }
856 if (SUCCEEDED(hrc))
857 {
858 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
859 hrc = i_setDefaultVRDEExtPack(aExtPack);
860 if (SUCCEEDED(hrc))
861 {
862 /* VirtualBox::i_saveSettings() needs the VirtualBox write lock. */
863 alock.release();
864 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
865 hrc = mParent->i_saveSettings();
866 }
867 }
868
869 return hrc;
870}
871
872
873HRESULT SystemProperties::getLogHistoryCount(ULONG *count)
874{
875 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
876
877 *count = m->uLogHistoryCount;
878
879 return S_OK;
880}
881
882
883HRESULT SystemProperties::setLogHistoryCount(ULONG count)
884{
885 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
886 m->uLogHistoryCount = count;
887 alock.release();
888
889 // VirtualBox::i_saveSettings() needs vbox write lock
890 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
891 HRESULT rc = mParent->i_saveSettings();
892
893 return rc;
894}
895
896HRESULT SystemProperties::getDefaultAudioDriver(AudioDriverType_T *aAudioDriver)
897{
898 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
899
900 *aAudioDriver = settings::MachineConfigFile::getHostDefaultAudioDriver();
901
902 return S_OK;
903}
904
905HRESULT SystemProperties::getAutostartDatabasePath(com::Utf8Str &aAutostartDbPath)
906{
907 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
908
909 aAutostartDbPath = m->strAutostartDatabasePath;
910
911 return S_OK;
912}
913
914HRESULT SystemProperties::setAutostartDatabasePath(const com::Utf8Str &aAutostartDbPath)
915{
916 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
917 HRESULT rc = i_setAutostartDatabasePath(aAutostartDbPath);
918 alock.release();
919
920 if (SUCCEEDED(rc))
921 {
922 // VirtualBox::i_saveSettings() needs vbox write lock
923 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
924 rc = mParent->i_saveSettings();
925 }
926
927 return rc;
928}
929
930HRESULT SystemProperties::getDefaultAdditionsISO(com::Utf8Str &aDefaultAdditionsISO)
931{
932 return i_getDefaultAdditionsISO(aDefaultAdditionsISO);
933}
934
935HRESULT SystemProperties::setDefaultAdditionsISO(const com::Utf8Str &aDefaultAdditionsISO)
936{
937 RT_NOREF(aDefaultAdditionsISO);
938 /** @todo not yet implemented, settings handling is missing */
939 ReturnComNotImplemented();
940#if 0 /* not implemented */
941 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
942 HRESULT rc = i_setDefaultAdditionsISO(aDefaultAdditionsISO);
943 alock.release();
944
945 if (SUCCEEDED(rc))
946 {
947 // VirtualBox::i_saveSettings() needs vbox write lock
948 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
949 rc = mParent->i_saveSettings();
950 }
951
952 return rc;
953#endif
954}
955
956HRESULT SystemProperties::getDefaultFrontend(com::Utf8Str &aDefaultFrontend)
957{
958 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
959 aDefaultFrontend = m->strDefaultFrontend;
960 return S_OK;
961}
962
963HRESULT SystemProperties::setDefaultFrontend(const com::Utf8Str &aDefaultFrontend)
964{
965 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
966 if (m->strDefaultFrontend == Utf8Str(aDefaultFrontend))
967 return S_OK;
968 HRESULT rc = i_setDefaultFrontend(aDefaultFrontend);
969 alock.release();
970
971 if (SUCCEEDED(rc))
972 {
973 // VirtualBox::i_saveSettings() needs vbox write lock
974 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
975 rc = mParent->i_saveSettings();
976 }
977
978 return rc;
979}
980
981HRESULT SystemProperties::getScreenShotFormats(std::vector<BitmapFormat_T> &aBitmapFormats)
982{
983 aBitmapFormats.push_back(BitmapFormat_BGR0);
984 aBitmapFormats.push_back(BitmapFormat_BGRA);
985 aBitmapFormats.push_back(BitmapFormat_RGBA);
986 aBitmapFormats.push_back(BitmapFormat_PNG);
987 return S_OK;
988}
989
990HRESULT SystemProperties::getProxyMode(ProxyMode_T *pProxyMode)
991{
992 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
993 ProxyMode_T enmMode = *pProxyMode = (ProxyMode_T)m->uProxyMode;
994 AssertMsgReturn(enmMode == ProxyMode_System || enmMode == ProxyMode_NoProxy || enmMode == ProxyMode_Manual,
995 ("enmMode=%d\n", enmMode), E_UNEXPECTED);
996 return S_OK;
997}
998
999HRESULT SystemProperties::setProxyMode(ProxyMode_T aProxyMode)
1000{
1001 /* Validate input. */
1002 switch (aProxyMode)
1003 {
1004 case ProxyMode_System:
1005 case ProxyMode_NoProxy:
1006 case ProxyMode_Manual:
1007 break;
1008 default:
1009 return setError(E_INVALIDARG, tr("Invalid ProxyMode value: %d"), (int)aProxyMode);
1010 }
1011
1012 /* Set and write out settings. */
1013 {
1014 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1015 m->uProxyMode = aProxyMode;
1016 }
1017 AutoWriteLock alock(mParent COMMA_LOCKVAL_SRC_POS); /* required for saving. */
1018 return mParent->i_saveSettings();
1019}
1020
1021HRESULT SystemProperties::getProxyURL(com::Utf8Str &aProxyURL)
1022{
1023 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1024 aProxyURL = m->strProxyUrl;
1025 return S_OK;
1026}
1027
1028HRESULT SystemProperties::setProxyURL(const com::Utf8Str &aProxyURL)
1029{
1030 /*
1031 * Validate input.
1032 */
1033 Utf8Str const *pStrProxyUrl = &aProxyURL;
1034 Utf8Str strTmp;
1035 if (pStrProxyUrl->isNotEmpty())
1036 {
1037 /* RTUriParse requires a scheme, so append 'http://' if none seems present: */
1038 if (pStrProxyUrl->find("://") == RTCString::npos)
1039 {
1040 strTmp.printf("http://%s", aProxyURL.c_str());
1041 pStrProxyUrl = &strTmp;
1042 }
1043
1044 /* Use RTUriParse to check the format. There must be a hostname, but nothing
1045 can follow it and the port. */
1046 RTURIPARSED Parsed;
1047 int vrc = RTUriParse(pStrProxyUrl->c_str(), &Parsed);
1048 if (RT_FAILURE(vrc))
1049 return setErrorBoth(E_INVALIDARG, vrc, tr("Failed to parse proxy URL: %Rrc"), vrc);
1050 if ( Parsed.cchAuthorityHost == 0
1051 && !RTUriIsSchemeMatch(pStrProxyUrl->c_str(), "direct"))
1052 return setError(E_INVALIDARG, tr("Proxy URL must include a hostname"));
1053 if (Parsed.cchPath > 0)
1054 return setError(E_INVALIDARG, tr("Proxy URL must not include a path component (%.*s)"),
1055 Parsed.cchPath, pStrProxyUrl->c_str() + Parsed.offPath);
1056 if (Parsed.cchQuery > 0)
1057 return setError(E_INVALIDARG, tr("Proxy URL must not include a query component (?%.*s)"),
1058 Parsed.cchQuery, pStrProxyUrl->c_str() + Parsed.offQuery);
1059 if (Parsed.cchFragment > 0)
1060 return setError(E_INVALIDARG, tr("Proxy URL must not include a fragment component (#%.*s)"),
1061 Parsed.cchFragment, pStrProxyUrl->c_str() + Parsed.offFragment);
1062 }
1063
1064 /*
1065 * Set and write out settings.
1066 */
1067 {
1068 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1069 m->strProxyUrl = *pStrProxyUrl;
1070 }
1071 AutoWriteLock alock(mParent COMMA_LOCKVAL_SRC_POS); /* required for saving. */
1072 return mParent->i_saveSettings();
1073}
1074
1075// public methods only for internal purposes
1076/////////////////////////////////////////////////////////////////////////////
1077
1078HRESULT SystemProperties::i_loadSettings(const settings::SystemProperties &data)
1079{
1080 AutoCaller autoCaller(this);
1081 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1082
1083 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1084 HRESULT rc = S_OK;
1085 rc = i_setDefaultMachineFolder(data.strDefaultMachineFolder);
1086 if (FAILED(rc)) return rc;
1087
1088 rc = i_setLoggingLevel(data.strLoggingLevel);
1089 if (FAILED(rc)) return rc;
1090
1091 rc = i_setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
1092 if (FAILED(rc)) return rc;
1093
1094 rc = i_setVRDEAuthLibrary(data.strVRDEAuthLibrary);
1095 if (FAILED(rc)) return rc;
1096
1097 rc = i_setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
1098 if (FAILED(rc)) return rc;
1099
1100 rc = i_setDefaultVRDEExtPack(data.strDefaultVRDEExtPack);
1101 if (FAILED(rc)) return rc;
1102
1103 m->uLogHistoryCount = data.uLogHistoryCount;
1104 m->fExclusiveHwVirt = data.fExclusiveHwVirt;
1105 m->uProxyMode = data.uProxyMode;
1106 m->strProxyUrl = data.strProxyUrl;
1107
1108 rc = i_setAutostartDatabasePath(data.strAutostartDatabasePath);
1109 if (FAILED(rc)) return rc;
1110
1111 {
1112 /* must ignore errors signalled here, because the guest additions
1113 * file may not exist, and in this case keep the empty string */
1114 ErrorInfoKeeper eik;
1115 (void)i_setDefaultAdditionsISO(data.strDefaultAdditionsISO);
1116 }
1117
1118 rc = i_setDefaultFrontend(data.strDefaultFrontend);
1119 if (FAILED(rc)) return rc;
1120
1121 return S_OK;
1122}
1123
1124HRESULT SystemProperties::i_saveSettings(settings::SystemProperties &data)
1125{
1126 AutoCaller autoCaller(this);
1127 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1128
1129 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1130
1131 data = *m;
1132
1133 return S_OK;
1134}
1135
1136/**
1137 * Returns a medium format object corresponding to the given format
1138 * identifier or null if no such format.
1139 *
1140 * @param aFormat Format identifier.
1141 *
1142 * @return ComObjPtr<MediumFormat>
1143 */
1144ComObjPtr<MediumFormat> SystemProperties::i_mediumFormat(const Utf8Str &aFormat)
1145{
1146 ComObjPtr<MediumFormat> format;
1147
1148 AutoCaller autoCaller(this);
1149 AssertComRCReturn (autoCaller.rc(), format);
1150
1151 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1152
1153 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
1154 it != m_llMediumFormats.end();
1155 ++ it)
1156 {
1157 /* MediumFormat is all const, no need to lock */
1158
1159 if ((*it)->i_getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
1160 {
1161 format = *it;
1162 break;
1163 }
1164 }
1165
1166 return format;
1167}
1168
1169/**
1170 * Returns a medium format object corresponding to the given file extension or
1171 * null if no such format.
1172 *
1173 * @param aExt File extension.
1174 *
1175 * @return ComObjPtr<MediumFormat>
1176 */
1177ComObjPtr<MediumFormat> SystemProperties::i_mediumFormatFromExtension(const Utf8Str &aExt)
1178{
1179 ComObjPtr<MediumFormat> format;
1180
1181 AutoCaller autoCaller(this);
1182 AssertComRCReturn (autoCaller.rc(), format);
1183
1184 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1185
1186 bool fFound = false;
1187 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
1188 it != m_llMediumFormats.end() && !fFound;
1189 ++it)
1190 {
1191 /* MediumFormat is all const, no need to lock */
1192 MediumFormat::StrArray aFileList = (*it)->i_getFileExtensions();
1193 for (MediumFormat::StrArray::const_iterator it1 = aFileList.begin();
1194 it1 != aFileList.end();
1195 ++it1)
1196 {
1197 if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0)
1198 {
1199 format = *it;
1200 fFound = true;
1201 break;
1202 }
1203 }
1204 }
1205
1206 return format;
1207}
1208
1209
1210/**
1211 * VD plugin load
1212 */
1213int SystemProperties::i_loadVDPlugin(const char *pszPluginLibrary)
1214{
1215 return VDPluginLoadFromFilename(pszPluginLibrary);
1216}
1217
1218/**
1219 * VD plugin unload
1220 */
1221int SystemProperties::i_unloadVDPlugin(const char *pszPluginLibrary)
1222{
1223 return VDPluginUnloadFromFilename(pszPluginLibrary);
1224}
1225
1226/**
1227 * Internally usable version of getDefaultAdditionsISO.
1228 */
1229HRESULT SystemProperties::i_getDefaultAdditionsISO(com::Utf8Str &aDefaultAdditionsISO)
1230{
1231 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1232 if (m->strDefaultAdditionsISO.isNotEmpty())
1233 aDefaultAdditionsISO = m->strDefaultAdditionsISO;
1234 else
1235 {
1236 /* no guest additions, check if it showed up in the mean time */
1237 alock.release();
1238 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS);
1239 if (m->strDefaultAdditionsISO.isEmpty())
1240 {
1241 ErrorInfoKeeper eik;
1242 (void)setDefaultAdditionsISO("");
1243 }
1244 aDefaultAdditionsISO = m->strDefaultAdditionsISO;
1245 }
1246 return S_OK;
1247}
1248
1249// private methods
1250/////////////////////////////////////////////////////////////////////////////
1251
1252/**
1253 * Returns the user's home directory. Wrapper around RTPathUserHome().
1254 * @param strPath
1255 * @return
1256 */
1257HRESULT SystemProperties::i_getUserHomeDirectory(Utf8Str &strPath)
1258{
1259 char szHome[RTPATH_MAX];
1260 int vrc = RTPathUserHome(szHome, sizeof(szHome));
1261 if (RT_FAILURE(vrc))
1262 return setErrorBoth(E_FAIL, vrc,
1263 tr("Cannot determine user home directory (%Rrc)"),
1264 vrc);
1265 strPath = szHome;
1266 return S_OK;
1267}
1268
1269/**
1270 * Internal implementation to set the default machine folder. Gets called
1271 * from the public attribute setter as well as loadSettings(). With 4.0,
1272 * the "default default" machine folder has changed, and we now require
1273 * a full path always.
1274 * @param strPath
1275 * @return
1276 */
1277HRESULT SystemProperties::i_setDefaultMachineFolder(const Utf8Str &strPath)
1278{
1279 Utf8Str path(strPath); // make modifiable
1280 if ( path.isEmpty() // used by API calls to reset the default
1281 || path == "Machines" // this value (exactly like this, without path) is stored
1282 // in VirtualBox.xml if user upgrades from before 4.0 and
1283 // has not changed the default machine folder
1284 )
1285 {
1286 // new default with VirtualBox 4.0: "$HOME/VirtualBox VMs"
1287 HRESULT rc = i_getUserHomeDirectory(path);
1288 if (FAILED(rc)) return rc;
1289 path += RTPATH_SLASH_STR "VirtualBox VMs";
1290 }
1291
1292 if (!RTPathStartsWithRoot(path.c_str()))
1293 return setError(E_INVALIDARG,
1294 tr("Given default machine folder '%s' is not fully qualified"),
1295 path.c_str());
1296
1297 m->strDefaultMachineFolder = path;
1298
1299 return S_OK;
1300}
1301
1302HRESULT SystemProperties::i_setLoggingLevel(const com::Utf8Str &aLoggingLevel)
1303{
1304 Utf8Str useLoggingLevel(aLoggingLevel);
1305 if (useLoggingLevel.isEmpty())
1306 useLoggingLevel = VBOXSVC_LOG_DEFAULT;
1307 int rc = RTLogGroupSettings(RTLogRelGetDefaultInstance(), useLoggingLevel.c_str());
1308 // If failed and not the default logging level - try to use the default logging level.
1309 if (RT_FAILURE(rc))
1310 {
1311 // If failed write message to the release log.
1312 LogRel(("Cannot set passed logging level=%s Error=%Rrc \n", useLoggingLevel.c_str(), rc));
1313 // If attempted logging level not the default one then try the default one.
1314 if (!useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT))
1315 {
1316 rc = RTLogGroupSettings(RTLogRelGetDefaultInstance(), VBOXSVC_LOG_DEFAULT);
1317 // If failed report this to the release log.
1318 if (RT_FAILURE(rc))
1319 LogRel(("Cannot set default logging level Error=%Rrc \n", rc));
1320 }
1321 // On any failure - set default level as the one to be stored.
1322 useLoggingLevel = VBOXSVC_LOG_DEFAULT;
1323 }
1324 // Set to passed value or if default used/attempted (even if error condition) use empty string.
1325 m->strLoggingLevel = (useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT) ? "" : useLoggingLevel);
1326 return RT_SUCCESS(rc) ? S_OK : E_FAIL;
1327}
1328
1329HRESULT SystemProperties::i_setDefaultHardDiskFormat(const com::Utf8Str &aFormat)
1330{
1331 if (!aFormat.isEmpty())
1332 m->strDefaultHardDiskFormat = aFormat;
1333 else
1334 m->strDefaultHardDiskFormat = "VDI";
1335
1336 return S_OK;
1337}
1338
1339HRESULT SystemProperties::i_setVRDEAuthLibrary(const com::Utf8Str &aPath)
1340{
1341 if (!aPath.isEmpty())
1342 m->strVRDEAuthLibrary = aPath;
1343 else
1344 m->strVRDEAuthLibrary = "VBoxAuth";
1345
1346 return S_OK;
1347}
1348
1349HRESULT SystemProperties::i_setWebServiceAuthLibrary(const com::Utf8Str &aPath)
1350{
1351 if (!aPath.isEmpty())
1352 m->strWebServiceAuthLibrary = aPath;
1353 else
1354 m->strWebServiceAuthLibrary = "VBoxAuth";
1355
1356 return S_OK;
1357}
1358
1359HRESULT SystemProperties::i_setDefaultVRDEExtPack(const com::Utf8Str &aExtPack)
1360{
1361 m->strDefaultVRDEExtPack = aExtPack;
1362
1363 return S_OK;
1364}
1365
1366HRESULT SystemProperties::i_setAutostartDatabasePath(const com::Utf8Str &aPath)
1367{
1368 HRESULT rc = S_OK;
1369 AutostartDb *autostartDb = this->mParent->i_getAutostartDb();
1370
1371 if (!aPath.isEmpty())
1372 {
1373 /* Update path in the autostart database. */
1374 int vrc = autostartDb->setAutostartDbPath(aPath.c_str());
1375 if (RT_SUCCESS(vrc))
1376 m->strAutostartDatabasePath = aPath;
1377 else
1378 rc = setErrorBoth(E_FAIL, vrc,
1379 tr("Cannot set the autostart database path (%Rrc)"),
1380 vrc);
1381 }
1382 else
1383 {
1384 int vrc = autostartDb->setAutostartDbPath(NULL);
1385 if (RT_SUCCESS(vrc) || vrc == VERR_NOT_SUPPORTED)
1386 m->strAutostartDatabasePath = "";
1387 else
1388 rc = setErrorBoth(E_FAIL, vrc,
1389 tr("Deleting the autostart database path failed (%Rrc)"),
1390 vrc);
1391 }
1392
1393 return rc;
1394}
1395
1396HRESULT SystemProperties::i_setDefaultAdditionsISO(const com::Utf8Str &aPath)
1397{
1398 com::Utf8Str path(aPath);
1399 if (path.isEmpty())
1400 {
1401 char strTemp[RTPATH_MAX];
1402 int vrc = RTPathAppPrivateNoArch(strTemp, sizeof(strTemp));
1403 AssertRC(vrc);
1404 Utf8Str strSrc1 = Utf8Str(strTemp).append("/VBoxGuestAdditions.iso");
1405
1406 vrc = RTPathExecDir(strTemp, sizeof(strTemp));
1407 AssertRC(vrc);
1408 Utf8Str strSrc2 = Utf8Str(strTemp).append("/additions/VBoxGuestAdditions.iso");
1409
1410 vrc = RTPathUserHome(strTemp, sizeof(strTemp));
1411 AssertRC(vrc);
1412 Utf8Str strSrc3 = Utf8StrFmt("%s/VBoxGuestAdditions_%s.iso", strTemp, VirtualBox::i_getVersionNormalized().c_str());
1413
1414 /* Check the standard image locations */
1415 if (RTFileExists(strSrc1.c_str()))
1416 path = strSrc1;
1417 else if (RTFileExists(strSrc2.c_str()))
1418 path = strSrc2;
1419 else if (RTFileExists(strSrc3.c_str()))
1420 path = strSrc3;
1421 else
1422 return setError(E_FAIL,
1423 tr("Cannot determine default Guest Additions ISO location. Most likely they are not available"));
1424 }
1425
1426 if (!RTPathStartsWithRoot(path.c_str()))
1427 return setError(E_INVALIDARG,
1428 tr("Given default machine Guest Additions ISO file '%s' is not fully qualified"),
1429 path.c_str());
1430
1431 if (!RTFileExists(path.c_str()))
1432 return setError(E_INVALIDARG,
1433 tr("Given default machine Guest Additions ISO file '%s' does not exist"),
1434 path.c_str());
1435
1436 m->strDefaultAdditionsISO = path;
1437
1438 return S_OK;
1439}
1440
1441HRESULT SystemProperties::i_setDefaultFrontend(const com::Utf8Str &aDefaultFrontend)
1442{
1443 m->strDefaultFrontend = aDefaultFrontend;
1444
1445 return S_OK;
1446}
1447
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