/* * 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 "cfitem.h" #include "idirectoryentry.h" #include "compoundfile_impl.h" #include using namespace CFCPP; _INT32 CFItem::CompareTo(const CFItem &other) const { return dirEntry.lock()->CompareTo(std::dynamic_pointer_cast(other.dirEntry.lock())); } bool CFItem::operator==(const CFItem &rightItem) const { return CompareTo(rightItem) == 0; } bool CFItem::operator!=(const CFItem &rightItem) const { return CompareTo(rightItem) != 0; } _INT32 CFItem::GetHashCode() const { return dirEntry.lock()->GetHashCode(); } std::wstring CFItem::Name() const { auto name = dirEntry.lock()->GetEntryName(); if (name.empty() == false) { auto removeIter = name.find_last_of(L'\0'); if (removeIter != std::wstring::npos) name.erase(removeIter); return name; } else return L""; } _INT64 CFItem::size() const { return dirEntry.lock()->getSize(); } bool CFItem::IsStorage() const { return dirEntry.lock()->getStgType() == StgType::StgStorage; } bool CFItem::IsStream() const { return dirEntry.lock()->getStgType() == StgType::StgStream; } bool CFItem::ISRoot() const { return dirEntry.lock()->getStgType() == StgType::StgRoot; } DataTime CFItem::getDataTime() const { if (!dirEntry.use_count()) return DataTime(0); return DataTime(dirEntry.lock()->getCreationDate()); } void CFItem::setDataTime(const DataTime &value) { if (!dirEntry.use_count()) return; if (dirEntry.lock()->getStgType() != StgStream && dirEntry.lock()->getStgType() != StgRoot) dirEntry.lock()->setModifyDate(value.getUINT64()); else throw CFException(L"Modify Date can only be set on storage entries"); } _GUID_ CFItem::getStorageCLSID() const { return dirEntry.lock()->getStorageCLSID(); } void CFItem::setStorageCLSID(_GUID_ value) { dirEntry.lock()->setStorageCLSID(value); } std::wstring CFItem::ToString() const { if (!dirEntry.expired()) return L"[" + std::to_wstring(dirEntry.lock()->getLeftSibling()) + L"," + std::to_wstring(dirEntry.lock()->getSid()) + L"," + std::to_wstring(dirEntry.lock()->getRightSibling()) + L"] " + dirEntry.lock()->GetEntryName(); else return L""; } void CFItem::setDirEntry(const std::weak_ptr &newDirEntry) { if (newDirEntry.expired() || newDirEntry.lock()->getSid() < 0) throw CFException("Attempting to create a CFStorage using an unitialized directory"); dirEntry = newDirEntry; } std::shared_ptr CFItem::getDirEntry() const { return dirEntry.lock(); } void CFItem::CheckDisposed() const { if (compoundFile != nullptr && compoundFile->IsClosed()) throw CFDisposedException("Owner Compound file has been closed and owned items have been invalidated"); } DataTime::DataTime(_UINT64 time) { memcpy(data, reinterpret_cast(&time), 8); } _UINT64 DataTime::getUINT64()const { _UINT64 timeStamp(0); memcpy(reinterpret_cast(&timeStamp), data, 8); return timeStamp; }