Unzip a zip file to the specified folder.
| 192 | // Unzip a zip file to the specified folder. |
| 193 | // |
| 194 | HRESULT UnzipToFolder(PCWSTR pszZipFile, PCWSTR pszDestFolder) |
| 195 | { |
| 196 | CComScopedInit comInit; |
| 197 | |
| 198 | HRESULT hr; |
| 199 | |
| 200 | CComPtr<IShellDispatch> spISD; |
| 201 | hr = spISD.CoCreateInstance(CLSID_Shell); |
| 202 | if (FAILED(hr)) |
| 203 | return hr; |
| 204 | |
| 205 | CComVariant vtZipFile(pszZipFile); |
| 206 | CComPtr<Folder> spZipFile; |
| 207 | hr = spISD->NameSpace(vtZipFile, &spZipFile); |
| 208 | if (FAILED(hr)) |
| 209 | return hr; |
| 210 | |
| 211 | CComVariant vtDestFolder(pszDestFolder); |
| 212 | CComPtr<Folder> spDestination; |
| 213 | hr = spISD->NameSpace(vtDestFolder, &spDestination); |
| 214 | if (FAILED(hr)) |
| 215 | return hr; |
| 216 | if (!spDestination) |
| 217 | return E_POINTER; |
| 218 | |
| 219 | CComPtr<FolderItems> spFilesInside; |
| 220 | hr = spZipFile->Items(&spFilesInside); |
| 221 | if (FAILED(hr)) |
| 222 | return hr; |
| 223 | |
| 224 | CComPtr<IDispatch> spDispItem; |
| 225 | hr = spFilesInside.QueryInterface(&spDispItem); |
| 226 | if (FAILED(hr)) |
| 227 | return hr; |
| 228 | |
| 229 | CComVariant vtItem(spDispItem); |
| 230 | CComVariant vtOptions(FOF_NO_UI); |
| 231 | hr = spDestination->CopyHere(vtItem, vtOptions); |
| 232 | if (FAILED(hr)) |
| 233 | return hr; |
| 234 | |
| 235 | return S_OK; |
| 236 | } |