#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_ZIPDIRECTORYREADER_H #define NUCLEX_STORAGE_FILESYSTEM_ZIP_ZIPDIRECTORYREADER_H #include "Nuclex/Storage/Config.h" #include #include #include #include namespace Nuclex { namespace Storage { namespace FileSystem { namespace Zip { // ------------------------------------------------------------------------------------------- // class ZippedContainer; class ZippedFile; class ZipReader; struct LocalFileHeader; // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Storage::FileSystem::Zip namespace Nuclex { namespace Storage { // ------------------------------------------------------------------------------------------- // class Blob; // ------------------------------------------------------------------------------------------- // }} // namespace Nuclex::Storage namespace Nuclex { namespace Storage { namespace FileSystem { namespace Zip { // ------------------------------------------------------------------------------------------ -// /// /// Reads the directory of a zip archive and creates the appropriate objects /// class ZipDirectoryReader { /// Smart pointer to a zipped container private: typedef std::shared_ptr ZippedContainerPointer; /// Smart pointer to a zipped file private: typedef std::shared_ptr ZippedFilePointer; /// Map of file names to zipped file informations private: typedef std::map ZippedContainerMap; /// Initializes a new zip directory reader /// System-specific path to the zip archive /// Zip archive of which the directory will be read public: ZipDirectoryReader( const std::string &nativeArchivePath, const std::shared_ptr &archive ); /// Frees all resources owned by the instance public: ~ZipDirectoryReader(); /// Reads the zip archive's directory public: void ReadDirectory(); /// Returns the root directory level container of the zip archive /// The container forthe zip archive's root directory level public: const std::shared_ptr &GetRootContainer() const; /// Reads the compressed file headers from the zip archive private: void scanLocalFileHeaders(); /// Adds the contents of a local file header to the hierarchy /// /// Local file header containing meta data about the compressed file /// /// /// Absolute offset of the compressed file contents in the zip archive /// private: void processLocalFileHeader( const LocalFileHeader &localFileHeader, std::uint64_t compressedDataPosition ); /// Retrieves or creates a new container for the specified path /// Directory for which the container will be returned /// The container for the specified directory private: const std::shared_ptr &getOrCreateContainerForDirectory( const std::string &directory ); /// Determines the parent directory of the specified directory /// Directory whose parent directory will be determined /// The parent directory of the specified directory private: static std::string getParentDirectory(const std::string &directory); /// Determines the name of the directory in the specified path /// /// Path from which the name of the deepest directory will be returned /// /// The name of the deepest directory in the specified path private: static std::string getDirectoryName(const std::string &path); /// Checks whether the specified path indicates a directory /// Path that will be checked /// True if the specified path is a directory private: static bool isDirectory(const std::string &path); private: ZipDirectoryReader(const ZipDirectoryReader &); private: ZipDirectoryReader &operator =(const ZipDirectoryReader &); /// Zip archive path in the format native to the operating system private: std::string nativeArchivePath; /// Cache that will be used to extract deflate-compressed files private: std::shared_ptr zipReader; /// Zip archive the directory reader operates on private: std::shared_ptr archive; /// Containers by their paths private: ZippedContainerMap containers; }; // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Storage::FileSystem::Zip #endif // NUCLEX_STORAGE_FILESYSTEM_ZIP_ZIPDIRECTORYREADER_H