I needed to have a case insensitive archive implementation for linux directories and also wanted a way to easily provide resource overrides. The resulting hacky code is provided here for everyone to use freely. Feel free to change and improve in any way you feel appropriate. The code was tested and works, but feel free to iron any bugs that would show up.

What it does

The implementation provides four new archive types which supply various transforms.

FirstOf and LastOf archives (MultiArchive class) enclose several archives into one virtual archive which uses ordered lookups for all operations (FirstOf tries to satisfy the operation searching from start - useful for prioritized loading from faster archives first think HDD install in combination with CD/DVD, LastOf works the other way round - useful for resource overrides for example).

ProxyArchive transforms the names of underlying archive. It is used in two implementations - LowerCase archive, which transforms all names to lower case, and Prefix archive, which transforms all the names by prefixing them with specified string.

Register the new archive factories

As with other user defined archive types, the factories have to be registered:

ArchiveManager::getSingleton().addArchiveFactory( new CaseLessTransformArchiveFactory() );
ArchiveManager::getSingleton().addArchiveFactory( new PrefixingTransformArchiveFactory() );
ArchiveManager::getSingleton().addArchiveFactory( new FirstOfArchiveFactory() );
ArchiveManager::getSingleton().addArchiveFactory( new LastOfArchiveFactory() );

Usage

The TransformArchive base class provides a static method parseAndCreate, which can be used to load an archive using the specification in code.
From resource specification, the outermost archive specification uses the standard Type=location convention, where location is the content of the bracket expression.

Bracket expressions

The archives use Type(parameters) convention. The parameters are archive specific:

  • FirstOf, LastOf - parameters are archives that are merged into the virtual one, separated by commas
  • LowerCase - parameter is an archive to transform to lower case.
  • Prefix - first parameter is prefix, second is the archive to prefix.




For simplicity of implementation, no whitespace or newlines is allowed. Feel free to change.

Examples (in the bracket expression form):

LowerCase(FileSystem(c:\dir\))
Prefix(zip/,Zip(file.zip))
FirstOf(FileSystem(c:\InstallDir),FileSystem(D:\CDFILES))
LastOf(Zip(base.zip),FileSystem(Overrides\))

ProxyArchive.cpp

#include "ProxyArchive.h"

#include <OgreException.h>
#include <OgreString.h>
#include <OgreFileSystem.h>
#include <OgreArchiveManager.h>
#include <OgreZip.h>

#define BRACKET_OPEN '('
#define BRACKET_CLOSE ')'
#define SEPARATOR ','

namespace Ogre {

    // -------------------------------------------------------
    // ----- TransformArchive --------------------------------
    // -------------------------------------------------------
    TransformArchive::TransformArchive(const String& name, const String& archType) 
            : Archive(name, archType) {
    
    }

    // -------------------------------------------------------
    std::pair<String, String> TransformArchive::parseSpec(const String& spec) {
        std::pair<String, String> as;
        
        // First the contents preceding the brackets
        size_t pos = spec.find_first_of(BRACKET_OPEN);
        
        if (pos == String::npos)
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Archive bracket expression did not contain any brackets : '"+ spec +"'", "TransformArchive::parseSpec");
        
        as.first = spec.substr(0, pos);
        
        // now the bracket itself. count bracket till back to zero
        size_t level = 1;
        size_t cbegin = ++pos;
        
        while (pos != spec.length()) {
            if (spec[pos] == BRACKET_OPEN)
                ++level;
            else if (spec[pos] == BRACKET_CLOSE)
                --level;
        
            if (level == 0)
                break;
            
            ++pos;
        }
        
        if (level != 0)
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Archive bracket expression - undisclosed bracket encountered", "TransformArchive::parseSpec");
        
        as.second = spec.substr(cbegin, pos - cbegin);
        
        return as;
    };

