addFileOpenDialog: case ignored, all lower-case?

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
johnny?
Posts: 2
Joined: Wed Sep 23, 2009 2:11 pm

addFileOpenDialog: case ignored, all lower-case?

Post by johnny? »

Possible bug:

I require case-sensitive filenames, and it appears that this addFileOpenDialog function only deals with lower-case filename strings.

It lists all the files in lower case, and also when I retrieve the selected name using getFileName the returned string appears to be similarly lowercased.

I tested this with MSVC on XP using the code from the tutorials:
(Irrlicht 1.7.1, not SVN)

Code: Select all

#include <irrlicht.h>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;


IGUIEnvironment* guienv = 0;
IGUIStaticText *guiTest = 0;


class MyEventReceiver : public IEventReceiver
{
public:

	virtual bool OnEvent(const SEvent& event)
	{
		if (event.EventType == EET_GUI_EVENT)
		{
			s32 id = event.GUIEvent.Caller->getID();

			switch(event.GUIEvent.EventType)
			{

				case EGET_BUTTON_CLICKED:
					switch(id)
					{
						case 20:
							guienv->addFileOpenDialog(L"Select a file, then click OK", true, 0, 10 );
							return true;
					}

				case EGET_FILE_SELECTED:			
					switch(id)
					{
						case 10:
						{
							IGUIFileOpenDialog* dialog = (IGUIFileOpenDialog*)event.GUIEvent.Caller;
							guiTest->setText( dialog->getFileName()  );
							return true;
						}

					default:
						return false;
					}
					break;

			default:
				break;
			}
		}


		return false;
	}

};




int main()
{
	IrrlichtDevice *device = createDevice( video::EDT_OPENGL, dimension2d<u32>(640, 480), 16, false, false, false, 0);
	if (!device)return 1;

	device->setWindowCaption(L"WHY ALL LOWER-CASE FILENAMES?!");

	MyEventReceiver receiver;
	device->setEventReceiver(&receiver);

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	guienv = device->getGUIEnvironment();

	guienv->addButton(rect<s32>(100,100,540,380), 0, 20, L"CLICK ME!!", L"Opens FileOpenDialogue");
	guiTest = guienv->addStaticText(L"", rect<s32>(20,20,620,42), true);
							
	while(device->run())
	{
		driver->beginScene(true, true, SColor(255,100,101,140));
			smgr->drawAll();
			guienv->drawAll();
		driver->endScene();
	}

	device->drop();

	return 0;
}
We would expect this work correctly on Linux and OSX, so why should it not do so on Windows?

:?:
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

Why do you want case-sensitive filenames on Windows? The system is not case sensitive, so imho it's OK in the way it works.
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
johnny?
Posts: 2
Joined: Wed Sep 23, 2009 2:11 pm

Post by johnny? »

We are developing a set of tools that work with our Irrlicht-driven engine across multiple platforms.
If a file generated from a tool on Windows does not store case-sensitive strings properly, then it will not parse correctly on OSX or Linux where the filenames don't change, but their case-sensitivity does.

Let's take a simple example:- a tool which writes out a simple text-file which stores the filename of an MD2 model and a texture image.
Compiled and executed on Windows, the tool would use addFileOpenDialog to select an MD2 model first from a pool of other files, and then select a texture file to associate with it.

Both strings would be written out to a text-file, ignoring all cases and written as retreived: in lower case.

On Windows: the text-file is parsed, the string filenames are read and everything works as expected

On OSX: the text-file is parsed, but the application fails because it couldn't find the incorrectly-cased filenames, from the same pool of files.


It isn't a question about how addFileOpenDialog is used, but how it's expected to behave

Could somebody explain why all strings should be forced to lowercase on Windows using this function?
At least on Windows OS, where case sensitivity doesn't matter and there isn't any reason to enforce lowercase filename strings, why is it being done at all?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

It does so in order to keep also the assets cross-platform. If you store everything in lower case files names, it will work everywhere.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

hybrid, are you saying that irrlicht DOES force the filenames to lowercase when they go through the filesystem? If so, what's the reason?

I guess johnny could just keep all his filenames lowercase on all systems but as filenames CAN be uppercase or lowercase shouldn't irrlicht support that ability? It seems a bit harsh to enforce users to keep their filenames in a specific format for use with Irrlicht...?

And of course if Irrlicht does do this then surely that would mean that it wouldn't work on linux/OSX as the case of the filenames matters so if you try and open a filename such as Foo.PNG but irrlicht forces you to open it as foo.png then it would fail wouldn't it?
Image Image Image
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

On Linux and OSX Irrlicht doesn't do that. I think it might by now no longer be necessary doing lowercase names on Windows with the 1.7 changes we made. Usually the lowercase name can be saved additionally or constructed on the fly. I had missed so far that the Windows filesystem still converts all names in the filelists to lower-case characters by default.

So I would say we should figure out if there really are still problems in keeping uppercase characters and add this to the bugtracker. I'm not sure about filelists in general, but at least the FileOpenDialog should probably display the real names.
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
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Pfff ... one of those things where I'm really not sure on how to fix them. My gut feeling is that converting to lowercase is just wrong and the original name should in no case be changed, except in comparison (and for that a lower-case version could be cached). But well, I wrote none of the places which uses filelists, so I basically only know about the FileOpenDialog.

One solution would be adding another flag in the filelists. Instead of just having ignoreCase it could be "ignoreCaseOnFind" and "convertToLower". I would set the first for Windows, but not the second. I don't know what the best setting for all the different readers would be.

The other solution is - remove the make_lower in CFileList::addItem, use a case-independent comparison in CFileList::findFile and check all places where getFileName or getFullFileName had been used and try to figure out how to fix those. As the case-information is in the filelist, this would probably need another function in filelist which allows comparing filenames regarding the active ignoreCase setting.

The first solution is probably more downward compatible, the second maybe cleaner. Feedback welcome.

edit: Just talked with Yoran and he had another idea which might be the simplest and most downward compatible. Keep internal the unconverted name, but convert on find and on the get functions (so Interface works the same as ever). But add additional functions to also get the original filename.
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: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yeah, the latter was the idea that bitplane started to work on. The FileSystem (or more specifically the file list) should take over the case sensitivity handling. I've also hit some of those problems recently when reworking some other file list problems. I'm not yet sure, though, what we have to change to get this really clean.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I thought some more about it and we don't even really need new functions, just another parameter for existing functions would be sufficient already. So we keep original names internally but return converted names per default to keep downward compatibility completely intact. Just add a parameter to the functions allow getting/using the original unmodified filename instead and use that one then in the IGUIFileOpenDialog.

Also - the FileList cares already in a certain way about sensitivity handling - the problem is that it doesn't do it correct. Correct handling on Windows is to keep case-sensitivity, but to ignore it (except for example for ordering and display). That's why my first proposal was adding another flag. But I don't know yet about all the other filesystems (zip, etc) and the rules for those. I think there might be some which actually do convert names.
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
Post Reply