Recently, there are a lot of questions about encryption. The current filesystem is not flexible enough and is incapable of such things without modification.
I want to propose a new design for the file system, which IMO is more flexible:
pseudo-code:
class IFileSystem:
{
public:
void addSubSystem(IFileSubSystem* fss)
createAndWriteFile()
createAndOpenFile()
//other methods like addZipArchive can be added here
...
}
class IFileSubSystem: //or ISubFileSystem, I dont know which is the right way to write it
{
IReadFile* createAndOpenFile()// return null if there's no such file in this subsystem
IWriteFile* createAndWriteFile()// return null if the file cannot be written or this subsystem is read-only
}
implementation of IFileSystem
class CFileSystem:
{
void addSubSystem(IFileSubSystem* fss)
{
subsystems.push_front(fss);//so that new subsystems overides old subsystems
}
createAndWriteFile()
{
//iterate through the list of subsystems.
//call createAndWriteFile on them
//return the first non-null result
}
createAndOpenFile()
{
//iterate through the list of subsystems.
//call createAndOpenFile on them
//return the first non-null result
}
private:
core::list<fss*> subsystems;
}
With this design:
-Zip archive, pak archive , folder archive, memory file can then be implemented as subsystems. We will have some built-in subsystems such as : CRealFileSystem(which use normal file access), CZipFileSystem, CPakFileSystem, CFolderSystem, CMemoryFileSystem ...
-changeWorkingDirectory can be done by changing the directory the current CFolderSystem
-Users have full control of input/output by writing their own subsystems to overrides the built-in ones. They can use whatever encryption
-Minimal rewrite: you only need to cut the existing code of CFileSystem and then paste it to different subsystems.
I know file system is of low priority compare to other things but a flexible virtual filesystem is important for game dev, which I think most irrlicht users are doing. It helps a lot in creating moddable games, protecting assets ....
Better file system design?
Better file system design?
My name is bull, for we are many ...