1 // Update.h
2
3 #ifndef ZIP7_INC_COMMON_UPDATE_H
4 #define ZIP7_INC_COMMON_UPDATE_H
5
6 #include "../../../Common/Wildcard.h"
7
8 #include "ArchiveOpenCallback.h"
9 #include "LoadCodecs.h"
10 #include "OpenArchive.h"
11 #include "Property.h"
12 #include "UpdateAction.h"
13 #include "UpdateCallback.h"
14
15 #include "DirItem.h"
16
17 enum EArcNameMode
18 {
19 k_ArcNameMode_Smart,
20 k_ArcNameMode_Exact,
21 k_ArcNameMode_Add
22 };
23
24 struct CArchivePath
25 {
26 UString OriginalPath;
27
28 UString Prefix; // path(folder) prefix including slash
29 UString Name; // base name
30 UString BaseExtension; // archive type extension or "exe" extension
31 UString VolExtension; // archive type extension for volumes
32
33 bool Temp;
34 FString TempPrefix; // path(folder) for temp location
35 FString TempPostfix;
36
CArchivePathCArchivePath37 CArchivePath(): Temp(false) {}
38
39 void ParseFromPath(const UString &path, EArcNameMode mode);
GetPathWithoutExtCArchivePath40 UString GetPathWithoutExt() const { return Prefix + Name; }
41 UString GetFinalPath() const;
42 UString GetFinalVolPath() const;
43 FString GetTempPath() const;
44 };
45
46 struct CUpdateArchiveCommand
47 {
48 UString UserArchivePath;
49 CArchivePath ArchivePath;
50 NUpdateArchive::CActionSet ActionSet;
51 };
52
53 struct CCompressionMethodMode
54 {
55 bool Type_Defined;
56 COpenType Type;
57 CObjectVector<CProperty> Properties;
58
CCompressionMethodModeCCompressionMethodMode59 CCompressionMethodMode(): Type_Defined(false) {}
60 };
61
62 namespace NRecursedType { enum EEnum
63 {
64 kRecursed,
65 kWildcardOnlyRecursed,
66 kNonRecursed
67 };}
68
69 struct CRenamePair
70 {
71 UString OldName;
72 UString NewName;
73 bool WildcardParsing;
74 NRecursedType::EEnum RecursedType;
75
CRenamePairCRenamePair76 CRenamePair(): WildcardParsing(true), RecursedType(NRecursedType::kNonRecursed) {}
77
78 bool Prepare();
79 bool GetNewPath(bool isFolder, const UString &src, UString &dest) const;
80 };
81
82 struct CUpdateOptions
83 {
84 bool UpdateArchiveItself;
85 bool SfxMode;
86
87 bool PreserveATime;
88 bool OpenShareForWrite;
89 bool StopAfterOpenError;
90
91 bool StdInMode;
92 bool StdOutMode;
93
94 bool EMailMode;
95 bool EMailRemoveAfter;
96
97 bool DeleteAfterCompressing;
98 bool SetArcMTime;
99
100 CBoolPair NtSecurity;
101 CBoolPair AltStreams;
102 CBoolPair HardLinks;
103 CBoolPair SymLinks;
104
105 CBoolPair StoreOwnerId;
106 CBoolPair StoreOwnerName;
107
108 EArcNameMode ArcNameMode;
109 NWildcard::ECensorPathMode PathMode;
110
111 CCompressionMethodMode MethodMode;
112
113 CObjectVector<CUpdateArchiveCommand> Commands;
114 CArchivePath ArchivePath;
115
116 FString SfxModule;
117 UString StdInFileName;
118 UString EMailAddress;
119 FString WorkingDir;
120 // UString AddPathPrefix;
121
122 CObjectVector<CRenamePair> RenamePairs;
123 CRecordVector<UInt64> VolumesSizes;
124
125 bool InitFormatIndex(const CCodecs *codecs, const CObjectVector<COpenType> &types, const UString &arcPath);
126 bool SetArcPath(const CCodecs *codecs, const UString &arcPath);
127
CUpdateOptionsCUpdateOptions128 CUpdateOptions():
129 UpdateArchiveItself(true),
130 SfxMode(false),
131
132 PreserveATime(false),
133 OpenShareForWrite(false),
134 StopAfterOpenError(false),
135
136 StdInMode(false),
137 StdOutMode(false),
138
139 EMailMode(false),
140 EMailRemoveAfter(false),
141
142 DeleteAfterCompressing(false),
143 SetArcMTime(false),
144
145 ArcNameMode(k_ArcNameMode_Smart),
146 PathMode(NWildcard::k_RelatPath)
147
148 {}
149
SetActionCommand_AddCUpdateOptions150 void SetActionCommand_Add()
151 {
152 Commands.Clear();
153 CUpdateArchiveCommand c;
154 c.ActionSet = NUpdateArchive::k_ActionSet_Add;
155 Commands.Add(c);
156 }
157 };
158
159
160 struct CUpdateErrorInfo
161 {
162 DWORD SystemError; // it's DWORD (WRes) only;
163 AString Message;
164 FStringVector FileNames;
165
ThereIsErrorCUpdateErrorInfo166 bool ThereIsError() const { return SystemError != 0 || !Message.IsEmpty() || !FileNames.IsEmpty(); }
Get_HRESULT_ErrorCUpdateErrorInfo167 HRESULT Get_HRESULT_Error() const { return SystemError == 0 ? E_FAIL : HRESULT_FROM_WIN32(SystemError); }
168 void SetFromLastError(const char *message);
169 HRESULT SetFromLastError(const char *message, const FString &fileName);
170 HRESULT SetFromError_DWORD(const char *message, const FString &fileName, DWORD error);
171
CUpdateErrorInfoCUpdateErrorInfo172 CUpdateErrorInfo(): SystemError(0) {}
173 };
174
175 struct CFinishArchiveStat
176 {
177 UInt64 OutArcFileSize;
178 unsigned NumVolumes;
179 bool IsMultiVolMode;
180
CFinishArchiveStatCFinishArchiveStat181 CFinishArchiveStat(): OutArcFileSize(0), NumVolumes(0), IsMultiVolMode(false) {}
182 };
183
184 Z7_PURE_INTERFACES_BEGIN
185
186 // INTERFACE_IUpdateCallbackUI(x)
187 // INTERFACE_IDirItemsCallback(x)
188
189 #define Z7_IFACEN_IUpdateCallbackUI2(x) \
190 virtual HRESULT OpenResult(const CCodecs *codecs, const CArchiveLink &arcLink, const wchar_t *name, HRESULT result) x \
191 virtual HRESULT StartScanning() x \
192 virtual HRESULT FinishScanning(const CDirItemsStat &st) x \
193 virtual HRESULT StartOpenArchive(const wchar_t *name) x \
194 virtual HRESULT StartArchive(const wchar_t *name, bool updating) x \
195 virtual HRESULT FinishArchive(const CFinishArchiveStat &st) x \
196 virtual HRESULT DeletingAfterArchiving(const FString &path, bool isDir) x \
197 virtual HRESULT FinishDeletingAfterArchiving() x \
198
DECLARE_INTERFACE(IUpdateCallbackUI2)199 DECLARE_INTERFACE(IUpdateCallbackUI2):
200 public IUpdateCallbackUI,
201 public IDirItemsCallback
202 {
203 Z7_IFACE_PURE(IUpdateCallbackUI2)
204 };
205 Z7_PURE_INTERFACES_END
206
207 HRESULT UpdateArchive(
208 CCodecs *codecs,
209 const CObjectVector<COpenType> &types,
210 const UString &cmdArcPath2,
211 NWildcard::CCensor &censor,
212 CUpdateOptions &options,
213 CUpdateErrorInfo &errorInfo,
214 IOpenCallbackUI *openCallback,
215 IUpdateCallbackUI2 *callback,
216 bool needSetPath);
217
218 #endif
219