//----------------------------------------------------------------------------//
void DefaultResourceProvider::unloadRawDataContainer(RawDataContainer& data)
{
    uint8* const ptr = data.getDataPtr();
    delete[] ptr;
    data.setData(0);
    data.setSize(0);
}
Exemplo n.º 2
0
    void XercesParser::doParse(XERCES_CPP_NAMESPACE::SAX2XMLReader* parser, const String& xmlFilename, const String& resourceGroup)
    {
        XERCES_CPP_NAMESPACE_USE;

        // use resource provider to load file data
        RawDataContainer rawXMLData;
        System::getSingleton().getResourceProvider()->loadRawDataContainer(xmlFilename, rawXMLData, resourceGroup);
        MemBufInputSource  fileData(
            rawXMLData.getDataPtr(),
            static_cast<const unsigned int>(rawXMLData.getSize()),
            xmlFilename.c_str(),
            false);

         // perform parse
         try
         {
             parser->parse(fileData);
         }
         catch(...)
         {
             // use resource provider to release loaded XML source (if it supports this)
             System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawXMLData);

             throw;
         }

         // use resource provider to release loaded XML source (if it supports this)
         System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawXMLData);
    }
Exemplo n.º 3
0
void GUIRenderer::initialize() {

	// BOOTSTRAP MANUAL
	guiRenderer = &Direct3D11Renderer::create(renderContext.device, renderContext.context);
	System::performVersionTest(CEGUI_VERSION_ABI, 208, CEGUI_FUNCTION_NAME);
	if (System::getSingletonPtr()) CEGUI_THROW(InvalidRequestException("CEGUI::System object is already initialised."));
	System::create(*guiRenderer, &ceguiResourceProvider);
	// BOOTSTRAP MANUAL

	WindowManager& windowManager = WindowManager::getSingleton();
	CEGUI::Window* rootWindow = windowManager.createWindow( "DefaultWindow", "root" );
	System::getSingleton().getDefaultGUIContext().setRootWindow( rootWindow );

	ImageManager::setImagesetDefaultResourceGroup("imagesets");
	Font::setDefaultResourceGroup("fonts");
	Scheme::setDefaultResourceGroup("schemes");
	WidgetLookManager::setDefaultResourceGroup("looknfeels");
	WindowManager::setDefaultResourceGroup("layouts");
	
	DataContainer dllData = DLLResourceLoader::loadCEGUI_scheme(resourcesHmodule);

	RawDataContainer cScheme;
	cScheme.setData((CEGUI::uint8*) dllData.dataBlob);
	cScheme.setSize((size_t) dllData.dataSize);

	SchemeManager::getSingleton().createFromContainer(cScheme);

	cScheme.setData(0);
	cScheme.setSize(0);
}
Exemplo n.º 4
0
/*************************************************************************
	Load texture from file.  Texture is made to be same size as image in
	file.
*************************************************************************/
void DirectX9Texture::loadFromFile(const String& filename, const String& resourceGroup)
{
	freeD3DTexture();
	
	// load the file via the resource provider
	RawDataContainer texFile;
	System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, texFile, resourceGroup);

	D3DXIMAGE_INFO texInfo;
	HRESULT hr = D3DXCreateTextureFromFileInMemoryEx(((DirectX9Renderer*)getRenderer())->getDevice(), texFile.getDataPtr(),
            static_cast<UINT>(texFile.getSize()), D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, 1, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
            D3DX_DEFAULT, D3DX_DEFAULT, 0, &texInfo, NULL, &d_d3dtexture);
	
	System::getSingleton().getResourceProvider()->unloadRawDataContainer(texFile);
	
	if (SUCCEEDED(hr))
	{
		d_width		= (ushort)texInfo.Width;
		d_height	= (ushort)texInfo.Height;

		d_filename = filename;
        d_resourceGroup = resourceGroup;
		d_isMemoryTexture = true;
		d_isRenderTarget = false;
	}
	else
	{
		throw RendererException((utf8*)"Failed to create Texture object from file '" + filename );
	}

}
Exemplo n.º 5
0
//----------------------------------------------------------------------------//
void LuaScriptModule::executeScriptFile_impl(const String& filename,
    const String& resourceGroup, const int err_idx, const int top)
{
    // load file
    RawDataContainer raw;
    System::getSingleton().getResourceProvider()->loadRawDataContainer(filename,
        raw, resourceGroup.empty() ? d_defaultResourceGroup : resourceGroup);

    // load code into lua
    int loaderr = luaL_loadbuffer(d_state,
                                  reinterpret_cast<char*>(raw.getDataPtr()),
                                  raw.getSize(), filename.c_str());

    System::getSingleton().getResourceProvider()->unloadRawDataContainer( raw );

    if (loaderr)
    {
        String errMsg = lua_tostring(d_state,-1);
        lua_settop(d_state,top);
        CEGUI_THROW(ScriptException("Unable to execute Lua script file: '" +
            filename + "'\n\n" + errMsg + "\n"));
    }

    // call it
    if (lua_pcall(d_state, 0, 0, err_idx))
    {
        String errMsg = lua_tostring(d_state,-1);
        lua_settop(d_state,top);
        CEGUI_THROW(ScriptException("Unable to execute Lua script file: '" +
            filename + "'\n\n" + errMsg + "\n"));
    }

    lua_settop(d_state,top); // just in case :P
}
//----------------------------------------------------------------------------//
void OgreResourceProvider::loadRawDataContainer(const String& filename,
                                                RawDataContainer& output,
                                                const String& resourceGroup)
{
    String orpGroup;
    if (resourceGroup.empty())
        orpGroup = d_defaultResourceGroup.empty() ?
            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME.c_str() :
            d_defaultResourceGroup;
    else
        orpGroup = resourceGroup;

    Ogre::DataStreamPtr input = Ogre::ResourceGroupManager::getSingleton().
        openResource(filename.c_str(), orpGroup.c_str());

    if (input.isNull())
        CEGUI_THROW(InvalidRequestException(
            "Unable to open resource file '" + filename +
            "' in resource group '" + orpGroup + "'."));

    Ogre::String buf = input->getAsString();
    const size_t memBuffSize = buf.length();

    unsigned char* mem = new unsigned char[memBuffSize];
    memcpy(mem, buf.c_str(), memBuffSize);

    output.setData(mem);
    output.setSize(memBuffSize);
}
Exemplo n.º 7
0
void ExpatParser::parseXML(XMLHandler& handler, const RawDataContainer& source, const String& /*schemaName*/, bool /*allowXmlValidation*/)
{
    // All stuff goes here
    XML_Parser parser = XML_ParserCreate(0); // Create a parser

    if (!parser)
    {
        CEGUI_THROW(GenericException("Unable to create a new Expat Parser"));
    }

    XML_SetUserData(parser, (void*)&handler); // Initialise user data
    XML_SetElementHandler(parser, startElement, endElement); // Register callback for elements
    XML_SetCharacterDataHandler(parser, characterData); // Register callback for character data

    // Parse the data (note that the last true parameter tels Expat that this is the last chunk of the document
    if (!XML_Parse(parser, reinterpret_cast<const char*>(source.getDataPtr()), source.getSize(), true))
    {
        String exception (String((const encoded_char*)"XML Parsing error '") +
                          String((const encoded_char*)XML_ErrorString(XML_GetErrorCode(parser))) +
                          String((const encoded_char*)"' at line ") +
                          PropertyHelper<uint>::toString(XML_GetCurrentLineNumber(parser)));
        // (We know it is a valid pointer, otherwise an exception would have been thrown above.)
        XML_ParserFree(parser);
        CEGUI_THROW(GenericException(exception));
    }

    // (We know it is a valid pointer, otherwise an exception would have been thrown above.)
    XML_ParserFree(parser);
}
Exemplo n.º 8
0
void LibxmlParser::parseXML(XMLHandler& handler,
                            const RawDataContainer& source,
                            const String& /*schemaName*/,
                            bool /*allowXmlValidation*/)
{
    xmlDocPtr doc = xmlParseMemory(
        reinterpret_cast<const char*>(source.getDataPtr()),
        source.getSize());

    if (!doc)
    {
        xmlError* err = xmlGetLastError();

        CEGUI_THROW(GenericException(
            String("xmlParseMemory failed in file: '") +
            err->file + "' at line number" +
            PropertyHelper<uint>::toString(err->line) + ".  Error is:" +
            err->message));
    }

    // get root element
    xmlNode* root = xmlDocGetRootElement(doc);

    // process all elements from root to end of doc
    processXMLElement(handler, root);

    // release the xmlDoc 
    xmlFreeDoc(doc);
}
//----------------------------------------------------------------------------//
void OgreResourceProvider::unloadRawDataContainer(RawDataContainer& data)
{
    if (data.getDataPtr())
    {
        delete[] data.getDataPtr();
        data.setData(0);
        data.setSize(0);
    }
}
    void DefaultResourceProvider::loadRawDataContainer(const String& filename, RawDataContainer& output, const String& resourceGroup)
    {
        if (filename.empty() || (filename == (utf8*)""))
        {
            throw InvalidRequestException((utf8*)
                "DefaultResourceProvider::load - Filename supplied for data loading must be valid");
        }


        std::wstring strFilename1 = filename.c_wstring ();
        std::wstring strFilename2 = System::getSingleton ().GetGuiWorkingDirectory().c_wstring () + strFilename1;

        // If supplied filename looks like it is absolute, try that first
        bool bIsAbsolutePath = false;
        {
            SString strTemp = PathConform ( filename.c_str () );
            if ( strTemp.Contains ( ":" ) || strTemp.BeginsWith ( "\\" ) )
                std::swap ( strFilename1, strFilename2 );
        }


        std::ifstream dataFile;
        dataFile.open(strFilename2.c_str (), std::ios::binary|std::ios::ate);

        if( dataFile.fail())
        {
            dataFile.clear();
            dataFile.open(strFilename1.c_str (), std::ios::binary|std::ios::ate);
            if( dataFile.fail())
            {
                throw InvalidRequestException((utf8*)
                    "DefaultResourceProvider::load - " + filename + " does not exist");
            }
        }
        std::streampos size = dataFile.tellg();
        dataFile.seekg (0, std::ios::beg);

        unsigned char* buffer = new unsigned char [(uint)size];

        try {
            dataFile.read(reinterpret_cast<char*>(buffer), size);
        }
        catch(std::ifstream::failure e) {
            delete [] buffer;
            throw GenericException((utf8*)
                "DefaultResourceProvider::loadRawDataContainer - Problem reading " + filename);
        }

        dataFile.close();

        //memcpy(container->getDataPtr(), buffer, size);
        output.setData(buffer);
        output.setSize((size_t)size);
        //delete [] buffer;
    }
