CFileSystem::addFolderFileArchive() bug fix

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
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

CFileSystem::addFolderFileArchive() bug fix

Post by MasterGod »

[Edit]
MasterGod's post from below wrote:Just to conclude this thread.
The following patch is a code I'm testing for more then two weeks now.
It works perfectly and under linux there's the only problem when choosing to ignore case but this bug is well known for the whole file system.
I've done many testings and it works just fine.
I hope you like it:

Code: Select all

Index: source/Irrlicht/CZipReader.cpp
===================================================================
--- source/Irrlicht/CZipReader.cpp	(revision 1309)
+++ source/Irrlicht/CZipReader.cpp	(working copy)
@@ -374,27 +374,90 @@
 		Base += "/";
 	}
 
+	core::stringc Buf = Parent->getWorkingDirectory();
+
+	Parent->changeWorkingDirectoryTo ( basename );
+	buildDirectory ( );
+	Parent->changeWorkingDirectoryTo ( Buf.c_str() );
+
+	FileList.sort();
 }
 
 void CUnZipReader::buildDirectory ( )
 {
+	IFileList * list = new CFileList();
+
+	SZipFileEntry entry;
+
+	const u32 size = list->getFileCount();
+	for (u32 i = 0; i!= size; ++i)
+	{
+		if ( !list->isDirectory( i ) )
+		{
+			entry.zipFileName = list->getFullFileName ( i );
+			entry.header.FilenameLength = entry.zipFileName.size ();
+			extractFilename(&entry);
+			FileList.push_back(entry);
+		}
+		else
+		{
+			const c8 * rel = list->getFileName ( i );
+
+			if (rel[0] != '.')
+			{
+				Parent->changeWorkingDirectoryTo ( rel );
+				buildDirectory ();
+				Parent->changeWorkingDirectoryTo ( ".." );
+			}
+		}
+	}
+
+	list->drop ();
 }
 
 //! opens a file by file name
 IReadFile* CUnZipReader::openFile(const c8* filename)
 {
-	core::stringc fname;
-	fname = Base;
-	fname += filename;
+	SZipFileEntry entry;
+	core::stringc fileName = core::stringc(filename);
 
+	if ( IgnoreCase )
+	{
+		Base.make_lower();
+		fileName.make_lower();
+		filename = fileName.c_str();
+	}
 
-	CUnzipReadFile* file = new CUnzipReadFile( fname, filename);
+	if ( IgnorePaths )
+	{
+		entry.simpleFileName = filename;
+		s32 index = FileList.binary_search(entry);
+		if(-1 == index)
+			return 0;
+
+		entry = FileList[index];
+	}
+	else
+	{
+		entry.zipFileName = Base;
+		entry.zipFileName += filename;
+		s32 i = fileName.findLastChar("\\/",2);
+		if (-1 == i)
+		{
+			entry.simpleFileName = filename;
+		}
+		else
+		{
+			entry.simpleFileName = fileName.subString( i+1, fileName.size() );
+		}
+	}
+
+	CUnzipReadFile* file = new CUnzipReadFile( entry.zipFileName, entry.simpleFileName.c_str() );
 	if (file->isOpen())
 		return file;
 
 	file->drop();
 	return 0;
-
 }
 
 //! returns fileindex
@@ -480,3 +543,5 @@
 } // end namespace io
 } // end namespace irr
 
+
+
Tested under:
1. Windows XP SP2, trunk revision 1309.
2. Linux Mint 4 (Based on Ubuntu), trunk revision 1309.
Tested with all combinations of 'ignorance' (lol) (true, true || false, false || true,false || false,true) and the behavior is as expected.

Also uploaded to the tracker:
http://sourceforge.net/tracker/index.ph ... tid=540678

I hope you like it :wink:
Cya.
[/Edit]

Post from below holding the latest fix - UP.
Original Post - DOWN.

hybrid wrote:The UnzipFolder is, just as md3, color chooser, and some other stuff, untested and mostly unfinished additions from one of the non-regular developers of Irrlicht. If you have worked with this code and know what it should do and how it should be implemented just tell us - we'll fix it then.
The method is bugged in a way that when you give it a parent directory it doesn't scan right all the files and sub directories of that parent folder.

Problem - This code will log "can't find files":

