| 1 | /************************************************************************ | 
|---|
| 2 |     filename:   OgreCEGUIResourceProvider.cpp | 
|---|
| 3 |     created:    8/7/2004 | 
|---|
| 4 |     author:             James '_mental_' O'Sullivan | 
|---|
| 5 |  | 
|---|
| 6 |     purpose:    Implements the Resource Provider common functionality | 
|---|
| 7 | *************************************************************************/ | 
|---|
| 8 | /************************************************************************* | 
|---|
| 9 |     Crazy Eddie's GUI System (http://www.cegui.org.uk) | 
|---|
| 10 |     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk) | 
|---|
| 11 |  | 
|---|
| 12 |     This library is free software; you can redistribute it and/or | 
|---|
| 13 |     modify it under the terms of the GNU Lesser General Public | 
|---|
| 14 |     License as published by the Free Software Foundation; either | 
|---|
| 15 |     version 2.1 of the License, or (at your option) any later version. | 
|---|
| 16 |  | 
|---|
| 17 |     This library is distributed in the hope that it will be useful, | 
|---|
| 18 |     but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 19 |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
| 20 |     Lesser General Public License for more details. | 
|---|
| 21 |  | 
|---|
| 22 |     You should have received a copy of the GNU Lesser General Public | 
|---|
| 23 |     License along with this library; if not, write to the Free Software | 
|---|
| 24 |     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | 
|---|
| 25 | *************************************************************************/ | 
|---|
| 26 | #include "OgreCEGUIResourceProvider.h" | 
|---|
| 27 |  | 
|---|
| 28 | #include <CEGUIExceptions.h> | 
|---|
| 29 | #include <OgreArchiveManager.h> | 
|---|
| 30 |  | 
|---|
| 31 |  | 
|---|
| 32 | // Start of CEGUI namespace section | 
|---|
| 33 | namespace CEGUI | 
|---|
| 34 | { | 
|---|
| 35 |     OgreCEGUIResourceProvider::OgreCEGUIResourceProvider() : ResourceProvider() | 
|---|
| 36 |     { | 
|---|
| 37 |         // set deafult resource group for Ogre | 
|---|
| 38 |         d_defaultResourceGroup = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME.c_str(); | 
|---|
| 39 |     } | 
|---|
| 40 |  | 
|---|
| 41 | //    void OgreResourceProvider::loadInputSourceContainer(const String& filename, InputSourceContainer& output) | 
|---|
| 42 | //   { | 
|---|
| 43 | //        Ogre::DataStreamPtr input = Ogre::ResourceGroupManager::getSingleton().openResource(filename.c_str()); | 
|---|
| 44 | // | 
|---|
| 45 | //              if (input.isNull()) | 
|---|
| 46 | //              { | 
|---|
| 47 | //                      throw InvalidRequestException((utf8*) | 
|---|
| 48 | //                              "Scheme::Scheme - Filename supplied for Scheme loading must be valid"); | 
|---|
| 49 | //              } | 
|---|
| 50 | // | 
|---|
| 51 | //       XERCES_CPP_NAMESPACE_USE | 
|---|
| 52 | //        size_t buffsz = input->size(); | 
|---|
| 53 | //        unsigned char* mem = reinterpret_cast<unsigned char*>(XMLPlatformUtils::fgArrayMemoryManager->allocate(buffsz)); | 
|---|
| 54 | //        memcpy(mem, input.getPointer()->getAsString().c_str(), buffsz); | 
|---|
| 55 | //        InputSource* mInputSource = new MemBufInputSource(mem, buffsz, filename.c_str(), true); | 
|---|
| 56 | //        input.setNull(); | 
|---|
| 57 | // | 
|---|
| 58 | //       output.setData(mInputSource); | 
|---|
| 59 | //    } | 
|---|
| 60 |  | 
|---|
| 61 |     void OgreCEGUIResourceProvider::loadRawDataContainer(const String& filename, RawDataContainer& output,  const String& resourceGroup) | 
|---|
| 62 |     { | 
|---|
| 63 |         String orpGroup; | 
|---|
| 64 |         if (resourceGroup.empty()) | 
|---|
| 65 |             orpGroup = d_defaultResourceGroup.empty() ? Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME.c_str() : d_defaultResourceGroup; | 
|---|
| 66 |         else | 
|---|
| 67 |             orpGroup = resourceGroup; | 
|---|
| 68 |  | 
|---|
| 69 |         Ogre::DataStreamPtr input = | 
|---|
| 70 |             Ogre::ResourceGroupManager::getSingleton().openResource(filename.c_str(), orpGroup.c_str()); | 
|---|
| 71 |  | 
|---|
| 72 |         if (input.isNull()) | 
|---|
| 73 |         { | 
|---|
| 74 |             throw InvalidRequestException((utf8*) | 
|---|
| 75 |                 "OgreCEGUIResourceProvider::loadRawDataContainer - Unable to open resource file '" + filename + (utf8*)"' in resource group '" + orpGroup + (utf8*)"'."); | 
|---|
| 76 |         } | 
|---|
| 77 |  | 
|---|
| 78 |         Ogre::String buf = input->getAsString(); | 
|---|
| 79 |         const size_t memBuffSize = buf.length(); | 
|---|
| 80 |  | 
|---|
| 81 |         unsigned char* mem = new unsigned char[memBuffSize]; | 
|---|
| 82 |         memcpy(mem, buf.c_str(), memBuffSize); | 
|---|
| 83 |  | 
|---|
| 84 |         output.setData(mem); | 
|---|
| 85 |         output.setSize(memBuffSize); | 
|---|
| 86 |     } | 
|---|
| 87 |  | 
|---|
| 88 |     void OgreCEGUIResourceProvider::unloadRawDataContainer(RawDataContainer& data) | 
|---|
| 89 |     { | 
|---|
| 90 |         if (data.getDataPtr()) | 
|---|
| 91 |         { | 
|---|
| 92 |             delete[] data.getDataPtr(); | 
|---|
| 93 |             data.setData(0); | 
|---|
| 94 |             data.setSize(0); | 
|---|
| 95 |         } | 
|---|
| 96 |     } | 
|---|
| 97 | } // End of  CEGUI namespace section | 
|---|