tdf#161541 sd: fix the orientation of handouts on the printed page
[LibreOffice.git] / svx / source / gallery2 / galleryfilestorage.cxx
blob5295492ca3be332a6692a6f2546f3fcc92f72c12
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/unomodel.hxx>
21 #include <svx/fmmodel.hxx>
22 #include <svx/galtheme.hxx>
23 #include <galobj.hxx>
24 #include <galleryfilestorage.hxx>
25 #include <svx/galleryobjectcollection.hxx>
26 #include <svx/gallery1.hxx>
27 #include "codec.hxx"
28 #include "gallerydrawmodel.hxx"
29 #include <vcl/cvtgrf.hxx>
30 #include <vcl/filter/SvmWriter.hxx>
32 #include <sal/log.hxx>
34 #include <com/sun/star/ucb/ContentCreationException.hpp>
35 #include <com/sun/star/sdbc/XResultSet.hpp>
36 #include <com/sun/star/ucb/XContentAccess.hpp>
37 #include <comphelper/fileformat.h>
38 #include <comphelper/graphicmimetype.hxx>
39 #include <comphelper/processfactory.hxx>
40 #include <tools/urlobj.hxx>
41 #include <comphelper/diagnose_ex.hxx>
42 #include <tools/datetime.hxx>
43 #include <unotools/datetime.hxx>
44 #include <unotools/ucbstreamhelper.hxx>
45 #include <unotools/streamwrap.hxx>
46 #include <unotools/tempfile.hxx>
47 #include <ucbhelper/content.hxx>
48 #include <tools/vcompat.hxx>
50 using namespace ::com::sun::star;
52 GalleryFileStorage::GalleryFileStorage(
53 const GalleryStorageLocations& rGalleryBinaryStorageLocations,
54 GalleryObjectCollection& rGalleryObjectCollection, bool bReadOnly)
55 : maGalleryStorageLocations(rGalleryBinaryStorageLocations)
56 , mrGalleryObjectCollection(rGalleryObjectCollection)
57 , mbReadOnly(bReadOnly)
58 , m_bDestDirRelative(false)
60 ImplCreateSvDrawStorage();
63 GalleryFileStorage::~GalleryFileStorage() { clearSotStorage(); }
65 void GalleryFileStorage::setDestDir(const OUString& rDestDir, bool bRelative)
67 m_aDestDir = rDestDir;
68 m_bDestDirRelative = bRelative;
71 void GalleryFileStorage::clearSotStorage() { m_aSvDrawStorageRef.clear(); }
73 void GalleryFileStorage::ImplCreateSvDrawStorage()
75 try
77 m_aSvDrawStorageRef
78 = new SotStorage(false, GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
79 mbReadOnly ? StreamMode::READ : StreamMode::STD_READWRITE);
80 // #i50423# ReadOnly may not been set though the file can't be written (because of security reasons)
81 if ((m_aSvDrawStorageRef->GetError() != ERRCODE_NONE) && !mbReadOnly)
82 m_aSvDrawStorageRef = new SotStorage(
83 false, GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
84 StreamMode::READ);
86 catch (const css::ucb::ContentCreationException&)
88 TOOLS_WARN_EXCEPTION("svx", "failed to open: " << GetSdvURL().GetMainURL(
89 INetURLObject::DecodeMechanism::NONE)
90 << "due to");
94 const rtl::Reference<SotStorage>& GalleryFileStorage::GetSvDrawStorage() const
96 return m_aSvDrawStorageRef;
99 bool GalleryFileStorage::implWrite(const GalleryTheme& rTheme, const GalleryThemeEntry* pThm)
101 INetURLObject aPathURL(GetThmURL());
103 aPathURL.removeSegment();
104 aPathURL.removeFinalSlash();
106 DBG_ASSERT(aPathURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
108 if (FileExists(aPathURL) || CreateDir(aPathURL))
110 #ifdef UNX
111 std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
112 GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
113 StreamMode::WRITE | StreamMode::COPY_ON_SYMLINK | StreamMode::TRUNC));
114 #else
115 std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
116 GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
117 StreamMode::WRITE | StreamMode::TRUNC));
118 #endif
120 if (pOStm)
122 writeGalleryTheme(*pOStm, rTheme, pThm);
123 pOStm.reset();
124 return true;
127 return false;
129 return true;
132 void GalleryFileStorage::insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry,
133 sal_uInt32 nInsertPos)
135 if (pFoundEntry)
137 GalleryObject aNewEntry;
139 // update title of new object if necessary
140 if (rObj.GetTitle().isEmpty())
142 std::unique_ptr<SgaObject> pOldObj(implReadSgaObject(pFoundEntry));
144 if (pOldObj)
146 const_cast<SgaObject&>(rObj).SetTitle(pOldObj->GetTitle());
149 else if (rObj.GetTitle() == "__<empty>__")
150 const_cast<SgaObject&>(rObj).SetTitle(u""_ustr);
152 implWriteSgaObject(rObj, nInsertPos, &aNewEntry);
153 pFoundEntry->nOffset = aNewEntry.nOffset;
155 else
156 implWriteSgaObject(rObj, nInsertPos, nullptr);
159 void GalleryFileStorage::removeObject(const std::unique_ptr<GalleryObject>& pEntry)
161 if (mrGalleryObjectCollection.getObjectList().empty())
162 KillFile(GetSdgURL());
164 if (SgaObjKind::SvDraw == pEntry->eObjKind)
165 GetSvDrawStorage()->Remove(
166 pEntry->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE));
169 std::unique_ptr<SgaObject> GalleryFileStorage::implReadSgaObject(GalleryObject const* pEntry)
171 std::unique_ptr<SgaObject> pSgaObj;
173 if (pEntry)
175 std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
176 GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
178 if (pIStm)
180 sal_uInt32 nInventor;
182 // Check to ensure that the file is a valid SGA file
183 pIStm->Seek(pEntry->nOffset);
184 pIStm->ReadUInt32(nInventor);
186 if (nInventor == COMPAT_FORMAT('S', 'G', 'A', '3'))
188 pIStm->Seek(pEntry->nOffset);
190 switch (pEntry->eObjKind)
192 case SgaObjKind::Bitmap:
193 pSgaObj.reset(new SgaObjectBmp());
194 break;
195 case SgaObjKind::Animation:
196 pSgaObj.reset(new SgaObjectAnim());
197 break;
198 case SgaObjKind::Inet:
199 pSgaObj.reset(new SgaObjectINet());
200 break;
201 case SgaObjKind::SvDraw:
202 pSgaObj.reset(new SgaObjectSvDraw());
203 break;
204 case SgaObjKind::Sound:
205 pSgaObj.reset(new SgaObjectSound());
206 break;
208 default:
209 break;
212 if (pSgaObj)
214 ReadSgaObject(*pIStm, *pSgaObj);
215 pSgaObj->ImplUpdateURL(*pEntry->m_oStorageUrl);
221 return pSgaObj;
224 bool GalleryFileStorage::implWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos,
225 GalleryObject* pExistentEntry)
227 std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
228 GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE));
229 bool bRet = false;
231 if (pOStm)
233 const sal_uInt32 nOffset = pOStm->Seek(STREAM_SEEK_TO_END);
235 rObj.WriteData(*pOStm, m_aDestDir);
237 if (!pOStm->GetError())
239 GalleryObject* pEntry;
241 if (!pExistentEntry)
243 pEntry = new GalleryObject;
244 if (nPos < mrGalleryObjectCollection.size())
246 mrGalleryObjectCollection.getObjectList().emplace(
247 mrGalleryObjectCollection.getObjectList().begin() + nPos, pEntry);
249 else
250 mrGalleryObjectCollection.getObjectList().emplace_back(pEntry);
252 else
253 pEntry = pExistentEntry;
255 pEntry->m_oStorageUrl = rObj.GetURL();
257 pEntry->nOffset = nOffset;
258 pEntry->eObjKind = rObj.GetObjKind();
259 bRet = true;
263 return bRet;
266 bool GalleryFileStorage::readModel(const GalleryObject* pObject, SdrModel& rModel)
268 rtl::Reference<SotStorage> xSotStorage(GetSvDrawStorage());
269 bool bRet = false;
270 const INetURLObject aURL(ImplGetURL(pObject));
272 if (xSotStorage.is())
274 const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
275 rtl::Reference<SotStorageStream> xInputStream(
276 xSotStorage->OpenSotStream(aStreamName, StreamMode::READ));
278 if (xInputStream.is() && !xInputStream->GetError())
280 xInputStream->SetBufferSize(STREAMBUF_SIZE);
281 bRet = GallerySvDrawImport(*xInputStream, rModel);
282 xInputStream->SetBufferSize(0);
285 return bRet;
288 SgaObjectSvDraw GalleryFileStorage::insertModel(const FmFormModel& rModel,
289 const INetURLObject& rUserURL)
291 INetURLObject aURL(implCreateUniqueURL(SgaObjKind::SvDraw, rUserURL));
292 rtl::Reference<SotStorage> xSotStorage(GetSvDrawStorage());
293 bool bRet = false;
295 if (xSotStorage.is())
297 const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
298 rtl::Reference<SotStorageStream> xOutputStream(
299 xSotStorage->OpenSotStream(aStreamName, StreamMode::WRITE | StreamMode::TRUNC));
301 if (xOutputStream.is() && !xOutputStream->GetError())
303 SvMemoryStream aMemoryStream(65535, 65535);
304 FmFormModel* pFormModel = const_cast<FmFormModel*>(&rModel);
306 pFormModel->BurnInStyleSheetAttributes();
309 uno::Reference<io::XOutputStream> xDocOut(
310 new utl::OOutputStreamWrapper(aMemoryStream));
312 if (xDocOut.is())
313 (void)SvxDrawingLayerExport(pFormModel, xDocOut);
316 aMemoryStream.Seek(0);
318 xOutputStream->SetBufferSize(16348);
319 GalleryCodec aCodec(*xOutputStream);
320 aCodec.Write(aMemoryStream);
322 xOutputStream->SetBufferSize(0);
323 xOutputStream->Commit();
324 bRet = !xOutputStream->GetError();
327 if (bRet)
329 SgaObjectSvDraw aObjSvDraw(rModel, aURL);
330 return aObjSvDraw;
332 return SgaObjectSvDraw();
335 bool GalleryFileStorage::readModelStream(const GalleryObject* pObject, SvStream& rxModelStream)
337 const INetURLObject aURL(ImplGetURL(pObject));
338 rtl::Reference<SotStorage> xSotStorage(GetSvDrawStorage());
339 bool bRet = false;
341 if (xSotStorage.is())
343 const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
344 rtl::Reference<SotStorageStream> xInputStream(
345 xSotStorage->OpenSotStream(aStreamName, StreamMode::READ));
347 if (xInputStream.is() && !xInputStream->GetError())
349 sal_uInt32 nVersion = 0;
351 xInputStream->SetBufferSize(16348);
353 if (GalleryCodec::IsCoded(*xInputStream, nVersion))
355 SvxGalleryDrawModel aModel;
357 if (aModel.GetModel())
359 if (GallerySvDrawImport(*xInputStream, *aModel.GetModel()))
361 aModel.GetModel()->BurnInStyleSheetAttributes();
364 uno::Reference<io::XOutputStream> xDocOut(
365 new utl::OOutputStreamWrapper(rxModelStream));
367 SvxDrawingLayerExport(aModel.GetModel(), xDocOut);
371 bRet = (rxModelStream.GetError() == ERRCODE_NONE);
375 xInputStream->SetBufferSize(0);
378 return bRet;
381 SgaObjectSvDraw GalleryFileStorage::insertModelStream(SvStream& rModelStream,
382 const INetURLObject& rUserURL)
384 INetURLObject aURL(implCreateUniqueURL(SgaObjKind::SvDraw, rUserURL));
385 rtl::Reference<SotStorage> xSotStorage(GetSvDrawStorage());
387 if (xSotStorage.is())
389 const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
390 rtl::Reference<SotStorageStream> xOutputStream(
391 xSotStorage->OpenSotStream(aStreamName, StreamMode::WRITE | StreamMode::TRUNC));
393 if (xOutputStream.is() && !xOutputStream->GetError())
395 GalleryCodec aCodec(*xOutputStream);
397 xOutputStream->SetBufferSize(16348);
398 aCodec.Write(rModelStream);
400 if (!xOutputStream->GetError())
402 xOutputStream->Seek(0);
403 SgaObjectSvDraw aObjSvDraw(*xOutputStream, aURL);
404 return aObjSvDraw;
408 return SgaObjectSvDraw();
411 INetURLObject GalleryFileStorage::implCreateUniqueURL(SgaObjKind eObjKind,
412 const INetURLObject& rUserURL,
413 ConvertDataFormat nFormat)
415 INetURLObject aDir(rUserURL);
416 INetURLObject aInfoFileURL(rUserURL);
417 INetURLObject aNewURL;
418 sal_uInt32 nNextNumber = 1999;
419 char const* pExt = nullptr;
420 bool bExists;
422 aDir.Append(u"dragdrop");
423 CreateDir(aDir);
425 aInfoFileURL.Append(u"sdddndx1");
427 // read next possible number
428 if (FileExists(aInfoFileURL))
430 std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
431 aInfoFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
433 if (pIStm)
435 pIStm->ReadUInt32(nNextNumber);
439 pExt = comphelper::GraphicMimeTypeHelper::GetExtensionForConvertDataFormat(nFormat);
443 // get URL
444 if (SgaObjKind::SvDraw == eObjKind)
446 OUString aFileName = "gallery/svdraw/dd" + OUString::number(++nNextNumber % 99999999);
447 aNewURL = INetURLObject(aFileName, INetProtocol::PrivSoffice);
449 bExists = false;
451 for (auto const& pObject : mrGalleryObjectCollection.getObjectList())
453 if (*pObject->m_oStorageUrl == aNewURL)
455 bExists = true;
456 break;
460 else
462 OUString aFileName = "dd" + OUString::number(++nNextNumber % 999999);
464 if (pExt)
465 aFileName += OUString(pExt, strlen(pExt), RTL_TEXTENCODING_ASCII_US);
467 aNewURL = aDir;
468 aNewURL.Append(aFileName);
470 bExists = FileExists(aNewURL);
472 } while (bExists);
474 // write updated number
475 std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
476 aInfoFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE));
478 if (pOStm)
480 pOStm->WriteUInt32(nNextNumber);
483 return aNewURL;
486 SgaObjectBmp GalleryFileStorage::insertGraphic(const Graphic& rGraphic, const GfxLink& aGfxLink,
487 const ConvertDataFormat& nExportFormat,
488 const INetURLObject& rUserURL)
490 const INetURLObject aURL(implCreateUniqueURL(SgaObjKind::Bitmap, rUserURL, nExportFormat));
491 std::unique_ptr<SvStream> pOStm(
492 ::utl::UcbStreamHelper::CreateStream(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
493 StreamMode::WRITE | StreamMode::TRUNC));
494 bool bRet = false;
496 if (pOStm)
498 pOStm->SetVersion(SOFFICE_FILEFORMAT_50);
500 if (ConvertDataFormat::SVM == nExportFormat)
502 const GDIMetaFile& aMtf(rGraphic.GetGDIMetaFile());
504 SvmWriter aWriter(*pOStm);
505 aWriter.Write(aMtf);
506 bRet = (pOStm->GetError() == ERRCODE_NONE);
508 else
510 if (aGfxLink.GetDataSize() && aGfxLink.GetData())
512 pOStm->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize());
513 bRet = (pOStm->GetError() == ERRCODE_NONE);
515 else
516 bRet = (GraphicConverter::Export(*pOStm, rGraphic, nExportFormat) == ERRCODE_NONE);
519 pOStm.reset();
521 if (bRet)
523 const SgaObjectBmp aObjBmp(aURL);
524 return aObjBmp;
526 return SgaObjectBmp();
529 SgaObjectSvDraw GalleryFileStorage::updateSvDrawObject(const GalleryObject* pEntry)
531 if (GetSvDrawStorage().is())
533 const OUString aStmName(GetSvDrawStreamNameFromURL(*pEntry->m_oStorageUrl));
534 rtl::Reference<SotStorageStream> pIStm
535 = GetSvDrawStorage()->OpenSotStream(aStmName, StreamMode::READ);
537 if (pIStm.is() && !pIStm->GetError())
539 pIStm->SetBufferSize(16384);
541 SgaObjectSvDraw aNewObj(*pIStm, *pEntry->m_oStorageUrl);
543 pIStm->SetBufferSize(0);
545 return aNewObj;
548 return SgaObjectSvDraw();
551 void GalleryFileStorage::updateTheme()
553 ::utl::TempFileNamed aTmp;
554 INetURLObject aInURL(GetSdgURL());
555 INetURLObject aTmpURL(aTmp.GetURL());
557 DBG_ASSERT(aInURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
558 DBG_ASSERT(aTmpURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
560 std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
561 aInURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
562 std::unique_ptr<SvStream> pTmpStm(::utl::UcbStreamHelper::CreateStream(
563 aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
564 StreamMode::WRITE | StreamMode::TRUNC));
566 if (pIStm && pTmpStm)
568 for (const auto& i : mrGalleryObjectCollection.getObjectList())
570 GalleryObject* pEntry = i.get();
571 std::unique_ptr<SgaObject> pObj;
573 switch (pEntry->eObjKind)
575 case SgaObjKind::Bitmap:
576 pObj.reset(new SgaObjectBmp());
577 break;
578 case SgaObjKind::Animation:
579 pObj.reset(new SgaObjectAnim());
580 break;
581 case SgaObjKind::Inet:
582 pObj.reset(new SgaObjectINet());
583 break;
584 case SgaObjKind::SvDraw:
585 pObj.reset(new SgaObjectSvDraw());
586 break;
587 case SgaObjKind::Sound:
588 pObj.reset(new SgaObjectSound());
589 break;
591 default:
592 break;
595 if (pObj)
597 pIStm->Seek(pEntry->nOffset);
598 ReadSgaObject(*pIStm, *pObj);
599 pEntry->nOffset = pTmpStm->Tell();
600 WriteSgaObject(*pTmpStm, *pObj);
604 else
606 OSL_FAIL("File(s) could not be opened");
609 pIStm.reset();
610 pTmpStm.reset();
612 CopyFile(aTmpURL, aInURL);
613 KillFile(aTmpURL);
615 ErrCode nStorErr = ERRCODE_NONE;
619 rtl::Reference<SotStorage> aTempStorageRef(
620 new SotStorage(false, aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
621 StreamMode::STD_READWRITE));
622 GetSvDrawStorage()->CopyTo(aTempStorageRef.get());
623 nStorErr = GetSvDrawStorage()->GetError();
625 catch (const css::ucb::ContentCreationException&)
627 TOOLS_WARN_EXCEPTION("svx", "failed to open: "
628 << aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)
629 << "due to");
630 nStorErr = ERRCODE_IO_GENERAL;
633 if (nStorErr == ERRCODE_NONE)
635 clearSotStorage();
636 CopyFile(aTmpURL, GetSdvURL());
637 ImplCreateSvDrawStorage();
640 KillFile(aTmpURL);
643 void GalleryFileStorage::insertFileOrDirURL(const INetURLObject& rFileOrDirURL,
644 std::vector<INetURLObject>& rURLVector)
646 INetURLObject aURL;
649 ::ucbhelper::Content aCnt(rFileOrDirURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
650 uno::Reference<ucb::XCommandEnvironment>(),
651 comphelper::getProcessComponentContext());
652 bool bFolder = false;
654 aCnt.getPropertyValue(u"IsFolder"_ustr) >>= bFolder;
656 if (bFolder)
658 uno::Sequence<OUString> aProps{ u"Url"_ustr };
659 uno::Reference<sdbc::XResultSet> xResultSet(
660 aCnt.createCursor(aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY));
661 uno::Reference<ucb::XContentAccess> xContentAccess(xResultSet, uno::UNO_QUERY);
662 if (xContentAccess.is())
664 while (xResultSet->next())
666 aURL.SetSmartURL(xContentAccess->queryContentIdentifierString());
667 rURLVector.push_back(aURL);
671 else
672 rURLVector.push_back(rFileOrDirURL);
674 catch (const ucb::ContentCreationException&)
677 catch (const uno::RuntimeException&)
680 catch (const uno::Exception&)
685 SvStream& GalleryFileStorage::writeGalleryTheme(SvStream& rOStm, const GalleryTheme& rTheme,
686 const GalleryThemeEntry* pThm)
688 const INetURLObject rRelURL1 = rTheme.GetParent()->GetRelativeURL();
689 const INetURLObject rRelURL2 = rTheme.GetParent()->GetUserURL();
690 const sal_uInt32 rId = rTheme.GetId();
691 sal_uInt32 nCount = mrGalleryObjectCollection.size();
692 bool bRel;
694 rOStm.WriteUInt16(0x0004);
695 write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, pThm->GetThemeName(),
696 RTL_TEXTENCODING_UTF8);
697 rOStm.WriteUInt32(nCount);
698 rOStm.WriteUInt16(RTL_TEXTENCODING_UTF8); // unused on reading
700 for (sal_uInt32 i = 0; i < nCount; i++)
702 const GalleryObject* pObj = mrGalleryObjectCollection.getForPosition(i);
703 OUString aPath;
705 if (SgaObjKind::SvDraw == pObj->eObjKind)
707 aPath = GetSvDrawStreamNameFromURL(*pObj->m_oStorageUrl);
708 bRel = false;
710 else
712 aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
713 aPath = aPath.copy(
714 0, std::min(rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
715 aPath.getLength()));
716 bRel = aPath == rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE);
718 if (bRel
719 && (pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE)
720 .getLength()
721 > (rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength() + 1)))
723 aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
724 aPath = aPath.copy(
725 std::min(rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
726 aPath.getLength()));
728 else
730 aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
731 aPath = aPath.copy(
733 std::min(rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
734 aPath.getLength()));
735 bRel = aPath == rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE);
737 if (bRel
738 && (pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE)
739 .getLength()
740 > (rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength()
741 + 1)))
743 aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
744 aPath = aPath.copy(std::min(
745 rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
746 aPath.getLength()));
748 else
749 aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
753 if (!m_aDestDir.isEmpty())
755 bool aFound = aPath.indexOf(m_aDestDir) != -1;
756 aPath = aPath.replaceFirst(m_aDestDir, "");
757 if (aFound)
758 bRel = m_bDestDirRelative;
759 else
760 SAL_WARN("svx", "failed to replace destdir of '" << m_aDestDir << "' in '" << aPath
761 << "'");
764 rOStm.WriteBool(bRel);
765 write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aPath, RTL_TEXTENCODING_UTF8);
766 rOStm.WriteUInt32(pObj->nOffset).WriteUInt16(static_cast<sal_uInt16>(pObj->eObjKind));
769 // more recently, a 512-byte reserve buffer is written,
770 // to recognize them two sal_uInt32-Ids will be written.
771 rOStm.WriteUInt32(COMPAT_FORMAT('G', 'A', 'L', 'R'))
772 .WriteUInt32(COMPAT_FORMAT('E', 'S', 'R', 'V'));
774 const sal_uInt64 nReservePos = rOStm.Tell();
775 std::unique_ptr<VersionCompatWrite> pCompat(new VersionCompatWrite(rOStm, 2));
777 rOStm.WriteUInt32(rId).WriteBool(pThm->IsNameFromResource()); // From version 2 and up
779 pCompat.reset();
781 // Fill the rest of the buffer.
782 const tools::Long nRest
783 = std::max(tools::Long(512 - (rOStm.Tell() - nReservePos)), tools::Long(0));
785 if (nRest)
787 std::unique_ptr<char[]> pReserve(new char[nRest]);
788 memset(pReserve.get(), 0, nRest);
789 rOStm.WriteBytes(pReserve.get(), nRest);
792 return rOStm;
795 DateTime GalleryFileStorage::getModificationDate() const
797 ::ucbhelper::Content aCnt(GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
798 uno::Reference<ucb::XCommandEnvironment>(),
799 comphelper::getProcessComponentContext());
800 util::DateTime aDateTimeModified;
801 DateTime aDateTime(DateTime::EMPTY);
803 aCnt.getPropertyValue(u"DateModified"_ustr) >>= aDateTimeModified;
804 ::utl::typeConvert(aDateTimeModified, aDateTime);
806 return aDateTime;
809 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */