Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/Resource.cc @ 7284

Last change on this file since 7284 was 6746, checked in by rgrieder, 14 years ago

Merged gamestates2 branch back to trunk.
This brings in some heavy changes in the GUI framework.
It should also fix problems with triggered asserts in the InputManager.

Note: PickupInventory does not seem to work —> Segfault when showing because before, the owner in GUIOverlay::setGUIName is already NULL.
I haven't tested it before, so I can't tell whether it's my changes.

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