diff options
Diffstat (limited to 'mp/src/public/tier1/lzmaDecoder.h')
| -rw-r--r-- | mp/src/public/tier1/lzmaDecoder.h | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/mp/src/public/tier1/lzmaDecoder.h b/mp/src/public/tier1/lzmaDecoder.h index 51ecfd1a..6f4b87fd 100644 --- a/mp/src/public/tier1/lzmaDecoder.h +++ b/mp/src/public/tier1/lzmaDecoder.h @@ -1,15 +1,22 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// // -// LZMA Decoder. Designed for run time decoding. +// LZMA Codec interface for engine. // -// LZMA SDK 4.43 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01) -// http://www.7-zip.org/ +// LZMA SDK 9.38 beta +// 2015-01-03 : Igor Pavlov : Public domain +// http://www.7-zip.org/ // -//=====================================================================================// +//========================================================================// #ifndef _LZMADECODER_H #define _LZMADECODER_H #pragma once +// Thanks for the useful define namespacing, LZMA +#include "../../utils/lzma/C/7zVersion.h" +#define LZMA_SDK_VERSION_MAJOR MY_VER_MAJOR +#define LZMA_SDK_VERSION_MINOR MY_VER_MINOR + #if !defined( _X360 ) #define LZMA_ID (('A'<<24)|('M'<<16)|('Z'<<8)|('L')) #else @@ -27,15 +34,69 @@ struct lzma_header_t }; #pragma pack() +class CLZMAStream; + class CLZMA { public: - unsigned int Uncompress( unsigned char *pInput, unsigned char *pOutput ); - bool IsCompressed( unsigned char *pInput ); - unsigned int GetActualSize( unsigned char *pInput ); + static unsigned int Uncompress( unsigned char *pInput, unsigned char *pOutput ); + static bool IsCompressed( unsigned char *pInput ); + static unsigned int GetActualSize( unsigned char *pInput ); +}; + +// For files besides the implementation, we forward declare a dummy struct. We can't unconditionally forward declare +// this because LzmaEnc.h typedefs this directly to an unnamed struct :-/ +#ifndef CLzmaDec_t +struct _CLzmaDec_t; +#define CLzmaDec_t struct _CLzmaDec_t +#endif + +class CLZMAStream +{ +public: + CLZMAStream(); + ~CLZMAStream(); + + // Initialize a stream to read data from a LZMA style zip file, passing the original size from the zip headers. + // Streams with a source-engine style header (lzma_header_t) do not need an init call. + void InitZIPHeader( unsigned int nCompressedSize, unsigned int nOriginalSize ); + + // Attempt to read up to nMaxInputBytes from the compressed stream, writing up to nMaxOutputBytes to pOutput. + // Makes progress until blocked on input or output. + // Returns false if read stops due to an error or if called at EOF (GetExpectedBytesRemaining == 0) + bool Read( unsigned char *pInput, unsigned int nMaxInputBytes, + unsigned char *pOutput, unsigned int nMaxOutputBytes, + /* out */ unsigned int &nCompressedBytesRead, /* out */ unsigned int &nOutputBytesWritten ); + + // Get the expected uncompressed bytes yet to be read from this stream. Returns false if not yet known, such as + // before being fed the header. + bool GetExpectedBytesRemaining( /* out */ unsigned int &nBytesRemaining ); private: + enum eHeaderParse + { + eHeaderParse_OK, + eHeaderParse_Fail, + eHeaderParse_NeedMoreBytes + }; + + eHeaderParse TryParseHeader( unsigned char *pInput, unsigned int nBytesAvailable, /* out */ unsigned int &nBytesConsumed ); + + void FreeDecoderState(); + bool CreateDecoderState( const unsigned char *pProperties ); + + // Init from a zip-embedded LZMA stream. Requires the original size be passed from zip headers. + CLzmaDec_t *m_pDecoderState; + + unsigned int m_nActualSize; + unsigned int m_nActualBytesRead; + unsigned int m_nCompressedSize; + unsigned int m_nCompressedBytesRead; + + // If we have read past the header + bool m_bParsedHeader : 1; + // If InitZIPHeader() was called. We're expecting a zip-style header and have size information. + bool m_bZIPStyleHeader : 1; }; #endif - |