- Timestamp:
- Feb 9, 2009 4:33:28 PM (16 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageImport.cpp
r16581 r16601 37 37 38 38 #include <list> 39 #include <map> 39 40 #endif /* !VBOX_ONLY_DOCS */ 40 41 … … 49 50 // funcs 50 51 /////////////////////////////////////////////////////////////////////////////// 52 53 typedef std::map<Utf8Str, Utf8Str> ArgsMap; // pairs of strings like "-vmname" => "newvmname" 54 typedef std::map<uint32_t, ArgsMap> ArgsMapsMap; // map of maps, one for each virtual system, sorted by index 55 56 static bool findArgValue(Utf8Str &strOut, 57 const ArgsMap *pmapArgs, 58 const Utf8Str &strKey) 59 { 60 if (pmapArgs) 61 { 62 ArgsMap::const_iterator it; 63 it = pmapArgs->find(strKey); 64 if (it != pmapArgs->end()) 65 { 66 strOut = it->second; 67 return true; 68 } 69 } 70 71 return false; 72 } 51 73 52 74 int handleImportAppliance(HandlerArg *a) … … 57 79 bool fExecute = false; // if true, then we actually do the import (-exec argument) 58 80 59 for (int i = 0; i < a->argc; i++) 81 uint32_t ulCurVsys = (uint32_t)-1; 82 83 // for each -vsys X command, maintain a map of command line items 84 // (we'll parse them later after interpreting the OVF, when we can 85 // actually check whether they make sense semantically) 86 ArgsMapsMap mapArgsMapsPerVsys; 87 88 for (int i = 0; 89 i < a->argc; 90 ++i) 60 91 { 61 if (!strcmp(a->argv[i], "-exec")) 92 Utf8Str strThisArg(a->argv[i]); 93 if (strThisArg == "-exec") 62 94 fExecute = true; 95 else if (strThisArg == "-vsys") 96 { 97 if (++i < a->argc) 98 { 99 uint32_t ulVsys; 100 if (VINF_SUCCESS == (rc = Utf8Str(a->argv[i]).toInt(ulVsys))) // don't use SUCCESS() macro, fail even on warnings 101 ulCurVsys = ulVsys; 102 else 103 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Argument to -vsys option must be a non-negative number."); 104 } 105 else 106 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Missing argument to -vsys option."); 107 } 108 else if ( (strThisArg == "-ostype") 109 || (strThisArg == "-vmname") 110 || (strThisArg == "-memory") 111 || (strThisArg == "-ignore") 112 || (strThisArg.substr(0, 5) == "-type") 113 || (strThisArg.substr(0, 11) == "-controller") 114 ) 115 { 116 if (ulCurVsys == (uint32_t)-1) 117 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding -vsys argument.", strThisArg.c_str()); 118 119 // store both this arg and the next one in the strings map for later parsing 120 if (++i < a->argc) 121 mapArgsMapsPerVsys[ulCurVsys][strThisArg] = Utf8Str(a->argv[i]); 122 else 123 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Missing argument to \"%s\" option.", strThisArg.c_str()); 124 } 125 else if (strThisArg[0] == '-') 126 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Unknown option \"%s\".", strThisArg.c_str()); 63 127 else if (!strOvfFilename) 64 strOvfFilename = a->argv[i];128 strOvfFilename = strThisArg; 65 129 else 66 130 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Too many arguments for \"import\" command."); … … 76 140 CHECK_ERROR_BREAK(a->virtualBox, OpenAppliance(bstrOvfFilename, appliance.asOutParam())); 77 141 78 RTPrintf("Interpreting ...\n");142 RTPrintf("Interpreting %s... ", strOvfFilename.c_str()); 79 143 CHECK_ERROR_BREAK(appliance, Interpret()); 80 144 RTPrintf("OK.\n"); … … 96 160 CHECK_ERROR_BREAK(appliance, 97 161 COMGETTER(VirtualSystemDescriptions)(ComSafeArrayAsOutParam(aVirtualSystemDescriptions))); 98 if (aVirtualSystemDescriptions.size() > 0) 99 { 100 for (unsigned i = 0; i < aVirtualSystemDescriptions.size(); ++i) 162 163 uint32_t cVirtualSystemDescriptions = aVirtualSystemDescriptions.size(); 164 165 // match command line arguments with virtual system descriptions; 166 // this is only to sort out invalid indices at this time 167 ArgsMapsMap::const_iterator it; 168 for (it = mapArgsMapsPerVsys.begin(); 169 it != mapArgsMapsPerVsys.end(); 170 ++it) 171 { 172 uint32_t ulVsys = it->first; 173 if (ulVsys >= cVirtualSystemDescriptions) 174 return errorSyntax(USAGE_IMPORTAPPLIANCE, 175 "Invalid index %RI32 with -vsys option; the OVF contains only %RI32 virtual system(s).", 176 ulVsys, cVirtualSystemDescriptions); 177 } 178 179 // dump virtual system descriptions and match command-line arguments 180 if (cVirtualSystemDescriptions > 0) 181 { 182 for (unsigned i = 0; i < cVirtualSystemDescriptions; ++i) 101 183 { 102 184 com::SafeArray<VirtualSystemDescriptionType_T> retTypes; … … 113 195 114 196 RTPrintf("Virtual system %i:\n", i); 197 198 // look up the corresponding command line options, if any 199 const ArgsMap *pmapArgs = NULL; 200 ArgsMapsMap::const_iterator itm = mapArgsMapsPerVsys.find(i); 201 if (itm != mapArgsMapsPerVsys.end()) 202 pmapArgs = &itm->second; 203 204 // ArgsMap::const_iterator it3; 205 // for (it3 = pmapArgs->begin(); 206 // it3 != pmapArgs->end(); 207 // ++it3) 208 // { 209 // RTPrintf("%s -> %s\n", it3->first.c_str(), it3->second.c_str()); 210 // } 211 // } 212 213 // Bstr bstrVMName; 214 // Bstr bstrOSType; 215 216 // this collects the final values for setFinalValues() 217 com::SafeArray<BOOL> aEnabled(retTypes.size()); 218 com::SafeArray<BSTR> aFinalValues(retTypes.size()); 219 115 220 for (unsigned a = 0; a < retTypes.size(); ++a) 116 221 { 117 222 VirtualSystemDescriptionType_T t = retTypes[a]; 118 223 119 Bstr bstrVMname; 120 Bstr bstrOstype; 121 uint32_t ulMemMB; 122 bool fUSB = false; 224 Utf8Str strOverride; 225 226 Bstr bstrFinalValue = aConfigValues[a]; 123 227 124 228 switch (t) 125 229 { 126 230 case VirtualSystemDescriptionType_Name: 127 bstrVMname = aConfigValues[a]; 128 RTPrintf("%2d: Suggested VM name \"%ls\"" 129 "\n (change with \"-vsys %d -vmname <name>\")\n", 130 a, bstrVMname.raw(), i); 231 if (findArgValue(strOverride, pmapArgs, "-vmname")) 232 { 233 bstrFinalValue = strOverride; 234 RTPrintf("%2d: VM name specified with -vmname: \"%ls\"\n", 235 a, bstrFinalValue.raw()); 236 } 237 else 238 RTPrintf("%2d: Suggested VM name \"%ls\"" 239 "\n (change with \"-vsys %d -vmname <name>\")\n", 240 a, bstrFinalValue.raw(), i); 131 241 break; 132 242 133 243 case VirtualSystemDescriptionType_OS: 134 bstrOstype = aConfigValues[a]; 135 RTPrintf("%2d: Suggested OS type: \"%ls\"" 136 "\n (change with \"-vsys %d -ostype <type>\"; use \"list ostypes\" to list all)\n", 137 a, bstrOstype.raw(), i); 244 if (findArgValue(strOverride, pmapArgs, "-ostype")) 245 { 246 bstrFinalValue = strOverride; 247 RTPrintf("%2d: OS type specified with -ostype: \"%ls\"\n", 248 a, bstrFinalValue.raw()); 249 } 250 else 251 RTPrintf("%2d: Suggested OS type: \"%ls\"" 252 "\n (change with \"-vsys %d -ostype <type>\"; use \"list ostypes\" to list all)\n", 253 a, bstrFinalValue.raw(), i); 138 254 break; 139 255 … … 144 260 145 261 case VirtualSystemDescriptionType_Memory: 146 Utf8Str(Bstr(aConfigValues[a])).toInt(ulMemMB); 147 RTPrintf("%2d: Guest memory: %u MB\n (change with \"-vsys %d -memory <MB>\")\n", 148 a, ulMemMB, i); 262 { 263 if (findArgValue(strOverride, pmapArgs, "-memory")) 264 { 265 uint32_t ulMemMB; 266 if (VINF_SUCCESS == strOverride.toInt(ulMemMB)) 267 { 268 bstrFinalValue = strOverride; 269 RTPrintf("%2d: Guest memory specified with -memory: %ls MB\n", 270 a, bstrFinalValue.raw()); 271 } 272 else 273 return errorSyntax(USAGE_IMPORTAPPLIANCE, 274 "Argument to -memory option must be a non-negative number."); 275 } 276 else 277 RTPrintf("%2d: Guest memory: %ls MB\n (change with \"-vsys %d -memory <MB>\")\n", 278 a, bstrFinalValue.raw(), i); 279 } 149 280 break; 150 281 … … 220 351 break; 221 352 } 353 354 bstrFinalValue.detachTo(&aFinalValues[a]); 222 355 } 223 } 356 357 if (fExecute) 358 CHECK_ERROR_BREAK(aVirtualSystemDescriptions[i], 359 SetFinalValues(ComSafeArrayAsInParam(aEnabled), 360 ComSafeArrayAsInParam(aFinalValues))); 361 362 } // for (unsigned i = 0; i < cVirtualSystemDescriptions; ++i) 224 363 225 364 if (fExecute) -
trunk/src/VBox/Main/ApplianceImpl.cpp
r16600 r16601 2147 2147 } 2148 2148 2149 STDMETHODIMP VirtualSystemDescription::DisableItem(ULONG index) 2150 { 2151 AutoCaller autoCaller(this); 2152 CheckComRCReturnRC(autoCaller.rc()); 2153 2154 AutoWriteLock alock(this); 2155 2156 list<VirtualSystemDescriptionEntry>::iterator it; 2157 for (it = m->descriptions.begin(); 2158 it != m->descriptions.end(); 2159 ++it) 2160 { 2161 VirtualSystemDescriptionEntry &e = *it; 2162 if (e.ulIndex == index) 2163 { 2164 e.type = VirtualSystemDescriptionType_Ignore; 2165 return S_OK; 2166 } 2167 } 2168 2169 return setError(VBOX_E_OBJECT_NOT_FOUND, 2170 tr("Array item index %d not found"), 2171 index); 2172 } 2173 2174 STDMETHODIMP VirtualSystemDescription::SetFinalValues(ComSafeArrayIn(IN_BSTR, aFinalValues)) 2149 STDMETHODIMP VirtualSystemDescription::SetFinalValues(ComSafeArrayIn(BOOL, aEnabled), 2150 ComSafeArrayIn(IN_BSTR, aFinalValues)) 2175 2151 { 2176 2152 CheckComArgSafeArrayNotNull(aFinalValues); … … 2192 2168 { 2193 2169 VirtualSystemDescriptionEntry& vsde = *it; 2194 vsde.strConfig = values[i]; 2170 2171 if (aEnabled[i]) 2172 vsde.strConfig = values[i]; 2173 else 2174 vsde.type = VirtualSystemDescriptionType_Ignore; 2195 2175 } 2196 2176 -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r16600 r16601 3122 3122 </method> 3123 3123 3124 <method name="disableItem"> 3125 <desc> 3126 Disables part of the configuration, as represented by the array items returned by 3127 <link to="getDescription" />. For example, to disable USB support for a given 3128 virtual system, pass in the array item index of the USB controller; its type will 3129 then be changed by this method from "USBController" to "Ignore". 3130 3131 This works only for items of the types HardDiskControllerIDE, HardDiskControllerSATA, 3124 <method name="setFinalValues"> 3125 <desc> 3126 This method allows the appliance's user to change the configuration for the virtual 3127 system descriptions. For each array item returned from <link to="getDescription" />, 3128 you must pass in one boolean value and one configuration value. 3129 3130 Each item in the boolean array determines whether the particular configuration item 3131 should be enabled. 3132 You can only disable items of the types HardDiskControllerIDE, HardDiskControllerSATA, 3132 3133 HardDiskControllerSCSI, HardDiskImage, CDROM, Floppy, NetworkAdapter, USBController 3133 3134 and SoundCard. 3134 </desc> 3135 3136 <param name="index" type="unsigned long" dir="in"> 3137 </param> 3138 </method> 3139 3140 <method name="SetFinalValues"> 3141 <desc></desc> 3142 3143 <param name="aFinaleValues" type="wstring" dir="in" safearray="yes"> 3135 3136 For the configuration values, if you pass in the same array as returned 3137 in the aConfigValues array from getDescription(), the configuration remains unchanged. 3138 Please see the documentation for getDescription() for valid configuration values 3139 for the individual array item types. If the corresponding item in the aEnabled array 3140 is false, the configuration value is gnored. 3141 </desc> 3142 3143 <param name="aEnabled" type="boolean" dir="in" safearray="yes"> 3144 3144 <desc></desc> 3145 3145 </param> 3146 3146 3147 <param name="aFinalValues" type="wstring" dir="in" safearray="yes"> 3148 <desc></desc> 3149 </param> 3150 3147 3151 </method> 3148 3152 3149 3153 <method name="getWarnings"> 3150 <desc>Returns textual warnings which occurs on the virtual system 3154 <desc>Returns textual warnings which occurs on the virtual system 3151 3155 interpretion.</desc> 3152 3156 -
trunk/src/VBox/Main/include/ApplianceImpl.h
r16600 r16601 153 153 ComSafeArrayOut(BSTR, aConfigValues), 154 154 ComSafeArrayOut(BSTR, aExtraConfigValues)); 155 STDMETHOD(DisableItem)(ULONG index);156 STDMETHOD(SetFinalValues)(ComSafeArrayIn(IN_BSTR, aFinalValues));157 155 158 156 STDMETHOD(SetFinalValues)(ComSafeArrayIn(BOOL, aEnabled), 157 ComSafeArrayIn(IN_BSTR, aFinalValues)); 159 158 160 159 STDMETHOD(GetWarnings)(ComSafeArrayOut(BSTR, aWarnings));
Note:
See TracChangeset
for help on using the changeset viewer.