raylib icon indicating copy to clipboard operation
raylib copied to clipboard

[core] File extension case sensitivity on Windows

Open gordonshamway23 opened this issue 1 year ago • 1 comments

When loading images, textures, sounds, etc, the raylib loading functions will fail when your file extensions are not lower case. This is only relevant on windows systems. Linux OSes have case sensitive filenames. As an example i tried to load a png file called "test.PNG" on windows 10:

Image img=LoadImage("test.PNG")

Which does not succeed even if the file exist. If i rename the file to "test.png" loading works:

Image img=LoadImage("test.png")

Quick look in the sources reveals that the loading functions compare file extensions with strcmp, like:

strcmp(ext, ".png")==0

I think this should be done with stricmp on windows, and strcasecmp on non windows systems. Or with some other techniques like TextToLower i have seen in the raylib source.

Not a big deal though, but would be nice to fix.

gordonshamway23 avatar Sep 18 '22 14:09 gordonshamway23

This issue was discussed in the past and finally opted for the case sensitivity in all platforms... but maybe it's a good time to review it again...

raysan5 avatar Sep 19 '22 16:09 raysan5

I'd still vote a no on case insensitivity, but that's just me :shrug: ... It would require a bit more extra file reads to correctly load files.

RobLoach avatar Sep 25 '22 18:09 RobLoach

@RobLoach @raysan5 The problem with attempting to be cases sensitive on a case-insensitive platform is that things can go very badly and mysteriously if two filenames are used that only have some case differences.

So, somehow, the platform differences need to be honored in a simply-understandable manner.

File extensions are a distinct problem. On current Windows versions there are multiple extensions (e.g., .jpg and .jpeg) for the same file type. There was a time when MIME types were associated with file extensions, but that does not seem to be the case for disambiguation any longer.

Also, filenames are stored in mixed case in the current Windows scheme. The application that creates a file determines a case-sensitive name for it. So they are not stored in some forced case, just searched in a case-insensitive manner.

For our mutual edification:

F22xy023-2022-09-25-1735-CaseInsensitive

@orcmid scratches his head and wanders off.

orcmid avatar Sep 26 '22 00:09 orcmid

I can totally understand the arguments for continuing with case-sensitive file search. Maybe my problem was more related to the fact that a format of a file is determined by looking at the file extension, which is ok so far. But I don't like that this is done case-sensitive, which means you can only load "test.png", but not a file called "test.PNG", which is the same on all operating systems. A user is therefore forced to rename all uppercase file extensions to lowercase in order to load those files at all.

As a sidenote, I came across many files named with uppercase extensions, because some developer(s) of Adobe CS6 thought it would be a good idea to save all png files that way, no offense :).

In general I don't like the approach of format detection by looking at the file extension. Reading the file header or first bytes and then decide the format I would find better. But that is my opinion. Maybe you have other thoughts.

Still no big deal, just some thoughts, I can live with the current implementation.

Have a nice day.

gordonshamway23 avatar Sep 26 '22 19:09 gordonshamway23

@gordonshamway23 @RobLoach @orcmid After thinking about it I decided to keep it as-is, I prefer to keep the same behaviour between all platforms despite the annoyance it could imply on Windows devices. In any case, users can check the case-sesitivity on their side.

raysan5 avatar Oct 02 '22 09:10 raysan5