VirtualBox

Changeset 33839 in vbox for trunk/src


Ignore:
Timestamp:
Nov 8, 2010 1:41:37 PM (14 years ago)
Author:
vboxsync
Message:

Frontends/VBoxManage: Fix error checking where important, the rest is caught by variable initialisation. Also run the event queue from time to time, cannot hurt.

File:
1 edited

Legend:

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

    r33766 r33839  
    6969}
    7070
    71 
    7271/**
    73  * Print out progress on the console
     72 * Print out progress on the console.
     73 *
     74 * This runs the main event queue every now and then to prevent piling up
     75 * unhandled things (which doesn't cause real problems, just makes things
     76 * react a little slower than in the ideal case).
    7477 */
    7578HRESULT showProgress(ComPtr<IProgress> progress)
     
    7780    using namespace com;
    7881
    79     BOOL fCompleted;
    80     ULONG ulCurrentPercent;
     82    BOOL fCompleted = FALSE;
     83    ULONG ulCurrentPercent = 0;
    8184    ULONG ulLastPercent = 0;
    8285
    83     ULONG ulCurrentOperationPercent;
    8486    ULONG ulLastOperationPercent = (ULONG)-1;
    8587
     
    8789    Bstr bstrOperationDescription;
    8890
    89     ULONG cOperations;
    90     progress->COMGETTER(OperationCount)(&cOperations);
     91    EventQueue::getMainEventQueue()->processEventQueue(0);
     92
     93    ULONG cOperations = 1;
     94    HRESULT hrc = progress->COMGETTER(OperationCount)(&cOperations);
     95    if (FAILED(hrc))
     96    {
     97        RTStrmPrintf(g_pStdErr, "Progress object failure: %Rhrc\n", hrc);
     98        RTStrmFlush(g_pStdErr);
     99        return hrc;
     100    }
    91101
    92102    if (!g_fDetailedProgress)
     
    99109    bool fCanceledAlready = false;
    100110    BOOL fCancelable;
    101     HRESULT hrc = progress->COMGETTER(Cancelable)(&fCancelable);
     111    hrc = progress->COMGETTER(Cancelable)(&fCancelable);
    102112    if (FAILED(hrc))
    103113        fCancelable = FALSE;
     
    110120    }
    111121
    112     while (SUCCEEDED(progress->COMGETTER(Completed(&fCompleted))))
    113     {
    114         ULONG ulOperation;
    115         progress->COMGETTER(Operation)(&ulOperation);
    116 
     122    hrc = progress->COMGETTER(Completed(&fCompleted));
     123    while (SUCCEEDED(hrc))
     124    {
    117125        progress->COMGETTER(Percent(&ulCurrentPercent));
    118         progress->COMGETTER(OperationPercent(&ulCurrentOperationPercent));
    119126
    120127        if (g_fDetailedProgress)
    121128        {
     129            ULONG ulOperation = 1;
     130            hrc = progress->COMGETTER(Operation)(&ulOperation);
     131            if (FAILED(hrc))
     132                break;
     133            ULONG ulCurrentOperationPercent = 0;
     134            hrc = progress->COMGETTER(OperationPercent(&ulCurrentOperationPercent));
     135            if (FAILED(hrc))
     136                break;
     137
    122138            if (ulLastOperation != ulOperation)
    123139            {
    124                 progress->COMGETTER(OperationDescription(bstrOperationDescription.asOutParam()));
     140                hrc = progress->COMGETTER(OperationDescription(bstrOperationDescription.asOutParam()));
     141                if (FAILED(hrc))
     142                    break;
    125143                ulLastPercent = (ULONG)-1;        // force print
    126144                ulLastOperation = ulOperation;
     
    131149               )
    132150            {
    133                 LONG lSecsRem;
     151                LONG lSecsRem = 0;
    134152                progress->COMGETTER(TimeRemaining)(&lSecsRem);
    135153
     
    171189        /* make sure the loop is not too tight */
    172190        progress->WaitForCompletion(100);
     191
     192        EventQueue::getMainEventQueue()->processEventQueue(0);
     193        hrc = progress->COMGETTER(Completed(&fCompleted));
    173194    }
    174195
     
    184205    /* complete the line. */
    185206    LONG iRc = E_FAIL;
    186     if (SUCCEEDED(progress->COMGETTER(ResultCode)(&iRc)))
     207    hrc = progress->COMGETTER(ResultCode)(&iRc);
     208    if (SUCCEEDED(hrc))
    187209    {
    188210        if (SUCCEEDED(iRc))
     
    191213            RTStrmPrintf(g_pStdErr, "CANCELED\n");
    192214        else
    193             RTStrmPrintf(g_pStdErr, "FAILED\n");
     215        {
     216            if (!g_fDetailedProgress)
     217                RTStrmPrintf(g_pStdErr, "\n");
     218            RTStrmPrintf(g_pStdErr, "Progress state: %Rhrc\n", iRc);
     219        }
     220        hrc = iRc;
    194221    }
    195222    else
    196         RTStrmPrintf(g_pStdErr, "\n");
     223    {
     224        if (!g_fDetailedProgress)
     225            RTStrmPrintf(g_pStdErr, "\n");
     226        RTStrmPrintf(g_pStdErr, "Progress object failure: %Rhrc\n", hrc);
     227    }
    197228    RTStrmFlush(g_pStdErr);
    198     return iRc;
     229    return hrc;
    199230}
    200231
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