Exemplo n.º 11
0
    TinyXMLDocument::TinyXMLDocument(XMLHandler& handler, const String& filename, const String& schemaName, const String& resourceGroup)
    {
        d_handler = &handler;

        // use resource provider to load file data
        // Fixed using patch from tracker item #000057
        // cegui_mk2-0.4.1-fixtinyxml.patch
        RawDataContainer rawXMLData;
        System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, rawXMLData, resourceGroup);

        // Create a buffer with extra bytes for a newline and a terminating null
        size_t size = rawXMLData.getSize();
        char* buf = new char[size + 2];
        memcpy(buf, rawXMLData.getDataPtr(), size);
        // PDT: The addition of the newline is a kludge to resolve an issue
        // whereby parse returns 0 if the xml file has no newline at the end but
        // is otherwise well formed.
        buf[size] = '\n';
        buf[size+1] = 0;

        // Parse the document
        CEGUI_TINYXML_NAMESPACE::TiXmlDocument doc;
        if (!doc.Parse((const char*)buf))
        {
            // error detected, cleanup out buffers
            delete[] buf;
            System::getSingleton().getResourceProvider()->
                unloadRawDataContainer(rawXMLData);
            // throw exception
            throw FileIOException("TinyXMLParser: an error occurred while "
                                  "parsing the XML document '" + filename +
                                  "' - check it for potential errors!.");
        }

        const CEGUI_TINYXML_NAMESPACE::TiXmlElement* currElement = doc.RootElement();
        if (currElement)
        {
            try
            {
                // function called recursively to parse xml data
                processElement(currElement);
            }
            catch(...)
            {
                delete [] buf;
                System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawXMLData);
                throw;
            }
        } // if (currElement)

        // Free memory
        delete [] buf;
        System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawXMLData);
    }