    // -------------------------------------------------------
    bool TransformArchive::fileNameMatch(const String& pattern, const String& name) {
        String unt = name;

        StringUtil::toLowerCase(unt);
        String lpattern = pattern;
        StringUtil::toLowerCase(lpattern);

        // inspired by one codeproject article (but a rewrite without using the code)

        enum State {
            PM_Match = 0,
            PM_Any,
            PM_AnySeq
        };

        // we don't wanna depend on some lib that does not exist for visual C anyway
        bool match = true;
        String::iterator pi = lpattern.begin();
        String::iterator pnext = pi; // only used for AnySeq
        String::iterator si = unt.begin();
        int state = 0;

        while (match && pi != lpattern.end()) {
            // if we're at the end of the source string
            if (si == unt.end()) {
                // match is found if pi got to end as well
                match = pi == lpattern.end();
                break;
            }

            // see what we're comparing to
            state = PM_Match;

            if (*pi == '*') {
                state = PM_AnySeq;
                pnext = pi;

                // eat all the consecutive stars
                while (*pnext == '*')
                        ++pnext;
            } else if (*pi == '?') {
                state = PM_Any;
            }

            switch (state) {
                case PM_Match:
                    match = *pi == *si;
                case PM_Any:
                    ++pi; ++si;
                    break;
                case PM_AnySeq:
                    // matched any character
                    ++si;

                    // found the end of pattern? If so,
                    // then the previous comparisons decide
                    if (pnext == lpattern.end()) {
                            match = true;
                            break;
                    }

                    // end for string, but some pattern following?
                    if (pnext != lpattern.end() &&
                        si == unt.end()) {
                            match = false;
                            break;
                    }

                    // or found a match after the star?
                    if (*si == *pnext) ++pi;
                    break;
            }
        }

        return match;
    }
    
    // -------------------------------------------------------
    Archive* TransformArchive::parseAndCreate(const String& spec) {
        // Strip out our parameters
        std::pair<String, String> as = parseSpec(spec);
        
        return ArchiveManager::getSingleton().load(as.second, as.first);
    }
    
    // -------------------------------------------------------
    std::vector<String> TransformArchive::splitParams(const String& spec) {
        // by hand, nicer implementation would be nice
        // now the bracket itself. count bracket till back to zero
        size_t level = 1;
        size_t pos = 0, last_pos = 0;
        std::vector<String> result;
        
        while (pos != spec.length()) {
            if (spec[pos] == BRACKET_OPEN)
                ++level;
            else if (spec[pos] == BRACKET_CLOSE)
                --level;
        
            // split on level one commas only
            if (spec[pos] == SEPARATOR && level == 1) {
                String token = spec.substr(last_pos, pos++);
                last_pos = pos;
                result.push_back(token);
            }
            
            if (level == 0)
                break;
            
            ++pos;
        }
        
        if (last_pos != pos) {
            if (level < 1)
                pos--;
            
            String token = spec.substr(last_pos, pos);
            result.push_back(token);
        }
        
        return result;
    }
    
    // -------------------------------------------------------
    // ----- Proxy Archive -----------------------------------
    // -------------------------------------------------------
    ProxyArchive::ProxyArchive(const String& name, const String& archType) :
        TransformArchive(name, archType),
        mArchive(NULL) {
        
    }

    // -------------------------------------------------------
    ProxyArchive::~ProxyArchive(void) {
        if (mArchive) {
            ArchiveManager::getSingleton().unload(mArchive);
        }
    }