Code: Select all

device->getFileSystem()->addFolderFileArchive("../../");

	IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

	/*
	To let the mesh look a little bit nicer, we change its material a
	little bit: We disable lighting because we do not have a dynamic light
	in here, and the mesh would be totally black. Then we set the frame
	loop, so that the animation is looped between the frames 0 and 310.
	And at last, we apply a texture to the mesh. Without it the mesh
	would be drawn using only a color.
	*/
	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation ( scene::EMAT_STAND );
		node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
Apply this patch:

Code: Select all

Index: CZipReader.cpp
===================================================================
--- CZipReader.cpp	(revision 1286)
+++ CZipReader.cpp	(working copy)
@@ -374,27 +374,83 @@
 		Base += "/";
 	}
 
+	core::stringc Buf = Parent->getWorkingDirectory();
+
+	Parent->changeWorkingDirectoryTo ( basename );
+	buildDirectory ( );
+	Parent->changeWorkingDirectoryTo ( Buf.c_str() );
+
+	FileList.sort();
 }
 
 void CUnZipReader::buildDirectory ( )
 {
+	IFileList * list = new CFileList();
+
+	SZipFileEntry entry;
+
+	const u32 size = list->getFileCount();
+	for (u32 i = 0; i!= size; ++i)
+	{
+		if ( !list->isDirectory( i ) )
+		{
+			entry.zipFileName = list->getFullFileName ( i );
+			entry.header.FilenameLength = entry.zipFileName.size ();
+			extractFilename(&entry);
+			FileList.push_back(entry);
+		}
+		else
+		{
+			const c8 * rel = list->getFileName ( i );
+
+			if (rel[0] != '.')
+			{
+				Parent->changeWorkingDirectoryTo ( rel );
+				buildDirectory ();
+				Parent->changeWorkingDirectoryTo ( ".." );
+			}
+		}
+	}
+
+	list->drop ();
 }
 
 //! opens a file by file name
 IReadFile* CUnZipReader::openFile(const c8* filename)
 {
-	core::stringc fname;
-	fname = Base;
-	fname += filename;
+	SZipFileEntry entry;
 
+	if ( IgnorePaths )
+	{
+		entry.simpleFileName = filename;
+		s32 index = FileList.binary_search(entry);
+		if(-1 == index)
+			return 0;
 
-	CUnzipReadFile* file = new CUnzipReadFile( fname, filename);
+		entry = FileList[index];
+	}
+	else
+	{
+		entry.zipFileName = Base;
+		entry.zipFileName += filename;
+		core::stringc fileName = filename;
+		s32 i = fileName.findLastChar("\\/",3);
+		if (-1 == i)
+		{
+			entry.simpleFileName = filename;
+		}
+		else
+		{
+			entry.simpleFileName = fileName.subString( i+1, fileName.size() );
+		}
+	}
+
+	CUnzipReadFile* file = new CUnzipReadFile( entry.zipFileName, filename);
 	if (file->isOpen())
 		return file;
 
 	file->drop();
 	return 0;
-
 }
 
 //! returns fileindex
Now that code will run as expected.

P.S
I'm wondering, does posting patches here is the best way to get it noticed or should I upload to the tracker or some other method :?:
Last edited by MasterGod on Tue May 13, 2008 11:40 am, edited 2 times in total.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

I would guess that your best way to get your patch noticed would be to offer up some money. :lol:

The point of my statement is the fact that this has been covered numerous times. The Irrlicht developers will get to it when they get to it, and they will definitely look at it. So just let things go as they go.
TheQuestion = 2B || !2B
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

No its ok.
I'll just use it until its gets into the official (which I guess it will).
Just wanted to give-it-away cause I want to use it in my engine so I needed that fix anyway.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I'd recommend that you put it in the tracker, otherwise you'll have to keep BUMPing this thread.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

There were two bugs in my fix. This is the fixed patch:

[edit]
1. Didn't check the IgnoreCase boolean in openFile method.
2.

Code: Select all

s32 i = fileName.findLastChar("\\/",3);
should have been

Code: Select all

s32 i = fileName.findLastChar("\\/",2);
[/edit]

Code: Select all

Index: source/Irrlicht/CZipReader.cpp
===================================================================
--- source/Irrlicht/CZipReader.cpp	(revision 1298)
+++ source/Irrlicht/CZipReader.cpp	(working copy)
@@ -374,27 +374,90 @@
 		Base += "/";
 	}
 
+	core::stringc Buf = Parent->getWorkingDirectory();
+
+	Parent->changeWorkingDirectoryTo ( basename );
+	buildDirectory ( );
+	Parent->changeWorkingDirectoryTo ( Buf.c_str() );
+
+	FileList.sort();
 }
 
 void CUnZipReader::buildDirectory ( )
 {
+	IFileList * list = new CFileList();
+
+	SZipFileEntry entry;
+
+	const u32 size = list->getFileCount();
+	for (u32 i = 0; i!= size; ++i)
+	{
+		if ( !list->isDirectory( i ) )
+		{
+			entry.zipFileName = list->getFullFileName ( i );
+			entry.header.FilenameLength = entry.zipFileName.size ();
+			extractFilename(&entry);
+			FileList.push_back(entry);
+		}
+		else
+		{
+			const c8 * rel = list->getFileName ( i );
+
+			if (rel[0] != '.')
+			{
+				Parent->changeWorkingDirectoryTo ( rel );
+				buildDirectory ();
+				Parent->changeWorkingDirectoryTo ( ".." );
+			}
+		}
+	}
+
+	list->drop ();
 }
 
 //! opens a file by file name
 IReadFile* CUnZipReader::openFile(const c8* filename)
 {
-	core::stringc fname;
-	fname = Base;
-	fname += filename;
+	SZipFileEntry entry;
+	core::stringc fileName = core::stringc(filename);
 
+	if ( IgnoreCase )
+	{
+		Base.make_lower();
+		fileName.make_lower();
+		filename = fileName.c_str();
+	}
 
-	CUnzipReadFile* file = new CUnzipReadFile( fname, filename);
+	if ( IgnorePaths )
+	{
+		entry.simpleFileName = filename;
+		s32 index = FileList.binary_search(entry);
+		if(-1 == index)
+			return 0;
+
+		entry = FileList[index];
+	}
+	else
+	{
+		entry.zipFileName = Base;
+		entry.zipFileName += filename;
+		s32 i = fileName.findLastChar("\\/",2);
+		if (-1 == i)
+		{
+			entry.simpleFileName = filename;
+		}
+		else
+		{
+			entry.simpleFileName = fileName.subString( i+1, fileName.size() );
+		}
+	}
+
+	CUnzipReadFile* file = new CUnzipReadFile( entry.zipFileName, entry.simpleFileName.c_str() );
 	if (file->isOpen())
 		return file;
 
 	file->drop();
 	return 0;
-
 }
 
 //! returns fileindex
A little note from the testings I did which I had no idea what to do about is that when you use the addFolder method and choose a font file which is an XML file, in it the png file is just a name, not path so if you choose to NOT to ignore paths and provide the full XML file path, the png file will not be found (as it should) because it will look for the png file in the base path you gave the method (because Not ignoring path)
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

I'm not sure how much of a test-case it is but I'm using this patch for over a week now and everything is working just fine.
"Complex" directory structure or a simple one works just fine.

What say you, bitplane?

P.S
Were were you by the way in the last week?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

I've tried this code under Linux and I get a problem because of this code:

Code: Select all

	if ( IgnoreCase )
	{
		Base.make_lower();
		fileName.make_lower();
		filename = fileName.c_str();
	}
It doesn't find the file because I "corrupt" the name by making it lower as you see.
When I wrote that I forgot that Linux is case sensitive so does any one else has any better idea about how to do it otherwise?

