Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | // ArchiveOpenCallback.cpp |
michael@0 | 2 | |
michael@0 | 3 | #include "StdAfx.h" |
michael@0 | 4 | |
michael@0 | 5 | #include "ArchiveOpenCallback.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "Common/StringConvert.h" |
michael@0 | 8 | #include "Windows/PropVariant.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "../../Common/FileStreams.h" |
michael@0 | 11 | |
michael@0 | 12 | using namespace NWindows; |
michael@0 | 13 | |
michael@0 | 14 | STDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes) |
michael@0 | 15 | { |
michael@0 | 16 | return Callback->SetTotal(files, bytes); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | STDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes) |
michael@0 | 20 | { |
michael@0 | 21 | return Callback->SetTotal(files, bytes); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | STDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value) |
michael@0 | 25 | { |
michael@0 | 26 | NCOM::CPropVariant propVariant; |
michael@0 | 27 | if (_subArchiveMode) |
michael@0 | 28 | { |
michael@0 | 29 | switch(propID) |
michael@0 | 30 | { |
michael@0 | 31 | case kpidName: |
michael@0 | 32 | propVariant = _subArchiveName; |
michael@0 | 33 | break; |
michael@0 | 34 | } |
michael@0 | 35 | propVariant.Detach(value); |
michael@0 | 36 | return S_OK; |
michael@0 | 37 | } |
michael@0 | 38 | switch(propID) |
michael@0 | 39 | { |
michael@0 | 40 | case kpidName: |
michael@0 | 41 | propVariant = _fileInfo.Name; |
michael@0 | 42 | break; |
michael@0 | 43 | case kpidIsFolder: |
michael@0 | 44 | propVariant = _fileInfo.IsDirectory(); |
michael@0 | 45 | break; |
michael@0 | 46 | case kpidSize: |
michael@0 | 47 | propVariant = _fileInfo.Size; |
michael@0 | 48 | break; |
michael@0 | 49 | case kpidAttributes: |
michael@0 | 50 | propVariant = (UInt32)_fileInfo.Attributes; |
michael@0 | 51 | break; |
michael@0 | 52 | case kpidLastAccessTime: |
michael@0 | 53 | propVariant = _fileInfo.LastAccessTime; |
michael@0 | 54 | break; |
michael@0 | 55 | case kpidCreationTime: |
michael@0 | 56 | propVariant = _fileInfo.CreationTime; |
michael@0 | 57 | break; |
michael@0 | 58 | case kpidLastWriteTime: |
michael@0 | 59 | propVariant = _fileInfo.LastWriteTime; |
michael@0 | 60 | break; |
michael@0 | 61 | } |
michael@0 | 62 | propVariant.Detach(value); |
michael@0 | 63 | return S_OK; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | int COpenCallbackImp::FindName(const UString &name) |
michael@0 | 67 | { |
michael@0 | 68 | for (int i = 0; i < FileNames.Size(); i++) |
michael@0 | 69 | if (name.CompareNoCase(FileNames[i]) == 0) |
michael@0 | 70 | return i; |
michael@0 | 71 | return -1; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | struct CInFileStreamVol: public CInFileStream |
michael@0 | 75 | { |
michael@0 | 76 | UString Name; |
michael@0 | 77 | COpenCallbackImp *OpenCallbackImp; |
michael@0 | 78 | CMyComPtr<IArchiveOpenCallback> OpenCallbackRef; |
michael@0 | 79 | ~CInFileStreamVol() |
michael@0 | 80 | { |
michael@0 | 81 | int index = OpenCallbackImp->FindName(Name); |
michael@0 | 82 | if (index >= 0) |
michael@0 | 83 | OpenCallbackImp->FileNames.Delete(index); |
michael@0 | 84 | } |
michael@0 | 85 | }; |
michael@0 | 86 | |
michael@0 | 87 | STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, |
michael@0 | 88 | IInStream **inStream) |
michael@0 | 89 | { |
michael@0 | 90 | if (_subArchiveMode) |
michael@0 | 91 | return S_FALSE; |
michael@0 | 92 | RINOK(Callback->CheckBreak()); |
michael@0 | 93 | *inStream = NULL; |
michael@0 | 94 | UString fullPath = _folderPrefix + name; |
michael@0 | 95 | if (!NFile::NFind::FindFile(fullPath, _fileInfo)) |
michael@0 | 96 | return S_FALSE; |
michael@0 | 97 | if (_fileInfo.IsDirectory()) |
michael@0 | 98 | return S_FALSE; |
michael@0 | 99 | CInFileStreamVol *inFile = new CInFileStreamVol; |
michael@0 | 100 | CMyComPtr<IInStream> inStreamTemp = inFile; |
michael@0 | 101 | if (!inFile->Open(fullPath)) |
michael@0 | 102 | return ::GetLastError(); |
michael@0 | 103 | *inStream = inStreamTemp.Detach(); |
michael@0 | 104 | inFile->Name = name; |
michael@0 | 105 | inFile->OpenCallbackImp = this; |
michael@0 | 106 | inFile->OpenCallbackRef = this; |
michael@0 | 107 | FileNames.Add(name); |
michael@0 | 108 | return S_OK; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | #ifndef _NO_CRYPTO |
michael@0 | 112 | STDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password) |
michael@0 | 113 | { |
michael@0 | 114 | return Callback->CryptoGetTextPassword(password); |
michael@0 | 115 | } |
michael@0 | 116 | #endif |
michael@0 | 117 |