    // -------------------------------------------------------
    void ProxyArchive::load(void) {
        if (!mArchive) {
            mArchive = parseAndCreate(mName);
        }
    
        // load, build map
        mArchive->load();

        StringVectorPtr lst = mArchive->list(true, false);

        StringVector::iterator it = lst->begin();

        while (it != lst->end()) {
            const std::string& fn = *it++;
            std::string tn = transformName(fn);
            
            StringUtil::toLowerCase(tn);
            // insert into the map
            std::pair<NameTable::iterator, bool> result =
                mExtToIntNames.insert(std::make_pair(tn, fn));

            // see if the result is ok, except if not
            if (!result.second)
                OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
                    "Archive '" + mName + "' contains duplicities : " + fn,
                    "ProxyArchive::load");
        }
    }

    // -------------------------------------------------------
    void ProxyArchive::unload(void) {
        // we don't unload the underlying archive as the Archive manager 
        // is not prepared to have archive to archive dependencies and that results in segv here
        mExtToIntNames.clear();
    }

    // -------------------------------------------------------
    FileInfoListPtr ProxyArchive::findFileInfo(const String& pattern, bool recursive , bool dirs) {
        /// have to list all infos, filter those which fit
        FileInfoListPtr lst = listFileInfo(recursive, dirs);

        FileInfoListPtr res(new FileInfoList());

        /// now iterate, the list, match using the name, return
        FileInfoList::iterator it = lst->begin();

        while (it != lst->end()) {
            const FileInfo& fi = *it++;
            // match?
            if (match(pattern, fi.filename)) {
                res->push_back(fi);
            }
        }

        return res;
    }

    // -------------------------------------------------------
    bool ProxyArchive::exists(const String& filename) {
        String un;

        if (untransformName(filename, un))
            return mArchive->exists(un);
        else
            return false;
    }

    // -------------------------------------------------------
    StringVectorPtr ProxyArchive::find(const String& pattern, bool recursive , bool dirs) {
        /// have to list all infos, filter those which fit
        StringVectorPtr lst = list(recursive, dirs);

        StringVectorPtr res(new StringVector());

        /// now iterate, the list, match using the name, return
        StringVector::iterator it = lst->begin();

        while (it != lst->end()) {
            const String& fn = *it++;
            // match?
            if (match(pattern, fn)) {
                res->push_back(fn);
            }
        }

        return res;
    }

    // -------------------------------------------------------
    FileInfoListPtr ProxyArchive::listFileInfo(bool recursive , bool dirs) {
        FileInfoListPtr list = mArchive->listFileInfo(recursive, dirs);

        FileInfoListPtr res(new FileInfoList());

        /// now iterate, the list, match using the name, return
        FileInfoList::iterator it = list->begin();

        while (it != list->end()) {
            const FileInfo& fi = *it++;

            FileInfo fin;

            fin.archive = this;
            fin.filename = transformName(fi.filename);
            fin.path = transformName(fi.path);
            fin.basename = transformName(fi.basename);

            fin.compressedSize = fi.compressedSize;
            fin.uncompressedSize = fi.uncompressedSize;

            res->push_back(fin);
        }

        return res;
    }

    // -------------------------------------------------------
    StringVectorPtr ProxyArchive::list(bool recursive , bool dirs) {
        /// have to list all infos, filter those which fit
        StringVectorPtr lst = mArchive->list(recursive, dirs);

        StringVectorPtr res(new StringVector());

        /// now iterate, the list, match using the name, return
        StringVector::iterator it = lst->begin();

        while (it != lst->end()) {
            const String& fn = *it++;

            res->push_back(transformName(fn));
        }

        return res;
    }

    // -------------------------------------------------------
    DataStreamPtr ProxyArchive::open(const String& filename) const {
        String un;

        if (untransformName(filename, un))
            return mArchive->open(un);
        else
            return DataStreamPtr();
    }

    // -------------------------------------------------------
    bool ProxyArchive::untransformName(const String& name, String& unt) const {
        String s = name;
        StringUtil::toLowerCase(s);
        NameTable::const_iterator it = mExtToIntNames.find(s);

        if (it != mExtToIntNames.end()) {
            unt = it->second;
            return true;
        } else {
            return false;
        }
    }

    // -------------------------------------------------------
    bool ProxyArchive::match(const String& pattern, const String& name) const {
        String unt;

        if (!untransformName(name, unt))
            return false;

        return fileNameMatch(pattern, unt);
    }

    // -------------------------------------------------------
    // ----- MultiArchive --------------------------------
    // -------------------------------------------------------
    MultiArchive::MultiArchive(const String& name, const String& archType, bool reverse)
        : TransformArchive(name, archType),
        mReverseOrder(reverse) {
        
    };
            
    // -------------------------------------------------------
    MultiArchive::~MultiArchive() {
        /** ArchiveList::iterator it = mArchiveList.begin();
        
        for (; it != mArchiveList.end(); ++it) {
            if (*it)
                ArchiveManager::getSingleton().unload((*it));
        }
        */
        mArchiveList.clear();
    };
    
    // -------------------------------------------------------
    void MultiArchive::load() {
        std::vector<String> sv = splitParams(mName);
        
        std::vector<String>::iterator it;
        
        // make archives for all the found ones
        for (it = sv.begin(); it != sv.end(); ++it) {
            // each splitted archive is parsed and processed
            // Strip out our parameters
            Archive *arch = parseAndCreate(*it);
            mArchiveList.push_back(arch);
        }
    }
    
        
    // -------------------------------------------------------
    void MultiArchive::unload(void) {
        // we don't unload the underlying archives as the Archive manager 
        // is not prepared to have archive to archive dependencies and that results in potential segv here
        mArchiveList.clear();
    }
            
    // -------------------------------------------------------
    DataStreamPtr MultiArchive::open(const String& filename) const {
        Archive* a = getArchiveForFileName(filename);
        
        if (a != NULL)
            return a->open(filename);
            
        OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND, "Invalid file name specified", "MultiArchive::open"); 
    };

    // -------------------------------------------------------
    StringVectorPtr MultiArchive::list(bool recursive, bool dirs) {
        // We collect the results using the defined order...
        ArchiveList::iterator it = mArchiveList.begin();
        
        std::set<String> resultset;
        
        for (;it != mArchiveList.end(); ++it) {
            // list the archive
            Archive *a = *it;
            
            // order strategy does not matter here, just merge the results
            StringVectorPtr svp = a->list(recursive, dirs);
            
            for(StringVector::iterator sit = svp->begin(); sit != svp->end(); ++sit) {
                resultset.insert(*sit);
            }
        }
    
        // convert to vector, return
        std::set<String>::iterator si = resultset.begin();
        std::set<String>::iterator se = resultset.end();
        
        StringVectorPtr sv(new StringVector());
        
        for (; si != se; ++si) {
            sv->push_back(*si);
        }
        
        return sv;
    };

    // -------------------------------------------------------
    FileInfoListPtr MultiArchive::listFileInfo(bool recursive, bool dirs) {
        ArchiveList::iterator it = mArchiveList.begin();
        
        std::map<String, FileInfo> resultmap;
        
        for (;it != mArchiveList.end(); ++it) {
            // list the archive
            Archive *a = *it;
            
            // order strategy does matter here. We either replace the FileInfo or not
            FileInfoListPtr svp = a->listFileInfo(recursive, dirs);
            
            for(FileInfoList::iterator sit = svp->begin(); sit != svp->end(); ++sit) {
                const String& fn = sit->filename;
                
                if (mReverseOrder) {
                        resultmap[fn] = *sit;
                } else {
                    // see if we already have the result
                    std::map<String, FileInfo>::iterator mi = resultmap.find(fn);
                    
                    if (mi == resultmap.end()) {
                        resultmap.insert(std::make_pair(fn, *sit));
                    }
                }
            }
        }
    
        // convert to vector, return
        std::map<String, FileInfo>::iterator si = resultmap.begin();
        std::map<String, FileInfo>::iterator se = resultmap.end();
        
        FileInfoListPtr sv(new FileInfoList());
        
        for (; si != se; ++si) {
            sv->push_back(si->second);
        } 
        
        return sv;
    };

    // -------------------------------------------------------
    StringVectorPtr MultiArchive::find(const String& pattern, bool recursive, bool dirs) {
        // We collect the results using the defined order...
        ArchiveList::iterator it = mArchiveList.begin();
        
        std::set<String> resultset;
        
        for (;it != mArchiveList.end(); ++it) {
            // list the archive
            Archive *a = *it;
            
            // order strategy does not matter here, just merge the results
            StringVectorPtr svp = a->find(pattern, recursive, dirs);
            
            for(StringVector::iterator sit = svp->begin(); sit != svp->end(); ++sit) {
                resultset.insert(*sit);
            }
        }
    
        // convert to vector, return
        std::set<String>::iterator si = resultset.begin();
        std::set<String>::iterator se = resultset.end();
        
        StringVectorPtr sv(new StringVector());
        
        for (; si != se; ++si) {
            sv->push_back(*si);
        }     
        
        return sv;
    };

    // -------------------------------------------------------
    bool MultiArchive::exists(const String& filename) {
        Archive* a = getArchiveForFileName(filename);
        
        return a != NULL;
    };

    // -------------------------------------------------------
    FileInfoListPtr MultiArchive::findFileInfo(const String& pattern, bool recursive, bool dirs) {
        ArchiveList::iterator it = mArchiveList.begin();
        
        std::map<String, FileInfo> resultmap;
        
        for (;it != mArchiveList.end(); ++it) {
            // list the archive
            Archive *a = *it;
            
            // order strategy does matter here. We either replace the FileInfo or not
            FileInfoListPtr svp = a->findFileInfo(pattern, recursive, dirs);
            
            for(FileInfoList::iterator sit = svp->begin(); sit != svp->end(); ++sit) {
                const String& fn = sit->filename;
                
                if (mReverseOrder) {
                        resultmap[fn] = *sit;
                } else {
                    // see if we already have the result
                    std::map<String, FileInfo>::iterator mi = resultmap.find(fn);
                    
                    if (mi == resultmap.end()) {
                        resultmap.insert(std::make_pair(fn, *sit));
                    }
                }
            }
        }
    
        // convert to vector, return
        std::map<String, FileInfo>::iterator si = resultmap.begin();
        std::map<String, FileInfo>::iterator se = resultmap.end();
        
        FileInfoListPtr sv(new FileInfoList());
        
        for (; si != se; ++si) {
            sv->push_back(si->second);
        }
        
        return sv;
    };

    // -------------------------------------------------------
    bool MultiArchive::isCaseSensitive(void) const {
        return true;
    };

    // -------------------------------------------------------
    time_t MultiArchive::getModifiedTime(const String& filename) {
        Archive* a = getArchiveForFileName(filename);
        
        if (a != NULL)
            return a->getModifiedTime(filename);
            
        OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND, "Invalid file name specified", "MultiArchive::getModifiedTime"); 
    };
    
    // -------------------------------------------------------
    Archive* MultiArchive::getArchiveForFileName(const std::string& name) const {
        // TODO: This could also be done dynamically on demand
        Archive* target = NULL;
        
        ArchiveList::const_iterator it = mArchiveList.begin();
        ArchiveList::const_iterator eit = mArchiveList.end();
        
        for (; it != eit; ++it) {
            // search for the file
            Archive* ca = *it;
            
            if (ca->exists(name)) {
                target = ca;

                // if going forward, the first match is the one
                // if going backward, the last one is
                if (!mReverseOrder)
                    break;
            }
        }
        
        return target;
    };
    
    // -------------------------------------------------------
    // ----- CaseLess Archive --------------------------------
    // -------------------------------------------------------
    CaseLessTransformArchive::CaseLessTransformArchive(const String& name,
            const String& archType) : ProxyArchive(name, archType) {
    }

    // -------------------------------------------------------
    bool CaseLessTransformArchive::isCaseSensitive(void) const {
        return false;
    }

    // -------------------------------------------------------
    String CaseLessTransformArchive::transformName(const std::string& name) {
        // simple - just lowercase the name
        String res = name;
        StringUtil::toLowerCase(res);
        return res;
    }
    
    // -------------------------------------------------------
    // ----- Prefixing Archive --------------------------------
    // -------------------------------------------------------
    PrefixingTransformArchive::PrefixingTransformArchive(const String& name,
            const String& archType) : ProxyArchive(name, archType) {
        // extract the prefix
        std::vector<String> split = splitParams(name);
        
        if (split.size() != 2)
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Archive expression did not contain required parameters : '"+ name +"'", "PrefixingTransformArchive::PrefixingTransformArchive");
        
        mPrefix = split[0];
        mName = split[1];
    }

    // -------------------------------------------------------
    bool PrefixingTransformArchive::isCaseSensitive(void) const {
        return true;
    }

    // -------------------------------------------------------
    String PrefixingTransformArchive::transformName(const std::string& name) {
        return mPrefix + name;
    }

    // -------------------------------------------------------
    // ----- Factory Stuff -----------------------------------
    // -------------------------------------------------------

    
    const String CaseLessTransformArchiveFactory::msTypeName = "LowerCase";
    
    const String& CaseLessTransformArchiveFactory::getType(void) const {
        return msTypeName;
    }
    
    const String PrefixingTransformArchiveFactory::msTypeName = "Prefix";
    
    const String& PrefixingTransformArchiveFactory::getType(void) const {
        return msTypeName;
    }

    const String FirstOfArchiveFactory::msTypeName = "FirstOf";
    
    const String& FirstOfArchiveFactory::getType(void) const {
        return msTypeName;
    }

    const String LastOfArchiveFactory::msTypeName = "LastOf";
    
    const String& LastOfArchiveFactory::getType(void) const {
        return msTypeName;
    }
    
}

