Changeset 57776 in vbox for trunk/src/VBox/GuestHost/DragAndDrop/DnDDroppedFiles.cpp
- Timestamp:
- Sep 16, 2015 9:40:54 AM (9 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/DragAndDrop/DnDDroppedFiles.cpp
r57756 r57776 28 28 #include <VBox/GuestHost/DragAndDrop.h> 29 29 30 int DnDDirDroppedAddFile(PDNDDIRDROPPEDFILES pDir, const char *pszFile) 31 { 32 AssertPtrReturn(pDir, VERR_INVALID_POINTER); 30 DnDDroppedFiles::DnDDroppedFiles(void) 31 : hDir(NULL) 32 , fOpen(false) { } 33 34 DnDDroppedFiles::DnDDroppedFiles(const char *pszPath, uint32_t fFlags) 35 : hDir(NULL) 36 , fOpen(false) 37 { 38 OpenEx(pszPath, fFlags); 39 } 40 41 DnDDroppedFiles::~DnDDroppedFiles(void) 42 { 43 Reset(true /* fRemoveDropDir */); 44 } 45 46 int DnDDroppedFiles::AddFile(const char *pszFile) 47 { 33 48 AssertPtrReturn(pszFile, VERR_INVALID_POINTER); 34 49 35 if (! pDir->lstFiles.contains(pszFile))36 pDir->lstFiles.append(pszFile);50 if (!this->lstFiles.contains(pszFile)) 51 this->lstFiles.append(pszFile); 37 52 return VINF_SUCCESS; 38 53 } 39 54 40 int DnDDirDroppedAddDir(PDNDDIRDROPPEDFILES pDir, const char *pszDir) 41 { 42 AssertPtrReturn(pDir, VERR_INVALID_POINTER); 55 int DnDDroppedFiles::AddDir(const char *pszDir) 56 { 43 57 AssertPtrReturn(pszDir, VERR_INVALID_POINTER); 44 58 45 if (! pDir->lstDirs.contains(pszDir))46 pDir->lstDirs.append(pszDir);59 if (!this->lstDirs.contains(pszDir)) 60 this->lstDirs.append(pszDir); 47 61 return VINF_SUCCESS; 48 62 } 49 63 50 static int dndDirDroppedFilesCreate(uint32_t fFlags, PDNDDIRDROPPEDFILES *ppDir) 51 { 64 const char *DnDDroppedFiles::GetDirAbs(void) const 65 { 66 return this->strPathAbs.c_str(); 67 } 68 69 bool DnDDroppedFiles::IsOpen(void) const 70 { 71 return this->fOpen; 72 } 73 74 int DnDDroppedFiles::OpenEx(const char *pszPath, uint32_t fFlags) 75 { 76 AssertPtrReturn(pszPath, VERR_INVALID_POINTER); 52 77 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) 69 { 70 AssertPtrReturn(pszPath, VERR_INVALID_POINTER); 71 AssertPtrReturn(ppDir, VERR_INVALID_POINTER); 72 73 PDNDDIRDROPPEDFILES pDir; 74 int rc = dndDirDroppedFilesCreate(fFlags, &pDir); 75 if (RT_FAILURE(rc)) 76 return rc; 78 79 int rc; 77 80 78 81 do 79 82 { 80 83 char pszDropDir[RTPATH_MAX]; 81 if (RTStrPrintf(pszDropDir, sizeof(pszDropDir), "%s", pszPath) <= 0) 82 { 83 rc = VERR_NO_MEMORY; 84 break; 85 } 84 size_t cchDropDir = RTStrPrintf(pszDropDir, sizeof(pszDropDir), "%s", pszPath); 86 85 87 86 /** @todo On Windows we also could use the registry to override … … 90 89 91 90 /* Append our base drop directory. */ 92 intrc = RTPathAppend(pszDropDir, sizeof(pszDropDir), "VirtualBox Dropped Files"); /** @todo Make this tag configurable? */91 rc = RTPathAppend(pszDropDir, sizeof(pszDropDir), "VirtualBox Dropped Files"); /** @todo Make this tag configurable? */ 93 92 if (RT_FAILURE(rc)) 94 93 break; … … 128 127 if (RT_SUCCESS(rc)) 129 128 { 130 pDir->hDir = phDir;131 pDir->strPathAbs = pszDropDir;132 pDir->fOpen = true;129 this->hDir = phDir; 130 this->strPathAbs = pszDropDir; 131 this->fOpen = true; 133 132 } 134 133 } … … 136 135 } while (0); 137 136 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) 137 return rc; 138 } 139 140 int DnDDroppedFiles::OpenTemp(uint32_t fFlags) 149 141 { 150 142 AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER); /* Flags not supported yet. */ 151 AssertPtrReturn(ppDir, VERR_INVALID_POINTER);152 153 PDNDDIRDROPPEDFILES pDir;154 143 155 144 /* … … 161 150 int rc = RTPathTemp(szTemp, sizeof(szTemp)); 162 151 if (RT_SUCCESS(rc)) 163 rc = DnDDirDroppedFilesCreateAndOpenEx(szTemp, fFlags, &pDir); 164 152 rc = OpenEx(szTemp, fFlags); 153 154 return rc; 155 } 156 157 int DnDDroppedFiles::Reset(bool fRemoveDropDir) 158 { 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 } 165 169 if (RT_SUCCESS(rc)) 166 170 { 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); 180 } 181 182 int DnDDirDroppedFilesClose(PDNDDIRDROPPEDFILES pDir, bool fRemove) 183 { 184 AssertPtrReturn(pDir, VERR_INVALID_POINTER); 185 186 int rc = VINF_SUCCESS; 187 if (pDir->fOpen) 188 { 189 rc = RTDirClose(pDir->hDir); 190 if (RT_SUCCESS(rc)) 191 { 192 pDir->fOpen = false; 193 pDir->hDir = NULL; 194 } 195 } 196 if (RT_SUCCESS(rc)) 197 { 198 pDir->lstDirs.clear(); 199 pDir->lstFiles.clear(); 200 201 if ( fRemove 202 && pDir->strPathAbs.isNotEmpty()) 171 this->lstDirs.clear(); 172 this->lstFiles.clear(); 173 174 if ( fRemoveDropDir 175 && this->strPathAbs.isNotEmpty()) 203 176 { 204 177 /* Try removing the (empty) drop directory in any case. */ 205 rc = RTDirRemove( pDir->strPathAbs.c_str());178 rc = RTDirRemove(this->strPathAbs.c_str()); 206 179 if (RT_SUCCESS(rc)) /* Only clear if successfully removed. */ 207 pDir->strPathAbs = ""; 208 } 209 } 210 211 return rc; 212 } 213 214 const char *DnDDirDroppedFilesGetDirAbs(PDNDDIRDROPPEDFILES pDir) 215 { 216 AssertPtrReturn(pDir, NULL); 217 return pDir->strPathAbs.c_str(); 218 } 219 220 int DnDDirDroppedFilesRollback(PDNDDIRDROPPEDFILES pDir) 221 { 222 AssertPtrReturn(pDir, VERR_INVALID_POINTER); 223 224 if (pDir->strPathAbs.isEmpty()) 180 this->strPathAbs = ""; 181 } 182 } 183 184 return rc; 185 } 186 187 int DnDDroppedFiles::Rollback(void) 188 { 189 if (this->strPathAbs.isEmpty()) 225 190 return VINF_SUCCESS; 191 192 Assert(this->fOpen); 193 Assert(this->hDir != NULL); 226 194 227 195 int rc = VINF_SUCCESS; … … 231 199 * Note: Only remove empty directories, never ever delete 232 200 * anything recursive here! Steam (tm) knows best ... :-) */ 233 for (size_t i = 0; i < pDir->lstFiles.size(); i++)234 { 235 rc2 = RTFileDelete( pDir->lstFiles.at(i).c_str());201 for (size_t i = 0; i < this->lstFiles.size(); i++) 202 { 203 rc2 = RTFileDelete(this->lstFiles.at(i).c_str()); 236 204 if (RT_SUCCESS(rc)) 237 205 rc = rc2; 238 206 } 239 207 240 for (size_t i = 0; i < pDir->lstDirs.size(); i++)241 { 242 rc2 = RTDirRemove( pDir->lstDirs.at(i).c_str());208 for (size_t i = 0; i < this->lstDirs.size(); i++) 209 { 210 rc2 = RTDirRemove(this->lstDirs.at(i).c_str()); 243 211 if (RT_SUCCESS(rc)) 244 212 rc = rc2; … … 246 214 247 215 /* Try to remove the empty root dropped files directory as well. */ 248 rc2 = RTDirRemove( pDir->strPathAbs.c_str());216 rc2 = RTDirRemove(this->strPathAbs.c_str()); 249 217 if (RT_SUCCESS(rc)) 250 218 rc = rc2;
Note:
See TracChangeset
for help on using the changeset viewer.