VirtualBox

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

Last change on this file since 81394 was 80734, checked in by vboxsync, 5 years ago

Main/SystemProperties: For now allow only disks on virtio-scsi storage controller (DVD to be added later).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.9 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 80734 2019-09-11 14:32:43Z 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 *aRawModeSupported = FALSE;
284 return S_OK;
285}
286
287
288HRESULT SystemProperties::getExclusiveHwVirt(BOOL *aExclusiveHwVirt)
289{
290 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
291
292 *aExclusiveHwVirt = m->fExclusiveHwVirt;
293
294 return S_OK;
295}
296
297HRESULT SystemProperties::setExclusiveHwVirt(BOOL aExclusiveHwVirt)
298{
299 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
300 m->fExclusiveHwVirt = !!aExclusiveHwVirt;
301 alock.release();
302
303 // VirtualBox::i_saveSettings() needs vbox write lock
304 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
305 HRESULT rc = mParent->i_saveSettings();
306
307 return rc;
308}
309
310HRESULT SystemProperties::getMaxNetworkAdapters(ChipsetType_T aChipset, ULONG *aMaxNetworkAdapters)
311{
312 /* no need for locking, no state */
313 uint32_t uResult = Global::getMaxNetworkAdapters(aChipset);
314 if (uResult == 0)
315 AssertMsgFailed(("Invalid chipset type %d\n", aChipset));
316 *aMaxNetworkAdapters = uResult;
317 return S_OK;
318}
319
320HRESULT SystemProperties::getMaxNetworkAdaptersOfType(ChipsetType_T aChipset, NetworkAttachmentType_T aType, ULONG *count)
321{
322 /* no need for locking, no state */
323 uint32_t uResult = Global::getMaxNetworkAdapters(aChipset);
324 if (uResult == 0)
325 AssertMsgFailed(("Invalid chipset type %d\n", aChipset));
326
327 switch (aType)
328 {
329 case NetworkAttachmentType_NAT:
330 case NetworkAttachmentType_Internal:
331 case NetworkAttachmentType_NATNetwork:
332 /* chipset default is OK */
333 break;
334 case NetworkAttachmentType_Bridged:
335 /* Maybe use current host interface count here? */
336 break;
337 case NetworkAttachmentType_HostOnly:
338 uResult = RT_MIN(uResult, 8);
339 break;
340 default:
341 AssertMsgFailed(("Unhandled attachment type %d\n", aType));
342 }
343
344 *count = uResult;
345
346 return S_OK;
347}
348
349
350HRESULT SystemProperties::getMaxDevicesPerPortForStorageBus(StorageBus_T aBus,
351 ULONG *aMaxDevicesPerPort)
352{
353 /* no need to lock, this is const */
354 switch (aBus)
355 {
356 case StorageBus_SATA:
357 case StorageBus_SCSI:
358 case StorageBus_SAS:
359 case StorageBus_USB:
360 case StorageBus_PCIe:
361 case StorageBus_VirtioSCSI:
362 {
363 /* SATA and both SCSI controllers only support one device per port. */
364 *aMaxDevicesPerPort = 1;
365 break;
366 }
367 case StorageBus_IDE:
368 case StorageBus_Floppy:
369 {
370 /* The IDE and Floppy controllers support 2 devices. One as master
371 * and one as slave (or floppy drive 0 and 1). */
372 *aMaxDevicesPerPort = 2;
373 break;
374 }
375 default:
376 AssertMsgFailed(("Invalid bus type %d\n", aBus));
377 }
378
379 return S_OK;
380}
381
382HRESULT SystemProperties::getMinPortCountForStorageBus(StorageBus_T aBus,
383 ULONG *aMinPortCount)
384{
385 /* no need to lock, this is const */
386 switch (aBus)
387 {
388 case StorageBus_SATA:
389 case StorageBus_SAS:
390 case StorageBus_PCIe:
391 case StorageBus_VirtioSCSI:
392 {
393 *aMinPortCount = 1;
394 break;
395 }
396 case StorageBus_SCSI:
397 {
398 *aMinPortCount = 16;
399 break;
400 }
401 case StorageBus_IDE:
402 {
403 *aMinPortCount = 2;
404 break;
405 }
406 case StorageBus_Floppy:
407 {
408 *aMinPortCount = 1;
409 break;
410 }
411 case StorageBus_USB:
412 {
413 *aMinPortCount = 8;
414 break;
415 }
416 default:
417 AssertMsgFailed(("Invalid bus type %d\n", aBus));
418 }
419
420 return S_OK;
421}
422
423HRESULT SystemProperties::getMaxPortCountForStorageBus(StorageBus_T aBus,
424 ULONG *aMaxPortCount)
425{
426 /* no need to lock, this is const */
427 switch (aBus)
428 {
429 case StorageBus_SATA:
430 {
431 *aMaxPortCount = 30;
432 break;
433 }
434 case StorageBus_SCSI:
435 {
436 *aMaxPortCount = 16;
437 break;
438 }
439 case StorageBus_IDE:
440 {
441 *aMaxPortCount = 2;
442 break;
443 }
444 case StorageBus_Floppy:
445 {
446 *aMaxPortCount = 1;
447 break;
448 }
449 case StorageBus_SAS:
450 case StorageBus_PCIe:
451 {
452 *aMaxPortCount = 255;
453 break;
454 }
455 case StorageBus_USB:
456 {
457 *aMaxPortCount = 8;
458 break;
459 }
460 case StorageBus_VirtioSCSI:
461 {
462 *aMaxPortCount = 256;
463 break;
464 }
465 default:
466 AssertMsgFailed(("Invalid bus type %d\n", aBus));
467 }
468
469 return S_OK;
470}
471
472HRESULT SystemProperties::getMaxInstancesOfStorageBus(ChipsetType_T aChipset,
473 StorageBus_T aBus,
474 ULONG *aMaxInstances)
475{
476 ULONG cCtrs = 0;
477
478 /* no need to lock, this is const */
479 switch (aBus)
480 {
481 case StorageBus_SATA:
482 case StorageBus_SCSI:
483 case StorageBus_SAS:
484 case StorageBus_PCIe:
485 case StorageBus_VirtioSCSI:
486 cCtrs = aChipset == ChipsetType_ICH9 ? 8 : 1;
487 break;
488 case StorageBus_USB:
489 case StorageBus_IDE:
490 case StorageBus_Floppy:
491 {
492 cCtrs = 1;
493 break;
494 }
495 default:
496 AssertMsgFailed(("Invalid bus type %d\n", aBus));
497 }
498
499 *aMaxInstances = cCtrs;
500
501 return S_OK;
502}
503
504HRESULT SystemProperties::getDeviceTypesForStorageBus(StorageBus_T aBus,
505 std::vector<DeviceType_T> &aDeviceTypes)
506{
507 aDeviceTypes.resize(0);
508
509 /* no need to lock, this is const */
510 switch (aBus)
511 {
512 case StorageBus_IDE:
513 case StorageBus_SATA:
514 case StorageBus_SCSI:
515 case StorageBus_SAS:
516 case StorageBus_USB:
517 {
518 aDeviceTypes.resize(2);
519 aDeviceTypes[0] = DeviceType_DVD;
520 aDeviceTypes[1] = DeviceType_HardDisk;
521 break;
522 }
523 case StorageBus_Floppy:
524 {
525 aDeviceTypes.resize(1);
526 aDeviceTypes[0] = DeviceType_Floppy;
527 break;
528 }
529 case StorageBus_VirtioSCSI:
530 case StorageBus_PCIe:
531 {
532 aDeviceTypes.resize(1);
533 aDeviceTypes[0] = DeviceType_HardDisk;
534 break;
535 }
536 default:
537 AssertMsgFailed(("Invalid bus type %d\n", aBus));
538 }
539
540 return S_OK;
541}
542
543HRESULT SystemProperties::getDefaultIoCacheSettingForStorageController(StorageControllerType_T aControllerType,
544 BOOL *aEnabled)
545{
546 /* no need to lock, this is const */
547 switch (aControllerType)
548 {
549 case StorageControllerType_LsiLogic:
550 case StorageControllerType_BusLogic:
551 case StorageControllerType_IntelAhci:
552 case StorageControllerType_LsiLogicSas:
553 case StorageControllerType_USB:
554 case StorageControllerType_NVMe:
555 case StorageControllerType_VirtioSCSI:
556 *aEnabled = false;
557 break;
558 case StorageControllerType_PIIX3:
559 case StorageControllerType_PIIX4:
560 case StorageControllerType_ICH6:
561 case StorageControllerType_I82078:
562 *aEnabled = true;
563 break;
564 default:
565 AssertMsgFailed(("Invalid controller type %d\n", aControllerType));
566 }
567 return S_OK;
568}
569
570HRESULT SystemProperties::getStorageControllerHotplugCapable(StorageControllerType_T aControllerType,
571 BOOL *aHotplugCapable)
572{
573 switch (aControllerType)
574 {
575 case StorageControllerType_IntelAhci:
576 case StorageControllerType_USB:
577 *aHotplugCapable = true;
578 break;
579 case StorageControllerType_LsiLogic:
580 case StorageControllerType_LsiLogicSas:
581 case StorageControllerType_BusLogic:
582 case StorageControllerType_NVMe:
583 case StorageControllerType_VirtioSCSI:
584 case StorageControllerType_PIIX3:
585 case StorageControllerType_PIIX4:
586 case StorageControllerType_ICH6:
587 case StorageControllerType_I82078:
588 *aHotplugCapable = false;
589 break;
590 default:
591 AssertMsgFailedReturn(("Invalid controller type %d\n", aControllerType), E_FAIL);
592 }
593
594 return S_OK;
595}
596
597HRESULT SystemProperties::getMaxInstancesOfUSBControllerType(ChipsetType_T aChipset,
598 USBControllerType_T aType,
599 ULONG *aMaxInstances)
600{
601 NOREF(aChipset);
602 ULONG cCtrs = 0;
603
604 /* no need to lock, this is const */
605 switch (aType)
606 {
607 case USBControllerType_OHCI:
608 case USBControllerType_EHCI:
609 case USBControllerType_XHCI:
610 {
611 cCtrs = 1;
612 break;
613 }
614 default:
615 AssertMsgFailed(("Invalid bus type %d\n", aType));
616 }
617
618 *aMaxInstances = cCtrs;
619
620 return S_OK;
621}
622
623HRESULT SystemProperties::getDefaultMachineFolder(com::Utf8Str &aDefaultMachineFolder)
624{
625 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
626 aDefaultMachineFolder = m->strDefaultMachineFolder;
627 return S_OK;
628}
629
630HRESULT SystemProperties::setDefaultMachineFolder(const com::Utf8Str &aDefaultMachineFolder)
631{
632 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
633 HRESULT rc = i_setDefaultMachineFolder(aDefaultMachineFolder);
634 alock.release();
635 if (SUCCEEDED(rc))
636 {
637 // VirtualBox::i_saveSettings() needs vbox write lock
638 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
639 rc = mParent->i_saveSettings();
640 }
641
642 return rc;
643}
644
645HRESULT SystemProperties::getLoggingLevel(com::Utf8Str &aLoggingLevel)
646{
647 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
648
649 aLoggingLevel = m->strLoggingLevel;
650
651 if (aLoggingLevel.isEmpty())
652 aLoggingLevel = VBOXSVC_LOG_DEFAULT;
653
654 return S_OK;
655}
656
657
658HRESULT SystemProperties::setLoggingLevel(const com::Utf8Str &aLoggingLevel)
659{
660 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
661 HRESULT rc = i_setLoggingLevel(aLoggingLevel);
662 alock.release();
663
664 if (SUCCEEDED(rc))
665 {
666 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
667 rc = mParent->i_saveSettings();
668 }
669 else
670 LogRel(("Cannot set passed logging level=%s, or the default one - Error=%Rhrc \n", aLoggingLevel.c_str(), rc));
671
672 return rc;
673}
674
675HRESULT SystemProperties::getMediumFormats(std::vector<ComPtr<IMediumFormat> > &aMediumFormats)
676{
677 MediumFormatList mediumFormats(m_llMediumFormats);
678 aMediumFormats.resize(mediumFormats.size());
679 size_t i = 0;
680 for (MediumFormatList::const_iterator it = mediumFormats.begin(); it != mediumFormats.end(); ++it, ++i)
681 (*it).queryInterfaceTo(aMediumFormats[i].asOutParam());
682 return S_OK;
683}
684
685HRESULT SystemProperties::getDefaultHardDiskFormat(com::Utf8Str &aDefaultHardDiskFormat)
686{
687 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
688 aDefaultHardDiskFormat = m->strDefaultHardDiskFormat;
689 return S_OK;
690}
691
692
693HRESULT SystemProperties::setDefaultHardDiskFormat(const com::Utf8Str &aDefaultHardDiskFormat)
694{
695 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
696 HRESULT rc = i_setDefaultHardDiskFormat(aDefaultHardDiskFormat);
697 alock.release();
698 if (SUCCEEDED(rc))
699 {
700 // VirtualBox::i_saveSettings() needs vbox write lock
701 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
702 rc = mParent->i_saveSettings();
703 }
704
705 return rc;
706}
707
708HRESULT SystemProperties::getFreeDiskSpaceWarning(LONG64 *aFreeSpace)
709{
710 NOREF(aFreeSpace);
711 ReturnComNotImplemented();
712}
713
714HRESULT SystemProperties::setFreeDiskSpaceWarning(LONG64 /* aFreeSpace */)
715{
716 ReturnComNotImplemented();
717}
718
719HRESULT SystemProperties::getFreeDiskSpacePercentWarning(ULONG *aFreeSpacePercent)
720{
721 NOREF(aFreeSpacePercent);
722 ReturnComNotImplemented();
723}
724
725HRESULT SystemProperties::setFreeDiskSpacePercentWarning(ULONG /* aFreeSpacePercent */)
726{
727 ReturnComNotImplemented();
728}
729
730HRESULT SystemProperties::getFreeDiskSpaceError(LONG64 *aFreeSpace)
731{
732 NOREF(aFreeSpace);
733 ReturnComNotImplemented();
734}
735
736HRESULT SystemProperties::setFreeDiskSpaceError(LONG64 /* aFreeSpace */)
737{
738 ReturnComNotImplemented();
739}
740
741HRESULT SystemProperties::getFreeDiskSpacePercentError(ULONG *aFreeSpacePercent)
742{
743 NOREF(aFreeSpacePercent);
744 ReturnComNotImplemented();
745}
746
747HRESULT SystemProperties::setFreeDiskSpacePercentError(ULONG /* aFreeSpacePercent */)
748{
749 ReturnComNotImplemented();
750}
751
752HRESULT SystemProperties::getVRDEAuthLibrary(com::Utf8Str &aVRDEAuthLibrary)
753{
754 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
755
756 aVRDEAuthLibrary = m->strVRDEAuthLibrary;
757
758 return S_OK;
759}
760
761HRESULT SystemProperties::setVRDEAuthLibrary(const com::Utf8Str &aVRDEAuthLibrary)
762{
763 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
764 HRESULT rc = i_setVRDEAuthLibrary(aVRDEAuthLibrary);
765 alock.release();
766 if (SUCCEEDED(rc))
767 {
768 // VirtualBox::i_saveSettings() needs vbox write lock
769 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
770 rc = mParent->i_saveSettings();
771 }
772
773 return rc;
774}
775
776HRESULT SystemProperties::getWebServiceAuthLibrary(com::Utf8Str &aWebServiceAuthLibrary)
777{
778 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
779
780 aWebServiceAuthLibrary = m->strWebServiceAuthLibrary;
781
782 return S_OK;
783}
784
785HRESULT SystemProperties::setWebServiceAuthLibrary(const com::Utf8Str &aWebServiceAuthLibrary)
786{
787 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
788 HRESULT rc = i_setWebServiceAuthLibrary(aWebServiceAuthLibrary);
789 alock.release();
790
791 if (SUCCEEDED(rc))
792 {
793 // VirtualBox::i_saveSettings() needs vbox write lock
794 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
795 rc = mParent->i_saveSettings();
796 }
797
798 return rc;
799}
800
801HRESULT SystemProperties::getDefaultVRDEExtPack(com::Utf8Str &aExtPack)
802{
803 HRESULT hrc = S_OK;
804 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
805 Utf8Str strExtPack(m->strDefaultVRDEExtPack);
806 if (strExtPack.isNotEmpty())
807 {
808 if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
809 hrc = S_OK;
810 else
811#ifdef VBOX_WITH_EXTPACK
812 hrc = mParent->i_getExtPackManager()->i_checkVrdeExtPack(&strExtPack);
813#else
814 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
815#endif
816 }
817 else
818 {
819#ifdef VBOX_WITH_EXTPACK
820 hrc = mParent->i_getExtPackManager()->i_getDefaultVrdeExtPack(&strExtPack);
821#endif
822 if (strExtPack.isEmpty())
823 {
824 /*
825 * Klugde - check if VBoxVRDP.dll/.so/.dylib is installed.
826 * This is hardcoded uglyness, sorry.
827 */
828 char szPath[RTPATH_MAX];
829 int vrc = RTPathAppPrivateArch(szPath, sizeof(szPath));
830 if (RT_SUCCESS(vrc))
831 vrc = RTPathAppend(szPath, sizeof(szPath), "VBoxVRDP");
832 if (RT_SUCCESS(vrc))
833 vrc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
834 if (RT_SUCCESS(vrc) && RTFileExists(szPath))
835 {
836 /* Illegal extpack name, so no conflict. */
837 strExtPack = VBOXVRDP_KLUDGE_EXTPACK_NAME;
838 }
839 }
840 }
841
842 if (SUCCEEDED(hrc))
843 aExtPack = strExtPack;
844
845 return S_OK;
846}
847
848
849HRESULT SystemProperties::setDefaultVRDEExtPack(const com::Utf8Str &aExtPack)
850{
851 HRESULT hrc = S_OK;
852 if (aExtPack.isNotEmpty())
853 {
854 if (aExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
855 hrc = S_OK;
856 else
857#ifdef VBOX_WITH_EXTPACK
858 hrc = mParent->i_getExtPackManager()->i_checkVrdeExtPack(&aExtPack);
859#else
860 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), aExtPack.c_str());
861#endif
862 }
863 if (SUCCEEDED(hrc))
864 {
865 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
866 hrc = i_setDefaultVRDEExtPack(aExtPack);
867 if (SUCCEEDED(hrc))
868 {
869 /* VirtualBox::i_saveSettings() needs the VirtualBox write lock. */
870 alock.release();
871 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
872 hrc = mParent->i_saveSettings();
873 }
874 }
875
876 return hrc;
877}
878
879
880HRESULT SystemProperties::getLogHistoryCount(ULONG *count)
881{
882 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
883
884 *count = m->uLogHistoryCount;
885
886 return S_OK;
887}
888
889
890HRESULT SystemProperties::setLogHistoryCount(ULONG count)
891{
892 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
893 m->uLogHistoryCount = count;
894 alock.release();
895
896 // VirtualBox::i_saveSettings() needs vbox write lock
897 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
898 HRESULT rc = mParent->i_saveSettings();
899
900 return rc;
901}
902
903HRESULT SystemProperties::getDefaultAudioDriver(AudioDriverType_T *aAudioDriver)
904{
905 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
906
907 *aAudioDriver = settings::MachineConfigFile::getHostDefaultAudioDriver();
908
909 return S_OK;
910}
911
912HRESULT SystemProperties::getAutostartDatabasePath(com::Utf8Str &aAutostartDbPath)
913{
914 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
915
916 aAutostartDbPath = m->strAutostartDatabasePath;
917
918 return S_OK;
919}
920
921HRESULT SystemProperties::setAutostartDatabasePath(const com::Utf8Str &aAutostartDbPath)
922{
923 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
924 HRESULT rc = i_setAutostartDatabasePath(aAutostartDbPath);
925 alock.release();
926
927 if (SUCCEEDED(rc))
928 {
929 // VirtualBox::i_saveSettings() needs vbox write lock
930 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
931 rc = mParent->i_saveSettings();
932 }
933
934 return rc;
935}
936
937HRESULT SystemProperties::getDefaultAdditionsISO(com::Utf8Str &aDefaultAdditionsISO)
938{
939 return i_getDefaultAdditionsISO(aDefaultAdditionsISO);
940}
941
942HRESULT SystemProperties::setDefaultAdditionsISO(const com::Utf8Str &aDefaultAdditionsISO)
943{
944 RT_NOREF(aDefaultAdditionsISO);
945 /** @todo not yet implemented, settings handling is missing */
946 ReturnComNotImplemented();
947#if 0 /* not implemented */
948 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
949 HRESULT rc = i_setDefaultAdditionsISO(aDefaultAdditionsISO);
950 alock.release();
951
952 if (SUCCEEDED(rc))
953 {
954 // VirtualBox::i_saveSettings() needs vbox write lock
955 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
956 rc = mParent->i_saveSettings();
957 }
958
959 return rc;
960#endif
961}
962
963HRESULT SystemProperties::getDefaultFrontend(com::Utf8Str &aDefaultFrontend)
964{
965 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
966 aDefaultFrontend = m->strDefaultFrontend;
967 return S_OK;
968}
969
970HRESULT SystemProperties::setDefaultFrontend(const com::Utf8Str &aDefaultFrontend)
971{
972 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
973 if (m->strDefaultFrontend == Utf8Str(aDefaultFrontend))
974 return S_OK;
975 HRESULT rc = i_setDefaultFrontend(aDefaultFrontend);
976 alock.release();
977
978 if (SUCCEEDED(rc))
979 {
980 // VirtualBox::i_saveSettings() needs vbox write lock
981 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
982 rc = mParent->i_saveSettings();
983 }
984
985 return rc;
986}
987
988HRESULT SystemProperties::getScreenShotFormats(std::vector<BitmapFormat_T> &aBitmapFormats)
989{
990 aBitmapFormats.push_back(BitmapFormat_BGR0);
991 aBitmapFormats.push_back(BitmapFormat_BGRA);
992 aBitmapFormats.push_back(BitmapFormat_RGBA);
993 aBitmapFormats.push_back(BitmapFormat_PNG);
994 return S_OK;
995}
996
997HRESULT SystemProperties::getProxyMode(ProxyMode_T *pProxyMode)
998{
999 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1000 ProxyMode_T enmMode = *pProxyMode = (ProxyMode_T)m->uProxyMode;
1001 AssertMsgReturn(enmMode == ProxyMode_System || enmMode == ProxyMode_NoProxy || enmMode == ProxyMode_Manual,
1002 ("enmMode=%d\n", enmMode), E_UNEXPECTED);
1003 return S_OK;
1004}
1005
1006HRESULT SystemProperties::setProxyMode(ProxyMode_T aProxyMode)
1007{
1008 /* Validate input. */
1009 switch (aProxyMode)
1010 {
1011 case ProxyMode_System:
1012 case ProxyMode_NoProxy:
1013 case ProxyMode_Manual:
1014 break;
1015 default:
1016 return setError(E_INVALIDARG, tr("Invalid ProxyMode value: %d"), (int)aProxyMode);
1017 }
1018
1019 /* Set and write out settings. */
1020 {
1021 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1022 m->uProxyMode = aProxyMode;
1023 }
1024 AutoWriteLock alock(mParent COMMA_LOCKVAL_SRC_POS); /* required for saving. */
1025 return mParent->i_saveSettings();
1026}
1027
1028HRESULT SystemProperties::getProxyURL(com::Utf8Str &aProxyURL)
1029{
1030 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1031 aProxyURL = m->strProxyUrl;
1032 return S_OK;
1033}
1034
1035HRESULT SystemProperties::setProxyURL(const com::Utf8Str &aProxyURL)
1036{
1037 /*
1038 * Validate input.
1039 */
1040 Utf8Str const *pStrProxyUrl = &aProxyURL;
1041 Utf8Str strTmp;
1042 if (pStrProxyUrl->isNotEmpty())
1043 {
1044 /* RTUriParse requires a scheme, so append 'http://' if none seems present: */
1045 if (pStrProxyUrl->find("://") == RTCString::npos)
1046 {
1047 strTmp.printf("http://%s", aProxyURL.c_str());
1048 pStrProxyUrl = &strTmp;
1049 }
1050
1051 /* Use RTUriParse to check the format. There must be a hostname, but nothing
1052 can follow it and the port. */
1053 RTURIPARSED Parsed;
1054 int vrc = RTUriParse(pStrProxyUrl->c_str(), &Parsed);
1055 if (RT_FAILURE(vrc))
1056 return setErrorBoth(E_INVALIDARG, vrc, tr("Failed to parse proxy URL: %Rrc"), vrc);
1057 if ( Parsed.cchAuthorityHost == 0
1058 && !RTUriIsSchemeMatch(pStrProxyUrl->c_str(), "direct"))
1059 return setError(E_INVALIDARG, tr("Proxy URL must include a hostname"));
1060 if (Parsed.cchPath > 0)
1061 return setError(E_INVALIDARG, tr("Proxy URL must not include a path component (%.*s)"),
1062 Parsed.cchPath, pStrProxyUrl->c_str() + Parsed.offPath);
1063 if (Parsed.cchQuery > 0)
1064 return setError(E_INVALIDARG, tr("Proxy URL must not include a query component (?%.*s)"),
1065 Parsed.cchQuery, pStrProxyUrl->c_str() + Parsed.offQuery);
1066 if (Parsed.cchFragment > 0)
1067 return setError(E_INVALIDARG, tr("Proxy URL must not include a fragment component (#%.*s)"),
1068 Parsed.cchFragment, pStrProxyUrl->c_str() + Parsed.offFragment);
1069 }
1070
1071 /*
1072 * Set and write out settings.
1073 */
1074 {
1075 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1076 m->strProxyUrl = *pStrProxyUrl;
1077 }
1078 AutoWriteLock alock(mParent COMMA_LOCKVAL_SRC_POS); /* required for saving. */
1079 return mParent->i_saveSettings();
1080}
1081
1082// public methods only for internal purposes
1083/////////////////////////////////////////////////////////////////////////////
1084
1085HRESULT SystemProperties::i_loadSettings(const settings::SystemProperties &data)
1086{
1087 AutoCaller autoCaller(this);
1088 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1089
1090 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1091 HRESULT rc = S_OK;
1092 rc = i_setDefaultMachineFolder(data.strDefaultMachineFolder);
1093 if (FAILED(rc)) return rc;
1094
1095 rc = i_setLoggingLevel(data.strLoggingLevel);
1096 if (FAILED(rc)) return rc;
1097
1098 rc = i_setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
1099 if (FAILED(rc)) return rc;
1100
1101 rc = i_setVRDEAuthLibrary(data.strVRDEAuthLibrary);
1102 if (FAILED(rc)) return rc;
1103
1104 rc = i_setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
1105 if (FAILED(rc)) return rc;
1106
1107 rc = i_setDefaultVRDEExtPack(data.strDefaultVRDEExtPack);
1108 if (FAILED(rc)) return rc;
1109
1110 m->uLogHistoryCount = data.uLogHistoryCount;
1111 m->fExclusiveHwVirt = data.fExclusiveHwVirt;
1112 m->uProxyMode = data.uProxyMode;
1113 m->strProxyUrl = data.strProxyUrl;
1114
1115 rc = i_setAutostartDatabasePath(data.strAutostartDatabasePath);
1116 if (FAILED(rc)) return rc;
1117
1118 {
1119 /* must ignore errors signalled here, because the guest additions
1120 * file may not exist, and in this case keep the empty string */
1121 ErrorInfoKeeper eik;
1122 (void)i_setDefaultAdditionsISO(data.strDefaultAdditionsISO);
1123 }
1124
1125 rc = i_setDefaultFrontend(data.strDefaultFrontend);
1126 if (FAILED(rc)) return rc;
1127
1128 return S_OK;
1129}
1130
1131HRESULT SystemProperties::i_saveSettings(settings::SystemProperties &data)
1132{
1133 AutoCaller autoCaller(this);
1134 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1135
1136 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1137
1138 data = *m;
1139
1140 return S_OK;
1141}
1142
1143/**
1144 * Returns a medium format object corresponding to the given format
1145 * identifier or null if no such format.
1146 *
1147 * @param aFormat Format identifier.
1148 *
1149 * @return ComObjPtr<MediumFormat>
1150 */
1151ComObjPtr<MediumFormat> SystemProperties::i_mediumFormat(const Utf8Str &aFormat)
1152{
1153 ComObjPtr<MediumFormat> format;
1154
1155 AutoCaller autoCaller(this);
1156 AssertComRCReturn (autoCaller.rc(), format);
1157
1158 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1159
1160 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
1161 it != m_llMediumFormats.end();
1162 ++ it)
1163 {
1164 /* MediumFormat is all const, no need to lock */
1165
1166 if ((*it)->i_getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
1167 {
1168 format = *it;
1169 break;
1170 }
1171 }
1172
1173 return format;
1174}
1175
1176/**
1177 * Returns a medium format object corresponding to the given file extension or
1178 * null if no such format.
1179 *
1180 * @param aExt File extension.
1181 *
1182 * @return ComObjPtr<MediumFormat>
1183 */
1184ComObjPtr<MediumFormat> SystemProperties::i_mediumFormatFromExtension(const Utf8Str &aExt)
1185{
1186 ComObjPtr<MediumFormat> format;
1187
1188 AutoCaller autoCaller(this);
1189 AssertComRCReturn (autoCaller.rc(), format);
1190
1191 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1192
1193 bool fFound = false;
1194 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
1195 it != m_llMediumFormats.end() && !fFound;
1196 ++it)
1197 {
1198 /* MediumFormat is all const, no need to lock */
1199 MediumFormat::StrArray aFileList = (*it)->i_getFileExtensions();
1200 for (MediumFormat::StrArray::const_iterator it1 = aFileList.begin();
1201 it1 != aFileList.end();
1202 ++it1)
1203 {
1204 if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0)
1205 {
1206 format = *it;
1207 fFound = true;
1208 break;
1209 }
1210 }
1211 }
1212
1213 return format;
1214}
1215
1216
1217/**
1218 * VD plugin load
1219 */
1220int SystemProperties::i_loadVDPlugin(const char *pszPluginLibrary)
1221{
1222 return VDPluginLoadFromFilename(pszPluginLibrary);
1223}
1224
1225/**
1226 * VD plugin unload
1227 */
1228int SystemProperties::i_unloadVDPlugin(const char *pszPluginLibrary)
1229{
1230 return VDPluginUnloadFromFilename(pszPluginLibrary);
1231}
1232
1233/**
1234 * Internally usable version of getDefaultAdditionsISO.
1235 */
1236HRESULT SystemProperties::i_getDefaultAdditionsISO(com::Utf8Str &aDefaultAdditionsISO)
1237{
1238 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1239 if (m->strDefaultAdditionsISO.isNotEmpty())
1240 aDefaultAdditionsISO = m->strDefaultAdditionsISO;
1241 else
1242 {
1243 /* no guest additions, check if it showed up in the mean time */
1244 alock.release();
1245 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS);
1246 if (m->strDefaultAdditionsISO.isEmpty())
1247 {
1248 ErrorInfoKeeper eik;
1249 (void)setDefaultAdditionsISO("");
1250 }
1251 aDefaultAdditionsISO = m->strDefaultAdditionsISO;
1252 }
1253 return S_OK;
1254}
1255
1256// private methods
1257/////////////////////////////////////////////////////////////////////////////
1258
1259/**
1260 * Returns the user's home directory. Wrapper around RTPathUserHome().
1261 * @param strPath
1262 * @return
1263 */
1264HRESULT SystemProperties::i_getUserHomeDirectory(Utf8Str &strPath)
1265{
1266 char szHome[RTPATH_MAX];
1267 int vrc = RTPathUserHome(szHome, sizeof(szHome));
1268 if (RT_FAILURE(vrc))
1269 return setErrorBoth(E_FAIL, vrc,
1270 tr("Cannot determine user home directory (%Rrc)"),
1271 vrc);
1272 strPath = szHome;
1273 return S_OK;
1274}
1275
1276/**
1277 * Internal implementation to set the default machine folder. Gets called
1278 * from the public attribute setter as well as loadSettings(). With 4.0,
1279 * the "default default" machine folder has changed, and we now require
1280 * a full path always.
1281 * @param strPath
1282 * @return
1283 */
1284HRESULT SystemProperties::i_setDefaultMachineFolder(const Utf8Str &strPath)
1285{
1286 Utf8Str path(strPath); // make modifiable
1287 if ( path.isEmpty() // used by API calls to reset the default
1288 || path == "Machines" // this value (exactly like this, without path) is stored
1289 // in VirtualBox.xml if user upgrades from before 4.0 and
1290 // has not changed the default machine folder
1291 )
1292 {
1293 // new default with VirtualBox 4.0: "$HOME/VirtualBox VMs"
1294 HRESULT rc = i_getUserHomeDirectory(path);
1295 if (FAILED(rc)) return rc;
1296 path += RTPATH_SLASH_STR "VirtualBox VMs";
1297 }
1298
1299 if (!RTPathStartsWithRoot(path.c_str()))
1300 return setError(E_INVALIDARG,
1301 tr("Given default machine folder '%s' is not fully qualified"),
1302 path.c_str());
1303
1304 m->strDefaultMachineFolder = path;
1305
1306 return S_OK;
1307}
1308
1309HRESULT SystemProperties::i_setLoggingLevel(const com::Utf8Str &aLoggingLevel)
1310{
1311 Utf8Str useLoggingLevel(aLoggingLevel);
1312 if (useLoggingLevel.isEmpty())
1313 useLoggingLevel = VBOXSVC_LOG_DEFAULT;
1314 int rc = RTLogGroupSettings(RTLogRelGetDefaultInstance(), useLoggingLevel.c_str());
1315 // If failed and not the default logging level - try to use the default logging level.
1316 if (RT_FAILURE(rc))
1317 {
1318 // If failed write message to the release log.
1319 LogRel(("Cannot set passed logging level=%s Error=%Rrc \n", useLoggingLevel.c_str(), rc));
1320 // If attempted logging level not the default one then try the default one.
1321 if (!useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT))
1322 {
1323 rc = RTLogGroupSettings(RTLogRelGetDefaultInstance(), VBOXSVC_LOG_DEFAULT);
1324 // If failed report this to the release log.
1325 if (RT_FAILURE(rc))
1326 LogRel(("Cannot set default logging level Error=%Rrc \n", rc));
1327 }
1328 // On any failure - set default level as the one to be stored.
1329 useLoggingLevel = VBOXSVC_LOG_DEFAULT;
1330 }
1331 // Set to passed value or if default used/attempted (even if error condition) use empty string.
1332 m->strLoggingLevel = (useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT) ? "" : useLoggingLevel);
1333 return RT_SUCCESS(rc) ? S_OK : E_FAIL;
1334}
1335
1336HRESULT SystemProperties::i_setDefaultHardDiskFormat(const com::Utf8Str &aFormat)
1337{
1338 if (!aFormat.isEmpty())
1339 m->strDefaultHardDiskFormat = aFormat;
1340 else
1341 m->strDefaultHardDiskFormat = "VDI";
1342
1343 return S_OK;
1344}
1345
1346HRESULT SystemProperties::i_setVRDEAuthLibrary(const com::Utf8Str &aPath)
1347{
1348 if (!aPath.isEmpty())
1349 m->strVRDEAuthLibrary = aPath;
1350 else
1351 m->strVRDEAuthLibrary = "VBoxAuth";
1352
1353 return S_OK;
1354}
1355
1356HRESULT SystemProperties::i_setWebServiceAuthLibrary(const com::Utf8Str &aPath)
1357{
1358 if (!aPath.isEmpty())
1359 m->strWebServiceAuthLibrary = aPath;
1360 else
1361 m->strWebServiceAuthLibrary = "VBoxAuth";
1362
1363 return S_OK;
1364}
1365
1366HRESULT SystemProperties::i_setDefaultVRDEExtPack(const com::Utf8Str &aExtPack)
1367{
1368 m->strDefaultVRDEExtPack = aExtPack;
1369
1370 return S_OK;
1371}
1372
1373HRESULT SystemProperties::i_setAutostartDatabasePath(const com::Utf8Str &aPath)
1374{
1375 HRESULT rc = S_OK;
1376 AutostartDb *autostartDb = this->mParent->i_getAutostartDb();
1377
1378 if (!aPath.isEmpty())
1379 {
1380 /* Update path in the autostart database. */
1381 int vrc = autostartDb->setAutostartDbPath(aPath.c_str());
1382 if (RT_SUCCESS(vrc))
1383 m->strAutostartDatabasePath = aPath;
1384 else
1385 rc = setErrorBoth(E_FAIL, vrc,
1386 tr("Cannot set the autostart database path (%Rrc)"),
1387 vrc);
1388 }
1389 else
1390 {
1391 int vrc = autostartDb->setAutostartDbPath(NULL);
1392 if (RT_SUCCESS(vrc) || vrc == VERR_NOT_SUPPORTED)
1393 m->strAutostartDatabasePath = "";
1394 else
1395 rc = setErrorBoth(E_FAIL, vrc,
1396 tr("Deleting the autostart database path failed (%Rrc)"),
1397 vrc);
1398 }
1399
1400 return rc;
1401}
1402
1403HRESULT SystemProperties::i_setDefaultAdditionsISO(const com::Utf8Str &aPath)
1404{
1405 com::Utf8Str path(aPath);
1406 if (path.isEmpty())
1407 {
1408 char strTemp[RTPATH_MAX];
1409 int vrc = RTPathAppPrivateNoArch(strTemp, sizeof(strTemp));
1410 AssertRC(vrc);
1411 Utf8Str strSrc1 = Utf8Str(strTemp).append("/VBoxGuestAdditions.iso");
1412
1413 vrc = RTPathExecDir(strTemp, sizeof(strTemp));
1414 AssertRC(vrc);
1415 Utf8Str strSrc2 = Utf8Str(strTemp).append("/additions/VBoxGuestAdditions.iso");
1416
1417 vrc = RTPathUserHome(strTemp, sizeof(strTemp));
1418 AssertRC(vrc);
1419 Utf8Str strSrc3 = Utf8StrFmt("%s/VBoxGuestAdditions_%s.iso", strTemp, VirtualBox::i_getVersionNormalized().c_str());
1420
1421 /* Check the standard image locations */
1422 if (RTFileExists(strSrc1.c_str()))
1423 path = strSrc1;
1424 else if (RTFileExists(strSrc2.c_str()))
1425 path = strSrc2;
1426 else if (RTFileExists(strSrc3.c_str()))
1427 path = strSrc3;
1428 else
1429 return setError(E_FAIL,
1430 tr("Cannot determine default Guest Additions ISO location. Most likely they are not available"));
1431 }
1432
1433 if (!RTPathStartsWithRoot(path.c_str()))
1434 return setError(E_INVALIDARG,
1435 tr("Given default machine Guest Additions ISO file '%s' is not fully qualified"),
1436 path.c_str());
1437
1438 if (!RTFileExists(path.c_str()))
1439 return setError(E_INVALIDARG,
1440 tr("Given default machine Guest Additions ISO file '%s' does not exist"),
1441 path.c_str());
1442
1443 m->strDefaultAdditionsISO = path;
1444
1445 return S_OK;
1446}
1447
1448HRESULT SystemProperties::i_setDefaultFrontend(const com::Utf8Str &aDefaultFrontend)
1449{
1450 m->strDefaultFrontend = aDefaultFrontend;
1451
1452 return S_OK;
1453}
1454
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