[5624] | 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 "ResourceLocation.h" |
---|
| 30 | |
---|
| 31 | #include <OgreResourceGroupManager.h> |
---|
| 32 | #include "util/Exception.h" |
---|
| 33 | #include "core/CoreIncludes.h" |
---|
| 34 | #include "core/XMLPort.h" |
---|
| 35 | |
---|
| 36 | namespace orxonox |
---|
| 37 | { |
---|
| 38 | ResourceLocation::ResourceLocation(BaseObject* creator) |
---|
| 39 | : BaseObject(creator) |
---|
| 40 | { |
---|
| 41 | RegisterObject(ResourceLocation); |
---|
| 42 | |
---|
| 43 | // Default values |
---|
| 44 | archiveType_ = "FileSystem"; |
---|
| 45 | bRecursive_ = false; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | ResourceLocation::~ResourceLocation() |
---|
| 49 | { |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | void ResourceLocation::XMLPort(Element& xmlElement, XMLPort::Mode mode) |
---|
| 53 | { |
---|
| 54 | XMLPortParam(ResourceLocation, "path", setPath, getPath, xmlElement, mode); |
---|
| 55 | XMLPortParam(ResourceLocation, "archiveType", setArchiveType, getArchiveType, xmlElement, mode); |
---|
| 56 | XMLPortParam(ResourceLocation, "recursive", setRecursive, getRecursive, xmlElement, mode); |
---|
| 57 | if (path_.empty()) |
---|
| 58 | ThrowException(AbortLoading, "ResourceLocation: No path given."); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void ResourceLocation::load(const std::string& resourceGroup) |
---|
| 62 | { |
---|
| 63 | if (path_.empty()) |
---|
| 64 | ThrowException(InitialisationFailed, "ResourceLocation: Trying to add one without the path being set"); |
---|
| 65 | // Add it to the Ogre paths |
---|
| 66 | Ogre::ResourceGroupManager::getSingleton().addResourceLocation( |
---|
| 67 | this->getPath(), this->getArchiveType(), resourceGroup, this->getRecursive()); |
---|
| 68 | resourceGroup_ = resourceGroup; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | void ResourceLocation::unload() |
---|
| 72 | { |
---|
| 73 | // Remove from Ogre paths |
---|
| 74 | resourceGroup_.erase(); |
---|
| 75 | try |
---|
| 76 | { |
---|
| 77 | Ogre::ResourceGroupManager::getSingleton().removeResourceLocation( |
---|
| 78 | this->getPath(), this->getResourceGroup()); |
---|
| 79 | } |
---|
| 80 | catch (const std::exception& ex) |
---|
| 81 | { |
---|
| 82 | COUT(1) << "Removing of a ResourceLocation failed: " << ex.what() << std::endl; |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | } |
---|