- Timestamp:
- Mar 27, 2015 6:56:06 AM (10 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageAppliance.cpp
r50447 r54979 92 92 else if (!RTStrNICmp(psz, "KeepNATMACs", len)) 93 93 options->push_back(ImportOptions_KeepNATMACs); 94 else if (!RTStrNICmp(psz, "ImportToVDI", len)) 95 options->push_back(ImportOptions_ImportToVDI); 94 96 else 95 97 rc = VERR_PARSE_ERROR; … … 338 340 if (retDisks.size() > 0) 339 341 { 340 RTPrintf("Disks: ");342 RTPrintf("Disks:\n"); 341 343 for (unsigned i = 0; i < retDisks.size(); i++) 342 RTPrintf(" %ls ", retDisks[i]);344 RTPrintf(" %ls\n", retDisks[i]); 343 345 RTPrintf("\n"); 344 346 } … … 634 636 { 635 637 Utf8StrFmt strTypeArg("disk%u", a); 638 RTCList<ImportOptions_T> optionsList = options.toList(); 639 640 bstrFinalValue = aVBoxValues[a]; 641 636 642 if (findArgValue(strOverride, pmapArgs, strTypeArg)) 637 643 { 638 RTUUID uuid; 639 /* Check if this is a uuid. If so, don't touch. */ 640 int vrc = RTUuidFromStr(&uuid, strOverride.c_str()); 641 if (vrc != VINF_SUCCESS) 644 if(!optionsList.contains(ImportOptions_ImportToVDI)) 642 645 { 643 /* Make the path absolute. */ 644 if (!RTPathStartsWithRoot(strOverride.c_str())) 646 RTUUID uuid; 647 /* Check if this is a uuid. If so, don't touch. */ 648 int vrc = RTUuidFromStr(&uuid, strOverride.c_str()); 649 if (vrc != VINF_SUCCESS) 645 650 { 646 char pszPwd[RTPATH_MAX]; 647 vrc = RTPathGetCurrent(pszPwd, RTPATH_MAX); 648 if (RT_SUCCESS(vrc)) 649 strOverride = Utf8Str(pszPwd).append(RTPATH_SLASH).append(strOverride); 651 /* Make the path absolute. */ 652 if (!RTPathStartsWithRoot(strOverride.c_str())) 653 { 654 char pszPwd[RTPATH_MAX]; 655 vrc = RTPathGetCurrent(pszPwd, RTPATH_MAX); 656 if (RT_SUCCESS(vrc)) 657 strOverride = Utf8Str(pszPwd).append(RTPATH_SLASH).append(strOverride); 658 } 650 659 } 660 bstrFinalValue = strOverride; 651 661 } 652 bstrFinalValue = strOverride; 662 else 663 { 664 //print some error about incompatible command-line arguments 665 return errorSyntax(USAGE_IMPORTAPPLIANCE, 666 "Option --ImportToVDI shall not be used together with " 667 "manually set target path."); 668 669 } 670 653 671 RTPrintf("%2u: Hard disk image: source image=%ls, target path=%ls, %ls\n", 654 672 a, … … 677 695 #endif 678 696 else 697 { 698 strOverride = aVBoxValues[a]; 699 700 /* 701 * Current solution isn't optimal. 702 * Better way is to provide API call for function 703 * Appliance::i_findMediumFormatFromDiskImage() 704 * and creating one new function which returns 705 * struct ovf::DiskImage for currently processed disk. 706 */ 707 708 /* 709 * if user wants to convert all imported disks to VDI format 710 * we need to replace files extensions to "vdi" 711 * except CD/DVD disks 712 */ 713 if(optionsList.contains(ImportOptions_ImportToVDI)) 714 { 715 ComPtr<IVirtualBox> pVirtualBox = arg->virtualBox; 716 ComPtr<ISystemProperties> systemProperties; 717 com::SafeIfaceArray<IMediumFormat> mediumFormats; 718 Bstr bstrFormatName; 719 720 CHECK_ERROR(pVirtualBox, 721 COMGETTER(SystemProperties)(systemProperties.asOutParam())); 722 723 CHECK_ERROR(systemProperties, 724 COMGETTER(MediumFormats)(ComSafeArrayAsOutParam(mediumFormats))); 725 726 /* go through all supported media formats and store files extensions only for RAW */ 727 com::SafeArray<BSTR> extensions; 728 729 for (unsigned i = 0; i < mediumFormats.size(); ++i) 730 { 731 com::SafeArray<DeviceType_T> deviceType; 732 ComPtr<IMediumFormat> mediumFormat = mediumFormats[i]; 733 CHECK_ERROR(mediumFormat, COMGETTER(Name)(bstrFormatName.asOutParam())); 734 Utf8Str strFormatName = Utf8Str(bstrFormatName); 735 736 if (strFormatName.compare("RAW", Utf8Str::CaseInsensitive) == 0) 737 { 738 /* getting files extensions for "RAW" format */ 739 CHECK_ERROR(mediumFormat, 740 DescribeFileExtensions(ComSafeArrayAsOutParam(extensions), 741 ComSafeArrayAsOutParam(deviceType))); 742 break; 743 } 744 } 745 746 /* go through files extensions for RAW format and compare them with 747 * extension of current file 748 */ 749 bool b_replace = true; 750 751 const char *pszExtension = RTPathSuffix(strOverride.c_str()); 752 if (pszExtension) 753 pszExtension++; 754 755 for (unsigned i = 0; i < extensions.size(); ++i) 756 { 757 Utf8Str strExtension(Bstr((extensions[i]))); 758 if(strExtension.compare(pszExtension, Utf8Str::CaseInsensitive) == 0) 759 { 760 b_replace = false; 761 break; 762 } 763 } 764 765 if (b_replace==true) 766 { 767 strOverride = strOverride.stripSuffix(); 768 strOverride = strOverride.append(".").append("vdi"); 769 } 770 } 771 772 bstrFinalValue = strOverride; 773 679 774 RTPrintf("%2u: Hard disk image: source image=%ls, target path=%ls, %ls" 680 775 "\n (change target path with \"--vsys %u --unit %u --disk path\";" … … 682 777 a, 683 778 aOvfValues[a], 684 aVBoxValues[a],779 bstrFinalValue.raw(), 685 780 aExtraConfigValues[a], 686 781 i, a, i, a); 782 } 687 783 } 688 784 break; -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r54911 r54979 409 409 "%s import %s <ovfname/ovaname>\n" 410 410 " [--dry-run|-n]\n" 411 " [--options keepallmacs|keepnatmacs ]\n"411 " [--options keepallmacs|keepnatmacs|importtovdi]\n" 412 412 " [more options]\n" 413 413 " (run with -n to have options displayed\n" -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r54976 r54979 2941 2941 </const> 2942 2942 2943 <const name="ImportToVDI" value="3"> 2944 <desc>Import all disks to VDI format</desc> 2945 </const> 2946 2943 2947 </enum> 2944 2948 -
trunk/src/VBox/Main/src-server/ApplianceImpl.cpp
r50899 r54979 742 742 if (strSrcFormat.isEmpty()) 743 743 { 744 strSrcFormat = di.strHref; 745 746 /* check either file gzipped or not 747 * if "yes" then remove last extension, 748 * i.e. "image.vmdk.gz"->"image.vmdk" 749 */ 750 if (di.strCompression == "gzip") 751 { 752 if (RTPathHasSuffix(strSrcFormat.c_str())) 753 { 754 strSrcFormat.stripSuffix(); 755 } 756 else 757 { 758 mf.setNull(); 759 rc = setError(E_FAIL, 760 tr("Internal inconsistency looking up medium format for the disk image '%s'"), 761 di.strHref.c_str()); 762 return rc; 763 } 764 } 744 765 /* Figure out from extension which format the image of disk has. */ 766 if (RTPathHasSuffix(strSrcFormat.c_str())) 745 767 { 746 c har *pszExt = RTPathSuffix(di.strHref.c_str());768 const char *pszExt = RTPathSuffix(strSrcFormat.c_str()); 747 769 if (pszExt) 748 770 pszExt++; 749 771 mf = pSysProps->i_mediumFormatFromExtension(pszExt); 750 772 } 773 else 774 mf.setNull(); 751 775 } 752 776 else -
trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
r54438 r54979 649 649 Utf8Str strTargetPath = Utf8Str(strMachineFolder); 650 650 strTargetPath.append(RTPATH_DELIMITER).append(di.strHref); 651 /* 652 * Remove last extension from the file name if the file is compressed 653 */ 654 if(di.strCompression.compare("gzip", Utf8Str::CaseInsensitive)==0) 655 { 656 strTargetPath.stripSuffix(); 657 } 658 651 659 i_searchUniqueDiskImageFilePath(strTargetPath); 652 660 … … 682 690 .append(RTPATH_DELIMITER) 683 691 .append(di.strHref); 692 /* 693 * Remove last extension from the file name if the file is compressed 694 */ 695 if(di.strCompression.compare("gzip", Utf8Str::CaseInsensitive)==0) 696 { 697 strTargetPath.stripSuffix(); 698 } 699 684 700 i_searchUniqueDiskImageFilePath(strTargetPath); 685 701 … … 2381 2397 /* Decompress the GZIP file and save a new file in the target path */ 2382 2398 strTargetDir = strTargetDir.stripFilename(); 2383 strTargetDir.append("/temp_"); 2384 2385 Utf8Str strTempTargetFilename(*strTargetPath); 2399 strTargetDir.append(RTPATH_SLASH_STR); 2400 strTargetDir.append("temp_"); 2401 2402 Utf8Str strTempTargetFilename(strSrcFilePath); 2386 2403 strTempTargetFilename = strTempTargetFilename.stripPath(); 2387 strTempTargetFilename = strTempTargetFilename.stripSuffix();2388 2404 2389 2405 strTargetDir.append(strTempTargetFilename); … … 2412 2428 /* Correct the source and the target with the actual values */ 2413 2429 strSrcFilePath = strTargetDir; 2414 strTargetDir = strTargetDir.stripFilename();2415 strTargetDir.append(RTPATH_SLASH_STR);2416 strTargetDir.append(strTempTargetFilename.c_str());2417 *strTargetPath = strTargetDir.c_str();2418 2430 2419 2431 pRealUsedStorage = &finalStorage; … … 2421 2433 2422 2434 Utf8Str strTrgFormat = "VMDK"; 2435 ComObjPtr<MediumFormat> trgFormat; 2436 Bstr bstrFormatName; 2423 2437 ULONG lCabs = 0; 2424 2438 2425 if (RTPathHasSuffix(strTargetPath->c_str())) 2426 { 2427 const char *pszSuff = RTPathSuffix(strTargetPath->c_str()); 2428 /* Figure out which format the user like to have. Default is VMDK. */ 2429 ComObjPtr<MediumFormat> trgFormat = pSysProps->i_mediumFormatFromExtension(&pszSuff[1]); 2439 //check existence of option "ImportToVDI", in this case all imported disks will be converted to VDI images 2440 bool chExt = m->optListImport.contains(ImportOptions_ImportToVDI); 2441 2442 char *pszSuff = NULL; 2443 2444 if ((pszSuff = RTPathSuffix(strTargetPath->c_str()))!=NULL) 2445 { 2446 /* 2447 * Figure out which format the user like to have. Default is VMDK 2448 * or it can be VDI if according command-line option is set 2449 */ 2450 2451 /* 2452 * We need a proper target format 2453 * if target format has been changed by user via GUI import wizard 2454 * or via VBoxManage import command (option --importtovdi) 2455 * then we need properly process such format like ISO 2456 * Because there is no conversion ISO to VDI 2457 */ 2458 2459 pszSuff++; 2460 trgFormat = pSysProps->i_mediumFormatFromExtension(pszSuff); 2430 2461 if (trgFormat.isNull()) 2431 throw setError(VBOX_E_NOT_SUPPORTED, 2432 tr("Could not find a valid medium format for the target disk '%s'"), 2433 strTargetPath->c_str()); 2462 { 2463 rc = setError(E_FAIL, 2464 tr("Internal inconsistency looking up medium format for the disk image '%s'"), 2465 di.strHref.c_str()); 2466 } 2467 2468 rc = trgFormat->COMGETTER(Name)(bstrFormatName.asOutParam()); 2469 if (FAILED(rc)) throw rc; 2470 2471 strTrgFormat = Utf8Str(bstrFormatName); 2472 2473 if(chExt && strTrgFormat.compare("RAW", Utf8Str::CaseInsensitive) != 0) 2474 { 2475 /* change the target extension */ 2476 strTrgFormat = "vdi"; 2477 trgFormat = pSysProps->i_mediumFormatFromExtension(strTrgFormat); 2478 *strTargetPath = strTargetPath->stripSuffix(); 2479 *strTargetPath = strTargetPath->append("."); 2480 *strTargetPath = strTargetPath->append(strTrgFormat.c_str()); 2481 } 2482 2434 2483 /* Check the capabilities. We need create capabilities. */ 2435 2484 lCabs = 0; … … 2450 2499 tr("Could not find a valid medium format for the target disk '%s'"), 2451 2500 strTargetPath->c_str()); 2452 Bstr bstrFormatName;2453 rc = trgFormat->COMGETTER(Name)(bstrFormatName.asOutParam());2454 if (FAILED(rc)) throw rc;2455 strTrgFormat = Utf8Str(bstrFormatName);2456 2501 } 2457 2502 else … … 3808 3853 Utf8Str savedVBoxCurrent = vsdeTargetHD->strVBoxCurrent; 3809 3854 ComObjPtr<Medium> pTargetHD; 3855 3810 3856 i_importOneDiskImage(diCurrent, 3811 3857 &vsdeTargetHD->strVBoxCurrent,
Note:
See TracChangeset
for help on using the changeset viewer.