Changeset 56575 in vbox
- Timestamp:
- Jun 22, 2015 12:28:52 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibDragAndDrop.cpp
r56505 r56575 347 347 } 348 348 349 static int vbglR3DnDHGProcessURIMessages(PVBGLR3GUESTDNDCMDCTX pCtx, 350 uint32_t *puScreenId, 351 char *pszFormat, 352 uint32_t cbFormat, 353 uint32_t *pcbFormatRecv, 354 void **ppvData, 355 uint32_t cbData, 356 size_t *pcbDataRecv) 349 static int vbglR3DnDHGProcessURIMessages(PVBGLR3GUESTDNDCMDCTX pCtx, 350 void **ppvData, 351 uint32_t cbData, 352 size_t *pcbDataRecv) 357 353 { 358 354 AssertPtrReturn(pCtx, VERR_INVALID_POINTER); … … 361 357 AssertPtrReturn(pcbDataRecv, VERR_INVALID_POINTER); 362 358 363 void *pvData = *ppvData; 364 uint32_t cbDataRecv = 0; 365 uint64_t cbDataToRead = *pcbDataRecv; 366 uint64_t cbDataWritten = 0; 367 368 int rc = VINF_SUCCESS; 369 370 /* Allocate temp buffer. */ 371 uint32_t cbTmpData = _64K; /** @todo Make this configurable? */ 372 void *pvTmpData = RTMemAlloc(cbTmpData); 373 if (!pvTmpData) 359 /* 360 * Allocate chunk buffer. 361 */ 362 uint32_t cbChunkMax = _64K; /** @todo Make this configurable? */ 363 void *pvChunk = RTMemAlloc(cbChunkMax); 364 if (!pvChunk) 374 365 return VERR_NO_MEMORY; 375 376 /* Create and query the (unique) drop target directory in the user's temporary directory. */ 366 uint32_t cbChunkRead = 0; 367 368 uint64_t cbFileSize = 0; /* Total file size (in bytes). */ 369 uint64_t cbFileWritten = 0; /* Written bytes. */ 370 371 /* 372 * Create and query the (unique) drop target directory in the user's temporary directory. 373 */ 377 374 DNDDIRDROPPEDFILES dirDroppedFiles; 378 375 const char *pszDropDir; 379 rc = DnDDirDroppedFilesCreateAndOpenTemp(&dirDroppedFiles);376 int rc = DnDDirDroppedFilesCreateAndOpenTemp(&dirDroppedFiles); 380 377 if (RT_SUCCESS(rc)) 381 378 pszDropDir = DnDDirDroppedFilesGetDirAbs(&dirDroppedFiles); 382 379 380 /* 381 * Enter the main loop of retieving files + directories. 382 */ 383 383 DnDURIList lstURI; 384 384 DnDURIObject objFile(DnDURIObject::File); … … 427 427 { 428 428 if (uNextMsg == DragAndDropSvc::HOST_DND_HG_SND_FILE_HDR) 429 { 429 430 rc = vbglR3DnDHGProcessSendFileHdrMessage(pCtx, 430 431 szPathName, … … 432 433 &fFlags, 433 434 &fMode, 434 &cbDataToRead); 435 &cbFileSize); 436 LogFlowFunc(("HOST_DND_HG_SND_FILE_HDR szPathName=%s, fFlags=0x%x, fMode=0x%x, cbFileSize=%RU64, rc=%Rrc\n", 437 szPathName, fFlags, fMode, cbFileSize, rc)); 438 } 435 439 else 440 { 436 441 rc = vbglR3DnDHGProcessSendFileMessage(pCtx, 437 442 szPathName, 438 443 sizeof(szPathName), 439 444 &cbPathName, 440 pv TmpData,441 cb TmpData,442 &cb DataRecv,445 pvChunk, 446 cbChunkMax, 447 &cbChunkRead, 443 448 &fMode); 449 LogFlowFunc(("HOST_DND_HG_SND_FILE_DATA " 450 "szPathName=%s, cbPathName=%RU32, cbChunkRead=%RU32, fMode=0x%x, rc=%Rrc\n", 451 szPathName, cbPathName, cbChunkRead, fMode, rc)); 452 } 453 444 454 if ( RT_SUCCESS(rc) 445 455 && ( uNextMsg == DragAndDropSvc::HOST_DND_HG_SND_FILE_HDR … … 451 461 if (pszPathAbs) 452 462 { 453 LogFlowFunc(("Opening pszPathName=%s, cbPathName=%RU32, fMode=0x%x, cb Size=%RU64\n",454 szPathName, cbPathName, fMode, cb DataToRead));463 LogFlowFunc(("Opening pszPathName=%s, cbPathName=%RU32, fMode=0x%x, cbFileSize=%zu\n", 464 szPathName, cbPathName, fMode, cbFileSize)); 455 465 456 466 uint64_t fOpen = RTFILE_O_WRITE | RTFILE_O_DENY_ALL; … … 463 473 if (!objFile.IsOpen()) 464 474 { 465 466 475 RTCString strPathAbs(pszPathAbs); 467 476 rc = objFile.OpenEx(strPathAbs, DnDURIObject::File, DnDURIObject::Target, fOpen, … … 472 481 if (RT_SUCCESS(rc)) 473 482 { 474 cb DataWritten = 0;483 cbFileWritten = 0; 475 484 476 485 if (pCtx->uProtocol >= 2) /* Set the expected file size. */ 477 objFile.SetSize(cb DataToRead);486 objFile.SetSize(cbFileSize); 478 487 } 479 488 } … … 493 502 bool fClose = false; 494 503 495 uint32_t cb Written;496 rc = objFile.Write(pv TmpData, cbDataRecv, &cbWritten);504 uint32_t cbChunkWritten; 505 rc = objFile.Write(pvChunk, cbChunkRead, &cbChunkWritten); 497 506 if (RT_SUCCESS(rc)) 498 507 { … … 505 514 fClose = true; /* Always close the file after each chunk. */ 506 515 507 cb DataWritten += cbWritten;508 Assert(cb DataWritten <= cbDataToRead);516 cbFileWritten += cbChunkWritten; 517 Assert(cbFileWritten <= cbFileSize); 509 518 } 510 519 … … 525 534 } 526 535 default: 536 { 527 537 LogFlowFunc(("Message %RU32 not supported\n", uNextMsg)); 528 538 rc = VERR_NOT_SUPPORTED; 529 539 break; 530 }531 532 #if 0 /* Not used yet. */533 if (pCtx->uProtocol >= XXX)534 {535 /*536 * Send the progress back to the host.537 */538 uint32_t uStatus;539 int guestRc;540 uint8_t uPercent;541 switch (rc)542 {543 case VINF_SUCCESS:544 {545 if (!cbData)546 cbData = 1;547 uPercent = cbDataWritten * 100 / (cbDataToRead ? cbDataToRead : 1);548 uStatus = uPercent >= 100 ?549 DragAndDropSvc::DND_PROGRESS_COMPLETE : DragAndDropSvc::DND_PROGRESS_RUNNING;550 guestRc = VINF_SUCCESS;551 break;552 }553 554 case VERR_CANCELLED:555 {556 uStatus = DragAndDropSvc::DND_PROGRESS_CANCELLED;557 uPercent = 100;558 guestRc = VINF_SUCCESS;559 break;560 }561 562 default:563 {564 uStatus = DragAndDropSvc::DND_PROGRESS_ERROR;565 uPercent = 100;566 guestRc = rc;567 break;568 }569 }570 571 int rc2 = VbglR3DnDHGSetProgress(pCtx, uStatus, uPercent, guestRc);572 LogFlowFunc(("cbDataWritten=%RU64 / cbDataToRead=%RU64 => %RU8%% (uStatus=%ld, %Rrc), rc=%Rrc\n", cbDataWritten, cbDataToRead,573 uPercent, uStatus, guestRc, rc2));574 if (RT_SUCCESS(rc))575 rc = rc2;576 577 /* All data transferred? */578 if ( RT_SUCCESS(rc)579 && uPercent == 100)580 {581 rc = VINF_EOF;582 break;583 540 } 584 541 } 585 #endif586 542 } 587 543 … … 597 553 rc = VINF_SUCCESS; 598 554 599 if (pvTmpData) 600 RTMemFree(pvTmpData); 555 /* Delete chunk buffer again. */ 556 if (pvChunk) 557 RTMemFree(pvChunk); 601 558 602 559 /* Cleanup on failure or if the user has canceled the operation or … … 610 567 { 611 568 /* 612 * Patch the old drop data with the new drop directory, so the drop target can find the files. 569 * Now we need to transform the URI list which came from the host into 570 * an URI list which also has the final "Dropped Files" directory as a prefix 571 * for each URI entry. 572 * 573 * So patch the old drop data with the new drop directory to let the drop 574 * target on the guest can find the files later. 613 575 */ 614 rc = lstURI.RootFromURIData(pvData, cbDataToRead, 0 /* fFlags */); 576 void *pvURIData = *ppvData; 577 size_t cbURIData = *pcbDataRecv; 578 579 rc = lstURI.RootFromURIData(pvURIData, cbURIData, 0 /* fFlags */); 615 580 if (RT_SUCCESS(rc)) 616 581 { 617 582 /* Cleanup the old data and write the new data back to the event. */ 618 RTMemFree(pv Data);583 RTMemFree(pvURIData); 619 584 620 585 RTCString strData = lstURI.RootToString(pszDropDir); 621 LogFlowFunc(("cbDataToRead: %zu -> %zu\n", cbDataToRead, strData.length() + 1)); 622 623 pvData = RTStrDupN(strData.c_str(), strData.length()); 624 cbDataToRead = strData.length() + 1; 586 Assert(!strData.isEmpty()); 587 LogFlowFunc(("New URI list now has %zu bytes (formerly %RU32 bytes)\n", strData.length() + 1, cbURIData)); 588 589 pvURIData = RTStrDupN(strData.c_str(), strData.length()); 590 if (pvURIData) 591 { 592 cbURIData = strData.length() + 1; 593 } 594 else 595 rc = VERR_NO_MEMORY; 625 596 } 626 597 627 598 if (RT_SUCCESS(rc)) 628 599 { 629 *ppvData = pv Data;630 *pcbDataRecv = cb DataToRead;600 *ppvData = pvURIData; 601 *pcbDataRecv = cbURIData; 631 602 } 632 603 … … 849 820 { 850 821 rc = vbglR3DnDHGProcessURIMessages(pCtx, 851 puScreenId,852 pszFormat,853 cbFormat,854 pcbFormatRecv,855 822 ppvData, 856 823 cbData,
Note:
See TracChangeset
for help on using the changeset viewer.

