Changeset 24810 in vbox
- Timestamp:
- Nov 19, 2009 7:17:02 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ApplianceImpl.cpp
r24526 r24810 1424 1424 } 1425 1425 1426 // Floppy support1427 std::list<VirtualSystemDescriptionEntry*> vsdeFloppy = vsdescThis->findByType(VirtualSystemDescriptionType_Floppy);1428 if (vsdeFloppy.size() > 1)1429 throw setError(VBOX_E_FILE_ERROR,1430 tr("Too many floppy controllers in OVF; import facility only supports one"));1431 if (vsdeFloppy.size() == 1)1432 {1433 ComPtr<IStorageController> pController;1434 rc = pNewMachine->AddStorageController(Bstr("Floppy Controller"), StorageBus_Floppy, pController.asOutParam());1435 if (FAILED(rc)) throw rc;1436 1437 Bstr bstrName;1438 rc = pController->COMGETTER(Name)(bstrName.asOutParam());1439 if (FAILED(rc)) throw rc;1440 1441 rc = pNewMachine->AttachDevice(bstrName, 0, 0, DeviceType_Floppy, Bstr(""));1442 if (FAILED(rc)) throw rc;1443 }1444 1445 1426 /* Hard disk controller IDE */ 1446 1427 std::list<VirtualSystemDescriptionEntry*> vsdeHDCIDE = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskControllerIDE); … … 1528 1509 llMachinesRegistered.push_back(newMachineId); 1529 1510 1511 // Add floppies and CD-ROMs to the appropriate controllers. 1512 std::list<VirtualSystemDescriptionEntry*> vsdeFloppy = vsdescThis->findByType(VirtualSystemDescriptionType_Floppy); 1513 if (vsdeFloppy.size() > 1) 1514 throw setError(VBOX_E_FILE_ERROR, 1515 tr("Too many floppy controllers in OVF; import facility only supports one")); 1516 std::list<VirtualSystemDescriptionEntry*> vsdeCDROM = vsdescThis->findByType(VirtualSystemDescriptionType_CDROM); 1517 if ( (vsdeFloppy.size() > 0) 1518 || (vsdeCDROM.size() > 0) 1519 ) 1520 { 1521 // If there's an error here we need to close the session, so 1522 // we need another try/catch block. 1523 1524 try 1525 { 1526 /* In order to attach things we need to open a session 1527 * for the new machine */ 1528 rc = mVirtualBox->OpenSession(session, newMachineId_); 1529 if (FAILED(rc)) throw rc; 1530 fSessionOpen = true; 1531 1532 ComPtr<IMachine> sMachine; 1533 rc = session->COMGETTER(Machine)(sMachine.asOutParam()); 1534 if (FAILED(rc)) throw rc; 1535 1536 // floppy first 1537 if (vsdeFloppy.size() == 1) 1538 { 1539 ComPtr<IStorageController> pController; 1540 rc = sMachine->AddStorageController(Bstr("Floppy Controller"), StorageBus_Floppy, pController.asOutParam()); 1541 if (FAILED(rc)) throw rc; 1542 1543 Bstr bstrName; 1544 rc = pController->COMGETTER(Name)(bstrName.asOutParam()); 1545 if (FAILED(rc)) throw rc; 1546 1547 // this is for rollback later 1548 MyHardDiskAttachment mhda; 1549 mhda.uuid = newMachineId; 1550 mhda.pMachine = pNewMachine; 1551 mhda.controllerType = bstrName; 1552 mhda.lChannel = 0; 1553 mhda.lDevice = 0; 1554 1555 Log(("Attaching floppy\n")); 1556 1557 rc = sMachine->AttachDevice(mhda.controllerType, 1558 mhda.lChannel, 1559 mhda.lDevice, 1560 DeviceType_Floppy, 1561 Bstr("")); 1562 if (FAILED(rc)) throw rc; 1563 1564 llHardDiskAttachments.push_back(mhda); 1565 } 1566 1567 1568 // CD-ROMs next 1569 for (std::list<VirtualSystemDescriptionEntry*>::const_iterator it = vsdeCDROM.begin(); 1570 it != vsdeCDROM.end(); 1571 ++it) 1572 { 1573 // for now always attach to secondary master on IDE controller; 1574 // there seems to be no useful information in OVF where else to 1575 // attach it (@todo test with latest versions of OVF software) 1576 1577 // find the IDE controller 1578 const HardDiskController *pController = NULL; 1579 for (ControllersMap::const_iterator it = vsysThis.mapControllers.begin(); 1580 it != vsysThis.mapControllers.end(); 1581 ++it) 1582 { 1583 if (it->second.system == HardDiskController::IDE) 1584 { 1585 pController = &it->second; 1586 } 1587 } 1588 1589 if (!pController) 1590 throw setError(VBOX_E_FILE_ERROR, 1591 tr("OVF wants a CD-ROM drive but cannot find IDE controller, which is required in this version of VirtualBox")); 1592 1593 // this is for rollback later 1594 MyHardDiskAttachment mhda; 1595 mhda.uuid = newMachineId; 1596 mhda.pMachine = pNewMachine; 1597 1598 ConvertDiskAttachmentValues(*pController, 1599 2, // interpreted as secondary master 1600 mhda.controllerType, // Bstr 1601 mhda.lChannel, 1602 mhda.lDevice); 1603 1604 Log(("Attaching CD-ROM to channel %d on device %d\n", mhda.lChannel, mhda.lDevice)); 1605 1606 rc = sMachine->AttachDevice(mhda.controllerType, 1607 mhda.lChannel, 1608 mhda.lDevice, 1609 DeviceType_DVD, 1610 Bstr("")); 1611 if (FAILED(rc)) throw rc; 1612 1613 llHardDiskAttachments.push_back(mhda); 1614 } // end for (itHD = avsdeHDs.begin(); 1615 1616 rc = sMachine->SaveSettings(); 1617 if (FAILED(rc)) throw rc; 1618 1619 // only now that we're done with all disks, close the session 1620 rc = session->Close(); 1621 if (FAILED(rc)) throw rc; 1622 fSessionOpen = false; 1623 } 1624 catch(HRESULT /* aRC */) 1625 { 1626 if (fSessionOpen) 1627 session->Close(); 1628 1629 throw; 1630 } 1631 } 1632 1530 1633 /* Create the hard disks & connect them to the appropriate controllers. */ 1531 1634 std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage); 1532 1635 if (avsdeHDs.size() > 0) 1533 1636 { 1534 / * If in the next block an error occur we have to deregister1535 the machine, so make an extra try/catch block. */1637 // If there's an error here we need to close the session, so 1638 // we need another try/catch block. 1536 1639 ComPtr<IMedium> srcHdVBox; 1537 1640 bool fSourceHdNeedsClosing = false; … … 1699 1802 rc = sMachine->SaveSettings(); 1700 1803 if (FAILED(rc)) throw rc; 1701 } // end for (itHD = avsdeHDs.begin();1702 1703 // only now that we're done with all disks, close the session1704 rc = session->Close();1705 if (FAILED(rc)) throw rc;1706 fSessionOpen = false;1707 }1708 catch(HRESULT /* aRC */)1709 {1710 if (fSourceHdNeedsClosing)1711 srcHdVBox->Close();1712 1713 if (fSessionOpen)1714 session->Close();1715 1716 throw;1717 }1718 }1719 1720 // Add CD-ROMs to the appropriate controllers.1721 std::list<VirtualSystemDescriptionEntry*> vsdeCDROM = vsdescThis->findByType(VirtualSystemDescriptionType_CDROM);1722 if (avsdeHDs.size() > 0)1723 {1724 /* If in the next block an error occur we have to deregister1725 the machine, so make an extra try/catch block. */1726 ComPtr<IMedium> srcHdVBox;1727 bool fSourceHdNeedsClosing = false;1728 1729 try1730 {1731 /* In order to attach hard disks we need to open a session1732 * for the new machine */1733 rc = mVirtualBox->OpenSession(session, newMachineId_);1734 if (FAILED(rc)) throw rc;1735 fSessionOpen = true;1736 1737 for (std::list<VirtualSystemDescriptionEntry*>::const_iterator it = vsdeCDROM.begin();1738 it != vsdeCDROM.end();1739 ++it)1740 {1741 // for now always attach to secondary master on IDE controller;1742 // there seems to be no useful information in OVF where else to1743 // attach it (@todo test with latest versions of OVF software)1744 1745 // find the IDE controller1746 const HardDiskController *pController = NULL;1747 for (ControllersMap::const_iterator it = vsysThis.mapControllers.begin();1748 it != vsysThis.mapControllers.end();1749 ++it)1750 {1751 if (it->second.system == HardDiskController::IDE)1752 {1753 pController = &it->second;1754 }1755 }1756 1757 if (!pController)1758 throw setError(VBOX_E_FILE_ERROR,1759 tr("OVF wants a CD-ROM drive but cannot find IDE controller, which is required in this version of VirtualBox"));1760 1761 // this is for rollback later1762 MyHardDiskAttachment mhda;1763 mhda.uuid = newMachineId;1764 mhda.pMachine = pNewMachine;1765 1766 ConvertDiskAttachmentValues(*pController,1767 2, // interpreted as secondary master1768 mhda.controllerType, // Bstr1769 mhda.lChannel,1770 mhda.lDevice);1771 1772 Log(("Attaching CD-ROM to channel %d on device %d\n", mhda.lChannel, mhda.lDevice));1773 1774 ComPtr<IMachine> sMachine;1775 rc = session->COMGETTER(Machine)(sMachine.asOutParam());1776 if (FAILED(rc)) throw rc;1777 1778 rc = sMachine->AttachDevice(mhda.controllerType,1779 mhda.lChannel,1780 mhda.lDevice,1781 DeviceType_DVD,1782 Bstr(""));1783 if (FAILED(rc)) throw rc;1784 1785 llHardDiskAttachments.push_back(mhda);1786 1787 rc = sMachine->SaveSettings();1788 if (FAILED(rc)) throw rc;1789 1790 1804 } // end for (itHD = avsdeHDs.begin(); 1791 1805
Note:
See TracChangeset
for help on using the changeset viewer.