Changeset 74364 in vbox for trunk/src/VBox/Additions/WINNT
- Timestamp:
- Sep 19, 2018 10:06:16 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDnDDropTarget.cpp
r69500 r74364 332 332 { 333 333 case CF_TEXT: 334 /* Fall through is intentional. */334 RT_FALL_THROUGH(); 335 335 case CF_UNICODETEXT: 336 336 { 337 337 AssertPtr(pvData); 338 338 size_t cbSize = GlobalSize(pvData); 339 LogFlowFunc(("CF_TEXT/CF_UNICODETEXT 0x%p got %zu bytes\n", pvData, cbSize)); 339 340 LogRel(("DnD: Got %zu bytes of %s\n", cbSize, 341 mFormatEtc.cfFormat == CF_TEXT 342 ? "ANSI text" : "Unicode text")); 340 343 if (cbSize) 341 344 { … … 372 375 DROPFILES *pDropFiles = (DROPFILES *)pvData; 373 376 AssertPtr(pDropFiles); 374 bool fUnicode = RT_BOOL(pDropFiles->fWide); 377 378 /* Do we need to do Unicode stuff? */ 379 const bool fUnicode = RT_BOOL(pDropFiles->fWide); 375 380 376 381 /* Get the offset of the file list. */ 377 382 Assert(pDropFiles->pFiles >= sizeof(DROPFILES)); 383 378 384 /* Note: This is *not* pDropFiles->pFiles! DragQueryFile only 379 385 * will work with the plain storage medium pointer! */ … … 384 390 char *pszFiles = NULL; 385 391 uint32_t cchFiles = 0; 386 UINT cFiles = DragQueryFile(hDrop, UINT32_MAX /* iFile */, 387 NULL /* lpszFile */, 0 /* cchFile */); 388 Log FlowFunc(("CF_HDROP got %RU16 file(s)\n", cFiles));392 UINT cFiles = DragQueryFile(hDrop, UINT32_MAX /* iFile */, NULL /* lpszFile */, 0 /* cchFile */); 393 394 LogRel2(("DnD: CF_HDROP got %RU16 file(s), fUnicode=%RTbool\n", cFiles, fUnicode)); 389 395 390 396 for (UINT i = 0; i < cFiles; i++) 391 397 { 392 UINT cch = DragQueryFile(hDrop, i /* File index */, 393 NULL /* Query size first */, 394 0 /* cchFile */); 395 Assert(cch); 398 UINT cchFile = DragQueryFile(hDrop, i /* File index */, NULL /* Query size first */, 0 /* cchFile */); 399 Assert(cchFile); 396 400 397 401 if (RT_FAILURE(rc)) 398 402 break; 399 403 400 char *pszFile = NULL; /* UTF-8 version. */401 UINT cchFile = 0;404 char *pszFileUtf8 = NULL; /* UTF-8 version. */ 405 UINT cchFileUtf8 = 0; 402 406 if (fUnicode) 403 407 { 404 408 /* Allocate enough space (including terminator). */ 405 WCHAR *pwszFile = (WCHAR *)RTMemAlloc((cch + 1) * sizeof(WCHAR));409 WCHAR *pwszFile = (WCHAR *)RTMemAlloc((cchFile + 1) * sizeof(WCHAR)); 406 410 if (pwszFile) 407 411 { 408 cchFile = DragQueryFileW(hDrop, i /* File index */, 409 pwszFile, cch + 1 /* Include terminator */); 410 AssertMsg(cchFile == cch, ("cchCopied (%RU16) does not match cchFile (%RU16)\n", 411 cchFile, cch)); 412 rc = RTUtf16ToUtf8(pwszFile, &pszFile); 412 const UINT cchFileUtf16 = DragQueryFileW(hDrop, i /* File index */, 413 pwszFile, cchFile + 1 /* Include terminator */); 414 415 AssertMsg(cchFileUtf16 == cchFile, ("cchFileUtf16 (%RU16) does not match cchFile (%RU16)\n", 416 cchFileUtf8, cchFile)); 417 418 rc = RTUtf16ToUtf8(pwszFile, &pszFileUtf8); 413 419 AssertRC(rc); 420 Assert(RTStrIsValidEncoding(pszFileUtf8)); 421 422 cchFileUtf8 = strlen(pszFileUtf8); 423 Assert(cchFileUtf8); 414 424 415 425 RTMemFree(pwszFile); … … 421 431 { 422 432 /* Allocate enough space (including terminator). */ 423 pszFile = (char *)RTMemAlloc((cch+ 1) * sizeof(char));424 if (pszFile )433 pszFileUtf8 = (char *)RTMemAlloc((cchFile + 1) * sizeof(char)); 434 if (pszFileUtf8) 425 435 { 426 cchFile = DragQueryFileA(hDrop, i /* File index */, 427 pszFile, cchFile + 1 /* Include terminator */); 428 AssertMsg(cchFile == cch, ("cchCopied (%RU16) does not match cchFile (%RU16)\n", 429 cchFile, cch)); 436 cchFileUtf8 = DragQueryFileA(hDrop, i /* File index */, 437 pszFileUtf8, cchFile + 1 /* Include terminator */); 438 439 AssertMsg(cchFileUtf8 == cchFile, ("cchFileUtf8 (%RU16) does not match cchFile (%RU16)\n", 440 cchFileUtf8, cchFile)); 430 441 } 431 442 else … … 435 446 if (RT_SUCCESS(rc)) 436 447 { 437 LogFlowFunc(("\tFile: %s (cchFile=%RU32)\n", pszFile, cchFile)); 438 rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */, 439 pszFile, cchFile); 448 LogFlowFunc(("\tFile: %s (cchFile=%RU16)\n", pszFileUtf8, cchFileUtf8)); 449 450 LogRel(("DnD: Adding guest file '%s'\n", pszFileUtf8)); 451 452 rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */, pszFileUtf8, cchFileUtf8); 440 453 if (RT_SUCCESS(rc)) 441 cchFiles += cchFile ;454 cchFiles += cchFileUtf8; 442 455 } 443 456 444 if (pszFile )445 RTStrFree(pszFile );457 if (pszFileUtf8) 458 RTStrFree(pszFileUtf8); 446 459 447 460 if (RT_FAILURE(rc)) … … 450 463 /* Add separation between filenames. 451 464 * Note: Also do this for the last element of the list. */ 452 rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */, 453 "\r\n", 2 /* Bytes */); 465 rc = RTStrAAppendExN(&pszFiles, 1 /* cPairs */, "\r\n", 2 /* Bytes */); 454 466 if (RT_SUCCESS(rc)) 455 467 cchFiles += 2; /* Include \r\n */
Note:
See TracChangeset
for help on using the changeset viewer.