• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Update.h
2 
3 #ifndef __COMMON_UPDATE_H
4 #define __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   CCompressionMethodMode MethodMode;
85 
86   CObjectVector<CUpdateArchiveCommand> Commands;
87   bool UpdateArchiveItself;
88   CArchivePath ArchivePath;
89   EArcNameMode ArcNameMode;
90 
91   bool SfxMode;
92   FString SfxModule;
93 
94   bool PreserveATime;
95   bool OpenShareForWrite;
96   bool StopAfterOpenError;
97 
98   bool StdInMode;
99   UString StdInFileName;
100   bool StdOutMode;
101 
102   bool EMailMode;
103   bool EMailRemoveAfter;
104   UString EMailAddress;
105 
106   FString WorkingDir;
107   NWildcard::ECensorPathMode PathMode;
108   // UString AddPathPrefix;
109 
110   CBoolPair NtSecurity;
111   CBoolPair AltStreams;
112   CBoolPair HardLinks;
113   CBoolPair SymLinks;
114 
115   CBoolPair StoreOwnerId;
116   CBoolPair StoreOwnerName;
117 
118   bool DeleteAfterCompressing;
119 
120   bool SetArcMTime;
121 
122   CObjectVector<CRenamePair> RenamePairs;
123 
124   bool InitFormatIndex(const CCodecs *codecs, const CObjectVector<COpenType> &types, const UString &arcPath);
125   bool SetArcPath(const CCodecs *codecs, const UString &arcPath);
126 
CUpdateOptionsCUpdateOptions127   CUpdateOptions():
128     UpdateArchiveItself(true),
129     ArcNameMode(k_ArcNameMode_Smart),
130 
131     SfxMode(false),
132 
133     PreserveATime(false),
134     OpenShareForWrite(false),
135     StopAfterOpenError(false),
136 
137     StdInMode(false),
138     StdOutMode(false),
139 
140     EMailMode(false),
141     EMailRemoveAfter(false),
142 
143     PathMode(NWildcard::k_RelatPath),
144 
145     DeleteAfterCompressing(false),
146     SetArcMTime(false)
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   CRecordVector<UInt64> VolumesSizes;
159 };
160 
161 struct CUpdateErrorInfo
162 {
163   DWORD SystemError; // it's DWORD (WRes) only;
164   AString Message;
165   FStringVector FileNames;
166 
ThereIsErrorCUpdateErrorInfo167   bool ThereIsError() const { return SystemError != 0 || !Message.IsEmpty() || !FileNames.IsEmpty(); }
Get_HRESULT_ErrorCUpdateErrorInfo168   HRESULT Get_HRESULT_Error() const { return SystemError == 0 ? E_FAIL : HRESULT_FROM_WIN32(SystemError); }
169   void SetFromLastError(const char *message);
170   HRESULT SetFromLastError(const char *message, const FString &fileName);
171   HRESULT SetFromError_DWORD(const char *message, const FString &fileName, DWORD error);
172 
CUpdateErrorInfoCUpdateErrorInfo173   CUpdateErrorInfo(): SystemError(0) {};
174 };
175 
176 struct CFinishArchiveStat
177 {
178   UInt64 OutArcFileSize;
179 
CFinishArchiveStatCFinishArchiveStat180   CFinishArchiveStat(): OutArcFileSize(0) {}
181 };
182 
183 #define INTERFACE_IUpdateCallbackUI2(x) \
184   INTERFACE_IUpdateCallbackUI(x) \
185   INTERFACE_IDirItemsCallback(x) \
186   virtual HRESULT OpenResult(const CCodecs *codecs, const CArchiveLink &arcLink, const wchar_t *name, HRESULT result) x; \
187   virtual HRESULT StartScanning() x; \
188   virtual HRESULT FinishScanning(const CDirItemsStat &st) x; \
189   virtual HRESULT StartOpenArchive(const wchar_t *name) x; \
190   virtual HRESULT StartArchive(const wchar_t *name, bool updating) x; \
191   virtual HRESULT FinishArchive(const CFinishArchiveStat &st) x; \
192   virtual HRESULT DeletingAfterArchiving(const FString &path, bool isDir) x; \
193   virtual HRESULT FinishDeletingAfterArchiving() x; \
194 
195 struct IUpdateCallbackUI2: public IUpdateCallbackUI, public IDirItemsCallback
196 {
197   INTERFACE_IUpdateCallbackUI2(=0)
198 };
199 
200 HRESULT UpdateArchive(
201     CCodecs *codecs,
202     const CObjectVector<COpenType> &types,
203     const UString &cmdArcPath2,
204     NWildcard::CCensor &censor,
205     CUpdateOptions &options,
206     CUpdateErrorInfo &errorInfo,
207     IOpenCallbackUI *openCallback,
208     IUpdateCallbackUI2 *callback,
209     bool needSetPath);
210 
211 #endif
212