Path: blob/main/misc/emulator/xnes/snes9x/jma/jma.h
28798 views
/*1Copyright (C) 2005-2006 NSRT Team ( http://nsrt.edgeemu.com )23This program is free software; you can redistribute it and/or4modify it under the terms of the GNU General Public License5version 2 as published by the Free Software Foundation.67This program is distributed in the hope that it will be useful,8but WITHOUT ANY WARRANTY; without even the implied warranty of9MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the10GNU General Public License for more details.1112You should have received a copy of the GNU General Public License13along with this program; if not, write to the Free Software14Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.15*/1617#ifndef JMA_H18#define JMA_H1920#include <string>21#include <fstream>22#include <vector>23#include <time.h>2425namespace JMA26{27enum jma_errors { JMA_NO_CREATE, JMA_NO_MEM_ALLOC, JMA_NO_OPEN, JMA_BAD_FILE,28JMA_UNSUPPORTED_VERSION, JMA_COMPRESS_FAILED, JMA_DECOMPRESS_FAILED,29JMA_FILE_NOT_FOUND };3031struct jma_file_info_base32{33std::string name;34std::string comment;35size_t size;36unsigned int crc32;37};3839struct jma_public_file_info : jma_file_info_base40{41time_t datetime;42};4344struct jma_file_info : jma_file_info_base45{46unsigned short date;47unsigned short time;48const unsigned char *buffer;49};5051template<class jma_file_type>52inline size_t get_total_size(std::vector<jma_file_type>& files)53{54size_t size = 0;55for (typename std::vector<jma_file_type>::iterator i = files.begin(); i != files.end(); i++)56{57size += i->size; //We do have a problem if this wraps around58}5960return(size);61}6263class jma_open64{65public:66jma_open(const char *) throw(jma_errors);67~jma_open();6869std::vector<jma_public_file_info> get_files_info();70std::vector<unsigned char *> get_all_files(unsigned char *) throw(jma_errors);71void extract_file(std::string& name, unsigned char *) throw(jma_errors);72bool is_solid();7374private:75std::ifstream stream;76std::vector<jma_file_info> files;77size_t chunk_size;78unsigned char *decompressed_buffer;79unsigned char *compressed_buffer;8081void chunk_seek(unsigned int) throw(jma_errors);82void retrieve_file_block() throw(jma_errors);83};8485time_t uint_to_time(unsigned short, unsigned short);86const char *jma_error_text(jma_errors);87}88#endif899091