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) Change-Id: I25475b419b5fbe863c71f553a336757d7950bf48 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2662 Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
parent
2a3b385efb
commit
17626df948
@ -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 @@ SVGImporter::Import(Icon* icon, const entry_ref* ref)
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user