Added some convenience overloads for archive handling. Cleaned up the existing methods.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2301 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2009-03-29 01:23:18 +00:00
parent 00c112d522
commit 824058e24a
9 changed files with 194 additions and 197 deletions

View File

@ -13,8 +13,8 @@ namespace irr
namespace io
{
//! FileSystemType: which Filesystem should be used for e.q browsing
enum eFileSystemType
//! FileSystemType: which Filesystem should be used for e.g. browsing
enum EFileSystemType
{
FILESYSTEM_NATIVE = 0, // Native OS FileSystem
FILESYSTEM_VIRTUAL, // Virtual FileSystem
@ -40,13 +40,13 @@ struct IFileArchiveEntry
}
};
//! The FileArchive manages files and archives and provides access to them.
/** It manages where files are, so that modules which use the the IO do not
need to know where every file is located. A file could be in a .zip-Archive or
as file on disk, using the IFileSystem makes no difference to this. */
struct IFileArchive : public virtual IReferenceCounted
{
//! return the id of the file Archive
virtual const core::string<c16>& getArchiveName() =0;
@ -56,16 +56,18 @@ struct IFileArchive : public virtual IReferenceCounted
//! opens a file by file name
virtual IReadFile* openFile(const core::string<c16>& filename) =0;
//! opens a file by position
virtual IReadFile* openFile(s32 index) =0;
//! returns fileindex
virtual s32 findFile(const core::string<c16>& filename) =0;
//! Returns the amount of files in the filelist.
/** \return Amount of files and directories in the file list. */
virtual u32 getFileCount() = 0;
virtual u32 getFileCount() const =0;
//! returns data of known file
virtual const IFileArchiveEntry* getFileInfo(u32 index) =0;
};
//! Class which is able to create an archive from a file.
@ -96,14 +98,11 @@ struct IArchiveLoader : public virtual IReferenceCounted
/** \param file File handle to check.
\return Pointer to newly created archive, or 0 upon error. */
virtual IFileArchive* createArchive(io::IReadFile* file, bool ignoreCase, bool ignorePaths) const =0;
};
} // end namespace io
} // end namespace irr
#endif

View File

