virtual size_t size() { if (!m_size) { GHL::UInt32 pos = m_ds->Tell(); m_ds->Seek(0, GHL::F_SEEK_END); m_size = m_ds->Tell(); m_ds->Seek(pos, GHL::F_SEEK_BEGIN); } return m_size; }
int MD5SumFile( lua_State* L ) { const char* fn = luaL_checkstring(L, 1); FileProvider* fp = luabind::stack<FileProvider*>::get(L, 2, false); GHL::DataStream* ds = fp->OpenFile(fn); if (!ds) { luaL_error(L, "not found file %s",fn); } lua_pushstring(L, MD5SumStream(ds).c_str()); ds->Release(); return 1; }
bool func_2(const char* event_name, const GHL::Byte* param_0, const GHL::ULong32 param_1) { if (std::strcmp("platform:make_screen_shoot", event_name) == 0) { GHL::VFS* fs = GHL_CreateVFS(); GHL::DataStream* ds = fs->OpenFile("e:/test.jpg", GHL::FILE_WRITE); ds->Write(param_0, param_1); ds->Release(); GHL_DestroyVFS(fs); return true; } char buf[80]; sprintf(buf, "call event \"%s\" not implement.", event_name); LOG_INFO("buf"); return false; }
bool DataManager::isDataExist(const std::string& _name, bool _texture) { if (_texture) { bool variant = false; GHL::DataStream* ds = m_file_provider->OpenFileVariant(_name.c_str(),variant); if (ds) { ds->Release(); return true; } } else { GHL::DataStream* ds = m_file_provider->OpenFile(_name.c_str()); if (ds) { ds->Release(); return true; } } return false; }
static int load(lua_State* L) { Document* self = Sandbox::luabind::stack<Document*>::get(L, 1, false); const char* path = luaL_checkstring(L, 2); Sandbox::FileProvider* fp = Sandbox::luabind::stack<Sandbox::FileProvider*>::get(L, 3, false); GHL::DataStream* ds = fp->OpenFile(path); if (!ds) { lua_pushnil(L); lua_pushfstring(L, "not found file %s",path); return 2; } GHL::Data* da = GHL_ReadAllData(ds); ds->Release(); pugi::xml_parse_result res = self->m_doc.load_buffer(da->GetData(),da->GetSize()); da->Release(); if (!res) { lua_pushnil(L); lua_pushstring(L, res.description()); return 2; } lua_pushboolean(L, 1); return 1; }
TileMapPtr LoadTileMapTMX(FileProvider* fp, const char* filename) { if (!fp || !filename) return TileMapPtr(); GHL::DataStream* ds = fp->OpenFile(filename); if (!ds) { LogError() << "not found file " << filename; return TileMapPtr(); } GHL::Data* tmx_data = GHL_ReadAllData( ds ); ds->Release(); sb_assert(tmx_data); pugi::xml_document doc; pugi::xml_parse_result parse_res = doc.load_buffer(tmx_data->GetData(), tmx_data->GetSize(), pugi::parse_default, pugi::encoding_utf8); tmx_data->Release(); if (!parse_res) { LogError() << "failed parse " << filename; LogError() << parse_res.description(); return TileMapPtr(); } pugi::xml_node n = doc.document_element(); size_t w = n.attribute("width").as_uint(); size_t h = n.attribute("height").as_uint(); TileMapPtr map = TileMapPtr(new TileMap(w,h)); for (pugi::xml_node_iterator it = n.begin();it!=n.end();++it) { if (::strcmp(it->name(), "layer")==0) { size_t lw = it->attribute("width").as_uint(); size_t lh = it->attribute("height").as_uint(); pugi::xml_node data_node = it->child("data"); if (data_node) { TileMapLayerPtr layer; if (!data_node.attribute("compression") && !data_node.attribute("encoding")) { size_t x = 0; size_t y = 0; layer = TileMapLayerPtr(new TileMapLayer(lw,lh)); for (pugi::xml_node_iterator ii=data_node.begin(); ii!=data_node.end(); ++ii) { if (::strcmp(ii->name(), "tile")==0) { TileMapLayer::data_t d = ii->attribute("gid").as_uint(); layer->SetAt(x, y, d); ++x; if (x>=lw) { ++y; x = 0; } } } } if (!layer) { GHL::Data* d = 0; if (::strcmp(data_node.attribute("encoding").as_string(),"base64")==0) { d = Base64DecodeData(data_node.child_value()); } else { continue; } if (!d) continue; if (::strcmp(data_node.attribute("compression").as_string(),"zlib")==0) { GHL::UInt32 size = sizeof(GHL::UInt32)*lw*lh; VectorData<GHL::Byte>* dd = new VectorData<GHL::Byte>(); dd->vector().resize(size); if( GHL_UnpackZlib(d, dd->vector().data(), &size ) && size == dd->GetSize() ) { d->Release(); d = dd; } else { dd->Release(); d->Release(); continue; } } else if (data_node.attribute("compression")) { LogError() << "unsupported compression " << data_node.attribute("compression").as_string(); d->Release(); continue; } layer = TileMapLayerPtr(new TileMapLayer(lw,lh,d)); } if (layer) { map->SetLayer(it->attribute("name").as_string(), layer); } } } } return map; }
virtual size_t read(void* _buf, size_t _count) { return m_ds->Read(reinterpret_cast<GHL::Byte*>(_buf), GHL::UInt32(_count)); }
virtual bool eof() { return m_ds->Eof(); }
~DataStream() { m_ds->Release(); }