aboutsummaryrefslogtreecommitdiff
path: root/mp/src/public/tier1/lzmaDecoder.h
diff options
context:
space:
mode:
authorJohn Schoenick <[email protected]>2015-09-09 18:35:41 -0700
committerJohn Schoenick <[email protected]>2015-09-09 18:35:41 -0700
commit0d8dceea4310fde5706b3ce1c70609d72a38efdf (patch)
treec831ef32c2c801a5c5a80401736b52c7b5a528ec /mp/src/public/tier1/lzmaDecoder.h
parentUpdated the SDK with the latest code from the TF and HL2 branches. (diff)
downloadsource-sdk-2013-master.tar.xz
source-sdk-2013-master.zip
Updated the SDK with the latest code from the TF and HL2 branches.HEADmaster
Diffstat (limited to 'mp/src/public/tier1/lzmaDecoder.h')
-rw-r--r--mp/src/public/tier1/lzmaDecoder.h77
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
-