Changeset 74574 in vbox for trunk/src/VBox/GuestHost/DragAndDrop/DnDURIObject.cpp
- Timestamp:
- Oct 2, 2018 9:38:42 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/DragAndDrop/DnDURIObject.cpp
r74527 r74574 38 38 DnDURIObject::DnDURIObject(void) 39 39 : m_Type(Type_Unknown) 40 , m_fOpen(false) 41 , m_fMode(0) 42 , m_cbSize(0) 43 , m_cbProcessed(0) 40 , m_fIsOpen(false) 44 41 { 45 42 RT_ZERO(u); … … 47 44 48 45 DnDURIObject::DnDURIObject(Type enmType, 49 const RTCString &strSrcPath /* = 0 */,50 const RTCString &strDstPath /* = 0 */,46 const RTCString &strSrcPathAbs /* = 0 */, 47 const RTCString &strDstPathAbs /* = 0 */, 51 48 uint32_t fMode /* = 0 */, uint64_t cbSize /* = 0 */) 52 49 : m_Type(enmType) 53 , m_strSrcPath(strSrcPath) 54 , m_strTgtPath(strDstPath) 55 , m_fOpen(false) 56 , m_fMode(fMode) 57 , m_cbSize(cbSize) 58 , m_cbProcessed(0) 59 { 50 , m_strSrcPathAbs(strSrcPathAbs) 51 , m_strTgtPathAbs(strDstPathAbs) 52 , m_fIsOpen(false) 53 { 54 RT_ZERO(u); 55 56 switch (m_Type) 57 { 58 case Type_File: 59 u.File.fMode = fMode; 60 u.File.cbSize = cbSize; 61 break; 62 63 default: 64 break; 65 } 60 66 } 61 67 … … 65 71 } 66 72 73 /** 74 * Closes the object's internal handles (to files / ...). 75 * 76 */ 67 77 void DnDURIObject::closeInternal(void) 68 78 { 69 79 LogFlowThisFuncEnter(); 70 80 71 if (!m_f Open)81 if (!m_fIsOpen) 72 82 return; 73 83 … … 76 86 case Type_File: 77 87 { 78 RTFileClose(u.m_hFile); 79 u.m_hFile = NIL_RTFILE; 88 RTFileClose(u.File.hFile); 89 u.File.hFile = NIL_RTFILE; 90 u.File.fMode = 0; 80 91 break; 81 92 } … … 88 99 } 89 100 90 m_fOpen = false; 91 } 92 101 m_fIsOpen = false; 102 } 103 104 /** 105 * Closes the object. 106 * This also closes the internal handles associated with the object (to files / ...). 107 */ 93 108 void DnDURIObject::Close(void) 94 109 { … … 96 111 } 97 112 113 /** 114 * Returns whether the processing of the object is complete or not. 115 * For file objects this means that all bytes have been processed. 116 * 117 * @return True if complete, False if not. 118 */ 98 119 bool DnDURIObject::IsComplete(void) const 99 120 { … … 103 124 { 104 125 case Type_File: 105 Assert( m_cbProcessed <= m_cbSize);106 fComplete = m_cbProcessed == m_cbSize;126 Assert(u.File.cbProcessed <= u.File.cbSize); 127 fComplete = u.File.cbProcessed == u.File.cbSize; 107 128 break; 108 129 … … 119 140 } 120 141 142 /** 143 * Returns whether the object is in an open state or not. 144 */ 121 145 bool DnDURIObject::IsOpen(void) const 122 146 { 123 return m_fOpen; 124 } 125 147 return m_fIsOpen; 148 } 149 150 /** 151 * (Re-)Opens the object with a specific view, open and file mode. 152 * 153 * @return IPRT status code. 154 * @param enmView View to use for opening the object. 155 * @param fOpen File open flags to use. 156 * @param fMode 157 * 158 * @remark 159 */ 126 160 int DnDURIObject::Open(View enmView, uint64_t fOpen /* = 0 */, uint32_t fMode /* = 0 */) 127 161 { 128 162 return OpenEx( enmView == View_Source 129 ? m_strSrcPath : m_strTgtPath163 ? m_strSrcPathAbs : m_strTgtPathAbs 130 164 , m_Type, enmView, fOpen, fMode, 0 /* fFlags */); 131 165 } 132 166 133 int DnDURIObject::OpenEx(const RTCString &strPath, Type enmType, View enmView, 167 /** 168 * Open the object with a specific file type, and, depending on the type, specifying additional parameters. 169 * 170 * @return IPRT status code. 171 * @param strPathAbs Absolute path of the object (file / directory / ...). 172 * @param enmType Type of the object. 173 * @param enmView View of the object. 174 * @param fOpen Open mode to use; only valid for file objects. 175 * @param fMode File mode to use; only valid for file objects. 176 * @param fFlags Additional DnD URI object flags. 177 */ 178 int DnDURIObject::OpenEx(const RTCString &strPathAbs, Type enmType, View enmView, 134 179 uint64_t fOpen /* = 0 */, uint32_t fMode /* = 0 */, DNDURIOBJECTFLAGS fFlags /* = DNDURIOBJECT_FLAGS_NONE */) 135 180 { 136 Assert(fFlags == 0); RT_NOREF1(fFlags); 181 AssertReturn(fFlags & DNDURIOBJECT_FLAGS_VALID_MASK, VERR_INVALID_PARAMETER); 182 RT_NOREF1(fFlags); 183 137 184 int rc = VINF_SUCCESS; 138 185 … … 140 187 { 141 188 case View_Source: 142 m_strSrcPath = strPath;189 m_strSrcPathAbs = strPathAbs; 143 190 break; 144 191 145 192 case View_Target: 146 m_strTgtPath = strPath;193 m_strTgtPathAbs = strPathAbs; 147 194 break; 148 195 … … 156 203 { 157 204 LogFlowThisFunc(("strPath=%s, enmType=%RU32, enmView=%RU32, fOpen=0x%x, fMode=0x%x, fFlags=0x%x\n", 158 strPath .c_str(), enmType, enmView, fOpen, fMode, fFlags));205 strPathAbs.c_str(), enmType, enmView, fOpen, fMode, fFlags)); 159 206 switch (enmType) 160 207 { 161 208 case Type_File: 162 209 { 163 if (!m_f Open)210 if (!m_fIsOpen) 164 211 { 165 212 /* … … 169 216 */ 170 217 LogFlowThisFunc(("Opening ...\n")); 171 rc = RTFileOpen(&u. m_hFile, strPath.c_str(), fOpen);218 rc = RTFileOpen(&u.File.hFile, strPathAbs.c_str(), fOpen); 172 219 if (RT_SUCCESS(rc)) 173 rc = RTFileGetSize(u. m_hFile, &m_cbSize);220 rc = RTFileGetSize(u.File.hFile, &u.File.cbSize); 174 221 175 222 if (RT_SUCCESS(rc)) … … 178 225 && fMode /* Some file mode to set specified? */) 179 226 { 180 rc = RTFileSetMode(u. m_hFile, fMode);227 rc = RTFileSetMode(u.File.hFile, fMode); 181 228 if (RT_SUCCESS(rc)) 182 m_fMode = fMode;229 u.File.fMode = fMode; 183 230 } 184 231 else if (fOpen & RTFILE_O_READ) … … 188 235 #else 189 236 RTFSOBJINFO ObjInfo; 190 rc = RTFileQueryInfo(u. m_hFile, &ObjInfo, RTFSOBJATTRADD_NOTHING);237 rc = RTFileQueryInfo(u.File.hFile, &ObjInfo, RTFSOBJATTRADD_NOTHING); 191 238 if (RT_SUCCESS(rc)) 192 m_fMode = ObjInfo.Attr.fMode;239 u.File.fMode = ObjInfo.Attr.fMode; 193 240 #endif 194 241 } … … 197 244 if (RT_SUCCESS(rc)) 198 245 { 199 LogFlowThisFunc(("cbSize=%RU64, fMode=0x%x\n", m_cbSize, m_fMode));200 m_cbProcessed = 0;246 LogFlowThisFunc(("cbSize=%RU64, fMode=0x%x\n", u.File.cbSize, u.File.fMode)); 247 u.File.cbProcessed = 0; 201 248 } 202 249 } … … 220 267 { 221 268 m_Type = enmType; 222 m_f Open = true;269 m_fIsOpen = true; 223 270 } 224 271 … … 227 274 } 228 275 276 /** 277 * Rebases an absolute URI path from an old path base to a new path base. 278 * This function is needed in order to transform path from the source side to the target side. 279 * 280 * @return IPRT status code. 281 * @param strPathAbs Absolute URI path to rebase. 282 * @param strBaseOld Old base path to rebase from. 283 * @param strBaseNew New base path to rebase to. 284 * 285 ** @todo Put this into an own class like DnDURIPath : public RTCString? 286 */ 229 287 /* static */ 230 /** @todo Put this into an own class like DnDURIPath : public RTCString? */ 231 int DnDURIObject::RebaseURIPath(RTCString &strPath, 288 int DnDURIObject::RebaseURIPath(RTCString &strPathAbs, 232 289 const RTCString &strBaseOld /* = "" */, 233 290 const RTCString &strBaseNew /* = "" */) 234 291 { 235 char *pszPath = RTUriFilePath(strPath .c_str());292 char *pszPath = RTUriFilePath(strPathAbs.c_str()); 236 293 if (!pszPath) /* No URI? */ 237 pszPath = RTStrDup(strPath .c_str());294 pszPath = RTStrDup(strPathAbs.c_str()); 238 295 239 296 int rc; … … 261 318 if (pszPathURI) 262 319 { 263 LogFlowFunc(("Rebasing \"%s\" to \"%s\"\n", strPath .c_str(), pszPathURI));264 265 strPath = RTCString(pszPathURI) + "\r\n";320 LogFlowFunc(("Rebasing \"%s\" to \"%s\"\n", strPathAbs.c_str(), pszPathURI)); 321 322 strPathAbs = RTCString(pszPathURI) + "\r\n"; 266 323 RTStrFree(pszPathURI); 267 324 } … … 283 340 } 284 341 342 /** 343 * Reads data from the object. Only applies to files objects. 344 * 345 * @return IPRT status code. 346 * @param pvBuf Buffer where to store the read data. 347 * @param cbBuf Size (in bytes) of the buffer. 348 * @param pcbRead Pointer where to store how many bytes were read. Optional. 349 */ 285 350 int DnDURIObject::Read(void *pvBuf, size_t cbBuf, uint32_t *pcbRead) 286 351 { … … 296 361 case Type_File: 297 362 { 298 rc = OpenEx(m_strSrcPath , Type_File, View_Source,363 rc = OpenEx(m_strSrcPathAbs, Type_File, View_Source, 299 364 /* Use some sensible defaults. */ 300 365 RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE, 0 /* fFlags */); 301 366 if (RT_SUCCESS(rc)) 302 367 { 303 rc = RTFileRead(u. m_hFile, pvBuf, cbBuf, &cbRead);368 rc = RTFileRead(u.File.hFile, pvBuf, cbBuf, &cbRead); 304 369 if (RT_SUCCESS(rc)) 305 370 { 306 m_cbProcessed += cbRead;307 Assert( m_cbProcessed <= m_cbSize);371 u.File.cbProcessed += cbRead; 372 Assert(u.File.cbProcessed <= u.File.cbSize); 308 373 309 374 /* End of file reached or error occurred? */ 310 if ( m_cbSize311 && m_cbProcessed == m_cbSize)375 if ( u.File.cbSize 376 && u.File.cbProcessed == u.File.cbSize) 312 377 { 313 378 rc = VINF_EOF; … … 336 401 } 337 402 338 LogFlowFunc(("Returning strSourcePath=%s, cbRead=%zu, rc=%Rrc\n", m_strSrcPath .c_str(), cbRead, rc));403 LogFlowFunc(("Returning strSourcePath=%s, cbRead=%zu, rc=%Rrc\n", m_strSrcPathAbs.c_str(), cbRead, rc)); 339 404 return rc; 340 405 } 341 406 407 /** 408 * Resets the object's state and closes all related handles. 409 */ 342 410 void DnDURIObject::Reset(void) 343 411 { … … 346 414 Close(); 347 415 348 m_Type = Type_Unknown; 349 m_strSrcPath = ""; 350 m_strTgtPath = ""; 351 m_fMode = 0; 352 m_cbSize = 0; 353 m_cbProcessed = 0; 354 } 355 416 m_Type = Type_Unknown; 417 m_strSrcPathAbs = ""; 418 m_strTgtPathAbs = ""; 419 420 RT_ZERO(u); 421 } 422 423 /** 424 * Writes data to an object. Only applies to file objects. 425 * 426 * @return IPRT status code. 427 * @param pvBuf Buffer of data to write. 428 * @param cbBuf Size (in bytes) of data to write. 429 * @param pcbWritten Pointer where to store how many bytes were written. Optional. 430 */ 356 431 int DnDURIObject::Write(const void *pvBuf, size_t cbBuf, uint32_t *pcbWritten) 357 432 { … … 367 442 case Type_File: 368 443 { 369 rc = OpenEx(m_strTgtPath , Type_File, View_Target,444 rc = OpenEx(m_strTgtPathAbs, Type_File, View_Target, 370 445 /* Use some sensible defaults. */ 371 446 RTFILE_O_OPEN_CREATE | RTFILE_O_DENY_WRITE | RTFILE_O_WRITE, 0 /* fFlags */); 372 447 if (RT_SUCCESS(rc)) 373 448 { 374 rc = RTFileWrite(u. m_hFile, pvBuf, cbBuf, &cbWritten);449 rc = RTFileWrite(u.File.hFile, pvBuf, cbBuf, &cbWritten); 375 450 if (RT_SUCCESS(rc)) 376 m_cbProcessed += cbWritten;451 u.File.cbProcessed += cbWritten; 377 452 } 378 453 break; … … 396 471 } 397 472 398 LogFlowThisFunc(("Returning strSourcePath =%s, cbWritten=%zu, rc=%Rrc\n", m_strSrcPath.c_str(), cbWritten, rc));473 LogFlowThisFunc(("Returning strSourcePathAbs=%s, cbWritten=%zu, rc=%Rrc\n", m_strSrcPathAbs.c_str(), cbWritten, rc)); 399 474 return rc; 400 475 }
Note:
See TracChangeset
for help on using the changeset viewer.