desktop/source/lib/init.cxx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
New commits: commit f1f423e739c3a1e1426d6649fed2b0db56ea1d6b Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Thu Feb 20 08:39:54 2025 +0000 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Sat Feb 22 20:53:18 2025 +0100 preload typedetection to share it with children. Change-Id: Ia212dbf44899932880180185977e74cfbfac34c3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182010 Reviewed-by: Michael Meeks <michael.me...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index a86a99176164..9b3de8876ca3 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -101,6 +101,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/document/XDocumentLanguages.hpp> +#include <com/sun/star/document/XTypeDetection.hpp> #include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/frame/DispatchResultEvent.hpp> #include <com/sun/star/frame/DispatchResultState.hpp> @@ -7757,6 +7758,31 @@ static void preLoadShortCutAccelerators() batch->commit(); } +static void preLoadTypeDetection() +{ + uno::Reference<document::XTypeDetection> xTypeDetection( + xFactory->createInstanceWithContext(u"com.sun.star.document.TypeDetection"_ustr, xContext), + uno::UNO_QUERY); + if (xTypeDetection) + { + SvMemoryStream aMemory; + // just enough to check zip based type detection + const sal_uInt8 aMinimalZip[30] = { 0x50, 0x4b, 0x03, 0x04, + 0x14, 0x00, 0x00, 0x08 }; + aMemory.WriteBytes(aMinimalZip, std::size(aMinimalZip)); + uno::Reference<io::XStream> xInputStream = new utl::OStreamWrapper(aMemory); + + uno::Sequence<beans::PropertyValue> aMediaDesc(2); + auto pArgs = aMediaDesc.getArray(); + pArgs[0].Name = "URL"; + pArgs[0].Value <<= OUString("private:stream"); + pArgs[1].Name = "InputStream"; + pArgs[1].Value <<= xInputStream; + + xTypeDetection->queryTypeByDescriptor(aMediaDesc, true); + } +} + /// Used only by LibreOfficeKit when used by Online to pre-initialize static void preloadData() { @@ -7942,6 +7968,9 @@ static void preloadData() xComp->dispose(); } + // Preload typedetection + preLoadTypeDetection(); + // Set user profile's path back to the original one rtl::Bootstrap::set(u"UserInstallation"_ustr, sUserPath);