Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / gallery2 / galleryfilestorage.cxx
blob1838520ec60af291d1b6e7ed58ffdd6f31ed2c65
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 <osl/thread.hxx>
28 #include "codec.hxx"
29 #include "gallerydrawmodel.hxx"
30 #include <vcl/cvtgrf.hxx>
31 #include <vcl/filter/SvmWriter.hxx>
33 #include <sal/log.hxx>
35 #include <com/sun/star/ucb/ContentCreationException.hpp>
36 #include <com/sun/star/sdbc/XResultSet.hpp>
37 #include <com/sun/star/ucb/XContentAccess.hpp>
38 #include <comphelper/fileformat.h>
39 #include <comphelper/graphicmimetype.hxx>
40 #include <comphelper/processfactory.hxx>
41 #include <tools/urlobj.hxx>
42 #include <comphelper/diagnose_ex.hxx>
43 #include <tools/datetime.hxx>
44 #include <unotools/datetime.hxx>
45 #include <unotools/ucbstreamhelper.hxx>
46 #include <unotools/streamwrap.hxx>
47 #include <unotools/tempfile.hxx>
48 #include <ucbhelper/content.hxx>
49 #include <tools/vcompat.hxx>
51 using namespace ::com::sun::star;
53 GalleryFileStorage::GalleryFileStorage(
54 const GalleryStorageLocations& rGalleryBinaryStorageLocations,
55 GalleryObjectCollection& rGalleryObjectCollection, bool bReadOnly)
56 : maGalleryStorageLocations(rGalleryBinaryStorageLocations)
57 , mrGalleryObjectCollection(rGalleryObjectCollection)
58 , mbReadOnly(bReadOnly)
59 , m_bDestDirRelative(false)
61 ImplCreateSvDrawStorage();
64 GalleryFileStorage::~GalleryFileStorage() { clearSotStorage(); }
66 void GalleryFileStorage::setDestDir(const OUString& rDestDir, bool bRelative)
68 m_aDestDir = rDestDir;
69 m_bDestDirRelative = bRelative;
72 void GalleryFileStorage::clearSotStorage() { m_aSvDrawStorageRef.clear(); }
74 void GalleryFileStorage::ImplCreateSvDrawStorage()
76 try
78 m_aSvDrawStorageRef
79 = new SotStorage(false, GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
80 mbReadOnly ? StreamMode::READ : StreamMode::STD_READWRITE);
81 // #i50423# ReadOnly may not been set though the file can't be written (because of security reasons)
82 if ((m_aSvDrawStorageRef->GetError() != ERRCODE_NONE) && !mbReadOnly)
83 m_aSvDrawStorageRef = new SotStorage(
84 false, GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
85 StreamMode::READ);
87 catch (const css::ucb::ContentCreationException&)
89 TOOLS_WARN_EXCEPTION("svx", "failed to open: " << GetSdvURL().GetMainURL(
90 INetURLObject::DecodeMechanism::NONE)
91 << "due to");
95 const tools::SvRef<SotStorage>& GalleryFileStorage::GetSvDrawStorage() const
97 return m_aSvDrawStorageRef;
100 bool GalleryFileStorage::implWrite(const GalleryTheme& rTheme, const GalleryThemeEntry* pThm)
102 INetURLObject aPathURL(GetThmURL());
104 aPathURL.removeSegment();
105 aPathURL.removeFinalSlash();
107 DBG_ASSERT(aPathURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
109 if (FileExists(aPathURL) || CreateDir(aPathURL))
111 #ifdef UNX
112 std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
113 GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
114 StreamMode::WRITE | StreamMode::COPY_ON_SYMLINK | StreamMode::TRUNC));
115 #else
116 std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
117 GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
118 StreamMode::WRITE | StreamMode::TRUNC));
119 #endif
121 if (pOStm)
123 writeGalleryTheme(*pOStm, rTheme, pThm);
124 pOStm.reset();
125 return true;
128 return false;
130 return true;
133 void GalleryFileStorage::insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry,
134 sal_uInt32 nInsertPos)
136 if (pFoundEntry)
138 GalleryObject aNewEntry;
140 // update title of new object if necessary
141 if (rObj.GetTitle().isEmpty())
143 std::unique_ptr<SgaObject> pOldObj(implReadSgaObject(pFoundEntry));
145 if (pOldObj)
147 const_cast<SgaObject&>(rObj).SetTitle(pOldObj->GetTitle());
150 else if (rObj.GetTitle() == "__<empty>__")
151 const_cast<SgaObject&>(rObj).SetTitle("");
153 implWriteSgaObject(rObj, nInsertPos, &aNewEntry);
154 pFoundEntry->nOffset = aNewEntry.nOffset;
156 else
157 implWriteSgaObject(rObj, nInsertPos, nullptr);
160 void GalleryFileStorage::removeObject(const std::unique_ptr<GalleryObject>& pEntry)
162 if (mrGalleryObjectCollection.getObjectList().empty())
163 KillFile(GetSdgURL());
165 if (SgaObjKind::SvDraw == pEntry->eObjKind)
166 GetSvDrawStorage()->Remove(
167 pEntry->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE));
170 std::unique_ptr<SgaObject> GalleryFileStorage::implReadSgaObject(GalleryObject const* pEntry)
172 std::unique_ptr<SgaObject> pSgaObj;
174 if (pEntry)
176 std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
177 GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
179 if (pIStm)
181 sal_uInt32 nInventor;
183 // Check to ensure that the file is a valid SGA file
184 pIStm->Seek(pEntry->nOffset);
185 pIStm->ReadUInt32(nInventor);
187 if (nInventor == COMPAT_FORMAT('S', 'G', 'A', '3'))
189 pIStm->Seek(pEntry->nOffset);
191 switch (pEntry->eObjKind)
193 case SgaObjKind::Bitmap:
194 pSgaObj.reset(new SgaObjectBmp());
195 break;
196 case SgaObjKind::Animation:
197 pSgaObj.reset(new SgaObjectAnim());
198 break;
199 case SgaObjKind::Inet:
200 pSgaObj.reset(new SgaObjectINet());
201 break;
202 case SgaObjKind::SvDraw:
203 pSgaObj.reset(new SgaObjectSvDraw());
204 break;
205 case SgaObjKind::Sound:
206 pSgaObj.reset(new SgaObjectSound());
207 break;
209 default:
210 break;
213 if (pSgaObj)
215 ReadSgaObject(*pIStm, *pSgaObj);
216 pSgaObj->ImplUpdateURL(*pEntry->m_oStorageUrl);
222 return pSgaObj;
225 bool GalleryFileStorage::implWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos,
226 GalleryObject* pExistentEntry)
228 std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
229 GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE));
230 bool bRet = false;
232 if (pOStm)
234 const sal_uInt32 nOffset = pOStm->Seek(STREAM_SEEK_TO_END);
236 rObj.WriteData(*pOStm, m_aDestDir);
238 if (!pOStm->GetError())
240 GalleryObject* pEntry;
242 if (!pExistentEntry)
244 pEntry = new GalleryObject;
245 if (nPos < mrGalleryObjectCollection.size())
247 mrGalleryObjectCollection.getObjectList().emplace(
248 mrGalleryObjectCollection.getObjectList().begin() + nPos, pEntry);
250 else
251 mrGalleryObjectCollection.getObjectList().emplace_back(pEntry);
253 else
254 pEntry = pExistentEntry;
256 pEntry->m_oStorageUrl = rObj.GetURL();
258 pEntry->nOffset = nOffset;
259 pEntry->eObjKind = rObj.GetObjKind();
260 bRet = true;
264 return bRet;
267 bool GalleryFileStorage::readModel(const GalleryObject* pObject, SdrModel& rModel)
269 tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage());
270 bool bRet = false;
271 const INetURLObject aURL(ImplGetURL(pObject));
273 if (xSotStorage.is())
275 const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
276 tools::SvRef<SotStorageStream> xInputStream(
277 xSotStorage->OpenSotStream(aStreamName, StreamMode::READ));
279 if (xInputStream.is() && !xInputStream->GetError())
281 xInputStream->SetBufferSize(STREAMBUF_SIZE);
282 bRet = GallerySvDrawImport(*xInputStream, rModel);
283 xInputStream->SetBufferSize(0);
286 return bRet;
289 SgaObjectSvDraw GalleryFileStorage::insertModel(const FmFormModel& rModel,
290 const INetURLObject& rUserURL)
292 INetURLObject aURL(implCreateUniqueURL(SgaObjKind::SvDraw, rUserURL));
293 tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage());
294 bool bRet = false;
296 if (xSotStorage.is())
298 const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
299 tools::SvRef<SotStorageStream> xOutputStream(
300 xSotStorage->OpenSotStream(aStreamName, StreamMode::WRITE | StreamMode::TRUNC));
302 if (xOutputStream.is() && !xOutputStream->GetError())
304 SvMemoryStream aMemoryStream(65535, 65535);
305 FmFormModel* pFormModel = const_cast<FmFormModel*>(&rModel);
307 pFormModel->BurnInStyleSheetAttributes();
310 uno::Reference<io::XOutputStream> xDocOut(
311 new utl::OOutputStreamWrapper(aMemoryStream));
313 if (xDocOut.is())
314 (void)SvxDrawingLayerExport(pFormModel, xDocOut);
317 aMemoryStream.Seek(0);
319 xOutputStream->SetBufferSize(16348);
320 GalleryCodec aCodec(*xOutputStream);
321 aCodec.Write(aMemoryStream);
323 xOutputStream->SetBufferSize(0);
324 xOutputStream->Commit();
325 bRet = !xOutputStream->GetError();
328 if (bRet)
330 SgaObjectSvDraw aObjSvDraw(rModel, aURL);
331 return aObjSvDraw;
333 return SgaObjectSvDraw();
336 bool GalleryFileStorage::readModelStream(const GalleryObject* pObject,
337 tools::SvRef<SotTempStream> const& rxModelStream)
339 const INetURLObject aURL(ImplGetURL(pObject));
340 tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage());
341 bool bRet = false;
343 if (xSotStorage.is())
345 const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
346 tools::SvRef<SotStorageStream> xInputStream(
347 xSotStorage->OpenSotStream(aStreamName, StreamMode::READ));
349 if (xInputStream.is() && !xInputStream->GetError())
351 sal_uInt32 nVersion = 0;
353 xInputStream->SetBufferSize(16348);
355 if (GalleryCodec::IsCoded(*xInputStream, nVersion))
357 SvxGalleryDrawModel aModel;
359 if (aModel.GetModel())
361 if (GallerySvDrawImport(*xInputStream, *aModel.GetModel()))
363 aModel.GetModel()->BurnInStyleSheetAttributes();
366 uno::Reference<io::XOutputStream> xDocOut(
367 new utl::OOutputStreamWrapper(*rxModelStream));
369 SvxDrawingLayerExport(aModel.GetModel(), xDocOut);
373 bRet = (rxModelStream->GetError() == ERRCODE_NONE);
377 xInputStream->SetBufferSize(0);
380 return bRet;
383 SgaObjectSvDraw
384 GalleryFileStorage::insertModelStream(const tools::SvRef<SotTempStream>& rxModelStream,
385 const INetURLObject& rUserURL)
387 INetURLObject aURL(implCreateUniqueURL(SgaObjKind::SvDraw, rUserURL));
388 tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage());
390 if (xSotStorage.is())
392 const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
393 tools::SvRef<SotStorageStream> xOutputStream(
394 xSotStorage->OpenSotStream(aStreamName, StreamMode::WRITE | StreamMode::TRUNC));
396 if (xOutputStream.is() && !xOutputStream->GetError())
398 GalleryCodec aCodec(*xOutputStream);
400 xOutputStream->SetBufferSize(16348);
401 aCodec.Write(*rxModelStream);
403 if (!xOutputStream->GetError())
405 xOutputStream->Seek(0);
406 SgaObjectSvDraw aObjSvDraw(*xOutputStream, aURL);
407 return aObjSvDraw;
411 return SgaObjectSvDraw();
414 INetURLObject GalleryFileStorage::implCreateUniqueURL(SgaObjKind eObjKind,
415 const INetURLObject& rUserURL,
416 ConvertDataFormat nFormat)
418 INetURLObject aDir(rUserURL);
419 INetURLObject aInfoFileURL(rUserURL);
420 INetURLObject aNewURL;
421 sal_uInt32 nNextNumber = 1999;
422 char const* pExt = nullptr;
423 bool bExists;
425 aDir.Append(u"dragdrop");
426 CreateDir(aDir);
428 aInfoFileURL.Append(u"sdddndx1");
430 // read next possible number
431 if (FileExists(aInfoFileURL))
433 std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
434 aInfoFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
436 if (pIStm)
438 pIStm->ReadUInt32(nNextNumber);
442 pExt = comphelper::GraphicMimeTypeHelper::GetExtensionForConvertDataFormat(nFormat);
446 // get URL
447 if (SgaObjKind::SvDraw == eObjKind)
449 OUString aFileName = "gallery/svdraw/dd" + OUString::number(++nNextNumber % 99999999);
450 aNewURL = INetURLObject(aFileName, INetProtocol::PrivSoffice);
452 bExists = false;
454 for (auto const& pObject : mrGalleryObjectCollection.getObjectList())
456 if (*pObject->m_oStorageUrl == aNewURL)
458 bExists = true;
459 break;
463 else
465 OUString aFileName = "dd" + OUString::number(++nNextNumber % 999999);
467 if (pExt)
468 aFileName += OUString(pExt, strlen(pExt), RTL_TEXTENCODING_ASCII_US);
470 aNewURL = aDir;
471 aNewURL.Append(aFileName);
473 bExists = FileExists(aNewURL);
475 } while (bExists);
477 // write updated number
478 std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
479 aInfoFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE));
481 if (pOStm)
483 pOStm->WriteUInt32(nNextNumber);
486 return aNewURL;
489 SgaObjectBmp GalleryFileStorage::insertGraphic(const Graphic& rGraphic, const GfxLink& aGfxLink,
490 const ConvertDataFormat& nExportFormat,
491 const INetURLObject& rUserURL)
493 const INetURLObject aURL(implCreateUniqueURL(SgaObjKind::Bitmap, rUserURL, nExportFormat));
494 std::unique_ptr<SvStream> pOStm(
495 ::utl::UcbStreamHelper::CreateStream(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
496 StreamMode::WRITE | StreamMode::TRUNC));
497 bool bRet = false;
499 if (pOStm)
501 pOStm->SetVersion(SOFFICE_FILEFORMAT_50);
503 if (ConvertDataFormat::SVM == nExportFormat)
505 GDIMetaFile aMtf(rGraphic.GetGDIMetaFile());
507 SvmWriter aWriter(*pOStm);
508 aWriter.Write(aMtf);
509 bRet = (pOStm->GetError() == ERRCODE_NONE);
511 else
513 if (aGfxLink.GetDataSize() && aGfxLink.GetData())
515 pOStm->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize());
516 bRet = (pOStm->GetError() == ERRCODE_NONE);
518 else
519 bRet = (GraphicConverter::Export(*pOStm, rGraphic, nExportFormat) == ERRCODE_NONE);
522 pOStm.reset();
524 if (bRet)
526 const SgaObjectBmp aObjBmp(aURL);
527 return aObjBmp;
529 return SgaObjectBmp();
532 SgaObjectSvDraw GalleryFileStorage::updateSvDrawObject(const GalleryObject* pEntry)
534 if (GetSvDrawStorage().is())
536 const OUString aStmName(GetSvDrawStreamNameFromURL(*pEntry->m_oStorageUrl));
537 tools::SvRef<SotStorageStream> pIStm
538 = GetSvDrawStorage()->OpenSotStream(aStmName, StreamMode::READ);
540 if (pIStm.is() && !pIStm->GetError())
542 pIStm->SetBufferSize(16384);
544 SgaObjectSvDraw aNewObj(*pIStm, *pEntry->m_oStorageUrl);
546 pIStm->SetBufferSize(0);
548 return aNewObj;
551 return SgaObjectSvDraw();
554 void GalleryFileStorage::updateTheme()
556 ::utl::TempFileNamed aTmp;
557 INetURLObject aInURL(GetSdgURL());
558 INetURLObject aTmpURL(aTmp.GetURL());
560 DBG_ASSERT(aInURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
561 DBG_ASSERT(aTmpURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
563 std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
564 aInURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
565 std::unique_ptr<SvStream> pTmpStm(::utl::UcbStreamHelper::CreateStream(
566 aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
567 StreamMode::WRITE | StreamMode::TRUNC));
569 if (pIStm && pTmpStm)
571 for (const auto& i : mrGalleryObjectCollection.getObjectList())
573 GalleryObject* pEntry = i.get();
574 std::unique_ptr<SgaObject> pObj;
576 switch (pEntry->eObjKind)
578 case SgaObjKind::Bitmap:
579 pObj.reset(new SgaObjectBmp());
580 break;
581 case SgaObjKind::Animation:
582 pObj.reset(new SgaObjectAnim());
583 break;
584 case SgaObjKind::Inet:
585 pObj.reset(new SgaObjectINet());
586 break;
587 case SgaObjKind::SvDraw:
588 pObj.reset(new SgaObjectSvDraw());
589 break;
590 case SgaObjKind::Sound:
591 pObj.reset(new SgaObjectSound());
592 break;
594 default:
595 break;
598 if (pObj)
600 pIStm->Seek(pEntry->nOffset);
601 ReadSgaObject(*pIStm, *pObj);
602 pEntry->nOffset = pTmpStm->Tell();
603 WriteSgaObject(*pTmpStm, *pObj);
607 else
609 OSL_FAIL("File(s) could not be opened");
612 pIStm.reset();
613 pTmpStm.reset();
615 CopyFile(aTmpURL, aInURL);
616 KillFile(aTmpURL);
618 ErrCode nStorErr = ERRCODE_NONE;
622 tools::SvRef<SotStorage> aTempStorageRef(
623 new SotStorage(false, aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
624 StreamMode::STD_READWRITE));
625 GetSvDrawStorage()->CopyTo(aTempStorageRef.get());
626 nStorErr = GetSvDrawStorage()->GetError();
628 catch (const css::ucb::ContentCreationException&)
630 TOOLS_WARN_EXCEPTION("svx", "failed to open: "
631 << aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)
632 << "due to");
633 nStorErr = ERRCODE_IO_GENERAL;
636 if (nStorErr == ERRCODE_NONE)
638 clearSotStorage();
639 CopyFile(aTmpURL, GetSdvURL());
640 ImplCreateSvDrawStorage();
643 KillFile(aTmpURL);
646 void GalleryFileStorage::insertFileOrDirURL(const INetURLObject& rFileOrDirURL,
647 std::vector<INetURLObject>& rURLVector)
649 INetURLObject aURL;
652 ::ucbhelper::Content aCnt(rFileOrDirURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
653 uno::Reference<ucb::XCommandEnvironment>(),
654 comphelper::getProcessComponentContext());
655 bool bFolder = false;
657 aCnt.getPropertyValue("IsFolder") >>= bFolder;
659 if (bFolder)
661 uno::Sequence<OUString> aProps{ "Url" };
662 uno::Reference<sdbc::XResultSet> xResultSet(
663 aCnt.createCursor(aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY));
664 uno::Reference<ucb::XContentAccess> xContentAccess(xResultSet, uno::UNO_QUERY);
665 if (xContentAccess.is())
667 while (xResultSet->next())
669 aURL.SetSmartURL(xContentAccess->queryContentIdentifierString());
670 rURLVector.push_back(aURL);
674 else
675 rURLVector.push_back(rFileOrDirURL);
677 catch (const ucb::ContentCreationException&)
680 catch (const uno::RuntimeException&)
683 catch (const uno::Exception&)
688 SvStream& GalleryFileStorage::writeGalleryTheme(SvStream& rOStm, const GalleryTheme& rTheme,
689 const GalleryThemeEntry* pThm)
691 const INetURLObject rRelURL1 = rTheme.GetParent()->GetRelativeURL();
692 const INetURLObject rRelURL2 = rTheme.GetParent()->GetUserURL();
693 const sal_uInt32 rId = rTheme.GetId();
694 sal_uInt32 nCount = mrGalleryObjectCollection.size();
695 bool bRel;
697 rOStm.WriteUInt16(0x0004);
698 write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, pThm->GetThemeName(),
699 RTL_TEXTENCODING_UTF8);
700 rOStm.WriteUInt32(nCount).WriteUInt16(osl_getThreadTextEncoding());
702 for (sal_uInt32 i = 0; i < nCount; i++)
704 const GalleryObject* pObj = mrGalleryObjectCollection.getForPosition(i);
705 OUString aPath;
707 if (SgaObjKind::SvDraw == pObj->eObjKind)
709 aPath = GetSvDrawStreamNameFromURL(*pObj->m_oStorageUrl);
710 bRel = false;
712 else
714 aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
715 aPath = aPath.copy(
716 0, std::min(rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
717 aPath.getLength()));
718 bRel = aPath == rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE);
720 if (bRel
721 && (pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE)
722 .getLength()
723 > (rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength() + 1)))
725 aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
726 aPath = aPath.copy(
727 std::min(rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
728 aPath.getLength()));
730 else
732 aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
733 aPath = aPath.copy(
735 std::min(rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
736 aPath.getLength()));
737 bRel = aPath == rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE);
739 if (bRel
740 && (pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE)
741 .getLength()
742 > (rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength()
743 + 1)))
745 aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
746 aPath = aPath.copy(std::min(
747 rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
748 aPath.getLength()));
750 else
751 aPath = pObj->m_oStorageUrl->GetMainURL(INetURLObject::DecodeMechanism::NONE);
755 if (!m_aDestDir.isEmpty())
757 bool aFound = aPath.indexOf(m_aDestDir) != -1;
758 aPath = aPath.replaceFirst(m_aDestDir, "");
759 if (aFound)
760 bRel = m_bDestDirRelative;
761 else
762 SAL_WARN("svx", "failed to replace destdir of '" << m_aDestDir << "' in '" << aPath
763 << "'");
766 rOStm.WriteBool(bRel);
767 write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aPath, RTL_TEXTENCODING_UTF8);
768 rOStm.WriteUInt32(pObj->nOffset).WriteUInt16(static_cast<sal_uInt16>(pObj->eObjKind));
771 // more recently, a 512-byte reserve buffer is written,
772 // to recognize them two sal_uInt32-Ids will be written.
773 rOStm.WriteUInt32(COMPAT_FORMAT('G', 'A', 'L', 'R'))
774 .WriteUInt32(COMPAT_FORMAT('E', 'S', 'R', 'V'));
776 const sal_uInt64 nReservePos = rOStm.Tell();
777 std::unique_ptr<VersionCompatWrite> pCompat(new VersionCompatWrite(rOStm, 2));
779 rOStm.WriteUInt32(rId).WriteBool(pThm->IsNameFromResource()); // From version 2 and up
781 pCompat.reset();
783 // Fill the rest of the buffer.
784 const tools::Long nRest
785 = std::max(tools::Long(512 - (rOStm.Tell() - nReservePos)), tools::Long(0));
787 if (nRest)
789 std::unique_ptr<char[]> pReserve(new char[nRest]);
790 memset(pReserve.get(), 0, nRest);
791 rOStm.WriteBytes(pReserve.get(), nRest);
794 return rOStm;
797 DateTime GalleryFileStorage::getModificationDate() const
799 ::ucbhelper::Content aCnt(GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
800 uno::Reference<ucb::XCommandEnvironment>(),
801 comphelper::getProcessComponentContext());
802 util::DateTime aDateTimeModified;
803 DateTime aDateTime(DateTime::EMPTY);
805 aCnt.getPropertyValue("DateModified") >>= aDateTimeModified;
806 ::utl::typeConvert(aDateTimeModified, aDateTime);
808 return aDateTime;
811 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */