FileDialog Not Working Under Linux

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
DrAnonymous

FileDialog Not Working Under Linux

Post by DrAnonymous »

I compiled irrlicht 0.11 under RH 8. It opens the filedialog, but it doesn't recognize any of the directories, including the . and ..

When I examined the source, the class CFileList isn't detecting any of the directories properly. The d_type is returning 0 for all the direntries.

Anyone else have this problem? Any ideas how to fix it?

Regards,
Dr. A>
DrAnonymous
Posts: 34
Joined: Thu Aug 04, 2005 9:37 pm

Post by DrAnonymous »

Any one have inputs or something similiar? This is a big deal for my current project.

Thanks,
Dr. A>
William Finlayson
Posts: 61
Joined: Mon Oct 25, 2004 12:11 am

Post by William Finlayson »

I just tried it out on Ubuntu and was surprised that I hadn't spotted this before, I get the exact same problem. I managed to fix it but it would be nice to know if it also works on your system.

All of the changes are in CFileList.cpp. Near the top in the LINUX includes, add:

Code: Select all

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
In the constructor CFileList::CFileList(), replace the linux version with this:

Code: Select all

// --------------------------------------------
	// Linux version
	#ifdef LINUX
	struct dirent **namelist;
	struct stat buf;
	FileEntry entry;
	Path = getcwd(NULL,0);
	
	s32 n = scandir(".", &namelist, 0, alphasort);
	if (n >= 0)
	{
		while(n--)
		{
			entry.Name = namelist[n]->d_name;
			if(stat(namelist[n]->d_name, &buf)==0) {
				entry.Size = buf.st_size;
				entry.isDirectory = S_ISDIR(buf.st_mode);
			}
			else {
				entry.Size = 0;
				entry.isDirectory = namelist[n]->d_type == DT_DIR;
			}
			Files.push_back(entry);
			free(namelist[n]);
		}
		free(namelist);
	}
	#endif
That should also report the correct filesize now, and also the cwd. Let me know if this compiles ok for you.[/code]
DrAnonymous
Posts: 34
Joined: Thu Aug 04, 2005 9:37 pm

Post by DrAnonymous »

I'll give it a try and awhile. Thanks!

Dr. A>
DrAnonymous
Posts: 34
Joined: Thu Aug 04, 2005 9:37 pm

Post by DrAnonymous »

Works great!!

I added a small change. I don't like the .. and . showing at the bottom of the list. The . path is unneccssary IMHO. Here is my slightly tweaked version -

after s32 n = scanr....

Code: Select all


// Add default parent - even when at /, this is available
entry.Name = "..";
entry.Size = 0;
entry.isDirectory = true;
Files.push_back(entry);

if(n >= 0)
...
...
     if(n > 1)  // Only add entries that aren't .. or . since they are already handled
           Files.push_back(entry);
     free(namelist[n]);

...
Does Niko comment on bug fixes as to whether he will put them in or not?

Cheers,
Dr. A>
William Finlayson
Posts: 61
Joined: Mon Oct 25, 2004 12:11 am

Post by William Finlayson »

Glad I could be some help :) I like the tweaks you made, they make it more conventional. I have an additional change though, under linux you can't guarantee that . and .. will be the last two entries on the list, as it is simply sorted alphabetically, and other files can start with "." as well. This should be safer to use:

Code: Select all

if (n >= 0)
	{
		while(n--)
		{
			if((strcmp(namelist[n]->d_name, ".")==0)|(strcmp(namelist[n]->d_name, "..")==0)) { 
				// Only add entries that aren't .. or . since they are already handled
				free(namelist[n]);
				continue;
			}
			entry.Name = namelist[n]->d_name;
			if(stat(namelist[n]->d_name, &buf)==0) {
				entry.Size = buf.st_size;
				entry.isDirectory = S_ISDIR(buf.st_mode);
			}
			else {
				entry.Size = 0;
				entry.isDirectory = namelist[n]->d_type == DT_DIR;
			}
           	Files.push_back(entry); 
			free(namelist[n]);
		}
		free(namelist);
	}
I'm sending Niko an email tonight anyway about another bug-fix, so incase he hasn't spotted this thread already, I'll let him know about it. He is understandably very busy though, so don't expect to hear anything on this too quick.
DrAnonymous
Posts: 34
Joined: Thu Aug 04, 2005 9:37 pm

Post by DrAnonymous »

Good idea about removing the dependance on the last 2 items being .. or .

Thanks for the assistance!

Cheers,
Dr. A>
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

DrAnonymous wrote:Does Niko comment on bug fixes as to whether he will put them in or not?
Sometimes, when I have enough time. :) But this will be included, thanks all :)
DrAnonymous
Posts: 34
Joined: Thu Aug 04, 2005 9:37 pm

Dohh! 0.12 Is still broke

Post by DrAnonymous »

The new 0.12 release updated the code, but it missed a few important lines. :(

It needs the following before the while() -

Code: Select all

// Add default parent - even when at /, this is available
entry.Name = "..";
entry.Size = 0;
entry.isDirectory = true;
Files.push_back(entry);
Without it, you can't navigate up to the parent directory.

Dr. A>
Post Reply