bool res_file_t::get_resource(uint32 type, int id, LoadedResource &rsrc) const { rsrc.Unload(); // Find resource in map type_map_t::const_iterator i = types.find(type); if (i != types.end()) { id_map_t::const_iterator j = i->second.find(id); if (j != i->second.end()) { // Found, read data size SDL_RWseek(f, j->second, SEEK_SET); uint32 size = SDL_ReadBE32(f); // Allocate memory and read data void *p = malloc(size); if (p == NULL) { return false; } SDL_RWread(f, p, 1, size); #ifdef mac rsrc.SetData(p, size); #else rsrc.p = p; rsrc.size = size; #endif // fprintf(stderr, "get_resource type %c%c%c%c, id %d -> data %p, size %d\n", type >> 24, type >> 16, type >> 8, type, id, p, size); return true; } } return false; }
bool res_file_t::get_ind_resource(uint32 type, int index, LoadedResource &rsrc) const { rsrc.Unload(); // Find resource in map type_map_t::const_iterator i = types.find(type); if (i != types.end()) { if (index < 1 || index > int(i->second.size())) return false; id_map_t::const_iterator j = i->second.begin(); for (int k=1; k<index; k++) ++j; // Read data size SDL_RWseek(f, j->second, SEEK_SET); uint32 size = SDL_ReadBE32(f); // Allocate memory and read data void *p = malloc(size); if (p == NULL) return false; SDL_RWread(f, p, 1, size); rsrc.p = p; rsrc.size = size; // fprintf(stderr, "get_ind_resource type %c%c%c%c, index %d -> data %p, size %d\n", type >> 24, type >> 16, type >> 8, type, index, p, size); return true; } return false; }
size_t res_file_t::count_resources(uint32 type) const { type_map_t::const_iterator i = types.find(type); if (i == types.end()) return 0; else return i->second.size(); }
void res_file_t::get_resource_id_list(uint32 type, vector<int> &ids) const { type_map_t::const_iterator i = types.find(type); if (i != types.end()) { id_map_t::const_iterator j, end = i->second.end(); for (j=i->second.begin(); j!=end; j++) ids.push_back(j->first); } }
bool res_file_t::has_resource(uint32 type, int id) const { type_map_t::const_iterator i = types.find(type); if (i != types.end()) { id_map_t::const_iterator j = i->second.find(id); if (j != i->second.end()) return true; } return false; }