Changeset 40575 in vbox for trunk/src/VBox/Main/src-client/GuestCtrlImplTasks.cpp
- Timestamp:
- Mar 22, 2012 2:12:26 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-client/GuestCtrlImplTasks.cpp
r40206 r40575 121 121 122 122 /* static */ 123 HRESULT GuestTask::setProgressErrorInfo(HRESULT hr, ComObjPtr<Progress> pProgress, 124 const char *pszText, ...) 123 HRESULT GuestTask::setProgressSuccess(ComObjPtr<Progress> pProgress) 124 { 125 BOOL fCanceled; 126 BOOL fCompleted; 127 if ( SUCCEEDED(pProgress->COMGETTER(Canceled(&fCanceled))) 128 && !fCanceled 129 && SUCCEEDED(pProgress->COMGETTER(Completed(&fCompleted))) 130 && !fCompleted) 131 { 132 return pProgress->notifyComplete(S_OK); 133 } 134 135 return S_OK; 136 } 137 138 /* static */ 139 HRESULT GuestTask::setProgressErrorMsg(HRESULT hr, ComObjPtr<Progress> pProgress, 140 const char *pszText, ...) 125 141 { 126 142 BOOL fCanceled; … … 147 163 148 164 /* static */ 149 HRESULT GuestTask::setProgressError Info(HRESULT hr,150 ComObjPtr<Progress> pProgress, ComObjPtr<Guest> pGuest)165 HRESULT GuestTask::setProgressErrorParent(HRESULT hr, 166 ComObjPtr<Progress> pProgress, ComObjPtr<Guest> pGuest) 151 167 { 152 return setProgressError Info(hr, pProgress,153 168 return setProgressErrorMsg(hr, pProgress, 169 Utf8Str(com::ErrorInfo((IGuest*)pGuest, COM_IIDOF(IGuest)).getText()).c_str()); 154 170 } 155 171 … … 177 193 if (!RTFileExists(aTask->strSource.c_str())) 178 194 { 179 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,180 Guest::tr("Source file \"%s\" does not exist,or is not a file"),181 195 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 196 Guest::tr("Source file \"%s\" does not exist or is not a file"), 197 aTask->strSource.c_str()); 182 198 } 183 199 else … … 188 204 if (RT_FAILURE(vrc)) 189 205 { 190 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,191 192 aTask->strSource.c_str(),vrc);206 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 207 Guest::tr("Could not open source file \"%s\" for reading (%Rrc)"), 208 aTask->strSource.c_str(), vrc); 193 209 } 194 210 else … … 198 214 if (RT_FAILURE(vrc)) 199 215 { 200 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,201 202 216 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 217 Guest::tr("Could not query file size of \"%s\" (%Rrc)"), 218 aTask->strSource.c_str(), vrc); 203 219 } 204 220 else … … 211 227 */ 212 228 char szOutput[RTPATH_MAX]; 213 if (RTStrPrintf(szOutput, sizeof(szOutput), "--output=%s", aTask->strDest.c_str()) <= sizeof(szOutput) - 1) 229 size_t cchOutput = RTStrPrintf(szOutput, sizeof(szOutput), "--output=%s", aTask->strDest.c_str()); 230 if (cchOutput && cchOutput <= sizeof(szOutput) - 1) 214 231 { 215 232 /* … … 231 248 } 232 249 else 233 { 234 rc = GuestTask::setProgressErrorInfo(VBOX_E_IPRT_ERROR, aTask->pProgress, 235 Guest::tr("Error preparing command line")); 236 } 250 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 251 Guest::tr("Destination file for source \"%s\" invalid (%ubytes)"), 252 aTask->strSource.c_str(), cchOutput); 237 253 238 254 ComPtr<IProgress> execProgress; … … 256 272 execProgress.asOutParam(), &uPID); 257 273 if (FAILED(rc)) 258 rc = GuestTask::setProgressError Info(rc, aTask->pProgress, pGuest);274 rc = GuestTask::setProgressErrorParent(rc, aTask->pProgress, pGuest); 259 275 } 260 276 … … 287 303 if (RT_FAILURE(vrc)) 288 304 { 289 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,290 291 305 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 306 Guest::tr("Could not read from file \"%s\" (%Rrc)"), 307 aTask->strSource.c_str(), vrc); 292 308 break; 293 309 } … … 295 311 else 296 312 { 297 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,298 299 313 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 314 Guest::tr("Seeking file \"%s\" failed; offset = %RU64 (%Rrc)"), 315 aTask->strSource.c_str(), cbTransferedTotal, vrc); 300 316 break; 301 317 } … … 324 340 if (FAILED(rc)) 325 341 { 326 rc = GuestTask::setProgressError Info(rc, aTask->pProgress, pGuest);342 rc = GuestTask::setProgressErrorParent(rc, aTask->pProgress, pGuest); 327 343 break; 328 344 } … … 348 364 && fCanceled) 349 365 { 350 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,351 352 366 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 367 Guest::tr("Copy operation of file \"%s\" was canceled on guest side"), 368 aTask->strSource.c_str()); 353 369 break; 354 370 } … … 368 384 if (FAILED(rc)) 369 385 { 370 rc = GuestTask::setProgressError Info(rc, aTask->pProgress, pGuest);386 rc = GuestTask::setProgressErrorParent(rc, aTask->pProgress, pGuest); 371 387 } 372 388 else … … 375 391 || retStatus != ExecuteProcessStatus_TerminatedNormally) 376 392 { 377 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,378 379 393 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 394 Guest::tr("Guest process reported error %u (status: %u) while copying file \"%s\" to \"%s\""), 395 uRetExitCode, retStatus, aTask->strSource.c_str(), aTask->strDest.c_str()); 380 396 } 381 397 } … … 390 406 * notify the object with a complete event when it's canceled. 391 407 */ 392 aTask->pProgress->notifyComplete(VBOX_E_IPRT_ERROR, 393 COM_IIDOF(IGuest), 394 Guest::getStaticComponentName(), 395 Guest::tr("Copying file \"%s\" canceled"), aTask->strSource.c_str()); 408 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 409 Guest::tr("Copying file \"%s\" to guest canceled"), 410 aTask->strSource.c_str()); 396 411 } 397 412 else … … 406 421 /* If nothing was transfered but the file size was > 0 then "vbox_cat" wasn't able to write 407 422 * to the destination -> access denied. */ 408 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,409 410 423 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 424 Guest::tr("Access denied when copying file \"%s\" to \"%s\""), 425 aTask->strSource.c_str(), aTask->strDest.c_str()); 411 426 } 412 427 else if (cbTransferedTotal < cbSize) 413 428 { 414 429 /* If we did not copy all let the user know. */ 415 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,416 417 430 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 431 Guest::tr("Copying file \"%s\" failed (%u/%u bytes transfered)"), 432 aTask->strSource.c_str(), cbTransferedTotal, cbSize); 418 433 } 419 434 else /* Yay, all went fine! */ 420 aTask->pProgress->notifyComplete(S_OK);435 rc = GuestTask::setProgressSuccess(aTask->pProgress); 421 436 } 422 437 } … … 468 483 { 469 484 if (!fFileExists) 470 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,471 472 485 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 486 Guest::tr("Source file \"%s\" does not exist, or is not a file"), 487 aTask->strSource.c_str()); 473 488 } 474 489 else 475 rc = GuestTask::setProgressError Info(rc, aTask->pProgress, pGuest);490 rc = GuestTask::setProgressErrorParent(rc, aTask->pProgress, pGuest); 476 491 477 492 /* Query file size to make an estimate for our progress object. */ … … 483 498 &lFileSize); 484 499 if (FAILED(rc)) 485 rc = GuestTask::setProgressError Info(rc, aTask->pProgress, pGuest);500 rc = GuestTask::setProgressErrorParent(rc, aTask->pProgress, pGuest); 486 501 487 502 com::SafeArray<IN_BSTR> args; … … 494 509 */ 495 510 char szSource[RTPATH_MAX]; 496 if (RTStrPrintf(szSource, sizeof(szSource), "%s", aTask->strSource.c_str()) <= sizeof(szSource) - 1) 511 size_t cchSource = RTStrPrintf(szSource, sizeof(szSource), "%s", aTask->strSource.c_str()); 512 if (cchSource && cchSource <= sizeof(szSource) - 1) 497 513 { 498 514 /* … … 514 530 } 515 531 else 516 rc = GuestTask::setProgressErrorInfo(VBOX_E_IPRT_ERROR, aTask->pProgress, 517 Guest::tr("Error preparing command line")); 532 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 533 Guest::tr("Source file \"%s\" too long (%ubytes)"), 534 aTask->strSource.c_str(), cchSource); 518 535 } 519 536 … … 540 557 execProgress.asOutParam(), &uPID); 541 558 if (FAILED(rc)) 542 rc = GuestTask::setProgressError Info(rc, aTask->pProgress, pGuest);559 rc = GuestTask::setProgressErrorParent(rc, aTask->pProgress, pGuest); 543 560 } 544 561 … … 552 569 RTFILE_O_WRITE | RTFILE_O_OPEN_CREATE | RTFILE_O_DENY_WRITE); 553 570 if (RT_FAILURE(vrc)) 554 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,555 556 571 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 572 Guest::tr("Unable to create/open destination file \"%s\", rc=%Rrc"), 573 aTask->strDest.c_str(), vrc); 557 574 else 558 575 { … … 575 592 if (RT_FAILURE(vrc)) 576 593 { 577 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,578 579 594 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 595 Guest::tr("Error writing to file \"%s\" (%u bytes left), rc=%Rrc"), 596 aTask->strSource.c_str(), cbToRead, vrc); 580 597 break; 581 598 } … … 592 609 else 593 610 { 594 rc = GuestTask::setProgressError Info(rc, aTask->pProgress, pGuest);611 rc = GuestTask::setProgressErrorParent(rc, aTask->pProgress, pGuest); 595 612 break; 596 613 } … … 609 626 * be (almost) sure that this file is not meant to be read by the specified user. 610 627 */ 611 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,612 613 628 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 629 Guest::tr("Unexpected end of file \"%s\" (%u bytes total, %u bytes transferred)"), 630 aTask->strSource.c_str(), lFileSize, cbTransfered); 614 631 } 615 632 616 633 if (SUCCEEDED(rc)) 617 aTask->pProgress->notifyComplete(S_OK);634 rc = GuestTask::setProgressSuccess(aTask->pProgress); 618 635 } 619 636 } … … 679 696 } 680 697 else /* Everything else is not supported (yet). */ 681 throw GuestTask::setProgressError Info(VBOX_E_NOT_SUPPORTED, aTask->pProgress,698 throw GuestTask::setProgressErrorMsg(VBOX_E_NOT_SUPPORTED, aTask->pProgress, 682 699 Guest::tr("Detected guest OS (%s) does not support automatic Guest Additions updating, please update manually"), 683 700 osTypeIdUtf8.c_str()); 684 701 } 685 702 else 686 throw GuestTask::setProgressError Info(VBOX_E_NOT_SUPPORTED, aTask->pProgress,703 throw GuestTask::setProgressErrorMsg(VBOX_E_NOT_SUPPORTED, aTask->pProgress, 687 704 Guest::tr("Could not detected guest OS type/version, please update manually")); 688 705 Assert(!installerImage.isEmpty()); … … 695 712 if (RT_FAILURE(vrc)) 696 713 { 697 rc = GuestTask::setProgressError Info(VBOX_E_FILE_ERROR, aTask->pProgress,698 699 714 rc = GuestTask::setProgressErrorMsg(VBOX_E_FILE_ERROR, aTask->pProgress, 715 Guest::tr("Invalid installation medium detected: \"%s\""), 716 aTask->strSource.c_str()); 700 717 } 701 718 else … … 710 727 vrc = RTFileSeek(iso.file, cbOffset, RTFILE_SEEK_BEGIN, NULL); 711 728 if (RT_FAILURE(vrc)) 712 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,713 714 729 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 730 Guest::tr("Could not seek to setup file on installation medium \"%s\" (%Rrc)"), 731 aTask->strSource.c_str(), vrc); 715 732 } 716 733 else … … 719 736 { 720 737 case VERR_FILE_NOT_FOUND: 721 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,722 723 738 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 739 Guest::tr("Setup file was not found on installation medium \"%s\""), 740 aTask->strSource.c_str()); 724 741 break; 725 742 726 743 default: 727 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,728 729 744 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 745 Guest::tr("An unknown error (%Rrc) occured while retrieving information of setup file on installation medium \"%s\""), 746 vrc, aTask->strSource.c_str()); 730 747 break; 731 748 } … … 780 797 case VERR_NOT_FOUND: 781 798 LogRel(("Guest Additions seem not to be installed yet\n")); 782 rc = GuestTask::setProgressError Info(VBOX_E_NOT_SUPPORTED, aTask->pProgress,783 799 rc = GuestTask::setProgressErrorMsg(VBOX_E_NOT_SUPPORTED, aTask->pProgress, 800 Guest::tr("Guest Additions seem not to be installed or are not ready to update yet")); 784 801 break; 785 802 … … 788 805 case VERR_INVALID_PARAMETER: 789 806 LogRel(("Guest Additions are installed but don't supported automatic updating\n")); 790 rc = GuestTask::setProgressError Info(VBOX_E_NOT_SUPPORTED, aTask->pProgress,791 807 rc = GuestTask::setProgressErrorMsg(VBOX_E_NOT_SUPPORTED, aTask->pProgress, 808 Guest::tr("Installed Guest Additions do not support automatic updating")); 792 809 break; 793 810 794 811 case VERR_TIMEOUT: 795 812 LogRel(("Guest was unable to start copying the Guest Additions setup within time\n")); 796 rc = GuestTask::setProgressError Info(E_FAIL, aTask->pProgress,797 813 rc = GuestTask::setProgressErrorMsg(E_FAIL, aTask->pProgress, 814 Guest::tr("Guest was unable to start copying the Guest Additions setup within time")); 798 815 break; 799 816 800 817 default: 801 rc = GuestTask::setProgressError Info(E_FAIL, aTask->pProgress,802 803 818 rc = GuestTask::setProgressErrorMsg(E_FAIL, aTask->pProgress, 819 Guest::tr("Error copying Guest Additions setup file to guest path \"%s\" (%Rrc)"), 820 strInstallerPath.c_str(), vrc); 804 821 break; 805 822 } … … 854 871 if (FAILED(rc)) 855 872 { 856 rc = GuestTask::setProgressError Info(rc, aTask->pProgress, pGuest);873 rc = GuestTask::setProgressErrorParent(rc, aTask->pProgress, pGuest); 857 874 break; 858 875 } … … 870 887 else if (RT_FAILURE(vrc)) 871 888 { 872 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,873 874 889 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 890 Guest::tr("Error while reading setup file \"%s\" (To read: %u, Size: %u) from installation medium (%Rrc)"), 891 installerImage.c_str(), cbToRead, cbLength, vrc); 875 892 } 876 893 } … … 943 960 * complete the progress object now so that the caller can do other work. */ 944 961 if (aTask->uFlags & AdditionsUpdateFlag_WaitForUpdateStartOnly) 945 aTask->pProgress->notifyComplete(S_OK); 962 { 963 rc = GuestTask::setProgressSuccess(aTask->pProgress); 964 ComAssertRC(rc); 965 } 946 966 else 947 967 aTask->pProgress->SetCurrentOperationProgress(70); … … 978 998 if ( SUCCEEDED(aTask->pProgress->COMGETTER(Completed(&fCompleted))) 979 999 && !fCompleted) 980 aTask->pProgress->notifyComplete(S_OK); 1000 { 1001 rc = GuestTask::setProgressSuccess(aTask->pProgress); 1002 } 981 1003 } 982 1004 else … … 984 1006 LogRel(("Guest Additions update failed (Exit code=%u, Status=%u, Flags=%u)\n", 985 1007 uRetExitCode, retStatus, uRetFlags)); 986 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,987 988 1008 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 1009 Guest::tr("Guest Additions update failed with exit code=%u (status=%u, flags=%u)"), 1010 uRetExitCode, retStatus, uRetFlags); 989 1011 } 990 1012 } … … 993 1015 { 994 1016 LogRel(("Guest Additions update was canceled\n")); 995 rc = GuestTask::setProgressError Info(VBOX_E_IPRT_ERROR, aTask->pProgress,996 997 1017 rc = GuestTask::setProgressErrorMsg(VBOX_E_IPRT_ERROR, aTask->pProgress, 1018 Guest::tr("Guest Additions update was canceled by the guest with exit code=%u (status=%u, flags=%u)"), 1019 uRetExitCode, retStatus, uRetFlags); 998 1020 } 999 1021 else … … 1003 1025 } 1004 1026 else 1005 rc = GuestTask::setProgressError Info(rc, aTask->pProgress, pGuest);1027 rc = GuestTask::setProgressErrorParent(rc, aTask->pProgress, pGuest); 1006 1028 } 1007 1029 else 1008 rc = GuestTask::setProgressError Info(rc, aTask->pProgress, pGuest);1030 rc = GuestTask::setProgressErrorParent(rc, aTask->pProgress, pGuest); 1009 1031 } 1010 1032 }
Note:
See TracChangeset
for help on using the changeset viewer.