summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compilerplugins/clang/mergeclasses.results1
-rw-r--r--include/svx/gallery1.hxx4
-rw-r--r--include/svx/galtheme.hxx6
-rw-r--r--svx/Library_svxcore.mk1
-rw-r--r--svx/inc/gallerybinaryengine.hxx109
-rw-r--r--svx/inc/galleryfilestorage.hxx85
-rw-r--r--svx/inc/galleryfilestorageentry.hxx5
-rw-r--r--svx/inc/galobj.hxx2
-rw-r--r--svx/source/gallery2/gallery1.cxx2
-rw-r--r--svx/source/gallery2/gallerybinaryengine.cxx811
-rw-r--r--svx/source/gallery2/galleryfilestorage.cxx789
-rw-r--r--svx/source/gallery2/galleryfilestorageentry.cxx6
-rw-r--r--svx/source/gallery2/galtheme.cxx4
-rw-r--r--svx/source/unogallery/unogalitem.cxx2
14 files changed, 886 insertions, 941 deletions
diff --git a/compilerplugins/clang/mergeclasses.results b/compilerplugins/clang/mergeclasses.results
index a1e8c6be6e3d..9d4e9d583926 100644
--- a/compilerplugins/clang/mergeclasses.results
+++ b/compilerplugins/clang/mergeclasses.results
@@ -54,7 +54,6 @@ merge FmRecordCountListener_Base with FmRecordCountListener
merge FmXDisposeListener with DisposeListenerGridBridge
merge FmXFormShell_Base_Disambiguation with FmXFormShell
merge GLWindow with GLX11Window
-merge GalleryFileStorage with GalleryBinaryEngine
merge GroupTable with PPTWriterBase
merge HostDetailsContainer with DavDetailsContainer
merge IDocumentChartDataProviderAccess with sw::DocumentChartDataProviderManager
diff --git a/include/svx/gallery1.hxx b/include/svx/gallery1.hxx
index 49427be4d723..6f159e3b5139 100644
--- a/include/svx/gallery1.hxx
+++ b/include/svx/gallery1.hxx
@@ -30,7 +30,7 @@
#include <vector>
class Gallery;
-class GalleryBinaryEngine;
+class GalleryFileStorage;
class GalleryFileStorageEntry;
class GalleryObjectCollection;
class GalleryStorageLocations;
@@ -61,7 +61,7 @@ public:
GalleryTheme* createGalleryTheme(Gallery* pGallery);
- std::unique_ptr<GalleryBinaryEngine> createGalleryStorageEngine(GalleryObjectCollection& mrGalleryObjectCollection);
+ std::unique_ptr<GalleryFileStorage> createGalleryStorageEngine(GalleryObjectCollection& mrGalleryObjectCollection);
const OUString& GetThemeName() const { return aName; }
diff --git a/include/svx/galtheme.hxx b/include/svx/galtheme.hxx
index e3ef7f7d991f..e14372066f51 100644
--- a/include/svx/galtheme.hxx
+++ b/include/svx/galtheme.hxx
@@ -31,7 +31,7 @@
#include <svx/galmisc.hxx>
#include <memory>
-class GalleryBinaryEngine;
+class GalleryFileStorage;
class GalleryThemeEntry;
class SgaObject;
class SotStorageStream;
@@ -57,7 +57,7 @@ class SVXCORE_DLLPUBLIC GalleryTheme final : public SfxBroadcaster
private:
- std::unique_ptr<GalleryBinaryEngine> mpGalleryStorageEngine;
+ std::unique_ptr<GalleryFileStorage> mpGalleryStorageEngine;
GalleryObjectCollection maGalleryObjectCollection;
Gallery* pParent;
GalleryThemeEntry* pThm;
@@ -67,7 +67,7 @@ private:
bool bDragging;
bool bAbortActualize;
- const std::unique_ptr<GalleryBinaryEngine>& getGalleryStorageEngine() const { return mpGalleryStorageEngine; }
+ const std::unique_ptr<GalleryFileStorage>& getGalleryStorageEngine() const { return mpGalleryStorageEngine; }
SAL_DLLPRIVATE void ImplSetModified( bool bModified );
SAL_DLLPRIVATE void ImplBroadcast(sal_uInt32 nUpdatePos);
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 8dd99ef5484b..b0ce4a15165f 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -204,7 +204,6 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
svx/source/gallery2/galobj \
svx/source/gallery2/galtheme \
svx/source/gallery2/GalleryControl \
- svx/source/gallery2/gallerybinaryengine \
svx/source/gallery2/galleryobjectcollection \
svx/source/gallery2/galleryfilestorage \
svx/source/gallery2/galleryfilestorageentry \
diff --git a/svx/inc/gallerybinaryengine.hxx b/svx/inc/gallerybinaryengine.hxx
deleted file mode 100644
index f1f221e34447..000000000000
--- a/svx/inc/gallerybinaryengine.hxx
+++ /dev/null
@@ -1,109 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#pragma once
-
-#include <svx/galmisc.hxx>
-#include <svx/svxdllapi.h>
-#include <svx/fmmodel.hxx>
-#include "gallerystoragelocations.hxx"
-#include "galleryfilestorage.hxx"
-#include <tools/urlobj.hxx>
-#include <sot/storage.hxx>
-#include <vcl/salctype.hxx>
-
-#include <tools/datetime.hxx>
-
-#include <memory>
-
-class GalleryObjectCollection;
-class SgaObjectSvDraw;
-class SgaObjectBmp;
-class SgaObject;
-class SotStorage;
-struct GalleryObject;
-class FmFormModel;
-class GalleryTheme;
-class GalleryThemeEntry;
-
-class SVXCORE_DLLPUBLIC GalleryBinaryEngine final : public GalleryFileStorage
-{
-private:
- tools::SvRef<SotStorage> m_aSvDrawStorageRef;
- const GalleryStorageLocations& maGalleryStorageLocations;
- GalleryObjectCollection& mrGalleryObjectCollection;
- bool mbReadOnly;
- OUString m_aDestDir;
- bool m_bDestDirRelative;
-
- const INetURLObject& GetSdgURL() const { return maGalleryStorageLocations.GetSdgURL(); }
- const INetURLObject& GetSdvURL() const { return maGalleryStorageLocations.GetSdvURL(); }
- const INetURLObject& GetStrURL() const { return maGalleryStorageLocations.GetStrURL(); }
- const INetURLObject& GetThmURL() const { return maGalleryStorageLocations.GetThmURL(); }
-
-public:
- GalleryBinaryEngine(const GalleryStorageLocations& rGalleryStorageLocations,
- GalleryObjectCollection& rGalleryObjectCollection, bool bReadOnly);
- SAL_DLLPRIVATE ~GalleryBinaryEngine();
-
- void clearSotStorage();
-
- void setDestDir(const OUString& rDestDir, bool bRelative);
-
- SAL_DLLPRIVATE void ImplCreateSvDrawStorage();
- SAL_DLLPRIVATE const tools::SvRef<SotStorage>& GetSvDrawStorage() const;
-
- const INetURLObject& getThemeURL() const { return maGalleryStorageLocations.getThemeURL(); }
-
- SAL_DLLPRIVATE bool implWrite(const GalleryTheme& rTheme, const GalleryThemeEntry* pThm);
-
- void insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry, sal_uInt32 nInsertPos);
- void removeObject(const std::unique_ptr<GalleryObject>& pEntry);
-
- std::unique_ptr<SgaObject> implReadSgaObject(GalleryObject const* pEntry);
- bool implWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, GalleryObject* pExistentEntry);
-
- bool readModel(const GalleryObject* pObject, SdrModel& rModel);
- SgaObjectSvDraw insertModel(const FmFormModel& rModel, const INetURLObject& rUserURL);
-
- bool readModelStream(const GalleryObject* pObject,
- tools::SvRef<SotTempStream> const& rxModelStream);
- SgaObjectSvDraw insertModelStream(const tools::SvRef<SotTempStream>& rxModelStream,
- const INetURLObject& rUserURL);
-
- INetURLObject implCreateUniqueURL(SgaObjKind eObjKind, const INetURLObject& rUserURL,
- ConvertDataFormat nFormat = ConvertDataFormat::Unknown);
-
- SgaObjectBmp insertGraphic(const Graphic& rGraphic, const GfxLink& aGfxLink,
- const ConvertDataFormat& nExportFormat,
- const INetURLObject& rUserURL);
-
- SgaObjectSvDraw updateSvDrawObject(const GalleryObject* pEntry);
-
- void updateTheme();
- static void insertFileOrDirURL(const INetURLObject& rFileOrDirURL,
- std::vector<INetURLObject>& rURLVector);
-
- SvStream& writeGalleryTheme(SvStream& rOStm, const GalleryTheme& rTheme,
- const GalleryThemeEntry* pThm);
-
- DateTime getModificationDate() const;
-};
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/inc/galleryfilestorage.hxx b/svx/inc/galleryfilestorage.hxx
index fee632e9b397..df3aecad7c80 100644
--- a/svx/inc/galleryfilestorage.hxx
+++ b/svx/inc/galleryfilestorage.hxx
@@ -19,10 +19,91 @@
#pragma once
-class GalleryFileStorage
+#include <svx/galmisc.hxx>
+#include <svx/svxdllapi.h>
+#include <svx/fmmodel.hxx>
+#include "gallerystoragelocations.hxx"
+#include "galleryfilestorage.hxx"
+#include <tools/urlobj.hxx>
+#include <sot/storage.hxx>
+#include <vcl/salctype.hxx>
+
+#include <tools/datetime.hxx>
+
+#include <memory>
+
+class GalleryObjectCollection;
+class SgaObjectSvDraw;
+class SgaObjectBmp;
+class SgaObject;
+class SotStorage;
+struct GalleryObject;
+class FmFormModel;
+class GalleryTheme;
+class GalleryThemeEntry;
+
+class SVXCORE_DLLPUBLIC GalleryFileStorage final
{
+private:
+ tools::SvRef<SotStorage> m_aSvDrawStorageRef;
+ const GalleryStorageLocations& maGalleryStorageLocations;
+ GalleryObjectCollection& mrGalleryObjectCollection;
+ bool mbReadOnly;
+ OUString m_aDestDir;
+ bool m_bDestDirRelative;
+
+ const INetURLObject& GetSdgURL() const { return maGalleryStorageLocations.GetSdgURL(); }
+ const INetURLObject& GetSdvURL() const { return maGalleryStorageLocations.GetSdvURL(); }
+ const INetURLObject& GetStrURL() const { return maGalleryStorageLocations.GetStrURL(); }
+ const INetURLObject& GetThmURL() const { return maGalleryStorageLocations.GetThmURL(); }
+
public:
- virtual ~GalleryFileStorage() = 0;
+ GalleryFileStorage(const GalleryStorageLocations& rGalleryStorageLocations,
+ GalleryObjectCollection& rGalleryObjectCollection, bool bReadOnly);
+ SAL_DLLPRIVATE ~GalleryFileStorage();
+
+ void clearSotStorage();
+
+ void setDestDir(const OUString& rDestDir, bool bRelative);
+
+ SAL_DLLPRIVATE void ImplCreateSvDrawStorage();
+ SAL_DLLPRIVATE const tools::SvRef<SotStorage>& GetSvDrawStorage() const;
+
+ const INetURLObject& getThemeURL() const { return maGalleryStorageLocations.getThemeURL(); }
+
+ SAL_DLLPRIVATE bool implWrite(const GalleryTheme& rTheme, const GalleryThemeEntry* pThm);
+
+ void insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry, sal_uInt32 nInsertPos);
+ void removeObject(const std::unique_ptr<GalleryObject>& pEntry);
+
+ std::unique_ptr<SgaObject> implReadSgaObject(GalleryObject const* pEntry);
+ bool implWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, GalleryObject* pExistentEntry);
+
+ bool readModel(const GalleryObject* pObject, SdrModel& rModel);
+ SgaObjectSvDraw insertModel(const FmFormModel& rModel, const INetURLObject& rUserURL);
+
+ bool readModelStream(const GalleryObject* pObject,
+ tools::SvRef<SotTempStream> const& rxModelStream);
+ SgaObjectSvDraw insertModelStream(const tools::SvRef<SotTempStream>& rxModelStream,
+ const INetURLObject& rUserURL);
+
+ INetURLObject implCreateUniqueURL(SgaObjKind eObjKind, const INetURLObject& rUserURL,
+ ConvertDataFormat nFormat = ConvertDataFormat::Unknown);
+
+ SgaObjectBmp insertGraphic(const Graphic& rGraphic, const GfxLink& aGfxLink,
+ const ConvertDataFormat& nExportFormat,
+ const INetURLObject& rUserURL);
+
+ SgaObjectSvDraw updateSvDrawObject(const GalleryObject* pEntry);
+
+ void updateTheme();
+ static void insertFileOrDirURL(const INetURLObject& rFileOrDirURL,
+ std::vector<INetURLObject>& rURLVector);
+
+ SvStream& writeGalleryTheme(SvStream& rOStm, const GalleryTheme& rTheme,
+ const GalleryThemeEntry* pThm);
+
+ DateTime getModificationDate() const;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/inc/galleryfilestorageentry.hxx b/svx/inc/galleryfilestorageentry.hxx
index 15f3a2f6faa4..66762fa82241 100644
--- a/svx/inc/galleryfilestorageentry.hxx
+++ b/svx/inc/galleryfilestorageentry.hxx
@@ -21,12 +21,11 @@
#include <tools/urlobj.hxx>
#include <svx/galtheme.hxx>
-#include "gallerybinaryengine.hxx"
+#include "galleryfilestorage.hxx"
#include "gallerystoragelocations.hxx"
#include "galleryfilestorageentry.hxx"
class GalleryObjectCollection;
-class GalleryBinaryEngine;
class GalleryFileStorageEntry final
{
@@ -57,7 +56,7 @@ public:
void setStorageLocations(INetURLObject& rURL);
- std::unique_ptr<GalleryBinaryEngine>
+ std::unique_ptr<GalleryFileStorage>
createGalleryStorageEngine(GalleryObjectCollection& mrGalleryObjectCollection, bool& bReadOnly);
};
diff --git a/svx/inc/galobj.hxx b/svx/inc/galobj.hxx
index 29c053baa114..df2b5ec36896 100644
--- a/svx/inc/galobj.hxx
+++ b/svx/inc/galobj.hxx
@@ -44,7 +44,7 @@ enum GalSoundType
class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) SgaObject
{
friend class GalleryTheme;
- friend class GalleryBinaryEngine;
+ friend class GalleryFileStorage;
private:
diff --git a/svx/source/gallery2/gallery1.cxx b/svx/source/gallery2/gallery1.cxx
index fbdf46acd6fd..8dad889b6a8c 100644
--- a/svx/source/gallery2/gallery1.cxx
+++ b/svx/source/gallery2/gallery1.cxx
@@ -176,7 +176,7 @@ GalleryTheme* GalleryThemeEntry::createGalleryTheme(Gallery* pGallery)
return new GalleryTheme(pGallery,this);
}
-std::unique_ptr<GalleryBinaryEngine> GalleryThemeEntry::createGalleryStorageEngine(GalleryObjectCollection& mrGalleryObjectCollection)
+std::unique_ptr<GalleryFileStorage> GalleryThemeEntry::createGalleryStorageEngine(GalleryObjectCollection& mrGalleryObjectCollection)
{
return mpGalleryStorageEngineEntry->createGalleryStorageEngine(mrGalleryObjectCollection, bReadOnly);
}
diff --git a/svx/source/gallery2/gallerybinaryengine.cxx b/svx/source/gallery2/gallerybinaryengine.cxx
deleted file mode 100644
index 009fe113f210..000000000000
--- a/svx/source/gallery2/gallerybinaryengine.cxx
+++ /dev/null
@@ -1,811 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <svx/unomodel.hxx>
-#include <svx/fmmodel.hxx>
-#include <svx/galtheme.hxx>
-#include <galobj.hxx>
-#include <gallerybinaryengine.hxx>
-#include <svx/galleryobjectcollection.hxx>
-#include <svx/gallery1.hxx>
-#include <osl/thread.hxx>
-#include "codec.hxx"
-#include "gallerydrawmodel.hxx"
-#include <vcl/cvtgrf.hxx>
-#include <vcl/filter/SvmWriter.hxx>
-
-#include <sal/log.hxx>
-
-#include <com/sun/star/ucb/ContentCreationException.hpp>
-#include <com/sun/star/sdbc/XResultSet.hpp>
-#include <com/sun/star/ucb/XContentAccess.hpp>
-#include <comphelper/fileformat.h>
-#include <comphelper/graphicmimetype.hxx>
-#include <comphelper/processfactory.hxx>
-#include <tools/urlobj.hxx>
-#include <comphelper/diagnose_ex.hxx>
-#include <tools/datetime.hxx>
-#include <unotools/datetime.hxx>
-#include <unotools/ucbstreamhelper.hxx>
-#include <unotools/streamwrap.hxx>
-#include <unotools/tempfile.hxx>
-#include <ucbhelper/content.hxx>
-#include <tools/vcompat.hxx>
-
-using namespace ::com::sun::star;
-
-GalleryBinaryEngine::GalleryBinaryEngine(
- const GalleryStorageLocations& rGalleryBinaryStorageLocations,
- GalleryObjectCollection& rGalleryObjectCollection, bool bReadOnly)
- : maGalleryStorageLocations(rGalleryBinaryStorageLocations)
- , mrGalleryObjectCollection(rGalleryObjectCollection)
- , mbReadOnly(bReadOnly)
- , m_bDestDirRelative(false)
-{
- ImplCreateSvDrawStorage();
-}
-
-GalleryBinaryEngine::~GalleryBinaryEngine() { clearSotStorage(); }
-
-void GalleryBinaryEngine::setDestDir(const OUString& rDestDir, bool bRelative)
-{
- m_aDestDir = rDestDir;
- m_bDestDirRelative = bRelative;
-}
-
-void GalleryBinaryEngine::clearSotStorage() { m_aSvDrawStorageRef.clear(); }
-
-void GalleryBinaryEngine::ImplCreateSvDrawStorage()
-{
- try
- {
- m_aSvDrawStorageRef
- = new SotStorage(false, GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
- mbReadOnly ? StreamMode::READ : StreamMode::STD_READWRITE);
- // #i50423# ReadOnly may not been set though the file can't be written (because of security reasons)
- if ((m_aSvDrawStorageRef->GetError() != ERRCODE_NONE) && !mbReadOnly)
- m_aSvDrawStorageRef = new SotStorage(
- false, GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
- StreamMode::READ);
- }
- catch (const css::ucb::ContentCreationException&)
- {
- TOOLS_WARN_EXCEPTION("svx", "failed to open: " << GetSdvURL().GetMainURL(
- INetURLObject::DecodeMechanism::NONE)
- << "due to");
- }
-}
-
-const tools::SvRef<SotStorage>& GalleryBinaryEngine::GetSvDrawStorage() const
-{
- return m_aSvDrawStorageRef;
-}
-
-bool GalleryBinaryEngine::implWrite(const GalleryTheme& rTheme, const GalleryThemeEntry* pThm)
-{
- INetURLObject aPathURL(GetThmURL());
-
- aPathURL.removeSegment();
- aPathURL.removeFinalSlash();
-
- DBG_ASSERT(aPathURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
-
- if (FileExists(aPathURL) || CreateDir(aPathURL))
- {
-#ifdef UNX
- std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
- GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
- StreamMode::WRITE | StreamMode::COPY_ON_SYMLINK | StreamMode::TRUNC));
-#else
- std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
- GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
- StreamMode::WRITE | StreamMode::TRUNC));
-#endif
-
- if (pOStm)
- {
- writeGalleryTheme(*pOStm, rTheme, pThm);
- pOStm.reset();
- return true;
- }
-
- return false;
- }
- return true;
-}
-
-void GalleryBinaryEngine::insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry,
- sal_uInt32 nInsertPos)
-{
- if (pFoundEntry)
- {
- GalleryObject aNewEntry;
-
- // update title of new object if necessary
- if (rObj.GetTitle().isEmpty())
- {
- std::unique_ptr<SgaObject> pOldObj(implReadSgaObject(pFoundEntry));
-
- if (pOldObj)
- {
- const_cast<SgaObject&>(rObj).SetTitle(pOldObj->GetTitle());
- }
- }
- else if (rObj.GetTitle() == "__<empty>__")
- const_cast<SgaObject&>(rObj).SetTitle("");
-
- implWriteSgaObject(rObj, nInsertPos, &aNewEntry);
- pFoundEntry->nOffset = aNewEntry.nOffset;
- }
- else
- implWriteSgaObject(rObj, nInsertPos, nullptr);
-}
-
-void GalleryBinaryEngine::removeObject(const std::unique_ptr<GalleryObject>& pEntry)
-{
- if (mrGalleryObjectCollection.getObjectList().empty())
- KillFile(GetSdgURL());
-
- if (SgaObjKind::SvDraw == pEntry->eObjKind)
- GetSvDrawStorage()->Remove(
- pEntry->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE));
-}
-
-std::unique_ptr<SgaObject> GalleryBinaryEngine::implReadSgaObject(GalleryObject const* pEntry)
-{
- std::unique_ptr<SgaObject> pSgaObj;
-
- if (pEntry)
- {
- std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
- GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
-
- if (pIStm)
- {
- sal_uInt32 nInventor;
-
- // Check to ensure that the file is a valid SGA file
- pIStm->Seek(pEntry->nOffset);
- pIStm->ReadUInt32(nInventor);
-
- if (nInventor == COMPAT_FORMAT('S', 'G', 'A', '3'))
- {
- pIStm->Seek(pEntry->nOffset);
-
- switch (pEntry->eObjKind)
- {
- case SgaObjKind::Bitmap:
- pSgaObj.reset(new SgaObjectBmp());
- break;
- case SgaObjKind::Animation:
- pSgaObj.reset(new SgaObjectAnim());
- break;
- case SgaObjKind::Inet:
- pSgaObj.reset(new SgaObjectINet());
- break;
- case SgaObjKind::SvDraw:
- pSgaObj.reset(new SgaObjectSvDraw());
- break;
- case SgaObjKind::Sound:
- pSgaObj.reset(new SgaObjectSound());
- break;
-
- default:
- break;
- }
-
- if (pSgaObj)
- {
- ReadSgaObject(*pIStm, *pSgaObj);
- pSgaObj->ImplUpdateURL(*pEntry->m_oStorageUrl);
- }
- }
- }
- }
-
- return pSgaObj;
-}
-
-bool GalleryBinaryEngine::implWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos,
- GalleryObject* pExistentEntry)
-{
- std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
- GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE));
- bool bRet = false;
-
- if (pOStm)
- {
- const sal_uInt32 nOffset = pOStm->Seek(STREAM_SEEK_TO_END);
-
- rObj.WriteData(*pOStm, m_aDestDir);
-
- if (!pOStm->GetError())
- {
- GalleryObject* pEntry;
-
- if (!pExistentEntry)
- {
- pEntry = new GalleryObject;
- if (nPos < mrGalleryObjectCollection.size())
- {
- mrGalleryObjectCollection.getObjectList().emplace(
- mrGalleryObjectCollection.getObjectList().begin() + nPos, pEntry);
- }
- else
- mrGalleryObjectCollection.getObjectList().emplace_back(pEntry);
- }
- else
- pEntry = pExistentEntry;
-
- pEntry->m_oStorageUrl = rObj.GetURL();
-
- pEntry->nOffset = nOffset;
- pEntry->eObjKind = rObj.GetObjKind();
- bRet = true;
- }
- }
-
- return bRet;
-}
-
-bool GalleryBinaryEngine::readModel(const GalleryObject* pObject, SdrModel& rModel)
-{
- tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage());
- bool bRet = false;
- const INetURLObject aURL(ImplGetURL(pObject));
-
- if (xSotStorage.is())
- {
- const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
- tools::SvRef<SotStorageStream> xInputStream(
- xSotStorage->OpenSotStream(aStreamName, StreamMode::READ));
-
- if (xInputStream.is() && !xInputStream->GetError())
- {
- xInputStream->SetBufferSize(STREAMBUF_SIZE);
- bRet = GallerySvDrawImport(*xInputStream, rModel);
- xInputStream->SetBufferSize(0);
- }
- }
- return bRet;
-}
-
-SgaObjectSvDraw GalleryBinaryEngine::insertModel(const FmFormModel& rModel,
- const INetURLObject& rUserURL)
-{
- INetURLObject aURL(implCreateUniqueURL(SgaObjKind::SvDraw, rUserURL));
- tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage());
- bool bRet = false;
-
- if (xSotStorage.is())
- {
- const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
- tools::SvRef<SotStorageStream> xOutputStream(
- xSotStorage->OpenSotStream(aStreamName, StreamMode::WRITE | StreamMode::TRUNC));
-
- if (xOutputStream.is() && !xOutputStream->GetError())
- {
- SvMemoryStream aMemoryStream(65535, 65535);
- FmFormModel* pFormModel = const_cast<FmFormModel*>(&rModel);
-
- pFormModel->BurnInStyleSheetAttributes();
-
- {
- uno::Reference<io::XOutputStream> xDocOut(
- new utl::OOutputStreamWrapper(aMemoryStream));
-
- if (xDocOut.is())
- (void)SvxDrawingLayerExport(pFormModel, xDocOut);
- }
-
- aMemoryStream.Seek(0);
-
- xOutputStream->SetBufferSize(16348);
- GalleryCodec aCodec(*xOutputStream);
- aCodec.Write(aMemoryStream);
-
- xOutputStream->SetBufferSize(0);
- xOutputStream->Commit();
- bRet = !xOutputStream->GetError();
- }
- }
- if (bRet)
- {
- SgaObjectSvDraw aObjSvDraw(rModel, aURL);
- return aObjSvDraw;
- }
- return SgaObjectSvDraw();
-}
-
-bool GalleryBinaryEngine::readModelStream(const GalleryObject* pObject,
- tools::SvRef<SotTempStream> const& rxModelStream)
-{
- const INetURLObject aURL(ImplGetURL(pObject));
- tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage());
- bool bRet = false;
-
- if (xSotStorage.is())
- {
- const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
- tools::SvRef<SotStorageStream> xInputStream(
- xSotStorage->OpenSotStream(aStreamName, StreamMode::READ));
-
- if (xInputStream.is() && !xInputStream->GetError())
- {
- sal_uInt32 nVersion = 0;
-
- xInputStream->SetBufferSize(16348);
-
- if (GalleryCodec::IsCoded(*xInputStream, nVersion))
- {
- SvxGalleryDrawModel aModel;
-
- if (aModel.GetModel())
- {
- if (GallerySvDrawImport(*xInputStream, *aModel.GetModel()))
- {
- aModel.GetModel()->BurnInStyleSheetAttributes();
-
- {
- uno::Reference<io::XOutputStream> xDocOut(
- new utl::OOutputStreamWrapper(*rxModelStream));
-
- SvxDrawingLayerExport(aModel.GetModel(), xDocOut);
- }
- }
-
- bRet = (rxModelStream->GetError() == ERRCODE_NONE);
- }
- }
-
- xInputStream->SetBufferSize(0);
- }
- }
- return bRet;
-}
-
-SgaObjectSvDraw
-GalleryBinaryEngine::insertModelStream(const tools::SvRef<SotTempStream>& rxModelStream,
- const INetURLObject& rUserURL)
-{
- INetURLObject aURL(implCreateUniqueURL(SgaObjKind::SvDraw, rUserURL));
- tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage());
-
- if (xSotStorage.is())
- {
- const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
- tools::SvRef<SotStorageStream> xOutputStream(
- xSotStorage->OpenSotStream(aStreamName, StreamMode::WRITE | StreamMode::TRUNC));
-
- if (xOutputStream.is() && !xOutputStream->GetError())
- {
- GalleryCodec aCodec(*xOutputStream);
-
- xOutputStream->SetBufferSize(16348);
- aCodec.Write(*rxModelStream);
-
- if (!xOutputStream->GetError())
- {
- xOutputStream->Seek(0);
- SgaObjectSvDraw aObjSvDraw(*xOutputStream, aURL);
- return aObjSvDraw;
- }
- }
- }
- return SgaObjectSvDraw();
-}
-
-INetURLObject GalleryBinaryEngine::implCreateUniqueURL(SgaObjKind eObjKind,
- const INetURLObject& rUserURL,
- ConvertDataFormat nFormat)
-{
- INetURLObject aDir(rUserURL);
- INetURLObject aInfoFileURL(rUserURL);
- INetURLObject aNewURL;
- sal_uInt32 nNextNumber = 1999;
- char const* pExt = nullptr;
- bool bExists;
-
- aDir.Append(u"dragdrop");
- CreateDir(aDir);
-
- aInfoFileURL.Append(u"sdddndx1");
-
- // read next possible number
- if (FileExists(aInfoFileURL))
- {
- std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
- aInfoFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
-
- if (pIStm)
- {
- pIStm->ReadUInt32(nNextNumber);
- }
- }
-
- pExt = comphelper::GraphicMimeTypeHelper::GetExtensionForConvertDataFormat(nFormat);
-
- do
- {
- // get URL
- if (SgaObjKind::SvDraw == eObjKind)
- {
- OUString aFileName = "gallery/svdraw/dd" + OUString::number(++nNextNumber % 99999999);
- aNewURL = INetURLObject(aFileName, INetProtocol::PrivSoffice);
-
- bExists = false;
-
- for (auto const& pObject : mrGalleryObjectCollection.getObjectList())
- {
- if (*pObject->m_oStorageUrl == aNewURL)
- {
- bExists = true;
- break;
- }
- }
- }
- else
- {
- OUString aFileName = "dd" + OUString::number(++nNextNumber % 999999);
-
- if (pExt)
- aFileName += OUString(pExt, strlen(pExt), RTL_TEXTENCODING_ASCII_US);
-
- aNewURL = aDir;
- aNewURL.Append(aFileName);
-
- bExists = FileExists(aNewURL);
- }
- } while (bExists);
-
- // write updated number
- std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
- aInfoFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE));
-
- if (pOStm)
- {
- pOStm->WriteUInt32(nNextNumber);
- }
-
- return aNewURL;
-}
-
-SgaObjectBmp GalleryBinaryEngine::insertGraphic(const Graphic& rGraphic, const GfxLink& aGfxLink,
- const ConvertDataFormat& nExportFormat,
- const INetURLObject& rUserURL)
-{
- const INetURLObject aURL(implCreateUniqueURL(SgaObjKind::Bitmap, rUserURL, nExportFormat));
- std::unique_ptr<SvStream> pOStm(
- ::utl::UcbStreamHelper::CreateStream(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
- StreamMode::WRITE | StreamMode::TRUNC));
- bool bRet = false;
-
- if (pOStm)
- {
- pOStm->SetVersion(SOFFICE_FILEFORMAT_50);
-
- if (ConvertDataFormat::SVM == nExportFormat)
- {
- GDIMetaFile aMtf(rGraphic.GetGDIMetaFile());
-
- SvmWriter aWriter(*pOStm);
- aWriter.Write(aMtf);
- bRet = (pOStm->GetError() == ERRCODE_NONE);
- }
- else
- {
- if (aGfxLink.GetDataSize() && aGfxLink.GetData())
- {
- pOStm->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize());
- bRet = (pOStm->GetError() == ERRCODE_NONE);
- }
- else
- bRet = (GraphicConverter::Export(*pOStm, rGraphic, nExportFormat) == ERRCODE_NONE);
- }
-
- pOStm.reset();
- }
- if (bRet)
- {
- const SgaObjectBmp aObjBmp(aURL);
- return aObjBmp;
- }
- return SgaObjectBmp();
-}
-
-SgaObjectSvDraw GalleryBinaryEngine::updateSvDrawObject(const GalleryObject* pEntry)
-{
- if (GetSvDrawStorage().is())
- {
- const OUString aStmName(GetSvDrawStreamNameFromURL(*pEntry->m_oStorageUrl));
- tools::SvRef<SotStorageStream> pIStm
- = GetSvDrawStorage()->OpenSotStream(aStmName, StreamMode::READ);
-
- if (pIStm.is() && !pIStm->GetError())
- {
- pIStm->SetBufferSize(16384);
-
- SgaObjectSvDraw aNewObj(*pIStm, *pEntry->m_oStorageUrl);
-
- pIStm->SetBufferSize(0);
-
- return aNewObj;
- }
- }
- return SgaObjectSvDraw();
-}
-
-void GalleryBinaryEngine::updateTheme()
-{
- ::utl::TempFileNamed aTmp;
- INetURLObject aInURL(GetSdgURL());
- INetURLObject aTmpURL(aTmp.GetURL());
-
- DBG_ASSERT(aInURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
- DBG_ASSERT(aTmpURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
-
- std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
- aInURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
- std::unique_ptr<SvStream> pTmpStm(::utl::UcbStreamHelper::CreateStream(
- aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
- StreamMode::WRITE | StreamMode::TRUNC));
-
- if (pIStm && pTmpStm)
- {
- for (const auto& i : mrGalleryObjectCollection.getObjectList())
- {
- GalleryObject* pEntry = i.get();
- std::unique_ptr<SgaObject> pObj;
-
- switch (pEntry->eObjKind)
- {
- case SgaObjKind::Bitmap:
- pObj.reset(new SgaObjectBmp());
- break;
- case SgaObjKind::Animation:
- pObj.reset(new SgaObjectAnim());
- break;
- case SgaObjKind::Inet:
- pObj.reset(new SgaObjectINet());
- break;
- case SgaObjKind::SvDraw:
- pObj.reset(new SgaObjectSvDraw());
- break;
- case SgaObjKind::Sound:
- pObj.reset(new SgaObjectSound());
- break;
-
- default:
- break;
- }
-
- if (pObj)
- {
- pIStm->Seek(pEntry->nOffset);
- ReadSgaObject(*pIStm, *pObj);
- pEntry->nOffset = pTmpStm->Tell();
- WriteSgaObject(*pTmpStm, *pObj);
- }
- }
- }
- else
- {
- OSL_FAIL("File(s) could not be opened");
- }
-
- pIStm.reset();
- pTmpStm.reset();
-
- CopyFile(aTmpURL, aInURL);
- KillFile(aTmpURL);
-
- ErrCode nStorErr = ERRCODE_NONE;
-
- try
- {
- tools::SvRef<SotStorage> aTempStorageRef(
- new SotStorage(false, aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
- StreamMode::STD_READWRITE));
- GetSvDrawStorage()->CopyTo(aTempStorageRef.get());
- nStorErr = GetSvDrawStorage()->GetError();
- }
- catch (const css::ucb::ContentCreationException&)
- {
- TOOLS_WARN_EXCEPTION("svx", "failed to open: "
- << aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)
- << "due to");
- nStorErr = ERRCODE_IO_GENERAL;
- }
-
- if (nStorErr == ERRCODE_NONE)
- {
- clearSotStorage();
- CopyFile(aTmpURL, GetSdvURL());
- ImplCreateSvDrawStorage();
- }
-
- KillFile(aTmpURL);
-}
-
-void GalleryBinaryEngine::insertFileOrDirURL(const INetURLObject& rFileOrDirURL,
- std::vector<INetURLObject>& rURLVector)
-{
- INetURLObject aURL;
- try
- {
- ::ucbhelper::Content aCnt(rFileOrDirURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
- uno::Reference<ucb::XCommandEnvironment>(),
- comphelper::getProcessComponentContext());
- bool bFolder = false;
-
- aCnt.getPropertyValue("IsFolder") >>= bFolder;
-
- if (bFolder)
- {
- uno::Sequence<OUString> aProps{ "Url" };
- uno::Reference<sdbc::XResultSet> xResultSet(
- aCnt.createCursor(aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY));
- uno::Reference<ucb::XContentAccess> xContentAccess(xResultSet, uno::UNO_QUERY);
- if (xContentAccess.is())
- {
- while (xResultSet->next())
- {
- aURL.SetSmartURL(xContentAccess->queryContentIdentifierString());
- rURLVector.push_back(aURL);
- }
- }
- }
- else
- rURLVector.push_back(rFileOrDirURL);
- }
- catch (const ucb::ContentCreationException&)
- {
- }
- catch (const uno::RuntimeException&)
- {
- }
- catch (const uno::Exception&)
- {
- }
-}
-
-SvStream& GalleryBinaryEngine::writeGalleryTheme(SvStream& rOStm, const GalleryTheme& rTheme,
- const GalleryThemeEntry* pThm)
-{
- const INetURLObject rRelURL1 = rTheme.GetParent()->GetRelativeURL();
- const INetURLObject rRelURL2 = rTheme.GetParent()->GetUserURL();
- const sal_uInt32 rId = rTheme.GetId();
- sal_uInt32 nCount = mrGalleryObjectCollection.size();
- bool bRel;
-
- rOStm.WriteUInt16(0x0004);
- write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, pThm->GetThemeName(),
- RTL_TEXTENCODING_UTF8);
- rOStm.WriteUInt32(nCount).WriteUInt16(osl_getThreadTextEncoding());
-
- for (sal_uInt32 i = 0; i < nCount; i++)
- {
- const GalleryObject* pObj = mrGalleryObjectCollection.getForPosition(i);
- OUString aPath;
-
- if (SgaObjKind::SvDraw == pObj->eObjKind)
- {
- aPath = GetSvDrawStreamNameFromURL(*pObj->m_oStorageUrl);
- bRel = false;
- }
- else
- {
- aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
- aPath = aPath.copy(
- 0, std::min(rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
- aPath.getLength()));
- bRel = aPath == rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE);
-
- if (bRel
- && (pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE)
- .getLength()
- > (rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength() + 1)))
- {
- aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
- aPath = aPath.copy(
- std::min(rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
- aPath.getLength()));
- }
- else
- {
- aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
- aPath = aPath.copy(
- 0,
- std::min(rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
- aPath.getLength()));
- bRel = aPath == rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE);
-
- if (bRel
- && (pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE)
- .getLength()
- > (rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength()
- + 1)))
- {
- aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
- aPath = aPath.copy(std::min(
- rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
- aPath.getLength()));
- }
- else
- aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
- }
- }
-
- if (!m_aDestDir.isEmpty())
- {
- bool aFound = aPath.indexOf(m_aDestDir) != -1;
- aPath = aPath.replaceFirst(m_aDestDir, "");
- if (aFound)
- bRel = m_bDestDirRelative;
- else
- SAL_WARN("svx", "failed to replace destdir of '" << m_aDestDir << "' in '" << aPath
- << "'");
- }
-
- rOStm.WriteBool(bRel);
- write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aPath, RTL_TEXTENCODING_UTF8);
- rOStm.WriteUInt32(pObj->nOffset).WriteUInt16(static_cast<sal_uInt16>(pObj->eObjKind));
- }
-
- // more recently, a 512-byte reserve buffer is written,
- // to recognize them two sal_uInt32-Ids will be written.
- rOStm.WriteUInt32(COMPAT_FORMAT('G', 'A', 'L', 'R'))
- .WriteUInt32(COMPAT_FORMAT('E', 'S', 'R', 'V'));
-
- const sal_uInt64 nReservePos = rOStm.Tell();
- std::unique_ptr<VersionCompatWrite> pCompat(new VersionCompatWrite(rOStm, 2));
-
- rOStm.WriteUInt32(rId).WriteBool(pThm->IsNameFromResource()); // From version 2 and up
-
- pCompat.reset();
-
- // Fill the rest of the buffer.
- const tools::Long nRest
- = std::max(tools::Long(512 - (rOStm.Tell() - nReservePos)), tools::Long(0));
-
- if (nRest)
- {
- std::unique_ptr<char[]> pReserve(new char[nRest]);
- memset(pReserve.get(), 0, nRest);
- rOStm.WriteBytes(pReserve.get(), nRest);
- }
-
- return rOStm;
-}
-
-DateTime GalleryBinaryEngine::getModificationDate() const
-{
- ::ucbhelper::Content aCnt(GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
- uno::Reference<ucb::XCommandEnvironment>(),
- comphelper::getProcessComponentContext());
- util::DateTime aDateTimeModified;
- DateTime aDateTime(DateTime::EMPTY);
-
- aCnt.getPropertyValue("DateModified") >>= aDateTimeModified;
- ::utl::typeConvert(aDateTimeModified, aDateTime);
-
- return aDateTime;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/gallery2/galleryfilestorage.cxx b/svx/source/gallery2/galleryfilestorage.cxx
index e8ce87ac3ecc..1838520ec60a 100644
--- a/svx/source/gallery2/galleryfilestorage.cxx
+++ b/svx/source/gallery2/galleryfilestorage.cxx
@@ -17,8 +17,795 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <svx/unomodel.hxx>
+#include <svx/fmmodel.hxx>
+#include <svx/galtheme.hxx>
+#include <galobj.hxx>
#include <galleryfilestorage.hxx>
+#include <svx/galleryobjectcollection.hxx>
+#include <svx/gallery1.hxx>
+#include <osl/thread.hxx>
+#include "codec.hxx"
+#include "gallerydrawmodel.hxx"
+#include <vcl/cvtgrf.hxx>
+#include <vcl/filter/SvmWriter.hxx>
-GalleryFileStorage::~GalleryFileStorage(){};
+#include <sal/log.hxx>
+
+#include <com/sun/star/ucb/ContentCreationException.hpp>
+#include <com/sun/star/sdbc/XResultSet.hpp>
+#include <com/sun/star/ucb/XContentAccess.hpp>
+#include <comphelper/fileformat.h>
+#include <comphelper/graphicmimetype.hxx>
+#include <comphelper/processfactory.hxx>
+#include <tools/urlobj.hxx>
+#include <comphelper/diagnose_ex.hxx>
+#include <tools/datetime.hxx>
+#include <unotools/datetime.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <unotools/streamwrap.hxx>
+#include <unotools/tempfile.hxx>
+#include <ucbhelper/content.hxx>
+#include <tools/vcompat.hxx>
+
+using namespace ::com::sun::star;
+
+GalleryFileStorage::GalleryFileStorage(
+ const GalleryStorageLocations& rGalleryBinaryStorageLocations,
+ GalleryObjectCollection& rGalleryObjectCollection, bool bReadOnly)
+ : maGalleryStorageLocations(rGalleryBinaryStorageLocations)
+ , mrGalleryObjectCollection(rGalleryObjectCollection)
+ , mbReadOnly(bReadOnly)
+ , m_bDestDirRelative(false)
+{
+ ImplCreateSvDrawStorage();
+}
+
+GalleryFileStorage::~GalleryFileStorage() { clearSotStorage(); }
+
+void GalleryFileStorage::setDestDir(const OUString& rDestDir, bool bRelative)
+{
+ m_aDestDir = rDestDir;
+ m_bDestDirRelative = bRelative;
+}
+
+void GalleryFileStorage::clearSotStorage() { m_aSvDrawStorageRef.clear(); }
+
+void GalleryFileStorage::ImplCreateSvDrawStorage()
+{
+ try
+ {
+ m_aSvDrawStorageRef
+ = new SotStorage(false, GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
+ mbReadOnly ? StreamMode::READ : StreamMode::STD_READWRITE);
+ // #i50423# ReadOnly may not been set though the file can't be written (because of security reasons)
+ if ((m_aSvDrawStorageRef->GetError() != ERRCODE_NONE) && !mbReadOnly)
+ m_aSvDrawStorageRef = new SotStorage(
+ false, GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
+ StreamMode::READ);
+ }
+ catch (const css::ucb::ContentCreationException&)
+ {
+ TOOLS_WARN_EXCEPTION("svx", "failed to open: " << GetSdvURL().GetMainURL(
+ INetURLObject::DecodeMechanism::NONE)
+ << "due to");
+ }
+}
+
+const tools::SvRef<SotStorage>& GalleryFileStorage::GetSvDrawStorage() const
+{
+ return m_aSvDrawStorageRef;
+}
+
+bool GalleryFileStorage::implWrite(const GalleryTheme& rTheme, const GalleryThemeEntry* pThm)
+{
+ INetURLObject aPathURL(GetThmURL());
+
+ aPathURL.removeSegment();
+ aPathURL.removeFinalSlash();
+
+ DBG_ASSERT(aPathURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
+
+ if (FileExists(aPathURL) || CreateDir(aPathURL))
+ {
+#ifdef UNX
+ std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
+ GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
+ StreamMode::WRITE | StreamMode::COPY_ON_SYMLINK | StreamMode::TRUNC));
+#else
+ std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
+ GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
+ StreamMode::WRITE | StreamMode::TRUNC));
+#endif
+
+ if (pOStm)
+ {
+ writeGalleryTheme(*pOStm, rTheme, pThm);
+ pOStm.reset();
+ return true;
+ }
+
+ return false;
+ }
+ return true;
+}
+
+void GalleryFileStorage::insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry,
+ sal_uInt32 nInsertPos)
+{
+ if (pFoundEntry)
+ {
+ GalleryObject aNewEntry;
+
+ // update title of new object if necessary
+ if (rObj.GetTitle().isEmpty())
+ {
+ std::unique_ptr<SgaObject> pOldObj(implReadSgaObject(pFoundEntry));
+
+ if (pOldObj)
+ {
+ const_cast<SgaObject&>(rObj).SetTitle(pOldObj->GetTitle());
+ }
+ }
+ else if (rObj.GetTitle() == "__<empty>__")
+ const_cast<SgaObject&>(rObj).SetTitle("");
+
+ implWriteSgaObject(rObj, nInsertPos, &aNewEntry);
+ pFoundEntry->nOffset = aNewEntry.nOffset;
+ }
+ else
+ implWriteSgaObject(rObj, nInsertPos, nullptr);
+}
+
+void GalleryFileStorage::removeObject(const std::unique_ptr<GalleryObject>& pEntry)
+{
+ if (mrGalleryObjectCollection.getObjectList().empty())
+ KillFile(GetSdgURL());
+
+ if (SgaObjKind::SvDraw == pEntry->eObjKind)
+ GetSvDrawStorage()->Remove(
+ pEntry->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE));
+}
+
+std::unique_ptr<SgaObject> GalleryFileStorage::implReadSgaObject(GalleryObject const* pEntry)
+{
+ std::unique_ptr<SgaObject> pSgaObj;
+
+ if (pEntry)
+ {
+ std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
+ GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
+
+ if (pIStm)
+ {
+ sal_uInt32 nInventor;
+
+ // Check to ensure that the file is a valid SGA file
+ pIStm->Seek(pEntry->nOffset);
+ pIStm->ReadUInt32(nInventor);
+
+ if (nInventor == COMPAT_FORMAT('S', 'G', 'A', '3'))
+ {
+ pIStm->Seek(pEntry->nOffset);
+
+ switch (pEntry->eObjKind)
+ {
+ case SgaObjKind::Bitmap:
+ pSgaObj.reset(new SgaObjectBmp());
+ break;
+ case SgaObjKind::Animation:
+ pSgaObj.reset(new SgaObjectAnim());
+ break;
+ case SgaObjKind::Inet:
+ pSgaObj.reset(new SgaObjectINet());
+ break;
+ case SgaObjKind::SvDraw:
+ pSgaObj.reset(new SgaObjectSvDraw());
+ break;
+ case SgaObjKind::Sound:
+ pSgaObj.reset(new SgaObjectSound());
+ break;
+
+ default:
+ break;
+ }
+
+ if (pSgaObj)
+ {
+ ReadSgaObject(*pIStm, *pSgaObj);
+ pSgaObj->ImplUpdateURL(*pEntry->m_oStorageUrl);
+ }
+ }
+ }
+ }
+
+ return pSgaObj;
+}
+
+bool GalleryFileStorage::implWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos,
+ GalleryObject* pExistentEntry)
+{
+ std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
+ GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE));
+ bool bRet = false;
+
+ if (pOStm)
+ {
+ const sal_uInt32 nOffset = pOStm->Seek(STREAM_SEEK_TO_END);
+
+ rObj.WriteData(*pOStm, m_aDestDir);
+
+ if (!pOStm->GetError())
+ {
+ GalleryObject* pEntry;
+
+ if (!pExistentEntry)
+ {
+ pEntry = new GalleryObject;
+ if (nPos < mrGalleryObjectCollection.size())
+ {
+ mrGalleryObjectCollection.getObjectList().emplace(
+ mrGalleryObjectCollection.getObjectList().begin() + nPos, pEntry);
+ }
+ else
+ mrGalleryObjectCollection.getObjectList().emplace_back(pEntry);
+ }
+ else
+ pEntry = pExistentEntry;
+
+ pEntry->m_oStorageUrl = rObj.GetURL();
+
+ pEntry->nOffset = nOffset;
+ pEntry->eObjKind = rObj.GetObjKind();
+ bRet = true;
+ }
+ }
+
+ return bRet;
+}
+
+bool GalleryFileStorage::readModel(const GalleryObject* pObject, SdrModel& rModel)
+{
+ tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage());
+ bool bRet = false;
+ const INetURLObject aURL(ImplGetURL(pObject));
+
+ if (xSotStorage.is())
+ {
+ const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
+ tools::SvRef<SotStorageStream> xInputStream(
+ xSotStorage->OpenSotStream(aStreamName, StreamMode::READ));
+
+ if (xInputStream.is() && !xInputStream->GetError())
+ {
+ xInputStream->SetBufferSize(STREAMBUF_SIZE);
+ bRet = GallerySvDrawImport(*xInputStream, rModel);
+ xInputStream->SetBufferSize(0);
+ }
+ }
+ return bRet;
+}
+
+SgaObjectSvDraw GalleryFileStorage::insertModel(const FmFormModel& rModel,
+ const INetURLObject& rUserURL)
+{
+ INetURLObject aURL(implCreateUniqueURL(SgaObjKind::SvDraw, rUserURL));
+ tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage());
+ bool bRet = false;
+
+ if (xSotStorage.is())
+ {
+ const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
+ tools::SvRef<SotStorageStream> xOutputStream(
+ xSotStorage->OpenSotStream(aStreamName, StreamMode::WRITE | StreamMode::TRUNC));
+
+ if (xOutputStream.is() && !xOutputStream->GetError())
+ {
+ SvMemoryStream aMemoryStream(65535, 65535);
+ FmFormModel* pFormModel = const_cast<FmFormModel*>(&rModel);
+
+ pFormModel->BurnInStyleSheetAttributes();
+
+ {
+ uno::Reference<io::XOutputStream> xDocOut(
+ new utl::OOutputStreamWrapper(aMemoryStream));
+
+ if (xDocOut.is())
+ (void)SvxDrawingLayerExport(pFormModel, xDocOut);
+ }
+
+ aMemoryStream.Seek(0);
+
+ xOutputStream->SetBufferSize(16348);
+ GalleryCodec aCodec(*xOutputStream);
+ aCodec.Write(aMemoryStream);
+
+ xOutputStream->SetBufferSize(0);
+ xOutputStream->Commit();
+ bRet = !xOutputStream->GetError();
+ }
+ }
+ if (bRet)
+ {
+ SgaObjectSvDraw aObjSvDraw(rModel, aURL);
+ return aObjSvDraw;
+ }
+ return SgaObjectSvDraw();
+}
+
+bool GalleryFileStorage::readModelStream(const GalleryObject* pObject,
+ tools::SvRef<SotTempStream> const& rxModelStream)
+{
+ const INetURLObject aURL(ImplGetURL(pObject));
+ tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage());
+ bool bRet = false;
+
+ if (xSotStorage.is())
+ {
+ const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
+ tools::SvRef<SotStorageStream> xInputStream(
+ xSotStorage->OpenSotStream(aStreamName, StreamMode::READ));
+
+ if (xInputStream.is() && !xInputStream->GetError())
+ {
+ sal_uInt32 nVersion = 0;
+
+ xInputStream->SetBufferSize(16348);
+
+ if (GalleryCodec::IsCoded(*xInputStream, nVersion))
+ {
+ SvxGalleryDrawModel aModel;
+
+ if (aModel.GetModel())
+ {
+ if (GallerySvDrawImport(*xInputStream, *aModel.GetModel()))
+ {
+ aModel.GetModel()->BurnInStyleSheetAttributes();
+
+ {
+ uno::Reference<io::XOutputStream> xDocOut(
+ new utl::OOutputStreamWrapper(*rxModelStream));
+
+ SvxDrawingLayerExport(aModel.GetModel(), xDocOut);
+ }
+ }
+
+ bRet = (rxModelStream->GetError() == ERRCODE_NONE);
+ }
+ }
+
+ xInputStream->SetBufferSize(0);
+ }
+ }
+ return bRet;
+}
+
+SgaObjectSvDraw
+GalleryFileStorage::insertModelStream(const tools::SvRef<SotTempStream>& rxModelStream,
+ const INetURLObject& rUserURL)
+{
+ INetURLObject aURL(implCreateUniqueURL(SgaObjKind::SvDraw, rUserURL));
+ tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage());
+
+ if (xSotStorage.is())
+ {
+ const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
+ tools::SvRef<SotStorageStream> xOutputStream(
+ xSotStorage->OpenSotStream(aStreamName, StreamMode::WRITE | StreamMode::TRUNC));
+
+ if (xOutputStream.is() && !xOutputStream->GetError())
+ {
+ GalleryCodec aCodec(*xOutputStream);
+
+ xOutputStream->SetBufferSize(16348);
+ aCodec.Write(*rxModelStream);
+
+ if (!xOutputStream->GetError())
+ {
+ xOutputStream->Seek(0);
+ SgaObjectSvDraw aObjSvDraw(*xOutputStream, aURL);
+ return aObjSvDraw;
+ }
+ }
+ }
+ return SgaObjectSvDraw();
+}
+
+INetURLObject GalleryFileStorage::implCreateUniqueURL(SgaObjKind eObjKind,
+ const INetURLObject& rUserURL,
+ ConvertDataFormat nFormat)
+{
+ INetURLObject aDir(rUserURL);
+ INetURLObject aInfoFileURL(rUserURL);
+ INetURLObject aNewURL;
+ sal_uInt32 nNextNumber = 1999;
+ char const* pExt = nullptr;
+ bool bExists;
+
+ aDir.Append(u"dragdrop");
+ CreateDir(aDir);
+
+ aInfoFileURL.Append(u"sdddndx1");
+
+ // read next possible number
+ if (FileExists(aInfoFileURL))
+ {
+ std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
+ aInfoFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
+
+ if (pIStm)
+ {
+ pIStm->ReadUInt32(nNextNumber);
+ }
+ }
+
+ pExt = comphelper::GraphicMimeTypeHelper::GetExtensionForConvertDataFormat(nFormat);
+
+ do
+ {
+ // get URL
+ if (SgaObjKind::SvDraw == eObjKind)
+ {
+ OUString aFileName = "gallery/svdraw/dd" + OUString::number(++nNextNumber % 99999999);
+ aNewURL = INetURLObject(aFileName, INetProtocol::PrivSoffice);
+
+ bExists = false;
+
+ for (auto const& pObject : mrGalleryObjectCollection.getObjectList())
+ {
+ if (*pObject->m_oStorageUrl == aNewURL)
+ {
+ bExists = true;
+ break;
+ }
+ }
+ }
+ else
+ {
+ OUString aFileName = "dd" + OUString::number(++nNextNumber % 999999);
+
+ if (pExt)
+ aFileName += OUString(pExt, strlen(pExt), RTL_TEXTENCODING_ASCII_US);
+
+ aNewURL = aDir;
+ aNewURL.Append(aFileName);
+
+ bExists = FileExists(aNewURL);
+ }
+ } while (bExists);
+
+ // write updated number
+ std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
+ aInfoFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE));
+
+ if (pOStm)
+ {
+ pOStm->WriteUInt32(nNextNumber);
+ }
+
+ return aNewURL;
+}
+
+SgaObjectBmp GalleryFileStorage::insertGraphic(const Graphic& rGraphic, const GfxLink& aGfxLink,
+ const ConvertDataFormat& nExportFormat,
+ const INetURLObject& rUserURL)
+{
+ const INetURLObject aURL(implCreateUniqueURL(SgaObjKind::Bitmap, rUserURL, nExportFormat));
+ std::unique_ptr<SvStream> pOStm(
+ ::utl::UcbStreamHelper::CreateStream(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
+ StreamMode::WRITE | StreamMode::TRUNC));
+ bool bRet = false;
+
+ if (pOStm)
+ {
+ pOStm->SetVersion(SOFFICE_FILEFORMAT_50);
+
+ if (ConvertDataFormat::SVM == nExportFormat)
+ {
+ GDIMetaFile aMtf(rGraphic.GetGDIMetaFile());
+
+ SvmWriter aWriter(*pOStm);
+ aWriter.Write(aMtf);
+ bRet = (pOStm->GetError() == ERRCODE_NONE);
+ }
+ else
+ {
+ if (aGfxLink.GetDataSize() && aGfxLink.GetData())
+ {
+ pOStm->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize());
+ bRet = (pOStm->GetError() == ERRCODE_NONE);
+ }
+ else
+ bRet = (GraphicConverter::Export(*pOStm, rGraphic, nExportFormat) == ERRCODE_NONE);
+ }
+
+ pOStm.reset();
+ }
+ if (bRet)
+ {
+ const SgaObjectBmp aObjBmp(aURL);
+ return aObjBmp;
+ }
+ return SgaObjectBmp();
+}
+
+SgaObjectSvDraw GalleryFileStorage::updateSvDrawObject(const GalleryObject* pEntry)
+{
+ if (GetSvDrawStorage().is())
+ {
+ const OUString aStmName(GetSvDrawStreamNameFromURL(*pEntry->m_oStorageUrl));
+ tools::SvRef<SotStorageStream> pIStm
+ = GetSvDrawStorage()->OpenSotStream(aStmName, StreamMode::READ);
+
+ if (pIStm.is() && !pIStm->GetError())
+ {
+ pIStm->SetBufferSize(16384);
+
+ SgaObjectSvDraw aNewObj(*pIStm, *pEntry->m_oStorageUrl);
+
+ pIStm->SetBufferSize(0);
+
+ return aNewObj;
+ }
+ }
+ return SgaObjectSvDraw();
+}
+
+void GalleryFileStorage::updateTheme()
+{
+ ::utl::TempFileNamed aTmp;
+ INetURLObject aInURL(GetSdgURL());
+ INetURLObject aTmpURL(aTmp.GetURL());
+
+ DBG_ASSERT(aInURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
+ DBG_ASSERT(aTmpURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
+
+ std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
+ aInURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
+ std::unique_ptr<SvStream> pTmpStm(::utl::UcbStreamHelper::CreateStream(
+ aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
+ StreamMode::WRITE | StreamMode::TRUNC));
+
+ if (pIStm && pTmpStm)
+ {
+ for (const auto& i : mrGalleryObjectCollection.getObjectList())
+ {
+ GalleryObject* pEntry = i.get();
+ std::unique_ptr<SgaObject> pObj;
+
+ switch (pEntry->eObjKind)
+ {
+ case SgaObjKind::Bitmap:
+ pObj.reset(new SgaObjectBmp());
+ break;
+ case SgaObjKind::Animation:
+ pObj.reset(new SgaObjectAnim());
+ break;
+ case SgaObjKind::Inet:
+ pObj.reset(new SgaObjectINet());
+ break;
+ case SgaObjKind::SvDraw:
+ pObj.reset(new SgaObjectSvDraw());
+ break;
+ case SgaObjKind::Sound:
+ pObj.reset(new SgaObjectSound());
+ break;
+
+ default:
+ break;
+ }
+
+ if (pObj)
+ {
+ pIStm->Seek(pEntry->nOffset);
+ ReadSgaObject(*pIStm, *pObj);
+ pEntry->nOffset = pTmpStm->Tell();
+ WriteSgaObject(*pTmpStm, *pObj);
+ }
+ }
+ }
+ else
+ {
+ OSL_FAIL("File(s) could not be opened");
+ }
+
+ pIStm.reset();
+ pTmpStm.reset();
+
+ CopyFile(aTmpURL, aInURL);
+ KillFile(aTmpURL);
+
+ ErrCode nStorErr = ERRCODE_NONE;
+
+ try
+ {
+ tools::SvRef<SotStorage> aTempStorageRef(
+ new SotStorage(false, aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
+ StreamMode::STD_READWRITE));
+ GetSvDrawStorage()->CopyTo(aTempStorageRef.get());
+ nStorErr = GetSvDrawStorage()->GetError();
+ }
+ catch (const css::ucb::ContentCreationException&)
+ {
+ TOOLS_WARN_EXCEPTION("svx", "failed to open: "
+ << aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)
+ << "due to");
+ nStorErr = ERRCODE_IO_GENERAL;
+ }
+
+ if (nStorErr == ERRCODE_NONE)
+ {
+ clearSotStorage();
+ CopyFile(aTmpURL, GetSdvURL());
+ ImplCreateSvDrawStorage();
+ }
+
+ KillFile(aTmpURL);
+}
+
+void GalleryFileStorage::insertFileOrDirURL(const INetURLObject& rFileOrDirURL,
+ std::vector<INetURLObject>& rURLVector)
+{
+ INetURLObject aURL;
+ try
+ {
+ ::ucbhelper::Content aCnt(rFileOrDirURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
+ uno::Reference<ucb::XCommandEnvironment>(),
+ comphelper::getProcessComponentContext());
+ bool bFolder = false;
+
+ aCnt.getPropertyValue("IsFolder") >>= bFolder;
+
+ if (bFolder)
+ {
+ uno::Sequence<OUString> aProps{ "Url" };
+ uno::Reference<sdbc::XResultSet> xResultSet(
+ aCnt.createCursor(aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY));
+ uno::Reference<ucb::XContentAccess> xContentAccess(xResultSet, uno::UNO_QUERY);
+ if (xContentAccess.is())
+ {
+ while (xResultSet->next())
+ {
+ aURL.SetSmartURL(xContentAccess->queryContentIdentifierString());
+ rURLVector.push_back(aURL);
+ }
+ }
+ }
+ else
+ rURLVector.push_back(rFileOrDirURL);
+ }
+ catch (const ucb::ContentCreationException&)
+ {
+ }
+ catch (const uno::RuntimeException&)
+ {
+ }
+ catch (const uno::Exception&)
+ {
+ }
+}
+
+SvStream& GalleryFileStorage::writeGalleryTheme(SvStream& rOStm, const GalleryTheme& rTheme,
+ const GalleryThemeEntry* pThm)
+{
+ const INetURLObject rRelURL1 = rTheme.GetParent()->GetRelativeURL();
+ const INetURLObject rRelURL2 = rTheme.GetParent()->GetUserURL();
+ const sal_uInt32 rId = rTheme.GetId();
+ sal_uInt32 nCount = mrGalleryObjectCollection.size();
+ bool bRel;
+
+ rOStm.WriteUInt16(0x0004);
+ write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, pThm->GetThemeName(),
+ RTL_TEXTENCODING_UTF8);
+ rOStm.WriteUInt32(nCount).WriteUInt16(osl_getThreadTextEncoding());
+
+ for (sal_uInt32 i = 0; i < nCount; i++)
+ {
+ const GalleryObject* pObj = mrGalleryObjectCollection.getForPosition(i);
+ OUString aPath;
+
+ if (SgaObjKind::SvDraw == pObj->eObjKind)
+ {
+ aPath = GetSvDrawStreamNameFromURL(*pObj->m_oStorageUrl);
+ bRel = false;
+ }
+ else
+ {
+ aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
+ aPath = aPath.copy(
+ 0, std::min(rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
+ aPath.getLength()));
+ bRel = aPath == rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE);
+
+ if (bRel
+ && (pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE)
+ .getLength()
+ > (rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength() + 1)))
+ {
+ aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
+ aPath = aPath.copy(
+ std::min(rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
+ aPath.getLength()));
+ }
+ else
+ {
+ aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
+ aPath = aPath.copy(
+ 0,
+ std::min(rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
+ aPath.getLength()));
+ bRel = aPath == rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE);
+
+ if (bRel
+ && (pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE)
+ .getLength()
+ > (rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength()
+ + 1)))
+ {
+ aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
+ aPath = aPath.copy(std::min(
+ rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
+ aPath.getLength()));
+ }
+ else
+ aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
+ }
+ }
+
+ if (!m_aDestDir.isEmpty())
+ {
+ bool aFound = aPath.indexOf(m_aDestDir) != -1;
+ aPath = aPath.replaceFirst(m_aDestDir, "");
+ if (aFound)
+ bRel = m_bDestDirRelative;
+ else
+ SAL_WARN("svx", "failed to replace destdir of '" << m_aDestDir << "' in '" << aPath
+ << "'");
+ }
+
+ rOStm.WriteBool(bRel);
+ write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aPath, RTL_TEXTENCODING_UTF8);
+ rOStm.WriteUInt32(pObj->nOffset).WriteUInt16(static_cast<sal_uInt16>(pObj->eObjKind));
+ }
+
+ // more recently, a 512-byte reserve buffer is written,
+ // to recognize them two sal_uInt32-Ids will be written.
+ rOStm.WriteUInt32(COMPAT_FORMAT('G', 'A', 'L', 'R'))
+ .WriteUInt32(COMPAT_FORMAT('E', 'S', 'R', 'V'));
+
+ const sal_uInt64 nReservePos = rOStm.Tell();
+ std::unique_ptr<VersionCompatWrite> pCompat(new VersionCompatWrite(rOStm, 2));
+
+ rOStm.WriteUInt32(rId).WriteBool(pThm->IsNameFromResource()); // From version 2 and up
+
+ pCompat.reset();
+
+ // Fill the rest of the buffer.
+ const tools::Long nRest
+ = std::max(tools::Long(512 - (rOStm.Tell() - nReservePos)), tools::Long(0));
+
+ if (nRest)
+ {
+ std::unique_ptr<char[]> pReserve(new char[nRest]);
+ memset(pReserve.get(), 0, nRest);
+ rOStm.WriteBytes(pReserve.get(), nRest);
+ }
+
+ return rOStm;
+}
+
+DateTime GalleryFileStorage::getModificationDate() const
+{
+ ::ucbhelper::Content aCnt(GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
+ uno::Reference<ucb::XCommandEnvironment>(),
+ comphelper::getProcessComponentContext());
+ util::DateTime aDateTimeModified;
+ DateTime aDateTime(DateTime::EMPTY);
+
+ aCnt.getPropertyValue("DateModified") >>= aDateTimeModified;
+ ::utl::typeConvert(aDateTimeModified, aDateTime);
+
+ return aDateTime;
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/gallery2/galleryfilestorageentry.cxx b/svx/source/gallery2/galleryfilestorageentry.cxx
index abbc6efcaea1..b7de500f66e3 100644
--- a/svx/source/gallery2/galleryfilestorageentry.cxx
+++ b/svx/source/gallery2/galleryfilestorageentry.cxx
@@ -45,11 +45,11 @@ void GalleryFileStorageEntry::setStorageLocations(INetURLObject& rURL)
mpGalleryStorageLocations->SetStorageLocations(rURL);
}
-std::unique_ptr<GalleryBinaryEngine> GalleryFileStorageEntry::createGalleryStorageEngine(
+std::unique_ptr<GalleryFileStorage> GalleryFileStorageEntry::createGalleryStorageEngine(
GalleryObjectCollection& mrGalleryObjectCollection, bool& bReadOnly)
{
- return std::make_unique<GalleryBinaryEngine>(*mpGalleryStorageLocations,
- mrGalleryObjectCollection, bReadOnly);
+ return std::make_unique<GalleryFileStorage>(*mpGalleryStorageLocations,
+ mrGalleryObjectCollection, bReadOnly);
}
void GalleryFileStorageEntry::CreateUniqueURL(const INetURLObject& rBaseURL, INetURLObject& aURL)
diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx
index 1c034b2a769b..1fd04b454249 100644
--- a/svx/source/gallery2/galtheme.cxx
+++ b/svx/source/gallery2/galtheme.cxx
@@ -41,7 +41,7 @@
#include <svx/galtheme.hxx>
#include <svx/svdpage.hxx>
#include <svx/galleryobjectcollection.hxx>
-#include <gallerybinaryengine.hxx>
+#include <galleryfilestorage.hxx>
#include <galobj.hxx>
#include <svx/gallery1.hxx>
#include "gallerydrawmodel.hxx"
@@ -523,7 +523,7 @@ bool GalleryTheme::InsertFileOrDirURL(const INetURLObject& rFileOrDirURL, sal_uI
{
bool bRet = false;
std::vector< INetURLObject > aURLVector;
- GalleryBinaryEngine::insertFileOrDirURL(rFileOrDirURL, aURLVector);
+ GalleryFileStorage::insertFileOrDirURL(rFileOrDirURL, aURLVector);
for( const auto& rURL : aURLVector )
bRet = bRet || InsertURL( rURL, nInsertPos );
diff --git a/svx/source/unogallery/unogalitem.cxx b/svx/source/unogallery/unogalitem.cxx
index c3725b5fba1e..c08e182a46aa 100644
--- a/svx/source/unogallery/unogalitem.cxx
+++ b/svx/source/unogallery/unogalitem.cxx
@@ -20,7 +20,7 @@
#include "unogalitem.hxx"
#include "unogaltheme.hxx"
-#include <gallerybinaryengine.hxx>
+#include <galleryfilestorage.hxx>
#include <svx/galtheme.hxx>
#include <svx/galmisc.hxx>
#include <svx/fmmodel.hxx>