Commit 824058e2 authored by hybrid's avatar hybrid

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
parent 00c112d5
...@@ -13,18 +13,18 @@ namespace irr ...@@ -13,18 +13,18 @@ namespace irr
namespace io namespace io
{ {
//! FileSystemType: which Filesystem should be used for e.q browsing //! FileSystemType: which Filesystem should be used for e.g. browsing
enum eFileSystemType enum EFileSystemType
{ {
FILESYSTEM_NATIVE = 0, // Native OS FileSystem FILESYSTEM_NATIVE = 0, // Native OS FileSystem
FILESYSTEM_VIRTUAL, // Virtual FileSystem FILESYSTEM_VIRTUAL, // Virtual FileSystem
}; };
//! Base Info which all File archives must support on browsing //! Base Info which all File archives must support on browsing
struct IFileArchiveEntry struct IFileArchiveEntry
{ {
IFileArchiveEntry () {} IFileArchiveEntry() {}
core::string<c16> simpleFileName; core::string<c16> simpleFileName;
core::string<c16> path; core::string<c16> path;
...@@ -40,32 +40,34 @@ struct IFileArchiveEntry ...@@ -40,32 +40,34 @@ struct IFileArchiveEntry
} }
}; };
//! The FileArchive manages files and archives and provides access to them. //! 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 /** 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 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. */ as file on disk, using the IFileSystem makes no difference to this. */
struct IFileArchive : public virtual IReferenceCounted struct IFileArchive : public virtual IReferenceCounted
{ {
//! return the id of the file Archive //! return the id of the file Archive
virtual const core::string<c16>& getArchiveName () = 0; virtual const core::string<c16>& getArchiveName() =0;
//! get the class Type //! get the class Type
virtual const core::string<c16>& getArchiveType() = 0; virtual const core::string<c16>& getArchiveType() =0;
//! opens a file by file name //! opens a file by file name
virtual IReadFile* openFile(const core::string<c16>& filename) = 0; virtual IReadFile* openFile(const core::string<c16>& filename) =0;
//! opens a file by position
virtual IReadFile* openFile(s32 index) =0;
//! returns fileindex //! returns fileindex
virtual s32 findFile(const core::string<c16>& filename) = 0; virtual s32 findFile(const core::string<c16>& filename) =0;
//! Returns the amount of files in the filelist. //! Returns the amount of files in the filelist.
/** \return Amount of files and directories in the file list. */ /** \return Amount of files and directories in the file list. */
virtual u32 getFileCount() = 0; virtual u32 getFileCount() const =0;
//! returns data of known file //! returns data of known file
virtual const IFileArchiveEntry* getFileInfo(u32 index) = 0; virtual const IFileArchiveEntry* getFileInfo(u32 index) =0;
}; };
//! Class which is able to create an archive from a file. //! Class which is able to create an archive from a file.
...@@ -79,31 +81,28 @@ struct IArchiveLoader : public virtual IReferenceCounted ...@@ -79,31 +81,28 @@ struct IArchiveLoader : public virtual IReferenceCounted
/** Check is based on the file extension (e.g. ".zip") /** Check is based on the file extension (e.g. ".zip")
\param fileName Name of file to check. \param fileName Name of file to check.
\return True if file seems to be loadable. */ \return True if file seems to be loadable. */
virtual bool isALoadableFileFormat(const core::string<c16>& filename) const = 0; virtual bool isALoadableFileFormat(const core::string<c16>& filename) const =0;
//! Creates an archive from the filename //! Creates an archive from the filename
/** \param file File handle to check. /** \param file File handle to check.
\return Pointer to newly created archive, or 0 upon error. */ \return Pointer to newly created archive, or 0 upon error. */
virtual IFileArchive* createArchive(const core::string<c16>& filename, bool ignoreCase, bool ignorePaths) const = 0; virtual IFileArchive* createArchive(const core::string<c16>& filename, bool ignoreCase, bool ignorePaths) const =0;
//! Check if the file might be loaded by this class //! Check if the file might be loaded by this class
/** Check might look into the file. /** Check might look into the file.
\param file File handle to check. \param file File handle to check.
\return True if file seems to be loadable. */ \return True if file seems to be loadable. */
virtual bool isALoadableFileFormat(io::IReadFile* file) const = 0; virtual bool isALoadableFileFormat(io::IReadFile* file) const =0;
//! Creates an archive from the file //! Creates an archive from the file
/** \param file File handle to check. /** \param file File handle to check.
\return Pointer to newly created archive, or 0 upon error. */ \return Pointer to newly created archive, or 0 upon error. */
virtual IFileArchive* createArchive(io::IReadFile* file, bool ignoreCase, bool ignorePaths) const = 0; virtual IFileArchive* createArchive(io::IReadFile* file, bool ignoreCase, bool ignorePaths) const =0;
}; };
} // end namespace io } // end namespace io
} // end namespace irr } // end namespace irr
#endif #endif
This diff is collapsed.
This diff is collapsed.
...@@ -51,11 +51,17 @@ public: ...@@ -51,11 +51,17 @@ public:
//! Adds an external archive loader to the engine. //! Adds an external archive loader to the engine.
virtual void addArchiveLoader(IArchiveLoader* loader); virtual void addArchiveLoader(IArchiveLoader* loader);
//! gets the file archive count
virtual u32 getFileArchiveCount() const;
//! gets an archive //! gets an archive
virtual u32 getFileArchiveCount(); virtual IFileArchive* getFileArchive(u32 index);
virtual IFileArchive* getFileArchive( u32 index );
//! removes an archive to the file system. //! removes an archive from the file system.
virtual bool unregisterFileArchive( u32 index ); 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 //! Returns the string of the current working directory
virtual const core::string<c16>& getWorkingDirectory(); virtual const core::string<c16>& getWorkingDirectory();
...@@ -80,12 +86,13 @@ public: ...@@ -80,12 +86,13 @@ public:
//! flatten a path and file name for example: "/you/me/../." becomes "/you" //! 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 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 //! Creates a list of files and directories in the current working directory
//! and returns it. //! and returns it.
virtual eFileSystemType setFileListSystem( eFileSystemType listType);
virtual IFileList* createFileList(); 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; virtual bool existFile(const core::string<c16>& filename) const;
//! Creates a XML Reader from a file. //! Creates a XML Reader from a file.
...@@ -111,12 +118,10 @@ public: ...@@ -111,12 +118,10 @@ public:
private: private:
eFileSystemType FileSystemType; // Currently used FileSystemType EFileSystemType FileSystemType; // Currently used FileSystemType
core::string<c16> WorkingDirectory [2]; // WorkingDirectory for Native/Virtual core::string<c16> WorkingDirectory [2]; // WorkingDirectory for Native/Virtual
core::array<IArchiveLoader*> ArchiveLoader; // currently attached ArchiveLoaders
core::array< IArchiveLoader* > ArchiveLoader; // currently attached ArchiveLoaders core::array<IFileArchive*> FileArchives; // currently attached Archives
core::array< IFileArchive*> FileArchive; // currently attached Archives
}; };
......
...@@ -23,12 +23,6 @@ CArchiveLoaderPAK::CArchiveLoaderPAK( io::IFileSystem* fs) ...@@ -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 //! returns true if the file maybe is able to be loaded by this class
bool CArchiveLoaderPAK::isALoadableFileFormat(const core::string<c16>& filename) const bool CArchiveLoaderPAK::isALoadableFileFormat(const core::string<c16>& filename) const
{ {
...@@ -219,7 +213,7 @@ IReadFile* CPakReader::openFile(s32 index) ...@@ -219,7 +213,7 @@ IReadFile* CPakReader::openFile(s32 index)
//! returns count of files in archive //! returns count of files in archive
u32 CPakReader::getFileCount() u32 CPakReader::getFileCount() const
{ {
return FileList.size(); return FileList.size();
} }
......
...@@ -38,9 +38,6 @@ namespace io ...@@ -38,9 +38,6 @@ namespace io
//! Constructor //! Constructor
CArchiveLoaderPAK(io::IFileSystem* fs); CArchiveLoaderPAK(io::IFileSystem* fs);
//! destructor
virtual ~CArchiveLoaderPAK();
//! returns true if the file maybe is able to be loaded by this class //! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".zip") //! based on the file extension (e.g. ".zip")
virtual bool isALoadableFileFormat(const core::string<c16>& filename) const; virtual bool isALoadableFileFormat(const core::string<c16>& filename) const;
...@@ -77,10 +74,10 @@ namespace io ...@@ -77,10 +74,10 @@ namespace io
virtual IReadFile* openFile(const core::string<c16>& filename); virtual IReadFile* openFile(const core::string<c16>& filename);
//! opens a file by index //! opens a file by index
IReadFile* openFile(s32 index); virtual IReadFile* openFile(s32 index);
//! returns count of files in archive //! returns count of files in archive
virtual u32 getFileCount(); virtual u32 getFileCount() const;
//! returns data of file //! returns data of file
virtual const IFileArchiveEntry* getFileInfo(u32 index); virtual const IFileArchiveEntry* getFileInfo(u32 index);
......
...@@ -1543,7 +1543,7 @@ void CQ3LevelMesh::InitShader() ...@@ -1543,7 +1543,7 @@ void CQ3LevelMesh::InitShader()
if ( LoadParam.loadAllShaders ) 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> save = FileSystem->getWorkingDirectory();
core::string<c16> newDir; core::string<c16> newDir;
......
...@@ -328,7 +328,6 @@ bool CZipReader::scanLocalHeader() ...@@ -328,7 +328,6 @@ bool CZipReader::scanLocalHeader()
} }
//! opens a file by file name //! opens a file by file name
IReadFile* CZipReader::openFile(const core::string<c16>& filename) IReadFile* CZipReader::openFile(const core::string<c16>& filename)
{ {
...@@ -341,7 +340,6 @@ 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 //! opens a file by index
IReadFile* CZipReader::openFile(s32 index) IReadFile* CZipReader::openFile(s32 index)
{ {
...@@ -440,15 +438,13 @@ IReadFile* CZipReader::openFile(s32 index) ...@@ -440,15 +438,13 @@ IReadFile* CZipReader::openFile(s32 index)
} }
//! returns count of files in archive //! returns count of files in archive
u32 CZipReader::getFileCount() u32 CZipReader::getFileCount() const
{ {
return FileList.size(); return FileList.size();
} }
//! returns data of file //! returns data of file
const IFileArchiveEntry* CZipReader::getFileInfo(u32 index) const IFileArchiveEntry* CZipReader::getFileInfo(u32 index)
{ {
...@@ -532,7 +528,7 @@ IFileArchive* CArchiveLoaderMount::createArchive(const core::string<c16>& filena ...@@ -532,7 +528,7 @@ IFileArchive* CArchiveLoaderMount::createArchive(const core::string<c16>& filena
{ {
IFileArchive *archive = 0; IFileArchive *archive = 0;
eFileSystemType current = FileSystem->setFileListSystem ( FILESYSTEM_NATIVE ); EFileSystemType current = FileSystem->setFileListSystem ( FILESYSTEM_NATIVE );
core::string<c16> save = FileSystem->getWorkingDirectory (); core::string<c16> save = FileSystem->getWorkingDirectory ();
core::string<c16> fullPath = FileSystem->getAbsolutePath ( filename ); core::string<c16> fullPath = FileSystem->getAbsolutePath ( filename );
......
...@@ -165,7 +165,7 @@ namespace io ...@@ -165,7 +165,7 @@ namespace io
virtual IReadFile* openFile(s32 index); virtual IReadFile* openFile(s32 index);
//! returns count of files in archive //! returns count of files in archive
virtual u32 getFileCount(); virtual u32 getFileCount() const;
//! returns data of file //! returns data of file
virtual const IFileArchiveEntry* getFileInfo(u32 index); virtual const IFileArchiveEntry* getFileInfo(u32 index);
...@@ -253,7 +253,7 @@ namespace io ...@@ -253,7 +253,7 @@ namespace io
private: private:
IFileSystem *Parent; IFileSystem *Parent;
void buildDirectory (); void buildDirectory();
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment