1 | /* $Id: SystemPropertiesImpl.cpp 39248 2011-11-09 12:29:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VirtualBox COM class implementation
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2011 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "SystemPropertiesImpl.h"
|
---|
20 | #include "VirtualBoxImpl.h"
|
---|
21 | #include "MachineImpl.h"
|
---|
22 | #ifdef VBOX_WITH_EXTPACK
|
---|
23 | # include "ExtPackManagerImpl.h"
|
---|
24 | #endif
|
---|
25 | #include "AutoCaller.h"
|
---|
26 | #include "Global.h"
|
---|
27 | #include "Logging.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 |
|
---|
49 | SystemProperties::SystemProperties()
|
---|
50 | : mParent(NULL),
|
---|
51 | m(new settings::SystemProperties)
|
---|
52 | {
|
---|
53 | }
|
---|
54 |
|
---|
55 | SystemProperties::~SystemProperties()
|
---|
56 | {
|
---|
57 | delete m;
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | HRESULT SystemProperties::FinalConstruct()
|
---|
62 | {
|
---|
63 | return BaseFinalConstruct();
|
---|
64 | }
|
---|
65 |
|
---|
66 | void 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 | */
|
---|
80 | HRESULT 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 | setDefaultHardDiskFormat(Utf8Str::Empty);
|
---|
94 |
|
---|
95 | setVRDEAuthLibrary(Utf8Str::Empty);
|
---|
96 | setDefaultVRDEExtPack(Utf8Str::Empty);
|
---|
97 |
|
---|
98 | m->ulLogHistoryCount = 3;
|
---|
99 |
|
---|
100 | HRESULT rc = S_OK;
|
---|
101 |
|
---|
102 | /* Fetch info of all available hd backends. */
|
---|
103 |
|
---|
104 | /// @todo NEWMEDIA VDBackendInfo needs to be improved to let us enumerate
|
---|
105 | /// any number of backends
|
---|
106 |
|
---|
107 | VDBACKENDINFO aVDInfo[100];
|
---|
108 | unsigned cEntries;
|
---|
109 | int vrc = VDBackendInfo(RT_ELEMENTS(aVDInfo), aVDInfo, &cEntries);
|
---|
110 | AssertRC(vrc);
|
---|
111 | if (RT_SUCCESS(vrc))
|
---|
112 | {
|
---|
113 | for (unsigned i = 0; i < cEntries; ++ i)
|
---|
114 | {
|
---|
115 | ComObjPtr<MediumFormat> hdf;
|
---|
116 | rc = hdf.createObject();
|
---|
117 | if (FAILED(rc)) break;
|
---|
118 |
|
---|
119 | rc = hdf->init(&aVDInfo[i]);
|
---|
120 | if (FAILED(rc)) break;
|
---|
121 |
|
---|
122 | m_llMediumFormats.push_back(hdf);
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | /* Confirm a successful initialization */
|
---|
127 | if (SUCCEEDED(rc))
|
---|
128 | autoInitSpan.setSucceeded();
|
---|
129 |
|
---|
130 | return rc;
|
---|
131 | }
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
135 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
136 | */
|
---|
137 | void SystemProperties::uninit()
|
---|
138 | {
|
---|
139 | LogFlowThisFunc(("\n"));
|
---|
140 |
|
---|
141 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
142 | AutoUninitSpan autoUninitSpan(this);
|
---|
143 | if (autoUninitSpan.uninitDone())
|
---|
144 | return;
|
---|
145 |
|
---|
146 | unconst(mParent) = NULL;
|
---|
147 | }
|
---|
148 |
|
---|
149 | // ISystemProperties properties
|
---|
150 | /////////////////////////////////////////////////////////////////////////////
|
---|
151 |
|
---|
152 |
|
---|
153 | STDMETHODIMP SystemProperties::COMGETTER(MinGuestRAM)(ULONG *minRAM)
|
---|
154 | {
|
---|
155 | CheckComArgOutPointerValid(minRAM);
|
---|
156 |
|
---|
157 | AutoCaller autoCaller(this);
|
---|
158 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
159 |
|
---|
160 | /* no need to lock, this is const */
|
---|
161 | AssertCompile(MM_RAM_MIN_IN_MB >= SchemaDefs::MinGuestRAM);
|
---|
162 | *minRAM = MM_RAM_MIN_IN_MB;
|
---|
163 |
|
---|
164 | return S_OK;
|
---|
165 | }
|
---|
166 |
|
---|
167 | STDMETHODIMP SystemProperties::COMGETTER(MaxGuestRAM)(ULONG *maxRAM)
|
---|
168 | {
|
---|
169 | CheckComArgOutPointerValid(maxRAM);
|
---|
170 |
|
---|
171 | AutoCaller autoCaller(this);
|
---|
172 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
173 |
|
---|
174 | /* no need to lock, this is const */
|
---|
175 | AssertCompile(MM_RAM_MAX_IN_MB <= SchemaDefs::MaxGuestRAM);
|
---|
176 | ULONG maxRAMSys = MM_RAM_MAX_IN_MB;
|
---|
177 | ULONG maxRAMArch = maxRAMSys;
|
---|
178 | *maxRAM = RT_MIN(maxRAMSys, maxRAMArch);
|
---|
179 |
|
---|
180 | return S_OK;
|
---|
181 | }
|
---|
182 |
|
---|
183 | STDMETHODIMP SystemProperties::COMGETTER(MinGuestVRAM)(ULONG *minVRAM)
|
---|
184 | {
|
---|
185 | CheckComArgOutPointerValid(minVRAM);
|
---|
186 |
|
---|
187 | AutoCaller autoCaller(this);
|
---|
188 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
189 |
|
---|
190 | /* no need to lock, this is const */
|
---|
191 | *minVRAM = SchemaDefs::MinGuestVRAM;
|
---|
192 |
|
---|
193 | return S_OK;
|
---|
194 | }
|
---|
195 |
|
---|
196 | STDMETHODIMP SystemProperties::COMGETTER(MaxGuestVRAM)(ULONG *maxVRAM)
|
---|
197 | {
|
---|
198 | CheckComArgOutPointerValid(maxVRAM);
|
---|
199 |
|
---|
200 | AutoCaller autoCaller(this);
|
---|
201 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
202 |
|
---|
203 | /* no need to lock, this is const */
|
---|
204 | *maxVRAM = SchemaDefs::MaxGuestVRAM;
|
---|
205 |
|
---|
206 | return S_OK;
|
---|
207 | }
|
---|
208 |
|
---|
209 | STDMETHODIMP SystemProperties::COMGETTER(MinGuestCPUCount)(ULONG *minCPUCount)
|
---|
210 | {
|
---|
211 | CheckComArgOutPointerValid(minCPUCount);
|
---|
212 |
|
---|
213 | AutoCaller autoCaller(this);
|
---|
214 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
215 |
|
---|
216 | /* no need to lock, this is const */
|
---|
217 | *minCPUCount = SchemaDefs::MinCPUCount; // VMM_MIN_CPU_COUNT
|
---|
218 |
|
---|
219 | return S_OK;
|
---|
220 | }
|
---|
221 |
|
---|
222 | STDMETHODIMP SystemProperties::COMGETTER(MaxGuestCPUCount)(ULONG *maxCPUCount)
|
---|
223 | {
|
---|
224 | CheckComArgOutPointerValid(maxCPUCount);
|
---|
225 |
|
---|
226 | AutoCaller autoCaller(this);
|
---|
227 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
228 |
|
---|
229 | /* no need to lock, this is const */
|
---|
230 | *maxCPUCount = SchemaDefs::MaxCPUCount; // VMM_MAX_CPU_COUNT
|
---|
231 |
|
---|
232 | return S_OK;
|
---|
233 | }
|
---|
234 |
|
---|
235 | STDMETHODIMP SystemProperties::COMGETTER(MaxGuestMonitors)(ULONG *maxMonitors)
|
---|
236 | {
|
---|
237 | CheckComArgOutPointerValid(maxMonitors);
|
---|
238 |
|
---|
239 | AutoCaller autoCaller(this);
|
---|
240 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
241 |
|
---|
242 | /* no need to lock, this is const */
|
---|
243 | *maxMonitors = SchemaDefs::MaxGuestMonitors;
|
---|
244 |
|
---|
245 | return S_OK;
|
---|
246 | }
|
---|
247 |
|
---|
248 | STDMETHODIMP SystemProperties::COMGETTER(InfoVDSize)(LONG64 *infoVDSize)
|
---|
249 | {
|
---|
250 | CheckComArgOutPointerValid(infoVDSize);
|
---|
251 |
|
---|
252 | AutoCaller autoCaller(this);
|
---|
253 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
254 |
|
---|
255 | /*
|
---|
256 | * The BIOS supports currently 32 bit LBA numbers (implementing the full
|
---|
257 | * 48 bit range is in theory trivial, but the crappy compiler makes things
|
---|
258 | * more difficult). This translates to almost 2 TiBytes (to be on the safe
|
---|
259 | * side, the reported limit is 1 MiByte less than that, as the total number
|
---|
260 | * of sectors should fit in 32 bits, too), which should be enough for the
|
---|
261 | * moment. Since the MBR partition tables support only 32bit sector numbers
|
---|
262 | * and thus the BIOS can only boot from disks smaller than 2T this is a
|
---|
263 | * rather hard limit.
|
---|
264 | *
|
---|
265 | * The virtual ATA/SATA disks support complete LBA48, and SCSI supports
|
---|
266 | * LBA64 (almost, more like LBA55 in practice), so the theoretical maximum
|
---|
267 | * disk size is 128 PiByte/16 EiByte. The GUI works nicely with 6 orders
|
---|
268 | * of magnitude, but not with 11..13 orders of magnitude.
|
---|
269 | */
|
---|
270 | /* no need to lock, this is const */
|
---|
271 | *infoVDSize = 2 * _1T - _1M;
|
---|
272 |
|
---|
273 | return S_OK;
|
---|
274 | }
|
---|
275 |
|
---|
276 | STDMETHODIMP SystemProperties::COMGETTER(SerialPortCount)(ULONG *count)
|
---|
277 | {
|
---|
278 | CheckComArgOutPointerValid(count);
|
---|
279 |
|
---|
280 | AutoCaller autoCaller(this);
|
---|
281 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
282 |
|
---|
283 | /* no need to lock, this is const */
|
---|
284 | *count = SchemaDefs::SerialPortCount;
|
---|
285 |
|
---|
286 | return S_OK;
|
---|
287 | }
|
---|
288 |
|
---|
289 | STDMETHODIMP SystemProperties::COMGETTER(ParallelPortCount)(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::ParallelPortCount;
|
---|
298 |
|
---|
299 | return S_OK;
|
---|
300 | }
|
---|
301 |
|
---|
302 | STDMETHODIMP SystemProperties::COMGETTER(MaxBootPosition)(ULONG *aMaxBootPosition)
|
---|
303 | {
|
---|
304 | CheckComArgOutPointerValid(aMaxBootPosition);
|
---|
305 |
|
---|
306 | AutoCaller autoCaller(this);
|
---|
307 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
308 |
|
---|
309 | /* no need to lock, this is const */
|
---|
310 | *aMaxBootPosition = SchemaDefs::MaxBootPosition;
|
---|
311 |
|
---|
312 | return S_OK;
|
---|
313 | }
|
---|
314 |
|
---|
315 |
|
---|
316 | STDMETHODIMP SystemProperties::GetMaxNetworkAdapters(ChipsetType_T aChipset, ULONG *count)
|
---|
317 | {
|
---|
318 | CheckComArgOutPointerValid(count);
|
---|
319 |
|
---|
320 | AutoCaller autoCaller(this);
|
---|
321 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
322 |
|
---|
323 | /* no need for locking, no state */
|
---|
324 | uint32_t uResult = Global::getMaxNetworkAdapters(aChipset);
|
---|
325 | if (uResult == 0)
|
---|
326 | AssertMsgFailed(("Invalid chipset type %d\n", aChipset));
|
---|
327 |
|
---|
328 | *count = uResult;
|
---|
329 |
|
---|
330 | return S_OK;
|
---|
331 | }
|
---|
332 |
|
---|
333 | STDMETHODIMP SystemProperties::GetMaxNetworkAdaptersOfType(ChipsetType_T aChipset, NetworkAttachmentType_T aType, ULONG *count)
|
---|
334 | {
|
---|
335 | CheckComArgOutPointerValid(count);
|
---|
336 |
|
---|
337 | AutoCaller autoCaller(this);
|
---|
338 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
339 |
|
---|
340 | /* no need for locking, no state */
|
---|
341 | uint32_t uResult = Global::getMaxNetworkAdapters(aChipset);
|
---|
342 | if (uResult == 0)
|
---|
343 | AssertMsgFailed(("Invalid chipset type %d\n", aChipset));
|
---|
344 |
|
---|
345 | switch (aType)
|
---|
346 | {
|
---|
347 | case NetworkAttachmentType_NAT:
|
---|
348 | case NetworkAttachmentType_Internal:
|
---|
349 | /* chipset default is OK */
|
---|
350 | break;
|
---|
351 | case NetworkAttachmentType_Bridged:
|
---|
352 | /* Maybe use current host interface count here? */
|
---|
353 | break;
|
---|
354 | case NetworkAttachmentType_HostOnly:
|
---|
355 | uResult = RT_MIN(uResult, 8);
|
---|
356 | break;
|
---|
357 | default:
|
---|
358 | AssertMsgFailed(("Unhandled attachment type %d\n", aType));
|
---|
359 | }
|
---|
360 |
|
---|
361 | *count = uResult;
|
---|
362 |
|
---|
363 | return S_OK;
|
---|
364 | }
|
---|
365 |
|
---|
366 |
|
---|
367 | STDMETHODIMP SystemProperties::GetMaxDevicesPerPortForStorageBus(StorageBus_T aBus,
|
---|
368 | ULONG *aMaxDevicesPerPort)
|
---|
369 | {
|
---|
370 | CheckComArgOutPointerValid(aMaxDevicesPerPort);
|
---|
371 |
|
---|
372 | AutoCaller autoCaller(this);
|
---|
373 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
374 |
|
---|
375 | /* no need to lock, this is const */
|
---|
376 | switch (aBus)
|
---|
377 | {
|
---|
378 | case StorageBus_SATA:
|
---|
379 | case StorageBus_SCSI:
|
---|
380 | case StorageBus_SAS:
|
---|
381 | {
|
---|
382 | /* SATA and both SCSI controllers only support one device per port. */
|
---|
383 | *aMaxDevicesPerPort = 1;
|
---|
384 | break;
|
---|
385 | }
|
---|
386 | case StorageBus_IDE:
|
---|
387 | case StorageBus_Floppy:
|
---|
388 | {
|
---|
389 | /* The IDE and Floppy controllers support 2 devices. One as master
|
---|
390 | * and one as slave (or floppy drive 0 and 1). */
|
---|
391 | *aMaxDevicesPerPort = 2;
|
---|
392 | break;
|
---|
393 | }
|
---|
394 | default:
|
---|
395 | AssertMsgFailed(("Invalid bus type %d\n", aBus));
|
---|
396 | }
|
---|
397 |
|
---|
398 | return S_OK;
|
---|
399 | }
|
---|
400 |
|
---|
401 | STDMETHODIMP SystemProperties::GetMinPortCountForStorageBus(StorageBus_T aBus,
|
---|
402 | ULONG *aMinPortCount)
|
---|
403 | {
|
---|
404 | CheckComArgOutPointerValid(aMinPortCount);
|
---|
405 |
|
---|
406 | AutoCaller autoCaller(this);
|
---|
407 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
408 |
|
---|
409 | /* no need to lock, this is const */
|
---|
410 | switch (aBus)
|
---|
411 | {
|
---|
412 | case StorageBus_SATA:
|
---|
413 | {
|
---|
414 | *aMinPortCount = 1;
|
---|
415 | break;
|
---|
416 | }
|
---|
417 | case StorageBus_SCSI:
|
---|
418 | {
|
---|
419 | *aMinPortCount = 16;
|
---|
420 | break;
|
---|
421 | }
|
---|
422 | case StorageBus_IDE:
|
---|
423 | {
|
---|
424 | *aMinPortCount = 2;
|
---|
425 | break;
|
---|
426 | }
|
---|
427 | case StorageBus_Floppy:
|
---|
428 | {
|
---|
429 | *aMinPortCount = 1;
|
---|
430 | break;
|
---|
431 | }
|
---|
432 | case StorageBus_SAS:
|
---|
433 | {
|
---|
434 | *aMinPortCount = 8;
|
---|
435 | break;
|
---|
436 | }
|
---|
437 | default:
|
---|
438 | AssertMsgFailed(("Invalid bus type %d\n", aBus));
|
---|
439 | }
|
---|
440 |
|
---|
441 | return S_OK;
|
---|
442 | }
|
---|
443 |
|
---|
444 | STDMETHODIMP SystemProperties::GetMaxPortCountForStorageBus(StorageBus_T aBus,
|
---|
445 | ULONG *aMaxPortCount)
|
---|
446 | {
|
---|
447 | CheckComArgOutPointerValid(aMaxPortCount);
|
---|
448 |
|
---|
449 | AutoCaller autoCaller(this);
|
---|
450 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
451 |
|
---|
452 | /* no need to lock, this is const */
|
---|
453 | switch (aBus)
|
---|
454 | {
|
---|
455 | case StorageBus_SATA:
|
---|
456 | {
|
---|
457 | *aMaxPortCount = 30;
|
---|
458 | break;
|
---|
459 | }
|
---|
460 | case StorageBus_SCSI:
|
---|
461 | {
|
---|
462 | *aMaxPortCount = 16;
|
---|
463 | break;
|
---|
464 | }
|
---|
465 | case StorageBus_IDE:
|
---|
466 | {
|
---|
467 | *aMaxPortCount = 2;
|
---|
468 | break;
|
---|
469 | }
|
---|
470 | case StorageBus_Floppy:
|
---|
471 | {
|
---|
472 | *aMaxPortCount = 1;
|
---|
473 | break;
|
---|
474 | }
|
---|
475 | case StorageBus_SAS:
|
---|
476 | {
|
---|
477 | *aMaxPortCount = 8;
|
---|
478 | break;
|
---|
479 | }
|
---|
480 | default:
|
---|
481 | AssertMsgFailed(("Invalid bus type %d\n", aBus));
|
---|
482 | }
|
---|
483 |
|
---|
484 | return S_OK;
|
---|
485 | }
|
---|
486 |
|
---|
487 | STDMETHODIMP SystemProperties::GetMaxInstancesOfStorageBus(ChipsetType_T aChipset,
|
---|
488 | StorageBus_T aBus,
|
---|
489 | ULONG *aMaxInstances)
|
---|
490 | {
|
---|
491 | CheckComArgOutPointerValid(aMaxInstances);
|
---|
492 |
|
---|
493 | AutoCaller autoCaller(this);
|
---|
494 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
495 |
|
---|
496 | ULONG cCtrs = 0;
|
---|
497 |
|
---|
498 | /* no need to lock, this is const */
|
---|
499 | switch (aBus)
|
---|
500 | {
|
---|
501 | case StorageBus_SATA:
|
---|
502 | case StorageBus_SCSI:
|
---|
503 | case StorageBus_SAS:
|
---|
504 | cCtrs = aChipset == ChipsetType_ICH9 ? 8 : 1;
|
---|
505 | break;
|
---|
506 | case StorageBus_IDE:
|
---|
507 | case StorageBus_Floppy:
|
---|
508 | {
|
---|
509 | cCtrs = 1;
|
---|
510 | break;
|
---|
511 | }
|
---|
512 | default:
|
---|
513 | AssertMsgFailed(("Invalid bus type %d\n", aBus));
|
---|
514 | }
|
---|
515 |
|
---|
516 | *aMaxInstances = cCtrs;
|
---|
517 |
|
---|
518 | return S_OK;
|
---|
519 | }
|
---|
520 |
|
---|
521 | STDMETHODIMP SystemProperties::GetDeviceTypesForStorageBus(StorageBus_T aBus,
|
---|
522 | ComSafeArrayOut(DeviceType_T, aDeviceTypes))
|
---|
523 | {
|
---|
524 | CheckComArgOutSafeArrayPointerValid(aDeviceTypes);
|
---|
525 |
|
---|
526 | AutoCaller autoCaller(this);
|
---|
527 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
528 |
|
---|
529 | /* no need to lock, this is const */
|
---|
530 | switch (aBus)
|
---|
531 | {
|
---|
532 | case StorageBus_IDE:
|
---|
533 | case StorageBus_SATA:
|
---|
534 | {
|
---|
535 | com::SafeArray<DeviceType_T> saDeviceTypes(2);
|
---|
536 | saDeviceTypes[0] = DeviceType_DVD;
|
---|
537 | saDeviceTypes[1] = DeviceType_HardDisk;
|
---|
538 | saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
|
---|
539 | break;
|
---|
540 | }
|
---|
541 | case StorageBus_SCSI:
|
---|
542 | case StorageBus_SAS:
|
---|
543 | {
|
---|
544 | com::SafeArray<DeviceType_T> saDeviceTypes(1);
|
---|
545 | saDeviceTypes[0] = DeviceType_HardDisk;
|
---|
546 | saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
|
---|
547 | break;
|
---|
548 | }
|
---|
549 | case StorageBus_Floppy:
|
---|
550 | {
|
---|
551 | com::SafeArray<DeviceType_T> saDeviceTypes(1);
|
---|
552 | saDeviceTypes[0] = DeviceType_Floppy;
|
---|
553 | saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
|
---|
554 | break;
|
---|
555 | }
|
---|
556 | default:
|
---|
557 | AssertMsgFailed(("Invalid bus type %d\n", aBus));
|
---|
558 | }
|
---|
559 |
|
---|
560 | return S_OK;
|
---|
561 | }
|
---|
562 |
|
---|
563 | STDMETHODIMP SystemProperties::GetDefaultIoCacheSettingForStorageController(StorageControllerType_T aControllerType, BOOL *aEnabled)
|
---|
564 | {
|
---|
565 | CheckComArgOutPointerValid(aEnabled);
|
---|
566 |
|
---|
567 | AutoCaller autoCaller(this);
|
---|
568 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
569 |
|
---|
570 | /* no need to lock, this is const */
|
---|
571 | switch (aControllerType)
|
---|
572 | {
|
---|
573 | case StorageControllerType_LsiLogic:
|
---|
574 | case StorageControllerType_BusLogic:
|
---|
575 | case StorageControllerType_IntelAhci:
|
---|
576 | case StorageControllerType_LsiLogicSas:
|
---|
577 | *aEnabled = false;
|
---|
578 | break;
|
---|
579 | case StorageControllerType_PIIX3:
|
---|
580 | case StorageControllerType_PIIX4:
|
---|
581 | case StorageControllerType_ICH6:
|
---|
582 | case StorageControllerType_I82078:
|
---|
583 | *aEnabled = true;
|
---|
584 | break;
|
---|
585 | default:
|
---|
586 | AssertMsgFailed(("Invalid controller type %d\n", aControllerType));
|
---|
587 | }
|
---|
588 | return S_OK;
|
---|
589 | }
|
---|
590 |
|
---|
591 | STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder)(BSTR *aDefaultMachineFolder)
|
---|
592 | {
|
---|
593 | CheckComArgOutPointerValid(aDefaultMachineFolder);
|
---|
594 |
|
---|
595 | AutoCaller autoCaller(this);
|
---|
596 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
597 |
|
---|
598 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
599 |
|
---|
600 | m->strDefaultMachineFolder.cloneTo(aDefaultMachineFolder);
|
---|
601 |
|
---|
602 | return S_OK;
|
---|
603 | }
|
---|
604 |
|
---|
605 | STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder)(IN_BSTR aDefaultMachineFolder)
|
---|
606 | {
|
---|
607 | AutoCaller autoCaller(this);
|
---|
608 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
609 |
|
---|
610 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
611 | HRESULT rc = setDefaultMachineFolder(aDefaultMachineFolder);
|
---|
612 | alock.release();
|
---|
613 |
|
---|
614 | if (SUCCEEDED(rc))
|
---|
615 | {
|
---|
616 | // VirtualBox::saveSettings() needs vbox write lock
|
---|
617 | AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
618 | rc = mParent->saveSettings();
|
---|
619 | }
|
---|
620 |
|
---|
621 | return rc;
|
---|
622 | }
|
---|
623 |
|
---|
624 | STDMETHODIMP SystemProperties::COMGETTER(MediumFormats)(ComSafeArrayOut(IMediumFormat *, aMediumFormats))
|
---|
625 | {
|
---|
626 | CheckComArgOutSafeArrayPointerValid(aMediumFormats);
|
---|
627 |
|
---|
628 | AutoCaller autoCaller(this);
|
---|
629 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
630 |
|
---|
631 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
632 |
|
---|
633 | SafeIfaceArray<IMediumFormat> mediumFormats(m_llMediumFormats);
|
---|
634 | mediumFormats.detachTo(ComSafeArrayOutArg(aMediumFormats));
|
---|
635 |
|
---|
636 | return S_OK;
|
---|
637 | }
|
---|
638 |
|
---|
639 | STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat)(BSTR *aDefaultHardDiskFormat)
|
---|
640 | {
|
---|
641 | CheckComArgOutPointerValid(aDefaultHardDiskFormat);
|
---|
642 |
|
---|
643 | AutoCaller autoCaller(this);
|
---|
644 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
645 |
|
---|
646 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
647 |
|
---|
648 | m->strDefaultHardDiskFormat.cloneTo(aDefaultHardDiskFormat);
|
---|
649 |
|
---|
650 | return S_OK;
|
---|
651 | }
|
---|
652 |
|
---|
653 | STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat)(IN_BSTR aDefaultHardDiskFormat)
|
---|
654 | {
|
---|
655 | AutoCaller autoCaller(this);
|
---|
656 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
657 |
|
---|
658 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
659 | HRESULT rc = setDefaultHardDiskFormat(aDefaultHardDiskFormat);
|
---|
660 | alock.release();
|
---|
661 |
|
---|
662 | if (SUCCEEDED(rc))
|
---|
663 | {
|
---|
664 | // VirtualBox::saveSettings() needs vbox write lock
|
---|
665 | AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
666 | rc = mParent->saveSettings();
|
---|
667 | }
|
---|
668 |
|
---|
669 | return rc;
|
---|
670 | }
|
---|
671 |
|
---|
672 | STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceWarning)(LONG64 *aFreeSpace)
|
---|
673 | {
|
---|
674 | CheckComArgOutPointerValid(aFreeSpace);
|
---|
675 |
|
---|
676 | ReturnComNotImplemented();
|
---|
677 | }
|
---|
678 |
|
---|
679 | STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceWarning)(LONG64 /* aFreeSpace */)
|
---|
680 | {
|
---|
681 | ReturnComNotImplemented();
|
---|
682 | }
|
---|
683 |
|
---|
684 | STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentWarning)(ULONG *aFreeSpacePercent)
|
---|
685 | {
|
---|
686 | CheckComArgOutPointerValid(aFreeSpacePercent);
|
---|
687 |
|
---|
688 | ReturnComNotImplemented();
|
---|
689 | }
|
---|
690 |
|
---|
691 | STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentWarning)(ULONG /* aFreeSpacePercent */)
|
---|
692 | {
|
---|
693 | ReturnComNotImplemented();
|
---|
694 | }
|
---|
695 |
|
---|
696 | STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceError)(LONG64 *aFreeSpace)
|
---|
697 | {
|
---|
698 | CheckComArgOutPointerValid(aFreeSpace);
|
---|
699 |
|
---|
700 | ReturnComNotImplemented();
|
---|
701 | }
|
---|
702 |
|
---|
703 | STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceError)(LONG64 /* aFreeSpace */)
|
---|
704 | {
|
---|
705 | ReturnComNotImplemented();
|
---|
706 | }
|
---|
707 |
|
---|
708 | STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentError)(ULONG *aFreeSpacePercent)
|
---|
709 | {
|
---|
710 | CheckComArgOutPointerValid(aFreeSpacePercent);
|
---|
711 |
|
---|
712 | ReturnComNotImplemented();
|
---|
713 | }
|
---|
714 |
|
---|
715 | STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentError)(ULONG /* aFreeSpacePercent */)
|
---|
716 | {
|
---|
717 | ReturnComNotImplemented();
|
---|
718 | }
|
---|
719 |
|
---|
720 | STDMETHODIMP SystemProperties::COMGETTER(VRDEAuthLibrary)(BSTR *aVRDEAuthLibrary)
|
---|
721 | {
|
---|
722 | CheckComArgOutPointerValid(aVRDEAuthLibrary);
|
---|
723 |
|
---|
724 | AutoCaller autoCaller(this);
|
---|
725 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
726 |
|
---|
727 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
728 |
|
---|
729 | m->strVRDEAuthLibrary.cloneTo(aVRDEAuthLibrary);
|
---|
730 |
|
---|
731 | return S_OK;
|
---|
732 | }
|
---|
733 |
|
---|
734 | STDMETHODIMP SystemProperties::COMSETTER(VRDEAuthLibrary)(IN_BSTR aVRDEAuthLibrary)
|
---|
735 | {
|
---|
736 | AutoCaller autoCaller(this);
|
---|
737 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
738 |
|
---|
739 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
740 | HRESULT rc = setVRDEAuthLibrary(aVRDEAuthLibrary);
|
---|
741 | alock.release();
|
---|
742 |
|
---|
743 | if (SUCCEEDED(rc))
|
---|
744 | {
|
---|
745 | // VirtualBox::saveSettings() needs vbox write lock
|
---|
746 | AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
747 | rc = mParent->saveSettings();
|
---|
748 | }
|
---|
749 |
|
---|
750 | return rc;
|
---|
751 | }
|
---|
752 |
|
---|
753 | STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary)(BSTR *aWebServiceAuthLibrary)
|
---|
754 | {
|
---|
755 | CheckComArgOutPointerValid(aWebServiceAuthLibrary);
|
---|
756 |
|
---|
757 | AutoCaller autoCaller(this);
|
---|
758 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
759 |
|
---|
760 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
761 |
|
---|
762 | m->strWebServiceAuthLibrary.cloneTo(aWebServiceAuthLibrary);
|
---|
763 |
|
---|
764 | return S_OK;
|
---|
765 | }
|
---|
766 |
|
---|
767 | STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary)(IN_BSTR aWebServiceAuthLibrary)
|
---|
768 | {
|
---|
769 | AutoCaller autoCaller(this);
|
---|
770 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
771 |
|
---|
772 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
773 | HRESULT rc = setWebServiceAuthLibrary(aWebServiceAuthLibrary);
|
---|
774 | alock.release();
|
---|
775 |
|
---|
776 | if (SUCCEEDED(rc))
|
---|
777 | {
|
---|
778 | // VirtualBox::saveSettings() needs vbox write lock
|
---|
779 | AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
780 | rc = mParent->saveSettings();
|
---|
781 | }
|
---|
782 |
|
---|
783 | return rc;
|
---|
784 | }
|
---|
785 |
|
---|
786 | STDMETHODIMP SystemProperties::COMGETTER(DefaultVRDEExtPack)(BSTR *aExtPack)
|
---|
787 | {
|
---|
788 | CheckComArgOutPointerValid(aExtPack);
|
---|
789 |
|
---|
790 | AutoCaller autoCaller(this);
|
---|
791 | HRESULT hrc = autoCaller.rc();
|
---|
792 | if (SUCCEEDED(hrc))
|
---|
793 | {
|
---|
794 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
795 | Utf8Str strExtPack(m->strDefaultVRDEExtPack);
|
---|
796 | if (strExtPack.isNotEmpty())
|
---|
797 | {
|
---|
798 | if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
|
---|
799 | hrc = S_OK;
|
---|
800 | else
|
---|
801 | #ifdef VBOX_WITH_EXTPACK
|
---|
802 | hrc = mParent->getExtPackManager()->checkVrdeExtPack(&strExtPack);
|
---|
803 | #else
|
---|
804 | hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
|
---|
805 | #endif
|
---|
806 | }
|
---|
807 | else
|
---|
808 | {
|
---|
809 | #ifdef VBOX_WITH_EXTPACK
|
---|
810 | hrc = mParent->getExtPackManager()->getDefaultVrdeExtPack(&strExtPack);
|
---|
811 | #endif
|
---|
812 | if (strExtPack.isEmpty())
|
---|
813 | {
|
---|
814 | /*
|
---|
815 | * Klugde - check if VBoxVRDP.dll/.so/.dylib is installed.
|
---|
816 | * This is hardcoded uglyness, sorry.
|
---|
817 | */
|
---|
818 | char szPath[RTPATH_MAX];
|
---|
819 | int vrc = RTPathAppPrivateArch(szPath, sizeof(szPath));
|
---|
820 | if (RT_SUCCESS(vrc))
|
---|
821 | vrc = RTPathAppend(szPath, sizeof(szPath), "VBoxVRDP");
|
---|
822 | if (RT_SUCCESS(vrc))
|
---|
823 | vrc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
|
---|
824 | if (RT_SUCCESS(vrc) && RTFileExists(szPath))
|
---|
825 | {
|
---|
826 | /* Illegal extpack name, so no conflict. */
|
---|
827 | strExtPack = VBOXVRDP_KLUDGE_EXTPACK_NAME;
|
---|
828 | }
|
---|
829 | }
|
---|
830 | }
|
---|
831 |
|
---|
832 | if (SUCCEEDED(hrc))
|
---|
833 | strExtPack.cloneTo(aExtPack);
|
---|
834 | }
|
---|
835 |
|
---|
836 | return S_OK;
|
---|
837 | }
|
---|
838 |
|
---|
839 | STDMETHODIMP SystemProperties::COMSETTER(DefaultVRDEExtPack)(IN_BSTR aExtPack)
|
---|
840 | {
|
---|
841 | CheckComArgNotNull(aExtPack);
|
---|
842 | Utf8Str strExtPack(aExtPack);
|
---|
843 |
|
---|
844 | AutoCaller autoCaller(this);
|
---|
845 | HRESULT hrc = autoCaller.rc();
|
---|
846 | if (SUCCEEDED(hrc))
|
---|
847 | {
|
---|
848 | if (strExtPack.isNotEmpty())
|
---|
849 | {
|
---|
850 | if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
|
---|
851 | hrc = S_OK;
|
---|
852 | else
|
---|
853 | #ifdef VBOX_WITH_EXTPACK
|
---|
854 | hrc = mParent->getExtPackManager()->checkVrdeExtPack(&strExtPack);
|
---|
855 | #else
|
---|
856 | hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
|
---|
857 | #endif
|
---|
858 | }
|
---|
859 | if (SUCCEEDED(hrc))
|
---|
860 | {
|
---|
861 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
862 | hrc = setDefaultVRDEExtPack(aExtPack);
|
---|
863 | if (SUCCEEDED(hrc))
|
---|
864 | {
|
---|
865 | /* VirtualBox::saveSettings() needs the VirtualBox write lock. */
|
---|
866 | alock.release();
|
---|
867 | AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
868 | hrc = mParent->saveSettings();
|
---|
869 | }
|
---|
870 | }
|
---|
871 | }
|
---|
872 |
|
---|
873 | return hrc;
|
---|
874 | }
|
---|
875 |
|
---|
876 | STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount)(ULONG *count)
|
---|
877 | {
|
---|
878 | CheckComArgOutPointerValid(count);
|
---|
879 |
|
---|
880 | AutoCaller autoCaller(this);
|
---|
881 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
882 |
|
---|
883 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
884 |
|
---|
885 | *count = m->ulLogHistoryCount;
|
---|
886 |
|
---|
887 | return S_OK;
|
---|
888 | }
|
---|
889 |
|
---|
890 | STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount)(ULONG count)
|
---|
891 | {
|
---|
892 | AutoCaller autoCaller(this);
|
---|
893 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
894 |
|
---|
895 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
896 | m->ulLogHistoryCount = count;
|
---|
897 | alock.release();
|
---|
898 |
|
---|
899 | // VirtualBox::saveSettings() needs vbox write lock
|
---|
900 | AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
901 | HRESULT rc = mParent->saveSettings();
|
---|
902 |
|
---|
903 | return rc;
|
---|
904 | }
|
---|
905 |
|
---|
906 | STDMETHODIMP SystemProperties::COMGETTER(DefaultAudioDriver)(AudioDriverType_T *aAudioDriver)
|
---|
907 | {
|
---|
908 | CheckComArgOutPointerValid(aAudioDriver);
|
---|
909 |
|
---|
910 | AutoCaller autoCaller(this);
|
---|
911 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
912 |
|
---|
913 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
914 |
|
---|
915 | *aAudioDriver = settings::MachineConfigFile::getHostDefaultAudioDriver();
|
---|
916 |
|
---|
917 | return S_OK;
|
---|
918 | }
|
---|
919 |
|
---|
920 | // public methods only for internal purposes
|
---|
921 | /////////////////////////////////////////////////////////////////////////////
|
---|
922 |
|
---|
923 | HRESULT SystemProperties::loadSettings(const settings::SystemProperties &data)
|
---|
924 | {
|
---|
925 | AutoCaller autoCaller(this);
|
---|
926 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
927 |
|
---|
928 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
929 |
|
---|
930 | HRESULT rc = S_OK;
|
---|
931 |
|
---|
932 | rc = setDefaultMachineFolder(data.strDefaultMachineFolder);
|
---|
933 | if (FAILED(rc)) return rc;
|
---|
934 |
|
---|
935 | rc = setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
|
---|
936 | if (FAILED(rc)) return rc;
|
---|
937 |
|
---|
938 | rc = setVRDEAuthLibrary(data.strVRDEAuthLibrary);
|
---|
939 | if (FAILED(rc)) return rc;
|
---|
940 |
|
---|
941 | rc = setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
|
---|
942 | if (FAILED(rc)) return rc;
|
---|
943 |
|
---|
944 | rc = setDefaultVRDEExtPack(data.strDefaultVRDEExtPack);
|
---|
945 | if (FAILED(rc)) return rc;
|
---|
946 |
|
---|
947 | m->ulLogHistoryCount = data.ulLogHistoryCount;
|
---|
948 |
|
---|
949 | return S_OK;
|
---|
950 | }
|
---|
951 |
|
---|
952 | HRESULT SystemProperties::saveSettings(settings::SystemProperties &data)
|
---|
953 | {
|
---|
954 | AutoCaller autoCaller(this);
|
---|
955 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
956 |
|
---|
957 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
958 |
|
---|
959 | data = *m;
|
---|
960 |
|
---|
961 | return S_OK;
|
---|
962 | }
|
---|
963 |
|
---|
964 | /**
|
---|
965 | * Returns a medium format object corresponding to the given format
|
---|
966 | * identifier or null if no such format.
|
---|
967 | *
|
---|
968 | * @param aFormat Format identifier.
|
---|
969 | *
|
---|
970 | * @return ComObjPtr<MediumFormat>
|
---|
971 | */
|
---|
972 | ComObjPtr<MediumFormat> SystemProperties::mediumFormat(const Utf8Str &aFormat)
|
---|
973 | {
|
---|
974 | ComObjPtr<MediumFormat> format;
|
---|
975 |
|
---|
976 | AutoCaller autoCaller(this);
|
---|
977 | AssertComRCReturn (autoCaller.rc(), format);
|
---|
978 |
|
---|
979 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
980 |
|
---|
981 | for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
|
---|
982 | it != m_llMediumFormats.end();
|
---|
983 | ++ it)
|
---|
984 | {
|
---|
985 | /* MediumFormat is all const, no need to lock */
|
---|
986 |
|
---|
987 | if ((*it)->getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
|
---|
988 | {
|
---|
989 | format = *it;
|
---|
990 | break;
|
---|
991 | }
|
---|
992 | }
|
---|
993 |
|
---|
994 | return format;
|
---|
995 | }
|
---|
996 |
|
---|
997 | /**
|
---|
998 | * Returns a medium format object corresponding to the given file extension or
|
---|
999 | * null if no such format.
|
---|
1000 | *
|
---|
1001 | * @param aExt File extension.
|
---|
1002 | *
|
---|
1003 | * @return ComObjPtr<MediumFormat>
|
---|
1004 | */
|
---|
1005 | ComObjPtr<MediumFormat> SystemProperties::mediumFormatFromExtension(const Utf8Str &aExt)
|
---|
1006 | {
|
---|
1007 | ComObjPtr<MediumFormat> format;
|
---|
1008 |
|
---|
1009 | AutoCaller autoCaller(this);
|
---|
1010 | AssertComRCReturn (autoCaller.rc(), format);
|
---|
1011 |
|
---|
1012 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1013 |
|
---|
1014 | bool fFound = false;
|
---|
1015 | for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
|
---|
1016 | it != m_llMediumFormats.end() && !fFound;
|
---|
1017 | ++it)
|
---|
1018 | {
|
---|
1019 | /* MediumFormat is all const, no need to lock */
|
---|
1020 | MediumFormat::StrList aFileList = (*it)->getFileExtensions();
|
---|
1021 | for (MediumFormat::StrList::const_iterator it1 = aFileList.begin();
|
---|
1022 | it1 != aFileList.end();
|
---|
1023 | ++it1)
|
---|
1024 | {
|
---|
1025 | if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0)
|
---|
1026 | {
|
---|
1027 | format = *it;
|
---|
1028 | fFound = true;
|
---|
1029 | break;
|
---|
1030 | }
|
---|
1031 | }
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | return format;
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | // private methods
|
---|
1038 | /////////////////////////////////////////////////////////////////////////////
|
---|
1039 |
|
---|
1040 | /**
|
---|
1041 | * Returns the user's home directory. Wrapper around RTPathUserHome().
|
---|
1042 | * @param strPath
|
---|
1043 | * @return
|
---|
1044 | */
|
---|
1045 | HRESULT SystemProperties::getUserHomeDirectory(Utf8Str &strPath)
|
---|
1046 | {
|
---|
1047 | char szHome[RTPATH_MAX];
|
---|
1048 | int vrc = RTPathUserHome(szHome, sizeof(szHome));
|
---|
1049 | if (RT_FAILURE(vrc))
|
---|
1050 | return setError(E_FAIL,
|
---|
1051 | tr("Cannot determine user home directory (%Rrc)"),
|
---|
1052 | vrc);
|
---|
1053 | strPath = szHome;
|
---|
1054 | return S_OK;
|
---|
1055 | }
|
---|
1056 |
|
---|
1057 | /**
|
---|
1058 | * Internal implementation to set the default machine folder. Gets called
|
---|
1059 | * from the public attribute setter as well as loadSettings(). With 4.0,
|
---|
1060 | * the "default default" machine folder has changed, and we now require
|
---|
1061 | * a full path always.
|
---|
1062 | * @param aPath
|
---|
1063 | * @return
|
---|
1064 | */
|
---|
1065 | HRESULT SystemProperties::setDefaultMachineFolder(const Utf8Str &strPath)
|
---|
1066 | {
|
---|
1067 | Utf8Str path(strPath); // make modifiable
|
---|
1068 | if ( path.isEmpty() // used by API calls to reset the default
|
---|
1069 | || path == "Machines" // this value (exactly like this, without path) is stored
|
---|
1070 | // in VirtualBox.xml if user upgrades from before 4.0 and
|
---|
1071 | // has not changed the default machine folder
|
---|
1072 | )
|
---|
1073 | {
|
---|
1074 | // new default with VirtualBox 4.0: "$HOME/VirtualBox VMs"
|
---|
1075 | HRESULT rc = getUserHomeDirectory(path);
|
---|
1076 | if (FAILED(rc)) return rc;
|
---|
1077 | path += RTPATH_SLASH_STR "VirtualBox VMs";
|
---|
1078 | }
|
---|
1079 |
|
---|
1080 | if (!RTPathStartsWithRoot(path.c_str()))
|
---|
1081 | return setError(E_INVALIDARG,
|
---|
1082 | tr("Given default machine folder '%s' is not fully qualified"),
|
---|
1083 | path.c_str());
|
---|
1084 |
|
---|
1085 | m->strDefaultMachineFolder = path;
|
---|
1086 |
|
---|
1087 | return S_OK;
|
---|
1088 | }
|
---|
1089 |
|
---|
1090 | HRESULT SystemProperties::setDefaultHardDiskFormat(const Utf8Str &aFormat)
|
---|
1091 | {
|
---|
1092 | if (!aFormat.isEmpty())
|
---|
1093 | m->strDefaultHardDiskFormat = aFormat;
|
---|
1094 | else
|
---|
1095 | m->strDefaultHardDiskFormat = "VDI";
|
---|
1096 |
|
---|
1097 | return S_OK;
|
---|
1098 | }
|
---|
1099 |
|
---|
1100 | HRESULT SystemProperties::setVRDEAuthLibrary(const Utf8Str &aPath)
|
---|
1101 | {
|
---|
1102 | if (!aPath.isEmpty())
|
---|
1103 | m->strVRDEAuthLibrary = aPath;
|
---|
1104 | else
|
---|
1105 | m->strVRDEAuthLibrary = "VBoxAuth";
|
---|
1106 |
|
---|
1107 | return S_OK;
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 | HRESULT SystemProperties::setWebServiceAuthLibrary(const Utf8Str &aPath)
|
---|
1111 | {
|
---|
1112 | if (!aPath.isEmpty())
|
---|
1113 | m->strWebServiceAuthLibrary = aPath;
|
---|
1114 | else
|
---|
1115 | m->strWebServiceAuthLibrary = "VBoxAuth";
|
---|
1116 |
|
---|
1117 | return S_OK;
|
---|
1118 | }
|
---|
1119 |
|
---|
1120 | HRESULT SystemProperties::setDefaultVRDEExtPack(const Utf8Str &aExtPack)
|
---|
1121 | {
|
---|
1122 | m->strDefaultVRDEExtPack = aExtPack;
|
---|
1123 |
|
---|
1124 | return S_OK;
|
---|
1125 | }
|
---|