summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-10-28 14:54:52 +0100
committerAndras Timar <andras.timar@collabora.com>2020-10-30 12:28:34 +0100
commitae1f51b4888a3aa14837ac6e4083f33b2176ca45 (patch)
tree6c73c8edc49b8127049ded71f43a5ac8239d5a2b /tools
parent8d2f2e313e62993baadf899c0a9771292e32dc72 (diff)
tdf#123476 filter: try to detect 0-byte files based on extension
A 0-byte ("empty") pptx file is obviously junk input, so it's not surprising if the catch-all generic_Text filter is chosen to open it in Writer at the end. But we can do better: if we really get an empty file URL with an extension we can recognize, that we can fake the filter type / filter name, so the empty "presentation" opens in Impress, and also a re-save works as expected. This builds on top of commit 8a201be240b6d408d15166be7ffc576b9e123634 (fdo#68903 Import .tsv and .xls plain text files in Calc by default, 2013-10-27), just the new way works for all supported file extensions and also with filters which would not handle empty input (e.g. pptx refuses the import if the ZIP storage is broken). Change-Id: Ie01650a5eb6ca42c35e090133965467b621bb526 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104939 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105038 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/source/stream/stream.cxx20
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index c10dad0457fa..3a6c6417815f 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -35,6 +35,7 @@
#include <sal/log.hxx>
#include <comphelper/fileformat.h>
+#include <comphelper/fileurl.hxx>
static void swapNibbles(unsigned char &c)
{
@@ -1414,6 +1415,25 @@ bool checkSeek(SvStream &rSt, sal_uInt64 nOffset)
return (nOffset <= nMaxSeek && rSt.Seek(nOffset) == nOffset);
}
+namespace tools
+{
+bool isEmptyFileUrl(const OUString& rUrl)
+{
+ if (!comphelper::isFileUrl(rUrl))
+ {
+ return false;
+ }
+
+ SvFileStream aStream(rUrl, StreamMode::READ);
+ if (!aStream.IsOpen())
+ {
+ return false;
+ }
+
+ return aStream.remainingSize() == 0;
+}
+}
+
//STREAM_SEEK_TO_END in some of the Seek backends is special cased to be
//efficient, in others e.g. SotStorageStream it's really horribly slow, and in
//those this should be overridden