- Timestamp:
- Sep 8, 2015 1:16:17 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/GuestHost/DragAndDrop.h
r57500 r57654 61 61 int DnDDirDroppedAddFile(PDNDDIRDROPPEDFILES pDir, const char *pszFile); 62 62 int DnDDirDroppedAddDir(PDNDDIRDROPPEDFILES pDir, const char *pszDir); 63 int DnDDirDroppedFilesCreateAndOpenEx(const char *pszPath, PDNDDIRDROPPEDFILESpDir);64 int DnDDirDroppedFilesCreateAndOpenTemp( PDNDDIRDROPPEDFILESpDir);63 int DnDDirDroppedFilesCreateAndOpenEx(const char *pszPath, uint32_t fFlags, PDNDDIRDROPPEDFILES *ppDir); 64 int DnDDirDroppedFilesCreateAndOpenTemp(uint32_t fFlags, PDNDDIRDROPPEDFILES *ppDir); 65 65 int DnDDirDroppedFilesClose(PDNDDIRDROPPEDFILES pDir, bool fRemove); 66 void DnDDirDroppedFilesDestroy(PDNDDIRDROPPEDFILES pDir); 66 67 const char *DnDDirDroppedFilesGetDirAbs(PDNDDIRDROPPEDFILES pDir); 67 68 int DnDDirDroppedFilesRollback(PDNDDIRDROPPEDFILES pDir); -
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibDragAndDrop.cpp
r57500 r57654 373 373 * Create and query the (unique) drop target directory in the user's temporary directory. 374 374 */ 375 DNDDIRDROPPEDFILES dirDroppedFiles;375 PDNDDIRDROPPEDFILES pDroppedFiles; 376 376 const char *pszDropDir = NULL; 377 int rc = DnDDirDroppedFilesCreateAndOpenTemp( &dirDroppedFiles);378 if (RT_SUCCESS(rc)) 379 pszDropDir = DnDDirDroppedFilesGetDirAbs( &dirDroppedFiles);377 int rc = DnDDirDroppedFilesCreateAndOpenTemp(0 /* fFlags */, &pDroppedFiles); 378 if (RT_SUCCESS(rc)) 379 pszDropDir = DnDDirDroppedFilesGetDirAbs(pDroppedFiles); 380 380 381 381 /* … … 421 421 rc = RTDirCreate(pszPathAbs, fCreationMode, 0); 422 422 if (RT_SUCCESS(rc)) 423 rc = DnDDirDroppedAddDir( &dirDroppedFiles, pszPathAbs);423 rc = DnDDirDroppedAddDir(pDroppedFiles, pszPathAbs); 424 424 425 425 RTStrFree(pszPathAbs); … … 488 488 if (RT_SUCCESS(rc)) 489 489 { 490 rc = DnDDirDroppedAddFile( &dirDroppedFiles, strPathAbs.c_str());490 rc = DnDDirDroppedAddFile(pDroppedFiles, strPathAbs.c_str()); 491 491 if (RT_SUCCESS(rc)) 492 492 { … … 571 571 if (RT_FAILURE(rc)) 572 572 { 573 int rc2 = DnDDirDroppedFilesRollback( &dirDroppedFiles);573 int rc2 = DnDDirDroppedFilesRollback(pDroppedFiles); 574 574 AssertRC(rc2); /* Not fatal, don't report back to host. */ 575 575 } … … 620 620 * by the client's drag'n drop operation lateron. 621 621 */ 622 int rc2 = DnDDirDroppedFilesClose( &dirDroppedFiles, false);622 int rc2 = DnDDirDroppedFilesClose(pDroppedFiles, false); 623 623 if (RT_FAILURE(rc2)) /* Not fatal, don't report back to host. */ 624 624 LogFlowFunc(("Closing dropped files directory failed with %Rrc\n", rc2)); 625 626 DnDDirDroppedFilesDestroy(pDroppedFiles); 625 627 626 628 LogFlowFuncLeaveRC(rc); -
trunk/src/VBox/GuestHost/DragAndDrop/DnDDir.cpp
r57372 r57654 48 48 } 49 49 50 int DnDDirDroppedFilesCreateAndOpenEx(const char *pszPath, PDNDDIRDROPPEDFILES pDir) 50 static int dndDirDroppedFilesCreate(uint32_t fFlags, PDNDDIRDROPPEDFILES *ppDir) 51 { 52 AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER); /* Flags not supported yet. */ 53 AssertPtrReturn(ppDir, VERR_INVALID_POINTER); 54 55 PDNDDIRDROPPEDFILES pDir = (PDNDDIRDROPPEDFILES)RTMemAlloc(sizeof(DNDDIRDROPPEDFILES)); 56 if (pDir) 57 { 58 pDir->hDir = NULL; 59 pDir->fOpen = false; 60 61 *ppDir = pDir; 62 return VINF_SUCCESS; 63 } 64 65 return VERR_NO_MEMORY; 66 } 67 68 int DnDDirDroppedFilesCreateAndOpenEx(const char *pszPath, uint32_t fFlags, PDNDDIRDROPPEDFILES *ppDir) 51 69 { 52 70 AssertPtrReturn(pszPath, VERR_INVALID_POINTER); 53 AssertPtrReturn(pDir, VERR_INVALID_POINTER); 54 55 char pszDropDir[RTPATH_MAX]; 56 if (RTStrPrintf(pszDropDir, sizeof(pszDropDir), "%s", pszPath) <= 0) 57 return VERR_NO_MEMORY; 58 59 /** @todo On Windows we also could use the registry to override 60 * this path, on Posix a dotfile and/or a guest property 61 * can be used. */ 62 63 /* Append our base drop directory. */ 64 int rc = RTPathAppend(pszDropDir, sizeof(pszDropDir), "VirtualBox Dropped Files"); /** @todo Make this tag configurable? */ 71 AssertPtrReturn(ppDir, VERR_INVALID_POINTER); 72 73 PDNDDIRDROPPEDFILES pDir; 74 int rc = dndDirDroppedFilesCreate(fFlags, &pDir); 65 75 if (RT_FAILURE(rc)) 66 76 return rc; 67 77 68 /* Create it when necessary. */ 69 if (!RTDirExists(pszDropDir)) 70 { 71 rc = RTDirCreateFullPath(pszDropDir, RTFS_UNIX_IRWXU); 78 do 79 { 80 char pszDropDir[RTPATH_MAX]; 81 if (RTStrPrintf(pszDropDir, sizeof(pszDropDir), "%s", pszPath) <= 0) 82 { 83 rc = VERR_NO_MEMORY; 84 break; 85 } 86 87 /** @todo On Windows we also could use the registry to override 88 * this path, on Posix a dotfile and/or a guest property 89 * can be used. */ 90 91 /* Append our base drop directory. */ 92 int rc = RTPathAppend(pszDropDir, sizeof(pszDropDir), "VirtualBox Dropped Files"); /** @todo Make this tag configurable? */ 72 93 if (RT_FAILURE(rc)) 73 return rc; 74 } 75 76 /* The actually drop directory consist of the current time stamp and a 77 * unique number when necessary. */ 78 char pszTime[64]; 79 RTTIMESPEC time; 80 if (!RTTimeSpecToString(RTTimeNow(&time), pszTime, sizeof(pszTime))) 81 return VERR_BUFFER_OVERFLOW; 82 rc = DnDPathSanitizeFilename(pszTime, sizeof(pszTime)); 83 if (RT_FAILURE(rc)) 84 return rc; 85 86 rc = RTPathAppend(pszDropDir, sizeof(pszDropDir), pszTime); 87 if (RT_FAILURE(rc)) 88 return rc; 89 90 /* Create it (only accessible by the current user) */ 91 rc = RTDirCreateUniqueNumbered(pszDropDir, sizeof(pszDropDir), RTFS_UNIX_IRWXU, 3, '-'); 92 if (RT_SUCCESS(rc)) 93 { 94 PRTDIR phDir; 95 rc = RTDirOpen(&phDir, pszDropDir); 96 if (RT_SUCCESS(rc)) 97 { 98 pDir->hDir = phDir; 99 pDir->strPathAbs = pszDropDir; 100 pDir->fOpen = true; 101 } 102 } 103 104 return rc; 105 } 106 107 int DnDDirDroppedFilesCreateAndOpenTemp(PDNDDIRDROPPEDFILES pDir) 108 { 109 AssertPtrReturn(pDir, VERR_INVALID_POINTER); 110 111 char szTemp[RTPATH_MAX]; 94 break; 95 96 /* Create it when necessary. */ 97 if (!RTDirExists(pszDropDir)) 98 { 99 rc = RTDirCreateFullPath(pszDropDir, RTFS_UNIX_IRWXU); 100 if (RT_FAILURE(rc)) 101 break; 102 } 103 104 /* The actually drop directory consist of the current time stamp and a 105 * unique number when necessary. */ 106 char pszTime[64]; 107 RTTIMESPEC time; 108 if (!RTTimeSpecToString(RTTimeNow(&time), pszTime, sizeof(pszTime))) 109 { 110 rc = VERR_BUFFER_OVERFLOW; 111 break; 112 } 113 114 rc = DnDPathSanitizeFilename(pszTime, sizeof(pszTime)); 115 if (RT_FAILURE(rc)) 116 break; 117 118 rc = RTPathAppend(pszDropDir, sizeof(pszDropDir), pszTime); 119 if (RT_FAILURE(rc)) 120 break; 121 122 /* Create it (only accessible by the current user) */ 123 rc = RTDirCreateUniqueNumbered(pszDropDir, sizeof(pszDropDir), RTFS_UNIX_IRWXU, 3, '-'); 124 if (RT_SUCCESS(rc)) 125 { 126 PRTDIR phDir; 127 rc = RTDirOpen(&phDir, pszDropDir); 128 if (RT_SUCCESS(rc)) 129 { 130 pDir->hDir = phDir; 131 pDir->strPathAbs = pszDropDir; 132 pDir->fOpen = true; 133 } 134 } 135 136 } while (0); 137 138 if (RT_SUCCESS(rc)) 139 { 140 *ppDir = pDir; 141 } 142 else 143 DnDDirDroppedFilesDestroy(pDir); 144 145 return rc; 146 } 147 148 int DnDDirDroppedFilesCreateAndOpenTemp(uint32_t fFlags, PDNDDIRDROPPEDFILES *ppDir) 149 { 150 AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER); /* Flags not supported yet. */ 151 AssertPtrReturn(ppDir, VERR_INVALID_POINTER); 152 153 PDNDDIRDROPPEDFILES pDir; 112 154 113 155 /* … … 116 158 * be kept after the guest OS used it. 117 159 */ 160 char szTemp[RTPATH_MAX]; 118 161 int rc = RTPathTemp(szTemp, sizeof(szTemp)); 119 if (RT_FAILURE(rc)) 120 return rc; 121 122 return DnDDirDroppedFilesCreateAndOpenEx(szTemp, pDir); 162 if (RT_SUCCESS(rc)) 163 rc = DnDDirDroppedFilesCreateAndOpenEx(szTemp, fFlags, &pDir); 164 165 if (RT_SUCCESS(rc)) 166 { 167 *ppDir = pDir; 168 } 169 else 170 DnDDirDroppedFilesDestroy(pDir); 171 172 return rc; 173 } 174 175 void DnDDirDroppedFilesDestroy(PDNDDIRDROPPEDFILES pDir) 176 { 177 AssertPtrReturnVoid(pDir); 178 179 RTMemFree(pDir); 123 180 } 124 181 … … 132 189 rc = RTDirClose(pDir->hDir); 133 190 if (RT_SUCCESS(rc)) 191 { 134 192 pDir->fOpen = false; 193 pDir->hDir = NULL; 194 } 135 195 } 136 196 if (RT_SUCCESS(rc)) -
trunk/src/VBox/Main/include/GuestDnDPrivate.h
r57505 r57654 138 138 { 139 139 GuestDnDURIData(void) 140 : pvScratchBuf(NULL) 141 , cbScratchBuf(0) 142 { 143 RT_ZERO(mDropDir); 144 } 140 : pDropDir(NULL) 141 , pvScratchBuf(NULL) 142 , cbScratchBuf(0) { } 145 143 146 144 virtual ~GuestDnDURIData(void) … … 170 168 objCtx.Reset(); 171 169 172 DnDDirDroppedFilesRollback(&mDropDir); 173 DnDDirDroppedFilesClose(&mDropDir, true /* fRemove */); 170 if (pDropDir) 171 { 172 int rc2 = DnDDirDroppedFilesRollback(pDropDir); 173 AssertRC(rc2); 174 rc2 = DnDDirDroppedFilesClose(pDropDir, true /* fRemove */); 175 AssertRC(rc2); 176 177 DnDDirDroppedFilesDestroy(pDropDir); 178 pDropDir = NULL; 179 } 174 180 175 181 if (pvScratchBuf) … … 182 188 } 183 189 184 DNDDIRDROPPEDFILES mDropDir; 190 /** Pointer to dropped files object. */ 191 PDNDDIRDROPPEDFILES pDropDir; 185 192 /** (Non-recursive) List of URI objects to handle. */ 186 193 DnDURIList lstURI; -
trunk/src/VBox/Main/src-client/GuestDnDSourceImpl.cpp
r57500 r57654 419 419 if (fHasURIList) 420 420 { 421 Utf8Str strURIs = pCtx->mURI.lstURI.RootToString(RTCString(DnDDirDroppedFilesGetDirAbs( &pCtx->mURI.mDropDir)));421 Utf8Str strURIs = pCtx->mURI.lstURI.RootToString(RTCString(DnDDirDroppedFilesGetDirAbs(pCtx->mURI.pDropDir))); 422 422 cbData = strURIs.length(); 423 423 … … 604 604 605 605 int rc; 606 char *pszDir = RTPathJoinA(DnDDirDroppedFilesGetDirAbs( &pCtx->mURI.mDropDir), pszPath);606 char *pszDir = RTPathJoinA(DnDDirDroppedFilesGetDirAbs(pCtx->mURI.pDropDir), pszPath); 607 607 if (pszDir) 608 608 { … … 663 663 664 664 char pszPathAbs[RTPATH_MAX]; 665 rc = RTPathJoin(pszPathAbs, sizeof(pszPathAbs), DnDDirDroppedFilesGetDirAbs( &pCtx->mURI.mDropDir), pszPath);665 rc = RTPathJoin(pszPathAbs, sizeof(pszPathAbs), DnDDirDroppedFilesGetDirAbs(pCtx->mURI.pDropDir), pszPath); 666 666 if (RT_FAILURE(rc)) 667 667 { … … 1036 1036 do 1037 1037 { 1038 rc = DnDDirDroppedFilesCreateAndOpenTemp( &pCtx->mURI.mDropDir);1038 rc = DnDDirDroppedFilesCreateAndOpenTemp(0 /* fFlags */, &pCtx->mURI.pDropDir); 1039 1039 if (RT_FAILURE(rc)) 1040 1040 break; 1041 LogFlowFunc(("rc=%Rrc, strDropDir=%s\n", rc, DnDDirDroppedFilesGetDirAbs( &pCtx->mURI.mDropDir)));1041 LogFlowFunc(("rc=%Rrc, strDropDir=%s\n", rc, DnDDirDroppedFilesGetDirAbs(pCtx->mURI.pDropDir))); 1042 1042 if (RT_FAILURE(rc)) 1043 1043 break; … … 1100 1100 } 1101 1101 1102 if (RT_FAILURE(rc)) 1103 { 1104 rc2 = DnDDirDroppedFilesRollback(&pCtx->mURI.mDropDir); /** @todo Inform user on rollback failure? */ 1105 LogFlowFunc(("Rolling back ended with rc=%Rrc\n", rc2)); 1106 } 1107 1108 rc2 = DnDDirDroppedFilesClose(&pCtx->mURI.mDropDir, RT_FAILURE(rc) ? true : false /* fRemove */); 1109 if (RT_SUCCESS(rc)) 1110 rc = rc2; 1102 if (pCtx->mURI.pDropDir) 1103 { 1104 if (RT_FAILURE(rc)) 1105 { 1106 rc2 = DnDDirDroppedFilesRollback(pCtx->mURI.pDropDir); /** @todo Inform user on rollback failure? */ 1107 LogFlowFunc(("Rolling back ended with rc=%Rrc\n", rc2)); 1108 } 1109 1110 rc2 = DnDDirDroppedFilesClose(pCtx->mURI.pDropDir, RT_FAILURE(rc) ? true : false /* fRemove */); 1111 if (RT_SUCCESS(rc)) 1112 rc = rc2; 1113 1114 DnDDirDroppedFilesDestroy(pCtx->mURI.pDropDir); 1115 pCtx->mURI.pDropDir = NULL; 1116 } 1111 1117 1112 1118 LogFlowFuncLeaveRC(rc);
Note:
See TracChangeset
for help on using the changeset viewer.