/* * (c) Copyright Ascensio System SIA 2010-2017 * * This program is a free software product. You can redistribute it and/or * modify it under the terms of the GNU Affero General Public License (AGPL) * version 3 as published by the Free Software Foundation. In accordance with * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect * that Ascensio System SIA expressly excludes the warranty of non-infringement * of any third-party rights. * * This program is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html * * You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, * EU, LV-1021. * * The interactive user interfaces in modified source and object code versions * of the Program must display Appropriate Legal Notices, as required under * Section 5 of the GNU AGPL version 3. * * Pursuant to Section 7(b) of the License you must retain the original Product * logo when distributing the program. Pursuant to Section 7(e) we decline to * grant you any rights under trademark law for use of our trademarks. * * All the Product's GUI elements, including illustrations and icon sets, as * well as technical writing content are licensed under the terms of the * Creative Commons Attribution-ShareAlike 4.0 International. See the License * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode * */ #include "FileContainer.h" #include "FileTypes.h" #include "LegacyDiagramText.h" #include "FileFactory.h" #include "WrapperFile.h" #include "../../Common/DocxFormat/Source/DocxFormat/Rels.h" #include "../../Common/DocxFormat/Source/DocxFormat/ContentTypes.h" #include "../../Common/DocxFormat/Source/DocxFormat/External/HyperLink.h" #include "../../Common/DocxFormat/Source/DocxFormat/FileTypes.h" #include namespace PPTX { void FileContainer::read(const OOX::CPath& filename) { //not implement FileContainer.read } void FileContainer::read(const OOX::CRels& rels, const OOX::CPath& path) { //not implement FileContainer.read } smart_ptr FileContainer::legacyDiagramText(const OOX::RId& rId) const { std::map>::const_iterator pPair = m_mContainer.find(rId.get()); if (pPair == m_mContainer.end ()) return smart_ptr(); return pPair->second.smart_dynamic_cast(); } void FileContainer::read(const OOX::CPath& filename, FileMap& map, IPPTXEvent* Event) { OOX::CRels rels(filename); OOX::CPath path = filename.GetDirectory(); read(rels, path, map, Event); } void FileContainer::read(const OOX::CRels& rels, const OOX::CPath& path, FileMap& map, IPPTXEvent* Event) { bool bIsSlide = false; OOX::File* pSrcFile = dynamic_cast(this); if (NULL != pSrcFile) bIsSlide = (pSrcFile->type() == OOX::Presentation::FileTypes::Slide) ? true : false; size_t nCount = rels.m_arrRelations.size(); for (size_t i = 0; i < nCount; ++i) { const OOX::Rels::CRelationShip* pRelation = rels.m_arrRelations[i]; OOX::CPath normPath = path / pRelation->Target(); std::map>::const_iterator pPair = map.find(normPath); if (bIsSlide && (pRelation->Type() == OOX::Presentation::FileTypes::Slide)) { long percent = Event->GetPercent(); smart_ptr file = smart_ptr(new OOX::HyperLink(pRelation->Target())); bool res = Event->Progress(0, percent + m_lPercent); Add(pRelation->rId(), file); if (res || m_bCancelled) { m_bCancelled = true; break; } } else { if (pPair != map.m_map.end()) { Add(pRelation->rId(), pPair->second); } else { long percent = Event->GetPercent(); smart_ptr file = PPTX::FileFactory::CreateFilePPTX(path, *pRelation, map); map.add(normPath, file); Add(pRelation->rId(), file); smart_ptr pContainer = file.smart_dynamic_cast(); bool res = Event->Progress(0, percent + m_lPercent); if (pContainer.IsInit()) { pContainer->m_lPercent = m_lPercent; Event->AddPercent(m_lPercent); pContainer->read(normPath, map, Event); m_bCancelled = pContainer->m_bCancelled; } //todo детально разобраться и вернуть проверку res.(до перехода на cross platform все было хорошо) //на презентация с hyperlink выходим при достижении 100%. Проценты считаются от количества обработанных файлов, а hyperlink не файл(Ligninger_og_uligheder.pptx) if (m_bCancelled) { m_bCancelled = true; break; } } } } } void FileContainer::write(const OOX::CPath& filename, const OOX::CPath& directory, OOX::CContentTypes& content) const { OOX::CRels rels; OOX::CPath current = filename.GetDirectory(); write(rels, current, directory, content); rels.Write(filename); } void FileContainer::write(OOX::CRels& rels, const OOX::CPath& curdir, const OOX::CPath& directory, OOX::CContentTypes& content) const { std::map mNamePair; for (std::map>::const_iterator pPair = m_mContainer.begin(); pPair != m_mContainer.end(); ++pPair) { smart_ptr pFile = pPair->second; smart_ptr pExt = pFile.smart_dynamic_cast(); if ( !pExt.IsInit() ) { smart_ptr file = pFile.smart_dynamic_cast(); if (file.IsInit()) { if (file->GetWrittenStatus() == false) { OOX::CPath defdir = pFile->DefaultDirectory(); OOX::CPath name = pFile->DefaultFileName(); //name = name + max_name_index(curdir, name.string()); OOX::CSystemUtility::CreateDirectories(directory / defdir); pFile->write(directory / defdir / name, directory, content); rels.Registration(pPair->first, pFile->type(), defdir / name); } else { OOX::CPath defdir = pFile->DefaultDirectory(); OOX::CPath name = file->GetWrittenFileName(); rels.Registration(pPair->first, pFile->type(), defdir / name); } } else { OOX::CPath defdir = pFile->DefaultDirectory(); OOX::CPath name = pFile->DefaultFileName(); OOX::CSystemUtility::CreateDirectories(directory / defdir); pFile->write(directory / defdir / name, directory, content); rels.Registration(pPair->first, pFile->type(), defdir / name); } } else { rels.Registration(pPair->first, pExt); } } } void FileContainer::WrittenSetFalse() { for (std::map>::const_iterator pPair = m_mContainer.begin(); pPair != m_mContainer.end(); ++pPair) { smart_ptr pFile = pPair->second; smart_ptr pWrapFile = pFile.smart_dynamic_cast(); smart_ptr pWrapCont = pFile.smart_dynamic_cast(); if (pWrapFile.is_init() && !pWrapFile->GetWrittenStatus()) { pWrapFile->WrittenSetFalse(); if (pWrapCont.is_init()) { pWrapCont->WrittenSetFalse(); } } } } void CCommonRels::_read(const OOX::CRels& rels, const OOX::CPath& path) { size_t nCount = rels.m_arrRelations.size(); for (size_t i = 0; i < nCount; ++i) { const OOX::Rels::CRelationShip* pRelation = rels.m_arrRelations[i]; smart_ptr _file = PPTX::FileFactory::CreateFilePPTX_OnlyMedia(path, *pRelation); Add(pRelation->rId(), _file); } } void CCommonRels::_read(const OOX::CPath& filename) { OOX::CRels rels(filename); OOX::CPath path = filename.GetDirectory(); _read(rels, path); } } // namespace PPTX