[haiku-commits] Change in haiku[master]: Icon-O-Matic: use the MIME sniffer to recognize SVG files

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 10 May 2020 16:58:20 +0000

From Adrien Destugues <pulkomandy@xxxxxxxxx>:

Adrien Destugues has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/2662 ;)


Change subject: Icon-O-Matic: use the MIME sniffer to recognize SVG files
......................................................................

Icon-O-Matic: use the MIME sniffer to recognize SVG files

Our sniffing rule is not perfect, but it is already a lot better than
what was done here.

Partially fixes #14437 (the icons also fails parsing for other reasons,
but with an error message, at least)
---
M src/apps/icon-o-matic/import_export/svg/SVGImporter.cpp
1 file changed, 6 insertions(+), 15 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/62/2662/1

diff --git a/src/apps/icon-o-matic/import_export/svg/SVGImporter.cpp 
b/src/apps/icon-o-matic/import_export/svg/SVGImporter.cpp
index 534b36c..8b3f176 100644
--- a/src/apps/icon-o-matic/import_export/svg/SVGImporter.cpp
+++ b/src/apps/icon-o-matic/import_export/svg/SVGImporter.cpp
@@ -15,6 +15,7 @@
 #include <Entry.h>
 #include <File.h>
 #include <Locale.h>
+#include <MimeType.h>
 #include <Path.h>

 #include "DocumentBuilder.h"
@@ -51,21 +52,11 @@
        if (ret < B_OK)
                return ret;

-       // peek into file to see if this could be an SVG file at all
-       BFile file(path.Path(), B_READ_ONLY);
-       ret = file.InitCheck();
-       if (ret < B_OK)
-               return ret;
-
-       ssize_t size = 5;
-       char buffer[size + 1];
-       if (file.Read(buffer, size) != size)
-               return B_ERROR;
-
-       // 0 terminate
-       buffer[size] = 0;
-       if (strcasecmp(buffer, "<?xml") != 0) {
-               // we might be  stretching it a bit, but what the heck
+       // Check that it indeed looks like an SVG file
+       BMimeType type;
+       ret = BMimeType::GuessMimeType(ref, &type);
+       if (ret != B_OK || strcmp(type.Type(), "image/svg+xml") != 0) {
+               printf("not an svg file %s %s\n", strerror(ret), type.Type());
                return B_ERROR;
        }


--
To view, visit https://review.haiku-os.org/c/haiku/+/2662
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I25475b419b5fbe863c71f553a336757d7950bf48
Gerrit-Change-Number: 2662
Gerrit-PatchSet: 1
Gerrit-Owner: Adrien Destugues <pulkomandy@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: Icon-O-Matic: use the MIME sniffer to recognize SVG files - Gerrit