Add infos into target window
[ryzomcore.git] / ryzom / client / src / login_xdelta.h
blob7f057e44cb1569cd6eca474dc86555ca1afefe66
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef CL_LOGIN_XDELTA_H
18 #define CL_LOGIN_XDELTA_H
20 #include "nel/misc/types_nl.h"
21 #include "nel/misc/md5.h"
22 #include <string>
23 #include <zlib.h>
25 #define XDELTA_PREFIX_LEN 8
26 #define XDELTA_HEADER_WORDS 6
27 #define XDELTA_HEADER_SPACE (XDELTA_HEADER_WORDS*4)
28 #define XDELTA_110_PREFIX "%XDZ004%"
29 #define XDELTA_FLAG_NO_VERIFY 1
30 #define XDELTA_FLAG_FROM_COMPRESSED 2
31 #define XDELTA_FLAG_TO_COMPRESSED 4
32 #define XDELTA_FLAG_PATCH_COMPRESSED 8
34 #define XDELTA_TYPE_CHECKSUM ((1<<(1+8))+3)
35 #define XDELTA_TYPE_INDEX ((1<<(2+8))+3)
36 #define XDELTA_TYPE_SOURCEINFO ((1<<(3+8))+3)
37 #define XDELTA_TYPE_CONTROL ((1<<(7+8))+3)
38 #define XDELTA_TYPE_INSTRUCTION ((1<<(8+8))+3)
40 class CXDPFileReader;
42 /**
43 * Class representing the xdelta control
44 * it can be 2 sources max : the patch and the file to patch
45 * Applying patch is copying from the source 'Index' at offset 'Offset' an amount of data
46 * of length 'Length'.
47 * \author Matthieu 'TrapII' Besson
48 * \author Nevrax France
49 * \date July 2004
51 struct SXDeltaCtrl
53 struct SSourceInfo
55 std::string Name;
56 NLMISC::CHashKeyMD5 MD5;
57 uint32 Len;
58 bool IsData;
59 bool Sequential;
60 uint32 Position;
61 uint32 Copies;
62 uint32 CopyLength;
64 bool read(CXDPFileReader &fr);
67 struct SInstruction
69 uint32 Index;
70 uint32 Offset;
71 uint32 Length;
73 bool read(CXDPFileReader &fr);
76 NLMISC::CHashKeyMD5 ToMD5;
77 uint32 ToLen;
78 bool HasData;
79 std::vector<SSourceInfo> SourceInfo;
80 std::vector<SInstruction> Inst;
82 bool read(CXDPFileReader &fr);
85 /**
86 * Class representing a delta patch
87 * We read only the 1.1 version. 'Compressed From' and 'Compressed To' are not supported.
88 * \author Matthieu 'TrapII' Besson
89 * \author Nevrax France
90 * \date July 2004
92 class CXDeltaPatch
94 public:
96 enum TApplyResult
98 ApplyResult_Ok = 0,
99 ApplyResult_DiskFull,
100 ApplyResult_WriteError,
101 ApplyResult_UnsupportedXDeltaFormat,
102 ApplyResult_Error, // misc error
105 // Callback progress for the file patching
106 class ICallBack
108 public:
109 // f is from 0 to 1 (0% to 100% (complete))
110 virtual void progress(float f)=0;
113 // Tools
114 static TApplyResult apply( const std::string &sPatchFilename, const std::string &sFileToPatchFilename,
115 const std::string &sOutputFilename, std::string &errorMsg, ICallBack *pCallBack = NULL);
116 static bool info(const std::string &sPatchFilename);
119 // Load a patch file
120 bool load(const std::string &sFilename);
122 TApplyResult apply(const std::string &sFileToPatch, const std::string &sFileOutput, std::string &errorMsg);
124 bool isNoVerify() { return (_Flags&XDELTA_FLAG_NO_VERIFY)!=0; }
125 bool isFromCompressed() { return (_Flags&XDELTA_FLAG_FROM_COMPRESSED)!=0; }
126 bool isToCompressed() { return (_Flags&XDELTA_FLAG_TO_COMPRESSED)!=0; }
127 bool isPatchCompressed() { return (_Flags&XDELTA_FLAG_PATCH_COMPRESSED)!=0; }
129 const std::string &getToName() const { return _ToName; }
130 const std::string &getFromName() const { return _FromName; }
131 const SXDeltaCtrl &getCtrl() const { return _Ctrl; }
133 bool checkIntegrity (CXDPFileReader &rFR, const NLMISC::CHashKeyMD5 &md5, uint32 nLength);
135 private:
136 std::string _FileName;
138 uint32 _Flags;
139 std::string _Version; // Look XDELTA_FLAG_*
140 uint32 _HeaderOffset;
141 uint32 _CtrlOffset;
143 std::string _FromName;
144 std::string _ToName;
146 SXDeltaCtrl _Ctrl;
148 static ICallBack *_CallBack;
152 * Class representing a stream
153 * Help us to read from zipped or not file seemlessly
154 * \author Matthieu 'TrapII' Besson
155 * \author Nevrax France
156 * \date July 2004
158 class CXDPFileReader
160 public:
161 CXDPFileReader();
162 ~CXDPFileReader();
163 bool init(const std::string &sFilename, sint32 nLowerBound, sint32 nUpperBound, bool bCompressed);
164 bool read(uint8 *pBuf, sint32 nSize);
165 bool readUInt32(uint32 &val);
166 bool readUInt(uint32 &val);
167 bool readBool(bool &val);
168 bool readString(std::string &s);
169 uint32 getFileSize();
170 bool seek(uint32 pos);
171 private:
172 sint32 _LowerBound, _UpperBound;
173 bool _Compressed;
174 FILE *_File;
175 gzFile _GzFile;
177 void freeZipMem();
178 bool _Optimize;
179 uint32 _OptimPage;
180 std::vector<uint8*> _ZipMem;
181 sint32 _Pos;
186 #endif // CL_LOGIN_XDELTA_H