VirtualBox

Changeset 33344 in vbox for trunk/src


Ignore:
Timestamp:
Oct 22, 2010 11:52:30 AM (14 years ago)
Author:
vboxsync
Message:

Main-OVF: Select the target format out of the available formats.

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ApplianceImplImport.cpp

    r33336 r33344  
    16751675                       strTargetPath.c_str());
    16761676
    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);
    16901680    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    }
    16991698
    17001699    bool fNeedsGlobalSaveSettings;
     
    17021701    pTargetHD.createObject();
    17031702    rc = pTargetHD->init(mVirtualBox,
    1704                          strFormat,
     1703                         strTrgFormat,
    17051704                         strTargetPath,
    17061705                         Guid::Empty,        // media registry
     
    17141713    if (FAILED(rc)) throw rc;
    17151714
     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
    17161719    /* If strHref is empty we have to create a new file */
    17171720    if (strSourceOVF.isEmpty())
    17181721    {
    17191722        // 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());
    17211724        if (FAILED(rc)) throw rc;
    17221725
     
    17341737            Utf8Str strSrcFormat = "VDI";
    17351738            if (   di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#sparse", Utf8Str::CaseInsensitive)
    1736                    || di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized", Utf8Str::CaseInsensitive)
    1737                    || di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive)
    1738                    || di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive)
     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)
    17391742               )
    1740                 strSrcFormat = "VMDK";
    1741             SystemProperties *pSysProps = mVirtualBox->getSystemProperties();
    1742             AutoReadLock propsLock(pSysProps COMMA_LOCKVAL_SRC_POS);
     1743                strSrcFormat = "VMDK1";
    17431744            format = pSysProps->mediumFormat(strSrcFormat);
    17441745            if (format.isNull())
    17451746                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()));
    17471749        }
    17481750
     
    17541756                                   pCallbacks, pStorage,
    17551757                                   nullParent,
    1756                                    pProgress3);
     1758                                   pProgress);
    17571759
    17581760        /* Advance to the next operation */
     
    17621764
    17631765    // now wait for the background disk operation to complete; this throws HRESULTs on error
    1764     ComPtr<IProgress> pp(pProgress3);
     1766    ComPtr<IProgress> pp(pProgress);
    17651767    waitForAsyncProgress(stack.pProgress, pp);
    17661768
  • trunk/src/VBox/Main/SystemPropertiesImpl.cpp

    r33240 r33344  
    850850}
    851851
     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 */
     860ComObjPtr<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
    852892// private methods
    853893/////////////////////////////////////////////////////////////////////////////
  • trunk/src/VBox/Main/include/SystemPropertiesImpl.h

    r33238 r33344  
    107107
    108108    ComObjPtr<MediumFormat> mediumFormat(const Utf8Str &aFormat);
     109    ComObjPtr<MediumFormat> mediumFormatFromExtension(const Utf8Str &aExt);
    109110
    110111    // public methods for internal purposes only
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette