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_Clear_PasswordWasAsked_Flag() 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 virtual HRESULT Open_Finished() x; \ 34 INTERFACE_IOpenCallbackUI_Crypto(x) 35 36 struct IOpenCallbackUI 37 { 38 INTERFACE_IOpenCallbackUI(=0) 39 }; 40 41 class COpenCallbackImp: 42 public IArchiveOpenCallback, 43 public IArchiveOpenVolumeCallback, 44 public IArchiveOpenSetSubArchiveName, 45 #ifndef _NO_CRYPTO 46 public ICryptoGetTextPassword, 47 #endif 48 public CMyUnknownImp 49 { 50 public: 51 MY_QUERYINTERFACE_BEGIN2(IArchiveOpenVolumeCallback) 52 MY_QUERYINTERFACE_ENTRY(IArchiveOpenSetSubArchiveName) 53 #ifndef _NO_CRYPTO 54 MY_QUERYINTERFACE_ENTRY(ICryptoGetTextPassword) 55 #endif 56 MY_QUERYINTERFACE_END 57 MY_ADDREF_RELEASE 58 59 INTERFACE_IArchiveOpenCallback(;) 60 INTERFACE_IArchiveOpenVolumeCallback(;) 61 62 #ifndef _NO_CRYPTO 63 STDMETHOD(CryptoGetTextPassword)(BSTR *password); 64 #endif 65 STDMETHOD(SetSubArchiveName (const wchar_t * name))66 STDMETHOD(SetSubArchiveName(const wchar_t *name)) 67 { 68 _subArchiveMode = true; 69 _subArchiveName = name; 70 // TotalSize = 0; 71 return S_OK; 72 } 73 74 private: 75 FString _folderPrefix; 76 NWindows::NFile::NFind::CFileInfo _fileInfo; 77 bool _subArchiveMode; 78 UString _subArchiveName; 79 80 public: 81 UStringVector FileNames; 82 CBoolVector FileNames_WasUsed; 83 CRecordVector<UInt64> FileSizes; 84 85 bool PasswordWasAsked; 86 87 IOpenCallbackUI *Callback; 88 CMyComPtr<IArchiveOpenCallback> ReOpenCallback; 89 // UInt64 TotalSize; 90 COpenCallbackImp()91 COpenCallbackImp(): Callback(NULL), _subArchiveMode(false) {} 92 Init(const FString & folderPrefix,const FString & fileName)93 void Init(const FString &folderPrefix, const FString &fileName) 94 { 95 _folderPrefix = folderPrefix; 96 if (!_fileInfo.Find(_folderPrefix + fileName)) 97 throw 20121118; 98 FileNames.Clear(); 99 FileNames_WasUsed.Clear(); 100 FileSizes.Clear(); 101 _subArchiveMode = false; 102 // TotalSize = 0; 103 PasswordWasAsked = false; 104 } 105 SetSecondFileInfo(CFSTR newName)106 bool SetSecondFileInfo(CFSTR newName) 107 { 108 return _fileInfo.Find(newName) && !_fileInfo.IsDir(); 109 } 110 }; 111 112 #endif 113