1 // AgentProxy.h 2 3 #ifndef ZIP7_INC_AGENT_PROXY_H 4 #define ZIP7_INC_AGENT_PROXY_H 5 6 #include "../Common/OpenArchive.h" 7 8 struct CProxyFile 9 { 10 const wchar_t *Name; 11 unsigned NameLen; 12 bool NeedDeleteName; 13 CProxyFileCProxyFile14 CProxyFile(): Name(NULL), NameLen(0), NeedDeleteName(false) {} ~CProxyFileCProxyFile15 ~CProxyFile() { if (NeedDeleteName) delete [](wchar_t *)(void *)Name; } // delete [](wchar_t *)Name; 16 }; 17 18 const unsigned k_Proxy_RootDirIndex = 0; 19 20 struct CProxyDir 21 { 22 const wchar_t *Name; 23 unsigned NameLen; 24 25 int ArcIndex; // index in proxy->Files[] ; -1 if there is no item for that folder 26 int ParentDir; // index in proxy->Dirs[] ; -1 for root folder; ; 27 CRecordVector<unsigned> SubDirs; 28 CRecordVector<unsigned> SubFiles; 29 30 UInt64 Size; 31 UInt64 PackSize; 32 UInt32 Crc; 33 UInt32 NumSubDirs; 34 UInt32 NumSubFiles; 35 bool CrcIsDefined; 36 CProxyDirCProxyDir37 CProxyDir(): Name(NULL), NameLen(0), ParentDir(-1) {} ~CProxyDirCProxyDir38 ~CProxyDir() { delete [](wchar_t *)(void *)Name; } 39 40 void Clear(); IsLeafCProxyDir41 bool IsLeaf() const { return ArcIndex != -1; } 42 }; 43 44 class CProxyArc 45 { 46 int FindSubDir(unsigned dirIndex, const wchar_t *name, unsigned &insertPos) const; 47 48 void CalculateSizes(unsigned dirIndex, IInArchive *archive); 49 unsigned AddDir(unsigned dirIndex, int arcIndex, const UString &name); 50 public: 51 CObjectVector<CProxyDir> Dirs; // Dirs[0] - root 52 CObjArray<CProxyFile> Files; // all items from archive in same order 53 54 // returns index in Dirs[], or -1, 55 int FindSubDir(unsigned dirIndex, const wchar_t *name) const; 56 57 void GetDirPathParts(unsigned dirIndex, UStringVector &pathParts) const; 58 // returns full path of Dirs[dirIndex], including back slash 59 UString GetDirPath_as_Prefix(unsigned dirIndex) const; 60 61 // AddRealIndices DOES ADD also item represented by dirIndex (if it's Leaf) 62 void AddRealIndices(unsigned dirIndex, CUIntVector &realIndices) const; 63 int GetRealIndex(unsigned dirIndex, unsigned index) const; 64 void GetRealIndices(unsigned dirIndex, const UInt32 *indices, UInt32 numItems, CUIntVector &realIndices) const; 65 66 HRESULT Load(const CArc &arc, IProgress *progress); 67 }; 68 69 70 // ---------- for Tree-mode archive ---------- 71 72 struct CProxyFile2 73 { 74 int DirIndex; // >= 0 for dir. (index in ProxyArchive2->Dirs) 75 int AltDirIndex; // >= 0 if there are alt streams. (index in ProxyArchive2->Dirs) 76 int Parent; // >= 0 if there is parent. (index in archive and in ProxyArchive2->Files) 77 const wchar_t *Name; 78 unsigned NameLen; 79 bool NeedDeleteName; 80 bool Ignore; 81 bool IsAltStream; 82 GetDirIndexCProxyFile283 int GetDirIndex(bool forAltStreams) const { return forAltStreams ? AltDirIndex : DirIndex; } 84 IsDirCProxyFile285 bool IsDir() const { return DirIndex != -1; } CProxyFile2CProxyFile286 CProxyFile2(): 87 DirIndex(-1), AltDirIndex(-1), Parent(-1), 88 Name(NULL), NameLen(0), 89 NeedDeleteName(false), 90 Ignore(false), 91 IsAltStream(false) 92 {} ~CProxyFile2CProxyFile293 ~CProxyFile2() 94 { 95 if (NeedDeleteName) 96 delete [](wchar_t *)(void *)Name; 97 } 98 }; 99 100 struct CProxyDir2 101 { 102 int ArcIndex; // = -1 for root folders, index in proxy->Files[] 103 CRecordVector<unsigned> Items; 104 UString PathPrefix; 105 UInt64 Size; 106 UInt64 PackSize; 107 bool CrcIsDefined; 108 UInt32 Crc; 109 UInt32 NumSubDirs; 110 UInt32 NumSubFiles; 111 CProxyDir2CProxyDir2112 CProxyDir2(): ArcIndex(-1) {} 113 void AddFileSubItem(UInt32 index, const UString &name); 114 void Clear(); 115 }; 116 117 const unsigned k_Proxy2_RootDirIndex = k_Proxy_RootDirIndex; 118 const unsigned k_Proxy2_AltRootDirIndex = 1; 119 const unsigned k_Proxy2_NumRootDirs = 2; 120 121 class CProxyArc2 122 { 123 void CalculateSizes(unsigned dirIndex, IInArchive *archive); 124 // AddRealIndices_of_Dir DOES NOT ADD item itself represented by dirIndex 125 void AddRealIndices_of_Dir(unsigned dirIndex, bool includeAltStreams, CUIntVector &realIndices) const; 126 public: 127 CObjectVector<CProxyDir2> Dirs; // Dirs[0] - root folder 128 // Dirs[1] - for alt streams of root dir 129 CObjArray<CProxyFile2> Files; // all items from archive in same order 130 131 bool IsThere_SubDir(unsigned dirIndex, const UString &name) const; 132 133 void GetDirPathParts(unsigned dirIndex, UStringVector &pathParts, bool &isAltStreamDir) const; 134 UString GetDirPath_as_Prefix(unsigned dirIndex, bool &isAltStreamDir) const; 135 bool IsAltDir(unsigned dirIndex) const; 136 137 // AddRealIndices_of_ArcItem DOES ADD item and subItems 138 void AddRealIndices_of_ArcItem(unsigned arcIndex, bool includeAltStreams, CUIntVector &realIndices) const; 139 unsigned GetRealIndex(unsigned dirIndex, unsigned index) const; 140 void GetRealIndices(unsigned dirIndex, const UInt32 *indices, UInt32 numItems, bool includeAltStreams, CUIntVector &realIndices) const; 141 142 HRESULT Load(const CArc &arc, IProgress *progress); 143 GetParentDirOfFile(UInt32 arcIndex)144 int GetParentDirOfFile(UInt32 arcIndex) const 145 { 146 const CProxyFile2 &file = Files[arcIndex]; 147 148 if (file.Parent == -1) 149 return file.IsAltStream ? 150 k_Proxy2_AltRootDirIndex : 151 k_Proxy2_RootDirIndex; 152 153 const CProxyFile2 &parentFile = Files[file.Parent]; 154 return file.IsAltStream ? 155 parentFile.AltDirIndex : 156 parentFile.DirIndex; 157 } 158 159 int FindItem(unsigned dirIndex, const wchar_t *name, bool foldersOnly) const; 160 }; 161 162 #endif 163