Changeset 34552 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Dec 1, 2010 10:13:08 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp
r34465 r34552 172 172 } 173 173 174 static int ctrlPrintError(ComPtr<IUnknown> object, const GUID &aIID) 175 { 176 com::ErrorInfo info(object, aIID); 177 if ( info.isFullAvailable() 178 || info.isBasicAvailable()) 174 static int ctrlPrintError(com::ErrorInfo &errorInfo) 175 { 176 if ( errorInfo.isFullAvailable() 177 || errorInfo.isBasicAvailable()) 179 178 { 180 179 /* If we got a VBOX_E_IPRT error we handle the error in a more gentle way 181 180 * because it contains more accurate info about what went wrong. */ 182 if ( info.getResultCode() == VBOX_E_IPRT_ERROR)183 RTMsgError("%ls.", info.getText().raw());181 if (errorInfo.getResultCode() == VBOX_E_IPRT_ERROR) 182 RTMsgError("%ls.", errorInfo.getText().raw()); 184 183 else 185 184 { 186 185 RTMsgError("Error details:"); 187 GluePrintErrorInfo( info);186 GluePrintErrorInfo(errorInfo); 188 187 } 189 188 return VERR_GENERAL_FAILURE; /** @todo */ … … 191 190 AssertMsgFailedReturn(("Object has indicated no error!?\n"), 192 191 VERR_INVALID_PARAMETER); 192 } 193 194 static int ctrlPrintProgressError(ComPtr<IProgress> progress) 195 { 196 return ctrlPrintError(com::ProgressErrorInfo(progress)); 193 197 } 194 198 … … 430 434 if (FAILED(rc)) 431 435 { 432 vrc = ctrlPrintError( guest, COM_IIDOF(IGuest));436 vrc = ctrlPrintError(com::ErrorInfo(guest, COM_IIDOF(IGuest))); 433 437 } 434 438 else … … 486 490 if (FAILED(rc)) 487 491 { 488 vrc = ctrlPrintError( guest, COM_IIDOF(IGuest));492 vrc = ctrlPrintError(com::ErrorInfo(guest, COM_IIDOF(IGuest))); 489 493 490 494 cbOutputData = 0; … … 560 564 && SUCCEEDED(rc)) 561 565 { 562 LONG iRc = false;566 LONG iRc; 563 567 CHECK_ERROR_RET(progress, COMGETTER(ResultCode)(&iRc), rc); 564 568 if (FAILED(iRc)) 565 569 { 566 vrc = ctrlPrint Error(progress, COM_IIDOF(IProgress));570 vrc = ctrlPrintProgressError(progress); 567 571 } 568 572 else if (fVerbose) … … 590 594 591 595 /** 592 * Appends a new to-copy object to a copylist.596 * Appends a new file/directory entry to a given list. 593 597 * 594 598 * @return IPRT status code. 595 * @param pszFileSource Full qualified source path of file to copy .596 * @param pszFileDest Full qualified destination path .599 * @param pszFileSource Full qualified source path of file to copy (optional). 600 * @param pszFileDest Full qualified destination path (optional). 597 601 * @param pList Copy list used for insertion. 598 602 */ 599 static int ctrlCopyDirectoryEntryAppend(const char *pszFileSource, const char *pszFileDest, 600 PRTLISTNODE pList) 601 { 602 AssertPtrReturn(pszFileSource, VERR_INVALID_POINTER); 603 AssertPtrReturn(pszFileDest, VERR_INVALID_POINTER); 603 static int ctrlDirectoryEntryAppend(const char *pszFileSource, const char *pszFileDest, 604 PRTLISTNODE pList) 605 { 604 606 AssertPtrReturn(pList, VERR_INVALID_POINTER); 607 AssertReturn(pszFileSource || pszFileDest, VERR_INVALID_PARAMETER); 605 608 606 609 PDIRECTORYENTRY pNode = (PDIRECTORYENTRY)RTMemAlloc(sizeof(DIRECTORYENTRY)); … … 608 611 return VERR_NO_MEMORY; 609 612 610 pNode->pszSourcePath = RTStrDup(pszFileSource); 611 pNode->pszDestPath = RTStrDup(pszFileDest); 612 if ( !pNode->pszSourcePath 613 || !pNode->pszDestPath) 614 { 615 return VERR_NO_MEMORY; 613 pNode->pszSourcePath = NULL; 614 pNode->pszDestPath = NULL; 615 616 if (pszFileSource) 617 { 618 pNode->pszSourcePath = RTStrDup(pszFileSource); 619 AssertPtrReturn(pNode->pszSourcePath, VERR_NO_MEMORY); 620 } 621 if (pszFileDest) 622 { 623 pNode->pszDestPath = RTStrDup(pszFileDest); 624 AssertPtrReturn(pNode->pszDestPath, VERR_NO_MEMORY); 616 625 } 617 626 … … 621 630 return VINF_SUCCESS; 622 631 } 632 633 /** 634 * Destroys a directory list. 635 * 636 * @param pList Pointer to list to destroy. 637 */ 638 static void ctrlDirectoryListDestroy(PRTLISTNODE pList) 639 { 640 AssertPtr(pList); 641 642 /* Destroy file list. */ 643 PDIRECTORYENTRY pNode = RTListGetFirst(pList, DIRECTORYENTRY, Node); 644 while (pNode) 645 { 646 PDIRECTORYENTRY pNext = RTListNodeGetNext(&pNode->Node, DIRECTORYENTRY, Node); 647 bool fLast = RTListNodeIsLast(pList, &pNode->Node); 648 649 if (pNode->pszSourcePath) 650 RTStrFree(pNode->pszSourcePath); 651 if (pNode->pszDestPath) 652 RTStrFree(pNode->pszDestPath); 653 RTListNodeRemove(&pNode->Node); 654 RTMemFree(pNode); 655 656 if (fLast) 657 break; 658 659 pNode = pNext; 660 } 661 } 662 623 663 624 664 /** … … 743 783 if (RT_SUCCESS(rc)) 744 784 { 745 rc = ctrl CopyDirectoryEntryAppend(pszFileSource, pszFileDest, pList);785 rc = ctrlDirectoryEntryAppend(pszFileSource, pszFileDest, pList); 746 786 if (RT_SUCCESS(rc)) 747 787 *pcObjects = *pcObjects + 1; … … 819 859 { 820 860 RTListInit(pList); 821 rc = ctrl CopyDirectoryEntryAppend(pszSourceAbs, pszDestAbs, pList);861 rc = ctrlDirectoryEntryAppend(pszSourceAbs, pszDestAbs, pList); 822 862 *pcObjects = 1; 823 863 } … … 900 940 rc = VERR_NO_MEMORY; 901 941 return rc; 902 }903 904 /**905 * Destroys a copy list.906 */907 static void ctrlCopyDestroy(PRTLISTNODE pList)908 {909 AssertPtr(pList);910 911 /* Destroy file list. */912 PDIRECTORYENTRY pNode = RTListGetFirst(pList, DIRECTORYENTRY, Node);913 while (pNode)914 {915 PDIRECTORYENTRY pNext = RTListNodeGetNext(&pNode->Node, DIRECTORYENTRY, Node);916 bool fLast = RTListNodeIsLast(pList, &pNode->Node);917 918 if (pNode->pszSourcePath)919 RTStrFree(pNode->pszSourcePath);920 if (pNode->pszDestPath)921 RTStrFree(pNode->pszDestPath);922 RTListNodeRemove(&pNode->Node);923 RTMemFree(pNode);924 925 if (fLast)926 break;927 928 pNode = pNext;929 }930 942 } 931 943 … … 957 969 if (FAILED(rc)) 958 970 { 959 vrc = ctrlPrintError( pGuest, COM_IIDOF(IGuest));971 vrc = ctrlPrintError(com::ErrorInfo(pGuest, COM_IIDOF(IGuest))); 960 972 } 961 973 else … … 1004 1016 && SUCCEEDED(rc)) 1005 1017 { 1006 LONG iRc = false;1018 LONG iRc; 1007 1019 CHECK_ERROR_RET(progress, COMGETTER(ResultCode)(&iRc), rc); 1008 1020 if (FAILED(iRc)) 1009 vrc = ctrlPrint Error(progress, COM_IIDOF(IProgress));1021 vrc = ctrlPrintProgressError(progress); 1010 1022 } 1011 1023 } … … 1106 1118 } 1107 1119 uNoOptionIdx++; 1120 if (uNoOptionIdx == UINT32_MAX) 1121 { 1122 RTMsgError("Too many files specified! Aborting.\n"); 1123 vrc = VERR_TOO_MUCH_DATA; 1124 } 1108 1125 break; 1109 1126 } … … 1194 1211 RTStrFree(pszDestPath); 1195 1212 if (FAILED(rc)) 1196 vrc = ctrlPrintError( guest, COM_IIDOF(IGuest));1213 vrc = ctrlPrintError(com::ErrorInfo(guest, COM_IIDOF(IGuest))); 1197 1214 else 1198 1215 { … … 1217 1234 RTPrintf("Copy operation successful!\n"); 1218 1235 } 1219 ctrl CopyDestroy(&listToCopy);1236 ctrlDirectoryListDestroy(&listToCopy); 1220 1237 } 1221 1238 ctrlUninitVM(a); … … 1251 1268 RTGetOptInit(&GetState, a->argc, a->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0); 1252 1269 1253 Utf8Str Utf8Directory(a->argv[1]);1254 1270 Utf8Str Utf8UserName; 1255 1271 Utf8Str Utf8Password; … … 1258 1274 bool fVerbose = false; 1259 1275 1276 RTLISTNODE listDirs; 1277 uint32_t uNumDirs = 0; 1278 RTListInit(&listDirs); 1279 1260 1280 int vrc = VINF_SUCCESS; 1261 1281 bool fUsageOK = true; … … 1292 1312 case VINF_GETOPT_NOT_OPTION: 1293 1313 { 1294 Utf8Directory = ValueUnion.psz; 1314 vrc = ctrlDirectoryEntryAppend(NULL, /* No source given */ 1315 ValueUnion.psz, /* Destination */ 1316 &listDirs); 1317 if (RT_SUCCESS(vrc)) 1318 { 1319 uNumDirs++; 1320 if (uNumDirs == UINT32_MAX) 1321 { 1322 RTMsgError("Too many directories specified! Aborting.\n"); 1323 vrc = VERR_TOO_MUCH_DATA; 1324 } 1325 } 1295 1326 break; 1296 1327 } … … 1304 1335 return errorSyntax(USAGE_GUESTCONTROL, "Incorrect parameters"); 1305 1336 1306 if ( Utf8Directory.isEmpty())1337 if (!uNumDirs) 1307 1338 return errorSyntax(USAGE_GUESTCONTROL, 1308 1339 "No directory to create specified!"); … … 1317 1348 if (RT_SUCCESS(vrc)) 1318 1349 { 1319 ComPtr<IProgress> progress;1320 rc = guest->CreateDirectory(Bstr(Utf8Directory).raw(),1321 Bstr(Utf8UserName).raw(), Bstr(Utf8Password).raw(), 1322 uMode, uFlags, progress.asOutParam());1323 if (FAILED(rc))1324 vrc = ctrlPrintError(guest, COM_IIDOF(IGuest));1325 else1326 {1327 /* Setup signal handling if cancelable. */ 1328 ASSERT(progress);1329 bool fCanceledAlready = false;1330 BOOL fCancelable;1331 rc = progress->COMGETTER(Cancelable)(&fCancelable);1350 if (fVerbose && uNumDirs > 1) 1351 RTPrintf("Creating %ld directories ...\n", uNumDirs); 1352 1353 PDIRECTORYENTRY pNode; 1354 RTListForEach(&listDirs, pNode, DIRECTORYENTRY, Node) 1355 { 1356 if (fVerbose) 1357 RTPrintf("Creating directory \"%s\" ...\n", pNode->pszDestPath); 1358 1359 ComPtr<IProgress> progress; 1360 rc = guest->CreateDirectory(Bstr(pNode->pszDestPath).raw(), 1361 Bstr(Utf8UserName).raw(), Bstr(Utf8Password).raw(), 1362 uMode, uFlags, progress.asOutParam()); 1332 1363 if (FAILED(rc)) 1333 fCancelable = FALSE; 1334 if (fCancelable) 1335 ctrlSignalHandlerInstall(); 1336 1337 /* Wait for process to exit ... */ 1338 BOOL fCompleted = FALSE; 1339 BOOL fCanceled = FALSE; 1340 while ( SUCCEEDED(progress->COMGETTER(Completed(&fCompleted))) 1341 && !fCompleted) 1342 { 1343 /* Process async cancelation */ 1344 if (g_fGuestCtrlCanceled && !fCanceledAlready) 1345 { 1346 rc = progress->Cancel(); 1347 if (SUCCEEDED(rc)) 1348 fCanceledAlready = TRUE; 1349 else 1350 g_fGuestCtrlCanceled = false; 1351 } 1352 1353 /* Progress canceled by Main API? */ 1354 if ( SUCCEEDED(progress->COMGETTER(Canceled(&fCanceled))) 1355 && fCanceled) 1356 { 1357 break; 1358 } 1359 } 1360 1361 /* Undo signal handling. */ 1362 if (fCancelable) 1363 ctrlSignalHandlerUninstall(); 1364 1365 if (fCanceled) 1366 { 1367 //RTPrintf("Copy operation canceled!\n"); 1368 } 1369 else if ( fCompleted 1370 && SUCCEEDED(rc)) 1371 { 1372 LONG iRc = false; 1364 vrc = ctrlPrintError(com::ErrorInfo(guest, COM_IIDOF(IGuest))); 1365 else 1366 { 1367 LONG iRc; 1373 1368 CHECK_ERROR_RET(progress, COMGETTER(ResultCode)(&iRc), rc); 1374 1369 if (FAILED(iRc)) 1375 vrc = ctrlPrintError(progress, COM_IIDOF(IProgress)); 1370 { 1371 vrc = ctrlPrintProgressError(progress); 1372 break; 1373 } 1374 else if (fVerbose) 1375 RTPrintf("Directory created: %s\n", pNode->pszDestPath); 1376 1376 } 1377 1377 } 1378 1378 ctrlUninitVM(a); 1379 1379 } 1380 ctrlDirectoryListDestroy(&listDirs); 1380 1381 1381 1382 if (RT_FAILURE(vrc)) … … 1472 1473 progress.asOutParam())); 1473 1474 if (FAILED(rc)) 1474 vrc = ctrlPrintError( guest, COM_IIDOF(IGuest));1475 vrc = ctrlPrintError(com::ErrorInfo(guest, COM_IIDOF(IGuest))); 1475 1476 else 1476 1477 { 1477 1478 rc = showProgress(progress); 1478 1479 if (FAILED(rc)) 1479 vrc = ctrlPrint Error(progress, COM_IIDOF(IProgress));1480 vrc = ctrlPrintProgressError(progress); 1480 1481 else if (fVerbose) 1481 1482 RTPrintf("Guest Additions installer successfully copied and started.\n");
Note:
See TracChangeset
for help on using the changeset viewer.