VirtualBox

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

Last change on this file since 49047 was 48985, checked in by vboxsync, 11 years ago

Main, Frontends: Make the port count of the SAS controller configurable and support up to 255 storage devices

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