Changeset 55640 in vbox for trunk/src/VBox/GuestHost/DragAndDrop
- Timestamp:
- May 4, 2015 12:38:57 PM (10 years ago)
- Location:
- trunk/src/VBox/GuestHost/DragAndDrop
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/DragAndDrop/DnDDir.cpp
r50460 r55640 5 5 6 6 /* 7 * Copyright (C) 2014 Oracle Corporation7 * Copyright (C) 2014-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 27 27 #include <VBox/GuestHost/DragAndDrop.h> 28 28 29 int DnDDirCreateDroppedFilesEx(const char *pszPath, 30 char *pszDropDir, size_t cbDropDir) 29 int DnDDirDroppedAddFile(PDNDDIRDROPPEDFILES pDir, const char *pszFile) 30 { 31 AssertPtrReturn(pDir, VERR_INVALID_POINTER); 32 AssertPtrReturn(pszFile, VERR_INVALID_POINTER); 33 34 if (!pDir->lstFiles.contains(pszFile)) 35 pDir->lstFiles.append(pszFile); 36 return VINF_SUCCESS; 37 } 38 39 int DnDDirDroppedAddDir(PDNDDIRDROPPEDFILES pDir, const char *pszDir) 40 { 41 AssertPtrReturn(pDir, VERR_INVALID_POINTER); 42 AssertPtrReturn(pszDir, VERR_INVALID_POINTER); 43 44 if (!pDir->lstDirs.contains(pszDir)) 45 pDir->lstDirs.append(pszDir); 46 return VINF_SUCCESS; 47 } 48 49 int DnDDirDroppedFilesCreateAndOpenEx(const char *pszPath, PDNDDIRDROPPEDFILES pDir) 31 50 { 32 51 AssertPtrReturn(pszPath, VERR_INVALID_POINTER); 33 AssertPtrReturn(pszDropDir, VERR_INVALID_POINTER); 34 AssertReturn(cbDropDir, VERR_INVALID_PARAMETER); 52 AssertPtrReturn(pDir, VERR_INVALID_POINTER); 35 53 36 if (RTStrPrintf(pszDropDir, cbDropDir, "%s", pszPath) <= 0) 54 char pszDropDir[RTPATH_MAX]; 55 if (RTStrPrintf(pszDropDir, sizeof(pszDropDir), "%s", pszPath) <= 0) 37 56 return VERR_NO_MEMORY; 38 57 … … 42 61 43 62 /* Append our base drop directory. */ 44 int rc = RTPathAppend(pszDropDir, cbDropDir, "VirtualBox Dropped Files");63 int rc = RTPathAppend(pszDropDir, sizeof(pszDropDir), "VirtualBox Dropped Files"); /** @todo Make this tag configurable? */ 45 64 if (RT_FAILURE(rc)) 46 65 return rc; … … 64 83 return rc; 65 84 66 rc = RTPathAppend(pszDropDir, cbDropDir, pszTime);85 rc = RTPathAppend(pszDropDir, sizeof(pszDropDir), pszTime); 67 86 if (RT_FAILURE(rc)) 68 87 return rc; 69 88 70 89 /* Create it (only accessible by the current user) */ 71 return RTDirCreateUniqueNumbered(pszDropDir, cbDropDir, RTFS_UNIX_IRWXU, 3, '-'); 90 rc = RTDirCreateUniqueNumbered(pszDropDir, sizeof(pszDropDir), RTFS_UNIX_IRWXU, 3, '-'); 91 if (RT_SUCCESS(rc)) 92 { 93 PRTDIR phDir; 94 rc = RTDirOpen(&phDir, pszDropDir); 95 if (RT_SUCCESS(rc)) 96 { 97 pDir->hDir = phDir; 98 pDir->strPathAbs = pszDropDir; 99 } 100 } 101 102 return rc; 72 103 } 73 104 74 int DnDDir CreateDroppedFiles(char *pszDropDir, size_t cbDropDir)105 int DnDDirDroppedFilesCreateAndOpenTemp(PDNDDIRDROPPEDFILES pDir) 75 106 { 76 AssertPtrReturn(pszDropDir, VERR_INVALID_POINTER); 77 AssertReturn(cbDropDir, VERR_INVALID_PARAMETER); 107 AssertPtrReturn(pDir, VERR_INVALID_POINTER); 78 108 79 109 char szTemp[RTPATH_MAX]; 80 110 81 /* Get the user's temp directory. Don't use the user's root directory (or 111 /* 112 * Get the user's temp directory. Don't use the user's root directory (or 82 113 * something inside it) because we don't know for how long/if the data will 83 * be kept after the guest OS used it. */ 114 * be kept after the guest OS used it. 115 */ 84 116 int rc = RTPathTemp(szTemp, sizeof(szTemp)); 85 117 if (RT_FAILURE(rc)) 86 118 return rc; 87 119 88 return DnDDir CreateDroppedFilesEx(szTemp, pszDropDir, cbDropDir);120 return DnDDirDroppedFilesCreateAndOpenEx(szTemp, pDir); 89 121 } 90 122 123 int DnDDirDroppedFilesClose(PDNDDIRDROPPEDFILES pDir, bool fRemove) 124 { 125 AssertPtrReturn(pDir, VERR_INVALID_POINTER); 126 127 int rc = RTDirClose(pDir->hDir); 128 if (RT_SUCCESS(rc)) 129 { 130 pDir->lstDirs.clear(); 131 pDir->lstFiles.clear(); 132 133 if (fRemove) 134 { 135 /* Try removing the (empty) drop directory in any case. */ 136 rc = RTDirRemove(pDir->strPathAbs.c_str()); 137 if (RT_SUCCESS(rc)) /* Only clear if successfully removed. */ 138 pDir->strPathAbs = ""; 139 } 140 } 141 142 return rc; 143 } 144 145 const char *DnDDirDroppedFilesGetDirAbs(PDNDDIRDROPPEDFILES pDir) 146 { 147 AssertPtrReturn(pDir, NULL); 148 return pDir->strPathAbs.c_str(); 149 } 150 151 int DnDDirDroppedFilesRollback(PDNDDIRDROPPEDFILES pDir) 152 { 153 AssertPtrReturn(pDir, VERR_INVALID_POINTER); 154 155 if (pDir->strPathAbs.isEmpty()) 156 return VINF_SUCCESS; 157 158 int rc = VINF_SUCCESS; 159 int rc2; 160 161 /* Rollback by removing any stuff created. 162 * Note: Only remove empty directories, never ever delete 163 * anything recursive here! Steam (tm) knows best ... :-) */ 164 for (size_t i = 0; i < pDir->lstFiles.size(); i++) 165 { 166 rc2 = RTFileDelete(pDir->lstFiles.at(i).c_str()); 167 if (RT_SUCCESS(rc)) 168 rc = rc2; 169 } 170 171 for (size_t i = 0; i < pDir->lstDirs.size(); i++) 172 { 173 rc2 = RTDirRemove(pDir->lstDirs.at(i).c_str()); 174 if (RT_SUCCESS(rc)) 175 rc = rc2; 176 } 177 178 /* Try to remove the empty root dropped files directory as well. */ 179 rc2 = RTDirRemove(pDir->strPathAbs.c_str()); 180 if (RT_SUCCESS(rc)) 181 rc = rc2; 182 183 return rc; 184 } 185 -
trunk/src/VBox/GuestHost/DragAndDrop/DnDURIList.cpp
r55556 r55640 336 336 } 337 337 338 int DnDURIList::RootFromURIData(const void *pvData, size_t cbData, 339 uint32_t fFlags) 338 int DnDURIList::RootFromURIData(const void *pvData, size_t cbData, uint32_t fFlags) 340 339 { 341 340 AssertPtrReturn(pvData, VERR_INVALID_POINTER); … … 380 379 } 381 380 382 RTCString DnDURIList::RootToString(const RTCString &str BasePath/* = "" */,381 RTCString DnDURIList::RootToString(const RTCString &strPathBase /* = "" */, 383 382 const RTCString &strSeparator /* = "\r\n" */) 384 383 { … … 390 389 LogFlowFunc(("pszCurRoot=%s\n", pszCurRoot)); 391 390 #endif 392 if (str BasePath.isNotEmpty())393 { 394 char *pszPath = RTPathJoinA(str BasePath.c_str(), pszCurRoot);391 if (strPathBase.isNotEmpty()) 392 { 393 char *pszPath = RTPathJoinA(strPathBase.c_str(), pszCurRoot); 395 394 if (pszPath) 396 395 { … … 399 398 { 400 399 strRet += RTCString(pszPathURI) + strSeparator; 401 #ifdef DEBUG_andy402 400 LogFlowFunc(("URI: %s\n", strRet.c_str())); 403 #endif404 401 RTStrFree(pszPathURI); 405 402 } … … 417 414 { 418 415 strRet += RTCString(pszPathURI) + strSeparator; 419 #ifdef DEBUG_andy420 416 LogFlowFunc(("URI: %s\n", strRet.c_str())); 421 #endif422 417 RTStrFree(pszPathURI); 423 418 } -
trunk/src/VBox/GuestHost/DragAndDrop/DnDURIObject.cpp
r55556 r55640 37 37 DnDURIObject::DnDURIObject(void) 38 38 : m_Type(Unknown) 39 , m_f CreationMode(0)39 , m_fMode(0) 40 40 , m_cbSize(0) 41 41 , m_cbProcessed(0) … … 51 51 , m_strSrcPath(strSrcPath) 52 52 , m_strTgtPath(strDstPath) 53 , m_f CreationMode(fMode)53 , m_fMode(fMode) 54 54 , m_cbSize(cbSize) 55 55 , m_cbProcessed(0) … … 155 155 } 156 156 157 int DnDURIObject::Open(Dest enmDest, uint64_t fOpen )157 int DnDURIObject::Open(Dest enmDest, uint64_t fOpen /* = 0 */, uint32_t fMode /* = 0 */) 158 158 { 159 159 return OpenEx( enmDest == Source 160 160 ? m_strSrcPath : m_strTgtPath 161 , m_Type, enmDest, fOpen, 0 /* fFlag s*/);161 , m_Type, enmDest, fOpen, fMode, 0 /* fFlags */); 162 162 } 163 163 164 164 int DnDURIObject::OpenEx(const RTCString &strPath, Type enmType, Dest enmDest, 165 uint64_t fOpen /* = 0 */, uint32_t f Flags /* = 0 */)165 uint64_t fOpen /* = 0 */, uint32_t fMode /* = 0 */, uint32_t fFlags /* = 0 */) 166 166 { 167 167 int rc = VINF_SUCCESS; … … 198 198 if (RT_SUCCESS(rc)) 199 199 rc = RTFileGetSize(u.m_hFile, &m_cbSize); 200 if (RT_SUCCESS(rc) 201 && fMode) 202 { 203 rc = RTFileSetMode(u.m_hFile, fMode); 204 } 200 205 if (RT_SUCCESS(rc)) 201 206 { 202 LogFlowFunc(("cbSize=%RU64, fMode=%RU32\n", m_cbSize, m_f CreationMode));207 LogFlowFunc(("cbSize=%RU64, fMode=%RU32\n", m_cbSize, m_fMode)); 203 208 m_cbProcessed = 0; 204 209 } … … 293 298 case File: 294 299 { 295 bool fDone = false;296 297 300 rc = OpenEx(m_strSrcPath, File, Source, 298 301 /* Use some sensible defaults. */ … … 307 310 308 311 /* End of file reached or error occurred? */ 309 if (m_cbProcessed == m_cbSize) 312 if ( m_cbSize 313 && m_cbProcessed == m_cbSize) 310 314 { 311 315 rc = VINF_EOF; 312 fDone = true;313 316 } 314 317 } 315 else316 fDone = true;317 318 if (fDone)319 closeInternal();320 318 } 321 319 … … 351 349 m_strSrcPath = ""; 352 350 m_strTgtPath = ""; 353 m_f CreationMode = 0;351 m_fMode = 0; 354 352 m_cbSize = 0; 355 353 m_cbProcessed = 0; … … 369 367 case File: 370 368 { 371 bool fDone = false;372 373 369 rc = OpenEx(m_strTgtPath, File, Target, 374 370 /* Use some sensible defaults. */ … … 379 375 if (RT_SUCCESS(rc)) 380 376 m_cbProcessed += cbWritten; 381 else382 fDone = true;383 384 if (fDone)385 closeInternal();386 377 } 387 378
Note:
See TracChangeset
for help on using the changeset viewer.