desktop/source/lib/init.cxx |   29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

New commits:
commit 8866b5f54a1b60a0cbc1c31b2a55528cda00b11d
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 19:54:51 2025 +0000

    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 84fe5f3e32f2..39966d11743a 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -95,6 +95,7 @@
 #include <com/sun/star/document/MacroExecMode.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/container/XNameAccess.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>
@@ -7732,6 +7733,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()
 {
@@ -7909,6 +7935,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);
 

Reply via email to