VirtualBox

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

Last change on this file since 76092 was 74431, checked in by vboxsync, 6 years ago

Main,GUI,VBoxManage: Provide API for proxy settings that picks up the current GUI settings and converts it to SystemProperties XML attributes. Adjusted GUI to use it. Updated VBoxMangage system properties handling accordingly. bugref:9249

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