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 <fstream> 00030 00031 // Start of CEGUI namespace section 00032 namespace CEGUI 00033 { 00034 // void DefaultResourceProvider::loadInputSourceContainer(const String& filename, InputSourceContainer& output) 00035 // { 00036 // if (filename.empty() || (filename == (utf8*)"")) 00037 // { 00038 // throw InvalidRequestException((utf8*) 00039 // "DefaultResourceProvider::load - Filename supplied for data loading must be valid"); 00040 // } 00041 // 00042 // XERCES_CPP_NAMESPACE_USE 00043 // XMLCh* pval = XMLString::transcode(filename.c_str()); 00044 // InputSource* mInputSource = new LocalFileInputSource(pval); 00045 // XMLString::release(&pval); 00046 // 00047 // output.setData(mInputSource); 00048 // } 00049 00050 void DefaultResourceProvider::loadRawDataContainer(const String& filename, RawDataContainer& output, const String& resourceGroup) 00051 { 00052 if (filename.empty() || (filename == (utf8*)"")) 00053 { 00054 throw InvalidRequestException((utf8*) 00055 "DefaultResourceProvider::load - Filename supplied for data loading must be valid"); 00056 } 00057 00058 std::ifstream dataFile(filename.c_str(), std::ios::binary|std::ios::ate); 00059 if( dataFile.fail()) 00060 { 00061 throw InvalidRequestException((utf8*) 00062 "DefaultResourceProvider::load - " + filename + " does not exist"); 00063 } 00064 std::streampos size = dataFile.tellg(); 00065 dataFile.seekg (0, std::ios::beg); 00066 00067 unsigned char* buffer = new unsigned char [size]; 00068 00069 try { 00070 dataFile.read(reinterpret_cast<char*>(buffer), size); 00071 } 00072 catch(std::ifstream::failure e) { 00073 delete [] buffer; 00074 throw GenericException((utf8*) 00075 "DefaultResourceProvider::loadRawDataContainer - Problem reading " + filename); 00076 } 00077 00078 dataFile.close(); 00079 00080 //memcpy(container->getDataPtr(), buffer, size); 00081 output.setData(buffer); 00082 output.setSize(size); 00083 //delete [] buffer; 00084 } 00085 00086 } // End of CEGUI namespace section