tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Update.h (5041B)


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