VirtualBox

Changeset 50734 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Mar 10, 2014 1:54:03 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
92721
Message:

DnD: Bugfixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/GuestDnDImpl.cpp

    r50724 r50734  
    204204    HRESULT queryProgressTo(IProgress **ppProgress);
    205205
     206    int writeToFile(const char *pszPath, size_t cbPath, void *pvData, size_t cbData, uint32_t fMode);
     207
    206208public:
    207209
     
    223225    /** Dropped files directory on the host. */
    224226    Utf8Str              m_strDropDir;
     227    /** The handle of the currently opened file being written to
     228     *  or read from. */
     229    RTFILE               m_hFile;
     230    Utf8Str              m_strFile;
    225231
    226232    ComObjPtr<Guest>     m_parent;
     
    294300  , m_cbDataCurrent(0)
    295301  , m_cbDataTotal(0)
     302  , m_hFile(NIL_RTFILE)
    296303  , m_parent(pGuest)
    297304{
     
    303310{
    304311    reset();
     312
    305313    int rc = RTSemEventDestroy(m_EventSem);
    306314    AssertRC(rc);
     
    346354            break;
    347355
     356        case VERR_NOT_FOUND:
     357            /* Should not happen due to file locking on the guest, but anyway ... */
     358            strError += Utf8StrFmt(pGuest->tr("One or more guest files or directories selected for transferring to the host were not"
     359                                              "found on the guest anymore. This can be the case if the guest files were moved and/or"
     360                                              "altered while the drag'n drop operation was in progress."));
     361            break;
     362
    348363        case VERR_SHARING_VIOLATION:
    349364            strError += Utf8StrFmt(pGuest->tr("One or more guest files or directories selected for transferring to the host were locked. "
     
    367382void DnDGuestResponse::reset(void)
    368383{
     384    LogFlowThisFuncEnter();
     385
     386    m_defAction = 0;
     387    m_allActions = 0;
     388
    369389    m_strDropDir = "";
    370390    m_strFormat = "";
     
    375395        m_pvData = NULL;
    376396    }
    377     m_cbData = 0;
    378 
     397    m_cbData = 0;   
    379398    m_cbDataCurrent = 0;
    380399    m_cbDataTotal = 0;
     400
     401    if (m_hFile != NIL_RTFILE)
     402    {
     403        RTFileClose(m_hFile);
     404        m_hFile = NIL_RTFILE;
     405    }
     406    m_strFile = "";
    381407}
    382408
     
    492518}
    493519
     520int DnDGuestResponse::writeToFile(const char *pszPath, size_t cbPath,
     521                                  void *pvData, size_t cbData, uint32_t fMode)
     522{
     523    /** @todo Support locking more than one file at a time! We
     524     *        might want to have a table in DnDGuestImpl which
     525     *        keeps those file pointers around, or extend the
     526     *        actual protocol for explicit open calls.
     527     * 
     528     *        For now we only keep one file open at a time, so if
     529     *        a client does alternating writes to different files
     530     *        this function will close the old and re-open the new
     531     *        file on every call. */
     532    int rc;
     533    if (   m_hFile == NIL_RTFILE
     534        || m_strFile != pszPath)
     535    {
     536        char *pszFile = RTPathJoinA(m_strDropDir.c_str(), pszPath);
     537        if (pszFile)
     538        {
     539            RTFILE hFile;
     540            /** @todo Respect fMode!  */
     541            rc = RTFileOpen(&hFile, pszFile,
     542                              RTFILE_O_OPEN_CREATE | RTFILE_O_DENY_WRITE
     543                            | RTFILE_O_WRITE | RTFILE_O_APPEND);
     544            if (RT_SUCCESS(rc))
     545            {
     546                LogFlowFunc(("Opening \"%s\" (fMode=0x%x) for writing ...\n",
     547                             pszFile, fMode));
     548
     549                m_hFile = hFile;
     550                m_strFile = pszPath;
     551            }
     552
     553            RTStrFree(pszFile);
     554        }
     555        else
     556            rc = VERR_NO_MEMORY;
     557    }
     558    else
     559        rc = VINF_SUCCESS;
     560
     561    if (RT_SUCCESS(rc))
     562    {
     563        rc = RTFileWrite(m_hFile, pvData, cbData,
     564                         NULL /* No partial writes */);
     565
     566        if (RT_SUCCESS(rc))
     567            rc = dataSetStatus(cbData);
     568    }
     569
     570    return rc;
     571}
     572
    494573///////////////////////////////////////////////////////////////////////////////
    495574
     
    719798
    720799        DnDGuestResponse *pResp = d->response();
    721         /* This blocks until the request is answered (or timeout). */
    722800        if (pResp->waitForGuestResponse() == VERR_TIMEOUT)
    723801            return S_OK;
     
    783861
    784862        DnDGuestResponse *pResp = d->response();
    785         /* This blocks until the request is answered (or timeout). */
    786863        if (pResp->waitForGuestResponse() == VERR_TIMEOUT)
    787864            return S_OK;
     
    813890
    814891        DnDGuestResponse *pResp = d->response();
    815         /* This blocks until the request is answered (or timeout). */
    816892        pResp->waitForGuestResponse();
    817893    }
     
    873949
    874950        DnDGuestResponse *pResp = d->response();
    875         /* This blocks until the request is answered (or timeout). */
    876951        if (pResp->waitForGuestResponse() == VERR_TIMEOUT)
    877952            return S_OK;
    878953
    879         /* Copy the response info */
     954        /* Get the resulting action from the guest. */
    880955        *pResultAction = d->toMainAction(pResp->defAction());
     956
     957        LogFlowFunc(("resFormat=%s, resAction=%RU32\n",
     958                     pResp->format().c_str(), pResp->defAction()));
     959
    881960        Bstr(pResp->format()).cloneTo(pstrFormat);
    882 
    883         LogFlowFunc(("*pResultAction=%ld\n", *pResultAction));
    884961    }
    885962    catch (HRESULT hr2)
     
    9571034                    paParms);
    9581035
    959         /* This blocks until the request is answered (or timed out). */
    9601036        DnDGuestResponse *pResp = d->response();
    9611037        if (pResp->waitForGuestResponse() == VERR_TIMEOUT)
     
    11671243                 pszPath, cbPath, fMode));
    11681244
    1169     /** @todo Add file locking between calls! */
    1170     int rc;
    1171     char *pszFile = RTPathJoinA(pResp->dropDir().c_str(), pszPath);
    1172     if (pszFile)
    1173     {
    1174         RTFILE hFile;
    1175         rc = RTFileOpen(&hFile, pszFile,
    1176                         RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_WRITE | RTFILE_O_WRITE);
    1177         if (RT_SUCCESS(rc))
    1178         {
    1179             rc = RTFileWrite(hFile, pvData, cbData,
    1180                              NULL /* No partial writes */);
    1181             RTFileClose(hFile);
    1182         }
    1183         RTStrFree(pszFile);
    1184     }
    1185     else
    1186         rc = VERR_NO_MEMORY;
    1187 
    1188     if (RT_SUCCESS(rc))
    1189         rc = pResp->dataSetStatus(cbData);
     1245    int rc = pResp->writeToFile(pszPath, cbPath, pvData, cbData, fMode);
    11901246
    11911247    LogFlowFuncLeaveRC(rc);
Note: See TracChangeset for help on using the changeset viewer.

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