VirtualBox

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

Last change on this file since 48914 was 48538, checked in by vboxsync, 11 years ago

Main/NetworkAdapter+Machine+Appliance+SystemProperties+Medium+Console+Settings+IDL: make NAT networking a separate network attachment type which improves the user experience, store the necessary settings, plus changing the design of the methods which will move images and entire VMs, they lacked a progress object
Frontends/VirtualBox: adapted fully, can configure NAT networks with proper drop down list support
Frontends/VBoxManage: also supports NAT networks completely, and adds the long missing code to list intnets

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.7 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 48538 2013-09-19 15:17:43Z 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 {
426 /* SATA and both SCSI controllers only support one device per port. */
427 *aMaxDevicesPerPort = 1;
428 break;
429 }
430 case StorageBus_IDE:
431 case StorageBus_Floppy:
432 {
433 /* The IDE and Floppy controllers support 2 devices. One as master
434 * and one as slave (or floppy drive 0 and 1). */
435 *aMaxDevicesPerPort = 2;
436 break;
437 }
438 default:
439 AssertMsgFailed(("Invalid bus type %d\n", aBus));
440 }
441
442 return S_OK;
443}
444
445STDMETHODIMP SystemProperties::GetMinPortCountForStorageBus(StorageBus_T aBus,
446 ULONG *aMinPortCount)
447{
448 CheckComArgOutPointerValid(aMinPortCount);
449
450 AutoCaller autoCaller(this);
451 if (FAILED(autoCaller.rc())) return autoCaller.rc();
452
453 /* no need to lock, this is const */
454 switch (aBus)
455 {
456 case StorageBus_SATA:
457 {
458 *aMinPortCount = 1;
459 break;
460 }
461 case StorageBus_SCSI:
462 {
463 *aMinPortCount = 16;
464 break;
465 }
466 case StorageBus_IDE:
467 {
468 *aMinPortCount = 2;
469 break;
470 }
471 case StorageBus_Floppy:
472 {
473 *aMinPortCount = 1;
474 break;
475 }
476 case StorageBus_SAS:
477 {
478 *aMinPortCount = 8;
479 break;
480 }
481 default:
482 AssertMsgFailed(("Invalid bus type %d\n", aBus));
483 }
484
485 return S_OK;
486}
487
488STDMETHODIMP SystemProperties::GetMaxPortCountForStorageBus(StorageBus_T aBus,
489 ULONG *aMaxPortCount)
490{
491 CheckComArgOutPointerValid(aMaxPortCount);
492
493 AutoCaller autoCaller(this);
494 if (FAILED(autoCaller.rc())) return autoCaller.rc();
495
496 /* no need to lock, this is const */
497 switch (aBus)
498 {
499 case StorageBus_SATA:
500 {
501 *aMaxPortCount = 30;
502 break;
503 }
504 case StorageBus_SCSI:
505 {
506 *aMaxPortCount = 16;
507 break;
508 }
509 case StorageBus_IDE:
510 {
511 *aMaxPortCount = 2;
512 break;
513 }
514 case StorageBus_Floppy:
515 {
516 *aMaxPortCount = 1;
517 break;
518 }
519 case StorageBus_SAS:
520 {
521 *aMaxPortCount = 8;
522 break;
523 }
524 default:
525 AssertMsgFailed(("Invalid bus type %d\n", aBus));
526 }
527
528 return S_OK;
529}
530
531STDMETHODIMP SystemProperties::GetMaxInstancesOfStorageBus(ChipsetType_T aChipset,
532 StorageBus_T aBus,
533 ULONG *aMaxInstances)
534{
535 CheckComArgOutPointerValid(aMaxInstances);
536
537 AutoCaller autoCaller(this);
538 if (FAILED(autoCaller.rc())) return autoCaller.rc();
539
540 ULONG cCtrs = 0;
541
542 /* no need to lock, this is const */
543 switch (aBus)
544 {
545 case StorageBus_SATA:
546 case StorageBus_SCSI:
547 case StorageBus_SAS:
548 cCtrs = aChipset == ChipsetType_ICH9 ? 8 : 1;
549 break;
550 case StorageBus_IDE:
551 case StorageBus_Floppy:
552 {
553 cCtrs = 1;
554 break;
555 }
556 default:
557 AssertMsgFailed(("Invalid bus type %d\n", aBus));
558 }
559
560 *aMaxInstances = cCtrs;
561
562 return S_OK;
563}
564
565STDMETHODIMP SystemProperties::GetDeviceTypesForStorageBus(StorageBus_T aBus,
566 ComSafeArrayOut(DeviceType_T, aDeviceTypes))
567{
568 CheckComArgOutSafeArrayPointerValid(aDeviceTypes);
569
570 AutoCaller autoCaller(this);
571 if (FAILED(autoCaller.rc())) return autoCaller.rc();
572
573 /* no need to lock, this is const */
574 switch (aBus)
575 {
576 case StorageBus_IDE:
577 case StorageBus_SATA:
578 case StorageBus_SCSI:
579 case StorageBus_SAS:
580 {
581 com::SafeArray<DeviceType_T> saDeviceTypes(2);
582 saDeviceTypes[0] = DeviceType_DVD;
583 saDeviceTypes[1] = DeviceType_HardDisk;
584 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
585 break;
586 }
587 case StorageBus_Floppy:
588 {
589 com::SafeArray<DeviceType_T> saDeviceTypes(1);
590 saDeviceTypes[0] = DeviceType_Floppy;
591 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
592 break;
593 }
594 default:
595 AssertMsgFailed(("Invalid bus type %d\n", aBus));
596 }
597
598 return S_OK;
599}
600
601STDMETHODIMP SystemProperties::GetDefaultIoCacheSettingForStorageController(StorageControllerType_T aControllerType, BOOL *aEnabled)
602{
603 CheckComArgOutPointerValid(aEnabled);
604
605 AutoCaller autoCaller(this);
606 if (FAILED(autoCaller.rc())) return autoCaller.rc();
607
608 /* no need to lock, this is const */
609 switch (aControllerType)
610 {
611 case StorageControllerType_LsiLogic:
612 case StorageControllerType_BusLogic:
613 case StorageControllerType_IntelAhci:
614 case StorageControllerType_LsiLogicSas:
615 *aEnabled = false;
616 break;
617 case StorageControllerType_PIIX3:
618 case StorageControllerType_PIIX4:
619 case StorageControllerType_ICH6:
620 case StorageControllerType_I82078:
621 *aEnabled = true;
622 break;
623 default:
624 AssertMsgFailed(("Invalid controller type %d\n", aControllerType));
625 }
626 return S_OK;
627}
628
629STDMETHODIMP SystemProperties::GetMaxInstancesOfUSBControllerType(ChipsetType_T aChipset,
630 USBControllerType_T aType,
631 ULONG *aMaxInstances)
632{
633 NOREF(aChipset);
634 CheckComArgOutPointerValid(aMaxInstances);
635
636 AutoCaller autoCaller(this);
637 if (FAILED(autoCaller.rc())) return autoCaller.rc();
638
639 ULONG cCtrs = 0;
640
641 /* no need to lock, this is const */
642 switch (aType)
643 {
644 case USBControllerType_OHCI:
645 case USBControllerType_EHCI:
646 {
647 cCtrs = 1;
648 break;
649 }
650 default:
651 AssertMsgFailed(("Invalid bus type %d\n", aType));
652 }
653
654 *aMaxInstances = cCtrs;
655
656 return S_OK;
657}
658
659STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder)(BSTR *aDefaultMachineFolder)
660{
661 CheckComArgOutPointerValid(aDefaultMachineFolder);
662
663 AutoCaller autoCaller(this);
664 if (FAILED(autoCaller.rc())) return autoCaller.rc();
665
666 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
667
668 m->strDefaultMachineFolder.cloneTo(aDefaultMachineFolder);
669
670 return S_OK;
671}
672
673STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder)(IN_BSTR aDefaultMachineFolder)
674{
675 AutoCaller autoCaller(this);
676 if (FAILED(autoCaller.rc())) return autoCaller.rc();
677
678 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
679 HRESULT rc = setDefaultMachineFolder(aDefaultMachineFolder);
680 alock.release();
681
682 if (SUCCEEDED(rc))
683 {
684 // VirtualBox::saveSettings() needs vbox write lock
685 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
686 rc = mParent->saveSettings();
687 }
688
689 return rc;
690}
691
692STDMETHODIMP SystemProperties::COMGETTER(LoggingLevel)(BSTR *aLoggingLevel)
693{
694 CheckComArgOutPointerValid(aLoggingLevel);
695
696 AutoCaller autoCaller(this);
697 if (FAILED(autoCaller.rc())) return autoCaller.rc();
698
699 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
700
701 Utf8Str useLoggingLevel(m->strLoggingLevel);
702 if (useLoggingLevel.isEmpty())
703 useLoggingLevel = VBOXSVC_LOG_DEFAULT;
704
705 useLoggingLevel.cloneTo(aLoggingLevel);
706 return S_OK;
707}
708
709
710STDMETHODIMP SystemProperties::COMSETTER(LoggingLevel)(IN_BSTR aLoggingLevel)
711{
712 AutoCaller autoCaller(this);
713 if (FAILED(autoCaller.rc())) return autoCaller.rc();
714
715 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
716 HRESULT rc = setLoggingLevel(aLoggingLevel);
717 alock.release();
718
719 if (SUCCEEDED(rc))
720 {
721 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
722 rc = mParent->saveSettings();
723 }
724 else
725 LogRel(("Cannot set passed logging level=%ls, or the default one - Error=%Rhrc \n", aLoggingLevel, rc));
726
727 return rc;
728}
729
730STDMETHODIMP SystemProperties::COMGETTER(MediumFormats)(ComSafeArrayOut(IMediumFormat *, aMediumFormats))
731{
732 CheckComArgOutSafeArrayPointerValid(aMediumFormats);
733
734 AutoCaller autoCaller(this);
735 if (FAILED(autoCaller.rc())) return autoCaller.rc();
736
737 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
738
739 SafeIfaceArray<IMediumFormat> mediumFormats(m_llMediumFormats);
740 mediumFormats.detachTo(ComSafeArrayOutArg(aMediumFormats));
741
742 return S_OK;
743}
744
745STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat)(BSTR *aDefaultHardDiskFormat)
746{
747 CheckComArgOutPointerValid(aDefaultHardDiskFormat);
748
749 AutoCaller autoCaller(this);
750 if (FAILED(autoCaller.rc())) return autoCaller.rc();
751
752 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
753
754 m->strDefaultHardDiskFormat.cloneTo(aDefaultHardDiskFormat);
755
756 return S_OK;
757}
758
759STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat)(IN_BSTR aDefaultHardDiskFormat)
760{
761 AutoCaller autoCaller(this);
762 if (FAILED(autoCaller.rc())) return autoCaller.rc();
763
764 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
765 HRESULT rc = setDefaultHardDiskFormat(aDefaultHardDiskFormat);
766 alock.release();
767
768 if (SUCCEEDED(rc))
769 {
770 // VirtualBox::saveSettings() needs vbox write lock
771 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
772 rc = mParent->saveSettings();
773 }
774
775 return rc;
776}
777
778STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceWarning)(LONG64 *aFreeSpace)
779{
780 CheckComArgOutPointerValid(aFreeSpace);
781
782 ReturnComNotImplemented();
783}
784
785STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceWarning)(LONG64 /* aFreeSpace */)
786{
787 ReturnComNotImplemented();
788}
789
790STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentWarning)(ULONG *aFreeSpacePercent)
791{
792 CheckComArgOutPointerValid(aFreeSpacePercent);
793
794 ReturnComNotImplemented();
795}
796
797STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentWarning)(ULONG /* aFreeSpacePercent */)
798{
799 ReturnComNotImplemented();
800}
801
802STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceError)(LONG64 *aFreeSpace)
803{
804 CheckComArgOutPointerValid(aFreeSpace);
805
806 ReturnComNotImplemented();
807}
808
809STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceError)(LONG64 /* aFreeSpace */)
810{
811 ReturnComNotImplemented();
812}
813
814STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentError)(ULONG *aFreeSpacePercent)
815{
816 CheckComArgOutPointerValid(aFreeSpacePercent);
817
818 ReturnComNotImplemented();
819}
820
821STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentError)(ULONG /* aFreeSpacePercent */)
822{
823 ReturnComNotImplemented();
824}
825
826STDMETHODIMP SystemProperties::COMGETTER(VRDEAuthLibrary)(BSTR *aVRDEAuthLibrary)
827{
828 CheckComArgOutPointerValid(aVRDEAuthLibrary);
829
830 AutoCaller autoCaller(this);
831 if (FAILED(autoCaller.rc())) return autoCaller.rc();
832
833 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
834
835 m->strVRDEAuthLibrary.cloneTo(aVRDEAuthLibrary);
836
837 return S_OK;
838}
839
840STDMETHODIMP SystemProperties::COMSETTER(VRDEAuthLibrary)(IN_BSTR aVRDEAuthLibrary)
841{
842 AutoCaller autoCaller(this);
843 if (FAILED(autoCaller.rc())) return autoCaller.rc();
844
845 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
846 HRESULT rc = setVRDEAuthLibrary(aVRDEAuthLibrary);
847 alock.release();
848
849 if (SUCCEEDED(rc))
850 {
851 // VirtualBox::saveSettings() needs vbox write lock
852 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
853 rc = mParent->saveSettings();
854 }
855
856 return rc;
857}
858
859STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary)(BSTR *aWebServiceAuthLibrary)
860{
861 CheckComArgOutPointerValid(aWebServiceAuthLibrary);
862
863 AutoCaller autoCaller(this);
864 if (FAILED(autoCaller.rc())) return autoCaller.rc();
865
866 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
867
868 m->strWebServiceAuthLibrary.cloneTo(aWebServiceAuthLibrary);
869
870 return S_OK;
871}
872
873STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary)(IN_BSTR aWebServiceAuthLibrary)
874{
875 AutoCaller autoCaller(this);
876 if (FAILED(autoCaller.rc())) return autoCaller.rc();
877
878 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
879 HRESULT rc = setWebServiceAuthLibrary(aWebServiceAuthLibrary);
880 alock.release();
881
882 if (SUCCEEDED(rc))
883 {
884 // VirtualBox::saveSettings() needs vbox write lock
885 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
886 rc = mParent->saveSettings();
887 }
888
889 return rc;
890}
891
892STDMETHODIMP SystemProperties::COMGETTER(DefaultVRDEExtPack)(BSTR *aExtPack)
893{
894 CheckComArgOutPointerValid(aExtPack);
895
896 AutoCaller autoCaller(this);
897 HRESULT hrc = autoCaller.rc();
898 if (SUCCEEDED(hrc))
899 {
900 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
901 Utf8Str strExtPack(m->strDefaultVRDEExtPack);
902 if (strExtPack.isNotEmpty())
903 {
904 if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
905 hrc = S_OK;
906 else
907#ifdef VBOX_WITH_EXTPACK
908 hrc = mParent->getExtPackManager()->checkVrdeExtPack(&strExtPack);
909#else
910 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
911#endif
912 }
913 else
914 {
915#ifdef VBOX_WITH_EXTPACK
916 hrc = mParent->getExtPackManager()->getDefaultVrdeExtPack(&strExtPack);
917#endif
918 if (strExtPack.isEmpty())
919 {
920 /*
921 * Klugde - check if VBoxVRDP.dll/.so/.dylib is installed.
922 * This is hardcoded uglyness, sorry.
923 */
924 char szPath[RTPATH_MAX];
925 int vrc = RTPathAppPrivateArch(szPath, sizeof(szPath));
926 if (RT_SUCCESS(vrc))
927 vrc = RTPathAppend(szPath, sizeof(szPath), "VBoxVRDP");
928 if (RT_SUCCESS(vrc))
929 vrc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
930 if (RT_SUCCESS(vrc) && RTFileExists(szPath))
931 {
932 /* Illegal extpack name, so no conflict. */
933 strExtPack = VBOXVRDP_KLUDGE_EXTPACK_NAME;
934 }
935 }
936 }
937
938 if (SUCCEEDED(hrc))
939 strExtPack.cloneTo(aExtPack);
940 }
941
942 return S_OK;
943}
944
945STDMETHODIMP SystemProperties::COMSETTER(DefaultVRDEExtPack)(IN_BSTR aExtPack)
946{
947 CheckComArgNotNull(aExtPack);
948 Utf8Str strExtPack(aExtPack);
949
950 AutoCaller autoCaller(this);
951 HRESULT hrc = autoCaller.rc();
952 if (SUCCEEDED(hrc))
953 {
954 if (strExtPack.isNotEmpty())
955 {
956 if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
957 hrc = S_OK;
958 else
959#ifdef VBOX_WITH_EXTPACK
960 hrc = mParent->getExtPackManager()->checkVrdeExtPack(&strExtPack);
961#else
962 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
963#endif
964 }
965 if (SUCCEEDED(hrc))
966 {
967 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
968 hrc = setDefaultVRDEExtPack(aExtPack);
969 if (SUCCEEDED(hrc))
970 {
971 /* VirtualBox::saveSettings() needs the VirtualBox write lock. */
972 alock.release();
973 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
974 hrc = mParent->saveSettings();
975 }
976 }
977 }
978
979 return hrc;
980}
981
982STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount)(ULONG *count)
983{
984 CheckComArgOutPointerValid(count);
985
986 AutoCaller autoCaller(this);
987 if (FAILED(autoCaller.rc())) return autoCaller.rc();
988
989 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
990
991 *count = m->ulLogHistoryCount;
992
993 return S_OK;
994}
995
996STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount)(ULONG count)
997{
998 AutoCaller autoCaller(this);
999 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1000
1001 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1002 m->ulLogHistoryCount = count;
1003 alock.release();
1004
1005 // VirtualBox::saveSettings() needs vbox write lock
1006 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
1007 HRESULT rc = mParent->saveSettings();
1008
1009 return rc;
1010}
1011
1012STDMETHODIMP SystemProperties::COMGETTER(DefaultAudioDriver)(AudioDriverType_T *aAudioDriver)
1013{
1014 CheckComArgOutPointerValid(aAudioDriver);
1015
1016 AutoCaller autoCaller(this);
1017 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1018
1019 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1020
1021 *aAudioDriver = settings::MachineConfigFile::getHostDefaultAudioDriver();
1022
1023 return S_OK;
1024}
1025
1026STDMETHODIMP SystemProperties::COMGETTER(AutostartDatabasePath)(BSTR *aAutostartDbPath)
1027{
1028 CheckComArgOutPointerValid(aAutostartDbPath);
1029
1030 AutoCaller autoCaller(this);
1031 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1032
1033 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1034
1035 m->strAutostartDatabasePath.cloneTo(aAutostartDbPath);
1036
1037 return S_OK;
1038}
1039
1040STDMETHODIMP SystemProperties::COMSETTER(AutostartDatabasePath)(IN_BSTR aAutostartDbPath)
1041{
1042 AutoCaller autoCaller(this);
1043 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1044
1045 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1046 HRESULT rc = setAutostartDatabasePath(aAutostartDbPath);
1047 alock.release();
1048
1049 if (SUCCEEDED(rc))
1050 {
1051 // VirtualBox::saveSettings() needs vbox write lock
1052 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
1053 rc = mParent->saveSettings();
1054 }
1055
1056 return rc;
1057}
1058
1059STDMETHODIMP SystemProperties::COMGETTER(DefaultAdditionsISO)(BSTR *aDefaultAdditionsISO)
1060{
1061 CheckComArgOutPointerValid(aDefaultAdditionsISO);
1062
1063 AutoCaller autoCaller(this);
1064 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1065
1066 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1067
1068 if (m->strDefaultAdditionsISO.isEmpty())
1069 {
1070 /* no guest additions, check if it showed up in the mean time */
1071 alock.release();
1072 {
1073 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS);
1074 ErrorInfoKeeper eik;
1075 (void)setDefaultAdditionsISO("");
1076 }
1077 alock.acquire();
1078 }
1079 m->strDefaultAdditionsISO.cloneTo(aDefaultAdditionsISO);
1080
1081 return S_OK;
1082}
1083
1084STDMETHODIMP SystemProperties::COMSETTER(DefaultAdditionsISO)(IN_BSTR aDefaultAdditionsISO)
1085{
1086 AutoCaller autoCaller(this);
1087 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1088
1089 /** @todo not yet implemented, settings handling is missing */
1090 ReturnComNotImplemented();
1091
1092 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1093 HRESULT rc = setDefaultAdditionsISO(aDefaultAdditionsISO);
1094 alock.release();
1095
1096 if (SUCCEEDED(rc))
1097 {
1098 // VirtualBox::saveSettings() needs vbox write lock
1099 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
1100 rc = mParent->saveSettings();
1101 }
1102
1103 return rc;
1104}
1105
1106STDMETHODIMP SystemProperties::COMGETTER(DefaultFrontend)(BSTR *aDefaultFrontend)
1107{
1108 CheckComArgOutPointerValid(aDefaultFrontend);
1109
1110 AutoCaller autoCaller(this);
1111 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1112
1113 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1114 m->strDefaultFrontend.cloneTo(aDefaultFrontend);
1115
1116 return S_OK;
1117}
1118
1119STDMETHODIMP SystemProperties::COMSETTER(DefaultFrontend)(IN_BSTR aDefaultFrontend)
1120{
1121 AutoCaller autoCaller(this);
1122 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1123
1124 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1125 if (m->strDefaultFrontend == Utf8Str(aDefaultFrontend))
1126 return S_OK;
1127 HRESULT rc = setDefaultFrontend(aDefaultFrontend);
1128 alock.release();
1129
1130 if (SUCCEEDED(rc))
1131 {
1132 // VirtualBox::saveSettings() needs vbox write lock
1133 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
1134 rc = mParent->saveSettings();
1135 }
1136
1137 return rc;
1138}
1139
1140// public methods only for internal purposes
1141/////////////////////////////////////////////////////////////////////////////
1142
1143HRESULT SystemProperties::loadSettings(const settings::SystemProperties &data)
1144{
1145 AutoCaller autoCaller(this);
1146 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1147
1148 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1149
1150 HRESULT rc = S_OK;
1151
1152 rc = setDefaultMachineFolder(data.strDefaultMachineFolder);
1153 if (FAILED(rc)) return rc;
1154
1155 rc = setLoggingLevel(data.strLoggingLevel);
1156 if (FAILED(rc)) return rc;
1157
1158 rc = setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
1159 if (FAILED(rc)) return rc;
1160
1161 rc = setVRDEAuthLibrary(data.strVRDEAuthLibrary);
1162 if (FAILED(rc)) return rc;
1163
1164 rc = setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
1165 if (FAILED(rc)) return rc;
1166
1167 rc = setDefaultVRDEExtPack(data.strDefaultVRDEExtPack);
1168 if (FAILED(rc)) return rc;
1169
1170 m->ulLogHistoryCount = data.ulLogHistoryCount;
1171 m->fExclusiveHwVirt = data.fExclusiveHwVirt;
1172
1173 rc = setAutostartDatabasePath(data.strAutostartDatabasePath);
1174 if (FAILED(rc)) return rc;
1175
1176 {
1177 /* must ignore errors signalled here, because the guest additions
1178 * file may not exist, and in this case keep the empty string */
1179 ErrorInfoKeeper eik;
1180 (void)setDefaultAdditionsISO(data.strDefaultAdditionsISO);
1181 }
1182
1183 rc = setDefaultFrontend(data.strDefaultFrontend);
1184 if (FAILED(rc)) return rc;
1185
1186 return S_OK;
1187}
1188
1189HRESULT SystemProperties::saveSettings(settings::SystemProperties &data)
1190{
1191 AutoCaller autoCaller(this);
1192 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1193
1194 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1195
1196 data = *m;
1197
1198 return S_OK;
1199}
1200
1201/**
1202 * Returns a medium format object corresponding to the given format
1203 * identifier or null if no such format.
1204 *
1205 * @param aFormat Format identifier.
1206 *
1207 * @return ComObjPtr<MediumFormat>
1208 */
1209ComObjPtr<MediumFormat> SystemProperties::mediumFormat(const Utf8Str &aFormat)
1210{
1211 ComObjPtr<MediumFormat> format;
1212
1213 AutoCaller autoCaller(this);
1214 AssertComRCReturn (autoCaller.rc(), format);
1215
1216 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1217
1218 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
1219 it != m_llMediumFormats.end();
1220 ++ it)
1221 {
1222 /* MediumFormat is all const, no need to lock */
1223
1224 if ((*it)->i_getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
1225 {
1226 format = *it;
1227 break;
1228 }
1229 }
1230
1231 return format;
1232}
1233
1234/**
1235 * Returns a medium format object corresponding to the given file extension or
1236 * null if no such format.
1237 *
1238 * @param aExt File extension.
1239 *
1240 * @return ComObjPtr<MediumFormat>
1241 */
1242ComObjPtr<MediumFormat> SystemProperties::mediumFormatFromExtension(const Utf8Str &aExt)
1243{
1244 ComObjPtr<MediumFormat> format;
1245
1246 AutoCaller autoCaller(this);
1247 AssertComRCReturn (autoCaller.rc(), format);
1248
1249 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1250
1251 bool fFound = false;
1252 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
1253 it != m_llMediumFormats.end() && !fFound;
1254 ++it)
1255 {
1256 /* MediumFormat is all const, no need to lock */
1257 MediumFormat::StrArray aFileList = (*it)->i_getFileExtensions();
1258 for (MediumFormat::StrArray::const_iterator it1 = aFileList.begin();
1259 it1 != aFileList.end();
1260 ++it1)
1261 {
1262 if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0)
1263 {
1264 format = *it;
1265 fFound = true;
1266 break;
1267 }
1268 }
1269 }
1270
1271 return format;
1272}
1273
1274// private methods
1275/////////////////////////////////////////////////////////////////////////////
1276
1277/**
1278 * Returns the user's home directory. Wrapper around RTPathUserHome().
1279 * @param strPath
1280 * @return
1281 */
1282HRESULT SystemProperties::getUserHomeDirectory(Utf8Str &strPath)
1283{
1284 char szHome[RTPATH_MAX];
1285 int vrc = RTPathUserHome(szHome, sizeof(szHome));
1286 if (RT_FAILURE(vrc))
1287 return setError(E_FAIL,
1288 tr("Cannot determine user home directory (%Rrc)"),
1289 vrc);
1290 strPath = szHome;
1291 return S_OK;
1292}
1293
1294/**
1295 * Internal implementation to set the default machine folder. Gets called
1296 * from the public attribute setter as well as loadSettings(). With 4.0,
1297 * the "default default" machine folder has changed, and we now require
1298 * a full path always.
1299 * @param aPath
1300 * @return
1301 */
1302HRESULT SystemProperties::setDefaultMachineFolder(const Utf8Str &strPath)
1303{
1304 Utf8Str path(strPath); // make modifiable
1305 if ( path.isEmpty() // used by API calls to reset the default
1306 || path == "Machines" // this value (exactly like this, without path) is stored
1307 // in VirtualBox.xml if user upgrades from before 4.0 and
1308 // has not changed the default machine folder
1309 )
1310 {
1311 // new default with VirtualBox 4.0: "$HOME/VirtualBox VMs"
1312 HRESULT rc = getUserHomeDirectory(path);
1313 if (FAILED(rc)) return rc;
1314 path += RTPATH_SLASH_STR "VirtualBox VMs";
1315 }
1316
1317 if (!RTPathStartsWithRoot(path.c_str()))
1318 return setError(E_INVALIDARG,
1319 tr("Given default machine folder '%s' is not fully qualified"),
1320 path.c_str());
1321
1322 m->strDefaultMachineFolder = path;
1323
1324 return S_OK;
1325}
1326
1327HRESULT SystemProperties::setLoggingLevel(const Utf8Str &aLoggingLevel)
1328{
1329 Utf8Str useLoggingLevel(aLoggingLevel);
1330 int rc = RTLogGroupSettings(RTLogRelDefaultInstance(), useLoggingLevel.c_str());
1331 // If failed and not the default logging level - try to use the default logging level.
1332 if (RT_FAILURE(rc))
1333 {
1334 // If failed write message to the release log.
1335 LogRel(("Cannot set passed logging level=%s Error=%Rrc \n", useLoggingLevel.c_str(), rc));
1336 // If attempted logging level not the default one then try the default one.
1337 if (!useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT))
1338 {
1339 rc = RTLogGroupSettings(RTLogRelDefaultInstance(), VBOXSVC_LOG_DEFAULT);
1340 // If failed report this to the release log.
1341 if (RT_FAILURE(rc))
1342 LogRel(("Cannot set default logging level Error=%Rrc \n", rc));
1343 }
1344 // On any failure - set default level as the one to be stored.
1345 useLoggingLevel = VBOXSVC_LOG_DEFAULT;
1346 }
1347 // Set to passed value or if default used/attempted (even if error condition) use empty string.
1348 m->strLoggingLevel = (useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT) ? "" : useLoggingLevel);
1349 return RT_SUCCESS(rc) ? S_OK : E_FAIL;
1350}
1351
1352HRESULT SystemProperties::setDefaultHardDiskFormat(const Utf8Str &aFormat)
1353{
1354 if (!aFormat.isEmpty())
1355 m->strDefaultHardDiskFormat = aFormat;
1356 else
1357 m->strDefaultHardDiskFormat = "VDI";
1358
1359 return S_OK;
1360}
1361
1362HRESULT SystemProperties::setVRDEAuthLibrary(const Utf8Str &aPath)
1363{
1364 if (!aPath.isEmpty())
1365 m->strVRDEAuthLibrary = aPath;
1366 else
1367 m->strVRDEAuthLibrary = "VBoxAuth";
1368
1369 return S_OK;
1370}
1371
1372HRESULT SystemProperties::setWebServiceAuthLibrary(const Utf8Str &aPath)
1373{
1374 if (!aPath.isEmpty())
1375 m->strWebServiceAuthLibrary = aPath;
1376 else
1377 m->strWebServiceAuthLibrary = "VBoxAuth";
1378
1379 return S_OK;
1380}
1381
1382HRESULT SystemProperties::setDefaultVRDEExtPack(const Utf8Str &aExtPack)
1383{
1384 m->strDefaultVRDEExtPack = aExtPack;
1385
1386 return S_OK;
1387}
1388
1389HRESULT SystemProperties::setAutostartDatabasePath(const Utf8Str &aPath)
1390{
1391 HRESULT rc = S_OK;
1392 AutostartDb *autostartDb = this->mParent->getAutostartDb();
1393
1394 if (!aPath.isEmpty())
1395 {
1396 /* Update path in the autostart database. */
1397 int vrc = autostartDb->setAutostartDbPath(aPath.c_str());
1398 if (RT_SUCCESS(vrc))
1399 m->strAutostartDatabasePath = aPath;
1400 else
1401 rc = setError(E_FAIL,
1402 tr("Cannot set the autostart database path (%Rrc)"),
1403 vrc);
1404 }
1405 else
1406 {
1407 int vrc = autostartDb->setAutostartDbPath(NULL);
1408 if (RT_SUCCESS(vrc) || vrc == VERR_NOT_SUPPORTED)
1409 m->strAutostartDatabasePath = "";
1410 else
1411 rc = setError(E_FAIL,
1412 tr("Deleting the autostart database path failed (%Rrc)"),
1413 vrc);
1414 }
1415
1416 return rc;
1417}
1418
1419HRESULT SystemProperties::setDefaultAdditionsISO(const Utf8Str &aPath)
1420{
1421 Utf8Str path(aPath);
1422 if (path.isEmpty())
1423 {
1424 char strTemp[RTPATH_MAX];
1425 int vrc = RTPathAppPrivateNoArch(strTemp, sizeof(strTemp));
1426 AssertRC(vrc);
1427 Utf8Str strSrc1 = Utf8Str(strTemp).append("/VBoxGuestAdditions.iso");
1428
1429 vrc = RTPathExecDir(strTemp, sizeof(strTemp));
1430 AssertRC(vrc);
1431 Utf8Str strSrc2 = Utf8Str(strTemp).append("/additions/VBoxGuestAdditions.iso");
1432
1433 vrc = RTPathUserHome(strTemp, sizeof(strTemp));
1434 AssertRC(vrc);
1435 Utf8Str strSrc3 = Utf8StrFmt("%s/VBoxGuestAdditions_%ls.iso", strTemp, VirtualBox::getVersionNormalized().raw());
1436
1437 /* Check the standard image locations */
1438 if (RTFileExists(strSrc1.c_str()))
1439 path = strSrc1;
1440 else if (RTFileExists(strSrc2.c_str()))
1441 path = strSrc2;
1442 else if (RTFileExists(strSrc3.c_str()))
1443 path = strSrc3;
1444 else
1445 return setError(E_FAIL,
1446 tr("Cannot determine default Guest Additions ISO location. Most likely they are not available"));
1447 }
1448
1449 if (!RTPathStartsWithRoot(path.c_str()))
1450 return setError(E_INVALIDARG,
1451 tr("Given default machine Guest Additions ISO file '%s' is not fully qualified"),
1452 path.c_str());
1453
1454 if (!RTFileExists(path.c_str()))
1455 return setError(E_INVALIDARG,
1456 tr("Given default machine Guest Additions ISO file '%s' does not exist"),
1457 path.c_str());
1458
1459 m->strDefaultAdditionsISO = path;
1460
1461 return S_OK;
1462}
1463
1464HRESULT SystemProperties::setDefaultFrontend(const Utf8Str &aDefaultFrontend)
1465{
1466 m->strDefaultFrontend = aDefaultFrontend;
1467
1468 return S_OK;
1469}
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