浏览代码

LibGfx: Make Bitmap path handling case insensitive

Bitmap::is_path_a_supported_image_format() and Bitmap::load_from_file()
now check the file extension with CaseSensitivity::CaseInsensitive.

This fixes a couple of inconsistencies, for example would
FileSystemModel::icon_for() recognize image files uppercase extensions
but couldn't create thumbnails for them (any attempt to create a bitmap
from such files would fail).
Linus Groh 4 年之前
父节点
当前提交
5b68ea8dde
共有 3 个文件被更改,包括 5 次插入5 次删除
  1. 1 1
      Libraries/LibGUI/FileSystemModel.cpp
  2. 2 2
      Libraries/LibGfx/Bitmap.cpp
  3. 2 2
      Libraries/LibGfx/Bitmap.h

+ 1 - 1
Libraries/LibGUI/FileSystemModel.cpp

@@ -471,7 +471,7 @@ Icon FileSystemModel::icon_for(const Node& node) const
     if (node.full_path() == "/")
         return FileIconProvider::icon_for_path("/");
 
-    if (Gfx::Bitmap::is_path_a_supported_image_format(node.name.to_lowercase())) {
+    if (Gfx::Bitmap::is_path_a_supported_image_format(node.name)) {
         if (!node.thumbnail) {
             if (!const_cast<FileSystemModel*>(this)->fetch_thumbnail_for(node))
                 return FileIconProvider::filetype_image_icon();

+ 2 - 2
Libraries/LibGfx/Bitmap.cpp

@@ -122,8 +122,8 @@ RefPtr<Bitmap> Bitmap::create_wrapper(BitmapFormat format, const IntSize& size,
 
 RefPtr<Bitmap> Bitmap::load_from_file(const StringView& path)
 {
-#define __ENUMERATE_IMAGE_FORMAT(Name, Ext) \
-    if (path.ends_with(Ext))                \
+#define __ENUMERATE_IMAGE_FORMAT(Name, Ext)                    \
+    if (path.ends_with(Ext, CaseSensitivity::CaseInsensitive)) \
         return load_##Name(path);
     ENUMERATE_IMAGE_FORMATS
 #undef __ENUMERATE_IMAGE_FORMAT

+ 2 - 2
Libraries/LibGfx/Bitmap.h

@@ -97,8 +97,8 @@ public:
     static RefPtr<Bitmap> create_from_serialized_byte_buffer(ByteBuffer&& buffer);
     static bool is_path_a_supported_image_format(const StringView& path)
     {
-#define __ENUMERATE_IMAGE_FORMAT(Name, Ext) \
-    if (path.ends_with(Ext))                \
+#define __ENUMERATE_IMAGE_FORMAT(Name, Ext)                    \
+    if (path.ends_with(Ext, CaseSensitivity::CaseInsensitive)) \
         return true;
         ENUMERATE_IMAGE_FORMATS
 #undef __ENUMERATE_IMAGE_FORMAT