ProxyArchive.h

#ifndef __PROXYARCHIVE_H
#define __PROXYARCHIVE_H

#include <OgreArchive.h>
#include <OgreArchiveFactory.h>
#include <OgreString.h>

#define __EXPORT

namespace Ogre {

    /** Base class for all transforming archives. Contains the common methods used in all implementation (namely the bracket parser). 
    * @note This class and all the descendants use archive specification language in form Type(parameters), where parameters are Type specific.
    * @author Volca */
    class __EXPORT TransformArchive : public Archive {
        
        public:
            TransformArchive(const String& name, const String& archType);
            
            /** Explodes the archive specification in the form "Type(contents)". The type is then understood as Archive Type, the contents
             * are passed as the archive name. 
             * @param spec The string representation of the archive spec
             * @return pair The pair containing type and contents strings forming the specification: "first(second)" 
             * @throw Ogre::Exception if the format is wrong */
            static std::pair<String, String> parseSpec(const String& spec);
            
            /** Does a wildcard match of the * pattern with the 'name' string
             * @param pattern The wildcard pattern, in which '*' means "anything"
             * @param name The name of the file to compare */
            static bool fileNameMatch(const String& pattern, const String& name);
            
            /** Parses the specification string and creates an archive based on it. */
            static Archive* parseAndCreate(const String& spec);
            
