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