Show neofczip.cpp syntax highlighted
/***************************************************************************
link.h - Automatic entry point for static lib
-------------------
begin : Thu Jun 03 2004
copyright : (C) 2004 by emedia-solutions wolf
email : markus@emedia-soltions-wolf.de
***************************************************************************
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is the NeoEngine, NeoFCZip, neofczip.cpp
The Initial Developer of the Original Code is Markus Wolf.
Portions created by Markus Wolf are Copyright (C) 2004
emedia-solutions wolf. All Rights Reserved.
***************************************************************************/
#include "neofczip.h"
#include "link.h"
#include <neoengine/file.h>
#include <neoengine/package.h>
#include <neoengine/logstream.h>
#include "zlib.h"
using namespace std;
using namespace NeoEngine;
namespace NeoZIP
{
#define ZIPEXPORT
ModuleStatic *g_pkStaticModule = 0;
//------------------------------------------------------------------------
ZIPEXPORT FileCodec *LoadFileCodec()
{
return new NeoZIP::FileCodec();
}
//------------------------------------------------------------------------
ZIPEXPORT int Initialize()
{
return 0;
}
//------------------------------------------------------------------------
ZIPEXPORT int Shutdown()
{
delete g_pkStaticModule;
return 0;
}
//------------------------------------------------------------------------
ZIPEXPORT void GetVersion( std::string *pstrName, int *piMajor, int *piMinor, int *piRevision )
{
*pstrName = "NeoFCZip";
*piMajor = NEOENGINEVERSION_MAJOR;
*piMinor = NEOENGINEVERSION_MINOR;
*piRevision = NEOENGINEVERSION_REVISION;
}
//----------------------------------------------------------------------------
FileCodec::FileCodec() :
NeoEngine::FileCodec( "zip compressed file" )
{
neolog << LogLevel( INFO ) << "Loading zip file codec" << endl << " Based on the zlib library, copyright (C) 1995-2002, Jean-loup Gailly and Mark Adler" << endl << " For license details, see the LICENSE" << endl;
m_iFileFlag = Package::FILEFLAG_ZIP_COMPRESSED;
}
//----------------------------------------------------------------------------
bool FileCodec::IsType( File *pkFile )
{
string strID;
char szID[3] = { 0, 0, 0 };
bool bBinary = pkFile->SetBinary( true );
int iOffset = pkFile->Tellg();
if( iOffset != 0 )
{
pkFile->Seekg( 0, ios_base::beg );
}
pkFile->Read( &szID, 2 );
pkFile->Seekg( iOffset, ios_base::beg );
pkFile->SetBinary( bBinary );
if( ( strID = szID ) != "PK" )
{
return false;
}
return true;
}
//----------------------------------------------------------------------------
int FileCodec::LoadFileData( File *pkFile, int iSrcSize, void *pData, int *piSize )
{
unsigned long iDestLen = ( unsigned long )*piSize;
unsigned int iSrcLen = iSrcSize;
unsigned char *pucSrcBuf = new unsigned char[ iSrcLen ];
int iRet = -1;
unsigned int uiCurPos = pkFile->Tellg();
pkFile->Read( pucSrcBuf, iSrcLen );
pkFile->Seekg( uiCurPos, ios_base::beg );
int iZRet;
z_stream kStream;
memset( &kStream, 0, sizeof( z_stream ) );
iZRet = inflateInit2( &kStream, -MAX_WBITS );
if ( iZRet == Z_OK )
{
kStream.next_out = ( Bytef* )pData;
kStream.avail_out = iDestLen;
kStream.next_in = ( Bytef* )pucSrcBuf;
kStream.avail_in = iSrcLen;
iZRet = inflate( &kStream, Z_FINISH );
if ( kStream.total_out == iDestLen )
{
iRet = 0;
*piSize = iDestLen;
} else
{
neolog << LogLevel( ERROR ) << "*** Unexpected end of stream" << endl;
neolog << LogLevel( ERROR ) << "*** Unable to uncompress ZIP file: Uncompress failed [" << iZRet << "]" << endl;
}
} else
{
neolog << LogLevel( ERROR ) << "*** Unable to init uncompress ZIP file: Uncompress failed [" << iZRet << "]" << endl;
}
delete [] pucSrcBuf;
return iRet;
}
//------------------------------------------------------------------------
Link::Link()
{
#if defined(WIN32) && defined(_DEBUG)
g_pkStaticModule = new ModuleStatic( "neofczip_debug" );
#else
g_pkStaticModule = new ModuleStatic( "neofczip" );
#endif
g_pkStaticModule->m_Symbols.Insert( "LoadFileCodec", (void**)LoadFileCodec );
g_pkStaticModule->m_Symbols.Insert( "GetVersion", (void**)GetVersion );
g_pkStaticModule->m_Symbols.Insert( "Initialize", (void**)Initialize );
g_pkStaticModule->m_Symbols.Insert( "Shutdown", (void**)Shutdown );
NeoEngine::Core::GetModuleManager()->InsertModule( g_pkStaticModule );
}
}; // namespace NeoZIP
See more files for this project here