VirtualBox

Ignore:
Timestamp:
Jul 23, 2020 1:38:14 PM (5 years ago)
Author:
vboxsync
Message:

DnD: Added DnDTransferListAppendRootsFromArray() + DnDTransferListAppendRootsFromBuffer().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/DragAndDrop/DnDTransferList.cpp

    r85429 r85435  
    760760
    761761/**
     762 * Appends the root entries for a transfer list.
     763 *
     764 * @returns VBox status code.
     765 * @param   pList               Transfer list to append to.
     766 * @param   enmFmt              Format of \a pszPaths to append.
     767 * @param   pszPaths            Buffer of paths to append.
     768 * @param   cbPaths             Size (in bytes) of buffer of paths to append.
     769 * @param   pcszSeparator       Separator string to use.
     770 * @param   fFlags              Transfer list flags to use for appending.
     771 */
     772int DnDTransferListAppendRootsFromBuffer(PDNDTRANSFERLIST pList,
     773                                         DNDTRANSFERLISTFMT enmFmt, const char *pszPaths, size_t cbPaths,
     774                                         const char *pcszSeparator, DNDTRANSFERLISTFLAGS fFlags)
     775{
     776    AssertPtrReturn(pList, VERR_INVALID_POINTER);
     777    AssertPtrReturn(pszPaths, VERR_INVALID_POINTER);
     778    AssertReturn(cbPaths, VERR_INVALID_PARAMETER);
     779
     780    char **papszPaths = NULL;
     781    size_t cPaths = 0;
     782    int rc = RTStrSplit(pszPaths, cbPaths, pcszSeparator, &papszPaths, &cPaths);
     783    if (RT_SUCCESS(rc))
     784        rc = DnDTransferListAppendRootsFromArray(pList, enmFmt, papszPaths, cPaths, fFlags);
     785
     786    for (size_t i = 0; i < cPaths; ++i)
     787        RTStrFree(papszPaths[i]);
     788    RTMemFree(papszPaths);
     789
     790    return rc;
     791}
     792
     793/**
     794 * Appends root entries to a transfer list.
     795 *
     796 * @returns VBox status code.
     797 * @param   pList               Transfer list to append root entries to.
     798 * @param   enmFmt              Format of \a papcszPaths to append.
     799 * @param   papcszPaths         Array of paths to append.
     800 * @param   cPaths              Number of paths in \a papcszPaths to append.
     801 * @param   fFlags              Transfer list flags to use for appending.
     802 */
     803int DnDTransferListAppendRootsFromArray(PDNDTRANSFERLIST pList,
     804                                        DNDTRANSFERLISTFMT enmFmt,
     805                                        const char * const *papcszPaths, size_t cPaths, DNDTRANSFERLISTFLAGS fFlags)
     806{
     807    AssertPtrReturn(pList, VERR_INVALID_POINTER);
     808    AssertPtrReturn(papcszPaths, VERR_INVALID_POINTER);
     809    AssertReturn(!(fFlags & ~DNDTRANSFERLIST_FLAGS_VALID_MASK), VERR_INVALID_FLAGS);
     810
     811    AssertMsgReturn(pList->pszPathRootAbs, ("Root path not set yet\n"), VERR_WRONG_ORDER);
     812
     813    int rc = VINF_SUCCESS;
     814
     815    if (!cPaths) /* Nothing to add? Bail out. */
     816        return VINF_SUCCESS;
     817
     818    char **papszPathsTmp = NULL;
     819
     820    /* If URI data is being handed in, extract the paths first. */
     821    if (enmFmt == DNDTRANSFERLISTFMT_URI)
     822    {
     823        papszPathsTmp = (char **)RTMemAlloc(sizeof(char *) * cPaths);
     824        if (papszPathsTmp)
     825        {
     826            for (size_t i = 0; i < cPaths; i++)
     827                papszPathsTmp[i] = RTUriFilePath(papcszPaths[i]);
     828        }
     829        else
     830            rc = VERR_NO_MEMORY;
     831    }
     832
     833    if (RT_FAILURE(rc))
     834        return rc;
     835
     836    char szPath[RTPATH_MAX];
     837
     838    /*
     839     * Add all root entries to the root list.
     840     */
     841    for (size_t i = 0; i < cPaths; i++)
     842    {
     843        const char *pcszPath = enmFmt == DNDTRANSFERLISTFMT_NATIVE
     844                             ? papcszPaths[i] : papszPathsTmp[i];
     845
     846        rc = RTPathJoin(szPath, sizeof(szPath), pList->pszPathRootAbs, pcszPath);
     847        AssertRCBreak(rc);
     848
     849        rc = DnDPathConvert(szPath, sizeof(szPath), DNDPATHCONVERT_FLAGS_TRANSPORT);
     850        AssertRCBreak(rc);
     851
     852        rc = dndTransferListRootAdd(pList, szPath);
     853        if (RT_FAILURE(rc))
     854        {
     855            LogRel(("DnD: Adding root entry '%s' (format %#x, root '%s') to transfer list failed with %Rrc\n",
     856                    szPath, enmFmt, pList->pszPathRootAbs, rc));
     857            break;
     858        }
     859    }
     860
     861    if (papszPathsTmp)
     862    {
     863        for (size_t i = 0; i < cPaths; i++)
     864            RTStrFree(papszPathsTmp[i]);
     865        RTMemFree(papszPathsTmp);
     866    }
     867
     868    LogFlowFuncLeaveRC(rc);
     869    return rc;
     870}
     871
     872/**
    762873 * Returns the first transfer object in a list.
    763874 *
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