mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 01:44:06 -04:00
*** empty log message ***
This commit is contained in:
parent
e56b75d5f0
commit
c99b3db61d
@ -89,6 +89,7 @@ initiate(Filename &source_file) {
|
||||
downloader_cat.debug()
|
||||
<< "Decompressor::request_decompress() - Unknown file extension: ."
|
||||
<< extension << endl;
|
||||
return DC_error_abort;
|
||||
}
|
||||
return initiate(source_file, dest_file);
|
||||
}
|
||||
@ -105,7 +106,7 @@ initiate(Filename &source_file, Filename &dest_file) {
|
||||
downloader_cat.error()
|
||||
<< "Decompressor::run() - Decompression has already been initiated"
|
||||
<< endl;
|
||||
return DS_error;
|
||||
return DC_error_abort;
|
||||
}
|
||||
|
||||
// Open source file
|
||||
@ -115,7 +116,7 @@ initiate(Filename &source_file, Filename &dest_file) {
|
||||
downloader_cat.error()
|
||||
<< "Decompressor::decompress() - Error opening source file: "
|
||||
<< _source_file << endl;
|
||||
return false;
|
||||
return DC_error_read;
|
||||
}
|
||||
|
||||
// Determine source file length
|
||||
@ -125,7 +126,7 @@ initiate(Filename &source_file, Filename &dest_file) {
|
||||
downloader_cat.warning()
|
||||
<< "Decompressor::decompress() - Zero length file: "
|
||||
<< source_file << endl;
|
||||
return true;
|
||||
return DC_error_read;
|
||||
}
|
||||
_read_stream.seekg(0, ios::beg);
|
||||
|
||||
@ -135,7 +136,7 @@ initiate(Filename &source_file, Filename &dest_file) {
|
||||
downloader_cat.error()
|
||||
<< "Decompressor::decompress() - Error opening dest file: "
|
||||
<< source_file << endl;
|
||||
return false;
|
||||
return DC_error_write;
|
||||
}
|
||||
|
||||
// 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;
|
||||
_initiated = true;
|
||||
_decompressor = new ZDecompressor();
|
||||
return DS_success;
|
||||
return DC_success;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -182,7 +183,7 @@ run(void) {
|
||||
downloader_cat.error()
|
||||
<< "Decompressor::run() - Decompression has not been initiated"
|
||||
<< endl;
|
||||
return DS_error;
|
||||
return DC_error_abort;
|
||||
}
|
||||
|
||||
// See if there is anything left in the source file
|
||||
@ -209,15 +210,15 @@ run(void) {
|
||||
next_out, avail_out, dest_buffer,
|
||||
dest_buffer_length, _write_stream);
|
||||
if (ret == ZCompressorBase::S_error)
|
||||
return DS_error_zlib;
|
||||
return DC_error_zlib;
|
||||
if ((int)_decompressor->get_total_in() == _source_file_length &&
|
||||
avail_out == dest_buffer_length) {
|
||||
cleanup();
|
||||
return DS_success;
|
||||
return DC_success;
|
||||
}
|
||||
}
|
||||
|
||||
return DS_ok;
|
||||
return DC_ok;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -232,7 +233,7 @@ decompress(Filename &source_file) {
|
||||
return false;
|
||||
for (;;) {
|
||||
ret = run();
|
||||
if (ret == DS_success)
|
||||
if (ret == DC_success)
|
||||
return true;
|
||||
else if (ret < 0)
|
||||
return false;
|
||||
|
@ -22,11 +22,12 @@
|
||||
class EXPCL_PANDAEXPRESS Decompressor {
|
||||
PUBLISHED:
|
||||
enum DecompressStatus {
|
||||
DS_ok = 2,
|
||||
DS_success = 1,
|
||||
DS_error = -1,
|
||||
DS_error_write = -2,
|
||||
DS_error_zlib = -3,
|
||||
DC_ok = 2,
|
||||
DC_success = 1,
|
||||
DC_error_abort = -1,
|
||||
DC_error_write = -2,
|
||||
DC_error_read = -3,
|
||||
DC_error_zlib = -4,
|
||||
};
|
||||
|
||||
Decompressor(void);
|
||||
|
@ -72,7 +72,7 @@ initiate(Filename &source_file, const Filename &rel_path) {
|
||||
downloader_cat.error()
|
||||
<< "Extractor::initiate() - Extraction has already been initiated"
|
||||
<< endl;
|
||||
return ES_error;
|
||||
return EX_error_abort;
|
||||
}
|
||||
|
||||
// Open source file
|
||||
@ -81,8 +81,8 @@ initiate(Filename &source_file, const Filename &rel_path) {
|
||||
if (!_source_file.open_read(_read_stream)) {
|
||||
downloader_cat.error()
|
||||
<< "Extractor::extract() - Error opening source file: "
|
||||
<< _source_file << endl;
|
||||
return ES_error_write;
|
||||
<< _source_file << " : " << strerror(errno) << endl;
|
||||
return EX_error_write;
|
||||
}
|
||||
|
||||
_rel_path = rel_path;
|
||||
@ -97,7 +97,7 @@ initiate(Filename &source_file, const Filename &rel_path) {
|
||||
_handled_all_input = false;
|
||||
_mfile = new Multifile();
|
||||
_initiated = true;
|
||||
return ES_success;
|
||||
return EX_success;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -132,7 +132,7 @@ run(void) {
|
||||
downloader_cat.error()
|
||||
<< "Extractor::run() - Extraction has not been initiated"
|
||||
<< endl;
|
||||
return ES_error;
|
||||
return EX_error_abort;
|
||||
}
|
||||
|
||||
// See if there is anything left in the source file
|
||||
@ -150,11 +150,17 @@ run(void) {
|
||||
int buffer_size = _source_buffer_length;
|
||||
|
||||
// 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();
|
||||
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;
|
||||
for (;;) {
|
||||
ret = run();
|
||||
if (ret == ES_success)
|
||||
if (ret == EX_success)
|
||||
return true;
|
||||
if (ret < 0)
|
||||
return false;
|
||||
|
@ -22,10 +22,11 @@
|
||||
class EXPCL_PANDAEXPRESS Extractor {
|
||||
PUBLISHED:
|
||||
enum ExtractorStatus {
|
||||
ES_ok = 2,
|
||||
ES_success = 1,
|
||||
ES_error = -1,
|
||||
ES_error_write = -2,
|
||||
EX_ok = 2,
|
||||
EX_success = 1,
|
||||
EX_error_abort = -1,
|
||||
EX_error_write = -2,
|
||||
EX_error_empty = -3,
|
||||
};
|
||||
|
||||
Extractor(void);
|
||||
|
@ -183,8 +183,9 @@ read(const Filename &name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
express_cat.debug()
|
||||
<< "Reading file: " << name << endl;
|
||||
if (express_cat.is_debug())
|
||||
express_cat.debug()
|
||||
<< "Multifile::Memfile::read() - Reading file: " << name << endl;
|
||||
|
||||
_header_length = name.length() + sizeof(_header_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
|
||||
// Description: Reads a Memfile from an open Multifile ifstream
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -297,15 +298,11 @@ write_to_multifile(ofstream &write_stream) {
|
||||
// written to disk.
|
||||
// Advances the start pointer as it writes.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool Multifile::Memfile::
|
||||
int Multifile::Memfile::
|
||||
write(char *&start, int &size, const Filename &rel_path) {
|
||||
// Make sure we've got a complete header first
|
||||
if (parse_header(start, size) == false) {
|
||||
if (express_cat.is_debug())
|
||||
express_cat.debug()
|
||||
<< "Multifile::Memfile::write() - parse_header() == false"
|
||||
<< endl;
|
||||
return false;
|
||||
return MF_ok;
|
||||
}
|
||||
|
||||
// Try to open the file for writing
|
||||
@ -321,19 +318,19 @@ write(char *&start, int &size, const Filename &rel_path) {
|
||||
express_cat.error()
|
||||
<< "Multfile::Memfile::write() - Couldn't open file: "
|
||||
<< name << endl;
|
||||
return false;
|
||||
return MF_error_write;
|
||||
}
|
||||
_file_open = true;
|
||||
}
|
||||
|
||||
// Don't write more than the buffer length
|
||||
bool done = false;
|
||||
int done = MF_ok;
|
||||
int tsize = size;
|
||||
nassertr(_buffer_length >= _bytes_written, false);
|
||||
int missing_bytes = _buffer_length - _bytes_written;
|
||||
if (size >= missing_bytes) {
|
||||
tsize = missing_bytes;
|
||||
done = true;
|
||||
done = MF_success;
|
||||
}
|
||||
|
||||
_write_stream.write(start, tsize);
|
||||
@ -342,7 +339,7 @@ write(char *&start, int &size, const Filename &rel_path) {
|
||||
nassertr(size >= tsize, false);
|
||||
size -= tsize;
|
||||
|
||||
if (done == true) {
|
||||
if (done == MF_success) {
|
||||
_write_stream.close();
|
||||
express_cat.debug()
|
||||
<< "Multifile::Memfile::write() - Closing mem file" << endl;
|
||||
@ -409,16 +406,16 @@ evaluate(const char *start, int size) {
|
||||
// Access: Public
|
||||
// Description: Returns true when a complete header has been parsed.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool Multifile::
|
||||
int Multifile::
|
||||
parse_header(char *&start, int &size) {
|
||||
if (_header_parsed == true)
|
||||
return true;
|
||||
return MF_success;
|
||||
|
||||
int dgramsize = _datagram.get_length();
|
||||
int tsize = size;
|
||||
|
||||
// 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;
|
||||
if (size >= missing_bytes) {
|
||||
tsize = missing_bytes;
|
||||
@ -436,13 +433,14 @@ parse_header(char *&start, int &size) {
|
||||
express_cat.error()
|
||||
<< "Multifile::parse_header() - Invalid magic number: "
|
||||
<< magic_number << " (" << _magic_number << ")" << endl;
|
||||
return false;
|
||||
return MF_error_abort;
|
||||
}
|
||||
_num_mfiles = di.get_int32();
|
||||
if (_num_mfiles <= 0) {
|
||||
express_cat.debug()
|
||||
<< "Multifile::parse_header() - No memfiles in multifile"
|
||||
<< endl;
|
||||
return MF_error_empty;
|
||||
}
|
||||
|
||||
// Advance start pointer to the end of the header
|
||||
@ -450,9 +448,10 @@ parse_header(char *&start, int &size) {
|
||||
nassertr(size >= tsize, false);
|
||||
size -= tsize;
|
||||
_datagram.clear();
|
||||
return MF_success;
|
||||
}
|
||||
|
||||
return _header_parsed;
|
||||
return MF_ok;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -521,10 +520,13 @@ read(Filename &name) {
|
||||
read_stream.read(buffer, _header_length);
|
||||
char *start = buffer;
|
||||
int len = _header_length;
|
||||
bool ret = parse_header(start, len);
|
||||
int ret = parse_header(start, len);
|
||||
delete buffer;
|
||||
if (ret == false)
|
||||
if (ret < 0) {
|
||||
express_cat.error()
|
||||
<< "Multifile::read() - invalid header" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_num_mfiles <= 0) {
|
||||
express_cat.error()
|
||||
@ -586,25 +588,35 @@ write(Filename name) {
|
||||
// written.
|
||||
// Advances the start pointer as it writes.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool Multifile::
|
||||
int Multifile::
|
||||
write(char *&start, int &size, const Filename &rel_path) {
|
||||
// Make sure we have a complete header first
|
||||
if (parse_header(start, size) == false)
|
||||
return false;
|
||||
int parse_ret = parse_header(start, size);
|
||||
if (parse_ret < 0) {
|
||||
express_cat.error()
|
||||
<< "Multifile::write() - bad header" << endl;
|
||||
return parse_ret;
|
||||
}
|
||||
|
||||
while (_num_mfiles > 0) {
|
||||
if (_current_mfile == NULL) {
|
||||
_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--;
|
||||
delete _current_mfile;
|
||||
_current_mfile = NULL;
|
||||
} else
|
||||
return false;
|
||||
} else {
|
||||
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::
|
||||
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;
|
||||
if (_current_mfile == (Memfile *)0L)
|
||||
_current_mfile = new Memfile;
|
||||
|
@ -25,6 +25,14 @@
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDAEXPRESS Multifile {
|
||||
PUBLISHED:
|
||||
enum MfileCode {
|
||||
MF_ok = 2,
|
||||
MF_success = 1,
|
||||
MF_error_abort = -1,
|
||||
MF_error_write = -2,
|
||||
MF_error_empty = -3,
|
||||
};
|
||||
|
||||
enum Type {
|
||||
T_unknown,
|
||||
T_valid,
|
||||
@ -44,13 +52,13 @@ PUBLISHED:
|
||||
|
||||
bool read(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 extract(const Filename &name, const Filename &rel_path = "");
|
||||
void extract_all(const Filename &rel_path = "");
|
||||
|
||||
void reset(void);
|
||||
bool parse_header(char *&start, int &size);
|
||||
int parse_header(char *&start, int &size);
|
||||
|
||||
private:
|
||||
|
||||
@ -67,7 +75,7 @@ private:
|
||||
bool read_from_multifile(ifstream &read_stream);
|
||||
bool write(const Filename &rel_path);
|
||||
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);
|
||||
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user