tqt::tqt(const char* filename) // Constructor. Open the file and read the table of contents. Keep // the stream open in order to load textures on demand. { m_source = SDL_RWFromFile(filename, "rb"); if (m_source == NULL) { throw "tqt::tqt() can't open file."; } // Read header. tqt_header_info info = read_tqt_header_info(m_source); if (info.m_version != TQT_VERSION) { m_source = NULL; throw "tqt::tqt() incorrect file version."; return; // Hm. } m_depth = info.m_tree_depth; m_tile_size = info.m_tile_size; // Read table of contents. Each entry is the offset of the // index'ed tile's JPEG data, relative to the start of the file. m_toc.resize(node_count(m_depth)); for (int i = 0; i < node_count(m_depth); i++) { m_toc[i] = SDL_ReadLE32(m_source); } }
/*static*/ bool tqt::is_tqt_file(const char* filename) // Return true if the given file looks like a .tqt file of our // appropriate version. Do this by attempting to read the header. { SDL_RWops* in = SDL_RWFromFile(filename, "rb"); if (in == NULL) { return false; } // Read header. tqt_header_info info = read_tqt_header_info(in); SDL_RWclose(in); if (info.m_version != TQT_VERSION) { return false; } return true; }
/*static*/ bool tqt::is_tqt_file(const char* filename) // Return true if the given file looks like a .tqt file of our // appropriate version. Do this by attempting to read the header. { tu_file in(filename, "rb"); if (in.get_error()) { return false; } // Read header. tqt_header_info info = read_tqt_header_info(&in); if (info.m_version != TQT_VERSION) { return false; } return true; }