#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 #ifndef NUCLEX_STORAGE_FILESYSTEM_ZIP_ZIPARCHIVECONTAINER_H #define NUCLEX_STORAGE_FILESYSTEM_ZIP_ZIPARCHIVECONTAINER_H #include "Nuclex/Storage/Config.h" #include "Nuclex/Storage/FileSystem/Container.h" #include "Nuclex/Storage/FileSystem/ContainerFileCodec.h" #include "ZipReader.h" #include namespace Nuclex { namespace Storage { namespace FileSystem { namespace Zip { // ------------------------------------------------------------------------------------------- // class ZippedFile; class ZippedContainer; // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Storage::FileSystem::Zip namespace Nuclex { namespace Storage { namespace FileSystem { namespace Zip { // ------------------------------------------------------------------------------------------- // /// Represents a zip archive as a container class ZipArchiveContainer : public Container, public virtual std::enable_shared_from_this { friend class ZippedFile; /// Smart pointer to a constant container private: typedef std::shared_ptr ConstContainerPointer; /// Smart pointer to a container private: typedef std::shared_ptr ContainerPointer; /// Smart pointer to a constant file private: typedef std::shared_ptr ConstFilePointer; /// Smart pointer to a file private: typedef std::shared_ptr FilePointer; /// Initializes a new zip archive based container /// Codecs used to open nested container files /// The zip archive the container will access public: ZipArchiveContainer( const std::shared_ptr &codecs, const std::shared_ptr &zipFile ); /// Closes the zip archive and frees all resources used public: virtual ~ZipArchiveContainer(); /// Returns the name of the file /// The file's name public: const std::string &GetName() const; /// Returns the path the file is stored at in the native format /// The file's absolute path in the native OS format public: const std::string &GetNativePath() const; /// Retrieves a list of the containers located in this container /// Wildcard of the containers to list /// A list of all containers matching the wildcard public: std::vector GetContainers( const std::string &wildcard = std::string() ) const; /// Retrieves a list of the containers located in this container /// Wildcard of the containers to list /// A list of all containers matching the wildcard public: virtual std::vector GetContainers( const std::string &wildcard = std::string() ); /// Retrieves the container with the specified name /// Name of the container that will be retrieved /// The container with the specified name public: virtual ConstContainerPointer GetContainer(const std::string &name) const; /// Retrieves the container with the specified name /// Name of the container that will be retrieved /// The container with the specified name public: virtual ContainerPointer GetContainer(const std::string &name); /// Checks if the container contains the specified child container /// Child container the container will be checked for /// True if the container has a child container with the specified name public: virtual bool HasContainer(const std::string &name) const; /// Creates a new container in this container /// Name of the created container /// The created container public: virtual ContainerPointer CreateContainer(const std::string &name); /// Deletes a container in this container /// Name of the deleted container /// True if the container was deleted, false if it didn't exist public: virtual bool DeleteContainer(const std::string &name); /// Retrieves a list of the files located in this container /// Wildcard of the files to list /// A list of all files matching the wildcard public: virtual std::vector GetFiles( const std::string &wildcard = std::string() ) const; /// Retrieves a list of the files located in this container /// Wildcard of the files to list /// A list of all files matching the wildcard public: virtual std::vector GetFiles( const std::string &wildcard = std::string() ); /// Retrieves the file with the specified name /// Name of the file that will be retrieved /// The file with the specified name public: virtual ConstFilePointer GetFile(const std::string &name) const; /// Retrieves the file with the specified name /// Name of the file that will be retrieved /// The file with the specified name public: virtual FilePointer GetFile(const std::string &name); /// Checks if the container contains the specified file /// File the container will be checked for /// True if the container contains a file with the specified name public: virtual bool HasFile(const std::string &name) const; /// Retrieves the file with the specified name /// Name of the file that will be retrieved /// The file with the specified name public: virtual FilePointer CreateFile(const std::string &name); /// Deletes the file with the specified name /// Name of the file that will be deleted /// True if the file was deleted, false if it didn't exist public: virtual bool DeleteFile(const std::string &name); /// Retrieves the file representing the zip archive itself /// The file through which the zip archive is opened protected: const std::shared_ptr GetZipFile() const { return this->zipFile; } /// Reads the zip archive's director private: void readZipDirectory() const; /// Zip archive the container is accessing private: std::shared_ptr zipFile; /// Set when the zip directory has been read private: mutable std::once_flag zipDirectoryRead; /// Holds the contents of the zip archive's root directory private: mutable std::shared_ptr rootContainer; }; // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Storage::FileSystem::Zip #endif // NUCLEX_STORAGE_FILESYSTEM_ZIP_ZIPARCHIVECONTAINER_H