00001 /************************************************************************ 00002 filename: CEGUIDefaultResourceProvider.cpp 00003 created: 8/7/2004 00004 author: James '_mental_' O'Sullivan 00005 00006 purpose: Implements the Resource Manager common functionality 00007 *************************************************************************/ 00008 /************************************************************************* 00009 Crazy Eddie's GUI System (http://www.cegui.org.uk) 00010 Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk) 00011 00012 This library is free software; you can redistribute it and/or 00013 modify it under the terms of the GNU Lesser General Public 00014 License as published by the Free Software Foundation; either 00015 version 2.1 of the License, or (at your option) any later version. 00016 00017 This library is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 Lesser General Public License for more details. 00021 00022 You should have received a copy of the GNU Lesser General Public 00023 License along with this library; if not, write to the Free Software 00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 *************************************************************************/ 00026 #include "CEGUIDefaultResourceProvider.h" 00027 #include "CEGUIExceptions.h" 00028 00029 #include <xercesc/framework/LocalFileInputSource.hpp> 00030 #include <xercesc/util/XMLString.hpp> 00031 #include <fstream> 00032 00033 // Start of CEGUI namespace section 00034 namespace CEGUI 00035 { 00036 // void DefaultResourceProvider::loadInputSourceContainer(const String& filename, InputSourceContainer& output) 00037 // { 00038 // if (filename.empty() || (filename == (utf8*)"")) 00039 // { 00040 // throw InvalidRequestException((utf8*) 00041 // "DefaultResourceProvider::load - Filename supplied for data loading must be valid"); 00042 // } 00043 // 00044 // XERCES_CPP_NAMESPACE_USE 00045 // XMLCh* pval = XMLString::transcode(filename.c_str()); 00046 // InputSource* mInputSource = new LocalFileInputSource(pval); 00047 // XMLString::release(&pval); 00048 // 00049 // output.setData(mInputSource); 00050 // } 00051 00052 void DefaultResourceProvider::loadRawDataContainer(const String& filename, RawDataContainer& output, const String& resourceGroup) 00053 { 00054 if (filename.empty() || (filename == (utf8*)"")) 00055 { 00056 throw InvalidRequestException((utf8*) 00057 "DefaultResourceProvider::load - Filename supplied for data loading must be valid"); 00058 } 00059 00060 std::ifstream dataFile(filename.c_str(), std::ios::binary|std::ios::ate); 00061 if( dataFile.fail()) 00062 { 00063 throw InvalidRequestException((utf8*) 00064 "DefaultResourceProvider::load - " + filename + " does not exist"); 00065 } 00066 std::streampos size = dataFile.tellg(); 00067 dataFile.seekg (0, std::ios::beg); 00068 00069 unsigned char* buffer = new unsigned char [size]; 00070 00071 try { 00072 dataFile.read(reinterpret_cast<char*>(buffer), size); 00073 } 00074 catch(std::ifstream::failure e) { 00075 delete [] buffer; 00076 throw GenericException((utf8*) 00077 "DefaultResourceProvider::loadRawDataContainer - Problem reading " + filename); 00078 } 00079 00080 dataFile.close(); 00081 00082 //memcpy(container->getDataPtr(), buffer, size); 00083 output.setData(buffer); 00084 output.setSize(size); 00085 //delete [] buffer; 00086 } 00087 00088 } // End of CEGUI namespace section