VirtualBox

Ignore:
Timestamp:
Jul 16, 2021 10:28:08 PM (4 years ago)
Author:
vboxsync
Message:

VBoxManage: Give showProgress() a flags argument so that it can poll
the progress quietly. While here, teach it to print the progress
description (alone, or before the running progress count). No
existing callers should be affected, though the couple of callers that
use g_fDetailedProgress should be converted to the the flags instead.

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp

    r86434 r90234  
    202202 * react a little slower than in the ideal case).
    203203 */
    204 HRESULT showProgress(ComPtr<IProgress> progress)
     204HRESULT showProgress(ComPtr<IProgress> progress, unsigned int fFlags)
    205205{
    206206    using namespace com;
     207    HRESULT hrc;
    207208
    208209    AssertReturn(progress.isNotNull(), E_FAIL);
     210
     211    /* grandfather the old callers */
     212    if (g_fDetailedProgress)
     213        fFlags = SHOW_PROGRESS_DETAILS;
     214
     215    const bool fDetailed = RT_BOOL(fFlags & SHOW_PROGRESS_DETAILS);
     216    const bool fQuiet = !RT_BOOL(fFlags & (SHOW_PROGRESS | SHOW_PROGRESS_DETAILS));
     217
    209218
    210219    BOOL fCompleted = FALSE;
     
    220229
    221230    ULONG cOperations = 1;
    222     HRESULT hrc = progress->COMGETTER(OperationCount)(&cOperations);
     231    hrc = progress->COMGETTER(OperationCount)(&cOperations);
    223232    if (FAILED(hrc))
    224233    {
     
    226235        RTStrmFlush(g_pStdErr);
    227236        return hrc;
     237    }
     238
     239    if (fFlags & SHOW_PROGRESS_DESC)
     240    {
     241        com::Bstr bstrDescription;
     242        hrc = progress->COMGETTER(Description(bstrDescription.asOutParam()));
     243        if (FAILED(hrc))
     244        {
     245            RTStrmPrintf(g_pStdErr, "Failed to get progress description: %Rhrc\n", hrc);
     246            return hrc;
     247        }
     248
     249        const char *pcszDescSep;
     250        if (fFlags & SHOW_PROGRESS_DETAILS)
     251            pcszDescSep = "\n";
     252        else
     253            pcszDescSep = ": ";
     254
     255        RTStrmPrintf(g_pStdErr, "%ls%s", bstrDescription.raw(), pcszDescSep);
     256        RTStrmFlush(g_pStdErr);
    228257    }
    229258
     
    234263     */
    235264
    236     if (!g_fDetailedProgress)
     265    if (!fQuiet && !fDetailed)
    237266    {
    238267        RTStrmPrintf(g_pStdErr, "0%%...");
     
    260289        progress->COMGETTER(Percent(&ulCurrentPercent));
    261290
    262         if (g_fDetailedProgress)
     291        if (fDetailed)
    263292        {
    264293            ULONG ulOperation = 1;
     
    293322            }
    294323        }
    295         else
     324        else if (!fQuiet)
    296325        {
    297326            /* did we cross a 10% mark? */
     
    345374    if (SUCCEEDED(hrc))
    346375    {
     376        /* async operation completed successfully */
    347377        if (SUCCEEDED(iRc))
    348             RTStrmPrintf(g_pStdErr, "100%%\n");
     378        {
     379            if (!fDetailed)
     380            {
     381                if (fFlags == SHOW_PROGRESS_DESC)
     382                    RTStrmPrintf(g_pStdErr, "ok\n");
     383                else if (!fQuiet)
     384                    RTStrmPrintf(g_pStdErr, "100%%\n");
     385            }
     386        }
    349387        else if (g_fCanceled)
    350388            RTStrmPrintf(g_pStdErr, "CANCELED\n");
    351389        else
    352390        {
    353             if (!g_fDetailedProgress)
     391            if (!fDetailed)
    354392                RTStrmPrintf(g_pStdErr, "\n");
    355393            RTStrmPrintf(g_pStdErr, "Progress state: %Rhrc\n", iRc);
     
    359397    else
    360398    {
    361         if (!g_fDetailedProgress)
     399        if (!fDetailed)
    362400            RTStrmPrintf(g_pStdErr, "\n");
    363401        RTStrmPrintf(g_pStdErr, "Progress object failure: %Rhrc\n", hrc);
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r88086 r90234  
    209209RTEXITCODE  errorSyntax(const char *pszFormat, ...);
    210210
    211 HRESULT showProgress(ComPtr<IProgress> progress);
     211
     212#define SHOW_PROGRESS_NONE      0
     213#define SHOW_PROGRESS_DESC      (1u << 0)
     214#define SHOW_PROGRESS           (1u << 1)
     215#define SHOW_PROGRESS_DETAILS   (1u << 2)
     216HRESULT showProgress(ComPtr<IProgress> progress, unsigned int fFlags = SHOW_PROGRESS);
    212217#endif
    213218
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette