- Timestamp:
- Apr 19, 2007 4:25:53 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp
r2029 r2238 1025 1025 if (++curArg >= argc) 1026 1026 { 1027 RTPrintf("Error: missing file/device name for first hard disk!\n");1027 RTPrintf("Error: missing file/device name for cdrom!\n"); 1028 1028 rc = E_FAIL; 1029 1029 break; … … 1334 1334 { 1335 1335 /* we've not found the image */ 1336 RTPrintf("Registering hard disk image %s\n", hdaFile);1336 RTPrintf("Registering hard disk image '%S'...\n", hdaFile); 1337 1337 virtualBox->OpenHardDisk (hdaFileBstr, hardDisk.asOutParam()); 1338 1338 if (hardDisk) … … 1358 1358 } 1359 1359 1360 /* 1361 * Mount a floppy if requested. 1362 */ 1360 1363 if (fdaFile) 1361 { 1362 ComPtr<IFloppyDrive> floppyDrive; 1363 gMachine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam()); 1364 Assert(floppyDrive); 1365 1366 ComPtr<IFloppyImageCollection> collection; 1367 virtualBox->COMGETTER(FloppyImages)(collection.asOutParam()); 1368 Assert(collection); 1369 ComPtr<IFloppyImageEnumerator> enumerator; 1370 collection->Enumerate(enumerator.asOutParam()); 1371 Assert(enumerator); 1372 ComPtr<IFloppyImage> floppyImage; 1373 BOOL hasMore = false; 1374 while (enumerator->HasMore(&hasMore), hasMore) 1375 { 1376 enumerator->GetNext(floppyImage.asOutParam()); 1377 Assert(floppyImage); 1378 Bstr file; 1379 floppyImage->COMGETTER(FilePath)(file.asOutParam()); 1380 Assert(file); 1381 /// @todo this will not work on case insensitive systems if the casing does not match the registration!!! 1382 if (file == fdaFile) 1383 break; 1384 else 1385 floppyImage = NULL; 1386 } 1387 /* we've not found the image? */ 1388 if (!floppyImage) 1389 { 1390 RTPrintf("Registering floppy disk image %s\n", fdaFile); 1391 Guid uuid; 1392 Bstr fileBstr = fdaFile; 1393 virtualBox->OpenFloppyImage (fileBstr, uuid, floppyImage.asOutParam()); 1394 virtualBox->RegisterFloppyImage (floppyImage); 1395 } 1396 /* do we have the right image now? */ 1397 if (floppyImage) 1398 { 1399 /* 1400 * Go and attach it! 1401 */ 1402 Guid uuid; 1403 floppyImage->COMGETTER(Id)(uuid.asOutParam()); 1404 floppyDrive->MountImage(uuid); 1405 } 1406 else 1407 { 1408 RTPrintf("Error: failed to mount the specified floppy disk image!\n"); 1409 goto leave; 1410 } 1411 } 1412 1413 /* 1414 * Are we supposed to use a different CDROM image? 1415 */ 1416 if (cdromFile) 1417 { 1418 ComPtr<IDVDDrive> dvdDrive; 1419 gMachine->COMGETTER(DVDDrive)(dvdDrive.asOutParam()); 1420 Assert(dvdDrive); 1364 do 1365 { 1366 ComPtr<IFloppyDrive> drive; 1367 CHECK_ERROR_BREAK (gMachine, COMGETTER(FloppyDrive)(drive.asOutParam())); 1421 1368 1422 1369 /* 1423 1370 * First special case 'none' to unmount 1424 1371 */ 1425 if (strcmp(cdromFile, "none") == 0) 1426 { 1427 dvdDrive->Unmount(); 1428 } 1429 else 1430 { 1431 /* 1432 * Determine if it's a host device or ISO image 1433 */ 1434 bool fHostDrive = false; 1435 #ifdef __WIN__ 1436 /* two characters with the 2nd being a colon */ 1437 if ((strlen(cdromFile) == 2) && (cdromFile[1] == ':')) 1438 { 1439 cdromFile[0] = toupper(cdromFile[0]); 1440 fHostDrive = true; 1441 } 1442 #else /* !__WIN__ */ 1443 /* it has to start with /dev/ */ 1444 if (strncmp(cdromFile, "/dev/", 5) == 0) 1445 fHostDrive = true; 1446 #endif /* !__WIN__ */ 1447 if (fHostDrive) 1448 { 1449 ComPtr<IHost> host; 1450 virtualBox->COMGETTER(Host)(host.asOutParam()); 1451 ComPtr<IHostDVDDriveCollection> collection; 1452 host->COMGETTER(DVDDrives)(collection.asOutParam()); 1453 ComPtr<IHostDVDDriveEnumerator> enumerator; 1454 collection->Enumerate(enumerator.asOutParam()); 1455 ComPtr<IHostDVDDrive> hostDVDDrive; 1456 BOOL hasMore = FALSE; 1457 while (enumerator->HasMore(&hasMore), hasMore) 1458 { 1459 enumerator->GetNext(hostDVDDrive.asOutParam()); 1460 Bstr driveName; 1461 hostDVDDrive->COMGETTER(Name)(driveName.asOutParam()); 1462 Utf8Str driveNameUtf8 = driveName; 1463 char *driveNameStr = (char*)driveNameUtf8.raw(); 1464 if (strcmp(driveNameStr, cdromFile) == 0) 1465 { 1466 rc = dvdDrive->CaptureHostDrive(hostDVDDrive); 1467 if (rc != S_OK) 1468 { 1469 RTPrintf("Error: could not mount host DVD drive %s! rc = 0x%x\n", driveNameStr, rc); 1470 } 1471 break; 1472 } 1473 } 1474 if (!hasMore) 1475 RTPrintf("Error: did not recognize DVD drive '%s'!\n", cdromFile); 1476 } 1477 else 1478 { 1479 /* 1480 * Same strategy as with the HDD images: check if already registered, 1481 * if not, register on the fly. 1482 */ 1483 ComPtr<IDVDImageCollection> collection; 1484 virtualBox->COMGETTER(DVDImages)(collection.asOutParam()); 1485 Assert(collection); 1486 ComPtr<IDVDImageEnumerator> enumerator; 1487 collection->Enumerate(enumerator.asOutParam()); 1488 Assert(enumerator); 1489 ComPtr<IDVDImage> dvdImage; 1490 BOOL hasMore = false; 1491 while (enumerator->HasMore(&hasMore), hasMore) 1492 { 1493 enumerator->GetNext(dvdImage.asOutParam()); 1494 Assert(dvdImage); 1495 Bstr dvdImageFile; 1496 dvdImage->COMGETTER(FilePath)(dvdImageFile.asOutParam()); 1497 Assert(dvdImageFile); 1498 /// @todo not correct for case insensitive platforms (win32) 1499 /// See comment on hdaFile. 1500 if (dvdImageFile == cdromFile) 1501 break; 1502 else 1503 dvdImage = NULL; 1504 } 1505 /* we've not found the image? */ 1506 if (!dvdImage) 1507 { 1508 RTPrintf("Registering ISO image %s\n", cdromFile); 1509 Guid uuid; // the system will generate UUID 1510 Bstr cdImageFileBstr = cdromFile; 1511 virtualBox->OpenDVDImage(cdImageFileBstr, uuid, dvdImage.asOutParam()); 1512 rc = virtualBox->RegisterDVDImage(dvdImage); 1513 if (!SUCCEEDED(rc)) 1514 { 1515 RTPrintf("Image registration failed with %08X\n", rc); 1516 } 1517 } 1518 /* do we have the right image now? */ 1519 if (dvdImage) 1520 { 1521 /* attach */ 1522 Guid uuid; 1523 dvdImage->COMGETTER(Id)(uuid.asOutParam()); 1524 dvdDrive->MountImage(uuid); 1525 } 1526 else 1527 { 1528 RTPrintf("Error: failed to mount the specified ISO image!\n"); 1529 goto leave; 1530 } 1531 } 1532 } 1533 } 1372 if (strcmp (fdaFile, "none") == 0) 1373 { 1374 CHECK_ERROR_BREAK (drive, Unmount()); 1375 break; 1376 } 1377 1378 Bstr media = fdaFile; 1379 bool done = false; 1380 1381 /* Assume it's a host drive name */ 1382 { 1383 ComPtr <IHost> host; 1384 CHECK_ERROR_BREAK (virtualBox, COMGETTER(Host)(host.asOutParam())); 1385 ComPtr <IHostFloppyDriveCollection> coll; 1386 CHECK_ERROR_BREAK (host, COMGETTER(FloppyDrives)(coll.asOutParam())); 1387 ComPtr <IHostFloppyDrive> hostDrive; 1388 rc = coll->FindByName (media, hostDrive.asOutParam()); 1389 if (SUCCEEDED (rc)) 1390 { 1391 done = true; 1392 CHECK_ERROR_BREAK (drive, CaptureHostDrive (hostDrive)); 1393 } 1394 } 1395 1396 /* Must be an image */ 1397 if (!done) 1398 { 1399 /* try to find an existing one */ 1400 ComPtr <IFloppyImage> image; 1401 rc = virtualBox->FindFloppyImage (media, image.asOutParam()); 1402 if (FAILED (rc)) 1403 { 1404 /* try to register */ 1405 RTPrintf ("Registering floppy image '%S'...\n", fdaFile); 1406 Guid uuid; 1407 CHECK_ERROR_BREAK (virtualBox, OpenFloppyImage (media, uuid, 1408 image.asOutParam())); 1409 CHECK_ERROR_BREAK (virtualBox, RegisterFloppyImage (image)); 1410 } 1411 1412 /* attach */ 1413 Guid uuid; 1414 image->COMGETTER(Id)(uuid.asOutParam()); 1415 CHECK_ERROR_BREAK (drive, MountImage (uuid)); 1416 } 1417 } 1418 while (0); 1419 if (FAILED (rc)) 1420 goto leave; 1421 1422 /* 1423 * Mount a CD-ROM if requested. 1424 */ 1425 if (cdromFile) 1426 do 1427 { 1428 ComPtr<IDVDDrive> drive; 1429 CHECK_ERROR_BREAK (gMachine, COMGETTER(DVDDrive)(drive.asOutParam())); 1430 1431 /* 1432 * First special case 'none' to unmount 1433 */ 1434 if (strcmp (cdromFile, "none") == 0) 1435 { 1436 CHECK_ERROR_BREAK (drive, Unmount()); 1437 break; 1438 } 1439 1440 Bstr media = cdromFile; 1441 bool done = false; 1442 1443 /* Assume it's a host drive name */ 1444 { 1445 ComPtr <IHost> host; 1446 CHECK_ERROR_BREAK (virtualBox, COMGETTER(Host)(host.asOutParam())); 1447 ComPtr <IHostDVDDriveCollection> coll; 1448 CHECK_ERROR_BREAK (host, COMGETTER(DVDDrives)(coll.asOutParam())); 1449 ComPtr <IHostDVDDrive> hostDrive; 1450 rc = coll->FindByName (media, hostDrive.asOutParam()); 1451 if (SUCCEEDED (rc)) 1452 { 1453 done = true; 1454 CHECK_ERROR_BREAK (drive, CaptureHostDrive (hostDrive)); 1455 } 1456 } 1457 1458 /* Must be an image */ 1459 if (!done) 1460 { 1461 /* try to find an existing one */ 1462 ComPtr <IDVDImage> image; 1463 rc = virtualBox->FindDVDImage (media, image.asOutParam()); 1464 if (FAILED (rc)) 1465 { 1466 /* try to register */ 1467 RTPrintf ("Registering ISO image '%S'...\n", cdromFile); 1468 Guid uuid; 1469 CHECK_ERROR_BREAK (virtualBox, OpenDVDImage (media, uuid, 1470 image.asOutParam())); 1471 CHECK_ERROR_BREAK (virtualBox, RegisterDVDImage (image)); 1472 } 1473 1474 /* attach */ 1475 Guid uuid; 1476 image->COMGETTER(Id)(uuid.asOutParam()); 1477 CHECK_ERROR_BREAK (drive, MountImage (uuid)); 1478 } 1479 } 1480 while (0); 1481 if (FAILED (rc)) 1482 goto leave; 1534 1483 1535 1484 if (fDiscardState)
Note:
See TracChangeset
for help on using the changeset viewer.