Removed unneeded whitespace.
This commit is contained in:
@@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
typedef NCompression::NArithmetic::CRangeDecoder CMyRangeDecoder;
|
||||
template <int aNumMoveBits> class CMyBitDecoder:
|
||||
template <int aNumMoveBits> class CMyBitDecoder:
|
||||
public NCompression::NArithmetic::CBitDecoder<aNumMoveBits> {};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace CRC32lib
|
||||
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d };
|
||||
|
||||
|
||||
|
||||
//CRC32 for char arrays
|
||||
unsigned int CRC32(const unsigned char *array, size_t size, register unsigned int crc32)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ HRESULT ISequentialInStream_Array::Read(void *aData, UINT32 aSize, UINT32 *aProc
|
||||
if (aSize > size)
|
||||
{
|
||||
aSize = size;
|
||||
}
|
||||
}
|
||||
|
||||
*aProcessedSize = aSize;
|
||||
memcpy(aData, data, aSize);
|
||||
@@ -57,7 +57,7 @@ HRESULT ISequentialInStream_String::Read(void *aData, UINT32 aSize, UINT32 *aPro
|
||||
if (aSize > data.size())
|
||||
{
|
||||
aSize = data.size();
|
||||
}
|
||||
}
|
||||
|
||||
*aProcessedSize = aSize;
|
||||
memcpy(aData, data.c_str(), aSize);
|
||||
|
||||
@@ -40,7 +40,7 @@ class ISequentialInStream_Array : public ISequentialInStream
|
||||
unsigned int size;
|
||||
public:
|
||||
ISequentialInStream_Array(const char *Adata, unsigned Asize) : data(Adata), size(Asize) { }
|
||||
|
||||
|
||||
HRESULT Read(void *aData, UINT32 aSize, UINT32 *aProcessedSize);
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@ class ISequentialInStream_String : public ISequentialInStream
|
||||
std::string& data;
|
||||
public:
|
||||
ISequentialInStream_String(std::string& Adata) : data(Adata) { }
|
||||
|
||||
|
||||
HRESULT Read(void *aData, UINT32 aSize, UINT32 *aProcessedSize);
|
||||
};
|
||||
|
||||
@@ -58,7 +58,7 @@ class ISequentialInStream_Istream : public ISequentialInStream
|
||||
std::istream& data;
|
||||
public:
|
||||
ISequentialInStream_Istream(std::istream& Adata) : data(Adata) { }
|
||||
|
||||
|
||||
HRESULT Read(void *aData, UINT32 aSize, UINT32 *aProcessedSize);
|
||||
};
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
virtual HRESULT Write(const void *, UINT32, UINT32 *) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class ISequentialOutStream_Array : public ISequentialOutStream
|
||||
{
|
||||
char *data;
|
||||
@@ -120,7 +120,7 @@ public:
|
||||
|
||||
class ISequentialStreamCRC32
|
||||
{
|
||||
protected:
|
||||
protected:
|
||||
unsigned int crc32;
|
||||
public:
|
||||
ISequentialStreamCRC32() : crc32(0) {}
|
||||
@@ -130,17 +130,17 @@ public:
|
||||
|
||||
class ISequentialInStreamCRC32_Array : public ISequentialInStream_Array, public ISequentialStreamCRC32
|
||||
{
|
||||
public:
|
||||
public:
|
||||
ISequentialInStreamCRC32_Array(const char *Adata, unsigned Asize) : ISequentialInStream_Array(Adata, Asize) { }
|
||||
|
||||
|
||||
HRESULT Read(void *aData, UINT32 aSize, UINT32 *aProcessedSize);
|
||||
};
|
||||
|
||||
class ISequentialInStreamCRC32_String : public ISequentialInStream_String, public ISequentialStreamCRC32
|
||||
{
|
||||
public:
|
||||
public:
|
||||
ISequentialInStreamCRC32_String(std::string& Adata) : ISequentialInStream_String(Adata) { }
|
||||
|
||||
|
||||
HRESULT Read(void *aData, UINT32 aSize, UINT32 *aProcessedSize);
|
||||
};
|
||||
|
||||
@@ -148,16 +148,16 @@ class ISequentialInStreamCRC32_Istream : public ISequentialInStream_Istream, pub
|
||||
{
|
||||
public:
|
||||
ISequentialInStreamCRC32_Istream(std::istream& Adata) : ISequentialInStream_Istream(Adata) { }
|
||||
|
||||
|
||||
HRESULT Read(void *aData, UINT32 aSize, UINT32 *aProcessedSize);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class ISequentialOutStreamCRC32_Array : public ISequentialOutStream_Array, public ISequentialStreamCRC32
|
||||
{
|
||||
public:
|
||||
ISequentialOutStreamCRC32_Array(char *Adata, unsigned Asize) : ISequentialOutStream_Array(Adata, Asize) { }
|
||||
|
||||
|
||||
HRESULT Write(const void *aData, UINT32 aSize, UINT32 *aProcessedSize);
|
||||
};
|
||||
|
||||
@@ -165,7 +165,7 @@ class ISequentialOutStreamCRC32_String : public ISequentialOutStream_String, pub
|
||||
{
|
||||
public:
|
||||
ISequentialOutStreamCRC32_String(std::string& Adata) : ISequentialOutStream_String(Adata) { }
|
||||
|
||||
|
||||
HRESULT Write(const void *aData, UINT32 aSize, UINT32 *aProcessedSize);
|
||||
};
|
||||
|
||||
@@ -174,7 +174,7 @@ class ISequentialOutStreamCRC32_Ostream : public ISequentialOutStream_Ostream, p
|
||||
{
|
||||
public:
|
||||
ISequentialOutStreamCRC32_Ostream(std::ostream& Adata) : ISequentialOutStream_Ostream(Adata) { }
|
||||
|
||||
|
||||
HRESULT Write(const void *aData, UINT32 aSize, UINT32 *aProcessedSize);
|
||||
};
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class CInByte
|
||||
public:
|
||||
CInByte(UINT32 aBufferSize = 0x100000);
|
||||
~CInByte();
|
||||
|
||||
|
||||
void Init(ISequentialInStream *aStream);
|
||||
|
||||
bool ReadByte(BYTE &aByte)
|
||||
|
||||
@@ -28,80 +28,80 @@ using namespace std;
|
||||
namespace JMA
|
||||
{
|
||||
const char jma_magic[] = { 'J', 'M', 'A', 0, 'N' };
|
||||
const unsigned int jma_header_length = 5;
|
||||
const unsigned int jma_header_length = 5;
|
||||
const unsigned char jma_version = 1;
|
||||
const unsigned int jma_version_length = 1;
|
||||
const unsigned int jma_total_header_length = jma_header_length + jma_version_length + UINT_SIZE;
|
||||
|
||||
|
||||
//Convert DOS/zip/JMA integer time to to time_t
|
||||
time_t uint_to_time(unsigned short date, unsigned short time)
|
||||
{
|
||||
tm formatted_time;
|
||||
|
||||
|
||||
formatted_time.tm_mday = date & 0x1F;
|
||||
formatted_time.tm_mon = ((date >> 5) & 0xF) - 1;
|
||||
formatted_time.tm_year = ((date >> 9) & 0x7f) + 80;
|
||||
formatted_time.tm_sec = (time & 0x1F) * 2;
|
||||
formatted_time.tm_min = (time >> 5) & 0x3F;
|
||||
formatted_time.tm_hour = (time >> 11) & 0x1F;
|
||||
|
||||
|
||||
return(mktime(&formatted_time));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Retreive the file block, what else?
|
||||
void jma_open::retrieve_file_block() throw(jma_errors)
|
||||
{
|
||||
unsigned char uint_buffer[UINT_SIZE];
|
||||
unsigned char ushort_buffer[USHORT_SIZE];
|
||||
|
||||
|
||||
//File block size is the last UINT in the file
|
||||
stream.seekg(-UINT_SIZE,ios::end);
|
||||
stream.read((char *)uint_buffer, UINT_SIZE);
|
||||
size_t file_block_size = charp_to_uint(uint_buffer);
|
||||
|
||||
|
||||
//Currently at the end of the file, so that's the file size
|
||||
size_t jma_file_size = stream.tellg();
|
||||
|
||||
|
||||
//The file block can't be larger than the JMA file without it's header.
|
||||
//This if can probably be improved
|
||||
if (file_block_size >= jma_file_size-jma_total_header_length)
|
||||
{
|
||||
throw(JMA_BAD_FILE);
|
||||
}
|
||||
|
||||
|
||||
//Seek to before file block so we can read the file block
|
||||
stream.seekg(-((int)file_block_size+UINT_SIZE),ios::end);
|
||||
|
||||
|
||||
//This is needed if the file block is compressed
|
||||
stringstream decompressed_file_block;
|
||||
//Pointer to where to read file block from (file or decompressed buffer)
|
||||
istream *file_block_stream;
|
||||
|
||||
|
||||
//Setup file info buffer and byte to read with
|
||||
jma_file_info file_info;
|
||||
char byte;
|
||||
|
||||
char byte;
|
||||
|
||||
stream.get(byte);
|
||||
if (!byte) //If file block is compressed
|
||||
{
|
||||
//Compressed size isn't counting the byte we just read or the UINT for compressed size
|
||||
size_t compressed_size = file_block_size - (1+UINT_SIZE);
|
||||
|
||||
|
||||
//Read decompressed size / true file block size
|
||||
stream.read((char *)uint_buffer, UINT_SIZE);
|
||||
file_block_size = charp_to_uint(uint_buffer);
|
||||
|
||||
|
||||
//Setup access methods for decompression
|
||||
ISequentialInStream_Istream compressed_data(stream);
|
||||
ISequentialOutStream_Ostream decompressed_data(decompressed_file_block);
|
||||
|
||||
|
||||
//Decompress the data
|
||||
if (!decompress_lzma_7z(compressed_data, compressed_size, decompressed_data, file_block_size))
|
||||
{
|
||||
throw(JMA_DECOMPRESS_FAILED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Go to beginning, setup pointer to buffer
|
||||
decompressed_file_block.seekg(0, ios::beg);
|
||||
file_block_stream = &decompressed_file_block;
|
||||
@@ -111,8 +111,8 @@ namespace JMA
|
||||
stream.putback(byte); //Putback byte, byte is part of filename, not compressed indicator
|
||||
file_block_stream = &stream;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Minimum file name length is 2 bytes, a char and a null
|
||||
//Minimum comment length is 1 byte, a null
|
||||
//There are currently 2 UINTs and 2 USHORTs per file
|
||||
@@ -120,7 +120,7 @@ namespace JMA
|
||||
{
|
||||
//First stored in the file block is the file name null terminated
|
||||
file_info.name = "";
|
||||
|
||||
|
||||
file_block_stream->get(byte);
|
||||
while (byte)
|
||||
{
|
||||
@@ -132,8 +132,8 @@ namespace JMA
|
||||
if (!file_info.name.length())
|
||||
{
|
||||
throw(JMA_BAD_FILE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Same trick as above for the comment
|
||||
file_info.comment = "";
|
||||
|
||||
@@ -143,38 +143,38 @@ namespace JMA
|
||||
file_info.comment += byte;
|
||||
file_block_stream->get(byte);
|
||||
}
|
||||
|
||||
|
||||
//Next is a UINT representing the file's size
|
||||
file_block_stream->read((char *)uint_buffer, UINT_SIZE);
|
||||
file_info.size = charp_to_uint(uint_buffer);
|
||||
|
||||
|
||||
//Followed by CRC32
|
||||
file_block_stream->read((char *)uint_buffer, UINT_SIZE);
|
||||
file_info.crc32 = charp_to_uint(uint_buffer);
|
||||
|
||||
|
||||
//Special USHORT representation of file's date
|
||||
file_block_stream->read((char *)ushort_buffer, USHORT_SIZE);
|
||||
file_info.date = charp_to_ushort(ushort_buffer);
|
||||
|
||||
|
||||
//Special USHORT representation of file's time
|
||||
file_block_stream->read((char *)ushort_buffer, USHORT_SIZE);
|
||||
file_info.time = charp_to_ushort(ushort_buffer);
|
||||
|
||||
|
||||
file_info.buffer = 0; //Pointing to null till we decompress files
|
||||
|
||||
|
||||
files.push_back(file_info); //Put file info into our structure
|
||||
|
||||
|
||||
//Subtract size of the file info we just read
|
||||
file_block_size -= file_info.name.length()+file_info.comment.length()+2+UINT_SIZE*2+USHORT_SIZE*2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Constructor for opening JMA files for reading
|
||||
jma_open::jma_open(const char *compressed_file_name) throw (jma_errors)
|
||||
jma_open::jma_open(const char *compressed_file_name) throw (jma_errors)
|
||||
{
|
||||
decompressed_buffer = 0;
|
||||
compressed_buffer = 0;
|
||||
|
||||
|
||||
stream.open(compressed_file_name, ios::in | ios::binary);
|
||||
if (!stream.is_open())
|
||||
{
|
||||
@@ -188,7 +188,7 @@ namespace JMA
|
||||
{
|
||||
throw(JMA_BAD_FILE);
|
||||
}
|
||||
|
||||
|
||||
//Not the cleanest code but logical
|
||||
stream.read((char *)header, 5);
|
||||
if (*header <= jma_version)
|
||||
@@ -216,7 +216,7 @@ namespace JMA
|
||||
{
|
||||
vector<jma_public_file_info> file_info_vector;
|
||||
jma_public_file_info file_info;
|
||||
|
||||
|
||||
for (vector<jma_file_info>::iterator i = files.begin(); i != files.end(); i++)
|
||||
{
|
||||
file_info.name = i->name;
|
||||
@@ -226,10 +226,10 @@ namespace JMA
|
||||
file_info.crc32 = i->crc32;
|
||||
file_info_vector.push_back(file_info);
|
||||
}
|
||||
|
||||
|
||||
return(file_info_vector);
|
||||
}
|
||||
|
||||
|
||||
//Skip forward a given number of chunks
|
||||
void jma_open::chunk_seek(unsigned int chunk_num) throw(jma_errors)
|
||||
{
|
||||
@@ -238,25 +238,25 @@ namespace JMA
|
||||
{
|
||||
throw(JMA_NO_OPEN);
|
||||
}
|
||||
|
||||
|
||||
//Clear possible errors so the seek will work
|
||||
stream.clear();
|
||||
|
||||
|
||||
//Move forward over header
|
||||
stream.seekg(jma_total_header_length, ios::beg);
|
||||
|
||||
unsigned char int4_buffer[UINT_SIZE];
|
||||
|
||||
unsigned char int4_buffer[UINT_SIZE];
|
||||
|
||||
while (chunk_num--)
|
||||
{
|
||||
//Read in size of chunk
|
||||
stream.read((char *)int4_buffer, UINT_SIZE);
|
||||
|
||||
|
||||
//Skip chunk plus it's CRC32
|
||||
stream.seekg(charp_to_uint(int4_buffer)+UINT_SIZE, ios::cur);
|
||||
stream.seekg(charp_to_uint(int4_buffer)+UINT_SIZE, ios::cur);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Return a vector of pointers to each file in the JMA, the buffer to hold all the files
|
||||
//must be initilized outside.
|
||||
vector<unsigned char *> jma_open::get_all_files(unsigned char *buffer) throw(jma_errors)
|
||||
@@ -266,19 +266,19 @@ namespace JMA
|
||||
{
|
||||
throw(JMA_NO_OPEN);
|
||||
}
|
||||
|
||||
|
||||
//Seek to the first chunk
|
||||
chunk_seek(0);
|
||||
|
||||
|
||||
//Set the buffer that decompressed data goes to
|
||||
decompressed_buffer = buffer;
|
||||
|
||||
|
||||
//If the JMA is not solid
|
||||
if (chunk_size)
|
||||
{
|
||||
unsigned char int4_buffer[UINT_SIZE];
|
||||
unsigned char int4_buffer[UINT_SIZE];
|
||||
size_t size = get_total_size(files);
|
||||
|
||||
|
||||
//For each chunk in the file...
|
||||
for (size_t remaining_size = size; remaining_size; remaining_size -= chunk_size)
|
||||
{
|
||||
@@ -299,7 +299,7 @@ namespace JMA
|
||||
|
||||
//Read all the compressed data in
|
||||
stream.read((char *)compressed_buffer, compressed_size);
|
||||
|
||||
|
||||
//Read the expected CRC of compressed data from the file
|
||||
stream.read((char *)int4_buffer, UINT_SIZE);
|
||||
|
||||
@@ -309,17 +309,17 @@ namespace JMA
|
||||
delete[] compressed_buffer;
|
||||
throw(JMA_BAD_FILE);
|
||||
}
|
||||
|
||||
|
||||
//Decompress the data, cleanup memory on failure
|
||||
if (!decompress_lzma_7z(compressed_buffer, compressed_size,
|
||||
decompressed_buffer+size-remaining_size,
|
||||
if (!decompress_lzma_7z(compressed_buffer, compressed_size,
|
||||
decompressed_buffer+size-remaining_size,
|
||||
(remaining_size > chunk_size) ? chunk_size : remaining_size))
|
||||
{
|
||||
delete[] compressed_buffer;
|
||||
throw(JMA_DECOMPRESS_FAILED);
|
||||
}
|
||||
delete[] compressed_buffer;
|
||||
|
||||
|
||||
if (remaining_size <= chunk_size) //If we just decompressed the remainder
|
||||
{
|
||||
break;
|
||||
@@ -328,25 +328,25 @@ namespace JMA
|
||||
}
|
||||
else //Solidly compressed JMA
|
||||
{
|
||||
unsigned char int4_buffer[UINT_SIZE];
|
||||
|
||||
unsigned char int4_buffer[UINT_SIZE];
|
||||
|
||||
//Read the size of the compressed data
|
||||
stream.read((char *)int4_buffer, UINT_SIZE);
|
||||
size_t compressed_size = charp_to_uint(int4_buffer);
|
||||
|
||||
//Get decompressed size
|
||||
size_t size = get_total_size(files);
|
||||
|
||||
|
||||
//Setup access methods for decompression
|
||||
ISequentialInStream_Istream compressed_data(stream);
|
||||
ISequentialOutStream_Array decompressed_data(reinterpret_cast<char*>(decompressed_buffer), size);
|
||||
|
||||
|
||||
//Decompress the data
|
||||
if (!decompress_lzma_7z(compressed_data, compressed_size, decompressed_data, size))
|
||||
{
|
||||
throw(JMA_DECOMPRESS_FAILED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
//Allocate memory of the right size to hold the compressed data in the JMA
|
||||
try
|
||||
@@ -357,14 +357,14 @@ namespace JMA
|
||||
{
|
||||
throw(JMA_NO_MEM_ALLOC);
|
||||
}
|
||||
|
||||
|
||||
//Copy the compressed data into memory
|
||||
stream.read((char *)compressed_buffer, compressed_size);
|
||||
size_t size = get_total_size(files);
|
||||
|
||||
|
||||
//Read the CRC of the compressed data
|
||||
stream.read((char *)int4_buffer, UINT_SIZE);
|
||||
|
||||
|
||||
//If it doesn't match, complain
|
||||
if (CRC32lib::CRC32(compressed_buffer, compressed_size) != charp_to_uint(int4_buffer))
|
||||
{
|
||||
@@ -381,10 +381,10 @@ namespace JMA
|
||||
delete[] compressed_buffer;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
vector<unsigned char *> file_pointers;
|
||||
size_t size = 0;
|
||||
|
||||
|
||||
//For each file, add it's pointer to the vector, size is pointer offset in the buffer
|
||||
for (vector<jma_file_info>::iterator i = files.begin(); i != files.end(); i++)
|
||||
{
|
||||
@@ -394,7 +394,7 @@ namespace JMA
|
||||
}
|
||||
|
||||
//Return the vector of pointers
|
||||
return(file_pointers);
|
||||
return(file_pointers);
|
||||
}
|
||||
|
||||
//Extracts the file with a given name found in the archive to the given buffer
|
||||
@@ -404,10 +404,10 @@ namespace JMA
|
||||
{
|
||||
throw(JMA_NO_OPEN);
|
||||
}
|
||||
|
||||
|
||||
size_t size_to_skip = 0;
|
||||
size_t our_file_size = 0;
|
||||
|
||||
|
||||
//Search through the vector of file information
|
||||
for (vector<jma_file_info>::iterator i = files.begin(); i != files.end(); i++)
|
||||
{
|
||||
@@ -417,11 +417,11 @@ namespace JMA
|
||||
our_file_size = i->size;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//Keep a running total of size
|
||||
size_to_skip += i->size;
|
||||
}
|
||||
|
||||
|
||||
if (!our_file_size) //File with the specified name was not found in the archive
|
||||
{
|
||||
throw(JMA_FILE_NOT_FOUND);
|
||||
@@ -433,14 +433,14 @@ namespace JMA
|
||||
get_all_files(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (chunk_size) //we are using non-solid archive..
|
||||
{
|
||||
unsigned int chunks_to_skip = size_to_skip / chunk_size;
|
||||
|
||||
|
||||
//skip over requisite number of chunks
|
||||
chunk_seek(chunks_to_skip);
|
||||
|
||||
|
||||
//Allocate memory for compressed and decompressed data
|
||||
unsigned char *comp_buffer = 0, *decomp_buffer = 0;
|
||||
try
|
||||
@@ -454,7 +454,7 @@ namespace JMA
|
||||
{
|
||||
throw(JMA_NO_MEM_ALLOC);
|
||||
}
|
||||
|
||||
|
||||
size_t first_chunk_offset = size_to_skip % chunk_size;
|
||||
unsigned char int4_buffer[UINT_SIZE];
|
||||
for (size_t i = 0; i < our_file_size;)
|
||||
@@ -462,29 +462,29 @@ namespace JMA
|
||||
//Get size
|
||||
stream.read((char *)int4_buffer, UINT_SIZE);
|
||||
size_t compressed_size = charp_to_uint(int4_buffer);
|
||||
|
||||
|
||||
//Read all the compressed data in
|
||||
stream.read((char *)comp_buffer, compressed_size);
|
||||
|
||||
//Read the CRC of the compressed data
|
||||
stream.read((char *)int4_buffer, UINT_SIZE);
|
||||
|
||||
|
||||
//If it doesn't match, complain
|
||||
if (CRC32lib::CRC32(comp_buffer, compressed_size) != charp_to_uint(int4_buffer))
|
||||
{
|
||||
delete[] comp_buffer;
|
||||
throw(JMA_BAD_FILE);
|
||||
}
|
||||
|
||||
|
||||
//Decompress chunk
|
||||
if (!decompress_lzma_7z(comp_buffer, compressed_size, decomp_buffer, chunk_size))
|
||||
{
|
||||
delete[] comp_buffer;
|
||||
throw(JMA_DECOMPRESS_FAILED);
|
||||
}
|
||||
|
||||
|
||||
size_t copy_amount = our_file_size-i > chunk_size-first_chunk_offset ? chunk_size-first_chunk_offset : our_file_size-i;
|
||||
|
||||
|
||||
memcpy(buffer+i, decomp_buffer+first_chunk_offset, copy_amount);
|
||||
first_chunk_offset = 0; //Set to zero since this is only for the first iteration
|
||||
i += copy_amount;
|
||||
@@ -502,11 +502,11 @@ namespace JMA
|
||||
{
|
||||
throw(JMA_NO_MEM_ALLOC);
|
||||
}
|
||||
|
||||
|
||||
get_all_files(decomp_buffer);
|
||||
|
||||
|
||||
memcpy(buffer, decomp_buffer+size_to_skip, our_file_size);
|
||||
|
||||
|
||||
delete[] decomp_buffer;
|
||||
}
|
||||
}
|
||||
@@ -515,32 +515,32 @@ namespace JMA
|
||||
{
|
||||
return(chunk_size ? false : true);
|
||||
}
|
||||
|
||||
|
||||
const char *jma_error_text(jma_errors error)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
case JMA_NO_CREATE:
|
||||
return("JMA could not be created");
|
||||
|
||||
|
||||
case JMA_NO_MEM_ALLOC:
|
||||
return("Memory for JMA could be allocated");
|
||||
|
||||
|
||||
case JMA_NO_OPEN:
|
||||
return("JMA could not be opened");
|
||||
|
||||
|
||||
case JMA_BAD_FILE:
|
||||
return("Invalid/Corrupt JMA");
|
||||
|
||||
|
||||
case JMA_UNSUPPORTED_VERSION:
|
||||
return("JMA version not supported");
|
||||
|
||||
|
||||
case JMA_COMPRESS_FAILED:
|
||||
return("JMA compression failed");
|
||||
|
||||
|
||||
case JMA_DECOMPRESS_FAILED:
|
||||
return("JMA decompression failed");
|
||||
|
||||
|
||||
case JMA_FILE_NOT_FOUND:
|
||||
return("File not found in JMA");
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
namespace JMA
|
||||
{
|
||||
enum jma_errors { JMA_NO_CREATE, JMA_NO_MEM_ALLOC, JMA_NO_OPEN, JMA_BAD_FILE,
|
||||
enum jma_errors { JMA_NO_CREATE, JMA_NO_MEM_ALLOC, JMA_NO_OPEN, JMA_BAD_FILE,
|
||||
JMA_UNSUPPORTED_VERSION, JMA_COMPRESS_FAILED, JMA_DECOMPRESS_FAILED,
|
||||
JMA_FILE_NOT_FOUND };
|
||||
|
||||
|
||||
struct jma_file_info_base
|
||||
{
|
||||
std::string name;
|
||||
@@ -38,12 +38,12 @@ namespace JMA
|
||||
size_t size;
|
||||
unsigned int crc32;
|
||||
};
|
||||
|
||||
|
||||
struct jma_public_file_info : jma_file_info_base
|
||||
{
|
||||
time_t datetime;
|
||||
};
|
||||
|
||||
|
||||
struct jma_file_info : jma_file_info_base
|
||||
{
|
||||
unsigned short date;
|
||||
@@ -59,7 +59,7 @@ namespace JMA
|
||||
{
|
||||
size += i->size; //We do have a problem if this wraps around
|
||||
}
|
||||
|
||||
|
||||
return(size);
|
||||
}
|
||||
|
||||
@@ -68,23 +68,23 @@ namespace JMA
|
||||
public:
|
||||
jma_open(const char *) throw(jma_errors);
|
||||
~jma_open();
|
||||
|
||||
|
||||
std::vector<jma_public_file_info> get_files_info();
|
||||
std::vector<unsigned char *> get_all_files(unsigned char *) throw(jma_errors);
|
||||
void extract_file(std::string& name, unsigned char *) throw(jma_errors);
|
||||
bool is_solid();
|
||||
|
||||
|
||||
private:
|
||||
std::ifstream stream;
|
||||
std::vector<jma_file_info> files;
|
||||
size_t chunk_size;
|
||||
unsigned char *decompressed_buffer;
|
||||
unsigned char *compressed_buffer;
|
||||
|
||||
|
||||
void chunk_seek(unsigned int) throw(jma_errors);
|
||||
void retrieve_file_block() throw(jma_errors);
|
||||
};
|
||||
|
||||
|
||||
const char *jma_error_text(jma_errors);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -52,7 +52,7 @@ class CDecoder
|
||||
CBitTreeDecoder<kNumMoveBits, kNumLenBits> m_LowCoder[kNumPosStatesMax];
|
||||
CMyBitDecoder<kNumMoveBits> m_Choice2;
|
||||
CBitTreeDecoder<kNumMoveBits, kNumMidBits> m_MidCoder[kNumPosStatesMax];
|
||||
CBitTreeDecoder<kNumMoveBits, kNumHighBits> m_HighCoder;
|
||||
CBitTreeDecoder<kNumMoveBits, kNumHighBits> m_HighCoder;
|
||||
UINT32 m_NumPosStates;
|
||||
public:
|
||||
void Create(UINT32 aNumPosStates)
|
||||
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
// UINT32 aBit = m_Decoders[1 + aMatchBit][aSymbol].Decode(aRangeDecoder);
|
||||
// aSymbol = (aSymbol << 1) | aBit;
|
||||
UINT32 aBit;
|
||||
RC_GETBIT2(kNumMoveBits, m_Decoders[1 + aMatchBit][aSymbol].m_Probability, aSymbol,
|
||||
RC_GETBIT2(kNumMoveBits, m_Decoders[1 + aMatchBit][aSymbol].m_Probability, aSymbol,
|
||||
aBit = 0, aBit = 1)
|
||||
if (aMatchBit != aBit)
|
||||
{
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
CDecoder(): m_Coders(0) {}
|
||||
~CDecoder() { Free(); }
|
||||
void Free()
|
||||
{
|
||||
{
|
||||
delete []m_Coders;
|
||||
m_Coders = 0;
|
||||
}
|
||||
|
||||
@@ -68,16 +68,16 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
const int kNumPosSlotBits = 6;
|
||||
const int kDicLogSizeMax = 28;
|
||||
const int kDistTableSizeMax = kDicLogSizeMax * 2;
|
||||
const int kNumPosSlotBits = 6;
|
||||
const int kDicLogSizeMax = 28;
|
||||
const int kDistTableSizeMax = kDicLogSizeMax * 2;
|
||||
|
||||
extern UINT32 kDistStart[kDistTableSizeMax];
|
||||
const BYTE kDistDirectBits[kDistTableSizeMax] =
|
||||
const BYTE kDistDirectBits[kDistTableSizeMax] =
|
||||
{
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
|
||||
10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19,
|
||||
20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26
|
||||
10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19,
|
||||
20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26
|
||||
};
|
||||
|
||||
const UINT32 kNumLenToPosStates = 4;
|
||||
|
||||
@@ -30,7 +30,7 @@ HRESULT CDecoder::SetDictionarySize(UINT32 aDictionarySize)
|
||||
{
|
||||
if (aDictionarySize > (1 << kDicLogSizeMax))
|
||||
return E_INVALIDARG;
|
||||
|
||||
|
||||
UINT32 aWindowReservSize = MyMax(aDictionarySize, UINT32(1 << 21));
|
||||
|
||||
if (m_DictionarySize != aDictionarySize)
|
||||
@@ -100,9 +100,9 @@ HRESULT CDecoder::Init(ISequentialInStream *anInStream,
|
||||
m_MatchRep1ChoiceDecoders[i].Init();
|
||||
m_MatchRep2ChoiceDecoders[i].Init();
|
||||
}
|
||||
|
||||
|
||||
m_LiteralDecoder.Init();
|
||||
|
||||
|
||||
// m_RepMatchLenDecoder.Init();
|
||||
|
||||
for (i = 0; (UINT32) i < kNumLenToPosStates; i++)
|
||||
@@ -110,7 +110,7 @@ HRESULT CDecoder::Init(ISequentialInStream *anInStream,
|
||||
|
||||
for(i = 0; i < kNumPosModels; i++)
|
||||
m_PosDecoders[i].Init();
|
||||
|
||||
|
||||
m_LenDecoder.Init();
|
||||
m_RepMatchLenDecoder.Init();
|
||||
|
||||
@@ -120,7 +120,7 @@ HRESULT CDecoder::Init(ISequentialInStream *anInStream,
|
||||
}
|
||||
|
||||
HRESULT CDecoder::CodeReal(ISequentialInStream *anInStream,
|
||||
ISequentialOutStream *anOutStream,
|
||||
ISequentialOutStream *anOutStream,
|
||||
const UINT64 *anInSize, const UINT64 *anOutSize)
|
||||
{
|
||||
if (anOutSize == NULL)
|
||||
@@ -151,21 +151,21 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *anInStream,
|
||||
if(aPeviousIsMatch)
|
||||
{
|
||||
BYTE aMatchByte = m_OutWindowStream.GetOneByte(0 - aRepDistances[0] - 1);
|
||||
aPreviousByte = m_LiteralDecoder.DecodeWithMatchByte(&m_RangeDecoder,
|
||||
aPreviousByte = m_LiteralDecoder.DecodeWithMatchByte(&m_RangeDecoder,
|
||||
UINT32(aNowPos64), aPreviousByte, aMatchByte);
|
||||
aPeviousIsMatch = false;
|
||||
}
|
||||
else
|
||||
aPreviousByte = m_LiteralDecoder.DecodeNormal(&m_RangeDecoder,
|
||||
aPreviousByte = m_LiteralDecoder.DecodeNormal(&m_RangeDecoder,
|
||||
UINT32(aNowPos64), aPreviousByte);
|
||||
m_OutWindowStream.PutOneByte(aPreviousByte);
|
||||
aNowPos64++;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
aPeviousIsMatch = true;
|
||||
UINT32 aDistance, aLen;
|
||||
if(m_MatchChoiceDecoders[aState.m_Index].Decode(&m_RangeDecoder) ==
|
||||
if(m_MatchChoiceDecoders[aState.m_Index].Decode(&m_RangeDecoder) ==
|
||||
(UINT32) kMatchChoiceRepetitionIndex)
|
||||
{
|
||||
if(m_MatchRepChoiceDecoders[aState.m_Index].Decode(&m_RangeDecoder) == 0)
|
||||
@@ -190,7 +190,7 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *anInStream,
|
||||
aRepDistances[1] = aRepDistances[0];
|
||||
// aCounts[3 + 1]++;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
if (m_MatchRep2ChoiceDecoders[aState.m_Index].Decode(&m_RangeDecoder) == 0)
|
||||
{
|
||||
@@ -225,7 +225,7 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *anInStream,
|
||||
aDistance += m_PosDecoders[aPosSlot - kStartPosModelIndex].Decode(&m_RangeDecoder);
|
||||
else
|
||||
{
|
||||
aDistance += (m_RangeDecoder.DecodeDirectBits(kDistDirectBits[aPosSlot] -
|
||||
aDistance += (m_RangeDecoder.DecodeDirectBits(kDistDirectBits[aPosSlot] -
|
||||
kNumAlignBits) << kNumAlignBits);
|
||||
aDistance += m_PosAlignDecoder.Decode(&m_RangeDecoder);
|
||||
}
|
||||
@@ -233,11 +233,11 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *anInStream,
|
||||
else
|
||||
aDistance = aPosSlot;
|
||||
|
||||
|
||||
|
||||
aRepDistances[3] = aRepDistances[2];
|
||||
aRepDistances[2] = aRepDistances[1];
|
||||
aRepDistances[1] = aRepDistances[0];
|
||||
|
||||
|
||||
aRepDistances[0] = aDistance;
|
||||
// UpdateStat(aLen, aPosSlot);
|
||||
}
|
||||
@@ -285,7 +285,7 @@ HRESULT CDecoder::ReadCoderProperties(ISequentialInStream *anInStream)
|
||||
UINT8 uint_buffer[UINT_SIZE];
|
||||
RETURN_IF_NOT_S_OK(anInStream->Read(uint_buffer, sizeof(aDictionarySize), &aProcessesedSize));
|
||||
aDictionarySize = charp_to_uint(uint_buffer);
|
||||
|
||||
|
||||
if (aProcessesedSize != sizeof(aDictionarySize))
|
||||
return E_INVALIDARG;
|
||||
|
||||
|
||||
@@ -48,14 +48,14 @@ class CDecoder
|
||||
CReverseBitTreeDecoder<kNumMoveBitsForAlignCoders, kNumAlignBits> m_PosAlignDecoder;
|
||||
// CBitTreeDecoder2<kNumMoveBitsForPosCoders> m_PosDecoders[kNumPosModels];
|
||||
// CBitTreeDecoder<kNumMoveBitsForAlignCoders, kNumAlignBits> m_PosAlignDecoder;
|
||||
|
||||
|
||||
NLength::CDecoder m_LenDecoder;
|
||||
NLength::CDecoder m_RepMatchLenDecoder;
|
||||
|
||||
NLiteral::CDecoder m_LiteralDecoder;
|
||||
|
||||
UINT32 m_DictionarySize;
|
||||
|
||||
|
||||
UINT32 m_PosStateMask;
|
||||
|
||||
HRESULT Create();
|
||||
@@ -69,7 +69,7 @@ class CDecoder
|
||||
public:
|
||||
|
||||
CDecoder();
|
||||
|
||||
|
||||
HRESULT Code(ISequentialInStream *anInStream, ISequentialOutStream *anOutStream, const UINT64 *anInSize, const UINT64 *anOutSize);
|
||||
HRESULT ReadCoderProperties(ISequentialInStream *anInStream);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
#define RC_INIT_VAR \
|
||||
UINT32 aRange = aRangeDecoder->m_Range; \
|
||||
UINT32 aCode = aRangeDecoder->m_Code;
|
||||
UINT32 aCode = aRangeDecoder->m_Code;
|
||||
|
||||
#define RC_FLUSH_VAR \
|
||||
aRangeDecoder->m_Range = aRange; \
|
||||
@@ -56,6 +56,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
}} \
|
||||
RC_NORMALIZE
|
||||
|
||||
#define RC_GETBIT(aNumMoveBits, aProb, aModelIndex) RC_GETBIT2(aNumMoveBits, aProb, aModelIndex, ; , ;)
|
||||
#define RC_GETBIT(aNumMoveBits, aProb, aModelIndex) RC_GETBIT2(aNumMoveBits, aProb, aModelIndex, ; , ;)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
m_Range <<= 8;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Init(ISequentialInStream *aStream)
|
||||
{
|
||||
m_Stream.Init(aStream);
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
m_Range >>= aNumTotalBits;
|
||||
UINT32 aThreshold = m_Code / m_Range;
|
||||
m_Code -= aThreshold * m_Range;
|
||||
|
||||
|
||||
Normalize();
|
||||
return aThreshold;
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
UINT32 DecodeDirectBits(UINT32 aNumTotalBits)
|
||||
{
|
||||
UINT32 aRange = m_Range;
|
||||
UINT32 aCode = m_Code;
|
||||
UINT32 aCode = m_Code;
|
||||
UINT32 aResult = 0;
|
||||
for (UINT32 i = aNumTotalBits; i > 0; i--)
|
||||
{
|
||||
@@ -109,7 +109,7 @@ public:
|
||||
if (aRange < kTopValue)
|
||||
{
|
||||
aCode = (aCode << 8) | m_Stream.ReadByte();
|
||||
aRange <<= 8;
|
||||
aRange <<= 8;
|
||||
}
|
||||
}
|
||||
m_Range = aRange;
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace NWindow {
|
||||
|
||||
// m_KeepSizeBefore: how mach BYTEs must be in buffer before m_Pos;
|
||||
// m_KeepSizeAfter: how mach BYTEs must be in buffer after m_Pos;
|
||||
// m_KeepSizeReserv: how mach BYTEs must be in buffer for Moving Reserv;
|
||||
// m_KeepSizeReserv: how mach BYTEs must be in buffer for Moving Reserv;
|
||||
// must be >= aKeepSizeAfter; // test it
|
||||
|
||||
class COut
|
||||
@@ -55,14 +55,14 @@ public:
|
||||
|
||||
void Init(ISequentialOutStream *aStream, bool aSolid = false);
|
||||
HRESULT Flush();
|
||||
|
||||
|
||||
UINT32 GetCurPos() const { return m_Pos; }
|
||||
const BYTE *GetPointerToCurrentPos() const { return m_Buffer + m_Pos;};
|
||||
|
||||
void CopyBackBlock(UINT32 aDistance, UINT32 aLen)
|
||||
{
|
||||
if (m_Pos >= m_PosLimit)
|
||||
MoveBlockBackward();
|
||||
MoveBlockBackward();
|
||||
BYTE *p = m_Buffer + m_Pos;
|
||||
aDistance++;
|
||||
for(UINT32 i = 0; i < aLen; i++)
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
void PutOneByte(BYTE aByte)
|
||||
{
|
||||
if (m_Pos >= m_PosLimit)
|
||||
MoveBlockBackward();
|
||||
MoveBlockBackward();
|
||||
m_Buffer[m_Pos++] = aByte;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,66 +1,66 @@
|
||||
/*
|
||||
Copyright (C) 2004 NSRT Team ( http://nsrt.edgeemu.com )
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
#include "zsnesjma.h"
|
||||
#include "jma.h"
|
||||
|
||||
extern "C" {
|
||||
extern unsigned char *romdata;
|
||||
extern unsigned int curromspace;
|
||||
extern unsigned int maxromspace;
|
||||
}
|
||||
|
||||
void load_jma_file(const char *filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
JMA::jma_open JMAFile(filename);
|
||||
vector<JMA::jma_public_file_info> file_info = JMAFile.get_files_info();
|
||||
|
||||
string our_file_name;
|
||||
size_t our_file_size = 0;
|
||||
|
||||
for (vector<JMA::jma_public_file_info>::iterator i = file_info.begin(); i != file_info.end(); i++)
|
||||
{
|
||||
//Check for valid ROM based on size
|
||||
if ((i->size <= maxromspace+512) && (i->size > our_file_size))
|
||||
{
|
||||
our_file_name = i->name;
|
||||
our_file_size = i->size;
|
||||
}
|
||||
}
|
||||
|
||||
if (!our_file_size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
JMAFile.extract_file(our_file_name, romdata);
|
||||
|
||||
curromspace = our_file_size;
|
||||
}
|
||||
catch (JMA::jma_errors jma_error)
|
||||
{
|
||||
//No need to do anything
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Copyright (C) 2004 NSRT Team ( http://nsrt.edgeemu.com )
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
#include "zsnesjma.h"
|
||||
#include "jma.h"
|
||||
|
||||
extern "C" {
|
||||
extern unsigned char *romdata;
|
||||
extern unsigned int curromspace;
|
||||
extern unsigned int maxromspace;
|
||||
}
|
||||
|
||||
void load_jma_file(const char *filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
JMA::jma_open JMAFile(filename);
|
||||
vector<JMA::jma_public_file_info> file_info = JMAFile.get_files_info();
|
||||
|
||||
string our_file_name;
|
||||
size_t our_file_size = 0;
|
||||
|
||||
for (vector<JMA::jma_public_file_info>::iterator i = file_info.begin(); i != file_info.end(); i++)
|
||||
{
|
||||
//Check for valid ROM based on size
|
||||
if ((i->size <= maxromspace+512) && (i->size > our_file_size))
|
||||
{
|
||||
our_file_name = i->name;
|
||||
our_file_size = i->size;
|
||||
}
|
||||
}
|
||||
|
||||
if (!our_file_size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
JMAFile.extract_file(our_file_name, romdata);
|
||||
|
||||
curromspace = our_file_size;
|
||||
}
|
||||
catch (JMA::jma_errors jma_error)
|
||||
{
|
||||
//No need to do anything
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user