Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/MemoryArchive.cc @ 5702

Last change on this file since 5702 was 5695, checked in by rgrieder, 15 years ago

Merged resource2 branch back to trunk.

IMPORTANT NOTE:
Upon this merge you need to specifically call your data directory "data_extern" when checking it out (when you don't provide a name, it will be just called 'trunk').
The new CMake variable is EXTERNAL_DATA_DIRECTORY. DATA_DIRECTORY now points to the one the source part of the repository.
UPDATE YOUR DATA DIRECTORY AS WELL!!!

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "MemoryArchive.h"
30
31#if OGRE_VERSION < 0x010600
32
33#include <OgreException.h>
34#include <boost/filesystem.hpp>
35
36namespace orxonox
37{
38    using namespace Ogre;
39
40    MemoryArchive::ArchiveMap MemoryArchive::archives_s;
41
42    void MemoryArchive::load()
43    {
44        if (archives_s.find(this->getName()) == archives_s.end())
45            OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR, this->getName() + " - MemoryArchive not found.", "MemoryArchive");
46    }
47
48    DataStreamPtr MemoryArchive::open(const String& filename) const
49    {
50        const FileMap& files = archives_s[this->getName()];
51        FileMap::const_iterator itFile = files.find(filename);
52        if (itFile == files.end())
53            return DataStreamPtr();
54        else
55            return MemoryDataStreamPtr(new MemoryDataStream(itFile->second.first.get(), itFile->second.second));
56    }
57
58    void MemoryArchive::findFiles(const String& pattern, bool bRecursive, 
59        bool bDirs, StringVector* simpleList, FileInfoList* detailList)
60    {
61        const FileMap& files = archives_s[this->getName()];
62
63        for (FileMap::const_iterator it = files.begin(); it != files.end(); ++it)
64        {
65            boost::filesystem::path file = it->first;
66            // Check pattern
67            if (!StringUtil::match(file.string(), pattern, true))
68                continue;
69            if (bDirs)
70                file = file.parent_path();
71            if (file.empty())
72                continue;
73            if (file.has_parent_path() && !bRecursive)
74                continue;
75            if (simpleList)
76                simpleList->push_back(file.string());
77            if (detailList)
78            {
79                FileInfo fi;
80                fi.archive = this;
81                fi.filename = file.string();
82                fi.basename = file.filename();
83                fi.path = file.parent_path().string();
84                fi.compressedSize = it->second.second;
85                fi.uncompressedSize = it->second.second;
86                detailList->push_back(fi);
87            }
88        }
89    }
90    StringVectorPtr MemoryArchive::list(bool recursive, bool dirs)
91    {
92        StringVectorPtr ret(new StringVector());
93        findFiles("*", recursive, dirs, ret.getPointer(), 0);
94        return ret;
95    }
96
97    FileInfoListPtr MemoryArchive::listFileInfo(bool recursive, bool dirs)
98    {
99        FileInfoListPtr ret(new FileInfoList());
100        findFiles("*", recursive, dirs, 0, ret.getPointer());
101        return ret;
102    }
103
104    StringVectorPtr MemoryArchive::find(const String& pattern,
105                                            bool recursive, bool dirs)
106    {
107        StringVectorPtr ret(new StringVector());
108        findFiles(pattern, recursive, dirs, ret.getPointer(), 0);
109        return ret;
110    }
111
112    FileInfoListPtr MemoryArchive::findFileInfo(const String& pattern, 
113        bool recursive, bool dirs)
114    {
115        FileInfoListPtr ret(new FileInfoList());
116        findFiles(pattern, recursive, dirs, 0, ret.getPointer());
117        return ret;
118    }
119
120    bool MemoryArchive::exists(const String& filename)
121        {
122        const FileMap& files = archives_s[this->getName()];
123        return files.find(filename) != files.end();
124        }
125
126    const Ogre::String& MemoryArchiveFactory::getType(void) const
127    {
128        static std::string result("Memory");
129        return result;
130    }
131}
132
133#endif /* OGRE_VERSION < 0x010600 */
Note: See TracBrowser for help on using the repository browser.