#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_ZIPPEDCONTAINER_H
#define NUCLEX_STORAGE_FILESYSTEM_ZIP_ZIPPEDCONTAINER_H
#include "Nuclex/Storage/Config.h"
#include "Nuclex/Storage/FileSystem/Container.h"
#include "../Generic/GenericArchivedContainer.h"
namespace Nuclex { namespace Storage { namespace FileSystem { namespace Zip {
// ------------------------------------------------------------------------------------------- //
class ZippedContainer;
class ZippedFile;
class ZipDirectoryReader;
// ------------------------------------------------------------------------------------------- //
}}}} // namespace Nuclex::Storage::FileSystem::Zip
namespace Nuclex { namespace Storage { namespace FileSystem { namespace Zip {
// ------------------------------------------------------------------------------------------- //
/// Represents a folder in a zip archive as a container
class ZippedContainer : public Container {
// GenericArchivedContainer
friend 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;
/// 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;
/// Map of file names to zipped file informations
private: typedef std::map ZippedFileMap;
/// Map of file names to zipped file informations
private: typedef std::map ZippedContainerMap;
/// Initializes a new zip archive based container
/// Codecs used to open nested archives
/// Native path of directory in the zip archive
/// Name of the container inside the file
public: ZippedContainer(
const std::shared_ptr &codecs,
const std::string &nativePath,
const std::string &name
);
/// Destroys the zipped folder interface
public: virtual ~ZippedContainer();
/// Returns the name of the file
/// The file's name
public: const std::string &GetName() const { return this->name; }
/// 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 { return this->nativePath; }
/// 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);
/// Adds a container as a child of this container
/// Container that will be stored inside this container
protected: void AddContainer(const std::shared_ptr &container);
/// Adds a file as a child of this container
/// File that will be stored inside this container
protected: void AddFile(const std::shared_ptr &file);
/// The native path to this container
private: std::string nativePath;
/// The container's name
private: std::string name;
/// Subdirectories inside this directory of the zip archive
private: ZippedContainerMap containers;
/// Files on this directory level of the zip archive
private: ZippedFileMap files;
};
// ------------------------------------------------------------------------------------------- //
}}}} // namespace Nuclex::Storage::FileSystem::Zip
#endif // NUCLEX_STORAGE_FILESYSTEM_ZIP_ZIPPEDCONTAINER_H