Home | History | Annotate | Download | only in Common
      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 
     37   CArchivePath(): Temp(false) {};
     38 
     39   void ParseFromPath(const UString &path, EArcNameMode mode);
     40   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 
     59   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 
     76   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 OpenShareForWrite;
     95 
     96   bool StdInMode;
     97   UString StdInFileName;
     98   bool StdOutMode;
     99 
    100   bool EMailMode;
    101   bool EMailRemoveAfter;
    102   UString EMailAddress;
    103 
    104   FString WorkingDir;
    105   NWildcard::ECensorPathMode PathMode;
    106   UString AddPathPrefix;
    107 
    108   CBoolPair NtSecurity;
    109   CBoolPair AltStreams;
    110   CBoolPair HardLinks;
    111   CBoolPair SymLinks;
    112 
    113   bool DeleteAfterCompressing;
    114 
    115   bool SetArcMTime;
    116 
    117   CObjectVector<CRenamePair> RenamePairs;
    118 
    119   bool InitFormatIndex(const CCodecs *codecs, const CObjectVector<COpenType> &types, const UString &arcPath);
    120   bool SetArcPath(const CCodecs *codecs, const UString &arcPath);
    121 
    122   CUpdateOptions():
    123     UpdateArchiveItself(true),
    124     SfxMode(false),
    125     StdInMode(false),
    126     StdOutMode(false),
    127     EMailMode(false),
    128     EMailRemoveAfter(false),
    129     OpenShareForWrite(false),
    130     ArcNameMode(k_ArcNameMode_Smart),
    131     PathMode(NWildcard::k_RelatPath),
    132 
    133     DeleteAfterCompressing(false),
    134     SetArcMTime(false)
    135 
    136       {};
    137 
    138   void SetActionCommand_Add()
    139   {
    140     Commands.Clear();
    141     CUpdateArchiveCommand c;
    142     c.ActionSet = NUpdateArchive::k_ActionSet_Add;
    143     Commands.Add(c);
    144   }
    145 
    146   CRecordVector<UInt64> VolumesSizes;
    147 };
    148 
    149 struct CUpdateErrorInfo
    150 {
    151   DWORD SystemError;
    152   AString Message;
    153   FStringVector FileNames;
    154 
    155   bool ThereIsError() const { return SystemError != 0 || !Message.IsEmpty() || !FileNames.IsEmpty(); }
    156   HRESULT Get_HRESULT_Error() const { return SystemError == 0 ? E_FAIL : HRESULT_FROM_WIN32(SystemError); }
    157   void SetFromLastError(const char *message);
    158   HRESULT SetFromLastError(const char *message, const FString &fileName);
    159 
    160   CUpdateErrorInfo(): SystemError(0) {};
    161 };
    162 
    163 struct CFinishArchiveStat
    164 {
    165   UInt64 OutArcFileSize;
    166 
    167   CFinishArchiveStat(): OutArcFileSize(0) {}
    168 };
    169 
    170 #define INTERFACE_IUpdateCallbackUI2(x) \
    171   INTERFACE_IUpdateCallbackUI(x) \
    172   INTERFACE_IDirItemsCallback(x) \
    173   virtual HRESULT OpenResult(const CCodecs *codecs, const CArchiveLink &arcLink, const wchar_t *name, HRESULT result) x; \
    174   virtual HRESULT StartScanning() x; \
    175   virtual HRESULT FinishScanning(const CDirItemsStat &st) x; \
    176   virtual HRESULT StartOpenArchive(const wchar_t *name) x; \
    177   virtual HRESULT StartArchive(const wchar_t *name, bool updating) x; \
    178   virtual HRESULT FinishArchive(const CFinishArchiveStat &st) x; \
    179   virtual HRESULT DeletingAfterArchiving(const FString &path, bool isDir) x; \
    180   virtual HRESULT FinishDeletingAfterArchiving() x; \
    181 
    182 struct IUpdateCallbackUI2: public IUpdateCallbackUI, public IDirItemsCallback
    183 {
    184   INTERFACE_IUpdateCallbackUI2(=0)
    185 };
    186 
    187 HRESULT UpdateArchive(
    188     CCodecs *codecs,
    189     const CObjectVector<COpenType> &types,
    190     const UString &cmdArcPath2,
    191     NWildcard::CCensor &censor,
    192     CUpdateOptions &options,
    193     CUpdateErrorInfo &errorInfo,
    194     IOpenCallbackUI *openCallback,
    195     IUpdateCallbackUI2 *callback,
    196     bool needSetPath);
    197 
    198 #endif
    199