1 // Update.h
2 
3 #ifndef __UPDATE_H
4 #define __UPDATE_H
5 
6 #include "Common/Wildcard.h"
7 #include "Windows/FileFind.h"
8 #include "../../Archive/IArchive.h"
9 
10 #include "UpdateAction.h"
11 #include "ArchiveOpenCallback.h"
12 #include "UpdateCallback.h"
13 #include "Property.h"
14 #include "LoadCodecs.h"
15 
16 struct CArchivePath
17 {
18   UString Prefix;   // path(folder) prefix including slash
19   UString Name; // base name
20   UString BaseExtension; // archive type extension or "exe" extension
21   UString VolExtension;  // archive type extension for volumes
22 
23   bool Temp;
24   UString TempPrefix;  // path(folder) for temp location
25   UString TempPostfix;
26 
CArchivePathCArchivePath27   CArchivePath(): Temp(false) {};
28 
ParseFromPathCArchivePath29   void ParseFromPath(const UString &path)
30   {
31     SplitPathToParts(path, Prefix, Name);
32     if (Name.IsEmpty())
33       return;
34     int dotPos = Name.ReverseFind(L'.');
35     if (dotPos <= 0)
36       return;
37     if (dotPos == Name.Length() - 1)
38     {
39       Name = Name.Left(dotPos);
40       BaseExtension.Empty();
41       return;
42     }
43     if (BaseExtension.CompareNoCase(Name.Mid(dotPos + 1)) == 0)
44     {
45       BaseExtension = Name.Mid(dotPos + 1);
46       Name = Name.Left(dotPos);
47     }
48     else
49       BaseExtension.Empty();
50   }
51 
GetPathWithoutExtCArchivePath52   UString GetPathWithoutExt() const
53   {
54     return Prefix + Name;
55   }
56 
GetFinalPathCArchivePath57   UString GetFinalPath() const
58   {
59     UString path = GetPathWithoutExt();
60     if (!BaseExtension.IsEmpty())
61       path += UString(L'.') + BaseExtension;
62     return path;
63   }
64 
65 
GetTempPathCArchivePath66   UString GetTempPath() const
67   {
68     UString path = TempPrefix + Name;
69     if (!BaseExtension.IsEmpty())
70       path += UString(L'.') + BaseExtension;
71     path += L".tmp";
72     path += TempPostfix;
73     return path;
74   }
75 };
76 
77 struct CUpdateArchiveCommand
78 {
79   UString UserArchivePath;
80   CArchivePath ArchivePath;
81   NUpdateArchive::CActionSet ActionSet;
82 };
83 
84 struct CCompressionMethodMode
85 {
86   int FormatIndex;
87   CObjectVector<CProperty> Properties;
CCompressionMethodModeCCompressionMethodMode88   CCompressionMethodMode(): FormatIndex(-1) {}
89 };
90 
91 struct CUpdateOptions
92 {
93   CCompressionMethodMode MethodMode;
94 
95   CObjectVector<CUpdateArchiveCommand> Commands;
96   bool UpdateArchiveItself;
97   CArchivePath ArchivePath;
98 
99   bool SfxMode;
100   UString SfxModule;
101 
102   bool OpenShareForWrite;
103 
104   bool StdInMode;
105   UString StdInFileName;
106   bool StdOutMode;
107 
108   bool EMailMode;
109   bool EMailRemoveAfter;
110   UString EMailAddress;
111 
112   UString WorkingDir;
113 
114   bool Init(const CCodecs *codecs, const CIntVector &formatIndices, const UString &arcPath);
115 
CUpdateOptionsCUpdateOptions116   CUpdateOptions():
117     UpdateArchiveItself(true),
118     SfxMode(false),
119     StdInMode(false),
120     StdOutMode(false),
121     EMailMode(false),
122     EMailRemoveAfter(false),
123     OpenShareForWrite(false)
124       {};
125   CRecordVector<UInt64> VolumesSizes;
126 };
127 
128 struct CErrorInfo
129 {
130   DWORD SystemError;
131   UString FileName;
132   UString FileName2;
133   UString Message;
134   // UStringVector ErrorPaths;
135   // CRecordVector<DWORD> ErrorCodes;
CErrorInfoCErrorInfo136   CErrorInfo(): SystemError(0) {};
137 };
138 
139 struct CUpdateErrorInfo: public CErrorInfo
140 {
141 };
142 
143 #define INTERFACE_IUpdateCallbackUI2(x) \
144   INTERFACE_IUpdateCallbackUI(x) \
145   virtual HRESULT OpenResult(const wchar_t *name, HRESULT result) x; \
146   virtual HRESULT StartScanning() x; \
147   virtual HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path) x; \
148   virtual HRESULT CanNotFindError(const wchar_t *name, DWORD systemError) x; \
149   virtual HRESULT FinishScanning() x; \
150   virtual HRESULT StartArchive(const wchar_t *name, bool updating) x; \
151   virtual HRESULT FinishArchive() x; \
152 
153 struct IUpdateCallbackUI2: public IUpdateCallbackUI
154 {
155   INTERFACE_IUpdateCallbackUI2(=0)
156 };
157 
158 HRESULT UpdateArchive(
159     CCodecs *codecs,
160     const NWildcard::CCensor &censor,
161     CUpdateOptions &options,
162     CUpdateErrorInfo &errorInfo,
163     IOpenCallbackUI *openCallback,
164     IUpdateCallbackUI2 *callback);
165 
166 #endif
167