1 | /* $Id: SystemPropertiesImpl.cpp 35761 2011-01-28 13:19: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 |
|
---|
354 |
|
---|
355 | /* no need for locking, no state */
|
---|
356 | switch (aType)
|
---|
357 | {
|
---|
358 | case NetworkAttachmentType_NAT:
|
---|
359 | case NetworkAttachmentType_Internal:
|
---|
360 | /* chipset default is OK */
|
---|
361 | break;
|
---|
362 | case NetworkAttachmentType_Bridged:
|
---|
363 | /* Maybe use current host interface count here? */
|
---|
364 | break;
|
---|
365 | case NetworkAttachmentType_HostOnly:
|
---|
366 | uResult = 8;
|
---|
367 | break;
|
---|
368 | default:
|
---|
369 | AssertMsgFailed(("Unhandled attachment type %d\n", aType));
|
---|
370 | }
|
---|
371 |
|
---|
372 | *count = uResult;
|
---|
373 |
|
---|
374 | return S_OK;
|
---|
375 | }
|
---|
376 |
|
---|
377 |
|
---|
378 | STDMETHODIMP SystemProperties::GetMaxDevicesPerPortForStorageBus(StorageBus_T aBus,
|
---|
379 | ULONG *aMaxDevicesPerPort)
|
---|
380 | {
|
---|
381 | CheckComArgOutPointerValid(aMaxDevicesPerPort);
|
---|
382 |
|
---|
383 | AutoCaller autoCaller(this);
|
---|
384 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
385 |
|
---|
386 | /* no need to lock, this is const */
|
---|
387 | switch (aBus)
|
---|
388 | {
|
---|
389 | case StorageBus_SATA:
|
---|
390 | case StorageBus_SCSI:
|
---|
391 | case StorageBus_SAS:
|
---|
392 | {
|
---|
393 | /* SATA and both SCSI controllers only support one device per port. */
|
---|
394 | *aMaxDevicesPerPort = 1;
|
---|
395 | break;
|
---|
396 | }
|
---|
397 | case StorageBus_IDE:
|
---|
398 | case StorageBus_Floppy:
|
---|
399 | {
|
---|
400 | /* The IDE and Floppy controllers support 2 devices. One as master
|
---|
401 | * and one as slave (or floppy drive 0 and 1). */
|
---|
402 | *aMaxDevicesPerPort = 2;
|
---|
403 | break;
|
---|
404 | }
|
---|
405 | default:
|
---|
406 | AssertMsgFailed(("Invalid bus type %d\n", aBus));
|
---|
407 | }
|
---|
408 |
|
---|
409 | return S_OK;
|
---|
410 | }
|
---|
411 |
|
---|
412 | STDMETHODIMP SystemProperties::GetMinPortCountForStorageBus(StorageBus_T aBus,
|
---|
413 | ULONG *aMinPortCount)
|
---|
414 | {
|
---|
415 | CheckComArgOutPointerValid(aMinPortCount);
|
---|
416 |
|
---|
417 | AutoCaller autoCaller(this);
|
---|
418 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
419 |
|
---|
420 | /* no need to lock, this is const */
|
---|
421 | switch (aBus)
|
---|
422 | {
|
---|
423 | case StorageBus_SATA:
|
---|
424 | {
|
---|
425 | *aMinPortCount = 1;
|
---|
426 | break;
|
---|
427 | }
|
---|
428 | case StorageBus_SCSI:
|
---|
429 | {
|
---|
430 | *aMinPortCount = 16;
|
---|
431 | break;
|
---|
432 | }
|
---|
433 | case StorageBus_IDE:
|
---|
434 | {
|
---|
435 | *aMinPortCount = 2;
|
---|
436 | break;
|
---|
437 | }
|
---|
438 | case StorageBus_Floppy:
|
---|
439 | {
|
---|
440 | *aMinPortCount = 1;
|
---|
441 | break;
|
---|
442 | }
|
---|
443 | case StorageBus_SAS:
|
---|
444 | {
|
---|
445 | *aMinPortCount = 8;
|
---|
446 | break;
|
---|
447 | }
|
---|
448 | default:
|
---|
449 | AssertMsgFailed(("Invalid bus type %d\n", aBus));
|
---|
450 | }
|
---|
451 |
|
---|
452 | return S_OK;
|
---|
453 | }
|
---|
454 |
|
---|
455 | STDMETHODIMP SystemProperties::GetMaxPortCountForStorageBus(StorageBus_T aBus,
|
---|
456 | ULONG *aMaxPortCount)
|
---|
457 | {
|
---|
458 | CheckComArgOutPointerValid(aMaxPortCount);
|
---|
459 |
|
---|
460 | AutoCaller autoCaller(this);
|
---|
461 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
462 |
|
---|
463 | /* no need to lock, this is const */
|
---|
464 | switch (aBus)
|
---|
465 | {
|
---|
466 | case StorageBus_SATA:
|
---|
467 | {
|
---|
468 | *aMaxPortCount = 30;
|
---|
469 | break;
|
---|
470 | }
|
---|
471 | case StorageBus_SCSI:
|
---|
472 | {
|
---|
473 | *aMaxPortCount = 16;
|
---|
474 | break;
|
---|
475 | }
|
---|
476 | case StorageBus_IDE:
|
---|
477 | {
|
---|
478 | *aMaxPortCount = 2;
|
---|
479 | break;
|
---|
480 | }
|
---|
481 | case StorageBus_Floppy:
|
---|
482 | {
|
---|
483 | *aMaxPortCount = 1;
|
---|
484 | break;
|
---|
485 | }
|
---|
486 | case StorageBus_SAS:
|
---|
487 | {
|
---|
488 | *aMaxPortCount = 8;
|
---|
489 | break;
|
---|
490 | }
|
---|
491 | default:
|
---|
492 | AssertMsgFailed(("Invalid bus type %d\n", aBus));
|
---|
493 | }
|
---|
494 |
|
---|
495 | return S_OK;
|
---|
496 | }
|
---|
497 |
|
---|
498 | STDMETHODIMP SystemProperties::GetMaxInstancesOfStorageBus(ChipsetType_T aChipset,
|
---|
499 | StorageBus_T aBus,
|
---|
500 | ULONG *aMaxInstances)
|
---|
501 | {
|
---|
502 | CheckComArgOutPointerValid(aMaxInstances);
|
---|
503 |
|
---|
504 | AutoCaller autoCaller(this);
|
---|
505 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
506 |
|
---|
507 | ULONG cCtrs = 0;
|
---|
508 |
|
---|
509 | /* no need to lock, this is const */
|
---|
510 | switch (aBus)
|
---|
511 | {
|
---|
512 | case StorageBus_SATA:
|
---|
513 | case StorageBus_SCSI:
|
---|
514 | case StorageBus_SAS:
|
---|
515 | cCtrs = aChipset == ChipsetType_ICH9 ? 8 : 1;
|
---|
516 | break;
|
---|
517 | case StorageBus_IDE:
|
---|
518 | case StorageBus_Floppy:
|
---|
519 | {
|
---|
520 | cCtrs = 1;
|
---|
521 | break;
|
---|
522 | }
|
---|
523 | default:
|
---|
524 | AssertMsgFailed(("Invalid bus type %d\n", aBus));
|
---|
525 | }
|
---|
526 |
|
---|
527 | *aMaxInstances = cCtrs;
|
---|
528 |
|
---|
529 | return S_OK;
|
---|
530 | }
|
---|
531 |
|
---|
532 | STDMETHODIMP SystemProperties::GetDeviceTypesForStorageBus(StorageBus_T aBus,
|
---|
533 | ComSafeArrayOut(DeviceType_T, aDeviceTypes))
|
---|
534 | {
|
---|
535 | CheckComArgOutSafeArrayPointerValid(aDeviceTypes);
|
---|
536 |
|
---|
537 | AutoCaller autoCaller(this);
|
---|
538 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
539 |
|
---|
540 | /* no need to lock, this is const */
|
---|
541 | switch (aBus)
|
---|
542 | {
|
---|
543 | case StorageBus_IDE:
|
---|
544 | case StorageBus_SATA:
|
---|
545 | {
|
---|
546 | com::SafeArray<DeviceType_T> saDeviceTypes(2);
|
---|
547 | saDeviceTypes[0] = DeviceType_DVD;
|
---|
548 | saDeviceTypes[1] = DeviceType_HardDisk;
|
---|
549 | saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
|
---|
550 | break;
|
---|
551 | }
|
---|
552 | case StorageBus_SCSI:
|
---|
553 | case StorageBus_SAS:
|
---|
554 | {
|
---|
555 | com::SafeArray<DeviceType_T> saDeviceTypes(1);
|
---|
556 | saDeviceTypes[0] = DeviceType_HardDisk;
|
---|
557 | saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
|
---|
558 | break;
|
---|
559 | }
|
---|
560 | case StorageBus_Floppy:
|
---|
561 | {
|
---|
562 | com::SafeArray<DeviceType_T> saDeviceTypes(1);
|
---|
563 | saDeviceTypes[0] = DeviceType_Floppy;
|
---|
564 | saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
|
---|
565 | break;
|
---|
566 | }
|
---|
567 | default:
|
---|
568 | AssertMsgFailed(("Invalid bus type %d\n", aBus));
|
---|
569 | }
|
---|
570 |
|
---|
571 | return S_OK;
|
---|
572 | }
|
---|
573 |
|
---|
574 | STDMETHODIMP SystemProperties::GetDefaultIoCacheSettingForStorageController(StorageControllerType_T aControllerType, BOOL *aEnabled)
|
---|
575 | {
|
---|
576 | CheckComArgOutPointerValid(aEnabled);
|
---|
577 |
|
---|
578 | AutoCaller autoCaller(this);
|
---|
579 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
580 |
|
---|
581 | /* no need to lock, this is const */
|
---|
582 | switch (aControllerType)
|
---|
583 | {
|
---|
584 | case StorageControllerType_LsiLogic:
|
---|
585 | case StorageControllerType_BusLogic:
|
---|
586 | case StorageControllerType_IntelAhci:
|
---|
587 | case StorageControllerType_LsiLogicSas:
|
---|
588 | *aEnabled = false;
|
---|
589 | break;
|
---|
590 | case StorageControllerType_PIIX3:
|
---|
591 | case StorageControllerType_PIIX4:
|
---|
592 | case StorageControllerType_ICH6:
|
---|
593 | case StorageControllerType_I82078:
|
---|
594 | *aEnabled = true;
|
---|
595 | break;
|
---|
596 | default:
|
---|
597 | AssertMsgFailed(("Invalid controller type %d\n", aControllerType));
|
---|
598 | }
|
---|
599 | return S_OK;
|
---|
600 | }
|
---|
601 |
|
---|
602 | STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder)(BSTR *aDefaultMachineFolder)
|
---|
603 | {
|
---|
604 | CheckComArgOutPointerValid(aDefaultMachineFolder);
|
---|
605 |
|
---|
606 | AutoCaller autoCaller(this);
|
---|
607 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
608 |
|
---|
609 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
610 |
|
---|
611 | m->strDefaultMachineFolder.cloneTo(aDefaultMachineFolder);
|
---|
612 |
|
---|
613 | return S_OK;
|
---|
614 | }
|
---|
615 |
|
---|
616 | STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder)(IN_BSTR aDefaultMachineFolder)
|
---|
617 | {
|
---|
618 | AutoCaller autoCaller(this);
|
---|
619 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
620 |
|
---|
621 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
622 | HRESULT rc = setDefaultMachineFolder(aDefaultMachineFolder);
|
---|
623 | alock.release();
|
---|
624 |
|
---|
625 | if (SUCCEEDED(rc))
|
---|
626 | {
|
---|
627 | // VirtualBox::saveSettings() needs vbox write lock
|
---|
628 | AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
629 | rc = mParent->saveSettings();
|
---|
630 | }
|
---|
631 |
|
---|
632 | return rc;
|
---|
633 | }
|
---|
634 |
|
---|
635 | STDMETHODIMP SystemProperties::COMGETTER(MediumFormats)(ComSafeArrayOut(IMediumFormat *, aMediumFormats))
|
---|
636 | {
|
---|
637 | CheckComArgOutSafeArrayPointerValid(aMediumFormats);
|
---|
638 |
|
---|
639 | AutoCaller autoCaller(this);
|
---|
640 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
641 |
|
---|
642 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
643 |
|
---|
644 | SafeIfaceArray<IMediumFormat> mediumFormats(m_llMediumFormats);
|
---|
645 | mediumFormats.detachTo(ComSafeArrayOutArg(aMediumFormats));
|
---|
646 |
|
---|
647 | return S_OK;
|
---|
648 | }
|
---|
649 |
|
---|
650 | STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat)(BSTR *aDefaultHardDiskFormat)
|
---|
651 | {
|
---|
652 | CheckComArgOutPointerValid(aDefaultHardDiskFormat);
|
---|
653 |
|
---|
654 | AutoCaller autoCaller(this);
|
---|
655 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
656 |
|
---|
657 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
658 |
|
---|
659 | m->strDefaultHardDiskFormat.cloneTo(aDefaultHardDiskFormat);
|
---|
660 |
|
---|
661 | return S_OK;
|
---|
662 | }
|
---|
663 |
|
---|
664 | STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat)(IN_BSTR aDefaultHardDiskFormat)
|
---|
665 | {
|
---|
666 | AutoCaller autoCaller(this);
|
---|
667 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
668 |
|
---|
669 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
670 | HRESULT rc = setDefaultHardDiskFormat(aDefaultHardDiskFormat);
|
---|
671 | alock.release();
|
---|
672 |
|
---|
673 | if (SUCCEEDED(rc))
|
---|
674 | {
|
---|
675 | // VirtualBox::saveSettings() needs vbox write lock
|
---|
676 | AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
677 | rc = mParent->saveSettings();
|
---|
678 | }
|
---|
679 |
|
---|
680 | return rc;
|
---|
681 | }
|
---|
682 |
|
---|
683 | STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceWarning)(LONG64 *aFreeSpace)
|
---|
684 | {
|
---|
685 | CheckComArgOutPointerValid(aFreeSpace);
|
---|
686 |
|
---|
687 | ReturnComNotImplemented();
|
---|
688 | }
|
---|
689 |
|
---|
690 | STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceWarning)(LONG64 /* aFreeSpace */)
|
---|
691 | {
|
---|
692 | ReturnComNotImplemented();
|
---|
693 | }
|
---|
694 |
|
---|
695 | STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentWarning)(ULONG *aFreeSpacePercent)
|
---|
696 | {
|
---|
697 | CheckComArgOutPointerValid(aFreeSpacePercent);
|
---|
698 |
|
---|
699 | ReturnComNotImplemented();
|
---|
700 | }
|
---|
701 |
|
---|
702 | STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentWarning)(ULONG /* aFreeSpacePercent */)
|
---|
703 | {
|
---|
704 | ReturnComNotImplemented();
|
---|
705 | }
|
---|
706 |
|
---|
707 | STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceError)(LONG64 *aFreeSpace)
|
---|
708 | {
|
---|
709 | CheckComArgOutPointerValid(aFreeSpace);
|
---|
710 |
|
---|
711 | ReturnComNotImplemented();
|
---|
712 | }
|
---|
713 |
|
---|
714 | STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceError)(LONG64 /* aFreeSpace */)
|
---|
715 | {
|
---|
716 | ReturnComNotImplemented();
|
---|
717 | }
|
---|
718 |
|
---|
719 | STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentError)(ULONG *aFreeSpacePercent)
|
---|
720 | {
|
---|
721 | CheckComArgOutPointerValid(aFreeSpacePercent);
|
---|
722 |
|
---|
723 | ReturnComNotImplemented();
|
---|
724 | }
|
---|
725 |
|
---|
726 | STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentError)(ULONG /* aFreeSpacePercent */)
|
---|
727 | {
|
---|
728 | ReturnComNotImplemented();
|
---|
729 | }
|
---|
730 |
|
---|
731 | STDMETHODIMP SystemProperties::COMGETTER(VRDEAuthLibrary)(BSTR *aVRDEAuthLibrary)
|
---|
732 | {
|
---|
733 | CheckComArgOutPointerValid(aVRDEAuthLibrary);
|
---|
734 |
|
---|
735 | AutoCaller autoCaller(this);
|
---|
736 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
737 |
|
---|
738 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
739 |
|
---|
740 | m->strVRDEAuthLibrary.cloneTo(aVRDEAuthLibrary);
|
---|
741 |
|
---|
742 | return S_OK;
|
---|
743 | }
|
---|
744 |
|
---|
745 | STDMETHODIMP SystemProperties::COMSETTER(VRDEAuthLibrary)(IN_BSTR aVRDEAuthLibrary)
|
---|
746 | {
|
---|
747 | AutoCaller autoCaller(this);
|
---|
748 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
749 |
|
---|
750 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
751 | HRESULT rc = setVRDEAuthLibrary(aVRDEAuthLibrary);
|
---|
752 | alock.release();
|
---|
753 |
|
---|
754 | if (SUCCEEDED(rc))
|
---|
755 | {
|
---|
756 | // VirtualBox::saveSettings() needs vbox write lock
|
---|
757 | AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
758 | rc = mParent->saveSettings();
|
---|
759 | }
|
---|
760 |
|
---|
761 | return rc;
|
---|
762 | }
|
---|
763 |
|
---|
764 | STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary)(BSTR *aWebServiceAuthLibrary)
|
---|
765 | {
|
---|
766 | CheckComArgOutPointerValid(aWebServiceAuthLibrary);
|
---|
767 |
|
---|
768 | AutoCaller autoCaller(this);
|
---|
769 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
770 |
|
---|
771 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
772 |
|
---|
773 | m->strWebServiceAuthLibrary.cloneTo(aWebServiceAuthLibrary);
|
---|
774 |
|
---|
775 | return S_OK;
|
---|
776 | }
|
---|
777 |
|
---|
778 | STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary)(IN_BSTR aWebServiceAuthLibrary)
|
---|
779 | {
|
---|
780 | AutoCaller autoCaller(this);
|
---|
781 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
782 |
|
---|
783 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
784 | HRESULT rc = setWebServiceAuthLibrary(aWebServiceAuthLibrary);
|
---|
785 | alock.release();
|
---|
786 |
|
---|
787 | if (SUCCEEDED(rc))
|
---|
788 | {
|
---|
789 | // VirtualBox::saveSettings() needs vbox write lock
|
---|
790 | AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
791 | rc = mParent->saveSettings();
|
---|
792 | }
|
---|
793 |
|
---|
794 | return rc;
|
---|
795 | }
|
---|
796 |
|
---|
797 | STDMETHODIMP SystemProperties::COMGETTER(DefaultVRDEExtPack)(BSTR *aExtPack)
|
---|
798 | {
|
---|
799 | CheckComArgOutPointerValid(aExtPack);
|
---|
800 |
|
---|
801 | AutoCaller autoCaller(this);
|
---|
802 | HRESULT hrc = autoCaller.rc();
|
---|
803 | if (SUCCEEDED(hrc))
|
---|
804 | {
|
---|
805 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
806 | Utf8Str strExtPack(m->strDefaultVRDEExtPack);
|
---|
807 | if (strExtPack.isNotEmpty())
|
---|
808 | {
|
---|
809 | if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
|
---|
810 | hrc = S_OK;
|
---|
811 | else
|
---|
812 | #ifdef VBOX_WITH_EXTPACK
|
---|
813 | hrc = mParent->getExtPackManager()->checkVrdeExtPack(&strExtPack);
|
---|
814 | #else
|
---|
815 | hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
|
---|
816 | #endif
|
---|
817 | }
|
---|
818 | else
|
---|
819 | {
|
---|
820 | #ifdef VBOX_WITH_EXTPACK
|
---|
821 | hrc = mParent->getExtPackManager()->getDefaultVrdeExtPack(&strExtPack);
|
---|
822 | #endif
|
---|
823 | if (strExtPack.isEmpty())
|
---|
824 | {
|
---|
825 | /*
|
---|
826 | * Klugde - check if VBoxVRDP.dll/.so/.dylib is installed.
|
---|
827 | * This is hardcoded uglyness, sorry.
|
---|
828 | */
|
---|
829 | char szPath[RTPATH_MAX];
|
---|
830 | int vrc = RTPathAppPrivateArch(szPath, sizeof(szPath));
|
---|
831 | if (RT_SUCCESS(vrc))
|
---|
832 | vrc = RTPathAppend(szPath, sizeof(szPath), "VBoxVRDP");
|
---|
833 | if (RT_SUCCESS(vrc))
|
---|
834 | vrc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
|
---|
835 | if (RT_SUCCESS(vrc) && RTFileExists(szPath))
|
---|
836 | {
|
---|
837 | /* Illegal extpack name, so no conflict. */
|
---|
838 | strExtPack = VBOXVRDP_KLUDGE_EXTPACK_NAME;
|
---|
839 | }
|
---|
840 | }
|
---|
841 | }
|
---|
842 |
|
---|
843 | if (SUCCEEDED(hrc))
|
---|
844 | strExtPack.cloneTo(aExtPack);
|
---|
845 | }
|
---|
846 |
|
---|
847 | return S_OK;
|
---|
848 | }
|
---|
849 |
|
---|
850 | STDMETHODIMP SystemProperties::COMSETTER(DefaultVRDEExtPack)(IN_BSTR aExtPack)
|
---|
851 | {
|
---|
852 | CheckComArgNotNull(aExtPack);
|
---|
853 | Utf8Str strExtPack(aExtPack);
|
---|
854 |
|
---|
855 | AutoCaller autoCaller(this);
|
---|
856 | HRESULT hrc = autoCaller.rc();
|
---|
857 | if (SUCCEEDED(hrc))
|
---|
858 | {
|
---|
859 | if (strExtPack.isNotEmpty())
|
---|
860 | {
|
---|
861 | if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
|
---|
862 | hrc = S_OK;
|
---|
863 | else
|
---|
864 | #ifdef VBOX_WITH_EXTPACK
|
---|
865 | hrc = mParent->getExtPackManager()->checkVrdeExtPack(&strExtPack);
|
---|
866 | #else
|
---|
867 | hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
|
---|
868 | #endif
|
---|
869 | }
|
---|
870 | if (SUCCEEDED(hrc))
|
---|
871 | {
|
---|
872 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
873 | hrc = setDefaultVRDEExtPack(aExtPack);
|
---|
874 | if (SUCCEEDED(hrc))
|
---|
875 | {
|
---|
876 | /* VirtualBox::saveSettings() needs the VirtualBox write lock. */
|
---|
877 | alock.release();
|
---|
878 | AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
879 | hrc = mParent->saveSettings();
|
---|
880 | }
|
---|
881 | }
|
---|
882 | }
|
---|
883 |
|
---|
884 | return hrc;
|
---|
885 | }
|
---|
886 |
|
---|
887 | STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount)(ULONG *count)
|
---|
888 | {
|
---|
889 | CheckComArgOutPointerValid(count);
|
---|
890 |
|
---|
891 | AutoCaller autoCaller(this);
|
---|
892 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
893 |
|
---|
894 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
895 |
|
---|
896 | *count = m->ulLogHistoryCount;
|
---|
897 |
|
---|
898 | return S_OK;
|
---|
899 | }
|
---|
900 |
|
---|
901 | STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount)(ULONG count)
|
---|
902 | {
|
---|
903 | AutoCaller autoCaller(this);
|
---|
904 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
905 |
|
---|
906 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
907 | m->ulLogHistoryCount = count;
|
---|
908 | alock.release();
|
---|
909 |
|
---|
910 | // VirtualBox::saveSettings() needs vbox write lock
|
---|
911 | AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
|
---|
912 | HRESULT rc = mParent->saveSettings();
|
---|
913 |
|
---|
914 | return rc;
|
---|
915 | }
|
---|
916 |
|
---|
917 | STDMETHODIMP SystemProperties::COMGETTER(DefaultAudioDriver)(AudioDriverType_T *aAudioDriver)
|
---|
918 | {
|
---|
919 | CheckComArgOutPointerValid(aAudioDriver);
|
---|
920 |
|
---|
921 | AutoCaller autoCaller(this);
|
---|
922 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
923 |
|
---|
924 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
925 |
|
---|
926 | *aAudioDriver = settings::MachineConfigFile::getHostDefaultAudioDriver();
|
---|
927 |
|
---|
928 | return S_OK;
|
---|
929 | }
|
---|
930 |
|
---|
931 | // public methods only for internal purposes
|
---|
932 | /////////////////////////////////////////////////////////////////////////////
|
---|
933 |
|
---|
934 | HRESULT SystemProperties::loadSettings(const settings::SystemProperties &data)
|
---|
935 | {
|
---|
936 | AutoCaller autoCaller(this);
|
---|
937 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
938 |
|
---|
939 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
940 |
|
---|
941 | HRESULT rc = S_OK;
|
---|
942 |
|
---|
943 | rc = setDefaultMachineFolder(data.strDefaultMachineFolder);
|
---|
944 | if (FAILED(rc)) return rc;
|
---|
945 |
|
---|
946 | rc = setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
|
---|
947 | if (FAILED(rc)) return rc;
|
---|
948 |
|
---|
949 | rc = setVRDEAuthLibrary(data.strVRDEAuthLibrary);
|
---|
950 | if (FAILED(rc)) return rc;
|
---|
951 |
|
---|
952 | rc = setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
|
---|
953 | if (FAILED(rc)) return rc;
|
---|
954 |
|
---|
955 | rc = setDefaultVRDEExtPack(data.strDefaultVRDEExtPack);
|
---|
956 | if (FAILED(rc)) return rc;
|
---|
957 |
|
---|
958 | m->ulLogHistoryCount = data.ulLogHistoryCount;
|
---|
959 |
|
---|
960 | return S_OK;
|
---|
961 | }
|
---|
962 |
|
---|
963 | HRESULT SystemProperties::saveSettings(settings::SystemProperties &data)
|
---|
964 | {
|
---|
965 | AutoCaller autoCaller(this);
|
---|
966 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
967 |
|
---|
968 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
969 |
|
---|
970 | data = *m;
|
---|
971 |
|
---|
972 | return S_OK;
|
---|
973 | }
|
---|
974 |
|
---|
975 | /**
|
---|
976 | * Returns a medium format object corresponding to the given format
|
---|
977 | * identifier or null if no such format.
|
---|
978 | *
|
---|
979 | * @param aFormat Format identifier.
|
---|
980 | *
|
---|
981 | * @return ComObjPtr<MediumFormat>
|
---|
982 | */
|
---|
983 | ComObjPtr<MediumFormat> SystemProperties::mediumFormat(const Utf8Str &aFormat)
|
---|
984 | {
|
---|
985 | ComObjPtr<MediumFormat> format;
|
---|
986 |
|
---|
987 | AutoCaller autoCaller(this);
|
---|
988 | AssertComRCReturn (autoCaller.rc(), format);
|
---|
989 |
|
---|
990 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
991 |
|
---|
992 | for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
|
---|
993 | it != m_llMediumFormats.end();
|
---|
994 | ++ it)
|
---|
995 | {
|
---|
996 | /* MediumFormat is all const, no need to lock */
|
---|
997 |
|
---|
998 | if ((*it)->getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
|
---|
999 | {
|
---|
1000 | format = *it;
|
---|
1001 | break;
|
---|
1002 | }
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | return format;
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | /**
|
---|
1009 | * Returns a medium format object corresponding to the given file extension or
|
---|
1010 | * null if no such format.
|
---|
1011 | *
|
---|
1012 | * @param aExt File extension.
|
---|
1013 | *
|
---|
1014 | * @return ComObjPtr<MediumFormat>
|
---|
1015 | */
|
---|
1016 | ComObjPtr<MediumFormat> SystemProperties::mediumFormatFromExtension(const Utf8Str &aExt)
|
---|
1017 | {
|
---|
1018 | ComObjPtr<MediumFormat> format;
|
---|
1019 |
|
---|
1020 | AutoCaller autoCaller(this);
|
---|
1021 | AssertComRCReturn (autoCaller.rc(), format);
|
---|
1022 |
|
---|
1023 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1024 |
|
---|
1025 | bool fFound = false;
|
---|
1026 | for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
|
---|
1027 | it != m_llMediumFormats.end() && !fFound;
|
---|
1028 | ++it)
|
---|
1029 | {
|
---|
1030 | /* MediumFormat is all const, no need to lock */
|
---|
1031 | MediumFormat::StrList aFileList = (*it)->getFileExtensions();
|
---|
1032 | for (MediumFormat::StrList::const_iterator it1 = aFileList.begin();
|
---|
1033 | it1 != aFileList.end();
|
---|
1034 | ++it1)
|
---|
1035 | {
|
---|
1036 | if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0)
|
---|
1037 | {
|
---|
1038 | format = *it;
|
---|
1039 | fFound = true;
|
---|
1040 | break;
|
---|
1041 | }
|
---|
1042 | }
|
---|
1043 | }
|
---|
1044 |
|
---|
1045 | return format;
|
---|
1046 | }
|
---|
1047 |
|
---|
1048 | // private methods
|
---|
1049 | /////////////////////////////////////////////////////////////////////////////
|
---|
1050 |
|
---|
1051 | /**
|
---|
1052 | * Returns the user's home directory. Wrapper around RTPathUserHome().
|
---|
1053 | * @param strPath
|
---|
1054 | * @return
|
---|
1055 | */
|
---|
1056 | HRESULT SystemProperties::getUserHomeDirectory(Utf8Str &strPath)
|
---|
1057 | {
|
---|
1058 | char szHome[RTPATH_MAX];
|
---|
1059 | int vrc = RTPathUserHome(szHome, sizeof(szHome));
|
---|
1060 | if (RT_FAILURE(vrc))
|
---|
1061 | return setError(E_FAIL,
|
---|
1062 | tr("Cannot determine user home directory (%Rrc)"),
|
---|
1063 | vrc);
|
---|
1064 | strPath = szHome;
|
---|
1065 | return S_OK;
|
---|
1066 | }
|
---|
1067 |
|
---|
1068 | /**
|
---|
1069 | * Internal implementation to set the default machine folder. Gets called
|
---|
1070 | * from the public attribute setter as well as loadSettings(). With 4.0,
|
---|
1071 | * the "default default" machine folder has changed, and we now require
|
---|
1072 | * a full path always.
|
---|
1073 | * @param aPath
|
---|
1074 | * @return
|
---|
1075 | */
|
---|
1076 | HRESULT SystemProperties::setDefaultMachineFolder(const Utf8Str &strPath)
|
---|
1077 | {
|
---|
1078 | Utf8Str path(strPath); // make modifiable
|
---|
1079 | if ( path.isEmpty() // used by API calls to reset the default
|
---|
1080 | || path == "Machines" // this value (exactly like this, without path) is stored
|
---|
1081 | // in VirtualBox.xml if user upgrades from before 4.0 and
|
---|
1082 | // has not changed the default machine folder
|
---|
1083 | )
|
---|
1084 | {
|
---|
1085 | // new default with VirtualBox 4.0: "$HOME/VirtualBox VMs"
|
---|
1086 | HRESULT rc = getUserHomeDirectory(path);
|
---|
1087 | if (FAILED(rc)) return rc;
|
---|
1088 | path += RTPATH_SLASH_STR "VirtualBox VMs";
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | if (!RTPathStartsWithRoot(path.c_str()))
|
---|
1092 | return setError(E_INVALIDARG,
|
---|
1093 | tr("Given default machine folder '%s' is not fully qualified"),
|
---|
1094 | path.c_str());
|
---|
1095 |
|
---|
1096 | m->strDefaultMachineFolder = path;
|
---|
1097 |
|
---|
1098 | return S_OK;
|
---|
1099 | }
|
---|
1100 |
|
---|
1101 | HRESULT SystemProperties::setDefaultHardDiskFormat(const Utf8Str &aFormat)
|
---|
1102 | {
|
---|
1103 | if (!aFormat.isEmpty())
|
---|
1104 | m->strDefaultHardDiskFormat = aFormat;
|
---|
1105 | else
|
---|
1106 | m->strDefaultHardDiskFormat = "VDI";
|
---|
1107 |
|
---|
1108 | return S_OK;
|
---|
1109 | }
|
---|
1110 |
|
---|
1111 | HRESULT SystemProperties::setVRDEAuthLibrary(const Utf8Str &aPath)
|
---|
1112 | {
|
---|
1113 | if (!aPath.isEmpty())
|
---|
1114 | m->strVRDEAuthLibrary = aPath;
|
---|
1115 | else
|
---|
1116 | m->strVRDEAuthLibrary = "VBoxAuth";
|
---|
1117 |
|
---|
1118 | return S_OK;
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | HRESULT SystemProperties::setWebServiceAuthLibrary(const Utf8Str &aPath)
|
---|
1122 | {
|
---|
1123 | if (!aPath.isEmpty())
|
---|
1124 | m->strWebServiceAuthLibrary = aPath;
|
---|
1125 | else
|
---|
1126 | m->strWebServiceAuthLibrary = "VBoxAuth";
|
---|
1127 |
|
---|
1128 | return S_OK;
|
---|
1129 | }
|
---|
1130 |
|
---|
1131 | HRESULT SystemProperties::setDefaultVRDEExtPack(const Utf8Str &aExtPack)
|
---|
1132 | {
|
---|
1133 | m->strDefaultVRDEExtPack = aExtPack;
|
---|
1134 |
|
---|
1135 | return S_OK;
|
---|
1136 | }
|
---|