*** empty log message ***

This commit is contained in:
Mike Goslin 2000-12-20 03:36:25 +00:00
parent e56b75d5f0
commit c99b3db61d
6 changed files with 89 additions and 59 deletions

View File

@ -89,6 +89,7 @@ initiate(Filename &source_file) {
downloader_cat.debug() downloader_cat.debug()
<< "Decompressor::request_decompress() - Unknown file extension: ." << "Decompressor::request_decompress() - Unknown file extension: ."
<< extension << endl; << extension << endl;
return DC_error_abort;
} }
return initiate(source_file, dest_file); return initiate(source_file, dest_file);
} }
@ -105,7 +106,7 @@ initiate(Filename &source_file, Filename &dest_file) {
downloader_cat.error() downloader_cat.error()
<< "Decompressor::run() - Decompression has already been initiated" << "Decompressor::run() - Decompression has already been initiated"
<< endl; << endl;
return DS_error; return DC_error_abort;
} }
// Open source file // Open source file
@ -115,7 +116,7 @@ initiate(Filename &source_file, Filename &dest_file) {
downloader_cat.error() downloader_cat.error()
<< "Decompressor::decompress() - Error opening source file: " << "Decompressor::decompress() - Error opening source file: "
<< _source_file << endl; << _source_file << endl;
return false; return DC_error_read;
} }
// Determine source file length // Determine source file length
@ -125,7 +126,7 @@ initiate(Filename &source_file, Filename &dest_file) {
downloader_cat.warning() downloader_cat.warning()
<< "Decompressor::decompress() - Zero length file: " << "Decompressor::decompress() - Zero length file: "
<< source_file << endl; << source_file << endl;
return true; return DC_error_read;
} }
_read_stream.seekg(0, ios::beg); _read_stream.seekg(0, ios::beg);
@ -135,7 +136,7 @@ initiate(Filename &source_file, Filename &dest_file) {
downloader_cat.error() downloader_cat.error()
<< "Decompressor::decompress() - Error opening dest file: " << "Decompressor::decompress() - Error opening dest file: "
<< source_file << endl; << source_file << endl;
return false; return DC_error_write;
} }
// Read from the source file into the first half of the buffer, // Read from the source file into the first half of the buffer,
@ -146,7 +147,7 @@ initiate(Filename &source_file, Filename &dest_file) {
_source_buffer_length; _source_buffer_length;
_initiated = true; _initiated = true;
_decompressor = new ZDecompressor(); _decompressor = new ZDecompressor();
return DS_success; return DC_success;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -182,7 +183,7 @@ run(void) {
downloader_cat.error() downloader_cat.error()
<< "Decompressor::run() - Decompression has not been initiated" << "Decompressor::run() - Decompression has not been initiated"
<< endl; << endl;
return DS_error; return DC_error_abort;
} }
// See if there is anything left in the source file // See if there is anything left in the source file
@ -209,15 +210,15 @@ run(void) {
next_out, avail_out, dest_buffer, next_out, avail_out, dest_buffer,
dest_buffer_length, _write_stream); dest_buffer_length, _write_stream);
if (ret == ZCompressorBase::S_error) if (ret == ZCompressorBase::S_error)
return DS_error_zlib; return DC_error_zlib;
if ((int)_decompressor->get_total_in() == _source_file_length && if ((int)_decompressor->get_total_in() == _source_file_length &&
avail_out == dest_buffer_length) { avail_out == dest_buffer_length) {
cleanup(); cleanup();
return DS_success; return DC_success;
} }
} }
return DS_ok; return DC_ok;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -232,7 +233,7 @@ decompress(Filename &source_file) {
return false; return false;
for (;;) { for (;;) {
ret = run(); ret = run();
if (ret == DS_success) if (ret == DC_success)
return true; return true;
else if (ret < 0) else if (ret < 0)
return false; return false;

View File

@ -22,11 +22,12 @@
class EXPCL_PANDAEXPRESS Decompressor { class EXPCL_PANDAEXPRESS Decompressor {
PUBLISHED: PUBLISHED:
enum DecompressStatus { enum DecompressStatus {
DS_ok = 2, DC_ok = 2,
DS_success = 1, DC_success = 1,
DS_error = -1, DC_error_abort = -1,
DS_error_write = -2, DC_error_write = -2,
DS_error_zlib = -3, DC_error_read = -3,
DC_error_zlib = -4,
}; };
Decompressor(void); Decompressor(void);

View File

@ -72,7 +72,7 @@ initiate(Filename &source_file, const Filename &rel_path) {
downloader_cat.error() downloader_cat.error()
<< "Extractor::initiate() - Extraction has already been initiated" << "Extractor::initiate() - Extraction has already been initiated"
<< endl; << endl;
return ES_error; return EX_error_abort;
} }
// Open source file // Open source file
@ -81,8 +81,8 @@ initiate(Filename &source_file, const Filename &rel_path) {
if (!_source_file.open_read(_read_stream)) { if (!_source_file.open_read(_read_stream)) {
downloader_cat.error() downloader_cat.error()
<< "Extractor::extract() - Error opening source file: " << "Extractor::extract() - Error opening source file: "
<< _source_file << endl; << _source_file << " : " << strerror(errno) << endl;
return ES_error_write; return EX_error_write;
} }
_rel_path = rel_path; _rel_path = rel_path;
@ -97,7 +97,7 @@ initiate(Filename &source_file, const Filename &rel_path) {
_handled_all_input = false; _handled_all_input = false;
_mfile = new Multifile(); _mfile = new Multifile();
_initiated = true; _initiated = true;
return ES_success; return EX_success;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -132,7 +132,7 @@ run(void) {
downloader_cat.error() downloader_cat.error()
<< "Extractor::run() - Extraction has not been initiated" << "Extractor::run() - Extraction has not been initiated"
<< endl; << endl;
return ES_error; return EX_error_abort;
} }
// See if there is anything left in the source file // See if there is anything left in the source file
@ -150,11 +150,17 @@ run(void) {
int buffer_size = _source_buffer_length; int buffer_size = _source_buffer_length;
// Write to the out file // Write to the out file
if (_mfile->write(buffer_start, buffer_size, _rel_path) == true) { int write_ret = _mfile->write(buffer_start, buffer_size, _rel_path);
if (write_ret == Multifile::MF_success) {
cleanup(); cleanup();
return ES_success; return EX_success;
} else if (write_ret < 0) {
downloader_cat.error()
<< "Extractor::run() - got error from Multifile: " << write_ret
<< endl;
return write_ret;
} }
return ES_ok; return EX_ok;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -169,7 +175,7 @@ extract(Filename &source_file, const Filename &rel_path) {
return false; return false;
for (;;) { for (;;) {
ret = run(); ret = run();
if (ret == ES_success) if (ret == EX_success)
return true; return true;
if (ret < 0) if (ret < 0)
return false; return false;

View File

@ -22,10 +22,11 @@
class EXPCL_PANDAEXPRESS Extractor { class EXPCL_PANDAEXPRESS Extractor {
PUBLISHED: PUBLISHED:
enum ExtractorStatus { enum ExtractorStatus {
ES_ok = 2, EX_ok = 2,
ES_success = 1, EX_success = 1,
ES_error = -1, EX_error_abort = -1,
ES_error_write = -2, EX_error_write = -2,
EX_error_empty = -3,
}; };
Extractor(void); Extractor(void);

View File

@ -183,8 +183,9 @@ read(const Filename &name) {
return false; return false;
} }
if (express_cat.is_debug())
express_cat.debug() express_cat.debug()
<< "Reading file: " << name << endl; << "Multifile::Memfile::read() - Reading file: " << name << endl;
_header_length = name.length() + sizeof(_header_length) + _header_length = name.length() + sizeof(_header_length) +
sizeof(_buffer_length); sizeof(_buffer_length);
@ -203,7 +204,7 @@ read(const Filename &name) {
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: Multifile::Memfile::read_multi // Function: Multifile::Memfile::read_from_multifile
// Access: Public // Access: Public
// Description: Reads a Memfile from an open Multifile ifstream // Description: Reads a Memfile from an open Multifile ifstream
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -297,15 +298,11 @@ write_to_multifile(ofstream &write_stream) {
// written to disk. // written to disk.
// Advances the start pointer as it writes. // Advances the start pointer as it writes.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool Multifile::Memfile:: int Multifile::Memfile::
write(char *&start, int &size, const Filename &rel_path) { write(char *&start, int &size, const Filename &rel_path) {
// Make sure we've got a complete header first // Make sure we've got a complete header first
if (parse_header(start, size) == false) { if (parse_header(start, size) == false) {
if (express_cat.is_debug()) return MF_ok;
express_cat.debug()
<< "Multifile::Memfile::write() - parse_header() == false"
<< endl;
return false;
} }
// Try to open the file for writing // Try to open the file for writing
@ -321,19 +318,19 @@ write(char *&start, int &size, const Filename &rel_path) {
express_cat.error() express_cat.error()
<< "Multfile::Memfile::write() - Couldn't open file: " << "Multfile::Memfile::write() - Couldn't open file: "
<< name << endl; << name << endl;
return false; return MF_error_write;
} }
_file_open = true; _file_open = true;
} }
// Don't write more than the buffer length // Don't write more than the buffer length
bool done = false; int done = MF_ok;
int tsize = size; int tsize = size;
nassertr(_buffer_length >= _bytes_written, false); nassertr(_buffer_length >= _bytes_written, false);
int missing_bytes = _buffer_length - _bytes_written; int missing_bytes = _buffer_length - _bytes_written;
if (size >= missing_bytes) { if (size >= missing_bytes) {
tsize = missing_bytes; tsize = missing_bytes;
done = true; done = MF_success;
} }
_write_stream.write(start, tsize); _write_stream.write(start, tsize);
@ -342,7 +339,7 @@ write(char *&start, int &size, const Filename &rel_path) {
nassertr(size >= tsize, false); nassertr(size >= tsize, false);
size -= tsize; size -= tsize;
if (done == true) { if (done == MF_success) {
_write_stream.close(); _write_stream.close();
express_cat.debug() express_cat.debug()
<< "Multifile::Memfile::write() - Closing mem file" << endl; << "Multifile::Memfile::write() - Closing mem file" << endl;
@ -409,16 +406,16 @@ evaluate(const char *start, int size) {
// Access: Public // Access: Public
// Description: Returns true when a complete header has been parsed. // Description: Returns true when a complete header has been parsed.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool Multifile:: int Multifile::
parse_header(char *&start, int &size) { parse_header(char *&start, int &size) {
if (_header_parsed == true) if (_header_parsed == true)
return true; return MF_success;
int dgramsize = _datagram.get_length(); int dgramsize = _datagram.get_length();
int tsize = size; int tsize = size;
// Make sure we don't exceed the length of the header // Make sure we don't exceed the length of the header
nassertr(_header_length >= dgramsize, false); nassertr(_header_length >= dgramsize, MF_error_abort);
int missing_bytes = _header_length - dgramsize; int missing_bytes = _header_length - dgramsize;
if (size >= missing_bytes) { if (size >= missing_bytes) {
tsize = missing_bytes; tsize = missing_bytes;
@ -436,13 +433,14 @@ parse_header(char *&start, int &size) {
express_cat.error() express_cat.error()
<< "Multifile::parse_header() - Invalid magic number: " << "Multifile::parse_header() - Invalid magic number: "
<< magic_number << " (" << _magic_number << ")" << endl; << magic_number << " (" << _magic_number << ")" << endl;
return false; return MF_error_abort;
} }
_num_mfiles = di.get_int32(); _num_mfiles = di.get_int32();
if (_num_mfiles <= 0) { if (_num_mfiles <= 0) {
express_cat.debug() express_cat.debug()
<< "Multifile::parse_header() - No memfiles in multifile" << "Multifile::parse_header() - No memfiles in multifile"
<< endl; << endl;
return MF_error_empty;
} }
// Advance start pointer to the end of the header // Advance start pointer to the end of the header
@ -450,9 +448,10 @@ parse_header(char *&start, int &size) {
nassertr(size >= tsize, false); nassertr(size >= tsize, false);
size -= tsize; size -= tsize;
_datagram.clear(); _datagram.clear();
return MF_success;
} }
return _header_parsed; return MF_ok;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -521,10 +520,13 @@ read(Filename &name) {
read_stream.read(buffer, _header_length); read_stream.read(buffer, _header_length);
char *start = buffer; char *start = buffer;
int len = _header_length; int len = _header_length;
bool ret = parse_header(start, len); int ret = parse_header(start, len);
delete buffer; delete buffer;
if (ret == false) if (ret < 0) {
express_cat.error()
<< "Multifile::read() - invalid header" << endl;
return false; return false;
}
if (_num_mfiles <= 0) { if (_num_mfiles <= 0) {
express_cat.error() express_cat.error()
@ -586,25 +588,35 @@ write(Filename name) {
// written. // written.
// Advances the start pointer as it writes. // Advances the start pointer as it writes.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool Multifile:: int Multifile::
write(char *&start, int &size, const Filename &rel_path) { write(char *&start, int &size, const Filename &rel_path) {
// Make sure we have a complete header first // Make sure we have a complete header first
if (parse_header(start, size) == false) int parse_ret = parse_header(start, size);
return false; if (parse_ret < 0) {
express_cat.error()
<< "Multifile::write() - bad header" << endl;
return parse_ret;
}
while (_num_mfiles > 0) { while (_num_mfiles > 0) {
if (_current_mfile == NULL) { if (_current_mfile == NULL) {
_current_mfile = new Memfile; _current_mfile = new Memfile;
} }
if (_current_mfile->write(start, size, rel_path) == true) { int write_ret = _current_mfile->write(start, size, rel_path);
if (write_ret == MF_success) {
_num_mfiles--; _num_mfiles--;
delete _current_mfile; delete _current_mfile;
_current_mfile = NULL; _current_mfile = NULL;
} else } else {
return false; if (write_ret < 0) {
express_cat.error()
<< "Multifile::write() - bad write: " << write_ret << endl;
}
return write_ret;
}
} }
return true; return MF_success;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -615,7 +627,8 @@ write(char *&start, int &size, const Filename &rel_path) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool Multifile:: bool Multifile::
write_extract(char *&start, int &size, const Filename &rel_path) { write_extract(char *&start, int &size, const Filename &rel_path) {
if (parse_header(start, size) == false) int parse_ret = parse_header(start, size);
if (parse_ret < 0)
return false; return false;
if (_current_mfile == (Memfile *)0L) if (_current_mfile == (Memfile *)0L)
_current_mfile = new Memfile; _current_mfile = new Memfile;

View File

@ -25,6 +25,14 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class EXPCL_PANDAEXPRESS Multifile { class EXPCL_PANDAEXPRESS Multifile {
PUBLISHED: PUBLISHED:
enum MfileCode {
MF_ok = 2,
MF_success = 1,
MF_error_abort = -1,
MF_error_write = -2,
MF_error_empty = -3,
};
enum Type { enum Type {
T_unknown, T_unknown,
T_valid, T_valid,
@ -44,13 +52,13 @@ PUBLISHED:
bool read(Filename &name); bool read(Filename &name);
bool write(Filename name); bool write(Filename name);
bool write(char *&start, int &size, const Filename &rel_path = ""); int write(char *&start, int &size, const Filename &rel_path = "");
bool write_extract(char *&start, int &size, const Filename &rel_path = ""); bool write_extract(char *&start, int &size, const Filename &rel_path = "");
bool extract(const Filename &name, const Filename &rel_path = ""); bool extract(const Filename &name, const Filename &rel_path = "");
void extract_all(const Filename &rel_path = ""); void extract_all(const Filename &rel_path = "");
void reset(void); void reset(void);
bool parse_header(char *&start, int &size); int parse_header(char *&start, int &size);
private: private:
@ -67,7 +75,7 @@ private:
bool read_from_multifile(ifstream &read_stream); bool read_from_multifile(ifstream &read_stream);
bool write(const Filename &rel_path); bool write(const Filename &rel_path);
void write_to_multifile(ofstream &write_stream); void write_to_multifile(ofstream &write_stream);
bool write(char *&start, int &size, const Filename &rel_path = ""); int write(char *&start, int &size, const Filename &rel_path = "");
void reset(void); void reset(void);
public: public: