Reads selected paths
| 146 | |
| 147 | /// Reads selected paths |
| 148 | HRESULT CWinMergeShell::Initialize(LPCITEMIDLIST pidlFolder, |
| 149 | LPDATAOBJECT pDataObj, HKEY hProgID) |
| 150 | { |
| 151 | HRESULT hr = E_INVALIDARG; |
| 152 | |
| 153 | std::vector<std::wstring> paths; |
| 154 | |
| 155 | // Files/folders selected normally from the explorer |
| 156 | if (pDataObj) |
| 157 | { |
| 158 | FORMATETC fmt = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; |
| 159 | STGMEDIUM stg = {TYMED_HGLOBAL}; |
| 160 | HDROP hDropInfo; |
| 161 | |
| 162 | // Look for CF_HDROP data in the data object. |
| 163 | if (FAILED(pDataObj->GetData(&fmt, &stg))) |
| 164 | // Nope! Return an "invalid argument" error back to Explorer. |
| 165 | return E_INVALIDARG; |
| 166 | |
| 167 | // Get a pointer to the actual data. |
| 168 | hDropInfo = (HDROP) GlobalLock(stg.hGlobal); |
| 169 | |
| 170 | // Make sure it worked. |
| 171 | if (NULL == hDropInfo) |
| 172 | return E_INVALIDARG; |
| 173 | |
| 174 | // Sanity check & make sure there is at least one filename. |
| 175 | UINT uNumFilesDropped = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0); |
| 176 | |
| 177 | if (uNumFilesDropped == 0) |
| 178 | { |
| 179 | GlobalUnlock(stg.hGlobal); |
| 180 | ReleaseStgMedium(&stg); |
| 181 | return E_INVALIDARG; |
| 182 | } |
| 183 | |
| 184 | hr = S_OK; |
| 185 | |
| 186 | /// Max. filecount to select |
| 187 | constexpr unsigned MaxFileCount = 3u; |
| 188 | |
| 189 | // Get all file names. |
| 190 | for (UINT x = 0 ; x < (std::min)(MaxFileCount + 1, uNumFilesDropped); x++) |
| 191 | { |
| 192 | // Get the number of bytes required by the file's full pathname |
| 193 | UINT wPathnameSize = DragQueryFile(hDropInfo, x, NULL, 0); |
| 194 | |
| 195 | // Allocate memory to contain full pathname & zero byte |
| 196 | wPathnameSize += 1; |
| 197 | LPTSTR npszFile = (TCHAR *) new TCHAR[wPathnameSize]; |
| 198 | |
| 199 | // If not enough memory, skip this one |
| 200 | if (npszFile == NULL) |
| 201 | continue; |
| 202 | |
| 203 | // Copy the pathname into the buffer |
| 204 | DragQueryFile(hDropInfo, x, npszFile, wPathnameSize); |
| 205 |
nothing calls this directly
no test coverage detected