FileDialog Not Working Under Linux
FileDialog Not Working Under Linux
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>
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>
-
- Posts: 34
- Joined: Thu Aug 04, 2005 9:37 pm
-
- Posts: 61
- Joined: Mon Oct 25, 2004 12:11 am
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:
In the constructor CFileList::CFileList(), replace the linux version with this:
That should also report the correct filesize now, and also the cwd. Let me know if this compiles ok for you.[/code]
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>
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
-
- Posts: 34
- Joined: Thu Aug 04, 2005 9:37 pm
-
- Posts: 34
- Joined: Thu Aug 04, 2005 9:37 pm
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....
Does Niko comment on bug fixes as to whether he will put them in or not?
Cheers,
Dr. A>
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]);
...
Cheers,
Dr. A>
-
- Posts: 61
- Joined: Mon Oct 25, 2004 12:11 am
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:
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.
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);
}
-
- Posts: 34
- Joined: Thu Aug 04, 2005 9:37 pm
-
- Posts: 34
- Joined: Thu Aug 04, 2005 9:37 pm
Dohh! 0.12 Is still broke
The new 0.12 release updated the code, but it missed a few important lines.
It needs the following before the while() -
Without it, you can't navigate up to the parent directory.
Dr. A>
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);
Dr. A>