Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickup2/src/libraries/core/Resource.cc @ 6551

Last change on this file since 6551 was 6412, checked in by dafrick, 15 years ago

Merged presentation2 branch into pickup2 branch.

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