            /** Splits the specified string on commas, obeying commas burried in enclosing brackets. */
            std::vector<String> splitParams(const String& spec);
    };

    /** Proxy archive, which performs name transforms and delegates to underlying archive instance.
    * There are couple different possible usages for this archive class:
    * <ul> 
    * <li>A case insensitive filesystem archive on *nix systems</li>
    * <li>A ZIP file handler which includes the FNAME.ZIP as FNAME/ in all names of the archive</li>
    * <li>Other</li>
    * </ul>
    * @author Volca
    */
    class __EXPORT ProxyArchive : public TransformArchive {
        public:
            /// constructor
            ProxyArchive(const String& name, const String& archType);

            /// destructor
            virtual ~ProxyArchive(void);

            /// performs the archive load. Scans the archive for filenames, builds the reverse transform table
            virtual void load(void);

            /// Unloads the archive, clears the transform map
            virtual void unload(void);

            /// opens a resource stream, unmapping the name first
            virtual DataStreamPtr open(const String& filename) const;

            /// lists the contents of the archive. transformed.
            virtual StringVectorPtr list(bool recursive = true, bool dirs = false);

            /// lists the contents of the archive. transformed, in the FileInfo structures.
            virtual FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false);

            /// performs a pattern match find on the archive files
            virtual StringVectorPtr find(const String& pattern, bool recursive = true,
                bool dirs = false);

