indent classes, align by spaces
This commit is contained in:
@@ -52,88 +52,88 @@ inline void buffer_findreplace( char* buffer, char find, char replace ){
|
||||
|
||||
class PakArchive final : public Archive
|
||||
{
|
||||
class PakRecord
|
||||
{
|
||||
public:
|
||||
PakRecord( unsigned int position, unsigned int stream_size )
|
||||
: m_position( position ), m_stream_size( stream_size ){
|
||||
}
|
||||
unsigned int m_position;
|
||||
unsigned int m_stream_size;
|
||||
};
|
||||
typedef GenericFileSystem<PakRecord> PakFileSystem;
|
||||
PakFileSystem m_filesystem;
|
||||
FileInputStream m_pakfile;
|
||||
CopiedString m_name;
|
||||
class PakRecord
|
||||
{
|
||||
public:
|
||||
PakRecord( unsigned int position, unsigned int stream_size )
|
||||
: m_position( position ), m_stream_size( stream_size ){
|
||||
}
|
||||
unsigned int m_position;
|
||||
unsigned int m_stream_size;
|
||||
};
|
||||
typedef GenericFileSystem<PakRecord> PakFileSystem;
|
||||
PakFileSystem m_filesystem;
|
||||
FileInputStream m_pakfile;
|
||||
CopiedString m_name;
|
||||
|
||||
public:
|
||||
|
||||
PakArchive( const char* name )
|
||||
: m_pakfile( name ), m_name( name ){
|
||||
if ( !m_pakfile.failed() ) {
|
||||
pakheader_t header;
|
||||
PakArchive( const char* name )
|
||||
: m_pakfile( name ), m_name( name ){
|
||||
if ( !m_pakfile.failed() ) {
|
||||
pakheader_t header;
|
||||
|
||||
m_pakfile.read( reinterpret_cast<FileInputStream::byte_type*>( header.magic ), 4 );
|
||||
header.diroffset = istream_read_uint32_le( m_pakfile );
|
||||
header.dirsize = istream_read_uint32_le( m_pakfile );
|
||||
m_pakfile.read( reinterpret_cast<FileInputStream::byte_type*>( header.magic ), 4 );
|
||||
header.diroffset = istream_read_uint32_le( m_pakfile );
|
||||
header.dirsize = istream_read_uint32_le( m_pakfile );
|
||||
|
||||
if ( strncmp( header.magic, "PACK", 4 ) == 0 ) {
|
||||
m_pakfile.seek( header.diroffset );
|
||||
if ( strncmp( header.magic, "PACK", 4 ) == 0 ) {
|
||||
m_pakfile.seek( header.diroffset );
|
||||
|
||||
for ( unsigned int i = 0; i < header.dirsize; i += sizeof( pakentry_t ) )
|
||||
{
|
||||
pakentry_t entry;
|
||||
|
||||
m_pakfile.read( reinterpret_cast<FileInputStream::byte_type*>( entry.filename ), 0x38 );
|
||||
entry.offset = istream_read_uint32_le( m_pakfile );
|
||||
entry.size = istream_read_uint32_le( m_pakfile );
|
||||
|
||||
buffer_findreplace( entry.filename, '\\', '/' );
|
||||
|
||||
PakFileSystem::entry_type& file = m_filesystem[entry.filename];
|
||||
if ( !file.is_directory() ) {
|
||||
globalWarningStream() << "Warning: pak archive " << makeQuoted( m_name.c_str() ) << " contains duplicated file: " << makeQuoted( entry.filename ) << "\n";
|
||||
}
|
||||
else
|
||||
for ( unsigned int i = 0; i < header.dirsize; i += sizeof( pakentry_t ) )
|
||||
{
|
||||
file = new PakRecord( entry.offset, entry.size );
|
||||
pakentry_t entry;
|
||||
|
||||
m_pakfile.read( reinterpret_cast<FileInputStream::byte_type*>( entry.filename ), 0x38 );
|
||||
entry.offset = istream_read_uint32_le( m_pakfile );
|
||||
entry.size = istream_read_uint32_le( m_pakfile );
|
||||
|
||||
buffer_findreplace( entry.filename, '\\', '/' );
|
||||
|
||||
PakFileSystem::entry_type& file = m_filesystem[entry.filename];
|
||||
if ( !file.is_directory() ) {
|
||||
globalWarningStream() << "Warning: pak archive " << makeQuoted( m_name.c_str() ) << " contains duplicated file: " << makeQuoted( entry.filename ) << "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
file = new PakRecord( entry.offset, entry.size );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~PakArchive(){
|
||||
for ( PakFileSystem::iterator i = m_filesystem.begin(); i != m_filesystem.end(); ++i )
|
||||
delete i->second.file();
|
||||
}
|
||||
~PakArchive(){
|
||||
for ( PakFileSystem::iterator i = m_filesystem.begin(); i != m_filesystem.end(); ++i )
|
||||
delete i->second.file();
|
||||
}
|
||||
|
||||
void release(){
|
||||
delete this;
|
||||
}
|
||||
ArchiveFile* openFile( const char* name ){
|
||||
PakFileSystem::iterator i = m_filesystem.find( name );
|
||||
if ( i != m_filesystem.end() && !i->second.is_directory() ) {
|
||||
PakRecord* file = i->second.file();
|
||||
return StoredArchiveFile::create( name, m_name.c_str(), file->m_position, file->m_stream_size, file->m_stream_size );
|
||||
void release(){
|
||||
delete this;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
virtual ArchiveTextFile* openTextFile( const char* name ){
|
||||
PakFileSystem::iterator i = m_filesystem.find( name );
|
||||
if ( i != m_filesystem.end() && !i->second.is_directory() ) {
|
||||
PakRecord* file = i->second.file();
|
||||
return StoredArchiveTextFile::create( name, m_name.c_str(), file->m_position, file->m_stream_size );
|
||||
ArchiveFile* openFile( const char* name ){
|
||||
PakFileSystem::iterator i = m_filesystem.find( name );
|
||||
if ( i != m_filesystem.end() && !i->second.is_directory() ) {
|
||||
PakRecord* file = i->second.file();
|
||||
return StoredArchiveFile::create( name, m_name.c_str(), file->m_position, file->m_stream_size, file->m_stream_size );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
virtual ArchiveTextFile* openTextFile( const char* name ){
|
||||
PakFileSystem::iterator i = m_filesystem.find( name );
|
||||
if ( i != m_filesystem.end() && !i->second.is_directory() ) {
|
||||
PakRecord* file = i->second.file();
|
||||
return StoredArchiveTextFile::create( name, m_name.c_str(), file->m_position, file->m_stream_size );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
bool containsFile( const char* name ){
|
||||
PakFileSystem::iterator i = m_filesystem.find( name );
|
||||
return i != m_filesystem.end() && !i->second.is_directory();
|
||||
}
|
||||
void forEachFile( VisitorFunc visitor, const char* root ){
|
||||
m_filesystem.traverse( visitor, root );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
bool containsFile( const char* name ){
|
||||
PakFileSystem::iterator i = m_filesystem.find( name );
|
||||
return i != m_filesystem.end() && !i->second.is_directory();
|
||||
}
|
||||
void forEachFile( VisitorFunc visitor, const char* root ){
|
||||
m_filesystem.traverse( visitor, root );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -146,16 +146,16 @@ Archive* OpenArchive( const char* name ){
|
||||
class TestArchive
|
||||
{
|
||||
public:
|
||||
TestArchive(){
|
||||
Archive* archive = OpenArchive( "c:/quake3/baseq3/pak0.pak" );
|
||||
ArchiveFile* file = archive->openFile( "gfx/palette.lmp" );
|
||||
if ( file != 0 ) {
|
||||
char buffer[1024];
|
||||
file->getInputStream().read( (InputStream::byte_type*)buffer, 1024 );
|
||||
file->release();
|
||||
TestArchive(){
|
||||
Archive* archive = OpenArchive( "c:/quake3/baseq3/pak0.pak" );
|
||||
ArchiveFile* file = archive->openFile( "gfx/palette.lmp" );
|
||||
if ( file != 0 ) {
|
||||
char buffer[1024];
|
||||
file->getInputStream().read( (InputStream::byte_type*)buffer, 1024 );
|
||||
file->release();
|
||||
}
|
||||
archive->release();
|
||||
}
|
||||
archive->release();
|
||||
}
|
||||
};
|
||||
|
||||
TestArchive g_test;
|
||||
@@ -166,43 +166,43 @@ TestArchive g_test;
|
||||
|
||||
class TestArchive
|
||||
{
|
||||
class TestVisitor : public Archive::IVisitor
|
||||
{
|
||||
public:
|
||||
void visit( const char* name ){
|
||||
int bleh = 0;
|
||||
}
|
||||
};
|
||||
public:
|
||||
TestArchive(){
|
||||
class TestVisitor : public Archive::IVisitor
|
||||
{
|
||||
Archive* archive = OpenArchive( "" );
|
||||
archive->release();
|
||||
}
|
||||
{
|
||||
Archive* archive = OpenArchive( "NONEXISTANTFILE" );
|
||||
archive->release();
|
||||
}
|
||||
{
|
||||
Archive* archive = OpenArchive( "c:/quake/id1/pak0.pak" );
|
||||
ArchiveFile* file = archive->openFile( "gfx/palette.lmp" );
|
||||
if ( file != 0 ) {
|
||||
char buffer[1024];
|
||||
file->getInputStream().read( (InputStream::byte_type*)buffer, 1024 );
|
||||
file->release();
|
||||
public:
|
||||
void visit( const char* name ){
|
||||
int bleh = 0;
|
||||
}
|
||||
};
|
||||
public:
|
||||
TestArchive(){
|
||||
{
|
||||
Archive* archive = OpenArchive( "" );
|
||||
archive->release();
|
||||
}
|
||||
{
|
||||
Archive* archive = OpenArchive( "NONEXISTANTFILE" );
|
||||
archive->release();
|
||||
}
|
||||
{
|
||||
Archive* archive = OpenArchive( "c:/quake/id1/pak0.pak" );
|
||||
ArchiveFile* file = archive->openFile( "gfx/palette.lmp" );
|
||||
if ( file != 0 ) {
|
||||
char buffer[1024];
|
||||
file->getInputStream().read( (InputStream::byte_type*)buffer, 1024 );
|
||||
file->release();
|
||||
}
|
||||
TestVisitor visitor;
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eFilesAndDirectories, 0 ), "" );
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eFiles, 0 ), "progs/" );
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eFiles, 0 ), "maps/" );
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eFiles, 1 ), "sound/ambience/" );
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eFilesAndDirectories, 1 ), "sound/" );
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eDirectories, 1 ), "sound/" );
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eFilesAndDirectories, 2 ), "sound/" );
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eFilesAndDirectories, 2 ), "" );
|
||||
archive->release();
|
||||
}
|
||||
TestVisitor visitor;
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eFilesAndDirectories, 0 ), "" );
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eFiles, 0 ), "progs/" );
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eFiles, 0 ), "maps/" );
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eFiles, 1 ), "sound/ambience/" );
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eFilesAndDirectories, 1 ), "sound/" );
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eDirectories, 1 ), "sound/" );
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eFilesAndDirectories, 2 ), "sound/" );
|
||||
archive->forEachFile( Archive::VisitorFunc( &visitor, Archive::eFilesAndDirectories, 2 ), "" );
|
||||
archive->release();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TestArchive g_test;
|
||||
|
||||
@@ -30,17 +30,17 @@
|
||||
|
||||
class ArchivePakAPI
|
||||
{
|
||||
_QERArchiveTable m_archivepak;
|
||||
_QERArchiveTable m_archivepak;
|
||||
public:
|
||||
typedef _QERArchiveTable Type;
|
||||
STRING_CONSTANT( Name, "pak" );
|
||||
typedef _QERArchiveTable Type;
|
||||
STRING_CONSTANT( Name, "pak" );
|
||||
|
||||
ArchivePakAPI(){
|
||||
m_archivepak.m_pfnOpenArchive = &OpenArchive;
|
||||
}
|
||||
_QERArchiveTable* getTable(){
|
||||
return &m_archivepak;
|
||||
}
|
||||
ArchivePakAPI(){
|
||||
m_archivepak.m_pfnOpenArchive = &OpenArchive;
|
||||
}
|
||||
_QERArchiveTable* getTable(){
|
||||
return &m_archivepak;
|
||||
}
|
||||
};
|
||||
|
||||
typedef SingletonModule<ArchivePakAPI> ArchivePakModule;
|
||||
|
||||
Reference in New Issue
Block a user