Exemplo n.º 12
0
    void XercesParser::initialiseSchema(XERCES_CPP_NAMESPACE::SAX2XMLReader* reader, const String& schemaName, const String& xmlFilename, const String& resourceGroup)
    {
        XERCES_CPP_NAMESPACE_USE;

        // enable schema use and set validation options
        reader->setFeature(XMLUni::fgXercesSchema, true);
        reader->setFeature(XMLUni::fgSAX2CoreValidation, true);
        reader->setFeature(XMLUni::fgXercesValidationErrorAsFatal, true);

        // load in the raw schema data
        RawDataContainer rawSchemaData;
        // try base filename first, from default resource group
        try
        {
            Logger::getSingleton().logEvent("XercesParser::initialiseSchema - Attempting to load schema from file '" + schemaName + "'.");
            System::getSingleton().getResourceProvider()->loadRawDataContainer(schemaName, rawSchemaData, d_defaultSchemaResourceGroup);
        }
        // oops, no file.  Try an alternative instead, using base path and
        // resource group from the XML file we're going to be processing.
        catch(InvalidRequestException)
        {
            // get path from filename
            String schemaFilename;
            size_t pos = xmlFilename.rfind("/");
            if (pos == String::npos) pos = xmlFilename.rfind("\\");
            if (pos != String::npos) schemaFilename.assign(xmlFilename, 0, pos + 1);
            // append schema filename
            schemaFilename += schemaName;
            // re-try the load operation.
            Logger::getSingleton().logEvent("XercesParser::initialiseSchema - Attempting to load schema from file '" + schemaFilename + "'.");
            System::getSingleton().getResourceProvider()->loadRawDataContainer(schemaFilename, rawSchemaData, resourceGroup);
        }
        // wrap schema data in a xerces MemBufInputSource object
        MemBufInputSource  schemaData(
            rawSchemaData.getDataPtr(),
            static_cast<const unsigned int>(rawSchemaData.getSize()),
            schemaName.c_str(),
            false);
        reader->loadGrammar(schemaData, Grammar::SchemaGrammarType, true);
        // enable grammar reuse
        reader->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, true);

        // set schema for usage
        XMLCh* pval = XMLString::transcode(schemaName.c_str());
        reader->setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation, pval);
        XMLString::release(&pval);
        Logger::getSingleton().logEvent("XercesParser::initialiseSchema - XML schema file '" + schemaName + "' has been initialised.");

        // use resource provider to release loaded schema data (if it supports this)
        System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawSchemaData);
    }
