1 // ArchiveOpenCallback.h
2 
3 #ifndef __ARCHIVE_OPEN_CALLBACK_H
4 #define __ARCHIVE_OPEN_CALLBACK_H
5 
6 #include "Common/MyCom.h"
7 #include "Common/MyString.h"
8 
9 #include "Windows/FileFind.h"
10 
11 #ifndef _NO_CRYPTO
12 #include "../../IPassword.h"
13 #endif
14 #include "../../Archive/IArchive.h"
15 
16 #ifdef _NO_CRYPTO
17 
18 #define INTERFACE_IOpenCallbackUI_Crypto(x)
19 
20 #else
21 
22 #define INTERFACE_IOpenCallbackUI_Crypto(x) \
23   virtual HRESULT Open_CryptoGetTextPassword(BSTR *password) x; \
24   virtual HRESULT Open_GetPasswordIfAny(UString &password) x; \
25   virtual bool Open_WasPasswordAsked() x; \
26   virtual void Open_ClearPasswordWasAskedFlag() x; \
27 
28 #endif
29 
30 #define INTERFACE_IOpenCallbackUI(x) \
31   virtual HRESULT Open_CheckBreak() x; \
32   virtual HRESULT Open_SetTotal(const UInt64 *files, const UInt64 *bytes) x; \
33   virtual HRESULT Open_SetCompleted(const UInt64 *files, const UInt64 *bytes) 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   #ifndef _NO_CRYPTO
52   MY_UNKNOWN_IMP3(
53       IArchiveOpenVolumeCallback,
54       ICryptoGetTextPassword,
55       IArchiveOpenSetSubArchiveName
56       )
57   #else
58   MY_UNKNOWN_IMP2(
59       IArchiveOpenVolumeCallback,
60       IArchiveOpenSetSubArchiveName
61       )
62   #endif
63 
64   INTERFACE_IArchiveOpenCallback(;)
65   INTERFACE_IArchiveOpenVolumeCallback(;)
66 
67   #ifndef _NO_CRYPTO
68   STDMETHOD(CryptoGetTextPassword)(BSTR *password);
69   #endif
70 
STDMETHOD(SetSubArchiveName (const wchar_t * name))71   STDMETHOD(SetSubArchiveName(const wchar_t *name))
72   {
73     _subArchiveMode = true;
74     _subArchiveName = name;
75     TotalSize = 0;
76     return  S_OK;
77   }
78 
79 private:
80   UString _folderPrefix;
81   NWindows::NFile::NFind::CFileInfoW _fileInfo;
82   bool _subArchiveMode;
83   UString _subArchiveName;
84 public:
85   UStringVector FileNames;
86   IOpenCallbackUI *Callback;
87   CMyComPtr<IArchiveOpenCallback> ReOpenCallback;
88   UInt64 TotalSize;
89 
COpenCallbackImp()90   COpenCallbackImp(): Callback(NULL) {}
Init(const UString & folderPrefix,const UString & fileName)91   void Init(const UString &folderPrefix, const UString &fileName)
92   {
93     _folderPrefix = folderPrefix;
94     if (!_fileInfo.Find(_folderPrefix + fileName))
95       throw 1;
96     FileNames.Clear();
97     _subArchiveMode = false;
98     TotalSize = 0;
99   }
100   int FindName(const UString &name);
101 };
102 
103 #endif
104