From 31b1c72ddc66512c3a9cef4e59b94bdafc713ad4 Mon Sep 17 00:00:00 2001 From: François Revol Date: Mon, 21 Nov 2016 16:38:22 +0100 Subject: haiku: add a file extension when viewing source Pe still requires it to detect the language, this makes it easier. --- frontends/beos/gui.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/frontends/beos/gui.cpp b/frontends/beos/gui.cpp index 254fa9059..c1b1536cf 100644 --- a/frontends/beos/gui.cpp +++ b/frontends/beos/gui.cpp @@ -840,13 +840,28 @@ void nsbeos_gui_view_source(struct hlcache_handle *content) * allow it to be re-used next time NetSurf is started. The * memory overhead from doing this is under 1 byte per * filename. */ - const char *filename = filename_request(); - if (!filename) { + BString filename(filename_request()); + if (filename.IsEmpty()) { beos_warn_user("NoMemory", 0); return; } + + lwc_string *mime = content_get_mime_type(content); + + /* provide an extension, as Pe still doesn't sniff the MIME */ + if (mime) { + BMimeType type(lwc_string_data(mime)); + BMessage extensions; + if (type.GetFileExtensions(&extensions) == B_OK) { + BString ext; + if (extensions.FindString("extensions", &ext) == B_OK) + filename << "." << ext; + } + /* we unref(mime) later on, we just leak on error */ + } + path.SetTo(TEMP_FILENAME_PREFIX); - path.Append(filename); + path.Append(filename.String()); BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE); err = file.InitCheck(); if (err < B_OK) { @@ -858,7 +873,7 @@ void nsbeos_gui_view_source(struct hlcache_handle *content) beos_warn_user("IOError", strerror(err)); return; } - lwc_string *mime = content_get_mime_type(content); + if (mime) { file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0LL, lwc_string_data(mime), lwc_string_length(mime) + 1); -- cgit v1.2.3