P.S
I removed it from the tracker until this problem is fixed.
Oh and next time I upload it, should I upload it to the Patches Tracker or Bugs Tracker (I'm taking about the fix itself)?


Thanks.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The tracker doesn't matter too much, it can also be changed later on. But fixes should probably go into patches.
Oh, and the case sensitivity problems will be addressed in the file system enhancements planned for some of the next Irrlicht releases - depending on when we find some time to sketch a proper Filesystem interface.
CuteAlien
Admin
Posts: 10069
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

@hybrid: As you mentioned the case sensitivity problems, do you refer by some chance also to those mentioned in that old thread ( http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=25414 ) ? Does that mean those won't be fixed for now? Not even by simply removing all the make_lower calls?

Just asking as those are the bugs that are currently bugging me more than any other problem in Irrlicht (not just because I can't use an unpatched Irrlicht currently because of that, but also because it feels so extremely wrong...) and your comment seems to hint that I will have to live with those maybe even longer :-(
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, we started some discussion about the new filesystem recently, but we had no progress for some weeks now also. We should decice soon if the Filesystem changes will be done in the near future (which would mean no updates until that happns) or if we will make some hotfixing and postpone the filesystem overhaul.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Hmm... I see..
Well, I hope you get to it soon :wink:
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Just to conclude this thread.
The following patch is a code I'm testing for more then two weeks now.
It works perfectly and under linux there's the only problem when choosing to ignore case but this bug is well known for the whole file system.
I've done many testings and it works just fine.
I hope you like it:

Code: Select all

Index: source/Irrlicht/CZipReader.cpp
===================================================================
--- source/Irrlicht/CZipReader.cpp	(revision 1309)
+++ source/Irrlicht/CZipReader.cpp	(working copy)
@@ -374,27 +374,90 @@
 		Base += "/";
 	}
 
+	core::stringc Buf = Parent->getWorkingDirectory();
+
+	Parent->changeWorkingDirectoryTo ( basename );
+	buildDirectory ( );
+	Parent->changeWorkingDirectoryTo ( Buf.c_str() );
+
+	FileList.sort();
 }
 
 void CUnZipReader::buildDirectory ( )
 {
+	IFileList * list = new CFileList();
+
+	SZipFileEntry entry;
+
+	const u32 size = list->getFileCount();
+	for (u32 i = 0; i!= size; ++i)
+	{
+		if ( !list->isDirectory( i ) )
+		{
+			entry.zipFileName = list->getFullFileName ( i );
+			entry.header.FilenameLength = entry.zipFileName.size ();
+			extractFilename(&entry);
+			FileList.push_back(entry);
+		}
+		else
+		{
+			const c8 * rel = list->getFileName ( i );
+
+			if (rel[0] != '.')
+			{
+				Parent->changeWorkingDirectoryTo ( rel );
+				buildDirectory ();
+				Parent->changeWorkingDirectoryTo ( ".." );
+			}
+		}
+	}
+
+	list->drop ();
 }
 
 //! opens a file by file name
 IReadFile* CUnZipReader::openFile(const c8* filename)
 {
-	core::stringc fname;
-	fname = Base;
-	fname += filename;
+	SZipFileEntry entry;
+	core::stringc fileName = core::stringc(filename);
 
+	if ( IgnoreCase )
+	{
+		Base.make_lower();
+		fileName.make_lower();
+		filename = fileName.c_str();
+	}
 
-	CUnzipReadFile* file = new CUnzipReadFile( fname, filename);
+	if ( IgnorePaths )
+	{
+		entry.simpleFileName = filename;
+		s32 index = FileList.binary_search(entry);
+		if(-1 == index)
+			return 0;
+
+		entry = FileList[index];
+	}
+	else
+	{
+		entry.zipFileName = Base;
+		entry.zipFileName += filename;
+		s32 i = fileName.findLastChar("\\/",2);
+		if (-1 == i)
+		{
+			entry.simpleFileName = filename;
+		}
+		else
+		{
+			entry.simpleFileName = fileName.subString( i+1, fileName.size() );
+		}
+	}
+
+	CUnzipReadFile* file = new CUnzipReadFile( entry.zipFileName, entry.simpleFileName.c_str() );
 	if (file->isOpen())
 		return file;
 
 	file->drop();
 	return 0;
-
 }
 
 //! returns fileindex
@@ -480,3 +543,5 @@
 } // end namespace io
 } // end namespace irr
 
+
+
Tested under:
1. Windows XP SP2, trunk revision 1309.
2. Linux Mint 4 (Based on Ubuntu), trunk revision 1309.
Tested with all combinations of 'ignorance' (lol) (true, true || false, false || true,false || false,true) and the behavior is as expected.

Also uploaded to the tracker:
http://sourceforge.net/tracker/index.ph ... tid=540678

I hope you like it :wink:
Cya.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Post Reply