- Timestamp:
- Oct 22, 2010 11:52:30 AM (14 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ApplianceImplImport.cpp
r33336 r33344 1675 1675 strTargetPath.c_str()); 1676 1676 1677 const Utf8Str &strSourceOVF = di.strHref; 1678 1679 // construct source file path 1680 Utf8StrFmt strSrcFilePath("%s%c%s", stack.strSourceDir.c_str(), RTPATH_DELIMITER, strSourceOVF.c_str()); 1681 1682 // subprogress object for hard disk 1683 ComPtr<IProgress> pProgress2; 1684 1685 /**************** Check */ 1686 ComObjPtr<Progress> pProgress3; 1687 pProgress3.createObject(); 1688 HRESULT rc = pProgress3->init(mVirtualBox, static_cast<IAppliance*>(this), BstrFmt(tr("Creating medium")).raw(), TRUE); 1689 // rc = pProgress3->init(mVirtualBox, static_cast<IAppliance*>(this), BstrFmt(tr("Creating medium '%s'"), strTargetFilePath.c_str()).raw(), TRUE); 1677 ComObjPtr<Progress> pProgress; 1678 pProgress.createObject(); 1679 HRESULT rc = pProgress->init(mVirtualBox, static_cast<IAppliance*>(this), BstrFmt(tr("Creating medium '%s'"), strTargetPath.c_str()).raw(), TRUE); 1690 1680 if (FAILED(rc)) throw rc; 1691 /**************** Check */ 1692 1693 /* Figure out which format the user like to have. Default is VMDK. */ 1694 Utf8Str strFormat = "VMDK"; 1695 if (strTargetPath.endsWith("vdi", Utf8Str::CaseInsensitive)) 1696 strFormat = "VDI"; 1697 else if (strTargetPath.endsWith("vhd", Utf8Str::CaseInsensitive)) 1698 strFormat = "VHD"; 1681 1682 Utf8Str strTrgFormat = "VMDK"; 1683 SystemProperties *pSysProps = mVirtualBox->getSystemProperties(); 1684 if (RTPathHaveExt(strTargetPath.c_str())) 1685 { 1686 char *pszExt = RTPathExt(strTargetPath.c_str()); 1687 /* Figure out which format the user like to have. Default is VMDK. */ 1688 ComObjPtr<MediumFormat> targetFormat = pSysProps->mediumFormatFromExtension(&pszExt[1]); 1689 if (targetFormat.isNull()) 1690 throw setError(VBOX_E_NOT_SUPPORTED, 1691 tr("Could not find a valid medium format for the target disk '%s'"), 1692 strTargetPath.c_str()); 1693 Bstr bstrFormatName; 1694 rc = targetFormat->COMGETTER(Name)(bstrFormatName.asOutParam()); 1695 if (FAILED(rc)) throw rc; 1696 strTrgFormat = Utf8Str(bstrFormatName); 1697 } 1699 1698 1700 1699 bool fNeedsGlobalSaveSettings; … … 1702 1701 pTargetHD.createObject(); 1703 1702 rc = pTargetHD->init(mVirtualBox, 1704 str Format,1703 strTrgFormat, 1705 1704 strTargetPath, 1706 1705 Guid::Empty, // media registry … … 1714 1713 if (FAILED(rc)) throw rc; 1715 1714 1715 const Utf8Str &strSourceOVF = di.strHref; 1716 // construct source file path 1717 Utf8StrFmt strSrcFilePath("%s%c%s", stack.strSourceDir.c_str(), RTPATH_DELIMITER, strSourceOVF.c_str()); 1718 1716 1719 /* If strHref is empty we have to create a new file */ 1717 1720 if (strSourceOVF.isEmpty()) 1718 1721 { 1719 1722 // create a dynamic growing disk image with the given capacity 1720 rc = pTargetHD->CreateBaseStorage(di.iCapacity / _1M, MediumVariant_Standard, pProgress2.asOutParam());1723 rc = pTargetHD->CreateBaseStorage(di.iCapacity / _1M, MediumVariant_Standard, ComPtr<IProgress>(pProgress).asOutParam()); 1721 1724 if (FAILED(rc)) throw rc; 1722 1725 … … 1734 1737 Utf8Str strSrcFormat = "VDI"; 1735 1738 if ( di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#sparse", Utf8Str::CaseInsensitive) 1736 1737 1738 1739 || di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized", Utf8Str::CaseInsensitive) 1740 || di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive) 1741 || di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive) 1739 1742 ) 1740 strSrcFormat = "VMDK"; 1741 SystemProperties *pSysProps = mVirtualBox->getSystemProperties(); 1742 AutoReadLock propsLock(pSysProps COMMA_LOCKVAL_SRC_POS); 1743 strSrcFormat = "VMDK1"; 1743 1744 format = pSysProps->mediumFormat(strSrcFormat); 1744 1745 if (format.isNull()) 1745 1746 throw setError(VBOX_E_NOT_SUPPORTED, 1746 tr("Invalid medium storage format")); 1747 tr("Could not find a valid medium format for the source disk '%s'"), 1748 RTPathFilename(strSrcFilePath.c_str())); 1747 1749 } 1748 1750 … … 1754 1756 pCallbacks, pStorage, 1755 1757 nullParent, 1756 pProgress 3);1758 pProgress); 1757 1759 1758 1760 /* Advance to the next operation */ … … 1762 1764 1763 1765 // now wait for the background disk operation to complete; this throws HRESULTs on error 1764 ComPtr<IProgress> pp(pProgress 3);1766 ComPtr<IProgress> pp(pProgress); 1765 1767 waitForAsyncProgress(stack.pProgress, pp); 1766 1768 -
trunk/src/VBox/Main/SystemPropertiesImpl.cpp
r33240 r33344 850 850 } 851 851 852 /** 853 * Returns a medium format object corresponding to the given file extension or 854 * null if no such format. 855 * 856 * @param aExt File extension. 857 * 858 * @return ComObjPtr<MediumFormat> 859 */ 860 ComObjPtr<MediumFormat> SystemProperties::mediumFormatFromExtension(const Utf8Str &aExt) 861 { 862 ComObjPtr<MediumFormat> format; 863 864 AutoCaller autoCaller(this); 865 AssertComRCReturn (autoCaller.rc(), format); 866 867 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 868 869 bool fFound = false; 870 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin(); 871 it != m_llMediumFormats.end() && !fFound; 872 ++it) 873 { 874 /* MediumFormat is all const, no need to lock */ 875 MediumFormat::StrList aFileList = (*it)->getFileExtensions(); 876 for (MediumFormat::StrList::const_iterator it1 = aFileList.begin(); 877 it1 != aFileList.end(); 878 ++it1) 879 { 880 if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0) 881 { 882 format = *it; 883 fFound = true; 884 break; 885 } 886 } 887 } 888 889 return format; 890 } 891 852 892 // private methods 853 893 ///////////////////////////////////////////////////////////////////////////// -
trunk/src/VBox/Main/include/SystemPropertiesImpl.h
r33238 r33344 107 107 108 108 ComObjPtr<MediumFormat> mediumFormat(const Utf8Str &aFormat); 109 ComObjPtr<MediumFormat> mediumFormatFromExtension(const Utf8Str &aExt); 109 110 110 111 // public methods for internal purposes only
Note:
See TracChangeset
for help on using the changeset viewer.