Files
core/OOXML/PPTXFormat/Folder.cpp
Alexander Trofimov 76ee07f61c [copyright] Update copyright header
Co-authored-by: Alexander Trofimov <alexander.trofimov@onlyoffice.com>
Co-committed-by: Alexander Trofimov <alexander.trofimov@onlyoffice.com>
2026-05-14 08:23:56 +00:00

215 lines
7.5 KiB
C++

/*
* Copyright (C) Ascensio System SIA, 2009-2026
*
* 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, together with the
* additional terms provided in the LICENSE file.
*
* 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: https://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA by email at info@onlyoffice.com
* or by postal mail at 20A-6 Ernesta Birznieka-Upisha Street, Riga,
* LV-1050, Latvia, European Union.
*
* The interactive user interfaces in modified versions of the Program
* are required to display Appropriate Legal Notices in accordance with
* Section 5 of the GNU AGPL version 3.
*
* No trademark rights are granted under this License.
*
* All non-code elements of the Product, including illustrations,
* icon sets, and technical writing content, are licensed under the
* Creative Commons Attribution-ShareAlike 4.0 International License:
* https://creativecommons.org/licenses/by-sa/4.0/legalcode
*
* This license applies only to such non-code elements and does not
* modify or replace the licensing terms applicable to the Program's
* source code, which remains licensed under the GNU Affero General
* Public License v3.
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
#include "../DocxFormat/Rels.h"
#include "../DocxFormat/FileTypes.h"
#include "FileTypes.h"
#include "Folder.h"
#include "FileMap.h"
#include "Presentation.h"
#include "Theme.h"
#include "SlideMaster.h"
#include "SlideLayout.h"
#include "Slide.h"
#include "NotesMaster.h"
#include "NotesSlide.h"
#include "HandoutMaster.h"
#include <map>
namespace PPTX
{
Document::Document() : FileContainer(this)
{
}
Document::Document(const OOX::CPath& path) : FileContainer(this)
{
read(path);
}
bool Document::read(const OOX::CPath& path)
{
OOX::CRels rels(path);
PPTX::FileMap map;
long files = CountFiles(path);
if(files == 0)
return false;
m_sDocumentPath = path.GetPath();
FileContainer::read(rels, path, map);
smart_ptr<PPTX::Presentation> _presentation = FileContainer::Get(OOX::Presentation::FileTypes::Presentation).smart_dynamic_cast<PPTX::Presentation>();
if (_presentation.is_init())
{
_presentation->commentAuthors = _presentation->Get(OOX::Presentation::FileTypes::CommentAuthors).smart_dynamic_cast<PPTX::Authors>();
if (false == _presentation->commentAuthors.IsInit())
{
_presentation->commentAuthors = _presentation->Get(OOX::Presentation::FileTypes::ModernCommentAuthors).smart_dynamic_cast<PPTX::Authors>();
}
if (_presentation->IsExist(OOX::FileTypes::VbaProject))
{
_presentation->m_bMacroEnabled = true;
_presentation->m_pVbaProject = _presentation->Get(OOX::FileTypes::VbaProject).smart_dynamic_cast<OOX::VbaProject>();
}
if (_presentation->IsExist(OOX::FileTypes::JsaProject))
{
_presentation->m_pJsaProject = _presentation->Get(OOX::FileTypes::JsaProject).smart_dynamic_cast<OOX::JsaProject>();
}
_presentation->comments = _presentation->Get(OOX::Presentation::FileTypes::SlideComments).smart_dynamic_cast<PPTX::Comments>();
}
for (std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair)
{
const OOX::FileType& curType = pPair->second->type();
if (OOX::FileTypes::Theme == curType)
{
smart_ptr<PPTX::Theme> pTheme = pPair->second.smart_dynamic_cast<PPTX::Theme>();
if (pTheme.IsInit())
pTheme->presentation = _presentation;
}
}
for (std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair)
{
const OOX::FileType& curType = pPair->second->type();
if (OOX::Presentation::FileTypes::SlideMaster == curType)
{
smart_ptr<PPTX::SlideMaster> pointer = pPair->second.smart_dynamic_cast<PPTX::SlideMaster>();
if (pointer.is_init())
pointer->ApplyRels();
}
}
for (std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair)
{
const OOX::FileType& curType = pPair->second->type();
if (OOX::Presentation::FileTypes::SlideLayout == curType)
{
smart_ptr<PPTX::SlideLayout> pointer = pPair->second.smart_dynamic_cast<PPTX::SlideLayout>();
if (pointer.is_init())
pointer->ApplyRels();
}
}
for (std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair)
{
const OOX::FileType& curType = pPair->second->type();
if (OOX::Presentation::FileTypes::Slide == curType)
{
smart_ptr<PPTX::Slide> pointer = pPair->second.smart_dynamic_cast<PPTX::Slide>();
if (pointer.is_init())
pointer->ApplyRels();
}
}
for (std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair)
{
const OOX::FileType& curType = pPair->second->type();
if (OOX::Presentation::FileTypes::NotesMaster == curType)
{
smart_ptr<PPTX::NotesMaster> pointer = pPair->second.smart_dynamic_cast<PPTX::NotesMaster>();
if (pointer.is_init())
pointer->ApplyRels();
}
}
for (std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair)
{
const OOX::FileType& curType = pPair->second->type();
if (OOX::Presentation::FileTypes::HandoutMaster == curType)
{
smart_ptr<PPTX::HandoutMaster> pointer = pPair->second.smart_dynamic_cast<PPTX::HandoutMaster>();
if (pointer.is_init())
pointer->ApplyRels();
}
}
for (std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair)
{
const OOX::FileType& curType = pPair->second->type();
if (OOX::Presentation::FileTypes::NotesSlide == curType)
{
smart_ptr<PPTX::NotesSlide> pointer = pPair->second.smart_dynamic_cast<PPTX::NotesSlide>();
if (pointer.is_init())
pointer->ApplyRels();
}
}
return true;
}
void Document::write(const OOX::CPath& path)
{
OOX::CSystemUtility::CreateDirectories(path);
OOX::CRels rels;
OOX::CContentTypes content;
OOX::CPath dir = path;
FileContainer::write(rels, path, dir, content);
rels.Write(path / FILE_SEPARATOR_STR);
content.Write(path);
FileContainer::WrittenSetFalse();
}
void Document::createFromTemplate(const OOX::CPath& path)
{
//read(path);
}
const bool Document::isValid(const OOX::CPath& path) const
{
return true;//FileContainer::exist(OOX::Presentation::FileTypes::Presentation);
}
long Document::CountFiles(const OOX::CPath& path)
{
return OOX::CSystemUtility::GetFilesCount(path.GetDirectory(), true);
}
} // namespace PPTX