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 "Property.h"
     11 #include "UpdateAction.h"
     12 #include "UpdateCallback.h"
     13 
     14 struct CArchivePath
     15 {
     16   UString OriginalPath;
     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 
     27   CArchivePath(): Temp(false) {};
     28 
     29   void ParseFromPath(const UString &path)
     30   {
     31     OriginalPath = path;
     32 
     33     SplitPathToParts(path, Prefix, Name);
     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 
     52   UString GetPathWithoutExt() const
     53   {
     54     return Prefix + Name;
     55   }
     56 
     57   UString GetFinalPath() const
     58   {
     59     UString path = GetPathWithoutExt();
     60     if (!BaseExtension.IsEmpty())
     61       path += UString(L'.') + BaseExtension;
     62     return path;
     63   }
     64 
     65 
     66   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;
     88   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 
    116   CUpdateOptions():
    117     UpdateArchiveItself(true),
    118     SfxMode(false),
    119     StdInMode(false),
    120     StdOutMode(false),
    121     EMailMode(false),
    122     EMailRemoveAfter(false),
    123     OpenShareForWrite(false)
    124       {};
    125 
    126   void SetAddActionCommand()
    127   {
    128     Commands.Clear();
    129     CUpdateArchiveCommand c;
    130     c.ActionSet = NUpdateArchive::kAddActionSet;
    131     Commands.Add(c);
    132   }
    133 
    134   CRecordVector<UInt64> VolumesSizes;
    135 };
    136 
    137 struct CErrorInfo
    138 {
    139   DWORD SystemError;
    140   UString FileName;
    141   UString FileName2;
    142   UString Message;
    143   // UStringVector ErrorPaths;
    144   // CRecordVector<DWORD> ErrorCodes;
    145   CErrorInfo(): SystemError(0) {};
    146 };
    147 
    148 struct CUpdateErrorInfo: public CErrorInfo
    149 {
    150 };
    151 
    152 #define INTERFACE_IUpdateCallbackUI2(x) \
    153   INTERFACE_IUpdateCallbackUI(x) \
    154   virtual HRESULT OpenResult(const wchar_t *name, HRESULT result) x; \
    155   virtual HRESULT StartScanning() x; \
    156   virtual HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path) x; \
    157   virtual HRESULT CanNotFindError(const wchar_t *name, DWORD systemError) x; \
    158   virtual HRESULT FinishScanning() x; \
    159   virtual HRESULT StartArchive(const wchar_t *name, bool updating) x; \
    160   virtual HRESULT FinishArchive() x; \
    161 
    162 struct IUpdateCallbackUI2: public IUpdateCallbackUI
    163 {
    164   INTERFACE_IUpdateCallbackUI2(=0)
    165 };
    166 
    167 HRESULT UpdateArchive(
    168     CCodecs *codecs,
    169     const NWildcard::CCensor &censor,
    170     CUpdateOptions &options,
    171     CUpdateErrorInfo &errorInfo,
    172     IOpenCallbackUI *openCallback,
    173     IUpdateCallbackUI2 *callback);
    174 
    175 #endif
    176