Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/kicklib/src/libraries/core/Resource.cc @ 8090

Last change on this file since 8090 was 8081, checked in by rgrieder, 14 years ago

Fixed serious static initialisation problem. And I thought we caught them all…
Also replaced remaining references to Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP with our own code.

  • Property svn:eol-style set to native
File size: 4.1 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 "Resource.h"
30
31#include <boost/filesystem/path.hpp>
32#include <OgreException.h>
33#include <OgreFileSystem.h>
34#include <OgreResourceGroupManager.h>
35
36namespace orxonox
37{
38    const std::string& Resource::getDefaultResourceGroup()
39    {
40        return Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME;
41    }
42
43    DataStreamPtr Resource::open(const std::string& name)
44    {
45        return Ogre::ResourceGroupManager::getSingleton().openResource(name,
46            getDefaultResourceGroup(), true);
47    }
48
49    DataStreamListPtr Resource::openMulti(const std::string& pattern)
50    {
51        DataStreamListPtr resources(new Ogre::DataStreamList());
52        const Ogre::StringVector& groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
53        for (Ogre::StringVector::const_iterator it = groups.begin(); it != groups.end(); ++it)
54        {
55            DataStreamListPtr temp = Ogre::ResourceGroupManager::getSingleton().openResources(pattern, *it);
56            resources->insert(resources->end(), temp->begin(), temp->end());
57        }
58        return resources;
59    }
60
61    bool Resource::exists(const std::string& name)
62    {
63        try
64        {
65            Ogre::ResourceGroupManager::getSingleton().findGroupContainingResource(name);
66            return true;
67        }
68        catch (const Ogre::Exception&)
69        {
70            return false;
71        }
72    }
73
74    shared_ptr<ResourceInfo> Resource::getInfo(const std::string& name)
75    {
76        std::string group;
77        try
78        {
79            group = Ogre::ResourceGroupManager::getSingleton().findGroupContainingResource(name);
80        }
81        catch (const Ogre::Exception&)
82        {
83            return shared_ptr<ResourceInfo>();
84        }
85        Ogre::FileInfoListPtr infos = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(group, name);
86        for (Ogre::FileInfoList::const_iterator it = infos->begin(); it != infos->end(); ++it)
87        {
88            if (it->filename == name)
89            {
90                shared_ptr<ResourceInfo> ptr(new ResourceInfo());
91                ptr->filename = name;
92                ptr->path = it->path;
93                ptr->basename = it->basename;
94                ptr->group = group;
95                ptr->size = it->uncompressedSize;
96                if (dynamic_cast<Ogre::FileSystemArchive*>(it->archive) != NULL)
97                {
98                    boost::filesystem::path base(it->archive->getName());
99                    base /= it->filename;
100                    ptr->fileSystemPath = base.string();
101                }
102                return ptr;
103            }
104        }
105        return shared_ptr<ResourceInfo>();
106    }
107
108    StringVectorPtr Resource::findResourceNames(const std::string& pattern)
109    {
110        StringVectorPtr resourceNames(new Ogre::StringVector());
111        const Ogre::StringVector& groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
112        for (Ogre::StringVector::const_iterator it = groups.begin(); it != groups.end(); ++it)
113        {
114            StringVectorPtr temp = Ogre::ResourceGroupManager::getSingleton().findResourceNames(*it, pattern);
115            resourceNames->insert(resourceNames->end(), temp->begin(), temp->end());
116        }
117        return resourceNames;
118    }
119}
Note: See TracBrowser for help on using the repository browser.