Changeset 16601 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Feb 9, 2009 4:33:28 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 42567
- File:
-
- 1 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)
Note:
See TracChangeset
for help on using the changeset viewer.