Changeset 78809 in vbox for trunk/src/VBox/GuestHost/SharedClipboard
- Timestamp:
- May 28, 2019 10:54:53 AM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 130905
- Location:
- trunk/src/VBox/GuestHost/SharedClipboard
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/ClipboardDataObjectImpl-win.cpp
r78725 r78809 42 42 #include <VBox/log.h> 43 43 44 #if 1 /** Not enabled yet, needs more testing first. */ 45 # define VBOX_CLIPBOARD_WITH_UNICODE_SUPPORT 1 46 #endif 47 44 48 VBoxClipboardWinDataObject::VBoxClipboardWinDataObject(SharedClipboardProvider *pProvider, 45 49 LPFORMATETC pFormatEtc, LPSTGMEDIUM pStgMed, ULONG cFormats) … … 48 52 , m_cFormats(0) 49 53 , m_pProvider(pProvider) 54 , m_pStream(NULL) 50 55 { 51 56 AssertPtr(pProvider); … … 53 58 HRESULT hr; 54 59 55 const ULONG cFixedFormats = 3; /* CFSTR_FILEDESCRIPTORA + CFSTR_FILEDESCRIPTORW + CFSTR_FILECONTENTS */ 60 ULONG cFixedFormats = 2; /* CFSTR_FILEDESCRIPTORA + CFSTR_FILECONTENTS */ 61 #ifdef VBOX_CLIPBOARD_WITH_UNICODE_SUPPORT 62 cFixedFormats++; /* CFSTR_FILEDESCRIPTORW */ 63 #endif 56 64 const ULONG cAllFormats = cFormats + cFixedFormats; 57 65 … … 69 77 */ 70 78 71 /* IStream interface, implemented in ClipboardStreamImpl-win.cpp. */79 LogFlowFunc(("Registering CFSTR_FILEDESCRIPTORA ...\n")); 72 80 registerFormat(&m_pFormatEtc[FormatIndex_FileDescriptorA], 73 81 RegisterClipboardFormat(CFSTR_FILEDESCRIPTORA)); 82 #ifdef VBOX_CLIPBOARD_WITH_UNICODE_SUPPORT 83 LogFlowFunc(("Registering CFSTR_FILEDESCRIPTORW ...\n")); 74 84 registerFormat(&m_pFormatEtc[FormatIndex_FileDescriptorW], 75 85 RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW)); 86 #endif 87 /* IStream interface, implemented in ClipboardStreamImpl-win.cpp. */ 88 LogFlowFunc(("Registering CFSTR_FILECONTENTS ...\n")); 76 89 registerFormat(&m_pFormatEtc[FormatIndex_FileContents], 77 90 RegisterClipboardFormat(CFSTR_FILECONTENTS), … … 171 184 } 172 185 186 /** 187 * Copies a chunk of data into a HGLOBAL object. 188 * 189 * @returns VBox status code. 190 * @param pvData Data to copy. 191 * @param cbData Size (in bytes) to copy. 192 * @param fFlags GlobalAlloc flags, used for allocating the HGLOBAL block. 193 * @param phGlobal Where to store the allocated HGLOBAL object. 194 */ 173 195 int VBoxClipboardWinDataObject::copyToHGlobal(const void *pvData, size_t cbData, UINT fFlags, HGLOBAL *phGlobal) 174 196 { … … 194 216 } 195 217 196 int VBoxClipboardWinDataObject::createFileGroupDescriptor(const SharedClipboardURIList &URIList, 197 bool fUnicode, HGLOBAL *phGlobal) 198 { 199 // AssertReturn(URIList.GetRootCount(), VERR_INVALID_PARAMETER); 200 AssertPtrReturn(phGlobal, VERR_INVALID_POINTER); 201 202 RT_NOREF(fUnicode); 203 204 int rc; 205 206 const size_t cItems = 2; URIList.GetRootCount(); 207 const size_t cbFGD = sizeof(FILEGROUPDESCRIPTOR) + sizeof(FILEDESCRIPTOR) * (cItems - 1); 208 209 LogFunc(("cItmes=%zu\n", cItems)); 210 218 /** 219 * Creates a FILEGROUPDESCRIPTOR object from a given Shared Clipboard URI list and stores 220 * the result into an HGLOBAL object. 221 * 222 * @returns VBox status code. 223 * @param URIList URI list to create object for. 224 * @param fUnicode Whether the FILEGROUPDESCRIPTOR object shall contain Unicode data or not. 225 * @param phGlobal Where to store the allocated HGLOBAL object on success. 226 */ 227 int VBoxClipboardWinDataObject::createFileGroupDescriptorFromURIList(const SharedClipboardURIList &URIList, 228 bool fUnicode, HGLOBAL *phGlobal) 229 { 230 AssertReturn(URIList.GetRootCount(), VERR_INVALID_PARAMETER); 231 AssertPtrReturn(phGlobal, VERR_INVALID_POINTER); 232 233 LogFlowFuncEnter(); 234 235 const size_t cbFileGroupDescriptor = fUnicode ? sizeof(FILEGROUPDESCRIPTORW) : sizeof(FILEGROUPDESCRIPTORA); 236 const size_t cbFileDescriptor = fUnicode ? sizeof(FILEDESCRIPTORW) : sizeof(FILEDESCRIPTORA); 237 238 const UINT cItems = (UINT)URIList.GetRootCount(); /** @todo UINT vs. uint64_t */ 239 const size_t cbFGD = cbFileGroupDescriptor + (cbFileDescriptor * (cItems - 1)); 240 241 LogFunc(("fUnicode=%RTbool, cItems=%u, cbFileDescriptor=%zu\n", fUnicode, cItems, cbFileDescriptor)); 242 243 /* FILEGROUPDESCRIPTORA / FILEGROUPDESCRIPTOR matches except the cFileName member (TCHAR vs. WCHAR). */ 211 244 FILEGROUPDESCRIPTOR *pFGD = (FILEGROUPDESCRIPTOR *)RTMemAlloc(cbFGD); 212 if (pFGD) 213 { 214 pFGD->cItems = (UINT)cItems; 215 216 217 FILEDESCRIPTOR *pFD = &pFGD->fgd[0]; 218 RT_BZERO(pFD, sizeof(FILEDESCRIPTOR)); 219 220 RTStrPrintf(pFD->cFileName, sizeof(pFD->cFileName), "barbaz.txt\n"); 221 222 #if 1 223 pFD->dwFlags = FD_ATTRIBUTES | FD_FILESIZE | FD_PROGRESSUI; 224 pFD->dwFileAttributes = FILE_ATTRIBUTE_NORMAL; // FILE_ATTRIBUTE_DIRECTORY; 225 226 uint64_t cbSize = _1M; 227 228 pFD->nFileSizeHigh = RT_HI_U32(cbSize); 229 pFD->nFileSizeLow = RT_LO_U32(cbSize); 230 #else 231 pFD->dwFlags = FD_ATTRIBUTES | FD_CREATETIME | FD_ACCESSTIME | FD_WRITESTIME | FD_FILESIZE; 245 if (!pFGD) 246 return VERR_NO_MEMORY; 247 248 int rc = VINF_SUCCESS; 249 250 pFGD->cItems = cItems; 251 252 char *pszFileSpec = NULL; 253 254 for (UINT i = 0; i < cItems; i++) 255 { 256 FILEDESCRIPTOR *pFD = &pFGD->fgd[i]; 257 RT_BZERO(pFD, cbFileDescriptor); 258 259 const SharedClipboardURIObject *pObj = URIList.At(i); 260 AssertPtr(pObj); 261 const char *pszFile = pObj->GetSourcePathAbs().c_str(); 262 AssertPtr(pszFile); 263 264 pszFileSpec = RTStrDup(pszFile); 265 AssertBreakStmt(pszFileSpec != NULL, rc = VERR_NO_MEMORY); 266 267 if (fUnicode) 268 { 269 PRTUTF16 pwszFileSpec; 270 rc = RTStrToUtf16(pszFileSpec, &pwszFileSpec); 271 if (RT_SUCCESS(rc)) 272 { 273 rc = RTUtf16CopyEx((PRTUTF16 )pFD->cFileName, sizeof(pFD->cFileName) / sizeof(WCHAR), 274 pwszFileSpec, RTUtf16Len(pwszFileSpec)); 275 RTUtf16Free(pwszFileSpec); 276 } 277 } 278 else 279 rc = RTStrCopy(pFD->cFileName, sizeof(pFD->cFileName), pszFileSpec); 280 281 RTStrFree(pszFileSpec); 282 pszFileSpec = NULL; 283 284 if (RT_FAILURE(rc)) 285 break; 286 287 pFD->dwFlags = FD_PROGRESSUI | FD_ATTRIBUTES; 288 if (fUnicode) /** @todo Only >= Vista. */ 289 pFD->dwFlags |= FD_UNICODE; 290 pFD->dwFileAttributes = FILE_ATTRIBUTE_NORMAL; 291 292 switch (pObj->GetType()) 293 { 294 case SharedClipboardURIObject::Type_Directory: 295 pFD->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY; 296 297 LogFunc(("pszDir=%s\n", pszFile)); 298 break; 299 300 case SharedClipboardURIObject::Type_File: 301 { 302 pFD->dwFlags |= FD_FILESIZE; 303 304 const uint64_t cbObjSize = pObj->GetSize(); 305 306 pFD->nFileSizeHigh = RT_HI_U32(cbObjSize); 307 pFD->nFileSizeLow = RT_LO_U32(cbObjSize); 308 309 LogFunc(("pszFile=%s, cbObjSize=%RU64\n", pszFile, cbObjSize)); 310 break; 311 } 312 313 default: 314 AssertFailed(); 315 break; 316 } 317 #if 0 318 pFD->dwFlags = FD_ATTRIBUTES | FD_CREATETIME | FD_ACCESSTIME | FD_WRITESTIME | FD_FILESIZE; /** @todo Implement this. */ 232 319 pFD->dwFileAttributes = 233 320 pFD->ftCreationTime = 234 321 pFD->ftLastAccessTime = 235 322 pFD->ftLastWriteTime = 236 pFD->nFileSizeHigh = 237 pFD->nFileSizeLow = 238 #endif 239 240 241 242 pFD = &pFGD->fgd[1]; 243 RT_BZERO(pFD, sizeof(FILEDESCRIPTOR)); 244 245 RTStrPrintf(pFD->cFileName, sizeof(pFD->cFileName), "barbaz_dir\n"); 246 247 #if 1 248 pFD->dwFlags = FD_ATTRIBUTES | FD_PROGRESSUI; 249 pFD->dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY; 250 #else 251 pFD->dwFlags = FD_ATTRIBUTES | FD_CREATETIME | FD_ACCESSTIME | FD_WRITESTIME | FD_FILESIZE; 252 pFD->dwFileAttributes = 253 pFD->ftCreationTime = 254 pFD->ftLastAccessTime = 255 pFD->ftLastWriteTime = 256 pFD->nFileSizeHigh = 257 pFD->nFileSizeLow = 258 #endif 259 260 323 #endif 324 } 325 326 if (pszFileSpec) 327 RTStrFree(pszFileSpec); 328 329 if (RT_SUCCESS(rc)) 330 { 261 331 rc = copyToHGlobal(pFGD, cbFGD, GMEM_MOVEABLE, phGlobal); 262 332 } 263 333 else 264 rc = VERR_NO_MEMORY; 265 334 { 335 RTMemFree(pFGD); 336 } 337 338 LogFlowFuncLeaveRC(rc); 266 339 return rc; 267 340 } … … 312 385 { 313 386 case FormatIndex_FileDescriptorA: /* ANSI */ 387 #ifdef VBOX_CLIPBOARD_WITH_UNICODE_SUPPORT 388 RT_FALL_THROUGH(); 314 389 case FormatIndex_FileDescriptorW: /* Unicode */ 390 #endif 315 391 { 316 392 const bool fUnicode = lIndex == FormatIndex_FileDescriptorW; … … 319 395 320 396 SharedClipboardURIList uriList; 321 int rc = m_pProvider->ReadMetaData(uriList, 0 /* fFlags */); 322 if (RT_SUCCESS(rc)) 397 int rc = m_pProvider->ReadMetaData(uriList); /** @todo Do this asynchronously some time earlier? */ 398 399 #if 0 400 SharedClipboardURIObject *pObj1 = new SharedClipboardURIObject(SharedClipboardURIObject::Type_File, "foobar.baz1"); 401 pObj1->SetSize(_64M); 402 uriList.AppendURIObject(pObj1); 403 #endif 404 405 if ( RT_SUCCESS(rc) 406 && !uriList.IsEmpty()) 323 407 { 324 408 HGLOBAL hGlobal; 325 rc = createFileGroupDescriptor (uriList, fUnicode, &hGlobal);409 rc = createFileGroupDescriptorFromURIList(uriList, fUnicode, &hGlobal); 326 410 if (RT_SUCCESS(rc)) 327 411 { 412 LogFlowFunc(("FOO1\n")); 413 328 414 pMedium->tymed = TYMED_HGLOBAL; 329 415 pMedium->hGlobal = hGlobal; 330 416 /* Note: hGlobal now is being owned by pMedium / the caller. */ 331 417 418 LogFlowFunc(("FOO2\n")); 332 419 hr = S_OK; 333 420 } 334 421 } 422 LogFlowFunc(("FOO2.1\n")); 335 423 break; 336 424 } … … 340 428 LogFlowFunc(("FormatIndex_FileContents\n")); 341 429 430 /* Hand-in the provider so that our IStream implementation can continue working with it. */ 342 431 hr = VBoxClipboardWinStreamImpl::Create(m_pProvider, &m_pStream); 343 432 if (SUCCEEDED(hr)) 344 433 { 345 434 /* Hand over the stream to the caller. */ 346 pMedium->tymed 347 pMedium->pstm 435 pMedium->tymed = TYMED_ISTREAM; 436 pMedium->pstm = m_pStream; 348 437 } 349 438 … … 355 444 } 356 445 446 LogFlowFunc(("FOO3\n")); 447 357 448 /* Error handling; at least return some basic data. */ 358 449 if (FAILED(hr)) … … 364 455 } 365 456 457 LogFlowFunc(("FOO4\n")); 458 366 459 if (hr == DV_E_FORMATETC) 367 460 LogRel(("Clipboard: Error handling format\n")); 461 462 LogFlowFunc(("FOO5\n")); 368 463 369 464 LogFlowFunc(("hr=%Rhrc\n", hr)); … … 586 681 { 587 682 if( (pFormatEtc->tymed & m_pFormatEtc[i].tymed) 588 && pFormatEtc->cfFormat == m_pFormatEtc[i].cfFormat 589 && pFormatEtc->dwAspect == m_pFormatEtc[i].dwAspect) 683 && pFormatEtc->cfFormat == m_pFormatEtc[i].cfFormat) 684 /* Note: Do *not* compare dwAspect here, as this can be dynamic, depending on how the object should be represented. */ 685 //&& pFormatEtc->dwAspect == m_pFormatEtc[i].dwAspect) 590 686 { 591 687 LogRel3(("Clipboard: Format found: tyMed=%RI32, cfFormat=%RI16, sFormats=%s, dwAspect=%RI32, ulIndex=%RU32\n", -
trunk/src/VBox/GuestHost/SharedClipboard/ClipboardEnumFormatEtcImpl-win.cpp
r78443 r78809 92 92 if (lCount == 0) 93 93 { 94 LogFlowFunc(("Delete\n")); 94 95 delete this; 95 96 return 0; … … 123 124 && ulCopied < cFormats) 124 125 { 125 VBoxClipboardWinEnumFormatEtc::CopyFormat(&pFormatEtc[ulCopied], 126 &m_pFormatEtc[m_nIndex]); 126 VBoxClipboardWinEnumFormatEtc::CopyFormat(&pFormatEtc[ulCopied], &m_pFormatEtc[m_nIndex]); 127 127 ulCopied++; 128 128 m_nIndex++; … … 149 149 STDMETHODIMP VBoxClipboardWinEnumFormatEtc::Clone(IEnumFORMATETC **ppEnumFormatEtc) 150 150 { 151 HRESULT hResult = 152 CreateEnumFormatEtc(m_nNumFormats, m_pFormatEtc, ppEnumFormatEtc); 153 151 HRESULT hResult = CreateEnumFormatEtc(m_nNumFormats, m_pFormatEtc, ppEnumFormatEtc); 154 152 if (hResult == S_OK) 155 153 ((VBoxClipboardWinEnumFormatEtc *) *ppEnumFormatEtc)->m_nIndex = m_nIndex; -
trunk/src/VBox/GuestHost/SharedClipboard/ClipboardProvider.cpp
r78727 r78809 34 34 #include <VBox/log.h> 35 35 36 37 36 38 SharedClipboardProvider::SharedClipboardProvider(void) 37 39 : m_cRefs(0) 38 40 { 41 LogFlowFuncEnter(); 39 42 } 40 43 41 44 SharedClipboardProvider::~SharedClipboardProvider(void) 42 45 { 46 LogFlowFuncEnter(); 43 47 Assert(m_cRefs == 0); 48 } 49 50 /** 51 * Creates a Shared Clipboard provider. 52 * 53 * @returns New Shared Clipboard provider instance. 54 * @param enmSource Source type to create provider for. 55 */ 56 /* static */ 57 SharedClipboardProvider *SharedClipboardProvider::Create(SourceType enmSource) 58 { 59 SharedClipboardProvider *pProvider = NULL; 60 61 switch (enmSource) 62 { 63 #ifdef VBOX_WITH_SHARED_CLIPBOARD_GUEST 64 case SourceType_VbglR3: 65 pProvider = new SharedClipboardProviderVbglR3(); 66 break; 67 #endif 68 69 #ifdef VBOX_WITH_SHARED_CLIPBOARD_HOST 70 case SourceType_HostService: 71 pProvider = new SharedClipboardProviderHostService(); 72 break; 73 #endif 74 default: 75 AssertFailed(); 76 break; 77 } 78 79 return pProvider; 44 80 } 45 81 … … 51 87 uint32_t SharedClipboardProvider::AddRef(void) 52 88 { 89 LogFlowFuncEnter(); 53 90 return ASMAtomicIncU32(&m_cRefs); 54 91 } … … 61 98 uint32_t SharedClipboardProvider::Release(void) 62 99 { 100 LogFlowFuncEnter(); 63 101 Assert(m_cRefs); 64 102 return ASMAtomicDecU32(&m_cRefs); 65 103 } 66 104 67 int SharedClipboardProvider::SetSource(SourceType enmSource)68 {69 return m_enmSource = enmSource;70 }71 72 int SharedClipboardProvider::ReadMetaData(SharedClipboardURIList &URIList, uint32_t fFlags /* = 0 */)73 {74 int rc = VINF_SUCCESS;75 76 RT_NOREF(URIList, fFlags);77 78 return rc;79 }80 -
trunk/src/VBox/GuestHost/SharedClipboard/ClipboardStreamImpl-win.cpp
r78725 r78809 50 50 , m_pProvider(pProvider) 51 51 { 52 LogFlowThisFuncEnter(); 53 52 54 m_pProvider->AddRef(); 55 56 cbFileSize = _64M; 57 cbSizeRead = 0; 53 58 } 54 59 55 60 VBoxClipboardWinStreamImpl::~VBoxClipboardWinStreamImpl(void) 56 61 { 62 LogFlowThisFuncEnter(); 57 63 m_pProvider->Release(); 58 64 } … … 114 120 RT_NOREF(dwFrags); 115 121 116 LogFlow FuncEnter();122 LogFlowThisFuncEnter(); 117 123 return E_NOTIMPL; 118 124 } … … 123 129 RT_NOREF(pDestStream, nBytesToCopy, nBytesRead, nBytesWritten); 124 130 125 LogFlow FuncEnter();131 LogFlowThisFuncEnter(); 126 132 return E_NOTIMPL; 127 133 } … … 131 137 RT_NOREF(nStart, nBytes, dwFlags); 132 138 133 LogFlowFuncEnter(); 134 return E_NOTIMPL; 135 } 136 137 static ULONG cbFileSize = _1M; 138 static ULONG cbSizeRead = 0; 139 LogFlowThisFuncEnter(); 140 return E_NOTIMPL; 141 } 139 142 140 143 STDMETHODIMP VBoxClipboardWinStreamImpl::Read(void* pvBuffer, ULONG nBytesToRead, ULONG* nBytesRead) … … 142 145 /* If the file size is 0, already return at least 1 byte, else the whole operation will fail. */ 143 146 144 ULONG cbToRead = RT_MIN(cbFileSize - cbSizeRead, _4K /* nBytesToRead */); 145 146 if (cbToRead > nBytesToRead) 147 cbToRead = nBytesToRead; 148 149 LogFlowFunc(("pvBuffer=%p, nBytesToRead=%u -> cbSizeRead=%u, cbToRead=%u\n", pvBuffer, nBytesToRead, cbSizeRead, cbToRead)); 150 151 if (cbToRead) 152 { 153 memset(pvBuffer, cbToRead, 0x65); 154 cbSizeRead += cbToRead; 155 } 156 157 if (nBytesRead) 158 *nBytesRead = cbToRead; 159 160 if (cbSizeRead == cbFileSize) 161 cbSizeRead = 0; 162 147 size_t cbRead = 0; 148 int rc = m_pProvider->ReadData(pvBuffer, (size_t)nBytesToRead, &cbRead); 149 if (RT_SUCCESS(rc)) 150 { 151 if (*nBytesRead) 152 *nBytesRead = (ULONG)cbRead; 153 } 154 155 LogFlowThisFunc(("nBytesToRead=%u, nBytesRead=%zu\n", nBytesToRead, cbRead)); 163 156 return S_OK; 164 157 } … … 166 159 STDMETHODIMP VBoxClipboardWinStreamImpl::Revert(void) 167 160 { 168 LogFlow FuncEnter();161 LogFlowThisFuncEnter(); 169 162 return E_NOTIMPL; 170 163 } … … 174 167 RT_NOREF(nMove, dwOrigin, nNewPos); 175 168 176 LogFlow FuncEnter();169 LogFlowThisFuncEnter(); 177 170 return E_NOTIMPL; 178 171 } … … 182 175 RT_NOREF(nNewSize); 183 176 184 LogFlow FuncEnter();177 LogFlowThisFuncEnter(); 185 178 return E_NOTIMPL; 186 179 } … … 190 183 RT_NOREF(statstg, dwFlags); 191 184 192 LogFlow FuncEnter();185 LogFlowThisFuncEnter(); 193 186 return E_NOTIMPL; 194 187 } … … 198 191 RT_NOREF(nStart, nBytes, dwFlags); 199 192 200 LogFlow FuncEnter();193 LogFlowThisFuncEnter(); 201 194 return E_NOTIMPL; 202 195 } … … 206 199 RT_NOREF(pvBuffer, nBytesToRead, nBytesRead); 207 200 208 LogFlow FuncEnter();201 LogFlowThisFuncEnter(); 209 202 return E_NOTIMPL; 210 203 } … … 224 217 HRESULT VBoxClipboardWinStreamImpl::Create(SharedClipboardProvider *pProvider, IStream **ppStream) 225 218 { 219 AssertPtrReturn(pProvider, E_POINTER); 220 226 221 VBoxClipboardWinStreamImpl *pStream = new VBoxClipboardWinStreamImpl(pProvider); 227 222 if (pStream) -
trunk/src/VBox/GuestHost/SharedClipboard/ClipboardURIList.cpp
r78648 r78809 46 46 } 47 47 48 int SharedClipboardURIList::a ddEntry(const char *pcszSource, const char *pcszTarget, SHAREDCLIPBOARDURILISTFLAGS fFlags)48 int SharedClipboardURIList::appendEntry(const char *pcszSource, const char *pcszTarget, SHAREDCLIPBOARDURILISTFLAGS fFlags) 49 49 { 50 50 AssertPtrReturn(pcszSource, VERR_INVALID_POINTER); … … 57 57 if (RT_SUCCESS(rc)) 58 58 { 59 if (RTFS_IS_FILE(objInfo.Attr.fMode)) 60 { 61 LogFlowFunc(("File '%s' -> '%s' (%RU64 bytes, file mode 0x%x)\n", 62 pcszSource, pcszTarget, (uint64_t)objInfo.cbObject, objInfo.Attr.fMode)); 63 64 SharedClipboardURIObject *pObjFile = new SharedClipboardURIObject(SharedClipboardURIObject::Type_File, 65 pcszSource, pcszTarget); 66 if (pObjFile) 67 { 68 /** @todo Add a standard fOpen mode for this list. */ 69 rc = pObjFile->Open(SharedClipboardURIObject::View_Source, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE); 70 if (RT_SUCCESS(rc)) 71 { 72 m_lstTree.append(pObjFile); 73 59 try 60 { 61 if (RTFS_IS_FILE(objInfo.Attr.fMode)) 62 { 63 LogFlowFunc(("File '%s' -> '%s' (%RU64 bytes, file mode 0x%x)\n", 64 pcszSource, pcszTarget, (uint64_t)objInfo.cbObject, objInfo.Attr.fMode)); 65 66 SharedClipboardURIObject *pObjFile = new SharedClipboardURIObject(SharedClipboardURIObject::Type_File, 67 pcszSource, pcszTarget); 68 if (pObjFile) 69 { 70 /** @todo Add a standard fOpen mode for this list. */ 71 rc = pObjFile->Open(SharedClipboardURIObject::View_Source, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE); 72 if (RT_SUCCESS(rc)) 73 { 74 rc = appendObject(pObjFile); 75 if (!(fFlags & SHAREDCLIPBOARDURILIST_FLAGS_KEEP_OPEN)) /* Shall we keep the file open while being added to this list? */ 76 pObjFile->Close(); 77 } 78 else 79 delete pObjFile; 80 } 81 else 82 rc = VERR_NO_MEMORY; 83 } 84 else if (RTFS_IS_DIRECTORY(objInfo.Attr.fMode)) 85 { 86 LogFlowFunc(("Directory '%s' -> '%s' (file mode 0x%x)\n", pcszSource, pcszTarget, objInfo.Attr.fMode)); 87 88 SharedClipboardURIObject *pObjDir = new SharedClipboardURIObject(SharedClipboardURIObject::Type_Directory, 89 pcszSource, pcszTarget); 90 if (pObjDir) 91 { 92 m_lstTree.append(pObjDir); 93 94 /** @todo Add SHAREDCLIPBOARDURILIST_FLAGS_KEEP_OPEN handling? */ 74 95 m_cTotal++; 75 m_cbTotal += pObjFile->GetSize();76 77 if (!(fFlags & SHAREDCLIPBOARDURILIST_FLAGS_KEEP_OPEN)) /* Shall we keep the file open while being added to this list? */78 pObjFile->Close();79 96 } 80 97 else 81 delete pObjFile; 82 } 98 rc = VERR_NO_MEMORY; 99 } 100 /* Note: Symlinks already should have been resolved at this point. */ 83 101 else 84 rc = VERR_NO_MEMORY; 85 } 86 else if (RTFS_IS_DIRECTORY(objInfo.Attr.fMode)) 87 { 88 LogFlowFunc(("Directory '%s' -> '%s' (file mode 0x%x)\n", pcszSource, pcszTarget, objInfo.Attr.fMode)); 89 90 SharedClipboardURIObject *pObjDir = new SharedClipboardURIObject(SharedClipboardURIObject::Type_Directory, 91 pcszSource, pcszTarget); 92 if (pObjDir) 93 { 94 m_lstTree.append(pObjDir); 95 96 /** @todo Add SHAREDCLIPBOARDURILIST_FLAGS_KEEP_OPEN handling? */ 97 m_cTotal++; 98 } 99 else 100 rc = VERR_NO_MEMORY; 101 } 102 /* Note: Symlinks already should have been resolved at this point. */ 103 else 104 rc = VERR_NOT_SUPPORTED; 102 rc = VERR_NOT_SUPPORTED; 103 } 104 catch (std::bad_alloc &) 105 { 106 rc = VERR_NO_MEMORY; 107 } 105 108 } 106 109 … … 126 129 if (RTFS_IS_DIRECTORY(objInfo.Attr.fMode)) 127 130 { 128 rc = a ddEntry(pcszSrcPath, &pcszDstPath[cchDstBase], fFlags);131 rc = appendEntry(pcszSrcPath, &pcszDstPath[cchDstBase], fFlags); 129 132 if (RT_SUCCESS(rc)) 130 133 { … … 181 184 if (pszDst) 182 185 { 183 rc = a ddEntry(pszSrc, &pszDst[cchDstBase], fFlags);186 rc = appendEntry(pszSrc, &pszDst[cchDstBase], fFlags); 184 187 RTStrFree(pszDst); 185 188 } … … 210 213 { 211 214 LogFlowFunc(("Directory entry is symlink to file\n")); 212 rc = a ddEntry(pszSrc, &pcszDstPath[cchDstBase], fFlags);215 rc = appendEntry(pszSrc, &pcszDstPath[cchDstBase], fFlags); 213 216 } 214 217 else … … 237 240 else if (RTFS_IS_FILE(objInfo.Attr.fMode)) 238 241 { 239 rc = a ddEntry(pcszSrcPath, &pcszDstPath[cchDstBase], fFlags);242 rc = appendEntry(pcszSrcPath, &pcszDstPath[cchDstBase], fFlags); 240 243 } 241 244 else if (RTFS_IS_SYMLINK(objInfo.Attr.fMode)) … … 257 260 { 258 261 LogFlowFunc(("Symlink to file\n")); 259 rc = a ddEntry(pszSrc, &pcszDstPath[cchDstBase], fFlags);262 rc = appendEntry(pszSrc, &pcszDstPath[cchDstBase], fFlags); 260 263 } 261 264 else … … 277 280 } 278 281 282 int SharedClipboardURIList::appendObject(SharedClipboardURIObject *pObject) 283 { 284 int rc; 285 286 try 287 { 288 m_lstTree.append(pObject); 289 m_lstRoot.append(pObject->GetSourcePathAbs());; 290 291 m_cTotal++; 292 m_cbTotal += pObject->GetSize(); 293 294 rc = VINF_SUCCESS; 295 } 296 catch (std::bad_alloc &) 297 { 298 rc = VERR_NO_MEMORY; 299 } 300 301 LogFlowFuncLeaveRC(rc); 302 return rc; 303 } 304 279 305 int SharedClipboardURIList::AppendNativePath(const char *pszPath, SHAREDCLIPBOARDURILISTFLAGS fFlags) 280 306 { … … 331 357 LogFlowFuncLeaveRC(rc); 332 358 return rc; 359 } 360 361 int SharedClipboardURIList::AppendURIObject(SharedClipboardURIObject *pObject) 362 { 363 AssertPtrReturn(pObject, VERR_INVALID_POINTER); 364 365 return appendObject(pObject); 333 366 } 334 367 … … 386 419 : pszFileName - pszSrcPath; 387 420 char *pszDstPath = &pszSrcPath[cchDstBase]; 388 m_lstRoot.append(pszDstPath); 389 390 LogFlowFunc(("pszSrcPath=%s, pszFileName=%s, pszRoot=%s\n", 391 pszSrcPath, pszFileName, pszDstPath)); 392 393 rc = appendPathRecursive(pszSrcPath, pszSrcPath, pszSrcPath, cchDstBase, fFlags); 421 422 try 423 { 424 m_lstRoot.append(pszDstPath); 425 426 LogFlowFunc(("pszSrcPath=%s, pszFileName=%s, pszRoot=%s\n", pszSrcPath, pszFileName, pszDstPath)); 427 rc = appendPathRecursive(pszSrcPath, pszSrcPath, pszSrcPath, cchDstBase, fFlags); 428 } 429 catch (std::bad_alloc &) 430 { 431 rc = VERR_NO_MEMORY; 432 } 394 433 } 395 434 else … … 437 476 void SharedClipboardURIList::Clear(void) 438 477 { 478 LogFlowThisFuncEnter(); 479 439 480 m_lstRoot.clear(); 440 481 … … 443 484 SharedClipboardURIObject *pCurObj = m_lstTree.at(i); 444 485 AssertPtr(pCurObj); 445 RTMemFree(pCurObj); 446 } 486 delete pCurObj; 487 } 488 447 489 m_lstTree.clear(); 448 490 449 491 m_cTotal = 0; 450 492 m_cbTotal = 0; 493 494 LogFlowThisFuncLeave(); 451 495 } 452 496 … … 464 508 465 509 pCurObj->Close(); 466 RTMemFree(pCurObj);510 delete pCurObj; 467 511 468 512 m_lstTree.removeFirst(); … … 499 543 if (RT_SUCCESS(rc)) 500 544 { 501 m_lstRoot.append(pszFilePath); 502 m_cTotal++; 545 try 546 { 547 m_lstRoot.append(pszFilePath); 548 m_cTotal++; 549 } 550 catch (std::bad_alloc &) 551 { 552 rc = VERR_NO_MEMORY; 553 } 503 554 } 504 555 -
trunk/src/VBox/GuestHost/SharedClipboard/ClipboardURIObject.cpp
r78390 r78809 86 86 case Type_File: 87 87 { 88 RTFileClose(u.File.hFile); 89 u.File.hFile = NIL_RTFILE; 88 if (RTFileIsValid(u.File.hFile)) 89 { 90 RTFileClose(u.File.hFile); 91 u.File.hFile = NIL_RTFILE; 92 } 90 93 RT_ZERO(u.File.objInfo); 91 94 break; … … 94 97 case Type_Directory: 95 98 { 96 RTDirClose(u.Dir.hDir); 97 u.Dir.hDir = NIL_RTDIR; 99 if (RTDirIsValid(u.Dir.hDir)) 100 { 101 RTDirClose(u.Dir.hDir); 102 u.Dir.hDir = NIL_RTDIR; 103 } 98 104 RT_ZERO(u.Dir.objInfo); 99 105 break; -
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-win.cpp
r78581 r78809 743 743 return rc; 744 744 } 745 746 /** 747 * Initializes a Windows-specific URI clipboard information struct. 748 * 749 * @returns VBox status code. 750 * @param pURI URI clipboard information struct to initialize. 751 * @param enmType What type of clipboard provider to use. 752 */ 753 int VBoxClipboardWinURIInit(PVBOXCLIPBOARDWINURI pURI, SharedClipboardProvider::SourceType enmType) 754 { 755 LogFlowFuncEnter(); 756 757 pURI->Transfer.pProvider = SharedClipboardProvider::Create(enmType); 758 if (!pURI->Transfer.pProvider) 759 return VERR_NO_MEMORY; 760 761 VBoxClipboardWinURIReset(pURI); 762 763 return VINF_SUCCESS; 764 } 765 766 /** 767 * Destroys a Windows-specific URI clipboard information struct. 768 * 769 * @param pURI URI clipboard information struct to destroy. 770 */ 771 void VBoxClipboardWinURIDestroy(PVBOXCLIPBOARDWINURI pURI) 772 { 773 LogFlowFuncEnter(); 774 775 if (pURI->Transfer.pProvider) 776 { 777 delete pURI->Transfer.pProvider; 778 pURI->Transfer.pProvider = NULL; 779 } 780 } 781 782 /** 783 * Resets a Windows-specific URI clipboard information struct. 784 * 785 * @param pURI URI clipboard information struct to reset. 786 */ 787 void VBoxClipboardWinURIReset(PVBOXCLIPBOARDWINURI pURI) 788 { 789 LogFlowFuncEnter(); 790 791 pURI->cTransfers = 0; 792 793 if (pURI->Transfer.pProvider) 794 pURI->Transfer.pProvider->Reset(); 795 } 745 796 #endif /* VBOX_WITH_SHARED_CLIPBOARD_URI_LIST */ 746 797
Note:
See TracChangeset
for help on using the changeset viewer.