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,18 +13,18 @@ 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
FILESYSTEM_NATIVE = 0, // Native OS FileSystem
FILESYSTEM_VIRTUAL, // Virtual FileSystem
};
//! Base Info which all File archives must support on browsing
struct IFileArchiveEntry
{
IFileArchiveEntry () {}
IFileArchiveEntry() {}
core::string<c16> simpleFileName;
core::string<c16> path;
@ -40,32 +40,34 @@ 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;
virtual const core::string<c16>& getArchiveName() =0;
//! get the class Type
virtual const core::string<c16>& getArchiveType() = 0;
virtual const core::string<c16>& getArchiveType() =0;
//! 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
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.
/** \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;
virtual const IFileArchiveEntry* getFileInfo(u32 index) =0;
};
//! Class which is able to create an archive from a file.
@ -79,31 +81,28 @@ struct IArchiveLoader : public virtual IReferenceCounted
/** Check is based on the file extension (e.g. ".zip")
\param fileName Name of file to check.
\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
/** \param file File handle to check.
\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 might look into the file.
\param file File handle to check.
\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
/** \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;
virtual IFileArchive* createArchive(io::IReadFile* file, bool ignoreCase, bool ignorePaths) const =0;
};
} // end namespace io
} // end namespace irr
#endif

View File

@ -38,7 +38,7 @@ public:
\return Returns a pointer to the created file interface.
The returned pointer should be dropped when no longer needed.
See IReferenceCounted::drop() for more information. */
virtual IReadFile* createAndOpenFile(const core::string<c16>& filename) = 0;
virtual IReadFile* createAndOpenFile(const core::string<c16>& filename) =0;
//! Creates an IReadFile interface for accessing memory like a file.
/** This allows you to use a pointer to memory where an IReadFile is requested.
@ -51,7 +51,7 @@ public:
The returned pointer should be dropped when no longer needed.
See IReferenceCounted::drop() for more information.
*/
virtual IReadFile* createMemoryReadFile(void* memory, s32 len, const core::string<c16>& fileName, bool deleteMemoryWhenDropped=false) = 0;
virtual IReadFile* createMemoryReadFile(void* memory, s32 len, const core::string<c16>& fileName, bool deleteMemoryWhenDropped=false) =0;
//! Creates an IWriteFile interface for accessing memory like a file.
/** This allows you to use a pointer to memory where an IWriteFile is requested.
@ -65,7 +65,7 @@ public:
The returned pointer should be dropped when no longer needed.
See IReferenceCounted::drop() for more information.
*/
virtual IWriteFile* createMemoryWriteFile(void* memory, s32 len, const core::string<c16>& fileName, bool deleteMemoryWhenDropped=false) = 0;
virtual IWriteFile* createMemoryWriteFile(void* memory, s32 len, const core::string<c16>& fileName, bool deleteMemoryWhenDropped=false) =0;
//! Opens a file for write access.
@ -76,7 +76,7 @@ public:
file could not created or opened for writing.
The returned pointer should be dropped when no longer needed.
See IReferenceCounted::drop() for more information. */
virtual IWriteFile* createAndWriteFile(const core::string<c16>& filename, bool append=false) = 0;
virtual IWriteFile* createAndWriteFile(const core::string<c16>& filename, bool append=false) =0;
//! Adds an archive to the file system.
/** After calling this, the Irrlicht Engine will search and open files directly from this archive too.
@ -88,22 +88,25 @@ public:
\param ignorePaths: If set to true, files in the added archive can be accessed
without its complete path.
\return Returns true if the archive was added successful, false if not. */
virtual bool registerFileArchive( const core::string<c16>& filename, bool ignoreCase = true, bool ignorePaths = true) = 0;
virtual bool registerFileArchive(const core::string<c16>& filename, bool ignoreCase=true, bool ignorePaths=true) =0;
//! Adds an external archive loader to the engine.
virtual void addArchiveLoader(IArchiveLoader* loader) = 0;
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;
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;
virtual bool moveFileArchive(u32 sourceIndex, s32 relative) =0;
//! get the Archive number index
virtual IFileArchive* getFileArchive( u32 index ) = 0;
virtual IFileArchive* getFileArchive(u32 index) =0;
//! Adds an zip archive to the file system.
/** After calling this, the Irrlicht Engine will search and open files directly from this archive too.
@ -115,12 +118,12 @@ public:
\param ignorePaths: If set to true, files in the added archive can be accessed
without its complete path.
\return Returns true if the archive was added successful, false if not. */
virtual bool addZipFileArchive(const c8* filename, bool ignoreCase = true, bool ignorePaths = true)
virtual bool addZipFileArchive(const c8* filename, bool ignoreCase=true, bool ignorePaths=true)
{
return registerFileArchive ( filename, ignoreCase, ignorePaths );
return registerFileArchive(filename, ignoreCase, ignorePaths);
}
//! Adds an unzipped archive ( or basedirectory with subdirectories..) to the file system.
//! Adds an unzipped archive (or basedirectory with subdirectories..) to the file system.
/** Useful for handling data which will be in a zip file
\param filename: Filename of the unzipped zip archive base directory to add to the file system.
\param ignoreCase: If set to true, files in the archive can be accessed without
@ -128,9 +131,9 @@ public:
\param ignorePaths: If set to true, files in the added archive can be accessed
without its complete path.
\return Returns true if the archive was added successful, false if not. */
virtual bool addFolderFileArchive(const c8* filename, bool ignoreCase = true, bool ignorePaths = true)
virtual bool addFolderFileArchive(const c8* filename, bool ignoreCase=true, bool ignorePaths=true)
{
return registerFileArchive ( filename, ignoreCase, ignorePaths );
return registerFileArchive(filename, ignoreCase, ignorePaths);
}
//! Adds an pak archive to the file system.
@ -143,54 +146,55 @@ public:
\param ignorePaths: If set to true, files in the added archive can be accessed
without its complete path.(should not use with Quake2 paks
\return Returns true if the archive was added successful, false if not. */
virtual bool addPakFileArchive(const c8* filename, bool ignoreCase = true, bool ignorePaths = true)
virtual bool addPakFileArchive(const c8* filename, bool ignoreCase=true, bool ignorePaths=true)
{
return registerFileArchive ( filename, ignoreCase, ignorePaths );
return registerFileArchive(filename, ignoreCase, ignorePaths);
}
//! Get the current working directory.
/** \return Current working directory as a string. */
virtual const core::string<c16>& getWorkingDirectory() = 0;
virtual const core::string<c16>& getWorkingDirectory() =0;
//! Changes the current working directory.
/** \param newDirectory: A string specifying the new working directory.
The string is operating system dependent. Under Windows it has
the form "<drive>:\<directory>\<sudirectory>\<..>". An example would be: "C:\Windows\"
\return True if successful, otherwise false. */
virtual bool changeWorkingDirectoryTo(const core::string<c16>& newDirectory) = 0;
virtual bool changeWorkingDirectoryTo(const core::string<c16>& newDirectory) =0;
//! Converts a relative path to an absolute (unique) path, resolving symbolic links if required
/** \param filename Possibly relative filename begin queried.
\result Absolute filename which points to the same file. */
virtual core::string<c16> getAbsolutePath(const core::string<c16>& filename) const = 0;
virtual core::string<c16> getAbsolutePath(const core::string<c16>& filename) const =0;
//! Returns the directory a file is located in.
/** \param filename: The file to get the directory from.
\return String containing the directory of the file. */
virtual core::string<c16> getFileDir(const core::string<c16>& filename) const = 0;
virtual core::string<c16> getFileDir(const core::string<c16>& filename) const =0;
//! Returns the base part of a filename, i.e. the name without the directory part.
/** If no directory is prefixed, the full name is returned.
\param filename: The file to get the basename from
\param keepExtension True if filename with extension is returned otherwise everything
after the final '.' is removed as well. */
virtual core::string<c16> getFileBasename(const core::string<c16>& filename, bool keepExtension=true) const = 0;
virtual core::string<c16> getFileBasename(const core::string<c16>& filename, bool keepExtension=true) const =0;
//! 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 = 0;
virtual core::string<c16>& flattenFilename(core::string<c16>& directory, const core::string<c16>& root="/") const =0;
//! Creates a list of files and directories in the current working directory and returns it.
/** \return a Pointer to the created IFileList is returned. After the list has been used
it has to be deleted using its IFileList::drop() method.
See IReferenceCounted::drop() for more information. */
virtual IFileList* createFileList() = 0;
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.
\return Returns true if file exists, and false if it does not exist or an error occured. */
virtual bool existFile(const core::string<c16>& filename) const = 0;
virtual bool existFile(const core::string<c16>& filename) const =0;
//! Creates a XML Reader from a file which returns all parsed strings as wide characters (wchar_t*).
/** Use createXMLReaderUTF8() if you prefer char* instead of wchar_t*. See IIrrXMLReader for
@ -199,7 +203,7 @@ public:
IXMLReader is returned. After use, the reader
has to be deleted using its IXMLReader::drop() method.
See IReferenceCounted::drop() for more information. */
virtual IXMLReader* createXMLReader(const core::string<c16>& filename) = 0;
virtual IXMLReader* createXMLReader(const core::string<c16>& filename) =0;
//! Creates a XML Reader from a file which returns all parsed strings as wide characters (wchar_t*).
/** Use createXMLReaderUTF8() if you prefer char* instead of wchar_t*. See IIrrXMLReader for
@ -208,7 +212,7 @@ public:
IXMLReader is returned. After use, the reader
has to be deleted using its IXMLReader::drop() method.
See IReferenceCounted::drop() for more information. */
virtual IXMLReader* createXMLReader(IReadFile* file) = 0;
virtual IXMLReader* createXMLReader(IReadFile* file) =0;
//! Creates a XML Reader from a file which returns all parsed strings as ASCII/UTF-8 characters (char*).
/** Use createXMLReader() if you prefer wchar_t* instead of char*. See IIrrXMLReader for
@ -217,7 +221,7 @@ public:
IXMLReader is returned. After use, the reader
has to be deleted using its IXMLReaderUTF8::drop() method.
See IReferenceCounted::drop() for more information. */
virtual IXMLReaderUTF8* createXMLReaderUTF8(const core::string<c16>& filename) = 0;
virtual IXMLReaderUTF8* createXMLReaderUTF8(const core::string<c16>& filename) =0;
//! Creates a XML Reader from a file which returns all parsed strings as ASCII/UTF-8 characters (char*).
/** Use createXMLReader() if you prefer wchar_t* instead of char*. See IIrrXMLReader for
@ -226,21 +230,21 @@ public:
IXMLReader is returned. After use, the reader
has to be deleted using its IXMLReaderUTF8::drop() method.
See IReferenceCounted::drop() for more information. */
virtual IXMLReaderUTF8* createXMLReaderUTF8(IReadFile* file) = 0;
virtual IXMLReaderUTF8* createXMLReaderUTF8(IReadFile* file) =0;
//! Creates a XML Writer from a file.
/** \return 0, if file could not be opened, otherwise a pointer to the created
IXMLWriter is returned. After use, the reader
has to be deleted using its IXMLWriter::drop() method.
See IReferenceCounted::drop() for more information. */
virtual IXMLWriter* createXMLWriter(const core::string<c16>& filename) = 0;
virtual IXMLWriter* createXMLWriter(const core::string<c16>& filename) =0;
//! Creates a XML Writer from a file.
/** \return 0, if file could not be opened, otherwise a pointer to the created
IXMLWriter is returned. After use, the reader
has to be deleted using its IXMLWriter::drop() method.
See IReferenceCounted::drop() for more information. */
virtual IXMLWriter* createXMLWriter(IWriteFile* file) = 0;
virtual IXMLWriter* createXMLWriter(IWriteFile* file) =0;
//! Creates a new empty collection of attributes, usable for serialization and more.
/** \param driver: Video driver to be used to load textures when specified as attribute values.
@ -248,7 +252,7 @@ public:
\return Pointer to the created object.
If you no longer need the object, you should call IAttributes::drop().
See IReferenceCounted::drop() for more information. */
virtual IAttributes* createEmptyAttributes(video::IVideoDriver* driver=0) = 0;
virtual IAttributes* createEmptyAttributes(video::IVideoDriver* driver=0) =0;
};

View File

@ -32,9 +32,6 @@ namespace irr
namespace io
{
//! constructor
CFileSystem::CFileSystem()
{
@ -42,12 +39,11 @@ CFileSystem::CFileSystem()
setDebugName("CFileSystem");
#endif
setFileListSystem ( FILESYSTEM_NATIVE );
setFileListSystem(FILESYSTEM_NATIVE);
addArchiveLoader ( new CArchiveLoaderZIP ( this ) );
addArchiveLoader ( new CArchiveLoaderMount ( this ) );
addArchiveLoader ( new CArchiveLoaderPAK ( this ) );
addArchiveLoader(new CArchiveLoaderZIP(this));
addArchiveLoader(new CArchiveLoaderMount(this));
addArchiveLoader(new CArchiveLoaderPAK(this));
}
@ -56,28 +52,27 @@ 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 ();
ArchiveLoader[i]->drop();
}
}
//! opens a file for read access
IReadFile* CFileSystem::createAndOpenFile( const core::string<c16>& filename)
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;
}
@ -89,7 +84,7 @@ IReadFile* CFileSystem::createAndOpenFile( const core::string<c16>& filename)
//! Creates an IReadFile interface for treating memory like a file.
IReadFile* CFileSystem::createMemoryReadFile(void* memory, s32 len,
IReadFile* CFileSystem::createMemoryReadFile(void* memory, s32 len,
const core::string<c16>& fileName, bool deleteMemoryWhenDropped)
{
if (!memory)
@ -99,8 +94,8 @@ IReadFile* CFileSystem::createMemoryReadFile(void* memory, s32 len,
}
//! Creates an IReadFile interface for treating memory like a file.
IWriteFile* CFileSystem::createMemoryWriteFile(void* memory, s32 len,
const core::string<c16>& fileName, bool deleteMemoryWhenDropped)
IWriteFile* CFileSystem::createMemoryWriteFile(void* memory, s32 len,
const core::string<c16>& fileName, bool deleteMemoryWhenDropped)
{
if (!memory)
return 0;
@ -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)
{
@ -124,63 +118,64 @@ void CFileSystem::addArchiveLoader(IArchiveLoader* loader)
return;
//loader->grab();
ArchiveLoader.push_back ( loader );
ArchiveLoader.push_back(loader);
}
//! move the hirarchy of the filesystem. moves sourceIndex relative up or down
bool CFileSystem::moveFileArchive( u32 sourceIndex, s32 relative )
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 )
for (s32 s = (s32) sourceIndex;s != dest; s += dir)
{
if ( s < 0 || s > sourceEnd || s + dir < 0 || s + dir > sourceEnd )
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 )
bool CFileSystem::registerFileArchive(const core::string<c16>& filename, bool ignoreCase, bool ignorePaths)
{
IFileArchive* archive = 0;
bool ret = false;
u32 i;
// try to load archive based on file name
for ( i = 0; i < ArchiveLoader.size(); ++i)
for (i = 0; i < ArchiveLoader.size(); ++i)
{
if ( ArchiveLoader[i]->isALoadableFileFormat( filename ) )
if (ArchiveLoader[i]->isALoadableFileFormat(filename))
{
archive = ArchiveLoader[i]->createArchive( filename, ignoreCase, ignorePaths );
archive = ArchiveLoader[i]->createArchive(filename, ignoreCase, ignorePaths);
if (archive)
break;
}
}
// try to load archive based on content
if ( 0 == archive )
if (0 == archive)
{
io::IReadFile* file = createAndOpenFile(filename);
if ( file )
if (file)
{
for ( i = 0; i < ArchiveLoader.size(); ++i)
for (i = 0; i < ArchiveLoader.size(); ++i)
{
file->seek ( 0 );
if ( ArchiveLoader[i]->isALoadableFileFormat( file ) )
file->seek(0);
if (ArchiveLoader[i]->isALoadableFileFormat(file))
{
file->seek ( 0 );
archive = ArchiveLoader[i]->createArchive( file, ignoreCase, ignorePaths );
file->seek(0);
archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths);
if (archive)
break;
}
@ -189,71 +184,81 @@ bool CFileSystem::registerFileArchive( const core::string<c16>& filename, bool i
}
}
if ( archive )
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.
bool CFileSystem::unregisterFileArchive( u32 index )
//! 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 )
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 )
if (type != FILESYSTEM_NATIVE)
{
type = FILESYSTEM_VIRTUAL;
}
else
{
const s32 FILE_SYSTEM_MAX_PATH = 1024;
WorkingDirectory [ type ].reserve ( FILE_SYSTEM_MAX_PATH );
c16* r = (c16*) WorkingDirectory [ type ].c_str();
WorkingDirectory[type].reserve(FILE_SYSTEM_MAX_PATH);
c16* r = (c16*) WorkingDirectory[type].c_str();
#if defined( _IRR_USE_WINDOWS_CE_DEVICE_)
#elif defined( _IRR_WINDOWS_API_)
#if defined ( _IRR_WCHAR_FILESYSTEM )
_wgetcwd ( r, FILE_SYSTEM_MAX_PATH );
#if defined(_IRR_USE_WINDOWS_CE_DEVICE_)
#elif defined(_IRR_WINDOWS_API_)
#if defined(_IRR_WCHAR_FILESYSTEM )
_wgetcwd(r, FILE_SYSTEM_MAX_PATH);
#else
_getcwd(r, FILE_SYSTEM_MAX_PATH);
#endif
@ -261,17 +266,17 @@ const core::string<c16>& CFileSystem::getWorkingDirectory()
#if (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_))
#if defined ( _IRR_WCHAR_FILESYSTEM )
wgetcwd ( r, FILE_SYSTEM_MAX_PATH );
#if defined(_IRR_WCHAR_FILESYSTEM )
wgetcwd(r, FILE_SYSTEM_MAX_PATH);
#else
getcwd(r, (size_t)FILE_SYSTEM_MAX_PATH);
#endif
#endif
#endif
WorkingDirectory [ type ].validate();
WorkingDirectory[type].validate();
}
return WorkingDirectory [ type ];
return WorkingDirectory[type];
}
@ -280,20 +285,20 @@ bool CFileSystem::changeWorkingDirectoryTo(const core::string<c16>& newDirectory
{
bool success=false;
if ( FileSystemType != FILESYSTEM_NATIVE )
if (FileSystemType != FILESYSTEM_NATIVE)
{
WorkingDirectory [ FILESYSTEM_VIRTUAL ].append ( newDirectory );
flattenFilename ( WorkingDirectory [ FILESYSTEM_VIRTUAL ], "" );
WorkingDirectory[FILESYSTEM_VIRTUAL].append(newDirectory);
flattenFilename(WorkingDirectory[FILESYSTEM_VIRTUAL], "");
success = 1;
}
else
{
WorkingDirectory [ FILESYSTEM_NATIVE ] = newDirectory;
WorkingDirectory[FILESYSTEM_NATIVE] = newDirectory;
#if defined( _IRR_USE_WINDOWS_CE_DEVICE_)
#if defined(_IRR_USE_WINDOWS_CE_DEVICE_)
success = true;
#elif defined( _MSC_VER)
#if defined ( _IRR_WCHAR_FILESYSTEM )
#elif defined(_MSC_VER)
#if defined(_IRR_WCHAR_FILESYSTEM)
success=(_wchdir(newDirectory.c_str()) == 0);
#else
success=(_chdir(newDirectory.c_str()) == 0);
@ -311,16 +316,16 @@ core::string<c16> CFileSystem::getAbsolutePath(const core::string<c16>& filename
{
c16 *p=0;
#if defined( _IRR_USE_WINDOWS_CE_DEVICE_)
#if defined(_IRR_USE_WINDOWS_CE_DEVICE_)
return filename;
#elif defined( _IRR_WINDOWS_API_)
#elif defined(_IRR_WINDOWS_API_)
#if defined ( _IRR_WCHAR_FILESYSTEM )
#if defined(_IRR_WCHAR_FILESYSTEM )
c16 fpath[_MAX_PATH];
p = _wfullpath( fpath, filename.c_str(), _MAX_PATH);
p = _wfullpath(fpath, filename.c_str(), _MAX_PATH);
#else
c8 fpath[_MAX_PATH];
p = _fullpath( fpath, filename.c_str(), _MAX_PATH);
p = _fullpath(fpath, filename.c_str(), _MAX_PATH);
#endif
#elif (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_))
@ -393,11 +398,11 @@ core::string<c16> CFileSystem::getFileBasename(const core::string<c16>& filename
//! flaten a path and file name for example: "/you/me/../." becomes "/you"
core::string<c16>& CFileSystem::flattenFilename( core::string<c16>& directory, const core::string<c16>& root ) const
core::string<c16>& CFileSystem::flattenFilename(core::string<c16>& directory, const core::string<c16>& root) const
{
directory.replace ( '\\', '/' );
if ( lastChar ( directory ) != '/' )
directory.append ( '/' );
directory.replace('\\', '/');
if (lastChar(directory) != '/')
directory.append('/');
core::string<c16> dir;
core::string<c16> subdir;
@ -405,23 +410,21 @@ core::string<c16>& CFileSystem::flattenFilename( core::string<c16>& directory, c
s32 lastpos = 0;
s32 pos = 0;
while ( ( pos = directory.findNext ( '/', lastpos ) ) >= 0 )
while ((pos = directory.findNext('/', lastpos)) >= 0)
{
subdir = directory.subString ( lastpos, pos - lastpos + 1 );
subdir = directory.subString(lastpos, pos - lastpos + 1);
if ( subdir == "../" )
if (subdir == "../")
{
deletePathFromPath ( dir, 2 );
deletePathFromPath(dir, 2);
}
else
if ( subdir == "/" )
else if (subdir == "/")
{
dir = root;
}
else
if ( subdir != "./" )
else if (subdir != "./" )
{
dir.append ( subdir );
dir.append(subdir);
}
lastpos = pos + 1;
@ -430,17 +433,18 @@ 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)
//! Creates a list of files and directories in the current working directory
EFileSystemType CFileSystem::setFileListSystem(EFileSystemType listType)
{
eFileSystemType current = FileSystemType;
EFileSystemType current = FileSystemType;
FileSystemType = listType;
return current;
}
//! Creates a list of files and directories in the current working directory
IFileList* CFileSystem::createFileList()
//! Creates a list of files and directories in the current working directory
IFileList* CFileSystem::createFileList()
{
FileEntry e2;
FileEntry e3;
@ -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 )
@ -557,7 +559,7 @@ bool CFileSystem::existFile(const core::string<c16>& filename) const
FILE* f = fopen(filename.c_str(), "rb");
#endif
if (f)
if (f)
{
fclose(f);
return true;

View File

@ -51,11 +51,17 @@ 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.
virtual bool unregisterFileArchive( u32 index );
virtual IFileArchive* getFileArchive(u32 index);
//! 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
core::string<c16> WorkingDirectory [2]; // WorkingDirectory for Native/Virtual
core::array< IArchiveLoader* > ArchiveLoader; // currently attached ArchiveLoaders
core::array< IFileArchive*> FileArchive; // currently attached Archives
EFileSystemType FileSystemType; // Currently used FileSystemType
core::string<c16> WorkingDirectory [2]; // WorkingDirectory for Native/Virtual
core::array<IArchiveLoader*> ArchiveLoader; // currently attached ArchiveLoaders
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);
@ -253,7 +253,7 @@ namespace io
private:
IFileSystem *Parent;
void buildDirectory ();
void buildDirectory();
};