- FEATURE : First version of PK3 format loader.

- FEATURE : First prototype of Quake 3 BSP format loader.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@755 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
kimmi 2010-06-18 17:36:46 +00:00
parent ca645a493c
commit f017b5a4a4
15 changed files with 3527 additions and 10 deletions

View File

@ -45,6 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Exceptional.h" #include "Exceptional.h"
#include <string> #include <string>
#include <map>
#include <vector>
#include "./../include/aiTypes.h" #include "./../include/aiTypes.h"
struct aiScene; struct aiScene;
@ -53,6 +55,10 @@ namespace Assimp {
class IOSystem; class IOSystem;
class Importer; class Importer;
class BaseImporter;
class BaseProcess;
class SharedPostProcessInfo;
class IOStream;
// utility to do char4 to uint32 in a portable manner // utility to do char4 to uint32 in a portable manner
#define AI_MAKE_MAGIC(string) ((uint32_t)((string[0] << 24) + \ #define AI_MAKE_MAGIC(string) ((uint32_t)((string[0] << 24) + \

View File

@ -370,12 +370,15 @@ SOURCE_GROUP( Q3D FILES
Q3DLoader.h Q3DLoader.h
) )
#SOURCE_GROUP( Q3BSP FILES SOURCE_GROUP( Q3BSP FILES
#Q3BSPFileParser.h Q3BSPFileData.h
#Q3BSPFileParser.cpp Q3BSPFileParser.h
#Q3BSPFileImporter.h Q3BSPFileParser.cpp
#Q3BSPFileImporter.cpp Q3BSPFileImporter.h
#) Q3BSPFileImporter.cpp
Q3BSPZipArchive.h
Q3BSPZipArchive.cpp
)
SOURCE_GROUP( Raw FILES SOURCE_GROUP( Raw FILES
RawLoader.cpp RawLoader.cpp
@ -450,6 +453,14 @@ SOURCE_GROUP( zlib FILES
../contrib/zlib/zutil.h ../contrib/zlib/zutil.h
) )
SOURCE_GROUP( unzip FILES
../contrib/unzip/crypt.h
../contrib/unzip/ioapi.c
../contrib/unzip/ioapi.h
../contrib/unzip/unzip.c
../contrib/unzip/unzip.h
)
ADD_LIBRARY( assimp SHARED ADD_LIBRARY( assimp SHARED
3DSConverter.cpp 3DSConverter.cpp
3DSHelper.h 3DSHelper.h
@ -586,10 +597,13 @@ ADD_LIBRARY( assimp SHARED
ProcessHelper.h ProcessHelper.h
Q3DLoader.cpp Q3DLoader.cpp
Q3DLoader.h Q3DLoader.h
# Q3BSPFileParser.h Q3BSPFileData.h
# Q3BSPFileParser.cpp Q3BSPFileParser.h
# Q3BSPFileImporter.h Q3BSPFileParser.cpp
# Q3BSPFileImporter.cpp Q3BSPFileImporter.h
Q3BSPFileImporter.cpp
Q3BSPZipArchive.h
Q3BSPZipArchive.cpp
RawLoader.cpp RawLoader.cpp
RawLoader.h RawLoader.h
RemoveComments.cpp RemoveComments.cpp
@ -677,6 +691,11 @@ ADD_LIBRARY( assimp SHARED
../contrib/zlib/zutil.c ../contrib/zlib/zutil.c
../contrib/zlib/zutil.h ../contrib/zlib/zutil.h
../contrib/ConvertUTF/ConvertUTF.c ../contrib/ConvertUTF/ConvertUTF.c
../contrib/unzip/crypt.h
../contrib/unzip/ioapi.c
../contrib/unzip/ioapi.h
../contrib/unzip/unzip.c
../contrib/unzip/unzip.h
Subdivision.cpp Subdivision.cpp
Subdivision.h Subdivision.h
Vertex.h Vertex.h

View File

@ -171,6 +171,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ASSIMP_BUILD_NO_COB_IMPORTER #ifndef ASSIMP_BUILD_NO_COB_IMPORTER
# include "BlenderLoader.h" # include "BlenderLoader.h"
#endif #endif
#ifndef ASSIMP_BUILD_NO_Q3BSP_IMPORTER
# include "Q3BSPFileImporter.h"
#endif
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Post processing-Steps // Post processing-Steps
@ -404,6 +407,9 @@ Importer::Importer()
#if (!defined ASSIMP_BUILD_NO_BLEND_IMPORTER) #if (!defined ASSIMP_BUILD_NO_BLEND_IMPORTER)
pimpl->mImporter.push_back( new BlenderImporter()); pimpl->mImporter.push_back( new BlenderImporter());
#endif #endif
#if (!defined ASSIMP_BUILD_NO_Q3BSP_IMPORTER)
pimpl->mImporter.push_back( new Q3BSPFileImporter );
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Add an instance of each post processing step here in the order // Add an instance of each post processing step here in the order

View File

@ -0,0 +1,194 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
#ifndef ASSIMP_Q§BSPFILEDATA_H_INC
#define ASSIMP_Q§BSPFILEDATA_H_INC
#include <vector>
namespace Assimp
{
namespace Q3BSP
{
static const unsigned int CE_BSP_LIGHTMAPSIZE = 128*128*3; ///< = 128( width ) * 128 ( height ) * 3 ( channels / RGB ).
static const int VERION_Q3LEVEL = 46; ///< Supported version.
/// Integer vector.
struct ceVec3i
{
int x, y, z;
ceVec3i(): x( 0 ), y( 0 ), z( 0 ) { /* empty */ }
ceVec3i( int iX, int iY=0, int iZ=0) : x( iX ), y( iY ), z( iZ ) { /* empty */ }
};
/// Fileheader
struct sQ3BSPHeader
{
char strID[ 4 ]; //!< Should be "IBSP"
int iVersion; //!< 46 for standard levels
};
/// Descripes an entry.
struct sQ3BSPLump
{
int iOffset; ///< Offset from startpointer of file
int iSize; ///< Size fo part
};
struct vec2f
{
float x,y;
};
struct vec3f
{
float x, y, z;
};
/// Vertex of a Q3 level
struct sQ3BSPVertex
{
vec3f vPosition; ///< Position of vertex
vec2f vTexCoord; ///< (u,v) Texturecoordinate of detailtexture
vec2f vLightmap; ///< (u,v) Texturecoordinate of lightmap
vec3f vNormal; ///< vertex normale
unsigned char bColor[ 4 ]; ///< Color in RGBA
};
/// A face in bsp format info
struct sQ3BSPFace
{
int iTextureID; ///< Index in texture array
int iEffect; ///< Index in effectarray (-1 = no effect)
int iType; ///< 1=Polygon, 2=Patch, 3=Mesh, 4=Billboard
int iVertexIndex; ///< Start index of polygon
int iNumOfVerts; ///< Number of vertices
int iMeshVertexIndex; ///< Index of first mesh vertex
int iNumOfMeshVerts; ///< Anzahl der Meshvertices
int iLightmapID; ///< Index in das Lightmaparray
int iLMapCorner[ 2 ]; ///< Die Ecke der Lightmap in der Textur
int iLMapSize[ 2 ]; ///< Size of the lightmap stored on the texture
vec3f vLMapPos; ///< 3D-Ursprung der Lightmap
vec3f vLMapVecs[ 2 ]; ///< 3D-s-t-Vektoren
vec3f vNormal; ///< Polygonnormale
int patchWidth, patchHeight; ///< bezier patch
};
/// A quake3 texture name.
struct sQ3BSPTexture
{
char strName[ 64 ]; //!< Name of the texture without extention
int iFlags; //!< Not used
int iContents; //!< Not used
};
//! A lightmap of the level, size 128 x 128, RGB components
struct sQ3BSPLightmap
{
unsigned char bLMapData[CE_BSP_LIGHTMAPSIZE];
sQ3BSPLightmap() { memset(bLMapData, 0, CE_BSP_LIGHTMAPSIZE); }
};
struct sRenderVertex
{
vec3f vPosition;
vec2f vTC;
vec2f vTCLightmap;
};
struct SubPatch
{
std::vector<sRenderVertex> controlPoints;
std::vector<sRenderVertex> vertices;
std::vector<size_t> indices;
int lightmapID;
};
enum eLumps
{
kEntities = 0,
kTextures,
kPlanes,
kNodes,
kLeafs,
kLeafFaces,
kLeafBrushes,
kModels,
kBrushes,
kBrushSides,
kVertices,
kMeshVerts,
kShaders,
kFaces,
kLightmaps,
kLightVolumes,
kVisData,
kMaxLumps
};
struct Q3BSPModel
{
std::vector<unsigned char> m_Data;
std::vector<sQ3BSPLump*> m_Lumps;
std::vector<sQ3BSPVertex*> m_Vertices;
std::vector<sQ3BSPFace*> m_Faces;
std::vector<int> m_Indices;
std::vector<sQ3BSPTexture*> m_Textures;
std::vector<sQ3BSPLightmap*> m_Lightmaps;
std::vector<char> m_EntityData;
Q3BSPModel() :
m_Data(),
m_Lumps(),
m_Vertices(),
m_Faces(),
m_Indices(),
m_Textures(),
m_Lightmaps(),
m_EntityData()
{
// empty
}
};
}
}
#endif // ASSIMP_Q§BSPFILEDATA_H_INC

View File

@ -0,0 +1,158 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
#include "AssimpPCH.h"
#ifndef ASSIMP_BUILD_NO_Q3BSP_IMPORTER
#include "DefaultIOSystem.h"
#include "Q3BSPFileImporter.h"
#include "Q3BSPZipArchive.h"
#include "Q3BSPFileParser.h"
#include "../contrib/zlib/zlib.h"
#include <vector>
namespace Assimp
{
using namespace Q3BSP;
// ------------------------------------------------------------------------------------------------
Q3BSPFileImporter::Q3BSPFileImporter()
{
}
// ------------------------------------------------------------------------------------------------
Q3BSPFileImporter::~Q3BSPFileImporter()
{
}
// ------------------------------------------------------------------------------------------------
bool Q3BSPFileImporter::CanRead( const std::string& rFile, IOSystem* pIOHandler, bool checkSig ) const
{
bool isBSPData = false;
if ( checkSig )
isBSPData = SimpleExtensionCheck( rFile, "pk3" );
return isBSPData;
}
// ------------------------------------------------------------------------------------------------
void Q3BSPFileImporter::GetExtensionList(std::set<std::string>& extensions)
{
extensions.insert("pk3");
}
// ------------------------------------------------------------------------------------------------
void Q3BSPFileImporter::InternReadFile(const std::string &rFile, aiScene* pScene, IOSystem* pIOHandler)
{
Q3BSPZipArchive Archive( rFile );
if ( !Archive.isOpen() )
{
throw new DeadlyImportError( "Failed to open file " + rFile + "." );
}
std::string archiveName( "" ), mapName( "" );
separateMapName( rFile, archiveName, mapName );
if ( mapName.empty() )
{
if ( !findFirstMapInArchive( Archive, mapName ) )
{
return;
}
}
Q3BSPFileParser fileParser( mapName, &Archive );
Q3BSPModel *pBSPModel = fileParser.getModel();
if ( NULL != pBSPModel )
{
}
}
// ------------------------------------------------------------------------------------------------
void Q3BSPFileImporter::separateMapName( const std::string &rImportName, std::string &rArchiveName,
std::string &rMapName )
{
rArchiveName = "";
rMapName = "";
if ( rImportName.empty() )
return;
std::string::size_type pos = rImportName.rfind( "," );
if ( std::string::npos == pos )
{
rArchiveName = rImportName;
return;
}
rArchiveName = rImportName.substr( 0, pos );
rMapName = rImportName.substr( pos, rImportName.size() - pos - 1 );
}
// ------------------------------------------------------------------------------------------------
bool Q3BSPFileImporter::findFirstMapInArchive( Q3BSPZipArchive &rArchive, std::string &rMapName )
{
rMapName = "";
std::vector<std::string> fileList;
rArchive.getFileList( fileList );
if ( fileList.empty() )
return false;
for ( std::vector<std::string>::iterator it = fileList.begin(); it != fileList.end();
++it )
{
std::string::size_type pos = (*it).find( "maps/" );
if ( std::string::npos != pos )
{
std::string::size_type extPos = (*it).find( ".bsp" );
if ( std::string::npos != extPos )
{
rMapName = *it;
return true;
}
}
}
return false;
}
// ------------------------------------------------------------------------------------------------
} // Namespace Assimp
#endif // ASSIMP_BUILD_NO_Q3BSP_IMPORTER

View File

@ -0,0 +1,78 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
#ifndef ASSIMP_Q3BSPFILEIMPORTER_H_INC
#define ASSIMP_Q3BSPFILEIMPORTER_H_INC
#include "BaseImporter.h"
namespace Assimp
{
namespace Q3BSP
{
class Q3BSPZipArchive;
}
class Q3BSPFileImporter : BaseImporter
{
friend class Importer;
protected:
/// \brief Default constructor,
Q3BSPFileImporter();
/// \brief Destructor.
~Q3BSPFileImporter();
public:
/// \brief Returns whether the class can handle the format of the given file.
/// \remark See BaseImporter::CanRead() for details.
bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig ) const;
private:
void GetExtensionList(std::set<std::string>& extensions);
void InternReadFile(const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
void separateMapName( const std::string &rImportName, std::string &rArchiveName, std::string &rMapName );
bool findFirstMapInArchive( Q3BSP::Q3BSPZipArchive &rArchive, std::string &rMapName );
};
} // Namespace Assimp
#endif // ASSIMP_Q3BSPFILEIMPORTER_H_INC

View File

@ -0,0 +1,265 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
#include "AssimpPCH.h"
#include "Q3BSPFileParser.h"
#include "DefaultIOSystem.h"
#include "Q3BSPFileData.h"
#include "Q3BSPZipArchive.h"
#include <vector>
namespace Assimp
{
using namespace Q3BSP;
// ------------------------------------------------------------------------------------------------
Q3BSPFileParser::Q3BSPFileParser( const std::string &rMapName, Q3BSPZipArchive *pZipArchive ) :
m_sOffset( 0 ),
m_Data(),
m_pModel( NULL ),
m_pZipArchive( pZipArchive )
{
ai_assert( NULL != m_pZipArchive );
ai_assert( !rMapName.empty() );
if ( !readData( rMapName ) )
return;
m_pModel = new Q3BSPModel;
if ( !parseFile() )
{
delete m_pModel;
m_pModel = NULL;
}
}
// ------------------------------------------------------------------------------------------------
Q3BSPFileParser::~Q3BSPFileParser()
{
delete m_pModel;
m_pModel = NULL;
}
// ------------------------------------------------------------------------------------------------
Q3BSP::Q3BSPModel *Q3BSPFileParser::getModel() const
{
return m_pModel;
}
// ------------------------------------------------------------------------------------------------
bool Q3BSPFileParser::readData(const std::string &rMapName)
{
if ( !m_pZipArchive->Exists( rMapName.c_str() ) )
return false;
IOStream *pMapFile = m_pZipArchive->Open( rMapName.c_str() );
if ( NULL == pMapFile )
return false;
const size_t size = pMapFile->FileSize();
m_Data.resize( size );
const size_t readSize = pMapFile->Read( &m_Data[0], sizeof( char ), size );
if ( readSize != size )
{
m_Data.clear();
return false;
}
m_pZipArchive->Close( pMapFile );
return true;
}
// ------------------------------------------------------------------------------------------------
bool Q3BSPFileParser::parseFile()
{
if ( m_Data.empty() )
return false;
if ( !validateFormat() )
return false;
getLumps();
countLumps();
// Read in Vertices
getVertices();
// Read in Indices
getIndices();
// Read Faces
getFaces();
// Read Textures
getTextures();
// Read Lightmaps
getLightMaps();
// Load the entities
getEntities();
return true;
}
// ------------------------------------------------------------------------------------------------
bool Q3BSPFileParser::validateFormat()
{
sQ3BSPHeader *pHeader = (sQ3BSPHeader*) &m_Data[ 0 ];
m_sOffset += sizeof( sQ3BSPHeader );
// Version and identify string validation
if (pHeader->strID[ 0 ] != 'I' || pHeader->strID[ 1 ] != 'B' || pHeader->strID[ 2 ] != 'S'
|| pHeader->strID[ 3 ] != 'P')
{
return false;
}
return true;
}
// ------------------------------------------------------------------------------------------------
void Q3BSPFileParser::getLumps()
{
size_t Offset = m_sOffset;
m_pModel->m_Lumps.resize( kMaxLumps );
for ( size_t idx=0; idx < kMaxLumps; idx++ )
{
sQ3BSPLump *pLump = new sQ3BSPLump;
memcpy( pLump, &m_Data[ Offset ], sizeof( sQ3BSPLump ) );
Offset += sizeof( sQ3BSPLump );
m_pModel->m_Lumps[ idx ] = pLump;
}
}
// ------------------------------------------------------------------------------------------------
void Q3BSPFileParser::countLumps()
{
m_pModel->m_Vertices.resize( m_pModel->m_Lumps[ kVertices ]->iSize / sizeof( sQ3BSPVertex ) );
m_pModel->m_Indices.resize( m_pModel->m_Lumps[ kMeshVerts ]->iSize / sizeof( int ) );
m_pModel->m_Faces.resize( m_pModel->m_Lumps[ kFaces ]->iSize / sizeof( sQ3BSPFace ) );
m_pModel->m_Textures.resize( m_pModel->m_Lumps[ kTextures ]->iSize / sizeof( sQ3BSPTexture ) );
m_pModel->m_Lightmaps.resize( m_pModel->m_Lumps[ kLightmaps ]->iSize / sizeof( sQ3BSPLightmap ) );
}
// ------------------------------------------------------------------------------------------------
void Q3BSPFileParser::getVertices()
{
size_t Offset = m_pModel->m_Lumps[ kVertices ]->iOffset;
for ( size_t idx = 0; idx < m_pModel->m_Vertices.size(); idx++ )
{
sQ3BSPVertex *pVertex = new sQ3BSPVertex;
memcpy( pVertex, &m_Data[ Offset ], sizeof( sQ3BSPVertex ) );
Offset += sizeof( sQ3BSPVertex );
m_pModel->m_Vertices[ idx ] = pVertex;
}
}
// ------------------------------------------------------------------------------------------------
void Q3BSPFileParser::getIndices()
{
ai_assert( NULL != m_pModel );
sQ3BSPLump *lump = m_pModel->m_Lumps[ kMeshVerts ];
size_t Offset = (size_t) lump->iOffset;
const size_t nIndices = lump->iSize / sizeof( int );
m_pModel->m_Indices.resize( nIndices );
memcpy( &m_pModel->m_Indices[ 0 ], &m_Data[ Offset ], lump->iSize );
}
// ------------------------------------------------------------------------------------------------
void Q3BSPFileParser::getFaces()
{
ai_assert( NULL != m_pModel );
size_t Offset = m_pModel->m_Lumps[ kFaces ]->iOffset;
for ( size_t idx = 0; idx < m_pModel->m_Faces.size(); idx++ )
{
sQ3BSPFace *pFace = new sQ3BSPFace;
memcpy( pFace, &m_Data[ Offset ], sizeof( sQ3BSPFace ) );
m_pModel->m_Faces[ idx ] = pFace;
Offset += sizeof( sQ3BSPFace );
}
}
// ------------------------------------------------------------------------------------------------
void Q3BSPFileParser::getTextures()
{
ai_assert( NULL != m_pModel );
size_t Offset = m_pModel->m_Lumps[ kTextures ]->iOffset;
for ( size_t idx=0; idx < m_pModel->m_Textures.size(); idx++ )
{
sQ3BSPTexture *pTexture = new sQ3BSPTexture;
memcpy( pTexture, &m_Data[ Offset ], sizeof(sQ3BSPTexture) );
m_pModel->m_Textures[ idx ] = pTexture;
Offset += sizeof(sQ3BSPTexture);
}
}
// ------------------------------------------------------------------------------------------------
void Q3BSPFileParser::getLightMaps()
{
ai_assert( NULL != m_pModel );
size_t Offset = m_pModel->m_Lumps[kLightmaps]->iOffset;
for ( size_t idx=0; idx < m_pModel->m_Lightmaps.size(); idx++ )
{
sQ3BSPLightmap *pLightmap = new sQ3BSPLightmap;
memcpy( pLightmap, &m_Data[ Offset ], sizeof( sQ3BSPLightmap ) );
Offset += sizeof( sQ3BSPLightmap );
//ChangeGamma( (unsigned char*) &pLightmap->bLMapData[ 0 ], sizeof( sQ3BSPLightmap ), 3.0f);
m_pModel->m_Lightmaps[ idx ] = pLightmap;
}
}
// ------------------------------------------------------------------------------------------------
void Q3BSPFileParser::getEntities()
{
int size = m_pModel->m_Lumps[ kEntities ]->iSize;
m_pModel->m_EntityData.resize( size );
size_t Offset = m_pModel->m_Lumps[ kEntities ]->iOffset;
memcpy( &m_pModel->m_EntityData[ 0 ], &m_Data[ Offset ], sizeof( char ) * size );
}
// ------------------------------------------------------------------------------------------------
} // Namespace Assimp

View File

@ -0,0 +1,89 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
#ifndef ASSIMP_Q3BSPFILEPARSER_H_INC
#define ASSIMP_Q3BSPFILEPARSER_H_INC
#include "BaseImporter.h"
#include <string>
namespace Assimp
{
namespace Q3BSP
{
class Q3BSPZipArchive;
struct Q3BSPModel;
class ZipFile;
}
// -------------------------------------------------------------------
// -------------------------------------------------------------------
class Q3BSPFileParser
{
public:
Q3BSPFileParser( const std::string &rMapName, Q3BSP::Q3BSPZipArchive *pZipArchive );
~Q3BSPFileParser();
Q3BSP::Q3BSPModel *getModel() const;
protected:
bool readData(const std::string &rMapName);
bool parseFile();
bool validateFormat();
void getLumps();
void countLumps();
void getVertices();
void getIndices();
void getFaces();
void getTextures();
void getLightMaps();
void getEntities();
private:
size_t m_sOffset;
std::vector<char> m_Data;
Q3BSP::Q3BSPModel *m_pModel;
Q3BSP::Q3BSPZipArchive *m_pZipArchive;
};
} // Namespace Assimp
#endif // ASSIMP_Q3BSPFILEPARSER_H_INC

View File

@ -0,0 +1,177 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
#include "Q3BSPZipArchive.h"
#include <algorithm>
#include <cassert>
namespace Assimp
{
namespace Q3BSP
{
// ------------------------------------------------------------------------------------------------
Q3BSPZipArchive::Q3BSPZipArchive( const std::string& rFile ) :
m_ZipFileHandle( NULL ),
m_FileList(),
m_bDirty( true )
{
if ( !rFile.empty() )
{
m_ZipFileHandle = unzOpen( rFile.c_str() );
if ( NULL != m_ZipFileHandle )
{
mapArchive();
}
}
}
// ------------------------------------------------------------------------------------------------
Q3BSPZipArchive::~Q3BSPZipArchive()
{
if ( NULL != m_ZipFileHandle )
unzClose( m_ZipFileHandle );
m_ZipFileHandle = NULL;
m_FileList.clear();
}
// ------------------------------------------------------------------------------------------------
bool Q3BSPZipArchive::isOpen() const
{
return ( NULL != m_ZipFileHandle );
}
// ------------------------------------------------------------------------------------------------
bool Q3BSPZipArchive::Exists( const char* pFile ) const
{
ai_assert( NULL != pFile );
std::string rFile( pFile );
std::vector<std::string>::const_iterator it = std::find( m_FileList.begin(), m_FileList.end(), rFile );
if ( m_FileList.end() == it )
return false;
return true;
}
// ------------------------------------------------------------------------------------------------
char Q3BSPZipArchive::getOsSeparator() const
{
return '/';
}
// ------------------------------------------------------------------------------------------------
IOStream *Q3BSPZipArchive::Open( const char* pFile, const char* pMode )
{
ai_assert( NULL != pFile );
std::string rItem( pFile );
std::vector<std::string>::iterator it = std::find( m_FileList.begin(), m_FileList.end(), rItem );
if ( m_FileList.end() == it )
return NULL;
ZipFile *pZipFile = new ZipFile( *it, m_ZipFileHandle );
m_ArchiveMap[ rItem ] = pZipFile;
return pZipFile;
}
// ------------------------------------------------------------------------------------------------
void Q3BSPZipArchive::Close( IOStream *pFile )
{
ai_assert( NULL != pFile );
std::map<std::string, IOStream*>::iterator it;
for ( it = m_ArchiveMap.begin(); it != m_ArchiveMap.end(); ++it )
{
if ( (*it).second == pFile )
{
ZipFile *pZipFile = reinterpret_cast<ZipFile*>( (*it).second );
delete pZipFile;
m_ArchiveMap.erase( it );
break;
}
}
}
// ------------------------------------------------------------------------------------------------
void Q3BSPZipArchive::getFileList( std::vector<std::string> &rFileList )
{
rFileList = m_FileList;
}
// ------------------------------------------------------------------------------------------------
bool Q3BSPZipArchive::mapArchive()
{
if ( NULL == m_ZipFileHandle )
return false;
if ( !m_bDirty )
return true;
if ( !m_FileList.empty() )
m_FileList.resize( 0 );
// At first ensure file is already open
if ( UNZ_OK == unzGoToFirstFile( m_ZipFileHandle ) )
{
char filename[ FileNameSize ];
unzGetCurrentFileInfo( m_ZipFileHandle, NULL, filename, FileNameSize, NULL, 0, NULL, 0 );
m_FileList.push_back( filename );
unzCloseCurrentFile( m_ZipFileHandle );
// Loop over all files
while ( unzGoToNextFile( m_ZipFileHandle ) != UNZ_END_OF_LIST_OF_FILE )
{
char filename[ FileNameSize ];
unzGetCurrentFileInfo( m_ZipFileHandle, NULL, filename, FileNameSize, NULL, 0, NULL, 0 );
m_FileList.push_back( filename );
unzCloseCurrentFile( m_ZipFileHandle );
}
}
std::sort( m_FileList.begin(), m_FileList.end() );
m_bDirty = false;
return true;
}
// ------------------------------------------------------------------------------------------------
} // Namespace Q3BSP
} // Namespace Assimp

View File

@ -0,0 +1,182 @@
/*
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2008, ASSIMP Development Team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the ASSIMP Development Team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
#ifndef AI_Q3BSP_ZIPARCHIVE_H_INC
#define AI_Q3BSP_ZIPARCHIVE_H_INC
#include "../contrib/unzip/unzip.h"
#include "../include/IOStream.h"
#include "../include/IOSystem.h"
#include <string>
#include <vector>
#include <map>
#include <cassert>
namespace Assimp
{
namespace Q3BSP
{
// ------------------------------------------------------------------------------------------------
/// \class ZipFile
/// \ingroup Assimp::Q3BSP
///
/// \brief
// ------------------------------------------------------------------------------------------------
class ZipFile : public IOStream
{
public:
ZipFile( const std::string &rFileName, unzFile zipFile ) :
m_Name( rFileName ),
m_zipFile( zipFile )
{
ai_assert( NULL != m_zipFile );
}
~ZipFile()
{
m_zipFile = NULL;
}
size_t Read(void* pvBuffer, size_t pSize, size_t pCount )
{
size_t bytes_read = 0;
if ( NULL == m_zipFile )
return bytes_read;
// search file and place file pointer there
if ( unzLocateFile( m_zipFile, m_Name.c_str(), 0 ) == UNZ_OK )
{
// get file size, etc.
unz_file_info fileInfo;
unzGetCurrentFileInfo( m_zipFile, &fileInfo, 0, 0, 0, 0, 0, 0 );
const size_t size = pSize * pCount;
assert( size <= fileInfo.uncompressed_size );
// The file has EXACTLY the size of uncompressed_size. In C
// you need to mark the last character with '\0', so add
// another character
unzOpenCurrentFile( m_zipFile );
bytes_read = unzReadCurrentFile( m_zipFile, pvBuffer, fileInfo.uncompressed_size);
if ( bytes_read < 0 || bytes_read != static_cast<size_t>( fileInfo.uncompressed_size ) )
{
return 0;
}
size_t filesize = fileInfo.uncompressed_size;
unzCloseCurrentFile( m_zipFile );
}
return bytes_read;
}
size_t Write(const void* pvBuffer, size_t pSize, size_t pCount)
{
return 0;
}
size_t FileSize() const
{
if ( NULL == m_zipFile )
return 0;
if ( unzLocateFile( m_zipFile, m_Name.c_str(), 0 ) == UNZ_OK )
{
unz_file_info fileInfo;
unzGetCurrentFileInfo( m_zipFile, &fileInfo, 0, 0, 0, 0, 0, 0 );
return fileInfo.uncompressed_size;
}
return 0;
}
aiReturn Seek(size_t pOffset, aiOrigin pOrigin)
{
return aiReturn_FAILURE;
}
size_t Tell() const
{
return 0;
}
void Flush()
{
// empty
}
private:
std::string m_Name;
unzFile m_zipFile;
};
// ------------------------------------------------------------------------------------------------
/// \class Q3BSPZipArchive
/// \ingroup Assimp::Q3BSP
///
/// \brief IMplements a zip archive like the WinZip archives. Will be also used to import data
/// from a P3K archive ( Quake level format ).
// ------------------------------------------------------------------------------------------------
class Q3BSPZipArchive : public Assimp::IOSystem
{
public:
static const unsigned int FileNameSize = 256;
public:
Q3BSPZipArchive( const std::string & rFile );
~Q3BSPZipArchive();
bool Exists( const char* pFile) const;
char getOsSeparator() const;
IOStream* Open(const char* pFile, const char* pMode = "rb");
void Close( IOStream* pFile);
bool isOpen() const;
void getFileList( std::vector<std::string> &rFileList );
private:
bool mapArchive();
private:
unzFile m_ZipFileHandle;
std::map<std::string, IOStream*> m_ArchiveMap;
std::vector<std::string> m_FileList;
bool m_bDirty;
};
// ------------------------------------------------------------------------------------------------
} // Namespace Q3BSP
} // Namespace Assimp
#endif // AI_Q3BSP_ZIPARCHIVE_H_INC

View File

@ -0,0 +1,132 @@
/* crypt.h -- base code for crypt/uncrypt ZIPfile
Version 1.01e, February 12th, 2005
Copyright (C) 1998-2005 Gilles Vollant
This code is a modified version of crypting code in Infozip distribution
The encryption/decryption parts of this source code (as opposed to the
non-echoing password parts) were originally written in Europe. The
whole source package can be freely distributed, including from the USA.
(Prior to January 2000, re-export from the US was a violation of US law.)
This encryption code is a direct transcription of the algorithm from
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
file (appnote.txt) is distributed with the PKZIP program (even in the
version without encryption capabilities).
If you don't need crypting in your application, just define symbols
NOCRYPT and NOUNCRYPT.
This code support the "Traditional PKWARE Encryption".
The new AES encryption added on Zip format by Winzip (see the page
http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
Encryption is not supported.
*/
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
/***********************************************************************
* Return the next byte in the pseudo-random sequence
*/
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
{
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem
* with any known compiler so far, though */
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
}
/***********************************************************************
* Update the encryption keys with the next byte of plain text
*/
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
{
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
{
register int keyshift = (int)((*(pkeys+1)) >> 24);
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
}
return c;
}
/***********************************************************************
* Initialize the encryption keys and the random header according to
* the given password.
*/
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
{
*(pkeys+0) = 305419896L;
*(pkeys+1) = 591751049L;
*(pkeys+2) = 878082192L;
while (*passwd != '\0') {
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
passwd++;
}
}
#define zdecode(pkeys,pcrc_32_tab,c) \
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
#define zencode(pkeys,pcrc_32_tab,c,t) \
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
#define RAND_HEAD_LEN 12
/* "last resort" source for second part of crypt seed pattern */
# ifndef ZCR_SEED2
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
# endif
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
const char *passwd; /* password string */
unsigned char *buf; /* where to write header */
int bufSize;
unsigned long* pkeys;
const unsigned long* pcrc_32_tab;
unsigned long crcForCrypting;
{
int n; /* index in random header */
int t; /* temporary */
int c; /* random byte */
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
static unsigned calls = 0; /* ensure different random header each time */
if (bufSize<RAND_HEAD_LEN)
return 0;
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
* output of rand() to get less predictability, since rand() is
* often poorly implemented.
*/
if (++calls == 1)
{
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
}
init_keys(passwd, pkeys, pcrc_32_tab);
for (n = 0; n < RAND_HEAD_LEN-2; n++)
{
c = (rand() >> 7) & 0xff;
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
}
/* Encrypt random header (last two bytes is high word of crc) */
init_keys(passwd, pkeys, pcrc_32_tab);
for (n = 0; n < RAND_HEAD_LEN-2; n++)
{
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
}
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
return n;
}
#endif

View File

@ -0,0 +1,177 @@
/* ioapi.c -- IO base function header for compress/uncompress .zip
files using zlib + zip or unzip API
Version 1.01e, February 12th, 2005
Copyright (C) 1998-2005 Gilles Vollant
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../contrib/zlib/zlib.h"
#include "ioapi.h"
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
#ifndef SEEK_CUR
#define SEEK_CUR 1
#endif
#ifndef SEEK_END
#define SEEK_END 2
#endif
#ifndef SEEK_SET
#define SEEK_SET 0
#endif
voidpf ZCALLBACK fopen_file_func (
voidpf opaque,
const char* filename,
int mode);
uLong ZCALLBACK fread_file_func (
voidpf opaque,
voidpf stream,
void* buf,
uLong size);
uLong ZCALLBACK fwrite_file_func (
voidpf opaque,
voidpf stream,
const void* buf,
uLong size);
long ZCALLBACK ftell_file_func (
voidpf opaque,
voidpf stream);
long ZCALLBACK fseek_file_func (
voidpf opaque,
voidpf stream,
uLong offset,
int origin);
int ZCALLBACK fclose_file_func (
voidpf opaque,
voidpf stream);
int ZCALLBACK ferror_file_func (
voidpf opaque,
voidpf stream);
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
voidpf opaque;
const char* filename;
int mode;
{
FILE* file = NULL;
const char* mode_fopen = NULL;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
mode_fopen = "rb";
else
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
mode_fopen = "r+b";
else
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
mode_fopen = "wb";
if ((filename!=NULL) && (mode_fopen != NULL))
file = fopen(filename, mode_fopen);
return file;
}
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
voidpf opaque;
voidpf stream;
void* buf;
uLong size;
{
uLong ret;
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
return ret;
}
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
voidpf opaque;
voidpf stream;
const void* buf;
uLong size;
{
uLong ret;
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
return ret;
}
long ZCALLBACK ftell_file_func (opaque, stream)
voidpf opaque;
voidpf stream;
{
long ret;
ret = ftell((FILE *)stream);
return ret;
}
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
voidpf opaque;
voidpf stream;
uLong offset;
int origin;
{
int fseek_origin=0;
long ret;
switch (origin)
{
case ZLIB_FILEFUNC_SEEK_CUR :
fseek_origin = SEEK_CUR;
break;
case ZLIB_FILEFUNC_SEEK_END :
fseek_origin = SEEK_END;
break;
case ZLIB_FILEFUNC_SEEK_SET :
fseek_origin = SEEK_SET;
break;
default: return -1;
}
ret = 0;
fseek((FILE *)stream, offset, fseek_origin);
return ret;
}
int ZCALLBACK fclose_file_func (opaque, stream)
voidpf opaque;
voidpf stream;
{
int ret;
ret = fclose((FILE *)stream);
return ret;
}
int ZCALLBACK ferror_file_func (opaque, stream)
voidpf opaque;
voidpf stream;
{
int ret;
ret = ferror((FILE *)stream);
return ret;
}
void fill_fopen_filefunc (pzlib_filefunc_def)
zlib_filefunc_def* pzlib_filefunc_def;
{
pzlib_filefunc_def->zopen_file = fopen_file_func;
pzlib_filefunc_def->zread_file = fread_file_func;
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
pzlib_filefunc_def->ztell_file = ftell_file_func;
pzlib_filefunc_def->zseek_file = fseek_file_func;
pzlib_filefunc_def->zclose_file = fclose_file_func;
pzlib_filefunc_def->zerror_file = ferror_file_func;
pzlib_filefunc_def->opaque = NULL;
}

View File

@ -0,0 +1,75 @@
/* ioapi.h -- IO base function header for compress/uncompress .zip
files using zlib + zip or unzip API
Version 1.01e, February 12th, 2005
Copyright (C) 1998-2005 Gilles Vollant
*/
#ifndef _ZLIBIOAPI_H
#define _ZLIBIOAPI_H
#define ZLIB_FILEFUNC_SEEK_CUR (1)
#define ZLIB_FILEFUNC_SEEK_END (2)
#define ZLIB_FILEFUNC_SEEK_SET (0)
#define ZLIB_FILEFUNC_MODE_READ (1)
#define ZLIB_FILEFUNC_MODE_WRITE (2)
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
#define ZLIB_FILEFUNC_MODE_CREATE (8)
#ifndef ZCALLBACK
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
#define ZCALLBACK CALLBACK
#else
#define ZCALLBACK
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef voidpf (ZCALLBACK *open_file_func) (voidpf opaque, const char* filename, int mode);
typedef uLong (ZCALLBACK *read_file_func) (voidpf opaque, voidpf stream, void* buf, uLong size);
typedef uLong (ZCALLBACK *write_file_func)(voidpf opaque, voidpf stream, const void* buf, uLong size);
typedef long (ZCALLBACK *tell_file_func) (voidpf opaque, voidpf stream);
typedef long (ZCALLBACK *seek_file_func) (voidpf opaque, voidpf stream, uLong offset, int origin);
typedef int (ZCALLBACK *close_file_func) (voidpf opaque, voidpf stream);
typedef int (ZCALLBACK *testerror_file_func) (voidpf opaque, voidpf stream);
typedef struct zlib_filefunc_def_s
{
open_file_func zopen_file;
read_file_func zread_file;
write_file_func zwrite_file;
tell_file_func ztell_file;
seek_file_func zseek_file;
close_file_func zclose_file;
testerror_file_func zerror_file;
voidpf opaque;
} zlib_filefunc_def;
void fill_fopen_filefunc (zlib_filefunc_def* pzlib_filefunc_def);
#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
#ifdef __cplusplus
}
#endif
#endif

1605
contrib/unzip/unzip.c 100644

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,354 @@
/* unzip.h -- IO for uncompress .zip files using zlib
Version 1.01e, February 12th, 2005
Copyright (C) 1998-2005 Gilles Vollant
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
Multi volume ZipFile (span) are not supported.
Encryption compatible with pkzip 2.04g only supported
Old compressions used by old PKZip 1.x are not supported
I WAIT FEEDBACK at mail info@winimage.com
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* for more info about .ZIP format, see
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
http://www.info-zip.org/pub/infozip/doc/
PkWare has also a specification at :
ftp://ftp.pkware.com/probdesc.zip
*/
#ifndef _unz_H
#define _unz_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _ZLIB_H
#include "../contrib/zlib/zlib.h"
#endif
#ifndef _ZLIBIOAPI_H
#include "ioapi.h"
#endif
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
/* like the STRICT of WIN32, we define a pointer that cannot be converted
from (void*) without cast */
typedef struct TagunzFile__ { int unused; } unzFile__;
typedef unzFile__ *unzFile;
#else
typedef voidp unzFile;
#endif
#define UNZ_OK (0)
#define UNZ_END_OF_LIST_OF_FILE (-100)
#define UNZ_ERRNO (Z_ERRNO)
#define UNZ_EOF (0)
#define UNZ_PARAMERROR (-102)
#define UNZ_BADZIPFILE (-103)
#define UNZ_INTERNALERROR (-104)
#define UNZ_CRCERROR (-105)
/* tm_unz contain date/time info */
typedef struct tm_unz_s
{
uInt tm_sec; /* seconds after the minute - [0,59] */
uInt tm_min; /* minutes after the hour - [0,59] */
uInt tm_hour; /* hours since midnight - [0,23] */
uInt tm_mday; /* day of the month - [1,31] */
uInt tm_mon; /* months since January - [0,11] */
uInt tm_year; /* years - [1980..2044] */
} tm_unz;
/* unz_global_info structure contain global data about the ZIPfile
These data comes from the end of central dir */
typedef struct unz_global_info_s
{
uLong number_entry; /* total number of entries in
the central dir on this disk */
uLong size_comment; /* size of the global comment of the zipfile */
} unz_global_info;
/* unz_file_info contain information about a file in the zipfile */
typedef struct unz_file_info_s
{
uLong version; /* version made by 2 bytes */
uLong version_needed; /* version needed to extract 2 bytes */
uLong flag; /* general purpose bit flag 2 bytes */
uLong compression_method; /* compression method 2 bytes */
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
uLong crc; /* crc-32 4 bytes */
uLong compressed_size; /* compressed size 4 bytes */
uLong uncompressed_size; /* uncompressed size 4 bytes */
uLong size_filename; /* filename length 2 bytes */
uLong size_file_extra; /* extra field length 2 bytes */
uLong size_file_comment; /* file comment length 2 bytes */
uLong disk_num_start; /* disk number start 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
tm_unz tmu_date;
} unz_file_info;
extern int ZEXPORT unzStringFileNameCompare (const char* fileName1,
const char* fileName2,
int iCaseSensitivity);
/*
Compare two filename (fileName1,fileName2).
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
or strcasecmp)
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
(like 1 on Unix, 2 on Windows)
*/
extern unzFile ZEXPORT unzOpen (const char *path);
/*
Open a Zip file. path contain the full pathname (by example,
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
"zlib/zlib113.zip".
If the zipfile cannot be opened (file don't exist or in not valid), the
return value is NULL.
Else, the return value is a unzFile Handle, usable with other function
of this unzip package.
*/
extern unzFile ZEXPORT unzOpen2 (const char *path,
zlib_filefunc_def* pzlib_filefunc_def);
/*
Open a Zip file, like unzOpen, but provide a set of file low level API
for read/write the zip file (see ioapi.h)
*/
extern int ZEXPORT unzClose (unzFile file);
/*
Close a ZipFile opened with unzipOpen.
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
return UNZ_OK if there is no problem. */
extern int ZEXPORT unzGetGlobalInfo (unzFile file,
unz_global_info *pglobal_info);
/*
Write info about the ZipFile in the *pglobal_info structure.
No preparation of the structure is needed
return UNZ_OK if there is no problem. */
extern int ZEXPORT unzGetGlobalComment (unzFile file,
char *szComment,
uLong uSizeBuf);
/*
Get the global comment string of the ZipFile, in the szComment buffer.
uSizeBuf is the size of the szComment buffer.
return the number of byte copied or an error code <0
*/
/***************************************************************************/
/* Unzip package allow you browse the directory of the zipfile */
extern int ZEXPORT unzGoToFirstFile (unzFile file);
/*
Set the current file of the zipfile to the first file.
return UNZ_OK if there is no problem
*/
extern int ZEXPORT unzGoToNextFile (unzFile file);
/*
Set the current file of the zipfile to the next file.
return UNZ_OK if there is no problem
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
*/
extern int ZEXPORT unzLocateFile (unzFile file,
const char *szFileName,
int iCaseSensitivity);
/*
Try locate the file szFileName in the zipfile.
For the iCaseSensitivity signification, see unzStringFileNameCompare
return value :
UNZ_OK if the file is found. It becomes the current file.
UNZ_END_OF_LIST_OF_FILE if the file is not found
*/
/* ****************************************** */
/* Ryan supplied functions */
/* unz_file_info contain information about a file in the zipfile */
typedef struct unz_file_pos_s
{
uLong pos_in_zip_directory; /* offset in zip file directory */
uLong num_of_file; /* # of file */
} unz_file_pos;
extern int ZEXPORT unzGetFilePos(
unzFile file,
unz_file_pos* file_pos);
extern int ZEXPORT unzGoToFilePos(
unzFile file,
unz_file_pos* file_pos);
/* ****************************************** */
extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
unz_file_info *pfile_info,
char *szFileName,
uLong fileNameBufferSize,
void *extraField,
uLong extraFieldBufferSize,
char *szComment,
uLong commentBufferSize);
/*
Get Info about the current file
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
the current file
if szFileName!=NULL, the filemane string will be copied in szFileName
(fileNameBufferSize is the size of the buffer)
if extraField!=NULL, the extra field information will be copied in extraField
(extraFieldBufferSize is the size of the buffer).
This is the Central-header version of the extra field
if szComment!=NULL, the comment string of the file will be copied in szComment
(commentBufferSize is the size of the buffer)
*/
/***************************************************************************/
/* for reading the content of the current zipfile, you can open it, read data
from it, and close it (you can close it before reading all the file)
*/
extern int ZEXPORT unzOpenCurrentFile (unzFile file);
/*
Open for reading data the current file in the zipfile.
If there is no error, the return value is UNZ_OK.
*/
extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file,
const char* password);
/*
Open for reading data the current file in the zipfile.
password is a crypting password
If there is no error, the return value is UNZ_OK.
*/
extern int ZEXPORT unzOpenCurrentFile2 (unzFile file,
int* method,
int* level,
int raw);
/*
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
if raw==1
*method will receive method of compression, *level will receive level of
compression
note : you can set level parameter as NULL (if you did not want known level,
but you CANNOT set method parameter as NULL
*/
extern int ZEXPORT unzOpenCurrentFile3 (unzFile file,
int* method,
int* level,
int raw,
const char* password);
/*
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
if raw==1
*method will receive method of compression, *level will receive level of
compression
note : you can set level parameter as NULL (if you did not want known level,
but you CANNOT set method parameter as NULL
*/
extern int ZEXPORT unzCloseCurrentFile (unzFile file);
/*
Close the file in zip opened with unzOpenCurrentFile
Return UNZ_CRCERROR if all the file was read but the CRC is not good
*/
extern int ZEXPORT unzReadCurrentFile (unzFile file,
voidp buf,
unsigned len);
/*
Read bytes from the current file (opened by unzOpenCurrentFile)
buf contain buffer where data must be copied
len the size of buf.
return the number of byte copied if somes bytes are copied
return 0 if the end of file was reached
return <0 with error code if there is an error
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
*/
extern z_off_t ZEXPORT unztell (unzFile file);
/*
Give the current position in uncompressed data
*/
extern int ZEXPORT unzeof (unzFile file);
/*
return 1 if the end of file was reached, 0 elsewhere
*/
extern int ZEXPORT unzGetLocalExtrafield (unzFile file,
voidp buf,
unsigned len);
/*
Read extra field from the current file (opened by unzOpenCurrentFile)
This is the local-header version of the extra field (sometimes, there is
more info in the local-header version than in the central-header)
if buf==NULL, it return the size of the local extra field
if buf!=NULL, len is the size of the buffer, the extra header is copied in
buf.
the return value is the number of bytes copied in buf, or (if <0)
the error code
*/
/***************************************************************************/
/* Get the current file offset */
extern uLong ZEXPORT unzGetOffset (unzFile file);
/* Set the current file offset */
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
#ifdef __cplusplus
}
#endif
#endif /* _unz_H */