VirtualBox

Ignore:
Timestamp:
Oct 13, 2015 11:49:33 AM (9 years ago)
Author:
vboxsync
Message:

DnD: Updates.

  • Introduced protocol changelog in DragAndDropSvc.h.
  • Implemented protocol v3 with HOST_DND_HG_SND_DATA_HDR message for doing proper object accounting, among other parameters like checksumming and compression flags.
  • Encapsulated a lot of functionality in class hierarchies.
  • Renamed a lot of functions to make the usage more clear.
  • Various other bugfixes.
File:
1 edited

Legend:

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

    r57776 r58212  
    2828#include <VBox/GuestHost/DragAndDrop.h>
    2929
     30#ifdef LOG_GROUP
     31 #undef LOG_GROUP
     32#endif
     33#define LOG_GROUP LOG_GROUP_GUEST_DND
     34#include <VBox/log.h>
     35
    3036DnDDroppedFiles::DnDDroppedFiles(void)
    3137    : hDir(NULL)
    32     , fOpen(false) { }
    33 
    34 DnDDroppedFiles::DnDDroppedFiles(const char *pszPath, uint32_t fFlags)
     38    , fOpen(0) { }
     39
     40DnDDroppedFiles::DnDDroppedFiles(const char *pszPath, uint32_t fOpen)
    3541    : hDir(NULL)
    36     , fOpen(false)
    37 {
    38     OpenEx(pszPath, fFlags);
     42    , fOpen(0)
     43{
     44    OpenEx(pszPath, fOpen);
    3945}
    4046
    4147DnDDroppedFiles::~DnDDroppedFiles(void)
    4248{
    43     Reset(true /* fRemoveDropDir */);
     49    /* Only make sure to not leak any handles and stuff, don't delete any
     50     * directories / files here. */
     51    closeInternal();
    4452}
    4553
     
    6270}
    6371
     72int DnDDroppedFiles::closeInternal(void)
     73{
     74    int rc;
     75    if (this->hDir != NULL)
     76    {
     77        rc = RTDirClose(this->hDir);
     78        if (RT_SUCCESS(rc))
     79            this->hDir = NULL;
     80    }
     81    else
     82        rc = VINF_SUCCESS;
     83
     84    LogFlowFuncLeaveRC(rc);
     85    return rc;
     86}
     87
     88int DnDDroppedFiles::Close(void)
     89{
     90    return closeInternal();
     91}
     92
    6493const char *DnDDroppedFiles::GetDirAbs(void) const
    6594{
     
    6998bool DnDDroppedFiles::IsOpen(void) const
    7099{
    71     return this->fOpen;
     100    return (this->hDir != NULL);
    72101}
    73102
     
    129158                this->hDir       = phDir;
    130159                this->strPathAbs = pszDropDir;
    131                 this->fOpen      = true;
     160                this->fOpen      = fFlags;
    132161            }
    133162        }
     
    135164    } while (0);
    136165
     166    LogFlowFuncLeaveRC(rc);
    137167    return rc;
    138168}
     
    157187int DnDDroppedFiles::Reset(bool fRemoveDropDir)
    158188{
    159     int rc = VINF_SUCCESS;
    160     if (this->fOpen)
    161     {
    162         rc = RTDirClose(this->hDir);
    163         if (RT_SUCCESS(rc))
    164         {
    165             this->fOpen = false;
    166             this->hDir  = NULL;
    167         }
    168     }
    169     if (RT_SUCCESS(rc))
    170     {
    171         this->lstDirs.clear();
    172         this->lstFiles.clear();
    173 
    174         if (   fRemoveDropDir
    175             && this->strPathAbs.isNotEmpty())
    176         {
    177             /* Try removing the (empty) drop directory in any case. */
    178             rc = RTDirRemove(this->strPathAbs.c_str());
    179             if (RT_SUCCESS(rc)) /* Only clear if successfully removed. */
    180                 this->strPathAbs = "";
    181         }
    182     }
    183 
    184     return rc;
     189    int rc = closeInternal();
     190    if (RT_SUCCESS(rc))
     191    {
     192        if (fRemoveDropDir)
     193        {
     194            rc = Rollback();
     195        }
     196        else
     197        {
     198            this->lstDirs.clear();
     199            this->lstFiles.clear();
     200        }
     201    }
     202
     203    LogFlowFuncLeaveRC(rc);
     204    return rc;
     205}
     206
     207int DnDDroppedFiles::Reopen(void)
     208{
     209    if (this->strPathAbs.isEmpty())
     210        return VERR_NOT_FOUND;
     211
     212    return OpenEx(this->strPathAbs.c_str(), this->fOpen);
    185213}
    186214
     
    190218        return VINF_SUCCESS;
    191219
    192     Assert(this->fOpen);
    193     Assert(this->hDir != NULL);
    194 
    195220    int rc = VINF_SUCCESS;
    196     int rc2;
    197221
    198222    /* Rollback by removing any stuff created.
    199223     * Note: Only remove empty directories, never ever delete
    200224     *       anything recursive here! Steam (tm) knows best ... :-) */
     225    int rc2;
    201226    for (size_t i = 0; i < this->lstFiles.size(); i++)
    202227    {
    203228        rc2 = RTFileDelete(this->lstFiles.at(i).c_str());
     229        if (RT_SUCCESS(rc2))
     230            this->lstFiles.removeAt(i);
     231
     232        if (RT_SUCCESS(rc))
     233           rc = rc2;
     234        /* Keep going. */
     235    }
     236
     237    for (size_t i = 0; i < this->lstDirs.size(); i++)
     238    {
     239        rc2 = RTDirRemove(this->lstDirs.at(i).c_str());
     240        if (RT_SUCCESS(rc2))
     241            this->lstDirs.removeAt(i);
     242
    204243        if (RT_SUCCESS(rc))
    205244            rc = rc2;
    206     }
    207 
    208     for (size_t i = 0; i < this->lstDirs.size(); i++)
    209     {
    210         rc2 = RTDirRemove(this->lstDirs.at(i).c_str());
    211         if (RT_SUCCESS(rc))
    212             rc = rc2;
    213     }
    214 
    215     /* Try to remove the empty root dropped files directory as well. */
    216     rc2 = RTDirRemove(this->strPathAbs.c_str());
     245        /* Keep going. */
     246    }
     247
     248    if (RT_SUCCESS(rc))
     249    {
     250        Assert(this->lstFiles.isEmpty());
     251        Assert(this->lstDirs.isEmpty());
     252
     253        rc2 = closeInternal();
     254        if (RT_SUCCESS(rc2))
     255        {
     256            /* Try to remove the empty root dropped files directory as well.
     257             * Might return VERR_DIR_NOT_EMPTY or similar. */
     258            rc2 = RTDirRemove(this->strPathAbs.c_str());
     259        }
     260    }
     261
    217262    if (RT_SUCCESS(rc))
    218263        rc = rc2;
    219264
    220     return rc;
    221 }
    222 
     265    LogFlowFuncLeaveRC(rc);
     266    return rc;
     267}
     268
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