- 時間撮記:
- 2015-4-24 下午01:52:33 (10 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/GuestHost/DragAndDrop/DnDURIList.cpp
r50830 r55422 5 5 6 6 /* 7 * Copyright (C) 2014 Oracle Corporation7 * Copyright (C) 2014-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 33 33 34 34 #include <VBox/GuestHost/DragAndDrop.h> 35 36 DnDURIObject::DnDURIObject(Type type,37 const RTCString &strSrcPath,38 const RTCString &strDstPath,39 uint32_t fMode, uint64_t cbSize)40 : m_Type(type)41 , m_strSrcPath(strSrcPath)42 , m_strDstPath(strDstPath)43 , m_fMode(fMode)44 , m_cbSize(cbSize)45 , m_cbProcessed(0)46 {47 RT_ZERO(u);48 }49 50 DnDURIObject::~DnDURIObject(void)51 {52 closeInternal();53 }54 55 void DnDURIObject::closeInternal(void)56 {57 if (m_Type == File)58 {59 if (u.m_hFile)60 {61 RTFileClose(u.m_hFile);62 u.m_hFile = NULL;63 }64 }65 }66 67 bool DnDURIObject::IsComplete(void) const68 {69 bool fComplete = false;70 71 Assert(m_cbProcessed <= m_cbSize);72 if (m_cbProcessed == m_cbSize)73 fComplete = true;74 75 switch (m_Type)76 {77 case File:78 if (!fComplete)79 fComplete = !u.m_hFile;80 break;81 82 case Directory:83 fComplete = true;84 break;85 86 default:87 break;88 }89 90 return fComplete;91 }92 93 /* static */94 /** @todo Put this into an own class like DnDURIPath : public RTCString? */95 int DnDURIObject::RebaseURIPath(RTCString &strPath,96 const RTCString &strBaseOld,97 const RTCString &strBaseNew)98 {99 int rc;100 const char *pszPath = RTUriPath(strPath.c_str());101 if (pszPath)102 {103 const char *pszPathStart = pszPath;104 const char *pszBaseOld = strBaseOld.c_str();105 if ( pszBaseOld106 && RTPathStartsWith(pszPath, pszBaseOld))107 {108 pszPathStart += strlen(pszBaseOld);109 }110 111 rc = VINF_SUCCESS;112 113 if (RT_SUCCESS(rc))114 {115 char *pszPathNew = RTPathJoinA(strBaseNew.c_str(), pszPathStart);116 if (pszPathNew)117 {118 char *pszPathURI = RTUriCreate("file" /* pszScheme */, "/" /* pszAuthority */,119 pszPathNew /* pszPath */,120 NULL /* pszQuery */, NULL /* pszFragment */);121 if (pszPathURI)122 {123 #ifdef DEBUG_andy124 LogFlowFunc(("Rebasing \"%s\" to \"%s\"", strPath.c_str(), pszPathURI));125 #endif126 strPath = RTCString(pszPathURI) + "\r\n";127 RTStrFree(pszPathURI);128 129 rc = VINF_SUCCESS;130 }131 else132 rc = VERR_INVALID_PARAMETER;133 134 RTStrFree(pszPathNew);135 }136 else137 rc = VERR_NO_MEMORY;138 }139 }140 else141 rc = VERR_INVALID_PARAMETER;142 143 #ifdef DEBUG_andy144 LogFlowFuncLeaveRC(rc);145 #endif146 return rc;147 }148 149 int DnDURIObject::Read(void *pvBuf, uint32_t cbToRead, uint32_t *pcbRead)150 {151 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);152 AssertReturn(cbToRead, VERR_INVALID_PARAMETER);153 /* pcbRead is optional. */154 155 int rc;156 switch (m_Type)157 {158 case File:159 {160 if (!u.m_hFile)161 {162 /* Open files on the source with RTFILE_O_DENY_WRITE to prevent races163 * where the OS writes to the file while the destination side transfers164 * it over. */165 rc = RTFileOpen(&u.m_hFile, m_strSrcPath.c_str(),166 RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);167 }168 else169 rc = VINF_SUCCESS;170 171 bool fDone = false;172 if (RT_SUCCESS(rc))173 {174 size_t cbRead;175 rc = RTFileRead(u.m_hFile, pvBuf, cbToRead, &cbRead);176 if (RT_SUCCESS(rc))177 {178 if (pcbRead)179 *pcbRead = (uint32_t)cbRead;180 181 m_cbProcessed += cbRead;182 Assert(m_cbProcessed <= m_cbSize);183 184 /* End of file reached or error occurred? */185 if ( m_cbProcessed == m_cbSize186 || RT_FAILURE(rc))187 {188 closeInternal();189 }190 }191 }192 193 break;194 }195 196 case Directory:197 {198 rc = VINF_SUCCESS;199 break;200 }201 202 default:203 rc = VERR_NOT_IMPLEMENTED;204 break;205 }206 207 LogFlowFunc(("Returning strSourcePath=%s, rc=%Rrc\n",208 m_strSrcPath.c_str(), rc));209 return rc;210 }211 212 /*** */213 35 214 36 DnDURIList::DnDURIList(void) … … 439 261 pszFilePath, pszFileName, pszRoot)); 440 262 #endif 441 rc = appendPathRecursive(pszFilePath, cbBase, 442 fFlags); 263 rc = appendPathRecursive(pszFilePath, cbBase, fFlags); 443 264 } 444 265 else … … 496 317 void DnDURIList::RemoveFirst(void) 497 318 { 319 if (m_lstTree.isEmpty()) 320 return; 321 498 322 DnDURIObject &curPath = m_lstTree.first(); 499 323
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器