VirtualBox

Ignore:
Timestamp:
May 28, 2019 10:54:53 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
130905
Message:

Shared Clipboard/URI: Update.

Location:
trunk/src/VBox/GuestHost/SharedClipboard
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/ClipboardDataObjectImpl-win.cpp

    r78725 r78809  
    4242#include <VBox/log.h>
    4343
     44#if 1 /** Not enabled yet, needs more testing first. */
     45# define VBOX_CLIPBOARD_WITH_UNICODE_SUPPORT 1
     46#endif
     47
    4448VBoxClipboardWinDataObject::VBoxClipboardWinDataObject(SharedClipboardProvider *pProvider,
    4549                                                       LPFORMATETC pFormatEtc, LPSTGMEDIUM pStgMed, ULONG cFormats)
     
    4852    , m_cFormats(0)
    4953    , m_pProvider(pProvider)
     54    , m_pStream(NULL)
    5055{
    5156    AssertPtr(pProvider);
     
    5358    HRESULT hr;
    5459
    55     const ULONG cFixedFormats = 3; /* CFSTR_FILEDESCRIPTORA + CFSTR_FILEDESCRIPTORW + CFSTR_FILECONTENTS */
     60    ULONG cFixedFormats = 2; /* CFSTR_FILEDESCRIPTORA + CFSTR_FILECONTENTS */
     61#ifdef VBOX_CLIPBOARD_WITH_UNICODE_SUPPORT
     62    cFixedFormats++; /* CFSTR_FILEDESCRIPTORW */
     63#endif
    5664    const ULONG cAllFormats   = cFormats + cFixedFormats;
    5765
     
    6977         */
    7078
    71         /* IStream interface, implemented in ClipboardStreamImpl-win.cpp. */
     79        LogFlowFunc(("Registering CFSTR_FILEDESCRIPTORA ...\n"));
    7280        registerFormat(&m_pFormatEtc[FormatIndex_FileDescriptorA],
    7381                       RegisterClipboardFormat(CFSTR_FILEDESCRIPTORA));
     82#ifdef VBOX_CLIPBOARD_WITH_UNICODE_SUPPORT
     83        LogFlowFunc(("Registering CFSTR_FILEDESCRIPTORW ...\n"));
    7484        registerFormat(&m_pFormatEtc[FormatIndex_FileDescriptorW],
    7585                       RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW));
     86#endif
     87        /* IStream interface, implemented in ClipboardStreamImpl-win.cpp. */
     88        LogFlowFunc(("Registering CFSTR_FILECONTENTS ...\n"));
    7689        registerFormat(&m_pFormatEtc[FormatIndex_FileContents],
    7790                       RegisterClipboardFormat(CFSTR_FILECONTENTS),
     
    171184}
    172185
     186/**
     187 * Copies a chunk of data into a HGLOBAL object.
     188 *
     189 * @returns VBox status code.
     190 * @param   pvData              Data to copy.
     191 * @param   cbData              Size (in bytes) to copy.
     192 * @param   fFlags              GlobalAlloc flags, used for allocating the HGLOBAL block.
     193 * @param   phGlobal            Where to store the allocated HGLOBAL object.
     194 */
    173195int VBoxClipboardWinDataObject::copyToHGlobal(const void *pvData, size_t cbData, UINT fFlags, HGLOBAL *phGlobal)
    174196{
     
    194216}
    195217
    196 int VBoxClipboardWinDataObject::createFileGroupDescriptor(const SharedClipboardURIList &URIList,
    197                                                           bool fUnicode, HGLOBAL *phGlobal)
    198 {
    199 //    AssertReturn(URIList.GetRootCount(), VERR_INVALID_PARAMETER);
    200     AssertPtrReturn(phGlobal, VERR_INVALID_POINTER);
    201 
    202     RT_NOREF(fUnicode);
    203 
    204     int rc;
    205 
    206     const size_t cItems = 2;  URIList.GetRootCount();
    207     const size_t cbFGD  = sizeof(FILEGROUPDESCRIPTOR) + sizeof(FILEDESCRIPTOR) * (cItems - 1);
    208 
    209     LogFunc(("cItmes=%zu\n", cItems));
    210 
     218/**
     219 * Creates a FILEGROUPDESCRIPTOR object from a given Shared Clipboard URI list and stores
     220 * the result into an HGLOBAL object.
     221 *
     222 * @returns VBox status code.
     223 * @param   URIList             URI list to create object for.
     224 * @param   fUnicode            Whether the FILEGROUPDESCRIPTOR object shall contain Unicode data or not.
     225 * @param   phGlobal            Where to store the allocated HGLOBAL object on success.
     226 */
     227int VBoxClipboardWinDataObject::createFileGroupDescriptorFromURIList(const SharedClipboardURIList &URIList,
     228                                                                     bool fUnicode, HGLOBAL *phGlobal)
     229{
     230    AssertReturn(URIList.GetRootCount(), VERR_INVALID_PARAMETER);
     231    AssertPtrReturn(phGlobal,            VERR_INVALID_POINTER);
     232
     233    LogFlowFuncEnter();
     234
     235    const size_t cbFileGroupDescriptor = fUnicode ? sizeof(FILEGROUPDESCRIPTORW) : sizeof(FILEGROUPDESCRIPTORA);
     236    const size_t cbFileDescriptor = fUnicode ? sizeof(FILEDESCRIPTORW) : sizeof(FILEDESCRIPTORA);
     237
     238    const UINT   cItems = (UINT)URIList.GetRootCount(); /** @todo UINT vs. uint64_t */
     239    const size_t cbFGD  = cbFileGroupDescriptor + (cbFileDescriptor * (cItems - 1));
     240
     241    LogFunc(("fUnicode=%RTbool, cItems=%u, cbFileDescriptor=%zu\n", fUnicode, cItems, cbFileDescriptor));
     242
     243    /* FILEGROUPDESCRIPTORA / FILEGROUPDESCRIPTOR matches except the cFileName member (TCHAR vs. WCHAR). */
    211244    FILEGROUPDESCRIPTOR *pFGD = (FILEGROUPDESCRIPTOR *)RTMemAlloc(cbFGD);
    212     if (pFGD)
    213     {
    214         pFGD->cItems = (UINT)cItems;
    215 
    216 
    217         FILEDESCRIPTOR *pFD = &pFGD->fgd[0];
    218         RT_BZERO(pFD, sizeof(FILEDESCRIPTOR));
    219 
    220         RTStrPrintf(pFD->cFileName, sizeof(pFD->cFileName), "barbaz.txt\n");
    221 
    222     #if 1
    223         pFD->dwFlags          = FD_ATTRIBUTES | FD_FILESIZE | FD_PROGRESSUI;
    224         pFD->dwFileAttributes = FILE_ATTRIBUTE_NORMAL; // FILE_ATTRIBUTE_DIRECTORY;
    225 
    226         uint64_t cbSize = _1M;
    227 
    228         pFD->nFileSizeHigh    = RT_HI_U32(cbSize);
    229         pFD->nFileSizeLow     = RT_LO_U32(cbSize);
    230     #else
    231         pFD->dwFlags = FD_ATTRIBUTES | FD_CREATETIME | FD_ACCESSTIME | FD_WRITESTIME | FD_FILESIZE;
     245    if (!pFGD)
     246        return VERR_NO_MEMORY;
     247
     248    int rc = VINF_SUCCESS;
     249
     250    pFGD->cItems = cItems;
     251
     252    char *pszFileSpec = NULL;
     253
     254    for (UINT i = 0; i < cItems; i++)
     255    {
     256        FILEDESCRIPTOR *pFD = &pFGD->fgd[i];
     257        RT_BZERO(pFD, cbFileDescriptor);
     258
     259        const SharedClipboardURIObject *pObj = URIList.At(i);
     260        AssertPtr(pObj);
     261        const char *pszFile = pObj->GetSourcePathAbs().c_str();
     262        AssertPtr(pszFile);
     263
     264        pszFileSpec = RTStrDup(pszFile);
     265        AssertBreakStmt(pszFileSpec != NULL, rc = VERR_NO_MEMORY);
     266
     267        if (fUnicode)
     268        {
     269            PRTUTF16 pwszFileSpec;
     270            rc = RTStrToUtf16(pszFileSpec, &pwszFileSpec);
     271            if (RT_SUCCESS(rc))
     272            {
     273                rc = RTUtf16CopyEx((PRTUTF16 )pFD->cFileName, sizeof(pFD->cFileName) / sizeof(WCHAR),
     274                                   pwszFileSpec, RTUtf16Len(pwszFileSpec));
     275                RTUtf16Free(pwszFileSpec);
     276            }
     277        }
     278        else
     279            rc = RTStrCopy(pFD->cFileName, sizeof(pFD->cFileName), pszFileSpec);
     280
     281        RTStrFree(pszFileSpec);
     282        pszFileSpec = NULL;
     283
     284        if (RT_FAILURE(rc))
     285            break;
     286
     287        pFD->dwFlags          = FD_PROGRESSUI | FD_ATTRIBUTES;
     288        if (fUnicode) /** @todo Only >= Vista. */
     289            pFD->dwFlags     |= FD_UNICODE;
     290        pFD->dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
     291
     292        switch (pObj->GetType())
     293        {
     294            case SharedClipboardURIObject::Type_Directory:
     295                pFD->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
     296
     297                LogFunc(("pszDir=%s\n", pszFile));
     298                break;
     299
     300            case SharedClipboardURIObject::Type_File:
     301            {
     302                pFD->dwFlags |= FD_FILESIZE;
     303
     304                const uint64_t cbObjSize = pObj->GetSize();
     305
     306                pFD->nFileSizeHigh = RT_HI_U32(cbObjSize);
     307                pFD->nFileSizeLow  = RT_LO_U32(cbObjSize);
     308
     309                LogFunc(("pszFile=%s, cbObjSize=%RU64\n", pszFile, cbObjSize));
     310                break;
     311            }
     312
     313            default:
     314                AssertFailed();
     315                break;
     316        }
     317#if 0
     318        pFD->dwFlags = FD_ATTRIBUTES | FD_CREATETIME | FD_ACCESSTIME | FD_WRITESTIME | FD_FILESIZE; /** @todo Implement this. */
    232319        pFD->dwFileAttributes =
    233320        pFD->ftCreationTime   =
    234321        pFD->ftLastAccessTime =
    235322        pFD->ftLastWriteTime  =
    236         pFD->nFileSizeHigh    =
    237         pFD->nFileSizeLow     =
    238     #endif
    239 
    240 
    241 
    242         pFD = &pFGD->fgd[1];
    243         RT_BZERO(pFD, sizeof(FILEDESCRIPTOR));
    244 
    245         RTStrPrintf(pFD->cFileName, sizeof(pFD->cFileName), "barbaz_dir\n");
    246 
    247     #if 1
    248         pFD->dwFlags          = FD_ATTRIBUTES | FD_PROGRESSUI;
    249         pFD->dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY;
    250     #else
    251         pFD->dwFlags = FD_ATTRIBUTES | FD_CREATETIME | FD_ACCESSTIME | FD_WRITESTIME | FD_FILESIZE;
    252         pFD->dwFileAttributes =
    253         pFD->ftCreationTime   =
    254         pFD->ftLastAccessTime =
    255         pFD->ftLastWriteTime  =
    256         pFD->nFileSizeHigh    =
    257         pFD->nFileSizeLow     =
    258     #endif
    259 
    260 
     323#endif
     324    }
     325
     326    if (pszFileSpec)
     327        RTStrFree(pszFileSpec);
     328
     329    if (RT_SUCCESS(rc))
     330    {
    261331        rc = copyToHGlobal(pFGD, cbFGD, GMEM_MOVEABLE, phGlobal);
    262332    }
    263333    else
    264         rc = VERR_NO_MEMORY;
    265 
     334    {
     335        RTMemFree(pFGD);
     336    }
     337
     338    LogFlowFuncLeaveRC(rc);
    266339    return rc;
    267340}
     
    312385    {
    313386        case FormatIndex_FileDescriptorA: /* ANSI */
     387#ifdef VBOX_CLIPBOARD_WITH_UNICODE_SUPPORT
     388            RT_FALL_THROUGH();
    314389        case FormatIndex_FileDescriptorW: /* Unicode */
     390#endif
    315391        {
    316392            const bool fUnicode = lIndex == FormatIndex_FileDescriptorW;
     
    319395
    320396            SharedClipboardURIList uriList;
    321             int rc = m_pProvider->ReadMetaData(uriList, 0 /* fFlags */);
    322             if (RT_SUCCESS(rc))
     397            int rc = m_pProvider->ReadMetaData(uriList); /** @todo Do this asynchronously some time earlier? */
     398
     399#if 0
     400    SharedClipboardURIObject *pObj1 = new SharedClipboardURIObject(SharedClipboardURIObject::Type_File, "foobar.baz1");
     401    pObj1->SetSize(_64M);
     402    uriList.AppendURIObject(pObj1);
     403#endif
     404
     405            if (   RT_SUCCESS(rc)
     406                && !uriList.IsEmpty())
    323407            {
    324408                HGLOBAL hGlobal;
    325                 rc = createFileGroupDescriptor(uriList, fUnicode, &hGlobal);
     409                rc = createFileGroupDescriptorFromURIList(uriList, fUnicode, &hGlobal);
    326410                if (RT_SUCCESS(rc))
    327411                {
     412                    LogFlowFunc(("FOO1\n"));
     413
    328414                    pMedium->tymed   = TYMED_HGLOBAL;
    329415                    pMedium->hGlobal = hGlobal;
    330416                    /* Note: hGlobal now is being owned by pMedium / the caller. */
    331417
     418                    LogFlowFunc(("FOO2\n"));
    332419                    hr = S_OK;
    333420                }
    334421            }
     422            LogFlowFunc(("FOO2.1\n"));
    335423            break;
    336424        }
     
    340428            LogFlowFunc(("FormatIndex_FileContents\n"));
    341429
     430            /* Hand-in the provider so that our IStream implementation can continue working with it. */
    342431            hr = VBoxClipboardWinStreamImpl::Create(m_pProvider, &m_pStream);
    343432            if (SUCCEEDED(hr))
    344433            {
    345434                /* Hand over the stream to the caller. */
    346                 pMedium->tymed          = TYMED_ISTREAM;
    347                 pMedium->pstm           = m_pStream;
     435                pMedium->tymed = TYMED_ISTREAM;
     436                pMedium->pstm  = m_pStream;
    348437            }
    349438
     
    355444    }
    356445
     446    LogFlowFunc(("FOO3\n"));
     447
    357448    /* Error handling; at least return some basic data. */
    358449    if (FAILED(hr))
     
    364455    }
    365456
     457LogFlowFunc(("FOO4\n"));
     458
    366459    if (hr == DV_E_FORMATETC)
    367460        LogRel(("Clipboard: Error handling format\n"));
     461
     462LogFlowFunc(("FOO5\n"));
    368463
    369464    LogFlowFunc(("hr=%Rhrc\n", hr));
     
    586681    {
    587682        if(    (pFormatEtc->tymed & m_pFormatEtc[i].tymed)
    588             && pFormatEtc->cfFormat == m_pFormatEtc[i].cfFormat
    589             && pFormatEtc->dwAspect == m_pFormatEtc[i].dwAspect)
     683            && pFormatEtc->cfFormat == m_pFormatEtc[i].cfFormat)
     684            /* Note: Do *not* compare dwAspect here, as this can be dynamic, depending on how the object should be represented. */
     685            //&& pFormatEtc->dwAspect == m_pFormatEtc[i].dwAspect)
    590686        {
    591687            LogRel3(("Clipboard: Format found: tyMed=%RI32, cfFormat=%RI16, sFormats=%s, dwAspect=%RI32, ulIndex=%RU32\n",
  • trunk/src/VBox/GuestHost/SharedClipboard/ClipboardEnumFormatEtcImpl-win.cpp

    r78443 r78809  
    9292    if (lCount == 0)
    9393    {
     94        LogFlowFunc(("Delete\n"));
    9495        delete this;
    9596        return 0;
     
    123124           && ulCopied < cFormats)
    124125    {
    125         VBoxClipboardWinEnumFormatEtc::CopyFormat(&pFormatEtc[ulCopied],
    126                                          &m_pFormatEtc[m_nIndex]);
     126        VBoxClipboardWinEnumFormatEtc::CopyFormat(&pFormatEtc[ulCopied], &m_pFormatEtc[m_nIndex]);
    127127        ulCopied++;
    128128        m_nIndex++;
     
    149149STDMETHODIMP VBoxClipboardWinEnumFormatEtc::Clone(IEnumFORMATETC **ppEnumFormatEtc)
    150150{
    151     HRESULT hResult =
    152         CreateEnumFormatEtc(m_nNumFormats, m_pFormatEtc, ppEnumFormatEtc);
    153 
     151    HRESULT hResult = CreateEnumFormatEtc(m_nNumFormats, m_pFormatEtc, ppEnumFormatEtc);
    154152    if (hResult == S_OK)
    155153        ((VBoxClipboardWinEnumFormatEtc *) *ppEnumFormatEtc)->m_nIndex = m_nIndex;
  • trunk/src/VBox/GuestHost/SharedClipboard/ClipboardProvider.cpp

    r78727 r78809  
    3434#include <VBox/log.h>
    3535
     36
     37
    3638SharedClipboardProvider::SharedClipboardProvider(void)
    3739    : m_cRefs(0)
    3840{
     41    LogFlowFuncEnter();
    3942}
    4043
    4144SharedClipboardProvider::~SharedClipboardProvider(void)
    4245{
     46    LogFlowFuncEnter();
    4347    Assert(m_cRefs == 0);
     48}
     49
     50/**
     51 * Creates a Shared Clipboard provider.
     52 *
     53 * @returns New Shared Clipboard provider instance.
     54 * @param   enmSource           Source type to create provider for.
     55 */
     56/* static */
     57SharedClipboardProvider *SharedClipboardProvider::Create(SourceType enmSource)
     58{
     59    SharedClipboardProvider *pProvider = NULL;
     60
     61    switch (enmSource)
     62    {
     63#ifdef VBOX_WITH_SHARED_CLIPBOARD_GUEST
     64        case SourceType_VbglR3:
     65            pProvider = new SharedClipboardProviderVbglR3();
     66            break;
     67#endif
     68
     69#ifdef VBOX_WITH_SHARED_CLIPBOARD_HOST
     70        case SourceType_HostService:
     71            pProvider = new SharedClipboardProviderHostService();
     72            break;
     73#endif
     74        default:
     75            AssertFailed();
     76            break;
     77    }
     78
     79    return pProvider;
    4480}
    4581
     
    5187uint32_t SharedClipboardProvider::AddRef(void)
    5288{
     89    LogFlowFuncEnter();
    5390    return ASMAtomicIncU32(&m_cRefs);
    5491}
     
    6198uint32_t SharedClipboardProvider::Release(void)
    6299{
     100    LogFlowFuncEnter();
    63101    Assert(m_cRefs);
    64102    return ASMAtomicDecU32(&m_cRefs);
    65103}
    66104
    67 int SharedClipboardProvider::SetSource(SourceType enmSource)
    68 {
    69     return m_enmSource = enmSource;
    70 }
    71 
    72 int SharedClipboardProvider::ReadMetaData(SharedClipboardURIList &URIList, uint32_t fFlags /* = 0 */)
    73 {
    74     int rc = VINF_SUCCESS;
    75 
    76     RT_NOREF(URIList, fFlags);
    77 
    78     return rc;
    79 }
    80 
  • trunk/src/VBox/GuestHost/SharedClipboard/ClipboardStreamImpl-win.cpp

    r78725 r78809  
    5050    , m_pProvider(pProvider)
    5151{
     52    LogFlowThisFuncEnter();
     53
    5254    m_pProvider->AddRef();
     55
     56    cbFileSize = _64M;
     57    cbSizeRead = 0;
    5358}
    5459
    5560VBoxClipboardWinStreamImpl::~VBoxClipboardWinStreamImpl(void)
    5661{
     62    LogFlowThisFuncEnter();
    5763    m_pProvider->Release();
    5864}
     
    114120    RT_NOREF(dwFrags);
    115121
    116     LogFlowFuncEnter();
     122    LogFlowThisFuncEnter();
    117123    return E_NOTIMPL;
    118124}
     
    123129    RT_NOREF(pDestStream, nBytesToCopy, nBytesRead, nBytesWritten);
    124130
    125     LogFlowFuncEnter();
     131    LogFlowThisFuncEnter();
    126132    return E_NOTIMPL;
    127133}
     
    131137    RT_NOREF(nStart, nBytes, dwFlags);
    132138
    133     LogFlowFuncEnter();
    134     return E_NOTIMPL;
    135 }
    136 
    137 static ULONG cbFileSize = _1M;
    138 static ULONG cbSizeRead = 0;
     139    LogFlowThisFuncEnter();
     140    return E_NOTIMPL;
     141}
    139142
    140143STDMETHODIMP VBoxClipboardWinStreamImpl::Read(void* pvBuffer, ULONG nBytesToRead, ULONG* nBytesRead)
     
    142145    /* If the file size is 0, already return at least 1 byte, else the whole operation will fail. */
    143146
    144     ULONG cbToRead = RT_MIN(cbFileSize - cbSizeRead,  _4K /* nBytesToRead */);
    145 
    146     if (cbToRead > nBytesToRead)
    147         cbToRead = nBytesToRead;
    148 
    149     LogFlowFunc(("pvBuffer=%p, nBytesToRead=%u -> cbSizeRead=%u, cbToRead=%u\n", pvBuffer, nBytesToRead, cbSizeRead, cbToRead));
    150 
    151     if (cbToRead)
    152     {
    153         memset(pvBuffer, cbToRead, 0x65);
    154         cbSizeRead += cbToRead;
    155     }
    156 
    157     if (nBytesRead)
    158         *nBytesRead = cbToRead;
    159 
    160     if (cbSizeRead == cbFileSize)
    161         cbSizeRead = 0;
    162 
     147    size_t cbRead = 0;
     148    int rc = m_pProvider->ReadData(pvBuffer, (size_t)nBytesToRead, &cbRead);
     149    if (RT_SUCCESS(rc))
     150    {
     151        if (*nBytesRead)
     152            *nBytesRead = (ULONG)cbRead;
     153    }
     154
     155    LogFlowThisFunc(("nBytesToRead=%u, nBytesRead=%zu\n", nBytesToRead, cbRead));
    163156    return S_OK;
    164157}
     
    166159STDMETHODIMP VBoxClipboardWinStreamImpl::Revert(void)
    167160{
    168     LogFlowFuncEnter();
     161    LogFlowThisFuncEnter();
    169162    return E_NOTIMPL;
    170163}
     
    174167    RT_NOREF(nMove, dwOrigin, nNewPos);
    175168
    176     LogFlowFuncEnter();
     169    LogFlowThisFuncEnter();
    177170    return E_NOTIMPL;
    178171}
     
    182175    RT_NOREF(nNewSize);
    183176
    184     LogFlowFuncEnter();
     177    LogFlowThisFuncEnter();
    185178    return E_NOTIMPL;
    186179}
     
    190183    RT_NOREF(statstg, dwFlags);
    191184
    192     LogFlowFuncEnter();
     185    LogFlowThisFuncEnter();
    193186    return E_NOTIMPL;
    194187}
     
    198191    RT_NOREF(nStart, nBytes, dwFlags);
    199192
    200     LogFlowFuncEnter();
     193    LogFlowThisFuncEnter();
    201194    return E_NOTIMPL;
    202195}
     
    206199    RT_NOREF(pvBuffer, nBytesToRead, nBytesRead);
    207200
    208     LogFlowFuncEnter();
     201    LogFlowThisFuncEnter();
    209202    return E_NOTIMPL;
    210203}
     
    224217HRESULT VBoxClipboardWinStreamImpl::Create(SharedClipboardProvider *pProvider, IStream **ppStream)
    225218{
     219    AssertPtrReturn(pProvider, E_POINTER);
     220
    226221    VBoxClipboardWinStreamImpl *pStream = new VBoxClipboardWinStreamImpl(pProvider);
    227222    if (pStream)
  • trunk/src/VBox/GuestHost/SharedClipboard/ClipboardURIList.cpp

    r78648 r78809  
    4646}
    4747
    48 int SharedClipboardURIList::addEntry(const char *pcszSource, const char *pcszTarget, SHAREDCLIPBOARDURILISTFLAGS fFlags)
     48int SharedClipboardURIList::appendEntry(const char *pcszSource, const char *pcszTarget, SHAREDCLIPBOARDURILISTFLAGS fFlags)
    4949{
    5050    AssertPtrReturn(pcszSource, VERR_INVALID_POINTER);
     
    5757    if (RT_SUCCESS(rc))
    5858    {
    59         if (RTFS_IS_FILE(objInfo.Attr.fMode))
    60         {
    61             LogFlowFunc(("File '%s' -> '%s' (%RU64 bytes, file mode 0x%x)\n",
    62                          pcszSource, pcszTarget, (uint64_t)objInfo.cbObject, objInfo.Attr.fMode));
    63 
    64             SharedClipboardURIObject *pObjFile = new SharedClipboardURIObject(SharedClipboardURIObject::Type_File,
    65                                                                               pcszSource, pcszTarget);
    66             if (pObjFile)
    67             {
    68                 /** @todo Add a standard fOpen mode for this list. */
    69                 rc = pObjFile->Open(SharedClipboardURIObject::View_Source, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
    70                 if (RT_SUCCESS(rc))
    71                 {
    72                     m_lstTree.append(pObjFile);
    73 
     59        try
     60        {
     61            if (RTFS_IS_FILE(objInfo.Attr.fMode))
     62            {
     63                LogFlowFunc(("File '%s' -> '%s' (%RU64 bytes, file mode 0x%x)\n",
     64                             pcszSource, pcszTarget, (uint64_t)objInfo.cbObject, objInfo.Attr.fMode));
     65
     66                SharedClipboardURIObject *pObjFile = new SharedClipboardURIObject(SharedClipboardURIObject::Type_File,
     67                                                                                  pcszSource, pcszTarget);
     68                if (pObjFile)
     69                {
     70                    /** @todo Add a standard fOpen mode for this list. */
     71                    rc = pObjFile->Open(SharedClipboardURIObject::View_Source, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
     72                    if (RT_SUCCESS(rc))
     73                    {
     74                        rc = appendObject(pObjFile);
     75                        if (!(fFlags & SHAREDCLIPBOARDURILIST_FLAGS_KEEP_OPEN)) /* Shall we keep the file open while being added to this list? */
     76                            pObjFile->Close();
     77                    }
     78                    else
     79                        delete pObjFile;
     80                }
     81                else
     82                    rc = VERR_NO_MEMORY;
     83            }
     84            else if (RTFS_IS_DIRECTORY(objInfo.Attr.fMode))
     85            {
     86                LogFlowFunc(("Directory '%s' -> '%s' (file mode 0x%x)\n", pcszSource, pcszTarget, objInfo.Attr.fMode));
     87
     88                SharedClipboardURIObject *pObjDir = new SharedClipboardURIObject(SharedClipboardURIObject::Type_Directory,
     89                                                                                 pcszSource, pcszTarget);
     90                if (pObjDir)
     91                {
     92                    m_lstTree.append(pObjDir);
     93
     94                    /** @todo Add SHAREDCLIPBOARDURILIST_FLAGS_KEEP_OPEN handling? */
    7495                    m_cTotal++;
    75                     m_cbTotal += pObjFile->GetSize();
    76 
    77                     if (!(fFlags & SHAREDCLIPBOARDURILIST_FLAGS_KEEP_OPEN)) /* Shall we keep the file open while being added to this list? */
    78                         pObjFile->Close();
    7996                }
    8097                else
    81                     delete pObjFile;
    82             }
     98                    rc = VERR_NO_MEMORY;
     99            }
     100            /* Note: Symlinks already should have been resolved at this point. */
    83101            else
    84                 rc = VERR_NO_MEMORY;
    85         }
    86         else if (RTFS_IS_DIRECTORY(objInfo.Attr.fMode))
    87         {
    88             LogFlowFunc(("Directory '%s' -> '%s' (file mode 0x%x)\n", pcszSource, pcszTarget, objInfo.Attr.fMode));
    89 
    90             SharedClipboardURIObject *pObjDir = new SharedClipboardURIObject(SharedClipboardURIObject::Type_Directory,
    91                                                                              pcszSource, pcszTarget);
    92             if (pObjDir)
    93             {
    94                 m_lstTree.append(pObjDir);
    95 
    96                 /** @todo Add SHAREDCLIPBOARDURILIST_FLAGS_KEEP_OPEN handling? */
    97                 m_cTotal++;
    98             }
    99             else
    100                 rc = VERR_NO_MEMORY;
    101         }
    102         /* Note: Symlinks already should have been resolved at this point. */
    103         else
    104             rc = VERR_NOT_SUPPORTED;
     102                rc = VERR_NOT_SUPPORTED;
     103        }
     104        catch (std::bad_alloc &)
     105        {
     106            rc = VERR_NO_MEMORY;
     107        }
    105108    }
    106109
     
    126129        if (RTFS_IS_DIRECTORY(objInfo.Attr.fMode))
    127130        {
    128             rc = addEntry(pcszSrcPath, &pcszDstPath[cchDstBase], fFlags);
     131            rc = appendEntry(pcszSrcPath, &pcszDstPath[cchDstBase], fFlags);
    129132            if (RT_SUCCESS(rc))
    130133            {
     
    181184                                    if (pszDst)
    182185                                    {
    183                                         rc = addEntry(pszSrc, &pszDst[cchDstBase], fFlags);
     186                                        rc = appendEntry(pszSrc, &pszDst[cchDstBase], fFlags);
    184187                                        RTStrFree(pszDst);
    185188                                    }
     
    210213                                            {
    211214                                                LogFlowFunc(("Directory entry is symlink to file\n"));
    212                                                 rc = addEntry(pszSrc, &pcszDstPath[cchDstBase], fFlags);
     215                                                rc = appendEntry(pszSrc, &pcszDstPath[cchDstBase], fFlags);
    213216                                            }
    214217                                            else
     
    237240        else if (RTFS_IS_FILE(objInfo.Attr.fMode))
    238241        {
    239             rc = addEntry(pcszSrcPath, &pcszDstPath[cchDstBase], fFlags);
     242            rc = appendEntry(pcszSrcPath, &pcszDstPath[cchDstBase], fFlags);
    240243        }
    241244        else if (RTFS_IS_SYMLINK(objInfo.Attr.fMode))
     
    257260                        {
    258261                            LogFlowFunc(("Symlink to file\n"));
    259                             rc = addEntry(pszSrc, &pcszDstPath[cchDstBase], fFlags);
     262                            rc = appendEntry(pszSrc, &pcszDstPath[cchDstBase], fFlags);
    260263                        }
    261264                        else
     
    277280}
    278281
     282int SharedClipboardURIList::appendObject(SharedClipboardURIObject *pObject)
     283{
     284    int rc;
     285
     286    try
     287    {
     288        m_lstTree.append(pObject);
     289        m_lstRoot.append(pObject->GetSourcePathAbs());;
     290
     291        m_cTotal++;
     292        m_cbTotal += pObject->GetSize();
     293
     294        rc = VINF_SUCCESS;
     295    }
     296    catch (std::bad_alloc &)
     297    {
     298        rc = VERR_NO_MEMORY;
     299    }
     300
     301    LogFlowFuncLeaveRC(rc);
     302    return rc;
     303}
     304
    279305int SharedClipboardURIList::AppendNativePath(const char *pszPath, SHAREDCLIPBOARDURILISTFLAGS fFlags)
    280306{
     
    331357    LogFlowFuncLeaveRC(rc);
    332358    return rc;
     359}
     360
     361int SharedClipboardURIList::AppendURIObject(SharedClipboardURIObject *pObject)
     362{
     363    AssertPtrReturn(pObject, VERR_INVALID_POINTER);
     364
     365    return appendObject(pObject);
    333366}
    334367
     
    386419                                  : pszFileName - pszSrcPath;
    387420                char *pszDstPath = &pszSrcPath[cchDstBase];
    388                 m_lstRoot.append(pszDstPath);
    389 
    390                 LogFlowFunc(("pszSrcPath=%s, pszFileName=%s, pszRoot=%s\n",
    391                              pszSrcPath, pszFileName, pszDstPath));
    392 
    393                 rc = appendPathRecursive(pszSrcPath, pszSrcPath, pszSrcPath, cchDstBase, fFlags);
     421
     422                try
     423                {
     424                    m_lstRoot.append(pszDstPath);
     425
     426                    LogFlowFunc(("pszSrcPath=%s, pszFileName=%s, pszRoot=%s\n", pszSrcPath, pszFileName, pszDstPath));
     427                    rc = appendPathRecursive(pszSrcPath, pszSrcPath, pszSrcPath, cchDstBase, fFlags);
     428                }
     429                catch (std::bad_alloc &)
     430                {
     431                    rc = VERR_NO_MEMORY;
     432                }
    394433            }
    395434            else
     
    437476void SharedClipboardURIList::Clear(void)
    438477{
     478    LogFlowThisFuncEnter();
     479
    439480    m_lstRoot.clear();
    440481
     
    443484        SharedClipboardURIObject *pCurObj = m_lstTree.at(i);
    444485        AssertPtr(pCurObj);
    445         RTMemFree(pCurObj);
    446     }
     486        delete pCurObj;
     487    }
     488
    447489    m_lstTree.clear();
    448490
    449491    m_cTotal  = 0;
    450492    m_cbTotal = 0;
     493
     494    LogFlowThisFuncLeave();
    451495}
    452496
     
    464508
    465509    pCurObj->Close();
    466     RTMemFree(pCurObj);
     510    delete pCurObj;
    467511
    468512    m_lstTree.removeFirst();
     
    499543            if (RT_SUCCESS(rc))
    500544            {
    501                 m_lstRoot.append(pszFilePath);
    502                 m_cTotal++;
     545                try
     546                {
     547                    m_lstRoot.append(pszFilePath);
     548                    m_cTotal++;
     549                }
     550                catch (std::bad_alloc &)
     551                {
     552                    rc = VERR_NO_MEMORY;
     553                }
    503554            }
    504555
  • trunk/src/VBox/GuestHost/SharedClipboard/ClipboardURIObject.cpp

    r78390 r78809  
    8686        case Type_File:
    8787        {
    88             RTFileClose(u.File.hFile);
    89             u.File.hFile = NIL_RTFILE;
     88            if (RTFileIsValid(u.File.hFile))
     89            {
     90                RTFileClose(u.File.hFile);
     91                u.File.hFile = NIL_RTFILE;
     92            }
    9093            RT_ZERO(u.File.objInfo);
    9194            break;
     
    9497        case Type_Directory:
    9598        {
    96             RTDirClose(u.Dir.hDir);
    97             u.Dir.hDir = NIL_RTDIR;
     99            if (RTDirIsValid(u.Dir.hDir))
     100            {
     101                RTDirClose(u.Dir.hDir);
     102                u.Dir.hDir = NIL_RTDIR;
     103            }
    98104            RT_ZERO(u.Dir.objInfo);
    99105            break;
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-win.cpp

    r78581 r78809  
    743743    return rc;
    744744}
     745
     746/**
     747 * Initializes a Windows-specific URI clipboard information struct.
     748 *
     749 * @returns VBox status code.
     750 * @param   pURI                URI clipboard information struct to initialize.
     751 * @param   enmType             What type of clipboard provider to use.
     752 */
     753int VBoxClipboardWinURIInit(PVBOXCLIPBOARDWINURI pURI, SharedClipboardProvider::SourceType enmType)
     754{
     755    LogFlowFuncEnter();
     756
     757    pURI->Transfer.pProvider = SharedClipboardProvider::Create(enmType);
     758    if (!pURI->Transfer.pProvider)
     759        return VERR_NO_MEMORY;
     760
     761    VBoxClipboardWinURIReset(pURI);
     762
     763    return VINF_SUCCESS;
     764}
     765
     766/**
     767 * Destroys a Windows-specific URI clipboard information struct.
     768 *
     769 * @param   pURI                URI clipboard information struct to destroy.
     770 */
     771void VBoxClipboardWinURIDestroy(PVBOXCLIPBOARDWINURI pURI)
     772{
     773    LogFlowFuncEnter();
     774
     775    if (pURI->Transfer.pProvider)
     776    {
     777        delete pURI->Transfer.pProvider;
     778        pURI->Transfer.pProvider = NULL;
     779    }
     780}
     781
     782/**
     783 * Resets a Windows-specific URI clipboard information struct.
     784 *
     785 * @param   pURI                URI clipboard information struct to reset.
     786 */
     787void VBoxClipboardWinURIReset(PVBOXCLIPBOARDWINURI pURI)
     788{
     789    LogFlowFuncEnter();
     790
     791    pURI->cTransfers = 0;
     792
     793    if (pURI->Transfer.pProvider)
     794        pURI->Transfer.pProvider->Reset();
     795}
    745796#endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */
    746797
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