1 // ExtractCallback.h
2 
3 #ifndef __EXTRACTCALLBACK_H
4 #define __EXTRACTCALLBACK_H
5 
6 #include "../Agent/IFolderArchive.h"
7 #include "Common/MyString.h"
8 #include "../Common/ArchiveOpenCallback.h"
9 
10 #ifdef _SFX
11 #include "ProgressDialog.h"
12 #else
13 #include "ProgressDialog2.h"
14 #endif
15 
16 #include "Windows/ResourceString.h"
17 
18 #ifdef LANG
19 #include "LangUtils.h"
20 #endif
21 
22 #ifndef _NO_CRYPTO
23 #include "../../IPassword.h"
24 #endif
25 #include "Common/MyCom.h"
26 #include "IFolder.h"
27 
28 class CExtractCallbackImp:
29   public IExtractCallbackUI,
30   public IOpenCallbackUI,
31   public IFolderOperationsExtractCallback,
32   // public IFolderArchiveExtractCallback, // mkultiple from IProgress
33   #ifndef _SFX
34   public ICompressProgressInfo,
35   #endif
36   #ifndef _NO_CRYPTO
37   public ICryptoGetTextPassword,
38   #endif
39   public CMyUnknownImp
40 {
41 public:
42   MY_QUERYINTERFACE_BEGIN2(IFolderOperationsExtractCallback)
43   MY_QUERYINTERFACE_ENTRY(IFolderArchiveExtractCallback)
44   #ifndef _SFX
45   MY_QUERYINTERFACE_ENTRY(ICompressProgressInfo)
46   #endif
47   #ifndef _NO_CRYPTO
48   MY_QUERYINTERFACE_ENTRY(ICryptoGetTextPassword)
49   #endif
50   MY_QUERYINTERFACE_END
51   MY_ADDREF_RELEASE
52 
53   #ifndef _SFX
54   STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
55   #endif
56 
57   INTERFACE_IProgress(;)
58   INTERFACE_IOpenCallbackUI(;)
59 
60   // IFolderArchiveExtractCallback
61   // STDMETHOD(SetTotalFiles)(UInt64 total);
62   // STDMETHOD(SetCompletedFiles)(const UInt64 *value);
63   STDMETHOD(AskOverwrite)(
64       const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,
65       const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,
66       Int32 *answer);
67   STDMETHOD (PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position);
68 
69   STDMETHOD(MessageError)(const wchar_t *message);
70   STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted);
71 
72   // IExtractCallbackUI
73 
74   HRESULT BeforeOpen(const wchar_t *name);
75   HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted);
76   HRESULT ThereAreNoFiles();
77   HRESULT ExtractResult(HRESULT result);
78 
79   #ifndef _NO_CRYPTO
80   HRESULT SetPassword(const UString &password);
81   #endif
82 
83   // IFolderOperationsExtractCallback
84   STDMETHOD(AskWrite)(
85       const wchar_t *srcPath,
86       Int32 srcIsFolder,
87       const FILETIME *srcTime,
88       const UInt64 *srcSize,
89       const wchar_t *destPathRequest,
90       BSTR *destPathResult,
91       Int32 *writeAnswer);
92   STDMETHOD(ShowMessage)(const wchar_t *message);
93   STDMETHOD(SetCurrentFilePath)(const wchar_t *filePath);
94   STDMETHOD(SetNumFiles)(UInt64 numFiles);
95 
96   // ICryptoGetTextPassword
97   #ifndef _NO_CRYPTO
98   STDMETHOD(CryptoGetTextPassword)(BSTR *password);
99   #endif
100 
101 private:
102   // bool _extractMode;
103   UString _currentArchivePath;
104   bool _needWriteArchivePath;
105 
106   UString _currentFilePath;
107   bool _isFolder;
108 
109   // void CreateComplexDirectory(const UStringVector &aDirPathParts);
110 
111   HRESULT SetCurrentFilePath2(const wchar_t *filePath);
112   void AddErrorMessage(LPCWSTR message);
113 public:
114   CProgressDialog ProgressDialog;
115   UStringVector Messages;
116   bool ShowMessages;
117   #ifndef _SFX
118   UInt64 NumFolders;
119   UInt64 NumFiles;
120   bool NeedAddFile;
121   #endif
122   HWND ParentWindow;
StartProgressDialog(const UString & title)123   INT_PTR StartProgressDialog(const UString &title)
124   {
125     return ProgressDialog.Create(title, ParentWindow);
126   }
127   UInt32 NumArchiveErrors;
128   NExtract::NOverwriteMode::EEnum OverwriteMode;
129 
130   #ifndef _NO_CRYPTO
131   bool PasswordIsDefined;
132   bool PasswordWasAsked;
133   UString Password;
134   #endif
135 
CExtractCallbackImp()136   CExtractCallbackImp():
137     #ifndef _NO_CRYPTO
138     PasswordIsDefined(false),
139     PasswordWasAsked(false),
140     #endif
141     OverwriteMode(NExtract::NOverwriteMode::kAskBefore),
142     ParentWindow(0),
143     ShowMessages(true)
144     {}
145 
146   ~CExtractCallbackImp();
147   void Init();
148 };
149 
150 #endif
151