@ -94,11 +94,14 @@ public:
virtual void addArchiveLoader(IArchiveLoader* loader) =0;
//! return the amount of currently attached Archives
virtual u32 getFileArchiveCount() = 0;
virtual u32 getFileArchiveCount() const =0;
//! removes an archive from the file system.
virtual bool unregisterFileArchive(u32 index) =0;
//! removes an archive from the file system.
virtual bool unregisterFileArchive(const core::string<c16>& filename) =0;
//! move the hirarchy of the filesystem. moves sourceIndex relative up or down
virtual bool moveFileArchive(u32 sourceIndex, s32 relative) =0;
@ -185,7 +188,8 @@ public:
See IReferenceCounted::drop() for more information. */
virtual IFileList* createFileList() =0;
virtual eFileSystemType setFileListSystem( eFileSystemType listType) = 0;
//! Set the active type of file system.
virtual EFileSystemType setFileListSystem(EFileSystemType listType) =0;
//! Determines if a file exists and could be opened.
/** \param filename is the string identifying the file which should be tested for existence.

View File

@ -32,9 +32,6 @@ namespace irr
namespace io
{
//! constructor
CFileSystem::CFileSystem()
{
@ -47,7 +44,6 @@ CFileSystem::CFileSystem()
addArchiveLoader(new CArchiveLoaderZIP(this));
addArchiveLoader(new CArchiveLoaderMount(this));
addArchiveLoader(new CArchiveLoaderPAK(this));
}
@ -56,16 +52,15 @@ CFileSystem::~CFileSystem()
{
u32 i;
for ( i=0; i < FileArchive.size(); ++i)
for ( i=0; i < FileArchives.size(); ++i)
{
FileArchive[i]->drop ();
FileArchives[i]->drop();
}
for ( i=0; i < ArchiveLoader.size(); ++i)
{
ArchiveLoader[i]->drop();
}
}
@ -75,9 +70,9 @@ IReadFile* CFileSystem::createAndOpenFile( const core::string<c16>& filename)
IReadFile* file = 0;
u32 i;
for ( i=0; i< FileArchive.size(); ++i)
for (i=0; i< FileArchives.size(); ++i)
{
file = FileArchive[i]->openFile(filename);
file = FileArchives[i]->openFile(filename);
if (file)
return file;
}
@ -116,7 +111,6 @@ IWriteFile* CFileSystem::createAndWriteFile(const core::string<c16>& filename, b
}
//! Adds an external archive loader to the engine.
void CFileSystem::addArchiveLoader(IArchiveLoader* loader)
{
@ -134,7 +128,7 @@ bool CFileSystem::moveFileArchive( u32 sourceIndex, s32 relative )
bool r = false;
const s32 dest = (s32) sourceIndex + relative;
const s32 dir = relative < 0 ? -1 : 1;
const s32 sourceEnd = ((s32) FileArchive.size() ) - 1;
const s32 sourceEnd = ((s32) FileArchives.size() ) - 1;
IFileArchive *t;
for (s32 s = (s32) sourceIndex;s != dest; s += dir)
@ -142,14 +136,15 @@ bool CFileSystem::moveFileArchive( u32 sourceIndex, s32 relative )
if (s < 0 || s > sourceEnd || s + dir < 0 || s + dir > sourceEnd)
continue;
t = FileArchive [ s + dir ];
FileArchive [ s + dir ] = FileArchive [ s ];
FileArchive [ s ] = t;
t = FileArchives[s + dir];
FileArchives[s + dir] = FileArchives[s];
FileArchives[s] = t;
r = true;
}
return r;
}
//! Adds an archive to the file system.
bool CFileSystem::registerFileArchive(const core::string<c16>& filename, bool ignoreCase, bool ignorePaths)
{
@ -191,54 +186,64 @@ bool CFileSystem::registerFileArchive( const core::string<c16>& filename, bool i
if (archive)
{
FileArchive.push_back ( archive );
FileArchives.push_back(archive);
ret = true;
}
else
{
char buf[256];
core::stringw showName ( filename );
snprintf ( buf, sizeof (buf), "Could not create archive for: %ls\n", showName.c_str() );
os::Printer::log( buf ,ELL_ERROR);
os::Printer::log("Could not create archive for", filename, ELL_ERROR);
}
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return ret;
}
//! removes an archive to the file system.
//! removes an archive from the file system.
bool CFileSystem::unregisterFileArchive(u32 index)
{
bool ret = false;
if ( index < FileArchive.size () )
if (index < FileArchives.size())
{
FileArchive[index]->drop();
FileArchive.erase ( index );
FileArchives[index]->drop();
FileArchives.erase(index);
ret = true;
}
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return ret;
}
//! removes an archive from the file system.
bool CFileSystem::unregisterFileArchive(const core::string<c16>& filename)
{
for (u32 i=0; i < FileArchives.size(); ++i)
{
if (filename == FileArchives[i]->getArchiveName())
return unregisterFileArchive(i);
}
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return false;
}
//! gets an archive
u32 CFileSystem::getFileArchiveCount()
u32 CFileSystem::getFileArchiveCount() const
{
return FileArchive.size();
return FileArchives.size();
}
IFileArchive* CFileSystem::getFileArchive(u32 index)
{
return index < getFileArchiveCount () ? FileArchive [ index ] : 0;
return index < getFileArchiveCount() ? FileArchives[index] : 0;
}
//! Returns the string of the current working directory
const core::string<c16>& CFileSystem::getWorkingDirectory()
{
eFileSystemType type = FileSystemType;
EFileSystemType type = FileSystemType;
if (type != FILESYSTEM_NATIVE)
{
@ -413,13 +418,11 @@ core::string<c16>& CFileSystem::flattenFilename( core::string<c16>& directory, c
{
deletePathFromPath(dir, 2);
}
else
if ( subdir == "/" )
else if (subdir == "/")
{
dir = root;
}
else
if ( subdir != "./" )
else if (subdir != "./" )
{
dir.append(subdir);
}
@ -430,10 +433,11 @@ core::string<c16>& CFileSystem::flattenFilename( core::string<c16>& directory, c
return directory;
}
//! Creates a list of files and directories in the current working directory
eFileSystemType CFileSystem::setFileListSystem( eFileSystemType listType)
EFileSystemType CFileSystem::setFileListSystem(EFileSystemType listType)
{
eFileSystemType current = FileSystemType;
EFileSystemType current = FileSystemType;
FileSystemType = listType;
return current;
}
@ -451,19 +455,19 @@ IFileList* CFileSystem::createFileList()
CFileList* r = new CFileList( "virtual" );
r->Path = WorkingDirectory [ FILESYSTEM_VIRTUAL ];
for ( u32 i = 0; i != FileArchive.size(); ++i)
for ( u32 i = 0; i != FileArchives.size(); ++i)
{
CFileList* flist[2] = { 0, 0 };
//! merge relative folder file archives
if ( FileArchive[i]->getArchiveType() == "mount" )
if ( FileArchives[i]->getArchiveType() == "mount" )
{
eFileSystemType currentType = setFileListSystem ( FILESYSTEM_NATIVE );
EFileSystemType currentType = setFileListSystem ( FILESYSTEM_NATIVE );
core::string<c16> save ( getWorkingDirectory () );
core::string<c16> current;
current = FileArchive[i]->getArchiveName() + WorkingDirectory [ FILESYSTEM_VIRTUAL ];
current = FileArchives[i]->getArchiveName() + WorkingDirectory [ FILESYSTEM_VIRTUAL ];
flattenFilename ( current );
if ( changeWorkingDirectoryTo ( current ) )
@ -476,7 +480,7 @@ IFileList* CFileSystem::createFileList()
setFileListSystem ( currentType );
}
else
if ( FileArchive[i]->getArchiveType() == "zip" )
if ( FileArchives[i]->getArchiveType() == "zip" )
{
flist[0] = new CFileList( "zip" );
flist[1] = new CFileList( "zip directory" );
@ -492,9 +496,9 @@ IFileList* CFileSystem::createFileList()
e2.FullName = r->Path + e2.Name;
flist[1]->Files.push_back ( e2 );
for ( u32 g = 0; g < FileArchive[i]->getFileCount(); ++g)
for ( u32 g = 0; g < FileArchives[i]->getFileCount(); ++g)
{
const SZipFileEntry *e = (SZipFileEntry*) FileArchive[i]->getFileInfo ( g );
const SZipFileEntry *e = (SZipFileEntry*) FileArchives[i]->getFileInfo(g);
s32 test = isInSameDirectory ( r->Path, e->zipFileName );
if ( test < 0 || test > 1 )
continue;
@ -545,10 +549,8 @@ IFileList* CFileSystem::createFileList()
//! determines if a file exists and would be able to be opened.
bool CFileSystem::existFile(const core::string<c16>& filename) const
{
u32 i;
for (i=0; i < FileArchive.size(); ++i)
if ( FileArchive[i]->findFile(filename)!=-1)
for (u32 i=0; i < FileArchives.size(); ++i)
if ( FileArchives[i]->findFile(filename)!=-1)
return true;
#if defined ( _IRR_WCHAR_FILESYSTEM )

View File

@ -51,12 +51,18 @@ public:
//! Adds an external archive loader to the engine.
virtual void addArchiveLoader(IArchiveLoader* loader);
//! gets the file archive count
virtual u32 getFileArchiveCount() const;
//! gets an archive
virtual u32 getFileArchiveCount();
virtual IFileArchive* getFileArchive(u32 index);
//! removes an archive to the file system.
//! removes an archive from the file system.
virtual bool unregisterFileArchive(u32 index);
//! removes an archive from the file system.
virtual bool unregisterFileArchive(const core::string<c16>& filename);
//! Returns the string of the current working directory
virtual const core::string<c16>& getWorkingDirectory();
@ -80,12 +86,13 @@ public:
//! flatten a path and file name for example: "/you/me/../." becomes "/you"
virtual core::string<c16>& flattenFilename( core::string<c16>& directory, const core::string<c16>& root = "/" ) const;
virtual EFileSystemType setFileListSystem(EFileSystemType listType);
//! Creates a list of files and directories in the current working directory
//! and returns it.
virtual eFileSystemType setFileListSystem( eFileSystemType listType);
virtual IFileList* createFileList();
//! determinates if a file exists and would be able to be opened.
//! determines if a file exists and would be able to be opened.
virtual bool existFile(const core::string<c16>& filename) const;
//! Creates a XML Reader from a file.
@ -111,12 +118,10 @@ public:
private:
eFileSystemType FileSystemType; // Currently used FileSystemType
EFileSystemType FileSystemType; // Currently used FileSystemType
core::string<c16> WorkingDirectory [2]; // WorkingDirectory for Native/Virtual
core::array<IArchiveLoader*> ArchiveLoader; // currently attached ArchiveLoaders
core::array< IFileArchive*> FileArchive; // currently attached Archives
core::array<IFileArchive*> FileArchives; // currently attached Archives
};

View File

@ -23,12 +23,6 @@ CArchiveLoaderPAK::CArchiveLoaderPAK( io::IFileSystem* fs)
}
//! destructor
CArchiveLoaderPAK::~CArchiveLoaderPAK()
{
}
//! returns true if the file maybe is able to be loaded by this class
bool CArchiveLoaderPAK::isALoadableFileFormat(const core::string<c16>& filename) const
{
@ -219,7 +213,7 @@ IReadFile* CPakReader::openFile(s32 index)
//! returns count of files in archive
u32 CPakReader::getFileCount()
u32 CPakReader::getFileCount() const
{
return FileList.size();
}

View File

@ -38,9 +38,6 @@ namespace io
//! Constructor
CArchiveLoaderPAK(io::IFileSystem* fs);
//! destructor
virtual ~CArchiveLoaderPAK();
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".zip")
virtual bool isALoadableFileFormat(const core::string<c16>& filename) const;
@ -77,10 +74,10 @@ namespace io
virtual IReadFile* openFile(const core::string<c16>& filename);
//! opens a file by index
IReadFile* openFile(s32 index);
virtual IReadFile* openFile(s32 index);
//! returns count of files in archive
virtual u32 getFileCount();
virtual u32 getFileCount() const;
//! returns data of file
virtual const IFileArchiveEntry* getFileInfo(u32 index);

View File

@ -1543,7 +1543,7 @@ void CQ3LevelMesh::InitShader()
if ( LoadParam.loadAllShaders )
{
io::eFileSystemType current = FileSystem->setFileListSystem ( io::FILESYSTEM_VIRTUAL );
io::EFileSystemType current = FileSystem->setFileListSystem ( io::FILESYSTEM_VIRTUAL );
core::string<c16> save = FileSystem->getWorkingDirectory();
core::string<c16> newDir;

View File

@ -328,7 +328,6 @@ bool CZipReader::scanLocalHeader()
}
//! opens a file by file name
IReadFile* CZipReader::openFile(const core::string<c16>& filename)
{
@ -341,7 +340,6 @@ IReadFile* CZipReader::openFile(const core::string<c16>& filename)
}
//! opens a file by index
IReadFile* CZipReader::openFile(s32 index)
{
@ -440,15 +438,13 @@ IReadFile* CZipReader::openFile(s32 index)
}
//! returns count of files in archive
u32 CZipReader::getFileCount()
u32 CZipReader::getFileCount() const
{
return FileList.size();
}
//! returns data of file
const IFileArchiveEntry* CZipReader::getFileInfo(u32 index)
{
@ -532,7 +528,7 @@ IFileArchive* CArchiveLoaderMount::createArchive(const core::string<c16>& filena
{
IFileArchive *archive = 0;
eFileSystemType current = FileSystem->setFileListSystem ( FILESYSTEM_NATIVE );
EFileSystemType current = FileSystem->setFileListSystem ( FILESYSTEM_NATIVE );
core::string<c16> save = FileSystem->getWorkingDirectory ();
core::string<c16> fullPath = FileSystem->getAbsolutePath ( filename );

View File

@ -165,7 +165,7 @@ namespace io
virtual IReadFile* openFile(s32 index);
//! returns count of files in archive
virtual u32 getFileCount();
virtual u32 getFileCount() const;
//! returns data of file
virtual const IFileArchiveEntry* getFileInfo(u32 index);