michael@0: // ArchiveOpenCallback.cpp michael@0: michael@0: #include "StdAfx.h" michael@0: michael@0: #include "ArchiveOpenCallback.h" michael@0: michael@0: #include "Common/StringConvert.h" michael@0: #include "Windows/PropVariant.h" michael@0: michael@0: #include "../../Common/FileStreams.h" michael@0: michael@0: using namespace NWindows; michael@0: michael@0: STDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes) michael@0: { michael@0: return Callback->SetTotal(files, bytes); michael@0: } michael@0: michael@0: STDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes) michael@0: { michael@0: return Callback->SetTotal(files, bytes); michael@0: } michael@0: michael@0: STDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value) michael@0: { michael@0: NCOM::CPropVariant propVariant; michael@0: if (_subArchiveMode) michael@0: { michael@0: switch(propID) michael@0: { michael@0: case kpidName: michael@0: propVariant = _subArchiveName; michael@0: break; michael@0: } michael@0: propVariant.Detach(value); michael@0: return S_OK; michael@0: } michael@0: switch(propID) michael@0: { michael@0: case kpidName: michael@0: propVariant = _fileInfo.Name; michael@0: break; michael@0: case kpidIsFolder: michael@0: propVariant = _fileInfo.IsDirectory(); michael@0: break; michael@0: case kpidSize: michael@0: propVariant = _fileInfo.Size; michael@0: break; michael@0: case kpidAttributes: michael@0: propVariant = (UInt32)_fileInfo.Attributes; michael@0: break; michael@0: case kpidLastAccessTime: michael@0: propVariant = _fileInfo.LastAccessTime; michael@0: break; michael@0: case kpidCreationTime: michael@0: propVariant = _fileInfo.CreationTime; michael@0: break; michael@0: case kpidLastWriteTime: michael@0: propVariant = _fileInfo.LastWriteTime; michael@0: break; michael@0: } michael@0: propVariant.Detach(value); michael@0: return S_OK; michael@0: } michael@0: michael@0: int COpenCallbackImp::FindName(const UString &name) michael@0: { michael@0: for (int i = 0; i < FileNames.Size(); i++) michael@0: if (name.CompareNoCase(FileNames[i]) == 0) michael@0: return i; michael@0: return -1; michael@0: } michael@0: michael@0: struct CInFileStreamVol: public CInFileStream michael@0: { michael@0: UString Name; michael@0: COpenCallbackImp *OpenCallbackImp; michael@0: CMyComPtr OpenCallbackRef; michael@0: ~CInFileStreamVol() michael@0: { michael@0: int index = OpenCallbackImp->FindName(Name); michael@0: if (index >= 0) michael@0: OpenCallbackImp->FileNames.Delete(index); michael@0: } michael@0: }; michael@0: michael@0: STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, michael@0: IInStream **inStream) michael@0: { michael@0: if (_subArchiveMode) michael@0: return S_FALSE; michael@0: RINOK(Callback->CheckBreak()); michael@0: *inStream = NULL; michael@0: UString fullPath = _folderPrefix + name; michael@0: if (!NFile::NFind::FindFile(fullPath, _fileInfo)) michael@0: return S_FALSE; michael@0: if (_fileInfo.IsDirectory()) michael@0: return S_FALSE; michael@0: CInFileStreamVol *inFile = new CInFileStreamVol; michael@0: CMyComPtr inStreamTemp = inFile; michael@0: if (!inFile->Open(fullPath)) michael@0: return ::GetLastError(); michael@0: *inStream = inStreamTemp.Detach(); michael@0: inFile->Name = name; michael@0: inFile->OpenCallbackImp = this; michael@0: inFile->OpenCallbackRef = this; michael@0: FileNames.Add(name); michael@0: return S_OK; michael@0: } michael@0: michael@0: #ifndef _NO_CRYPTO michael@0: STDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password) michael@0: { michael@0: return Callback->CryptoGetTextPassword(password); michael@0: } michael@0: #endif michael@0: