#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License // If the library is compiled as a DLL, this ensures symbols are exported #define NUCLEX_STORAGE_SOURCE 1 #include "ZipArchiveContainer.h" #include "ZippedFile.h" #include "ZippedContainer.h" #include "Nuclex/Storage/FileSystem/File.h" #include "Format/GeneralPurposeFlags.h" #include "ZipDirectoryReader.h" namespace Nuclex { namespace Storage { namespace FileSystem { namespace Zip { // ------------------------------------------------------------------------------------------- // ZipArchiveContainer::ZipArchiveContainer( const std::shared_ptr &codecs, const std::shared_ptr &zipFile ) : Container(codecs), zipFile(zipFile), rootContainer(nullptr) {} // ------------------------------------------------------------------------------------------- // ZipArchiveContainer::~ZipArchiveContainer() {} // ------------------------------------------------------------------------------------------- // const std::string &ZipArchiveContainer::GetName() const { return this->zipFile->GetName(); } // ------------------------------------------------------------------------------------------- // const std::string &ZipArchiveContainer::GetNativePath() const { return this->zipFile->GetNativePath(); } // ------------------------------------------------------------------------------------------- // std::vector ZipArchiveContainer::GetContainers( const std::string &wildcard /* = std::string() */ ) const { std::call_once(this->zipDirectoryRead, &ZipArchiveContainer::readZipDirectory, this); const Container *rootContainer = this->rootContainer.get(); return rootContainer->GetContainers(wildcard); } // ------------------------------------------------------------------------------------------- // std::vector ZipArchiveContainer::GetContainers( const std::string &wildcard /* = std::string() */ ) { std::call_once(this->zipDirectoryRead, &ZipArchiveContainer::readZipDirectory, this); return this->rootContainer->GetContainers(wildcard); } // ------------------------------------------------------------------------------------------- // ZipArchiveContainer::ConstContainerPointer ZipArchiveContainer::GetContainer( const std::string &name ) const { std::call_once(this->zipDirectoryRead, &ZipArchiveContainer::readZipDirectory, this); const Container *rootContainer = this->rootContainer.get(); return rootContainer->GetContainer(name); } // ------------------------------------------------------------------------------------------- // ZipArchiveContainer::ContainerPointer ZipArchiveContainer::GetContainer( const std::string &name ) { std::call_once(this->zipDirectoryRead, &ZipArchiveContainer::readZipDirectory, this); return this->rootContainer->GetContainer(name); } // ------------------------------------------------------------------------------------------- // bool ZipArchiveContainer::HasContainer(const std::string &name) const { std::call_once(this->zipDirectoryRead, &ZipArchiveContainer::readZipDirectory, this); return this->rootContainer->HasContainer(name); } // ------------------------------------------------------------------------------------------- // ZipArchiveContainer::ContainerPointer ZipArchiveContainer::CreateContainer( const std::string & ) { throw std::runtime_error("Zip archives cannot be modified"); } // ------------------------------------------------------------------------------------------- // bool ZipArchiveContainer::DeleteContainer(const std::string &) { throw std::runtime_error("Zip archives cannot be modified"); } // ------------------------------------------------------------------------------------------- // std::vector ZipArchiveContainer::GetFiles( const std::string &wildcard /* = std::wstring() */ ) const { std::call_once(this->zipDirectoryRead, &ZipArchiveContainer::readZipDirectory, this); const Container *rootContainer = this->rootContainer.get(); return rootContainer->GetFiles(wildcard); } // ------------------------------------------------------------------------------------------- // std::vector ZipArchiveContainer::GetFiles( const std::string &wildcard /* = std::wstring() */ ) { std::call_once(this->zipDirectoryRead, &ZipArchiveContainer::readZipDirectory, this); return this->rootContainer->GetFiles(wildcard); } // ------------------------------------------------------------------------------------------- // ZipArchiveContainer::ConstFilePointer ZipArchiveContainer::GetFile( const std::string &name ) const { std::call_once(this->zipDirectoryRead, &ZipArchiveContainer::readZipDirectory, this); const Container *rootContainer = this->rootContainer.get(); return rootContainer->GetFile(name); } // ------------------------------------------------------------------------------------------- // ZipArchiveContainer::FilePointer ZipArchiveContainer::GetFile(const std::string &name) { std::call_once(this->zipDirectoryRead, &ZipArchiveContainer::readZipDirectory, this); return this->rootContainer->GetFile(name); } // ------------------------------------------------------------------------------------------- // bool ZipArchiveContainer::HasFile(const std::string &name) const { std::call_once(this->zipDirectoryRead, &ZipArchiveContainer::readZipDirectory, this); return this->rootContainer->HasFile(name); } // ------------------------------------------------------------------------------------------- // ZipArchiveContainer::FilePointer ZipArchiveContainer::CreateFile(const std::string &) { throw std::runtime_error("Zip archives cannot be modified"); } // ------------------------------------------------------------------------------------------- // bool ZipArchiveContainer::DeleteFile(const std::string &) { throw std::runtime_error("Zip archives cannot be modified"); } // ------------------------------------------------------------------------------------------- // void ZipArchiveContainer::readZipDirectory() const { if(this->rootContainer == nullptr) { std::shared_ptr self = shared_from_this(); ZipDirectoryReader reader(this->zipFile->GetNativePath(), this->zipFile); reader.ReadDirectory(); this->rootContainer = reader.GetRootContainer(); } } // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Storage::FileSystem::Zip