1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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"
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)
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
47 * \author Matthieu 'TrapII' Besson
48 * \author Nevrax France
56 NLMISC::CHashKeyMD5 MD5
;
64 bool read(CXDPFileReader
&fr
);
73 bool read(CXDPFileReader
&fr
);
76 NLMISC::CHashKeyMD5 ToMD5
;
79 std::vector
<SSourceInfo
> SourceInfo
;
80 std::vector
<SInstruction
> Inst
;
82 bool read(CXDPFileReader
&fr
);
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
100 ApplyResult_WriteError
,
101 ApplyResult_UnsupportedXDeltaFormat
,
102 ApplyResult_Error
, // misc error
105 // Callback progress for the file patching
109 // f is from 0 to 1 (0% to 100% (complete))
110 virtual void progress(float f
)=0;
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
);
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
);
136 std::string _FileName
;
139 std::string _Version
; // Look XDELTA_FLAG_*
140 uint32 _HeaderOffset
;
143 std::string _FromName
;
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
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
);
172 sint32 _LowerBound
, _UpperBound
;
180 std::vector
<uint8
*> _ZipMem
;
186 #endif // CL_LOGIN_XDELTA_H