            /// Searches for the given name, untransforming it first
            virtual bool exists(const String& filename);

            /** Searches for files that match the given pattern
             * @see find
            */
            virtual FileInfoListPtr findFileInfo(const String& pattern,
                bool recursive = true, bool dirs = false);

            /// reports case sensitiveness of this proxy archive
            virtual bool isCaseSensitive(void) const = 0;

            time_t getModifiedTime(const String& filename) {return 0;};

        protected:
            /// performs the forward transform on a single name
            virtual String transformName(const String& name) = 0;

            /// performs an inverse transform on a single name, turning internal name from the external one
            virtual bool untransformName(const String& name, String& unt) const;

            /** compares if the given filename matches the pattern
            * By default, this does case insensitive filename match on the untransformed name
            */
            virtual bool match(const String& pattern, const String& name) const;

            typedef std::map<std::string, std::string> NameTable;

            NameTable mExtToIntNames;

            Archive* mArchive;
    };

    /** Content merging archive. A base class for various archives which map multiple archives into one.
    * For this to work, we have a step which maps each file name to an archive pointer 
    * @author Volca */
    class __EXPORT MultiArchive : public TransformArchive {
        public:
            /// Constructor
            MultiArchive(const String& name, const String& archType, bool reverse);
            
            /// Destrucor
            ~MultiArchive();

            /// performs the archive load. Scans the archive for filenames, builds the reverse transform table
            virtual void load(void);

            /// Unloads the archive, clears the transform map
            virtual void unload(void);

            /// opens a resource stream from the archive mapped to the filename (case sensitive)
            virtual DataStreamPtr open(const String& filename) const;

            /// lists the contents of the archive
            virtual StringVectorPtr list(bool recursive = true, bool dirs = false);

            /// lists the contents of the archive. That means contents of all the archives merged, in the FileInfo structures.
            virtual FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false);

            /// performs a pattern match find on the archive files
            virtual StringVectorPtr find(const String& pattern, bool recursive = true,
                bool dirs = false);

            /// Searches for the given file name
            virtual bool exists(const String& filename);

            /** Searches for files that match the given pattern
             * @see find
            */
            virtual FileInfoListPtr findFileInfo(const String& pattern,
                bool recursive = true, bool dirs = false);

            /// reports case sensitiveness of this proxy archive
            virtual bool isCaseSensitive(void) const;

            /// reports the modification time of the given file
            time_t getModifiedTime(const String& filename);

        
        protected:
            /// Gets the archive for the specified file name, or NULL if file name is invalid
            Archive* getArchiveForFileName(const std::string& name) const;
        
            typedef std::list<Archive*> ArchiveList;
            
            /// List of archives present
            ArchiveList mArchiveList;
            /// Take the last archive as the first one (reversed order of evaluation)
            bool mReverseOrder;
    };

    /** Lowercase transforming file system archive.
    * @author Volca */
    class __EXPORT CaseLessTransformArchive : public ProxyArchive {
        public:
            CaseLessTransformArchive(const String& name, const String& archType);

            bool isCaseSensitive(void) const;

        protected:
            String transformName(const std::string& name);

    };

    /** String prefixing file system archive. Prefixes all file names in the archive with a custom specified string (the contents of the file name up to the first comma are used)
    * @author Volca */
    class __EXPORT PrefixingTransformArchive : public ProxyArchive {
        public:
            PrefixingTransformArchive(const String& name, const String& archType);

            bool isCaseSensitive(void) const;

        protected:
            String transformName(const std::string& name);
            
            String mPrefix;
    };

    // Factories, so we can actually use these
    class __EXPORT CaseLessTransformArchiveFactory : public ArchiveFactory {
        public:
            virtual ~CaseLessTransformArchiveFactory() { }

            const String& getType(void) const;

            Archive* createInstance(const String& name) {
                return new CaseLessTransformArchive(name, msTypeName);
            }

            void destroyInstance( Archive* arch) { delete arch; }
            
        protected:
            static const String msTypeName;
    };
    
    class __EXPORT PrefixingTransformArchiveFactory : public ArchiveFactory {
        public:
            virtual ~PrefixingTransformArchiveFactory() { }

            const String& getType(void) const;

            Archive* createInstance(const String& name) {
                return new PrefixingTransformArchive(name, msTypeName);
            }

            void destroyInstance( Archive* arch) { delete arch; }
            
        protected:
            static const String msTypeName;
    };
    
    class __EXPORT FirstOfArchiveFactory : public ArchiveFactory {
        public:
            virtual ~FirstOfArchiveFactory() {}

            const String& getType(void) const;

            Archive* createInstance(const String& name) {
                return new MultiArchive(name, msTypeName, false);
            }

            void destroyInstance( Archive* arch) { delete arch; }
            
        protected:
            static const String msTypeName;
    };
    
    class __EXPORT LastOfArchiveFactory : public ArchiveFactory {
        public:
            virtual ~LastOfArchiveFactory() {}

            const String& getType(void) const;

            Archive* createInstance(const String& name) {
                return new MultiArchive(name, msTypeName, true);
            }

            void destroyInstance( Archive* arch) { delete arch; }
            
        protected:
            static const String msTypeName;
    };

}

