Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/consolecommands2/src/libraries/core/MemoryArchive.cc @ 6451

Last change on this file since 6451 was 6417, checked in by rgrieder, 15 years ago

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
  • Property svn:eol-style set to native
File size: 4.5 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#include <boost/version.hpp>
36
37// Boost 1.36 has some issues with deprecated functions that have been omitted
38#if (BOOST_VERSION == 103600)
39#  define BOOST_HAS_BRANCH_PATH_FUNCTION has_parent_path
40#else
41#  define BOOST_HAS_BRANCH_PATH_FUNCTION has_branch_path
42#endif
43
44namespace orxonox
45{
46    using namespace Ogre;
47
48    MemoryArchive::ArchiveMap MemoryArchive::archives_s;
49
50    void MemoryArchive::load()
51    {
52        if (archives_s.find(this->getName()) == archives_s.end())
53            OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR, this->getName() + " - MemoryArchive not found.", "MemoryArchive");
54    }
55
56    DataStreamPtr MemoryArchive::open(const String& filename) const
57    {
58        const FileMap& files = archives_s[this->getName()];
59        FileMap::const_iterator itFile = files.find(filename);
60        if (itFile == files.end())
61            return DataStreamPtr();
62        else
63            return MemoryDataStreamPtr(new MemoryDataStream(itFile->second.first.get(), itFile->second.second));
64    }
65
66    void MemoryArchive::findFiles(const String& pattern, bool bRecursive,
67        bool bDirs, StringVector* simpleList, FileInfoList* detailList)
68    {
69        const FileMap& files = archives_s[this->getName()];
70
71        for (FileMap::const_iterator it = files.begin(); it != files.end(); ++it)
72        {
73            boost::filesystem::path file = it->first;
74            // Check pattern
75            if (!StringUtil::match(file.string(), pattern, true))
76                continue;
77            if (bDirs)
78                file = file.branch_path();
79            if (file.empty())
80                continue;
81            if (file.BOOST_HAS_BRANCH_PATH_FUNCTION() && !bRecursive)
82                continue;
83            if (simpleList)
84                simpleList->push_back(file.string());
85            if (detailList)
86            {
87                FileInfo fi;
88                fi.archive = this;
89                fi.filename = file.string();
90                fi.basename = file.leaf();
91                fi.path = file.branch_path().string();
92                fi.compressedSize = it->second.second;
93                fi.uncompressedSize = it->second.second;
94                detailList->push_back(fi);
95            }
96        }
97    }
98    StringVectorPtr MemoryArchive::list(bool recursive, bool dirs)
99    {
100        StringVectorPtr ret(new StringVector());
101        findFiles("*", recursive, dirs, ret.getPointer(), 0);
102        return ret;
103    }
104
105    FileInfoListPtr MemoryArchive::listFileInfo(bool recursive, bool dirs)
106    {
107        FileInfoListPtr ret(new FileInfoList());
108        findFiles("*", recursive, dirs, 0, ret.getPointer());
109        return ret;
110    }
111
112    StringVectorPtr MemoryArchive::find(const String& pattern,
113                                            bool recursive, bool dirs)
114    {
115        StringVectorPtr ret(new StringVector());
116        findFiles(pattern, recursive, dirs, ret.getPointer(), 0);
117        return ret;
118    }
119
120    FileInfoListPtr MemoryArchive::findFileInfo(const String& pattern,
121        bool recursive, bool dirs)
122    {
123        FileInfoListPtr ret(new FileInfoList());
124        findFiles(pattern, recursive, dirs, 0, ret.getPointer());
125        return ret;
126    }
127
128    bool MemoryArchive::exists(const String& filename)
129    {
130        const FileMap& files = archives_s[this->getName()];
131        return files.find(filename) != files.end();
132    }
133
134    const Ogre::String& MemoryArchiveFactory::getType(void) const
135    {
136        static std::string result("Memory");
137        return result;
138    }
139}
140
141#endif /* OGRE_VERSION < 0x010600 */
Note: See TracBrowser for help on using the repository browser.