As i tried to load from another archive-format than zip, i found no
point to 'add' this functionality from outside. So i added a small Interface
to Irrlicht : IExternFileSystem. And added also a method to add a extern filesystem
to irrlicht. with this addition you should be able to load from own archives or
from memory.
You have only to implement the IExternFileSystem.
One Note from me - this is a 'smooth' patch , instead of making this complete -
define all FileSystems as ExternFileSystems and reduce the loop and amount of arrays in CFileSystem.
This should be done by someone who is 'closer' to the core-team. But i think it
would be good if we can specify whre irrlicht looks for the files and where not.
At the Moment Irrlicht look at first in FileSytem, ZIp and Pack and then (with this Patch)
in a added extern filesystems. Sometime we want that irrlicht looks only in a specific
archive/filesystem.
Code: Select all
Index: include/IExternFileSystem.h
===================================================================
--- include/IExternFileSystem.h (revision 0)
+++ include/IExternFileSystem.h (revision 0)
@@ -0,0 +1,30 @@
+#ifndef IEXTERNFILESYSTEM_H_INCLUDED
+#define IEXTERNFILESYSTEM_H_INCLUDED
+
+#include "IReferenceCounted.h"
+
+namespace irr
+{
+namespace io
+{
+
+class IReadFile;
+
+class IExternFileSystem : public virtual IReferenceCounted
+{
+public:
+
+ //! destructor
+ virtual ~IExternFileSystem() {};
+
+ //! opens a file by file name
+ virtual IReadFile* openFile(const c8* filename) = 0;
+
+ //! returns fileindex
+ virtual s32 findFile(const c8* filename) = 0;
+
+};
+
+}
+}
+#endif // IEXTERNFILESYSTEM_H_INCLUDED
Index: include/IFileSystem.h
===================================================================
--- include/IFileSystem.h (revision 1027)
+++ include/IFileSystem.h (working copy)
@@ -9,6 +9,8 @@
#include "IXMLReader.h"
#include "irrString.h"
+#include "IExternFileSystem.h"
+
namespace irr
{
namespace video
@@ -38,6 +40,9 @@
//! destructor
virtual ~IFileSystem() {}
+ virtual void addExternFileSysten(IExternFileSystem* extFS) = 0;
+
+
//! Opens a file for read access.
/** \param filename: Name of file to open.
\return Returns a pointer to the created file interface.
@@ -50,17 +55,17 @@
\param memory: A pointer to the start of the file in memory
\param len: The length of the memory in bytes
\param fileName: The name given to this file
- \param deleteMemoryWhenDropped: True if the memory should be deleted
+ \param deleteMemoryWhenDropped: True if the memory should be deleted
along with the IReadFile when it is dropped.
\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.
+ See IReferenceCounted::drop() for more information.
*/
virtual IReadFile* createMemoryReadFile(void* memory, s32 len, const c8* fileName, bool deleteMemoryWhenDropped=false) = 0;
//! Opens a file for write access.
/** \param filename: Name of file to open.
- \param append: If the file already exist, all write operations are
+ \param append: If the file already exist, all write operations are
appended to the file.
\return Returns a pointer to the created file interface. 0 is returned, if the
file could not created or opened for writing.
@@ -69,7 +74,7 @@
virtual IWriteFile* createAndWriteFile(const c8* filename, bool append=false) = 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.
+ /** After calling this, the Irrlicht Engine will search and open files directly from this archive too.
This is useful for hiding data from the end user, speeding up file access and making it possible to
access for example Quake3 .pk3 files, which are nothing different than .zip files.
\param filename: Filename of the zip archive to add to the file system.
@@ -89,9 +94,9 @@
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) = 0;
-
+
//! Adds an pak archive to the file system.
- /** After calling this, the Irrlicht Engine will search and open files directly from this archive too.
+ /** After calling this, the Irrlicht Engine will search and open files directly from this archive too.
This is useful for hiding data from the end user, speeding up file access and making it possible to
access for example Quake2/KingPin/Hexen2 .pak files
\param filename: Filename of the pak archive to add to the file system.
Index: source/Irrlicht/CFileSystem.cpp
===================================================================
--- source/Irrlicht/CFileSystem.cpp (revision 1027)
+++ source/Irrlicht/CFileSystem.cpp (working copy)
@@ -56,7 +56,16 @@
}
+void CFileSystem::addExternFileSysten(IExternFileSystem* extFS)
+{
+ if (extFS)
+ {
+ ExternSystems.push_back(extFS);
+ }
+}
+
+
//! opens a file for read access
IReadFile* CFileSystem::createAndOpenFile(const c8* filename)
{
@@ -84,12 +93,20 @@
return file;
}
+
+ for ( i = 0; i<ExternSystems.size(); ++i)
+ {
+ file = ExternSystems[i]->openFile(filename);
+ if (file)
+ return file;
+ }
+
file = createReadFile(filename);
return file;
}
//! 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 c8* fileName, bool deleteMemoryWhenDropped)
{
if (!memory)
@@ -244,7 +261,7 @@
return ".";
}
-//! Creates a list of files and directories in the current working directory
+//! Creates a list of files and directories in the current working directory
IFileList* CFileSystem::createFileList() const
{
return new CFileList();
@@ -268,8 +285,12 @@
if (UnZipFileSystems[i]->findFile(filename)!=-1)
return true;
+ for (i=0; i<ExternSystems.size(); ++i)
+ if (ExternSystems[i]->findFile(filename)!=-1)
+ return true;
+
FILE* f = fopen(filename, "rb");
- if (f)
+ if (f)
{
fclose(f);
return true;
Index: source/Irrlicht/CFileSystem.h
===================================================================
--- source/Irrlicht/CFileSystem.h (revision 1027)
+++ source/Irrlicht/CFileSystem.h (working copy)
@@ -31,6 +31,8 @@
//! destructor
virtual ~CFileSystem();
+ virtual void addExternFileSysten(IExternFileSystem* extFS);
+
//! opens a file for read access
virtual IReadFile* createAndOpenFile(const c8* filename);
@@ -62,7 +64,7 @@
/** \param filename: The file to get the directory from */
virtual core::stringc getFileDir(const core::stringc& filename) const;
- //! 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.
virtual IFileList* createFileList() const;
@@ -95,6 +97,8 @@
core::array<CZipReader*> ZipFileSystems;
core::array<CPakReader*> PakFileSystems;
core::array<CUnZipReader*> UnZipFileSystems;
+ core::array<IExternFileSystem*> ExternSystems;
+
c8 WorkingDirectory[FILE_SYSTEM_MAX_PATH];
};
Mike