Exemplo n.º 13
0
void StdDataLoop::execPart2() {
    if (verbose)
        std::cout << __PRETTY_FUNCTION__ << std::endl;
    unsigned count = 0;
    uint32_t done = 0;
    //uint32_t rate = 0;
    //uint32_t curCnt = 0;
    unsigned iterations = 0;
    //uint32_t startAddr = 0;


    std::vector<RawData*> tmp_storage;
    RawData *newData = NULL;
    RawDataContainer *rdc = new RawDataContainer();
    while (done == 0) {
        //rate = g_rx->getDataRate();
        //curCnt = g_rx->getCurCount();
        done = g_tx->isTrigDone();
        do {
            newData =  g_rx->readData();
            iterations++;
            if (newData != NULL) {
                rdc->add(newData);
                count += newData->words;
            }
        } while (newData != NULL);
        delete newData;
    }
    // Gather rest of data after timeout (~0.1ms)
    std::this_thread::sleep_for(std::chrono::microseconds(500));
    do {
        //curCnt = g_rx->getCurCount();
        newData =  g_rx->readData();
        iterations++;
        if (newData != NULL) {
            rdc->add(newData);
            count += newData->words;
        }
    } while (newData != NULL);
    delete newData;
    
    rdc->stat = *g_stat;
    storage->pushData(rdc);
        
    if (verbose)
        std::cout << " --> Received " << count << " words! " << iterations << std::endl;
    m_done = true;
    counter++;
}
Exemplo n.º 14
0
	void IrrlichtTexture::loadFromFile(const String& filename, const String& resourceGroup)
	{
		freeTexture();

        RawDataContainer texFile;
        System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, texFile, resourceGroup);

        IrrlichtMemoryFile imf(filename, texFile.getDataPtr(), texFile.getSize());

		driver->setTextureCreationFlag(irr::video::ETCF_CREATE_MIP_MAPS,true);
		tex=driver->getTexture(&imf);
		tex->grab();

        // unload file data buffer
        System::getSingleton().getResourceProvider()->unloadRawDataContainer(texFile);
        updateCachedScaleValues();
	}
Exemplo n.º 15
0
    TinyXMLDocument::TinyXMLDocument(XMLHandler& handler, const RawDataContainer& source, const String& /*schemaName*/)
    {
        d_handler = &handler;

        // Create a buffer with extra bytes for a newline and a terminating null
        size_t size = source.getSize();
        char* buf = new char[size + 2];
        memcpy(buf, source.getDataPtr(), size);
        // PDT: The addition of the newline is a kludge to resolve an issue
        // whereby parse returns 0 if the xml file has no newline at the end but
        // is otherwise well formed.
        buf[size] = '\n';
        buf[size+1] = 0;

        // Parse the document
        TiXmlDocument doc;
        if (!doc.Parse((const char*)buf))
        {
            // error detected, cleanup out buffers
            delete[] buf;

            // throw exception
            throw FileIOException("an error occurred while "
                "parsing the XML document - check it for potential errors!.");
        }

        const TiXmlElement* currElement = doc.RootElement();
        if (currElement)
        {
            try
            {
                // function called recursively to parse xml data
                processElement(currElement);
            }
            catch (...)
            {
                delete [] buf;

                throw;
            }
        } // if (currElement)

        // Free memory
        delete [] buf;
    }
Exemplo n.º 16
0
    void XMLParser::parseXMLString(XMLHandler& handler, const String& source, const String& schemaName)
    {
        // Put the source string into a RawDataContainer
        RawDataContainer rawXMLData;

        const char* c_str = source.c_str();
        rawXMLData.setData((uint8*)c_str);
        rawXMLData.setSize(strlen(c_str));

        try
        {
        	// The actual parsing action (this is overridden and depends on the specific parser)
        	parseXML(handler, rawXMLData, schemaName);
        }
        catch(...)
        {
        	// make sure we don't allow rawXMLData to release String owned data no matter what!
        	rawXMLData.setData(0);
			rawXMLData.setSize(0);

			CEGUI_RETHROW;
        }

        // !!! We must not allow DataContainer to delete String owned data,
        //     therefore, we set it's data to 0 to avoid double-deletion
        rawXMLData.setData(0);
        rawXMLData.setSize(0);
    }
Exemplo n.º 17
0
void StdDataGatherer::execPart2() {
    if (verbose)
        std::cout << __PRETTY_FUNCTION__ << std::endl;
    unsigned count = 0;
    uint32_t done = 0;
    uint32_t rate = 0;

    signaled = 0;
    signal(SIGINT, [](int signum){signaled = 1;});

    std::cout << "### IMPORTANT ### Going into endless loop, interrupt with ^c (SIGINT)!" << std::endl;

    std::vector<RawData*> tmp_storage;
    RawData *newData = NULL;
    while (done == 0) {
        RawDataContainer *rdc = new RawDataContainer();
        rate = g_rx->getDataRate();
        if (verbose)
            std::cout << " --> Data Rate: " << rate/256.0/1024.0 << " MB/s" << std::endl;
        done = g_tx->isTrigDone();
        do {
            newData =  g_rx->readData();
            if (newData != NULL) {
                rdc->add(newData);
                count += newData->words;
            }
        } while (newData != NULL);
        delete newData;
        rdc->stat = *g_stat;
        storage->pushData(rdc);
        if (signaled == 1) {
            std::cout << "Caught interrupt, stopping data taking!" << std::endl;
            std::cout << "Abort will leave buffers full of data!" << std::endl;
            g_tx->toggleTrigAbort();
        }
        std::this_thread::sleep_for(std::chrono::microseconds(500));
    }
        
    m_done = true;
    counter++;
}
Exemplo n.º 18
0
	void IrrlichtResourceProvider::loadRawDataContainer(const String& filename, RawDataContainer& output, const String& resourceGroup)
	{
		if(!fsys->existFile(filename.c_str()))
		{
			String sMsg=(utf8*)"IrrlichtResourceProvider::loadRawDataContainer - Filename supplied for loading must be valid";
			sMsg+=(utf8*)" ["+filename+(utf8*)"]";
			throw InvalidRequestException(sMsg);
		}
		else
		{
			irr::u8* input;
			irr::u32 input_size;
			irr::io::IReadFile* f=fsys->createAndOpenFile(filename.c_str());
			input_size=f->getSize();
			input= new irr::u8[input_size];
			f->read(input,input_size);

			output.setData(input);
			output.setSize(input_size);
		}
	}
//----------------------------------------------------------------------------//
void DefaultResourceProvider::loadRawDataContainer(const String& filename,
                                                   RawDataContainer& output,
                                                   const String& resourceGroup)
{
    if (filename.empty())
        CEGUI_THROW(InvalidRequestException("DefaultResourceProvider::load: "
            "Filename supplied for data loading must be valid"));

    const String final_filename(getFinalFilename(filename, resourceGroup));

#if defined(__WIN32__) || defined(_WIN32)
    FILE* file = _wfopen(Utf8ToUtf16(final_filename.c_str()).c_str(), L"rb");
#else
    FILE* file = fopen(final_filename.c_str(), "rb");
#endif

    if (file == 0)
        CEGUI_THROW(InvalidRequestException("DefaultResourceProvider::load: " +
            final_filename + " does not exist"));

    fseek(file, 0, SEEK_END);
    const long size = ftell(file);
    fseek(file, 0, SEEK_SET);

    unsigned char* const buffer = new unsigned char[size];

    const size_t size_read = fread(buffer, sizeof(char), size, file);
    fclose(file);

    if (size_read != size)
    {
        delete[] buffer;
        CEGUI_THROW(GenericException(
            "DefaultResourceProvider::loadRawDataContainer: "
            "A problem occurred while reading file: " + final_filename));
    }

    output.setData(buffer);
    output.setSize(size);
}
Exemplo n.º 20
0
    TinyXMLDocument::TinyXMLDocument(XMLHandler& handler, const String& filename, const String& schemaName, const String& resourceGroup)
    {
        d_handler = &handler;

        // use resource provider to load file data
        // Fixed using patch from tracker item #000057
        // cegui_mk2-0.4.1-fixtinyxml.patch
        RawDataContainer rawXMLData;
        System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, rawXMLData, resourceGroup);
        
        // Create a buffer with the missing extra byte 
        size_t size = rawXMLData.getSize();
        char* buf = new char[size + 1];
        memcpy(buf, rawXMLData.getDataPtr(), size);
        buf[size] = 0; 

		try 
		{
			// Parse the document 
			CEGUITinyXML::TiXmlDocument doc;
			doc.Parse((const char*)buf);
			const CEGUITinyXML::TiXmlElement* currElement = doc.RootElement();
			if (currElement)
			{
				// function called recursively to parse xml data
				processElement(currElement);
			} // if (currElement)
		}
		catch(...)
		{
			delete [] buf;
			System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawXMLData);
			throw;
		}
		// Free memory 
        delete [] buf;
        System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawXMLData);
    }
Exemplo n.º 21
0
	void NeLResourceProvider::loadRawDataContainer(const String &filename, RawDataContainer &output, const String& resourceGroup)
	{
		if(!NLMISC::CPath::exists(filename.c_str()))
		{
			nlinfo("Scheme::Scheme - Filename supplied for Scheme loading must be valid [%s]",filename.c_str());
			String sMsg=(utf8*)"Scheme::Scheme - Filename supplied for Scheme loading must be valid";
			sMsg+=(utf8*)" ["+filename+(utf8*)"]";
			throw InvalidRequestException(sMsg);
		}

		uint32 input_size;
		std::string fname=NLMISC::CPath::lookup(filename.c_str());
		NLMISC::CIFile f(NLMISC::CPath::lookup(filename.c_str()));

		// get the size of the file and create a temp container.
		input_size=f.getFileSize();
		uint8 *input=new uint8[input_size+1];
		input[input_size]=0;
		f.serialBuffer(input,input_size);
		f.close();

		output.setData(input);
		output.setSize(input_size);
	}
