Patch to IFileSystem::createFileList - support for zip/pak!

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
IPv6
Posts: 188
Joined: Tue Aug 08, 2006 11:58 am

Patch to IFileSystem::createFileList - support for zip/pak!

Post by IPv6 »

Hello!

Irrlicht have a great VFS subsystem but there is a long-standing problem with IFileSystem::createFileList: it is completely ignoring added zip/pak files so there is no way to enumerate them, which is useful sometimes. I suggest a small patch (well not patch really... but there is not much changes anyway) to address this problem. It is not ideal (but do the work) but can be used as a base for future changes.

So here it is.

PART 1/3. Changes in include/*.h files:
IFileSystem.h

Code: Select all

	// WAS: 	virtual IFileList* createFileList() const = 0;
	virtual IFileList* createFileList(bool vfsList = false) const = 0;

NOTE: we can`t use old createFileList declaration without new parameter, since createFileList on real file system enumerates top directories only but vfs enumerate all dirs and files at once. There is a problem - createFileList used recursely (by jumping into every directory in it) can cause infinte loop for vfs file list mixed with old file list, so there is a parameter to distinct this cases

IFileSystem.h

Code: Select all

	// new method
	// it can be used for many purposes in fact, with this method we can create custom file lists for internal usage, etc
	virtual bool addFile(const c8* filePath, bool isDir) = 0;
Last edited by IPv6 on Fri Dec 05, 2008 4:03 am, edited 2 times in total.
GameRotor-Games and more...
Wiredplane-Shareware utilities...
IPv6
Posts: 188
Joined: Tue Aug 08, 2006 11:58 am

PART 2/3.

Post by IPv6 »

PART 2/3. Changes in source/*.h files:
CFileSystem.h

Code: Select all

class CFileSystem : public IFileSystem
{
***
	//! Creates a list of files and directories in the current working directory 
	//! and returns it.
	virtual IFileList* createFileList(bool vfsList = false) const;
***
}
CFileList.h

Code: Select all

***
	//! constructor
	// WAS: CFileList();
	CFileList(bool bAddWorkingDirectoryList = true);
***
NOTE: we need an option to create empty file list (we do not want to mix zip/pak files with the rest ones)

CPakReader.h

Code: Select all

class CPakReader
{
***
	//! NEW method
	bool getFileList(IFileList* toList);
***
}
CZipReader.h

Code: Select all

class CZipReader
{
***
	//! NEW method
	bool getFileList(IFileList* toList);
***
}

class CUnZipReader

{
***
	//! NEW method
	bool getFileList(IFileList* toList);
***
}
GameRotor-Games and more...
Wiredplane-Shareware utilities...
IPv6
Posts: 188
Joined: Tue Aug 08, 2006 11:58 am

PART 3/3

Post by IPv6 »

PART 3/3. Changes in source/*.cpp

CFileList.cpp

Code: Select all

// WAS: CFileList::CFileList()
CFileList::CFileList(bool bAddWorkingDirectoryList)
{
	if(bAddWorkingDirectoryList)
	{
		*** // Old content of this function leaved intact
	}
}
CFileSystem.cpp

Code: Select all

//! Creates a list of files and directories in the current working directory 
IFileList* CFileSystem::createFileList(bool vfsList) const
{
	// Important: we should not add pak/zip files every time, only when the calling side expects it!
	// Since current use of createFileList 
	// can  be to try to make full list of some dir by recursivly jumping into every dir it get through this list
	// causing infinite loop

	// Besides that there is a GUI dialog that can hard to suit to walk on VFS files, for backward compatibility
	CFileList* result = new CFileList(vfsList?false:true);
	if (vfsList)
	{
		// So we adding VFS files only when asked nicely
		u32 i=0;
		for (i=0; i<ZipFileSystems.size(); ++i)
			ZipFileSystems[i]->getFileList(result);

		for (i=0; i<PakFileSystems.size(); ++i)
			PakFileSystems[i]->getFileList(result);

		for (i=0; i<UnZipFileSystems.size(); ++i)
			UnZipFileSystems[i]->getFileList(result);
	}
	return result;
}
CPakReader.cpp

Code: Select all

// NEW
bool CPakReader::getFileList(IFileList* toList)
{
	for (u32 i=0; i<FileList.size(); ++i)
	{
		SPakFileEntry entry = FileList[i];
		if (IgnoreCase)
		{
			entry.pakFileName.make_lower();
		}
		bool isDir = false;
		if (entry.pakFileName.size()>0 && (entry.pakFileName[entry.pakFileName.size()-1]=='/' || entry.pakFileName[entry.pakFileName.size()-1]=='\\'))
		{
			isDir = true;
		}
		if (!isDir && IgnorePaths)
		{
			deletePathFromFilename(entry.pakFileName);
		}
		toList->addFile(entry.pakFileName.c_str(),isDir);
	}
	return true;
}

CZipReader.cpp

Code: Select all

// NEW
bool CZipReader::getFileList(IFileList* toList)
{
	for (u32 i=0; i<FileList.size(); ++i)
	{
		SZipFileEntry entry = FileList[i];
		if (IgnoreCase)
		{
			entry.zipFileName.make_lower();
		}
		bool isDir = false;
		if (entry.zipFileName.size()>0 && (entry.zipFileName[entry.zipFileName.size()-1]=='/' || entry.zipFileName[entry.zipFileName.size()-1]=='\\'))
		{
			isDir = true;
		}
		if (!isDir && IgnorePaths)
		{
			deletePathFromFilename(entry.zipFileName);
		}
		toList->addFile(entry.zipFileName.c_str(),isDir);
	}
	return true;
}

// NEW
// TODO. Not implemented, since there will be the same files (actually) that are given by old createFileList. I mean if we really need list of files we can get it already... so not now
bool CUnZipReader::getFileList(IFileList* toList)
{
	return false;
}
GameRotor-Games and more...
Wiredplane-Shareware utilities...
IPv6
Posts: 188
Joined: Tue Aug 08, 2006 11:58 am

Post by IPv6 »

What you think? :)
GameRotor-Games and more...
Wiredplane-Shareware utilities...
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

We'll get to the file system fixes for Irrlicht 1.6. Right now the changes won't be integrated, because it would affect a vital part of the engine shortly before the next major release. Moreover, IIRC, most of the code should already exist in the archive file systems, it's just not exposed correctly. But that will all change in Irrlicht 1.6 :D
IPv6
Posts: 188
Joined: Tue Aug 08, 2006 11:58 am

Post by IPv6 »

great, thanks! :)
GameRotor-Games and more...
Wiredplane-Shareware utilities...
Post Reply