VirtualBox

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

Last change on this file since 48983 was 48983, checked in by vboxsync, 12 years ago

Main,Frontends: Support for the USB storage controller

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette