Index: /trunk/src/VBox/Main/include/ApplianceImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/ApplianceImpl.h	(revision 49619)
+++ /trunk/src/VBox/Main/include/ApplianceImpl.h	(revision 49620)
@@ -23,4 +23,5 @@
 /* VBox includes */
 #include "VirtualBoxBase.h"
+#include "MediumFormatImpl.h"
 
 /* Todo: This file needs massive cleanup. Split IAppliance in a public and
@@ -154,4 +155,6 @@
 
     Utf8Str applianceIOName(APPLIANCEIONAME type) const;
+
+    HRESULT findMediumFormatFromDiskImage(const ovf::DiskImage &di, ComObjPtr<MediumFormat>& mf);
 
     /*******************************************************************************
Index: /trunk/src/VBox/Main/src-server/ApplianceImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/ApplianceImpl.cpp	(revision 49619)
+++ /trunk/src/VBox/Main/src-server/ApplianceImpl.cpp	(revision 49620)
@@ -29,5 +29,4 @@
 #include "ProgressImpl.h"
 #include "MachineImpl.h"
-#include "MediumFormatImpl.h"
 #include "SystemPropertiesImpl.h"
 #include "AutoCaller.h"
@@ -728,4 +727,52 @@
 }
 
+
+/**
+ * Returns a medium format object corresponding to the given 
+ * disk image or null if no such format. 
+ *
+ * @param di   Disk Image
+ * @param mf   Medium Format
+ *
+ * @return ComObjPtr<MediumFormat>
+ */
+HRESULT Appliance::findMediumFormatFromDiskImage(const ovf::DiskImage &di, ComObjPtr<MediumFormat>& mf)
+{
+    HRESULT rc = S_OK;
+
+    /* Get the system properties. */
+    SystemProperties *pSysProps = mVirtualBox->getSystemProperties();
+
+    /* We need a proper source format description */
+    /* Which format to use? */
+    Utf8Str strSrcFormat = typeOfVirtualDiskFormatFromURI(di.strFormat);
+
+    /*
+     * fallback, if we can't determine virtual disk format using URI from the attribute ovf:format
+     * in the corresponding section <Disk> in the OVF file.
+     */
+    if (strSrcFormat.isEmpty())
+    {
+        /* Figure out from extension which format the image of disk has. */
+        {
+            char *pszExt = RTPathSuffix(di.strHref.c_str());
+            if (pszExt)
+                pszExt++;
+            mf = pSysProps->mediumFormatFromExtension(pszExt);
+        }
+    }
+    else
+        mf = pSysProps->mediumFormat(strSrcFormat);
+
+    if (mf.isNull())
+    {
+        rc = setError(E_FAIL,
+               tr("Internal inconsistency looking up medium format for the disk image '%s'"),
+               di.strHref.c_str());
+    }
+
+    return rc;
+}
+
 /**
  * Returns true if the appliance is in "idle" state. This should always be the
Index: /trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp	(revision 49619)
+++ /trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp	(revision 49620)
@@ -631,35 +631,16 @@
                      * So possibly, we aren't able to recognize some URIs.
                      */
-                    Utf8Str vdf = typeOfVirtualDiskFormatFromURI(di.strFormat);
-
-                    /*
-                     * fallback, if we can't determine virtual disk format using URI from the attribute ovf:format
-                     * in the corresponding section <Disk> in the OVF file.
-                     */
-                    if (vdf.isEmpty())
-                    {
-                        /* Figure out from extension which format the image of disk has. */
-                        {
-                            char *pszExt = RTPathSuffix(di.strHref.c_str());
-                            if (pszExt)
-                                pszExt++;
-                            /* Get the system properties. */
-                            SystemProperties *pSysProps = mVirtualBox->getSystemProperties();
-                            ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension(pszExt);
-                            if (trgFormat.isNull())
-                            {
-                                throw setError(E_FAIL,
-                                       tr("Internal inconsistency looking up medium format for the disk image '%s'"),
-                                       di.strHref.c_str());
-                            }
-
-                            Bstr bstrFormatName;
-                            rc = trgFormat->COMGETTER(Name)(bstrFormatName.asOutParam());
-                            if (FAILED(rc))
-                                throw rc;
-
-                            vdf = Utf8Str(bstrFormatName);
-                        }
-                    }
+
+                    ComObjPtr<MediumFormat> mediumFormat;
+                    rc = findMediumFormatFromDiskImage(di, mediumFormat);
+                    if (FAILED(rc))
+                        throw rc;
+
+                    Bstr bstrFormatName;
+                    rc = mediumFormat->COMGETTER(Name)(bstrFormatName.asOutParam());
+                    if (FAILED(rc))
+                        throw rc;
+
+                    Utf8Str vdf = Utf8Str(bstrFormatName);
 
                     // @todo:
@@ -2301,5 +2282,4 @@
                 strTempTargetFilename = strTempTargetFilename.stripPath();
                 strTempTargetFilename = strTempTargetFilename.stripSuffix();
-                Utf8Str vdf = typeOfVirtualDiskFormatFromURI(di.strFormat);
 
                 strTargetDir.append(strTempTargetFilename);
@@ -2462,11 +2442,11 @@
                     /* We need a proper source format description */
                     /* Which format to use? */
-                    Utf8Str strSrcFormat = typeOfVirtualDiskFormatFromURI(di.strFormat);
-
-                    ComObjPtr<MediumFormat> srcFormat = pSysProps->mediumFormat(strSrcFormat);
-                    if (srcFormat.isNull())
+                    ComObjPtr<MediumFormat> srcFormat; 
+                    rc = findMediumFormatFromDiskImage(di, srcFormat);
+                    if (FAILED(rc))
                         throw setError(VBOX_E_NOT_SUPPORTED,
                                        tr("Could not find a valid medium format for the source disk '%s' "
-                                          "Check correctness of the image format URL in the OVF description file."),
+                                          "Check correctness of the image format URL in the OVF description file "
+                                          "or extension of the image"),
                                        RTPathFilename(strSourceOVF.c_str()));
 
@@ -3184,5 +3164,15 @@
                 vsdeTargetHD->strVboxCurrent.c_str(), mhda.lControllerPort, mhda.lDevice));
 
-                Utf8Str vdf = typeOfVirtualDiskFormatFromURI(diCurrent.strFormat);
+                ComObjPtr<MediumFormat> mediumFormat;
+                rc = findMediumFormatFromDiskImage(diCurrent, mediumFormat);
+                if (FAILED(rc))
+                    throw rc;
+
+                Bstr bstrFormatName;
+                rc = mediumFormat->COMGETTER(Name)(bstrFormatName.asOutParam());
+                if (FAILED(rc))
+                    throw rc;
+
+                Utf8Str vdf = Utf8Str(bstrFormatName);
 
                 if (vdf.compare("RAW", Utf8Str::CaseInsensitive) == 0)
@@ -3699,5 +3689,15 @@
                 Bstr hdId;
 
-                Utf8Str vdf = typeOfVirtualDiskFormatFromURI(diCurrent.strFormat);
+                ComObjPtr<MediumFormat> mediumFormat;
+                rc = findMediumFormatFromDiskImage(diCurrent, mediumFormat);
+                if (FAILED(rc))
+                    throw rc;
+
+                Bstr bstrFormatName;
+                rc = mediumFormat->COMGETTER(Name)(bstrFormatName.asOutParam());
+                if (FAILED(rc))
+                    throw rc;
+
+                Utf8Str vdf = Utf8Str(bstrFormatName);
 
                 if (vdf.compare("RAW", Utf8Str::CaseInsensitive) == 0)
