///////////////////////////////////////////////////////////////////// IDataObject /////////////////////////////////////////////////////////////////////
| 99 | // IDataObject |
| 100 | ////////////////////////////////////////////////////////////////////////// |
| 101 | STDMETHODIMP GitDataObject::GetData(FORMATETC* pformatetcIn, STGMEDIUM* pmedium) |
| 102 | { |
| 103 | if (!pformatetcIn) |
| 104 | return E_INVALIDARG; |
| 105 | if (!pmedium) |
| 106 | return E_POINTER; |
| 107 | pmedium->hGlobal = nullptr; |
| 108 | |
| 109 | if ((pformatetcIn->tymed & TYMED_ISTREAM) && (pformatetcIn->dwAspect == DVASPECT_CONTENT) && (pformatetcIn->cfFormat == CF_FILECONTENTS)) |
| 110 | { |
| 111 | // supports the IStream format. |
| 112 | // The lindex param is the index of the file to return |
| 113 | CString filepath; |
| 114 | IStream* pIStream = nullptr; |
| 115 | |
| 116 | // Note: we don't get called for directories since those are simply created and don't |
| 117 | // need to be fetched. |
| 118 | |
| 119 | // Note2: It would be really nice if we could get a stream from the subversion library |
| 120 | // from where we could read the file contents. But the Subversion lib is not implemented |
| 121 | // to *read* from a remote stream but so that the library *writes* to a stream we pass. |
| 122 | // Since we can't get such a read stream, we have to fetch the file in whole first to |
| 123 | // a temp location and then pass the shell an IStream for that temp file. |
| 124 | |
| 125 | if (m_revision.IsEmpty()) |
| 126 | { |
| 127 | if (pformatetcIn->lindex >= 0 && pformatetcIn->lindex < static_cast<LONG>(m_allPaths.size())) |
| 128 | filepath = g_Git.CombinePath(m_allPaths[pformatetcIn->lindex]); |
| 129 | } |
| 130 | else |
| 131 | { |
| 132 | filepath = CTempFiles::Instance().GetTempFilePath(true).GetWinPathString(); |
| 133 | if (pformatetcIn->lindex >= 0 && pformatetcIn->lindex < static_cast<LONG>(m_allPaths.size())) |
| 134 | { |
| 135 | if (g_Git.GetOneFile(m_revision.ToString(), m_allPaths[pformatetcIn->lindex], filepath)) |
| 136 | { |
| 137 | DeleteFile(filepath); |
| 138 | return STG_E_ACCESSDENIED; |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | HRESULT res = SHCreateStreamOnFileEx(filepath, STGM_READ, FILE_ATTRIBUTE_NORMAL, FALSE, nullptr, &pIStream); |
| 144 | if (res == S_OK) |
| 145 | { |
| 146 | // http://blogs.msdn.com/b/oldnewthing/archive/2014/09/18/10558763.aspx |
| 147 | LARGE_INTEGER liZero = { 0, 0 }; |
| 148 | pIStream->Seek(liZero, STREAM_SEEK_END, nullptr); |
| 149 | |
| 150 | pmedium->pstm = pIStream; |
| 151 | pmedium->tymed = TYMED_ISTREAM; |
| 152 | return S_OK; |
| 153 | } |
| 154 | return res; |
| 155 | } |
| 156 | else if ((pformatetcIn->tymed & TYMED_HGLOBAL) && (pformatetcIn->dwAspect == DVASPECT_CONTENT) && (pformatetcIn->cfFormat == CF_FILEDESCRIPTOR)) |
| 157 | { |
| 158 | for (int i = 0; i < m_gitPaths.GetCount(); ++i) |
no test coverage detected