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