LibreOffice Module svx (master)  1
gallerybinaryengine.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <svx/unomodel.hxx>
21 #include <svx/fmmodel.hxx>
22 #include <galobj.hxx>
25 #include <svx/gallery1.hxx>
27 #include <osl/thread.hxx>
28 #include "codec.hxx"
29 #include "gallerydrawmodel.hxx"
30 #include <vcl/cvtgrf.hxx>
31 #include <sot/formats.hxx>
32 
33 #include <sal/log.hxx>
34 
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>
41 #include <tools/urlobj.hxx>
42 #include <tools/diagnose_ex.h>
43 #include <tools/datetime.hxx>
44 #include <unotools/datetime.hxx>
46 #include <unotools/streamwrap.hxx>
47 #include <unotools/tempfile.hxx>
48 #include <ucbhelper/content.hxx>
49 #include <tools/vcompat.hxx>
50 
51 using namespace ::com::sun::star;
52 
54  const GalleryBinaryStorageLocations& rGalleryBinaryStorageLocations,
55  GalleryObjectCollection& rGalleryObjectCollection, bool bReadOnly)
56  : maGalleryStorageLocations(rGalleryBinaryStorageLocations)
57  , mrGalleryObjectCollection(rGalleryObjectCollection)
58  , mbReadOnly(bReadOnly)
59  , m_bDestDirRelative(false)
60 {
62 }
63 
65 
66 void GalleryBinaryEngine::setDestDir(const OUString& rDestDir, bool bRelative)
67 {
68  m_aDestDir = rDestDir;
69  m_bDestDirRelative = bRelative;
70 }
71 
73 
75 {
76  try
77  {
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)
85  StreamMode::READ);
86  }
87  catch (const css::ucb::ContentCreationException&)
88  {
89  TOOLS_WARN_EXCEPTION("svx", "failed to open: " << GetSdvURL().GetMainURL(
91  << "due to");
92  }
93 }
94 
96 {
97  return m_aSvDrawStorageRef;
98 }
99 
101 {
102  INetURLObject aPathURL(GetThmURL());
103 
104  aPathURL.removeSegment();
105  aPathURL.removeFinalSlash();
106 
107  DBG_ASSERT(aPathURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
108 
109  if (FileExists(aPathURL) || CreateDir(aPathURL))
110  {
111 #ifdef UNX
112  std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
114  StreamMode::WRITE | StreamMode::COPY_ON_SYMLINK | StreamMode::TRUNC));
115 #else
116  std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
118  StreamMode::WRITE | StreamMode::TRUNC));
119 #endif
120 
121  if (pOStm)
122  {
123  writeGalleryTheme(*pOStm, rTheme, pThm);
124  pOStm.reset();
125  return true;
126  }
127 
128  return false;
129  }
130  return true;
131 }
132 
133 void GalleryBinaryEngine::insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry,
134  sal_uInt32 nInsertPos)
135 {
136  if (pFoundEntry)
137  {
138  GalleryObject aNewEntry;
139 
140  // update title of new object if necessary
141  if (rObj.GetTitle().isEmpty())
142  {
143  std::unique_ptr<SgaObject> pOldObj(implReadSgaObject(pFoundEntry));
144 
145  if (pOldObj)
146  {
147  const_cast<SgaObject&>(rObj).SetTitle(pOldObj->GetTitle());
148  }
149  }
150  else if (rObj.GetTitle() == "__<empty>__")
151  const_cast<SgaObject&>(rObj).SetTitle("");
152 
153  implWriteSgaObject(rObj, nInsertPos, &aNewEntry);
154  pFoundEntry->nOffset = aNewEntry.nOffset;
155  }
156  else
157  implWriteSgaObject(rObj, nInsertPos, nullptr);
158 }
159 
160 void GalleryBinaryEngine::removeObject(const std::unique_ptr<GalleryObject>& pEntry)
161 {
163  KillFile(GetSdgURL());
164 
165  if (SgaObjKind::SvDraw == pEntry->eObjKind)
166  GetSvDrawStorage()->Remove(
167  pEntry->getURL().GetMainURL(INetURLObject::DecodeMechanism::NONE));
168 }
169 
170 std::unique_ptr<SgaObject> GalleryBinaryEngine::implReadSgaObject(GalleryObject const* pEntry)
171 {
172  std::unique_ptr<SgaObject> pSgaObj;
173 
174  if (pEntry)
175  {
176  std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
177  GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
178 
179  if (pIStm)
180  {
181  sal_uInt32 nInventor;
182 
183  // Check to ensure that the file is a valid SGA file
184  pIStm->Seek(pEntry->nOffset);
185  pIStm->ReadUInt32(nInventor);
186 
187  if (nInventor == COMPAT_FORMAT('S', 'G', 'A', '3'))
188  {
189  pIStm->Seek(pEntry->nOffset);
190 
191  switch (pEntry->eObjKind)
192  {
193  case SgaObjKind::Bitmap:
194  pSgaObj.reset(new SgaObjectBmp());
195  break;
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;
208 
209  default:
210  break;
211  }
212 
213  if (pSgaObj)
214  {
215  ReadSgaObject(*pIStm, *pSgaObj);
216  pSgaObj->ImplUpdateURL(pEntry->getURL());
217  }
218  }
219  }
220  }
221 
222  return pSgaObj;
223 }
224 
225 bool GalleryBinaryEngine::implWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos,
226  GalleryObject* pExistentEntry)
227 {
228  std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
229  GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE));
230  bool bRet = false;
231 
232  if (pOStm)
233  {
234  const sal_uInt32 nOffset = pOStm->Seek(STREAM_SEEK_TO_END);
235 
236  rObj.WriteData(*pOStm, m_aDestDir);
237 
238  if (!pOStm->GetError())
239  {
240  GalleryObject* pEntry;
241 
242  if (!pExistentEntry)
243  {
244  pEntry = new GalleryObject;
245  if (nPos < mrGalleryObjectCollection.size())
246  {
248  mrGalleryObjectCollection.getObjectList().begin() + nPos, pEntry);
249  }
250  else
251  mrGalleryObjectCollection.getObjectList().emplace_back(pEntry);
252  }
253  else
254  pEntry = pExistentEntry;
255 
256  pEntry->m_pGalleryObjectStorage = std::make_unique<GalleryObjectBinaryStorage>();
257  pEntry->m_pGalleryObjectStorage->setURL(rObj.GetURL());
258 
259  pEntry->nOffset = nOffset;
260  pEntry->eObjKind = rObj.GetObjKind();
261  bRet = true;
262  }
263  }
264 
265  return bRet;
266 }
267 
269 {
271  bool bRet = false;
272  const INetURLObject aURL(ImplGetURL(pObject));
273 
274  if (xSotStorage.is())
275  {
276  const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
277  tools::SvRef<SotStorageStream> xInputStream(
278  xSotStorage->OpenSotStream(aStreamName, StreamMode::READ));
279 
280  if (xInputStream.is() && !xInputStream->GetError())
281  {
282  xInputStream->SetBufferSize(STREAMBUF_SIZE);
283  bRet = GallerySvDrawImport(*xInputStream, rModel);
284  xInputStream->SetBufferSize(0);
285  }
286  }
287  return bRet;
288 }
289 
291  const INetURLObject& rUserURL)
292 {
295  bool bRet = false;
296 
297  if (xSotStorage.is())
298  {
299  const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
300  tools::SvRef<SotStorageStream> xOutputStream(
301  xSotStorage->OpenSotStream(aStreamName, StreamMode::WRITE | StreamMode::TRUNC));
302 
303  if (xOutputStream.is() && !xOutputStream->GetError())
304  {
305  SvMemoryStream aMemoryStream(65535, 65535);
306  FmFormModel* pFormModel = const_cast<FmFormModel*>(&rModel);
307 
308  pFormModel->BurnInStyleSheetAttributes();
309 
310  {
311  uno::Reference<io::XOutputStream> xDocOut(
312  new utl::OOutputStreamWrapper(aMemoryStream));
313 
314  if (xDocOut.is())
315  (void)SvxDrawingLayerExport(pFormModel, xDocOut);
316  }
317 
318  aMemoryStream.Seek(0);
319 
320  xOutputStream->SetBufferSize(16348);
321  GalleryCodec aCodec(*xOutputStream);
322  aCodec.Write(aMemoryStream);
323 
324  xOutputStream->SetBufferSize(0);
325  xOutputStream->Commit();
326  bRet = !xOutputStream->GetError();
327  }
328  }
329  if (bRet)
330  {
331  SgaObjectSvDraw aObjSvDraw(rModel, aURL);
332  return aObjSvDraw;
333  }
334  return SgaObjectSvDraw();
335 }
336 
338  tools::SvRef<SotStorageStream> const& rxModelStream)
339 {
340  const INetURLObject aURL(ImplGetURL(pObject));
342  bool bRet = false;
343 
344  if (xSotStorage.is())
345  {
346  const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
347  tools::SvRef<SotStorageStream> xInputStream(
348  xSotStorage->OpenSotStream(aStreamName, StreamMode::READ));
349 
350  if (xInputStream.is() && !xInputStream->GetError())
351  {
352  sal_uInt32 nVersion = 0;
353 
354  xInputStream->SetBufferSize(16348);
355 
356  if (GalleryCodec::IsCoded(*xInputStream, nVersion))
357  {
358  SvxGalleryDrawModel aModel;
359 
360  if (aModel.GetModel())
361  {
362  if (GallerySvDrawImport(*xInputStream, *aModel.GetModel()))
363  {
365 
366  {
367  uno::Reference<io::XOutputStream> xDocOut(
368  new utl::OOutputStreamWrapper(*rxModelStream));
369 
370  if (SvxDrawingLayerExport(aModel.GetModel(), xDocOut))
371  rxModelStream->Commit();
372  }
373  }
374 
375  bRet = (rxModelStream->GetError() == ERRCODE_NONE);
376  }
377  }
378 
379  xInputStream->SetBufferSize(0);
380  }
381  }
382  return bRet;
383 }
384 
387  const INetURLObject& rUserURL)
388 {
391 
392  if (xSotStorage.is())
393  {
394  const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL));
395  tools::SvRef<SotStorageStream> xOutputStream(
396  xSotStorage->OpenSotStream(aStreamName, StreamMode::WRITE | StreamMode::TRUNC));
397 
398  if (xOutputStream.is() && !xOutputStream->GetError())
399  {
400  GalleryCodec aCodec(*xOutputStream);
401 
402  xOutputStream->SetBufferSize(16348);
403  aCodec.Write(*rxModelStream);
404 
405  if (!xOutputStream->GetError())
406  {
407  xOutputStream->Seek(0);
408  SgaObjectSvDraw aObjSvDraw(*xOutputStream, aURL);
409  return aObjSvDraw;
410  }
411  }
412  }
413  return SgaObjectSvDraw();
414 }
415 
417  const INetURLObject& rUserURL,
418  ConvertDataFormat nFormat)
419 {
420  INetURLObject aDir(rUserURL);
421  INetURLObject aInfoFileURL(rUserURL);
422  INetURLObject aNewURL;
423  sal_uInt32 nNextNumber = 1999;
424  char const* pExt = nullptr;
425  bool bExists;
426 
427  aDir.Append("dragdrop");
428  CreateDir(aDir);
429 
430  aInfoFileURL.Append("sdddndx1");
431 
432  // read next possible number
433  if (FileExists(aInfoFileURL))
434  {
435  std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
436  aInfoFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
437 
438  if (pIStm)
439  {
440  pIStm->ReadUInt32(nNextNumber);
441  }
442  }
443 
445 
446  do
447  {
448  // get URL
449  if (SgaObjKind::SvDraw == eObjKind)
450  {
451  OUString aFileName = "gallery/svdraw/dd" + OUString::number(++nNextNumber % 99999999);
452  aNewURL = INetURLObject(aFileName, INetProtocol::PrivSoffice);
453 
454  bExists = false;
455 
456  for (auto const& pObject : mrGalleryObjectCollection.getObjectList())
457  {
458  if (pObject->getURL() == aNewURL)
459  {
460  bExists = true;
461  break;
462  }
463  }
464  }
465  else
466  {
467  OUString aFileName = "dd" + OUString::number(++nNextNumber % 999999);
468 
469  if (pExt)
470  aFileName += OUString(pExt, strlen(pExt), RTL_TEXTENCODING_ASCII_US);
471 
472  aNewURL = aDir;
473  aNewURL.Append(aFileName);
474 
475  bExists = FileExists(aNewURL);
476  }
477  } while (bExists);
478 
479  // write updated number
480  std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
481  aInfoFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE));
482 
483  if (pOStm)
484  {
485  pOStm->WriteUInt32(nNextNumber);
486  }
487 
488  return aNewURL;
489 }
490 
492  const ConvertDataFormat& nExportFormat,
493  const INetURLObject& rUserURL)
494 {
495  const INetURLObject aURL(implCreateUniqueURL(SgaObjKind::Bitmap, rUserURL, nExportFormat));
496  std::unique_ptr<SvStream> pOStm(
498  StreamMode::WRITE | StreamMode::TRUNC));
499  bool bRet = false;
500 
501  if (pOStm)
502  {
503  pOStm->SetVersion(SOFFICE_FILEFORMAT_50);
504 
505  if (ConvertDataFormat::SVM == nExportFormat)
506  {
507  GDIMetaFile aMtf(rGraphic.GetGDIMetaFile());
508 
509  aMtf.Write(*pOStm);
510  bRet = (pOStm->GetError() == ERRCODE_NONE);
511  }
512  else
513  {
514  if (aGfxLink.GetDataSize() && aGfxLink.GetData())
515  {
516  pOStm->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize());
517  bRet = (pOStm->GetError() == ERRCODE_NONE);
518  }
519  else
520  bRet = (GraphicConverter::Export(*pOStm, rGraphic, nExportFormat) == ERRCODE_NONE);
521  }
522 
523  pOStm.reset();
524  }
525  if (bRet)
526  {
527  const SgaObjectBmp aObjBmp(aURL);
528  return aObjBmp;
529  }
530  return SgaObjectBmp();
531 }
532 
534 {
535  if (GetSvDrawStorage().is())
536  {
537  const OUString aStmName(GetSvDrawStreamNameFromURL(pEntry->getURL()));
539  = GetSvDrawStorage()->OpenSotStream(aStmName, StreamMode::READ);
540 
541  if (pIStm.is() && !pIStm->GetError())
542  {
543  pIStm->SetBufferSize(16384);
544 
545  SgaObjectSvDraw aNewObj(*pIStm, pEntry->getURL());
546 
547  pIStm->SetBufferSize(0);
548 
549  return aNewObj;
550  }
551  }
552  return SgaObjectSvDraw();
553 }
554 
556 {
557  ::utl::TempFile aTmp;
558  INetURLObject aInURL(GetSdgURL());
559  INetURLObject aTmpURL(aTmp.GetURL());
560 
561  DBG_ASSERT(aInURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
562  DBG_ASSERT(aTmpURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
563 
564  std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
565  aInURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
566  std::unique_ptr<SvStream> pTmpStm(::utl::UcbStreamHelper::CreateStream(
567  aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
568  StreamMode::WRITE | StreamMode::TRUNC));
569 
570  if (pIStm && pTmpStm)
571  {
572  for (const auto& i : mrGalleryObjectCollection.getObjectList())
573  {
574  GalleryObject* pEntry = i.get();
575  std::unique_ptr<SgaObject> pObj;
576 
577  switch (pEntry->eObjKind)
578  {
579  case SgaObjKind::Bitmap:
580  pObj.reset(new SgaObjectBmp());
581  break;
583  pObj.reset(new SgaObjectAnim());
584  break;
585  case SgaObjKind::Inet:
586  pObj.reset(new SgaObjectINet());
587  break;
588  case SgaObjKind::SvDraw:
589  pObj.reset(new SgaObjectSvDraw());
590  break;
591  case SgaObjKind::Sound:
592  pObj.reset(new SgaObjectSound());
593  break;
594 
595  default:
596  break;
597  }
598 
599  if (pObj)
600  {
601  pIStm->Seek(pEntry->nOffset);
602  ReadSgaObject(*pIStm, *pObj);
603  pEntry->nOffset = pTmpStm->Tell();
604  WriteSgaObject(*pTmpStm, *pObj);
605  }
606  }
607  }
608  else
609  {
610  OSL_FAIL("File(s) could not be opened");
611  }
612 
613  pIStm.reset();
614  pTmpStm.reset();
615 
616  CopyFile(aTmpURL, aInURL);
617  KillFile(aTmpURL);
618 
619  ErrCode nStorErr = ERRCODE_NONE;
620 
621  try
622  {
623  tools::SvRef<SotStorage> aTempStorageRef(
624  new SotStorage(false, aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),
625  StreamMode::STD_READWRITE));
626  GetSvDrawStorage()->CopyTo(aTempStorageRef.get());
627  nStorErr = GetSvDrawStorage()->GetError();
628  }
629  catch (const css::ucb::ContentCreationException&)
630  {
631  TOOLS_WARN_EXCEPTION("svx", "failed to open: "
632  << aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)
633  << "due to");
634  nStorErr = ERRCODE_IO_GENERAL;
635  }
636 
637  if (nStorErr == ERRCODE_NONE)
638  {
639  clearSotStorage();
640  CopyFile(aTmpURL, GetSdvURL());
642  }
643 
644  KillFile(aTmpURL);
645 }
646 
648  std::vector<INetURLObject>& rURLVector)
649 {
651  try
652  {
654  uno::Reference<ucb::XCommandEnvironment>(),
656  bool bFolder = false;
657 
658  aCnt.getPropertyValue("IsFolder") >>= bFolder;
659 
660  if (bFolder)
661  {
662  uno::Sequence<OUString> aProps{ "Url" };
663  uno::Reference<sdbc::XResultSet> xResultSet(
664  aCnt.createCursor(aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY));
665  uno::Reference<ucb::XContentAccess> xContentAccess(xResultSet, uno::UNO_QUERY);
666  if (xContentAccess.is())
667  {
668  while (xResultSet->next())
669  {
670  aURL.SetSmartURL(xContentAccess->queryContentIdentifierString());
671  rURLVector.push_back(aURL);
672  }
673  }
674  }
675  else
676  rURLVector.push_back(rFileOrDirURL);
677  }
678  catch (const ucb::ContentCreationException&)
679  {
680  }
681  catch (const uno::RuntimeException&)
682  {
683  }
684  catch (const uno::Exception&)
685  {
686  }
687 }
688 
690  const GalleryThemeEntry* pThm)
691 {
692  const INetURLObject rRelURL1 = rTheme.GetParent()->GetRelativeURL();
693  const INetURLObject rRelURL2 = rTheme.GetParent()->GetUserURL();
694  const sal_uInt32 rId = rTheme.GetId();
695  sal_uInt32 nCount = mrGalleryObjectCollection.size();
696  bool bRel;
697 
698  rOStm.WriteUInt16(0x0004);
700  RTL_TEXTENCODING_UTF8);
701  rOStm.WriteUInt32(nCount).WriteUInt16(osl_getThreadTextEncoding());
702 
703  for (sal_uInt32 i = 0; i < nCount; i++)
704  {
706  OUString aPath;
707 
708  if (SgaObjKind::SvDraw == pObj->eObjKind)
709  {
710  aPath = GetSvDrawStreamNameFromURL(pObj->getURL());
711  bRel = false;
712  }
713  else
714  {
716  aPath = aPath.copy(
717  0, std::min(rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
718  aPath.getLength()));
719  bRel = aPath == rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE);
720 
721  if (bRel
723  > (rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength() + 1)))
724  {
726  aPath = aPath.copy(
727  std::min(rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
728  aPath.getLength()));
729  }
730  else
731  {
733  aPath = aPath.copy(
734  0,
735  std::min(rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
736  aPath.getLength()));
737  bRel = aPath == rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE);
738 
739  if (bRel
741  > (rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength()
742  + 1)))
743  {
745  aPath = aPath.copy(std::min(
746  rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(),
747  aPath.getLength()));
748  }
749  else
751  }
752  }
753 
754  if (!m_aDestDir.isEmpty())
755  {
756  bool aFound = aPath.indexOf(m_aDestDir) != -1;
757  aPath = aPath.replaceFirst(m_aDestDir, "");
758  if (aFound)
759  bRel = m_bDestDirRelative;
760  else
761  SAL_WARN("svx", "failed to replace destdir of '" << m_aDestDir << "' in '" << aPath
762  << "'");
763  }
764 
765  rOStm.WriteBool(bRel);
766  write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aPath, RTL_TEXTENCODING_UTF8);
767  rOStm.WriteUInt32(pObj->nOffset).WriteUInt16(static_cast<sal_uInt16>(pObj->eObjKind));
768  }
769 
770  // more recently, a 512-byte reserve buffer is written,
771  // to recognize them two sal_uInt32-Ids will be written.
772  rOStm.WriteUInt32(COMPAT_FORMAT('G', 'A', 'L', 'R'))
773  .WriteUInt32(COMPAT_FORMAT('E', 'S', 'R', 'V'));
774 
775  const tools::Long nReservePos = rOStm.Tell();
776  std::unique_ptr<VersionCompat> pCompat(new VersionCompat(rOStm, StreamMode::WRITE, 2));
777 
778  rOStm.WriteUInt32(rId).WriteBool(pThm->IsNameFromResource()); // From version 2 and up
779 
780  pCompat.reset();
781 
782  // Fill the rest of the buffer.
783  const tools::Long nRest
784  = std::max(tools::Long(512 - (rOStm.Tell() - nReservePos)), tools::Long(0));
785 
786  if (nRest)
787  {
788  std::unique_ptr<char[]> pReserve(new char[nRest]);
789  memset(pReserve.get(), 0, nRest);
790  rOStm.WriteBytes(pReserve.get(), nRest);
791  }
792 
793  return rOStm;
794 }
795 
797 {
799  uno::Reference<ucb::XCommandEnvironment>(),
801  util::DateTime aDateTimeModified;
802  DateTime aDateTime(DateTime::EMPTY);
803 
804  aCnt.getPropertyValue("DateModified") >>= aDateTimeModified;
805  ::utl::typeConvert(aDateTimeModified, aDateTime);
806 
807  return aDateTime;
808 }
809 
810 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvStream & WriteBool(bool b)
bool readModelStream(const GalleryObject *pObject, tools::SvRef< SotStorageStream > const &rxModelStream)
bool is() const
URL aURL
sal_uInt32 GetId() const
Definition: galtheme.cxx:785
SvStream & WriteUInt16(sal_uInt16 nUInt16)
SvStream & ReadSgaObject(SvStream &rIn, SgaObject &rObj)
Definition: galobj.cxx:238
SAL_DLLPRIVATE Gallery * GetParent() const
Definition: galtheme.hxx:119
std::vector< std::unique_ptr< GalleryObject > > & getObjectList()
SgaObjectSvDraw insertModel(const FmFormModel &rModel, const INetURLObject &rUserURL)
bool SvxDrawingLayerExport(SdrModel *pModel, const uno::Reference< io::XOutputStream > &xOut, const Reference< lang::XComponent > &xComponent)
Definition: xmlexport.cxx:42
SgaObjectBmp insertGraphic(const Graphic &rGraphic, const GfxLink &aGfxLink, const ConvertDataFormat &nExportFormat, const INetURLObject &rUserURL)
long Long
css::uno::Any getPropertyValue(const OUString &rPropertyName)
#define STREAM_SEEK_TO_END
SAL_DLLPRIVATE const INetURLObject & GetRelativeURL() const
Definition: gallery1.hxx:141
const INetURLObject & getURL() const
sal_uInt64 Seek(sal_uInt64 nPos)
SvStream & WriteSgaObject(SvStream &rOut, const SgaObject &rObj)
Definition: galobj.cxx:232
FmFormModel * GetModel() const
SgaObjectSvDraw insertModelStream(const tools::SvRef< SotStorageStream > &rxModelStream, const INetURLObject &rUserURL)
bool bReadOnly
EmbeddedObjectRef * pObject
void BurnInStyleSheetAttributes()
Definition: svdmodel.cxx:824
DateTime getModificationDate() const
bool CreateDir(const INetURLObject &rURL)
Definition: galmisc.cxx:227
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
INetURLObject ImplGetURL(const GalleryObject *pObject)
Definition: galmisc.cxx:554
bool implWriteSgaObject(const SgaObject &rObj, sal_uInt32 nPos, GalleryObject *pExistentEntry)
int nCount
const GDIMetaFile & GetGDIMetaFile() const
SvStream & WriteUInt32(sal_uInt32 nUInt32)
tools::SvRef< SotStorage > m_aSvDrawStorageRef
void insertObject(const SgaObject &rObj, GalleryObject *pFoundEntry, sal_uInt32 nInsertPos)
const INetURLObject & GetSdvURL() const
SgaObjKind
Definition: galmisc.hxx:55
T * get() const
const INetURLObject & GetThmURL() const
#define SOFFICE_FILEFORMAT_50
#define TOOLS_WARN_EXCEPTION(area, stream)
SAL_DLLPRIVATE const INetURLObject & GetUserURL() const
Definition: gallery1.hxx:140
#define ERRCODE_IO_GENERAL
#define DBG_ASSERT(sCon, aError)
int i
bool Append(OUString const &rTheSegment, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
OUString const & GetURL() const
static void insertFileOrDirURL(const INetURLObject &rFileOrDirURL, std::vector< INetURLObject > &rURLVector)
sal_uInt32 COMPAT_FORMAT(char char1, char char2, char char3, char char4)
SvStream & writeGalleryTheme(SvStream &rOStm, const GalleryTheme &rTheme, const GalleryThemeEntry *pThm)
ConvertDataFormat
void removeObject(const std::unique_ptr< GalleryObject > &pEntry)
std::size_t WriteBytes(const void *pData, std::size_t nSize)
bool removeFinalSlash()
sal_Int16 nVersion
bool KillFile(const INetURLObject &rURL)
Definition: galmisc.cxx:288
bool GallerySvDrawImport(SvStream &rIStm, SdrModel &rModel)
Definition: galmisc.cxx:76
bool IsNameFromResource() const
Definition: gallery1.hxx:75
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool CopyFile(const INetURLObject &rSrcURL, const INetURLObject &rDstURL)
Definition: galmisc.cxx:262
static ErrCode Export(SvStream &rOStm, const Graphic &rGraphic, ConvertDataFormat nFormat)
static bool FileExists(const INetURLObject &rURL, const OUString &rExt)
void setDestDir(const OUString &rDestDir, bool bRelative)
#define ERRCODE_NONE
bool readModel(const GalleryObject *pObject, SdrModel &rModel)
INetProtocol GetProtocol() const
const GalleryObject * getForPosition(sal_uInt32 nPos) const
SAL_DLLPRIVATE void ImplCreateSvDrawStorage()
const INetURLObject & GetSdgURL() const
void Write(SvStream &rStmToWrite)
Definition: codec.cxx:60
sal_uInt64 Tell() const
Reference< XComponentContext > getProcessComponentContext()
SAL_DLLPRIVATE bool implWrite(const GalleryTheme &rTheme, const GalleryThemeEntry *pThm)
static bool IsCoded(SvStream &rStm, sal_uInt32 &rVersion)
Definition: codec.cxx:36
#define SAL_WARN(area, stream)
OUString GetSvDrawStreamNameFromURL(const INetURLObject &rSvDrawObjURL)
Definition: galmisc.cxx:186
SgaObjectSvDraw updateSvDrawObject(const GalleryObject *pEntry)
GalleryBinaryEngine(const GalleryBinaryStorageLocations &rGalleryStorageLocations, GalleryObjectCollection &rGalleryObjectCollection, bool bReadOnly)
std::unique_ptr< GalleryObjectStorage > m_pGalleryObjectStorage
static char const * GetExtensionForConvertDataFormat(ConvertDataFormat nFormat)
std::size_t write_uInt16_lenPrefixed_uInt8s_FromOUString(SvStream &rStrm, const OUString &rStr, rtl_TextEncoding eEnc)
const char * pExt
Definition: xtable.cxx:371
std::unique_ptr< SgaObject > implReadSgaObject(GalleryObject const *pEntry)
#define STREAMBUF_SIZE
Definition: galmisc.hxx:67
INCLUDE_DOCUMENTS_ONLY
const OUString & GetThemeName() const
Definition: gallery1.hxx:64
INetURLObject implCreateUniqueURL(SgaObjKind eObjKind, const INetURLObject &rUserURL, ConvertDataFormat nFormat=ConvertDataFormat::Unknown)
SAL_DLLPRIVATE const tools::SvRef< SotStorage > & GetSvDrawStorage() const
SvStream & Write(SvStream &rOStm)
SAL_DLLPRIVATE ~GalleryBinaryEngine()
bool SetSmartURL(OUString const &rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
GalleryObjectCollection & mrGalleryObjectCollection
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)