#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 "SevenZipArchiveContainer.h" #include "SevenZippedContainer.h" #include "SevenZippedFile.h" #include "SevenZipDirectoryReader.h" namespace Nuclex { namespace Storage { namespace FileSystem { namespace SevenZip { // ------------------------------------------------------------------------------------------- // SevenZipArchiveContainer::SevenZipArchiveContainer( const std::shared_ptr &codecs, const std::shared_ptr &sevenZipFile ) : Container(codecs), sevenZipFile(sevenZipFile), rootContainer(nullptr) {} // ------------------------------------------------------------------------------------------- // SevenZipArchiveContainer::~SevenZipArchiveContainer() {} // ------------------------------------------------------------------------------------------- // const std::string &SevenZipArchiveContainer::GetName() const { return this->sevenZipFile->GetName(); } // ------------------------------------------------------------------------------------------- // const std::string &SevenZipArchiveContainer::GetNativePath() const { return this->sevenZipFile->GetNativePath(); } // ------------------------------------------------------------------------------------------- // std::vector SevenZipArchiveContainer::GetContainers( const std::string &wildcard /* = std::string() */ ) const { std::call_once( this->sevenZipDirectoryRead, &SevenZipArchiveContainer::readSevenZipDirectory, this ); const Container *rootContainer = this->rootContainer.get(); return rootContainer->GetContainers(wildcard); } // ------------------------------------------------------------------------------------------- // std::vector SevenZipArchiveContainer::GetContainers( const std::string &wildcard /* = std::string() */ ) { std::call_once( this->sevenZipDirectoryRead, &SevenZipArchiveContainer::readSevenZipDirectory, this ); return this->rootContainer->GetContainers(wildcard); } // ------------------------------------------------------------------------------------------- // SevenZipArchiveContainer::ConstContainerPointer SevenZipArchiveContainer::GetContainer( const std::string &name ) const { std::call_once( this->sevenZipDirectoryRead, &SevenZipArchiveContainer::readSevenZipDirectory, this ); const Container *rootContainer = this->rootContainer.get(); return rootContainer->GetContainer(name); } // ------------------------------------------------------------------------------------------- // SevenZipArchiveContainer::ContainerPointer SevenZipArchiveContainer::GetContainer( const std::string &name ) { std::call_once( this->sevenZipDirectoryRead, &SevenZipArchiveContainer::readSevenZipDirectory, this ); return this->rootContainer->GetContainer(name); } // ------------------------------------------------------------------------------------------- // bool SevenZipArchiveContainer::HasContainer(const std::string &name) const { std::call_once( this->sevenZipDirectoryRead, &SevenZipArchiveContainer::readSevenZipDirectory, this ); return this->rootContainer->HasContainer(name); } // ------------------------------------------------------------------------------------------- // SevenZipArchiveContainer::ContainerPointer SevenZipArchiveContainer::CreateContainer( const std::string & ) { throw std::runtime_error("Zip archives cannot be modified"); } // ------------------------------------------------------------------------------------------- // bool SevenZipArchiveContainer::DeleteContainer(const std::string &) { throw std::runtime_error("Zip archives cannot be modified"); } // ------------------------------------------------------------------------------------------- // std::vector SevenZipArchiveContainer::GetFiles( const std::string &wildcard /* = std::wstring() */ ) const { std::call_once( this->sevenZipDirectoryRead, &SevenZipArchiveContainer::readSevenZipDirectory, this ); const Container *rootContainer = this->rootContainer.get(); return rootContainer->GetFiles(wildcard); } // ------------------------------------------------------------------------------------------- // std::vector SevenZipArchiveContainer::GetFiles( const std::string &wildcard /* = std::wstring() */ ) { std::call_once( this->sevenZipDirectoryRead, &SevenZipArchiveContainer::readSevenZipDirectory, this ); return this->rootContainer->GetFiles(wildcard); } // ------------------------------------------------------------------------------------------- // SevenZipArchiveContainer::ConstFilePointer SevenZipArchiveContainer::GetFile( const std::string &name ) const { std::call_once( this->sevenZipDirectoryRead, &SevenZipArchiveContainer::readSevenZipDirectory, this ); const Container *rootContainer = this->rootContainer.get(); return rootContainer->GetFile(name); } // ------------------------------------------------------------------------------------------- // SevenZipArchiveContainer::FilePointer SevenZipArchiveContainer::GetFile(const std::string &name) { std::call_once( this->sevenZipDirectoryRead, &SevenZipArchiveContainer::readSevenZipDirectory, this ); return this->rootContainer->GetFile(name); } // ------------------------------------------------------------------------------------------- // bool SevenZipArchiveContainer::HasFile(const std::string &name) const { std::call_once( this->sevenZipDirectoryRead, &SevenZipArchiveContainer::readSevenZipDirectory, this ); return this->rootContainer->HasFile(name); } // ------------------------------------------------------------------------------------------- // SevenZipArchiveContainer::FilePointer SevenZipArchiveContainer::CreateFile(const std::string &) { throw std::runtime_error("7-Zip archives cannot be modified"); } // ------------------------------------------------------------------------------------------- // bool SevenZipArchiveContainer::DeleteFile(const std::string &) { throw std::runtime_error("7-Zip archives cannot be modified"); } // ------------------------------------------------------------------------------------------- // void SevenZipArchiveContainer::readSevenZipDirectory() const { if(this->rootContainer == nullptr) { std::shared_ptr self = shared_from_this(); SevenZipDirectoryReader reader(this->sevenZipFile->GetNativePath(), this->sevenZipFile); reader.ReadDirectory(); this->rootContainer = reader.GetRootContainer(); } } // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Storage::FileSystem::SevenZip