3 #ifndef __ARCHIVE_CHM_IN_H
\r
4 #define __ARCHIVE_CHM_IN_H
\r
6 #include "Common/Buffer.h"
\r
7 #include "Common/MyString.h"
\r
9 #include "../../IStream.h"
\r
10 #include "../../Common/InBuffer.h"
\r
12 #include "ChmHeader.h"
\r
14 namespace NArchive {
\r
24 bool IsFormatRelatedItem() const
\r
26 if (Name.Length() < 2)
\r
28 return Name[0] == ':' && Name[1] == ':';
\r
31 bool IsUserItem() const
\r
33 if (Name.Length() < 2)
\r
35 return Name[0] == '/';
\r
40 if (Name.Length() == 0)
\r
42 return (Name[Name.Length() - 1] == '/');
\r
48 UInt64 ContentOffset;
\r
49 CObjectVector<CItem> Items;
\r
50 AString NewFormatString;
\r
54 int FindItem(const AString &name) const
\r
56 for (int i = 0; i < Items.Size(); i++)
\r
57 if (Items[i].Name == name)
\r
65 NewFormatString.Empty();
\r
66 Help2Format = false;
\r
73 UInt64 UncompressedSize;
\r
74 UInt64 CompressedSize;
\r
76 CRecordVector<UInt64> ResetOffsets;
\r
77 bool GetCompressedSizeOfBlocks(UInt64 blockIndex, UInt32 numBlocks, UInt64 &size) const
\r
79 if (blockIndex >= ResetOffsets.Size())
\r
81 UInt64 startPos = ResetOffsets[(int)blockIndex];
\r
82 if (blockIndex + numBlocks >= ResetOffsets.Size())
\r
83 size = CompressedSize - startPos;
\r
85 size = ResetOffsets[(int)(blockIndex + numBlocks)] - startPos;
\r
88 bool GetCompressedSizeOfBlock(UInt64 blockIndex, UInt64 &size) const
\r
90 return GetCompressedSizeOfBlocks(blockIndex, 1, size);
\r
92 UInt64 GetNumBlocks(UInt64 size) const
\r
94 return (size + BlockSize - 1) / BlockSize;
\r
101 UInt32 ResetInterval;
\r
104 CResetTable ResetTable;
\r
106 UInt32 GetNumDictBits() const
\r
108 if (Version == 2 || Version == 3)
\r
110 for (int i = 0; i <= 31; i++)
\r
111 if (((UInt32)1 << i) >= WindowSize)
\r
117 UInt64 GetFolderSize() const { return ResetTable.BlockSize * ResetInterval; };
\r
118 UInt64 GetFolder(UInt64 offset) const { return offset / GetFolderSize(); };
\r
119 UInt64 GetFolderPos(UInt64 folderIndex) const { return folderIndex * GetFolderSize(); };
\r
120 UInt64 GetBlockIndexFromFolderIndex(UInt64 folderIndex) const { return folderIndex * ResetInterval; };
\r
121 bool GetOffsetOfFolder(UInt64 folderIndex, UInt64 &offset) const
\r
123 UInt64 blockIndex = GetBlockIndexFromFolderIndex(folderIndex);
\r
124 if (blockIndex >= ResetTable.ResetOffsets.Size())
\r
126 offset = ResetTable.ResetOffsets[(int)blockIndex];
\r
129 bool GetCompressedSizeOfFolder(UInt64 folderIndex, UInt64 &size) const
\r
131 UInt64 blockIndex = GetBlockIndexFromFolderIndex(folderIndex);
\r
132 return ResetTable.GetCompressedSizeOfBlocks(blockIndex, ResetInterval, size);
\r
139 CByteBuffer ControlData;
\r
141 bool IsLzx() const;
\r
142 bool IsDes() const;
\r
143 AString GetGuidString() const;
\r
144 UString GetName() const;
\r
147 struct CSectionInfo
\r
150 UInt64 CompressedSize;
\r
151 UInt64 UncompressedSize;
\r
154 CObjectVector<CMethodInfo> Methods;
\r
156 bool IsLzx() const;
\r
157 UString GetMethodName() const;
\r
160 class CFilesDatabase: public CDatabase
\r
164 CRecordVector<int> Indices;
\r
165 CObjectVector<CSectionInfo> Sections;
\r
167 UInt64 GetFileSize(int fileIndex) const { return Items[Indices[fileIndex]].Size; }
\r
168 UInt64 GetFileOffset(int fileIndex) const { return Items[Indices[fileIndex]].Offset; }
\r
170 UInt64 GetFolder(int fileIndex) const
\r
172 const CItem &item = Items[Indices[fileIndex]];
\r
173 const CSectionInfo §ion = Sections[(int)item.Section];
\r
174 if (section.IsLzx())
\r
175 return section.Methods[0].LzxInfo.GetFolder(item.Offset);
\r
179 UInt64 GetLastFolder(int fileIndex) const
\r
181 const CItem &item = Items[Indices[fileIndex]];
\r
182 const CSectionInfo §ion = Sections[(int)item.Section];
\r
183 if (section.IsLzx())
\r
184 return section.Methods[0].LzxInfo.GetFolder(item.Offset + item.Size - 1);
\r
188 void HighLevelClear()
\r
197 CDatabase::Clear();
\r
205 class CProgressVirt
\r
208 STDMETHOD(SetTotal)(const UInt64 *numFiles) PURE;
\r
209 STDMETHOD(SetCompleted)(const UInt64 *numFiles) PURE;
\r
214 UInt64 _startPosition;
\r
215 ::CInBuffer _inBuffer;
\r
219 void ReadBytes(Byte *data, UInt32 size);
\r
220 void Skip(size_t size);
\r
221 UInt16 ReadUInt16();
\r
222 UInt32 ReadUInt32();
\r
223 UInt64 ReadUInt64();
\r
224 UInt64 ReadEncInt();
\r
225 void ReadString(int size, AString &s);
\r
226 void ReadUString(int size, UString &s);
\r
227 void ReadGUID(GUID &g);
\r
229 HRESULT ReadChunk(IInStream *inStream, UInt64 pos, UInt64 size);
\r
231 HRESULT ReadDirEntry(CDatabase &database);
\r
232 HRESULT DecompressStream(IInStream *inStream, const CDatabase &database, const AString &name);
\r
235 HRESULT OpenChm(IInStream *inStream, CDatabase &database);
\r
236 HRESULT OpenHelp2(IInStream *inStream, CDatabase &database);
\r
237 HRESULT OpenHighLevel(IInStream *inStream, CFilesDatabase &database);
\r
238 HRESULT Open2(IInStream *inStream, const UInt64 *searchHeaderSizeLimit, CFilesDatabase &database);
\r
239 HRESULT Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit, CFilesDatabase &database);
\r