#endif


Alias:ProxyArchive

<HR>
Creative Commons Copyright -- Some rights reserved.


THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.

BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.

1. Definitions

  • "Collective Work" means a work, such as a periodical issue, anthology or encyclopedia, in which the Work in its entirety in unmodified form, along with a number of other contributions, constituting separate and independent works in themselves, are assembled into a collective whole. A work that constitutes a Collective Work will not be considered a Derivative Work (as defined below) for the purposes of this License.
  • "Derivative Work" means a work based upon the Work or upon the Work and other pre-existing works, such as a translation, musical arrangement, dramatization, fictionalization, motion picture version, sound recording, art reproduction, abridgment, condensation, or any other form in which the Work may be recast, transformed, or adapted, except that a work that constitutes a Collective Work will not be considered a Derivative Work for the purpose of this License. For the avoidance of doubt, where the Work is a musical composition or sound recording, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered a Derivative Work for the purpose of this License.
  • "Licensor" means the individual or entity that offers the Work under the terms of this License.
  • "Original Author" means the individual or entity who created the Work.
  • "Work" means the copyrightable work of authorship offered under the terms of this License.
  • "You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
  • "License Elements" means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, ShareAlike.

2. Fair Use Rights

Nothing in this license is intended to reduce, limit, or restrict any rights arising from fair use, first sale or other limitations on the exclusive rights of the copyright owner under copyright law or other applicable laws.

