Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8144 was 6746, checked in by rgrieder, 15 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
RevLine 
[5653]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"
[6417]30
[6746]31#include <boost/filesystem/path.hpp>
[6417]32#include <OgreException.h>
[6746]33#include <OgreFileSystem.h>
[5653]34#include <OgreResourceGroupManager.h>
35
36namespace orxonox
37{
38    std::string Resource::DEFAULT_GROUP(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
39
[6417]40    DataStreamPtr Resource::open(const std::string& name)
[5653]41    {
[6417]42        return Ogre::ResourceGroupManager::getSingleton().openResource(name,
43            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
[5653]44    }
45
[6417]46    DataStreamListPtr Resource::openMulti(const std::string& pattern)
[5653]47    {
[6417]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;
[5653]56    }
57
[6417]58    bool Resource::exists(const std::string& name)
[5653]59    {
[6417]60        try
61        {
62            Ogre::ResourceGroupManager::getSingleton().findGroupContainingResource(name);
63            return true;
64        }
65        catch (const Ogre::Exception&)
66        {
67            return false;
68        }
[5653]69    }
70
[6417]71    shared_ptr<ResourceInfo> Resource::getInfo(const std::string& name)
[5653]72    {
[6417]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        }
[5653]82        Ogre::FileInfoListPtr infos = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(group, name);
[6501]83        for (Ogre::FileInfoList::const_iterator it = infos->begin(); it != infos->end(); ++it)
[5653]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;
[6746]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                }
[5653]99                return ptr;
100            }
101        }
102        return shared_ptr<ResourceInfo>();
103    }
[6417]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    }
[5653]116}
Note: See TracBrowser for help on using the repository browser.