Changeset 57654 in vbox for trunk/src/VBox/GuestHost/DragAndDrop
- Timestamp:
- Sep 8, 2015 1:16:17 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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))
Note:
See TracChangeset
for help on using the changeset viewer.