Exemplo n.º 22
0
//----------------------------------------------------------------------------//
RapidXMLDocument::RapidXMLDocument(XMLHandler& handler,
                                   const String& filename,
                                   const String& /*schemaName*/,
                                   const String& resourceGroup)
{
    d_handler = &handler;

    // use resource provider to load file data
    RawDataContainer rawXMLData;
    System::getSingleton().getResourceProvider()->
        loadRawDataContainer(filename, rawXMLData, resourceGroup);

    // Create a buffer with extra bytes for a newline and a terminating null
    size_t size = rawXMLData.getSize();
    char* buf = new char[size + 2];
    memcpy(buf, rawXMLData.getDataPtr(), size);
    // PDT: The addition of the newline is a kludge to resolve an issue
    // whereby parse returns 0 if the xml file has no newline at the end but
    // is otherwise well formed.
    buf[size] = '\n';
    buf[size + 1] = 0;

    // Parse the document
    rapidxml::xml_document<> doc;    // character type defaults to char

    try
    {
        doc.parse<0>(buf);          // 0 means default parse flags
    }
    catch (...)
    {
        // error detected, cleanup out buffers
        delete[] buf;
        System::getSingleton().getResourceProvider()->
        unloadRawDataContainer(rawXMLData);
        // throw exception
        throw FileIOException("RapidXMLParser: an error occurred while "
                              "parsing the XML document '" + filename +
                              "' - check it for potential errors!.");
    }

    rapidxml::xml_node<>* currElement = doc.first_node();

    if (currElement)
    {
        try
        {
            // function called recursively to parse xml data
            processElement(currElement);
        }
        catch (...)
        {
            delete[] buf;
            System::getSingleton().getResourceProvider()->
                unloadRawDataContainer(rawXMLData);
            throw;
        }
    }

    // Free memory
    delete[] buf;
    System::getSingleton().getResourceProvider()->
        unloadRawDataContainer(rawXMLData);
}
//----------------------------------------------------------------------------//
void MinizipResourceProvider::loadRawDataContainer(const String& filename,
                                                   RawDataContainer& output,
                                                   const String& resourceGroup)
{
    const String final_filename = getFinalFilename(filename, resourceGroup);

    if (d_pimpl->d_loadLocal && doesFileExist(final_filename))
    {
        DefaultResourceProvider::loadRawDataContainer(filename,
                                                      output,
                                                      resourceGroup);
        return;
    }

    if (d_pimpl->d_zfile == 0)
    {
        throw InvalidRequestException(
            "'" + final_filename + "' cannot be "
            "loaded because the archive has not been set");
    }

#if CEGUI_STRING_CLASS == CEGUI_STRING_CLASS_STD
    if (unzLocateFile(d_pimpl->d_zfile, final_filename.c_str(), 0) != UNZ_OK)
#elif CEGUI_STRING_CLASS == CEGUI_STRING_CLASS_UNICODE
    if (unzLocateFile(d_pimpl->d_zfile, final_filename.toUtf8String().c_str(), 0) != UNZ_OK)
#endif
    {
        throw InvalidRequestException("'" + final_filename +
            "' does not exist");
    }

    unz_file_info file_info;

    if (unzGetCurrentFileInfo(d_pimpl->d_zfile, &file_info,
                              0, 0, 0, 0, 0, 0) != UNZ_OK)
    {
        throw FileIOException("'" + final_filename +
            "' error reading file header");
    }

    if (unzOpenCurrentFile(d_pimpl->d_zfile) != Z_OK)
    {
        throw FileIOException("'" + final_filename +
            "' error opening file");
    }

    std::uint64_t size = file_info.uncompressed_size;
    std::uint8_t* buffer = new std::uint8_t[size];

    if (unzReadCurrentFile(d_pimpl->d_zfile, buffer, size) < 0)
    {
        throw FileIOException("'" + final_filename +
            "' error reading file");
    }

    if (unzCloseCurrentFile(d_pimpl->d_zfile) != UNZ_OK)
    {
        throw GenericException("'" + final_filename +
            "' error validating file");
    }

    output.setData(buffer);
    output.setSize(size);
}