3. License Grant

Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:

  • to reproduce the Work, to incorporate the Work into one or more Collective Works, and to reproduce the Work as incorporated in the Collective Works;
  • to create and reproduce Derivative Works;
  • to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission the Work including as incorporated in Collective Works;
  • to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission Derivative Works.
  • For the avoidance of doubt, where the work is a musical composition:
    • Performance Royalties Under Blanket Licenses. Licensor waives the exclusive right to collect, whether individually or via a performance rights society (e.g. ASCAP, BMI, SESAC), royalties for the public performance or public digital performance (e.g. webcast) of the Work.
    • Mechanical Rights and Statutory Royalties. Licensor waives the exclusive right to collect, whether individually or via a music rights society or designated agent (e.g. Harry Fox Agency), royalties for any phonorecord You create from the Work ("cover version") and distribute, subject to the compulsory license created by 17 USC Section 115 of the US Copyright Act (or the equivalent in other jurisdictions).
    • Webcasting Rights and Statutory Royalties. For the avoidance of doubt, where the Work is a sound recording, Licensor waives the exclusive right to collect, whether individually or via a performance-rights society (e.g. SoundExchange), royalties for the public digital performance (e.g. webcast) of the Work, subject to the compulsory license created by 17 USC Section 114 of the US Copyright Act (or the equivalent in other jurisdictions).


The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. All rights not expressly granted by Licensor are hereby reserved.

4. Restrictions

The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:

  • You may distribute, publicly display, publicly perform, or publicly digitally perform the Work only under the terms of this License, and You must include a copy of, or the Uniform Resource Identifier for, this License with every copy or phonorecord of the Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Work that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Work itself to be made subject to the terms of this License. If You create a Collective Work, upon notice from any Licensor You must, to the extent practicable, remove from the Collective Work any credit as required by clause 4(c), as requested. If You create a Derivative Work, upon notice from any Licensor You must, to the extent practicable, remove from the Derivative Work any credit as required by clause 4(c), as requested.
  • You may distribute, publicly display, publicly perform, or publicly digitally perform a Derivative Work only under the terms of this License, a later version of this License with the same License Elements as this License, or a Creative Commons iCommons license that contains the same License Elements as this License (e.g. Attribution-ShareAlike 2.5 Japan). You must include a copy of, or the Uniform Resource Identifier for, this License or other license specified in the previous sentence with every copy or phonorecord of each Derivative Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Derivative Works that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder, and You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Derivative Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Derivative Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Derivative Work itself to be made subject to the terms of this License.
  • If you distribute, publicly display, publicly perform, or publicly digitally perform the Work or any Derivative Works or Collective Works, You must keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or (ii) if the Original Author and/or Licensor designate another party or parties (e.g. a sponsor institute, publishing entity, journal) for attribution in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; the title of the Work if supplied; to the extent reasonably practicable, the Uniform Resource Identifier, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and in the case of a Derivative Work, a credit identifying the use of the Work in the Derivative Work (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). Such credit may be implemented in any reasonable manner; provided, however, that in the case of a Derivative Work or Collective Work, at a minimum such credit will appear where any other comparable authorship credit appears and in a manner at least as prominent as such other comparable authorship credit.

5. Representations, Warranties and Disclaimer

UNLESS OTHERWISE AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE MATERIALS, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.

6. Limitation on Liability.

EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

7. Termination

  • This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Derivative Works or Collective Works from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
  • Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.

8. Miscellaneous

  • Each time You distribute or publicly digitally perform the Work or a Collective Work, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
  • Each time You distribute or publicly digitally perform a Derivative Work, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
  • If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
  • No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
  • This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.