1 // ArchiveOpenCallback.h 2 3 #ifndef __ARCHIVE_OPEN_CALLBACK_H 4 #define __ARCHIVE_OPEN_CALLBACK_H 5 6 #include "../../../Common/MyCom.h" 7 8 #include "../../../Windows/FileFind.h" 9 10 #ifndef _NO_CRYPTO 11 #include "../../IPassword.h" 12 #endif 13 #include "../../Archive/IArchive.h" 14 15 #ifdef _NO_CRYPTO 16 17 #define INTERFACE_IOpenCallbackUI_Crypto(x) 18 19 #else 20 21 #define INTERFACE_IOpenCallbackUI_Crypto(x) \ 22 virtual HRESULT Open_CryptoGetTextPassword(BSTR *password) x; \ 23 virtual HRESULT Open_GetPasswordIfAny(bool &passwordIsDefined, UString &password) x; \ 24 virtual bool Open_WasPasswordAsked() x; \ 25 virtual void Open_ClearPasswordWasAskedFlag() x; \ 26 27 #endif 28 29 #define INTERFACE_IOpenCallbackUI(x) \ 30 virtual HRESULT Open_CheckBreak() x; \ 31 virtual HRESULT Open_SetTotal(const UInt64 *files, const UInt64 *bytes) x; \ 32 virtual HRESULT Open_SetCompleted(const UInt64 *files, const UInt64 *bytes) x; \ 33 INTERFACE_IOpenCallbackUI_Crypto(x) 34 35 struct IOpenCallbackUI 36 { 37 INTERFACE_IOpenCallbackUI(=0) 38 }; 39 40 class COpenCallbackImp: 41 public IArchiveOpenCallback, 42 public IArchiveOpenVolumeCallback, 43 public IArchiveOpenSetSubArchiveName, 44 #ifndef _NO_CRYPTO 45 public ICryptoGetTextPassword, 46 #endif 47 public CMyUnknownImp 48 { 49 public: 50 #ifndef _NO_CRYPTO 51 MY_UNKNOWN_IMP3( 52 IArchiveOpenVolumeCallback, 53 ICryptoGetTextPassword, 54 IArchiveOpenSetSubArchiveName 55 ) 56 #else 57 MY_UNKNOWN_IMP2( 58 IArchiveOpenVolumeCallback, 59 IArchiveOpenSetSubArchiveName 60 ) 61 #endif 62 63 INTERFACE_IArchiveOpenCallback(;) 64 INTERFACE_IArchiveOpenVolumeCallback(;) 65 66 #ifndef _NO_CRYPTO 67 STDMETHOD(CryptoGetTextPassword)(BSTR *password); 68 #endif 69 70 STDMETHOD(SetSubArchiveName(const wchar_t *name)) 71 { 72 _subArchiveMode = true; 73 _subArchiveName = name; 74 // TotalSize = 0; 75 return S_OK; 76 } 77 78 private: 79 FString _folderPrefix; 80 NWindows::NFile::NFind::CFileInfo _fileInfo; 81 bool _subArchiveMode; 82 UString _subArchiveName; 83 84 public: 85 UStringVector FileNames; 86 CBoolVector FileNames_WasUsed; 87 CRecordVector<UInt64> FileSizes; 88 89 IOpenCallbackUI *Callback; 90 CMyComPtr<IArchiveOpenCallback> ReOpenCallback; 91 // UInt64 TotalSize; 92 93 COpenCallbackImp(): Callback(NULL) {} 94 void Init(const FString &folderPrefix, const FString &fileName) 95 { 96 _folderPrefix = folderPrefix; 97 if (!_fileInfo.Find(_folderPrefix + fileName)) 98 throw 20121118; 99 FileNames.Clear(); 100 FileNames_WasUsed.Clear(); 101 FileSizes.Clear(); 102 _subArchiveMode = false; 103 // TotalSize = 0; 104 } 105 bool SetSecondFileInfo(CFSTR newName) 106 { 107 return _fileInfo.Find(newName) && !_fileInfo.IsDir(); 108 } 109 }; 110 111 #endif 112