1/*
2Copyright (C) 2005-2006 NSRT Team ( http://nsrt.edgeemu.com )
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6version 2 as published by the Free Software Foundation.
7
8This program is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License
14along with this program; if not, write to the Free Software
15Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16*/
17
18#ifndef JMA_H
19#define JMA_H
20
21#include <string>
22#include <fstream>
23#include <vector>
24#include <time.h>
25
26namespace JMA
27{
28 enum jma_errors { JMA_NO_CREATE, JMA_NO_MEM_ALLOC, JMA_NO_OPEN, JMA_BAD_FILE,
29 JMA_UNSUPPORTED_VERSION, JMA_COMPRESS_FAILED, JMA_DECOMPRESS_FAILED,
30 JMA_FILE_NOT_FOUND };
31
32 struct jma_file_info_base
33 {
34 std::string name;
35 std::string comment;
36 size_t size;
37 unsigned int crc32;
38 };
39
40 struct jma_public_file_info : jma_file_info_base
41 {
42 time_t datetime;
43 };
44
45 struct jma_file_info : jma_file_info_base
46 {
47 unsigned short date;
48 unsigned short time;
49 const unsigned char *buffer;
50 };
51
52 template<class jma_file_type>
53 inline size_t get_total_size(std::vector<jma_file_type>& files)
54 {
55 size_t size = 0;
56 for (typename std::vector<jma_file_type>::iterator i = files.begin(); i != files.end(); i++)
57 {
58 size += i->size; //We do have a problem if this wraps around
59 }
60
61 return(size);
62 }
63
64 class jma_open
65 {
66 public:
67 jma_open(const char *);
68 ~jma_open();
69
70 std::vector<jma_public_file_info> get_files_info();
71 std::vector<unsigned char *> get_all_files(unsigned char *);
72 void extract_file(std::string& name, unsigned char *);
73 bool is_solid();
74
75 private:
76 std::ifstream stream;
77 std::vector<jma_file_info> files;
78 size_t chunk_size;
79 unsigned char *decompressed_buffer;
80 unsigned char *compressed_buffer;
81
82 void chunk_seek(unsigned int);
83 void retrieve_file_block();
84 };
85
86 time_t uint_to_time(unsigned short, unsigned short);
87 const char *jma_error_text(jma_errors);
88}
89#endif
90